Merge master.kernel.org:/home/rmk/linux-2.6-arm
diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle
index ce780ef..ce5d2c0 100644
--- a/Documentation/CodingStyle
+++ b/Documentation/CodingStyle
@@ -199,7 +199,7 @@
     modifications are prevented
 - saves the compiler work to optimize redundant code away ;)
 
-int fun(int )
+int fun(int a)
 {
 	int result = 0;
 	char *buffer = kmalloc(SIZE);
diff --git a/Documentation/DocBook/.gitignore b/Documentation/DocBook/.gitignore
new file mode 100644
index 0000000..c102c02
--- /dev/null
+++ b/Documentation/DocBook/.gitignore
@@ -0,0 +1,6 @@
+*.xml
+*.ps
+*.pdf
+*.html
+*.9.gz
+*.9
diff --git a/Documentation/DocBook/kernel-api.tmpl b/Documentation/DocBook/kernel-api.tmpl
index 3c47a3f..8c9c670 100644
--- a/Documentation/DocBook/kernel-api.tmpl
+++ b/Documentation/DocBook/kernel-api.tmpl
@@ -54,6 +54,11 @@
 !Ekernel/sched.c
 !Ekernel/timer.c
      </sect1>
+     <sect1><title>High-resolution timers</title>
+!Iinclude/linux/ktime.h
+!Iinclude/linux/hrtimer.h
+!Ekernel/hrtimer.c
+     </sect1>
      <sect1><title>Internal Functions</title>
 !Ikernel/exit.c
 !Ikernel/signal.c
diff --git a/Documentation/applying-patches.txt b/Documentation/applying-patches.txt
index 05a08c2..a083ba3 100644
--- a/Documentation/applying-patches.txt
+++ b/Documentation/applying-patches.txt
@@ -3,8 +3,7 @@
 	------------------------------------
 
 	Original by: Jesper Juhl, August 2005
-	Last update: 2005-12-02
-
+	Last update: 2006-01-05
 
 
 A frequently asked question on the Linux Kernel Mailing List is how to apply
@@ -77,7 +76,7 @@
 
 If you wish to uncompress the patch file by hand first before applying it
 (what I assume you've done in the examples below), then you simply run
-gunzip or bunzip2 on the file - like this:
+gunzip or bunzip2 on the file -- like this:
 	gunzip patch-x.y.z.gz
 	bunzip2 patch-x.y.z.bz2
 
@@ -95,7 +94,7 @@
 ---
  When patch applies a patch file it attempts to verify the sanity of the
 file in different ways.
-Checking that the file looks like a valid patch file, checking the code
+Checking that the file looks like a valid patch file & checking the code
 around the bits being modified matches the context provided in the patch are
 just two of the basic sanity checks patch does.
 
@@ -122,7 +121,7 @@
 read this file to see exactly what change couldn't be applied, so you can
 go fix it up by hand if you wish.
 
-If you don't have any third party patches applied to your kernel source, but
+If you don't have any third-party patches applied to your kernel source, but
 only patches from kernel.org and you apply the patches in the correct order,
 and have made no modifications yourself to the source files, then you should
 never see a fuzz or reject message from patch. If you do see such messages
@@ -137,7 +136,7 @@
 find a file to be patched. Most likely you forgot to specify -p1 or you are
 in the wrong directory. Less often, you'll find patches that need to be
 applied with -p0 instead of -p1 (reading the patch file should reveal if
-this is the case - if so, then this is an error by the person who created
+this is the case -- if so, then this is an error by the person who created
 the patch but is not fatal).
 
 If you get "Hunk #2 succeeded at 1887 with fuzz 2 (offset 7 lines)." or a
@@ -168,13 +167,17 @@
 
 A message similar to "patch: **** unexpected end of file in patch" or "patch
 unexpectedly ends in middle of line" means that patch could make no sense of
-the file you fed to it. Either your download is broken or you tried to feed
-patch a compressed patch file without uncompressing it first.
+the file you fed to it. Either your download is broken, you tried to feed
+patch a compressed patch file without uncompressing it first, or the patch
+file that you are using has been mangled by a mail client or mail transfer
+agent along the way somewhere, e.g., by splitting a long line into two lines.
+Often these warnings can easily be fixed by joining (concatenating) the
+two lines that had been split.
 
 As I already mentioned above, these errors should never happen if you apply
 a patch from kernel.org to the correct version of an unmodified source tree.
 So if you get these errors with kernel.org patches then you should probably
-assume that either your patch file or your tree is broken and I'd advice you
+assume that either your patch file or your tree is broken and I'd advise you
 to start over with a fresh download of a full kernel tree and the patch you
 wish to apply.
 
@@ -200,10 +203,10 @@
  Another alternative is `ketchup', which is a python script for automatic
 downloading and applying of patches (http://www.selenic.com/ketchup/).
 
- Other nice tools are diffstat which shows a summary of changes made by a
-patch, lsdiff which displays a short listing of affected files in a patch
-file, along with (optionally) the line numbers of the start of each patch
-and grepdiff which displays a list of the files modified by a patch where
+ Other nice tools are diffstat, which shows a summary of changes made by a
+patch; lsdiff, which displays a short listing of affected files in a patch
+file, along with (optionally) the line numbers of the start of each patch;
+and grepdiff, which displays a list of the files modified by a patch where
 the patch contains a given regular expression.
 
 
@@ -228,8 +231,8 @@
 In place of ftp.kernel.org you can use ftp.cc.kernel.org, where cc is a
 country code. This way you'll be downloading from a mirror site that's most
 likely geographically closer to you, resulting in faster downloads for you,
-less bandwidth used globally and less load on the main kernel.org servers -
-these are good things, do use mirrors when possible.
+less bandwidth used globally and less load on the main kernel.org servers --
+these are good things, so do use mirrors when possible.
 
 
 The 2.6.x kernels
@@ -237,14 +240,14 @@
  These are the base stable releases released by Linus. The highest numbered
 release is the most recent.
 
-If regressions or other serious flaws are found then a -stable fix patch
+If regressions or other serious flaws are found, then a -stable fix patch
 will be released (see below) on top of this base. Once a new 2.6.x base
 kernel is released, a patch is made available that is a delta between the
 previous 2.6.x kernel and the new one.
 
-To apply a patch moving from 2.6.11 to 2.6.12 you'd do the following (note
+To apply a patch moving from 2.6.11 to 2.6.12, you'd do the following (note
 that such patches do *NOT* apply on top of 2.6.x.y kernels but on top of the
-base 2.6.x kernel - if you need to move from 2.6.x.y to 2.6.x+1 you need to
+base 2.6.x kernel -- if you need to move from 2.6.x.y to 2.6.x+1 you need to
 first revert the 2.6.x.y patch).
 
 Here are some examples:
@@ -266,7 +269,7 @@
 
 The 2.6.x.y kernels
 ---
- Kernels with 4 digit versions are -stable kernels. They contain small(ish)
+ Kernels with 4-digit versions are -stable kernels. They contain small(ish)
 critical fixes for security problems or significant regressions discovered
 in a given 2.6.x kernel.
 
@@ -277,9 +280,14 @@
 If no 2.6.x.y kernel is available, then the highest numbered 2.6.x kernel is
 the current stable kernel.
 
+ note: the -stable team usually do make incremental patches available as well
+ as patches against the latest mainline release, but I only cover the
+ non-incremental ones below. The incremental ones can be found at
+ ftp://ftp.kernel.org/pub/linux/kernel/v2.6/incr/
+
 These patches are not incremental, meaning that for example the 2.6.12.3
 patch does not apply on top of the 2.6.12.2 kernel source, but rather on top
-of the base 2.6.12 kernel source.
+of the base 2.6.12 kernel source .
 So, in order to apply the 2.6.12.3 patch to your existing 2.6.12.2 kernel
 source you have to first back out the 2.6.12.2 patch (so you are left with a
 base 2.6.12 kernel source) and then apply the new 2.6.12.3 patch.
@@ -345,12 +353,12 @@
 repository, hence the name).
 
 These patches are usually released daily and represent the current state of
-Linus' tree. They are more experimental than -rc kernels since they are
+Linus's tree. They are more experimental than -rc kernels since they are
 generated automatically without even a cursory glance to see if they are
 sane.
 
 -git patches are not incremental and apply either to a base 2.6.x kernel or
-a base 2.6.x-rc kernel - you can see which from their name.
+a base 2.6.x-rc kernel -- you can see which from their name.
 A patch named 2.6.12-git1 applies to the 2.6.12 kernel source and a patch
 named 2.6.13-rc3-git2 applies to the source of the 2.6.13-rc3 kernel.
 
@@ -393,12 +401,12 @@
 ensure maximum testing.
 
 This branch is in constant flux and contains many experimental features, a
-lot of debugging patches not appropriate for mainline etc and is the most
+lot of debugging patches not appropriate for mainline etc., and is the most
 experimental of the branches described in this document.
 
 These kernels are not appropriate for use on systems that are supposed to be
 stable and they are more risky to run than any of the other branches (make
-sure you have up-to-date backups - that goes for any experimental kernel but
+sure you have up-to-date backups -- that goes for any experimental kernel but
 even more so for -mm kernels).
 
 These kernels in addition to all the other experimental patches they contain
diff --git a/Documentation/cpusets.txt b/Documentation/cpusets.txt
index 9e49b1c..990998e 100644
--- a/Documentation/cpusets.txt
+++ b/Documentation/cpusets.txt
@@ -135,7 +135,7 @@
 The implementation of cpusets requires a few, simple hooks
 into the rest of the kernel, none in performance critical paths:
 
- - in main/init.c, to initialize the root cpuset at system boot.
+ - in init/main.c, to initialize the root cpuset at system boot.
  - in fork and exit, to attach and detach a task from its cpuset.
  - in sched_setaffinity, to mask the requested CPUs by what's
    allowed in that tasks cpuset.
@@ -146,7 +146,7 @@
    and related changes in both sched.c and arch/ia64/kernel/domain.c
  - in the mbind and set_mempolicy system calls, to mask the requested
    Memory Nodes by what's allowed in that tasks cpuset.
- - in page_alloc, to restrict memory to allowed nodes.
+ - in page_alloc.c, to restrict memory to allowed nodes.
  - in vmscan.c, to restrict page recovery to the current cpuset.
 
 In addition a new file system, of type "cpuset" may be mounted,
diff --git a/Documentation/filesystems/ext3.txt b/Documentation/filesystems/ext3.txt
index 22e4040..afb1335 100644
--- a/Documentation/filesystems/ext3.txt
+++ b/Documentation/filesystems/ext3.txt
@@ -2,11 +2,11 @@
 Ext3 Filesystem
 ===============
 
-ext3 was originally released in September 1999. Written by Stephen Tweedie
-for 2.2 branch, and ported to 2.4 kernels by Peter Braam, Andreas Dilger, 
+Ext3 was originally released in September 1999. Written by Stephen Tweedie
+for the 2.2 branch, and ported to 2.4 kernels by Peter Braam, Andreas Dilger,
 Andrew Morton, Alexander Viro, Ted Ts'o and Stephen Tweedie.
 
-ext3 is ext2 filesystem enhanced with journalling capabilities. 
+Ext3 is the ext2 filesystem enhanced with journalling capabilities.
 
 Options
 =======
@@ -14,81 +14,81 @@
 When mounting an ext3 filesystem, the following option are accepted:
 (*) == default
 
-jounal=update		Update the ext3 file system's journal to the 
-			current format.
+journal=update		Update the ext3 file system's journal to the current
+			format.
 
-journal=inum		When a journal already exists, this option is 
-			ignored. Otherwise, it specifies the number of
-			the inode which will represent the ext3 file
-			system's journal file.
+journal=inum		When a journal already exists, this option is ignored.
+			Otherwise, it specifies the number of the inode which
+			will represent the ext3 file system's journal file.
 
 journal_dev=devnum	When the external journal device's major/minor numbers
-			have changed, this option allows to specify the new
-			journal location. The journal device is identified
-			through its new major/minor numbers encoded in devnum.
+			have changed, this option allows the user to specify
+			the new journal location.  The journal device is
+			identified through its new major/minor numbers encoded
+			in devnum.
 
 noload			Don't load the journal on mounting.
 
-data=journal		All data are committed into the journal prior
-			to being written into the main file system.
+data=journal		All data are committed into the journal prior to being
+			written into the main file system.
 
 data=ordered	(*)	All data are forced directly out to the main file
-			system prior to its metadata being committed to
-			the journal.
+			system prior to its metadata being committed to the
+			journal.
 
-data=writeback		Data ordering is not preserved, data may be
-			written into the main file system after its
-			metadata has been committed to the journal.
+data=writeback		Data ordering is not preserved, data may be written
+			into the main file system after its metadata has been
+			committed to the journal.
 
 commit=nrsec	(*)	Ext3 can be told to sync all its data and metadata
 			every 'nrsec' seconds. The default value is 5 seconds.
-			This means that if you lose your power, you will lose,
-			as much, the latest 5 seconds of work (your filesystem
-			will not be damaged though, thanks to journaling). This
-			default value (or any low value) will hurt performance,
-			but it's good for data-safety. Setting it to 0 will
-			have the same effect than leaving the default 5 sec.
+			This means that if you lose your power, you will lose
+			as much as the latest 5 seconds of work (your
+			filesystem will not be damaged though, thanks to the
+			journaling).  This default value (or any low value)
+			will hurt performance, but it's good for data-safety.
+			Setting it to 0 will have the same effect as leaving
+			it at the default (5 seconds).
 			Setting it to very large values will improve
 			performance.
 
-barrier=1		This enables/disables barriers. barrier=0 disables it,
-			barrier=1 enables it.
+barrier=1		This enables/disables barriers.  barrier=0 disables
+			it, barrier=1 enables it.
 
-orlov		(*)	This enables the new Orlov block allocator. It's enabled
-			by default.
+orlov		(*)	This enables the new Orlov block allocator. It is
+			enabled by default.
 
-oldalloc		This disables the Orlov block allocator and enables the
-			old block allocator. Orlov should have better performance,
-			we'd like to get some feedback if it's the contrary for
-			you.
+oldalloc		This disables the Orlov block allocator and enables
+			the old block allocator.  Orlov should have better
+			performance - we'd like to get some feedback if it's
+			the contrary for you.
 
-user_xattr		Enables Extended User Attributes. Additionally, you need
-			to have extended attribute support enabled in the kernel
-			configuration (CONFIG_EXT3_FS_XATTR). See the attr(5)
-			manual page and http://acl.bestbits.at to learn more
-			about extended attributes.
+user_xattr		Enables Extended User Attributes.  Additionally, you
+			need to have extended attribute support enabled in the
+			kernel configuration (CONFIG_EXT3_FS_XATTR).  See the
+			attr(5) manual page and http://acl.bestbits.at/ to
+			learn more about extended attributes.
 
 nouser_xattr		Disables Extended User Attributes.
 
-acl			Enables POSIX Access Control Lists support.  Additionally,
-			you need to have ACL support enabled in the kernel
-			configuration (CONFIG_EXT3_FS_POSIX_ACL). See the acl(5)
-			manual page and http://acl.bestbits.at for more
-			information.
+acl			Enables POSIX Access Control Lists support.
+			Additionally, you need to have ACL support enabled in
+			the kernel configuration (CONFIG_EXT3_FS_POSIX_ACL).
+			See the acl(5) manual page and http://acl.bestbits.at/
+			for more information.
 
-noacl			This option disables POSIX Access Control List support.
+noacl			This option disables POSIX Access Control List
+			support.
 
 reservation
 
 noreservation
 
-resize=
-
 bsddf 		(*)	Make 'df' act like BSD.
 minixdf			Make 'df' act like Minix.
 
 check=none		Don't do extra checking of bitmaps on mount.
-nocheck		
+nocheck
 
 debug			Extra debugging information is sent to syslog.
 
@@ -97,7 +97,7 @@
 errors=panic		Panic and halt the machine if an error occurs.
 
 grpid			Give objects the same group ID as their creator.
-bsdgroups		
+bsdgroups
 
 nogrpid		(*)	New objects have the group ID of their creator.
 sysvgroups
@@ -108,81 +108,83 @@
 
 sb=n			Use alternate superblock at this location.
 
-quota			Quota options are currently silently ignored.
-noquota			(see fs/ext3/super.c, line 594)
+quota
+noquota
 grpquota
 usrquota
 
 
 Specification
 =============
-ext3 shares all disk implementation with ext2 filesystem, and add
-transactions capabilities to ext2.  Journaling is done by the
-Journaling block device layer.
+Ext3 shares all disk implementation with the ext2 filesystem, and adds
+transactions capabilities to ext2.  Journaling is done by the Journaling Block
+Device layer.
 
 Journaling Block Device layer
 -----------------------------
-The Journaling Block Device layer (JBD) isn't ext3 specific.  It was
-design to add journaling capabilities on a block device.  The ext3
-filesystem code will inform the JBD of modifications it is performing
-(Call a transaction).  the journal support the transactions start and
-stop, and in case of crash, the journal can replayed the transactions
-to put the partition on a consistent state fastly.
+The Journaling Block Device layer (JBD) isn't ext3 specific.  It was design to
+add journaling capabilities on a block device.  The ext3 filesystem code will
+inform the JBD of modifications it is performing (called a transaction).  The
+journal supports the transactions start and stop, and in case of crash, the
+journal can replayed the transactions to put the partition back in a
+consistent state fast.
 
-handles represent a single atomic update to a filesystem.  JBD can
-handle external journal on a block device.
+Handles represent a single atomic update to a filesystem.  JBD can handle an
+external journal on a block device.
 
 Data Mode
 ---------
-There's 3 different data modes:
+There are 3 different data modes:
 
 * writeback mode
-In data=writeback mode, ext3 does not journal data at all.  This mode
-provides a similar level of journaling as XFS, JFS, and ReiserFS in its
-default mode - metadata journaling.  A crash+recovery can cause
-incorrect data to appear in files which were written shortly before the
-crash.  This mode will typically provide the best ext3 performance.
+In data=writeback mode, ext3 does not journal data at all.  This mode provides
+a similar level of journaling as that of XFS, JFS, and ReiserFS in its default
+mode - metadata journaling.  A crash+recovery can cause incorrect data to
+appear in files which were written shortly before the crash.  This mode will
+typically provide the best ext3 performance.
 
 * ordered mode
-In data=ordered mode, ext3 only officially journals metadata, but it
-logically groups metadata and data blocks into a single unit called a
-transaction.  When it's time to write the new metadata out to disk, the
-associated data blocks are written first.  In general, this mode
-perform slightly slower than writeback but significantly faster than
-journal mode.
+In data=ordered mode, ext3 only officially journals metadata, but it logically
+groups metadata and data blocks into a single unit called a transaction.  When
+it's time to write the new metadata out to disk, the associated data blocks
+are written first.  In general, this mode performs slightly slower than
+writeback but significantly faster than journal mode.
 
 * journal mode
-data=journal mode provides full data and metadata journaling.  All new
-data is written to the journal first, and then to its final location. 
-In the event of a crash, the journal can be replayed, bringing both
-data and metadata into a consistent state.  This mode is the slowest
-except when data needs to be read from and written to disk at the same
-time where it outperform all others mode.
+data=journal mode provides full data and metadata journaling.  All new data is
+written to the journal first, and then to its final location.
+In the event of a crash, the journal can be replayed, bringing both data and
+metadata into a consistent state.  This mode is the slowest except when data
+needs to be read from and written to disk at the same time where it
+outperforms all others modes.
 
 Compatibility
 -------------
 
 Ext2 partitions can be easily convert to ext3, with `tune2fs -j <dev>`.
-Ext3 is fully compatible with Ext2.  Ext3 partitions can easily be
-mounted as Ext2.
+Ext3 is fully compatible with Ext2.  Ext3 partitions can easily be mounted as
+Ext2.
+
 
 External Tools
 ==============
-see manual pages to know more.
+See manual pages to learn more.
 
-tune2fs: 	create a ext3 journal on a ext2 partition with the -j flags
-mke2fs: 	create a ext3 partition with the -j flags
-debugfs: 	ext2 and ext3 file system debugger
+tune2fs: 	create a ext3 journal on a ext2 partition with the -j flag.
+mke2fs: 	create a ext3 partition with the -j flag.
+debugfs: 	ext2 and ext3 file system debugger.
+ext2online:	online (mounted) ext2 and ext3 filesystem resizer
+
 
 References
 ==========
 
-kernel source:	file:/usr/src/linux/fs/ext3
-		file:/usr/src/linux/fs/jbd
+kernel source:	<file:fs/ext3/>
+		<file:fs/jbd/>
 
-programs: 	http://e2fsprogs.sourceforge.net
+programs: 	http://e2fsprogs.sourceforge.net/
+		http://ext2resize.sourceforge.net
 
-useful link:
-		http://www.zip.com.au/~akpm/linux/ext3/ext3-usage.html
+useful links:	http://www.zip.com.au/~akpm/linux/ext3/ext3-usage.html
 		http://www-106.ibm.com/developerworks/linux/library/l-fs7/
 		http://www-106.ibm.com/developerworks/linux/library/l-fs8/
diff --git a/Documentation/hrtimers.txt b/Documentation/hrtimers.txt
new file mode 100644
index 0000000..7620ff7
--- /dev/null
+++ b/Documentation/hrtimers.txt
@@ -0,0 +1,178 @@
+
+hrtimers - subsystem for high-resolution kernel timers
+----------------------------------------------------
+
+This patch introduces a new subsystem for high-resolution kernel timers.
+
+One might ask the question: we already have a timer subsystem
+(kernel/timers.c), why do we need two timer subsystems? After a lot of
+back and forth trying to integrate high-resolution and high-precision
+features into the existing timer framework, and after testing various
+such high-resolution timer implementations in practice, we came to the
+conclusion that the timer wheel code is fundamentally not suitable for
+such an approach. We initially didnt believe this ('there must be a way
+to solve this'), and spent a considerable effort trying to integrate
+things into the timer wheel, but we failed. In hindsight, there are
+several reasons why such integration is hard/impossible:
+
+- the forced handling of low-resolution and high-resolution timers in
+  the same way leads to a lot of compromises, macro magic and #ifdef
+  mess. The timers.c code is very "tightly coded" around jiffies and
+  32-bitness assumptions, and has been honed and micro-optimized for a
+  relatively narrow use case (jiffies in a relatively narrow HZ range)
+  for many years - and thus even small extensions to it easily break
+  the wheel concept, leading to even worse compromises. The timer wheel
+  code is very good and tight code, there's zero problems with it in its
+  current usage - but it is simply not suitable to be extended for
+  high-res timers.
+
+- the unpredictable [O(N)] overhead of cascading leads to delays which
+  necessiate a more complex handling of high resolution timers, which
+  in turn decreases robustness. Such a design still led to rather large
+  timing inaccuracies. Cascading is a fundamental property of the timer
+  wheel concept, it cannot be 'designed out' without unevitably
+  degrading other portions of the timers.c code in an unacceptable way.
+
+- the implementation of the current posix-timer subsystem on top of
+  the timer wheel has already introduced a quite complex handling of
+  the required readjusting of absolute CLOCK_REALTIME timers at
+  settimeofday or NTP time - further underlying our experience by
+  example: that the timer wheel data structure is too rigid for high-res
+  timers.
+
+- the timer wheel code is most optimal for use cases which can be
+  identified as "timeouts". Such timeouts are usually set up to cover
+  error conditions in various I/O paths, such as networking and block
+  I/O. The vast majority of those timers never expire and are rarely
+  recascaded because the expected correct event arrives in time so they
+  can be removed from the timer wheel before any further processing of
+  them becomes necessary. Thus the users of these timeouts can accept
+  the granularity and precision tradeoffs of the timer wheel, and
+  largely expect the timer subsystem to have near-zero overhead.
+  Accurate timing for them is not a core purpose - in fact most of the
+  timeout values used are ad-hoc. For them it is at most a necessary
+  evil to guarantee the processing of actual timeout completions
+  (because most of the timeouts are deleted before completion), which
+  should thus be as cheap and unintrusive as possible.
+
+The primary users of precision timers are user-space applications that
+utilize nanosleep, posix-timers and itimer interfaces. Also, in-kernel
+users like drivers and subsystems which require precise timed events
+(e.g. multimedia) can benefit from the availability of a seperate
+high-resolution timer subsystem as well.
+
+While this subsystem does not offer high-resolution clock sources just
+yet, the hrtimer subsystem can be easily extended with high-resolution
+clock capabilities, and patches for that exist and are maturing quickly.
+The increasing demand for realtime and multimedia applications along
+with other potential users for precise timers gives another reason to
+separate the "timeout" and "precise timer" subsystems.
+
+Another potential benefit is that such a seperation allows even more
+special-purpose optimization of the existing timer wheel for the low
+resolution and low precision use cases - once the precision-sensitive
+APIs are separated from the timer wheel and are migrated over to
+hrtimers. E.g. we could decrease the frequency of the timeout subsystem
+from 250 Hz to 100 HZ (or even smaller).
+
+hrtimer subsystem implementation details
+----------------------------------------
+
+the basic design considerations were:
+
+- simplicity
+
+- data structure not bound to jiffies or any other granularity. All the
+  kernel logic works at 64-bit nanoseconds resolution - no compromises.
+
+- simplification of existing, timing related kernel code
+
+another basic requirement was the immediate enqueueing and ordering of
+timers at activation time. After looking at several possible solutions
+such as radix trees and hashes, we chose the red black tree as the basic
+data structure. Rbtrees are available as a library in the kernel and are
+used in various performance-critical areas of e.g. memory management and
+file systems. The rbtree is solely used for time sorted ordering, while
+a separate list is used to give the expiry code fast access to the
+queued timers, without having to walk the rbtree.
+
+(This seperate list is also useful for later when we'll introduce
+high-resolution clocks, where we need seperate pending and expired
+queues while keeping the time-order intact.)
+
+Time-ordered enqueueing is not purely for the purposes of
+high-resolution clocks though, it also simplifies the handling of
+absolute timers based on a low-resolution CLOCK_REALTIME. The existing
+implementation needed to keep an extra list of all armed absolute
+CLOCK_REALTIME timers along with complex locking. In case of
+settimeofday and NTP, all the timers (!) had to be dequeued, the
+time-changing code had to fix them up one by one, and all of them had to
+be enqueued again. The time-ordered enqueueing and the storage of the
+expiry time in absolute time units removes all this complex and poorly
+scaling code from the posix-timer implementation - the clock can simply
+be set without having to touch the rbtree. This also makes the handling
+of posix-timers simpler in general.
+
+The locking and per-CPU behavior of hrtimers was mostly taken from the
+existing timer wheel code, as it is mature and well suited. Sharing code
+was not really a win, due to the different data structures. Also, the
+hrtimer functions now have clearer behavior and clearer names - such as
+hrtimer_try_to_cancel() and hrtimer_cancel() [which are roughly
+equivalent to del_timer() and del_timer_sync()] - so there's no direct
+1:1 mapping between them on the algorithmical level, and thus no real
+potential for code sharing either.
+
+Basic data types: every time value, absolute or relative, is in a
+special nanosecond-resolution type: ktime_t. The kernel-internal
+representation of ktime_t values and operations is implemented via
+macros and inline functions, and can be switched between a "hybrid
+union" type and a plain "scalar" 64bit nanoseconds representation (at
+compile time). The hybrid union type optimizes time conversions on 32bit
+CPUs. This build-time-selectable ktime_t storage format was implemented
+to avoid the performance impact of 64-bit multiplications and divisions
+on 32bit CPUs. Such operations are frequently necessary to convert
+between the storage formats provided by kernel and userspace interfaces
+and the internal time format. (See include/linux/ktime.h for further
+details.)
+
+hrtimers - rounding of timer values
+-----------------------------------
+
+the hrtimer code will round timer events to lower-resolution clocks
+because it has to. Otherwise it will do no artificial rounding at all.
+
+one question is, what resolution value should be returned to the user by
+the clock_getres() interface. This will return whatever real resolution
+a given clock has - be it low-res, high-res, or artificially-low-res.
+
+hrtimers - testing and verification
+----------------------------------
+
+We used the high-resolution clock subsystem ontop of hrtimers to verify
+the hrtimer implementation details in praxis, and we also ran the posix
+timer tests in order to ensure specification compliance. We also ran
+tests on low-resolution clocks.
+
+The hrtimer patch converts the following kernel functionality to use
+hrtimers:
+
+ - nanosleep
+ - itimers
+ - posix-timers
+
+The conversion of nanosleep and posix-timers enabled the unification of
+nanosleep and clock_nanosleep.
+
+The code was successfully compiled for the following platforms:
+
+ i386, x86_64, ARM, PPC, PPC64, IA64
+
+The code was run-tested on the following platforms:
+
+ i386(UP/SMP), x86_64(UP/SMP), ARM, PPC
+
+hrtimers were also integrated into the -rt tree, along with a
+hrtimers-based high-resolution clock implementation, so the hrtimers
+code got a healthy amount of testing and use in practice.
+
+	Thomas Gleixner, Ingo Molnar
diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
index d802ce8..443230b 100644
--- a/Documentation/kbuild/makefiles.txt
+++ b/Documentation/kbuild/makefiles.txt
@@ -1033,9 +1033,9 @@
 
 	Example:
 		#arch/i386/Makefile
-		GCC_VERSION := $(call cc-version)
 		cflags-y += $(shell \
-		if [ $(GCC_VERSION) -ge 0300 ] ; then echo "-mregparm=3"; fi ;)
+		if [ $(call cc-version) -ge 0300 ] ; then \
+			echo "-mregparm=3"; fi ;)
 
 	In the above example -mregparm=3 is only used for gcc version greater
 	than or equal to gcc 3.0.
diff --git a/Documentation/kdump/gdbmacros.txt b/Documentation/kdump/gdbmacros.txt
index bc1b9eb..dcf5580 100644
--- a/Documentation/kdump/gdbmacros.txt
+++ b/Documentation/kdump/gdbmacros.txt
@@ -177,3 +177,25 @@
 	'trapinfo <pid>' will tell you by which trap & possibly
 	addresthe kernel paniced.
 end
+
+
+define dmesg
+	set $i = 0
+	set $end_idx = (log_end - 1) & (log_buf_len - 1)
+
+	while ($i < logged_chars)
+		set $idx = (log_end - 1 - logged_chars + $i) & (log_buf_len - 1)
+
+		if ($idx + 100 <= $end_idx) || \
+		   ($end_idx <= $idx && $idx + 100 < log_buf_len)
+			printf "%.100s", &log_buf[$idx]
+			set $i = $i + 100
+		else
+			printf "%c", log_buf[$idx]
+			set $i = $i + 1
+		end
+	end
+end
+document dmesg
+	print the kernel ring buffer
+end
diff --git a/Documentation/kdump/kdump.txt b/Documentation/kdump/kdump.txt
index 5f08f9c..212cf3c 100644
--- a/Documentation/kdump/kdump.txt
+++ b/Documentation/kdump/kdump.txt
@@ -4,10 +4,10 @@
 DESIGN
 ======
 
-Kdump uses kexec to reboot to a second kernel whenever a dump needs to be taken.
-This second kernel is booted with very little memory. The first kernel reserves
-the section of memory that the second kernel uses. This ensures that on-going
-DMA from the first kernel does not corrupt the second kernel.
+Kdump uses kexec to reboot to a second kernel whenever a dump needs to be
+taken. This second kernel is booted with very little memory. The first kernel
+reserves the section of memory that the second kernel uses. This ensures that
+on-going DMA from the first kernel does not corrupt the second kernel.
 
 All the necessary information about Core image is encoded in ELF format and
 stored in reserved area of memory before crash. Physical address of start of
@@ -35,77 +35,82 @@
 SETUP
 =====
 
-1) Download http://www.xmission.com/~ebiederm/files/kexec/kexec-tools-1.101.tar.gz
-   and apply http://lse.sourceforge.net/kdump/patches/kexec-tools-1.101-kdump.patch
-   and after that build the source.
+1) Download the upstream kexec-tools userspace package from
+   http://www.xmission.com/~ebiederm/files/kexec/kexec-tools-1.101.tar.gz.
 
-2) Download and build the appropriate (2.6.13-rc1 onwards) vanilla kernel.
+   Apply the latest consolidated kdump patch on top of kexec-tools-1.101
+   from http://lse.sourceforge.net/kdump/. This arrangment has been made
+   till all the userspace patches supporting kdump are integrated with
+   upstream kexec-tools userspace.
 
+2) Download and build the appropriate (2.6.13-rc1 onwards) vanilla kernels.
    Two kernels need to be built in order to get this feature working.
+   Following are the steps to properly configure the two kernels specific
+   to kexec and kdump features:
 
-  A) First kernel:
+  A) First kernel or regular kernel:
+  ----------------------------------
    a) Enable "kexec system call" feature (in Processor type and features).
-	CONFIG_KEXEC=y
-   b) This kernel's physical load address should be the default value of
-      0x100000 (0x100000, 1 MB) (in Processor type and features).
-	CONFIG_PHYSICAL_START=0x100000
-   c) Enable "sysfs file system support" (in Pseudo filesystems).
-	CONFIG_SYSFS=y
+      CONFIG_KEXEC=y
+   b) Enable "sysfs file system support" (in Pseudo filesystems).
+      CONFIG_SYSFS=y
+   c) make
    d) Boot into first kernel with the command line parameter "crashkernel=Y@X".
       Use appropriate values for X and Y. Y denotes how much memory to reserve
-      for the second kernel, and X denotes at what physical address the reserved
-      memory section starts. For example: "crashkernel=64M@16M".
+      for the second kernel, and X denotes at what physical address the
+      reserved memory section starts. For example: "crashkernel=64M@16M".
 
-  B) Second kernel:
-   a) Enable "kernel crash dumps" feature (in Processor type and features).
-	CONFIG_CRASH_DUMP=y
-   b) Specify a suitable value for "Physical address where the kernel is
-      loaded" (in Processor type and features). Typically this value
-      should be same as X (See option d) above, e.g., 16 MB or 0x1000000.
-	CONFIG_PHYSICAL_START=0x1000000
-   c) Enable "/proc/vmcore support" (Optional, in Pseudo filesystems).
-	CONFIG_PROC_VMCORE=y
-   d) Disable SMP support and build a UP kernel (Until it is fixed).
-	CONFIG_SMP=n
-   e) Enable "Local APIC support on uniprocessors".
-	CONFIG_X86_UP_APIC=y
-   f) Enable "IO-APIC support on uniprocessors"
-	CONFIG_X86_UP_IOAPIC=y
 
-  Note:   i) Options a) and b) depend upon "Configure standard kernel features
-	     (for small systems)" (under General setup).
-	 ii) Option a) also depends on CONFIG_HIGHMEM (under Processor
-		type and features).
-	iii) Both option a) and b) are under "Processor type and features".
+  B) Second kernel or dump capture kernel:
+  ---------------------------------------
+   a) For i386 architecture enable Highmem support
+      CONFIG_HIGHMEM=y
+   b) Enable "kernel crash dumps" feature (under "Processor type and features")
+      CONFIG_CRASH_DUMP=y
+   c) Make sure a suitable value for "Physical address where the kernel is
+      loaded" (under "Processor type and features"). By default this value
+      is 0x1000000 (16MB) and it should be same as X (See option d above),
+      e.g., 16 MB or 0x1000000.
+      CONFIG_PHYSICAL_START=0x1000000
+   d) Enable "/proc/vmcore support" (Optional, under "Pseudo filesystems").
+      CONFIG_PROC_VMCORE=y
 
-3) Boot into the first kernel. You are now ready to try out kexec-based crash
-   dumps.
-
-4) Load the second kernel to be booted using:
+3) After booting to regular kernel or first kernel, load the second kernel
+   using the following command:
 
    kexec -p <second-kernel> --args-linux --elf32-core-headers
-   --append="root=<root-dev> init 1 irqpoll"
+   --append="root=<root-dev> init 1 irqpoll maxcpus=1"
 
-   Note: i) <second-kernel> has to be a vmlinux image. bzImage will not work,
-	    as of now.
-	ii) By default ELF headers are stored in ELF64 format. Option
-	    --elf32-core-headers forces generation of ELF32 headers. gdb can
-	    not open ELF64 headers on 32 bit systems. So creating ELF32
-	    headers can come handy for users who have got non-PAE systems and
-	    hence have memory less than 4GB.
-       iii) Specify "irqpoll" as command line parameter. This reduces driver
-            initialization failures in second kernel due to shared interrupts.
-        iv) <root-dev> needs to be specified in a format corresponding to
-            the root device name in the output of mount command.
-         v) If you have built the drivers required to mount root file
-            system as modules in <second-kernel>, then, specify
-            --initrd=<initrd-for-second-kernel>.
+   Notes:
+   ======
+     i) <second-kernel> has to be a vmlinux image ie uncompressed elf image.
+        bzImage will not work, as of now.
+    ii) --args-linux has to be speicfied as if kexec it loading an elf image,
+        it needs to know that the arguments supplied are of linux type.
+   iii) By default ELF headers are stored in ELF64 format to support systems
+        with more than 4GB memory. Option --elf32-core-headers forces generation
+        of ELF32 headers. The reason for this option being, as of now gdb can
+        not open vmcore file with ELF64 headers on a 32 bit systems. So ELF32
+        headers can be used if one has non-PAE systems and hence memory less
+        than 4GB.
+    iv) Specify "irqpoll" as command line parameter. This reduces driver
+         initialization failures in second kernel due to shared interrupts.
+     v) <root-dev> needs to be specified in a format corresponding to the root
+        device name in the output of mount command.
+    vi) If you have built the drivers required to mount root file system as
+        modules in <second-kernel>, then, specify
+        --initrd=<initrd-for-second-kernel>.
+   vii) Specify maxcpus=1 as, if during first kernel run, if panic happens on
+        non-boot cpus, second kernel doesn't seem to be boot up all the cpus.
+        The other option is to always built the second kernel without SMP
+        support ie CONFIG_SMP=n
 
-5) System reboots into the second kernel when a panic occurs. A module can be
-   written to force the panic or "ALT-SysRq-c" can be used initiate a crash
-   dump for testing purposes.
+4) After successfully loading the second kernel as above, if a panic occurs
+   system reboots into the second kernel. A module can be written to force
+   the panic or "ALT-SysRq-c" can be used initiate a crash dump for testing
+   purposes.
 
-6) Write out the dump file using
+5) Once the second kernel has booted, write out the dump file using
 
    cp /proc/vmcore <dump-file>
 
@@ -119,9 +124,9 @@
 
    Entire memory:  dd if=/dev/oldmem of=oldmem.001
 
+
 ANALYSIS
 ========
-
 Limited analysis can be done using gdb on the dump file copied out of
 /proc/vmcore. Use vmlinux built with -g and run
 
@@ -132,15 +137,19 @@
 
 Note: gdb cannot analyse core files generated in ELF64 format for i386.
 
+Latest "crash" (crash-4.0-2.18) as available on Dave Anderson's site
+http://people.redhat.com/~anderson/ works well with kdump format.
+
+
 TODO
 ====
-
 1) Provide a kernel pages filtering mechanism so that core file size is not
    insane on systems having huge memory banks.
-2) Modify "crash" tool to make it recognize this dump.
+2) Relocatable kernel can help in maintaining multiple kernels for crashdump
+   and same kernel as the first kernel can be used to capture the dump.
+
 
 CONTACT
 =======
-
 Vivek Goyal (vgoyal@in.ibm.com)
 Maneesh Soni (maneesh@in.ibm.com)
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 0dc848b..fe11fcc 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -475,10 +475,11 @@
 			See Documentation/block/as-iosched.txt and
 			Documentation/block/deadline-iosched.txt for details.
 
-	elfcorehdr=	[IA-32]
+	elfcorehdr=	[IA-32, X86_64]
 			Specifies physical address of start of kernel core
-			image elf header.
-			See Documentation/kdump.txt for details.
+			image elf header. Generally kexec loader will
+			pass this option to capture kernel.
+			See Documentation/kdump/kdump.txt for details.
 
 	enforcing	[SELINUX] Set initial enforcing status.
 			Format: {"0" | "1"}
@@ -832,7 +833,7 @@
 	mem=nopentium	[BUGS=IA-32] Disable usage of 4MB pages for kernel
 			memory.
 
-	memmap=exactmap	[KNL,IA-32] Enable setting of an exact
+	memmap=exactmap	[KNL,IA-32,X86_64] Enable setting of an exact
 			E820 memory map, as specified by the user.
 			Such memmap=exactmap lines can be constructed based on
 			BIOS output or other requirements. See the memmap=nn@ss
@@ -855,6 +856,49 @@
 
 	mga=		[HW,DRM]
 
+	migration_cost=
+			[KNL,SMP] debug: override scheduler migration costs
+			Format: <level-1-usecs>,<level-2-usecs>,...
+			This debugging option can be used to override the
+			default scheduler migration cost matrix. The numbers
+			are indexed by 'CPU domain distance'.
+			E.g. migration_cost=1000,2000,3000 on an SMT NUMA
+			box will set up an intra-core migration cost of
+			1 msec, an inter-core migration cost of 2 msecs,
+			and an inter-node migration cost of 3 msecs.
+
+			WARNING: using the wrong values here can break
+			scheduler performance, so it's only for scheduler
+			development purposes, not production environments.
+
+	migration_debug=
+			[KNL,SMP] migration cost auto-detect verbosity
+			Format=<0|1|2>
+			If a system's migration matrix reported at bootup
+			seems erroneous then this option can be used to
+			increase verbosity of the detection process.
+			We default to 0 (no extra messages), 1 will print
+			some more information, and 2 will be really
+			verbose (probably only useful if you also have a
+			serial console attached to the system).
+
+	migration_factor=
+			[KNL,SMP] multiply/divide migration costs by a factor
+			Format=<percent>
+			This debug option can be used to proportionally
+			increase or decrease the auto-detected migration
+			costs for all entries of the migration matrix.
+			E.g. migration_factor=150 will increase migration
+			costs by 50%. (and thus the scheduler will be less
+			eager migrating cache-hot tasks)
+			migration_factor=80 will decrease migration costs
+			by 20%. (thus the scheduler will be more eager to
+			migrate tasks)
+
+			WARNING: using the wrong values here can break
+			scheduler performance, so it's only for scheduler
+			development purposes, not production environments.
+
 	mousedev.tap_time=
 			[MOUSE] Maximum time between finger touching and
 			leaving touchpad surface for touch to be considered
diff --git a/Documentation/laptop-mode.txt b/Documentation/laptop-mode.txt
index dc4e810..f42e4c0 100644
--- a/Documentation/laptop-mode.txt
+++ b/Documentation/laptop-mode.txt
@@ -3,7 +3,7 @@
 
 Document Author: Bart Samwel (bart@samwel.tk)
 Date created: January 2, 2004
-Last modified: July 10, 2004
+Last modified: December 06, 2004
 
 Introduction
 ------------
@@ -33,7 +33,7 @@
 laptop mode will automatically be started when you're on battery. For
 your convenience, a tarball containing an installer can be downloaded at:
 
-http://www.xs4all.nl/~bsamwel/laptop_mode/tools
+http://www.xs4all.nl/~bsamwel/laptop_mode/tools/
 
 To configure laptop mode, you need to edit the configuration file, which is
 located in /etc/default/laptop-mode on Debian-based systems, or in
@@ -912,7 +912,7 @@
     exit(0);
 }
 
-int main(int ac, char **av)
+int main(int argc, char **argv)
 {
     int fd;
     char *disk = 0;
diff --git a/Documentation/locks.txt b/Documentation/locks.txt
index ce1be79..e3b402e 100644
--- a/Documentation/locks.txt
+++ b/Documentation/locks.txt
@@ -65,20 +65,3 @@
 mandatory locking only be enabled on a local filesystem as the specific need
 arises.
 
-Until an updated version of mount(8) becomes available you may have to apply
-this patch to the mount sources (based on the version distributed with Rick
-Faith's util-linux-2.5 package):
-
-*** mount.c.orig	Sat Jun  8 09:14:31 1996
---- mount.c	Sat Jun  8 09:13:02 1996
-***************
-*** 100,105 ****
---- 100,107 ----
-    { "noauto",	0, MS_NOAUTO	},	/* Can  only be mounted explicitly */
-    { "user",	0, MS_USER	},	/* Allow ordinary user to mount */
-    { "nouser",	1, MS_USER	},	/* Forbid ordinary user to mount */
-+   { "mand",	0, MS_MANDLOCK	},	/* Allow mandatory locks on this FS */
-+   { "nomand",	1, MS_MANDLOCK	},	/* Forbid mandatory locks on this FS */
-    /* add new options here */
-  #ifdef MS_NOSUB
-    { "sub",	1, MS_NOSUB	},	/* allow submounts */
diff --git a/Documentation/oops-tracing.txt b/Documentation/oops-tracing.txt
index 05960f8..2503404 100644
--- a/Documentation/oops-tracing.txt
+++ b/Documentation/oops-tracing.txt
@@ -41,11 +41,9 @@
     run a null modem to a second machine and capture the output there
     using your favourite communication program.  Minicom works well.
 
-(3) Patch the kernel with one of the crash dump patches.  These save
-    data to a floppy disk or video rom or a swap partition.  None of
-    these are standard kernel patches so you have to find and apply
-    them yourself.  Search kernel archives for kmsgdump, lkcd and
-    oops+smram.
+(3) Use Kdump (see Documentation/kdump/kdump.txt),
+    extract the kernel ring buffer from old memory with using dmesg
+    gdbmacro in Documentation/kdump/gdbmacros.txt.
 
 
 Full Information
diff --git a/Documentation/stable_kernel_rules.txt b/Documentation/stable_kernel_rules.txt
index 2c81305..e409e5d 100644
--- a/Documentation/stable_kernel_rules.txt
+++ b/Documentation/stable_kernel_rules.txt
@@ -1,58 +1,56 @@
 Everything you ever wanted to know about Linux 2.6 -stable releases.
 
-Rules on what kind of patches are accepted, and what ones are not, into
-the "-stable" tree:
+Rules on what kind of patches are accepted, and which ones are not, into the
+"-stable" tree:
 
  - It must be obviously correct and tested.
- - It can not bigger than 100 lines, with context.
+ - It can not be bigger than 100 lines, with context.
  - It must fix only one thing.
  - It must fix a real bug that bothers people (not a, "This could be a
-   problem..." type thing.)
+   problem..." type thing).
  - It must fix a problem that causes a build error (but not for things
    marked CONFIG_BROKEN), an oops, a hang, data corruption, a real
-   security issue, or some "oh, that's not good" issue.  In short,
-   something critical.
- - No "theoretical race condition" issues, unless an explanation of how
-   the race can be exploited.
+   security issue, or some "oh, that's not good" issue.  In short, something
+   critical.
+ - No "theoretical race condition" issues, unless an explanation of how the
+   race can be exploited is also provided.
  - It can not contain any "trivial" fixes in it (spelling changes,
-   whitespace cleanups, etc.)
+   whitespace cleanups, etc).
  - It must be accepted by the relevant subsystem maintainer.
- - It must follow Documentation/SubmittingPatches rules.
+ - It must follow the Documentation/SubmittingPatches rules.
 
 
 Procedure for submitting patches to the -stable tree:
 
  - Send the patch, after verifying that it follows the above rules, to
    stable@kernel.org.
- - The sender will receive an ack when the patch has been accepted into
-   the queue, or a nak if the patch is rejected.  This response might
-   take a few days, according to the developer's schedules.
- - If accepted, the patch will be added to the -stable queue, for review
-   by other developers.
+ - The sender will receive an ACK when the patch has been accepted into the
+   queue, or a NAK if the patch is rejected.  This response might take a few
+   days, according to the developer's schedules.
+ - If accepted, the patch will be added to the -stable queue, for review by
+   other developers.
  - Security patches should not be sent to this alias, but instead to the
-   documented security@kernel.org.
+   documented security@kernel.org address.
 
 
 Review cycle:
 
- - When the -stable maintainers decide for a review cycle, the patches
-   will be sent to the review committee, and the maintainer of the
-   affected area of the patch (unless the submitter is the maintainer of
-   the area) and CC: to the linux-kernel mailing list.
- - The review committee has 48 hours in which to ack or nak the patch.
+ - When the -stable maintainers decide for a review cycle, the patches will be
+   sent to the review committee, and the maintainer of the affected area of
+   the patch (unless the submitter is the maintainer of the area) and CC: to
+   the linux-kernel mailing list.
+ - The review committee has 48 hours in which to ACK or NAK the patch.
  - If the patch is rejected by a member of the committee, or linux-kernel
-   members object to the patch, bringing up issues that the maintainers
-   and members did not realize, the patch will be dropped from the
-   queue.
- - At the end of the review cycle, the acked patches will be added to
-   the latest -stable release, and a new -stable release will happen.
- - Security patches will be accepted into the -stable tree directly from
-   the security kernel team, and not go through the normal review cycle.
+   members object to the patch, bringing up issues that the maintainers and
+   members did not realize, the patch will be dropped from the queue.
+ - At the end of the review cycle, the ACKed patches will be added to the
+   latest -stable release, and a new -stable release will happen.
+ - Security patches will be accepted into the -stable tree directly from the
+   security kernel team, and not go through the normal review cycle.
    Contact the kernel security team for more details on this procedure.
 
 
 Review committe:
 
- - This will be made up of a number of kernel developers who have
-   volunteered for this task, and a few that haven't.
-
+ - This is made up of a number of kernel developers who have volunteered for
+   this task, and a few that haven't.
diff --git a/Documentation/video4linux/CARDLIST.bttv b/Documentation/video4linux/CARDLIST.bttv
index 74fb085..b72706c 100644
--- a/Documentation/video4linux/CARDLIST.bttv
+++ b/Documentation/video4linux/CARDLIST.bttv
@@ -142,3 +142,4 @@
 141 -> Asound Skyeye PCTV
 142 -> Sabrent TV-FM (bttv version)
 143 -> Hauppauge ImpactVCB (bt878)                         [0070:13eb]
+144 -> MagicTV
diff --git a/Documentation/video4linux/CARDLIST.cx88 b/Documentation/video4linux/CARDLIST.cx88
index 34b6e59..56e194f 100644
--- a/Documentation/video4linux/CARDLIST.cx88
+++ b/Documentation/video4linux/CARDLIST.cx88
@@ -19,7 +19,7 @@
  18 -> Hauppauge Nova-T DVB-T                              [0070:9002,0070:9001]
  19 -> Conexant DVB-T reference design                     [14f1:0187]
  20 -> Provideo PV259                                      [1540:2580]
- 21 -> DViCO FusionHDTV DVB-T Plus                         [18ac:db10]
+ 21 -> DViCO FusionHDTV DVB-T Plus                         [18ac:db10,18ac:db11]
  22 -> pcHDTV HD3000 HDTV                                  [7063:3000]
  23 -> digitalnow DNTV Live! DVB-T                         [17de:a8a6]
  24 -> Hauppauge WinTV 28xxx (Roslyn) models               [0070:2801]
diff --git a/Documentation/x86_64/boot-options.txt b/Documentation/x86_64/boot-options.txt
index e566aff..72ab9b9 100644
--- a/Documentation/x86_64/boot-options.txt
+++ b/Documentation/x86_64/boot-options.txt
@@ -125,7 +125,7 @@
   cpumask=MASK   only use cpus with bits set in mask
 
   additional_cpus=NUM Allow NUM more CPUs for hotplug
-		 (defaults are specified by the BIOS or half the available CPUs)
+		 (defaults are specified by the BIOS, see Documentation/x86_64/cpu-hotplug-spec)
 
 NUMA
 
diff --git a/Documentation/x86_64/cpu-hotplug-spec b/Documentation/x86_64/cpu-hotplug-spec
new file mode 100644
index 0000000..5c0fa34
--- /dev/null
+++ b/Documentation/x86_64/cpu-hotplug-spec
@@ -0,0 +1,21 @@
+Firmware support for CPU hotplug under Linux/x86-64
+---------------------------------------------------
+
+Linux/x86-64 supports CPU hotplug now. For various reasons Linux wants to
+know in advance boot time the maximum number of CPUs that could be plugged
+into the system. ACPI 3.0 currently has no official way to supply
+this information from the firmware to the operating system.
+
+In ACPI each CPU needs an LAPIC object in the MADT table (5.2.11.5 in the
+ACPI 3.0 specification).  ACPI already has the concept of disabled LAPIC
+objects by setting the Enabled bit in the LAPIC object to zero.
+
+For CPU hotplug Linux/x86-64 expects now that any possible future hotpluggable
+CPU is already available in the MADT. If the CPU is not available yet
+it should have its LAPIC Enabled bit set to 0. Linux will use the number
+of disabled LAPICs to compute the maximum number of future CPUs.
+
+In the worst case the user can overwrite this choice using a command line
+option (additional_cpus=...), but it is recommended to supply the correct
+number (or a reasonable approximation of it, with erring towards more not less)
+in the MADT to avoid manual configuration.
diff --git a/Kbuild b/Kbuild
index 7900391..95d6a00 100644
--- a/Kbuild
+++ b/Kbuild
@@ -22,8 +22,6 @@
 
 quiet_cmd_offsets = GEN     $@
 define cmd_offsets
-	mkdir -p $(dir $@); \
-	cat $< | \
 	(set -e; \
 	 echo "#ifndef __ASM_OFFSETS_H__"; \
 	 echo "#define __ASM_OFFSETS_H__"; \
@@ -34,7 +32,7 @@
 	 echo " *"; \
 	 echo " */"; \
 	 echo ""; \
-	 sed -ne $(sed-y); \
+	 sed -ne $(sed-y) $<; \
 	 echo ""; \
 	 echo "#endif" ) > $@
 endef
@@ -45,5 +43,6 @@
 	$(call if_changed_dep,cc_s_c)
 
 $(obj)/$(offsets-file): arch/$(ARCH)/kernel/asm-offsets.s Kbuild
+	$(Q)mkdir -p $(dir $@)
 	$(call cmd,offsets)
 
diff --git a/MAINTAINERS b/MAINTAINERS
index 0742016..0db72a3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -804,6 +804,7 @@
 DOCBOOK FOR DOCUMENTATION
 P:	Martin Waitz
 M:	tali@admingilde.org
+T:	git http://tali.admingilde.org/git/linux-docbook.git
 S:	Maintained
 
 DOUBLETALK DRIVER
@@ -2358,13 +2359,6 @@
 M:	nico@cam.org
 S:	Maintained
 
-SNA NETWORK LAYER
-P:	Jay Schulist
-M:	jschlst@samba.org
-L:	linux-sna@turbolinux.com
-W:	http://www.linux-sna.org
-S:	Supported
-
 SOFTWARE RAID (Multiple Disks) SUPPORT
 P:	Ingo Molnar
 M:	mingo@redhat.com
@@ -2486,7 +2480,7 @@
 M:	lethal@linux-sh.org
 P:	Kazumoto Kojima
 M:	kkojima@rr.iij4u.or.jp
-L:	linux-sh@m17n.org
+L:	linuxsh-dev@lists.sourceforge.net
 W:	http://www.linux-sh.org
 W:	http://www.m17n.org/linux-sh/
 W:	http://www.rr.iij4u.or.jp/~kkojima/linux-sh4.html
diff --git a/Makefile b/Makefile
index fb497ea..deedaf7 100644
--- a/Makefile
+++ b/Makefile
@@ -141,24 +141,6 @@
 
 export srctree objtree VPATH TOPDIR
 
-nullstring :=
-space      := $(nullstring) # end of line
-
-# Take the contents of any files called localversion* and the config
-# variable CONFIG_LOCALVERSION and append them to KERNELRELEASE. Be
-# careful not to include files twice if building in the source
-# directory. LOCALVERSION from the command line override all of this
-
-localver := $(objtree)/localversion* $(srctree)/localversion*
-localver := $(sort $(wildcard $(localver)))
-# skip backup files (containing '~')
-localver := $(foreach f, $(localver), $(if $(findstring ~, $(f)),,$(f)))
-
-LOCALVERSION = $(subst $(space),, \
-	       $(shell cat /dev/null $(localver)) \
-	       $(patsubst "%",%,$(CONFIG_LOCALVERSION)))
-
-KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)$(LOCALVERSION)
 
 # SUBARCH tells the usermode build what the underlying arch is.  That is set
 # first, and if a usermode build is happening, the "ARCH=um" on the command
@@ -353,7 +335,10 @@
 		   -ffreestanding
 AFLAGS		:= -D__ASSEMBLY__
 
-export	VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION LOCALVERSION KERNELRELEASE \
+# Read KERNELRELEASE from .kernelrelease (if it exists)
+KERNELRELEASE = $(shell cat .kernelrelease 2> /dev/null)
+
+export	VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE \
 	ARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC \
 	CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL UTS_MACHINE \
 	HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
@@ -551,26 +536,6 @@
 # images. Default is /boot, but you can set it to other values
 export	INSTALL_PATH ?= /boot
 
-# If CONFIG_LOCALVERSION_AUTO is set, we automatically perform some tests
-# and try to determine if the current source tree is a release tree, of any sort,
-# or if is a pure development tree.
-#
-# A 'release tree' is any tree with a git TAG associated
-# with it.  The primary goal of this is to make it safe for a native
-# git/CVS/SVN user to build a release tree (i.e, 2.6.9) and also to
-# continue developing against the current Linus tree, without having the Linus
-# tree overwrite the 2.6.9 tree when installed.
-#
-# Currently, only git is supported.
-# Other SCMs can edit scripts/setlocalversion and add the appropriate
-# checks as needed.
-
-
-ifdef CONFIG_LOCALVERSION_AUTO
-	localversion-auto := $(shell $(PERL) $(srctree)/scripts/setlocalversion $(srctree))
-	LOCALVERSION := $(LOCALVERSION)$(localversion-auto)
-endif
-
 #
 # INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
 # relocations required by build roots.  This is not defined in the
@@ -782,6 +747,50 @@
 $(vmlinux-dirs): prepare scripts
 	$(Q)$(MAKE) $(build)=$@
 
+# Build the kernel release string
+# The KERNELRELEASE is stored in a file named .kernelrelease
+# to be used when executing for example make install or make modules_install
+#
+# Take the contents of any files called localversion* and the config
+# variable CONFIG_LOCALVERSION and append them to KERNELRELEASE.
+# LOCALVERSION from the command line override all of this
+
+nullstring :=
+space      := $(nullstring) # end of line
+
+___localver = $(objtree)/localversion* $(srctree)/localversion*
+__localver  = $(sort $(wildcard $(___localver)))
+# skip backup files (containing '~')
+_localver = $(foreach f, $(__localver), $(if $(findstring ~, $(f)),,$(f)))
+
+localver = $(subst $(space),, \
+	   $(shell cat /dev/null $(_localver)) \
+	   $(patsubst "%",%,$(CONFIG_LOCALVERSION)))
+	       
+# If CONFIG_LOCALVERSION_AUTO is set scripts/setlocalversion is called
+# and if the SCM is know a tag from the SCM is appended.
+# The appended tag is determinded by the SCM used.
+#
+# Currently, only git is supported.
+# Other SCMs can edit scripts/setlocalversion and add the appropriate
+# checks as needed.
+ifdef CONFIG_LOCALVERSION_AUTO
+	_localver-auto = $(shell $(CONFIG_SHELL) \
+	                  $(srctree)/scripts/setlocalversion $(srctree))
+	localver-auto  = $(LOCALVERSION)$(_localver-auto)
+endif
+
+localver-full = $(localver)$(localver-auto)
+
+# Store (new) KERNELRELASE string in .kernelrelease
+kernelrelease = \
+       $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)$(localver-full)
+.kernelrelease: FORCE
+	$(Q)rm -f .kernelrelease
+	$(Q)echo $(kernelrelease) > .kernelrelease
+	$(Q)echo "  Building kernel $(kernelrelease)"
+
+
 # Things we need to do before we recursively start building the kernel
 # or the modules are listed in "prepare".
 # A multi level approach is used. prepareN is processed before prepareN-1.
@@ -798,8 +807,7 @@
 # and if so do:
 # 1) Check that make has not been executed in the kernel src $(srctree)
 # 2) Create the include2 directory, used for the second asm symlink
-
-prepare3:
+prepare3: .kernelrelease
 ifneq ($(KBUILD_SRC),)
 	@echo '  Using $(srctree) as source for kernel'
 	$(Q)if [ -f $(srctree)/.config ]; then \
@@ -984,9 +992,9 @@
 
 # Directories & files removed with 'make mrproper'
 MRPROPER_DIRS  += include/config include2
-MRPROPER_FILES += .config .config.old include/asm .version \
+MRPROPER_FILES += .config .config.old include/asm .version .old_version \
                   include/linux/autoconf.h include/linux/version.h \
-                  Module.symvers tags TAGS cscope*
+		  .kernelrelease Module.symvers tags TAGS cscope*
 
 # clean - Delete most, but leave enough to build external modules
 #
@@ -1072,6 +1080,7 @@
 	@echo  '  tags/TAGS	  - Generate tags file for editors'
 	@echo  '  cscope	  - Generate cscope index'
 	@echo  '  kernelrelease	  - Output the release version string'
+	@echo  '  kernelversion	  - Output the version stored in Makefile'
 	@echo  ''
 	@echo  'Static analysers'
 	@echo  '  buildcheck      - List dangling references to vmlinux discarded sections'
@@ -1293,6 +1302,8 @@
 
 kernelrelease:
 	@echo $(KERNELRELEASE)
+kernelversion:
+	@echo $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 
 # FIXME Should go into a make.lib or something 
 # ===========================================================================
diff --git a/arch/alpha/kernel/alpha_ksyms.c b/arch/alpha/kernel/alpha_ksyms.c
index f3e98f8..1898ea7 100644
--- a/arch/alpha/kernel/alpha_ksyms.c
+++ b/arch/alpha/kernel/alpha_ksyms.c
@@ -40,7 +40,6 @@
 #include <asm/unistd.h>
 
 extern struct hwrpb_struct *hwrpb;
-extern void dump_thread(struct pt_regs *, struct user *);
 extern spinlock_t rtc_lock;
 
 /* these are C runtime functions with special calling conventions: */
diff --git a/arch/alpha/kernel/pci-noop.c b/arch/alpha/kernel/pci-noop.c
index 9903e3a..fff5cf9 100644
--- a/arch/alpha/kernel/pci-noop.c
+++ b/arch/alpha/kernel/pci-noop.c
@@ -7,6 +7,7 @@
 #include <linux/pci.h>
 #include <linux/init.h>
 #include <linux/bootmem.h>
+#include <linux/capability.h>
 #include <linux/mm.h>
 #include <linux/errno.h>
 #include <linux/sched.h>
diff --git a/arch/alpha/kernel/process.c b/arch/alpha/kernel/process.c
index abb739b..9924fd0 100644
--- a/arch/alpha/kernel/process.c
+++ b/arch/alpha/kernel/process.c
@@ -276,7 +276,7 @@
 {
 	extern void ret_from_fork(void);
 
-	struct thread_info *childti = p->thread_info;
+	struct thread_info *childti = task_thread_info(p);
 	struct pt_regs * childregs;
 	struct switch_stack * childstack, *stack;
 	unsigned long stack_offset, settls;
@@ -285,7 +285,7 @@
 	if (!(regs->ps & 8))
 		stack_offset = (PAGE_SIZE-1) & (unsigned long) regs;
 	childregs = (struct pt_regs *)
-	  (stack_offset + PAGE_SIZE + (long) childti);
+	  (stack_offset + PAGE_SIZE + task_stack_page(p));
 		
 	*childregs = *regs;
 	settls = regs->r20;
@@ -428,30 +428,15 @@
 int
 dump_elf_task(elf_greg_t *dest, struct task_struct *task)
 {
-	struct thread_info *ti;
-	struct pt_regs *pt;
-
-	ti = task->thread_info;
-	pt = (struct pt_regs *)((unsigned long)ti + 2*PAGE_SIZE) - 1;
-
-	dump_elf_thread(dest, pt, ti);
-
+	dump_elf_thread(dest, task_pt_regs(task), task_thread_info(task));
 	return 1;
 }
 
 int
 dump_elf_task_fp(elf_fpreg_t *dest, struct task_struct *task)
 {
-	struct thread_info *ti;
-	struct pt_regs *pt;
-	struct switch_stack *sw;
-
-	ti = task->thread_info;
-	pt = (struct pt_regs *)((unsigned long)ti + 2*PAGE_SIZE) - 1;
-	sw = (struct switch_stack *)pt - 1;
-
+	struct switch_stack *sw = (struct switch_stack *)task_pt_regs(task) - 1;
 	memcpy(dest, sw->fp, 32 * 8);
-
 	return 1;
 }
 
@@ -492,8 +477,8 @@
 unsigned long
 thread_saved_pc(task_t *t)
 {
-	unsigned long base = (unsigned long)t->thread_info;
-	unsigned long fp, sp = t->thread_info->pcb.ksp;
+	unsigned long base = (unsigned long)task_stack_page(t);
+	unsigned long fp, sp = task_thread_info(t)->pcb.ksp;
 
 	if (sp > base && sp+6*8 < base + 16*1024) {
 		fp = ((unsigned long*)sp)[6];
@@ -523,7 +508,7 @@
 
 	pc = thread_saved_pc(p);
 	if (in_sched_functions(pc)) {
-		schedule_frame = ((unsigned long *)p->thread_info->pcb.ksp)[6];
+		schedule_frame = ((unsigned long *)task_thread_info(p)->pcb.ksp)[6];
 		return ((unsigned long *)schedule_frame)[12];
 	}
 	return pc;
diff --git a/arch/alpha/kernel/ptrace.c b/arch/alpha/kernel/ptrace.c
index 9969d21..0cd0605 100644
--- a/arch/alpha/kernel/ptrace.c
+++ b/arch/alpha/kernel/ptrace.c
@@ -72,6 +72,13 @@
 	REG_R0 = 0, REG_F0 = 32, REG_FPCR = 63, REG_PC = 64
 };
 
+#define PT_REG(reg) \
+  (PAGE_SIZE*2 - sizeof(struct pt_regs) + offsetof(struct pt_regs, reg))
+
+#define SW_REG(reg) \
+ (PAGE_SIZE*2 - sizeof(struct pt_regs) - sizeof(struct switch_stack) \
+  + offsetof(struct switch_stack, reg))
+
 static int regoff[] = {
 	PT_REG(	   r0), PT_REG(	   r1), PT_REG(	   r2), PT_REG(	  r3),
 	PT_REG(	   r4), PT_REG(	   r5), PT_REG(	   r6), PT_REG(	  r7),
@@ -103,14 +110,14 @@
 	unsigned long *addr;
 
 	if (regno == 30) {
-		addr = &task->thread_info->pcb.usp;
+		addr = &task_thread_info(task)->pcb.usp;
 	} else if (regno == 65) {
-		addr = &task->thread_info->pcb.unique;
+		addr = &task_thread_info(task)->pcb.unique;
 	} else if (regno == 31 || regno > 65) {
 		zero = 0;
 		addr = &zero;
 	} else {
-		addr = (void *)task->thread_info + regoff[regno];
+		addr = task_stack_page(task) + regoff[regno];
 	}
 	return addr;
 }
@@ -125,7 +132,7 @@
 	if (regno == 63) {
 		unsigned long fpcr = *get_reg_addr(task, regno);
 		unsigned long swcr
-		  = task->thread_info->ieee_state & IEEE_SW_MASK;
+		  = task_thread_info(task)->ieee_state & IEEE_SW_MASK;
 		swcr = swcr_update_status(swcr, fpcr);
 		return fpcr | swcr;
 	}
@@ -139,8 +146,8 @@
 put_reg(struct task_struct *task, unsigned long regno, unsigned long data)
 {
 	if (regno == 63) {
-		task->thread_info->ieee_state
-		  = ((task->thread_info->ieee_state & ~IEEE_SW_MASK)
+		task_thread_info(task)->ieee_state
+		  = ((task_thread_info(task)->ieee_state & ~IEEE_SW_MASK)
 		     | (data & IEEE_SW_MASK));
 		data = (data & FPCR_DYN_MASK) | ieee_swcr_to_fpcr(data);
 	}
@@ -188,35 +195,35 @@
 		 * branch (emulation can be tricky for fp branches).
 		 */
 		displ = ((s32)(insn << 11)) >> 9;
-		child->thread_info->bpt_addr[nsaved++] = pc + 4;
+		task_thread_info(child)->bpt_addr[nsaved++] = pc + 4;
 		if (displ)		/* guard against unoptimized code */
-			child->thread_info->bpt_addr[nsaved++]
+			task_thread_info(child)->bpt_addr[nsaved++]
 			  = pc + 4 + displ;
 		DBG(DBG_BPT, ("execing branch\n"));
 	} else if (op_code == 0x1a) {
 		reg_b = (insn >> 16) & 0x1f;
-		child->thread_info->bpt_addr[nsaved++] = get_reg(child, reg_b);
+		task_thread_info(child)->bpt_addr[nsaved++] = get_reg(child, reg_b);
 		DBG(DBG_BPT, ("execing jump\n"));
 	} else {
-		child->thread_info->bpt_addr[nsaved++] = pc + 4;
+		task_thread_info(child)->bpt_addr[nsaved++] = pc + 4;
 		DBG(DBG_BPT, ("execing normal insn\n"));
 	}
 
 	/* install breakpoints: */
 	for (i = 0; i < nsaved; ++i) {
-		res = read_int(child, child->thread_info->bpt_addr[i],
+		res = read_int(child, task_thread_info(child)->bpt_addr[i],
 			       (int *) &insn);
 		if (res < 0)
 			return res;
-		child->thread_info->bpt_insn[i] = insn;
+		task_thread_info(child)->bpt_insn[i] = insn;
 		DBG(DBG_BPT, ("    -> next_pc=%lx\n",
-			      child->thread_info->bpt_addr[i]));
-		res = write_int(child, child->thread_info->bpt_addr[i],
+			      task_thread_info(child)->bpt_addr[i]));
+		res = write_int(child, task_thread_info(child)->bpt_addr[i],
 				BREAKINST);
 		if (res < 0)
 			return res;
 	}
-	child->thread_info->bpt_nsaved = nsaved;
+	task_thread_info(child)->bpt_nsaved = nsaved;
 	return 0;
 }
 
@@ -227,9 +234,9 @@
 int
 ptrace_cancel_bpt(struct task_struct * child)
 {
-	int i, nsaved = child->thread_info->bpt_nsaved;
+	int i, nsaved = task_thread_info(child)->bpt_nsaved;
 
-	child->thread_info->bpt_nsaved = 0;
+	task_thread_info(child)->bpt_nsaved = 0;
 
 	if (nsaved > 2) {
 		printk("ptrace_cancel_bpt: bogus nsaved: %d!\n", nsaved);
@@ -237,8 +244,8 @@
 	}
 
 	for (i = 0; i < nsaved; ++i) {
-		write_int(child, child->thread_info->bpt_addr[i],
-			  child->thread_info->bpt_insn[i]);
+		write_int(child, task_thread_info(child)->bpt_addr[i],
+			  task_thread_info(child)->bpt_insn[i]);
 	}
 	return (nsaved != 0);
 }
@@ -355,7 +362,7 @@
 		if (!valid_signal(data))
 			break;
 		/* Mark single stepping.  */
-		child->thread_info->bpt_nsaved = -1;
+		task_thread_info(child)->bpt_nsaved = -1;
 		clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
 		child->exit_code = data;
 		wake_up_process(child);
diff --git a/arch/alpha/kernel/smp.c b/arch/alpha/kernel/smp.c
index da0be34..4b87352 100644
--- a/arch/alpha/kernel/smp.c
+++ b/arch/alpha/kernel/smp.c
@@ -302,7 +302,7 @@
 		 + hwrpb->processor_offset
 		 + cpuid * hwrpb->processor_size);
 	hwpcb = (struct pcb_struct *) cpu->hwpcb;
-	ipcb = &idle->thread_info->pcb;
+	ipcb = &task_thread_info(idle)->pcb;
 
 	/* Initialize the CPU's HWPCB to something just good enough for
 	   us to get started.  Immediately after starting, we'll swpctx
diff --git a/arch/alpha/mm/init.c b/arch/alpha/mm/init.c
index 90752f6..486d794 100644
--- a/arch/alpha/mm/init.c
+++ b/arch/alpha/mm/init.c
@@ -7,6 +7,7 @@
 /* 2.3.x zone allocator, 1999 Andrea Arcangeli <andrea@suse.de> */
 
 #include <linux/config.h>
+#include <linux/pagemap.h>
 #include <linux/signal.h>
 #include <linux/sched.h>
 #include <linux/kernel.h>
diff --git a/arch/arm/common/rtctime.c b/arch/arm/common/rtctime.c
index 00f6278..48b1e19 100644
--- a/arch/arm/common/rtctime.c
+++ b/arch/arm/common/rtctime.c
@@ -17,6 +17,7 @@
 #include <linux/proc_fs.h>
 #include <linux/miscdevice.h>
 #include <linux/spinlock.h>
+#include <linux/capability.h>
 #include <linux/device.h>
 #include <linux/mutex.h>
 
diff --git a/arch/arm/kernel/apm.c b/arch/arm/kernel/apm.c
index b9df1b7..766b6c0 100644
--- a/arch/arm/kernel/apm.c
+++ b/arch/arm/kernel/apm.c
@@ -18,6 +18,7 @@
 #include <linux/proc_fs.h>
 #include <linux/miscdevice.h>
 #include <linux/apm_bios.h>
+#include <linux/capability.h>
 #include <linux/sched.h>
 #include <linux/pm.h>
 #include <linux/device.h>
diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
index 54a21bd..4b4e4cf 100644
--- a/arch/arm/kernel/process.c
+++ b/arch/arm/kernel/process.c
@@ -342,10 +342,10 @@
 void release_thread(struct task_struct *dead_task)
 {
 #if defined(CONFIG_VFP)
-	vfp_release_thread(&dead_task->thread_info->vfpstate);
+	vfp_release_thread(&task_thread_info(dead_task)->vfpstate);
 #endif
 #if defined(CONFIG_IWMMXT)
-	iwmmxt_task_release(dead_task->thread_info);
+	iwmmxt_task_release(task_thread_info(dead_task));
 #endif
 }
 
@@ -355,10 +355,9 @@
 copy_thread(int nr, unsigned long clone_flags, unsigned long stack_start,
 	    unsigned long stk_sz, struct task_struct *p, struct pt_regs *regs)
 {
-	struct thread_info *thread = p->thread_info;
-	struct pt_regs *childregs;
+	struct thread_info *thread = task_thread_info(p);
+	struct pt_regs *childregs = task_pt_regs(p);
 
-	childregs = (void *)thread + THREAD_START_SP - sizeof(*regs);
 	*childregs = *regs;
 	childregs->ARM_r0 = 0;
 	childregs->ARM_sp = stack_start;
@@ -460,8 +459,8 @@
 	if (!p || p == current || p->state == TASK_RUNNING)
 		return 0;
 
-	stack_start = (unsigned long)(p->thread_info + 1);
-	stack_end = ((unsigned long)p->thread_info) + THREAD_SIZE;
+	stack_start = (unsigned long)end_of_stack(p);
+	stack_end = (unsigned long)task_stack_page(p) + THREAD_SIZE;
 
 	fp = thread_saved_fp(p);
 	do {
diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
index 2b84f78..e591f72b 100644
--- a/arch/arm/kernel/ptrace.c
+++ b/arch/arm/kernel/ptrace.c
@@ -55,23 +55,6 @@
 #endif
 
 /*
- * Get the address of the live pt_regs for the specified task.
- * These are saved onto the top kernel stack when the process
- * is not running.
- *
- * Note: if a user thread is execve'd from kernel space, the
- * kernel stack will not be empty on entry to the kernel, so
- * ptracing these tasks will fail.
- */
-static inline struct pt_regs *
-get_user_regs(struct task_struct *task)
-{
-	return (struct pt_regs *)
-		((unsigned long)task->thread_info + THREAD_SIZE -
-				 8 - sizeof(struct pt_regs));
-}
-
-/*
  * this routine will get a word off of the processes privileged stack.
  * the offset is how far from the base addr as stored in the THREAD.
  * this routine assumes that all the privileged stacks are in our
@@ -79,7 +62,7 @@
  */
 static inline long get_user_reg(struct task_struct *task, int offset)
 {
-	return get_user_regs(task)->uregs[offset];
+	return task_pt_regs(task)->uregs[offset];
 }
 
 /*
@@ -91,7 +74,7 @@
 static inline int
 put_user_reg(struct task_struct *task, int offset, long data)
 {
-	struct pt_regs newregs, *regs = get_user_regs(task);
+	struct pt_regs newregs, *regs = task_pt_regs(task);
 	int ret = -EINVAL;
 
 	newregs = *regs;
@@ -421,7 +404,7 @@
 	u32 insn;
 	int res;
 
-	regs = get_user_regs(child);
+	regs = task_pt_regs(child);
 	pc = instruction_pointer(regs);
 
 	if (thumb_mode(regs)) {
@@ -572,7 +555,7 @@
  */
 static int ptrace_getregs(struct task_struct *tsk, void __user *uregs)
 {
-	struct pt_regs *regs = get_user_regs(tsk);
+	struct pt_regs *regs = task_pt_regs(tsk);
 
 	return copy_to_user(uregs, regs, sizeof(struct pt_regs)) ? -EFAULT : 0;
 }
@@ -587,7 +570,7 @@
 
 	ret = -EFAULT;
 	if (copy_from_user(&newregs, uregs, sizeof(struct pt_regs)) == 0) {
-		struct pt_regs *regs = get_user_regs(tsk);
+		struct pt_regs *regs = task_pt_regs(tsk);
 
 		ret = -EINVAL;
 		if (valid_user_regs(&newregs)) {
@@ -604,7 +587,7 @@
  */
 static int ptrace_getfpregs(struct task_struct *tsk, void __user *ufp)
 {
-	return copy_to_user(ufp, &tsk->thread_info->fpstate,
+	return copy_to_user(ufp, &task_thread_info(tsk)->fpstate,
 			    sizeof(struct user_fp)) ? -EFAULT : 0;
 }
 
@@ -613,7 +596,7 @@
  */
 static int ptrace_setfpregs(struct task_struct *tsk, void __user *ufp)
 {
-	struct thread_info *thread = tsk->thread_info;
+	struct thread_info *thread = task_thread_info(tsk);
 	thread->used_cp[1] = thread->used_cp[2] = 1;
 	return copy_from_user(&thread->fpstate, ufp,
 			      sizeof(struct user_fp)) ? -EFAULT : 0;
@@ -626,7 +609,7 @@
  */
 static int ptrace_getwmmxregs(struct task_struct *tsk, void __user *ufp)
 {
-	struct thread_info *thread = tsk->thread_info;
+	struct thread_info *thread = task_thread_info(tsk);
 	void *ptr = &thread->fpstate;
 
 	if (!test_ti_thread_flag(thread, TIF_USING_IWMMXT))
@@ -643,7 +626,7 @@
  */
 static int ptrace_setwmmxregs(struct task_struct *tsk, void __user *ufp)
 {
-	struct thread_info *thread = tsk->thread_info;
+	struct thread_info *thread = task_thread_info(tsk);
 	void *ptr = &thread->fpstate;
 
 	if (!test_ti_thread_flag(thread, TIF_USING_IWMMXT))
@@ -779,7 +762,7 @@
 #endif
 
 		case PTRACE_GET_THREAD_AREA:
-			ret = put_user(child->thread_info->tp_value,
+			ret = put_user(task_thread_info(child)->tp_value,
 				       (unsigned long __user *) data);
 			break;
 
diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
index 373c095..7338948 100644
--- a/arch/arm/kernel/smp.c
+++ b/arch/arm/kernel/smp.c
@@ -114,7 +114,7 @@
 	 * We need to tell the secondary core where to find
 	 * its stack and the page tables.
 	 */
-	secondary_data.stack = (void *)idle->thread_info + THREAD_START_SP;
+	secondary_data.stack = task_stack_page(idle) + THREAD_START_SP;
 	secondary_data.pgdir = virt_to_phys(pgd);
 	wmb();
 
@@ -245,7 +245,7 @@
 	__asm__("mov	sp, %0\n"
 	"	b	secondary_start_kernel"
 		:
-		: "r" ((void *)current->thread_info + THREAD_SIZE - 8));
+		: "r" (task_stack_page(current) + THREAD_SIZE - 8));
 }
 #endif /* CONFIG_HOTPLUG_CPU */
 
diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
index c9fe6f5..93cfd3f 100644
--- a/arch/arm/kernel/traps.c
+++ b/arch/arm/kernel/traps.c
@@ -164,7 +164,7 @@
 	} else if (verify_stack(fp)) {
 		printk("invalid frame pointer 0x%08x", fp);
 		ok = 0;
-	} else if (fp < (unsigned long)(tsk->thread_info + 1))
+	} else if (fp < (unsigned long)end_of_stack(tsk))
 		printk("frame pointer underflow");
 	printk("\n");
 
@@ -210,7 +210,7 @@
 
 	if (!user_mode(regs) || in_interrupt()) {
 		dump_mem("Stack: ", regs->ARM_sp,
-			 THREAD_SIZE + (unsigned long)tsk->thread_info);
+			 THREAD_SIZE + (unsigned long)task_stack_page(tsk));
 		dump_backtrace(regs, tsk);
 		dump_instr(regs);
 	}
diff --git a/arch/arm/plat-omap/dma.c b/arch/arm/plat-omap/dma.c
index f5cc21a..a4e5ac7 100644
--- a/arch/arm/plat-omap/dma.c
+++ b/arch/arm/plat-omap/dma.c
@@ -64,7 +64,7 @@
 static spinlock_t dma_chan_lock;
 static struct omap_dma_lch dma_chan[OMAP_LOGICAL_DMA_CH_COUNT];
 
-const static u8 omap1_dma_irq[OMAP_LOGICAL_DMA_CH_COUNT] = {
+static const u8 omap1_dma_irq[OMAP_LOGICAL_DMA_CH_COUNT] = {
 	INT_DMA_CH0_6, INT_DMA_CH1_7, INT_DMA_CH2_8, INT_DMA_CH3,
 	INT_DMA_CH4, INT_DMA_CH5, INT_1610_DMA_CH6, INT_1610_DMA_CH7,
 	INT_1610_DMA_CH8, INT_1610_DMA_CH9, INT_1610_DMA_CH10,
diff --git a/arch/arm26/kernel/armksyms.c b/arch/arm26/kernel/armksyms.c
index 35514b3..811a6376c 100644
--- a/arch/arm26/kernel/armksyms.c
+++ b/arch/arm26/kernel/armksyms.c
@@ -35,7 +35,6 @@
 #include <asm/checksum.h>
 #include <asm/mach-types.h>
 
-extern void dump_thread(struct pt_regs *, struct user *);
 extern int dump_fpu(struct pt_regs *, struct user_fp_struct *);
 extern void inswb(unsigned int port, void *to, int len);
 extern void outswb(unsigned int port, const void *to, int len);
diff --git a/arch/arm26/kernel/process.c b/arch/arm26/kernel/process.c
index 15833a0..3863056 100644
--- a/arch/arm26/kernel/process.c
+++ b/arch/arm26/kernel/process.c
@@ -277,10 +277,9 @@
 copy_thread(int nr, unsigned long clone_flags, unsigned long stack_start,
 	    unsigned long unused, struct task_struct *p, struct pt_regs *regs)
 {
-	struct thread_info *thread = p->thread_info;
-	struct pt_regs *childregs;
+	struct thread_info *thread = task_thread_info(p);
+	struct pt_regs *childregs = task_pt_regs(p);
 
-	childregs = __get_user_regs(thread);
 	*childregs = *regs;
 	childregs->ARM_r0 = 0;
 	childregs->ARM_sp = stack_start;
diff --git a/arch/arm26/kernel/ptrace.c b/arch/arm26/kernel/ptrace.c
index 4e6b735..3c3371d 100644
--- a/arch/arm26/kernel/ptrace.c
+++ b/arch/arm26/kernel/ptrace.c
@@ -40,21 +40,6 @@
 #define BREAKINST_ARM	0xef9f0001
 
 /*
- * Get the address of the live pt_regs for the specified task.
- * These are saved onto the top kernel stack when the process
- * is not running.
- *
- * Note: if a user thread is execve'd from kernel space, the
- * kernel stack will not be empty on entry to the kernel, so
- * ptracing these tasks will fail.
- */
-static inline struct pt_regs *
-get_user_regs(struct task_struct *task)
-{
-	return __get_user_regs(task->thread_info);
-}
-
-/*
  * this routine will get a word off of the processes privileged stack.
  * the offset is how far from the base addr as stored in the THREAD.
  * this routine assumes that all the privileged stacks are in our
@@ -62,7 +47,7 @@
  */
 static inline long get_user_reg(struct task_struct *task, int offset)
 {
-	return get_user_regs(task)->uregs[offset];
+	return task_pt_regs(task)->uregs[offset];
 }
 
 /*
@@ -74,7 +59,7 @@
 static inline int
 put_user_reg(struct task_struct *task, int offset, long data)
 {
-	struct pt_regs newregs, *regs = get_user_regs(task);
+	struct pt_regs newregs, *regs = task_pt_regs(task);
 	int ret = -EINVAL;
 
 	newregs = *regs;
@@ -377,7 +362,7 @@
 	u32 insn;
 	int res;
 
-	regs = get_user_regs(child);
+	regs = task_pt_regs(child);
 	pc = instruction_pointer(regs);
 
 	res = read_instr(child, pc, &insn);
@@ -500,7 +485,7 @@
  */
 static int ptrace_getregs(struct task_struct *tsk, void *uregs)
 {
-	struct pt_regs *regs = get_user_regs(tsk);
+	struct pt_regs *regs = task_pt_regs(tsk);
 
 	return copy_to_user(uregs, regs, sizeof(struct pt_regs)) ? -EFAULT : 0;
 }
@@ -515,7 +500,7 @@
 
 	ret = -EFAULT;
 	if (copy_from_user(&newregs, uregs, sizeof(struct pt_regs)) == 0) {
-		struct pt_regs *regs = get_user_regs(tsk);
+		struct pt_regs *regs = task_pt_regs(tsk);
 
 		ret = -EINVAL;
 		if (valid_user_regs(&newregs)) {
@@ -532,7 +517,7 @@
  */
 static int ptrace_getfpregs(struct task_struct *tsk, void *ufp)
 {
-	return copy_to_user(ufp, &tsk->thread_info->fpstate,
+	return copy_to_user(ufp, &task_thread_info(tsk)->fpstate,
 			    sizeof(struct user_fp)) ? -EFAULT : 0;
 }
 
@@ -542,7 +527,7 @@
 static int ptrace_setfpregs(struct task_struct *tsk, void *ufp)
 {
 	set_stopped_child_used_math(tsk);
-	return copy_from_user(&tsk->thread_info->fpstate, ufp,
+	return copy_from_user(&task_threas_info(tsk)->fpstate, ufp,
 			      sizeof(struct user_fp)) ? -EFAULT : 0;
 }
 
diff --git a/arch/arm26/kernel/traps.c b/arch/arm26/kernel/traps.c
index f64f590..5847ea5 100644
--- a/arch/arm26/kernel/traps.c
+++ b/arch/arm26/kernel/traps.c
@@ -132,7 +132,7 @@
 
 /*static*/ void __dump_stack(struct task_struct *tsk, unsigned long sp)
 {
-	dump_mem("Stack: ", sp, 8192+(unsigned long)tsk->thread_info);
+	dump_mem("Stack: ", sp, 8192+(unsigned long)task_stack_page(tsk));
 }
 
 void dump_stack(void)
@@ -158,7 +158,7 @@
 	} else if (verify_stack(fp)) {
 		printk("invalid frame pointer 0x%08x", fp);
 		ok = 0;
-	} else if (fp < (unsigned long)(tsk->thread_info + 1))
+	} else if (fp < (unsigned long)end_of_stack(tsk))
 		printk("frame pointer underflow");
 	printk("\n");
 
@@ -168,7 +168,7 @@
 
 /* FIXME - this is probably wrong.. */
 void show_stack(struct task_struct *task, unsigned long *sp) {
-	dump_mem("Stack: ", (unsigned long)sp, 8192+(unsigned long)task->thread_info);
+	dump_mem("Stack: ", (unsigned long)sp, 8192+(unsigned long)task_stack_page(task));
 }
 
 DEFINE_SPINLOCK(die_lock);
@@ -187,7 +187,7 @@
 	printk("CPU: %d\n", smp_processor_id());
 	show_regs(regs);
 	printk("Process %s (pid: %d, stack limit = 0x%p)\n",
-		current->comm, current->pid, tsk->thread_info + 1);
+		current->comm, current->pid, end_of_stack(tsk));
 
 	if (!user_mode(regs) || in_interrupt()) {
 		__dump_stack(tsk, (unsigned long)(regs + 1));
diff --git a/arch/cris/arch-v10/drivers/ds1302.c b/arch/cris/arch-v10/drivers/ds1302.c
index 10795f6..b100f26 100644
--- a/arch/cris/arch-v10/drivers/ds1302.c
+++ b/arch/cris/arch-v10/drivers/ds1302.c
@@ -148,6 +148,7 @@
 #include <linux/miscdevice.h>
 #include <linux/delay.h>
 #include <linux/bcd.h>
+#include <linux/capability.h>
 
 #include <asm/uaccess.h>
 #include <asm/system.h>
diff --git a/arch/cris/arch-v10/drivers/pcf8563.c b/arch/cris/arch-v10/drivers/pcf8563.c
index f2c5574..af517c2 100644
--- a/arch/cris/arch-v10/drivers/pcf8563.c
+++ b/arch/cris/arch-v10/drivers/pcf8563.c
@@ -28,6 +28,7 @@
 #include <linux/ioctl.h>
 #include <linux/delay.h>
 #include <linux/bcd.h>
+#include <linux/capability.h>
 
 #include <asm/uaccess.h>
 #include <asm/system.h>
diff --git a/arch/cris/arch-v10/kernel/process.c b/arch/cris/arch-v10/kernel/process.c
index 69e28b4..0a675ce 100644
--- a/arch/cris/arch-v10/kernel/process.c
+++ b/arch/cris/arch-v10/kernel/process.c
@@ -79,7 +79,7 @@
  */
 unsigned long thread_saved_pc(struct task_struct *t)
 {
-	return (unsigned long)user_regs(t->thread_info)->irp;
+	return task_pt_regs(t)->irp;
 }
 
 static void kernel_thread_helper(void* dummy, int (*fn)(void *), void * arg)
@@ -128,7 +128,7 @@
 	 * remember that the task_struct doubles as the kernel stack for the task
 	 */
 
-	childregs = user_regs(p->thread_info);        
+	childregs = task_pt_regs(p);
         
 	*childregs = *regs;  /* struct copy of pt_regs */
         
diff --git a/arch/cris/arch-v10/kernel/ptrace.c b/arch/cris/arch-v10/kernel/ptrace.c
index 6cbd34a..f214f74 100644
--- a/arch/cris/arch-v10/kernel/ptrace.c
+++ b/arch/cris/arch-v10/kernel/ptrace.c
@@ -37,7 +37,7 @@
 	if (regno == PT_USP)
 		return task->thread.usp;
 	else if (regno < PT_MAX)
-		return ((unsigned long *)user_regs(task->thread_info))[regno];
+		return ((unsigned long *)task_pt_regs(task))[regno];
 	else
 		return 0;
 }
@@ -51,7 +51,7 @@
 	if (regno == PT_USP)
 		task->thread.usp = data;
 	else if (regno < PT_MAX)
-		((unsigned long *)user_regs(task->thread_info))[regno] = data;
+		((unsigned long *)task_pt_regs(task))[regno] = data;
 	else
 		return -1;
 	return 0;
diff --git a/arch/cris/arch-v32/kernel/process.c b/arch/cris/arch-v32/kernel/process.c
index 882be42..8435131 100644
--- a/arch/cris/arch-v32/kernel/process.c
+++ b/arch/cris/arch-v32/kernel/process.c
@@ -96,7 +96,7 @@
  */
 unsigned long thread_saved_pc(struct task_struct *t)
 {
-	return (unsigned long)user_regs(t->thread_info)->erp;
+	return task_pt_regs(t)->erp;
 }
 
 static void
@@ -148,7 +148,7 @@
 	 * fix it up. Note: the task_struct doubles as the kernel stack for the
 	 * task.
 	 */
-	childregs = user_regs(p->thread_info);
+	childregs = task_pt_regs(p);
 	*childregs = *regs;	/* Struct copy of pt_regs. */
         p->set_child_tid = p->clear_child_tid = NULL;
         childregs->r10 = 0;	/* Child returns 0 after a fork/clone. */
@@ -157,7 +157,7 @@
 	 * The TLS is in $mof beacuse it is the 5th argument to sys_clone.
 	 */
 	if (p->mm && (clone_flags & CLONE_SETTLS)) {
-		p->thread_info->tls = regs->mof;
+		task_thread_info(p)->tls = regs->mof;
 	}
 
 	/* Put the switch stack right below the pt_regs. */
diff --git a/arch/cris/arch-v32/kernel/ptrace.c b/arch/cris/arch-v32/kernel/ptrace.c
index 5528b83..82cf2e3 100644
--- a/arch/cris/arch-v32/kernel/ptrace.c
+++ b/arch/cris/arch-v32/kernel/ptrace.c
@@ -46,7 +46,7 @@
 	unsigned long ret;
 
 	if (regno <= PT_EDA)
-		ret = ((unsigned long *)user_regs(task->thread_info))[regno];
+		ret = ((unsigned long *)task_pt_regs(task))[regno];
 	else if (regno == PT_USP)
 		ret = task->thread.usp;
 	else if (regno == PT_PPC)
@@ -65,13 +65,13 @@
 int put_reg(struct task_struct *task, unsigned int regno, unsigned long data)
 {
 	if (regno <= PT_EDA)
-		((unsigned long *)user_regs(task->thread_info))[regno] = data;
+		((unsigned long *)task_pt_regs(task))[regno] = data;
 	else if (regno == PT_USP)
 		task->thread.usp = data;
 	else if (regno == PT_PPC) {
 		/* Write pseudo-PC to ERP only if changed. */
 		if (data != get_pseudo_pc(task))
-			((unsigned long *)user_regs(task->thread_info))[PT_ERP] = data;
+			task_pt_regs(task)->erp = data;
 	} else if (regno <= PT_MAX)
 		return put_debugreg(task->pid, regno, data);
 	else
diff --git a/arch/cris/arch-v32/kernel/smp.c b/arch/cris/arch-v32/kernel/smp.c
index 13867f4..da40d19 100644
--- a/arch/cris/arch-v32/kernel/smp.c
+++ b/arch/cris/arch-v32/kernel/smp.c
@@ -113,10 +113,10 @@
 	if (IS_ERR(idle))
 		panic("SMP: fork failed for CPU:%d", cpuid);
 
-	idle->thread_info->cpu = cpuid;
+	task_thread_info(idle)->cpu = cpuid;
 
 	/* Information to the CPU that is about to boot */
-	smp_init_current_idle_thread = idle->thread_info;
+	smp_init_current_idle_thread = task_thread_info(idle);
 	cpu_now_booting = cpuid;
 
 	/* Wait for CPU to come online */
diff --git a/arch/cris/arch-v32/mm/tlb.c b/arch/cris/arch-v32/mm/tlb.c
index b08a28b..9d75d76 100644
--- a/arch/cris/arch-v32/mm/tlb.c
+++ b/arch/cris/arch-v32/mm/tlb.c
@@ -198,9 +198,9 @@
 	per_cpu(current_pgd, cpu) = next->pgd;
 
 	/* Switch context in the MMU. */
-        if (tsk && tsk->thread_info)
+        if (tsk && task_thread_info(tsk))
         {
-          SPEC_REG_WR(SPEC_REG_PID, next->context.page_id | tsk->thread_info->tls);
+          SPEC_REG_WR(SPEC_REG_PID, next->context.page_id | task_thread_info(tsk)->tls);
         }
         else
         {
diff --git a/arch/cris/kernel/crisksyms.c b/arch/cris/kernel/crisksyms.c
index 85833d7..de39725 100644
--- a/arch/cris/kernel/crisksyms.c
+++ b/arch/cris/kernel/crisksyms.c
@@ -21,7 +21,6 @@
 #include <asm/pgtable.h>
 #include <asm/fasttimer.h>
 
-extern void dump_thread(struct pt_regs *, struct user *);
 extern unsigned long get_cmos_time(void);
 extern void __Udiv(void);
 extern void __Umod(void);
@@ -33,7 +32,6 @@
 extern void iounmap(volatile void * __iomem);
 
 /* Platform dependent support */
-EXPORT_SYMBOL(dump_thread);
 EXPORT_SYMBOL(kernel_thread);
 EXPORT_SYMBOL(get_cmos_time);
 EXPORT_SYMBOL(loops_per_usec);
diff --git a/arch/cris/kernel/process.c b/arch/cris/kernel/process.c
index 7c80afb..4ab3e8711 100644
--- a/arch/cris/kernel/process.c
+++ b/arch/cris/kernel/process.c
@@ -257,34 +257,6 @@
 {
 }
 
-/*
- * fill in the user structure for a core dump..
- */
-void dump_thread(struct pt_regs * regs, struct user * dump)
-{
-#if 0
-	int i;
-
-	/* changed the size calculations - should hopefully work better. lbt */
-	dump->magic = CMAGIC;
-	dump->start_code = 0;
-	dump->start_stack = regs->esp & ~(PAGE_SIZE - 1);
-	dump->u_tsize = ((unsigned long) current->mm->end_code) >> PAGE_SHIFT;
-	dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1))) >> PAGE_SHIFT;
-	dump->u_dsize -= dump->u_tsize;
-	dump->u_ssize = 0;
-	for (i = 0; i < 8; i++)
-		dump->u_debugreg[i] = current->debugreg[i];  
-
-	if (dump->start_stack < TASK_SIZE)
-		dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> PAGE_SHIFT;
-
-	dump->regs = *regs;
-
-	dump->u_fpvalid = dump_fpu (regs, &dump->i387);
-#endif 
-}
-
 /* Fill in the fpu structure for a core dump. */
 int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
 {
diff --git a/arch/frv/Kconfig b/arch/frv/Kconfig
index 61261b7..60a617a 100644
--- a/arch/frv/Kconfig
+++ b/arch/frv/Kconfig
@@ -6,10 +6,6 @@
 	bool
 	default y
 
-config UID16
-	bool
-	default y
-
 config RWSEM_GENERIC_SPINLOCK
 	bool
 	default y
diff --git a/arch/frv/boot/Makefile b/arch/frv/boot/Makefile
index d75e0d7..5dfc93f 100644
--- a/arch/frv/boot/Makefile
+++ b/arch/frv/boot/Makefile
@@ -57,10 +57,10 @@
 # installation
 #
 install: $(CONFIGURE) Image
-	sh ./install.sh $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) Image $(TOPDIR)/System.map "$(INSTALL_PATH)"
+	sh ./install.sh $(KERNELRELEASE) Image $(TOPDIR)/System.map "$(INSTALL_PATH)"
 
 zinstall: $(CONFIGURE) zImage
-	sh ./install.sh $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) zImage $(TOPDIR)/System.map "$(INSTALL_PATH)"
+	sh ./install.sh $(KERNELRELEASE) zImage $(TOPDIR)/System.map "$(INSTALL_PATH)"
 
 #
 # miscellany
diff --git a/arch/frv/kernel/frv_ksyms.c b/arch/frv/kernel/frv_ksyms.c
index 5f118c8..0f1c6cb 100644
--- a/arch/frv/kernel/frv_ksyms.c
+++ b/arch/frv/kernel/frv_ksyms.c
@@ -18,7 +18,6 @@
 #include <asm/hardirq.h>
 #include <asm/cacheflush.h>
 
-extern void dump_thread(struct pt_regs *, struct user *);
 extern long __memcpy_user(void *dst, const void *src, size_t count);
 extern long __memset_user(void *dst, const void *src, size_t count);
 
@@ -27,7 +26,6 @@
 EXPORT_SYMBOL(__ioremap);
 EXPORT_SYMBOL(iounmap);
 
-EXPORT_SYMBOL(dump_thread);
 EXPORT_SYMBOL(strnlen);
 EXPORT_SYMBOL(strrchr);
 EXPORT_SYMBOL(strstr);
diff --git a/arch/frv/kernel/process.c b/arch/frv/kernel/process.c
index 54a4521..0fff8a6 100644
--- a/arch/frv/kernel/process.c
+++ b/arch/frv/kernel/process.c
@@ -204,7 +204,7 @@
 
 	regs0 = __kernel_frame0_ptr;
 	childregs0 = (struct pt_regs *)
-		((unsigned long) p->thread_info + THREAD_SIZE - USER_CONTEXT_SIZE);
+		(task_stack_page(p) + THREAD_SIZE - USER_CONTEXT_SIZE);
 	childregs = childregs0;
 
 	/* set up the userspace frame (the only place that the USP is stored) */
@@ -220,7 +220,7 @@
 		*childregs = *regs;
 		childregs->sp = (unsigned long) childregs0;
 		childregs->next_frame = childregs0;
-		childregs->gr15 = (unsigned long) p->thread_info;
+		childregs->gr15 = (unsigned long) task_thread_info(p);
 		childregs->gr29 = (unsigned long) p;
 	}
 
@@ -244,28 +244,6 @@
 } /* end copy_thread() */
 
 /*
- * fill in the user structure for a core dump..
- */
-void dump_thread(struct pt_regs *regs, struct user *dump)
-{
-#if 0
-	/* changed the size calculations - should hopefully work better. lbt */
-	dump->magic = CMAGIC;
-	dump->start_code = 0;
-	dump->start_stack = user_stack(regs) & ~(PAGE_SIZE - 1);
-	dump->u_tsize = ((unsigned long) current->mm->end_code) >> PAGE_SHIFT;
-	dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1))) >> PAGE_SHIFT;
-	dump->u_dsize -= dump->u_tsize;
-	dump->u_ssize = 0;
-
-	if (dump->start_stack < TASK_SIZE)
-		dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> PAGE_SHIFT;
-
-	dump->regs = *(struct user_context *) regs;
-#endif
-}
-
-/*
  * sys_execve() executes a new program.
  */
 asmlinkage int sys_execve(char *name, char **argv, char **envp)
diff --git a/arch/h8300/kernel/gpio.c b/arch/h8300/kernel/gpio.c
index 795682b..d195568 100644
--- a/arch/h8300/kernel/gpio.c
+++ b/arch/h8300/kernel/gpio.c
@@ -122,7 +122,7 @@
 static char *port_status(int portno)
 {
 	static char result[10];
-	const static char io[2]={'I','O'};
+	static const char io[2]={'I','O'};
 	char *rp;
 	int c;
 	unsigned char used,ddr;
@@ -143,7 +143,7 @@
                           int len, int *unused_i, void *unused_v)
 {
 	int c,outlen;
-	const static char port_name[]="123456789ABCDEFGH";
+	static const char port_name[]="123456789ABCDEFGH";
 	outlen = 0;
 	for (c = 0; c < MAX_PORT; c++) {
 		if (ddrs[c] == NULL)
diff --git a/arch/h8300/kernel/h8300_ksyms.c b/arch/h8300/kernel/h8300_ksyms.c
index 5a63023..5cc76ef 100644
--- a/arch/h8300/kernel/h8300_ksyms.c
+++ b/arch/h8300/kernel/h8300_ksyms.c
@@ -22,11 +22,8 @@
 //asmlinkage long long __lshrdi3 (long long, int);
 extern char h8300_debug_device[];
 
-extern void dump_thread(struct pt_regs *, struct user *);
-
 /* platform dependent support */
 
-EXPORT_SYMBOL(dump_thread);
 EXPORT_SYMBOL(strnlen);
 EXPORT_SYMBOL(strrchr);
 EXPORT_SYMBOL(strstr);
@@ -103,10 +100,6 @@
 EXPORT_SYMBOL(__umoddi3);
 EXPORT_SYMBOL(__umodsi3);
 
-#ifdef MAGIC_ROM_PTR
-EXPORT_SYMBOL(is_in_rom);
-#endif
-
 EXPORT_SYMBOL(h8300_reserved_gpio);
 EXPORT_SYMBOL(h8300_free_gpio);
 EXPORT_SYMBOL(h8300_set_gpio_dir);
diff --git a/arch/h8300/kernel/process.c b/arch/h8300/kernel/process.c
index fe21adf..ed79ae2 100644
--- a/arch/h8300/kernel/process.c
+++ b/arch/h8300/kernel/process.c
@@ -195,7 +195,7 @@
 {
 	struct pt_regs * childregs;
 
-	childregs = ((struct pt_regs *) (THREAD_SIZE + (unsigned long) p->thread_info)) - 1;
+	childregs = (struct pt_regs *) (THREAD_SIZE + task_stack_page(p)) - 1;
 
 	*childregs = *regs;
 	childregs->retpc = (unsigned long) ret_from_fork;
@@ -208,34 +208,6 @@
 }
 
 /*
- * fill in the user structure for a core dump..
- */
-void dump_thread(struct pt_regs * regs, struct user * dump)
-{
-/* changed the size calculations - should hopefully work better. lbt */
-	dump->magic = CMAGIC;
-	dump->start_code = 0;
-	dump->start_stack = rdusp() & ~(PAGE_SIZE - 1);
-	dump->u_tsize = ((unsigned long) current->mm->end_code) >> PAGE_SHIFT;
-	dump->u_dsize = ((unsigned long) (current->mm->brk +
-					  (PAGE_SIZE-1))) >> PAGE_SHIFT;
-	dump->u_dsize -= dump->u_tsize;
-	dump->u_ssize = 0;
-
-	dump->u_ar0 = (struct user_regs_struct *)(((int)(&dump->regs)) -((int)(dump)));
-	dump->regs.er0 = regs->er0;
-	dump->regs.er1 = regs->er1;
-	dump->regs.er2 = regs->er2;
-	dump->regs.er3 = regs->er3;
-	dump->regs.er4 = regs->er4;
-	dump->regs.er5 = regs->er5;
-	dump->regs.er6 = regs->er6;
-	dump->regs.orig_er0 = regs->orig_er0;
-	dump->regs.ccr = regs->ccr;
-	dump->regs.pc  = regs->pc;
-}
-
-/*
  * sys_execve() executes a new program.
  */
 asmlinkage int sys_execve(char *name, char **argv, char **envp,int dummy,...)
diff --git a/arch/h8300/mm/memory.c b/arch/h8300/mm/memory.c
index f4ddece..81eace9 100644
--- a/arch/h8300/mm/memory.c
+++ b/arch/h8300/mm/memory.c
@@ -55,16 +55,3 @@
 	return paddr;
 }
 
-#ifdef MAGIC_ROM_PTR
-
-int is_in_rom(unsigned long addr)
-{
-	/* Anything not in operational RAM is returned as in rom! */
-	if (addr < _ramstart || addr >= _ramend)
- 		return 1;
-	else
-		return 0;
-}
-
-#endif
-
diff --git a/arch/h8300/platform/h8300h/ptrace_h8300h.c b/arch/h8300/platform/h8300h/ptrace_h8300h.c
index 6ac93c0..746b1ae 100644
--- a/arch/h8300/platform/h8300h/ptrace_h8300h.c
+++ b/arch/h8300/platform/h8300h/ptrace_h8300h.c
@@ -98,7 +98,7 @@
 		.type       = jmp, \
 	}
 
-const static struct optable optable_0[] = {
+static const struct optable optable_0[] = {
 	OPTABLE(0x00,0xff, 1,none), /* 0x00 */
 	OPTABLE(0x01,0xff,-1,none), /* 0x01 */
 	OPTABLE(0x02,0xfe, 1,none), /* 0x02-0x03 */
@@ -131,31 +131,31 @@
 	OPTABLE(0x80,0x80, 1,none), /* 0x80-0xff */
 };
 
-const static struct optable optable_1[] = {
+static const struct optable optable_1[] = {
 	OPTABLE(0x00,0xff,-3,none), /* 0x0100 */
 	OPTABLE(0x40,0xf0,-3,none), /* 0x0140-0x14f */
 	OPTABLE(0x80,0xf0, 1,none), /* 0x0180-0x018f */
 	OPTABLE(0xc0,0xc0, 2,none), /* 0x01c0-0x01ff */
 };
 
-const static struct optable optable_2[] = {
+static const struct optable optable_2[] = {
 	OPTABLE(0x00,0x20, 2,none), /* 0x6a0?/0x6a8?/0x6b0?/0x6b8? */
 	OPTABLE(0x20,0x20, 3,none), /* 0x6a2?/0x6aa?/0x6b2?/0x6ba? */
 };
 
-const static struct optable optable_3[] = {
+static const struct optable optable_3[] = {
 	OPTABLE(0x69,0xfb, 2,none), /* 0x010069/0x01006d/014069/0x01406d */
 	OPTABLE(0x6b,0xff,-4,none), /* 0x01006b/0x01406b */
 	OPTABLE(0x6f,0xff, 3,none), /* 0x01006f/0x01406f */
 	OPTABLE(0x78,0xff, 5,none), /* 0x010078/0x014078 */
 };
 
-const static struct optable optable_4[] = {
+static const struct optable optable_4[] = {
 	OPTABLE(0x00,0x78, 3,none), /* 0x0100690?/0x01006d0?/0140690/0x01406d0?/0x0100698?/0x01006d8?/0140698?/0x01406d8? */
 	OPTABLE(0x20,0x78, 4,none), /* 0x0100692?/0x01006d2?/0140692/0x01406d2?/0x010069a?/0x01006da?/014069a?/0x01406da? */
 };
 
-const static struct optables_list {
+static const struct optables_list {
 	const struct optable *ptr;
 	int size;
 } optables[] = {
diff --git a/arch/h8300/platform/h8s/ints.c b/arch/h8300/platform/h8s/ints.c
index 5441cdd..f6ed663 100644
--- a/arch/h8300/platform/h8s/ints.c
+++ b/arch/h8300/platform/h8s/ints.c
@@ -52,7 +52,7 @@
 	unsigned char bit_no;
 };
 /* ISTR = 0 */
-const static struct irq_pins irq_assign_table0[16]={
+static const struct irq_pins irq_assign_table0[16]={
         {H8300_GPIO_P5,H8300_GPIO_B0},{H8300_GPIO_P5,H8300_GPIO_B1},
 	{H8300_GPIO_P5,H8300_GPIO_B2},{H8300_GPIO_P5,H8300_GPIO_B3},
 	{H8300_GPIO_P5,H8300_GPIO_B4},{H8300_GPIO_P5,H8300_GPIO_B5},
@@ -63,7 +63,7 @@
 	{H8300_GPIO_PF,H8300_GPIO_B1},{H8300_GPIO_PF,H8300_GPIO_B2},
 };
 /* ISTR = 1 */
-const static struct irq_pins irq_assign_table1[16]={
+static const struct irq_pins irq_assign_table1[16]={
 	{H8300_GPIO_P8,H8300_GPIO_B0},{H8300_GPIO_P8,H8300_GPIO_B1},
 	{H8300_GPIO_P8,H8300_GPIO_B2},{H8300_GPIO_P8,H8300_GPIO_B3},
 	{H8300_GPIO_P8,H8300_GPIO_B4},{H8300_GPIO_P8,H8300_GPIO_B5},
diff --git a/arch/h8300/platform/h8s/ints_h8s.c b/arch/h8300/platform/h8s/ints_h8s.c
index f53de49..8268dfd 100644
--- a/arch/h8300/platform/h8s/ints_h8s.c
+++ b/arch/h8300/platform/h8s/ints_h8s.c
@@ -42,7 +42,7 @@
 	unsigned char bit_no;
 } __attribute__((aligned(1),packed));
 /* ISTR = 0 */
-const static struct irq_pins irq_assign_table0[16]={
+static const struct irq_pins irq_assign_table0[16]={
         {H8300_GPIO_P5,H8300_GPIO_B0},{H8300_GPIO_P5,H8300_GPIO_B1},
 	{H8300_GPIO_P5,H8300_GPIO_B2},{H8300_GPIO_P5,H8300_GPIO_B3},
 	{H8300_GPIO_P5,H8300_GPIO_B4},{H8300_GPIO_P5,H8300_GPIO_B5},
@@ -53,7 +53,7 @@
 	{H8300_GPIO_PF,H8300_GPIO_B1},{H8300_GPIO_PF,H8300_GPIO_B2},
 }; 
 /* ISTR = 1 */
-const static struct irq_pins irq_assign_table1[16]={
+static const struct irq_pins irq_assign_table1[16]={
 	{H8300_GPIO_P8,H8300_GPIO_B0},{H8300_GPIO_P8,H8300_GPIO_B1},
 	{H8300_GPIO_P8,H8300_GPIO_B2},{H8300_GPIO_P8,H8300_GPIO_B3},
 	{H8300_GPIO_P8,H8300_GPIO_B4},{H8300_GPIO_P8,H8300_GPIO_B5},
diff --git a/arch/i386/Kconfig b/arch/i386/Kconfig
index d849c68..d5d0df7 100644
--- a/arch/i386/Kconfig
+++ b/arch/i386/Kconfig
@@ -41,8 +41,21 @@
 	bool
 	default y
 
+config DMI
+	bool
+	default y
+
 source "init/Kconfig"
 
+config DOUBLEFAULT
+	default y
+	bool "Enable doublefault exception handler" if EMBEDDED
+	help
+          This option allows trapping of rare doublefault exceptions that
+          would otherwise cause a system to silently reboot. Disabling this
+          option saves about 4k and might cause you much additional grey
+          hair.
+
 menu "Processor type and features"
 
 choice
@@ -645,17 +658,6 @@
 
 source kernel/Kconfig.hz
 
-config PHYSICAL_START
-	hex "Physical address where the kernel is loaded" if EMBEDDED
-	default "0x100000"
-	help
-	  This gives the physical address where the kernel is loaded.
-	  Primarily used in the case of kexec on panic where the
-	  fail safe kernel needs to run at a different address than
-	  the panic-ed kernel.
-
-	  Don't change this unless you know what you are doing.
-
 config KEXEC
 	bool "kexec system call (EXPERIMENTAL)"
 	depends on EXPERIMENTAL
@@ -675,11 +677,31 @@
 
 config CRASH_DUMP
 	bool "kernel crash dumps (EXPERIMENTAL)"
-	depends on EMBEDDED
 	depends on EXPERIMENTAL
 	depends on HIGHMEM
 	help
 	  Generate crash dump after being started by kexec.
+
+config PHYSICAL_START
+	hex "Physical address where the kernel is loaded" if (EMBEDDED || CRASH_DUMP)
+
+	default "0x1000000" if CRASH_DUMP
+	default "0x100000"
+	help
+	  This gives the physical address where the kernel is loaded. Normally
+	  for regular kernels this value is 0x100000 (1MB). But in the case
+	  of kexec on panic the fail safe kernel needs to run at a different
+	  address than the panic-ed kernel. This option is used to set the load
+	  address for kernels used to capture crash dump on being kexec'ed
+	  after panic. The default value for crash dump kernels is
+	  0x1000000 (16MB). This can also be set based on the "X" value as
+	  specified in the "crashkernel=YM@XM" command line boot parameter
+	  passed to the panic-ed kernel. Typically this parameter is set as
+	  crashkernel=64M@16M. Please take a look at
+	  Documentation/kdump/kdump.txt for more details about crash dumps.
+
+	  Don't change this unless you know what you are doing.
+
 endmenu
 
 
@@ -1051,3 +1073,7 @@
 	bool
 	depends on X86_SMP || (X86_VOYAGER && SMP)
 	default y
+
+config KTIME_SCALAR
+	bool
+	default y
diff --git a/arch/i386/Makefile b/arch/i386/Makefile
index b84119f..d3c0409 100644
--- a/arch/i386/Makefile
+++ b/arch/i386/Makefile
@@ -37,7 +37,10 @@
 # CPU-specific tuning. Anything which can be shared with UML should go here.
 include $(srctree)/arch/i386/Makefile.cpu
 
-cflags-$(CONFIG_REGPARM) 	+= -mregparm=3
+# -mregparm=3 works ok on gcc-3.0 and later
+#
+cflags-$(CONFIG_REGPARM) += $(shell if [ $(call cc-version) -ge 0300 ] ; then \
+                            echo "-mregparm=3"; fi ;)
 
 # Disable unit-at-a-time mode, it makes gcc use a lot more stack
 # due to the lack of sharing of stacklots.
@@ -100,7 +103,7 @@
 boot := arch/i386/boot
 
 .PHONY: zImage bzImage compressed zlilo bzlilo \
-	zdisk bzdisk fdimage fdimage144 fdimage288 install kernel_install
+	zdisk bzdisk fdimage fdimage144 fdimage288 install
 
 all: bzImage
 
@@ -122,8 +125,7 @@
 fdimage fdimage144 fdimage288: vmlinux
 	$(Q)$(MAKE) $(build)=$(boot) BOOTIMAGE=$(KBUILD_IMAGE) $@
 
-install: vmlinux
-install kernel_install:
+install:
 	$(Q)$(MAKE) $(build)=$(boot) BOOTIMAGE=$(KBUILD_IMAGE) install
 
 archclean:
diff --git a/arch/i386/boot/Makefile b/arch/i386/boot/Makefile
index 1e71382..f136752 100644
--- a/arch/i386/boot/Makefile
+++ b/arch/i386/boot/Makefile
@@ -100,5 +100,5 @@
 	cp System.map $(INSTALL_PATH)/
 	if [ -x /sbin/lilo ]; then /sbin/lilo; else /etc/lilo/install; fi
 
-install: $(BOOTIMAGE)
-	sh $(srctree)/$(src)/install.sh $(KERNELRELEASE) $< System.map "$(INSTALL_PATH)"
+install:
+	sh $(srctree)/$(src)/install.sh $(KERNELRELEASE) $(BOOTIMAGE) System.map "$(INSTALL_PATH)"
diff --git a/arch/i386/boot/install.sh b/arch/i386/boot/install.sh
index f17b40d..5e44c73 100644
--- a/arch/i386/boot/install.sh
+++ b/arch/i386/boot/install.sh
@@ -19,6 +19,20 @@
 #   $4 - default install path (blank if root directory)
 #
 
+verify () {
+	if [ ! -f "$1" ]; then
+		echo ""                                                   1>&2
+		echo " *** Missing file: $1"                              1>&2
+		echo ' *** You need to run "make" before "make install".' 1>&2
+		echo ""                                                   1>&2
+		exit 1
+ 	fi
+}
+
+# Make sure the files actually exist
+verify "$2"
+verify "$3"
+
 # User may have a custom install script
 
 if [ -x ~/bin/${CROSS_COMPILE}installkernel ]; then exec ~/bin/${CROSS_COMPILE}installkernel "$@"; fi
diff --git a/arch/i386/boot/video.S b/arch/i386/boot/video.S
index 92f6694..2ac40c8 100644
--- a/arch/i386/boot/video.S
+++ b/arch/i386/boot/video.S
@@ -97,7 +97,6 @@
 #define PARAM_VESAPM_OFF	0x30
 #define PARAM_LFB_PAGES		0x32
 #define PARAM_VESA_ATTRIB	0x34
-#define PARAM_CAPABILITIES      0x36
 
 /* Define DO_STORE according to CONFIG_VIDEO_RETAIN */
 #ifdef CONFIG_VIDEO_RETAIN
@@ -234,10 +233,6 @@
 	movw	18(%di), %ax
 	movl	%eax, %fs:(PARAM_LFB_SIZE)
 
-# store mode capabilities
-	movl    10(%di), %eax
-	movl    %eax, %fs:(PARAM_CAPABILITIES)
-
 # switching the DAC to 8-bit is for <= 8 bpp only
 	movw	%fs:(PARAM_LFB_DEPTH), %ax
 	cmpw	$8, %ax
diff --git a/arch/i386/kernel/Makefile b/arch/i386/kernel/Makefile
index be1880b..60c3f76 100644
--- a/arch/i386/kernel/Makefile
+++ b/arch/i386/kernel/Makefile
@@ -25,6 +25,7 @@
 obj-$(CONFIG_X86_IO_APIC)	+= io_apic.o
 obj-$(CONFIG_X86_REBOOTFIXUPS)	+= reboot_fixups.o
 obj-$(CONFIG_KEXEC)		+= machine_kexec.o relocate_kernel.o crash.o
+obj-$(CONFIG_CRASH_DUMP)	+= crash_dump.o
 obj-$(CONFIG_X86_NUMAQ)		+= numaq.o
 obj-$(CONFIG_X86_SUMMIT_NUMA)	+= summit.o
 obj-$(CONFIG_KPROBES)		+= kprobes.o
diff --git a/arch/i386/kernel/acpi/boot.c b/arch/i386/kernel/acpi/boot.c
index 447fa9e..2111529 100644
--- a/arch/i386/kernel/acpi/boot.c
+++ b/arch/i386/kernel/acpi/boot.c
@@ -108,7 +108,7 @@
 	if (!phys_addr || !size)
 		return NULL;
 
-	if (phys_addr < (end_pfn_map << PAGE_SHIFT))
+	if (phys_addr+size <= (end_pfn_map << PAGE_SHIFT) + PAGE_SIZE)
 		return __va(phys_addr);
 
 	return NULL;
diff --git a/arch/i386/kernel/apic.c b/arch/i386/kernel/apic.c
index d8f94e7..acd3f1e 100644
--- a/arch/i386/kernel/apic.c
+++ b/arch/i386/kernel/apic.c
@@ -26,6 +26,7 @@
 #include <linux/kernel_stat.h>
 #include <linux/sysdev.h>
 #include <linux/cpu.h>
+#include <linux/module.h>
 
 #include <asm/atomic.h>
 #include <asm/smp.h>
@@ -37,10 +38,17 @@
 #include <asm/i8253.h>
 
 #include <mach_apic.h>
+#include <mach_ipi.h>
 
 #include "io_ports.h"
 
 /*
+ * cpu_mask that denotes the CPUs that needs timer interrupt coming in as
+ * IPIs in place of local APIC timers
+ */
+static cpumask_t timer_bcast_ipi;
+
+/*
  * Knob to control our willingness to enable the local APIC.
  */
 int enable_local_apic __initdata = 0; /* -1=force-disable, +1=force-enable */
@@ -92,10 +100,6 @@
 /* Using APIC to generate smp_local_timer_interrupt? */
 int using_apic_timer = 0;
 
-static DEFINE_PER_CPU(int, prof_multiplier) = 1;
-static DEFINE_PER_CPU(int, prof_old_multiplier) = 1;
-static DEFINE_PER_CPU(int, prof_counter) = 1;
-
 static int enabled_via_apicbase;
 
 void enable_NMI_through_LVT0 (void * dummy)
@@ -935,11 +939,16 @@
 static void __setup_APIC_LVTT(unsigned int clocks)
 {
 	unsigned int lvtt_value, tmp_value, ver;
+	int cpu = smp_processor_id();
 
 	ver = GET_APIC_VERSION(apic_read(APIC_LVR));
 	lvtt_value = APIC_LVT_TIMER_PERIODIC | LOCAL_TIMER_VECTOR;
 	if (!APIC_INTEGRATED(ver))
 		lvtt_value |= SET_APIC_TIMER_BASE(APIC_TIMER_BASE_DIV);
+
+	if (cpu_isset(cpu, timer_bcast_ipi))
+		lvtt_value |= APIC_LVT_MASKED;
+
 	apic_write_around(APIC_LVTT, lvtt_value);
 
 	/*
@@ -1072,7 +1081,7 @@
 	setup_APIC_timer(calibration_result);
 }
 
-void __devinit disable_APIC_timer(void)
+void disable_APIC_timer(void)
 {
 	if (using_apic_timer) {
 		unsigned long v;
@@ -1084,7 +1093,10 @@
 
 void enable_APIC_timer(void)
 {
-	if (using_apic_timer) {
+	int cpu = smp_processor_id();
+
+	if (using_apic_timer &&
+	    !cpu_isset(cpu, timer_bcast_ipi)) {
 		unsigned long v;
 
 		v = apic_read(APIC_LVTT);
@@ -1092,33 +1104,31 @@
 	}
 }
 
-/*
- * the frequency of the profiling timer can be changed
- * by writing a multiplier value into /proc/profile.
- */
-int setup_profiling_timer(unsigned int multiplier)
+void switch_APIC_timer_to_ipi(void *cpumask)
 {
-	int i;
+	cpumask_t mask = *(cpumask_t *)cpumask;
+	int cpu = smp_processor_id();
 
-	/*
-	 * Sanity check. [at least 500 APIC cycles should be
-	 * between APIC interrupts as a rule of thumb, to avoid
-	 * irqs flooding us]
-	 */
-	if ( (!multiplier) || (calibration_result/multiplier < 500))
-		return -EINVAL;
-
-	/* 
-	 * Set the new multiplier for each CPU. CPUs don't start using the
-	 * new values until the next timer interrupt in which they do process
-	 * accounting. At that time they also adjust their APIC timers
-	 * accordingly.
-	 */
-	for (i = 0; i < NR_CPUS; ++i)
-		per_cpu(prof_multiplier, i) = multiplier;
-
-	return 0;
+	if (cpu_isset(cpu, mask) &&
+	    !cpu_isset(cpu, timer_bcast_ipi)) {
+		disable_APIC_timer();
+		cpu_set(cpu, timer_bcast_ipi);
+	}
 }
+EXPORT_SYMBOL(switch_APIC_timer_to_ipi);
+
+void switch_ipi_to_APIC_timer(void *cpumask)
+{
+	cpumask_t mask = *(cpumask_t *)cpumask;
+	int cpu = smp_processor_id();
+
+	if (cpu_isset(cpu, mask) &&
+	    cpu_isset(cpu, timer_bcast_ipi)) {
+		cpu_clear(cpu, timer_bcast_ipi);
+		enable_APIC_timer();
+	}
+}
+EXPORT_SYMBOL(switch_ipi_to_APIC_timer);
 
 #undef APIC_DIVISOR
 
@@ -1134,32 +1144,10 @@
 
 inline void smp_local_timer_interrupt(struct pt_regs * regs)
 {
-	int cpu = smp_processor_id();
-
 	profile_tick(CPU_PROFILING, regs);
-	if (--per_cpu(prof_counter, cpu) <= 0) {
-		/*
-		 * The multiplier may have changed since the last time we got
-		 * to this point as a result of the user writing to
-		 * /proc/profile. In this case we need to adjust the APIC
-		 * timer accordingly.
-		 *
-		 * Interrupts are already masked off at this point.
-		 */
-		per_cpu(prof_counter, cpu) = per_cpu(prof_multiplier, cpu);
-		if (per_cpu(prof_counter, cpu) !=
-					per_cpu(prof_old_multiplier, cpu)) {
-			__setup_APIC_LVTT(
-					calibration_result/
-					per_cpu(prof_counter, cpu));
-			per_cpu(prof_old_multiplier, cpu) =
-						per_cpu(prof_counter, cpu);
-		}
-
 #ifdef CONFIG_SMP
-		update_process_times(user_mode_vm(regs));
+	update_process_times(user_mode_vm(regs));
 #endif
-	}
 
 	/*
 	 * We take the 'long' return path, and there every subsystem
@@ -1206,6 +1194,43 @@
 	irq_exit();
 }
 
+#ifndef CONFIG_SMP
+static void up_apic_timer_interrupt_call(struct pt_regs *regs)
+{
+	int cpu = smp_processor_id();
+
+	/*
+	 * the NMI deadlock-detector uses this.
+	 */
+	per_cpu(irq_stat, cpu).apic_timer_irqs++;
+
+	smp_local_timer_interrupt(regs);
+}
+#endif
+
+void smp_send_timer_broadcast_ipi(struct pt_regs *regs)
+{
+	cpumask_t mask;
+
+	cpus_and(mask, cpu_online_map, timer_bcast_ipi);
+	if (!cpus_empty(mask)) {
+#ifdef CONFIG_SMP
+		send_IPI_mask(mask, LOCAL_TIMER_VECTOR);
+#else
+		/*
+		 * We can directly call the apic timer interrupt handler
+		 * in UP case. Minus all irq related functions
+		 */
+		up_apic_timer_interrupt_call(regs);
+#endif
+	}
+}
+
+int setup_profiling_timer(unsigned int multiplier)
+{
+	return -EINVAL;
+}
+
 /*
  * This interrupt should _never_ happen with our APIC/SMP architecture
  */
diff --git a/arch/i386/kernel/apm.c b/arch/i386/kernel/apm.c
index 9d88271..05312a8 100644
--- a/arch/i386/kernel/apm.c
+++ b/arch/i386/kernel/apm.c
@@ -219,6 +219,7 @@
 #include <linux/sched.h>
 #include <linux/pm.h>
 #include <linux/pm_legacy.h>
+#include <linux/capability.h>
 #include <linux/device.h>
 #include <linux/kernel.h>
 #include <linux/smp.h>
diff --git a/arch/i386/kernel/cpu/amd.c b/arch/i386/kernel/cpu/amd.c
index e7697e0..333578a 100644
--- a/arch/i386/kernel/cpu/amd.c
+++ b/arch/i386/kernel/cpu/amd.c
@@ -216,6 +216,12 @@
 			c->x86_max_cores = 1;
 	}
 
+	if (cpuid_eax(0x80000000) >= 0x80000007) {
+		c->x86_power = cpuid_edx(0x80000007);
+		if (c->x86_power & (1<<8))
+			set_bit(X86_FEATURE_CONSTANT_TSC, c->x86_capability);
+	}
+
 #ifdef CONFIG_X86_HT
 	/*
 	 * On a AMD dual core setup the lower bits of the APIC id
@@ -233,6 +239,7 @@
 		       cpu, c->x86_max_cores, cpu_core_id[cpu]);
 	}
 #endif
+
 }
 
 static unsigned int amd_size_cache(struct cpuinfo_x86 * c, unsigned int size)
diff --git a/arch/i386/kernel/cpu/common.c b/arch/i386/kernel/cpu/common.c
index 1704008..15aee26 100644
--- a/arch/i386/kernel/cpu/common.c
+++ b/arch/i386/kernel/cpu/common.c
@@ -204,7 +204,10 @@
 
 /* Do minimum CPU detection early.
    Fields really needed: vendor, cpuid_level, family, model, mask, cache alignment.
-   The others are not touched to avoid unwanted side effects. */
+   The others are not touched to avoid unwanted side effects.
+
+   WARNING: this function is only called on the BP.  Don't add code here
+   that is supposed to run on all CPUs. */
 static void __init early_cpu_detect(void)
 {
 	struct cpuinfo_x86 *c = &boot_cpu_data;
@@ -236,12 +239,6 @@
 		if (cap0 & (1<<19))
 			c->x86_cache_alignment = ((misc >> 8) & 0xff) * 8;
 	}
-
-	early_intel_workaround(c);
-
-#ifdef CONFIG_X86_HT
-	phys_proc_id[smp_processor_id()] = (cpuid_ebx(1) >> 24) & 0xff;
-#endif
 }
 
 void __devinit generic_identify(struct cpuinfo_x86 * c)
@@ -289,6 +286,12 @@
 				get_model_name(c); /* Default name */
 		}
 	}
+
+	early_intel_workaround(c);
+
+#ifdef CONFIG_X86_HT
+	phys_proc_id[smp_processor_id()] = (cpuid_ebx(1) >> 24) & 0xff;
+#endif
 }
 
 static void __devinit squash_the_stupid_serial_number(struct cpuinfo_x86 *c)
diff --git a/arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c b/arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c
index 871366b..7975e79 100644
--- a/arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c
+++ b/arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c
@@ -40,8 +40,6 @@
 #include <linux/acpi.h>
 #include <acpi/processor.h>
 
-#include "speedstep-est-common.h"
-
 #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "acpi-cpufreq", msg)
 
 MODULE_AUTHOR("Paul Diefenbaugh, Dominik Brodowski");
@@ -367,6 +365,7 @@
 	unsigned int		cpu = policy->cpu;
 	struct cpufreq_acpi_io	*data;
 	unsigned int		result = 0;
+	struct cpuinfo_x86 *c = &cpu_data[policy->cpu];
 
 	union acpi_object		arg0 = {ACPI_TYPE_BUFFER};
 	u32				arg0_buf[3];
@@ -390,7 +389,7 @@
 	if (result)
 		goto err_free;
 
-	if (is_const_loops_cpu(cpu)) {
+	if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
 		acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
 	}
 
diff --git a/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c b/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c
index edb9873..9a826cd 100644
--- a/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c
+++ b/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c
@@ -35,8 +35,6 @@
 #include <asm/processor.h>
 #include <asm/cpufeature.h>
 
-#include "speedstep-est-common.h"
-
 #define PFX		"speedstep-centrino: "
 #define MAINTAINER	"Jeremy Fitzhardinge <jeremy@goop.org>"
 
@@ -493,12 +491,13 @@
 	unsigned l, h;
 	int ret;
 	int i;
+	struct cpuinfo_x86 *c = &cpu_data[policy->cpu];
 
 	/* Only Intel makes Enhanced Speedstep-capable CPUs */
 	if (cpu->x86_vendor != X86_VENDOR_INTEL || !cpu_has(cpu, X86_FEATURE_EST))
 		return -ENODEV;
 
-	if (is_const_loops_cpu(policy->cpu)) {
+	if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
 		centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
 	}
 
diff --git a/arch/i386/kernel/cpu/cpufreq/speedstep-est-common.h b/arch/i386/kernel/cpu/cpufreq/speedstep-est-common.h
deleted file mode 100644
index 5ce995c..0000000
--- a/arch/i386/kernel/cpu/cpufreq/speedstep-est-common.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Routines common for drivers handling Enhanced Speedstep Technology
- *  Copyright (C) 2004 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
- *
- *  Licensed under the terms of the GNU GPL License version 2 -- see
- *  COPYING for details.
- */
-
-static inline int is_const_loops_cpu(unsigned int cpu)
-{
-	struct cpuinfo_x86 	*c = cpu_data + cpu;
-
-	if (c->x86_vendor != X86_VENDOR_INTEL || !cpu_has(c, X86_FEATURE_EST))
-		return 0;
-
-	/*
-	 * on P-4s, the TSC runs with constant frequency independent of cpu freq
-	 * when we use EST
-	 */
-	if (c->x86 == 0xf)
-		return 1;
-
-	return 0;
-}
-
diff --git a/arch/i386/kernel/cpu/intel.c b/arch/i386/kernel/cpu/intel.c
index 5e2da70..8c01201 100644
--- a/arch/i386/kernel/cpu/intel.c
+++ b/arch/i386/kernel/cpu/intel.c
@@ -183,10 +183,13 @@
 	}
 #endif
 
-	if (c->x86 == 15) 
+	if (c->x86 == 15)
 		set_bit(X86_FEATURE_P4, c->x86_capability);
 	if (c->x86 == 6) 
 		set_bit(X86_FEATURE_P3, c->x86_capability);
+	if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
+		(c->x86 == 0x6 && c->x86_model >= 0x0e))
+		set_bit(X86_FEATURE_CONSTANT_TSC, c->x86_capability);
 }
 
 
diff --git a/arch/i386/kernel/cpu/mtrr/if.c b/arch/i386/kernel/cpu/mtrr/if.c
index cf39e20..5ac051b 100644
--- a/arch/i386/kernel/cpu/mtrr/if.c
+++ b/arch/i386/kernel/cpu/mtrr/if.c
@@ -1,5 +1,6 @@
 #include <linux/init.h>
 #include <linux/proc_fs.h>
+#include <linux/capability.h>
 #include <linux/ctype.h>
 #include <linux/module.h>
 #include <linux/seq_file.h>
diff --git a/arch/i386/kernel/cpu/proc.c b/arch/i386/kernel/cpu/proc.c
index 6d91b27..89a85af 100644
--- a/arch/i386/kernel/cpu/proc.c
+++ b/arch/i386/kernel/cpu/proc.c
@@ -29,7 +29,7 @@
 		NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 		NULL, NULL, NULL, "syscall", NULL, NULL, NULL, NULL,
 		NULL, NULL, NULL, "mp", "nx", NULL, "mmxext", NULL,
-		NULL, "fxsr_opt", NULL, NULL, NULL, "lm", "3dnowext", "3dnow",
+		NULL, "fxsr_opt", "rdtscp", NULL, NULL, "lm", "3dnowext", "3dnow",
 
 		/* Transmeta-defined */
 		"recovery", "longrun", NULL, "lrti", NULL, NULL, NULL, NULL,
@@ -40,7 +40,7 @@
 		/* Other (Linux-defined) */
 		"cxmmx", "k6_mtrr", "cyrix_arr", "centaur_mcr",
 		NULL, NULL, NULL, NULL,
-		NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+		"constant_tsc", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 		NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 		NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 
@@ -57,11 +57,21 @@
 		NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 
 		/* AMD-defined (#2) */
-		"lahf_lm", "cmp_legacy", NULL, NULL, NULL, NULL, NULL, NULL,
+		"lahf_lm", "cmp_legacy", "svm", NULL, "cr8legacy", NULL, NULL, NULL,
 		NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 		NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 		NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 	};
+	static char *x86_power_flags[] = {
+		"ts",	/* temperature sensor */
+		"fid",  /* frequency id control */
+		"vid",  /* voltage id control */
+		"ttp",  /* thermal trip */
+		"tm",
+		"stc",
+		NULL,
+		/* nothing */	/* constant_tsc - moved to flags */
+	};
 	struct cpuinfo_x86 *c = v;
 	int i, n = c - cpu_data;
 	int fpu_exception;
@@ -131,6 +141,17 @@
 		     x86_cap_flags[i] != NULL )
 			seq_printf(m, " %s", x86_cap_flags[i]);
 
+	for (i = 0; i < 32; i++)
+		if (c->x86_power & (1 << i)) {
+			if (i < ARRAY_SIZE(x86_power_flags) &&
+			    x86_power_flags[i])
+				seq_printf(m, "%s%s",
+					   x86_power_flags[i][0]?" ":"",
+					   x86_power_flags[i]);
+			else
+				seq_printf(m, " [%d]", i);
+		}
+
 	seq_printf(m, "\nbogomips\t: %lu.%02lu\n\n",
 		     c->loops_per_jiffy/(500000/HZ),
 		     (c->loops_per_jiffy/(5000/HZ)) % 100);
diff --git a/arch/i386/kernel/crash.c b/arch/i386/kernel/crash.c
index 0248e08..d49dbe8 100644
--- a/arch/i386/kernel/crash.c
+++ b/arch/i386/kernel/crash.c
@@ -25,7 +25,6 @@
 #include <mach_ipi.h>
 
 
-note_buf_t crash_notes[NR_CPUS];
 /* This keeps a track of which one is crashing cpu. */
 static int crashing_cpu;
 
@@ -72,7 +71,9 @@
 	 * squirrelled away.  ELF notes happen to provide
 	 * all of that that no need to invent something new.
 	 */
-	buf = &crash_notes[cpu][0];
+	buf = (u32*)per_cpu_ptr(crash_notes, cpu);
+	if (!buf)
+		return;
 	memset(&prstatus, 0, sizeof(prstatus));
 	prstatus.pr_pid = current->pid;
 	elf_core_copy_regs(&prstatus.pr_reg, regs);
@@ -81,51 +82,12 @@
 	final_note(buf);
 }
 
-static void crash_get_current_regs(struct pt_regs *regs)
+static void crash_save_self(struct pt_regs *regs)
 {
-	__asm__ __volatile__("movl %%ebx,%0" : "=m"(regs->ebx));
-	__asm__ __volatile__("movl %%ecx,%0" : "=m"(regs->ecx));
-	__asm__ __volatile__("movl %%edx,%0" : "=m"(regs->edx));
-	__asm__ __volatile__("movl %%esi,%0" : "=m"(regs->esi));
-	__asm__ __volatile__("movl %%edi,%0" : "=m"(regs->edi));
-	__asm__ __volatile__("movl %%ebp,%0" : "=m"(regs->ebp));
-	__asm__ __volatile__("movl %%eax,%0" : "=m"(regs->eax));
-	__asm__ __volatile__("movl %%esp,%0" : "=m"(regs->esp));
-	__asm__ __volatile__("movw %%ss, %%ax;" :"=a"(regs->xss));
-	__asm__ __volatile__("movw %%cs, %%ax;" :"=a"(regs->xcs));
-	__asm__ __volatile__("movw %%ds, %%ax;" :"=a"(regs->xds));
-	__asm__ __volatile__("movw %%es, %%ax;" :"=a"(regs->xes));
-	__asm__ __volatile__("pushfl; popl %0" :"=m"(regs->eflags));
-
-	regs->eip = (unsigned long)current_text_addr();
-}
-
-/* CPU does not save ss and esp on stack if execution is already
- * running in kernel mode at the time of NMI occurrence. This code
- * fixes it.
- */
-static void crash_setup_regs(struct pt_regs *newregs, struct pt_regs *oldregs)
-{
-	memcpy(newregs, oldregs, sizeof(*newregs));
-	newregs->esp = (unsigned long)&(oldregs->esp);
-	__asm__ __volatile__("xorl %eax, %eax;");
-	__asm__ __volatile__ ("movw %%ss, %%ax;" :"=a"(newregs->xss));
-}
-
-/* We may have saved_regs from where the error came from
- * or it is NULL if via a direct panic().
- */
-static void crash_save_self(struct pt_regs *saved_regs)
-{
-	struct pt_regs regs;
 	int cpu;
 
 	cpu = smp_processor_id();
-	if (saved_regs)
-		crash_setup_regs(&regs, saved_regs);
-	else
-		crash_get_current_regs(&regs);
-	crash_save_this_cpu(&regs, cpu);
+	crash_save_this_cpu(regs, cpu);
 }
 
 #ifdef CONFIG_SMP
@@ -144,7 +106,7 @@
 	local_irq_disable();
 
 	if (!user_mode(regs)) {
-		crash_setup_regs(&fixed_regs, regs);
+		crash_fixup_ss_esp(&fixed_regs, regs);
 		regs = &fixed_regs;
 	}
 	crash_save_this_cpu(regs, cpu);
diff --git a/arch/i386/kernel/crash_dump.c b/arch/i386/kernel/crash_dump.c
new file mode 100644
index 0000000..3f532df
--- /dev/null
+++ b/arch/i386/kernel/crash_dump.c
@@ -0,0 +1,74 @@
+/*
+ *	kernel/crash_dump.c - Memory preserving reboot related code.
+ *
+ *	Created by: Hariprasad Nellitheertha (hari@in.ibm.com)
+ *	Copyright (C) IBM Corporation, 2004. All rights reserved
+ */
+
+#include <linux/errno.h>
+#include <linux/highmem.h>
+#include <linux/crash_dump.h>
+
+#include <asm/uaccess.h>
+
+static void *kdump_buf_page;
+
+/**
+ * copy_oldmem_page - copy one page from "oldmem"
+ * @pfn: page frame number to be copied
+ * @buf: target memory address for the copy; this can be in kernel address
+ *	space or user address space (see @userbuf)
+ * @csize: number of bytes to copy
+ * @offset: offset in bytes into the page (based on pfn) to begin the copy
+ * @userbuf: if set, @buf is in user address space, use copy_to_user(),
+ *	otherwise @buf is in kernel address space, use memcpy().
+ *
+ * Copy a page from "oldmem". For this page, there is no pte mapped
+ * in the current kernel. We stitch up a pte, similar to kmap_atomic.
+ *
+ * Calling copy_to_user() in atomic context is not desirable. Hence first
+ * copying the data to a pre-allocated kernel page and then copying to user
+ * space in non-atomic context.
+ */
+ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
+                               size_t csize, unsigned long offset, int userbuf)
+{
+	void  *vaddr;
+
+	if (!csize)
+		return 0;
+
+	vaddr = kmap_atomic_pfn(pfn, KM_PTE0);
+
+	if (!userbuf) {
+		memcpy(buf, (vaddr + offset), csize);
+		kunmap_atomic(vaddr, KM_PTE0);
+	} else {
+		if (!kdump_buf_page) {
+			printk(KERN_WARNING "Kdump: Kdump buffer page not"
+				" allocated\n");
+			return -EFAULT;
+		}
+		copy_page(kdump_buf_page, vaddr);
+		kunmap_atomic(vaddr, KM_PTE0);
+		if (copy_to_user(buf, (kdump_buf_page + offset), csize))
+			return -EFAULT;
+	}
+
+	return csize;
+}
+
+static int __init kdump_buf_page_init(void)
+{
+	int ret = 0;
+
+	kdump_buf_page = kmalloc(PAGE_SIZE, GFP_KERNEL);
+	if (!kdump_buf_page) {
+		printk(KERN_WARNING "Kdump: Failed to allocate kdump buffer"
+			 " page\n");
+		ret = -ENOMEM;
+	}
+
+	return ret;
+}
+arch_initcall(kdump_buf_page_init);
diff --git a/arch/i386/kernel/dmi_scan.c b/arch/i386/kernel/dmi_scan.c
index 58516e2..6a93d75 100644
--- a/arch/i386/kernel/dmi_scan.c
+++ b/arch/i386/kernel/dmi_scan.c
@@ -4,7 +4,7 @@
 #include <linux/module.h>
 #include <linux/dmi.h>
 #include <linux/bootmem.h>
-
+#include <linux/slab.h>
 
 static char * __init dmi_string(struct dmi_header *dm, u8 s)
 {
@@ -19,7 +19,7 @@
 		}
 
 		if (*bp != 0) {
-			str = alloc_bootmem(strlen(bp) + 1);
+			str = dmi_alloc(strlen(bp) + 1);
 			if (str != NULL)
 				strcpy(str, bp);
 			else
@@ -40,7 +40,7 @@
 	u8 *buf, *data;
 	int i = 0;
 		
-	buf = bt_ioremap(base, len);
+	buf = dmi_ioremap(base, len);
 	if (buf == NULL)
 		return -1;
 
@@ -65,7 +65,7 @@
 		data += 2;
 		i++;
 	}
-	bt_iounmap(buf, len);
+	dmi_iounmap(buf, len);
 	return 0;
 }
 
@@ -112,7 +112,7 @@
 		if ((*d & 0x80) == 0)
 			continue;
 
-		dev = alloc_bootmem(sizeof(*dev));
+		dev = dmi_alloc(sizeof(*dev));
 		if (!dev) {
 			printk(KERN_ERR "dmi_save_devices: out of memory.\n");
 			break;
@@ -131,7 +131,7 @@
 	struct dmi_device *dev;
 	void * data;
 
-	data = alloc_bootmem(dm->length);
+	data = dmi_alloc(dm->length);
 	if (data == NULL) {
 		printk(KERN_ERR "dmi_save_ipmi_device: out of memory.\n");
 		return;
@@ -139,7 +139,7 @@
 
 	memcpy(data, dm, dm->length);
 
-	dev = alloc_bootmem(sizeof(*dev));
+	dev = dmi_alloc(sizeof(*dev));
 	if (!dev) {
 		printk(KERN_ERR "dmi_save_ipmi_device: out of memory.\n");
 		return;
@@ -221,7 +221,7 @@
 		}
 	}
 
-out:	printk(KERN_INFO "DMI not present.\n");
+out:	printk(KERN_INFO "DMI not present or invalid.\n");
 }
 
 
diff --git a/arch/i386/kernel/io_apic.c b/arch/i386/kernel/io_apic.c
index 7554f8f..f2dd218 100644
--- a/arch/i386/kernel/io_apic.c
+++ b/arch/i386/kernel/io_apic.c
@@ -1649,7 +1649,7 @@
 	for(apic = 0; apic < nr_ioapics; apic++) {
 		int pin;
 		/* See if any of the pins is in ExtINT mode */
-		for(pin = 0; pin < nr_ioapic_registers[i]; pin++) {
+		for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
 			struct IO_APIC_route_entry entry;
 			spin_lock_irqsave(&ioapic_lock, flags);
 			*(((int *)&entry) + 0) = io_apic_read(apic, 0x10 + 2 * pin);
diff --git a/arch/i386/kernel/ioport.c b/arch/i386/kernel/ioport.c
index b59a34d..79026f0 100644
--- a/arch/i386/kernel/ioport.c
+++ b/arch/i386/kernel/ioport.c
@@ -7,6 +7,7 @@
 
 #include <linux/sched.h>
 #include <linux/kernel.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/types.h>
 #include <linux/ioport.h>
diff --git a/arch/i386/kernel/kprobes.c b/arch/i386/kernel/kprobes.c
index 19edcd5..6483eeb 100644
--- a/arch/i386/kernel/kprobes.c
+++ b/arch/i386/kernel/kprobes.c
@@ -58,13 +58,9 @@
 
 int __kprobes arch_prepare_kprobe(struct kprobe *p)
 {
-	return 0;
-}
-
-void __kprobes arch_copy_kprobe(struct kprobe *p)
-{
 	memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
 	p->opcode = *p->addr;
+	return 0;
 }
 
 void __kprobes arch_arm_kprobe(struct kprobe *p)
@@ -81,10 +77,6 @@
 			   (unsigned long) p->addr + sizeof(kprobe_opcode_t));
 }
 
-void __kprobes arch_remove_kprobe(struct kprobe *p)
-{
-}
-
 static inline void save_previous_kprobe(struct kprobe_ctlblk *kcb)
 {
 	kcb->prev_kprobe.kp = kprobe_running();
@@ -196,6 +188,19 @@
 			kcb->kprobe_status = KPROBE_REENTER;
 			return 1;
 		} else {
+			if (regs->eflags & VM_MASK) {
+			/* We are in virtual-8086 mode. Return 0 */
+				goto no_kprobe;
+			}
+			if (*addr != BREAKPOINT_INSTRUCTION) {
+			/* The breakpoint instruction was removed by
+			 * another cpu right after we hit, no further
+			 * handling of this interrupt is appropriate
+			 */
+				regs->eip -= sizeof(kprobe_opcode_t);
+				ret = 1;
+				goto no_kprobe;
+			}
 			p = __get_cpu_var(current_kprobe);
 			if (p->break_handler && p->break_handler(p, regs)) {
 				goto ss_probe;
diff --git a/arch/i386/kernel/microcode.c b/arch/i386/kernel/microcode.c
index 165f131..d3fdf00 100644
--- a/arch/i386/kernel/microcode.c
+++ b/arch/i386/kernel/microcode.c
@@ -70,6 +70,7 @@
  */
 
 //#define DEBUG /* pr_debug */
+#include <linux/capability.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/sched.h>
@@ -165,7 +166,7 @@
 
 	wrmsr(MSR_IA32_UCODE_REV, 0, 0);
 	/* see notes above for revision 1.07.  Apparent chip bug */
-	serialize_cpu();
+	sync_core();
 	/* get the current revision from MSR 0x8B */
 	rdmsr(MSR_IA32_UCODE_REV, val[0], uci->rev);
 	pr_debug("microcode: collect_cpu_info : sig=0x%x, pf=0x%x, rev=0x%x\n",
@@ -379,7 +380,7 @@
 	wrmsr(MSR_IA32_UCODE_REV, 0, 0);
 
 	/* see notes above for revision 1.07.  Apparent chip bug */
-	serialize_cpu();
+	sync_core();
 
 	/* get the current revision from MSR 0x8B */
 	rdmsr(MSR_IA32_UCODE_REV, val[0], val[1]);
diff --git a/arch/i386/kernel/process.c b/arch/i386/kernel/process.c
index 035928f..2185377 100644
--- a/arch/i386/kernel/process.c
+++ b/arch/i386/kernel/process.c
@@ -424,18 +424,7 @@
 	struct task_struct *tsk;
 	int err;
 
-	childregs = ((struct pt_regs *) (THREAD_SIZE + (unsigned long) p->thread_info)) - 1;
-	/*
-	 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
-	 * This is necessary to guarantee that the entire "struct pt_regs"
-	 * is accessable even if the CPU haven't stored the SS/ESP registers
-	 * on the stack (interrupt gate does not save these registers
-	 * when switching to the same priv ring).
-	 * Therefore beware: accessing the xss/esp fields of the
-	 * "struct pt_regs" is possible, but they may contain the
-	 * completely wrong values.
-	 */
-	childregs = (struct pt_regs *) ((unsigned long) childregs - 8);
+	childregs = task_pt_regs(p);
 	*childregs = *regs;
 	childregs->eax = 0;
 	childregs->esp = esp;
@@ -540,12 +529,7 @@
  */
 int dump_task_regs(struct task_struct *tsk, elf_gregset_t *regs)
 {
-	struct pt_regs ptregs;
-	
-	ptregs = *(struct pt_regs *)
-		((unsigned long)tsk->thread_info +
-		/* see comments in copy_thread() about -8 */
-		THREAD_SIZE - sizeof(ptregs) - 8);
+	struct pt_regs ptregs = *task_pt_regs(tsk);
 	ptregs.xcs &= 0xffff;
 	ptregs.xds &= 0xffff;
 	ptregs.xes &= 0xffff;
@@ -601,8 +585,8 @@
 	 * gcc should eliminate the ->thread_info dereference if
 	 * has_secure_computing returns 0 at compile time (SECCOMP=n).
 	 */
-	prev = prev_p->thread_info;
-	next = next_p->thread_info;
+	prev = task_thread_info(prev_p);
+	next = task_thread_info(next_p);
 
 	if (has_secure_computing(prev) || has_secure_computing(next)) {
 		/* slow path here */
@@ -787,7 +771,7 @@
 	int count = 0;
 	if (!p || p == current || p->state == TASK_RUNNING)
 		return 0;
-	stack_page = (unsigned long)p->thread_info;
+	stack_page = (unsigned long)task_stack_page(p);
 	esp = p->thread.esp;
 	if (!stack_page || esp < stack_page || esp > top_esp+stack_page)
 		return 0;
diff --git a/arch/i386/kernel/reboot.c b/arch/i386/kernel/reboot.c
index 2fa5803..d207242 100644
--- a/arch/i386/kernel/reboot.c
+++ b/arch/i386/kernel/reboot.c
@@ -12,6 +12,7 @@
 #include <linux/efi.h>
 #include <linux/dmi.h>
 #include <linux/ctype.h>
+#include <linux/pm.h>
 #include <asm/uaccess.h>
 #include <asm/apic.h>
 #include <asm/desc.h>
@@ -355,10 +356,10 @@
 
 void machine_power_off(void)
 {
-	machine_shutdown();
-
-	if (pm_power_off)
+	if (pm_power_off) {
+		machine_shutdown();
 		pm_power_off();
+	}
 }
 
 
diff --git a/arch/i386/kernel/setup.c b/arch/i386/kernel/setup.c
index 27c956d..51e513b 100644
--- a/arch/i386/kernel/setup.c
+++ b/arch/i386/kernel/setup.c
@@ -45,6 +45,7 @@
 #include <linux/nodemask.h>
 #include <linux/kexec.h>
 #include <linux/crash_dump.h>
+#include <linux/dmi.h>
 
 #include <video/edid.h>
 
@@ -146,7 +147,6 @@
 struct e820map e820;
 
 extern void early_cpu_init(void);
-extern void dmi_scan_machine(void);
 extern void generic_apic_probe(char *);
 extern int root_mountflags;
 
@@ -898,7 +898,7 @@
 			}
 		}
 #endif
-#ifdef CONFIG_CRASH_DUMP
+#ifdef CONFIG_PROC_VMCORE
 		/* elfcorehdr= specifies the location of elf core header
 		 * stored by the crashed kernel.
 		 */
@@ -1584,7 +1584,7 @@
 		if (s) {
 			extern void setup_early_printk(char *);
 
-			setup_early_printk(s);
+			setup_early_printk(strchr(s, '=') + 1);
 			printk("early console enabled\n");
 		}
 	}
diff --git a/arch/i386/kernel/smpboot.c b/arch/i386/kernel/smpboot.c
index b3c2e2c..255adb4 100644
--- a/arch/i386/kernel/smpboot.c
+++ b/arch/i386/kernel/smpboot.c
@@ -875,8 +875,7 @@
 		/* initialize thread_struct.  we really want to avoid destroy
 		 * idle tread
 		 */
-		idle->thread.esp = (unsigned long)(((struct pt_regs *)
-			(THREAD_SIZE + (unsigned long) idle->thread_info)) - 1);
+		idle->thread.esp = (unsigned long)task_pt_regs(idle);
 		init_idle(idle, cpu);
 		return idle;
 	}
@@ -1096,6 +1095,7 @@
 			cachesize = 16; /* Pentiums, 2x8kB cache */
 			bandwidth = 100;
 		}
+		max_cache_size = cachesize * 1024;
 	}
 }
 
diff --git a/arch/i386/kernel/time.c b/arch/i386/kernel/time.c
index 41c5b2d..a14d594 100644
--- a/arch/i386/kernel/time.c
+++ b/arch/i386/kernel/time.c
@@ -302,6 +302,12 @@
 	do_timer_interrupt(irq, regs);
 
 	write_sequnlock(&xtime_lock);
+
+#ifdef CONFIG_X86_LOCAL_APIC
+	if (using_apic_timer)
+		smp_send_timer_broadcast_ipi(regs);
+#endif
+
 	return IRQ_HANDLED;
 }
 
diff --git a/arch/i386/kernel/traps.c b/arch/i386/kernel/traps.c
index 53ad954e..b9f0030 100644
--- a/arch/i386/kernel/traps.c
+++ b/arch/i386/kernel/traps.c
@@ -120,7 +120,7 @@
 #ifdef	CONFIG_FRAME_POINTER
 	while (valid_stack_ptr(tinfo, (void *)ebp)) {
 		addr = *(unsigned long *)(ebp + 4);
-		printk(" [<%08lx>] ", addr);
+		printk(KERN_EMERG " [<%08lx>] ", addr);
 		print_symbol("%s", addr);
 		printk("\n");
 		ebp = *(unsigned long *)ebp;
@@ -129,7 +129,7 @@
 	while (valid_stack_ptr(tinfo, stack)) {
 		addr = *stack++;
 		if (__kernel_text_address(addr)) {
-			printk(" [<%08lx>]", addr);
+			printk(KERN_EMERG " [<%08lx>]", addr);
 			print_symbol(" %s", addr);
 			printk("\n");
 		}
@@ -161,7 +161,7 @@
 		stack = (unsigned long*)context->previous_esp;
 		if (!stack)
 			break;
-		printk(" =======================\n");
+		printk(KERN_EMERG " =======================\n");
 	}
 }
 
@@ -178,14 +178,15 @@
 	}
 
 	stack = esp;
+	printk(KERN_EMERG);
 	for(i = 0; i < kstack_depth_to_print; i++) {
 		if (kstack_end(stack))
 			break;
 		if (i && ((i % 8) == 0))
-			printk("\n       ");
+			printk("\n" KERN_EMERG "       ");
 		printk("%08lx ", *stack++);
 	}
-	printk("\nCall Trace:\n");
+	printk("\n" KERN_EMERG "Call Trace:\n");
 	show_trace(task, esp);
 }
 
@@ -216,18 +217,18 @@
 		ss = regs->xss & 0xffff;
 	}
 	print_modules();
-	printk("CPU:    %d\nEIP:    %04x:[<%08lx>]    %s VLI\nEFLAGS: %08lx"
-			"   (%s) \n",
+	printk(KERN_EMERG "CPU:    %d\nEIP:    %04x:[<%08lx>]    %s VLI\n"
+			"EFLAGS: %08lx   (%s) \n",
 		smp_processor_id(), 0xffff & regs->xcs, regs->eip,
 		print_tainted(), regs->eflags, system_utsname.release);
-	print_symbol("EIP is at %s\n", regs->eip);
-	printk("eax: %08lx   ebx: %08lx   ecx: %08lx   edx: %08lx\n",
+	print_symbol(KERN_EMERG "EIP is at %s\n", regs->eip);
+	printk(KERN_EMERG "eax: %08lx   ebx: %08lx   ecx: %08lx   edx: %08lx\n",
 		regs->eax, regs->ebx, regs->ecx, regs->edx);
-	printk("esi: %08lx   edi: %08lx   ebp: %08lx   esp: %08lx\n",
+	printk(KERN_EMERG "esi: %08lx   edi: %08lx   ebp: %08lx   esp: %08lx\n",
 		regs->esi, regs->edi, regs->ebp, esp);
-	printk("ds: %04x   es: %04x   ss: %04x\n",
+	printk(KERN_EMERG "ds: %04x   es: %04x   ss: %04x\n",
 		regs->xds & 0xffff, regs->xes & 0xffff, ss);
-	printk("Process %s (pid: %d, threadinfo=%p task=%p)",
+	printk(KERN_EMERG "Process %s (pid: %d, threadinfo=%p task=%p)",
 		current->comm, current->pid, current_thread_info(), current);
 	/*
 	 * When in-kernel, we also print out the stack and code at the
@@ -236,10 +237,10 @@
 	if (in_kernel) {
 		u8 __user *eip;
 
-		printk("\nStack: ");
+		printk("\n" KERN_EMERG "Stack: ");
 		show_stack(NULL, (unsigned long*)esp);
 
-		printk("Code: ");
+		printk(KERN_EMERG "Code: ");
 
 		eip = (u8 __user *)regs->eip - 43;
 		for (i = 0; i < 64; i++, eip++) {
@@ -280,15 +281,15 @@
 		(unsigned long)file < PAGE_OFFSET || __get_user(c, file))
 		file = "<bad filename>";
 
-	printk("------------[ cut here ]------------\n");
-	printk(KERN_ALERT "kernel BUG at %s:%d!\n", file, line);
+	printk(KERN_EMERG "------------[ cut here ]------------\n");
+	printk(KERN_EMERG "kernel BUG at %s:%d!\n", file, line);
 
 no_bug:
 	return;
 
 	/* Here we know it was a BUG but file-n-line is unavailable */
 bug:
-	printk("Kernel BUG\n");
+	printk(KERN_EMERG "Kernel BUG\n");
 }
 
 /* This is gone through when something in the kernel
@@ -321,16 +322,20 @@
 	if (++die.lock_owner_depth < 3) {
 		int nl = 0;
 		handle_BUG(regs);
-		printk(KERN_ALERT "%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter);
+		printk(KERN_EMERG "%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter);
 #ifdef CONFIG_PREEMPT
-		printk("PREEMPT ");
+		printk(KERN_EMERG "PREEMPT ");
 		nl = 1;
 #endif
 #ifdef CONFIG_SMP
+		if (!nl)
+			printk(KERN_EMERG);
 		printk("SMP ");
 		nl = 1;
 #endif
 #ifdef CONFIG_DEBUG_PAGEALLOC
+		if (!nl)
+			printk(KERN_EMERG);
 		printk("DEBUG_PAGEALLOC");
 		nl = 1;
 #endif
@@ -339,7 +344,7 @@
 	notify_die(DIE_OOPS, (char *)str, regs, err, 255, SIGSEGV);
 		show_registers(regs);
   	} else
-		printk(KERN_ERR "Recursive die() failure, output suppressed\n");
+		printk(KERN_EMERG "Recursive die() failure, output suppressed\n");
 
 	bust_spinlocks(0);
 	die.lock_owner = -1;
@@ -527,8 +532,10 @@
 
 static void mem_parity_error(unsigned char reason, struct pt_regs * regs)
 {
-	printk("Uhhuh. NMI received. Dazed and confused, but trying to continue\n");
-	printk("You probably have a hardware problem with your RAM chips\n");
+	printk(KERN_EMERG "Uhhuh. NMI received. Dazed and confused, but trying "
+			"to continue\n");
+	printk(KERN_EMERG "You probably have a hardware problem with your RAM "
+			"chips\n");
 
 	/* Clear and disable the memory parity error line. */
 	clear_mem_error(reason);
@@ -538,7 +545,7 @@
 {
 	unsigned long i;
 
-	printk("NMI: IOCK error (debug interrupt?)\n");
+	printk(KERN_EMERG "NMI: IOCK error (debug interrupt?)\n");
 	show_registers(regs);
 
 	/* Re-enable the IOCK line, wait for a few seconds */
@@ -580,11 +587,11 @@
 	* to get a message out.
 	*/
 	bust_spinlocks(1);
-	printk(msg);
+	printk(KERN_EMERG "%s", msg);
 	printk(" on CPU%d, eip %08lx, registers:\n",
 		smp_processor_id(), regs->eip);
 	show_registers(regs);
-	printk("console shuts up ...\n");
+	printk(KERN_EMERG "console shuts up ...\n");
 	console_silent();
 	spin_unlock(&nmi_print_lock);
 	bust_spinlocks(0);
@@ -990,8 +997,8 @@
 
 asmlinkage void math_emulate(long arg)
 {
-	printk("math-emulation not enabled and no coprocessor found.\n");
-	printk("killing %s.\n",current->comm);
+	printk(KERN_EMERG "math-emulation not enabled and no coprocessor found.\n");
+	printk(KERN_EMERG "killing %s.\n",current->comm);
 	force_sig(SIGFPE,current);
 	schedule();
 }
diff --git a/arch/i386/kernel/vm86.c b/arch/i386/kernel/vm86.c
index fc19935..0c90ae5 100644
--- a/arch/i386/kernel/vm86.c
+++ b/arch/i386/kernel/vm86.c
@@ -30,6 +30,7 @@
  *
  */
 
+#include <linux/capability.h>
 #include <linux/config.h>
 #include <linux/errno.h>
 #include <linux/interrupt.h>
@@ -310,7 +311,7 @@
 		"movl %1,%%ebp\n\t"
 		"jmp resume_userspace"
 		: /* no outputs */
-		:"r" (&info->regs), "r" (tsk->thread_info) : "ax");
+		:"r" (&info->regs), "r" (task_thread_info(tsk)) : "ax");
 	/* we never return here */
 }
 
diff --git a/arch/i386/mm/pageattr.c b/arch/i386/mm/pageattr.c
index e8a5355..d0cadb3 100644
--- a/arch/i386/mm/pageattr.c
+++ b/arch/i386/mm/pageattr.c
@@ -224,7 +224,7 @@
 		return;
 	if (!enable)
 		mutex_debug_check_no_locks_freed(page_address(page),
-						 page_address(page+numpages));
+						 numpages * PAGE_SIZE);
 
 	/* the return value is ignored - the calls cannot fail,
 	 * large pages are disabled at boot time.
diff --git a/arch/ia64/Makefile b/arch/ia64/Makefile
index 57b047c..f722e1a 100644
--- a/arch/ia64/Makefile
+++ b/arch/ia64/Makefile
@@ -25,7 +25,6 @@
 		   -falign-functions=32 -frename-registers -fno-optimize-sibling-calls
 CFLAGS_KERNEL	:= -mconstant-gp
 
-GCC_VERSION     := $(call cc-version)
 GAS_STATUS	= $(shell $(srctree)/arch/ia64/scripts/check-gas "$(CC)" "$(OBJDUMP)")
 CPPFLAGS += $(shell $(srctree)/arch/ia64/scripts/toolchain-flags "$(CC)" "$(OBJDUMP)" "$(READELF)")
 
@@ -37,7 +36,7 @@
 		ftp://ftp.hpl.hp.com/pub/linux-ia64/gas-030124.tar.gz)
 endif
 
-ifeq ($(GCC_VERSION),0304)
+ifeq ($(call cc-version),0304)
 	cflags-$(CONFIG_ITANIUM)	+= -mtune=merced
 	cflags-$(CONFIG_MCKINLEY)	+= -mtune=mckinley
 endif
diff --git a/arch/ia64/hp/sim/simserial.c b/arch/ia64/hp/sim/simserial.c
index 19ee635..a346e18 100644
--- a/arch/ia64/hp/sim/simserial.c
+++ b/arch/ia64/hp/sim/simserial.c
@@ -26,6 +26,7 @@
 #include <linux/fcntl.h>
 #include <linux/mm.h>
 #include <linux/slab.h>
+#include <linux/capability.h>
 #include <linux/console.h>
 #include <linux/module.h>
 #include <linux/serial.h>
diff --git a/arch/ia64/ia32/Makefile b/arch/ia64/ia32/Makefile
index 2ed90da..61cb60a 100644
--- a/arch/ia64/ia32/Makefile
+++ b/arch/ia64/ia32/Makefile
@@ -2,11 +2,9 @@
 # Makefile for the ia32 kernel emulation subsystem.
 #
 
-obj-y := ia32_entry.o sys_ia32.o ia32_ioctl.o ia32_signal.o \
+obj-y := ia32_entry.o sys_ia32.o ia32_signal.o \
 	 ia32_support.o ia32_traps.o binfmt_elf32.o ia32_ldt.o
 
-CFLAGS_ia32_ioctl.o += -Ifs/
-
 # Don't let GCC uses f16-f31 so that save_ia32_fpstate_live() and
 # restore_ia32_fpstate_live() can be sure the live register contain user-level state.
 CFLAGS_ia32_signal.o += -mfixed-range=f16-f31
diff --git a/arch/ia64/ia32/elfcore32.h b/arch/ia64/ia32/elfcore32.h
index b73b8b6..a47f63b 100644
--- a/arch/ia64/ia32/elfcore32.h
+++ b/arch/ia64/ia32/elfcore32.h
@@ -95,8 +95,7 @@
 static inline int elf_core_copy_task_regs(struct task_struct *t,
 					  elf_gregset_t* elfregs)
 {
-	struct pt_regs *pp = ia64_task_regs(t);
-	ELF_CORE_COPY_REGS((*elfregs), pp);
+	ELF_CORE_COPY_REGS((*elfregs), task_pt_regs(t));
 	return 1;
 }
 
diff --git a/arch/ia64/ia32/ia32_entry.S b/arch/ia64/ia32/ia32_entry.S
index 494fad6..95fe044 100644
--- a/arch/ia64/ia32/ia32_entry.S
+++ b/arch/ia64/ia32/ia32_entry.S
@@ -469,7 +469,7 @@
 	data8 sys32_epoll_wait
 	data8 sys_remap_file_pages
 	data8 sys_set_tid_address
- 	data8 sys32_timer_create
+ 	data8 compat_sys_timer_create
  	data8 compat_sys_timer_settime	/* 260 */
  	data8 compat_sys_timer_gettime
  	data8 sys_timer_getoverrun
diff --git a/arch/ia64/ia32/ia32_ioctl.c b/arch/ia64/ia32/ia32_ioctl.c
deleted file mode 100644
index 8873939..0000000
--- a/arch/ia64/ia32/ia32_ioctl.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * IA32 Architecture-specific ioctl shim code
- *
- * Copyright (C) 2000 VA Linux Co
- * Copyright (C) 2000 Don Dugger <n0ano@valinux.com>
- * Copyright (C) 2001-2003 Hewlett-Packard Co
- *	David Mosberger-Tang <davidm@hpl.hp.com>
- */
-
-#include <linux/signal.h>	/* argh, msdos_fs.h isn't self-contained... */
-#include <linux/syscalls.h>
-#include "ia32priv.h"
-  
-#define	INCLUDES
-#include "compat_ioctl.c"
-
-#define IOCTL_NR(a)	((a) & ~(_IOC_SIZEMASK << _IOC_SIZESHIFT))
-
-#define DO_IOCTL(fd, cmd, arg) ({			\
-	int _ret;					\
-	mm_segment_t _old_fs = get_fs();		\
-							\
-	set_fs(KERNEL_DS);				\
-	_ret = sys_ioctl(fd, cmd, (unsigned long)arg);	\
-	set_fs(_old_fs);				\
-	_ret;						\
-})
-
-#define CODE
-#include "compat_ioctl.c"
-
-#define COMPATIBLE_IOCTL(cmd)		HANDLE_IOCTL((cmd),sys_ioctl)
-#define HANDLE_IOCTL(cmd,handler)	{ (cmd), (ioctl_trans_handler_t)(handler), NULL },
-#define IOCTL_TABLE_START \
-	struct ioctl_trans ioctl_start[] = {
-#define IOCTL_TABLE_END \
-	};
-
-IOCTL_TABLE_START
-#define DECLARES
-#include "compat_ioctl.c"
-#include <linux/compat_ioctl.h>
-IOCTL_TABLE_END
-
-int ioctl_table_size = ARRAY_SIZE(ioctl_start);
diff --git a/arch/ia64/ia32/ia32_signal.c b/arch/ia64/ia32/ia32_signal.c
index aa891c9..5856510 100644
--- a/arch/ia64/ia32/ia32_signal.c
+++ b/arch/ia64/ia32/ia32_signal.c
@@ -255,7 +255,7 @@
 	 */
 	fp_tos = (fsr>>11)&0x7;
 	fr8_st_map = (8-fp_tos)&0x7;
-	ptp = ia64_task_regs(tsk);
+	ptp = task_pt_regs(tsk);
 	fpregp = (struct _fpreg_ia32 *)(((unsigned long)buf + 15) & ~15);
 	ia64f2ia32f(fpregp, &ptp->f8);
 	copy_to_user(&save->_st[(0+fr8_st_map)&0x7], fpregp, sizeof(struct _fpreg_ia32));
@@ -389,7 +389,7 @@
 	fr8_st_map = (8-fp_tos)&0x7;
 	fpregp = (struct _fpreg_ia32 *)(((unsigned long)buf + 15) & ~15);
 
-	ptp = ia64_task_regs(tsk);
+	ptp = task_pt_regs(tsk);
 	copy_from_user(fpregp, &save->_st[(0+fr8_st_map)&0x7], sizeof(struct _fpreg_ia32));
 	ia32f2ia64f(&ptp->f8, fpregp);
 	copy_from_user(fpregp, &save->_st[(1+fr8_st_map)&0x7], sizeof(struct _fpreg_ia32));
diff --git a/arch/ia64/ia32/ia32_support.c b/arch/ia64/ia32/ia32_support.c
index 4f63004..c187743 100644
--- a/arch/ia64/ia32/ia32_support.c
+++ b/arch/ia64/ia32/ia32_support.c
@@ -58,7 +58,7 @@
 void
 ia32_load_segment_descriptors (struct task_struct *task)
 {
-	struct pt_regs *regs = ia64_task_regs(task);
+	struct pt_regs *regs = task_pt_regs(task);
 
 	/* Setup the segment descriptors */
 	regs->r24 = load_desc(regs->r16 >> 16);		/* ESD */
@@ -113,7 +113,7 @@
 ia32_load_state (struct task_struct *t)
 {
 	unsigned long eflag, fsr, fcr, fir, fdr, tssd;
-	struct pt_regs *regs = ia64_task_regs(t);
+	struct pt_regs *regs = task_pt_regs(t);
 
 	eflag = t->thread.eflag;
 	fsr = t->thread.fsr;
diff --git a/arch/ia64/ia32/sys_ia32.c b/arch/ia64/ia32/sys_ia32.c
index 9f8e8d5..3945d37 100644
--- a/arch/ia64/ia32/sys_ia32.c
+++ b/arch/ia64/ia32/sys_ia32.c
@@ -48,6 +48,7 @@
 #include <linux/ptrace.h>
 #include <linux/stat.h>
 #include <linux/ipc.h>
+#include <linux/capability.h>
 #include <linux/compat.h>
 #include <linux/vfs.h>
 #include <linux/mman.h>
@@ -1481,7 +1482,7 @@
 {
 	struct pt_regs *child_regs;
 
-	child_regs = ia64_task_regs(child);
+	child_regs = task_pt_regs(child);
 	switch (regno / sizeof(int)) {
 	      case PT_EBX: return child_regs->r11;
 	      case PT_ECX: return child_regs->r9;
@@ -1509,7 +1510,7 @@
 {
 	struct pt_regs *child_regs;
 
-	child_regs = ia64_task_regs(child);
+	child_regs = task_pt_regs(child);
 	switch (regno / sizeof(int)) {
 	      case PT_EBX: child_regs->r11 = value; break;
 	      case PT_ECX: child_regs->r9 = value; break;
@@ -1625,7 +1626,7 @@
 	 *  Stack frames start with 16-bytes of temp space
 	 */
 	swp = (struct switch_stack *)(tsk->thread.ksp + 16);
-	ptp = ia64_task_regs(tsk);
+	ptp = task_pt_regs(tsk);
 	tos = (tsk->thread.fsr >> 11) & 7;
 	for (i = 0; i < 8; i++)
 		put_fpreg(i, &save->st_space[i], ptp, swp, tos);
@@ -1658,7 +1659,7 @@
 	 *  Stack frames start with 16-bytes of temp space
 	 */
 	swp = (struct switch_stack *)(tsk->thread.ksp + 16);
-	ptp = ia64_task_regs(tsk);
+	ptp = task_pt_regs(tsk);
 	tos = (tsk->thread.fsr >> 11) & 7;
 	for (i = 0; i < 8; i++)
 		get_fpreg(i, &save->st_space[i], ptp, swp, tos);
@@ -1689,7 +1690,7 @@
          *  Stack frames start with 16-bytes of temp space
          */
         swp = (struct switch_stack *)(tsk->thread.ksp + 16);
-        ptp = ia64_task_regs(tsk);
+        ptp = task_pt_regs(tsk);
 	tos = (tsk->thread.fsr >> 11) & 7;
         for (i = 0; i < 8; i++)
 		put_fpreg(i, (struct _fpreg_ia32 __user *)&save->st_space[4*i], ptp, swp, tos);
@@ -1733,7 +1734,7 @@
 	 *  Stack frames start with 16-bytes of temp space
 	 */
 	swp = (struct switch_stack *)(tsk->thread.ksp + 16);
-	ptp = ia64_task_regs(tsk);
+	ptp = task_pt_regs(tsk);
 	tos = (tsk->thread.fsr >> 11) & 7;
 	for (i = 0; i < 8; i++)
 	get_fpreg(i, (struct _fpreg_ia32 __user *)&save->st_space[4*i], ptp, swp, tos);
@@ -2553,34 +2554,6 @@
 	return 0;
 }
 
-asmlinkage long
-sys32_timer_create(u32 clock, struct compat_sigevent __user *se32, timer_t __user *timer_id)
-{
-	struct sigevent se;
-	mm_segment_t oldfs;
-	timer_t t;
-	long err;
-
-	if (se32 == NULL)
-		return sys_timer_create(clock, NULL, timer_id);
-
-	if (get_compat_sigevent(&se, se32))
-		return -EFAULT;
-
-	if (!access_ok(VERIFY_WRITE,timer_id,sizeof(timer_t)))
-		return -EFAULT;
-
-	oldfs = get_fs();
-	set_fs(KERNEL_DS);
-	err = sys_timer_create(clock, (struct sigevent __user *) &se, (timer_t __user *) &t);
-	set_fs(oldfs);
-
-	if (!err)
-		err = __put_user (t, timer_id);
-
-	return err;
-}
-
 long sys32_fadvise64_64(int fd, __u32 offset_low, __u32 offset_high, 
 			__u32 len_low, __u32 len_high, int advice)
 { 
diff --git a/arch/ia64/kernel/kprobes.c b/arch/ia64/kernel/kprobes.c
index 89a7040..346fedf 100644
--- a/arch/ia64/kernel/kprobes.c
+++ b/arch/ia64/kernel/kprobes.c
@@ -467,10 +467,6 @@
 	flush_icache_range(arm_addr, arm_addr + sizeof(bundle_t));
 }
 
-void __kprobes arch_remove_kprobe(struct kprobe *p)
-{
-}
-
 /*
  * We are resuming execution after a single step fault, so the pt_regs
  * structure reflects the register state after we executed the instruction
@@ -642,6 +638,13 @@
 			if (p->break_handler && p->break_handler(p, regs)) {
 				goto ss_probe;
 			}
+		} else if (!is_ia64_break_inst(regs)) {
+			/* The breakpoint instruction was removed by
+			 * another cpu right after we hit, no further
+			 * handling of this interrupt is appropriate
+			 */
+			ret = 1;
+			goto no_kprobe;
 		} else {
 			/* Not our break */
 			goto no_kprobe;
diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
index 355af15..ee7eec9 100644
--- a/arch/ia64/kernel/mca.c
+++ b/arch/ia64/kernel/mca.c
@@ -766,7 +766,7 @@
 			l = strlen(previous_current->comm);
 		snprintf(comm, sizeof(comm), "%s %*s %d",
 			current->comm, l, previous_current->comm,
-			previous_current->thread_info->cpu);
+			task_thread_info(previous_current)->cpu);
 	}
 	memcpy(current->comm, comm, sizeof(current->comm));
 
@@ -1423,7 +1423,7 @@
 	struct task_struct *p = (struct task_struct *)((char *)mca_data + offset);
 	struct thread_info *ti;
 	memset(p, 0, KERNEL_STACK_SIZE);
-	ti = (struct thread_info *)((char *)p + IA64_TASK_SIZE);
+	ti = task_thread_info(p);
 	ti->flags = _TIF_MCA_INIT;
 	ti->preempt_count = 1;
 	ti->task = p;
diff --git a/arch/ia64/kernel/perfmon.c b/arch/ia64/kernel/perfmon.c
index 410d480..bd87cb6 100644
--- a/arch/ia64/kernel/perfmon.c
+++ b/arch/ia64/kernel/perfmon.c
@@ -38,6 +38,7 @@
 #include <linux/pagemap.h>
 #include <linux/mount.h>
 #include <linux/bitops.h>
+#include <linux/capability.h>
 #include <linux/rcupdate.h>
 
 #include <asm/errno.h>
@@ -1709,7 +1710,7 @@
 pfm_syswide_force_stop(void *info)
 {
 	pfm_context_t   *ctx = (pfm_context_t *)info;
-	struct pt_regs *regs = ia64_task_regs(current);
+	struct pt_regs *regs = task_pt_regs(current);
 	struct task_struct *owner;
 	unsigned long flags;
 	int ret;
@@ -1814,7 +1815,7 @@
 	is_system = ctx->ctx_fl_system;
 
 	task = PFM_CTX_TASK(ctx);
-	regs = ia64_task_regs(task);
+	regs = task_pt_regs(task);
 
 	DPRINT(("ctx_state=%d is_current=%d\n",
 		state,
@@ -1944,7 +1945,7 @@
 	is_system = ctx->ctx_fl_system;
 
 	task = PFM_CTX_TASK(ctx);
-	regs = ia64_task_regs(task);
+	regs = task_pt_regs(task);
 
 	DPRINT(("ctx_state=%d is_current=%d\n", 
 		state,
@@ -4051,7 +4052,7 @@
 	 	 */
 		ia64_psr(regs)->up = 0;
 	} else {
-		tregs = ia64_task_regs(task);
+		tregs = task_pt_regs(task);
 
 		/*
 	 	 * stop monitoring at the user level
@@ -4133,7 +4134,7 @@
 		ia64_psr(regs)->up = 1;
 
 	} else {
-		tregs = ia64_task_regs(ctx->ctx_task);
+		tregs = task_pt_regs(ctx->ctx_task);
 
 		/*
 		 * start monitoring at the kernel level the next
@@ -4403,7 +4404,7 @@
 		/*
 		 * when not current, task MUST be stopped, so this is safe
 		 */
-		regs = ia64_task_regs(task);
+		regs = task_pt_regs(task);
 
 		/* force a full reload */
 		ctx->ctx_last_activation = PFM_INVALID_ACTIVATION;
@@ -4529,7 +4530,7 @@
 	/*
 	 * per-task mode
 	 */
-	tregs = task == current ? regs : ia64_task_regs(task);
+	tregs = task == current ? regs : task_pt_regs(task);
 
 	if (task == current) {
 		/*
@@ -4592,7 +4593,7 @@
 {
 	pfm_context_t *ctx;
 	unsigned long flags;
-	struct pt_regs *regs = ia64_task_regs(task);
+	struct pt_regs *regs = task_pt_regs(task);
 	int ret, state;
 	int free_ok = 0;
 
@@ -4925,7 +4926,7 @@
 	if (unlikely(ret)) goto abort_locked;
 
 skip_fd:
-	ret = (*func)(ctx, args_k, count, ia64_task_regs(current));
+	ret = (*func)(ctx, args_k, count, task_pt_regs(current));
 
 	call_made = 1;
 
@@ -5049,7 +5050,7 @@
 
 	pfm_clear_task_notify();
 
-	regs = ia64_task_regs(current);
+	regs = task_pt_regs(current);
 
 	/*
 	 * extract reason for being here and clear
@@ -5793,7 +5794,7 @@
 	 * on every CPU, so we can rely on the pid to identify the idle task.
 	 */
 	if ((info & PFM_CPUINFO_EXCL_IDLE) == 0 || task->pid) {
-		regs = ia64_task_regs(task);
+		regs = task_pt_regs(task);
 		ia64_psr(regs)->pp = is_ctxswin ? dcr_pp : 0;
 		return;
 	}
@@ -5876,7 +5877,7 @@
 	flags = pfm_protect_ctx_ctxsw(ctx);
 
 	if (ctx->ctx_state == PFM_CTX_ZOMBIE) {
-		struct pt_regs *regs = ia64_task_regs(task);
+		struct pt_regs *regs = task_pt_regs(task);
 
 		pfm_clear_psr_up();
 
@@ -6076,7 +6077,7 @@
 	BUG_ON(psr & IA64_PSR_I);
 
 	if (unlikely(ctx->ctx_state == PFM_CTX_ZOMBIE)) {
-		struct pt_regs *regs = ia64_task_regs(task);
+		struct pt_regs *regs = task_pt_regs(task);
 
 		BUG_ON(ctx->ctx_smpl_hdr);
 
@@ -6445,7 +6446,7 @@
 {
 	struct pt_regs *regs;
 
-	regs = ia64_task_regs(current);
+	regs = task_pt_regs(current);
 
 	DPRINT(("called\n"));
 
@@ -6471,7 +6472,7 @@
 {
 	struct pt_regs *regs;
 
-	regs = ia64_task_regs(current);
+	regs = task_pt_regs(current);
 
 	DPRINT(("called\n"));
 
@@ -6753,7 +6754,7 @@
 	local_irq_save(flags);
 
 	this_cpu = smp_processor_id();
-	regs     = ia64_task_regs(current);
+	regs     = task_pt_regs(current);
 	info     = PFM_CPUINFO_GET();
 	dcr      = ia64_getreg(_IA64_REG_CR_DCR);
 
diff --git a/arch/ia64/kernel/process.c b/arch/ia64/kernel/process.c
index e9904c7..309d596 100644
--- a/arch/ia64/kernel/process.c
+++ b/arch/ia64/kernel/process.c
@@ -328,7 +328,7 @@
 #endif
 
 #ifdef CONFIG_IA32_SUPPORT
-	if (IS_IA32_PROCESS(ia64_task_regs(task)))
+	if (IS_IA32_PROCESS(task_pt_regs(task)))
 		ia32_save_state(task);
 #endif
 }
@@ -353,7 +353,7 @@
 #endif
 
 #ifdef CONFIG_IA32_SUPPORT
-	if (IS_IA32_PROCESS(ia64_task_regs(task)))
+	if (IS_IA32_PROCESS(task_pt_regs(task)))
 		ia32_load_state(task);
 #endif
 }
@@ -488,7 +488,7 @@
 	 * If we're cloning an IA32 task then save the IA32 extra
 	 * state from the current task to the new task
 	 */
-	if (IS_IA32_PROCESS(ia64_task_regs(current))) {
+	if (IS_IA32_PROCESS(task_pt_regs(current))) {
 		ia32_save_state(p);
 		if (clone_flags & CLONE_SETTLS)
 			retval = ia32_clone_tls(p, child_ptregs);
@@ -701,7 +701,7 @@
 kernel_thread_helper (int (*fn)(void *), void *arg)
 {
 #ifdef CONFIG_IA32_SUPPORT
-	if (IS_IA32_PROCESS(ia64_task_regs(current))) {
+	if (IS_IA32_PROCESS(task_pt_regs(current))) {
 		/* A kernel thread is always a 64-bit process. */
 		current->thread.map_base  = DEFAULT_MAP_BASE;
 		current->thread.task_size = DEFAULT_TASK_SIZE;
@@ -722,7 +722,7 @@
 	current->thread.flags &= ~(IA64_THREAD_FPH_VALID | IA64_THREAD_DBG_VALID);
 	ia64_drop_fpu(current);
 #ifdef CONFIG_IA32_SUPPORT
-	if (IS_IA32_PROCESS(ia64_task_regs(current))) {
+	if (IS_IA32_PROCESS(task_pt_regs(current))) {
 		ia32_drop_partial_page_list(current);
 		current->thread.task_size = IA32_PAGE_OFFSET;
 		set_fs(USER_DS);
@@ -755,7 +755,7 @@
 	if (current->thread.flags & IA64_THREAD_DBG_VALID)
 		pfm_release_debug_registers(current);
 #endif
-	if (IS_IA32_PROCESS(ia64_task_regs(current)))
+	if (IS_IA32_PROCESS(task_pt_regs(current)))
 		ia32_drop_partial_page_list(current);
 }
 
diff --git a/arch/ia64/kernel/ptrace.c b/arch/ia64/kernel/ptrace.c
index 8d88eee..eaed14a 100644
--- a/arch/ia64/kernel/ptrace.c
+++ b/arch/ia64/kernel/ptrace.c
@@ -254,7 +254,7 @@
 	long num_regs, nbits;
 	struct pt_regs *pt;
 
-	pt = ia64_task_regs(task);
+	pt = task_pt_regs(task);
 	kbsp = (unsigned long *) sw->ar_bspstore;
 	ubspstore = (unsigned long *) pt->ar_bspstore;
 
@@ -314,7 +314,7 @@
 	struct pt_regs *pt;
 	unsigned long cfm, *urbs_kargs;
 
-	pt = ia64_task_regs(task);
+	pt = task_pt_regs(task);
 	kbsp = (unsigned long *) sw->ar_bspstore;
 	ubspstore = (unsigned long *) pt->ar_bspstore;
 
@@ -407,7 +407,7 @@
 
 	urbs_end = (long *) user_rbs_end;
 	laddr = (unsigned long *) addr;
-	child_regs = ia64_task_regs(child);
+	child_regs = task_pt_regs(child);
 	bspstore = (unsigned long *) child_regs->ar_bspstore;
 	krbs = (unsigned long *) child + IA64_RBS_OFFSET/8;
 	if (on_kernel_rbs(addr, (unsigned long) bspstore,
@@ -467,7 +467,7 @@
 	struct pt_regs *child_regs;
 
 	laddr = (unsigned long *) addr;
-	child_regs = ia64_task_regs(child);
+	child_regs = task_pt_regs(child);
 	bspstore = (unsigned long *) child_regs->ar_bspstore;
 	krbs = (unsigned long *) child + IA64_RBS_OFFSET/8;
 	if (on_kernel_rbs(addr, (unsigned long) bspstore,
@@ -567,7 +567,7 @@
 		 */
 		return 0;
 
-	thread_regs = ia64_task_regs(thread);
+	thread_regs = task_pt_regs(thread);
 	thread_rbs_end = ia64_get_user_rbs_end(thread, thread_regs, NULL);
 	if (!on_kernel_rbs(addr, thread_regs->ar_bspstore, thread_rbs_end))
 		return 0;
@@ -627,7 +627,7 @@
 inline void
 ia64_flush_fph (struct task_struct *task)
 {
-	struct ia64_psr *psr = ia64_psr(ia64_task_regs(task));
+	struct ia64_psr *psr = ia64_psr(task_pt_regs(task));
 
 	/*
 	 * Prevent migrating this task while
@@ -653,7 +653,7 @@
 void
 ia64_sync_fph (struct task_struct *task)
 {
-	struct ia64_psr *psr = ia64_psr(ia64_task_regs(task));
+	struct ia64_psr *psr = ia64_psr(task_pt_regs(task));
 
 	ia64_flush_fph(task);
 	if (!(task->thread.flags & IA64_THREAD_FPH_VALID)) {
@@ -794,7 +794,7 @@
 					  + offsetof(struct pt_regs, reg)))
 
 
-	pt = ia64_task_regs(child);
+	pt = task_pt_regs(child);
 	sw = (struct switch_stack *) (child->thread.ksp + 16);
 
 	if ((addr & 0x7) != 0) {
@@ -1120,7 +1120,7 @@
 	if (!access_ok(VERIFY_WRITE, ppr, sizeof(struct pt_all_user_regs)))
 		return -EIO;
 
-	pt = ia64_task_regs(child);
+	pt = task_pt_regs(child);
 	sw = (struct switch_stack *) (child->thread.ksp + 16);
 	unw_init_from_blocked_task(&info, child);
 	if (unw_unwind_to_user(&info) < 0) {
@@ -1265,7 +1265,7 @@
 	if (!access_ok(VERIFY_READ, ppr, sizeof(struct pt_all_user_regs)))
 		return -EIO;
 
-	pt = ia64_task_regs(child);
+	pt = task_pt_regs(child);
 	sw = (struct switch_stack *) (child->thread.ksp + 16);
 	unw_init_from_blocked_task(&info, child);
 	if (unw_unwind_to_user(&info) < 0) {
@@ -1403,7 +1403,7 @@
 void
 ptrace_disable (struct task_struct *child)
 {
-	struct ia64_psr *child_psr = ia64_psr(ia64_task_regs(child));
+	struct ia64_psr *child_psr = ia64_psr(task_pt_regs(child));
 
 	/* make sure the single step/taken-branch trap bits are not set: */
 	child_psr->ss = 0;
@@ -1456,7 +1456,7 @@
 	if (ret < 0)
 		goto out_tsk;
 
-	pt = ia64_task_regs(child);
+	pt = task_pt_regs(child);
 	sw = (struct switch_stack *) (child->thread.ksp + 16);
 
 	switch (request) {
diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
index 1461dc6..a87a162 100644
--- a/arch/ia64/kernel/salinfo.c
+++ b/arch/ia64/kernel/salinfo.c
@@ -29,6 +29,7 @@
  *   Replace some NR_CPUS by cpus_online, for hotplug cpu.
  */
 
+#include <linux/capability.h>
 #include <linux/types.h>
 #include <linux/proc_fs.h>
 #include <linux/module.h>
diff --git a/arch/ia64/kernel/setup.c b/arch/ia64/kernel/setup.c
index c33305d..c076657 100644
--- a/arch/ia64/kernel/setup.c
+++ b/arch/ia64/kernel/setup.c
@@ -60,6 +60,7 @@
 #include <asm/smp.h>
 #include <asm/system.h>
 #include <asm/unistd.h>
+#include <asm/system.h>
 
 #if defined(CONFIG_SMP) && (IA64_CPU_SIZE > PAGE_SIZE)
 # error "struct cpuinfo_ia64 too big!"
@@ -695,6 +696,7 @@
 get_max_cacheline_size (void)
 {
 	unsigned long line_size, max = 1;
+	unsigned int cache_size = 0;
 	u64 l, levels, unique_caches;
         pal_cache_config_info_t cci;
         s64 status;
@@ -724,6 +726,8 @@
 		line_size = 1 << cci.pcci_line_size;
 		if (line_size > max)
 			max = line_size;
+		if (cache_size < cci.pcci_cache_size)
+			cache_size = cci.pcci_cache_size;
 		if (!cci.pcci_unified) {
 			status = ia64_pal_cache_config_info(l,
 						    /* cache_type (instruction)= */ 1,
@@ -740,6 +744,9 @@
 			ia64_i_cache_stride_shift = cci.pcci_stride;
 	}
   out:
+#ifdef CONFIG_SMP
+	max_cache_size = max(max_cache_size, cache_size);
+#endif
 	if (max > ia64_max_cacheline_size)
 		ia64_max_cacheline_size = max;
 }
@@ -794,7 +801,7 @@
 #endif
 
 	/* Clear the stack memory reserved for pt_regs: */
-	memset(ia64_task_regs(current), 0, sizeof(struct pt_regs));
+	memset(task_pt_regs(current), 0, sizeof(struct pt_regs));
 
 	ia64_set_kr(IA64_KR_FPU_OWNER, 0);
 
@@ -870,6 +877,15 @@
 	pm_idle = default_idle;
 }
 
+/*
+ * On SMP systems, when the scheduler does migration-cost autodetection,
+ * it needs a way to flush as much of the CPU's caches as possible.
+ */
+void sched_cacheflush(void)
+{
+	ia64_sal_cache_flush(3);
+}
+
 void
 check_bugs (void)
 {
diff --git a/arch/ia64/kernel/signal.c b/arch/ia64/kernel/signal.c
index 58ce07e..463f6bb 100644
--- a/arch/ia64/kernel/signal.c
+++ b/arch/ia64/kernel/signal.c
@@ -655,11 +655,11 @@
 
 		if (!t)
 			return;
-		t->thread_info->sigdelayed.signo = signo;
-		t->thread_info->sigdelayed.code = code;
-		t->thread_info->sigdelayed.addr = addr;
-		t->thread_info->sigdelayed.start_time = start_time;
-		t->thread_info->sigdelayed.pid = pid;
+		task_thread_info(t)->sigdelayed.signo = signo;
+		task_thread_info(t)->sigdelayed.code = code;
+		task_thread_info(t)->sigdelayed.addr = addr;
+		task_thread_info(t)->sigdelayed.start_time = start_time;
+		task_thread_info(t)->sigdelayed.pid = pid;
 		wmb();
 		set_tsk_thread_flag(t, TIF_SIGDELAYED);
 	}
diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
index f2dbcd1..c7b943f 100644
--- a/arch/ia64/kernel/sys_ia64.c
+++ b/arch/ia64/kernel/sys_ia64.c
@@ -151,7 +151,7 @@
 asmlinkage long
 sys_pipe (void)
 {
-	struct pt_regs *regs = ia64_task_regs(current);
+	struct pt_regs *regs = task_pt_regs(current);
 	int fd[2];
 	int retval;
 
diff --git a/arch/ia64/sn/kernel/tiocx.c b/arch/ia64/sn/kernel/tiocx.c
index 768c21d..493fb3f 100644
--- a/arch/ia64/sn/kernel/tiocx.c
+++ b/arch/ia64/sn/kernel/tiocx.c
@@ -11,6 +11,7 @@
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/proc_fs.h>
+#include <linux/capability.h>
 #include <linux/device.h>
 #include <linux/delay.h>
 #include <asm/system.h>
diff --git a/arch/m32r/Kconfig b/arch/m32r/Kconfig
index fae67bb..a3dcc3f 100644
--- a/arch/m32r/Kconfig
+++ b/arch/m32r/Kconfig
@@ -12,10 +12,6 @@
 config SBUS
 	bool
 
-config UID16
-	bool
-	default n
-
 config GENERIC_ISA_DMA
 	bool
 	default y
diff --git a/arch/m32r/kernel/m32r_ksyms.c b/arch/m32r/kernel/m32r_ksyms.c
index e5ec134..dbc8a39 100644
--- a/arch/m32r/kernel/m32r_ksyms.c
+++ b/arch/m32r/kernel/m32r_ksyms.c
@@ -18,8 +18,6 @@
 #include <asm/irq.h>
 #include <asm/tlbflush.h>
 
-extern void dump_thread(struct pt_regs *, struct user *);
-
 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_HD) || defined(CONFIG_BLK_DEV_IDE_MODULE) || defined(CONFIG_BLK_DEV_HD_MODULE)
 extern struct drive_info_struct drive_info;
 EXPORT_SYMBOL(drive_info);
@@ -27,7 +25,6 @@
 
 /* platform dependent support */
 EXPORT_SYMBOL(boot_cpu_data);
-EXPORT_SYMBOL(dump_thread);
 EXPORT_SYMBOL(dump_fpu);
 EXPORT_SYMBOL(__ioremap);
 EXPORT_SYMBOL(iounmap);
diff --git a/arch/m32r/kernel/process.c b/arch/m32r/kernel/process.c
index 3bf55d9..5dfc7ea 100644
--- a/arch/m32r/kernel/process.c
+++ b/arch/m32r/kernel/process.c
@@ -242,13 +242,10 @@
 int copy_thread(int nr, unsigned long clone_flags, unsigned long spu,
 	unsigned long unused, struct task_struct *tsk, struct pt_regs *regs)
 {
-	struct pt_regs *childregs;
-	unsigned long sp = (unsigned long)tsk->thread_info + THREAD_SIZE;
+	struct pt_regs *childregs = task_pt_regs(tsk);
 	extern void ret_from_fork(void);
 
 	/* Copy registers */
-	sp -= sizeof (struct pt_regs);
-	childregs = (struct pt_regs *)sp;
 	*childregs = *regs;
 
 	childregs->spu = spu;
@@ -261,14 +258,6 @@
 }
 
 /*
- * fill in the user structure for a core dump..
- */
-void dump_thread(struct pt_regs * regs, struct user * dump)
-{
-	/* M32R_FIXME */
-}
-
-/*
  * 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)
diff --git a/arch/m32r/kernel/ptrace.c b/arch/m32r/kernel/ptrace.c
index 9b75caa..340a3bf 100644
--- a/arch/m32r/kernel/ptrace.c
+++ b/arch/m32r/kernel/ptrace.c
@@ -35,23 +35,6 @@
 #include <asm/mmu_context.h>
 
 /*
- * Get the address of the live pt_regs for the specified task.
- * These are saved onto the top kernel stack when the process
- * is not running.
- *
- * Note: if a user thread is execve'd from kernel space, the
- * kernel stack will not be empty on entry to the kernel, so
- * ptracing these tasks will fail.
- */
-static inline struct pt_regs *
-get_user_regs(struct task_struct *task)
-{
-        return (struct pt_regs *)
-                ((unsigned long)task->thread_info + THREAD_SIZE
-                 - sizeof(struct pt_regs));
-}
-
-/*
  * This routine will get a word off of the process kernel stack.
  */
 static inline unsigned long int
@@ -59,7 +42,7 @@
 {
 	unsigned long *stack;
 
-	stack = (unsigned long *)get_user_regs(task);
+	stack = (unsigned long *)task_pt_regs(task);
 
 	return stack[offset];
 }
@@ -72,7 +55,7 @@
 {
 	unsigned long *stack;
 
-	stack = (unsigned long *)get_user_regs(task);
+	stack = (unsigned long *)task_pt_regs(task);
 	stack[offset] = data;
 
 	return 0;
@@ -208,7 +191,7 @@
  */
 static int ptrace_getregs(struct task_struct *tsk, void __user *uregs)
 {
-	struct pt_regs *regs = get_user_regs(tsk);
+	struct pt_regs *regs = task_pt_regs(tsk);
 
 	return copy_to_user(uregs, regs, sizeof(struct pt_regs)) ? -EFAULT : 0;
 }
@@ -223,7 +206,7 @@
 
 	ret = -EFAULT;
 	if (copy_from_user(&newregs, uregs, sizeof(struct pt_regs)) == 0) {
-		struct pt_regs *regs = get_user_regs(tsk);
+		struct pt_regs *regs = task_pt_regs(tsk);
 		*regs = newregs;
 		ret = 0;
 	}
diff --git a/arch/m32r/kernel/smpboot.c b/arch/m32r/kernel/smpboot.c
index b90c541..d7ec16e 100644
--- a/arch/m32r/kernel/smpboot.c
+++ b/arch/m32r/kernel/smpboot.c
@@ -286,7 +286,7 @@
 	/* So we see what's up   */
 	printk("Booting processor %d/%d\n", phys_id, cpu_id);
 	stack_start.spi = (void *)idle->thread.sp;
-	idle->thread_info->cpu = cpu_id;
+	task_thread_info(idle)->cpu = cpu_id;
 
 	/*
 	 * Send Startup IPI
diff --git a/arch/m68k/amiga/amiints.c b/arch/m68k/amiga/amiints.c
index d9edf2d..b0aa61bf 100644
--- a/arch/m68k/amiga/amiints.c
+++ b/arch/m68k/amiga/amiints.c
@@ -126,9 +126,9 @@
 		gayle.inten = GAYLE_IRQ_IDE;
 
 	/* turn off all interrupts and enable the master interrupt bit */
-	custom.intena = 0x7fff;
-	custom.intreq = 0x7fff;
-	custom.intena = IF_SETCLR | IF_INTEN;
+	amiga_custom.intena = 0x7fff;
+	amiga_custom.intreq = 0x7fff;
+	amiga_custom.intena = IF_SETCLR | IF_INTEN;
 
 	cia_init_IRQ(&ciaa_base);
 	cia_init_IRQ(&ciab_base);
@@ -245,7 +245,7 @@
 
 	/* enable the interrupt */
 	if (irq < IRQ_AMIGA_PORTS && !ami_ablecount[irq])
-		custom.intena = IF_SETCLR | amiga_intena_vals[irq];
+		amiga_custom.intena = IF_SETCLR | amiga_intena_vals[irq];
 
 	return error;
 }
@@ -274,7 +274,7 @@
 		amiga_delete_irq(&ami_irq_list[irq], dev_id);
 		/* if server list empty, disable the interrupt */
 		if (!ami_irq_list[irq] && irq < IRQ_AMIGA_PORTS)
-			custom.intena = amiga_intena_vals[irq];
+			amiga_custom.intena = amiga_intena_vals[irq];
 	} else {
 		if (ami_irq_list[irq]->dev_id != dev_id)
 			printk("%s: removing probably wrong IRQ %d from %s\n",
@@ -283,7 +283,7 @@
 		ami_irq_list[irq]->flags   = 0;
 		ami_irq_list[irq]->dev_id  = NULL;
 		ami_irq_list[irq]->devname = NULL;
-		custom.intena = amiga_intena_vals[irq];
+		amiga_custom.intena = amiga_intena_vals[irq];
 	}
 }
 
@@ -327,7 +327,7 @@
 	}
 
 	/* enable the interrupt */
-	custom.intena = IF_SETCLR | amiga_intena_vals[irq];
+	amiga_custom.intena = IF_SETCLR | amiga_intena_vals[irq];
 }
 
 void amiga_disable_irq(unsigned int irq)
@@ -358,7 +358,7 @@
 	}
 
 	/* disable the interrupt */
-	custom.intena = amiga_intena_vals[irq];
+	amiga_custom.intena = amiga_intena_vals[irq];
 }
 
 inline void amiga_do_irq(int irq, struct pt_regs *fp)
@@ -373,7 +373,7 @@
 
 	kstat_cpu(0).irqs[SYS_IRQS + irq]++;
 
-	custom.intreq = amiga_intena_vals[irq];
+	amiga_custom.intreq = amiga_intena_vals[irq];
 
 	for (node = ami_irq_list[irq]; node; node = node->next)
 		node->handler(irq, node->dev_id, fp);
@@ -385,23 +385,23 @@
 
 static irqreturn_t ami_int1(int irq, void *dev_id, struct pt_regs *fp)
 {
-	unsigned short ints = custom.intreqr & custom.intenar;
+	unsigned short ints = amiga_custom.intreqr & amiga_custom.intenar;
 
 	/* if serial transmit buffer empty, interrupt */
 	if (ints & IF_TBE) {
-		custom.intreq = IF_TBE;
+		amiga_custom.intreq = IF_TBE;
 		amiga_do_irq(IRQ_AMIGA_TBE, fp);
 	}
 
 	/* if floppy disk transfer complete, interrupt */
 	if (ints & IF_DSKBLK) {
-		custom.intreq = IF_DSKBLK;
+		amiga_custom.intreq = IF_DSKBLK;
 		amiga_do_irq(IRQ_AMIGA_DSKBLK, fp);
 	}
 
 	/* if software interrupt set, interrupt */
 	if (ints & IF_SOFT) {
-		custom.intreq = IF_SOFT;
+		amiga_custom.intreq = IF_SOFT;
 		amiga_do_irq(IRQ_AMIGA_SOFT, fp);
 	}
 	return IRQ_HANDLED;
@@ -409,17 +409,17 @@
 
 static irqreturn_t ami_int3(int irq, void *dev_id, struct pt_regs *fp)
 {
-	unsigned short ints = custom.intreqr & custom.intenar;
+	unsigned short ints = amiga_custom.intreqr & amiga_custom.intenar;
 
 	/* if a blitter interrupt */
 	if (ints & IF_BLIT) {
-		custom.intreq = IF_BLIT;
+		amiga_custom.intreq = IF_BLIT;
 		amiga_do_irq(IRQ_AMIGA_BLIT, fp);
 	}
 
 	/* if a copper interrupt */
 	if (ints & IF_COPER) {
-		custom.intreq = IF_COPER;
+		amiga_custom.intreq = IF_COPER;
 		amiga_do_irq(IRQ_AMIGA_COPPER, fp);
 	}
 
@@ -431,29 +431,29 @@
 
 static irqreturn_t ami_int4(int irq, void *dev_id, struct pt_regs *fp)
 {
-	unsigned short ints = custom.intreqr & custom.intenar;
+	unsigned short ints = amiga_custom.intreqr & amiga_custom.intenar;
 
 	/* if audio 0 interrupt */
 	if (ints & IF_AUD0) {
-		custom.intreq = IF_AUD0;
+		amiga_custom.intreq = IF_AUD0;
 		amiga_do_irq(IRQ_AMIGA_AUD0, fp);
 	}
 
 	/* if audio 1 interrupt */
 	if (ints & IF_AUD1) {
-		custom.intreq = IF_AUD1;
+		amiga_custom.intreq = IF_AUD1;
 		amiga_do_irq(IRQ_AMIGA_AUD1, fp);
 	}
 
 	/* if audio 2 interrupt */
 	if (ints & IF_AUD2) {
-		custom.intreq = IF_AUD2;
+		amiga_custom.intreq = IF_AUD2;
 		amiga_do_irq(IRQ_AMIGA_AUD2, fp);
 	}
 
 	/* if audio 3 interrupt */
 	if (ints & IF_AUD3) {
-		custom.intreq = IF_AUD3;
+		amiga_custom.intreq = IF_AUD3;
 		amiga_do_irq(IRQ_AMIGA_AUD3, fp);
 	}
 	return IRQ_HANDLED;
@@ -461,7 +461,7 @@
 
 static irqreturn_t ami_int5(int irq, void *dev_id, struct pt_regs *fp)
 {
-	unsigned short ints = custom.intreqr & custom.intenar;
+	unsigned short ints = amiga_custom.intreqr & amiga_custom.intenar;
 
 	/* if serial receive buffer full interrupt */
 	if (ints & IF_RBF) {
@@ -471,7 +471,7 @@
 
 	/* if a disk sync interrupt */
 	if (ints & IF_DSKSYN) {
-		custom.intreq = IF_DSKSYN;
+		amiga_custom.intreq = IF_DSKSYN;
 		amiga_do_irq(IRQ_AMIGA_DSKSYN, fp);
 	}
 	return IRQ_HANDLED;
diff --git a/arch/m68k/amiga/amisound.c b/arch/m68k/amiga/amisound.c
index bd5d134e..ae94db5 100644
--- a/arch/m68k/amiga/amisound.c
+++ b/arch/m68k/amiga/amisound.c
@@ -24,6 +24,8 @@
 };
 #define DATA_SIZE	(sizeof(sine_data)/sizeof(sine_data[0]))
 
+#define custom amiga_custom
+
     /*
      * The minimum period for audio may be modified by the frame buffer
      * device since it depends on htotal (for OCS/ECS/AGA)
diff --git a/arch/m68k/amiga/cia.c b/arch/m68k/amiga/cia.c
index 7d55682..9476eb9 100644
--- a/arch/m68k/amiga/cia.c
+++ b/arch/m68k/amiga/cia.c
@@ -60,7 +60,7 @@
 	else
 		base->icr_data &= ~mask;
 	if (base->icr_data & base->icr_mask)
-		custom.intreq = IF_SETCLR | base->int_mask;
+		amiga_custom.intreq = IF_SETCLR | base->int_mask;
 	return old & base->icr_mask;
 }
 
@@ -89,7 +89,7 @@
 		}
 	}
 	if (base->icr_data & base->icr_mask)
-		custom.intreq = IF_SETCLR | base->int_mask;
+		amiga_custom.intreq = IF_SETCLR | base->int_mask;
 	return old;
 }
 
@@ -133,7 +133,7 @@
 	mach_irq = base->cia_irq;
 	irq = SYS_IRQS + mach_irq;
 	ints = cia_set_irq(base, CIA_ICR_ALL);
-	custom.intreq = base->int_mask;
+	amiga_custom.intreq = base->int_mask;
 	for (i = 0; i < CIA_IRQS; i++, irq++, mach_irq++) {
 		if (ints & 1) {
 			kstat_cpu(0).irqs[irq]++;
@@ -162,7 +162,7 @@
 	/* install CIA handler */
 	request_irq(base->handler_irq, cia_handler, 0, base->name, base);
 
-	custom.intena = IF_SETCLR | base->int_mask;
+	amiga_custom.intena = IF_SETCLR | base->int_mask;
 }
 
 int cia_get_irq_list(struct ciabase *base, struct seq_file *p)
diff --git a/arch/m68k/amiga/config.c b/arch/m68k/amiga/config.c
index 4775e18..12e3706 100644
--- a/arch/m68k/amiga/config.c
+++ b/arch/m68k/amiga/config.c
@@ -105,9 +105,6 @@
 static int amiga_set_clock_mmss (unsigned long);
 static unsigned int amiga_get_ss (void);
 extern void amiga_mksound( unsigned int count, unsigned int ticks );
-#ifdef CONFIG_AMIGA_FLOPPY
-extern void amiga_floppy_setup(char *, int *);
-#endif
 static void amiga_reset (void);
 extern void amiga_init_sound(void);
 static void amiga_savekmsg_init(void);
@@ -290,7 +287,7 @@
     case CS_OCS:
     case CS_ECS:
     case CS_AGA:
-      switch (custom.deniseid & 0xf) {
+      switch (amiga_custom.deniseid & 0xf) {
       case 0x0c:
 	AMIGAHW_SET(DENISE_HR);
 	break;
@@ -303,7 +300,7 @@
       AMIGAHW_SET(DENISE);
       break;
     }
-    switch ((custom.vposr>>8) & 0x7f) {
+    switch ((amiga_custom.vposr>>8) & 0x7f) {
     case 0x00:
       AMIGAHW_SET(AGNUS_PAL);
       break;
@@ -427,13 +424,7 @@
 
   mach_set_clock_mmss  = amiga_set_clock_mmss;
   mach_get_ss          = amiga_get_ss;
-#ifdef CONFIG_AMIGA_FLOPPY
-  mach_floppy_setup    = amiga_floppy_setup;
-#endif
   mach_reset           = amiga_reset;
-#ifdef CONFIG_DUMMY_CONSOLE
-  conswitchp           = &dummy_con;
-#endif
 #if defined(CONFIG_INPUT_M68K_BEEP) || defined(CONFIG_INPUT_M68K_BEEP_MODULE)
   mach_beep            = amiga_mksound;
 #endif
@@ -447,9 +438,9 @@
   amiga_colorclock = 5*amiga_eclock;	/* 3.5 MHz */
 
   /* clear all DMA bits */
-  custom.dmacon = DMAF_ALL;
+  amiga_custom.dmacon = DMAF_ALL;
   /* ensure that the DMA master bit is set */
-  custom.dmacon = DMAF_SETCLR | DMAF_MASTER;
+  amiga_custom.dmacon = DMAF_SETCLR | DMAF_MASTER;
 
   /* don't use Z2 RAM as system memory on Z3 capable machines */
   if (AMIGAHW_PRESENT(ZORRO3)) {
@@ -830,8 +821,8 @@
 
 static void amiga_serial_putc(char c)
 {
-    custom.serdat = (unsigned char)c | 0x100;
-    while (!(custom.serdatr & 0x2000))
+    amiga_custom.serdat = (unsigned char)c | 0x100;
+    while (!(amiga_custom.serdatr & 0x2000))
 	;
 }
 
@@ -855,11 +846,11 @@
 {
     int ch;
 
-    while (!(custom.intreqr & IF_RBF))
+    while (!(amiga_custom.intreqr & IF_RBF))
 	barrier();
-    ch = custom.serdatr & 0xff;
+    ch = amiga_custom.serdatr & 0xff;
     /* clear the interrupt, so that another character can be read */
-    custom.intreq = IF_RBF;
+    amiga_custom.intreq = IF_RBF;
     return ch;
 }
 
diff --git a/arch/m68k/apollo/config.c b/arch/m68k/apollo/config.c
index 2649294..d401962 100644
--- a/arch/m68k/apollo/config.c
+++ b/arch/m68k/apollo/config.c
@@ -176,9 +176,6 @@
 	mach_set_clock_mmss  = dn_dummy_set_clock_mmss; /* */
 	mach_process_int     = dn_process_int;
 	mach_reset	     = dn_dummy_reset;  /* */
-#ifdef CONFIG_DUMMY_CONSOLE
-        conswitchp           = &dummy_con;
-#endif
 #ifdef CONFIG_HEARTBEAT
 	mach_heartbeat = dn_heartbeat;
 #endif
diff --git a/arch/m68k/atari/config.c b/arch/m68k/atari/config.c
index 9261d2d..1012b08e5 100644
--- a/arch/m68k/atari/config.c
+++ b/arch/m68k/atari/config.c
@@ -52,9 +52,6 @@
 
 /* local function prototypes */
 static void atari_reset( void );
-#ifdef CONFIG_ATARI_FLOPPY
-extern void atari_floppy_setup(char *, int *);
-#endif
 static void atari_get_model(char *model);
 static int atari_get_hardware_list(char *buffer);
 
@@ -244,12 +241,6 @@
     mach_get_irq_list	 = show_atari_interrupts;
     mach_gettimeoffset   = atari_gettimeoffset;
     mach_reset           = atari_reset;
-#ifdef CONFIG_ATARI_FLOPPY
-    mach_floppy_setup	 = atari_floppy_setup;
-#endif
-#ifdef CONFIG_DUMMY_CONSOLE
-    conswitchp	         = &dummy_con;
-#endif
     mach_max_dma_address = 0xffffff;
 #if defined(CONFIG_INPUT_M68K_BEEP) || defined(CONFIG_INPUT_M68K_BEEP_MODULE)
     mach_beep          = atari_mksound;
diff --git a/arch/m68k/bvme6000/rtc.c b/arch/m68k/bvme6000/rtc.c
index eb63ca6..703cbc6 100644
--- a/arch/m68k/bvme6000/rtc.c
+++ b/arch/m68k/bvme6000/rtc.c
@@ -11,6 +11,7 @@
 #include <linux/miscdevice.h>
 #include <linux/slab.h>
 #include <linux/ioport.h>
+#include <linux/capability.h>
 #include <linux/fcntl.h>
 #include <linux/init.h>
 #include <linux/poll.h>
@@ -46,6 +47,7 @@
 	unsigned char msr;
 	unsigned long flags;
 	struct rtc_time wtime;
+	void __user *argp = (void __user *)arg;
 
 	switch (cmd) {
 	case RTC_RD_TIME:	/* Read the time/date from RTC	*/
@@ -68,7 +70,7 @@
 		} while (wtime.tm_sec != BCD2BIN(rtc->bcd_sec));
 		rtc->msr = msr;
 		local_irq_restore(flags);
-		return copy_to_user((void *)arg, &wtime, sizeof wtime) ?
+		return copy_to_user(argp, &wtime, sizeof wtime) ?
 								-EFAULT : 0;
 	}
 	case RTC_SET_TIME:	/* Set the RTC */
@@ -80,8 +82,7 @@
 		if (!capable(CAP_SYS_ADMIN))
 			return -EACCES;
 
-		if (copy_from_user(&rtc_tm, (struct rtc_time*)arg,
-				   sizeof(struct rtc_time)))
+		if (copy_from_user(&rtc_tm, argp, sizeof(struct rtc_time)))
 			return -EFAULT;
 
 		yrs = rtc_tm.tm_year;
diff --git a/arch/m68k/hp300/config.c b/arch/m68k/hp300/config.c
index a0b854f..6d129ee 100644
--- a/arch/m68k/hp300/config.c
+++ b/arch/m68k/hp300/config.c
@@ -261,9 +261,6 @@
 #ifdef CONFIG_HEARTBEAT
 	mach_heartbeat       = hp300_pulse;
 #endif
-#ifdef CONFIG_DUMMY_CONSOLE
-	conswitchp	     = &dummy_con;
-#endif
 	mach_max_dma_address = 0xffffffff;
 
 	if (hp300_model >= HP_330 && hp300_model <= HP_433S && hp300_model != HP_350) {
diff --git a/arch/m68k/kernel/asm-offsets.c b/arch/m68k/kernel/asm-offsets.c
index c787c5b..246a882 100644
--- a/arch/m68k/kernel/asm-offsets.c
+++ b/arch/m68k/kernel/asm-offsets.c
@@ -92,7 +92,7 @@
 	DEFINE(TRAP_TRACE, TRAP_TRACE);
 
 	/* offsets into the custom struct */
-	DEFINE(CUSTOMBASE, &custom);
+	DEFINE(CUSTOMBASE, &amiga_custom);
 	DEFINE(C_INTENAR, offsetof(struct CUSTOM, intenar));
 	DEFINE(C_INTREQR, offsetof(struct CUSTOM, intreqr));
 	DEFINE(C_INTENA, offsetof(struct CUSTOM, intena));
diff --git a/arch/m68k/kernel/head.S b/arch/m68k/kernel/head.S
index d4336d8..70002c1 100644
--- a/arch/m68k/kernel/head.S
+++ b/arch/m68k/kernel/head.S
@@ -273,8 +273,10 @@
  * Macintosh console support
  */
 
+#ifdef CONFIG_FRAMEBUFFER_CONSOLE
 #define CONSOLE
 #define CONSOLE_PENGUIN
+#endif
 
 /*
  * Macintosh serial debug support; outputs boot info to the printer
diff --git a/arch/m68k/kernel/m68k_ksyms.c b/arch/m68k/kernel/m68k_ksyms.c
index 73e2f5e..3d7f200 100644
--- a/arch/m68k/kernel/m68k_ksyms.c
+++ b/arch/m68k/kernel/m68k_ksyms.c
@@ -23,8 +23,6 @@
 asmlinkage long long __muldi3 (long long, long long);
 extern char m68k_debug_device[];
 
-extern void dump_thread(struct pt_regs *, struct user *);
-
 /* platform dependent support */
 
 EXPORT_SYMBOL(m68k_machtype);
diff --git a/arch/m68k/kernel/process.c b/arch/m68k/kernel/process.c
index 13d10932..3f9cb55 100644
--- a/arch/m68k/kernel/process.c
+++ b/arch/m68k/kernel/process.c
@@ -238,10 +238,9 @@
 {
 	struct pt_regs * childregs;
 	struct switch_stack * childstack, *stack;
-	unsigned long stack_offset, *retp;
+	unsigned long *retp;
 
-	stack_offset = THREAD_SIZE - sizeof(struct pt_regs);
-	childregs = (struct pt_regs *) ((unsigned long) (p->thread_info) + stack_offset);
+	childregs = (struct pt_regs *) (task_stack_page(p) + THREAD_SIZE) - 1;
 
 	*childregs = *regs;
 	childregs->d0 = 0;
@@ -386,7 +385,7 @@
 	if (!p || p == current || p->state == TASK_RUNNING)
 		return 0;
 
-	stack_page = (unsigned long)(p->thread_info);
+	stack_page = (unsigned long)task_stack_page(p);
 	fp = ((struct switch_stack *)p->thread.ksp)->a6;
 	do {
 		if (fp < stack_page+sizeof(struct thread_info) ||
diff --git a/arch/m68k/kernel/setup.c b/arch/m68k/kernel/setup.c
index d6ca992..750d5b3 100644
--- a/arch/m68k/kernel/setup.c
+++ b/arch/m68k/kernel/setup.c
@@ -84,9 +84,6 @@
 void (*mach_halt)( void );
 void (*mach_power_off)( void );
 long mach_max_dma_address = 0x00ffffff; /* default set to the lower 16MB */
-#if defined(CONFIG_AMIGA_FLOPPY) || defined(CONFIG_ATARI_FLOPPY)
-void (*mach_floppy_setup) (char *, int *) __initdata = NULL;
-#endif
 #ifdef CONFIG_HEARTBEAT
 void (*mach_heartbeat) (int);
 EXPORT_SYMBOL(mach_heartbeat);
@@ -100,6 +97,8 @@
 #if defined(CONFIG_ISA) && defined(MULTI_ISA)
 int isa_type;
 int isa_sex;
+EXPORT_SYMBOL(isa_type);
+EXPORT_SYMBOL(isa_sex);
 #endif
 
 extern int amiga_parse_bootinfo(const struct bi_record *);
@@ -280,6 +279,10 @@
 	    }
 	}
 
+#ifdef CONFIG_DUMMY_CONSOLE
+	conswitchp = &dummy_con;
+#endif
+
 	switch (m68k_machtype) {
 #ifdef CONFIG_AMIGA
 	    case MACH_AMIGA:
@@ -521,16 +524,6 @@
     return(len);
 }
 
-
-#if defined(CONFIG_AMIGA_FLOPPY) || defined(CONFIG_ATARI_FLOPPY)
-void __init floppy_setup(char *str, int *ints)
-{
-	if (mach_floppy_setup)
-		mach_floppy_setup (str, ints);
-}
-
-#endif
-
 void check_bugs(void)
 {
 #ifndef CONFIG_M68KFPU_EMU
diff --git a/arch/m68k/kernel/signal.c b/arch/m68k/kernel/signal.c
index 9c636a4..866917b 100644
--- a/arch/m68k/kernel/signal.c
+++ b/arch/m68k/kernel/signal.c
@@ -96,7 +96,7 @@
 asmlinkage int
 do_rt_sigsuspend(struct pt_regs *regs)
 {
-	sigset_t *unewset = (sigset_t *)regs->d1;
+	sigset_t __user *unewset = (sigset_t __user *)regs->d1;
 	size_t sigsetsize = (size_t)regs->d2;
 	sigset_t saveset, newset;
 
@@ -122,8 +122,8 @@
 }
 
 asmlinkage int
-sys_sigaction(int sig, const struct old_sigaction *act,
-	      struct old_sigaction *oact)
+sys_sigaction(int sig, const struct old_sigaction __user *act,
+	      struct old_sigaction __user *oact)
 {
 	struct k_sigaction new_ka, old_ka;
 	int ret;
@@ -154,7 +154,7 @@
 }
 
 asmlinkage int
-sys_sigaltstack(const stack_t *uss, stack_t *uoss)
+sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss)
 {
 	return do_sigaltstack(uss, uoss, rdusp());
 }
@@ -169,10 +169,10 @@
 
 struct sigframe
 {
-	char *pretcode;
+	char __user *pretcode;
 	int sig;
 	int code;
-	struct sigcontext *psc;
+	struct sigcontext __user *psc;
 	char retcode[8];
 	unsigned long extramask[_NSIG_WORDS-1];
 	struct sigcontext sc;
@@ -180,10 +180,10 @@
 
 struct rt_sigframe
 {
-	char *pretcode;
+	char __user *pretcode;
 	int sig;
-	struct siginfo *pinfo;
-	void *puc;
+	struct siginfo __user *pinfo;
+	void __user *puc;
 	char retcode[8];
 	struct siginfo info;
 	struct ucontext uc;
@@ -248,7 +248,7 @@
 #define uc_formatvec	uc_filler[FPCONTEXT_SIZE/4]
 #define uc_extra	uc_filler[FPCONTEXT_SIZE/4+1]
 
-static inline int rt_restore_fpu_state(struct ucontext *uc)
+static inline int rt_restore_fpu_state(struct ucontext __user *uc)
 {
 	unsigned char fpstate[FPCONTEXT_SIZE];
 	int context_size = CPU_IS_060 ? 8 : 0;
@@ -267,7 +267,7 @@
 		return 0;
 	}
 
-	if (__get_user(*(long *)fpstate, (long *)&uc->uc_fpstate))
+	if (__get_user(*(long *)fpstate, (long __user *)&uc->uc_fpstate))
 		goto out;
 	if (CPU_IS_060 ? fpstate[2] : fpstate[0]) {
 		if (!CPU_IS_060)
@@ -306,7 +306,7 @@
 				    "m" (*fpregs.f_fpcntl));
 	}
 	if (context_size &&
-	    __copy_from_user(fpstate + 4, (long *)&uc->uc_fpstate + 1,
+	    __copy_from_user(fpstate + 4, (long __user *)&uc->uc_fpstate + 1,
 			     context_size))
 		goto out;
 	__asm__ volatile (".chip 68k/68881\n\t"
@@ -319,7 +319,7 @@
 }
 
 static inline int
-restore_sigcontext(struct pt_regs *regs, struct sigcontext *usc, void *fp,
+restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *usc, void __user *fp,
 		   int *pd0)
 {
 	int fsize, formatvec;
@@ -404,10 +404,10 @@
 
 static inline int
 rt_restore_ucontext(struct pt_regs *regs, struct switch_stack *sw,
-		    struct ucontext *uc, int *pd0)
+		    struct ucontext __user *uc, int *pd0)
 {
 	int fsize, temp;
-	greg_t *gregs = uc->uc_mcontext.gregs;
+	greg_t __user *gregs = uc->uc_mcontext.gregs;
 	unsigned long usp;
 	int err;
 
@@ -506,7 +506,7 @@
 	struct switch_stack *sw = (struct switch_stack *) &__unused;
 	struct pt_regs *regs = (struct pt_regs *) (sw + 1);
 	unsigned long usp = rdusp();
-	struct sigframe *frame = (struct sigframe *)(usp - 4);
+	struct sigframe __user *frame = (struct sigframe __user *)(usp - 4);
 	sigset_t set;
 	int d0;
 
@@ -536,7 +536,7 @@
 	struct switch_stack *sw = (struct switch_stack *) &__unused;
 	struct pt_regs *regs = (struct pt_regs *) (sw + 1);
 	unsigned long usp = rdusp();
-	struct rt_sigframe *frame = (struct rt_sigframe *)(usp - 4);
+	struct rt_sigframe __user *frame = (struct rt_sigframe __user *)(usp - 4);
 	sigset_t set;
 	int d0;
 
@@ -596,7 +596,7 @@
 	}
 }
 
-static inline int rt_save_fpu_state(struct ucontext *uc, struct pt_regs *regs)
+static inline int rt_save_fpu_state(struct ucontext __user *uc, struct pt_regs *regs)
 {
 	unsigned char fpstate[FPCONTEXT_SIZE];
 	int context_size = CPU_IS_060 ? 8 : 0;
@@ -617,7 +617,7 @@
 			  ".chip 68k"
 			  : : "m" (*fpstate) : "memory");
 
-	err |= __put_user(*(long *)fpstate, (long *)&uc->uc_fpstate);
+	err |= __put_user(*(long *)fpstate, (long __user *)&uc->uc_fpstate);
 	if (CPU_IS_060 ? fpstate[2] : fpstate[0]) {
 		fpregset_t fpregs;
 		if (!CPU_IS_060)
@@ -642,7 +642,7 @@
 				    sizeof(fpregs));
 	}
 	if (context_size)
-		err |= copy_to_user((long *)&uc->uc_fpstate + 1, fpstate + 4,
+		err |= copy_to_user((long __user *)&uc->uc_fpstate + 1, fpstate + 4,
 				    context_size);
 	return err;
 }
@@ -662,10 +662,10 @@
 	save_fpu_state(sc, regs);
 }
 
-static inline int rt_setup_ucontext(struct ucontext *uc, struct pt_regs *regs)
+static inline int rt_setup_ucontext(struct ucontext __user *uc, struct pt_regs *regs)
 {
 	struct switch_stack *sw = (struct switch_stack *)regs - 1;
-	greg_t *gregs = uc->uc_mcontext.gregs;
+	greg_t __user *gregs = uc->uc_mcontext.gregs;
 	int err = 0;
 
 	err |= __put_user(MCONTEXT_VERSION, &uc->uc_mcontext.version);
@@ -753,7 +753,7 @@
 	}
 }
 
-static inline void *
+static inline void __user *
 get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size)
 {
 	unsigned long usp;
@@ -766,13 +766,13 @@
 		if (!on_sig_stack(usp))
 			usp = current->sas_ss_sp + current->sas_ss_size;
 	}
-	return (void *)((usp - frame_size) & -8UL);
+	return (void __user *)((usp - frame_size) & -8UL);
 }
 
 static void setup_frame (int sig, struct k_sigaction *ka,
 			 sigset_t *set, struct pt_regs *regs)
 {
-	struct sigframe *frame;
+	struct sigframe __user *frame;
 	int fsize = frame_extra_sizes[regs->format];
 	struct sigcontext context;
 	int err = 0;
@@ -813,7 +813,7 @@
 	err |= __put_user(frame->retcode, &frame->pretcode);
 	/* moveq #,d0; trap #0 */
 	err |= __put_user(0x70004e40 + (__NR_sigreturn << 16),
-			  (long *)(frame->retcode));
+			  (long __user *)(frame->retcode));
 
 	if (err)
 		goto give_sigsegv;
@@ -849,7 +849,7 @@
 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;
+	struct rt_sigframe __user *frame;
 	int fsize = frame_extra_sizes[regs->format];
 	int err = 0;
 
@@ -880,8 +880,8 @@
 
 	/* Create the ucontext.  */
 	err |= __put_user(0, &frame->uc.uc_flags);
-	err |= __put_user(0, &frame->uc.uc_link);
-	err |= __put_user((void *)current->sas_ss_sp,
+	err |= __put_user(NULL, &frame->uc.uc_link);
+	err |= __put_user((void __user *)current->sas_ss_sp,
 			  &frame->uc.uc_stack.ss_sp);
 	err |= __put_user(sas_ss_flags(rdusp()),
 			  &frame->uc.uc_stack.ss_flags);
@@ -893,8 +893,8 @@
 	err |= __put_user(frame->retcode, &frame->pretcode);
 	/* moveq #,d0; notb d0; trap #0 */
 	err |= __put_user(0x70004600 + ((__NR_rt_sigreturn ^ 0xff) << 16),
-			  (long *)(frame->retcode + 0));
-	err |= __put_user(0x4e40, (short *)(frame->retcode + 4));
+			  (long __user *)(frame->retcode + 0));
+	err |= __put_user(0x4e40, (short __user *)(frame->retcode + 4));
 
 	if (err)
 		goto give_sigsegv;
diff --git a/arch/m68k/kernel/sys_m68k.c b/arch/m68k/kernel/sys_m68k.c
index 2ed7b78..143c552 100644
--- a/arch/m68k/kernel/sys_m68k.c
+++ b/arch/m68k/kernel/sys_m68k.c
@@ -6,6 +6,7 @@
  * platform.
  */
 
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/sched.h>
 #include <linux/mm.h>
@@ -31,7 +32,7 @@
  * sys_pipe() is the normal C calling standard for creating
  * a pipe. It's not the way unix traditionally does this, though.
  */
-asmlinkage int sys_pipe(unsigned long * fildes)
+asmlinkage int sys_pipe(unsigned long __user * fildes)
 {
 	int fd[2];
 	int error;
@@ -93,7 +94,7 @@
 	unsigned long offset;
 };
 
-asmlinkage int old_mmap(struct mmap_arg_struct *arg)
+asmlinkage int old_mmap(struct mmap_arg_struct __user *arg)
 {
 	struct mmap_arg_struct a;
 	int error = -EFAULT;
@@ -159,11 +160,11 @@
 
 struct sel_arg_struct {
 	unsigned long n;
-	fd_set *inp, *outp, *exp;
-	struct timeval *tvp;
+	fd_set __user *inp, *outp, *exp;
+	struct timeval __user *tvp;
 };
 
-asmlinkage int old_select(struct sel_arg_struct *arg)
+asmlinkage int old_select(struct sel_arg_struct __user *arg)
 {
 	struct sel_arg_struct a;
 
@@ -179,7 +180,7 @@
  * This is really horribly ugly.
  */
 asmlinkage int sys_ipc (uint call, int first, int second,
-			int third, void *ptr, long fifth)
+			int third, void __user *ptr, long fifth)
 {
 	int version, ret;
 
@@ -189,14 +190,14 @@
 	if (call <= SEMCTL)
 		switch (call) {
 		case SEMOP:
-			return sys_semop (first, (struct sembuf *)ptr, second);
+			return sys_semop (first, ptr, second);
 		case SEMGET:
 			return sys_semget (first, second, third);
 		case SEMCTL: {
 			union semun fourth;
 			if (!ptr)
 				return -EINVAL;
-			if (get_user(fourth.__pad, (void **) ptr))
+			if (get_user(fourth.__pad, (void __user *__user *) ptr))
 				return -EFAULT;
 			return sys_semctl (first, second, third, fourth);
 			}
@@ -206,31 +207,26 @@
 	if (call <= MSGCTL)
 		switch (call) {
 		case MSGSND:
-			return sys_msgsnd (first, (struct msgbuf *) ptr,
-					  second, third);
+			return sys_msgsnd (first, ptr, second, third);
 		case MSGRCV:
 			switch (version) {
 			case 0: {
 				struct ipc_kludge tmp;
 				if (!ptr)
 					return -EINVAL;
-				if (copy_from_user (&tmp,
-						    (struct ipc_kludge *)ptr,
-						    sizeof (tmp)))
+				if (copy_from_user (&tmp, ptr, sizeof (tmp)))
 					return -EFAULT;
 				return sys_msgrcv (first, tmp.msgp, second,
 						   tmp.msgtyp, third);
 				}
 			default:
-				return sys_msgrcv (first,
-						   (struct msgbuf *) ptr,
+				return sys_msgrcv (first, ptr,
 						   second, fifth, third);
 			}
 		case MSGGET:
 			return sys_msgget ((key_t) first, second);
 		case MSGCTL:
-			return sys_msgctl (first, second,
-					   (struct msqid_ds *) ptr);
+			return sys_msgctl (first, second, ptr);
 		default:
 			return -ENOSYS;
 		}
@@ -240,20 +236,18 @@
 			switch (version) {
 			default: {
 				ulong raddr;
-				ret = do_shmat (first, (char *) ptr,
-						 second, &raddr);
+				ret = do_shmat (first, ptr, second, &raddr);
 				if (ret)
 					return ret;
-				return put_user (raddr, (ulong *) third);
+				return put_user (raddr, (ulong __user *) third);
 			}
 			}
 		case SHMDT:
-			return sys_shmdt ((char *)ptr);
+			return sys_shmdt (ptr);
 		case SHMGET:
 			return sys_shmget (first, second, third);
 		case SHMCTL:
-			return sys_shmctl (first, second,
-					   (struct shmid_ds *) ptr);
+			return sys_shmctl (first, second, ptr);
 		default:
 			return -ENOSYS;
 		}
diff --git a/arch/m68k/kernel/traps.c b/arch/m68k/kernel/traps.c
index deb36e8..cdf58fb 100644
--- a/arch/m68k/kernel/traps.c
+++ b/arch/m68k/kernel/traps.c
@@ -169,25 +169,25 @@
 
 	if (CPU_IS_060 && !FPU_IS_EMU) {
 		/* set up IFPSP entry points */
-		asmlinkage void snan_vec(void) asm ("_060_fpsp_snan");
-		asmlinkage void operr_vec(void) asm ("_060_fpsp_operr");
-		asmlinkage void ovfl_vec(void) asm ("_060_fpsp_ovfl");
-		asmlinkage void unfl_vec(void) asm ("_060_fpsp_unfl");
-		asmlinkage void dz_vec(void) asm ("_060_fpsp_dz");
-		asmlinkage void inex_vec(void) asm ("_060_fpsp_inex");
-		asmlinkage void fline_vec(void) asm ("_060_fpsp_fline");
-		asmlinkage void unsupp_vec(void) asm ("_060_fpsp_unsupp");
-		asmlinkage void effadd_vec(void) asm ("_060_fpsp_effadd");
+		asmlinkage void snan_vec6(void) asm ("_060_fpsp_snan");
+		asmlinkage void operr_vec6(void) asm ("_060_fpsp_operr");
+		asmlinkage void ovfl_vec6(void) asm ("_060_fpsp_ovfl");
+		asmlinkage void unfl_vec6(void) asm ("_060_fpsp_unfl");
+		asmlinkage void dz_vec6(void) asm ("_060_fpsp_dz");
+		asmlinkage void inex_vec6(void) asm ("_060_fpsp_inex");
+		asmlinkage void fline_vec6(void) asm ("_060_fpsp_fline");
+		asmlinkage void unsupp_vec6(void) asm ("_060_fpsp_unsupp");
+		asmlinkage void effadd_vec6(void) asm ("_060_fpsp_effadd");
 
-		vectors[VEC_FPNAN] = snan_vec;
-		vectors[VEC_FPOE] = operr_vec;
-		vectors[VEC_FPOVER] = ovfl_vec;
-		vectors[VEC_FPUNDER] = unfl_vec;
-		vectors[VEC_FPDIVZ] = dz_vec;
-		vectors[VEC_FPIR] = inex_vec;
-		vectors[VEC_LINE11] = fline_vec;
-		vectors[VEC_FPUNSUP] = unsupp_vec;
-		vectors[VEC_UNIMPEA] = effadd_vec;
+		vectors[VEC_FPNAN] = snan_vec6;
+		vectors[VEC_FPOE] = operr_vec6;
+		vectors[VEC_FPOVER] = ovfl_vec6;
+		vectors[VEC_FPUNDER] = unfl_vec6;
+		vectors[VEC_FPDIVZ] = dz_vec6;
+		vectors[VEC_FPIR] = inex_vec6;
+		vectors[VEC_LINE11] = fline_vec6;
+		vectors[VEC_FPUNSUP] = unsupp_vec6;
+		vectors[VEC_UNIMPEA] = effadd_vec6;
 	}
 
         /* if running on an amiga, make the NMI interrupt do nothing */
diff --git a/arch/m68k/kernel/vmlinux-std.lds b/arch/m68k/kernel/vmlinux-std.lds
index e58654f..69d1d3d 100644
--- a/arch/m68k/kernel/vmlinux-std.lds
+++ b/arch/m68k/kernel/vmlinux-std.lds
@@ -13,6 +13,7 @@
   .text : {
 	*(.text)
 	SCHED_TEXT
+	LOCK_TEXT
 	*(.fixup)
 	*(.gnu.warning)
 	} :text = 0x4e75
diff --git a/arch/m68k/kernel/vmlinux-sun3.lds b/arch/m68k/kernel/vmlinux-sun3.lds
index cc37e8d..65cc39c 100644
--- a/arch/m68k/kernel/vmlinux-sun3.lds
+++ b/arch/m68k/kernel/vmlinux-sun3.lds
@@ -14,6 +14,7 @@
 	*(.head)
 	*(.text)
 	SCHED_TEXT
+	LOCK_TEXT
 	*(.fixup)
 	*(.gnu.warning)
 	} :text = 0x4e75
@@ -66,7 +67,7 @@
 	__initramfs_end = .;
 	. = ALIGN(8192);
 	__init_end = .;
-	.init.task : { *(init_task) }
+	.data.init.task : { *(.data.init_task) }
 
 
   .bss : { *(.bss) }		/* BSS */
diff --git a/arch/m68k/lib/checksum.c b/arch/m68k/lib/checksum.c
index 4a5c544..cb13c6e 100644
--- a/arch/m68k/lib/checksum.c
+++ b/arch/m68k/lib/checksum.c
@@ -134,7 +134,7 @@
  */
 
 unsigned int
-csum_partial_copy_from_user(const unsigned char *src, unsigned char *dst,
+csum_partial_copy_from_user(const unsigned char __user *src, unsigned char *dst,
 			    int len, int sum, int *csum_err)
 {
 	/*
diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c
index cd19cbb..14f8d3f4 100644
--- a/arch/m68k/mac/config.c
+++ b/arch/m68k/mac/config.c
@@ -212,9 +212,6 @@
 	mach_reset           = mac_reset;
 	mach_halt            = mac_poweroff;
 	mach_power_off       = mac_poweroff;
-#ifdef CONFIG_DUMMY_CONSOLE
-	conswitchp	         = &dummy_con;
-#endif
 	mach_max_dma_address = 0xffffffff;
 #if 0
 	mach_debug_init	 = mac_debug_init;
diff --git a/arch/m68k/mac/iop.c b/arch/m68k/mac/iop.c
index d889ba8..9179a37 100644
--- a/arch/m68k/mac/iop.c
+++ b/arch/m68k/mac/iop.c
@@ -293,8 +293,8 @@
 	}
 
 	for (i = 0 ; i < NUM_IOP_CHAN ; i++) {
-		iop_send_queue[IOP_NUM_SCC][i] = 0;
-		iop_send_queue[IOP_NUM_ISM][i] = 0;
+		iop_send_queue[IOP_NUM_SCC][i] = NULL;
+		iop_send_queue[IOP_NUM_ISM][i] = NULL;
 		iop_listeners[IOP_NUM_SCC][i].devname = NULL;
 		iop_listeners[IOP_NUM_SCC][i].handler = NULL;
 		iop_listeners[IOP_NUM_ISM][i].devname = NULL;
diff --git a/arch/m68k/mac/misc.c b/arch/m68k/mac/misc.c
index 5b80d7c..bbb0c3b 100644
--- a/arch/m68k/mac/misc.c
+++ b/arch/m68k/mac/misc.c
@@ -39,72 +39,163 @@
 extern struct mac_booter_data mac_bi_data;
 static void (*rom_reset)(void);
 
-#ifdef CONFIG_ADB
-/*
- * Return the current time as the number of seconds since January 1, 1904.
- */
-
-static long adb_read_time(void)
+#ifdef CONFIG_ADB_CUDA
+static long cuda_read_time(void)
 {
-	volatile struct adb_request req;
+	struct adb_request req;
 	long time;
 
-	adb_request((struct adb_request *) &req, NULL,
-			ADBREQ_RAW|ADBREQ_SYNC,
-			2, CUDA_PACKET, CUDA_GET_TIME);
+	if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_GET_TIME) < 0)
+		return 0;
+	while (!req.complete)
+		cuda_poll();
 
 	time = (req.reply[3] << 24) | (req.reply[4] << 16)
 		| (req.reply[5] << 8) | req.reply[6];
 	return time - RTC_OFFSET;
 }
 
-/*
- * Set the current system time
- */
-
-static void adb_write_time(long data)
+static void cuda_write_time(long data)
 {
-	volatile struct adb_request req;
-
+	struct adb_request req;
 	data += RTC_OFFSET;
+	if (cuda_request(&req, NULL, 6, CUDA_PACKET, CUDA_SET_TIME,
+			(data >> 24) & 0xFF, (data >> 16) & 0xFF,
+			(data >> 8) & 0xFF, data & 0xFF) < 0)
+		return;
+	while (!req.complete)
+		cuda_poll();
+}
 
-	adb_request((struct adb_request *) &req, NULL,
-			ADBREQ_RAW|ADBREQ_SYNC,
-			6, CUDA_PACKET, CUDA_SET_TIME,
+static __u8 cuda_read_pram(int offset)
+{
+	struct adb_request req;
+	if (cuda_request(&req, NULL, 4, CUDA_PACKET, CUDA_GET_PRAM,
+			(offset >> 8) & 0xFF, offset & 0xFF) < 0)
+		return 0;
+	while (!req.complete)
+		cuda_poll();
+	return req.reply[3];
+}
+
+static void cuda_write_pram(int offset, __u8 data)
+{
+	struct adb_request req;
+	if (cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_SET_PRAM,
+			(offset >> 8) & 0xFF, offset & 0xFF, data) < 0)
+		return;
+	while (!req.complete)
+		cuda_poll();
+}
+#else
+#define cuda_read_time() 0
+#define cuda_write_time(n)
+#define cuda_read_pram NULL
+#define cuda_write_pram NULL
+#endif
+
+#ifdef CONFIG_ADB_PMU68K
+static long pmu_read_time(void)
+{
+	struct adb_request req;
+	long time;
+
+	if (pmu_request(&req, NULL, 1, PMU_READ_RTC) < 0)
+		return 0;
+	while (!req.complete)
+		pmu_poll();
+
+	time = (req.reply[0] << 24) | (req.reply[1] << 16)
+		| (req.reply[2] << 8) | req.reply[3];
+	return time - RTC_OFFSET;
+}
+
+static void pmu_write_time(long data)
+{
+	struct adb_request req;
+	data += RTC_OFFSET;
+	if (pmu_request(&req, NULL, 5, PMU_SET_RTC,
+			(data >> 24) & 0xFF, (data >> 16) & 0xFF,
+			(data >> 8) & 0xFF, data & 0xFF) < 0)
+		return;
+	while (!req.complete)
+		pmu_poll();
+}
+
+static __u8 pmu_read_pram(int offset)
+{
+	struct adb_request req;
+	if (pmu_request(&req, NULL, 3, PMU_READ_NVRAM,
+			(offset >> 8) & 0xFF, offset & 0xFF) < 0)
+		return 0;
+	while (!req.complete)
+		pmu_poll();
+	return req.reply[3];
+}
+
+static void pmu_write_pram(int offset, __u8 data)
+{
+	struct adb_request req;
+	if (pmu_request(&req, NULL, 4, PMU_WRITE_NVRAM,
+			(offset >> 8) & 0xFF, offset & 0xFF, data) < 0)
+		return;
+	while (!req.complete)
+		pmu_poll();
+}
+#else
+#define pmu_read_time() 0
+#define pmu_write_time(n)
+#define pmu_read_pram NULL
+#define pmu_write_pram NULL
+#endif
+
+#ifdef CONFIG_ADB_MACIISI
+extern int maciisi_request(struct adb_request *req,
+			void (*done)(struct adb_request *), int nbytes, ...);
+
+static long maciisi_read_time(void)
+{
+	struct adb_request req;
+	long time;
+
+	if (maciisi_request(&req, NULL, 2, CUDA_PACKET, CUDA_GET_TIME))
+		return 0;
+
+	time = (req.reply[3] << 24) | (req.reply[4] << 16)
+		| (req.reply[5] << 8) | req.reply[6];
+	return time - RTC_OFFSET;
+}
+
+static void maciisi_write_time(long data)
+{
+	struct adb_request req;
+	data += RTC_OFFSET;
+	maciisi_request(&req, NULL, 6, CUDA_PACKET, CUDA_SET_TIME,
 			(data >> 24) & 0xFF, (data >> 16) & 0xFF,
 			(data >> 8) & 0xFF, data & 0xFF);
 }
 
-/*
- * Get a byte from the NVRAM
- */
-
-static __u8 adb_read_pram(int offset)
+static __u8 maciisi_read_pram(int offset)
 {
-	volatile struct adb_request req;
-
-	adb_request((struct adb_request *) &req, NULL,
-			ADBREQ_RAW|ADBREQ_SYNC,
-			4, CUDA_PACKET, CUDA_GET_PRAM,
-			(offset >> 8) & 0xFF, offset & 0xFF);
+	struct adb_request req;
+	if (maciisi_request(&req, NULL, 4, CUDA_PACKET, CUDA_GET_PRAM,
+			(offset >> 8) & 0xFF, offset & 0xFF))
+		return 0;
 	return req.reply[3];
 }
 
-/*
- * Write a byte to the NVRAM
- */
-
-static void adb_write_pram(int offset, __u8 data)
+static void maciisi_write_pram(int offset, __u8 data)
 {
-	volatile struct adb_request req;
-
-	adb_request((struct adb_request *) &req, NULL,
-			ADBREQ_RAW|ADBREQ_SYNC,
-			5, CUDA_PACKET, CUDA_SET_PRAM,
-			(offset >> 8) & 0xFF, offset & 0xFF,
-			data);
+	struct adb_request req;
+	maciisi_request(&req, NULL, 5, CUDA_PACKET, CUDA_SET_PRAM,
+			(offset >> 8) & 0xFF, offset & 0xFF, data);
 }
-#endif /* CONFIG_ADB */
+#else
+#define maciisi_read_time() 0
+#define maciisi_write_time(n)
+#define maciisi_read_pram NULL
+#define maciisi_write_pram NULL
+#endif
 
 /*
  * VIA PRAM/RTC access routines
@@ -305,42 +396,55 @@
 
 static void cuda_restart(void)
 {
-	adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC,
-			2, CUDA_PACKET, CUDA_RESET_SYSTEM);
+	struct adb_request req;
+	if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_RESET_SYSTEM) < 0)
+		return;
+	while (!req.complete)
+		cuda_poll();
 }
 
 static void cuda_shutdown(void)
 {
-	adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC,
-			2, CUDA_PACKET, CUDA_POWERDOWN);
+	struct adb_request req;
+	if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_POWERDOWN) < 0)
+		return;
+	while (!req.complete)
+		cuda_poll();
 }
 
 #endif /* CONFIG_ADB_CUDA */
 
-#ifdef CONFIG_ADB_PMU
+#ifdef CONFIG_ADB_PMU68K
 
 void pmu_restart(void)
 {
-	adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC,
-			3, PMU_PACKET, PMU_SET_INTR_MASK,
-			PMU_INT_ADB|PMU_INT_TICK);
-
-	adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC,
-			2, PMU_PACKET, PMU_RESET);
+	struct adb_request req;
+	if (pmu_request(&req, NULL,
+			2, PMU_SET_INTR_MASK, PMU_INT_ADB|PMU_INT_TICK) < 0)
+		return;
+	while (!req.complete)
+		pmu_poll();
+	if (pmu_request(&req, NULL, 1, PMU_RESET) < 0)
+		return;
+	while (!req.complete)
+		pmu_poll();
 }
 
 void pmu_shutdown(void)
 {
-	adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC,
-			3, PMU_PACKET, PMU_SET_INTR_MASK,
-			PMU_INT_ADB|PMU_INT_TICK);
-
-	adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC,
-			6, PMU_PACKET, PMU_SHUTDOWN,
-			'M', 'A', 'T', 'T');
+	struct adb_request req;
+	if (pmu_request(&req, NULL,
+			2, PMU_SET_INTR_MASK, PMU_INT_ADB|PMU_INT_TICK) < 0)
+		return;
+	while (!req.complete)
+		pmu_poll();
+	if (pmu_request(&req, NULL, 5, PMU_SHUTDOWN, 'M', 'A', 'T', 'T') < 0)
+		return;
+	while (!req.complete)
+		pmu_poll();
 }
 
-#endif /* CONFIG_ADB_PMU */
+#endif
 
 /*
  *-------------------------------------------------------------------
@@ -351,21 +455,22 @@
 
 void mac_pram_read(int offset, __u8 *buffer, int len)
 {
-	__u8 (*func)(int) = NULL;
+	__u8 (*func)(int);
 	int i;
 
-	if (macintosh_config->adb_type == MAC_ADB_IISI ||
-	    macintosh_config->adb_type == MAC_ADB_PB1 ||
-	    macintosh_config->adb_type == MAC_ADB_PB2 ||
-	    macintosh_config->adb_type == MAC_ADB_CUDA) {
-#ifdef CONFIG_ADB
-		func = adb_read_pram;
-#else
-		return;
-#endif
-	} else {
+	switch(macintosh_config->adb_type) {
+	case MAC_ADB_IISI:
+		func = maciisi_read_pram; break;
+	case MAC_ADB_PB1:
+	case MAC_ADB_PB2:
+		func = pmu_read_pram; break;
+	case MAC_ADB_CUDA:
+		func = cuda_read_pram; break;
+	default:
 		func = via_read_pram;
 	}
+	if (!func)
+		return;
 	for (i = 0 ; i < len ; i++) {
 		buffer[i] = (*func)(offset++);
 	}
@@ -373,21 +478,22 @@
 
 void mac_pram_write(int offset, __u8 *buffer, int len)
 {
-	void (*func)(int, __u8) = NULL;
+	void (*func)(int, __u8);
 	int i;
 
-	if (macintosh_config->adb_type == MAC_ADB_IISI ||
-	    macintosh_config->adb_type == MAC_ADB_PB1 ||
-	    macintosh_config->adb_type == MAC_ADB_PB2 ||
-	    macintosh_config->adb_type == MAC_ADB_CUDA) {
-#ifdef CONFIG_ADB
-		func = adb_write_pram;
-#else
-		return;
-#endif
-	} else {
+	switch(macintosh_config->adb_type) {
+	case MAC_ADB_IISI:
+		func = maciisi_write_pram; break;
+	case MAC_ADB_PB1:
+	case MAC_ADB_PB2:
+		func = pmu_write_pram; break;
+	case MAC_ADB_CUDA:
+		func = cuda_write_pram; break;
+	default:
 		func = via_write_pram;
 	}
+	if (!func)
+		return;
 	for (i = 0 ; i < len ; i++) {
 		(*func)(offset++, buffer[i]);
 	}
@@ -408,7 +514,7 @@
 	} else if (macintosh_config->adb_type == MAC_ADB_CUDA) {
 		cuda_shutdown();
 #endif
-#ifdef CONFIG_ADB_PMU
+#ifdef CONFIG_ADB_PMU68K
 	} else if (macintosh_config->adb_type == MAC_ADB_PB1
 		|| macintosh_config->adb_type == MAC_ADB_PB2) {
 		pmu_shutdown();
@@ -448,7 +554,7 @@
 	} else if (macintosh_config->adb_type == MAC_ADB_CUDA) {
 		cuda_restart();
 #endif
-#ifdef CONFIG_ADB_PMU
+#ifdef CONFIG_ADB_PMU68K
 	} else if (macintosh_config->adb_type == MAC_ADB_PB1
 		|| macintosh_config->adb_type == MAC_ADB_PB2) {
 		pmu_restart();
@@ -466,12 +572,13 @@
 		/* make a 1-to-1 mapping, using the transparent tran. reg. */
 		unsigned long virt = (unsigned long) mac_reset;
 		unsigned long phys = virt_to_phys(mac_reset);
+		unsigned long addr = (phys&0xFF000000)|0x8777;
 		unsigned long offset = phys-virt;
 		local_irq_disable(); /* lets not screw this up, ok? */
 		__asm__ __volatile__(".chip 68030\n\t"
 				     "pmove %0,%/tt0\n\t"
 				     ".chip 68k"
-				     : : "m" ((phys&0xFF000000)|0x8777));
+				     : : "m" (addr));
 		/* Now jump to physical address so we can disable MMU */
 		__asm__ __volatile__(
                     ".chip 68030\n\t"
@@ -588,20 +695,22 @@
 	unsigned long now;
 
 	if (!op) { /* read */
-		if (macintosh_config->adb_type == MAC_ADB_II) {
+		switch (macintosh_config->adb_type) {
+		case MAC_ADB_II:
+		case MAC_ADB_IOP:
 			now = via_read_time();
-		} else
-#ifdef CONFIG_ADB
-		if ((macintosh_config->adb_type == MAC_ADB_IISI) ||
-			   (macintosh_config->adb_type == MAC_ADB_PB1) ||
-			   (macintosh_config->adb_type == MAC_ADB_PB2) ||
-			   (macintosh_config->adb_type == MAC_ADB_CUDA)) {
-			now = adb_read_time();
-		} else
-#endif
-		if (macintosh_config->adb_type == MAC_ADB_IOP) {
-			now = via_read_time();
-		} else {
+			break;
+		case MAC_ADB_IISI:
+			now = maciisi_read_time();
+			break;
+		case MAC_ADB_PB1:
+		case MAC_ADB_PB2:
+			now = pmu_read_time();
+			break;
+		case MAC_ADB_CUDA:
+			now = cuda_read_time();
+			break;
+		default:
 			now = 0;
 		}
 
@@ -619,15 +728,20 @@
 		now = mktime(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
 			     t->tm_hour, t->tm_min, t->tm_sec);
 
-		if (macintosh_config->adb_type == MAC_ADB_II) {
+		switch (macintosh_config->adb_type) {
+		case MAC_ADB_II:
+		case MAC_ADB_IOP:
 			via_write_time(now);
-		} else if ((macintosh_config->adb_type == MAC_ADB_IISI) ||
-			   (macintosh_config->adb_type == MAC_ADB_PB1) ||
-			   (macintosh_config->adb_type == MAC_ADB_PB2) ||
-			   (macintosh_config->adb_type == MAC_ADB_CUDA)) {
-			adb_write_time(now);
-		} else if (macintosh_config->adb_type == MAC_ADB_IOP) {
-			via_write_time(now);
+			break;
+		case MAC_ADB_CUDA:
+			cuda_write_time(now);
+			break;
+		case MAC_ADB_PB1:
+		case MAC_ADB_PB2:
+			pmu_write_time(now);
+			break;
+		case MAC_ADB_IISI:
+			maciisi_write_time(now);
 		}
 #endif
 	}
diff --git a/arch/m68k/math-emu/multi_arith.h b/arch/m68k/math-emu/multi_arith.h
index 02251e5..4ad0ca9 100644
--- a/arch/m68k/math-emu/multi_arith.h
+++ b/arch/m68k/math-emu/multi_arith.h
@@ -366,7 +366,7 @@
 
 #define fp_mul64(desth, destl, src1, src2) ({				\
 	asm ("mulu.l %2,%1:%0" : "=d" (destl), "=d" (desth)		\
-		: "g" (src1), "0" (src2));				\
+		: "dm" (src1), "0" (src2));				\
 })
 #define fp_div64(quot, rem, srch, srcl, div)				\
 	asm ("divu.l %2,%1:%0" : "=d" (quot), "=d" (rem)		\
diff --git a/arch/m68k/mm/kmap.c b/arch/m68k/mm/kmap.c
index fe2383e..85ad19a 100644
--- a/arch/m68k/mm/kmap.c
+++ b/arch/m68k/mm/kmap.c
@@ -102,7 +102,7 @@
  */
 /* Rewritten by Andreas Schwab to remove all races. */
 
-void *__ioremap(unsigned long physaddr, unsigned long size, int cacheflag)
+void __iomem *__ioremap(unsigned long physaddr, unsigned long size, int cacheflag)
 {
 	struct vm_struct *area;
 	unsigned long virtaddr, retaddr;
@@ -121,7 +121,7 @@
 	if (MACH_IS_AMIGA) {
 		if ((physaddr >= 0x40000000) && (physaddr + size < 0x60000000)
 		    && (cacheflag == IOMAP_NOCACHE_SER))
-			return (void *)physaddr;
+			return (void __iomem *)physaddr;
 	}
 #endif
 
@@ -218,21 +218,21 @@
 #endif
 	flush_tlb_all();
 
-	return (void *)retaddr;
+	return (void __iomem *)retaddr;
 }
 
 /*
  * Unmap a ioremap()ed region again
  */
-void iounmap(void *addr)
+void iounmap(void __iomem *addr)
 {
 #ifdef CONFIG_AMIGA
 	if ((!MACH_IS_AMIGA) ||
 	    (((unsigned long)addr < 0x40000000) ||
 	     ((unsigned long)addr > 0x60000000)))
-			free_io_area(addr);
+			free_io_area((__force void *)addr);
 #else
-	free_io_area(addr);
+	free_io_area((__force void *)addr);
 #endif
 }
 
diff --git a/arch/m68k/mvme16x/rtc.c b/arch/m68k/mvme16x/rtc.c
index 7977eae..a69fe30 100644
--- a/arch/m68k/mvme16x/rtc.c
+++ b/arch/m68k/mvme16x/rtc.c
@@ -11,6 +11,7 @@
 #include <linux/miscdevice.h>
 #include <linux/slab.h>
 #include <linux/ioport.h>
+#include <linux/capability.h>
 #include <linux/fcntl.h>
 #include <linux/init.h>
 #include <linux/poll.h>
@@ -44,6 +45,7 @@
 	volatile MK48T08ptr_t rtc = (MK48T08ptr_t)MVME_RTC_BASE;
 	unsigned long flags;
 	struct rtc_time wtime;
+	void __user *argp = (void __user *)arg;
 
 	switch (cmd) {
 	case RTC_RD_TIME:	/* Read the time/date from RTC	*/
@@ -63,7 +65,7 @@
 		wtime.tm_wday = BCD2BIN(rtc->bcd_dow)-1;
 		rtc->ctrl = 0;
 		local_irq_restore(flags);
-		return copy_to_user((void *)arg, &wtime, sizeof wtime) ?
+		return copy_to_user(argp, &wtime, sizeof wtime) ?
 								-EFAULT : 0;
 	}
 	case RTC_SET_TIME:	/* Set the RTC */
@@ -75,8 +77,7 @@
 		if (!capable(CAP_SYS_ADMIN))
 			return -EACCES;
 
-		if (copy_from_user(&rtc_tm, (struct rtc_time*)arg,
-				   sizeof(struct rtc_time)))
+		if (copy_from_user(&rtc_tm, argp, sizeof(struct rtc_time)))
 			return -EFAULT;
 
 		yrs = rtc_tm.tm_year;
diff --git a/arch/m68k/q40/config.c b/arch/m68k/q40/config.c
index 02b626bae..5e0f9b0 100644
--- a/arch/m68k/q40/config.c
+++ b/arch/m68k/q40/config.c
@@ -36,8 +36,6 @@
 #include <asm/machdep.h>
 #include <asm/q40_master.h>
 
-extern void floppy_setup(char *str, int *ints);
-
 extern irqreturn_t q40_process_int (int level, struct pt_regs *regs);
 extern irqreturn_t (*q40_default_handler[]) (int, void *, struct pt_regs *);  /* added just for debugging */
 extern void q40_init_IRQ (void);
@@ -194,9 +192,6 @@
     mach_heartbeat = q40_heartbeat;
 #endif
     mach_halt = q40_halt;
-#ifdef CONFIG_DUMMY_CONSOLE
-    conswitchp = &dummy_con;
-#endif
 
     /* disable a few things that SMSQ might have left enabled */
     q40_disable_irqs();
diff --git a/arch/m68k/sun3/config.c b/arch/m68k/sun3/config.c
index 77d05bc..f1ca0df 100644
--- a/arch/m68k/sun3/config.c
+++ b/arch/m68k/sun3/config.c
@@ -160,9 +160,6 @@
 	mach_hwclk           =  sun3_hwclk;
 	mach_halt	     =  sun3_halt;
 	mach_get_hardware_list = sun3_get_hardware_list;
-#if defined(CONFIG_DUMMY_CONSOLE)
-	conswitchp	     = &dummy_con;
-#endif
 
 	memory_start = ((((int)&_end) + 0x2000) & ~0x1fff);
 // PROM seems to want the last couple of physical pages. --m
diff --git a/arch/m68k/sun3x/config.c b/arch/m68k/sun3x/config.c
index 0ef547f..0920f5d 100644
--- a/arch/m68k/sun3x/config.c
+++ b/arch/m68k/sun3x/config.c
@@ -71,10 +71,6 @@
 	mach_get_model       = sun3_get_model;
 	mach_get_hardware_list = sun3x_get_hardware_list;
 
-#ifdef CONFIG_DUMMY_CONSOLE
-	conswitchp	     = &dummy_con;
-#endif
-
 	sun3_intreg = (unsigned char *)SUN3X_INTREG;
 
 	/* only the serial console is known to work anyway... */
diff --git a/arch/m68knommu/Makefile b/arch/m68knommu/Makefile
index b6b5c14..6f880cb 100644
--- a/arch/m68knommu/Makefile
+++ b/arch/m68knommu/Makefile
@@ -99,7 +99,6 @@
 AFLAGS += $(cflags-y)
 
 CFLAGS += $(cflags-y)
-CFLAGS += -O1 -g
 CFLAGS += -D__linux__
 CFLAGS += -DUTS_SYSNAME=\"uClinux\"
 
diff --git a/arch/m68knommu/kernel/m68k_ksyms.c b/arch/m68knommu/kernel/m68k_ksyms.c
index b2c62ee..eddb8d3e 100644
--- a/arch/m68knommu/kernel/m68k_ksyms.c
+++ b/arch/m68knommu/kernel/m68k_ksyms.c
@@ -18,7 +18,6 @@
 #include <asm/checksum.h>
 #include <asm/current.h>
 
-extern void dump_thread(struct pt_regs *, struct user *);
 extern int dump_fpu(struct pt_regs *, elf_fpregset_t *);
 
 /* platform dependent support */
@@ -26,7 +25,6 @@
 EXPORT_SYMBOL(__ioremap);
 EXPORT_SYMBOL(iounmap);
 EXPORT_SYMBOL(dump_fpu);
-EXPORT_SYMBOL(dump_thread);
 EXPORT_SYMBOL(strnlen);
 EXPORT_SYMBOL(strrchr);
 EXPORT_SYMBOL(strstr);
diff --git a/arch/m68knommu/kernel/process.c b/arch/m68knommu/kernel/process.c
index 82e7ec8..99bf438 100644
--- a/arch/m68knommu/kernel/process.c
+++ b/arch/m68knommu/kernel/process.c
@@ -198,10 +198,9 @@
 {
 	struct pt_regs * childregs;
 	struct switch_stack * childstack, *stack;
-	unsigned long stack_offset, *retp;
+	unsigned long *retp;
 
-	stack_offset = THREAD_SIZE - sizeof(struct pt_regs);
-	childregs = (struct pt_regs *) ((unsigned long) p->thread_info + stack_offset);
+	childregs = (struct pt_regs *) (task_stack_page(p) + THREAD_SIZE) - 1;
 
 	*childregs = *regs;
 	childregs->d0 = 0;
@@ -276,52 +275,6 @@
 }
 
 /*
- * fill in the user structure for a core dump..
- */
-void dump_thread(struct pt_regs * regs, struct user * dump)
-{
-	struct switch_stack *sw;
-
-	/* changed the size calculations - should hopefully work better. lbt */
-	dump->magic = CMAGIC;
-	dump->start_code = 0;
-	dump->start_stack = rdusp() & ~(PAGE_SIZE - 1);
-	dump->u_tsize = ((unsigned long) current->mm->end_code) >> PAGE_SHIFT;
-	dump->u_dsize = ((unsigned long) (current->mm->brk +
-					  (PAGE_SIZE-1))) >> PAGE_SHIFT;
-	dump->u_dsize -= dump->u_tsize;
-	dump->u_ssize = 0;
-
-	if (dump->start_stack < TASK_SIZE)
-		dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> PAGE_SHIFT;
-
-	dump->u_ar0 = (struct user_regs_struct *)((int)&dump->regs - (int)dump);
-	sw = ((struct switch_stack *)regs) - 1;
-	dump->regs.d1 = regs->d1;
-	dump->regs.d2 = regs->d2;
-	dump->regs.d3 = regs->d3;
-	dump->regs.d4 = regs->d4;
-	dump->regs.d5 = regs->d5;
-	dump->regs.d6 = sw->d6;
-	dump->regs.d7 = sw->d7;
-	dump->regs.a0 = regs->a0;
-	dump->regs.a1 = regs->a1;
-	dump->regs.a2 = regs->a2;
-	dump->regs.a3 = sw->a3;
-	dump->regs.a4 = sw->a4;
-	dump->regs.a5 = sw->a5;
-	dump->regs.a6 = sw->a6;
-	dump->regs.d0 = regs->d0;
-	dump->regs.orig_d0 = regs->orig_d0;
-	dump->regs.stkadj = regs->stkadj;
-	dump->regs.sr = regs->sr;
-	dump->regs.pc = regs->pc;
-	dump->regs.fmtvec = (regs->format << 12) | regs->vector;
-	/* dump floating point stuff */
-	dump->u_fpvalid = dump_fpu (regs, &dump->m68kfp);
-}
-
-/*
  *	Generic dumping code. Used for panic and debug.
  */
 void dump(struct pt_regs *fp)
diff --git a/arch/m68knommu/kernel/ptrace.c b/arch/m68knommu/kernel/ptrace.c
index 262ab8c..382ca57 100644
--- a/arch/m68knommu/kernel/ptrace.c
+++ b/arch/m68knommu/kernel/ptrace.c
@@ -101,7 +101,7 @@
 	put_reg(child, PT_SR, tmp);
 }
 
-long arch_ptrace(truct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 {
 	int ret;
 
diff --git a/arch/m68knommu/kernel/signal.c b/arch/m68knommu/kernel/signal.c
index 43a2726..e1b3aa3 100644
--- a/arch/m68knommu/kernel/signal.c
+++ b/arch/m68knommu/kernel/signal.c
@@ -285,6 +285,7 @@
 	regs->d1 = context.sc_d1;
 	regs->a0 = context.sc_a0;
 	regs->a1 = context.sc_a1;
+	((struct switch_stack *)regs - 1)->a5 = context.sc_a5;
 	regs->sr = (regs->sr & 0xff00) | (context.sc_sr & 0xff);
 	regs->pc = context.sc_pc;
 	regs->orig_d0 = -1;		/* disable syscall checks */
@@ -498,6 +499,7 @@
 	sc->sc_d1 = regs->d1;
 	sc->sc_a0 = regs->a0;
 	sc->sc_a1 = regs->a1;
+	sc->sc_a5 = ((struct switch_stack *)regs - 1)->a5;
 	sc->sc_sr = regs->sr;
 	sc->sc_pc = regs->pc;
 	sc->sc_formatvec = regs->format << 12 | regs->vector;
@@ -597,6 +599,9 @@
 	/* Set up registers for signal handler */
 	wrusp ((unsigned long) frame);
 	regs->pc = (unsigned long) ka->sa.sa_handler;
+	((struct switch_stack *)regs - 1)->a5 = current->mm->start_data;
+	regs->format = 0x4; /*set format byte to make stack appear modulo 4 
+						which it will be when doing the rte */
 
 adjust_stack:
 	/* Prepare to skip over the extra stuff in the exception frame.  */
@@ -664,6 +669,9 @@
 	/* Set up registers for signal handler */
 	wrusp ((unsigned long) frame);
 	regs->pc = (unsigned long) ka->sa.sa_handler;
+	((struct switch_stack *)regs - 1)->a5 = current->mm->start_data;
+	regs->format = 0x4; /*set format byte to make stack appear modulo 4 
+						which it will be when doing the rte */
 
 adjust_stack:
 	/* Prepare to skip over the extra stuff in the exception frame.  */
diff --git a/arch/m68knommu/kernel/vmlinux.lds.S b/arch/m68knommu/kernel/vmlinux.lds.S
index 0eab92c..ac9de26 100644
--- a/arch/m68knommu/kernel/vmlinux.lds.S
+++ b/arch/m68knommu/kernel/vmlinux.lds.S
@@ -129,7 +129,7 @@
  */
 #if defined(CONFIG_M5208EVB)
 #define	RAM_START	0x40020000
-#define	RAM_LENGTH	0x01e00000
+#define	RAM_LENGTH	0x01fe0000
 #endif
 
 /*
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index b50be44..c3e852e 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -1471,7 +1471,7 @@
 
 config 64BIT_PHYS_ADDR
 	bool "Support for 64-bit physical address space"
-	depends on (CPU_R4X00 || CPU_R5000 || CPU_RM7000 || CPU_RM9000 || CPU_R10000 || CPU_SB1 || CPU_MIPS32_R1 || CPU_MIPS64_R1) && 32BIT
+	depends on (CPU_R4X00 || CPU_R5000 || CPU_RM7000 || CPU_RM9000 || CPU_R10000 || CPU_SB1 || CPU_MIPS32 || CPU_MIPS64) && 32BIT
 
 config CPU_ADVANCED
 	bool "Override CPU Options"
@@ -1492,14 +1492,6 @@
 	  for better performance, N if you don't know.  You must say Y here
 	  for multiprocessor machines.
 
-config CPU_HAS_LLDSCD
-	bool "lld/scd Instructions available" if CPU_ADVANCED
-	default y if !CPU_ADVANCED && !CPU_R3000 && !CPU_VR41XX && !CPU_TX39XX && !CPU_MIPS32_R1
-	help
-	  Say Y here if your CPU has the lld and scd instructions, the 64-bit
-	  equivalents of ll and sc.  Say Y here for better performance, N if
-	  you don't know.  You must say Y here for multiprocessor machines.
-
 config CPU_HAS_WB
 	bool "Writeback Buffer available" if CPU_ADVANCED
 	default y if !CPU_ADVANCED && CPU_R3000 && MACH_DECSTATION
diff --git a/arch/mips/Makefile b/arch/mips/Makefile
index e14ba5e..2a9f2ef 100644
--- a/arch/mips/Makefile
+++ b/arch/mips/Makefile
@@ -93,7 +93,6 @@
 #
 cflags-y			+= -I $(TOPDIR)/include/asm/gcc
 cflags-y			+= -G 0 -mno-abicalls -fno-pic -pipe
-cflags-y			+= $(call cc-option, -finline-limit=100000)
 LDFLAGS_vmlinux			+= -G 0 -static -n -nostdlib
 MODFLAGS			+= -mlong-calls
 
diff --git a/arch/mips/configs/bigsur_defconfig b/arch/mips/configs/bigsur_defconfig
index 069f9d1..6fd3537 100644
--- a/arch/mips/configs/bigsur_defconfig
+++ b/arch/mips/configs/bigsur_defconfig
@@ -130,7 +130,6 @@
 # CONFIG_SIBYTE_DMA_PAGEOPS is not set
 # CONFIG_MIPS_MT is not set
 CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_LLDSCD=y
 CONFIG_CPU_HAS_SYNC=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_IRQ_PROBE=y
diff --git a/arch/mips/configs/cobalt_defconfig b/arch/mips/configs/cobalt_defconfig
index 216f402..1d3ee18 100644
--- a/arch/mips/configs/cobalt_defconfig
+++ b/arch/mips/configs/cobalt_defconfig
@@ -115,7 +115,6 @@
 # CONFIG_MIPS_MT is not set
 # CONFIG_CPU_ADVANCED is not set
 CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_LLDSCD=y
 CONFIG_CPU_HAS_SYNC=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_IRQ_PROBE=y
diff --git a/arch/mips/configs/ddb5476_defconfig b/arch/mips/configs/ddb5476_defconfig
index bea00a9..a81e2de 100644
--- a/arch/mips/configs/ddb5476_defconfig
+++ b/arch/mips/configs/ddb5476_defconfig
@@ -116,7 +116,6 @@
 # CONFIG_MIPS_MT is not set
 # CONFIG_CPU_ADVANCED is not set
 CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_LLDSCD=y
 CONFIG_CPU_HAS_SYNC=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_IRQ_PROBE=y
diff --git a/arch/mips/configs/ddb5477_defconfig b/arch/mips/configs/ddb5477_defconfig
index 61f7171..f1c27c2 100644
--- a/arch/mips/configs/ddb5477_defconfig
+++ b/arch/mips/configs/ddb5477_defconfig
@@ -116,7 +116,6 @@
 # CONFIG_MIPS_MT is not set
 # CONFIG_CPU_ADVANCED is not set
 CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_LLDSCD=y
 CONFIG_CPU_HAS_SYNC=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_IRQ_PROBE=y
diff --git a/arch/mips/configs/ev64120_defconfig b/arch/mips/configs/ev64120_defconfig
index 14e3815f..aa24d85 100644
--- a/arch/mips/configs/ev64120_defconfig
+++ b/arch/mips/configs/ev64120_defconfig
@@ -118,7 +118,6 @@
 # CONFIG_64BIT_PHYS_ADDR is not set
 # CONFIG_CPU_ADVANCED is not set
 CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_LLDSCD=y
 CONFIG_CPU_HAS_SYNC=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_IRQ_PROBE=y
diff --git a/arch/mips/configs/ev96100_defconfig b/arch/mips/configs/ev96100_defconfig
index 5108195..eeed0e5 100644
--- a/arch/mips/configs/ev96100_defconfig
+++ b/arch/mips/configs/ev96100_defconfig
@@ -121,7 +121,6 @@
 # CONFIG_64BIT_PHYS_ADDR is not set
 # CONFIG_CPU_ADVANCED is not set
 CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_LLDSCD=y
 CONFIG_CPU_HAS_SYNC=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_IRQ_PROBE=y
diff --git a/arch/mips/configs/ip22_defconfig b/arch/mips/configs/ip22_defconfig
index 67979e3..e56351a 100644
--- a/arch/mips/configs/ip22_defconfig
+++ b/arch/mips/configs/ip22_defconfig
@@ -123,7 +123,6 @@
 # CONFIG_64BIT_PHYS_ADDR is not set
 # CONFIG_CPU_ADVANCED is not set
 CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_LLDSCD=y
 CONFIG_CPU_HAS_SYNC=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_IRQ_PROBE=y
diff --git a/arch/mips/configs/ip27_defconfig b/arch/mips/configs/ip27_defconfig
index 03af44d..e17d3ad 100644
--- a/arch/mips/configs/ip27_defconfig
+++ b/arch/mips/configs/ip27_defconfig
@@ -119,7 +119,6 @@
 CONFIG_CPU_HAS_PREFETCH=y
 # CONFIG_MIPS_MT is not set
 CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_LLDSCD=y
 CONFIG_CPU_HAS_SYNC=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_IRQ_PROBE=y
diff --git a/arch/mips/configs/ip32_defconfig b/arch/mips/configs/ip32_defconfig
index cba2a49..967e7ac 100644
--- a/arch/mips/configs/ip32_defconfig
+++ b/arch/mips/configs/ip32_defconfig
@@ -121,7 +121,6 @@
 CONFIG_RM7000_CPU_SCACHE=y
 # CONFIG_MIPS_MT is not set
 CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_LLDSCD=y
 CONFIG_CPU_HAS_SYNC=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_IRQ_PROBE=y
diff --git a/arch/mips/configs/it8172_defconfig b/arch/mips/configs/it8172_defconfig
index e7ee167..b5fa963 100644
--- a/arch/mips/configs/it8172_defconfig
+++ b/arch/mips/configs/it8172_defconfig
@@ -117,7 +117,6 @@
 # CONFIG_MIPS_MT is not set
 # CONFIG_CPU_ADVANCED is not set
 CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_LLDSCD=y
 CONFIG_CPU_HAS_SYNC=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_IRQ_PROBE=y
diff --git a/arch/mips/configs/ivr_defconfig b/arch/mips/configs/ivr_defconfig
index 138c8a6..7138693 100644
--- a/arch/mips/configs/ivr_defconfig
+++ b/arch/mips/configs/ivr_defconfig
@@ -114,7 +114,6 @@
 # CONFIG_MIPS_MT is not set
 # CONFIG_CPU_ADVANCED is not set
 CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_LLDSCD=y
 CONFIG_CPU_HAS_SYNC=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_IRQ_PROBE=y
diff --git a/arch/mips/configs/jaguar-atx_defconfig b/arch/mips/configs/jaguar-atx_defconfig
index 6238e0d..14fb468 100644
--- a/arch/mips/configs/jaguar-atx_defconfig
+++ b/arch/mips/configs/jaguar-atx_defconfig
@@ -124,7 +124,6 @@
 # CONFIG_64BIT_PHYS_ADDR is not set
 # CONFIG_CPU_ADVANCED is not set
 CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_LLDSCD=y
 CONFIG_CPU_HAS_SYNC=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_IRQ_PROBE=y
diff --git a/arch/mips/configs/lasat200_defconfig b/arch/mips/configs/lasat200_defconfig
index a7ad99b..6c5df76 100644
--- a/arch/mips/configs/lasat200_defconfig
+++ b/arch/mips/configs/lasat200_defconfig
@@ -121,7 +121,6 @@
 # CONFIG_64BIT_PHYS_ADDR is not set
 # CONFIG_CPU_ADVANCED is not set
 CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_LLDSCD=y
 CONFIG_CPU_HAS_SYNC=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_IRQ_PROBE=y
diff --git a/arch/mips/configs/malta_defconfig b/arch/mips/configs/malta_defconfig
index d1c4421..da0677a 100644
--- a/arch/mips/configs/malta_defconfig
+++ b/arch/mips/configs/malta_defconfig
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.15-rc2
-# Thu Nov 24 01:06:35 2005
+# Linux kernel version: 2.6.15-rc5
+# Fri Dec 23 02:21:03 2005
 #
 CONFIG_MIPS=y
 
@@ -87,8 +87,8 @@
 #
 # CPU selection
 #
-CONFIG_CPU_MIPS32_R1=y
-# CONFIG_CPU_MIPS32_R2 is not set
+# CONFIG_CPU_MIPS32_R1 is not set
+CONFIG_CPU_MIPS32_R2=y
 # CONFIG_CPU_MIPS64_R1 is not set
 # CONFIG_CPU_MIPS64_R2 is not set
 # CONFIG_CPU_R3000 is not set
@@ -112,7 +112,7 @@
 CONFIG_SYS_HAS_CPU_NEVADA=y
 CONFIG_SYS_HAS_CPU_RM7000=y
 CONFIG_CPU_MIPS32=y
-CONFIG_CPU_MIPSR1=y
+CONFIG_CPU_MIPSR2=y
 CONFIG_SYS_SUPPORTS_32BIT_KERNEL=y
 CONFIG_SYS_SUPPORTS_64BIT_KERNEL=y
 CONFIG_CPU_SUPPORTS_32BIT_KERNEL=y
diff --git a/arch/mips/configs/ocelot_3_defconfig b/arch/mips/configs/ocelot_3_defconfig
index 9081ea5..7ad8718 100644
--- a/arch/mips/configs/ocelot_3_defconfig
+++ b/arch/mips/configs/ocelot_3_defconfig
@@ -122,7 +122,6 @@
 # CONFIG_64BIT_PHYS_ADDR is not set
 # CONFIG_CPU_ADVANCED is not set
 CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_LLDSCD=y
 CONFIG_CPU_HAS_SYNC=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_IRQ_PROBE=y
diff --git a/arch/mips/configs/ocelot_c_defconfig b/arch/mips/configs/ocelot_c_defconfig
index 570fc4d..e8d6bb3 100644
--- a/arch/mips/configs/ocelot_c_defconfig
+++ b/arch/mips/configs/ocelot_c_defconfig
@@ -118,7 +118,6 @@
 CONFIG_CPU_HAS_PREFETCH=y
 # CONFIG_MIPS_MT is not set
 CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_LLDSCD=y
 CONFIG_CPU_HAS_SYNC=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_IRQ_PROBE=y
diff --git a/arch/mips/configs/ocelot_defconfig b/arch/mips/configs/ocelot_defconfig
index 6634ab2..f3787b6 100644
--- a/arch/mips/configs/ocelot_defconfig
+++ b/arch/mips/configs/ocelot_defconfig
@@ -123,7 +123,6 @@
 # CONFIG_64BIT_PHYS_ADDR is not set
 # CONFIG_CPU_ADVANCED is not set
 CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_LLDSCD=y
 CONFIG_CPU_HAS_SYNC=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_IRQ_PROBE=y
diff --git a/arch/mips/configs/ocelot_g_defconfig b/arch/mips/configs/ocelot_g_defconfig
index 4c396e1..b6126ad 100644
--- a/arch/mips/configs/ocelot_g_defconfig
+++ b/arch/mips/configs/ocelot_g_defconfig
@@ -121,7 +121,6 @@
 CONFIG_CPU_HAS_PREFETCH=y
 # CONFIG_MIPS_MT is not set
 CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_LLDSCD=y
 CONFIG_CPU_HAS_SYNC=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_IRQ_PROBE=y
diff --git a/arch/mips/configs/pnx8550-v2pci_defconfig b/arch/mips/configs/pnx8550-v2pci_defconfig
index d9a0d2f..4c650e7 100644
--- a/arch/mips/configs/pnx8550-v2pci_defconfig
+++ b/arch/mips/configs/pnx8550-v2pci_defconfig
@@ -116,7 +116,6 @@
 # CONFIG_64BIT_PHYS_ADDR is not set
 CONFIG_CPU_ADVANCED=y
 CONFIG_CPU_HAS_LLSC=y
-# CONFIG_CPU_HAS_LLDSCD is not set
 # CONFIG_CPU_HAS_WB is not set
 CONFIG_CPU_HAS_SYNC=y
 CONFIG_GENERIC_HARDIRQS=y
diff --git a/arch/mips/configs/rbhma4500_defconfig b/arch/mips/configs/rbhma4500_defconfig
index 1cc1450..9aaa430 100644
--- a/arch/mips/configs/rbhma4500_defconfig
+++ b/arch/mips/configs/rbhma4500_defconfig
@@ -124,7 +124,6 @@
 # CONFIG_MIPS_MT is not set
 CONFIG_CPU_ADVANCED=y
 CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_LLDSCD=y
 CONFIG_CPU_HAS_WB=y
 CONFIG_CPU_HAS_SYNC=y
 CONFIG_GENERIC_HARDIRQS=y
diff --git a/arch/mips/configs/rm200_defconfig b/arch/mips/configs/rm200_defconfig
index 30975b3..abf6109 100644
--- a/arch/mips/configs/rm200_defconfig
+++ b/arch/mips/configs/rm200_defconfig
@@ -124,7 +124,6 @@
 # CONFIG_64BIT_PHYS_ADDR is not set
 # CONFIG_CPU_ADVANCED is not set
 CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_LLDSCD=y
 CONFIG_CPU_HAS_SYNC=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_IRQ_PROBE=y
diff --git a/arch/mips/configs/sb1250-swarm_defconfig b/arch/mips/configs/sb1250-swarm_defconfig
index 63f1be1..52048c9 100644
--- a/arch/mips/configs/sb1250-swarm_defconfig
+++ b/arch/mips/configs/sb1250-swarm_defconfig
@@ -133,7 +133,6 @@
 # CONFIG_MIPS_MT is not set
 CONFIG_SB1_PASS_1_WORKAROUNDS=y
 CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_LLDSCD=y
 CONFIG_CPU_HAS_SYNC=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_IRQ_PROBE=y
diff --git a/arch/mips/configs/yosemite_defconfig b/arch/mips/configs/yosemite_defconfig
index d51d5d1..468c2e4 100644
--- a/arch/mips/configs/yosemite_defconfig
+++ b/arch/mips/configs/yosemite_defconfig
@@ -118,7 +118,6 @@
 # CONFIG_64BIT_PHYS_ADDR is not set
 # CONFIG_CPU_ADVANCED is not set
 CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_LLDSCD=y
 CONFIG_CPU_HAS_SYNC=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_IRQ_PROBE=y
diff --git a/arch/mips/defconfig b/arch/mips/defconfig
index 2a1b844..4f125e9 100644
--- a/arch/mips/defconfig
+++ b/arch/mips/defconfig
@@ -123,7 +123,6 @@
 # CONFIG_64BIT_PHYS_ADDR is not set
 # CONFIG_CPU_ADVANCED is not set
 CONFIG_CPU_HAS_LLSC=y
-CONFIG_CPU_HAS_LLDSCD=y
 CONFIG_CPU_HAS_SYNC=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_IRQ_PROBE=y
diff --git a/arch/mips/kernel/Makefile b/arch/mips/kernel/Makefile
index 72f2126..f36c4f2 100644
--- a/arch/mips/kernel/Makefile
+++ b/arch/mips/kernel/Makefile
@@ -50,7 +50,7 @@
 obj-$(CONFIG_32BIT)		+= scall32-o32.o
 obj-$(CONFIG_64BIT)		+= scall64-64.o
 obj-$(CONFIG_BINFMT_IRIX)	+= binfmt_irix.o
-obj-$(CONFIG_MIPS32_COMPAT)	+= ioctl32.o linux32.o signal32.o
+obj-$(CONFIG_MIPS32_COMPAT)	+= linux32.o signal32.o
 obj-$(CONFIG_MIPS32_N32)	+= binfmt_elfn32.o scall64-n32.o signal_n32.o
 obj-$(CONFIG_MIPS32_O32)	+= binfmt_elfo32.o scall64-o32.o ptrace32.o
 
@@ -60,6 +60,5 @@
 obj-$(CONFIG_64BIT)		+= cpu-bugs64.o
 
 CFLAGS_cpu-bugs64.o	= $(shell if $(CC) $(CFLAGS) -Wa,-mdaddi -c -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-DHAVE_AS_SET_DADDI"; fi)
-CFLAGS_ioctl32.o	+= -Ifs/
 
 EXTRA_AFLAGS := $(CFLAGS)
diff --git a/arch/mips/kernel/cpu-probe.c b/arch/mips/kernel/cpu-probe.c
index 5e1b08b..fac48ad 100644
--- a/arch/mips/kernel/cpu-probe.c
+++ b/arch/mips/kernel/cpu-probe.c
@@ -435,6 +435,9 @@
 	}
 }
 
+static char unknown_isa[] __initdata = KERN_ERR \
+	"Unsupported ISA type, c0.config0: %d.";
+
 static inline unsigned int decode_config0(struct cpuinfo_mips *c)
 {
 	unsigned int config0;
@@ -447,16 +450,37 @@
 	isa = (config0 & MIPS_CONF_AT) >> 13;
 	switch (isa) {
 	case 0:
-		c->isa_level = MIPS_CPU_ISA_M32;
+		switch ((config0 >> 10) & 7) {
+		case 0:
+			c->isa_level = MIPS_CPU_ISA_M32R1;
+			break;
+		case 1:
+			c->isa_level = MIPS_CPU_ISA_M32R2;
+			break;
+		default:
+			goto unknown;
+		}
 		break;
 	case 2:
-		c->isa_level = MIPS_CPU_ISA_M64;
+		switch ((config0 >> 10) & 7) {
+		case 0:
+			c->isa_level = MIPS_CPU_ISA_M64R1;
+			break;
+		case 1:
+			c->isa_level = MIPS_CPU_ISA_M64R2;
+			break;
+		default:
+			goto unknown;
+		}
 		break;
 	default:
-		panic("Unsupported ISA type, cp0.config0.at: %d.", isa);
+		goto unknown;
 	}
 
 	return config0 & MIPS_CONF_M;
+
+unknown:
+	panic(unknown_isa, config0);
 }
 
 static inline unsigned int decode_config1(struct cpuinfo_mips *c)
@@ -568,7 +592,6 @@
 		break;
 	case PRID_IMP_34K:
 		c->cputype = CPU_34K;
-		c->isa_level = MIPS_CPU_ISA_M32;
 		break;
 	}
 }
@@ -647,7 +670,7 @@
 	switch (c->processor_id & 0xff00) {
 	case PRID_IMP_PR4450:
 		c->cputype = CPU_PR4450;
-		c->isa_level = MIPS_CPU_ISA_M32;
+		c->isa_level = MIPS_CPU_ISA_M32R1;
 		break;
 	default:
 		panic("Unknown Philips Core!"); /* REVISIT: die? */
@@ -690,8 +713,10 @@
 	if (c->options & MIPS_CPU_FPU) {
 		c->fpu_id = cpu_get_fpu_id();
 
-		if (c->isa_level == MIPS_CPU_ISA_M32 ||
-		    c->isa_level == MIPS_CPU_ISA_M64) {
+		if (c->isa_level == MIPS_CPU_ISA_M32R1 ||
+		    c->isa_level == MIPS_CPU_ISA_M32R2 ||
+		    c->isa_level == MIPS_CPU_ISA_M64R1 ||
+		    c->isa_level == MIPS_CPU_ISA_M64R2) {
 			if (c->fpu_id & MIPS_FPIR_3D)
 				c->ases |= MIPS_ASE_MIPS3D;
 		}
diff --git a/arch/mips/kernel/ioctl32.c b/arch/mips/kernel/ioctl32.c
deleted file mode 100644
index 9ea1fc7..0000000
--- a/arch/mips/kernel/ioctl32.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * ioctl32.c: Conversion between 32bit and 64bit native ioctls.
- *
- * Copyright (C) 2000 Silicon Graphics, Inc.
- * Written by Ulf Carlsson (ulfc@engr.sgi.com)
- * Copyright (C) 2000, 2004 Ralf Baechle
- * Copyright (C) 2002, 2003  Maciej W. Rozycki
- */
-#define INCLUDES
-#include "compat_ioctl.c"
-
-#include <linux/config.h>
-#include <linux/types.h>
-#include <linux/compat.h>
-#include <linux/ioctl32.h>
-#include <linux/syscalls.h>
-
-#ifdef CONFIG_SIBYTE_TBPROF
-#include <asm/sibyte/trace_prof.h>
-#endif
-
-#define A(__x) ((unsigned long)(__x))
-
-long sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg);
-
-#define CODE
-#include "compat_ioctl.c"
-
-#define COMPATIBLE_IOCTL(cmd)		HANDLE_IOCTL((cmd),sys_ioctl)
-#define HANDLE_IOCTL(cmd,handler)	{ (cmd), (ioctl_trans_handler_t)(handler), NULL },
-#define IOCTL_TABLE_START \
-	struct ioctl_trans ioctl_start[] = {
-#define IOCTL_TABLE_END \
-	};
-
-IOCTL_TABLE_START
-
-#include <linux/compat_ioctl.h>
-#define DECLARES
-#include "compat_ioctl.c"
-
-/*HANDLE_IOCTL(RTC_IRQP_READ, w_long)
-COMPATIBLE_IOCTL(RTC_IRQP_SET)
-HANDLE_IOCTL(RTC_EPOCH_READ, w_long)
-COMPATIBLE_IOCTL(RTC_EPOCH_SET)
-*/
-
-IOCTL_TABLE_END
-
-int ioctl_table_size = ARRAY_SIZE(ioctl_start);
diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
index dd72577..fa98f10 100644
--- a/arch/mips/kernel/process.c
+++ b/arch/mips/kernel/process.c
@@ -140,12 +140,12 @@
 int copy_thread(int nr, unsigned long clone_flags, unsigned long usp,
 	unsigned long unused, struct task_struct *p, struct pt_regs *regs)
 {
-	struct thread_info *ti = p->thread_info;
+	struct thread_info *ti = task_thread_info(p);
 	struct pt_regs *childregs;
 	long childksp;
 	p->set_child_tid = p->clear_child_tid = NULL;
 
-	childksp = (unsigned long)ti + THREAD_SIZE - 32;
+	childksp = (unsigned long)task_stack_page(p) + THREAD_SIZE - 32;
 
 	preempt_disable();
 
@@ -205,7 +205,7 @@
 	return 1;
 }
 
-void dump_regs(elf_greg_t *gp, struct pt_regs *regs)
+void elf_dump_regs(elf_greg_t *gp, struct pt_regs *regs)
 {
 	int i;
 
@@ -229,9 +229,7 @@
 
 int dump_task_regs (struct task_struct *tsk, elf_gregset_t *regs)
 {
-	struct thread_info *ti = tsk->thread_info;
-	long ksp = (unsigned long)ti + THREAD_SIZE - 32;
-	dump_regs(&(*regs)[0], (struct pt_regs *) ksp - 1);
+	elf_dump_regs(*regs, task_pt_regs(tsk));
 	return 1;
 }
 
@@ -409,7 +407,7 @@
 	if (!p || p == current || p->state == TASK_RUNNING)
 		return 0;
 
-	stack_page = (unsigned long)p->thread_info;
+	stack_page = (unsigned long)task_stack_page(p);
 	if (!stack_page || !mips_frame_info_initialized)
 		return 0;
 
diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
index 510da5f..f838b36 100644
--- a/arch/mips/kernel/ptrace.c
+++ b/arch/mips/kernel/ptrace.c
@@ -64,8 +64,7 @@
 	if (!access_ok(VERIFY_WRITE, data, 38 * 8))
 		return -EIO;
 
-	regs = (struct pt_regs *) ((unsigned long) child->thread_info +
-	       THREAD_SIZE - 32 - sizeof(struct pt_regs));
+	regs = task_pt_regs(child);
 
 	for (i = 0; i < 32; i++)
 		__put_user (regs->regs[i], data + i);
@@ -92,8 +91,7 @@
 	if (!access_ok(VERIFY_READ, data, 38 * 8))
 		return -EIO;
 
-	regs = (struct pt_regs *) ((unsigned long) child->thread_info +
-	       THREAD_SIZE - 32 - sizeof(struct pt_regs));
+	regs = task_pt_regs(child);
 
 	for (i = 0; i < 32; i++)
 		__get_user (regs->regs[i], data + i);
@@ -198,8 +196,7 @@
 		struct pt_regs *regs;
 		unsigned long tmp = 0;
 
-		regs = (struct pt_regs *) ((unsigned long) child->thread_info +
-		       THREAD_SIZE - 32 - sizeof(struct pt_regs));
+		regs = task_pt_regs(child);
 		ret = 0;  /* Default return value. */
 
 		switch (addr) {
@@ -280,12 +277,8 @@
 				ret = -EIO;
 				goto out;
 			}
-			if (child->thread.dsp.used_dsp) {
-				dregs = __get_dsp_regs(child);
-				tmp = (unsigned long) (dregs[addr - DSP_BASE]);
-			} else {
-				tmp = -1;	/* DSP registers yet used  */
-			}
+			dregs = __get_dsp_regs(child);
+			tmp = (unsigned long) (dregs[addr - DSP_BASE]);
 			break;
 		}
 		case DSP_CONTROL:
@@ -318,8 +311,7 @@
 	case PTRACE_POKEUSR: {
 		struct pt_regs *regs;
 		ret = 0;
-		regs = (struct pt_regs *) ((unsigned long) child->thread_info +
-		       THREAD_SIZE - 32 - sizeof(struct pt_regs));
+		regs = task_pt_regs(child);
 
 		switch (addr) {
 		case 0 ... 31:
@@ -446,7 +438,7 @@
 		break;
 
 	case PTRACE_GET_THREAD_AREA:
-		ret = put_user(child->thread_info->tp_value,
+		ret = put_user(task_thread_info(child)->tp_value,
 				(unsigned long __user *) data);
 		break;
 
diff --git a/arch/mips/kernel/ptrace32.c b/arch/mips/kernel/ptrace32.c
index 7e55457..0c82b25 100644
--- a/arch/mips/kernel/ptrace32.c
+++ b/arch/mips/kernel/ptrace32.c
@@ -126,8 +126,7 @@
 		struct pt_regs *regs;
 		unsigned int tmp;
 
-		regs = (struct pt_regs *) ((unsigned long) child->thread_info +
-		       THREAD_SIZE - 32 - sizeof(struct pt_regs));
+		regs = task_pt_regs(child);
 		ret = 0;  /* Default return value. */
 
 		switch (addr) {
@@ -201,12 +200,8 @@
 				ret = -EIO;
 				goto out_tsk;
 			}
-			if (child->thread.dsp.used_dsp) {
-				dspreg_t *dregs = __get_dsp_regs(child);
-				tmp = (unsigned long) (dregs[addr - DSP_BASE]);
-			} else {
-				tmp = -1;	/* DSP registers yet used  */
-			}
+			dspreg_t *dregs = __get_dsp_regs(child);
+			tmp = (unsigned long) (dregs[addr - DSP_BASE]);
 			break;
 		case DSP_CONTROL:
 			if (!cpu_has_dsp) {
@@ -263,8 +258,7 @@
 	case PTRACE_POKEUSR: {
 		struct pt_regs *regs;
 		ret = 0;
-		regs = (struct pt_regs *) ((unsigned long) child->thread_info +
-		       THREAD_SIZE - 32 - sizeof(struct pt_regs));
+		regs = task_pt_regs(child);
 
 		switch (addr) {
 		case 0 ... 31:
@@ -381,7 +375,7 @@
 		break;
 
 	case PTRACE_GET_THREAD_AREA:
-		ret = put_user(child->thread_info->tp_value,
+		ret = put_user(task_thread_info(child)->tp_value,
 				(unsigned int __user *) (unsigned long) data);
 		break;
 
@@ -395,7 +389,7 @@
 		break;
 
 	case PTRACE_GET_THREAD_AREA_3264:
-		ret = put_user(child->thread_info->tp_value,
+		ret = put_user(task_thread_info(child)->tp_value,
 				(unsigned long __user *) (unsigned long) data);
 		break;
 
diff --git a/arch/mips/kernel/signal32.c b/arch/mips/kernel/signal32.c
index c856dbc..98b185b 100644
--- a/arch/mips/kernel/signal32.c
+++ b/arch/mips/kernel/signal32.c
@@ -588,7 +588,7 @@
 	err |= __put_user(regs->hi, &sc->sc_mdhi);
 	err |= __put_user(regs->lo, &sc->sc_mdlo);
 	if (cpu_has_dsp) {
-		err |= __put_user(rddsp(DSP_MASK), &sc->sc_hi1);
+		err |= __put_user(rddsp(DSP_MASK), &sc->sc_dsp);
 		err |= __put_user(mfhi1(), &sc->sc_hi1);
 		err |= __put_user(mflo1(), &sc->sc_lo1);
 		err |= __put_user(mfhi2(), &sc->sc_hi2);
diff --git a/arch/mips/kernel/smp_mt.c b/arch/mips/kernel/smp_mt.c
index d429544..794a1c3 100644
--- a/arch/mips/kernel/smp_mt.c
+++ b/arch/mips/kernel/smp_mt.c
@@ -287,6 +287,7 @@
  */
 void prom_boot_secondary(int cpu, struct task_struct *idle)
 {
+	struct thread_info *gp = task_thread_info(idle);
 	dvpe();
 	set_c0_mvpcontrol(MVPCONTROL_VPC);
 
@@ -307,11 +308,9 @@
 	write_tc_gpr_sp( __KSTK_TOS(idle));
 
 	/* global pointer */
-	write_tc_gpr_gp((unsigned long)idle->thread_info);
+	write_tc_gpr_gp((unsigned long)gp);
 
-	flush_icache_range((unsigned long)idle->thread_info,
-					   (unsigned long)idle->thread_info +
-					   sizeof(struct thread_info));
+	flush_icache_range((unsigned long)gp, (unsigned long)(gp + 1));
 
 	/* finally out of configuration and into chaos */
 	clear_c0_mvpcontrol(MVPCONTROL_VPC);
diff --git a/arch/mips/kernel/syscall.c b/arch/mips/kernel/syscall.c
index ee98eeb..3323584 100644
--- a/arch/mips/kernel/syscall.c
+++ b/arch/mips/kernel/syscall.c
@@ -9,6 +9,7 @@
  */
 #include <linux/config.h>
 #include <linux/a.out.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/linkage.h>
 #include <linux/mm.h>
@@ -262,7 +263,7 @@
 
 void sys_set_thread_area(unsigned long addr)
 {
-	struct thread_info *ti = current->thread_info;
+	struct thread_info *ti = task_thread_info(current);
 
 	ti->tp_value = addr;
 
diff --git a/arch/mips/kernel/sysirix.c b/arch/mips/kernel/sysirix.c
index 52924f8..0fc3730 100644
--- a/arch/mips/kernel/sysirix.c
+++ b/arch/mips/kernel/sysirix.c
@@ -8,6 +8,7 @@
 #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/binfmts.h>
+#include <linux/capability.h>
 #include <linux/highuid.h>
 #include <linux/pagemap.h>
 #include <linux/mm.h>
diff --git a/arch/mips/kernel/time.c b/arch/mips/kernel/time.c
index 787ed54..7050b4f 100644
--- a/arch/mips/kernel/time.c
+++ b/arch/mips/kernel/time.c
@@ -507,14 +507,38 @@
 	return IRQ_HANDLED;
 }
 
+int null_perf_irq(struct pt_regs *regs)
+{
+	return 0;
+}
+
+int (*perf_irq)(struct pt_regs *regs) = null_perf_irq;
+
+EXPORT_SYMBOL(null_perf_irq);
+EXPORT_SYMBOL(perf_irq);
+
 asmlinkage void ll_timer_interrupt(int irq, struct pt_regs *regs)
 {
+	int r2 = cpu_has_mips_r2;
+
 	irq_enter();
 	kstat_this_cpu.irqs[irq]++;
 
-	/* we keep interrupt disabled all the time */
-	timer_interrupt(irq, NULL, regs);
+	/*
+	 * Suckage alert:
+	 * Before R2 of the architecture there was no way to see if a
+	 * performance counter interrupt was pending, so we have to run the
+	 * performance counter interrupt handler anyway.
+	 */
+	if (!r2 || (read_c0_cause() & (1 << 26)))
+		if (perf_irq(regs))
+			goto out;
 
+	/* we keep interrupt disabled all the time */
+	if (!r2 || (read_c0_cause() & (1 << 30)))
+		timer_interrupt(irq, NULL, regs);
+
+out:
 	irq_exit();
 }
 
@@ -628,9 +652,9 @@
 			mips_hpt_init = c0_hpt_init;
 		}
 
-		if ((current_cpu_data.isa_level == MIPS_CPU_ISA_M32) ||
-			 (current_cpu_data.isa_level == MIPS_CPU_ISA_I) ||
-			 (current_cpu_data.isa_level == MIPS_CPU_ISA_II))
+		if (cpu_has_mips32r1 || cpu_has_mips32r2 ||
+		    (current_cpu_data.isa_level == MIPS_CPU_ISA_I) ||
+		    (current_cpu_data.isa_level == MIPS_CPU_ISA_II))
 			/*
 			 * We need to calibrate the counter but we don't have
 			 * 64-bit division.
diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
index 7058893..59a1879 100644
--- a/arch/mips/kernel/traps.c
+++ b/arch/mips/kernel/traps.c
@@ -519,7 +519,7 @@
  */
 static inline int simulate_rdhwr(struct pt_regs *regs)
 {
-	struct thread_info *ti = current->thread_info;
+	struct thread_info *ti = task_thread_info(current);
 	unsigned int opcode;
 
 	if (unlikely(get_insn_opcode(regs, &opcode)))
diff --git a/arch/mips/kernel/vpe.c b/arch/mips/kernel/vpe.c
index 9c89eeb..ae83b75 100644
--- a/arch/mips/kernel/vpe.c
+++ b/arch/mips/kernel/vpe.c
@@ -99,9 +99,9 @@
 
 	/* elfloader stuff */
 	void *load_addr;
-	u32 len;
+	unsigned long len;
 	char *pbuffer;
-	u32 plen;
+	unsigned long plen;
 
 	unsigned long __start;
 
@@ -253,11 +253,11 @@
 }
 
 /* Find some VPE program space  */
-static void *alloc_progmem(u32 len)
+static void *alloc_progmem(unsigned long len)
 {
 #ifdef CONFIG_MIPS_VPE_LOADER_TOM
 	/* this means you must tell linux to use less memory than you physically have */
-	return (void *)((max_pfn * PAGE_SIZE) + KSEG0);
+	return pfn_to_kaddr(max_pfn);
 #else
 	// simple grab some mem for now
 	return kmalloc(len, GFP_KERNEL);
diff --git a/arch/mips/lib/iomap.c b/arch/mips/lib/iomap.c
index b5d5fa8..7e2ced71 100644
--- a/arch/mips/lib/iomap.c
+++ b/arch/mips/lib/iomap.c
@@ -3,7 +3,7 @@
  *
  *  This code is based on lib/iomap.c, by Linus Torvalds.
  *
- *  Copyright (C) 2004-2005  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2004-2005  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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 --git a/arch/mips/math-emu/dp_fint.c b/arch/mips/math-emu/dp_fint.c
index 0065dea..a1962eb 100644
--- a/arch/mips/math-emu/dp_fint.c
+++ b/arch/mips/math-emu/dp_fint.c
@@ -33,8 +33,6 @@
 
 	CLEARCX;
 
-	xc = ( 0 ? xc : xc );
-
 	if (x == 0)
 		return ieee754dp_zero(0);
 	if (x == 1 || x == -1)
diff --git a/arch/mips/math-emu/dp_flong.c b/arch/mips/math-emu/dp_flong.c
index cb105b1..eae90a8 100644
--- a/arch/mips/math-emu/dp_flong.c
+++ b/arch/mips/math-emu/dp_flong.c
@@ -33,8 +33,6 @@
 
 	CLEARCX;
 
-	xc = ( 0 ? xc : xc );
-
 	if (x == 0)
 		return ieee754dp_zero(0);
 	if (x == 1 || x == -1)
diff --git a/arch/mips/math-emu/sp_fint.c b/arch/mips/math-emu/sp_fint.c
index 42d9ed4..7aac13a 100644
--- a/arch/mips/math-emu/sp_fint.c
+++ b/arch/mips/math-emu/sp_fint.c
@@ -33,8 +33,6 @@
 
 	CLEARCX;
 
-	xc = ( 0 ? xc : xc );
-
 	if (x == 0)
 		return ieee754sp_zero(0);
 	if (x == 1 || x == -1)
diff --git a/arch/mips/math-emu/sp_flong.c b/arch/mips/math-emu/sp_flong.c
index 1e26795..3d6c1d1 100644
--- a/arch/mips/math-emu/sp_flong.c
+++ b/arch/mips/math-emu/sp_flong.c
@@ -33,8 +33,6 @@
 
 	CLEARCX;
 
-	xc = ( 0 ? xc : xc );
-
 	if (x == 0)
 		return ieee754sp_zero(0);
 	if (x == 1 || x == -1)
diff --git a/arch/mips/mips-boards/generic/time.c b/arch/mips/mips-boards/generic/time.c
index 72a12d9..93f3bf2 100644
--- a/arch/mips/mips-boards/generic/time.c
+++ b/arch/mips/mips-boards/generic/time.c
@@ -75,20 +75,31 @@
 	do_IRQ (mips_cpu_timer_irq, regs);
 }
 
+extern int null_perf_irq(struct pt_regs *regs);
+
+extern int (*perf_irq)(struct pt_regs *regs);
+
 irqreturn_t mips_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 {
-#ifdef CONFIG_SMP
+	int r2 = cpu_has_mips_r2;
 	int cpu = smp_processor_id();
 
 	if (cpu == 0) {
 		/*
-		 * CPU 0 handles the global timer interrupt job and process accounting
-		 * resets count/compare registers to trigger next timer int.
+		 * CPU 0 handles the global timer interrupt job and process
+		 * accounting resets count/compare registers to trigger next
+		 * timer int.
 		 */
-		(void) timer_interrupt(irq, dev_id, regs);
+		if (!r2 || (read_c0_cause() & (1 << 26)))
+			if (perf_irq(regs))
+				goto out;
+
+		/* we keep interrupt disabled all the time */
+		if (!r2 || (read_c0_cause() & (1 << 30)))
+			timer_interrupt(irq, NULL, regs);
+
 		scroll_display_message();
-	}
-	else {
+	} else {
 		/* Everyone else needs to reset the timer int here as
 		   ll_local_timer_interrupt doesn't */
 		/*
@@ -103,16 +114,8 @@
 		local_timer_interrupt (irq, dev_id, regs);
 	}
 
+out:
 	return IRQ_HANDLED;
-#else
-	irqreturn_t r;
-
-	r = timer_interrupt(irq, dev_id, regs);
-
-	scroll_display_message();
-
-	return r;
-#endif
 }
 
 /*
diff --git a/arch/mips/mm/c-r4k.c b/arch/mips/mm/c-r4k.c
index 38223b4..422b55f 100644
--- a/arch/mips/mm/c-r4k.c
+++ b/arch/mips/mm/c-r4k.c
@@ -1183,8 +1183,8 @@
 	if (!sc_present)
 		return;
 
-	if ((c->isa_level == MIPS_CPU_ISA_M32 ||
-	     c->isa_level == MIPS_CPU_ISA_M64) &&
+	if ((c->isa_level == MIPS_CPU_ISA_M32R1 ||
+	     c->isa_level == MIPS_CPU_ISA_M64R1) &&
 	    !(c->scache.flags & MIPS_CACHE_NOT_PRESENT))
 		panic("Dunno how to handle MIPS32 / MIPS64 second level cache");
 
diff --git a/arch/mips/oprofile/common.c b/arch/mips/oprofile/common.c
index dd2cc42..53f9889 100644
--- a/arch/mips/oprofile/common.c
+++ b/arch/mips/oprofile/common.c
@@ -75,7 +75,10 @@
 	int res;
 
 	switch (current_cpu_data.cputype) {
+	case CPU_5KC:
+	case CPU_20KC:
 	case CPU_24K:
+	case CPU_25KF:
 		lmodel = &op_model_mipsxx;
 		break;
 
diff --git a/arch/mips/oprofile/op_impl.h b/arch/mips/oprofile/op_impl.h
index f012155..5cfce7d 100644
--- a/arch/mips/oprofile/op_impl.h
+++ b/arch/mips/oprofile/op_impl.h
@@ -12,8 +12,8 @@
 
 struct pt_regs;
 
-extern void null_perf_irq(struct pt_regs *regs);
-extern void (*perf_irq)(struct pt_regs *regs);
+extern int null_perf_irq(struct pt_regs *regs);
+extern int (*perf_irq)(struct pt_regs *regs);
 
 /* Per-counter configuration as set via oprofilefs.  */
 struct op_counter_config {
diff --git a/arch/mips/oprofile/op_model_mipsxx.c b/arch/mips/oprofile/op_model_mipsxx.c
index d36b64d..1d1eee4 100644
--- a/arch/mips/oprofile/op_model_mipsxx.c
+++ b/arch/mips/oprofile/op_model_mipsxx.c
@@ -114,11 +114,12 @@
 	}
 }
 
-static void mipsxx_perfcount_handler(struct pt_regs *regs)
+static int mipsxx_perfcount_handler(struct pt_regs *regs)
 {
 	unsigned int counters = op_model_mipsxx.num_counters;
 	unsigned int control;
 	unsigned int counter;
+	int handled = 0;
 
 	switch (counters) {
 #define HANDLE_COUNTER(n)						\
@@ -129,12 +130,15 @@
 		    (counter & M_COUNTER_OVERFLOW)) {			\
 			oprofile_add_sample(regs, n);			\
 			write_c0_perfcntr ## n(reg.counter[n]);		\
+			handled = 1;					\
 		}
 	HANDLE_COUNTER(3)
 	HANDLE_COUNTER(2)
 	HANDLE_COUNTER(1)
 	HANDLE_COUNTER(0)
 	}
+
+	return handled;
 }
 
 #define M_CONFIG1_PC	(1 << 4)
@@ -176,17 +180,31 @@
 	int counters;
 
 	counters = n_counters();
-	if (counters == 0)
+	if (counters == 0) {
+		printk(KERN_ERR "Oprofile: CPU has no performance counters\n");
 		return -ENODEV;
+	}
 
 	reset_counters(counters);
 
 	op_model_mipsxx.num_counters = counters;
 	switch (current_cpu_data.cputype) {
+	case CPU_20KC:
+		op_model_mipsxx.cpu_type = "mips/20K";
+		break;
+
 	case CPU_24K:
 		op_model_mipsxx.cpu_type = "mips/24K";
 		break;
 
+	case CPU_25KF:
+		op_model_mipsxx.cpu_type = "mips/25K";
+		break;
+
+	case CPU_5KC:
+		op_model_mipsxx.cpu_type = "mips/5K";
+		break;
+
 	default:
 		printk(KERN_ERR "Profiling unsupported for this CPU\n");
 
diff --git a/arch/mips/pci/fixup-capcella.c b/arch/mips/pci/fixup-capcella.c
index f2fc82c..1e53075 100644
--- a/arch/mips/pci/fixup-capcella.c
+++ b/arch/mips/pci/fixup-capcella.c
@@ -1,7 +1,7 @@
 /*
  *  fixup-cappcela.c, The ZAO Networks Capcella specific PCI fixups.
  *
- *  Copyright (C) 2002,2004  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2002,2004  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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 --git a/arch/mips/pci/fixup-mpc30x.c b/arch/mips/pci/fixup-mpc30x.c
index 4975846..b67ddaa 100644
--- a/arch/mips/pci/fixup-mpc30x.c
+++ b/arch/mips/pci/fixup-mpc30x.c
@@ -1,7 +1,7 @@
 /*
  *  fixup-mpc30x.c, The Victor MP-C303/304 specific PCI fixups.
  *
- *  Copyright (C) 2002,2004  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2002,2004  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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 --git a/arch/mips/pci/fixup-tb0219.c b/arch/mips/pci/fixup-tb0219.c
index bc55b06..734f2b7 100644
--- a/arch/mips/pci/fixup-tb0219.c
+++ b/arch/mips/pci/fixup-tb0219.c
@@ -2,7 +2,7 @@
  *  fixup-tb0219.c, The TANBAC TB0219 specific PCI fixups.
  *
  *  Copyright (C) 2003  Megasolution Inc. <matsu@megasolution.jp>
- *  Copyright (C) 2004  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2004  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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 --git a/arch/mips/pci/fixup-tb0226.c b/arch/mips/pci/fixup-tb0226.c
index b5d42b1..c9e7cb4 100644
--- a/arch/mips/pci/fixup-tb0226.c
+++ b/arch/mips/pci/fixup-tb0226.c
@@ -1,7 +1,7 @@
 /*
  *  fixup-tb0226.c, The TANBAC TB0226 specific PCI fixups.
  *
- *  Copyright (C) 2002-2005  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2002-2005  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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 --git a/arch/mips/pci/fixup-tb0287.c b/arch/mips/pci/fixup-tb0287.c
index 8436d7f..fbe6bcb 100644
--- a/arch/mips/pci/fixup-tb0287.c
+++ b/arch/mips/pci/fixup-tb0287.c
@@ -1,7 +1,7 @@
 /*
  *  fixup-tb0287.c, The TANBAC TB0287 specific PCI fixups.
  *
- *  Copyright (C) 2005  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2005  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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 --git a/arch/mips/pci/ops-vr41xx.c b/arch/mips/pci/ops-vr41xx.c
index 430429b..900c6b3 100644
--- a/arch/mips/pci/ops-vr41xx.c
+++ b/arch/mips/pci/ops-vr41xx.c
@@ -3,7 +3,7 @@
  *
  *  Copyright (C) 2001-2003 MontaVista Software Inc.
  *    Author: Yoichi Yuasa <yyuasa@mvista.com or source@mvista.com>
- *  Copyright (C) 2004-2005  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2004-2005  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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 --git a/arch/mips/pci/pci-vr41xx.c b/arch/mips/pci/pci-vr41xx.c
index 91df4da..9885fa403 100644
--- a/arch/mips/pci/pci-vr41xx.c
+++ b/arch/mips/pci/pci-vr41xx.c
@@ -3,7 +3,7 @@
  *
  *  Copyright (C) 2001-2003 MontaVista Software Inc.
  *    Author: Yoichi Yuasa <yyuasa@mvista.com or source@mvista.com>
- *  Copyright (C) 2004-2005  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2004-2005  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *  Copyright (C) 2004 by Ralf Baechle (ralf@linux-mips.org)
  *
  *  This program is free software; you can redistribute it and/or modify
diff --git a/arch/mips/pci/pci-vr41xx.h b/arch/mips/pci/pci-vr41xx.h
index e087ec5..8a35e32 100644
--- a/arch/mips/pci/pci-vr41xx.h
+++ b/arch/mips/pci/pci-vr41xx.h
@@ -3,7 +3,7 @@
  *
  *  Copyright (C) 2002  MontaVista Software Inc.
  *    Author: Yoichi Yuasa <yyuasa@mvista.com or source@mvista.com>
- *  Copyright (C) 2004-2005  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2004-2005  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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 --git a/arch/mips/pmc-sierra/yosemite/smp.c b/arch/mips/pmc-sierra/yosemite/smp.c
index 0527170..f17f575 100644
--- a/arch/mips/pmc-sierra/yosemite/smp.c
+++ b/arch/mips/pmc-sierra/yosemite/smp.c
@@ -93,8 +93,8 @@
  */
 void prom_boot_secondary(int cpu, struct task_struct *idle)
 {
-	unsigned long gp = (unsigned long) idle->thread_info;
-	unsigned long sp = gp + THREAD_SIZE - 32;
+	unsigned long gp = (unsigned long) task_thread_info(idle);
+	unsigned long sp = __KSTK_TOP(idle);
 
 	secondary_sp = sp;
 	secondary_gp = gp;
diff --git a/arch/mips/sgi-ip27/ip27-smp.c b/arch/mips/sgi-ip27/ip27-smp.c
index 3a8291b..dbef3f6 100644
--- a/arch/mips/sgi-ip27/ip27-smp.c
+++ b/arch/mips/sgi-ip27/ip27-smp.c
@@ -168,8 +168,8 @@
  */
 void __init prom_boot_secondary(int cpu, struct task_struct *idle)
 {
-	unsigned long gp = (unsigned long) idle->thread_info;
-	unsigned long sp = gp + THREAD_SIZE - 32;
+	unsigned long gp = (unsigned long)task_thread_info(idle);
+	unsigned long sp = __KSTK_TOS(idle);
 
 	LAUNCH_SLAVE(cputonasid(cpu),cputoslice(cpu),
 		(launch_proc_t)MAPPED_KERN_RW_TO_K0(smp_bootstrap),
diff --git a/arch/mips/sibyte/cfe/smp.c b/arch/mips/sibyte/cfe/smp.c
index e848512..4477af3 100644
--- a/arch/mips/sibyte/cfe/smp.c
+++ b/arch/mips/sibyte/cfe/smp.c
@@ -60,7 +60,7 @@
 
 	retval = cfe_cpu_start(cpu_logical_map(cpu), &smp_bootstrap,
 			       __KSTK_TOS(idle),
-			       (unsigned long)idle->thread_info, 0);
+			       (unsigned long)task_thread_info(idle), 0);
 	if (retval != 0)
 		printk("cfe_start_cpu(%i) returned %i\n" , cpu, retval);
 }
diff --git a/arch/mips/vr41xx/casio-e55/setup.c b/arch/mips/vr41xx/casio-e55/setup.c
index d29201a..8149009 100644
--- a/arch/mips/vr41xx/casio-e55/setup.c
+++ b/arch/mips/vr41xx/casio-e55/setup.c
@@ -1,7 +1,7 @@
 /*
  *  setup.c, Setup for the CASIO CASSIOPEIA E-11/15/55/65.
  *
- *  Copyright (C) 2002-2005  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2002-2005  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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 --git a/arch/mips/vr41xx/common/bcu.c b/arch/mips/vr41xx/common/bcu.c
index cdfa427..de0c1b3 100644
--- a/arch/mips/vr41xx/common/bcu.c
+++ b/arch/mips/vr41xx/common/bcu.c
@@ -3,7 +3,7 @@
  *
  *  Copyright (C) 2002  MontaVista Software Inc.
  *    Author: Yoichi Yuasa <yyuasa@mvista.com, or source@mvista.com>
- *  Copyright (C) 2003-2005  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2003-2005  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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
@@ -25,7 +25,7 @@
  *  - New creation, NEC VR4122 and VR4131 are supported.
  *  - Added support for NEC VR4111 and VR4121.
  *
- *  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *  - Added support for NEC VR4133.
  */
 #include <linux/kernel.h>
diff --git a/arch/mips/vr41xx/common/cmu.c b/arch/mips/vr41xx/common/cmu.c
index d758e43..657c513 100644
--- a/arch/mips/vr41xx/common/cmu.c
+++ b/arch/mips/vr41xx/common/cmu.c
@@ -3,7 +3,7 @@
  *
  *  Copyright (C) 2001-2002  MontaVista Software Inc.
  *    Author: Yoichi Yuasa <yyuasa@mvista.com or source@mvista.com>
- *  Copuright (C) 2003-2005  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copuright (C) 2003-2005  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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
@@ -25,7 +25,7 @@
  *  - New creation, NEC VR4122 and VR4131 are supported.
  *  - Added support for NEC VR4111 and VR4121.
  *
- *  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *  - Added support for NEC VR4133.
  */
 #include <linux/init.h>
diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
index 0b73c5a..07ae19c 100644
--- a/arch/mips/vr41xx/common/icu.c
+++ b/arch/mips/vr41xx/common/icu.c
@@ -3,7 +3,7 @@
  *
  *  Copyright (C) 2001-2002  MontaVista Software Inc.
  *    Author: Yoichi Yuasa <yyuasa@mvista.com or source@mvista.com>
- *  Copyright (C) 2003-2005  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2003-2005  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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
@@ -25,7 +25,7 @@
  *  - New creation, NEC VR4122 and VR4131 are supported.
  *  - Added support for NEC VR4111 and VR4121.
  *
- *  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *  - Coped with INTASSIGN of NEC VR4133.
  */
 #include <linux/errno.h>
diff --git a/arch/mips/vr41xx/common/init.c b/arch/mips/vr41xx/common/init.c
index 578f649..707bd09 100644
--- a/arch/mips/vr41xx/common/init.c
+++ b/arch/mips/vr41xx/common/init.c
@@ -1,7 +1,7 @@
 /*
  *  init.c, Common initialization routines for NEC VR4100 series.
  *
- *  Copyright (C) 2003-2005  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2003-2005  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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 --git a/arch/mips/vr41xx/common/int-handler.S b/arch/mips/vr41xx/common/int-handler.S
index 272c13a..2b6043f 100644
--- a/arch/mips/vr41xx/common/int-handler.S
+++ b/arch/mips/vr41xx/common/int-handler.S
@@ -35,7 +35,7 @@
  *  MontaVista Software Inc. <yyuasa@mvista.com> or <source@mvista.com>
  *  - New creation, NEC VR4100 series are supported.
  *
- *  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *  - Coped with INTASSIGN of NEC VR4133.
  */
 #include <asm/asm.h>
diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
index 43b214d..61aa264 100644
--- a/arch/mips/vr41xx/common/irq.c
+++ b/arch/mips/vr41xx/common/irq.c
@@ -1,7 +1,7 @@
 /*
  *  Interrupt handing routines for NEC VR4100 series.
  *
- *  Copyright (C) 2005  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2005  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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 --git a/arch/mips/vr41xx/common/pmu.c b/arch/mips/vr41xx/common/pmu.c
index 53166f3..02bf4f7 100644
--- a/arch/mips/vr41xx/common/pmu.c
+++ b/arch/mips/vr41xx/common/pmu.c
@@ -1,7 +1,7 @@
 /*
  *  pmu.c, Power Management Unit routines for NEC VR4100 series.
  *
- *  Copyright (C) 2003-2005  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2003-2005  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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 --git a/arch/mips/vr41xx/common/type.c b/arch/mips/vr41xx/common/type.c
index bcb5f71..e0c1ac5 100644
--- a/arch/mips/vr41xx/common/type.c
+++ b/arch/mips/vr41xx/common/type.c
@@ -1,7 +1,7 @@
 /*
  *  type.c, System type for NEC VR4100 series.
  *
- *  Copyright (C) 2005  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2005  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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 --git a/arch/mips/vr41xx/common/vrc4173.c b/arch/mips/vr41xx/common/vrc4173.c
index cc52e75..3e31f81 100644
--- a/arch/mips/vr41xx/common/vrc4173.c
+++ b/arch/mips/vr41xx/common/vrc4173.c
@@ -3,7 +3,7 @@
  *
  *  Copyright (C) 2001-2003  MontaVista Software Inc.
  *    Author: Yoichi Yuasa <yyuasa@mvista.com, or source@mvista.com>
- *  Copyright (C) 2004  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2004  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *  Copyright (C) 2005 Ralf Baechle (ralf@linux-mips.org)
  *
  *  This program is free software; you can redistribute it and/or modify
diff --git a/arch/mips/vr41xx/ibm-workpad/setup.c b/arch/mips/vr41xx/ibm-workpad/setup.c
index e4b34ad..50fe8af 100644
--- a/arch/mips/vr41xx/ibm-workpad/setup.c
+++ b/arch/mips/vr41xx/ibm-workpad/setup.c
@@ -1,7 +1,7 @@
 /*
  *  setup.c, Setup for the IBM WorkPad z50.
  *
- *  Copyright (C) 2002-2005  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2002-2005  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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 --git a/arch/parisc/hpux/sys_hpux.c b/arch/parisc/hpux/sys_hpux.c
index a64fd48..29b4d61 100644
--- a/arch/parisc/hpux/sys_hpux.c
+++ b/arch/parisc/hpux/sys_hpux.c
@@ -22,6 +22,7 @@
  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include <linux/capability.h>
 #include <linux/file.h>
 #include <linux/fs.h>
 #include <linux/namei.h>
diff --git a/arch/parisc/kernel/Makefile b/arch/parisc/kernel/Makefile
index 171f9c2..27827bc 100644
--- a/arch/parisc/kernel/Makefile
+++ b/arch/parisc/kernel/Makefile
@@ -6,7 +6,6 @@
 
 AFLAGS_entry.o	:= -traditional
 AFLAGS_pacache.o := -traditional
-CFLAGS_ioctl32.o := -Ifs/
 
 obj-y	     	:= cache.o pacache.o setup.o traps.o time.o irq.o \
 		   pa7300lc.o syscall.o entry.o sys_parisc.o firmware.o \
@@ -19,6 +18,6 @@
 obj-$(CONFIG_PA11)	+= pci-dma.o
 obj-$(CONFIG_PCI)	+= pci.o
 obj-$(CONFIG_MODULES)	+= module.o
-obj-$(CONFIG_64BIT)	+= binfmt_elf32.o sys_parisc32.o ioctl32.o signal32.o
+obj-$(CONFIG_64BIT)	+= binfmt_elf32.o sys_parisc32.o signal32.o
 # only supported for PCX-W/U in 64-bit mode at the moment
 obj-$(CONFIG_64BIT)	+= perf.o perf_asm.o
diff --git a/arch/parisc/kernel/cache.c b/arch/parisc/kernel/cache.c
index a065349..d8a4ca0 100644
--- a/arch/parisc/kernel/cache.c
+++ b/arch/parisc/kernel/cache.c
@@ -29,9 +29,9 @@
 #include <asm/processor.h>
 #include <asm/sections.h>
 
-int split_tlb;
-int dcache_stride;
-int icache_stride;
+int split_tlb __read_mostly;
+int dcache_stride __read_mostly;
+int icache_stride __read_mostly;
 EXPORT_SYMBOL(dcache_stride);
 
 
@@ -45,29 +45,29 @@
 EXPORT_SYMBOL(pa_tlb_lock);
 #endif
 
-struct pdc_cache_info cache_info;
+struct pdc_cache_info cache_info __read_mostly;
 #ifndef CONFIG_PA20
-static struct pdc_btlb_info btlb_info;
+static struct pdc_btlb_info btlb_info __read_mostly;
 #endif
 
 #ifdef CONFIG_SMP
 void
 flush_data_cache(void)
 {
-	on_each_cpu((void (*)(void *))flush_data_cache_local, NULL, 1, 1);
+	on_each_cpu(flush_data_cache_local, NULL, 1, 1);
 }
 void 
 flush_instruction_cache(void)
 {
-	on_each_cpu((void (*)(void *))flush_instruction_cache_local, NULL, 1, 1);
+	on_each_cpu(flush_instruction_cache_local, NULL, 1, 1);
 }
 #endif
 
 void
 flush_cache_all_local(void)
 {
-	flush_instruction_cache_local();
-	flush_data_cache_local();
+	flush_instruction_cache_local(NULL);
+	flush_data_cache_local(NULL);
 }
 EXPORT_SYMBOL(flush_cache_all_local);
 
@@ -332,7 +332,7 @@
 }
 
 #define FLUSH_THRESHOLD 0x80000 /* 0.5MB */
-int parisc_cache_flush_threshold = FLUSH_THRESHOLD;
+int parisc_cache_flush_threshold __read_mostly = FLUSH_THRESHOLD;
 
 void parisc_setup_cache_timing(void)
 {
diff --git a/arch/parisc/kernel/drivers.c b/arch/parisc/kernel/drivers.c
index d016d67..1eaa0d3 100644
--- a/arch/parisc/kernel/drivers.c
+++ b/arch/parisc/kernel/drivers.c
@@ -39,7 +39,7 @@
 #include <asm/parisc-device.h>
 
 /* See comments in include/asm-parisc/pci.h */
-struct hppa_dma_ops *hppa_dma_ops;
+struct hppa_dma_ops *hppa_dma_ops __read_mostly;
 EXPORT_SYMBOL(hppa_dma_ops);
 
 static struct device root = {
@@ -515,8 +515,13 @@
 			(iodc_data[5] << 8) | iodc_data[6];
 	dev->hpa.name = parisc_pathname(dev);
 	dev->hpa.start = hpa;
-	if (hpa == 0xf4000000 || hpa == 0xf6000000 ||
-	    hpa == 0xf8000000 || hpa == 0xfa000000) {
+	/* This is awkward.  The STI spec says that gfx devices may occupy
+	 * 32MB or 64MB.  Unfortunately, we don't know how to tell whether
+	 * it's the former or the latter.  Assumptions either way can hurt us.
+	 */
+	if (hpa == 0xf4000000 || hpa == 0xf8000000) {
+		dev->hpa.end = hpa + 0x03ffffff;
+	} else if (hpa == 0xf6000000 || hpa == 0xfa000000) {
 		dev->hpa.end = hpa + 0x01ffffff;
 	} else {
 		dev->hpa.end = hpa + 0xfff;
@@ -834,7 +839,7 @@
 
 	if (dev->num_addrs) {
 		int k;
-		printk(",  additional addresses: ");
+		printk(", additional addresses: ");
 		for (k = 0; k < dev->num_addrs; k++)
 			printk("0x%lx ", dev->addr[k]);
 	}
diff --git a/arch/parisc/kernel/firmware.c b/arch/parisc/kernel/firmware.c
index 553f8fe..2dc06b8 100644
--- a/arch/parisc/kernel/firmware.c
+++ b/arch/parisc/kernel/firmware.c
@@ -80,7 +80,7 @@
 
 /* Firmware needs to be initially set to narrow to determine the 
  * actual firmware width. */
-int parisc_narrow_firmware = 1;
+int parisc_narrow_firmware __read_mostly = 1;
 #endif
 
 /* On most currently-supported platforms, IODC I/O calls are 32-bit calls
diff --git a/arch/parisc/kernel/hardware.c b/arch/parisc/kernel/hardware.c
index 2071b5b..3058bff 100644
--- a/arch/parisc/kernel/hardware.c
+++ b/arch/parisc/kernel/hardware.c
@@ -551,6 +551,7 @@
 	{HPHW_BCPORT, 0x804, 0x0000C, 0x10, "REO I/O BC Merced Port"}, 
 	{HPHW_BCPORT, 0x782, 0x0000C, 0x00, "REO I/O BC Ropes Port"}, 
 	{HPHW_BCPORT, 0x784, 0x0000C, 0x00, "Pluto I/O BC Ropes Port"}, 
+	{HPHW_BRIDGE, 0x05D, 0x0000A, 0x00, "SummitHawk Dino PCI Bridge"}, 
 	{HPHW_BRIDGE, 0x680, 0x0000A, 0x00, "Dino PCI Bridge"}, 
 	{HPHW_BRIDGE, 0x682, 0x0000A, 0x00, "Cujo PCI Bridge"}, 
 	{HPHW_BRIDGE, 0x782, 0x0000A, 0x00, "Elroy PCI Bridge"}, 
diff --git a/arch/parisc/kernel/inventory.c b/arch/parisc/kernel/inventory.c
index 8f56387..4e847ba 100644
--- a/arch/parisc/kernel/inventory.c
+++ b/arch/parisc/kernel/inventory.c
@@ -38,7 +38,7 @@
 */
 #undef DEBUG_PAT
 
-int pdc_type = PDC_TYPE_ILLEGAL;
+int pdc_type __read_mostly = PDC_TYPE_ILLEGAL;
 
 void __init setup_pdc(void)
 {
@@ -120,8 +120,8 @@
 	 * pdc info is bad in this case).
 	 */
 
-	if (   ((start & (PAGE_SIZE - 1)) != 0)
-	    || ((pages4k & ((1UL << PDC_PAGE_ADJ_SHIFT) - 1)) != 0) ) {
+	if (unlikely( ((start & (PAGE_SIZE - 1)) != 0)
+	    || ((pages4k & ((1UL << PDC_PAGE_ADJ_SHIFT) - 1)) != 0) )) {
 
 		panic("Memory range doesn't align with page size!\n");
 	}
diff --git a/arch/parisc/kernel/ioctl32.c b/arch/parisc/kernel/ioctl32.c
deleted file mode 100644
index 4eada1b..0000000
--- a/arch/parisc/kernel/ioctl32.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/* $Id: ioctl32.c,v 1.5 2002/10/18 00:21:43 varenet Exp $
- * ioctl32.c: Conversion between 32bit and 64bit native ioctls.
- *
- * Copyright (C) 1997-2000  Jakub Jelinek  (jakub@redhat.com)
- * Copyright (C) 1998  Eddie C. Dost  (ecd@skynet.be)
- *
- * These routines maintain argument size conversion between 32bit and 64bit
- * ioctls.
- */
-
-#include <linux/syscalls.h>
-
-#define INCLUDES
-#include "compat_ioctl.c"
-
-#include <asm/perf.h>
-#include <asm/ioctls.h>
-
-#define CODE
-#include "compat_ioctl.c"
-
-#define HANDLE_IOCTL(cmd, handler) { cmd, (ioctl_trans_handler_t)handler, NULL },
-#define COMPATIBLE_IOCTL(cmd) HANDLE_IOCTL(cmd, sys_ioctl) 
-
-#define IOCTL_TABLE_START  struct ioctl_trans ioctl_start[] = {
-#define IOCTL_TABLE_END    };
-
-IOCTL_TABLE_START
-#include <linux/compat_ioctl.h>
-
-#define DECLARES
-#include "compat_ioctl.c"
-
-/* And these ioctls need translation */
-HANDLE_IOCTL(SIOCGPPPSTATS, dev_ifsioc)
-HANDLE_IOCTL(SIOCGPPPCSTATS, dev_ifsioc)
-HANDLE_IOCTL(SIOCGPPPVER, dev_ifsioc)
-
-#if defined(CONFIG_GEN_RTC)
-COMPATIBLE_IOCTL(RTC_AIE_ON)
-COMPATIBLE_IOCTL(RTC_AIE_OFF)
-COMPATIBLE_IOCTL(RTC_UIE_ON)
-COMPATIBLE_IOCTL(RTC_UIE_OFF)
-COMPATIBLE_IOCTL(RTC_PIE_ON)
-COMPATIBLE_IOCTL(RTC_PIE_OFF)
-COMPATIBLE_IOCTL(RTC_WIE_ON)
-COMPATIBLE_IOCTL(RTC_WIE_OFF)
-COMPATIBLE_IOCTL(RTC_ALM_SET)   /* struct rtc_time only has ints */
-COMPATIBLE_IOCTL(RTC_ALM_READ)  /* struct rtc_time only has ints */
-COMPATIBLE_IOCTL(RTC_RD_TIME)   /* struct rtc_time only has ints */
-COMPATIBLE_IOCTL(RTC_SET_TIME)  /* struct rtc_time only has ints */
-HANDLE_IOCTL(RTC_IRQP_READ, w_long)
-COMPATIBLE_IOCTL(RTC_IRQP_SET)
-HANDLE_IOCTL(RTC_EPOCH_READ, w_long)
-COMPATIBLE_IOCTL(RTC_EPOCH_SET)
-#endif
-
-IOCTL_TABLE_END
-
-int ioctl_table_size = ARRAY_SIZE(ioctl_start);
diff --git a/arch/parisc/kernel/pci-dma.c b/arch/parisc/kernel/pci-dma.c
index f94a02e..a6caf10 100644
--- a/arch/parisc/kernel/pci-dma.c
+++ b/arch/parisc/kernel/pci-dma.c
@@ -33,10 +33,10 @@
 #include <asm/uaccess.h>
 #include <asm/tlbflush.h>	/* for purge_tlb_*() macros */
 
-static struct proc_dir_entry * proc_gsc_root = NULL;
+static struct proc_dir_entry * proc_gsc_root __read_mostly = NULL;
 static int pcxl_proc_info(char *buffer, char **start, off_t offset, int length);
-static unsigned long pcxl_used_bytes = 0;
-static unsigned long pcxl_used_pages = 0;
+static unsigned long pcxl_used_bytes __read_mostly = 0;
+static unsigned long pcxl_used_pages __read_mostly = 0;
 
 extern unsigned long pcxl_dma_start; /* Start of pcxl dma mapping area */
 static spinlock_t   pcxl_res_lock;
diff --git a/arch/parisc/kernel/pdc_chassis.c b/arch/parisc/kernel/pdc_chassis.c
index 52004ae..2a01fe1 100644
--- a/arch/parisc/kernel/pdc_chassis.c
+++ b/arch/parisc/kernel/pdc_chassis.c
@@ -30,6 +30,7 @@
 #include <linux/kernel.h>
 #include <linux/reboot.h>
 #include <linux/notifier.h>
+#include <linux/cache.h>
 
 #include <asm/pdc_chassis.h>
 #include <asm/processor.h>
@@ -38,8 +39,8 @@
 
 
 #ifdef CONFIG_PDC_CHASSIS
-static int pdc_chassis_old = 0;	
-static unsigned int pdc_chassis_enabled = 1;
+static int pdc_chassis_old __read_mostly = 0;	
+static unsigned int pdc_chassis_enabled __read_mostly = 1;
 
 
 /**
@@ -132,7 +133,7 @@
 {
 #ifdef CONFIG_PDC_CHASSIS
 	int handle = 0;
-	if (pdc_chassis_enabled) {
+	if (likely(pdc_chassis_enabled)) {
 		DPRINTK(KERN_DEBUG "%s: parisc_pdc_chassis_init()\n", __FILE__);
 
 		/* Let see if we have something to handle... */
@@ -142,7 +143,7 @@
 			printk(KERN_INFO "Enabling PDC_PAT chassis codes support.\n");
 			handle = 1;
 		}
-		else if (pdc_chassis_old) {
+		else if (unlikely(pdc_chassis_old)) {
 			printk(KERN_INFO "Enabling old style chassis LED panel support.\n");
 			handle = 1;
 		}
@@ -178,7 +179,7 @@
 	/* Maybe we should do that in an other way ? */
 	int retval = 0;
 #ifdef CONFIG_PDC_CHASSIS
-	if (pdc_chassis_enabled) {
+	if (likely(pdc_chassis_enabled)) {
 
 		DPRINTK(KERN_DEBUG "%s: pdc_chassis_send_status(%d)\n", __FILE__, message);
 
@@ -214,7 +215,7 @@
 			}
 		} else retval = -1;
 #else
-		if (pdc_chassis_old) {
+		if (unlikely(pdc_chassis_old)) {
 			switch (message) {
 				case PDC_CHASSIS_DIRECT_BSTART:
 				case PDC_CHASSIS_DIRECT_BCOMPLETE:
diff --git a/arch/parisc/kernel/perf.c b/arch/parisc/kernel/perf.c
index f6fec62..11d406c 100644
--- a/arch/parisc/kernel/perf.c
+++ b/arch/parisc/kernel/perf.c
@@ -42,6 +42,7 @@
  *  on every box. 
  */
 
+#include <linux/capability.h>
 #include <linux/init.h>
 #include <linux/proc_fs.h>
 #include <linux/miscdevice.h>
@@ -66,10 +67,10 @@
 	uint8_t		write_control;
 };
 
-static int perf_processor_interface = UNKNOWN_INTF;
-static int perf_enabled = 0;
+static int perf_processor_interface __read_mostly = UNKNOWN_INTF;
+static int perf_enabled __read_mostly = 0;
 static spinlock_t perf_lock;
-struct parisc_device *cpu_device = NULL;
+struct parisc_device *cpu_device __read_mostly = NULL;
 
 /* RDRs to write for PCX-W */
 static int perf_rdrs_W[] = 
diff --git a/arch/parisc/kernel/process.c b/arch/parisc/kernel/process.c
index fee4f1f..5da4167 100644
--- a/arch/parisc/kernel/process.c
+++ b/arch/parisc/kernel/process.c
@@ -54,7 +54,7 @@
 #include <asm/uaccess.h>
 #include <asm/unwind.h>
 
-static int hlt_counter;
+static int hlt_counter __read_mostly;
 
 /*
  * Power off function, if any
@@ -295,7 +295,7 @@
 	    struct task_struct * p, struct pt_regs * pregs)
 {
 	struct pt_regs * cregs = &(p->thread.regs);
-	struct thread_info *ti = p->thread_info;
+	void *stack = task_stack_page(p);
 	
 	/* We have to use void * instead of a function pointer, because
 	 * function pointers aren't a pointer to the function on 64-bit.
@@ -322,7 +322,7 @@
 	 */
 	if (usp == 1) {
 		/* kernel thread */
-		cregs->ksp = (((unsigned long)(ti)) + THREAD_SZ_ALGN);
+		cregs->ksp = (unsigned long)stack + THREAD_SZ_ALGN;
 		/* Must exit via ret_from_kernel_thread in order
 		 * to call schedule_tail()
 		 */
@@ -344,7 +344,7 @@
 		 */
 
 		/* Use same stack depth as parent */
-		cregs->ksp = ((unsigned long)(ti))
+		cregs->ksp = (unsigned long)stack
 			+ (pregs->gr[21] & (THREAD_SIZE - 1));
 		cregs->gr[30] = usp;
 		if (p->personality == PER_HPUX) {
diff --git a/arch/parisc/kernel/processor.c b/arch/parisc/kernel/processor.c
index 4f5bbcf..6df9f62 100644
--- a/arch/parisc/kernel/processor.c
+++ b/arch/parisc/kernel/processor.c
@@ -44,10 +44,10 @@
 #include <asm/irq.h>		/* for struct irq_region */
 #include <asm/parisc-device.h>
 
-struct system_cpuinfo_parisc boot_cpu_data;
+struct system_cpuinfo_parisc boot_cpu_data __read_mostly;
 EXPORT_SYMBOL(boot_cpu_data);
 
-struct cpuinfo_parisc cpu_data[NR_CPUS];
+struct cpuinfo_parisc cpu_data[NR_CPUS] __read_mostly;
 
 /*
 **  	PARISC CPU driver - claim "device" and initialize CPU data structures.
@@ -378,12 +378,12 @@
 	return 0;
 }
 
-static struct parisc_device_id processor_tbl[] = {
+static struct parisc_device_id processor_tbl[] __read_mostly = {
 	{ HPHW_NPROC, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, SVERSION_ANY_ID },
 	{ 0, }
 };
 
-static struct parisc_driver cpu_driver = {
+static struct parisc_driver cpu_driver __read_mostly = {
 	.name		= "CPU",
 	.id_table	= processor_tbl,
 	.probe		= processor_probe
diff --git a/arch/parisc/kernel/setup.c b/arch/parisc/kernel/setup.c
index 73e9c34..4a36ec3 100644
--- a/arch/parisc/kernel/setup.c
+++ b/arch/parisc/kernel/setup.c
@@ -46,15 +46,15 @@
 #include <asm/io.h>
 #include <asm/setup.h>
 
-char	command_line[COMMAND_LINE_SIZE];
+char	command_line[COMMAND_LINE_SIZE] __read_mostly;
 
 /* Intended for ccio/sba/cpu statistics under /proc/bus/{runway|gsc} */
-struct proc_dir_entry * proc_runway_root = NULL;
-struct proc_dir_entry * proc_gsc_root = NULL;
-struct proc_dir_entry * proc_mckinley_root = NULL;
+struct proc_dir_entry * proc_runway_root __read_mostly = NULL;
+struct proc_dir_entry * proc_gsc_root __read_mostly = NULL;
+struct proc_dir_entry * proc_mckinley_root __read_mostly = NULL;
 
 #if !defined(CONFIG_PA20) && (defined(CONFIG_IOMMU_CCIO) || defined(CONFIG_IOMMU_SBA))
-int parisc_bus_is_phys = 1;	/* Assume no IOMMU is present */
+int parisc_bus_is_phys __read_mostly = 1;	/* Assume no IOMMU is present */
 EXPORT_SYMBOL(parisc_bus_is_phys);
 #endif
 
diff --git a/arch/parisc/kernel/smp.c b/arch/parisc/kernel/smp.c
index ce89da0..25564b7 100644
--- a/arch/parisc/kernel/smp.c
+++ b/arch/parisc/kernel/smp.c
@@ -39,7 +39,7 @@
 #include <asm/atomic.h>
 #include <asm/current.h>
 #include <asm/delay.h>
-#include <asm/pgalloc.h>	/* for flush_tlb_all() proto/macro */
+#include <asm/tlbflush.h>
 
 #include <asm/io.h>
 #include <asm/irq.h>		/* for CPU_IRQ_REGION and friends */
@@ -58,9 +58,9 @@
 
 volatile struct task_struct *smp_init_current_idle_task;
 
-static volatile int cpu_now_booting = 0;	/* track which CPU is booting */
+static volatile int cpu_now_booting __read_mostly = 0;	/* track which CPU is booting */
 
-static int parisc_max_cpus = 1;
+static int parisc_max_cpus __read_mostly = 1;
 
 /* online cpus are ones that we've managed to bring up completely
  * possible cpus are all valid cpu 
@@ -71,8 +71,8 @@
  * empty in the beginning.
  */
 
-cpumask_t cpu_online_map = CPU_MASK_NONE;	/* Bitmap of online CPUs */
-cpumask_t cpu_possible_map = CPU_MASK_ALL;	/* Bitmap of Present CPUs */
+cpumask_t cpu_online_map   __read_mostly = CPU_MASK_NONE;	/* Bitmap of online CPUs */
+cpumask_t cpu_possible_map __read_mostly = CPU_MASK_ALL;	/* Bitmap of Present CPUs */
 
 EXPORT_SYMBOL(cpu_online_map);
 EXPORT_SYMBOL(cpu_possible_map);
@@ -406,12 +406,10 @@
  * as we want to ensure all TLB's flushed before proceeding.
  */
 
-extern void flush_tlb_all_local(void);
-
 void
 smp_flush_tlb_all(void)
 {
-	on_each_cpu((void (*)(void *))flush_tlb_all_local, NULL, 1, 1);
+	on_each_cpu(flush_tlb_all_local, NULL, 1, 1);
 }
 
 
@@ -487,7 +485,7 @@
 #endif
 
 	flush_cache_all_local(); /* start with known state */
-	flush_tlb_all_local();
+	flush_tlb_all_local(NULL);
 
 	local_irq_enable();  /* Interrupts have been off until now */
 
@@ -519,7 +517,7 @@
 	if (IS_ERR(idle))
 		panic("SMP: fork failed for CPU:%d", cpuid);
 
-	idle->thread_info->cpu = cpuid;
+	task_thread_info(idle)->cpu = cpuid;
 
 	/* Let _start know what logical CPU we're booting
 	** (offset into init_tasks[],cpu_data[])
diff --git a/arch/parisc/kernel/time.c b/arch/parisc/kernel/time.c
index cded256..594930b 100644
--- a/arch/parisc/kernel/time.c
+++ b/arch/parisc/kernel/time.c
@@ -36,8 +36,8 @@
 /* xtime and wall_jiffies keep wall-clock time */
 extern unsigned long wall_jiffies;
 
-static long clocktick;	/* timer cycles per tick */
-static long halftick;
+static long clocktick __read_mostly;	/* timer cycles per tick */
+static long halftick __read_mostly;
 
 #ifdef CONFIG_SMP
 extern void smp_do_timer(struct pt_regs *regs);
diff --git a/arch/parisc/kernel/topology.c b/arch/parisc/kernel/topology.c
index ac2a406..3ba0400 100644
--- a/arch/parisc/kernel/topology.c
+++ b/arch/parisc/kernel/topology.c
@@ -20,8 +20,9 @@
 #include <linux/init.h>
 #include <linux/smp.h>
 #include <linux/cpu.h>
+#include <linux/cache.h>
 
-static struct cpu cpu_devices[NR_CPUS];
+static struct cpu cpu_devices[NR_CPUS] __read_mostly;
 
 static int __init topology_init(void)
 {
diff --git a/arch/parisc/kernel/unaligned.c b/arch/parisc/kernel/unaligned.c
index eaae8a0..de0a1b2 100644
--- a/arch/parisc/kernel/unaligned.c
+++ b/arch/parisc/kernel/unaligned.c
@@ -122,7 +122,7 @@
 #define ERR_NOTHANDLED	-1
 #define ERR_PAGEFAULT	-2
 
-int unaligned_enabled = 1;
+int unaligned_enabled __read_mostly = 1;
 
 void die_if_kernel (char *str, struct pt_regs *regs, long err);
 
diff --git a/arch/parisc/kernel/unwind.c b/arch/parisc/kernel/unwind.c
index db14110..cc1c1af 100644
--- a/arch/parisc/kernel/unwind.c
+++ b/arch/parisc/kernel/unwind.c
@@ -35,7 +35,7 @@
  * we can call unwind_init as early in the bootup process as 
  * possible (before the slab allocator is initialized)
  */
-static struct unwind_table kernel_unwind_table;
+static struct unwind_table kernel_unwind_table __read_mostly;
 static LIST_HEAD(unwind_tables);
 
 static inline const struct unwind_table_entry *
diff --git a/arch/parisc/kernel/vmlinux.lds.S b/arch/parisc/kernel/vmlinux.lds.S
index e5fac3e..6d6436a 100644
--- a/arch/parisc/kernel/vmlinux.lds.S
+++ b/arch/parisc/kernel/vmlinux.lds.S
@@ -68,7 +68,7 @@
   RODATA
 
   /* writeable */
-  . = ALIGN(4096);		/* Make sure this is paged aligned so
+  . = ALIGN(4096);		/* Make sure this is page aligned so
   				   that we can properly leave these
 				   as writable */
   data_start = .;
@@ -105,6 +105,10 @@
   . = ALIGN(16);
   .data.lock_aligned : { *(.data.lock_aligned) }
 
+  /* rarely changed data like cpu maps */
+  . = ALIGN(16);
+  .data.read_mostly : { *(.data.read_mostly) }
+
   _edata = .;			/* End of data section */
 
   . = ALIGN(16384); 		/* init_task */
@@ -194,14 +198,7 @@
 #endif
 	}
 
-  /* Stabs debugging sections.  */
-  .stab 0 : { *(.stab) }
-  .stabstr 0 : { *(.stabstr) }
-  .stab.excl 0 : { *(.stab.excl) }
-  .stab.exclstr 0 : { *(.stab.exclstr) }
-  .stab.index 0 : { *(.stab.index) }
-  .stab.indexstr 0 : { *(.stab.indexstr) }
-  .comment 0 : { *(.comment) }
+  STABS_DEBUG
   .note 0 : { *(.note) }	
 
 }
diff --git a/arch/parisc/mm/init.c b/arch/parisc/mm/init.c
index 29b998e..720287d 100644
--- a/arch/parisc/mm/init.c
+++ b/arch/parisc/mm/init.c
@@ -36,9 +36,9 @@
 extern char __init_begin, __init_end;
 
 #ifdef CONFIG_DISCONTIGMEM
-struct node_map_data node_data[MAX_NUMNODES];
-bootmem_data_t bmem_data[MAX_NUMNODES];
-unsigned char pfnnid_map[PFNNID_MAP_MAX];
+struct node_map_data node_data[MAX_NUMNODES] __read_mostly;
+bootmem_data_t bmem_data[MAX_NUMNODES] __read_mostly;
+unsigned char pfnnid_map[PFNNID_MAP_MAX] __read_mostly;
 #endif
 
 static struct resource data_resource = {
@@ -58,14 +58,14 @@
 	.flags	= IORESOURCE_BUSY | IORESOURCE_MEM,
 };
 
-static struct resource sysram_resources[MAX_PHYSMEM_RANGES];
+static struct resource sysram_resources[MAX_PHYSMEM_RANGES] __read_mostly;
 
 /* The following array is initialized from the firmware specific
  * information retrieved in kernel/inventory.c.
  */
 
-physmem_range_t pmem_ranges[MAX_PHYSMEM_RANGES];
-int npmem_ranges;
+physmem_range_t pmem_ranges[MAX_PHYSMEM_RANGES] __read_mostly;
+int npmem_ranges __read_mostly;
 
 #ifdef __LP64__
 #define MAX_MEM         (~0UL)
@@ -73,7 +73,7 @@
 #define MAX_MEM         (3584U*1024U*1024U)
 #endif /* !__LP64__ */
 
-static unsigned long mem_limit = MAX_MEM;
+static unsigned long mem_limit __read_mostly = MAX_MEM;
 
 static void __init mem_limit_func(void)
 {
@@ -300,6 +300,13 @@
 			max_pfn = start_pfn + npages;
 	}
 
+	/* IOMMU is always used to access "high mem" on those boxes
+	 * that can support enough mem that a PCI device couldn't
+	 * directly DMA to any physical addresses.
+	 * ISA DMA support will need to revisit this.
+	 */
+	max_low_pfn = max_pfn;
+
 	if ((bootmap_pfn - bootmap_start_pfn) != bootmap_pages) {
 		printk(KERN_WARNING "WARNING! bootmap sizing is messed up!\n");
 		BUG();
@@ -431,11 +438,11 @@
 #define SET_MAP_OFFSET(x) ((void *)(((unsigned long)(x) + VM_MAP_OFFSET) \
 				     & ~(VM_MAP_OFFSET-1)))
 
-void *vmalloc_start;
+void *vmalloc_start __read_mostly;
 EXPORT_SYMBOL(vmalloc_start);
 
 #ifdef CONFIG_PA11
-unsigned long pcxl_dma_start;
+unsigned long pcxl_dma_start __read_mostly;
 #endif
 
 void __init mem_init(void)
@@ -475,7 +482,7 @@
 	return 0;
 }
 
-unsigned long *empty_zero_page;
+unsigned long *empty_zero_page __read_mostly;
 
 void show_mem(void)
 {
@@ -998,7 +1005,7 @@
 void flush_tlb_all(void)
 {
 	spin_lock(&sid_lock);
-	flush_tlb_all_local();
+	flush_tlb_all_local(NULL);
 	recycle_sids();
 	spin_unlock(&sid_lock);
 }
diff --git a/arch/parisc/mm/ioremap.c b/arch/parisc/mm/ioremap.c
index 5c7a1b3..edd9a95 100644
--- a/arch/parisc/mm/ioremap.c
+++ b/arch/parisc/mm/ioremap.c
@@ -1,12 +1,9 @@
 /*
  * arch/parisc/mm/ioremap.c
  *
- * Re-map IO memory to kernel address space so that we can access it.
- * This is needed for high PCI addresses that aren't mapped in the
- * 640k-1MB IO memory area on PC's
- *
  * (C) Copyright 1995 1996 Linus Torvalds
  * (C) Copyright 2001 Helge Deller <deller@gmx.de>
+ * (C) Copyright 2005 Kyle McMartin <kyle@parisc-linux.org>
  */
 
 #include <linux/vmalloc.h>
@@ -14,81 +11,107 @@
 #include <linux/module.h>
 #include <asm/io.h>
 #include <asm/pgalloc.h>
+#include <asm/tlbflush.h>
+#include <asm/cacheflush.h>
 
-static inline void remap_area_pte(pte_t * pte, unsigned long address, unsigned long size,
-	unsigned long phys_addr, unsigned long flags)
+static inline void 
+remap_area_pte(pte_t *pte, unsigned long address, unsigned long size,
+	       unsigned long phys_addr, unsigned long flags)
 {
-	unsigned long end;
+	unsigned long end, pfn;
+	pgprot_t pgprot = __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY |
+				   _PAGE_ACCESSED | flags);
 
 	address &= ~PMD_MASK;
+
 	end = address + size;
 	if (end > PMD_SIZE)
 		end = PMD_SIZE;
-	if (address >= end)
-		BUG();
+
+	BUG_ON(address >= end);
+
+	pfn = phys_addr >> PAGE_SHIFT;
 	do {
-		if (!pte_none(*pte)) {
-			printk(KERN_ERR "remap_area_pte: page already exists\n");
-			BUG();
-		}
-		set_pte(pte, mk_pte_phys(phys_addr, __pgprot(_PAGE_PRESENT | _PAGE_RW | 
-					_PAGE_DIRTY | _PAGE_ACCESSED | flags)));
+		BUG_ON(!pte_none(*pte));
+
+		set_pte(pte, pfn_pte(pfn, pgprot));
+
 		address += PAGE_SIZE;
-		phys_addr += PAGE_SIZE;
+		pfn++;
 		pte++;
 	} while (address && (address < end));
 }
 
-static inline int remap_area_pmd(pmd_t * pmd, unsigned long address, unsigned long size,
-	unsigned long phys_addr, unsigned long flags)
+static inline int 
+remap_area_pmd(pmd_t *pmd, unsigned long address, unsigned long size,
+	       unsigned long phys_addr, unsigned long flags)
 {
 	unsigned long end;
 
 	address &= ~PGDIR_MASK;
+
 	end = address + size;
 	if (end > PGDIR_SIZE)
 		end = PGDIR_SIZE;
+
+	BUG_ON(address >= end);
+
 	phys_addr -= address;
-	if (address >= end)
-		BUG();
 	do {
-		pte_t * pte = pte_alloc_kernel(pmd, address);
+		pte_t *pte = pte_alloc_kernel(pmd, address);
 		if (!pte)
 			return -ENOMEM;
-		remap_area_pte(pte, address, end - address, address + phys_addr, flags);
+
+		remap_area_pte(pte, address, end - address, 
+			       address + phys_addr, flags);
+
 		address = (address + PMD_SIZE) & PMD_MASK;
 		pmd++;
 	} while (address && (address < end));
+
 	return 0;
 }
 
-#if (USE_HPPA_IOREMAP)
-static int remap_area_pages(unsigned long address, unsigned long phys_addr,
-				 unsigned long size, unsigned long flags)
+#if USE_HPPA_IOREMAP
+static int 
+remap_area_pages(unsigned long address, unsigned long phys_addr,
+		 unsigned long size, unsigned long flags)
 {
-	int error;
-	pgd_t * dir;
+	pgd_t *dir;
+	int error = 0;
 	unsigned long end = address + size;
 
+	BUG_ON(address >= end);
+
 	phys_addr -= address;
-	dir = pgd_offset(&init_mm, address);
+	dir = pgd_offset_k(address);
+
 	flush_cache_all();
-	if (address >= end)
-		BUG();
+
 	do {
+		pud_t *pud;
 		pmd_t *pmd;
-		pmd = pmd_alloc(&init_mm, dir, address);
+
 		error = -ENOMEM;
+		pud = pud_alloc(&init_mm, dir, address);
+		if (!pud)
+			break;
+
+		pmd = pmd_alloc(&init_mm, pud, address);
 		if (!pmd)
 			break;
+
 		if (remap_area_pmd(pmd, address, end - address,
-					 phys_addr + address, flags))
+				   phys_addr + address, flags))
 			break;
+
 		error = 0;
 		address = (address + PGDIR_SIZE) & PGDIR_MASK;
 		dir++;
 	} while (address && (address < end));
+
 	flush_tlb_all();
+
 	return error;
 }
 #endif /* USE_HPPA_IOREMAP */
@@ -123,8 +146,7 @@
 
 /*
  * Remap an arbitrary physical address space into the kernel virtual
- * address space. Needed when the kernel wants to access high addresses
- * directly.
+ * address space.
  *
  * NOTE! We need to allow non-page-aligned mappings too: we will obviously
  * have to convert them into an offset in a page-aligned mapping, but the
@@ -148,8 +170,8 @@
 #endif
 
 #else
-	void * addr;
-	struct vm_struct * area;
+	void *addr;
+	struct vm_struct *area;
 	unsigned long offset, last_addr;
 
 	/* Don't allow wraparound or zero size */
@@ -167,9 +189,11 @@
 		t_addr = __va(phys_addr);
 		t_end = t_addr + (size - 1);
 	   
-		for(page = virt_to_page(t_addr); page <= virt_to_page(t_end); page++)
+		for (page = virt_to_page(t_addr); 
+		     page <= virt_to_page(t_end); page++) {
 			if(!PageReserved(page))
 				return NULL;
+		}
 	}
 
 	/*
@@ -185,11 +209,13 @@
 	area = get_vm_area(size, VM_IOREMAP);
 	if (!area)
 		return NULL;
+
 	addr = area->addr;
 	if (remap_area_pages((unsigned long) addr, phys_addr, size, flags)) {
 		vfree(addr);
 		return NULL;
 	}
+
 	return (void __iomem *) (offset + (char *)addr);
 #endif
 }
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 28004f0..01feed0 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -71,15 +71,39 @@
 	bool
 	default y
 
+config PPC_OF
+	def_bool y
+
+config PPC_UDBG_16550
+	bool
+	default n
+
+config CRASH_DUMP
+	bool "kernel crash dumps (EXPERIMENTAL)"
+	depends on PPC_MULTIPLATFORM
+	depends on EXPERIMENTAL
+	help
+	  Build a kernel suitable for use as a kdump capture kernel.
+	  The kernel will be linked at a different address than normal, and
+	  so can only be used for Kdump.
+
+	  Don't change this unless you know what you are doing.
+
+config GENERIC_TBSYNC
+	bool
+	default y if PPC32 && SMP
+	default n
+
 menu "Processor support"
 choice
 	prompt "Processor Type"
 	depends on PPC32
 	default 6xx
 
-config 6xx
+config CLASSIC32
 	bool "6xx/7xx/74xx"
 	select PPC_FPU
+	select 6xx
 	help
 	  There are four families of PowerPC chips supported.  The more common
 	  types (601, 603, 604, 740, 750, 7400), the Motorola embedded
@@ -93,12 +117,20 @@
 
 config PPC_52xx
 	bool "Freescale 52xx"
+	select 6xx
+	select PPC_FPU
 	
 config PPC_82xx
 	bool "Freescale 82xx"
+	select 6xx
+	select PPC_FPU
 
 config PPC_83xx
 	bool "Freescale 83xx"
+	select 6xx
+	select FSL_SOC
+	select 83xx
+	select PPC_FPU
 
 config 40x
 	bool "AMCC 40x"
@@ -134,6 +166,13 @@
 	depends on PPC64
 	def_bool y
 
+config 6xx
+	bool
+
+# this is temp to handle compat with arch=ppc
+config 83xx
+	bool
+
 config PPC_FPU
 	bool
 	default y if PPC64
@@ -166,7 +205,7 @@
 
 config ALTIVEC
 	bool "AltiVec Support"
-	depends on 6xx || POWER4
+	depends on CLASSIC32 || POWER4
 	---help---
 	  This option enables kernel support for the Altivec extensions to the
 	  PowerPC processor. The kernel currently supports saving and restoring
@@ -239,7 +278,7 @@
 source "init/Kconfig"
 
 menu "Platform support"
-	depends on PPC64 || 6xx
+	depends on PPC64 || CLASSIC32
 
 choice
 	prompt "Machine type"
@@ -275,6 +314,7 @@
 	select PPC_I8259
 	select PPC_RTAS
 	select RTAS_ERROR_LOGGING
+	select PPC_UDBG_16550
 	default y
 
 config PPC_CHRP
@@ -284,6 +324,7 @@
 	select PPC_INDIRECT_PCI
 	select PPC_RTAS
 	select PPC_MPC106
+	select PPC_UDBG_16550
 	default y
 
 config PPC_PMAC
@@ -306,6 +347,7 @@
 	depends on PPC_MULTIPLATFORM && PPC32 && BROKEN
 	select PPC_I8259
 	select PPC_INDIRECT_PCI
+	select PPC_UDBG_16550
 	default y
 
 config PPC_MAPLE
@@ -314,6 +356,7 @@
 	select U3_DART
 	select MPIC_BROKEN_U3
 	select GENERIC_TBSYNC
+	select PPC_UDBG_16550
 	default n
 	help
           This option enables support for the Maple 970FX Evaluation Board.
@@ -324,9 +367,7 @@
 	depends on PPC_MULTIPLATFORM && PPC64
 	select PPC_RTAS
 	select MMIO_NVRAM
-
-config PPC_OF
-	def_bool y
+	select PPC_UDBG_16550
 
 config XICS
 	depends on PPC_PSERIES
@@ -375,17 +416,6 @@
 	bool
 	default y
 
-config CRASH_DUMP
-	bool "kernel crash dumps (EXPERIMENTAL)"
-	depends on PPC_MULTIPLATFORM
-	depends on EXPERIMENTAL
-	help
-	  Build a kernel suitable for use as a kdump capture kernel.
-	  The kernel will be linked at a different address than normal, and
-	  so can only be used for Kdump.
-
-	  Don't change this unless you know what you are doing.
-
 config IBMVIO
 	depends on PPC_PSERIES || PPC_ISERIES
 	bool
@@ -401,11 +431,6 @@
 	bool
 	default n
 
-config GENERIC_TBSYNC
-	bool
-	default y if CONFIG_PPC32 && CONFIG_SMP
-	default n
-
 source "drivers/cpufreq/Kconfig"
 
 config CPU_FREQ_PMAC
@@ -486,6 +511,7 @@
 
 source arch/powerpc/platforms/embedded6xx/Kconfig
 source arch/powerpc/platforms/4xx/Kconfig
+source arch/powerpc/platforms/83xx/Kconfig
 source arch/powerpc/platforms/85xx/Kconfig
 source arch/powerpc/platforms/8xx/Kconfig
 source arch/powerpc/platforms/cell/Kconfig
@@ -709,7 +735,7 @@
 config PPC_INDIRECT_PCI
 	bool
 	depends on PCI
-	default y if 40x || 44x || 85xx || 83xx
+	default y if 40x || 44x || 85xx
 	default n
 
 config EISA
@@ -718,13 +744,16 @@
 config SBUS
 	bool
 
+config FSL_SOC
+	bool
+
 # Yes MCA RS/6000s exist but Linux-PPC does not currently support any
 config MCA
 	bool
 
 config PCI
-	bool "PCI support" if 40x || CPM2 || 83xx || 85xx || PPC_MPC52xx || (EMBEDDED && PPC_ISERIES)
-	default y if !40x && !CPM2 && !8xx && !APUS && !83xx && !85xx
+	bool "PCI support" if 40x || CPM2 || PPC_83xx || 85xx || PPC_MPC52xx || (EMBEDDED && PPC_ISERIES)
+	default y if !40x && !CPM2 && !8xx && !APUS && !PPC_83xx && !85xx
 	default PCI_PERMEDIA if !4xx && !CPM2 && !8xx && APUS
 	default PCI_QSPAN if !4xx && !CPM2 && 8xx
 	help
@@ -737,11 +766,6 @@
 	bool
 	default PCI
 
-config MPC83xx_PCI2
-	bool "  Supprt for 2nd PCI host controller"
-	depends on PCI && MPC834x
-	default y if MPC834x_SYS
-
 config PCI_QSPAN
 	bool "QSpan PCI"
 	depends on !4xx && !CPM2 && 8xx
diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug
index 30a30bf..9254806 100644
--- a/arch/powerpc/Kconfig.debug
+++ b/arch/powerpc/Kconfig.debug
@@ -115,4 +115,46 @@
 	depends on IBM_OCP || XILINX_OCP
 	default y
 
+choice
+	prompt "Early debugging (dangerous)"
+	bool
+	optional
+	help
+	  Enable early debugging. Careful, if you enable debugging for the
+	  wrong type of machine your kernel _will not boot_.
+
+config PPC_EARLY_DEBUG_LPAR
+	bool "LPAR HV Console"
+	depends on PPC_PSERIES
+	help
+	  Select this to enable early debugging for a machine with a HVC
+	  console on vterm 0.
+
+config PPC_EARLY_DEBUG_G5
+	bool "Apple G5"
+	depends on PPC_PMAC64
+	help
+	  Select this to enable early debugging for Apple G5 machines.
+
+config PPC_EARLY_DEBUG_RTAS
+	bool "RTAS Panel"
+	depends on PPC_RTAS
+	help
+	  Select this to enable early debugging via the RTAS panel.
+
+config PPC_EARLY_DEBUG_MAPLE
+	bool "Maple real mode"
+	depends on PPC_MAPLE
+	help
+	  Select this to enable early debugging for Maple.
+
+config PPC_EARLY_DEBUG_ISERIES
+	bool "iSeries HV Console"
+	depends on PPC_ISERIES
+	help
+	  Select this to enable early debugging for legacy iSeries. You need
+	  to hit "Ctrl-x Ctrl-x" to see the messages on the console.
+
+endchoice
+
 endmenu
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 5f80e58..d3654a2 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -76,8 +76,7 @@
 CHECKFLAGS	+= -m$(SZ) -D__powerpc__ -D__powerpc$(SZ)__
 
 ifeq ($(CONFIG_PPC64),y)
-GCC_VERSION     := $(call cc-version)
-GCC_BROKEN_VEC	:= $(shell if [ $(GCC_VERSION) -lt 0400 ] ; then echo "y"; fi)
+GCC_BROKEN_VEC	:= $(shell if [ $(call cc-version) -lt 0400 ] ; then echo "y"; fi)
 
 ifeq ($(CONFIG_POWER4_ONLY),y)
 ifeq ($(CONFIG_ALTIVEC),y)
@@ -189,10 +188,9 @@
 # Ensure this is binutils 2.12.1 (or 2.12.90.0.7) or later for altivec
 # instructions.
 # gcc-3.4 and binutils-2.14 are a fatal combination.
-GCC_VERSION	:= $(call cc-version)
 
 checkbin:
-	@if test "$(GCC_VERSION)" = "0304" ; then \
+	@if test "$(call cc-version)" = "0304" ; then \
 		if ! /bin/echo mftb 5 | $(AS) -v -mppc -many -o $(TOUT) >/dev/null 2>&1 ; then \
 			echo -n '*** ${VERSION}.${PATCHLEVEL} kernels no longer build '; \
 			echo 'correctly with gcc-3.4 and your version of binutils.'; \
diff --git a/arch/powerpc/boot/.gitignore b/arch/powerpc/boot/.gitignore
new file mode 100644
index 0000000..45c9ad2
--- /dev/null
+++ b/arch/powerpc/boot/.gitignore
@@ -0,0 +1,20 @@
+addnote
+infblock.c
+infblock.h
+infcodes.c
+infcodes.h
+inffast.c
+inffast.h
+inflate.c
+inftrees.c
+inftrees.h
+infutil.c
+infutil.h
+kernel-vmlinux.strip.c
+kernel-vmlinux.strip.gz
+uImage
+zImage
+zImage.vmode
+zconf.h
+zlib.h
+zutil.h
diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile
index 22726ae..b53d677 100644
--- a/arch/powerpc/boot/Makefile
+++ b/arch/powerpc/boot/Makefile
@@ -176,4 +176,4 @@
 install: $(CONFIGURE) $(BOOTIMAGE)
 	sh -x $(srctree)/$(src)/install.sh "$(KERNELRELEASE)" vmlinux System.map "$(INSTALL_PATH)" "$(BOOTIMAGE)"
 
-clean-files := $(addprefix $(objtree)/, $(obj-boot) vmlinux.strip)
+clean-files += $(addprefix $(objtree)/, $(obj-boot) vmlinux.strip)
diff --git a/arch/powerpc/configs/ppc64_defconfig b/arch/powerpc/configs/ppc64_defconfig
index 509399e..0b2b55a 100644
--- a/arch/powerpc/configs/ppc64_defconfig
+++ b/arch/powerpc/configs/ppc64_defconfig
@@ -861,7 +861,7 @@
 CONFIG_SERIAL_CORE_CONSOLE=y
 # CONFIG_SERIAL_PMACZILOG is not set
 CONFIG_SERIAL_ICOM=m
-CONFIG_SERIAL_JSM=m
+# CONFIG_SERIAL_JSM is not set
 CONFIG_UNIX98_PTYS=y
 CONFIG_LEGACY_PTYS=y
 CONFIG_LEGACY_PTY_COUNT=256
@@ -878,7 +878,7 @@
 #
 # CONFIG_WATCHDOG is not set
 # CONFIG_RTC is not set
-# CONFIG_GEN_RTC is not set
+CONFIG_GEN_RTC=y
 # CONFIG_DTLK is not set
 # CONFIG_R3964 is not set
 # CONFIG_APPLICOM is not set
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index 6e03b59..a94699d 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -4,7 +4,6 @@
 
 ifeq ($(CONFIG_PPC64),y)
 EXTRA_CFLAGS	+= -mno-minimal-toc
-CFLAGS_ioctl32.o += -Ifs/
 endif
 ifeq ($(CONFIG_PPC32),y)
 CFLAGS_prom_init.o      += -fPIC
@@ -12,11 +11,12 @@
 endif
 
 obj-y				:= semaphore.o cputable.o ptrace.o syscalls.o \
-				   irq.o align.o signal_32.o pmc.o vdso.o
+				   irq.o align.o signal_32.o pmc.o vdso.o \
+				   init_task.o process.o
 obj-y				+= vdso32/
 obj-$(CONFIG_PPC64)		+= setup_64.o binfmt_elf32.o sys_ppc32.o \
 				   signal_64.o ptrace32.o systbl.o \
-				   paca.o ioctl32.o cpu_setup_power4.o \
+				   paca.o cpu_setup_power4.o \
 				   firmware.o sysfs.o idle_64.o
 obj-$(CONFIG_PPC64)		+= vdso64/
 obj-$(CONFIG_ALTIVEC)		+= vecemu.o vector.o
@@ -45,8 +45,7 @@
 extra-$(CONFIG_8xx)		:= head_8xx.o
 extra-y				+= vmlinux.lds
 
-obj-y				+= process.o init_task.o time.o \
-				   prom.o traps.o setup-common.o udbg.o
+obj-y				+= time.o prom.o traps.o setup-common.o udbg.o
 obj-$(CONFIG_PPC32)		+= entry_32.o setup_32.o misc_32.o systbl.o
 obj-$(CONFIG_PPC64)		+= misc_64.o dma_64.o iommu.o
 obj-$(CONFIG_PPC_MULTIPLATFORM)	+= prom_init.o
@@ -55,16 +54,16 @@
 obj-$(CONFIG_6xx)		+= idle_6xx.o
 obj-$(CONFIG_SMP)		+= smp.o
 obj-$(CONFIG_KPROBES)		+= kprobes.o
-obj-$(CONFIG_SERIAL_8250)	+= legacy_serial.o udbg_16550.o
+obj-$(CONFIG_PPC_UDBG_16550)	+= legacy_serial.o udbg_16550.o
 module-$(CONFIG_PPC64)		+= module_64.o
 obj-$(CONFIG_MODULES)		+= $(module-y)
 
 pci64-$(CONFIG_PPC64)		+= pci_64.o pci_dn.o pci_iommu.o \
 				   pci_direct_iommu.o iomap.o
 obj-$(CONFIG_PCI)		+= $(pci64-y)
-kexec-$(CONFIG_PPC64)		:= machine_kexec_64.o
+kexec-$(CONFIG_PPC64)		:= machine_kexec_64.o crash.o
 kexec-$(CONFIG_PPC32)		:= machine_kexec_32.o
-obj-$(CONFIG_KEXEC)		+= machine_kexec.o crash.o $(kexec-y)
+obj-$(CONFIG_KEXEC)		+= machine_kexec.o $(kexec-y)
 
 ifeq ($(CONFIG_PPC_ISERIES),y)
 $(obj)/head_64.o: $(obj)/lparmap.s
diff --git a/arch/powerpc/kernel/crash.c b/arch/powerpc/kernel/crash.c
index 4681155..5f248e3 100644
--- a/arch/powerpc/kernel/crash.c
+++ b/arch/powerpc/kernel/crash.c
@@ -18,7 +18,6 @@
 #include <linux/kexec.h>
 #include <linux/bootmem.h>
 #include <linux/crash_dump.h>
-#include <linux/irq.h>
 #include <linux/delay.h>
 #include <linux/elf.h>
 #include <linux/elfcore.h>
@@ -30,6 +29,7 @@
 #include <asm/kdump.h>
 #include <asm/lmb.h>
 #include <asm/firmware.h>
+#include <asm/smp.h>
 
 #ifdef DEBUG
 #include <asm/udbg.h>
diff --git a/arch/powerpc/kernel/crash_dump.c b/arch/powerpc/kernel/crash_dump.c
index 87effa3..211d726 100644
--- a/arch/powerpc/kernel/crash_dump.c
+++ b/arch/powerpc/kernel/crash_dump.c
@@ -55,6 +55,7 @@
 	DBG(" <- kdump_setup()\n");
 }
 
+#ifdef CONFIG_PROC_VMCORE
 static int __init parse_elfcorehdr(char *p)
 {
 	if (p)
@@ -63,6 +64,7 @@
 	return 0;
 }
 __setup("elfcorehdr=", parse_elfcorehdr);
+#endif
 
 static int __init parse_savemaxmem(char *p)
 {
diff --git a/arch/powerpc/kernel/ioctl32.c b/arch/powerpc/kernel/ioctl32.c
deleted file mode 100644
index 0fa3d27..0000000
--- a/arch/powerpc/kernel/ioctl32.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * ioctl32.c: Conversion between 32bit and 64bit native ioctls.
- *
- * Based on sparc64 ioctl32.c by:
- *
- * Copyright (C) 1997-2000  Jakub Jelinek  (jakub@redhat.com)
- * Copyright (C) 1998  Eddie C. Dost  (ecd@skynet.be)
- *
- * ppc64 changes:
- *
- * Copyright (C) 2000  Ken Aaker (kdaaker@rchland.vnet.ibm.com)
- * Copyright (C) 2001  Anton Blanchard (antonb@au.ibm.com)
- *
- * These routines maintain argument size conversion between 32bit and 64bit
- * ioctls.
- *
- * 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.
- */
-
-#define INCLUDES
-#include "compat_ioctl.c"
-#include <linux/syscalls.h>
-
-#define CODE
-#include "compat_ioctl.c"
-
-#define HANDLE_IOCTL(cmd,handler) { cmd, (ioctl_trans_handler_t)handler, NULL },
-#define COMPATIBLE_IOCTL(cmd) HANDLE_IOCTL(cmd,sys_ioctl)
-
-#define IOCTL_TABLE_START \
-	struct ioctl_trans ioctl_start[] = {
-#define IOCTL_TABLE_END \
-	};
-
-IOCTL_TABLE_START
-#include <linux/compat_ioctl.h>
-#define DECLARES
-#include "compat_ioctl.c"
-
-IOCTL_TABLE_END
-
-int ioctl_table_size = ARRAY_SIZE(ioctl_start);
diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c
index 5368f9c..cfab485 100644
--- a/arch/powerpc/kernel/kprobes.c
+++ b/arch/powerpc/kernel/kprobes.c
@@ -35,7 +35,6 @@
 #include <asm/kdebug.h>
 #include <asm/sstep.h>
 
-static DECLARE_MUTEX(kprobe_mutex);
 DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
 DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
 
@@ -54,19 +53,17 @@
 
 	/* insn must be on a special executable page on ppc64 */
 	if (!ret) {
-		down(&kprobe_mutex);
 		p->ainsn.insn = get_insn_slot();
-		up(&kprobe_mutex);
 		if (!p->ainsn.insn)
 			ret = -ENOMEM;
 	}
-	return ret;
-}
 
-void __kprobes arch_copy_kprobe(struct kprobe *p)
-{
-	memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
-	p->opcode = *p->addr;
+	if (!ret) {
+		memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
+		p->opcode = *p->addr;
+	}
+
+	return ret;
 }
 
 void __kprobes arch_arm_kprobe(struct kprobe *p)
@@ -182,6 +179,18 @@
 			kcb->kprobe_status = KPROBE_REENTER;
 			return 1;
 		} else {
+			if (*addr != BREAKPOINT_INSTRUCTION) {
+				/* If trap variant, then it belongs not to us */
+				kprobe_opcode_t cur_insn = *addr;
+				if (is_trap(cur_insn))
+		       			goto no_kprobe;
+				/* The breakpoint instruction was removed by
+				 * another cpu right after we hit, no further
+				 * handling of this interrupt is appropriate
+				 */
+				ret = 1;
+				goto no_kprobe;
+			}
 			p = __get_cpu_var(current_kprobe);
 			if (p->break_handler && p->break_handler(p, regs)) {
 				goto ss_probe;
diff --git a/arch/powerpc/kernel/machine_kexec.c b/arch/powerpc/kernel/machine_kexec.c
index a91e40c..a81ca1b 100644
--- a/arch/powerpc/kernel/machine_kexec.c
+++ b/arch/powerpc/kernel/machine_kexec.c
@@ -14,12 +14,6 @@
 #include <linux/threads.h>
 #include <asm/machdep.h>
 
-/*
- * Provide a dummy crash_notes definition until crash dump is implemented.
- * This prevents breakage of crash_notes attribute in kernel/ksysfs.c.
- */
-note_buf_t crash_notes[NR_CPUS];
-
 void machine_crash_shutdown(struct pt_regs *regs)
 {
 	if (ppc_md.machine_crash_shutdown)
diff --git a/arch/powerpc/kernel/pci_64.c b/arch/powerpc/kernel/pci_64.c
index fc60a77..c367520 100644
--- a/arch/powerpc/kernel/pci_64.c
+++ b/arch/powerpc/kernel/pci_64.c
@@ -53,6 +53,7 @@
 #ifdef CONFIG_PPC_MULTIPLATFORM
 static void fixup_resource(struct resource *res, struct pci_dev *dev);
 static void do_bus_setup(struct pci_bus *bus);
+static void phbs_remap_io(void);
 #endif
 
 /* pci_io_base -- the base address from which io bars are offsets.
@@ -251,6 +252,7 @@
 		kfree(phb);
 }
 
+#ifndef CONFIG_PPC_ISERIES
 void __devinit pcibios_claim_one_bus(struct pci_bus *b)
 {
 	struct pci_dev *dev;
@@ -271,8 +273,10 @@
 	list_for_each_entry(child_bus, &b->children, node)
 		pcibios_claim_one_bus(child_bus);
 }
+#ifdef CONFIG_HOTPLUG
+EXPORT_SYMBOL_GPL(pcibios_claim_one_bus);
+#endif
 
-#ifndef CONFIG_PPC_ISERIES
 static void __init pcibios_claim_of_setup(void)
 {
 	struct pci_bus *b;
@@ -381,7 +385,7 @@
 	dev->subsystem_vendor = get_int_prop(node, "subsystem-vendor-id", 0);
 	dev->subsystem_device = get_int_prop(node, "subsystem-id", 0);
 
-	dev->cfg_size = 256; /*pci_cfg_space_size(dev);*/
+	dev->cfg_size = pci_cfg_space_size(dev);
 
 	sprintf(pci_name(dev), "%04x:%02x:%02x.%d", pci_domain_nr(bus),
 		dev->bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn));
@@ -1215,7 +1219,7 @@
 }
 EXPORT_SYMBOL(remap_bus_range);
 
-void phbs_remap_io(void)
+static void phbs_remap_io(void)
 {
 	struct pci_controller *hose, *tmp;
 
diff --git a/arch/powerpc/kernel/ppc_ksyms.c b/arch/powerpc/kernel/ppc_ksyms.c
index b275814..16d9a90 100644
--- a/arch/powerpc/kernel/ppc_ksyms.c
+++ b/arch/powerpc/kernel/ppc_ksyms.c
@@ -244,7 +244,6 @@
 extern long mol_trampoline;
 EXPORT_SYMBOL(mol_trampoline); /* For MOL */
 EXPORT_SYMBOL(flush_hash_pages); /* For MOL */
-EXPORT_SYMBOL_GPL(__handle_mm_fault); /* For MOL */
 #ifdef CONFIG_SMP
 extern int mmu_hash_lock;
 EXPORT_SYMBOL(mmu_hash_lock); /* For MOL */
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 105d560..5770399 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -201,13 +201,13 @@
 }
 #endif /* CONFIG_SPE */
 
+#ifndef CONFIG_SMP
 /*
  * If we are doing lazy switching of CPU state (FP, altivec or SPE),
  * and the current task has some state, discard it.
  */
-static inline void discard_lazy_cpu_state(void)
+void discard_lazy_cpu_state(void)
 {
-#ifndef CONFIG_SMP
 	preempt_disable();
 	if (last_task_used_math == current)
 		last_task_used_math = NULL;
@@ -220,9 +220,10 @@
 		last_task_used_spe = NULL;
 #endif
 	preempt_enable();
-#endif /* CONFIG_SMP */
 }
+#endif /* CONFIG_SMP */
 
+#ifdef CONFIG_PPC_MERGE		/* XXX for now */
 int set_dabr(unsigned long dabr)
 {
 	if (ppc_md.set_dabr)
@@ -231,6 +232,7 @@
 	mtspr(SPRN_DABR, dabr);
 	return 0;
 }
+#endif
 
 #ifdef CONFIG_PPC64
 DEFINE_PER_CPU(struct cpu_usage, cpu_usage_array);
@@ -424,7 +426,7 @@
 	if (trap == 0x300 || trap == 0x600)
 		printk("DAR: "REG", DSISR: "REG"\n", regs->dar, regs->dsisr);
 	printk("TASK = %p[%d] '%s' THREAD: %p",
-	       current, current->pid, current->comm, current->thread_info);
+	       current, current->pid, current->comm, task_thread_info(current));
 
 #ifdef CONFIG_SMP
 	printk(" CPU: %d", smp_processor_id());
@@ -503,7 +505,7 @@
 {
 	struct pt_regs *childregs, *kregs;
 	extern void ret_from_fork(void);
-	unsigned long sp = (unsigned long)p->thread_info + THREAD_SIZE;
+	unsigned long sp = (unsigned long)task_stack_page(p) + THREAD_SIZE;
 
 	CHECK_FULL_REGS(regs);
 	/* Copy registers */
@@ -516,7 +518,7 @@
 #ifdef CONFIG_PPC32
 		childregs->gpr[2] = (unsigned long) p;
 #else
-		clear_ti_thread_flag(p->thread_info, TIF_32BIT);
+		clear_tsk_thread_flag(p, TIF_32BIT);
 #endif
 		p->thread.regs = NULL;	/* no user register state */
 	} else {
@@ -588,10 +590,8 @@
 	 * set.  Do it now.
 	 */
 	if (!current->thread.regs) {
-		unsigned long childregs = (unsigned long)current->thread_info +
-						THREAD_SIZE;
-		childregs -= sizeof(struct pt_regs);
-		current->thread.regs = (struct pt_regs *)childregs;
+		struct pt_regs *regs = task_stack_page(current) + THREAD_SIZE;
+		current->thread.regs = regs - 1;
 	}
 
 	memset(regs->gpr, 0, sizeof(regs->gpr));
@@ -767,7 +767,7 @@
 static int validate_sp(unsigned long sp, struct task_struct *p,
 		       unsigned long nbytes)
 {
-	unsigned long stack_page = (unsigned long)p->thread_info;
+	unsigned long stack_page = (unsigned long)task_stack_page(p);
 
 	if (sp >= stack_page + sizeof(struct thread_struct)
 	    && sp <= stack_page + THREAD_SIZE - nbytes)
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index 34ab0da..02e2115 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -1100,17 +1100,37 @@
 
 static void __init early_reserve_mem(void)
 {
-	unsigned long base, size;
-	unsigned long *reserve_map;
+	u64 base, size;
+	u64 *reserve_map;
 
-	reserve_map = (unsigned long *)(((unsigned long)initial_boot_params) +
+	reserve_map = (u64 *)(((unsigned long)initial_boot_params) +
 					initial_boot_params->off_mem_rsvmap);
+#ifdef CONFIG_PPC32
+	/* 
+	 * Handle the case where we might be booting from an old kexec
+	 * image that setup the mem_rsvmap as pairs of 32-bit values
+	 */
+	if (*reserve_map > 0xffffffffull) {
+		u32 base_32, size_32;
+		u32 *reserve_map_32 = (u32 *)reserve_map;
+
+		while (1) {
+			base_32 = *(reserve_map_32++);
+			size_32 = *(reserve_map_32++);
+			if (size_32 == 0)
+				break;
+			DBG("reserving: %lx -> %lx\n", base_32, size_32);
+			lmb_reserve(base_32, size_32);
+		}
+		return;
+	}
+#endif
 	while (1) {
 		base = *(reserve_map++);
 		size = *(reserve_map++);
 		if (size == 0)
 			break;
-		DBG("reserving: %lx -> %lx\n", base, size);
+		DBG("reserving: %llx -> %llx\n", base, size);
 		lmb_reserve(base, size);
 	}
 
diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index e381f2f..d963a12 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -137,8 +137,8 @@
 };
 
 struct mem_map_entry {
-	unsigned long	base;
-	unsigned long	size;
+	u64	base;
+	u64	size;
 };
 
 typedef u32 cell_t;
@@ -897,9 +897,9 @@
  * If problems seem to show up, it would be a good start to track
  * them down.
  */
-static void reserve_mem(unsigned long base, unsigned long size)
+static void reserve_mem(u64 base, u64 size)
 {
-	unsigned long top = base + size;
+	u64 top = base + size;
 	unsigned long cnt = RELOC(mem_reserve_cnt);
 
 	if (size == 0)
diff --git a/arch/powerpc/kernel/ptrace-common.h b/arch/powerpc/kernel/ptrace-common.h
index b1babb7..5ccbdbe 100644
--- a/arch/powerpc/kernel/ptrace-common.h
+++ b/arch/powerpc/kernel/ptrace-common.h
@@ -62,7 +62,7 @@
 	struct pt_regs *regs = task->thread.regs;
 	if (regs != NULL)
 		regs->msr |= MSR_SE;
-	set_ti_thread_flag(task->thread_info, TIF_SINGLESTEP);
+	set_tsk_thread_flag(task, TIF_SINGLESTEP);
 }
 
 static inline void clear_single_step(struct task_struct *task)
@@ -70,7 +70,7 @@
 	struct pt_regs *regs = task->thread.regs;
 	if (regs != NULL)
 		regs->msr &= ~MSR_SE;
-	clear_ti_thread_flag(task->thread_info, TIF_SINGLESTEP);
+	clear_tsk_thread_flag(task, TIF_SINGLESTEP);
 }
 
 #ifdef CONFIG_ALTIVEC
diff --git a/arch/powerpc/kernel/rtas.c b/arch/powerpc/kernel/rtas.c
index ae2e2a3..4b9cfe4 100644
--- a/arch/powerpc/kernel/rtas.c
+++ b/arch/powerpc/kernel/rtas.c
@@ -17,6 +17,7 @@
 #include <linux/spinlock.h>
 #include <linux/module.h>
 #include <linux/init.h>
+#include <linux/capability.h>
 #include <linux/delay.h>
 
 #include <asm/prom.h>
@@ -29,6 +30,7 @@
 #include <asm/delay.h>
 #include <asm/uaccess.h>
 #include <asm/lmb.h>
+#include <asm/udbg.h>
 
 struct rtas_t rtas = {
 	.lock = SPIN_LOCK_UNLOCKED
@@ -52,7 +54,7 @@
  * are designed only for very early low-level debugging, which
  * is why the token is hard-coded to 10.
  */
-void call_rtas_display_status(unsigned char c)
+static void call_rtas_display_status(char c)
 {
 	struct rtas_args *args = &rtas.args;
 	unsigned long s;
@@ -65,14 +67,14 @@
 	args->nargs = 1;
 	args->nret  = 1;
 	args->rets  = (rtas_arg_t *)&(args->args[1]);
-	args->args[0] = (int)c;
+	args->args[0] = (unsigned char)c;
 
 	enter_rtas(__pa(args));
 
 	spin_unlock_irqrestore(&rtas.lock, s);
 }
 
-void call_rtas_display_status_delay(unsigned char c)
+static void call_rtas_display_status_delay(char c)
 {
 	static int pending_newline = 0;  /* did last write end with unprinted newline? */
 	static int width = 16;
@@ -96,6 +98,11 @@
 	}
 }
 
+void __init udbg_init_rtas(void)
+{
+	udbg_putc = call_rtas_display_status_delay;
+}
+
 void rtas_progress(char *s, unsigned short hex)
 {
 	struct device_node *root;
diff --git a/arch/powerpc/kernel/rtas_pci.c b/arch/powerpc/kernel/rtas_pci.c
index 45b8109..5579f65 100644
--- a/arch/powerpc/kernel/rtas_pci.c
+++ b/arch/powerpc/kernel/rtas_pci.c
@@ -72,7 +72,7 @@
         return 0;
 }
 
-static int rtas_read_config(struct pci_dn *pdn, int where, int size, u32 *val)
+int rtas_read_config(struct pci_dn *pdn, int where, int size, u32 *val)
 {
 	int returnval = -1;
 	unsigned long buid, addr;
diff --git a/arch/powerpc/kernel/setup_32.c b/arch/powerpc/kernel/setup_32.c
index e5d285a..db72a92 100644
--- a/arch/powerpc/kernel/setup_32.c
+++ b/arch/powerpc/kernel/setup_32.c
@@ -299,9 +299,7 @@
 	if (ppc_md.init_early)
 		ppc_md.init_early();
 
-#ifdef CONFIG_SERIAL_8250
 	find_legacy_serial_ports();
-#endif
 	finish_device_tree();
 
 	smp_setup_cpu_maps();
diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index 81567e9..e29b275 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -33,6 +33,7 @@
 #include <linux/unistd.h>
 #include <linux/serial.h>
 #include <linux/serial_8250.h>
+#include <linux/bootmem.h>
 #include <asm/io.h>
 #include <asm/kdump.h>
 #include <asm/prom.h>
@@ -70,33 +71,6 @@
 #define DBG(fmt...)
 #endif
 
-/*
- * Here are some early debugging facilities. You can enable one
- * but your kernel will not boot on anything else if you do so
- */
-
-/* This one is for use on LPAR machines that support an HVC console
- * on vterm 0
- */
-extern void udbg_init_debug_lpar(void);
-/* This one is for use on Apple G5 machines
- */
-extern void udbg_init_pmac_realmode(void);
-/* That's RTAS panel debug */
-extern void call_rtas_display_status_delay(unsigned char c);
-/* Here's maple real mode debug */
-extern void udbg_init_maple_realmode(void);
-
-#define EARLY_DEBUG_INIT() do {} while(0)
-
-#if 0
-#define EARLY_DEBUG_INIT() udbg_init_debug_lpar()
-#define EARLY_DEBUG_INIT() udbg_init_maple_realmode()
-#define EARLY_DEBUG_INIT() udbg_init_pmac_realmode()
-#define EARLY_DEBUG_INIT()						\
-	do { udbg_putc = call_rtas_display_status_delay; } while(0)
-#endif
-
 int have_of = 1;
 int boot_cpuid = 0;
 int boot_cpuid_phys = 0;
@@ -237,11 +211,8 @@
 	struct paca_struct *lpaca = get_paca();
 	static struct machdep_calls **mach;
 
-	/*
-	 * Enable early debugging if any specified (see top of
-	 * this file)
-	 */
-	EARLY_DEBUG_INIT();
+	/* Enable early debugging if any specified (see udbg.h) */
+	udbg_early_init();
 
 	DBG(" -> early_setup()\n");
 
@@ -472,9 +443,7 @@
 	 * hash table management for us, thus ioremap works. We do that early
 	 * so that further code can be debugged
 	 */
-#ifdef CONFIG_SERIAL_8250
 	find_legacy_serial_ports();
-#endif
 
 	/*
 	 * "Finish" the device-tree, that is do the actual parsing of
@@ -686,3 +655,28 @@
 	if (ppc_md.cpu_die)
 		ppc_md.cpu_die();
 }
+
+#ifdef CONFIG_SMP
+void __init setup_per_cpu_areas(void)
+{
+	int i;
+	unsigned long size;
+	char *ptr;
+
+	/* Copy section for each CPU (we discard the original) */
+	size = ALIGN(__per_cpu_end - __per_cpu_start, SMP_CACHE_BYTES);
+#ifdef CONFIG_MODULES
+	if (size < PERCPU_ENOUGH_ROOM)
+		size = PERCPU_ENOUGH_ROOM;
+#endif
+
+	for_each_cpu(i) {
+		ptr = alloc_bootmem_node(NODE_DATA(cpu_to_node(i)), size);
+		if (!ptr)
+			panic("Cannot allocate cpu data for CPU %d\n", i);
+
+		paca[i].data_offset = ptr - __per_cpu_start;
+		memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
+	}
+}
+#endif
diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
index d3f0b6d..177bba7 100644
--- a/arch/powerpc/kernel/signal_32.c
+++ b/arch/powerpc/kernel/signal_32.c
@@ -497,6 +497,15 @@
 	if (err)
 		return 1;
 
+	/*
+	 * Do this before updating the thread state in
+	 * current->thread.fpr/vr/evr.  That way, if we get preempted
+	 * and another task grabs the FPU/Altivec/SPE, it won't be
+	 * tempted to save the current CPU state into the thread_struct
+	 * and corrupt what we are writing there.
+	 */
+	discard_lazy_cpu_state();
+
 	/* force the process to reload the FP registers from
 	   current->thread when it next does FP instructions */
 	regs->msr &= ~(MSR_FP | MSR_FE0 | MSR_FE1);
@@ -538,18 +547,6 @@
 		return 1;
 #endif /* CONFIG_SPE */
 
-#ifndef CONFIG_SMP
-	preempt_disable();
-	if (last_task_used_math == current)
-		last_task_used_math = NULL;
-	if (last_task_used_altivec == current)
-		last_task_used_altivec = NULL;
-#ifdef CONFIG_SPE
-	if (last_task_used_spe == current)
-		last_task_used_spe = NULL;
-#endif
-	preempt_enable();
-#endif
 	return 0;
 }
 
diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
index 5462bef..7b9d999 100644
--- a/arch/powerpc/kernel/signal_64.c
+++ b/arch/powerpc/kernel/signal_64.c
@@ -207,10 +207,20 @@
 
 	if (!sig)
 		regs->gpr[13] = save_r13;
-	err |= __copy_from_user(&current->thread.fpr, &sc->fp_regs, FP_REGS_SIZE);
 	if (set != NULL)
 		err |=  __get_user(set->sig[0], &sc->oldmask);
 
+	/*
+	 * Do this before updating the thread state in
+	 * current->thread.fpr/vr.  That way, if we get preempted
+	 * and another task grabs the FPU/Altivec, it won't be
+	 * tempted to save the current CPU state into the thread_struct
+	 * and corrupt what we are writing there.
+	 */
+	discard_lazy_cpu_state();
+
+	err |= __copy_from_user(&current->thread.fpr, &sc->fp_regs, FP_REGS_SIZE);
+
 #ifdef CONFIG_ALTIVEC
 	err |= __get_user(v_regs, &sc->v_regs);
 	err |= __get_user(msr, &sc->gp_regs[PT_MSR]);
@@ -229,14 +239,6 @@
 		current->thread.vrsave = 0;
 #endif /* CONFIG_ALTIVEC */
 
-#ifndef CONFIG_SMP
-	preempt_disable();
-	if (last_task_used_math == current)
-		last_task_used_math = NULL;
-	if (last_task_used_altivec == current)
-		last_task_used_altivec = NULL;
-	preempt_enable();
-#endif
 	/* Force reload of FP/VEC */
 	regs->msr &= ~(MSR_FP | MSR_FE0 | MSR_FE1 | MSR_VEC);
 
diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index d381ec9..c8458c5 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -338,8 +338,8 @@
 #ifdef CONFIG_PPC64
 	paca[cpu].__current = p;
 #endif
-	current_set[cpu] = p->thread_info;
-	p->thread_info->cpu = cpu;
+	current_set[cpu] = task_thread_info(p);
+	task_thread_info(p)->cpu = cpu;
 }
 
 void __init smp_prepare_cpus(unsigned int max_cpus)
@@ -375,7 +375,7 @@
 #ifdef CONFIG_PPC64
 	paca[boot_cpuid].__current = current;
 #endif
-	current_set[boot_cpuid] = current->thread_info;
+	current_set[boot_cpuid] = task_thread_info(current);
 }
 
 #ifdef CONFIG_HOTPLUG_CPU
diff --git a/arch/powerpc/kernel/sys_ppc32.c b/arch/powerpc/kernel/sys_ppc32.c
index 9c921d1..475249d 100644
--- a/arch/powerpc/kernel/sys_ppc32.c
+++ b/arch/powerpc/kernel/sys_ppc32.c
@@ -552,30 +552,6 @@
 	return ret;
 }
 
-asmlinkage int compat_sys_pciconfig_read(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf)
-{
-	return sys_pciconfig_read((unsigned long) bus,
-				  (unsigned long) dfn,
-				  (unsigned long) off,
-				  (unsigned long) len,
-				  compat_ptr(ubuf));
-}
-
-asmlinkage int compat_sys_pciconfig_write(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf)
-{
-	return sys_pciconfig_write((unsigned long) bus,
-				   (unsigned long) dfn,
-				   (unsigned long) off,
-				   (unsigned long) len,
-				   compat_ptr(ubuf));
-}
-
-asmlinkage int compat_sys_pciconfig_iobase(u32 which, u32 in_bus, u32 in_devfn)
-{
-	return sys_pciconfig_iobase(which, in_bus, in_devfn);
-}
-
-
 /* Note: it is necessary to treat mode as an unsigned int,
  * with the corresponding cast to a signed int to insure that the 
  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
@@ -956,38 +932,6 @@
 			     advice);
 }
 
-long ppc32_timer_create(clockid_t clock,
-			struct compat_sigevent __user *ev32,
-			timer_t __user *timer_id)
-{
-	sigevent_t event;
-	timer_t t;
-	long err;
-	mm_segment_t savefs;
-
-	if (ev32 == NULL)
-		return sys_timer_create(clock, NULL, timer_id);
-
-	if (get_compat_sigevent(&event, ev32))
-		return -EFAULT;
-
-	if (!access_ok(VERIFY_WRITE, timer_id, sizeof(timer_t)))
-		return -EFAULT;
-
-	savefs = get_fs();
-	set_fs(KERNEL_DS);
-	/* The __user pointer casts are valid due to the set_fs() */
-	err = sys_timer_create(clock,
-		(sigevent_t __user *) &event,
-		(timer_t __user *) &t);
-	set_fs(savefs);
-
-	if (err == 0)
-		err = __put_user(t, timer_id);
-
-	return err;
-}
-
 asmlinkage long compat_sys_add_key(const char __user *_type,
 			      const char __user *_description,
 			      const void __user *_payload,
diff --git a/arch/powerpc/kernel/systbl.S b/arch/powerpc/kernel/systbl.S
index 65463a1..6801317 100644
--- a/arch/powerpc/kernel/systbl.S
+++ b/arch/powerpc/kernel/systbl.S
@@ -239,9 +239,9 @@
 SYSX(sys_ni_syscall,sys_stat64,sys_stat64)
 SYSX(sys_ni_syscall,sys_lstat64,sys_lstat64)
 SYSX(sys_ni_syscall,sys_fstat64,sys_fstat64)
-COMPAT_SYS(pciconfig_read)
-COMPAT_SYS(pciconfig_write)
-COMPAT_SYS(pciconfig_iobase)
+SYSCALL(pciconfig_read)
+SYSCALL(pciconfig_write)
+SYSCALL(pciconfig_iobase)
 SYSCALL(ni_syscall)
 SYSCALL(getdents64)
 SYSCALL(pivot_root)
@@ -281,7 +281,7 @@
 SYSCALL(epoll_ctl)
 SYSCALL(epoll_wait)
 SYSCALL(remap_file_pages)
-SYSX(sys_timer_create,ppc32_timer_create,sys_timer_create)
+SYSX(sys_timer_create,compat_sys_timer_create,sys_timer_create)
 COMPAT_SYS(timer_settime)
 COMPAT_SYS(timer_gettime)
 SYSCALL(timer_getoverrun)
diff --git a/arch/powerpc/kernel/udbg.c b/arch/powerpc/kernel/udbg.c
index 558c1ce..3774e80 100644
--- a/arch/powerpc/kernel/udbg.c
+++ b/arch/powerpc/kernel/udbg.c
@@ -15,11 +15,36 @@
 #include <linux/sched.h>
 #include <linux/console.h>
 #include <asm/processor.h>
+#include <asm/udbg.h>
 
 void (*udbg_putc)(char c);
 int (*udbg_getc)(void);
 int (*udbg_getc_poll)(void);
 
+/*
+ * Early debugging facilities. You can enable _one_ of these via .config,
+ * if you do so your kernel _will not boot_ on anything else. Be careful.
+ */
+void __init udbg_early_init(void)
+{
+#if defined(CONFIG_PPC_EARLY_DEBUG_LPAR)
+	/* For LPAR machines that have an HVC console on vterm 0 */
+	udbg_init_debug_lpar();
+#elif defined(CONFIG_PPC_EARLY_DEBUG_G5)
+	/* For use on Apple G5 machines */
+	udbg_init_pmac_realmode();
+#elif defined(CONFIG_PPC_EARLY_DEBUG_RTAS)
+	/* RTAS panel debug */
+	udbg_init_rtas();
+#elif defined(CONFIG_PPC_EARLY_DEBUG_MAPLE)
+	/* Maple real mode debug */
+	udbg_init_maple_realmode();
+#elif defined(CONFIG_PPC_EARLY_DEBUG_ISERIES)
+	/* For iSeries - hit Ctrl-x Ctrl-x to see the output */
+	udbg_init_iseries();
+#endif
+}
+
 /* udbg library, used by xmon et al */
 void udbg_puts(const char *s)
 {
diff --git a/arch/powerpc/kernel/udbg_16550.c b/arch/powerpc/kernel/udbg_16550.c
index 7541bf4..2da65a9 100644
--- a/arch/powerpc/kernel/udbg_16550.c
+++ b/arch/powerpc/kernel/udbg_16550.c
@@ -155,7 +155,7 @@
 	}
 }
 
-void udbg_init_maple_realmode(void)
+void __init udbg_init_maple_realmode(void)
 {
 	udbg_comport = (volatile struct NS16550 __iomem *)0xf40003f8;
 
diff --git a/arch/powerpc/kernel/vdso32/.gitignore b/arch/powerpc/kernel/vdso32/.gitignore
new file mode 100644
index 0000000..e45fba9
--- /dev/null
+++ b/arch/powerpc/kernel/vdso32/.gitignore
@@ -0,0 +1 @@
+vdso32.lds
diff --git a/arch/powerpc/kernel/vdso64/.gitignore b/arch/powerpc/kernel/vdso64/.gitignore
new file mode 100644
index 0000000..3fd18cf
--- /dev/null
+++ b/arch/powerpc/kernel/vdso64/.gitignore
@@ -0,0 +1 @@
+vdso64.lds
diff --git a/arch/powerpc/mm/pgtable_64.c b/arch/powerpc/mm/pgtable_64.c
index 2ffca63..7b278d83 100644
--- a/arch/powerpc/mm/pgtable_64.c
+++ b/arch/powerpc/mm/pgtable_64.c
@@ -174,7 +174,7 @@
 	pa = addr & PAGE_MASK;
 	size = PAGE_ALIGN(addr + size) - pa;
 
-	if (size == 0)
+	if ((size == 0) || (pa == 0))
 		return NULL;
 
 	if (mem_init_done) {
diff --git a/arch/powerpc/platforms/83xx/Kconfig b/arch/powerpc/platforms/83xx/Kconfig
new file mode 100644
index 0000000..b20812d
--- /dev/null
+++ b/arch/powerpc/platforms/83xx/Kconfig
@@ -0,0 +1,26 @@
+menu "Platform support"
+	depends on PPC_83xx
+
+choice
+	prompt "Machine Type"
+	default MPC834x_SYS
+
+config MPC834x_SYS
+	bool "Freescale MPC834x SYS"
+	help
+	  This option enables support for the MPC 834x SYS evaluation board.
+
+	  Be aware that PCI buses can only function when SYS board is plugged
+	  into the PIB (Platform IO Board) board from Freescale which provide
+	  3 PCI slots.  The PIBs PCI initialization is the bootloader's
+	  responsiblilty.
+
+endchoice
+
+config MPC834x
+	bool
+	select PPC_UDBG_16550
+	select PPC_INDIRECT_PCI
+	default y if MPC834x_SYS
+
+endmenu
diff --git a/arch/powerpc/platforms/83xx/Makefile b/arch/powerpc/platforms/83xx/Makefile
new file mode 100644
index 0000000..9d8b28ef
--- /dev/null
+++ b/arch/powerpc/platforms/83xx/Makefile
@@ -0,0 +1,4 @@
+#
+# Makefile for the PowerPC 83xx linux kernel.
+#
+obj-$(CONFIG_MPC834x_SYS)	+= mpc834x_sys.o pci.o
diff --git a/arch/powerpc/platforms/Makefile b/arch/powerpc/platforms/Makefile
index 8836b3a..04073fd 100644
--- a/arch/powerpc/platforms/Makefile
+++ b/arch/powerpc/platforms/Makefile
@@ -7,6 +7,7 @@
 endif
 obj-$(CONFIG_PPC_CHRP)		+= chrp/
 obj-$(CONFIG_4xx)		+= 4xx/
+obj-$(CONFIG_PPC_83xx)		+= 83xx/
 obj-$(CONFIG_85xx)		+= 85xx/
 obj-$(CONFIG_PPC_PSERIES)	+= pseries/
 obj-$(CONFIG_PPC_ISERIES)	+= iseries/
diff --git a/arch/powerpc/platforms/cell/pervasive.c b/arch/powerpc/platforms/cell/pervasive.c
index 85152544..e0e051c 100644
--- a/arch/powerpc/platforms/cell/pervasive.c
+++ b/arch/powerpc/platforms/cell/pervasive.c
@@ -142,7 +142,7 @@
 	}
 }
 
-int cbe_system_reset_exception(struct pt_regs *regs)
+static int cbe_system_reset_exception(struct pt_regs *regs)
 {
 	switch (regs->msr & SRR1_WAKEMASK) {
 	case SRR1_WAKEEE:
diff --git a/arch/powerpc/platforms/cell/setup.c b/arch/powerpc/platforms/cell/setup.c
index 18e25e6..b33a444 100644
--- a/arch/powerpc/platforms/cell/setup.c
+++ b/arch/powerpc/platforms/cell/setup.c
@@ -57,7 +57,7 @@
 #define DBG(fmt...)
 #endif
 
-void cell_show_cpuinfo(struct seq_file *m)
+static void cell_show_cpuinfo(struct seq_file *m)
 {
 	struct device_node *root;
 	const char *model = "";
diff --git a/arch/powerpc/platforms/cell/smp.c b/arch/powerpc/platforms/cell/smp.c
index de96ead..bdf6c5f 100644
--- a/arch/powerpc/platforms/cell/smp.c
+++ b/arch/powerpc/platforms/cell/smp.c
@@ -86,7 +86,7 @@
 	pcpu = get_hard_smp_processor_id(lcpu);
 
 	/* Fixup atomic count: it exited inside IRQ handler. */
-	paca[lcpu].__current->thread_info->preempt_count	= 0;
+	task_thread_info(paca[lcpu].__current)->preempt_count	= 0;
 
 	/*
 	 * If the RTAS start-cpu token does not exist then presume the
diff --git a/arch/powerpc/platforms/cell/spufs/inode.c b/arch/powerpc/platforms/cell/spufs/inode.c
index d2ba358..b3962c3a 100644
--- a/arch/powerpc/platforms/cell/spufs/inode.c
+++ b/arch/powerpc/platforms/cell/spufs/inode.c
@@ -138,7 +138,7 @@
 {
 	struct dentry *dentry, *tmp;
 	mutex_lock(&dir->d_inode->i_mutex);
-	list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_child) {
+	list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_u.d_child) {
 		spin_lock(&dcache_lock);
 		spin_lock(&dentry->d_lock);
 		if (!(d_unhashed(dentry)) && dentry->d_inode) {
diff --git a/arch/powerpc/platforms/cell/spufs/switch.c b/arch/powerpc/platforms/cell/spufs/switch.c
index 1061c12..212db28 100644
--- a/arch/powerpc/platforms/cell/spufs/switch.c
+++ b/arch/powerpc/platforms/cell/spufs/switch.c
@@ -169,11 +169,33 @@
 	struct spu_priv2 __iomem *priv2 = spu->priv2;
 
 	/* Save, Step 8:
-	 *     Read and save MFC_CNTL[Ss].
+	 *     Suspend DMA and save MFC_CNTL.
 	 */
-	if (csa) {
-		csa->priv2.mfc_control_RW = in_be64(&priv2->mfc_control_RW) &
-		    MFC_CNTL_SUSPEND_DMA_STATUS_MASK;
+	switch (in_be64(&priv2->mfc_control_RW) &
+	       MFC_CNTL_SUSPEND_DMA_STATUS_MASK) {
+	case MFC_CNTL_SUSPEND_IN_PROGRESS:
+		POLL_WHILE_FALSE((in_be64(&priv2->mfc_control_RW) &
+				  MFC_CNTL_SUSPEND_DMA_STATUS_MASK) ==
+				 MFC_CNTL_SUSPEND_COMPLETE);
+		/* fall through */
+	case MFC_CNTL_SUSPEND_COMPLETE:
+		if (csa) {
+			csa->priv2.mfc_control_RW =
+				in_be64(&priv2->mfc_control_RW) |
+				MFC_CNTL_SUSPEND_DMA_QUEUE;
+		}
+		break;
+	case MFC_CNTL_NORMAL_DMA_QUEUE_OPERATION:
+		out_be64(&priv2->mfc_control_RW, MFC_CNTL_SUSPEND_DMA_QUEUE);
+		POLL_WHILE_FALSE((in_be64(&priv2->mfc_control_RW) &
+				  MFC_CNTL_SUSPEND_DMA_STATUS_MASK) ==
+				 MFC_CNTL_SUSPEND_COMPLETE);
+		if (csa) {
+			csa->priv2.mfc_control_RW =
+				in_be64(&priv2->mfc_control_RW) &
+				~MFC_CNTL_SUSPEND_DMA_QUEUE;
+		}
+		break;
 	}
 }
 
@@ -237,6 +259,8 @@
 		eieio();
 		csa->spu_chnldata_RW[7] = in_be64(&priv2->spu_chnldata_RW);
 		eieio();
+	} else {
+		csa->priv2.mfc_control_RW &= ~MFC_CNTL_DECREMENTER_RUNNING;
 	}
 }
 
diff --git a/arch/powerpc/platforms/cell/spufs/syscalls.c b/arch/powerpc/platforms/cell/spufs/syscalls.c
index d549aa7..e6565a9 100644
--- a/arch/powerpc/platforms/cell/spufs/syscalls.c
+++ b/arch/powerpc/platforms/cell/spufs/syscalls.c
@@ -29,7 +29,9 @@
  * value of the spu_status register after the SPU has stopped.
  *
  */
-long do_spu_run(struct file *filp, __u32 __user *unpc, __u32 __user *ustatus)
+static long do_spu_run(struct file *filp,
+			__u32 __user *unpc,
+			__u32 __user *ustatus)
 {
 	long ret;
 	struct spufs_inode_info *i;
diff --git a/arch/powerpc/platforms/embedded6xx/Kconfig b/arch/powerpc/platforms/embedded6xx/Kconfig
index 81250090..4fdbc9a 100644
--- a/arch/powerpc/platforms/embedded6xx/Kconfig
+++ b/arch/powerpc/platforms/embedded6xx/Kconfig
@@ -144,16 +144,6 @@
 	  much but it's only been tested on this board version. I think this
 	  board is also known as IceCube.
 
-config MPC834x_SYS
-	bool "Freescale MPC834x SYS"
-	help
-	  This option enables support for the MPC 834x SYS evaluation board.
-
-	  Be aware that PCI buses can only function when SYS board is plugged
-	  into the PIB (Platform IO Board) board from Freescale which provide
-	  3 PCI slots.  The PIBs PCI initialization is the bootloader's
-	  responsiblilty.
-
 config EV64360
 	bool "Marvell-EV64360BP"
 	help
@@ -192,14 +182,6 @@
 	  The MPC8272 CPM has a different internal dpram setup than other CPM2
 	  devices
 
-config 83xx
-	bool
-	default y if MPC834x_SYS
-
-config MPC834x
-	bool
-	default y if MPC834x_SYS
-
 config CPM2
 	bool
 	depends on 8260 || MPC8560 || MPC8555
diff --git a/arch/powerpc/platforms/iseries/Makefile b/arch/powerpc/platforms/iseries/Makefile
index 127b465..ce8c0b9 100644
--- a/arch/powerpc/platforms/iseries/Makefile
+++ b/arch/powerpc/platforms/iseries/Makefile
@@ -1,8 +1,8 @@
 EXTRA_CFLAGS	+= -mno-minimal-toc
 
 obj-y += hvlog.o hvlpconfig.o lpardata.o setup.o mf.o lpevents.o \
-	hvcall.o proc.o htab.o iommu.o misc.o
-obj-$(CONFIG_PCI) += pci.o irq.o vpdinfo.o
+	hvcall.o proc.o htab.o iommu.o misc.o irq.o
+obj-$(CONFIG_PCI) += pci.o vpdinfo.o
 obj-$(CONFIG_IBMVIO) += vio.o
 obj-$(CONFIG_SMP) += smp.o
 obj-$(CONFIG_VIOPATH) += viopath.o
diff --git a/arch/powerpc/platforms/iseries/iommu.c b/arch/powerpc/platforms/iseries/iommu.c
index 2b54eeb..bea0b70 100644
--- a/arch/powerpc/platforms/iseries/iommu.c
+++ b/arch/powerpc/platforms/iseries/iommu.c
@@ -34,6 +34,8 @@
 #include <asm/pci-bridge.h>
 #include <asm/iseries/hv_call_xm.h>
 
+#include "iommu.h"
+
 extern struct list_head iSeries_Global_Device_List;
 
 
diff --git a/arch/powerpc/platforms/iseries/iommu.h b/arch/powerpc/platforms/iseries/iommu.h
new file mode 100644
index 0000000..cb5658f
--- /dev/null
+++ b/arch/powerpc/platforms/iseries/iommu.h
@@ -0,0 +1,35 @@
+#ifndef _PLATFORMS_ISERIES_IOMMU_H
+#define _PLATFORMS_ISERIES_IOMMU_H
+
+/*
+ * Copyright (C) 2005  Stephen Rothwell, IBM Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the:
+ * Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330,
+ * Boston, MA  02111-1307  USA
+ */
+
+struct device_node;
+struct iommu_table;
+
+/* Creates table for an individual device node */
+extern void iommu_devnode_init_iSeries(struct device_node *dn);
+
+/* Get table parameters from HV */
+extern void iommu_table_getparms_iSeries(unsigned long busno,
+		unsigned char slotno, unsigned char virtbus,
+		struct iommu_table *tbl);
+
+#endif /* _PLATFORMS_ISERIES_IOMMU_H */
diff --git a/arch/powerpc/platforms/iseries/irq.c b/arch/powerpc/platforms/iseries/irq.c
index 42e978e..83442ea 100644
--- a/arch/powerpc/platforms/iseries/irq.c
+++ b/arch/powerpc/platforms/iseries/irq.c
@@ -48,6 +48,8 @@
 extern void iSeries_smp_message_recv(struct pt_regs *);
 #endif
 
+#ifdef CONFIG_PCI
+
 enum pci_event_type {
 	pe_bus_created		= 0,	/* PHB has been created */
 	pe_bus_error		= 1,	/* PHB has failed */
@@ -147,20 +149,11 @@
 static void pci_event_handler(struct HvLpEvent *event, struct pt_regs *regs)
 {
 	if (event && (event->xType == HvLpEvent_Type_PciIo)) {
-		switch (event->xFlags.xFunction) {
-		case HvLpEvent_Function_Int:
+		if (hvlpevent_is_int(event))
 			int_received((struct pci_event *)event, regs);
-			break;
-		case HvLpEvent_Function_Ack:
+		else
 			printk(KERN_ERR
 				"pci_event_handler: unexpected ack received\n");
-			break;
-		default:
-			printk(KERN_ERR
-				"pci_event_handler: unexpected event function %d\n",
-				(int)event->xFlags.xFunction);
-			break;
-		}
 	} else if (event)
 		printk(KERN_ERR
 			"pci_event_handler: Unrecognized PCI event type 0x%x\n",
@@ -334,6 +327,8 @@
 	return virtirq;
 }
 
+#endif /* CONFIG_PCI */
+
 /*
  * Get the next pending IRQ.
  */
@@ -353,6 +348,7 @@
 	if (hvlpevent_is_pending())
 		process_hvlpevents(regs);
 
+#ifdef CONFIG_PCI
 	if (num_pending_irqs) {
 		spin_lock(&pending_irqs_lock);
 		for (irq = 0; irq < NR_IRQS; irq++) {
@@ -366,6 +362,7 @@
 		if (irq >= NR_IRQS)
 			irq = -2;
 	}
+#endif
 
 	return irq;
 }
diff --git a/arch/powerpc/platforms/iseries/lpardata.c b/arch/powerpc/platforms/iseries/lpardata.c
index ea72385..438e2db 100644
--- a/arch/powerpc/platforms/iseries/lpardata.c
+++ b/arch/powerpc/platforms/iseries/lpardata.c
@@ -93,10 +93,7 @@
 	.xPirEnvironMode = 0,		/* Piranha stuff */
 	.xPirConsoleMode = 0,
 	.xPirDasdMode = 0,
-	.xLparInstalled = 0,
-	.xSysPartitioned = 0,
-	.xHwSyncedTBs = 0,
-	.xIntProcUtilHmt = 0,
+	.flags = 0,
 	.xSpVpdFormat = 0,
 	.xIntProcRatio = 0,
 	.xPlicVrmIndex = 0,		/* VRM index of PLIC */
diff --git a/arch/powerpc/platforms/iseries/lpevents.c b/arch/powerpc/platforms/iseries/lpevents.c
index e9fb98b..0b88530 100644
--- a/arch/powerpc/platforms/iseries/lpevents.c
+++ b/arch/powerpc/platforms/iseries/lpevents.c
@@ -53,7 +53,7 @@
 	struct HvLpEvent * event;
 	event = (struct HvLpEvent *)hvlpevent_queue.xSlicCurEventPtr;
 
-	if (event->xFlags.xValid) {
+	if (hvlpevent_is_valid(event)) {
 		/* rmb() needed only for weakly consistent machines (regatta) */
 		rmb();
 		/* Set pointer to next potential event */
@@ -84,7 +84,7 @@
 
 	next_event = (struct HvLpEvent *)hvlpevent_queue.xSlicCurEventPtr;
 
-	return next_event->xFlags.xValid |
+	return hvlpevent_is_valid(next_event) ||
 		hvlpevent_queue.xPlicOverflowIntPending;
 }
 
@@ -101,18 +101,18 @@
 	switch (extra) {
 	case 3:
 		tmp = (struct HvLpEvent*)((char*)event + 3 * LpEventAlign);
-		tmp->xFlags.xValid = 0;
+		hvlpevent_invalidate(tmp);
 	case 2:
 		tmp = (struct HvLpEvent*)((char*)event + 2 * LpEventAlign);
-		tmp->xFlags.xValid = 0;
+		hvlpevent_invalidate(tmp);
 	case 1:
 		tmp = (struct HvLpEvent*)((char*)event + 1 * LpEventAlign);
-		tmp->xFlags.xValid = 0;
+		hvlpevent_invalidate(tmp);
 	}
 
 	mb();
 
-	event->xFlags.xValid = 0;
+	hvlpevent_invalidate(event);
 }
 
 void process_hvlpevents(struct pt_regs *regs)
diff --git a/arch/powerpc/platforms/iseries/mf.c b/arch/powerpc/platforms/iseries/mf.c
index 49e7e4b..a41d8b7 100644
--- a/arch/powerpc/platforms/iseries/mf.c
+++ b/arch/powerpc/platforms/iseries/mf.c
@@ -251,10 +251,7 @@
 	}
 	memset(ev, 0, sizeof(struct pending_event));
 	hev = &ev->event.hp_lp_event;
-	hev->xFlags.xValid = 1;
-	hev->xFlags.xAckType = HvLpEvent_AckType_ImmediateAck;
-	hev->xFlags.xAckInd = HvLpEvent_AckInd_DoAck;
-	hev->xFlags.xFunction = HvLpEvent_Function_Int;
+	hev->flags = HV_LP_EVENT_VALID | HV_LP_EVENT_DO_ACK | HV_LP_EVENT_INT;
 	hev->xType = HvLpEvent_Type_MachineFac;
 	hev->xSourceLp = HvLpConfig_getLpIndex();
 	hev->xTargetLp = primary_lp;
@@ -518,17 +515,10 @@
 static void hv_handler(struct HvLpEvent *event, struct pt_regs *regs)
 {
 	if ((event != NULL) && (event->xType == HvLpEvent_Type_MachineFac)) {
-		switch(event->xFlags.xFunction) {
-		case HvLpEvent_Function_Ack:
+		if (hvlpevent_is_ack(event))
 			handle_ack((struct io_mf_lp_event *)event);
-			break;
-		case HvLpEvent_Function_Int:
+		else
 			handle_int((struct io_mf_lp_event *)event);
-			break;
-		default:
-			printk(KERN_ERR "mf.c: non ack/int event received\n");
-			break;
-		}
 	} else
 		printk(KERN_ERR "mf.c: alien event received\n");
 }
diff --git a/arch/powerpc/platforms/iseries/pci.c b/arch/powerpc/platforms/iseries/pci.c
index dafc518..a19833b 100644
--- a/arch/powerpc/platforms/iseries/pci.c
+++ b/arch/powerpc/platforms/iseries/pci.c
@@ -43,6 +43,7 @@
 #include "irq.h"
 #include "pci.h"
 #include "call_pci.h"
+#include "iommu.h"
 
 extern unsigned long io_page_mask;
 
diff --git a/arch/powerpc/platforms/iseries/setup.c b/arch/powerpc/platforms/iseries/setup.c
index ad5ef805..c6bbe5c 100644
--- a/arch/powerpc/platforms/iseries/setup.c
+++ b/arch/powerpc/platforms/iseries/setup.c
@@ -52,6 +52,7 @@
 #include <asm/iseries/mf.h>
 #include <asm/iseries/hv_lp_event.h>
 #include <asm/iseries/lpar_map.h>
+#include <asm/udbg.h>
 
 #include "naca.h"
 #include "setup.h"
@@ -62,10 +63,8 @@
 #include "call_sm.h"
 #include "call_hpt.h"
 
-extern void hvlog(char *fmt, ...);
-
 #ifdef DEBUG
-#define DBG(fmt...) hvlog(fmt)
+#define DBG(fmt...) udbg_printf(fmt)
 #else
 #define DBG(fmt...)
 #endif
@@ -474,14 +473,6 @@
 	printk("HPT absolute addr = %016lx, size = %dK\n",
 			chunk_to_addr(hptFirstChunk), hptSizeChunks * 256);
 
-	ppc64_pft_size = __ilog2(hptSizePages * HW_PAGE_SIZE);
-
-	/*
-	 * The actual hashed page table is in the hypervisor,
-	 * we have no direct access
-	 */
-	htab_address = NULL;
-
 	/*
 	 * Determine if absolute memory has any
 	 * holes so that we can interpret the
@@ -861,6 +852,11 @@
 	dt_prop(dt, name, (char *)data, sizeof(u64) * n);
 }
 
+void dt_prop_u32_list(struct iseries_flat_dt *dt, char *name, u32 *data, int n)
+{
+	dt_prop(dt, name, (char *)data, sizeof(u32) * n);
+}
+
 void dt_prop_empty(struct iseries_flat_dt *dt, char *name)
 {
 	dt_prop(dt, name, NULL, 0);
@@ -872,6 +868,7 @@
 	unsigned char *p;
 	unsigned int i, index;
 	struct IoHriProcessorVpd *d;
+	u32 pft_size[2];
 
 	/* yuck */
 	snprintf(buf, 32, "PowerPC,%s", cur_cpu_spec->cpu_name);
@@ -882,6 +879,9 @@
 	dt_prop_u32(dt, "#address-cells", 1);
 	dt_prop_u32(dt, "#size-cells", 0);
 
+	pft_size[0] = 0; /* NUMA CEC cookie, 0 for non NUMA  */
+	pft_size[1] = __ilog2(HvCallHpt_getHptPages() * HW_PAGE_SIZE);
+
 	for (i = 0; i < NR_CPUS; i++) {
 		if (paca[i].lppaca.dyn_proc_status >= 2)
 			continue;
@@ -908,6 +908,8 @@
 
 		dt_prop_u32(dt, "reg", i);
 
+		dt_prop_u32_list(dt, "ibm,pft-size", pft_size, 2);
+
 		dt_end_node(dt);
 	}
 
@@ -984,3 +986,16 @@
 	return 0;
 }
 early_param("mem", early_parsemem);
+
+static void hvputc(char c)
+{
+	if (c == '\n')
+		hvputc('\r');
+
+	HvCall_writeLogBuffer(&c, 1);
+}
+
+void __init udbg_init_iseries(void)
+{
+	udbg_putc = hvputc;
+}
diff --git a/arch/powerpc/platforms/iseries/vio.c b/arch/powerpc/platforms/iseries/vio.c
index 384360e..ad36ab0 100644
--- a/arch/powerpc/platforms/iseries/vio.c
+++ b/arch/powerpc/platforms/iseries/vio.c
@@ -22,6 +22,8 @@
 #include <asm/iseries/hv_lp_config.h>
 #include <asm/iseries/hv_call_xm.h>
 
+#include "iommu.h"
+
 struct device *iSeries_vio_dev = &vio_bus_device.dev;
 EXPORT_SYMBOL(iSeries_vio_dev);
 
diff --git a/arch/powerpc/platforms/iseries/viopath.c b/arch/powerpc/platforms/iseries/viopath.c
index 84267269..622a301 100644
--- a/arch/powerpc/platforms/iseries/viopath.c
+++ b/arch/powerpc/platforms/iseries/viopath.c
@@ -270,7 +270,7 @@
 	 * First see if this is just a normal monitor message from the
 	 * other partition
 	 */
-	if (event->xFlags.xFunction == HvLpEvent_Function_Int) {
+	if (hvlpevent_is_int(event)) {
 		remoteLp = event->xSourceLp;
 		if (!viopathStatus[remoteLp].isActive)
 			sendMonMsg(remoteLp);
@@ -331,13 +331,12 @@
 {
 	if (!event)
 		return;
-	if (event->xFlags.xFunction == HvLpEvent_Function_Int) {
+	if (hvlpevent_is_int(event)) {
 		printk(VIOPATH_KERN_WARN
 		       "unexpected config request from partition %d",
 		       event->xSourceLp);
 
-		if ((event->xFlags.xFunction == HvLpEvent_Function_Int) &&
-		    (event->xFlags.xAckInd == HvLpEvent_AckInd_DoAck)) {
+		if (hvlpevent_need_ack(event)) {
 			event->xRc = HvLpEvent_Rc_InvalidSubtype;
 			HvCallEvent_ackLpEvent(event);
 		}
@@ -377,7 +376,7 @@
 	int subtype = (event->xSubtype & VIOMAJOR_SUBTYPE_MASK)
 		>> VIOMAJOR_SUBTYPE_SHIFT;
 
-	if (event->xFlags.xFunction == HvLpEvent_Function_Int) {
+	if (hvlpevent_is_int(event)) {
 		remoteLp = event->xSourceLp;
 		/*
 		 * The isActive is checked because if the hosting partition
@@ -436,8 +435,7 @@
 		       "unexpected virtual io event subtype %d from partition %d\n",
 		       event->xSubtype, remoteLp);
 		/* No handler.  Ack if necessary */
-		if ((event->xFlags.xFunction == HvLpEvent_Function_Int) &&
-		    (event->xFlags.xAckInd == HvLpEvent_AckInd_DoAck)) {
+		if (hvlpevent_is_int(event) && hvlpevent_need_ack(event)) {
 			event->xRc = HvLpEvent_Rc_InvalidSubtype;
 			HvCallEvent_ackLpEvent(event);
 		}
diff --git a/arch/powerpc/platforms/maple/setup.c b/arch/powerpc/platforms/maple/setup.c
index dd73e38..a1cb4d2 100644
--- a/arch/powerpc/platforms/maple/setup.c
+++ b/arch/powerpc/platforms/maple/setup.c
@@ -71,9 +71,6 @@
 #define DBG(fmt...)
 #endif
 
-extern void generic_find_legacy_serial_ports(u64 *physport,
-		unsigned int *default_speed);
-
 static void maple_restart(char *cmd)
 {
 	unsigned int maple_nvram_base;
diff --git a/arch/powerpc/platforms/powermac/setup.c b/arch/powerpc/platforms/powermac/setup.c
index 3b1a9d4..89c4c36 100644
--- a/arch/powerpc/platforms/powermac/setup.c
+++ b/arch/powerpc/platforms/powermac/setup.c
@@ -278,7 +278,7 @@
 }
 #endif
 
-void __init pmac_setup_arch(void)
+static void __init pmac_setup_arch(void)
 {
 	struct device_node *cpu, *ic;
 	int *fp;
diff --git a/arch/powerpc/platforms/powermac/udbg_scc.c b/arch/powerpc/platforms/powermac/udbg_scc.c
index e87d53a..c4352a8 100644
--- a/arch/powerpc/platforms/powermac/udbg_scc.c
+++ b/arch/powerpc/platforms/powermac/udbg_scc.c
@@ -153,7 +153,7 @@
 		udbg_real_scc_putc('\r');
 }
 
-void udbg_init_pmac_realmode(void)
+void __init udbg_init_pmac_realmode(void)
 {
 	sccc = (volatile u8 __iomem *)0x80013020ul;
 	sccd = (volatile u8 __iomem *)0x80013030ul;
diff --git a/arch/powerpc/platforms/pseries/Makefile b/arch/powerpc/platforms/pseries/Makefile
index 6accdd1..61616d1 100644
--- a/arch/powerpc/platforms/pseries/Makefile
+++ b/arch/powerpc/platforms/pseries/Makefile
@@ -4,7 +4,7 @@
 obj-$(CONFIG_IBMVIO)	+= vio.o
 obj-$(CONFIG_XICS)	+= xics.o
 obj-$(CONFIG_SCANLOG)	+= scanlog.o
-obj-$(CONFIG_EEH)	+= eeh.o eeh_event.o
+obj-$(CONFIG_EEH)	+= eeh.o eeh_cache.o eeh_driver.o eeh_event.o
 
 obj-$(CONFIG_HVC_CONSOLE)	+= hvconsole.o
 obj-$(CONFIG_HVCS)		+= hvcserver.o
diff --git a/arch/powerpc/platforms/pseries/eeh.c b/arch/powerpc/platforms/pseries/eeh.c
index 7fbfd16..8357831 100644
--- a/arch/powerpc/platforms/pseries/eeh.c
+++ b/arch/powerpc/platforms/pseries/eeh.c
@@ -76,15 +76,14 @@
  */
 #define EEH_MAX_FAILS	100000
 
-/* Misc forward declaraions */
-static void eeh_save_bars(struct pci_dev * pdev, struct pci_dn *pdn);
-
 /* RTAS tokens */
 static int ibm_set_eeh_option;
 static int ibm_set_slot_reset;
 static int ibm_read_slot_reset_state;
 static int ibm_read_slot_reset_state2;
 static int ibm_slot_error_detail;
+static int ibm_get_config_addr_info;
+static int ibm_configure_bridge;
 
 int eeh_subsystem_enabled;
 EXPORT_SYMBOL(eeh_subsystem_enabled);
@@ -98,308 +97,23 @@
 static int eeh_error_buf_size;
 
 /* System monitoring statistics */
-static DEFINE_PER_CPU(unsigned long, no_device);
-static DEFINE_PER_CPU(unsigned long, no_dn);
-static DEFINE_PER_CPU(unsigned long, no_cfg_addr);
-static DEFINE_PER_CPU(unsigned long, ignored_check);
-static DEFINE_PER_CPU(unsigned long, total_mmio_ffs);
-static DEFINE_PER_CPU(unsigned long, false_positives);
-static DEFINE_PER_CPU(unsigned long, ignored_failures);
-static DEFINE_PER_CPU(unsigned long, slot_resets);
+static unsigned long no_device;
+static unsigned long no_dn;
+static unsigned long no_cfg_addr;
+static unsigned long ignored_check;
+static unsigned long total_mmio_ffs;
+static unsigned long false_positives;
+static unsigned long ignored_failures;
+static unsigned long slot_resets;
 
-/**
- * The pci address cache subsystem.  This subsystem places
- * PCI device address resources into a red-black tree, sorted
- * according to the address range, so that given only an i/o
- * address, the corresponding PCI device can be **quickly**
- * found. It is safe to perform an address lookup in an interrupt
- * context; this ability is an important feature.
- *
- * Currently, the only customer of this code is the EEH subsystem;
- * thus, this code has been somewhat tailored to suit EEH better.
- * In particular, the cache does *not* hold the addresses of devices
- * for which EEH is not enabled.
- *
- * (Implementation Note: The RB tree seems to be better/faster
- * than any hash algo I could think of for this problem, even
- * with the penalty of slow pointer chases for d-cache misses).
- */
-struct pci_io_addr_range
-{
-	struct rb_node rb_node;
-	unsigned long addr_lo;
-	unsigned long addr_hi;
-	struct pci_dev *pcidev;
-	unsigned int flags;
-};
-
-static struct pci_io_addr_cache
-{
-	struct rb_root rb_root;
-	spinlock_t piar_lock;
-} pci_io_addr_cache_root;
-
-static inline struct pci_dev *__pci_get_device_by_addr(unsigned long addr)
-{
-	struct rb_node *n = pci_io_addr_cache_root.rb_root.rb_node;
-
-	while (n) {
-		struct pci_io_addr_range *piar;
-		piar = rb_entry(n, struct pci_io_addr_range, rb_node);
-
-		if (addr < piar->addr_lo) {
-			n = n->rb_left;
-		} else {
-			if (addr > piar->addr_hi) {
-				n = n->rb_right;
-			} else {
-				pci_dev_get(piar->pcidev);
-				return piar->pcidev;
-			}
-		}
-	}
-
-	return NULL;
-}
-
-/**
- * pci_get_device_by_addr - Get device, given only address
- * @addr: mmio (PIO) phys address or i/o port number
- *
- * Given an mmio phys address, or a port number, find a pci device
- * that implements this address.  Be sure to pci_dev_put the device
- * when finished.  I/O port numbers are assumed to be offset
- * from zero (that is, they do *not* have pci_io_addr added in).
- * It is safe to call this function within an interrupt.
- */
-static struct pci_dev *pci_get_device_by_addr(unsigned long addr)
-{
-	struct pci_dev *dev;
-	unsigned long flags;
-
-	spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);
-	dev = __pci_get_device_by_addr(addr);
-	spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
-	return dev;
-}
-
-#ifdef DEBUG
-/*
- * Handy-dandy debug print routine, does nothing more
- * than print out the contents of our addr cache.
- */
-static void pci_addr_cache_print(struct pci_io_addr_cache *cache)
-{
-	struct rb_node *n;
-	int cnt = 0;
-
-	n = rb_first(&cache->rb_root);
-	while (n) {
-		struct pci_io_addr_range *piar;
-		piar = rb_entry(n, struct pci_io_addr_range, rb_node);
-		printk(KERN_DEBUG "PCI: %s addr range %d [%lx-%lx]: %s\n",
-		       (piar->flags & IORESOURCE_IO) ? "i/o" : "mem", cnt,
-		       piar->addr_lo, piar->addr_hi, pci_name(piar->pcidev));
-		cnt++;
-		n = rb_next(n);
-	}
-}
-#endif
-
-/* Insert address range into the rb tree. */
-static struct pci_io_addr_range *
-pci_addr_cache_insert(struct pci_dev *dev, unsigned long alo,
-		      unsigned long ahi, unsigned int flags)
-{
-	struct rb_node **p = &pci_io_addr_cache_root.rb_root.rb_node;
-	struct rb_node *parent = NULL;
-	struct pci_io_addr_range *piar;
-
-	/* Walk tree, find a place to insert into tree */
-	while (*p) {
-		parent = *p;
-		piar = rb_entry(parent, struct pci_io_addr_range, rb_node);
-		if (ahi < piar->addr_lo) {
-			p = &parent->rb_left;
-		} else if (alo > piar->addr_hi) {
-			p = &parent->rb_right;
-		} else {
-			if (dev != piar->pcidev ||
-			    alo != piar->addr_lo || ahi != piar->addr_hi) {
-				printk(KERN_WARNING "PIAR: overlapping address range\n");
-			}
-			return piar;
-		}
-	}
-	piar = (struct pci_io_addr_range *)kmalloc(sizeof(struct pci_io_addr_range), GFP_ATOMIC);
-	if (!piar)
-		return NULL;
-
-	piar->addr_lo = alo;
-	piar->addr_hi = ahi;
-	piar->pcidev = dev;
-	piar->flags = flags;
-
-#ifdef DEBUG
-	printk(KERN_DEBUG "PIAR: insert range=[%lx:%lx] dev=%s\n",
-	                  alo, ahi, pci_name (dev));
-#endif
-
-	rb_link_node(&piar->rb_node, parent, p);
-	rb_insert_color(&piar->rb_node, &pci_io_addr_cache_root.rb_root);
-
-	return piar;
-}
-
-static void __pci_addr_cache_insert_device(struct pci_dev *dev)
-{
-	struct device_node *dn;
-	struct pci_dn *pdn;
-	int i;
-	int inserted = 0;
-
-	dn = pci_device_to_OF_node(dev);
-	if (!dn) {
-		printk(KERN_WARNING "PCI: no pci dn found for dev=%s\n", pci_name(dev));
-		return;
-	}
-
-	/* Skip any devices for which EEH is not enabled. */
-	pdn = PCI_DN(dn);
-	if (!(pdn->eeh_mode & EEH_MODE_SUPPORTED) ||
-	    pdn->eeh_mode & EEH_MODE_NOCHECK) {
-#ifdef DEBUG
-		printk(KERN_INFO "PCI: skip building address cache for=%s - %s\n",
-		       pci_name(dev), pdn->node->full_name);
-#endif
-		return;
-	}
-
-	/* The cache holds a reference to the device... */
-	pci_dev_get(dev);
-
-	/* Walk resources on this device, poke them into the tree */
-	for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
-		unsigned long start = pci_resource_start(dev,i);
-		unsigned long end = pci_resource_end(dev,i);
-		unsigned int flags = pci_resource_flags(dev,i);
-
-		/* We are interested only bus addresses, not dma or other stuff */
-		if (0 == (flags & (IORESOURCE_IO | IORESOURCE_MEM)))
-			continue;
-		if (start == 0 || ~start == 0 || end == 0 || ~end == 0)
-			 continue;
-		pci_addr_cache_insert(dev, start, end, flags);
-		inserted = 1;
-	}
-
-	/* If there was nothing to add, the cache has no reference... */
-	if (!inserted)
-		pci_dev_put(dev);
-}
-
-/**
- * pci_addr_cache_insert_device - Add a device to the address cache
- * @dev: PCI device whose I/O addresses we are interested in.
- *
- * In order to support the fast lookup of devices based on addresses,
- * we maintain a cache of devices that can be quickly searched.
- * This routine adds a device to that cache.
- */
-static void pci_addr_cache_insert_device(struct pci_dev *dev)
-{
-	unsigned long flags;
-
-	spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);
-	__pci_addr_cache_insert_device(dev);
-	spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
-}
-
-static inline void __pci_addr_cache_remove_device(struct pci_dev *dev)
-{
-	struct rb_node *n;
-	int removed = 0;
-
-restart:
-	n = rb_first(&pci_io_addr_cache_root.rb_root);
-	while (n) {
-		struct pci_io_addr_range *piar;
-		piar = rb_entry(n, struct pci_io_addr_range, rb_node);
-
-		if (piar->pcidev == dev) {
-			rb_erase(n, &pci_io_addr_cache_root.rb_root);
-			removed = 1;
-			kfree(piar);
-			goto restart;
-		}
-		n = rb_next(n);
-	}
-
-	/* The cache no longer holds its reference to this device... */
-	if (removed)
-		pci_dev_put(dev);
-}
-
-/**
- * pci_addr_cache_remove_device - remove pci device from addr cache
- * @dev: device to remove
- *
- * Remove a device from the addr-cache tree.
- * This is potentially expensive, since it will walk
- * the tree multiple times (once per resource).
- * But so what; device removal doesn't need to be that fast.
- */
-static void pci_addr_cache_remove_device(struct pci_dev *dev)
-{
-	unsigned long flags;
-
-	spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);
-	__pci_addr_cache_remove_device(dev);
-	spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
-}
-
-/**
- * pci_addr_cache_build - Build a cache of I/O addresses
- *
- * Build a cache of pci i/o addresses.  This cache will be used to
- * find the pci device that corresponds to a given address.
- * This routine scans all pci busses to build the cache.
- * Must be run late in boot process, after the pci controllers
- * have been scaned for devices (after all device resources are known).
- */
-void __init pci_addr_cache_build(void)
-{
-	struct device_node *dn;
-	struct pci_dev *dev = NULL;
-
-	if (!eeh_subsystem_enabled)
-		return;
-
-	spin_lock_init(&pci_io_addr_cache_root.piar_lock);
-
-	while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
-		/* Ignore PCI bridges ( XXX why ??) */
-		if ((dev->class >> 16) == PCI_BASE_CLASS_BRIDGE) {
-			continue;
-		}
-		pci_addr_cache_insert_device(dev);
-
-		/* Save the BAR's; firmware doesn't restore these after EEH reset */
-		dn = pci_device_to_OF_node(dev);
-		eeh_save_bars(dev, PCI_DN(dn));
-	}
-
-#ifdef DEBUG
-	/* Verify tree built up above, echo back the list of addrs. */
-	pci_addr_cache_print(&pci_io_addr_cache_root);
-#endif
-}
+#define IS_BRIDGE(class_code) (((class_code)<<16) == PCI_BASE_CLASS_BRIDGE)
 
 /* --------------------------------------------------------------- */
-/* Above lies the PCI Address Cache. Below lies the EEH event infrastructure */
+/* Below lies the EEH event infrastructure */
 
 void eeh_slot_error_detail (struct pci_dn *pdn, int severity)
 {
+	int config_addr;
 	unsigned long flags;
 	int rc;
 
@@ -407,8 +121,13 @@
 	spin_lock_irqsave(&slot_errbuf_lock, flags);
 	memset(slot_errbuf, 0, eeh_error_buf_size);
 
+	/* Use PE configuration address, if present */
+	config_addr = pdn->eeh_config_addr;
+	if (pdn->eeh_pe_config_addr)
+		config_addr = pdn->eeh_pe_config_addr;
+
 	rc = rtas_call(ibm_slot_error_detail,
-	               8, 1, NULL, pdn->eeh_config_addr,
+	               8, 1, NULL, config_addr,
 	               BUID_HI(pdn->phb->buid),
 	               BUID_LO(pdn->phb->buid), NULL, 0,
 	               virt_to_phys(slot_errbuf),
@@ -428,6 +147,7 @@
 static int read_slot_reset_state(struct pci_dn *pdn, int rets[])
 {
 	int token, outputs;
+	int config_addr;
 
 	if (ibm_read_slot_reset_state2 != RTAS_UNKNOWN_SERVICE) {
 		token = ibm_read_slot_reset_state2;
@@ -438,7 +158,12 @@
 		outputs = 3;
 	}
 
-	return rtas_call(token, 3, outputs, rets, pdn->eeh_config_addr,
+	/* Use PE configuration address, if present */
+	config_addr = pdn->eeh_config_addr;
+	if (pdn->eeh_pe_config_addr)
+		config_addr = pdn->eeh_pe_config_addr;
+
+	return rtas_call(token, 3, outputs, rets, config_addr,
 			 BUID_HI(pdn->phb->buid), BUID_LO(pdn->phb->buid));
 }
 
@@ -462,7 +187,7 @@
 /** 
  * Return the "partitionable endpoint" (pe) under which this device lies
  */
-static struct device_node * find_device_pe(struct device_node *dn)
+struct device_node * find_device_pe(struct device_node *dn)
 {
 	while ((dn->parent) && PCI_DN(dn->parent) &&
 	      (PCI_DN(dn->parent)->eeh_mode & EEH_MODE_SUPPORTED)) {
@@ -483,8 +208,14 @@
 {
 	while (dn) {
 		if (PCI_DN(dn)) {
+			/* Mark the pci device driver too */
+			struct pci_dev *dev = PCI_DN(dn)->pcidev;
+
 			PCI_DN(dn)->eeh_mode |= mode_flag;
 
+			if (dev && dev->driver)
+				dev->error_state = pci_channel_io_frozen;
+
 			if (dn->child)
 				__eeh_mark_slot (dn->child, mode_flag);
 		}
@@ -495,6 +226,11 @@
 void eeh_mark_slot (struct device_node *dn, int mode_flag)
 {
 	dn = find_device_pe (dn);
+
+	/* Back up one, since config addrs might be shared */
+	if (PCI_DN(dn) && PCI_DN(dn)->eeh_pe_config_addr)
+		dn = dn->parent;
+
 	PCI_DN(dn)->eeh_mode |= mode_flag;
 	__eeh_mark_slot (dn->child, mode_flag);
 }
@@ -516,7 +252,13 @@
 {
 	unsigned long flags;
 	spin_lock_irqsave(&confirm_error_lock, flags);
+	
 	dn = find_device_pe (dn);
+	
+	/* Back up one, since config addrs might be shared */
+	if (PCI_DN(dn) && PCI_DN(dn)->eeh_pe_config_addr)
+		dn = dn->parent;
+
 	PCI_DN(dn)->eeh_mode &= ~mode_flag;
 	PCI_DN(dn)->eeh_check_count = 0;
 	__eeh_clear_slot (dn->child, mode_flag);
@@ -544,15 +286,16 @@
 	int rets[3];
 	unsigned long flags;
 	struct pci_dn *pdn;
+	enum pci_channel_state state;
 	int rc = 0;
 
-	__get_cpu_var(total_mmio_ffs)++;
+	total_mmio_ffs++;
 
 	if (!eeh_subsystem_enabled)
 		return 0;
 
 	if (!dn) {
-		__get_cpu_var(no_dn)++;
+		no_dn++;
 		return 0;
 	}
 	pdn = PCI_DN(dn);
@@ -560,7 +303,7 @@
 	/* Access to IO BARs might get this far and still not want checking. */
 	if (!(pdn->eeh_mode & EEH_MODE_SUPPORTED) ||
 	    pdn->eeh_mode & EEH_MODE_NOCHECK) {
-		__get_cpu_var(ignored_check)++;
+		ignored_check++;
 #ifdef DEBUG
 		printk ("EEH:ignored check (%x) for %s %s\n", 
 		        pdn->eeh_mode, pci_name (dev), dn->full_name);
@@ -568,8 +311,8 @@
 		return 0;
 	}
 
-	if (!pdn->eeh_config_addr) {
-		__get_cpu_var(no_cfg_addr)++;
+	if (!pdn->eeh_config_addr && !pdn->eeh_pe_config_addr) {
+		no_cfg_addr++;
 		return 0;
 	}
 
@@ -611,7 +354,7 @@
 	if (ret != 0) {
 		printk(KERN_WARNING "EEH: read_slot_reset_state() failed; rc=%d dn=%s\n",
 		       ret, dn->full_name);
-		__get_cpu_var(false_positives)++;
+		false_positives++;
 		rc = 0;
 		goto dn_unlock;
 	}
@@ -620,14 +363,14 @@
 	if (rets[1] != 1) {
 		printk(KERN_WARNING "EEH: event on unsupported device, rc=%d dn=%s\n",
 		       ret, dn->full_name);
-		__get_cpu_var(false_positives)++;
+		false_positives++;
 		rc = 0;
 		goto dn_unlock;
 	}
 
 	/* If not the kind of error we know about, punt. */
 	if (rets[0] != 2 && rets[0] != 4 && rets[0] != 5) {
-		__get_cpu_var(false_positives)++;
+		false_positives++;
 		rc = 0;
 		goto dn_unlock;
 	}
@@ -635,12 +378,12 @@
 	/* Note that config-io to empty slots may fail;
 	 * we recognize empty because they don't have children. */
 	if ((rets[0] == 5) && (dn->child == NULL)) {
-		__get_cpu_var(false_positives)++;
+		false_positives++;
 		rc = 0;
 		goto dn_unlock;
 	}
 
-	__get_cpu_var(slot_resets)++;
+	slot_resets++;
  
 	/* Avoid repeated reports of this failure, including problems
 	 * with other functions on this device, and functions under
@@ -648,8 +391,13 @@
 	eeh_mark_slot (dn, EEH_MODE_ISOLATED);
 	spin_unlock_irqrestore(&confirm_error_lock, flags);
 
-	eeh_send_failure_event (dn, dev, rets[0], rets[2]);
-	
+	state = pci_channel_io_normal;
+	if ((rets[0] == 2) || (rets[0] == 4))
+		state = pci_channel_io_frozen;
+	if (rets[0] == 5)
+		state = pci_channel_io_perm_failure;
+	eeh_send_failure_event (dn, dev, state, rets[2]);
+
 	/* Most EEH events are due to device driver bugs.  Having
 	 * a stack trace will help the device-driver authors figure
 	 * out what happened.  So print that out. */
@@ -685,7 +433,7 @@
 	addr = eeh_token_to_phys((unsigned long __force) token);
 	dev = pci_get_device_by_addr(addr);
 	if (!dev) {
-		__get_cpu_var(no_device)++;
+		no_device++;
 		return val;
 	}
 
@@ -716,11 +464,16 @@
 	if (rc) return rc;
 
 	if (rets[1] == 0) return -1;  /* EEH is not supported */
-	if (rets[0] == 0)  return 0;  /* Oll Korrect */
+	if (rets[0] == 0) return 0;   /* Oll Korrect */
 	if (rets[0] == 5) {
 		if (rets[2] == 0) return -1; /* permanently unavailable */
 		return rets[2]; /* number of millisecs to wait */
 	}
+	if (rets[0] == 1)
+		return 250;
+
+	printk (KERN_ERR "EEH: Slot unavailable: rc=%d, rets=%d %d %d\n",
+		rc, rets[0], rets[1], rets[2]);
 	return -1;
 }
 
@@ -737,6 +490,7 @@
 static void
 rtas_pci_slot_reset(struct pci_dn *pdn, int state)
 {
+	int config_addr;
 	int rc;
 
 	BUG_ON (pdn==NULL); 
@@ -747,8 +501,13 @@
 		return;
 	}
 
+	/* Use PE configuration address, if present */
+	config_addr = pdn->eeh_config_addr;
+	if (pdn->eeh_pe_config_addr)
+		config_addr = pdn->eeh_pe_config_addr;
+
 	rc = rtas_call(ibm_set_slot_reset,4,1, NULL,
-	               pdn->eeh_config_addr,
+	               config_addr,
 	               BUID_HI(pdn->phb->buid),
 	               BUID_LO(pdn->phb->buid),
 	               state);
@@ -761,9 +520,11 @@
 
 /** rtas_set_slot_reset -- assert the pci #RST line for 1/4 second
  *  dn -- device node to be reset.
+ *
+ *  Return 0 if success, else a non-zero value.
  */
 
-void
+int
 rtas_set_slot_reset(struct pci_dn *pdn)
 {
 	int i, rc;
@@ -793,10 +554,21 @@
 	 * ready to be used; if not, wait for recovery. */
 	for (i=0; i<10; i++) {
 		rc = eeh_slot_availability (pdn);
-		if (rc <= 0) break;
+		if (rc < 0)
+			printk (KERN_ERR "EEH: failed (%d) to reset slot %s\n", rc, pdn->node->full_name);
+		if (rc == 0)
+			return 0;
+		if (rc < 0)
+			return -1;
 
 		msleep (rc+100);
 	}
+
+	rc = eeh_slot_availability (pdn);
+	if (rc)
+		printk (KERN_ERR "EEH: timeout resetting slot %s\n", pdn->node->full_name);
+
+	return rc;
 }
 
 /* ------------------------------------------------------- */
@@ -851,7 +623,7 @@
 	if (!pdn) 
 		return;
 	
-	if (! pdn->eeh_is_bridge)
+	if ((pdn->eeh_mode & EEH_MODE_SUPPORTED) && !IS_BRIDGE(pdn->class_code))
 		__restore_bars (pdn);
 
 	dn = pdn->node->child;
@@ -869,30 +641,30 @@
  * PCI devices are added individuallly; but, for the restore,
  * an entire slot is reset at a time.
  */
-static void eeh_save_bars(struct pci_dev * pdev, struct pci_dn *pdn)
+static void eeh_save_bars(struct pci_dn *pdn)
 {
 	int i;
 
-	if (!pdev || !pdn )
+	if (!pdn )
 		return;
 	
 	for (i = 0; i < 16; i++)
-		pci_read_config_dword(pdev, i * 4, &pdn->config_space[i]);
-
-	if (pdev->hdr_type == PCI_HEADER_TYPE_BRIDGE)
-		pdn->eeh_is_bridge = 1;
+		rtas_read_config(pdn, i * 4, 4, &pdn->config_space[i]);
 }
 
 void
 rtas_configure_bridge(struct pci_dn *pdn)
 {
-	int token = rtas_token ("ibm,configure-bridge");
+	int config_addr;
 	int rc;
 
-	if (token == RTAS_UNKNOWN_SERVICE)
-		return;
-	rc = rtas_call(token,3,1, NULL,
-	               pdn->eeh_config_addr,
+	/* Use PE configuration address, if present */
+	config_addr = pdn->eeh_config_addr;
+	if (pdn->eeh_pe_config_addr)
+		config_addr = pdn->eeh_pe_config_addr;
+
+	rc = rtas_call(ibm_configure_bridge,3,1, NULL,
+	               config_addr,
 	               BUID_HI(pdn->phb->buid),
 	               BUID_LO(pdn->phb->buid));
 	if (rc) {
@@ -927,6 +699,7 @@
 	int enable;
 	struct pci_dn *pdn = PCI_DN(dn);
 
+	pdn->class_code = 0;
 	pdn->eeh_mode = 0;
 	pdn->eeh_check_count = 0;
 	pdn->eeh_freeze_count = 0;
@@ -943,6 +716,7 @@
 		pdn->eeh_mode |= EEH_MODE_NOCHECK;
 		return NULL;
 	}
+	pdn->class_code = *class_code;
 
 	/*
 	 * Now decide if we are going to "Disable" EEH checking
@@ -953,8 +727,10 @@
 	 * But there are a few cases like display devices that make sense.
 	 */
 	enable = 1;	/* i.e. we will do checking */
+#if 0
 	if ((*class_code >> 16) == PCI_BASE_CLASS_DISPLAY)
 		enable = 0;
+#endif
 
 	if (!enable)
 		pdn->eeh_mode |= EEH_MODE_NOCHECK;
@@ -973,8 +749,22 @@
 			eeh_subsystem_enabled = 1;
 			pdn->eeh_mode |= EEH_MODE_SUPPORTED;
 			pdn->eeh_config_addr = regs[0];
+
+			/* If the newer, better, ibm,get-config-addr-info is supported, 
+			 * then use that instead. */
+			pdn->eeh_pe_config_addr = 0;
+			if (ibm_get_config_addr_info != RTAS_UNKNOWN_SERVICE) {
+				unsigned int rets[2];
+				ret = rtas_call (ibm_get_config_addr_info, 4, 2, rets, 
+					pdn->eeh_config_addr, 
+					info->buid_hi, info->buid_lo,
+					0);
+				if (ret == 0)
+					pdn->eeh_pe_config_addr = rets[0];
+			}
 #ifdef DEBUG
-			printk(KERN_DEBUG "EEH: %s: eeh enabled\n", dn->full_name);
+			printk(KERN_DEBUG "EEH: %s: eeh enabled, config=%x pe_config=%x\n",
+			       dn->full_name, pdn->eeh_config_addr, pdn->eeh_pe_config_addr);
 #endif
 		} else {
 
@@ -993,6 +783,7 @@
 		       dn->full_name);
 	}
 
+	eeh_save_bars(pdn);
 	return NULL;
 }
 
@@ -1026,6 +817,8 @@
 	ibm_read_slot_reset_state2 = rtas_token("ibm,read-slot-reset-state2");
 	ibm_read_slot_reset_state = rtas_token("ibm,read-slot-reset-state");
 	ibm_slot_error_detail = rtas_token("ibm,slot-error-detail");
+	ibm_get_config_addr_info = rtas_token("ibm,get-config-addr-info");
+	ibm_configure_bridge = rtas_token ("ibm,configure-bridge");
 
 	if (ibm_set_eeh_option == RTAS_UNKNOWN_SERVICE)
 		return;
@@ -1080,12 +873,10 @@
 	if (!dn || !PCI_DN(dn))
 		return;
 	phb = PCI_DN(dn)->phb;
-	if (NULL == phb || 0 == phb->buid) {
-		printk(KERN_WARNING "EEH: Expected buid but found none for %s\n",
-		       dn->full_name);
-		dump_stack();
+
+	/* USB Bus children of PCI devices will not have BUID's */
+	if (NULL == phb || 0 == phb->buid)
 		return;
-	}
 
 	info.buid_hi = BUID_HI(phb->buid);
 	info.buid_lo = BUID_LO(phb->buid);
@@ -1127,7 +918,6 @@
 	pdn->pcidev = dev;
 
 	pci_addr_cache_insert_device (dev);
-	eeh_save_bars(dev, pdn);
 }
 EXPORT_SYMBOL_GPL(eeh_add_device_late);
 
@@ -1175,25 +965,9 @@
 
 static int proc_eeh_show(struct seq_file *m, void *v)
 {
-	unsigned int cpu;
-	unsigned long ffs = 0, positives = 0, failures = 0;
-	unsigned long resets = 0;
-	unsigned long no_dev = 0, no_dn = 0, no_cfg = 0, no_check = 0;
-
-	for_each_cpu(cpu) {
-		ffs += per_cpu(total_mmio_ffs, cpu);
-		positives += per_cpu(false_positives, cpu);
-		failures += per_cpu(ignored_failures, cpu);
-		resets += per_cpu(slot_resets, cpu);
-		no_dev += per_cpu(no_device, cpu);
-		no_dn += per_cpu(no_dn, cpu);
-		no_cfg += per_cpu(no_cfg_addr, cpu);
-		no_check += per_cpu(ignored_check, cpu);
-	}
-
 	if (0 == eeh_subsystem_enabled) {
 		seq_printf(m, "EEH Subsystem is globally disabled\n");
-		seq_printf(m, "eeh_total_mmio_ffs=%ld\n", ffs);
+		seq_printf(m, "eeh_total_mmio_ffs=%ld\n", total_mmio_ffs);
 	} else {
 		seq_printf(m, "EEH Subsystem is enabled\n");
 		seq_printf(m,
@@ -1205,8 +979,10 @@
 				"eeh_false_positives=%ld\n"
 				"eeh_ignored_failures=%ld\n"
 				"eeh_slot_resets=%ld\n",
-				no_dev, no_dn, no_cfg, no_check,
-				ffs, positives, failures, resets);
+				no_device, no_dn, no_cfg_addr, 
+				ignored_check, total_mmio_ffs, 
+				false_positives, ignored_failures, 
+				slot_resets);
 	}
 
 	return 0;
diff --git a/arch/powerpc/platforms/pseries/eeh_cache.c b/arch/powerpc/platforms/pseries/eeh_cache.c
new file mode 100644
index 0000000..d4a402c
--- /dev/null
+++ b/arch/powerpc/platforms/pseries/eeh_cache.c
@@ -0,0 +1,316 @@
+/*
+ * eeh_cache.c
+ * PCI address cache; allows the lookup of PCI devices based on I/O address
+ *
+ * Copyright (C) 2004 Linas Vepstas <linas@austin.ibm.com> IBM Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+
+#include <linux/list.h>
+#include <linux/pci.h>
+#include <linux/rbtree.h>
+#include <linux/spinlock.h>
+#include <asm/atomic.h>
+#include <asm/pci-bridge.h>
+#include <asm/ppc-pci.h>
+
+#undef DEBUG
+
+/**
+ * The pci address cache subsystem.  This subsystem places
+ * PCI device address resources into a red-black tree, sorted
+ * according to the address range, so that given only an i/o
+ * address, the corresponding PCI device can be **quickly**
+ * found. It is safe to perform an address lookup in an interrupt
+ * context; this ability is an important feature.
+ *
+ * Currently, the only customer of this code is the EEH subsystem;
+ * thus, this code has been somewhat tailored to suit EEH better.
+ * In particular, the cache does *not* hold the addresses of devices
+ * for which EEH is not enabled.
+ *
+ * (Implementation Note: The RB tree seems to be better/faster
+ * than any hash algo I could think of for this problem, even
+ * with the penalty of slow pointer chases for d-cache misses).
+ */
+struct pci_io_addr_range
+{
+	struct rb_node rb_node;
+	unsigned long addr_lo;
+	unsigned long addr_hi;
+	struct pci_dev *pcidev;
+	unsigned int flags;
+};
+
+static struct pci_io_addr_cache
+{
+	struct rb_root rb_root;
+	spinlock_t piar_lock;
+} pci_io_addr_cache_root;
+
+static inline struct pci_dev *__pci_get_device_by_addr(unsigned long addr)
+{
+	struct rb_node *n = pci_io_addr_cache_root.rb_root.rb_node;
+
+	while (n) {
+		struct pci_io_addr_range *piar;
+		piar = rb_entry(n, struct pci_io_addr_range, rb_node);
+
+		if (addr < piar->addr_lo) {
+			n = n->rb_left;
+		} else {
+			if (addr > piar->addr_hi) {
+				n = n->rb_right;
+			} else {
+				pci_dev_get(piar->pcidev);
+				return piar->pcidev;
+			}
+		}
+	}
+
+	return NULL;
+}
+
+/**
+ * pci_get_device_by_addr - Get device, given only address
+ * @addr: mmio (PIO) phys address or i/o port number
+ *
+ * Given an mmio phys address, or a port number, find a pci device
+ * that implements this address.  Be sure to pci_dev_put the device
+ * when finished.  I/O port numbers are assumed to be offset
+ * from zero (that is, they do *not* have pci_io_addr added in).
+ * It is safe to call this function within an interrupt.
+ */
+struct pci_dev *pci_get_device_by_addr(unsigned long addr)
+{
+	struct pci_dev *dev;
+	unsigned long flags;
+
+	spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);
+	dev = __pci_get_device_by_addr(addr);
+	spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
+	return dev;
+}
+
+#ifdef DEBUG
+/*
+ * Handy-dandy debug print routine, does nothing more
+ * than print out the contents of our addr cache.
+ */
+static void pci_addr_cache_print(struct pci_io_addr_cache *cache)
+{
+	struct rb_node *n;
+	int cnt = 0;
+
+	n = rb_first(&cache->rb_root);
+	while (n) {
+		struct pci_io_addr_range *piar;
+		piar = rb_entry(n, struct pci_io_addr_range, rb_node);
+		printk(KERN_DEBUG "PCI: %s addr range %d [%lx-%lx]: %s\n",
+		       (piar->flags & IORESOURCE_IO) ? "i/o" : "mem", cnt,
+		       piar->addr_lo, piar->addr_hi, pci_name(piar->pcidev));
+		cnt++;
+		n = rb_next(n);
+	}
+}
+#endif
+
+/* Insert address range into the rb tree. */
+static struct pci_io_addr_range *
+pci_addr_cache_insert(struct pci_dev *dev, unsigned long alo,
+		      unsigned long ahi, unsigned int flags)
+{
+	struct rb_node **p = &pci_io_addr_cache_root.rb_root.rb_node;
+	struct rb_node *parent = NULL;
+	struct pci_io_addr_range *piar;
+
+	/* Walk tree, find a place to insert into tree */
+	while (*p) {
+		parent = *p;
+		piar = rb_entry(parent, struct pci_io_addr_range, rb_node);
+		if (ahi < piar->addr_lo) {
+			p = &parent->rb_left;
+		} else if (alo > piar->addr_hi) {
+			p = &parent->rb_right;
+		} else {
+			if (dev != piar->pcidev ||
+			    alo != piar->addr_lo || ahi != piar->addr_hi) {
+				printk(KERN_WARNING "PIAR: overlapping address range\n");
+			}
+			return piar;
+		}
+	}
+	piar = (struct pci_io_addr_range *)kmalloc(sizeof(struct pci_io_addr_range), GFP_ATOMIC);
+	if (!piar)
+		return NULL;
+
+	piar->addr_lo = alo;
+	piar->addr_hi = ahi;
+	piar->pcidev = dev;
+	piar->flags = flags;
+
+#ifdef DEBUG
+	printk(KERN_DEBUG "PIAR: insert range=[%lx:%lx] dev=%s\n",
+	                  alo, ahi, pci_name (dev));
+#endif
+
+	rb_link_node(&piar->rb_node, parent, p);
+	rb_insert_color(&piar->rb_node, &pci_io_addr_cache_root.rb_root);
+
+	return piar;
+}
+
+static void __pci_addr_cache_insert_device(struct pci_dev *dev)
+{
+	struct device_node *dn;
+	struct pci_dn *pdn;
+	int i;
+	int inserted = 0;
+
+	dn = pci_device_to_OF_node(dev);
+	if (!dn) {
+		printk(KERN_WARNING "PCI: no pci dn found for dev=%s\n", pci_name(dev));
+		return;
+	}
+
+	/* Skip any devices for which EEH is not enabled. */
+	pdn = PCI_DN(dn);
+	if (!(pdn->eeh_mode & EEH_MODE_SUPPORTED) ||
+	    pdn->eeh_mode & EEH_MODE_NOCHECK) {
+#ifdef DEBUG
+		printk(KERN_INFO "PCI: skip building address cache for=%s - %s\n",
+		       pci_name(dev), pdn->node->full_name);
+#endif
+		return;
+	}
+
+	/* The cache holds a reference to the device... */
+	pci_dev_get(dev);
+
+	/* Walk resources on this device, poke them into the tree */
+	for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
+		unsigned long start = pci_resource_start(dev,i);
+		unsigned long end = pci_resource_end(dev,i);
+		unsigned int flags = pci_resource_flags(dev,i);
+
+		/* We are interested only bus addresses, not dma or other stuff */
+		if (0 == (flags & (IORESOURCE_IO | IORESOURCE_MEM)))
+			continue;
+		if (start == 0 || ~start == 0 || end == 0 || ~end == 0)
+			 continue;
+		pci_addr_cache_insert(dev, start, end, flags);
+		inserted = 1;
+	}
+
+	/* If there was nothing to add, the cache has no reference... */
+	if (!inserted)
+		pci_dev_put(dev);
+}
+
+/**
+ * pci_addr_cache_insert_device - Add a device to the address cache
+ * @dev: PCI device whose I/O addresses we are interested in.
+ *
+ * In order to support the fast lookup of devices based on addresses,
+ * we maintain a cache of devices that can be quickly searched.
+ * This routine adds a device to that cache.
+ */
+void pci_addr_cache_insert_device(struct pci_dev *dev)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);
+	__pci_addr_cache_insert_device(dev);
+	spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
+}
+
+static inline void __pci_addr_cache_remove_device(struct pci_dev *dev)
+{
+	struct rb_node *n;
+	int removed = 0;
+
+restart:
+	n = rb_first(&pci_io_addr_cache_root.rb_root);
+	while (n) {
+		struct pci_io_addr_range *piar;
+		piar = rb_entry(n, struct pci_io_addr_range, rb_node);
+
+		if (piar->pcidev == dev) {
+			rb_erase(n, &pci_io_addr_cache_root.rb_root);
+			removed = 1;
+			kfree(piar);
+			goto restart;
+		}
+		n = rb_next(n);
+	}
+
+	/* The cache no longer holds its reference to this device... */
+	if (removed)
+		pci_dev_put(dev);
+}
+
+/**
+ * pci_addr_cache_remove_device - remove pci device from addr cache
+ * @dev: device to remove
+ *
+ * Remove a device from the addr-cache tree.
+ * This is potentially expensive, since it will walk
+ * the tree multiple times (once per resource).
+ * But so what; device removal doesn't need to be that fast.
+ */
+void pci_addr_cache_remove_device(struct pci_dev *dev)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);
+	__pci_addr_cache_remove_device(dev);
+	spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
+}
+
+/**
+ * pci_addr_cache_build - Build a cache of I/O addresses
+ *
+ * Build a cache of pci i/o addresses.  This cache will be used to
+ * find the pci device that corresponds to a given address.
+ * This routine scans all pci busses to build the cache.
+ * Must be run late in boot process, after the pci controllers
+ * have been scaned for devices (after all device resources are known).
+ */
+void __init pci_addr_cache_build(void)
+{
+	struct device_node *dn;
+	struct pci_dev *dev = NULL;
+
+	spin_lock_init(&pci_io_addr_cache_root.piar_lock);
+
+	while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
+		/* Ignore PCI bridges */
+		if ((dev->class >> 16) == PCI_BASE_CLASS_BRIDGE)
+			continue;
+
+		pci_addr_cache_insert_device(dev);
+
+		dn = pci_device_to_OF_node(dev);
+		pci_dev_get (dev);  /* matching put is in eeh_remove_device() */
+		PCI_DN(dn)->pcidev = dev;
+	}
+
+#ifdef DEBUG
+	/* Verify tree built up above, echo back the list of addrs. */
+	pci_addr_cache_print(&pci_io_addr_cache_root);
+#endif
+}
+
diff --git a/arch/powerpc/platforms/pseries/eeh_driver.c b/arch/powerpc/platforms/pseries/eeh_driver.c
new file mode 100644
index 0000000..6373372
--- /dev/null
+++ b/arch/powerpc/platforms/pseries/eeh_driver.c
@@ -0,0 +1,376 @@
+/*
+ * PCI Error Recovery Driver for RPA-compliant PPC64 platform.
+ * Copyright (C) 2004, 2005 Linas Vepstas <linas@linas.org>
+ *
+ * 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 <linas@us.ibm.com>
+ *
+ */
+#include <linux/delay.h>
+#include <linux/irq.h>
+#include <linux/interrupt.h>
+#include <linux/notifier.h>
+#include <linux/pci.h>
+#include <asm/eeh.h>
+#include <asm/eeh_event.h>
+#include <asm/ppc-pci.h>
+#include <asm/pci-bridge.h>
+#include <asm/prom.h>
+#include <asm/rtas.h>
+
+
+static inline const char * pcid_name (struct pci_dev *pdev)
+{
+	if (pdev->dev.driver)
+		return pdev->dev.driver->name;
+	return "";
+}
+
+#ifdef DEBUG
+static void print_device_node_tree (struct pci_dn *pdn, int dent)
+{
+	int i;
+	if (!pdn) return;
+	for (i=0;i<dent; i++)
+		printk(" ");
+	printk("dn=%s mode=%x \tcfg_addr=%x pe_addr=%x \tfull=%s\n",
+		pdn->node->name, pdn->eeh_mode, pdn->eeh_config_addr,
+		pdn->eeh_pe_config_addr, pdn->node->full_name);
+	dent += 3;
+	struct device_node *pc = pdn->node->child;
+	while (pc) {
+		print_device_node_tree(PCI_DN(pc), dent);
+		pc = pc->sibling;
+	}
+}
+#endif
+
+/** 
+ * irq_in_use - return true if this irq is being used 
+ */
+static int irq_in_use(unsigned int irq)
+{
+	int rc = 0;
+	unsigned long flags;
+   struct irq_desc *desc = irq_desc + irq;
+
+	spin_lock_irqsave(&desc->lock, flags);
+	if (desc->action)
+		rc = 1;
+	spin_unlock_irqrestore(&desc->lock, flags);
+	return rc;
+}
+
+/* ------------------------------------------------------- */
+/** eeh_report_error - report an EEH error to each device,
+ *  collect up and merge the device responses.
+ */
+
+static void eeh_report_error(struct pci_dev *dev, void *userdata)
+{
+	enum pci_ers_result rc, *res = userdata;
+	struct pci_driver *driver = dev->driver;
+
+	dev->error_state = pci_channel_io_frozen;
+
+	if (!driver)
+		return;
+
+	if (irq_in_use (dev->irq)) {
+		struct device_node *dn = pci_device_to_OF_node(dev);
+		PCI_DN(dn)->eeh_mode |= EEH_MODE_IRQ_DISABLED;
+		disable_irq_nosync(dev->irq);
+	}
+	if (!driver->err_handler)
+		return;
+	if (!driver->err_handler->error_detected)
+		return;
+
+	rc = driver->err_handler->error_detected (dev, pci_channel_io_frozen);
+	if (*res == PCI_ERS_RESULT_NONE) *res = rc;
+	if (*res == PCI_ERS_RESULT_NEED_RESET) return;
+	if (*res == PCI_ERS_RESULT_DISCONNECT &&
+	     rc == PCI_ERS_RESULT_NEED_RESET) *res = rc;
+}
+
+/** eeh_report_reset -- tell this device that the pci slot
+ *  has been reset.
+ */
+
+static void eeh_report_reset(struct pci_dev *dev, void *userdata)
+{
+	struct pci_driver *driver = dev->driver;
+	struct device_node *dn = pci_device_to_OF_node(dev);
+
+	if (!driver)
+		return;
+
+	if ((PCI_DN(dn)->eeh_mode) & EEH_MODE_IRQ_DISABLED) {
+		PCI_DN(dn)->eeh_mode &= ~EEH_MODE_IRQ_DISABLED;
+		enable_irq(dev->irq);
+	}
+	if (!driver->err_handler)
+		return;
+	if (!driver->err_handler->slot_reset)
+		return;
+
+	driver->err_handler->slot_reset(dev);
+}
+
+static void eeh_report_resume(struct pci_dev *dev, void *userdata)
+{
+	struct pci_driver *driver = dev->driver;
+
+	dev->error_state = pci_channel_io_normal;
+
+	if (!driver)
+		return;
+	if (!driver->err_handler)
+		return;
+	if (!driver->err_handler->resume)
+		return;
+
+	driver->err_handler->resume(dev);
+}
+
+static void eeh_report_failure(struct pci_dev *dev, void *userdata)
+{
+	struct pci_driver *driver = dev->driver;
+
+	dev->error_state = pci_channel_io_perm_failure;
+
+	if (!driver)
+		return;
+
+	if (irq_in_use (dev->irq)) {
+		struct device_node *dn = pci_device_to_OF_node(dev);
+		PCI_DN(dn)->eeh_mode |= EEH_MODE_IRQ_DISABLED;
+		disable_irq_nosync(dev->irq);
+	}
+	if (!driver->err_handler)
+		return;
+	if (!driver->err_handler->error_detected)
+		return;
+	driver->err_handler->error_detected(dev, pci_channel_io_perm_failure);
+}
+
+/* ------------------------------------------------------- */
+/**
+ * handle_eeh_events -- reset a PCI device after hard lockup.
+ *
+ * pSeries systems will isolate a PCI slot if the PCI-Host
+ * bridge detects address or data parity errors, DMA's
+ * occuring to wild addresses (which usually happen due to
+ * bugs in device drivers or in PCI adapter firmware).
+ * Slot isolations also occur if #SERR, #PERR or other misc
+ * PCI-related errors are detected.
+ *
+ * Recovery process consists of unplugging the device driver
+ * (which generated hotplug events to userspace), then issuing
+ * a PCI #RST to the device, then reconfiguring the PCI config
+ * space for all bridges & devices under this slot, and then
+ * finally restarting the device drivers (which cause a second
+ * set of hotplug events to go out to userspace).
+ */
+
+/**
+ * eeh_reset_device() -- perform actual reset of a pci slot
+ * Args: bus: pointer to the pci bus structure corresponding
+ *            to the isolated slot. A non-null value will
+ *            cause all devices under the bus to be removed
+ *            and then re-added.
+ *     pe_dn: pointer to a "Partionable Endpoint" device node.
+ *            This is the top-level structure on which pci
+ *            bus resets can be performed.
+ */
+
+static int eeh_reset_device (struct pci_dn *pe_dn, struct pci_bus *bus)
+{
+	int rc;
+	if (bus)
+		pcibios_remove_pci_devices(bus);
+
+	/* Reset the pci controller. (Asserts RST#; resets config space).
+	 * Reconfigure bridges and devices. Don't try to bring the system
+	 * up if the reset failed for some reason. */
+	rc = rtas_set_slot_reset(pe_dn);
+	if (rc)
+		return rc;
+
+ 	/* New-style config addrs might be shared across multiple devices,
+ 	 * Walk over all functions on this device */
+ 	if (pe_dn->eeh_pe_config_addr) {
+ 		struct device_node *pe = pe_dn->node;
+ 		pe = pe->parent->child;
+ 		while (pe) {
+ 			struct pci_dn *ppe = PCI_DN(pe);
+ 			if (pe_dn->eeh_pe_config_addr == ppe->eeh_pe_config_addr) {
+ 				rtas_configure_bridge(ppe);
+ 				eeh_restore_bars(ppe);
+ 			}
+ 			pe = pe->sibling;
+ 		}
+ 	} else {
+ 		rtas_configure_bridge(pe_dn);
+ 		eeh_restore_bars(pe_dn);
+ 	}
+
+	/* Give the system 5 seconds to finish running the user-space
+	 * hotplug shutdown scripts, e.g. ifdown for ethernet.  Yes, 
+	 * this is a hack, but if we don't do this, and try to bring 
+	 * the device up before the scripts have taken it down, 
+	 * potentially weird things happen.
+	 */
+	if (bus) {
+		ssleep (5);
+		pcibios_add_pci_devices(bus);
+	}
+
+	return 0;
+}
+
+/* The longest amount of time to wait for a pci device
+ * to come back on line, in seconds.
+ */
+#define MAX_WAIT_FOR_RECOVERY 15
+
+void handle_eeh_events (struct eeh_event *event)
+{
+	struct device_node *frozen_dn;
+	struct pci_dn *frozen_pdn;
+	struct pci_bus *frozen_bus;
+	int rc = 0;
+	enum pci_ers_result result = PCI_ERS_RESULT_NONE;
+
+	frozen_dn = find_device_pe(event->dn);
+	frozen_bus = pcibios_find_pci_bus(frozen_dn);
+
+	if (!frozen_dn) {
+		printk(KERN_ERR "EEH: Error: Cannot find partition endpoint for %s\n",
+		        pci_name(event->dev));
+		return;
+	}
+
+	/* There are two different styles for coming up with the PE.
+	 * In the old style, it was the highest EEH-capable device
+	 * which was always an EADS pci bridge.  In the new style,
+	 * there might not be any EADS bridges, and even when there are,
+	 * the firmware marks them as "EEH incapable". So another
+	 * two-step is needed to find the pci bus.. */
+	if (!frozen_bus)
+		frozen_bus = pcibios_find_pci_bus (frozen_dn->parent);
+
+	if (!frozen_bus) {
+		printk(KERN_ERR "EEH: Cannot find PCI bus for %s\n",
+		        frozen_dn->full_name);
+		return;
+	}
+
+#if 0
+	/* We may get "permanent failure" messages on empty slots.
+	 * These are false alarms. Empty slots have no child dn. */
+	if ((event->state == pci_channel_io_perm_failure) && (frozen_device == NULL))
+		return;
+#endif
+
+	frozen_pdn = PCI_DN(frozen_dn);
+	frozen_pdn->eeh_freeze_count++;
+	
+	if (frozen_pdn->eeh_freeze_count > EEH_MAX_ALLOWED_FREEZES)
+		goto hard_fail;
+
+	/* If the reset state is a '5' and the time to reset is 0 (infinity)
+	 * or is more then 15 seconds, then mark this as a permanent failure.
+	 */
+	if ((event->state == pci_channel_io_perm_failure) &&
+	    ((event->time_unavail <= 0) ||
+	     (event->time_unavail > MAX_WAIT_FOR_RECOVERY*1000)))
+		goto hard_fail;
+
+	eeh_slot_error_detail(frozen_pdn, 1 /* Temporary Error */);
+	printk(KERN_WARNING
+	   "EEH: This PCI device has failed %d times since last reboot: %s - %s\n",
+		frozen_pdn->eeh_freeze_count,
+		pci_name (frozen_pdn->pcidev), 
+		pcid_name(frozen_pdn->pcidev));
+
+	/* Walk the various device drivers attached to this slot through
+	 * a reset sequence, giving each an opportunity to do what it needs
+	 * to accomplish the reset.  Each child gets a report of the
+	 * status ... if any child can't handle the reset, then the entire
+	 * slot is dlpar removed and added.
+	 */
+	pci_walk_bus(frozen_bus, eeh_report_error, &result);
+
+	/* If all device drivers were EEH-unaware, then shut
+	 * down all of the device drivers, and hope they
+	 * go down willingly, without panicing the system.
+	 */
+	if (result == PCI_ERS_RESULT_NONE) {
+		rc = eeh_reset_device(frozen_pdn, frozen_bus);
+		if (rc)
+			goto hard_fail;
+	}
+
+	/* If any device called out for a reset, then reset the slot */
+	if (result == PCI_ERS_RESULT_NEED_RESET) {
+		rc = eeh_reset_device(frozen_pdn, NULL);
+		if (rc)
+			goto hard_fail;
+		pci_walk_bus(frozen_bus, eeh_report_reset, 0);
+	}
+
+	/* If all devices reported they can proceed, the re-enable PIO */
+	if (result == PCI_ERS_RESULT_CAN_RECOVER) {
+		/* XXX Not supported; we brute-force reset the device */
+		rc = eeh_reset_device(frozen_pdn, NULL);
+		if (rc)
+			goto hard_fail;
+		pci_walk_bus(frozen_bus, eeh_report_reset, 0);
+	}
+
+	/* Tell all device drivers that they can resume operations */
+	pci_walk_bus(frozen_bus, eeh_report_resume, 0);
+
+	return;
+	
+hard_fail:
+	/*
+	 * About 90% of all real-life EEH failures in the field
+	 * are due to poorly seated PCI cards. Only 10% or so are
+	 * due to actual, failed cards.
+	 */
+	printk(KERN_ERR
+	   "EEH: PCI device %s - %s has failed %d times \n"
+	   "and has been permanently disabled.  Please try reseating\n"
+	   "this device or replacing it.\n",
+		pci_name (frozen_pdn->pcidev), 
+		pcid_name(frozen_pdn->pcidev), 
+		frozen_pdn->eeh_freeze_count);
+
+	eeh_slot_error_detail(frozen_pdn, 2 /* Permanent Error */);
+
+	/* Notify all devices that they're about to go down. */
+	pci_walk_bus(frozen_bus, eeh_report_failure, 0);
+
+	/* Shut down the device drivers for good. */
+	pcibios_remove_pci_devices(frozen_bus);
+}
+
+/* ---------- end of file ---------- */
diff --git a/arch/powerpc/platforms/pseries/eeh_event.c b/arch/powerpc/platforms/pseries/eeh_event.c
index 9249733..9a9961f 100644
--- a/arch/powerpc/platforms/pseries/eeh_event.c
+++ b/arch/powerpc/platforms/pseries/eeh_event.c
@@ -21,6 +21,7 @@
 #include <linux/list.h>
 #include <linux/pci.h>
 #include <asm/eeh_event.h>
+#include <asm/ppc-pci.h>
 
 /** Overview:
  *  EEH error states may be detected within exception handlers;
@@ -37,31 +38,6 @@
 DECLARE_WORK(eeh_event_wq, eeh_thread_launcher, NULL);
 
 /**
- * eeh_panic - call panic() for an eeh event that cannot be handled.
- * The philosophy of this routine is that it is better to panic and
- * halt the OS than it is to risk possible data corruption by
- * oblivious device drivers that don't know better.
- *
- * @dev pci device that had an eeh event
- * @reset_state current reset state of the device slot
- */
-static void eeh_panic(struct pci_dev *dev, int reset_state)
-{
-	/*
-	 * Since the panic_on_oops sysctl is used to halt the system
-	 * in light of potential corruption, we can use it here.
-	 */
-	if (panic_on_oops) {
-		panic("EEH: MMIO failure (%d) on device:%s\n", reset_state,
-		      pci_name(dev));
-	}
-	else {
-		printk(KERN_INFO "EEH: Ignored MMIO failure (%d) on device:%s\n",
-		       reset_state, pci_name(dev));
-	}
-}
-
-/**
  * eeh_event_handler - dispatch EEH events.  The detection of a frozen
  * slot can occur inside an interrupt, where it can be hard to do
  * anything about it.  The goal of this routine is to pull these
@@ -82,10 +58,16 @@
 
 		spin_lock_irqsave(&eeh_eventlist_lock, flags);
 		event = NULL;
+
+		/* Unqueue the event, get ready to process. */
 		if (!list_empty(&eeh_eventlist)) {
 			event = list_entry(eeh_eventlist.next, struct eeh_event, list);
 			list_del(&event->list);
 		}
+		
+		if (event)
+			eeh_mark_slot(event->dn, EEH_MODE_RECOVERING);
+
 		spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
 		if (event == NULL)
 			break;
@@ -93,8 +75,11 @@
 		printk(KERN_INFO "EEH: Detected PCI bus error on device %s\n",
 		       pci_name(event->dev));
 
-		eeh_panic (event->dev, event->state);
+		handle_eeh_events(event);
 
+		eeh_clear_slot(event->dn, EEH_MODE_RECOVERING);
+
+		pci_dev_put(event->dev);
 		kfree(event);
 	}
 
@@ -122,7 +107,7 @@
  */
 int eeh_send_failure_event (struct device_node *dn,
                             struct pci_dev *dev,
-                            int state,
+                            enum pci_channel_state state,
                             int time_unavail)
 {
 	unsigned long flags;
diff --git a/arch/powerpc/platforms/pseries/hvcserver.c b/arch/powerpc/platforms/pseries/hvcserver.c
index 4d58417..22bfb5c 100644
--- a/arch/powerpc/platforms/pseries/hvcserver.c
+++ b/arch/powerpc/platforms/pseries/hvcserver.c
@@ -40,7 +40,7 @@
  * functions aren't performance sensitive, so this conversion isn't an
  * issue.
  */
-int hvcs_convert(long to_convert)
+static int hvcs_convert(long to_convert)
 {
 	switch (to_convert) {
 		case H_Success:
@@ -91,7 +91,7 @@
 EXPORT_SYMBOL(hvcs_free_partner_info);
 
 /* Helper function for hvcs_get_partner_info */
-int hvcs_next_partner(uint32_t unit_address,
+static int hvcs_next_partner(uint32_t unit_address,
 		unsigned long last_p_partition_ID,
 		unsigned long last_p_unit_address, unsigned long *pi_buff)
 
diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c
index 169f914..48cfbfc 100644
--- a/arch/powerpc/platforms/pseries/iommu.c
+++ b/arch/powerpc/platforms/pseries/iommu.c
@@ -51,8 +51,6 @@
 
 #define DBG(fmt...)
 
-extern int is_python(struct device_node *);
-
 static void tce_build_pSeries(struct iommu_table *tbl, long index, 
 			      long npages, unsigned long uaddr, 
 			      enum dma_data_direction direction)
diff --git a/arch/powerpc/platforms/pseries/scanlog.c b/arch/powerpc/platforms/pseries/scanlog.c
index 2edc947..5064349 100644
--- a/arch/powerpc/platforms/pseries/scanlog.c
+++ b/arch/powerpc/platforms/pseries/scanlog.c
@@ -192,7 +192,7 @@
 	.release	= scanlog_release,
 };
 
-int __init scanlog_init(void)
+static int __init scanlog_init(void)
 {
 	struct proc_dir_entry *ent;
 
@@ -222,7 +222,7 @@
 	return 0;
 }
 
-void __exit scanlog_cleanup(void)
+static void __exit scanlog_cleanup(void)
 {
 	if (proc_ppc64_scan_log_dump) {
 		kfree(proc_ppc64_scan_log_dump->data);
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index 8903cf6..68b7f08 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -86,7 +86,7 @@
 
 struct mpic *pSeries_mpic;
 
-void pSeries_show_cpuinfo(struct seq_file *m)
+static void pSeries_show_cpuinfo(struct seq_file *m)
 {
 	struct device_node *root;
 	const char *model = "";
diff --git a/arch/powerpc/platforms/pseries/smp.c b/arch/powerpc/platforms/pseries/smp.c
index 25181c5..8e6b1ed 100644
--- a/arch/powerpc/platforms/pseries/smp.c
+++ b/arch/powerpc/platforms/pseries/smp.c
@@ -93,7 +93,7 @@
 	return cpu_status;
 }
 
-int pSeries_cpu_disable(void)
+static int pSeries_cpu_disable(void)
 {
 	int cpu = smp_processor_id();
 
@@ -109,7 +109,7 @@
 	return 0;
 }
 
-void pSeries_cpu_die(unsigned int cpu)
+static void pSeries_cpu_die(unsigned int cpu)
 {
 	int tries;
 	int cpu_status;
@@ -282,7 +282,7 @@
 	pcpu = get_hard_smp_processor_id(lcpu);
 
 	/* Fixup atomic count: it exited inside IRQ handler. */
-	paca[lcpu].__current->thread_info->preempt_count	= 0;
+	task_thread_info(paca[lcpu].__current)->preempt_count	= 0;
 
 	/* 
 	 * If the RTAS start-cpu token does not exist then presume the
diff --git a/arch/powerpc/platforms/pseries/xics.c b/arch/powerpc/platforms/pseries/xics.c
index 0c0cfa3..fd823c7 100644
--- a/arch/powerpc/platforms/pseries/xics.c
+++ b/arch/powerpc/platforms/pseries/xics.c
@@ -381,7 +381,7 @@
 
 #ifdef CONFIG_SMP
 
-irqreturn_t xics_ipi_action(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t xics_ipi_action(int irq, void *dev_id, struct pt_regs *regs)
 {
 	int cpu = smp_processor_id();
 
diff --git a/arch/powerpc/sysdev/Makefile b/arch/powerpc/sysdev/Makefile
index 14b9abd..0ae8413 100644
--- a/arch/powerpc/sysdev/Makefile
+++ b/arch/powerpc/sysdev/Makefile
@@ -6,4 +6,4 @@
 obj-$(CONFIG_40x)		+= dcr.o
 obj-$(CONFIG_U3_DART)		+= dart_iommu.o
 obj-$(CONFIG_MMIO_NVRAM)	+= mmio_nvram.o
-obj-$(CONFIG_83xx)		+= ipic.o
+obj-$(CONFIG_PPC_83xx)		+= ipic.o
diff --git a/arch/powerpc/sysdev/dart_iommu.c b/arch/powerpc/sysdev/dart_iommu.c
index e00b46b..977de9d 100644
--- a/arch/powerpc/sysdev/dart_iommu.c
+++ b/arch/powerpc/sysdev/dart_iommu.c
@@ -139,7 +139,6 @@
 
 		*(dp++) = DARTMAP_VALID | (rpn & DARTMAP_RPNMASK);
 
-		rpn++;
 		uaddr += DART_PAGE_SIZE;
 	}
 
diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index 22612ed..7d02fa2 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -311,7 +311,7 @@
 }
 #endif
 
-int xmon_core(struct pt_regs *regs, int fromipi)
+static int xmon_core(struct pt_regs *regs, int fromipi)
 {
 	int cmd = 0;
 	unsigned long msr;
@@ -528,7 +528,7 @@
 	return IRQ_HANDLED;
 }
 
-int xmon_bpt(struct pt_regs *regs)
+static int xmon_bpt(struct pt_regs *regs)
 {
 	struct bpt *bp;
 	unsigned long offset;
@@ -554,7 +554,7 @@
 	return 1;
 }
 
-int xmon_sstep(struct pt_regs *regs)
+static int xmon_sstep(struct pt_regs *regs)
 {
 	if (user_mode(regs))
 		return 0;
@@ -562,7 +562,7 @@
 	return 1;
 }
 
-int xmon_dabr_match(struct pt_regs *regs)
+static int xmon_dabr_match(struct pt_regs *regs)
 {
 	if ((regs->msr & (MSR_IR|MSR_PR|MSR_SF)) != (MSR_IR|MSR_SF))
 		return 0;
@@ -572,7 +572,7 @@
 	return 1;
 }
 
-int xmon_iabr_match(struct pt_regs *regs)
+static int xmon_iabr_match(struct pt_regs *regs)
 {
 	if ((regs->msr & (MSR_IR|MSR_PR|MSR_SF)) != (MSR_IR|MSR_SF))
 		return 0;
@@ -582,7 +582,7 @@
 	return 1;
 }
 
-int xmon_ipi(struct pt_regs *regs)
+static int xmon_ipi(struct pt_regs *regs)
 {
 #ifdef CONFIG_SMP
 	if (in_xmon && !cpu_isset(smp_processor_id(), cpus_in_xmon))
@@ -591,7 +591,7 @@
 	return 0;
 }
 
-int xmon_fault_handler(struct pt_regs *regs)
+static int xmon_fault_handler(struct pt_regs *regs)
 {
 	struct bpt *bp;
 	unsigned long offset;
diff --git a/arch/ppc/4xx_io/serial_sicc.c b/arch/ppc/4xx_io/serial_sicc.c
index 84d96b8..ebc4db8 100644
--- a/arch/ppc/4xx_io/serial_sicc.c
+++ b/arch/ppc/4xx_io/serial_sicc.c
@@ -47,6 +47,7 @@
 #include <linux/mm.h>
 #include <linux/slab.h>
 #include <linux/init.h>
+#include <linux/capability.h>
 #include <linux/circ_buf.h>
 #include <linux/serial.h>
 #include <linux/console.h>
diff --git a/arch/ppc/Kconfig b/arch/ppc/Kconfig
index e396f45..d658101 100644
--- a/arch/ppc/Kconfig
+++ b/arch/ppc/Kconfig
@@ -743,6 +743,10 @@
 	bool
 	default y if MPC834x_SYS
 
+config PPC_83xx
+	bool
+	default y if 83xx
+
 config CPM1
 	bool
 	depends on 8xx
diff --git a/arch/ppc/Makefile b/arch/ppc/Makefile
index e719a49..98e940b 100644
--- a/arch/ppc/Makefile
+++ b/arch/ppc/Makefile
@@ -128,10 +128,9 @@
 # Ensure this is binutils 2.12.1 (or 2.12.90.0.7) or later for altivec
 # instructions.
 # gcc-3.4 and binutils-2.14 are a fatal combination.
-GCC_VERSION	:= $(call cc-version)
 
 checkbin:
-	@if test "$(GCC_VERSION)" = "0304" ; then \
+	@if test "$(call cc-version)" = "0304" ; then \
 		if ! /bin/echo mftb 5 | $(AS) -v -mppc -many -o $(TOUT) >/dev/null 2>&1 ; then \
 			echo -n '*** ${VERSION}.${PATCHLEVEL} kernels no longer build '; \
 			echo 'correctly with gcc-3.4 and your version of binutils.'; \
diff --git a/arch/ppc/amiga/amiints.c b/arch/ppc/amiga/amiints.c
index 91195e2..5f35cf3 100644
--- a/arch/ppc/amiga/amiints.c
+++ b/arch/ppc/amiga/amiints.c
@@ -96,8 +96,8 @@
 		gayle.inten = GAYLE_IRQ_IDE;
 
 	/* turn off all interrupts... */
-	custom.intena = 0x7fff;
-	custom.intreq = 0x7fff;
+	amiga_custom.intena = 0x7fff;
+	amiga_custom.intreq = 0x7fff;
 
 #ifdef CONFIG_APUS
 	/* Clear any inter-CPU interrupt requests. Circumvents bug in
@@ -110,7 +110,7 @@
 	APUS_WRITE(APUS_IPL_EMU, IPLEMU_SETRESET | IPLEMU_IPLMASK);
 #endif
 	/* ... and enable the master interrupt bit */
-	custom.intena = IF_SETCLR | IF_INTEN;
+	amiga_custom.intena = IF_SETCLR | IF_INTEN;
 
 	cia_init_IRQ(&ciaa_base);
 	cia_init_IRQ(&ciab_base);
@@ -151,7 +151,7 @@
 	}
 
 	/* enable the interrupt */
-	custom.intena = IF_SETCLR | ami_intena_vals[irq];
+	amiga_custom.intena = IF_SETCLR | ami_intena_vals[irq];
 }
 
 void amiga_disable_irq(unsigned int irq)
@@ -177,7 +177,7 @@
 	}
 
 	/* disable the interrupt */
-	custom.intena = ami_intena_vals[irq];
+	amiga_custom.intena = ami_intena_vals[irq];
 }
 
 inline void amiga_do_irq(int irq, struct pt_regs *fp)
@@ -196,7 +196,7 @@
 
 	kstat_cpu(0).irqs[irq]++;
 
-	custom.intreq = ami_intena_vals[irq];
+	amiga_custom.intreq = ami_intena_vals[irq];
 
 	for (action = desc->action; action; action = action->next)
 		action->handler(irq, action->dev_id, fp);
@@ -208,40 +208,40 @@
 
 static void ami_int1(int irq, void *dev_id, struct pt_regs *fp)
 {
-	unsigned short ints = custom.intreqr & custom.intenar;
+	unsigned short ints = amiga_custom.intreqr & amiga_custom.intenar;
 
 	/* if serial transmit buffer empty, interrupt */
 	if (ints & IF_TBE) {
-		custom.intreq = IF_TBE;
+		amiga_custom.intreq = IF_TBE;
 		amiga_do_irq(IRQ_AMIGA_TBE, fp);
 	}
 
 	/* if floppy disk transfer complete, interrupt */
 	if (ints & IF_DSKBLK) {
-		custom.intreq = IF_DSKBLK;
+		amiga_custom.intreq = IF_DSKBLK;
 		amiga_do_irq(IRQ_AMIGA_DSKBLK, fp);
 	}
 
 	/* if software interrupt set, interrupt */
 	if (ints & IF_SOFT) {
-		custom.intreq = IF_SOFT;
+		amiga_custom.intreq = IF_SOFT;
 		amiga_do_irq(IRQ_AMIGA_SOFT, fp);
 	}
 }
 
 static void ami_int3(int irq, void *dev_id, struct pt_regs *fp)
 {
-	unsigned short ints = custom.intreqr & custom.intenar;
+	unsigned short ints = amiga_custom.intreqr & amiga_custom.intenar;
 
 	/* if a blitter interrupt */
 	if (ints & IF_BLIT) {
-		custom.intreq = IF_BLIT;
+		amiga_custom.intreq = IF_BLIT;
 		amiga_do_irq(IRQ_AMIGA_BLIT, fp);
 	}
 
 	/* if a copper interrupt */
 	if (ints & IF_COPER) {
-		custom.intreq = IF_COPER;
+		amiga_custom.intreq = IF_COPER;
 		amiga_do_irq(IRQ_AMIGA_COPPER, fp);
 	}
 
@@ -252,36 +252,36 @@
 
 static void ami_int4(int irq, void *dev_id, struct pt_regs *fp)
 {
-	unsigned short ints = custom.intreqr & custom.intenar;
+	unsigned short ints = amiga_custom.intreqr & amiga_custom.intenar;
 
 	/* if audio 0 interrupt */
 	if (ints & IF_AUD0) {
-		custom.intreq = IF_AUD0;
+		amiga_custom.intreq = IF_AUD0;
 		amiga_do_irq(IRQ_AMIGA_AUD0, fp);
 	}
 
 	/* if audio 1 interrupt */
 	if (ints & IF_AUD1) {
-		custom.intreq = IF_AUD1;
+		amiga_custom.intreq = IF_AUD1;
 		amiga_do_irq(IRQ_AMIGA_AUD1, fp);
 	}
 
 	/* if audio 2 interrupt */
 	if (ints & IF_AUD2) {
-		custom.intreq = IF_AUD2;
+		amiga_custom.intreq = IF_AUD2;
 		amiga_do_irq(IRQ_AMIGA_AUD2, fp);
 	}
 
 	/* if audio 3 interrupt */
 	if (ints & IF_AUD3) {
-		custom.intreq = IF_AUD3;
+		amiga_custom.intreq = IF_AUD3;
 		amiga_do_irq(IRQ_AMIGA_AUD3, fp);
 	}
 }
 
 static void ami_int5(int irq, void *dev_id, struct pt_regs *fp)
 {
-	unsigned short ints = custom.intreqr & custom.intenar;
+	unsigned short ints = amiga_custom.intreqr & amiga_custom.intenar;
 
 	/* if serial receive buffer full interrupt */
 	if (ints & IF_RBF) {
@@ -291,7 +291,7 @@
 
 	/* if a disk sync interrupt */
 	if (ints & IF_DSKSYN) {
-		custom.intreq = IF_DSKSYN;
+		amiga_custom.intreq = IF_DSKSYN;
 		amiga_do_irq(IRQ_AMIGA_DSKSYN, fp);
 	}
 }
diff --git a/arch/ppc/amiga/cia.c b/arch/ppc/amiga/cia.c
index ad96146..4431c58 100644
--- a/arch/ppc/amiga/cia.c
+++ b/arch/ppc/amiga/cia.c
@@ -66,7 +66,7 @@
 	else
 		base->icr_data &= ~mask;
 	if (base->icr_data & base->icr_mask)
-		custom.intreq = IF_SETCLR | base->int_mask;
+		amiga_custom.intreq = IF_SETCLR | base->int_mask;
 	return old & base->icr_mask;
 }
 
@@ -114,7 +114,7 @@
 	base->icr_mask &= CIA_ICR_ALL;
 
 	if (base->icr_data & base->icr_mask)
-		custom.intreq = IF_SETCLR | base->int_mask;
+		amiga_custom.intreq = IF_SETCLR | base->int_mask;
 	return old;
 }
 
@@ -145,7 +145,7 @@
 	irq = base->cia_irq;
 	desc = irq_desc + irq;
 	ints = cia_set_irq_private(base, CIA_ICR_ALL);
-	custom.intreq = base->int_mask;
+	amiga_custom.intreq = base->int_mask;
 	for (i = 0; i < CIA_IRQS; i++, irq++) {
 		if (ints & 1) {
 			kstat_cpu(0).irqs[irq]++;
@@ -174,5 +174,5 @@
 	action->name = base->name;
 	setup_irq(base->handler_irq, &amiga_sys_irqaction[base->handler_irq-IRQ_AMIGA_AUTO]);
 
-	custom.intena = IF_SETCLR | base->int_mask;
+	amiga_custom.intena = IF_SETCLR | base->int_mask;
 }
diff --git a/arch/ppc/amiga/config.c b/arch/ppc/amiga/config.c
index af881d7..60e2da1 100644
--- a/arch/ppc/amiga/config.c
+++ b/arch/ppc/amiga/config.c
@@ -90,9 +90,6 @@
 static void a2000_gettod (int *, int *, int *, int *, int *, int *);
 static int amiga_hwclk (int, struct hwclk_time *);
 static int amiga_set_clock_mmss (unsigned long);
-#ifdef CONFIG_AMIGA_FLOPPY
-extern void amiga_floppy_setup(char *, int *);
-#endif
 static void amiga_reset (void);
 extern void amiga_init_sound(void);
 static void amiga_savekmsg_init(void);
@@ -281,7 +278,7 @@
     case CS_OCS:
     case CS_ECS:
     case CS_AGA:
-      switch (custom.deniseid & 0xf) {
+      switch (amiga_custom.deniseid & 0xf) {
       case 0x0c:
 	AMIGAHW_SET(DENISE_HR);
 	break;
@@ -294,7 +291,7 @@
       AMIGAHW_SET(DENISE);
       break;
     }
-    switch ((custom.vposr>>8) & 0x7f) {
+    switch ((amiga_custom.vposr>>8) & 0x7f) {
     case 0x00:
       AMIGAHW_SET(AGNUS_PAL);
       break;
@@ -419,9 +416,6 @@
 
   mach_hwclk           = amiga_hwclk;
   mach_set_clock_mmss  = amiga_set_clock_mmss;
-#ifdef CONFIG_AMIGA_FLOPPY
-  mach_floppy_setup    = amiga_floppy_setup;
-#endif
   mach_reset           = amiga_reset;
 #ifdef CONFIG_HEARTBEAT
   mach_heartbeat = amiga_heartbeat;
@@ -432,9 +426,9 @@
   amiga_colorclock = 5*amiga_eclock;	/* 3.5 MHz */
 
   /* clear all DMA bits */
-  custom.dmacon = DMAF_ALL;
+  amiga_custom.dmacon = DMAF_ALL;
   /* ensure that the DMA master bit is set */
-  custom.dmacon = DMAF_SETCLR | DMAF_MASTER;
+  amiga_custom.dmacon = DMAF_SETCLR | DMAF_MASTER;
 
   /* request all RAM */
   for (i = 0; i < m68k_num_memory; i++) {
@@ -753,9 +747,9 @@
 
 static void amiga_serial_putc(char c)
 {
-    custom.serdat = (unsigned char)c | 0x100;
+    amiga_custom.serdat = (unsigned char)c | 0x100;
     mb();
-    while (!(custom.serdatr & 0x2000))
+    while (!(amiga_custom.serdatr & 0x2000))
        ;
 }
 
@@ -785,11 +779,11 @@
 {
     int ch;
 
-    while (!(custom.intreqr & IF_RBF))
+    while (!(amiga_custom.intreqr & IF_RBF))
 	barrier();
-    ch = custom.serdatr & 0xff;
+    ch = amiga_custom.serdatr & 0xff;
     /* clear the interrupt, so that another character can be read */
-    custom.intreq = IF_RBF;
+    amiga_custom.intreq = IF_RBF;
     return ch;
 }
 
diff --git a/arch/ppc/kernel/Makefile b/arch/ppc/kernel/Makefile
index e6c1d615..ca02013 100644
--- a/arch/ppc/kernel/Makefile
+++ b/arch/ppc/kernel/Makefile
@@ -13,7 +13,6 @@
 extra-y				+= vmlinux.lds
 
 obj-y				:= entry.o traps.o idle.o time.o misc.o \
-					process.o \
 					setup.o \
 					ppc_htab.o
 obj-$(CONFIG_6xx)		+= l2cr.o cpu_setup_6xx.o
diff --git a/arch/ppc/kernel/machine_kexec.c b/arch/ppc/kernel/machine_kexec.c
index a882b0d..84d65a8 100644
--- a/arch/ppc/kernel/machine_kexec.c
+++ b/arch/ppc/kernel/machine_kexec.c
@@ -28,12 +28,6 @@
 const extern unsigned char relocate_new_kernel[];
 const extern unsigned int relocate_new_kernel_size;
 
-/*
- * Provide a dummy crash_notes definition while crash dump arrives to ppc.
- * This prevents breakage of crash_notes attribute in kernel/ksysfs.c.
- */
-note_buf_t crash_notes[NR_CPUS];
-
 void machine_shutdown(void)
 {
 	if (ppc_md.machine_shutdown)
diff --git a/arch/ppc/kernel/ppc_htab.c b/arch/ppc/kernel/ppc_htab.c
index ca81002..2f5c765 100644
--- a/arch/ppc/kernel/ppc_htab.c
+++ b/arch/ppc/kernel/ppc_htab.c
@@ -16,6 +16,7 @@
 #include <linux/proc_fs.h>
 #include <linux/stat.h>
 #include <linux/sysctl.h>
+#include <linux/capability.h>
 #include <linux/ctype.h>
 #include <linux/threads.h>
 #include <linux/smp_lock.h>
diff --git a/arch/ppc/kernel/process.c b/arch/ppc/kernel/process.c
deleted file mode 100644
index 25cbdc8..0000000
--- a/arch/ppc/kernel/process.c
+++ /dev/null
@@ -1,851 +0,0 @@
-/*
- *  arch/ppc/kernel/process.c
- *
- *  Derived from "arch/i386/kernel/process.c"
- *    Copyright (C) 1995  Linus Torvalds
- *
- *  Updated and modified by Cort Dougan (cort@cs.nmt.edu) and
- *  Paul Mackerras (paulus@cs.anu.edu.au)
- *
- *  PowerPC version
- *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
- *
- *  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.
- *
- */
-
-#include <linux/config.h>
-#include <linux/errno.h>
-#include <linux/sched.h>
-#include <linux/kernel.h>
-#include <linux/mm.h>
-#include <linux/smp.h>
-#include <linux/smp_lock.h>
-#include <linux/stddef.h>
-#include <linux/unistd.h>
-#include <linux/ptrace.h>
-#include <linux/slab.h>
-#include <linux/user.h>
-#include <linux/elf.h>
-#include <linux/init.h>
-#include <linux/prctl.h>
-#include <linux/init_task.h>
-#include <linux/module.h>
-#include <linux/kallsyms.h>
-#include <linux/mqueue.h>
-#include <linux/hardirq.h>
-
-#include <asm/pgtable.h>
-#include <asm/uaccess.h>
-#include <asm/system.h>
-#include <asm/io.h>
-#include <asm/processor.h>
-#include <asm/mmu.h>
-#include <asm/prom.h>
-
-extern unsigned long _get_SP(void);
-
-struct task_struct *last_task_used_math = NULL;
-struct task_struct *last_task_used_altivec = NULL;
-struct task_struct *last_task_used_spe = NULL;
-
-static struct fs_struct init_fs = INIT_FS;
-static struct files_struct init_files = INIT_FILES;
-static struct signal_struct init_signals = INIT_SIGNALS(init_signals);
-static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
-struct mm_struct init_mm = INIT_MM(init_mm);
-EXPORT_SYMBOL(init_mm);
-
-/* this is 8kB-aligned so we can get to the thread_info struct
-   at the base of it from the stack pointer with 1 integer instruction. */
-union thread_union init_thread_union
-	__attribute__((__section__(".data.init_task"))) =
-{ INIT_THREAD_INFO(init_task) };
-
-/* initial task structure */
-struct task_struct init_task = INIT_TASK(init_task);
-EXPORT_SYMBOL(init_task);
-
-/* only used to get secondary processor up */
-struct task_struct *current_set[NR_CPUS] = {&init_task, };
-
-#undef SHOW_TASK_SWITCHES
-#undef CHECK_STACK
-
-#if defined(CHECK_STACK)
-unsigned long
-kernel_stack_top(struct task_struct *tsk)
-{
-	return ((unsigned long)tsk) + sizeof(union task_union);
-}
-
-unsigned long
-task_top(struct task_struct *tsk)
-{
-	return ((unsigned long)tsk) + sizeof(struct thread_info);
-}
-
-/* check to make sure the kernel stack is healthy */
-int check_stack(struct task_struct *tsk)
-{
-	unsigned long stack_top = kernel_stack_top(tsk);
-	unsigned long tsk_top = task_top(tsk);
-	int ret = 0;
-
-#if 0
-	/* check thread magic */
-	if ( tsk->thread.magic != THREAD_MAGIC )
-	{
-		ret |= 1;
-		printk("thread.magic bad: %08x\n", tsk->thread.magic);
-	}
-#endif
-
-	if ( !tsk )
-		printk("check_stack(): tsk bad tsk %p\n",tsk);
-
-	/* check if stored ksp is bad */
-	if ( (tsk->thread.ksp > stack_top) || (tsk->thread.ksp < tsk_top) )
-	{
-		printk("stack out of bounds: %s/%d\n"
-		       " tsk_top %08lx ksp %08lx stack_top %08lx\n",
-		       tsk->comm,tsk->pid,
-		       tsk_top, tsk->thread.ksp, stack_top);
-		ret |= 2;
-	}
-
-	/* check if stack ptr RIGHT NOW is bad */
-	if ( (tsk == current) && ((_get_SP() > stack_top ) || (_get_SP() < tsk_top)) )
-	{
-		printk("current stack ptr out of bounds: %s/%d\n"
-		       " tsk_top %08lx sp %08lx stack_top %08lx\n",
-		       current->comm,current->pid,
-		       tsk_top, _get_SP(), stack_top);
-		ret |= 4;
-	}
-
-#if 0
-	/* check amount of free stack */
-	for ( i = (unsigned long *)task_top(tsk) ; i < kernel_stack_top(tsk) ; i++ )
-	{
-		if ( !i )
-			printk("check_stack(): i = %p\n", i);
-		if ( *i != 0 )
-		{
-			/* only notify if it's less than 900 bytes */
-			if ( (i - (unsigned long *)task_top(tsk))  < 900 )
-				printk("%d bytes free on stack\n",
-				       i - task_top(tsk));
-			break;
-		}
-	}
-#endif
-
-	if (ret)
-	{
-		panic("bad kernel stack");
-	}
-	return(ret);
-}
-#endif /* defined(CHECK_STACK) */
-
-/*
- * Make sure the floating-point register state in the
- * the thread_struct is up to date for task tsk.
- */
-void flush_fp_to_thread(struct task_struct *tsk)
-{
-	if (tsk->thread.regs) {
-		/*
-		 * We need to disable preemption here because if we didn't,
-		 * another process could get scheduled after the regs->msr
-		 * test but before we have finished saving the FP registers
-		 * to the thread_struct.  That process could take over the
-		 * FPU, and then when we get scheduled again we would store
-		 * bogus values for the remaining FP registers.
-		 */
-		preempt_disable();
-		if (tsk->thread.regs->msr & MSR_FP) {
-#ifdef CONFIG_SMP
-			/*
-			 * This should only ever be called for current or
-			 * for a stopped child process.  Since we save away
-			 * the FP register state on context switch on SMP,
-			 * there is something wrong if a stopped child appears
-			 * to still have its FP state in the CPU registers.
-			 */
-			BUG_ON(tsk != current);
-#endif
-			giveup_fpu(current);
-		}
-		preempt_enable();
-	}
-}
-
-void enable_kernel_fp(void)
-{
-	WARN_ON(preemptible());
-
-#ifdef CONFIG_SMP
-	if (current->thread.regs && (current->thread.regs->msr & MSR_FP))
-		giveup_fpu(current);
-	else
-		giveup_fpu(NULL);	/* just enables FP for kernel */
-#else
-	giveup_fpu(last_task_used_math);
-#endif /* CONFIG_SMP */
-}
-EXPORT_SYMBOL(enable_kernel_fp);
-
-int dump_task_fpu(struct task_struct *tsk, elf_fpregset_t *fpregs)
-{
-	preempt_disable();
-	if (tsk->thread.regs && (tsk->thread.regs->msr & MSR_FP))
-		giveup_fpu(tsk);
-	preempt_enable();
-	memcpy(fpregs, &tsk->thread.fpr[0], sizeof(*fpregs));
-	return 1;
-}
-
-#ifdef CONFIG_ALTIVEC
-void enable_kernel_altivec(void)
-{
-	WARN_ON(preemptible());
-
-#ifdef CONFIG_SMP
-	if (current->thread.regs && (current->thread.regs->msr & MSR_VEC))
-		giveup_altivec(current);
-	else
-		giveup_altivec(NULL);	/* just enable AltiVec for kernel - force */
-#else
-	giveup_altivec(last_task_used_altivec);
-#endif /* __SMP __ */
-}
-EXPORT_SYMBOL(enable_kernel_altivec);
-
-/*
- * Make sure the VMX/Altivec register state in the
- * the thread_struct is up to date for task tsk.
- */
-void flush_altivec_to_thread(struct task_struct *tsk)
-{
-	if (tsk->thread.regs) {
-		preempt_disable();
-		if (tsk->thread.regs->msr & MSR_VEC) {
-#ifdef CONFIG_SMP
-			BUG_ON(tsk != current);
-#endif
-			giveup_altivec(current);
-		}
-		preempt_enable();
-	}
-}
-
-int dump_altivec(struct pt_regs *regs, elf_vrregset_t *vrregs)
-{
-	if (regs->msr & MSR_VEC)
-		giveup_altivec(current);
-	memcpy(vrregs, &current->thread.vr[0], sizeof(*vrregs));
-	return 1;
-}
-#endif /* CONFIG_ALTIVEC */
-
-#ifdef CONFIG_SPE
-void
-enable_kernel_spe(void)
-{
-	WARN_ON(preemptible());
-
-#ifdef CONFIG_SMP
-	if (current->thread.regs && (current->thread.regs->msr & MSR_SPE))
-		giveup_spe(current);
-	else
-		giveup_spe(NULL);	/* just enable SPE for kernel - force */
-#else
-	giveup_spe(last_task_used_spe);
-#endif /* __SMP __ */
-}
-EXPORT_SYMBOL(enable_kernel_spe);
-
-void flush_spe_to_thread(struct task_struct *tsk)
-{
-	if (tsk->thread.regs) {
-		preempt_disable();
-		if (tsk->thread.regs->msr & MSR_SPE) {
-#ifdef CONFIG_SMP
-			BUG_ON(tsk != current);
-#endif
-			giveup_spe(current);
-		}
-		preempt_enable();
-	}
-}
-
-int dump_spe(struct pt_regs *regs, elf_vrregset_t *evrregs)
-{
-	if (regs->msr & MSR_SPE)
-		giveup_spe(current);
-	/* We copy u32 evr[32] + u64 acc + u32 spefscr -> 35 */
-	memcpy(evrregs, &current->thread.evr[0], sizeof(u32) * 35);
-	return 1;
-}
-#endif /* CONFIG_SPE */
-
-struct task_struct *__switch_to(struct task_struct *prev,
-	struct task_struct *new)
-{
-	struct thread_struct *new_thread, *old_thread;
-	unsigned long s;
-	struct task_struct *last;
-
-	local_irq_save(s);
-#ifdef CHECK_STACK
-	check_stack(prev);
-	check_stack(new);
-#endif
-
-#ifdef CONFIG_SMP
-	/* avoid complexity of lazy save/restore of fpu
-	 * by just saving it every time we switch out if
-	 * this task used the fpu during the last quantum.
-	 *
-	 * If it tries to use the fpu again, it'll trap and
-	 * reload its fp regs.  So we don't have to do a restore
-	 * every switch, just a save.
-	 *  -- Cort
-	 */
-	if (prev->thread.regs && (prev->thread.regs->msr & MSR_FP))
-		giveup_fpu(prev);
-#ifdef CONFIG_ALTIVEC
-	/*
-	 * If the previous thread used altivec in the last quantum
-	 * (thus changing altivec regs) then save them.
-	 * We used to check the VRSAVE register but not all apps
-	 * set it, so we don't rely on it now (and in fact we need
-	 * to save & restore VSCR even if VRSAVE == 0).  -- paulus
-	 *
-	 * On SMP we always save/restore altivec regs just to avoid the
-	 * complexity of changing processors.
-	 *  -- Cort
-	 */
-	if ((prev->thread.regs && (prev->thread.regs->msr & MSR_VEC)))
-		giveup_altivec(prev);
-#endif /* CONFIG_ALTIVEC */
-#ifdef CONFIG_SPE
-	/*
-	 * If the previous thread used spe in the last quantum
-	 * (thus changing spe regs) then save them.
-	 *
-	 * On SMP we always save/restore spe regs just to avoid the
-	 * complexity of changing processors.
-	 */
-	if ((prev->thread.regs && (prev->thread.regs->msr & MSR_SPE)))
-		giveup_spe(prev);
-#endif /* CONFIG_SPE */
-#endif /* CONFIG_SMP */
-
-#ifdef CONFIG_ALTIVEC
-	/* Avoid the trap.  On smp this this never happens since
-	 * we don't set last_task_used_altivec -- Cort
-	 */
-	if (new->thread.regs && last_task_used_altivec == new)
-		new->thread.regs->msr |= MSR_VEC;
-#endif
-#ifdef CONFIG_SPE
-	/* Avoid the trap.  On smp this this never happens since
-	 * we don't set last_task_used_spe
-	 */
-	if (new->thread.regs && last_task_used_spe == new)
-		new->thread.regs->msr |= MSR_SPE;
-#endif /* CONFIG_SPE */
-	new_thread = &new->thread;
-	old_thread = &current->thread;
-	last = _switch(old_thread, new_thread);
-	local_irq_restore(s);
-	return last;
-}
-
-void show_regs(struct pt_regs * regs)
-{
-	int i, trap;
-
-	printk("NIP: %08lX LR: %08lX SP: %08lX REGS: %p TRAP: %04lx    %s\n",
-	       regs->nip, regs->link, regs->gpr[1], regs, regs->trap,
-	       print_tainted());
-	printk("MSR: %08lx EE: %01x PR: %01x FP: %01x ME: %01x IR/DR: %01x%01x\n",
-	       regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
-	       regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
-	       regs->msr&MSR_IR ? 1 : 0,
-	       regs->msr&MSR_DR ? 1 : 0);
-	trap = TRAP(regs);
-	if (trap == 0x300 || trap == 0x600)
-		printk("DAR: %08lX, DSISR: %08lX\n", regs->dar, regs->dsisr);
-	printk("TASK = %p[%d] '%s' THREAD: %p\n",
-	       current, current->pid, current->comm, current->thread_info);
-	printk("Last syscall: %ld ", current->thread.last_syscall);
-
-#ifdef CONFIG_SMP
-	printk(" CPU: %d", smp_processor_id());
-#endif /* CONFIG_SMP */
-
-	for (i = 0;  i < 32;  i++) {
-		long r;
-		if ((i % 8) == 0)
-			printk("\n" KERN_INFO "GPR%02d: ", i);
-		if (__get_user(r, &regs->gpr[i]))
-			break;
-		printk("%08lX ", r);
-		if (i == 12 && !FULL_REGS(regs))
-			break;
-	}
-	printk("\n");
-#ifdef CONFIG_KALLSYMS
-	/*
-	 * Lookup NIP late so we have the best change of getting the
-	 * above info out without failing
-	 */
-	printk("NIP [%08lx] ", regs->nip);
-	print_symbol("%s\n", regs->nip);
-	printk("LR [%08lx] ", regs->link);
-	print_symbol("%s\n", regs->link);
-#endif
-	show_stack(current, (unsigned long *) regs->gpr[1]);
-}
-
-void exit_thread(void)
-{
-	preempt_disable();
-	if (last_task_used_math == current)
-		last_task_used_math = NULL;
-	if (last_task_used_altivec == current)
-		last_task_used_altivec = NULL;
-#ifdef CONFIG_SPE
-	if (last_task_used_spe == current)
-		last_task_used_spe = NULL;
-#endif
-	preempt_enable();
-}
-
-void flush_thread(void)
-{
-	preempt_disable();
-	if (last_task_used_math == current)
-		last_task_used_math = NULL;
-	if (last_task_used_altivec == current)
-		last_task_used_altivec = NULL;
-#ifdef CONFIG_SPE
-	if (last_task_used_spe == current)
-		last_task_used_spe = NULL;
-#endif
-	preempt_enable();
-}
-
-void
-release_thread(struct task_struct *t)
-{
-}
-
-/*
- * This gets called before we allocate a new thread and copy
- * the current task into it.
- */
-void prepare_to_copy(struct task_struct *tsk)
-{
-	struct pt_regs *regs = tsk->thread.regs;
-
-	if (regs == NULL)
-		return;
-	preempt_disable();
-	if (regs->msr & MSR_FP)
-		giveup_fpu(current);
-#ifdef CONFIG_ALTIVEC
-	if (regs->msr & MSR_VEC)
-		giveup_altivec(current);
-#endif /* CONFIG_ALTIVEC */
-#ifdef CONFIG_SPE
-	if (regs->msr & MSR_SPE)
-		giveup_spe(current);
-#endif /* CONFIG_SPE */
-	preempt_enable();
-}
-
-/*
- * Copy a thread..
- */
-int
-copy_thread(int nr, unsigned long clone_flags, unsigned long usp,
-	    unsigned long unused,
-	    struct task_struct *p, struct pt_regs *regs)
-{
-	struct pt_regs *childregs, *kregs;
-	extern void ret_from_fork(void);
-	unsigned long sp = (unsigned long)p->thread_info + THREAD_SIZE;
-	unsigned long childframe;
-
-	CHECK_FULL_REGS(regs);
-	/* Copy registers */
-	sp -= sizeof(struct pt_regs);
-	childregs = (struct pt_regs *) sp;
-	*childregs = *regs;
-	if ((childregs->msr & MSR_PR) == 0) {
-		/* for kernel thread, set `current' and stackptr in new task */
-		childregs->gpr[1] = sp + sizeof(struct pt_regs);
-		childregs->gpr[2] = (unsigned long) p;
-		p->thread.regs = NULL;	/* no user register state */
-	} else {
-		childregs->gpr[1] = usp;
-		p->thread.regs = childregs;
-		if (clone_flags & CLONE_SETTLS)
-			childregs->gpr[2] = childregs->gpr[6];
-	}
-	childregs->gpr[3] = 0;  /* Result from fork() */
-	sp -= STACK_FRAME_OVERHEAD;
-	childframe = sp;
-
-	/*
-	 * The way this works is that at some point in the future
-	 * some task will call _switch to switch to the new task.
-	 * That will pop off the stack frame created below and start
-	 * the new task running at ret_from_fork.  The new task will
-	 * do some house keeping and then return from the fork or clone
-	 * system call, using the stack frame created above.
-	 */
-	sp -= sizeof(struct pt_regs);
-	kregs = (struct pt_regs *) sp;
-	sp -= STACK_FRAME_OVERHEAD;
-	p->thread.ksp = sp;
-	kregs->nip = (unsigned long)ret_from_fork;
-
-	p->thread.last_syscall = -1;
-
-	return 0;
-}
-
-/*
- * Set up a thread for executing a new program
- */
-void start_thread(struct pt_regs *regs, unsigned long nip, unsigned long sp)
-{
-	set_fs(USER_DS);
-	memset(regs->gpr, 0, sizeof(regs->gpr));
-	regs->ctr = 0;
-	regs->link = 0;
-	regs->xer = 0;
-	regs->ccr = 0;
-	regs->mq = 0;
-	regs->nip = nip;
-	regs->gpr[1] = sp;
-	regs->msr = MSR_USER;
-	preempt_disable();
-	if (last_task_used_math == current)
-		last_task_used_math = NULL;
-	if (last_task_used_altivec == current)
-		last_task_used_altivec = NULL;
-#ifdef CONFIG_SPE
-	if (last_task_used_spe == current)
-		last_task_used_spe = NULL;
-#endif
-	preempt_enable();
-	memset(current->thread.fpr, 0, sizeof(current->thread.fpr));
-	current->thread.fpscr.val = 0;
-#ifdef CONFIG_ALTIVEC
-	memset(current->thread.vr, 0, sizeof(current->thread.vr));
-	memset(&current->thread.vscr, 0, sizeof(current->thread.vscr));
-	current->thread.vrsave = 0;
-	current->thread.used_vr = 0;
-#endif /* CONFIG_ALTIVEC */
-#ifdef CONFIG_SPE
-	memset(current->thread.evr, 0, sizeof(current->thread.evr));
-	current->thread.acc = 0;
-	current->thread.spefscr = 0;
-	current->thread.used_spe = 0;
-#endif /* CONFIG_SPE */
-}
-
-#define PR_FP_ALL_EXCEPT (PR_FP_EXC_DIV | PR_FP_EXC_OVF | PR_FP_EXC_UND \
-		| PR_FP_EXC_RES | PR_FP_EXC_INV)
-
-int set_fpexc_mode(struct task_struct *tsk, unsigned int val)
-{
-	struct pt_regs *regs = tsk->thread.regs;
-
-	/* This is a bit hairy.  If we are an SPE enabled  processor
-	 * (have embedded fp) we store the IEEE exception enable flags in
-	 * fpexc_mode.  fpexc_mode is also used for setting FP exception
-	 * mode (asyn, precise, disabled) for 'Classic' FP. */
-	if (val & PR_FP_EXC_SW_ENABLE) {
-#ifdef CONFIG_SPE
-		tsk->thread.fpexc_mode = val &
-			(PR_FP_EXC_SW_ENABLE | PR_FP_ALL_EXCEPT);
-#else
-		return -EINVAL;
-#endif
-	} else {
-		/* on a CONFIG_SPE this does not hurt us.  The bits that
-		 * __pack_fe01 use do not overlap with bits used for
-		 * PR_FP_EXC_SW_ENABLE.  Additionally, the MSR[FE0,FE1] bits
-		 * on CONFIG_SPE implementations are reserved so writing to
-		 * them does not change anything */
-		if (val > PR_FP_EXC_PRECISE)
-			return -EINVAL;
-		tsk->thread.fpexc_mode = __pack_fe01(val);
-		if (regs != NULL && (regs->msr & MSR_FP) != 0)
-			regs->msr = (regs->msr & ~(MSR_FE0|MSR_FE1))
-				| tsk->thread.fpexc_mode;
-	}
-	return 0;
-}
-
-int get_fpexc_mode(struct task_struct *tsk, unsigned long adr)
-{
-	unsigned int val;
-
-	if (tsk->thread.fpexc_mode & PR_FP_EXC_SW_ENABLE)
-#ifdef CONFIG_SPE
-		val = tsk->thread.fpexc_mode;
-#else
-		return -EINVAL;
-#endif
-	else
-		val = __unpack_fe01(tsk->thread.fpexc_mode);
-	return put_user(val, (unsigned int __user *) adr);
-}
-
-int sys_clone(unsigned long clone_flags, unsigned long usp,
-	      int __user *parent_tidp, void __user *child_threadptr,
-	      int __user *child_tidp, int p6,
-	      struct pt_regs *regs)
-{
-	CHECK_FULL_REGS(regs);
-	if (usp == 0)
-		usp = regs->gpr[1];	/* stack pointer for child */
- 	return do_fork(clone_flags, usp, regs, 0, parent_tidp, child_tidp);
-}
-
-int sys_fork(unsigned long p1, unsigned long p2, unsigned long p3,
-	     unsigned long p4, unsigned long p5, unsigned long p6,
-	     struct pt_regs *regs)
-{
-	CHECK_FULL_REGS(regs);
-	return do_fork(SIGCHLD, regs->gpr[1], regs, 0, NULL, NULL);
-}
-
-int sys_vfork(unsigned long p1, unsigned long p2, unsigned long p3,
-	      unsigned long p4, unsigned long p5, unsigned long p6,
-	      struct pt_regs *regs)
-{
-	CHECK_FULL_REGS(regs);
-	return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->gpr[1],
-			regs, 0, NULL, NULL);
-}
-
-int sys_execve(unsigned long a0, unsigned long a1, unsigned long a2,
-	       unsigned long a3, unsigned long a4, unsigned long a5,
-	       struct pt_regs *regs)
-{
-	int error;
-	char * filename;
-
-	filename = getname((char __user *) a0);
-	error = PTR_ERR(filename);
-	if (IS_ERR(filename))
-		goto out;
-	preempt_disable();
-	if (regs->msr & MSR_FP)
-		giveup_fpu(current);
-#ifdef CONFIG_ALTIVEC
-	if (regs->msr & MSR_VEC)
-		giveup_altivec(current);
-#endif /* CONFIG_ALTIVEC */
-#ifdef CONFIG_SPE
-	if (regs->msr & MSR_SPE)
-		giveup_spe(current);
-#endif /* CONFIG_SPE */
-	preempt_enable();
-	error = do_execve(filename, (char __user *__user *) a1,
-			  (char __user *__user *) a2, regs);
-	if (error == 0) {
-		task_lock(current);
-		current->ptrace &= ~PT_DTRACE;
-		task_unlock(current);
-	}
-	putname(filename);
-out:
-	return error;
-}
-
-void dump_stack(void)
-{
-	show_stack(current, NULL);
-}
-
-EXPORT_SYMBOL(dump_stack);
-
-void show_stack(struct task_struct *tsk, unsigned long *stack)
-{
-	unsigned long sp, stack_top, prev_sp, ret;
-	int count = 0;
-	unsigned long next_exc = 0;
-	struct pt_regs *regs;
-	extern char ret_from_except, ret_from_except_full, ret_from_syscall;
-
-	sp = (unsigned long) stack;
-	if (tsk == NULL)
-		tsk = current;
-	if (sp == 0) {
-		if (tsk == current)
-			asm("mr %0,1" : "=r" (sp));
-		else
-			sp = tsk->thread.ksp;
-	}
-
-	prev_sp = (unsigned long) (tsk->thread_info + 1);
-	stack_top = (unsigned long) tsk->thread_info + THREAD_SIZE;
-	while (count < 16 && sp > prev_sp && sp < stack_top && (sp & 3) == 0) {
-		if (count == 0) {
-			printk("Call trace:");
-#ifdef CONFIG_KALLSYMS
-			printk("\n");
-#endif
-		} else {
-			if (next_exc) {
-				ret = next_exc;
-				next_exc = 0;
-			} else
-				ret = *(unsigned long *)(sp + 4);
-			printk(" [%08lx] ", ret);
-#ifdef CONFIG_KALLSYMS
-			print_symbol("%s", ret);
-			printk("\n");
-#endif
-			if (ret == (unsigned long) &ret_from_except
-			    || ret == (unsigned long) &ret_from_except_full
-			    || ret == (unsigned long) &ret_from_syscall) {
-				/* sp + 16 points to an exception frame */
-				regs = (struct pt_regs *) (sp + 16);
-				if (sp + 16 + sizeof(*regs) <= stack_top)
-					next_exc = regs->nip;
-			}
-		}
-		++count;
-		sp = *(unsigned long *)sp;
-	}
-#ifndef CONFIG_KALLSYMS
-	if (count > 0)
-		printk("\n");
-#endif
-}
-
-#if 0
-/*
- * Low level print for debugging - Cort
- */
-int __init ll_printk(const char *fmt, ...)
-{
-        va_list args;
-	char buf[256];
-        int i;
-
-        va_start(args, fmt);
-        i=vsprintf(buf,fmt,args);
-	ll_puts(buf);
-        va_end(args);
-        return i;
-}
-
-int lines = 24, cols = 80;
-int orig_x = 0, orig_y = 0;
-
-void puthex(unsigned long val)
-{
-	unsigned char buf[10];
-	int i;
-	for (i = 7;  i >= 0;  i--)
-	{
-		buf[i] = "0123456789ABCDEF"[val & 0x0F];
-		val >>= 4;
-	}
-	buf[8] = '\0';
-	prom_print(buf);
-}
-
-void __init ll_puts(const char *s)
-{
-	int x,y;
-	char *vidmem = (char *)/*(_ISA_MEM_BASE + 0xB8000) */0xD00B8000;
-	char c;
-	extern int mem_init_done;
-
-	if ( mem_init_done ) /* assume this means we can printk */
-	{
-		printk(s);
-		return;
-	}
-
-#if 0
-	if ( have_of )
-	{
-		prom_print(s);
-		return;
-	}
-#endif
-
-	/*
-	 * can't ll_puts on chrp without openfirmware yet.
-	 * vidmem just needs to be setup for it.
-	 * -- Cort
-	 */
-	if ( _machine != _MACH_prep )
-		return;
-	x = orig_x;
-	y = orig_y;
-
-	while ( ( c = *s++ ) != '\0' ) {
-		if ( c == '\n' ) {
-			x = 0;
-			if ( ++y >= lines ) {
-				/*scroll();*/
-				/*y--;*/
-				y = 0;
-			}
-		} else {
-			vidmem [ ( x + cols * y ) * 2 ] = c;
-			if ( ++x >= cols ) {
-				x = 0;
-				if ( ++y >= lines ) {
-					/*scroll();*/
-					/*y--;*/
-					y = 0;
-				}
-			}
-		}
-	}
-
-	orig_x = x;
-	orig_y = y;
-}
-#endif
-
-unsigned long get_wchan(struct task_struct *p)
-{
-	unsigned long ip, sp;
-	unsigned long stack_page = (unsigned long) p->thread_info;
-	int count = 0;
-	if (!p || p == current || p->state == TASK_RUNNING)
-		return 0;
-	sp = p->thread.ksp;
-	do {
-		sp = *(unsigned long *)sp;
-		if (sp < stack_page || sp >= stack_page + 8188)
-			return 0;
-		if (count > 0) {
-			ip = *(unsigned long *)(sp + 4);
-			if (!in_sched_functions(ip))
-				return ip;
-		}
-	} while (count++ < 16);
-	return 0;
-}
diff --git a/arch/ppc/kernel/smp.c b/arch/ppc/kernel/smp.c
index becbfa3..e55cdda 100644
--- a/arch/ppc/kernel/smp.c
+++ b/arch/ppc/kernel/smp.c
@@ -318,7 +318,7 @@
 		p = fork_idle(cpu);
 		if (IS_ERR(p))
 			panic("failed fork for CPU %u: %li", cpu, PTR_ERR(p));
-		p->thread_info->cpu = cpu;
+		task_thread_info(p)->cpu = cpu;
 		idle_tasks[cpu] = p;
 	}
 }
@@ -369,7 +369,7 @@
 	char buf[32];
 	int c;
 
-	secondary_ti = idle_tasks[cpu]->thread_info;
+	secondary_ti = task_thread_info(idle_tasks[cpu]);
 	mb();
 
 	/*
diff --git a/arch/ppc/platforms/apus_setup.c b/arch/ppc/platforms/apus_setup.c
index 2f74fde..c42c500 100644
--- a/arch/ppc/platforms/apus_setup.c
+++ b/arch/ppc/platforms/apus_setup.c
@@ -55,9 +55,6 @@
 int (*mach_set_clock_mmss) (unsigned long) = NULL;
 void (*mach_reset)( void );
 long mach_max_dma_address = 0x00ffffff; /* default set to the lower 16MB */
-#if defined(CONFIG_AMIGA_FLOPPY)
-void (*mach_floppy_setup) (char *, int *) __initdata = NULL;
-#endif
 #ifdef CONFIG_HEARTBEAT
 void (*mach_heartbeat) (int) = NULL;
 extern void apus_heartbeat (void);
@@ -76,7 +73,6 @@
 
 struct mem_info ramdisk;
 
-extern void amiga_floppy_setup(char *, int *);
 extern void config_amiga(void);
 
 static int __60nsram = 0;
@@ -305,16 +301,6 @@
 {
 }
 
-/*********************************************************** FLOPPY */
-#if defined(CONFIG_AMIGA_FLOPPY)
-__init
-void floppy_setup(char *str, int *ints)
-{
-	if (mach_floppy_setup)
-		mach_floppy_setup (str, ints);
-}
-#endif
-
 /*********************************************************** MEMORY */
 #define KMAP_MAX 32
 unsigned long kmap_chunks[KMAP_MAX*3];
@@ -574,9 +560,9 @@
 
 int __debug_ser_out( unsigned char c )
 {
-	custom.serdat = c | 0x100;
+	amiga_custom.serdat = c | 0x100;
 	mb();
-	while (!(custom.serdatr & 0x2000))
+	while (!(amiga_custom.serdatr & 0x2000))
 		barrier();
 	return 1;
 }
@@ -586,11 +572,11 @@
 	unsigned char c;
 
 	/* XXX: is that ok?? derived from amiga_ser.c... */
-	while( !(custom.intreqr & IF_RBF) )
+	while( !(amiga_custom.intreqr & IF_RBF) )
 		barrier();
-	c = custom.serdatr;
+	c = amiga_custom.serdatr;
 	/* clear the interrupt, so that another character can be read */
-	custom.intreq = IF_RBF;
+	amiga_custom.intreq = IF_RBF;
 	return c;
 }
 
@@ -601,10 +587,10 @@
 	local_irq_save(flags);
 
 	/* turn off Rx and Tx interrupts */
-	custom.intena = IF_RBF | IF_TBE;
+	amiga_custom.intena = IF_RBF | IF_TBE;
 
 	/* clear any pending interrupt */
-	custom.intreq = IF_RBF | IF_TBE;
+	amiga_custom.intreq = IF_RBF | IF_TBE;
 
 	local_irq_restore(flags);
 
@@ -617,7 +603,7 @@
 
 #ifdef CONFIG_KGDB
 	/* turn Rx interrupts on for GDB */
-	custom.intena = IF_SETCLR | IF_RBF;
+	amiga_custom.intena = IF_SETCLR | IF_RBF;
 	ser_RTSon();
 #endif
 
diff --git a/arch/ppc/xmon/xmon.c b/arch/ppc/xmon/xmon.c
index 2b483b4..9075a75 100644
--- a/arch/ppc/xmon/xmon.c
+++ b/arch/ppc/xmon/xmon.c
@@ -99,7 +99,7 @@
 static void insert_bpts(void);
 static struct bpt *at_breakpoint(unsigned pc);
 static void bpt_cmds(void);
-static void cacheflush(void);
+void cacheflush(void);
 #ifdef CONFIG_SMP
 static void cpu_cmd(void);
 #endif /* CONFIG_SMP */
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 6fe532d..b66602a 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -27,11 +27,6 @@
 	bool
 	default y
 
-config UID16
-	bool
-	default y
-	depends on !64BIT
-
 source "init/Kconfig"
 
 menu "Base setup"
diff --git a/arch/s390/kernel/Makefile b/arch/s390/kernel/Makefile
index 4865e4b..9269b57 100644
--- a/arch/s390/kernel/Makefile
+++ b/arch/s390/kernel/Makefile
@@ -17,8 +17,7 @@
 obj-$(CONFIG_SMP)		+= smp.o
 
 obj-$(CONFIG_COMPAT)		+= compat_linux.o compat_signal.o \
-					compat_ioctl.o compat_wrapper.o \
-					compat_exec_domain.o
+					compat_wrapper.o compat_exec_domain.o
 obj-$(CONFIG_BINFMT_ELF32)	+= binfmt_elf32.o
 
 obj-$(CONFIG_VIRT_TIMER)	+= vtime.o
diff --git a/arch/s390/kernel/binfmt_elf32.c b/arch/s390/kernel/binfmt_elf32.c
index 03ba589..1f451c2 100644
--- a/arch/s390/kernel/binfmt_elf32.c
+++ b/arch/s390/kernel/binfmt_elf32.c
@@ -112,7 +112,7 @@
 
 static inline int dump_task_regs32(struct task_struct *tsk, elf_gregset_t *regs)
 {
-	struct pt_regs *ptregs = __KSTK_PTREGS(tsk);
+	struct pt_regs *ptregs = task_pt_regs(tsk);
 	int i;
 
 	memcpy(&regs->psw.mask, &ptregs->psw.mask, 4);
diff --git a/arch/s390/kernel/compat_ioctl.c b/arch/s390/kernel/compat_ioctl.c
deleted file mode 100644
index 6504c4e..0000000
--- a/arch/s390/kernel/compat_ioctl.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * ioctl32.c: Conversion between 32bit and 64bit native ioctls.
- *
- *  S390 version
- *    Copyright (C) 2000-2003 IBM Deutschland Entwicklung GmbH, IBM Corporation
- *    Author(s): Gerhard Tonn (ton@de.ibm.com)
- *               Arnd Bergmann (arndb@de.ibm.com)
- *
- * Original implementation from 32-bit Sparc compat code which is
- * Copyright (C) 2000 Silicon Graphics, Inc.
- * Written by Ulf Carlsson (ulfc@engr.sgi.com) 
- */
-
-#include "compat_linux.h"
-#define INCLUDES
-#define CODE
-#include "../../../fs/compat_ioctl.c"
-#include <asm/dasd.h>
-#include <asm/cmb.h>
-#include <asm/tape390.h>
-#include <asm/ccwdev.h>
-#include "../../../drivers/s390/char/raw3270.h"
-
-static int do_ioctl32_pointer(unsigned int fd, unsigned int cmd,
-				unsigned long arg, struct file *f)
-{
-	return sys_ioctl(fd, cmd, (unsigned long)compat_ptr(arg));
-}
-
-static int do_ioctl32_ulong(unsigned int fd, unsigned int cmd,
-				unsigned long arg, struct file *f)
-{
-	return sys_ioctl(fd, cmd, arg);
-}
-
-#define COMPATIBLE_IOCTL(cmd)		HANDLE_IOCTL((cmd),(ioctl_trans_handler_t)do_ioctl32_pointer)
-#define ULONG_IOCTL(cmd)		HANDLE_IOCTL((cmd),(ioctl_trans_handler_t)do_ioctl32_ulong)
-#define HANDLE_IOCTL(cmd,handler)	{ (cmd), (ioctl_trans_handler_t)(handler), NULL },
-
-struct ioctl_trans ioctl_start[] = {
-/* architecture independent ioctls */
-#include <linux/compat_ioctl.h>
-#define DECLARES
-#include "../../../fs/compat_ioctl.c"
-
-/* s390 only ioctls */
-COMPATIBLE_IOCTL(DASDAPIVER)
-COMPATIBLE_IOCTL(BIODASDDISABLE)
-COMPATIBLE_IOCTL(BIODASDENABLE)
-COMPATIBLE_IOCTL(BIODASDRSRV)
-COMPATIBLE_IOCTL(BIODASDRLSE)
-COMPATIBLE_IOCTL(BIODASDSLCK)
-COMPATIBLE_IOCTL(BIODASDINFO)
-COMPATIBLE_IOCTL(BIODASDINFO2)
-COMPATIBLE_IOCTL(BIODASDFMT)
-COMPATIBLE_IOCTL(BIODASDPRRST)
-COMPATIBLE_IOCTL(BIODASDQUIESCE)
-COMPATIBLE_IOCTL(BIODASDRESUME)
-COMPATIBLE_IOCTL(BIODASDPRRD)
-COMPATIBLE_IOCTL(BIODASDPSRD)
-COMPATIBLE_IOCTL(BIODASDGATTR)
-COMPATIBLE_IOCTL(BIODASDSATTR)
-COMPATIBLE_IOCTL(BIODASDCMFENABLE)
-COMPATIBLE_IOCTL(BIODASDCMFDISABLE)
-COMPATIBLE_IOCTL(BIODASDREADALLCMB)
-
-COMPATIBLE_IOCTL(TUBICMD)
-COMPATIBLE_IOCTL(TUBOCMD)
-COMPATIBLE_IOCTL(TUBGETI)
-COMPATIBLE_IOCTL(TUBGETO)
-COMPATIBLE_IOCTL(TUBSETMOD)
-COMPATIBLE_IOCTL(TUBGETMOD)
-
-COMPATIBLE_IOCTL(TAPE390_DISPLAY)
-
-/* s390 doesn't need handlers here */
-COMPATIBLE_IOCTL(TIOCGSERIAL)
-COMPATIBLE_IOCTL(TIOCSSERIAL)
-};
-
-int ioctl_table_size = ARRAY_SIZE(ioctl_start);
diff --git a/arch/s390/kernel/compat_linux.c b/arch/s390/kernel/compat_linux.c
index 41b197a..bf9a7a3 100644
--- a/arch/s390/kernel/compat_linux.c
+++ b/arch/s390/kernel/compat_linux.c
@@ -55,6 +55,7 @@
 #include <linux/syscalls.h>
 #include <linux/sysctl.h>
 #include <linux/binfmts.h>
+#include <linux/capability.h>
 #include <linux/compat.h>
 #include <linux/vfs.h>
 #include <linux/ptrace.h>
@@ -1014,38 +1015,6 @@
 }
 
 /*
- * Wrapper function for sys_timer_create.
- */
-extern asmlinkage long
-sys_timer_create(clockid_t, struct sigevent *, timer_t *);
-
-asmlinkage long
-sys32_timer_create(clockid_t which_clock, struct compat_sigevent *se32,
-		timer_t *timer_id)
-{
-	struct sigevent se;
-	timer_t ktimer_id;
-	mm_segment_t old_fs;
-	long ret;
-
-	if (se32 == NULL)
-		return sys_timer_create(which_clock, NULL, timer_id);
-
-	if (get_compat_sigevent(&se, se32))
-		return -EFAULT;
-
-	old_fs = get_fs();
-	set_fs(KERNEL_DS);
-	ret = sys_timer_create(which_clock, &se, &ktimer_id);
-	set_fs(old_fs);
-
-	if (!ret)
-		ret = put_user (ktimer_id, timer_id);
-
-	return ret;
-}
-
-/*
  * 31 bit emulation wrapper functions for sys_fadvise64/fadvise64_64.
  * These need to rewrite the advise values for POSIX_FADV_{DONTNEED,NOREUSE}
  * because the 31 bit values differ from the 64 bit values.
diff --git a/arch/s390/kernel/compat_wrapper.S b/arch/s390/kernel/compat_wrapper.S
index 23fe94e..cfde190 100644
--- a/arch/s390/kernel/compat_wrapper.S
+++ b/arch/s390/kernel/compat_wrapper.S
@@ -1289,7 +1289,7 @@
 	lgfr	%r2,%r2			# timer_t (int)
 	llgtr	%r3,%r3			# struct compat_sigevent *
 	llgtr	%r4,%r4			# timer_t *
-	jg	sys32_timer_create
+	jg	compat_sys_timer_create
 
 	.globl	sys32_timer_settime_wrapper
 sys32_timer_settime_wrapper:
diff --git a/arch/s390/kernel/crash.c b/arch/s390/kernel/crash.c
index 7bd169c..926ccee 100644
--- a/arch/s390/kernel/crash.c
+++ b/arch/s390/kernel/crash.c
@@ -10,8 +10,6 @@
 #include <linux/threads.h>
 #include <linux/kexec.h>
 
-note_buf_t crash_notes[NR_CPUS];
-
 void machine_crash_shutdown(struct pt_regs *regs)
 {
 }
diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
index a942bf2..2ff90a1 100644
--- a/arch/s390/kernel/process.c
+++ b/arch/s390/kernel/process.c
@@ -153,7 +153,7 @@
 {
 	struct task_struct *tsk = current;
 
-        printk("CPU:    %d    %s\n", tsk->thread_info->cpu, print_tainted());
+        printk("CPU:    %d    %s\n", task_thread_info(tsk)->cpu, print_tainted());
         printk("Process %s (pid: %d, task: %p, ksp: %p)\n",
 	       current->comm, current->pid, (void *) tsk,
 	       (void *) tsk->thread.ksp);
@@ -217,8 +217,7 @@
             struct pt_regs childregs;
           } *frame;
 
-        frame = ((struct fake_frame *)
-		 (THREAD_SIZE + (unsigned long) p->thread_info)) - 1;
+        frame = container_of(task_pt_regs(p), struct fake_frame, childregs);
         p->thread.ksp = (unsigned long) frame;
 	/* Store access registers to kernel stack of new process. */
         frame->childregs = *regs;
@@ -352,38 +351,16 @@
 	return 1;
 }
 
-/*
- * fill in the user structure for a core dump..
- */
-void dump_thread(struct pt_regs * regs, struct user * dump)
-{
-
-/* changed the size calculations - should hopefully work better. lbt */
-	dump->magic = CMAGIC;
-	dump->start_code = 0;
-	dump->start_stack = regs->gprs[15] & ~(PAGE_SIZE - 1);
-	dump->u_tsize = current->mm->end_code >> PAGE_SHIFT;
-	dump->u_dsize = (current->mm->brk + PAGE_SIZE - 1) >> PAGE_SHIFT;
-	dump->u_dsize -= dump->u_tsize;
-	dump->u_ssize = 0;
-	if (dump->start_stack < TASK_SIZE)
-		dump->u_ssize = (TASK_SIZE - dump->start_stack) >> PAGE_SHIFT;
-	memcpy(&dump->regs, regs, sizeof(s390_regs));
-	dump_fpu (regs, &dump->regs.fp_regs);
-	dump->regs.per_info = current->thread.per_info;
-}
-
 unsigned long get_wchan(struct task_struct *p)
 {
 	struct stack_frame *sf, *low, *high;
 	unsigned long return_address;
 	int count;
 
-	if (!p || p == current || p->state == TASK_RUNNING || !p->thread_info)
+	if (!p || p == current || p->state == TASK_RUNNING || !task_stack_page(p))
 		return 0;
-	low = (struct stack_frame *) p->thread_info;
-	high = (struct stack_frame *)
-		((unsigned long) p->thread_info + THREAD_SIZE) - 1;
+	low = task_stack_page(p);
+	high = (struct stack_frame *) task_pt_regs(p);
 	sf = (struct stack_frame *) (p->thread.ksp & PSW_ADDR_INSN);
 	if (sf <= low || sf > high)
 		return 0;
diff --git a/arch/s390/kernel/ptrace.c b/arch/s390/kernel/ptrace.c
index cc02232..37dfe33 100644
--- a/arch/s390/kernel/ptrace.c
+++ b/arch/s390/kernel/ptrace.c
@@ -52,7 +52,7 @@
 	struct pt_regs *regs;
 	per_struct *per_info;
 
-	regs = __KSTK_PTREGS(task);
+	regs = task_pt_regs(task);
 	per_info = (per_struct *) &task->thread.per_info;
 	per_info->control_regs.bits.em_instruction_fetch =
 		per_info->single_step | per_info->instruction_fetch;
@@ -150,7 +150,7 @@
 		/*
 		 * psw and gprs are stored on the stack
 		 */
-		tmp = *(addr_t *)((addr_t) &__KSTK_PTREGS(child)->psw + addr);
+		tmp = *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr);
 		if (addr == (addr_t) &dummy->regs.psw.mask)
 			/* Remove per bit from user psw. */
 			tmp &= ~PSW_MASK_PER;
@@ -176,7 +176,7 @@
 		/*
 		 * orig_gpr2 is stored on the kernel stack
 		 */
-		tmp = (addr_t) __KSTK_PTREGS(child)->orig_gpr2;
+		tmp = (addr_t) task_pt_regs(child)->orig_gpr2;
 
 	} else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
 		/* 
@@ -243,7 +243,7 @@
 			   high order bit but older gdb's rely on it */
 			data |= PSW_ADDR_AMODE;
 #endif
-		*(addr_t *)((addr_t) &__KSTK_PTREGS(child)->psw + addr) = data;
+		*(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr) = data;
 
 	} else if (addr < (addr_t) (&dummy->regs.orig_gpr2)) {
 		/*
@@ -267,7 +267,7 @@
 		/*
 		 * orig_gpr2 is stored on the kernel stack
 		 */
-		__KSTK_PTREGS(child)->orig_gpr2 = data;
+		task_pt_regs(child)->orig_gpr2 = data;
 
 	} else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
 		/*
@@ -393,15 +393,15 @@
 		 */
 		if (addr == (addr_t) &dummy32->regs.psw.mask) {
 			/* Fake a 31 bit psw mask. */
-			tmp = (__u32)(__KSTK_PTREGS(child)->psw.mask >> 32);
+			tmp = (__u32)(task_pt_regs(child)->psw.mask >> 32);
 			tmp = PSW32_MASK_MERGE(PSW32_USER_BITS, tmp);
 		} else if (addr == (addr_t) &dummy32->regs.psw.addr) {
 			/* Fake a 31 bit psw address. */
-			tmp = (__u32) __KSTK_PTREGS(child)->psw.addr |
+			tmp = (__u32) task_pt_regs(child)->psw.addr |
 				PSW32_ADDR_AMODE31;
 		} else {
 			/* gpr 0-15 */
-			tmp = *(__u32 *)((addr_t) &__KSTK_PTREGS(child)->psw +
+			tmp = *(__u32 *)((addr_t) &task_pt_regs(child)->psw +
 					 addr*2 + 4);
 		}
 	} else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
@@ -415,7 +415,7 @@
 		/*
 		 * orig_gpr2 is stored on the kernel stack
 		 */
-		tmp = *(__u32*)((addr_t) &__KSTK_PTREGS(child)->orig_gpr2 + 4);
+		tmp = *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4);
 
 	} else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
 		/*
@@ -472,15 +472,15 @@
 			if (tmp != PSW32_MASK_MERGE(PSW32_USER_BITS, tmp))
 				/* Invalid psw mask. */
 				return -EINVAL;
-			__KSTK_PTREGS(child)->psw.mask =
+			task_pt_regs(child)->psw.mask =
 				PSW_MASK_MERGE(PSW_USER32_BITS, (__u64) tmp << 32);
 		} else if (addr == (addr_t) &dummy32->regs.psw.addr) {
 			/* Build a 64 bit psw address from 31 bit address. */
-			__KSTK_PTREGS(child)->psw.addr = 
+			task_pt_regs(child)->psw.addr =
 				(__u64) tmp & PSW32_ADDR_INSN;
 		} else {
 			/* gpr 0-15 */
-			*(__u32*)((addr_t) &__KSTK_PTREGS(child)->psw
+			*(__u32*)((addr_t) &task_pt_regs(child)->psw
 				  + addr*2 + 4) = tmp;
 		}
 	} else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
@@ -494,7 +494,7 @@
 		/*
 		 * orig_gpr2 is stored on the kernel stack
 		 */
-		*(__u32*)((addr_t) &__KSTK_PTREGS(child)->orig_gpr2 + 4) = tmp;
+		*(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4) = tmp;
 
 	} else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
 		/*
diff --git a/arch/s390/kernel/s390_ksyms.c b/arch/s390/kernel/s390_ksyms.c
index bee654a..4176c77 100644
--- a/arch/s390/kernel/s390_ksyms.c
+++ b/arch/s390/kernel/s390_ksyms.c
@@ -10,7 +10,6 @@
 #include <linux/smp.h>
 #include <linux/syscalls.h>
 #include <linux/interrupt.h>
-#include <linux/ioctl32.h>
 #include <asm/checksum.h>
 #include <asm/cpcmd.h>
 #include <asm/delay.h>
diff --git a/arch/s390/kernel/smp.c b/arch/s390/kernel/smp.c
index e10f4ca..cbfcfd0 100644
--- a/arch/s390/kernel/smp.c
+++ b/arch/s390/kernel/smp.c
@@ -657,7 +657,7 @@
 	idle = current_set[cpu];
         cpu_lowcore = lowcore_ptr[cpu];
 	cpu_lowcore->kernel_stack = (unsigned long)
-		idle->thread_info + (THREAD_SIZE);
+		task_stack_page(idle) + (THREAD_SIZE);
 	sf = (struct stack_frame *) (cpu_lowcore->kernel_stack
 				     - sizeof(struct pt_regs)
 				     - sizeof(struct stack_frame));
diff --git a/arch/s390/kernel/time.c b/arch/s390/kernel/time.c
index c36353e..b0d8ca8 100644
--- a/arch/s390/kernel/time.c
+++ b/arch/s390/kernel/time.c
@@ -282,7 +282,7 @@
 {
 	if (!cpu_isset(smp_processor_id(), nohz_cpu_mask))
 		return;
-	account_ticks(__KSTK_PTREGS(current));
+	account_ticks(task_pt_regs(current));
 	cpu_clear(smp_processor_id(), nohz_cpu_mask);
 }
 
diff --git a/arch/s390/kernel/traps.c b/arch/s390/kernel/traps.c
index 95d1099..5d21e9e 100644
--- a/arch/s390/kernel/traps.c
+++ b/arch/s390/kernel/traps.c
@@ -136,8 +136,8 @@
 	sp = __show_trace(sp, S390_lowcore.async_stack - ASYNC_SIZE,
 			  S390_lowcore.async_stack);
 	if (task)
-		__show_trace(sp, (unsigned long) task->thread_info,
-			     (unsigned long) task->thread_info + THREAD_SIZE);
+		__show_trace(sp, (unsigned long) task_stack_page(task),
+			     (unsigned long) task_stack_page(task) + THREAD_SIZE);
 	else
 		__show_trace(sp, S390_lowcore.thread_info,
 			     S390_lowcore.thread_info + THREAD_SIZE);
@@ -240,7 +240,7 @@
 {
 	struct pt_regs *regs;
 
-	regs = __KSTK_PTREGS(task);
+	regs = task_pt_regs(task);
 	buffer += sprintf(buffer, "task: %p, ksp: %p\n",
 		       task, (void *)task->thread.ksp);
 	buffer += sprintf(buffer, "User PSW : %p %p\n",
diff --git a/arch/sh/kernel/process.c b/arch/sh/kernel/process.c
index fd4f240..aac15e4 100644
--- a/arch/sh/kernel/process.c
+++ b/arch/sh/kernel/process.c
@@ -191,13 +191,8 @@
 {
 #if defined(CONFIG_SH_FPU)
 	struct task_struct *tsk = current;
-	struct pt_regs *regs = (struct pt_regs *)
-				((unsigned long)tsk->thread_info
-				 + THREAD_SIZE - sizeof(struct pt_regs)
-				 - sizeof(unsigned long));
-
 	/* Forget lazy FPU state */
-	clear_fpu(tsk, regs);
+	clear_fpu(tsk, task_pt_regs(tsk));
 	clear_used_math();
 #endif
 }
@@ -232,13 +227,7 @@
 {
 	struct pt_regs ptregs;
 	
-	ptregs = *(struct pt_regs *)
-		((unsigned long)tsk->thread_info + THREAD_SIZE
-		 - sizeof(struct pt_regs)
-#ifdef CONFIG_SH_DSP
-		 - sizeof(struct pt_dspregs)
-#endif
-		 - sizeof(unsigned long));
+	ptregs = *task_pt_regs(tsk);
 	elf_core_copy_regs(regs, &ptregs);
 
 	return 1;
@@ -252,11 +241,7 @@
 #if defined(CONFIG_SH_FPU)
 	fpvalid = !!tsk_used_math(tsk);
 	if (fpvalid) {
-		struct pt_regs *regs = (struct pt_regs *)
-					((unsigned long)tsk->thread_info
-					 + THREAD_SIZE - sizeof(struct pt_regs)
-					 - sizeof(unsigned long));
-		unlazy_fpu(tsk, regs);
+		unlazy_fpu(tsk, task_pt_regs(tsk));
 		memcpy(fpu, &tsk->thread.fpu.hard, sizeof(*fpu));
 	}
 #endif
@@ -279,18 +264,13 @@
 	copy_to_stopped_child_used_math(p);
 #endif
 
-	childregs = ((struct pt_regs *)
-		(THREAD_SIZE + (unsigned long) p->thread_info)
-#ifdef CONFIG_SH_DSP
-		- sizeof(struct pt_dspregs)
-#endif
-		- sizeof(unsigned long)) - 1;
+	childregs = task_pt_regs(p);
 	*childregs = *regs;
 
 	if (user_mode(regs)) {
 		childregs->regs[15] = usp;
 	} else {
-		childregs->regs[15] = (unsigned long)p->thread_info + THREAD_SIZE;
+		childregs->regs[15] = (unsigned long)task_stack_page(p) + THREAD_SIZE;
 	}
         if (clone_flags & CLONE_SETTLS) {
 		childregs->gbr = childregs->regs[0];
@@ -305,26 +285,6 @@
 	return 0;
 }
 
-/*
- * fill in the user structure for a core dump..
- */
-void dump_thread(struct pt_regs * regs, struct user * dump)
-{
-	dump->magic = CMAGIC;
-	dump->start_code = current->mm->start_code;
-	dump->start_data  = current->mm->start_data;
-	dump->start_stack = regs->regs[15] & ~(PAGE_SIZE - 1);
-	dump->u_tsize = (current->mm->end_code - dump->start_code) >> PAGE_SHIFT;
-	dump->u_dsize = (current->mm->brk + (PAGE_SIZE-1) - dump->start_data) >> PAGE_SHIFT;
-	dump->u_ssize = (current->mm->start_stack - dump->start_stack +
-			 PAGE_SIZE - 1) >> PAGE_SHIFT;
-	/* Debug registers will come here. */
-
-	dump->regs = *regs;
-
-	dump->u_fpvalid = dump_fpu(regs, &dump->fpu);
-}
-
 /* Tracing by user break controller.  */
 static void
 ubc_set_tracing(int asid, unsigned long pc)
@@ -353,11 +313,7 @@
 struct task_struct *__switch_to(struct task_struct *prev, struct task_struct *next)
 {
 #if defined(CONFIG_SH_FPU)
-	struct pt_regs *regs = (struct pt_regs *)
-				((unsigned long)prev->thread_info
-				 + THREAD_SIZE - sizeof(struct pt_regs)
-				 - sizeof(unsigned long));
-	unlazy_fpu(prev, regs);
+	unlazy_fpu(prev, task_pt_regs(prev));
 #endif
 
 #ifdef CONFIG_PREEMPT
@@ -366,13 +322,7 @@
 		struct pt_regs *regs;
 
 		local_irq_save(flags);
-		regs = (struct pt_regs *)
-			((unsigned long)prev->thread_info
-			 + THREAD_SIZE - sizeof(struct pt_regs)
-#ifdef CONFIG_SH_DSP
-			 - sizeof(struct pt_dspregs)
-#endif
-			 - sizeof(unsigned long));
+		regs = task_pt_regs(prev);
 		if (user_mode(regs) && regs->regs[15] >= 0xc0000000) {
 			int offset = (int)regs->regs[15];
 
@@ -392,7 +342,7 @@
 	 */
 	asm volatile("ldc	%0, r7_bank"
 		     : /* no output */
-		     : "r" (next->thread_info));
+		     : "r" (task_thread_info(next)));
 
 #ifdef CONFIG_MMU
 	/* If no tasks are using the UBC, we're done */
diff --git a/arch/sh/kernel/ptrace.c b/arch/sh/kernel/ptrace.c
index 1a8be06..3887b4f 100644
--- a/arch/sh/kernel/ptrace.c
+++ b/arch/sh/kernel/ptrace.c
@@ -41,12 +41,7 @@
 {
 	unsigned char *stack;
 
-	stack = (unsigned char *)
-		task->thread_info + THREAD_SIZE	- sizeof(struct pt_regs)
-#ifdef CONFIG_SH_DSP
-		- sizeof(struct pt_dspregs)
-#endif
-		- sizeof(unsigned long);
+	stack = (unsigned char *)task_pt_regs(task);
 	stack += offset;
 	return (*((int *)stack));
 }
@@ -59,12 +54,7 @@
 {
 	unsigned char *stack;
 
-	stack = (unsigned char *)
-		task->thread_info + THREAD_SIZE - sizeof(struct pt_regs)
-#ifdef CONFIG_SH_DSP
-		- sizeof(struct pt_dspregs)
-#endif
-		- sizeof(unsigned long);
+	stack = (unsigned char *)task_pt_regs(task);
 	stack += offset;
 	*(unsigned long *) stack = data;
 	return 0;
diff --git a/arch/sh/kernel/sh_ksyms.c b/arch/sh/kernel/sh_ksyms.c
index 6954fd6..1cf94a6 100644
--- a/arch/sh/kernel/sh_ksyms.c
+++ b/arch/sh/kernel/sh_ksyms.c
@@ -21,14 +21,12 @@
 #include <asm/cacheflush.h>
 #include <asm/checksum.h>
 
-extern void dump_thread(struct pt_regs *, struct user *);
 extern int dump_fpu(struct pt_regs *, elf_fpregset_t *);
 extern struct hw_interrupt_type no_irq_type;
 
 EXPORT_SYMBOL(sh_mv);
 
 /* platform dependent support */
-EXPORT_SYMBOL(dump_thread);
 EXPORT_SYMBOL(dump_fpu);
 EXPORT_SYMBOL(iounmap);
 EXPORT_SYMBOL(enable_irq);
diff --git a/arch/sh/kernel/smp.c b/arch/sh/kernel/smp.c
index 59e49b1..62c7d1c 100644
--- a/arch/sh/kernel/smp.c
+++ b/arch/sh/kernel/smp.c
@@ -103,7 +103,7 @@
 	if (IS_ERR(tsk))
 		panic("Failed forking idle task for cpu %d\n", cpu);
 	
-	tsk->thread_info->cpu = cpu;
+	task_thread_info(tsk)->cpu = cpu;
 
 	cpu_set(cpu, cpu_online_map);
 
diff --git a/arch/sh64/Kconfig b/arch/sh64/Kconfig
index fb35b45..07b172d 100644
--- a/arch/sh64/Kconfig
+++ b/arch/sh64/Kconfig
@@ -17,10 +17,6 @@
 	bool
 	default y
 
-config UID16
-	bool
-	default y
-
 config RWSEM_GENERIC_SPINLOCK
 	bool
 	default y
diff --git a/arch/sh64/kernel/process.c b/arch/sh64/kernel/process.c
index b95d041..1da9c61 100644
--- a/arch/sh64/kernel/process.c
+++ b/arch/sh64/kernel/process.c
@@ -744,7 +744,7 @@
 	}
 #endif
 	/* Copy from sh version */
-	childregs = ((struct pt_regs *)(THREAD_SIZE + (unsigned long) p->thread_info )) - 1;
+	childregs = (struct pt_regs *)(THREAD_SIZE + task_stack_page(p)) - 1;
 
 	*childregs = *regs;
 
@@ -752,7 +752,7 @@
 		childregs->regs[15] = usp;
 		p->thread.uregs = childregs;
 	} else {
-		childregs->regs[15] = (unsigned long)p->thread_info + THREAD_SIZE;
+		childregs->regs[15] = (unsigned long)task_stack_page(p) + THREAD_SIZE;
 	}
 
 	childregs->regs[9] = 0; /* Set return value for child */
@@ -775,26 +775,6 @@
 	return 0;
 }
 
-/*
- * fill in the user structure for a core dump..
- */
-void dump_thread(struct pt_regs * regs, struct user * dump)
-{
-	dump->magic = CMAGIC;
-	dump->start_code = current->mm->start_code;
-	dump->start_data  = current->mm->start_data;
-	dump->start_stack = regs->regs[15] & ~(PAGE_SIZE - 1);
-	dump->u_tsize = (current->mm->end_code - dump->start_code) >> PAGE_SHIFT;
-	dump->u_dsize = (current->mm->brk + (PAGE_SIZE-1) - dump->start_data) >> PAGE_SHIFT;
-	dump->u_ssize = (current->mm->start_stack - dump->start_stack +
-			 PAGE_SIZE - 1) >> PAGE_SHIFT;
-	/* Debug registers will come here. */
-
-	dump->regs = *regs;
-
-	dump->u_fpvalid = dump_fpu(regs, &dump->fpu);
-}
-
 asmlinkage int sys_fork(unsigned long r2, unsigned long r3,
 			unsigned long r4, unsigned long r5,
 			unsigned long r6, unsigned long r7,
diff --git a/arch/sh64/kernel/sh_ksyms.c b/arch/sh64/kernel/sh_ksyms.c
index 0b5497d..472b450 100644
--- a/arch/sh64/kernel/sh_ksyms.c
+++ b/arch/sh64/kernel/sh_ksyms.c
@@ -29,7 +29,6 @@
 #include <asm/delay.h>
 #include <asm/irq.h>
 
-extern void dump_thread(struct pt_regs *, struct user *);
 extern int dump_fpu(struct pt_regs *, elf_fpregset_t *);
 
 #if 0
@@ -41,7 +40,6 @@
 #endif
 
 /* platform dependent support */
-EXPORT_SYMBOL(dump_thread);
 EXPORT_SYMBOL(dump_fpu);
 EXPORT_SYMBOL(iounmap);
 EXPORT_SYMBOL(enable_irq);
diff --git a/arch/sh64/lib/dbg.c b/arch/sh64/lib/dbg.c
index 526feda..5808733 100644
--- a/arch/sh64/lib/dbg.c
+++ b/arch/sh64/lib/dbg.c
@@ -174,7 +174,7 @@
 	struct ring_node *rr;
 
 	pid = current->pid;
-	stack_bottom = (unsigned long) current->thread_info;
+	stack_bottom = (unsigned long) task_stack_page(current);
 	asm volatile("ori r15, 0, %0" : "=r" (sp));
 	rr = event_ring + event_ptr;
 	rr->evt = evt;
diff --git a/arch/sparc/kernel/process.c b/arch/sparc/kernel/process.c
index ea86474..fbb05a4 100644
--- a/arch/sparc/kernel/process.c
+++ b/arch/sparc/kernel/process.c
@@ -302,7 +302,7 @@
 	int count = 0;
 
 	if (tsk != NULL)
-		task_base = (unsigned long) tsk->thread_info;
+		task_base = (unsigned long) task_stack_page(tsk);
 	else
 		task_base = (unsigned long) current_thread_info();
 
@@ -337,7 +337,7 @@
  */
 unsigned long thread_saved_pc(struct task_struct *tsk)
 {
-	return tsk->thread_info->kpc;
+	return task_thread_info(tsk)->kpc;
 }
 
 /*
@@ -392,7 +392,7 @@
 		/* We must fixup kregs as well. */
 		/* XXX This was not fixed for ti for a while, worked. Unused? */
 		current->thread.kregs = (struct pt_regs *)
-		    ((char *)current->thread_info + (THREAD_SIZE - TRACEREG_SZ));
+		    (task_stack_page(current) + (THREAD_SIZE - TRACEREG_SZ));
 	}
 }
 
@@ -459,7 +459,7 @@
 		unsigned long unused,
 		struct task_struct *p, struct pt_regs *regs)
 {
-	struct thread_info *ti = p->thread_info;
+	struct thread_info *ti = task_thread_info(p);
 	struct pt_regs *childregs;
 	char *new_stack;
 
@@ -482,7 +482,7 @@
 	 *  V                      V (stk.fr.) V  (pt_regs)  { (stk.fr.) }
 	 *  +----- - - - - - ------+===========+============={+==========}+
 	 */
-	new_stack = (char*)ti + THREAD_SIZE;
+	new_stack = task_stack_page(p) + THREAD_SIZE;
 	if (regs->psr & PSR_PS)
 		new_stack -= STACKFRAME_SZ;
 	new_stack -= STACKFRAME_SZ + TRACEREG_SZ;
@@ -724,7 +724,7 @@
             task->state == TASK_RUNNING)
 		goto out;
 
-	fp = task->thread_info->ksp + bias;
+	fp = task_thread_info(task)->ksp + bias;
 	do {
 		/* Bogus frame pointer? */
 		if (fp < (task_base + sizeof(struct thread_info)) ||
diff --git a/arch/sparc/kernel/ptrace.c b/arch/sparc/kernel/ptrace.c
index fc470c0..1baf13e 100644
--- a/arch/sparc/kernel/ptrace.c
+++ b/arch/sparc/kernel/ptrace.c
@@ -75,7 +75,7 @@
 				   struct task_struct *tsk, long __user *addr)
 {
 	struct pt_regs *cregs = tsk->thread.kregs;
-	struct thread_info *t = tsk->thread_info;
+	struct thread_info *t = task_thread_info(tsk);
 	int v;
 	
 	if(offset >= 1024)
@@ -170,7 +170,7 @@
 				    struct task_struct *tsk)
 {
 	struct pt_regs *cregs = tsk->thread.kregs;
-	struct thread_info *t = tsk->thread_info;
+	struct thread_info *t = task_thread_info(tsk);
 	unsigned long value = regs->u_regs[UREG_I3];
 
 	if(offset >= 1024)
diff --git a/arch/sparc/kernel/sparc_ksyms.c b/arch/sparc/kernel/sparc_ksyms.c
index 1c8fd0f..0b0d492 100644
--- a/arch/sparc/kernel/sparc_ksyms.c
+++ b/arch/sparc/kernel/sparc_ksyms.c
@@ -82,8 +82,6 @@
 extern int __muldi3(int, int);
 extern int __divdi3(int, int);
 
-extern void dump_thread(struct pt_regs *, struct user *);
-
 /* Private functions with odd calling conventions. */
 extern void ___atomic24_add(void);
 extern void ___atomic24_sub(void);
diff --git a/arch/sparc/kernel/sun4d_smp.c b/arch/sparc/kernel/sun4d_smp.c
index cc1fc89..40d426c 100644
--- a/arch/sparc/kernel/sun4d_smp.c
+++ b/arch/sparc/kernel/sun4d_smp.c
@@ -200,7 +200,7 @@
 			/* Cook up an idler for this guy. */
 			p = fork_idle(i);
 			cpucount++;
-			current_set[i] = p->thread_info;
+			current_set[i] = task_thread_info(p);
 			for (no = 0; !cpu_find_by_instance(no, NULL, &mid)
 				     && mid != i; no++) ;
 
diff --git a/arch/sparc/kernel/sun4m_smp.c b/arch/sparc/kernel/sun4m_smp.c
index f113422..a21f27d 100644
--- a/arch/sparc/kernel/sun4m_smp.c
+++ b/arch/sparc/kernel/sun4m_smp.c
@@ -173,7 +173,7 @@
 			/* Cook up an idler for this guy. */
 			p = fork_idle(i);
 			cpucount++;
-			current_set[i] = p->thread_info;
+			current_set[i] = task_thread_info(p);
 			/* See trampoline.S for details... */
 			entry += ((i-1) * 3);
 
diff --git a/arch/sparc/kernel/sys_sunos.c b/arch/sparc/kernel/sys_sunos.c
index d07ae02..288de27 100644
--- a/arch/sparc/kernel/sys_sunos.c
+++ b/arch/sparc/kernel/sys_sunos.c
@@ -30,6 +30,7 @@
 #include <linux/stat.h>
 #include <linux/slab.h>
 #include <linux/pagemap.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/smp.h>
 #include <linux/smp_lock.h>
diff --git a/arch/sparc/kernel/traps.c b/arch/sparc/kernel/traps.c
index 3f451ae..41d45c2 100644
--- a/arch/sparc/kernel/traps.c
+++ b/arch/sparc/kernel/traps.c
@@ -291,7 +291,7 @@
 #ifndef CONFIG_SMP
 	if(!fpt) {
 #else
-        if(!(fpt->thread_info->flags & _TIF_USEDFPU)) {
+        if(!(task_thread_info(fpt)->flags & _TIF_USEDFPU)) {
 #endif
 		fpsave(&fake_regs[0], &fake_fsr, &fake_queue[0], &fake_depth);
 		regs->psr &= ~PSR_EF;
@@ -334,7 +334,7 @@
 	/* nope, better SIGFPE the offending process... */
 	       
 #ifdef CONFIG_SMP
-	fpt->thread_info->flags &= ~_TIF_USEDFPU;
+	task_thread_info(fpt)->flags &= ~_TIF_USEDFPU;
 #endif
 	if(psr & PSR_PS) {
 		/* The first fsr store/load we tried trapped,
diff --git a/arch/sparc64/Kconfig b/arch/sparc64/Kconfig
index b775ceb..ab733be 100644
--- a/arch/sparc64/Kconfig
+++ b/arch/sparc64/Kconfig
@@ -179,7 +179,7 @@
 	bool "512K"
 
 config HUGETLB_PAGE_SIZE_64K
-	depends on !SPARC64_PAGE_SIZE_4MB && !SPARC64_PAGE_SIZE_512K
+	depends on !SPARC64_PAGE_SIZE_4MB && !SPARC64_PAGE_SIZE_512KB
 	bool "64K"
 
 endchoice
diff --git a/arch/sparc64/kernel/Makefile b/arch/sparc64/kernel/Makefile
index 6f00ab8..83d67eb 100644
--- a/arch/sparc64/kernel/Makefile
+++ b/arch/sparc64/kernel/Makefile
@@ -16,7 +16,7 @@
 obj-$(CONFIG_PCI)	 += ebus.o isa.o pci_common.o pci_iommu.o \
 			    pci_psycho.o pci_sabre.o pci_schizo.o
 obj-$(CONFIG_SMP)	 += smp.o trampoline.o
-obj-$(CONFIG_SPARC32_COMPAT) += sys32.o sys_sparc32.o signal32.o ioctl32.o
+obj-$(CONFIG_SPARC32_COMPAT) += sys32.o sys_sparc32.o signal32.o
 obj-$(CONFIG_BINFMT_ELF32) += binfmt_elf32.o
 obj-$(CONFIG_BINFMT_AOUT32) += binfmt_aout32.o
 obj-$(CONFIG_MODULES) += module.o
@@ -40,5 +40,3 @@
 
 head.o: head.S ttable.S itlb_base.S dtlb_base.S dtlb_backend.S dtlb_prot.S \
 	etrap.S rtrap.S winfixup.S entry.S
-
-CFLAGS_ioctl32.o += -Ifs/
diff --git a/arch/sparc64/kernel/binfmt_aout32.c b/arch/sparc64/kernel/binfmt_aout32.c
index edf52d06..202a80c 100644
--- a/arch/sparc64/kernel/binfmt_aout32.c
+++ b/arch/sparc64/kernel/binfmt_aout32.c
@@ -36,8 +36,6 @@
 static int load_aout32_library(struct file*);
 static int aout32_core_dump(long signr, struct pt_regs * regs, struct file *file);
 
-extern void dump_thread(struct pt_regs *, struct user *);
-
 static struct linux_binfmt aout32_format = {
 	NULL, THIS_MODULE, load_aout32_binary, load_aout32_library, aout32_core_dump,
 	PAGE_SIZE
diff --git a/arch/sparc64/kernel/ioctl32.c b/arch/sparc64/kernel/ioctl32.c
deleted file mode 100644
index 196b208..0000000
--- a/arch/sparc64/kernel/ioctl32.c
+++ /dev/null
@@ -1,39 +0,0 @@
-/* $Id: ioctl32.c,v 1.136 2002/01/14 09:49:52 davem Exp $
- * ioctl32.c: Conversion between 32bit and 64bit native ioctls.
- *
- * Copyright (C) 1997-2000  Jakub Jelinek  (jakub@redhat.com)
- * Copyright (C) 1998  Eddie C. Dost  (ecd@skynet.be)
- * Copyright (C) 2003  Pavel Machek (pavel@suse.cz)
- *
- * These routines maintain argument size conversion between 32bit and 64bit
- * ioctls.
- */
-
-#define INCLUDES
-#include "compat_ioctl.c"
-#include <linux/syscalls.h>
-
-#define CODE
-#include "compat_ioctl.c"
-
-#define COMPATIBLE_IOCTL(cmd)		HANDLE_IOCTL((cmd),sys_ioctl)
-#define HANDLE_IOCTL(cmd,handler)	{ (cmd), (ioctl_trans_handler_t)(handler), NULL },
-#define IOCTL_TABLE_START \
-	struct ioctl_trans ioctl_start[] = {
-#define IOCTL_TABLE_END \
-	};
-
-IOCTL_TABLE_START
-#include <linux/compat_ioctl.h>
-#define DECLARES
-#include "compat_ioctl.c"
-#if 0
-HANDLE_IOCTL(RTC32_IRQP_READ, do_rtc_ioctl)
-HANDLE_IOCTL(RTC32_IRQP_SET, do_rtc_ioctl)
-HANDLE_IOCTL(RTC32_EPOCH_READ, do_rtc_ioctl)
-HANDLE_IOCTL(RTC32_EPOCH_SET, do_rtc_ioctl)
-#endif
-/* take care of sizeof(sizeof()) breakage */
-IOCTL_TABLE_END
-
-int ioctl_table_size = ARRAY_SIZE(ioctl_start);
diff --git a/arch/sparc64/kernel/kprobes.c b/arch/sparc64/kernel/kprobes.c
index a97b0f0..b9a9ce7 100644
--- a/arch/sparc64/kernel/kprobes.c
+++ b/arch/sparc64/kernel/kprobes.c
@@ -43,14 +43,10 @@
 
 int __kprobes arch_prepare_kprobe(struct kprobe *p)
 {
-	return 0;
-}
-
-void __kprobes arch_copy_kprobe(struct kprobe *p)
-{
 	p->ainsn.insn[0] = *p->addr;
 	p->ainsn.insn[1] = BREAKPOINT_INSTRUCTION_2;
 	p->opcode = *p->addr;
+	return 0;
 }
 
 void __kprobes arch_arm_kprobe(struct kprobe *p)
@@ -65,10 +61,6 @@
 	flushi(p->addr);
 }
 
-void __kprobes arch_remove_kprobe(struct kprobe *p)
-{
-}
-
 static inline void save_previous_kprobe(struct kprobe_ctlblk *kcb)
 {
 	kcb->prev_kprobe.kp = kprobe_running();
@@ -143,6 +135,14 @@
 			prepare_singlestep(p, regs, kcb);
 			return 1;
 		} else {
+			if (*(u32 *)addr != BREAKPOINT_INSTRUCTION) {
+			/* The breakpoint instruction was removed by
+			 * another cpu right after we hit, no further
+			 * handling of this interrupt is appropriate
+			 */
+				ret = 1;
+				goto no_kprobe;
+			}
 			p = __get_cpu_var(current_kprobe);
 			if (p->break_handler && p->break_handler(p, regs))
 				goto ss_probe;
diff --git a/arch/sparc64/kernel/process.c b/arch/sparc64/kernel/process.c
index 02f9dec..1dc3650 100644
--- a/arch/sparc64/kernel/process.c
+++ b/arch/sparc64/kernel/process.c
@@ -390,7 +390,7 @@
 
 unsigned long thread_saved_pc(struct task_struct *tsk)
 {
-	struct thread_info *ti = tsk->thread_info;
+	struct thread_info *ti = task_thread_info(tsk);
 	unsigned long ret = 0xdeadbeefUL;
 	
 	if (ti && ti->ksp) {
@@ -616,11 +616,11 @@
 		unsigned long unused,
 		struct task_struct *p, struct pt_regs *regs)
 {
-	struct thread_info *t = p->thread_info;
+	struct thread_info *t = task_thread_info(p);
 	char *child_trap_frame;
 
 	/* Calculate offset to stack_frame & pt_regs */
-	child_trap_frame = ((char *)t) + (THREAD_SIZE - (TRACEREG_SZ+STACKFRAME_SZ));
+	child_trap_frame = task_stack_page(p) + (THREAD_SIZE - (TRACEREG_SZ+STACKFRAME_SZ));
 	memcpy(child_trap_frame, (((struct sparc_stackf *)regs)-1), (TRACEREG_SZ+STACKFRAME_SZ));
 
 	t->flags = (t->flags & ~((0xffUL << TI_FLAG_CWP_SHIFT) | (0xffUL << TI_FLAG_CURRENT_DS_SHIFT))) |
@@ -845,9 +845,9 @@
             task->state == TASK_RUNNING)
 		goto out;
 
-	thread_info_base = (unsigned long) task->thread_info;
+	thread_info_base = (unsigned long) task_stack_page(task);
 	bias = STACK_BIAS;
-	fp = task->thread_info->ksp + bias;
+	fp = task_thread_info(task)->ksp + bias;
 
 	do {
 		/* Bogus frame pointer? */
diff --git a/arch/sparc64/kernel/ptrace.c b/arch/sparc64/kernel/ptrace.c
index 84d3df2..3f9746f 100644
--- a/arch/sparc64/kernel/ptrace.c
+++ b/arch/sparc64/kernel/ptrace.c
@@ -296,7 +296,7 @@
 	case PTRACE_GETREGS: {
 		struct pt_regs32 __user *pregs =
 			(struct pt_regs32 __user *) addr;
-		struct pt_regs *cregs = child->thread_info->kregs;
+		struct pt_regs *cregs = task_pt_regs(child);
 		int rval;
 
 		if (__put_user(tstate_to_psr(cregs->tstate), (&pregs->psr)) ||
@@ -320,11 +320,11 @@
 
 	case PTRACE_GETREGS64: {
 		struct pt_regs __user *pregs = (struct pt_regs __user *) addr;
-		struct pt_regs *cregs = child->thread_info->kregs;
+		struct pt_regs *cregs = task_pt_regs(child);
 		unsigned long tpc = cregs->tpc;
 		int rval;
 
-		if ((child->thread_info->flags & _TIF_32BIT) != 0)
+		if ((task_thread_info(child)->flags & _TIF_32BIT) != 0)
 			tpc &= 0xffffffff;
 		if (__put_user(cregs->tstate, (&pregs->tstate)) ||
 		    __put_user(tpc, (&pregs->tpc)) ||
@@ -348,7 +348,7 @@
 	case PTRACE_SETREGS: {
 		struct pt_regs32 __user *pregs =
 			(struct pt_regs32 __user *) addr;
-		struct pt_regs *cregs = child->thread_info->kregs;
+		struct pt_regs *cregs = task_pt_regs(child);
 		unsigned int psr, pc, npc, y;
 		int i;
 
@@ -381,7 +381,7 @@
 
 	case PTRACE_SETREGS64: {
 		struct pt_regs __user *pregs = (struct pt_regs __user *) addr;
-		struct pt_regs *cregs = child->thread_info->kregs;
+		struct pt_regs *cregs = task_pt_regs(child);
 		unsigned long tstate, tpc, tnpc, y;
 		int i;
 
@@ -395,7 +395,7 @@
 			pt_error_return(regs, EFAULT);
 			goto out_tsk;
 		}
-		if ((child->thread_info->flags & _TIF_32BIT) != 0) {
+		if ((task_thread_info(child)->flags & _TIF_32BIT) != 0) {
 			tpc &= 0xffffffff;
 			tnpc &= 0xffffffff;
 		}
@@ -430,11 +430,11 @@
 			} fpq[16];
 		};
 		struct fps __user *fps = (struct fps __user *) addr;
-		unsigned long *fpregs = child->thread_info->fpregs;
+		unsigned long *fpregs = task_thread_info(child)->fpregs;
 
 		if (copy_to_user(&fps->regs[0], fpregs,
 				 (32 * sizeof(unsigned int))) ||
-		    __put_user(child->thread_info->xfsr[0], (&fps->fsr)) ||
+		    __put_user(task_thread_info(child)->xfsr[0], (&fps->fsr)) ||
 		    __put_user(0, (&fps->fpqd)) ||
 		    __put_user(0, (&fps->flags)) ||
 		    __put_user(0, (&fps->extra)) ||
@@ -452,11 +452,11 @@
 			unsigned long fsr;
 		};
 		struct fps __user *fps = (struct fps __user *) addr;
-		unsigned long *fpregs = child->thread_info->fpregs;
+		unsigned long *fpregs = task_thread_info(child)->fpregs;
 
 		if (copy_to_user(&fps->regs[0], fpregs,
 				 (64 * sizeof(unsigned int))) ||
-		    __put_user(child->thread_info->xfsr[0], (&fps->fsr))) {
+		    __put_user(task_thread_info(child)->xfsr[0], (&fps->fsr))) {
 			pt_error_return(regs, EFAULT);
 			goto out_tsk;
 		}
@@ -477,7 +477,7 @@
 			} fpq[16];
 		};
 		struct fps __user *fps = (struct fps __user *) addr;
-		unsigned long *fpregs = child->thread_info->fpregs;
+		unsigned long *fpregs = task_thread_info(child)->fpregs;
 		unsigned fsr;
 
 		if (copy_from_user(fpregs, &fps->regs[0],
@@ -486,11 +486,11 @@
 			pt_error_return(regs, EFAULT);
 			goto out_tsk;
 		}
-		child->thread_info->xfsr[0] &= 0xffffffff00000000UL;
-		child->thread_info->xfsr[0] |= fsr;
-		if (!(child->thread_info->fpsaved[0] & FPRS_FEF))
-			child->thread_info->gsr[0] = 0;
-		child->thread_info->fpsaved[0] |= (FPRS_FEF | FPRS_DL);
+		task_thread_info(child)->xfsr[0] &= 0xffffffff00000000UL;
+		task_thread_info(child)->xfsr[0] |= fsr;
+		if (!(task_thread_info(child)->fpsaved[0] & FPRS_FEF))
+			task_thread_info(child)->gsr[0] = 0;
+		task_thread_info(child)->fpsaved[0] |= (FPRS_FEF | FPRS_DL);
 		pt_succ_return(regs, 0);
 		goto out_tsk;
 	}
@@ -501,17 +501,17 @@
 			unsigned long fsr;
 		};
 		struct fps __user *fps = (struct fps __user *) addr;
-		unsigned long *fpregs = child->thread_info->fpregs;
+		unsigned long *fpregs = task_thread_info(child)->fpregs;
 
 		if (copy_from_user(fpregs, &fps->regs[0],
 				   (64 * sizeof(unsigned int))) ||
-		    __get_user(child->thread_info->xfsr[0], (&fps->fsr))) {
+		    __get_user(task_thread_info(child)->xfsr[0], (&fps->fsr))) {
 			pt_error_return(regs, EFAULT);
 			goto out_tsk;
 		}
-		if (!(child->thread_info->fpsaved[0] & FPRS_FEF))
-			child->thread_info->gsr[0] = 0;
-		child->thread_info->fpsaved[0] |= (FPRS_FEF | FPRS_DL | FPRS_DU);
+		if (!(task_thread_info(child)->fpsaved[0] & FPRS_FEF))
+			task_thread_info(child)->gsr[0] = 0;
+		task_thread_info(child)->fpsaved[0] |= (FPRS_FEF | FPRS_DL | FPRS_DU);
 		pt_succ_return(regs, 0);
 		goto out_tsk;
 	}
@@ -562,8 +562,8 @@
 #ifdef DEBUG_PTRACE
 		printk("CONT: %s [%d]: set exit_code = %x %lx %lx\n", child->comm,
 			child->pid, child->exit_code,
-			child->thread_info->kregs->tpc,
-			child->thread_info->kregs->tnpc);
+			task_pt_regs(child)->tpc,
+			task_pt_regs(child)->tnpc);
 		       
 #endif
 		wake_up_process(child);
diff --git a/arch/sparc64/kernel/setup.c b/arch/sparc64/kernel/setup.c
index 4818053..2507458 100644
--- a/arch/sparc64/kernel/setup.c
+++ b/arch/sparc64/kernel/setup.c
@@ -520,7 +520,7 @@
 	rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);	
 #endif
 
-	init_task.thread_info->kregs = &fake_swapper_regs;
+	task_thread_info(&init_task)->kregs = &fake_swapper_regs;
 
 #ifdef CONFIG_IP_PNP
 	if (!ic_set_manually) {
diff --git a/arch/sparc64/kernel/smp.c b/arch/sparc64/kernel/smp.c
index 6efc03df..1fb6323 100644
--- a/arch/sparc64/kernel/smp.c
+++ b/arch/sparc64/kernel/smp.c
@@ -335,7 +335,7 @@
 
 	p = fork_idle(cpu);
 	callin_flag = 0;
-	cpu_new_thread = p->thread_info;
+	cpu_new_thread = task_thread_info(p);
 	cpu_set(cpu, cpu_callout_map);
 
 	cpu_find_by_mid(cpu, &cpu_node);
diff --git a/arch/sparc64/kernel/sparc64_ksyms.c b/arch/sparc64/kernel/sparc64_ksyms.c
index fb7a537..d177d7e 100644
--- a/arch/sparc64/kernel/sparc64_ksyms.c
+++ b/arch/sparc64/kernel/sparc64_ksyms.c
@@ -94,7 +94,6 @@
 
 extern int __ashrdi3(int, int);
 
-extern void dump_thread(struct pt_regs *, struct user *);
 extern int dump_fpu (struct pt_regs * regs, elf_fpregset_t * fpregs);
 
 extern unsigned long phys_base;
@@ -241,7 +240,6 @@
 EXPORT_SYMBOL(_sigpause_common);
 EXPORT_SYMBOL(verify_compat_iovec);
 
-EXPORT_SYMBOL(dump_thread);
 EXPORT_SYMBOL(dump_fpu);
 EXPORT_SYMBOL(pte_alloc_one_kernel);
 #ifndef CONFIG_SMP
diff --git a/arch/sparc64/kernel/sys_sparc32.c b/arch/sparc64/kernel/sys_sparc32.c
index 7f6239e..d4b7a10 100644
--- a/arch/sparc64/kernel/sys_sparc32.c
+++ b/arch/sparc64/kernel/sys_sparc32.c
@@ -11,6 +11,7 @@
 #include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
+#include <linux/capability.h>
 #include <linux/fs.h> 
 #include <linux/mm.h> 
 #include <linux/file.h> 
@@ -1120,39 +1121,3 @@
 	return sys_lookup_dcookie((cookie_high << 32) | cookie_low,
 				  buf, len);
 }
-
-extern asmlinkage long
-sys_timer_create(clockid_t which_clock,
-		 struct sigevent __user *timer_event_spec,
-		 timer_t __user *created_timer_id);
-
-long
-sys32_timer_create(u32 clock, struct compat_sigevent __user *se32,
-		   timer_t __user *timer_id)
-{
-	struct sigevent se;
-	mm_segment_t oldfs;
-	timer_t t;
-	long err;
-
-	if (se32 == NULL)
-		return sys_timer_create(clock, NULL, timer_id);
-
-	if (get_compat_sigevent(&se, se32))
-		return -EFAULT;
-
-	if (!access_ok(VERIFY_WRITE,timer_id,sizeof(timer_t)))
-		return -EFAULT;
-
-	oldfs = get_fs();
-	set_fs(KERNEL_DS);
-	err = sys_timer_create(clock,
-			       (struct sigevent __user *) &se,
-			       (timer_t __user *) &t);
-	set_fs(oldfs);
-
-	if (!err)
-		err = __put_user (t, timer_id);
-
-	return err;
-}
diff --git a/arch/sparc64/kernel/sys_sunos32.c b/arch/sparc64/kernel/sys_sunos32.c
index bfa4aa6..ae5b32f 100644
--- a/arch/sparc64/kernel/sys_sunos32.c
+++ b/arch/sparc64/kernel/sys_sunos32.c
@@ -12,6 +12,7 @@
 #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/types.h>
+#include <linux/capability.h>
 #include <linux/compat.h>
 #include <linux/mman.h>
 #include <linux/mm.h>
diff --git a/arch/sparc64/kernel/systbls.S b/arch/sparc64/kernel/systbls.S
index 53eaf23..98d24bc 100644
--- a/arch/sparc64/kernel/systbls.S
+++ b/arch/sparc64/kernel/systbls.S
@@ -73,7 +73,7 @@
 /*250*/	.word sys32_mremap, sys32_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
 	.word sys_ni_syscall, sys32_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
 /*260*/	.word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
-	.word sys_timer_delete, sys32_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
+	.word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
 /*270*/	.word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
 	.word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
 /*280*/	.word sys_ni_syscall, sys_add_key, sys_request_key, sys_keyctl
@@ -98,7 +98,7 @@
 	.word sys_umount, sys_setgid, sys_getgid, sys_signal, sys_geteuid
 /*50*/	.word sys_getegid, sys_acct, sys_memory_ordering, sys_nis_syscall, sys_ioctl
 	.word sys_reboot, sys_nis_syscall, sys_symlink, sys_readlink, sys_execve
-/*60*/	.word sys_umask, sys_chroot, sys_newfstat, sys_stat64, sys_getpagesize
+/*60*/	.word sys_umask, sys_chroot, sys_newfstat, sys_fstat64, sys_getpagesize
 	.word sys_msync, sys_vfork, sys_pread64, sys_pwrite64, sys_nis_syscall
 /*70*/	.word sys_nis_syscall, sys_mmap, sys_nis_syscall, sys64_munmap, sys_mprotect
 	.word sys_madvise, sys_vhangup, sys_nis_syscall, sys_mincore, sys_getgroups
diff --git a/arch/sparc64/kernel/traps.c b/arch/sparc64/kernel/traps.c
index 5570e7b..8d44ae5 100644
--- a/arch/sparc64/kernel/traps.c
+++ b/arch/sparc64/kernel/traps.c
@@ -1808,7 +1808,7 @@
 void show_stack(struct task_struct *tsk, unsigned long *_ksp)
 {
 	unsigned long pc, fp, thread_base, ksp;
-	struct thread_info *tp = tsk->thread_info;
+	void *tp = task_stack_page(tsk);
 	struct reg_window *rw;
 	int count = 0;
 
@@ -1862,7 +1862,7 @@
 			return 0;
 	}
 
-	thread_base = (unsigned long) task->thread_info;
+	thread_base = (unsigned long) task_stack_page(task);
 	thread_end = thread_base + sizeof(union thread_union);
 	if (rw_addr >= thread_base &&
 	    rw_addr < thread_end &&
diff --git a/arch/sparc64/solaris/fs.c b/arch/sparc64/solaris/fs.c
index d7c99fa..4885ca6 100644
--- a/arch/sparc64/solaris/fs.c
+++ b/arch/sparc64/solaris/fs.c
@@ -10,6 +10,7 @@
 #include <linux/types.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
+#include <linux/capability.h>
 #include <linux/fs.h>
 #include <linux/namei.h>
 #include <linux/mm.h>
diff --git a/arch/um/Kconfig b/arch/um/Kconfig
index b4ff2e5..8ff3bcb 100644
--- a/arch/um/Kconfig
+++ b/arch/um/Kconfig
@@ -35,12 +35,12 @@
 
 config MODE_TT
 	bool "Tracing thread support"
-	default y
+	default n
 	help
 	This option controls whether tracing thread support is compiled
-	into UML.  Normally, this should be set to Y.  If you intend to
-	use only skas mode (and the host has the skas patch applied to it),
-	then it is OK to say N here.
+	into UML.  This option is largely obsolete, given that skas0 provides
+	skas security and performance without needing to patch the host.
+	It is safe to say 'N' here.
 
 config STATIC_LINK
 	bool "Force a static link"
diff --git a/arch/um/Makefile b/arch/um/Makefile
index 1b12fee..322972f 100644
--- a/arch/um/Makefile
+++ b/arch/um/Makefile
@@ -189,6 +189,12 @@
 	sed 's/ CONFIG/ UML_CONFIG/'
 endef
 
+$(ARCH_DIR)/include/uml-config.h : include/linux/autoconf.h
+	$(call filechk,umlconfig)
+
+$(ARCH_DIR)/user-offsets.s: $(ARCH_DIR)/sys-$(SUBARCH)/user-offsets.c
+	$(CC) $(USER_CFLAGS) -S -o $@ $<
+
 define filechk_gen-asm-offsets
         (set -e; \
          echo "/*"; \
@@ -202,24 +208,13 @@
          echo ""; )
 endef
 
-$(ARCH_DIR)/include/uml-config.h : include/linux/autoconf.h
-	$(call filechk,umlconfig)
-
-$(ARCH_DIR)/user-offsets.s: $(ARCH_DIR)/sys-$(SUBARCH)/user-offsets.c
-	$(CC) $(USER_CFLAGS) -S -o $@ $<
-
 $(ARCH_DIR)/include/user_constants.h: $(ARCH_DIR)/user-offsets.s
 	$(call filechk,gen-asm-offsets)
 
 CLEAN_FILES += $(ARCH_DIR)/user-offsets.s
 
-$(ARCH_DIR)/kernel-offsets.s: $(ARCH_DIR)/sys-$(SUBARCH)/kernel-offsets.c \
-				   archprepare
-	$(CC) $(CFLAGS) $(NOSTDINC_FLAGS) $(CPPFLAGS) -S -o $@ $<
-
-$(ARCH_DIR)/include/kern_constants.h: $(ARCH_DIR)/kernel-offsets.s
-	$(call filechk,gen-asm-offsets)
-
-CLEAN_FILES += $(ARCH_DIR)/kernel-offsets.s
+$(ARCH_DIR)/include/kern_constants.h:
+	@echo '  SYMLINK $@'
+	$(Q) ln -sf ../../../include/asm-um/asm-offsets.h $@
 
 export SUBARCH USER_CFLAGS OS
diff --git a/arch/um/drivers/chan_kern.c b/arch/um/drivers/chan_kern.c
index cd13b91..ab0d0b1 100644
--- a/arch/um/drivers/chan_kern.c
+++ b/arch/um/drivers/chan_kern.c
@@ -186,9 +186,6 @@
 		}
 	}
 
-	if((tty->flip.flag_buf_ptr == NULL) ||
-	   (tty->flip.char_buf_ptr == NULL))
-		return;
 	tty_insert_flip_char(tty, ch, TTY_NORMAL);
 }
 
@@ -653,8 +650,7 @@
 		chan = list_entry(ele, struct chan, list);
 		if(!chan->input || (chan->ops->read == NULL)) continue;
 		do {
-			if((tty != NULL) &&
-			   (tty->flip.count >= TTY_FLIPBUF_SIZE)){
+			if (tty && !tty_buffer_request_room(tty, 1)) {
 				schedule_delayed_work(task, 1);
 				goto out;
 			}
diff --git a/arch/um/drivers/mconsole_kern.c b/arch/um/drivers/mconsole_kern.c
index be61012..e3d5765 100644
--- a/arch/um/drivers/mconsole_kern.c
+++ b/arch/um/drivers/mconsole_kern.c
@@ -500,7 +500,7 @@
 
 static struct console mc_console = { .name	= "mc",
 				     .write	= console_write,
-				     .flags	= CON_PRINTBUFFER | CON_ENABLED,
+				     .flags	= CON_ENABLED,
 				     .index	= -1 };
 
 static int mc_add_console(void)
diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c
index 3a93c6f..7696f8d 100644
--- a/arch/um/drivers/ubd_kern.c
+++ b/arch/um/drivers/ubd_kern.c
@@ -1073,7 +1073,6 @@
 static int ubd_ioctl(struct inode * inode, struct file * file,
 		     unsigned int cmd, unsigned long arg)
 {
-	struct hd_geometry __user *loc = (struct hd_geometry __user *) arg;
 	struct ubd *dev = inode->i_bdev->bd_disk->private_data;
 	struct hd_driveid ubd_id = {
 		.cyls		= 0,
diff --git a/arch/um/sys-i386/kernel-offsets.c b/arch/um/include/sysdep-i386/kernel-offsets.h
similarity index 79%
rename from arch/um/sys-i386/kernel-offsets.c
rename to arch/um/include/sysdep-i386/kernel-offsets.h
index 35db850..82f96c5 100644
--- a/arch/um/sys-i386/kernel-offsets.c
+++ b/arch/um/include/sysdep-i386/kernel-offsets.h
@@ -1,12 +1,9 @@
-#include <linux/config.h>
 #include <linux/stddef.h>
 #include <linux/sched.h>
-#include <linux/time.h>
 #include <linux/elf.h>
-#include <asm/page.h>
 
 #define DEFINE(sym, val) \
-        asm volatile("\n->" #sym " %0 " #val : : "i" (val))
+	asm volatile("\n->" #sym " %0 " #val : : "i" (val))
 
 #define STR(x) #x
 #define DEFINE_STR(sym, val) asm volatile("\n->" #sym " " STR(val) " " #val: : )
diff --git a/arch/um/sys-x86_64/kernel-offsets.c b/arch/um/include/sysdep-x86_64/kernel-offsets.h
similarity index 89%
rename from arch/um/sys-x86_64/kernel-offsets.c
rename to arch/um/include/sysdep-x86_64/kernel-offsets.h
index bfcb104..5ce93abd 100644
--- a/arch/um/sys-x86_64/kernel-offsets.c
+++ b/arch/um/include/sysdep-x86_64/kernel-offsets.h
@@ -6,7 +6,7 @@
 #include <asm/page.h>
 
 #define DEFINE(sym, val) \
-        asm volatile("\n->" #sym " %0 " #val : : "i" (val))
+	asm volatile("\n->" #sym " %0 " #val : : "i" (val))
 
 #define DEFINE_STR1(x) #x
 #define DEFINE_STR(sym, val) asm volatile("\n->" #sym " " DEFINE_STR1(val) " " #val: : )
diff --git a/arch/um/kernel/asm-offsets.c b/arch/um/kernel/asm-offsets.c
index c13a64a..91ea538 100644
--- a/arch/um/kernel/asm-offsets.c
+++ b/arch/um/kernel/asm-offsets.c
@@ -1 +1 @@
-/* Dummy file to make kbuild happy - unused! */
+#include "sysdep/kernel-offsets.h"
diff --git a/arch/um/kernel/process_kern.c b/arch/um/kernel/process_kern.c
index d2d3f25..7f13b85 100644
--- a/arch/um/kernel/process_kern.c
+++ b/arch/um/kernel/process_kern.c
@@ -107,7 +107,7 @@
 {
 	struct task_struct *task = t;
 
-	cpu_tasks[task->thread_info->cpu] = ((struct cpu_task) 
+	cpu_tasks[task_thread_info(task)->cpu] = ((struct cpu_task)
 		{ external_pid(task), task });
 }
 
diff --git a/arch/um/kernel/skas/process.c b/arch/um/kernel/skas/process.c
index 9264d40..3b3955d 100644
--- a/arch/um/kernel/skas/process.c
+++ b/arch/um/kernel/skas/process.c
@@ -68,7 +68,7 @@
 
         if((n < 0) || !WIFSTOPPED(status) ||
            (WSTOPSIG(status) != SIGUSR1 && WSTOPSIG(status) != SIGTRAP)){
-		unsigned long regs[FRAME_SIZE];
+		unsigned long regs[HOST_FRAME_SIZE];
 		if(ptrace(PTRACE_GETREGS, pid, 0, regs) < 0)
 			printk("Failed to get registers from stub, "
 			       "errno = %d\n", errno);
@@ -76,7 +76,7 @@
 			int i;
 
 			printk("Stub registers -\n");
-			for(i = 0; i < FRAME_SIZE; i++)
+			for(i = 0; i < HOST_FRAME_SIZE; i++)
 				printk("\t%d - %lx\n", i, regs[i]);
 		}
                 panic("%s : failed to wait for SIGUSR1/SIGTRAP, "
diff --git a/arch/um/kernel/skas/process_kern.c b/arch/um/kernel/skas/process_kern.c
index 09790cc..dc41c6d 100644
--- a/arch/um/kernel/skas/process_kern.c
+++ b/arch/um/kernel/skas/process_kern.c
@@ -118,7 +118,7 @@
 		handler = new_thread_handler;
 	}
 
-	new_thread(p->thread_info, &p->thread.mode.skas.switch_buf,
+	new_thread(task_stack_page(p), &p->thread.mode.skas.switch_buf,
 		   &p->thread.mode.skas.fork_buf, handler);
 	return(0);
 }
@@ -185,7 +185,7 @@
 
 	init_task.thread.request.u.thread.proc = start_kernel_proc;
 	init_task.thread.request.u.thread.arg = NULL;
-	return(start_idle_thread(init_task.thread_info,
+	return(start_idle_thread(task_stack_page(&init_task),
 				 &init_task.thread.mode.skas.switch_buf,
 				 &init_task.thread.mode.skas.fork_buf));
 }
diff --git a/arch/um/kernel/time.c b/arch/um/kernel/time.c
index 11f518a..8fa2ae7 100644
--- a/arch/um/kernel/time.c
+++ b/arch/um/kernel/time.c
@@ -99,7 +99,8 @@
 	set_interval(ITIMER_REAL);
 }
 
-extern int do_posix_clock_monotonic_gettime(struct timespec *tp);
+extern void ktime_get_ts(struct timespec *ts);
+#define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts)
 
 void time_init(void)
 {
@@ -114,8 +115,8 @@
 	wall_to_monotonic.tv_nsec = -now.tv_nsec;
 }
 
-/* Declared in linux/time.h, which can't be included here */
-extern void clock_was_set(void);
+/* Defined in linux/ktimer.h, which can't be included here */
+#define clock_was_set()		do { } while (0)
 
 void do_gettimeofday(struct timeval *tv)
 {
diff --git a/arch/um/kernel/tt/exec_kern.c b/arch/um/kernel/tt/exec_kern.c
index 136e54c..8f40e48 100644
--- a/arch/um/kernel/tt/exec_kern.c
+++ b/arch/um/kernel/tt/exec_kern.c
@@ -39,7 +39,7 @@
 		do_exit(SIGKILL);
 	}
 		
-	new_pid = start_fork_tramp(current->thread_info, stack, 0, exec_tramp);
+	new_pid = start_fork_tramp(task_stack_page(current), stack, 0, exec_tramp);
 	if(new_pid < 0){
 		printk(KERN_ERR 
 		       "flush_thread : new thread failed, errno = %d\n",
diff --git a/arch/um/kernel/tt/process_kern.c b/arch/um/kernel/tt/process_kern.c
index 14d4622..6253530 100644
--- a/arch/um/kernel/tt/process_kern.c
+++ b/arch/um/kernel/tt/process_kern.c
@@ -36,7 +36,7 @@
 	from = prev;
 	to = next;
 
-	cpu = from->thread_info->cpu;
+	cpu = task_thread_info(from)->cpu;
 	if(cpu == 0)
 		forward_interrupts(to->thread.mode.tt.extern_pid);
 #ifdef CONFIG_SMP
@@ -253,7 +253,7 @@
 
 	clone_flags &= CLONE_VM;
 	p->thread.temp_stack = stack;
-	new_pid = start_fork_tramp(p->thread_info, stack, clone_flags, tramp);
+	new_pid = start_fork_tramp(task_stack_page(p), stack, clone_flags, tramp);
 	if(new_pid < 0){
 		printk(KERN_ERR "copy_thread : clone failed - errno = %d\n", 
 		       -new_pid);
@@ -343,7 +343,7 @@
 		pid = thread->request.u.exec.pid;
 		do_exec(thread->mode.tt.extern_pid, pid);
 		thread->mode.tt.extern_pid = pid;
-		cpu_tasks[task->thread_info->cpu].pid = pid;
+		cpu_tasks[task_thread_info(task)->cpu].pid = pid;
 		break;
 	case OP_FORK:
 		attach_process(thread->request.u.fork.pid);
@@ -425,7 +425,7 @@
 	int pages;
 
 	pages = (1 << CONFIG_KERNEL_STACK_ORDER);
-	sp = (void *) ((unsigned long) init_task.thread_info) +
+	sp = task_stack_page(&init_task) +
 		pages * PAGE_SIZE - sizeof(unsigned long);
 	return(tracer(start_kernel_proc, sp));
 }
diff --git a/arch/um/kernel/um_arch.c b/arch/um/kernel/um_arch.c
index 73747ac..e2d3ca4 100644
--- a/arch/um/kernel/um_arch.c
+++ b/arch/um/kernel/um_arch.c
@@ -243,10 +243,6 @@
 	return(0);
 }
 
-#else
-
-#error Either CONFIG_MODE_TT or CONFIG_MODE_SKAS must be enabled
-
 #endif
 #endif
 #endif
diff --git a/arch/v850/kernel/process.c b/arch/v850/kernel/process.c
index 39cf247..eb90993 100644
--- a/arch/v850/kernel/process.c
+++ b/arch/v850/kernel/process.c
@@ -114,7 +114,7 @@
 		 struct task_struct *p, struct pt_regs *regs)
 {
 	/* Start pushing stuff from the top of the child's kernel stack.  */
-	unsigned long orig_ksp = (unsigned long)p->thread_info + THREAD_SIZE;
+	unsigned long orig_ksp = task_tos(p);
 	unsigned long ksp = orig_ksp;
 	/* We push two `state save' stack fames (see entry.S) on the new
 	   kernel stack:
@@ -164,30 +164,6 @@
 }
 
 /*
- * fill in the user structure for a core dump..
- */
-void dump_thread (struct pt_regs *regs, struct user *dump)
-{
-#if 0  /* Later.  XXX */
-	dump->magic = CMAGIC;
-	dump->start_code = 0;
-	dump->start_stack = regs->gpr[GPR_SP];
-	dump->u_tsize = ((unsigned long) current->mm->end_code) >> PAGE_SHIFT;
-	dump->u_dsize = ((unsigned long) (current->mm->brk +
-					  (PAGE_SIZE-1))) >> PAGE_SHIFT;
-	dump->u_dsize -= dump->u_tsize;
-	dump->u_ssize = 0;
-
-	if (dump->start_stack < TASK_SIZE)
-		dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> PAGE_SHIFT;
-
-	dump->u_ar0 = (struct user_regs_struct *)((int)&dump->regs - (int)dump);
-	dump->regs = *regs;
-	dump->u_fpvalid = 0;
-#endif
-}
-
-/*
  * sys_execve() executes a new program.
  */
 int sys_execve (char *name, char **argv, char **envp, struct pt_regs *regs)
diff --git a/arch/v850/kernel/ptrace.c b/arch/v850/kernel/ptrace.c
index 18492d0..67e0575 100644
--- a/arch/v850/kernel/ptrace.c
+++ b/arch/v850/kernel/ptrace.c
@@ -58,7 +58,7 @@
 		regs = thread_saved_regs (t);
 	else
 		/* Register saved during kernel entry (or not available).  */
-		regs = task_regs (t);
+		regs = task_pt_regs (t);
 
 	return (v850_reg_t *)((char *)regs + reg_offs);
 }
diff --git a/arch/v850/kernel/v850_ksyms.c b/arch/v850/kernel/v850_ksyms.c
index 0ca6490..8ffc29c 100644
--- a/arch/v850/kernel/v850_ksyms.c
+++ b/arch/v850/kernel/v850_ksyms.c
@@ -21,8 +21,6 @@
 EXPORT_SYMBOL (trap_table);
 
 /* platform dependent support */
-extern void dump_thread (struct pt_regs *, struct user *);
-EXPORT_SYMBOL (dump_thread);
 EXPORT_SYMBOL (kernel_thread);
 EXPORT_SYMBOL (enable_irq);
 EXPORT_SYMBOL (disable_irq);
diff --git a/arch/x86_64/Kconfig b/arch/x86_64/Kconfig
index 4f3e925..2efc4be 100644
--- a/arch/x86_64/Kconfig
+++ b/arch/x86_64/Kconfig
@@ -69,12 +69,34 @@
 	bool
 	default y
 
+config DMI
+	bool
+	default y
+
 source "init/Kconfig"
 
 
 menu "Processor type and features"
 
 choice
+	prompt "Subarchitecture Type"
+	default X86_PC
+
+config X86_PC
+	bool "PC-compatible"
+	help
+	  Choose this option if your computer is a standard PC or compatible.
+
+config X86_VSMP
+	bool "Support for ScaleMP vSMP"
+	 help
+	  Support for ScaleMP vSMP systems.  Say 'Y' here if this kernel is
+	  supposed to run on these EM64T-based machines.  Only choose this option
+	  if you have one of these machines.
+
+endchoice
+
+choice
 	prompt "Processor family"
 	default MK8
 
@@ -347,32 +369,24 @@
 	depends on HPET_TIMER && RTC=y
 
 config GART_IOMMU
-	bool "IOMMU support"
+	bool "K8 GART IOMMU support"
 	default y
+	select SWIOTLB
 	depends on PCI
 	help
 	  Support the IOMMU. Needed to run systems with more than 3GB of memory
 	  properly with 32-bit PCI devices that do not support DAC (Double Address
 	  Cycle). The IOMMU can be turned off at runtime with the iommu=off parameter.
 	  Normally the kernel will take the right choice by itself.
-	  This option includes a driver for the AMD Opteron/Athlon64 IOMMU
-	  and a software emulation used on some other systems.
+	  This option includes a driver for the AMD Opteron/Athlon64 northbridge IOMMU
+	  and a software emulation used on other systems.
 	  If unsure, say Y.
 
 # need this always enabled with GART_IOMMU for the VIA workaround
 config SWIOTLB
-       bool
-       depends on GART_IOMMU
-       default y
-
-config DUMMY_IOMMU
 	bool
-	depends on !GART_IOMMU && !SWIOTLB
 	default y
-	help
-	  Don't use IOMMU code. This will cause problems when you have more than 4GB
-	  of memory and any 32-bit devices. Don't turn on unless you know what you
-	  are doing.
+	depends on GART_IOMMU
 
 config X86_MCE
 	bool "Machine check support" if EMBEDDED
@@ -399,17 +413,6 @@
 	   Additional support for AMD specific MCE features such as
 	   the DRAM Error Threshold.
 
-config PHYSICAL_START
-	hex "Physical address where the kernel is loaded" if EMBEDDED
-	default "0x100000"
-	help
-	  This gives the physical address where the kernel is loaded.
-	  Primarily used in the case of kexec on panic where the
-	  fail safe kernel needs to run at a different address than
-	  the panic-ed kernel.
-
-	  Don't change this unless you know what you are doing.
-
 config KEXEC
 	bool "kexec system call (EXPERIMENTAL)"
 	depends on EXPERIMENTAL
@@ -427,6 +430,31 @@
 	  support.  As of this writing the exact hardware interface is
 	  strongly in flux, so no good recommendation can be made.
 
+config CRASH_DUMP
+	bool "kernel crash dumps (EXPERIMENTAL)"
+	depends on EXPERIMENTAL
+	help
+		Generate crash dump after being started by kexec.
+
+config PHYSICAL_START
+	hex "Physical address where the kernel is loaded" if (EMBEDDED || CRASH_DUMP)
+	default "0x1000000" if CRASH_DUMP
+	default "0x100000"
+	help
+	  This gives the physical address where the kernel is loaded. Normally
+	  for regular kernels this value is 0x100000 (1MB). But in the case
+	  of kexec on panic the fail safe kernel needs to run at a different
+	  address than the panic-ed kernel. This option is used to set the load
+	  address for kernels used to capture crash dump on being kexec'ed
+	  after panic. The default value for crash dump kernels is
+	  0x1000000 (16MB). This can also be set based on the "X" value as
+	  specified in the "crashkernel=YM@XM" command line boot parameter
+	  passed to the panic-ed kernel. Typically this parameter is set as
+	  crashkernel=64M@16M. Please take a look at
+	  Documentation/kdump/kdump.txt for more details about crash dumps.
+
+	  Don't change this unless you know what you are doing.
+
 config SECCOMP
 	bool "Enable seccomp to safely compute untrusted bytecode"
 	depends on PROC_FS
diff --git a/arch/x86_64/Makefile b/arch/x86_64/Makefile
index a9cd42e..d7fd464 100644
--- a/arch/x86_64/Makefile
+++ b/arch/x86_64/Makefile
@@ -31,6 +31,7 @@
 cflags-$(CONFIG_MPSC) += $(call cc-option,-march=nocona)
 CFLAGS += $(cflags-y)
 
+CFLAGS += -m64
 CFLAGS += -mno-red-zone
 CFLAGS += -mcmodel=kernel
 CFLAGS += -pipe
@@ -38,8 +39,10 @@
 # actually it makes the kernel smaller too.
 CFLAGS += -fno-reorder-blocks	
 CFLAGS += -Wno-sign-compare
-ifneq ($(CONFIG_DEBUG_INFO),y)
+ifneq ($(CONFIG_UNWIND_INFO),y)
 CFLAGS += -fno-asynchronous-unwind-tables
+endif
+ifneq ($(CONFIG_DEBUG_INFO),y)
 # -fweb shrinks the kernel a bit, but the difference is very small
 # it also messes up debugging, so don't use it for now.
 #CFLAGS += $(call cc-option,-fweb)
@@ -50,6 +53,8 @@
 # prevent gcc from generating any FP code by mistake
 CFLAGS += $(call cc-option,-mno-sse -mno-mmx -mno-sse2 -mno-3dnow,)
 
+AFLAGS += -m64
+
 head-y := arch/x86_64/kernel/head.o arch/x86_64/kernel/head64.o arch/x86_64/kernel/init_task.o
 
 libs-y 					+= arch/x86_64/lib/
@@ -80,9 +85,12 @@
 bzdisk: vmlinux
 	$(Q)$(MAKE) $(build)=$(boot) BOOTIMAGE=$(BOOTIMAGE) zdisk
 
-install fdimage fdimage144 fdimage288: vmlinux
+fdimage fdimage144 fdimage288: vmlinux
 	$(Q)$(MAKE) $(build)=$(boot) BOOTIMAGE=$(BOOTIMAGE) $@
 
+install:
+	$(Q)$(MAKE) $(build)=$(boot) BOOTIMAGE=$(BOOTIMAGE) $@ 
+
 archclean:
 	$(Q)$(MAKE) $(clean)=$(boot)
 
diff --git a/arch/x86_64/boot/Makefile b/arch/x86_64/boot/Makefile
index 18c6e91..29f8396 100644
--- a/arch/x86_64/boot/Makefile
+++ b/arch/x86_64/boot/Makefile
@@ -98,5 +98,5 @@
 	cp System.map $(INSTALL_PATH)/
 	if [ -x /sbin/lilo ]; then /sbin/lilo; else /etc/lilo/install; fi
 
-install: $(BOOTIMAGE)
+install:
 	sh $(srctree)/$(src)/install.sh $(KERNELRELEASE) $(BOOTIMAGE) System.map "$(INSTALL_PATH)"
diff --git a/arch/x86_64/boot/install.sh b/arch/x86_64/boot/install.sh
index 198af15..baaa236 100644
--- a/arch/x86_64/boot/install.sh
+++ b/arch/x86_64/boot/install.sh
@@ -1,40 +1,2 @@
 #!/bin/sh
-#
-# arch/x86_64/boot/install.sh
-#
-# 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) 1995 by Linus Torvalds
-#
-# Adapted from code in arch/i386/boot/Makefile by H. Peter Anvin
-#
-# "make install" script for i386 architecture
-#
-# Arguments:
-#   $1 - kernel version
-#   $2 - kernel image file
-#   $3 - kernel map file
-#   $4 - default install path (blank if root directory)
-#
-
-# User may have a custom install script
-
-if [ -x ~/bin/${CROSS_COMPILE}installkernel ]; then exec ~/bin/${CROSS_COMPILE}installkernel "$@"; fi
-if [ -x /sbin/${CROSS_COMPILE}installkernel ]; then exec /sbin/${CROSS_COMPILE}installkernel "$@"; fi
-
-# Default install - same as make zlilo
-
-if [ -f $4/vmlinuz ]; then
-	mv $4/vmlinuz $4/vmlinuz.old
-fi
-
-if [ -f $4/System.map ]; then
-	mv $4/System.map $4/System.old
-fi
-
-cat $2 > $4/vmlinuz
-cp $3 $4/System.map
-
-if [ -x /sbin/lilo ]; then /sbin/lilo; else /etc/lilo/install; fi
+. $srctree/arch/i386/boot/install.sh
diff --git a/arch/x86_64/defconfig b/arch/x86_64/defconfig
index 5d56542..054dcd8 100644
--- a/arch/x86_64/defconfig
+++ b/arch/x86_64/defconfig
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.14-git7
-# Sat Nov  5 15:55:50 2005
+# Linux kernel version: 2.6.15-git7
+# Wed Jan 11 11:57:36 2006
 #
 CONFIG_X86_64=y
 CONFIG_64BIT=y
@@ -15,6 +15,7 @@
 CONFIG_GENERIC_ISA_DMA=y
 CONFIG_GENERIC_IOMAP=y
 CONFIG_ARCH_MAY_HAVE_PC_FDC=y
+CONFIG_DMI=y
 
 #
 # Code maturity level options
@@ -35,18 +36,21 @@
 # CONFIG_BSD_PROCESS_ACCT is not set
 CONFIG_SYSCTL=y
 # CONFIG_AUDIT is not set
-CONFIG_HOTPLUG=y
-CONFIG_KOBJECT_UEVENT=y
 CONFIG_IKCONFIG=y
 CONFIG_IKCONFIG_PROC=y
 # CONFIG_CPUSETS is not set
 CONFIG_INITRAMFS_SOURCE=""
+CONFIG_UID16=y
+CONFIG_VM86=y
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
 # CONFIG_EMBEDDED is not set
 CONFIG_KALLSYMS=y
 CONFIG_KALLSYMS_ALL=y
 # CONFIG_KALLSYMS_EXTRA_PASS is not set
+CONFIG_HOTPLUG=y
 CONFIG_PRINTK=y
 CONFIG_BUG=y
+CONFIG_ELF_CORE=y
 CONFIG_BASE_FULL=y
 CONFIG_FUTEX=y
 CONFIG_EPOLL=y
@@ -55,8 +59,10 @@
 CONFIG_CC_ALIGN_LABELS=0
 CONFIG_CC_ALIGN_LOOPS=0
 CONFIG_CC_ALIGN_JUMPS=0
+CONFIG_SLAB=y
 # CONFIG_TINY_SHMEM is not set
 CONFIG_BASE_SMALL=0
+# CONFIG_SLOB is not set
 
 #
 # Loadable module support
@@ -71,8 +77,28 @@
 CONFIG_STOP_MACHINE=y
 
 #
+# Block layer
+#
+CONFIG_LBD=y
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+# CONFIG_IOSCHED_AS is not set
+CONFIG_IOSCHED_DEADLINE=y
+CONFIG_IOSCHED_CFQ=y
+# CONFIG_DEFAULT_AS is not set
+# CONFIG_DEFAULT_DEADLINE is not set
+CONFIG_DEFAULT_CFQ=y
+# CONFIG_DEFAULT_NOOP is not set
+CONFIG_DEFAULT_IOSCHED="cfq"
+
+#
 # Processor type and features
 #
+CONFIG_X86_PC=y
+# CONFIG_X86_VSMP is not set
 # CONFIG_MK8 is not set
 # CONFIG_MPSC is not set
 CONFIG_GENERIC_CPU=y
@@ -89,14 +115,14 @@
 CONFIG_MTRR=y
 CONFIG_SMP=y
 CONFIG_SCHED_SMT=y
-CONFIG_PREEMPT_NONE=y
-# CONFIG_PREEMPT_VOLUNTARY is not set
+# CONFIG_PREEMPT_NONE is not set
+CONFIG_PREEMPT_VOLUNTARY=y
 # CONFIG_PREEMPT is not set
 CONFIG_PREEMPT_BKL=y
 CONFIG_NUMA=y
 CONFIG_K8_NUMA=y
 CONFIG_X86_64_ACPI_NUMA=y
-# CONFIG_NUMA_EMU is not set
+CONFIG_NUMA_EMU=y
 CONFIG_ARCH_DISCONTIGMEM_ENABLE=y
 CONFIG_ARCH_DISCONTIGMEM_DEFAULT=y
 CONFIG_ARCH_SPARSEMEM_ENABLE=y
@@ -109,6 +135,7 @@
 CONFIG_NEED_MULTIPLE_NODES=y
 # CONFIG_SPARSEMEM_STATIC is not set
 CONFIG_SPLIT_PTLOCK_CPUS=4
+CONFIG_MIGRATION=y
 CONFIG_HAVE_ARCH_EARLY_PFN_TO_NID=y
 CONFIG_NR_CPUS=32
 CONFIG_HOTPLUG_CPU=y
@@ -120,8 +147,9 @@
 CONFIG_X86_MCE=y
 CONFIG_X86_MCE_INTEL=y
 CONFIG_X86_MCE_AMD=y
-CONFIG_PHYSICAL_START=0x100000
 # CONFIG_KEXEC is not set
+# CONFIG_CRASH_DUMP is not set
+CONFIG_PHYSICAL_START=0x100000
 CONFIG_SECCOMP=y
 # CONFIG_HZ_100 is not set
 CONFIG_HZ_250=y
@@ -136,6 +164,7 @@
 # Power management options
 #
 CONFIG_PM=y
+# CONFIG_PM_LEGACY is not set
 # CONFIG_PM_DEBUG is not set
 CONFIG_SOFTWARE_SUSPEND=y
 CONFIG_PM_STD_PARTITION=""
@@ -152,7 +181,7 @@
 CONFIG_ACPI_BATTERY=y
 CONFIG_ACPI_BUTTON=y
 # CONFIG_ACPI_VIDEO is not set
-CONFIG_ACPI_HOTKEY=m
+# CONFIG_ACPI_HOTKEY is not set
 CONFIG_ACPI_FAN=y
 CONFIG_ACPI_PROCESSOR=y
 CONFIG_ACPI_HOTPLUG_CPU=y
@@ -205,7 +234,7 @@
 CONFIG_PCI_DIRECT=y
 CONFIG_PCI_MMCONFIG=y
 CONFIG_UNORDERED_IO=y
-# CONFIG_PCIEPORTBUS is not set
+CONFIG_PCIEPORTBUS=y
 CONFIG_PCI_MSI=y
 # CONFIG_PCI_LEGACY_PROC is not set
 # CONFIG_PCI_DEBUG is not set
@@ -229,7 +258,6 @@
 CONFIG_IA32_AOUT=y
 CONFIG_COMPAT=y
 CONFIG_SYSVIPC_COMPAT=y
-CONFIG_UID16=y
 
 #
 # Networking
@@ -294,8 +322,11 @@
 # CONFIG_NET_DIVERT is not set
 # CONFIG_ECONET is not set
 # CONFIG_WAN_ROUTER is not set
+
+#
+# QoS and/or fair queueing
+#
 # CONFIG_NET_SCHED is not set
-# CONFIG_NET_CLS_ROUTE is not set
 
 #
 # Network testing
@@ -315,7 +346,7 @@
 #
 CONFIG_STANDALONE=y
 CONFIG_PREVENT_FIRMWARE_BUILD=y
-# CONFIG_FW_LOADER is not set
+CONFIG_FW_LOADER=y
 # CONFIG_DEBUG_DRIVER is not set
 
 #
@@ -356,21 +387,7 @@
 CONFIG_BLK_DEV_RAM_COUNT=16
 CONFIG_BLK_DEV_RAM_SIZE=4096
 CONFIG_BLK_DEV_INITRD=y
-CONFIG_LBD=y
 # CONFIG_CDROM_PKTCDVD is not set
-
-#
-# IO Schedulers
-#
-CONFIG_IOSCHED_NOOP=y
-# CONFIG_IOSCHED_AS is not set
-CONFIG_IOSCHED_DEADLINE=y
-CONFIG_IOSCHED_CFQ=y
-# CONFIG_DEFAULT_AS is not set
-CONFIG_DEFAULT_DEADLINE=y
-# CONFIG_DEFAULT_CFQ is not set
-# CONFIG_DEFAULT_NOOP is not set
-CONFIG_DEFAULT_IOSCHED="cfq"
 # CONFIG_ATA_OVER_ETH is not set
 
 #
@@ -410,7 +427,7 @@
 # CONFIG_BLK_DEV_AEC62XX is not set
 # CONFIG_BLK_DEV_ALI15X3 is not set
 CONFIG_BLK_DEV_AMD74XX=y
-# CONFIG_BLK_DEV_ATIIXP is not set
+CONFIG_BLK_DEV_ATIIXP=y
 # CONFIG_BLK_DEV_CMD64X is not set
 # CONFIG_BLK_DEV_TRIFLEX is not set
 # CONFIG_BLK_DEV_CY82C693 is not set
@@ -458,20 +475,21 @@
 # Some SCSI devices (e.g. CD jukebox) support multiple LUNs
 #
 # CONFIG_SCSI_MULTI_LUN is not set
-# CONFIG_SCSI_CONSTANTS is not set
+CONFIG_SCSI_CONSTANTS=y
 # CONFIG_SCSI_LOGGING is not set
 
 #
 # SCSI Transport Attributes
 #
 CONFIG_SCSI_SPI_ATTRS=y
-# CONFIG_SCSI_FC_ATTRS is not set
+CONFIG_SCSI_FC_ATTRS=y
 # CONFIG_SCSI_ISCSI_ATTRS is not set
 # CONFIG_SCSI_SAS_ATTRS is not set
 
 #
 # SCSI low-level drivers
 #
+# CONFIG_ISCSI_TCP is not set
 # CONFIG_BLK_DEV_3W_XXXX_RAID is not set
 # CONFIG_SCSI_3W_9XXX is not set
 # CONFIG_SCSI_ACARD is not set
@@ -485,11 +503,13 @@
 # CONFIG_AIC79XX_DEBUG_ENABLE is not set
 CONFIG_AIC79XX_DEBUG_MASK=0
 # CONFIG_AIC79XX_REG_PRETTY_PRINT is not set
-# CONFIG_MEGARAID_NEWGEN is not set
+CONFIG_MEGARAID_NEWGEN=y
+CONFIG_MEGARAID_MM=y
+CONFIG_MEGARAID_MAILBOX=y
 # CONFIG_MEGARAID_LEGACY is not set
-# CONFIG_MEGARAID_SAS is not set
+CONFIG_MEGARAID_SAS=y
 CONFIG_SCSI_SATA=y
-# CONFIG_SCSI_SATA_AHCI is not set
+CONFIG_SCSI_SATA_AHCI=y
 # CONFIG_SCSI_SATA_SVW is not set
 CONFIG_SCSI_ATA_PIIX=y
 # CONFIG_SCSI_SATA_MV is not set
@@ -498,7 +518,7 @@
 # CONFIG_SCSI_SATA_QSTOR is not set
 # CONFIG_SCSI_SATA_PROMISE is not set
 # CONFIG_SCSI_SATA_SX4 is not set
-# CONFIG_SCSI_SATA_SIL is not set
+CONFIG_SCSI_SATA_SIL=y
 # CONFIG_SCSI_SATA_SIL24 is not set
 # CONFIG_SCSI_SATA_SIS is not set
 # CONFIG_SCSI_SATA_ULI is not set
@@ -518,12 +538,7 @@
 # CONFIG_SCSI_QLOGIC_FC is not set
 # CONFIG_SCSI_QLOGIC_1280 is not set
 CONFIG_SCSI_QLA2XXX=y
-# CONFIG_SCSI_QLA21XX is not set
-# CONFIG_SCSI_QLA22XX is not set
-# CONFIG_SCSI_QLA2300 is not set
-# CONFIG_SCSI_QLA2322 is not set
-# CONFIG_SCSI_QLA6312 is not set
-# CONFIG_SCSI_QLA24XX is not set
+# CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE is not set
 # CONFIG_SCSI_LPFC is not set
 # CONFIG_SCSI_DC395x is not set
 # CONFIG_SCSI_DC390T is not set
@@ -633,6 +648,7 @@
 # CONFIG_R8169 is not set
 # CONFIG_SIS190 is not set
 # CONFIG_SKGE is not set
+# CONFIG_SKY2 is not set
 # CONFIG_SK98LIN is not set
 # CONFIG_VIA_VELOCITY is not set
 CONFIG_TIGON3=y
@@ -645,7 +661,6 @@
 # CONFIG_IXGB is not set
 CONFIG_S2IO=m
 # CONFIG_S2IO_NAPI is not set
-# CONFIG_2BUFF_MODE is not set
 
 #
 # Token Ring devices
@@ -744,6 +759,7 @@
 CONFIG_SERIAL_8250_CONSOLE=y
 # CONFIG_SERIAL_8250_ACPI is not set
 CONFIG_SERIAL_8250_NR_UARTS=4
+CONFIG_SERIAL_8250_RUNTIME_UARTS=4
 # CONFIG_SERIAL_8250_EXTENDED is not set
 
 #
@@ -751,7 +767,6 @@
 #
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
-# CONFIG_SERIAL_JSM is not set
 CONFIG_UNIX98_PTYS=y
 CONFIG_LEGACY_PTYS=y
 CONFIG_LEGACY_PTY_COUNT=256
@@ -817,10 +832,10 @@
 # CONFIG_DRM is not set
 # CONFIG_MWAVE is not set
 CONFIG_RAW_DRIVER=y
+CONFIG_MAX_RAW_DEVS=256
 CONFIG_HPET=y
 # CONFIG_HPET_RTC_IRQ is not set
 CONFIG_HPET_MMAP=y
-CONFIG_MAX_RAW_DEVS=256
 # CONFIG_HANGCHECK_TIMER is not set
 
 #
@@ -892,6 +907,7 @@
 # Open Sound System
 #
 CONFIG_SOUND_PRIME=y
+CONFIG_OBSOLETE_OSS_DRIVER=y
 # CONFIG_SOUND_BT878 is not set
 # CONFIG_SOUND_CMPCI is not set
 # CONFIG_SOUND_EMU10K1 is not set
@@ -968,7 +984,8 @@
 # CONFIG_USB_STORAGE_SDDR09 is not set
 # CONFIG_USB_STORAGE_SDDR55 is not set
 # CONFIG_USB_STORAGE_JUMPSHOT is not set
-# CONFIG_USB_STORAGE_ONETOUCH is not set
+# CONFIG_USB_STORAGE_ALAUDA is not set
+# CONFIG_USB_LIBUSUAL is not set
 
 #
 # USB Input Devices
@@ -988,6 +1005,7 @@
 # CONFIG_USB_YEALINK is not set
 # CONFIG_USB_XPAD is not set
 # CONFIG_USB_ATI_REMOTE is not set
+# CONFIG_USB_ATI_REMOTE2 is not set
 # CONFIG_USB_KEYSPAN_REMOTE is not set
 # CONFIG_USB_APPLETOUCH is not set
 
@@ -1097,6 +1115,7 @@
 # CONFIG_JFS_FS is not set
 CONFIG_FS_POSIX_ACL=y
 # CONFIG_XFS_FS is not set
+# CONFIG_OCFS2_FS is not set
 # CONFIG_MINIX_FS is not set
 # CONFIG_ROMFS_FS is not set
 CONFIG_INOTIFY=y
@@ -1135,6 +1154,7 @@
 CONFIG_HUGETLB_PAGE=y
 CONFIG_RAMFS=y
 CONFIG_RELAYFS_FS=y
+# CONFIG_CONFIGFS_FS is not set
 
 #
 # Miscellaneous filesystems
@@ -1232,21 +1252,23 @@
 CONFIG_NLS_UTF8=y
 
 #
-# Profiling support
+# Instrumentation Support
 #
 CONFIG_PROFILING=y
 CONFIG_OPROFILE=y
+CONFIG_KPROBES=y
 
 #
 # Kernel hacking
 #
 # CONFIG_PRINTK_TIME is not set
-CONFIG_DEBUG_KERNEL=y
 CONFIG_MAGIC_SYSRQ=y
+CONFIG_DEBUG_KERNEL=y
 CONFIG_LOG_BUF_SHIFT=18
 CONFIG_DETECT_SOFTLOCKUP=y
 # CONFIG_SCHEDSTATS is not set
 # CONFIG_DEBUG_SLAB is not set
+# CONFIG_DEBUG_MUTEXES is not set
 # CONFIG_DEBUG_SPINLOCK is not set
 # CONFIG_DEBUG_SPINLOCK_SLEEP is not set
 # CONFIG_DEBUG_KOBJECT is not set
@@ -1256,8 +1278,8 @@
 # CONFIG_FRAME_POINTER is not set
 # CONFIG_RCU_TORTURE_TEST is not set
 CONFIG_INIT_DEBUG=y
+# CONFIG_DEBUG_RODATA is not set
 # CONFIG_IOMMU_DEBUG is not set
-CONFIG_KPROBES=y
 
 #
 # Security options
diff --git a/arch/x86_64/ia32/Makefile b/arch/x86_64/ia32/Makefile
index f76217d..051608d 100644
--- a/arch/x86_64/ia32/Makefile
+++ b/arch/x86_64/ia32/Makefile
@@ -2,8 +2,7 @@
 # Makefile for the ia32 kernel emulation subsystem.
 #
 
-obj-$(CONFIG_IA32_EMULATION) := ia32entry.o sys_ia32.o ia32_ioctl.o \
-	ia32_signal.o tls32.o \
+obj-$(CONFIG_IA32_EMULATION) := ia32entry.o sys_ia32.o ia32_signal.o tls32.o \
 	ia32_binfmt.o fpu32.o ptrace32.o syscall32.o syscall32_syscall.o
 
 sysv-$(CONFIG_SYSVIPC) := ipc32.o
@@ -29,4 +28,3 @@
 
 AFLAGS_vsyscall-sysenter.o = -m32
 AFLAGS_vsyscall-syscall.o = -m32
-CFLAGS_ia32_ioctl.o += -Ifs/
diff --git a/arch/x86_64/ia32/ia32_binfmt.c b/arch/x86_64/ia32/ia32_binfmt.c
index 2b760d0..029bdda 100644
--- a/arch/x86_64/ia32/ia32_binfmt.c
+++ b/arch/x86_64/ia32/ia32_binfmt.c
@@ -197,8 +197,7 @@
 
 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);
-	--pp;
+	struct pt_regs *pp = task_pt_regs(t);
 	ELF_CORE_COPY_REGS((*elfregs), pp);
 	/* fix wrong segments */ 
 	(*elfregs)[7] = t->thread.ds; 
@@ -217,7 +216,7 @@
 	if (!tsk_used_math(tsk))
 		return 0;
 	if (!regs)
-		regs = ((struct pt_regs *)tsk->thread.rsp0) - 1;
+		regs = task_pt_regs(tsk);
 	if (tsk == current)
 		unlazy_fpu(tsk);
 	set_fs(KERNEL_DS); 
@@ -233,7 +232,7 @@
 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; 
+	struct pt_regs *regs = task_pt_regs(t);
 	if (!tsk_used_math(t))
 		return 0;
 	if (t == current)
diff --git a/arch/x86_64/ia32/ia32_ioctl.c b/arch/x86_64/ia32/ia32_ioctl.c
deleted file mode 100644
index e335bd0..0000000
--- a/arch/x86_64/ia32/ia32_ioctl.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/* $Id: ia32_ioctl.c,v 1.25 2002/10/11 07:17:06 ak Exp $
- * ioctl32.c: Conversion between 32bit and 64bit native ioctls.
- *
- * Copyright (C) 1997-2000  Jakub Jelinek  (jakub@redhat.com)
- * Copyright (C) 1998  Eddie C. Dost  (ecd@skynet.be)
- * Copyright (C) 2001,2002  Andi Kleen, SuSE Labs 
- *
- * These routines maintain argument size conversion between 32bit and 64bit
- * ioctls.
- */
-
-#define INCLUDES
-#include <linux/syscalls.h>
-#include "compat_ioctl.c"
-#include <asm/ia32.h>
-
-#define CODE
-#include "compat_ioctl.c"
-  
-#define RTC_IRQP_READ32	_IOR('p', 0x0b, unsigned int)	 /* Read IRQ rate   */
-#define RTC_IRQP_SET32	_IOW('p', 0x0c, unsigned int)	 /* Set IRQ rate    */
-#define RTC_EPOCH_READ32	_IOR('p', 0x0d, unsigned)	 /* Read epoch      */
-#define RTC_EPOCH_SET32		_IOW('p', 0x0e, unsigned)	 /* Set epoch       */
-
-static int rtc32_ioctl(unsigned fd, unsigned cmd, unsigned long arg) 
-{ 
-	unsigned long val;
-	mm_segment_t oldfs = get_fs(); 
-	int ret; 
-	
-	switch (cmd) { 
-	case RTC_IRQP_READ32: 
-		set_fs(KERNEL_DS); 
-		ret = sys_ioctl(fd, RTC_IRQP_READ, (unsigned long)&val); 
-		set_fs(oldfs); 
-		if (!ret)
-			ret = put_user(val, (unsigned int __user *) arg); 
-		return ret; 
-
-	case RTC_IRQP_SET32: 
-		cmd = RTC_IRQP_SET; 
-		break; 
-
-	case RTC_EPOCH_READ32:
-		set_fs(KERNEL_DS); 
-		ret = sys_ioctl(fd, RTC_EPOCH_READ, (unsigned long) &val); 
-		set_fs(oldfs); 
-		if (!ret)
-			ret = put_user(val, (unsigned int __user *) arg); 
-		return ret; 
-
-	case RTC_EPOCH_SET32:
-		cmd = RTC_EPOCH_SET; 
-		break; 
-	} 
-	return sys_ioctl(fd,cmd,arg); 
-} 
-
-
-#define HANDLE_IOCTL(cmd,handler) { (cmd), (ioctl_trans_handler_t)(handler) }, 
-#define COMPATIBLE_IOCTL(cmd) HANDLE_IOCTL(cmd,sys_ioctl)
-
-struct ioctl_trans ioctl_start[] = { 
-#include <linux/compat_ioctl.h>
-#define DECLARES
-#include "compat_ioctl.c"
-
-/* And these ioctls need translation */
-/* realtime device */
-HANDLE_IOCTL(RTC_IRQP_READ,  rtc32_ioctl)
-HANDLE_IOCTL(RTC_IRQP_READ32,rtc32_ioctl)
-HANDLE_IOCTL(RTC_IRQP_SET32, rtc32_ioctl)
-HANDLE_IOCTL(RTC_EPOCH_READ32, rtc32_ioctl)
-HANDLE_IOCTL(RTC_EPOCH_SET32, rtc32_ioctl)
-/* take care of sizeof(sizeof()) breakage */
-}; 
-
-int ioctl_table_size = ARRAY_SIZE(ioctl_start);
-
diff --git a/arch/x86_64/ia32/ia32_signal.c b/arch/x86_64/ia32/ia32_signal.c
index 0903cc1..e0a9243 100644
--- a/arch/x86_64/ia32/ia32_signal.c
+++ b/arch/x86_64/ia32/ia32_signal.c
@@ -353,7 +353,6 @@
 		 struct pt_regs *regs, unsigned int mask)
 {
 	int tmp, err = 0;
-	u32 eflags;
 
 	tmp = 0;
 	__asm__("movl %%gs,%0" : "=r"(tmp): "0"(tmp));
@@ -378,10 +377,7 @@
 	err |= __put_user(current->thread.trap_no, &sc->trapno);
 	err |= __put_user(current->thread.error_code, &sc->err);
 	err |= __put_user((u32)regs->rip, &sc->eip);
-	eflags = regs->eflags;
-	if (current->ptrace & PT_PTRACED)
-		eflags &= ~TF_MASK;
-	err |= __put_user((u32)eflags, &sc->eflags);
+	err |= __put_user((u32)regs->eflags, &sc->eflags);
 	err |= __put_user((u32)regs->rsp, &sc->esp_at_signal);
 
 	tmp = save_i387_ia32(current, fpstate, regs, 0);
@@ -505,13 +501,9 @@
 	regs->ss = __USER32_DS; 
 
 	set_fs(USER_DS);
-	if (regs->eflags & TF_MASK) {
-		if (current->ptrace & PT_PTRACED) {
-			ptrace_notify(SIGTRAP);
-		} else {
-			regs->eflags &= ~TF_MASK;
-		}
-	}
+    regs->eflags &= ~TF_MASK;
+    if (test_thread_flag(TIF_SINGLESTEP))
+        ptrace_notify(SIGTRAP);
 
 #if DEBUG_SIG
 	printk("SIG deliver (%s:%d): sp=%p pc=%p ra=%p\n",
@@ -605,13 +597,9 @@
 	regs->ss = __USER32_DS; 
 
 	set_fs(USER_DS);
-	if (regs->eflags & TF_MASK) {
-		if (current->ptrace & PT_PTRACED) {
-			ptrace_notify(SIGTRAP);
-		} else {
-			regs->eflags &= ~TF_MASK;
-		}
-	}
+    regs->eflags &= ~TF_MASK;
+    if (test_thread_flag(TIF_SINGLESTEP))
+        ptrace_notify(SIGTRAP);
 
 #if DEBUG_SIG
 	printk("SIG deliver (%s:%d): sp=%p pc=%p ra=%p\n",
diff --git a/arch/x86_64/ia32/ia32entry.S b/arch/x86_64/ia32/ia32entry.S
index 1f0ff5a..58f5bfb 100644
--- a/arch/x86_64/ia32/ia32entry.S
+++ b/arch/x86_64/ia32/ia32entry.S
@@ -35,6 +35,18 @@
 	movq	%rax,R8(%rsp)
 	.endm
 
+	.macro CFI_STARTPROC32 simple
+	CFI_STARTPROC	\simple
+	CFI_UNDEFINED	r8
+	CFI_UNDEFINED	r9
+	CFI_UNDEFINED	r10
+	CFI_UNDEFINED	r11
+	CFI_UNDEFINED	r12
+	CFI_UNDEFINED	r13
+	CFI_UNDEFINED	r14
+	CFI_UNDEFINED	r15
+	.endm
+
 /*
  * 32bit SYSENTER instruction entry.
  *
@@ -55,7 +67,7 @@
  * with the int 0x80 path.
  */ 	
 ENTRY(ia32_sysenter_target)
-	CFI_STARTPROC	simple
+	CFI_STARTPROC32	simple
 	CFI_DEF_CFA	rsp,0
 	CFI_REGISTER	rsp,rbp
 	swapgs
@@ -92,6 +104,7 @@
  	.quad 1b,ia32_badarg
  	.previous	
 	GET_THREAD_INFO(%r10)
+	orl    $TS_COMPAT,threadinfo_status(%r10)
 	testl  $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%r10)
 	CFI_REMEMBER_STATE
 	jnz  sysenter_tracesys
@@ -105,6 +118,7 @@
 	cli
 	testl	$_TIF_ALLWORK_MASK,threadinfo_flags(%r10)
 	jnz	int_ret_from_sys_call
+	andl    $~TS_COMPAT,threadinfo_status(%r10)
 	/* clear IF, that popfq doesn't enable interrupts early */
 	andl  $~0x200,EFLAGS-R11(%rsp) 
 	RESTORE_ARGS 1,24,1,1,1,1
@@ -161,7 +175,7 @@
  * with the int 0x80 path.	
  */ 	
 ENTRY(ia32_cstar_target)
-	CFI_STARTPROC	simple
+	CFI_STARTPROC32	simple
 	CFI_DEF_CFA	rsp,0
 	CFI_REGISTER	rip,rcx
 	/*CFI_REGISTER	rflags,r11*/
@@ -191,6 +205,7 @@
 	.quad 1b,ia32_badarg
 	.previous	
 	GET_THREAD_INFO(%r10)
+	orl   $TS_COMPAT,threadinfo_status(%r10)
 	testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%r10)
 	CFI_REMEMBER_STATE
 	jnz   cstar_tracesys
@@ -204,6 +219,7 @@
 	cli
 	testl $_TIF_ALLWORK_MASK,threadinfo_flags(%r10)
 	jnz  int_ret_from_sys_call
+	andl $~TS_COMPAT,threadinfo_status(%r10)
 	RESTORE_ARGS 1,-ARG_SKIP,1,1,1
 	movl RIP-ARGOFFSET(%rsp),%ecx
 	CFI_REGISTER rip,rcx
@@ -276,6 +292,7 @@
 	   this could be a problem. */
 	SAVE_ARGS 0,0,1
 	GET_THREAD_INFO(%r10)
+	orl   $TS_COMPAT,threadinfo_status(%r10)
 	testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%r10)
 	jnz ia32_tracesys
 ia32_do_syscall:	
@@ -318,7 +335,7 @@
 	jmp  ia32_ptregs_common	
 	.endm
 
-	CFI_STARTPROC
+	CFI_STARTPROC32
 
 	PTREGSCALL stub32_rt_sigreturn, sys32_rt_sigreturn, %rdi
 	PTREGSCALL stub32_sigreturn, sys32_sigreturn, %rdi
@@ -333,8 +350,19 @@
 
 ENTRY(ia32_ptregs_common)
 	popq %r11
-	CFI_ADJUST_CFA_OFFSET -8
-	CFI_REGISTER rip, r11
+	CFI_ENDPROC
+	CFI_STARTPROC32	simple
+	CFI_DEF_CFA	rsp,SS+8-ARGOFFSET
+	CFI_REL_OFFSET	rax,RAX-ARGOFFSET
+	CFI_REL_OFFSET	rcx,RCX-ARGOFFSET
+	CFI_REL_OFFSET	rdx,RDX-ARGOFFSET
+	CFI_REL_OFFSET	rsi,RSI-ARGOFFSET
+	CFI_REL_OFFSET	rdi,RDI-ARGOFFSET
+	CFI_REL_OFFSET	rip,RIP-ARGOFFSET
+/*	CFI_REL_OFFSET	cs,CS-ARGOFFSET*/
+/*	CFI_REL_OFFSET	rflags,EFLAGS-ARGOFFSET*/
+	CFI_REL_OFFSET	rsp,RSP-ARGOFFSET
+/*	CFI_REL_OFFSET	ss,SS-ARGOFFSET*/
 	SAVE_REST
 	call *%rax
 	RESTORE_REST
@@ -608,7 +636,7 @@
 	.quad sys_epoll_wait
 	.quad sys_remap_file_pages
 	.quad sys_set_tid_address
-	.quad sys32_timer_create
+	.quad compat_sys_timer_create
 	.quad compat_sys_timer_settime	/* 260 */
 	.quad compat_sys_timer_gettime
 	.quad sys_timer_getoverrun
diff --git a/arch/x86_64/ia32/ptrace32.c b/arch/x86_64/ia32/ptrace32.c
index 5f4cdfa..23a4515 100644
--- a/arch/x86_64/ia32/ptrace32.c
+++ b/arch/x86_64/ia32/ptrace32.c
@@ -28,9 +28,12 @@
 #include <asm/i387.h>
 #include <asm/fpu32.h>
 
-/* determines which flags the user has access to. */
-/* 1 = access 0 = no access */
-#define FLAG_MASK 0x44dd5UL
+/*
+ * Determines which flags the user has access to [1 = access, 0 = no access].
+ * Prohibits changing ID(21), VIP(20), VIF(19), VM(17), IOPL(12-13), IF(9).
+ * Also masks reserved bits (31-22, 15, 5, 3, 1).
+ */
+#define FLAG_MASK 0x54dd5UL
 
 #define R32(l,q) \
 	case offsetof(struct user32, regs.l): stack[offsetof(struct pt_regs, q)/8] = val; break
@@ -38,7 +41,7 @@
 static int putreg32(struct task_struct *child, unsigned regno, u32 val)
 {
 	int i;
-	__u64 *stack = (__u64 *)(child->thread.rsp0 - sizeof(struct pt_regs)); 
+	__u64 *stack = (__u64 *)task_pt_regs(child);
 
 	switch (regno) {
 	case offsetof(struct user32, regs.fs):
@@ -134,7 +137,7 @@
 
 static int getreg32(struct task_struct *child, unsigned regno, u32 *val)
 {
-	__u64 *stack = (__u64 *)(child->thread.rsp0 - sizeof(struct pt_regs)); 
+	__u64 *stack = (__u64 *)task_pt_regs(child);
 
 	switch (regno) {
 	case offsetof(struct user32, regs.fs):
@@ -235,7 +238,7 @@
 	if (ret < 0)
 		goto out;
 
-	childregs = (struct pt_regs *)(child->thread.rsp0 - sizeof(struct pt_regs)); 
+	childregs = task_pt_regs(child);
 
 	switch (request) {
 	case PTRACE_PEEKDATA:
diff --git a/arch/x86_64/ia32/sys_ia32.c b/arch/x86_64/ia32/sys_ia32.c
index 5389df6..54481af 100644
--- a/arch/x86_64/ia32/sys_ia32.c
+++ b/arch/x86_64/ia32/sys_ia32.c
@@ -969,25 +969,6 @@
 	return sys_kill(pid, sig);
 }
  
-extern asmlinkage long
-sys_timer_create(clockid_t which_clock,
-		 struct sigevent __user *timer_event_spec,
-		 timer_t __user * created_timer_id);
-
-long
-sys32_timer_create(u32 clock, struct compat_sigevent __user *se32, timer_t __user *timer_id)
-{
-	struct sigevent __user *p = NULL;
-	if (se32) { 
-		struct sigevent se;
-		p = compat_alloc_user_space(sizeof(struct sigevent));
-		if (get_compat_sigevent(&se, se32) ||
-		    copy_to_user(p, &se, sizeof(se)))
-			return -EFAULT;
-	} 
-	return sys_timer_create(clock, p, timer_id);
-} 
-
 long sys32_fadvise64_64(int fd, __u32 offset_low, __u32 offset_high, 
 			__u32 len_low, __u32 len_high, int advice)
 { 
diff --git a/arch/x86_64/ia32/vsyscall-sigreturn.S b/arch/x86_64/ia32/vsyscall-sigreturn.S
index 8b5a4b0..d90321f 100644
--- a/arch/x86_64/ia32/vsyscall-sigreturn.S
+++ b/arch/x86_64/ia32/vsyscall-sigreturn.S
@@ -7,6 +7,7 @@
  * by doing ".balign 32" must match in both versions of the page.
  */
 
+	.code32
 	.section .text.sigreturn,"ax"
 	.balign 32
 	.globl __kernel_sigreturn
diff --git a/arch/x86_64/ia32/vsyscall-syscall.S b/arch/x86_64/ia32/vsyscall-syscall.S
index b024965b..cf9ef67 100644
--- a/arch/x86_64/ia32/vsyscall-syscall.S
+++ b/arch/x86_64/ia32/vsyscall-syscall.S
@@ -6,6 +6,7 @@
 #include <asm/asm-offsets.h>
 #include <asm/segment.h>
 
+	.code32
 	.text
 	.section .text.vsyscall,"ax"
 	.globl __kernel_vsyscall
diff --git a/arch/x86_64/ia32/vsyscall-sysenter.S b/arch/x86_64/ia32/vsyscall-sysenter.S
index 71f3de5..ae056e5 100644
--- a/arch/x86_64/ia32/vsyscall-sysenter.S
+++ b/arch/x86_64/ia32/vsyscall-sysenter.S
@@ -5,6 +5,7 @@
 #include <asm/ia32_unistd.h>
 #include <asm/asm-offsets.h>
 
+	.code32
 	.text
 	.section .text.vsyscall,"ax"
 	.globl __kernel_vsyscall
diff --git a/arch/x86_64/kernel/Makefile b/arch/x86_64/kernel/Makefile
index fe4cbd1..72fe60c 100644
--- a/arch/x86_64/kernel/Makefile
+++ b/arch/x86_64/kernel/Makefile
@@ -7,7 +7,8 @@
 obj-y	:= process.o signal.o entry.o traps.o irq.o \
 		ptrace.o time.o ioport.o ldt.o setup.o i8259.o sys_x86_64.o \
 		x8664_ksyms.o i387.o syscall.o vsyscall.o \
-		setup64.o bootflag.o e820.o reboot.o quirks.o i8237.o
+		setup64.o bootflag.o e820.o reboot.o quirks.o i8237.o \
+		dmi_scan.o pci-dma.o pci-nommu.o
 
 obj-$(CONFIG_X86_MCE)         += mce.o
 obj-$(CONFIG_X86_MCE_INTEL)	+= mce_intel.o
@@ -22,14 +23,16 @@
 obj-$(CONFIG_X86_IO_APIC)	+= io_apic.o mpparse.o \
 		genapic.o genapic_cluster.o genapic_flat.o
 obj-$(CONFIG_KEXEC)		+= machine_kexec.o relocate_kernel.o crash.o
+obj-$(CONFIG_CRASH_DUMP)	+= crash_dump.o
 obj-$(CONFIG_PM)		+= suspend.o
 obj-$(CONFIG_SOFTWARE_SUSPEND)	+= suspend_asm.o
 obj-$(CONFIG_CPU_FREQ)		+= cpufreq/
 obj-$(CONFIG_EARLY_PRINTK)	+= early_printk.o
 obj-$(CONFIG_GART_IOMMU)	+= pci-gart.o aperture.o
-obj-$(CONFIG_DUMMY_IOMMU)	+= pci-nommu.o pci-dma.o
+obj-$(CONFIG_SWIOTLB)		+= pci-swiotlb.o
 obj-$(CONFIG_KPROBES)		+= kprobes.o
 obj-$(CONFIG_X86_PM_TIMER)	+= pmtimer.o
+obj-$(CONFIG_X86_VSMP)		+= vsmp.o
 
 obj-$(CONFIG_MODULES)		+= module.o
 
@@ -46,3 +49,5 @@
 quirks-y			+= ../../i386/kernel/quirks.o
 i8237-y				+= ../../i386/kernel/i8237.o
 msr-$(subst m,y,$(CONFIG_X86_MSR))  += ../../i386/kernel/msr.o
+dmi_scan-y			+= ../../i386/kernel/dmi_scan.o
+
diff --git a/arch/x86_64/kernel/aperture.c b/arch/x86_64/kernel/aperture.c
index c7f4fdd..e4e2b7d 100644
--- a/arch/x86_64/kernel/aperture.c
+++ b/arch/x86_64/kernel/aperture.c
@@ -23,6 +23,7 @@
 #include <asm/io.h>
 #include <asm/proto.h>
 #include <asm/pci-direct.h>
+#include <asm/dma.h>
 
 int iommu_aperture;
 int iommu_aperture_disabled __initdata = 0;
@@ -247,7 +248,7 @@
 		/* Got the aperture from the AGP bridge */
 	} else if (swiotlb && !valid_agp) {
 		/* Do nothing */
-	} else if ((!no_iommu && end_pfn >= 0xffffffff>>PAGE_SHIFT) ||
+	} else if ((!no_iommu && end_pfn >= MAX_DMA32_PFN) ||
 		   force_iommu ||
 		   valid_agp ||
 		   fallback_aper_force) { 
diff --git a/arch/x86_64/kernel/apic.c b/arch/x86_64/kernel/apic.c
index 18691ce..8fdd089 100644
--- a/arch/x86_64/kernel/apic.c
+++ b/arch/x86_64/kernel/apic.c
@@ -25,6 +25,7 @@
 #include <linux/mc146818rtc.h>
 #include <linux/kernel_stat.h>
 #include <linux/sysdev.h>
+#include <linux/module.h>
 
 #include <asm/atomic.h>
 #include <asm/smp.h>
@@ -33,36 +34,36 @@
 #include <asm/pgalloc.h>
 #include <asm/mach_apic.h>
 #include <asm/nmi.h>
+#include <asm/idle.h>
 
 int apic_verbosity;
 
 int disable_apic_timer __initdata;
 
+/*
+ * cpu_mask that denotes the CPUs that needs timer interrupt coming in as
+ * IPIs in place of local APIC timers
+ */
+static cpumask_t timer_interrupt_broadcast_ipi_mask;
+
 /* Using APIC to generate smp_local_timer_interrupt? */
 int using_apic_timer = 0;
 
-static DEFINE_PER_CPU(int, prof_multiplier) = 1;
-static DEFINE_PER_CPU(int, prof_old_multiplier) = 1;
-static DEFINE_PER_CPU(int, prof_counter) = 1;
-
 static void apic_pm_activate(void);
 
 void enable_NMI_through_LVT0 (void * dummy)
 {
-	unsigned int v, ver;
+	unsigned int v;
 	
-	ver = apic_read(APIC_LVR);
-	ver = GET_APIC_VERSION(ver);
 	v = APIC_DM_NMI;                        /* unmask and set to NMI */
-	apic_write_around(APIC_LVT0, v);
+	apic_write(APIC_LVT0, v);
 }
 
 int get_maxlvt(void)
 {
-	unsigned int v, ver, maxlvt;
+	unsigned int v, maxlvt;
 
 	v = apic_read(APIC_LVR);
-	ver = GET_APIC_VERSION(v);
 	maxlvt = GET_APIC_MAXLVT(v);
 	return maxlvt;
 }
@@ -80,33 +81,33 @@
 	 */
 	if (maxlvt >= 3) {
 		v = ERROR_APIC_VECTOR; /* any non-zero vector will do */
-		apic_write_around(APIC_LVTERR, v | APIC_LVT_MASKED);
+		apic_write(APIC_LVTERR, v | APIC_LVT_MASKED);
 	}
 	/*
 	 * Careful: we have to set masks only first to deassert
 	 * any level-triggered sources.
 	 */
 	v = apic_read(APIC_LVTT);
-	apic_write_around(APIC_LVTT, v | APIC_LVT_MASKED);
+	apic_write(APIC_LVTT, v | APIC_LVT_MASKED);
 	v = apic_read(APIC_LVT0);
-	apic_write_around(APIC_LVT0, v | APIC_LVT_MASKED);
+	apic_write(APIC_LVT0, v | APIC_LVT_MASKED);
 	v = apic_read(APIC_LVT1);
-	apic_write_around(APIC_LVT1, v | APIC_LVT_MASKED);
+	apic_write(APIC_LVT1, v | APIC_LVT_MASKED);
 	if (maxlvt >= 4) {
 		v = apic_read(APIC_LVTPC);
-		apic_write_around(APIC_LVTPC, v | APIC_LVT_MASKED);
+		apic_write(APIC_LVTPC, v | APIC_LVT_MASKED);
 	}
 
 	/*
 	 * Clean APIC state for other OSs:
 	 */
-	apic_write_around(APIC_LVTT, APIC_LVT_MASKED);
-	apic_write_around(APIC_LVT0, APIC_LVT_MASKED);
-	apic_write_around(APIC_LVT1, APIC_LVT_MASKED);
+	apic_write(APIC_LVTT, APIC_LVT_MASKED);
+	apic_write(APIC_LVT0, APIC_LVT_MASKED);
+	apic_write(APIC_LVT1, APIC_LVT_MASKED);
 	if (maxlvt >= 3)
-		apic_write_around(APIC_LVTERR, APIC_LVT_MASKED);
+		apic_write(APIC_LVTERR, APIC_LVT_MASKED);
 	if (maxlvt >= 4)
-		apic_write_around(APIC_LVTPC, APIC_LVT_MASKED);
+		apic_write(APIC_LVTPC, APIC_LVT_MASKED);
 	v = GET_APIC_VERSION(apic_read(APIC_LVR));
 	apic_write(APIC_ESR, 0);
 	apic_read(APIC_ESR);
@@ -151,7 +152,7 @@
 		value &= ~APIC_VECTOR_MASK;
 		value |= APIC_SPIV_APIC_ENABLED;
 		value |= 0xf;
-		apic_write_around(APIC_SPIV, value);
+		apic_write(APIC_SPIV, value);
 
 		if (!virt_wire_setup) {
 			/* For LVT0 make it edge triggered, active high, external and enabled */
@@ -161,11 +162,11 @@
 				APIC_LVT_LEVEL_TRIGGER | APIC_LVT_MASKED );
 			value |= APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING;
 			value = SET_APIC_DELIVERY_MODE(value, APIC_MODE_EXTINT);
-			apic_write_around(APIC_LVT0, value);
+			apic_write(APIC_LVT0, value);
 		}
 		else {
 			/* Disable LVT0 */
-			apic_write_around(APIC_LVT0, APIC_LVT_MASKED);
+			apic_write(APIC_LVT0, APIC_LVT_MASKED);
 		}
 
 		/* For LVT1 make it edge triggered, active high, nmi and enabled */
@@ -176,7 +177,7 @@
 			APIC_LVT_LEVEL_TRIGGER | APIC_LVT_MASKED);
 		value |= APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING;
 		value = SET_APIC_DELIVERY_MODE(value, APIC_MODE_NMI);
-		apic_write_around(APIC_LVT1, value);
+		apic_write(APIC_LVT1, value);
 	}
 }
 
@@ -192,7 +193,7 @@
 	 */
 	value = apic_read(APIC_SPIV);
 	value &= ~APIC_SPIV_APIC_ENABLED;
-	apic_write_around(APIC_SPIV, value);
+	apic_write(APIC_SPIV, value);
 }
 
 /*
@@ -269,7 +270,7 @@
 	apic_wait_icr_idle();
 
 	apic_printk(APIC_DEBUG, "Synchronizing Arb IDs.\n");
-	apic_write_around(APIC_ICR, APIC_DEST_ALLINC | APIC_INT_LEVELTRIG
+	apic_write(APIC_ICR, APIC_DEST_ALLINC | APIC_INT_LEVELTRIG
 				| APIC_DM_INIT);
 }
 
@@ -280,7 +281,7 @@
  */
 void __init init_bsp_APIC(void)
 {
-	unsigned int value, ver;
+	unsigned int value;
 
 	/*
 	 * Don't do the setup now if we have a SMP BIOS as the
@@ -290,7 +291,6 @@
 		return;
 
 	value = apic_read(APIC_LVR);
-	ver = GET_APIC_VERSION(value);
 
 	/*
 	 * Do not trust the local APIC being empty at bootup.
@@ -305,22 +305,21 @@
 	value |= APIC_SPIV_APIC_ENABLED;
 	value |= APIC_SPIV_FOCUS_DISABLED;
 	value |= SPURIOUS_APIC_VECTOR;
-	apic_write_around(APIC_SPIV, value);
+	apic_write(APIC_SPIV, value);
 
 	/*
 	 * Set up the virtual wire mode.
 	 */
-	apic_write_around(APIC_LVT0, APIC_DM_EXTINT);
+	apic_write(APIC_LVT0, APIC_DM_EXTINT);
 	value = APIC_DM_NMI;
-	apic_write_around(APIC_LVT1, value);
+	apic_write(APIC_LVT1, value);
 }
 
 void __cpuinit setup_local_APIC (void)
 {
-	unsigned int value, ver, maxlvt;
+	unsigned int value, maxlvt;
 
 	value = apic_read(APIC_LVR);
-	ver = GET_APIC_VERSION(value);
 
 	if ((SPURIOUS_APIC_VECTOR & 0x0f) != 0x0f)
 		__error_in_apic_c();
@@ -345,7 +344,7 @@
 	 */
 	value = apic_read(APIC_TASKPRI);
 	value &= ~APIC_TPRI_MASK;
-	apic_write_around(APIC_TASKPRI, value);
+	apic_write(APIC_TASKPRI, value);
 
 	/*
 	 * Now that we are all set up, enable the APIC
@@ -387,7 +386,7 @@
 	 * Set spurious IRQ vector
 	 */
 	value |= SPURIOUS_APIC_VECTOR;
-	apic_write_around(APIC_SPIV, value);
+	apic_write(APIC_SPIV, value);
 
 	/*
 	 * Set up LVT0, LVT1:
@@ -407,7 +406,7 @@
 		value = APIC_DM_EXTINT | APIC_LVT_MASKED;
 		apic_printk(APIC_VERBOSE, "masked ExtINT on CPU#%d\n", smp_processor_id());
 	}
-	apic_write_around(APIC_LVT0, value);
+	apic_write(APIC_LVT0, value);
 
 	/*
 	 * only the BP should see the LINT1 NMI signal, obviously.
@@ -416,14 +415,14 @@
 		value = APIC_DM_NMI;
 	else
 		value = APIC_DM_NMI | APIC_LVT_MASKED;
-	apic_write_around(APIC_LVT1, value);
+	apic_write(APIC_LVT1, value);
 
 	{
 		unsigned oldvalue;
 		maxlvt = get_maxlvt();
 		oldvalue = apic_read(APIC_ESR);
 		value = ERROR_APIC_VECTOR;      // enables sending errors
-		apic_write_around(APIC_LVTERR, value);
+		apic_write(APIC_LVTERR, value);
 		/*
 		 * spec says clear errors after enabling vector.
 		 */
@@ -660,20 +659,25 @@
 static void __setup_APIC_LVTT(unsigned int clocks)
 {
 	unsigned int lvtt_value, tmp_value, ver;
+	int cpu = smp_processor_id();
 
 	ver = GET_APIC_VERSION(apic_read(APIC_LVR));
 	lvtt_value = APIC_LVT_TIMER_PERIODIC | LOCAL_TIMER_VECTOR;
-	apic_write_around(APIC_LVTT, lvtt_value);
+
+	if (cpu_isset(cpu, timer_interrupt_broadcast_ipi_mask))
+		lvtt_value |= APIC_LVT_MASKED;
+
+	apic_write(APIC_LVTT, lvtt_value);
 
 	/*
 	 * Divide PICLK by 16
 	 */
 	tmp_value = apic_read(APIC_TDCR);
-	apic_write_around(APIC_TDCR, (tmp_value
+	apic_write(APIC_TDCR, (tmp_value
 				& ~(APIC_TDR_DIV_1 | APIC_TDR_DIV_TMBASE))
 				| APIC_TDR_DIV_16);
 
-	apic_write_around(APIC_TMICT, clocks/APIC_DIVISOR);
+	apic_write(APIC_TMICT, clocks/APIC_DIVISOR);
 }
 
 static void setup_APIC_timer(unsigned int clocks)
@@ -682,12 +686,6 @@
 
 	local_irq_save(flags);
 
-	/* For some reasons this doesn't work on Simics, so fake it for now */ 
-	if (!strstr(boot_cpu_data.x86_model_id, "Screwdriver")) { 
-	__setup_APIC_LVTT(clocks);
-		return;
-	} 
-
 	/* wait for irq slice */
  	if (vxtime.hpet_address) {
  		int trigger = hpet_readl(HPET_T0_CMP);
@@ -700,7 +698,7 @@
 		outb_p(0x00, 0x43);
 		c2 = inb_p(0x40);
 		c2 |= inb_p(0x40) << 8;
-	do {
+		do {
 			c1 = c2;
 			outb_p(0x00, 0x43);
 			c2 = inb_p(0x40);
@@ -785,52 +783,68 @@
 	local_irq_enable();
 }
 
-void __cpuinit disable_APIC_timer(void)
+void disable_APIC_timer(void)
 {
 	if (using_apic_timer) {
 		unsigned long v;
 
 		v = apic_read(APIC_LVTT);
-		apic_write_around(APIC_LVTT, v | APIC_LVT_MASKED);
+		apic_write(APIC_LVTT, v | APIC_LVT_MASKED);
 	}
 }
 
 void enable_APIC_timer(void)
 {
-	if (using_apic_timer) {
+	int cpu = smp_processor_id();
+
+	if (using_apic_timer &&
+	    !cpu_isset(cpu, timer_interrupt_broadcast_ipi_mask)) {
 		unsigned long v;
 
 		v = apic_read(APIC_LVTT);
-		apic_write_around(APIC_LVTT, v & ~APIC_LVT_MASKED);
+		apic_write(APIC_LVTT, v & ~APIC_LVT_MASKED);
 	}
 }
 
-/*
- * the frequency of the profiling timer can be changed
- * by writing a multiplier value into /proc/profile.
- */
+void switch_APIC_timer_to_ipi(void *cpumask)
+{
+	cpumask_t mask = *(cpumask_t *)cpumask;
+	int cpu = smp_processor_id();
+
+	if (cpu_isset(cpu, mask) &&
+	    !cpu_isset(cpu, timer_interrupt_broadcast_ipi_mask)) {
+		disable_APIC_timer();
+		cpu_set(cpu, timer_interrupt_broadcast_ipi_mask);
+	}
+}
+EXPORT_SYMBOL(switch_APIC_timer_to_ipi);
+
+void smp_send_timer_broadcast_ipi(void)
+{
+	cpumask_t mask;
+
+	cpus_and(mask, cpu_online_map, timer_interrupt_broadcast_ipi_mask);
+	if (!cpus_empty(mask)) {
+		send_IPI_mask(mask, LOCAL_TIMER_VECTOR);
+	}
+}
+
+void switch_ipi_to_APIC_timer(void *cpumask)
+{
+	cpumask_t mask = *(cpumask_t *)cpumask;
+	int cpu = smp_processor_id();
+
+	if (cpu_isset(cpu, mask) &&
+	    cpu_isset(cpu, timer_interrupt_broadcast_ipi_mask)) {
+		cpu_clear(cpu, timer_interrupt_broadcast_ipi_mask);
+		enable_APIC_timer();
+	}
+}
+EXPORT_SYMBOL(switch_ipi_to_APIC_timer);
+
 int setup_profiling_timer(unsigned int multiplier)
 {
-	int i;
-
-	/*
-	 * Sanity check. [at least 500 APIC cycles should be
-	 * between APIC interrupts as a rule of thumb, to avoid
-	 * irqs flooding us]
-	 */
-	if ( (!multiplier) || (calibration_result/multiplier < 500))
-		return -EINVAL;
-
-	/* 
-	 * Set the new multiplier for each CPU. CPUs don't start using the
-	 * new values until the next timer interrupt in which they do process
-	 * accounting. At that time they also adjust their APIC timers
-	 * accordingly.
-	 */
-	for (i = 0; i < NR_CPUS; ++i)
-		per_cpu(prof_multiplier, i) = multiplier;
-
-	return 0;
+	return -EINVAL;
 }
 
 #ifdef CONFIG_X86_MCE_AMD
@@ -857,32 +871,10 @@
 
 void smp_local_timer_interrupt(struct pt_regs *regs)
 {
-	int cpu = smp_processor_id();
-
 	profile_tick(CPU_PROFILING, regs);
-	if (--per_cpu(prof_counter, cpu) <= 0) {
-		/*
-		 * The multiplier may have changed since the last time we got
-		 * to this point as a result of the user writing to
-		 * /proc/profile. In this case we need to adjust the APIC
-		 * timer accordingly.
-		 *
-		 * Interrupts are already masked off at this point.
-		 */
-		per_cpu(prof_counter, cpu) = per_cpu(prof_multiplier, cpu);
-		if (per_cpu(prof_counter, cpu) != 
-		    per_cpu(prof_old_multiplier, cpu)) {
-			__setup_APIC_LVTT(calibration_result/
-					per_cpu(prof_counter, cpu));
-			per_cpu(prof_old_multiplier, cpu) =
-				per_cpu(prof_counter, cpu);
-		}
-
 #ifdef CONFIG_SMP
-		update_process_times(user_mode(regs));
+	update_process_times(user_mode(regs));
 #endif
-	}
-
 	/*
 	 * We take the 'long' return path, and there every subsystem
 	 * grabs the appropriate locks (kernel lock/ irq lock).
@@ -920,6 +912,7 @@
 	 * Besides, if we don't timer interrupts ignore the global
 	 * interrupt lock, which is the WrongThing (tm) to do.
 	 */
+	exit_idle();
 	irq_enter();
 	smp_local_timer_interrupt(regs);
 	irq_exit();
@@ -979,6 +972,7 @@
 asmlinkage void smp_spurious_interrupt(void)
 {
 	unsigned int v;
+	exit_idle();
 	irq_enter();
 	/*
 	 * Check if this really is a spurious interrupt and ACK it
@@ -1014,6 +1008,7 @@
 {
 	unsigned int v, v1;
 
+	exit_idle();
 	irq_enter();
 	/* First tickle the hardware, only then report what went on. -- REW */
 	v = apic_read(APIC_ESR);
@@ -1060,7 +1055,7 @@
 	connect_bsp_APIC();
 
 	phys_cpu_present_map = physid_mask_of_physid(boot_cpu_id);
-	apic_write_around(APIC_ID, boot_cpu_id);
+	apic_write(APIC_ID, SET_APIC_ID(boot_cpu_id));
 
 	setup_local_APIC();
 
diff --git a/arch/x86_64/kernel/asm-offsets.c b/arch/x86_64/kernel/asm-offsets.c
index aaa6d38..cfb4f9c 100644
--- a/arch/x86_64/kernel/asm-offsets.c
+++ b/arch/x86_64/kernel/asm-offsets.c
@@ -33,6 +33,7 @@
 	ENTRY(flags);
 	ENTRY(addr_limit);
 	ENTRY(preempt_count);
+	ENTRY(status);
 	BLANK();
 #undef ENTRY
 #define ENTRY(entry) DEFINE(pda_ ## entry, offsetof(struct x8664_pda, entry))
@@ -64,5 +65,9 @@
 	DEFINE(pbe_address, offsetof(struct pbe, address));
 	DEFINE(pbe_orig_address, offsetof(struct pbe, orig_address));
 	DEFINE(pbe_next, offsetof(struct pbe, next));
+	BLANK();
+#if DEBUG_STKSZ > EXCEPTION_STKSZ
+	DEFINE(DEBUG_IST, DEBUG_STACK);
+#endif
 	return 0;
 }
diff --git a/arch/x86_64/kernel/crash.c b/arch/x86_64/kernel/crash.c
index 535e04466..4e6c3b7 100644
--- a/arch/x86_64/kernel/crash.c
+++ b/arch/x86_64/kernel/crash.c
@@ -11,19 +11,156 @@
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/smp.h>
+#include <linux/irq.h>
 #include <linux/reboot.h>
 #include <linux/kexec.h>
+#include <linux/delay.h>
+#include <linux/elf.h>
+#include <linux/elfcore.h>
 
 #include <asm/processor.h>
 #include <asm/hardirq.h>
 #include <asm/nmi.h>
 #include <asm/hw_irq.h>
+#include <asm/mach_apic.h>
 
-note_buf_t crash_notes[NR_CPUS];
+/* This keeps a track of which one is crashing cpu. */
+static int crashing_cpu;
+
+static u32 *append_elf_note(u32 *buf, char *name, unsigned type,
+						void *data, size_t data_len)
+{
+	struct elf_note note;
+
+	note.n_namesz = strlen(name) + 1;
+	note.n_descsz = data_len;
+	note.n_type   = type;
+	memcpy(buf, &note, sizeof(note));
+	buf += (sizeof(note) +3)/4;
+	memcpy(buf, name, note.n_namesz);
+	buf += (note.n_namesz + 3)/4;
+	memcpy(buf, data, note.n_descsz);
+	buf += (note.n_descsz + 3)/4;
+
+	return buf;
+}
+
+static void final_note(u32 *buf)
+{
+	struct elf_note note;
+
+	note.n_namesz = 0;
+	note.n_descsz = 0;
+	note.n_type   = 0;
+	memcpy(buf, &note, sizeof(note));
+}
+
+static void crash_save_this_cpu(struct pt_regs *regs, int cpu)
+{
+	struct elf_prstatus prstatus;
+	u32 *buf;
+
+	if ((cpu < 0) || (cpu >= NR_CPUS))
+		return;
+
+	/* Using ELF notes here is opportunistic.
+	 * I need a well defined structure format
+	 * for the data I pass, and I need tags
+	 * on the data to indicate what information I have
+	 * squirrelled away.  ELF notes happen to provide
+	 * all of that that no need to invent something new.
+	 */
+
+	buf = (u32*)per_cpu_ptr(crash_notes, cpu);
+
+	if (!buf)
+		return;
+
+	memset(&prstatus, 0, sizeof(prstatus));
+	prstatus.pr_pid = current->pid;
+	elf_core_copy_regs(&prstatus.pr_reg, regs);
+	buf = append_elf_note(buf, "CORE", NT_PRSTATUS, &prstatus,
+					sizeof(prstatus));
+	final_note(buf);
+}
+
+static void crash_save_self(struct pt_regs *regs)
+{
+	int cpu;
+
+	cpu = smp_processor_id();
+	crash_save_this_cpu(regs, cpu);
+}
+
+#ifdef CONFIG_SMP
+static atomic_t waiting_for_crash_ipi;
+
+static int crash_nmi_callback(struct pt_regs *regs, int cpu)
+{
+	/*
+	 * Don't do anything if this handler is invoked on crashing cpu.
+	 * Otherwise, system will completely hang. Crashing cpu can get
+	 * an NMI if system was initially booted with nmi_watchdog parameter.
+	 */
+	if (cpu == crashing_cpu)
+		return 1;
+	local_irq_disable();
+
+	crash_save_this_cpu(regs, cpu);
+	disable_local_APIC();
+	atomic_dec(&waiting_for_crash_ipi);
+	/* Assume hlt works */
+	for(;;)
+		asm("hlt");
+
+	return 1;
+}
+
+static void smp_send_nmi_allbutself(void)
+{
+	send_IPI_allbutself(APIC_DM_NMI);
+}
+
+/*
+ * This code is a best effort heuristic to get the
+ * other cpus to stop executing. So races with
+ * cpu hotplug shouldn't matter.
+ */
+
+static void nmi_shootdown_cpus(void)
+{
+	unsigned long msecs;
+
+	atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1);
+	set_nmi_callback(crash_nmi_callback);
+
+	/*
+	 * Ensure the new callback function is set before sending
+	 * out the NMI
+	 */
+	wmb();
+
+	smp_send_nmi_allbutself();
+
+	msecs = 1000; /* Wait at most a second for the other cpus to stop */
+	while ((atomic_read(&waiting_for_crash_ipi) > 0) && msecs) {
+		mdelay(1);
+		msecs--;
+	}
+	/* Leave the nmi callback set */
+	disable_local_APIC();
+}
+#else
+static void nmi_shootdown_cpus(void)
+{
+	/* There are no cpus to shootdown */
+}
+#endif
 
 void machine_crash_shutdown(struct pt_regs *regs)
 {
-	/* This function is only called after the system
+	/*
+	 * This function is only called after the system
 	 * has paniced or is otherwise in a critical state.
 	 * The minimum amount of code to allow a kexec'd kernel
 	 * to run successfully needs to happen here.
@@ -31,4 +168,19 @@
 	 * In practice this means shooting down the other cpus in
 	 * an SMP system.
 	 */
+	/* The kernel is broken so disable interrupts */
+	local_irq_disable();
+
+	/* Make a note of crashing cpu. Will be used in NMI callback.*/
+	crashing_cpu = smp_processor_id();
+	nmi_shootdown_cpus();
+
+	if(cpu_has_apic)
+		 disable_local_APIC();
+
+#if defined(CONFIG_X86_IO_APIC)
+	disable_IO_APIC();
+#endif
+
+	crash_save_self(regs);
 }
diff --git a/kernel/crash_dump.c b/arch/x86_64/kernel/crash_dump.c
similarity index 60%
rename from kernel/crash_dump.c
rename to arch/x86_64/kernel/crash_dump.c
index fccb27d..942deac 100644
--- a/kernel/crash_dump.c
+++ b/arch/x86_64/kernel/crash_dump.c
@@ -5,21 +5,12 @@
  *	Copyright (C) IBM Corporation, 2004. All rights reserved
  */
 
-#include <linux/smp_lock.h>
 #include <linux/errno.h>
-#include <linux/proc_fs.h>
-#include <linux/bootmem.h>
-#include <linux/highmem.h>
 #include <linux/crash_dump.h>
 
-#include <asm/io.h>
 #include <asm/uaccess.h>
-#include <asm/kexec.h>
+#include <asm/io.h>
 
-/* Stores the physical address of elf header of crash image. */
-unsigned long long elfcorehdr_addr = ELFCORE_ADDR_MAX;
-
-#ifndef HAVE_ARCH_COPY_OLDMEM_PAGE
 /**
  * copy_oldmem_page - copy one page from "oldmem"
  * @pfn: page frame number to be copied
@@ -34,31 +25,23 @@
  * in the current kernel. We stitch up a pte, similar to kmap_atomic.
  */
 ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
-				size_t csize, unsigned long offset, int userbuf)
+                               size_t csize, unsigned long offset, int userbuf)
 {
-	void *page, *vaddr;
+	void  *vaddr;
 
 	if (!csize)
 		return 0;
 
-	page = kmalloc(PAGE_SIZE, GFP_KERNEL);
-	if (!page)
-		return -ENOMEM;
-
-	vaddr = kmap_atomic_pfn(pfn, KM_PTE0);
-	copy_page(page, vaddr);
-	kunmap_atomic(vaddr, KM_PTE0);
+	vaddr = ioremap(pfn << PAGE_SHIFT, PAGE_SIZE);
 
 	if (userbuf) {
-		if (copy_to_user(buf, (page + offset), csize)) {
-			kfree(page);
+		if (copy_to_user(buf, (vaddr + offset), csize)) {
+			iounmap(vaddr);
 			return -EFAULT;
 		}
-	} else {
-		memcpy(buf, (page + offset), csize);
-	}
+	} else
+	memcpy(buf, (vaddr + offset), csize);
 
-	kfree(page);
+	iounmap(vaddr);
 	return csize;
 }
-#endif
diff --git a/arch/x86_64/kernel/e820.c b/arch/x86_64/kernel/e820.c
index 17579a1..293cd71 100644
--- a/arch/x86_64/kernel/e820.c
+++ b/arch/x86_64/kernel/e820.c
@@ -559,6 +559,27 @@
 	end_user_pfn >>= PAGE_SHIFT;	
 } 
 
+void __init parse_memmapopt(char *p, char **from)
+{
+	unsigned long long start_at, mem_size;
+
+	mem_size = memparse(p, from);
+	p = *from;
+	if (*p == '@') {
+		start_at = memparse(p+1, from);
+		add_memory_region(start_at, mem_size, E820_RAM);
+	} else if (*p == '#') {
+		start_at = memparse(p+1, from);
+		add_memory_region(start_at, mem_size, E820_ACPI);
+	} else if (*p == '$') {
+		start_at = memparse(p+1, from);
+		add_memory_region(start_at, mem_size, E820_RESERVED);
+	} else {
+		end_user_pfn = (mem_size >> PAGE_SHIFT);
+	}
+	p = *from;
+}
+
 unsigned long pci_mem_start = 0xaeedbabe;
 
 /*
diff --git a/arch/x86_64/kernel/early_printk.c b/arch/x86_64/kernel/early_printk.c
index 9cd968d..6dffb49 100644
--- a/arch/x86_64/kernel/early_printk.c
+++ b/arch/x86_64/kernel/early_printk.c
@@ -216,7 +216,7 @@
 	va_end(ap); 
 } 
 
-static int keep_early; 
+static int __initdata keep_early;
 
 int __init setup_early_printk(char *opt) 
 {  
@@ -226,8 +226,6 @@
 	if (early_console_initialized)
 		return -1;
 
-	opt = strchr(opt, '=') + 1;
-
 	strlcpy(buf,opt,sizeof(buf)); 
 	space = strchr(buf, ' '); 
 	if (space)
diff --git a/arch/x86_64/kernel/entry.S b/arch/x86_64/kernel/entry.S
index 9ff4204..632fc0f 100644
--- a/arch/x86_64/kernel/entry.S
+++ b/arch/x86_64/kernel/entry.S
@@ -313,6 +313,7 @@
 	movl threadinfo_flags(%rcx),%edx
 	andl %edi,%edx
 	jnz   int_careful
+	andl    $~TS_COMPAT,threadinfo_status(%rcx)
 	jmp   retint_swapgs
 
 	/* Either reschedule or signal or syscall exit tracking needed. */
@@ -673,7 +674,10 @@
 
 	/* error code is on the stack already */
 	/* handle NMI like exceptions that can happen everywhere */
-	.macro paranoidentry sym
+#ifndef DEBUG_IST
+# define DEBUG_IST 0
+#endif
+	.macro paranoidentry sym, ist=0
 	SAVE_ALL
 	cld
 	movl $1,%ebx
@@ -683,10 +687,20 @@
 	js    1f
 	swapgs
 	xorl  %ebx,%ebx
-1:	movq %rsp,%rdi
+1:
+	.if \ist
+	movq	%gs:pda_data_offset, %rbp
+	.endif
+	movq %rsp,%rdi
 	movq ORIG_RAX(%rsp),%rsi
 	movq $-1,ORIG_RAX(%rsp)
+	.if \ist
+	subq	$EXCEPTION_STACK_SIZE, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp)
+	.endif
 	call \sym
+	.if \ist
+	addq	$EXCEPTION_STACK_SIZE, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp)
+	.endif
 	cli
 	.endm
 	
@@ -754,7 +768,7 @@
 	jnz  retint_careful
 	swapgs 
 	RESTORE_ARGS 0,8,0						
-	iretq
+	jmp iret_label
 	CFI_ENDPROC
 
 error_kernelspace:
@@ -904,7 +918,7 @@
  	INTR_FRAME
 	pushq $0
 	CFI_ADJUST_CFA_OFFSET 8		
-	paranoidentry do_debug
+	paranoidentry do_debug, DEBUG_IST
 	jmp paranoid_exit
 	CFI_ENDPROC
 	.previous .text
@@ -959,7 +973,12 @@
 	CFI_ENDPROC
 
 KPROBE_ENTRY(int3)
-	zeroentry do_int3	
+ 	INTR_FRAME
+ 	pushq $0
+ 	CFI_ADJUST_CFA_OFFSET 8
+ 	paranoidentry do_int3, DEBUG_IST
+ 	jmp paranoid_exit
+ 	CFI_ENDPROC
 	.previous .text
 
 ENTRY(overflow)
@@ -1021,23 +1040,18 @@
 	CFI_ENDPROC
 #endif
 
-ENTRY(call_debug)
-       zeroentry do_call_debug
-
 ENTRY(call_softirq)
 	CFI_STARTPROC
 	movq %gs:pda_irqstackptr,%rax
-	pushq %r15
-	CFI_ADJUST_CFA_OFFSET 8
-	movq %rsp,%r15
-	CFI_DEF_CFA_REGISTER	r15
+	movq %rsp,%rdx
+	CFI_DEF_CFA_REGISTER	rdx
 	incl %gs:pda_irqcount
 	cmove %rax,%rsp
+	pushq %rdx
+	/*todo CFI_DEF_CFA_EXPRESSION ...*/
 	call __do_softirq
-	movq %r15,%rsp
+	popq %rsp
 	CFI_DEF_CFA_REGISTER	rsp
 	decl %gs:pda_irqcount
-	popq %r15
-	CFI_ADJUST_CFA_OFFSET -8
 	ret
 	CFI_ENDPROC
diff --git a/arch/x86_64/kernel/genapic_cluster.c b/arch/x86_64/kernel/genapic_cluster.c
index a472d62..43fcf62 100644
--- a/arch/x86_64/kernel/genapic_cluster.c
+++ b/arch/x86_64/kernel/genapic_cluster.c
@@ -72,14 +72,11 @@
 static void cluster_send_IPI_allbutself(int vector)
 {
 	cpumask_t mask = cpu_online_map;
-	int me = get_cpu(); /* Ensure we are not preempted when we clear */
 
-	cpu_clear(me, mask);
+	cpu_clear(smp_processor_id(), mask);
 
 	if (!cpus_empty(mask))
 		cluster_send_IPI_mask(mask, vector);
-
-	put_cpu();
 }
 
 static void cluster_send_IPI_all(int vector)
diff --git a/arch/x86_64/kernel/genapic_flat.c b/arch/x86_64/kernel/genapic_flat.c
index 9da3edb..1a2ab82 100644
--- a/arch/x86_64/kernel/genapic_flat.c
+++ b/arch/x86_64/kernel/genapic_flat.c
@@ -83,12 +83,11 @@
 		__send_IPI_shortcut(APIC_DEST_ALLBUT, vector,APIC_DEST_LOGICAL);
 #else
 	cpumask_t allbutme = cpu_online_map;
-	int me = get_cpu(); /* Ensure we are not preempted when we clear */
-	cpu_clear(me, allbutme);
+
+	cpu_clear(smp_processor_id(), allbutme);
 
 	if (!cpus_empty(allbutme))
 		flat_send_IPI_mask(allbutme, vector);
-	put_cpu();
 #endif
 }
 
@@ -149,10 +148,9 @@
 static void physflat_send_IPI_allbutself(int vector)
 {
 	cpumask_t allbutme = cpu_online_map;
-	int me = get_cpu();
-	cpu_clear(me, allbutme);
+
+	cpu_clear(smp_processor_id(), allbutme);
 	physflat_send_IPI_mask(allbutme, vector);
-	put_cpu();
 }
 
 static void physflat_send_IPI_all(int vector)
diff --git a/arch/x86_64/kernel/head.S b/arch/x86_64/kernel/head.S
index 1529096..38fc3d5 100644
--- a/arch/x86_64/kernel/head.S
+++ b/arch/x86_64/kernel/head.S
@@ -379,14 +379,14 @@
  * Also sysret mandates a special GDT layout 
  */
 		 		
-.align L1_CACHE_BYTES
+.align PAGE_SIZE
 
 /* The TLS descriptors are currently at a different place compared to i386.
    Hopefully nobody expects them at a fixed place (Wine?) */
 	
 ENTRY(cpu_gdt_table)
 	.quad	0x0000000000000000	/* NULL descriptor */
-	.quad	0x008f9a000000ffff	/* __KERNEL_COMPAT32_CS */	
+	.quad	0x0			/* unused */
 	.quad	0x00af9a000000ffff	/* __KERNEL_CS */
 	.quad	0x00cf92000000ffff	/* __KERNEL_DS */
 	.quad	0x00cffa000000ffff	/* __USER32_CS */
@@ -396,15 +396,15 @@
 	.quad	0,0			/* TSS */
 	.quad	0,0			/* LDT */
 	.quad   0,0,0			/* three TLS descriptors */ 
-	.quad	0x00009a000000ffff	/* __KERNEL16_CS - 16bit PM for S3 wakeup. */
-					/* base must be patched for real base address. */
+	.quad	0			/* unused */
 gdt_end:	
 	/* asm/segment.h:GDT_ENTRIES must match this */	
 	/* This should be a multiple of the cache line size */
-	/* GDTs of other CPUs: */	
-	.fill (GDT_SIZE * NR_CPUS) - (gdt_end - cpu_gdt_table)
+	/* GDTs of other CPUs are now dynamically allocated */
 
-	.align  L1_CACHE_BYTES
+	/* zero the remaining page */
+	.fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
+
 ENTRY(idt_table)	
 	.rept   256
 	.quad   0
diff --git a/arch/x86_64/kernel/head64.c b/arch/x86_64/kernel/head64.c
index b675c5a..cea20a6 100644
--- a/arch/x86_64/kernel/head64.c
+++ b/arch/x86_64/kernel/head64.c
@@ -92,6 +92,9 @@
 	memcpy(init_level4_pgt, boot_level4_pgt, PTRS_PER_PGD*sizeof(pgd_t));
 	asm volatile("movq %0,%%cr3" :: "r" (__pa_symbol(&init_level4_pgt)));
 
+ 	for (i = 0; i < NR_CPUS; i++)
+ 		cpu_pda(i) = &boot_cpu_pda[i];
+
 	pda_init(0);
 	copy_bootdata(real_mode_data);
 #ifdef CONFIG_SMP
@@ -99,7 +102,7 @@
 #endif
 	s = strstr(saved_command_line, "earlyprintk=");
 	if (s != NULL)
-		setup_early_printk(s);
+		setup_early_printk(strchr(s, '=') + 1);
 #ifdef CONFIG_NUMA
 	s = strstr(saved_command_line, "numa=");
 	if (s != NULL)
diff --git a/arch/x86_64/kernel/i387.c b/arch/x86_64/kernel/i387.c
index d9b22b6..a5d7e16 100644
--- a/arch/x86_64/kernel/i387.c
+++ b/arch/x86_64/kernel/i387.c
@@ -95,7 +95,7 @@
 	if (!used_math())
 		return 0;
 	clear_used_math(); /* trigger finit */
-	if (tsk->thread_info->status & TS_USEDFPU) {
+	if (task_thread_info(tsk)->status & TS_USEDFPU) {
 		err = save_i387_checking((struct i387_fxsave_struct __user *)buf);
 		if (err) return err;
 		stts();
diff --git a/arch/x86_64/kernel/i8259.c b/arch/x86_64/kernel/i8259.c
index 6e5101a..5ecd34a 100644
--- a/arch/x86_64/kernel/i8259.c
+++ b/arch/x86_64/kernel/i8259.c
@@ -133,7 +133,7 @@
 {
 	if (irq > 256) { 
 		char var;
-		printk("return %p stack %p ti %p\n", __builtin_return_address(0), &var, current->thread_info); 
+		printk("return %p stack %p ti %p\n", __builtin_return_address(0), &var, task_thread_info(current));
 
 		BUG(); 
 	}
@@ -549,10 +549,9 @@
 		int vector = FIRST_EXTERNAL_VECTOR + i;
 		if (i >= NR_IRQS)
 			break;
-		if (vector != IA32_SYSCALL_VECTOR && vector != KDB_VECTOR) { 
+		if (vector != IA32_SYSCALL_VECTOR)
 			set_intr_gate(vector, interrupt[i]);
 	}
-	}
 
 #ifdef CONFIG_SMP
 	/*
diff --git a/arch/x86_64/kernel/io_apic.c b/arch/x86_64/kernel/io_apic.c
index 97154ab..e8cf44e 100644
--- a/arch/x86_64/kernel/io_apic.c
+++ b/arch/x86_64/kernel/io_apic.c
@@ -37,6 +37,7 @@
 #include <asm/proto.h>
 #include <asm/mach_apic.h>
 #include <asm/acpi.h>
+#include <asm/dma.h>
 
 #define __apicdebuginit  __init
 
@@ -46,6 +47,9 @@
 
 int disable_timer_pin_1 __initdata;
 
+/* Where if anywhere is the i8259 connect in external int mode */
+static struct { int pin, apic; } ioapic_i8259 = { -1, -1 };
+
 static DEFINE_SPINLOCK(ioapic_lock);
 
 /*
@@ -260,9 +264,6 @@
 void __init check_ioapic(void) 
 { 
 	int num,slot,func; 
-	if (ioapic_force) 
-		return; 
-
 	/* Poor man's PCI discovery */
 	for (num = 0; num < 32; num++) { 
 		for (slot = 0; slot < 32; slot++) { 
@@ -284,7 +285,7 @@
 				switch (vendor) { 
 				case PCI_VENDOR_ID_VIA:
 #ifdef CONFIG_GART_IOMMU
-					if ((end_pfn >= (0xffffffff>>PAGE_SHIFT) ||
+					if ((end_pfn > MAX_DMA32_PFN ||
 					     force_iommu) &&
 					    !iommu_aperture_allowed) {
 						printk(KERN_INFO
@@ -363,7 +364,7 @@
 /*
  * Find the pin to which IRQ[irq] (ISA) is connected
  */
-static int find_isa_irq_pin(int irq, int type)
+static int __init find_isa_irq_pin(int irq, int type)
 {
 	int i;
 
@@ -381,6 +382,31 @@
 	return -1;
 }
 
+static int __init find_isa_irq_apic(int irq, int type)
+{
+	int i;
+
+	for (i = 0; i < mp_irq_entries; i++) {
+		int lbus = mp_irqs[i].mpc_srcbus;
+
+		if ((mp_bus_id_to_type[lbus] == MP_BUS_ISA ||
+		     mp_bus_id_to_type[lbus] == MP_BUS_EISA ||
+		     mp_bus_id_to_type[lbus] == MP_BUS_MCA) &&
+		    (mp_irqs[i].mpc_irqtype == type) &&
+		    (mp_irqs[i].mpc_srcbusirq == irq))
+			break;
+	}
+	if (i < mp_irq_entries) {
+		int apic;
+		for(apic = 0; apic < nr_ioapics; apic++) {
+			if (mp_ioapics[apic].mpc_apicid == mp_irqs[i].mpc_dstapic)
+				return apic;
+		}
+	}
+
+	return -1;
+}
+
 /*
  * Find a specific PCI IRQ entry.
  * Not an __init, possibly needed by modules
@@ -874,7 +900,7 @@
  * Set up the 8259A-master output pin as broadcast to all
  * CPUs.
  */
-static void __init setup_ExtINT_IRQ0_pin(unsigned int pin, int vector)
+static void __init setup_ExtINT_IRQ0_pin(unsigned int apic, unsigned int pin, int vector)
 {
 	struct IO_APIC_route_entry entry;
 	unsigned long flags;
@@ -884,7 +910,7 @@
 	disable_8259A_irq(0);
 
 	/* mask LVT0 */
-	apic_write_around(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);
+	apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);
 
 	/*
 	 * We use logical delivery to get the timer IRQ
@@ -908,8 +934,8 @@
 	 * Add it to the IO-APIC irq-routing table:
 	 */
 	spin_lock_irqsave(&ioapic_lock, flags);
-	io_apic_write(0, 0x11+2*pin, *(((int *)&entry)+1));
-	io_apic_write(0, 0x10+2*pin, *(((int *)&entry)+0));
+	io_apic_write(apic, 0x11+2*pin, *(((int *)&entry)+1));
+	io_apic_write(apic, 0x10+2*pin, *(((int *)&entry)+0));
 	spin_unlock_irqrestore(&ioapic_lock, flags);
 
 	enable_8259A_irq(0);
@@ -1188,7 +1214,8 @@
 static void __init enable_IO_APIC(void)
 {
 	union IO_APIC_reg_01 reg_01;
-	int i;
+	int i8259_apic, i8259_pin;
+	int i, apic;
 	unsigned long flags;
 
 	for (i = 0; i < PIN_MAP_SIZE; i++) {
@@ -1202,11 +1229,48 @@
 	/*
 	 * The number of IO-APIC IRQ registers (== #pins):
 	 */
-	for (i = 0; i < nr_ioapics; i++) {
+	for (apic = 0; apic < nr_ioapics; apic++) {
 		spin_lock_irqsave(&ioapic_lock, flags);
-		reg_01.raw = io_apic_read(i, 1);
+		reg_01.raw = io_apic_read(apic, 1);
 		spin_unlock_irqrestore(&ioapic_lock, flags);
-		nr_ioapic_registers[i] = reg_01.bits.entries+1;
+		nr_ioapic_registers[apic] = reg_01.bits.entries+1;
+	}
+	for(apic = 0; apic < nr_ioapics; apic++) {
+		int pin;
+		/* See if any of the pins is in ExtINT mode */
+		for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
+			struct IO_APIC_route_entry entry;
+			spin_lock_irqsave(&ioapic_lock, flags);
+			*(((int *)&entry) + 0) = io_apic_read(apic, 0x10 + 2 * pin);
+			*(((int *)&entry) + 1) = io_apic_read(apic, 0x11 + 2 * pin);
+			spin_unlock_irqrestore(&ioapic_lock, flags);
+
+
+			/* If the interrupt line is enabled and in ExtInt mode
+			 * I have found the pin where the i8259 is connected.
+			 */
+			if ((entry.mask == 0) && (entry.delivery_mode == dest_ExtINT)) {
+				ioapic_i8259.apic = apic;
+				ioapic_i8259.pin  = pin;
+				goto found_i8259;
+			}
+		}
+	}
+ found_i8259:
+	/* Look to see what if the MP table has reported the ExtINT */
+	i8259_pin  = find_isa_irq_pin(0, mp_ExtINT);
+	i8259_apic = find_isa_irq_apic(0, mp_ExtINT);
+	/* Trust the MP table if nothing is setup in the hardware */
+	if ((ioapic_i8259.pin == -1) && (i8259_pin >= 0)) {
+		printk(KERN_WARNING "ExtINT not setup in hardware but reported by MP table\n");
+		ioapic_i8259.pin  = i8259_pin;
+		ioapic_i8259.apic = i8259_apic;
+	}
+	/* Complain if the MP table and the hardware disagree */
+	if (((ioapic_i8259.apic != i8259_apic) || (ioapic_i8259.pin != i8259_pin)) &&
+		(i8259_pin >= 0) && (ioapic_i8259.pin >= 0))
+	{
+		printk(KERN_WARNING "ExtINT in hardware and MP table differ\n");
 	}
 
 	/*
@@ -1220,7 +1284,6 @@
  */
 void disable_IO_APIC(void)
 {
-	int pin;
 	/*
 	 * Clear the IO-APIC before rebooting:
 	 */
@@ -1231,8 +1294,7 @@
 	 * Put that IOAPIC in virtual wire mode
 	 * so legacy interrupts can be delivered.
 	 */
-	pin = find_isa_irq_pin(0, mp_ExtINT);
-	if (pin != -1) {
+	if (ioapic_i8259.pin != -1) {
 		struct IO_APIC_route_entry entry;
 		unsigned long flags;
 
@@ -1243,21 +1305,23 @@
 		entry.polarity        = 0; /* High */
 		entry.delivery_status = 0;
 		entry.dest_mode       = 0; /* Physical */
-		entry.delivery_mode   = 7; /* ExtInt */
+		entry.delivery_mode   = dest_ExtINT; /* ExtInt */
 		entry.vector          = 0;
-		entry.dest.physical.physical_dest = 0;
-
+		entry.dest.physical.physical_dest =
+					GET_APIC_ID(apic_read(APIC_ID));
 
 		/*
 		 * Add it to the IO-APIC irq-routing table:
 		 */
 		spin_lock_irqsave(&ioapic_lock, flags);
-		io_apic_write(0, 0x11+2*pin, *(((int *)&entry)+1));
-		io_apic_write(0, 0x10+2*pin, *(((int *)&entry)+0));
+		io_apic_write(ioapic_i8259.apic, 0x11+2*ioapic_i8259.pin,
+			*(((int *)&entry)+1));
+		io_apic_write(ioapic_i8259.apic, 0x10+2*ioapic_i8259.pin,
+			*(((int *)&entry)+0));
 		spin_unlock_irqrestore(&ioapic_lock, flags);
 	}
 
-	disconnect_bsp_APIC(pin != -1);
+	disconnect_bsp_APIC(ioapic_i8259.pin != -1);
 }
 
 /*
@@ -1571,7 +1635,7 @@
 	unsigned long v;
 
 	v = apic_read(APIC_LVT0);
-	apic_write_around(APIC_LVT0, v & ~APIC_LVT_MASKED);
+	apic_write(APIC_LVT0, v & ~APIC_LVT_MASKED);
 }
 
 static void disable_lapic_irq (unsigned int irq)
@@ -1579,7 +1643,7 @@
 	unsigned long v;
 
 	v = apic_read(APIC_LVT0);
-	apic_write_around(APIC_LVT0, v | APIC_LVT_MASKED);
+	apic_write(APIC_LVT0, v | APIC_LVT_MASKED);
 }
 
 static void ack_lapic_irq (unsigned int irq)
@@ -1626,20 +1690,21 @@
  */
 static inline void unlock_ExtINT_logic(void)
 {
-	int pin, i;
+	int apic, pin, i;
 	struct IO_APIC_route_entry entry0, entry1;
 	unsigned char save_control, save_freq_select;
 	unsigned long flags;
 
-	pin = find_isa_irq_pin(8, mp_INT);
+	pin  = find_isa_irq_pin(8, mp_INT);
+	apic = find_isa_irq_apic(8, mp_INT);
 	if (pin == -1)
 		return;
 
 	spin_lock_irqsave(&ioapic_lock, flags);
-	*(((int *)&entry0) + 1) = io_apic_read(0, 0x11 + 2 * pin);
-	*(((int *)&entry0) + 0) = io_apic_read(0, 0x10 + 2 * pin);
+	*(((int *)&entry0) + 1) = io_apic_read(apic, 0x11 + 2 * pin);
+	*(((int *)&entry0) + 0) = io_apic_read(apic, 0x10 + 2 * pin);
 	spin_unlock_irqrestore(&ioapic_lock, flags);
-	clear_IO_APIC_pin(0, pin);
+	clear_IO_APIC_pin(apic, pin);
 
 	memset(&entry1, 0, sizeof(entry1));
 
@@ -1652,8 +1717,8 @@
 	entry1.vector = 0;
 
 	spin_lock_irqsave(&ioapic_lock, flags);
-	io_apic_write(0, 0x11 + 2 * pin, *(((int *)&entry1) + 1));
-	io_apic_write(0, 0x10 + 2 * pin, *(((int *)&entry1) + 0));
+	io_apic_write(apic, 0x11 + 2 * pin, *(((int *)&entry1) + 1));
+	io_apic_write(apic, 0x10 + 2 * pin, *(((int *)&entry1) + 0));
 	spin_unlock_irqrestore(&ioapic_lock, flags);
 
 	save_control = CMOS_READ(RTC_CONTROL);
@@ -1671,11 +1736,11 @@
 
 	CMOS_WRITE(save_control, RTC_CONTROL);
 	CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);
-	clear_IO_APIC_pin(0, pin);
+	clear_IO_APIC_pin(apic, pin);
 
 	spin_lock_irqsave(&ioapic_lock, flags);
-	io_apic_write(0, 0x11 + 2 * pin, *(((int *)&entry0) + 1));
-	io_apic_write(0, 0x10 + 2 * pin, *(((int *)&entry0) + 0));
+	io_apic_write(apic, 0x11 + 2 * pin, *(((int *)&entry0) + 1));
+	io_apic_write(apic, 0x10 + 2 * pin, *(((int *)&entry0) + 0));
 	spin_unlock_irqrestore(&ioapic_lock, flags);
 }
 
@@ -1687,7 +1752,7 @@
  */
 static inline void check_timer(void)
 {
-	int pin1, pin2;
+	int apic1, pin1, apic2, pin2;
 	int vector;
 
 	/*
@@ -1704,14 +1769,17 @@
 	 * the 8259A which implies the virtual wire has to be
 	 * disabled in the local APIC.
 	 */
-	apic_write_around(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);
+	apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);
 	init_8259A(1);
 	enable_8259A_irq(0);
 
-	pin1 = find_isa_irq_pin(0, mp_INT);
-	pin2 = find_isa_irq_pin(0, mp_ExtINT);
+	pin1  = find_isa_irq_pin(0, mp_INT);
+	apic1 = find_isa_irq_apic(0, mp_INT);
+	pin2  = ioapic_i8259.pin;
+	apic2 = ioapic_i8259.apic;
 
-	apic_printk(APIC_VERBOSE,KERN_INFO "..TIMER: vector=0x%02X pin1=%d pin2=%d\n", vector, pin1, pin2);
+	apic_printk(APIC_VERBOSE,KERN_INFO "..TIMER: vector=0x%02X apic1=%d pin1=%d apic2=%d pin2=%d\n",
+		vector, apic1, pin1, apic2, pin2);
 
 	if (pin1 != -1) {
 		/*
@@ -1729,17 +1797,20 @@
 				clear_IO_APIC_pin(0, pin1);
 			return;
 		}
-		clear_IO_APIC_pin(0, pin1);
-		apic_printk(APIC_QUIET,KERN_ERR "..MP-BIOS bug: 8254 timer not connected to IO-APIC\n");
+		clear_IO_APIC_pin(apic1, pin1);
+		apic_printk(APIC_QUIET,KERN_ERR "..MP-BIOS bug: 8254 timer not "
+				"connected to IO-APIC\n");
 	}
 
-	apic_printk(APIC_VERBOSE,KERN_INFO "...trying to set up timer (IRQ0) through the 8259A ... ");
+	apic_printk(APIC_VERBOSE,KERN_INFO "...trying to set up timer (IRQ0) "
+				"through the 8259A ... ");
 	if (pin2 != -1) {
-		apic_printk(APIC_VERBOSE,"\n..... (found pin %d) ...", pin2);
+		apic_printk(APIC_VERBOSE,"\n..... (found apic %d pin %d) ...",
+			apic2, pin2);
 		/*
 		 * legacy devices should be connected to IO APIC #0
 		 */
-		setup_ExtINT_IRQ0_pin(pin2, vector);
+		setup_ExtINT_IRQ0_pin(apic2, pin2, vector);
 		if (timer_irq_works()) {
 			printk("works.\n");
 			nmi_watchdog_default();
@@ -1751,7 +1822,7 @@
 		/*
 		 * Cleanup, just in case ...
 		 */
-		clear_IO_APIC_pin(0, pin2);
+		clear_IO_APIC_pin(apic2, pin2);
 	}
 	printk(" failed.\n");
 
@@ -1764,21 +1835,21 @@
 
 	disable_8259A_irq(0);
 	irq_desc[0].handler = &lapic_irq_type;
-	apic_write_around(APIC_LVT0, APIC_DM_FIXED | vector);	/* Fixed mode */
+	apic_write(APIC_LVT0, APIC_DM_FIXED | vector);	/* Fixed mode */
 	enable_8259A_irq(0);
 
 	if (timer_irq_works()) {
 		apic_printk(APIC_QUIET, " works.\n");
 		return;
 	}
-	apic_write_around(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_FIXED | vector);
+	apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_FIXED | vector);
 	apic_printk(APIC_VERBOSE," failed.\n");
 
 	apic_printk(APIC_VERBOSE, KERN_INFO "...trying to set up timer as ExtINT IRQ...");
 
 	init_8259A(0);
 	make_8259A_irq(0);
-	apic_write_around(APIC_LVT0, APIC_DM_EXTINT);
+	apic_write(APIC_LVT0, APIC_DM_EXTINT);
 
 	unlock_ExtINT_logic();
 
diff --git a/arch/x86_64/kernel/ioport.c b/arch/x86_64/kernel/ioport.c
index cde0e86..b816149 100644
--- a/arch/x86_64/kernel/ioport.c
+++ b/arch/x86_64/kernel/ioport.c
@@ -7,6 +7,7 @@
 
 #include <linux/sched.h>
 #include <linux/kernel.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/types.h>
 #include <linux/ioport.h>
diff --git a/arch/x86_64/kernel/irq.c b/arch/x86_64/kernel/irq.c
index d6a04a8..30d2a1e 100644
--- a/arch/x86_64/kernel/irq.c
+++ b/arch/x86_64/kernel/irq.c
@@ -17,6 +17,7 @@
 #include <linux/delay.h>
 #include <asm/uaccess.h>
 #include <asm/io_apic.h>
+#include <asm/idle.h>
 
 atomic_t irq_err_count;
 #ifdef CONFIG_X86_IO_APIC
@@ -69,13 +70,13 @@
 		seq_printf(p, "NMI: ");
 		for (j = 0; j < NR_CPUS; j++)
 			if (cpu_online(j))
-				seq_printf(p, "%10u ", cpu_pda[j].__nmi_count);
+				seq_printf(p, "%10u ", cpu_pda(j)->__nmi_count);
 		seq_putc(p, '\n');
 #ifdef CONFIG_X86_LOCAL_APIC
 		seq_printf(p, "LOC: ");
 		for (j = 0; j < NR_CPUS; j++)
 			if (cpu_online(j))
-				seq_printf(p, "%10u ", cpu_pda[j].apic_timer_irqs);
+				seq_printf(p, "%10u ", cpu_pda(j)->apic_timer_irqs);
 		seq_putc(p, '\n');
 #endif
 		seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
@@ -98,6 +99,7 @@
 	/* high bits used in ret_from_ code  */
 	unsigned irq = regs->orig_rax & 0xff;
 
+	exit_idle();
 	irq_enter();
 
 	__do_IRQ(irq, regs);
diff --git a/arch/x86_64/kernel/kprobes.c b/arch/x86_64/kernel/kprobes.c
index afe11f4..8b866a8 100644
--- a/arch/x86_64/kernel/kprobes.c
+++ b/arch/x86_64/kernel/kprobes.c
@@ -42,8 +42,8 @@
 #include <asm/pgtable.h>
 #include <asm/kdebug.h>
 
-static DECLARE_MUTEX(kprobe_mutex);
 void jprobe_return_end(void);
+static void __kprobes arch_copy_kprobe(struct kprobe *p);
 
 DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
 DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
@@ -69,12 +69,11 @@
 int __kprobes arch_prepare_kprobe(struct kprobe *p)
 {
 	/* insn: must be on special executable page on x86_64. */
-	down(&kprobe_mutex);
 	p->ainsn.insn = get_insn_slot();
-	up(&kprobe_mutex);
 	if (!p->ainsn.insn) {
 		return -ENOMEM;
 	}
+	arch_copy_kprobe(p);
 	return 0;
 }
 
@@ -181,7 +180,7 @@
 	return NULL;
 }
 
-void __kprobes arch_copy_kprobe(struct kprobe *p)
+static void __kprobes arch_copy_kprobe(struct kprobe *p)
 {
 	s32 *ripdisp;
 	memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE);
@@ -335,6 +334,15 @@
 				return 1;
 			}
 		} else {
+			if (*addr != BREAKPOINT_INSTRUCTION) {
+			/* The breakpoint instruction was removed by
+			 * another cpu right after we hit, no further
+			 * handling of this interrupt is appropriate
+			 */
+				regs->rip = (unsigned long)addr;
+				ret = 1;
+				goto no_kprobe;
+			}
 			p = __get_cpu_var(current_kprobe);
 			if (p->break_handler && p->break_handler(p, regs)) {
 				goto ss_probe;
diff --git a/arch/x86_64/kernel/mce.c b/arch/x86_64/kernel/mce.c
index 183dc61..13a2ead 100644
--- a/arch/x86_64/kernel/mce.c
+++ b/arch/x86_64/kernel/mce.c
@@ -15,6 +15,7 @@
 #include <linux/sysdev.h>
 #include <linux/miscdevice.h>
 #include <linux/fs.h>
+#include <linux/capability.h>
 #include <linux/cpu.h>
 #include <linux/percpu.h>
 #include <linux/ctype.h>
@@ -23,9 +24,10 @@
 #include <asm/mce.h>
 #include <asm/kdebug.h>
 #include <asm/uaccess.h>
+#include <asm/smp.h>
 
 #define MISC_MCELOG_MINOR 227
-#define NR_BANKS 5
+#define NR_BANKS 6
 
 static int mce_dont_init;
 
@@ -91,6 +93,7 @@
 static void print_mce(struct mce *m)
 {
 	printk(KERN_EMERG "\n"
+	       KERN_EMERG "HARDWARE ERROR\n"
 	       KERN_EMERG
 	       "CPU %d: Machine Check Exception: %16Lx Bank %d: %016Lx\n",
 	       m->cpu, m->mcgstatus, m->bank, m->status);
@@ -109,6 +112,9 @@
 	if (m->misc)
 		printk("MISC %Lx ", m->misc); 	
 	printk("\n");
+	printk(KERN_EMERG "This is not a software problem!\n");
+        printk(KERN_EMERG
+    "Run through mcelog --ascii to decode and contact your hardware vendor\n");
 }
 
 static void mce_panic(char *msg, struct mce *backup, unsigned long start)
@@ -168,12 +174,12 @@
 	int panicm_found = 0;
 
 	if (regs)
-		notify_die(DIE_NMI, "machine check", regs, error_code, 255, SIGKILL);
+		notify_die(DIE_NMI, "machine check", regs, error_code, 18, SIGKILL);
 	if (!banks)
 		return;
 
 	memset(&m, 0, sizeof(struct mce));
-	m.cpu = hard_smp_processor_id();
+	m.cpu = safe_smp_processor_id();
 	rdmsrl(MSR_IA32_MCG_STATUS, m.mcgstatus);
 	if (!(m.mcgstatus & MCG_STATUS_RIPV))
 		kill_it = 1;
@@ -573,6 +579,10 @@
 ACCESSOR(bank2ctl,bank[2],mce_restart())
 ACCESSOR(bank3ctl,bank[3],mce_restart())
 ACCESSOR(bank4ctl,bank[4],mce_restart())
+ACCESSOR(bank5ctl,bank[5],mce_restart())
+static struct sysdev_attribute * bank_attributes[NR_BANKS] = {
+	&attr_bank0ctl, &attr_bank1ctl, &attr_bank2ctl,
+	&attr_bank3ctl, &attr_bank4ctl, &attr_bank5ctl};
 ACCESSOR(tolerant,tolerant,)
 ACCESSOR(check_interval,check_interval,mce_restart())
 
@@ -580,6 +590,7 @@
 static __cpuinit int mce_create_device(unsigned int cpu)
 {
 	int err;
+	int i;
 	if (!mce_available(&cpu_data[cpu]))
 		return -EIO;
 
@@ -589,11 +600,9 @@
 	err = sysdev_register(&per_cpu(device_mce,cpu));
 
 	if (!err) {
-		sysdev_create_file(&per_cpu(device_mce,cpu), &attr_bank0ctl);
-		sysdev_create_file(&per_cpu(device_mce,cpu), &attr_bank1ctl);
-		sysdev_create_file(&per_cpu(device_mce,cpu), &attr_bank2ctl);
-		sysdev_create_file(&per_cpu(device_mce,cpu), &attr_bank3ctl);
-		sysdev_create_file(&per_cpu(device_mce,cpu), &attr_bank4ctl);
+		for (i = 0; i < banks; i++)
+			sysdev_create_file(&per_cpu(device_mce,cpu),
+				bank_attributes[i]);
 		sysdev_create_file(&per_cpu(device_mce,cpu), &attr_tolerant);
 		sysdev_create_file(&per_cpu(device_mce,cpu), &attr_check_interval);
 	}
@@ -603,11 +612,11 @@
 #ifdef CONFIG_HOTPLUG_CPU
 static __cpuinit void mce_remove_device(unsigned int cpu)
 {
-	sysdev_remove_file(&per_cpu(device_mce,cpu), &attr_bank0ctl);
-	sysdev_remove_file(&per_cpu(device_mce,cpu), &attr_bank1ctl);
-	sysdev_remove_file(&per_cpu(device_mce,cpu), &attr_bank2ctl);
-	sysdev_remove_file(&per_cpu(device_mce,cpu), &attr_bank3ctl);
-	sysdev_remove_file(&per_cpu(device_mce,cpu), &attr_bank4ctl);
+	int i;
+
+	for (i = 0; i < banks; i++)
+		sysdev_remove_file(&per_cpu(device_mce,cpu),
+			bank_attributes[i]);
 	sysdev_remove_file(&per_cpu(device_mce,cpu), &attr_tolerant);
 	sysdev_remove_file(&per_cpu(device_mce,cpu), &attr_check_interval);
 	sysdev_unregister(&per_cpu(device_mce,cpu));
diff --git a/arch/x86_64/kernel/mce_amd.c b/arch/x86_64/kernel/mce_amd.c
index 1f76175..d3ad7d8 100644
--- a/arch/x86_64/kernel/mce_amd.c
+++ b/arch/x86_64/kernel/mce_amd.c
@@ -27,6 +27,7 @@
 #include <asm/mce.h>
 #include <asm/msr.h>
 #include <asm/percpu.h>
+#include <asm/idle.h>
 
 #define PFX "mce_threshold: "
 #define VERSION "version 1.00.9"
@@ -140,6 +141,7 @@
 	struct mce m;
 
 	ack_APIC_irq();
+	exit_idle();
 	irq_enter();
 
 	memset(&m, 0, sizeof(m));
@@ -318,7 +320,7 @@
 static __cpuinit int threshold_create_bank(unsigned int cpu, int bank)
 {
 	int err = 0;
-	struct threshold_bank *b = 0;
+	struct threshold_bank *b = NULL;
 
 #ifdef CONFIG_SMP
 	if (cpu_core_id[cpu] && shared_bank[bank]) {	/* symlink */
@@ -407,7 +409,7 @@
 	if (shared_bank[bank] && atomic_read(&b->kobj.kref.refcount) > 2) {
 		sprintf(name, "bank%i", bank);
 		sysfs_remove_link(&per_cpu(device_threshold, cpu).kobj, name);
-		per_cpu(threshold_banks, cpu)[bank] = 0;
+		per_cpu(threshold_banks, cpu)[bank] = NULL;
 	} else {
 		kobject_unregister(&b->kobj);
 		kfree(per_cpu(threshold_banks, cpu)[bank]);
diff --git a/arch/x86_64/kernel/mce_intel.c b/arch/x86_64/kernel/mce_intel.c
index 0be0a79..8f533d2 100644
--- a/arch/x86_64/kernel/mce_intel.c
+++ b/arch/x86_64/kernel/mce_intel.c
@@ -10,6 +10,7 @@
 #include <asm/msr.h>
 #include <asm/mce.h>
 #include <asm/hw_irq.h>
+#include <asm/idle.h>
 
 static DEFINE_PER_CPU(unsigned long, next_check);
 
@@ -19,6 +20,7 @@
 
 	ack_APIC_irq();
 
+	exit_idle();
 	irq_enter();
 	if (time_before(jiffies, __get_cpu_var(next_check)))
 		goto done;
@@ -78,7 +80,7 @@
 
 	h = THERMAL_APIC_VECTOR;
 	h |= (APIC_DM_FIXED | APIC_LVT_MASKED);
-	apic_write_around(APIC_LVTTHMR, h);
+	apic_write(APIC_LVTTHMR, h);
 
 	rdmsr(MSR_IA32_THERM_INTERRUPT, l, h);
 	wrmsr(MSR_IA32_THERM_INTERRUPT, l | 0x03, h);
@@ -87,7 +89,7 @@
 	wrmsr(MSR_IA32_MISC_ENABLE, l | (1 << 3), h);
 
 	l = apic_read(APIC_LVTTHMR);
-	apic_write_around(APIC_LVTTHMR, l & ~APIC_LVT_MASKED);
+	apic_write(APIC_LVTTHMR, l & ~APIC_LVT_MASKED);
 	printk(KERN_INFO "CPU%d: Thermal monitoring enabled (%s)\n",
 		cpu, tm2 ? "TM2" : "TM1");
 	return;
diff --git a/arch/x86_64/kernel/nmi.c b/arch/x86_64/kernel/nmi.c
index 39d445e..5fae6f0 100644
--- a/arch/x86_64/kernel/nmi.c
+++ b/arch/x86_64/kernel/nmi.c
@@ -151,23 +151,25 @@
 
 	printk(KERN_INFO "testing NMI watchdog ... ");
 
+#ifdef CONFIG_SMP
 	if (nmi_watchdog == NMI_LOCAL_APIC)
 		smp_call_function(nmi_cpu_busy, (void *)&endflag, 0, 0);
+#endif
 
 	for (cpu = 0; cpu < NR_CPUS; cpu++)
-		counts[cpu] = cpu_pda[cpu].__nmi_count; 
+		counts[cpu] = cpu_pda(cpu)->__nmi_count;
 	local_irq_enable();
 	mdelay((10*1000)/nmi_hz); // wait 10 ticks
 
 	for (cpu = 0; cpu < NR_CPUS; cpu++) {
 		if (!cpu_online(cpu))
 			continue;
-		if (cpu_pda[cpu].__nmi_count - counts[cpu] <= 5) {
+		if (cpu_pda(cpu)->__nmi_count - counts[cpu] <= 5) {
 			endflag = 1;
 			printk("CPU#%d: NMI appears to be stuck (%d->%d)!\n",
 			       cpu,
 			       counts[cpu],
-			       cpu_pda[cpu].__nmi_count);
+			       cpu_pda(cpu)->__nmi_count);
 			nmi_active = 0;
 			lapic_nmi_owner &= ~LAPIC_NMI_WATCHDOG;
 			nmi_perfctr_msr = 0;
diff --git a/arch/x86_64/kernel/pci-dma.c b/arch/x86_64/kernel/pci-dma.c
index cab471c..2f5d832 100644
--- a/arch/x86_64/kernel/pci-dma.c
+++ b/arch/x86_64/kernel/pci-dma.c
@@ -8,53 +8,259 @@
 #include <linux/pci.h>
 #include <linux/module.h>
 #include <asm/io.h>
+#include <asm/proto.h>
 
-/* Map a set of buffers described by scatterlist in streaming
- * mode for DMA.  This is the scatter-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.
- */
-int dma_map_sg(struct device *hwdev, struct scatterlist *sg,
-	       int nents, int direction)
+int iommu_merge __read_mostly = 0;
+EXPORT_SYMBOL(iommu_merge);
+
+dma_addr_t bad_dma_address __read_mostly;
+EXPORT_SYMBOL(bad_dma_address);
+
+/* This tells the BIO block layer to assume merging. Default to off
+   because we cannot guarantee merging later. */
+int iommu_bio_merge __read_mostly = 0;
+EXPORT_SYMBOL(iommu_bio_merge);
+
+int iommu_sac_force __read_mostly = 0;
+EXPORT_SYMBOL(iommu_sac_force);
+
+int no_iommu __read_mostly;
+#ifdef CONFIG_IOMMU_DEBUG
+int panic_on_overflow __read_mostly = 1;
+int force_iommu __read_mostly = 1;
+#else
+int panic_on_overflow __read_mostly = 0;
+int force_iommu __read_mostly= 0;
+#endif
+
+/* Dummy device used for NULL arguments (normally ISA). Better would
+   be probably a smaller DMA mask, but this is bug-to-bug compatible
+   to i386. */
+struct device fallback_dev = {
+	.bus_id = "fallback device",
+	.coherent_dma_mask = 0xffffffff,
+	.dma_mask = &fallback_dev.coherent_dma_mask,
+};
+
+/* Allocate DMA memory on node near device */
+noinline static void *
+dma_alloc_pages(struct device *dev, gfp_t gfp, unsigned order)
 {
-	int i;
+	struct page *page;
+	int node;
+	if (dev->bus == &pci_bus_type)
+		node = pcibus_to_node(to_pci_dev(dev)->bus);
+	else
+		node = numa_node_id();
+	page = alloc_pages_node(node, gfp, order);
+	return page ? page_address(page) : NULL;
+}
 
-	BUG_ON(direction == DMA_NONE);
- 	for (i = 0; i < nents; i++ ) {
-		struct scatterlist *s = &sg[i];
-		BUG_ON(!s->page); 
-		s->dma_address = virt_to_bus(page_address(s->page) +s->offset);
-		s->dma_length = s->length;
+/*
+ * Allocate memory for a coherent mapping.
+ */
+void *
+dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
+		   gfp_t gfp)
+{
+	void *memory;
+	unsigned long dma_mask = 0;
+	u64 bus;
+
+	if (!dev)
+		dev = &fallback_dev;
+	dma_mask = dev->coherent_dma_mask;
+	if (dma_mask == 0)
+		dma_mask = 0xffffffff;
+
+	/* Kludge to make it bug-to-bug compatible with i386. i386
+	   uses the normal dma_mask for alloc_coherent. */
+	dma_mask &= *dev->dma_mask;
+
+	/* Why <=? Even when the mask is smaller than 4GB it is often
+	   larger than 16MB and in this case we have a chance of
+	   finding fitting memory in the next higher zone first. If
+	   not retry with true GFP_DMA. -AK */
+	if (dma_mask <= 0xffffffff)
+		gfp |= GFP_DMA32;
+
+ again:
+	memory = dma_alloc_pages(dev, gfp, get_order(size));
+	if (memory == NULL)
+		return NULL;
+
+	{
+		int high, mmu;
+		bus = virt_to_bus(memory);
+	        high = (bus + size) >= dma_mask;
+		mmu = high;
+		if (force_iommu && !(gfp & GFP_DMA))
+			mmu = 1;
+		else if (high) {
+			free_pages((unsigned long)memory,
+				   get_order(size));
+
+			/* Don't use the 16MB ZONE_DMA unless absolutely
+			   needed. It's better to use remapping first. */
+			if (dma_mask < 0xffffffff && !(gfp & GFP_DMA)) {
+				gfp = (gfp & ~GFP_DMA32) | GFP_DMA;
+				goto again;
+			}
+
+			if (dma_ops->alloc_coherent)
+				return dma_ops->alloc_coherent(dev, size,
+							   dma_handle, gfp);
+			return NULL;
+		}
+
+		memset(memory, 0, size);
+		if (!mmu) {
+			*dma_handle = virt_to_bus(memory);
+			return memory;
+		}
 	}
-	return nents;
+
+	if (dma_ops->alloc_coherent) {
+		free_pages((unsigned long)memory, get_order(size));
+		gfp &= ~(GFP_DMA|GFP_DMA32);
+		return dma_ops->alloc_coherent(dev, size, dma_handle, gfp);
+	}
+
+	if (dma_ops->map_simple) {
+		*dma_handle = dma_ops->map_simple(dev, memory,
+					      size,
+					      PCI_DMA_BIDIRECTIONAL);
+		if (*dma_handle != bad_dma_address)
+			return memory;
+	}
+
+	if (panic_on_overflow)
+		panic("dma_alloc_coherent: IOMMU overflow by %lu bytes\n",size);
+	free_pages((unsigned long)memory, get_order(size));
+	return NULL;
 }
+EXPORT_SYMBOL(dma_alloc_coherent);
 
-EXPORT_SYMBOL(dma_map_sg);
-
-/* Unmap a set of streaming mode DMA translations.
- * Again, cpu read rules concerning calls here are the same as for
- * pci_unmap_single() above.
+/*
+ * Unmap coherent memory.
+ * The caller must ensure that the device has finished accessing the mapping.
  */
-void dma_unmap_sg(struct device *dev, struct scatterlist *sg,
-		  int nents, int dir)
+void dma_free_coherent(struct device *dev, size_t size,
+			 void *vaddr, dma_addr_t bus)
 {
-	int i;
-	for (i = 0; i < nents; i++) { 
-		struct scatterlist *s = &sg[i];
-		BUG_ON(s->page == NULL); 
-		BUG_ON(s->dma_address == 0); 
-		dma_unmap_single(dev, s->dma_address, s->dma_length, dir);
-	} 
+	if (dma_ops->unmap_single)
+		dma_ops->unmap_single(dev, bus, size, 0);
+	free_pages((unsigned long)vaddr, get_order(size));
 }
+EXPORT_SYMBOL(dma_free_coherent);
 
-EXPORT_SYMBOL(dma_unmap_sg);
+int dma_supported(struct device *dev, u64 mask)
+{
+	if (dma_ops->dma_supported)
+		return dma_ops->dma_supported(dev, mask);
+
+	/* Copied from i386. Doesn't make much sense, because it will
+	   only work for pci_alloc_coherent.
+	   The caller just has to use GFP_DMA in this case. */
+        if (mask < 0x00ffffff)
+                return 0;
+
+	/* Tell the device to use SAC when IOMMU force is on.  This
+	   allows the driver to use cheaper accesses in some cases.
+
+	   Problem with this is that if we overflow the IOMMU area and
+	   return DAC as fallback address the device may not handle it
+	   correctly.
+
+	   As a special case some controllers have a 39bit address
+	   mode that is as efficient as 32bit (aic79xx). Don't force
+	   SAC for these.  Assume all masks <= 40 bits are of this
+	   type. Normally this doesn't make any difference, but gives
+	   more gentle handling of IOMMU overflow. */
+	if (iommu_sac_force && (mask >= 0xffffffffffULL)) {
+		printk(KERN_INFO "%s: Force SAC with mask %Lx\n", dev->bus_id,mask);
+		return 0;
+	}
+
+	return 1;
+}
+EXPORT_SYMBOL(dma_supported);
+
+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;
+}
+EXPORT_SYMBOL(dma_set_mask);
+
+/* iommu=[size][,noagp][,off][,force][,noforce][,leak][,memaper[=order]][,merge]
+         [,forcesac][,fullflush][,nomerge][,biomerge]
+   size  set size of iommu (in bytes)
+   noagp don't initialize the AGP driver and use full aperture.
+   off   don't use the IOMMU
+   leak  turn on simple iommu leak tracing (only when CONFIG_IOMMU_LEAK is on)
+   memaper[=order] allocate an own aperture over RAM with size 32MB^order.
+   noforce don't force IOMMU usage. Default.
+   force  Force IOMMU.
+   merge  Do lazy merging. This may improve performance on some block devices.
+          Implies force (experimental)
+   biomerge Do merging at the BIO layer. This is more efficient than merge,
+            but should be only done with very big IOMMUs. Implies merge,force.
+   nomerge Don't do SG merging.
+   forcesac For SAC mode for masks <40bits  (experimental)
+   fullflush Flush IOMMU on each allocation (default)
+   nofullflush Don't use IOMMU fullflush
+   allowed  overwrite iommu off workarounds for specific chipsets.
+   soft	 Use software bounce buffering (default for Intel machines)
+   noaperture Don't touch the aperture for AGP.
+*/
+__init int iommu_setup(char *p)
+{
+    iommu_merge = 1;
+
+    while (*p) {
+	    if (!strncmp(p,"off",3))
+		    no_iommu = 1;
+	    /* gart_parse_options has more force support */
+	    if (!strncmp(p,"force",5))
+		    force_iommu = 1;
+	    if (!strncmp(p,"noforce",7)) {
+		    iommu_merge = 0;
+		    force_iommu = 0;
+	    }
+
+	    if (!strncmp(p, "biomerge",8)) {
+		    iommu_bio_merge = 4096;
+		    iommu_merge = 1;
+		    force_iommu = 1;
+	    }
+	    if (!strncmp(p, "panic",5))
+		    panic_on_overflow = 1;
+	    if (!strncmp(p, "nopanic",7))
+		    panic_on_overflow = 0;
+	    if (!strncmp(p, "merge",5)) {
+		    iommu_merge = 1;
+		    force_iommu = 1;
+	    }
+	    if (!strncmp(p, "nomerge",7))
+		    iommu_merge = 0;
+	    if (!strncmp(p, "forcesac",8))
+		    iommu_sac_force = 1;
+
+#ifdef CONFIG_SWIOTLB
+	    if (!strncmp(p, "soft",4))
+		    swiotlb = 1;
+#endif
+
+#ifdef CONFIG_GART_IOMMU
+	    gart_parse_options(p);
+#endif
+
+	    p += strcspn(p, ",");
+	    if (*p == ',')
+		    ++p;
+    }
+    return 1;
+}
diff --git a/arch/x86_64/kernel/pci-gart.c b/arch/x86_64/kernel/pci-gart.c
index 2e28e85..c37fc77 100644
--- a/arch/x86_64/kernel/pci-gart.c
+++ b/arch/x86_64/kernel/pci-gart.c
@@ -30,8 +30,8 @@
 #include <asm/proto.h>
 #include <asm/cacheflush.h>
 #include <asm/kdebug.h>
-
-dma_addr_t bad_dma_address;
+#include <asm/swiotlb.h>
+#include <asm/dma.h>
 
 unsigned long iommu_bus_base;	/* GART remapping area (physical) */
 static unsigned long iommu_size; 	/* size of remapping area bytes */
@@ -39,18 +39,6 @@
 
 u32 *iommu_gatt_base; 		/* Remapping table */
 
-int no_iommu; 
-static int no_agp; 
-#ifdef CONFIG_IOMMU_DEBUG
-int panic_on_overflow = 1; 
-int force_iommu = 1;
-#else
-int panic_on_overflow = 0;
-int force_iommu = 0;
-#endif
-int iommu_merge = 1;
-int iommu_sac_force = 0; 
-
 /* If this is disabled the IOMMU will use an optimized flushing strategy
    of only flushing when an mapping is reused. With it true the GART is flushed 
    for every mapping. Problem is that doing the lazy flush seems to trigger
@@ -58,10 +46,6 @@
    also seen with Qlogic at least). */
 int iommu_fullflush = 1;
 
-/* This tells the BIO block layer to assume merging. Default to off
-   because we cannot guarantee merging later. */
-int iommu_bio_merge = 0;
-
 #define MAX_NB 8
 
 /* Allocation bitmap for the remapping area */ 
@@ -102,16 +86,6 @@
 
 static unsigned long next_bit;  /* protected by iommu_bitmap_lock */
 static int need_flush; 		/* global flush state. set for each gart wrap */
-static dma_addr_t dma_map_area(struct device *dev, unsigned long phys_mem,
-			       size_t size, int dir, int do_panic);
-
-/* Dummy device used for NULL arguments (normally ISA). Better would
-   be probably a smaller DMA mask, but this is bug-to-bug compatible to i386. */
-static struct device fallback_dev = {
-	.bus_id = "fallback device",
-	.coherent_dma_mask = 0xffffffff,
-	.dma_mask = &fallback_dev.coherent_dma_mask,
-};
 
 static unsigned long alloc_iommu(int size) 
 { 	
@@ -185,114 +159,7 @@
 	spin_unlock_irqrestore(&iommu_bitmap_lock, flags);
 } 
 
-/* Allocate DMA memory on node near device */
-noinline
-static void *dma_alloc_pages(struct device *dev, gfp_t gfp, unsigned order)
-{
-	struct page *page;
-	int node;
-	if (dev->bus == &pci_bus_type)
-		node = pcibus_to_node(to_pci_dev(dev)->bus);
-	else
-		node = numa_node_id();
-	page = alloc_pages_node(node, gfp, order);
-	return page ? page_address(page) : NULL;
-}
 
-/* 
- * Allocate memory for a coherent mapping.
- */
-void *
-dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
-		   gfp_t gfp)
-{
-	void *memory;
-	unsigned long dma_mask = 0;
-	u64 bus;
-
-	if (!dev)
-		dev = &fallback_dev;
-	dma_mask = dev->coherent_dma_mask;
-	if (dma_mask == 0) 
-		dma_mask = 0xffffffff; 
-
-	/* Kludge to make it bug-to-bug compatible with i386. i386
-	   uses the normal dma_mask for alloc_coherent. */
-	dma_mask &= *dev->dma_mask;
-
-	/* Why <=? Even when the mask is smaller than 4GB it is often larger 
-	   than 16MB and in this case we have a chance of finding fitting memory 
-	   in the next higher zone first. If not retry with true GFP_DMA. -AK */
-	if (dma_mask <= 0xffffffff)
-		gfp |= GFP_DMA32;
-
- again:
-	memory = dma_alloc_pages(dev, gfp, get_order(size));
-	if (memory == NULL)
-		return NULL;
-
-	{
-		int high, mmu;
-		bus = virt_to_bus(memory);
-	        high = (bus + size) >= dma_mask;
-		mmu = high;
-		if (force_iommu && !(gfp & GFP_DMA)) 
-			mmu = 1;
-		if (no_iommu || dma_mask < 0xffffffffUL) { 
-			if (high) {
-				free_pages((unsigned long)memory,
-					   get_order(size));
-
-				if (swiotlb) {
-					return
-					swiotlb_alloc_coherent(dev, size,
-							       dma_handle,
-							       gfp);
-				}
-
-				if (!(gfp & GFP_DMA)) { 
-					gfp = (gfp & ~GFP_DMA32) | GFP_DMA;
-					goto again;
-				}
-				return NULL;
-			}
-			mmu = 0; 
-		} 	
-		memset(memory, 0, size); 
-		if (!mmu) { 
-			*dma_handle = virt_to_bus(memory);
-			return memory;
-		}
-	} 
-
-	*dma_handle = dma_map_area(dev, bus, size, PCI_DMA_BIDIRECTIONAL, 0);
-	if (*dma_handle == bad_dma_address)
-		goto error; 
-	flush_gart(dev);
-	return memory; 
-	
-error:
-	if (panic_on_overflow)
-		panic("dma_alloc_coherent: IOMMU overflow by %lu bytes\n", size);
-	free_pages((unsigned long)memory, get_order(size)); 
-	return NULL; 
-}
-
-/* 
- * Unmap coherent memory.
- * The caller must ensure that the device has finished accessing the mapping.
- */
-void dma_free_coherent(struct device *dev, size_t size,
-			 void *vaddr, dma_addr_t bus)
-{
-	if (swiotlb) {
-		swiotlb_free_coherent(dev, size, vaddr, bus);
-		return;
-	}
-
-	dma_unmap_single(dev, bus, size, 0);
-	free_pages((unsigned long)vaddr, get_order(size)); 		
-}
 
 #ifdef CONFIG_IOMMU_LEAK
 
@@ -326,7 +193,7 @@
 #define CLEAR_LEAK(x)
 #endif
 
-static void iommu_full(struct device *dev, size_t size, int dir, int do_panic)
+static void iommu_full(struct device *dev, size_t size, int dir)
 {
 	/* 
 	 * Ran out of IOMMU space for this operation. This is very bad.
@@ -342,11 +209,11 @@
   "PCI-DMA: Out of IOMMU space for %lu bytes at device %s\n",
 	       size, dev->bus_id);
 
-	if (size > PAGE_SIZE*EMERGENCY_PAGES && do_panic) {
+	if (size > PAGE_SIZE*EMERGENCY_PAGES) {
 		if (dir == PCI_DMA_FROMDEVICE || dir == PCI_DMA_BIDIRECTIONAL)
 			panic("PCI-DMA: Memory would be corrupted\n");
 		if (dir == PCI_DMA_TODEVICE || dir == PCI_DMA_BIDIRECTIONAL) 
-			panic("PCI-DMA: Random memory would be DMAed\n");
+			panic(KERN_ERR "PCI-DMA: Random memory would be DMAed\n");
 	} 
 
 #ifdef CONFIG_IOMMU_LEAK
@@ -385,8 +252,8 @@
 /* Map a single continuous physical area into the IOMMU.
  * Caller needs to check if the iommu is needed and flush.
  */
-static dma_addr_t dma_map_area(struct device *dev, unsigned long phys_mem,
-				size_t size, int dir, int do_panic)
+static dma_addr_t dma_map_area(struct device *dev, dma_addr_t phys_mem,
+				size_t size, int dir)
 { 
 	unsigned long npages = to_pages(phys_mem, size);
 	unsigned long iommu_page = alloc_iommu(npages);
@@ -396,7 +263,7 @@
 			return phys_mem; 
 		if (panic_on_overflow)
 			panic("dma_map_area overflow %lu bytes\n", size);
-		iommu_full(dev, size, dir, do_panic);
+		iommu_full(dev, size, dir);
 		return bad_dma_address;
 	}
 
@@ -408,15 +275,21 @@
 	return iommu_bus_base + iommu_page*PAGE_SIZE + (phys_mem & ~PAGE_MASK);
 }
 
+static dma_addr_t gart_map_simple(struct device *dev, char *buf,
+				 size_t size, int dir)
+{
+	dma_addr_t map = dma_map_area(dev, virt_to_bus(buf), size, dir);
+	flush_gart(dev);
+	return map;
+}
+
 /* Map a single area into the IOMMU */
-dma_addr_t dma_map_single(struct device *dev, void *addr, size_t size, int dir)
+dma_addr_t gart_map_single(struct device *dev, void *addr, size_t size, int dir)
 {
 	unsigned long phys_mem, bus;
 
 	BUG_ON(dir == DMA_NONE);
 
-	if (swiotlb)
-		return swiotlb_map_single(dev,addr,size,dir);
 	if (!dev)
 		dev = &fallback_dev;
 
@@ -424,10 +297,24 @@
 	if (!need_iommu(dev, phys_mem, size))
 		return phys_mem; 
 
-	bus = dma_map_area(dev, phys_mem, size, dir, 1);
-	flush_gart(dev); 
+	bus = gart_map_simple(dev, addr, size, dir);
 	return bus; 
-} 
+}
+
+/*
+ * Wrapper for pci_unmap_single working with scatterlists.
+ */
+void gart_unmap_sg(struct device *dev, struct scatterlist *sg, int nents, int dir)
+{
+	int i;
+
+	for (i = 0; i < nents; i++) {
+		struct scatterlist *s = &sg[i];
+		if (!s->dma_length || !s->length)
+			break;
+		dma_unmap_single(dev, s->dma_address, s->dma_length, dir);
+	}
+}
 
 /* Fallback for dma_map_sg in case of overflow */
 static int dma_map_sg_nonforce(struct device *dev, struct scatterlist *sg,
@@ -443,10 +330,10 @@
 		struct scatterlist *s = &sg[i];
 		unsigned long addr = page_to_phys(s->page) + s->offset; 
 		if (nonforced_iommu(dev, addr, s->length)) { 
-			addr = dma_map_area(dev, addr, s->length, dir, 0);
+			addr = dma_map_area(dev, addr, s->length, dir);
 			if (addr == bad_dma_address) { 
 				if (i > 0) 
-					dma_unmap_sg(dev, sg, i, dir);
+					gart_unmap_sg(dev, sg, i, dir);
 				nents = 0; 
 				sg[0].dma_length = 0;
 				break;
@@ -515,7 +402,7 @@
  * DMA map all entries in a scatterlist.
  * Merge chunks that have page aligned sizes into a continuous mapping. 
  */
-int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, int dir)
+int gart_map_sg(struct device *dev, struct scatterlist *sg, int nents, int dir)
 {
 	int i;
 	int out;
@@ -527,8 +414,6 @@
 	if (nents == 0) 
 		return 0;
 
-	if (swiotlb)
-		return swiotlb_map_sg(dev,sg,nents,dir);
 	if (!dev)
 		dev = &fallback_dev;
 
@@ -571,13 +456,13 @@
 
 error:
 	flush_gart(NULL);
-	dma_unmap_sg(dev, sg, nents, dir);
+	gart_unmap_sg(dev, sg, nents, dir);
 	/* When it was forced try again unforced */
 	if (force_iommu) 
 		return dma_map_sg_nonforce(dev, sg, nents, dir);
 	if (panic_on_overflow)
 		panic("dma_map_sg: overflow on %lu pages\n", pages);
-	iommu_full(dev, pages << PAGE_SHIFT, dir, 0);
+	iommu_full(dev, pages << PAGE_SHIFT, dir);
 	for (i = 0; i < nents; i++)
 		sg[i].dma_address = bad_dma_address;
 	return 0;
@@ -586,18 +471,13 @@
 /*
  * Free a DMA mapping.
  */ 
-void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
+void gart_unmap_single(struct device *dev, dma_addr_t dma_addr,
 		      size_t size, int direction)
 {
 	unsigned long iommu_page; 
 	int npages;
 	int i;
 
-	if (swiotlb) {
-		swiotlb_unmap_single(dev,dma_addr,size,direction);
-		return;
-	}
-
 	if (dma_addr < iommu_bus_base + EMERGENCY_PAGES*PAGE_SIZE || 
 	    dma_addr >= iommu_bus_base + iommu_size)
 		return;
@@ -610,68 +490,7 @@
 	free_iommu(iommu_page, npages);
 }
 
-/* 
- * Wrapper for pci_unmap_single working with scatterlists.
- */ 
-void dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents, int dir)
-{
-	int i;
-	if (swiotlb) {
-		swiotlb_unmap_sg(dev,sg,nents,dir);
-		return;
-	}
-	for (i = 0; i < nents; i++) { 
-		struct scatterlist *s = &sg[i];
-		if (!s->dma_length || !s->length) 
-			break;
-		dma_unmap_single(dev, s->dma_address, s->dma_length, dir);
-	}
-}
-
-int dma_supported(struct device *dev, u64 mask)
-{
-	/* Copied from i386. Doesn't make much sense, because it will 
-	   only work for pci_alloc_coherent.
-	   The caller just has to use GFP_DMA in this case. */
-        if (mask < 0x00ffffff)
-                return 0;
-
-	/* Tell the device to use SAC when IOMMU force is on. 
-	   This allows the driver to use cheaper accesses in some cases.
-
-	   Problem with this is that if we overflow the IOMMU area
-	   and return DAC as fallback address the device may not handle it correctly.
-	   
-	   As a special case some controllers have a 39bit address mode 
-	   that is as efficient as 32bit (aic79xx). Don't force SAC for these.
-	   Assume all masks <= 40 bits are of this type. Normally this doesn't
-	   make any difference, but gives more gentle handling of IOMMU overflow. */
-	if (iommu_sac_force && (mask >= 0xffffffffffULL)) { 
-		printk(KERN_INFO "%s: Force SAC with mask %Lx\n", dev->bus_id,mask);
-		return 0; 
-	}
-
-	return 1;
-} 
-
-int dma_get_cache_alignment(void)
-{
-	return boot_cpu_data.x86_clflush_size;
-}
-
-EXPORT_SYMBOL(dma_unmap_sg);
-EXPORT_SYMBOL(dma_map_sg);
-EXPORT_SYMBOL(dma_map_single);
-EXPORT_SYMBOL(dma_unmap_single);
-EXPORT_SYMBOL(dma_supported);
-EXPORT_SYMBOL(no_iommu);
-EXPORT_SYMBOL(force_iommu); 
-EXPORT_SYMBOL(bad_dma_address);
-EXPORT_SYMBOL(iommu_bio_merge);
-EXPORT_SYMBOL(iommu_sac_force);
-EXPORT_SYMBOL(dma_get_cache_alignment);
-EXPORT_SYMBOL(dma_alloc_coherent);
-EXPORT_SYMBOL(dma_free_coherent);
+static int no_agp;
 
 static __init unsigned long check_iommu_size(unsigned long aper, u64 aper_size)
 { 
@@ -772,12 +591,27 @@
  nommu:
  	/* Should not happen anymore */
 	printk(KERN_ERR "PCI-DMA: More than 4GB of RAM and no IOMMU\n"
-	       KERN_ERR "PCI-DMA: 32bit PCI IO may malfunction."); 
+	       KERN_ERR "PCI-DMA: 32bit PCI IO may malfunction.\n");
 	return -1; 
 } 
 
 extern int agp_amd64_init(void);
 
+static struct dma_mapping_ops gart_dma_ops = {
+	.mapping_error = NULL,
+	.map_single = gart_map_single,
+	.map_simple = gart_map_simple,
+	.unmap_single = gart_unmap_single,
+	.sync_single_for_cpu = NULL,
+	.sync_single_for_device = NULL,
+	.sync_single_range_for_cpu = NULL,
+	.sync_single_range_for_device = NULL,
+	.sync_sg_for_cpu = NULL,
+	.sync_sg_for_device = NULL,
+	.map_sg = gart_map_sg,
+	.unmap_sg = gart_unmap_sg,
+};
+
 static int __init pci_iommu_init(void)
 { 
 	struct agp_kern_info info;
@@ -799,16 +633,15 @@
 
 	if (swiotlb) { 
 		no_iommu = 1;
-		printk(KERN_INFO "PCI-DMA: Using software bounce buffering for IO (SWIOTLB)\n");
 		return -1; 
 	} 
 	
 	if (no_iommu ||
-	    (!force_iommu && end_pfn < 0xffffffff>>PAGE_SHIFT) ||
+	    (!force_iommu && end_pfn <= MAX_DMA32_PFN) ||
 	    !iommu_aperture ||
 	    (no_agp && init_k8_gatt(&info) < 0)) {
-		printk(KERN_INFO "PCI-DMA: Disabling IOMMU.\n"); 
 		no_iommu = 1;
+		no_iommu_init();
 		return -1;
 	}
 
@@ -885,100 +718,50 @@
 		     
 	flush_gart(NULL);
 
+	printk(KERN_INFO "PCI-DMA: using GART IOMMU.\n");
+	dma_ops = &gart_dma_ops;
+
 	return 0;
 } 
 
 /* Must execute after PCI subsystem */
 fs_initcall(pci_iommu_init);
 
-/* iommu=[size][,noagp][,off][,force][,noforce][,leak][,memaper[=order]][,merge]
-         [,forcesac][,fullflush][,nomerge][,biomerge]
-   size  set size of iommu (in bytes) 
-   noagp don't initialize the AGP driver and use full aperture.
-   off   don't use the IOMMU
-   leak  turn on simple iommu leak tracing (only when CONFIG_IOMMU_LEAK is on)
-   memaper[=order] allocate an own aperture over RAM with size 32MB^order.  
-   noforce don't force IOMMU usage. Default.
-   force  Force IOMMU.
-   merge  Do lazy merging. This may improve performance on some block devices.
-          Implies force (experimental)
-   biomerge Do merging at the BIO layer. This is more efficient than merge,
-            but should be only done with very big IOMMUs. Implies merge,force.
-   nomerge Don't do SG merging.
-   forcesac For SAC mode for masks <40bits  (experimental)
-   fullflush Flush IOMMU on each allocation (default) 
-   nofullflush Don't use IOMMU fullflush
-   allowed  overwrite iommu off workarounds for specific chipsets.
-   soft	 Use software bounce buffering (default for Intel machines)
-   noaperture Don't touch the aperture for AGP.
-*/
-__init int iommu_setup(char *p)
-{ 
-    int arg;
+void gart_parse_options(char *p)
+{
+	int arg;
 
-    while (*p) {
-	    if (!strncmp(p,"noagp",5))
-		    no_agp = 1;
-	    if (!strncmp(p,"off",3))
-		    no_iommu = 1;
-	    if (!strncmp(p,"force",5)) {
-		    force_iommu = 1;
-		    iommu_aperture_allowed = 1;
-	    }
-	    if (!strncmp(p,"allowed",7))
-		    iommu_aperture_allowed = 1;
-	    if (!strncmp(p,"noforce",7)) {
-		    iommu_merge = 0;
-		    force_iommu = 0;
-	    }
-	    if (!strncmp(p, "memaper", 7)) {
-		    fallback_aper_force = 1; 
-		    p += 7; 
-		    if (*p == '=') {
-			    ++p;
-			    if (get_option(&p, &arg))
-				    fallback_aper_order = arg;
-		    }
-	    } 
-	    if (!strncmp(p, "biomerge",8)) {
-		    iommu_bio_merge = 4096;
-		    iommu_merge = 1;
-		    force_iommu = 1;
-	    }
-	    if (!strncmp(p, "panic",5))
-		    panic_on_overflow = 1;
-	    if (!strncmp(p, "nopanic",7))
-		    panic_on_overflow = 0;	    
-	    if (!strncmp(p, "merge",5)) {
-		    iommu_merge = 1;
-		    force_iommu = 1; 
-	    }
-	    if (!strncmp(p, "nomerge",7))
-		    iommu_merge = 0;
-	    if (!strncmp(p, "forcesac",8))
-		    iommu_sac_force = 1;
-	    if (!strncmp(p, "fullflush",8))
-		    iommu_fullflush = 1;
-	    if (!strncmp(p, "nofullflush",11))
-		    iommu_fullflush = 0;
-	    if (!strncmp(p, "soft",4))
-		    swiotlb = 1;
-	    if (!strncmp(p, "noaperture",10))
-		    fix_aperture = 0;
 #ifdef CONFIG_IOMMU_LEAK
-	    if (!strncmp(p,"leak",4)) {
-		    leak_trace = 1;
-		    p += 4; 
-		    if (*p == '=') ++p;
-		    if (isdigit(*p) && get_option(&p, &arg))
-			    iommu_leak_pages = arg;
-	    } else
+	if (!strncmp(p,"leak",4)) {
+		leak_trace = 1;
+		p += 4;
+		if (*p == '=') ++p;
+		if (isdigit(*p) && get_option(&p, &arg))
+			iommu_leak_pages = arg;
+	}
 #endif
-	    if (isdigit(*p) && get_option(&p, &arg)) 
-		    iommu_size = arg;
-	    p += strcspn(p, ",");
-	    if (*p == ',')
-		    ++p;
-    }
-    return 1;
-} 
+	if (isdigit(*p) && get_option(&p, &arg))
+		iommu_size = arg;
+	if (!strncmp(p, "fullflush",8))
+		iommu_fullflush = 1;
+	if (!strncmp(p, "nofullflush",11))
+		iommu_fullflush = 0;
+	if (!strncmp(p,"noagp",5))
+		no_agp = 1;
+	if (!strncmp(p, "noaperture",10))
+		fix_aperture = 0;
+	/* duplicated from pci-dma.c */
+	if (!strncmp(p,"force",5))
+		iommu_aperture_allowed = 1;
+	if (!strncmp(p,"allowed",7))
+		iommu_aperture_allowed = 1;
+	if (!strncmp(p, "memaper", 7)) {
+		fallback_aper_force = 1;
+		p += 7;
+		if (*p == '=') {
+			++p;
+			if (get_option(&p, &arg))
+				fallback_aper_order = arg;
+		}
+	}
+}
diff --git a/arch/x86_64/kernel/pci-nommu.c b/arch/x86_64/kernel/pci-nommu.c
index 5a981dc..e415649 100644
--- a/arch/x86_64/kernel/pci-nommu.c
+++ b/arch/x86_64/kernel/pci-nommu.c
@@ -6,89 +6,94 @@
 #include <linux/string.h>
 #include <asm/proto.h>
 #include <asm/processor.h>
+#include <asm/dma.h>
 
-int iommu_merge = 0;
-EXPORT_SYMBOL(iommu_merge);
-
-dma_addr_t bad_dma_address;
-EXPORT_SYMBOL(bad_dma_address);
-
-int iommu_bio_merge = 0;
-EXPORT_SYMBOL(iommu_bio_merge);
-
-int iommu_sac_force = 0;
-EXPORT_SYMBOL(iommu_sac_force);
-
-/* 
- * Dummy IO MMU functions
- */
-
-void *dma_alloc_coherent(struct device *hwdev, size_t size,
-			 dma_addr_t *dma_handle, gfp_t gfp)
+static int
+check_addr(char *name, struct device *hwdev, dma_addr_t bus, size_t size)
 {
-	void *ret;
-	u64 mask;
-	int order = get_order(size);
-
-	if (hwdev)
-		mask = hwdev->coherent_dma_mask & *hwdev->dma_mask;
-	else
-		mask = 0xffffffff;
-	for (;;) {
-		ret = (void *)__get_free_pages(gfp, order);
-		if (ret == NULL)
-			return NULL;
-		*dma_handle = virt_to_bus(ret);
-		if ((*dma_handle & ~mask) == 0)
-			break;
-		free_pages((unsigned long)ret, order);
-		if (gfp & GFP_DMA)
-			return NULL;
-		gfp |= GFP_DMA;
+        if (hwdev && bus + size > *hwdev->dma_mask) {
+		printk(KERN_ERR
+		    "nommu_%s: overflow %Lx+%lu of device mask %Lx\n",
+	       name, (long long)bus, size, (long long)*hwdev->dma_mask);
+		return 0;
 	}
-
-	memset(ret, 0, size);
-	return ret;
-}
-EXPORT_SYMBOL(dma_alloc_coherent);
-
-void dma_free_coherent(struct device *hwdev, size_t size,
-			 void *vaddr, dma_addr_t dma_handle)
-{
-	free_pages((unsigned long)vaddr, get_order(size));
-}
-EXPORT_SYMBOL(dma_free_coherent);
-
-int dma_supported(struct device *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..
-	 * RED-PEN this won't work for pci_map_single. Caller has to
-	 * use GFP_DMA in the first place.
-         */
-        if (mask < 0x00ffffff)
-                return 0;
-
 	return 1;
-} 
-EXPORT_SYMBOL(dma_supported);
-
-int dma_get_cache_alignment(void)
-{
-	return boot_cpu_data.x86_clflush_size;
 }
-EXPORT_SYMBOL(dma_get_cache_alignment);
 
-static int __init check_ram(void) 
-{ 
-	if (end_pfn >= 0xffffffff>>PAGE_SHIFT) { 
-		printk(
-		KERN_ERR "WARNING more than 4GB of memory but IOMMU not compiled in.\n"
-		KERN_ERR "WARNING 32bit PCI may malfunction.\n");
-	} 
-	return 0;
-} 
-__initcall(check_ram);
+static dma_addr_t
+nommu_map_single(struct device *hwdev, void *ptr, size_t size,
+	       int direction)
+{
+	dma_addr_t bus = virt_to_bus(ptr);
+	if (!check_addr("map_single", hwdev, bus, size))
+				return bad_dma_address;
+	return bus;
+}
 
+void nommu_unmap_single(struct device *dev, dma_addr_t addr,size_t size,
+			int direction)
+{
+}
+
+/* Map a set of buffers described by scatterlist in streaming
+ * mode for DMA.  This is the scatter-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.
+ */
+int nommu_map_sg(struct device *hwdev, struct scatterlist *sg,
+	       int nents, int direction)
+{
+	int i;
+
+	BUG_ON(direction == DMA_NONE);
+ 	for (i = 0; i < nents; i++ ) {
+		struct scatterlist *s = &sg[i];
+		BUG_ON(!s->page);
+		s->dma_address = virt_to_bus(page_address(s->page) +s->offset);
+		if (!check_addr("map_sg", hwdev, s->dma_address, s->length))
+			return 0;
+		s->dma_length = s->length;
+	}
+	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.
+ */
+void nommu_unmap_sg(struct device *dev, struct scatterlist *sg,
+		  int nents, int dir)
+{
+}
+
+struct dma_mapping_ops nommu_dma_ops = {
+	.map_single = nommu_map_single,
+	.unmap_single = nommu_unmap_single,
+	.map_sg = nommu_map_sg,
+	.unmap_sg = nommu_unmap_sg,
+	.is_phys = 1,
+};
+
+void __init no_iommu_init(void)
+{
+	if (dma_ops)
+		return;
+	printk(KERN_INFO "PCI-DMA: Disabling IOMMU.\n");
+	dma_ops = &nommu_dma_ops;
+	if (end_pfn > MAX_DMA32_PFN) {
+		printk(KERN_ERR
+		       "WARNING more than 4GB of memory but IOMMU not compiled in.\n"
+		       KERN_ERR "WARNING 32bit PCI may malfunction.\n"
+		       KERN_ERR "You might want to enable CONFIG_GART_IOMMU\n");
+	}
+}
diff --git a/arch/x86_64/kernel/pci-swiotlb.c b/arch/x86_64/kernel/pci-swiotlb.c
new file mode 100644
index 0000000..3569a25
--- /dev/null
+++ b/arch/x86_64/kernel/pci-swiotlb.c
@@ -0,0 +1,42 @@
+/* Glue code to lib/swiotlb.c */
+
+#include <linux/pci.h>
+#include <linux/cache.h>
+#include <linux/module.h>
+#include <asm/dma-mapping.h>
+#include <asm/proto.h>
+#include <asm/swiotlb.h>
+#include <asm/dma.h>
+
+int swiotlb __read_mostly;
+EXPORT_SYMBOL(swiotlb);
+
+struct dma_mapping_ops swiotlb_dma_ops = {
+	.mapping_error = swiotlb_dma_mapping_error,
+	.alloc_coherent = swiotlb_alloc_coherent,
+	.free_coherent = swiotlb_free_coherent,
+	.map_single = swiotlb_map_single,
+	.unmap_single = swiotlb_unmap_single,
+	.sync_single_for_cpu = swiotlb_sync_single_for_cpu,
+	.sync_single_for_device = swiotlb_sync_single_for_device,
+	.sync_single_range_for_cpu = swiotlb_sync_single_range_for_cpu,
+	.sync_single_range_for_device = swiotlb_sync_single_range_for_device,
+	.sync_sg_for_cpu = swiotlb_sync_sg_for_cpu,
+	.sync_sg_for_device = swiotlb_sync_sg_for_device,
+	.map_sg = swiotlb_map_sg,
+	.unmap_sg = swiotlb_unmap_sg,
+	.dma_supported = NULL,
+};
+
+void pci_swiotlb_init(void)
+{
+	/* don't initialize swiotlb if iommu=off (no_iommu=1) */
+	if (!iommu_aperture && !no_iommu &&
+	    (end_pfn > MAX_DMA32_PFN || force_iommu))
+	       swiotlb = 1;
+	if (swiotlb) {
+		swiotlb_init();
+		printk(KERN_INFO "PCI-DMA: Using software bounce buffering for IO (SWIOTLB)\n");
+		dma_ops = &swiotlb_dma_ops;
+	}
+}
diff --git a/arch/x86_64/kernel/process.c b/arch/x86_64/kernel/process.c
index 3060ed9..8ded407 100644
--- a/arch/x86_64/kernel/process.c
+++ b/arch/x86_64/kernel/process.c
@@ -36,6 +36,7 @@
 #include <linux/utsname.h>
 #include <linux/random.h>
 #include <linux/kprobes.h>
+#include <linux/notifier.h>
 
 #include <asm/uaccess.h>
 #include <asm/pgtable.h>
@@ -50,13 +51,12 @@
 #include <asm/desc.h>
 #include <asm/proto.h>
 #include <asm/ia32.h>
+#include <asm/idle.h>
 
 asmlinkage extern void ret_from_fork(void);
 
 unsigned long kernel_thread_flags = CLONE_VM | CLONE_UNTRACED;
 
-static atomic_t hlt_counter = ATOMIC_INIT(0);
-
 unsigned long boot_option_idle_override = 0;
 EXPORT_SYMBOL(boot_option_idle_override);
 
@@ -66,19 +66,49 @@
 void (*pm_idle)(void);
 static DEFINE_PER_CPU(unsigned int, cpu_idle_state);
 
-void disable_hlt(void)
+static struct notifier_block *idle_notifier;
+static DEFINE_SPINLOCK(idle_notifier_lock);
+
+void idle_notifier_register(struct notifier_block *n)
 {
-	atomic_inc(&hlt_counter);
+	unsigned long flags;
+	spin_lock_irqsave(&idle_notifier_lock, flags);
+	notifier_chain_register(&idle_notifier, n);
+	spin_unlock_irqrestore(&idle_notifier_lock, flags);
+}
+EXPORT_SYMBOL_GPL(idle_notifier_register);
+
+void idle_notifier_unregister(struct notifier_block *n)
+{
+	unsigned long flags;
+	spin_lock_irqsave(&idle_notifier_lock, flags);
+	notifier_chain_unregister(&idle_notifier, n);
+	spin_unlock_irqrestore(&idle_notifier_lock, flags);
+}
+EXPORT_SYMBOL(idle_notifier_unregister);
+
+enum idle_state { CPU_IDLE, CPU_NOT_IDLE };
+static DEFINE_PER_CPU(enum idle_state, idle_state) = CPU_NOT_IDLE;
+
+void enter_idle(void)
+{
+	__get_cpu_var(idle_state) = CPU_IDLE;
+	notifier_call_chain(&idle_notifier, IDLE_START, NULL);
 }
 
-EXPORT_SYMBOL(disable_hlt);
-
-void enable_hlt(void)
+static void __exit_idle(void)
 {
-	atomic_dec(&hlt_counter);
+	__get_cpu_var(idle_state) = CPU_NOT_IDLE;
+	notifier_call_chain(&idle_notifier, IDLE_END, NULL);
 }
 
-EXPORT_SYMBOL(enable_hlt);
+/* Called from interrupts to signify idle end */
+void exit_idle(void)
+{
+	if (current->pid | read_pda(irqcount))
+		return;
+	__exit_idle();
+}
 
 /*
  * We use this if we don't have any better
@@ -88,21 +118,16 @@
 {
 	local_irq_enable();
 
-	if (!atomic_read(&hlt_counter)) {
-		clear_thread_flag(TIF_POLLING_NRFLAG);
-		smp_mb__after_clear_bit();
-		while (!need_resched()) {
-			local_irq_disable();
-			if (!need_resched())
-				safe_halt();
-			else
-				local_irq_enable();
-		}
-		set_thread_flag(TIF_POLLING_NRFLAG);
-	} else {
-		while (!need_resched())
-			cpu_relax();
+	clear_thread_flag(TIF_POLLING_NRFLAG);
+	smp_mb__after_clear_bit();
+	while (!need_resched()) {
+		local_irq_disable();
+		if (!need_resched())
+			safe_halt();
+		else
+			local_irq_enable();
 	}
+	set_thread_flag(TIF_POLLING_NRFLAG);
 }
 
 /*
@@ -201,7 +226,9 @@
 				idle = default_idle;
 			if (cpu_is_offline(smp_processor_id()))
 				play_dead();
+			enter_idle();
 			idle();
+			__exit_idle();
 		}
 
 		preempt_enable_no_resched();
@@ -424,7 +451,7 @@
 	struct task_struct *me = current;
 
 	childregs = ((struct pt_regs *)
-			(THREAD_SIZE + (unsigned long) p->thread_info)) - 1;
+			(THREAD_SIZE + task_stack_page(p))) - 1;
 	*childregs = *regs;
 
 	childregs->rax = 0;
@@ -436,7 +463,7 @@
 	p->thread.rsp0 = (unsigned long) (childregs+1);
 	p->thread.userrsp = me->thread.userrsp; 
 
-	set_ti_thread_flag(p->thread_info, TIF_FORK);
+	set_tsk_thread_flag(p, TIF_FORK);
 
 	p->thread.fs = me->thread.fs;
 	p->thread.gs = me->thread.gs;
@@ -563,7 +590,7 @@
 	write_pda(oldrsp, next->userrsp); 
 	write_pda(pcurrent, next_p); 
 	write_pda(kernelstack,
-	    (unsigned long)next_p->thread_info + THREAD_SIZE - PDA_STACKOFFSET);
+		  task_stack_page(next_p) + THREAD_SIZE - PDA_STACKOFFSET);
 
 	/*
 	 * Now maybe reload the debug registers
@@ -677,7 +704,7 @@
 
 	if (!p || p == current || p->state==TASK_RUNNING)
 		return 0; 
-	stack = (unsigned long)p->thread_info; 
+	stack = (unsigned long)task_stack_page(p);
 	if (p->thread.rsp < stack || p->thread.rsp > stack+THREAD_SIZE)
 		return 0;
 	fp = *(u64 *)(p->thread.rsp);
@@ -795,8 +822,7 @@
 {
 	struct pt_regs *pp, ptregs;
 
-	pp = (struct pt_regs *)(tsk->thread.rsp0);
-	--pp; 
+	pp = task_pt_regs(tsk);
 
 	ptregs = *pp; 
 	ptregs.cs &= 0xffff;
diff --git a/arch/x86_64/kernel/ptrace.c b/arch/x86_64/kernel/ptrace.c
index a87b6ce..5320562 100644
--- a/arch/x86_64/kernel/ptrace.c
+++ b/arch/x86_64/kernel/ptrace.c
@@ -36,9 +36,12 @@
  * in exit.c or in signal.c.
  */
 
-/* determines which flags the user has access to. */
-/* 1 = access 0 = no access */
-#define FLAG_MASK 0x44dd5UL
+/*
+ * Determines which flags the user has access to [1 = access, 0 = no access].
+ * Prohibits changing ID(21), VIP(20), VIF(19), VM(17), IOPL(12-13), IF(9).
+ * Also masks reserved bits (63-22, 15, 5, 3, 1).
+ */
+#define FLAG_MASK 0x54dd5UL
 
 /* set's the trap flag. */
 #define TRAP_FLAG 0x100UL
@@ -64,12 +67,6 @@
 	return (*((unsigned long *)stack));
 }
 
-static inline struct pt_regs *get_child_regs(struct task_struct *task)
-{
-	struct pt_regs *regs = (void *)task->thread.rsp0;
-	return regs - 1;
-}
-
 /*
  * this routine will put a word on the processes privileged stack. 
  * the offset is how far from the base addr as stored in the TSS.  
@@ -167,7 +164,7 @@
 
 static void set_singlestep(struct task_struct *child)
 {
-	struct pt_regs *regs = get_child_regs(child);
+	struct pt_regs *regs = task_pt_regs(child);
 
 	/*
 	 * Always set TIF_SINGLESTEP - this guarantees that
@@ -205,7 +202,7 @@
 
 	/* But touch TF only if it was set by us.. */
 	if (child->ptrace & PT_DTRACE) {
-		struct pt_regs *regs = get_child_regs(child);
+		struct pt_regs *regs = task_pt_regs(child);
 		regs->eflags &= ~TRAP_FLAG;
 		child->ptrace &= ~PT_DTRACE;
 	}
diff --git a/arch/x86_64/kernel/reboot.c b/arch/x86_64/kernel/reboot.c
index 75235ed..57117b8 100644
--- a/arch/x86_64/kernel/reboot.c
+++ b/arch/x86_64/kernel/reboot.c
@@ -6,6 +6,7 @@
 #include <linux/kernel.h>
 #include <linux/ctype.h>
 #include <linux/string.h>
+#include <linux/pm.h>
 #include <asm/io.h>
 #include <asm/kdebug.h>
 #include <asm/delay.h>
@@ -154,10 +155,11 @@
 
 void machine_power_off(void)
 {
-	if (!reboot_force) {
-		machine_shutdown();
-	}
-	if (pm_power_off)
+	if (pm_power_off) {
+		if (!reboot_force) {
+			machine_shutdown();
+		}
 		pm_power_off();
+	}
 }
 
diff --git a/arch/x86_64/kernel/setup.c b/arch/x86_64/kernel/setup.c
index 64c4534..28895c0 100644
--- a/arch/x86_64/kernel/setup.c
+++ b/arch/x86_64/kernel/setup.c
@@ -35,6 +35,7 @@
 #include <asm/processor.h>
 #include <linux/console.h>
 #include <linux/seq_file.h>
+#include <linux/crash_dump.h>
 #include <linux/root_dev.h>
 #include <linux/pci.h>
 #include <linux/acpi.h>
@@ -43,6 +44,8 @@
 #include <linux/mmzone.h>
 #include <linux/kexec.h>
 #include <linux/cpufreq.h>
+#include <linux/dmi.h>
+#include <linux/dma-mapping.h>
 
 #include <asm/mtrr.h>
 #include <asm/uaccess.h>
@@ -61,7 +64,9 @@
 #include <asm/setup.h>
 #include <asm/mach_apic.h>
 #include <asm/numa.h>
+#include <asm/swiotlb.h>
 #include <asm/sections.h>
+#include <asm/gart-mapping.h>
 
 /*
  * Machine setup..
@@ -86,11 +91,6 @@
 
 unsigned long saved_video_mode;
 
-#ifdef CONFIG_SWIOTLB
-int swiotlb;
-EXPORT_SYMBOL(swiotlb);
-#endif
-
 /*
  * Setup options
  */
@@ -275,10 +275,7 @@
 {
 	char c = ' ', *to = command_line, *from = COMMAND_LINE;
 	int len = 0;
-
-	/* Save unparsed command line copy for /proc/cmdline */
-	memcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
-	saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
+	int userdef = 0;
 
 	for (;;) {
 		if (c != ' ') 
@@ -346,10 +343,14 @@
 		    !memcmp(from, "disableapic", 11))
 			disable_apic = 1;
 
-		if (!memcmp(from, "noapic", 6)) 
+		/* Don't confuse with noapictimer */
+		if (!memcmp(from, "noapic", 6) &&
+			(from[6] == ' ' || from[6] == 0))
 			skip_ioapic_setup = 1;
 
-		if (!memcmp(from, "apic", 4)) { 
+		/* Make sure to not confuse with apic= */
+		if (!memcmp(from, "apic", 4) &&
+			(from[4] == ' ' || from[4] == 0)) {
 			skip_ioapic_setup = 0;
 			ioapic_force = 1;
 		}
@@ -357,16 +358,36 @@
 		if (!memcmp(from, "mem=", 4))
 			parse_memopt(from+4, &from); 
 
+		if (!memcmp(from, "memmap=", 7)) {
+			/* exactmap option is for used defined memory */
+			if (!memcmp(from+7, "exactmap", 8)) {
+#ifdef CONFIG_CRASH_DUMP
+				/* If we are doing a crash dump, we
+				 * still need to know the real mem
+				 * size before original memory map is
+				 * reset.
+				 */
+				saved_max_pfn = e820_end_of_ram();
+#endif
+				from += 8+7;
+				end_pfn_map = 0;
+				e820.nr_map = 0;
+				userdef = 1;
+			}
+			else {
+				parse_memmapopt(from+7, &from);
+				userdef = 1;
+			}
+		}
+
 #ifdef CONFIG_NUMA
 		if (!memcmp(from, "numa=", 5))
 			numa_setup(from+5); 
 #endif
 
-#ifdef CONFIG_GART_IOMMU 
 		if (!memcmp(from,"iommu=",6)) { 
 			iommu_setup(from+6); 
 		}
-#endif
 
 		if (!memcmp(from,"oops=panic", 10))
 			panic_on_oops = 1;
@@ -395,6 +416,14 @@
 		}
 #endif
 
+#ifdef CONFIG_PROC_VMCORE
+		/* elfcorehdr= specifies the location of elf core header
+		 * stored by the crashed kernel. This option will be passed
+		 * by kexec loader to the capture kernel.
+		 */
+		else if(!memcmp(from, "elfcorehdr=", 11))
+			elfcorehdr_addr = memparse(from+11, &from);
+#endif
 	next_char:
 		c = *(from++);
 		if (!c)
@@ -403,6 +432,10 @@
 			break;
 		*(to++) = c;
 	}
+	if (userdef) {
+		printk(KERN_INFO "user-defined physical RAM map:\n");
+		e820_print_map("user");
+	}
 	*to = '\0';
 	*cmdline_p = command_line;
 }
@@ -443,6 +476,8 @@
      k8nops + 1 + 2 + 3 + 4 + 5 + 6 + 7,
 }; 
 
+extern char __vsyscall_0;
+
 /* Replace instructions with better alternatives for this CPU type.
 
    This runs before SMP is initialized to avoid SMP problems with
@@ -454,11 +489,17 @@
 	struct alt_instr *a; 
 	int diff, i, k;
 	for (a = start; (void *)a < end; a++) { 
+		u8 *instr;
+
 		if (!boot_cpu_has(a->cpuid))
 			continue;
 
 		BUG_ON(a->replacementlen > a->instrlen); 
-		__inline_memcpy(a->instr, a->replacement, a->replacementlen); 
+		instr = a->instr;
+		/* vsyscall code is not mapped yet. resolve it manually. */
+		if (instr >= (u8 *)VSYSCALL_START && instr < (u8*)VSYSCALL_END)
+			instr = __va(instr - (u8*)VSYSCALL_START + (u8*)__pa_symbol(&__vsyscall_0));
+		__inline_memcpy(instr, a->replacement, a->replacementlen);
 		diff = a->instrlen - a->replacementlen; 
 
 		/* Pad the rest with nops */
@@ -466,7 +507,7 @@
 			k = diff;
 			if (k > ASM_NOP_MAX)
 				k = ASM_NOP_MAX;
-			__inline_memcpy(a->instr + i, k8_nops[k], k); 
+			__inline_memcpy(instr + i, k8_nops[k], k);
 		} 
 	}
 } 
@@ -670,6 +711,8 @@
 	acpi_boot_init();
 #endif
 
+	init_cpu_to_node();
+
 #ifdef CONFIG_X86_LOCAL_APIC
 	/*
 	 * get boot-time SMP configuration:
@@ -834,7 +877,6 @@
 static int __init init_amd(struct cpuinfo_x86 *c)
 {
 	int r;
-	int level;
 
 #ifdef CONFIG_SMP
 	unsigned long value;
@@ -857,11 +899,6 @@
 	   3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
 	clear_bit(0*32+31, &c->x86_capability);
 	
-	/* C-stepping K8? */
-	level = cpuid_eax(1);
-	if ((level >= 0x0f48 && level < 0x0f50) || level >= 0x0f58)
-		set_bit(X86_FEATURE_K8_C, &c->x86_capability);
-
 	r = get_model_name(c);
 	if (!r) { 
 		switch (c->x86) { 
@@ -874,6 +911,10 @@
 	} 
 	display_cacheinfo(c);
 
+	/* c->x86_power is 8000_0007 edx. Bit 8 is constant TSC */
+	if (c->x86_power & (1<<8))
+		set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability);
+
 	if (c->extended_cpuid_level >= 0x80000008) {
 		c->x86_max_cores = (cpuid_ecx(0x80000008) & 0xff) + 1;
 		if (c->x86_max_cores & (c->x86_max_cores - 1))
@@ -992,8 +1033,10 @@
 
 	if (c->x86 == 15)
 		c->x86_cache_alignment = c->x86_clflush_size * 2;
-	if (c->x86 >= 15)
+	if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
+	    (c->x86 == 0x6 && c->x86_model >= 0x0e))
 		set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability);
+	set_bit(X86_FEATURE_SYNC_RDTSC, &c->x86_capability);
  	c->x86_max_cores = intel_num_cpu_cores(c);
 
 	srat_detect_node();
@@ -1192,7 +1235,7 @@
 		NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 		NULL, NULL, NULL, "syscall", NULL, NULL, NULL, NULL,
 		NULL, NULL, NULL, NULL, "nx", NULL, "mmxext", NULL,
-		NULL, "fxsr_opt", NULL, NULL, NULL, "lm", "3dnowext", "3dnow",
+		NULL, "fxsr_opt", "rdtscp", NULL, NULL, "lm", "3dnowext", "3dnow",
 
 		/* Transmeta-defined */
 		"recovery", "longrun", NULL, "lrti", NULL, NULL, NULL, NULL,
@@ -1220,7 +1263,7 @@
 		NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 
 		/* AMD-defined (#2) */
-		"lahf_lm", "cmp_legacy", NULL, NULL, NULL, NULL, NULL, NULL,
+		"lahf_lm", "cmp_legacy", "svm", NULL, "cr8_legacy", NULL, NULL, NULL,
 		NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 		NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 		NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
@@ -1231,7 +1274,9 @@
 		"vid",  /* voltage id control */
 		"ttp",  /* thermal trip */
 		"tm",
-		"stc"
+		"stc",
+		NULL,
+		/* nothing */	/* constant_tsc - moved to flags */
 	};
 
 
@@ -1311,8 +1356,11 @@
 		unsigned i;
 		for (i = 0; i < 32; i++) 
 			if (c->x86_power & (1 << i)) {
-				if (i < ARRAY_SIZE(x86_power_flags))
-					seq_printf(m, " %s", x86_power_flags[i]);
+				if (i < ARRAY_SIZE(x86_power_flags) &&
+					x86_power_flags[i])
+					seq_printf(m, "%s%s",
+						x86_power_flags[i][0]?" ":"",
+						x86_power_flags[i]);
 				else
 					seq_printf(m, " [%d]", i);
 			}
@@ -1344,3 +1392,11 @@
 	.stop =	c_stop,
 	.show =	show_cpuinfo,
 };
+
+static int __init run_dmi_scan(void)
+{
+	dmi_scan_machine();
+	return 0;
+}
+core_initcall(run_dmi_scan);
+
diff --git a/arch/x86_64/kernel/setup64.c b/arch/x86_64/kernel/setup64.c
index 06dc354..6eff51e 100644
--- a/arch/x86_64/kernel/setup64.c
+++ b/arch/x86_64/kernel/setup64.c
@@ -30,7 +30,8 @@
 
 cpumask_t cpu_initialized __cpuinitdata = CPU_MASK_NONE;
 
-struct x8664_pda cpu_pda[NR_CPUS] __cacheline_aligned; 
+struct x8664_pda *_cpu_pda[NR_CPUS] __read_mostly;
+struct x8664_pda boot_cpu_pda[NR_CPUS] __cacheline_aligned;
 
 struct desc_ptr idt_descr = { 256 * 16, (unsigned long) idt_table }; 
 
@@ -110,18 +111,18 @@
 		}
 		if (!ptr)
 			panic("Cannot allocate cpu data for CPU %d\n", i);
-		cpu_pda[i].data_offset = ptr - __per_cpu_start;
+		cpu_pda(i)->data_offset = ptr - __per_cpu_start;
 		memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
 	}
 } 
 
 void pda_init(int cpu)
 { 
-	struct x8664_pda *pda = &cpu_pda[cpu];
+	struct x8664_pda *pda = cpu_pda(cpu);
 
 	/* Setup up data that may be needed in __get_free_pages early */
 	asm volatile("movl %0,%%fs ; movl %0,%%gs" :: "r" (0)); 
-	wrmsrl(MSR_GS_BASE, cpu_pda + cpu);
+	wrmsrl(MSR_GS_BASE, pda);
 
 	pda->cpunumber = cpu; 
 	pda->irqcount = -1;
@@ -145,7 +146,7 @@
 	pda->irqstackptr += IRQSTACKSIZE-64;
 } 
 
-char boot_exception_stacks[N_EXCEPTION_STACKS * EXCEPTION_STKSZ] 
+char boot_exception_stacks[(N_EXCEPTION_STACKS - 2) * EXCEPTION_STKSZ + DEBUG_STKSZ]
 __attribute__((section(".bss.page_aligned")));
 
 /* May not be marked __init: used by software suspend */
@@ -213,23 +214,14 @@
 	 * Initialize the per-CPU GDT with the boot GDT,
 	 * and set up the GDT descriptor:
 	 */
-	if (cpu) {
-		memcpy(cpu_gdt_table[cpu], cpu_gdt_table[0], GDT_SIZE);
-	}	
+	if (cpu)
+ 		memcpy(cpu_gdt(cpu), cpu_gdt_table, GDT_SIZE);
 
 	cpu_gdt_descr[cpu].size = GDT_SIZE;
-	cpu_gdt_descr[cpu].address = (unsigned long)cpu_gdt_table[cpu];
 	asm volatile("lgdt %0" :: "m" (cpu_gdt_descr[cpu]));
 	asm volatile("lidt %0" :: "m" (idt_descr));
 
-	memcpy(me->thread.tls_array, cpu_gdt_table[cpu], GDT_ENTRY_TLS_ENTRIES * 8);
-
-	/*
-	 * Delete NT
-	 */
-
-	asm volatile("pushfq ; popq %%rax ; btr $14,%%rax ; pushq %%rax ; popfq" ::: "eax");
-
+	memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
 	syscall_init();
 
 	wrmsrl(MSR_FS_BASE, 0);
@@ -243,13 +235,27 @@
 	 */
 	for (v = 0; v < N_EXCEPTION_STACKS; v++) {
 		if (cpu) {
-			estacks = (char *)__get_free_pages(GFP_ATOMIC, 
-						   EXCEPTION_STACK_ORDER);
+			static const unsigned int order[N_EXCEPTION_STACKS] = {
+				[0 ... N_EXCEPTION_STACKS - 1] = EXCEPTION_STACK_ORDER,
+				[DEBUG_STACK - 1] = DEBUG_STACK_ORDER
+			};
+
+			estacks = (char *)__get_free_pages(GFP_ATOMIC, order[v]);
 			if (!estacks)
 				panic("Cannot allocate exception stack %ld %d\n",
 				      v, cpu); 
 		}
-		estacks += EXCEPTION_STKSZ;
+		switch (v + 1) {
+#if DEBUG_STKSZ > EXCEPTION_STKSZ
+		case DEBUG_STACK:
+			cpu_pda[cpu].debugstack = (unsigned long)estacks;
+			estacks += DEBUG_STKSZ;
+			break;
+#endif
+		default:
+			estacks += EXCEPTION_STKSZ;
+			break;
+		}
 		t->ist[v] = (unsigned long)estacks;
 	}
 
diff --git a/arch/x86_64/kernel/smp.c b/arch/x86_64/kernel/smp.c
index cfc3d9d..19ef012 100644
--- a/arch/x86_64/kernel/smp.c
+++ b/arch/x86_64/kernel/smp.c
@@ -27,6 +27,7 @@
 #include <asm/mmu_context.h>
 #include <asm/proto.h>
 #include <asm/apicdef.h>
+#include <asm/idle.h>
 
 /*
  *	Smarter SMP flushing macros. 
@@ -280,11 +281,6 @@
 	on_each_cpu(do_flush_tlb_all, NULL, 1, 1);
 }
 
-void smp_kdb_stop(void)
-{
-	send_IPI_allbutself(KDB_VECTOR);
-}
-
 /*
  * this function sends a 'reschedule' IPI to another CPU.
  * it goes straight through and wastes no time serializing
@@ -512,6 +508,7 @@
 	/*
 	 * At this point the info structure may be out of scope unless wait==1
 	 */
+	exit_idle();
 	irq_enter();
 	(*func)(info);
 	irq_exit();
diff --git a/arch/x86_64/kernel/smpboot.c b/arch/x86_64/kernel/smpboot.c
index ecbd7b8..a28756e 100644
--- a/arch/x86_64/kernel/smpboot.c
+++ b/arch/x86_64/kernel/smpboot.c
@@ -335,7 +335,13 @@
 
 static void __cpuinit tsc_sync_wait(void)
 {
-	if (notscsync || !cpu_has_tsc)
+	/*
+	 * When the CPU has synchronized TSCs assume the BIOS
+  	 * or the hardware already synced.  Otherwise we could
+	 * mess up a possible perfect synchronization with a
+	 * not-quite-perfect algorithm.
+	 */
+	if (notscsync || !cpu_has_tsc || !unsynchronized_tsc())
 		return;
 	sync_tsc(0);
 }
@@ -646,6 +652,7 @@
 		send_status = apic_read(APIC_ICR) & APIC_ICR_BUSY;
 	} while (send_status && (timeout++ < 1000));
 
+	mb();
 	atomic_set(&init_deasserted, 1);
 
 	num_starts = 2;
@@ -659,7 +666,6 @@
 
 	for (j = 1; j <= num_starts; j++) {
 		Dprintk("Sending STARTUP #%d.\n",j);
-		apic_read_around(APIC_SPIV);
 		apic_write(APIC_ESR, 0);
 		apic_read(APIC_ESR);
 		Dprintk("After apic_write.\n");
@@ -698,7 +704,6 @@
 		 * Due to the Pentium erratum 3AP.
 		 */
 		if (maxlvt > 3) {
-			apic_read_around(APIC_SPIV);
 			apic_write(APIC_ESR, 0);
 		}
 		accept_status = (apic_read(APIC_ESR) & 0xEF);
@@ -743,11 +748,35 @@
 	};
 	DECLARE_WORK(work, do_fork_idle, &c_idle);
 
+	/* allocate memory for gdts of secondary cpus. Hotplug is considered */
+	if (!cpu_gdt_descr[cpu].address &&
+		!(cpu_gdt_descr[cpu].address = get_zeroed_page(GFP_KERNEL))) {
+		printk(KERN_ERR "Failed to allocate GDT for CPU %d\n", cpu);
+		return -1;
+	}
+
+	/* Allocate node local memory for AP pdas */
+	if (cpu_pda(cpu) == &boot_cpu_pda[cpu]) {
+		struct x8664_pda *newpda, *pda;
+		int node = cpu_to_node(cpu);
+		pda = cpu_pda(cpu);
+		newpda = kmalloc_node(sizeof (struct x8664_pda), GFP_ATOMIC,
+				      node);
+		if (newpda) {
+			memcpy(newpda, pda, sizeof (struct x8664_pda));
+			cpu_pda(cpu) = newpda;
+		} else
+			printk(KERN_ERR
+		"Could not allocate node local PDA for CPU %d on node %d\n",
+				cpu, node);
+	}
+
+
 	c_idle.idle = get_idle_for_cpu(cpu);
 
 	if (c_idle.idle) {
 		c_idle.idle->thread.rsp = (unsigned long) (((struct pt_regs *)
-			(THREAD_SIZE + (unsigned long) c_idle.idle->thread_info)) - 1);
+			(THREAD_SIZE +  task_stack_page(c_idle.idle))) - 1);
 		init_idle(c_idle.idle, cpu);
 		goto do_rest;
 	}
@@ -778,14 +807,14 @@
 
 do_rest:
 
-	cpu_pda[cpu].pcurrent = c_idle.idle;
+	cpu_pda(cpu)->pcurrent = c_idle.idle;
 
 	start_rip = setup_trampoline();
 
 	init_rsp = c_idle.idle->thread.rsp;
 	per_cpu(init_tss,cpu).rsp0 = init_rsp;
 	initial_code = start_secondary;
-	clear_ti_thread_flag(c_idle.idle->thread_info, TIF_FORK);
+	clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
 
 	printk(KERN_INFO "Booting processor %d/%d APIC 0x%x\n", cpu,
 		cpus_weight(cpu_present_map),
@@ -811,11 +840,8 @@
 	/*
 	 * Be paranoid about clearing APIC errors.
 	 */
-	if (APIC_INTEGRATED(apic_version[apicid])) {
-		apic_read_around(APIC_SPIV);
-		apic_write(APIC_ESR, 0);
-		apic_read(APIC_ESR);
-	}
+	apic_write(APIC_ESR, 0);
+	apic_read(APIC_ESR);
 
 	/*
 	 * Status is now clean
@@ -927,8 +953,8 @@
  *
  * Three ways to find out the number of additional hotplug CPUs:
  * - If the BIOS specified disabled CPUs in ACPI/mptables use that.
- * - otherwise use half of the available CPUs or 2, whatever is more.
  * - The user can overwrite it with additional_cpus=NUM
+ * - Otherwise don't reserve additional CPUs.
  * We do this because additional CPUs waste a lot of memory.
  * -AK
  */
@@ -938,13 +964,10 @@
 	int possible;
 
  	if (additional_cpus == -1) {
- 		if (disabled_cpus > 0) {
+ 		if (disabled_cpus > 0)
  			additional_cpus = disabled_cpus;
- 		} else {
- 			additional_cpus = num_processors / 2;
- 			if (additional_cpus == 0)
- 				additional_cpus = 2;
- 		}
+ 		else
+			additional_cpus = 0;
  	}
 	possible = num_processors + additional_cpus;
 	if (possible > NR_CPUS) 
@@ -996,7 +1019,7 @@
 	/*
 	 * If we couldn't find a local APIC, then get out of here now!
 	 */
-	if (APIC_INTEGRATED(apic_version[boot_cpu_id]) && !cpu_has_apic) {
+	if (!cpu_has_apic) {
 		printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n",
 			boot_cpu_id);
 		printk(KERN_ERR "... forcing use of dummy APIC emulation. (tell your hw vendor)\n");
diff --git a/arch/x86_64/kernel/suspend.c b/arch/x86_64/kernel/suspend.c
index fd2bef7..ecbd34c 100644
--- a/arch/x86_64/kernel/suspend.c
+++ b/arch/x86_64/kernel/suspend.c
@@ -120,7 +120,7 @@
 
 	set_tss_desc(cpu,t);	/* This just modifies memory; should not be neccessary. But... This is neccessary, because 386 hardware has concept of busy TSS or some similar stupidity. */
 
-	cpu_gdt_table[cpu][GDT_ENTRY_TSS].type = 9;
+	cpu_gdt(cpu)[GDT_ENTRY_TSS].type = 9;
 
 	syscall_init();                         /* This sets MSR_*STAR and related */
 	load_TR_desc();				/* This does ltr */
diff --git a/arch/x86_64/kernel/time.c b/arch/x86_64/kernel/time.c
index 43c9fa0..f8c47c6 100644
--- a/arch/x86_64/kernel/time.c
+++ b/arch/x86_64/kernel/time.c
@@ -71,14 +71,6 @@
 struct timespec __xtime __section_xtime;
 struct timezone __sys_tz __section_sys_tz;
 
-static inline void rdtscll_sync(unsigned long *tsc)
-{
-#ifdef CONFIG_SMP
-	sync_core();
-#endif
-	rdtscll(*tsc);
-}
-
 /*
  * do_gettimeoffset() returns microseconds since last timer interrupt was
  * triggered by hardware. A memory read of HPET is slower than a register read
@@ -93,7 +85,7 @@
 {
 	unsigned long t;
 	unsigned long x;
-	rdtscll_sync(&t);
+	t = get_cycles_sync();
 	if (t < vxtime.last_tsc) t = vxtime.last_tsc; /* hack */
 	x = ((t - vxtime.last_tsc) * vxtime.tsc_quot) >> 32;
 	return x;
@@ -259,8 +251,8 @@
 #endif
 
 	{
-			BIN_TO_BCD(real_seconds);
-			BIN_TO_BCD(real_minutes);
+		BIN_TO_BCD(real_seconds);
+		BIN_TO_BCD(real_minutes);
 		CMOS_WRITE(real_seconds, RTC_SECONDS);
 		CMOS_WRITE(real_minutes, RTC_MINUTES);
 	}
@@ -297,25 +289,21 @@
 			last_offset = vxtime.last;
 			base = monotonic_base;
 			this_offset = hpet_readl(HPET_COUNTER);
-
 		} while (read_seqretry(&xtime_lock, seq));
 		offset = (this_offset - last_offset);
 		offset *=(NSEC_PER_SEC/HZ)/hpet_tick;
 		return base + offset;
-	}else{
+	} else {
 		do {
 			seq = read_seqbegin(&xtime_lock);
 
 			last_offset = vxtime.last_tsc;
 			base = monotonic_base;
 		} while (read_seqretry(&xtime_lock, seq));
-		sync_core();
-		rdtscll(this_offset);
+		this_offset = get_cycles_sync();
 		offset = (this_offset - last_offset)*1000/cpu_khz; 
 		return base + offset;
 	}
-
-
 }
 EXPORT_SYMBOL(monotonic_clock);
 
@@ -391,7 +379,7 @@
 		delay = LATCH - 1 - delay;
 	}
 
-	rdtscll_sync(&tsc);
+	tsc = get_cycles_sync();
 
 	if (vxtime.mode == VXTIME_HPET) {
 		if (offset - vxtime.last > hpet_tick) {
@@ -471,6 +459,11 @@
  
 	write_sequnlock(&xtime_lock);
 
+#ifdef CONFIG_X86_LOCAL_APIC
+	if (using_apic_timer)
+		smp_send_timer_broadcast_ipi();
+#endif
+
 	return IRQ_HANDLED;
 }
 
@@ -509,10 +502,10 @@
 	return cycles_2_ns(a);
 }
 
-unsigned long get_cmos_time(void)
+static unsigned long get_cmos_time(void)
 {
-	unsigned int timeout, year, mon, day, hour, min, sec;
-	unsigned char last, this;
+	unsigned int timeout = 1000000, year, mon, day, hour, min, sec;
+	unsigned char uip = 0, this = 0;
 	unsigned long flags;
 
 /*
@@ -525,45 +518,41 @@
 
 	spin_lock_irqsave(&rtc_lock, flags);
 
-	timeout = 1000000;
-	last = this = 0;
-
-	while (timeout && last && !this) {
-		last = this;
+	while (timeout && (!uip || this)) {
+		uip |= this;
 		this = CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP;
 		timeout--;
 	}
 
-/*
- * Here we are safe to assume the registers won't change for a whole second, so
- * we just go ahead and read them.
-	 */
-
-		sec = CMOS_READ(RTC_SECONDS);
-		min = CMOS_READ(RTC_MINUTES);
-		hour = CMOS_READ(RTC_HOURS);
-		day = CMOS_READ(RTC_DAY_OF_MONTH);
-		mon = CMOS_READ(RTC_MONTH);
-		year = CMOS_READ(RTC_YEAR);
+	/*
+	 * Here we are safe to assume the registers won't change for a whole
+	 * second, so we just go ahead and read them.
+ 	 */
+	sec = CMOS_READ(RTC_SECONDS);
+	min = CMOS_READ(RTC_MINUTES);
+	hour = CMOS_READ(RTC_HOURS);
+	day = CMOS_READ(RTC_DAY_OF_MONTH);
+	mon = CMOS_READ(RTC_MONTH);
+	year = CMOS_READ(RTC_YEAR);
 
 	spin_unlock_irqrestore(&rtc_lock, flags);
 
-/*
- * We know that x86-64 always uses BCD format, no need to check the config
- * register.
- */
+	/*
+	 * We know that x86-64 always uses BCD format, no need to check the
+	 * config register.
+ 	*/
 
-	    BCD_TO_BIN(sec);
-	    BCD_TO_BIN(min);
-	    BCD_TO_BIN(hour);
-	    BCD_TO_BIN(day);
-	    BCD_TO_BIN(mon);
-	    BCD_TO_BIN(year);
+	BCD_TO_BIN(sec);
+	BCD_TO_BIN(min);
+	BCD_TO_BIN(hour);
+	BCD_TO_BIN(day);
+	BCD_TO_BIN(mon);
+	BCD_TO_BIN(year);
 
-/*
- * x86-64 systems only exists since 2002.
- * This will work up to Dec 31, 2100
- */
+	/*
+	 * x86-64 systems only exists since 2002.
+	 * This will work up to Dec 31, 2100
+	 */
 	year += 2000;
 
 	return mktime(year, mon, day, hour, min, sec);
@@ -695,8 +684,7 @@
 	do {
 		local_irq_disable();
 		hpet_now = hpet_readl(HPET_COUNTER);
-		sync_core();
-		rdtscl(tsc_now);
+		tsc_now = get_cycles_sync();
 		local_irq_restore(flags);
 	} while ((tsc_now - tsc_start) < TICK_COUNT &&
 		 (hpet_now - hpet_start) < TICK_COUNT);
@@ -726,11 +714,9 @@
 	outb(0xb0, 0x43);
 	outb((PIT_TICK_RATE / (1000 / 50)) & 0xff, 0x42);
 	outb((PIT_TICK_RATE / (1000 / 50)) >> 8, 0x42);
-	rdtscll(start);
-	sync_core();
+	start = get_cycles_sync();
 	while ((inb(0x61) & 0x20) == 0);
-	sync_core();
-	rdtscll(end);
+	end = get_cycles_sync();
 
 	spin_unlock_irqrestore(&i8253_lock, flags);
 	
@@ -744,7 +730,7 @@
 	unsigned int 		ntimer;
 
 	if (!vxtime.hpet_address)
-          return -1;
+        	return -1;
 
 	memset(&hd, 0, sizeof (hd));
 
@@ -878,8 +864,6 @@
 	timer_interrupt, SA_INTERRUPT, CPU_MASK_NONE, "timer", NULL, NULL
 };
 
-extern void __init config_acpi_tables(void);
-
 void __init time_init(void)
 {
 	char *timename;
@@ -934,7 +918,7 @@
 	vxtime.mode = VXTIME_TSC;
 	vxtime.quot = (1000000L << 32) / vxtime_hz;
 	vxtime.tsc_quot = (1000L << 32) / cpu_khz;
-	rdtscll_sync(&vxtime.last_tsc);
+	vxtime.last_tsc = get_cycles_sync();
 	setup_irq(0, &irq0);
 
 	set_cyc2ns_scale(cpu_khz);
@@ -948,7 +932,7 @@
  * Make an educated guess if the TSC is trustworthy and synchronized
  * over all CPUs.
  */
-static __init int unsynchronized_tsc(void)
+__init int unsynchronized_tsc(void)
 {
 #ifdef CONFIG_SMP
 	if (oem_force_hpet_timer())
@@ -959,7 +943,7 @@
  		return 0;
 #endif
  	/* Assume multi socket systems are not synchronized */
- 	return num_online_cpus() > 1;
+ 	return num_present_cpus() > 1;
 }
 
 /*
@@ -999,6 +983,10 @@
 static long clock_cmos_diff;
 static unsigned long sleep_start;
 
+/*
+ * sysfs support for the timer.
+ */
+
 static int timer_suspend(struct sys_device *dev, pm_message_t state)
 {
 	/*
@@ -1041,7 +1029,6 @@
 	set_kset_name("timer"),
 };
 
-
 /* XXX this driverfs stuff should probably go elsewhere later -john */
 static struct sys_device device_timer = {
 	.id	= 0,
@@ -1283,8 +1270,6 @@
 }
 #endif
 
-
-
 static int __init nohpet_setup(char *s) 
 { 
 	nohpet = 1;
@@ -1301,5 +1286,3 @@
 }
 
 __setup("notsc", notsc_setup);
-
-
diff --git a/arch/x86_64/kernel/trampoline.S b/arch/x86_64/kernel/trampoline.S
index 6d9c9a8..23a03eb9 100644
--- a/arch/x86_64/kernel/trampoline.S
+++ b/arch/x86_64/kernel/trampoline.S
@@ -42,8 +42,15 @@
 	movl	$0xA5A5A5A5, trampoline_data - r_base
 				# write marker for master knows we're running
 
-	lidt	idt_48 - r_base	# load idt with 0, 0
-	lgdt	gdt_48 - r_base	# load gdt with whatever is appropriate
+	/*
+	 * GDT tables in non default location kernel can be beyond 16MB and
+	 * lgdt will not be able to load the address as in real mode default
+	 * operand size is 16bit. Use lgdtl instead to force operand size
+	 * to 32 bit.
+	 */
+
+	lidtl	idt_48 - r_base	# load idt with 0, 0
+	lgdtl	gdt_48 - r_base	# load gdt with whatever is appropriate
 
 	xor	%ax, %ax
 	inc	%ax		# protected mode (PE) bit
diff --git a/arch/x86_64/kernel/traps.c b/arch/x86_64/kernel/traps.c
index bf337f4..8bb0aed 100644
--- a/arch/x86_64/kernel/traps.c
+++ b/arch/x86_64/kernel/traps.c
@@ -70,7 +70,6 @@
 asmlinkage void alignment_check(void);
 asmlinkage void machine_check(void);
 asmlinkage void spurious_interrupt_bug(void);
-asmlinkage void call_debug(void);
 
 struct notifier_block *die_chain;
 static DEFINE_SPINLOCK(die_notifier_lock);
@@ -121,19 +120,31 @@
 static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack,
 					unsigned *usedp, const char **idp)
 {
-	static const char ids[N_EXCEPTION_STACKS][8] = {
+	static char ids[][8] = {
 		[DEBUG_STACK - 1] = "#DB",
 		[NMI_STACK - 1] = "NMI",
 		[DOUBLEFAULT_STACK - 1] = "#DF",
 		[STACKFAULT_STACK - 1] = "#SS",
 		[MCE_STACK - 1] = "#MC",
+#if DEBUG_STKSZ > EXCEPTION_STKSZ
+		[N_EXCEPTION_STACKS ... N_EXCEPTION_STACKS + DEBUG_STKSZ / EXCEPTION_STKSZ - 2] = "#DB[?]"
+#endif
 	};
 	unsigned k;
 
 	for (k = 0; k < N_EXCEPTION_STACKS; k++) {
 		unsigned long end;
 
-		end = per_cpu(init_tss, cpu).ist[k];
+		switch (k + 1) {
+#if DEBUG_STKSZ > EXCEPTION_STKSZ
+		case DEBUG_STACK:
+			end = cpu_pda(cpu)->debugstack + DEBUG_STKSZ;
+			break;
+#endif
+		default:
+			end = per_cpu(init_tss, cpu).ist[k];
+			break;
+		}
 		if (stack >= end)
 			continue;
 		if (stack >= end - EXCEPTION_STKSZ) {
@@ -143,6 +154,22 @@
 			*idp = ids[k];
 			return (unsigned long *)end;
 		}
+#if DEBUG_STKSZ > EXCEPTION_STKSZ
+		if (k == DEBUG_STACK - 1 && stack >= end - DEBUG_STKSZ) {
+			unsigned j = N_EXCEPTION_STACKS - 1;
+
+			do {
+				++j;
+				end -= EXCEPTION_STKSZ;
+				ids[j][4] = '1' + (j - N_EXCEPTION_STACKS);
+			} while (stack < end - EXCEPTION_STKSZ);
+			if (*usedp & (1U << j))
+				break;
+			*usedp |= 1U << j;
+			*idp = ids[j];
+			return (unsigned long *)end;
+		}
+#endif
 	}
 	return NULL;
 }
@@ -156,9 +183,8 @@
 
 void show_trace(unsigned long *stack)
 {
-	unsigned long addr;
 	const unsigned cpu = safe_smp_processor_id();
-	unsigned long *irqstack_end = (unsigned long *)cpu_pda[cpu].irqstackptr;
+	unsigned long *irqstack_end = (unsigned long *)cpu_pda(cpu)->irqstackptr;
 	int i;
 	unsigned used = 0;
 
@@ -166,8 +192,14 @@
 
 #define HANDLE_STACK(cond) \
 	do while (cond) { \
-		addr = *stack++; \
+		unsigned long addr = *stack++; \
 		if (kernel_text_address(addr)) { \
+			if (i > 50) { \
+				printk("\n       "); \
+				i = 0; \
+			} \
+			else \
+				i += printk(" "); \
 			/* \
 			 * If the address is either in the text segment of the \
 			 * kernel, or in the region which contains vmalloc'ed \
@@ -177,25 +209,19 @@
 			 * out the call path that was taken. \
 			 */ \
 			i += printk_address(addr); \
-			if (i > 50) { \
-				printk("\n       "); \
-				i = 0; \
-			} \
-			else \
-				i += printk(" "); \
 		} \
 	} while (0)
 
-	for(i = 0; ; ) {
+	for(i = 11; ; ) {
 		const char *id;
 		unsigned long *estack_end;
 		estack_end = in_exception_stack(cpu, (unsigned long)stack,
 						&used, &id);
 
 		if (estack_end) {
-			i += printk(" <%s> ", id);
+			i += printk(" <%s>", id);
 			HANDLE_STACK (stack < estack_end);
-			i += printk(" <EOE> ");
+			i += printk(" <EOE>");
 			stack = (unsigned long *) estack_end[-2];
 			continue;
 		}
@@ -205,11 +231,11 @@
 				(IRQSTACKSIZE - 64) / sizeof(*irqstack);
 
 			if (stack >= irqstack && stack < irqstack_end) {
-				i += printk(" <IRQ> ");
+				i += printk(" <IRQ>");
 				HANDLE_STACK (stack < irqstack_end);
 				stack = (unsigned long *) (irqstack_end[-1]);
 				irqstack_end = NULL;
-				i += printk(" <EOI> ");
+				i += printk(" <EOI>");
 				continue;
 			}
 		}
@@ -226,8 +252,8 @@
 	unsigned long *stack;
 	int i;
 	const int cpu = safe_smp_processor_id();
-	unsigned long *irqstack_end = (unsigned long *) (cpu_pda[cpu].irqstackptr);
-	unsigned long *irqstack = (unsigned long *) (cpu_pda[cpu].irqstackptr - IRQSTACKSIZE);    
+	unsigned long *irqstack_end = (unsigned long *) (cpu_pda(cpu)->irqstackptr);
+	unsigned long *irqstack = (unsigned long *) (cpu_pda(cpu)->irqstackptr - IRQSTACKSIZE);
 
 	// debugging aid: "show_stack(NULL, NULL);" prints the
 	// back trace for this cpu.
@@ -275,14 +301,14 @@
 	int in_kernel = !user_mode(regs);
 	unsigned long rsp;
 	const int cpu = safe_smp_processor_id(); 
-	struct task_struct *cur = cpu_pda[cpu].pcurrent; 
+	struct task_struct *cur = cpu_pda(cpu)->pcurrent;
 
 		rsp = regs->rsp;
 
 	printk("CPU %d ", cpu);
 	__show_regs(regs);
 	printk("Process %s (pid: %d, threadinfo %p, task %p)\n",
-		cur->comm, cur->pid, cur->thread_info, cur);
+		cur->comm, cur->pid, task_thread_info(cur), cur);
 
 	/*
 	 * When in-kernel, we also print out the stack and code at the
@@ -314,20 +340,26 @@
 void handle_BUG(struct pt_regs *regs)
 { 
 	struct bug_frame f;
-	char tmp;
+	long len;
+	const char *prefix = "";
 
 	if (user_mode(regs))
 		return; 
-	if (__copy_from_user(&f, (struct bug_frame *) regs->rip, 
+	if (__copy_from_user(&f, (const void __user *) regs->rip,
 			     sizeof(struct bug_frame)))
 		return; 
 	if (f.filename >= 0 ||
 	    f.ud2[0] != 0x0f || f.ud2[1] != 0x0b) 
 		return;
-	if (__get_user(tmp, (char *)(long)f.filename))
+	len = __strnlen_user((char *)(long)f.filename, PATH_MAX) - 1;
+	if (len < 0 || len >= PATH_MAX)
 		f.filename = (int)(long)"unmapped filename";
+	else if (len > 50) {
+		f.filename += len - 50;
+		prefix = "...";
+	}
 	printk("----------- [cut here ] --------- [please bite here ] ---------\n");
-	printk(KERN_ALERT "Kernel BUG at %.50s:%d\n", (char *)(long)f.filename, f.line);
+	printk(KERN_ALERT "Kernel BUG at %s%.50s:%d\n", prefix, (char *)(long)f.filename, f.line);
 } 
 
 #ifdef CONFIG_BUG
@@ -382,7 +414,7 @@
 	printk("DEBUG_PAGEALLOC");
 #endif
 	printk("\n");
-	notify_die(DIE_OOPS, (char *)str, regs, err, 255, SIGSEGV);
+	notify_die(DIE_OOPS, str, regs, err, current->thread.trap_no, SIGSEGV);
 	show_registers(regs);
 	/* Executive summary in case the oops scrolled away */
 	printk(KERN_ALERT "RIP ");
@@ -399,11 +431,6 @@
 	oops_end(flags);
 	do_exit(SIGSEGV); 
 }
-static inline void die_if_kernel(const char * str, struct pt_regs * regs, long err)
-{
-	if (!(regs->eflags & VM_MASK) && (regs->cs == __KERNEL_CS))
-		die(str, regs, err);
-}
 
 void die_nmi(char *str, struct pt_regs *regs)
 {
@@ -426,19 +453,20 @@
 			      struct pt_regs * regs, long error_code,
 			      siginfo_t *info)
 {
+	struct task_struct *tsk = current;
+
 	conditional_sti(regs);
 
-	if (user_mode(regs)) {
-		struct task_struct *tsk = current;
+	tsk->thread.error_code = error_code;
+	tsk->thread.trap_no = trapnr;
 
+	if (user_mode(regs)) {
 		if (exception_trace && unhandled_signal(tsk, signr))
 			printk(KERN_INFO
 			       "%s[%d] trap %s rip:%lx rsp:%lx error:%lx\n",
 			       tsk->comm, tsk->pid, str,
 			       regs->rip,regs->rsp,error_code); 
 
-		tsk->thread.error_code = error_code;
-		tsk->thread.trap_no = trapnr;
 		if (info)
 			force_sig_info(signr, info, tsk);
 		else
@@ -485,7 +513,7 @@
 DO_ERROR_INFO( 0, SIGFPE,  "divide error", divide_error, FPE_INTDIV, regs->rip)
 DO_ERROR( 4, SIGSEGV, "overflow", overflow)
 DO_ERROR( 5, SIGSEGV, "bounds", bounds)
-DO_ERROR_INFO( 6, SIGILL,  "invalid operand", invalid_op, ILL_ILLOPN, regs->rip)
+DO_ERROR_INFO( 6, SIGILL,  "invalid opcode", invalid_op, ILL_ILLOPN, regs->rip)
 DO_ERROR( 7, SIGSEGV, "device not available", device_not_available)
 DO_ERROR( 9, SIGFPE,  "coprocessor segment overrun", coprocessor_segment_overrun)
 DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS)
@@ -493,24 +521,41 @@
 DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0)
 DO_ERROR(18, SIGSEGV, "reserved", reserved)
 DO_ERROR(12, SIGBUS,  "stack segment", stack_segment)
-DO_ERROR( 8, SIGSEGV, "double fault", double_fault)
+
+asmlinkage void do_double_fault(struct pt_regs * regs, long error_code)
+{
+	static const char str[] = "double fault";
+	struct task_struct *tsk = current;
+
+	/* Return not checked because double check cannot be ignored */
+	notify_die(DIE_TRAP, str, regs, error_code, 8, SIGSEGV);
+
+	tsk->thread.error_code = error_code;
+	tsk->thread.trap_no = 8;
+
+	/* This is always a kernel trap and never fixable (and thus must
+	   never return). */
+	for (;;)
+		die(str, regs, error_code);
+}
 
 asmlinkage void __kprobes do_general_protection(struct pt_regs * regs,
 						long error_code)
 {
+	struct task_struct *tsk = current;
+
 	conditional_sti(regs);
 
-	if (user_mode(regs)) {
-		struct task_struct *tsk = current;
+	tsk->thread.error_code = error_code;
+	tsk->thread.trap_no = 13;
 
+	if (user_mode(regs)) {
 		if (exception_trace && unhandled_signal(tsk, SIGSEGV))
 			printk(KERN_INFO
 		       "%s[%d] general protection rip:%lx rsp:%lx error:%lx\n",
 			       tsk->comm, tsk->pid,
 			       regs->rip,regs->rsp,error_code); 
 
-		tsk->thread.error_code = error_code;
-		tsk->thread.trap_no = 13;
 		force_sig(SIGSEGV, tsk);
 		return;
 	} 
@@ -573,7 +618,7 @@
 		reason = get_nmi_reason();
 
 	if (!(reason & 0xc0)) {
-		if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 0, SIGINT)
+		if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 2, SIGINT)
 								== NOTIFY_STOP)
 			return;
 #ifdef CONFIG_X86_LOCAL_APIC
@@ -589,7 +634,7 @@
 		unknown_nmi_error(reason, regs);
 		return;
 	}
-	if (notify_die(DIE_NMI, "nmi", regs, reason, 0, SIGINT) == NOTIFY_STOP)
+	if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP)
 		return; 
 
 	/* AK: following checks seem to be broken on modern chipsets. FIXME */
@@ -600,6 +645,7 @@
 		io_check_error(reason, regs);
 }
 
+/* runs on IST stack. */
 asmlinkage void __kprobes do_int3(struct pt_regs * regs, long error_code)
 {
 	if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP) == NOTIFY_STOP) {
@@ -620,7 +666,7 @@
 		;
 	/* Exception from user space */
 	else if (user_mode(eregs))
-		regs = ((struct pt_regs *)current->thread.rsp0) - 1;
+		regs = task_pt_regs(current);
 	/* Exception from kernel and interrupts are enabled. Move to
  	   kernel process stack. */
 	else if (eregs->eflags & X86_EFLAGS_IF)
@@ -684,11 +730,9 @@
 	info.si_signo = SIGTRAP;
 	info.si_errno = 0;
 	info.si_code = TRAP_BRKPT;
-	if (!user_mode(regs))
-		goto clear_dr7; 
+	info.si_addr = user_mode(regs) ? (void __user *)regs->rip : NULL;
+	force_sig_info(SIGTRAP, &info, tsk);
 
-	info.si_addr = (void __user *)regs->rip;
-	force_sig_info(SIGTRAP, &info, tsk);	
 clear_dr7:
 	set_debugreg(0UL, 7);
 	return;
@@ -698,7 +742,7 @@
 	regs->eflags &= ~TF_MASK;
 }
 
-static int kernel_math_error(struct pt_regs *regs, char *str)
+static int kernel_math_error(struct pt_regs *regs, const char *str, int trapnr)
 {
 	const struct exception_table_entry *fixup;
 	fixup = search_exception_tables(regs->rip);
@@ -706,8 +750,9 @@
 		regs->rip = fixup->fixup;
 		return 1;
 	}
-	notify_die(DIE_GPF, str, regs, 0, 16, SIGFPE);
+	notify_die(DIE_GPF, str, regs, 0, trapnr, SIGFPE);
 	/* Illegal floating point operation in the kernel */
+	current->thread.trap_no = trapnr;
 	die(str, regs, 0);
 	return 0;
 }
@@ -726,7 +771,7 @@
 
 	conditional_sti(regs);
 	if (!user_mode(regs) &&
-	    kernel_math_error(regs, "kernel x87 math error"))
+	    kernel_math_error(regs, "kernel x87 math error", 16))
 		return;
 
 	/*
@@ -795,7 +840,7 @@
 
 	conditional_sti(regs);
 	if (!user_mode(regs) &&
-        	kernel_math_error(regs, "kernel simd math error"))
+        	kernel_math_error(regs, "kernel simd math error", 19))
 		return;
 
 	/*
@@ -867,12 +912,7 @@
 	if (!used_math())
 		init_fpu(me);
 	restore_fpu_checking(&me->thread.i387.fxsave);
-	me->thread_info->status |= TS_USEDFPU;
-}
-
-void do_call_debug(struct pt_regs *regs) 
-{ 
-	notify_die(DIE_CALL, "debug call", regs, 0, 255, SIGINT); 
+	task_thread_info(me)->status |= TS_USEDFPU;
 }
 
 void __init trap_init(void)
@@ -880,9 +920,9 @@
 	set_intr_gate(0,&divide_error);
 	set_intr_gate_ist(1,&debug,DEBUG_STACK);
 	set_intr_gate_ist(2,&nmi,NMI_STACK);
-	set_system_gate(3,&int3);
-	set_system_gate(4,&overflow);	/* int4-5 can be called from all */
-	set_system_gate(5,&bounds);
+ 	set_system_gate_ist(3,&int3,DEBUG_STACK); /* int3 can be called from all */
+	set_system_gate(4,&overflow);	/* int4 can be called from all */
+	set_intr_gate(5,&bounds);
 	set_intr_gate(6,&invalid_op);
 	set_intr_gate(7,&device_not_available);
 	set_intr_gate_ist(8,&double_fault, DOUBLEFAULT_STACK);
@@ -904,8 +944,6 @@
 	set_system_gate(IA32_SYSCALL_VECTOR, ia32_syscall);
 #endif
        
-	set_intr_gate(KDB_VECTOR, call_debug);
-       
 	/*
 	 * Should be a barrier for any external CPU state.
 	 */
diff --git a/arch/x86_64/kernel/vmlinux.lds.S b/arch/x86_64/kernel/vmlinux.lds.S
index 58b1921..b0eed1f 100644
--- a/arch/x86_64/kernel/vmlinux.lds.S
+++ b/arch/x86_64/kernel/vmlinux.lds.S
@@ -8,6 +8,8 @@
 #include <asm/page.h>
 #include <linux/config.h>
 
+#undef i386	/* in case the preprocessor is a 32bit one */
+
 OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64")
 OUTPUT_ARCH(i386:x86-64)
 ENTRY(phys_startup_64)
@@ -189,7 +191,7 @@
   /* Sections to be discarded */
   /DISCARD/ : {
 	*(.exitcall.exit)
-#ifndef CONFIG_DEBUG_INFO
+#ifndef CONFIG_UNWIND_INFO
 	*(.eh_frame)
 #endif
 	}
diff --git a/arch/x86_64/kernel/vsmp.c b/arch/x86_64/kernel/vsmp.c
new file mode 100644
index 0000000..92f70c7
--- /dev/null
+++ b/arch/x86_64/kernel/vsmp.c
@@ -0,0 +1,45 @@
+/*
+ * vSMPowered(tm) systems specific initialization
+ * Copyright (C) 2005 ScaleMP Inc.
+ *
+ * Use of this code is subject to the terms and conditions of the
+ * GNU general public license version 2. See "COPYING" or
+ * http://www.gnu.org/licenses/gpl.html
+ *
+ * Ravikiran Thirumalai <kiran@scalemp.com>,
+ * Shai Fultheim <shai@scalemp.com>
+ */
+
+#include <linux/init.h>
+#include <linux/pci_ids.h>
+#include <linux/pci_regs.h>
+#include <asm/pci-direct.h>
+
+static int __init vsmp_init(void)
+{
+	void *address;
+	unsigned int cap, ctl;
+
+	/* Check if we are running on a ScaleMP vSMP box */
+	if ((read_pci_config_16(0, 0x1f, 0, PCI_VENDOR_ID) != PCI_VENDOR_ID_SCALEMP) ||
+	    (read_pci_config_16(0, 0x1f, 0, PCI_DEVICE_ID) != PCI_DEVICE_ID_SCALEMP_VSMP_CTL))
+		return 0;
+
+	/* set vSMP magic bits to indicate vSMP capable kernel */
+	address = ioremap(read_pci_config(0, 0x1f, 0, PCI_BASE_ADDRESS_0), 8);
+	cap = readl(address);
+	ctl = readl(address + 4);
+	printk("vSMP CTL: capabilities:0x%08x  control:0x%08x\n", cap, ctl);
+	if (cap & ctl & (1 << 4)) {
+		/* Turn on vSMP IRQ fastpath handling (see system.h) */
+		ctl &= ~(1 << 4);
+		writel(ctl, address + 4);
+		ctl = readl(address + 4);
+		printk("vSMP CTL: control set to:0x%08x\n", ctl);
+	}
+
+	iounmap(address);
+	return 0;
+}
+
+core_initcall(vsmp_init);
diff --git a/arch/x86_64/kernel/vsyscall.c b/arch/x86_64/kernel/vsyscall.c
index 70a0bd1..9468fb2 100644
--- a/arch/x86_64/kernel/vsyscall.c
+++ b/arch/x86_64/kernel/vsyscall.c
@@ -35,14 +35,13 @@
 #include <asm/io.h>
 
 #define __vsyscall(nr) __attribute__ ((unused,__section__(".vsyscall_" #nr)))
-#define force_inline __attribute__((always_inline)) inline
 
 int __sysctl_vsyscall __section_sysctl_vsyscall = 1;
 seqlock_t __xtime_lock __section_xtime_lock = SEQLOCK_UNLOCKED;
 
 #include <asm/unistd.h>
 
-static force_inline void timeval_normalize(struct timeval * tv)
+static __always_inline void timeval_normalize(struct timeval * tv)
 {
 	time_t __sec;
 
@@ -53,7 +52,7 @@
 	}
 }
 
-static force_inline void do_vgettimeofday(struct timeval * tv)
+static __always_inline void do_vgettimeofday(struct timeval * tv)
 {
 	long sequence, t;
 	unsigned long sec, usec;
@@ -66,8 +65,7 @@
 			(__jiffies - __wall_jiffies) * (1000000 / HZ);
 
 		if (__vxtime.mode != VXTIME_HPET) {
-			sync_core();
-			rdtscll(t);
+			t = get_cycles_sync();
 			if (t < __vxtime.last_tsc)
 				t = __vxtime.last_tsc;
 			usec += ((t - __vxtime.last_tsc) *
@@ -84,12 +82,12 @@
 }
 
 /* RED-PEN may want to readd seq locking, but then the variable should be write-once. */
-static force_inline void do_get_tz(struct timezone * tz)
+static __always_inline void do_get_tz(struct timezone * tz)
 {
 	*tz = __sys_tz;
 }
 
-static force_inline int gettimeofday(struct timeval *tv, struct timezone *tz)
+static __always_inline int gettimeofday(struct timeval *tv, struct timezone *tz)
 {
 	int ret;
 	asm volatile("vsysc2: syscall"
@@ -98,7 +96,7 @@
 	return ret;
 }
 
-static force_inline long time_syscall(long *t)
+static __always_inline long time_syscall(long *t)
 {
 	long secs;
 	asm volatile("vsysc1: syscall"
diff --git a/arch/x86_64/kernel/x8664_ksyms.c b/arch/x86_64/kernel/x8664_ksyms.c
index 4a54221..b614d54 100644
--- a/arch/x86_64/kernel/x8664_ksyms.c
+++ b/arch/x86_64/kernel/x8664_ksyms.c
@@ -13,7 +13,6 @@
 #include <linux/string.h>
 #include <linux/syscalls.h>
 #include <linux/tty.h>
-#include <linux/ioctl32.h>
 
 #include <asm/semaphore.h>
 #include <asm/processor.h>
@@ -45,22 +44,15 @@
 EXPORT_SYMBOL(drive_info);
 #endif
 
-extern unsigned long get_cmos_time(void);
-
 /* platform dependent support */
 EXPORT_SYMBOL(boot_cpu_data);
 //EXPORT_SYMBOL(dump_fpu);
 EXPORT_SYMBOL(__ioremap);
 EXPORT_SYMBOL(ioremap_nocache);
 EXPORT_SYMBOL(iounmap);
-EXPORT_SYMBOL(enable_irq);
-EXPORT_SYMBOL(disable_irq);
-EXPORT_SYMBOL(disable_irq_nosync);
-EXPORT_SYMBOL(probe_irq_mask);
 EXPORT_SYMBOL(kernel_thread);
 EXPORT_SYMBOL(pm_idle);
 EXPORT_SYMBOL(pm_power_off);
-EXPORT_SYMBOL(get_cmos_time);
 
 EXPORT_SYMBOL(__down_failed);
 EXPORT_SYMBOL(__down_failed_interruptible);
@@ -84,9 +76,6 @@
 EXPORT_SYMBOL(__put_user_4);
 EXPORT_SYMBOL(__put_user_8);
 
-EXPORT_SYMBOL(strpbrk);
-EXPORT_SYMBOL(strstr);
-
 EXPORT_SYMBOL(strncpy_from_user);
 EXPORT_SYMBOL(__strncpy_from_user);
 EXPORT_SYMBOL(clear_user);
@@ -98,25 +87,18 @@
 EXPORT_SYMBOL(strnlen_user);
 
 #ifdef CONFIG_PCI
-EXPORT_SYMBOL(pci_alloc_consistent);
-EXPORT_SYMBOL(pci_free_consistent);
-#endif
-
-#ifdef CONFIG_PCI
 EXPORT_SYMBOL(pci_mem_start);
 #endif
 
 EXPORT_SYMBOL(copy_page);
 EXPORT_SYMBOL(clear_page);
 
-EXPORT_SYMBOL(cpu_pda);
+EXPORT_SYMBOL(_cpu_pda);
 #ifdef CONFIG_SMP
 EXPORT_SYMBOL(cpu_data);
-EXPORT_SYMBOL(cpu_online_map);
 EXPORT_SYMBOL(__write_lock_failed);
 EXPORT_SYMBOL(__read_lock_failed);
 
-EXPORT_SYMBOL(synchronize_irq);
 EXPORT_SYMBOL(smp_call_function);
 EXPORT_SYMBOL(cpu_callout_map);
 #endif
@@ -137,30 +119,17 @@
 #undef memcpy
 #undef memset
 #undef memmove
-#undef memchr
 #undef strlen
-#undef strncmp
-#undef strncpy
-#undef strchr	
 
 extern void * memset(void *,int,__kernel_size_t);
 extern size_t strlen(const char *);
 extern void * memmove(void * dest,const void *src,size_t count);
-extern void *memchr(const void *s, int c, size_t n);
 extern void * memcpy(void *,const void *,__kernel_size_t);
 extern void * __memcpy(void *,const void *,__kernel_size_t);
 
 EXPORT_SYMBOL(memset);
 EXPORT_SYMBOL(strlen);
 EXPORT_SYMBOL(memmove);
-EXPORT_SYMBOL(strncmp);
-EXPORT_SYMBOL(strncpy);
-EXPORT_SYMBOL(strchr);
-EXPORT_SYMBOL(strncat);
-EXPORT_SYMBOL(memchr);
-EXPORT_SYMBOL(strrchr);
-EXPORT_SYMBOL(strnlen);
-EXPORT_SYMBOL(memscan);
 EXPORT_SYMBOL(memcpy);
 EXPORT_SYMBOL(__memcpy);
 
diff --git a/arch/x86_64/lib/copy_user.S b/arch/x86_64/lib/copy_user.S
index dfa358b..79422b6 100644
--- a/arch/x86_64/lib/copy_user.S
+++ b/arch/x86_64/lib/copy_user.S
@@ -4,12 +4,9 @@
  * Functions to copy from and to user space.		
  */		 
 
-#define FIX_ALIGNMENT 1
-		
 	#include <asm/current.h>
 	#include <asm/asm-offsets.h>
 	#include <asm/thread_info.h>
-	#include <asm/cpufeature.h>
 
 /* Standard copy_to_user with segment limit checking */		
 	.globl copy_to_user
@@ -21,23 +18,7 @@
 	jc  bad_to_user
 	cmpq threadinfo_addr_limit(%rax),%rcx
 	jae bad_to_user
-2:	
-	.byte 0xe9	/* 32bit jump */
-	.long .Lcug-1f
-1:
-
-	.section .altinstr_replacement,"ax"
-3:	.byte 0xe9			/* replacement jmp with 8 bit immediate */
-	.long copy_user_generic_c-1b	/* offset */
-	.previous
-	.section .altinstructions,"a"
-	.align 8
-	.quad  2b
-	.quad  3b
-	.byte  X86_FEATURE_K8_C
-	.byte  5
-	.byte  5
-	.previous
+	jmp copy_user_generic
 
 /* Standard copy_from_user with segment limit checking */	
 	.globl copy_from_user
@@ -72,223 +53,44 @@
  * rsi source
  * rdx count
  *
+ * Only 4GB of copy is supported. This shouldn't be a problem
+ * because the kernel normally only writes from/to page sized chunks
+ * even if user space passed a longer buffer.
+ * And more would be dangerous because both Intel and AMD have
+ * errata with rep movsq > 4GB. If someone feels the need to fix
+ * this please consider this.
+ *
  * Output:		
  * eax uncopied bytes or 0 if successful.
  */
-	.globl copy_user_generic	
-	.p2align 4
-copy_user_generic:	
-	.byte 0x66,0x66,0x90	/* 5 byte nop for replacement jump */	
-	.byte 0x66,0x90
-1:		
-	.section .altinstr_replacement,"ax"
-2:	.byte 0xe9	             /* near jump with 32bit immediate */
-	.long copy_user_generic_c-1b /* offset */
-	.previous
-	.section .altinstructions,"a"
-	.align 8
-	.quad  copy_user_generic
-	.quad  2b
-	.byte  X86_FEATURE_K8_C
-	.byte  5
-	.byte  5
-	.previous
-.Lcug:	
-	pushq %rbx
-	xorl %eax,%eax		/*zero for the exception handler */
 
-#ifdef FIX_ALIGNMENT
-	/* check for bad alignment of destination */
-	movl %edi,%ecx
-	andl $7,%ecx
-	jnz  .Lbad_alignment
-.Lafter_bad_alignment:
-#endif
-
-	movq %rdx,%rcx
-
-	movl $64,%ebx	
-	shrq $6,%rdx
-	decq %rdx
-	js   .Lhandle_tail
-	
-	.p2align 4
-.Lloop:
-.Ls1:	movq (%rsi),%r11
-.Ls2:	movq 1*8(%rsi),%r8
-.Ls3:	movq 2*8(%rsi),%r9
-.Ls4:	movq 3*8(%rsi),%r10
-.Ld1:	movq %r11,(%rdi)
-.Ld2:	movq %r8,1*8(%rdi)
-.Ld3:	movq %r9,2*8(%rdi)
-.Ld4:	movq %r10,3*8(%rdi)
-		
-.Ls5:	movq 4*8(%rsi),%r11
-.Ls6:	movq 5*8(%rsi),%r8
-.Ls7:	movq 6*8(%rsi),%r9
-.Ls8:	movq 7*8(%rsi),%r10
-.Ld5:	movq %r11,4*8(%rdi)
-.Ld6:	movq %r8,5*8(%rdi)
-.Ld7:	movq %r9,6*8(%rdi)
-.Ld8:	movq %r10,7*8(%rdi)
-	
-	decq %rdx
-
-	leaq 64(%rsi),%rsi
-	leaq 64(%rdi),%rdi
-	
-	jns  .Lloop
-
-	.p2align 4
-.Lhandle_tail:
-	movl %ecx,%edx
-	andl $63,%ecx
-	shrl $3,%ecx
-	jz   .Lhandle_7
-	movl $8,%ebx
-	.p2align 4
-.Lloop_8:
-.Ls9:	movq (%rsi),%r8
-.Ld9:	movq %r8,(%rdi)
-	decl %ecx
-	leaq 8(%rdi),%rdi
-	leaq 8(%rsi),%rsi
-	jnz .Lloop_8
-	
-.Lhandle_7:		
-	movl %edx,%ecx	
-	andl $7,%ecx
-	jz   .Lende
-	.p2align 4
-.Lloop_1:
-.Ls10:	movb (%rsi),%bl
-.Ld10:	movb %bl,(%rdi)
-	incq %rdi
-	incq %rsi
-	decl %ecx
-	jnz .Lloop_1
-			
-.Lende:
-	popq %rbx
-	ret	
-
-#ifdef FIX_ALIGNMENT		  		
-	/* align destination */
-	.p2align 4
-.Lbad_alignment:
-	movl $8,%r9d
-	subl %ecx,%r9d
-	movl %r9d,%ecx
-	cmpq %r9,%rdx
-	jz   .Lhandle_7
-	js   .Lhandle_7
-.Lalign_1:		
-.Ls11:	movb (%rsi),%bl
-.Ld11:	movb %bl,(%rdi)
-	incq %rsi
-	incq %rdi
-	decl %ecx
-	jnz .Lalign_1
-	subq %r9,%rdx
-	jmp .Lafter_bad_alignment
-#endif
-	
-	/* table sorted by exception address */	
-	.section __ex_table,"a"
-	.align 8
-	.quad .Ls1,.Ls1e
-	.quad .Ls2,.Ls2e
-	.quad .Ls3,.Ls3e
-	.quad .Ls4,.Ls4e	
-	.quad .Ld1,.Ls1e
-	.quad .Ld2,.Ls2e
-	.quad .Ld3,.Ls3e
-	.quad .Ld4,.Ls4e
-	.quad .Ls5,.Ls5e
-	.quad .Ls6,.Ls6e
-	.quad .Ls7,.Ls7e
-	.quad .Ls8,.Ls8e	
-	.quad .Ld5,.Ls5e
-	.quad .Ld6,.Ls6e
-	.quad .Ld7,.Ls7e
-	.quad .Ld8,.Ls8e
-	.quad .Ls9,.Le_quad
-	.quad .Ld9,.Le_quad
-	.quad .Ls10,.Le_byte
-	.quad .Ld10,.Le_byte
-#ifdef FIX_ALIGNMENT	
-	.quad .Ls11,.Lzero_rest
-	.quad .Ld11,.Lzero_rest
-#endif
-	.quad .Le5,.Le_zero
-	.previous
-
-	/* compute 64-offset for main loop. 8 bytes accuracy with error on the 
-	   pessimistic side. this is gross. it would be better to fix the 
-	   interface. */	
-	/* eax: zero, ebx: 64 */
-.Ls1e: 	addl $8,%eax
-.Ls2e: 	addl $8,%eax
-.Ls3e: 	addl $8,%eax
-.Ls4e: 	addl $8,%eax
-.Ls5e: 	addl $8,%eax
-.Ls6e: 	addl $8,%eax
-.Ls7e: 	addl $8,%eax
-.Ls8e: 	addl $8,%eax
-	addq %rbx,%rdi	/* +64 */
-	subq %rax,%rdi  /* correct destination with computed offset */
-
-	shlq $6,%rdx	/* loop counter * 64 (stride length) */
-	addq %rax,%rdx	/* add offset to loopcnt */
-	andl $63,%ecx	/* remaining bytes */
-	addq %rcx,%rdx	/* add them */
-	jmp .Lzero_rest
-
-	/* exception on quad word loop in tail handling */
-	/* ecx:	loopcnt/8, %edx: length, rdi: correct */
-.Le_quad:
-	shll $3,%ecx
-	andl $7,%edx
-	addl %ecx,%edx
-	/* edx: bytes to zero, rdi: dest, eax:zero */
-.Lzero_rest:
-	movq %rdx,%rcx
-.Le_byte:
-	xorl %eax,%eax
-.Le5:	rep 
-	stosb
-	/* when there is another exception while zeroing the rest just return */
-.Le_zero:		
-	movq %rdx,%rax
-	jmp .Lende
-
-	/* C stepping K8 run faster using the string copy instructions.
-	   This is also a lot simpler. Use them when possible.
-	   Patch in jmps to this code instead of copying it fully
-	   to avoid unwanted aliasing in the exception tables. */
-		
- /* rdi	destination
-  * rsi source
-  * rdx count
-  *
-  * Output:		
-  * eax uncopied bytes or 0 if successfull.
-  */			
-copy_user_generic_c:
+	.globl copy_user_generic
+copy_user_generic:
 	movl %edx,%ecx
 	shrl $3,%ecx
 	andl $7,%edx	
+	jz   5f
 1:	rep 
 	movsq 
 	movl %edx,%ecx
+	xor %eax,%eax
 2:	rep
 	movsb
-4:	movl %ecx,%eax
 	ret
+	/* align here? */
+5: 	xorl %eax,%eax
+6:	rep movsq
+	ret
+
+	.section .fixup,"ax"
 3:	lea (%rdx,%rcx,8),%rax
 	ret
-	
+4:	movl %ecx,%eax
+	ret
+	.previous
+
 	.section __ex_table,"a"
 	.quad 1b,3b
 	.quad 2b,4b
+	.quad 6b,4b
 	.previous
diff --git a/arch/x86_64/lib/delay.c b/arch/x86_64/lib/delay.c
index 841bd73..03c460c 100644
--- a/arch/x86_64/lib/delay.c
+++ b/arch/x86_64/lib/delay.c
@@ -39,7 +39,7 @@
 
 inline void __const_udelay(unsigned long xloops)
 {
-	__delay(((xloops * cpu_data[raw_smp_processor_id()].loops_per_jiffy) >> 32) * HZ);
+	__delay((xloops * HZ * cpu_data[raw_smp_processor_id()].loops_per_jiffy) >> 32);
 }
 
 void __udelay(unsigned long usecs)
diff --git a/arch/x86_64/lib/usercopy.c b/arch/x86_64/lib/usercopy.c
index db8abba..9bc2c29 100644
--- a/arch/x86_64/lib/usercopy.c
+++ b/arch/x86_64/lib/usercopy.c
@@ -109,14 +109,11 @@
  * Return 0 on exception, a value greater than N if too long
  */
 
-long strnlen_user(const char __user *s, long n)
+long __strnlen_user(const char __user *s, long n)
 {
 	long res = 0;
 	char c;
 
-	if (!access_ok(VERIFY_READ, s, n))
-		return 0;
-
 	while (1) {
 		if (res>n)
 			return n+1;
@@ -129,6 +126,13 @@
 	}
 }
 
+long strnlen_user(const char __user *s, long n)
+{
+	if (!access_ok(VERIFY_READ, s, n))
+		return 0;
+	return __strnlen_user(s, n);
+}
+
 long strlen_user(const char __user *s)
 {
 	long res = 0;
diff --git a/arch/x86_64/mm/fault.c b/arch/x86_64/mm/fault.c
index 3a63707..26eac19 100644
--- a/arch/x86_64/mm/fault.c
+++ b/arch/x86_64/mm/fault.c
@@ -35,6 +35,13 @@
 #include <asm-generic/sections.h>
 #include <asm/kdebug.h>
 
+/* Page fault error code bits */
+#define PF_PROT	(1<<0)		/* or no page found */
+#define PF_WRITE	(1<<1)
+#define PF_USER	(1<<2)
+#define PF_RSVD	(1<<3)
+#define PF_INSTR	(1<<4)
+
 void bust_spinlocks(int yes)
 {
 	int loglevel_save = console_loglevel;
@@ -68,7 +75,7 @@
 	unsigned char *max_instr;
 
 	/* If it was a exec fault ignore */
-	if (error_code & (1<<4))
+	if (error_code & PF_INSTR)
 		return 0;
 	
 	instr = (unsigned char *)convert_rip_to_linear(current, regs);
@@ -222,17 +229,22 @@
 				 unsigned long error_code)
 {
 	unsigned long flags = oops_begin();
+	struct task_struct *tsk;
 
 	printk(KERN_ALERT "%s: Corrupted page table at address %lx\n",
 	       current->comm, address);
 	dump_pagetable(address);
+	tsk = current;
+	tsk->thread.cr2 = address;
+	tsk->thread.trap_no = 14;
+	tsk->thread.error_code = error_code;
 	__die("Bad pagetable", regs, error_code);
 	oops_end(flags);
 	do_exit(SIGKILL);
 }
 
 /*
- * Handle a fault on the vmalloc or module mapping area
+ * Handle a fault on the vmalloc area
  *
  * This assumes no large pages in there.
  */
@@ -278,7 +290,6 @@
 	   that. */
 	if (!pte_present(*pte) || pte_pfn(*pte) != pte_pfn(*pte_ref))
 		BUG();
-	__flush_tlb_all();
 	return 0;
 }
 
@@ -289,12 +300,6 @@
  * This routine handles page faults.  It determines the address,
  * and the problem, and then passes it off to one of the appropriate
  * routines.
- *
- * error_code:
- *	bit 0 == 0 means no page found, 1 means protection fault
- *	bit 1 == 0 means read, 1 means write
- *	bit 2 == 0 means kernel, 1 means user-mode
- *      bit 3 == 1 means fault was an instruction fetch
  */
 asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,
 					unsigned long error_code)
@@ -337,12 +342,16 @@
 	 *
 	 * This verifies that the fault happens in kernel space
 	 * (error_code & 4) == 0, and that the fault was not a
-	 * protection error (error_code & 1) == 0.
+	 * protection error (error_code & 9) == 0.
 	 */
 	if (unlikely(address >= TASK_SIZE64)) {
-		if (!(error_code & 5) &&
-		      ((address >= VMALLOC_START && address < VMALLOC_END) ||
-		       (address >= MODULES_VADDR && address < MODULES_END))) {
+		/*
+		 * Don't check for the module range here: its PML4
+		 * is always initialized because it's shared with the main
+		 * kernel text. Only vmalloc may need PML4 syncups.
+		 */
+		if (!(error_code & (PF_RSVD|PF_USER|PF_PROT)) &&
+		      ((address >= VMALLOC_START && address < VMALLOC_END))) {
 			if (vmalloc_fault(address) < 0)
 				goto bad_area_nosemaphore;
 			return;
@@ -354,7 +363,7 @@
 		goto bad_area_nosemaphore;
 	}
 
-	if (unlikely(error_code & (1 << 3)))
+	if (unlikely(error_code & PF_RSVD))
 		pgtable_bad(address, regs, error_code);
 
 	/*
@@ -381,7 +390,7 @@
 	 * thus avoiding the deadlock.
 	 */
 	if (!down_read_trylock(&mm->mmap_sem)) {
-		if ((error_code & 4) == 0 &&
+		if ((error_code & PF_USER) == 0 &&
 		    !search_exception_tables(regs->rip))
 			goto bad_area_nosemaphore;
 		down_read(&mm->mmap_sem);
@@ -408,17 +417,17 @@
 good_area:
 	info.si_code = SEGV_ACCERR;
 	write = 0;
-	switch (error_code & 3) {
+	switch (error_code & (PF_PROT|PF_WRITE)) {
 		default:	/* 3: write, present */
 			/* fall through */
-		case 2:		/* write, not present */
+		case PF_WRITE:		/* write, not present */
 			if (!(vma->vm_flags & VM_WRITE))
 				goto bad_area;
 			write++;
 			break;
-		case 1:		/* read, present */
+		case PF_PROT:		/* read, present */
 			goto bad_area;
-		case 0:		/* read, not present */
+		case 0:			/* read, not present */
 			if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
 				goto bad_area;
 	}
@@ -453,7 +462,7 @@
 
 bad_area_nosemaphore:
 	/* User mode accesses just cause a SIGSEGV */
-	if (error_code & 4) {
+	if (error_code & PF_USER) {
 		if (is_prefetch(regs, address, error_code))
 			return;
 
@@ -521,6 +530,9 @@
 	printk_address(regs->rip);
 	printk("\n");
 	dump_pagetable(address);
+	tsk->thread.cr2 = address;
+	tsk->thread.trap_no = 14;
+	tsk->thread.error_code = error_code;
 	__die("Oops", regs, error_code);
 	/* Executive summary in case the body of the oops scrolled away */
 	printk(KERN_EMERG "CR2: %016lx\n", address);
@@ -546,7 +558,7 @@
 	up_read(&mm->mmap_sem);
 
 	/* Kernel mode? Handle exceptions or die */
-	if (!(error_code & 4))
+	if (!(error_code & PF_USER))
 		goto no_context;
 
 	tsk->thread.cr2 = address;
diff --git a/arch/x86_64/mm/init.c b/arch/x86_64/mm/init.c
index 1faae5f..eca6012 100644
--- a/arch/x86_64/mm/init.c
+++ b/arch/x86_64/mm/init.c
@@ -23,6 +23,7 @@
 #include <linux/bootmem.h>
 #include <linux/proc_fs.h>
 #include <linux/pci.h>
+#include <linux/dma-mapping.h>
 
 #include <asm/processor.h>
 #include <asm/system.h>
@@ -38,11 +39,16 @@
 #include <asm/proto.h>
 #include <asm/smp.h>
 #include <asm/sections.h>
+#include <asm/dma-mapping.h>
+#include <asm/swiotlb.h>
 
 #ifndef Dprintk
 #define Dprintk(x...)
 #endif
 
+struct dma_mapping_ops* dma_ops;
+EXPORT_SYMBOL(dma_ops);
+
 static unsigned long dma_reserve __initdata;
 
 DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
@@ -249,14 +255,26 @@
 
 static void __init find_early_table_space(unsigned long end)
 {
-	unsigned long puds, pmds, tables;
+	unsigned long puds, pmds, tables, start;
 
 	puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
 	pmds = (end + PMD_SIZE - 1) >> PMD_SHIFT;
 	tables = round_up(puds * sizeof(pud_t), PAGE_SIZE) +
 		 round_up(pmds * sizeof(pmd_t), PAGE_SIZE);
 
-	table_start = find_e820_area(0x8000, __pa_symbol(&_text), tables);
+	/* Put page tables beyond the DMA zones if possible.
+	   RED-PEN might be better to spread them out more over
+	   memory to avoid hotspots */
+	if (end > MAX_DMA32_PFN<<PAGE_SHIFT)
+		start = MAX_DMA32_PFN << PAGE_SHIFT;
+	else if (end > MAX_DMA_PFN << PAGE_SHIFT)
+		start = MAX_DMA_PFN << PAGE_SHIFT;
+	else
+		start = 0x8000;
+
+	table_start = find_e820_area(start, end, tables);
+	if (table_start == -1)
+		table_start = find_e820_area(0x8000, end, tables);
 	if (table_start == -1UL)
 		panic("Cannot find space for the kernel page tables");
 
@@ -423,12 +441,9 @@
 	long codesize, reservedpages, datasize, initsize;
 
 #ifdef CONFIG_SWIOTLB
-	if (!iommu_aperture &&
-	    (end_pfn >= 0xffffffff>>PAGE_SHIFT || force_iommu))
-	       swiotlb = 1;
-	if (swiotlb)
-		swiotlb_init();	
+	pci_swiotlb_init();
 #endif
+	no_iommu_init();
 
 	/* How many end-of-memory variables you have, grandma! */
 	max_low_pfn = end_pfn;
diff --git a/arch/x86_64/mm/numa.c b/arch/x86_64/mm/numa.c
index 15b67d2..6ef9f9a 100644
--- a/arch/x86_64/mm/numa.c
+++ b/arch/x86_64/mm/numa.c
@@ -46,8 +46,8 @@
  * 0 if memnodmap[] too small (of shift too small)
  * -1 if node overlap or lost ram (shift too big)
  */
-static int __init populate_memnodemap(
-	const struct node *nodes, int numnodes, int shift)
+static int __init
+populate_memnodemap(const struct node *nodes, int numnodes, int shift)
 {
 	int i; 
 	int res = -1;
@@ -81,7 +81,7 @@
 	while (populate_memnodemap(nodes, numnodes, shift + 1) >= 0)
 		shift++;
 
-	printk(KERN_DEBUG "Using %d for the hash shift.\n",
+	printk(KERN_DEBUG "NUMA: Using %d for the hash shift.\n",
 		shift);
 
 	if (populate_memnodemap(nodes, numnodes, shift) != 1) {
@@ -110,7 +110,7 @@
 
 	start = round_up(start, ZONE_ALIGN); 
 
-	printk("Bootmem setup node %d %016lx-%016lx\n", nodeid, start, end);
+	printk(KERN_INFO "Bootmem setup node %d %016lx-%016lx\n", nodeid, start, end);
 
 	start_pfn = start >> PAGE_SHIFT;
 	end_pfn = end >> PAGE_SHIFT;
@@ -156,7 +156,7 @@
  	start_pfn = node_start_pfn(nodeid);
  	end_pfn = node_end_pfn(nodeid);
 
-	Dprintk(KERN_INFO "setting up node %d %lx-%lx\n",
+	Dprintk(KERN_INFO "Setting up node %d %lx-%lx\n",
 		nodeid, start_pfn, end_pfn);
 
 	size_zones(zones, holes, start_pfn, end_pfn);
@@ -200,7 +200,7 @@
  		while ((x << 1) < sz)
  			x <<= 1;
  		if (x < sz/2)
- 			printk("Numa emulation unbalanced. Complain to maintainer\n");
+ 			printk(KERN_ERR "Numa emulation unbalanced. Complain to maintainer\n");
  		sz = x;
  	}
 
@@ -272,7 +272,7 @@
 
 void __cpuinit numa_set_node(int cpu, int node)
 {
-	cpu_pda[cpu].nodenumber = node;
+	cpu_pda(cpu)->nodenumber = node;
 	cpu_to_node[cpu] = node;
 }
 
@@ -330,8 +330,69 @@
 	return 1;
 } 
 
+/*
+ * Setup early cpu_to_node.
+ *
+ * Populate cpu_to_node[] only if x86_cpu_to_apicid[],
+ * and apicid_to_node[] tables have valid entries for a CPU.
+ * This means we skip cpu_to_node[] initialisation for NUMA
+ * emulation and faking node case (when running a kernel compiled
+ * for NUMA on a non NUMA box), which is OK as cpu_to_node[]
+ * is already initialized in a round robin manner at numa_init_array,
+ * prior to this call, and this initialization is good enough
+ * for the fake NUMA cases.
+ */
+void __init init_cpu_to_node(void)
+{
+	int i;
+ 	for (i = 0; i < NR_CPUS; i++) {
+		u8 apicid = x86_cpu_to_apicid[i];
+		if (apicid == BAD_APICID)
+			continue;
+		if (apicid_to_node[apicid] == NUMA_NO_NODE)
+			continue;
+ 		cpu_to_node[i] = apicid_to_node[apicid];
+	}
+}
+
 EXPORT_SYMBOL(cpu_to_node);
 EXPORT_SYMBOL(node_to_cpumask);
 EXPORT_SYMBOL(memnode_shift);
 EXPORT_SYMBOL(memnodemap);
 EXPORT_SYMBOL(node_data);
+
+#ifdef CONFIG_DISCONTIGMEM
+/*
+ * Functions to convert PFNs from/to per node page addresses.
+ * These are out of line because they are quite big.
+ * They could be all tuned by pre caching more state.
+ * Should do that.
+ */
+
+/* Requires pfn_valid(pfn) to be true */
+struct page *pfn_to_page(unsigned long pfn)
+{
+	int nid = phys_to_nid(((unsigned long)(pfn)) << PAGE_SHIFT);
+	return (pfn - node_start_pfn(nid)) + NODE_DATA(nid)->node_mem_map;
+}
+EXPORT_SYMBOL(pfn_to_page);
+
+unsigned long page_to_pfn(struct page *page)
+{
+	return (long)(((page) - page_zone(page)->zone_mem_map) +
+		      page_zone(page)->zone_start_pfn);
+}
+EXPORT_SYMBOL(page_to_pfn);
+
+int pfn_valid(unsigned long pfn)
+{
+	unsigned nid;
+	if (pfn >= num_physpages)
+		return 0;
+	nid = pfn_to_nid(pfn);
+	if (nid == 0xff)
+		return 0;
+	return pfn >= node_start_pfn(nid) && (pfn) < node_end_pfn(nid);
+}
+EXPORT_SYMBOL(pfn_valid);
+#endif
diff --git a/arch/x86_64/mm/srat.c b/arch/x86_64/mm/srat.c
index 33340bd..8b7f856 100644
--- a/arch/x86_64/mm/srat.c
+++ b/arch/x86_64/mm/srat.c
@@ -17,21 +17,23 @@
 #include <linux/topology.h>
 #include <asm/proto.h>
 #include <asm/numa.h>
+#include <asm/e820.h>
 
 static struct acpi_table_slit *acpi_slit;
 
 static nodemask_t nodes_parsed __initdata;
 static nodemask_t nodes_found __initdata;
 static struct node nodes[MAX_NUMNODES] __initdata;
-static __u8  pxm2node[256] = { [0 ... 255] = 0xff };
+static u8 pxm2node[256] = { [0 ... 255] = 0xff };
 
 static int node_to_pxm(int n);
 
 int pxm_to_node(int pxm)
 {
 	if ((unsigned)pxm >= 256)
-		return 0;
-	return pxm2node[pxm];
+		return -1;
+	/* Extend 0xff to (int)-1 */
+	return (signed char)pxm2node[pxm];
 }
 
 static __init int setup_node(int pxm)
@@ -91,9 +93,36 @@
 	return numa_off || acpi_numa < 0;
 }
 
+/*
+ * A lot of BIOS fill in 10 (= no distance) everywhere. This messes
+ * up the NUMA heuristics which wants the local node to have a smaller
+ * distance than the others.
+ * Do some quick checks here and only use the SLIT if it passes.
+ */
+static __init int slit_valid(struct acpi_table_slit *slit)
+{
+	int i, j;
+	int d = slit->localities;
+	for (i = 0; i < d; i++) {
+		for (j = 0; j < d; j++)  {
+			u8 val = slit->entry[d*i + j];
+			if (i == j) {
+				if (val != 10)
+					return 0;
+			} else if (val <= 10)
+				return 0;
+		}
+	}
+	return 1;
+}
+
 /* Callback for SLIT parsing */
 void __init acpi_numa_slit_init(struct acpi_table_slit *slit)
 {
+	if (!slit_valid(slit)) {
+		printk(KERN_INFO "ACPI: SLIT table looks invalid. Not used.\n");
+		return;
+	}
 	acpi_slit = slit;
 }
 
@@ -168,12 +197,39 @@
 	       nd->start, nd->end);
 }
 
+/* Sanity check to catch more bad SRATs (they are amazingly common).
+   Make sure the PXMs cover all memory. */
+static int nodes_cover_memory(void)
+{
+	int i;
+	unsigned long pxmram, e820ram;
+
+	pxmram = 0;
+	for_each_node_mask(i, nodes_parsed) {
+		unsigned long s = nodes[i].start >> PAGE_SHIFT;
+		unsigned long e = nodes[i].end >> PAGE_SHIFT;
+		pxmram += e - s;
+		pxmram -= e820_hole_size(s, e);
+	}
+
+	e820ram = end_pfn - e820_hole_size(0, end_pfn);
+	if (pxmram < e820ram) {
+		printk(KERN_ERR
+	"SRAT: PXMs only cover %luMB of your %luMB e820 RAM. Not used.\n",
+			(pxmram << PAGE_SHIFT) >> 20,
+			(e820ram << PAGE_SHIFT) >> 20);
+		return 0;
+	}
+	return 1;
+}
+
 void __init acpi_numa_arch_fixup(void) {}
 
 /* Use the information discovered above to actually set up the nodes. */
 int __init acpi_scan_nodes(unsigned long start, unsigned long end)
 {
 	int i;
+
 	if (acpi_numa <= 0)
 		return -1;
 
@@ -184,6 +240,11 @@
 			node_clear(i, nodes_parsed);
 	}
 
+	if (!nodes_cover_memory()) {
+		bad_srat();
+		return -1;
+	}
+
 	memnode_shift = compute_hash_shift(nodes, nodes_weight(nodes_parsed));
 	if (memnode_shift < 0) {
 		printk(KERN_ERR
diff --git a/arch/x86_64/pci/Makefile-BUS b/arch/x86_64/pci/Makefile-BUS
deleted file mode 100644
index 4f0c05a..0000000
--- a/arch/x86_64/pci/Makefile-BUS
+++ /dev/null
@@ -1,22 +0,0 @@
-#
-# Makefile for X86_64 specific PCI routines
-#
-# Reuse the i386 PCI subsystem
-#
-CFLAGS += -I arch/i386/pci
-
-obj-y		:= i386.o
-obj-$(CONFIG_PCI_DIRECT)+= direct.o
-obj-y		+= fixup.o
-obj-$(CONFIG_ACPI)	+= acpi.o
-obj-y			+= legacy.o irq.o common.o
-# mmconfig has a 64bit special
-obj-$(CONFIG_PCI_MMCONFIG) += mmconfig.o
-
-direct-y += ../../i386/pci/direct.o
-acpi-y   += ../../i386/pci/acpi.o
-legacy-y += ../../i386/pci/legacy.o
-irq-y    += ../../i386/pci/irq.o
-common-y += ../../i386/pci/common.o
-fixup-y  += ../../i386/pci/fixup.o
-i386-y  += ../../i386/pci/i386.o
diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig
index 7e841aa..7ee4a14 100644
--- a/arch/xtensa/Kconfig
+++ b/arch/xtensa/Kconfig
@@ -18,10 +18,6 @@
 	  with reasonable minimum requirements.  The Xtensa Linux project has
 	  a home page at <http://xtensa.sourceforge.net/>.
 
-config UID16
-	bool
-	default n
-
 config RWSEM_XCHGADD_ALGORITHM
 	bool
 	default y
diff --git a/arch/xtensa/kernel/process.c b/arch/xtensa/kernel/process.c
index 6a44b54..f1f5966 100644
--- a/arch/xtensa/kernel/process.c
+++ b/arch/xtensa/kernel/process.c
@@ -145,7 +145,7 @@
 	int user_mode = user_mode(regs);
 
 	/* Set up new TSS. */
-	tos = (unsigned long)p->thread_info + THREAD_SIZE;
+	tos = (unsigned long)task_stack_page(p) + THREAD_SIZE;
 	if (user_mode)
 		childregs = (struct pt_regs*)(tos - PT_USER_SIZE);
 	else
@@ -217,7 +217,7 @@
 unsigned long get_wchan(struct task_struct *p)
 {
 	unsigned long sp, pc;
-	unsigned long stack_page = (unsigned long) p->thread_info;
+	unsigned long stack_page = (unsigned long) task_stack_page(p);
 	int count = 0;
 
 	if (!p || p == current || p->state == TASK_RUNNING)
diff --git a/arch/xtensa/kernel/ptrace.c b/arch/xtensa/kernel/ptrace.c
index ab5c4c6..4cc8528 100644
--- a/arch/xtensa/kernel/ptrace.c
+++ b/arch/xtensa/kernel/ptrace.c
@@ -72,7 +72,7 @@
 		struct pt_regs *regs;
 		unsigned long tmp;
 
-		regs = xtensa_pt_regs(child);
+		regs = task_pt_regs(child);
 		tmp = 0;  /* Default return value. */
 
 		switch(addr) {
@@ -149,7 +149,7 @@
 	case PTRACE_POKEUSR:
 		{
 		struct pt_regs *regs;
-		regs = xtensa_pt_regs(child);
+		regs = task_pt_regs(child);
 
 		switch (addr) {
 		case REG_AR_BASE ... REG_AR_BASE + XCHAL_NUM_AREGS - 1:
@@ -240,7 +240,7 @@
 		 * elf_gregset_t format. */
 
 		xtensa_gregset_t format;
-		struct pt_regs *regs = xtensa_pt_regs(child);
+		struct pt_regs *regs = task_pt_regs(child);
 
 		do_copy_regs (&format, regs, child);
 
@@ -257,7 +257,7 @@
 		 * values in the elf_gregset_t format. */
 
 		xtensa_gregset_t format;
-		struct pt_regs *regs = xtensa_pt_regs(child);
+		struct pt_regs *regs = task_pt_regs(child);
 
 		if (copy_from_user(&format,(void *)data,sizeof(elf_gregset_t))){
 			ret = -EFAULT;
@@ -281,7 +281,7 @@
 		 * elf_fpregset_t format. */
 
 		elf_fpregset_t fpregs;
-		struct pt_regs *regs = xtensa_pt_regs(child);
+		struct pt_regs *regs = task_pt_regs(child);
 
 		do_save_fpregs (&fpregs, regs, child);
 
@@ -299,7 +299,7 @@
 		 * values in the elf_fpregset_t format.
 		 */
 		elf_fpregset_t fpregs;
-		struct pt_regs *regs = xtensa_pt_regs(child);
+		struct pt_regs *regs = task_pt_regs(child);
 
 		ret = 0;
 		if (copy_from_user(&fpregs, (void *)data, sizeof(elf_fpregset_t))) {
diff --git a/block/elevator.c b/block/elevator.c
index 99a4d7b..1d075917 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -610,23 +610,23 @@
 	 * request is released from the driver, io must be done
 	 */
 	if (blk_account_rq(rq)) {
-		struct request *first_rq = list_entry_rq(q->queue_head.next);
-
 		q->in_flight--;
+		if (blk_sorted_rq(rq) && e->ops->elevator_completed_req_fn)
+			e->ops->elevator_completed_req_fn(q, rq);
+	}
 
-		/*
-		 * Check if the queue is waiting for fs requests to be
-		 * drained for flush sequence.
-		 */
-		if (q->ordseq && q->in_flight == 0 &&
+	/*
+	 * Check if the queue is waiting for fs requests to be
+	 * drained for flush sequence.
+	 */
+	if (unlikely(q->ordseq)) {
+		struct request *first_rq = list_entry_rq(q->queue_head.next);
+		if (q->in_flight == 0 &&
 		    blk_ordered_cur_seq(q) == QUEUE_ORDSEQ_DRAIN &&
 		    blk_ordered_req_seq(first_rq) > QUEUE_ORDSEQ_DRAIN) {
 			blk_ordered_complete_seq(q, QUEUE_ORDSEQ_DRAIN, 0);
 			q->request_fn(q);
 		}
-
-		if (blk_sorted_rq(rq) && e->ops->elevator_completed_req_fn)
-			e->ops->elevator_completed_req_fn(q, rq);
 	}
 }
 
diff --git a/block/ioctl.c b/block/ioctl.c
index 82030e1..e110949 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -1,4 +1,4 @@
-#include <linux/sched.h>		/* for capable() */
+#include <linux/capability.h>
 #include <linux/blkdev.h>
 #include <linux/blkpg.h>
 #include <linux/hdreg.h>
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index 18de84c..cc72210 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -21,6 +21,7 @@
 #include <linux/string.h>
 #include <linux/module.h>
 #include <linux/blkdev.h>
+#include <linux/capability.h>
 #include <linux/completion.h>
 #include <linux/cdrom.h>
 #include <linux/slab.h>
diff --git a/drivers/acorn/char/i2c.c b/drivers/acorn/char/i2c.c
index c22bb9d..c26c08b 100644
--- a/drivers/acorn/char/i2c.c
+++ b/drivers/acorn/char/i2c.c
@@ -12,6 +12,7 @@
  *  On Acorn machines, the following i2c devices are on the bus:
  *	- PCF8583 real time clock & static RAM
  */
+#include <linux/capability.h>
 #include <linux/init.h>
 #include <linux/sched.h>
 #include <linux/time.h>
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 807b0df..cc04933 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -843,6 +843,15 @@
 	unsigned int i;
 	unsigned int working = 0;
 
+#ifdef ARCH_APICTIMER_STOPS_ON_C3
+	struct cpuinfo_x86 *c = cpu_data + pr->id;
+	cpumask_t mask = cpumask_of_cpu(pr->id);
+
+	if (c->x86_vendor == X86_VENDOR_INTEL) {
+		on_each_cpu(switch_ipi_to_APIC_timer, &mask, 1, 1);
+	}
+#endif
+
 	for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
 		struct acpi_processor_cx *cx = &pr->power.states[i];
 
@@ -857,6 +866,12 @@
 
 		case ACPI_STATE_C3:
 			acpi_processor_power_verify_c3(pr, cx);
+#ifdef ARCH_APICTIMER_STOPS_ON_C3
+			if (c->x86_vendor == X86_VENDOR_INTEL) {
+				on_each_cpu(switch_APIC_timer_to_ipi,
+						&mask, 1, 1);
+			}
+#endif
 			break;
 		}
 
diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
index 55959e4..f484747 100644
--- a/drivers/atm/zatm.c
+++ b/drivers/atm/zatm.c
@@ -669,11 +669,13 @@
 		u32 *put;
 		int i;
 
-		dsc = (u32 *) kmalloc(uPD98401_TXPD_SIZE*2+
-		    uPD98401_TXBD_SIZE*ATM_SKB(skb)->iovcnt,GFP_ATOMIC);
+		dsc = kmalloc(uPD98401_TXPD_SIZE * 2 +
+			uPD98401_TXBD_SIZE * ATM_SKB(skb)->iovcnt, GFP_ATOMIC);
 		if (!dsc) {
-			if (vcc->pop) vcc->pop(vcc,skb);
-			else dev_kfree_skb_irq(skb);
+			if (vcc->pop)
+				vcc->pop(vcc, skb);
+			else
+				dev_kfree_skb_irq(skb);
 			return -EAGAIN;
 		}
 		/* @@@ should check alignment */
@@ -683,7 +685,7 @@
 		    (ATM_SKB(skb)->atm_options & ATM_ATMOPT_CLP ?
 		    uPD98401_CLPM_1 : uPD98401_CLPM_0));
 		dsc[1] = 0;
-		dsc[2] = ATM_SKB(skb)->iovcnt*uPD98401_TXBD_SIZE;
+		dsc[2] = ATM_SKB(skb)->iovcnt * uPD98401_TXBD_SIZE;
 		dsc[3] = virt_to_bus(put);
 		for (i = 0; i < ATM_SKB(skb)->iovcnt; i++) {
 			*put++ = ((struct iovec *) skb->data)[i].iov_len;
diff --git a/drivers/base/core.c b/drivers/base/core.c
index fd80599..6b355bd 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -161,8 +161,8 @@
 	return count;
 }
 
-/**
- *	device_subsys - structure to be registered with kobject core.
+/*
+ *	devices_subsys - structure to be registered with kobject core.
  */
 
 decl_subsys(devices, &ktype_device, &device_uevent_ops);
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 281d267..07a7f97 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -83,6 +83,31 @@
 }
 #endif /* CONFIG_HOTPLUG_CPU */
 
+#ifdef CONFIG_KEXEC
+#include <linux/kexec.h>
+
+static ssize_t show_crash_notes(struct sys_device *dev, char *buf)
+{
+	struct cpu *cpu = container_of(dev, struct cpu, sysdev);
+	ssize_t rc;
+	unsigned long long addr;
+	int cpunum;
+
+	cpunum = cpu->sysdev.id;
+
+	/*
+	 * Might be reading other cpu's data based on which cpu read thread
+	 * has been scheduled. But cpu data (memory) is allocated once during
+	 * boot up and this data does not change there after. Hence this
+	 * operation should be safe. No locking required.
+	 */
+	addr = __pa(per_cpu_ptr(crash_notes, cpunum));
+	rc = sprintf(buf, "%Lx\n", addr);
+	return rc;
+}
+static SYSDEV_ATTR(crash_notes, 0400, show_crash_notes, NULL);
+#endif
+
 /*
  * register_cpu - Setup a driverfs device for a CPU.
  * @cpu - Callers can set the cpu->no_control field to 1, to indicate not to
@@ -108,6 +133,11 @@
 		register_cpu_control(cpu);
 	if (!error)
 		cpu_sys_devices[num] = &cpu->sysdev;
+
+#ifdef CONFIG_KEXEC
+	if (!error)
+		error = sysdev_create_file(&cpu->sysdev, &attr_crash_notes);
+#endif
 	return error;
 }
 
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 5b3d5e9..3d384e3 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -7,6 +7,7 @@
  *
  */
 
+#include <linux/capability.h>
 #include <linux/device.h>
 #include <linux/module.h>
 #include <linux/init.h>
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 58801d7..d1a0522 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -13,8 +13,8 @@
 #include <linux/sysdev.h>
 #include <linux/module.h>
 #include <linux/init.h>
-#include <linux/sched.h>	/* capable() */
 #include <linux/topology.h>
+#include <linux/capability.h>
 #include <linux/device.h>
 #include <linux/memory.h>
 #include <linux/kobject.h>
diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c
index 3c679d3..b6e2909 100644
--- a/drivers/block/amiflop.c
+++ b/drivers/block/amiflop.c
@@ -194,6 +194,8 @@
  */
 #define MAX_ERRORS 12
 
+#define custom amiga_custom
+
 /* Prevent "aliased" accesses. */
 static int fd_ref[4] = { 0,0,0,0 };
 static int fd_device[4] = { 0, 0, 0, 0 };
@@ -1439,6 +1441,7 @@
 {
 	int drive = iminor(inode) & 3;
 	static struct floppy_struct getprm;
+	void __user *argp = (void __user *)param;
 
 	switch(cmd){
 	case FDFMTBEG:
@@ -1484,9 +1487,7 @@
 		getprm.head=unit[drive].type->heads;
 		getprm.sect=unit[drive].dtype->sects * unit[drive].type->sect_mult;
 		getprm.size=unit[drive].blocks;
-		if (copy_to_user((void *)param,
-				 (void *)&getprm,
-				 sizeof(struct floppy_struct)))
+		if (copy_to_user(argp, &getprm, sizeof(struct floppy_struct)))
 			return -EFAULT;
 		break;
 	case FDSETPRM:
@@ -1498,8 +1499,7 @@
 		break;
 #ifdef RAW_IOCTL
 	case IOCTL_RAW_TRACK:
-		if (copy_to_user((void *)param, raw_buf,
-				 unit[drive].type->read_size))
+		if (copy_to_user(argp, raw_buf, unit[drive].type->read_size))
 			return -EFAULT;
 		else
 			return unit[drive].type->read_size;
@@ -1654,12 +1654,6 @@
 	.media_changed	= amiga_floppy_change,
 };
 
-void __init amiga_floppy_setup (char *str, int *ints)
-{
-	printk (KERN_INFO "amiflop: Setting default df0 to %x\n", ints[1]);
-	fd_def_df0 = ints[1];
-}
-
 static int __init fd_probe_drives(void)
 {
 	int drive,drives,nomem;
@@ -1845,4 +1839,18 @@
 	unregister_blkdev(FLOPPY_MAJOR, "fd");
 }
 #endif
+
+#else
+static int __init amiga_floppy_setup (char *str)
+{
+	int n;
+	if (!MACH_IS_AMIGA)
+		return 0;
+	if (!get_option(&str, &n))
+		return 0;
+	printk (KERN_INFO "amiflop: Setting default df0 to %x\n", n);
+	fd_def_df0 = n;
+}
+
+__setup("floppy=", amiga_floppy_setup);
 #endif
diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
index 3aa68a54..f8ce235 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -1361,7 +1361,7 @@
 		   formats, for 'permanent user-defined' parameter:
 		   restore default_params[] here if flagged valid! */
 		if (default_params[drive].blocks == 0)
-			UDT = 0;
+			UDT = NULL;
 		else
 			UDT = &default_params[drive];
 	}
@@ -1495,6 +1495,7 @@
 	struct floppy_struct getprm;
 	int settype;
 	struct floppy_struct setprm;
+	void __user *argp = (void __user *)param;
 
 	switch (cmd) {
 	case FDGETPRM:
@@ -1521,7 +1522,7 @@
 		getprm.head = 2;
 		getprm.track = dtp->blocks/dtp->spt/2;
 		getprm.stretch = dtp->stretch;
-		if (copy_to_user((void *)param, &getprm, sizeof(getprm)))
+		if (copy_to_user(argp, &getprm, sizeof(getprm)))
 			return -EFAULT;
 		return 0;
 	}
@@ -1540,7 +1541,7 @@
 		/* get the parameters from user space */
 		if (floppy->ref != 1 && floppy->ref != -1)
 			return -EBUSY;
-		if (copy_from_user(&setprm, (void *) param, sizeof(setprm)))
+		if (copy_from_user(&setprm, argp, sizeof(setprm)))
 			return -EFAULT;
 		/* 
 		 * first of all: check for floppy change and revalidate, 
@@ -1647,7 +1648,7 @@
 	case FDFMTTRK:
 		if (floppy->ref != 1 && floppy->ref != -1)
 			return -EBUSY;
-		if (copy_from_user(&fmt_desc, (void *) param, sizeof(fmt_desc)))
+		if (copy_from_user(&fmt_desc, argp, sizeof(fmt_desc)))
 			return -EFAULT;
 		return do_format(drive, type, &fmt_desc);
 	case FDCLRPRM:
@@ -1950,14 +1951,20 @@
 	return -ENOMEM;
 }
 
-
-void __init atari_floppy_setup( char *str, int *ints )
+#ifndef MODULE
+static int __init atari_floppy_setup(char *str)
 {
+	int ints[3 + FD_MAX_UNITS];
 	int i;
+
+	if (!MACH_IS_ATARI)
+		return 0;
+
+	str = get_options(str, 3 + FD_MAX_UNITS, ints);
 	
 	if (ints[0] < 1) {
 		printk(KERN_ERR "ataflop_setup: no arguments!\n" );
-		return;
+		return 0;
 	}
 	else if (ints[0] > 2+FD_MAX_UNITS) {
 		printk(KERN_ERR "ataflop_setup: too many arguments\n" );
@@ -1977,9 +1984,13 @@
 		else
 			UserSteprate[i-3] = ints[i];
 	}
+	return 1;
 }
 
-static void atari_floppy_exit(void)
+__setup("floppy=", atari_floppy_setup);
+#endif
+
+static void __exit atari_floppy_exit(void)
 {
 	int i;
 	blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256);
diff --git a/drivers/block/viodasd.c b/drivers/block/viodasd.c
index d1aaf31b..f63e07b 100644
--- a/drivers/block/viodasd.c
+++ b/drivers/block/viodasd.c
@@ -293,6 +293,7 @@
 	u16 viocmd;
 	HvLpEvent_Rc hvrc;
 	struct vioblocklpevent *bevent;
+	struct HvLpEvent *hev;
 	struct scatterlist sg[VIOMAXBLOCKDMA];
 	int sgindex;
 	int statindex;
@@ -347,22 +348,19 @@
 		 * token so we can match the response up later
 		 */
 		memset(bevent, 0, sizeof(struct vioblocklpevent));
-		bevent->event.xFlags.xValid = 1;
-		bevent->event.xFlags.xFunction = HvLpEvent_Function_Int;
-		bevent->event.xFlags.xAckInd = HvLpEvent_AckInd_DoAck;
-		bevent->event.xFlags.xAckType = HvLpEvent_AckType_ImmediateAck;
-		bevent->event.xType = HvLpEvent_Type_VirtualIo;
-		bevent->event.xSubtype = viocmd;
-		bevent->event.xSourceLp = HvLpConfig_getLpIndex();
-		bevent->event.xTargetLp = viopath_hostLp;
-		bevent->event.xSizeMinus1 =
+		hev = &bevent->event;
+		hev->flags = HV_LP_EVENT_VALID | HV_LP_EVENT_DO_ACK |
+			HV_LP_EVENT_INT;
+		hev->xType = HvLpEvent_Type_VirtualIo;
+		hev->xSubtype = viocmd;
+		hev->xSourceLp = HvLpConfig_getLpIndex();
+		hev->xTargetLp = viopath_hostLp;
+		hev->xSizeMinus1 =
 			offsetof(struct vioblocklpevent, u.rw_data.dma_info) +
 			(sizeof(bevent->u.rw_data.dma_info[0]) * nsg) - 1;
-		bevent->event.xSourceInstanceId =
-			viopath_sourceinst(viopath_hostLp);
-		bevent->event.xTargetInstanceId =
-			viopath_targetinst(viopath_hostLp);
-		bevent->event.xCorrelationToken = (u64)req;
+		hev->xSourceInstanceId = viopath_sourceinst(viopath_hostLp);
+		hev->xTargetInstanceId = viopath_targetinst(viopath_hostLp);
+		hev->xCorrelationToken = (u64)req;
 		bevent->version = VIOVERSION;
 		bevent->disk = DEVICE_NO(d);
 		bevent->u.rw_data.offset = start;
@@ -649,10 +647,10 @@
 		/* Notification that a partition went away! */
 		return;
 	/* First, we should NEVER get an int here...only acks */
-	if (event->xFlags.xFunction == HvLpEvent_Function_Int) {
+	if (hvlpevent_is_int(event)) {
 		printk(VIOD_KERN_WARNING
 		       "Yikes! got an int in viodasd event handler!\n");
-		if (event->xFlags.xAckInd == HvLpEvent_AckInd_DoAck) {
+		if (hvlpevent_need_ack(event)) {
 			event->xRc = HvLpEvent_Rc_InvalidSubtype;
 			HvCallEvent_ackLpEvent(event);
 		}
@@ -695,7 +693,7 @@
 
 	default:
 		printk(VIOD_KERN_WARNING "invalid subtype!");
-		if (event->xFlags.xAckInd == HvLpEvent_AckInd_DoAck) {
+		if (hvlpevent_need_ack(event)) {
 			event->xRc = HvLpEvent_Rc_InvalidSubtype;
 			HvCallEvent_ackLpEvent(event);
 		}
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index 573ff6c..613673b 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -279,6 +279,7 @@
 
 	tty->disc_data = hu;
 	hu->tty = tty;
+	tty->receive_room = 65536;
 
 	spin_lock_init(&hu->rx_lock);
 
@@ -348,20 +349,6 @@
 		hci_uart_tx_wakeup(hu);
 }
 
-/* hci_uart_tty_room()
- * 
- *    Callback function from tty driver. Return the amount of 
- *    space left in the receiver's buffer to decide if remote
- *    transmitter is to be throttled.
- *
- * Arguments:        tty    pointer to associated tty instance data
- * Return Value:    number of bytes left in receive buffer
- */
-static int hci_uart_tty_room (struct tty_struct *tty)
-{
-	return 65536;
-}
-
 /* hci_uart_tty_receive()
  * 
  *     Called by tty low level driver when receive data is
@@ -544,7 +531,6 @@
 	hci_uart_ldisc.write		= hci_uart_tty_write;
 	hci_uart_ldisc.ioctl		= hci_uart_tty_ioctl;
 	hci_uart_ldisc.poll		= hci_uart_tty_poll;
-	hci_uart_ldisc.receive_room	= hci_uart_tty_room;
 	hci_uart_ldisc.receive_buf	= hci_uart_tty_receive;
 	hci_uart_ldisc.write_wakeup	= hci_uart_tty_wakeup;
 	hci_uart_ldisc.owner		= THIS_MODULE;
diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index 1539603..879bbc2 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -1131,7 +1131,7 @@
 	This ensures that the drive gets unlocked after a mount fails.  This 
 	is a goto to avoid bloating the driver with redundant code. */ 
 clean_up_and_return:
-	cdinfo(CD_WARNING, "open failed.\n"); 
+	cdinfo(CD_OPEN, "open failed.\n"); 
 	if (CDROM_CAN(CDC_LOCK) && cdi->options & CDO_LOCK) {
 			cdo->lock_door(cdi, 0);
 			cdinfo(CD_OPEN, "door unlocked.\n");
diff --git a/drivers/cdrom/viocd.c b/drivers/cdrom/viocd.c
index b519178..193446e 100644
--- a/drivers/cdrom/viocd.c
+++ b/drivers/cdrom/viocd.c
@@ -542,10 +542,10 @@
 		/* Notification that a partition went away! */
 		return;
 	/* First, we should NEVER get an int here...only acks */
-	if (event->xFlags.xFunction == HvLpEvent_Function_Int) {
+	if (hvlpevent_is_int(event)) {
 		printk(VIOCD_KERN_WARNING
 				"Yikes! got an int in viocd event handler!\n");
-		if (event->xFlags.xAckInd == HvLpEvent_AckInd_DoAck) {
+		if (hvlpevent_need_ack(event)) {
 			event->xRc = HvLpEvent_Rc_InvalidSubtype;
 			HvCallEvent_ackLpEvent(event);
 		}
@@ -616,7 +616,7 @@
 		printk(VIOCD_KERN_WARNING
 				"message with invalid subtype %0x04X!\n",
 				event->xSubtype & VIOMINOR_SUBTYPE_MASK);
-		if (event->xFlags.xAckInd == HvLpEvent_AckInd_DoAck) {
+		if (hvlpevent_need_ack(event)) {
 			event->xRc = HvLpEvent_Rc_InvalidSubtype;
 			HvCallEvent_ackLpEvent(event);
 		}
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index dd7e690..d6fcd0a 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -80,7 +80,7 @@
 
 config COMPUTONE
 	tristate "Computone IntelliPort Plus serial support"
-	depends on SERIAL_NONSTANDARD && BROKEN_ON_SMP
+	depends on SERIAL_NONSTANDARD
 	---help---
 	  This driver supports the entire family of Intelliport II/Plus
 	  controllers with the exception of the MicroChannel controllers and
@@ -153,7 +153,7 @@
 
 config ESPSERIAL
 	tristate "Hayes ESP serial port support"
-	depends on SERIAL_NONSTANDARD && ISA && BROKEN_ON_SMP && ISA_DMA_API
+	depends on SERIAL_NONSTANDARD && ISA && ISA_DMA_API
 	help
 	  This is a driver which supports Hayes ESP serial ports.  Both single
 	  port cards and multiport cards are supported.  Make sure to read
@@ -166,7 +166,7 @@
 
 config MOXA_INTELLIO
 	tristate "Moxa Intellio support"
-	depends on SERIAL_NONSTANDARD && BROKEN_ON_SMP
+	depends on SERIAL_NONSTANDARD
 	help
 	  Say Y here if you have a Moxa Intellio multiport serial card.
 
@@ -290,7 +290,7 @@
 
 config RIO
 	tristate "Specialix RIO system support"
-	depends on SERIAL_NONSTANDARD && BROKEN_ON_SMP
+	depends on SERIAL_NONSTANDARD && BROKEN_ON_SMP && !64BIT
 	help
 	  This is a driver for the Specialix RIO, a smart serial card which
 	  drives an outboard box that can support up to 128 ports.  Product
@@ -936,6 +936,15 @@
 
 	  If compiled as a module, it will be called scx200_gpio.
 
+config CS5535_GPIO
+	tristate "AMD CS5535/CS5536 GPIO (Geode Companion Device)"
+	depends on X86_32
+	help
+	  Give userspace access to the GPIO pins on the AMD CS5535 and
+	  CS5536 Geode companion devices.
+
+	  If compiled as a module, it will be called cs5535_gpio.
+
 config GPIO_VR41XX
 	tristate "NEC VR4100 series General-purpose I/O Unit support"
 	depends on CPU_VR41XX
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index d973d14..503dd90 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -81,6 +81,7 @@
 obj-$(CONFIG_NWBUTTON) += nwbutton.o
 obj-$(CONFIG_NWFLASH) += nwflash.o
 obj-$(CONFIG_SCx200_GPIO) += scx200_gpio.o
+obj-$(CONFIG_CS5535_GPIO) += cs5535_gpio.o
 obj-$(CONFIG_GPIO_VR41XX) += vr41xx_giu.o
 obj-$(CONFIG_TANBAC_TB0219) += tb0219.o
 obj-$(CONFIG_TELCLOCK) += tlclk.o
diff --git a/drivers/char/amiserial.c b/drivers/char/amiserial.c
index a124f8c..667a21c 100644
--- a/drivers/char/amiserial.c
+++ b/drivers/char/amiserial.c
@@ -99,6 +99,7 @@
 #define _INLINE_ inline
 #endif
 
+#define custom amiga_custom
 static char *serial_name = "Amiga-builtin serial driver";
 
 static struct tty_driver *serial_driver;
@@ -116,7 +117,7 @@
 
 static struct serial_state rs_table[1];
 
-#define NR_PORTS	(sizeof(rs_table)/sizeof(struct serial_state))
+#define NR_PORTS ARRAY_SIZE(rs_table)
 
 /*
  * tmp_buf is used as a temporary buffer by serial_write.  We need to
@@ -265,8 +266,9 @@
         int status;
 	int serdatr;
 	struct tty_struct *tty = info->tty;
-	unsigned char ch;
+	unsigned char ch, flag;
 	struct	async_icount *icount;
+	int oe = 0;
 
 	icount = &info->state->icount;
 
@@ -282,15 +284,12 @@
 	    status |= UART_LSR_OE;
 
 	ch = serdatr & 0xff;
-	if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-	  goto ignore_char;
-	*tty->flip.char_buf_ptr = ch;
 	icount->rx++;
 
 #ifdef SERIAL_DEBUG_INTR
 	printk("DR%02x:%02x...", ch, status);
 #endif
-	*tty->flip.flag_buf_ptr = 0;
+	flag = TTY_NORMAL;
 
 	/*
 	 * We don't handle parity or frame errors - but I have left
@@ -319,7 +318,7 @@
 	   * should be ignored.
 	   */
 	  if (status & info->ignore_status_mask)
-	    goto ignore_char;
+	    goto out;
 
 	  status &= info->read_status_mask;
 
@@ -327,33 +326,28 @@
 #ifdef SERIAL_DEBUG_INTR
 	    printk("handling break....");
 #endif
-	    *tty->flip.flag_buf_ptr = TTY_BREAK;
+	    flag = TTY_BREAK;
 	    if (info->flags & ASYNC_SAK)
 	      do_SAK(tty);
 	  } else if (status & UART_LSR_PE)
-	    *tty->flip.flag_buf_ptr = TTY_PARITY;
+	    flag = TTY_PARITY;
 	  else if (status & UART_LSR_FE)
-	    *tty->flip.flag_buf_ptr = TTY_FRAME;
+	    flag = TTY_FRAME;
 	  if (status & UART_LSR_OE) {
 	    /*
 	     * Overrun is special, since it's
 	     * reported immediately, and doesn't
 	     * affect the current character
 	     */
-	    if (tty->flip.count < TTY_FLIPBUF_SIZE) {
-	      tty->flip.count++;
-	      tty->flip.flag_buf_ptr++;
-	      tty->flip.char_buf_ptr++;
-	      *tty->flip.flag_buf_ptr = TTY_OVERRUN;
-	    }
+	     oe = 1;
 	  }
 	}
-	tty->flip.flag_buf_ptr++;
-	tty->flip.char_buf_ptr++;
-	tty->flip.count++;
- ignore_char:
-
+	tty_insert_flip_char(tty, ch, flag);
+	if (oe == 1)
+		tty_insert_flip_char(tty, 0, TTY_OVERRUN);
 	tty_flip_buffer_push(tty);
+out:
+	return;
 }
 
 static _INLINE_ void transmit_chars(struct async_struct *info)
@@ -1095,7 +1089,7 @@
  */
 
 static int get_serial_info(struct async_struct * info,
-			   struct serial_struct * retinfo)
+			   struct serial_struct __user * retinfo)
 {
 	struct serial_struct tmp;
 	struct serial_state *state = info->state;
@@ -1119,7 +1113,7 @@
 }
 
 static int set_serial_info(struct async_struct * info,
-			   struct serial_struct * new_info)
+			   struct serial_struct __user * new_info)
 {
 	struct serial_struct new_serial;
  	struct serial_state old_state, *state;
@@ -1200,7 +1194,7 @@
  * 	    transmit holding register is empty.  This functionality
  * 	    allows an RS485 driver to be written in user space. 
  */
-static int get_lsr_info(struct async_struct * info, unsigned int *value)
+static int get_lsr_info(struct async_struct * info, unsigned int __user *value)
 {
 	unsigned char status;
 	unsigned int result;
@@ -1291,6 +1285,7 @@
 	struct async_struct * info = (struct async_struct *)tty->driver_data;
 	struct async_icount cprev, cnow;	/* kernel counter temps */
 	struct serial_icounter_struct icount;
+	void __user *argp = (void __user *)arg;
 	unsigned long flags;
 
 	if (serial_paranoia_check(info, tty->name, "rs_ioctl"))
@@ -1305,19 +1300,17 @@
 
 	switch (cmd) {
 		case TIOCGSERIAL:
-			return get_serial_info(info,
-					       (struct serial_struct *) arg);
+			return get_serial_info(info, argp);
 		case TIOCSSERIAL:
-			return set_serial_info(info,
-					       (struct serial_struct *) arg);
+			return set_serial_info(info, argp);
 		case TIOCSERCONFIG:
 			return 0;
 
 		case TIOCSERGETLSR: /* Get line status register */
-			return get_lsr_info(info, (unsigned int *) arg);
+			return get_lsr_info(info, argp);
 
 		case TIOCSERGSTRUCT:
-			if (copy_to_user((struct async_struct *) arg,
+			if (copy_to_user(argp,
 					 info, sizeof(struct async_struct)))
 				return -EFAULT;
 			return 0;
@@ -1376,7 +1369,7 @@
 			icount.brk = cnow.brk;
 			icount.buf_overrun = cnow.buf_overrun;
 
-			if (copy_to_user((void *)arg, &icount, sizeof(icount)))
+			if (copy_to_user(argp, &icount, sizeof(icount)))
 				return -EFAULT;
 			return 0;
 		case TIOCSERGWILD:
diff --git a/drivers/char/cs5535_gpio.c b/drivers/char/cs5535_gpio.c
new file mode 100644
index 0000000..5d72f50
--- /dev/null
+++ b/drivers/char/cs5535_gpio.c
@@ -0,0 +1,250 @@
+/*
+ * AMD CS5535/CS5536 GPIO driver.
+ * Allows a user space process to play with the GPIO pins.
+ *
+ * Copyright (c) 2005 Ben Gardner <bgardner@wabtec.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the smems of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ */
+
+#include <linux/fs.h>
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/cdev.h>
+#include <linux/ioport.h>
+#include <linux/pci.h>
+#include <asm/uaccess.h>
+#include <asm/io.h>
+
+
+#define NAME			"cs5535_gpio"
+
+MODULE_AUTHOR("Ben Gardner <bgardner@wabtec.com>");
+MODULE_DESCRIPTION("AMD CS5535/CS5536 GPIO Pin Driver");
+MODULE_LICENSE("GPL");
+
+static int major;
+module_param(major, int, 0);
+MODULE_PARM_DESC(major, "Major device number");
+
+static ulong mask;
+module_param(mask, ulong, 0);
+MODULE_PARM_DESC(mask, "GPIO channel mask");
+
+#define MSR_LBAR_GPIO		0x5140000C
+
+static u32 gpio_base;
+
+static struct pci_device_id divil_pci[] = {
+	{ PCI_DEVICE(PCI_VENDOR_ID_NS,  PCI_DEVICE_ID_NS_CS5535_ISA) },
+	{ PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) },
+	{ } /* NULL entry */
+};
+
+static struct cdev cs5535_gpio_cdev;
+
+/* reserve 32 entries even though some aren't usable */
+#define CS5535_GPIO_COUNT	32
+
+/* IO block size */
+#define CS5535_GPIO_SIZE	256
+
+struct gpio_regmap {
+	u32	rd_offset;
+	u32	wr_offset;
+	char	on;
+	char	off;
+};
+static struct gpio_regmap rm[] =
+{
+	{ 0x30, 0x00, '1', '0' },	/* GPIOx_READ_BACK / GPIOx_OUT_VAL */
+	{ 0x20, 0x20, 'I', 'i' },	/* GPIOx_IN_EN */
+	{ 0x04, 0x04, 'O', 'o' },	/* GPIOx_OUT_EN */
+	{ 0x08, 0x08, 't', 'T' },	/* GPIOx_OUT_OD_EN */
+	{ 0x18, 0x18, 'P', 'p' },	/* GPIOx_OUT_PU_EN */
+	{ 0x1c, 0x1c, 'D', 'd' },	/* GPIOx_OUT_PD_EN */
+};
+
+
+/**
+ * Gets the register offset for the GPIO bank.
+ * Low (0-15) starts at 0x00, high (16-31) starts at 0x80
+ */
+static inline u32 cs5535_lowhigh_base(int reg)
+{
+	return (reg & 0x10) << 3;
+}
+
+static ssize_t cs5535_gpio_write(struct file *file, const char __user *data,
+				 size_t len, loff_t *ppos)
+{
+	u32	m = iminor(file->f_dentry->d_inode);
+	int	i, j;
+	u32	base = gpio_base + cs5535_lowhigh_base(m);
+	u32	m0, m1;
+	char	c;
+
+	/**
+	 * Creates the mask for atomic bit programming.
+	 * The high 16 bits and the low 16 bits are used to set the mask.
+	 * For example, GPIO 15 maps to 31,15: 0,1 => On; 1,0=> Off
+	 */
+	m1 = 1 << (m & 0x0F);
+	m0 = m1 << 16;
+
+	for (i = 0; i < len; ++i) {
+		if (get_user(c, data+i))
+			return -EFAULT;
+
+		for (j = 0; j < ARRAY_SIZE(rm); j++) {
+			if (c == rm[j].on) {
+				outl(m1, base + rm[j].wr_offset);
+				break;
+			} else if (c == rm[j].off) {
+				outl(m0, base + rm[j].wr_offset);
+				break;
+			}
+		}
+	}
+	*ppos = 0;
+	return len;
+}
+
+static ssize_t cs5535_gpio_read(struct file *file, char __user *buf,
+				size_t len, loff_t *ppos)
+{
+	u32	m = iminor(file->f_dentry->d_inode);
+	u32	base = gpio_base + cs5535_lowhigh_base(m);
+	int	rd_bit = 1 << (m & 0x0f);
+	int	i;
+	char	ch;
+	ssize_t	count = 0;
+
+	if (*ppos >= ARRAY_SIZE(rm))
+		return 0;
+
+	for (i = *ppos; (i < (*ppos + len)) && (i < ARRAY_SIZE(rm)); i++) {
+		ch = (inl(base + rm[i].rd_offset) & rd_bit) ?
+		     rm[i].on : rm[i].off;
+
+		if (put_user(ch, buf+count))
+			return -EFAULT;
+
+		count++;
+	}
+
+	/* add a line-feed if there is room */
+	if ((i == ARRAY_SIZE(rm)) && (count < len)) {
+		put_user('\n', buf + count);
+		count++;
+	}
+
+	*ppos += count;
+	return count;
+}
+
+static int cs5535_gpio_open(struct inode *inode, struct file *file)
+{
+	u32 m = iminor(inode);
+
+	/* the mask says which pins are usable by this driver */
+	if ((mask & (1 << m)) == 0)
+		return -EINVAL;
+
+	return nonseekable_open(inode, file);
+}
+
+static struct file_operations cs5535_gpio_fops = {
+	.owner	= THIS_MODULE,
+	.write	= cs5535_gpio_write,
+	.read	= cs5535_gpio_read,
+	.open	= cs5535_gpio_open
+};
+
+static int __init cs5535_gpio_init(void)
+{
+	dev_t	dev_id;
+	u32	low, hi;
+	int	retval;
+
+	if (pci_dev_present(divil_pci) == 0) {
+		printk(KERN_WARNING NAME ": DIVIL not found\n");
+		return -ENODEV;
+	}
+
+	/* Grab the GPIO I/O range */
+	rdmsr(MSR_LBAR_GPIO, low, hi);
+
+	/* Check the mask and whether GPIO is enabled (sanity check) */
+	if (hi != 0x0000f001) {
+		printk(KERN_WARNING NAME ": GPIO not enabled\n");
+		return -ENODEV;
+	}
+
+	/* Mask off the IO base address */
+	gpio_base = low & 0x0000ff00;
+
+	/**
+	 * Some GPIO pins
+	 *  31-29,23 : reserved (always mask out)
+	 *  28       : Power Button
+	 *  26       : PME#
+	 *  22-16    : LPC
+	 *  14,15    : SMBus
+	 *  9,8      : UART1
+	 *  7        : PCI INTB
+	 *  3,4      : UART2/DDC
+	 *  2        : IDE_IRQ0
+	 *  0        : PCI INTA
+	 *
+	 * If a mask was not specified, be conservative and only allow:
+	 *  1,2,5,6,10-13,24,25,27
+	 */
+	if (mask != 0)
+		mask &= 0x1f7fffff;
+	else
+		mask = 0x0b003c66;
+
+	if (request_region(gpio_base, CS5535_GPIO_SIZE, NAME) == 0) {
+		printk(KERN_ERR NAME ": can't allocate I/O for GPIO\n");
+		return -ENODEV;
+	}
+
+	if (major) {
+		dev_id = MKDEV(major, 0);
+		retval = register_chrdev_region(dev_id, CS5535_GPIO_COUNT,
+						NAME);
+	} else {
+		retval = alloc_chrdev_region(&dev_id, 0, CS5535_GPIO_COUNT,
+					     NAME);
+		major = MAJOR(dev_id);
+	}
+
+	if (retval) {
+		release_region(gpio_base, CS5535_GPIO_SIZE);
+		return -1;
+	}
+
+	printk(KERN_DEBUG NAME ": base=%#x mask=%#lx major=%d\n",
+	       gpio_base, mask, major);
+
+	cdev_init(&cs5535_gpio_cdev, &cs5535_gpio_fops);
+	cdev_add(&cs5535_gpio_cdev, dev_id, CS5535_GPIO_COUNT);
+
+	return 0;
+}
+
+static void __exit cs5535_gpio_cleanup(void)
+{
+	dev_t dev_id = MKDEV(major, 0);
+	unregister_chrdev_region(dev_id, CS5535_GPIO_COUNT);
+	if (gpio_base != 0)
+		release_region(gpio_base, CS5535_GPIO_SIZE);
+}
+
+module_init(cs5535_gpio_init);
+module_exit(cs5535_gpio_cleanup);
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
index c7f818c..39c61a7 100644
--- a/drivers/char/cyclades.c
+++ b/drivers/char/cyclades.c
@@ -641,6 +641,7 @@
 #include <linux/timer.h>
 #include <linux/interrupt.h>
 #include <linux/tty.h>
+#include <linux/tty_flip.h>
 #include <linux/serial.h>
 #include <linux/major.h>
 #include <linux/string.h>
@@ -723,7 +724,7 @@
         0xDE000,
         0,0,0,0,0,0,0,0
 };
-#define NR_ISA_ADDRS (sizeof(cy_isa_addresses)/sizeof(unsigned char*))
+#define NR_ISA_ADDRS ARRAY_SIZE(cy_isa_addresses)
 
 #ifdef MODULE
 static long maddr[NR_CARDS] = { 0, };
@@ -1086,7 +1087,7 @@
   int had_work;
   int mdm_change;
   int mdm_status;
-
+  int len;
     if((cinfo = (struct cyclades_card *)dev_id) == 0){
 #ifdef CY_DEBUG_INTERRUPTS
 	printk("cyy_interrupt: spurious interrupt %d\n\r", irq);
@@ -1163,63 +1164,43 @@
 				info->icount.rx++;
                                 continue;
                             }
-                            if (tty->flip.count < TTY_FLIPBUF_SIZE){
-                                tty->flip.count++;
+                            if (tty_buffer_request_room(tty, 1)) {
                                 if (data & info->read_status_mask){
                                     if(data & CyBREAK){
-                                        *tty->flip.flag_buf_ptr++ =
-	    						    TTY_BREAK;
-                                        *tty->flip.char_buf_ptr++ =
-					  cy_readb(base_addr+(CyRDSR<<index));
+                                        tty_insert_flip_char(tty, cy_readb(base_addr+(CyRDSR<<index)), TTY_BREAK);
 					info->icount.rx++;
                                         if (info->flags & ASYNC_SAK){
                                             do_SAK(tty);
                                         }
                                     }else if(data & CyFRAME){
-                                        *tty->flip.flag_buf_ptr++ =
-							    TTY_FRAME;
-                                        *tty->flip.char_buf_ptr++ =
-					  cy_readb(base_addr+(CyRDSR<<index));
+                                        tty_insert_flip_char(tty, cy_readb(base_addr+(CyRDSR<<index)), TTY_FRAME);
 					info->icount.rx++;
 					info->idle_stats.frame_errs++;
                                     }else if(data & CyPARITY){
-                                        *tty->flip.flag_buf_ptr++ =
-							    TTY_PARITY;
-                                        *tty->flip.char_buf_ptr++ =
-					  cy_readb(base_addr+(CyRDSR<<index));
+					/* Pieces of seven... */
+                                        tty_insert_flip_char(tty, cy_readb(base_addr+(CyRDSR<<index)), TTY_PARITY);
 					info->icount.rx++;
 					info->idle_stats.parity_errs++;
                                     }else if(data & CyOVERRUN){
-                                        *tty->flip.flag_buf_ptr++ =
-							    TTY_OVERRUN;
-                                        *tty->flip.char_buf_ptr++ = 0;
+                                        tty_insert_flip_char(tty, 0, TTY_OVERRUN);
 					info->icount.rx++;
                                         /* If the flip buffer itself is
                                            overflowing, we still lose
                                            the next incoming character.
                                          */
-                                        if(tty->flip.count
-					           < TTY_FLIPBUF_SIZE){
-                                            tty->flip.count++;
-                                            *tty->flip.flag_buf_ptr++ =
-							     TTY_NORMAL;
-                                           *tty->flip.char_buf_ptr++ =
-					    cy_readb(base_addr+(CyRDSR<<index));
-					    info->icount.rx++;
-                                        }
+                                        tty_insert_flip_char(tty, cy_readb(base_addr+(CyRDSR<<index)), TTY_FRAME);
+				        info->icount.rx++;
 					info->idle_stats.overruns++;
                                     /* These two conditions may imply */
                                     /* a normal read should be done. */
                                     /* }else if(data & CyTIMEOUT){ */
                                     /* }else if(data & CySPECHAR){ */
-                                    }else{
-                                        *tty->flip.flag_buf_ptr++ = 0;
-                                        *tty->flip.char_buf_ptr++ = 0;
-					info->icount.rx++;
+                                    }else {
+					tty_insert_flip_char(tty, 0, TTY_NORMAL);
+				        info->icount.rx++;
                                     }
                                 }else{
-                                    *tty->flip.flag_buf_ptr++ = 0;
-                                    *tty->flip.char_buf_ptr++ = 0;
+				    tty_insert_flip_char(tty, 0, TTY_NORMAL);
 				    info->icount.rx++;
                                 }
                             }else{
@@ -1240,14 +1221,10 @@
                                info->mon.char_max = char_count;
                             info->mon.char_last = char_count;
 #endif
-                            while(char_count--){
-                                if (tty->flip.count >= TTY_FLIPBUF_SIZE){
-                                        break;
-                                }
-                                tty->flip.count++;
+			    len = tty_buffer_request_room(tty, char_count);
+                            while(len--){
                                 data = cy_readb(base_addr+(CyRDSR<<index));
-                                *tty->flip.flag_buf_ptr++ = TTY_NORMAL;
-                                *tty->flip.char_buf_ptr++ = data;
+				tty_insert_flip_char(tty, data, TTY_NORMAL);
 				info->idle_stats.recv_bytes++;
 				info->icount.rx++;
 #ifdef CY_16Y_HACK
@@ -1256,7 +1233,7 @@
                             }
                              info->idle_stats.recv_idle = jiffies;
                         }
-                        schedule_delayed_work(&tty->flip.work, 1);
+                        schedule_delayed_work(&tty->buf.work, 1);
                     }
                     /* end of service */
                     cy_writeb(base_addr+(CyRIR<<index), (save_xir & 0x3f));
@@ -1551,6 +1528,7 @@
   struct cyclades_card *cinfo = &cy_card[info->card];
   struct tty_struct *tty = info->tty;
   volatile int char_count;
+  int len;
 #ifdef BLOCKMOVE
   int small_count;
 #else
@@ -1606,18 +1584,11 @@
 		tty->flip.count += small_count;
 	    }
 #else
-	    while(char_count--){
-		if (tty->flip.count >= N_TTY_BUF_SIZE - tty->read_cnt)
-                    break;
-
-		if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-		    break;
-
+	    len = tty_buffer_request_room(tty, char_count);
+	    while(len--){
 		data = cy_readb(cinfo->base_addr + rx_bufaddr + new_rx_get);
 		new_rx_get = (new_rx_get + 1) & (rx_bufsize - 1);
-		tty->flip.count++;
-		*tty->flip.flag_buf_ptr++ = TTY_NORMAL;
-		*tty->flip.char_buf_ptr++ = data;
+		tty_insert_flip_char(tty, data, TTY_NORMAL);
 		info->idle_stats.recv_bytes++;
 		info->icount.rx++;
 	    }
@@ -1635,7 +1606,7 @@
 	    }
 #endif
 	    info->idle_stats.recv_idle = jiffies;
-	    schedule_delayed_work(&tty->flip.work, 1);
+	    schedule_delayed_work(&tty->buf.work, 1);
 	}
 	/* Update rx_get */
 	cy_writel(&buf_ctrl->rx_get, new_rx_get);
@@ -1763,23 +1734,17 @@
 
 	switch(cmd) {
 	    case C_CM_PR_ERROR:
-		tty->flip.count++;
-		*tty->flip.flag_buf_ptr++ = TTY_PARITY;
-		*tty->flip.char_buf_ptr++ = 0;
+		tty_insert_flip_char(tty, 0, TTY_PARITY);
 		info->icount.rx++;
 		special_count++;
 		break;
 	    case C_CM_FR_ERROR:
-		tty->flip.count++;
-		*tty->flip.flag_buf_ptr++ = TTY_FRAME;
-		*tty->flip.char_buf_ptr++ = 0;
+		tty_insert_flip_char(tty, 0, TTY_FRAME);
 		info->icount.rx++;
 		special_count++;
 		break;
 	    case C_CM_RXBRK:
-		tty->flip.count++;
-		*tty->flip.flag_buf_ptr++ = TTY_BREAK;
-		*tty->flip.char_buf_ptr++ = 0;
+		tty_insert_flip_char(tty, 0, TTY_BREAK);
 		info->icount.rx++;
 		special_count++;
 		break;
@@ -1844,7 +1809,7 @@
 	if(delta_count)
 	    cy_sched_event(info, Cy_EVENT_DELTA_WAKEUP);
 	if(special_count)
-	    schedule_delayed_work(&tty->flip.work, 1);
+	    schedule_delayed_work(&tty->buf.work, 1);
     }
 }
 
diff --git a/drivers/char/drm/drm_ioc32.c b/drivers/char/drm/drm_ioc32.c
index dd91ff6..e9e2db1 100644
--- a/drivers/char/drm/drm_ioc32.c
+++ b/drivers/char/drm/drm_ioc32.c
@@ -28,7 +28,6 @@
  * IN THE SOFTWARE.
  */
 #include <linux/compat.h>
-#include <linux/ioctl32.h>
 
 #include "drmP.h"
 #include "drm_core.h"
diff --git a/drivers/char/drm/i915_ioc32.c b/drivers/char/drm/i915_ioc32.c
index 2218a94..296248c 100644
--- a/drivers/char/drm/i915_ioc32.c
+++ b/drivers/char/drm/i915_ioc32.c
@@ -30,7 +30,6 @@
  * IN THE SOFTWARE.
  */
 #include <linux/compat.h>
-#include <linux/ioctl32.h>
 
 #include "drmP.h"
 #include "drm.h"
diff --git a/drivers/char/drm/mga_ioc32.c b/drivers/char/drm/mga_ioc32.c
index 24a9d4e..54a18eb 100644
--- a/drivers/char/drm/mga_ioc32.c
+++ b/drivers/char/drm/mga_ioc32.c
@@ -31,7 +31,6 @@
  * IN THE SOFTWARE.
  */
 #include <linux/compat.h>
-#include <linux/ioctl32.h>
 
 #include "drmP.h"
 #include "drm.h"
diff --git a/drivers/char/drm/r128_ioc32.c b/drivers/char/drm/r128_ioc32.c
index 1e2e367..9dd6d41 100644
--- a/drivers/char/drm/r128_ioc32.c
+++ b/drivers/char/drm/r128_ioc32.c
@@ -30,7 +30,6 @@
  * IN THE SOFTWARE.
  */
 #include <linux/compat.h>
-#include <linux/ioctl32.h>
 
 #include "drmP.h"
 #include "drm.h"
diff --git a/drivers/char/drm/radeon_ioc32.c b/drivers/char/drm/radeon_ioc32.c
index fef4a2b..0ccfd361 100644
--- a/drivers/char/drm/radeon_ioc32.c
+++ b/drivers/char/drm/radeon_ioc32.c
@@ -28,7 +28,6 @@
  * IN THE SOFTWARE.
  */
 #include <linux/compat.h>
-#include <linux/ioctl32.h>
 
 #include "drmP.h"
 #include "drm.h"
diff --git a/drivers/char/dsp56k.c b/drivers/char/dsp56k.c
index 8693835..e233cf2 100644
--- a/drivers/char/dsp56k.c
+++ b/drivers/char/dsp56k.c
@@ -165,7 +165,7 @@
 	return 0;
 }
 
-static int dsp56k_upload(u_char *bin, int len)
+static int dsp56k_upload(u_char __user *bin, int len)
 {
 	int i;
 	u_char *p;
@@ -199,7 +199,7 @@
 	return 0;
 }
 
-static ssize_t dsp56k_read(struct file *file, char *buf, size_t count,
+static ssize_t dsp56k_read(struct file *file, char __user *buf, size_t count,
 			   loff_t *ppos)
 {
 	struct inode *inode = file->f_dentry->d_inode;
@@ -225,10 +225,10 @@
 		}
 		case 2:  /* 16 bit */
 		{
-			short *data;
+			short __user *data;
 
 			count /= 2;
-			data = (short*) buf;
+			data = (short __user *) buf;
 			handshake(count, dsp56k.maxio, dsp56k.timeout, DSP56K_RECEIVE,
 				  put_user(dsp56k_host_interface.data.w[1], data+n++));
 			return 2*n;
@@ -244,10 +244,10 @@
 		}
 		case 4:  /* 32 bit */
 		{
-			long *data;
+			long __user *data;
 
 			count /= 4;
-			data = (long*) buf;
+			data = (long __user *) buf;
 			handshake(count, dsp56k.maxio, dsp56k.timeout, DSP56K_RECEIVE,
 				  put_user(dsp56k_host_interface.data.l, data+n++));
 			return 4*n;
@@ -262,7 +262,7 @@
 	}
 }
 
-static ssize_t dsp56k_write(struct file *file, const char *buf, size_t count,
+static ssize_t dsp56k_write(struct file *file, const char __user *buf, size_t count,
 			    loff_t *ppos)
 {
 	struct inode *inode = file->f_dentry->d_inode;
@@ -287,10 +287,10 @@
 		}
 		case 2:  /* 16 bit */
 		{
-			const short *data;
+			const short __user *data;
 
 			count /= 2;
-			data = (const short *)buf;
+			data = (const short __user *)buf;
 			handshake(count, dsp56k.maxio, dsp56k.timeout, DSP56K_TRANSMIT,
 				  get_user(dsp56k_host_interface.data.w[1], data+n++));
 			return 2*n;
@@ -306,10 +306,10 @@
 		}
 		case 4:  /* 32 bit */
 		{
-			const long *data;
+			const long __user *data;
 
 			count /= 4;
-			data = (const long *)buf;
+			data = (const long __user *)buf;
 			handshake(count, dsp56k.maxio, dsp56k.timeout, DSP56K_TRANSMIT,
 				  get_user(dsp56k_host_interface.data.l, data+n++));
 			return 4*n;
@@ -328,6 +328,7 @@
 			unsigned int cmd, unsigned long arg)
 {
 	int dev = iminor(inode) & 0x0f;
+	void __user *argp = (void __user *)arg;
 
 	switch(dev)
 	{
@@ -336,9 +337,9 @@
 		switch(cmd) {
 		case DSP56K_UPLOAD:
 		{
-			char *bin;
+			char __user *bin;
 			int r, len;
-			struct dsp56k_upload *binary = (struct dsp56k_upload *) arg;
+			struct dsp56k_upload __user *binary = argp;
     
 			if(get_user(len, &binary->len) < 0)
 				return -EFAULT;
@@ -372,7 +373,7 @@
 		case DSP56K_HOST_FLAGS:
 		{
 			int dir, out, status;
-			struct dsp56k_host_flags *hf = (struct dsp56k_host_flags*) arg;
+			struct dsp56k_host_flags __user *hf = argp;
     
 			if(get_user(dir, &hf->dir) < 0)
 				return -EFAULT;
diff --git a/drivers/char/epca.c b/drivers/char/epca.c
index 407708a..765c5c1 100644
--- a/drivers/char/epca.c
+++ b/drivers/char/epca.c
@@ -1786,9 +1786,7 @@
 		if (tty)  { /* Begin if valid tty */
 			if (event & BREAK_IND)  { /* Begin if BREAK_IND */
 				/* A break has been indicated */
-				tty->flip.count++;
-				*tty->flip.flag_buf_ptr++ = TTY_BREAK;
-				*tty->flip.char_buf_ptr++ = 0;
+				tty_insert_flip_char(tty, 0, TTY_BREAK);
 				tty_schedule_flip(tty); 
 			} else if (event & LOWTX_IND)  { /* Begin LOWTX_IND */
 				if (ch->statusflags & LOWWAIT) 
@@ -2124,7 +2122,6 @@
 	int dataToRead, wrapgap, bytesAvailable;
 	unsigned int tail, head;
 	unsigned int wrapmask;
-	int rc;
 
 	/* ---------------------------------------------------------------
 		This routine is called by doint when a receive data event 
@@ -2162,16 +2159,15 @@
 		return;
 	}
 
-	if (tty->flip.count == TTY_FLIPBUF_SIZE) 
+	if (tty_buffer_request_room(tty, bytesAvailable + 1) == 0)
 		return;
 
 	if (readb(&bc->orun)) {
 		writeb(0, &bc->orun);
 		printk(KERN_WARNING "epca; overrun! DigiBoard device %s\n",tty->name);
+		tty_insert_flip_char(tty, 0, TTY_OVERRUN);
 	}
 	rxwinon(ch);
-	rptr = tty->flip.char_buf_ptr;
-	rc = tty->flip.count;
 	while (bytesAvailable > 0)  { /* Begin while there is data on the card */
 		wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
 		/* ---------------------------------------------------------------
@@ -2183,8 +2179,7 @@
 		/* --------------------------------------------------------------
 		   Make sure we don't overflow the buffer
 		----------------------------------------------------------------- */
-		if ((rc + dataToRead) > TTY_FLIPBUF_SIZE)
-			dataToRead = TTY_FLIPBUF_SIZE - rc;
+		dataToRead = tty_prepare_flip_string(tty, &rptr, dataToRead);
 		if (dataToRead == 0)
 			break;
 		/* ---------------------------------------------------------------
@@ -2192,13 +2187,9 @@
 			for translation if necessary.
 		------------------------------------------------------------------ */
 		memcpy_fromio(rptr, ch->rxptr + tail, dataToRead);
-		rc   += dataToRead;
-		rptr += dataToRead;
 		tail = (tail + dataToRead) & wrapmask;
 		bytesAvailable -= dataToRead;
 	} /* End while there is data on the card */
-	tty->flip.count = rc;
-	tty->flip.char_buf_ptr = rptr;
 	globalwinon(ch);
 	writew(tail, &bc->rout);
 	/* Must be called with global data */
diff --git a/drivers/char/esp.c b/drivers/char/esp.c
index 9f53d2fc..e469f64 100644
--- a/drivers/char/esp.c
+++ b/drivers/char/esp.c
@@ -345,26 +345,22 @@
 
 	for (i = 0; i < num_bytes; i++) {
 		if (!(err_buf->data[i] & status_mask)) {
-			*(tty->flip.char_buf_ptr++) = pio_buf->data[i];
+			int flag = 0;
 
 			if (err_buf->data[i] & 0x04) {
-				*(tty->flip.flag_buf_ptr++) = TTY_BREAK;
-
+				flag = TTY_BREAK;
 				if (info->flags & ASYNC_SAK)
 					do_SAK(tty);
 			}
 			else if (err_buf->data[i] & 0x02)
-				*(tty->flip.flag_buf_ptr++) = TTY_FRAME;
+				flag = TTY_FRAME;
 			else if (err_buf->data[i] & 0x01)
-				*(tty->flip.flag_buf_ptr++) = TTY_PARITY;
-			else
-				*(tty->flip.flag_buf_ptr++) = 0;
-		
-			tty->flip.count++;
+				flag = TTY_PARITY;
+			tty_insert_flip_char(tty, pio_buf->data[i], flag);
 		}
 	}
 
-	schedule_delayed_work(&tty->flip.work, 1);
+	schedule_delayed_work(&tty->buf.work, 1);
 
 	info->stat_flags &= ~ESP_STAT_RX_TIMEOUT;
 	release_pio_buffer(pio_buf);
@@ -397,7 +393,6 @@
 	int num_bytes;
 	unsigned long flags;
 	
-	
 	flags=claim_dma_lock();
 	disable_dma(dma);
 	clear_dma_ff(dma);
@@ -408,38 +403,31 @@
 	
 	info->icount.rx += num_bytes;
 
-	memcpy(tty->flip.char_buf_ptr, dma_buffer, num_bytes);
-	tty->flip.char_buf_ptr += num_bytes;
-	tty->flip.count += num_bytes;
-	memset(tty->flip.flag_buf_ptr, 0, num_bytes);
-	tty->flip.flag_buf_ptr += num_bytes;
-
 	if (num_bytes > 0) {
-		tty->flip.flag_buf_ptr--;
+		tty_insert_flip_string(tty, dma_buffer, num_bytes - 1);
 
 		status &= (0x1c & info->read_status_mask);
-
-		if (status & info->ignore_status_mask) {
-			tty->flip.count--;
-			tty->flip.char_buf_ptr--;
-			tty->flip.flag_buf_ptr--;
-		} else if (status & 0x10) {
-			*tty->flip.flag_buf_ptr = TTY_BREAK;
-			(info->icount.brk)++;
-			if (info->flags & ASYNC_SAK)
-				do_SAK(tty);
-		} else if (status & 0x08) {
-			*tty->flip.flag_buf_ptr = TTY_FRAME;
-			(info->icount.frame)++;
-		}
-		else if (status & 0x04) {
-			*tty->flip.flag_buf_ptr = TTY_PARITY;
-			(info->icount.parity)++;
-		}
-
-		tty->flip.flag_buf_ptr++;
 		
-		schedule_delayed_work(&tty->flip.work, 1);
+		/* Is the status significant or do we throw the last byte ? */
+		if (!(status & info->ignore_status_mask)) {
+			int statflag = 0;
+
+			if (status & 0x10) {
+				statflag = TTY_BREAK;
+				(info->icount.brk)++;
+				if (info->flags & ASYNC_SAK)
+					do_SAK(tty);
+			} else if (status & 0x08) {
+				statflag = TTY_FRAME;
+				(info->icount.frame)++;
+			}
+			else if (status & 0x04) {
+				statflag = TTY_PARITY;
+				(info->icount.parity)++;
+			}
+			tty_insert_flip_char(tty, dma_buffer[num_bytes - 1], statflag);
+		}
+		schedule_delayed_work(&tty->buf.work, 1);
 	}
 
 	if (dma_bytes != num_bytes) {
@@ -693,8 +681,7 @@
 		num_bytes = serial_in(info, UART_ESI_STAT1) << 8;
 		num_bytes |= serial_in(info, UART_ESI_STAT2);
 
-		if (num_bytes > (TTY_FLIPBUF_SIZE - info->tty->flip.count))
-		  num_bytes = TTY_FLIPBUF_SIZE - info->tty->flip.count;
+		num_bytes = tty_buffer_request_room(info->tty, num_bytes);
 
 		if (num_bytes) {
 			if (dma_bytes ||
diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c
index f921776..1994a92 100644
--- a/drivers/char/hvc_console.c
+++ b/drivers/char/hvc_console.c
@@ -597,9 +597,7 @@
 
 	/* Read data if any */
 	for (;;) {
-		int count = N_INBUF;
-		if (count > (TTY_FLIPBUF_SIZE - tty->flip.count))
-			count = TTY_FLIPBUF_SIZE - tty->flip.count;
+		int count = tty_buffer_request_room(tty, N_INBUF);
 
 		/* If flip is full, just reschedule a later read */
 		if (count == 0) {
@@ -635,7 +633,7 @@
 			tty_insert_flip_char(tty, buf[i], 0);
 		}
 
-		if (tty->flip.count)
+		if (count)
 			tty_schedule_flip(tty);
 
 		/*
diff --git a/drivers/char/hvcs.c b/drivers/char/hvcs.c
index 53dc77c..831eb4e 100644
--- a/drivers/char/hvcs.c
+++ b/drivers/char/hvcs.c
@@ -456,12 +456,11 @@
 	/* remove the read masks */
 	hvcsd->todo_mask &= ~(HVCS_READ_MASK);
 
-	if ((tty->flip.count + HVCS_BUFF_LEN) < TTY_FLIPBUF_SIZE) {
+	if (tty_buffer_request_room(tty, HVCS_BUFF_LEN) >= HVCS_BUFF_LEN) {
 		got = hvc_get_chars(unit_address,
 				&buf[0],
 				HVCS_BUFF_LEN);
-		for (i=0;got && i<got;i++)
-			tty_insert_flip_char(tty, buf[i], TTY_NORMAL);
+		tty_insert_flip_string(tty, buf, got);
 	}
 
 	/* Give the TTY time to process the data we just sent. */
@@ -469,10 +468,9 @@
 		hvcsd->todo_mask |= HVCS_QUICK_READ;
 
 	spin_unlock_irqrestore(&hvcsd->lock, flags);
-	if (tty->flip.count) {
-		/* This is synch because tty->low_latency == 1 */
+	/* This is synch because tty->low_latency == 1 */
+	if(got)
 		tty_flip_buffer_push(tty);
-	}
 
 	if (!got) {
 		/* Do this _after_ the flip_buffer_push */
diff --git a/drivers/char/hvsi.c b/drivers/char/hvsi.c
index a22aa94..a952218 100644
--- a/drivers/char/hvsi.c
+++ b/drivers/char/hvsi.c
@@ -197,7 +197,7 @@
 	};
 	const char *name = state_names[hp->state];
 
-	if (hp->state > (sizeof(state_names)/sizeof(char*)))
+	if (hp->state > ARRAY_SIZE(state_names))
 		name = "UNKNOWN";
 
 	pr_debug("hvsi%i: state = %s\n", hp->index, name);
diff --git a/drivers/char/ip2/i2lib.c b/drivers/char/ip2/i2lib.c
index ba85eb1..fc944d37 100644
--- a/drivers/char/ip2/i2lib.c
+++ b/drivers/char/ip2/i2lib.c
@@ -854,7 +854,7 @@
 		count += IBUF_SIZE;
 	}
 	// Don't give more than can be taken by the line discipline
-	amountToMove = pCh->pTTY->ldisc.receive_room( pCh->pTTY );
+	amountToMove = pCh->pTTY->receive_room;
 	if (count > amountToMove) {
 		count = amountToMove;
 	}
diff --git a/drivers/char/ip2main.c b/drivers/char/ip2main.c
index d815d19..56e93a5 100644
--- a/drivers/char/ip2main.c
+++ b/drivers/char/ip2main.c
@@ -172,7 +172,7 @@
 /* Private (static) functions */
 static int  ip2_open(PTTY, struct file *);
 static void ip2_close(PTTY, struct file *);
-static int  ip2_write(PTTY, int, const unsigned char *, int);
+static int  ip2_write(PTTY, const unsigned char *, int);
 static void ip2_putchar(PTTY, unsigned char);
 static void ip2_flush_chars(PTTY);
 static int  ip2_write_room(PTTY);
@@ -1713,7 +1713,7 @@
 /*                                                                            */
 /******************************************************************************/
 static int
-ip2_write( PTTY tty, int user, const unsigned char *pData, int count)
+ip2_write( PTTY tty, const unsigned char *pData, int count)
 {
 	i2ChanStrPtr  pCh = tty->driver_data;
 	int bytesSent = 0;
@@ -1726,7 +1726,7 @@
 
 	/* This is the actual move bit. Make sure it does what we need!!!!! */
 	WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
-	bytesSent = i2Output( pCh, pData, count, user );
+	bytesSent = i2Output( pCh, pData, count, 0 );
 	WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
 
 	ip2trace (CHANN, ITRC_WRITE, ITRC_RETURN, 1, bytesSent );
@@ -2001,7 +2001,9 @@
 static int ip2_tiocmget(struct tty_struct *tty, struct file *file)
 {
 	i2ChanStrPtr pCh = DevTable[tty->index];
+#ifdef	ENABLE_DSSNOW
 	wait_queue_t wait;
+#endif
 
 	if (pCh == NULL)
 		return -ENODEV;
@@ -2089,15 +2091,17 @@
 {
 	wait_queue_t wait;
 	i2ChanStrPtr pCh = DevTable[tty->index];
+	i2eBordStrPtr pB;
 	struct async_icount cprev, cnow;	/* kernel counter temps */
 	struct serial_icounter_struct __user *p_cuser;
 	int rc = 0;
 	unsigned long flags;
 	void __user *argp = (void __user *)arg;
 
-	if ( pCh == NULL ) {
+	if ( pCh == NULL )
 		return -ENODEV;
-	}
+
+	pB = pCh->pMyBord;
 
 	ip2trace (CHANN, ITRC_IOCTL, ITRC_ENTER, 2, cmd, arg );
 
@@ -2206,9 +2210,9 @@
 	 * for masking). Caller should use TIOCGICOUNT to see which one it was
 	 */
 	case TIOCMIWAIT:
-		save_flags(flags);cli();
+		WRITE_LOCK_IRQSAVE(&pB->read_fifo_spinlock, flags);
 		cprev = pCh->icount;	 /* note the counters on entry */
-		restore_flags(flags);
+		WRITE_UNLOCK_IRQRESTORE(&pB->read_fifo_spinlock, flags);
 		i2QueueCommands(PTYPE_BYPASS, pCh, 100, 4, 
 						CMD_DCD_REP, CMD_CTS_REP, CMD_DSR_REP, CMD_RI_REP);
 		init_waitqueue_entry(&wait, current);
@@ -2228,9 +2232,9 @@
 				rc = -ERESTARTSYS;
 				break;
 			}
-			save_flags(flags);cli();
+			WRITE_LOCK_IRQSAVE(&pB->read_fifo_spinlock, flags);
 			cnow = pCh->icount; /* atomic copy */
-			restore_flags(flags);
+			WRITE_UNLOCK_IRQRESTORE(&pB->read_fifo_spinlock, flags);
 			if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
 				cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
 				rc =  -EIO; /* no change => rc */
@@ -2268,9 +2272,9 @@
 	case TIOCGICOUNT:
 		ip2trace (CHANN, ITRC_IOCTL, 11, 1, rc );
 
-		save_flags(flags);cli();
+		WRITE_LOCK_IRQSAVE(&pB->read_fifo_spinlock, flags);
 		cnow = pCh->icount;
-		restore_flags(flags);
+		WRITE_UNLOCK_IRQRESTORE(&pB->read_fifo_spinlock, flags);
 		p_cuser = argp;
 		rc = put_user(cnow.cts, &p_cuser->cts);
 		rc = put_user(cnow.dsr, &p_cuser->dsr);
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 561430e..0097f06 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -57,6 +57,7 @@
 
 #ifdef CONFIG_PROC_FS
 struct proc_dir_entry *proc_ipmi_root = NULL;
+EXPORT_SYMBOL(proc_ipmi_root);
 #endif /* CONFIG_PROC_FS */
 
 #define MAX_EVENTS_IN_QUEUE	25
@@ -3295,6 +3296,5 @@
 EXPORT_SYMBOL(ipmi_set_my_LUN);
 EXPORT_SYMBOL(ipmi_get_my_LUN);
 EXPORT_SYMBOL(ipmi_smi_add_proc_entry);
-EXPORT_SYMBOL(proc_ipmi_root);
 EXPORT_SYMBOL(ipmi_user_set_run_to_completion);
 EXPORT_SYMBOL(ipmi_free_recv_msg);
diff --git a/drivers/char/ipmi/ipmi_poweroff.c b/drivers/char/ipmi/ipmi_poweroff.c
index e053ead..49c09ae 100644
--- a/drivers/char/ipmi/ipmi_poweroff.c
+++ b/drivers/char/ipmi/ipmi_poweroff.c
@@ -612,11 +612,14 @@
 #endif
 
 	rv = ipmi_smi_watcher_register(&smi_watcher);
+
+#ifdef CONFIG_PROC_FS
 	if (rv) {
 		unregister_sysctl_table(ipmi_table_header);
 		printk(KERN_ERR PFX "Unable to register SMI watcher: %d\n", rv);
 		goto out_err;
 	}
+#endif
 
  out_err:
 	return rv;
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index beea450..c67ef3e 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -1056,7 +1056,7 @@
 #define IPMI_MEM_ADDR_SPACE 1
 #define IPMI_IO_ADDR_SPACE  2
 
-#if defined(CONFIG_ACPI) || defined(CONFIG_X86) || defined(CONFIG_PCI)
+#if defined(CONFIG_ACPI) || defined(CONFIG_DMI) || defined(CONFIG_PCI)
 static int is_new_interface(int intf, u8 addr_space, unsigned long base_addr)
 {
 	int i;
@@ -1669,7 +1669,7 @@
 }
 #endif
 
-#ifdef CONFIG_X86
+#ifdef CONFIG_DMI
 typedef struct dmi_ipmi_data
 {
 	u8   		type;
@@ -1829,7 +1829,7 @@
 	       ipmi_data->slave_addr);
 	return 0;
 }
-#endif /* CONFIG_X86 */
+#endif /* CONFIG_DMI */
 
 #ifdef CONFIG_PCI
 
@@ -2222,7 +2222,7 @@
 	if (rv && si_trydefaults)
 		rv = try_init_acpi(intf_num, &new_smi);
 #endif
-#ifdef CONFIG_X86
+#ifdef CONFIG_DMI
 	if (rv && si_trydefaults)
 		rv = try_init_smbios(intf_num, &new_smi);
 #endif
@@ -2433,7 +2433,7 @@
 
 	printk(KERN_INFO "IPMI System Interface driver.\n");
 
-#ifdef CONFIG_X86
+#ifdef CONFIG_DMI
 	dmi_find_bmc();
 #endif
 
diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c
index 1bbf507..e9ebaba 100644
--- a/drivers/char/isicom.c
+++ b/drivers/char/isicom.c
@@ -20,7 +20,7 @@
  *	3/9/99	sameer			Added support for ISI4616 cards.
  *
  *	16/9/99	sameer			We do not force RTS low anymore.
- *					This is to prevent the firmware 
+ *					This is to prevent the firmware
  *					from getting confused.
  *
  *	26/10/99 sameer			Cosmetic changes:The driver now
@@ -31,28 +31,28 @@
  *
  *	10/5/00  sameer			Fixed isicom_shutdown_board()
  *					to not lower DTR on all the ports
- *					when the last port on the card is 
+ *					when the last port on the card is
  *					closed.
  *
  *	10/5/00  sameer			Signal mask setup command added
- *					to  isicom_setup_port and 
+ *					to  isicom_setup_port and
  *					isicom_shutdown_port.
  *
  *	24/5/00  sameer			The driver is now SMP aware.
- *					
- *	
+ *
+ *
  *	27/11/00 Vinayak P Risbud	Fixed the Driver Crash Problem
- *	
- *	
+ *
+ *
  *	03/01/01  anil .s		Added support for resetting the
  *					internal modems on ISI cards.
  *
  *	08/02/01  anil .s		Upgraded the driver for kernel
  *					2.4.x
  *
- *      11/04/01  Kevin			Fixed firmware load problem with
+ *	11/04/01  Kevin			Fixed firmware load problem with
  *					ISIHP-4X card
- *	
+ *
  *	30/04/01  anil .s		Fixed the remote login through
  *					ISI port problem. Now the link
  *					does not go down before password
@@ -62,9 +62,9 @@
  *					among ISI-PCI cards.
  *
  *	03/05/01  anil .s		Added support to display the version
- *					info during insmod as well as module 
+ *					info during insmod as well as module
  *					listing by lsmod.
- *	
+ *
  *	10/05/01  anil .s		Done the modifications to the source
  *					file and Install script so that the
  *					same installation can be used for
@@ -73,19 +73,19 @@
  *	06/06/01  anil .s		Now we drop both dtr and rts during
  *					shutdown_port as well as raise them
  *					during isicom_config_port.
- *  	
+ *
  *	09/06/01 acme@conectiva.com.br	use capable, not suser, do
  *					restore_flags on failure in
  *					isicom_send_break, verify put_user
  *					result
  *
- *  	11/02/03  ranjeeth		Added support for 230 Kbps and 460 Kbps
- *  					Baud index extended to 21
- *  	
- *  	20/03/03  ranjeeth		Made to work for Linux Advanced server.
- *  					Taken care of license warning.	
- *      
- *	10/12/03  Ravindra		Made to work for Fedora Core 1 of 
+ *	11/02/03  ranjeeth		Added support for 230 Kbps and 460 Kbps
+ *					Baud index extended to 21
+ *
+ *	20/03/03  ranjeeth		Made to work for Linux Advanced server.
+ *					Taken care of license warning.
+ *
+ *	10/12/03  Ravindra		Made to work for Fedora Core 1 of
  *					Red Hat Distribution
  *
  *	06/01/05  Alan Cox 		Merged the ISI and base kernel strands
@@ -93,10 +93,10 @@
  *
  *	***********************************************************
  *
- *	To use this driver you also need the support package. You 
+ *	To use this driver you also need the support package. You
  *	can find this in RPM format on
  *		ftp://ftp.linux.org.uk/pub/linux/alan
- * 	
+ *
  *	You can find the original tools for this direct from Multitech
  *		ftp://ftp.multitech.com/ISI-Cards/
  *
@@ -107,20 +107,20 @@
  *	Omit those entries for boards you don't have installed.
  *
  *	TODO
- *		Hotplug
  *		Merge testing
  *		64-bit verification
  */
 
 #include <linux/module.h>
+#include <linux/firmware.h>
 #include <linux/kernel.h>
 #include <linux/tty.h>
+#include <linux/tty_flip.h>
 #include <linux/termios.h>
 #include <linux/fs.h>
 #include <linux/sched.h>
 #include <linux/serial.h>
 #include <linux/mm.h>
-#include <linux/miscdevice.h>
 #include <linux/interrupt.h>
 #include <linux/timer.h>
 #include <linux/delay.h>
@@ -134,50 +134,62 @@
 
 #include <linux/isicom.h>
 
+#define InterruptTheCard(base) outw(0, (base) + 0xc)
+#define ClearInterrupt(base) inw((base) + 0x0a)
+
+#ifdef DEBUG
+#define pr_dbg(str...) printk(KERN_DEBUG "ISICOM: " str)
+#define isicom_paranoia_check(a, b, c) __isicom_paranoia_check((a), (b), (c))
+#else
+#define pr_dbg(str...) do { } while (0)
+#define isicom_paranoia_check(a, b, c) 0
+#endif
+
+static int isicom_probe(struct pci_dev *, const struct pci_device_id *);
+static void __devexit isicom_remove(struct pci_dev *);
+
 static struct pci_device_id isicom_pci_tbl[] = {
-	{ VENDOR_ID, 0x2028, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
-	{ VENDOR_ID, 0x2051, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
-	{ VENDOR_ID, 0x2052, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
-	{ VENDOR_ID, 0x2053, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
-	{ VENDOR_ID, 0x2054, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
-	{ VENDOR_ID, 0x2055, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
-	{ VENDOR_ID, 0x2056, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
-	{ VENDOR_ID, 0x2057, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
-	{ VENDOR_ID, 0x2058, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
+	{ PCI_DEVICE(VENDOR_ID, 0x2028) },
+	{ PCI_DEVICE(VENDOR_ID, 0x2051) },
+	{ PCI_DEVICE(VENDOR_ID, 0x2052) },
+	{ PCI_DEVICE(VENDOR_ID, 0x2053) },
+	{ PCI_DEVICE(VENDOR_ID, 0x2054) },
+	{ PCI_DEVICE(VENDOR_ID, 0x2055) },
+	{ PCI_DEVICE(VENDOR_ID, 0x2056) },
+	{ PCI_DEVICE(VENDOR_ID, 0x2057) },
+	{ PCI_DEVICE(VENDOR_ID, 0x2058) },
 	{ 0 }
 };
 MODULE_DEVICE_TABLE(pci, isicom_pci_tbl);
 
+static struct pci_driver isicom_driver = {
+	.name		= "isicom",
+	.id_table	= isicom_pci_tbl,
+	.probe		= isicom_probe,
+	.remove		= __devexit_p(isicom_remove)
+};
+
 static int prev_card = 3;	/*	start servicing isi_card[0]	*/
 static struct tty_driver *isicom_normal;
 
 static struct timer_list tx;
 static char re_schedule = 1;
-#ifdef ISICOM_DEBUG
-static unsigned long tx_count = 0;
-#endif
-
-static int ISILoad_ioctl(struct inode *inode, struct file *filp, unsigned  int cmd, unsigned long arg);
 
 static void isicom_tx(unsigned long _data);
-static void isicom_start(struct tty_struct * tty);
-
-static unsigned char * tmp_buf;
-static DECLARE_MUTEX(tmp_buf_sem);
+static void isicom_start(struct tty_struct *tty);
 
 /*   baud index mappings from linux defns to isi */
 
 static signed char linuxb_to_isib[] = {
-	-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 15, 16, 17,     
-	18, 19
+	-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 15, 16, 17, 18, 19
 };
 
 struct	isi_board {
-	unsigned short		base;
+	unsigned long		base;
 	unsigned char		irq;
 	unsigned char		port_count;
 	unsigned short		status;
-	unsigned short		port_status; /* each bit represents a single port */
+	unsigned short		port_status; /* each bit for each port */
 	unsigned short		shift_count;
 	struct isi_port		* ports;
 	signed char		count;
@@ -192,9 +204,9 @@
 	int			count;
 	int			blocked_open;
 	int			close_delay;
-	unsigned short		channel;
-	unsigned short		status;
-	unsigned short		closing_wait;
+	u16			channel;
+	u16			status;
+	u16			closing_wait;
 	struct isi_board	* card;
 	struct tty_struct 	* tty;
 	wait_queue_head_t	close_wait;
@@ -215,35 +227,37 @@
  *	the kernel lock for the card and have the card in a position that
  *	it wants to talk.
  */
- 
+
 static int lock_card(struct isi_board *card)
 {
 	char		retries;
-	unsigned short base = card->base;
+	unsigned long base = card->base;
 
 	for (retries = 0; retries < 100; retries++) {
 		spin_lock_irqsave(&card->card_lock, card->flags);
 		if (inw(base + 0xe) & 0x1) {
-			return 1; 
+			return 1;
 		} else {
 			spin_unlock_irqrestore(&card->card_lock, card->flags);
 			udelay(1000);   /* 1ms */
 		}
 	}
-	printk(KERN_WARNING "ISICOM: Failed to lock Card (0x%x)\n", card->base);
+	printk(KERN_WARNING "ISICOM: Failed to lock Card (0x%lx)\n",
+		card->base);
+
 	return 0;	/* Failed to aquire the card! */
 }
 
 static int lock_card_at_interrupt(struct isi_board *card)
 {
 	unsigned char		retries;
-	unsigned short 		base = card->base;
+	unsigned long base = card->base;
 
 	for (retries = 0; retries < 200; retries++) {
 		spin_lock_irqsave(&card->card_lock, card->flags);
 
 		if (inw(base + 0xe) & 0x1)
-			return 1; 
+			return 1;
 		else
 			spin_unlock_irqrestore(&card->card_lock, card->flags);
 	}
@@ -259,373 +273,141 @@
 /*
  *  ISI Card specific ops ...
  */
- 
-static void raise_dtr(struct isi_port * port)
+
+static void raise_dtr(struct isi_port *port)
 {
-	struct isi_board * card = port->card;
-	unsigned short base = card->base;
-	unsigned char channel = port->channel;
+	struct isi_board *card = port->card;
+	unsigned long base = card->base;
+	u16 channel = port->channel;
 
 	if (!lock_card(card))
 		return;
 
-	outw(0x8000 | (channel << card->shift_count) | 0x02 , base);
+	outw(0x8000 | (channel << card->shift_count) | 0x02, base);
 	outw(0x0504, base);
 	InterruptTheCard(base);
 	port->status |= ISI_DTR;
 	unlock_card(card);
 }
 
-static inline void drop_dtr(struct isi_port * port)
-{	
-	struct isi_board * card = port->card;
-	unsigned short base = card->base;
-	unsigned char channel = port->channel;
+static inline void drop_dtr(struct isi_port *port)
+{
+	struct isi_board *card = port->card;
+	unsigned long base = card->base;
+	u16 channel = port->channel;
 
 	if (!lock_card(card))
 		return;
 
-	outw(0x8000 | (channel << card->shift_count) | 0x02 , base);
+	outw(0x8000 | (channel << card->shift_count) | 0x02, base);
 	outw(0x0404, base);
-	InterruptTheCard(base);	
+	InterruptTheCard(base);
 	port->status &= ~ISI_DTR;
 	unlock_card(card);
 }
 
-static inline void raise_rts(struct isi_port * port)
+static inline void raise_rts(struct isi_port *port)
 {
-	struct isi_board * card = port->card;
-	unsigned short base = card->base;
-	unsigned char channel = port->channel;
+	struct isi_board *card = port->card;
+	unsigned long base = card->base;
+	u16 channel = port->channel;
 
 	if (!lock_card(card))
 		return;
 
-	outw(0x8000 | (channel << card->shift_count) | 0x02 , base);
+	outw(0x8000 | (channel << card->shift_count) | 0x02, base);
 	outw(0x0a04, base);
-	InterruptTheCard(base);	
+	InterruptTheCard(base);
 	port->status |= ISI_RTS;
 	unlock_card(card);
 }
-static inline void drop_rts(struct isi_port * port)
+static inline void drop_rts(struct isi_port *port)
 {
-	struct isi_board * card = port->card;
-	unsigned short base = card->base;
-	unsigned char channel = port->channel;
+	struct isi_board *card = port->card;
+	unsigned long base = card->base;
+	u16 channel = port->channel;
 
 	if (!lock_card(card))
 		return;
 
-	outw(0x8000 | (channel << card->shift_count) | 0x02 , base);
+	outw(0x8000 | (channel << card->shift_count) | 0x02, base);
 	outw(0x0804, base);
-	InterruptTheCard(base);	
+	InterruptTheCard(base);
 	port->status &= ~ISI_RTS;
 	unlock_card(card);
 }
 
-static inline void raise_dtr_rts(struct isi_port * port)
+static inline void raise_dtr_rts(struct isi_port *port)
 {
-	struct isi_board * card = port->card;
-	unsigned short base = card->base;
-	unsigned char channel = port->channel;
+	struct isi_board *card = port->card;
+	unsigned long base = card->base;
+	u16 channel = port->channel;
 
 	if (!lock_card(card))
 		return;
 
-	outw(0x8000 | (channel << card->shift_count) | 0x02 , base);
+	outw(0x8000 | (channel << card->shift_count) | 0x02, base);
 	outw(0x0f04, base);
 	InterruptTheCard(base);
 	port->status |= (ISI_DTR | ISI_RTS);
 	unlock_card(card);
 }
 
-static void drop_dtr_rts(struct isi_port * port)
+static void drop_dtr_rts(struct isi_port *port)
 {
-	struct isi_board * card = port->card;
-	unsigned short base = card->base;
-	unsigned char channel = port->channel;
+	struct isi_board *card = port->card;
+	unsigned long base = card->base;
+	u16 channel = port->channel;
 
 	if (!lock_card(card))
 		return;
 
-	outw(0x8000 | (channel << card->shift_count) | 0x02 , base);
+	outw(0x8000 | (channel << card->shift_count) | 0x02, base);
 	outw(0x0c04, base);
-	InterruptTheCard(base);	
+	InterruptTheCard(base);
 	port->status &= ~(ISI_RTS | ISI_DTR);
 	unlock_card(card);
 }
 
-static inline void kill_queue(struct isi_port * port, short queue)
+static inline void kill_queue(struct isi_port *port, short queue)
 {
-	struct isi_board * card = port->card;
-	unsigned short base = card->base;
-	unsigned char channel = port->channel;
+	struct isi_board *card = port->card;
+	unsigned long base = card->base;
+	u16 channel = port->channel;
 
 	if (!lock_card(card))
 		return;
 
-	outw(0x8000 | (channel << card->shift_count) | 0x02 , base);
+	outw(0x8000 | (channel << card->shift_count) | 0x02, base);
 	outw((queue << 8) | 0x06, base);
-	InterruptTheCard(base);	
+	InterruptTheCard(base);
 	unlock_card(card);
 }
 
-
-/* 
- *  Firmware loader driver specific routines. This needs to mostly die
- *  and be replaced with request_firmware.
- */
-
-static struct file_operations ISILoad_fops = {
-	.owner		= THIS_MODULE,
-	.ioctl		= ISILoad_ioctl,
-};
-
-static struct miscdevice isiloader_device = {
-	ISILOAD_MISC_MINOR, "isictl", &ISILoad_fops
-};
-
- 
-static inline int WaitTillCardIsFree(unsigned short base)
-{
-	unsigned long count=0;
-	while( (!(inw(base+0xe) & 0x1)) && (count++ < 6000000));
-	if (inw(base+0xe)&0x1)  
-		return 0;
-	else
-		return 1;
-}
-
-static int ISILoad_ioctl(struct inode *inode, struct file *filp,
-		         unsigned int cmd, unsigned long arg)
-{
-	unsigned int card, i, j, signature, status, portcount = 0;
-	unsigned long t;
-	unsigned short word_count, base;
-	bin_frame frame;
-	void __user *argp = (void __user *)arg;
-	/* exec_record exec_rec; */
-	
-	if(get_user(card, (int __user *)argp))
-		return -EFAULT;
-		
-	if(card < 0 || card >= BOARD_COUNT)
-		return -ENXIO;
-		
-	base=isi_card[card].base;
-	
-	if(base==0)
-		return -ENXIO;	/* disabled or not used */
-	
-	switch(cmd) {
-		case MIOCTL_RESET_CARD:
-			if (!capable(CAP_SYS_ADMIN))
-				return -EPERM;
-			printk(KERN_DEBUG "ISILoad:Resetting Card%d at 0x%x ",card+1,base);
-								
-			inw(base+0x8);
-			
-			for(t=jiffies+HZ/100;time_before(jiffies, t););
-				
-			outw(0,base+0x8); /* Reset */
-			
-			for(j=1;j<=3;j++) {
-				for(t=jiffies+HZ;time_before(jiffies, t););
-				printk(".");
-			}	
-			signature=(inw(base+0x4)) & 0xff;	
-			if (isi_card[card].isa) {
-					
-				if (!(inw(base+0xe) & 0x1) || (inw(base+0x2))) {
-#ifdef ISICOM_DEBUG				
-					printk("\nbase+0x2=0x%x , base+0xe=0x%x",inw(base+0x2),inw(base+0xe));
-#endif				
-					printk("\nISILoad:ISA Card%d reset failure (Possible bad I/O Port Address 0x%x).\n",card+1,base);
-					return -EIO;					
-				}
-			}	
-			else {
-				portcount = inw(base+0x2);
-				if (!(inw(base+0xe) & 0x1) || ((portcount!=0) && (portcount!=4) && (portcount!=8))) {	
-#ifdef ISICOM_DEBUG
-					printk("\nbase+0x2=0x%x , base+0xe=0x%x",inw(base+0x2),inw(base+0xe));
-#endif
-					printk("\nISILoad:PCI Card%d reset failure (Possible bad I/O Port Address 0x%x).\n",card+1,base);
-					return -EIO;
-				}
-			}	
-			switch(signature) {
-			case	0xa5:
-			case	0xbb:
-			case	0xdd:	
-					if (isi_card[card].isa) 
-						isi_card[card].port_count = 8;
-					else {
-						if (portcount == 4)
-							isi_card[card].port_count = 4;
-						else
-							isi_card[card].port_count = 8;
-					}	
-				     	isi_card[card].shift_count = 12;
-				     	break;
-				        
-			case	0xcc:	isi_card[card].port_count = 16;
-					isi_card[card].shift_count = 11;
-					break;  			
-					
-			default: printk("ISILoad:Card%d reset failure (Possible bad I/O Port Address 0x%x).\n",card+1,base);
-#ifdef ISICOM_DEBUG			
-				 printk("Sig=0x%x\n",signature);
-#endif				 
-				 return -EIO;
-			}
-			printk("-Done\n");
-			return put_user(signature,(unsigned __user *)argp);
-						
-	case	MIOCTL_LOAD_FIRMWARE:
-			if (!capable(CAP_SYS_ADMIN))
-				return -EPERM;
-				
-			if(copy_from_user(&frame, argp, sizeof(bin_frame)))
-				return -EFAULT;
-			
-			if (WaitTillCardIsFree(base))
-				return -EIO;
-			
-			outw(0xf0,base);	/* start upload sequence */ 
-			outw(0x00,base);
-			outw((frame.addr), base);/*      lsb of adderess    */
-			
-			word_count=(frame.count >> 1) + frame.count % 2;
-			outw(word_count, base);
-			InterruptTheCard(base);
-			
-			for(i=0;i<=0x2f;i++);	/* a wee bit of delay */
-			
-			if (WaitTillCardIsFree(base)) 
-				return -EIO;
-				
-			if ((status=inw(base+0x4))!=0) {
-				printk(KERN_WARNING "ISILoad:Card%d rejected load header:\nAddress:0x%x \nCount:0x%x \nStatus:0x%x \n", 
-				card+1, frame.addr, frame.count, status);
-				return -EIO;
-			}
-			outsw(base, (void *) frame.bin_data, word_count);
-			
-			InterruptTheCard(base);
-			
-			for(i=0;i<=0x0f;i++);	/* another wee bit of delay */ 
-			
-			if (WaitTillCardIsFree(base)) 
-				return -EIO;
-				
-			if ((status=inw(base+0x4))!=0) {
-				printk(KERN_ERR "ISILoad:Card%d got out of sync.Card Status:0x%x\n",card+1, status);
-				return -EIO;
-			}	
-			return 0;
-						
-	case	MIOCTL_READ_FIRMWARE:
-			if (!capable(CAP_SYS_ADMIN))
-				return -EPERM;
-				
-			if(copy_from_user(&frame, argp, sizeof(bin_header)))
-				return -EFAULT;
-			
-			if (WaitTillCardIsFree(base))
-				return -EIO;
-			
-			outw(0xf1,base);	/* start download sequence */ 
-			outw(0x00,base);
-			outw((frame.addr), base);/*      lsb of adderess    */
-			
-			word_count=(frame.count >> 1) + frame.count % 2;
-			outw(word_count+1, base);
-			InterruptTheCard(base);
-			
-			for(i=0;i<=0xf;i++);	/* a wee bit of delay */
-			
-			if (WaitTillCardIsFree(base)) 
-				return -EIO;
-				
-			if ((status=inw(base+0x4))!=0) {
-				printk(KERN_WARNING "ISILoad:Card%d rejected verify header:\nAddress:0x%x \nCount:0x%x \nStatus:0x%x \n", 
-				card+1, frame.addr, frame.count, status);
-				return -EIO;
-			}
-			
-			inw(base);
-			insw(base, frame.bin_data, word_count);
-			InterruptTheCard(base);
-			
-			for(i=0;i<=0x0f;i++);	/* another wee bit of delay */ 
-			
-			if (WaitTillCardIsFree(base)) 
-				return -EIO;
-				
-			if ((status=inw(base+0x4))!=0) {
-				printk(KERN_ERR "ISILoad:Card%d verify got out of sync.Card Status:0x%x\n",card+1, status);
-				return -EIO;
-			}	
-			
-			if(copy_to_user(argp, &frame, sizeof(bin_frame)))
-				return -EFAULT;
-			return 0;
-	
-	case	MIOCTL_XFER_CTRL:
-			if (!capable(CAP_SYS_ADMIN))
-				return -EPERM;
-			if (WaitTillCardIsFree(base)) 
-				return -EIO;
-					
-			outw(0xf2, base);
-			outw(0x800, base);
-			outw(0x0, base);
-			outw(0x0, base);
-			InterruptTheCard(base);
-			outw(0x0, base+0x4);    /* for ISI4608 cards */
-							
-			isi_card[card].status |= FIRMWARE_LOADED;
-			return 0;	
-			
-	default:
-#ifdef ISICOM_DEBUG	
-		printk(KERN_DEBUG "ISILoad: Received Ioctl cmd 0x%x.\n", cmd); 
-#endif
-		return -ENOIOCTLCMD;
-	
-	}
-	
-}
-		        	
-
 /*
  *	ISICOM Driver specific routines ...
  *
  */
- 
-static inline int isicom_paranoia_check(struct isi_port const * port, char *name, 
-					const char * routine)
+
+static inline int __isicom_paranoia_check(struct isi_port const *port,
+	char *name, const char *routine)
 {
-#ifdef ISICOM_DEBUG 
-	static const char * badmagic = 
-			KERN_WARNING "ISICOM: Warning: bad isicom magic for dev %s in %s.\n";
-	static const char * badport = 
-			KERN_WARNING "ISICOM: Warning: NULL isicom port for dev %s in %s.\n";		
 	if (!port) {
-		printk(badport, name, routine);
+		printk(KERN_WARNING "ISICOM: Warning: bad isicom magic for "
+			"dev %s in %s.\n", name, routine);
 		return 1;
 	}
 	if (port->magic != ISICOM_MAGIC) {
-		printk(badmagic, name, routine);
+		printk(KERN_WARNING "ISICOM: Warning: NULL isicom port for "
+			"dev %s in %s.\n", name, routine);
 		return 1;
-	}	
-#endif	
+	}
+
 	return 0;
 }
-			
+
 /*
- *	Transmitter. 
+ *	Transmitter.
  *
  *	We shovel data into the card buffers on a regular basis. The card
  *	will do the rest of the work for us.
@@ -635,25 +417,21 @@
 {
 	short count = (BOARD_COUNT-1), card, base;
 	short txcount, wrd, residue, word_count, cnt;
-	struct isi_port * port;
-	struct tty_struct * tty;
-	
-#ifdef ISICOM_DEBUG
-	++tx_count;
-#endif	
-	
+	struct isi_port *port;
+	struct tty_struct *tty;
+
 	/*	find next active board	*/
 	card = (prev_card + 1) & 0x0003;
 	while(count-- > 0) {
-		if (isi_card[card].status & BOARD_ACTIVE) 
+		if (isi_card[card].status & BOARD_ACTIVE)
 			break;
-		card = (card + 1) & 0x0003;	
+		card = (card + 1) & 0x0003;
 	}
 	if (!(isi_card[card].status & BOARD_ACTIVE))
 		goto sched_again;
-		
+
 	prev_card = card;
-	
+
 	count = isi_card[card].port_count;
 	port = isi_card[card].ports;
 	base = isi_card[card].base;
@@ -662,18 +440,18 @@
 			continue;
 		/* port not active or tx disabled to force flow control */
 		if (!(port->flags & ASYNC_INITIALIZED) ||
-		 	!(port->status & ISI_TXOK))
+				!(port->status & ISI_TXOK))
 			unlock_card(&isi_card[card]);
 			continue;
-		
+
 		tty = port->tty;
-		
-		
-		if(tty == NULL) {
+
+
+		if (tty == NULL) {
 			unlock_card(&isi_card[card]);
 			continue;
 		}
-		
+
 		txcount = min_t(short, TX_SIZE, port->xmit_cnt);
 		if (txcount <= 0 || tty->stopped || tty->hw_stopped) {
 			unlock_card(&isi_card[card]);
@@ -681,44 +459,45 @@
 		}
 		if (!(inw(base + 0x02) & (1 << port->channel))) {
 			unlock_card(&isi_card[card]);
-			continue;		
+			continue;
 		}
-#ifdef ISICOM_DEBUG
-		printk(KERN_DEBUG "ISICOM: txing %d bytes, port%d.\n", 
-				txcount, port->channel+1); 
-#endif	
-		outw((port->channel << isi_card[card].shift_count) | txcount
-					, base);
+		pr_dbg("txing %d bytes, port%d.\n", txcount,
+			port->channel + 1);
+		outw((port->channel << isi_card[card].shift_count) | txcount,
+			base);
 		residue = NO;
-		wrd = 0;			
+		wrd = 0;
 		while (1) {
-			cnt = min_t(int, txcount, (SERIAL_XMIT_SIZE - port->xmit_tail));
+			cnt = min_t(int, txcount, (SERIAL_XMIT_SIZE
+					- port->xmit_tail));
 			if (residue == YES) {
 				residue = NO;
 				if (cnt > 0) {
-					wrd |= (port->xmit_buf[port->xmit_tail] << 8);
-					port->xmit_tail = (port->xmit_tail + 1) & (SERIAL_XMIT_SIZE - 1);
+					wrd |= (port->xmit_buf[port->xmit_tail]
+									<< 8);
+					port->xmit_tail = (port->xmit_tail + 1)
+						& (SERIAL_XMIT_SIZE - 1);
 					port->xmit_cnt--;
 					txcount--;
 					cnt--;
-					outw(wrd, base);			
-				}
-				else {
+					outw(wrd, base);
+				} else {
 					outw(wrd, base);
 					break;
 				}
-			}		
+			}
 			if (cnt <= 0) break;
 			word_count = cnt >> 1;
-			outsw(base, port->xmit_buf+port->xmit_tail, word_count);
-			port->xmit_tail = (port->xmit_tail + (word_count << 1)) &
-						(SERIAL_XMIT_SIZE - 1);
+			outsw(base, port->xmit_buf+port->xmit_tail,word_count);
+			port->xmit_tail = (port->xmit_tail
+				+ (word_count << 1)) & (SERIAL_XMIT_SIZE - 1);
 			txcount -= (word_count << 1);
 			port->xmit_cnt -= (word_count << 1);
 			if (cnt & 0x0001) {
 				residue = YES;
 				wrd = port->xmit_buf[port->xmit_tail];
-				port->xmit_tail = (port->xmit_tail + 1) & (SERIAL_XMIT_SIZE - 1);
+				port->xmit_tail = (port->xmit_tail + 1)
+					& (SERIAL_XMIT_SIZE - 1);
 				port->xmit_cnt--;
 				txcount--;
 			}
@@ -730,81 +509,82 @@
 		if (port->xmit_cnt <= WAKEUP_CHARS)
 			schedule_work(&port->bh_tqueue);
 		unlock_card(&isi_card[card]);
-	}	
+	}
 
-	/*	schedule another tx for hopefully in about 10ms	*/	
-sched_again:	
-	if (!re_schedule)	
-		return;
+	/*	schedule another tx for hopefully in about 10ms	*/
+sched_again:
+	if (!re_schedule) {
+		re_schedule = 2;
+ 		return;
+	}
+
 	init_timer(&tx);
 	tx.expires = jiffies + HZ/100;
 	tx.data = 0;
 	tx.function = isicom_tx;
 	add_timer(&tx);
-	
-	return;	
-}		
- 
+
+	return;
+}
+
 /* 	Interrupt handlers 	*/
 
- 
-static void isicom_bottomhalf(void * data)
+
+static void isicom_bottomhalf(void *data)
 {
-	struct isi_port * port = (struct isi_port *) data;
-	struct tty_struct * tty = port->tty;
-	
+	struct isi_port *port = (struct isi_port *) data;
+	struct tty_struct *tty = port->tty;
+
 	if (!tty)
 		return;
 
-	tty_wakeup(tty);	
+	tty_wakeup(tty);
 	wake_up_interruptible(&tty->write_wait);
-} 		
- 		
+}
+
 /*
- *	Main interrupt handler routine 
+ *	Main interrupt handler routine
  */
- 
-static irqreturn_t isicom_interrupt(int irq, void *dev_id,
-					struct pt_regs *regs)
+
+static irqreturn_t isicom_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 {
-	struct isi_board * card;
-	struct isi_port * port;
-	struct tty_struct * tty;
-	unsigned short base, header, word_count, count;
-	unsigned char channel;
+	struct isi_board *card = dev_id;
+	struct isi_port *port;
+	struct tty_struct *tty;
+	unsigned long base;
+	u16 header, word_count, count, channel;
 	short byte_count;
-	
-	card = (struct isi_board *) dev_id;
+	unsigned char *rp;
 
 	if (!card || !(card->status & FIRMWARE_LOADED))
 		return IRQ_NONE;
-	
+
 	base = card->base;
 	spin_lock(&card->card_lock);
-	
+
 	if (card->isa == NO) {
 		/*
-		 *      disable any interrupts from the PCI card and lower the
-		 *      interrupt line
+		 * disable any interrupts from the PCI card and lower the
+		 * interrupt line
 		 */
 		outw(0x8000, base+0x04);
 		ClearInterrupt(base);
 	}
-	
+
 	inw(base);		/* get the dummy word out */
 	header = inw(base);
 	channel = (header & 0x7800) >> card->shift_count;
 	byte_count = header & 0xff;
 
 	if (channel + 1 > card->port_count) {
-		printk(KERN_WARNING "ISICOM: isicom_interrupt(0x%x): %d(channel) > port_count.\n",
-				base, channel+1);
+		printk(KERN_WARNING "ISICOM: isicom_interrupt(0x%lx): "
+			"%d(channel) > port_count.\n", base, channel+1);
 		if (card->isa)
 			ClearInterrupt(base);
 		else
-			outw(0x0000, base+0x04); /* enable interrupts */		
+			outw(0x0000, base+0x04); /* enable interrupts */
 		spin_unlock(&card->card_lock);
-		return IRQ_HANDLED;			
+		return IRQ_HANDLED;
 	}
 	port = card->ports + channel;
 	if (!(port->flags & ASYNC_INITIALIZED)) {
@@ -813,8 +593,8 @@
 		else
 			outw(0x0000, base+0x04); /* enable interrupts */
 		return IRQ_HANDLED;
-	}	
-		
+	}
+
 	tty = port->tty;
 	if (tty == NULL) {
 		word_count = byte_count >> 1;
@@ -831,224 +611,204 @@
 		spin_unlock(&card->card_lock);
 		return IRQ_HANDLED;
 	}
-	
+
 	if (header & 0x8000) {		/* Status Packet */
 		header = inw(base);
 		switch(header & 0xff) {
-			case 0:	/* Change in EIA signals */
-				
-				if (port->flags & ASYNC_CHECK_CD) {
-					if (port->status & ISI_DCD) {
-						if (!(header & ISI_DCD)) {
-						/* Carrier has been lost  */
-#ifdef ISICOM_DEBUG						
-							printk(KERN_DEBUG "ISICOM: interrupt: DCD->low.\n");
-#endif							
-							port->status &= ~ISI_DCD;
-							schedule_work(&port->hangup_tq);
-						}
-					}
-					else {
-						if (header & ISI_DCD) {
-						/* Carrier has been detected */
-#ifdef ISICOM_DEBUG
-							printk(KERN_DEBUG "ISICOM: interrupt: DCD->high.\n");
-#endif							
-							port->status |= ISI_DCD;
-							wake_up_interruptible(&port->open_wait);
-						}
-					}
-				}
-				else {
-					if (header & ISI_DCD) 
-						port->status |= ISI_DCD;
-					else
+		case 0:	/* Change in EIA signals */
+			if (port->flags & ASYNC_CHECK_CD) {
+				if (port->status & ISI_DCD) {
+					if (!(header & ISI_DCD)) {
+					/* Carrier has been lost  */
+						pr_dbg("interrupt: DCD->low.\n"
+							);
 						port->status &= ~ISI_DCD;
-				}	
-				
-				if (port->flags & ASYNC_CTS_FLOW) {
-					if (port->tty->hw_stopped) {
-						if (header & ISI_CTS) {
-							port->tty->hw_stopped = 0;
-							/* start tx ing */
-							port->status |= (ISI_TXOK | ISI_CTS);
-							schedule_work(&port->bh_tqueue);
-						}
+						schedule_work(&port->hangup_tq);
 					}
-					else {
-						if (!(header & ISI_CTS)) {
-							port->tty->hw_stopped = 1;
-							/* stop tx ing */
-							port->status &= ~(ISI_TXOK | ISI_CTS);
-						}
+				} else if (header & ISI_DCD) {
+				/* Carrier has been detected */
+					pr_dbg("interrupt: DCD->high.\n");
+					port->status |= ISI_DCD;
+					wake_up_interruptible(&port->open_wait);
+				}
+			} else {
+				if (header & ISI_DCD)
+					port->status |= ISI_DCD;
+				else
+					port->status &= ~ISI_DCD;
+			}
+
+			if (port->flags & ASYNC_CTS_FLOW) {
+				if (port->tty->hw_stopped) {
+					if (header & ISI_CTS) {
+						port->tty->hw_stopped = 0;
+						/* start tx ing */
+						port->status |= (ISI_TXOK
+							| ISI_CTS);
+						schedule_work(&port->bh_tqueue);
 					}
+				} else if (!(header & ISI_CTS)) {
+					port->tty->hw_stopped = 1;
+					/* stop tx ing */
+					port->status &= ~(ISI_TXOK | ISI_CTS);
 				}
-				else {
-					if (header & ISI_CTS) 
-						port->status |= ISI_CTS;
-					else
-						port->status &= ~ISI_CTS;
-				}
-				
-				if (header & ISI_DSR) 
-					port->status |= ISI_DSR;
+			} else {
+				if (header & ISI_CTS)
+					port->status |= ISI_CTS;
 				else
-					port->status &= ~ISI_DSR;
-				
-				if (header & ISI_RI) 
-					port->status |= ISI_RI;
-				else
-					port->status &= ~ISI_RI;						
-				
-				break;
-				
-			case 1:	/* Received Break !!!	 */
-				if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-					break;
-				*tty->flip.flag_buf_ptr++ = TTY_BREAK;
-				*tty->flip.char_buf_ptr++ = 0;
-				tty->flip.count++;
-				if (port->flags & ASYNC_SAK)
-					do_SAK(tty);
-				schedule_delayed_work(&tty->flip.work, 1);
-				break;
-				
-			case 2:	/* Statistics		 */
-				printk(KERN_DEBUG "ISICOM: isicom_interrupt: stats!!!.\n");			
-				break;
-				
-			default:
-				printk(KERN_WARNING "ISICOM: Intr: Unknown code in status packet.\n");
-				break;
-		}	 
-	}
-	else {				/* Data   Packet */
-		count = min_t(unsigned short, byte_count, (TTY_FLIPBUF_SIZE - tty->flip.count));
-#ifdef ISICOM_DEBUG
-		printk(KERN_DEBUG "ISICOM: Intr: Can rx %d of %d bytes.\n", 
-					count, byte_count);
-#endif			
+					port->status &= ~ISI_CTS;
+			}
+
+			if (header & ISI_DSR)
+				port->status |= ISI_DSR;
+			else
+				port->status &= ~ISI_DSR;
+
+			if (header & ISI_RI)
+				port->status |= ISI_RI;
+			else
+				port->status &= ~ISI_RI;
+
+			break;
+
+		case 1:	/* Received Break !!! */
+			tty_insert_flip_char(tty, 0, TTY_BREAK);
+			if (port->flags & ASYNC_SAK)
+				do_SAK(tty);
+			tty_flip_buffer_push(tty);
+			break;
+
+		case 2:	/* Statistics		 */
+			pr_dbg("isicom_interrupt: stats!!!.\n");
+			break;
+
+		default:
+			pr_dbg("Intr: Unknown code in status packet.\n");
+			break;
+		}
+	} else {				/* Data   Packet */
+
+		count = tty_prepare_flip_string(tty, &rp, byte_count & ~1);
+		pr_dbg("Intr: Can rx %d of %d bytes.\n", count, byte_count);
 		word_count = count >> 1;
-		insw(base, tty->flip.char_buf_ptr, word_count);
-		tty->flip.char_buf_ptr += (word_count << 1);		
+		insw(base, rp, word_count);
 		byte_count -= (word_count << 1);
 		if (count & 0x0001) {
-			*tty->flip.char_buf_ptr++ = (char)(inw(base) & 0xff);
+			tty_insert_flip_char(tty,  inw(base) & 0xff,
+				TTY_NORMAL);
 			byte_count -= 2;
-		}	
-		memset(tty->flip.flag_buf_ptr, 0, count);
-		tty->flip.flag_buf_ptr += count;
-		tty->flip.count += count;
-		
+		}
 		if (byte_count > 0) {
-			printk(KERN_DEBUG "ISICOM: Intr(0x%x:%d): Flip buffer overflow! dropping bytes...\n",
-					base, channel+1);
+			pr_dbg("Intr(0x%lx:%d): Flip buffer overflow! dropping "
+				"bytes...\n", base, channel + 1);
 			while(byte_count > 0) { /* drain out unread xtra data */
 				inw(base);
 				byte_count -= 2;
 			}
 		}
-		schedule_delayed_work(&tty->flip.work, 1);
+		tty_flip_buffer_push(tty);
 	}
 	if (card->isa == YES)
 		ClearInterrupt(base);
 	else
-		outw(0x0000, base+0x04); /* enable interrupts */	
-	return IRQ_HANDLED;
-} 
+		outw(0x0000, base+0x04); /* enable interrupts */
 
-static void isicom_config_port(struct isi_port * port)
+	return IRQ_HANDLED;
+}
+
+static void isicom_config_port(struct isi_port *port)
 {
-	struct isi_board * card = port->card;
-	struct tty_struct * tty;
+	struct isi_board *card = port->card;
+	struct tty_struct *tty;
 	unsigned long baud;
-	unsigned short channel_setup, base = card->base;
-	unsigned short channel = port->channel, shift_count = card->shift_count;
+	unsigned long base = card->base;
+	u16 channel_setup, channel = port->channel,
+		shift_count = card->shift_count;
 	unsigned char flow_ctrl;
-	
+
 	if (!(tty = port->tty) || !tty->termios)
 		return;
 	baud = C_BAUD(tty);
 	if (baud & CBAUDEX) {
 		baud &= ~CBAUDEX;
-		
+
 		/*  if CBAUDEX bit is on and the baud is set to either 50 or 75
 		 *  then the card is programmed for 57.6Kbps or 115Kbps
 		 *  respectively.
-		 */   
-		 
+		 */
+
 		if (baud < 1 || baud > 2)
 			port->tty->termios->c_cflag &= ~CBAUDEX;
 		else
 			baud += 15;
-	}	
+	}
 	if (baud == 15) {
-	
-		/*  the ASYNC_SPD_HI and ASYNC_SPD_VHI options are set 
+
+		/*  the ASYNC_SPD_HI and ASYNC_SPD_VHI options are set
 		 *  by the set_serial_info ioctl ... this is done by
 		 *  the 'setserial' utility.
-		 */  
-			
+		 */
+
 		if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
-			baud++;     /*  57.6 Kbps */
+			baud++; /*  57.6 Kbps */
 		if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
-			baud +=2;   /*  115  Kbps */	 
+			baud +=2; /*  115  Kbps */
 	}
 	if (linuxb_to_isib[baud] == -1) {
 		/* hang up */
-	 	drop_dtr(port);
-	 	return;
-	}	
-	else  
+		drop_dtr(port);
+		return;
+	}
+	else
 		raise_dtr(port);
-		
+
 	if (lock_card(card)) {
 		outw(0x8000 | (channel << shift_count) |0x03, base);
 		outw(linuxb_to_isib[baud] << 8 | 0x03, base);
 		channel_setup = 0;
 		switch(C_CSIZE(tty)) {
-			case CS5:
-				channel_setup |= ISICOM_CS5;
-				break;
-			case CS6:
-				channel_setup |= ISICOM_CS6;
-				break;
-			case CS7:
-				channel_setup |= ISICOM_CS7;
-				break;
-			case CS8:
-				channel_setup |= ISICOM_CS8;
-				break;
+		case CS5:
+			channel_setup |= ISICOM_CS5;
+			break;
+		case CS6:
+			channel_setup |= ISICOM_CS6;
+			break;
+		case CS7:
+			channel_setup |= ISICOM_CS7;
+			break;
+		case CS8:
+			channel_setup |= ISICOM_CS8;
+			break;
 		}
-			
+
 		if (C_CSTOPB(tty))
 			channel_setup |= ISICOM_2SB;
 		if (C_PARENB(tty)) {
 			channel_setup |= ISICOM_EVPAR;
 			if (C_PARODD(tty))
-				channel_setup |= ISICOM_ODPAR;	
+				channel_setup |= ISICOM_ODPAR;
 		}
-		outw(channel_setup, base);	
+		outw(channel_setup, base);
 		InterruptTheCard(base);
-		unlock_card(card);	
-	}	
+		unlock_card(card);
+	}
 	if (C_CLOCAL(tty))
 		port->flags &= ~ASYNC_CHECK_CD;
 	else
-		port->flags |= ASYNC_CHECK_CD;	
-	
+		port->flags |= ASYNC_CHECK_CD;
+
 	/* flow control settings ...*/
 	flow_ctrl = 0;
 	port->flags &= ~ASYNC_CTS_FLOW;
 	if (C_CRTSCTS(tty)) {
 		port->flags |= ASYNC_CTS_FLOW;
 		flow_ctrl |= ISICOM_CTSRTS;
-	}	
-	if (I_IXON(tty))	
+	}
+	if (I_IXON(tty))
 		flow_ctrl |= ISICOM_RESPOND_XONXOFF;
 	if (I_IXOFF(tty))
-		flow_ctrl |= ISICOM_INITIATE_XONXOFF;	
-		
+		flow_ctrl |= ISICOM_INITIATE_XONXOFF;
+
 	if (lock_card(card)) {
 		outw(0x8000 | (channel << shift_count) |0x04, base);
 		outw(flow_ctrl << 8 | 0x05, base);
@@ -1056,22 +816,22 @@
 		InterruptTheCard(base);
 		unlock_card(card);
 	}
-	
+
 	/*	rx enabled -> enable port for rx on the card	*/
 	if (C_CREAD(tty)) {
 		card->port_status |= (1 << channel);
 		outw(card->port_status, base + 0x02);
 	}
 }
- 
-/* open et all */ 
 
-static inline void isicom_setup_board(struct isi_board * bp)
+/* open et all */
+
+static inline void isicom_setup_board(struct isi_board *bp)
 {
 	int channel;
-	struct isi_port * port;
+	struct isi_port *port;
 	unsigned long flags;
-	
+
 	spin_lock_irqsave(&bp->card_lock, flags);
 	if (bp->status & BOARD_ACTIVE) {
 		spin_unlock_irqrestore(&bp->card_lock, flags);
@@ -1080,53 +840,54 @@
 	port = bp->ports;
 	bp->status |= BOARD_ACTIVE;
 	spin_unlock_irqrestore(&bp->card_lock, flags);
-	for(channel = 0; channel < bp->port_count; channel++, port++)
+	for (channel = 0; channel < bp->port_count; channel++, port++)
 		drop_dtr_rts(port);
 	return;
 }
- 
-static int isicom_setup_port(struct isi_port * port)
+
+static int isicom_setup_port(struct isi_port *port)
 {
-	struct isi_board * card = port->card;
+	struct isi_board *card = port->card;
 	unsigned long flags;
-	
+
 	if (port->flags & ASYNC_INITIALIZED) {
 		return 0;
 	}
 	if (!port->xmit_buf) {
 		unsigned long page;
-		
+
 		if (!(page = get_zeroed_page(GFP_KERNEL)))
 			return -ENOMEM;
-		
+
 		if (port->xmit_buf) {
 			free_page(page);
 			return -ERESTARTSYS;
 		}
-		port->xmit_buf = (unsigned char *) page;	
-	}	
+		port->xmit_buf = (unsigned char *) page;
+	}
 
 	spin_lock_irqsave(&card->card_lock, flags);
 	if (port->tty)
 		clear_bit(TTY_IO_ERROR, &port->tty->flags);
 	if (port->count == 1)
 		card->count++;
-		
+
 	port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
-	
+
 	/*	discard any residual data	*/
 	kill_queue(port, ISICOM_KILLTX | ISICOM_KILLRX);
-	
+
 	isicom_config_port(port);
 	port->flags |= ASYNC_INITIALIZED;
 	spin_unlock_irqrestore(&card->card_lock, flags);
-	
-	return 0;		
-} 
- 
-static int block_til_ready(struct tty_struct * tty, struct file * filp, struct isi_port * port) 
+
+	return 0;
+}
+
+static int block_til_ready(struct tty_struct *tty, struct file *filp,
+	struct isi_port *port)
 {
-	struct isi_board * card = port->card;
+	struct isi_board *card = port->card;
 	int do_clocal = 0, retval;
 	unsigned long flags;
 	DECLARE_WAITQUEUE(wait, current);
@@ -1134,30 +895,27 @@
 	/* block if port is in the process of being closed */
 
 	if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
-#ifdef ISICOM_DEBUG	
-		printk(KERN_DEBUG "ISICOM: block_til_ready: close in progress.\n");
-#endif		
+		pr_dbg("block_til_ready: close in progress.\n");
 		interruptible_sleep_on(&port->close_wait);
 		if (port->flags & ASYNC_HUP_NOTIFY)
 			return -EAGAIN;
 		else
 			return -ERESTARTSYS;
 	}
-	
+
 	/* if non-blocking mode is set ... */
-	
-	if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) {
-#ifdef ISICOM_DEBUG	
-		printk(KERN_DEBUG "ISICOM: block_til_ready: non-block mode.\n");
-#endif		
+
+	if ((filp->f_flags & O_NONBLOCK) ||
+			(tty->flags & (1 << TTY_IO_ERROR))) {
+		pr_dbg("block_til_ready: non-block mode.\n");
 		port->flags |= ASYNC_NORMAL_ACTIVE;
-		return 0;	
-	}	
-	
+		return 0;
+	}
+
 	if (C_CLOCAL(tty))
 		do_clocal = 1;
-	
-	/* block waiting for DCD to be asserted, and while 
+
+	/* block waiting for DCD to be asserted, and while
 						callout dev is busy */
 	retval = 0;
 	add_wait_queue(&port->open_wait, &wait);
@@ -1167,27 +925,27 @@
 		port->count--;
 	port->blocked_open++;
 	spin_unlock_irqrestore(&card->card_lock, flags);
-	
+
 	while (1) {
 		raise_dtr_rts(port);
 
 		set_current_state(TASK_INTERRUPTIBLE);
-		if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) { 	
+		if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) {
 			if (port->flags & ASYNC_HUP_NOTIFY)
 				retval = -EAGAIN;
 			else
 				retval = -ERESTARTSYS;
 			break;
-		}	
+		}
 		if (!(port->flags & ASYNC_CLOSING) &&
-		    (do_clocal || (port->status & ISI_DCD))) {
+				(do_clocal || (port->status & ISI_DCD))) {
 			break;
-		}	
+		}
 		if (signal_pending(current)) {
 			retval = -ERESTARTSYS;
 			break;
 		}
-		schedule();		
+		schedule();
 	}
 	set_current_state(TASK_RUNNING);
 	remove_wait_queue(&port->open_wait, &wait);
@@ -1201,11 +959,11 @@
 	port->flags |= ASYNC_NORMAL_ACTIVE;
 	return 0;
 }
- 
-static int isicom_open(struct tty_struct * tty, struct file * filp)
+
+static int isicom_open(struct tty_struct *tty, struct file *filp)
 {
-	struct isi_port * port;
-	struct isi_board * card;
+	struct isi_port *port;
+	struct isi_board *card;
 	unsigned int line, board;
 	int error;
 
@@ -1214,20 +972,20 @@
 		return -ENODEV;
 	board = BOARD(line);
 	card = &isi_card[board];
-	
+
 	if (!(card->status & FIRMWARE_LOADED))
 		return -ENODEV;
-	
+
 	/*  open on a port greater than the port count for the card !!! */
 	if (line > ((board * 16) + card->port_count - 1))
 		return -ENODEV;
 
-	port = &isi_ports[line];	
+	port = &isi_ports[line];
 	if (isicom_paranoia_check(port, tty->name, "isicom_open"))
 		return -ENODEV;
-		
-	isicom_setup_board(card);		
-	
+
+	isicom_setup_board(card);
+
 	port->count++;
 	tty->driver_data = port;
 	port->tty = tty;
@@ -1236,12 +994,12 @@
 	if ((error = block_til_ready(tty, filp, port))!=0)
 		return error;
 
-	return 0;      		
+	return 0;
 }
- 
+
 /* close et all */
 
-static inline void isicom_shutdown_board(struct isi_board * bp)
+static inline void isicom_shutdown_board(struct isi_board *bp)
 {
 	unsigned long flags;
 
@@ -1252,15 +1010,15 @@
 	spin_unlock_irqrestore(&bp->card_lock, flags);
 }
 
-static void isicom_shutdown_port(struct isi_port * port)
+static void isicom_shutdown_port(struct isi_port *port)
 {
-	struct isi_board * card = port->card;
-	struct tty_struct * tty;	
+	struct isi_board *card = port->card;
+	struct tty_struct *tty;
 	unsigned long flags;
-	
+
 	tty = port->tty;
 
-	spin_lock_irqsave(&card->card_lock, flags);	
+	spin_lock_irqsave(&card->card_lock, flags);
 	if (!(port->flags & ASYNC_INITIALIZED)) {
 		spin_unlock_irqrestore(&card->card_lock, flags);
 		return;
@@ -1268,93 +1026,91 @@
 	if (port->xmit_buf) {
 		free_page((unsigned long) port->xmit_buf);
 		port->xmit_buf = NULL;
-	}	
+	}
 	port->flags &= ~ASYNC_INITIALIZED;
 	/* 3rd October 2000 : Vinayak P Risbud */
 	port->tty = NULL;
 	spin_unlock_irqrestore(&card->card_lock, flags);
-	
+
 	/*Fix done by Anil .S on 30-04-2001
 	remote login through isi port has dtr toggle problem
 	due to which the carrier drops before the password prompt
-	appears on the remote end. Now we drop the dtr only if the 
+	appears on the remote end. Now we drop the dtr only if the
 	HUPCL(Hangup on close) flag is set for the tty*/
-	
-	if (C_HUPCL(tty)) 
+
+	if (C_HUPCL(tty))
 		/* drop dtr on this port */
 		drop_dtr(port);
-		
-	/* any other port uninits  */ 
+
+	/* any other port uninits  */
 	if (tty)
 		set_bit(TTY_IO_ERROR, &tty->flags);
-	
+
 	if (--card->count < 0) {
-		printk(KERN_DEBUG "ISICOM: isicom_shutdown_port: bad board(0x%x) count %d.\n",
+		pr_dbg("isicom_shutdown_port: bad board(0x%lx) count %d.\n",
 			card->base, card->count);
-		card->count = 0;	
+		card->count = 0;
 	}
-	
-	/* last port was closed , shutdown that boad too */
-	if(C_HUPCL(tty)) {
+
+	/* last port was closed, shutdown that boad too */
+	if (C_HUPCL(tty)) {
 		if (!card->count)
 			isicom_shutdown_board(card);
 	}
 }
 
-static void isicom_close(struct tty_struct * tty, struct file * filp)
+static void isicom_close(struct tty_struct *tty, struct file *filp)
 {
-	struct isi_port * port = (struct isi_port *) tty->driver_data;
-	struct isi_board * card = port->card;
+	struct isi_port *port = tty->driver_data;
+	struct isi_board *card = port->card;
 	unsigned long flags;
-	
+
 	if (!port)
 		return;
 	if (isicom_paranoia_check(port, tty->name, "isicom_close"))
 		return;
-	
-#ifdef ISICOM_DEBUG		
-	printk(KERN_DEBUG "ISICOM: Close start!!!.\n");
-#endif	
-	
+
+	pr_dbg("Close start!!!.\n");
+
 	spin_lock_irqsave(&card->card_lock, flags);
 	if (tty_hung_up_p(filp)) {
 		spin_unlock_irqrestore(&card->card_lock, flags);
 		return;
 	}
-	
+
 	if (tty->count == 1 && port->count != 1) {
-		printk(KERN_WARNING "ISICOM:(0x%x) isicom_close: bad port count"
-			"tty->count = 1	port count = %d.\n",
+		printk(KERN_WARNING "ISICOM:(0x%lx) isicom_close: bad port "
+			"count tty->count = 1 port count = %d.\n",
 			card->base, port->count);
 		port->count = 1;
 	}
 	if (--port->count < 0) {
-		printk(KERN_WARNING "ISICOM:(0x%x) isicom_close: bad port count for"
-			"channel%d = %d", card->base, port->channel, 
+		printk(KERN_WARNING "ISICOM:(0x%lx) isicom_close: bad port "
+			"count for channel%d = %d", card->base, port->channel,
 			port->count);
-		port->count = 0;	
+		port->count = 0;
 	}
-	
+
 	if (port->count) {
 		spin_unlock_irqrestore(&card->card_lock, flags);
 		return;
-	} 	
+	}
 	port->flags |= ASYNC_CLOSING;
 	tty->closing = 1;
 	spin_unlock_irqrestore(&card->card_lock, flags);
-	
+
 	if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
 		tty_wait_until_sent(tty, port->closing_wait);
-	/* indicate to the card that no more data can be received 
+	/* indicate to the card that no more data can be received
 	   on this port */
 	spin_lock_irqsave(&card->card_lock, flags);
-	if (port->flags & ASYNC_INITIALIZED) {   
+	if (port->flags & ASYNC_INITIALIZED) {
 		card->port_status &= ~(1 << port->channel);
 		outw(card->port_status, card->base + 0x02);
-	}	
+	}
 	isicom_shutdown_port(port);
 	spin_unlock_irqrestore(&card->card_lock, flags);
-	
+
 	if (tty->driver->flush_buffer)
 		tty->driver->flush_buffer(tty);
 	tty_ldisc_flush(tty);
@@ -1365,65 +1121,65 @@
 	if (port->blocked_open) {
 		spin_unlock_irqrestore(&card->card_lock, flags);
 		if (port->close_delay) {
-#ifdef ISICOM_DEBUG			
-			printk(KERN_DEBUG "ISICOM: scheduling until time out.\n");
-#endif			
-			msleep_interruptible(jiffies_to_msecs(port->close_delay));
+			pr_dbg("scheduling until time out.\n");
+			msleep_interruptible(
+				jiffies_to_msecs(port->close_delay));
 		}
 		spin_lock_irqsave(&card->card_lock, flags);
 		wake_up_interruptible(&port->open_wait);
-	}	
+	}
 	port->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
 	wake_up_interruptible(&port->close_wait);
 	spin_unlock_irqrestore(&card->card_lock, flags);
 }
 
 /* write et all */
-static int isicom_write(struct tty_struct * tty,
-			const unsigned char * buf, int count)
+static int isicom_write(struct tty_struct *tty,	const unsigned char *buf,
+	int count)
 {
-	struct isi_port * port = (struct isi_port *) tty->driver_data;
-	struct isi_board * card = port->card;
+	struct isi_port *port = tty->driver_data;
+	struct isi_board *card = port->card;
 	unsigned long flags;
 	int cnt, total = 0;
 
 	if (isicom_paranoia_check(port, tty->name, "isicom_write"))
 		return 0;
-	
-	if (!tty || !port->xmit_buf || !tmp_buf)
+
+	if (!tty || !port->xmit_buf)
 		return 0;
-		
+
 	spin_lock_irqsave(&card->card_lock, flags);
-	
-	while(1) {	
-		cnt = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
-					    SERIAL_XMIT_SIZE - port->xmit_head));
-		if (cnt <= 0) 
+
+	while(1) {
+		cnt = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt
+				- 1, SERIAL_XMIT_SIZE - port->xmit_head));
+		if (cnt <= 0)
 			break;
-		
+
 		memcpy(port->xmit_buf + port->xmit_head, buf, cnt);
-		port->xmit_head = (port->xmit_head + cnt) & (SERIAL_XMIT_SIZE - 1);
+		port->xmit_head = (port->xmit_head + cnt) & (SERIAL_XMIT_SIZE
+			- 1);
 		port->xmit_cnt += cnt;
 		buf += cnt;
 		count -= cnt;
 		total += cnt;
-	}		
+	}
 	if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped)
 		port->status |= ISI_TXOK;
 	spin_unlock_irqrestore(&card->card_lock, flags);
-	return total;	
+	return total;
 }
 
 /* put_char et all */
-static void isicom_put_char(struct tty_struct * tty, unsigned char ch)
+static void isicom_put_char(struct tty_struct *tty, unsigned char ch)
 {
-	struct isi_port * port = (struct isi_port *) tty->driver_data;
-	struct isi_board * card = port->card;
+	struct isi_port *port = tty->driver_data;
+	struct isi_board *card = port->card;
 	unsigned long flags;
-	
+
 	if (isicom_paranoia_check(port, tty->name, "isicom_put_char"))
 		return;
-	
+
 	if (!tty || !port->xmit_buf)
 		return;
 
@@ -1432,7 +1188,7 @@
 		spin_unlock_irqrestore(&card->card_lock, flags);
 		return;
 	}
-	
+
 	port->xmit_buf[port->xmit_head++] = ch;
 	port->xmit_head &= (SERIAL_XMIT_SIZE - 1);
 	port->xmit_cnt++;
@@ -1440,30 +1196,31 @@
 }
 
 /* flush_chars et all */
-static void isicom_flush_chars(struct tty_struct * tty)
+static void isicom_flush_chars(struct tty_struct *tty)
 {
-	struct isi_port * port = (struct isi_port *) tty->driver_data;
-	
+	struct isi_port *port = tty->driver_data;
+
 	if (isicom_paranoia_check(port, tty->name, "isicom_flush_chars"))
 		return;
-	
-	if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped || !port->xmit_buf)
+
+	if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
+			!port->xmit_buf)
 		return;
-		
+
 	/* this tells the transmitter to consider this port for
 	   data output to the card ... that's the best we can do. */
-	port->status |= ISI_TXOK;	
+	port->status |= ISI_TXOK;
 }
 
 /* write_room et all */
-static int isicom_write_room(struct tty_struct * tty)
+static int isicom_write_room(struct tty_struct *tty)
 {
-	struct isi_port * port = (struct isi_port *) tty->driver_data;
+	struct isi_port *port = tty->driver_data;
 	int free;
 
 	if (isicom_paranoia_check(port, tty->name, "isicom_write_room"))
 		return 0;
-	
+
 	free = SERIAL_XMIT_SIZE - port->xmit_cnt - 1;
 	if (free < 0)
 		free = 0;
@@ -1471,23 +1228,24 @@
 }
 
 /* chars_in_buffer et all */
-static int isicom_chars_in_buffer(struct tty_struct * tty)
+static int isicom_chars_in_buffer(struct tty_struct *tty)
 {
-	struct isi_port * port = (struct isi_port *) tty->driver_data;
+	struct isi_port *port = tty->driver_data;
 	if (isicom_paranoia_check(port, tty->name, "isicom_chars_in_buffer"))
 		return 0;
 	return port->xmit_cnt;
 }
 
 /* ioctl et all */
-static inline void isicom_send_break(struct isi_port * port, unsigned long length)
+static inline void isicom_send_break(struct isi_port *port,
+	unsigned long length)
 {
-	struct isi_board * card = port->card;
-	unsigned short base = card->base;	
-	
-	if(!lock_card(card))
+	struct isi_board *card = port->card;
+	unsigned long base = card->base;
+
+	if (!lock_card(card))
 		return;
-		
+
 	outw(0x8000 | ((port->channel) << (card->shift_count)) | 0x3, base);
 	outw((length & 0xff) << 8 | 0x00, base);
 	outw((length & 0xff00), base);
@@ -1498,13 +1256,13 @@
 
 static int isicom_tiocmget(struct tty_struct *tty, struct file *file)
 {
-	struct isi_port * port = (struct isi_port *) tty->driver_data;
+	struct isi_port *port = tty->driver_data;
 	/* just send the port status */
-	unsigned short status = port->status;
+	u16 status = port->status;
 
 	if (isicom_paranoia_check(port, tty->name, "isicom_ioctl"))
 		return -ENODEV;
-	
+
 	return  ((status & ISI_RTS) ? TIOCM_RTS : 0) |
 		((status & ISI_DTR) ? TIOCM_DTR : 0) |
 		((status & ISI_DCD) ? TIOCM_CAR : 0) |
@@ -1514,13 +1272,13 @@
 }
 
 static int isicom_tiocmset(struct tty_struct *tty, struct file *file,
-			   unsigned int set, unsigned int clear)
+	unsigned int set, unsigned int clear)
 {
-	struct isi_port * port = (struct isi_port *) tty->driver_data;
-	
+	struct isi_port *port = tty->driver_data;
+
 	if (isicom_paranoia_check(port, tty->name, "isicom_ioctl"))
 		return -ENODEV;
-	
+
 	if (set & TIOCM_RTS)
 		raise_rts(port);
 	if (set & TIOCM_DTR)
@@ -1532,46 +1290,46 @@
 		drop_dtr(port);
 
 	return 0;
-}			
+}
 
-static int isicom_set_serial_info(struct isi_port * port,
-					struct serial_struct __user *info)
+static int isicom_set_serial_info(struct isi_port *port,
+	struct serial_struct __user *info)
 {
 	struct serial_struct newinfo;
 	int reconfig_port;
 
-	if(copy_from_user(&newinfo, info, sizeof(newinfo)))
+	if (copy_from_user(&newinfo, info, sizeof(newinfo)))
 		return -EFAULT;
-		
-	reconfig_port = ((port->flags & ASYNC_SPD_MASK) != 
-			 (newinfo.flags & ASYNC_SPD_MASK));
-	
+
+	reconfig_port = ((port->flags & ASYNC_SPD_MASK) !=
+		(newinfo.flags & ASYNC_SPD_MASK));
+
 	if (!capable(CAP_SYS_ADMIN)) {
 		if ((newinfo.close_delay != port->close_delay) ||
-		    (newinfo.closing_wait != port->closing_wait) ||
-		    ((newinfo.flags & ~ASYNC_USR_MASK) != 
-		     (port->flags & ~ASYNC_USR_MASK)))
+				(newinfo.closing_wait != port->closing_wait) ||
+				((newinfo.flags & ~ASYNC_USR_MASK) !=
+				(port->flags & ~ASYNC_USR_MASK)))
 			return -EPERM;
 		port->flags = ((port->flags & ~ ASYNC_USR_MASK) |
 				(newinfo.flags & ASYNC_USR_MASK));
-	}	
+	}
 	else {
 		port->close_delay = newinfo.close_delay;
-		port->closing_wait = newinfo.closing_wait; 
-		port->flags = ((port->flags & ~ASYNC_FLAGS) | 
+		port->closing_wait = newinfo.closing_wait;
+		port->flags = ((port->flags & ~ASYNC_FLAGS) |
 				(newinfo.flags & ASYNC_FLAGS));
 	}
 	if (reconfig_port) {
 		isicom_config_port(port);
 	}
-	return 0;		 
-}		
+	return 0;
+}
 
-static int isicom_get_serial_info(struct isi_port * port, 
-					struct serial_struct __user *info)
+static int isicom_get_serial_info(struct isi_port *port,
+	struct serial_struct __user *info)
 {
 	struct serial_struct out_info;
-	
+
 	memset(&out_info, 0, sizeof(out_info));
 /*	out_info.type = ? */
 	out_info.line = port - isi_ports;
@@ -1581,15 +1339,15 @@
 /*	out_info.baud_base = ? */
 	out_info.close_delay = port->close_delay;
 	out_info.closing_wait = port->closing_wait;
-	if(copy_to_user(info, &out_info, sizeof(out_info)))
+	if (copy_to_user(info, &out_info, sizeof(out_info)))
 		return -EFAULT;
 	return 0;
-}					
+}
 
-static int isicom_ioctl(struct tty_struct * tty, struct file * filp,
-			unsigned int cmd, unsigned long arg) 
+static int isicom_ioctl(struct tty_struct *tty, struct file *filp,
+	unsigned int cmd, unsigned long arg)
 {
-	struct isi_port * port = (struct isi_port *) tty->driver_data;
+	struct isi_port *port = tty->driver_data;
 	void __user *argp = (void __user *)arg;
 	int retval;
 
@@ -1597,139 +1355,141 @@
 		return -ENODEV;
 
 	switch(cmd) {
-		case TCSBRK:
-			retval = tty_check_change(tty);
-			if (retval)
-				return retval;
-			tty_wait_until_sent(tty, 0);
-			if (!arg)
-				isicom_send_break(port, HZ/4);
-			return 0;
-			
-		case TCSBRKP:	
-			retval = tty_check_change(tty);
-			if (retval)
-				return retval;
-			tty_wait_until_sent(tty, 0);
-			isicom_send_break(port, arg ? arg * (HZ/10) : HZ/4);
-			return 0;
-			
-		case TIOCGSOFTCAR:
-			return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *)argp);
-			
-		case TIOCSSOFTCAR:
-			if(get_user(arg, (unsigned long __user *) argp))
-				return -EFAULT;
-			tty->termios->c_cflag =
-				((tty->termios->c_cflag & ~CLOCAL) |
-				(arg ? CLOCAL : 0));
-			return 0;	
-			
-		case TIOCGSERIAL:
-			return isicom_get_serial_info(port, argp);
-		
-		case TIOCSSERIAL:
-			return isicom_set_serial_info(port, argp);
-					
-		default:
-			return -ENOIOCTLCMD;						
+	case TCSBRK:
+		retval = tty_check_change(tty);
+		if (retval)
+			return retval;
+		tty_wait_until_sent(tty, 0);
+		if (!arg)
+			isicom_send_break(port, HZ/4);
+		return 0;
+
+	case TCSBRKP:
+		retval = tty_check_change(tty);
+		if (retval)
+			return retval;
+		tty_wait_until_sent(tty, 0);
+		isicom_send_break(port, arg ? arg * (HZ/10) : HZ/4);
+		return 0;
+
+	case TIOCGSOFTCAR:
+		return put_user(C_CLOCAL(tty) ? 1 : 0,
+				(unsigned long __user *)argp);
+
+	case TIOCSSOFTCAR:
+		if (get_user(arg, (unsigned long __user *) argp))
+			return -EFAULT;
+		tty->termios->c_cflag =
+			((tty->termios->c_cflag & ~CLOCAL) |
+			(arg ? CLOCAL : 0));
+		return 0;
+
+	case TIOCGSERIAL:
+		return isicom_get_serial_info(port, argp);
+
+	case TIOCSSERIAL:
+		return isicom_set_serial_info(port, argp);
+
+	default:
+		return -ENOIOCTLCMD;
 	}
 	return 0;
 }
 
 /* set_termios et all */
-static void isicom_set_termios(struct tty_struct * tty, struct termios * old_termios)
+static void isicom_set_termios(struct tty_struct *tty,
+	struct termios *old_termios)
 {
-	struct isi_port * port = (struct isi_port *) tty->driver_data;
-	
+	struct isi_port *port = tty->driver_data;
+
 	if (isicom_paranoia_check(port, tty->name, "isicom_set_termios"))
 		return;
-	
+
 	if (tty->termios->c_cflag == old_termios->c_cflag &&
-	    tty->termios->c_iflag == old_termios->c_iflag)
+			tty->termios->c_iflag == old_termios->c_iflag)
 		return;
-		
+
 	isicom_config_port(port);
-	
+
 	if ((old_termios->c_cflag & CRTSCTS) &&
-	    !(tty->termios->c_cflag & CRTSCTS)) {	
+			!(tty->termios->c_cflag & CRTSCTS)) {
 		tty->hw_stopped = 0;
-		isicom_start(tty);   
-	}    
+		isicom_start(tty);
+	}
 }
 
 /* throttle et all */
-static void isicom_throttle(struct tty_struct * tty)
+static void isicom_throttle(struct tty_struct *tty)
 {
-	struct isi_port * port = (struct isi_port *) tty->driver_data;
-	struct isi_board * card = port->card;
-	
+	struct isi_port *port = tty->driver_data;
+	struct isi_board *card = port->card;
+
 	if (isicom_paranoia_check(port, tty->name, "isicom_throttle"))
 		return;
-	
+
 	/* tell the card that this port cannot handle any more data for now */
 	card->port_status &= ~(1 << port->channel);
 	outw(card->port_status, card->base + 0x02);
 }
 
 /* unthrottle et all */
-static void isicom_unthrottle(struct tty_struct * tty)
+static void isicom_unthrottle(struct tty_struct *tty)
 {
-	struct isi_port * port = (struct isi_port *) tty->driver_data;
-	struct isi_board * card = port->card;
-	
+	struct isi_port *port = tty->driver_data;
+	struct isi_board *card = port->card;
+
 	if (isicom_paranoia_check(port, tty->name, "isicom_unthrottle"))
 		return;
-	
+
 	/* tell the card that this port is ready to accept more data */
 	card->port_status |= (1 << port->channel);
 	outw(card->port_status, card->base + 0x02);
 }
 
 /* stop et all */
-static void isicom_stop(struct tty_struct * tty)
+static void isicom_stop(struct tty_struct *tty)
 {
-	struct isi_port * port = (struct isi_port *) tty->driver_data;
+	struct isi_port *port = tty->driver_data;
 
 	if (isicom_paranoia_check(port, tty->name, "isicom_stop"))
 		return;
-	
+
 	/* this tells the transmitter not to consider this port for
 	   data output to the card. */
 	port->status &= ~ISI_TXOK;
 }
 
 /* start et all */
-static void isicom_start(struct tty_struct * tty)
+static void isicom_start(struct tty_struct *tty)
 {
-	struct isi_port * port = (struct isi_port *) tty->driver_data;
-	
+	struct isi_port *port = tty->driver_data;
+
 	if (isicom_paranoia_check(port, tty->name, "isicom_start"))
 		return;
-	
+
 	/* this tells the transmitter to consider this port for
 	   data output to the card. */
 	port->status |= ISI_TXOK;
 }
 
 /* hangup et all */
-static void do_isicom_hangup(void * data)
+static void do_isicom_hangup(void *data)
 {
-	struct isi_port * port = (struct isi_port *) data;
-	struct tty_struct * tty;
-	
+	struct isi_port *port = data;
+	struct tty_struct *tty;
+
 	tty = port->tty;
 	if (tty)
 		tty_hangup(tty);
 }
 
-static void isicom_hangup(struct tty_struct * tty)
+static void isicom_hangup(struct tty_struct *tty)
 {
-	struct isi_port * port = (struct isi_port *) tty->driver_data;
-	
+	struct isi_port *port = tty->driver_data;
+
 	if (isicom_paranoia_check(port, tty->name, "isicom_hangup"))
 		return;
-	
+
 	isicom_shutdown_port(port);
 	port->count = 0;
 	port->flags &= ~ASYNC_NORMAL_ACTIVE;
@@ -1738,220 +1498,535 @@
 }
 
 /* flush_buffer et all */
-static void isicom_flush_buffer(struct tty_struct * tty)
+static void isicom_flush_buffer(struct tty_struct *tty)
 {
-	struct isi_port * port = (struct isi_port *) tty->driver_data;
-	struct isi_board * card = port->card;
+	struct isi_port *port = tty->driver_data;
+	struct isi_board *card = port->card;
 	unsigned long flags;
-	
+
 	if (isicom_paranoia_check(port, tty->name, "isicom_flush_buffer"))
 		return;
-	
+
 	spin_lock_irqsave(&card->card_lock, flags);
 	port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
 	spin_unlock_irqrestore(&card->card_lock, flags);
-	
+
 	wake_up_interruptible(&tty->write_wait);
 	tty_wakeup(tty);
 }
 
+/*
+ * Driver init and deinit functions
+ */
 
-static int __devinit register_ioregion(void)
+static int __devinit isicom_register_ioregion(struct pci_dev *pdev,
+	const unsigned int index)
 {
-	int count, done=0;
-	for (count=0; count < BOARD_COUNT; count++ ) {
-		if (isi_card[count].base)
-			if (!request_region(isi_card[count].base,16,ISICOM_NAME)) {
-				printk(KERN_DEBUG "ISICOM: I/O Region 0x%x-0x%x is busy. Card%d will be disabled.\n",
-					isi_card[count].base,isi_card[count].base+15,count+1);
-				isi_card[count].base=0;
-				done++;
-			}
-	}
-	return done;
+	struct isi_board *board = pci_get_drvdata(pdev);
+
+	if (!board->base)
+		return -EINVAL;
+
+	if (!request_region(board->base, 16, ISICOM_NAME)) {
+		dev_dbg(&pdev->dev, "I/O Region 0x%lx-0x%lx is busy. Card%d "
+			"will be disabled.\n", board->base, board->base + 15,
+			index + 1);
+		return -EBUSY;
+ 	}
+
+	return 0;
 }
 
-static void unregister_ioregion(void)
+static void isicom_unregister_ioregion(struct pci_dev *pdev)
 {
-	int count;
-	for (count=0; count < BOARD_COUNT; count++ ) 
-		if (isi_card[count].base) {
-			release_region(isi_card[count].base,16);
-#ifdef ISICOM_DEBUG			
-			printk(KERN_DEBUG "ISICOM: I/O Region 0x%x-0x%x released for Card%d.\n",isi_card[count].base,isi_card[count].base+15,count+1);
-#endif			
-		}
+	struct isi_board *board = pci_get_drvdata(pdev);
+
+	if (!board->base)
+		return;
+
+	release_region(board->base, 16);
+	dev_dbg(&pdev->dev, "I/O Region 0x%lx-0x%lx released.\n",
+		board->base, board->base + 15);
+	board->base = 0;
 }
 
 static struct tty_operations isicom_ops = {
-	.open	= isicom_open,
-	.close	= isicom_close,
-	.write	= isicom_write,
-	.put_char	= isicom_put_char,
-	.flush_chars	= isicom_flush_chars,
-	.write_room	= isicom_write_room,
+	.open			= isicom_open,
+	.close			= isicom_close,
+	.write			= isicom_write,
+	.put_char		= isicom_put_char,
+	.flush_chars		= isicom_flush_chars,
+	.write_room		= isicom_write_room,
 	.chars_in_buffer	= isicom_chars_in_buffer,
-	.ioctl	= isicom_ioctl,
-	.set_termios	= isicom_set_termios,
-	.throttle	= isicom_throttle,
-	.unthrottle	= isicom_unthrottle,
-	.stop	= isicom_stop,
-	.start	= isicom_start,
-	.hangup	= isicom_hangup,
-	.flush_buffer	= isicom_flush_buffer,
-	.tiocmget	= isicom_tiocmget,
-	.tiocmset	= isicom_tiocmset,
+	.ioctl			= isicom_ioctl,
+	.set_termios		= isicom_set_termios,
+	.throttle		= isicom_throttle,
+	.unthrottle		= isicom_unthrottle,
+	.stop			= isicom_stop,
+	.start			= isicom_start,
+	.hangup			= isicom_hangup,
+	.flush_buffer		= isicom_flush_buffer,
+	.tiocmget		= isicom_tiocmget,
+	.tiocmset		= isicom_tiocmset,
 };
 
-static int __devinit register_drivers(void)
+static int __devinit isicom_register_tty_driver(void)
 {
-	int error;
+	int error = -ENOMEM;
 
 	/* tty driver structure initialization */
 	isicom_normal = alloc_tty_driver(PORT_COUNT);
 	if (!isicom_normal)
-		return -ENOMEM;
+		goto end;
 
-	isicom_normal->owner	= THIS_MODULE;
-	isicom_normal->name 	= "ttyM";
-	isicom_normal->devfs_name = "isicom/";
-	isicom_normal->major	= ISICOM_NMAJOR;
-	isicom_normal->minor_start	= 0;
-	isicom_normal->type	= TTY_DRIVER_TYPE_SERIAL;
-	isicom_normal->subtype	= SERIAL_TYPE_NORMAL;
-	isicom_normal->init_termios	= tty_std_termios;
-	isicom_normal->init_termios.c_cflag	= 
-				B9600 | CS8 | CREAD | HUPCL |CLOCAL;
-	isicom_normal->flags	= TTY_DRIVER_REAL_RAW;
+	isicom_normal->owner			= THIS_MODULE;
+	isicom_normal->name 			= "ttyM";
+	isicom_normal->devfs_name	 	= "isicom/";
+	isicom_normal->major			= ISICOM_NMAJOR;
+	isicom_normal->minor_start		= 0;
+	isicom_normal->type			= TTY_DRIVER_TYPE_SERIAL;
+	isicom_normal->subtype			= SERIAL_TYPE_NORMAL;
+	isicom_normal->init_termios		= tty_std_termios;
+	isicom_normal->init_termios.c_cflag	= B9600 | CS8 | CREAD | HUPCL |
+		CLOCAL;
+	isicom_normal->flags			= TTY_DRIVER_REAL_RAW;
 	tty_set_operations(isicom_normal, &isicom_ops);
-	
-	if ((error=tty_register_driver(isicom_normal))!=0) {
-		printk(KERN_DEBUG "ISICOM: Couldn't register the dialin driver, error=%d\n",
+
+	if ((error = tty_register_driver(isicom_normal))) {
+		pr_dbg("Couldn't register the dialin driver, error=%d\n",
 			error);
 		put_tty_driver(isicom_normal);
-		return error;
 	}
-	return 0;
+end:
+	return error;
 }
 
-static void unregister_drivers(void)
+static void isicom_unregister_tty_driver(void)
 {
-	int error = tty_unregister_driver(isicom_normal);
-	if (error)
-		printk(KERN_DEBUG "ISICOM: couldn't unregister normal driver error=%d.\n",error);
+	int error;
+
+	if ((error = tty_unregister_driver(isicom_normal)))
+		pr_dbg("couldn't unregister normal driver, error=%d.\n", error);
+
 	put_tty_driver(isicom_normal);
 }
 
-static int __devinit register_isr(void)
+static int __devinit isicom_register_isr(struct pci_dev *pdev,
+	const unsigned int index)
 {
-	int count, done=0;
-	unsigned long irqflags;
+	struct isi_board *board = pci_get_drvdata(pdev);
+	unsigned long irqflags = SA_INTERRUPT;
+	int retval = -EINVAL;
 
-	for (count=0; count < BOARD_COUNT; count++ ) {
-		if (isi_card[count].base) {
-			irqflags = (isi_card[count].isa == YES) ? 
-					SA_INTERRUPT : 
-					(SA_INTERRUPT | SA_SHIRQ);
+	if (!board->base)
+		goto end;
 
-			if (request_irq(isi_card[count].irq, 
-					isicom_interrupt, 
-					irqflags, 
-					ISICOM_NAME, &isi_card[count])) {
+	if (board->isa == NO)
+		irqflags |= SA_SHIRQ;
 
-				printk(KERN_WARNING "ISICOM: Could not"
-					" install handler at Irq %d."
-					" Card%d will be disabled.\n",
-					isi_card[count].irq, count+1);
+	retval = request_irq(board->irq, isicom_interrupt, irqflags,
+		ISICOM_NAME, board);
+	if (retval < 0)
+		dev_warn(&pdev->dev, "Could not install handler at Irq %d. "
+			"Card%d will be disabled.\n", board->irq, index + 1);
+ 	else
+		retval = 0;
+end:
+	return retval;
+}
 
-				release_region(isi_card[count].base,16);
-				isi_card[count].base=0;
+static int __devinit reset_card(struct pci_dev *pdev,
+	const unsigned int card, unsigned int *signature)
+{
+	struct isi_board *board = pci_get_drvdata(pdev);
+	unsigned long base = board->base;
+	unsigned int portcount = 0;
+	int retval = 0;
+
+	dev_dbg(&pdev->dev, "ISILoad:Resetting Card%d at 0x%lx\n", card + 1,
+		base);
+
+	inw(base + 0x8);
+
+	mdelay(10);
+
+	outw(0, base + 0x8); /* Reset */
+
+	msleep(3000);
+
+	*signature = inw(base + 0x4) & 0xff;
+
+	if (board->isa == YES) {
+		if (!(inw(base + 0xe) & 0x1) || (inw(base + 0x2))) {
+			dev_dbg(&pdev->dev, "base+0x2=0x%lx, base+0xe=0x%lx\n",
+				inw(base + 0x2), inw(base + 0xe));
+			dev_err(&pdev->dev, "ISILoad:ISA Card%d reset failure "
+				"(Possible bad I/O Port Address 0x%lx).\n",
+				card + 1, base);
+			retval = -EIO;
+			goto end;
+		}
+	} else {
+		portcount = inw(base + 0x2);
+		if (!(inw(base + 0xe) & 0x1) || ((portcount != 0) &&
+				(portcount != 4) && (portcount != 8))) {
+			dev_dbg(&pdev->dev, "base+0x2=0x%lx, base+0xe=0x%lx\n",
+				inw(base + 0x2), inw(base + 0xe));
+			dev_err(&pdev->dev, "ISILoad:PCI Card%d reset failure "
+				"(Possible bad I/O Port Address 0x%lx).\n",
+				card + 1, base);
+			retval = -EIO;
+			goto end;
+		}
+	}
+
+	switch (*signature) {
+	case 0xa5:
+	case 0xbb:
+	case 0xdd:
+		board->port_count = (board->isa == NO && portcount == 4) ? 4 :
+			8;
+		board->shift_count = 12;
+		break;
+	case 0xcc:
+		board->port_count = 16;
+		board->shift_count = 11;
+		break;
+	default:
+		dev_warn(&pdev->dev, "ISILoad:Card%d reset failure (Possible "
+			"bad I/O Port Address 0x%lx).\n", card + 1, base);
+		dev_dbg(&pdev->dev, "Sig=0x%lx\n", signature);
+		retval = -EIO;
+	}
+	dev_info(&pdev->dev, "-Done\n");
+
+end:
+	return retval;
+}
+
+static inline int WaitTillCardIsFree(u16 base)
+{
+	unsigned long count = 0;
+
+	while (!(inw(base + 0xe) & 0x1) && count++ < 100)
+		msleep(5);
+
+	return !(inw(base + 0xe) & 0x1);
+}
+
+static int __devinit load_firmware(struct pci_dev *pdev,
+	const unsigned int index, const unsigned int signature)
+{
+	struct isi_board *board = pci_get_drvdata(pdev);
+	const struct firmware *fw;
+	unsigned long base = board->base;
+	unsigned int a;
+	u16 word_count, status;
+	int retval = -EIO;
+	char *name;
+	u8 *data;
+
+	struct stframe {
+		u16	addr;
+		u16	count;
+		u8	data[0];
+	} *frame;
+
+	switch (signature) {
+	case 0xa5:
+		name = "isi608.bin";
+		break;
+	case 0xbb:
+		name = "isi608em.bin";
+		break;
+	case 0xcc:
+		name = "isi616em.bin";
+		break;
+	case 0xdd:
+		name = "isi4608.bin";
+		break;
+	case 0xee:
+		name = "isi4616.bin";
+		break;
+	default:
+		dev_err(&pdev->dev, "Unknown signature.\n");
+		goto end;
+ 	}
+
+	retval = request_firmware(&fw, name, &pdev->dev);
+	if (retval)
+		goto end;
+
+	for (frame = (struct stframe *)fw->data;
+			frame < (struct stframe *)(fw->data + fw->size);
+			frame++) {
+		if (WaitTillCardIsFree(base))
+			goto errrelfw;
+
+		outw(0xf0, base);	/* start upload sequence */
+		outw(0x00, base);
+		outw(frame->addr, base); /* lsb of address */
+
+		word_count = frame->count / 2 + frame->count % 2;
+		outw(word_count, base);
+		InterruptTheCard(base);
+
+		udelay(100); /* 0x2f */
+
+		if (WaitTillCardIsFree(base))
+			goto errrelfw;
+
+		if ((status = inw(base + 0x4)) != 0) {
+			dev_warn(&pdev->dev, "Card%d rejected load header:\n"
+				"Address:0x%x\nCount:0x%x\nStatus:0x%x\n",
+				index + 1, frame->addr, frame->count, status);
+			goto errrelfw;
+		}
+		outsw(base, frame->data, word_count);
+
+		InterruptTheCard(base);
+
+		udelay(50); /* 0x0f */
+
+		if (WaitTillCardIsFree(base))
+			goto errrelfw;
+
+		if ((status = inw(base + 0x4)) != 0) {
+			dev_err(&pdev->dev, "Card%d got out of sync.Card "
+				"Status:0x%x\n", index + 1, status);
+			goto errrelfw;
+		}
+ 	}
+
+	retval = -EIO;
+
+	if (WaitTillCardIsFree(base))
+		goto errrelfw;
+
+	outw(0xf2, base);
+	outw(0x800, base);
+	outw(0x0, base);
+	outw(0x0, base);
+	InterruptTheCard(base);
+	outw(0x0, base + 0x4); /* for ISI4608 cards */
+
+/* XXX: should we test it by reading it back and comparing with original like
+ * in load firmware package? */
+	for (frame = (struct stframe*)fw->data;
+			frame < (struct stframe*)(fw->data + fw->size);
+			frame++) {
+		if (WaitTillCardIsFree(base))
+			goto errrelfw;
+
+		outw(0xf1, base); /* start download sequence */
+		outw(0x00, base);
+		outw(frame->addr, base); /* lsb of address */
+
+		word_count = (frame->count >> 1) + frame->count % 2;
+		outw(word_count + 1, base);
+		InterruptTheCard(base);
+
+		udelay(50); /* 0xf */
+
+		if (WaitTillCardIsFree(base))
+			goto errrelfw;
+
+		if ((status = inw(base + 0x4)) != 0) {
+			dev_warn(&pdev->dev, "Card%d rejected verify header:\n"
+				"Address:0x%x\nCount:0x%x\nStatus: 0x%x\n",
+				index + 1, frame->addr, frame->count, status);
+			goto errrelfw;
+		}
+
+		data = kmalloc(word_count * 2, GFP_KERNEL);
+		inw(base);
+		insw(base, data, word_count);
+		InterruptTheCard(base);
+
+		for (a = 0; a < frame->count; a++)
+			if (data[a] != frame->data[a]) {
+				kfree(data);
+				dev_err(&pdev->dev, "Card%d, firmware upload "
+					"failed\n", index + 1);
+				goto errrelfw;
 			}
-			else
-				done++;
-		}	
-	}
-	return done;
-}
+		kfree(data);
 
-static void __exit unregister_isr(void)
-{
-	int count;
+		udelay(50); /* 0xf */
 
-	for (count=0; count < BOARD_COUNT; count++ ) {
-		if (isi_card[count].base)
-			free_irq(isi_card[count].irq, &isi_card[count]);
-	}
-}
+		if (WaitTillCardIsFree(base))
+			goto errrelfw;
 
-static int __devinit isicom_init(void)
-{
-	int card, channel, base;
-	struct isi_port * port;
-	unsigned long page;
-	
-	if (!tmp_buf) { 
-		page = get_zeroed_page(GFP_KERNEL);
-	      	if (!page) {
-#ifdef ISICOM_DEBUG	      	
-	      		printk(KERN_DEBUG "ISICOM: Couldn't allocate page for tmp_buf.\n");
-#else
-			printk(KERN_ERR "ISICOM: Not enough memory...\n");
-#endif	      
-	      		return 0;
-	      	}	
-	      	tmp_buf = (unsigned char *) page;
+		if ((status = inw(base + 0x4)) != 0) {
+			dev_err(&pdev->dev, "Card%d verify got out of sync. "
+				"Card Status:0x%x\n", index + 1, status);
+			goto errrelfw;
+		}
 	}
-	
-	if (!register_ioregion()) 
-	{
-		printk(KERN_ERR "ISICOM: All required I/O space found busy.\n");
-		free_page((unsigned long)tmp_buf);
-		return 0;
-	}
-	if (register_drivers()) 
-	{
-		unregister_ioregion();
-		free_page((unsigned long)tmp_buf);
-		return 0;
-	}
-	if (!register_isr()) 
-	{
-		unregister_drivers();
-		/*  ioports already uregistered in register_isr */
-		free_page((unsigned long)tmp_buf);
-		return 0;		
-	}
-	
-	memset(isi_ports, 0, sizeof(isi_ports));
-	for (card = 0; card < BOARD_COUNT; card++) {
-		port = &isi_ports[card * 16];
-		isi_card[card].ports = port;
-		spin_lock_init(&isi_card[card].card_lock);
-		base = isi_card[card].base;
-		for (channel = 0; channel < 16; channel++, port++) {
-			port->magic = ISICOM_MAGIC;
-			port->card = &isi_card[card];
-			port->channel = channel;
-		 	port->close_delay = 50 * HZ/100;
-		 	port->closing_wait = 3000 * HZ/100;
-		 	INIT_WORK(&port->hangup_tq, do_isicom_hangup, port);
-		 	INIT_WORK(&port->bh_tqueue, isicom_bottomhalf, port);
-		 	port->status = 0;
-			init_waitqueue_head(&port->open_wait);	 				
-			init_waitqueue_head(&port->close_wait);
-			/*  . . .  */
- 		}
-	} 
-	
-	return 1;	
+
+	board->status |= FIRMWARE_LOADED;
+	retval = 0;
+
+errrelfw:
+	release_firmware(fw);
+end:
+	return retval;
 }
 
 /*
  *	Insmod can set static symbols so keep these static
  */
- 
 static int io[4];
 static int irq[4];
+static int card;
+
+static int __devinit isicom_probe(struct pci_dev *pdev,
+	const struct pci_device_id *ent)
+{
+	unsigned int ioaddr, signature, index;
+	int retval = -EPERM;
+	u8 pciirq;
+	struct isi_board *board = NULL;
+
+	if (card >= BOARD_COUNT)
+		goto err;
+
+	ioaddr = pci_resource_start(pdev, 3);
+	/* i.e at offset 0x1c in the PCI configuration register space. */
+	pciirq = pdev->irq;
+	dev_info(&pdev->dev, "ISI PCI Card(Device ID 0x%x)\n", ent->device);
+
+	/* allot the first empty slot in the array */
+	for (index = 0; index < BOARD_COUNT; index++)
+		if (isi_card[index].base == 0) {
+			board = &isi_card[index];
+			break;
+		}
+
+	board->base = ioaddr;
+	board->irq = pciirq;
+	board->isa = NO;
+	card++;
+
+	pci_set_drvdata(pdev, board);
+
+	retval = isicom_register_ioregion(pdev, index);
+	if (retval < 0)
+		goto err;
+
+	retval = isicom_register_isr(pdev, index);
+	if (retval < 0)
+		goto errunrr;
+
+	retval = reset_card(pdev, index, &signature);
+	if (retval < 0)
+		goto errunri;
+
+	retval = load_firmware(pdev, index, signature);
+	if (retval < 0)
+		goto errunri;
+
+	return 0;
+
+errunri:
+	free_irq(board->irq, board);
+errunrr:
+	isicom_unregister_ioregion(pdev);
+err:
+	board->base = 0;
+	return retval;
+}
+
+static void __devexit isicom_remove(struct pci_dev *pdev)
+{
+	struct isi_board *board = pci_get_drvdata(pdev);
+
+	free_irq(board->irq, board);
+	isicom_unregister_ioregion(pdev);
+}
+
+static int __devinit isicom_setup(void)
+{
+	int retval, idx, channel;
+	struct isi_port *port;
+
+	card = 0;
+	memset(isi_ports, 0, sizeof(isi_ports));
+
+	for(idx = 0; idx < BOARD_COUNT; idx++) {
+		port = &isi_ports[idx * 16];
+		isi_card[idx].ports = port;
+		spin_lock_init(&isi_card[idx].card_lock);
+		for (channel = 0; channel < 16; channel++, port++) {
+			port->magic = ISICOM_MAGIC;
+			port->card = &isi_card[idx];
+			port->channel = channel;
+			port->close_delay = 50 * HZ/100;
+			port->closing_wait = 3000 * HZ/100;
+			INIT_WORK(&port->hangup_tq, do_isicom_hangup, port);
+			INIT_WORK(&port->bh_tqueue, isicom_bottomhalf, port);
+			port->status = 0;
+			init_waitqueue_head(&port->open_wait);
+			init_waitqueue_head(&port->close_wait);
+			/*  . . .  */
+ 		}
+		isi_card[idx].base = 0;
+		isi_card[idx].irq = 0;
+
+		if (!io[idx])
+			continue;
+
+		if (irq[idx] == 2 || irq[idx] == 3 || irq[idx] == 4	||
+				irq[idx] == 5	|| irq[idx] == 7	||
+				irq[idx] == 10	|| irq[idx] == 11	||
+				irq[idx] == 12	|| irq[idx] == 15) {
+			printk(KERN_ERR "ISICOM: ISA not supported yet.\n");
+			retval = -EINVAL;
+			goto error;
+		} else
+			printk(KERN_ERR "ISICOM: Irq %d unsupported. "
+				"Disabling Card%d...\n", irq[idx], idx + 1);
+	}
+
+	retval = isicom_register_tty_driver();
+	if (retval < 0)
+		goto error;
+
+	retval = pci_register_driver(&isicom_driver);
+	if (retval < 0) {
+		printk(KERN_ERR "ISICOM: Unable to register pci driver.\n");
+		goto errtty;
+	}
+
+	init_timer(&tx);
+	tx.expires = jiffies + 1;
+	tx.data = 0;
+	tx.function = isicom_tx;
+	re_schedule = 1;
+	add_timer(&tx);
+
+	return 0;
+errtty:
+	isicom_unregister_tty_driver();
+error:
+	return retval;
+}
+
+static void __exit isicom_exit(void)
+{
+	unsigned int index = 0;
+
+	re_schedule = 0;
+
+	while (re_schedule != 2 && index++ < 100)
+		msleep(10);
+
+	pci_unregister_driver(&isicom_driver);
+	isicom_unregister_tty_driver();
+}
+
+module_init(isicom_setup);
+module_exit(isicom_exit);
 
 MODULE_AUTHOR("MultiTech");
 MODULE_DESCRIPTION("Driver for the ISI series of cards by MultiTech");
@@ -1960,120 +2035,3 @@
 MODULE_PARM_DESC(io, "I/O ports for the cards");
 module_param_array(irq, int, NULL, 0);
 MODULE_PARM_DESC(irq, "Interrupts for the cards");
-
-static int __devinit isicom_setup(void)
-{
-	struct pci_dev *dev = NULL;
-	int retval, card, idx, count;
-	unsigned char pciirq;
-	unsigned int ioaddr;
-	                
-	card = 0;
-	for(idx=0; idx < BOARD_COUNT; idx++) {	
-		if (io[idx]) {
-			isi_card[idx].base=io[idx];
-			isi_card[idx].irq=irq[idx];
-			isi_card[idx].isa=YES;
-			card++;
-		}
-		else {
-			isi_card[idx].base = 0;
-			isi_card[idx].irq = 0;
-		}
-	}
-	
-	for (idx=0 ;idx < card; idx++) {
-		if (!((isi_card[idx].irq==2)||(isi_card[idx].irq==3)||
-		    (isi_card[idx].irq==4)||(isi_card[idx].irq==5)||
-		    (isi_card[idx].irq==7)||(isi_card[idx].irq==10)||
-		    (isi_card[idx].irq==11)||(isi_card[idx].irq==12)||
-		    (isi_card[idx].irq==15))) {
-			
-			if (isi_card[idx].base) {
-				printk(KERN_ERR "ISICOM: Irq %d unsupported. Disabling Card%d...\n",
-					isi_card[idx].irq, idx+1);
-				isi_card[idx].base=0;
-				card--;
-			}	
-		}
-	}	
-	
-	if (card < BOARD_COUNT) {
-		for (idx=0; idx < DEVID_COUNT; idx++) {
-			dev = NULL;
-			for (;;){
-				if (!(dev = pci_find_device(VENDOR_ID, isicom_pci_tbl[idx].device, dev)))
-					break;
-				if (card >= BOARD_COUNT)
-					break;
-					
-				if (pci_enable_device(dev))
-					break;
-
-				/* found a PCI ISI card! */
-				ioaddr = pci_resource_start (dev, 3); /* i.e at offset 0x1c in the
-								       * PCI configuration register
-								       * space.
-								       */
-				pciirq = dev->irq;
-				printk(KERN_INFO "ISI PCI Card(Device ID 0x%x)\n", isicom_pci_tbl[idx].device);
-				/*
-				 * allot the first empty slot in the array
-				 */				
-				for (count=0; count < BOARD_COUNT; count++) {				
-					if (isi_card[count].base == 0) {
-						isi_card[count].base = ioaddr;
-						isi_card[count].irq = pciirq;
-						isi_card[count].isa = NO;
-						card++;
-						break;
-					}
-				}
-			}				
-			if (card >= BOARD_COUNT) break;
-		}
-	}
-	
-	if (!(isi_card[0].base || isi_card[1].base || isi_card[2].base || isi_card[3].base)) {
-		printk(KERN_ERR "ISICOM: No valid card configuration. Driver cannot be initialized...\n"); 
-		return -EIO;
-	}	
-
-	retval = misc_register(&isiloader_device);
-	if (retval < 0) {
-		printk(KERN_ERR "ISICOM: Unable to register firmware loader driver.\n");
-		return retval;
-	}
-	
-	if (!isicom_init()) {
-		if (misc_deregister(&isiloader_device)) 
-			printk(KERN_ERR "ISICOM: Unable to unregister Firmware Loader driver\n");
-		return -EIO;
-	}
-	
-	init_timer(&tx);
-	tx.expires = jiffies + 1;
-	tx.data = 0;
-	tx.function = isicom_tx;
-	re_schedule = 1;
-	add_timer(&tx);
-	
-	return 0;
-}
-
-static void __exit isicom_exit(void)
-{
-	re_schedule = 0;
-	/* FIXME */
-	msleep(1000);
-	unregister_isr();
-	unregister_drivers();
-	unregister_ioregion();	
-	if(tmp_buf)
-		free_page((unsigned long)tmp_buf);
-	if (misc_deregister(&isiloader_device))
-		printk(KERN_ERR "ISICOM: Unable to unregister Firmware Loader driver\n");
-}
-
-module_init(isicom_setup);
-module_exit(isicom_exit);
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index ce3bc0d..28c5a31 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -135,7 +135,7 @@
 	/*{ BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },*/
 };
 
-static int	stli_nrbrds = sizeof(stli_brdconf) / sizeof(stlconf_t);
+static int	stli_nrbrds = ARRAY_SIZE(stli_brdconf);
 
 /*
  *	There is some experimental EISA board detection code in this driver.
@@ -406,7 +406,7 @@
 	0xff000000, 0xff010000, 0xff020000, 0xff030000,
 };
 
-static int	stli_eisamempsize = sizeof(stli_eisamemprobeaddrs) / sizeof(unsigned long);
+static int	stli_eisamempsize = ARRAY_SIZE(stli_eisamemprobeaddrs);
 
 /*
  *	Define the Stallion PCI vendor and device IDs.
@@ -899,15 +899,13 @@
 {
 	stlconf_t	conf;
 	stlibrd_t	*brdp;
-	int		nrargs, i;
+	int		i;
 
 #ifdef DEBUG
 	printk("stli_argbrds()\n");
 #endif
 
-	nrargs = sizeof(stli_brdsp) / sizeof(char **);
-
-	for (i = stli_nrbrds; (i < nrargs); i++) {
+	for (i = stli_nrbrds; i < ARRAY_SIZE(stli_brdsp); i++) {
 		memset(&conf, 0, sizeof(conf));
 		if (stli_parsebrd(&conf, stli_brdsp[i]) == 0)
 			continue;
@@ -967,7 +965,7 @@
 static int stli_parsebrd(stlconf_t *confp, char **argp)
 {
 	char	*sp;
-	int	nrbrdnames, i;
+	int	i;
 
 #ifdef DEBUG
 	printk("stli_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
@@ -979,14 +977,13 @@
 	for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
 		*sp = TOLOWER(*sp);
 
-	nrbrdnames = sizeof(stli_brdstr) / sizeof(stlibrdtype_t);
-	for (i = 0; (i < nrbrdnames); i++) {
+	for (i = 0; i < ARRAY_SIZE(stli_brdstr); i++) {
 		if (strcmp(stli_brdstr[i].name, argp[0]) == 0)
 			break;
 	}
-	if (i >= nrbrdnames) {
+	if (i == ARRAY_SIZE(stli_brdstr)) {
 		printk("STALLION: unknown board name, %s?\n", argp[0]);
-		return(0);
+		return 0;
 	}
 
 	confp->brdtype = stli_brdstr[i].type;
@@ -2714,17 +2711,13 @@
 		stlen = size - tail;
 	}
 
-	len = MIN(len, (TTY_FLIPBUF_SIZE - tty->flip.count));
+	len = tty_buffer_request_room(tty, len);
+	/* FIXME : iomap ? */
 	shbuf = (volatile char *) EBRDGETMEMPTR(brdp, portp->rxoffset);
 
 	while (len > 0) {
 		stlen = MIN(len, stlen);
-		memcpy(tty->flip.char_buf_ptr, (char *) (shbuf + tail), stlen);
-		memset(tty->flip.flag_buf_ptr, 0, stlen);
-		tty->flip.char_buf_ptr += stlen;
-		tty->flip.flag_buf_ptr += stlen;
-		tty->flip.count += stlen;
-
+		tty_insert_flip_string(tty, (char *)(shbuf + tail), stlen);
 		len -= stlen;
 		tail += stlen;
 		if (tail >= size) {
@@ -2909,16 +2902,12 @@
 
 		if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) {
 			if (tty != (struct tty_struct *) NULL) {
-				if (tty->flip.count < TTY_FLIPBUF_SIZE) {
-					tty->flip.count++;
-					*tty->flip.flag_buf_ptr++ = TTY_BREAK;
-					*tty->flip.char_buf_ptr++ = 0;
-					if (portp->flags & ASYNC_SAK) {
-						do_SAK(tty);
-						EBRDENABLE(brdp);
-					}
-					tty_schedule_flip(tty);
+				tty_insert_flip_char(tty, 0, TTY_BREAK);
+				if (portp->flags & ASYNC_SAK) {
+					do_SAK(tty);
+					EBRDENABLE(brdp);
 				}
+				tty_schedule_flip(tty);
 			}
 		}
 
@@ -4943,7 +4932,7 @@
 	if (portp->tty != (struct tty_struct *) NULL) {
 		if (portp->tty->driver_data == portp) {
 			stli_comstats.ttystate = portp->tty->flags;
-			stli_comstats.rxbuffered = portp->tty->flip.count;
+			stli_comstats.rxbuffered = -1 /*portp->tty->flip.count*/;
 			if (portp->tty->termios != (struct termios *) NULL) {
 				stli_comstats.cflags = portp->tty->termios->c_cflag;
 				stli_comstats.iflags = portp->tty->termios->c_iflag;
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 704c3c0..29c41f4 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -534,7 +534,7 @@
  	return virtr + wrote;
 }
 
-#if (defined(CONFIG_ISA) || !defined(__mc68000__)) && (!defined(CONFIG_PPC_ISERIES) || defined(CONFIG_PCI))
+#if defined(CONFIG_ISA) || !defined(__mc68000__)
 static ssize_t read_port(struct file * file, char __user * buf,
 			 size_t count, loff_t *ppos)
 {
@@ -795,7 +795,7 @@
 	.write		= write_null,
 };
 
-#if (defined(CONFIG_ISA) || !defined(__mc68000__)) && (!defined(CONFIG_PPC_ISERIES) || defined(CONFIG_PCI))
+#if defined(CONFIG_ISA) || !defined(__mc68000__)
 static struct file_operations port_fops = {
 	.llseek		= memory_lseek,
 	.read		= read_port,
@@ -865,7 +865,7 @@
 		case 3:
 			filp->f_op = &null_fops;
 			break;
-#if (defined(CONFIG_ISA) || !defined(__mc68000__)) && (!defined(CONFIG_PPC_ISERIES) || defined(CONFIG_PCI))
+#if defined(CONFIG_ISA) || !defined(__mc68000__)
 		case 4:
 			filp->f_op = &port_fops;
 			break;
@@ -912,7 +912,7 @@
 	{1, "mem",     S_IRUSR | S_IWUSR | S_IRGRP, &mem_fops},
 	{2, "kmem",    S_IRUSR | S_IWUSR | S_IRGRP, &kmem_fops},
 	{3, "null",    S_IRUGO | S_IWUGO,           &null_fops},
-#if (defined(CONFIG_ISA) || !defined(__mc68000__)) && (!defined(CONFIG_PPC_ISERIES) || defined(CONFIG_PCI))
+#if defined(CONFIG_ISA) || !defined(__mc68000__)
 	{4, "port",    S_IRUSR | S_IWUSR | S_IRGRP, &port_fops},
 #endif
 	{5, "zero",    S_IRUGO | S_IWUGO,           &zero_fops},
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index 79e490e..f43c2e0 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -269,7 +269,7 @@
 static int MoxaPortDCDON(int);
 static void MoxaPortFlushData(int, int);
 static int MoxaPortWriteData(int, unsigned char *, int);
-static int MoxaPortReadData(int, unsigned char *, int);
+static int MoxaPortReadData(int, struct tty_struct *tty);
 static int MoxaPortTxQueue(int);
 static int MoxaPortRxQueue(int);
 static int MoxaPortTxFree(int);
@@ -301,6 +301,8 @@
 	.tiocmset = moxa_tiocmset,
 };
 
+static spinlock_t moxa_lock = SPIN_LOCK_UNLOCKED;
+
 #ifdef CONFIG_PCI
 static int moxa_get_PCI_conf(struct pci_dev *p, int board_type, moxa_board_conf * board)
 {
@@ -448,7 +450,7 @@
 #ifdef CONFIG_PCI
 	{
 		struct pci_dev *p = NULL;
-		int n = (sizeof(moxa_pcibrds) / sizeof(moxa_pcibrds[0])) - 1;
+		int n = ARRAY_SIZE(moxa_pcibrds) - 1;
 		i = 0;
 		while (i < n) {
 			while ((p = pci_get_device(moxa_pcibrds[i].vendor, moxa_pcibrds[i].device, p))!=NULL)
@@ -645,10 +647,10 @@
 	if (ch == NULL)
 		return (0);
 	port = ch->port;
-	save_flags(flags);
-	cli();
+
+	spin_lock_irqsave(&moxa_lock, flags);
 	len = MoxaPortWriteData(port, (unsigned char *) buf, count);
-	restore_flags(flags);
+	spin_unlock_irqrestore(&moxa_lock, flags);
 
 	/*********************************************
 	if ( !(ch->statusflags & LOWWAIT) &&
@@ -723,11 +725,10 @@
 	if (ch == NULL)
 		return;
 	port = ch->port;
-	save_flags(flags);
-	cli();
+	spin_lock_irqsave(&moxa_lock, flags);
 	moxaXmitBuff[0] = c;
 	MoxaPortWriteData(port, moxaXmitBuff, 1);
-	restore_flags(flags);
+	spin_unlock_irqrestore(&moxa_lock, flags);
 	/************************************************
 	if ( !(ch->statusflags & LOWWAIT) && (MoxaPortTxFree(port) <= 100) )
 	*************************************************/
@@ -1030,12 +1031,12 @@
 	printk("block_til_ready before block: ttys%d, count = %d\n",
 	       ch->line, ch->count);
 #endif
-	save_flags(flags);
-	cli();
+	spin_lock_irqsave(&moxa_lock, flags);
 	if (!tty_hung_up_p(filp))
 		ch->count--;
-	restore_flags(flags);
 	ch->blocked_open++;
+	spin_unlock_irqrestore(&moxa_lock, flags);
+
 	while (1) {
 		set_current_state(TASK_INTERRUPTIBLE);
 		if (tty_hung_up_p(filp) ||
@@ -1062,17 +1063,21 @@
 	}
 	set_current_state(TASK_RUNNING);
 	remove_wait_queue(&ch->open_wait, &wait);
+
+	spin_lock_irqsave(&moxa_lock, flags);
 	if (!tty_hung_up_p(filp))
 		ch->count++;
 	ch->blocked_open--;
+	spin_unlock_irqrestore(&moxa_lock, flags);
 #ifdef SERIAL_DEBUG_OPEN
 	printk("block_til_ready after blocking: ttys%d, count = %d\n",
 	       ch->line, ch->count);
 #endif
 	if (retval)
 		return (retval);
+	/* FIXME: review to see if we need to use set_bit on these */
 	ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
-	return (0);
+	return 0;
 }
 
 static void setup_empty_event(struct tty_struct *tty)
@@ -1080,15 +1085,14 @@
 	struct moxa_str *ch = tty->driver_data;
 	unsigned long flags;
 
-	save_flags(flags);
-	cli();
+	spin_lock_irqsave(&moxa_lock, flags);
 	ch->statusflags |= EMPTYWAIT;
 	moxaEmptyTimer_on[ch->port] = 0;
 	del_timer(&moxaEmptyTimer[ch->port]);
 	moxaEmptyTimer[ch->port].expires = jiffies + HZ;
 	moxaEmptyTimer_on[ch->port] = 1;
 	add_timer(&moxaEmptyTimer[ch->port]);
-	restore_flags(flags);
+	spin_unlock_irqrestore(&moxa_lock, flags);
 }
 
 static void check_xmit_empty(unsigned long data)
@@ -1135,8 +1139,6 @@
 {
 	struct tty_struct *tp;
 	struct termios *ts;
-	int i, count, rc, space;
-	unsigned char *charptr, *flagptr;
 	unsigned long flags;
 
 	ts = NULL;
@@ -1150,24 +1152,10 @@
 		MoxaPortFlushData(ch->port, 0);
 		return;
 	}
-	space = TTY_FLIPBUF_SIZE - tp->flip.count;
-	if (space <= 0)
-		return;
-	charptr = tp->flip.char_buf_ptr;
-	flagptr = tp->flip.flag_buf_ptr;
-	rc = tp->flip.count;
-	save_flags(flags);
-	cli();
-	count = MoxaPortReadData(ch->port, charptr, space);
-	restore_flags(flags);
-	for (i = 0; i < count; i++)
-		*flagptr++ = 0;
-	charptr += count;
-	rc += count;
-	tp->flip.count = rc;
-	tp->flip.char_buf_ptr = charptr;
-	tp->flip.flag_buf_ptr = flagptr;
-	tty_schedule_flip(ch->tty);
+	spin_lock_irqsave(&moxa_lock, flags);
+	MoxaPortReadData(ch->port, tp);
+	spin_unlock_irqrestore(&moxa_lock, flags);
+	tty_schedule_flip(tp);
 }
 
 #define Magic_code	0x404
@@ -1661,6 +1649,8 @@
 	case MOXA_FIND_BOARD:
 	case MOXA_LOAD_C320B:
 	case MOXA_LOAD_CODE:
+		if (!capable(CAP_SYS_RAWIO))
+			return -EPERM;
 		break;
 	}
 
@@ -1774,7 +1764,7 @@
  *	14. MoxaPortDCDON(int port);					     *
  *	15. MoxaPortFlushData(int port, int mode);	                     *
  *	16. MoxaPortWriteData(int port, unsigned char * buffer, int length); *
- *	17. MoxaPortReadData(int port, unsigned char * buffer, int length);  *
+ *	17. MoxaPortReadData(int port, struct tty_struct *tty); 	     *
  *	18. MoxaPortTxBufSize(int port);				     *
  *	19. MoxaPortRxBufSize(int port);				     *
  *	20. MoxaPortTxQueue(int port);					     *
@@ -2003,10 +1993,9 @@
  *
  *      Function 21:    Read data.
  *      Syntax:
- *      int  MoxaPortReadData(int port, unsigned char * buffer, int length);
+ *      int  MoxaPortReadData(int port, struct tty_struct *tty);
  *           int port           : port number (0 - 127)
- *           unsigned char * buffer     : pointer to read data buffer.
- *           int length         : read data buffer length
+ *	     struct tty_struct *tty : tty for data
  *
  *           return:    0 - length      : real read data length
  *
@@ -2504,7 +2493,7 @@
 	return (total);
 }
 
-int MoxaPortReadData(int port, unsigned char * buffer, int space)
+int MoxaPortReadData(int port, struct tty_struct *tty)
 {
 	register ushort head, pageofs;
 	int i, count, cnt, len, total, remain;
@@ -2522,9 +2511,9 @@
 	count = (tail >= head) ? (tail - head)
 	    : (tail - head + rx_mask + 1);
 	if (count == 0)
-		return (0);
+		return 0;
 
-	total = (space > count) ? count : space;
+	total = count;
 	remain = count - total;
 	moxaLog.rxcnt[port] += total;
 	count = total;
@@ -2539,7 +2528,7 @@
 			len = (count > len) ? len : count;
 			ofs = baseAddr + DynPage_addr + bufhead + head;
 			for (i = 0; i < len; i++)
-				*buffer++ = readb(ofs + i);
+				tty_insert_flip_char(tty, readb(ofs + i), TTY_NORMAL);
 			head = (head + len) & rx_mask;
 			count -= len;
 		}
@@ -2556,7 +2545,7 @@
 			writew(pageno, baseAddr + Control_reg);
 			ofs = baseAddr + DynPage_addr + pageofs;
 			for (i = 0; i < cnt; i++)
-				*buffer++ = readb(ofs + i);
+				tty_insert_flip_char(tty, readb(ofs + i), TTY_NORMAL);
 			if (count == 0) {
 				writew((head + len) & rx_mask, ofsAddr + RXrptr);
 				break;
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index 26448f1..ea725a9 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -813,7 +813,7 @@
 
 	/* start finding PCI board here */
 #ifdef CONFIG_PCI
-	n = (sizeof(mxser_pcibrds) / sizeof(mxser_pcibrds[0])) - 1;
+	n = ARRAY_SIZE(mxser_pcibrds) - 1;
 	index = 0;
 	b = 0;
 	while (b < n) {
@@ -1982,7 +1982,7 @@
 
 	spin_lock_irqsave(&info->slock, flags);
 
-	recv_room = tty->ldisc.receive_room(tty);
+	recv_room = tty->receive_room;
 	if ((recv_room == 0) && (!info->ldisc_stop_rx)) {
 		//mxser_throttle(tty);
 		mxser_stoprx(tty);
diff --git a/drivers/char/n_hdlc.c b/drivers/char/n_hdlc.c
index a133a62..9f54733 100644
--- a/drivers/char/n_hdlc.c
+++ b/drivers/char/n_hdlc.c
@@ -191,7 +191,6 @@
 				    poll_table *wait);
 static int n_hdlc_tty_open(struct tty_struct *tty);
 static void n_hdlc_tty_close(struct tty_struct *tty);
-static int n_hdlc_tty_room(struct tty_struct *tty);
 static void n_hdlc_tty_receive(struct tty_struct *tty, const __u8 *cp,
 			       char *fp, int count);
 static void n_hdlc_tty_wakeup(struct tty_struct *tty);
@@ -212,7 +211,6 @@
 	.ioctl		= n_hdlc_tty_ioctl,
 	.poll		= n_hdlc_tty_poll,
 	.receive_buf	= n_hdlc_tty_receive,
-	.receive_room	= n_hdlc_tty_room,
 	.write_wakeup	= n_hdlc_tty_wakeup,
 };
 
@@ -337,6 +335,7 @@
 		
 	tty->disc_data = n_hdlc;
 	n_hdlc->tty    = tty;
+	tty->receive_room = 65536;
 	
 #if defined(TTY_NO_WRITE_SPLIT)
 	/* change tty_io write() to not split large writes into 8K chunks */
@@ -478,22 +477,6 @@
 }	/* end of n_hdlc_tty_wakeup() */
 
 /**
- * n_hdlc_tty_room - Return the amount of space left in the receiver's buffer
- * @tty	- pointer to associated tty instance data
- *
- * Callback function from tty driver. Return the amount of space left in the
- * receiver's buffer to decide if remote transmitter is to be throttled.
- */
-static int n_hdlc_tty_room(struct tty_struct *tty)
-{
-	if (debuglevel >= DEBUG_LEVEL_INFO)	
-		printk("%s(%d)n_hdlc_tty_room() called\n",__FILE__,__LINE__);
-	/* always return a larger number to prevent */
-	/* throttling of remote transmitter. */
-	return 65536;
-}	/* end of n_hdlc_tty_root() */
-
-/**
  * n_hdlc_tty_receive - Called by tty driver when receive data is available
  * @tty	- pointer to tty instance data
  * @data - pointer to received data
diff --git a/drivers/char/n_r3964.c b/drivers/char/n_r3964.c
index 853c98c..c48de09 100644
--- a/drivers/char/n_r3964.c
+++ b/drivers/char/n_r3964.c
@@ -147,7 +147,6 @@
 		      struct poll_table_struct  *wait);
 static void r3964_receive_buf(struct tty_struct *tty, const unsigned char *cp,
                               char *fp, int count);
-static int  r3964_receive_room(struct tty_struct *tty);
 
 static struct tty_ldisc tty_ldisc_N_R3964 = {
 	.owner	 = THIS_MODULE,
@@ -161,7 +160,6 @@
 	.set_termios = r3964_set_termios,
 	.poll	= r3964_poll,            
 	.receive_buf = r3964_receive_buf,
-	.receive_room = r3964_receive_room,
 };
 
 
@@ -1119,6 +1117,7 @@
    pInfo->nRetry = 0;
    
    tty->disc_data = pInfo;
+   tty->receive_room = 65536;
 
    init_timer(&pInfo->tmr);
    pInfo->tmr.data = (unsigned long)pInfo;
@@ -1405,12 +1404,5 @@
     }
 }
 
-static int r3964_receive_room(struct tty_struct *tty)
-{
-   TRACE_L("receive_room");
-   return -1;
-}
-
-
 MODULE_LICENSE("GPL");
 MODULE_ALIAS_LDISC(N_R3964);
diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c
index c556f4d..ccad7ae 100644
--- a/drivers/char/n_tty.c
+++ b/drivers/char/n_tty.c
@@ -78,7 +78,32 @@
 		free_page((unsigned long) buf);
 }
 
-static inline void put_tty_queue_nolock(unsigned char c, struct tty_struct *tty)
+/**
+ *	n_tty_set__room	-	receive space
+ *	@tty: terminal
+ *
+ *	Called by the driver to find out how much data it is
+ *	permitted to feed to the line discipline without any being lost
+ *	and thus to manage flow control. Not serialized. Answers for the
+ *	"instant".
+ */
+
+static void n_tty_set_room(struct tty_struct *tty)
+{
+	int	left = N_TTY_BUF_SIZE - tty->read_cnt - 1;
+
+	/*
+	 * If we are doing input canonicalization, and there are no
+	 * pending newlines, let characters through without limit, so
+	 * that erase characters will be handled.  Other excess
+	 * characters will be beeped.
+	 */
+	if (left <= 0)
+		left = tty->icanon && !tty->canon_data;
+	tty->receive_room = left;
+}
+
+static void put_tty_queue_nolock(unsigned char c, struct tty_struct *tty)
 {
 	if (tty->read_cnt < N_TTY_BUF_SIZE) {
 		tty->read_buf[tty->read_head] = c;
@@ -87,7 +112,7 @@
 	}
 }
 
-static inline void put_tty_queue(unsigned char c, struct tty_struct *tty)
+static void put_tty_queue(unsigned char c, struct tty_struct *tty)
 {
 	unsigned long flags;
 	/*
@@ -136,6 +161,7 @@
 	spin_unlock_irqrestore(&tty->read_lock, flags);
 	tty->canon_head = tty->canon_data = tty->erasing = 0;
 	memset(&tty->read_flags, 0, sizeof tty->read_flags);
+	n_tty_set_room(tty);
 	check_unthrottle(tty);
 }
 
@@ -838,30 +864,6 @@
 	put_tty_queue(c, tty);
 }	
 
-/**
- *	n_tty_receive_room	-	receive space
- *	@tty: terminal
- *
- *	Called by the driver to find out how much data it is
- *	permitted to feed to the line discipline without any being lost
- *	and thus to manage flow control. Not serialized. Answers for the
- *	"instant".
- */
- 
-static int n_tty_receive_room(struct tty_struct *tty)
-{
-	int	left = N_TTY_BUF_SIZE - tty->read_cnt - 1;
-
-	/*
-	 * If we are doing input canonicalization, and there are no
-	 * pending newlines, let characters through without limit, so
-	 * that erase characters will be handled.  Other excess
-	 * characters will be beeped.
-	 */
-	if (left <= 0)
-		left = tty->icanon && !tty->canon_data;
-	return left;
-}
 
 /**
  *	n_tty_write_wakeup	-	asynchronous I/O notifier
@@ -953,6 +955,8 @@
 			tty->driver->flush_chars(tty);
 	}
 
+	n_tty_set_room(tty);
+
 	if (!tty->icanon && (tty->read_cnt >= tty->minimum_to_wake)) {
 		kill_fasync(&tty->fasync, SIGIO, POLL_IN);
 		if (waitqueue_active(&tty->read_wait))
@@ -964,7 +968,7 @@
 	 * mode.  We don't want to throttle the driver if we're in
 	 * canonical mode and don't have a newline yet!
 	 */
-	if (n_tty_receive_room(tty) < TTY_THRESHOLD_THROTTLE) {
+	if (tty->receive_room < TTY_THRESHOLD_THROTTLE) {
 		/* check TTY_THROTTLED first so it indicates our state */
 		if (!test_and_set_bit(TTY_THROTTLED, &tty->flags) &&
 		    tty->driver->throttle)
@@ -999,6 +1003,7 @@
 	if (test_bit(TTY_HW_COOK_IN, &tty->flags)) {
 		tty->raw = 1;
 		tty->real_raw = 1;
+		n_tty_set_room(tty);
 		return;
 	}
 	if (I_ISTRIP(tty) || I_IUCLC(tty) || I_IGNCR(tty) ||
@@ -1051,6 +1056,7 @@
 		else
 			tty->real_raw = 0;
 	}
+	n_tty_set_room(tty);
 }
 
 /**
@@ -1130,7 +1136,7 @@
  *
  */
  
-static inline int copy_from_read_buf(struct tty_struct *tty,
+static int copy_from_read_buf(struct tty_struct *tty,
 				      unsigned char __user **b,
 				      size_t *nr)
 
@@ -1308,6 +1314,7 @@
 				retval = -ERESTARTSYS;
 				break;
 			}
+			n_tty_set_room(tty);
 			clear_bit(TTY_DONT_FLIP, &tty->flags);
 			timeout = schedule_timeout(timeout);
 			set_bit(TTY_DONT_FLIP, &tty->flags);
@@ -1401,6 +1408,8 @@
 	} else if (test_and_clear_bit(TTY_PUSH, &tty->flags))
 		 goto do_it_again;
 
+	n_tty_set_room(tty);
+
 	return retval;
 }
 
@@ -1553,7 +1562,6 @@
 	normal_poll,		/* poll */
 	NULL,			/* hangup */
 	n_tty_receive_buf,	/* receive_buf */
-	n_tty_receive_room,	/* receive_room */
 	n_tty_write_wakeup	/* write_wakeup */
 };
 
diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
index 1af733d..3556ccd 100644
--- a/drivers/char/nvram.c
+++ b/drivers/char/nvram.c
@@ -557,13 +557,13 @@
 	    (nvram[6] & 1) ? (nvram[6] >> 6) + 1 : 0);
 	PRINT_PROC("Floppy 0 type  : ");
 	type = nvram[2] >> 4;
-	if (type < sizeof (floppy_types) / sizeof (*floppy_types))
+	if (type < ARRAY_SIZE(floppy_types))
 		PRINT_PROC("%s\n", floppy_types[type]);
 	else
 		PRINT_PROC("%d (unknown)\n", type);
 	PRINT_PROC("Floppy 1 type  : ");
 	type = nvram[2] & 0x0f;
-	if (type < sizeof (floppy_types) / sizeof (*floppy_types))
+	if (type < ARRAY_SIZE(floppy_types))
 		PRINT_PROC("%s\n", floppy_types[type]);
 	else
 		PRINT_PROC("%d (unknown)\n", type);
@@ -843,8 +843,6 @@
 	"2", "4", "16", "256", "65536", "??", "??", "??"
 };
 
-#define fieldsize(a)	(sizeof(a)/sizeof(*a))
-
 static int
 atari_proc_infos(unsigned char *nvram, char *buffer, int *len,
     off_t *begin, off_t offset, int size)
@@ -856,7 +854,7 @@
 	PRINT_PROC("Checksum status  : %svalid\n", checksum ? "" : "not ");
 
 	PRINT_PROC("Boot preference  : ");
-	for (i = fieldsize(boot_prefs) - 1; i >= 0; --i) {
+	for (i = ARRAY_SIZE(boot_prefs) - 1; i >= 0; --i) {
 		if (nvram[1] == boot_prefs[i].val) {
 			PRINT_PROC("%s\n", boot_prefs[i].name);
 			break;
@@ -878,12 +876,12 @@
 		return 1;
 
 	PRINT_PROC("OS language      : ");
-	if (nvram[6] < fieldsize(languages))
+	if (nvram[6] < ARRAY_SIZE(languages))
 		PRINT_PROC("%s\n", languages[nvram[6]]);
 	else
 		PRINT_PROC("%u (undefined)\n", nvram[6]);
 	PRINT_PROC("Keyboard language: ");
-	if (nvram[7] < fieldsize(languages))
+	if (nvram[7] < ARRAY_SIZE(languages))
 		PRINT_PROC("%s\n", languages[nvram[7]]);
 	else
 		PRINT_PROC("%u (undefined)\n", nvram[7]);
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index cf45b10..8a8ca32 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -1007,8 +1007,9 @@
 
 static void rx_ready_async(MGSLPC_INFO *info, int tcd)
 {
-	unsigned char data, status;
+	unsigned char data, status, flag;
 	int fifo_count;
+	int work = 0;
  	struct tty_struct *tty = info->tty;
  	struct mgsl_icount *icount = &info->icount;
 
@@ -1023,20 +1024,16 @@
 			fifo_count = 32;
 	} else
 		fifo_count = 32;
-	
+
+	tty_buffer_request_room(tty, fifo_count);
 	/* Flush received async data to receive data buffer. */ 
 	while (fifo_count) {
 		data   = read_reg(info, CHA + RXFIFO);
 		status = read_reg(info, CHA + RXFIFO);
 		fifo_count -= 2;
 
-		if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-			break;
-			
-		*tty->flip.char_buf_ptr = data;
 		icount->rx++;
-		
-		*tty->flip.flag_buf_ptr = 0;
+		flag = TTY_NORMAL;
 
 		// if no frameing/crc error then save data
 		// BIT7:parity error
@@ -1055,26 +1052,23 @@
 			status &= info->read_status_mask;
 
 			if (status & BIT7)
-				*tty->flip.flag_buf_ptr = TTY_PARITY;
+				flag = TTY_PARITY;
 			else if (status & BIT6)
-				*tty->flip.flag_buf_ptr = TTY_FRAME;
+				flag = TTY_FRAME;
 		}
-		
-		tty->flip.flag_buf_ptr++;
-		tty->flip.char_buf_ptr++;
-		tty->flip.count++;
+		work += tty_insert_flip_char(tty, data, flag);
 	}
 	issue_command(info, CHA, CMD_RXFIFO);
 
 	if (debug_level >= DEBUG_LEVEL_ISR) {
-		printk("%s(%d):rx_ready_async count=%d\n",
-			__FILE__,__LINE__,tty->flip.count);
+		printk("%s(%d):rx_ready_async",
+			__FILE__,__LINE__);
 		printk("%s(%d):rx=%d brk=%d parity=%d frame=%d overrun=%d\n",
 			__FILE__,__LINE__,icount->rx,icount->brk,
 			icount->parity,icount->frame,icount->overrun);
 	}
 			
-	if (tty->flip.count)
+	if (work)
 		tty_flip_buffer_push(tty);
 }
 
@@ -4005,7 +3999,7 @@
 {
 	static unsigned char patterns[] = 
 	    { 0x00, 0xff, 0xaa, 0x55, 0x69, 0x96, 0x0f };
-	static unsigned int count = sizeof(patterns) / sizeof(patterns[0]);
+	static unsigned int count = ARRAY_SIZE(patterns);
 	unsigned int i;
 	BOOLEAN rc = TRUE;
 	unsigned long flags;
@@ -4016,7 +4010,7 @@
 	for (i = 0; i < count; i++) {
 		write_reg(info, XAD1, patterns[i]);
 		write_reg(info, XAD2, patterns[(i + 1) % count]);
-		if ((read_reg(info, XAD1) != patterns[i]) || 
+		if ((read_reg(info, XAD1) != patterns[i]) ||
 		    (read_reg(info, XAD2) != patterns[(i + 1) % count])) {
 			rc = FALSE;
 			break;
diff --git a/drivers/char/pty.c b/drivers/char/pty.c
index 49f3997..9b5a2c0 100644
--- a/drivers/char/pty.c
+++ b/drivers/char/pty.c
@@ -111,7 +111,7 @@
 	if (!to || tty->stopped)
 		return 0;
 
-	c = to->ldisc.receive_room(to);
+	c = to->receive_room;
 	if (c > count)
 		c = count;
 	to->ldisc.receive_buf(to, buf, NULL, c);
@@ -126,7 +126,7 @@
 	if (!to || tty->stopped)
 		return 0;
 
-	return to->ldisc.receive_room(to);
+	return to->receive_room;
 }
 
 /*
diff --git a/drivers/char/random.c b/drivers/char/random.c
index bdfdfd2..86be04b 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -632,7 +632,7 @@
 	preempt_enable();
 }
 
-extern void add_input_randomness(unsigned int type, unsigned int code,
+void add_input_randomness(unsigned int type, unsigned int code,
 				 unsigned int value)
 {
 	static unsigned char last_value;
diff --git a/drivers/char/rio/board.h b/drivers/char/rio/board.h
index 0b397e1..29c9802 100644
--- a/drivers/char/rio/board.h
+++ b/drivers/char/rio/board.h
@@ -52,63 +52,57 @@
 /*
 **	The shape of the Host Control area, at offset 0x7C00, Write Only
 */
-struct s_Ctrl
-{
-	BYTE	DpCtl;				/* 7C00 */
-	BYTE	Dp_Unused2_[127];
-	BYTE	DpIntSet;			/* 7C80 */
-	BYTE	Dp_Unused3_[127];
-	BYTE	DpTpuReset;			/* 7D00 */
-	BYTE	Dp_Unused4_[127];
-	BYTE	DpIntReset;			/* 7D80 */
-	BYTE	Dp_Unused5_[127];
+struct s_Ctrl {
+	BYTE DpCtl;		/* 7C00 */
+	BYTE Dp_Unused2_[127];
+	BYTE DpIntSet;		/* 7C80 */
+	BYTE Dp_Unused3_[127];
+	BYTE DpTpuReset;	/* 7D00 */
+	BYTE Dp_Unused4_[127];
+	BYTE DpIntReset;	/* 7D80 */
+	BYTE Dp_Unused5_[127];
 };
 
 /*
 ** The PROM data area on the host (0x7C00), Read Only
 */
-struct s_Prom
-{
-	WORD	DpSlxCode[2];
-	WORD	DpRev;
-	WORD	Dp_Unused6_;
-	WORD	DpUniq[4];
-	WORD	DpJahre;
-	WORD	DpWoche;
-	WORD	DpHwFeature[5];
-	WORD	DpOemId;
-	WORD	DpSiggy[16];
+struct s_Prom {
+	WORD DpSlxCode[2];
+	WORD DpRev;
+	WORD Dp_Unused6_;
+	WORD DpUniq[4];
+	WORD DpJahre;
+	WORD DpWoche;
+	WORD DpHwFeature[5];
+	WORD DpOemId;
+	WORD DpSiggy[16];
 };
 
 /*
 ** Union of the Ctrl and Prom areas
 */
-union u_CtrlProm	/* This is the control/PROM area (0x7C00) */
-{
-	struct s_Ctrl	DpCtrl;
-	struct s_Prom	DpProm;
+union u_CtrlProm {		/* This is the control/PROM area (0x7C00) */
+	struct s_Ctrl DpCtrl;
+	struct s_Prom DpProm;
 };
 
 /*
 ** The top end of memory!
 */
-struct s_ParmMapS		/* Area containing Parm Map Pointer */
-{
-	BYTE	Dp_Unused8_[DP_PARMMAP_ADDR];
-	WORD	DpParmMapAd;
+struct s_ParmMapS {		/* Area containing Parm Map Pointer */
+	BYTE Dp_Unused8_[DP_PARMMAP_ADDR];
+	WORD DpParmMapAd;
 };
 
-struct s_StartUpS
-{
-	BYTE    Dp_Unused9_[DP_STARTUP_ADDR];
-	BYTE	Dp_LongJump[0x4];
-	BYTE	Dp_Unused10_[2];
-	BYTE	Dp_ShortJump[0x2];
+struct s_StartUpS {
+	BYTE Dp_Unused9_[DP_STARTUP_ADDR];
+	BYTE Dp_LongJump[0x4];
+	BYTE Dp_Unused10_[2];
+	BYTE Dp_ShortJump[0x2];
 };
 
-union u_Sram2ParmMap	/* This is the top of memory (0x7E00-0x7FFF) */
-{
-	BYTE	DpSramMem[DP_SRAM2_SIZE];
+union u_Sram2ParmMap {		/* This is the top of memory (0x7E00-0x7FFF) */
+	BYTE DpSramMem[DP_SRAM2_SIZE];
 	struct s_ParmMapS DpParmMapS;
 	struct s_StartUpS DpStartUpS;
 };
@@ -116,13 +110,12 @@
 /*
 **	This is the DP RAM overlay.
 */
-struct DpRam
-{
-    BYTE 		 DpSram1[DP_SRAM1_SIZE];     /* 0000 - 7BFF */
-    union u_CtrlProm     DpCtrlProm;                 /* 7C00 - 7DFF */
-    union u_Sram2ParmMap DpSram2ParmMap;             /* 7E00 - 7FFF */
-    BYTE		 DpScratch[DP_SCRATCH_SIZE]; /* 8000 - 8FFF */
-    BYTE		 DpSram3[DP_SRAM3_SIZE];     /* 9000 - FFFF */
+struct DpRam {
+	BYTE DpSram1[DP_SRAM1_SIZE];	/* 0000 - 7BFF */
+	union u_CtrlProm DpCtrlProm;	/* 7C00 - 7DFF */
+	union u_Sram2ParmMap DpSram2ParmMap;	/* 7E00 - 7FFF */
+	BYTE DpScratch[DP_SCRATCH_SIZE];	/* 8000 - 8FFF */
+	BYTE DpSram3[DP_SRAM3_SIZE];	/* 9000 - FFFF */
 };
 
 #define	DpControl	DpCtrlProm.DpCtrl.DpCtl
diff --git a/drivers/char/rio/bootpkt.h b/drivers/char/rio/bootpkt.h
index c329aeb..602266e 100644
--- a/drivers/char/rio/bootpkt.h
+++ b/drivers/char/rio/bootpkt.h
@@ -41,7 +41,7 @@
 
 #ifndef lint
 #ifdef SCCS
-static char *_rio_bootpkt_h_sccs = "@(#)bootpkt.h	1.1" ;
+static char *_rio_bootpkt_h_sccs = "@(#)bootpkt.h	1.1";
 #endif
 #endif
 
@@ -49,14 +49,13 @@
      * Overlayed onto the Data fields of a regular
      * Packet
      ************************************************/
-typedef struct BOOT_PKT BOOT_PKT ;
+typedef struct BOOT_PKT BOOT_PKT;
 struct BOOT_PKT {
-                    short     seq_num ;
-                    char      data[10] ;
-                } ;
+	short seq_num;
+	char data[10];
+};
 
 
 #endif
 
 /*********** end of file ***********/
-
diff --git a/drivers/char/rio/brates.h b/drivers/char/rio/brates.h
index bd4fc84..dd686d5 100644
--- a/drivers/char/rio/brates.h
+++ b/drivers/char/rio/brates.h
@@ -97,11 +97,10 @@
 
 #define MAX_RATE B2000
 
-struct    baud_rate            /* Tag for baud rates */
-{
-     /* short    host_rate,*/        /* As passed by the driver */
-     short    divisor,          /* The divisor */
-              prescaler;        /* The pre-scaler */
+struct baud_rate {		/* Tag for baud rates */
+	/* short    host_rate, *//* As passed by the driver */
+	short divisor,		/* The divisor */
+	 prescaler;		/* The pre-scaler */
 };
 
 #endif
diff --git a/drivers/char/rio/chan.h b/drivers/char/rio/chan.h
index 5b30654..af14311 100644
--- a/drivers/char/rio/chan.h
+++ b/drivers/char/rio/chan.h
@@ -21,7 +21,7 @@
 
 #ifndef lint
 #ifdef SCCS
-static char *_rio_chan_h_sccs = "@(#)chan.h	1.1" ;
+static char *_rio_chan_h_sccs = "@(#)chan.h	1.1";
 #endif
 #endif
 
diff --git a/drivers/char/rio/cirrus.h b/drivers/char/rio/cirrus.h
index cf056a9..217ff09 100644
--- a/drivers/char/rio/cirrus.h
+++ b/drivers/char/rio/cirrus.h
@@ -73,20 +73,20 @@
 #define	TIMER_TICK	0x82
 #define STOP_BREAK	0x83
 #define BASE(a) ((a) < 4 ? (short*)CIRRUS_FIRST : ((a) < 8 ? (short *)CIRRUS_SECOND : ((a) < 12 ? (short*)CIRRUS_THIRD : (short *)CIRRUS_FOURTH)))
-#define txack1	((short *)0x7104) 
-#define rxack1	((short *)0x7102) 
+#define txack1	((short *)0x7104)
+#define rxack1	((short *)0x7102)
 #define mdack1  ((short *)0x7106)
-#define txack2  ((short *)0x7006) 
-#define rxack2	((short *)0x7004) 
-#define mdack2  ((short *)0x7100) 
+#define txack2  ((short *)0x7006)
+#define rxack2	((short *)0x7004)
+#define mdack2  ((short *)0x7100)
 #define int_latch       ((short *) 0x7800)
-#define int_status      ((short *) 0x7c00) 
-#define tx1_pending     0x20 
-#define rx1_pending     0x10 
-#define md1_pending     0x40 
-#define tx2_pending     0x02 
-#define rx2_pending     0x01 
-#define md2_pending     0x40 
+#define int_status      ((short *) 0x7c00)
+#define tx1_pending     0x20
+#define rx1_pending     0x10
+#define md1_pending     0x40
+#define tx2_pending     0x02
+#define rx2_pending     0x01
+#define md2_pending     0x40
 #define module1_bits	0x07
 #define module1_modern	0x08
 #define module2_bits	0x70
@@ -113,65 +113,65 @@
    NB. These registers are relative values on 8 bit boundaries whereas
    on the RTA's the CIRRUS registers are on word boundaries. Use pointer
    arithmetic (short *) to obtain the real addresses required */
-#define ccr	0x05	/* Channel Command Register     */
-#define ier	0x06	/* Interrupt Enable Register    */
-#define cor1	0x08	/* Channel Option Register 1    */
-#define cor2	0x09	/* Channel Option Register 2    */
-#define cor3	0x0a	/* Channel Option Register 3    */
-#define cor4	0x1e	/* Channel Option Register 4    */
-#define	cor5	0x1f	/* Channel Option Register 5	*/
+#define ccr	0x05		/* Channel Command Register     */
+#define ier	0x06		/* Interrupt Enable Register    */
+#define cor1	0x08		/* Channel Option Register 1    */
+#define cor2	0x09		/* Channel Option Register 2    */
+#define cor3	0x0a		/* Channel Option Register 3    */
+#define cor4	0x1e		/* Channel Option Register 4    */
+#define	cor5	0x1f		/* Channel Option Register 5    */
 
-#define ccsr	0x0b	/* Channel Control Status Register */
-#define rdcr	0x0e	/* Receive Data Count Register  */
-#define tdcr	0x12	/* Transmit Data Count Register */
-#define mcor1	0x15	/* Modem Change Option Register 1 */
-#define mcor2	0x16	/* Modem Change Option Regsiter 2 */
+#define ccsr	0x0b		/* Channel Control Status Register */
+#define rdcr	0x0e		/* Receive Data Count Register  */
+#define tdcr	0x12		/* Transmit Data Count Register */
+#define mcor1	0x15		/* Modem Change Option Register 1 */
+#define mcor2	0x16		/* Modem Change Option Regsiter 2 */
 
-#define livr	0x18	/* Local Interrupt Vector Register */
-#define schr1	0x1a	/* Special Character Register 1 */
-#define schr2	0x1b	/* Special Character Register 2 */
-#define schr3	0x1c	/* Special Character Register 3 */
-#define schr4	0x1d	/* Special Character Register 4 */
+#define livr	0x18		/* Local Interrupt Vector Register */
+#define schr1	0x1a		/* Special Character Register 1 */
+#define schr2	0x1b		/* Special Character Register 2 */
+#define schr3	0x1c		/* Special Character Register 3 */
+#define schr4	0x1d		/* Special Character Register 4 */
 
-#define rtr	0x20    /* Receive Timer Register */
-#define rtpr	0x21	/* Receive Timeout Period Register */
-#define lnc	0x24	/* Lnext character */
+#define rtr	0x20		/* Receive Timer Register */
+#define rtpr	0x21		/* Receive Timeout Period Register */
+#define lnc	0x24		/* Lnext character */
 
-#define rivr	0x43	/* Receive Interrupt Vector Register    */
-#define tivr	0x42	/* Transmit Interrupt Vector Register   */
-#define mivr	0x41	/* Modem Interrupt Vector Register      */
-#define gfrcr	0x40	/* Global Firmware Revision code Reg    */
-#define ricr	0x44	/* Receive Interrupting Channel Reg     */
-#define ticr	0x45	/* Transmit Interrupting Channel Reg    */
-#define micr	0x46	/* Modem Interrupting Channel Register  */
+#define rivr	0x43		/* Receive Interrupt Vector Register    */
+#define tivr	0x42		/* Transmit Interrupt Vector Register   */
+#define mivr	0x41		/* Modem Interrupt Vector Register      */
+#define gfrcr	0x40		/* Global Firmware Revision code Reg    */
+#define ricr	0x44		/* Receive Interrupting Channel Reg     */
+#define ticr	0x45		/* Transmit Interrupting Channel Reg    */
+#define micr	0x46		/* Modem Interrupting Channel Register  */
 
-#define gcr	0x4b	/* Global configuration register*/
-#define misr    0x4c    /* Modem interrupt status register */
+#define gcr	0x4b		/* Global configuration register */
+#define misr    0x4c		/* Modem interrupt status register */
 
 #define rbusr	0x59
 #define tbusr	0x5a
 #define mbusr	0x5b
 
-#define eoir	0x60	/* End Of Interrupt Register */
-#define rdsr	0x62	/* Receive Data / Status Register */
-#define tdr	0x63	/* Transmit Data Register */
-#define svrr	0x67	/* Service Request Register */
+#define eoir	0x60		/* End Of Interrupt Register */
+#define rdsr	0x62		/* Receive Data / Status Register */
+#define tdr	0x63		/* Transmit Data Register */
+#define svrr	0x67		/* Service Request Register */
 
-#define car	0x68	/* Channel Access Register */
-#define mir	0x69	/* Modem Interrupt Register */
-#define tir	0x6a	/* Transmit Interrupt Register */
-#define rir	0x6b	/* Receive Interrupt Register */
-#define msvr1	0x6c	/* Modem Signal Value Register 1 */
-#define msvr2	0x6d	/* Modem Signal Value Register 2*/
-#define psvr	0x6f	/* Printer Signal Value Register*/
+#define car	0x68		/* Channel Access Register */
+#define mir	0x69		/* Modem Interrupt Register */
+#define tir	0x6a		/* Transmit Interrupt Register */
+#define rir	0x6b		/* Receive Interrupt Register */
+#define msvr1	0x6c		/* Modem Signal Value Register 1 */
+#define msvr2	0x6d		/* Modem Signal Value Register 2 */
+#define psvr	0x6f		/* Printer Signal Value Register */
 
-#define tbpr	0x72	/* Transmit Baud Rate Period Register */
-#define tcor	0x76	/* Transmit Clock Option Register */
+#define tbpr	0x72		/* Transmit Baud Rate Period Register */
+#define tcor	0x76		/* Transmit Clock Option Register */
 
-#define rbpr	0x78	/* Receive Baud Rate Period Register */
-#define rber	0x7a	/* Receive Baud Rate Extension Register */
-#define rcor	0x7c	/* Receive Clock Option Register*/
-#define ppr	0x7e	/* Prescalar Period Register    */
+#define rbpr	0x78		/* Receive Baud Rate Period Register */
+#define rber	0x7a		/* Receive Baud Rate Extension Register */
+#define rcor	0x7c		/* Receive Clock Option Register */
+#define ppr	0x7e		/* Prescalar Period Register    */
 
 /* Misc registers used for forcing the 1400 out of its reset woes */
 #define airl	0x6d
@@ -192,10 +192,10 @@
 
 /* RDSR - when status read from FIFO */
 #define	RDSR_BREAK		0x08	/* Break received */
-#define RDSR_TIMEOUT    	0x80    /* No new data timeout */
-#define RDSR_SC1  	  	0x10    /* Special char 1 (tx XON) matched */
-#define RDSR_SC2  	  	0x20    /* Special char 2 (tx XOFF) matched */
-#define RDSR_SC12_MASK	  	0x30    /* Mask for special chars 1 and 2 */
+#define RDSR_TIMEOUT    	0x80	/* No new data timeout */
+#define RDSR_SC1  	  	0x10	/* Special char 1 (tx XON) matched */
+#define RDSR_SC2  	  	0x20	/* Special char 2 (tx XOFF) matched */
+#define RDSR_SC12_MASK	  	0x30	/* Mask for special chars 1 and 2 */
 
 /* PPR */
 #define PPR_DEFAULT	0x31	/* Default value - for a 25Mhz clock gives
@@ -244,7 +244,7 @@
 #define IER_TIMEOUT	0x01	/* Timeout on no data */
 
 #define	IER_DEFAULT	0x94	/* Default values */
-#define IER_PARALLEL    0x84    /* Default for Parallel */
+#define IER_PARALLEL    0x84	/* Default for Parallel */
 #define	IER_EMPTY	0x92	/* Transmitter empty rather than ready */
 
 /* COR1 - Driver only */
@@ -264,11 +264,11 @@
 #define	COR1_7BITS	0x02	/* 7 data bits */
 #define	COR1_8BITS	0x03	/* 8 data bits */
 
-#define COR1_HOST       0xef    /* Safe host bits */
+#define COR1_HOST       0xef	/* Safe host bits */
 
 /* RTA only */
-#define COR1_CINPCK     0x00    /* Check parity of received characters */
-#define COR1_CNINPCK    0x10    /* Don't check parity */
+#define COR1_CINPCK     0x00	/* Check parity of received characters */
+#define COR1_CNINPCK    0x10	/* Don't check parity */
 
 /* COR2 bits for both RTA and driver use */
 #define	COR2_IXANY	0x80	/* IXANY - any character is XON */
@@ -293,9 +293,9 @@
 #define	COR3_FCT	0x20	/* Flow control transparency */
 #define	COR3_SCD12	0x10	/* Special character detect for SCHR's 1 + 2 */
 #define	COR3_FIFO12	0x0c	/* 12 chars for receive FIFO threshold */
-#define COR3_FIFO10     0x0a    /* 10 chars for receive FIFO threshold */
-#define COR3_FIFO8      0x08    /* 8 chars for receive FIFO threshold */
-#define COR3_FIFO6      0x06    /* 6 chars for receive FIFO threshold */
+#define COR3_FIFO10     0x0a	/* 10 chars for receive FIFO threshold */
+#define COR3_FIFO8      0x08	/* 8 chars for receive FIFO threshold */
+#define COR3_FIFO6      0x06	/* 6 chars for receive FIFO threshold */
 
 #define COR3_THRESHOLD  COR3_FIFO8	/* MUST BE LESS THAN MCOR_THRESHOLD */
 
@@ -386,7 +386,7 @@
 
 #define	MCOR_THRESHBITS 0x0F	/* mask for ANDing out the above */
 
-#define	MCOR_THRESHOLD	MCOR_THRESH9 /* MUST BE GREATER THAN COR3_THRESHOLD */
+#define	MCOR_THRESHOLD	MCOR_THRESH9	/* MUST BE GREATER THAN COR3_THRESHOLD */
 
 
 /* RTPR */
@@ -429,25 +429,25 @@
 #define CONFIG		0x01	/* Configure a port */
 #define	MOPEN		0x02	/* Modem open (block for DCD) */
 #define	CLOSE		0x03	/* Close a port */
-#define	WFLUSH		(0x04 | PRE_EMPTIVE) /* Write flush */
-#define	RFLUSH		(0x05 | PRE_EMPTIVE) /* Read flush */
-#define	RESUME		(0x06 | PRE_EMPTIVE) /* Resume if xoffed */
-#define	SBREAK		0x07 	/* Start break */
+#define	WFLUSH		(0x04 | PRE_EMPTIVE)	/* Write flush */
+#define	RFLUSH		(0x05 | PRE_EMPTIVE)	/* Read flush */
+#define	RESUME		(0x06 | PRE_EMPTIVE)	/* Resume if xoffed */
+#define	SBREAK		0x07	/* Start break */
 #define	EBREAK		0x08	/* End break */
-#define	SUSPEND		(0x09 | PRE_EMPTIVE) /* Susp op (behave as tho xoffed) */
-#define FCLOSE          (0x0a | PRE_EMPTIVE) /* Force close */
-#define XPRINT          0x0b    /* Xprint packet */
-#define MBIS		(0x0c | PRE_EMPTIVE) /* Set modem lines */
-#define MBIC		(0x0d | PRE_EMPTIVE) /* Clear modem lines */
-#define MSET		(0x0e | PRE_EMPTIVE) /* Set modem lines */
+#define	SUSPEND		(0x09 | PRE_EMPTIVE)	/* Susp op (behave as tho xoffed) */
+#define FCLOSE          (0x0a | PRE_EMPTIVE)	/* Force close */
+#define XPRINT          0x0b	/* Xprint packet */
+#define MBIS		(0x0c | PRE_EMPTIVE)	/* Set modem lines */
+#define MBIC		(0x0d | PRE_EMPTIVE)	/* Clear modem lines */
+#define MSET		(0x0e | PRE_EMPTIVE)	/* Set modem lines */
 #define PCLOSE		0x0f	/* Pseudo close - Leaves rx/tx enabled */
-#define MGET		(0x10 | PRE_EMPTIVE) /* Force update of modem status */
-#define MEMDUMP		(0x11 | PRE_EMPTIVE) /* Send back mem from addr supplied */
-#define	READ_REGISTER	(0x12 | PRE_EMPTIVE) /* Read CD1400 register (debug) */
+#define MGET		(0x10 | PRE_EMPTIVE)	/* Force update of modem status */
+#define MEMDUMP		(0x11 | PRE_EMPTIVE)	/* Send back mem from addr supplied */
+#define	READ_REGISTER	(0x12 | PRE_EMPTIVE)	/* Read CD1400 register (debug) */
 
 /* "Command" packets going from remote to host COMPLETE and MODEM_STATUS
    use data[4] / data[3] to indicate current state and modem status respectively
-*/ 
+*/
 
 #define	COMPLETE	(0x20 | PRE_EMPTIVE)
 				/* Command complete */
diff --git a/drivers/char/rio/cmd.h b/drivers/char/rio/cmd.h
index c369eda..797b624 100644
--- a/drivers/char/rio/cmd.h
+++ b/drivers/char/rio/cmd.h
@@ -42,7 +42,7 @@
 
 #ifndef lint
 #ifdef SCCS
-static char *_rio_cmd_h_sccs = "@(#)cmd.h	1.1" ;
+static char *_rio_cmd_h_sccs = "@(#)cmd.h	1.1";
 #endif
 #endif
 
@@ -52,7 +52,7 @@
 
 #define CMD_IGNORE_PKT          ( (ushort) 0)
 #define CMD_STATUS_REQ          ( (ushort) 1)
-#define CMD_UNIT_STATUS_REQ     ( (ushort) 2)     /* Is this needed ??? */
+#define CMD_UNIT_STATUS_REQ     ( (ushort) 2)	/* Is this needed ??? */
 #define CMD_CONF_PORT           ( (ushort) 3)
 #define CMD_CONF_UNIT           ( (ushort) 4)
 #define CMD_ROUTE_MAP_REQ       ( (ushort) 5)
@@ -81,4 +81,3 @@
 #endif
 
 /*********** end of file ***********/
-
diff --git a/drivers/char/rio/cmdblk.h b/drivers/char/rio/cmdblk.h
index 2b8efbd..a9a8c45 100644
--- a/drivers/char/rio/cmdblk.h
+++ b/drivers/char/rio/cmdblk.h
@@ -44,16 +44,15 @@
 ** a rup.
 */
 
-struct CmdBlk
-{
- struct CmdBlk *NextP;          /* Pointer to next command block */
- struct	PKT     Packet;         /* A packet, to copy to the rup */
-    	                        /* The func to call to check if OK */
-    	int     (*PreFuncP)(int, struct CmdBlk *);
-    	int     PreArg;         /* The arg for the func */
-    	                        /* The func to call when completed */
-    	int     (*PostFuncP)(int, struct CmdBlk *);
-    	int     PostArg;        /* The arg for the func */
+struct CmdBlk {
+	struct CmdBlk *NextP;	/* Pointer to next command block */
+	struct PKT Packet;	/* A packet, to copy to the rup */
+	/* The func to call to check if OK */
+	int (*PreFuncP) (int, struct CmdBlk *);
+	int PreArg;		/* The arg for the func */
+	/* The func to call when completed */
+	int (*PostFuncP) (int, struct CmdBlk *);
+	int PostArg;		/* The arg for the func */
 };
 
 #define NUM_RIO_CMD_BLKS (3 * (MAX_RUP * 4 + LINKS_PER_UNIT * 4))
diff --git a/drivers/char/rio/cmdpkt.h b/drivers/char/rio/cmdpkt.h
index 46befd3..77cee8d 100644
--- a/drivers/char/rio/cmdpkt.h
+++ b/drivers/char/rio/cmdpkt.h
@@ -54,135 +54,112 @@
 ** This structure overlays a PktCmd->CmdData structure, and so starts
 ** at Data[2] in the actual pkt!
 */
-struct BootSequence
-{
-    WORD	NumPackets;
-    WORD	LoadBase;
-    WORD	CodeSize;
+struct BootSequence {
+	WORD NumPackets;
+	WORD LoadBase;
+	WORD CodeSize;
 };
 
 #define	BOOT_SEQUENCE_LEN	8
 
-struct SamTop
-{
-    BYTE Unit;
-    BYTE Link;
+struct SamTop {
+	BYTE Unit;
+	BYTE Link;
 };
 
-struct CmdHdr
-{
-    BYTE PcCommand;
-    union
-    {
-    BYTE PcPhbNum;
-    BYTE PcLinkNum;
-    BYTE PcIDNum;
-    } U0;
+struct CmdHdr {
+	BYTE PcCommand;
+	union {
+		BYTE PcPhbNum;
+		BYTE PcLinkNum;
+		BYTE PcIDNum;
+	} U0;
 };
 
 
-struct PktCmd
-{
-    union
-    {
-	struct 
-	{
-	    struct CmdHdr CmdHdr;
-	    struct BootSequence PcBootSequence;
-	} S1;
-	struct
-	{
-	    WORD PcSequence;
-	    BYTE PcBootData[RTA_BOOT_DATA_SIZE];
-	} S2;
-	struct
-	{
-	    WORD  __crud__;
-	    BYTE  PcUniqNum[4];	        /* this is really a uint. */
-	    BYTE  PcModuleTypes;  	/* what modules are fitted */
-	} S3;
-	struct
-	{
-	    struct CmdHdr CmdHdr;
-	    BYTE   __undefined__;
-	    BYTE   PcModemStatus;
-	    BYTE   PcPortStatus;
-	    BYTE   PcSubCommand;	/* commands like mem or register dump */
-	    WORD   PcSubAddr;		/* Address for command */
-	    BYTE   PcSubData[64];	/* Date area for command */
-	} S4;
-	struct
-	{
-	    struct CmdHdr CmdHdr;
-	    BYTE   PcCommandText[1];
-	    BYTE   __crud__[20];
-	    BYTE   PcIDNum2;		/* It had to go somewhere! */
-	} S5;
-	struct
-	{
-	    struct CmdHdr CmdHdr;
-	    struct SamTop    Topology[LINKS_PER_UNIT];
-	} S6;
-    } U1;
+struct PktCmd {
+	union {
+		struct {
+			struct CmdHdr CmdHdr;
+			struct BootSequence PcBootSequence;
+		} S1;
+		struct {
+			WORD PcSequence;
+			BYTE PcBootData[RTA_BOOT_DATA_SIZE];
+		} S2;
+		struct {
+			WORD __crud__;
+			BYTE PcUniqNum[4];	/* this is really a uint. */
+			BYTE PcModuleTypes;	/* what modules are fitted */
+		} S3;
+		struct {
+			struct CmdHdr CmdHdr;
+			BYTE __undefined__;
+			BYTE PcModemStatus;
+			BYTE PcPortStatus;
+			BYTE PcSubCommand;	/* commands like mem or register dump */
+			WORD PcSubAddr;	/* Address for command */
+			BYTE PcSubData[64];	/* Date area for command */
+		} S4;
+		struct {
+			struct CmdHdr CmdHdr;
+			BYTE PcCommandText[1];
+			BYTE __crud__[20];
+			BYTE PcIDNum2;	/* It had to go somewhere! */
+		} S5;
+		struct {
+			struct CmdHdr CmdHdr;
+			struct SamTop Topology[LINKS_PER_UNIT];
+		} S6;
+	} U1;
 };
 
-struct PktCmd_M
-{
-    union
-    {
-	struct 
-	{
-	    struct
-	    {
-    		uchar PcCommand;
-    		union
-    		{
-    		    uchar PcPhbNum;
-    		    uchar PcLinkNum;
-    		    uchar PcIDNum;
-    		} U0;
-	    } CmdHdr;
-	    struct
-	    {
-                ushort	NumPackets;
-                ushort	LoadBase;
-                ushort	CodeSize;
-            } PcBootSequence;
-	} S1;
-	struct
-	{
-	    ushort PcSequence;
-	    uchar PcBootData[RTA_BOOT_DATA_SIZE];
-	} S2;
-	struct
-	{
-	    ushort  __crud__;
-	    uchar  PcUniqNum[4];	        /* this is really a uint. */
-	    uchar  PcModuleTypes;  	/* what modules are fitted */
-	} S3;
-	struct
-	{
-	    ushort  __cmd_hdr__;
-	    uchar   __undefined__;
-	    uchar   PcModemStatus;
-	    uchar   PcPortStatus;
-	    uchar   PcSubCommand;
-	    ushort  PcSubAddr;
-	    uchar   PcSubData[64];
-	} S4;
-	struct
-	{
-	    ushort  __cmd_hdr__;
-	    uchar   PcCommandText[1];
-	    uchar   __crud__[20];
-	    uchar   PcIDNum2;		/* Tacked on end */
-	} S5;
-	struct
-	{
-	    ushort  __cmd_hdr__;
-	    struct Top Topology[LINKS_PER_UNIT];
-	} S6;
-    } U1;
+struct PktCmd_M {
+	union {
+		struct {
+			struct {
+				uchar PcCommand;
+				union {
+					uchar PcPhbNum;
+					uchar PcLinkNum;
+					uchar PcIDNum;
+				} U0;
+			} CmdHdr;
+			struct {
+				ushort NumPackets;
+				ushort LoadBase;
+				ushort CodeSize;
+			} PcBootSequence;
+		} S1;
+		struct {
+			ushort PcSequence;
+			uchar PcBootData[RTA_BOOT_DATA_SIZE];
+		} S2;
+		struct {
+			ushort __crud__;
+			uchar PcUniqNum[4];	/* this is really a uint. */
+			uchar PcModuleTypes;	/* what modules are fitted */
+		} S3;
+		struct {
+			ushort __cmd_hdr__;
+			uchar __undefined__;
+			uchar PcModemStatus;
+			uchar PcPortStatus;
+			uchar PcSubCommand;
+			ushort PcSubAddr;
+			uchar PcSubData[64];
+		} S4;
+		struct {
+			ushort __cmd_hdr__;
+			uchar PcCommandText[1];
+			uchar __crud__[20];
+			uchar PcIDNum2;	/* Tacked on end */
+		} S5;
+		struct {
+			ushort __cmd_hdr__;
+			struct Top Topology[LINKS_PER_UNIT];
+		} S6;
+	} U1;
 };
 
 #define Command		U1.S1.CmdHdr.PcCommand
diff --git a/drivers/char/rio/control.h b/drivers/char/rio/control.h
index 1712f62..6853d03 100644
--- a/drivers/char/rio/control.h
+++ b/drivers/char/rio/control.h
@@ -51,12 +51,11 @@
 #define	UFOAD		( CONTROL + 4 )
 #define IWAIT		( CONTROL + 5 )
 
-#define	IFOAD_MAGIC	0xF0AD		/* of course */
+#define	IFOAD_MAGIC	0xF0AD	/* of course */
 #define	ZOMBIE_MAGIC	(~0xDEAD)	/* not dead -> zombie */
-#define	UFOAD_MAGIC	0xD1E		/* kill-your-neighbour */
-#define	IWAIT_MAGIC	0xB1DE		/* Bide your time */
+#define	UFOAD_MAGIC	0xD1E	/* kill-your-neighbour */
+#define	IWAIT_MAGIC	0xB1DE	/* Bide your time */
 
 #endif
 
 /*********** end of file ***********/
-
diff --git a/drivers/char/rio/daemon.h b/drivers/char/rio/daemon.h
index 62dba0e..28a991b 100644
--- a/drivers/char/rio/daemon.h
+++ b/drivers/char/rio/daemon.h
@@ -44,18 +44,16 @@
 ** structures used on /dev/rio
 */
 
-struct Error
-{
-	uint	Error;
-	uint	Entry;
-	uint	Other;
+struct Error {
+	uint Error;
+	uint Entry;
+	uint Other;
 };
 
-struct DownLoad
-{
-	char	*DataP;
-	uint	Count;
-	uint	ProductCode;
+struct DownLoad {
+	char *DataP;
+	uint Count;
+	uint ProductCode;
 };
 
 /*
@@ -66,46 +64,41 @@
 #endif
 
 #ifndef MAX_XP_CTRL_LEN
-#define	MAX_XP_CTRL_LEN 16		/* ALSO IN PORT.H */
+#define	MAX_XP_CTRL_LEN 16	/* ALSO IN PORT.H */
 #endif
 
-struct	PortSetup
-{
-	uint	From;	/* Set/Clear XP & IXANY Control from this port.... */
-	uint	To;	/* .... to this port */
-	uint	XpCps;			/* at this speed */
-	char	XpOn[MAX_XP_CTRL_LEN];	/* this is the start string */
-	char	XpOff[MAX_XP_CTRL_LEN];	/* this is the stop string */
-	uchar	IxAny;			/* enable/disable IXANY */
-	uchar	IxOn;			/* enable/disable IXON */
-	uchar	Lock;			/* lock port params */
-	uchar	Store;			/* store params across closes */
-	uchar	Drain;			/* close only when drained */
+struct PortSetup {
+	uint From;		/* Set/Clear XP & IXANY Control from this port.... */
+	uint To;		/* .... to this port */
+	uint XpCps;		/* at this speed */
+	char XpOn[MAX_XP_CTRL_LEN];	/* this is the start string */
+	char XpOff[MAX_XP_CTRL_LEN];	/* this is the stop string */
+	uchar IxAny;		/* enable/disable IXANY */
+	uchar IxOn;		/* enable/disable IXON */
+	uchar Lock;		/* lock port params */
+	uchar Store;		/* store params across closes */
+	uchar Drain;		/* close only when drained */
 };
 
-struct	LpbReq
-{
-	uint	Host;
-	uint	Link;
-	struct  LPB     *LpbP;
+struct LpbReq {
+	uint Host;
+	uint Link;
+	struct LPB *LpbP;
 };
 
-struct	RupReq
-{
-	uint	HostNum;
-	uint	RupNum;
-	struct  RUP 	*RupP;
+struct RupReq {
+	uint HostNum;
+	uint RupNum;
+	struct RUP *RupP;
 };
 
-struct	PortReq
-{
-	uint	SysPort;
-	struct  Port 	*PortP;
+struct PortReq {
+	uint SysPort;
+	struct Port *PortP;
 };
 
-struct  StreamInfo
-{
-	uint	SysPort;
+struct StreamInfo {
+	uint SysPort;
 #if 0
 	queue_t RQueue;
 	queue_t WQueue;
@@ -115,68 +108,59 @@
 #endif
 };
 
-struct	HostReq
-{
-	uint	HostNum;
-	struct  Host 	*HostP;
+struct HostReq {
+	uint HostNum;
+	struct Host *HostP;
 };
 
-struct	HostDpRam
-{
-	uint	HostNum;
-	struct	DpRam	*DpRamP;
+struct HostDpRam {
+	uint HostNum;
+	struct DpRam *DpRamP;
 };
 
-struct	DebugCtrl
-{
-	uint	SysPort;
-	uint	Debug;
-	uint	Wait;
+struct DebugCtrl {
+	uint SysPort;
+	uint Debug;
+	uint Wait;
 };
 
-struct	MapInfo
-{
-	uint	FirstPort;	/* 8 ports, starting from this (tty) number */
-	uint	RtaUnique;	/* reside on this RTA (unique number) */
+struct MapInfo {
+	uint FirstPort;		/* 8 ports, starting from this (tty) number */
+	uint RtaUnique;		/* reside on this RTA (unique number) */
 };
 
-struct	MapIn
-{
-	uint	NumEntries;		/* How many port sets are we mapping? */
-	struct  MapInfo	*MapInfoP;	/* Pointer to (user space) info */
+struct MapIn {
+	uint NumEntries;	/* How many port sets are we mapping? */
+	struct MapInfo *MapInfoP;	/* Pointer to (user space) info */
 };
 
-struct  SendPack
-{
-        unsigned int	PortNum;
-	unsigned char	Len;
-	unsigned char	Data[PKT_MAX_DATA_LEN];
+struct SendPack {
+	unsigned int PortNum;
+	unsigned char Len;
+	unsigned char Data[PKT_MAX_DATA_LEN];
 };
 
-struct SpecialRupCmd
-{
-	struct	PKT		Packet;
-	unsigned short	Host;
-	unsigned short	RupNum;
+struct SpecialRupCmd {
+	struct PKT Packet;
+	unsigned short Host;
+	unsigned short RupNum;
 };
 
-struct	IdentifyRta
-{
-	ulong	RtaUnique;
-	uchar	ID;
+struct IdentifyRta {
+	ulong RtaUnique;
+	uchar ID;
 };
 
-struct	KillNeighbour
-{
-	ulong	UniqueNum;
-	uchar	Link;
+struct KillNeighbour {
+	ulong UniqueNum;
+	uchar Link;
 };
 
 struct rioVersion {
-    char        version[MAX_VERSION_LEN];
-    char        relid[MAX_VERSION_LEN];
-    int         buildLevel;
-    char        buildDate[MAX_VERSION_LEN];
+	char version[MAX_VERSION_LEN];
+	char relid[MAX_VERSION_LEN];
+	int buildLevel;
+	char buildDate[MAX_VERSION_LEN];
 };
 
 
@@ -316,16 +300,16 @@
 #define	RIO_SET_XP_CPS    rIOCW(155,int)
 #define RIO_GET_IXANY     rIOCR(156,int)	/* ixany allowed? */
 #define RIO_SET_IXANY     rIOCW(157,int)
-#define RIO_SET_IXANY_ON  rIOCN(158)		/* allow ixany */
-#define RIO_SET_IXANY_OFF rIOCN(159)		/* disallow ixany */
+#define RIO_SET_IXANY_ON  rIOCN(158)	/* allow ixany */
+#define RIO_SET_IXANY_OFF rIOCN(159)	/* disallow ixany */
 #define RIO_GET_MODEM     rIOCR(160,int)	/* port is modem/direct line? */
 #define RIO_SET_MODEM     rIOCW(161,int)
-#define RIO_SET_MODEM_ON  rIOCN(162)		/* port is a modem */
-#define RIO_SET_MODEM_OFF rIOCN(163)		/* port is direct */
+#define RIO_SET_MODEM_ON  rIOCN(162)	/* port is a modem */
+#define RIO_SET_MODEM_OFF rIOCN(163)	/* port is direct */
 #define RIO_GET_IXON      rIOCR(164,int)	/* ixon allowed? */
 #define RIO_SET_IXON      rIOCW(165,int)
-#define RIO_SET_IXON_ON   rIOCN(166)		/* allow ixon */
-#define RIO_SET_IXON_OFF  rIOCN(167)		/* disallow ixon */
+#define RIO_SET_IXON_ON   rIOCN(166)	/* allow ixon */
+#define RIO_SET_IXON_OFF  rIOCN(167)	/* disallow ixon */
 
 #define RIO_GET_SIVIEW	  ((('s')<<8) | 106)	/* backwards compatible with SI */
 
diff --git a/drivers/char/rio/debug.h b/drivers/char/rio/debug.h
index b6e0d09..6ae95c0 100644
--- a/drivers/char/rio/debug.h
+++ b/drivers/char/rio/debug.h
@@ -33,7 +33,7 @@
 #define	DBPACKET(pkt, opt, str, chn) 	debug_packet((pkt), (opt), (str), (chn))
 #else
 #define	DBPACKET(pkt, opt, str, c)
-#endif	/* DCIRRUS */
+#endif				/* DCIRRUS */
 
 
-#endif	/* _debug_h_ */
+#endif				/* _debug_h_ */
diff --git a/drivers/char/rio/defaults.h b/drivers/char/rio/defaults.h
index 2e7309e..5b600c3 100644
--- a/drivers/char/rio/defaults.h
+++ b/drivers/char/rio/defaults.h
@@ -37,13 +37,13 @@
 
 #ifndef lint
 #ifdef SCCS
-static char *_rio_defaults_h_sccs = "@(#)defaults.h	1.1" ;
+static char *_rio_defaults_h_sccs = "@(#)defaults.h	1.1";
 #endif
 #endif
 
 
-#define MILLISECOND           (int) (1000/64)   /* 15.625 low ticks */
-#define SECOND                (int) 15625       /* Low priority ticks */
+#define MILLISECOND           (int) (1000/64)	/* 15.625 low ticks */
+#define SECOND                (int) 15625	/* Low priority ticks */
 
 #ifdef RTA
 #define RX_LIMIT       (ushort) 3
@@ -56,4 +56,3 @@
 
 
 /*********** end of file ***********/
-
diff --git a/drivers/char/rio/eisa.h b/drivers/char/rio/eisa.h
index 59371b0..c2abaf0 100644
--- a/drivers/char/rio/eisa.h
+++ b/drivers/char/rio/eisa.h
@@ -60,7 +60,7 @@
 
 #define	EISA_PRODUCT_IDENT_LO		0xC80	/* where RIO_EISA_IDENT is */
 #define	EISA_PRODUCT_IDENT_HI		0xC81
-#define	EISA_PRODUCT_NUMBER		0xC82   /* where PROD_CODE is */
+#define	EISA_PRODUCT_NUMBER		0xC82	/* where PROD_CODE is */
 #define	EISA_REVISION_NUMBER		0xC83	/* revision (1dp) */
 #define	EISA_ENABLE			0xC84	/* set LSB to enable card */
 #define	EISA_UNIQUE_NUM_0		0xC88	/* vomit */
@@ -101,4 +101,4 @@
 #define	INBZ(z,x)	inb(((z)<<12) | (x))
 #define	OUTBZ(z,x,y)	outb((((z)<<12) | (x)), y)
 
-#endif /* __rio_eisa_h__ */
+#endif				/* __rio_eisa_h__ */
diff --git a/drivers/char/rio/enable.h b/drivers/char/rio/enable.h
index 8e9a419e..e06673f 100644
--- a/drivers/char/rio/enable.h
+++ b/drivers/char/rio/enable.h
@@ -36,7 +36,7 @@
 
 #ifndef lint
 #ifdef SCCS
-static char *_rio_enable_h_sccs = "@(#)enable.h	1.1" ;
+static char *_rio_enable_h_sccs = "@(#)enable.h	1.1";
 #endif
 #endif
 
@@ -46,5 +46,3 @@
 
 
 /*********** end of file ***********/
-
-
diff --git a/drivers/char/rio/error.h b/drivers/char/rio/error.h
index 229438e..f20f078 100644
--- a/drivers/char/rio/error.h
+++ b/drivers/char/rio/error.h
@@ -80,6 +80,3 @@
 
 
 /*********** end of file ***********/
-
-
-
diff --git a/drivers/char/rio/errors.h b/drivers/char/rio/errors.h
index f920b9f..1d0d891 100644
--- a/drivers/char/rio/errors.h
+++ b/drivers/char/rio/errors.h
@@ -101,4 +101,4 @@
 #define	NOT_ENOUGH_CORE_FOR_PCI_COPY	53
 
 
-#endif /* __rio_errors_h__ */
+#endif				/* __rio_errors_h__ */
diff --git a/drivers/char/rio/formpkt.h b/drivers/char/rio/formpkt.h
index a8b65ae..3c7c91a 100644
--- a/drivers/char/rio/formpkt.h
+++ b/drivers/char/rio/formpkt.h
@@ -41,114 +41,113 @@
 
 #ifndef lint
 #ifdef SCCS
-static char *_rio_formpkt_h_sccs = "@(#)formpkt.h	1.1" ;
+static char *_rio_formpkt_h_sccs = "@(#)formpkt.h	1.1";
 #endif
 #endif
 
-typedef struct FORM_BOOT_PKT_1 FORM_BOOT_PKT_1 ;
+typedef struct FORM_BOOT_PKT_1 FORM_BOOT_PKT_1;
 struct FORM_BOOT_PKT_1 {
-                           ushort pkt_number ;
-                           ushort pkt_total ;
-                           ushort boot_top ;
-                       } ;
+	ushort pkt_number;
+	ushort pkt_total;
+	ushort boot_top;
+};
 
-typedef struct FORM_BOOT_PKT_2 FORM_BOOT_PKT_2 ;
+typedef struct FORM_BOOT_PKT_2 FORM_BOOT_PKT_2;
 struct FORM_BOOT_PKT_2 {
-                           ushort pkt_number ;
-                           char   boot_data[10] ;
-                       } ;
+	ushort pkt_number;
+	char boot_data[10];
+};
 
 
-typedef struct FORM_ATTACH_RTA   FORM_ATTACH_RTA ;
-struct FORM_ATTACH_RTA  {
-                       char    cmd_code ;
-                       char    booter_serial[4] ;
-                       char    booter_link ;
-                       char    bootee_serial[4] ;
-                       char    bootee_link ;
-                   } ;
+typedef struct FORM_ATTACH_RTA FORM_ATTACH_RTA;
+struct FORM_ATTACH_RTA {
+	char cmd_code;
+	char booter_serial[4];
+	char booter_link;
+	char bootee_serial[4];
+	char bootee_link;
+};
 
 
-typedef struct FORM_BOOT_ID   FORM_BOOT_ID ;
-struct FORM_BOOT_ID  {
-                       char    cmd_code ;
-                       char    bootee_serial[4] ;
-                       char    bootee_prod_id ;
-                       char    bootee_link ;
-                   } ;
+typedef struct FORM_BOOT_ID FORM_BOOT_ID;
+struct FORM_BOOT_ID {
+	char cmd_code;
+	char bootee_serial[4];
+	char bootee_prod_id;
+	char bootee_link;
+};
 
 
 
-typedef struct FORM_ROUTE_1   FORM_ROUTE_1 ;
+typedef struct FORM_ROUTE_1 FORM_ROUTE_1;
 struct FORM_ROUTE_1 {
-                        char     cmd_code ;
-                        char     pkt_number ;
-                        char     total_in_sequence ;
-                        char     unit_id ;
-                        char     host_unit_id ;
-                    } ;
+	char cmd_code;
+	char pkt_number;
+	char total_in_sequence;
+	char unit_id;
+	char host_unit_id;
+};
 
-typedef struct FORM_ROUTE_2   FORM_ROUTE_2 ;
+typedef struct FORM_ROUTE_2 FORM_ROUTE_2;
 struct FORM_ROUTE_2 {
-                        char   cmd_code ;
-                        char   pkt_number ;
-                        char   total_in_sequence ;
-                        char   route_data[9] ;
-                    } ;
+	char cmd_code;
+	char pkt_number;
+	char total_in_sequence;
+	char route_data[9];
+};
 
-typedef struct FORM_ROUTE_REQ   FORM_ROUTE_REQ ;
+typedef struct FORM_ROUTE_REQ FORM_ROUTE_REQ;
 struct FORM_ROUTE_REQ {
-                          char   cmd_code ;
-                          char   pkt_number ;
-                          char   total_in_sequence ;
-                          char   route_data[10] ;
-                      } ;
+	char cmd_code;
+	char pkt_number;
+	char total_in_sequence;
+	char route_data[10];
+};
 
 
-typedef struct FORM_ERROR   FORM_ERROR ;
+typedef struct FORM_ERROR FORM_ERROR;
 struct FORM_ERROR {
-                        char   cmd_code ;
-                        char   error_code ;
+	char cmd_code;
+	char error_code;
 
-                    } ;
+};
 
-typedef struct FORM_STATUS   FORM_STATUS ;
+typedef struct FORM_STATUS FORM_STATUS;
 struct FORM_STATUS {
-                        char   cmd_code ;
-                        char   status_code ;
-                        char   last_packet_valid ;
-                        char   tx_buffer ;
-                        char   rx_buffer ;
-                        char   port_status ;
-                        char   phb_status ;
-                    } ;
+	char cmd_code;
+	char status_code;
+	char last_packet_valid;
+	char tx_buffer;
+	char rx_buffer;
+	char port_status;
+	char phb_status;
+};
 
 
-typedef struct FORM_LINK_STATUS   FORM_LINK_STATUS ;
+typedef struct FORM_LINK_STATUS FORM_LINK_STATUS;
 struct FORM_LINK_STATUS {
-                        char    cmd_code ;
-                        char    status_code ;
-                        char    link_number ;
-                        ushort  rx_errors ;
-                        ushort  tx_errors ;
-                        ushort  csum_errors ;
-                        ushort  disconnects ;
-                    } ;
+	char cmd_code;
+	char status_code;
+	char link_number;
+	ushort rx_errors;
+	ushort tx_errors;
+	ushort csum_errors;
+	ushort disconnects;
+};
 
 
 
-typedef struct FORM_PARTITION FORM_PARTITION ;
+typedef struct FORM_PARTITION FORM_PARTITION;
 struct FORM_PARTITION {
-                        char    cmd_code ;
-                        char    status_code ;
-                        char    port_number ;
-                        char    tx_max ;
-                        char    rx_max ;
-                        char    rx_limit ;
-                      } ;
+	char cmd_code;
+	char status_code;
+	char port_number;
+	char tx_max;
+	char rx_max;
+	char rx_limit;
+};
 
 
 #endif
 
 /*********** end of file ***********/
-
diff --git a/drivers/char/rio/func.h b/drivers/char/rio/func.h
index 01987c6..b477841 100644
--- a/drivers/char/rio/func.h
+++ b/drivers/char/rio/func.h
@@ -47,20 +47,19 @@
 int RIOBootCodeUNKNOWN(struct rio_info *, struct DownLoad *);
 void msec_timeout(struct Host *);
 int RIOBootRup(struct rio_info *, uint, struct Host *, struct PKT *);
-int RIOBootOk(struct rio_info *,struct Host *, ulong);
-int RIORtaBound(struct rio_info *, uint); 
+int RIOBootOk(struct rio_info *, struct Host *, ulong);
+int RIORtaBound(struct rio_info *, uint);
 void FillSlot(int, int, uint, struct Host *);
 
 /* riocmd.c */
 int RIOFoadRta(struct Host *, struct Map *);
 int RIOZombieRta(struct Host *, struct Map *);
-int RIOCommandRta(struct rio_info *, uint, int (* func)( struct Host *, 
-								struct Map *));
-int RIOIdentifyRta(struct rio_info *, caddr_t); 
+int RIOCommandRta(struct rio_info *, uint, int (*func) (struct Host *, struct Map *));
+int RIOIdentifyRta(struct rio_info *, caddr_t);
 int RIOKillNeighbour(struct rio_info *, caddr_t);
 int RIOSuspendBootRta(struct Host *, int, int);
 int RIOFoadWakeup(struct rio_info *);
-struct CmdBlk * RIOGetCmdBlk(void);
+struct CmdBlk *RIOGetCmdBlk(void);
 void RIOFreeCmdBlk(struct CmdBlk *);
 int RIOQueueCmdBlk(struct Host *, uint, struct CmdBlk *);
 void RIOPollHostCommands(struct rio_info *, struct Host *);
@@ -71,13 +70,13 @@
 
 /* rioctrl.c */
 int copyin(int, caddr_t, int);
-int riocontrol(struct rio_info *, dev_t,int,caddr_t,int); 
-int RIOPreemptiveCmd(struct rio_info *,struct Port *,uchar);
+int riocontrol(struct rio_info *, dev_t, int, caddr_t, int);
+int RIOPreemptiveCmd(struct rio_info *, struct Port *, uchar);
 
 /* rioinit.c */
 void rioinit(struct rio_info *, struct RioHostInfo *);
 void RIOInitHosts(struct rio_info *, struct RioHostInfo *);
-void RIOISAinit(struct rio_info *,int);
+void RIOISAinit(struct rio_info *, int);
 int RIODoAT(struct rio_info *, int, int);
 caddr_t RIOCheckForATCard(int);
 int RIOAssignAT(struct rio_info *, int, caddr_t, int);
@@ -85,7 +84,7 @@
 void RIOAllocDataStructs(struct rio_info *);
 void RIOSetupDataStructs(struct rio_info *);
 int RIODefaultName(struct rio_info *, struct Host *, uint);
-struct rioVersion * RIOVersid(void);
+struct rioVersion *RIOVersid(void);
 int RIOMapin(paddr_t, int, caddr_t *);
 void RIOMapout(paddr_t, long, caddr_t);
 void RIOHostReset(uint, volatile struct DpRam *, uint);
@@ -108,7 +107,7 @@
 
 /* rioroute.c */
 int RIORouteRup(struct rio_info *, uint, struct Host *, struct PKT *);
-void RIOFixPhbs(struct rio_info *, struct Host *, uint); 
+void RIOFixPhbs(struct rio_info *, struct Host *, uint);
 uint GetUnitType(uint);
 int RIOSetChange(struct rio_info *);
 int RIOFindFreeID(struct rio_info *, struct Host *, uint *, uint *);
@@ -116,9 +115,9 @@
 
 /* riotty.c */
 
-int riotopen(struct tty_struct * tty, struct file * filp);
-int riotclose(void  *ptr);
-int riotioctl(struct rio_info *, struct tty_struct *, register int, register caddr_t); 
+int riotopen(struct tty_struct *tty, struct file *filp);
+int riotclose(void *ptr);
+int riotioctl(struct rio_info *, struct tty_struct *, register int, register caddr_t);
 void ttyseth(struct Port *, struct ttystatics *, struct old_sgttyb *sg);
 
 /* riotable.c */
@@ -127,27 +126,27 @@
 int RIODeleteRta(struct rio_info *, struct Map *);
 int RIOAssignRta(struct rio_info *, struct Map *);
 int RIOReMapPorts(struct rio_info *, struct Host *, struct Map *);
-int RIOChangeName(struct rio_info *, struct Map*);
+int RIOChangeName(struct rio_info *, struct Map *);
 
 #if 0
 /* riodrvr.c */
-struct rio_info * rio_install(struct RioHostInfo *);
+struct rio_info *rio_install(struct RioHostInfo *);
 int rio_uninstall(register struct rio_info *);
 int rio_open(struct rio_info *, int, struct file *);
 int rio_close(struct rio_info *, struct file *);
 int rio_read(struct rio_info *, struct file *, char *, int);
-int rio_write(struct rio_info *, struct file *	f, char *, int);
+int rio_write(struct rio_info *, struct file *f, char *, int);
 int rio_ioctl(struct rio_info *, struct file *, int, char *);
-int rio_select(struct rio_info *, struct file *	f, int, struct sel *);
-int	rio_intr(char *);
-int rio_isr_thread(char  *);
-struct rio_info * rio_info_store( int cmd, struct rio_info * p);
+int rio_select(struct rio_info *, struct file *f, int, struct sel *);
+int rio_intr(char *);
+int rio_isr_thread(char *);
+struct rio_info *rio_info_store(int cmd, struct rio_info *p);
 #endif
 
-extern int    rio_pcicopy(char *src, char *dst, int n);
-extern int rio_minor (struct tty_struct *tty);
-extern int rio_ismodem (struct tty_struct *tty);
+extern int rio_pcicopy(char *src, char *dst, int n);
+extern int rio_minor(struct tty_struct *tty);
+extern int rio_ismodem(struct tty_struct *tty);
 
-extern void rio_start_card_running (struct Host * HostP);
+extern void rio_start_card_running(struct Host *HostP);
 
-#endif	/* __func_h_def */
+#endif				/* __func_h_def */
diff --git a/drivers/char/rio/host.h b/drivers/char/rio/host.h
index 4c65963..f7dfced 100644
--- a/drivers/char/rio/host.h
+++ b/drivers/char/rio/host.h
@@ -49,33 +49,32 @@
 **    Host data structure. This is used for the software equiv. of
 **    the host.
 */
-struct    Host
-{
-    uchar             	    Type;      /* RIO_EISA, RIO_MCA, ... */
-    uchar             	    Ivec;      /* POLLED or ivec number */
-    uchar             	    Mode;      /* Control stuff */
-    uchar                   Slot;      /* Slot */
-    volatile caddr_t        Caddr;     /* KV address of DPRAM */
-    volatile struct DpRam  *CardP;     /* KV address of DPRAM, with overlay */
-    paddr_t          	    PaddrP;    /* Phys. address of DPRAM */
-    char                    Name[MAX_NAME_LEN];  /* The name of the host */
-    uint            	    UniqueNum; /* host unique number */
-    spinlock_t	            HostLock;  /* Lock structure for MPX */
-    /*struct pci_devinfo    PciDevInfo; *//* PCI Bus/Device/Function stuff */
-    /*struct lockb	    HostLock;  *//* Lock structure for MPX */
-    uint                    WorkToBeDone; /* set to true each interrupt */
-    uint                    InIntr;    /* Being serviced? */
-    uint                    IntSrvDone;/* host's interrupt has been serviced */
-    int			    (*Copy)( caddr_t, caddr_t, int ); /* copy func */
-    struct timer_list timer;
-    /*
-    **               I M P O R T A N T !
-    **
-    ** The rest of this data structure is cleared to zero after
-    ** a RIO_HOST_FOAD command.
-    */
-    
-    ulong                   Flags;     /* Whats going down */
+struct Host {
+	uchar Type;		/* RIO_EISA, RIO_MCA, ... */
+	uchar Ivec;		/* POLLED or ivec number */
+	uchar Mode;		/* Control stuff */
+	uchar Slot;		/* Slot */
+	volatile caddr_t Caddr;	/* KV address of DPRAM */
+	volatile struct DpRam *CardP;	/* KV address of DPRAM, with overlay */
+	paddr_t PaddrP;		/* Phys. address of DPRAM */
+	char Name[MAX_NAME_LEN];	/* The name of the host */
+	uint UniqueNum;		/* host unique number */
+	spinlock_t HostLock;	/* Lock structure for MPX */
+	/*struct pci_devinfo    PciDevInfo; *//* PCI Bus/Device/Function stuff */
+	/*struct lockb          HostLock;  *//* Lock structure for MPX */
+	uint WorkToBeDone;	/* set to true each interrupt */
+	uint InIntr;		/* Being serviced? */
+	uint IntSrvDone;	/* host's interrupt has been serviced */
+	int (*Copy) (caddr_t, caddr_t, int);	/* copy func */
+	struct timer_list timer;
+	/*
+	 **               I M P O R T A N T !
+	 **
+	 ** The rest of this data structure is cleared to zero after
+	 ** a RIO_HOST_FOAD command.
+	 */
+
+	ulong Flags;		/* Whats going down */
 #define RC_WAITING            0
 #define RC_STARTUP            1
 #define RC_RUNNING            2
@@ -93,25 +92,25 @@
 #define RC_BOOT_OWN           0x10	/* Only boot RTAs bound to this system */
 #define RC_BOOT_NONE          0x20	/* Don't boot any RTAs (slave mode) */
 
-    struct Top		    Topology[LINKS_PER_UNIT]; /* one per link */
-    struct Map              Mapping[MAX_RUP];     /* Mappings for host */
-    struct PHB		    *PhbP;                /* Pointer to the PHB array */
-    ushort           	    *PhbNumP;             /* Ptr to Number of PHB's */
-    struct LPB 	            *LinkStrP ;           /* Link Structure Array */
-    struct RUP       	    *RupP;                /* Sixteen real rups here */
-    struct PARM_MAP  	    *ParmMapP;            /* points to the parmmap */
-    uint                    ExtraUnits[MAX_EXTRA_UNITS]; /* unknown things */
-    uint                    NumExtraBooted;       /* how many of the above */
-    /*
-    ** Twenty logical rups.
-    ** The first sixteen are the real Rup entries (above), the last four
-    ** are the link RUPs.
-    */
-    struct UnixRup	    UnixRups[MAX_RUP+LINKS_PER_UNIT];
-	int				timeout_id;	/* For calling 100 ms delays */
-	int				timeout_sem;/* For calling 100 ms delays */
-    long locks; /* long req'd for set_bit --RR */
-    char             	    ____end_marker____;
+	struct Top Topology[LINKS_PER_UNIT];	/* one per link */
+	struct Map Mapping[MAX_RUP];	/* Mappings for host */
+	struct PHB *PhbP;	/* Pointer to the PHB array */
+	ushort *PhbNumP;	/* Ptr to Number of PHB's */
+	struct LPB *LinkStrP;	/* Link Structure Array */
+	struct RUP *RupP;	/* Sixteen real rups here */
+	struct PARM_MAP *ParmMapP;	/* points to the parmmap */
+	uint ExtraUnits[MAX_EXTRA_UNITS];	/* unknown things */
+	uint NumExtraBooted;	/* how many of the above */
+	/*
+	 ** Twenty logical rups.
+	 ** The first sixteen are the real Rup entries (above), the last four
+	 ** are the link RUPs.
+	 */
+	struct UnixRup UnixRups[MAX_RUP + LINKS_PER_UNIT];
+	int timeout_id;		/* For calling 100 ms delays */
+	int timeout_sem;	/* For calling 100 ms delays */
+	long locks;		/* long req'd for set_bit --RR */
+	char ____end_marker____;
 };
 #define Control      CardP->DpControl
 #define SetInt       CardP->DpSetInt
@@ -129,6 +128,6 @@
 #define Year         CardP->DpYear
 #define Week         CardP->DpWeek
 
-#define RIO_DUMBPARM 0x0860    /* what not to expect */
+#define RIO_DUMBPARM 0x0860	/* what not to expect */
 
 #endif
diff --git a/drivers/char/rio/hosthw.h b/drivers/char/rio/hosthw.h
index f6f31ec..6281fe4 100644
--- a/drivers/char/rio/hosthw.h
+++ b/drivers/char/rio/hosthw.h
@@ -37,7 +37,7 @@
 
 #ifndef lint
 #ifdef SCCS_LABELS
-static char *_rio_hosthw_h_sccs = "@(#)hosthw.h	1.2" ;
+static char *_rio_hosthw_h_sccs = "@(#)hosthw.h	1.2";
 #endif
 #endif
 
@@ -53,5 +53,3 @@
 
 
 /*********** end of file ***********/
-
-
diff --git a/drivers/char/rio/link.h b/drivers/char/rio/link.h
index 9722503..bfba5b0 100644
--- a/drivers/char/rio/link.h
+++ b/drivers/char/rio/link.h
@@ -70,27 +70,27 @@
 #define  DIE_NOW		(ushort) 0x0200
 
 /* Boot request stuff */
-#define BOOT_REQUEST       ((ushort) 0)    /* Request for a boot */
-#define BOOT_ABORT         ((ushort) 1)    /* Abort a boot */
-#define BOOT_SEQUENCE      ((ushort) 2)    /* Packet with the number of packets
-                                              and load address */
-#define BOOT_COMPLETED     ((ushort) 3)    /* Boot completed */
+#define BOOT_REQUEST       ((ushort) 0)	/* Request for a boot */
+#define BOOT_ABORT         ((ushort) 1)	/* Abort a boot */
+#define BOOT_SEQUENCE      ((ushort) 2)	/* Packet with the number of packets
+					   and load address */
+#define BOOT_COMPLETED     ((ushort) 3)	/* Boot completed */
 
 /* States that a link can be in */
-#define	LINK_DISCONNECTED  ((ushort) 0)    /* Disconnected */
-#define LINK_BOOT1         ((ushort) 1)    /* Trying to send 1st stage boot */
-#define LINK_BOOT2         ((ushort) 2)    /* Trying to send 2nd stage boot */
-#define LINK_BOOT2WAIT     ((ushort) 3)    /* Waiting for selftest results */
-#define LINK_BOOT3         ((ushort) 4)    /* Trying to send 3rd stage boots */
-#define LINK_SYNC          ((ushort) 5)    /* Syncing */
+#define	LINK_DISCONNECTED  ((ushort) 0)	/* Disconnected */
+#define LINK_BOOT1         ((ushort) 1)	/* Trying to send 1st stage boot */
+#define LINK_BOOT2         ((ushort) 2)	/* Trying to send 2nd stage boot */
+#define LINK_BOOT2WAIT     ((ushort) 3)	/* Waiting for selftest results */
+#define LINK_BOOT3         ((ushort) 4)	/* Trying to send 3rd stage boots */
+#define LINK_SYNC          ((ushort) 5)	/* Syncing */
 
-#define LINK_INTRO         ((ushort) 10)    /* Introductory packet */
-#define LINK_SUPPLYID      ((ushort) 11)    /* Trying to supply an ID */
-#define LINK_TOPOLOGY      ((ushort) 12)    /* Send a topology update */
-#define LINK_REQUESTID     ((ushort) 13)    /* Waiting for an ID */
-#define LINK_CONNECTED     ((ushort) 14)    /* Connected */
+#define LINK_INTRO         ((ushort) 10)	/* Introductory packet */
+#define LINK_SUPPLYID      ((ushort) 11)	/* Trying to supply an ID */
+#define LINK_TOPOLOGY      ((ushort) 12)	/* Send a topology update */
+#define LINK_REQUESTID     ((ushort) 13)	/* Waiting for an ID */
+#define LINK_CONNECTED     ((ushort) 14)	/* Connected */
 
-#define LINK_INTERCONNECT  ((ushort) 20)   /* Subnets interconnected */
+#define LINK_INTERCONNECT  ((ushort) 20)	/* Subnets interconnected */
 
 #define LINK_SPARE	   ((ushort) 40)
 
@@ -103,12 +103,12 @@
 ** LED stuff
 */
 #if defined(RTA)
-#define LED_OFF            ((ushort) 0)    /* LED off */
-#define LED_RED            ((ushort) 1)    /* LED Red */
-#define LED_GREEN          ((ushort) 2)    /* LED Green */
-#define LED_ORANGE         ((ushort) 4)    /* LED Orange */
-#define LED_1TO8_OPEN      ((ushort) 1)    /* Port 1->8 LED on */
-#define LED_9TO16_OPEN     ((ushort) 2)    /* Port 9->16 LED on */
+#define LED_OFF            ((ushort) 0)	/* LED off */
+#define LED_RED            ((ushort) 1)	/* LED Red */
+#define LED_GREEN          ((ushort) 2)	/* LED Green */
+#define LED_ORANGE         ((ushort) 4)	/* LED Orange */
+#define LED_1TO8_OPEN      ((ushort) 1)	/* Port 1->8 LED on */
+#define LED_9TO16_OPEN     ((ushort) 2)	/* Port 9->16 LED on */
 #define LED_SET_COLOUR(colour)	(link->led = (colour))
 #define LED_OR_COLOUR(colour)	(link->led |= (colour))
 #define LED_TIMEOUT(time)    (link->led_timeout = RioTimePlus(RioTime(),(time)))
@@ -116,72 +116,72 @@
 #define LED_SET_COLOUR(colour)
 #define LED_OR_COLOUR(colour)
 #define LED_TIMEOUT(time)
-#endif /* RTA */
+#endif				/* RTA */
 
 struct LPB {
-               WORD          link_number ;       /* Link Number */
-               Channel_ptr   in_ch ;             /* Link In Channel */
-               Channel_ptr   out_ch ;            /* Link Out Channel */
+	WORD link_number;	/* Link Number */
+	Channel_ptr in_ch;	/* Link In Channel */
+	Channel_ptr out_ch;	/* Link Out Channel */
 #ifdef RTA
-               uchar        stat_led ;          /* Port open leds */
-               uchar        led ;               /* True, light led! */
+	uchar stat_led;		/* Port open leds */
+	uchar led;		/* True, light led! */
 #endif
-               BYTE attached_serial[4]; /* Attached serial number */
-               BYTE attached_host_serial[4];
-                                                 /* Serial number of Host who
-                                                    booted the other end */
-               WORD          descheduled ;       /* Currently Descheduled */
-               WORD          state;              /* Current state */
-               WORD          send_poll ;         /* Send a Poll Packet */
-               Process_ptr   ltt_p ;             /* Process Descriptor */
-               Process_ptr   lrt_p ;             /* Process Descriptor */
-               WORD          lrt_status ;        /* Current lrt status */
-               WORD          ltt_status ;        /* Current ltt status */
-               WORD          timeout ;           /* Timeout value */
-               WORD          topology;           /* Topology bits */
-               WORD          mon_ltt ;
-               WORD          mon_lrt ;
-               WORD          WaitNoBoot ;	 /* Secs to hold off booting */
-               PKT_ptr       add_packet_list;    /* Add packets to here */
-               PKT_ptr       remove_packet_list; /* Send packets from here */
+	BYTE attached_serial[4];	/* Attached serial number */
+	BYTE attached_host_serial[4];
+	/* Serial number of Host who
+	   booted the other end */
+	WORD descheduled;	/* Currently Descheduled */
+	WORD state;		/* Current state */
+	WORD send_poll;		/* Send a Poll Packet */
+	Process_ptr ltt_p;	/* Process Descriptor */
+	Process_ptr lrt_p;	/* Process Descriptor */
+	WORD lrt_status;	/* Current lrt status */
+	WORD ltt_status;	/* Current ltt status */
+	WORD timeout;		/* Timeout value */
+	WORD topology;		/* Topology bits */
+	WORD mon_ltt;
+	WORD mon_lrt;
+	WORD WaitNoBoot;	/* Secs to hold off booting */
+	PKT_ptr add_packet_list;	/* Add packets to here */
+	PKT_ptr remove_packet_list;	/* Send packets from here */
 #ifdef RTA
 #ifdef DCIRRUS
-#define    QBUFS_PER_REDIRECT (4 / PKTS_PER_BUFFER + 1) 
+#define    QBUFS_PER_REDIRECT (4 / PKTS_PER_BUFFER + 1)
 #else
-#define    QBUFS_PER_REDIRECT (8 / PKTS_PER_BUFFER + 1) 
+#define    QBUFS_PER_REDIRECT (8 / PKTS_PER_BUFFER + 1)
 #endif
-               PKT_ptr_ptr   rd_add ;            /* Add a new Packet here */
-               Q_BUF_ptr     rd_add_qb;          /* Pointer to the add Q buf */
-               PKT_ptr_ptr   rd_add_st_qbb ;     /* Pointer to start of the Q's buf */
-               PKT_ptr_ptr   rd_add_end_qbb ;    /* Pointer to the end of the Q's buf */
-               PKT_ptr_ptr   rd_remove ;         /* Remove a Packet here */
-               Q_BUF_ptr     rd_remove_qb ;      /* Pointer to the remove Q buf */
-               PKT_ptr_ptr   rd_remove_st_qbb ;  /* Pointer to the start of the Q buf */
-               PKT_ptr_ptr   rd_remove_end_qbb ; /* Pointer to the end of the Q buf */
-               ushort        pkts_in_q ;         /* Packets in queue */
+	PKT_ptr_ptr rd_add;	/* Add a new Packet here */
+	Q_BUF_ptr rd_add_qb;	/* Pointer to the add Q buf */
+	PKT_ptr_ptr rd_add_st_qbb;	/* Pointer to start of the Q's buf */
+	PKT_ptr_ptr rd_add_end_qbb;	/* Pointer to the end of the Q's buf */
+	PKT_ptr_ptr rd_remove;	/* Remove a Packet here */
+	Q_BUF_ptr rd_remove_qb;	/* Pointer to the remove Q buf */
+	PKT_ptr_ptr rd_remove_st_qbb;	/* Pointer to the start of the Q buf */
+	PKT_ptr_ptr rd_remove_end_qbb;	/* Pointer to the end of the Q buf */
+	ushort pkts_in_q;	/* Packets in queue */
 #endif
 
-               Channel_ptr   lrt_fail_chan ;     /* Lrt's failure channel */
-               Channel_ptr   ltt_fail_chan ;     /* Ltt's failure channel */
+	Channel_ptr lrt_fail_chan;	/* Lrt's failure channel */
+	Channel_ptr ltt_fail_chan;	/* Ltt's failure channel */
 
 #if defined (HOST) || defined (INKERNEL)
- /* RUP structure for HOST to driver communications */
-               struct RUP           rup ;              
+	/* RUP structure for HOST to driver communications */
+	struct RUP rup;
 #endif
-               struct RUP           link_rup;           /* RUP for the link (POLL,
-                                                    topology etc.) */
-               WORD          attached_link ;     /* Number of attached link */
-               WORD          csum_errors ;       /* csum errors */
-               WORD          num_disconnects ;   /* number of disconnects */
-               WORD          num_sync_rcvd ;     /* # sync's received */
-               WORD          num_sync_rqst ;     /* # sync requests */
-               WORD          num_tx ;            /* Num pkts sent */
-               WORD          num_rx ;            /* Num pkts received */
-               WORD          module_attached;    /* Module tpyes of attached */
-               WORD          led_timeout;        /* LED timeout */
-               WORD          first_port;         /* First port to service */
-               WORD          last_port;          /* Last port to service */
-           } ;
+	struct RUP link_rup;	/* RUP for the link (POLL,
+				   topology etc.) */
+	WORD attached_link;	/* Number of attached link */
+	WORD csum_errors;	/* csum errors */
+	WORD num_disconnects;	/* number of disconnects */
+	WORD num_sync_rcvd;	/* # sync's received */
+	WORD num_sync_rqst;	/* # sync requests */
+	WORD num_tx;		/* Num pkts sent */
+	WORD num_rx;		/* Num pkts received */
+	WORD module_attached;	/* Module tpyes of attached */
+	WORD led_timeout;	/* LED timeout */
+	WORD first_port;	/* First port to service */
+	WORD last_port;		/* Last port to service */
+};
 
 #endif
 
diff --git a/drivers/char/rio/linux_compat.h b/drivers/char/rio/linux_compat.h
index d53843a..17a14c4 100644
--- a/drivers/char/rio/linux_compat.h
+++ b/drivers/char/rio/linux_compat.h
@@ -41,7 +41,7 @@
 #endif
 
 struct ttystatics {
-  struct termios tm;
+	struct termios tm;
 };
 
 #define bzero(d, n)         memset((d), 0, (n))
@@ -97,26 +97,24 @@
 the definitions from Linux, and is incompatible... */
 
 /* RxBaud and TxBaud definitions... */
-#define	RIO_B0			0x00			/* RTS / DTR signals dropped */
-#define	RIO_B50			0x01			/* 50 baud */
-#define	RIO_B75			0x02			/* 75 baud */
-#define	RIO_B110		0x03			/* 110 baud */
-#define	RIO_B134		0x04			/* 134.5 baud */
-#define	RIO_B150		0x05			/* 150 baud */
-#define	RIO_B200		0x06			/* 200 baud */
-#define	RIO_B300		0x07			/* 300 baud */
-#define	RIO_B600		0x08			/* 600 baud */
-#define	RIO_B1200		0x09			/* 1200 baud */
-#define	RIO_B1800		0x0A			/* 1800 baud */
-#define	RIO_B2400		0x0B			/* 2400 baud */
-#define	RIO_B4800		0x0C			/* 4800 baud */
-#define	RIO_B9600		0x0D			/* 9600 baud */
-#define	RIO_B19200		0x0E			/* 19200 baud */
-#define	RIO_B38400		0x0F			/* 38400 baud */
-#define	RIO_B56000		0x10			/* 56000 baud */
-#define	RIO_B57600		0x11			/* 57600 baud */
-#define	RIO_B64000		0x12			/* 64000 baud */
-#define	RIO_B115200		0x13			/* 115200 baud */
-#define	RIO_B2000		0x14			/* 2000 baud */
-
-
+#define	RIO_B0			0x00	/* RTS / DTR signals dropped */
+#define	RIO_B50			0x01	/* 50 baud */
+#define	RIO_B75			0x02	/* 75 baud */
+#define	RIO_B110		0x03	/* 110 baud */
+#define	RIO_B134		0x04	/* 134.5 baud */
+#define	RIO_B150		0x05	/* 150 baud */
+#define	RIO_B200		0x06	/* 200 baud */
+#define	RIO_B300		0x07	/* 300 baud */
+#define	RIO_B600		0x08	/* 600 baud */
+#define	RIO_B1200		0x09	/* 1200 baud */
+#define	RIO_B1800		0x0A	/* 1800 baud */
+#define	RIO_B2400		0x0B	/* 2400 baud */
+#define	RIO_B4800		0x0C	/* 4800 baud */
+#define	RIO_B9600		0x0D	/* 9600 baud */
+#define	RIO_B19200		0x0E	/* 19200 baud */
+#define	RIO_B38400		0x0F	/* 38400 baud */
+#define	RIO_B56000		0x10	/* 56000 baud */
+#define	RIO_B57600		0x11	/* 57600 baud */
+#define	RIO_B64000		0x12	/* 64000 baud */
+#define	RIO_B115200		0x13	/* 115200 baud */
+#define	RIO_B2000		0x14	/* 2000 baud */
diff --git a/drivers/char/rio/list.h b/drivers/char/rio/list.h
index a4f7f1f..36aad4c 100644
--- a/drivers/char/rio/list.h
+++ b/drivers/char/rio/list.h
@@ -38,7 +38,7 @@
 
 #ifdef SCCS_LABELS
 #ifndef lint
-static char *_rio_list_h_sccs = "@(#)list.h	1.9" ;
+static char *_rio_list_h_sccs = "@(#)list.h	1.9";
 #endif
 #endif
 
@@ -166,7 +166,7 @@
 #endif
 
 
-#else /* !IN_KERNEL */
+#else				/* !IN_KERNEL */
 
 #define ZERO_PTR NULL
 
@@ -192,5 +192,5 @@
 #define splx(oldspl)    if ((oldspl) == 0) spl0()
 #endif
 
-#endif /* ifndef _list.h */
+#endif				/* ifndef _list.h */
 /*********** end of file ***********/
diff --git a/drivers/char/rio/lrt.h b/drivers/char/rio/lrt.h
index bbac8fa..b41764d 100644
--- a/drivers/char/rio/lrt.h
+++ b/drivers/char/rio/lrt.h
@@ -36,7 +36,7 @@
 
 #ifndef lint
 #ifdef SCCS_LABELS
-static char *_rio_lrt_h_sccs = "@(#)lrt.h	1.1" ;
+static char *_rio_lrt_h_sccs = "@(#)lrt.h	1.1";
 #endif
 #endif
 
@@ -50,6 +50,3 @@
 
 
 /*********** end of file ***********/
-
-
-
diff --git a/drivers/char/rio/ltt.h b/drivers/char/rio/ltt.h
index f27dcec..ab04004 100644
--- a/drivers/char/rio/ltt.h
+++ b/drivers/char/rio/ltt.h
@@ -36,7 +36,7 @@
 
 #ifndef lint
 #ifdef SCCS_LABELS
-static char *_rio_ltt_h_sccs = "@(#)ltt.h	1.1" ;
+static char *_rio_ltt_h_sccs = "@(#)ltt.h	1.1";
 #endif
 #endif
 
@@ -45,11 +45,8 @@
 #else
 #define LTT_STACK       (ushort) 200
 #endif
- 
+
 
 
 
 /*********** end of file ***********/
-
-
-
diff --git a/drivers/char/rio/lttwake.h b/drivers/char/rio/lttwake.h
index fe17d0e..fdf0c1f 100644
--- a/drivers/char/rio/lttwake.h
+++ b/drivers/char/rio/lttwake.h
@@ -39,7 +39,7 @@
 
 #ifndef lint
 #ifdef SCCS_LABELS
-static char *_rio_lttwake_h_sccs = "@(#)lttwake.h	1.1" ;
+static char *_rio_lttwake_h_sccs = "@(#)lttwake.h	1.1";
 #endif
 #endif
 
@@ -48,6 +48,3 @@
 
 
 /*********** end of file ***********/
-
-
-
diff --git a/drivers/char/rio/map.h b/drivers/char/rio/map.h
index 400645a1..97fe287 100644
--- a/drivers/char/rio/map.h
+++ b/drivers/char/rio/map.h
@@ -46,21 +46,20 @@
 #define	TOTAL_MAP_ENTRIES (MAX_MAP_ENTRY*RIO_SLOTS)
 #define	MAX_NAME_LEN 32
 
-struct Map
-{
-	uint	HostUniqueNum;	        /* Supporting hosts unique number */
-	uint	RtaUniqueNum;	        /* Unique number */
+struct Map {
+	uint HostUniqueNum;	/* Supporting hosts unique number */
+	uint RtaUniqueNum;	/* Unique number */
 	/*
-	** The next two IDs must be swapped on big-endian architectures
-	** when using a v2.04 /etc/rio/config with a v3.00 driver (when
-	** upgrading for example).
-	*/
-	ushort	ID;			/* ID used in the subnet */
-	ushort	ID2;			/* ID of 2nd block of 8 for 16 port */
-	ulong	Flags;			/* Booted, ID Given, Disconnected */
-	ulong	SysPort;		/* First tty mapped to this port */
-	struct Top   Topology[LINKS_PER_UNIT];	/* ID connected to each link */
-	char	Name[MAX_NAME_LEN];        /* Cute name by which RTA is known */
+	 ** The next two IDs must be swapped on big-endian architectures
+	 ** when using a v2.04 /etc/rio/config with a v3.00 driver (when
+	 ** upgrading for example).
+	 */
+	ushort ID;		/* ID used in the subnet */
+	ushort ID2;		/* ID of 2nd block of 8 for 16 port */
+	ulong Flags;		/* Booted, ID Given, Disconnected */
+	ulong SysPort;		/* First tty mapped to this port */
+	struct Top Topology[LINKS_PER_UNIT];	/* ID connected to each link */
+	char Name[MAX_NAME_LEN];	/* Cute name by which RTA is known */
 };
 
 /*
diff --git a/drivers/char/rio/mca.h b/drivers/char/rio/mca.h
index 08a327e..d01e76b 100644
--- a/drivers/char/rio/mca.h
+++ b/drivers/char/rio/mca.h
@@ -70,4 +70,4 @@
 
 #define	RIO_MCA_DEFAULT_MODE	SLOW_LINKS
 
-#endif	/* __rio_mca_h__ */
+#endif				/* __rio_mca_h__ */
diff --git a/drivers/char/rio/mesg.h b/drivers/char/rio/mesg.h
index 9cf6c0b..dd9be58 100644
--- a/drivers/char/rio/mesg.h
+++ b/drivers/char/rio/mesg.h
@@ -38,4 +38,4 @@
 #endif
 
 
-#endif /* __rio_mesg_h__ */
+#endif				/* __rio_mesg_h__ */
diff --git a/drivers/char/rio/param.h b/drivers/char/rio/param.h
index 2dc30b9..de7e571 100644
--- a/drivers/char/rio/param.h
+++ b/drivers/char/rio/param.h
@@ -42,20 +42,19 @@
 ** the param command block, as used in OPEN and PARAM calls.
 */
 
-struct phb_param
-{
-    BYTE    Cmd;        /* It is very important that these line up */
-    BYTE    Cor1;       /* with what is expected at the other end. */
-    BYTE    Cor2;       /* to confirm that you've got it right,    */
-    BYTE    Cor4;       /* check with cirrus/cirrus.h              */
-    BYTE    Cor5;
-    BYTE    TxXon;	/* Transmit X-On character */
-    BYTE    TxXoff;	/* Transmit X-Off character */
-    BYTE    RxXon;	/* Receive X-On character */
-    BYTE    RxXoff;	/* Receive X-Off character */
-    BYTE    LNext;	/* Literal-next character */
-    BYTE    TxBaud;	/* Transmit baudrate */
-    BYTE    RxBaud;	/* Receive baudrate */
+struct phb_param {
+	BYTE Cmd;		/* It is very important that these line up */
+	BYTE Cor1;		/* with what is expected at the other end. */
+	BYTE Cor2;		/* to confirm that you've got it right,    */
+	BYTE Cor4;		/* check with cirrus/cirrus.h              */
+	BYTE Cor5;
+	BYTE TxXon;		/* Transmit X-On character */
+	BYTE TxXoff;		/* Transmit X-Off character */
+	BYTE RxXon;		/* Receive X-On character */
+	BYTE RxXoff;		/* Receive X-Off character */
+	BYTE LNext;		/* Literal-next character */
+	BYTE TxBaud;		/* Transmit baudrate */
+	BYTE RxBaud;		/* Receive baudrate */
 };
 
 #endif
diff --git a/drivers/char/rio/parmmap.h b/drivers/char/rio/parmmap.h
index 46f99df..fe4e005 100644
--- a/drivers/char/rio/parmmap.h
+++ b/drivers/char/rio/parmmap.h
@@ -44,53 +44,50 @@
 #endif
 #endif
 
-typedef struct PARM_MAP PARM_MAP ;
+typedef struct PARM_MAP PARM_MAP;
 
-struct PARM_MAP
-{
-PHB_ptr           phb_ptr ;              /* Pointer to the PHB array */
-WORD_ptr          phb_num_ptr ;          /* Ptr to Number of PHB's */
-FREE_LIST_ptr     free_list;             /* Free List pointer */
-FREE_LIST_ptr     free_list_end;         /* Free List End pointer */
-Q_BUF_ptr_ptr     q_free_list_ptr ;      /* Ptr to Q_BUF variable */
-BYTE_ptr          unit_id_ptr ;          /* Unit Id */
-LPB_ptr           link_str_ptr ;         /* Link Structure Array */
-BYTE_ptr          bootloader_1 ;         /* 1st Stage Boot Loader */
-BYTE_ptr          bootloader_2 ;         /* 2nd Stage Boot Loader */
-WORD_ptr          port_route_map_ptr ;   /* Port Route Map */
-ROUTE_STR_ptr     route_ptr ;            /* Unit Route Map */
-NUMBER_ptr        map_present ;          /* Route Map present */
-NUMBER            pkt_num ;               /* Total number of packets */
-NUMBER            q_num ;                 /* Total number of Q packets */
-WORD              buffers_per_port ;      /* Number of buffers per port */
-WORD              heap_size ;             /* Initial size of heap */
-WORD              heap_left ;             /* Current Heap left */
-WORD              error ;                 /* Error code */
-WORD              tx_max;                 /* Max number of tx pkts per phb */
-WORD              rx_max;                 /* Max number of rx pkts per phb */
-WORD              rx_limit;               /* For high / low watermarks */
-NUMBER            links ;                 /* Links to use */
-NUMBER            timer ;                 /* Interrupts per second */
-RUP_ptr           rups ;                 /* Pointer to the RUPs */
-WORD              max_phb ;              /* Mostly for debugging */
-WORD              living ;               /* Just increments!! */
-WORD              init_done ;            /* Initialisation over */
-WORD              booting_link ;
-WORD              idle_count ;           /* Idle time counter */
-WORD              busy_count ;           /* Busy counter */
-WORD              idle_control ;         /* Control Idle Process */
+struct PARM_MAP {
+	PHB_ptr phb_ptr;	/* Pointer to the PHB array */
+	WORD_ptr phb_num_ptr;	/* Ptr to Number of PHB's */
+	FREE_LIST_ptr free_list;	/* Free List pointer */
+	FREE_LIST_ptr free_list_end;	/* Free List End pointer */
+	Q_BUF_ptr_ptr q_free_list_ptr;	/* Ptr to Q_BUF variable */
+	BYTE_ptr unit_id_ptr;	/* Unit Id */
+	LPB_ptr link_str_ptr;	/* Link Structure Array */
+	BYTE_ptr bootloader_1;	/* 1st Stage Boot Loader */
+	BYTE_ptr bootloader_2;	/* 2nd Stage Boot Loader */
+	WORD_ptr port_route_map_ptr;	/* Port Route Map */
+	ROUTE_STR_ptr route_ptr;	/* Unit Route Map */
+	NUMBER_ptr map_present;	/* Route Map present */
+	NUMBER pkt_num;		/* Total number of packets */
+	NUMBER q_num;		/* Total number of Q packets */
+	WORD buffers_per_port;	/* Number of buffers per port */
+	WORD heap_size;		/* Initial size of heap */
+	WORD heap_left;		/* Current Heap left */
+	WORD error;		/* Error code */
+	WORD tx_max;		/* Max number of tx pkts per phb */
+	WORD rx_max;		/* Max number of rx pkts per phb */
+	WORD rx_limit;		/* For high / low watermarks */
+	NUMBER links;		/* Links to use */
+	NUMBER timer;		/* Interrupts per second */
+	RUP_ptr rups;		/* Pointer to the RUPs */
+	WORD max_phb;		/* Mostly for debugging */
+	WORD living;		/* Just increments!! */
+	WORD init_done;		/* Initialisation over */
+	WORD booting_link;
+	WORD idle_count;	/* Idle time counter */
+	WORD busy_count;	/* Busy counter */
+	WORD idle_control;	/* Control Idle Process */
 #if defined(HOST) || defined(INKERNEL)
-WORD              tx_intr;               /* TX interrupt pending */
-WORD              rx_intr;               /* RX interrupt pending */
-WORD              rup_intr;              /* RUP interrupt pending */
+	WORD tx_intr;		/* TX interrupt pending */
+	WORD rx_intr;		/* RX interrupt pending */
+	WORD rup_intr;		/* RUP interrupt pending */
 #endif
 #if defined(RTA)
-WORD		  dying_count;		/* Count of processes dead */
+	WORD dying_count;	/* Count of processes dead */
 #endif
-} ;
+};
 
 #endif
 
 /*********** end of file ***********/
-
-
diff --git a/drivers/char/rio/pci.h b/drivers/char/rio/pci.h
index dc635bd..1eba911 100644
--- a/drivers/char/rio/pci.h
+++ b/drivers/char/rio/pci.h
@@ -73,4 +73,4 @@
 
 #define	RIO_PCI_DEFAULT_MODE	0x05
 
-#endif	/* __rio_pci_h__ */
+#endif				/* __rio_pci_h__ */
diff --git a/drivers/char/rio/phb.h b/drivers/char/rio/phb.h
index e1483a0..3baebf8 100644
--- a/drivers/char/rio/phb.h
+++ b/drivers/char/rio/phb.h
@@ -58,37 +58,37 @@
 /*************************************************
  * Handshake asserted. Deasserted by the LTT(s)
  ************************************************/
-#define PHB_HANDSHAKE_SET      ((ushort) 0x001) /* Set by LRT */
+#define PHB_HANDSHAKE_SET      ((ushort) 0x001)	/* Set by LRT */
 
-#define PHB_HANDSHAKE_RESET     ((ushort) 0x002) /* Set by ISR / driver */
+#define PHB_HANDSHAKE_RESET     ((ushort) 0x002)	/* Set by ISR / driver */
 
 #define PHB_HANDSHAKE_FLAGS     (PHB_HANDSHAKE_RESET | PHB_HANDSHAKE_SET)
-                                                /* Reset by ltt */
+						/* Reset by ltt */
 
 
 /*************************************************
  * Maximum number of PHB's
  ************************************************/
 #if defined (HOST) || defined (INKERNEL)
-#define MAX_PHB               ((ushort) 128)  /* range 0-127 */
+#define MAX_PHB               ((ushort) 128)	/* range 0-127 */
 #else
-#define MAX_PHB               ((ushort) 8)    /* range 0-7 */
+#define MAX_PHB               ((ushort) 8)	/* range 0-7 */
 #endif
 
 /*************************************************
  * Defines for the mode fields
  ************************************************/
-#define TXPKT_INCOMPLETE        0x0001  /* Previous tx packet not completed */
-#define TXINTR_ENABLED          0x0002  /* Tx interrupt is enabled */
-#define TX_TAB3                 0x0004  /* TAB3 mode */
-#define TX_OCRNL                0x0008  /* OCRNL mode */
-#define TX_ONLCR                0x0010  /* ONLCR mode */
-#define TX_SENDSPACES           0x0020  /* Send n spaces command needs 
-                                           completing */
-#define TX_SENDNULL             0x0040  /* Escaping NULL needs completing */
-#define TX_SENDLF               0x0080  /* LF -> CR LF needs completing */
-#define TX_PARALLELBUG          0x0100  /* CD1400 LF -> CR LF bug on parallel
-                                           port */
+#define TXPKT_INCOMPLETE        0x0001	/* Previous tx packet not completed */
+#define TXINTR_ENABLED          0x0002	/* Tx interrupt is enabled */
+#define TX_TAB3                 0x0004	/* TAB3 mode */
+#define TX_OCRNL                0x0008	/* OCRNL mode */
+#define TX_ONLCR                0x0010	/* ONLCR mode */
+#define TX_SENDSPACES           0x0020	/* Send n spaces command needs
+					   completing */
+#define TX_SENDNULL             0x0040	/* Escaping NULL needs completing */
+#define TX_SENDLF               0x0080	/* LF -> CR LF needs completing */
+#define TX_PARALLELBUG          0x0100	/* CD1400 LF -> CR LF bug on parallel
+					   port */
 #define TX_HANGOVER             (TX_SENDSPACES | TX_SENDLF | TX_SENDNULL)
 #define TX_DTRFLOW		0x0200	/* DTR tx flow control */
 #define	TX_DTRFLOWED		0x0400	/* DTR is low - don't allow more data
@@ -96,34 +96,34 @@
 #define	TX_DATAINFIFO		0x0800	/* There is data in the FIFO */
 #define	TX_BUSY			0x1000	/* Data in FIFO, shift or holding regs */
 
-#define RX_SPARE	        0x0001   /* SPARE */
-#define RXINTR_ENABLED          0x0002   /* Rx interrupt enabled */
-#define RX_ICRNL                0x0008   /* ICRNL mode */
-#define RX_INLCR                0x0010   /* INLCR mode */
-#define RX_IGNCR                0x0020   /* IGNCR mode */
-#define RX_CTSFLOW              0x0040   /* CTSFLOW enabled */
-#define RX_IXOFF                0x0080   /* IXOFF enabled */
-#define RX_CTSFLOWED            0x0100   /* CTSFLOW and CTS dropped */
-#define RX_IXOFFED              0x0200   /* IXOFF and xoff sent */
-#define RX_BUFFERED		0x0400	 /* Try and pass on complete packets */
+#define RX_SPARE	        0x0001	/* SPARE */
+#define RXINTR_ENABLED          0x0002	/* Rx interrupt enabled */
+#define RX_ICRNL                0x0008	/* ICRNL mode */
+#define RX_INLCR                0x0010	/* INLCR mode */
+#define RX_IGNCR                0x0020	/* IGNCR mode */
+#define RX_CTSFLOW              0x0040	/* CTSFLOW enabled */
+#define RX_IXOFF                0x0080	/* IXOFF enabled */
+#define RX_CTSFLOWED            0x0100	/* CTSFLOW and CTS dropped */
+#define RX_IXOFFED              0x0200	/* IXOFF and xoff sent */
+#define RX_BUFFERED		0x0400	/* Try and pass on complete packets */
 
-#define PORT_ISOPEN             0x0001  /* Port open? */
-#define PORT_HUPCL              0x0002  /* Hangup on close? */
-#define PORT_MOPENPEND          0x0004  /* Modem open pending */
-#define PORT_ISPARALLEL         0x0008  /* Parallel port */
-#define PORT_BREAK              0x0010  /* Port on break */
-#define PORT_STATUSPEND		0x0020  /* Status packet pending */
-#define PORT_BREAKPEND          0x0040  /* Break packet pending */
-#define PORT_MODEMPEND          0x0080  /* Modem status packet pending */
-#define PORT_PARALLELBUG        0x0100  /* CD1400 LF -> CR LF bug on parallel
-                                           port */
-#define PORT_FULLMODEM          0x0200  /* Full modem signals */
-#define PORT_RJ45               0x0400  /* RJ45 connector - no RI signal */
-#define PORT_RESTRICTED         0x0600  /* Restricted connector - no RI / DTR */
+#define PORT_ISOPEN             0x0001	/* Port open? */
+#define PORT_HUPCL              0x0002	/* Hangup on close? */
+#define PORT_MOPENPEND          0x0004	/* Modem open pending */
+#define PORT_ISPARALLEL         0x0008	/* Parallel port */
+#define PORT_BREAK              0x0010	/* Port on break */
+#define PORT_STATUSPEND		0x0020	/* Status packet pending */
+#define PORT_BREAKPEND          0x0040	/* Break packet pending */
+#define PORT_MODEMPEND          0x0080	/* Modem status packet pending */
+#define PORT_PARALLELBUG        0x0100	/* CD1400 LF -> CR LF bug on parallel
+					   port */
+#define PORT_FULLMODEM          0x0200	/* Full modem signals */
+#define PORT_RJ45               0x0400	/* RJ45 connector - no RI signal */
+#define PORT_RESTRICTED         0x0600	/* Restricted connector - no RI / DTR */
 
-#define PORT_MODEMBITS          0x0600  /* Mask for modem fields */
+#define PORT_MODEMBITS          0x0600	/* Mask for modem fields */
 
-#define PORT_WCLOSE             0x0800  /* Waiting for close */
+#define PORT_WCLOSE             0x0800	/* Waiting for close */
 #define	PORT_HANDSHAKEFIX	0x1000	/* Port has H/W flow control fix */
 #define	PORT_WASPCLOSED		0x2000	/* Port closed with PCLOSE */
 #define	DUMPMODE		0x4000	/* Dump RTA mem */
@@ -155,139 +155,128 @@
 #define rx_end       u4.s1.rx_end_ptr_ptr
 #define rx_remove    u4.s1.rx_remove_ptr_ptr
 #endif
-typedef struct PHB PHB ;
+typedef struct PHB PHB;
 struct PHB {
 #ifdef RTA
-        ushort      port;
+	ushort port;
 #endif
 #ifdef INKERNEL
-        WORD      source;
+	WORD source;
 #else
-        union       
-        {
-            ushort source;              /* Complete source */
-            struct
-            {
-                unsigned char unit;     /* Source unit */
-                unsigned char port;     /* Source port */
-            } s2;
-        } u2;
+	union {
+		ushort source;	/* Complete source */
+		struct {
+			unsigned char unit;	/* Source unit */
+			unsigned char port;	/* Source port */
+		} s2;
+	} u2;
 #endif
-        WORD      handshake ;
-        WORD      status ;
-        NUMBER       timeout ;           /* Maximum of 1.9 seconds */
-        WORD      link ;              /* Send down this link */
+	WORD handshake;
+	WORD status;
+	NUMBER timeout;		/* Maximum of 1.9 seconds */
+	WORD link;		/* Send down this link */
 #ifdef INKERNEL
-        WORD      destination;
+	WORD destination;
 #else
-        union       
-        {
-            ushort destination;         /* Complete destination */
-            struct
-            {
-                unsigned char unit;     /* Destination unit */
-                unsigned char port;     /* Destination port */
-            } s1;
-        } u1;
+	union {
+		ushort destination;	/* Complete destination */
+		struct {
+			unsigned char unit;	/* Destination unit */
+			unsigned char port;	/* Destination port */
+		} s1;
+	} u1;
 #endif
 #ifdef RTA
-        ushort      tx_pkts_added;
-        ushort      tx_pkts_removed;
-        Q_BUF_ptr   tx_q_start ;        /* Start of the Q list chain */
-        short       num_tx_q_bufs ;     /* Number of Q buffers in the chain */
-        PKT_ptr_ptr tx_add ;            /* Add a new Packet here */
-        Q_BUF_ptr   tx_add_qb;          /* Pointer to the add Q buf */
-        PKT_ptr_ptr tx_add_st_qbb ;     /* Pointer to start of the Q's buf */
-        PKT_ptr_ptr tx_add_end_qbb ;    /* Pointer to the end of the Q's buf */
-        PKT_ptr_ptr tx_remove ;         /* Remove a Packet here */
-        Q_BUF_ptr   tx_remove_qb ;      /* Pointer to the remove Q buf */
-        PKT_ptr_ptr tx_remove_st_qbb ;  /* Pointer to the start of the Q buf */
-        PKT_ptr_ptr tx_remove_end_qbb ; /* Pointer to the end of the Q buf */
+	ushort tx_pkts_added;
+	ushort tx_pkts_removed;
+	Q_BUF_ptr tx_q_start;	/* Start of the Q list chain */
+	short num_tx_q_bufs;	/* Number of Q buffers in the chain */
+	PKT_ptr_ptr tx_add;	/* Add a new Packet here */
+	Q_BUF_ptr tx_add_qb;	/* Pointer to the add Q buf */
+	PKT_ptr_ptr tx_add_st_qbb;	/* Pointer to start of the Q's buf */
+	PKT_ptr_ptr tx_add_end_qbb;	/* Pointer to the end of the Q's buf */
+	PKT_ptr_ptr tx_remove;	/* Remove a Packet here */
+	Q_BUF_ptr tx_remove_qb;	/* Pointer to the remove Q buf */
+	PKT_ptr_ptr tx_remove_st_qbb;	/* Pointer to the start of the Q buf */
+	PKT_ptr_ptr tx_remove_end_qbb;	/* Pointer to the end of the Q buf */
 #endif
 #ifdef INKERNEL
-        PKT_ptr_ptr tx_start ;
-        PKT_ptr_ptr tx_end ;
-        PKT_ptr_ptr tx_add ;
-        PKT_ptr_ptr tx_remove ;
+	PKT_ptr_ptr tx_start;
+	PKT_ptr_ptr tx_end;
+	PKT_ptr_ptr tx_add;
+	PKT_ptr_ptr tx_remove;
 #endif
 #ifdef HOST
-        union
-        {
-            struct
-            {
-                PKT_ptr_ptr tx_start_ptr_ptr;
-                PKT_ptr_ptr tx_end_ptr_ptr;
-                PKT_ptr_ptr tx_add_ptr_ptr;
-                PKT_ptr_ptr tx_remove_ptr_ptr;
-            } s1;
-            struct
-            {
-                ushort * tx_start_ptr;
-                ushort * tx_end_ptr;
-                ushort * tx_add_ptr;
-                ushort * tx_remove_ptr;
-            } s2;
-        } u3;
+	union {
+		struct {
+			PKT_ptr_ptr tx_start_ptr_ptr;
+			PKT_ptr_ptr tx_end_ptr_ptr;
+			PKT_ptr_ptr tx_add_ptr_ptr;
+			PKT_ptr_ptr tx_remove_ptr_ptr;
+		} s1;
+		struct {
+			ushort *tx_start_ptr;
+			ushort *tx_end_ptr;
+			ushort *tx_add_ptr;
+			ushort *tx_remove_ptr;
+		} s2;
+	} u3;
 #endif
 
 #ifdef  RTA
-        ushort      rx_pkts_added;
-        ushort      rx_pkts_removed;
-        Q_BUF_ptr   rx_q_start ;        /* Start of the Q list chain */
-        short       num_rx_q_bufs ;     /* Number of Q buffers in the chain */
-        PKT_ptr_ptr rx_add ;            /* Add a new Packet here */
-        Q_BUF_ptr   rx_add_qb ;         /* Pointer to the add Q buf */
-        PKT_ptr_ptr rx_add_st_qbb ;     /* Pointer to start of the Q's buf */
-        PKT_ptr_ptr rx_add_end_qbb ;    /* Pointer to the end of the Q's buf */
-        PKT_ptr_ptr rx_remove ;         /* Remove a Packet here */
-        Q_BUF_ptr   rx_remove_qb ;      /* Pointer to the remove Q buf */
-        PKT_ptr_ptr rx_remove_st_qbb ;  /* Pointer to the start of the Q buf */
-        PKT_ptr_ptr rx_remove_end_qbb ; /* Pointer to the end of the Q buf */
+	ushort rx_pkts_added;
+	ushort rx_pkts_removed;
+	Q_BUF_ptr rx_q_start;	/* Start of the Q list chain */
+	short num_rx_q_bufs;	/* Number of Q buffers in the chain */
+	PKT_ptr_ptr rx_add;	/* Add a new Packet here */
+	Q_BUF_ptr rx_add_qb;	/* Pointer to the add Q buf */
+	PKT_ptr_ptr rx_add_st_qbb;	/* Pointer to start of the Q's buf */
+	PKT_ptr_ptr rx_add_end_qbb;	/* Pointer to the end of the Q's buf */
+	PKT_ptr_ptr rx_remove;	/* Remove a Packet here */
+	Q_BUF_ptr rx_remove_qb;	/* Pointer to the remove Q buf */
+	PKT_ptr_ptr rx_remove_st_qbb;	/* Pointer to the start of the Q buf */
+	PKT_ptr_ptr rx_remove_end_qbb;	/* Pointer to the end of the Q buf */
 #endif
 #ifdef INKERNEL
-        PKT_ptr_ptr rx_start ;
-        PKT_ptr_ptr rx_end ;
-        PKT_ptr_ptr rx_add ;
-        PKT_ptr_ptr rx_remove ;
+	PKT_ptr_ptr rx_start;
+	PKT_ptr_ptr rx_end;
+	PKT_ptr_ptr rx_add;
+	PKT_ptr_ptr rx_remove;
 #endif
 #ifdef HOST
-        union
-        {
-            struct
-            {
-                PKT_ptr_ptr rx_start_ptr_ptr;
-                PKT_ptr_ptr rx_end_ptr_ptr;
-                PKT_ptr_ptr rx_add_ptr_ptr;
-                PKT_ptr_ptr rx_remove_ptr_ptr;
-            } s1;
-            struct
-            {
-                ushort * rx_start_ptr;
-                ushort * rx_end_ptr;
-                ushort * rx_add_ptr;
-                ushort * rx_remove_ptr;
-            } s2;
-        } u4;
+	union {
+		struct {
+			PKT_ptr_ptr rx_start_ptr_ptr;
+			PKT_ptr_ptr rx_end_ptr_ptr;
+			PKT_ptr_ptr rx_add_ptr_ptr;
+			PKT_ptr_ptr rx_remove_ptr_ptr;
+		} s1;
+		struct {
+			ushort *rx_start_ptr;
+			ushort *rx_end_ptr;
+			ushort *rx_add_ptr;
+			ushort *rx_remove_ptr;
+		} s2;
+	} u4;
 #endif
 
-#ifdef RTA                              /* some fields for the remotes */
-        ushort     flush_count;		/* Count of write flushes */
-        ushort     txmode;		/* Modes for tx */
-        ushort     rxmode;		/* Modes for rx */
-        ushort     portmode;		/* Generic modes */
-        ushort     column;		/* TAB3 column count */
-        ushort     tx_subscript;	/* (TX) Subscript into data field */
-        ushort     rx_subscript;	/* (RX) Subscript into data field */
-        PKT_ptr    rx_incomplete;	/* Hold an incomplete packet here */
-        ushort     modem_bits;		/* Modem bits to mask */
-	ushort	   lastModem;		/* Modem control lines. */
-        ushort     addr;		/* Address for sub commands */
-        ushort     MonitorTstate;	/* TRUE if monitoring tstop */
+#ifdef RTA			/* some fields for the remotes */
+	ushort flush_count;	/* Count of write flushes */
+	ushort txmode;		/* Modes for tx */
+	ushort rxmode;		/* Modes for rx */
+	ushort portmode;	/* Generic modes */
+	ushort column;		/* TAB3 column count */
+	ushort tx_subscript;	/* (TX) Subscript into data field */
+	ushort rx_subscript;	/* (RX) Subscript into data field */
+	PKT_ptr rx_incomplete;	/* Hold an incomplete packet here */
+	ushort modem_bits;	/* Modem bits to mask */
+	ushort lastModem;	/* Modem control lines. */
+	ushort addr;		/* Address for sub commands */
+	ushort MonitorTstate;	/* TRUE if monitoring tstop */
 #endif
 
-        } ;
+};
 
 #endif
 
 /*********** end of file ***********/
-
diff --git a/drivers/char/rio/pkt.h b/drivers/char/rio/pkt.h
index 66bb2ff..882fd42 100644
--- a/drivers/char/rio/pkt.h
+++ b/drivers/char/rio/pkt.h
@@ -69,52 +69,44 @@
 #define CONTROL_PKT_TTL_MASK (PKT_TTL_MASK << 8)
 #define CONTROL_DATA_WNDW  (DATA_WNDW << 8)
 
-struct PKT    {
+struct PKT {
 #ifdef INKERNEL
-                   BYTE    dest_unit ;    /* Destination Unit Id */
-                   BYTE    dest_port ;    /* Destination POrt */
-                   BYTE    src_unit ;     /* Source Unit Id */
-                   BYTE    src_port ;     /* Source POrt */
+	BYTE dest_unit;		/* Destination Unit Id */
+	BYTE dest_port;		/* Destination POrt */
+	BYTE src_unit;		/* Source Unit Id */
+	BYTE src_port;		/* Source POrt */
 #else
-                   union       
-                   {
-                       ushort destination;         /* Complete destination */
-                       struct
-                       {
-                           unsigned char unit;     /* Destination unit */
-                           unsigned char port;     /* Destination port */
-                       } s1;
-                   } u1;
-                   union       
-                   {
-                       ushort source;              /* Complete source */
-                       struct
-                       {
-                           unsigned char unit;     /* Source unit */
-                           unsigned char port;     /* Source port */
-                       } s2;
-                   } u2;
+	union {
+		ushort destination;	/* Complete destination */
+		struct {
+			unsigned char unit;	/* Destination unit */
+			unsigned char port;	/* Destination port */
+		} s1;
+	} u1;
+	union {
+		ushort source;	/* Complete source */
+		struct {
+			unsigned char unit;	/* Source unit */
+			unsigned char port;	/* Source port */
+		} s2;
+	} u2;
 #endif
 #ifdef INKERNEL
-                   BYTE len ;
-                   BYTE control;
+	BYTE len;
+	BYTE control;
 #else
-                   union
-                   {
-                        ushort      control;
-                        struct
-                        {
-                            unsigned char len;
-                            unsigned char control;
-                        } s3;
-                    } u3;
+	union {
+		ushort control;
+		struct {
+			unsigned char len;
+			unsigned char control;
+		} s3;
+	} u3;
 #endif
-                   BYTE    data[PKT_MAX_DATA_LEN] ;     
-                                                   /* Actual data :-) */
-                   WORD  csum ;                  /* C-SUM */
-               } ;
+	BYTE data[PKT_MAX_DATA_LEN];
+	/* Actual data :-) */
+	WORD csum;		/* C-SUM */
+};
 #endif
 
 /*********** end of file ***********/
-
-
diff --git a/drivers/char/rio/poll.h b/drivers/char/rio/poll.h
index d9b8e98..9616ee4 100644
--- a/drivers/char/rio/poll.h
+++ b/drivers/char/rio/poll.h
@@ -39,7 +39,7 @@
 
 #ifndef lint
 #ifdef SCCS_LABELS
-static char *_rio_poll_h_sccs = "@(#)poll.h	1.2" ;
+static char *_rio_poll_h_sccs = "@(#)poll.h	1.2";
 #endif
 #endif
 
@@ -54,23 +54,20 @@
 #define POLL_PERIOD           (int) SECOND
 
 /* The various poll commands */
-#define POLL_POLL             0            /* We are connected and happy.. */
-#define POLL_INTRO            1            /* Introduction packet */
-#define POLL_TOPOLOGY         2            /* Topology update */
-#define POLL_ASSIGN           3            /* ID assign */
-#define POLL_FOAD             4            /* F*** Off And Die */
-#define POLL_LMD	      5		   /* Let Me Die */
-#define POLL_DYB	      6		   /* Die You Ba***** */
+#define POLL_POLL             0	/* We are connected and happy.. */
+#define POLL_INTRO            1	/* Introduction packet */
+#define POLL_TOPOLOGY         2	/* Topology update */
+#define POLL_ASSIGN           3	/* ID assign */
+#define POLL_FOAD             4	/* F*** Off And Die */
+#define POLL_LMD	      5	/* Let Me Die */
+#define POLL_DYB	      6	/* Die You Ba***** */
 
 /* The way data fields are split up for POLL packets */
-#define POLL_HOST_SERIAL      2            /* Host who booted me */
-#define POLL_MY_SERIAL        6            /* My serial number */
-#define POLL_YOUR_ID          1            /* Your ID number */
-#define POLL_TOPOLOGY_FIELDS  2            /* Topology maps */
+#define POLL_HOST_SERIAL      2	/* Host who booted me */
+#define POLL_MY_SERIAL        6	/* My serial number */
+#define POLL_YOUR_ID          1	/* Your ID number */
+#define POLL_TOPOLOGY_FIELDS  2	/* Topology maps */
 
 #endif
 
 /*********** end of file ***********/
-
-
-
diff --git a/drivers/char/rio/port.h b/drivers/char/rio/port.h
index 8506af0..c99b1e7 100644
--- a/drivers/char/rio/port.h
+++ b/drivers/char/rio/port.h
@@ -46,96 +46,94 @@
 */
 
 #ifdef STATS
-struct RIOStats
-{
+struct RIOStats {
 	/*
-	** interrupt statistics
-	*/
-	uint	BreakIntCnt;
-	uint	ModemOffCnt;
-	uint	ModemOnCnt;
-	uint	RxIntCnt;
-	uint	TxIntCnt;
+	 ** interrupt statistics
+	 */
+	uint BreakIntCnt;
+	uint ModemOffCnt;
+	uint ModemOnCnt;
+	uint RxIntCnt;
+	uint TxIntCnt;
 	/*
-	** throughput statistics
-	*/
-	uint	RxCharCnt;
-	uint	RxPktCnt;
-	uint	RxSaveCnt;
-	uint	TxCharCnt;
-	uint	TxPktCnt;
+	 ** throughput statistics
+	 */
+	uint RxCharCnt;
+	uint RxPktCnt;
+	uint RxSaveCnt;
+	uint TxCharCnt;
+	uint TxPktCnt;
 	/*
-	** driver entry statistics
-	*/
-	uint	CloseCnt;
-	uint	IoctlCnt;
-	uint	OpenCnt;
-	uint	ReadCnt;
-	uint	WriteCnt;
+	 ** driver entry statistics
+	 */
+	uint CloseCnt;
+	uint IoctlCnt;
+	uint OpenCnt;
+	uint ReadCnt;
+	uint WriteCnt;
 	/*
-	** proc statistics
-	*/
-	uint	BlockCnt;
-	uint	OutputCnt;
-	uint	ResumeCnt;
-	uint	RflushCnt;
-	uint	SuspendCnt;
-	uint	TbreakCnt;
-	uint	TimeoutCnt;
-	uint	UnblockCnt;
-	uint	WflushCnt;
-	uint	WFBodgeCnt;
+	 ** proc statistics
+	 */
+	uint BlockCnt;
+	uint OutputCnt;
+	uint ResumeCnt;
+	uint RflushCnt;
+	uint SuspendCnt;
+	uint TbreakCnt;
+	uint TimeoutCnt;
+	uint UnblockCnt;
+	uint WflushCnt;
+	uint WFBodgeCnt;
 };
 #endif
 
 /*
 **	Port data structure
 */
-struct	Port
-{
-  struct gs_port gs; 
-  int				PortNum;	/* RIO port no., 0-511 */
-  struct Host	*HostP;
-  volatile caddr_t		Caddr;
-  ushort			HostPort;  /* Port number on host card */
-  uchar			RupNum;	/* Number of RUP for port */
-  uchar			ID2;	/* Second ID of RTA for port */
-  ulong			State;	/* FLAGS for open & xopen */
-#define	RIO_LOPEN	0x00001		/* Local open */
-#define	RIO_MOPEN	0x00002		/* Modem open */
-#define	RIO_WOPEN	0x00004		/* Waiting for open */
-#define	RIO_CLOSING	0x00008		/* The port is being close */
-#define	RIO_XPBUSY	0x00010		/* Transparent printer busy */
-#define	RIO_BREAKING	0x00020		/* Break in progress */
-#define	RIO_DIRECT	0x00040		/* Doing Direct output */
-#define	RIO_EXCLUSIVE	0x00080		/* Stream open for exclusive use */
-#define	RIO_NDELAY	0x00100		/* Stream is open FNDELAY */
-#define	RIO_CARR_ON	0x00200		/* Stream has carrier present */
-#define	RIO_XPWANTR	0x00400		/* Stream wanted by Xprint */
-#define	RIO_RBLK	0x00800		/* Stream is read-blocked */
-#define	RIO_BUSY	0x01000		/* Stream is BUSY for write */
-#define	RIO_TIMEOUT	0x02000		/* Stream timeout in progress */
-#define	RIO_TXSTOP	0x04000		/* Stream output is stopped */
-#define	RIO_WAITFLUSH	0x08000		/* Stream waiting for flush */
-#define	RIO_DYNOROD	0x10000		/* Drain failed */
-#define	RIO_DELETED	0x20000		/* RTA has been deleted */
-#define RIO_ISSCANCODE	0x40000		/* This line is in scancode mode */
+struct Port {
+	struct gs_port gs;
+	int PortNum;		/* RIO port no., 0-511 */
+	struct Host *HostP;
+	volatile caddr_t Caddr;
+	ushort HostPort;	/* Port number on host card */
+	uchar RupNum;		/* Number of RUP for port */
+	uchar ID2;		/* Second ID of RTA for port */
+	ulong State;		/* FLAGS for open & xopen */
+#define	RIO_LOPEN	0x00001	/* Local open */
+#define	RIO_MOPEN	0x00002	/* Modem open */
+#define	RIO_WOPEN	0x00004	/* Waiting for open */
+#define	RIO_CLOSING	0x00008	/* The port is being close */
+#define	RIO_XPBUSY	0x00010	/* Transparent printer busy */
+#define	RIO_BREAKING	0x00020	/* Break in progress */
+#define	RIO_DIRECT	0x00040	/* Doing Direct output */
+#define	RIO_EXCLUSIVE	0x00080	/* Stream open for exclusive use */
+#define	RIO_NDELAY	0x00100	/* Stream is open FNDELAY */
+#define	RIO_CARR_ON	0x00200	/* Stream has carrier present */
+#define	RIO_XPWANTR	0x00400	/* Stream wanted by Xprint */
+#define	RIO_RBLK	0x00800	/* Stream is read-blocked */
+#define	RIO_BUSY	0x01000	/* Stream is BUSY for write */
+#define	RIO_TIMEOUT	0x02000	/* Stream timeout in progress */
+#define	RIO_TXSTOP	0x04000	/* Stream output is stopped */
+#define	RIO_WAITFLUSH	0x08000	/* Stream waiting for flush */
+#define	RIO_DYNOROD	0x10000	/* Drain failed */
+#define	RIO_DELETED	0x20000	/* RTA has been deleted */
+#define RIO_ISSCANCODE	0x40000	/* This line is in scancode mode */
 #define	RIO_USING_EUC	0x100000	/* Using extended Unix chars */
 #define	RIO_CAN_COOK	0x200000	/* This line can do cooking */
-#define RIO_TRIAD_MODE  0x400000        /* Enable TRIAD special ops. */
-#define RIO_TRIAD_BLOCK 0x800000        /* Next read will block */
-#define RIO_TRIAD_FUNC  0x1000000       /* Seen a function key coming in */
-#define RIO_THROTTLE_RX 0x2000000       /* RX needs to be throttled. */
+#define RIO_TRIAD_MODE  0x400000	/* Enable TRIAD special ops. */
+#define RIO_TRIAD_BLOCK 0x800000	/* Next read will block */
+#define RIO_TRIAD_FUNC  0x1000000	/* Seen a function key coming in */
+#define RIO_THROTTLE_RX 0x2000000	/* RX needs to be throttled. */
 
-    ulong			Config;	/* FLAGS for NOREAD.... */
-#define	RIO_NOREAD	0x0001		/* Are not allowed to read port */
-#define	RIO_NOWRITE	0x0002		/* Are not allowed to write port */
-#define	RIO_NOXPRINT	0x0004		/* Are not allowed to xprint port */
-#define	RIO_NOMASK	0x0007		/* All not allowed things */
-#define RIO_IXANY	0x0008          /* Port is allowed ixany */
-#define	RIO_MODEM	0x0010		/* Stream is a modem device */
-#define	RIO_IXON	0x0020		/* Port is allowed ixon */
-#define RIO_WAITDRAIN	0x0040		/* Wait for port to completely drain */
+	ulong Config;		/* FLAGS for NOREAD.... */
+#define	RIO_NOREAD	0x0001	/* Are not allowed to read port */
+#define	RIO_NOWRITE	0x0002	/* Are not allowed to write port */
+#define	RIO_NOXPRINT	0x0004	/* Are not allowed to xprint port */
+#define	RIO_NOMASK	0x0007	/* All not allowed things */
+#define RIO_IXANY	0x0008	/* Port is allowed ixany */
+#define	RIO_MODEM	0x0010	/* Stream is a modem device */
+#define	RIO_IXON	0x0020	/* Port is allowed ixon */
+#define RIO_WAITDRAIN	0x0040	/* Wait for port to completely drain */
 #define RIO_MAP_50_TO_50	0x0080	/* Map 50 baud to 50 baud */
 #define RIO_MAP_110_TO_110	0x0100	/* Map 110 baud to 110 baud */
 
@@ -144,92 +142,90 @@
 ** As LynxOS does not appear to support Hardware Flow Control .....
 ** Define our own flow control flags in 'Config'.
 */
-#define RIO_CTSFLOW	0x0200		/* RIO's own CTSFLOW flag */
-#define RIO_RTSFLOW	0x0400		/* RIO's own RTSFLOW flag */
+#define RIO_CTSFLOW	0x0200	/* RIO's own CTSFLOW flag */
+#define RIO_RTSFLOW	0x0400	/* RIO's own RTSFLOW flag */
 
 
-    struct PHB			*PhbP;	  /* pointer to PHB for port */
-    WORD                        *TxAdd;   /* Add packets here */
-    WORD                        *TxStart; /* Start of add array */
-    WORD                        *TxEnd;         /* End of add array */
-    WORD                        *RxRemove;      /* Remove packets here */
-    WORD                        *RxStart;       /* Start of remove array */
-    WORD                        *RxEnd;         /* End of remove array */
-    uint			RtaUniqueNum;	/* Unique number of RTA */
-    ushort			PortState;	/* status of port */
-    ushort			ModemState;	/* status of modem lines */
-    ulong			ModemLines;	/* Modem bits sent to RTA */
-    uchar			CookMode;	/* who expands CR/LF? */
-    uchar			ParamSem;	/* Prevent write during param */
-    uchar			Mapped;		/* if port mapped onto host */
-    uchar			SecondBlock;	/* if port belongs to 2nd block
-						   of 16 port RTA */
-    uchar			InUse;		/* how many pre-emptive cmds */
-    uchar			Lock;		/* if params locked */
-    uchar			Store;	/* if params stored across closes */
-    uchar			FirstOpen; /* TRUE if first time port opened */
-    uchar			FlushCmdBodge;	/* if doing a (non)flush */
-    uchar			MagicFlags;	/* require intr processing */
+	struct PHB *PhbP;	/* pointer to PHB for port */
+	WORD *TxAdd;		/* Add packets here */
+	WORD *TxStart;		/* Start of add array */
+	WORD *TxEnd;		/* End of add array */
+	WORD *RxRemove;		/* Remove packets here */
+	WORD *RxStart;		/* Start of remove array */
+	WORD *RxEnd;		/* End of remove array */
+	uint RtaUniqueNum;	/* Unique number of RTA */
+	ushort PortState;	/* status of port */
+	ushort ModemState;	/* status of modem lines */
+	ulong ModemLines;	/* Modem bits sent to RTA */
+	uchar CookMode;		/* who expands CR/LF? */
+	uchar ParamSem;		/* Prevent write during param */
+	uchar Mapped;		/* if port mapped onto host */
+	uchar SecondBlock;	/* if port belongs to 2nd block
+				   of 16 port RTA */
+	uchar InUse;		/* how many pre-emptive cmds */
+	uchar Lock;		/* if params locked */
+	uchar Store;		/* if params stored across closes */
+	uchar FirstOpen;	/* TRUE if first time port opened */
+	uchar FlushCmdBodge;	/* if doing a (non)flush */
+	uchar MagicFlags;	/* require intr processing */
 #define	MAGIC_FLUSH	0x01	/* mirror of WflushFlag */
 #define	MAGIC_REBOOT	0x02	/* RTA re-booted, re-open ports */
 #define	MORE_OUTPUT_EYGOR 0x04	/* riotproc failed to empty clists */
-    uchar			WflushFlag;	/* 1 How many WFLUSHs active */
+	uchar WflushFlag;	/* 1 How many WFLUSHs active */
 /*
 ** Transparent print stuff
 */
-    struct Xprint
-    {
+	struct Xprint {
 #ifndef MAX_XP_CTRL_LEN
-#define MAX_XP_CTRL_LEN		16		/* ALSO IN DAEMON.H */
+#define MAX_XP_CTRL_LEN		16	/* ALSO IN DAEMON.H */
 #endif
-	uint			XpCps;
-	char			XpOn[MAX_XP_CTRL_LEN];
-	char			XpOff[MAX_XP_CTRL_LEN];
-	ushort			XpLen;		/* strlen(XpOn)+strlen(XpOff) */
-	uchar			XpActive;
-	uchar			XpLastTickOk;	/* TRUE if we can process */
+		uint XpCps;
+		char XpOn[MAX_XP_CTRL_LEN];
+		char XpOff[MAX_XP_CTRL_LEN];
+		ushort XpLen;	/* strlen(XpOn)+strlen(XpOff) */
+		uchar XpActive;
+		uchar XpLastTickOk;	/* TRUE if we can process */
 #define	XP_OPEN		00001
 #define	XP_RUNABLE	00002
-	struct ttystatics 		*XttyP;
-    } Xprint;
+		struct ttystatics *XttyP;
+	} Xprint;
 #ifdef VPIX
-    v86_t			*StashP;
-    uint			IntMask;
-    struct termss 		VpixSs;
-    uchar			ModemStatusReg;	/* Modem status register */
+	v86_t *StashP;
+	uint IntMask;
+	struct termss VpixSs;
+	uchar ModemStatusReg;	/* Modem status register */
 #endif
-    uchar			RxDataStart;
-    uchar			Cor2Copy;	/* copy of COR2 */
-    char			*Name;		/* points to the Rta's name */
+	uchar RxDataStart;
+	uchar Cor2Copy;		/* copy of COR2 */
+	char *Name;		/* points to the Rta's name */
 #ifdef STATS
-    struct RIOStats 		Stat;		/* ports statistics */
+	struct RIOStats Stat;	/* ports statistics */
 #endif
-    char			*TxRingBuffer;
-    ushort			TxBufferIn;	/* New data arrives here */
-    ushort			TxBufferOut;	/* Intr removes data here */
-    ushort			OldTxBufferOut;	/* Indicates if draining */
-    int				TimeoutId;	/* Timeout ID */
-    uint			Debug;
-    uchar			WaitUntilBooted; /* True if open should block */
-    uint			statsGather;	/* True if gathering stats */
-    ulong			txchars;	/* Chars transmitted */
-    ulong			rxchars;	/* Chars received */
-    ulong			opens;		/* port open count */
-    ulong			closes;		/* port close count */
-    ulong			ioctls;		/* ioctl count */
-    uchar			LastRxTgl;	/* Last state of rx toggle bit */
-  spinlock_t				portSem;	/* Lock using this sem */
-	int				MonitorTstate;	/* Monitoring ? */
-	int				timeout_id;	/* For calling 100 ms delays */
-	int				timeout_sem;/* For calling 100 ms delays */
-	int				firstOpen;	/* First time open ? */
-	char *			p;			/* save the global struc here .. */
+	char *TxRingBuffer;
+	ushort TxBufferIn;	/* New data arrives here */
+	ushort TxBufferOut;	/* Intr removes data here */
+	ushort OldTxBufferOut;	/* Indicates if draining */
+	int TimeoutId;		/* Timeout ID */
+	uint Debug;
+	uchar WaitUntilBooted;	/* True if open should block */
+	uint statsGather;	/* True if gathering stats */
+	ulong txchars;		/* Chars transmitted */
+	ulong rxchars;		/* Chars received */
+	ulong opens;		/* port open count */
+	ulong closes;		/* port close count */
+	ulong ioctls;		/* ioctl count */
+	uchar LastRxTgl;	/* Last state of rx toggle bit */
+	spinlock_t portSem;	/* Lock using this sem */
+	int MonitorTstate;	/* Monitoring ? */
+	int timeout_id;		/* For calling 100 ms delays */
+	int timeout_sem;	/* For calling 100 ms delays */
+	int firstOpen;		/* First time open ? */
+	char *p;		/* save the global struc here .. */
 };
 
-struct ModuleInfo
-{
-	char	*Name;
-	uint	Flags[4];	/* one per port on a module */
+struct ModuleInfo {
+	char *Name;
+	uint Flags[4];		/* one per port on a module */
 };
 #endif
 
@@ -238,8 +234,8 @@
 ** runs into problems with differing struct sizes between driver and config.
 */
 struct PortParams {
-	uint	Port;
-	ulong	Config;
-	ulong	State;
-	struct ttystatics	*TtyP;
+	uint Port;
+	ulong Config;
+	ulong State;
+	struct ttystatics *TtyP;
 };
diff --git a/drivers/char/rio/proto.h b/drivers/char/rio/proto.h
index ddff0ef..f9a3376 100644
--- a/drivers/char/rio/proto.h
+++ b/drivers/char/rio/proto.h
@@ -23,15 +23,15 @@
 /*
 ** boot.c
 */
-void init_boot( char *p, short stage);
+void init_boot(char *p, short stage);
 
 /*
 ** disconct.c
 */
-void kill_boot ( LPB *link );
-void disconnected( LPB *link );
-short boot_3( LPB *link, PKT *pkt );
-short send_3_pkt( LPB *link, PKT *pkt);
+void kill_boot(LPB * link);
+void disconnected(LPB * link);
+short boot_3(LPB * link, PKT * pkt);
+short send_3_pkt(LPB * link, PKT * pkt);
 
 /*
 ** error.c
@@ -41,116 +41,116 @@
 /*
 ** formpkt.c
 */
-ushort sum_it( PKT *pkt ) ;
-void form_rup_pkt( RUP *form_rup, PKT *pkt );
-void form_poll_pkt ( int type, LPB *link, int node );
-void form_route_pkt ( int type, PKT *pkt, LPB *link );
+ushort sum_it(PKT * pkt);
+void form_rup_pkt(RUP * form_rup, PKT * pkt);
+void form_poll_pkt(int type, LPB * link, int node);
+void form_route_pkt(int type, PKT * pkt, LPB * link);
 
 /*
 ** idle.c
 */
-void idle( Process *idle_p );
+void idle(Process * idle_p);
 
 /*
 ** init.c
 */
 void general_init(void);
-void mem_halt( int error);
+void mem_halt(int error);
 
 /*
 ** linkinit.c
 */
-void initlink( u_short number, LPB *link);
-void runlink( LPB *link);
+void initlink(u_short number, LPB * link);
+void runlink(LPB * link);
 
 /*
 ** list.c
 */
 PKT *get_free_start(void);
-void put_free_start( PKT *pkt);
+void put_free_start(PKT * pkt);
 
 #ifdef HOST
-int can_remove_transmit ( PKT **pkt, PKT *pointer );
+int can_remove_transmit(PKT ** pkt, PKT * pointer);
 #endif
 
 #ifdef RTA
-int spl7 ( void );
-int spl0 ( void );
-Q_BUF *get_free_q( void );
+int spl7(void);
+int spl0(void);
+Q_BUF *get_free_q(void);
 PKT *get_free_end(void);
-int add_end( PKT *pkt, PHB *phb, int type);
-unsigned short free_packets( PHB *phb, int type);
-int can_remove_start( PKT **pkt, PHB *phb, int type);
-int can_add_start( PHB *phb, int type);
-int can_add_end( PHB *phb, int type);
-void put_free_end( PKT *pkt);
-int remove_start( PKT **pkt, PHB *phb, int type);
+int add_end(PKT * pkt, PHB * phb, int type);
+unsigned short free_packets(PHB * phb, int type);
+int can_remove_start(PKT ** pkt, PHB * phb, int type);
+int can_add_start(PHB * phb, int type);
+int can_add_end(PHB * phb, int type);
+void put_free_end(PKT * pkt);
+int remove_start(PKT ** pkt, PHB * phb, int type);
 #endif
 
 /*
 ** Lrt.c
 */
-void lrt( Process *lrt_p, LPB *link );
+void lrt(Process * lrt_p, LPB * link);
 
 #ifdef RTA
-void set_led_red ( LPB *link );
+void set_led_red(LPB * link);
 #endif
 
 /*
 ** ltt.c
 */
-void ltt( Process *ltt_p, LPB *link, PHB *phb_ptr[] );
-void send_poll ( LPB *link );
-void request_id ( LPB *link );
-void send_topology_update ( LPB *link );
-void send_topology ( LPB *link );
-void supply_id ( LPB *link );
+void ltt(Process * ltt_p, LPB * link, PHB * phb_ptr[]);
+void send_poll(LPB * link);
+void request_id(LPB * link);
+void send_topology_update(LPB * link);
+void send_topology(LPB * link);
+void supply_id(LPB * link);
 
 #ifdef RTA
-void redirect_queue ( LPB *link, ushort flush );
-int obtain_rup ( int rup_number, PKT **pkt_address, LPB *link );
+void redirect_queue(LPB * link, ushort flush);
+int obtain_rup(int rup_number, PKT ** pkt_address, LPB * link);
 #endif
 
 #ifdef TESTING_PERF
-int consume_cpu( void );
+int consume_cpu(void);
 #endif
 
 /*
 ** lttwake.c
 */
 #ifdef HOST
-void ltt_wakeup( Process *ltt_wakeup_p );
+void ltt_wakeup(Process * ltt_wakeup_p);
 #endif
 
 /*
 ** mapgen.c
 */
-void generate_id_map( short mapping, ROUTE_STR route[] );
-void gen_map( int mapping, int looking_at, int come_from, ROUTE_STR route[], int link, int *ttl );
-void adjust_ttl( int mapping, int looking_at, int come_from, ROUTE_STR route[], int link, int *ttl);
+void generate_id_map(short mapping, ROUTE_STR route[]);
+void gen_map(int mapping, int looking_at, int come_from, ROUTE_STR route[], int link, int *ttl);
+void adjust_ttl(int mapping, int looking_at, int come_from, ROUTE_STR route[], int link, int *ttl);
 void init_sys_map(void);
 
 /*
 ** mmu.c
 */
-char *rio_malloc( unsigned int amount);
-char *rio_calloc( unsigned int num, unsigned int size);
-ERROR rio_mmu_init( uint total_mem );
+char *rio_malloc(unsigned int amount);
+char *rio_calloc(unsigned int num, unsigned int size);
+ERROR rio_mmu_init(uint total_mem);
 
 /*
 ** partn.c
 */
-void partition_tx( struct PHB *phb, u_short tx_size, u_short rx_size, u_short rx_limit);
+void partition_tx(struct PHB *phb, u_short tx_size, u_short rx_size, u_short rx_limit);
 
 /*
 ** poll.c
 */
-void tx_poll( Process *tx_poll_p);
+void tx_poll(Process * tx_poll_p);
 
 /*
 ** process.c
 */
-int  get_proc_space( Process **pd, int **pws, int wssize);
+int get_proc_space(Process ** pd, int **pws, int wssize);
 
 /*
 ** readrom.c
@@ -160,85 +160,85 @@
 /*
 ** rio.c
 */
-int main( void );
+int main(void);
 
 /*
 ** route.c
 */
-void route_update ( PKT *pkt, LPB *link);
+void route_update(PKT * pkt, LPB * link);
 
 /*
 ** rtainit.c
 */
 #if defined(RTA)
 void rta_init(ushort RtaType);
-#endif /* defined(RTA) */
+#endif				/* defined(RTA) */
 
 /*
 ** rupboot.c
 */
-void rup_boot( PKT *pkt, RUP *this_rup, LPB *link);
+void rup_boot(PKT * pkt, RUP * this_rup, LPB * link);
 
 #ifdef RTA
-void kill_your_neighbour( int link_to_kill );
+void kill_your_neighbour(int link_to_kill);
 #endif
 
 /*
 ** rupcmd.c
 */
-void rup_command( PKT *pkt, struct RUP *this_rup, LPB *link);
+void rup_command(PKT * pkt, struct RUP *this_rup, LPB * link);
 
 /*
 ** ruperr.c
 */
-void rup_error( PKT *pkt, RUP *this_rup, LPB *link );
-void illegal_cmd( PKT *src_pkt );
+void rup_error(PKT * pkt, RUP * this_rup, LPB * link);
+void illegal_cmd(PKT * src_pkt);
 
 /*
 ** ruppoll.c
 */
-void rup_poll( PKT *pkt, RUP *this_rup, LPB *link );
+void rup_poll(PKT * pkt, RUP * this_rup, LPB * link);
 
 /*
 ** ruppower.c
 */
-void rup_power( PKT *pkt, RUP *this_rup, LPB *link );
+void rup_power(PKT * pkt, RUP * this_rup, LPB * link);
 
 /*
 ** ruprm.c
 */
-void rup_route_map( PKT *pkt, RUP *this_rup, LPB *link);
+void rup_route_map(PKT * pkt, RUP * this_rup, LPB * link);
 
 /*
 ** rupstat.c
 */
-void rup_status( PKT *pkt, RUP *this_rup, LPB *link);
+void rup_status(PKT * pkt, RUP * this_rup, LPB * link);
 
 /*
 ** rupsync.c
 */
-void rup_sync( PKT *pkt);
+void rup_sync(PKT * pkt);
 
 /*
 ** rxpkt.c
 */
-ERROR  rx_pkt( PKT_ptr_ptr pkt_address, LPB *link);
+ERROR rx_pkt(PKT_ptr_ptr pkt_address, LPB * link);
 
 /*
 ** sendsts.c
 */
-void send_status( PKT *requesting_pkt, RUP *this_rup);
+void send_status(PKT * requesting_pkt, RUP * this_rup);
 
 /*
 ** serial.c
 */
-void assign_serial ( char *ser_in, char *ser_out);
-int cmp_serial ( char *ser_1, char *ser_2);
+void assign_serial(char *ser_in, char *ser_out);
+int cmp_serial(char *ser_1, char *ser_2);
 
 /*
 ** txpkt.c
 */
-ERROR  tx_pkt( PKT *pkt, LPB *link);
-short send_sync( LPB *link);
+ERROR tx_pkt(PKT * pkt, LPB * link);
+short send_sync(LPB * link);
 
-#endif	/* _prototypes_h */
+#endif				/* _prototypes_h */
diff --git a/drivers/char/rio/protsts.h b/drivers/char/rio/protsts.h
index 848111a..69fc4bc 100644
--- a/drivers/char/rio/protsts.h
+++ b/drivers/char/rio/protsts.h
@@ -115,5 +115,3 @@
 #endif
 
 /*********** end of file ***********/
-
-
diff --git a/drivers/char/rio/qbuf.h b/drivers/char/rio/qbuf.h
index 1fce02f..acd9e8e 100644
--- a/drivers/char/rio/qbuf.h
+++ b/drivers/char/rio/qbuf.h
@@ -40,7 +40,7 @@
 
 #ifndef lint
 #ifdef SCCS_LABELS
-static char *_rio_qbuf_h_sccs = "@(#)qbuf.h	1.1" ;
+static char *_rio_qbuf_h_sccs = "@(#)qbuf.h	1.1";
 #endif
 #endif
 
@@ -52,16 +52,15 @@
 #define PKTS_PER_BUFFER    (220 / PKT_LENGTH)
 #endif
 
-typedef struct Q_BUF Q_BUF ;
-struct Q_BUF  {
-                  Q_BUF_ptr next ;
-                  Q_BUF_ptr prev ;
-                  PKT_ptr buf[PKTS_PER_BUFFER] ;
-              } ;
+typedef struct Q_BUF Q_BUF;
+struct Q_BUF {
+	Q_BUF_ptr next;
+	Q_BUF_ptr prev;
+	PKT_ptr buf[PKTS_PER_BUFFER];
+};
 
 
 #endif
 
 
 /*********** end of file ***********/
-
diff --git a/drivers/char/rio/rio.h b/drivers/char/rio/rio.h
index 13a9931..7f45e1a 100644
--- a/drivers/char/rio/rio.h
+++ b/drivers/char/rio/rio.h
@@ -72,8 +72,8 @@
 #define	RIO_HOSTS	4	/* number of hosts that can be found */
 #define	PORTS_PER_HOST	128	/* number of ports per host */
 #define	LINKS_PER_UNIT	4	/* number of links from a host */
-#define	RIO_PORTS	(PORTS_PER_HOST * RIO_HOSTS) /* max. no. of ports */
-#define	RTAS_PER_HOST	(MAX_RUP) /* number of RTAs per host */
+#define	RIO_PORTS	(PORTS_PER_HOST * RIO_HOSTS)	/* max. no. of ports */
+#define	RTAS_PER_HOST	(MAX_RUP)	/* number of RTAs per host */
 #define	PORTS_PER_RTA	(PORTS_PER_HOST/RTAS_PER_HOST)	/* ports on a rta */
 #define	PORTS_PER_MODULE 4	/* number of ports on a plug-in module */
 				/* number of modules on an RTA */
@@ -216,10 +216,9 @@
 #define	RIO_PRI	(PZERO+10)
 #define RIO_CLOSE_PRI	PZERO-1	/* uninterruptible sleeps for close */
 
-typedef struct DbInf
-{
-	uint	Flag;
-	char	Name[8];
+typedef struct DbInf {
+	uint Flag;
+	char Name[8];
 } DbInf;
 
 #ifndef TRUE
@@ -251,7 +250,7 @@
 	*((uint *)PK)    = PP->PacketInfo; \
 }
 
-#define	RIO_LINK_ENABLE	0x80FF /* FF is a hack, mainly for Mips, to        */
+#define	RIO_LINK_ENABLE	0x80FF	/* FF is a hack, mainly for Mips, to        */
 			       /* prevent a really stupid race condition.  */
 
 #define	NOT_INITIALISED	0
@@ -291,4 +290,4 @@
 #define DIST_LINESW_OUTPUT	0x40
 #define DIST_LINESW_MDMINT	0x80
 
-#endif /* __rio_h__ */
+#endif				/* __rio_h__ */
diff --git a/drivers/char/rio/rio_linux.c b/drivers/char/rio/rio_linux.c
index d7d4840..8825bd6 100644
--- a/drivers/char/rio/rio_linux.c
+++ b/drivers/char/rio/rio_linux.c
@@ -33,7 +33,7 @@
  * */
 
 #include <linux/module.h>
-#include <linux/config.h> 
+#include <linux/config.h>
 #include <linux/kdev_t.h>
 #include <asm/io.h>
 #include <linux/kernel.h>
@@ -56,10 +56,6 @@
 #include <linux/generic_serial.h>
 #include <asm/uaccess.h>
 
-#if BITS_PER_LONG != 32
-#  error FIXME: this driver only works on 32-bit platforms
-#endif
-
 #include "linux_compat.h"
 #include "typdef.h"
 #include "pkt.h"
@@ -116,7 +112,7 @@
 #define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000
 #endif
 
-#ifndef RIO_WINDOW_LEN 
+#ifndef RIO_WINDOW_LEN
 #define RIO_WINDOW_LEN 0x10000
 #endif
 
@@ -144,34 +140,51 @@
  */
 #define RIO_REPORT_FIFO
 #define RIO_REPORT_OVERRUN
-#endif 
+#endif
 
 
 /* These constants are derived from SCO Source */
 static struct Conf
-RIOConf =
-{
-  /* locator */         "RIO Config here",
-  /* startuptime */     HZ*2,           /* how long to wait for card to run */
-  /* slowcook */        0,              /* TRUE -> always use line disc. */
-  /* intrpolltime */    1,              /* The frequency of OUR polls */
-  /* breakinterval */   25,             /* x10 mS XXX: units seem to be 1ms not 10! -- REW*/
-  /* timer */           10,             /* mS */
-  /* RtaLoadBase */     0x7000,
-  /* HostLoadBase */    0x7C00,
-  /* XpHz */            5,              /* number of Xprint hits per second */
-  /* XpCps */           120,            /* Xprint characters per second */
-  /* XpOn */            "\033d#",       /* start Xprint for a wyse 60 */
-  /* XpOff */           "\024",         /* end Xprint for a wyse 60 */
-  /* MaxXpCps */        2000,           /* highest Xprint speed */
-  /* MinXpCps */        10,             /* slowest Xprint speed */
-  /* SpinCmds */        1,              /* non-zero for mega fast boots */
-  /* First Addr */      0x0A0000,       /* First address to look at */
-  /* Last Addr */       0xFF0000,       /* Last address looked at */
-  /* BufferSize */      1024,           /* Bytes per port of buffering */
-  /* LowWater */        256,            /* how much data left before wakeup */
-  /* LineLength */      80,             /* how wide is the console? */
-  /* CmdTimeout */      HZ,             /* how long a close command may take */
+ RIOConf = {
+	/* locator */ "RIO Config here",
+					/* startuptime */ HZ * 2,
+					/* how long to wait for card to run */
+				/* slowcook */ 0,
+				/* TRUE -> always use line disc. */
+				/* intrpolltime */ 1,
+				/* The frequency of OUR polls */
+				/* breakinterval */ 25,
+				/* x10 mS XXX: units seem to be 1ms not 10! -- REW */
+				/* timer */ 10,
+				/* mS */
+	/* RtaLoadBase */ 0x7000,
+	/* HostLoadBase */ 0x7C00,
+				/* XpHz */ 5,
+				/* number of Xprint hits per second */
+				/* XpCps */ 120,
+				/* Xprint characters per second */
+				/* XpOn */ "\033d#",
+				/* start Xprint for a wyse 60 */
+				/* XpOff */ "\024",
+				/* end Xprint for a wyse 60 */
+				/* MaxXpCps */ 2000,
+				/* highest Xprint speed */
+				/* MinXpCps */ 10,
+				/* slowest Xprint speed */
+				/* SpinCmds */ 1,
+				/* non-zero for mega fast boots */
+					/* First Addr */ 0x0A0000,
+					/* First address to look at */
+					/* Last Addr */ 0xFF0000,
+					/* Last address looked at */
+				/* BufferSize */ 1024,
+				/* Bytes per port of buffering */
+				/* LowWater */ 256,
+				/* how much data left before wakeup */
+				/* LineLength */ 80,
+				/* how wide is the console? */
+				/* CmdTimeout */ HZ,
+				/* how long a close command may take */
 };
 
 
@@ -179,21 +192,20 @@
 
 /* Function prototypes */
 
-static void rio_disable_tx_interrupts (void * ptr); 
-static void rio_enable_tx_interrupts (void * ptr); 
-static void rio_disable_rx_interrupts (void * ptr); 
-static void rio_enable_rx_interrupts (void * ptr); 
-static int  rio_get_CD (void * ptr); 
-static void rio_shutdown_port (void * ptr);
-static int  rio_set_real_termios (void  *ptr);
-static void rio_hungup (void  *ptr);
-static void rio_close (void  *ptr);
-static int rio_chars_in_buffer (void * ptr);
-static int rio_fw_ioctl (struct inode *inode, struct file *filp,
-		         unsigned int cmd, unsigned long arg);
+static void rio_disable_tx_interrupts(void *ptr);
+static void rio_enable_tx_interrupts(void *ptr);
+static void rio_disable_rx_interrupts(void *ptr);
+static void rio_enable_rx_interrupts(void *ptr);
+static int rio_get_CD(void *ptr);
+static void rio_shutdown_port(void *ptr);
+static int rio_set_real_termios(void *ptr);
+static void rio_hungup(void *ptr);
+static void rio_close(void *ptr);
+static int rio_chars_in_buffer(void *ptr);
+static int rio_fw_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg);
 static int rio_init_drivers(void);
 
-static void my_hd (void *addr, int len);
+static void my_hd(void *addr, int len);
 
 static struct tty_driver *rio_driver, *rio_driver2;
 
@@ -213,9 +225,9 @@
 
 /* These are the only open spaces in my computer. Yours may have more
    or less.... */
-static int rio_probe_addrs[]= {0xc0000, 0xd0000, 0xe0000};
+static int rio_probe_addrs[] = { 0xc0000, 0xd0000, 0xe0000 };
 
-#define NR_RIO_ADDRS (sizeof(rio_probe_addrs)/sizeof (int))
+#define NR_RIO_ADDRS ARRAY_SIZE(rio_probe_addrs)
 
 
 /* Set the mask to all-ones. This alas, only supports 32 interrupts. 
@@ -231,17 +243,17 @@
 module_param(rio_irqmask, long, 0);
 
 static struct real_driver rio_real_driver = {
-  rio_disable_tx_interrupts,
-  rio_enable_tx_interrupts,
-  rio_disable_rx_interrupts,
-  rio_enable_rx_interrupts,
-  rio_get_CD,
-  rio_shutdown_port, 
-  rio_set_real_termios, 
-  rio_chars_in_buffer,
-  rio_close,
-  rio_hungup,
-  NULL
+	rio_disable_tx_interrupts,
+	rio_enable_tx_interrupts,
+	rio_disable_rx_interrupts,
+	rio_enable_rx_interrupts,
+	rio_get_CD,
+	rio_shutdown_port,
+	rio_set_real_termios,
+	rio_chars_in_buffer,
+	rio_close,
+	rio_hungup,
+	NULL
 };
 
 /* 
@@ -250,8 +262,8 @@
  */
 
 static struct file_operations rio_fw_fops = {
-	.owner		= THIS_MODULE,
-	.ioctl		= rio_fw_ioctl,
+	.owner = THIS_MODULE,
+	.ioctl = rio_fw_ioctl,
 };
 
 static struct miscdevice rio_fw_device = {
@@ -266,25 +278,22 @@
 
 /* This doesn't work. Who's paranoid around here? Not me! */
 
-static inline int rio_paranoia_check(struct rio_port const * port,
-				    char *name, const char *routine)
+static inline int rio_paranoia_check(struct rio_port const *port, char *name, const char *routine)
 {
 
-  static const char *badmagic =
-    KERN_ERR "rio: Warning: bad rio port magic number for device %s in %s\n";
-  static const char *badinfo =
-    KERN_ERR "rio: Warning: null rio port for device %s in %s\n";
- 
-  if (!port) {
-    printk (badinfo, name, routine);
-    return 1;
-  }
-  if (port->magic != RIO_MAGIC) {
-    printk (badmagic, name, routine);
-    return 1;
-  }
+	static const char *badmagic = KERN_ERR "rio: Warning: bad rio port magic number for device %s in %s\n";
+	static const char *badinfo = KERN_ERR "rio: Warning: null rio port for device %s in %s\n";
 
-  return 0;
+	if (!port) {
+		printk(badinfo, name, routine);
+		return 1;
+	}
+	if (port->magic != RIO_MAGIC) {
+		printk(badmagic, name, routine);
+		return 1;
+	}
+
+	return 0;
 }
 #else
 #define rio_paranoia_check(a,b,c) 0
@@ -292,53 +301,53 @@
 
 
 #ifdef DEBUG
-static void my_hd (void *ad, int len)
+static void my_hd(void *ad, int len)
 {
-  int i, j, ch;
-  unsigned char *addr = ad;
-  
-  for (i=0;i<len;i+=16) {
-    rio_dprintk (RIO_DEBUG_PARAM, "%08x ", (int) addr+i);
-    for (j=0;j<16;j++) {
-      rio_dprintk (RIO_DEBUG_PARAM, "%02x %s", addr[j+i], (j==7)?" ":"");
-    }
-    for (j=0;j<16;j++) {
-      ch = addr[j+i];
-      rio_dprintk (RIO_DEBUG_PARAM, "%c", (ch < 0x20)?'.':((ch > 0x7f)?'.':ch));
-    }
-    rio_dprintk (RIO_DEBUG_PARAM, "\n");
-  }
+	int i, j, ch;
+	unsigned char *addr = ad;
+
+	for (i = 0; i < len; i += 16) {
+		rio_dprintk(RIO_DEBUG_PARAM, "%08x ", (int) addr + i);
+		for (j = 0; j < 16; j++) {
+			rio_dprintk(RIO_DEBUG_PARAM, "%02x %s", addr[j + i], (j == 7) ? " " : "");
+		}
+		for (j = 0; j < 16; j++) {
+			ch = addr[j + i];
+			rio_dprintk(RIO_DEBUG_PARAM, "%c", (ch < 0x20) ? '.' : ((ch > 0x7f) ? '.' : ch));
+		}
+		rio_dprintk(RIO_DEBUG_PARAM, "\n");
+	}
 }
 #else
 #define my_hd(ad,len) do{/* nothing*/ } while (0)
 #endif
 
 
-/* Delay a number of jiffies, allowing a signal to interrupt */ 
-int RIODelay (struct Port *PortP, int njiffies)
+/* Delay a number of jiffies, allowing a signal to interrupt */
+int RIODelay(struct Port *PortP, int njiffies)
 {
-  func_enter ();
+	func_enter();
 
-  rio_dprintk (RIO_DEBUG_DELAY, "delaying %d jiffies\n", njiffies);  
-  msleep_interruptible(jiffies_to_msecs(njiffies));
-  func_exit();
+	rio_dprintk(RIO_DEBUG_DELAY, "delaying %d jiffies\n", njiffies);
+	msleep_interruptible(jiffies_to_msecs(njiffies));
+	func_exit();
 
-  if (signal_pending(current))
-    return RIO_FAIL;
-  else
-    return !RIO_FAIL;
+	if (signal_pending(current))
+		return RIO_FAIL;
+	else
+		return !RIO_FAIL;
 }
 
 
-/* Delay a number of jiffies, disallowing a signal to interrupt */ 
-int RIODelay_ni (struct Port *PortP, int njiffies)
+/* Delay a number of jiffies, disallowing a signal to interrupt */
+int RIODelay_ni(struct Port *PortP, int njiffies)
 {
-  func_enter ();
+	func_enter();
 
-  rio_dprintk (RIO_DEBUG_DELAY, "delaying %d jiffies (ni)\n", njiffies);  
-  msleep(jiffies_to_msecs(njiffies));
-  func_exit();
-  return !RIO_FAIL;
+	rio_dprintk(RIO_DEBUG_DELAY, "delaying %d jiffies (ni)\n", njiffies);
+	msleep(jiffies_to_msecs(njiffies));
+	func_exit();
+	return !RIO_FAIL;
 }
 
 
@@ -354,126 +363,121 @@
 }
 
 
-static int rio_set_real_termios (void *ptr)
+static int rio_set_real_termios(void *ptr)
 {
-  int rv, modem;
-  struct tty_struct *tty;
-  func_enter();
+	int rv, modem;
+	struct tty_struct *tty;
+	func_enter();
 
-  tty = ((struct Port *)ptr)->gs.tty;
+	tty = ((struct Port *) ptr)->gs.tty;
 
-  modem = rio_ismodem(tty);
+	modem = rio_ismodem(tty);
 
-  rv = RIOParam( (struct Port *) ptr, CONFIG, modem, 1);
+	rv = RIOParam((struct Port *) ptr, CONFIG, modem, 1);
 
-  func_exit ();
+	func_exit();
 
-  return rv;
+	return rv;
 }
 
 
-static void rio_reset_interrupt (struct Host *HostP)
+static void rio_reset_interrupt(struct Host *HostP)
 {
-  func_enter();
+	func_enter();
 
-  switch( HostP->Type ) {
-  case RIO_AT:
-  case RIO_MCA:
-  case RIO_PCI:
-    WBYTE(HostP->ResetInt , 0xff);
-  }
+	switch (HostP->Type) {
+	case RIO_AT:
+	case RIO_MCA:
+	case RIO_PCI:
+		WBYTE(HostP->ResetInt, 0xff);
+	}
 
-  func_exit();
+	func_exit();
 }
 
 
-static irqreturn_t rio_interrupt (int irq, void *ptr, struct pt_regs *regs)
+static irqreturn_t rio_interrupt(int irq, void *ptr, struct pt_regs *regs)
 {
-  struct Host *HostP;
-  func_enter ();
+	struct Host *HostP;
+	func_enter();
 
-  HostP = (struct Host*)ptr; /* &p->RIOHosts[(long)ptr]; */
-  rio_dprintk (RIO_DEBUG_IFLOW, "rio: enter rio_interrupt (%d/%d)\n", 
-               irq, HostP->Ivec); 
+	HostP = (struct Host *) ptr;	/* &p->RIOHosts[(long)ptr]; */
+	rio_dprintk(RIO_DEBUG_IFLOW, "rio: enter rio_interrupt (%d/%d)\n", irq, HostP->Ivec);
 
-  /* AAargh! The order in which to do these things is essential and
-     not trivial. 
-     
-     - Rate limit goes before "recursive". Otherwise a series of
-       recursive calls will hang the machine in the interrupt routine. 
+	/* AAargh! The order in which to do these things is essential and
+	   not trivial.
 
-     - hardware twiddling goes before "recursive". Otherwise when we
-       poll the card, and a recursive interrupt happens, we won't
-       ack the card, so it might keep on interrupting us. (especially
-       level sensitive interrupt systems like PCI).
+	   - Rate limit goes before "recursive". Otherwise a series of
+	   recursive calls will hang the machine in the interrupt routine.
 
-     - Rate limit goes before hardware twiddling. Otherwise we won't
-       catch a card that has gone bonkers.
+	   - hardware twiddling goes before "recursive". Otherwise when we
+	   poll the card, and a recursive interrupt happens, we won't
+	   ack the card, so it might keep on interrupting us. (especially
+	   level sensitive interrupt systems like PCI).
 
-     - The "initialized" test goes after the hardware twiddling. Otherwise
-       the card will stick us in the interrupt routine again.
+	   - Rate limit goes before hardware twiddling. Otherwise we won't
+	   catch a card that has gone bonkers.
 
-     - The initialized test goes before recursive. 
-  */
+	   - The "initialized" test goes after the hardware twiddling. Otherwise
+	   the card will stick us in the interrupt routine again.
+
+	   - The initialized test goes before recursive.
+	 */
 
 
 
 #ifdef IRQ_RATE_LIMIT
-  /* Aaargh! I'm ashamed. This costs more lines-of-code than the
-     actual interrupt routine!. (Well, used to when I wrote that comment) */
-  {
-    static int lastjif;
-    static int nintr=0;
+	/* Aaargh! I'm ashamed. This costs more lines-of-code than the
+	   actual interrupt routine!. (Well, used to when I wrote that comment) */
+	{
+		static int lastjif;
+		static int nintr = 0;
 
-    if (lastjif == jiffies) {
-      if (++nintr > IRQ_RATE_LIMIT) {
-        free_irq (HostP->Ivec, ptr);
-        printk (KERN_ERR "rio: Too many interrupts. Turning off interrupt %d.\n", 
-                HostP->Ivec);
-      }
-    } else {
-      lastjif = jiffies;
-      nintr = 0;
-    }
-  }
+		if (lastjif == jiffies) {
+			if (++nintr > IRQ_RATE_LIMIT) {
+				free_irq(HostP->Ivec, ptr);
+				printk(KERN_ERR "rio: Too many interrupts. Turning off interrupt %d.\n", HostP->Ivec);
+			}
+		} else {
+			lastjif = jiffies;
+			nintr = 0;
+		}
+	}
 #endif
-  rio_dprintk (RIO_DEBUG_IFLOW, "rio: We've have noticed the interrupt\n"); 
-  if (HostP->Ivec == irq) {
-    /* Tell the card we've noticed the interrupt. */
-    rio_reset_interrupt (HostP);
-  }
+	rio_dprintk(RIO_DEBUG_IFLOW, "rio: We've have noticed the interrupt\n");
+	if (HostP->Ivec == irq) {
+		/* Tell the card we've noticed the interrupt. */
+		rio_reset_interrupt(HostP);
+	}
 
-  if ((HostP->Flags & RUN_STATE) != RC_RUNNING)
-  	return IRQ_HANDLED;
+	if ((HostP->Flags & RUN_STATE) != RC_RUNNING)
+		return IRQ_HANDLED;
 
-  if (test_and_set_bit (RIO_BOARD_INTR_LOCK, &HostP->locks)) {
-    printk (KERN_ERR "Recursive interrupt! (host %d/irq%d)\n", 
-            (int) ptr, HostP->Ivec);
-    return IRQ_HANDLED;
-  }
+	if (test_and_set_bit(RIO_BOARD_INTR_LOCK, &HostP->locks)) {
+		printk(KERN_ERR "Recursive interrupt! (host %d/irq%d)\n", (int) ptr, HostP->Ivec);
+		return IRQ_HANDLED;
+	}
 
-  RIOServiceHost(p, HostP, irq);
+	RIOServiceHost(p, HostP, irq);
 
-  rio_dprintk ( RIO_DEBUG_IFLOW, "riointr() doing host %d type %d\n", 
-                (int) ptr, HostP->Type);
+	rio_dprintk(RIO_DEBUG_IFLOW, "riointr() doing host %d type %d\n", (int) ptr, HostP->Type);
 
-  clear_bit (RIO_BOARD_INTR_LOCK, &HostP->locks);
-  rio_dprintk (RIO_DEBUG_IFLOW, "rio: exit rio_interrupt (%d/%d)\n", 
-               irq, HostP->Ivec); 
-  func_exit ();
-  return IRQ_HANDLED;
+	clear_bit(RIO_BOARD_INTR_LOCK, &HostP->locks);
+	rio_dprintk(RIO_DEBUG_IFLOW, "rio: exit rio_interrupt (%d/%d)\n", irq, HostP->Ivec);
+	func_exit();
+	return IRQ_HANDLED;
 }
 
 
-static void rio_pollfunc (unsigned long data)
+static void rio_pollfunc(unsigned long data)
 {
-  func_enter ();
+	func_enter();
 
-  rio_interrupt (0, &p->RIOHosts[data], NULL);
-  p->RIOHosts[data].timer.expires = jiffies + rio_poll;
-  add_timer (&p->RIOHosts[data].timer);
+	rio_interrupt(0, &p->RIOHosts[data], NULL);
+	p->RIOHosts[data].timer.expires = jiffies + rio_poll;
+	add_timer(&p->RIOHosts[data].timer);
 
-  func_exit ();
+	func_exit();
 }
 
 
@@ -485,106 +489,106 @@
 /* Ehhm. I don't know how to fiddle with interrupts on the Specialix 
    cards. ....   Hmm. Ok I figured it out. You don't.  -- REW */
 
-static void rio_disable_tx_interrupts (void * ptr) 
+static void rio_disable_tx_interrupts(void *ptr)
 {
-  func_enter();
+	func_enter();
 
-  /*  port->gs.flags &= ~GS_TX_INTEN; */
+	/*  port->gs.flags &= ~GS_TX_INTEN; */
 
-  func_exit();
+	func_exit();
 }
 
 
-static void rio_enable_tx_interrupts (void * ptr) 
+static void rio_enable_tx_interrupts(void *ptr)
 {
-  struct Port *PortP = ptr;
-  /* int hn; */
+	struct Port *PortP = ptr;
+	/* int hn; */
 
-  func_enter();
+	func_enter();
 
-  /* hn = PortP->HostP - p->RIOHosts;
+	/* hn = PortP->HostP - p->RIOHosts;
 
-     rio_dprintk (RIO_DEBUG_TTY, "Pushing host %d\n", hn);
-     rio_interrupt (-1,(void *) hn, NULL); */
+	   rio_dprintk (RIO_DEBUG_TTY, "Pushing host %d\n", hn);
+	   rio_interrupt (-1,(void *) hn, NULL); */
 
-  RIOTxEnable((char *) PortP);
+	RIOTxEnable((char *) PortP);
 
-  /* 
-   * In general we cannot count on "tx empty" interrupts, although
-   * the interrupt routine seems to be able to tell the difference. 
-   */
-  PortP->gs.flags &= ~GS_TX_INTEN;
+	/*
+	 * In general we cannot count on "tx empty" interrupts, although
+	 * the interrupt routine seems to be able to tell the difference.
+	 */
+	PortP->gs.flags &= ~GS_TX_INTEN;
 
-  func_exit();
+	func_exit();
 }
 
 
-static void rio_disable_rx_interrupts (void * ptr) 
+static void rio_disable_rx_interrupts(void *ptr)
 {
-  func_enter();
-  func_exit();
+	func_enter();
+	func_exit();
 }
 
-static void rio_enable_rx_interrupts (void * ptr) 
+static void rio_enable_rx_interrupts(void *ptr)
 {
-  /*  struct rio_port *port = ptr; */
-  func_enter();
-  func_exit();
+	/*  struct rio_port *port = ptr; */
+	func_enter();
+	func_exit();
 }
 
 
 /* Jeez. Isn't this simple?  */
-static int rio_get_CD (void * ptr) 
+static int rio_get_CD(void *ptr)
 {
-  struct Port *PortP = ptr;
-  int rv;
+	struct Port *PortP = ptr;
+	int rv;
 
-  func_enter();
-  rv = (PortP->ModemState & MSVR1_CD) != 0;
+	func_enter();
+	rv = (PortP->ModemState & MSVR1_CD) != 0;
 
-  rio_dprintk (RIO_DEBUG_INIT, "Getting CD status: %d\n", rv);
-  
-  func_exit();  
-  return rv;
+	rio_dprintk(RIO_DEBUG_INIT, "Getting CD status: %d\n", rv);
+
+	func_exit();
+	return rv;
 }
 
 
 /* Jeez. Isn't this simple? Actually, we can sync with the actual port
    by just pushing stuff into the queue going to the port... */
-static int rio_chars_in_buffer (void * ptr) 
+static int rio_chars_in_buffer(void *ptr)
 {
-  func_enter();
+	func_enter();
 
-  func_exit();  
-  return 0;
+	func_exit();
+	return 0;
 }
 
 
 /* Nothing special here... */
-static void rio_shutdown_port (void * ptr) 
+static void rio_shutdown_port(void *ptr)
 {
-  struct Port *PortP;
+	struct Port *PortP;
 
-  func_enter();
+	func_enter();
 
-  PortP = (struct Port *)ptr;
-  PortP->gs.tty = NULL;
+	PortP = (struct Port *) ptr;
+	PortP->gs.tty = NULL;
 #if 0
-  port->gs.flags &= ~ GS_ACTIVE;
-  if (!port->gs.tty) {
-    rio_dprintk (RIO_DBUG_TTY, "No tty.\n");
-    return;
-  }
-  if (!port->gs.tty->termios) {
-    rio_dprintk (RIO_DEBUG_TTY, "No termios.\n");
-    return;
-  }
-  if (port->gs.tty->termios->c_cflag & HUPCL) {
-    rio_setsignals (port, 0, 0);
-  }
+	port->gs.flags &= ~GS_ACTIVE;
+	if (!port->gs.tty) {
+		rio_dprintk(RIO_DBUG_TTY, "No tty.\n");
+		return;
+	}
+	if (!port->gs.tty->termios) {
+		rio_dprintk(RIO_DEBUG_TTY, "No termios.\n");
+		return;
+	}
+	if (port->gs.tty->termios->c_cflag & HUPCL) {
+		rio_setsignals(port, 0, 0);
+	}
 #endif
 
-  func_exit();
+	func_exit();
 }
 
 
@@ -595,16 +599,16 @@
    running minicom on a serial port that is driven by a modularized
    driver. Have the modem hangup. Then remove the driver module. Then
    exit minicom.  I expect an "oops".  -- REW */
-static void rio_hungup (void *ptr)
+static void rio_hungup(void *ptr)
 {
-  struct Port *PortP;
+	struct Port *PortP;
 
-  func_enter();
-  
-  PortP = (struct Port *)ptr;
-  PortP->gs.tty = NULL;
+	func_enter();
 
-  func_exit ();
+	PortP = (struct Port *) ptr;
+	PortP->gs.tty = NULL;
+
+	func_exit();
 }
 
 
@@ -612,146 +616,135 @@
    this. 
    rs_close (...){save_flags;cli;real_close();dec_use_count;restore_flags;}
  */
-static void rio_close (void *ptr)
+static void rio_close(void *ptr)
 {
-  struct Port *PortP;
+	struct Port *PortP;
 
-  func_enter ();
+	func_enter();
 
-  PortP = (struct Port *)ptr;
+	PortP = (struct Port *) ptr;
 
-  riotclose (ptr);
+	riotclose(ptr);
 
-  if(PortP->gs.count) {
-    printk (KERN_ERR "WARNING port count:%d\n", PortP->gs.count);
-    PortP->gs.count = 0; 
-  }                
+	if (PortP->gs.count) {
+		printk(KERN_ERR "WARNING port count:%d\n", PortP->gs.count);
+		PortP->gs.count = 0;
+	}
 
-  PortP->gs.tty = NULL;
-  func_exit ();
+	PortP->gs.tty = NULL;
+	func_exit();
 }
 
 
 
-static int rio_fw_ioctl (struct inode *inode, struct file *filp,
-		         unsigned int cmd, unsigned long arg)
+static int rio_fw_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
 {
-  int rc = 0;
-  func_enter();
+	int rc = 0;
+	func_enter();
 
-  /* The "dev" argument isn't used. */
-  rc = riocontrol (p, 0, cmd, (void *)arg, capable(CAP_SYS_ADMIN));
+	/* The "dev" argument isn't used. */
+	rc = riocontrol(p, 0, cmd, (void *) arg, capable(CAP_SYS_ADMIN));
 
-  func_exit ();
-  return rc;
+	func_exit();
+	return rc;
 }
 
-extern int RIOShortCommand(struct rio_info *p, struct Port *PortP,
-               int command, int len, int arg);
+extern int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg);
 
-static int rio_ioctl (struct tty_struct * tty, struct file * filp, 
-                     unsigned int cmd, unsigned long arg)
+static int rio_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd, unsigned long arg)
 {
-  int rc;
-  struct Port *PortP;
-  int ival;
+	int rc;
+	struct Port *PortP;
+	int ival;
 
-  func_enter();
+	func_enter();
 
-  PortP = (struct Port *)tty->driver_data;
+	PortP = (struct Port *) tty->driver_data;
 
-  rc  = 0;
-  switch (cmd) {
+	rc = 0;
+	switch (cmd) {
 #if 0
-  case TIOCGSOFTCAR:
-    rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
-                  (unsigned int *) arg);
-    break;
+	case TIOCGSOFTCAR:
+		rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0), (unsigned int *) arg);
+		break;
 #endif
-  case TIOCSSOFTCAR:
-    if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
-      tty->termios->c_cflag =
-        (tty->termios->c_cflag & ~CLOCAL) |
-        (ival ? CLOCAL : 0);
-    }
-    break;
-  case TIOCGSERIAL:
-    rc = -EFAULT;
-    if (access_ok(VERIFY_WRITE, (void *) arg,
-                          sizeof(struct serial_struct)))
-      rc = gs_getserial(&PortP->gs, (struct serial_struct *) arg);
-    break;
-  case TCSBRK:
-    if ( PortP->State & RIO_DELETED ) {
-      rio_dprintk (RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
-      rc = -EIO;      
-    } else {
-      if (RIOShortCommand(p, PortP, SBREAK, 2, 250) == RIO_FAIL) {
-         rio_dprintk (RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
-         rc = -EIO;
-      }          
-    }
-    break;
-  case TCSBRKP:
-    if ( PortP->State & RIO_DELETED ) {
-      rio_dprintk (RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
-      rc = -EIO;      
-    } else {
-      int l;
-      l = arg?arg*100:250;
-      if (l > 255) l = 255;
-      if (RIOShortCommand(p, PortP, SBREAK, 2, arg?arg*100:250) == RIO_FAIL) {
-         rio_dprintk (RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
-         rc = -EIO;
-      }          
-    }
-    break;
-  case TIOCSSERIAL:
-    rc = -EFAULT;
-    if (access_ok(VERIFY_READ, (void *) arg,
-                          sizeof(struct serial_struct)))
-      rc = gs_setserial(&PortP->gs, (struct serial_struct *) arg);
-    break;
+	case TIOCSSOFTCAR:
+		if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
+			tty->termios->c_cflag = (tty->termios->c_cflag & ~CLOCAL) | (ival ? CLOCAL : 0);
+		}
+		break;
+	case TIOCGSERIAL:
+		rc = -EFAULT;
+		if (access_ok(VERIFY_WRITE, (void *) arg, sizeof(struct serial_struct)))
+			rc = gs_getserial(&PortP->gs, (struct serial_struct *) arg);
+		break;
+	case TCSBRK:
+		if (PortP->State & RIO_DELETED) {
+			rio_dprintk(RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
+			rc = -EIO;
+		} else {
+			if (RIOShortCommand(p, PortP, SBREAK, 2, 250) == RIO_FAIL) {
+				rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
+				rc = -EIO;
+			}
+		}
+		break;
+	case TCSBRKP:
+		if (PortP->State & RIO_DELETED) {
+			rio_dprintk(RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
+			rc = -EIO;
+		} else {
+			int l;
+			l = arg ? arg * 100 : 250;
+			if (l > 255)
+				l = 255;
+			if (RIOShortCommand(p, PortP, SBREAK, 2, arg ? arg * 100 : 250) == RIO_FAIL) {
+				rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
+				rc = -EIO;
+			}
+		}
+		break;
+	case TIOCSSERIAL:
+		rc = -EFAULT;
+		if (access_ok(VERIFY_READ, (void *) arg, sizeof(struct serial_struct)))
+			rc = gs_setserial(&PortP->gs, (struct serial_struct *) arg);
+		break;
 #if 0
-  /*
-   * note: these IOCTLs no longer reach here.  Use
-   * tiocmset/tiocmget driver methods instead.  The
-   * #if 0 disablement predates this comment.
-   */
-  case TIOCMGET:
-    rc = -EFAULT;
-    if (access_ok(VERIFY_WRITE, (void *) arg,
-                          sizeof(unsigned int))) {
-      rc = 0;
-      ival = rio_getsignals(port);
-      put_user(ival, (unsigned int *) arg);
-    }
-    break;
-  case TIOCMBIS:
-    if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
-      rio_setsignals(port, ((ival & TIOCM_DTR) ? 1 : -1),
-                           ((ival & TIOCM_RTS) ? 1 : -1));
-    }
-    break;
-  case TIOCMBIC:
-    if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
-      rio_setsignals(port, ((ival & TIOCM_DTR) ? 0 : -1),
-                           ((ival & TIOCM_RTS) ? 0 : -1));
-    }
-    break;
-  case TIOCMSET:
-    if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
-      rio_setsignals(port, ((ival & TIOCM_DTR) ? 1 : 0),
-                           ((ival & TIOCM_RTS) ? 1 : 0));
-    }
-    break;
+		/*
+		 * note: these IOCTLs no longer reach here.  Use
+		 * tiocmset/tiocmget driver methods instead.  The
+		 * #if 0 disablement predates this comment.
+		 */
+	case TIOCMGET:
+		rc = -EFAULT;
+		if (access_ok(VERIFY_WRITE, (void *) arg, sizeof(unsigned int))) {
+			rc = 0;
+			ival = rio_getsignals(port);
+			put_user(ival, (unsigned int *) arg);
+		}
+		break;
+	case TIOCMBIS:
+		if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
+			rio_setsignals(port, ((ival & TIOCM_DTR) ? 1 : -1), ((ival & TIOCM_RTS) ? 1 : -1));
+		}
+		break;
+	case TIOCMBIC:
+		if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
+			rio_setsignals(port, ((ival & TIOCM_DTR) ? 0 : -1), ((ival & TIOCM_RTS) ? 0 : -1));
+		}
+		break;
+	case TIOCMSET:
+		if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
+			rio_setsignals(port, ((ival & TIOCM_DTR) ? 1 : 0), ((ival & TIOCM_RTS) ? 1 : 0));
+		}
+		break;
 #endif
-  default:
-    rc = -ENOIOCTLCMD;
-    break;
-  }
-  func_exit();
-  return rc;
+	default:
+		rc = -ENOIOCTLCMD;
+		break;
+	}
+	func_exit();
+	return rc;
 }
 
 
@@ -771,37 +764,37 @@
  * flow control scheme is in use for that port. -- Simon Allen
  */
 
-static void rio_throttle (struct tty_struct * tty)
+static void rio_throttle(struct tty_struct *tty)
 {
-  struct Port *port = (struct Port *)tty->driver_data;
-  
-  func_enter();
-  /* If the port is using any type of input flow
-   * control then throttle the port.
-   */
+	struct Port *port = (struct Port *) tty->driver_data;
 
-  if((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty)) ) {
-    port->State |= RIO_THROTTLE_RX;
-  }
+	func_enter();
+	/* If the port is using any type of input flow
+	 * control then throttle the port.
+	 */
 
-  func_exit();
+	if ((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty))) {
+		port->State |= RIO_THROTTLE_RX;
+	}
+
+	func_exit();
 }
 
 
-static void rio_unthrottle (struct tty_struct * tty)
+static void rio_unthrottle(struct tty_struct *tty)
 {
-  struct Port *port = (struct Port *)tty->driver_data;
+	struct Port *port = (struct Port *) tty->driver_data;
 
-  func_enter();
-  /* Always unthrottle even if flow control is not enabled on
-   * this port in case we disabled flow control while the port
-   * was throttled
-   */
+	func_enter();
+	/* Always unthrottle even if flow control is not enabled on
+	 * this port in case we disabled flow control while the port
+	 * was throttled
+	 */
 
-  port->State &= ~RIO_THROTTLE_RX;
+	port->State &= ~RIO_THROTTLE_RX;
 
-  func_exit();
-  return;
+	func_exit();
+	return;
 }
 
 
@@ -813,35 +806,34 @@
  * ********************************************************************** */
 
 
-static struct vpd_prom *get_VPD_PROM (struct Host *hp)
+static struct vpd_prom *get_VPD_PROM(struct Host *hp)
 {
-  static struct vpd_prom vpdp;
-  char *p;
-  int i;
+	static struct vpd_prom vpdp;
+	char *p;
+	int i;
 
-  func_enter();
-  rio_dprintk (RIO_DEBUG_PROBE, "Going to verify vpd prom at %p.\n", 
-              hp->Caddr + RIO_VPD_ROM);
+	func_enter();
+	rio_dprintk(RIO_DEBUG_PROBE, "Going to verify vpd prom at %p.\n", hp->Caddr + RIO_VPD_ROM);
 
-  p = (char *) &vpdp;
-  for (i=0;i< sizeof (struct vpd_prom);i++)
-    *p++ = readb (hp->Caddr+RIO_VPD_ROM + i*2);
-      /* read_rio_byte (hp, RIO_VPD_ROM + i*2); */
+	p = (char *) &vpdp;
+	for (i = 0; i < sizeof(struct vpd_prom); i++)
+		*p++ = readb(hp->Caddr + RIO_VPD_ROM + i * 2);
+	/* read_rio_byte (hp, RIO_VPD_ROM + i*2); */
 
-  /* Terminate the identifier string. 
-     *** requires one extra byte in struct vpd_prom *** */
-  *p++=0; 
+	/* Terminate the identifier string.
+	 *** requires one extra byte in struct vpd_prom *** */
+	*p++ = 0;
 
-  if (rio_debug & RIO_DEBUG_PROBE)
-    my_hd ((char *)&vpdp, 0x20);
-  
-  func_exit();
+	if (rio_debug & RIO_DEBUG_PROBE)
+		my_hd((char *) &vpdp, 0x20);
 
-  return &vpdp;
+	func_exit();
+
+	return &vpdp;
 }
 
 static struct tty_operations rio_ops = {
-	.open  = riotopen,
+	.open = riotopen,
 	.close = gs_close,
 	.write = gs_write,
 	.put_char = gs_put_char,
@@ -893,7 +885,7 @@
 	rio_driver2->flags = TTY_DRIVER_REAL_RAW;
 	tty_set_operations(rio_driver2, &rio_ops);
 
-	rio_dprintk (RIO_DEBUG_INIT, "set_termios = %p\n", gs_set_termios);
+	rio_dprintk(RIO_DEBUG_INIT, "set_termios = %p\n", gs_set_termios);
 
 	if ((error = tty_register_driver(rio_driver)))
 		goto out2;
@@ -901,116 +893,111 @@
 		goto out3;
 	func_exit();
 	return 0;
-out3:
+      out3:
 	tty_unregister_driver(rio_driver);
-out2:
+      out2:
 	put_tty_driver(rio_driver2);
-out1:
+      out1:
 	put_tty_driver(rio_driver);
-out:
-	printk(KERN_ERR "rio: Couldn't register a rio driver, error = %d\n",
-	     error);
+      out:
+	printk(KERN_ERR "rio: Couldn't register a rio driver, error = %d\n", error);
 	return 1;
 }
 
 
-static void * ckmalloc (int size)
+static void *ckmalloc(int size)
 {
-  void *p;
+	void *p;
 
-  p = kmalloc(size, GFP_KERNEL);
-  if (p) 
-    memset(p, 0, size);
-  return p;
+	p = kmalloc(size, GFP_KERNEL);
+	if (p)
+		memset(p, 0, size);
+	return p;
 }
 
 
 
-static int rio_init_datastructures (void)
+static int rio_init_datastructures(void)
 {
-  int i;
-  struct Port *port;
-  func_enter();
+	int i;
+	struct Port *port;
+	func_enter();
 
-  /* Many drivers statically allocate the maximum number of ports
-     There is no reason not to allocate them dynamically. Is there? -- REW */
-  /* However, the RIO driver allows users to configure their first
-     RTA as the ports numbered 504-511. We therefore need to allocate 
-     the whole range. :-(   -- REW */
-  
+	/* Many drivers statically allocate the maximum number of ports
+	   There is no reason not to allocate them dynamically. Is there? -- REW */
+	/* However, the RIO driver allows users to configure their first
+	   RTA as the ports numbered 504-511. We therefore need to allocate
+	   the whole range. :-(   -- REW */
+
 #define RI_SZ   sizeof(struct rio_info)
 #define HOST_SZ sizeof(struct Host)
 #define PORT_SZ sizeof(struct Port *)
 #define TMIO_SZ sizeof(struct termios *)
-  rio_dprintk (RIO_DEBUG_INIT, "getting : %d %d %d %d %d bytes\n", 
-               RI_SZ, 
-               RIO_HOSTS * HOST_SZ,
-               RIO_PORTS * PORT_SZ,
-               RIO_PORTS * TMIO_SZ,
-               RIO_PORTS * TMIO_SZ);
-  
-  if (!(p                  = ckmalloc (              RI_SZ))) goto free0;
-  if (!(p->RIOHosts        = ckmalloc (RIO_HOSTS * HOST_SZ))) goto free1;
-  if (!(p->RIOPortp        = ckmalloc (RIO_PORTS * PORT_SZ))) goto free2;
-  p->RIOConf = RIOConf;
-  rio_dprintk (RIO_DEBUG_INIT, "Got : %p %p %p\n", 
-               p, p->RIOHosts, p->RIOPortp);
+	rio_dprintk(RIO_DEBUG_INIT, "getting : %d %d %d %d %d bytes\n", RI_SZ, RIO_HOSTS * HOST_SZ, RIO_PORTS * PORT_SZ, RIO_PORTS * TMIO_SZ, RIO_PORTS * TMIO_SZ);
+
+	if (!(p = ckmalloc(RI_SZ)))
+		goto free0;
+	if (!(p->RIOHosts = ckmalloc(RIO_HOSTS * HOST_SZ)))
+		goto free1;
+	if (!(p->RIOPortp = ckmalloc(RIO_PORTS * PORT_SZ)))
+		goto free2;
+	p->RIOConf = RIOConf;
+	rio_dprintk(RIO_DEBUG_INIT, "Got : %p %p %p\n", p, p->RIOHosts, p->RIOPortp);
 
 #if 1
-  for (i = 0; i < RIO_PORTS; i++) {
-    port = p->RIOPortp[i] = ckmalloc (sizeof (struct Port));
-    if (!port) {
-      goto free6;
-    }
-    rio_dprintk (RIO_DEBUG_INIT, "initing port %d (%d)\n", i, port->Mapped);
-    port->PortNum = i;
-    port->gs.magic = RIO_MAGIC;
-    port->gs.close_delay = HZ/2;
-    port->gs.closing_wait = 30 * HZ;
-    port->gs.rd = &rio_real_driver;
-    spin_lock_init(&port->portSem);
-    /*
-     * Initializing wait queue
-     */
-    init_waitqueue_head(&port->gs.open_wait);
-    init_waitqueue_head(&port->gs.close_wait);
-  }
+	for (i = 0; i < RIO_PORTS; i++) {
+		port = p->RIOPortp[i] = ckmalloc(sizeof(struct Port));
+		if (!port) {
+			goto free6;
+		}
+		rio_dprintk(RIO_DEBUG_INIT, "initing port %d (%d)\n", i, port->Mapped);
+		port->PortNum = i;
+		port->gs.magic = RIO_MAGIC;
+		port->gs.close_delay = HZ / 2;
+		port->gs.closing_wait = 30 * HZ;
+		port->gs.rd = &rio_real_driver;
+		spin_lock_init(&port->portSem);
+		/*
+		 * Initializing wait queue
+		 */
+		init_waitqueue_head(&port->gs.open_wait);
+		init_waitqueue_head(&port->gs.close_wait);
+	}
 #else
-  /* We could postpone initializing them to when they are configured. */
+	/* We could postpone initializing them to when they are configured. */
 #endif
 
 
-  
-  if (rio_debug & RIO_DEBUG_INIT) {
-    my_hd (&rio_real_driver, sizeof (rio_real_driver));
-  }
 
-  
-  func_exit();
-  return 0;
+	if (rio_debug & RIO_DEBUG_INIT) {
+		my_hd(&rio_real_driver, sizeof(rio_real_driver));
+	}
 
- free6:for (i--;i>=0;i--)
-        kfree (p->RIOPortp[i]);
+
+	func_exit();
+	return 0;
+
+      free6:for (i--; i >= 0; i--)
+		kfree(p->RIOPortp[i]);
 /*free5:
  free4:
- free3:*/kfree (p->RIOPortp);
- free2:kfree (p->RIOHosts);
- free1:
-  rio_dprintk (RIO_DEBUG_INIT, "Not enough memory! %p %p %p\n", 
-        	       p, p->RIOHosts, p->RIOPortp);
-  kfree(p);        	      
- free0:
-  return -ENOMEM;
+ free3:*/ kfree(p->RIOPortp);
+      free2:kfree(p->RIOHosts);
+      free1:
+	rio_dprintk(RIO_DEBUG_INIT, "Not enough memory! %p %p %p\n", p, p->RIOHosts, p->RIOPortp);
+	kfree(p);
+      free0:
+	return -ENOMEM;
 }
 
-static void  __exit rio_release_drivers(void)
+static void __exit rio_release_drivers(void)
 {
-  func_enter();
-  tty_unregister_driver(rio_driver2);
-  tty_unregister_driver(rio_driver);
-  put_tty_driver(rio_driver2);
-  put_tty_driver(rio_driver);
-  func_exit();
+	func_enter();
+	tty_unregister_driver(rio_driver2);
+	tty_unregister_driver(rio_driver);
+	put_tty_driver(rio_driver2);
+	put_tty_driver(rio_driver);
+	func_exit();
 }
 
 
@@ -1021,7 +1008,7 @@
     There is another bit besides Bit 17. Turning that bit off
     (on boards shipped with the fix in the eeprom) results in a 
     hang on the next access to the card. 
- */
+  */
 
  /******************************************************** 
  * Setting bit 17 in the CNTRL register of the PLX 9050  * 
@@ -1034,319 +1021,293 @@
    EEprom.  As the bit is read/write for the CPU, we can fix it here,
    if we detect that it isn't set correctly. -- REW */
 
-static void fix_rio_pci (struct pci_dev *pdev)
+static void fix_rio_pci(struct pci_dev *pdev)
 {
-  unsigned int hwbase;
-  unsigned long rebase;
-  unsigned int t;
+	unsigned int hwbase;
+	unsigned long rebase;
+	unsigned int t;
 
 #define CNTRL_REG_OFFSET        0x50
 #define CNTRL_REG_GOODVALUE     0x18260000
 
-  pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &hwbase);
-  hwbase &= PCI_BASE_ADDRESS_MEM_MASK;
-  rebase =  (ulong) ioremap(hwbase, 0x80);
-  t = readl (rebase + CNTRL_REG_OFFSET);
-  if (t != CNTRL_REG_GOODVALUE) {
-    printk (KERN_DEBUG "rio: performing cntrl reg fix: %08x -> %08x\n", 
-            t, CNTRL_REG_GOODVALUE); 
-    writel (CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET);  
-  }
-  iounmap((char*) rebase);
+	pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &hwbase);
+	hwbase &= PCI_BASE_ADDRESS_MEM_MASK;
+	rebase = (ulong) ioremap(hwbase, 0x80);
+	t = readl(rebase + CNTRL_REG_OFFSET);
+	if (t != CNTRL_REG_GOODVALUE) {
+		printk(KERN_DEBUG "rio: performing cntrl reg fix: %08x -> %08x\n", t, CNTRL_REG_GOODVALUE);
+		writel(CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET);
+	}
+	iounmap((char *) rebase);
 }
 #endif
 
 
-static int __init rio_init(void) 
+static int __init rio_init(void)
 {
-  int found = 0;
-  int i;
-  struct Host *hp;
-  int retval;
-  struct vpd_prom *vpdp;
-  int okboard;
+	int found = 0;
+	int i;
+	struct Host *hp;
+	int retval;
+	struct vpd_prom *vpdp;
+	int okboard;
 
 #ifdef CONFIG_PCI
-  struct pci_dev *pdev = NULL;
-  unsigned int tint;
-  unsigned short tshort;
+	struct pci_dev *pdev = NULL;
+	unsigned int tint;
+	unsigned short tshort;
 #endif
 
-  func_enter();
-  rio_dprintk (RIO_DEBUG_INIT, "Initing rio module... (rio_debug=%d)\n", 
-	       rio_debug);
+	func_enter();
+	rio_dprintk(RIO_DEBUG_INIT, "Initing rio module... (rio_debug=%d)\n", rio_debug);
 
-  if (abs ((long) (&rio_debug) - rio_debug) < 0x10000) {
-    printk (KERN_WARNING "rio: rio_debug is an address, instead of a value. "
-            "Assuming -1. Was %x/%p.\n", rio_debug, &rio_debug);
-    rio_debug=-1;
-  }
+	if (abs((long) (&rio_debug) - rio_debug) < 0x10000) {
+		printk(KERN_WARNING "rio: rio_debug is an address, instead of a value. " "Assuming -1. Was %x/%p.\n", rio_debug, &rio_debug);
+		rio_debug = -1;
+	}
 
-  if (misc_register(&rio_fw_device) < 0) {
-    printk(KERN_ERR "RIO: Unable to register firmware loader driver.\n");
-    return -EIO;
-  }
+	if (misc_register(&rio_fw_device) < 0) {
+		printk(KERN_ERR "RIO: Unable to register firmware loader driver.\n");
+		return -EIO;
+	}
 
-  retval = rio_init_datastructures ();
-  if (retval < 0) {
-    misc_deregister(&rio_fw_device);
-    return retval;
-  }
-
+	retval = rio_init_datastructures();
+	if (retval < 0) {
+		misc_deregister(&rio_fw_device);
+		return retval;
+	}
 #ifdef CONFIG_PCI
-    /* First look for the JET devices: */
-    while ((pdev = pci_get_device (PCI_VENDOR_ID_SPECIALIX,
-                                    PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, 
-                                    pdev))) {
-       if (pci_enable_device(pdev)) continue;
+	/* First look for the JET devices: */
+	while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, pdev))) {
+		if (pci_enable_device(pdev))
+			continue;
 
-      /* Specialix has a whole bunch of cards with
-         0x2000 as the device ID. They say its because
-         the standard requires it. Stupid standard. */
-      /* It seems that reading a word doesn't work reliably on 2.0.
-         Also, reading a non-aligned dword doesn't work. So we read the
-         whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID)
-         ourselves */
-      /* I don't know why the define doesn't work, constant 0x2c does --REW */ 
-      pci_read_config_dword (pdev, 0x2c, &tint);
-      tshort = (tint >> 16) & 0xffff;
-      rio_dprintk (RIO_DEBUG_PROBE, "Got a specialix card: %x.\n", tint);
-      if (tshort != 0x0100) {
-        rio_dprintk (RIO_DEBUG_PROBE, "But it's not a RIO card (%d)...\n", 
-                    tshort);
-        continue;
-      }
-      rio_dprintk (RIO_DEBUG_PROBE, "cp1\n");
+		/* Specialix has a whole bunch of cards with
+		   0x2000 as the device ID. They say its because
+		   the standard requires it. Stupid standard. */
+		/* It seems that reading a word doesn't work reliably on 2.0.
+		   Also, reading a non-aligned dword doesn't work. So we read the
+		   whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID)
+		   ourselves */
+		/* I don't know why the define doesn't work, constant 0x2c does --REW */
+		pci_read_config_dword(pdev, 0x2c, &tint);
+		tshort = (tint >> 16) & 0xffff;
+		rio_dprintk(RIO_DEBUG_PROBE, "Got a specialix card: %x.\n", tint);
+		if (tshort != 0x0100) {
+			rio_dprintk(RIO_DEBUG_PROBE, "But it's not a RIO card (%d)...\n", tshort);
+			continue;
+		}
+		rio_dprintk(RIO_DEBUG_PROBE, "cp1\n");
 
-      pci_read_config_dword(pdev, PCI_BASE_ADDRESS_2, &tint);
+		pci_read_config_dword(pdev, PCI_BASE_ADDRESS_2, &tint);
 
-      hp = &p->RIOHosts[p->RIONumHosts];
-      hp->PaddrP =  tint & PCI_BASE_ADDRESS_MEM_MASK;
-      hp->Ivec = pdev->irq;
-      if (((1 << hp->Ivec) & rio_irqmask) == 0)
-              hp->Ivec = 0;
-      hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
-      hp->CardP	= (struct DpRam *) hp->Caddr;
-      hp->Type  = RIO_PCI;
-      hp->Copy  = rio_pcicopy; 
-      hp->Mode  = RIO_PCI_BOOT_FROM_RAM;
-      spin_lock_init(&hp->HostLock);
-      rio_reset_interrupt (hp);
-      rio_start_card_running (hp);
+		hp = &p->RIOHosts[p->RIONumHosts];
+		hp->PaddrP = tint & PCI_BASE_ADDRESS_MEM_MASK;
+		hp->Ivec = pdev->irq;
+		if (((1 << hp->Ivec) & rio_irqmask) == 0)
+			hp->Ivec = 0;
+		hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
+		hp->CardP = (struct DpRam *) hp->Caddr;
+		hp->Type = RIO_PCI;
+		hp->Copy = rio_pcicopy;
+		hp->Mode = RIO_PCI_BOOT_FROM_RAM;
+		spin_lock_init(&hp->HostLock);
+		rio_reset_interrupt(hp);
+		rio_start_card_running(hp);
 
-      rio_dprintk (RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n",
-                   (void *)p->RIOHosts[p->RIONumHosts].PaddrP,
-                   p->RIOHosts[p->RIONumHosts].Caddr);
-      if (RIOBoardTest( p->RIOHosts[p->RIONumHosts].PaddrP,
-                        p->RIOHosts[p->RIONumHosts].Caddr, 
-                        RIO_PCI, 0 ) == RIO_SUCCESS) {
-              rio_dprintk (RIO_DEBUG_INIT, "Done RIOBoardTest\n");
-              WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff);
-              p->RIOHosts[p->RIONumHosts].UniqueNum  =
-                      ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0]) &0xFF)<< 0)|
-                      ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1]) &0xFF)<< 8)|
-                      ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2]) &0xFF)<<16)|
-                      ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3]) &0xFF)<<24);
-              rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n",
-                           p->RIOHosts[p->RIONumHosts].UniqueNum);
-              
-              fix_rio_pci (pdev);
-              p->RIOLastPCISearch = RIO_SUCCESS;
-              p->RIONumHosts++;
-              found++;
-      } else {
-              iounmap((char*) (p->RIOHosts[p->RIONumHosts].Caddr));
-      }
-    }
-    
-    /* Then look for the older PCI card.... : */
+		rio_dprintk(RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", (void *) p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr);
+		if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == RIO_SUCCESS) {
+			rio_dprintk(RIO_DEBUG_INIT, "Done RIOBoardTest\n");
+			WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff);
+			p->RIOHosts[p->RIONumHosts].UniqueNum =
+			    ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) |
+			    ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1]) & 0xFF) << 8) | ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2]) & 0xFF) << 16) | ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3]) & 0xFF) << 24);
+			rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
 
-  /* These older PCI cards have problems (only byte-mode access is
-     supported), which makes them a bit awkward to support. 
-     They also have problems sharing interrupts. Be careful. 
-     (The driver now refuses to share interrupts for these
-     cards. This should be sufficient).
-  */
+			fix_rio_pci(pdev);
+			p->RIOLastPCISearch = RIO_SUCCESS;
+			p->RIONumHosts++;
+			found++;
+		} else {
+			iounmap((char *) (p->RIOHosts[p->RIONumHosts].Caddr));
+		}
+	}
 
-    /* Then look for the older RIO/PCI devices: */
-    while ((pdev = pci_get_device (PCI_VENDOR_ID_SPECIALIX,
-                                    PCI_DEVICE_ID_SPECIALIX_RIO, 
-                                    pdev))) {
-       if (pci_enable_device(pdev)) continue;
+	/* Then look for the older PCI card.... : */
+
+	/* These older PCI cards have problems (only byte-mode access is
+	   supported), which makes them a bit awkward to support.
+	   They also have problems sharing interrupts. Be careful.
+	   (The driver now refuses to share interrupts for these
+	   cards. This should be sufficient).
+	 */
+
+	/* Then look for the older RIO/PCI devices: */
+	while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_RIO, pdev))) {
+		if (pci_enable_device(pdev))
+			continue;
 
 #ifdef CONFIG_RIO_OLDPCI
-      pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &tint);
+		pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &tint);
 
-      hp = &p->RIOHosts[p->RIONumHosts];
-      hp->PaddrP =  tint & PCI_BASE_ADDRESS_MEM_MASK;
-      hp->Ivec = pdev->irq;
-      if (((1 << hp->Ivec) & rio_irqmask) == 0) 
-      	hp->Ivec = 0;
-      hp->Ivec |= 0x8000; /* Mark as non-sharable */
-      hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
-      hp->CardP	= (struct DpRam *) hp->Caddr;
-      hp->Type  = RIO_PCI;
-      hp->Copy  = rio_pcicopy;
-      hp->Mode  = RIO_PCI_BOOT_FROM_RAM;
-      spin_lock_init(&hp->HostLock);
+		hp = &p->RIOHosts[p->RIONumHosts];
+		hp->PaddrP = tint & PCI_BASE_ADDRESS_MEM_MASK;
+		hp->Ivec = pdev->irq;
+		if (((1 << hp->Ivec) & rio_irqmask) == 0)
+			hp->Ivec = 0;
+		hp->Ivec |= 0x8000;	/* Mark as non-sharable */
+		hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
+		hp->CardP = (struct DpRam *) hp->Caddr;
+		hp->Type = RIO_PCI;
+		hp->Copy = rio_pcicopy;
+		hp->Mode = RIO_PCI_BOOT_FROM_RAM;
+		spin_lock_init(&hp->HostLock);
 
-      rio_dprintk (RIO_DEBUG_PROBE, "Ivec: %x\n", hp->Ivec);
-      rio_dprintk (RIO_DEBUG_PROBE, "Mode: %x\n", hp->Mode);
+		rio_dprintk(RIO_DEBUG_PROBE, "Ivec: %x\n", hp->Ivec);
+		rio_dprintk(RIO_DEBUG_PROBE, "Mode: %x\n", hp->Mode);
 
-      rio_reset_interrupt (hp);
-      rio_start_card_running (hp);
-       rio_dprintk (RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n",
-                   (void *)p->RIOHosts[p->RIONumHosts].PaddrP,
-                   p->RIOHosts[p->RIONumHosts].Caddr);
-      if (RIOBoardTest( p->RIOHosts[p->RIONumHosts].PaddrP,
-                        p->RIOHosts[p->RIONumHosts].Caddr, 
-                        RIO_PCI, 0 ) == RIO_SUCCESS) {
-        WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff);
-        p->RIOHosts[p->RIONumHosts].UniqueNum  =
-          ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0]) &0xFF)<< 0)|
-          ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1]) &0xFF)<< 8)|
-          ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2]) &0xFF)<<16)|
-          ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3]) &0xFF)<<24);
-        rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n",
-                   p->RIOHosts[p->RIONumHosts].UniqueNum);
+		rio_reset_interrupt(hp);
+		rio_start_card_running(hp);
+		rio_dprintk(RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", (void *) p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr);
+		if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == RIO_SUCCESS) {
+			WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff);
+			p->RIOHosts[p->RIONumHosts].UniqueNum =
+			    ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) |
+			    ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1]) & 0xFF) << 8) | ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2]) & 0xFF) << 16) | ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3]) & 0xFF) << 24);
+			rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
 
-        p->RIOLastPCISearch = RIO_SUCCESS;
-        p->RIONumHosts++;
-        found++;
-      } else {
-        iounmap((char*) (p->RIOHosts[p->RIONumHosts].Caddr));
-      }
+			p->RIOLastPCISearch = RIO_SUCCESS;
+			p->RIONumHosts++;
+			found++;
+		} else {
+			iounmap((char *) (p->RIOHosts[p->RIONumHosts].Caddr));
+		}
 #else
-      printk (KERN_ERR "Found an older RIO PCI card, but the driver is not "
-              "compiled to support it.\n");
+		printk(KERN_ERR "Found an older RIO PCI card, but the driver is not " "compiled to support it.\n");
 #endif
-    }
-#endif /* PCI */
+	}
+#endif				/* PCI */
 
-  /* Now probe for ISA cards... */
-  for (i=0;i<NR_RIO_ADDRS;i++) {
-    hp = &p->RIOHosts[p->RIONumHosts];
-    hp->PaddrP = rio_probe_addrs[i];
-    /* There was something about the IRQs of these cards. 'Forget what.--REW */
-    hp->Ivec = 0;
-    hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
-    hp->CardP = (struct DpRam *) hp->Caddr;
-    hp->Type = RIO_AT;
-    hp->Copy = rio_pcicopy; /* AT card PCI???? - PVDL
-                             * -- YES! this is now a normal copy. Only the 
-                             * old PCI card uses the special PCI copy. 
-                             * Moreover, the ISA card will work with the 
-                             * special PCI copy anyway. -- REW */
-    hp->Mode = 0;
-    spin_lock_init(&hp->HostLock);
+	/* Now probe for ISA cards... */
+	for (i = 0; i < NR_RIO_ADDRS; i++) {
+		hp = &p->RIOHosts[p->RIONumHosts];
+		hp->PaddrP = rio_probe_addrs[i];
+		/* There was something about the IRQs of these cards. 'Forget what.--REW */
+		hp->Ivec = 0;
+		hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
+		hp->CardP = (struct DpRam *) hp->Caddr;
+		hp->Type = RIO_AT;
+		hp->Copy = rio_pcicopy;	/* AT card PCI???? - PVDL
+					 * -- YES! this is now a normal copy. Only the
+					 * old PCI card uses the special PCI copy.
+					 * Moreover, the ISA card will work with the
+					 * special PCI copy anyway. -- REW */
+		hp->Mode = 0;
+		spin_lock_init(&hp->HostLock);
 
-    vpdp = get_VPD_PROM (hp);
-    rio_dprintk (RIO_DEBUG_PROBE, "Got VPD ROM\n");
-    okboard = 0;
-    if ((strncmp (vpdp->identifier, RIO_ISA_IDENT, 16) == 0) ||
-        (strncmp (vpdp->identifier, RIO_ISA2_IDENT, 16) == 0) ||
-        (strncmp (vpdp->identifier, RIO_ISA3_IDENT, 16) == 0)) {
-      /* Board is present... */
-      if (RIOBoardTest (hp->PaddrP, 
-                        hp->Caddr, RIO_AT, 0) == RIO_SUCCESS) {
-        /* ... and feeling fine!!!! */
-        rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n",
-                   p->RIOHosts[p->RIONumHosts].UniqueNum);
-        if (RIOAssignAT(p, hp->PaddrP, hp->Caddr, 0)) {        
-          rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, host%d uniqid = %x.\n",
-                       p->RIONumHosts, 
-                       p->RIOHosts[p->RIONumHosts-1].UniqueNum);
-          okboard++;
-          found++;
-        }
-      }
+		vpdp = get_VPD_PROM(hp);
+		rio_dprintk(RIO_DEBUG_PROBE, "Got VPD ROM\n");
+		okboard = 0;
+		if ((strncmp(vpdp->identifier, RIO_ISA_IDENT, 16) == 0) || (strncmp(vpdp->identifier, RIO_ISA2_IDENT, 16) == 0) || (strncmp(vpdp->identifier, RIO_ISA3_IDENT, 16) == 0)) {
+			/* Board is present... */
+			if (RIOBoardTest(hp->PaddrP, hp->Caddr, RIO_AT, 0) == RIO_SUCCESS) {
+				/* ... and feeling fine!!!! */
+				rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
+				if (RIOAssignAT(p, hp->PaddrP, hp->Caddr, 0)) {
+					rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, host%d uniqid = %x.\n", p->RIONumHosts, p->RIOHosts[p->RIONumHosts - 1].UniqueNum);
+					okboard++;
+					found++;
+				}
+			}
 
-    if (!okboard)
-      iounmap ((char*) (hp->Caddr));
-    }
-  }
+			if (!okboard)
+				iounmap((char *) (hp->Caddr));
+		}
+	}
 
 
-  for (i=0;i<p->RIONumHosts;i++) {
-    hp = &p->RIOHosts[i];
-    if (hp->Ivec) {
-      int mode = SA_SHIRQ;
-      if (hp->Ivec & 0x8000) {mode = 0; hp->Ivec &= 0x7fff;}
-      rio_dprintk (RIO_DEBUG_INIT, "Requesting interrupt hp: %p rio_interrupt: %d Mode: %x\n", hp,hp->Ivec, hp->Mode);
-      retval = request_irq (hp->Ivec, rio_interrupt, mode, "rio", hp);
-      rio_dprintk (RIO_DEBUG_INIT, "Return value from request_irq: %d\n", retval);
-      if (retval) {
-              printk(KERN_ERR "rio: Cannot allocate irq %d.\n", hp->Ivec);
-              hp->Ivec = 0;
-      }
-      rio_dprintk (RIO_DEBUG_INIT, "Got irq %d.\n", hp->Ivec);
-      if (hp->Ivec != 0){
-              rio_dprintk (RIO_DEBUG_INIT, "Enabling interrupts on rio card.\n"); 
-              hp->Mode |= RIO_PCI_INT_ENABLE;
-      } else
-              hp->Mode &= !RIO_PCI_INT_ENABLE;
-      rio_dprintk (RIO_DEBUG_INIT, "New Mode: %x\n", hp->Mode);
-      rio_start_card_running (hp);
-    }
-    /* Init the timer "always" to make sure that it can safely be 
-       deleted when we unload... */
+	for (i = 0; i < p->RIONumHosts; i++) {
+		hp = &p->RIOHosts[i];
+		if (hp->Ivec) {
+			int mode = SA_SHIRQ;
+			if (hp->Ivec & 0x8000) {
+				mode = 0;
+				hp->Ivec &= 0x7fff;
+			}
+			rio_dprintk(RIO_DEBUG_INIT, "Requesting interrupt hp: %p rio_interrupt: %d Mode: %x\n", hp, hp->Ivec, hp->Mode);
+			retval = request_irq(hp->Ivec, rio_interrupt, mode, "rio", hp);
+			rio_dprintk(RIO_DEBUG_INIT, "Return value from request_irq: %d\n", retval);
+			if (retval) {
+				printk(KERN_ERR "rio: Cannot allocate irq %d.\n", hp->Ivec);
+				hp->Ivec = 0;
+			}
+			rio_dprintk(RIO_DEBUG_INIT, "Got irq %d.\n", hp->Ivec);
+			if (hp->Ivec != 0) {
+				rio_dprintk(RIO_DEBUG_INIT, "Enabling interrupts on rio card.\n");
+				hp->Mode |= RIO_PCI_INT_ENABLE;
+			} else
+				hp->Mode &= !RIO_PCI_INT_ENABLE;
+			rio_dprintk(RIO_DEBUG_INIT, "New Mode: %x\n", hp->Mode);
+			rio_start_card_running(hp);
+		}
+		/* Init the timer "always" to make sure that it can safely be
+		   deleted when we unload... */
 
-    init_timer (&hp->timer);
-    if (!hp->Ivec) {
-      rio_dprintk (RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n", 
-                   rio_poll);
-      hp->timer.data = i;
-      hp->timer.function = rio_pollfunc;
-      hp->timer.expires = jiffies + rio_poll;
-      add_timer (&hp->timer);
-    }
-  }
+		init_timer(&hp->timer);
+		if (!hp->Ivec) {
+			rio_dprintk(RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n", rio_poll);
+			hp->timer.data = i;
+			hp->timer.function = rio_pollfunc;
+			hp->timer.expires = jiffies + rio_poll;
+			add_timer(&hp->timer);
+		}
+	}
 
-  if (found) {
-    rio_dprintk (RIO_DEBUG_INIT, "rio: total of %d boards detected.\n", found);
-    rio_init_drivers ();
-  } else {
-    /* deregister the misc device we created earlier */
-    misc_deregister(&rio_fw_device);
-  }
+	if (found) {
+		rio_dprintk(RIO_DEBUG_INIT, "rio: total of %d boards detected.\n", found);
+		rio_init_drivers();
+	} else {
+		/* deregister the misc device we created earlier */
+		misc_deregister(&rio_fw_device);
+	}
 
-  func_exit();
-  return found?0:-EIO;
+	func_exit();
+	return found ? 0 : -EIO;
 }
 
 
-static void __exit rio_exit (void)
+static void __exit rio_exit(void)
 {
-  int i; 
-  struct Host *hp;
-  
-  func_enter();
+	int i;
+	struct Host *hp;
 
-  for (i=0,hp=p->RIOHosts;i<p->RIONumHosts;i++, hp++) {
-    RIOHostReset (hp->Type, hp->CardP, hp->Slot);
-    if (hp->Ivec) {
-      free_irq (hp->Ivec, hp);
-      rio_dprintk (RIO_DEBUG_INIT, "freed irq %d.\n", hp->Ivec);
-    }
-    /* It is safe/allowed to del_timer a non-active timer */
-    del_timer (&hp->timer);
-  }
+	func_enter();
 
-  if (misc_deregister(&rio_fw_device) < 0) {
-    printk (KERN_INFO "rio: couldn't deregister control-device\n");
-  }
+	for (i = 0, hp = p->RIOHosts; i < p->RIONumHosts; i++, hp++) {
+		RIOHostReset(hp->Type, hp->CardP, hp->Slot);
+		if (hp->Ivec) {
+			free_irq(hp->Ivec, hp);
+			rio_dprintk(RIO_DEBUG_INIT, "freed irq %d.\n", hp->Ivec);
+		}
+		/* It is safe/allowed to del_timer a non-active timer */
+		del_timer(&hp->timer);
+	}
+
+	if (misc_deregister(&rio_fw_device) < 0) {
+		printk(KERN_INFO "rio: couldn't deregister control-device\n");
+	}
 
 
-  rio_dprintk (RIO_DEBUG_CLEANUP, "Cleaning up drivers\n");
+	rio_dprintk(RIO_DEBUG_CLEANUP, "Cleaning up drivers\n");
 
-  rio_release_drivers ();
+	rio_release_drivers();
 
-  /* Release dynamically allocated memory */
-  kfree (p->RIOPortp);
-  kfree (p->RIOHosts);
-  kfree (p);
+	/* Release dynamically allocated memory */
+	kfree(p->RIOPortp);
+	kfree(p->RIOHosts);
+	kfree(p);
 
-  func_exit();
+	func_exit();
 }
 
 module_init(rio_init);
@@ -1372,4 +1333,3 @@
  * tab-width: 8
  * End:
  */
-
diff --git a/drivers/char/rio/rio_linux.h b/drivers/char/rio/rio_linux.h
index 1fba19d5..4ce77fb 100644
--- a/drivers/char/rio/rio_linux.h
+++ b/drivers/char/rio/rio_linux.h
@@ -37,15 +37,15 @@
 
 
 struct vpd_prom {
-  unsigned short id;
-  char hwrev;
-  char hwass;
-  int uniqid;
-  char myear;
-  char mweek;
-  char hw_feature[5];
-  char oem_id;
-  char identifier[16];
+	unsigned short id;
+	char hwrev;
+	char hwass;
+	int uniqid;
+	char myear;
+	char mweek;
+	char hw_feature[5];
+	char oem_id;
+	char identifier[16];
 };
 
 
@@ -75,13 +75,13 @@
       (L_ISIG(tty)))
 
 
-#endif /* __KERNEL__ */
+#endif				/* __KERNEL__ */
 
 
 #define RIO_BOARD_INTR_LOCK  1
 
 
-#ifndef RIOCTL_MISC_MINOR 
+#ifndef RIOCTL_MISC_MINOR
 /* Allow others to gather this into "major.h" or something like that */
 #define RIOCTL_MISC_MINOR    169
 #endif
@@ -121,39 +121,39 @@
             spin_unlock_irqrestore(sem, flags)
 
 #define rio_spin_lock(sem) \
-            spin_lock(sem) 
+            spin_lock(sem)
 
 #define rio_spin_unlock(sem) \
-            spin_unlock(sem) 
+            spin_unlock(sem)
 
 #endif
 
 
 
 #ifdef CONFIG_RIO_OLDPCI
-static inline void *rio_memcpy_toio (void *dummy, void *dest, void *source, int n)
+static inline void *rio_memcpy_toio(void *dummy, void *dest, void *source, int n)
 {
-  char *dst = dest;
-  char *src = source;
+	char *dst = dest;
+	char *src = source;
 
-  while (n--) {
-    writeb (*src++, dst++);
-    (void) readb (dummy);
-  }
+	while (n--) {
+		writeb(*src++, dst++);
+		(void) readb(dummy);
+	}
 
-  return dest;
+	return dest;
 }
 
 
-static inline void *rio_memcpy_fromio (void *dest, void *source, int n)
+static inline void *rio_memcpy_fromio(void *dest, void *source, int n)
 {
-  char *dst = dest;
-  char *src = source;
+	char *dst = dest;
+	char *src = source;
 
-  while (n--) 
-    *dst++ = readb (src++);
+	while (n--)
+		*dst++ = readb(src++);
 
-  return dest;
+	return dest;
 }
 
 #else
@@ -179,9 +179,8 @@
 #define func_exit()  rio_dprintk (RIO_DEBUG_FLOW, "rio: exit  %s\n", __FUNCTION__)
 #define func_enter2() rio_dprintk (RIO_DEBUG_FLOW, "rio: enter %s (port %d)\n",__FUNCTION__, port->line)
 #else
-#define rio_dprintk(f, str...) /* nothing */
+#define rio_dprintk(f, str...)	/* nothing */
 #define func_enter()
 #define func_exit()
 #define func_enter2()
 #endif
-
diff --git a/drivers/char/rio/rioboard.h b/drivers/char/rio/rioboard.h
index cc6ac6a..822c071 100644
--- a/drivers/char/rio/rioboard.h
+++ b/drivers/char/rio/rioboard.h
@@ -35,7 +35,7 @@
 
 */
 
-#ifndef	_rioboard_h				/* If RIOBOARD.H not already defined */
+#ifndef	_rioboard_h		/* If RIOBOARD.H not already defined */
 #define	_rioboard_h    1
 
 /*****************************************************************************
@@ -46,7 +46,7 @@
 
 /* Hardware Registers... */
 
-#define	RIO_REG_BASE	0x7C00			/* Base of control registers */
+#define	RIO_REG_BASE	0x7C00	/* Base of control registers */
 
 #define	RIO_CONFIG	RIO_REG_BASE + 0x0000	/* WRITE: Configuration Register */
 #define	RIO_INTSET	RIO_REG_BASE + 0x0080	/* WRITE: Interrupt Set */
@@ -58,30 +58,30 @@
 #define	RIO_RESETSTAT	RIO_REG_BASE + 0x0100	/* READ: Reset Status (Jet boards only) */
 
 /* RIO_VPD_ROM definitions... */
-#define	VPD_SLX_ID1	0x00			/* READ: Specialix Identifier #1 */
-#define	VPD_SLX_ID2	0x01			/* READ: Specialix Identifier #2 */
-#define	VPD_HW_REV	0x02			/* READ: Hardware Revision */
-#define	VPD_HW_ASSEM	0x03			/* READ: Hardware Assembly Level */
-#define	VPD_UNIQUEID4	0x04			/* READ: Unique Identifier #4 */
-#define	VPD_UNIQUEID3	0x05			/* READ: Unique Identifier #3 */
-#define	VPD_UNIQUEID2	0x06			/* READ: Unique Identifier #2 */
-#define	VPD_UNIQUEID1	0x07			/* READ: Unique Identifier #1 */
-#define	VPD_MANU_YEAR	0x08			/* READ: Year Of Manufacture (0 = 1970) */
-#define	VPD_MANU_WEEK	0x09			/* READ: Week Of Manufacture (0 = week 1 Jan) */
-#define	VPD_HWFEATURE1	0x0A			/* READ: Hardware Feature Byte 1 */
-#define	VPD_HWFEATURE2	0x0B			/* READ: Hardware Feature Byte 2 */
-#define	VPD_HWFEATURE3	0x0C			/* READ: Hardware Feature Byte 3 */
-#define	VPD_HWFEATURE4	0x0D			/* READ: Hardware Feature Byte 4 */
-#define	VPD_HWFEATURE5	0x0E			/* READ: Hardware Feature Byte 5 */
-#define	VPD_OEMID	0x0F			/* READ: OEM Identifier */
-#define	VPD_IDENT	0x10			/* READ: Identifier string (16 bytes) */
+#define	VPD_SLX_ID1	0x00	/* READ: Specialix Identifier #1 */
+#define	VPD_SLX_ID2	0x01	/* READ: Specialix Identifier #2 */
+#define	VPD_HW_REV	0x02	/* READ: Hardware Revision */
+#define	VPD_HW_ASSEM	0x03	/* READ: Hardware Assembly Level */
+#define	VPD_UNIQUEID4	0x04	/* READ: Unique Identifier #4 */
+#define	VPD_UNIQUEID3	0x05	/* READ: Unique Identifier #3 */
+#define	VPD_UNIQUEID2	0x06	/* READ: Unique Identifier #2 */
+#define	VPD_UNIQUEID1	0x07	/* READ: Unique Identifier #1 */
+#define	VPD_MANU_YEAR	0x08	/* READ: Year Of Manufacture (0 = 1970) */
+#define	VPD_MANU_WEEK	0x09	/* READ: Week Of Manufacture (0 = week 1 Jan) */
+#define	VPD_HWFEATURE1	0x0A	/* READ: Hardware Feature Byte 1 */
+#define	VPD_HWFEATURE2	0x0B	/* READ: Hardware Feature Byte 2 */
+#define	VPD_HWFEATURE3	0x0C	/* READ: Hardware Feature Byte 3 */
+#define	VPD_HWFEATURE4	0x0D	/* READ: Hardware Feature Byte 4 */
+#define	VPD_HWFEATURE5	0x0E	/* READ: Hardware Feature Byte 5 */
+#define	VPD_OEMID	0x0F	/* READ: OEM Identifier */
+#define	VPD_IDENT	0x10	/* READ: Identifier string (16 bytes) */
 #define	VPD_IDENT_LEN	0x10
 
 /* VPD ROM Definitions... */
 #define	SLX_ID1		0x4D
 #define	SLX_ID2		0x98
 
-#define	PRODUCT_ID(a)	((a>>4)&0xF)		/* Use to obtain Product ID from VPD_UNIQUEID1 */
+#define	PRODUCT_ID(a)	((a>>4)&0xF)	/* Use to obtain Product ID from VPD_UNIQUEID1 */
 
 #define	ID_SX_ISA	0x2
 #define	ID_RIO_EISA	0x3
@@ -101,7 +101,7 @@
 
 /* Firmware load position... */
 
-#define	FIRMWARELOADADDR	0x7C00		/* Firmware is loaded _before_ this address */
+#define	FIRMWARELOADADDR	0x7C00	/* Firmware is loaded _before_ this address */
 
 /*****************************************************************************
 *****************************                    *****************************
@@ -112,14 +112,14 @@
 /* Control Register Definitions... */
 #define	RIO_ISA_IDENT	"JBJGPGGHINSMJPJR"
 
-#define	RIO_ISA_CFG_BOOTRAM	0x01		/* Boot from RAM, else Link */
-#define	RIO_ISA_CFG_BUSENABLE	0x02		/* Enable processor bus */
-#define	RIO_ISA_CFG_IRQMASK	0x30		/* Interrupt mask */
-#define	  RIO_ISA_CFG_IRQ12	0x10		/* Interrupt Level 12 */
-#define	  RIO_ISA_CFG_IRQ11	0x20		/* Interrupt Level 11 */
-#define	  RIO_ISA_CFG_IRQ9	0x30		/* Interrupt Level 9 */
-#define	RIO_ISA_CFG_LINK20	0x40		/* 20Mbps link, else 10Mbps */
-#define	RIO_ISA_CFG_WAITSTATE0	0x80		/* 0 waitstates, else 1 */
+#define	RIO_ISA_CFG_BOOTRAM	0x01	/* Boot from RAM, else Link */
+#define	RIO_ISA_CFG_BUSENABLE	0x02	/* Enable processor bus */
+#define	RIO_ISA_CFG_IRQMASK	0x30	/* Interrupt mask */
+#define	  RIO_ISA_CFG_IRQ12	0x10	/* Interrupt Level 12 */
+#define	  RIO_ISA_CFG_IRQ11	0x20	/* Interrupt Level 11 */
+#define	  RIO_ISA_CFG_IRQ9	0x30	/* Interrupt Level 9 */
+#define	RIO_ISA_CFG_LINK20	0x40	/* 20Mbps link, else 10Mbps */
+#define	RIO_ISA_CFG_WAITSTATE0	0x80	/* 0 waitstates, else 1 */
 
 /*****************************************************************************
 *****************************                    *****************************
@@ -130,17 +130,17 @@
 /* Control Register Definitions... */
 #define	RIO_ISA2_IDENT	"JBJGPGGHINSMJPJR"
 
-#define	RIO_ISA2_CFG_BOOTRAM	0x01		/* Boot from RAM, else Link */
-#define	RIO_ISA2_CFG_BUSENABLE	0x02		/* Enable processor bus */
-#define	RIO_ISA2_CFG_INTENABLE	0x04		/* Interrupt enable, else disable */
-#define	RIO_ISA2_CFG_16BIT	0x08		/* 16bit mode, else 8bit */
-#define	RIO_ISA2_CFG_IRQMASK	0x30		/* Interrupt mask */
-#define	  RIO_ISA2_CFG_IRQ15	0x00		/* Interrupt Level 15 */
-#define	  RIO_ISA2_CFG_IRQ12	0x10		/* Interrupt Level 12 */
-#define	  RIO_ISA2_CFG_IRQ11	0x20		/* Interrupt Level 11 */
-#define	  RIO_ISA2_CFG_IRQ9	0x30		/* Interrupt Level 9 */
-#define	RIO_ISA2_CFG_LINK20	0x40		/* 20Mbps link, else 10Mbps */
-#define	RIO_ISA2_CFG_WAITSTATE0	0x80		/* 0 waitstates, else 1 */
+#define	RIO_ISA2_CFG_BOOTRAM	0x01	/* Boot from RAM, else Link */
+#define	RIO_ISA2_CFG_BUSENABLE	0x02	/* Enable processor bus */
+#define	RIO_ISA2_CFG_INTENABLE	0x04	/* Interrupt enable, else disable */
+#define	RIO_ISA2_CFG_16BIT	0x08	/* 16bit mode, else 8bit */
+#define	RIO_ISA2_CFG_IRQMASK	0x30	/* Interrupt mask */
+#define	  RIO_ISA2_CFG_IRQ15	0x00	/* Interrupt Level 15 */
+#define	  RIO_ISA2_CFG_IRQ12	0x10	/* Interrupt Level 12 */
+#define	  RIO_ISA2_CFG_IRQ11	0x20	/* Interrupt Level 11 */
+#define	  RIO_ISA2_CFG_IRQ9	0x30	/* Interrupt Level 9 */
+#define	RIO_ISA2_CFG_LINK20	0x40	/* 20Mbps link, else 10Mbps */
+#define	RIO_ISA2_CFG_WAITSTATE0	0x80	/* 0 waitstates, else 1 */
 
 /*****************************************************************************
 *****************************                   ******************************
@@ -151,14 +151,14 @@
 /* Control Register Definitions... */
 #define	RIO_ISA3_IDENT	"JET HOST BY KEV#"
 
-#define	RIO_ISA3_CFG_BUSENABLE	0x02		/* Enable processor bus */
-#define	RIO_ISA3_CFG_INTENABLE	0x04		/* Interrupt enable, else disable */
-#define	RIO_ISA32_CFG_IRQMASK	0xF30		/* Interrupt mask */
-#define	  RIO_ISA3_CFG_IRQ15	0xF0		/* Interrupt Level 15 */
-#define	  RIO_ISA3_CFG_IRQ12	0xC0		/* Interrupt Level 12 */
-#define	  RIO_ISA3_CFG_IRQ11	0xB0		/* Interrupt Level 11 */
-#define	  RIO_ISA3_CFG_IRQ10	0xA0		/* Interrupt Level 10 */
-#define	  RIO_ISA3_CFG_IRQ9	0x90		/* Interrupt Level 9 */
+#define	RIO_ISA3_CFG_BUSENABLE	0x02	/* Enable processor bus */
+#define	RIO_ISA3_CFG_INTENABLE	0x04	/* Interrupt enable, else disable */
+#define	RIO_ISA32_CFG_IRQMASK	0xF30	/* Interrupt mask */
+#define	  RIO_ISA3_CFG_IRQ15	0xF0	/* Interrupt Level 15 */
+#define	  RIO_ISA3_CFG_IRQ12	0xC0	/* Interrupt Level 12 */
+#define	  RIO_ISA3_CFG_IRQ11	0xB0	/* Interrupt Level 11 */
+#define	  RIO_ISA3_CFG_IRQ10	0xA0	/* Interrupt Level 10 */
+#define	  RIO_ISA3_CFG_IRQ9	0x90	/* Interrupt Level 9 */
 
 /*****************************************************************************
 *********************************             ********************************
@@ -169,9 +169,9 @@
 /* Control Register Definitions... */
 #define	RIO_MCA_IDENT	"JBJGPGGHINSMJPJR"
 
-#define	RIO_MCA_CFG_BOOTRAM	0x01		/* Boot from RAM, else Link */
-#define	RIO_MCA_CFG_BUSENABLE	0x02		/* Enable processor bus */
-#define	RIO_MCA_CFG_LINK20	0x40		/* 20Mbps link, else 10Mbps */
+#define	RIO_MCA_CFG_BOOTRAM	0x01	/* Boot from RAM, else Link */
+#define	RIO_MCA_CFG_BUSENABLE	0x02	/* Enable processor bus */
+#define	RIO_MCA_CFG_LINK20	0x40	/* 20Mbps link, else 10Mbps */
 
 /*****************************************************************************
 ********************************              ********************************
@@ -185,35 +185,35 @@
 #define	EISA_PRODUCT_NUMBER	0xC82
 #define	EISA_REVISION_NUMBER	0xC83
 #define	EISA_CARD_ENABLE	0xC84
-#define	EISA_VPD_UNIQUEID4	0xC88		/* READ: Unique Identifier #4 */
-#define	EISA_VPD_UNIQUEID3	0xC8A		/* READ: Unique Identifier #3 */
-#define	EISA_VPD_UNIQUEID2	0xC90		/* READ: Unique Identifier #2 */
-#define	EISA_VPD_UNIQUEID1	0xC92		/* READ: Unique Identifier #1 */
-#define	EISA_VPD_MANU_YEAR	0xC98		/* READ: Year Of Manufacture (0 = 1970) */
-#define	EISA_VPD_MANU_WEEK	0xC9A		/* READ: Week Of Manufacture (0 = week 1 Jan) */
+#define	EISA_VPD_UNIQUEID4	0xC88	/* READ: Unique Identifier #4 */
+#define	EISA_VPD_UNIQUEID3	0xC8A	/* READ: Unique Identifier #3 */
+#define	EISA_VPD_UNIQUEID2	0xC90	/* READ: Unique Identifier #2 */
+#define	EISA_VPD_UNIQUEID1	0xC92	/* READ: Unique Identifier #1 */
+#define	EISA_VPD_MANU_YEAR	0xC98	/* READ: Year Of Manufacture (0 = 1970) */
+#define	EISA_VPD_MANU_WEEK	0xC9A	/* READ: Week Of Manufacture (0 = week 1 Jan) */
 #define	EISA_MEM_ADDR_23_16	0xC00
 #define	EISA_MEM_ADDR_31_24	0xC01
-#define	EISA_RIO_CONFIG		0xC02		/* WRITE: Configuration Register */
-#define	EISA_RIO_INTSET		0xC03		/* WRITE: Interrupt Set */
-#define	EISA_RIO_INTRESET	0xC03		/* READ:  Interrupt Reset */
+#define	EISA_RIO_CONFIG		0xC02	/* WRITE: Configuration Register */
+#define	EISA_RIO_INTSET		0xC03	/* WRITE: Interrupt Set */
+#define	EISA_RIO_INTRESET	0xC03	/* READ:  Interrupt Reset */
 
 /* Control Register Definitions... */
-#define	RIO_EISA_CFG_BOOTRAM	0x01		/* Boot from RAM, else Link */
-#define	RIO_EISA_CFG_LINK20	0x02		/* 20Mbps link, else 10Mbps */
-#define	RIO_EISA_CFG_BUSENABLE	0x04		/* Enable processor bus */
-#define	RIO_EISA_CFG_PROCRUN	0x08		/* Processor running, else reset */
-#define	RIO_EISA_CFG_IRQMASK	0xF0		/* Interrupt mask */
-#define	  RIO_EISA_CFG_IRQ15	0xF0		/* Interrupt Level 15 */
-#define	  RIO_EISA_CFG_IRQ14	0xE0		/* Interrupt Level 14 */
-#define	  RIO_EISA_CFG_IRQ12	0xC0		/* Interrupt Level 12 */
-#define	  RIO_EISA_CFG_IRQ11	0xB0		/* Interrupt Level 11 */
-#define	  RIO_EISA_CFG_IRQ10	0xA0		/* Interrupt Level 10 */
-#define	  RIO_EISA_CFG_IRQ9	0x90		/* Interrupt Level 9 */
-#define	  RIO_EISA_CFG_IRQ7	0x70		/* Interrupt Level 7 */
-#define	  RIO_EISA_CFG_IRQ6	0x60		/* Interrupt Level 6 */
-#define	  RIO_EISA_CFG_IRQ5	0x50		/* Interrupt Level 5 */
-#define	  RIO_EISA_CFG_IRQ4	0x40		/* Interrupt Level 4 */
-#define	  RIO_EISA_CFG_IRQ3	0x30		/* Interrupt Level 3 */
+#define	RIO_EISA_CFG_BOOTRAM	0x01	/* Boot from RAM, else Link */
+#define	RIO_EISA_CFG_LINK20	0x02	/* 20Mbps link, else 10Mbps */
+#define	RIO_EISA_CFG_BUSENABLE	0x04	/* Enable processor bus */
+#define	RIO_EISA_CFG_PROCRUN	0x08	/* Processor running, else reset */
+#define	RIO_EISA_CFG_IRQMASK	0xF0	/* Interrupt mask */
+#define	  RIO_EISA_CFG_IRQ15	0xF0	/* Interrupt Level 15 */
+#define	  RIO_EISA_CFG_IRQ14	0xE0	/* Interrupt Level 14 */
+#define	  RIO_EISA_CFG_IRQ12	0xC0	/* Interrupt Level 12 */
+#define	  RIO_EISA_CFG_IRQ11	0xB0	/* Interrupt Level 11 */
+#define	  RIO_EISA_CFG_IRQ10	0xA0	/* Interrupt Level 10 */
+#define	  RIO_EISA_CFG_IRQ9	0x90	/* Interrupt Level 9 */
+#define	  RIO_EISA_CFG_IRQ7	0x70	/* Interrupt Level 7 */
+#define	  RIO_EISA_CFG_IRQ6	0x60	/* Interrupt Level 6 */
+#define	  RIO_EISA_CFG_IRQ5	0x50	/* Interrupt Level 5 */
+#define	  RIO_EISA_CFG_IRQ4	0x40	/* Interrupt Level 4 */
+#define	  RIO_EISA_CFG_IRQ3	0x30	/* Interrupt Level 3 */
 
 /*****************************************************************************
 ********************************              ********************************
@@ -224,20 +224,20 @@
 /* Control Register Definitions... */
 #define	RIO_SBUS_IDENT	"JBPGK#\0\0\0\0\0\0\0\0\0\0"
 
-#define	RIO_SBUS_CFG_BOOTRAM	0x01		/* Boot from RAM, else Link */
-#define	RIO_SBUS_CFG_BUSENABLE	0x02		/* Enable processor bus */
-#define	RIO_SBUS_CFG_INTENABLE	0x04		/* Interrupt enable, else disable */
-#define	RIO_SBUS_CFG_IRQMASK	0x38		/* Interrupt mask */
-#define	  RIO_SBUS_CFG_IRQNONE	0x00		/* No Interrupt */
-#define	  RIO_SBUS_CFG_IRQ7	0x38		/* Interrupt Level 7 */
-#define	  RIO_SBUS_CFG_IRQ6	0x30		/* Interrupt Level 6 */
-#define	  RIO_SBUS_CFG_IRQ5	0x28		/* Interrupt Level 5 */
-#define	  RIO_SBUS_CFG_IRQ4	0x20		/* Interrupt Level 4 */
-#define	  RIO_SBUS_CFG_IRQ3	0x18		/* Interrupt Level 3 */
-#define	  RIO_SBUS_CFG_IRQ2	0x10		/* Interrupt Level 2 */
-#define	  RIO_SBUS_CFG_IRQ1	0x08		/* Interrupt Level 1 */
-#define	RIO_SBUS_CFG_LINK20	0x40		/* 20Mbps link, else 10Mbps */
-#define	RIO_SBUS_CFG_PROC25	0x80		/* 25Mhz processor clock, else 20Mhz */
+#define	RIO_SBUS_CFG_BOOTRAM	0x01	/* Boot from RAM, else Link */
+#define	RIO_SBUS_CFG_BUSENABLE	0x02	/* Enable processor bus */
+#define	RIO_SBUS_CFG_INTENABLE	0x04	/* Interrupt enable, else disable */
+#define	RIO_SBUS_CFG_IRQMASK	0x38	/* Interrupt mask */
+#define	  RIO_SBUS_CFG_IRQNONE	0x00	/* No Interrupt */
+#define	  RIO_SBUS_CFG_IRQ7	0x38	/* Interrupt Level 7 */
+#define	  RIO_SBUS_CFG_IRQ6	0x30	/* Interrupt Level 6 */
+#define	  RIO_SBUS_CFG_IRQ5	0x28	/* Interrupt Level 5 */
+#define	  RIO_SBUS_CFG_IRQ4	0x20	/* Interrupt Level 4 */
+#define	  RIO_SBUS_CFG_IRQ3	0x18	/* Interrupt Level 3 */
+#define	  RIO_SBUS_CFG_IRQ2	0x10	/* Interrupt Level 2 */
+#define	  RIO_SBUS_CFG_IRQ1	0x08	/* Interrupt Level 1 */
+#define	RIO_SBUS_CFG_LINK20	0x40	/* 20Mbps link, else 10Mbps */
+#define	RIO_SBUS_CFG_PROC25	0x80	/* 25Mhz processor clock, else 20Mhz */
 
 /*****************************************************************************
 *********************************             ********************************
@@ -248,18 +248,18 @@
 /* Control Register Definitions... */
 #define	RIO_PCI_IDENT	"ECDDPGJGJHJRGSK#"
 
-#define	RIO_PCI_CFG_BOOTRAM	0x01		/* Boot from RAM, else Link */
-#define	RIO_PCI_CFG_BUSENABLE	0x02		/* Enable processor bus */
-#define	RIO_PCI_CFG_INTENABLE	0x04		/* Interrupt enable, else disable */
-#define	RIO_PCI_CFG_LINK20	0x40		/* 20Mbps link, else 10Mbps */
-#define	RIO_PCI_CFG_PROC25	0x80		/* 25Mhz processor clock, else 20Mhz */
+#define	RIO_PCI_CFG_BOOTRAM	0x01	/* Boot from RAM, else Link */
+#define	RIO_PCI_CFG_BUSENABLE	0x02	/* Enable processor bus */
+#define	RIO_PCI_CFG_INTENABLE	0x04	/* Interrupt enable, else disable */
+#define	RIO_PCI_CFG_LINK20	0x40	/* 20Mbps link, else 10Mbps */
+#define	RIO_PCI_CFG_PROC25	0x80	/* 25Mhz processor clock, else 20Mhz */
 
 /* PCI Definitions... */
-#define	SPX_VENDOR_ID		0x11CB		/* Assigned by the PCI SIG */
-#define	SPX_DEVICE_ID		0x8000		/* RIO bridge boards */
-#define	SPX_PLXDEVICE_ID	0x2000		/* PLX bridge boards */
+#define	SPX_VENDOR_ID		0x11CB	/* Assigned by the PCI SIG */
+#define	SPX_DEVICE_ID		0x8000	/* RIO bridge boards */
+#define	SPX_PLXDEVICE_ID	0x2000	/* PLX bridge boards */
 #define	SPX_SUB_VENDOR_ID	SPX_VENDOR_ID	/* Same as vendor id */
-#define	RIO_SUB_SYS_ID		0x0800		/* RIO PCI board */
+#define	RIO_SUB_SYS_ID		0x0800	/* RIO PCI board */
 
 /*****************************************************************************
 *****************************                   ******************************
@@ -270,11 +270,11 @@
 /* Control Register Definitions... */
 #define	RIO_PCI2_IDENT	"JET HOST BY KEV#"
 
-#define	RIO_PCI2_CFG_BUSENABLE	0x02		/* Enable processor bus */
-#define	RIO_PCI2_CFG_INTENABLE	0x04		/* Interrupt enable, else disable */
+#define	RIO_PCI2_CFG_BUSENABLE	0x02	/* Enable processor bus */
+#define	RIO_PCI2_CFG_INTENABLE	0x04	/* Interrupt enable, else disable */
 
 /* PCI Definitions... */
-#define	RIO2_SUB_SYS_ID		0x0100		/* RIO (Jet) PCI board */
+#define	RIO2_SUB_SYS_ID		0x0100	/* RIO (Jet) PCI board */
 
 #endif						/*_rioboard_h */
 
diff --git a/drivers/char/rio/riocmd.c b/drivers/char/rio/riocmd.c
index 533085e..b97dd9f 100644
--- a/drivers/char/rio/riocmd.c
+++ b/drivers/char/rio/riocmd.c
@@ -83,102 +83,98 @@
 static struct IdentifyRta IdRta;
 static struct KillNeighbour KillUnit;
 
-int
-RIOFoadRta(struct Host *HostP, struct Map *MapP)
+int RIOFoadRta(struct Host *HostP, struct Map *MapP)
 {
 	struct CmdBlk *CmdBlkP;
 
-	rio_dprintk (RIO_DEBUG_CMD, "FOAD RTA\n");
+	rio_dprintk(RIO_DEBUG_CMD, "FOAD RTA\n");
 
 	CmdBlkP = RIOGetCmdBlk();
 
-	if ( !CmdBlkP ) {
-		rio_dprintk (RIO_DEBUG_CMD, "FOAD RTA: GetCmdBlk failed\n");
+	if (!CmdBlkP) {
+		rio_dprintk(RIO_DEBUG_CMD, "FOAD RTA: GetCmdBlk failed\n");
 		return -ENXIO;
 	}
 
 	CmdBlkP->Packet.dest_unit = MapP->ID;
 	CmdBlkP->Packet.dest_port = BOOT_RUP;
-	CmdBlkP->Packet.src_unit  = 0;
-	CmdBlkP->Packet.src_port  = BOOT_RUP;
-	CmdBlkP->Packet.len	   = 0x84;
-	CmdBlkP->Packet.data[0]   = IFOAD;
-	CmdBlkP->Packet.data[1]   = 0;
-	CmdBlkP->Packet.data[2]   = IFOAD_MAGIC & 0xFF;
-	CmdBlkP->Packet.data[3]   = (IFOAD_MAGIC >> 8) & 0xFF;
+	CmdBlkP->Packet.src_unit = 0;
+	CmdBlkP->Packet.src_port = BOOT_RUP;
+	CmdBlkP->Packet.len = 0x84;
+	CmdBlkP->Packet.data[0] = IFOAD;
+	CmdBlkP->Packet.data[1] = 0;
+	CmdBlkP->Packet.data[2] = IFOAD_MAGIC & 0xFF;
+	CmdBlkP->Packet.data[3] = (IFOAD_MAGIC >> 8) & 0xFF;
 
-	if ( RIOQueueCmdBlk( HostP, MapP->ID-1, CmdBlkP) == RIO_FAIL ) {
-		rio_dprintk (RIO_DEBUG_CMD, "FOAD RTA: Failed to queue foad command\n");
+	if (RIOQueueCmdBlk(HostP, MapP->ID - 1, CmdBlkP) == RIO_FAIL) {
+		rio_dprintk(RIO_DEBUG_CMD, "FOAD RTA: Failed to queue foad command\n");
 		return -EIO;
 	}
 	return 0;
 }
 
-int
-RIOZombieRta(struct Host *HostP, struct Map *MapP)
+int RIOZombieRta(struct Host *HostP, struct Map *MapP)
 {
 	struct CmdBlk *CmdBlkP;
 
-	rio_dprintk (RIO_DEBUG_CMD, "ZOMBIE RTA\n");
+	rio_dprintk(RIO_DEBUG_CMD, "ZOMBIE RTA\n");
 
 	CmdBlkP = RIOGetCmdBlk();
 
-	if ( !CmdBlkP ) {
-		rio_dprintk (RIO_DEBUG_CMD, "ZOMBIE RTA: GetCmdBlk failed\n");
+	if (!CmdBlkP) {
+		rio_dprintk(RIO_DEBUG_CMD, "ZOMBIE RTA: GetCmdBlk failed\n");
 		return -ENXIO;
 	}
 
 	CmdBlkP->Packet.dest_unit = MapP->ID;
 	CmdBlkP->Packet.dest_port = BOOT_RUP;
-	CmdBlkP->Packet.src_unit  = 0;
-	CmdBlkP->Packet.src_port  = BOOT_RUP;
-	CmdBlkP->Packet.len	   = 0x84;
-	CmdBlkP->Packet.data[0]   = ZOMBIE;
-	CmdBlkP->Packet.data[1]   = 0;
-	CmdBlkP->Packet.data[2]   = ZOMBIE_MAGIC & 0xFF;
-	CmdBlkP->Packet.data[3]   = (ZOMBIE_MAGIC >> 8) & 0xFF;
+	CmdBlkP->Packet.src_unit = 0;
+	CmdBlkP->Packet.src_port = BOOT_RUP;
+	CmdBlkP->Packet.len = 0x84;
+	CmdBlkP->Packet.data[0] = ZOMBIE;
+	CmdBlkP->Packet.data[1] = 0;
+	CmdBlkP->Packet.data[2] = ZOMBIE_MAGIC & 0xFF;
+	CmdBlkP->Packet.data[3] = (ZOMBIE_MAGIC >> 8) & 0xFF;
 
-	if ( RIOQueueCmdBlk( HostP, MapP->ID-1, CmdBlkP) == RIO_FAIL ) {
-		rio_dprintk (RIO_DEBUG_CMD, "ZOMBIE RTA: Failed to queue zombie command\n");
+	if (RIOQueueCmdBlk(HostP, MapP->ID - 1, CmdBlkP) == RIO_FAIL) {
+		rio_dprintk(RIO_DEBUG_CMD, "ZOMBIE RTA: Failed to queue zombie command\n");
 		return -EIO;
 	}
 	return 0;
 }
 
-int
-RIOCommandRta(struct rio_info *p, uint RtaUnique,
-	int (* func)(struct Host *HostP, struct Map *MapP))
+int RIOCommandRta(struct rio_info *p, uint RtaUnique, int (*func) (struct Host * HostP, struct Map * MapP))
 {
 	uint Host;
 
-	rio_dprintk (RIO_DEBUG_CMD, "Command RTA 0x%x func 0x%x\n", RtaUnique, (int)func);
+	rio_dprintk(RIO_DEBUG_CMD, "Command RTA 0x%x func 0x%x\n", RtaUnique, (int) func);
 
-	if ( !RtaUnique )
-		return(0);
+	if (!RtaUnique)
+		return (0);
 
-	for ( Host = 0; Host < p->RIONumHosts; Host++ ) {
+	for (Host = 0; Host < p->RIONumHosts; Host++) {
 		uint Rta;
 		struct Host *HostP = &p->RIOHosts[Host];
 
-		for ( Rta = 0; Rta < RTAS_PER_HOST; Rta++ ) {
+		for (Rta = 0; Rta < RTAS_PER_HOST; Rta++) {
 			struct Map *MapP = &HostP->Mapping[Rta];
 
-			if ( MapP->RtaUniqueNum == RtaUnique ) {
+			if (MapP->RtaUniqueNum == RtaUnique) {
 				uint Link;
 
 				/*
-				** now, lets just check we have a route to it...
-				** IF the routing stuff is working, then one of the
-				** topology entries for this unit will have a legit
-				** route *somewhere*. We care not where - if its got
-				** any connections, we can get to it.
-				*/
-				for ( Link = 0; Link < LINKS_PER_UNIT; Link++ ) {
-					if ( MapP->Topology[Link].Unit <= (uchar)MAX_RUP ) {
+				 ** now, lets just check we have a route to it...
+				 ** IF the routing stuff is working, then one of the
+				 ** topology entries for this unit will have a legit
+				 ** route *somewhere*. We care not where - if its got
+				 ** any connections, we can get to it.
+				 */
+				for (Link = 0; Link < LINKS_PER_UNIT; Link++) {
+					if (MapP->Topology[Link].Unit <= (uchar) MAX_RUP) {
 						/*
-						** Its worth trying the operation...
-						*/
-						return (*func)( HostP, MapP );
+						 ** Its worth trying the operation...
+						 */
+						return (*func) (HostP, MapP);
 					}
 				}
 			}
@@ -188,60 +184,59 @@
 }
 
 
-int
-RIOIdentifyRta(struct rio_info *p, caddr_t arg)
+int RIOIdentifyRta(struct rio_info *p, caddr_t arg)
 {
 	uint Host;
 
-	if ( copyin( (int)arg, (caddr_t)&IdRta, sizeof(IdRta) ) == COPYFAIL ) {
-		rio_dprintk (RIO_DEBUG_CMD, "RIO_IDENTIFY_RTA copy failed\n");
+	if (copyin((int) arg, (caddr_t) & IdRta, sizeof(IdRta)) == COPYFAIL) {
+		rio_dprintk(RIO_DEBUG_CMD, "RIO_IDENTIFY_RTA copy failed\n");
 		p->RIOError.Error = COPYIN_FAILED;
 		return -EFAULT;
 	}
 
-	for ( Host = 0 ; Host < p->RIONumHosts; Host++ ) {
+	for (Host = 0; Host < p->RIONumHosts; Host++) {
 		uint Rta;
 		struct Host *HostP = &p->RIOHosts[Host];
 
-		for ( Rta = 0; Rta < RTAS_PER_HOST; Rta++ ) {
+		for (Rta = 0; Rta < RTAS_PER_HOST; Rta++) {
 			struct Map *MapP = &HostP->Mapping[Rta];
 
-			if ( MapP->RtaUniqueNum == IdRta.RtaUnique ) {
+			if (MapP->RtaUniqueNum == IdRta.RtaUnique) {
 				uint Link;
 				/*
-				** now, lets just check we have a route to it...
-				** IF the routing stuff is working, then one of the
-				** topology entries for this unit will have a legit
-				** route *somewhere*. We care not where - if its got
-				** any connections, we can get to it.
-				*/
-				for ( Link = 0; Link < LINKS_PER_UNIT; Link++ ) {
-					if ( MapP->Topology[Link].Unit <= (uchar)MAX_RUP ) {
+				 ** now, lets just check we have a route to it...
+				 ** IF the routing stuff is working, then one of the
+				 ** topology entries for this unit will have a legit
+				 ** route *somewhere*. We care not where - if its got
+				 ** any connections, we can get to it.
+				 */
+				for (Link = 0; Link < LINKS_PER_UNIT; Link++) {
+					if (MapP->Topology[Link].Unit <= (uchar) MAX_RUP) {
 						/*
-						** Its worth trying the operation...
-						*/
+						 ** Its worth trying the operation...
+						 */
 						struct CmdBlk *CmdBlkP;
 
-						rio_dprintk (RIO_DEBUG_CMD, "IDENTIFY RTA\n");
+						rio_dprintk(RIO_DEBUG_CMD, "IDENTIFY RTA\n");
 
 						CmdBlkP = RIOGetCmdBlk();
 
-						if ( !CmdBlkP ) {
-							rio_dprintk (RIO_DEBUG_CMD, "IDENTIFY RTA: GetCmdBlk failed\n");
+						if (!CmdBlkP) {
+							rio_dprintk(RIO_DEBUG_CMD, "IDENTIFY RTA: GetCmdBlk failed\n");
 							return -ENXIO;
 						}
-		
+
 						CmdBlkP->Packet.dest_unit = MapP->ID;
 						CmdBlkP->Packet.dest_port = BOOT_RUP;
-						CmdBlkP->Packet.src_unit  = 0;
-						CmdBlkP->Packet.src_port  = BOOT_RUP;
-						CmdBlkP->Packet.len	   = 0x84;
-						CmdBlkP->Packet.data[0]   = IDENTIFY;
-						CmdBlkP->Packet.data[1]   = 0;
-						CmdBlkP->Packet.data[2]   = IdRta.ID;
-		
-						if ( RIOQueueCmdBlk( HostP, MapP->ID-1, CmdBlkP) == RIO_FAIL ) {
-							rio_dprintk (RIO_DEBUG_CMD, "IDENTIFY RTA: Failed to queue command\n");
+						CmdBlkP->Packet.src_unit = 0;
+						CmdBlkP->Packet.src_port = BOOT_RUP;
+						CmdBlkP->Packet.len = 0x84;
+						CmdBlkP->Packet.data[0] = IDENTIFY;
+						CmdBlkP->Packet.data[1] = 0;
+						CmdBlkP->Packet.data[2] = IdRta.ID;
+
+						if (RIOQueueCmdBlk(HostP, MapP->ID - 1, CmdBlkP) == RIO_FAIL) {
+							rio_dprintk(RIO_DEBUG_CMD, "IDENTIFY RTA: Failed to queue command\n");
 							return -EIO;
 						}
 						return 0;
@@ -249,114 +244,110 @@
 				}
 			}
 		}
-	} 
+	}
 	return -ENOENT;
 }
 
 
-int
-RIOKillNeighbour(struct rio_info *p, caddr_t arg)
+int RIOKillNeighbour(struct rio_info *p, caddr_t arg)
 {
 	uint Host;
 	uint ID;
 	struct Host *HostP;
 	struct CmdBlk *CmdBlkP;
 
-	rio_dprintk (RIO_DEBUG_CMD, "KILL HOST NEIGHBOUR\n");
+	rio_dprintk(RIO_DEBUG_CMD, "KILL HOST NEIGHBOUR\n");
 
-	if ( copyin( (int)arg, (caddr_t)&KillUnit, sizeof(KillUnit) ) == COPYFAIL ) {
-		rio_dprintk (RIO_DEBUG_CMD, "RIO_KILL_NEIGHBOUR copy failed\n");
+	if (copyin((int) arg, (caddr_t) & KillUnit, sizeof(KillUnit)) == COPYFAIL) {
+		rio_dprintk(RIO_DEBUG_CMD, "RIO_KILL_NEIGHBOUR copy failed\n");
 		p->RIOError.Error = COPYIN_FAILED;
 		return -EFAULT;
 	}
 
-	if ( KillUnit.Link > 3 )
+	if (KillUnit.Link > 3)
 		return -ENXIO;
- 
+
 	CmdBlkP = RIOGetCmdBlk();
 
-	if ( !CmdBlkP ) {
-		rio_dprintk (RIO_DEBUG_CMD, "UFOAD: GetCmdBlk failed\n");
+	if (!CmdBlkP) {
+		rio_dprintk(RIO_DEBUG_CMD, "UFOAD: GetCmdBlk failed\n");
 		return -ENXIO;
 	}
 
 	CmdBlkP->Packet.dest_unit = 0;
-	CmdBlkP->Packet.src_unit  = 0;
+	CmdBlkP->Packet.src_unit = 0;
 	CmdBlkP->Packet.dest_port = BOOT_RUP;
-	CmdBlkP->Packet.src_port  = BOOT_RUP;
-	CmdBlkP->Packet.len	   = 0x84;
-	CmdBlkP->Packet.data[0]   = UFOAD;
-	CmdBlkP->Packet.data[1]   = KillUnit.Link;
-	CmdBlkP->Packet.data[2]   = UFOAD_MAGIC & 0xFF;
-	CmdBlkP->Packet.data[3]   = (UFOAD_MAGIC >> 8) & 0xFF;
+	CmdBlkP->Packet.src_port = BOOT_RUP;
+	CmdBlkP->Packet.len = 0x84;
+	CmdBlkP->Packet.data[0] = UFOAD;
+	CmdBlkP->Packet.data[1] = KillUnit.Link;
+	CmdBlkP->Packet.data[2] = UFOAD_MAGIC & 0xFF;
+	CmdBlkP->Packet.data[3] = (UFOAD_MAGIC >> 8) & 0xFF;
 
-	for ( Host = 0; Host < p->RIONumHosts; Host++ ) {
+	for (Host = 0; Host < p->RIONumHosts; Host++) {
 		ID = 0;
 		HostP = &p->RIOHosts[Host];
 
-		if ( HostP->UniqueNum == KillUnit.UniqueNum ) {
-			if ( RIOQueueCmdBlk( HostP, RTAS_PER_HOST+KillUnit.Link,
-							CmdBlkP) == RIO_FAIL ) {
-				rio_dprintk (RIO_DEBUG_CMD, "UFOAD: Failed queue command\n");
+		if (HostP->UniqueNum == KillUnit.UniqueNum) {
+			if (RIOQueueCmdBlk(HostP, RTAS_PER_HOST + KillUnit.Link, CmdBlkP) == RIO_FAIL) {
+				rio_dprintk(RIO_DEBUG_CMD, "UFOAD: Failed queue command\n");
 				return -EIO;
 			}
 			return 0;
 		}
 
-		for ( ID=0; ID < RTAS_PER_HOST; ID++ ) {
-			if ( HostP->Mapping[ID].RtaUniqueNum == KillUnit.UniqueNum ) {
-				CmdBlkP->Packet.dest_unit = ID+1;
-				if ( RIOQueueCmdBlk( HostP, ID, CmdBlkP) == RIO_FAIL ) {
-					rio_dprintk (RIO_DEBUG_CMD, "UFOAD: Failed queue command\n");
+		for (ID = 0; ID < RTAS_PER_HOST; ID++) {
+			if (HostP->Mapping[ID].RtaUniqueNum == KillUnit.UniqueNum) {
+				CmdBlkP->Packet.dest_unit = ID + 1;
+				if (RIOQueueCmdBlk(HostP, ID, CmdBlkP) == RIO_FAIL) {
+					rio_dprintk(RIO_DEBUG_CMD, "UFOAD: Failed queue command\n");
 					return -EIO;
 				}
 				return 0;
 			}
 		}
 	}
-	RIOFreeCmdBlk( CmdBlkP );
+	RIOFreeCmdBlk(CmdBlkP);
 	return -ENXIO;
 }
 
-int
-RIOSuspendBootRta(struct Host *HostP, int ID, int Link)
+int RIOSuspendBootRta(struct Host *HostP, int ID, int Link)
 {
 	struct CmdBlk *CmdBlkP;
 
-	rio_dprintk (RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA ID %d, link %c\n", ID, 'A' + Link);
+	rio_dprintk(RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA ID %d, link %c\n", ID, 'A' + Link);
 
 	CmdBlkP = RIOGetCmdBlk();
 
-	if ( !CmdBlkP ) {
-		rio_dprintk (RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA: GetCmdBlk failed\n");
+	if (!CmdBlkP) {
+		rio_dprintk(RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA: GetCmdBlk failed\n");
 		return -ENXIO;
 	}
 
 	CmdBlkP->Packet.dest_unit = ID;
 	CmdBlkP->Packet.dest_port = BOOT_RUP;
-	CmdBlkP->Packet.src_unit  = 0;
-	CmdBlkP->Packet.src_port  = BOOT_RUP;
-	CmdBlkP->Packet.len	   = 0x84;
-	CmdBlkP->Packet.data[0]   = IWAIT;
-	CmdBlkP->Packet.data[1]   = Link;
-	CmdBlkP->Packet.data[2]   = IWAIT_MAGIC & 0xFF;
-	CmdBlkP->Packet.data[3]   = (IWAIT_MAGIC >> 8) & 0xFF;
+	CmdBlkP->Packet.src_unit = 0;
+	CmdBlkP->Packet.src_port = BOOT_RUP;
+	CmdBlkP->Packet.len = 0x84;
+	CmdBlkP->Packet.data[0] = IWAIT;
+	CmdBlkP->Packet.data[1] = Link;
+	CmdBlkP->Packet.data[2] = IWAIT_MAGIC & 0xFF;
+	CmdBlkP->Packet.data[3] = (IWAIT_MAGIC >> 8) & 0xFF;
 
-	if ( RIOQueueCmdBlk( HostP, ID - 1, CmdBlkP) == RIO_FAIL ) {
-		rio_dprintk (RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA: Failed to queue iwait command\n");
+	if (RIOQueueCmdBlk(HostP, ID - 1, CmdBlkP) == RIO_FAIL) {
+		rio_dprintk(RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA: Failed to queue iwait command\n");
 		return -EIO;
 	}
 	return 0;
 }
 
-int
-RIOFoadWakeup(struct rio_info *p)
+int RIOFoadWakeup(struct rio_info *p)
 {
 	int port;
 	register struct Port *PortP;
 	unsigned long flags;
 
-	for ( port=0; port<RIO_PORTS; port++) {
+	for (port = 0; port < RIO_PORTS; port++) {
 		PortP = p->RIOPortp[port];
 
 		rio_spin_lock_irqsave(&PortP->portSem, flags);
@@ -377,16 +368,15 @@
 		PortP->TxBufferOut = 0;
 		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 	}
-	return(0);
+	return (0);
 }
 
 /*
 ** Incoming command on the COMMAND_RUP to be processed.
 */
-static int
-RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT *PacketP)
+static int RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP)
 {
-	struct PktCmd *PktCmdP = (struct PktCmd *)PacketP->data;
+	struct PktCmd *PktCmdP = (struct PktCmd *) PacketP->data;
 	struct Port *PortP;
 	struct UnixRup *UnixRupP;
 	ushort SysPort;
@@ -395,128 +385,114 @@
 	ushort subCommand;
 	unsigned long flags;
 
-	func_enter ();
+	func_enter();
 
 #ifdef CHECK
-	CheckHost( Host );
-	CheckHostP( HostP );
-	CheckPacketP( PacketP );
+	CheckHost(Host);
+	CheckHostP(HostP);
+	CheckPacketP(PacketP);
 #endif
 
 	/*
-	** 16 port RTA note:
-	** Command rup packets coming from the RTA will have pkt->data[1] (which
-	** translates to PktCmdP->PhbNum) set to the host port number for the
-	** particular unit. To access the correct BaseSysPort for a 16 port RTA,
-	** we can use PhbNum to get the rup number for the appropriate 8 port
-	** block (for the first block, this should be equal to 'Rup').
-	*/
-	rup = RBYTE(PktCmdP->PhbNum) / (ushort)PORTS_PER_RTA;
+	 ** 16 port RTA note:
+	 ** Command rup packets coming from the RTA will have pkt->data[1] (which
+	 ** translates to PktCmdP->PhbNum) set to the host port number for the
+	 ** particular unit. To access the correct BaseSysPort for a 16 port RTA,
+	 ** we can use PhbNum to get the rup number for the appropriate 8 port
+	 ** block (for the first block, this should be equal to 'Rup').
+	 */
+	rup = RBYTE(PktCmdP->PhbNum) / (ushort) PORTS_PER_RTA;
 	UnixRupP = &HostP->UnixRups[rup];
-	SysPort = UnixRupP->BaseSysPort + 
-			(RBYTE(PktCmdP->PhbNum) % (ushort)PORTS_PER_RTA);
-	rio_dprintk (RIO_DEBUG_CMD, "Command on rup %d, port %d\n", rup, SysPort);
+	SysPort = UnixRupP->BaseSysPort + (RBYTE(PktCmdP->PhbNum) % (ushort) PORTS_PER_RTA);
+	rio_dprintk(RIO_DEBUG_CMD, "Command on rup %d, port %d\n", rup, SysPort);
 
 #ifdef CHECK
-	CheckRup( rup );
-	CheckUnixRupP( UnixRupP );
+	CheckRup(rup);
+	CheckUnixRupP(UnixRupP);
 #endif
-	if ( UnixRupP->BaseSysPort == NO_PORT ) {
-		rio_dprintk (RIO_DEBUG_CMD, "OBSCURE ERROR!\n");
-		rio_dprintk (RIO_DEBUG_CMD, "Diagnostics follow. Please WRITE THESE DOWN and report them to Specialix Technical Support\n");
-		rio_dprintk (RIO_DEBUG_CMD, "CONTROL information: Host number %d, name ``%s''\n", 
-			     HostP-p->RIOHosts, HostP->Name );
-		rio_dprintk (RIO_DEBUG_CMD, "CONTROL information: Rup number  0x%x\n", rup);
+	if (UnixRupP->BaseSysPort == NO_PORT) {
+		rio_dprintk(RIO_DEBUG_CMD, "OBSCURE ERROR!\n");
+		rio_dprintk(RIO_DEBUG_CMD, "Diagnostics follow. Please WRITE THESE DOWN and report them to Specialix Technical Support\n");
+		rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: Host number %d, name ``%s''\n", HostP - p->RIOHosts, HostP->Name);
+		rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: Rup number  0x%x\n", rup);
 
-		if ( Rup >= (ushort)MAX_RUP ) {
-			rio_dprintk (RIO_DEBUG_CMD, "CONTROL information: This is the RUP for RTA ``%s''\n",
-				     HostP->Mapping[Rup].Name);
+		if (Rup >= (ushort) MAX_RUP) {
+			rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: This is the RUP for RTA ``%s''\n", HostP->Mapping[Rup].Name);
 		} else
-			rio_dprintk (RIO_DEBUG_CMD, "CONTROL information: This is the RUP for link ``%c'' of host ``%s''\n", 
-				     ('A' + Rup - MAX_RUP), HostP->Name);
+			rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: This is the RUP for link ``%c'' of host ``%s''\n", ('A' + Rup - MAX_RUP), HostP->Name);
 
-		rio_dprintk (RIO_DEBUG_CMD, "PACKET information: Destination 0x%x:0x%x\n",
-			     PacketP->dest_unit, PacketP->dest_port );
-		rio_dprintk (RIO_DEBUG_CMD, "PACKET information: Source	  0x%x:0x%x\n",
-			     PacketP->src_unit, PacketP->src_port );
-		rio_dprintk (RIO_DEBUG_CMD, "PACKET information: Length	  0x%x (%d)\n", PacketP->len,PacketP->len );
-		rio_dprintk (RIO_DEBUG_CMD, "PACKET information: Control	 0x%x (%d)\n", PacketP->control, PacketP->control);
-		rio_dprintk (RIO_DEBUG_CMD, "PACKET information: Check	   0x%x (%d)\n", PacketP->csum, PacketP->csum );
-		rio_dprintk (RIO_DEBUG_CMD, "COMMAND information: Host Port Number 0x%x, "
-					"Command Code 0x%x\n", PktCmdP->PhbNum, PktCmdP->Command );
+		rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Destination 0x%x:0x%x\n", PacketP->dest_unit, PacketP->dest_port);
+		rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Source	  0x%x:0x%x\n", PacketP->src_unit, PacketP->src_port);
+		rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Length	  0x%x (%d)\n", PacketP->len, PacketP->len);
+		rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Control	 0x%x (%d)\n", PacketP->control, PacketP->control);
+		rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Check	   0x%x (%d)\n", PacketP->csum, PacketP->csum);
+		rio_dprintk(RIO_DEBUG_CMD, "COMMAND information: Host Port Number 0x%x, " "Command Code 0x%x\n", PktCmdP->PhbNum, PktCmdP->Command);
 		return TRUE;
 	}
-
 #ifdef CHECK
-	CheckSysPort( SysPort );
+	CheckSysPort(SysPort);
 #endif
-	PortP = p->RIOPortp[ SysPort ];
+	PortP = p->RIOPortp[SysPort];
 	rio_spin_lock_irqsave(&PortP->portSem, flags);
-	switch( RBYTE(PktCmdP->Command) ) {
-		case BREAK_RECEIVED:
-			rio_dprintk (RIO_DEBUG_CMD, "Received a break!\n");
-			/* If the current line disc. is not multi-threading and
-	   			the current processor is not the default, reset rup_intr
-	   			and return FALSE to ensure that the command packet is
-	   			not freed. */
-			/* Call tmgr HANGUP HERE */
-			/* Fix this later when every thing works !!!! RAMRAJ */
-			gs_got_break (&PortP->gs);
+	switch (RBYTE(PktCmdP->Command)) {
+	case BREAK_RECEIVED:
+		rio_dprintk(RIO_DEBUG_CMD, "Received a break!\n");
+		/* If the current line disc. is not multi-threading and
+		   the current processor is not the default, reset rup_intr
+		   and return FALSE to ensure that the command packet is
+		   not freed. */
+		/* Call tmgr HANGUP HERE */
+		/* Fix this later when every thing works !!!! RAMRAJ */
+		gs_got_break(&PortP->gs);
+		break;
+
+	case COMPLETE:
+		rio_dprintk(RIO_DEBUG_CMD, "Command complete on phb %d host %d\n", RBYTE(PktCmdP->PhbNum), HostP - p->RIOHosts);
+		subCommand = 1;
+		switch (RBYTE(PktCmdP->SubCommand)) {
+		case MEMDUMP:
+			rio_dprintk(RIO_DEBUG_CMD, "Memory dump cmd (0x%x) from addr 0x%x\n", RBYTE(PktCmdP->SubCommand), RWORD(PktCmdP->SubAddr));
 			break;
+		case READ_REGISTER:
+			rio_dprintk(RIO_DEBUG_CMD, "Read register (0x%x)\n", RWORD(PktCmdP->SubAddr));
+			p->CdRegister = (RBYTE(PktCmdP->ModemStatus) & MSVR1_HOST);
+			break;
+		default:
+			subCommand = 0;
+			break;
+		}
+		if (subCommand)
+			break;
+		rio_dprintk(RIO_DEBUG_CMD, "New status is 0x%x was 0x%x\n", RBYTE(PktCmdP->PortStatus), PortP->PortState);
+		if (PortP->PortState != RBYTE(PktCmdP->PortStatus)) {
+			rio_dprintk(RIO_DEBUG_CMD, "Mark status & wakeup\n");
+			PortP->PortState = RBYTE(PktCmdP->PortStatus);
+			/* What should we do here ...
+			   wakeup( &PortP->PortState );
+			 */
+		} else
+			rio_dprintk(RIO_DEBUG_CMD, "No change\n");
 
-		case COMPLETE:
-			rio_dprintk (RIO_DEBUG_CMD, "Command complete on phb %d host %d\n",
-			     RBYTE(PktCmdP->PhbNum), HostP-p->RIOHosts);
-			subCommand = 1;
-			switch (RBYTE(PktCmdP->SubCommand)) {
-				case MEMDUMP :
-			rio_dprintk (RIO_DEBUG_CMD, "Memory dump cmd (0x%x) from addr 0x%x\n",
-				     RBYTE(PktCmdP->SubCommand), RWORD(PktCmdP->SubAddr));
-					break;
-				case READ_REGISTER :
-			rio_dprintk (RIO_DEBUG_CMD, "Read register (0x%x)\n", RWORD(PktCmdP->SubAddr));
-					p->CdRegister = (RBYTE(PktCmdP->ModemStatus) & MSVR1_HOST);
-					break;
-				default :
-					subCommand = 0;
-				break;
-			}
-			if (subCommand)
-				break;
-			rio_dprintk (RIO_DEBUG_CMD, "New status is 0x%x was 0x%x\n",
-				     RBYTE(PktCmdP->PortStatus),PortP->PortState);
-			if (PortP->PortState != RBYTE(PktCmdP->PortStatus)) {
-				rio_dprintk (RIO_DEBUG_CMD, "Mark status & wakeup\n");
-				PortP->PortState = RBYTE(PktCmdP->PortStatus);
-				/* What should we do here ...
-				wakeup( &PortP->PortState );
-				*/
-		} else 
-			rio_dprintk (RIO_DEBUG_CMD, "No change\n");
-
-			/* FALLTHROUGH */
-		case MODEM_STATUS:
+		/* FALLTHROUGH */
+	case MODEM_STATUS:
+		/*
+		 ** Knock out the tbusy and tstop bits, as these are not relevant
+		 ** to the check for modem status change (they're just there because
+		 ** it's a convenient place to put them!).
+		 */
+		ReportedModemStatus = RBYTE(PktCmdP->ModemStatus);
+		if ((PortP->ModemState & MSVR1_HOST) == (ReportedModemStatus & MSVR1_HOST)) {
+			rio_dprintk(RIO_DEBUG_CMD, "Modem status unchanged 0x%x\n", PortP->ModemState);
 			/*
-			** Knock out the tbusy and tstop bits, as these are not relevant
-			** to the check for modem status change (they're just there because
-			** it's a convenient place to put them!).
-			*/
-			ReportedModemStatus = RBYTE(PktCmdP->ModemStatus);
-			if ((PortP->ModemState & MSVR1_HOST) ==
-					(ReportedModemStatus & MSVR1_HOST)) {
-				rio_dprintk (RIO_DEBUG_CMD, "Modem status unchanged 0x%x\n", PortP->ModemState);
-				/*
-				** Update ModemState just in case tbusy or tstop states have
-				** changed.
-				*/
-				PortP->ModemState = ReportedModemStatus;
-			}
-			else {
-				rio_dprintk (RIO_DEBUG_CMD, "Modem status change from 0x%x to 0x%x\n",
-				     PortP->ModemState, ReportedModemStatus);
-				PortP->ModemState = ReportedModemStatus;
+			 ** Update ModemState just in case tbusy or tstop states have
+			 ** changed.
+			 */
+			PortP->ModemState = ReportedModemStatus;
+		} else {
+			rio_dprintk(RIO_DEBUG_CMD, "Modem status change from 0x%x to 0x%x\n", PortP->ModemState, ReportedModemStatus);
+			PortP->ModemState = ReportedModemStatus;
 #ifdef MODEM_SUPPORT
-				if ( PortP->Mapped ) {
+			if (PortP->Mapped) {
 				/***********************************************************\
 				*************************************************************
 				***													   ***
@@ -525,68 +501,67 @@
 				*************************************************************
 				\***********************************************************/
 				/*
-				** If the device is a modem, then check the modem
-				** carrier.
-				*/
+				 ** If the device is a modem, then check the modem
+				 ** carrier.
+				 */
 				if (PortP->gs.tty == NULL)
 					break;
 				if (PortP->gs.tty->termios == NULL)
 					break;
-			  
-				if (!(PortP->gs.tty->termios->c_cflag & CLOCAL) &&
-				((PortP->State & (RIO_MOPEN|RIO_WOPEN)))) {
 
-					rio_dprintk (RIO_DEBUG_CMD, "Is there a Carrier?\n");
-			/*
-			** Is there a carrier?
-			*/
-					if ( PortP->ModemState & MSVR1_CD ) {
-			/*
-			** Has carrier just appeared?
-			*/
+				if (!(PortP->gs.tty->termios->c_cflag & CLOCAL) && ((PortP->State & (RIO_MOPEN | RIO_WOPEN)))) {
+
+					rio_dprintk(RIO_DEBUG_CMD, "Is there a Carrier?\n");
+					/*
+					 ** Is there a carrier?
+					 */
+					if (PortP->ModemState & MSVR1_CD) {
+						/*
+						 ** Has carrier just appeared?
+						 */
 						if (!(PortP->State & RIO_CARR_ON)) {
-							rio_dprintk (RIO_DEBUG_CMD, "Carrier just came up.\n");
+							rio_dprintk(RIO_DEBUG_CMD, "Carrier just came up.\n");
 							PortP->State |= RIO_CARR_ON;
-				/*
-				** wakeup anyone in WOPEN
-				*/
-							if (PortP->State & (PORT_ISOPEN | RIO_WOPEN) )
-								wake_up_interruptible (&PortP->gs.open_wait);
+							/*
+							 ** wakeup anyone in WOPEN
+							 */
+							if (PortP->State & (PORT_ISOPEN | RIO_WOPEN))
+								wake_up_interruptible(&PortP->gs.open_wait);
 #ifdef STATS
-				PortP->Stat.ModemOnCnt++;
+							PortP->Stat.ModemOnCnt++;
 #endif
-			}
+						}
 					} else {
-			/*
-			** Has carrier just dropped?
-			*/
+						/*
+						 ** Has carrier just dropped?
+						 */
 						if (PortP->State & RIO_CARR_ON) {
-							if (PortP->State & (PORT_ISOPEN|RIO_WOPEN|RIO_MOPEN))
-								tty_hangup (PortP->gs.tty);
+							if (PortP->State & (PORT_ISOPEN | RIO_WOPEN | RIO_MOPEN))
+								tty_hangup(PortP->gs.tty);
 							PortP->State &= ~RIO_CARR_ON;
-							rio_dprintk (RIO_DEBUG_CMD, "Carrirer just went down\n");
+							rio_dprintk(RIO_DEBUG_CMD, "Carrirer just went down\n");
 #ifdef STATS
-				PortP->Stat.ModemOffCnt++;
+							PortP->Stat.ModemOffCnt++;
 #endif
+						}
+					}
+				}
 			}
-			}
-		}
-		}
 #endif
-			}
-			break;
+		}
+		break;
 
-		default:
-			rio_dprintk (RIO_DEBUG_CMD, "Unknown command %d on CMD_RUP of host %d\n",
-			     RBYTE(PktCmdP->Command),HostP-p->RIOHosts);
-			break;
+	default:
+		rio_dprintk(RIO_DEBUG_CMD, "Unknown command %d on CMD_RUP of host %d\n", RBYTE(PktCmdP->Command), HostP - p->RIOHosts);
+		break;
 	}
 	rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 
-	func_exit ();
+	func_exit();
 
 	return TRUE;
 }
+
 /*
 ** The command mechanism:
 **	Each rup has a chain of commands associated with it.
@@ -600,12 +575,11 @@
 /*
 ** Allocate an empty command block.
 */
-struct CmdBlk *
-RIOGetCmdBlk(void)
+struct CmdBlk *RIOGetCmdBlk(void)
 {
 	struct CmdBlk *CmdBlkP;
 
-	CmdBlkP = (struct CmdBlk *)sysbrk(sizeof(struct CmdBlk));
+	CmdBlkP = (struct CmdBlk *) sysbrk(sizeof(struct CmdBlk));
 	if (CmdBlkP)
 		bzero(CmdBlkP, sizeof(struct CmdBlk));
 
@@ -615,31 +589,29 @@
 /*
 ** Return a block to the head of the free list.
 */
-void
-RIOFreeCmdBlk(struct CmdBlk *CmdBlkP)
+void RIOFreeCmdBlk(struct CmdBlk *CmdBlkP)
 {
-	sysfree((void *)CmdBlkP, sizeof(struct CmdBlk));
+	sysfree((void *) CmdBlkP, sizeof(struct CmdBlk));
 }
 
 /*
 ** attach a command block to the list of commands to be performed for
 ** a given rup.
 */
-int
-RIOQueueCmdBlk(struct Host *HostP, uint Rup, struct CmdBlk *CmdBlkP)
+int RIOQueueCmdBlk(struct Host *HostP, uint Rup, struct CmdBlk *CmdBlkP)
 {
 	struct CmdBlk **Base;
 	struct UnixRup *UnixRupP;
 	unsigned long flags;
 
 #ifdef CHECK
-	CheckHostP( HostP );
-	CheckRup( Rup );
-	CheckCmdBlkP( CmdBlkP );
+	CheckHostP(HostP);
+	CheckRup(Rup);
+	CheckCmdBlkP(CmdBlkP);
 #endif
-	if ( Rup >= (ushort)(MAX_RUP+LINKS_PER_UNIT) ) {
-		rio_dprintk (RIO_DEBUG_CMD, "Illegal rup number %d in RIOQueueCmdBlk\n",Rup);
-		RIOFreeCmdBlk( CmdBlkP );
+	if (Rup >= (ushort) (MAX_RUP + LINKS_PER_UNIT)) {
+		rio_dprintk(RIO_DEBUG_CMD, "Illegal rup number %d in RIOQueueCmdBlk\n", Rup);
+		RIOFreeCmdBlk(CmdBlkP);
 		return RIO_FAIL;
 	}
 
@@ -648,57 +620,52 @@
 	rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
 
 	/*
-	** If the RUP is currently inactive, then put the request
-	** straight on the RUP....
-	*/
-	if ( (UnixRupP->CmdsWaitingP == NULL) && (UnixRupP->CmdPendingP == NULL) && 
-	     (RWORD(UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE ) &&
-		(CmdBlkP->PreFuncP ? (*CmdBlkP->PreFuncP)(CmdBlkP->PreArg,CmdBlkP)
-							:TRUE)) {
-		rio_dprintk (RIO_DEBUG_CMD, "RUP inactive-placing command straight on. Cmd byte is 0x%x\n",
-					     CmdBlkP->Packet.data[0]);
+	 ** If the RUP is currently inactive, then put the request
+	 ** straight on the RUP....
+	 */
+	if ((UnixRupP->CmdsWaitingP == NULL) && (UnixRupP->CmdPendingP == NULL) && (RWORD(UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE) && (CmdBlkP->PreFuncP ? (*CmdBlkP->PreFuncP) (CmdBlkP->PreArg, CmdBlkP)
+																	     : TRUE)) {
+		rio_dprintk(RIO_DEBUG_CMD, "RUP inactive-placing command straight on. Cmd byte is 0x%x\n", CmdBlkP->Packet.data[0]);
 
 		/*
-		** Whammy! blat that pack!
-		*/
-		HostP->Copy( (caddr_t)&CmdBlkP->Packet, 
-			RIO_PTR(HostP->Caddr, UnixRupP->RupP->txpkt ), sizeof(PKT) );
+		 ** Whammy! blat that pack!
+		 */
+		HostP->Copy((caddr_t) & CmdBlkP->Packet, RIO_PTR(HostP->Caddr, UnixRupP->RupP->txpkt), sizeof(PKT));
 
 		/*
-		** place command packet on the pending position.
-		*/
+		 ** place command packet on the pending position.
+		 */
 		UnixRupP->CmdPendingP = CmdBlkP;
 
 		/*
-		** set the command register
-		*/
-		WWORD(UnixRupP->RupP->txcontrol , TX_PACKET_READY);
+		 ** set the command register
+		 */
+		WWORD(UnixRupP->RupP->txcontrol, TX_PACKET_READY);
 
 		rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
 
 		return RIO_SUCCESS;
 	}
-	rio_dprintk (RIO_DEBUG_CMD, "RUP active - en-queing\n");
+	rio_dprintk(RIO_DEBUG_CMD, "RUP active - en-queing\n");
 
-	if ( UnixRupP->CmdsWaitingP != NULL)
-		rio_dprintk (RIO_DEBUG_CMD, "Rup active - command waiting\n");
-	if ( UnixRupP->CmdPendingP != NULL )
-		rio_dprintk (RIO_DEBUG_CMD, "Rup active - command pending\n");
-	if ( RWORD(UnixRupP->RupP->txcontrol) != TX_RUP_INACTIVE )
-		rio_dprintk (RIO_DEBUG_CMD, "Rup active - command rup not ready\n");
+	if (UnixRupP->CmdsWaitingP != NULL)
+		rio_dprintk(RIO_DEBUG_CMD, "Rup active - command waiting\n");
+	if (UnixRupP->CmdPendingP != NULL)
+		rio_dprintk(RIO_DEBUG_CMD, "Rup active - command pending\n");
+	if (RWORD(UnixRupP->RupP->txcontrol) != TX_RUP_INACTIVE)
+		rio_dprintk(RIO_DEBUG_CMD, "Rup active - command rup not ready\n");
 
 	Base = &UnixRupP->CmdsWaitingP;
 
-	rio_dprintk (RIO_DEBUG_CMD, "First try to queue cmdblk 0x%x at 0x%x\n", (int)CmdBlkP,(int)Base);
+	rio_dprintk(RIO_DEBUG_CMD, "First try to queue cmdblk 0x%x at 0x%x\n", (int) CmdBlkP, (int) Base);
 
-	while ( *Base ) {
-		rio_dprintk (RIO_DEBUG_CMD, "Command cmdblk 0x%x here\n", (int)(*Base));
+	while (*Base) {
+		rio_dprintk(RIO_DEBUG_CMD, "Command cmdblk 0x%x here\n", (int) (*Base));
 		Base = &((*Base)->NextP);
-		rio_dprintk (RIO_DEBUG_CMD, "Now try to queue cmd cmdblk 0x%x at 0x%x\n",
-					     (int)CmdBlkP,(int)Base);
+		rio_dprintk(RIO_DEBUG_CMD, "Now try to queue cmd cmdblk 0x%x at 0x%x\n", (int) CmdBlkP, (int) Base);
 	}
 
-	rio_dprintk (RIO_DEBUG_CMD, "Will queue cmdblk 0x%x at 0x%x\n",(int)CmdBlkP,(int)Base);
+	rio_dprintk(RIO_DEBUG_CMD, "Will queue cmdblk 0x%x at 0x%x\n", (int) CmdBlkP, (int) Base);
 
 	*Base = CmdBlkP;
 
@@ -713,8 +680,7 @@
 ** Here we go - if there is an empty rup, fill it!
 ** must be called at splrio() or higher.
 */
-void
-RIOPollHostCommands(struct rio_info *p, struct Host *HostP)
+void RIOPollHostCommands(struct rio_info *p, struct Host *HostP)
 {
 	register struct CmdBlk *CmdBlkP;
 	register struct UnixRup *UnixRupP;
@@ -723,262 +689,246 @@
 	unsigned long flags;
 
 
-	Rup = MAX_RUP+LINKS_PER_UNIT;
+	Rup = MAX_RUP + LINKS_PER_UNIT;
 
-	do {	/* do this loop for each RUP */
+	do {			/* do this loop for each RUP */
 		/*
-		** locate the rup we are processing & lock it
-		*/
+		 ** locate the rup we are processing & lock it
+		 */
 		UnixRupP = &HostP->UnixRups[--Rup];
 
 		spin_lock_irqsave(&UnixRupP->RupLock, flags);
 
 		/*
-		** First check for incoming commands:
-		*/
-		if ( RWORD(UnixRupP->RupP->rxcontrol) != RX_RUP_INACTIVE ) {
+		 ** First check for incoming commands:
+		 */
+		if (RWORD(UnixRupP->RupP->rxcontrol) != RX_RUP_INACTIVE) {
 			int FreeMe;
 
-			PacketP =(PKT *)RIO_PTR(HostP->Caddr,RWORD(UnixRupP->RupP->rxpkt));
+			PacketP = (PKT *) RIO_PTR(HostP->Caddr, RWORD(UnixRupP->RupP->rxpkt));
 
-			ShowPacket( DBG_CMD, PacketP );
+			ShowPacket(DBG_CMD, PacketP);
 
-			switch ( RBYTE(PacketP->dest_port) ) {
-				case BOOT_RUP:
-					rio_dprintk (RIO_DEBUG_CMD, "Incoming Boot %s packet '%x'\n", 
-						RBYTE(PacketP->len) & 0x80 ? "Command":"Data", 
-							     RBYTE(PacketP->data[0])); 
-					rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
-					FreeMe= RIOBootRup(p, Rup,HostP,PacketP);
-					rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
-					break;
+			switch (RBYTE(PacketP->dest_port)) {
+			case BOOT_RUP:
+				rio_dprintk(RIO_DEBUG_CMD, "Incoming Boot %s packet '%x'\n", RBYTE(PacketP->len) & 0x80 ? "Command" : "Data", RBYTE(PacketP->data[0]));
+				rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
+				FreeMe = RIOBootRup(p, Rup, HostP, PacketP);
+				rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
+				break;
 
-				case COMMAND_RUP:
-					/*
-					** Free the RUP lock as loss of carrier causes a
-					** ttyflush which will (eventually) call another
-					** routine that uses the RUP lock.
-					*/
-					rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
-					FreeMe= RIOCommandRup(p, Rup,HostP,PacketP);
-					if (PacketP->data[5] == MEMDUMP) {
-						rio_dprintk (RIO_DEBUG_CMD, "Memdump from 0x%x complete\n",
-								     *(ushort *) &(PacketP->data[6]));
-						HostP->Copy( (caddr_t)&(PacketP->data[8]), 
-								(caddr_t)p->RIOMemDump, 32 );
-					}
-					rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
-					break;
+			case COMMAND_RUP:
+				/*
+				 ** Free the RUP lock as loss of carrier causes a
+				 ** ttyflush which will (eventually) call another
+				 ** routine that uses the RUP lock.
+				 */
+				rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
+				FreeMe = RIOCommandRup(p, Rup, HostP, PacketP);
+				if (PacketP->data[5] == MEMDUMP) {
+					rio_dprintk(RIO_DEBUG_CMD, "Memdump from 0x%x complete\n", *(ushort *) & (PacketP->data[6]));
+					HostP->Copy((caddr_t) & (PacketP->data[8]), (caddr_t) p->RIOMemDump, 32);
+				}
+				rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
+				break;
 
-				case ROUTE_RUP:
-					rio_spin_unlock_irqrestore( &UnixRupP->RupLock, flags);
-					FreeMe = RIORouteRup(p, Rup, HostP, PacketP );
-					rio_spin_lock_irqsave( &UnixRupP->RupLock, flags );
-					break;
+			case ROUTE_RUP:
+				rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
+				FreeMe = RIORouteRup(p, Rup, HostP, PacketP);
+				rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
+				break;
 
-				default:
-					rio_dprintk (RIO_DEBUG_CMD, "Unknown RUP %d\n", RBYTE(PacketP->dest_port));
-					FreeMe = 1;
-					break;
+			default:
+				rio_dprintk(RIO_DEBUG_CMD, "Unknown RUP %d\n", RBYTE(PacketP->dest_port));
+				FreeMe = 1;
+				break;
 			}
 
-			if ( FreeMe ) {
-				rio_dprintk (RIO_DEBUG_CMD, "Free processed incoming command packet\n");
-				put_free_end(HostP,PacketP);
+			if (FreeMe) {
+				rio_dprintk(RIO_DEBUG_CMD, "Free processed incoming command packet\n");
+				put_free_end(HostP, PacketP);
 
-				WWORD(UnixRupP->RupP->rxcontrol , RX_RUP_INACTIVE);
+				WWORD(UnixRupP->RupP->rxcontrol, RX_RUP_INACTIVE);
 
-				if ( RWORD(UnixRupP->RupP->handshake)==PHB_HANDSHAKE_SET ) {
-					rio_dprintk (RIO_DEBUG_CMD, "Handshake rup %d\n",Rup);
-					WWORD(UnixRupP->RupP->handshake,
-						PHB_HANDSHAKE_SET|PHB_HANDSHAKE_RESET);
+				if (RWORD(UnixRupP->RupP->handshake) == PHB_HANDSHAKE_SET) {
+					rio_dprintk(RIO_DEBUG_CMD, "Handshake rup %d\n", Rup);
+					WWORD(UnixRupP->RupP->handshake, PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET);
 				}
 			}
 		}
 
 		/*
-		** IF a command was running on the port, 
-		** and it has completed, then tidy it up.
-		*/
-		if ( (CmdBlkP = UnixRupP->CmdPendingP) && /* ASSIGN! */
-		     (RWORD(UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) {
+		 ** IF a command was running on the port,
+		 ** and it has completed, then tidy it up.
+		 */
+		if ((CmdBlkP = UnixRupP->CmdPendingP) &&	/* ASSIGN! */
+		    (RWORD(UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) {
 			/*
-			** we are idle.
-			** there is a command in pending.
-			** Therefore, this command has finished.
-			** So, wakeup whoever is waiting for it (and tell them
-			** what happened).
-			*/
-			if ( CmdBlkP->Packet.dest_port == BOOT_RUP )
-				rio_dprintk (RIO_DEBUG_CMD, "Free Boot %s Command Block '%x'\n", 
-						CmdBlkP->Packet.len & 0x80 ? "Command":"Data", 
-							     CmdBlkP->Packet.data[0]);
+			 ** we are idle.
+			 ** there is a command in pending.
+			 ** Therefore, this command has finished.
+			 ** So, wakeup whoever is waiting for it (and tell them
+			 ** what happened).
+			 */
+			if (CmdBlkP->Packet.dest_port == BOOT_RUP)
+				rio_dprintk(RIO_DEBUG_CMD, "Free Boot %s Command Block '%x'\n", CmdBlkP->Packet.len & 0x80 ? "Command" : "Data", CmdBlkP->Packet.data[0]);
 
-			rio_dprintk (RIO_DEBUG_CMD, "Command 0x%x completed\n",(int)CmdBlkP);
+			rio_dprintk(RIO_DEBUG_CMD, "Command 0x%x completed\n", (int) CmdBlkP);
 
 			/*
-			** Clear the Rup lock to prevent mutual exclusion.
-			*/
-			if ( CmdBlkP->PostFuncP ) {
+			 ** Clear the Rup lock to prevent mutual exclusion.
+			 */
+			if (CmdBlkP->PostFuncP) {
 				rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
-				(*CmdBlkP->PostFuncP) (CmdBlkP->PostArg,CmdBlkP);
+				(*CmdBlkP->PostFuncP) (CmdBlkP->PostArg, CmdBlkP);
 				rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
 			}
 
 			/*
-			** ....clear the pending flag....
-			*/
+			 ** ....clear the pending flag....
+			 */
 			UnixRupP->CmdPendingP = NULL;
 
 			/*
-			** ....and return the command block to the freelist.
-			*/
-			RIOFreeCmdBlk( CmdBlkP );
+			 ** ....and return the command block to the freelist.
+			 */
+			RIOFreeCmdBlk(CmdBlkP);
 		}
 
 		/*
-		** If there is a command for this rup, and the rup
-		** is idle, then process the command
-		*/
-		if ( (CmdBlkP = UnixRupP->CmdsWaitingP) && /* ASSIGN! */
-			(UnixRupP->CmdPendingP == NULL) &&
-		     (RWORD(UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) {
+		 ** If there is a command for this rup, and the rup
+		 ** is idle, then process the command
+		 */
+		if ((CmdBlkP = UnixRupP->CmdsWaitingP) &&	/* ASSIGN! */
+		    (UnixRupP->CmdPendingP == NULL) && (RWORD(UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) {
 			/*
-			** if the pre-function is non-zero, call it.
-			** If it returns RIO_FAIL then don't
-			** send this command yet!
-			*/
+			 ** if the pre-function is non-zero, call it.
+			 ** If it returns RIO_FAIL then don't
+			 ** send this command yet!
+			 */
 #ifdef CHECK
-			CheckCmdBlkP (CmdBlkP);
+			CheckCmdBlkP(CmdBlkP);
 #endif
-			if ( !(CmdBlkP->PreFuncP ?
-				(*CmdBlkP->PreFuncP)(CmdBlkP->PreArg, CmdBlkP) : TRUE)) {
-				rio_dprintk (RIO_DEBUG_CMD, "Not ready to start command 0x%x\n",(int)CmdBlkP);
-			}
-			else {
-				rio_dprintk (RIO_DEBUG_CMD, "Start new command 0x%x Cmd byte is 0x%x\n",
-							     (int)CmdBlkP, CmdBlkP->Packet.data[0]);
+			if (!(CmdBlkP->PreFuncP ? (*CmdBlkP->PreFuncP) (CmdBlkP->PreArg, CmdBlkP) : TRUE)) {
+				rio_dprintk(RIO_DEBUG_CMD, "Not ready to start command 0x%x\n", (int) CmdBlkP);
+			} else {
+				rio_dprintk(RIO_DEBUG_CMD, "Start new command 0x%x Cmd byte is 0x%x\n", (int) CmdBlkP, CmdBlkP->Packet.data[0]);
 				/*
-				** Whammy! blat that pack!
-				*/
+				 ** Whammy! blat that pack!
+				 */
 #ifdef CHECK
-				CheckPacketP ((PKT *)RIO_PTR(HostP->Caddr, UnixRupP->RupP->txpkt));
+				CheckPacketP((PKT *) RIO_PTR(HostP->Caddr, UnixRupP->RupP->txpkt));
 #endif
-				HostP->Copy( (caddr_t)&CmdBlkP->Packet, 
-					RIO_PTR(HostP->Caddr, UnixRupP->RupP->txpkt), sizeof(PKT));
+				HostP->Copy((caddr_t) & CmdBlkP->Packet, RIO_PTR(HostP->Caddr, UnixRupP->RupP->txpkt), sizeof(PKT));
 
 				/*
-				** remove the command from the rup command queue...
-				*/
+				 ** remove the command from the rup command queue...
+				 */
 				UnixRupP->CmdsWaitingP = CmdBlkP->NextP;
 
 				/*
-				** ...and place it on the pending position.
-				*/
+				 ** ...and place it on the pending position.
+				 */
 				UnixRupP->CmdPendingP = CmdBlkP;
 
 				/*
-				** set the command register
-				*/
-				WWORD(UnixRupP->RupP->txcontrol,TX_PACKET_READY);
+				 ** set the command register
+				 */
+				WWORD(UnixRupP->RupP->txcontrol, TX_PACKET_READY);
 
 				/*
-				** the command block will be freed
-				** when the command has been processed.
-				*/
+				 ** the command block will be freed
+				 ** when the command has been processed.
+				 */
 			}
 		}
 		spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
-	} while ( Rup );
+	} while (Rup);
 }
 
-int
-RIOWFlushMark(int iPortP, struct CmdBlk *CmdBlkP)
+int RIOWFlushMark(int iPortP, struct CmdBlk *CmdBlkP)
 {
-	struct Port *	PortP = (struct Port *)iPortP;
+	struct Port *PortP = (struct Port *) iPortP;
 	unsigned long flags;
 
 	rio_spin_lock_irqsave(&PortP->portSem, flags);
 #ifdef CHECK
-	CheckPortP( PortP );
+	CheckPortP(PortP);
 #endif
 	PortP->WflushFlag++;
 	PortP->MagicFlags |= MAGIC_FLUSH;
 	rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-	return RIOUnUse( iPortP, CmdBlkP );
+	return RIOUnUse(iPortP, CmdBlkP);
 }
 
-int
-RIORFlushEnable(int iPortP, struct CmdBlk *CmdBlkP)
+int RIORFlushEnable(int iPortP, struct CmdBlk *CmdBlkP)
 {
-	struct Port *	PortP = (struct Port *)iPortP;
+	struct Port *PortP = (struct Port *) iPortP;
 	PKT *PacketP;
 	unsigned long flags;
 
 	rio_spin_lock_irqsave(&PortP->portSem, flags);
 
-	while ( can_remove_receive(&PacketP, PortP) ) {
+	while (can_remove_receive(&PacketP, PortP)) {
 		remove_receive(PortP);
-		ShowPacket(DBG_PROC, PacketP );
-		put_free_end( PortP->HostP, PacketP );
+		ShowPacket(DBG_PROC, PacketP);
+		put_free_end(PortP->HostP, PacketP);
 	}
 
-	if ( RWORD(PortP->PhbP->handshake)==PHB_HANDSHAKE_SET ) {
+	if (RWORD(PortP->PhbP->handshake) == PHB_HANDSHAKE_SET) {
 		/*
-		** MAGIC! (Basically, handshake the RX buffer, so that
-		** the RTAs upstream can be re-enabled.)
-		*/
-		rio_dprintk (RIO_DEBUG_CMD, "Util: Set RX handshake bit\n");
-		WWORD(PortP->PhbP->handshake, PHB_HANDSHAKE_SET|PHB_HANDSHAKE_RESET);
+		 ** MAGIC! (Basically, handshake the RX buffer, so that
+		 ** the RTAs upstream can be re-enabled.)
+		 */
+		rio_dprintk(RIO_DEBUG_CMD, "Util: Set RX handshake bit\n");
+		WWORD(PortP->PhbP->handshake, PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET);
 	}
 	rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-	return RIOUnUse( iPortP, CmdBlkP );
+	return RIOUnUse(iPortP, CmdBlkP);
 }
 
-int
-RIOUnUse(int iPortP, struct CmdBlk *CmdBlkP)
+int RIOUnUse(int iPortP, struct CmdBlk *CmdBlkP)
 {
-	struct Port *	PortP = (struct Port *)iPortP;
+	struct Port *PortP = (struct Port *) iPortP;
 	unsigned long flags;
 
 	rio_spin_lock_irqsave(&PortP->portSem, flags);
 
 #ifdef CHECK
-	CheckPortP( PortP );
+	CheckPortP(PortP);
 #endif
-	rio_dprintk (RIO_DEBUG_CMD, "Decrement in use count for port\n");
+	rio_dprintk(RIO_DEBUG_CMD, "Decrement in use count for port\n");
 
 	if (PortP->InUse) {
-		if ( --PortP->InUse != NOT_INUSE ) {
+		if (--PortP->InUse != NOT_INUSE) {
 			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 			return 0;
 		}
 	}
 	/*
-	** While PortP->InUse is set (i.e. a preemptive command has been sent to
-	** the RTA and is awaiting completion), any transmit data is prevented from
-	** being transferred from the write queue into the transmit packets
-	** (add_transmit) and no furthur transmit interrupt will be sent for that
-	** data. The next interrupt will occur up to 500ms later (RIOIntr is called
-	** twice a second as a saftey measure). This was the case when kermit was
-	** used to send data into a RIO port. After each packet was sent, TCFLSH
-	** was called to flush the read queue preemptively. PortP->InUse was
-	** incremented, thereby blocking the 6 byte acknowledgement packet
-	** transmitted back. This acknowledgment hung around for 500ms before
-	** being sent, thus reducing input performance substantially!.
-	** When PortP->InUse becomes NOT_INUSE, we must ensure that any data
-	** hanging around in the transmit buffer is sent immediately.
-	*/
+	 ** While PortP->InUse is set (i.e. a preemptive command has been sent to
+	 ** the RTA and is awaiting completion), any transmit data is prevented from
+	 ** being transferred from the write queue into the transmit packets
+	 ** (add_transmit) and no furthur transmit interrupt will be sent for that
+	 ** data. The next interrupt will occur up to 500ms later (RIOIntr is called
+	 ** twice a second as a saftey measure). This was the case when kermit was
+	 ** used to send data into a RIO port. After each packet was sent, TCFLSH
+	 ** was called to flush the read queue preemptively. PortP->InUse was
+	 ** incremented, thereby blocking the 6 byte acknowledgement packet
+	 ** transmitted back. This acknowledgment hung around for 500ms before
+	 ** being sent, thus reducing input performance substantially!.
+	 ** When PortP->InUse becomes NOT_INUSE, we must ensure that any data
+	 ** hanging around in the transmit buffer is sent immediately.
+	 */
 	WWORD(PortP->HostP->ParmMapP->tx_intr, 1);
 	/* What to do here ..
-	wakeup( (caddr_t)&(PortP->InUse) );
-	*/
+	   wakeup( (caddr_t)&(PortP->InUse) );
+	 */
 	rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 	return 0;
 }
 
-void
-ShowPacket(uint Flags, struct PKT *PacketP)
+void ShowPacket(uint Flags, struct PKT *PacketP)
 {
 }
 
diff --git a/drivers/char/rio/rioctrl.c b/drivers/char/rio/rioctrl.c
index b4d1a23..0b7700d 100644
--- a/drivers/char/rio/rioctrl.c
+++ b/drivers/char/rio/rioctrl.c
@@ -82,16 +82,16 @@
 #include "rioioctl.h"
 
 
-static struct LpbReq	 LpbReq;
-static struct RupReq	 RupReq;
-static struct PortReq	PortReq;
-static struct HostReq	HostReq;
+static struct LpbReq LpbReq;
+static struct RupReq RupReq;
+static struct PortReq PortReq;
+static struct HostReq HostReq;
 static struct HostDpRam HostDpRam;
 static struct DebugCtrl DebugCtrl;
-static struct Map		 MapEnt;
+static struct Map MapEnt;
 static struct PortSetup PortSetup;
-static struct DownLoad	DownLoad;
-static struct SendPack  SendPack;
+static struct DownLoad DownLoad;
+static struct SendPack SendPack;
 /* static struct StreamInfo	StreamInfo; */
 /* static char modemtable[RIO_PORTS]; */
 static struct SpecialRupCmd SpecialRupCmd;
@@ -99,18 +99,18 @@
 static struct portStats portStats;
 
 static struct SubCmdStruct {
-	ushort	Host;
-	ushort	Rup;
-	ushort	Port;
-	ushort	Addr;
+	ushort Host;
+	ushort Rup;
+	ushort Port;
+	ushort Addr;
 } SubCmd;
 
 struct PortTty {
-	uint		port;
-	struct ttystatics	Tty;
+	uint port;
+	struct ttystatics Tty;
 };
 
-static struct PortTty	PortTty;
+static struct PortTty PortTty;
 typedef struct ttystatics TERMIO;
 
 /*
@@ -121,267 +121,264 @@
 ** The RIOBootCodeUNKNOWN entry is there to politely tell the calling
 ** process to bog off.
 */
-static int 
-(*RIOBootTable[MAX_PRODUCT])(struct rio_info *, struct DownLoad *) =
-{
-/* 0 */	RIOBootCodeHOST,	/* Host Card */
-/* 1 */	RIOBootCodeRTA,		/* RTA */
+static int
+ (*RIOBootTable[MAX_PRODUCT]) (struct rio_info *, struct DownLoad *) = {
+					/* 0 */ RIOBootCodeHOST,
+					/* Host Card */
+					/* 1 */ RIOBootCodeRTA,
+					/* RTA */
 };
 
 #define drv_makedev(maj, min) ((((uint) maj & 0xff) << 8) | ((uint) min & 0xff))
 
-int copyin (int arg, caddr_t dp, int siz)
+int copyin(int arg, caddr_t dp, int siz)
 {
-  int rv;
+	int rv;
 
-  rio_dprintk (RIO_DEBUG_CTRL, "Copying %d bytes from user %p to %p.\n", siz, (void *)arg, dp);
-  rv = copy_from_user (dp, (void *)arg, siz);
-  if (rv) return COPYFAIL;
-  else return rv;
+	rio_dprintk(RIO_DEBUG_CTRL, "Copying %d bytes from user %p to %p.\n", siz, (void *) arg, dp);
+	rv = copy_from_user(dp, (void *) arg, siz);
+	if (rv)
+		return COPYFAIL;
+	else
+		return rv;
 }
 
-static int copyout (caddr_t dp, int arg, int siz)
+static int copyout(caddr_t dp, int arg, int siz)
 {
-  int rv;
+	int rv;
 
-  rio_dprintk (RIO_DEBUG_CTRL, "Copying %d bytes to user %p from %p.\n", siz, (void *)arg, dp);
-  rv = copy_to_user ((void *)arg, dp, siz);
-  if (rv) return COPYFAIL;
-  else return rv;
+	rio_dprintk(RIO_DEBUG_CTRL, "Copying %d bytes to user %p from %p.\n", siz, (void *) arg, dp);
+	rv = copy_to_user((void *) arg, dp, siz);
+	if (rv)
+		return COPYFAIL;
+	else
+		return rv;
 }
 
-int
-riocontrol(p, dev, cmd, arg, su)
-struct rio_info	* p;
-dev_t		dev;
-int		cmd;
-caddr_t		arg;
-int		su;
+int riocontrol(p, dev, cmd, arg, su)
+struct rio_info *p;
+dev_t dev;
+int cmd;
+caddr_t arg;
+int su;
 {
-	uint	Host;	/* leave me unsigned! */
-	uint	port;	/* and me! */
-	struct Host	*HostP;
-	ushort	loop;
-	int		Entry;
-	struct Port	*PortP;
-	PKT	*PacketP;
-	int		retval = 0;
+	uint Host;		/* leave me unsigned! */
+	uint port;		/* and me! */
+	struct Host *HostP;
+	ushort loop;
+	int Entry;
+	struct Port *PortP;
+	PKT *PacketP;
+	int retval = 0;
 	unsigned long flags;
-	
-	func_enter ();
-	
+
+	func_enter();
+
 	/* Confuse the compiler to think that we've initialized these */
-	Host=0;
+	Host = 0;
 	PortP = NULL;
 
-	rio_dprintk (RIO_DEBUG_CTRL, "control ioctl cmd: 0x%x arg: 0x%x\n", cmd, (int)arg);
+	rio_dprintk(RIO_DEBUG_CTRL, "control ioctl cmd: 0x%x arg: 0x%x\n", cmd, (int) arg);
 
 	switch (cmd) {
 		/*
-		** RIO_SET_TIMER
-		**
-		** Change the value of the host card interrupt timer.
-		** If the host card number is -1 then all host cards are changed
-		** otherwise just the specified host card will be changed.
-		*/
-		case RIO_SET_TIMER:
-			rio_dprintk (RIO_DEBUG_CTRL, "RIO_SET_TIMER to %dms\n", (uint)arg);
-			{
-				int host, value;
-				host = (uint)arg >> 16;
-				value = (uint)arg & 0x0000ffff;
-				if (host == -1) {
-					for (host = 0; host < p->RIONumHosts; host++) {
-						if (p->RIOHosts[host].Flags == RC_RUNNING) {
-							WWORD(p->RIOHosts[host].ParmMapP->timer , value);
-						}
-					}
-				} else if (host >= p->RIONumHosts) {
-					return -EINVAL;
-				} else {
-					if ( p->RIOHosts[host].Flags == RC_RUNNING ) {
-						WWORD(p->RIOHosts[host].ParmMapP->timer , value);
+		 ** RIO_SET_TIMER
+		 **
+		 ** Change the value of the host card interrupt timer.
+		 ** If the host card number is -1 then all host cards are changed
+		 ** otherwise just the specified host card will be changed.
+		 */
+	case RIO_SET_TIMER:
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_TIMER to %dms\n", (uint) arg);
+		{
+			int host, value;
+			host = (uint) arg >> 16;
+			value = (uint) arg & 0x0000ffff;
+			if (host == -1) {
+				for (host = 0; host < p->RIONumHosts; host++) {
+					if (p->RIOHosts[host].Flags == RC_RUNNING) {
+						WWORD(p->RIOHosts[host].ParmMapP->timer, value);
 					}
 				}
-			}
-			return 0;
-
-		case RIO_IDENTIFY_DRIVER:
-			/*
-			** 15.10.1998 ARG - ESIL 0760 part fix
-			** Added driver ident string output.
-			**
-#ifndef __THIS_RELEASE__
-#warning Driver Version string not defined !
-#endif
-			cprintf("%s %s %s %s\n",
-				RIO_DRV_STR,
-				__THIS_RELEASE__,
-				__DATE__, __TIME__ );
-
-			return 0;
-
-		case RIO_DISPLAY_HOST_CFG:
-			**
-			** 15.10.1998 ARG - ESIL 0760 part fix
-			** Added driver host card ident string output.
-			**
-			** Note that the only types currently supported
-			** are ISA and PCI. Also this driver does not
-			** (yet) distinguish between the Old PCI card
-			** and the Jet PCI card. In fact I think this
-			** driver only supports JET PCI !
-			**
-
-			for (Host = 0; Host < p->RIONumHosts; Host++)
-			{
-				HostP = &(p->RIOHosts[Host]);
-
-				switch ( HostP->Type )
-				{
-				    case RIO_AT :
-					strcpy( host_type, RIO_AT_HOST_STR );
-					break;
-
-				    case RIO_PCI :
-					strcpy( host_type, RIO_PCI_HOST_STR );
-					break;
-
-				    default :
-					strcpy( host_type, "Unknown" );
-					break;
-				}
-
-				cprintf(
-				  "RIO Host %d - Type:%s Addr:%X IRQ:%d\n",
-					Host, host_type,
-					(uint)HostP->PaddrP,
-					(int)HostP->Ivec - 32  );
-			}
-			return 0;
-			**
-			*/
-
-		case RIO_FOAD_RTA:
-			rio_dprintk (RIO_DEBUG_CTRL, "RIO_FOAD_RTA\n");
-			return RIOCommandRta(p, (uint)arg, RIOFoadRta);
-
-		case RIO_ZOMBIE_RTA:
-			rio_dprintk (RIO_DEBUG_CTRL, "RIO_ZOMBIE_RTA\n");
-			return RIOCommandRta(p, (uint)arg, RIOZombieRta);
-
-		case RIO_IDENTIFY_RTA:
-			rio_dprintk (RIO_DEBUG_CTRL, "RIO_IDENTIFY_RTA\n");
-			return RIOIdentifyRta(p, arg);
-
-		case RIO_KILL_NEIGHBOUR:
-			rio_dprintk (RIO_DEBUG_CTRL, "RIO_KILL_NEIGHBOUR\n");
-			return RIOKillNeighbour(p, arg);
-
-		case SPECIAL_RUP_CMD:
-			{
-				struct CmdBlk *CmdBlkP;
-
-				rio_dprintk (RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD\n");
-				if (copyin((int)arg, (caddr_t)&SpecialRupCmd, 
-							sizeof(SpecialRupCmd)) == COPYFAIL ) {
-					rio_dprintk (RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD copy failed\n");
-					p->RIOError.Error = COPYIN_FAILED;
-		 			return -EFAULT;
-				}
-				CmdBlkP = RIOGetCmdBlk();
-				if ( !CmdBlkP ) {
-					rio_dprintk (RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD GetCmdBlk failed\n");
-					return -ENXIO;
-				}
-				CmdBlkP->Packet = SpecialRupCmd.Packet;
-				if ( SpecialRupCmd.Host >= p->RIONumHosts )
-					SpecialRupCmd.Host = 0;
-					rio_dprintk (RIO_DEBUG_CTRL, "Queue special rup command for host %d rup %d\n",
-						SpecialRupCmd.Host, SpecialRupCmd.RupNum);
-					if (RIOQueueCmdBlk(&p->RIOHosts[SpecialRupCmd.Host], 
-							SpecialRupCmd.RupNum, CmdBlkP) == RIO_FAIL) {
-						cprintf("FAILED TO QUEUE SPECIAL RUP COMMAND\n");
-					}
-					return 0;
-				}
-
-			case RIO_DEBUG_MEM:
-#ifdef DEBUG_MEM_SUPPORT
-RIO_DEBUG_CTRL, 				if (su)
-					return rio_RIODebugMemory(RIO_DEBUG_CTRL, arg);
-				else
-#endif
-					return -EPERM;
-
-			case RIO_ALL_MODEM:
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_ALL_MODEM\n");
-				p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
+			} else if (host >= p->RIONumHosts) {
 				return -EINVAL;
-
-			case RIO_GET_TABLE:
-				/*
-				** Read the routing table from the device driver to user space
-				*/
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_GET_TABLE\n");
-
-				if ((retval = RIOApel(p)) != 0)
-		 			return retval;
-
-				if (copyout((caddr_t)p->RIOConnectTable, (int)arg,
-						TOTAL_MAP_ENTRIES*sizeof(struct Map)) == COPYFAIL) {
-		 			rio_dprintk (RIO_DEBUG_CTRL, "RIO_GET_TABLE copy failed\n");
-		 			p->RIOError.Error = COPYOUT_FAILED;
-		 			return -EFAULT;
+			} else {
+				if (p->RIOHosts[host].Flags == RC_RUNNING) {
+					WWORD(p->RIOHosts[host].ParmMapP->timer, value);
 				}
+			}
+		}
+		return 0;
 
-				{
-					int entry;
-					rio_dprintk (RIO_DEBUG_CTRL,  "*****\nMAP ENTRIES\n");
-					for ( entry=0; entry<TOTAL_MAP_ENTRIES; entry++ )
-					{
-					  if ((p->RIOConnectTable[entry].ID == 0) &&
-					      (p->RIOConnectTable[entry].HostUniqueNum == 0) &&
-					      (p->RIOConnectTable[entry].RtaUniqueNum == 0)) continue;
-					      
-						rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum );
-						rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum );
-						rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID );
-						rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2 );
-						rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.Flags = 0x%x\n", entry, (int)p->RIOConnectTable[entry].Flags );
-						rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.SysPort = 0x%x\n", entry, (int)p->RIOConnectTable[entry].SysPort );
-						rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.Top[0].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Unit );
-						rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.Top[0].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Link );
-						rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.Top[1].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Unit );
-						rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.Top[1].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Link );
-						rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.Top[2].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Unit );
-						rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.Top[2].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Link );
-						rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.Top[3].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Unit );
-						rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.Top[4].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Link );
-						rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name );
-					}
-					rio_dprintk (RIO_DEBUG_CTRL,  "*****\nEND MAP ENTRIES\n");
-				}
-				p->RIOQuickCheck = NOT_CHANGED;	/* a table has been gotten */
-				return 0;
+	case RIO_IDENTIFY_DRIVER:
+		/*
+		 ** 15.10.1998 ARG - ESIL 0760 part fix
+		 ** Added driver ident string output.
+		 **
+		 #ifndef __THIS_RELEASE__
+		 #warning Driver Version string not defined !
+		 #endif
+		 cprintf("%s %s %s %s\n",
+		 RIO_DRV_STR,
+		 __THIS_RELEASE__,
+		 __DATE__, __TIME__ );
 
-			case RIO_PUT_TABLE:
-				/*
-				** Write the routing table to the device driver from user space
-				*/
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_PUT_TABLE\n");
+		 return 0;
 
-				if ( !su ) {
-		 			rio_dprintk (RIO_DEBUG_CTRL, "RIO_PUT_TABLE !Root\n");
-		 			p->RIOError.Error = NOT_SUPER_USER;
-		 			return -EPERM;
-				}
-				if ( copyin((int)arg, (caddr_t)&p->RIOConnectTable[0], 
-					TOTAL_MAP_ENTRIES*sizeof(struct Map) ) == COPYFAIL ) {
-		 			rio_dprintk (RIO_DEBUG_CTRL, "RIO_PUT_TABLE copy failed\n");
-		 			p->RIOError.Error = COPYIN_FAILED;
-		 			return -EFAULT;
-				}
+		 case RIO_DISPLAY_HOST_CFG:
+		 **
+		 ** 15.10.1998 ARG - ESIL 0760 part fix
+		 ** Added driver host card ident string output.
+		 **
+		 ** Note that the only types currently supported
+		 ** are ISA and PCI. Also this driver does not
+		 ** (yet) distinguish between the Old PCI card
+		 ** and the Jet PCI card. In fact I think this
+		 ** driver only supports JET PCI !
+		 **
+
+		 for (Host = 0; Host < p->RIONumHosts; Host++)
+		 {
+		 HostP = &(p->RIOHosts[Host]);
+
+		 switch ( HostP->Type )
+		 {
+		 case RIO_AT :
+		 strcpy( host_type, RIO_AT_HOST_STR );
+		 break;
+
+		 case RIO_PCI :
+		 strcpy( host_type, RIO_PCI_HOST_STR );
+		 break;
+
+		 default :
+		 strcpy( host_type, "Unknown" );
+		 break;
+		 }
+
+		 cprintf(
+		 "RIO Host %d - Type:%s Addr:%X IRQ:%d\n",
+		 Host, host_type,
+		 (uint)HostP->PaddrP,
+		 (int)HostP->Ivec - 32  );
+		 }
+		 return 0;
+		 **
+		 */
+
+	case RIO_FOAD_RTA:
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_FOAD_RTA\n");
+		return RIOCommandRta(p, (uint) arg, RIOFoadRta);
+
+	case RIO_ZOMBIE_RTA:
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_ZOMBIE_RTA\n");
+		return RIOCommandRta(p, (uint) arg, RIOZombieRta);
+
+	case RIO_IDENTIFY_RTA:
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_IDENTIFY_RTA\n");
+		return RIOIdentifyRta(p, arg);
+
+	case RIO_KILL_NEIGHBOUR:
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_KILL_NEIGHBOUR\n");
+		return RIOKillNeighbour(p, arg);
+
+	case SPECIAL_RUP_CMD:
+		{
+			struct CmdBlk *CmdBlkP;
+
+			rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD\n");
+			if (copyin((int) arg, (caddr_t) & SpecialRupCmd, sizeof(SpecialRupCmd)) == COPYFAIL) {
+				rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD copy failed\n");
+				p->RIOError.Error = COPYIN_FAILED;
+				return -EFAULT;
+			}
+			CmdBlkP = RIOGetCmdBlk();
+			if (!CmdBlkP) {
+				rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD GetCmdBlk failed\n");
+				return -ENXIO;
+			}
+			CmdBlkP->Packet = SpecialRupCmd.Packet;
+			if (SpecialRupCmd.Host >= p->RIONumHosts)
+				SpecialRupCmd.Host = 0;
+			rio_dprintk(RIO_DEBUG_CTRL, "Queue special rup command for host %d rup %d\n", SpecialRupCmd.Host, SpecialRupCmd.RupNum);
+			if (RIOQueueCmdBlk(&p->RIOHosts[SpecialRupCmd.Host], SpecialRupCmd.RupNum, CmdBlkP) == RIO_FAIL) {
+				cprintf("FAILED TO QUEUE SPECIAL RUP COMMAND\n");
+			}
+			return 0;
+		}
+
+	case RIO_DEBUG_MEM:
+#ifdef DEBUG_MEM_SUPPORT
+		RIO_DEBUG_CTRL, if (su)
+			return rio_RIODebugMemory(RIO_DEBUG_CTRL, arg);
+		else
+#endif
+			return -EPERM;
+
+	case RIO_ALL_MODEM:
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_ALL_MODEM\n");
+		p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
+		return -EINVAL;
+
+	case RIO_GET_TABLE:
+		/*
+		 ** Read the routing table from the device driver to user space
+		 */
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE\n");
+
+		if ((retval = RIOApel(p)) != 0)
+			return retval;
+
+		if (copyout((caddr_t) p->RIOConnectTable, (int) arg, TOTAL_MAP_ENTRIES * sizeof(struct Map)) == COPYFAIL) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE copy failed\n");
+			p->RIOError.Error = COPYOUT_FAILED;
+			return -EFAULT;
+		}
+
+		{
+			int entry;
+			rio_dprintk(RIO_DEBUG_CTRL, "*****\nMAP ENTRIES\n");
+			for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
+				if ((p->RIOConnectTable[entry].ID == 0) && (p->RIOConnectTable[entry].HostUniqueNum == 0) && (p->RIOConnectTable[entry].RtaUniqueNum == 0))
+					continue;
+
+				rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum);
+				rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum);
+				rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID);
+				rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2);
+				rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Flags = 0x%x\n", entry, (int) p->RIOConnectTable[entry].Flags);
+				rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.SysPort = 0x%x\n", entry, (int) p->RIOConnectTable[entry].SysPort);
+				rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Unit);
+				rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Link);
+				rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Unit);
+				rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Link);
+				rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Unit);
+				rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Link);
+				rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[3].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Unit);
+				rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[4].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Link);
+				rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name);
+			}
+			rio_dprintk(RIO_DEBUG_CTRL, "*****\nEND MAP ENTRIES\n");
+		}
+		p->RIOQuickCheck = NOT_CHANGED;	/* a table has been gotten */
+		return 0;
+
+	case RIO_PUT_TABLE:
+		/*
+		 ** Write the routing table to the device driver from user space
+		 */
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE\n");
+
+		if (!su) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE !Root\n");
+			p->RIOError.Error = NOT_SUPER_USER;
+			return -EPERM;
+		}
+		if (copyin((int) arg, (caddr_t) & p->RIOConnectTable[0], TOTAL_MAP_ENTRIES * sizeof(struct Map)) == COPYFAIL) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE copy failed\n");
+			p->RIOError.Error = COPYIN_FAILED;
+			return -EFAULT;
+		}
 /*
 ***********************************
 				{
@@ -409,1353 +406,1244 @@
 				}
 ***********************************
 */
-				return RIONewTable(p);
+		return RIONewTable(p);
 
-	 		case RIO_GET_BINDINGS :
-				/*
-				** Send bindings table, containing unique numbers of RTAs owned
-				** by this system to user space
-				*/
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_GET_BINDINGS\n");
+	case RIO_GET_BINDINGS:
+		/*
+		 ** Send bindings table, containing unique numbers of RTAs owned
+		 ** by this system to user space
+		 */
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS\n");
 
-				if ( !su )
-				{
-		 			rio_dprintk (RIO_DEBUG_CTRL, "RIO_GET_BINDINGS !Root\n");
-		 			p->RIOError.Error = NOT_SUPER_USER;
-		 			return -EPERM;
-				}
-				if (copyout((caddr_t) p->RIOBindTab, (int)arg, 
-						(sizeof(ulong) * MAX_RTA_BINDINGS)) == COPYFAIL ) {
-		 			rio_dprintk (RIO_DEBUG_CTRL, "RIO_GET_BINDINGS copy failed\n");
-		 			p->RIOError.Error = COPYOUT_FAILED;
-		 			return -EFAULT;
-				}
-				return 0;
+		if (!su) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS !Root\n");
+			p->RIOError.Error = NOT_SUPER_USER;
+			return -EPERM;
+		}
+		if (copyout((caddr_t) p->RIOBindTab, (int) arg, (sizeof(ulong) * MAX_RTA_BINDINGS)) == COPYFAIL) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS copy failed\n");
+			p->RIOError.Error = COPYOUT_FAILED;
+			return -EFAULT;
+		}
+		return 0;
 
-	 		case RIO_PUT_BINDINGS :
+	case RIO_PUT_BINDINGS:
+		/*
+		 ** Receive a bindings table, containing unique numbers of RTAs owned
+		 ** by this system
+		 */
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS\n");
+
+		if (!su) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS !Root\n");
+			p->RIOError.Error = NOT_SUPER_USER;
+			return -EPERM;
+		}
+		if (copyin((int) arg, (caddr_t) & p->RIOBindTab[0], (sizeof(ulong) * MAX_RTA_BINDINGS)) == COPYFAIL) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS copy failed\n");
+			p->RIOError.Error = COPYIN_FAILED;
+			return -EFAULT;
+		}
+		return 0;
+
+	case RIO_BIND_RTA:
+		{
+			int EmptySlot = -1;
 			/*
-			** Receive a bindings table, containing unique numbers of RTAs owned
-			** by this system
-			*/
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS\n");
+			 ** Bind this RTA to host, so that it will be booted by
+			 ** host in 'boot owned RTAs' mode.
+			 */
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA\n");
 
-				if ( !su )
-				{
-		 			rio_dprintk (RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS !Root\n");
-		 			p->RIOError.Error = NOT_SUPER_USER;
-		 			return -EPERM;
-				}
-				if (copyin((int)arg, (caddr_t)&p->RIOBindTab[0], 
-						(sizeof(ulong) * MAX_RTA_BINDINGS))==COPYFAIL ) {
-		 			rio_dprintk (RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS copy failed\n");
-		 			p->RIOError.Error = COPYIN_FAILED;
-		 			return -EFAULT;
-				}
-				return 0;
-
-			case RIO_BIND_RTA :
-				{
-					int	EmptySlot = -1;
+			if (!su) {
+				rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA !Root\n");
+				p->RIOError.Error = NOT_SUPER_USER;
+				return -EPERM;
+			}
+			for (Entry = 0; Entry < MAX_RTA_BINDINGS; Entry++) {
+				if ((EmptySlot == -1) && (p->RIOBindTab[Entry] == 0L))
+					EmptySlot = Entry;
+				else if (p->RIOBindTab[Entry] == (int) arg) {
 					/*
-					** Bind this RTA to host, so that it will be booted by 
-					** host in 'boot owned RTAs' mode.
-					*/
-					rio_dprintk (RIO_DEBUG_CTRL, "RIO_BIND_RTA\n");
-
-					if ( !su ) {
-		 				rio_dprintk (RIO_DEBUG_CTRL, "RIO_BIND_RTA !Root\n");
-		 				p->RIOError.Error = NOT_SUPER_USER;
-		 				return -EPERM;
-					}
-					for (Entry = 0; Entry < MAX_RTA_BINDINGS; Entry++) {
-		 				if ((EmptySlot == -1) && (p->RIOBindTab[Entry] == 0L))
-							EmptySlot = Entry;
-		 				else if (p->RIOBindTab[Entry] == (int) arg) {
-							/*
-							** Already exists - delete
-							*/
-							p->RIOBindTab[Entry] = 0L;
-							rio_dprintk (RIO_DEBUG_CTRL, "Removing Rta %x from p->RIOBindTab\n",
-		 												(int) arg);
-							return 0;
-		 				}
-					}
-					/*
-					** Dosen't exist - add
-					*/
-					if (EmptySlot != -1) {
-		 				p->RIOBindTab[EmptySlot] = (int) arg;
-		 				rio_dprintk (RIO_DEBUG_CTRL, "Adding Rta %x to p->RIOBindTab\n",
-		  					(int) arg);
-					}
-					else {
-		 				rio_dprintk (RIO_DEBUG_CTRL, "p->RIOBindTab full! - Rta %x not added\n",
-		  					(int) arg);
-		 				return -ENOMEM;
-					}
+					 ** Already exists - delete
+					 */
+					p->RIOBindTab[Entry] = 0L;
+					rio_dprintk(RIO_DEBUG_CTRL, "Removing Rta %x from p->RIOBindTab\n", (int) arg);
 					return 0;
 				}
-
-			case RIO_RESUME :
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_RESUME\n");
-				port = (uint) arg;
-				if ((port < 0) || (port > 511)) {
-		 			rio_dprintk (RIO_DEBUG_CTRL, "RIO_RESUME: Bad port number %d\n", port);
-		 			p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
-		 			return -EINVAL;
-				}
-				PortP = p->RIOPortp[port];
-				if (!PortP->Mapped) {
-		 			rio_dprintk (RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not mapped\n", port);
-		 			p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
-		 			return -EINVAL;
-				}
-				if (!(PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
-					rio_dprintk (RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not open\n", port);
-		 			return -EINVAL;
-				}
-
-				rio_spin_lock_irqsave(&PortP->portSem, flags);
-				if (RIOPreemptiveCmd(p, (p->RIOPortp[port]), RESUME) == 
-										RIO_FAIL) {
-					rio_dprintk (RIO_DEBUG_CTRL, "RIO_RESUME failed\n");
-					rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-					return -EBUSY;
-				}
-				else {
-					rio_dprintk (RIO_DEBUG_CTRL, "RIO_RESUME: Port %d resumed\n", port);
-					PortP->State |= RIO_BUSY;
-				}
-				rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-				return retval;
-
-			case RIO_ASSIGN_RTA:
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA\n");
-				if ( !su ) {
-					rio_dprintk (RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA !Root\n");
-					p->RIOError.Error = NOT_SUPER_USER;
-					return -EPERM;
-				}
-				if (copyin((int)arg, (caddr_t)&MapEnt, sizeof(MapEnt))
-									== COPYFAIL) {
-					rio_dprintk (RIO_DEBUG_CTRL, "Copy from user space failed\n");
-					p->RIOError.Error = COPYIN_FAILED;
-					return -EFAULT;
-				}
-				return RIOAssignRta(p, &MapEnt);
-
-			case RIO_CHANGE_NAME:
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_CHANGE_NAME\n");
-				if ( !su ) {
-					rio_dprintk (RIO_DEBUG_CTRL, "RIO_CHANGE_NAME !Root\n");
-					p->RIOError.Error = NOT_SUPER_USER;
-					return -EPERM;
-				}
-				if (copyin((int)arg, (caddr_t)&MapEnt, sizeof(MapEnt))
-						== COPYFAIL) {
-					rio_dprintk (RIO_DEBUG_CTRL, "Copy from user space failed\n");
-					p->RIOError.Error = COPYIN_FAILED;
-					return -EFAULT;
-				}
-				return RIOChangeName(p, &MapEnt);
-
-			case RIO_DELETE_RTA:
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_DELETE_RTA\n");
-				if ( !su ) {
-		 			rio_dprintk (RIO_DEBUG_CTRL, "RIO_DELETE_RTA !Root\n");
-		 			p->RIOError.Error = NOT_SUPER_USER;
-		 			return -EPERM;
-				}
-				if (copyin((int)arg, (caddr_t)&MapEnt, sizeof(MapEnt))
-							== COPYFAIL ) {
-		 			rio_dprintk (RIO_DEBUG_CTRL, "Copy from data space failed\n");
-		 			p->RIOError.Error = COPYIN_FAILED;
-		 			return -EFAULT;
-				}
-				return RIODeleteRta(p, &MapEnt);
-
-			case RIO_QUICK_CHECK:
-				/*
-				** 09.12.1998 ARG - ESIL 0776 part fix
-				** A customer was using this to get the RTAs
-				** connect/disconnect status.
-				** RIOConCon() had been botched use RIOHalted
-				** to keep track of RTA connections and
-				** disconnections. That has been changed and
-				** RIORtaDisCons in the rio_info struct now
-				** does the job. So we need to return the value
-				** of RIORtaCons instead of RIOHalted.
-				**
-				if (copyout((caddr_t)&p->RIOHalted,(int)arg,
-							sizeof(uint))==COPYFAIL) {
-				**
-				*/
-
-				if (copyout((caddr_t)&p->RIORtaDisCons,(int)arg,
-							sizeof(uint))==COPYFAIL) {
-					p->RIOError.Error = COPYOUT_FAILED;
-					return -EFAULT;
-				}
-				return 0;
-
-			case RIO_LAST_ERROR:
-				if (copyout((caddr_t)&p->RIOError, (int)arg, 
-						sizeof(struct Error)) ==COPYFAIL )
-					return -EFAULT;
-				return 0;
-
-			case RIO_GET_LOG:
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_GET_LOG\n");
-#ifdef LOGGING
-				RIOGetLog(arg);
-				return 0;
-#else
-				return -EINVAL;
-#endif
-
-			case RIO_GET_MODTYPE:
-				if ( copyin( (int)arg, (caddr_t)&port, 
-									sizeof(uint)) == COPYFAIL )
-				{
-		 			p->RIOError.Error = COPYIN_FAILED;
-		 			return -EFAULT;
-				}
-				rio_dprintk (RIO_DEBUG_CTRL, "Get module type for port %d\n", port);
-				if ( port < 0 || port > 511 )
-				{
-		 			rio_dprintk (RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Bad port number %d\n", port);
-		 			p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
-		 			return -EINVAL;
-				}
-				PortP = (p->RIOPortp[port]);
-				if (!PortP->Mapped)
-				{
-		 			rio_dprintk (RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Port %d not mapped\n", port);
-		 			p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
-		 			return -EINVAL;
-				}
-				/*
-				** Return module type of port
-				*/
-				port = PortP->HostP->UnixRups[PortP->RupNum].ModTypes;
-				if (copyout((caddr_t)&port, (int)arg, 
-							sizeof(uint)) == COPYFAIL) {
-		 			p->RIOError.Error = COPYOUT_FAILED;
-		 			return -EFAULT;
-				}
-				return(0);
+			}
 			/*
-			** 02.03.1999 ARG - ESIL 0820 fix
-			** We are no longer using "Boot Mode", so these ioctls
-			** are not required :
-			**
-	 		case RIO_GET_BOOT_MODE :
-				rio_dprint(RIO_DEBUG_CTRL, ("Get boot mode - %x\n", p->RIOBootMode));
-				**
-				** Return boot state of system - BOOT_ALL, BOOT_OWN or BOOT_NONE
-				**
-				if (copyout((caddr_t)&p->RIOBootMode, (int)arg, 
-						sizeof(p->RIOBootMode)) == COPYFAIL) {
-		 			p->RIOError.Error = COPYOUT_FAILED;
-		 			return -EFAULT;
-				}
-				return(0);
-			
- 			case RIO_SET_BOOT_MODE :
-				p->RIOBootMode = (uint) arg;
-				rio_dprint(RIO_DEBUG_CTRL, ("Set boot mode to 0x%x\n", p->RIOBootMode));
-				return(0);
-			**
-			** End ESIL 0820 fix
-			*/
+			 ** Dosen't exist - add
+			 */
+			if (EmptySlot != -1) {
+				p->RIOBindTab[EmptySlot] = (int) arg;
+				rio_dprintk(RIO_DEBUG_CTRL, "Adding Rta %x to p->RIOBindTab\n", (int) arg);
+			} else {
+				rio_dprintk(RIO_DEBUG_CTRL, "p->RIOBindTab full! - Rta %x not added\n", (int) arg);
+				return -ENOMEM;
+			}
+			return 0;
+		}
 
-	 		case RIO_BLOCK_OPENS:
-				rio_dprintk (RIO_DEBUG_CTRL, "Opens block until booted\n");
-				for ( Entry=0; Entry < RIO_PORTS; Entry++ ) {
-		 			rio_spin_lock_irqsave(&PortP->portSem, flags);
-		 			p->RIOPortp[Entry]->WaitUntilBooted = 1;
-		 			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-				}
-				return 0;
-			
-	 		case RIO_SETUP_PORTS:
-				rio_dprintk (RIO_DEBUG_CTRL, "Setup ports\n");
-				if (copyin((int)arg, (caddr_t)&PortSetup, sizeof(PortSetup)) 
-						== COPYFAIL ) {
-					 p->RIOError.Error = COPYIN_FAILED;
-					 rio_dprintk (RIO_DEBUG_CTRL, "EFAULT");
-					 return -EFAULT;
-				}
-				if ( PortSetup.From > PortSetup.To || 
-								PortSetup.To >= RIO_PORTS ) {
-					 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
-					 rio_dprintk (RIO_DEBUG_CTRL, "ENXIO");
-					 return -ENXIO;
-				}
-				if ( PortSetup.XpCps > p->RIOConf.MaxXpCps ||
-					 PortSetup.XpCps < p->RIOConf.MinXpCps ) {
-					 p->RIOError.Error = XPRINT_CPS_OUT_OF_RANGE;
-					 rio_dprintk (RIO_DEBUG_CTRL, "EINVAL");
-					 return -EINVAL;
-				}
-				if ( !p->RIOPortp ) {
-					 cprintf("No p->RIOPortp array!\n");
-					 rio_dprintk (RIO_DEBUG_CTRL, "No p->RIOPortp array!\n");
-					 return -EIO;
-				}
-				rio_dprintk (RIO_DEBUG_CTRL, "entering loop (%d %d)!\n", PortSetup.From, PortSetup.To);
-				for (loop=PortSetup.From; loop<=PortSetup.To; loop++) {
-				rio_dprintk (RIO_DEBUG_CTRL, "in loop (%d)!\n", loop);
-#if 0
-					PortP = p->RIOPortp[loop];
-					if ( !PortP->TtyP )
-						PortP->TtyP = &p->channel[loop];
+	case RIO_RESUME:
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME\n");
+		port = (uint) arg;
+		if ((port < 0) || (port > 511)) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Bad port number %d\n", port);
+			p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
+			return -EINVAL;
+		}
+		PortP = p->RIOPortp[port];
+		if (!PortP->Mapped) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not mapped\n", port);
+			p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
+			return -EINVAL;
+		}
+		if (!(PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not open\n", port);
+			return -EINVAL;
+		}
 
-		 				rio_spin_lock_irqsave(&PortP->portSem, flags);
-						if ( PortSetup.IxAny )
-							PortP->Config |= RIO_IXANY;
-						else
-							PortP->Config &= ~RIO_IXANY;
-						if ( PortSetup.IxOn )
-							PortP->Config |= RIO_IXON;
-						else
-							PortP->Config &= ~RIO_IXON;
-					 
-					 /*
-					 ** If the port needs to wait for all a processes output
-					 ** to drain before closing then this flag will be set.
-					 */
-					 	if (PortSetup.Drain) {
-							PortP->Config |= RIO_WAITDRAIN;
-					 	} else {
-							PortP->Config &= ~RIO_WAITDRAIN;
-					 	}
-					 /*
-					 ** Store settings if locking or unlocking port or if the
-					 ** port is not locked, when setting the store option.
-					 */
-					 if (PortP->Mapped &&
-						 ((PortSetup.Lock && !PortP->Lock) ||
-							(!PortP->Lock &&
-							(PortSetup.Store && !PortP->Store)))) {
-						PortP->StoredTty.iflag = PortP->TtyP->tm.c_iflag;
-						PortP->StoredTty.oflag = PortP->TtyP->tm.c_oflag;
-						PortP->StoredTty.cflag = PortP->TtyP->tm.c_cflag;
-						PortP->StoredTty.lflag = PortP->TtyP->tm.c_lflag;
-						PortP->StoredTty.line = PortP->TtyP->tm.c_line;
-						bcopy(PortP->TtyP->tm.c_cc, PortP->StoredTty.cc,
-					 		NCC + 5);
-					 }
-					 PortP->Lock = PortSetup.Lock;
-					 PortP->Store = PortSetup.Store;
-					 PortP->Xprint.XpCps = PortSetup.XpCps;
-					 bcopy(PortSetup.XpOn,PortP->Xprint.XpOn,MAX_XP_CTRL_LEN);
-					 bcopy(PortSetup.XpOff,PortP->Xprint.XpOff,MAX_XP_CTRL_LEN);
-					 PortP->Xprint.XpOn[MAX_XP_CTRL_LEN-1] = '\0';
-					 PortP->Xprint.XpOff[MAX_XP_CTRL_LEN-1] = '\0';
-					 PortP->Xprint.XpLen = RIOStrlen(PortP->Xprint.XpOn)+
-								RIOStrlen(PortP->Xprint.XpOff);
-					 rio_spin_unlock_irqrestore( &PortP->portSem , flags);
-#endif
-				}
-				rio_dprintk (RIO_DEBUG_CTRL, "after loop (%d)!\n", loop);
-				rio_dprintk (RIO_DEBUG_CTRL, "Retval:%x\n", retval);
-				return retval;
+		rio_spin_lock_irqsave(&PortP->portSem, flags);
+		if (RIOPreemptiveCmd(p, (p->RIOPortp[port]), RESUME) == RIO_FAIL) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME failed\n");
+			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+			return -EBUSY;
+		} else {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d resumed\n", port);
+			PortP->State |= RIO_BUSY;
+		}
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		return retval;
 
-			case RIO_GET_PORT_SETUP :
-				rio_dprintk (RIO_DEBUG_CTRL, "Get port setup\n");
-				if (copyin((int)arg, (caddr_t)&PortSetup, sizeof(PortSetup)) 
-							== COPYFAIL ) {
-					 p->RIOError.Error = COPYIN_FAILED;
-					 return -EFAULT;
-				}
-				if ( PortSetup.From >= RIO_PORTS ) {
-					 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
-					 return -ENXIO;
-				}
+	case RIO_ASSIGN_RTA:
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA\n");
+		if (!su) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA !Root\n");
+			p->RIOError.Error = NOT_SUPER_USER;
+			return -EPERM;
+		}
+		if (copyin((int) arg, (caddr_t) & MapEnt, sizeof(MapEnt))
+		    == COPYFAIL) {
+			rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
+			p->RIOError.Error = COPYIN_FAILED;
+			return -EFAULT;
+		}
+		return RIOAssignRta(p, &MapEnt);
 
-				port = PortSetup.To = PortSetup.From;
-				PortSetup.IxAny = (p->RIOPortp[port]->Config & RIO_IXANY) ? 
-													1 : 0;
-				PortSetup.IxOn = (p->RIOPortp[port]->Config & RIO_IXON) ? 
-													1 : 0;
-				PortSetup.Drain = (p->RIOPortp[port]->Config & RIO_WAITDRAIN) ?
-												 	1 : 0;
-				PortSetup.Store = p->RIOPortp[port]->Store;
-				PortSetup.Lock = p->RIOPortp[port]->Lock;
-				PortSetup.XpCps = p->RIOPortp[port]->Xprint.XpCps;
-				bcopy(p->RIOPortp[port]->Xprint.XpOn, PortSetup.XpOn,
-													MAX_XP_CTRL_LEN);
-				bcopy(p->RIOPortp[port]->Xprint.XpOff, PortSetup.XpOff,
-													MAX_XP_CTRL_LEN);
-				PortSetup.XpOn[MAX_XP_CTRL_LEN-1] = '\0';
-				PortSetup.XpOff[MAX_XP_CTRL_LEN-1] = '\0';
+	case RIO_CHANGE_NAME:
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_CHANGE_NAME\n");
+		if (!su) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_CHANGE_NAME !Root\n");
+			p->RIOError.Error = NOT_SUPER_USER;
+			return -EPERM;
+		}
+		if (copyin((int) arg, (caddr_t) & MapEnt, sizeof(MapEnt))
+		    == COPYFAIL) {
+			rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
+			p->RIOError.Error = COPYIN_FAILED;
+			return -EFAULT;
+		}
+		return RIOChangeName(p, &MapEnt);
 
-				if ( copyout((caddr_t)&PortSetup,(int)arg,sizeof(PortSetup))
-														==COPYFAIL ) {
-					 p->RIOError.Error = COPYOUT_FAILED;
-					 return -EFAULT;
-				}
-				return retval;
+	case RIO_DELETE_RTA:
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_DELETE_RTA\n");
+		if (!su) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_DELETE_RTA !Root\n");
+			p->RIOError.Error = NOT_SUPER_USER;
+			return -EPERM;
+		}
+		if (copyin((int) arg, (caddr_t) & MapEnt, sizeof(MapEnt))
+		    == COPYFAIL) {
+			rio_dprintk(RIO_DEBUG_CTRL, "Copy from data space failed\n");
+			p->RIOError.Error = COPYIN_FAILED;
+			return -EFAULT;
+		}
+		return RIODeleteRta(p, &MapEnt);
 
-			case RIO_GET_PORT_PARAMS :
-				rio_dprintk (RIO_DEBUG_CTRL, "Get port params\n");
-				if (copyin( (int)arg, (caddr_t)&PortParams,
-					sizeof(struct PortParams)) == COPYFAIL) {
-					p->RIOError.Error = COPYIN_FAILED;
-					return -EFAULT;
-				}
-				if (PortParams.Port >= RIO_PORTS) {
-					p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
-					return -ENXIO;
-				}
-				PortP = (p->RIOPortp[PortParams.Port]);
-				PortParams.Config = PortP->Config;
-				PortParams.State = PortP->State;
-				rio_dprintk (RIO_DEBUG_CTRL, "Port %d\n", PortParams.Port);
+	case RIO_QUICK_CHECK:
+		/*
+		 ** 09.12.1998 ARG - ESIL 0776 part fix
+		 ** A customer was using this to get the RTAs
+		 ** connect/disconnect status.
+		 ** RIOConCon() had been botched use RIOHalted
+		 ** to keep track of RTA connections and
+		 ** disconnections. That has been changed and
+		 ** RIORtaDisCons in the rio_info struct now
+		 ** does the job. So we need to return the value
+		 ** of RIORtaCons instead of RIOHalted.
+		 **
+		 if (copyout((caddr_t)&p->RIOHalted,(int)arg,
+		 sizeof(uint))==COPYFAIL) {
+		 **
+		 */
 
-				if (copyout((caddr_t)&PortParams, (int)arg, 
-						sizeof(struct PortParams)) == COPYFAIL ) {
-					 p->RIOError.Error = COPYOUT_FAILED;
-					 return -EFAULT;
-				}
-				return retval;
+		if (copyout((caddr_t) & p->RIORtaDisCons, (int) arg, sizeof(uint)) == COPYFAIL) {
+			p->RIOError.Error = COPYOUT_FAILED;
+			return -EFAULT;
+		}
+		return 0;
 
-			case RIO_GET_PORT_TTY :
-				rio_dprintk (RIO_DEBUG_CTRL, "Get port tty\n");
-				if (copyin((int)arg, (caddr_t)&PortTty, sizeof(struct PortTty)) 
-						== COPYFAIL) {
-					 p->RIOError.Error = COPYIN_FAILED;
-					 return -EFAULT;
-				}
-				if ( PortTty.port >= RIO_PORTS ) {
-					 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
-					 return -ENXIO;
-				}
+	case RIO_LAST_ERROR:
+		if (copyout((caddr_t) & p->RIOError, (int) arg, sizeof(struct Error)) == COPYFAIL)
+			return -EFAULT;
+		return 0;
 
-				rio_dprintk (RIO_DEBUG_CTRL, "Port %d\n", PortTty.port);
-				PortP = (p->RIOPortp[PortTty.port]);
-#if 0
-				PortTty.Tty.tm.c_iflag = PortP->TtyP->tm.c_iflag;
-				PortTty.Tty.tm.c_oflag = PortP->TtyP->tm.c_oflag;
-				PortTty.Tty.tm.c_cflag = PortP->TtyP->tm.c_cflag;
-				PortTty.Tty.tm.c_lflag = PortP->TtyP->tm.c_lflag;
-#endif
-				if (copyout((caddr_t)&PortTty, (int)arg, 
-							sizeof(struct PortTty)) == COPYFAIL) {
-					p->RIOError.Error = COPYOUT_FAILED;
-					return -EFAULT;
-				}
-				return retval;
-
-			case RIO_SET_PORT_TTY :
-				if (copyin((int)arg, (caddr_t)&PortTty, 
-						sizeof(struct PortTty)) == COPYFAIL) {
-					 p->RIOError.Error = COPYIN_FAILED;
-					 return -EFAULT;
-				}
-				rio_dprintk (RIO_DEBUG_CTRL, "Set port %d tty\n", PortTty.port);
-				if (PortTty.port >= (ushort) RIO_PORTS) {
-					 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
-					 return -ENXIO;
-				}
-				PortP = (p->RIOPortp[PortTty.port]);
-#if 0
-		 		rio_spin_lock_irqsave(&PortP->portSem, flags);
-				PortP->TtyP->tm.c_iflag = PortTty.Tty.tm.c_iflag;
-				PortP->TtyP->tm.c_oflag = PortTty.Tty.tm.c_oflag;
-				PortP->TtyP->tm.c_cflag = PortTty.Tty.tm.c_cflag;
-				PortP->TtyP->tm.c_lflag = PortTty.Tty.tm.c_lflag;
-				rio_spin_unlock_irqrestore( &PortP->portSem , flags);
+	case RIO_GET_LOG:
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_LOG\n");
+#ifdef LOGGING
+		RIOGetLog(arg);
+		return 0;
+#else
+		return -EINVAL;
 #endif
 
-				RIOParam(PortP, CONFIG, PortP->State & RIO_MODEM, OK_TO_SLEEP);
-				return retval;
+	case RIO_GET_MODTYPE:
+		if (copyin((int) arg, (caddr_t) & port, sizeof(uint)) == COPYFAIL) {
+			p->RIOError.Error = COPYIN_FAILED;
+			return -EFAULT;
+		}
+		rio_dprintk(RIO_DEBUG_CTRL, "Get module type for port %d\n", port);
+		if (port < 0 || port > 511) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Bad port number %d\n", port);
+			p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
+			return -EINVAL;
+		}
+		PortP = (p->RIOPortp[port]);
+		if (!PortP->Mapped) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Port %d not mapped\n", port);
+			p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
+			return -EINVAL;
+		}
+		/*
+		 ** Return module type of port
+		 */
+		port = PortP->HostP->UnixRups[PortP->RupNum].ModTypes;
+		if (copyout((caddr_t) & port, (int) arg, sizeof(uint)) == COPYFAIL) {
+			p->RIOError.Error = COPYOUT_FAILED;
+			return -EFAULT;
+		}
+		return (0);
+		/*
+		 ** 02.03.1999 ARG - ESIL 0820 fix
+		 ** We are no longer using "Boot Mode", so these ioctls
+		 ** are not required :
+		 **
+		 case RIO_GET_BOOT_MODE :
+		 rio_dprint(RIO_DEBUG_CTRL, ("Get boot mode - %x\n", p->RIOBootMode));
+		 **
+		 ** Return boot state of system - BOOT_ALL, BOOT_OWN or BOOT_NONE
+		 **
+		 if (copyout((caddr_t)&p->RIOBootMode, (int)arg,
+		 sizeof(p->RIOBootMode)) == COPYFAIL) {
+		 p->RIOError.Error = COPYOUT_FAILED;
+		 return -EFAULT;
+		 }
+		 return(0);
 
-			case RIO_SET_PORT_PARAMS :
-				rio_dprintk (RIO_DEBUG_CTRL, "Set port params\n");
-				if ( copyin((int)arg, (caddr_t)&PortParams, sizeof(PortParams))
-					== COPYFAIL ) {
-					 p->RIOError.Error = COPYIN_FAILED;
-					 return -EFAULT;
-				}
-				if (PortParams.Port >= (ushort) RIO_PORTS) {
-					 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
-					 return -ENXIO;
-				}
-				PortP = (p->RIOPortp[PortParams.Port]);
-		 		rio_spin_lock_irqsave(&PortP->portSem, flags);
-				PortP->Config = PortParams.Config;
-				rio_spin_unlock_irqrestore( &PortP->portSem , flags);
-				return retval;
+		 case RIO_SET_BOOT_MODE :
+		 p->RIOBootMode = (uint) arg;
+		 rio_dprint(RIO_DEBUG_CTRL, ("Set boot mode to 0x%x\n", p->RIOBootMode));
+		 return(0);
+		 **
+		 ** End ESIL 0820 fix
+		 */
 
-			case RIO_GET_PORT_STATS :
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_GET_PORT_STATS\n");
-				if ( copyin((int)arg, (caddr_t)&portStats, 
-						sizeof(struct portStats)) == COPYFAIL ) {
-					 p->RIOError.Error = COPYIN_FAILED;
-					 return -EFAULT;
-				}
-				if ( portStats.port >= RIO_PORTS ) {
-					 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
-					 return -ENXIO;
-				}
-				PortP = (p->RIOPortp[portStats.port]);
-				portStats.gather = PortP->statsGather;
-				portStats.txchars = PortP->txchars;
-				portStats.rxchars = PortP->rxchars;
-				portStats.opens = PortP->opens;
-				portStats.closes = PortP->closes;
-				portStats.ioctls = PortP->ioctls;
-				if ( copyout((caddr_t)&portStats, (int)arg, 
-							sizeof(struct portStats)) == COPYFAIL ) {
-					 p->RIOError.Error = COPYOUT_FAILED;
-					 return -EFAULT;
-				}
-				return retval;
+	case RIO_BLOCK_OPENS:
+		rio_dprintk(RIO_DEBUG_CTRL, "Opens block until booted\n");
+		for (Entry = 0; Entry < RIO_PORTS; Entry++) {
+			rio_spin_lock_irqsave(&PortP->portSem, flags);
+			p->RIOPortp[Entry]->WaitUntilBooted = 1;
+			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		}
+		return 0;
 
-			case RIO_RESET_PORT_STATS :
-				port = (uint) arg;
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_RESET_PORT_STATS\n");
-				if ( port >= RIO_PORTS ) {
-					 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
-					 return -ENXIO;
-				}
-				PortP = (p->RIOPortp[port]);
-				rio_spin_lock_irqsave(&PortP->portSem, flags);
-				PortP->txchars	= 0;
-				PortP->rxchars	= 0;
-				PortP->opens	= 0;
-				PortP->closes	= 0;
-				PortP->ioctls	= 0;
-				rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-				return retval;
+	case RIO_SETUP_PORTS:
+		rio_dprintk(RIO_DEBUG_CTRL, "Setup ports\n");
+		if (copyin((int) arg, (caddr_t) & PortSetup, sizeof(PortSetup))
+		    == COPYFAIL) {
+			p->RIOError.Error = COPYIN_FAILED;
+			rio_dprintk(RIO_DEBUG_CTRL, "EFAULT");
+			return -EFAULT;
+		}
+		if (PortSetup.From > PortSetup.To || PortSetup.To >= RIO_PORTS) {
+			p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
+			rio_dprintk(RIO_DEBUG_CTRL, "ENXIO");
+			return -ENXIO;
+		}
+		if (PortSetup.XpCps > p->RIOConf.MaxXpCps || PortSetup.XpCps < p->RIOConf.MinXpCps) {
+			p->RIOError.Error = XPRINT_CPS_OUT_OF_RANGE;
+			rio_dprintk(RIO_DEBUG_CTRL, "EINVAL");
+			return -EINVAL;
+		}
+		if (!p->RIOPortp) {
+			cprintf("No p->RIOPortp array!\n");
+			rio_dprintk(RIO_DEBUG_CTRL, "No p->RIOPortp array!\n");
+			return -EIO;
+		}
+		rio_dprintk(RIO_DEBUG_CTRL, "entering loop (%d %d)!\n", PortSetup.From, PortSetup.To);
+		for (loop = PortSetup.From; loop <= PortSetup.To; loop++) {
+			rio_dprintk(RIO_DEBUG_CTRL, "in loop (%d)!\n", loop);
+#if 0
+			PortP = p->RIOPortp[loop];
+			if (!PortP->TtyP)
+				PortP->TtyP = &p->channel[loop];
 
-			case RIO_GATHER_PORT_STATS :
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_GATHER_PORT_STATS\n");
-				if ( copyin( (int)arg, (caddr_t)&portStats, 
-						sizeof(struct portStats)) == COPYFAIL ) {
-					 p->RIOError.Error = COPYIN_FAILED;
-					 return -EFAULT;
-				}
-				if ( portStats.port >= RIO_PORTS ) {
-					 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
-					 return -ENXIO;
-				}
-				PortP = (p->RIOPortp[portStats.port]);
-				rio_spin_lock_irqsave(&PortP->portSem, flags);
-				PortP->statsGather = portStats.gather;
-				rio_spin_unlock_irqrestore( &PortP->portSem , flags);
-				return retval;
+			rio_spin_lock_irqsave(&PortP->portSem, flags);
+			if (PortSetup.IxAny)
+				PortP->Config |= RIO_IXANY;
+			else
+				PortP->Config &= ~RIO_IXANY;
+			if (PortSetup.IxOn)
+				PortP->Config |= RIO_IXON;
+			else
+				PortP->Config &= ~RIO_IXON;
+
+			/*
+			 ** If the port needs to wait for all a processes output
+			 ** to drain before closing then this flag will be set.
+			 */
+			if (PortSetup.Drain) {
+				PortP->Config |= RIO_WAITDRAIN;
+			} else {
+				PortP->Config &= ~RIO_WAITDRAIN;
+			}
+			/*
+			 ** Store settings if locking or unlocking port or if the
+			 ** port is not locked, when setting the store option.
+			 */
+			if (PortP->Mapped && ((PortSetup.Lock && !PortP->Lock) || (!PortP->Lock && (PortSetup.Store && !PortP->Store)))) {
+				PortP->StoredTty.iflag = PortP->TtyP->tm.c_iflag;
+				PortP->StoredTty.oflag = PortP->TtyP->tm.c_oflag;
+				PortP->StoredTty.cflag = PortP->TtyP->tm.c_cflag;
+				PortP->StoredTty.lflag = PortP->TtyP->tm.c_lflag;
+				PortP->StoredTty.line = PortP->TtyP->tm.c_line;
+				bcopy(PortP->TtyP->tm.c_cc, PortP->StoredTty.cc, NCC + 5);
+			}
+			PortP->Lock = PortSetup.Lock;
+			PortP->Store = PortSetup.Store;
+			PortP->Xprint.XpCps = PortSetup.XpCps;
+			bcopy(PortSetup.XpOn, PortP->Xprint.XpOn, MAX_XP_CTRL_LEN);
+			bcopy(PortSetup.XpOff, PortP->Xprint.XpOff, MAX_XP_CTRL_LEN);
+			PortP->Xprint.XpOn[MAX_XP_CTRL_LEN - 1] = '\0';
+			PortP->Xprint.XpOff[MAX_XP_CTRL_LEN - 1] = '\0';
+			PortP->Xprint.XpLen = RIOStrlen(PortP->Xprint.XpOn) + RIOStrlen(PortP->Xprint.XpOff);
+			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+#endif
+		}
+		rio_dprintk(RIO_DEBUG_CTRL, "after loop (%d)!\n", loop);
+		rio_dprintk(RIO_DEBUG_CTRL, "Retval:%x\n", retval);
+		return retval;
+
+	case RIO_GET_PORT_SETUP:
+		rio_dprintk(RIO_DEBUG_CTRL, "Get port setup\n");
+		if (copyin((int) arg, (caddr_t) & PortSetup, sizeof(PortSetup))
+		    == COPYFAIL) {
+			p->RIOError.Error = COPYIN_FAILED;
+			return -EFAULT;
+		}
+		if (PortSetup.From >= RIO_PORTS) {
+			p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
+			return -ENXIO;
+		}
+
+		port = PortSetup.To = PortSetup.From;
+		PortSetup.IxAny = (p->RIOPortp[port]->Config & RIO_IXANY) ? 1 : 0;
+		PortSetup.IxOn = (p->RIOPortp[port]->Config & RIO_IXON) ? 1 : 0;
+		PortSetup.Drain = (p->RIOPortp[port]->Config & RIO_WAITDRAIN) ? 1 : 0;
+		PortSetup.Store = p->RIOPortp[port]->Store;
+		PortSetup.Lock = p->RIOPortp[port]->Lock;
+		PortSetup.XpCps = p->RIOPortp[port]->Xprint.XpCps;
+		bcopy(p->RIOPortp[port]->Xprint.XpOn, PortSetup.XpOn, MAX_XP_CTRL_LEN);
+		bcopy(p->RIOPortp[port]->Xprint.XpOff, PortSetup.XpOff, MAX_XP_CTRL_LEN);
+		PortSetup.XpOn[MAX_XP_CTRL_LEN - 1] = '\0';
+		PortSetup.XpOff[MAX_XP_CTRL_LEN - 1] = '\0';
+
+		if (copyout((caddr_t) & PortSetup, (int) arg, sizeof(PortSetup))
+		    == COPYFAIL) {
+			p->RIOError.Error = COPYOUT_FAILED;
+			return -EFAULT;
+		}
+		return retval;
+
+	case RIO_GET_PORT_PARAMS:
+		rio_dprintk(RIO_DEBUG_CTRL, "Get port params\n");
+		if (copyin((int) arg, (caddr_t) & PortParams, sizeof(struct PortParams)) == COPYFAIL) {
+			p->RIOError.Error = COPYIN_FAILED;
+			return -EFAULT;
+		}
+		if (PortParams.Port >= RIO_PORTS) {
+			p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
+			return -ENXIO;
+		}
+		PortP = (p->RIOPortp[PortParams.Port]);
+		PortParams.Config = PortP->Config;
+		PortParams.State = PortP->State;
+		rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortParams.Port);
+
+		if (copyout((caddr_t) & PortParams, (int) arg, sizeof(struct PortParams)) == COPYFAIL) {
+			p->RIOError.Error = COPYOUT_FAILED;
+			return -EFAULT;
+		}
+		return retval;
+
+	case RIO_GET_PORT_TTY:
+		rio_dprintk(RIO_DEBUG_CTRL, "Get port tty\n");
+		if (copyin((int) arg, (caddr_t) & PortTty, sizeof(struct PortTty))
+		    == COPYFAIL) {
+			p->RIOError.Error = COPYIN_FAILED;
+			return -EFAULT;
+		}
+		if (PortTty.port >= RIO_PORTS) {
+			p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
+			return -ENXIO;
+		}
+
+		rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortTty.port);
+		PortP = (p->RIOPortp[PortTty.port]);
+#if 0
+		PortTty.Tty.tm.c_iflag = PortP->TtyP->tm.c_iflag;
+		PortTty.Tty.tm.c_oflag = PortP->TtyP->tm.c_oflag;
+		PortTty.Tty.tm.c_cflag = PortP->TtyP->tm.c_cflag;
+		PortTty.Tty.tm.c_lflag = PortP->TtyP->tm.c_lflag;
+#endif
+		if (copyout((caddr_t) & PortTty, (int) arg, sizeof(struct PortTty)) == COPYFAIL) {
+			p->RIOError.Error = COPYOUT_FAILED;
+			return -EFAULT;
+		}
+		return retval;
+
+	case RIO_SET_PORT_TTY:
+		if (copyin((int) arg, (caddr_t) & PortTty, sizeof(struct PortTty)) == COPYFAIL) {
+			p->RIOError.Error = COPYIN_FAILED;
+			return -EFAULT;
+		}
+		rio_dprintk(RIO_DEBUG_CTRL, "Set port %d tty\n", PortTty.port);
+		if (PortTty.port >= (ushort) RIO_PORTS) {
+			p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
+			return -ENXIO;
+		}
+		PortP = (p->RIOPortp[PortTty.port]);
+#if 0
+		rio_spin_lock_irqsave(&PortP->portSem, flags);
+		PortP->TtyP->tm.c_iflag = PortTty.Tty.tm.c_iflag;
+		PortP->TtyP->tm.c_oflag = PortTty.Tty.tm.c_oflag;
+		PortP->TtyP->tm.c_cflag = PortTty.Tty.tm.c_cflag;
+		PortP->TtyP->tm.c_lflag = PortTty.Tty.tm.c_lflag;
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+#endif
+
+		RIOParam(PortP, CONFIG, PortP->State & RIO_MODEM, OK_TO_SLEEP);
+		return retval;
+
+	case RIO_SET_PORT_PARAMS:
+		rio_dprintk(RIO_DEBUG_CTRL, "Set port params\n");
+		if (copyin((int) arg, (caddr_t) & PortParams, sizeof(PortParams))
+		    == COPYFAIL) {
+			p->RIOError.Error = COPYIN_FAILED;
+			return -EFAULT;
+		}
+		if (PortParams.Port >= (ushort) RIO_PORTS) {
+			p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
+			return -ENXIO;
+		}
+		PortP = (p->RIOPortp[PortParams.Port]);
+		rio_spin_lock_irqsave(&PortP->portSem, flags);
+		PortP->Config = PortParams.Config;
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		return retval;
+
+	case RIO_GET_PORT_STATS:
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_PORT_STATS\n");
+		if (copyin((int) arg, (caddr_t) & portStats, sizeof(struct portStats)) == COPYFAIL) {
+			p->RIOError.Error = COPYIN_FAILED;
+			return -EFAULT;
+		}
+		if (portStats.port >= RIO_PORTS) {
+			p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
+			return -ENXIO;
+		}
+		PortP = (p->RIOPortp[portStats.port]);
+		portStats.gather = PortP->statsGather;
+		portStats.txchars = PortP->txchars;
+		portStats.rxchars = PortP->rxchars;
+		portStats.opens = PortP->opens;
+		portStats.closes = PortP->closes;
+		portStats.ioctls = PortP->ioctls;
+		if (copyout((caddr_t) & portStats, (int) arg, sizeof(struct portStats)) == COPYFAIL) {
+			p->RIOError.Error = COPYOUT_FAILED;
+			return -EFAULT;
+		}
+		return retval;
+
+	case RIO_RESET_PORT_STATS:
+		port = (uint) arg;
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESET_PORT_STATS\n");
+		if (port >= RIO_PORTS) {
+			p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
+			return -ENXIO;
+		}
+		PortP = (p->RIOPortp[port]);
+		rio_spin_lock_irqsave(&PortP->portSem, flags);
+		PortP->txchars = 0;
+		PortP->rxchars = 0;
+		PortP->opens = 0;
+		PortP->closes = 0;
+		PortP->ioctls = 0;
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		return retval;
+
+	case RIO_GATHER_PORT_STATS:
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_GATHER_PORT_STATS\n");
+		if (copyin((int) arg, (caddr_t) & portStats, sizeof(struct portStats)) == COPYFAIL) {
+			p->RIOError.Error = COPYIN_FAILED;
+			return -EFAULT;
+		}
+		if (portStats.port >= RIO_PORTS) {
+			p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
+			return -ENXIO;
+		}
+		PortP = (p->RIOPortp[portStats.port]);
+		rio_spin_lock_irqsave(&PortP->portSem, flags);
+		PortP->statsGather = portStats.gather;
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		return retval;
 
 #ifdef DEBUG_SUPPORTED
-			case RIO_READ_LEVELS:
-				{
-					 int num;
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_READ_LEVELS\n");
-					 for ( num=0; RIODbInf[num].Flag; num++ ) ;
-					 rio_dprintk (RIO_DEBUG_CTRL, "%d levels to copy\n",num);
-					 if (copyout((caddr_t)RIODbInf,(int)arg,
-						sizeof(struct DbInf)*(num+1))==COPYFAIL) {
-						rio_dprintk (RIO_DEBUG_CTRL, "ReadLevels Copy failed\n");
-						p->RIOError.Error = COPYOUT_FAILED;
-						return -EFAULT;
-					 }
-					 rio_dprintk (RIO_DEBUG_CTRL, "%d levels to copied\n",num);
-					 return retval;
-				}
+	case RIO_READ_LEVELS:
+		{
+			int num;
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_LEVELS\n");
+			for (num = 0; RIODbInf[num].Flag; num++);
+			rio_dprintk(RIO_DEBUG_CTRL, "%d levels to copy\n", num);
+			if (copyout((caddr_t) RIODbInf, (int) arg, sizeof(struct DbInf) * (num + 1)) == COPYFAIL) {
+				rio_dprintk(RIO_DEBUG_CTRL, "ReadLevels Copy failed\n");
+				p->RIOError.Error = COPYOUT_FAILED;
+				return -EFAULT;
+			}
+			rio_dprintk(RIO_DEBUG_CTRL, "%d levels to copied\n", num);
+			return retval;
+		}
 #endif
 
-			 case RIO_READ_CONFIG:
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_READ_CONFIG\n");
-				if (copyout((caddr_t)&p->RIOConf, (int)arg, 
-							sizeof(struct Conf)) ==COPYFAIL ) {
-					 p->RIOError.Error = COPYOUT_FAILED;
-					 return -EFAULT;
-				}
-				return retval;
+	case RIO_READ_CONFIG:
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_CONFIG\n");
+		if (copyout((caddr_t) & p->RIOConf, (int) arg, sizeof(struct Conf)) == COPYFAIL) {
+			p->RIOError.Error = COPYOUT_FAILED;
+			return -EFAULT;
+		}
+		return retval;
 
-			case RIO_SET_CONFIG:
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_SET_CONFIG\n");
-				if ( !su ) {
-					 p->RIOError.Error = NOT_SUPER_USER;
-					 return -EPERM;
-				}
-				if ( copyin((int)arg, (caddr_t)&p->RIOConf, sizeof(struct Conf) )
-						==COPYFAIL ) {
-					 p->RIOError.Error = COPYIN_FAILED;
-					 return -EFAULT;
-				}
-				/*
-				** move a few value around
-				*/
-				for (Host=0; Host < p->RIONumHosts; Host++)
-					 if ( (p->RIOHosts[Host].Flags & RUN_STATE) == RC_RUNNING )
-					 	WWORD(p->RIOHosts[Host].ParmMapP->timer , 
-								p->RIOConf.Timer);
-				return retval;
+	case RIO_SET_CONFIG:
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_CONFIG\n");
+		if (!su) {
+			p->RIOError.Error = NOT_SUPER_USER;
+			return -EPERM;
+		}
+		if (copyin((int) arg, (caddr_t) & p->RIOConf, sizeof(struct Conf))
+		    == COPYFAIL) {
+			p->RIOError.Error = COPYIN_FAILED;
+			return -EFAULT;
+		}
+		/*
+		 ** move a few value around
+		 */
+		for (Host = 0; Host < p->RIONumHosts; Host++)
+			if ((p->RIOHosts[Host].Flags & RUN_STATE) == RC_RUNNING)
+				WWORD(p->RIOHosts[Host].ParmMapP->timer, p->RIOConf.Timer);
+		return retval;
 
-			case RIO_START_POLLER:
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_START_POLLER\n");
-				return -EINVAL;
+	case RIO_START_POLLER:
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_START_POLLER\n");
+		return -EINVAL;
 
-			case RIO_STOP_POLLER:
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_STOP_POLLER\n");
-				if ( !su ) {
-					 p->RIOError.Error = NOT_SUPER_USER;
-					 return -EPERM;
-				}
-				p->RIOPolling = NOT_POLLING;
-				return retval;
+	case RIO_STOP_POLLER:
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_STOP_POLLER\n");
+		if (!su) {
+			p->RIOError.Error = NOT_SUPER_USER;
+			return -EPERM;
+		}
+		p->RIOPolling = NOT_POLLING;
+		return retval;
 
-			case RIO_SETDEBUG:
-			case RIO_GETDEBUG:
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_SETDEBUG/RIO_GETDEBUG\n");
-				if ( copyin( (int)arg, (caddr_t)&DebugCtrl, sizeof(DebugCtrl) )
-							==COPYFAIL ) {
-					 p->RIOError.Error = COPYIN_FAILED;
-					 return -EFAULT;
+	case RIO_SETDEBUG:
+	case RIO_GETDEBUG:
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG/RIO_GETDEBUG\n");
+		if (copyin((int) arg, (caddr_t) & DebugCtrl, sizeof(DebugCtrl))
+		    == COPYFAIL) {
+			p->RIOError.Error = COPYIN_FAILED;
+			return -EFAULT;
+		}
+		if (DebugCtrl.SysPort == NO_PORT) {
+			if (cmd == RIO_SETDEBUG) {
+				if (!su) {
+					p->RIOError.Error = NOT_SUPER_USER;
+					return -EPERM;
 				}
-				if ( DebugCtrl.SysPort == NO_PORT ) {
-					if ( cmd == RIO_SETDEBUG ) {
-						if ( !su ) {
-							p->RIOError.Error = NOT_SUPER_USER;
-							return -EPERM;
-						}
-						p->rio_debug = DebugCtrl.Debug;
-						p->RIODebugWait = DebugCtrl.Wait;
-						rio_dprintk (RIO_DEBUG_CTRL, "Set global debug to 0x%x set wait to 0x%x\n",
-							p->rio_debug,p->RIODebugWait);
-					}
-				 	else {
-						rio_dprintk (RIO_DEBUG_CTRL, "Get global debug 0x%x wait 0x%x\n",
-										p->rio_debug,p->RIODebugWait);
-						DebugCtrl.Debug = p->rio_debug;
-						DebugCtrl.Wait  = p->RIODebugWait;
-						if ( copyout((caddr_t)&DebugCtrl,(int)arg,
-								sizeof(DebugCtrl)) == COPYFAIL ) {
-							rio_dprintk (RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n",
-									DebugCtrl.SysPort);
-						 	p->RIOError.Error = COPYOUT_FAILED;
-						 	return -EFAULT;
-						}
-					}
+				p->rio_debug = DebugCtrl.Debug;
+				p->RIODebugWait = DebugCtrl.Wait;
+				rio_dprintk(RIO_DEBUG_CTRL, "Set global debug to 0x%x set wait to 0x%x\n", p->rio_debug, p->RIODebugWait);
+			} else {
+				rio_dprintk(RIO_DEBUG_CTRL, "Get global debug 0x%x wait 0x%x\n", p->rio_debug, p->RIODebugWait);
+				DebugCtrl.Debug = p->rio_debug;
+				DebugCtrl.Wait = p->RIODebugWait;
+				if (copyout((caddr_t) & DebugCtrl, (int) arg, sizeof(DebugCtrl)) == COPYFAIL) {
+					rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
+					p->RIOError.Error = COPYOUT_FAILED;
+					return -EFAULT;
 				}
-				else if ( DebugCtrl.SysPort >= RIO_PORTS && 
-							DebugCtrl.SysPort != NO_PORT ) {
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n",
-									DebugCtrl.SysPort);
-					 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
-					 return -ENXIO;
-				}
-				else if ( cmd == RIO_SETDEBUG ) {
-					if ( !su ) {
-						p->RIOError.Error = NOT_SUPER_USER;
-						return -EPERM;
-					}
-					rio_spin_lock_irqsave(&PortP->portSem, flags);
-					p->RIOPortp[DebugCtrl.SysPort]->Debug = DebugCtrl.Debug;
-					rio_spin_unlock_irqrestore( &PortP->portSem , flags);
-					rio_dprintk (RIO_DEBUG_CTRL, "RIO_SETDEBUG 0x%x\n",
-								p->RIOPortp[DebugCtrl.SysPort]->Debug);
-				}
-				else {
-					rio_dprintk (RIO_DEBUG_CTRL, "RIO_GETDEBUG 0x%x\n",
-									 p->RIOPortp[DebugCtrl.SysPort]->Debug);
-					DebugCtrl.Debug = p->RIOPortp[DebugCtrl.SysPort]->Debug;
-					if ( copyout((caddr_t)&DebugCtrl,(int)arg,
-								sizeof(DebugCtrl))==COPYFAIL ) {
-						rio_dprintk (RIO_DEBUG_CTRL, "RIO_GETDEBUG: Bad copy to user space\n");
-						p->RIOError.Error = COPYOUT_FAILED;
-						return -EFAULT;
-					}
-				}
-				return retval;
+			}
+		} else if (DebugCtrl.SysPort >= RIO_PORTS && DebugCtrl.SysPort != NO_PORT) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
+			p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
+			return -ENXIO;
+		} else if (cmd == RIO_SETDEBUG) {
+			if (!su) {
+				p->RIOError.Error = NOT_SUPER_USER;
+				return -EPERM;
+			}
+			rio_spin_lock_irqsave(&PortP->portSem, flags);
+			p->RIOPortp[DebugCtrl.SysPort]->Debug = DebugCtrl.Debug;
+			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
+		} else {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
+			DebugCtrl.Debug = p->RIOPortp[DebugCtrl.SysPort]->Debug;
+			if (copyout((caddr_t) & DebugCtrl, (int) arg, sizeof(DebugCtrl)) == COPYFAIL) {
+				rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG: Bad copy to user space\n");
+				p->RIOError.Error = COPYOUT_FAILED;
+				return -EFAULT;
+			}
+		}
+		return retval;
 
-			case RIO_VERSID:
-				/*
-				** Enquire about the release and version.
-				** We return MAX_VERSION_LEN bytes, being a
-				** textual null terminated string.
-				*/
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_VERSID\n");
-				if ( copyout(	(caddr_t)RIOVersid(),
-						(int)arg,
-						sizeof(struct rioVersion) ) == COPYFAIL )
-				{
-					 rio_dprintk (RIO_DEBUG_CTRL,  "RIO_VERSID: Bad copy to user space (host=%d)\n", Host);
-					 p->RIOError.Error = COPYOUT_FAILED;
-					 return -EFAULT;
-				}
-				return retval;
+	case RIO_VERSID:
+		/*
+		 ** Enquire about the release and version.
+		 ** We return MAX_VERSION_LEN bytes, being a
+		 ** textual null terminated string.
+		 */
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID\n");
+		if (copyout((caddr_t) RIOVersid(), (int) arg, sizeof(struct rioVersion)) == COPYFAIL) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID: Bad copy to user space (host=%d)\n", Host);
+			p->RIOError.Error = COPYOUT_FAILED;
+			return -EFAULT;
+		}
+		return retval;
 
-			/*
-			** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-			** !! commented out previous 'RIO_VERSID' functionality !!
-			** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-			**
-			case RIO_VERSID:
-				**
-				** Enquire about the release and version.
-				** We return MAX_VERSION_LEN bytes, being a textual null
-				** terminated string.
-				**
-				rio_dprint(RIO_DEBUG_CTRL, ("RIO_VERSID\n"));
-				if (copyout((caddr_t)RIOVersid(), 
-						(int)arg, MAX_VERSION_LEN ) == COPYFAIL ) {
-					 rio_dprint(RIO_DEBUG_CTRL, ("RIO_VERSID: Bad copy to user space\n",Host));
-					 p->RIOError.Error = COPYOUT_FAILED;
-					 return -EFAULT;
-				}
-				return retval;
-			**
-			** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-			*/
+		/*
+		 ** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+		 ** !! commented out previous 'RIO_VERSID' functionality !!
+		 ** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+		 **
+		 case RIO_VERSID:
+		 **
+		 ** Enquire about the release and version.
+		 ** We return MAX_VERSION_LEN bytes, being a textual null
+		 ** terminated string.
+		 **
+		 rio_dprint(RIO_DEBUG_CTRL, ("RIO_VERSID\n"));
+		 if (copyout((caddr_t)RIOVersid(),
+		 (int)arg, MAX_VERSION_LEN ) == COPYFAIL ) {
+		 rio_dprint(RIO_DEBUG_CTRL, ("RIO_VERSID: Bad copy to user space\n",Host));
+		 p->RIOError.Error = COPYOUT_FAILED;
+		 return -EFAULT;
+		 }
+		 return retval;
+		 **
+		 ** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+		 */
 
-			case RIO_NUM_HOSTS:
-				/*
-				** Enquire as to the number of hosts located
-				** at init time.
-				*/
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_NUM_HOSTS\n");
-				if (copyout((caddr_t)&p->RIONumHosts, (int)arg, 
-							sizeof(p->RIONumHosts) )==COPYFAIL ) {
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_NUM_HOSTS: Bad copy to user space\n");
-					 p->RIOError.Error = COPYOUT_FAILED;
-					 return -EFAULT;
-				}
-				return retval;
+	case RIO_NUM_HOSTS:
+		/*
+		 ** Enquire as to the number of hosts located
+		 ** at init time.
+		 */
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS\n");
+		if (copyout((caddr_t) & p->RIONumHosts, (int) arg, sizeof(p->RIONumHosts)) == COPYFAIL) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS: Bad copy to user space\n");
+			p->RIOError.Error = COPYOUT_FAILED;
+			return -EFAULT;
+		}
+		return retval;
 
-			case RIO_HOST_FOAD:
-				/*
-				** Kill host. This may not be in the final version...
-				*/
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_FOAD %d\n", (int)arg);
-				if ( !su ) {
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_FOAD: Not super user\n");
-					 p->RIOError.Error = NOT_SUPER_USER;
-					 return -EPERM;
-				}
-				p->RIOHalted = 1;
-				p->RIOSystemUp = 0;
+	case RIO_HOST_FOAD:
+		/*
+		 ** Kill host. This may not be in the final version...
+		 */
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD %d\n", (int) arg);
+		if (!su) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD: Not super user\n");
+			p->RIOError.Error = NOT_SUPER_USER;
+			return -EPERM;
+		}
+		p->RIOHalted = 1;
+		p->RIOSystemUp = 0;
 
-				for ( Host=0; Host<p->RIONumHosts; Host++ ) {
-					 (void)RIOBoardTest( p->RIOHosts[Host].PaddrP, 
-						p->RIOHosts[Host].Caddr, p->RIOHosts[Host].Type, 
-								p->RIOHosts[Host].Slot );
-					 bzero( (caddr_t)&p->RIOHosts[Host].Flags, 
-							((int)&p->RIOHosts[Host].____end_marker____) -
-								 ((int)&p->RIOHosts[Host].Flags) );
-					 p->RIOHosts[Host].Flags  = RC_WAITING;
+		for (Host = 0; Host < p->RIONumHosts; Host++) {
+			(void) RIOBoardTest(p->RIOHosts[Host].PaddrP, p->RIOHosts[Host].Caddr, p->RIOHosts[Host].Type, p->RIOHosts[Host].Slot);
+			bzero((caddr_t) & p->RIOHosts[Host].Flags, ((int) &p->RIOHosts[Host].____end_marker____) - ((int) &p->RIOHosts[Host].Flags));
+			p->RIOHosts[Host].Flags = RC_WAITING;
 #if 0
-					 RIOSetupDataStructs(p);
+			RIOSetupDataStructs(p);
 #endif
-				}
-				RIOFoadWakeup(p);
-				p->RIONumBootPkts = 0;
-				p->RIOBooting = 0;
+		}
+		RIOFoadWakeup(p);
+		p->RIONumBootPkts = 0;
+		p->RIOBooting = 0;
 
 #ifdef RINGBUFFER_SUPPORT
-				for( loop=0; loop<RIO_PORTS; loop++ )
-					if ( p->RIOPortp[loop]->TxRingBuffer )
-						sysfree((void *)p->RIOPortp[loop]->TxRingBuffer, 
-							RIOBufferSize );
+		for (loop = 0; loop < RIO_PORTS; loop++)
+			if (p->RIOPortp[loop]->TxRingBuffer)
+				sysfree((void *) p->RIOPortp[loop]->TxRingBuffer, RIOBufferSize);
 #endif
 #if 0
-				bzero((caddr_t)&p->RIOPortp[0],RIO_PORTS*sizeof(struct Port));
+		bzero((caddr_t) & p->RIOPortp[0], RIO_PORTS * sizeof(struct Port));
 #else
-				printk ("HEEEEELP!\n");
+		printk("HEEEEELP!\n");
 #endif
 
-				for( loop=0; loop<RIO_PORTS; loop++ ) {
+		for (loop = 0; loop < RIO_PORTS; loop++) {
 #if 0
-					p->RIOPortp[loop]->TtyP = &p->channel[loop];
+			p->RIOPortp[loop]->TtyP = &p->channel[loop];
 #endif
-					
-					spin_lock_init(&p->RIOPortp[loop]->portSem);
-					p->RIOPortp[loop]->InUse = NOT_INUSE;
-				}
 
-				p->RIOSystemUp = 0;
-				return retval;
+			spin_lock_init(&p->RIOPortp[loop]->portSem);
+			p->RIOPortp[loop]->InUse = NOT_INUSE;
+		}
 
-			case RIO_DOWNLOAD:
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_DOWNLOAD\n");
-				if ( !su ) {
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Not super user\n");
-					 p->RIOError.Error = NOT_SUPER_USER;
-					 return -EPERM;
-				}
-				if ( copyin((int)arg, (caddr_t)&DownLoad, 
-							sizeof(DownLoad) )==COPYFAIL ) {
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Copy in from user space failed\n");
-					 p->RIOError.Error = COPYIN_FAILED;
-					 return -EFAULT;
-				}
-				rio_dprintk (RIO_DEBUG_CTRL, "Copied in download code for product code 0x%x\n",
-				    DownLoad.ProductCode);
+		p->RIOSystemUp = 0;
+		return retval;
 
-				/*
-				** It is important that the product code is an unsigned object!
-				*/
-				if ( DownLoad.ProductCode > MAX_PRODUCT ) {
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Bad product code %d passed\n",
-							DownLoad.ProductCode);
-					 p->RIOError.Error = NO_SUCH_PRODUCT;
-					 return -ENXIO;
-				}
-				/*
-				** do something!
-				*/
-				retval = (*(RIOBootTable[DownLoad.ProductCode]))(p, &DownLoad);
-										/* <-- Panic */
-				p->RIOHalted = 0;
-				/*
-				** and go back, content with a job well completed.
-				*/
-				return retval;
+	case RIO_DOWNLOAD:
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD\n");
+		if (!su) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Not super user\n");
+			p->RIOError.Error = NOT_SUPER_USER;
+			return -EPERM;
+		}
+		if (copyin((int) arg, (caddr_t) & DownLoad, sizeof(DownLoad)) == COPYFAIL) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Copy in from user space failed\n");
+			p->RIOError.Error = COPYIN_FAILED;
+			return -EFAULT;
+		}
+		rio_dprintk(RIO_DEBUG_CTRL, "Copied in download code for product code 0x%x\n", DownLoad.ProductCode);
 
-			case RIO_PARMS:
-				{
-					uint host;
+		/*
+		 ** It is important that the product code is an unsigned object!
+		 */
+		if (DownLoad.ProductCode > MAX_PRODUCT) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Bad product code %d passed\n", DownLoad.ProductCode);
+			p->RIOError.Error = NO_SUCH_PRODUCT;
+			return -ENXIO;
+		}
+		/*
+		 ** do something!
+		 */
+		retval = (*(RIOBootTable[DownLoad.ProductCode])) (p, &DownLoad);
+		/* <-- Panic */
+		p->RIOHalted = 0;
+		/*
+		 ** and go back, content with a job well completed.
+		 */
+		return retval;
 
-					if (copyin((int)arg, (caddr_t)&host, 
-							sizeof(host) ) == COPYFAIL ) {
-						rio_dprintk (RIO_DEBUG_CTRL, 
-							"RIO_HOST_REQ: Copy in from user space failed\n");
-						p->RIOError.Error = COPYIN_FAILED;
-						return -EFAULT;
-					}
-					/*
-					** Fetch the parmmap
-					*/
-					rio_dprintk (RIO_DEBUG_CTRL, "RIO_PARMS\n");
-					if ( copyout( (caddr_t)p->RIOHosts[host].ParmMapP, 
-								(int)arg, sizeof(PARM_MAP) )==COPYFAIL ) {
-						p->RIOError.Error = COPYOUT_FAILED;
-						rio_dprintk (RIO_DEBUG_CTRL, "RIO_PARMS: Copy out to user space failed\n");
-						return -EFAULT;
-					}
-				}
-				return retval;
+	case RIO_PARMS:
+		{
+			uint host;
 
-			case RIO_HOST_REQ:
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_REQ\n");
-				if (copyin((int)arg, (caddr_t)&HostReq, 
-							sizeof(HostReq) )==COPYFAIL ) {
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
-					 p->RIOError.Error = COPYIN_FAILED;
-					 return -EFAULT;
-				}
-				if ( HostReq.HostNum >= p->RIONumHosts ) {
-					 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_REQ: Illegal host number %d\n",
-							HostReq.HostNum);
-					 return -ENXIO;
-				}
-				rio_dprintk (RIO_DEBUG_CTRL, "Request for host %d\n", HostReq.HostNum);
+			if (copyin((int) arg, (caddr_t) & host, sizeof(host)) == COPYFAIL) {
+				rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
+				p->RIOError.Error = COPYIN_FAILED;
+				return -EFAULT;
+			}
+			/*
+			 ** Fetch the parmmap
+			 */
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS\n");
+			if (copyout((caddr_t) p->RIOHosts[host].ParmMapP, (int) arg, sizeof(PARM_MAP)) == COPYFAIL) {
+				p->RIOError.Error = COPYOUT_FAILED;
+				rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS: Copy out to user space failed\n");
+				return -EFAULT;
+			}
+		}
+		return retval;
 
-				if (copyout((caddr_t)&p->RIOHosts[HostReq.HostNum], 
-					(int)HostReq.HostP,sizeof(struct Host) ) == COPYFAIL) {
-					p->RIOError.Error = COPYOUT_FAILED;
-					rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_REQ: Bad copy to user space\n");
-					return -EFAULT;
-				}
-				return retval;
+	case RIO_HOST_REQ:
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ\n");
+		if (copyin((int) arg, (caddr_t) & HostReq, sizeof(HostReq)) == COPYFAIL) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
+			p->RIOError.Error = COPYIN_FAILED;
+			return -EFAULT;
+		}
+		if (HostReq.HostNum >= p->RIONumHosts) {
+			p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Illegal host number %d\n", HostReq.HostNum);
+			return -ENXIO;
+		}
+		rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostReq.HostNum);
 
-			 case RIO_HOST_DPRAM:
-				rio_dprintk (RIO_DEBUG_CTRL, "Request for DPRAM\n");
-				if ( copyin( (int)arg, (caddr_t)&HostDpRam, 
-								sizeof(HostDpRam) )==COPYFAIL ) {
-					rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Copy in from user space failed\n");
-					p->RIOError.Error = COPYIN_FAILED;
-					return -EFAULT;
-				}
-				if ( HostDpRam.HostNum >= p->RIONumHosts ) {
-					p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
-					rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Illegal host number %d\n",
-										HostDpRam.HostNum);
-					return -ENXIO;
-				}
-				rio_dprintk (RIO_DEBUG_CTRL, "Request for host %d\n", HostDpRam.HostNum);
+		if (copyout((caddr_t) & p->RIOHosts[HostReq.HostNum], (int) HostReq.HostP, sizeof(struct Host)) == COPYFAIL) {
+			p->RIOError.Error = COPYOUT_FAILED;
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Bad copy to user space\n");
+			return -EFAULT;
+		}
+		return retval;
 
-				if (p->RIOHosts[HostDpRam.HostNum].Type == RIO_PCI) {
-					 int off;
-					 /* It's hardware like this that really gets on my tits. */
-					 static unsigned char copy[sizeof(struct DpRam)];
-					for ( off=0; off<sizeof(struct DpRam); off++ )
-						copy[off] = p->RIOHosts[HostDpRam.HostNum].Caddr[off];
-					if ( copyout( (caddr_t)copy, (int)HostDpRam.DpRamP, 
-							sizeof(struct DpRam) ) == COPYFAIL ) {
-						p->RIOError.Error = COPYOUT_FAILED;
-						rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
-						return -EFAULT;
-					}
-				}
-				else if (copyout((caddr_t)p->RIOHosts[HostDpRam.HostNum].Caddr,
-					(int)HostDpRam.DpRamP, 
-						sizeof(struct DpRam) ) == COPYFAIL ) {
-					 p->RIOError.Error = COPYOUT_FAILED;
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
-					 return -EFAULT;
-				}
-				return retval;
+	case RIO_HOST_DPRAM:
+		rio_dprintk(RIO_DEBUG_CTRL, "Request for DPRAM\n");
+		if (copyin((int) arg, (caddr_t) & HostDpRam, sizeof(HostDpRam)) == COPYFAIL) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Copy in from user space failed\n");
+			p->RIOError.Error = COPYIN_FAILED;
+			return -EFAULT;
+		}
+		if (HostDpRam.HostNum >= p->RIONumHosts) {
+			p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Illegal host number %d\n", HostDpRam.HostNum);
+			return -ENXIO;
+		}
+		rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostDpRam.HostNum);
 
-			 case RIO_SET_BUSY:
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_SET_BUSY\n");
-				if ( (int)arg < 0 || (int)arg > 511 ) {
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_SET_BUSY: Bad port number %d\n",(int)arg);
-					 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
-					 return -EINVAL;
-				}
-				rio_spin_lock_irqsave(&PortP->portSem, flags);
-				p->RIOPortp[(int)arg]->State |= RIO_BUSY;
-				rio_spin_unlock_irqrestore( &PortP->portSem , flags);
-				return retval;
+		if (p->RIOHosts[HostDpRam.HostNum].Type == RIO_PCI) {
+			int off;
+			/* It's hardware like this that really gets on my tits. */
+			static unsigned char copy[sizeof(struct DpRam)];
+			for (off = 0; off < sizeof(struct DpRam); off++)
+				copy[off] = p->RIOHosts[HostDpRam.HostNum].Caddr[off];
+			if (copyout((caddr_t) copy, (int) HostDpRam.DpRamP, sizeof(struct DpRam)) == COPYFAIL) {
+				p->RIOError.Error = COPYOUT_FAILED;
+				rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
+				return -EFAULT;
+			}
+		} else if (copyout((caddr_t) p->RIOHosts[HostDpRam.HostNum].Caddr, (int) HostDpRam.DpRamP, sizeof(struct DpRam)) == COPYFAIL) {
+			p->RIOError.Error = COPYOUT_FAILED;
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
+			return -EFAULT;
+		}
+		return retval;
 
-			 case RIO_HOST_PORT:
-				/*
-				** The daemon want port information
-				** (probably for debug reasons)
-				*/
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_PORT\n");
-				if ( copyin((int)arg, (caddr_t)&PortReq, 
-					sizeof(PortReq) )==COPYFAIL ) {
-					rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_PORT: Copy in from user space failed\n");
-					p->RIOError.Error = COPYIN_FAILED;
-					return -EFAULT;
-				}
+	case RIO_SET_BUSY:
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY\n");
+		if ((int) arg < 0 || (int) arg > 511) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY: Bad port number %d\n", (int) arg);
+			p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
+			return -EINVAL;
+		}
+		rio_spin_lock_irqsave(&PortP->portSem, flags);
+		p->RIOPortp[(int) arg]->State |= RIO_BUSY;
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		return retval;
 
-				if (PortReq.SysPort >= RIO_PORTS) { /* SysPort is unsigned */
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_PORT: Illegal port number %d\n",
-											PortReq.SysPort);
-					 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
-					 return -ENXIO;
-				}
-				rio_dprintk (RIO_DEBUG_CTRL, "Request for port %d\n", PortReq.SysPort);
-				if (copyout((caddr_t)p->RIOPortp[PortReq.SysPort], 
-							 (int)PortReq.PortP,
-								sizeof(struct Port) ) == COPYFAIL) {
-					 p->RIOError.Error = COPYOUT_FAILED;
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_PORT: Bad copy to user space\n");
-					 return -EFAULT;
-				}
-				return retval;
+	case RIO_HOST_PORT:
+		/*
+		 ** The daemon want port information
+		 ** (probably for debug reasons)
+		 */
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT\n");
+		if (copyin((int) arg, (caddr_t) & PortReq, sizeof(PortReq)) == COPYFAIL) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Copy in from user space failed\n");
+			p->RIOError.Error = COPYIN_FAILED;
+			return -EFAULT;
+		}
 
-			case RIO_HOST_RUP:
-				/*
-				** The daemon want rup information
-				** (probably for debug reasons)
-				*/
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_RUP\n");
-				if (copyin((int)arg, (caddr_t)&RupReq, 
-						sizeof(RupReq) )==COPYFAIL ) {
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_RUP: Copy in from user space failed\n");
-					 p->RIOError.Error = COPYIN_FAILED;
-					 return -EFAULT;
-				}
-				if (RupReq.HostNum >= p->RIONumHosts) { /* host is unsigned */
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal host number %d\n",
-								RupReq.HostNum);
-					 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
-					 return -ENXIO;
-				}
-				if ( RupReq.RupNum >= MAX_RUP+LINKS_PER_UNIT ) { /* eek! */
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal rup number %d\n",
-							RupReq.RupNum);
-					 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
-					 return -EINVAL;
-				}
-				HostP = &p->RIOHosts[RupReq.HostNum];
+		if (PortReq.SysPort >= RIO_PORTS) {	/* SysPort is unsigned */
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Illegal port number %d\n", PortReq.SysPort);
+			p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
+			return -ENXIO;
+		}
+		rio_dprintk(RIO_DEBUG_CTRL, "Request for port %d\n", PortReq.SysPort);
+		if (copyout((caddr_t) p->RIOPortp[PortReq.SysPort], (int) PortReq.PortP, sizeof(struct Port)) == COPYFAIL) {
+			p->RIOError.Error = COPYOUT_FAILED;
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Bad copy to user space\n");
+			return -EFAULT;
+		}
+		return retval;
 
-				if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_RUP: Host %d not running\n",
-							RupReq.HostNum);
-					 p->RIOError.Error = HOST_NOT_RUNNING;
-					 return -EIO;
-				}
-				rio_dprintk (RIO_DEBUG_CTRL, "Request for rup %d from host %d\n",
-						RupReq.RupNum,RupReq.HostNum);
+	case RIO_HOST_RUP:
+		/*
+		 ** The daemon want rup information
+		 ** (probably for debug reasons)
+		 */
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP\n");
+		if (copyin((int) arg, (caddr_t) & RupReq, sizeof(RupReq)) == COPYFAIL) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Copy in from user space failed\n");
+			p->RIOError.Error = COPYIN_FAILED;
+			return -EFAULT;
+		}
+		if (RupReq.HostNum >= p->RIONumHosts) {	/* host is unsigned */
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal host number %d\n", RupReq.HostNum);
+			p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
+			return -ENXIO;
+		}
+		if (RupReq.RupNum >= MAX_RUP + LINKS_PER_UNIT) {	/* eek! */
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal rup number %d\n", RupReq.RupNum);
+			p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
+			return -EINVAL;
+		}
+		HostP = &p->RIOHosts[RupReq.HostNum];
 
-				if (copyout((caddr_t)HostP->UnixRups[RupReq.RupNum].RupP,
-					(int)RupReq.RupP,sizeof(struct RUP) ) == COPYFAIL) {
-					p->RIOError.Error = COPYOUT_FAILED;
-					rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_RUP: Bad copy to user space\n");
-					return -EFAULT;
-				}
-				return retval;
+		if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Host %d not running\n", RupReq.HostNum);
+			p->RIOError.Error = HOST_NOT_RUNNING;
+			return -EIO;
+		}
+		rio_dprintk(RIO_DEBUG_CTRL, "Request for rup %d from host %d\n", RupReq.RupNum, RupReq.HostNum);
 
-			case RIO_HOST_LPB:
-				/*
-				** The daemon want lpb information
-				** (probably for debug reasons)
-				*/
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_LPB\n");
-				if (copyin((int)arg, (caddr_t)&LpbReq, 
-					sizeof(LpbReq) )==COPYFAIL ) {
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy from user space\n");
-					 p->RIOError.Error = COPYIN_FAILED;
-					 return -EFAULT;
-				}
-				if (LpbReq.Host >= p->RIONumHosts) { /* host is unsigned */
-					rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal host number %d\n",
-							LpbReq.Host);
-					p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
-					return -ENXIO;
-				}
-				if ( LpbReq.Link >= LINKS_PER_UNIT ) { /* eek! */
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal link number %d\n",
-							LpbReq.Link);
-					 p->RIOError.Error = LINK_NUMBER_OUT_OF_RANGE;
-					 return -EINVAL;
-				}
-				HostP = &p->RIOHosts[LpbReq.Host];
+		if (copyout((caddr_t) HostP->UnixRups[RupReq.RupNum].RupP, (int) RupReq.RupP, sizeof(struct RUP)) == COPYFAIL) {
+			p->RIOError.Error = COPYOUT_FAILED;
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Bad copy to user space\n");
+			return -EFAULT;
+		}
+		return retval;
 
-				if ( (HostP->Flags & RUN_STATE) != RC_RUNNING ) {
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_LPB: Host %d not running\n",
-						LpbReq.Host );
-					 p->RIOError.Error = HOST_NOT_RUNNING;
-					 return -EIO;
-				}
-				rio_dprintk (RIO_DEBUG_CTRL, "Request for lpb %d from host %d\n",
-					LpbReq.Link, LpbReq.Host);
+	case RIO_HOST_LPB:
+		/*
+		 ** The daemon want lpb information
+		 ** (probably for debug reasons)
+		 */
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB\n");
+		if (copyin((int) arg, (caddr_t) & LpbReq, sizeof(LpbReq)) == COPYFAIL) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy from user space\n");
+			p->RIOError.Error = COPYIN_FAILED;
+			return -EFAULT;
+		}
+		if (LpbReq.Host >= p->RIONumHosts) {	/* host is unsigned */
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal host number %d\n", LpbReq.Host);
+			p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
+			return -ENXIO;
+		}
+		if (LpbReq.Link >= LINKS_PER_UNIT) {	/* eek! */
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal link number %d\n", LpbReq.Link);
+			p->RIOError.Error = LINK_NUMBER_OUT_OF_RANGE;
+			return -EINVAL;
+		}
+		HostP = &p->RIOHosts[LpbReq.Host];
 
-				if (copyout((caddr_t)&HostP->LinkStrP[LpbReq.Link],
-					(int)LpbReq.LpbP,sizeof(struct LPB) ) == COPYFAIL) {
-					rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy to user space\n");
-					p->RIOError.Error = COPYOUT_FAILED;
-					return -EFAULT;
-				}
-				return retval;
+		if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Host %d not running\n", LpbReq.Host);
+			p->RIOError.Error = HOST_NOT_RUNNING;
+			return -EIO;
+		}
+		rio_dprintk(RIO_DEBUG_CTRL, "Request for lpb %d from host %d\n", LpbReq.Link, LpbReq.Host);
 
-				/*
-				** Here 3 IOCTL's that allow us to change the way in which
-				** rio logs errors. send them just to syslog or send them
-				** to both syslog and console or send them to just the console.
-				**
-				** See RioStrBuf() in util.c for the other half.
-				*/
-			case RIO_SYSLOG_ONLY:
-				p->RIOPrintLogState = PRINT_TO_LOG;	/* Just syslog */
-				return 0;
+		if (copyout((caddr_t) & HostP->LinkStrP[LpbReq.Link], (int) LpbReq.LpbP, sizeof(struct LPB)) == COPYFAIL) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy to user space\n");
+			p->RIOError.Error = COPYOUT_FAILED;
+			return -EFAULT;
+		}
+		return retval;
 
-			case RIO_SYSLOG_CONS:
-				p->RIOPrintLogState = PRINT_TO_LOG_CONS;/* syslog and console */
-				return 0;
+		/*
+		 ** Here 3 IOCTL's that allow us to change the way in which
+		 ** rio logs errors. send them just to syslog or send them
+		 ** to both syslog and console or send them to just the console.
+		 **
+		 ** See RioStrBuf() in util.c for the other half.
+		 */
+	case RIO_SYSLOG_ONLY:
+		p->RIOPrintLogState = PRINT_TO_LOG;	/* Just syslog */
+		return 0;
 
-			case RIO_CONS_ONLY:
-				p->RIOPrintLogState = PRINT_TO_CONS;	/* Just console */
-				return 0;
+	case RIO_SYSLOG_CONS:
+		p->RIOPrintLogState = PRINT_TO_LOG_CONS;	/* syslog and console */
+		return 0;
 
-			case RIO_SIGNALS_ON:
-				if ( p->RIOSignalProcess ) {
-					 p->RIOError.Error = SIGNALS_ALREADY_SET;
-					 return -EBUSY;
-				}
-				p->RIOSignalProcess = getpid();
-				p->RIOPrintDisabled = DONT_PRINT;
-				return retval;
+	case RIO_CONS_ONLY:
+		p->RIOPrintLogState = PRINT_TO_CONS;	/* Just console */
+		return 0;
 
-			case RIO_SIGNALS_OFF:
-				if ( p->RIOSignalProcess != getpid() ) {
-					 p->RIOError.Error = NOT_RECEIVING_PROCESS;
-					 return -EPERM;
-				}
-				rio_dprintk (RIO_DEBUG_CTRL, "Clear signal process to zero\n");
-				p->RIOSignalProcess = 0;
-				return retval;
+	case RIO_SIGNALS_ON:
+		if (p->RIOSignalProcess) {
+			p->RIOError.Error = SIGNALS_ALREADY_SET;
+			return -EBUSY;
+		}
+		p->RIOSignalProcess = getpid();
+		p->RIOPrintDisabled = DONT_PRINT;
+		return retval;
 
-			case RIO_SET_BYTE_MODE:
-				for ( Host=0; Host<p->RIONumHosts; Host++ )
-					 if ( p->RIOHosts[Host].Type == RIO_AT )
-						 p->RIOHosts[Host].Mode &= ~WORD_OPERATION;
-				return retval;
+	case RIO_SIGNALS_OFF:
+		if (p->RIOSignalProcess != getpid()) {
+			p->RIOError.Error = NOT_RECEIVING_PROCESS;
+			return -EPERM;
+		}
+		rio_dprintk(RIO_DEBUG_CTRL, "Clear signal process to zero\n");
+		p->RIOSignalProcess = 0;
+		return retval;
 
-			case RIO_SET_WORD_MODE:
-				for ( Host=0; Host<p->RIONumHosts; Host++ )
-					 if ( p->RIOHosts[Host].Type == RIO_AT )
-						 p->RIOHosts[Host].Mode |= WORD_OPERATION;
-				return retval;
+	case RIO_SET_BYTE_MODE:
+		for (Host = 0; Host < p->RIONumHosts; Host++)
+			if (p->RIOHosts[Host].Type == RIO_AT)
+				p->RIOHosts[Host].Mode &= ~WORD_OPERATION;
+		return retval;
 
-			case RIO_SET_FAST_BUS:
-				for ( Host=0; Host<p->RIONumHosts; Host++ )
-					 if ( p->RIOHosts[Host].Type == RIO_AT )
-						 p->RIOHosts[Host].Mode |= FAST_AT_BUS;
-				return retval;
+	case RIO_SET_WORD_MODE:
+		for (Host = 0; Host < p->RIONumHosts; Host++)
+			if (p->RIOHosts[Host].Type == RIO_AT)
+				p->RIOHosts[Host].Mode |= WORD_OPERATION;
+		return retval;
 
-			case RIO_SET_SLOW_BUS:
-				for ( Host=0; Host<p->RIONumHosts; Host++ )
-					 if ( p->RIOHosts[Host].Type == RIO_AT )
-						 p->RIOHosts[Host].Mode &= ~FAST_AT_BUS;
-				return retval;
+	case RIO_SET_FAST_BUS:
+		for (Host = 0; Host < p->RIONumHosts; Host++)
+			if (p->RIOHosts[Host].Type == RIO_AT)
+				p->RIOHosts[Host].Mode |= FAST_AT_BUS;
+		return retval;
 
-			case RIO_MAP_B50_TO_50:
-			case RIO_MAP_B50_TO_57600:
-			case RIO_MAP_B110_TO_110:
-			case RIO_MAP_B110_TO_115200:
-				rio_dprintk (RIO_DEBUG_CTRL, "Baud rate mapping\n");
-				port = (uint) arg;
-				if ( port < 0 || port > 511 ) {
-					 rio_dprintk (RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", port);
-					 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
-					 return -EINVAL;
-				}
-				rio_spin_lock_irqsave(&PortP->portSem, flags);
-				switch( cmd )
-				{
-					case RIO_MAP_B50_TO_50 :
-						p->RIOPortp[port]->Config |= RIO_MAP_50_TO_50;
-						break;
-					case RIO_MAP_B50_TO_57600 :
-						p->RIOPortp[port]->Config &= ~RIO_MAP_50_TO_50;
-						break;
-					case RIO_MAP_B110_TO_110 :
-						p->RIOPortp[port]->Config |= RIO_MAP_110_TO_110;
-						break;
-					case RIO_MAP_B110_TO_115200 :
-						p->RIOPortp[port]->Config &= ~RIO_MAP_110_TO_110;
-						break;
-				}
-				rio_spin_unlock_irqrestore( &PortP->portSem , flags);
-				return retval;
+	case RIO_SET_SLOW_BUS:
+		for (Host = 0; Host < p->RIONumHosts; Host++)
+			if (p->RIOHosts[Host].Type == RIO_AT)
+				p->RIOHosts[Host].Mode &= ~FAST_AT_BUS;
+		return retval;
 
-			case RIO_STREAM_INFO:
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_STREAM_INFO\n");
-				return -EINVAL;
+	case RIO_MAP_B50_TO_50:
+	case RIO_MAP_B50_TO_57600:
+	case RIO_MAP_B110_TO_110:
+	case RIO_MAP_B110_TO_115200:
+		rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping\n");
+		port = (uint) arg;
+		if (port < 0 || port > 511) {
+			rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", port);
+			p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
+			return -EINVAL;
+		}
+		rio_spin_lock_irqsave(&PortP->portSem, flags);
+		switch (cmd) {
+		case RIO_MAP_B50_TO_50:
+			p->RIOPortp[port]->Config |= RIO_MAP_50_TO_50;
+			break;
+		case RIO_MAP_B50_TO_57600:
+			p->RIOPortp[port]->Config &= ~RIO_MAP_50_TO_50;
+			break;
+		case RIO_MAP_B110_TO_110:
+			p->RIOPortp[port]->Config |= RIO_MAP_110_TO_110;
+			break;
+		case RIO_MAP_B110_TO_115200:
+			p->RIOPortp[port]->Config &= ~RIO_MAP_110_TO_110;
+			break;
+		}
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		return retval;
 
-			case RIO_SEND_PACKET:
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_SEND_PACKET\n");
-				if ( copyin( (int)arg, (caddr_t)&SendPack,
-									sizeof(SendPack) )==COPYFAIL ) {
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_SEND_PACKET: Bad copy from user space\n");
-					 p->RIOError.Error = COPYIN_FAILED;
-					 return -EFAULT;
-				}
-				if ( SendPack.PortNum >= 128 ) {
-					 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
-					 return -ENXIO;
-				}
+	case RIO_STREAM_INFO:
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_STREAM_INFO\n");
+		return -EINVAL;
 
-				PortP = p->RIOPortp[SendPack.PortNum];
-				rio_spin_lock_irqsave(&PortP->portSem, flags);
+	case RIO_SEND_PACKET:
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET\n");
+		if (copyin((int) arg, (caddr_t) & SendPack, sizeof(SendPack)) == COPYFAIL) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET: Bad copy from user space\n");
+			p->RIOError.Error = COPYIN_FAILED;
+			return -EFAULT;
+		}
+		if (SendPack.PortNum >= 128) {
+			p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
+			return -ENXIO;
+		}
 
-				if ( !can_add_transmit(&PacketP,PortP) ) {
-					 p->RIOError.Error = UNIT_IS_IN_USE;
-					 rio_spin_unlock_irqrestore( &PortP->portSem , flags);
-					 return -ENOSPC;
-				}
+		PortP = p->RIOPortp[SendPack.PortNum];
+		rio_spin_lock_irqsave(&PortP->portSem, flags);
 
-				for ( loop=0; loop<(ushort)(SendPack.Len & 127); loop++ )
-					 WBYTE(PacketP->data[loop], SendPack.Data[loop] );
+		if (!can_add_transmit(&PacketP, PortP)) {
+			p->RIOError.Error = UNIT_IS_IN_USE;
+			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+			return -ENOSPC;
+		}
 
-				WBYTE(PacketP->len, SendPack.Len);
+		for (loop = 0; loop < (ushort) (SendPack.Len & 127); loop++)
+			WBYTE(PacketP->data[loop], SendPack.Data[loop]);
 
-				add_transmit( PortP );
-				/*
-				** Count characters transmitted for port statistics reporting
-				*/
-				if (PortP->statsGather)
-					 PortP->txchars += (SendPack.Len & 127);
-				rio_spin_unlock_irqrestore( &PortP->portSem , flags);
-				return retval;
+		WBYTE(PacketP->len, SendPack.Len);
 
-			case RIO_NO_MESG:
-				if ( su )
-					 p->RIONoMessage = 1;
-				return su ? 0 : -EPERM;
+		add_transmit(PortP);
+		/*
+		 ** Count characters transmitted for port statistics reporting
+		 */
+		if (PortP->statsGather)
+			PortP->txchars += (SendPack.Len & 127);
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		return retval;
 
-			case RIO_MESG:
-				if ( su )
-					p->RIONoMessage = 0;
-				return su ? 0 : -EPERM;
+	case RIO_NO_MESG:
+		if (su)
+			p->RIONoMessage = 1;
+		return su ? 0 : -EPERM;
 
-			case RIO_WHAT_MESG:
-				if ( copyout( (caddr_t)&p->RIONoMessage, (int)arg, 
-					sizeof(p->RIONoMessage) )==COPYFAIL ) {
-					rio_dprintk (RIO_DEBUG_CTRL, "RIO_WHAT_MESG: Bad copy to user space\n");
-					p->RIOError.Error = COPYOUT_FAILED;
-					return -EFAULT;
-				}
-				return 0;
+	case RIO_MESG:
+		if (su)
+			p->RIONoMessage = 0;
+		return su ? 0 : -EPERM;
 
-			case RIO_MEM_DUMP :
-				if (copyin((int)arg, (caddr_t)&SubCmd, 
-						sizeof(struct SubCmdStruct)) == COPYFAIL) {
-					 p->RIOError.Error = COPYIN_FAILED;
-					 return -EFAULT;
-				}
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_MEM_DUMP host %d rup %d addr %x\n", 
-						SubCmd.Host, SubCmd.Rup, SubCmd.Addr);
+	case RIO_WHAT_MESG:
+		if (copyout((caddr_t) & p->RIONoMessage, (int) arg, sizeof(p->RIONoMessage)) == COPYFAIL) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_WHAT_MESG: Bad copy to user space\n");
+			p->RIOError.Error = COPYOUT_FAILED;
+			return -EFAULT;
+		}
+		return 0;
 
-				if (SubCmd.Rup >= MAX_RUP+LINKS_PER_UNIT ) {
-					 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
-					 return -EINVAL;
-				}
+	case RIO_MEM_DUMP:
+		if (copyin((int) arg, (caddr_t) & SubCmd, sizeof(struct SubCmdStruct)) == COPYFAIL) {
+			p->RIOError.Error = COPYIN_FAILED;
+			return -EFAULT;
+		}
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP host %d rup %d addr %x\n", SubCmd.Host, SubCmd.Rup, SubCmd.Addr);
 
-				if (SubCmd.Host >= p->RIONumHosts ) {
-					 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
-					 return -EINVAL;
-				}
+		if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) {
+			p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
+			return -EINVAL;
+		}
 
-				port = p->RIOHosts[SubCmd.Host].
-								UnixRups[SubCmd.Rup].BaseSysPort;
+		if (SubCmd.Host >= p->RIONumHosts) {
+			p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
+			return -EINVAL;
+		}
 
-				PortP = p->RIOPortp[port];
+		port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort;
 
-				rio_spin_lock_irqsave(&PortP->portSem, flags);
+		PortP = p->RIOPortp[port];
 
-				if ( RIOPreemptiveCmd(p,  PortP, MEMDUMP ) == RIO_FAIL ) {
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_MEM_DUMP failed\n");
-					 rio_spin_unlock_irqrestore( &PortP->portSem , flags);
-					 return -EBUSY;
-				}
-				else
-					 PortP->State |= RIO_BUSY;
+		rio_spin_lock_irqsave(&PortP->portSem, flags);
 
-				rio_spin_unlock_irqrestore( &PortP->portSem , flags);
-				if ( copyout( (caddr_t)p->RIOMemDump, (int)arg, 
-							MEMDUMP_SIZE) == COPYFAIL ) {
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_MEM_DUMP copy failed\n");
-					 p->RIOError.Error = COPYOUT_FAILED;
-					 return -EFAULT;
-				}
-				return 0;
+		if (RIOPreemptiveCmd(p, PortP, MEMDUMP) == RIO_FAIL) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP failed\n");
+			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+			return -EBUSY;
+		} else
+			PortP->State |= RIO_BUSY;
 
-			case RIO_TICK:
-				if ((int)arg < 0 || (int)arg >= p->RIONumHosts)
-					 return -EINVAL;
-				rio_dprintk (RIO_DEBUG_CTRL, "Set interrupt for host %d\n", (int)arg);
-				WBYTE(p->RIOHosts[(int)arg].SetInt , 0xff);
-				return 0;
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		if (copyout((caddr_t) p->RIOMemDump, (int) arg, MEMDUMP_SIZE) == COPYFAIL) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP copy failed\n");
+			p->RIOError.Error = COPYOUT_FAILED;
+			return -EFAULT;
+		}
+		return 0;
 
-			case RIO_TOCK:
-				if ((int)arg < 0 || (int)arg >= p->RIONumHosts)
-					 return -EINVAL;
-				rio_dprintk (RIO_DEBUG_CTRL, "Clear interrupt for host %d\n", (int)arg);
-				WBYTE((p->RIOHosts[(int)arg].ResetInt) , 0xff);
-				return 0;
+	case RIO_TICK:
+		if ((int) arg < 0 || (int) arg >= p->RIONumHosts)
+			return -EINVAL;
+		rio_dprintk(RIO_DEBUG_CTRL, "Set interrupt for host %d\n", (int) arg);
+		WBYTE(p->RIOHosts[(int) arg].SetInt, 0xff);
+		return 0;
 
-			case RIO_READ_CHECK:
-				/* Check reads for pkts with data[0] the same */
-				p->RIOReadCheck = !p->RIOReadCheck;
-				if (copyout((caddr_t)&p->RIOReadCheck,(int)arg,
-							sizeof(uint))== COPYFAIL) {
-					 p->RIOError.Error = COPYOUT_FAILED;
-					 return -EFAULT;
-				}
-				return 0;
+	case RIO_TOCK:
+		if ((int) arg < 0 || (int) arg >= p->RIONumHosts)
+			return -EINVAL;
+		rio_dprintk(RIO_DEBUG_CTRL, "Clear interrupt for host %d\n", (int) arg);
+		WBYTE((p->RIOHosts[(int) arg].ResetInt), 0xff);
+		return 0;
 
-			case RIO_READ_REGISTER :
-				if (copyin((int)arg, (caddr_t)&SubCmd, 
-							sizeof(struct SubCmdStruct)) == COPYFAIL) {
-					 p->RIOError.Error = COPYIN_FAILED;
-					 return -EFAULT;
-				}
-				rio_dprintk (RIO_DEBUG_CTRL, "RIO_READ_REGISTER host %d rup %d port %d reg %x\n", 
-						SubCmd.Host, SubCmd.Rup, SubCmd.Port, SubCmd.Addr);
+	case RIO_READ_CHECK:
+		/* Check reads for pkts with data[0] the same */
+		p->RIOReadCheck = !p->RIOReadCheck;
+		if (copyout((caddr_t) & p->RIOReadCheck, (int) arg, sizeof(uint)) == COPYFAIL) {
+			p->RIOError.Error = COPYOUT_FAILED;
+			return -EFAULT;
+		}
+		return 0;
 
-				if (SubCmd.Port > 511) {
-					 rio_dprintk (RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", 
-								SubCmd.Port);
-					 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
-					 return -EINVAL;
-				}
+	case RIO_READ_REGISTER:
+		if (copyin((int) arg, (caddr_t) & SubCmd, sizeof(struct SubCmdStruct)) == COPYFAIL) {
+			p->RIOError.Error = COPYIN_FAILED;
+			return -EFAULT;
+		}
+		rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER host %d rup %d port %d reg %x\n", SubCmd.Host, SubCmd.Rup, SubCmd.Port, SubCmd.Addr);
 
-				if (SubCmd.Rup >= MAX_RUP+LINKS_PER_UNIT ) {
-					 p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
-					 return -EINVAL;
-				}
+		if (SubCmd.Port > 511) {
+			rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", SubCmd.Port);
+			p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
+			return -EINVAL;
+		}
 
-				if (SubCmd.Host >= p->RIONumHosts ) {
-					 p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
-					 return -EINVAL;
-				}
+		if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) {
+			p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
+			return -EINVAL;
+		}
 
-				port = p->RIOHosts[SubCmd.Host].
-						UnixRups[SubCmd.Rup].BaseSysPort + SubCmd.Port;
-				PortP = p->RIOPortp[port];
+		if (SubCmd.Host >= p->RIONumHosts) {
+			p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
+			return -EINVAL;
+		}
 
-				rio_spin_lock_irqsave(&PortP->portSem, flags);
+		port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort + SubCmd.Port;
+		PortP = p->RIOPortp[port];
 
-				if (RIOPreemptiveCmd(p, PortP, READ_REGISTER) == RIO_FAIL) {
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_READ_REGISTER failed\n");
-					 rio_spin_unlock_irqrestore( &PortP->portSem , flags);
-					 return -EBUSY;
-				}
-				else
-					 PortP->State |= RIO_BUSY;
+		rio_spin_lock_irqsave(&PortP->portSem, flags);
 
-				rio_spin_unlock_irqrestore( &PortP->portSem , flags);
-				if (copyout((caddr_t)&p->CdRegister, (int)arg, 
-							sizeof(uint)) == COPYFAIL ) {
-					 rio_dprintk (RIO_DEBUG_CTRL, "RIO_READ_REGISTER copy failed\n");
-					 p->RIOError.Error = COPYOUT_FAILED;
-					 return -EFAULT;
-				}
-				return 0;
-				/*
-				** rio_make_dev: given port number (0-511) ORed with port type
-				** (RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT) return dev_t
-				** value to pass to mknod to create the correct device node.
-				*/
-			case RIO_MAKE_DEV:
-				{
-					uint port = (uint)arg & RIO_MODEM_MASK;
+		if (RIOPreemptiveCmd(p, PortP, READ_REGISTER) == RIO_FAIL) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER failed\n");
+			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+			return -EBUSY;
+		} else
+			PortP->State |= RIO_BUSY;
 
-					switch ( (uint)arg & RIO_DEV_MASK ) {
-						case RIO_DEV_DIRECT:
-							arg = (caddr_t)drv_makedev(MAJOR(dev), port);
-							rio_dprintk (RIO_DEBUG_CTRL, "Makedev direct 0x%x is 0x%x\n",port, (int)arg);
-							return (int)arg;
-					 	case RIO_DEV_MODEM:
-							arg =  (caddr_t)drv_makedev(MAJOR(dev), (port|RIO_MODEM_BIT) );
-							rio_dprintk (RIO_DEBUG_CTRL, "Makedev modem 0x%x is 0x%x\n",port, (int)arg);
-							return (int)arg;
-						case RIO_DEV_XPRINT:
-							arg = (caddr_t)drv_makedev(MAJOR(dev), port);
-							rio_dprintk (RIO_DEBUG_CTRL, "Makedev printer 0x%x is 0x%x\n",port, (int)arg);
-							return (int)arg;
-					}
-					rio_dprintk (RIO_DEBUG_CTRL, "MAKE Device is called\n");
-					return -EINVAL;
-				}
-				/*
-				** rio_minor: given a dev_t from a stat() call, return
-				** the port number (0-511) ORed with the port type
-				** ( RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT )
-				*/
-			case RIO_MINOR:
-				{
-					dev_t dv;
-					int mino;
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		if (copyout((caddr_t) & p->CdRegister, (int) arg, sizeof(uint)) == COPYFAIL) {
+			rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER copy failed\n");
+			p->RIOError.Error = COPYOUT_FAILED;
+			return -EFAULT;
+		}
+		return 0;
+		/*
+		 ** rio_make_dev: given port number (0-511) ORed with port type
+		 ** (RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT) return dev_t
+		 ** value to pass to mknod to create the correct device node.
+		 */
+	case RIO_MAKE_DEV:
+		{
+			uint port = (uint) arg & RIO_MODEM_MASK;
 
-					dv = (dev_t)((int)arg);
-					mino = RIO_UNMODEM(dv);
+			switch ((uint) arg & RIO_DEV_MASK) {
+			case RIO_DEV_DIRECT:
+				arg = (caddr_t) drv_makedev(MAJOR(dev), port);
+				rio_dprintk(RIO_DEBUG_CTRL, "Makedev direct 0x%x is 0x%x\n", port, (int) arg);
+				return (int) arg;
+			case RIO_DEV_MODEM:
+				arg = (caddr_t) drv_makedev(MAJOR(dev), (port | RIO_MODEM_BIT));
+				rio_dprintk(RIO_DEBUG_CTRL, "Makedev modem 0x%x is 0x%x\n", port, (int) arg);
+				return (int) arg;
+			case RIO_DEV_XPRINT:
+				arg = (caddr_t) drv_makedev(MAJOR(dev), port);
+				rio_dprintk(RIO_DEBUG_CTRL, "Makedev printer 0x%x is 0x%x\n", port, (int) arg);
+				return (int) arg;
+			}
+			rio_dprintk(RIO_DEBUG_CTRL, "MAKE Device is called\n");
+			return -EINVAL;
+		}
+		/*
+		 ** rio_minor: given a dev_t from a stat() call, return
+		 ** the port number (0-511) ORed with the port type
+		 ** ( RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT )
+		 */
+	case RIO_MINOR:
+		{
+			dev_t dv;
+			int mino;
 
-					if ( RIO_ISMODEM(dv) ) {
-						rio_dprintk (RIO_DEBUG_CTRL, "Minor for device 0x%x: modem %d\n", dv, mino);
-						arg = (caddr_t)(mino | RIO_DEV_MODEM);
-					}
-					else {
-						rio_dprintk (RIO_DEBUG_CTRL, "Minor for device 0x%x: direct %d\n", dv, mino);
-						arg = (caddr_t)(mino | RIO_DEV_DIRECT);
-					}
-					return (int)arg;
-				}
+			dv = (dev_t) ((int) arg);
+			mino = RIO_UNMODEM(dv);
+
+			if (RIO_ISMODEM(dv)) {
+				rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: modem %d\n", dv, mino);
+				arg = (caddr_t) (mino | RIO_DEV_MODEM);
+			} else {
+				rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: direct %d\n", dv, mino);
+				arg = (caddr_t) (mino | RIO_DEV_DIRECT);
+			}
+			return (int) arg;
+		}
 	}
-	rio_dprintk (RIO_DEBUG_CTRL, "INVALID DAEMON IOCTL 0x%x\n",cmd);
+	rio_dprintk(RIO_DEBUG_CTRL, "INVALID DAEMON IOCTL 0x%x\n", cmd);
 	p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
 
-	func_exit ();
+	func_exit();
 	return -EINVAL;
 }
 
 /*
 ** Pre-emptive commands go on RUPs and are only one byte long.
 */
-int
-RIOPreemptiveCmd(p, PortP, Cmd)
-struct rio_info *	p;
+int RIOPreemptiveCmd(p, PortP, Cmd)
+struct rio_info *p;
 struct Port *PortP;
 uchar Cmd;
 {
@@ -1766,104 +1654,99 @@
 	int port;
 
 #ifdef CHECK
-	CheckPortP( PortP );
+	CheckPortP(PortP);
 #endif
 
-	if ( PortP->State & RIO_DELETED ) {
-		rio_dprintk (RIO_DEBUG_CTRL, "Preemptive command to deleted RTA ignored\n");
+	if (PortP->State & RIO_DELETED) {
+		rio_dprintk(RIO_DEBUG_CTRL, "Preemptive command to deleted RTA ignored\n");
 		return RIO_FAIL;
 	}
 
-	if (((int)((char)PortP->InUse) == -1) || ! (CmdBlkP = RIOGetCmdBlk()) ) {
-		rio_dprintk (RIO_DEBUG_CTRL, "Cannot allocate command block for command %d on port %d\n",
-		       Cmd, PortP->PortNum);
+	if (((int) ((char) PortP->InUse) == -1) || !(CmdBlkP = RIOGetCmdBlk())) {
+		rio_dprintk(RIO_DEBUG_CTRL, "Cannot allocate command block for command %d on port %d\n", Cmd, PortP->PortNum);
 		return RIO_FAIL;
 	}
 
-	rio_dprintk (RIO_DEBUG_CTRL, "Command blk 0x%x - InUse now %d\n", 
-	       (int)CmdBlkP,PortP->InUse);
+	rio_dprintk(RIO_DEBUG_CTRL, "Command blk 0x%x - InUse now %d\n", (int) CmdBlkP, PortP->InUse);
 
-	PktCmdP = (struct PktCmd_M *)&CmdBlkP->Packet.data[0];
+	PktCmdP = (struct PktCmd_M *) &CmdBlkP->Packet.data[0];
 
-	CmdBlkP->Packet.src_unit  = 0;
+	CmdBlkP->Packet.src_unit = 0;
 	if (PortP->SecondBlock)
 		rup = PortP->ID2;
 	else
 		rup = PortP->RupNum;
 	CmdBlkP->Packet.dest_unit = rup;
-	CmdBlkP->Packet.src_port  = COMMAND_RUP;
+	CmdBlkP->Packet.src_port = COMMAND_RUP;
 	CmdBlkP->Packet.dest_port = COMMAND_RUP;
-	CmdBlkP->Packet.len	  = PKT_CMD_BIT | 2;
-	CmdBlkP->PostFuncP	= RIOUnUse;
-	CmdBlkP->PostArg	= (int)PortP;
-	PktCmdP->Command	= Cmd;
-	port				= PortP->HostPort % (ushort)PORTS_PER_RTA;
+	CmdBlkP->Packet.len = PKT_CMD_BIT | 2;
+	CmdBlkP->PostFuncP = RIOUnUse;
+	CmdBlkP->PostArg = (int) PortP;
+	PktCmdP->Command = Cmd;
+	port = PortP->HostPort % (ushort) PORTS_PER_RTA;
 	/*
-	** Index ports 8-15 for 2nd block of 16 port RTA.
-	*/
+	 ** Index ports 8-15 for 2nd block of 16 port RTA.
+	 */
 	if (PortP->SecondBlock)
 		port += (ushort) PORTS_PER_RTA;
-	PktCmdP->PhbNum	   = port;
+	PktCmdP->PhbNum = port;
 
-	switch ( Cmd ) {
-		case MEMDUMP:
-			rio_dprintk (RIO_DEBUG_CTRL, "Queue MEMDUMP command blk 0x%x (addr 0x%x)\n",
-			       (int)CmdBlkP, (int)SubCmd.Addr);
-			PktCmdP->SubCommand		= MEMDUMP;
-			PktCmdP->SubAddr		= SubCmd.Addr;
-			break;
-		case FCLOSE:
-			rio_dprintk (RIO_DEBUG_CTRL, "Queue FCLOSE command blk 0x%x\n",(int)CmdBlkP);
-			break;
-		case READ_REGISTER:
-			rio_dprintk (RIO_DEBUG_CTRL, "Queue READ_REGISTER (0x%x) command blk 0x%x\n",
-		 		(int)SubCmd.Addr, (int)CmdBlkP);
-			PktCmdP->SubCommand		= READ_REGISTER;
-			PktCmdP->SubAddr		= SubCmd.Addr;
-			break;
-		case RESUME:
-			rio_dprintk (RIO_DEBUG_CTRL, "Queue RESUME command blk 0x%x\n",(int)CmdBlkP);
-			break;
-		case RFLUSH:
-			rio_dprintk (RIO_DEBUG_CTRL, "Queue RFLUSH command blk 0x%x\n",(int)CmdBlkP);
-			CmdBlkP->PostFuncP = RIORFlushEnable;
-			break;
-		case SUSPEND:
-			rio_dprintk (RIO_DEBUG_CTRL, "Queue SUSPEND command blk 0x%x\n",(int)CmdBlkP);
-			break;
+	switch (Cmd) {
+	case MEMDUMP:
+		rio_dprintk(RIO_DEBUG_CTRL, "Queue MEMDUMP command blk 0x%x (addr 0x%x)\n", (int) CmdBlkP, (int) SubCmd.Addr);
+		PktCmdP->SubCommand = MEMDUMP;
+		PktCmdP->SubAddr = SubCmd.Addr;
+		break;
+	case FCLOSE:
+		rio_dprintk(RIO_DEBUG_CTRL, "Queue FCLOSE command blk 0x%x\n", (int) CmdBlkP);
+		break;
+	case READ_REGISTER:
+		rio_dprintk(RIO_DEBUG_CTRL, "Queue READ_REGISTER (0x%x) command blk 0x%x\n", (int) SubCmd.Addr, (int) CmdBlkP);
+		PktCmdP->SubCommand = READ_REGISTER;
+		PktCmdP->SubAddr = SubCmd.Addr;
+		break;
+	case RESUME:
+		rio_dprintk(RIO_DEBUG_CTRL, "Queue RESUME command blk 0x%x\n", (int) CmdBlkP);
+		break;
+	case RFLUSH:
+		rio_dprintk(RIO_DEBUG_CTRL, "Queue RFLUSH command blk 0x%x\n", (int) CmdBlkP);
+		CmdBlkP->PostFuncP = RIORFlushEnable;
+		break;
+	case SUSPEND:
+		rio_dprintk(RIO_DEBUG_CTRL, "Queue SUSPEND command blk 0x%x\n", (int) CmdBlkP);
+		break;
 
-		case MGET :
-			rio_dprintk (RIO_DEBUG_CTRL, "Queue MGET command blk 0x%x\n", (int)CmdBlkP);
-			break;
+	case MGET:
+		rio_dprintk(RIO_DEBUG_CTRL, "Queue MGET command blk 0x%x\n", (int) CmdBlkP);
+		break;
 
-		case MSET :
-		case MBIC :
-		case MBIS :
-			CmdBlkP->Packet.data[4] = (char) PortP->ModemLines;
-			rio_dprintk (RIO_DEBUG_CTRL, "Queue MSET/MBIC/MBIS command blk 0x%x\n", (int)CmdBlkP);
-			break;
+	case MSET:
+	case MBIC:
+	case MBIS:
+		CmdBlkP->Packet.data[4] = (char) PortP->ModemLines;
+		rio_dprintk(RIO_DEBUG_CTRL, "Queue MSET/MBIC/MBIS command blk 0x%x\n", (int) CmdBlkP);
+		break;
 
-		case WFLUSH:
-			/*
-			** If we have queued up the maximum number of Write flushes
-			** allowed then we should not bother sending any more to the
-			** RTA.
-			*/
-			if ((int)((char)PortP->WflushFlag) == (int)-1) {
-				rio_dprintk (RIO_DEBUG_CTRL, "Trashed WFLUSH, WflushFlag about to wrap!");
-				RIOFreeCmdBlk(CmdBlkP);
-				return(RIO_FAIL);
-			} else {
-				rio_dprintk (RIO_DEBUG_CTRL, "Queue WFLUSH command blk 0x%x\n",
-				       (int)CmdBlkP);
-				CmdBlkP->PostFuncP = RIOWFlushMark;
-			}
-			break;
+	case WFLUSH:
+		/*
+		 ** If we have queued up the maximum number of Write flushes
+		 ** allowed then we should not bother sending any more to the
+		 ** RTA.
+		 */
+		if ((int) ((char) PortP->WflushFlag) == (int) -1) {
+			rio_dprintk(RIO_DEBUG_CTRL, "Trashed WFLUSH, WflushFlag about to wrap!");
+			RIOFreeCmdBlk(CmdBlkP);
+			return (RIO_FAIL);
+		} else {
+			rio_dprintk(RIO_DEBUG_CTRL, "Queue WFLUSH command blk 0x%x\n", (int) CmdBlkP);
+			CmdBlkP->PostFuncP = RIOWFlushMark;
+		}
+		break;
 	}
 
 	PortP->InUse++;
 
-	Ret = RIOQueueCmdBlk( PortP->HostP, rup, CmdBlkP );
+	Ret = RIOQueueCmdBlk(PortP->HostP, rup, CmdBlkP);
 
 	return Ret;
 }
diff --git a/drivers/char/rio/riodrvr.h b/drivers/char/rio/riodrvr.h
index bc38ac5..663ee09 100644
--- a/drivers/char/rio/riodrvr.h
+++ b/drivers/char/rio/riodrvr.h
@@ -33,7 +33,7 @@
 #ifndef __riodrvr_h
 #define __riodrvr_h
 
-#include <asm/param.h>	/* for HZ */
+#include <asm/param.h>		/* for HZ */
 
 #ifdef SCCS_LABELS
 static char *_riodrvr_h_sccs_ = "@(#)riodrvr.h	1.3";
@@ -44,15 +44,15 @@
 
 
 struct rio_info {
-	int			mode;			/* Intr or polled, word/byte */
-	spinlock_t		RIOIntrSem;		/* Interrupt thread sem */
-	int			current_chan;		/* current channel */
-	int			RIOFailed;		/* Not initialised ? */
-	int			RIOInstallAttempts;	/* no. of rio-install() calls */
-	int			RIOLastPCISearch;	/* status of last search */
-	int			RIONumHosts;		/* Number of RIO Hosts */
-	struct Host		* RIOHosts;		/* RIO Host values */
-	struct Port		**RIOPortp;		/* RIO port values */
+	int mode;		/* Intr or polled, word/byte */
+	spinlock_t RIOIntrSem;	/* Interrupt thread sem */
+	int current_chan;	/* current channel */
+	int RIOFailed;		/* Not initialised ? */
+	int RIOInstallAttempts;	/* no. of rio-install() calls */
+	int RIOLastPCISearch;	/* status of last search */
+	int RIONumHosts;	/* Number of RIO Hosts */
+	struct Host *RIOHosts;	/* RIO Host values */
+	struct Port **RIOPortp;	/* RIO port values */
 /*
 ** 02.03.1999 ARG - ESIL 0820 fix
 ** We no longer use RIOBootMode
@@ -60,9 +60,9 @@
 	int			RIOBootMode;		* RIO boot mode *
 **
 */
-	int			RIOPrintDisabled;	/* RIO printing disabled ? */
-	int			RIOPrintLogState;	/* RIO printing state ? */
-	int			RIOPolling;		/* Polling ? */
+	int RIOPrintDisabled;	/* RIO printing disabled ? */
+	int RIOPrintLogState;	/* RIO printing state ? */
+	int RIOPolling;		/* Polling ? */
 /*
 ** 09.12.1998 ARG - ESIL 0776 part fix
 ** The 'RIO_QUICK_CHECK' ioctl was using RIOHalted.
@@ -70,61 +70,61 @@
 ** updated in RIOConCon() - to keep track of RTA connections/disconnections.
 ** 'RIO_QUICK_CHECK' now returns the value of RIORtaDisCons.
 */
-	int			RIOHalted;		/* halted ? */
-	int			RIORtaDisCons;		/* RTA connections/disconnections */
-	uint			RIOReadCheck;		/* Rio read check */
-	uint			RIONoMessage;		/* To display message or not */
-	uint			RIONumBootPkts;		/* how many packets for an RTA */
-	uint			RIOBootCount; 		/* size of RTA code */
-	uint			RIOBooting;		/* count of outstanding boots */
-	uint			RIOSystemUp;		/* Booted ?? */
-	uint			RIOCounting;		/* for counting interrupts */
-	uint			RIOIntCount;		/* # of intr since last check */
-	uint			RIOTxCount;		/* number of xmit intrs  */
-	uint			RIORxCount;		/* number of rx intrs */
-	uint			RIORupCount;		/* number of rup intrs */
-	int			RIXTimer; 
-	int			RIOBufferSize;		/* Buffersize */
-	int			RIOBufferMask;		/* Buffersize */
+	int RIOHalted;		/* halted ? */
+	int RIORtaDisCons;	/* RTA connections/disconnections */
+	uint RIOReadCheck;	/* Rio read check */
+	uint RIONoMessage;	/* To display message or not */
+	uint RIONumBootPkts;	/* how many packets for an RTA */
+	uint RIOBootCount;	/* size of RTA code */
+	uint RIOBooting;	/* count of outstanding boots */
+	uint RIOSystemUp;	/* Booted ?? */
+	uint RIOCounting;	/* for counting interrupts */
+	uint RIOIntCount;	/* # of intr since last check */
+	uint RIOTxCount;	/* number of xmit intrs  */
+	uint RIORxCount;	/* number of rx intrs */
+	uint RIORupCount;	/* number of rup intrs */
+	int RIXTimer;
+	int RIOBufferSize;	/* Buffersize */
+	int RIOBufferMask;	/* Buffersize */
 
-	int			RIOFirstMajor;		/* First host card's major no */
+	int RIOFirstMajor;	/* First host card's major no */
 
-	uint			RIOLastPortsMapped;	/* highest port number known */
-	uint			RIOFirstPortsMapped;	/* lowest port number known */
+	uint RIOLastPortsMapped;	/* highest port number known */
+	uint RIOFirstPortsMapped;	/* lowest port number known */
 
-	uint			RIOLastPortsBooted;	/* highest port number running */
-	uint			RIOFirstPortsBooted;	/* lowest port number running */
+	uint RIOLastPortsBooted;	/* highest port number running */
+	uint RIOFirstPortsBooted;	/* lowest port number running */
 
-	uint			RIOLastPortsOpened;	/* highest port number running */
-	uint			RIOFirstPortsOpened;	/* lowest port number running */
+	uint RIOLastPortsOpened;	/* highest port number running */
+	uint RIOFirstPortsOpened;	/* lowest port number running */
 
 	/* Flag to say that the topology information has been changed. */
-	uint			RIOQuickCheck; 
-	uint			CdRegister;		/* ??? */
-	int			RIOSignalProcess;	/* Signalling process */
-	int			rio_debug;		/* To debug ... */
-	int			RIODebugWait;		/* For what ??? */
-	int			tpri;			/* Thread prio */
-	int			tid;			/* Thread id */
-	uint			_RIO_Polled;		/* Counter for polling */
-	uint			_RIO_Interrupted;	/* Counter for interrupt */
-	int			intr_tid;		/* iointset return value */
-	int			TxEnSem;		/* TxEnable Semaphore */
+	uint RIOQuickCheck;
+	uint CdRegister;	/* ??? */
+	int RIOSignalProcess;	/* Signalling process */
+	int rio_debug;		/* To debug ... */
+	int RIODebugWait;	/* For what ??? */
+	int tpri;		/* Thread prio */
+	int tid;		/* Thread id */
+	uint _RIO_Polled;	/* Counter for polling */
+	uint _RIO_Interrupted;	/* Counter for interrupt */
+	int intr_tid;		/* iointset return value */
+	int TxEnSem;		/* TxEnable Semaphore */
 
 
-	struct Error		RIOError;		/* to Identify what went wrong */ 
-	struct Conf		RIOConf;		/* Configuration ??? */
-	struct ttystatics	channel[RIO_PORTS];	/* channel information */
-	char			RIOBootPackets[1+(SIXTY_FOUR_K/RTA_BOOT_DATA_SIZE)]
-								[RTA_BOOT_DATA_SIZE];
-	struct Map		RIOConnectTable[TOTAL_MAP_ENTRIES];
-	struct Map		RIOSavedTable[TOTAL_MAP_ENTRIES];
+	struct Error RIOError;	/* to Identify what went wrong */
+	struct Conf RIOConf;	/* Configuration ??? */
+	struct ttystatics channel[RIO_PORTS];	/* channel information */
+	char RIOBootPackets[1 + (SIXTY_FOUR_K / RTA_BOOT_DATA_SIZE)]
+	    [RTA_BOOT_DATA_SIZE];
+	struct Map RIOConnectTable[TOTAL_MAP_ENTRIES];
+	struct Map RIOSavedTable[TOTAL_MAP_ENTRIES];
 
 	/* RTA to host binding table for master/slave operation */
-	ulong			RIOBindTab[MAX_RTA_BINDINGS];
+	ulong RIOBindTab[MAX_RTA_BINDINGS];
 	/* RTA memory dump variable */
-	uchar			RIOMemDump[MEMDUMP_SIZE]; 
-	struct ModuleInfo 	RIOModuleTypes[MAX_MODULE_TYPES];
+	uchar RIOMemDump[MEMDUMP_SIZE];
+	struct ModuleInfo RIOModuleTypes[MAX_MODULE_TYPES];
 
 };
 
@@ -141,4 +141,4 @@
 #define WRBYTE(x,y)		*(volatile unsigned char *)((x)) = \
 					(unsigned char)(y)
 
-#endif	/* __riodrvr.h */
+#endif				/* __riodrvr.h */
diff --git a/drivers/char/rio/rioinfo.h b/drivers/char/rio/rioinfo.h
index e08421c..8de7966 100644
--- a/drivers/char/rio/rioinfo.h
+++ b/drivers/char/rio/rioinfo.h
@@ -41,29 +41,29 @@
 ** Host card data structure
 */
 struct RioHostInfo {
-	long	location;	/* RIO Card Base I/O address */
-	long	vector;		/* RIO Card IRQ vector */
-	int	bus;		/* ISA/EISA/MCA/PCI */
-	int	mode;		/* pointer to host mode - INTERRUPT / POLLED */
+	long location;		/* RIO Card Base I/O address */
+	long vector;		/* RIO Card IRQ vector */
+	int bus;		/* ISA/EISA/MCA/PCI */
+	int mode;		/* pointer to host mode - INTERRUPT / POLLED */
 	struct old_sgttyb
-		* Sg;		/* pointer to default term characteristics */
+	*Sg;			/* pointer to default term characteristics */
 };
 
 
 /* Mode in rio device info */
-#define INTERRUPTED_MODE	0x01		/* Interrupt is generated */
-#define POLLED_MODE		0x02		/* No interrupt */
-#define AUTO_MODE		0x03		/* Auto mode */
+#define INTERRUPTED_MODE	0x01	/* Interrupt is generated */
+#define POLLED_MODE		0x02	/* No interrupt */
+#define AUTO_MODE		0x03	/* Auto mode */
 
-#define WORD_ACCESS_MODE	0x10		/* Word Access Mode */
-#define BYTE_ACCESS_MODE	0x20		/* Byte Access Mode */
+#define WORD_ACCESS_MODE	0x10	/* Word Access Mode */
+#define BYTE_ACCESS_MODE	0x20	/* Byte Access Mode */
 
 
 /* Bus type that RIO supports */
-#define ISA_BUS			0x01		/* The card is ISA */
-#define EISA_BUS		0x02		/* The card is EISA */
-#define MCA_BUS			0x04		/* The card is MCA */
-#define PCI_BUS			0x08		/* The card is PCI */
+#define ISA_BUS			0x01	/* The card is ISA */
+#define EISA_BUS		0x02	/* The card is EISA */
+#define MCA_BUS			0x04	/* The card is MCA */
+#define PCI_BUS			0x08	/* The card is PCI */
 
 /*
 ** 11.11.1998 ARG - ESIL ???? part fix
@@ -93,4 +93,4 @@
 	'V' - '@'				/* literal next char */ \
 }
 
-#endif /* __rioinfo_h */
+#endif				/* __rioinfo_h */
diff --git a/drivers/char/rio/riointr.c b/drivers/char/rio/riointr.c
index e42e7b5..34d8787 100644
--- a/drivers/char/rio/riointr.c
+++ b/drivers/char/rio/riointr.c
@@ -38,6 +38,7 @@
 #include <linux/slab.h>
 #include <linux/errno.h>
 #include <linux/tty.h>
+#include <linux/tty_flip.h>
 #include <asm/io.h>
 #include <asm/system.h>
 #include <asm/string.h>
@@ -87,99 +88,93 @@
 static void RIOReceive(struct rio_info *, struct Port *);
 
 
-static char *firstchars (char *p, int nch)
+static char *firstchars(char *p, int nch)
 {
-  static char buf[2][128];
-  static int t=0;
-  t = ! t;
-  memcpy (buf[t], p, nch);
-  buf[t][nch] = 0;
-  return buf[t];
+	static char buf[2][128];
+	static int t = 0;
+	t = !t;
+	memcpy(buf[t], p, nch);
+	buf[t][nch] = 0;
+	return buf[t];
 }
 
 
 #define	INCR( P, I )	((P) = (((P)+(I)) & p->RIOBufferMask))
 /* Enable and start the transmission of packets */
-void
-RIOTxEnable(en)
-char *		en;
+void RIOTxEnable(en)
+char *en;
 {
-  struct Port *	PortP;
-  struct rio_info *p;
-  struct tty_struct* tty;
-  int c;
-  struct PKT *	PacketP;
-  unsigned long flags;
+	struct Port *PortP;
+	struct rio_info *p;
+	struct tty_struct *tty;
+	int c;
+	struct PKT *PacketP;
+	unsigned long flags;
 
-  PortP = (struct Port *)en; 
-  p = (struct rio_info *)PortP->p;
-  tty = PortP->gs.tty;
+	PortP = (struct Port *) en;
+	p = (struct rio_info *) PortP->p;
+	tty = PortP->gs.tty;
 
 
-  rio_dprintk (RIO_DEBUG_INTR, "tx port %d: %d chars queued.\n", 
-	      PortP->PortNum, PortP->gs.xmit_cnt);
+	rio_dprintk(RIO_DEBUG_INTR, "tx port %d: %d chars queued.\n", PortP->PortNum, PortP->gs.xmit_cnt);
 
-  if (!PortP->gs.xmit_cnt) return;
-  
+	if (!PortP->gs.xmit_cnt)
+		return;
 
-  /* This routine is an order of magnitude simpler than the specialix
-     version. One of the disadvantages is that this version will send
-     an incomplete packet (usually 64 bytes instead of 72) once for
-     every 4k worth of data. Let's just say that this won't influence
-     performance significantly..... */
 
-  rio_spin_lock_irqsave(&PortP->portSem, flags);
+	/* This routine is an order of magnitude simpler than the specialix
+	   version. One of the disadvantages is that this version will send
+	   an incomplete packet (usually 64 bytes instead of 72) once for
+	   every 4k worth of data. Let's just say that this won't influence
+	   performance significantly..... */
 
-  while (can_add_transmit( &PacketP, PortP )) {
-    c = PortP->gs.xmit_cnt;
-    if (c > PKT_MAX_DATA_LEN) c = PKT_MAX_DATA_LEN;
+	rio_spin_lock_irqsave(&PortP->portSem, flags);
 
-    /* Don't copy past the end of the source buffer */
-    if (c > SERIAL_XMIT_SIZE - PortP->gs.xmit_tail) 
-      c = SERIAL_XMIT_SIZE - PortP->gs.xmit_tail;
+	while (can_add_transmit(&PacketP, PortP)) {
+		c = PortP->gs.xmit_cnt;
+		if (c > PKT_MAX_DATA_LEN)
+			c = PKT_MAX_DATA_LEN;
 
-    { int t;
-    t = (c > 10)?10:c;
-    
-    rio_dprintk (RIO_DEBUG_INTR, "rio: tx port %d: copying %d chars: %s - %s\n", 
-		 PortP->PortNum, c, 
-		 firstchars (PortP->gs.xmit_buf + PortP->gs.xmit_tail      , t),
-		 firstchars (PortP->gs.xmit_buf + PortP->gs.xmit_tail + c-t, t));
-    }
-    /* If for one reason or another, we can't copy more data, 
-       we're done! */
-    if (c == 0) break;
+		/* Don't copy past the end of the source buffer */
+		if (c > SERIAL_XMIT_SIZE - PortP->gs.xmit_tail)
+			c = SERIAL_XMIT_SIZE - PortP->gs.xmit_tail;
 
-    rio_memcpy_toio (PortP->HostP->Caddr, (caddr_t)PacketP->data, 
-		 PortP->gs.xmit_buf + PortP->gs.xmit_tail, c);
-    /*    udelay (1); */
+		{
+			int t;
+			t = (c > 10) ? 10 : c;
 
-    writeb (c, &(PacketP->len));
-    if (!( PortP->State & RIO_DELETED ) ) {
-      add_transmit ( PortP );
-      /*
-      ** Count chars tx'd for port statistics reporting
-      */
-      if ( PortP->statsGather )
-	PortP->txchars += c;
-    }
-    PortP->gs.xmit_tail = (PortP->gs.xmit_tail + c) & (SERIAL_XMIT_SIZE-1);
-    PortP->gs.xmit_cnt -= c;
-  }
+			rio_dprintk(RIO_DEBUG_INTR, "rio: tx port %d: copying %d chars: %s - %s\n", PortP->PortNum, c, firstchars(PortP->gs.xmit_buf + PortP->gs.xmit_tail, t), firstchars(PortP->gs.xmit_buf + PortP->gs.xmit_tail + c - t, t));
+		}
+		/* If for one reason or another, we can't copy more data,
+		   we're done! */
+		if (c == 0)
+			break;
 
-  rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		rio_memcpy_toio(PortP->HostP->Caddr, (caddr_t) PacketP->data, PortP->gs.xmit_buf + PortP->gs.xmit_tail, c);
+		/*    udelay (1); */
 
-  if (PortP->gs.xmit_cnt <= (PortP->gs.wakeup_chars + 2*PKT_MAX_DATA_LEN)) {
-    rio_dprintk (RIO_DEBUG_INTR, "Waking up.... ldisc:%d (%d/%d)....",
-		 (int)(PortP->gs.tty->flags & (1 << TTY_DO_WRITE_WAKEUP)),
-		 PortP->gs.wakeup_chars, PortP->gs.xmit_cnt); 
-    if ((PortP->gs.tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
-	PortP->gs.tty->ldisc.write_wakeup)
-      (PortP->gs.tty->ldisc.write_wakeup)(PortP->gs.tty);
-    rio_dprintk (RIO_DEBUG_INTR, "(%d/%d)\n",
-		PortP->gs.wakeup_chars, PortP->gs.xmit_cnt); 
-    wake_up_interruptible(&PortP->gs.tty->write_wait);
-  }
+		writeb(c, &(PacketP->len));
+		if (!(PortP->State & RIO_DELETED)) {
+			add_transmit(PortP);
+			/*
+			 ** Count chars tx'd for port statistics reporting
+			 */
+			if (PortP->statsGather)
+				PortP->txchars += c;
+		}
+		PortP->gs.xmit_tail = (PortP->gs.xmit_tail + c) & (SERIAL_XMIT_SIZE - 1);
+		PortP->gs.xmit_cnt -= c;
+	}
+
+	rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+
+	if (PortP->gs.xmit_cnt <= (PortP->gs.wakeup_chars + 2 * PKT_MAX_DATA_LEN)) {
+		rio_dprintk(RIO_DEBUG_INTR, "Waking up.... ldisc:%d (%d/%d)....", (int) (PortP->gs.tty->flags & (1 << TTY_DO_WRITE_WAKEUP)), PortP->gs.wakeup_chars, PortP->gs.xmit_cnt);
+		if ((PortP->gs.tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && PortP->gs.tty->ldisc.write_wakeup)
+			(PortP->gs.tty->ldisc.write_wakeup) (PortP->gs.tty);
+		rio_dprintk(RIO_DEBUG_INTR, "(%d/%d)\n", PortP->gs.wakeup_chars, PortP->gs.xmit_cnt);
+		wake_up_interruptible(&PortP->gs.tty->write_wait);
+	}
 
 }
 
@@ -188,361 +183,349 @@
 ** RIO Host Service routine. Does all the work traditionally associated with an
 ** interrupt.
 */
-static int	RupIntr;
-static int	RxIntr;
-static int	TxIntr;
-void
-RIOServiceHost(p, HostP, From)
-struct rio_info *	p;
+static int RupIntr;
+static int RxIntr;
+static int TxIntr;
+void RIOServiceHost(p, HostP, From)
+struct rio_info *p;
 struct Host *HostP;
-int From; 
+int From;
 {
-  rio_spin_lock (&HostP->HostLock);
-  if ( (HostP->Flags & RUN_STATE) != RC_RUNNING ) { 
-    static int t =0;
-    rio_spin_unlock (&HostP->HostLock); 
-    if ((t++ % 200) == 0)
-      rio_dprintk (RIO_DEBUG_INTR, "Interrupt but host not running. flags=%x.\n", (int)HostP->Flags);
-    return;
-  }
-  rio_spin_unlock (&HostP->HostLock); 
-
-  if ( RWORD( HostP->ParmMapP->rup_intr ) ) {
-    WWORD( HostP->ParmMapP->rup_intr , 0 );
-    p->RIORupCount++;
-    RupIntr++;
-    rio_dprintk (RIO_DEBUG_INTR, "rio: RUP interrupt on host %d\n", HostP-p->RIOHosts);
-    RIOPollHostCommands(p, HostP );
-  }
-
-  if ( RWORD( HostP->ParmMapP->rx_intr ) ) {
-    int port;
-
-    WWORD( HostP->ParmMapP->rx_intr , 0 );
-    p->RIORxCount++;
-    RxIntr++;
-
-    rio_dprintk (RIO_DEBUG_INTR, "rio: RX interrupt on host %d\n", HostP-p->RIOHosts);
-    /*
-    ** Loop through every port. If the port is mapped into
-    ** the system ( i.e. has /dev/ttyXXXX associated ) then it is
-    ** worth checking. If the port isn't open, grab any packets
-    ** hanging on its receive queue and stuff them on the free
-    ** list; check for commands on the way.
-    */
-    for ( port=p->RIOFirstPortsBooted; 
-	  port<p->RIOLastPortsBooted+PORTS_PER_RTA; port++ ) {
-      struct Port *PortP = p->RIOPortp[port];
-      struct tty_struct *ttyP;
-      struct PKT *PacketP;
-		
-      /*
-      ** not mapped in - most of the RIOPortp[] information
-      ** has not been set up!
-      ** Optimise: ports come in bundles of eight.
-      */
-      if ( !PortP->Mapped ) {
-	port += 7;
-	continue; /* with the next port */
-      }
-
-      /*
-      ** If the host board isn't THIS host board, check the next one.
-      ** optimise: ports come in bundles of eight.
-      */
-      if ( PortP->HostP != HostP ) {
-	port += 7;
-	continue;
-      }
-
-      /*
-      ** Let us see - is the port open? If not, then don't service it.
-      */
-      if ( !( PortP->PortState & PORT_ISOPEN ) ) {
-	continue;
-      }
-
-      /*
-      ** find corresponding tty structure. The process of mapping
-      ** the ports puts these here.
-      */
-      ttyP = PortP->gs.tty;
-
-      /*
-      ** Lock the port before we begin working on it.
-      */
-      rio_spin_lock(&PortP->portSem);
-
-      /*
-      ** Process received data if there is any.
-      */
-      if ( can_remove_receive( &PacketP, PortP ) )
-	RIOReceive(p, PortP);
-
-      /*
-      ** If there is no data left to be read from the port, and
-      ** it's handshake bit is set, then we must clear the handshake,
-      ** so that that downstream RTA is re-enabled.
-      */
-      if ( !can_remove_receive( &PacketP, PortP ) && 
-	   ( RWORD( PortP->PhbP->handshake )==PHB_HANDSHAKE_SET ) ) {
-				/*
-				** MAGIC! ( Basically, handshake the RX buffer, so that
-				** the RTAs upstream can be re-enabled. )
-				*/
-	rio_dprintk (RIO_DEBUG_INTR, "Set RX handshake bit\n");
-	WWORD( PortP->PhbP->handshake, 
-	       PHB_HANDSHAKE_SET|PHB_HANDSHAKE_RESET );
-      }
-      rio_spin_unlock(&PortP->portSem);
-    }
-  }
-
-  if ( RWORD( HostP->ParmMapP->tx_intr ) ) {
-    int port;
-
-    WWORD( HostP->ParmMapP->tx_intr , 0);
-
-    p->RIOTxCount++;
-    TxIntr++;
-    rio_dprintk (RIO_DEBUG_INTR, "rio: TX interrupt on host %d\n", HostP-p->RIOHosts);
-
-    /*
-    ** Loop through every port.
-    ** If the port is mapped into the system ( i.e. has /dev/ttyXXXX
-    ** associated ) then it is worth checking.
-    */
-    for ( port=p->RIOFirstPortsBooted; 
-	  port<p->RIOLastPortsBooted+PORTS_PER_RTA; port++ ) {
-      struct Port *PortP = p->RIOPortp[port];
-      struct tty_struct *ttyP;
-      struct PKT *PacketP;
-
-      /*
-      ** not mapped in - most of the RIOPortp[] information
-      ** has not been set up!
-      */
-      if ( !PortP->Mapped ) {
-	port += 7;
-	continue; /* with the next port */
-      }
-
-      /*
-      ** If the host board isn't running, then its data structures
-      ** are no use to us - continue quietly.
-      */
-      if ( PortP->HostP != HostP ) {
-	port += 7;
-	continue; /* with the next port */
-      }
-
-      /*
-      ** Let us see - is the port open? If not, then don't service it.
-      */
-      if ( !( PortP->PortState & PORT_ISOPEN ) ) {
-	continue;
-      }
-
-      rio_dprintk (RIO_DEBUG_INTR, "rio: Looking into port %d.\n", port);
-      /*
-      ** Lock the port before we begin working on it.
-      */
-      rio_spin_lock(&PortP->portSem);
-
-      /*
-      ** If we can't add anything to the transmit queue, then
-      ** we need do none of this processing.
-      */
-      if ( !can_add_transmit( &PacketP, PortP ) ) {
-	rio_dprintk (RIO_DEBUG_INTR, "Can't add to port, so skipping.\n");
-	rio_spin_unlock(&PortP->portSem);
-	continue;
-      }
-
-      /*
-      ** find corresponding tty structure. The process of mapping
-      ** the ports puts these here.
-      */
-      ttyP = PortP->gs.tty;
-      /* If ttyP is NULL, the port is getting closed. Forget about it. */
-      if (!ttyP) {
-	rio_dprintk (RIO_DEBUG_INTR, "no tty, so skipping.\n");
-	rio_spin_unlock(&PortP->portSem);
-	continue;
-      }
-      /*
-      ** If there is more room available we start up the transmit
-      ** data process again. This can be direct I/O, if the cookmode
-      ** is set to COOK_RAW or COOK_MEDIUM, or will be a call to the
-      ** riotproc( T_OUTPUT ) if we are in COOK_WELL mode, to fetch
-      ** characters via the line discipline. We must always call
-      ** the line discipline,
-      ** so that user input characters can be echoed correctly.
-      **
-      ** ++++ Update +++++
-      ** With the advent of double buffering, we now see if
-      ** TxBufferOut-In is non-zero. If so, then we copy a packet
-      ** to the output place, and set it going. If this empties
-      ** the buffer, then we must issue a wakeup( ) on OUT.
-      ** If it frees space in the buffer then we must issue
-      ** a wakeup( ) on IN.
-      **
-      ** ++++ Extra! Extra! If PortP->WflushFlag is set, then we
-      ** have to send a WFLUSH command down the PHB, to mark the
-      ** end point of a WFLUSH. We also need to clear out any
-      ** data from the double buffer! ( note that WflushFlag is a
-      ** *count* of the number of WFLUSH commands outstanding! )
-      **
-      ** ++++ And there's more!
-      ** If an RTA is powered off, then on again, and rebooted,
-      ** whilst it has ports open, then we need to re-open the ports.
-      ** ( reasonable enough ). We can't do this when we spot the
-      ** re-boot, in interrupt time, because the queue is probably
-      ** full. So, when we come in here, we need to test if any
-      ** ports are in this condition, and re-open the port before
-      ** we try to send any more data to it. Now, the re-booted
-      ** RTA will be discarding packets from the PHB until it
-      ** receives this open packet, but don't worry tooo much
-      ** about that. The one thing that is interesting is the
-      ** combination of this effect and the WFLUSH effect!
-      */
-      /* For now don't handle RTA reboots. -- REW. 
-	 Reenabled. Otherwise RTA reboots didn't work. Duh. -- REW */
-      if ( PortP->MagicFlags ) {
-#if 1
-	if ( PortP->MagicFlags & MAGIC_REBOOT ) {
-	  /*
-	  ** well, the RTA has been rebooted, and there is room
-	  ** on its queue to add the open packet that is required.
-	  **
-	  ** The messy part of this line is trying to decide if
-	  ** we need to call the Param function as a tty or as
-	  ** a modem.
-	  ** DONT USE CLOCAL AS A TEST FOR THIS!
-	  **
-	  ** If we can't param the port, then move on to the
-	  ** next port.
-	  */
-	  PortP->InUse = NOT_INUSE;
-
-	  rio_spin_unlock(&PortP->portSem);
-	  if ( RIOParam(PortP, OPEN, ((PortP->Cor2Copy & 
-				       (COR2_RTSFLOW|COR2_CTSFLOW ) )== 
-				      (COR2_RTSFLOW|COR2_CTSFLOW ) ) ? 
-			TRUE : FALSE, DONT_SLEEP ) == RIO_FAIL ) {
-	    continue; /* with next port */
-	  }
-	  rio_spin_lock(&PortP->portSem);
-	  PortP->MagicFlags &= ~MAGIC_REBOOT;
+	rio_spin_lock(&HostP->HostLock);
+	if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
+		static int t = 0;
+		rio_spin_unlock(&HostP->HostLock);
+		if ((t++ % 200) == 0)
+			rio_dprintk(RIO_DEBUG_INTR, "Interrupt but host not running. flags=%x.\n", (int) HostP->Flags);
+		return;
 	}
+	rio_spin_unlock(&HostP->HostLock);
+
+	if (RWORD(HostP->ParmMapP->rup_intr)) {
+		WWORD(HostP->ParmMapP->rup_intr, 0);
+		p->RIORupCount++;
+		RupIntr++;
+		rio_dprintk(RIO_DEBUG_INTR, "rio: RUP interrupt on host %d\n", HostP - p->RIOHosts);
+		RIOPollHostCommands(p, HostP);
+	}
+
+	if (RWORD(HostP->ParmMapP->rx_intr)) {
+		int port;
+
+		WWORD(HostP->ParmMapP->rx_intr, 0);
+		p->RIORxCount++;
+		RxIntr++;
+
+		rio_dprintk(RIO_DEBUG_INTR, "rio: RX interrupt on host %d\n", HostP - p->RIOHosts);
+		/*
+		 ** Loop through every port. If the port is mapped into
+		 ** the system ( i.e. has /dev/ttyXXXX associated ) then it is
+		 ** worth checking. If the port isn't open, grab any packets
+		 ** hanging on its receive queue and stuff them on the free
+		 ** list; check for commands on the way.
+		 */
+		for (port = p->RIOFirstPortsBooted; port < p->RIOLastPortsBooted + PORTS_PER_RTA; port++) {
+			struct Port *PortP = p->RIOPortp[port];
+			struct tty_struct *ttyP;
+			struct PKT *PacketP;
+
+			/*
+			 ** not mapped in - most of the RIOPortp[] information
+			 ** has not been set up!
+			 ** Optimise: ports come in bundles of eight.
+			 */
+			if (!PortP->Mapped) {
+				port += 7;
+				continue;	/* with the next port */
+			}
+
+			/*
+			 ** If the host board isn't THIS host board, check the next one.
+			 ** optimise: ports come in bundles of eight.
+			 */
+			if (PortP->HostP != HostP) {
+				port += 7;
+				continue;
+			}
+
+			/*
+			 ** Let us see - is the port open? If not, then don't service it.
+			 */
+			if (!(PortP->PortState & PORT_ISOPEN)) {
+				continue;
+			}
+
+			/*
+			 ** find corresponding tty structure. The process of mapping
+			 ** the ports puts these here.
+			 */
+			ttyP = PortP->gs.tty;
+
+			/*
+			 ** Lock the port before we begin working on it.
+			 */
+			rio_spin_lock(&PortP->portSem);
+
+			/*
+			 ** Process received data if there is any.
+			 */
+			if (can_remove_receive(&PacketP, PortP))
+				RIOReceive(p, PortP);
+
+			/*
+			 ** If there is no data left to be read from the port, and
+			 ** it's handshake bit is set, then we must clear the handshake,
+			 ** so that that downstream RTA is re-enabled.
+			 */
+			if (!can_remove_receive(&PacketP, PortP) && (RWORD(PortP->PhbP->handshake) == PHB_HANDSHAKE_SET)) {
+				/*
+				 ** MAGIC! ( Basically, handshake the RX buffer, so that
+				 ** the RTAs upstream can be re-enabled. )
+				 */
+				rio_dprintk(RIO_DEBUG_INTR, "Set RX handshake bit\n");
+				WWORD(PortP->PhbP->handshake, PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET);
+			}
+			rio_spin_unlock(&PortP->portSem);
+		}
+	}
+
+	if (RWORD(HostP->ParmMapP->tx_intr)) {
+		int port;
+
+		WWORD(HostP->ParmMapP->tx_intr, 0);
+
+		p->RIOTxCount++;
+		TxIntr++;
+		rio_dprintk(RIO_DEBUG_INTR, "rio: TX interrupt on host %d\n", HostP - p->RIOHosts);
+
+		/*
+		 ** Loop through every port.
+		 ** If the port is mapped into the system ( i.e. has /dev/ttyXXXX
+		 ** associated ) then it is worth checking.
+		 */
+		for (port = p->RIOFirstPortsBooted; port < p->RIOLastPortsBooted + PORTS_PER_RTA; port++) {
+			struct Port *PortP = p->RIOPortp[port];
+			struct tty_struct *ttyP;
+			struct PKT *PacketP;
+
+			/*
+			 ** not mapped in - most of the RIOPortp[] information
+			 ** has not been set up!
+			 */
+			if (!PortP->Mapped) {
+				port += 7;
+				continue;	/* with the next port */
+			}
+
+			/*
+			 ** If the host board isn't running, then its data structures
+			 ** are no use to us - continue quietly.
+			 */
+			if (PortP->HostP != HostP) {
+				port += 7;
+				continue;	/* with the next port */
+			}
+
+			/*
+			 ** Let us see - is the port open? If not, then don't service it.
+			 */
+			if (!(PortP->PortState & PORT_ISOPEN)) {
+				continue;
+			}
+
+			rio_dprintk(RIO_DEBUG_INTR, "rio: Looking into port %d.\n", port);
+			/*
+			 ** Lock the port before we begin working on it.
+			 */
+			rio_spin_lock(&PortP->portSem);
+
+			/*
+			 ** If we can't add anything to the transmit queue, then
+			 ** we need do none of this processing.
+			 */
+			if (!can_add_transmit(&PacketP, PortP)) {
+				rio_dprintk(RIO_DEBUG_INTR, "Can't add to port, so skipping.\n");
+				rio_spin_unlock(&PortP->portSem);
+				continue;
+			}
+
+			/*
+			 ** find corresponding tty structure. The process of mapping
+			 ** the ports puts these here.
+			 */
+			ttyP = PortP->gs.tty;
+			/* If ttyP is NULL, the port is getting closed. Forget about it. */
+			if (!ttyP) {
+				rio_dprintk(RIO_DEBUG_INTR, "no tty, so skipping.\n");
+				rio_spin_unlock(&PortP->portSem);
+				continue;
+			}
+			/*
+			 ** If there is more room available we start up the transmit
+			 ** data process again. This can be direct I/O, if the cookmode
+			 ** is set to COOK_RAW or COOK_MEDIUM, or will be a call to the
+			 ** riotproc( T_OUTPUT ) if we are in COOK_WELL mode, to fetch
+			 ** characters via the line discipline. We must always call
+			 ** the line discipline,
+			 ** so that user input characters can be echoed correctly.
+			 **
+			 ** ++++ Update +++++
+			 ** With the advent of double buffering, we now see if
+			 ** TxBufferOut-In is non-zero. If so, then we copy a packet
+			 ** to the output place, and set it going. If this empties
+			 ** the buffer, then we must issue a wakeup( ) on OUT.
+			 ** If it frees space in the buffer then we must issue
+			 ** a wakeup( ) on IN.
+			 **
+			 ** ++++ Extra! Extra! If PortP->WflushFlag is set, then we
+			 ** have to send a WFLUSH command down the PHB, to mark the
+			 ** end point of a WFLUSH. We also need to clear out any
+			 ** data from the double buffer! ( note that WflushFlag is a
+			 ** *count* of the number of WFLUSH commands outstanding! )
+			 **
+			 ** ++++ And there's more!
+			 ** If an RTA is powered off, then on again, and rebooted,
+			 ** whilst it has ports open, then we need to re-open the ports.
+			 ** ( reasonable enough ). We can't do this when we spot the
+			 ** re-boot, in interrupt time, because the queue is probably
+			 ** full. So, when we come in here, we need to test if any
+			 ** ports are in this condition, and re-open the port before
+			 ** we try to send any more data to it. Now, the re-booted
+			 ** RTA will be discarding packets from the PHB until it
+			 ** receives this open packet, but don't worry tooo much
+			 ** about that. The one thing that is interesting is the
+			 ** combination of this effect and the WFLUSH effect!
+			 */
+			/* For now don't handle RTA reboots. -- REW.
+			   Reenabled. Otherwise RTA reboots didn't work. Duh. -- REW */
+			if (PortP->MagicFlags) {
+#if 1
+				if (PortP->MagicFlags & MAGIC_REBOOT) {
+					/*
+					 ** well, the RTA has been rebooted, and there is room
+					 ** on its queue to add the open packet that is required.
+					 **
+					 ** The messy part of this line is trying to decide if
+					 ** we need to call the Param function as a tty or as
+					 ** a modem.
+					 ** DONT USE CLOCAL AS A TEST FOR THIS!
+					 **
+					 ** If we can't param the port, then move on to the
+					 ** next port.
+					 */
+					PortP->InUse = NOT_INUSE;
+
+					rio_spin_unlock(&PortP->portSem);
+					if (RIOParam(PortP, OPEN, ((PortP->Cor2Copy & (COR2_RTSFLOW | COR2_CTSFLOW)) == (COR2_RTSFLOW | COR2_CTSFLOW)) ? TRUE : FALSE, DONT_SLEEP) == RIO_FAIL) {
+						continue;	/* with next port */
+					}
+					rio_spin_lock(&PortP->portSem);
+					PortP->MagicFlags &= ~MAGIC_REBOOT;
+				}
 #endif
 
-	/*
-	** As mentioned above, this is a tacky hack to cope
-	** with WFLUSH
-	*/
-	if ( PortP->WflushFlag ) {
-	  rio_dprintk (RIO_DEBUG_INTR, "Want to WFLUSH mark this port\n");
+				/*
+				 ** As mentioned above, this is a tacky hack to cope
+				 ** with WFLUSH
+				 */
+				if (PortP->WflushFlag) {
+					rio_dprintk(RIO_DEBUG_INTR, "Want to WFLUSH mark this port\n");
 
-	  if ( PortP->InUse )
-	    rio_dprintk (RIO_DEBUG_INTR, "FAILS - PORT IS IN USE\n");
+					if (PortP->InUse)
+						rio_dprintk(RIO_DEBUG_INTR, "FAILS - PORT IS IN USE\n");
+				}
+
+				while (PortP->WflushFlag && can_add_transmit(&PacketP, PortP) && (PortP->InUse == NOT_INUSE)) {
+					int p;
+					struct PktCmd *PktCmdP;
+
+					rio_dprintk(RIO_DEBUG_INTR, "Add WFLUSH marker to data queue\n");
+					/*
+					 ** make it look just like a WFLUSH command
+					 */
+					PktCmdP = (struct PktCmd *) &PacketP->data[0];
+
+					WBYTE(PktCmdP->Command, WFLUSH);
+
+					p = PortP->HostPort % (ushort) PORTS_PER_RTA;
+
+					/*
+					 ** If second block of ports for 16 port RTA, add 8
+					 ** to index 8-15.
+					 */
+					if (PortP->SecondBlock)
+						p += PORTS_PER_RTA;
+
+					WBYTE(PktCmdP->PhbNum, p);
+
+					/*
+					 ** to make debuggery easier
+					 */
+					WBYTE(PacketP->data[2], 'W');
+					WBYTE(PacketP->data[3], 'F');
+					WBYTE(PacketP->data[4], 'L');
+					WBYTE(PacketP->data[5], 'U');
+					WBYTE(PacketP->data[6], 'S');
+					WBYTE(PacketP->data[7], 'H');
+					WBYTE(PacketP->data[8], ' ');
+					WBYTE(PacketP->data[9], '0' + PortP->WflushFlag);
+					WBYTE(PacketP->data[10], ' ');
+					WBYTE(PacketP->data[11], ' ');
+					WBYTE(PacketP->data[12], '\0');
+
+					/*
+					 ** its two bytes long!
+					 */
+					WBYTE(PacketP->len, PKT_CMD_BIT | 2);
+
+					/*
+					 ** queue it!
+					 */
+					if (!(PortP->State & RIO_DELETED)) {
+						add_transmit(PortP);
+						/*
+						 ** Count chars tx'd for port statistics reporting
+						 */
+						if (PortP->statsGather)
+							PortP->txchars += 2;
+					}
+
+					if (--(PortP->WflushFlag) == 0) {
+						PortP->MagicFlags &= ~MAGIC_FLUSH;
+					}
+
+					rio_dprintk(RIO_DEBUG_INTR, "Wflush count now stands at %d\n", PortP->WflushFlag);
+				}
+				if (PortP->MagicFlags & MORE_OUTPUT_EYGOR) {
+					if (PortP->MagicFlags & MAGIC_FLUSH) {
+						PortP->MagicFlags |= MORE_OUTPUT_EYGOR;
+					} else {
+						if (!can_add_transmit(&PacketP, PortP)) {
+							rio_spin_unlock(&PortP->portSem);
+							continue;
+						}
+						rio_spin_unlock(&PortP->portSem);
+						RIOTxEnable((char *) PortP);
+						rio_spin_lock(&PortP->portSem);
+						PortP->MagicFlags &= ~MORE_OUTPUT_EYGOR;
+					}
+				}
+			}
+
+
+			/*
+			 ** If we can't add anything to the transmit queue, then
+			 ** we need do none of the remaining processing.
+			 */
+			if (!can_add_transmit(&PacketP, PortP)) {
+				rio_spin_unlock(&PortP->portSem);
+				continue;
+			}
+
+			rio_spin_unlock(&PortP->portSem);
+			RIOTxEnable((char *) PortP);
+		}
 	}
-				
-	while ( PortP->WflushFlag &&
-		can_add_transmit( &PacketP, PortP ) && 
-		( PortP->InUse == NOT_INUSE ) ) {
-	  int p;
-	  struct PktCmd *PktCmdP;
-
-	  rio_dprintk (RIO_DEBUG_INTR, "Add WFLUSH marker to data queue\n");
-	  /*
-	  ** make it look just like a WFLUSH command
-	  */
-	  PktCmdP = ( struct PktCmd * )&PacketP->data[0];
-
-	  WBYTE( PktCmdP->Command , WFLUSH );
-
-	  p =  PortP->HostPort % ( ushort )PORTS_PER_RTA;
-
-	  /*
-	  ** If second block of ports for 16 port RTA, add 8
-	  ** to index 8-15.
-	  */
-	  if ( PortP->SecondBlock )
-	    p += PORTS_PER_RTA;
-
-	  WBYTE( PktCmdP->PhbNum, p );
-
-	  /*
-	  ** to make debuggery easier
-	  */
-	  WBYTE( PacketP->data[ 2], 'W'  );
-	  WBYTE( PacketP->data[ 3], 'F'  );
-	  WBYTE( PacketP->data[ 4], 'L'  );
-	  WBYTE( PacketP->data[ 5], 'U'  );
-	  WBYTE( PacketP->data[ 6], 'S'  );
-	  WBYTE( PacketP->data[ 7], 'H'  );
-	  WBYTE( PacketP->data[ 8], ' '  );
-	  WBYTE( PacketP->data[ 9], '0'+PortP->WflushFlag );
-	  WBYTE( PacketP->data[10], ' '  );
-	  WBYTE( PacketP->data[11], ' '  );
-	  WBYTE( PacketP->data[12], '\0' );
-
-	  /*
-	  ** its two bytes long!
-	  */
-	  WBYTE( PacketP->len , PKT_CMD_BIT | 2 );
-
-	  /*
-	  ** queue it!
-	  */
-	  if ( !( PortP->State & RIO_DELETED ) ) {
-	    add_transmit( PortP );
-	    /*
-	    ** Count chars tx'd for port statistics reporting
-	    */
-	    if ( PortP->statsGather )
-	      PortP->txchars += 2;
-	  }
-
-	  if ( --( PortP->WflushFlag ) == 0 ) {
-	    PortP->MagicFlags &= ~MAGIC_FLUSH;
-	  }
-
-	  rio_dprintk (RIO_DEBUG_INTR, "Wflush count now stands at %d\n", 
-		 PortP->WflushFlag);
-	}
-	if ( PortP->MagicFlags & MORE_OUTPUT_EYGOR ) {
-	  if ( PortP->MagicFlags & MAGIC_FLUSH ) {
-	    PortP->MagicFlags |= MORE_OUTPUT_EYGOR;
-	  }
-	  else {
-	    if ( !can_add_transmit( &PacketP, PortP ) ) {
-	      rio_spin_unlock(&PortP->portSem);
-	      continue;
-	    }
-	    rio_spin_unlock(&PortP->portSem);
-	    RIOTxEnable((char *)PortP);
-	    rio_spin_lock(&PortP->portSem);
-	    PortP->MagicFlags &= ~MORE_OUTPUT_EYGOR;
-	  }
-	}
-      }
-
-
-      /*
-      ** If we can't add anything to the transmit queue, then
-      ** we need do none of the remaining processing.
-      */
-      if (!can_add_transmit( &PacketP, PortP ) ) {
-	rio_spin_unlock(&PortP->portSem);
-	continue;
-      }
-
-      rio_spin_unlock(&PortP->portSem);
-      RIOTxEnable((char *)PortP);
-    }
-  }
 }
 
 /*
@@ -550,180 +533,162 @@
 ** NB: Called with the tty locked. The spl from the lockb( ) is passed.
 ** we return the ttySpl level that we re-locked at.
 */
-static void
-RIOReceive(p, PortP)
-struct rio_info *	p;
-struct Port *		PortP;
+static void RIOReceive(p, PortP)
+struct rio_info *p;
+struct Port *PortP;
 {
-  struct tty_struct *TtyP;
-  register ushort transCount;
-  struct PKT *PacketP;
-  register uint	DataCnt;
-  uchar *	ptr;
-  int copied =0;
+	struct tty_struct *TtyP;
+	register ushort transCount;
+	struct PKT *PacketP;
+	register uint DataCnt;
+	uchar *ptr;
+	unsigned char *buf;
+	int copied = 0;
 
-  static int intCount, RxIntCnt;
+	static int intCount, RxIntCnt;
 
-  /*
-  ** The receive data process is to remove packets from the
-  ** PHB until there aren't any more or the current cblock
-  ** is full. When this occurs, there will be some left over
-  ** data in the packet, that we must do something with.
-  ** As we haven't unhooked the packet from the read list
-  ** yet, we can just leave the packet there, having first
-  ** made a note of how far we got. This means that we need
-  ** a pointer per port saying where we start taking the
-  ** data from - this will normally be zero, but when we
-  ** run out of space it will be set to the offset of the
-  ** next byte to copy from the packet data area. The packet
-  ** length field is decremented by the number of bytes that
-  ** we succesfully removed from the packet. When this reaches
-  ** zero, we reset the offset pointer to be zero, and free
-  ** the packet from the front of the queue.
-  */
+	/*
+	 ** The receive data process is to remove packets from the
+	 ** PHB until there aren't any more or the current cblock
+	 ** is full. When this occurs, there will be some left over
+	 ** data in the packet, that we must do something with.
+	 ** As we haven't unhooked the packet from the read list
+	 ** yet, we can just leave the packet there, having first
+	 ** made a note of how far we got. This means that we need
+	 ** a pointer per port saying where we start taking the
+	 ** data from - this will normally be zero, but when we
+	 ** run out of space it will be set to the offset of the
+	 ** next byte to copy from the packet data area. The packet
+	 ** length field is decremented by the number of bytes that
+	 ** we succesfully removed from the packet. When this reaches
+	 ** zero, we reset the offset pointer to be zero, and free
+	 ** the packet from the front of the queue.
+	 */
 
-  intCount++;
+	intCount++;
 
-  TtyP = PortP->gs.tty;
-  if (!TtyP) {
-    rio_dprintk (RIO_DEBUG_INTR, "RIOReceive: tty is null. \n");
-    return;
-  }
-
-  if (PortP->State & RIO_THROTTLE_RX) {
-    rio_dprintk (RIO_DEBUG_INTR, "RIOReceive: Throttled. Can't handle more input.\n");
-    return;
-  }
-
-  if ( PortP->State & RIO_DELETED )
-    {
-      while ( can_remove_receive( &PacketP, PortP ) )
-	{
-	  remove_receive( PortP );
-	  put_free_end( PortP->HostP, PacketP );
+	TtyP = PortP->gs.tty;
+	if (!TtyP) {
+		rio_dprintk(RIO_DEBUG_INTR, "RIOReceive: tty is null. \n");
+		return;
 	}
-    }
-  else
-    {
-      /*
-      ** loop, just so long as:
-      **   i ) there's some data ( i.e. can_remove_receive )
-      **  ii ) we haven't been blocked
-      ** iii ) there's somewhere to put the data
-      **  iv ) we haven't outstayed our welcome
-      */
-      transCount = 1;
-      while ( can_remove_receive(&PacketP, PortP)
-	      && transCount)
-	{
+
+	if (PortP->State & RIO_THROTTLE_RX) {
+		rio_dprintk(RIO_DEBUG_INTR, "RIOReceive: Throttled. Can't handle more input.\n");
+		return;
+	}
+
+	if (PortP->State & RIO_DELETED) {
+		while (can_remove_receive(&PacketP, PortP)) {
+			remove_receive(PortP);
+			put_free_end(PortP->HostP, PacketP);
+		}
+	} else {
+		/*
+		 ** loop, just so long as:
+		 **   i ) there's some data ( i.e. can_remove_receive )
+		 **  ii ) we haven't been blocked
+		 ** iii ) there's somewhere to put the data
+		 **  iv ) we haven't outstayed our welcome
+		 */
+		transCount = 1;
+		while (can_remove_receive(&PacketP, PortP)
+		       && transCount) {
 #ifdef STATS
-	  PortP->Stat.RxIntCnt++;
-#endif /* STATS */
-	  RxIntCnt++;
+			PortP->Stat.RxIntCnt++;
+#endif				/* STATS */
+			RxIntCnt++;
 
-	  /*
-	  ** check that it is not a command!
-	  */
-	  if ( PacketP->len & PKT_CMD_BIT ) {
-	    rio_dprintk (RIO_DEBUG_INTR, "RIO: unexpected command packet received on PHB\n");
-	    /*	    rio_dprint(RIO_DEBUG_INTR, (" sysport   = %d\n", p->RIOPortp->PortNum)); */
-	    rio_dprintk (RIO_DEBUG_INTR, " dest_unit = %d\n", PacketP->dest_unit);
-	    rio_dprintk (RIO_DEBUG_INTR, " dest_port = %d\n", PacketP->dest_port);
-	    rio_dprintk (RIO_DEBUG_INTR, " src_unit  = %d\n", PacketP->src_unit);
-	    rio_dprintk (RIO_DEBUG_INTR, " src_port  = %d\n", PacketP->src_port);
-	    rio_dprintk (RIO_DEBUG_INTR, " len	   = %d\n", PacketP->len);
-	    rio_dprintk (RIO_DEBUG_INTR, " control   = %d\n", PacketP->control);
-	    rio_dprintk (RIO_DEBUG_INTR, " csum	   = %d\n", PacketP->csum);
-	    rio_dprintk (RIO_DEBUG_INTR, "	 data bytes: ");
-	    for ( DataCnt=0; DataCnt<PKT_MAX_DATA_LEN; DataCnt++ )
-	      rio_dprintk (RIO_DEBUG_INTR, "%d\n", PacketP->data[DataCnt]);
-	    remove_receive( PortP );
-	    put_free_end( PortP->HostP, PacketP );
-	    continue; /* with next packet */
-	  }
+			/*
+			 ** check that it is not a command!
+			 */
+			if (PacketP->len & PKT_CMD_BIT) {
+				rio_dprintk(RIO_DEBUG_INTR, "RIO: unexpected command packet received on PHB\n");
+				/*      rio_dprint(RIO_DEBUG_INTR, (" sysport   = %d\n", p->RIOPortp->PortNum)); */
+				rio_dprintk(RIO_DEBUG_INTR, " dest_unit = %d\n", PacketP->dest_unit);
+				rio_dprintk(RIO_DEBUG_INTR, " dest_port = %d\n", PacketP->dest_port);
+				rio_dprintk(RIO_DEBUG_INTR, " src_unit  = %d\n", PacketP->src_unit);
+				rio_dprintk(RIO_DEBUG_INTR, " src_port  = %d\n", PacketP->src_port);
+				rio_dprintk(RIO_DEBUG_INTR, " len	   = %d\n", PacketP->len);
+				rio_dprintk(RIO_DEBUG_INTR, " control   = %d\n", PacketP->control);
+				rio_dprintk(RIO_DEBUG_INTR, " csum	   = %d\n", PacketP->csum);
+				rio_dprintk(RIO_DEBUG_INTR, "	 data bytes: ");
+				for (DataCnt = 0; DataCnt < PKT_MAX_DATA_LEN; DataCnt++)
+					rio_dprintk(RIO_DEBUG_INTR, "%d\n", PacketP->data[DataCnt]);
+				remove_receive(PortP);
+				put_free_end(PortP->HostP, PacketP);
+				continue;	/* with next packet */
+			}
 
-	  /*
-	  ** How many characters can we move 'upstream' ?
-	  **
-	  ** Determine the minimum of the amount of data
-	  ** available and the amount of space in which to
-	  ** put it.
-	  **
-	  ** 1.	Get the packet length by masking 'len'
-	  **	for only the length bits.
-	  ** 2.	Available space is [buffer size] - [space used]
-	  **
-	  ** Transfer count is the minimum of packet length
-	  ** and available space.
-	  */
-			
-	  transCount = min_t(unsigned int, PacketP->len & PKT_LEN_MASK,
-			   TTY_FLIPBUF_SIZE - TtyP->flip.count);
-	  rio_dprintk (RIO_DEBUG_REC,  "port %d: Copy %d bytes\n", 
-				      PortP->PortNum, transCount);
-	  /*
-	  ** To use the following 'kkprintfs' for debugging - change the '#undef'
-	  ** to '#define', (this is the only place ___DEBUG_IT___ occurs in the
-	  ** driver).
-	  */
+			/*
+			 ** How many characters can we move 'upstream' ?
+			 **
+			 ** Determine the minimum of the amount of data
+			 ** available and the amount of space in which to
+			 ** put it.
+			 **
+			 ** 1.        Get the packet length by masking 'len'
+			 **   for only the length bits.
+			 ** 2.        Available space is [buffer size] - [space used]
+			 **
+			 ** Transfer count is the minimum of packet length
+			 ** and available space.
+			 */
+
+			transCount = tty_buffer_request_room(TtyP, PacketP->len & PKT_LEN_MASK);
+			rio_dprintk(RIO_DEBUG_REC, "port %d: Copy %d bytes\n", PortP->PortNum, transCount);
+			/*
+			 ** To use the following 'kkprintfs' for debugging - change the '#undef'
+			 ** to '#define', (this is the only place ___DEBUG_IT___ occurs in the
+			 ** driver).
+			 */
 #undef ___DEBUG_IT___
 #ifdef ___DEBUG_IT___
-	  kkprintf("I:%d R:%d P:%d Q:%d C:%d F:%x ",
-		   intCount,
-		   RxIntCnt,
-		   PortP->PortNum,
-		   TtyP->rxqueue.count,
-		   transCount,
-		   TtyP->flags );
+			kkprintf("I:%d R:%d P:%d Q:%d C:%d F:%x ", intCount, RxIntCnt, PortP->PortNum, TtyP->rxqueue.count, transCount, TtyP->flags);
 #endif
-	  ptr = (uchar *) PacketP->data + PortP->RxDataStart;
+			ptr = (uchar *) PacketP->data + PortP->RxDataStart;
 
-	  rio_memcpy_fromio (TtyP->flip.char_buf_ptr, ptr, transCount);
-	  memset(TtyP->flip.flag_buf_ptr, TTY_NORMAL, transCount);
-
+			tty_prepare_flip_string(TtyP, &buf, transCount);
+			rio_memcpy_fromio(buf, ptr, transCount);
 #ifdef STATS
-	  /*
-	  ** keep a count for statistical purposes
-	  */
-	  PortP->Stat.RxCharCnt	+= transCount;
+			/*
+			 ** keep a count for statistical purposes
+			 */
+			PortP->Stat.RxCharCnt += transCount;
 #endif
-	  PortP->RxDataStart	+= transCount;
-	  PacketP->len		-= transCount;
-	  copied += transCount;
-	  TtyP->flip.count += transCount;
-	  TtyP->flip.char_buf_ptr += transCount;
-	  TtyP->flip.flag_buf_ptr += transCount;
+			PortP->RxDataStart += transCount;
+			PacketP->len -= transCount;
+			copied += transCount;
 
 
 #ifdef ___DEBUG_IT___
-	  kkprintf("T:%d L:%d\n", DataCnt, PacketP->len );
+			kkprintf("T:%d L:%d\n", DataCnt, PacketP->len);
 #endif
 
-	  if ( PacketP->len == 0 )
-	    {
+			if (PacketP->len == 0) {
 				/*
-				** If we have emptied the packet, then we can
-				** free it, and reset the start pointer for
-				** the next packet.
-				*/
-	      remove_receive( PortP );
-	      put_free_end( PortP->HostP, PacketP );
-	      PortP->RxDataStart = 0;
+				 ** If we have emptied the packet, then we can
+				 ** free it, and reset the start pointer for
+				 ** the next packet.
+				 */
+				remove_receive(PortP);
+				put_free_end(PortP->HostP, PacketP);
+				PortP->RxDataStart = 0;
 #ifdef STATS
 				/*
-				** more lies ( oops, I mean statistics )
-				*/
-	      PortP->Stat.RxPktCnt++;
-#endif /* STATS */
-	    }
+				 ** more lies ( oops, I mean statistics )
+				 */
+				PortP->Stat.RxPktCnt++;
+#endif				/* STATS */
+			}
+		}
 	}
-    }
-  if (copied) {
-    rio_dprintk (RIO_DEBUG_REC, "port %d: pushing tty flip buffer: %d total bytes copied.\n", PortP->PortNum, copied);
-    tty_flip_buffer_push (TtyP);
-  }
+	if (copied) {
+		rio_dprintk(RIO_DEBUG_REC, "port %d: pushing tty flip buffer: %d total bytes copied.\n", PortP->PortNum, copied);
+		tty_flip_buffer_push(TtyP);
+	}
 
-  return;
+	return;
 }
 
 #ifdef FUTURE_RELEASE
@@ -731,221 +696,210 @@
 ** The proc routine called by the line discipline to do the work for it.
 ** The proc routine works hand in hand with the interrupt routine.
 */
-int
-riotproc(p, tp, cmd, port)
-struct rio_info *	p;
+int riotproc(p, tp, cmd, port)
+struct rio_info *p;
 register struct ttystatics *tp;
 int cmd;
-int	port;
+int port;
 {
 	register struct Port *PortP;
 	int SysPort;
 	struct PKT *PacketP;
 
-	SysPort = port;	/* Believe me, it works. */
+	SysPort = port;		/* Believe me, it works. */
 
-	if ( SysPort < 0 || SysPort >= RIO_PORTS ) {
-		rio_dprintk (RIO_DEBUG_INTR, "Illegal port %d derived from TTY in riotproc()\n",SysPort);
+	if (SysPort < 0 || SysPort >= RIO_PORTS) {
+		rio_dprintk(RIO_DEBUG_INTR, "Illegal port %d derived from TTY in riotproc()\n", SysPort);
 		return 0;
 	}
 	PortP = p->RIOPortp[SysPort];
 
-	if ((uint)PortP->PhbP < (uint)PortP->Caddr || 
-			(uint)PortP->PhbP >= (uint)PortP->Caddr+SIXTY_FOUR_K ) {
-		rio_dprintk (RIO_DEBUG_INTR, "RIO: NULL or BAD PhbP on sys port %d in proc routine\n",
-							SysPort);
-		rio_dprintk (RIO_DEBUG_INTR, "	 PortP = 0x%x\n",PortP);
-		rio_dprintk (RIO_DEBUG_INTR, "	 PortP->PhbP = 0x%x\n",PortP->PhbP);
-		rio_dprintk (RIO_DEBUG_INTR, "	 PortP->Caddr = 0x%x\n",PortP->PhbP);
-		rio_dprintk (RIO_DEBUG_INTR, "	 PortP->HostPort = 0x%x\n",PortP->HostPort);
+	if ((uint) PortP->PhbP < (uint) PortP->Caddr || (uint) PortP->PhbP >= (uint) PortP->Caddr + SIXTY_FOUR_K) {
+		rio_dprintk(RIO_DEBUG_INTR, "RIO: NULL or BAD PhbP on sys port %d in proc routine\n", SysPort);
+		rio_dprintk(RIO_DEBUG_INTR, "	 PortP = 0x%x\n", PortP);
+		rio_dprintk(RIO_DEBUG_INTR, "	 PortP->PhbP = 0x%x\n", PortP->PhbP);
+		rio_dprintk(RIO_DEBUG_INTR, "	 PortP->Caddr = 0x%x\n", PortP->PhbP);
+		rio_dprintk(RIO_DEBUG_INTR, "	 PortP->HostPort = 0x%x\n", PortP->HostPort);
 		return 0;
 	}
 
-	switch(cmd) {
-		case T_WFLUSH:
-			rio_dprintk (RIO_DEBUG_INTR, "T_WFLUSH\n");
+	switch (cmd) {
+	case T_WFLUSH:
+		rio_dprintk(RIO_DEBUG_INTR, "T_WFLUSH\n");
+		/*
+		 ** Because of the spooky way the RIO works, we don't need
+		 ** to issue a flush command on any of the SET*F commands,
+		 ** as that causes trouble with getty and login, which issue
+		 ** these commands to incur a READ flush, and rely on the fact
+		 ** that the line discipline does a wait for drain for them.
+		 ** As the rio doesn't wait for drain, the write flush would
+		 ** destroy the Password: prompt. This isn't very friendly, so
+		 ** here we only issue a WFLUSH command if we are in the interrupt
+		 ** routine, or we aren't executing a SET*F command.
+		 */
+		if (PortP->HostP->InIntr || !PortP->FlushCmdBodge) {
 			/*
-			** Because of the spooky way the RIO works, we don't need
-			** to issue a flush command on any of the SET*F commands,
-			** as that causes trouble with getty and login, which issue
-			** these commands to incur a READ flush, and rely on the fact
-			** that the line discipline does a wait for drain for them.
-			** As the rio doesn't wait for drain, the write flush would
-			** destroy the Password: prompt. This isn't very friendly, so
-			** here we only issue a WFLUSH command if we are in the interrupt
-			** routine, or we aren't executing a SET*F command.
-			*/
-			if ( PortP->HostP->InIntr || !PortP->FlushCmdBodge ) {
-				/*
-				** form a wflush packet - 1 byte long, no data
-				*/
-				if ( PortP->State & RIO_DELETED ) {
-					rio_dprintk (RIO_DEBUG_INTR, "WFLUSH on deleted RTA\n");
-				}
-				else {
-					if ( RIOPreemptiveCmd(p, PortP, WFLUSH ) == RIO_FAIL ) {
-						rio_dprintk (RIO_DEBUG_INTR, "T_WFLUSH Command failed\n");
-					}
-					else
-						rio_dprintk (RIO_DEBUG_INTR, "T_WFLUSH Command\n");
-				}
-				/*
-				** WFLUSH operation - flush the data!
-				*/
-				PortP->TxBufferIn = PortP->TxBufferOut = 0;
-			}
-			else {
-				rio_dprintk (RIO_DEBUG_INTR, "T_WFLUSH Command ignored\n");
+			 ** form a wflush packet - 1 byte long, no data
+			 */
+			if (PortP->State & RIO_DELETED) {
+				rio_dprintk(RIO_DEBUG_INTR, "WFLUSH on deleted RTA\n");
+			} else {
+				if (RIOPreemptiveCmd(p, PortP, WFLUSH) == RIO_FAIL) {
+					rio_dprintk(RIO_DEBUG_INTR, "T_WFLUSH Command failed\n");
+				} else
+					rio_dprintk(RIO_DEBUG_INTR, "T_WFLUSH Command\n");
 			}
 			/*
-			** sort out the line discipline
-			*/
-			if (PortP->CookMode == COOK_WELL)
-				goto start;
-			break;
-	
-		case T_RESUME:
-			rio_dprintk (RIO_DEBUG_INTR, "T_RESUME\n");
-			/*
-			** send pre-emptive resume packet
-			*/
-			if ( PortP->State & RIO_DELETED ) {
-				rio_dprintk (RIO_DEBUG_INTR, "RESUME on deleted RTA\n");
+			 ** WFLUSH operation - flush the data!
+			 */
+			PortP->TxBufferIn = PortP->TxBufferOut = 0;
+		} else {
+			rio_dprintk(RIO_DEBUG_INTR, "T_WFLUSH Command ignored\n");
+		}
+		/*
+		 ** sort out the line discipline
+		 */
+		if (PortP->CookMode == COOK_WELL)
+			goto start;
+		break;
+
+	case T_RESUME:
+		rio_dprintk(RIO_DEBUG_INTR, "T_RESUME\n");
+		/*
+		 ** send pre-emptive resume packet
+		 */
+		if (PortP->State & RIO_DELETED) {
+			rio_dprintk(RIO_DEBUG_INTR, "RESUME on deleted RTA\n");
+		} else {
+			if (RIOPreemptiveCmd(p, PortP, RESUME) == RIO_FAIL) {
+				rio_dprintk(RIO_DEBUG_INTR, "T_RESUME Command failed\n");
 			}
-			else {
-				if ( RIOPreemptiveCmd(p, PortP, RESUME ) == RIO_FAIL ) {
-					rio_dprintk (RIO_DEBUG_INTR, "T_RESUME Command failed\n");
-				}
+		}
+		/*
+		 ** and re-start the sender software!
+		 */
+		if (PortP->CookMode == COOK_WELL)
+			goto start;
+		break;
+
+	case T_TIME:
+		rio_dprintk(RIO_DEBUG_INTR, "T_TIME\n");
+		/*
+		 ** T_TIME is called when xDLY is set in oflags and
+		 ** the line discipline timeout has expired. It's
+		 ** function in life is to clear the TIMEOUT flag
+		 ** and to re-start output to the port.
+		 */
+		/*
+		 ** Fall through and re-start output
+		 */
+	case T_OUTPUT:
+	      start:
+		if (PortP->MagicFlags & MAGIC_FLUSH) {
+			PortP->MagicFlags |= MORE_OUTPUT_EYGOR;
+			return 0;
+		}
+		RIOTxEnable((char *) PortP);
+		PortP->MagicFlags &= ~MORE_OUTPUT_EYGOR;
+		/*rio_dprint(RIO_DEBUG_INTR, PortP,DBG_PROC,"T_OUTPUT finished\n"); */
+		break;
+
+	case T_SUSPEND:
+		rio_dprintk(RIO_DEBUG_INTR, "T_SUSPEND\n");
+		/*
+		 ** send a suspend pre-emptive packet.
+		 */
+		if (PortP->State & RIO_DELETED) {
+			rio_dprintk(RIO_DEBUG_INTR, "SUSPEND deleted RTA\n");
+		} else {
+			if (RIOPreemptiveCmd(p, PortP, SUSPEND) == RIO_FAIL) {
+				rio_dprintk(RIO_DEBUG_INTR, "T_SUSPEND Command failed\n");
 			}
-			/*
-			** and re-start the sender software!
-			*/
-			if (PortP->CookMode == COOK_WELL)
-				goto start;
-			break;
-	
-		case T_TIME:
-			rio_dprintk (RIO_DEBUG_INTR, "T_TIME\n");
-			/*
-			** T_TIME is called when xDLY is set in oflags and
-			** the line discipline timeout has expired. It's
-			** function in life is to clear the TIMEOUT flag
-			** and to re-start output to the port.
-			*/
-			/*
-			** Fall through and re-start output
-			*/
-		case T_OUTPUT:
-start:
-			if ( PortP->MagicFlags & MAGIC_FLUSH ) {
-				PortP->MagicFlags |= MORE_OUTPUT_EYGOR;
+		}
+		/*
+		 ** done!
+		 */
+		break;
+
+	case T_BLOCK:
+		rio_dprintk(RIO_DEBUG_INTR, "T_BLOCK\n");
+		break;
+
+	case T_RFLUSH:
+		rio_dprintk(RIO_DEBUG_INTR, "T_RFLUSH\n");
+		if (PortP->State & RIO_DELETED) {
+			rio_dprintk(RIO_DEBUG_INTR, "RFLUSH on deleted RTA\n");
+			PortP->RxDataStart = 0;
+		} else {
+			if (RIOPreemptiveCmd(p, PortP, RFLUSH) == RIO_FAIL) {
+				rio_dprintk(RIO_DEBUG_INTR, "T_RFLUSH Command failed\n");
 				return 0;
 			}
-			RIOTxEnable((char *)PortP);
-			PortP->MagicFlags &= ~MORE_OUTPUT_EYGOR;
-			/*rio_dprint(RIO_DEBUG_INTR, PortP,DBG_PROC,"T_OUTPUT finished\n");*/
-			break;
-	
-		case T_SUSPEND:
-			rio_dprintk (RIO_DEBUG_INTR, "T_SUSPEND\n");
-			/*
-			** send a suspend pre-emptive packet.
-			*/
-			if ( PortP->State & RIO_DELETED ) {
-				rio_dprintk (RIO_DEBUG_INTR, "SUSPEND deleted RTA\n");
+			PortP->RxDataStart = 0;
+			while (can_remove_receive(&PacketP, PortP)) {
+				remove_receive(PortP);
+				ShowPacket(DBG_PROC, PacketP);
+				put_free_end(PortP->HostP, PacketP);
 			}
-			else {
-				if ( RIOPreemptiveCmd(p, PortP, SUSPEND ) == RIO_FAIL ) {
-					rio_dprintk (RIO_DEBUG_INTR, "T_SUSPEND Command failed\n");
-				}
+			if (PortP->PhbP->handshake == PHB_HANDSHAKE_SET) {
+				/*
+				 ** MAGIC!
+				 */
+				rio_dprintk(RIO_DEBUG_INTR, "Set receive handshake bit\n");
+				PortP->PhbP->handshake |= PHB_HANDSHAKE_RESET;
 			}
-			/*
-			** done!
-			*/
-			break;
-	
-		case T_BLOCK:
-			rio_dprintk (RIO_DEBUG_INTR, "T_BLOCK\n");
-			break;
-	
-		case T_RFLUSH:
-			rio_dprintk (RIO_DEBUG_INTR, "T_RFLUSH\n");
-			if ( PortP->State & RIO_DELETED ) {
-				rio_dprintk (RIO_DEBUG_INTR, "RFLUSH on deleted RTA\n");
-				PortP->RxDataStart = 0;
+		}
+		break;
+		/* FALLTHROUGH */
+	case T_UNBLOCK:
+		rio_dprintk(RIO_DEBUG_INTR, "T_UNBLOCK\n");
+		/*
+		 ** If there is any data to receive set a timeout to service it.
+		 */
+		RIOReceive(p, PortP);
+		break;
+
+	case T_BREAK:
+		rio_dprintk(RIO_DEBUG_INTR, "T_BREAK\n");
+		/*
+		 ** Send a break command. For Sys V
+		 ** this is a timed break, so we
+		 ** send a SBREAK[time] packet
+		 */
+		/*
+		 ** Build a BREAK command
+		 */
+		if (PortP->State & RIO_DELETED) {
+			rio_dprintk(RIO_DEBUG_INTR, "BREAK on deleted RTA\n");
+		} else {
+			if (RIOShortCommand(PortP, SBREAK, 2, p->RIOConf.BreakInterval) == RIO_FAIL) {
+				rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
 			}
-			else {
-				if ( RIOPreemptiveCmd( p, PortP, RFLUSH ) == RIO_FAIL ) {
-					rio_dprintk (RIO_DEBUG_INTR, "T_RFLUSH Command failed\n");
-					return 0;
-				}
-				PortP->RxDataStart = 0;
-				while ( can_remove_receive(&PacketP, PortP) ) {
-					remove_receive(PortP);
-					ShowPacket(DBG_PROC, PacketP );
-					put_free_end(PortP->HostP, PacketP );
-				}
-				if ( PortP->PhbP->handshake == PHB_HANDSHAKE_SET ) {
-					/*
-					** MAGIC!
-					*/
-					rio_dprintk (RIO_DEBUG_INTR, "Set receive handshake bit\n");
-					PortP->PhbP->handshake |= PHB_HANDSHAKE_RESET;
-				}
-			}
-			break;
-			/* FALLTHROUGH */
-		case T_UNBLOCK:
-			rio_dprintk (RIO_DEBUG_INTR, "T_UNBLOCK\n");
-			/*
-			** If there is any data to receive set a timeout to service it.
-			*/
-			RIOReceive(p, PortP);
-			break;
-	
-		case T_BREAK:
-			rio_dprintk (RIO_DEBUG_INTR, "T_BREAK\n");
-			/*
-			** Send a break command. For Sys V
-			** this is a timed break, so we
-			** send a SBREAK[time] packet
-			*/
-			/*
-			** Build a BREAK command
-			*/
-			if ( PortP->State & RIO_DELETED ) {
-				rio_dprintk (RIO_DEBUG_INTR, "BREAK on deleted RTA\n");
-			}
-			else {
-				if (RIOShortCommand(PortP,SBREAK,2,
-								p->RIOConf.BreakInterval)==RIO_FAIL) {
-			   		rio_dprintk (RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
-				}
-			}
-	
-			/*
-			** done!
-			*/
-			break;
-	
-		case T_INPUT:
-			rio_dprintk (RIO_DEBUG_INTR, "Proc T_INPUT called - I don't know what to do!\n");
-			break;
-		case T_PARM:
-			rio_dprintk (RIO_DEBUG_INTR, "Proc T_PARM called - I don't know what to do!\n");
-			break;
-	
-		case T_SWTCH:
-			rio_dprintk (RIO_DEBUG_INTR, "Proc T_SWTCH called - I don't know what to do!\n");
-			break;
-	
-		default:
-			rio_dprintk (RIO_DEBUG_INTR, "Proc UNKNOWN command %d\n",cmd);
+		}
+
+		/*
+		 ** done!
+		 */
+		break;
+
+	case T_INPUT:
+		rio_dprintk(RIO_DEBUG_INTR, "Proc T_INPUT called - I don't know what to do!\n");
+		break;
+	case T_PARM:
+		rio_dprintk(RIO_DEBUG_INTR, "Proc T_PARM called - I don't know what to do!\n");
+		break;
+
+	case T_SWTCH:
+		rio_dprintk(RIO_DEBUG_INTR, "Proc T_SWTCH called - I don't know what to do!\n");
+		break;
+
+	default:
+		rio_dprintk(RIO_DEBUG_INTR, "Proc UNKNOWN command %d\n", cmd);
 	}
 	/*
-	** T_OUTPUT returns without passing through this point!
-	*/
-	/*rio_dprint(RIO_DEBUG_INTR, PortP,DBG_PROC,"riotproc done\n");*/
-	return(0);
+	 ** T_OUTPUT returns without passing through this point!
+	 */
+	/*rio_dprint(RIO_DEBUG_INTR, PortP,DBG_PROC,"riotproc done\n"); */
+	return (0);
 }
 #endif
diff --git a/drivers/char/rio/rioioctl.h b/drivers/char/rio/rioioctl.h
index c3d6797..14b83fa 100644
--- a/drivers/char/rio/rioioctl.h
+++ b/drivers/char/rio/rioioctl.h
@@ -42,14 +42,14 @@
 */
 
 struct portStats {
-	int	port;
-	int	gather;
-	ulong	txchars;
-	ulong	rxchars;
-	ulong	opens;
-	ulong	closes;
-	ulong	ioctls;
-}; 
+	int port;
+	int gather;
+	ulong txchars;
+	ulong rxchars;
+	ulong opens;
+	ulong closes;
+	ulong ioctls;
+};
 
 
 #define rIOC	('r'<<8)
@@ -100,4 +100,4 @@
 #define RIO_RESET_PORT_STATS	(RIOC | 194)
 #define RIO_GET_PORT_STATS	(RIOC | 195)
 
-#endif	/* __rioioctl_h__ */
+#endif				/* __rioioctl_h__ */
diff --git a/drivers/char/rio/rioparam.c b/drivers/char/rio/rioparam.c
index f109163..4cc7f49 100644
--- a/drivers/char/rio/rioparam.c
+++ b/drivers/char/rio/rioparam.c
@@ -157,46 +157,44 @@
 ** NB. for MPX
 **	tty lock must NOT have been previously acquired.
 */
-int
-RIOParam(PortP, cmd, Modem, SleepFlag)
+int RIOParam(PortP, cmd, Modem, SleepFlag)
 struct Port *PortP;
 int cmd;
 int Modem;
-int SleepFlag; 
+int SleepFlag;
 {
 	register struct tty_struct *TtyP;
-	int	retval;
+	int retval;
 	register struct phb_param *phb_param_ptr;
 	PKT *PacketP;
 	int res;
-	uchar Cor1=0, Cor2=0, Cor4=0, Cor5=0;
-	uchar TxXon=0, TxXoff=0, RxXon=0, RxXoff=0;
-	uchar LNext=0, TxBaud=0, RxBaud=0;
-	int		retries = 0xff;
+	uchar Cor1 = 0, Cor2 = 0, Cor4 = 0, Cor5 = 0;
+	uchar TxXon = 0, TxXoff = 0, RxXon = 0, RxXoff = 0;
+	uchar LNext = 0, TxBaud = 0, RxBaud = 0;
+	int retries = 0xff;
 	unsigned long flags;
 
-	func_enter ();
+	func_enter();
 
 	TtyP = PortP->gs.tty;
 
-	rio_dprintk (RIO_DEBUG_PARAM, "RIOParam: Port:%d cmd:%d Modem:%d SleepFlag:%d Mapped: %d, tty=%p\n",
-	    PortP->PortNum, cmd, Modem, SleepFlag, PortP->Mapped, TtyP);
+	rio_dprintk(RIO_DEBUG_PARAM, "RIOParam: Port:%d cmd:%d Modem:%d SleepFlag:%d Mapped: %d, tty=%p\n", PortP->PortNum, cmd, Modem, SleepFlag, PortP->Mapped, TtyP);
 
 	if (!TtyP) {
-	  rio_dprintk (RIO_DEBUG_PARAM, "Can't call rioparam with null tty.\n");
+		rio_dprintk(RIO_DEBUG_PARAM, "Can't call rioparam with null tty.\n");
 
-	  func_exit ();
+		func_exit();
 
-	  return RIO_FAIL;
+		return RIO_FAIL;
 	}
-	rio_spin_lock_irqsave(&PortP->portSem, flags );
+	rio_spin_lock_irqsave(&PortP->portSem, flags);
 
 	if (cmd == OPEN) {
 		/*
-		** If the port is set to store or lock the parameters, and it is
-		** paramed with OPEN, we want to restore the saved port termio, but
-		** only if StoredTermio has been saved, i.e. NOT 1st open after reboot.
-		*/
+		 ** If the port is set to store or lock the parameters, and it is
+		 ** paramed with OPEN, we want to restore the saved port termio, but
+		 ** only if StoredTermio has been saved, i.e. NOT 1st open after reboot.
+		 */
 #if 0
 		if (PortP->FirstOpen) {
 			PortP->StoredTty.iflag = TtyP->tm.c_iflag;
@@ -207,9 +205,8 @@
 			for (i = 0; i < NCC + 5; i++)
 				PortP->StoredTty.cc[i] = TtyP->tm.c_cc[i];
 			PortP->FirstOpen = 0;
-		}
-		else if (PortP->Store || PortP->Lock) {
-			rio_dprintk (RIO_DEBUG_PARAM, "OPEN: Restoring stored/locked params\n");
+		} else if (PortP->Store || PortP->Lock) {
+			rio_dprintk(RIO_DEBUG_PARAM, "OPEN: Restoring stored/locked params\n");
 			TtyP->tm.c_iflag = PortP->StoredTty.iflag;
 			TtyP->tm.c_oflag = PortP->StoredTty.oflag;
 			TtyP->tm.c_cflag = PortP->StoredTty.cflag;
@@ -222,230 +219,222 @@
 	}
 
 	/*
-	** wait for space
-	*/
-	while ( !(res=can_add_transmit(&PacketP,PortP)) || 
-			(PortP->InUse != NOT_INUSE) ) {
-		if (retries -- <= 0) {
+	 ** wait for space
+	 */
+	while (!(res = can_add_transmit(&PacketP, PortP)) || (PortP->InUse != NOT_INUSE)) {
+		if (retries-- <= 0) {
 			break;
 		}
-		if ( PortP->InUse != NOT_INUSE ) {
-			rio_dprintk (RIO_DEBUG_PARAM, "Port IN_USE for pre-emptive command\n");
+		if (PortP->InUse != NOT_INUSE) {
+			rio_dprintk(RIO_DEBUG_PARAM, "Port IN_USE for pre-emptive command\n");
 		}
 
-		if ( !res ) {
-			rio_dprintk (RIO_DEBUG_PARAM, "Port has no space on transmit queue\n");
+		if (!res) {
+			rio_dprintk(RIO_DEBUG_PARAM, "Port has no space on transmit queue\n");
 		}
 
-		if ( SleepFlag != OK_TO_SLEEP ) {
-			rio_spin_unlock_irqrestore( &PortP->portSem, flags);
+		if (SleepFlag != OK_TO_SLEEP) {
+			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 			func_exit();
-			
+
 			return RIO_FAIL;
 		}
 
-		rio_dprintk (RIO_DEBUG_PARAM, "wait for can_add_transmit\n");
-		rio_spin_unlock_irqrestore( &PortP->portSem, flags);
+		rio_dprintk(RIO_DEBUG_PARAM, "wait for can_add_transmit\n");
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 		retval = RIODelay(PortP, HUNDRED_MS);
-		rio_spin_lock_irqsave( &PortP->portSem, flags);
+		rio_spin_lock_irqsave(&PortP->portSem, flags);
 		if (retval == RIO_FAIL) {
-			rio_dprintk (RIO_DEBUG_PARAM, "wait for can_add_transmit broken by signal\n");
-			rio_spin_unlock_irqrestore( &PortP->portSem, flags);
+			rio_dprintk(RIO_DEBUG_PARAM, "wait for can_add_transmit broken by signal\n");
+			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 			pseterr(EINTR);
 			func_exit();
 
 			return RIO_FAIL;
 		}
-		if ( PortP->State & RIO_DELETED ) {
-			rio_spin_unlock_irqrestore( &PortP->portSem, flags);
-			func_exit ();
+		if (PortP->State & RIO_DELETED) {
+			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+			func_exit();
 
 			return RIO_SUCCESS;
 		}
 	}
 
 	if (!res) {
-		rio_spin_unlock_irqrestore( &PortP->portSem, flags);
-		func_exit ();
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		func_exit();
 
 		return RIO_FAIL;
 	}
 
-	rio_dprintk (RIO_DEBUG_PARAM, "can_add_transmit() returns %x\n",res);
-	rio_dprintk (RIO_DEBUG_PARAM, "Packet is 0x%x\n",(int) PacketP);
+	rio_dprintk(RIO_DEBUG_PARAM, "can_add_transmit() returns %x\n", res);
+	rio_dprintk(RIO_DEBUG_PARAM, "Packet is 0x%x\n", (int) PacketP);
 
-	phb_param_ptr = (struct phb_param *)PacketP->data;
+	phb_param_ptr = (struct phb_param *) PacketP->data;
 
 
 #if 0
 	/*
-	** COR 1
-	*/
-	if ( TtyP->tm.c_iflag & INPCK ) {
-		rio_dprintk (RIO_DEBUG_PARAM, "Parity checking on input enabled\n");
+	 ** COR 1
+	 */
+	if (TtyP->tm.c_iflag & INPCK) {
+		rio_dprintk(RIO_DEBUG_PARAM, "Parity checking on input enabled\n");
 		Cor1 |= COR1_INPCK;
 	}
 #endif
 
-	switch ( TtyP->termios->c_cflag & CSIZE ) {
-		case CS5:
+	switch (TtyP->termios->c_cflag & CSIZE) {
+	case CS5:
 		{
-			rio_dprintk (RIO_DEBUG_PARAM, "5 bit data\n");
+			rio_dprintk(RIO_DEBUG_PARAM, "5 bit data\n");
 			Cor1 |= COR1_5BITS;
 			break;
 		}
-		case CS6:
+	case CS6:
 		{
-			rio_dprintk (RIO_DEBUG_PARAM, "6 bit data\n");
+			rio_dprintk(RIO_DEBUG_PARAM, "6 bit data\n");
 			Cor1 |= COR1_6BITS;
 			break;
 		}
-		case CS7:
+	case CS7:
 		{
-			rio_dprintk (RIO_DEBUG_PARAM, "7 bit data\n");
+			rio_dprintk(RIO_DEBUG_PARAM, "7 bit data\n");
 			Cor1 |= COR1_7BITS;
 			break;
 		}
-		case CS8:
+	case CS8:
 		{
-			rio_dprintk (RIO_DEBUG_PARAM, "8 bit data\n");
+			rio_dprintk(RIO_DEBUG_PARAM, "8 bit data\n");
 			Cor1 |= COR1_8BITS;
 			break;
 		}
 	}
 
-	if ( TtyP->termios->c_cflag & CSTOPB ) {
-		rio_dprintk (RIO_DEBUG_PARAM, "2 stop bits\n");
+	if (TtyP->termios->c_cflag & CSTOPB) {
+		rio_dprintk(RIO_DEBUG_PARAM, "2 stop bits\n");
 		Cor1 |= COR1_2STOP;
-	}
-	else {
-		rio_dprintk (RIO_DEBUG_PARAM, "1 stop bit\n");
+	} else {
+		rio_dprintk(RIO_DEBUG_PARAM, "1 stop bit\n");
 		Cor1 |= COR1_1STOP;
 	}
 
-	if ( TtyP->termios->c_cflag & PARENB ) {
-		rio_dprintk (RIO_DEBUG_PARAM, "Enable parity\n");
+	if (TtyP->termios->c_cflag & PARENB) {
+		rio_dprintk(RIO_DEBUG_PARAM, "Enable parity\n");
 		Cor1 |= COR1_NORMAL;
-	}
-	else {
-		rio_dprintk (RIO_DEBUG_PARAM, "Disable parity\n");
+	} else {
+		rio_dprintk(RIO_DEBUG_PARAM, "Disable parity\n");
 		Cor1 |= COR1_NOP;
 	}
-	if ( TtyP->termios->c_cflag & PARODD ) {
-		rio_dprintk (RIO_DEBUG_PARAM, "Odd parity\n");
+	if (TtyP->termios->c_cflag & PARODD) {
+		rio_dprintk(RIO_DEBUG_PARAM, "Odd parity\n");
 		Cor1 |= COR1_ODD;
-	}
-	else {
-		rio_dprintk (RIO_DEBUG_PARAM, "Even parity\n");
-		Cor1 |= COR1_EVEN; 
+	} else {
+		rio_dprintk(RIO_DEBUG_PARAM, "Even parity\n");
+		Cor1 |= COR1_EVEN;
 	}
 
 	/*
-	** COR 2
-	*/
-	if ( TtyP->termios->c_iflag & IXON ) {
-		rio_dprintk (RIO_DEBUG_PARAM, "Enable start/stop output control\n");
+	 ** COR 2
+	 */
+	if (TtyP->termios->c_iflag & IXON) {
+		rio_dprintk(RIO_DEBUG_PARAM, "Enable start/stop output control\n");
 		Cor2 |= COR2_IXON;
-	}
-	else {
-		if ( PortP->Config & RIO_IXON ) {
-			rio_dprintk (RIO_DEBUG_PARAM, "Force enable start/stop output control\n");
+	} else {
+		if (PortP->Config & RIO_IXON) {
+			rio_dprintk(RIO_DEBUG_PARAM, "Force enable start/stop output control\n");
 			Cor2 |= COR2_IXON;
-		}
-		else
-			rio_dprintk (RIO_DEBUG_PARAM, "IXON has been disabled.\n");
+		} else
+			rio_dprintk(RIO_DEBUG_PARAM, "IXON has been disabled.\n");
 	}
 
 	if (TtyP->termios->c_iflag & IXANY) {
-		if ( PortP->Config & RIO_IXANY ) {
-			rio_dprintk (RIO_DEBUG_PARAM, "Enable any key to restart output\n");
+		if (PortP->Config & RIO_IXANY) {
+			rio_dprintk(RIO_DEBUG_PARAM, "Enable any key to restart output\n");
 			Cor2 |= COR2_IXANY;
-		}
-		else
-			rio_dprintk (RIO_DEBUG_PARAM, "IXANY has been disabled due to sanity reasons.\n");
+		} else
+			rio_dprintk(RIO_DEBUG_PARAM, "IXANY has been disabled due to sanity reasons.\n");
 	}
 
-	if ( TtyP->termios->c_iflag & IXOFF ) {
-		rio_dprintk (RIO_DEBUG_PARAM, "Enable start/stop input control 2\n");
+	if (TtyP->termios->c_iflag & IXOFF) {
+		rio_dprintk(RIO_DEBUG_PARAM, "Enable start/stop input control 2\n");
 		Cor2 |= COR2_IXOFF;
 	}
 
-	if ( TtyP->termios->c_cflag & HUPCL ) {
-		rio_dprintk (RIO_DEBUG_PARAM, "Hangup on last close\n");
+	if (TtyP->termios->c_cflag & HUPCL) {
+		rio_dprintk(RIO_DEBUG_PARAM, "Hangup on last close\n");
 		Cor2 |= COR2_HUPCL;
 	}
 
-	if ( C_CRTSCTS (TtyP)) {
-		rio_dprintk (RIO_DEBUG_PARAM, "Rx hardware flow control enabled\n");
+	if (C_CRTSCTS(TtyP)) {
+		rio_dprintk(RIO_DEBUG_PARAM, "Rx hardware flow control enabled\n");
 		Cor2 |= COR2_CTSFLOW;
 		Cor2 |= COR2_RTSFLOW;
 	} else {
-		rio_dprintk (RIO_DEBUG_PARAM, "Rx hardware flow control disabled\n");
+		rio_dprintk(RIO_DEBUG_PARAM, "Rx hardware flow control disabled\n");
 		Cor2 &= ~COR2_CTSFLOW;
 		Cor2 &= ~COR2_RTSFLOW;
 	}
 
 
-	if ( TtyP->termios->c_cflag & CLOCAL ) {
-		rio_dprintk (RIO_DEBUG_PARAM, "Local line\n");
-	}
-	else {
-		rio_dprintk (RIO_DEBUG_PARAM, "Possible Modem line\n");
+	if (TtyP->termios->c_cflag & CLOCAL) {
+		rio_dprintk(RIO_DEBUG_PARAM, "Local line\n");
+	} else {
+		rio_dprintk(RIO_DEBUG_PARAM, "Possible Modem line\n");
 	}
 
 	/*
-	** COR 4 (there is no COR 3)
-	*/
-	if ( TtyP->termios->c_iflag & IGNBRK ) {
-		rio_dprintk (RIO_DEBUG_PARAM, "Ignore break condition\n");
+	 ** COR 4 (there is no COR 3)
+	 */
+	if (TtyP->termios->c_iflag & IGNBRK) {
+		rio_dprintk(RIO_DEBUG_PARAM, "Ignore break condition\n");
 		Cor4 |= COR4_IGNBRK;
 	}
-	if ( !(TtyP->termios->c_iflag & BRKINT) ) {
-		rio_dprintk (RIO_DEBUG_PARAM, "Break generates NULL condition\n");
+	if (!(TtyP->termios->c_iflag & BRKINT)) {
+		rio_dprintk(RIO_DEBUG_PARAM, "Break generates NULL condition\n");
 		Cor4 |= COR4_NBRKINT;
 	} else {
-		rio_dprintk (RIO_DEBUG_PARAM, "Interrupt on	break condition\n");
+		rio_dprintk(RIO_DEBUG_PARAM, "Interrupt on	break condition\n");
 	}
 
-	if ( TtyP->termios->c_iflag & INLCR ) {
-		rio_dprintk (RIO_DEBUG_PARAM, "Map newline to carriage return on input\n");
+	if (TtyP->termios->c_iflag & INLCR) {
+		rio_dprintk(RIO_DEBUG_PARAM, "Map newline to carriage return on input\n");
 		Cor4 |= COR4_INLCR;
 	}
 
-	if ( TtyP->termios->c_iflag & IGNCR ) {
-		rio_dprintk (RIO_DEBUG_PARAM, "Ignore carriage return on input\n");
+	if (TtyP->termios->c_iflag & IGNCR) {
+		rio_dprintk(RIO_DEBUG_PARAM, "Ignore carriage return on input\n");
 		Cor4 |= COR4_IGNCR;
 	}
 
-	if ( TtyP->termios->c_iflag & ICRNL ) {
-		rio_dprintk (RIO_DEBUG_PARAM, "Map carriage return to newline on input\n");
+	if (TtyP->termios->c_iflag & ICRNL) {
+		rio_dprintk(RIO_DEBUG_PARAM, "Map carriage return to newline on input\n");
 		Cor4 |= COR4_ICRNL;
 	}
-	if ( TtyP->termios->c_iflag & IGNPAR ) {
-		rio_dprintk (RIO_DEBUG_PARAM, "Ignore characters with parity errors\n");
+	if (TtyP->termios->c_iflag & IGNPAR) {
+		rio_dprintk(RIO_DEBUG_PARAM, "Ignore characters with parity errors\n");
 		Cor4 |= COR4_IGNPAR;
 	}
-	if ( TtyP->termios->c_iflag & PARMRK ) {
-		rio_dprintk (RIO_DEBUG_PARAM, "Mark parity errors\n");
+	if (TtyP->termios->c_iflag & PARMRK) {
+		rio_dprintk(RIO_DEBUG_PARAM, "Mark parity errors\n");
 		Cor4 |= COR4_PARMRK;
 	}
 
 	/*
-	** Set the RAISEMOD flag to ensure that the modem lines are raised
-	** on reception of a config packet.
-	** The download code handles the zero baud condition.
-	*/
+	 ** Set the RAISEMOD flag to ensure that the modem lines are raised
+	 ** on reception of a config packet.
+	 ** The download code handles the zero baud condition.
+	 */
 	Cor4 |= COR4_RAISEMOD;
 
 	/*
-	** COR 5
-	*/
+	 ** COR 5
+	 */
 
 	Cor5 = COR5_CMOE;
 
 	/*
-	** Set to monitor tbusy/tstop (or not).
-	*/
+	 ** Set to monitor tbusy/tstop (or not).
+	 */
 
 	if (PortP->MonitorTstate)
 		Cor5 |= COR5_TSTATE_ON;
@@ -453,182 +442,195 @@
 		Cor5 |= COR5_TSTATE_OFF;
 
 	/*
-	** Could set LNE here if you wanted LNext processing. SVR4 will use it.
-	*/
-	if ( TtyP->termios->c_iflag & ISTRIP ) {
-		rio_dprintk (RIO_DEBUG_PARAM, "Strip input characters\n");
-		if (! (PortP->State & RIO_TRIAD_MODE)) {
+	 ** Could set LNE here if you wanted LNext processing. SVR4 will use it.
+	 */
+	if (TtyP->termios->c_iflag & ISTRIP) {
+		rio_dprintk(RIO_DEBUG_PARAM, "Strip input characters\n");
+		if (!(PortP->State & RIO_TRIAD_MODE)) {
 			Cor5 |= COR5_ISTRIP;
 		}
 	}
 
-	if ( TtyP->termios->c_oflag & ONLCR ) {
-		rio_dprintk (RIO_DEBUG_PARAM, "Map newline to carriage-return, newline on output\n");
-		if ( PortP->CookMode == COOK_MEDIUM )
+	if (TtyP->termios->c_oflag & ONLCR) {
+		rio_dprintk(RIO_DEBUG_PARAM, "Map newline to carriage-return, newline on output\n");
+		if (PortP->CookMode == COOK_MEDIUM)
 			Cor5 |= COR5_ONLCR;
 	}
-	if ( TtyP->termios->c_oflag & OCRNL ) {
-		rio_dprintk (RIO_DEBUG_PARAM, "Map carriage return to newline on output\n");
-		if ( PortP->CookMode == COOK_MEDIUM )
+	if (TtyP->termios->c_oflag & OCRNL) {
+		rio_dprintk(RIO_DEBUG_PARAM, "Map carriage return to newline on output\n");
+		if (PortP->CookMode == COOK_MEDIUM)
 			Cor5 |= COR5_OCRNL;
 	}
-	if ( ( TtyP->termios->c_oflag & TABDLY) == TAB3 ) {
-		rio_dprintk (RIO_DEBUG_PARAM, "Tab delay 3 set\n");
-		if ( PortP->CookMode == COOK_MEDIUM )
+	if ((TtyP->termios->c_oflag & TABDLY) == TAB3) {
+		rio_dprintk(RIO_DEBUG_PARAM, "Tab delay 3 set\n");
+		if (PortP->CookMode == COOK_MEDIUM)
 			Cor5 |= COR5_TAB3;
 	}
 
 	/*
-	** Flow control bytes.
-	*/
+	 ** Flow control bytes.
+	 */
 	TxXon = TtyP->termios->c_cc[VSTART];
 	TxXoff = TtyP->termios->c_cc[VSTOP];
 	RxXon = TtyP->termios->c_cc[VSTART];
 	RxXoff = TtyP->termios->c_cc[VSTOP];
 	/*
-	** LNEXT byte
-	*/
+	 ** LNEXT byte
+	 */
 	LNext = 0;
 
 	/*
-	** Baud rate bytes
-	*/
-	rio_dprintk (RIO_DEBUG_PARAM, "Mapping of rx/tx baud %x (%x)\n", 
-				     TtyP->termios->c_cflag, CBAUD);
+	 ** Baud rate bytes
+	 */
+	rio_dprintk(RIO_DEBUG_PARAM, "Mapping of rx/tx baud %x (%x)\n", TtyP->termios->c_cflag, CBAUD);
 
 	switch (TtyP->termios->c_cflag & CBAUD) {
 #define e(b) case B ## b : RxBaud = TxBaud = RIO_B ## b ;break
-	  e(50);e(75);e(110);e(134);e(150);e(200);e(300);e(600);e(1200);
-	  e(1800);e(2400);e(4800);e(9600);e(19200);e(38400);e(57600);
-	  e(115200); /* e(230400);e(460800); e(921600);  */
+		e(50);
+		e(75);
+		e(110);
+		e(134);
+		e(150);
+		e(200);
+		e(300);
+		e(600);
+		e(1200);
+		e(1800);
+		e(2400);
+		e(4800);
+		e(9600);
+		e(19200);
+		e(38400);
+		e(57600);
+		e(115200);	/* e(230400);e(460800); e(921600);  */
 	}
 
 	/* XXX MIssing conversion table. XXX */
-	/* 	 (TtyP->termios->c_cflag & V_CBAUD); */
+	/*       (TtyP->termios->c_cflag & V_CBAUD); */
 
-	rio_dprintk (RIO_DEBUG_PARAM, "tx baud 0x%x, rx baud 0x%x\n", TxBaud, RxBaud);
+	rio_dprintk(RIO_DEBUG_PARAM, "tx baud 0x%x, rx baud 0x%x\n", TxBaud, RxBaud);
 
 
 	/*
-	** Leftovers
-	*/
-	if ( TtyP->termios->c_cflag & CREAD )
-		rio_dprintk (RIO_DEBUG_PARAM, "Enable receiver\n");
+	 ** Leftovers
+	 */
+	if (TtyP->termios->c_cflag & CREAD)
+		rio_dprintk(RIO_DEBUG_PARAM, "Enable receiver\n");
 #ifdef RCV1EN
-	if ( TtyP->termios->c_cflag & RCV1EN )
-		rio_dprintk (RIO_DEBUG_PARAM, "RCV1EN (?)\n");
+	if (TtyP->termios->c_cflag & RCV1EN)
+		rio_dprintk(RIO_DEBUG_PARAM, "RCV1EN (?)\n");
 #endif
 #ifdef XMT1EN
-	if ( TtyP->termios->c_cflag & XMT1EN )
-		rio_dprintk (RIO_DEBUG_PARAM, "XMT1EN (?)\n");
+	if (TtyP->termios->c_cflag & XMT1EN)
+		rio_dprintk(RIO_DEBUG_PARAM, "XMT1EN (?)\n");
 #endif
 #if 0
-	if ( TtyP->termios->c_cflag & LOBLK )
-		rio_dprintk (RIO_DEBUG_PARAM, "LOBLK - JCL output blocks when not current\n");
+	if (TtyP->termios->c_cflag & LOBLK)
+		rio_dprintk(RIO_DEBUG_PARAM, "LOBLK - JCL output blocks when not current\n");
 #endif
-	if ( TtyP->termios->c_lflag & ISIG )
-		rio_dprintk (RIO_DEBUG_PARAM, "Input character signal generating enabled\n");
-	if ( TtyP->termios->c_lflag & ICANON )
-		rio_dprintk (RIO_DEBUG_PARAM, "Canonical input: erase and kill enabled\n");
-	if ( TtyP->termios->c_lflag & XCASE )
-		rio_dprintk (RIO_DEBUG_PARAM, "Canonical upper/lower presentation\n");
-	if ( TtyP->termios->c_lflag & ECHO )
-		rio_dprintk (RIO_DEBUG_PARAM, "Enable input echo\n");
-	if ( TtyP->termios->c_lflag & ECHOE )
-		rio_dprintk (RIO_DEBUG_PARAM, "Enable echo erase\n");
-	if ( TtyP->termios->c_lflag & ECHOK )
-		rio_dprintk (RIO_DEBUG_PARAM, "Enable echo kill\n");
-	if ( TtyP->termios->c_lflag & ECHONL )
-		rio_dprintk (RIO_DEBUG_PARAM, "Enable echo newline\n");
-	if ( TtyP->termios->c_lflag & NOFLSH )
-		rio_dprintk (RIO_DEBUG_PARAM, "Disable flush after interrupt or quit\n");
+	if (TtyP->termios->c_lflag & ISIG)
+		rio_dprintk(RIO_DEBUG_PARAM, "Input character signal generating enabled\n");
+	if (TtyP->termios->c_lflag & ICANON)
+		rio_dprintk(RIO_DEBUG_PARAM, "Canonical input: erase and kill enabled\n");
+	if (TtyP->termios->c_lflag & XCASE)
+		rio_dprintk(RIO_DEBUG_PARAM, "Canonical upper/lower presentation\n");
+	if (TtyP->termios->c_lflag & ECHO)
+		rio_dprintk(RIO_DEBUG_PARAM, "Enable input echo\n");
+	if (TtyP->termios->c_lflag & ECHOE)
+		rio_dprintk(RIO_DEBUG_PARAM, "Enable echo erase\n");
+	if (TtyP->termios->c_lflag & ECHOK)
+		rio_dprintk(RIO_DEBUG_PARAM, "Enable echo kill\n");
+	if (TtyP->termios->c_lflag & ECHONL)
+		rio_dprintk(RIO_DEBUG_PARAM, "Enable echo newline\n");
+	if (TtyP->termios->c_lflag & NOFLSH)
+		rio_dprintk(RIO_DEBUG_PARAM, "Disable flush after interrupt or quit\n");
 #ifdef TOSTOP
-	if ( TtyP->termios->c_lflag & TOSTOP )
-		rio_dprintk (RIO_DEBUG_PARAM, "Send SIGTTOU for background output\n");
+	if (TtyP->termios->c_lflag & TOSTOP)
+		rio_dprintk(RIO_DEBUG_PARAM, "Send SIGTTOU for background output\n");
 #endif
 #ifdef XCLUDE
-	if ( TtyP->termios->c_lflag & XCLUDE )
-		rio_dprintk (RIO_DEBUG_PARAM, "Exclusive use of this line\n");
+	if (TtyP->termios->c_lflag & XCLUDE)
+		rio_dprintk(RIO_DEBUG_PARAM, "Exclusive use of this line\n");
 #endif
-	if ( TtyP->termios->c_iflag & IUCLC )
-		rio_dprintk (RIO_DEBUG_PARAM, "Map uppercase to lowercase on input\n");
-	if ( TtyP->termios->c_oflag & OPOST )
-		rio_dprintk (RIO_DEBUG_PARAM, "Enable output post-processing\n");
-	if ( TtyP->termios->c_oflag & OLCUC )
-		rio_dprintk (RIO_DEBUG_PARAM, "Map lowercase to uppercase on output\n");
-	if ( TtyP->termios->c_oflag & ONOCR )
-		rio_dprintk (RIO_DEBUG_PARAM, "No carriage return output at column 0\n");
-	if ( TtyP->termios->c_oflag & ONLRET )
-		rio_dprintk (RIO_DEBUG_PARAM, "Newline performs carriage return function\n");
-	if ( TtyP->termios->c_oflag & OFILL )
-		rio_dprintk (RIO_DEBUG_PARAM, "Use fill characters for delay\n");
-	if ( TtyP->termios->c_oflag & OFDEL )
-		rio_dprintk (RIO_DEBUG_PARAM, "Fill character is DEL\n");
-	if ( TtyP->termios->c_oflag & NLDLY )
-		rio_dprintk (RIO_DEBUG_PARAM, "Newline delay set\n");
-	if ( TtyP->termios->c_oflag & CRDLY )
-		rio_dprintk (RIO_DEBUG_PARAM, "Carriage return delay set\n");
-	if ( TtyP->termios->c_oflag & TABDLY )
-		rio_dprintk (RIO_DEBUG_PARAM, "Tab delay set\n");
+	if (TtyP->termios->c_iflag & IUCLC)
+		rio_dprintk(RIO_DEBUG_PARAM, "Map uppercase to lowercase on input\n");
+	if (TtyP->termios->c_oflag & OPOST)
+		rio_dprintk(RIO_DEBUG_PARAM, "Enable output post-processing\n");
+	if (TtyP->termios->c_oflag & OLCUC)
+		rio_dprintk(RIO_DEBUG_PARAM, "Map lowercase to uppercase on output\n");
+	if (TtyP->termios->c_oflag & ONOCR)
+		rio_dprintk(RIO_DEBUG_PARAM, "No carriage return output at column 0\n");
+	if (TtyP->termios->c_oflag & ONLRET)
+		rio_dprintk(RIO_DEBUG_PARAM, "Newline performs carriage return function\n");
+	if (TtyP->termios->c_oflag & OFILL)
+		rio_dprintk(RIO_DEBUG_PARAM, "Use fill characters for delay\n");
+	if (TtyP->termios->c_oflag & OFDEL)
+		rio_dprintk(RIO_DEBUG_PARAM, "Fill character is DEL\n");
+	if (TtyP->termios->c_oflag & NLDLY)
+		rio_dprintk(RIO_DEBUG_PARAM, "Newline delay set\n");
+	if (TtyP->termios->c_oflag & CRDLY)
+		rio_dprintk(RIO_DEBUG_PARAM, "Carriage return delay set\n");
+	if (TtyP->termios->c_oflag & TABDLY)
+		rio_dprintk(RIO_DEBUG_PARAM, "Tab delay set\n");
 #if 0
-	if ( TtyP->termios->c_oflag & BSDLY )
-		rio_dprintk (RIO_DEBUG_PARAM, "Back-space delay set\n");
-	if ( TtyP->termios->c_oflag & VTDLY )
-		rio_dprintk (RIO_DEBUG_PARAM, "Vertical tab delay set\n");
-	if ( TtyP->termios->c_oflag & FFDLY )
-		rio_dprintk (RIO_DEBUG_PARAM, "Form-feed delay set\n");
+	if (TtyP->termios->c_oflag & BSDLY)
+		rio_dprintk(RIO_DEBUG_PARAM, "Back-space delay set\n");
+	if (TtyP->termios->c_oflag & VTDLY)
+		rio_dprintk(RIO_DEBUG_PARAM, "Vertical tab delay set\n");
+	if (TtyP->termios->c_oflag & FFDLY)
+		rio_dprintk(RIO_DEBUG_PARAM, "Form-feed delay set\n");
 #endif
 	/*
-	** These things are kind of useful in a later life!
-	*/
+	 ** These things are kind of useful in a later life!
+	 */
 	PortP->Cor2Copy = Cor2;
 
-	if ( PortP->State & RIO_DELETED ) {
-		rio_spin_unlock_irqrestore( &PortP->portSem, flags);
-		func_exit ();
+	if (PortP->State & RIO_DELETED) {
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		func_exit();
 
 		return RIO_FAIL;
 	}
 
 	/*
-	** Actually write the info into the packet to be sent
-	*/
-	WBYTE(phb_param_ptr->Cmd,	cmd);
-	WBYTE(phb_param_ptr->Cor1,	 Cor1);
-	WBYTE(phb_param_ptr->Cor2,	 Cor2);
-	WBYTE(phb_param_ptr->Cor4,	 Cor4);
-	WBYTE(phb_param_ptr->Cor5,	 Cor5);
-	WBYTE(phb_param_ptr->TxXon,	TxXon);
-	WBYTE(phb_param_ptr->RxXon,	RxXon);
+	 ** Actually write the info into the packet to be sent
+	 */
+	WBYTE(phb_param_ptr->Cmd, cmd);
+	WBYTE(phb_param_ptr->Cor1, Cor1);
+	WBYTE(phb_param_ptr->Cor2, Cor2);
+	WBYTE(phb_param_ptr->Cor4, Cor4);
+	WBYTE(phb_param_ptr->Cor5, Cor5);
+	WBYTE(phb_param_ptr->TxXon, TxXon);
+	WBYTE(phb_param_ptr->RxXon, RxXon);
 	WBYTE(phb_param_ptr->TxXoff, TxXoff);
 	WBYTE(phb_param_ptr->RxXoff, RxXoff);
-	WBYTE(phb_param_ptr->LNext,	LNext);
+	WBYTE(phb_param_ptr->LNext, LNext);
 	WBYTE(phb_param_ptr->TxBaud, TxBaud);
 	WBYTE(phb_param_ptr->RxBaud, RxBaud);
 
 	/*
-	** Set the length/command field
-	*/
-	WBYTE(PacketP->len , 12 | PKT_CMD_BIT);
+	 ** Set the length/command field
+	 */
+	WBYTE(PacketP->len, 12 | PKT_CMD_BIT);
 
 	/*
-	** The packet is formed - now, whack it off
-	** to its final destination:
-	*/
+	 ** The packet is formed - now, whack it off
+	 ** to its final destination:
+	 */
 	add_transmit(PortP);
 	/*
-	** Count characters transmitted for port statistics reporting
-	*/
+	 ** Count characters transmitted for port statistics reporting
+	 */
 	if (PortP->statsGather)
 		PortP->txchars += 12;
 
-	rio_spin_unlock_irqrestore( &PortP->portSem, flags);
+	rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 
-	rio_dprintk (RIO_DEBUG_PARAM, "add_transmit returned.\n");
+	rio_dprintk(RIO_DEBUG_PARAM, "add_transmit returned.\n");
 	/*
-	** job done.
-	*/
-	func_exit ();
+	 ** job done.
+	 */
+	func_exit();
 
 	return RIO_SUCCESS;
 }
@@ -638,16 +640,15 @@
 ** We can add another packet to a transmit queue if the packet pointer pointed
 ** to by the TxAdd pointer has PKT_IN_USE clear in its address.
 */
-int
-can_add_transmit(PktP, PortP)
+int can_add_transmit(PktP, PortP)
 PKT **PktP;
-struct Port *PortP; 
+struct Port *PortP;
 {
 	register PKT *tp;
 
-	*PktP = tp = (PKT *)RIO_PTR(PortP->Caddr,RWORD(*PortP->TxAdd));
+	*PktP = tp = (PKT *) RIO_PTR(PortP->Caddr, RWORD(*PortP->TxAdd));
 
-	return !((uint)tp & PKT_IN_USE);
+	return !((uint) tp & PKT_IN_USE);
 }
 
 /*
@@ -655,25 +656,22 @@
 ** and then move the TxAdd pointer along one position to point to the next
 ** packet pointer. You must wrap the pointer from the end back to the start.
 */
-void
-add_transmit(PortP)
-struct Port *PortP; 
+void add_transmit(PortP)
+struct Port *PortP;
 {
-  if (RWORD(*PortP->TxAdd) & PKT_IN_USE) {
-    rio_dprintk (RIO_DEBUG_PARAM, "add_transmit: Packet has been stolen!");
-  }
-	WWORD( *(ushort *)PortP->TxAdd, RWORD(*PortP->TxAdd) | PKT_IN_USE);
-	PortP->TxAdd = (PortP->TxAdd == PortP->TxEnd) ? PortP->TxStart : 
-					PortP->TxAdd + 1;
-	WWORD( PortP->PhbP->tx_add , RIO_OFF(PortP->Caddr,PortP->TxAdd) );
+	if (RWORD(*PortP->TxAdd) & PKT_IN_USE) {
+		rio_dprintk(RIO_DEBUG_PARAM, "add_transmit: Packet has been stolen!");
+	}
+	WWORD(*(ushort *) PortP->TxAdd, RWORD(*PortP->TxAdd) | PKT_IN_USE);
+	PortP->TxAdd = (PortP->TxAdd == PortP->TxEnd) ? PortP->TxStart : PortP->TxAdd + 1;
+	WWORD(PortP->PhbP->tx_add, RIO_OFF(PortP->Caddr, PortP->TxAdd));
 }
 
 /****************************************
  * Put a packet onto the end of the
  * free list
  ****************************************/
-void
-put_free_end(HostP, PktP)
+void put_free_end(HostP, PktP)
 struct Host *HostP;
 PKT *PktP;
 {
@@ -688,24 +686,23 @@
 	*
 	************************************************/
 
-	rio_dprintk (RIO_DEBUG_PFE,  "put_free_end(PktP=%x)\n",(int)PktP);
+	rio_dprintk(RIO_DEBUG_PFE, "put_free_end(PktP=%x)\n", (int) PktP);
 
-	if ((old_end=RWORD(HostP->ParmMapP->free_list_end)) != TPNULL) {
-		new_end = RIO_OFF(HostP->Caddr,PktP);
-		tmp_pointer = (FREE_LIST *)RIO_PTR(HostP->Caddr,old_end);
-		WWORD(tmp_pointer->next , new_end );
-		WWORD(((FREE_LIST *)PktP)->prev , old_end);
-		WWORD(((FREE_LIST *)PktP)->next , TPNULL);
+	if ((old_end = RWORD(HostP->ParmMapP->free_list_end)) != TPNULL) {
+		new_end = RIO_OFF(HostP->Caddr, PktP);
+		tmp_pointer = (FREE_LIST *) RIO_PTR(HostP->Caddr, old_end);
+		WWORD(tmp_pointer->next, new_end);
+		WWORD(((FREE_LIST *) PktP)->prev, old_end);
+		WWORD(((FREE_LIST *) PktP)->next, TPNULL);
 		WWORD(HostP->ParmMapP->free_list_end, new_end);
+	} else {		/* First packet on the free list this should never happen! */
+		rio_dprintk(RIO_DEBUG_PFE, "put_free_end(): This should never happen\n");
+		WWORD(HostP->ParmMapP->free_list_end, RIO_OFF(HostP->Caddr, PktP));
+		tmp_pointer = (FREE_LIST *) PktP;
+		WWORD(tmp_pointer->prev, TPNULL);
+		WWORD(tmp_pointer->next, TPNULL);
 	}
-	else {	/* First packet on the free list this should never happen! */
-		rio_dprintk (RIO_DEBUG_PFE, "put_free_end(): This should never happen\n");
-		WWORD(HostP->ParmMapP->free_list_end , RIO_OFF(HostP->Caddr,PktP));
-		tmp_pointer = (FREE_LIST *)PktP;
-		WWORD(tmp_pointer->prev , TPNULL);
-		WWORD(tmp_pointer->next , TPNULL);
-	}
-	rio_dprintk (RIO_DEBUG_CMD, "Before unlock: %p\n", &HostP->HostLock);
+	rio_dprintk(RIO_DEBUG_CMD, "Before unlock: %p\n", &HostP->HostLock);
 	rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
 }
 
@@ -715,14 +712,12 @@
 ** relevant packet, [having cleared the PKT_IN_USE bit]. If PKT_IN_USE is clear,
 ** then can_remove_receive() returns 0.
 */
-int
-can_remove_receive(PktP, PortP)
+int can_remove_receive(PktP, PortP)
 PKT **PktP;
 struct Port *PortP;
 {
-	if ( RWORD(*PortP->RxRemove) & PKT_IN_USE) {
-		*PktP = (PKT *)RIO_PTR(PortP->Caddr,
-					RWORD(*PortP->RxRemove) & ~PKT_IN_USE);
+	if (RWORD(*PortP->RxRemove) & PKT_IN_USE) {
+		*PktP = (PKT *) RIO_PTR(PortP->Caddr, RWORD(*PortP->RxRemove) & ~PKT_IN_USE);
 		return 1;
 	}
 	return 0;
@@ -733,12 +728,10 @@
 ** and then bump the pointers. Once the pointers get to the end, they must
 ** be wrapped back to the start.
 */
-void
-remove_receive(PortP)
-struct Port *PortP; 
+void remove_receive(PortP)
+struct Port *PortP;
 {
-	WWORD( *PortP->RxRemove, RWORD(*PortP->RxRemove) & ~PKT_IN_USE );
-	PortP->RxRemove = (PortP->RxRemove == PortP->RxEnd) ? PortP->RxStart : 
-								PortP->RxRemove + 1;
-	WWORD( PortP->PhbP->rx_remove , RIO_OFF(PortP->Caddr, PortP->RxRemove) );
+	WWORD(*PortP->RxRemove, RWORD(*PortP->RxRemove) & ~PKT_IN_USE);
+	PortP->RxRemove = (PortP->RxRemove == PortP->RxEnd) ? PortP->RxStart : PortP->RxRemove + 1;
+	WWORD(PortP->PhbP->rx_remove, RIO_OFF(PortP->Caddr, PortP->RxRemove));
 }
diff --git a/drivers/char/rio/riopcicopy.c b/drivers/char/rio/riopcicopy.c
index 2ea99a6..535afaa 100644
--- a/drivers/char/rio/riopcicopy.c
+++ b/drivers/char/rio/riopcicopy.c
@@ -1,8 +1,8 @@
 
 /* Yeah. We have copyright on this one. Sure. */
 
-void rio_pcicopy( char *from, char *to, int amount)
+void rio_pcicopy(char *from, char *to, int amount)
 {
-  while ( amount-- )
-    *to++ = *from++;
+	while (amount--)
+		*to++ = *from++;
 }
diff --git a/drivers/char/rio/rioroute.c b/drivers/char/rio/rioroute.c
index e9564c9..0f4cd33 100644
--- a/drivers/char/rio/rioroute.c
+++ b/drivers/char/rio/rioroute.c
@@ -93,625 +93,517 @@
 ** Incoming on the ROUTE_RUP
 ** I wrote this while I was tired. Forgive me.
 */
-int RIORouteRup( struct rio_info *p, uint Rup, struct Host *HostP, PKT *PacketP )
+int RIORouteRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP)
 {
-  struct PktCmd *PktCmdP = (struct PktCmd *)PacketP->data;
-  struct PktCmd_M *PktReplyP;
-  struct CmdBlk *CmdBlkP;
-  struct Port *PortP;
-  struct Map *MapP;
-  struct Top *TopP;
-  int ThisLink, ThisLinkMin, ThisLinkMax;
-  int port;
-  int Mod, Mod1, Mod2;
-  ushort RtaType;
-  uint RtaUniq;
-  uint ThisUnit, ThisUnit2;	/* 2 ids to accommodate 16 port RTA */
-  uint OldUnit, NewUnit, OldLink, NewLink;
-  char *MyType, *MyName;
-  int Lies;
-  unsigned long flags;
+	struct PktCmd *PktCmdP = (struct PktCmd *) PacketP->data;
+	struct PktCmd_M *PktReplyP;
+	struct CmdBlk *CmdBlkP;
+	struct Port *PortP;
+	struct Map *MapP;
+	struct Top *TopP;
+	int ThisLink, ThisLinkMin, ThisLinkMax;
+	int port;
+	int Mod, Mod1, Mod2;
+	ushort RtaType;
+	uint RtaUniq;
+	uint ThisUnit, ThisUnit2;	/* 2 ids to accommodate 16 port RTA */
+	uint OldUnit, NewUnit, OldLink, NewLink;
+	char *MyType, *MyName;
+	int Lies;
+	unsigned long flags;
 
 #ifdef STACK
-    RIOStackCheck("RIORouteRup");
+	RIOStackCheck("RIORouteRup");
 #endif
 #ifdef CHECK
-    CheckPacketP(PacketP);
-    CheckHostP(HostP);
-    CheckRup(Rup);
-    CheckHost(Host);
+	CheckPacketP(PacketP);
+	CheckHostP(HostP);
+	CheckRup(Rup);
+	CheckHost(Host);
 #endif
-  /*
-  ** Is this unit telling us it's current link topology?
-  */
-  if ( RBYTE(PktCmdP->Command) == ROUTE_TOPOLOGY )
-  {
-    MapP = HostP->Mapping;
-
-    /*
-    ** The packet can be sent either by the host or by an RTA.
-    ** If it comes from the host, then we need to fill in the
-    ** Topology array in the host structure. If it came in
-    ** from an RTA then we need to fill in the Mapping structure's
-    ** Topology array for the unit.
-    */
-    if ( Rup >= (ushort)MAX_RUP )
-    {
-      ThisUnit = HOST_ID;
-      TopP = HostP->Topology;
-      MyType = "Host";
-      MyName = HostP->Name;
-      ThisLinkMin = ThisLinkMax = Rup - MAX_RUP;
-    }
-    else
-    {
-      ThisUnit = Rup+1;
-      TopP = HostP->Mapping[Rup].Topology;
-      MyType = "RTA";
-      MyName = HostP->Mapping[Rup].Name;
-      ThisLinkMin = 0;
-      ThisLinkMax = LINKS_PER_UNIT - 1;
-    }
-
-    /*
-    ** Lies will not be tolerated.
-    ** If any pair of links claim to be connected to the same
-    ** place, then ignore this packet completely.
-    */
-    Lies = 0;
-    for ( ThisLink=ThisLinkMin + 1; ThisLink <= ThisLinkMax; ThisLink++)
-    {
-      /*
-      ** it won't lie about network interconnect, total disconnects
-      ** and no-IDs. (or at least, it doesn't *matter* if it does)
-      */
-      if ( RBYTE(PktCmdP->RouteTopology[ThisLink].Unit) > (ushort)MAX_RUP )
-	  continue;
-
-      for ( NewLink=ThisLinkMin; NewLink < ThisLink; NewLink++ )
-      {
-        if ( (RBYTE(PktCmdP->RouteTopology[ThisLink].Unit) ==
-              RBYTE(PktCmdP->RouteTopology[NewLink].Unit)) &&
-	     (RBYTE(PktCmdP->RouteTopology[ThisLink].Link) ==
-              RBYTE(PktCmdP->RouteTopology[NewLink].Link)) )
-	{
-          Lies++;
-	}
-      }
-    }
-
-    if ( Lies )
-    {
-      rio_dprintk (RIO_DEBUG_ROUTE, "LIES! DAMN LIES! %d LIES!\n",Lies);
-      rio_dprintk (RIO_DEBUG_ROUTE, "%d:%c %d:%c %d:%c %d:%c\n",
-          RBYTE(PktCmdP->RouteTopology[0].Unit), 
-	  'A'+RBYTE(PktCmdP->RouteTopology[0].Link),
-          RBYTE(PktCmdP->RouteTopology[1].Unit),
-	  'A'+RBYTE(PktCmdP->RouteTopology[1].Link),
-          RBYTE(PktCmdP->RouteTopology[2].Unit),
-	  'A'+RBYTE(PktCmdP->RouteTopology[2].Link),
-          RBYTE(PktCmdP->RouteTopology[3].Unit),
-	  'A'+RBYTE(PktCmdP->RouteTopology[3].Link));
-      return TRUE;
-    }
-
-    /*
-    ** now, process each link.
-    */
-    for ( ThisLink=ThisLinkMin; ThisLink <= ThisLinkMax; ThisLink++)
-    {
-      /*
-      ** this is what it was connected to
-      */
-      OldUnit = TopP[ThisLink].Unit;
-      OldLink = TopP[ThisLink].Link;
-
-      /*
-      ** this is what it is now connected to
-      */
-      NewUnit = RBYTE(PktCmdP->RouteTopology[ThisLink].Unit);
-      NewLink = RBYTE(PktCmdP->RouteTopology[ThisLink].Link);
-
-      if ( OldUnit != NewUnit || OldLink != NewLink )
-      {
 	/*
-	** something has changed!
-	*/
+	 ** Is this unit telling us it's current link topology?
+	 */
+	if (RBYTE(PktCmdP->Command) == ROUTE_TOPOLOGY) {
+		MapP = HostP->Mapping;
 
-        if ( NewUnit > MAX_RUP &&
-	     NewUnit != ROUTE_DISCONNECT &&
-	     NewUnit != ROUTE_NO_ID &&
-	     NewUnit != ROUTE_INTERCONNECT )
-	{
-	    rio_dprintk (RIO_DEBUG_ROUTE, "I have a link from %s %s to unit %d:%d - I don't like it.\n",
-		  MyType,
-		  MyName,
-		  NewUnit,
-		  NewLink);
+		/*
+		 ** The packet can be sent either by the host or by an RTA.
+		 ** If it comes from the host, then we need to fill in the
+		 ** Topology array in the host structure. If it came in
+		 ** from an RTA then we need to fill in the Mapping structure's
+		 ** Topology array for the unit.
+		 */
+		if (Rup >= (ushort) MAX_RUP) {
+			ThisUnit = HOST_ID;
+			TopP = HostP->Topology;
+			MyType = "Host";
+			MyName = HostP->Name;
+			ThisLinkMin = ThisLinkMax = Rup - MAX_RUP;
+		} else {
+			ThisUnit = Rup + 1;
+			TopP = HostP->Mapping[Rup].Topology;
+			MyType = "RTA";
+			MyName = HostP->Mapping[Rup].Name;
+			ThisLinkMin = 0;
+			ThisLinkMax = LINKS_PER_UNIT - 1;
+		}
+
+		/*
+		 ** Lies will not be tolerated.
+		 ** If any pair of links claim to be connected to the same
+		 ** place, then ignore this packet completely.
+		 */
+		Lies = 0;
+		for (ThisLink = ThisLinkMin + 1; ThisLink <= ThisLinkMax; ThisLink++) {
+			/*
+			 ** it won't lie about network interconnect, total disconnects
+			 ** and no-IDs. (or at least, it doesn't *matter* if it does)
+			 */
+			if (RBYTE(PktCmdP->RouteTopology[ThisLink].Unit) > (ushort) MAX_RUP)
+				continue;
+
+			for (NewLink = ThisLinkMin; NewLink < ThisLink; NewLink++) {
+				if ((RBYTE(PktCmdP->RouteTopology[ThisLink].Unit) == RBYTE(PktCmdP->RouteTopology[NewLink].Unit)) && (RBYTE(PktCmdP->RouteTopology[ThisLink].Link) == RBYTE(PktCmdP->RouteTopology[NewLink].Link))) {
+					Lies++;
+				}
+			}
+		}
+
+		if (Lies) {
+			rio_dprintk(RIO_DEBUG_ROUTE, "LIES! DAMN LIES! %d LIES!\n", Lies);
+			rio_dprintk(RIO_DEBUG_ROUTE, "%d:%c %d:%c %d:%c %d:%c\n",
+				    RBYTE(PktCmdP->RouteTopology[0].Unit),
+				    'A' + RBYTE(PktCmdP->RouteTopology[0].Link),
+				    RBYTE(PktCmdP->RouteTopology[1].Unit),
+				    'A' + RBYTE(PktCmdP->RouteTopology[1].Link), RBYTE(PktCmdP->RouteTopology[2].Unit), 'A' + RBYTE(PktCmdP->RouteTopology[2].Link), RBYTE(PktCmdP->RouteTopology[3].Unit), 'A' + RBYTE(PktCmdP->RouteTopology[3].Link));
+			return TRUE;
+		}
+
+		/*
+		 ** now, process each link.
+		 */
+		for (ThisLink = ThisLinkMin; ThisLink <= ThisLinkMax; ThisLink++) {
+			/*
+			 ** this is what it was connected to
+			 */
+			OldUnit = TopP[ThisLink].Unit;
+			OldLink = TopP[ThisLink].Link;
+
+			/*
+			 ** this is what it is now connected to
+			 */
+			NewUnit = RBYTE(PktCmdP->RouteTopology[ThisLink].Unit);
+			NewLink = RBYTE(PktCmdP->RouteTopology[ThisLink].Link);
+
+			if (OldUnit != NewUnit || OldLink != NewLink) {
+				/*
+				 ** something has changed!
+				 */
+
+				if (NewUnit > MAX_RUP && NewUnit != ROUTE_DISCONNECT && NewUnit != ROUTE_NO_ID && NewUnit != ROUTE_INTERCONNECT) {
+					rio_dprintk(RIO_DEBUG_ROUTE, "I have a link from %s %s to unit %d:%d - I don't like it.\n", MyType, MyName, NewUnit, NewLink);
+				} else {
+					/*
+					 ** put the new values in
+					 */
+					TopP[ThisLink].Unit = NewUnit;
+					TopP[ThisLink].Link = NewLink;
+
+					RIOSetChange(p);
+
+					if (OldUnit <= MAX_RUP) {
+						/*
+						 ** If something has become bust, then re-enable them messages
+						 */
+						if (!p->RIONoMessage)
+							RIOConCon(p, HostP, ThisUnit, ThisLink, OldUnit, OldLink, DISCONNECT);
+					}
+
+					if ((NewUnit <= MAX_RUP) && !p->RIONoMessage)
+						RIOConCon(p, HostP, ThisUnit, ThisLink, NewUnit, NewLink, CONNECT);
+
+					if (NewUnit == ROUTE_NO_ID)
+						rio_dprintk(RIO_DEBUG_ROUTE, "%s %s (%c) is connected to an unconfigured unit.\n", MyType, MyName, 'A' + ThisLink);
+
+					if (NewUnit == ROUTE_INTERCONNECT) {
+						if (!p->RIONoMessage)
+							cprintf("%s '%s' (%c) is connected to another network.\n", MyType, MyName, 'A' + ThisLink);
+					}
+
+					/*
+					 ** perform an update for 'the other end', so that these messages
+					 ** only appears once. Only disconnect the other end if it is pointing
+					 ** at us!
+					 */
+					if (OldUnit == HOST_ID) {
+						if (HostP->Topology[OldLink].Unit == ThisUnit && HostP->Topology[OldLink].Link == ThisLink) {
+							rio_dprintk(RIO_DEBUG_ROUTE, "SETTING HOST (%c) TO DISCONNECTED!\n", OldLink + 'A');
+							HostP->Topology[OldLink].Unit = ROUTE_DISCONNECT;
+							HostP->Topology[OldLink].Link = NO_LINK;
+						} else {
+							rio_dprintk(RIO_DEBUG_ROUTE, "HOST(%c) WAS NOT CONNECTED TO %s (%c)!\n", OldLink + 'A', HostP->Mapping[ThisUnit - 1].Name, ThisLink + 'A');
+						}
+					} else if (OldUnit <= MAX_RUP) {
+						if (HostP->Mapping[OldUnit - 1].Topology[OldLink].Unit == ThisUnit && HostP->Mapping[OldUnit - 1].Topology[OldLink].Link == ThisLink) {
+							rio_dprintk(RIO_DEBUG_ROUTE, "SETTING RTA %s (%c) TO DISCONNECTED!\n", HostP->Mapping[OldUnit - 1].Name, OldLink + 'A');
+							HostP->Mapping[OldUnit - 1].Topology[OldLink].Unit = ROUTE_DISCONNECT;
+							HostP->Mapping[OldUnit - 1].Topology[OldLink].Link = NO_LINK;
+						} else {
+							rio_dprintk(RIO_DEBUG_ROUTE, "RTA %s (%c) WAS NOT CONNECTED TO %s (%c)\n", HostP->Mapping[OldUnit - 1].Name, OldLink + 'A', HostP->Mapping[ThisUnit - 1].Name, ThisLink + 'A');
+						}
+					}
+					if (NewUnit == HOST_ID) {
+						rio_dprintk(RIO_DEBUG_ROUTE, "MARKING HOST (%c) CONNECTED TO %s (%c)\n", NewLink + 'A', MyName, ThisLink + 'A');
+						HostP->Topology[NewLink].Unit = ThisUnit;
+						HostP->Topology[NewLink].Link = ThisLink;
+					} else if (NewUnit <= MAX_RUP) {
+						rio_dprintk(RIO_DEBUG_ROUTE, "MARKING RTA %s (%c) CONNECTED TO %s (%c)\n", HostP->Mapping[NewUnit - 1].Name, NewLink + 'A', MyName, ThisLink + 'A');
+						HostP->Mapping[NewUnit - 1].Topology[NewLink].Unit = ThisUnit;
+						HostP->Mapping[NewUnit - 1].Topology[NewLink].Link = ThisLink;
+					}
+				}
+				RIOSetChange(p);
+				RIOCheckIsolated(p, HostP, OldUnit);
+			}
+		}
+		return TRUE;
 	}
-	else
-	{
-	  /*
-	  ** put the new values in
-	  */
-	  TopP[ThisLink].Unit = NewUnit;
-	  TopP[ThisLink].Link = NewLink;
 
-	  RIOSetChange(p);
-
-	  if ( OldUnit <= MAX_RUP )
-	  {
-	    /*
-	    ** If something has become bust, then re-enable them messages
-	    */
-	    if (! p->RIONoMessage)
-		RIOConCon(p,HostP,ThisUnit,ThisLink,OldUnit,OldLink,DISCONNECT);
-	  }
-
-	  if ( ( NewUnit <= MAX_RUP ) && !p->RIONoMessage )
-	    RIOConCon(p,HostP,ThisUnit,ThisLink,NewUnit,NewLink,CONNECT);
-
-	  if ( NewUnit == ROUTE_NO_ID )
-	    rio_dprintk (RIO_DEBUG_ROUTE, "%s %s (%c) is connected to an unconfigured unit.\n",
-		    MyType,MyName,'A'+ThisLink);
-
-	  if ( NewUnit == ROUTE_INTERCONNECT )
-	  {
-	    if (! p->RIONoMessage)
-		cprintf("%s '%s' (%c) is connected to another network.\n", MyType,MyName,'A'+ThisLink);
-	  }
-
-	  /*
-	  ** perform an update for 'the other end', so that these messages
-	  ** only appears once. Only disconnect the other end if it is pointing
-	  ** at us!
-	  */
-	  if ( OldUnit == HOST_ID )
-	  {
-	    if ( HostP->Topology[OldLink].Unit == ThisUnit &&
-		 HostP->Topology[OldLink].Link == ThisLink )
-	    {
-	      rio_dprintk (RIO_DEBUG_ROUTE, "SETTING HOST (%c) TO DISCONNECTED!\n", OldLink+'A');
-	      HostP->Topology[OldLink].Unit = ROUTE_DISCONNECT;
-	      HostP->Topology[OldLink].Link = NO_LINK;
-	    }
-	    else
-	    {
-	      rio_dprintk (RIO_DEBUG_ROUTE, "HOST(%c) WAS NOT CONNECTED TO %s (%c)!\n",
-		    OldLink+'A',HostP->Mapping[ThisUnit-1].Name,ThisLink+'A');
-	    }
-	  }
-	  else if ( OldUnit <= MAX_RUP )
-	  {
-	    if ( HostP->Mapping[OldUnit-1].Topology[OldLink].Unit == ThisUnit &&
-	         HostP->Mapping[OldUnit-1].Topology[OldLink].Link == ThisLink )
-	    {
-	      rio_dprintk (RIO_DEBUG_ROUTE, "SETTING RTA %s (%c) TO DISCONNECTED!\n",
-				   HostP->Mapping[OldUnit-1].Name,OldLink+'A');
-	      HostP->Mapping[OldUnit-1].Topology[OldLink].Unit=ROUTE_DISCONNECT;
-	      HostP->Mapping[OldUnit-1].Topology[OldLink].Link=NO_LINK;
-	    }
-	    else
-	    {
-	      rio_dprintk (RIO_DEBUG_ROUTE, "RTA %s (%c) WAS NOT CONNECTED TO %s (%c)\n",
-			    HostP->Mapping[OldUnit-1].Name,OldLink+'A',
-			    HostP->Mapping[ThisUnit-1].Name,ThisLink+'A');
-	    }
-	  }
-	  if ( NewUnit == HOST_ID )
-	  {
-	    rio_dprintk (RIO_DEBUG_ROUTE, "MARKING HOST (%c) CONNECTED TO %s (%c)\n",
-				NewLink+'A',MyName,ThisLink+'A');
-	    HostP->Topology[NewLink].Unit = ThisUnit;
-	    HostP->Topology[NewLink].Link = ThisLink;
-	  }
-	  else if ( NewUnit <= MAX_RUP )
-	  {
-	    rio_dprintk (RIO_DEBUG_ROUTE, "MARKING RTA %s (%c) CONNECTED TO %s (%c)\n",
-	      HostP->Mapping[NewUnit-1].Name,NewLink+'A',MyName,ThisLink+'A');
-	    HostP->Mapping[NewUnit-1].Topology[NewLink].Unit=ThisUnit;
-	    HostP->Mapping[NewUnit-1].Topology[NewLink].Link=ThisLink;
-	  }
+	/*
+	 ** The only other command we recognise is a route_request command
+	 */
+	if (RBYTE(PktCmdP->Command) != ROUTE_REQUEST) {
+		rio_dprintk(RIO_DEBUG_ROUTE, "Unknown command %d received on rup %d host %d ROUTE_RUP\n", RBYTE(PktCmdP->Command), Rup, (int) HostP);
+		return TRUE;
 	}
-	RIOSetChange(p);
-	RIOCheckIsolated(p, HostP, OldUnit );
-      }
-    }
-    return TRUE;
-  }
 
-  /*
-  ** The only other command we recognise is a route_request command
-  */
-  if ( RBYTE(PktCmdP->Command) != ROUTE_REQUEST )
-  {
-    rio_dprintk (RIO_DEBUG_ROUTE, "Unknown command %d received on rup %d host %d ROUTE_RUP\n", 
-	   RBYTE(PktCmdP->Command),Rup,(int)HostP);
-    return TRUE;
-  }
-      
-  RtaUniq = (RBYTE(PktCmdP->UniqNum[0])) +
-	    (RBYTE(PktCmdP->UniqNum[1]) << 8) +
-	    (RBYTE(PktCmdP->UniqNum[2]) << 16) +
-	    (RBYTE(PktCmdP->UniqNum[3]) << 24);
+	RtaUniq = (RBYTE(PktCmdP->UniqNum[0])) + (RBYTE(PktCmdP->UniqNum[1]) << 8) + (RBYTE(PktCmdP->UniqNum[2]) << 16) + (RBYTE(PktCmdP->UniqNum[3]) << 24);
 
-  /*
-  ** Determine if 8 or 16 port RTA
-  */
-  RtaType = GetUnitType(RtaUniq);
+	/*
+	 ** Determine if 8 or 16 port RTA
+	 */
+	RtaType = GetUnitType(RtaUniq);
 
-  rio_dprintk (RIO_DEBUG_ROUTE, "Received a request for an ID for serial number %x\n", RtaUniq);
+	rio_dprintk(RIO_DEBUG_ROUTE, "Received a request for an ID for serial number %x\n", RtaUniq);
 
-  Mod = RBYTE(PktCmdP->ModuleTypes);
-  Mod1 = LONYBLE(Mod);
-  if (RtaType == TYPE_RTA16)
-  {
-    /*
-    ** Only one ident is set for a 16 port RTA. To make compatible
-    ** with 8 port, set 2nd ident in Mod2 to the same as Mod1.
-    */
-    Mod2 = Mod1;
-    rio_dprintk (RIO_DEBUG_ROUTE, "Backplane type is %s (all ports)\n",
-     p->RIOModuleTypes[Mod1].Name);
-  }
-  else
-  {
-    Mod2 = HINYBLE(Mod);
-    rio_dprintk (RIO_DEBUG_ROUTE, "Module types are %s (ports 0-3) and %s (ports 4-7)\n",
-     p->RIOModuleTypes[Mod1].Name, p->RIOModuleTypes[Mod2].Name);
-  }
-
-  if ( RtaUniq == 0xffffffff )
-  {
-      ShowPacket( DBG_SPECIAL, PacketP );
-  }
-
-  /*
-  ** try to unhook a command block from the command free list.
-  */
-  if ( !(CmdBlkP = RIOGetCmdBlk()) )
-  {
-    rio_dprintk (RIO_DEBUG_ROUTE, "No command blocks to route RTA! come back later.\n");
-    return 0;
-  }
-
-  /*
-  ** Fill in the default info on the command block
-  */
-  CmdBlkP->Packet.dest_unit = Rup;
-  CmdBlkP->Packet.dest_port = ROUTE_RUP;
-  CmdBlkP->Packet.src_unit = HOST_ID;
-  CmdBlkP->Packet.src_port = ROUTE_RUP;
-  CmdBlkP->Packet.len = PKT_CMD_BIT | 1;
-  CmdBlkP->PreFuncP = CmdBlkP->PostFuncP = NULL;
-  PktReplyP = (struct PktCmd_M *)CmdBlkP->Packet.data;
-
-  if (! RIOBootOk(p, HostP, RtaUniq))
-  {
-    rio_dprintk (RIO_DEBUG_ROUTE, "RTA %x tried to get an ID, but does not belong - FOAD it!\n",
-	  RtaUniq);
-    PktReplyP->Command = ROUTE_FOAD;
-    HostP->Copy("RT_FOAD", PktReplyP->CommandText, 7);
-    RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
-    return TRUE;
-  }
-
-  /*
-  ** Check to see if the RTA is configured for this host
-  */
-  for ( ThisUnit=0; ThisUnit<MAX_RUP; ThisUnit++ )
-  {
-    rio_dprintk (RIO_DEBUG_ROUTE, "Entry %d Flags=%s %s UniqueNum=0x%x\n",
-			ThisUnit,
-			HostP->Mapping[ThisUnit].Flags & SLOT_IN_USE ?
-					    "Slot-In-Use":"Not In Use",
-			HostP->Mapping[ThisUnit].Flags & SLOT_TENTATIVE ? 
-					    "Slot-Tentative":"Not Tentative",
-			HostP->Mapping[ThisUnit].RtaUniqueNum);
-
-    /*
-    ** We have an entry for it.
-    */
-    if ( (HostP->Mapping[ThisUnit].Flags & (SLOT_IN_USE | SLOT_TENTATIVE)) &&
-         (HostP->Mapping[ThisUnit].RtaUniqueNum == RtaUniq) )
-    {
-      if (RtaType == TYPE_RTA16)
-      {
-	  ThisUnit2 = HostP->Mapping[ThisUnit].ID2 - 1;
-          rio_dprintk (RIO_DEBUG_ROUTE, "Found unit 0x%x at slots %d+%d\n",
-					    RtaUniq,ThisUnit,ThisUnit2);
-      }
-      else
-          rio_dprintk (RIO_DEBUG_ROUTE, "Found unit 0x%x at slot %d\n",
-					    RtaUniq,ThisUnit);
-      /*
-      ** If we have no knowledge of booting it, then the host has
-      ** been re-booted, and so we must kill the RTA, so that it
-      ** will be booted again (potentially with new bins)
-      ** and it will then re-ask for an ID, which we will service.
-      */
-      if ( (HostP->Mapping[ThisUnit].Flags & SLOT_IN_USE) && 
-	  !(HostP->Mapping[ThisUnit].Flags & RTA_BOOTED) )
-      {
-	if ( !(HostP->Mapping[ThisUnit].Flags & MSG_DONE) )
-	{
-	    if ( !p->RIONoMessage )
-	        cprintf("RTA '%s' is being updated.\n",HostP->Mapping[ThisUnit].Name);
-	    HostP->Mapping[ThisUnit].Flags |= MSG_DONE;
+	Mod = RBYTE(PktCmdP->ModuleTypes);
+	Mod1 = LONYBLE(Mod);
+	if (RtaType == TYPE_RTA16) {
+		/*
+		 ** Only one ident is set for a 16 port RTA. To make compatible
+		 ** with 8 port, set 2nd ident in Mod2 to the same as Mod1.
+		 */
+		Mod2 = Mod1;
+		rio_dprintk(RIO_DEBUG_ROUTE, "Backplane type is %s (all ports)\n", p->RIOModuleTypes[Mod1].Name);
+	} else {
+		Mod2 = HINYBLE(Mod);
+		rio_dprintk(RIO_DEBUG_ROUTE, "Module types are %s (ports 0-3) and %s (ports 4-7)\n", p->RIOModuleTypes[Mod1].Name, p->RIOModuleTypes[Mod2].Name);
 	}
-	PktReplyP->Command = ROUTE_FOAD;
-	HostP->Copy("RT_FOAD",PktReplyP->CommandText,7);
+
+	if (RtaUniq == 0xffffffff) {
+		ShowPacket(DBG_SPECIAL, PacketP);
+	}
+
+	/*
+	 ** try to unhook a command block from the command free list.
+	 */
+	if (!(CmdBlkP = RIOGetCmdBlk())) {
+		rio_dprintk(RIO_DEBUG_ROUTE, "No command blocks to route RTA! come back later.\n");
+		return 0;
+	}
+
+	/*
+	 ** Fill in the default info on the command block
+	 */
+	CmdBlkP->Packet.dest_unit = Rup;
+	CmdBlkP->Packet.dest_port = ROUTE_RUP;
+	CmdBlkP->Packet.src_unit = HOST_ID;
+	CmdBlkP->Packet.src_port = ROUTE_RUP;
+	CmdBlkP->Packet.len = PKT_CMD_BIT | 1;
+	CmdBlkP->PreFuncP = CmdBlkP->PostFuncP = NULL;
+	PktReplyP = (struct PktCmd_M *) CmdBlkP->Packet.data;
+
+	if (!RIOBootOk(p, HostP, RtaUniq)) {
+		rio_dprintk(RIO_DEBUG_ROUTE, "RTA %x tried to get an ID, but does not belong - FOAD it!\n", RtaUniq);
+		PktReplyP->Command = ROUTE_FOAD;
+		HostP->Copy("RT_FOAD", PktReplyP->CommandText, 7);
+		RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
+		return TRUE;
+	}
+
+	/*
+	 ** Check to see if the RTA is configured for this host
+	 */
+	for (ThisUnit = 0; ThisUnit < MAX_RUP; ThisUnit++) {
+		rio_dprintk(RIO_DEBUG_ROUTE, "Entry %d Flags=%s %s UniqueNum=0x%x\n",
+			    ThisUnit, HostP->Mapping[ThisUnit].Flags & SLOT_IN_USE ? "Slot-In-Use" : "Not In Use", HostP->Mapping[ThisUnit].Flags & SLOT_TENTATIVE ? "Slot-Tentative" : "Not Tentative", HostP->Mapping[ThisUnit].RtaUniqueNum);
+
+		/*
+		 ** We have an entry for it.
+		 */
+		if ((HostP->Mapping[ThisUnit].Flags & (SLOT_IN_USE | SLOT_TENTATIVE)) && (HostP->Mapping[ThisUnit].RtaUniqueNum == RtaUniq)) {
+			if (RtaType == TYPE_RTA16) {
+				ThisUnit2 = HostP->Mapping[ThisUnit].ID2 - 1;
+				rio_dprintk(RIO_DEBUG_ROUTE, "Found unit 0x%x at slots %d+%d\n", RtaUniq, ThisUnit, ThisUnit2);
+			} else
+				rio_dprintk(RIO_DEBUG_ROUTE, "Found unit 0x%x at slot %d\n", RtaUniq, ThisUnit);
+			/*
+			 ** If we have no knowledge of booting it, then the host has
+			 ** been re-booted, and so we must kill the RTA, so that it
+			 ** will be booted again (potentially with new bins)
+			 ** and it will then re-ask for an ID, which we will service.
+			 */
+			if ((HostP->Mapping[ThisUnit].Flags & SLOT_IN_USE) && !(HostP->Mapping[ThisUnit].Flags & RTA_BOOTED)) {
+				if (!(HostP->Mapping[ThisUnit].Flags & MSG_DONE)) {
+					if (!p->RIONoMessage)
+						cprintf("RTA '%s' is being updated.\n", HostP->Mapping[ThisUnit].Name);
+					HostP->Mapping[ThisUnit].Flags |= MSG_DONE;
+				}
+				PktReplyP->Command = ROUTE_FOAD;
+				HostP->Copy("RT_FOAD", PktReplyP->CommandText, 7);
+				RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
+				return TRUE;
+			}
+
+			/*
+			 ** Send the ID (entry) to this RTA. The ID number is implicit as
+			 ** the offset into the table. It is worth noting at this stage
+			 ** that offset zero in the table contains the entries for the
+			 ** RTA with ID 1!!!!
+			 */
+			PktReplyP->Command = ROUTE_ALLOCATE;
+			PktReplyP->IDNum = ThisUnit + 1;
+			if (RtaType == TYPE_RTA16) {
+				if (HostP->Mapping[ThisUnit].Flags & SLOT_IN_USE)
+					/*
+					 ** Adjust the phb and tx pkt dest_units for 2nd block of 8
+					 ** only if the RTA has ports associated (SLOT_IN_USE)
+					 */
+					RIOFixPhbs(p, HostP, ThisUnit2);
+				PktReplyP->IDNum2 = ThisUnit2 + 1;
+				rio_dprintk(RIO_DEBUG_ROUTE, "RTA '%s' has been allocated IDs %d+%d\n", HostP->Mapping[ThisUnit].Name, PktReplyP->IDNum, PktReplyP->IDNum2);
+			} else {
+				PktReplyP->IDNum2 = ROUTE_NO_ID;
+				rio_dprintk(RIO_DEBUG_ROUTE, "RTA '%s' has been allocated ID %d\n", HostP->Mapping[ThisUnit].Name, PktReplyP->IDNum);
+			}
+			HostP->Copy("RT_ALLOCAT", PktReplyP->CommandText, 10);
+
+			RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
+
+			/*
+			 ** If this is a freshly booted RTA, then we need to re-open
+			 ** the ports, if any where open, so that data may once more
+			 ** flow around the system!
+			 */
+			if ((HostP->Mapping[ThisUnit].Flags & RTA_NEWBOOT) && (HostP->Mapping[ThisUnit].SysPort != NO_PORT)) {
+				/*
+				 ** look at the ports associated with this beast and
+				 ** see if any where open. If they was, then re-open
+				 ** them, using the info from the tty flags.
+				 */
+				for (port = 0; port < PORTS_PER_RTA; port++) {
+					PortP = p->RIOPortp[port + HostP->Mapping[ThisUnit].SysPort];
+					if (PortP->State & (RIO_MOPEN | RIO_LOPEN)) {
+						rio_dprintk(RIO_DEBUG_ROUTE, "Re-opened this port\n");
+						rio_spin_lock_irqsave(&PortP->portSem, flags);
+						PortP->MagicFlags |= MAGIC_REBOOT;
+						rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+					}
+				}
+				if (RtaType == TYPE_RTA16) {
+					for (port = 0; port < PORTS_PER_RTA; port++) {
+						PortP = p->RIOPortp[port + HostP->Mapping[ThisUnit2].SysPort];
+						if (PortP->State & (RIO_MOPEN | RIO_LOPEN)) {
+							rio_dprintk(RIO_DEBUG_ROUTE, "Re-opened this port\n");
+							rio_spin_lock_irqsave(&PortP->portSem, flags);
+							PortP->MagicFlags |= MAGIC_REBOOT;
+							rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+						}
+					}
+				}
+			}
+
+			/*
+			 ** keep a copy of the module types!
+			 */
+			HostP->UnixRups[ThisUnit].ModTypes = Mod;
+			if (RtaType == TYPE_RTA16)
+				HostP->UnixRups[ThisUnit2].ModTypes = Mod;
+
+			/*
+			 ** If either of the modules on this unit is read-only or write-only
+			 ** or none-xprint, then we need to transfer that info over to the
+			 ** relevant ports.
+			 */
+			if (HostP->Mapping[ThisUnit].SysPort != NO_PORT) {
+				for (port = 0; port < PORTS_PER_MODULE; port++) {
+					p->RIOPortp[port + HostP->Mapping[ThisUnit].SysPort]->Config &= ~RIO_NOMASK;
+					p->RIOPortp[port + HostP->Mapping[ThisUnit].SysPort]->Config |= p->RIOModuleTypes[Mod1].Flags[port];
+					p->RIOPortp[port + PORTS_PER_MODULE + HostP->Mapping[ThisUnit].SysPort]->Config &= ~RIO_NOMASK;
+					p->RIOPortp[port + PORTS_PER_MODULE + HostP->Mapping[ThisUnit].SysPort]->Config |= p->RIOModuleTypes[Mod2].Flags[port];
+				}
+				if (RtaType == TYPE_RTA16) {
+					for (port = 0; port < PORTS_PER_MODULE; port++) {
+						p->RIOPortp[port + HostP->Mapping[ThisUnit2].SysPort]->Config &= ~RIO_NOMASK;
+						p->RIOPortp[port + HostP->Mapping[ThisUnit2].SysPort]->Config |= p->RIOModuleTypes[Mod1].Flags[port];
+						p->RIOPortp[port + PORTS_PER_MODULE + HostP->Mapping[ThisUnit2].SysPort]->Config &= ~RIO_NOMASK;
+						p->RIOPortp[port + PORTS_PER_MODULE + HostP->Mapping[ThisUnit2].SysPort]->Config |= p->RIOModuleTypes[Mod2].Flags[port];
+					}
+				}
+			}
+
+			/*
+			 ** Job done, get on with the interrupts!
+			 */
+			return TRUE;
+		}
+	}
+	/*
+	 ** There is no table entry for this RTA at all.
+	 **
+	 ** Lets check to see if we actually booted this unit - if not,
+	 ** then we reset it and it will go round the loop of being booted
+	 ** we can then worry about trying to fit it into the table.
+	 */
+	for (ThisUnit = 0; ThisUnit < HostP->NumExtraBooted; ThisUnit++)
+		if (HostP->ExtraUnits[ThisUnit] == RtaUniq)
+			break;
+	if (ThisUnit == HostP->NumExtraBooted && ThisUnit != MAX_EXTRA_UNITS) {
+		/*
+		 ** if the unit wasn't in the table, and the table wasn't full, then
+		 ** we reset the unit, because we didn't boot it.
+		 ** However, if the table is full, it could be that we did boot
+		 ** this unit, and so we won't reboot it, because it isn't really
+		 ** all that disasterous to keep the old bins in most cases. This
+		 ** is a rather tacky feature, but we are on the edge of reallity
+		 ** here, because the implication is that someone has connected
+		 ** 16+MAX_EXTRA_UNITS onto one host.
+		 */
+		static int UnknownMesgDone = 0;
+
+		if (!UnknownMesgDone) {
+			if (!p->RIONoMessage)
+				cprintf("One or more unknown RTAs are being updated.\n");
+			UnknownMesgDone = 1;
+		}
+
+		PktReplyP->Command = ROUTE_FOAD;
+		HostP->Copy("RT_FOAD", PktReplyP->CommandText, 7);
+	} else {
+		/*
+		 ** we did boot it (as an extra), and there may now be a table
+		 ** slot free (because of a delete), so we will try to make
+		 ** a tentative entry for it, so that the configurator can see it
+		 ** and fill in the details for us.
+		 */
+		if (RtaType == TYPE_RTA16) {
+			if (RIOFindFreeID(p, HostP, &ThisUnit, &ThisUnit2) == 0) {
+				RIODefaultName(p, HostP, ThisUnit);
+				FillSlot(ThisUnit, ThisUnit2, RtaUniq, HostP);
+			}
+		} else {
+			if (RIOFindFreeID(p, HostP, &ThisUnit, NULL) == 0) {
+				RIODefaultName(p, HostP, ThisUnit);
+				FillSlot(ThisUnit, 0, RtaUniq, HostP);
+			}
+		}
+		PktReplyP->Command = ROUTE_USED;
+		HostP->Copy("RT_USED", PktReplyP->CommandText, 7);
+	}
 	RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
 	return TRUE;
-      }
-
-      /*
-      ** Send the ID (entry) to this RTA. The ID number is implicit as
-      ** the offset into the table. It is worth noting at this stage
-      ** that offset zero in the table contains the entries for the
-      ** RTA with ID 1!!!!
-      */
-      PktReplyP->Command = ROUTE_ALLOCATE;
-      PktReplyP->IDNum   = ThisUnit+1;
-      if (RtaType == TYPE_RTA16)
-      {
-        if (HostP->Mapping[ThisUnit].Flags & SLOT_IN_USE)
-	    /*
-	    ** Adjust the phb and tx pkt dest_units for 2nd block of 8
-	    ** only if the RTA has ports associated (SLOT_IN_USE)
-	    */
-	    RIOFixPhbs(p, HostP, ThisUnit2);
-	    PktReplyP->IDNum2  = ThisUnit2+1;
-	    rio_dprintk (RIO_DEBUG_ROUTE, "RTA '%s' has been allocated IDs %d+%d\n",
-	          HostP->Mapping[ThisUnit].Name, PktReplyP->IDNum, PktReplyP->IDNum2);
-      }
-      else
-      {
-	    PktReplyP->IDNum2 = ROUTE_NO_ID;
-	    rio_dprintk (RIO_DEBUG_ROUTE, "RTA '%s' has been allocated ID %d\n",
-	          HostP->Mapping[ThisUnit].Name,PktReplyP->IDNum);
-      }
-      HostP->Copy("RT_ALLOCAT",PktReplyP->CommandText,10);
-
-      RIOQueueCmdBlk( HostP, Rup, CmdBlkP);
-
-      /*
-      ** If this is a freshly booted RTA, then we need to re-open
-      ** the ports, if any where open, so that data may once more
-      ** flow around the system!
-      */
-      if ( (HostP->Mapping[ThisUnit].Flags & RTA_NEWBOOT) &&
-	   (HostP->Mapping[ThisUnit].SysPort != NO_PORT) )
-      {
-	/*
-	** look at the ports associated with this beast and
-	** see if any where open. If they was, then re-open
-	** them, using the info from the tty flags.
-	*/
-	for ( port=0; port<PORTS_PER_RTA; port++ )
-	{
-	  PortP = p->RIOPortp[port+HostP->Mapping[ThisUnit].SysPort];
-	  if ( PortP->State & (RIO_MOPEN|RIO_LOPEN) )
-	  {
-	    rio_dprintk (RIO_DEBUG_ROUTE, "Re-opened this port\n");
-	    rio_spin_lock_irqsave(&PortP->portSem, flags);
-	    PortP->MagicFlags |= MAGIC_REBOOT;
-	    rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-	  }
-	}
-	if (RtaType == TYPE_RTA16)
-	{
-	  for ( port=0; port<PORTS_PER_RTA; port++ )
-	  {
-	    PortP = p->RIOPortp[port+HostP->Mapping[ThisUnit2].SysPort];
-	    if ( PortP->State & (RIO_MOPEN|RIO_LOPEN) )
-	    {
-	      rio_dprintk (RIO_DEBUG_ROUTE, "Re-opened this port\n");
-	      rio_spin_lock_irqsave(&PortP->portSem, flags);
-	      PortP->MagicFlags |= MAGIC_REBOOT;
-	      rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-	    }
-	  }
-	}
-      }
-
-      /*
-      ** keep a copy of the module types!
-      */
-      HostP->UnixRups[ThisUnit].ModTypes = Mod;
-      if (RtaType == TYPE_RTA16)
-	      HostP->UnixRups[ThisUnit2].ModTypes = Mod;
-
-      /*
-      ** If either of the modules on this unit is read-only or write-only
-      ** or none-xprint, then we need to transfer that info over to the
-      ** relevant ports.
-      */
-      if ( HostP->Mapping[ThisUnit].SysPort != NO_PORT )
-      {
-        for ( port=0; port<PORTS_PER_MODULE; port++ )
-	{
-	  p->RIOPortp[port+HostP->Mapping[ThisUnit].SysPort]->Config &= ~RIO_NOMASK;
-	  p->RIOPortp[port+HostP->Mapping[ThisUnit].SysPort]->Config |=
-	   p->RIOModuleTypes[Mod1].Flags[port];
-	  p->RIOPortp[port+PORTS_PER_MODULE+HostP->Mapping[ThisUnit].SysPort]->Config &= ~RIO_NOMASK;
-	  p->RIOPortp[port+PORTS_PER_MODULE+HostP->Mapping[ThisUnit].SysPort]->Config |= p->RIOModuleTypes[Mod2].Flags[port];
-	}
-	if (RtaType == TYPE_RTA16)
-	{
-          for ( port=0; port<PORTS_PER_MODULE; port++ )
-	  {
-	    p->RIOPortp[port+HostP->Mapping[ThisUnit2].SysPort]->Config &= ~RIO_NOMASK;
-	    p->RIOPortp[port+HostP->Mapping[ThisUnit2].SysPort]->Config |= p->RIOModuleTypes[Mod1].Flags[port];
-	    p->RIOPortp[port+PORTS_PER_MODULE+HostP->Mapping[ThisUnit2].SysPort]->Config &= ~RIO_NOMASK;
-	    p->RIOPortp[port+PORTS_PER_MODULE+HostP->Mapping[ThisUnit2].SysPort]->Config |= p->RIOModuleTypes[Mod2].Flags[port];
-          }
-	}
-      }
-
-      /*
-      ** Job done, get on with the interrupts!
-      */
-      return TRUE;
-    }
-  }
-  /*
-  ** There is no table entry for this RTA at all.
-  **
-  ** Lets check to see if we actually booted this unit - if not,
-  ** then we reset it and it will go round the loop of being booted
-  ** we can then worry about trying to fit it into the table.
-  */
-  for ( ThisUnit=0; ThisUnit<HostP->NumExtraBooted; ThisUnit++ )
-    if ( HostP->ExtraUnits[ThisUnit] == RtaUniq )
-      break;
-  if ( ThisUnit == HostP->NumExtraBooted && ThisUnit != MAX_EXTRA_UNITS )
-  {
-    /*
-    ** if the unit wasn't in the table, and the table wasn't full, then
-    ** we reset the unit, because we didn't boot it.
-    ** However, if the table is full, it could be that we did boot
-    ** this unit, and so we won't reboot it, because it isn't really
-    ** all that disasterous to keep the old bins in most cases. This
-    ** is a rather tacky feature, but we are on the edge of reallity
-    ** here, because the implication is that someone has connected
-    ** 16+MAX_EXTRA_UNITS onto one host.
-    */
-    static int UnknownMesgDone = 0;
-
-    if ( !UnknownMesgDone )
-    {
-	if (! p->RIONoMessage)
-	    cprintf("One or more unknown RTAs are being updated.\n");
-	UnknownMesgDone = 1;
-    }
-
-    PktReplyP->Command = ROUTE_FOAD;
-    HostP->Copy("RT_FOAD",PktReplyP->CommandText,7);
-  }
-  else
-  {
-    /*
-    ** we did boot it (as an extra), and there may now be a table
-    ** slot free (because of a delete), so we will try to make
-    ** a tentative entry for it, so that the configurator can see it
-    ** and fill in the details for us.
-    */
-    if (RtaType == TYPE_RTA16)
-    {
-	if (RIOFindFreeID(p, HostP, &ThisUnit, &ThisUnit2) == 0)
-	{
-	    RIODefaultName(p, HostP, ThisUnit);
-	    FillSlot(ThisUnit, ThisUnit2, RtaUniq, HostP);
-	}
-    }
-    else
-    {
-	if (RIOFindFreeID(p, HostP, &ThisUnit, NULL) == 0)
-	{
-	    RIODefaultName(p, HostP, ThisUnit);
-	    FillSlot(ThisUnit, 0, RtaUniq, HostP);
-	}
-    }
-    PktReplyP->Command = ROUTE_USED;
-    HostP->Copy("RT_USED",PktReplyP->CommandText,7);
-  }
-  RIOQueueCmdBlk( HostP, Rup, CmdBlkP);
-  return TRUE;
 }
 
 
-void
-RIOFixPhbs(p, HostP, unit)
+void RIOFixPhbs(p, HostP, unit)
 struct rio_info *p;
 struct Host *HostP;
 uint unit;
 {
-	ushort			link, port;
-	struct Port		*PortP;
+	ushort link, port;
+	struct Port *PortP;
 	unsigned long flags;
 	int PortN = HostP->Mapping[unit].SysPort;
 
-	rio_dprintk (RIO_DEBUG_ROUTE, "RIOFixPhbs unit %d sysport %d\n", unit, PortN);
+	rio_dprintk(RIO_DEBUG_ROUTE, "RIOFixPhbs unit %d sysport %d\n", unit, PortN);
 
 	if (PortN != -1) {
-		ushort		dest_unit = HostP->Mapping[unit].ID2;
+		ushort dest_unit = HostP->Mapping[unit].ID2;
 
 		/*
-		** Get the link number used for the 1st 8 phbs on this unit.
-		*/
+		 ** Get the link number used for the 1st 8 phbs on this unit.
+		 */
 		PortP = p->RIOPortp[HostP->Mapping[dest_unit - 1].SysPort];
 
 		link = RWORD(PortP->PhbP->link);
 
 		for (port = 0; port < PORTS_PER_RTA; port++, PortN++) {
-			ushort		dest_port = port + 8;
+			ushort dest_port = port + 8;
 #if 0
-			uint		PktInt;
+			uint PktInt;
 #endif
-			WORD		*TxPktP;
-			PKT		*Pkt;
+			WORD *TxPktP;
+			PKT *Pkt;
 
 			PortP = p->RIOPortp[PortN];
 
 			rio_spin_lock_irqsave(&PortP->portSem, flags);
 			/*
-			** If RTA is not powered on, the tx packets will be
-			** unset, so go no further.
-			*/
+			 ** If RTA is not powered on, the tx packets will be
+			 ** unset, so go no further.
+			 */
 			if (PortP->TxStart == 0) {
-					rio_dprintk (RIO_DEBUG_ROUTE, "Tx pkts not set up yet\n");
-					rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-					break;
+				rio_dprintk(RIO_DEBUG_ROUTE, "Tx pkts not set up yet\n");
+				rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+				break;
 			}
 
 			/*
-			** For the second slot of a 16 port RTA, the driver needs to
-			** sort out the phb to port mappings. The dest_unit for this
-			** group of 8 phbs is set to the dest_unit of the accompanying
-			** 8 port block. The dest_port of the second unit is set to
-			** be in the range 8-15 (i.e. 8 is added). Thus, for a 16 port
-			** RTA with IDs 5 and 6, traffic bound for port 6 of unit 6
-			** (being the second map ID) will be sent to dest_unit 5, port
-			** 14. When this RTA is deleted, dest_unit for ID 6 will be
-			** restored, and the dest_port will be reduced by 8.
-			** Transmit packets also have a destination field which needs
-			** adjusting in the same manner.
-			** Note that the unit/port bytes in 'dest' are swapped.
-			** We also need to adjust the phb and rup link numbers for the
-			** second block of 8 ttys.
-			*/
+			 ** For the second slot of a 16 port RTA, the driver needs to
+			 ** sort out the phb to port mappings. The dest_unit for this
+			 ** group of 8 phbs is set to the dest_unit of the accompanying
+			 ** 8 port block. The dest_port of the second unit is set to
+			 ** be in the range 8-15 (i.e. 8 is added). Thus, for a 16 port
+			 ** RTA with IDs 5 and 6, traffic bound for port 6 of unit 6
+			 ** (being the second map ID) will be sent to dest_unit 5, port
+			 ** 14. When this RTA is deleted, dest_unit for ID 6 will be
+			 ** restored, and the dest_port will be reduced by 8.
+			 ** Transmit packets also have a destination field which needs
+			 ** adjusting in the same manner.
+			 ** Note that the unit/port bytes in 'dest' are swapped.
+			 ** We also need to adjust the phb and rup link numbers for the
+			 ** second block of 8 ttys.
+			 */
 			for (TxPktP = PortP->TxStart; TxPktP <= PortP->TxEnd; TxPktP++) {
 				/*
-				** *TxPktP is the pointer to the transmit packet on the host
-				** card. This needs to be translated into a 32 bit pointer
-				** so it can be accessed from the driver.
-				*/
-				Pkt = (PKT *) RIO_PTR(HostP->Caddr,RINDW(TxPktP));
+				 ** *TxPktP is the pointer to the transmit packet on the host
+				 ** card. This needs to be translated into a 32 bit pointer
+				 ** so it can be accessed from the driver.
+				 */
+				Pkt = (PKT *) RIO_PTR(HostP->Caddr, RINDW(TxPktP));
 
 				/*
-				** If the packet is used, reset it.
-				*/
-				Pkt = (PKT *)((uint)Pkt & ~PKT_IN_USE);
+				 ** If the packet is used, reset it.
+				 */
+				Pkt = (PKT *) ((uint) Pkt & ~PKT_IN_USE);
 				WBYTE(Pkt->dest_unit, dest_unit);
 				WBYTE(Pkt->dest_port, dest_port);
 			}
-			rio_dprintk (RIO_DEBUG_ROUTE, "phb dest: Old %x:%x New %x:%x\n",
-					RWORD(PortP->PhbP->destination) & 0xff,
-					(RWORD(PortP->PhbP->destination) >> 8) & 0xff,
-					dest_unit, dest_port);
+			rio_dprintk(RIO_DEBUG_ROUTE, "phb dest: Old %x:%x New %x:%x\n", RWORD(PortP->PhbP->destination) & 0xff, (RWORD(PortP->PhbP->destination) >> 8) & 0xff, dest_unit, dest_port);
 			WWORD(PortP->PhbP->destination, dest_unit + (dest_port << 8));
 			WWORD(PortP->PhbP->link, link);
 
 			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 		}
 		/*
-		** Now make sure the range of ports to be serviced includes
-		** the 2nd 8 on this 16 port RTA.
-		*/
-		if (link > 3) return;
+		 ** Now make sure the range of ports to be serviced includes
+		 ** the 2nd 8 on this 16 port RTA.
+		 */
+		if (link > 3)
+			return;
 		if (((unit * 8) + 7) > RWORD(HostP->LinkStrP[link].last_port)) {
-			rio_dprintk (RIO_DEBUG_ROUTE, "last port on host link %d: %d\n", link, (unit * 8) + 7);
+			rio_dprintk(RIO_DEBUG_ROUTE, "last port on host link %d: %d\n", link, (unit * 8) + 7);
 			WWORD(HostP->LinkStrP[link].last_port, (unit * 8) + 7);
 		}
 	}
@@ -723,9 +615,8 @@
 ** the world about it. This is done to ensure that the configurator
 ** only gets up-to-date information about what is going on.
 */
-static int
-RIOCheckIsolated(p, HostP, UnitId)
-struct rio_info *	p;
+static int RIOCheckIsolated(p, HostP, UnitId)
+struct rio_info *p;
 struct Host *HostP;
 uint UnitId;
 {
@@ -733,16 +624,16 @@
 	rio_spin_lock_irqsave(&HostP->HostLock, flags);
 
 #ifdef CHECK
-	CheckHostP( HostP );
-	CheckUnitId( UnitId );
+	CheckHostP(HostP);
+	CheckUnitId(UnitId);
 #endif
-	if ( RIOCheck( HostP, UnitId ) ) {
-		rio_dprintk (RIO_DEBUG_ROUTE, "Unit %d is NOT isolated\n", UnitId);
+	if (RIOCheck(HostP, UnitId)) {
+		rio_dprintk(RIO_DEBUG_ROUTE, "Unit %d is NOT isolated\n", UnitId);
 		rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
-		return(0);
+		return (0);
 	}
 
-	RIOIsolate(p, HostP, UnitId );
+	RIOIsolate(p, HostP, UnitId);
 	RIOSetChange(p);
 	rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
 	return 1;
@@ -753,85 +644,83 @@
 ** all the units attached to it. This will mean that the entire
 ** subnet will re-introduce itself.
 */
-static int
-RIOIsolate(p, HostP, UnitId)
-struct rio_info *	p;
-struct Host *		HostP;
-uint UnitId; 
+static int RIOIsolate(p, HostP, UnitId)
+struct rio_info *p;
+struct Host *HostP;
+uint UnitId;
 {
 	uint link, unit;
 
 #ifdef CHECK
-	CheckHostP( HostP );
-	CheckUnitId( UnitId );
+	CheckHostP(HostP);
+	CheckUnitId(UnitId);
 #endif
 	UnitId--;		/* this trick relies on the Unit Id being UNSIGNED! */
 
-	if ( UnitId >= MAX_RUP )	/* dontcha just lurv unsigned maths! */
-		return(0);
+	if (UnitId >= MAX_RUP)	/* dontcha just lurv unsigned maths! */
+		return (0);
 
-	if ( HostP->Mapping[UnitId].Flags & BEEN_HERE )
-		return(0);
+	if (HostP->Mapping[UnitId].Flags & BEEN_HERE)
+		return (0);
 
 	HostP->Mapping[UnitId].Flags |= BEEN_HERE;
 
-	if ( p->RIOPrintDisabled == DO_PRINT )
-		rio_dprintk (RIO_DEBUG_ROUTE, "RIOMesgIsolated %s", HostP->Mapping[UnitId].Name);
+	if (p->RIOPrintDisabled == DO_PRINT)
+		rio_dprintk(RIO_DEBUG_ROUTE, "RIOMesgIsolated %s", HostP->Mapping[UnitId].Name);
 
-	for ( link=0; link<LINKS_PER_UNIT; link++) {
+	for (link = 0; link < LINKS_PER_UNIT; link++) {
 		unit = HostP->Mapping[UnitId].Topology[link].Unit;
 		HostP->Mapping[UnitId].Topology[link].Unit = ROUTE_DISCONNECT;
 		HostP->Mapping[UnitId].Topology[link].Link = NO_LINK;
-		RIOIsolate(p, HostP, unit );
+		RIOIsolate(p, HostP, unit);
 	}
 	HostP->Mapping[UnitId].Flags &= ~BEEN_HERE;
 	return 1;
 }
 
-static int
-RIOCheck(HostP, UnitId)
+static int RIOCheck(HostP, UnitId)
 struct Host *HostP;
 uint UnitId;
 {
-  unsigned char link;
+	unsigned char link;
 
 #ifdef CHECK
-	CheckHostP( HostP );
-	CheckUnitId( UnitId );
+	CheckHostP(HostP);
+	CheckUnitId(UnitId);
 #endif
 /* 	rio_dprint(RIO_DEBUG_ROUTE, ("Check to see if unit %d has a route to the host\n",UnitId)); */
-	rio_dprintk (RIO_DEBUG_ROUTE, "RIOCheck : UnitID = %d\n", UnitId);
+	rio_dprintk(RIO_DEBUG_ROUTE, "RIOCheck : UnitID = %d\n", UnitId);
 
-	if ( UnitId == HOST_ID ) {
+	if (UnitId == HOST_ID) {
 		/* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d is NOT isolated - it IS the host!\n", UnitId)); */
 		return 1;
 	}
 
 	UnitId--;
 
-	if ( UnitId >= MAX_RUP ) {
+	if (UnitId >= MAX_RUP) {
 		/* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d - ignored.\n", UnitId)); */
 		return 0;
 	}
 
-	for ( link=0; link<LINKS_PER_UNIT; link++ ) {
-		if ( HostP->Mapping[UnitId].Topology[link].Unit==HOST_ID ) {
+	for (link = 0; link < LINKS_PER_UNIT; link++) {
+		if (HostP->Mapping[UnitId].Topology[link].Unit == HOST_ID) {
 			/* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d is connected directly to host via link (%c).\n", 
-						UnitId, 'A'+link)); */
+			   UnitId, 'A'+link)); */
 			return 1;
 		}
 	}
 
-	if ( HostP->Mapping[UnitId].Flags & BEEN_HERE ) {
+	if (HostP->Mapping[UnitId].Flags & BEEN_HERE) {
 		/* rio_dprint(RIO_DEBUG_ROUTE, ("Been to Unit %d before - ignoring\n", UnitId)); */
 		return 0;
 	}
 
 	HostP->Mapping[UnitId].Flags |= BEEN_HERE;
 
-	for ( link=0; link < LINKS_PER_UNIT; link++ ) {
+	for (link = 0; link < LINKS_PER_UNIT; link++) {
 		/* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d check link (%c)\n", UnitId,'A'+link)); */
-		if ( RIOCheck( HostP, HostP->Mapping[UnitId].Topology[link].Unit ) ) {
+		if (RIOCheck(HostP, HostP->Mapping[UnitId].Topology[link].Unit)) {
 			/* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d is connected to something that knows the host via link (%c)\n", UnitId,link+'A')); */
 			HostP->Mapping[UnitId].Flags &= ~BEEN_HERE;
 			return 1;
@@ -841,7 +730,7 @@
 	HostP->Mapping[UnitId].Flags &= ~BEEN_HERE;
 
 	/* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d DOESNT KNOW THE HOST!\n", UnitId)); */
-	
+
 	return 0;
 }
 
@@ -849,61 +738,57 @@
 ** Returns the type of unit (host, 16/8 port RTA)
 */
 
-uint
-GetUnitType(Uniq)
+uint GetUnitType(Uniq)
 uint Uniq;
 {
-	switch ( (Uniq >> 28) & 0xf)
-	{
-		case RIO_AT:
-		case RIO_MCA:
-		case RIO_EISA:
-		case RIO_PCI:
-			rio_dprintk (RIO_DEBUG_ROUTE, "Unit type: Host\n");
-			return(TYPE_HOST);
-		case RIO_RTA_16:
-			rio_dprintk (RIO_DEBUG_ROUTE, "Unit type: 16 port RTA\n");
-			return(TYPE_RTA16);
-		case RIO_RTA:
-			rio_dprintk (RIO_DEBUG_ROUTE, "Unit type: 8 port RTA\n");
-			return(TYPE_RTA8);
-		default :
-			rio_dprintk (RIO_DEBUG_ROUTE, "Unit type: Unrecognised\n");
-			return(99);
+	switch ((Uniq >> 28) & 0xf) {
+	case RIO_AT:
+	case RIO_MCA:
+	case RIO_EISA:
+	case RIO_PCI:
+		rio_dprintk(RIO_DEBUG_ROUTE, "Unit type: Host\n");
+		return (TYPE_HOST);
+	case RIO_RTA_16:
+		rio_dprintk(RIO_DEBUG_ROUTE, "Unit type: 16 port RTA\n");
+		return (TYPE_RTA16);
+	case RIO_RTA:
+		rio_dprintk(RIO_DEBUG_ROUTE, "Unit type: 8 port RTA\n");
+		return (TYPE_RTA8);
+	default:
+		rio_dprintk(RIO_DEBUG_ROUTE, "Unit type: Unrecognised\n");
+		return (99);
 	}
 }
 
-int
-RIOSetChange(p)
-struct rio_info *	p;
+int RIOSetChange(p)
+struct rio_info *p;
 {
-	if ( p->RIOQuickCheck != NOT_CHANGED )
-		return(0);
+	if (p->RIOQuickCheck != NOT_CHANGED)
+		return (0);
 	p->RIOQuickCheck = CHANGED;
-	if ( p->RIOSignalProcess ) {
-		rio_dprintk (RIO_DEBUG_ROUTE, "Send SIG-HUP");
+	if (p->RIOSignalProcess) {
+		rio_dprintk(RIO_DEBUG_ROUTE, "Send SIG-HUP");
 		/*
-		psignal( RIOSignalProcess, SIGHUP );
-		*/
+		   psignal( RIOSignalProcess, SIGHUP );
+		 */
 	}
-	return(0);
+	return (0);
 }
 
-static void
-RIOConCon(p, HostP, FromId, FromLink, ToId, ToLink, Change)
-struct rio_info *	p;
+static void RIOConCon(p, HostP, FromId, FromLink, ToId, ToLink, Change)
+struct rio_info *p;
 struct Host *HostP;
 uint FromId;
 uint FromLink;
 uint ToId;
 uint ToLink;
-int Change; 
+int Change;
 {
-    char *FromName;
-    char *FromType;
-    char *ToName;
-    char *ToType;
-    unsigned int tp;
+	char *FromName;
+	char *FromType;
+	char *ToName;
+	char *ToType;
+	unsigned int tp;
 
 /*
 ** 15.10.1998 ARG - ESIL 0759
@@ -932,38 +817,32 @@
 ** rio_info struct - RIORtaDisCons (RIO RTA connections) keeps track of RTA
 ** connections and disconnections. 
 */
-    if (Change == CONNECT) {
-		if (p->RIORtaDisCons) p->RIORtaDisCons--;
-	 }
-	 else {
+	if (Change == CONNECT) {
+		if (p->RIORtaDisCons)
+			p->RIORtaDisCons--;
+	} else {
 		p->RIORtaDisCons++;
-	 }
+	}
 
-    if ( p->RIOPrintDisabled == DONT_PRINT )
+	if (p->RIOPrintDisabled == DONT_PRINT)
 		return;
 
-    if ( FromId > ToId ) {
+	if (FromId > ToId) {
 		tp = FromId;
 		FromId = ToId;
 		ToId = tp;
 		tp = FromLink;
 		FromLink = ToLink;
 		ToLink = tp;
-    }
+	}
 
-    FromName = FromId ? HostP->Mapping[FromId-1].Name : HostP->Name;
-    FromType = FromId ? "RTA" : "HOST";
-    ToName = ToId ? HostP->Mapping[ToId-1].Name : HostP->Name;
-    ToType = ToId ? "RTA" : "HOST";
+	FromName = FromId ? HostP->Mapping[FromId - 1].Name : HostP->Name;
+	FromType = FromId ? "RTA" : "HOST";
+	ToName = ToId ? HostP->Mapping[ToId - 1].Name : HostP->Name;
+	ToType = ToId ? "RTA" : "HOST";
 
-    rio_dprintk (RIO_DEBUG_ROUTE, "Link between %s '%s' (%c) and %s '%s' (%c) %s.\n",
-			    FromType, FromName, 'A'+FromLink,
-			    ToType,   ToName,   'A'+ToLink,
-			    (Change==CONNECT) ? "established" : "disconnected");
-    cprintf("Link between %s '%s' (%c) and %s '%s' (%c) %s.\n",
-			    FromType, FromName, 'A'+FromLink,
-			    ToType,   ToName,   'A'+ToLink,
-			    (Change==CONNECT) ? "established" : "disconnected");
+	rio_dprintk(RIO_DEBUG_ROUTE, "Link between %s '%s' (%c) and %s '%s' (%c) %s.\n", FromType, FromName, 'A' + FromLink, ToType, ToName, 'A' + ToLink, (Change == CONNECT) ? "established" : "disconnected");
+	cprintf("Link between %s '%s' (%c) and %s '%s' (%c) %s.\n", FromType, FromName, 'A' + FromLink, ToType, ToName, 'A' + ToLink, (Change == CONNECT) ? "established" : "disconnected");
 }
 
 /*
@@ -972,24 +851,21 @@
 ** Delete and RTA entry from the saved table given to us
 ** by the configuration program.
 */
-static int
-RIORemoveFromSavedTable(struct rio_info *p, struct Map *pMap)
+static int RIORemoveFromSavedTable(struct rio_info *p, struct Map *pMap)
 {
-    int		entry;
+	int entry;
 
-    /*
-    ** We loop for all entries even after finding an entry and
-    ** zeroing it because we may have two entries to delete if
-    ** it's a 16 port RTA.
-    */
-    for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++)
-    {
-	if (p->RIOSavedTable[entry].RtaUniqueNum == pMap->RtaUniqueNum)
-	{
-	    bzero((caddr_t)&p->RIOSavedTable[entry], sizeof(struct Map));
+	/*
+	 ** We loop for all entries even after finding an entry and
+	 ** zeroing it because we may have two entries to delete if
+	 ** it's a 16 port RTA.
+	 */
+	for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
+		if (p->RIOSavedTable[entry].RtaUniqueNum == pMap->RtaUniqueNum) {
+			bzero((caddr_t) & p->RIOSavedTable[entry], sizeof(struct Map));
+		}
 	}
-    }
-    return 0;
+	return 0;
 }
 
 
@@ -999,64 +875,58 @@
 ** Scan the unit links to and return zero if the unit is completely
 ** disconnected.
 */
-static int
-RIOFreeDisconnected(struct rio_info *p, struct Host *HostP, int unit)
+static int RIOFreeDisconnected(struct rio_info *p, struct Host *HostP, int unit)
 {
-    int		link;
+	int link;
 
 
-    rio_dprintk (RIO_DEBUG_ROUTE, "RIOFreeDisconnect unit %d\n", unit);
-    /*
-    ** If the slot is tentative and does not belong to the
-    ** second half of a 16 port RTA then scan to see if
-    ** is disconnected.
-    */
-    for (link = 0; link < LINKS_PER_UNIT; link++)
-    {
-	if (HostP->Mapping[unit].Topology[link].Unit != ROUTE_DISCONNECT)
-	    break;
-    }
+	rio_dprintk(RIO_DEBUG_ROUTE, "RIOFreeDisconnect unit %d\n", unit);
+	/*
+	 ** If the slot is tentative and does not belong to the
+	 ** second half of a 16 port RTA then scan to see if
+	 ** is disconnected.
+	 */
+	for (link = 0; link < LINKS_PER_UNIT; link++) {
+		if (HostP->Mapping[unit].Topology[link].Unit != ROUTE_DISCONNECT)
+			break;
+	}
 
-    /*
-    ** If not all links are disconnected then we can forget about it.
-    */
-    if (link < LINKS_PER_UNIT)
-	    return 1;
+	/*
+	 ** If not all links are disconnected then we can forget about it.
+	 */
+	if (link < LINKS_PER_UNIT)
+		return 1;
 
 #ifdef NEED_TO_FIX_THIS
-    /* Ok so all the links are disconnected. But we may have only just
-    ** made this slot tentative and not yet received a topology update.
-    ** Lets check how long ago we made it tentative.
-    */
-    rio_dprintk (RIO_DEBUG_ROUTE, "Just about to check LBOLT on entry %d\n", unit);
-    if (drv_getparm(LBOLT, (ulong_t *) &current_time))
-        rio_dprintk (RIO_DEBUG_ROUTE, "drv_getparm(LBOLT,....) Failed.\n");
+	/* Ok so all the links are disconnected. But we may have only just
+	 ** made this slot tentative and not yet received a topology update.
+	 ** Lets check how long ago we made it tentative.
+	 */
+	rio_dprintk(RIO_DEBUG_ROUTE, "Just about to check LBOLT on entry %d\n", unit);
+	if (drv_getparm(LBOLT, (ulong_t *) & current_time))
+		rio_dprintk(RIO_DEBUG_ROUTE, "drv_getparm(LBOLT,....) Failed.\n");
 
-    elapse_time = current_time - TentTime[unit];
-    rio_dprintk (RIO_DEBUG_ROUTE, "elapse %d = current %d - tent %d (%d usec)\n",
-        elapse_time, current_time, TentTime[unit], drv_hztousec(elapse_time));
-    if (drv_hztousec(elapse_time) < WAIT_TO_FINISH)
-    {
-      rio_dprintk (RIO_DEBUG_ROUTE, "Skipping slot %d, not timed out yet %d\n",
-            unit, drv_hztousec(elapse_time));
-        return 1;
-    }
+	elapse_time = current_time - TentTime[unit];
+	rio_dprintk(RIO_DEBUG_ROUTE, "elapse %d = current %d - tent %d (%d usec)\n", elapse_time, current_time, TentTime[unit], drv_hztousec(elapse_time));
+	if (drv_hztousec(elapse_time) < WAIT_TO_FINISH) {
+		rio_dprintk(RIO_DEBUG_ROUTE, "Skipping slot %d, not timed out yet %d\n", unit, drv_hztousec(elapse_time));
+		return 1;
+	}
 #endif
 
-    /*
-    ** We have found an usable slot.
-    ** If it is half of a 16 port RTA then delete the other half.
-    */
-    if (HostP->Mapping[unit].ID2 != 0)
-    {
-	int nOther = (HostP->Mapping[unit].ID2) -1;
+	/*
+	 ** We have found an usable slot.
+	 ** If it is half of a 16 port RTA then delete the other half.
+	 */
+	if (HostP->Mapping[unit].ID2 != 0) {
+		int nOther = (HostP->Mapping[unit].ID2) - 1;
 
-	rio_dprintk (RIO_DEBUG_ROUTE, "RioFreedis second slot %d.\n", nOther);
-	bzero((caddr_t)&HostP->Mapping[nOther], sizeof(struct Map));
-    }
-    RIORemoveFromSavedTable(p, &HostP->Mapping[unit]);
+		rio_dprintk(RIO_DEBUG_ROUTE, "RioFreedis second slot %d.\n", nOther);
+		bzero((caddr_t) & HostP->Mapping[nOther], sizeof(struct Map));
+	}
+	RIORemoveFromSavedTable(p, &HostP->Mapping[unit]);
 
-    return 0;
+	return 0;
 }
 
 
@@ -1066,150 +936,134 @@
 ** This function scans the given host table for either one
 ** or two free unit ID's.
 */
-int
-RIOFindFreeID(struct rio_info *p, struct Host *HostP, uint *pID1, uint *pID2)
+int RIOFindFreeID(struct rio_info *p, struct Host *HostP, uint * pID1, uint * pID2)
 {
-    int unit,tempID;
+	int unit, tempID;
 
-    /*
-    ** Initialise the ID's to MAX_RUP.
-    ** We do this to make the loop for setting the ID's as simple as
-    ** possible.
-    */
-    *pID1 = MAX_RUP;
-    if (pID2 != NULL)
-	*pID2 = MAX_RUP;
-
-    /*
-    ** Scan all entries of the host mapping table for free slots.
-    ** We scan for free slots first and then if that is not successful
-    ** we start all over again looking for tentative slots we can re-use.
-    */
-    for (unit = 0; unit < MAX_RUP; unit++)
-    {
-	rio_dprintk (RIO_DEBUG_ROUTE, "Scanning unit %d\n",unit);
 	/*
-	** If the flags are zero then the slot is empty.
-	*/
-	if (HostP->Mapping[unit].Flags == 0)
-	{
-	    rio_dprintk (RIO_DEBUG_ROUTE, "      This slot is empty.\n");
-	    /*
-	    ** If we haven't allocated the first ID then do it now.
-	    */
-	    if (*pID1 == MAX_RUP)
-	    {
-		rio_dprintk (RIO_DEBUG_ROUTE, "Make tentative entry for first unit %d\n", unit);
-		*pID1 = unit;
+	 ** Initialise the ID's to MAX_RUP.
+	 ** We do this to make the loop for setting the ID's as simple as
+	 ** possible.
+	 */
+	*pID1 = MAX_RUP;
+	if (pID2 != NULL)
+		*pID2 = MAX_RUP;
 
+	/*
+	 ** Scan all entries of the host mapping table for free slots.
+	 ** We scan for free slots first and then if that is not successful
+	 ** we start all over again looking for tentative slots we can re-use.
+	 */
+	for (unit = 0; unit < MAX_RUP; unit++) {
+		rio_dprintk(RIO_DEBUG_ROUTE, "Scanning unit %d\n", unit);
 		/*
-		** If the second ID is not needed then we can return
-		** now.
-		*/
-		if (pID2 == NULL)
-		    return 0;
-	    }
-	    else
-	    {
-		/*
-		** Allocate the second slot and return.
-		*/
-		rio_dprintk (RIO_DEBUG_ROUTE, "Make tentative entry for second unit %d\n", unit);
-		*pID2 = unit;
-		return 0;
-	    }
-	}
-    }
+		 ** If the flags are zero then the slot is empty.
+		 */
+		if (HostP->Mapping[unit].Flags == 0) {
+			rio_dprintk(RIO_DEBUG_ROUTE, "      This slot is empty.\n");
+			/*
+			 ** If we haven't allocated the first ID then do it now.
+			 */
+			if (*pID1 == MAX_RUP) {
+				rio_dprintk(RIO_DEBUG_ROUTE, "Make tentative entry for first unit %d\n", unit);
+				*pID1 = unit;
 
-    /*
-    ** If we manage to come out of the free slot loop then we
-    ** need to start all over again looking for tentative slots
-    ** that we can re-use.
-    */
-    rio_dprintk (RIO_DEBUG_ROUTE, "Starting to scan for tentative slots\n");
-    for (unit = 0; unit < MAX_RUP; unit++)
-    {
-	if (((HostP->Mapping[unit].Flags & SLOT_TENTATIVE) ||
-	                       (HostP->Mapping[unit].Flags == 0))  && ! 
-	   (HostP->Mapping[unit].Flags & RTA16_SECOND_SLOT ))
-	{
-	    rio_dprintk (RIO_DEBUG_ROUTE, "    Slot %d looks promising.\n",unit);
-
-	    if(unit == *pID1)
-	    {
-	    	rio_dprintk (RIO_DEBUG_ROUTE, "    No it isn't, its the 1st half\n");
-		continue;
-	    }
-
-	    /*
-	    ** Slot is Tentative or Empty, but not a tentative second 
-	    ** slot of a 16 porter.
-	    ** Attempt to free up this slot (and its parnter if
-	    ** it is a 16 port slot. The second slot will become
-	    ** empty after a call to RIOFreeDisconnected so thats why
-	    ** we look for empty slots above  as well).
-	    */
-	    if (HostP->Mapping[unit].Flags != 0) 
-	    	if (RIOFreeDisconnected(p, HostP, unit) != 0)
-			    continue;
-	    /*
-	    ** If we haven't allocated the first ID then do it now.
-	    */
-	    if (*pID1 == MAX_RUP)
-	    {
-		rio_dprintk (RIO_DEBUG_ROUTE, "Grab tentative entry for first unit %d\n", unit);
-		*pID1 = unit;
-
-		/*
-		** Clear out this slot now that we intend to use it.
-		*/
-		bzero(&HostP->Mapping[unit], sizeof(struct Map));
-
-		/*
-		** If the second ID is not needed then we can return
-		** now.
-		*/
-		if (pID2 == NULL)
-		    return 0;
-	    }
-	    else
-	    {
-		/*
-		** Allocate the second slot and return.
-		*/
-		rio_dprintk (RIO_DEBUG_ROUTE, "Grab tentative/empty  entry for second unit %d\n",
-		      unit);
-		*pID2 = unit;
-
-		/*
-		** Clear out this slot now that we intend to use it.
-		*/
-		bzero(&HostP->Mapping[unit], sizeof(struct Map));
-
-		/* At this point under the right(wrong?) conditions
-		** we may have a first unit ID being higher than the
-		** second unit ID. This is a bad idea if we are about
-		** to fill the slots with a 16 port RTA.
-		** Better check and swap them over.
-		*/
-
-		if (*pID1 > *pID2)
-		{
-			rio_dprintk (RIO_DEBUG_ROUTE, "Swapping IDS %d %d\n", *pID1, *pID2);
-			tempID = *pID1;
-			*pID1 = *pID2;
-			*pID2 = tempID;
+				/*
+				 ** If the second ID is not needed then we can return
+				 ** now.
+				 */
+				if (pID2 == NULL)
+					return 0;
+			} else {
+				/*
+				 ** Allocate the second slot and return.
+				 */
+				rio_dprintk(RIO_DEBUG_ROUTE, "Make tentative entry for second unit %d\n", unit);
+				*pID2 = unit;
+				return 0;
+			}
 		}
-		return 0;
-	    }
 	}
-    }
 
-    /*
-    ** If we manage to get to the end of the second loop then we
-    ** can give up and return a failure.
-    */
-    return 1;
+	/*
+	 ** If we manage to come out of the free slot loop then we
+	 ** need to start all over again looking for tentative slots
+	 ** that we can re-use.
+	 */
+	rio_dprintk(RIO_DEBUG_ROUTE, "Starting to scan for tentative slots\n");
+	for (unit = 0; unit < MAX_RUP; unit++) {
+		if (((HostP->Mapping[unit].Flags & SLOT_TENTATIVE) || (HostP->Mapping[unit].Flags == 0)) && !(HostP->Mapping[unit].Flags & RTA16_SECOND_SLOT)) {
+			rio_dprintk(RIO_DEBUG_ROUTE, "    Slot %d looks promising.\n", unit);
+
+			if (unit == *pID1) {
+				rio_dprintk(RIO_DEBUG_ROUTE, "    No it isn't, its the 1st half\n");
+				continue;
+			}
+
+			/*
+			 ** Slot is Tentative or Empty, but not a tentative second
+			 ** slot of a 16 porter.
+			 ** Attempt to free up this slot (and its parnter if
+			 ** it is a 16 port slot. The second slot will become
+			 ** empty after a call to RIOFreeDisconnected so thats why
+			 ** we look for empty slots above  as well).
+			 */
+			if (HostP->Mapping[unit].Flags != 0)
+				if (RIOFreeDisconnected(p, HostP, unit) != 0)
+					continue;
+			/*
+			 ** If we haven't allocated the first ID then do it now.
+			 */
+			if (*pID1 == MAX_RUP) {
+				rio_dprintk(RIO_DEBUG_ROUTE, "Grab tentative entry for first unit %d\n", unit);
+				*pID1 = unit;
+
+				/*
+				 ** Clear out this slot now that we intend to use it.
+				 */
+				bzero(&HostP->Mapping[unit], sizeof(struct Map));
+
+				/*
+				 ** If the second ID is not needed then we can return
+				 ** now.
+				 */
+				if (pID2 == NULL)
+					return 0;
+			} else {
+				/*
+				 ** Allocate the second slot and return.
+				 */
+				rio_dprintk(RIO_DEBUG_ROUTE, "Grab tentative/empty  entry for second unit %d\n", unit);
+				*pID2 = unit;
+
+				/*
+				 ** Clear out this slot now that we intend to use it.
+				 */
+				bzero(&HostP->Mapping[unit], sizeof(struct Map));
+
+				/* At this point under the right(wrong?) conditions
+				 ** we may have a first unit ID being higher than the
+				 ** second unit ID. This is a bad idea if we are about
+				 ** to fill the slots with a 16 port RTA.
+				 ** Better check and swap them over.
+				 */
+
+				if (*pID1 > *pID2) {
+					rio_dprintk(RIO_DEBUG_ROUTE, "Swapping IDS %d %d\n", *pID1, *pID2);
+					tempID = *pID1;
+					*pID1 = *pID2;
+					*pID2 = tempID;
+				}
+				return 0;
+			}
+		}
+	}
+
+	/*
+	 ** If we manage to get to the end of the second loop then we
+	 ** can give up and return a failure.
+	 */
+	return 1;
 }
 
 
diff --git a/drivers/char/rio/riospace.h b/drivers/char/rio/riospace.h
index 32b09b0..534f1f5 100644
--- a/drivers/char/rio/riospace.h
+++ b/drivers/char/rio/riospace.h
@@ -47,9 +47,8 @@
 ** In particular, it won't be able to see changes to RIO_SLOTS
 */
 
-struct Conf
-{
-	char         Locator[24];
+struct Conf {
+	char Locator[24];
 	unsigned int StartupTime;
 	unsigned int SlowCook;
 	unsigned int IntrPollTime;
@@ -59,8 +58,8 @@
 	unsigned int HostLoadBase;
 	unsigned int XpHz;
 	unsigned int XpCps;
-	char         *XpOn;
-	char         *XpOff;
+	char *XpOn;
+	char *XpOff;
 	unsigned int MaxXpCps;
 	unsigned int MinXpCps;
 	unsigned int SpinCmds;
@@ -74,7 +73,7 @@
 
 /*
 **	Board types - these MUST correspond to product codes!
-*/ 
+*/
 #define	RIO_EMPTY	0x0
 #define	RIO_EISA	0x3
 #define	RIO_RTA_16	0x9
@@ -86,18 +85,16 @@
 /*
 **	Board data structure. This is used for configuration info
 */
-struct	Brd
-{
-    unsigned char Type;	/* RIO_EISA, RIO_MCA, RIO_AT, RIO_EMPTY... */
-    unsigned char Ivec;	/* POLLED or ivec number */
-    unsigned char Mode;	/* Control stuff, see below */
+struct Brd {
+	unsigned char Type;	/* RIO_EISA, RIO_MCA, RIO_AT, RIO_EMPTY... */
+	unsigned char Ivec;	/* POLLED or ivec number */
+	unsigned char Mode;	/* Control stuff, see below */
 };
 
-struct	Board
-{
-    char       Locator[RIO_LOCATOR_LEN];
-    int        NumSlots;
-    struct Brd Boards[MAX_RIO_BOARDS];
+struct Board {
+	char Locator[RIO_LOCATOR_LEN];
+	int NumSlots;
+	struct Brd Boards[MAX_RIO_BOARDS];
 };
 
 #define	BOOT_FROM_LINK		0x00
@@ -158,4 +155,4 @@
 
 #define	DBG_ALWAYS	0x80000000
 
-#endif /* __rio_riospace_h__ */
+#endif				/* __rio_riospace_h__ */
diff --git a/drivers/char/rio/riotable.c b/drivers/char/rio/riotable.c
index e45bc27..42c3dffc 100644
--- a/drivers/char/rio/riotable.c
+++ b/drivers/char/rio/riotable.c
@@ -91,9 +91,8 @@
 ** A configuration table has been loaded. It is now up to us
 ** to sort it out and use the information contained therein.
 */
-int
-RIONewTable(p)
-struct rio_info *	p;
+int RIONewTable(p)
+struct rio_info *p;
 {
 	int Host, Host1, Host2, NameIsUnique, Entry, SubEnt;
 	struct Map *MapP;
@@ -103,26 +102,26 @@
 	char *cptr;
 
 	/*
-	** We have been sent a new table to install. We need to break
-	** it down into little bits and spread it around a bit to see
-	** what we have got.
-	*/
+	 ** We have been sent a new table to install. We need to break
+	 ** it down into little bits and spread it around a bit to see
+	 ** what we have got.
+	 */
 	/*
-	** Things to check:
-	** (things marked 'xx' aren't checked any more!)
-	** (1)	That there are no booted Hosts/RTAs out there.
-	** (2)	That the names are properly formed
-	** (3)	That blank entries really are.
-	** xx (4)	That hosts mentioned in the table actually exist. xx
-	** (5)	That the IDs are unique (per host).
-	** (6)	That host IDs are zero
-	** (7)	That port numbers are valid
-	** (8)	That port numbers aren't duplicated
-	** (9)	That names aren't duplicated
-	** xx (10) That hosts that actually exist are mentioned in the table. xx
-	*/
-	rio_dprintk (RIO_DEBUG_TABLE, "RIONewTable: entering(1)\n"); 
-	if ( p->RIOSystemUp ) {		/* (1) */
+	 ** Things to check:
+	 ** (things marked 'xx' aren't checked any more!)
+	 ** (1) That there are no booted Hosts/RTAs out there.
+	 ** (2) That the names are properly formed
+	 ** (3) That blank entries really are.
+	 ** xx (4)      That hosts mentioned in the table actually exist. xx
+	 ** (5) That the IDs are unique (per host).
+	 ** (6) That host IDs are zero
+	 ** (7) That port numbers are valid
+	 ** (8) That port numbers aren't duplicated
+	 ** (9) That names aren't duplicated
+	 ** xx (10) That hosts that actually exist are mentioned in the table. xx
+	 */
+	rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(1)\n");
+	if (p->RIOSystemUp) {	/* (1) */
 		p->RIOError.Error = HOST_HAS_ALREADY_BEEN_BOOTED;
 		return -EBUSY;
 	}
@@ -131,19 +130,19 @@
 	p->RIOError.Entry = -1;
 	p->RIOError.Other = -1;
 
-	for ( Entry=0; Entry<TOTAL_MAP_ENTRIES; Entry++ ) {
+	for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
 		MapP = &p->RIOConnectTable[Entry];
 		if ((MapP->Flags & RTA16_SECOND_SLOT) == 0) {
-			rio_dprintk (RIO_DEBUG_TABLE, "RIONewTable: entering(2)\n");
-			cptr = MapP->Name;		/* (2) */
-			cptr[MAX_NAME_LEN-1]='\0';
-			if ( cptr[0]=='\0' ) {
-				bcopy(MapP->RtaUniqueNum?"RTA	NN":"HOST NN",MapP->Name,8);
-				MapP->Name[5] = '0'+Entry/10;
-				MapP->Name[6] = '0'+Entry%10;
+			rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(2)\n");
+			cptr = MapP->Name;	/* (2) */
+			cptr[MAX_NAME_LEN - 1] = '\0';
+			if (cptr[0] == '\0') {
+				bcopy(MapP->RtaUniqueNum ? "RTA	NN" : "HOST NN", MapP->Name, 8);
+				MapP->Name[5] = '0' + Entry / 10;
+				MapP->Name[6] = '0' + Entry % 10;
 			}
-			while ( *cptr ) {
-				if ( *cptr<' ' || *cptr>'~' ) {
+			while (*cptr) {
+				if (*cptr < ' ' || *cptr > '~') {
 					p->RIOError.Error = BAD_CHARACTER_IN_NAME;
 					p->RIOError.Entry = Entry;
 					return -ENXIO;
@@ -153,133 +152,119 @@
 		}
 
 		/*
-		** If the entry saved was a tentative entry then just forget
-		** about it.
-		*/
-		if ( MapP->Flags & SLOT_TENTATIVE ) {
+		 ** If the entry saved was a tentative entry then just forget
+		 ** about it.
+		 */
+		if (MapP->Flags & SLOT_TENTATIVE) {
 			MapP->HostUniqueNum = 0;
 			MapP->RtaUniqueNum = 0;
 			continue;
 		}
 
-		rio_dprintk (RIO_DEBUG_TABLE, "RIONewTable: entering(3)\n");
-		if ( !MapP->RtaUniqueNum && !MapP->HostUniqueNum ) { /* (3) */
-			if ( MapP->ID || MapP->SysPort || MapP->Flags ) {
-				rio_dprintk (RIO_DEBUG_TABLE, "%s pretending to be empty but isn't\n",MapP->Name);
+		rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(3)\n");
+		if (!MapP->RtaUniqueNum && !MapP->HostUniqueNum) {	/* (3) */
+			if (MapP->ID || MapP->SysPort || MapP->Flags) {
+				rio_dprintk(RIO_DEBUG_TABLE, "%s pretending to be empty but isn't\n", MapP->Name);
 				p->RIOError.Error = TABLE_ENTRY_ISNT_PROPERLY_NULL;
 				p->RIOError.Entry = Entry;
 				return -ENXIO;
 			}
-			rio_dprintk (RIO_DEBUG_TABLE, "!RIO: Daemon: test (3) passes\n");
+			rio_dprintk(RIO_DEBUG_TABLE, "!RIO: Daemon: test (3) passes\n");
 			continue;
 		}
 
-		rio_dprintk (RIO_DEBUG_TABLE, "RIONewTable: entering(4)\n");
-		for ( Host=0; Host<p->RIONumHosts; Host++ ) { /* (4) */
-			if ( p->RIOHosts[Host].UniqueNum==MapP->HostUniqueNum ) {
+		rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(4)\n");
+		for (Host = 0; Host < p->RIONumHosts; Host++) {	/* (4) */
+			if (p->RIOHosts[Host].UniqueNum == MapP->HostUniqueNum) {
 				HostP = &p->RIOHosts[Host];
 				/*
-				** having done the lookup, we don't really want to do
-				** it again, so hang the host number in a safe place
-				*/
+				 ** having done the lookup, we don't really want to do
+				 ** it again, so hang the host number in a safe place
+				 */
 				MapP->Topology[0].Unit = Host;
 				break;
 			}
 		}
 
-		if ( Host >= p->RIONumHosts ) {
-			rio_dprintk (RIO_DEBUG_TABLE, "RTA %s has unknown host unique number 0x%x\n",
-									MapP->Name, MapP->HostUniqueNum);
+		if (Host >= p->RIONumHosts) {
+			rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has unknown host unique number 0x%x\n", MapP->Name, MapP->HostUniqueNum);
 			MapP->HostUniqueNum = 0;
-			/* MapP->RtaUniqueNum	= 0; */
-			/* MapP->ID			= 0; */
-			/* MapP->Flags		 = 0; */
-			/* MapP->SysPort		 = 0; */
-			/* MapP->Name[0]		 = 0; */
+			/* MapP->RtaUniqueNum   = 0; */
+			/* MapP->ID                     = 0; */
+			/* MapP->Flags           = 0; */
+			/* MapP->SysPort                 = 0; */
+			/* MapP->Name[0]                 = 0; */
 			continue;
 		}
 
-		rio_dprintk (RIO_DEBUG_TABLE, "RIONewTable: entering(5)\n"); 
-		if ( MapP->RtaUniqueNum ) { /* (5) */
-			if ( !MapP->ID ) {
-				rio_dprintk (RIO_DEBUG_TABLE, "RIO: RTA %s has been allocated an ID of zero!\n",
-							MapP->Name);
-				p->RIOError.Error		 = ZERO_RTA_ID;
+		rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(5)\n");
+		if (MapP->RtaUniqueNum) {	/* (5) */
+			if (!MapP->ID) {
+				rio_dprintk(RIO_DEBUG_TABLE, "RIO: RTA %s has been allocated an ID of zero!\n", MapP->Name);
+				p->RIOError.Error = ZERO_RTA_ID;
 				p->RIOError.Entry = Entry;
 				return -ENXIO;
 			}
-			if ( MapP->ID > MAX_RUP ) {
-				rio_dprintk (RIO_DEBUG_TABLE, "RIO: RTA %s has been allocated an invalid ID %d\n",
-							MapP->Name, MapP->ID);
+			if (MapP->ID > MAX_RUP) {
+				rio_dprintk(RIO_DEBUG_TABLE, "RIO: RTA %s has been allocated an invalid ID %d\n", MapP->Name, MapP->ID);
 				p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
 				p->RIOError.Entry = Entry;
 				return -ENXIO;
 			}
-			for ( SubEnt=0; SubEnt<Entry; SubEnt++ ) {
-				if ( MapP->HostUniqueNum == 
-						p->RIOConnectTable[SubEnt].HostUniqueNum && 
-						MapP->ID == p->RIOConnectTable[SubEnt].ID ) {
-					rio_dprintk (RIO_DEBUG_TABLE, "Dupl. ID number allocated to RTA %s and RTA %s\n",
-							MapP->Name, p->RIOConnectTable[SubEnt].Name);
+			for (SubEnt = 0; SubEnt < Entry; SubEnt++) {
+				if (MapP->HostUniqueNum == p->RIOConnectTable[SubEnt].HostUniqueNum && MapP->ID == p->RIOConnectTable[SubEnt].ID) {
+					rio_dprintk(RIO_DEBUG_TABLE, "Dupl. ID number allocated to RTA %s and RTA %s\n", MapP->Name, p->RIOConnectTable[SubEnt].Name);
 					p->RIOError.Error = DUPLICATED_RTA_ID;
 					p->RIOError.Entry = Entry;
 					p->RIOError.Other = SubEnt;
 					return -ENXIO;
 				}
 				/*
-				** If the RtaUniqueNum is the same, it may be looking at both
-				** entries for a 16 port RTA, so check the ids
-				*/
-				if ((MapP->RtaUniqueNum == 
-						p->RIOConnectTable[SubEnt].RtaUniqueNum)
-				 		&& (MapP->ID2 != p->RIOConnectTable[SubEnt].ID)) {
-					rio_dprintk (RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n",MapP->Name);
-					rio_dprintk (RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n",
-										p->RIOConnectTable[SubEnt].Name);
+				 ** If the RtaUniqueNum is the same, it may be looking at both
+				 ** entries for a 16 port RTA, so check the ids
+				 */
+				if ((MapP->RtaUniqueNum == p->RIOConnectTable[SubEnt].RtaUniqueNum)
+				    && (MapP->ID2 != p->RIOConnectTable[SubEnt].ID)) {
+					rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n", MapP->Name);
+					rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n", p->RIOConnectTable[SubEnt].Name);
 					p->RIOError.Error = DUPLICATE_UNIQUE_NUMBER;
 					p->RIOError.Entry = Entry;
 					p->RIOError.Other = SubEnt;
 					return -ENXIO;
 				}
 			}
-			rio_dprintk (RIO_DEBUG_TABLE, "RIONewTable: entering(7a)\n"); 
+			rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(7a)\n");
 			/* (7a) */
-			if ((MapP->SysPort != NO_PORT)&&(MapP->SysPort % PORTS_PER_RTA)) {
-				rio_dprintk (RIO_DEBUG_TABLE, "TTY Port number %d-RTA %s is not a multiple of %d!\n",
-					(int)MapP->SysPort,MapP->Name, PORTS_PER_RTA);
+			if ((MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA)) {
+				rio_dprintk(RIO_DEBUG_TABLE, "TTY Port number %d-RTA %s is not a multiple of %d!\n", (int) MapP->SysPort, MapP->Name, PORTS_PER_RTA);
 				p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
 				p->RIOError.Entry = Entry;
 				return -ENXIO;
 			}
-			rio_dprintk (RIO_DEBUG_TABLE, "RIONewTable: entering(7b)\n"); 
+			rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(7b)\n");
 			/* (7b) */
-			if ((MapP->SysPort != NO_PORT)&&(MapP->SysPort >= RIO_PORTS)) {
-				rio_dprintk (RIO_DEBUG_TABLE, "TTY Port number %d for RTA %s is too big\n",
-							(int)MapP->SysPort, MapP->Name);
+			if ((MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS)) {
+				rio_dprintk(RIO_DEBUG_TABLE, "TTY Port number %d for RTA %s is too big\n", (int) MapP->SysPort, MapP->Name);
 				p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
 				p->RIOError.Entry = Entry;
 				return -ENXIO;
 			}
-			for ( SubEnt=0; SubEnt<Entry; SubEnt++ ) {
-				if ( p->RIOConnectTable[SubEnt].Flags & RTA16_SECOND_SLOT )
-						continue;
-				if ( p->RIOConnectTable[SubEnt].RtaUniqueNum ) {
-					rio_dprintk (RIO_DEBUG_TABLE, "RIONewTable: entering(8)\n"); 
+			for (SubEnt = 0; SubEnt < Entry; SubEnt++) {
+				if (p->RIOConnectTable[SubEnt].Flags & RTA16_SECOND_SLOT)
+					continue;
+				if (p->RIOConnectTable[SubEnt].RtaUniqueNum) {
+					rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(8)\n");
 					/* (8) */
-					if ( (MapP->SysPort != NO_PORT) && (MapP->SysPort == 
-									p->RIOConnectTable[SubEnt].SysPort) ) {
-						rio_dprintk (RIO_DEBUG_TABLE, "RTA %s:same TTY port # as RTA %s (%d)\n",
-							MapP->Name, p->RIOConnectTable[SubEnt].Name,
-							(int)MapP->SysPort);
+					if ((MapP->SysPort != NO_PORT) && (MapP->SysPort == p->RIOConnectTable[SubEnt].SysPort)) {
+						rio_dprintk(RIO_DEBUG_TABLE, "RTA %s:same TTY port # as RTA %s (%d)\n", MapP->Name, p->RIOConnectTable[SubEnt].Name, (int) MapP->SysPort);
 						p->RIOError.Error = TTY_NUMBER_IN_USE;
 						p->RIOError.Entry = Entry;
 						p->RIOError.Other = SubEnt;
 						return -ENXIO;
 					}
-					rio_dprintk (RIO_DEBUG_TABLE, "RIONewTable: entering(9)\n"); 
-					if (strcmp(MapP->Name,
-							p->RIOConnectTable[SubEnt].Name)==0 && !(MapP->Flags & RTA16_SECOND_SLOT)) { /* (9) */
-						rio_dprintk (RIO_DEBUG_TABLE, "RTA name %s used twice\n", MapP->Name);
+					rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(9)\n");
+					if (strcmp(MapP->Name, p->RIOConnectTable[SubEnt].Name) == 0 && !(MapP->Flags & RTA16_SECOND_SLOT)) {	/* (9) */
+						rio_dprintk(RIO_DEBUG_TABLE, "RTA name %s used twice\n", MapP->Name);
 						p->RIOError.Error = NAME_USED_TWICE;
 						p->RIOError.Entry = Entry;
 						p->RIOError.Other = SubEnt;
@@ -287,19 +272,16 @@
 					}
 				}
 			}
-		}
-		else { /* (6) */
-			rio_dprintk (RIO_DEBUG_TABLE, "RIONewTable: entering(6)\n"); 
-			if ( MapP->ID ) {
-				rio_dprintk (RIO_DEBUG_TABLE, "RIO:HOST %s has been allocated ID that isn't zero!\n",
-					MapP->Name);
+		} else {	/* (6) */
+			rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(6)\n");
+			if (MapP->ID) {
+				rio_dprintk(RIO_DEBUG_TABLE, "RIO:HOST %s has been allocated ID that isn't zero!\n", MapP->Name);
 				p->RIOError.Error = HOST_ID_NOT_ZERO;
 				p->RIOError.Entry = Entry;
 				return -ENXIO;
 			}
-			if ( MapP->SysPort != NO_PORT ) {
-				rio_dprintk (RIO_DEBUG_TABLE, "RIO: HOST %s has been allocated port numbers!\n",
-					MapP->Name);
+			if (MapP->SysPort != NO_PORT) {
+				rio_dprintk(RIO_DEBUG_TABLE, "RIO: HOST %s has been allocated port numbers!\n", MapP->Name);
 				p->RIOError.Error = HOST_SYSPORT_BAD;
 				p->RIOError.Entry = Entry;
 				return -ENXIO;
@@ -308,106 +290,101 @@
 	}
 
 	/*
-	** wow! if we get here then it's a goody!
-	*/
+	 ** wow! if we get here then it's a goody!
+	 */
 
 	/*
-	** Zero the (old) entries for each host...
-	*/
-	for ( Host=0; Host<RIO_HOSTS; Host++ ) {
-		for ( Entry=0; Entry<MAX_RUP; Entry++ ) {
-			bzero((caddr_t)&p->RIOHosts[Host].Mapping[Entry], 
-											sizeof(struct Map));
+	 ** Zero the (old) entries for each host...
+	 */
+	for (Host = 0; Host < RIO_HOSTS; Host++) {
+		for (Entry = 0; Entry < MAX_RUP; Entry++) {
+			bzero((caddr_t) & p->RIOHosts[Host].Mapping[Entry], sizeof(struct Map));
 		}
-		bzero((caddr_t)&p->RIOHosts[Host].Name[0],
-								sizeof(p->RIOHosts[Host].Name) );
+		bzero((caddr_t) & p->RIOHosts[Host].Name[0], sizeof(p->RIOHosts[Host].Name));
 	}
 
 	/*
-	** Copy in the new table entries
-	*/
-	for ( Entry=0; Entry< TOTAL_MAP_ENTRIES; Entry++ ) {
-		rio_dprintk (RIO_DEBUG_TABLE, "RIONewTable: Copy table for Host entry %d\n", Entry);
+	 ** Copy in the new table entries
+	 */
+	for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
+		rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: Copy table for Host entry %d\n", Entry);
 		MapP = &p->RIOConnectTable[Entry];
 
 		/*
-		** Now, if it is an empty slot ignore it!
-		*/
-		if ( MapP->HostUniqueNum==0 )
+		 ** Now, if it is an empty slot ignore it!
+		 */
+		if (MapP->HostUniqueNum == 0)
 			continue;
 
 		/*
-		** we saved the host number earlier, so grab it back
-		*/
+		 ** we saved the host number earlier, so grab it back
+		 */
 		HostP = &p->RIOHosts[MapP->Topology[0].Unit];
 
 		/*
-		** If it is a host, then we only need to fill in the name field.
-		*/
-		if ( MapP->ID==0 ) {
-			rio_dprintk (RIO_DEBUG_TABLE, "Host entry found. Name %s\n", MapP->Name);
-			bcopy(MapP->Name,HostP->Name,MAX_NAME_LEN);
+		 ** If it is a host, then we only need to fill in the name field.
+		 */
+		if (MapP->ID == 0) {
+			rio_dprintk(RIO_DEBUG_TABLE, "Host entry found. Name %s\n", MapP->Name);
+			bcopy(MapP->Name, HostP->Name, MAX_NAME_LEN);
 			continue;
 		}
 
 		/*
-		** Its an RTA entry, so fill in the host mapping entries for it
-		** and the port mapping entries. Notice that entry zero is for
-		** ID one.
-		*/
-		HostMapP = &HostP->Mapping[MapP->ID-1];
+		 ** Its an RTA entry, so fill in the host mapping entries for it
+		 ** and the port mapping entries. Notice that entry zero is for
+		 ** ID one.
+		 */
+		HostMapP = &HostP->Mapping[MapP->ID - 1];
 
 		if (MapP->Flags & SLOT_IN_USE) {
-			rio_dprintk (RIO_DEBUG_TABLE, "Rta entry found. Name %s\n", MapP->Name);
+			rio_dprintk(RIO_DEBUG_TABLE, "Rta entry found. Name %s\n", MapP->Name);
 			/*
-			** structure assign, then sort out the bits we shouldn't have done
-			*/
+			 ** structure assign, then sort out the bits we shouldn't have done
+			 */
 			*HostMapP = *MapP;
 
 			HostMapP->Flags = SLOT_IN_USE;
 			if (MapP->Flags & RTA16_SECOND_SLOT)
 				HostMapP->Flags |= RTA16_SECOND_SLOT;
 
-			RIOReMapPorts(p, HostP, HostMapP );
-		}
-		else {
-			rio_dprintk (RIO_DEBUG_TABLE, "TENTATIVE Rta entry found. Name %s\n", MapP->Name);
+			RIOReMapPorts(p, HostP, HostMapP);
+		} else {
+			rio_dprintk(RIO_DEBUG_TABLE, "TENTATIVE Rta entry found. Name %s\n", MapP->Name);
 		}
 	}
 
-	for ( Entry=0; Entry< TOTAL_MAP_ENTRIES; Entry++ ) {
+	for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
 		p->RIOSavedTable[Entry] = p->RIOConnectTable[Entry];
 	}
 
-	for ( Host=0; Host<p->RIONumHosts; Host++ ) {
-		for ( SubEnt=0; SubEnt<LINKS_PER_UNIT; SubEnt++ ) {
+	for (Host = 0; Host < p->RIONumHosts; Host++) {
+		for (SubEnt = 0; SubEnt < LINKS_PER_UNIT; SubEnt++) {
 			p->RIOHosts[Host].Topology[SubEnt].Unit = ROUTE_DISCONNECT;
 			p->RIOHosts[Host].Topology[SubEnt].Link = NO_LINK;
 		}
-		for ( Entry=0; Entry<MAX_RUP; Entry++ ) {
-			for ( SubEnt=0; SubEnt<LINKS_PER_UNIT; SubEnt++ ) {
-				p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Unit = 
-								ROUTE_DISCONNECT;
-				p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Link = 
-								NO_LINK;
+		for (Entry = 0; Entry < MAX_RUP; Entry++) {
+			for (SubEnt = 0; SubEnt < LINKS_PER_UNIT; SubEnt++) {
+				p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Unit = ROUTE_DISCONNECT;
+				p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Link = NO_LINK;
 			}
 		}
-		if ( !p->RIOHosts[Host].Name[0] ) {
-			bcopy("HOST 1",p->RIOHosts[Host].Name,7);
+		if (!p->RIOHosts[Host].Name[0]) {
+			bcopy("HOST 1", p->RIOHosts[Host].Name, 7);
 			p->RIOHosts[Host].Name[5] += Host;
 		}
 		/*
-		** Check that default name assigned is unique.
-		*/
+		 ** Check that default name assigned is unique.
+		 */
 		Host1 = Host;
 		NameIsUnique = 0;
 		while (!NameIsUnique) {
 			NameIsUnique = 1;
-			for ( Host2=0; Host2<p->RIONumHosts; Host2++ ) {
+			for (Host2 = 0; Host2 < p->RIONumHosts; Host2++) {
 				if (Host2 == Host)
 					continue;
 				if (strcmp(p->RIOHosts[Host].Name, p->RIOHosts[Host2].Name)
-									 == 0) {
+				    == 0) {
 					NameIsUnique = 0;
 					Host1++;
 					if (Host1 >= p->RIONumHosts)
@@ -417,15 +394,14 @@
 			}
 		}
 		/*
-		** Rename host if name already used.
-		*/
-		if (Host1 != Host)
-		{
-			rio_dprintk (RIO_DEBUG_TABLE, "Default name %s already used\n", p->RIOHosts[Host].Name);
-			bcopy("HOST 1",p->RIOHosts[Host].Name,7);
+		 ** Rename host if name already used.
+		 */
+		if (Host1 != Host) {
+			rio_dprintk(RIO_DEBUG_TABLE, "Default name %s already used\n", p->RIOHosts[Host].Name);
+			bcopy("HOST 1", p->RIOHosts[Host].Name, 7);
 			p->RIOHosts[Host].Name[5] += Host1;
 		}
-		rio_dprintk (RIO_DEBUG_TABLE, "Assigning default name %s\n", p->RIOHosts[Host].Name);
+		rio_dprintk(RIO_DEBUG_TABLE, "Assigning default name %s\n", p->RIOHosts[Host].Name);
 	}
 	return 0;
 }
@@ -434,9 +410,8 @@
 ** User process needs the config table - build it from first
 ** principles.
 */
-int
-RIOApel(p)
-struct rio_info *	p;
+int RIOApel(p)
+struct rio_info *p;
 {
 	int Host;
 	int link;
@@ -446,35 +421,34 @@
 	struct Host *HostP;
 	long oldspl;
 
-	disable(oldspl);		/* strange but true! */
- 
-	rio_dprintk (RIO_DEBUG_TABLE, "Generating a table to return to config.rio\n");
+	disable(oldspl);	/* strange but true! */
 
-	bzero((caddr_t)&p->RIOConnectTable[0], 
-					sizeof(struct Map) * TOTAL_MAP_ENTRIES );
+	rio_dprintk(RIO_DEBUG_TABLE, "Generating a table to return to config.rio\n");
 
-	for ( Host=0; Host<RIO_HOSTS; Host++ ) {
-		rio_dprintk (RIO_DEBUG_TABLE, "Processing host %d\n", Host);
+	bzero((caddr_t) & p->RIOConnectTable[0], sizeof(struct Map) * TOTAL_MAP_ENTRIES);
+
+	for (Host = 0; Host < RIO_HOSTS; Host++) {
+		rio_dprintk(RIO_DEBUG_TABLE, "Processing host %d\n", Host);
 		HostP = &p->RIOHosts[Host];
 		MapP = &p->RIOConnectTable[Next++];
 		MapP->HostUniqueNum = HostP->UniqueNum;
-		if ( (HostP->Flags & RUN_STATE) != RC_RUNNING )
+		if ((HostP->Flags & RUN_STATE) != RC_RUNNING)
 			continue;
 		MapP->RtaUniqueNum = 0;
 		MapP->ID = 0;
 		MapP->Flags = SLOT_IN_USE;
 		MapP->SysPort = NO_PORT;
-		for ( link=0; link<LINKS_PER_UNIT; link++ )
+		for (link = 0; link < LINKS_PER_UNIT; link++)
 			MapP->Topology[link] = HostP->Topology[link];
-		bcopy(HostP->Name,MapP->Name,MAX_NAME_LEN);
-		for ( Rup=0; Rup<MAX_RUP; Rup++ ) {
-			if ( HostP->Mapping[Rup].Flags & (SLOT_IN_USE|SLOT_TENTATIVE) ) {
+		bcopy(HostP->Name, MapP->Name, MAX_NAME_LEN);
+		for (Rup = 0; Rup < MAX_RUP; Rup++) {
+			if (HostP->Mapping[Rup].Flags & (SLOT_IN_USE | SLOT_TENTATIVE)) {
 				p->RIOConnectTable[Next] = HostP->Mapping[Rup];
-				if ( HostP->Mapping[Rup].Flags & SLOT_IN_USE)
+				if (HostP->Mapping[Rup].Flags & SLOT_IN_USE)
 					p->RIOConnectTable[Next].Flags |= SLOT_IN_USE;
-				if ( HostP->Mapping[Rup].Flags & SLOT_TENTATIVE)
+				if (HostP->Mapping[Rup].Flags & SLOT_TENTATIVE)
 					p->RIOConnectTable[Next].Flags |= SLOT_TENTATIVE;
-				if ( HostP->Mapping[Rup].Flags & RTA16_SECOND_SLOT )
+				if (HostP->Mapping[Rup].Flags & RTA16_SECOND_SLOT)
 					p->RIOConnectTable[Next].Flags |= RTA16_SECOND_SLOT;
 				Next++;
 			}
@@ -489,8 +463,7 @@
 ** if the entry is suitably inactive, then we can gob on it and remove
 ** it from the table.
 */
-int
-RIODeleteRta(p, MapP)
+int RIODeleteRta(p, MapP)
 struct rio_info *p;
 struct Map *MapP;
 {
@@ -502,110 +475,98 @@
 	int work_done = 0;
 	unsigned long lock_flags, sem_flags;
 
-	rio_dprintk (RIO_DEBUG_TABLE, "Delete entry on host %x, rta %x\n",
-								MapP->HostUniqueNum, MapP->RtaUniqueNum);
+	rio_dprintk(RIO_DEBUG_TABLE, "Delete entry on host %x, rta %x\n", MapP->HostUniqueNum, MapP->RtaUniqueNum);
 
-	for ( host=0; host < p->RIONumHosts; host++ ) {
+	for (host = 0; host < p->RIONumHosts; host++) {
 		HostP = &p->RIOHosts[host];
 
-		rio_spin_lock_irqsave( &HostP->HostLock, lock_flags );
+		rio_spin_lock_irqsave(&HostP->HostLock, lock_flags);
 
-		if ( (HostP->Flags & RUN_STATE) != RC_RUNNING ) {
+		if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
 			rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
 			continue;
 		}
 
-		for ( entry=0; entry<MAX_RUP; entry++ ) {
-			if ( MapP->RtaUniqueNum == HostP->Mapping[entry].RtaUniqueNum ) {
+		for (entry = 0; entry < MAX_RUP; entry++) {
+			if (MapP->RtaUniqueNum == HostP->Mapping[entry].RtaUniqueNum) {
 				HostMapP = &HostP->Mapping[entry];
-				rio_dprintk (RIO_DEBUG_TABLE, "Found entry offset %d on host %s\n", 
-						entry, HostP->Name);
+				rio_dprintk(RIO_DEBUG_TABLE, "Found entry offset %d on host %s\n", entry, HostP->Name);
 
 				/*
-				** Check all four links of the unit are disconnected
-				*/
-				for ( link=0; link< LINKS_PER_UNIT; link++ ) {
-					if ( HostMapP->Topology[link].Unit != ROUTE_DISCONNECT ) {
-						rio_dprintk (RIO_DEBUG_TABLE, "Entry is in use and cannot be deleted!\n");
+				 ** Check all four links of the unit are disconnected
+				 */
+				for (link = 0; link < LINKS_PER_UNIT; link++) {
+					if (HostMapP->Topology[link].Unit != ROUTE_DISCONNECT) {
+						rio_dprintk(RIO_DEBUG_TABLE, "Entry is in use and cannot be deleted!\n");
 						p->RIOError.Error = UNIT_IS_IN_USE;
-						rio_spin_unlock_irqrestore( &HostP->HostLock, lock_flags);
+						rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
 						return -EBUSY;
 					}
 				}
 				/*
-				** Slot has been allocated, BUT not booted/routed/
-				** connected/selected or anything else-ed
-				*/
+				 ** Slot has been allocated, BUT not booted/routed/
+				 ** connected/selected or anything else-ed
+				 */
 				SysPort = HostMapP->SysPort;
 
-				if ( SysPort != NO_PORT ) {
-					for (port=SysPort; port < SysPort+PORTS_PER_RTA; port++) {
+				if (SysPort != NO_PORT) {
+					for (port = SysPort; port < SysPort + PORTS_PER_RTA; port++) {
 						PortP = p->RIOPortp[port];
-						rio_dprintk (RIO_DEBUG_TABLE, "Unmap port\n");
+						rio_dprintk(RIO_DEBUG_TABLE, "Unmap port\n");
 
-						rio_spin_lock_irqsave( &PortP->portSem, sem_flags );
+						rio_spin_lock_irqsave(&PortP->portSem, sem_flags);
 
 						PortP->Mapped = 0;
 
-						if ( PortP->State & (RIO_MOPEN|RIO_LOPEN) ) {
+						if (PortP->State & (RIO_MOPEN | RIO_LOPEN)) {
 
-							rio_dprintk (RIO_DEBUG_TABLE, "Gob on port\n");
+							rio_dprintk(RIO_DEBUG_TABLE, "Gob on port\n");
 							PortP->TxBufferIn = PortP->TxBufferOut = 0;
 							/* What should I do 
-							wakeup( &PortP->TxBufferIn );
-							wakeup( &PortP->TxBufferOut);
-							*/
+							   wakeup( &PortP->TxBufferIn );
+							   wakeup( &PortP->TxBufferOut);
+							 */
 							PortP->InUse = NOT_INUSE;
 							/* What should I do 
-							wakeup( &PortP->InUse );
-							signal(PortP->TtyP->t_pgrp,SIGKILL);
-							ttyflush(PortP->TtyP,(FREAD|FWRITE));
-							*/
+							   wakeup( &PortP->InUse );
+							   signal(PortP->TtyP->t_pgrp,SIGKILL);
+							   ttyflush(PortP->TtyP,(FREAD|FWRITE));
+							 */
 							PortP->State |= RIO_CLOSING | RIO_DELETED;
 						}
 
 						/*
-						** For the second slot of a 16 port RTA, the
-						** driver needs to reset the changes made to
-						** the phb to port mappings in RIORouteRup.
-						*/
+						 ** For the second slot of a 16 port RTA, the
+						 ** driver needs to reset the changes made to
+						 ** the phb to port mappings in RIORouteRup.
+						 */
 						if (PortP->SecondBlock) {
 							ushort dest_unit = HostMapP->ID;
 							ushort dest_port = port - SysPort;
-							WORD	 *TxPktP;
-							PKT	*Pkt;
+							WORD *TxPktP;
+							PKT *Pkt;
 
-							for (TxPktP = PortP->TxStart;
-								TxPktP <= PortP->TxEnd; TxPktP++) {
+							for (TxPktP = PortP->TxStart; TxPktP <= PortP->TxEnd; TxPktP++) {
 								/*
-								** *TxPktP is the pointer to the
-								** transmit packet on the host card.
-								** This needs to be translated into
-								** a 32 bit pointer so it can be
-								** accessed from the driver.
-								*/
-								Pkt = (PKT *) RIO_PTR(HostP->Caddr,
-								 	RWORD(*TxPktP));
-								rio_dprintk (RIO_DEBUG_TABLE, 
-						"Tx packet (%x) destination: Old %x:%x New %x:%x\n",
-								 *TxPktP, Pkt->dest_unit,
-								 Pkt->dest_port, dest_unit, dest_port);
+								 ** *TxPktP is the pointer to the
+								 ** transmit packet on the host card.
+								 ** This needs to be translated into
+								 ** a 32 bit pointer so it can be
+								 ** accessed from the driver.
+								 */
+								Pkt = (PKT *) RIO_PTR(HostP->Caddr, RWORD(*TxPktP));
+								rio_dprintk(RIO_DEBUG_TABLE, "Tx packet (%x) destination: Old %x:%x New %x:%x\n", *TxPktP, Pkt->dest_unit, Pkt->dest_port, dest_unit, dest_port);
 								WWORD(Pkt->dest_unit, dest_unit);
 								WWORD(Pkt->dest_port, dest_port);
 							}
-							rio_dprintk (RIO_DEBUG_TABLE, 
-						"Port %d phb destination: Old %x:%x New %x:%x\n",
-							 port, PortP->PhbP->destination & 0xff,
-							 (PortP->PhbP->destination >> 8) & 0xff,
-							 dest_unit, dest_port);
-							WWORD(PortP->PhbP->destination,
-							 dest_unit + (dest_port << 8));
+							rio_dprintk(RIO_DEBUG_TABLE, "Port %d phb destination: Old %x:%x New %x:%x\n", port, PortP->PhbP->destination & 0xff, (PortP->PhbP->destination >> 8) & 0xff, dest_unit, dest_port);
+							WWORD(PortP->PhbP->destination, dest_unit + (dest_port << 8));
 						}
 						rio_spin_unlock_irqrestore(&PortP->portSem, sem_flags);
 					}
 				}
-				rio_dprintk (RIO_DEBUG_TABLE, "Entry nulled.\n");
-				bzero((char *)HostMapP,sizeof(struct Map));
+				rio_dprintk(RIO_DEBUG_TABLE, "Entry nulled.\n");
+				bzero((char *) HostMapP, sizeof(struct Map));
 				work_done++;
 			}
 		}
@@ -613,203 +574,178 @@
 	}
 
 	/* XXXXX lock me up */
-	for ( entry=0; entry< TOTAL_MAP_ENTRIES; entry++ ) {
-		if ( p->RIOSavedTable[entry].RtaUniqueNum == MapP->RtaUniqueNum ) {
-			bzero((char *)&p->RIOSavedTable[entry],sizeof(struct Map));
+	for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
+		if (p->RIOSavedTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) {
+			bzero((char *) &p->RIOSavedTable[entry], sizeof(struct Map));
 			work_done++;
 		}
-		if ( p->RIOConnectTable[entry].RtaUniqueNum == MapP->RtaUniqueNum ) {
-			bzero((char *)&p->RIOConnectTable[entry],sizeof(struct Map));
+		if (p->RIOConnectTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) {
+			bzero((char *) &p->RIOConnectTable[entry], sizeof(struct Map));
 			work_done++;
 		}
 	}
-	if ( work_done )
+	if (work_done)
 		return 0;
 
-	rio_dprintk (RIO_DEBUG_TABLE, "Couldn't find entry to be deleted\n");
+	rio_dprintk(RIO_DEBUG_TABLE, "Couldn't find entry to be deleted\n");
 	p->RIOError.Error = COULDNT_FIND_ENTRY;
 	return -ENXIO;
 }
 
-int RIOAssignRta( struct rio_info *p, struct Map *MapP )
+int RIOAssignRta(struct rio_info *p, struct Map *MapP)
 {
-    int host;
-    struct Map *HostMapP;
-    char *sptr;
-    int	link;
+	int host;
+	struct Map *HostMapP;
+	char *sptr;
+	int link;
 
 
-    rio_dprintk (RIO_DEBUG_TABLE, "Assign entry on host %x, rta %x, ID %d, Sysport %d\n",
-				MapP->HostUniqueNum,MapP->RtaUniqueNum,
-				MapP->ID, (int)MapP->SysPort);
+	rio_dprintk(RIO_DEBUG_TABLE, "Assign entry on host %x, rta %x, ID %d, Sysport %d\n", MapP->HostUniqueNum, MapP->RtaUniqueNum, MapP->ID, (int) MapP->SysPort);
 
-    if ((MapP->ID != (ushort)-1) &&
-	((int)MapP->ID < (int)1 || (int)MapP->ID > MAX_RUP ))
-    {
-	rio_dprintk (RIO_DEBUG_TABLE, "Bad ID in map entry!\n");
-	p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
-	return -EINVAL;
-    }
-    if (MapP->RtaUniqueNum == 0)
-    {
-	rio_dprintk (RIO_DEBUG_TABLE, "Rta Unique number zero!\n");
-	p->RIOError.Error = RTA_UNIQUE_NUMBER_ZERO;
-	return -EINVAL;
-    }
-    if ( (MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA) )
-    {
-	rio_dprintk (RIO_DEBUG_TABLE, "Port %d not multiple of %d!\n",(int)MapP->SysPort,PORTS_PER_RTA);
-	p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
-	return -EINVAL;
-    }
-    if ( (MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS) )
-    {
-	rio_dprintk (RIO_DEBUG_TABLE, "Port %d not valid!\n",(int)MapP->SysPort);
-	p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
-	return -EINVAL;
-    }
-
-    /*
-    ** Copy the name across to the map entry.
-    */
-    MapP->Name[MAX_NAME_LEN-1] = '\0';
-    sptr = MapP->Name;
-    while ( *sptr )
-    {
-    if ( *sptr<' ' || *sptr>'~' )
-    {
-	rio_dprintk (RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n");
-	p->RIOError.Error = BAD_CHARACTER_IN_NAME;
-	return -EINVAL;
-    }
-    sptr++;
-    }
-
-    for ( host=0; host < p->RIONumHosts; host++ )
-    {
-	if ( MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum )
-	{
-	    if ( (p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING )
-	    {
-		p->RIOError.Error = HOST_NOT_RUNNING;
-		return -ENXIO;
-	    }
-
-	    /*
-	    ** Now we have a host we need to allocate an ID
-	    ** if the entry does not already have one.
-	    */
-	    if (MapP->ID == (ushort)-1)
-	    {
-		int nNewID;
-
-		rio_dprintk (RIO_DEBUG_TABLE, "Attempting to get a new ID for rta \"%s\"\n",
-		      MapP->Name);
-		/*
-		** The idea here is to allow RTA's to be assigned
-		** before they actually appear on the network.
-		** This allows the addition of RTA's without having
-		** to plug them in.
-		** What we do is:
-		**  - Find a free ID and allocate it to the RTA.
-		**  - If this map entry is the second half of a
-		**    16 port entry then find the other half and
-		**    make sure the 2 cross reference each other.
-		*/
-		if (RIOFindFreeID(p, &p->RIOHosts[host], &nNewID, NULL) != 0)
-		{
-		    p->RIOError.Error = COULDNT_FIND_ENTRY;
-		    return -EBUSY;
-		}
-		MapP->ID = (ushort)nNewID + 1;
-		rio_dprintk (RIO_DEBUG_TABLE, "Allocated ID %d for this new RTA.\n", MapP->ID);
-		HostMapP = &p->RIOHosts[host].Mapping[nNewID];
-		HostMapP->RtaUniqueNum = MapP->RtaUniqueNum;
-		HostMapP->HostUniqueNum = MapP->HostUniqueNum;
-		HostMapP->ID = MapP->ID;
-		for (link = 0; link < LINKS_PER_UNIT; link++)
-		{
-		    HostMapP->Topology[link].Unit = ROUTE_DISCONNECT;
-		    HostMapP->Topology[link].Link = NO_LINK;
-		}
-		if (MapP->Flags & RTA16_SECOND_SLOT)
-		{
-		    int unit;
-
-		    for (unit = 0; unit < MAX_RUP; unit++)
-			if (p->RIOHosts[host].Mapping[unit].RtaUniqueNum ==
-			    MapP->RtaUniqueNum)
-			    break;
-		    if (unit == MAX_RUP)
-		    {
-			p->RIOError.Error = COULDNT_FIND_ENTRY;
-			return -EBUSY;
-		    }
-		    HostMapP->Flags |= RTA16_SECOND_SLOT;
-		    HostMapP->ID2 = MapP->ID2 = p->RIOHosts[host].Mapping[unit].ID;
-		    p->RIOHosts[host].Mapping[unit].ID2 = MapP->ID;
-		    rio_dprintk (RIO_DEBUG_TABLE, "Cross referenced id %d to ID %d.\n",
-			  MapP->ID,
-			  p->RIOHosts[host].Mapping[unit].ID);
-		}
-	    }
-
-	    HostMapP = &p->RIOHosts[host].Mapping[MapP->ID-1];
-
-	    if ( HostMapP->Flags & SLOT_IN_USE )
-	    {
-		rio_dprintk (RIO_DEBUG_TABLE, "Map table slot for ID %d is already in use.\n", MapP->ID);
-		p->RIOError.Error = ID_ALREADY_IN_USE;
-		return -EBUSY;
-	    }
-
-	    /*
-	    ** Assign the sys ports and the name, and mark the slot as
-	    ** being in use.
-	    */
-	    HostMapP->SysPort = MapP->SysPort;
-	    if ((MapP->Flags & RTA16_SECOND_SLOT) == 0)
-	      CCOPY( MapP->Name, HostMapP->Name, MAX_NAME_LEN );
-	    HostMapP->Flags = SLOT_IN_USE | RTA_BOOTED;
-#ifdef NEED_TO_FIX
-	    RIO_SV_BROADCAST(p->RIOHosts[host].svFlags[MapP->ID-1]);
-#endif
-	    if (MapP->Flags & RTA16_SECOND_SLOT)
-		HostMapP->Flags |= RTA16_SECOND_SLOT;
-
-	    RIOReMapPorts( p, &p->RIOHosts[host], HostMapP );
-	    /*
-	    ** Adjust 2nd block of 8 phbs
-	    */
-	    if (MapP->Flags & RTA16_SECOND_SLOT)
-		RIOFixPhbs(p, &p->RIOHosts[host], HostMapP->ID - 1);
-
-	    if ( HostMapP->SysPort != NO_PORT )
-	    {
-		if ( HostMapP->SysPort < p->RIOFirstPortsBooted )
-		    p->RIOFirstPortsBooted = HostMapP->SysPort;
-		if ( HostMapP->SysPort > p->RIOLastPortsBooted )
-		    p->RIOLastPortsBooted = HostMapP->SysPort;
-	    }
-	    if (MapP->Flags & RTA16_SECOND_SLOT)
-	        rio_dprintk (RIO_DEBUG_TABLE, "Second map of RTA %s added to configuration\n",
-		 p->RIOHosts[host].Mapping[MapP->ID2 - 1].Name);
-	    else
-	        rio_dprintk (RIO_DEBUG_TABLE, "RTA %s added to configuration\n", MapP->Name);
-	    return 0;
+	if ((MapP->ID != (ushort) - 1) && ((int) MapP->ID < (int) 1 || (int) MapP->ID > MAX_RUP)) {
+		rio_dprintk(RIO_DEBUG_TABLE, "Bad ID in map entry!\n");
+		p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
+		return -EINVAL;
 	}
-    }
-    p->RIOError.Error = UNKNOWN_HOST_NUMBER;
-    rio_dprintk (RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum);
-    return -ENXIO;
+	if (MapP->RtaUniqueNum == 0) {
+		rio_dprintk(RIO_DEBUG_TABLE, "Rta Unique number zero!\n");
+		p->RIOError.Error = RTA_UNIQUE_NUMBER_ZERO;
+		return -EINVAL;
+	}
+	if ((MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA)) {
+		rio_dprintk(RIO_DEBUG_TABLE, "Port %d not multiple of %d!\n", (int) MapP->SysPort, PORTS_PER_RTA);
+		p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
+		return -EINVAL;
+	}
+	if ((MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS)) {
+		rio_dprintk(RIO_DEBUG_TABLE, "Port %d not valid!\n", (int) MapP->SysPort);
+		p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
+		return -EINVAL;
+	}
+
+	/*
+	 ** Copy the name across to the map entry.
+	 */
+	MapP->Name[MAX_NAME_LEN - 1] = '\0';
+	sptr = MapP->Name;
+	while (*sptr) {
+		if (*sptr < ' ' || *sptr > '~') {
+			rio_dprintk(RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n");
+			p->RIOError.Error = BAD_CHARACTER_IN_NAME;
+			return -EINVAL;
+		}
+		sptr++;
+	}
+
+	for (host = 0; host < p->RIONumHosts; host++) {
+		if (MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum) {
+			if ((p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING) {
+				p->RIOError.Error = HOST_NOT_RUNNING;
+				return -ENXIO;
+			}
+
+			/*
+			 ** Now we have a host we need to allocate an ID
+			 ** if the entry does not already have one.
+			 */
+			if (MapP->ID == (ushort) - 1) {
+				int nNewID;
+
+				rio_dprintk(RIO_DEBUG_TABLE, "Attempting to get a new ID for rta \"%s\"\n", MapP->Name);
+				/*
+				 ** The idea here is to allow RTA's to be assigned
+				 ** before they actually appear on the network.
+				 ** This allows the addition of RTA's without having
+				 ** to plug them in.
+				 ** What we do is:
+				 **  - Find a free ID and allocate it to the RTA.
+				 **  - If this map entry is the second half of a
+				 **    16 port entry then find the other half and
+				 **    make sure the 2 cross reference each other.
+				 */
+				if (RIOFindFreeID(p, &p->RIOHosts[host], &nNewID, NULL) != 0) {
+					p->RIOError.Error = COULDNT_FIND_ENTRY;
+					return -EBUSY;
+				}
+				MapP->ID = (ushort) nNewID + 1;
+				rio_dprintk(RIO_DEBUG_TABLE, "Allocated ID %d for this new RTA.\n", MapP->ID);
+				HostMapP = &p->RIOHosts[host].Mapping[nNewID];
+				HostMapP->RtaUniqueNum = MapP->RtaUniqueNum;
+				HostMapP->HostUniqueNum = MapP->HostUniqueNum;
+				HostMapP->ID = MapP->ID;
+				for (link = 0; link < LINKS_PER_UNIT; link++) {
+					HostMapP->Topology[link].Unit = ROUTE_DISCONNECT;
+					HostMapP->Topology[link].Link = NO_LINK;
+				}
+				if (MapP->Flags & RTA16_SECOND_SLOT) {
+					int unit;
+
+					for (unit = 0; unit < MAX_RUP; unit++)
+						if (p->RIOHosts[host].Mapping[unit].RtaUniqueNum == MapP->RtaUniqueNum)
+							break;
+					if (unit == MAX_RUP) {
+						p->RIOError.Error = COULDNT_FIND_ENTRY;
+						return -EBUSY;
+					}
+					HostMapP->Flags |= RTA16_SECOND_SLOT;
+					HostMapP->ID2 = MapP->ID2 = p->RIOHosts[host].Mapping[unit].ID;
+					p->RIOHosts[host].Mapping[unit].ID2 = MapP->ID;
+					rio_dprintk(RIO_DEBUG_TABLE, "Cross referenced id %d to ID %d.\n", MapP->ID, p->RIOHosts[host].Mapping[unit].ID);
+				}
+			}
+
+			HostMapP = &p->RIOHosts[host].Mapping[MapP->ID - 1];
+
+			if (HostMapP->Flags & SLOT_IN_USE) {
+				rio_dprintk(RIO_DEBUG_TABLE, "Map table slot for ID %d is already in use.\n", MapP->ID);
+				p->RIOError.Error = ID_ALREADY_IN_USE;
+				return -EBUSY;
+			}
+
+			/*
+			 ** Assign the sys ports and the name, and mark the slot as
+			 ** being in use.
+			 */
+			HostMapP->SysPort = MapP->SysPort;
+			if ((MapP->Flags & RTA16_SECOND_SLOT) == 0)
+				CCOPY(MapP->Name, HostMapP->Name, MAX_NAME_LEN);
+			HostMapP->Flags = SLOT_IN_USE | RTA_BOOTED;
+#ifdef NEED_TO_FIX
+			RIO_SV_BROADCAST(p->RIOHosts[host].svFlags[MapP->ID - 1]);
+#endif
+			if (MapP->Flags & RTA16_SECOND_SLOT)
+				HostMapP->Flags |= RTA16_SECOND_SLOT;
+
+			RIOReMapPorts(p, &p->RIOHosts[host], HostMapP);
+			/*
+			 ** Adjust 2nd block of 8 phbs
+			 */
+			if (MapP->Flags & RTA16_SECOND_SLOT)
+				RIOFixPhbs(p, &p->RIOHosts[host], HostMapP->ID - 1);
+
+			if (HostMapP->SysPort != NO_PORT) {
+				if (HostMapP->SysPort < p->RIOFirstPortsBooted)
+					p->RIOFirstPortsBooted = HostMapP->SysPort;
+				if (HostMapP->SysPort > p->RIOLastPortsBooted)
+					p->RIOLastPortsBooted = HostMapP->SysPort;
+			}
+			if (MapP->Flags & RTA16_SECOND_SLOT)
+				rio_dprintk(RIO_DEBUG_TABLE, "Second map of RTA %s added to configuration\n", p->RIOHosts[host].Mapping[MapP->ID2 - 1].Name);
+			else
+				rio_dprintk(RIO_DEBUG_TABLE, "RTA %s added to configuration\n", MapP->Name);
+			return 0;
+		}
+	}
+	p->RIOError.Error = UNKNOWN_HOST_NUMBER;
+	rio_dprintk(RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum);
+	return -ENXIO;
 }
 
 
-int
-RIOReMapPorts(p, HostP, HostMapP)
-struct rio_info *	p;
+int RIOReMapPorts(p, HostP, HostMapP)
+struct rio_info *p;
 struct Host *HostP;
-struct Map *HostMapP; 
+struct Map *HostMapP;
 {
 	register struct Port *PortP;
 	uint SubEnt;
@@ -819,135 +755,127 @@
 	unsigned long flags;
 
 #ifdef CHECK
-	CheckHostP( HostP );
-	CheckHostMapP( HostMapP );
+	CheckHostP(HostP);
+	CheckHostMapP(HostMapP);
 #endif
 
-	rio_dprintk (RIO_DEBUG_TABLE, "Mapping sysport %d to id %d\n", (int)HostMapP->SysPort, HostMapP->ID);
+	rio_dprintk(RIO_DEBUG_TABLE, "Mapping sysport %d to id %d\n", (int) HostMapP->SysPort, HostMapP->ID);
 
 	/*
-	** We need to tell the UnixRups which sysport the rup corresponds to
-	*/
-	HostP->UnixRups[HostMapP->ID-1].BaseSysPort = HostMapP->SysPort;
+	 ** We need to tell the UnixRups which sysport the rup corresponds to
+	 */
+	HostP->UnixRups[HostMapP->ID - 1].BaseSysPort = HostMapP->SysPort;
 
-	if ( HostMapP->SysPort == NO_PORT )
-		return(0);
+	if (HostMapP->SysPort == NO_PORT)
+		return (0);
 
 	RtaType = GetUnitType(HostMapP->RtaUniqueNum);
-	rio_dprintk (RIO_DEBUG_TABLE, "Mapping sysport %d-%d\n",
-				(int)HostMapP->SysPort, (int)HostMapP->SysPort+PORTS_PER_RTA-1);
+	rio_dprintk(RIO_DEBUG_TABLE, "Mapping sysport %d-%d\n", (int) HostMapP->SysPort, (int) HostMapP->SysPort + PORTS_PER_RTA - 1);
 
 	/*
-	** now map each of its eight ports
-	*/
-	for ( SubEnt=0; SubEnt<PORTS_PER_RTA; SubEnt++) {
-	  rio_dprintk (RIO_DEBUG_TABLE, "subent = %d, HostMapP->SysPort = %d\n", 
-		  SubEnt, (int)HostMapP->SysPort);
-		SysPort = HostMapP->SysPort+SubEnt;		/* portnumber within system */
-					/* portnumber on host */
-		
-		HostPort = (HostMapP->ID-1)*PORTS_PER_RTA+SubEnt; 
+	 ** now map each of its eight ports
+	 */
+	for (SubEnt = 0; SubEnt < PORTS_PER_RTA; SubEnt++) {
+		rio_dprintk(RIO_DEBUG_TABLE, "subent = %d, HostMapP->SysPort = %d\n", SubEnt, (int) HostMapP->SysPort);
+		SysPort = HostMapP->SysPort + SubEnt;	/* portnumber within system */
+		/* portnumber on host */
 
-		rio_dprintk (RIO_DEBUG_TABLE, "c1 p = %p, p->rioPortp = %p\n", p, p->RIOPortp);
+		HostPort = (HostMapP->ID - 1) * PORTS_PER_RTA + SubEnt;
+
+		rio_dprintk(RIO_DEBUG_TABLE, "c1 p = %p, p->rioPortp = %p\n", p, p->RIOPortp);
 		PortP = p->RIOPortp[SysPort];
 #if 0
-		PortP->TtyP	= &p->channel[SysPort];
+		PortP->TtyP = &p->channel[SysPort];
 #endif
-		rio_dprintk (RIO_DEBUG_TABLE, "Map port\n");
+		rio_dprintk(RIO_DEBUG_TABLE, "Map port\n");
 
 		/*
-		** Point at all the real neat data structures
-		*/
+		 ** Point at all the real neat data structures
+		 */
 		rio_spin_lock_irqsave(&PortP->portSem, flags);
 		PortP->HostP = HostP;
 		PortP->Caddr = HostP->Caddr;
 
 		/*
-		** The PhbP cannot be filled in yet
-		** unless the host has been booted
-		*/
+		 ** The PhbP cannot be filled in yet
+		 ** unless the host has been booted
+		 */
 		if ((HostP->Flags & RUN_STATE) == RC_RUNNING) {
 			struct PHB *PhbP = PortP->PhbP = &HostP->PhbP[HostPort];
-			PortP->TxAdd =(WORD *)RIO_PTR(HostP->Caddr,RWORD(PhbP->tx_add));
-			PortP->TxStart =(WORD *)RIO_PTR(HostP->Caddr,RWORD(PhbP->tx_start));
-			PortP->TxEnd =(WORD *)RIO_PTR(HostP->Caddr,RWORD(PhbP->tx_end));
-			PortP->RxRemove=(WORD *)RIO_PTR(HostP->Caddr,
-									RWORD(PhbP->rx_remove));
-			PortP->RxStart =(WORD *)RIO_PTR(HostP->Caddr,RWORD(PhbP->rx_start));
-			PortP->RxEnd =(WORD *)RIO_PTR(HostP->Caddr,RWORD(PhbP->rx_end));
-		}
-		else
+			PortP->TxAdd = (WORD *) RIO_PTR(HostP->Caddr, RWORD(PhbP->tx_add));
+			PortP->TxStart = (WORD *) RIO_PTR(HostP->Caddr, RWORD(PhbP->tx_start));
+			PortP->TxEnd = (WORD *) RIO_PTR(HostP->Caddr, RWORD(PhbP->tx_end));
+			PortP->RxRemove = (WORD *) RIO_PTR(HostP->Caddr, RWORD(PhbP->rx_remove));
+			PortP->RxStart = (WORD *) RIO_PTR(HostP->Caddr, RWORD(PhbP->rx_start));
+			PortP->RxEnd = (WORD *) RIO_PTR(HostP->Caddr, RWORD(PhbP->rx_end));
+		} else
 			PortP->PhbP = NULL;
 
 		/*
-		** port related flags
-		*/
-		PortP->HostPort	= HostPort;
+		 ** port related flags
+		 */
+		PortP->HostPort = HostPort;
 		/*
-		** For each part of a 16 port RTA, RupNum is ID - 1.
-		*/
+		 ** For each part of a 16 port RTA, RupNum is ID - 1.
+		 */
 		PortP->RupNum = HostMapP->ID - 1;
 		if (HostMapP->Flags & RTA16_SECOND_SLOT) {
-			PortP->ID2			 = HostMapP->ID2 - 1;
-			PortP->SecondBlock	 = TRUE;
-		}
-		else {
-			PortP->ID2			 = 0;
-			PortP->SecondBlock	 = FALSE;
-		}
-		PortP->RtaUniqueNum	= HostMapP->RtaUniqueNum;
-
-		/*
-		** If the port was already mapped then thats all we need to do.
-		*/
-		if (PortP->Mapped) {
-			rio_spin_unlock_irqrestore( &PortP->portSem, flags);
-			continue;
-		}
-		else HostMapP->Flags &= ~RTA_NEWBOOT;
-
-		PortP->State		 = 0;
-		PortP->Config		= 0;
-		/*
-		** Check out the module type - if it is special (read only etc.)
-		** then we need to set flags in the PortP->Config.
-		** Note: For 16 port RTA, all ports are of the same type.
-		*/
-		if (RtaType == TYPE_RTA16) {
-			PortP->Config |= p->RIOModuleTypes[HostP->UnixRups
-				[HostMapP->ID-1].ModTypes].Flags[SubEnt % PORTS_PER_MODULE];
+			PortP->ID2 = HostMapP->ID2 - 1;
+			PortP->SecondBlock = TRUE;
 		} else {
-			if ( SubEnt < PORTS_PER_MODULE )
-				PortP->Config |= p->RIOModuleTypes[LONYBLE(HostP->UnixRups
-				[HostMapP->ID-1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE];
+			PortP->ID2 = 0;
+			PortP->SecondBlock = FALSE;
+		}
+		PortP->RtaUniqueNum = HostMapP->RtaUniqueNum;
+
+		/*
+		 ** If the port was already mapped then thats all we need to do.
+		 */
+		if (PortP->Mapped) {
+			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+			continue;
+		} else
+			HostMapP->Flags &= ~RTA_NEWBOOT;
+
+		PortP->State = 0;
+		PortP->Config = 0;
+		/*
+		 ** Check out the module type - if it is special (read only etc.)
+		 ** then we need to set flags in the PortP->Config.
+		 ** Note: For 16 port RTA, all ports are of the same type.
+		 */
+		if (RtaType == TYPE_RTA16) {
+			PortP->Config |= p->RIOModuleTypes[HostP->UnixRups[HostMapP->ID - 1].ModTypes].Flags[SubEnt % PORTS_PER_MODULE];
+		} else {
+			if (SubEnt < PORTS_PER_MODULE)
+				PortP->Config |= p->RIOModuleTypes[LONYBLE(HostP->UnixRups[HostMapP->ID - 1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE];
 			else
-				PortP->Config |= p->RIOModuleTypes[HINYBLE(HostP->UnixRups
-				[HostMapP->ID-1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE];
+				PortP->Config |= p->RIOModuleTypes[HINYBLE(HostP->UnixRups[HostMapP->ID - 1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE];
 		}
 
 		/*
-		** more port related flags
-		*/
-		PortP->PortState	= 0;
-		PortP->ModemLines	= 0;
-		PortP->ModemState	= 0;
-		PortP->CookMode		= COOK_WELL;
-		PortP->ParamSem		= 0;
-		PortP->FlushCmdBodge= 0;
-		PortP->WflushFlag	= 0;
-		PortP->MagicFlags	= 0;
-		PortP->Lock			= 0;
-		PortP->Store		= 0;
-		PortP->FirstOpen	= 1;
+		 ** more port related flags
+		 */
+		PortP->PortState = 0;
+		PortP->ModemLines = 0;
+		PortP->ModemState = 0;
+		PortP->CookMode = COOK_WELL;
+		PortP->ParamSem = 0;
+		PortP->FlushCmdBodge = 0;
+		PortP->WflushFlag = 0;
+		PortP->MagicFlags = 0;
+		PortP->Lock = 0;
+		PortP->Store = 0;
+		PortP->FirstOpen = 1;
 
 		/*
-		** Buffers 'n things
-		*/
-		PortP->RxDataStart	= 0;
-		PortP->Cor2Copy	 = 0;
-		PortP->Name		 = &HostMapP->Name[0];
+		 ** Buffers 'n things
+		 */
+		PortP->RxDataStart = 0;
+		PortP->Cor2Copy = 0;
+		PortP->Name = &HostMapP->Name[0];
 #ifdef STATS
-		bzero( (caddr_t)&PortP->Stat, sizeof(struct RIOStats) );
+		bzero((caddr_t) & PortP->Stat, sizeof(struct RIOStats));
 #endif
 		PortP->statsGather = 0;
 		PortP->txchars = 0;
@@ -955,90 +883,87 @@
 		PortP->opens = 0;
 		PortP->closes = 0;
 		PortP->ioctls = 0;
-		if ( PortP->TxRingBuffer )
-			bzero( PortP->TxRingBuffer, p->RIOBufferSize );
-		else if ( p->RIOBufferSize ) {
+		if (PortP->TxRingBuffer)
+			bzero(PortP->TxRingBuffer, p->RIOBufferSize);
+		else if (p->RIOBufferSize) {
 			PortP->TxRingBuffer = sysbrk(p->RIOBufferSize);
-			bzero( PortP->TxRingBuffer, p->RIOBufferSize );
+			bzero(PortP->TxRingBuffer, p->RIOBufferSize);
 		}
-		PortP->TxBufferOut	= 0;
-		PortP->TxBufferIn	 = 0;
-		PortP->Debug		= 0;
+		PortP->TxBufferOut = 0;
+		PortP->TxBufferIn = 0;
+		PortP->Debug = 0;
 		/*
-		** LastRxTgl stores the state of the rx toggle bit for this
-		** port, to be compared with the state of the next pkt received.
-		** If the same, we have received the same rx pkt from the RTA
-		** twice. Initialise to a value not equal to PHB_RX_TGL or 0.
-		*/
-		PortP->LastRxTgl	= ~(uchar)PHB_RX_TGL;
+		 ** LastRxTgl stores the state of the rx toggle bit for this
+		 ** port, to be compared with the state of the next pkt received.
+		 ** If the same, we have received the same rx pkt from the RTA
+		 ** twice. Initialise to a value not equal to PHB_RX_TGL or 0.
+		 */
+		PortP->LastRxTgl = ~(uchar) PHB_RX_TGL;
 
 		/*
-		** and mark the port as usable
-		*/
+		 ** and mark the port as usable
+		 */
 		PortP->Mapped = 1;
 		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 	}
-	if ( HostMapP->SysPort < p->RIOFirstPortsMapped )
+	if (HostMapP->SysPort < p->RIOFirstPortsMapped)
 		p->RIOFirstPortsMapped = HostMapP->SysPort;
-	if ( HostMapP->SysPort > p->RIOLastPortsMapped )
+	if (HostMapP->SysPort > p->RIOLastPortsMapped)
 		p->RIOLastPortsMapped = HostMapP->SysPort;
 
 	return 0;
 }
 
-int
-RIOChangeName(p, MapP)
+int RIOChangeName(p, MapP)
 struct rio_info *p;
-struct Map* MapP; 
+struct Map *MapP;
 {
 	int host;
 	struct Map *HostMapP;
 	char *sptr;
 
-	rio_dprintk (RIO_DEBUG_TABLE, "Change name entry on host %x, rta %x, ID %d, Sysport %d\n",
-								MapP->HostUniqueNum,MapP->RtaUniqueNum,
-								MapP->ID, (int)MapP->SysPort);
+	rio_dprintk(RIO_DEBUG_TABLE, "Change name entry on host %x, rta %x, ID %d, Sysport %d\n", MapP->HostUniqueNum, MapP->RtaUniqueNum, MapP->ID, (int) MapP->SysPort);
 
-	if ( MapP->ID > MAX_RUP ) {
-		rio_dprintk (RIO_DEBUG_TABLE, "Bad ID in map entry!\n");
+	if (MapP->ID > MAX_RUP) {
+		rio_dprintk(RIO_DEBUG_TABLE, "Bad ID in map entry!\n");
 		p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
 		return -EINVAL;
 	}
 
-	MapP->Name[MAX_NAME_LEN-1] = '\0';
+	MapP->Name[MAX_NAME_LEN - 1] = '\0';
 	sptr = MapP->Name;
 
-	while ( *sptr ) {
-		if ( *sptr<' ' || *sptr>'~' ) {
-			rio_dprintk (RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n");
+	while (*sptr) {
+		if (*sptr < ' ' || *sptr > '~') {
+			rio_dprintk(RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n");
 			p->RIOError.Error = BAD_CHARACTER_IN_NAME;
 			return -EINVAL;
 		}
 		sptr++;
 	}
 
-	for ( host=0; host < p->RIONumHosts; host++ ) {
-		if ( MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum ) {
-			if ( (p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING ) {
+	for (host = 0; host < p->RIONumHosts; host++) {
+		if (MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum) {
+			if ((p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING) {
 				p->RIOError.Error = HOST_NOT_RUNNING;
 				return -ENXIO;
 			}
-			if ( MapP->ID==0 ) {
-				CCOPY( MapP->Name, p->RIOHosts[host].Name, MAX_NAME_LEN );
+			if (MapP->ID == 0) {
+				CCOPY(MapP->Name, p->RIOHosts[host].Name, MAX_NAME_LEN);
 				return 0;
 			}
 
-			HostMapP = &p->RIOHosts[host].Mapping[MapP->ID-1];
+			HostMapP = &p->RIOHosts[host].Mapping[MapP->ID - 1];
 
-			if ( HostMapP->RtaUniqueNum != MapP->RtaUniqueNum ) {
+			if (HostMapP->RtaUniqueNum != MapP->RtaUniqueNum) {
 				p->RIOError.Error = RTA_NUMBER_WRONG;
 				return -ENXIO;
 			}
-			CCOPY( MapP->Name, HostMapP->Name, MAX_NAME_LEN );
+			CCOPY(MapP->Name, HostMapP->Name, MAX_NAME_LEN);
 			return 0;
 		}
 	}
 	p->RIOError.Error = UNKNOWN_HOST_NUMBER;
-	rio_dprintk (RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum);
+	rio_dprintk(RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum);
 	return -ENXIO;
 }
diff --git a/drivers/char/rio/riotime.h b/drivers/char/rio/riotime.h
index 66d52bc0..35e01cd 100644
--- a/drivers/char/rio/riotime.h
+++ b/drivers/char/rio/riotime.h
@@ -40,7 +40,7 @@
 
 #ifndef lint
 #ifdef SCCS
-static char *_rio_riotime_h_sccs = "@(#)riotime.h	1.1" ;
+static char *_rio_riotime_h_sccs = "@(#)riotime.h	1.1";
 #endif
 #endif
 
@@ -52,7 +52,7 @@
 /**************************************
  * Convert a RIO tick (1/10th second)
  * into transputer low priority ticks
- *************************************/ 
+ *************************************/
 #define RioTimeToLow(time) (time*(100000 / 64))
 #define RioLowToTime(time) ((time*64)/100000)
 
diff --git a/drivers/char/rio/riotty.c b/drivers/char/rio/riotty.c
index 78a321a..5894a25 100644
--- a/drivers/char/rio/riotty.c
+++ b/drivers/char/rio/riotty.c
@@ -90,21 +90,19 @@
 #include "sam.h"
 
 #if 0
-static void ttyseth_pv(struct Port *, struct ttystatics *, 
-				struct termios *sg, int);
+static void ttyseth_pv(struct Port *, struct ttystatics *, struct termios *sg, int);
 #endif
 
 static void RIOClearUp(struct Port *PortP);
-int RIOShortCommand(struct rio_info *p, struct Port *PortP, 
-			   int command, int len, int arg);
+int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg);
 
 #if 0
 static int RIOCookMode(struct ttystatics *);
 #endif
 
-extern int	conv_vb[];	/* now defined in ttymgr.c */
-extern int	conv_bv[];	/* now defined in ttymgr.c */
- 
+extern int conv_vb[];		/* now defined in ttymgr.c */
+extern int conv_bv[];		/* now defined in ttymgr.c */
+
 /*
 ** 16.09.1998 ARG - Fix to build riotty.k.o for Modular Kernel Support
 **
@@ -117,27 +115,25 @@
 #endif
 
 #ifdef NEED_THIS2
-static struct old_sgttyb 
-default_sg = 
-{ 
-	B19200, B19200,				/* input and output speed */ 
-	'H' - '@',					/* erase char */ 
-	-1,							/* 2nd erase char */ 
-	'U' - '@',					/* kill char */ 
-	ECHO | CRMOD,				/* mode */ 
-	'C' - '@',					/* interrupt character */ 
-	'\\' - '@',					/* quit char */ 
-	'Q' - '@',					/* start char */
-	'S' - '@',					/* stop char */ 
-	'D' - '@',					/* EOF */
-	-1,							/* brk */
-	(LCRTBS | LCRTERA | LCRTKIL | LCTLECH),	/* local mode word */ 
-	'Z' - '@',					/* process stop */
-	'Y' - '@',					/* delayed stop */
-	'R' - '@',					/* reprint line */ 
-	'O' - '@',					/* flush output */
-	'W' - '@',					/* word erase */
-	'V' - '@'					/* literal next char */
+static struct old_sgttyb default_sg = {
+	B19200, B19200,		/* input and output speed */
+	'H' - '@',		/* erase char */
+	-1,			/* 2nd erase char */
+	'U' - '@',		/* kill char */
+	ECHO | CRMOD,		/* mode */
+	'C' - '@',		/* interrupt character */
+	'\\' - '@',		/* quit char */
+	'Q' - '@',		/* start char */
+	'S' - '@',		/* stop char */
+	'D' - '@',		/* EOF */
+	-1,			/* brk */
+	(LCRTBS | LCRTERA | LCRTKIL | LCTLECH),	/* local mode word */
+	'Z' - '@',		/* process stop */
+	'Y' - '@',		/* delayed stop */
+	'R' - '@',		/* reprint line */
+	'O' - '@',		/* flush output */
+	'W' - '@',		/* word erase */
+	'V' - '@'		/* literal next char */
 };
 #endif
 
@@ -145,62 +141,59 @@
 extern struct rio_info *p;
 
 
-int
-riotopen(struct tty_struct * tty, struct file * filp)
+int riotopen(struct tty_struct *tty, struct file *filp)
 {
 	register uint SysPort;
 	int Modem;
 	int repeat_this = 250;
-	struct Port *PortP;		 /* pointer to the port structure */
+	struct Port *PortP;	/* pointer to the port structure */
 	unsigned long flags;
 	int retval = 0;
 
-	func_enter ();
+	func_enter();
 
 	/* Make sure driver_data is NULL in case the rio isn't booted jet. Else gs_close
 	   is going to oops.
-	*/
+	 */
 	tty->driver_data = NULL;
-        
-	SysPort = rio_minor(tty);
-	Modem   = rio_ismodem(tty);
 
-	if ( p->RIOFailed ) {
-		rio_dprintk (RIO_DEBUG_TTY, "System initialisation failed\n");
+	SysPort = rio_minor(tty);
+	Modem = rio_ismodem(tty);
+
+	if (p->RIOFailed) {
+		rio_dprintk(RIO_DEBUG_TTY, "System initialisation failed\n");
 		pseterr(ENXIO);
-		func_exit ();
+		func_exit();
 		return -ENXIO;
 	}
 
-	rio_dprintk (RIO_DEBUG_TTY, "port open SysPort %d (%s) (mapped:%d)\n",
-	       SysPort,  Modem ? "Modem" : "tty",
-				   p->RIOPortp[SysPort]->Mapped);
+	rio_dprintk(RIO_DEBUG_TTY, "port open SysPort %d (%s) (mapped:%d)\n", SysPort, Modem ? "Modem" : "tty", p->RIOPortp[SysPort]->Mapped);
 
 	/*
-	** Validate that we have received a legitimate request.
-	** Currently, just check that we are opening a port on
-	** a host card that actually exists, and that the port
-	** has been mapped onto a host.
-	*/
+	 ** Validate that we have received a legitimate request.
+	 ** Currently, just check that we are opening a port on
+	 ** a host card that actually exists, and that the port
+	 ** has been mapped onto a host.
+	 */
 	if (SysPort >= RIO_PORTS) {	/* out of range ? */
-		rio_dprintk (RIO_DEBUG_TTY, "Illegal port number %d\n",SysPort);
+		rio_dprintk(RIO_DEBUG_TTY, "Illegal port number %d\n", SysPort);
 		pseterr(ENXIO);
 		func_exit();
 		return -ENXIO;
 	}
 
 	/*
-	** Grab pointer to the port stucture
-	*/
+	 ** Grab pointer to the port stucture
+	 */
 	PortP = p->RIOPortp[SysPort];	/* Get control struc */
-	rio_dprintk (RIO_DEBUG_TTY, "PortP: %p\n", PortP);
-	if ( !PortP->Mapped ) {	/* we aren't mapped yet! */
+	rio_dprintk(RIO_DEBUG_TTY, "PortP: %p\n", PortP);
+	if (!PortP->Mapped) {	/* we aren't mapped yet! */
 		/*
-		** The system doesn't know which RTA this port
-		** corresponds to.
-		*/
-		rio_dprintk (RIO_DEBUG_TTY, "port not mapped into system\n");
-		func_exit ();
+		 ** The system doesn't know which RTA this port
+		 ** corresponds to.
+		 */
+		rio_dprintk(RIO_DEBUG_TTY, "port not mapped into system\n");
+		func_exit();
 		pseterr(ENXIO);
 		return -ENXIO;
 	}
@@ -210,132 +203,131 @@
 	PortP->gs.tty = tty;
 	PortP->gs.count++;
 
-	rio_dprintk (RIO_DEBUG_TTY, "%d bytes in tx buffer\n",
-				   PortP->gs.xmit_cnt);
+	rio_dprintk(RIO_DEBUG_TTY, "%d bytes in tx buffer\n", PortP->gs.xmit_cnt);
 
-	retval = gs_init_port (&PortP->gs);
+	retval = gs_init_port(&PortP->gs);
 	if (retval) {
 		PortP->gs.count--;
 		return -ENXIO;
 	}
 	/*
-	** If the host hasn't been booted yet, then 
-	** fail
-	*/
-	if ( (PortP->HostP->Flags & RUN_STATE) != RC_RUNNING ) {
-		rio_dprintk (RIO_DEBUG_TTY, "Host not running\n");
+	 ** If the host hasn't been booted yet, then
+	 ** fail
+	 */
+	if ((PortP->HostP->Flags & RUN_STATE) != RC_RUNNING) {
+		rio_dprintk(RIO_DEBUG_TTY, "Host not running\n");
 		pseterr(ENXIO);
-		func_exit ();
+		func_exit();
 		return -ENXIO;
 	}
 
 	/*
-	** If the RTA has not booted yet and the user has choosen to block
-	** until the RTA is present then we must spin here waiting for
-	** the RTA to boot.
-	*/
+	 ** If the RTA has not booted yet and the user has choosen to block
+	 ** until the RTA is present then we must spin here waiting for
+	 ** the RTA to boot.
+	 */
 #if 0
 	if (!(PortP->HostP->Mapping[PortP->RupNum].Flags & RTA_BOOTED)) {
 		if (PortP->WaitUntilBooted) {
-			rio_dprintk (RIO_DEBUG_TTY, "Waiting for RTA to boot\n");
+			rio_dprintk(RIO_DEBUG_TTY, "Waiting for RTA to boot\n");
 			do {
 				if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
-					rio_dprintk (RIO_DEBUG_TTY, "RTA EINTR in delay \n");
-					func_exit ();
+					rio_dprintk(RIO_DEBUG_TTY, "RTA EINTR in delay \n");
+					func_exit();
 					return -EINTR;
 				}
-				if (repeat_this -- <= 0) {
-					rio_dprintk (RIO_DEBUG_TTY, "Waiting for RTA to boot timeout\n");
-					RIOPreemptiveCmd(p, PortP, FCLOSE ); 
+				if (repeat_this-- <= 0) {
+					rio_dprintk(RIO_DEBUG_TTY, "Waiting for RTA to boot timeout\n");
+					RIOPreemptiveCmd(p, PortP, FCLOSE);
 					pseterr(EINTR);
-					func_exit ();
+					func_exit();
 					return -EIO;
 				}
-			} while(!(PortP->HostP->Mapping[PortP->RupNum].Flags & RTA_BOOTED));
-			rio_dprintk (RIO_DEBUG_TTY, "RTA has been booted\n");
+			} while (!(PortP->HostP->Mapping[PortP->RupNum].Flags & RTA_BOOTED));
+			rio_dprintk(RIO_DEBUG_TTY, "RTA has been booted\n");
 		} else {
-			rio_dprintk (RIO_DEBUG_TTY, "RTA never booted\n");
+			rio_dprintk(RIO_DEBUG_TTY, "RTA never booted\n");
 			pseterr(ENXIO);
-			func_exit ();
+			func_exit();
 			return 0;
 		}
 	}
 #else
 	/* I find the above code a bit hairy. I find the below code
-           easier to read and shorter. Now, if it works too that would
+	   easier to read and shorter. Now, if it works too that would
 	   be great... -- REW 
-	*/
-	rio_dprintk (RIO_DEBUG_TTY, "Checking if RTA has booted... \n");
+	 */
+	rio_dprintk(RIO_DEBUG_TTY, "Checking if RTA has booted... \n");
 	while (!(PortP->HostP->Mapping[PortP->RupNum].Flags & RTA_BOOTED)) {
-	  if (!PortP->WaitUntilBooted) {
-	    rio_dprintk (RIO_DEBUG_TTY, "RTA never booted\n");
-	    func_exit ();
-	    return -ENXIO;
-	  }
+		if (!PortP->WaitUntilBooted) {
+			rio_dprintk(RIO_DEBUG_TTY, "RTA never booted\n");
+			func_exit();
+			return -ENXIO;
+		}
 
-	  /* Under Linux you'd normally use a wait instead of this
-	     busy-waiting. I'll stick with the old implementation for
-	     now. --REW 
-	  */
-	  if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
-	    rio_dprintk (RIO_DEBUG_TTY, "RTA_wait_for_boot: EINTR in delay \n");
-	    func_exit ();
-	    return -EINTR;
-	  }
-	  if (repeat_this -- <= 0) {
-	    rio_dprintk (RIO_DEBUG_TTY, "Waiting for RTA to boot timeout\n");
-	    func_exit ();
-	    return -EIO;
-	  }
+		/* Under Linux you'd normally use a wait instead of this
+		   busy-waiting. I'll stick with the old implementation for
+		   now. --REW
+		 */
+		if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
+			rio_dprintk(RIO_DEBUG_TTY, "RTA_wait_for_boot: EINTR in delay \n");
+			func_exit();
+			return -EINTR;
+		}
+		if (repeat_this-- <= 0) {
+			rio_dprintk(RIO_DEBUG_TTY, "Waiting for RTA to boot timeout\n");
+			func_exit();
+			return -EIO;
+		}
 	}
-	rio_dprintk (RIO_DEBUG_TTY, "RTA has been booted\n");
+	rio_dprintk(RIO_DEBUG_TTY, "RTA has been booted\n");
 #endif
 #if 0
-	tp =  PortP->TtyP;		/* get tty struct */
+	tp = PortP->TtyP;	/* get tty struct */
 #endif
 	rio_spin_lock_irqsave(&PortP->portSem, flags);
-	if ( p->RIOHalted ) {
+	if (p->RIOHalted) {
 		goto bombout;
 	}
 #if 0
 	retval = gs_init_port(&PortP->gs);
-	if (retval){
-		func_exit ();
+	if (retval) {
+		func_exit();
 		return retval;
 	}
 #endif
 
 	/*
-	** If the port is in the final throws of being closed,
-	** we should wait here (politely), waiting
-	** for it to finish, so that it doesn't close us!
-	*/
-	while ( (PortP->State & RIO_CLOSING) && !p->RIOHalted ) {
-		rio_dprintk (RIO_DEBUG_TTY, "Waiting for RIO_CLOSING to go away\n");
-		if (repeat_this -- <= 0) {
-			rio_dprintk (RIO_DEBUG_TTY, "Waiting for not idle closed broken by signal\n");
-			RIOPreemptiveCmd(p, PortP, FCLOSE ); 
+	 ** If the port is in the final throws of being closed,
+	 ** we should wait here (politely), waiting
+	 ** for it to finish, so that it doesn't close us!
+	 */
+	while ((PortP->State & RIO_CLOSING) && !p->RIOHalted) {
+		rio_dprintk(RIO_DEBUG_TTY, "Waiting for RIO_CLOSING to go away\n");
+		if (repeat_this-- <= 0) {
+			rio_dprintk(RIO_DEBUG_TTY, "Waiting for not idle closed broken by signal\n");
+			RIOPreemptiveCmd(p, PortP, FCLOSE);
 			retval = -EINTR;
 			goto bombout;
 		}
 		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 		if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
-			rio_spin_lock_irqsave(&PortP->portSem, flags); 
+			rio_spin_lock_irqsave(&PortP->portSem, flags);
 			retval = -EINTR;
 			goto bombout;
 		}
-		rio_spin_lock_irqsave(&PortP->portSem, flags); 
+		rio_spin_lock_irqsave(&PortP->portSem, flags);
 	}
 
-	if ( !PortP->Mapped ) {
-		rio_dprintk (RIO_DEBUG_TTY, "Port unmapped while closing!\n");
+	if (!PortP->Mapped) {
+		rio_dprintk(RIO_DEBUG_TTY, "Port unmapped while closing!\n");
 		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 		retval = -ENXIO;
-		func_exit ();
+		func_exit();
 		return retval;
 	}
 
-	if ( p->RIOHalted ) {
+	if (p->RIOHalted) {
 		goto bombout;
 	}
 
@@ -346,16 +338,16 @@
 */
 	/* Uh? Suppose I turn these on and then another process opens
 	   the port again? The flags get cleared! Not good. -- REW */
-	if ( !(PortP->State & (RIO_LOPEN | RIO_MOPEN)) ) {
-		PortP->Config &= ~(RIO_CTSFLOW|RIO_RTSFLOW);
+	if (!(PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
+		PortP->Config &= ~(RIO_CTSFLOW | RIO_RTSFLOW);
 	}
 
 	if (!(PortP->firstOpen)) {	/* First time ? */
-		rio_dprintk (RIO_DEBUG_TTY, "First open for this port\n");
-	
+		rio_dprintk(RIO_DEBUG_TTY, "First open for this port\n");
+
 
 		PortP->firstOpen++;
-		PortP->CookMode = 0; /* XXX RIOCookMode(tp); */
+		PortP->CookMode = 0;	/* XXX RIOCookMode(tp); */
 		PortP->InUse = NOT_INUSE;
 
 		/* Tentative fix for bug PR27. Didn't work. */
@@ -363,26 +355,26 @@
 
 		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 #ifdef NEED_THIS
-		ttyseth(PortP, tp, (struct old_sgttyb *)&default_sg);
+		ttyseth(PortP, tp, (struct old_sgttyb *) &default_sg);
 #endif
 
 		/* Someone explain to me why this delay/config is
-                   here. If I read the docs correctly the "open"
-                   command piggybacks the parameters immediately. 
+		   here. If I read the docs correctly the "open"
+		   command piggybacks the parameters immediately.
 		   -- REW */
-		RIOParam(PortP,OPEN,Modem,OK_TO_SLEEP);		/* Open the port */
+		RIOParam(PortP, OPEN, Modem, OK_TO_SLEEP);	/* Open the port */
 #if 0
 		/* This delay of 1 second was annoying. I removed it. -- REW */
-		RIODelay(PortP, HUNDRED_MS*10);
-		RIOParam(PortP,CONFIG,Modem,OK_TO_SLEEP);	/* Config the port */
+		RIODelay(PortP, HUNDRED_MS * 10);
+		RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP);	/* Config the port */
 #endif
 		rio_spin_lock_irqsave(&PortP->portSem, flags);
 
 		/*
-		** wait for the port to be not closed.
-		*/
-		while ( !(PortP->PortState & PORT_ISOPEN) && !p->RIOHalted ) {
-			rio_dprintk (RIO_DEBUG_TTY, "Waiting for PORT_ISOPEN-currently %x\n",PortP->PortState);
+		 ** wait for the port to be not closed.
+		 */
+		while (!(PortP->PortState & PORT_ISOPEN) && !p->RIOHalted) {
+			rio_dprintk(RIO_DEBUG_TTY, "Waiting for PORT_ISOPEN-currently %x\n", PortP->PortState);
 /*
 ** 15.10.1998 ARG - ESIL 0759
 ** (Part) fix for port being trashed when opened whilst RTA "disconnected"
@@ -399,115 +391,109 @@
 */
 			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 			if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
-				rio_dprintk (RIO_DEBUG_TTY, "Waiting for open to finish broken by signal\n");
-				RIOPreemptiveCmd(p, PortP, FCLOSE );
-				func_exit ();
+				rio_dprintk(RIO_DEBUG_TTY, "Waiting for open to finish broken by signal\n");
+				RIOPreemptiveCmd(p, PortP, FCLOSE);
+				func_exit();
 				return -EINTR;
 			}
 			rio_spin_lock_irqsave(&PortP->portSem, flags);
 		}
 
-		if ( p->RIOHalted ) {
-		  retval = -EIO;
-bombout:
-		  /* 			RIOClearUp( PortP ); */
+		if (p->RIOHalted) {
+			retval = -EIO;
+		      bombout:
+			/*                    RIOClearUp( PortP ); */
 			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 			return retval;
 		}
-		rio_dprintk (RIO_DEBUG_TTY, "PORT_ISOPEN found\n");
+		rio_dprintk(RIO_DEBUG_TTY, "PORT_ISOPEN found\n");
 	}
-
-#ifdef MODEM_SUPPORT 
+#ifdef MODEM_SUPPORT
 	if (Modem) {
-		rio_dprintk (RIO_DEBUG_TTY, "Modem - test for carrier\n");
+		rio_dprintk(RIO_DEBUG_TTY, "Modem - test for carrier\n");
 		/*
-		** ACTION
-		** insert test for carrier here. -- ???
-		** I already see that test here. What's the deal? -- REW
-		*/
-		if ((PortP->gs.tty->termios->c_cflag & CLOCAL) || (PortP->ModemState & MSVR1_CD))
-		{
-			rio_dprintk (RIO_DEBUG_TTY, "open(%d) Modem carr on\n", SysPort);
+		 ** ACTION
+		 ** insert test for carrier here. -- ???
+		 ** I already see that test here. What's the deal? -- REW
+		 */
+		if ((PortP->gs.tty->termios->c_cflag & CLOCAL) || (PortP->ModemState & MSVR1_CD)) {
+			rio_dprintk(RIO_DEBUG_TTY, "open(%d) Modem carr on\n", SysPort);
 			/*
-			tp->tm.c_state |= CARR_ON;
-			wakeup((caddr_t) &tp->tm.c_canq);
-			*/
+			   tp->tm.c_state |= CARR_ON;
+			   wakeup((caddr_t) &tp->tm.c_canq);
+			 */
 			PortP->State |= RIO_CARR_ON;
-			wake_up_interruptible (&PortP->gs.open_wait);
-		}
-		else /* no carrier - wait for DCD */
-		{
-		  /*
-			while (!(PortP->gs.tty->termios->c_state & CARR_ON) && 
-			       !(filp->f_flags & O_NONBLOCK) && !p->RIOHalted )
-		  */
-			while (!(PortP->State & RIO_CARR_ON) && 
-			       !(filp->f_flags & O_NONBLOCK) && !p->RIOHalted ) {
+			wake_up_interruptible(&PortP->gs.open_wait);
+		} else {	/* no carrier - wait for DCD */
 
-				rio_dprintk (RIO_DEBUG_TTY, "open(%d) sleeping for carr on\n",SysPort);
+			/*
+			   while (!(PortP->gs.tty->termios->c_state & CARR_ON) &&
+			   !(filp->f_flags & O_NONBLOCK) && !p->RIOHalted )
+			 */
+			while (!(PortP->State & RIO_CARR_ON) && !(filp->f_flags & O_NONBLOCK) && !p->RIOHalted) {
+
+				rio_dprintk(RIO_DEBUG_TTY, "open(%d) sleeping for carr on\n", SysPort);
 				/*
-				PortP->gs.tty->termios->c_state |= WOPEN;
-				*/
+				   PortP->gs.tty->termios->c_state |= WOPEN;
+				 */
 				PortP->State |= RIO_WOPEN;
 				rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-				if (RIODelay (PortP, HUNDRED_MS) == RIO_FAIL)
+				if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL)
 #if 0
-				if ( sleep((caddr_t)&tp->tm.c_canqo, TTIPRI|PCATCH))
+					if (sleep((caddr_t) & tp->tm.c_canqo, TTIPRI | PCATCH))
 #endif
-				{
-					/*
-					** ACTION: verify that this is a good thing
-					** to do here. -- ???
-					** I think it's OK. -- REW
-					*/
-					rio_dprintk (RIO_DEBUG_TTY, "open(%d) sleeping for carr broken by signal\n",
-					       SysPort);
-					RIOPreemptiveCmd( p, PortP, FCLOSE );
-					/*
-					tp->tm.c_state &= ~WOPEN;
-					*/
-					PortP->State &= ~RIO_WOPEN;
-					rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-					func_exit ();
-					return -EINTR;
-				}
+					{
+						/*
+						 ** ACTION: verify that this is a good thing
+						 ** to do here. -- ???
+						 ** I think it's OK. -- REW
+						 */
+						rio_dprintk(RIO_DEBUG_TTY, "open(%d) sleeping for carr broken by signal\n", SysPort);
+						RIOPreemptiveCmd(p, PortP, FCLOSE);
+						/*
+						   tp->tm.c_state &= ~WOPEN;
+						 */
+						PortP->State &= ~RIO_WOPEN;
+						rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+						func_exit();
+						return -EINTR;
+					}
 			}
 			PortP->State &= ~RIO_WOPEN;
 		}
-		if ( p->RIOHalted )
+		if (p->RIOHalted)
 			goto bombout;
-		rio_dprintk (RIO_DEBUG_TTY, "Setting RIO_MOPEN\n");
+		rio_dprintk(RIO_DEBUG_TTY, "Setting RIO_MOPEN\n");
 		PortP->State |= RIO_MOPEN;
-	}
-	else
+	} else
 #endif
 	{
 		/*
-		** ACTION
-		** Direct line open - force carrier (will probably mean
-		** that sleeping Modem line fubar)
-		*/
+		 ** ACTION
+		 ** Direct line open - force carrier (will probably mean
+		 ** that sleeping Modem line fubar)
+		 */
 		PortP->State |= RIO_LOPEN;
 	}
 
-	if ( p->RIOHalted ) {
+	if (p->RIOHalted) {
 		goto bombout;
 	}
 
-	rio_dprintk (RIO_DEBUG_TTY, "high level open done\n");
+	rio_dprintk(RIO_DEBUG_TTY, "high level open done\n");
 
 #ifdef STATS
 	PortP->Stat.OpenCnt++;
 #endif
 	/*
-	** Count opens for port statistics reporting
-	*/
+	 ** Count opens for port statistics reporting
+	 */
 	if (PortP->statsGather)
 		PortP->opens++;
 
 	rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-	rio_dprintk (RIO_DEBUG_TTY, "Returning from open\n");
-	func_exit ();
+	rio_dprintk(RIO_DEBUG_TTY, "Returning from open\n");
+	func_exit();
 	return 0;
 }
 
@@ -516,36 +502,35 @@
 ** The operating system thinks that this is last close for the device.
 ** As there are two interfaces to the port (Modem and tty), we need to
 ** check that both are closed before we close the device.
-*/ 
-int
-riotclose(void  *ptr)
+*/
+int riotclose(void *ptr)
 {
 #if 0
 	register uint SysPort = dev;
-	struct ttystatics *tp;		/* pointer to our ttystruct */
+	struct ttystatics *tp;	/* pointer to our ttystruct */
 #endif
 	struct Port *PortP = ptr;	/* pointer to the port structure */
 	int deleted = 0;
-	int	try = -1; /* Disable the timeouts by setting them to -1 */
-	int	repeat_this = -1; /* Congrats to those having 15 years of 
-				     uptime! (You get to break the driver.) */
+	int try = -1;		/* Disable the timeouts by setting them to -1 */
+	int repeat_this = -1;	/* Congrats to those having 15 years of
+				   uptime! (You get to break the driver.) */
 	unsigned long end_time;
-	struct tty_struct * tty;
+	struct tty_struct *tty;
 	unsigned long flags;
 	int Modem;
 	int rv = 0;
-	
-	rio_dprintk (RIO_DEBUG_TTY, "port close SysPort %d\n",PortP->PortNum);
+
+	rio_dprintk(RIO_DEBUG_TTY, "port close SysPort %d\n", PortP->PortNum);
 
 	/* PortP = p->RIOPortp[SysPort]; */
-	rio_dprintk (RIO_DEBUG_TTY, "Port is at address 0x%x\n",(int)PortP);
-	/* tp = PortP->TtyP;*/			/* Get tty */
+	rio_dprintk(RIO_DEBUG_TTY, "Port is at address 0x%x\n", (int) PortP);
+	/* tp = PortP->TtyP; *//* Get tty */
 	tty = PortP->gs.tty;
-	rio_dprintk (RIO_DEBUG_TTY, "TTY is at address 0x%x\n",(int)tty);
+	rio_dprintk(RIO_DEBUG_TTY, "TTY is at address 0x%x\n", (int) tty);
 
-	if (PortP->gs.closing_wait) 
+	if (PortP->gs.closing_wait)
 		end_time = jiffies + PortP->gs.closing_wait;
-	else 
+	else
 		end_time = jiffies + MAX_SCHEDULE_TIMEOUT;
 
 	Modem = rio_ismodem(tty);
@@ -553,48 +538,48 @@
 	/* What F.CKING cache? Even then, a higly idle multiprocessor,
 	   system with large caches this won't work . Better find out when 
 	   this doesn't work asap, and fix the cause.  -- REW */
-	
-	RIODelay(PortP, HUNDRED_MS*10);	/* To flush the cache */
+
+	RIODelay(PortP, HUNDRED_MS * 10);	/* To flush the cache */
 #endif
 	rio_spin_lock_irqsave(&PortP->portSem, flags);
 
 	/*
-	** Setting this flag will make any process trying to open
-	** this port block until we are complete closing it.
-	*/
+	 ** Setting this flag will make any process trying to open
+	 ** this port block until we are complete closing it.
+	 */
 	PortP->State |= RIO_CLOSING;
 
-	if ( (PortP->State & RIO_DELETED) ) {
-		rio_dprintk (RIO_DEBUG_TTY, "Close on deleted RTA\n");
+	if ((PortP->State & RIO_DELETED)) {
+		rio_dprintk(RIO_DEBUG_TTY, "Close on deleted RTA\n");
 		deleted = 1;
 	}
-	
-	if ( p->RIOHalted ) {
-		RIOClearUp( PortP );
+
+	if (p->RIOHalted) {
+		RIOClearUp(PortP);
 		rv = -EIO;
 		goto close_end;
 	}
 
-	rio_dprintk (RIO_DEBUG_TTY, "Clear bits\n");
+	rio_dprintk(RIO_DEBUG_TTY, "Clear bits\n");
 	/*
-	** clear the open bits for this device
-	*/
+	 ** clear the open bits for this device
+	 */
 	PortP->State &= (Modem ? ~RIO_MOPEN : ~RIO_LOPEN);
 	PortP->State &= ~RIO_CARR_ON;
 	PortP->ModemState &= ~MSVR1_CD;
 	/*
-	** If the device was open as both a Modem and a tty line
-	** then we need to wimp out here, as the port has not really
-	** been finally closed (gee, whizz!) The test here uses the
-	** bit for the OTHER mode of operation, to see if THAT is
-	** still active!
-	*/
-	if ( (PortP->State & (RIO_LOPEN|RIO_MOPEN)) ) {
+	 ** If the device was open as both a Modem and a tty line
+	 ** then we need to wimp out here, as the port has not really
+	 ** been finally closed (gee, whizz!) The test here uses the
+	 ** bit for the OTHER mode of operation, to see if THAT is
+	 ** still active!
+	 */
+	if ((PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
 		/*
-		** The port is still open for the other task -
-		** return, pretending that we are still active.
-		*/
-		rio_dprintk (RIO_DEBUG_TTY, "Channel %d still open !\n",PortP->PortNum);
+		 ** The port is still open for the other task -
+		 ** return, pretending that we are still active.
+		 */
+		rio_dprintk(RIO_DEBUG_TTY, "Channel %d still open !\n", PortP->PortNum);
 		PortP->State &= ~RIO_CLOSING;
 		if (PortP->firstOpen)
 			PortP->firstOpen--;
@@ -602,48 +587,47 @@
 		return -EIO;
 	}
 
-	rio_dprintk (RIO_DEBUG_TTY, "Closing down - everything must go!\n");
+	rio_dprintk(RIO_DEBUG_TTY, "Closing down - everything must go!\n");
 
 	PortP->State &= ~RIO_DYNOROD;
 
 	/*
-	** This is where we wait for the port
-	** to drain down before closing. Bye-bye....
-	** (We never meant to do this)
-	*/
-	rio_dprintk (RIO_DEBUG_TTY, "Timeout 1 starts\n");
+	 ** This is where we wait for the port
+	 ** to drain down before closing. Bye-bye....
+	 ** (We never meant to do this)
+	 */
+	rio_dprintk(RIO_DEBUG_TTY, "Timeout 1 starts\n");
 
 	if (!deleted)
-	while ( (PortP->InUse != NOT_INUSE) && !p->RIOHalted && 
-		(PortP->TxBufferIn != PortP->TxBufferOut) ) {
-		cprintf("Need to flush the ttyport\n");
-		if (repeat_this -- <= 0) {
-			rv = -EINTR;
-			rio_dprintk (RIO_DEBUG_TTY, "Waiting for not idle closed broken by signal\n");
-			RIOPreemptiveCmd(p, PortP, FCLOSE);
-			goto close_end;
-		}
-		rio_dprintk (RIO_DEBUG_TTY, "Calling timeout to flush in closing\n");
-		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-		if (RIODelay_ni(PortP, HUNDRED_MS*10) == RIO_FAIL) {
-			rio_dprintk (RIO_DEBUG_TTY, "RTA EINTR in delay \n");
-			rv = -EINTR;
+		while ((PortP->InUse != NOT_INUSE) && !p->RIOHalted && (PortP->TxBufferIn != PortP->TxBufferOut)) {
+			cprintf("Need to flush the ttyport\n");
+			if (repeat_this-- <= 0) {
+				rv = -EINTR;
+				rio_dprintk(RIO_DEBUG_TTY, "Waiting for not idle closed broken by signal\n");
+				RIOPreemptiveCmd(p, PortP, FCLOSE);
+				goto close_end;
+			}
+			rio_dprintk(RIO_DEBUG_TTY, "Calling timeout to flush in closing\n");
+			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+			if (RIODelay_ni(PortP, HUNDRED_MS * 10) == RIO_FAIL) {
+				rio_dprintk(RIO_DEBUG_TTY, "RTA EINTR in delay \n");
+				rv = -EINTR;
+				rio_spin_lock_irqsave(&PortP->portSem, flags);
+				goto close_end;
+			}
 			rio_spin_lock_irqsave(&PortP->portSem, flags);
-			goto close_end;
 		}
-		rio_spin_lock_irqsave(&PortP->portSem, flags);
-	}
 
 	PortP->TxBufferIn = PortP->TxBufferOut = 0;
 	repeat_this = 0xff;
 
 	PortP->InUse = 0;
-	if ( (PortP->State & (RIO_LOPEN|RIO_MOPEN)) ) {
+	if ((PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
 		/*
-		** The port has been re-opened for the other task -
-		** return, pretending that we are still active.
-		*/
-		rio_dprintk (RIO_DEBUG_TTY, "Channel %d re-open!\n", PortP->PortNum);
+		 ** The port has been re-opened for the other task -
+		 ** return, pretending that we are still active.
+		 */
+		rio_dprintk(RIO_DEBUG_TTY, "Channel %d re-open!\n", PortP->PortNum);
 		PortP->State &= ~RIO_CLOSING;
 		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 		if (PortP->firstOpen)
@@ -651,8 +635,8 @@
 		return -EIO;
 	}
 
-	if ( p->RIOHalted ) {
-		RIOClearUp( PortP );
+	if (p->RIOHalted) {
+		RIOClearUp(PortP);
 		goto close_end;
 	}
 
@@ -665,57 +649,56 @@
 	}
 
 	if (!deleted)
-	  while (try && (PortP->PortState & PORT_ISOPEN)) {
-	        try--;
-		if (time_after (jiffies, end_time)) {
-		  rio_dprintk (RIO_DEBUG_TTY, "Run out of tries - force the bugger shut!\n" );
-		  RIOPreemptiveCmd(p, PortP,FCLOSE);
-		  break;
-		}
-		rio_dprintk (RIO_DEBUG_TTY, "Close: PortState:ISOPEN is %d\n", 
-					   PortP->PortState & PORT_ISOPEN);
+		while (try && (PortP->PortState & PORT_ISOPEN)) {
+			try--;
+			if (time_after(jiffies, end_time)) {
+				rio_dprintk(RIO_DEBUG_TTY, "Run out of tries - force the bugger shut!\n");
+				RIOPreemptiveCmd(p, PortP, FCLOSE);
+				break;
+			}
+			rio_dprintk(RIO_DEBUG_TTY, "Close: PortState:ISOPEN is %d\n", PortP->PortState & PORT_ISOPEN);
 
-		if ( p->RIOHalted ) {
-			RIOClearUp( PortP );
-			goto close_end;
+			if (p->RIOHalted) {
+				RIOClearUp(PortP);
+				goto close_end;
+			}
+			if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
+				rio_dprintk(RIO_DEBUG_TTY, "RTA EINTR in delay \n");
+				RIOPreemptiveCmd(p, PortP, FCLOSE);
+				break;
+			}
 		}
-		if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
-			rio_dprintk (RIO_DEBUG_TTY, "RTA EINTR in delay \n");
-			RIOPreemptiveCmd(p, PortP,FCLOSE);
-			break;
-		}
-	}
 	rio_spin_lock_irqsave(&PortP->portSem, flags);
-	rio_dprintk (RIO_DEBUG_TTY, "Close: try was %d on completion\n", try );
- 
+	rio_dprintk(RIO_DEBUG_TTY, "Close: try was %d on completion\n", try);
+
 	/* RIOPreemptiveCmd(p, PortP, FCLOSE); */
 
 /*
 ** 15.10.1998 ARG - ESIL 0761 part fix
 ** RIO has it's own CTSFLOW and RTSFLOW flags in 'Config' in the port structure,** we need to make sure that the flags are clear when the port is opened.
 */
-	PortP->Config &= ~(RIO_CTSFLOW|RIO_RTSFLOW);
+	PortP->Config &= ~(RIO_CTSFLOW | RIO_RTSFLOW);
 
 #ifdef STATS
 	PortP->Stat.CloseCnt++;
 #endif
 	/*
-	** Count opens for port statistics reporting
-	*/
+	 ** Count opens for port statistics reporting
+	 */
 	if (PortP->statsGather)
 		PortP->closes++;
 
-close_end:
+      close_end:
 	/* XXX: Why would a "DELETED" flag be reset here? I'd have
 	   thought that a "deleted" flag means that the port was
 	   permanently gone, but here we can make it reappear by it
 	   being in close during the "deletion".
-	*/
-	PortP->State &= ~(RIO_CLOSING|RIO_DELETED);
+	 */
+	PortP->State &= ~(RIO_CLOSING | RIO_DELETED);
 	if (PortP->firstOpen)
 		PortP->firstOpen--;
 	rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-	rio_dprintk (RIO_DEBUG_TTY, "Return from close\n");
+	rio_dprintk(RIO_DEBUG_TTY, "Return from close\n");
 	return rv;
 }
 
@@ -728,52 +711,50 @@
 ** COOK_MEDIUM if the card can do all the processing necessary.
 */
 #if 0
-static int
-RIOCookMode(struct ttystatics *tp)
+static int RIOCookMode(struct ttystatics *tp)
 {
 	/*
-	** We can't handle tm.c_mstate != 0 on SCO
-	** We can't handle mapping
-	** We can't handle non-ttwrite line disc.
-	** We can't handle lflag XCASE
-	** We can handle oflag OPOST & (OCRNL, ONLCR, TAB3)
-	*/
+	 ** We can't handle tm.c_mstate != 0 on SCO
+	 ** We can't handle mapping
+	 ** We can't handle non-ttwrite line disc.
+	 ** We can't handle lflag XCASE
+	 ** We can handle oflag OPOST & (OCRNL, ONLCR, TAB3)
+	 */
 
 #ifdef CHECK
-	CheckTtyP( tp );
+	CheckTtyP(tp);
 #endif
 	if (!(tp->tm.c_oflag & OPOST))	/* No post processing */
 		return COOK_RAW;	/* Raw mode o/p */
 
-	if ( tp->tm.c_lflag & XCASE )
+	if (tp->tm.c_lflag & XCASE)
 		return COOK_WELL;	/* Use line disc */
 
-	if (tp->tm.c_oflag & ~(OPOST | ONLCR | OCRNL | TAB3 ) )
+	if (tp->tm.c_oflag & ~(OPOST | ONLCR | OCRNL | TAB3))
 		return COOK_WELL;	/* Use line disc for strange modes */
 
-	if ( tp->tm.c_oflag == OPOST )	/* If only OPOST is set, do RAW */
+	if (tp->tm.c_oflag == OPOST)	/* If only OPOST is set, do RAW */
 		return COOK_RAW;
 
 	/*
-	** So, we need to output process!
-	*/
+	 ** So, we need to output process!
+	 */
 	return COOK_MEDIUM;
 }
 #endif
 
-static void
-RIOClearUp(PortP)
+static void RIOClearUp(PortP)
 struct Port *PortP;
 {
-	rio_dprintk (RIO_DEBUG_TTY, "RIOHalted set\n");
-	PortP->Config = 0;	  /* Direct semaphore */
+	rio_dprintk(RIO_DEBUG_TTY, "RIOHalted set\n");
+	PortP->Config = 0;	/* Direct semaphore */
 	PortP->PortState = 0;
 	PortP->firstOpen = 0;
 	PortP->FlushCmdBodge = 0;
 	PortP->ModemState = PortP->CookMode = 0;
 	PortP->Mapped = 0;
 	PortP->WflushFlag = 0;
-	PortP->MagicFlags	= 0;
+	PortP->MagicFlags = 0;
 	PortP->RxDataStart = 0;
 	PortP->TxBufferIn = 0;
 	PortP->TxBufferOut = 0;
@@ -788,33 +769,31 @@
 ** Other values of len aren't allowed, and will cause
 ** a panic.
 */
-int RIOShortCommand(struct rio_info *p, struct Port *PortP,
-		int command, int len, int arg)
+int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg)
 {
 	PKT *PacketP;
-	int		retries = 20; /* at 10 per second -> 2 seconds */
+	int retries = 20;	/* at 10 per second -> 2 seconds */
 	unsigned long flags;
 
-	rio_dprintk (RIO_DEBUG_TTY, "entering shortcommand.\n");
+	rio_dprintk(RIO_DEBUG_TTY, "entering shortcommand.\n");
 #ifdef CHECK
-	CheckPortP( PortP );
-	if ( len < 1 || len > 2 )
-		cprintf(("STUPID LENGTH %d\n",len));
+	CheckPortP(PortP);
+	if (len < 1 || len > 2)
+		cprintf(("STUPID LENGTH %d\n", len));
 #endif
 
-	if ( PortP->State & RIO_DELETED ) {
-		rio_dprintk (RIO_DEBUG_TTY, "Short command to deleted RTA ignored\n");
+	if (PortP->State & RIO_DELETED) {
+		rio_dprintk(RIO_DEBUG_TTY, "Short command to deleted RTA ignored\n");
 		return RIO_FAIL;
 	}
 	rio_spin_lock_irqsave(&PortP->portSem, flags);
 
 	/*
-	** If the port is in use for pre-emptive command, then wait for it to 
-	** be free again.
-	*/
-	while ( (PortP->InUse != NOT_INUSE) && !p->RIOHalted ) {
-		rio_dprintk (RIO_DEBUG_TTY, "Waiting for not in use (%d)\n", 
-					   retries);
+	 ** If the port is in use for pre-emptive command, then wait for it to
+	 ** be free again.
+	 */
+	while ((PortP->InUse != NOT_INUSE) && !p->RIOHalted) {
+		rio_dprintk(RIO_DEBUG_TTY, "Waiting for not in use (%d)\n", retries);
 		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 		if (retries-- <= 0) {
 			return RIO_FAIL;
@@ -824,47 +803,47 @@
 		}
 		rio_spin_lock_irqsave(&PortP->portSem, flags);
 	}
-	if ( PortP->State & RIO_DELETED ) {
-		rio_dprintk (RIO_DEBUG_TTY, "Short command to deleted RTA ignored\n");
+	if (PortP->State & RIO_DELETED) {
+		rio_dprintk(RIO_DEBUG_TTY, "Short command to deleted RTA ignored\n");
 		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 		return RIO_FAIL;
 	}
 
-	while ( !can_add_transmit(&PacketP,PortP) && !p->RIOHalted ) {
-		rio_dprintk (RIO_DEBUG_TTY, "Waiting to add short command to queue (%d)\n", retries);
+	while (!can_add_transmit(&PacketP, PortP) && !p->RIOHalted) {
+		rio_dprintk(RIO_DEBUG_TTY, "Waiting to add short command to queue (%d)\n", retries);
 		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 		if (retries-- <= 0) {
-		  rio_dprintk (RIO_DEBUG_TTY, "out of tries. Failing\n");
+			rio_dprintk(RIO_DEBUG_TTY, "out of tries. Failing\n");
 			return RIO_FAIL;
 		}
-		if ( RIODelay_ni(PortP, HUNDRED_MS)==RIO_FAIL ) {
+		if (RIODelay_ni(PortP, HUNDRED_MS) == RIO_FAIL) {
 			return RIO_FAIL;
 		}
 		rio_spin_lock_irqsave(&PortP->portSem, flags);
 	}
 
-	if ( p->RIOHalted ) {
+	if (p->RIOHalted) {
 		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 		return RIO_FAIL;
 	}
 
 	/*
-	** set the command byte and the argument byte
-	*/
-	WBYTE(PacketP->data[0] , command);
+	 ** set the command byte and the argument byte
+	 */
+	WBYTE(PacketP->data[0], command);
 
-	if ( len==2 )
-		WBYTE(PacketP->data[1] , arg);
+	if (len == 2)
+		WBYTE(PacketP->data[1], arg);
 
 	/*
-	** set the length of the packet and set the command bit.
-	*/
-	WBYTE(PacketP->len , PKT_CMD_BIT | len);
+	 ** set the length of the packet and set the command bit.
+	 */
+	WBYTE(PacketP->len, PKT_CMD_BIT | len);
 
 	add_transmit(PortP);
 	/*
-	** Count characters transmitted for port statistics reporting
-	*/
+	 ** Count characters transmitted for port statistics reporting
+	 */
 	if (PortP->statsGather)
 		PortP->txchars += len;
 
@@ -878,28 +857,26 @@
 ** This is an ioctl interface. This is the twentieth century. You know what
 ** its all about.
 */
-int
-riotioctl(struct rio_info *p, struct tty_struct *tty, int cmd, caddr_t arg)
+int riotioctl(struct rio_info *p, struct tty_struct *tty, int cmd, caddr_t arg)
 {
-	register struct		Port *PortP;
-	register struct		ttystatics *tp;
-	int					current;
-	int					ParamSemIncremented = 0;
-	int					old_oflag, old_cflag, old_iflag, changed, oldcook;
-	int					i;
-	unsigned char		sio_regs[5];		/* Here be magic */
-	short				vpix_cflag;
-	short				divisor;
-	int					baud;
-	uint				SysPort = rio_minor(tty);
-	int				Modem = rio_ismodem(tty);
-	int					ioctl_processed;
+	register struct Port *PortP;
+	register struct ttystatics *tp;
+	int current;
+	int ParamSemIncremented = 0;
+	int old_oflag, old_cflag, old_iflag, changed, oldcook;
+	int i;
+	unsigned char sio_regs[5];	/* Here be magic */
+	short vpix_cflag;
+	short divisor;
+	int baud;
+	uint SysPort = rio_minor(tty);
+	int Modem = rio_ismodem(tty);
+	int ioctl_processed;
 
-	rio_dprintk (RIO_DEBUG_TTY, "port ioctl SysPort %d command 0x%x argument 0x%x %s\n",
-			SysPort, cmd, arg, Modem?"Modem":"tty") ;
+	rio_dprintk(RIO_DEBUG_TTY, "port ioctl SysPort %d command 0x%x argument 0x%x %s\n", SysPort, cmd, arg, Modem ? "Modem" : "tty");
 
-	if ( SysPort >= RIO_PORTS ) {
-		rio_dprintk (RIO_DEBUG_TTY, "Bad port number %d\n", SysPort);
+	if (SysPort >= RIO_PORTS) {
+		rio_dprintk(RIO_DEBUG_TTY, "Bad port number %d\n", SysPort);
 		return -ENXIO;
 	}
 
@@ -912,205 +889,195 @@
 	PortP->Stat.IoctlCnt++;
 #endif
 
-	if ( PortP->State & RIO_DELETED ) {
+	if (PortP->State & RIO_DELETED) {
 		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 		return -EIO;
 	}
 
 
-	if ( p->RIOHalted ) {
-		RIOClearUp( PortP );
+	if (p->RIOHalted) {
+		RIOClearUp(PortP);
 		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 		return -EIO;
 	}
 
 	/*
-	** Count ioctls for port statistics reporting
-	*/
+	 ** Count ioctls for port statistics reporting
+	 */
 	if (PortP->statsGather)
 		PortP->ioctls++;
 
 	/*
-	** Specialix RIO Ioctl calls
-	*/
+	 ** Specialix RIO Ioctl calls
+	 */
 	switch (cmd) {
 
-		case TCRIOTRIAD:
-			if ( arg )
-				PortP->State |= RIO_TRIAD_MODE;
-			else
-				PortP->State &= ~RIO_TRIAD_MODE;
-			/*
-			** Normally, when istrip is set on a port, a config is
-			** sent to the RTA instructing the CD1400 to do the
-			** stripping. In TRIAD mode, the interrupt receive routine
-			** must do the stripping instead, since it has to detect
-			** an 8 bit function key sequence. If istrip is set with
-			** TRIAD mode on(off), and 8 bit data is being read by
-			** the port, the user then turns TRIAD mode off(on), the RTA
-			** must be reconfigured (not) to do the stripping.
-			** Hence we call RIOParam here.
-			*/
-			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-			RIOParam(PortP,CONFIG,Modem,OK_TO_SLEEP);	
-			return 0;
+	case TCRIOTRIAD:
+		if (arg)
+			PortP->State |= RIO_TRIAD_MODE;
+		else
+			PortP->State &= ~RIO_TRIAD_MODE;
+		/*
+		 ** Normally, when istrip is set on a port, a config is
+		 ** sent to the RTA instructing the CD1400 to do the
+		 ** stripping. In TRIAD mode, the interrupt receive routine
+		 ** must do the stripping instead, since it has to detect
+		 ** an 8 bit function key sequence. If istrip is set with
+		 ** TRIAD mode on(off), and 8 bit data is being read by
+		 ** the port, the user then turns TRIAD mode off(on), the RTA
+		 ** must be reconfigured (not) to do the stripping.
+		 ** Hence we call RIOParam here.
+		 */
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP);
+		return 0;
 
-		case TCRIOTSTATE:
-			rio_dprintk (RIO_DEBUG_TTY, "tbusy/tstop monitoring %sabled\n",
-		 		arg ? "en" : "dis");
-			/* MonitorTstate = 0 ;*/
-			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-			RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP);
-			return 0;
+	case TCRIOTSTATE:
+		rio_dprintk(RIO_DEBUG_TTY, "tbusy/tstop monitoring %sabled\n", arg ? "en" : "dis");
+		/* MonitorTstate = 0 ; */
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP);
+		return 0;
 
-		case TCRIOSTATE: /* current state of Modem input pins */
-			rio_dprintk (RIO_DEBUG_TTY, "TCRIOSTATE\n");
-			if (RIOPreemptiveCmd(p, PortP, MGET) == RIO_FAIL)
-				rio_dprintk (RIO_DEBUG_TTY, "TCRIOSTATE command failed\n");
-			PortP->State |= RIO_BUSY;
-			current = PortP->ModemState;
-			if ( copyout((caddr_t)&current, (int)arg,
-							sizeof(current))==COPYFAIL ) {
-				rio_dprintk (RIO_DEBUG_TTY, "Copyout failed\n");
-				rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-				pseterr(EFAULT);
-			}
+	case TCRIOSTATE:	/* current state of Modem input pins */
+		rio_dprintk(RIO_DEBUG_TTY, "TCRIOSTATE\n");
+		if (RIOPreemptiveCmd(p, PortP, MGET) == RIO_FAIL)
+			rio_dprintk(RIO_DEBUG_TTY, "TCRIOSTATE command failed\n");
+		PortP->State |= RIO_BUSY;
+		current = PortP->ModemState;
+		if (copyout((caddr_t) & current, (int) arg, sizeof(current)) == COPYFAIL) {
+			rio_dprintk(RIO_DEBUG_TTY, "Copyout failed\n");
 			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-			return 0;
+			pseterr(EFAULT);
+		}
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		return 0;
 
-		case TCRIOMBIS:		/* Set modem lines */
-		case TCRIOMBIC:		/* Clear modem lines */
-			rio_dprintk (RIO_DEBUG_TTY, "TCRIOMBIS/TCRIOMBIC\n");
-			if (cmd == TCRIOMBIS) {
-				uint		state;
-				state = (uint)arg;
-				PortP->ModemState |= (ushort)state;
-				PortP->ModemLines = (ulong) arg;
-				if (RIOPreemptiveCmd(p, PortP, MBIS) == RIO_FAIL)
-					rio_dprintk (RIO_DEBUG_TTY, 
-					 "TCRIOMBIS command failed\n");
-			}
-			else {
-				uint		state;
+	case TCRIOMBIS:	/* Set modem lines */
+	case TCRIOMBIC:	/* Clear modem lines */
+		rio_dprintk(RIO_DEBUG_TTY, "TCRIOMBIS/TCRIOMBIC\n");
+		if (cmd == TCRIOMBIS) {
+			uint state;
+			state = (uint) arg;
+			PortP->ModemState |= (ushort) state;
+			PortP->ModemLines = (ulong) arg;
+			if (RIOPreemptiveCmd(p, PortP, MBIS) == RIO_FAIL)
+				rio_dprintk(RIO_DEBUG_TTY, "TCRIOMBIS command failed\n");
+		} else {
+			uint state;
 
-				state = (uint)arg;
-				PortP->ModemState &= ~(ushort)state;
-				PortP->ModemLines = (ulong) arg;
-				if (RIOPreemptiveCmd(p, PortP, MBIC) == RIO_FAIL)
-					rio_dprintk (RIO_DEBUG_TTY, "TCRIOMBIC command failed\n");
-			}
-			PortP->State |= RIO_BUSY;
+			state = (uint) arg;
+			PortP->ModemState &= ~(ushort) state;
+			PortP->ModemLines = (ulong) arg;
+			if (RIOPreemptiveCmd(p, PortP, MBIC) == RIO_FAIL)
+				rio_dprintk(RIO_DEBUG_TTY, "TCRIOMBIC command failed\n");
+		}
+		PortP->State |= RIO_BUSY;
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		return 0;
+
+	case TCRIOXPON:	/* set Xprint ON string */
+		rio_dprintk(RIO_DEBUG_TTY, "TCRIOXPON\n");
+		if (copyin((int) arg, (caddr_t) PortP->Xprint.XpOn, MAX_XP_CTRL_LEN) == COPYFAIL) {
+			rio_dprintk(RIO_DEBUG_TTY, "Copyin failed\n");
+			PortP->Xprint.XpOn[0] = '\0';
 			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-			return 0;
+			pseterr(EFAULT);
+		}
+		PortP->Xprint.XpOn[MAX_XP_CTRL_LEN - 1] = '\0';
+		PortP->Xprint.XpLen = strlen(PortP->Xprint.XpOn) + strlen(PortP->Xprint.XpOff);
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		return 0;
 
-		case TCRIOXPON: /* set Xprint ON string */
-			rio_dprintk (RIO_DEBUG_TTY, "TCRIOXPON\n");
-			if ( copyin((int)arg, (caddr_t)PortP->Xprint.XpOn,
-						MAX_XP_CTRL_LEN)==COPYFAIL ) {
-				rio_dprintk (RIO_DEBUG_TTY, "Copyin failed\n");
-				PortP->Xprint.XpOn[0] = '\0';
-				rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-				pseterr(EFAULT);
-			}
-			PortP->Xprint.XpOn[MAX_XP_CTRL_LEN-1] = '\0';
-			PortP->Xprint.XpLen = strlen(PortP->Xprint.XpOn)+
-												strlen(PortP->Xprint.XpOff);
+	case TCRIOXPOFF:	/* set Xprint OFF string */
+		rio_dprintk(RIO_DEBUG_TTY, "TCRIOXPOFF\n");
+		if (copyin((int) arg, (caddr_t) PortP->Xprint.XpOff, MAX_XP_CTRL_LEN) == COPYFAIL) {
+			rio_dprintk(RIO_DEBUG_TTY, "Copyin failed\n");
+			PortP->Xprint.XpOff[0] = '\0';
 			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-			return 0;
+			pseterr(EFAULT);
+		}
+		PortP->Xprint.XpOff[MAX_XP_CTRL_LEN - 1] = '\0';
+		PortP->Xprint.XpLen = strlen(PortP->Xprint.XpOn) + strlen(PortP->Xprint.XpOff);
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		return 0;
 
-		case TCRIOXPOFF: /* set Xprint OFF string */
-			rio_dprintk (RIO_DEBUG_TTY, "TCRIOXPOFF\n");
-			if ( copyin( (int)arg, (caddr_t)PortP->Xprint.XpOff,
-						MAX_XP_CTRL_LEN)==COPYFAIL ) {
-				rio_dprintk (RIO_DEBUG_TTY, "Copyin failed\n");
-				PortP->Xprint.XpOff[0] = '\0';
-				rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-				pseterr(EFAULT);
-			}
-			PortP->Xprint.XpOff[MAX_XP_CTRL_LEN-1] = '\0';
-			PortP->Xprint.XpLen = strlen(PortP->Xprint.XpOn)+
-										strlen(PortP->Xprint.XpOff);
+	case TCRIOXPCPS:	/* set Xprint CPS string */
+		rio_dprintk(RIO_DEBUG_TTY, "TCRIOXPCPS\n");
+		if ((uint) arg > p->RIOConf.MaxXpCps || (uint) arg < p->RIOConf.MinXpCps) {
+			rio_dprintk(RIO_DEBUG_TTY, "%d CPS out of range\n", arg);
 			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+			pseterr(EINVAL);
 			return 0;
+		}
+		PortP->Xprint.XpCps = (uint) arg;
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		return 0;
 
-		case TCRIOXPCPS: /* set Xprint CPS string */
-			rio_dprintk (RIO_DEBUG_TTY, "TCRIOXPCPS\n");
-			if ( (uint)arg > p->RIOConf.MaxXpCps || 
-					(uint)arg < p->RIOConf.MinXpCps ) {
-				rio_dprintk (RIO_DEBUG_TTY, "%d CPS out of range\n",arg);
-				rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-				pseterr(EINVAL);
-				return 0;
-			}
-			PortP->Xprint.XpCps = (uint)arg;
+	case TCRIOXPRINT:
+		rio_dprintk(RIO_DEBUG_TTY, "TCRIOXPRINT\n");
+		if (copyout((caddr_t) & PortP->Xprint, (int) arg, sizeof(struct Xprint)) == COPYFAIL) {
 			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-			return 0;
+			pseterr(EFAULT);
+		}
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		return 0;
 
-		case TCRIOXPRINT:
-			rio_dprintk (RIO_DEBUG_TTY, "TCRIOXPRINT\n");
-			if ( copyout((caddr_t)&PortP->Xprint, (int)arg,
-					sizeof(struct Xprint))==COPYFAIL ) {
-			        rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-				pseterr(EFAULT);
-			}
-			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-			return 0;
+	case TCRIOIXANYON:
+		rio_dprintk(RIO_DEBUG_TTY, "TCRIOIXANYON\n");
+		PortP->Config |= RIO_IXANY;
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		return 0;
 
-		case TCRIOIXANYON:
-			rio_dprintk (RIO_DEBUG_TTY, "TCRIOIXANYON\n");
-			PortP->Config |= RIO_IXANY;
-			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-			return 0;
+	case TCRIOIXANYOFF:
+		rio_dprintk(RIO_DEBUG_TTY, "TCRIOIXANYOFF\n");
+		PortP->Config &= ~RIO_IXANY;
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		return 0;
 
-		case TCRIOIXANYOFF:
-			rio_dprintk (RIO_DEBUG_TTY, "TCRIOIXANYOFF\n");
-			PortP->Config &= ~RIO_IXANY;
-			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-			return 0;
+	case TCRIOIXONON:
+		rio_dprintk(RIO_DEBUG_TTY, "TCRIOIXONON\n");
+		PortP->Config |= RIO_IXON;
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		return 0;
 
-		case TCRIOIXONON:
-			rio_dprintk (RIO_DEBUG_TTY, "TCRIOIXONON\n");
-			PortP->Config |= RIO_IXON;
-			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-			return 0;
-
-		case TCRIOIXONOFF:
-			rio_dprintk (RIO_DEBUG_TTY, "TCRIOIXONOFF\n");
-			PortP->Config &= ~RIO_IXON;
-			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-			return 0;
+	case TCRIOIXONOFF:
+		rio_dprintk(RIO_DEBUG_TTY, "TCRIOIXONOFF\n");
+		PortP->Config &= ~RIO_IXON;
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		return 0;
 
 /*
 ** 15.10.1998 ARG - ESIL 0761 part fix
 ** Added support for CTS and RTS flow control ioctls :
 */
-		case TCRIOCTSFLOWEN:
-			rio_dprintk (RIO_DEBUG_TTY, "TCRIOCTSFLOWEN\n");
-			PortP->Config |= RIO_CTSFLOW;
-			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-			RIOParam(PortP,CONFIG,Modem,OK_TO_SLEEP);	
-			return 0;
+	case TCRIOCTSFLOWEN:
+		rio_dprintk(RIO_DEBUG_TTY, "TCRIOCTSFLOWEN\n");
+		PortP->Config |= RIO_CTSFLOW;
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP);
+		return 0;
 
-		case TCRIOCTSFLOWDIS:
-			rio_dprintk (RIO_DEBUG_TTY, "TCRIOCTSFLOWDIS\n");
-			PortP->Config &= ~RIO_CTSFLOW;
-			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-			RIOParam(PortP,CONFIG,Modem,OK_TO_SLEEP);	
-			return 0;
+	case TCRIOCTSFLOWDIS:
+		rio_dprintk(RIO_DEBUG_TTY, "TCRIOCTSFLOWDIS\n");
+		PortP->Config &= ~RIO_CTSFLOW;
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP);
+		return 0;
 
-		case TCRIORTSFLOWEN:
-			rio_dprintk (RIO_DEBUG_TTY, "TCRIORTSFLOWEN\n");
-			PortP->Config |= RIO_RTSFLOW;
-			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-			RIOParam(PortP,CONFIG,Modem,OK_TO_SLEEP);	
-			return 0;
+	case TCRIORTSFLOWEN:
+		rio_dprintk(RIO_DEBUG_TTY, "TCRIORTSFLOWEN\n");
+		PortP->Config |= RIO_RTSFLOW;
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP);
+		return 0;
 
-		case TCRIORTSFLOWDIS:
-			rio_dprintk (RIO_DEBUG_TTY, "TCRIORTSFLOWDIS\n");
-			PortP->Config &= ~RIO_RTSFLOW;
-			rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-			RIOParam(PortP,CONFIG,Modem,OK_TO_SLEEP);	
-			return 0;
+	case TCRIORTSFLOWDIS:
+		rio_dprintk(RIO_DEBUG_TTY, "TCRIORTSFLOWDIS\n");
+		PortP->Config &= ~RIO_RTSFLOW;
+		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
+		RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP);
+		return 0;
 
 /* end ESIL 0761 part fix */
 
@@ -1119,35 +1086,35 @@
 
 	/* Lynx IOCTLS */
 	switch (cmd) {
-		case TIOCSETP:
-		case TIOCSETN:
-		case OTIOCSETP:
-		case OTIOCSETN:
-			ioctl_processed++;
-			ttyseth(PortP, tp, (struct old_sgttyb *)arg);
-			break;
-		case TCSETA:
-		case TCSETAW:
-		case TCSETAF:
-			ioctl_processed++;
-			rio_dprintk (RIO_DEBUG_TTY, "NON POSIX ioctl\n");
-			ttyseth_pv(PortP, tp, (struct termios *)arg, 0);
-			break;
-		case TCSETAP:	/* posix tcsetattr() */
-		case TCSETAWP:	/* posix tcsetattr() */
-		case TCSETAFP:	/* posix tcsetattr() */
-			rio_dprintk (RIO_DEBUG_TTY, "NON POSIX SYSV ioctl\n");
-			ttyseth_pv(PortP, tp, (struct termios *)arg, 1);
-			ioctl_processed++;
-			break;
+	case TIOCSETP:
+	case TIOCSETN:
+	case OTIOCSETP:
+	case OTIOCSETN:
+		ioctl_processed++;
+		ttyseth(PortP, tp, (struct old_sgttyb *) arg);
+		break;
+	case TCSETA:
+	case TCSETAW:
+	case TCSETAF:
+		ioctl_processed++;
+		rio_dprintk(RIO_DEBUG_TTY, "NON POSIX ioctl\n");
+		ttyseth_pv(PortP, tp, (struct termios *) arg, 0);
+		break;
+	case TCSETAP:		/* posix tcsetattr() */
+	case TCSETAWP:		/* posix tcsetattr() */
+	case TCSETAFP:		/* posix tcsetattr() */
+		rio_dprintk(RIO_DEBUG_TTY, "NON POSIX SYSV ioctl\n");
+		ttyseth_pv(PortP, tp, (struct termios *) arg, 1);
+		ioctl_processed++;
+		break;
 	}
 
 	/*
-	** If its any of the commands that require the port to be in the
-	** non-busy state wait until all output has drained 
-	*/
+	 ** If its any of the commands that require the port to be in the
+	 ** non-busy state wait until all output has drained
+	 */
 	if (!ioctl_processed)
-	switch(cmd) {
+		switch (cmd) {
 		case TCSETAW:
 		case TCSETAF:
 		case TCSETA:
@@ -1171,29 +1138,29 @@
 #endif
 		case TIOCSETD:
 		case TIOCSETN:
-			rio_dprintk (RIO_DEBUG_TTY, "wait for non-BUSY, semaphore set\n");
+			rio_dprintk(RIO_DEBUG_TTY, "wait for non-BUSY, semaphore set\n");
 			/*
-			** Wait for drain here, at least as far as the double buffer
-			** being empty.
-			*/
+			 ** Wait for drain here, at least as far as the double buffer
+			 ** being empty.
+			 */
 			/* XXX Does the above comment mean that this has
 			   still to be implemented? -- REW */
 			/* XXX Is the locking OK together with locking
-                           in txenable? (Deadlock?) -- REW */
-			
-			RIOTxEnable((char *)PortP);
+			   in txenable? (Deadlock?) -- REW */
+
+			RIOTxEnable((char *) PortP);
 			break;
 		default:
 			break;
-	}
+		}
 
 	old_cflag = tp->tm.c_cflag;
 	old_iflag = tp->tm.c_iflag;
 	old_oflag = tp->tm.c_oflag;
 	oldcook = PortP->CookMode;
 
-	if ( p->RIOHalted ) {
-		RIOClearUp( PortP );
+	if (p->RIOHalted) {
+		RIOClearUp(PortP);
 		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 		pseterr(EIO);
 		return 0;
@@ -1202,10 +1169,10 @@
 	PortP->FlushCmdBodge = 0;
 
 	/*
-	** If the port is locked, and it is reconfigured, we want
-	** to restore the state of the tty structure so the change is NOT
-	** made.
-	*/
+	 ** If the port is locked, and it is reconfigured, we want
+	 ** to restore the state of the tty structure so the change is NOT
+	 ** made.
+	 */
 	if (PortP->Lock) {
 		tp->tm.c_iflag = PortP->StoredTty.iflag;
 		tp->tm.c_oflag = PortP->StoredTty.oflag;
@@ -1214,13 +1181,12 @@
 		tp->tm.c_line = PortP->StoredTty.line;
 		for (i = 0; i < NCC + 1; i++)
 			tp->tm.c_cc[i] = PortP->StoredTty.cc[i];
-	}
-	else {
+	} else {
 		/*
-		** If the port is set to store the parameters, and it is
-		** reconfigured, we want to save the current tty struct so it
-		** may be restored on the next open.
-		*/
+		 ** If the port is set to store the parameters, and it is
+		 ** reconfigured, we want to save the current tty struct so it
+		 ** may be restored on the next open.
+		 */
 		if (PortP->Store) {
 			PortP->StoredTty.iflag = tp->tm.c_iflag;
 			PortP->StoredTty.oflag = tp->tm.c_oflag;
@@ -1232,44 +1198,41 @@
 		}
 	}
 
-	changed = (tp->tm.c_cflag != old_cflag) ||
-				(tp->tm.c_iflag != old_iflag) ||
-				(tp->tm.c_oflag != old_oflag);
+	changed = (tp->tm.c_cflag != old_cflag) || (tp->tm.c_iflag != old_iflag) || (tp->tm.c_oflag != old_oflag);
 
 	PortP->CookMode = RIOCookMode(tp);	/* Set new cooking mode */
 
-	rio_dprintk (RIO_DEBUG_TTY, "RIOIoctl changed %d newcook %d oldcook %d\n",
-			changed,PortP->CookMode,oldcook);
+	rio_dprintk(RIO_DEBUG_TTY, "RIOIoctl changed %d newcook %d oldcook %d\n", changed, PortP->CookMode, oldcook);
 
 #ifdef MODEM_SUPPORT
 	/*
-	** kludge to force CARR_ON if CLOCAL set
-	*/
-	if ((tp->tm.c_cflag & CLOCAL) || (PortP->ModemState & MSVR1_CD))	{
+	 ** kludge to force CARR_ON if CLOCAL set
+	 */
+	if ((tp->tm.c_cflag & CLOCAL) || (PortP->ModemState & MSVR1_CD)) {
 		tp->tm.c_state |= CARR_ON;
-		wakeup ((caddr_t)&tp->tm.c_canq);
+		wakeup((caddr_t) & tp->tm.c_canq);
 	}
 #endif
 
-	if ( p->RIOHalted ) {
-		RIOClearUp( PortP );
+	if (p->RIOHalted) {
+		RIOClearUp(PortP);
 		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 		pseterr(EIO);
 		return 0;
 	}
 	/*
-	** Re-configure if modes or cooking have changed
-	*/
+	 ** Re-configure if modes or cooking have changed
+	 */
 	if (changed || oldcook != PortP->CookMode || (ioctl_processed)) {
 		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-		rio_dprintk (RIO_DEBUG_TTY, "Ioctl changing the PORT settings\n");
-		RIOParam(PortP,CONFIG,Modem,OK_TO_SLEEP);	
+		rio_dprintk(RIO_DEBUG_TTY, "Ioctl changing the PORT settings\n");
+		RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP);
 		rio_spin_lock_irqsave(&PortP->portSem, flags);
 	}
 
 	if (p->RIOHalted) {
 		rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-		RIOClearUp( PortP );
+		RIOClearUp(PortP);
 		pseterr(EIO);
 		return 0;
 	}
@@ -1280,36 +1243,32 @@
 /*
 	ttyseth -- set hardware dependent tty settings
 */
-void
-ttyseth(PortP, s, sg)
-struct Port *		PortP;
-struct ttystatics *		s;
+void ttyseth(PortP, s, sg)
+struct Port *PortP;
+struct ttystatics *s;
 struct old_sgttyb *sg;
 {
-	struct old_sgttyb *	tsg;
+	struct old_sgttyb *tsg;
 	struct termios *tp = &s->tm;
 
 	tsg = &s->sg;
 
-	if (sg->sg_flags & (EVENP|ODDP))  {
+	if (sg->sg_flags & (EVENP | ODDP)) {
 		tp->c_cflag &= PARENB;
 		if (sg->sg_flags & EVENP) {
 			if (sg->sg_flags & ODDP) {
 				tp->c_cflag &= V_CS7;
 				tp->c_cflag &= ~PARENB;
-			}
-			else {
+			} else {
 				tp->c_cflag &= V_CS7;
 				tp->c_cflag &= PARENB;
 				tp->c_cflag &= PARODD;
 			}
-		}
-		else if (sg->sg_flags & ODDP) {
+		} else if (sg->sg_flags & ODDP) {
 			tp->c_cflag &= V_CS7;
 			tp->c_cflag &= PARENB;
 			tp->c_cflag &= PARODD;
-		}
-		else {
+		} else {
 			tp->c_cflag &= V_CS7;
 			tp->c_cflag &= PARENB;
 		}
@@ -1320,16 +1279,16 @@
  * I will have to use separate sets of flags to store them in the 
  * Port structure.
  */
-	if ( !sg->sg_ospeed )
+	if (!sg->sg_ospeed)
 		sg->sg_ospeed = sg->sg_ispeed;
 	else
 		sg->sg_ispeed = sg->sg_ospeed;
-	if (sg->sg_ispeed > V_EXTB ) 
+	if (sg->sg_ispeed > V_EXTB)
 		sg->sg_ispeed = V_EXTB;
 	if (sg->sg_ispeed < V_B0)
 		sg->sg_ispeed = V_B0;
 	*tsg = *sg;
-   tp->c_cflag = (tp->c_cflag & ~V_CBAUD) | conv_bv[(int)sg->sg_ispeed];
+	tp->c_cflag = (tp->c_cflag & ~V_CBAUD) | conv_bv[(int) sg->sg_ispeed];
 }
 
 /*
@@ -1338,36 +1297,33 @@
 				sysv = 0 => (POSIX):	 struct termios *sg
 				sysv != 0 => (System V): struct termio *sg
 */
-static void
-ttyseth_pv(PortP, s, sg, sysv)
+static void ttyseth_pv(PortP, s, sg, sysv)
 struct Port *PortP;
 struct ttystatics *s;
 struct termios *sg;
 int sysv;
 {
-    int speed;
-    unsigned char csize;
-    unsigned char cread;
-    unsigned int lcr_flags;
-    int ps;
- 
-    if (sysv) {
-        /* sg points to a System V termio structure */
-        csize = ((struct termio *)sg)->c_cflag & CSIZE;
-        cread = ((struct termio *)sg)->c_cflag & CREAD;
-        speed = conv_vb[((struct termio *)sg)->c_cflag & V_CBAUD];
-    }
-    else {
-        /* sg points to a POSIX termios structure */
-        csize = sg->c_cflag & CSIZE;
-        cread = sg->c_cflag & CREAD;
-        speed = conv_vb[sg->c_cflag & V_CBAUD];
-    }
-    if (s->sg.sg_ispeed != speed || s->sg.sg_ospeed != speed) {
-        s->sg.sg_ispeed = speed;
-        s->sg.sg_ospeed = speed;
-        s->tm.c_cflag = (s->tm.c_cflag & ~V_CBAUD) |
-                         conv_bv[(int)s->sg.sg_ispeed];
-    }
+	int speed;
+	unsigned char csize;
+	unsigned char cread;
+	unsigned int lcr_flags;
+	int ps;
+
+	if (sysv) {
+		/* sg points to a System V termio structure */
+		csize = ((struct termio *) sg)->c_cflag & CSIZE;
+		cread = ((struct termio *) sg)->c_cflag & CREAD;
+		speed = conv_vb[((struct termio *) sg)->c_cflag & V_CBAUD];
+	} else {
+		/* sg points to a POSIX termios structure */
+		csize = sg->c_cflag & CSIZE;
+		cread = sg->c_cflag & CREAD;
+		speed = conv_vb[sg->c_cflag & V_CBAUD];
+	}
+	if (s->sg.sg_ispeed != speed || s->sg.sg_ospeed != speed) {
+		s->sg.sg_ispeed = speed;
+		s->sg.sg_ospeed = speed;
+		s->tm.c_cflag = (s->tm.c_cflag & ~V_CBAUD) | conv_bv[(int) s->sg.sg_ispeed];
+	}
 }
 #endif
diff --git a/drivers/char/rio/riotypes.h b/drivers/char/rio/riotypes.h
index 1c7c42c..9b67e24 100644
--- a/drivers/char/rio/riotypes.h
+++ b/drivers/char/rio/riotypes.h
@@ -89,47 +89,46 @@
 typedef RIO_POINTER ushort_ptr;
 #endif
 
-#else /* not INKERNEL */
-typedef unsigned char   BYTE;
-typedef unsigned short  WORD;
-typedef unsigned long   DWORD;
-typedef short           NUMBER;
-typedef short           *NUMBER_ptr;
-typedef unsigned short  *WORD_ptr;
-typedef unsigned char   *BYTE_ptr;
-typedef unsigned char   uchar ;
-typedef unsigned short  ushort ;
-typedef unsigned int    uint ;
-typedef unsigned long   ulong ;
-typedef unsigned char   u_char ;
-typedef unsigned short  u_short ;
-typedef unsigned int    u_int ;
-typedef unsigned long   u_long ;
-typedef unsigned short  ERROR ;
-typedef unsigned long ID ;
-typedef char             *char_ptr;
-typedef Channel          *Channel_ptr;
+#else				/* not INKERNEL */
+typedef unsigned char BYTE;
+typedef unsigned short WORD;
+typedef unsigned long DWORD;
+typedef short NUMBER;
+typedef short *NUMBER_ptr;
+typedef unsigned short *WORD_ptr;
+typedef unsigned char *BYTE_ptr;
+typedef unsigned char uchar;
+typedef unsigned short ushort;
+typedef unsigned int uint;
+typedef unsigned long ulong;
+typedef unsigned char u_char;
+typedef unsigned short u_short;
+typedef unsigned int u_int;
+typedef unsigned long u_long;
+typedef unsigned short ERROR;
+typedef unsigned long ID;
+typedef char *char_ptr;
+typedef Channel *Channel_ptr;
 typedef struct FREE_LIST *FREE_LIST_ptr;
 typedef struct FREE_LIST **FREE_LIST_ptr_ptr;
-typedef struct LPB       *LPB_ptr;
-typedef struct Process   *Process_ptr;
-typedef struct PHB       *PHB_ptr;
-typedef struct PKT       *PKT_ptr;
-typedef struct PKT       **PKT_ptr_ptr;
-typedef struct Q_BUF     *Q_BUF_ptr;
-typedef struct Q_BUF     **Q_BUF_ptr_ptr;
+typedef struct LPB *LPB_ptr;
+typedef struct Process *Process_ptr;
+typedef struct PHB *PHB_ptr;
+typedef struct PKT *PKT_ptr;
+typedef struct PKT **PKT_ptr_ptr;
+typedef struct Q_BUF *Q_BUF_ptr;
+typedef struct Q_BUF **Q_BUF_ptr_ptr;
 typedef struct ROUTE_STR *ROUTE_STR_ptr;
-typedef struct RUP       *RUP_ptr;
-typedef short            *short_ptr;
-typedef u_short          *u_short_ptr;
-typedef ushort           *ushort_ptr;
-typedef struct PKT	 PKT;
-typedef struct LPB	 LPB;
-typedef struct RUP	 RUP;
+typedef struct RUP *RUP_ptr;
+typedef short *short_ptr;
+typedef u_short *u_short_ptr;
+typedef ushort *ushort_ptr;
+typedef struct PKT PKT;
+typedef struct LPB LPB;
+typedef struct RUP RUP;
 #endif
 
 
-#endif /* __riotypes__ */
+#endif				/* __riotypes__ */
 
 /*********** end of file ***********/
-
diff --git a/drivers/char/rio/riowinif.h b/drivers/char/rio/riowinif.h
index 18a4f14..f802d75 100644
--- a/drivers/char/rio/riowinif.h
+++ b/drivers/char/rio/riowinif.h
@@ -40,7 +40,7 @@
 
 */
 
-#ifndef	_riowinif_h				/* If RIOWINDIF.H not already defined */
+#ifndef	_riowinif_h		/* If RIOWINDIF.H not already defined */
 #define	_riowinif_h    1
 
 /*****************************************************************************
@@ -60,42 +60,41 @@
 /* The PARM_MAP structure defines global values relating to the Host Card / RTA
    and is the main structure from which all other structures are referenced. */
 
-typedef	struct	_PARM_MAP
-{
-	_u16	phb_ptr;		/* 0x00 Pointer to the PHB array */
-	_u16	phb_num_ptr;		/* 0x02 Ptr to Number of PHB's */
-	_u16	free_list;		/* 0x04 Free List pointer */
-	_u16	free_list_end;		/* 0x06 Free List End pointer */
-	_u16	q_free_list_ptr;	/* 0x08 Ptr to Q_BUF variable */
-	_u16	unit_id_ptr;		/* 0x0A Unit Id */
-	_u16	link_str_ptr;		/* 0x0C Link Structure Array */
-	_u16	bootloader_1;		/* 0x0E 1st Stage Boot Loader */
-	_u16	bootloader_2;		/* 0x10 2nd Stage Boot Loader */
-	_u16	port_route_map_ptr;	/* 0x12 Port Route Map */
-	_u16	route_ptr;		/* 0x14 Route Map */
-	_u16	map_present;		/* 0x16 Route Map present */
-	_u16	pkt_num;		/* 0x18 Total number of packets */
-	_u16	q_num;			/* 0x1A Total number of Q packets */
-	_u16	buffers_per_port;	/* 0x1C Number of buffers per port */
-	_u16	heap_size;		/* 0x1E Initial size of heap */
-	_u16	heap_left;		/* 0x20 Current Heap left */
-	_u16	error;			/* 0x22 Error code */
-	_u16	tx_max;			/* 0x24 Max number of tx pkts per phb */
-	_u16	rx_max;			/* 0x26 Max number of rx pkts per phb */
-	_u16	rx_limit;		/* 0x28 For high / low watermarks */
-	_u16	links;			/* 0x2A Links to use */
-	_u16	timer;			/* 0x2C Interrupts per second */
-	_u16	rups;			/* 0x2E Pointer to the RUPs */
-	_u16	max_phb;		/* 0x30 Mostly for debugging */
-	_u16	living;			/* 0x32 Just increments!! */
-	_u16	init_done;		/* 0x34 Initialisation over */
-	_u16	booting_link;		/* 0x36 */
-	_u16	idle_count;		/* 0x38 Idle time counter */
-	_u16	busy_count;		/* 0x3A Busy counter */
-	_u16	idle_control;		/* 0x3C Control Idle Process */
-	_u16	tx_intr;		/* 0x3E TX interrupt pending */
-	_u16	rx_intr;		/* 0x40 RX interrupt pending */
-	_u16	rup_intr;		/* 0x42 RUP interrupt pending */
+typedef struct _PARM_MAP {
+	_u16 phb_ptr;		/* 0x00 Pointer to the PHB array */
+	_u16 phb_num_ptr;	/* 0x02 Ptr to Number of PHB's */
+	_u16 free_list;		/* 0x04 Free List pointer */
+	_u16 free_list_end;	/* 0x06 Free List End pointer */
+	_u16 q_free_list_ptr;	/* 0x08 Ptr to Q_BUF variable */
+	_u16 unit_id_ptr;	/* 0x0A Unit Id */
+	_u16 link_str_ptr;	/* 0x0C Link Structure Array */
+	_u16 bootloader_1;	/* 0x0E 1st Stage Boot Loader */
+	_u16 bootloader_2;	/* 0x10 2nd Stage Boot Loader */
+	_u16 port_route_map_ptr;	/* 0x12 Port Route Map */
+	_u16 route_ptr;		/* 0x14 Route Map */
+	_u16 map_present;	/* 0x16 Route Map present */
+	_u16 pkt_num;		/* 0x18 Total number of packets */
+	_u16 q_num;		/* 0x1A Total number of Q packets */
+	_u16 buffers_per_port;	/* 0x1C Number of buffers per port */
+	_u16 heap_size;		/* 0x1E Initial size of heap */
+	_u16 heap_left;		/* 0x20 Current Heap left */
+	_u16 error;		/* 0x22 Error code */
+	_u16 tx_max;		/* 0x24 Max number of tx pkts per phb */
+	_u16 rx_max;		/* 0x26 Max number of rx pkts per phb */
+	_u16 rx_limit;		/* 0x28 For high / low watermarks */
+	_u16 links;		/* 0x2A Links to use */
+	_u16 timer;		/* 0x2C Interrupts per second */
+	_u16 rups;		/* 0x2E Pointer to the RUPs */
+	_u16 max_phb;		/* 0x30 Mostly for debugging */
+	_u16 living;		/* 0x32 Just increments!! */
+	_u16 init_done;		/* 0x34 Initialisation over */
+	_u16 booting_link;	/* 0x36 */
+	_u16 idle_count;	/* 0x38 Idle time counter */
+	_u16 busy_count;	/* 0x3A Busy counter */
+	_u16 idle_control;	/* 0x3C Control Idle Process */
+	_u16 tx_intr;		/* 0x3E TX interrupt pending */
+	_u16 rx_intr;		/* 0x40 RX interrupt pending */
+	_u16 rup_intr;		/* 0x42 RUP interrupt pending */
 
 } PARM_MAP;
 
@@ -184,45 +183,44 @@
    attached to the system and there is normally an array of MAX_RUPS (=16) structures
    in a host card, defined by PARM_MAP->rup. */
 
-typedef	struct	_RUP
-{
-	_u16		txpkt;			/* 0x00 Outgoing packet */
-	_u16		rxpkt;			/* 0x02 ncoming packet */
-	_u16		link;			/* 0x04 Which link to send packet down ? */
-	_u8		rup_dest_unit[2];	/* 0x06 Destination Unit */
-	_u16		handshake;		/* 0x08 Handshaking */
-	_u16		timeout;		/* 0x0A Timeout */
-	_u16		status;			/* 0x0C Status */
-	_u16		txcontrol;		/* 0x0E Transmit control */
-	_u16		rxcontrol;		/* 0x10 Receive control */
+typedef struct _RUP {
+	_u16 txpkt;		/* 0x00 Outgoing packet */
+	_u16 rxpkt;		/* 0x02 ncoming packet */
+	_u16 link;		/* 0x04 Which link to send packet down ? */
+	_u8 rup_dest_unit[2];	/* 0x06 Destination Unit */
+	_u16 handshake;		/* 0x08 Handshaking */
+	_u16 timeout;		/* 0x0A Timeout */
+	_u16 status;		/* 0x0C Status */
+	_u16 txcontrol;		/* 0x0E Transmit control */
+	_u16 rxcontrol;		/* 0x10 Receive control */
 
 } RUP;
 
 /* Same thing again, but defined as offsets... */
 
-#define	RUP_txpkt		0x00		/* 0x00 Outgoing packet */
-#define	RUP_rxpkt		0x02		/* 0x02 Incoming packet */
-#define	RUP_link		0x04		/* 0x04 Which link to send packet down ? */
-#define	RUP_rup_dest_unit	0x06		/* 0x06 Destination Unit */
-#define	RUP_handshake		0x08		/* 0x08 Handshaking */
-#define	RUP_timeout		0x0A		/* 0x0A Timeout */
-#define	RUP_status		0x0C		/* 0x0C Status */
-#define	RUP_txcontrol		0x0E		/* 0x0E Transmit control */
-#define	RUP_rxcontrol		0x10		/* 0x10 Receive control */
-#define	sizeof_RUP		0x12		/* structure size = 0x12 */
+#define	RUP_txpkt		0x00	/* 0x00 Outgoing packet */
+#define	RUP_rxpkt		0x02	/* 0x02 Incoming packet */
+#define	RUP_link		0x04	/* 0x04 Which link to send packet down ? */
+#define	RUP_rup_dest_unit	0x06	/* 0x06 Destination Unit */
+#define	RUP_handshake		0x08	/* 0x08 Handshaking */
+#define	RUP_timeout		0x0A	/* 0x0A Timeout */
+#define	RUP_status		0x0C	/* 0x0C Status */
+#define	RUP_txcontrol		0x0E	/* 0x0E Transmit control */
+#define	RUP_rxcontrol		0x10	/* 0x10 Receive control */
+#define	sizeof_RUP		0x12	/* structure size = 0x12 */
 
 #define MAX_RUP			16
 
 /* RUP.txcontrol definitions... */
-#define	TX_RUP_INACTIVE		0		/* Nothing to transmit */
-#define	TX_PACKET_READY		1		/* Transmit packet ready */
-#define	TX_LOCK_RUP		2		/* Transmit side locked */
+#define	TX_RUP_INACTIVE		0	/* Nothing to transmit */
+#define	TX_PACKET_READY		1	/* Transmit packet ready */
+#define	TX_LOCK_RUP		2	/* Transmit side locked */
 
 /* RUP.txcontrol definitions... */
-#define	RX_RUP_INACTIVE		0		/* Nothing received */
-#define	RX_PACKET_READY		1		/* Packet received */
+#define	RX_RUP_INACTIVE		0	/* Nothing received */
+#define	RX_PACKET_READY		1	/* Packet received */
 
-#define	RUP_NO_OWNER		0xFF		/* RUP not owned by any process */
+#define	RUP_NO_OWNER		0xFF	/* RUP not owned by any process */
 
 /*****************************************************************************
 **********************************         ***********************************
@@ -234,52 +232,51 @@
    to the system and there is normally an array of MAX_PHBS (=128) structures
    in a host card, defined by PARM_MAP->phb_ptr and PARM_MAP->phb_num_ptr. */
 
-typedef	struct	_PHB
-{
-	_u16		source;			/* 0x00 Location of the PHB in the host card */
-	_u16		handshake;		/* 0x02 Used to manage receive packet flow control */
-	_u16		status;			/* 0x04 Internal port transmit/receive status */
-	_u16		timeout;		/* 0x06 Time period to wait for an ACK */
-	_u16		link;			/* 0x08 The host link associated with the PHB */
-	_u16		destination;		/* 0x0A Location of the remote port on the network */
+typedef struct _PHB {
+	_u16 source;		/* 0x00 Location of the PHB in the host card */
+	_u16 handshake;		/* 0x02 Used to manage receive packet flow control */
+	_u16 status;		/* 0x04 Internal port transmit/receive status */
+	_u16 timeout;		/* 0x06 Time period to wait for an ACK */
+	_u16 link;		/* 0x08 The host link associated with the PHB */
+	_u16 destination;	/* 0x0A Location of the remote port on the network */
 
-	_u16		tx_start;		/* 0x0C first entry in the packet array for transmit packets */
-	_u16		tx_end;			/* 0x0E last entry in the packet array for transmit packets */
-	_u16		tx_add;			/* 0x10 position in the packet array for new transmit packets */
-	_u16		tx_remove;		/* 0x12 current position in the packet pointer array */
+	_u16 tx_start;		/* 0x0C first entry in the packet array for transmit packets */
+	_u16 tx_end;		/* 0x0E last entry in the packet array for transmit packets */
+	_u16 tx_add;		/* 0x10 position in the packet array for new transmit packets */
+	_u16 tx_remove;		/* 0x12 current position in the packet pointer array */
 
-	_u16		rx_start;		/* 0x14 first entry in the packet array for receive packets */
-	_u16		rx_end;			/* 0x16 last entry in the packet array for receive packets */
-	_u16		rx_add;			/* 0x18 position in the packet array for new receive packets */
-	_u16		rx_remove;		/* 0x1A current position in the packet pointer array */
+	_u16 rx_start;		/* 0x14 first entry in the packet array for receive packets */
+	_u16 rx_end;		/* 0x16 last entry in the packet array for receive packets */
+	_u16 rx_add;		/* 0x18 position in the packet array for new receive packets */
+	_u16 rx_remove;		/* 0x1A current position in the packet pointer array */
 
 } PHB;
 
 /* Same thing again, but defined as offsets... */
 
-#define	PHB_source		0x00		/* 0x00 Location of the PHB in the host card */
-#define	PHB_handshake		0x02		/* 0x02 Used to manage receive packet flow control */
-#define	PHB_status		0x04		/* 0x04 Internal port transmit/receive status */
-#define	PHB_timeout		0x06		/* 0x06 Time period to wait for an ACK */
-#define	PHB_link		0x08		/* 0x08 The host link associated with the PHB */
-#define	PHB_destination		0x0A		/* 0x0A Location of the remote port on the network */
-#define	PHB_tx_start		0x0C		/* 0x0C first entry in the packet array for transmit packets */
-#define	PHB_tx_end		0x0E		/* 0x0E last entry in the packet array for transmit packets */
-#define	PHB_tx_add		0x10		/* 0x10 position in the packet array for new transmit packets */
-#define	PHB_tx_remove		0x12		/* 0x12 current position in the packet pointer array */
-#define	PHB_rx_start		0x14		/* 0x14 first entry in the packet array for receive packets */
-#define	PHB_rx_end		0x16		/* 0x16 last entry in the packet array for receive packets */
-#define	PHB_rx_add		0x18		/* 0x18 position in the packet array for new receive packets */
-#define	PHB_rx_remove		0x1A		/* 0x1A current position in the packet pointer array */
-#define	sizeof_PHB		0x1C		/* structure size = 0x1C */
+#define	PHB_source		0x00	/* 0x00 Location of the PHB in the host card */
+#define	PHB_handshake		0x02	/* 0x02 Used to manage receive packet flow control */
+#define	PHB_status		0x04	/* 0x04 Internal port transmit/receive status */
+#define	PHB_timeout		0x06	/* 0x06 Time period to wait for an ACK */
+#define	PHB_link		0x08	/* 0x08 The host link associated with the PHB */
+#define	PHB_destination		0x0A	/* 0x0A Location of the remote port on the network */
+#define	PHB_tx_start		0x0C	/* 0x0C first entry in the packet array for transmit packets */
+#define	PHB_tx_end		0x0E	/* 0x0E last entry in the packet array for transmit packets */
+#define	PHB_tx_add		0x10	/* 0x10 position in the packet array for new transmit packets */
+#define	PHB_tx_remove		0x12	/* 0x12 current position in the packet pointer array */
+#define	PHB_rx_start		0x14	/* 0x14 first entry in the packet array for receive packets */
+#define	PHB_rx_end		0x16	/* 0x16 last entry in the packet array for receive packets */
+#define	PHB_rx_add		0x18	/* 0x18 position in the packet array for new receive packets */
+#define	PHB_rx_remove		0x1A	/* 0x1A current position in the packet pointer array */
+#define	sizeof_PHB		0x1C	/* structure size = 0x1C */
 
 /* PHB.handshake definitions... */
-#define	PHB_HANDSHAKE_SET	0x0001		/* Set by LRT */
-#define	PHB_HANDSHAKE_RESET	0x0002		/* Set by ISR / driver */
+#define	PHB_HANDSHAKE_SET	0x0001	/* Set by LRT */
+#define	PHB_HANDSHAKE_RESET	0x0002	/* Set by ISR / driver */
 #define	PHB_HANDSHAKE_FLAGS	(PHB_HANDSHAKE_RESET|PHB_HANDSHAKE_SET)
 						/* Reset by ltt */
 
-#define	MAX_PHB			128		/* range 0-127 */
+#define	MAX_PHB			128	/* range 0-127 */
 
 /*****************************************************************************
 **********************************         ***********************************
@@ -291,86 +288,85 @@
    and there is normally an array of MAX_LINKS (=4) structures in a host card,
    defined by PARM_MAP->link_str_ptr. */
 
-typedef	struct	_LPB
-{
-	_u16		link_number;		/* 0x00 Link Number */
-	_u16		in_ch;			/* 0x02 Link In Channel */
-	_u16		out_ch;			/* 0x04 Link Out Channel */
-	_u8		attached_serial[4];	/* 0x06 Attached serial number */
-	_u8		attached_host_serial[4];/* 0x0A Serial number of Host who booted other end */
-	_u16		descheduled;		/* 0x0E Currently Descheduled */
-	_u16		state;			/* 0x10 Current state */
-	_u16		send_poll;		/* 0x12 Send a Poll Packet */
-	_u16		ltt_p;			/* 0x14 Process Descriptor */
-	_u16		lrt_p;			/* 0x16 Process Descriptor */
-	_u16		lrt_status;		/* 0x18 Current lrt status */
-	_u16		ltt_status;		/* 0x1A Current ltt status */
-	_u16		timeout;		/* 0x1C Timeout value */
-	_u16		topology;		/* 0x1E Topology bits */
-	_u16		mon_ltt;		/* 0x20 */
-	_u16		mon_lrt;		/* 0x22 */
-	_u16		num_pkts;		/* 0x24 */
-	_u16		add_packet_list;	/* 0x26 Add packets to here */
-	_u16		remove_packet_list;	/* 0x28 Send packets from here */
+typedef struct _LPB {
+	_u16 link_number;	/* 0x00 Link Number */
+	_u16 in_ch;		/* 0x02 Link In Channel */
+	_u16 out_ch;		/* 0x04 Link Out Channel */
+	_u8 attached_serial[4];	/* 0x06 Attached serial number */
+	_u8 attached_host_serial[4];	/* 0x0A Serial number of Host who booted other end */
+	_u16 descheduled;	/* 0x0E Currently Descheduled */
+	_u16 state;		/* 0x10 Current state */
+	_u16 send_poll;		/* 0x12 Send a Poll Packet */
+	_u16 ltt_p;		/* 0x14 Process Descriptor */
+	_u16 lrt_p;		/* 0x16 Process Descriptor */
+	_u16 lrt_status;	/* 0x18 Current lrt status */
+	_u16 ltt_status;	/* 0x1A Current ltt status */
+	_u16 timeout;		/* 0x1C Timeout value */
+	_u16 topology;		/* 0x1E Topology bits */
+	_u16 mon_ltt;		/* 0x20 */
+	_u16 mon_lrt;		/* 0x22 */
+	_u16 num_pkts;		/* 0x24 */
+	_u16 add_packet_list;	/* 0x26 Add packets to here */
+	_u16 remove_packet_list;	/* 0x28 Send packets from here */
 
-	_u16		lrt_fail_chan;		/* 0x2A Lrt's failure channel */
-	_u16		ltt_fail_chan;		/* 0x2C Ltt's failure channel */
+	_u16 lrt_fail_chan;	/* 0x2A Lrt's failure channel */
+	_u16 ltt_fail_chan;	/* 0x2C Ltt's failure channel */
 
-	RUP		rup;			/* 0x2E RUP structure for HOST to driver comms */
-	RUP		link_rup;		/* 0x40 RUP for the link (POLL, topology etc.) */
-	_u16		attached_link;		/* 0x52 Number of attached link */
-	_u16		csum_errors;		/* 0x54 csum errors */
-	_u16		num_disconnects;	/* 0x56 number of disconnects */
-	_u16		num_sync_rcvd;		/* 0x58 # sync's received */
-	_u16		num_sync_rqst;		/* 0x5A # sync requests */
-	_u16		num_tx;			/* 0x5C Num pkts sent */
-	_u16		num_rx;			/* 0x5E Num pkts received */
-	_u16		module_attached;	/* 0x60 Module tpyes of attached */
-	_u16		led_timeout;		/* 0x62 LED timeout */
-	_u16		first_port;		/* 0x64 First port to service */
-	_u16		last_port;		/* 0x66 Last port to service */
+	RUP rup;		/* 0x2E RUP structure for HOST to driver comms */
+	RUP link_rup;		/* 0x40 RUP for the link (POLL, topology etc.) */
+	_u16 attached_link;	/* 0x52 Number of attached link */
+	_u16 csum_errors;	/* 0x54 csum errors */
+	_u16 num_disconnects;	/* 0x56 number of disconnects */
+	_u16 num_sync_rcvd;	/* 0x58 # sync's received */
+	_u16 num_sync_rqst;	/* 0x5A # sync requests */
+	_u16 num_tx;		/* 0x5C Num pkts sent */
+	_u16 num_rx;		/* 0x5E Num pkts received */
+	_u16 module_attached;	/* 0x60 Module tpyes of attached */
+	_u16 led_timeout;	/* 0x62 LED timeout */
+	_u16 first_port;	/* 0x64 First port to service */
+	_u16 last_port;		/* 0x66 Last port to service */
 
 } LPB;
 
 /* Same thing again, but defined as offsets... */
 
-#define	LPB_link_number		0x00		/* 0x00 Link Number */
-#define	LPB_in_ch		0x02		/* 0x02 Link In Channel */
-#define	LPB_out_ch		0x04		/* 0x04 Link Out Channel */
-#define	LPB_attached_serial	0x06		/* 0x06 Attached serial number */
-#define	LPB_attached_host_serial 0x0A		/* 0x0A Serial number of Host who booted other end */
-#define	LPB_descheduled		0x0E		/* 0x0E Currently Descheduled */
-#define	LPB_state		0x10		/* 0x10 Current state */
-#define	LPB_send_poll		0x12		/* 0x12 Send a Poll Packet */
-#define	LPB_ltt_p		0x14		/* 0x14 Process Descriptor */
-#define	LPB_lrt_p		0x16		/* 0x16 Process Descriptor */
-#define	LPB_lrt_status		0x18		/* 0x18 Current lrt status */
-#define	LPB_ltt_status		0x1A		/* 0x1A Current ltt status */
-#define	LPB_timeout		0x1C		/* 0x1C Timeout value */
-#define	LPB_topology		0x1E		/* 0x1E Topology bits */
-#define	LPB_mon_ltt		0x20		/* 0x20 */
-#define	LPB_mon_lrt		0x22		/* 0x22 */
-#define	LPB_num_pkts		0x24		/* 0x24 */
-#define	LPB_add_packet_list	0x26		/* 0x26 Add packets to here */
-#define	LPB_remove_packet_list	0x28		/* 0x28 Send packets from here */
-#define	LPB_lrt_fail_chan	0x2A		/* 0x2A Lrt's failure channel */
-#define	LPB_ltt_fail_chan	0x2C		/* 0x2C Ltt's failure channel */
-#define	LPB_rup			0x2E		/* 0x2E RUP structure for HOST to driver comms */
-#define	LPB_link_rup		0x40		/* 0x40 RUP for the link (POLL, topology etc.) */
-#define	LPB_attached_link	0x52		/* 0x52 Number of attached link */
-#define	LPB_csum_errors		0x54		/* 0x54 csum errors */
-#define	LPB_num_disconnects	0x56		/* 0x56 number of disconnects */
-#define	LPB_num_sync_rcvd	0x58		/* 0x58 # sync's received */
-#define	LPB_num_sync_rqst	0x5A		/* 0x5A # sync requests */
-#define	LPB_num_tx		0x5C		/* 0x5C Num pkts sent */
-#define	LPB_num_rx		0x5E		/* 0x5E Num pkts received */
-#define	LPB_module_attached	0x60		/* 0x60 Module tpyes of attached */
-#define	LPB_led_timeout		0x62		/* 0x62 LED timeout */
-#define	LPB_first_port		0x64		/* 0x64 First port to service */
-#define	LPB_last_port		0x66		/* 0x66 Last port to service */
-#define	sizeof_LPB		0x68		/* structure size = 0x68 */
+#define	LPB_link_number		0x00	/* 0x00 Link Number */
+#define	LPB_in_ch		0x02	/* 0x02 Link In Channel */
+#define	LPB_out_ch		0x04	/* 0x04 Link Out Channel */
+#define	LPB_attached_serial	0x06	/* 0x06 Attached serial number */
+#define	LPB_attached_host_serial 0x0A	/* 0x0A Serial number of Host who booted other end */
+#define	LPB_descheduled		0x0E	/* 0x0E Currently Descheduled */
+#define	LPB_state		0x10	/* 0x10 Current state */
+#define	LPB_send_poll		0x12	/* 0x12 Send a Poll Packet */
+#define	LPB_ltt_p		0x14	/* 0x14 Process Descriptor */
+#define	LPB_lrt_p		0x16	/* 0x16 Process Descriptor */
+#define	LPB_lrt_status		0x18	/* 0x18 Current lrt status */
+#define	LPB_ltt_status		0x1A	/* 0x1A Current ltt status */
+#define	LPB_timeout		0x1C	/* 0x1C Timeout value */
+#define	LPB_topology		0x1E	/* 0x1E Topology bits */
+#define	LPB_mon_ltt		0x20	/* 0x20 */
+#define	LPB_mon_lrt		0x22	/* 0x22 */
+#define	LPB_num_pkts		0x24	/* 0x24 */
+#define	LPB_add_packet_list	0x26	/* 0x26 Add packets to here */
+#define	LPB_remove_packet_list	0x28	/* 0x28 Send packets from here */
+#define	LPB_lrt_fail_chan	0x2A	/* 0x2A Lrt's failure channel */
+#define	LPB_ltt_fail_chan	0x2C	/* 0x2C Ltt's failure channel */
+#define	LPB_rup			0x2E	/* 0x2E RUP structure for HOST to driver comms */
+#define	LPB_link_rup		0x40	/* 0x40 RUP for the link (POLL, topology etc.) */
+#define	LPB_attached_link	0x52	/* 0x52 Number of attached link */
+#define	LPB_csum_errors		0x54	/* 0x54 csum errors */
+#define	LPB_num_disconnects	0x56	/* 0x56 number of disconnects */
+#define	LPB_num_sync_rcvd	0x58	/* 0x58 # sync's received */
+#define	LPB_num_sync_rqst	0x5A	/* 0x5A # sync requests */
+#define	LPB_num_tx		0x5C	/* 0x5C Num pkts sent */
+#define	LPB_num_rx		0x5E	/* 0x5E Num pkts received */
+#define	LPB_module_attached	0x60	/* 0x60 Module tpyes of attached */
+#define	LPB_led_timeout		0x62	/* 0x62 LED timeout */
+#define	LPB_first_port		0x64	/* 0x64 First port to service */
+#define	LPB_last_port		0x66	/* 0x66 Last port to service */
+#define	sizeof_LPB		0x68	/* structure size = 0x68 */
 
-#define	LINKS_PER_UNIT		4		/* number of links from a host */
+#define	LINKS_PER_UNIT		4	/* number of links from a host */
 
 /*****************************************************************************
 ********************************               *******************************
@@ -380,17 +376,16 @@
 
 /* Used to overlay packet headers when allocating/freeing packets from the free list */
 
-typedef	struct	_FREE_LIST
-{
-	_u16		next;			/* 0x00 offset of next list item */
-	_u16		prev;			/* 0x02 offset of previous list item */
+typedef struct _FREE_LIST {
+	_u16 next;		/* 0x00 offset of next list item */
+	_u16 prev;		/* 0x02 offset of previous list item */
 
 } FREE_LIST;
 
 /* Same thing again, but defined as offsets... */
 
-#define	FL_next			0x00		/* 0x00 offset of next list item */
-#define	FL_prev			0x02		/* 0x02 offset of previous list item */
+#define	FL_next			0x00	/* 0x00 offset of next list item */
+#define	FL_prev			0x02	/* 0x02 offset of previous list item */
 
 /*****************************************************************************
 **********************************         ***********************************
@@ -401,32 +396,31 @@
 /* The PKT is the main unit of communication between Host Cards and RTAs across
    the RIO network.  */
 
-#define PKT_MAX_DATA_LEN   72			/* Size of packet data */
+#define PKT_MAX_DATA_LEN   72	/* Size of packet data */
 
-typedef	struct	_PKT
-{
-	_u8		dest_unit;		/* 0x00 Destination Unit Id */
-	_u8		dest_port;		/* 0x01 Destination Port */
-	_u8		src_unit;		/* 0x02 Source Unit Id */
-	_u8		src_port;		/* 0x03 Source Port */
-	_u8		len;			/* 0x04 Length (in bytes) of data field */
-	_u8		control;		/* 0x05 */
-	_u8		data[PKT_MAX_DATA_LEN];	/* 0x06 Actual data */
-	_u16		csum;			/* 0x4E C-SUM */
+typedef struct _PKT {
+	_u8 dest_unit;		/* 0x00 Destination Unit Id */
+	_u8 dest_port;		/* 0x01 Destination Port */
+	_u8 src_unit;		/* 0x02 Source Unit Id */
+	_u8 src_port;		/* 0x03 Source Port */
+	_u8 len;		/* 0x04 Length (in bytes) of data field */
+	_u8 control;		/* 0x05 */
+	_u8 data[PKT_MAX_DATA_LEN];	/* 0x06 Actual data */
+	_u16 csum;		/* 0x4E C-SUM */
 
 } PKT;
 
 /* Same thing again, but defined as offsets... */
 
-#define	PKT_dest_unit		0x00		/* 0x00 Destination Unit Id */
-#define	PKT_dest_port		0x01		/* 0x01 Destination Port */
-#define	PKT_src_unit		0x02		/* 0x02 Source Unit Id */
-#define	PKT_src_port		0x03		/* 0x03 Source Port */
-#define	PKT_len			0x04		/* 0x04 Length (in bytes) of data field */
-#define	PKT_control		0x05		/* 0x05 */
-#define	PKT_data		0x06		/* 0x06 Actual data */
-#define	PKT_csum		0x4E		/* 0x4E C-SUM */
-#define	sizeof_PKT		0x50		/* structure size = 0x50 */
+#define	PKT_dest_unit		0x00	/* 0x00 Destination Unit Id */
+#define	PKT_dest_port		0x01	/* 0x01 Destination Port */
+#define	PKT_src_unit		0x02	/* 0x02 Source Unit Id */
+#define	PKT_src_port		0x03	/* 0x03 Source Port */
+#define	PKT_len			0x04	/* 0x04 Length (in bytes) of data field */
+#define	PKT_control		0x05	/* 0x05 */
+#define	PKT_data		0x06	/* 0x06 Actual data */
+#define	PKT_csum		0x4E	/* 0x4E C-SUM */
+#define	sizeof_PKT		0x50	/* structure size = 0x50 */
 
 /* PKT.len definitions... */
 #define	PKT_CMD_BIT		0x80
@@ -449,38 +443,38 @@
 /* The following definitions and structures define the control packets sent
    between the driver and RIO Ports, RTAs and Host Cards. */
 
-#define	PRE_EMPTIVE		0x80			/* Pre-emptive command (sent via port's RUP) */
+#define	PRE_EMPTIVE		0x80	/* Pre-emptive command (sent via port's RUP) */
 
 /* "in-band" and "pre-emptive" port commands... */
-#define	OPEN			0x00			/* Driver->RIO Open a port */
-#define	CONFIG			0x01			/* Driver->RIO Configure a port */
-#define	MOPEN			0x02			/* Driver->RIO Modem open (wait for DCD) */
-#define	CLOSE			0x03			/* Driver->RIO Close a port */
+#define	OPEN			0x00	/* Driver->RIO Open a port */
+#define	CONFIG			0x01	/* Driver->RIO Configure a port */
+#define	MOPEN			0x02	/* Driver->RIO Modem open (wait for DCD) */
+#define	CLOSE			0x03	/* Driver->RIO Close a port */
 #define	WFLUSH			(0x04|PRE_EMPTIVE)	/* Driver->RIO Write flush */
 #define	RFLUSH			(0x05|PRE_EMPTIVE)	/* Driver->RIO Read flush */
 #define	RESUME			(0x06|PRE_EMPTIVE)	/* Driver->RIO Behave as if XON received */
-#define	SBREAK			0x07			/* Driver->RIO Start break */
-#define	EBREAK			0x08			/* Driver->RIO End break */
+#define	SBREAK			0x07	/* Driver->RIO Start break */
+#define	EBREAK			0x08	/* Driver->RIO End break */
 #define	SUSPEND			(0x09|PRE_EMPTIVE)	/* Driver->RIO Behave as if XOFF received */
 #define	FCLOSE			(0x0A|PRE_EMPTIVE)	/* Driver->RIO Force close */
-#define	XPRINT			0x0B			/* Driver->RIO Xprint packet */
+#define	XPRINT			0x0B	/* Driver->RIO Xprint packet */
 #define	MBIS			(0x0C|PRE_EMPTIVE)	/* Driver->RIO Set modem lines */
 #define	MBIC			(0x0D|PRE_EMPTIVE)	/* Driver->RIO Clear modem lines */
 #define	MSET			(0x0E|PRE_EMPTIVE)	/* Driver->RIO Set modem lines */
-#define	PCLOSE			0x0F			/* Driver->RIO Pseudo close */
+#define	PCLOSE			0x0F	/* Driver->RIO Pseudo close */
 #define	MGET			(0x10|PRE_EMPTIVE)	/* Driver->RIO Force update of modem status */
 #define	MEMDUMP			(0x11|PRE_EMPTIVE)	/* Driver->RIO DEBUG request for RTA memory */
 #define	READ_REGISTER		(0x12|PRE_EMPTIVE)	/* Driver->RIO DEBUG read CD1400 register */
 
 /* Remote Unit Port (RUP) packet definitions... (specified in PKT.dest_unit and PKT.src_unit) */
-#define	SYNC_RUP		0xFF			/* Download internal */
-#define	COMMAND_RUP		0xFE			/* Command ack/status */
-#define	ERROR_RUP		0xFD			/* Download internal */
-#define	POLL_RUP		0xFC			/* Download internal */
-#define	BOOT_RUP		0xFB			/* Used to boot RTAs */
-#define	ROUTE_RUP		0xFA			/* Used to specify routing/topology */
-#define	STATUS_RUP		0xF9			/* Not used */
-#define	POWER_RUP		0xF8			/* Download internal */
+#define	SYNC_RUP		0xFF	/* Download internal */
+#define	COMMAND_RUP		0xFE	/* Command ack/status */
+#define	ERROR_RUP		0xFD	/* Download internal */
+#define	POLL_RUP		0xFC	/* Download internal */
+#define	BOOT_RUP		0xFB	/* Used to boot RTAs */
+#define	ROUTE_RUP		0xFA	/* Used to specify routing/topology */
+#define	STATUS_RUP		0xF9	/* Not used */
+#define	POWER_RUP		0xF8	/* Download internal */
 
 /* COMMAND_RUP definitions... */
 #define	COMPLETE		(0x20|PRE_EMPTIVE)	/* RIO->Driver Command complete */
@@ -488,24 +482,24 @@
 #define	MODEM_STATUS		(0x22|PRE_EMPTIVE)	/* RIO->Driver Modem status change */
 
 /* BOOT_RUP definitions... */
-#define	BOOT_REQUEST		0x00			/* RIO->Driver Request for boot */
-#define	BOOT_ABORT		0x01			/* Driver->RIO Abort a boot */
-#define	BOOT_SEQUENCE		0x02			/* Driver->RIO Packet with firmware details */
-#define	BOOT_COMPLETED		0x03			/* RIO->Driver Boot completed */
-#define IFOAD			0x2F			/* Driver->RIO Shutdown/Reboot RTA (Fall Over And Die) */
-#define	IDENTIFY		0x30			/* Driver->RIO Identify RTA */
-#define	ZOMBIE			0x31			/* Driver->RIO Shutdown/Flash LEDs */
-#define	UFOAD			0x32			/* Driver->RIO Shutdown/Reboot neighbouring RTA */
-#define IWAIT			0x33			/* Driver->RIO Pause booting process */
+#define	BOOT_REQUEST		0x00	/* RIO->Driver Request for boot */
+#define	BOOT_ABORT		0x01	/* Driver->RIO Abort a boot */
+#define	BOOT_SEQUENCE		0x02	/* Driver->RIO Packet with firmware details */
+#define	BOOT_COMPLETED		0x03	/* RIO->Driver Boot completed */
+#define IFOAD			0x2F	/* Driver->RIO Shutdown/Reboot RTA (Fall Over And Die) */
+#define	IDENTIFY		0x30	/* Driver->RIO Identify RTA */
+#define	ZOMBIE			0x31	/* Driver->RIO Shutdown/Flash LEDs */
+#define	UFOAD			0x32	/* Driver->RIO Shutdown/Reboot neighbouring RTA */
+#define IWAIT			0x33	/* Driver->RIO Pause booting process */
 
 /* ROUTE_RUP definitions... */
-#define	ROUTE_REQUEST		0x00			/* RIO->Driver Request an ID */
-#define	ROUTE_FOAD		0x01			/* Driver->RIO Shutdown/reboot RTA */
-#define	ROUTE_ALREADY		0x02			/* Driver->RIO Not used */
-#define	ROUTE_USED		0x03			/* Driver->RIO Not used */
-#define	ROUTE_ALLOCATE		0x04			/* Driver->RIO Allocate RTA RUP numbers */
-#define	ROUTE_REQ_TOP		0x05			/* Driver->RIO Not used */
-#define ROUTE_TOPOLOGY		0x06			/* RIO->Driver Route/Topology status */
+#define	ROUTE_REQUEST		0x00	/* RIO->Driver Request an ID */
+#define	ROUTE_FOAD		0x01	/* Driver->RIO Shutdown/reboot RTA */
+#define	ROUTE_ALREADY		0x02	/* Driver->RIO Not used */
+#define	ROUTE_USED		0x03	/* Driver->RIO Not used */
+#define	ROUTE_ALLOCATE		0x04	/* Driver->RIO Allocate RTA RUP numbers */
+#define	ROUTE_REQ_TOP		0x05	/* Driver->RIO Not used */
+#define ROUTE_TOPOLOGY		0x06	/* RIO->Driver Route/Topology status */
 
 /*****************************************************************************
 **********************************          **********************************
@@ -518,89 +512,89 @@
    Sent to open a port. 
    Structure of configuration info used with OPEN, CONFIG and MOPEN packets... */
 
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
-#define	PKT_Cor1		(PKT_Data+1)		/* Channel Option Register 1 */
-#define	PKT_Cor2		(PKT_Data+2)		/* Channel Option Register 2 */
-#define	PKT_Cor4		(PKT_Data+3)		/* Channel Option Register 4 */
-#define	PKT_Cor5		(PKT_Data+4)		/* Channel Option Register 5 */
-#define	PKT_TxXon		(PKT_Data+5)		/* Transmit XON character */
-#define	PKT_TxXoff		(PKT_Data+6)		/* Transmit XOFF character */
-#define	PKT_RxXon		(PKT_Data+7)		/* Receive XON character */
-#define	PKT_RxXoff		(PKT_Data+8)		/* Receive XOFF character */
-#define	PKT_Lnext		(PKT_Data+9)		/* Lnext character */
-#define	PKT_TxBaud		(PKT_Data+10)		/* Transmit baud rate */
-#define	PKT_RxBaud		(PKT_Data+11)		/* Receive baud rate */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
+#define	PKT_Cor1		(PKT_Data+1)	/* Channel Option Register 1 */
+#define	PKT_Cor2		(PKT_Data+2)	/* Channel Option Register 2 */
+#define	PKT_Cor4		(PKT_Data+3)	/* Channel Option Register 4 */
+#define	PKT_Cor5		(PKT_Data+4)	/* Channel Option Register 5 */
+#define	PKT_TxXon		(PKT_Data+5)	/* Transmit XON character */
+#define	PKT_TxXoff		(PKT_Data+6)	/* Transmit XOFF character */
+#define	PKT_RxXon		(PKT_Data+7)	/* Receive XON character */
+#define	PKT_RxXoff		(PKT_Data+8)	/* Receive XOFF character */
+#define	PKT_Lnext		(PKT_Data+9)	/* Lnext character */
+#define	PKT_TxBaud		(PKT_Data+10)	/* Transmit baud rate */
+#define	PKT_RxBaud		(PKT_Data+11)	/* Receive baud rate */
 
 /* COR1 definitions... */
-#define	COR1_PARITY		0xE0			/* Parity mask */
-#define	COR1_NONE		0x00			/* No parity */
-#define	COR1_SPACE		0x20			/* Space parity */
-#define	COR1_EVEN		0x40			/* Even parity */
-#define	COR1_MARK		0xA0			/* Mark parity */
-#define	COR1_ODD		0xC0			/* Odd parity */
+#define	COR1_PARITY		0xE0	/* Parity mask */
+#define	COR1_NONE		0x00	/* No parity */
+#define	COR1_SPACE		0x20	/* Space parity */
+#define	COR1_EVEN		0x40	/* Even parity */
+#define	COR1_MARK		0xA0	/* Mark parity */
+#define	COR1_ODD		0xC0	/* Odd parity */
 
-#define	COR1_STOPBITS		0x0C			/* Stop bits mask */
-#define	COR1_STOP1		0x00			/* 1 stop bit */
-#define	COR1_STOP1_5		0x04			/* 1.5 stop bits */
-#define	COR1_STOP2		0x08			/* 2 stop bits */
+#define	COR1_STOPBITS		0x0C	/* Stop bits mask */
+#define	COR1_STOP1		0x00	/* 1 stop bit */
+#define	COR1_STOP1_5		0x04	/* 1.5 stop bits */
+#define	COR1_STOP2		0x08	/* 2 stop bits */
 
-#define	COR1_DATABITS		0x03			/* Data bits mask */
-#define	COR1_DATA5		0x00			/* 5 data bits */
-#define	COR1_DATA6		0x01			/* 6 data bits */
-#define	COR1_DATA7		0x02			/* 7 data bits */
-#define	COR1_DATA8		0x03			/* 8 data bits */
+#define	COR1_DATABITS		0x03	/* Data bits mask */
+#define	COR1_DATA5		0x00	/* 5 data bits */
+#define	COR1_DATA6		0x01	/* 6 data bits */
+#define	COR1_DATA7		0x02	/* 7 data bits */
+#define	COR1_DATA8		0x03	/* 8 data bits */
 
 /* COR2 definitions... */
-#define	COR2_XON_TXFLOW		0x40			/* XON/XOFF Transmit Flow */
-#define	COR2_XANY_TXFLOW	0xC0			/* XON/XANY Transmit Flow */
-#define	COR2_HUPCL		0x20			/* Hang Up On Close */
-#define	COR2_DSR_TXFLOW		0x08			/* DSR Transmit Flow Control */
-#define	COR2_RTS_RXFLOW		0x04			/* RTS Receive Flow Control */
-#define	COR2_CTS_TXFLOW		0x02			/* CTS Transmit Flow Control */
-#define	COR2_XON_RXFLOW		0x01			/* XON/XOFF Receive Flow */
+#define	COR2_XON_TXFLOW		0x40	/* XON/XOFF Transmit Flow */
+#define	COR2_XANY_TXFLOW	0xC0	/* XON/XANY Transmit Flow */
+#define	COR2_HUPCL		0x20	/* Hang Up On Close */
+#define	COR2_DSR_TXFLOW		0x08	/* DSR Transmit Flow Control */
+#define	COR2_RTS_RXFLOW		0x04	/* RTS Receive Flow Control */
+#define	COR2_CTS_TXFLOW		0x02	/* CTS Transmit Flow Control */
+#define	COR2_XON_RXFLOW		0x01	/* XON/XOFF Receive Flow */
 
 /* COR4 definition... */
-#define	COR4_IGNCR		0x80			/* Discard received CR */
-#define	COR4_ICRNL		0x40			/* Map received CR -> NL */
-#define	COR4_INLCR		0x20			/* Map received NL -> CR */
-#define	COR4_IGNBRK		0x10			/* Ignore Received Break */
-#define	COR4_NBRKINT		0x08			/* No interrupt on rx Break */
-#define	COR4_IGNPAR		0x04			/* ignore rx parity error chars */
-#define	COR4_PARMRK		0x02			/* Mark rx parity error chars */
-#define	COR4_RAISEMOD		0x01			/* Raise modem lines on !0 baud */
+#define	COR4_IGNCR		0x80	/* Discard received CR */
+#define	COR4_ICRNL		0x40	/* Map received CR -> NL */
+#define	COR4_INLCR		0x20	/* Map received NL -> CR */
+#define	COR4_IGNBRK		0x10	/* Ignore Received Break */
+#define	COR4_NBRKINT		0x08	/* No interrupt on rx Break */
+#define	COR4_IGNPAR		0x04	/* ignore rx parity error chars */
+#define	COR4_PARMRK		0x02	/* Mark rx parity error chars */
+#define	COR4_RAISEMOD		0x01	/* Raise modem lines on !0 baud */
 
 /* COR5 definitions... */
-#define	COR5_ISTRIP		0x80			/* Strip input chars to 7 bits */
-#define	COR5_LNE		0x40			/* Enable LNEXT processing */
-#define	COR5_CMOE		0x20			/* Match good & error characters */
-#define	COR5_TAB3		0x10			/* TAB3 mode */
-#define	COR5_TSTATE_ON		0x08			/* Enable tbusy/tstop monitoring */
-#define	COR5_TSTATE_OFF		0x04			/* Disable tbusy/tstop monitoring */
-#define	COR5_ONLCR		0x02			/* NL -> CR NL on output */
-#define	COR5_OCRNL		0x01			/* CR -> NL on output */
+#define	COR5_ISTRIP		0x80	/* Strip input chars to 7 bits */
+#define	COR5_LNE		0x40	/* Enable LNEXT processing */
+#define	COR5_CMOE		0x20	/* Match good & error characters */
+#define	COR5_TAB3		0x10	/* TAB3 mode */
+#define	COR5_TSTATE_ON		0x08	/* Enable tbusy/tstop monitoring */
+#define	COR5_TSTATE_OFF		0x04	/* Disable tbusy/tstop monitoring */
+#define	COR5_ONLCR		0x02	/* NL -> CR NL on output */
+#define	COR5_OCRNL		0x01	/* CR -> NL on output */
 
 /* RxBaud and TxBaud definitions... */
-#define	RIO_B0			0x00			/* RTS / DTR signals dropped */
-#define	RIO_B50			0x01			/* 50 baud */
-#define	RIO_B75			0x02			/* 75 baud */
-#define	RIO_B110		0x03			/* 110 baud */
-#define	RIO_B134		0x04			/* 134.5 baud */
-#define	RIO_B150		0x05			/* 150 baud */
-#define	RIO_B200		0x06			/* 200 baud */
-#define	RIO_B300		0x07			/* 300 baud */
-#define	RIO_B600		0x08			/* 600 baud */
-#define	RIO_B1200		0x09			/* 1200 baud */
-#define	RIO_B1800		0x0A			/* 1800 baud */
-#define	RIO_B2400		0x0B			/* 2400 baud */
-#define	RIO_B4800		0x0C			/* 4800 baud */
-#define	RIO_B9600		0x0D			/* 9600 baud */
-#define	RIO_B19200		0x0E			/* 19200 baud */
-#define	RIO_B38400		0x0F			/* 38400 baud */
-#define	RIO_B56000		0x10			/* 56000 baud */
-#define	RIO_B57600		0x11			/* 57600 baud */
-#define	RIO_B64000		0x12			/* 64000 baud */
-#define	RIO_B115200		0x13			/* 115200 baud */
-#define	RIO_B2000		0x14			/* 2000 baud */
+#define	RIO_B0			0x00	/* RTS / DTR signals dropped */
+#define	RIO_B50			0x01	/* 50 baud */
+#define	RIO_B75			0x02	/* 75 baud */
+#define	RIO_B110		0x03	/* 110 baud */
+#define	RIO_B134		0x04	/* 134.5 baud */
+#define	RIO_B150		0x05	/* 150 baud */
+#define	RIO_B200		0x06	/* 200 baud */
+#define	RIO_B300		0x07	/* 300 baud */
+#define	RIO_B600		0x08	/* 600 baud */
+#define	RIO_B1200		0x09	/* 1200 baud */
+#define	RIO_B1800		0x0A	/* 1800 baud */
+#define	RIO_B2400		0x0B	/* 2400 baud */
+#define	RIO_B4800		0x0C	/* 4800 baud */
+#define	RIO_B9600		0x0D	/* 9600 baud */
+#define	RIO_B19200		0x0E	/* 19200 baud */
+#define	RIO_B38400		0x0F	/* 38400 baud */
+#define	RIO_B56000		0x10	/* 56000 baud */
+#define	RIO_B57600		0x11	/* 57600 baud */
+#define	RIO_B64000		0x12	/* 64000 baud */
+#define	RIO_B115200		0x13	/* 115200 baud */
+#define	RIO_B2000		0x14	/* 2000 baud */
 
 /*****************************************************************************
 *********************************            *********************************
@@ -636,7 +630,7 @@
    No parameters.
  */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
 #endif
 /*****************************************************************************
 *********************************            *********************************
@@ -653,9 +647,9 @@
    write flushing previously started by a pre-emptive WFLUSH packet. (in-band)
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
 #endif
-#define	PKT_PhbNum		(PKT_Data+1)		/* Port number wrt RTA */
+#define	PKT_PhbNum		(PKT_Data+1)	/* Port number wrt RTA */
 
 /*****************************************************************************
 *********************************            *********************************
@@ -669,8 +663,8 @@
    packets of a port.
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
-#define	PKT_PhbNum		(PKT_Data+1)		/* Port number wrt RTA */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
+#define	PKT_PhbNum		(PKT_Data+1)	/* Port number wrt RTA */
 #endif
 
 /*****************************************************************************
@@ -685,8 +679,8 @@
    transmission of data if blocked by XOFF.  (as if XON had been received)
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
-#define	PKT_PhbNum		(PKT_Data+1)		/* Port number wrt RTA */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
+#define	PKT_PhbNum		(PKT_Data+1)	/* Port number wrt RTA */
 #endif
 
 /*****************************************************************************
@@ -707,9 +701,9 @@
    specified number of mS.
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
 #endif
-#define	PKT_BreakDelay		(PKT_Data+1)		/* Break delay in mS */
+#define	PKT_BreakDelay		(PKT_Data+1)	/* Break delay in mS */
 
 /*****************************************************************************
 *********************************            *********************************
@@ -736,8 +730,8 @@
    transmission of data.  (as if XOFF had been received)
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
-#define	PKT_PhbNum		(PKT_Data+1)		/* Port number wrt RTA */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
+#define	PKT_PhbNum		(PKT_Data+1)	/* Port number wrt RTA */
 #endif
 
 /*****************************************************************************
@@ -753,8 +747,8 @@
    modem signals if the COR5_HUPCL (Hang Up On Close) flag is set.
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
-#define	PKT_PhbNum		(PKT_Data+1)		/* Port number wrt RTA */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
+#define	PKT_PhbNum		(PKT_Data+1)	/* Port number wrt RTA */
 #endif
 
 /*****************************************************************************
@@ -774,8 +768,8 @@
    -	Transparent Print Stop Sequence.
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
-#define	PKT_PhbNum		(PKT_Data+1)		/* Port number wrt RTA */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
+#define	PKT_PhbNum		(PKT_Data+1)	/* Port number wrt RTA */
 #endif
 
 /*****************************************************************************
@@ -789,14 +783,14 @@
    MBIS is sent pre-emptively from the driver to set a port's modem signals.
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
-#define	PKT_PhbNum		(PKT_Data+1)		/* Port number wrt RTA */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
+#define	PKT_PhbNum		(PKT_Data+1)	/* Port number wrt RTA */
 #endif
-#define	PKT_ModemSet		(PKT_Data+4)		/* Modem set signals mask */
+#define	PKT_ModemSet		(PKT_Data+4)	/* Modem set signals mask */
 
 /* ModemSet definitions... */
-#define	MBIS_RTS		0x01			/* RTS modem signal */
-#define	MBIS_DTR		0x02			/* DTR modem signal */
+#define	MBIS_RTS		0x01	/* RTS modem signal */
+#define	MBIS_DTR		0x02	/* DTR modem signal */
 
 /*****************************************************************************
 **********************************          **********************************
@@ -808,16 +802,16 @@
 
    MBIC is sent pre-emptively from the driver to clear a port's modem signals.
    */
-#if 0   
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
-#define	PKT_PhbNum		(PKT_Data+1)		/* Port number wrt RTA */
+#if 0
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
+#define	PKT_PhbNum		(PKT_Data+1)	/* Port number wrt RTA */
 #endif
 
-#define	PKT_ModemClear		(PKT_Data+4)		/* Modem clear signals mask */
+#define	PKT_ModemClear		(PKT_Data+4)	/* Modem clear signals mask */
 
 /* ModemClear definitions... */
-#define	MBIC_RTS		0x01			/* RTS modem signal */
-#define	MBIC_DTR		0x02			/* DTR modem signal */
+#define	MBIC_RTS		0x01	/* RTS modem signal */
+#define	MBIC_DTR		0x02	/* DTR modem signal */
 
 /*****************************************************************************
 **********************************          **********************************
@@ -829,15 +823,15 @@
 
    MSET is sent pre-emptively from the driver to set/clear a port's modem signals. */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
-#define	PKT_PhbNum		(PKT_Data+1)		/* Port number wrt RTA */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
+#define	PKT_PhbNum		(PKT_Data+1)	/* Port number wrt RTA */
 #endif
 
-#define	PKT_ModemSet		(PKT_Data+4)		/* Modem set signals mask */
+#define	PKT_ModemSet		(PKT_Data+4)	/* Modem set signals mask */
 
 /* ModemSet definitions... */
-#define	MSET_RTS		0x01			/* RTS modem signal */
-#define	MSET_DTR		0x02			/* DTR modem signal */
+#define	MSET_RTS		0x01	/* RTS modem signal */
+#define	MSET_DTR		0x02	/* DTR modem signal */
 
 /*****************************************************************************
 *********************************            *********************************
@@ -853,7 +847,7 @@
    port's transmit / receive and modem signals will be left enabled and the
    port marked internally as Pseudo Closed. */
 
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
 
 /*****************************************************************************
 **********************************          **********************************
@@ -865,8 +859,8 @@
 
    MGET is sent pre-emptively from the driver to request the port's current modem signals. */
 
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
-#define	PKT_PhbNum		(PKT_Data+1)		/* Port number wrt RTA */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
+#define	PKT_PhbNum		(PKT_Data+1)	/* Port number wrt RTA */
 
 /*****************************************************************************
 *********************************             ********************************
@@ -880,11 +874,11 @@
    of the specified port's RTA address space.
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
 #endif
-#define	PKT_PhbNum		(PKT_Data+1)		/* Port number wrt RTA */
-#define	PKT_SubCmd		(PKT_Data+5)		/* Sub Command */
-#define	PKT_Address		(PKT_Data+6)		/* Requested address */
+#define	PKT_PhbNum		(PKT_Data+1)	/* Port number wrt RTA */
+#define	PKT_SubCmd		(PKT_Data+5)	/* Sub Command */
+#define	PKT_Address		(PKT_Data+6)	/* Requested address */
 
 /*****************************************************************************
 ******************************                   *****************************
@@ -898,11 +892,11 @@
    of the CD1400 register specified in address.
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
 #endif
-#define	PKT_PhbNum		(PKT_Data+1)		/* Port number wrt RTA */
-#define	PKT_SubCmd		(PKT_Data+5)		/* Sub Command */
-#define	PKT_Address		(PKT_Data+6)		/* Requested address */
+#define	PKT_PhbNum		(PKT_Data+1)	/* Port number wrt RTA */
+#define	PKT_SubCmd		(PKT_Data+5)	/* Sub Command */
+#define	PKT_Address		(PKT_Data+6)	/* Requested address */
 
 /*****************************************************************************
 ************************                            **************************
@@ -916,33 +910,33 @@
    packets, except MEMDUMP and READ_REGISTER.
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
 #endif
-#define	PKT_PhbNum		(PKT_Data+1)		/* Port number wrt RTA */
-#define	PKT_Cmd2		(PKT_Data+2)		/* Command code copy */
-#define	PKT_ModemStatus		(PKT_Data+3)		/* Modem signal status */
-#define	PKT_PortStatus		(PKT_Data+4)		/* Port signal status */
-#define	PKT_SubCmd		(PKT_Data+5)		/* Sub Command */
+#define	PKT_PhbNum		(PKT_Data+1)	/* Port number wrt RTA */
+#define	PKT_Cmd2		(PKT_Data+2)	/* Command code copy */
+#define	PKT_ModemStatus		(PKT_Data+3)	/* Modem signal status */
+#define	PKT_PortStatus		(PKT_Data+4)	/* Port signal status */
+#define	PKT_SubCmd		(PKT_Data+5)	/* Sub Command */
 
 /* ModemStatus definitions... */
-#define	MODEM_DSR		0x80			/* Data Set Ready modem state */
-#define	MODEM_CTS		0x40			/* Clear To Send modem state */
-#define	MODEM_RI		0x20			/* Ring Indicate modem state */
-#define	MODEM_CD		0x10			/* Carrier Detect modem state */
-#define	MODEM_TSTOP		0x08			/* Transmit Stopped state */
-#define	MODEM_TEMPTY		0x04			/* Transmit Empty state */
-#define	MODEM_DTR		0x02			/* DTR modem output state */
-#define	MODEM_RTS		0x01			/* RTS modem output state */
+#define	MODEM_DSR		0x80	/* Data Set Ready modem state */
+#define	MODEM_CTS		0x40	/* Clear To Send modem state */
+#define	MODEM_RI		0x20	/* Ring Indicate modem state */
+#define	MODEM_CD		0x10	/* Carrier Detect modem state */
+#define	MODEM_TSTOP		0x08	/* Transmit Stopped state */
+#define	MODEM_TEMPTY		0x04	/* Transmit Empty state */
+#define	MODEM_DTR		0x02	/* DTR modem output state */
+#define	MODEM_RTS		0x01	/* RTS modem output state */
 
 /* PortStatus definitions... */
-#define	PORT_ISOPEN		0x01			/* Port open ? */
-#define	PORT_HUPCL		0x02			/* Hangup on close? */
-#define	PORT_MOPENPEND		0x04			/* Modem open pending */
-#define	PORT_ISPARALLEL		0x08			/* Parallel port */
-#define	PORT_BREAK		0x10			/* Port on break */
-#define	PORT_STATUSPEND		0020			/* Status packet pending */
-#define	PORT_BREAKPEND		0x40			/* Break packet pending */
-#define	PORT_MODEMPEND		0x80			/* Modem status packet pending */
+#define	PORT_ISOPEN		0x01	/* Port open ? */
+#define	PORT_HUPCL		0x02	/* Hangup on close? */
+#define	PORT_MOPENPEND		0x04	/* Modem open pending */
+#define	PORT_ISPARALLEL		0x08	/* Parallel port */
+#define	PORT_BREAK		0x10	/* Port on break */
+#define	PORT_STATUSPEND		0020	/* Status packet pending */
+#define	PORT_BREAKPEND		0x40	/* Break packet pending */
+#define	PORT_MODEMPEND		0x80	/* Modem status packet pending */
 
 /*****************************************************************************
 ************************                            **************************
@@ -956,35 +950,35 @@
    packets, except MEMDUMP and READ_REGISTER.
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
-#define	PKT_PhbNum		(PKT_Data+1)		/* Port number wrt RTA */
-#define	PKT_Cmd2		(PKT_Data+2)		/* Command code copy */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
+#define	PKT_PhbNum		(PKT_Data+1)	/* Port number wrt RTA */
+#define	PKT_Cmd2		(PKT_Data+2)	/* Command code copy */
 #endif
-#define	PKT_ModemStatus		(PKT_Data+3)		/* Modem signal status */
-#define	PKT_PortStatus		(PKT_Data+4)		/* Port signal status */
+#define	PKT_ModemStatus		(PKT_Data+3)	/* Modem signal status */
+#define	PKT_PortStatus		(PKT_Data+4)	/* Port signal status */
 #if 0
-#define	PKT_SubCmd		(PKT_Data+5)		/* Sub Command */
+#define	PKT_SubCmd		(PKT_Data+5)	/* Sub Command */
 #endif
 
 /* ModemStatus definitions... */
-#define	MODEM_DSR		0x80			/* Data Set Ready modem state */
-#define	MODEM_CTS		0x40			/* Clear To Send modem state */
-#define	MODEM_RI		0x20			/* Ring Indicate modem state */
-#define	MODEM_CD		0x10			/* Carrier Detect modem state */
-#define	MODEM_TSTOP		0x08			/* Transmit Stopped state */
-#define	MODEM_TEMPTY		0x04			/* Transmit Empty state */
-#define	MODEM_DTR		0x02			/* DTR modem output state */
-#define	MODEM_RTS		0x01			/* RTS modem output state */
+#define	MODEM_DSR		0x80	/* Data Set Ready modem state */
+#define	MODEM_CTS		0x40	/* Clear To Send modem state */
+#define	MODEM_RI		0x20	/* Ring Indicate modem state */
+#define	MODEM_CD		0x10	/* Carrier Detect modem state */
+#define	MODEM_TSTOP		0x08	/* Transmit Stopped state */
+#define	MODEM_TEMPTY		0x04	/* Transmit Empty state */
+#define	MODEM_DTR		0x02	/* DTR modem output state */
+#define	MODEM_RTS		0x01	/* RTS modem output state */
 
 /* PortStatus definitions... */
-#define	PORT_ISOPEN		0x01			/* Port open ? */
-#define	PORT_HUPCL		0x02			/* Hangup on close? */
-#define	PORT_MOPENPEND		0x04			/* Modem open pending */
-#define	PORT_ISPARALLEL		0x08			/* Parallel port */
-#define	PORT_BREAK		0x10			/* Port on break */
-#define	PORT_STATUSPEND		0020			/* Status packet pending */
-#define	PORT_BREAKPEND		0x40			/* Break packet pending */
-#define	PORT_MODEMPEND		0x80			/* Modem status packet pending */
+#define	PORT_ISOPEN		0x01	/* Port open ? */
+#define	PORT_HUPCL		0x02	/* Hangup on close? */
+#define	PORT_MOPENPEND		0x04	/* Modem open pending */
+#define	PORT_ISPARALLEL		0x08	/* Parallel port */
+#define	PORT_BREAK		0x10	/* Port on break */
+#define	PORT_STATUSPEND		0020	/* Status packet pending */
+#define	PORT_BREAKPEND		0x40	/* Break packet pending */
+#define	PORT_MODEMPEND		0x80	/* Modem status packet pending */
 
 /*****************************************************************************
 ********************                                      ********************
@@ -998,15 +992,15 @@
    port I/O control command packet.
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
-#define	PKT_PhbNum		(PKT_Data+1)		/* Port number wrt RTA */
-#define	PKT_Cmd2		(PKT_Data+2)		/* Command code copy */
-#define	PKT_ModemStatus		(PKT_Data+3)		/* Modem signal status */
-#define	PKT_PortStatus		(PKT_Data+4)		/* Port signal status */
-#define	PKT_SubCmd		(PKT_Data+5)		/* Sub Command */
-#define	PKT_Address		(PKT_Data+6)		/* Requested address */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
+#define	PKT_PhbNum		(PKT_Data+1)	/* Port number wrt RTA */
+#define	PKT_Cmd2		(PKT_Data+2)	/* Command code copy */
+#define	PKT_ModemStatus		(PKT_Data+3)	/* Modem signal status */
+#define	PKT_PortStatus		(PKT_Data+4)	/* Port signal status */
+#define	PKT_SubCmd		(PKT_Data+5)	/* Sub Command */
+#define	PKT_Address		(PKT_Data+6)	/* Requested address */
 #endif
-#define	PKT_Dump		(PKT_Data+8)		/* 32bytes of requested dump data */
+#define	PKT_Dump		(PKT_Data+8)	/* 32bytes of requested dump data */
 
 /*****************************************************************************
 *****************                                            *****************
@@ -1020,14 +1014,14 @@
    READ_REGISTER port I/O control command packet.
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/*Command code */
-#define	PKT_PhbNum		(PKT_Data+1)		/*Port number wrt RTA */
-#define	PKT_Cmd2		(PKT_Data+2)		/* Command code copy */
+#define	PKT_Cmd			(PKT_Data+0)	/*Command code */
+#define	PKT_PhbNum		(PKT_Data+1)	/*Port number wrt RTA */
+#define	PKT_Cmd2		(PKT_Data+2)	/* Command code copy */
 #endif
-#define	PKT_RegisterValue	(PKT_Data+3)		/* Modem signal status */
+#define	PKT_RegisterValue	(PKT_Data+3)	/* Modem signal status */
 #if 0
-#define	PKT_PortStatus		(PKT_Data+4)		/* Port signal status */
-#define	PKT_SubCmd		(PKT_Data+5)		/* Sub Command */
+#define	PKT_PortStatus		(PKT_Data+4)	/* Port signal status */
+#define	PKT_SubCmd		(PKT_Data+5)	/* Sub Command */
 #endif
 
 /*****************************************************************************
@@ -1041,9 +1035,9 @@
    COMMAND_RUP - BREAK_RECEIVED packets are sent when the port detects a receive BREAK signal.
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
-#define	PKT_PhbNum		(PKT_Data+1)		/* Port number wrt RTA */
-#define	PKT_Cmd2		(PKT_Data+2)		/* Command code copy */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
+#define	PKT_PhbNum		(PKT_Data+1)	/* Port number wrt RTA */
+#define	PKT_Cmd2		(PKT_Data+2)	/* Command code copy */
 #endif
 
 /*****************************************************************************
@@ -1059,10 +1053,10 @@
 
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
-#define	PKT_PhbNum		(PKT_Data+1)		/* Port number wrt RTA */
-#define	PKT_Cmd2		(PKT_Data+2)		/* Command code copy */
-#define	PKT_ModemStatus		(PKT_Data+3)		/* Modem signal status */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
+#define	PKT_PhbNum		(PKT_Data+1)	/* Port number wrt RTA */
+#define	PKT_Cmd2		(PKT_Data+2)	/* Command code copy */
+#define	PKT_ModemStatus		(PKT_Data+3)	/* Modem signal status */
 #endif
 
 /*****************************************************************************
@@ -1077,7 +1071,7 @@
    firmware code to load onto attached RTAs.
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
 #endif
 
 /*****************************************************************************
@@ -1092,12 +1086,12 @@
    to a BOOT_RUP - BOOT_REQUEST packet.
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
 #endif
-#define	PKT_NumPackets		(PKT_Data+2)		/* Packets required to load firmware */
-#define	PKT_LoadBase		(PKT_Data+4)		/* RTA firmware load address */
-#define	PKT_CodeSize		(PKT_Data+6)		/* Size of firmware in bytes */
-#define	PKT_CmdString		(PKT_Data+8)		/* Command string */
+#define	PKT_NumPackets		(PKT_Data+2)	/* Packets required to load firmware */
+#define	PKT_LoadBase		(PKT_Data+4)	/* RTA firmware load address */
+#define	PKT_CodeSize		(PKT_Data+6)	/* Size of firmware in bytes */
+#define	PKT_CmdString		(PKT_Data+8)	/* Command string */
 
 /*****************************************************************************
 ************************                               ***********************
@@ -1111,10 +1105,10 @@
    RTA firmware has completed.
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
 #endif
-#define	PKT_LinkNumber		(PKT_Data+1)		/* Link number RTA booted on */
-#define	PKT_SerialNumber	(PKT_Data+2)		/* 4 byte serial number */
+#define	PKT_LinkNumber		(PKT_Data+1)	/* Link number RTA booted on */
+#define	PKT_SerialNumber	(PKT_Data+2)	/* 4 byte serial number */
 
 /*****************************************************************************
 ************************                               ***********************
@@ -1127,7 +1121,7 @@
    BOOT_RUP packet without the PKT_CMD_BIT set in the PKT->len field is sent
    from RIO to the Driver as a request for a firmware boot packet. */
 
-#define	PKT_SequenceNumber	(PKT_Data+0)		/* Packet sequence number */
+#define	PKT_SequenceNumber	(PKT_Data+0)	/* Packet sequence number */
 
 /*****************************************************************************
 ***********************                                ***********************
@@ -1141,9 +1135,9 @@
    packet with the 70 bytes of the requested sequence.
    */
 #if 0
-#define	PKT_SequenceNumber	(PKT_Data+0)		/* Packet sequence number */
+#define	PKT_SequenceNumber	(PKT_Data+0)	/* Packet sequence number */
 #endif
-#define	PKT_FirmwarePacket	(PKT_Data+2)		/* Firmware packet */
+#define	PKT_FirmwarePacket	(PKT_Data+2)	/* Firmware packet */
 
 /*****************************************************************************
 ****************************                      ****************************
@@ -1157,10 +1151,10 @@
    RTA to shut down and reboot.
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
 #endif
-#define	PKT_IfoadId1		(PKT_Data+2)		/* IFOAD Id 1 */
-#define	PKT_IfoadId2		(PKT_Data+3)		/* IFOAD Id 2 */
+#define	PKT_IfoadId1		(PKT_Data+2)	/* IFOAD Id 1 */
+#define	PKT_IfoadId2		(PKT_Data+3)	/* IFOAD Id 2 */
 
 #define	IFOADID1		0xAD
 #define	IFOADID2		0xF0
@@ -1177,9 +1171,9 @@
    RTA to flash its LEDs for a period of time.
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
 #endif
-#define	PKT_IdentifyId		(PKT_Data+2)		/* defines pattern to flash */
+#define	PKT_IdentifyId		(PKT_Data+2)	/* defines pattern to flash */
 
 /*****************************************************************************
 ****************************                       ***************************
@@ -1193,10 +1187,10 @@
    RTA to shut down and flash it's LEDs.
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
 #endif
-#define	PKT_ZombieId1		(PKT_Data+2)		/* ZOMBIE Id 1 */
-#define	PKT_ZombieId2		(PKT_Data+3)		/* ZOMBIE Id 2 */
+#define	PKT_ZombieId1		(PKT_Data+2)	/* ZOMBIE Id 1 */
+#define	PKT_ZombieId2		(PKT_Data+3)	/* ZOMBIE Id 2 */
 
 #define	ZOMBIEID1		0x52
 #define	ZOMBIEID2		0x21
@@ -1213,11 +1207,11 @@
    to ask it's neighbouring RTA to shut down and reboot.
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
-#define	PKT_LinkNumber		(PKT_Data+1)		/* Link number of RTA to UFOAD */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
+#define	PKT_LinkNumber		(PKT_Data+1)	/* Link number of RTA to UFOAD */
 #endif
-#define	PKT_UfoadId1		(PKT_Data+2)		/* UFOAD Id 1 */
-#define	PKT_UfoadId2		(PKT_Data+3)		/* UFOAD Id 2 */
+#define	PKT_UfoadId1		(PKT_Data+2)	/* UFOAD Id 1 */
+#define	PKT_UfoadId2		(PKT_Data+3)	/* UFOAD Id 2 */
 
 #define	UFOADID1		0x1E
 #define	UFOADID2		0x0D
@@ -1234,11 +1228,11 @@
    to pause booting on the specified link for 30 seconds.
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
-#define	PKT_LinkNumber		(PKT_Data+1)		/* Link number of RTA to UFOAD */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
+#define	PKT_LinkNumber		(PKT_Data+1)	/* Link number of RTA to UFOAD */
 #endif
-#define	PKT_IwaitId1		(PKT_Data+2)		/* IWAIT Id 1 */
-#define	PKT_IwaitId2		(PKT_Data+3)		/* IWAIT Id 2 */
+#define	PKT_IwaitId1		(PKT_Data+2)	/* IWAIT Id 1 */
+#define	PKT_IwaitId2		(PKT_Data+3)	/* IWAIT Id 2 */
 
 #define	IWAITID1		0xDE
 #define	IWAITID2		0xB1
@@ -1255,20 +1249,20 @@
    RTA to a Driver to request an ID (RUP or unit number).
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
 #endif
-#define	PKT_SerialNumber	(PKT_Data+2)		/* 4 byte serial number */
-#define	PKT_ModuleTypes		(PKT_Data+6)		/* RTA Module types */
+#define	PKT_SerialNumber	(PKT_Data+2)	/* 4 byte serial number */
+#define	PKT_ModuleTypes		(PKT_Data+6)	/* RTA Module types */
 
 /* ModuleTypes definitions... */
-#define	MOD_BLANK		0x0F			/* Blank plate attached */
-#define	MOD_RS232DB25		0x00			/* RS232 DB25 connector */
-#define	MOD_RS232RJ45		0x01			/* RS232 RJ45 connector */
-#define	MOD_RS422DB25		0x02			/* RS422 DB25 connector */
-#define	MOD_RS485DB25		0x03			/* RS485 DB25 connector */
-#define	MOD_PARALLEL		0x04			/* Centronics parallel */
+#define	MOD_BLANK		0x0F	/* Blank plate attached */
+#define	MOD_RS232DB25		0x00	/* RS232 DB25 connector */
+#define	MOD_RS232RJ45		0x01	/* RS232 RJ45 connector */
+#define	MOD_RS422DB25		0x02	/* RS422 DB25 connector */
+#define	MOD_RS485DB25		0x03	/* RS485 DB25 connector */
+#define	MOD_PARALLEL		0x04	/* Centronics parallel */
 
-#define	MOD2			0x08			/* Set to indicate Rev2 module */
+#define	MOD2			0x08	/* Set to indicate Rev2 module */
 
 /*****************************************************************************
 *************************                            *************************
@@ -1282,9 +1276,9 @@
    packet to cause the RTA to "Fall Over And Die"., i.e. shutdown and reboot.
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
 #endif
-#define	PKT_RouteCmdString	(PKT_Data+2)		/* Command string */
+#define	PKT_RouteCmdString	(PKT_Data+2)	/* Command string */
 
 /*****************************************************************************
 ***********************                                ***********************
@@ -1298,13 +1292,13 @@
    packet to allocate the RTA's Id number (RUP number 1..16)
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
 #endif
-#define	PKT_IdNum		(PKT_Data+1)		/* RUP number for ports 1..8 */
+#define	PKT_IdNum		(PKT_Data+1)	/* RUP number for ports 1..8 */
 #if 0
-#define	PKT_RouteCmdString	(PKT_Data+2)		/* Command string */
+#define	PKT_RouteCmdString	(PKT_Data+2)	/* Command string */
 #endif
-#define	PKT_IdNum2		(PKT_Data+0x17)		/* RUP number for ports 9..16 */
+#define	PKT_IdNum2		(PKT_Data+0x17)	/* RUP number for ports 9..16 */
 
 /*****************************************************************************
 ***********************                                ***********************
@@ -1318,18 +1312,18 @@
    current link status.
    */
 #if 0
-#define	PKT_Cmd			(PKT_Data+0)		/* Command code */
+#define	PKT_Cmd			(PKT_Data+0)	/* Command code */
 #endif
-#define	PKT_Link1Rup		(PKT_Data+2)		/* Link 1 RUP number */
-#define	PKT_Link1Link		(PKT_Data+3)		/* Link 1 link number */
-#define	PKT_Link2Rup		(PKT_Data+4)		/* Link 2 RUP number */
-#define	PKT_Link2Link		(PKT_Data+5)		/* Link 2 link number */
-#define	PKT_Link3Rup		(PKT_Data+6)		/* Link 3 RUP number */
-#define	PKT_Link3Link		(PKT_Data+7)		/* Link 3 link number */
-#define	PKT_Link4Rup		(PKT_Data+8)		/* Link 4 RUP number */
-#define	PKT_Link4Link		(PKT_Data+9)		/* Link 4 link number */
-#define	PKT_RtaVpdProm		(PKT_Data+10)		/* 32 bytes of RTA VPD PROM Contents */
+#define	PKT_Link1Rup		(PKT_Data+2)	/* Link 1 RUP number */
+#define	PKT_Link1Link		(PKT_Data+3)	/* Link 1 link number */
+#define	PKT_Link2Rup		(PKT_Data+4)	/* Link 2 RUP number */
+#define	PKT_Link2Link		(PKT_Data+5)	/* Link 2 link number */
+#define	PKT_Link3Rup		(PKT_Data+6)	/* Link 3 RUP number */
+#define	PKT_Link3Link		(PKT_Data+7)	/* Link 3 link number */
+#define	PKT_Link4Rup		(PKT_Data+8)	/* Link 4 RUP number */
+#define	PKT_Link4Link		(PKT_Data+9)	/* Link 4 link number */
+#define	PKT_RtaVpdProm		(PKT_Data+10)	/* 32 bytes of RTA VPD PROM Contents */
 
-#endif						/* _sxwinif_h */
+#endif				/* _sxwinif_h */
 
 /* End of RIOWINIF.H */
diff --git a/drivers/char/rio/riscos.h b/drivers/char/rio/riscos.h
index 7685cc1..60d66d0 100644
--- a/drivers/char/rio/riscos.h
+++ b/drivers/char/rio/riscos.h
@@ -60,4 +60,4 @@
 #define RINDW(A)	(*(ushort *)(A))
 #define WINDW(A,V)	(*(ushort *)(A)=(ushort)(V))
 
-#endif /* __rio_riscos_h__ */
+#endif				/* __rio_riscos_h__ */
diff --git a/drivers/char/rio/rom.h b/drivers/char/rio/rom.h
index ee79b8e..58a7843 100644
--- a/drivers/char/rio/rom.h
+++ b/drivers/char/rio/rom.h
@@ -39,19 +39,19 @@
 
 #ifndef lint
 #ifdef SCCS
-static char *_rio_rom_h_sccs = "@(#)rom.h	1.1" ;
+static char *_rio_rom_h_sccs = "@(#)rom.h	1.1";
 #endif
 #endif
 
-typedef struct  ROM  ROM ;
-struct  ROM  {
-                 u_short    slx ;
-                 char       pcb_letter_rev ;
-                 char       pcb_number_rev ;
-                 char       serial[4] ;
-                 char       year ;
-                 char       week ;
-             } ;
+typedef struct ROM ROM;
+struct ROM {
+	u_short slx;
+	char pcb_letter_rev;
+	char pcb_number_rev;
+	char serial[4];
+	char year;
+	char week;
+};
 
 #endif
 
@@ -60,5 +60,3 @@
 #define ROM_LENGTH  0x20
 
 /*********** end of file ***********/
-
-
diff --git a/drivers/char/rio/route.h b/drivers/char/rio/route.h
index c42dbb9..769744e 100644
--- a/drivers/char/rio/route.h
+++ b/drivers/char/rio/route.h
@@ -44,26 +44,26 @@
 #endif
 
 #define MAX_LINKS 4
-#define MAX_NODES 17                          /* Maximum nodes in a subnet */
-#define NODE_BYTES ((MAX_NODES / 8) + 1)      /* Number of bytes needed for
-                                                 1 bit per node */
-#define ROUTE_DATA_SIZE  (NODE_BYTES + 2)     /* Number of bytes for complete 
-                                                 info about cost etc. */
+#define MAX_NODES 17		/* Maximum nodes in a subnet */
+#define NODE_BYTES ((MAX_NODES / 8) + 1)	/* Number of bytes needed for
+						   1 bit per node */
+#define ROUTE_DATA_SIZE  (NODE_BYTES + 2)	/* Number of bytes for complete
+						   info about cost etc. */
 #define ROUTES_PER_PACKET ((PKT_MAX_DATA_LEN -2)/ ROUTE_DATA_SIZE)
-                                              /* Number of nodes we can squeeze
-                                                 into one packet */
+					      /* Number of nodes we can squeeze
+					         into one packet */
 #define MAX_TOPOLOGY_PACKETS (MAX_NODES / ROUTES_PER_PACKET + 1)
 /************************************************
  * Define the types of command for the ROUTE RUP.
  ************************************************/
-#define ROUTE_REQUEST    0                    /* Request an ID */
-#define ROUTE_FOAD       1                    /* Kill the RTA */
-#define ROUTE_ALREADY    2                    /* ID given already */
-#define ROUTE_USED       3                    /* All ID's used */
-#define ROUTE_ALLOCATE   4                    /* Here it is */
-#define ROUTE_REQ_TOP    5                    /* I bet you didn't expect....
-                                                 the Topological Inquisition */
-#define ROUTE_TOPOLOGY   6                    /* Topology request answered FD */
+#define ROUTE_REQUEST    0	/* Request an ID */
+#define ROUTE_FOAD       1	/* Kill the RTA */
+#define ROUTE_ALREADY    2	/* ID given already */
+#define ROUTE_USED       3	/* All ID's used */
+#define ROUTE_ALLOCATE   4	/* Here it is */
+#define ROUTE_REQ_TOP    5	/* I bet you didn't expect....
+				   the Topological Inquisition */
+#define ROUTE_TOPOLOGY   6	/* Topology request answered FD */
 /*******************************************************************
  * Define the Route Map Structure
  *
@@ -72,22 +72,22 @@
  ******************************************************************/
 typedef struct COST_ROUTE COST_ROUTE;
 struct COST_ROUTE {
-                      unsigned char cost;        /* Cost down this link */
-                      unsigned char route[NODE_BYTES]; /* Nodes thorough this route */
-                  } ;
+	unsigned char cost;	/* Cost down this link */
+	unsigned char route[NODE_BYTES];	/* Nodes thorough this route */
+};
 
-typedef struct ROUTE_STR ROUTE_STR ;
-struct  ROUTE_STR {
-                      COST_ROUTE cost_route[MAX_LINKS];
-                                                /* cost / route for this link */
-                      ushort favoured;          /* favoured link */
-                  } ;
+typedef struct ROUTE_STR ROUTE_STR;
+struct ROUTE_STR {
+	COST_ROUTE cost_route[MAX_LINKS];
+	/* cost / route for this link */
+	ushort favoured;	/* favoured link */
+};
 
 
-#define NO_LINK            (short) 5      /* Link unattached */
-#define ROUTE_NO_ID        (short) 100    /* No Id */
-#define ROUTE_DISCONNECT   (ushort) 0xff  /* Not connected */
-#define ROUTE_INTERCONNECT (ushort) 0x40  /* Sub-net interconnect */
+#define NO_LINK            (short) 5	/* Link unattached */
+#define ROUTE_NO_ID        (short) 100	/* No Id */
+#define ROUTE_DISCONNECT   (ushort) 0xff	/* Not connected */
+#define ROUTE_INTERCONNECT (ushort) 0x40	/* Sub-net interconnect */
 
 
 #define SYNC_RUP         (ushort) 255
@@ -99,10 +99,9 @@
 #define STATUS_RUP       (ushort) 249
 #define POWER_RUP        (ushort) 248
 
-#define HIGHEST_RUP      (ushort) 255   /* Set to Top one */
-#define LOWEST_RUP       (ushort) 248   /* Set to bottom one */
+#define HIGHEST_RUP      (ushort) 255	/* Set to Top one */
+#define LOWEST_RUP       (ushort) 248	/* Set to bottom one */
 
 #endif
 
 /*********** end of file ***********/
-
diff --git a/drivers/char/rio/rtahw.h b/drivers/char/rio/rtahw.h
index 0686011..e6c2cdf 100644
--- a/drivers/char/rio/rtahw.h
+++ b/drivers/char/rio/rtahw.h
@@ -37,7 +37,7 @@
 
 #ifndef lint
 #ifdef SCCS_LABELS
-static char *_rio_rtahw_h_sccs = "@(#)rtahw.h	1.5" ;
+static char *_rio_rtahw_h_sccs = "@(#)rtahw.h	1.5";
 #endif
 #endif
 
@@ -58,12 +58,12 @@
 ** Define the different types of modules we can have
 */
 enum module {
-    MOD_BLANK		= 0x0f,		/* Blank plate attached */
-    MOD_RS232DB25	= 0x00,		/* RS232 DB25 connector */
-    MOD_RS232RJ45	= 0x01,		/* RS232 RJ45 connector */
-    MOD_RS422DB25	= 0x02,		/* RS422 DB25 connector */
-    MOD_RS485DB25	= 0x03,		/* RS485 DB25 connector */
-    MOD_PARALLEL	= 0x04		/* Centronics parallel */
+	MOD_BLANK = 0x0f,	/* Blank plate attached */
+	MOD_RS232DB25 = 0x00,	/* RS232 DB25 connector */
+	MOD_RS232RJ45 = 0x01,	/* RS232 RJ45 connector */
+	MOD_RS422DB25 = 0x02,	/* RS422 DB25 connector */
+	MOD_RS485DB25 = 0x03,	/* RS485 DB25 connector */
+	MOD_PARALLEL = 0x04	/* Centronics parallel */
 };
 
 #define TYPE_HOST	0
diff --git a/drivers/char/rio/rup.h b/drivers/char/rio/rup.h
index b9d2bc0..8d44fec 100644
--- a/drivers/char/rio/rup.h
+++ b/drivers/char/rio/rup.h
@@ -44,39 +44,38 @@
 #endif
 
 #if defined( HOST ) || defined( INKERNEL )
-#define MAX_RUP          ((short) 16) 
+#define MAX_RUP          ((short) 16)
 #endif
 #ifdef RTA
 #define MAX_RUP          ((short) 1)
 #endif
 
-#define PKTS_PER_RUP     ((short) 2)     /* They are always used in pairs */
+#define PKTS_PER_RUP     ((short) 2)	/* They are always used in pairs */
 
 /*************************************************
  * Define all the  packet request stuff
  ************************************************/
-#define TX_RUP_INACTIVE          0        /* Nothing to transmit */
-#define TX_PACKET_READY          1        /* Transmit packet ready */
-#define TX_LOCK_RUP              2        /* Transmit side locked */
+#define TX_RUP_INACTIVE          0	/* Nothing to transmit */
+#define TX_PACKET_READY          1	/* Transmit packet ready */
+#define TX_LOCK_RUP              2	/* Transmit side locked */
 
-#define RX_RUP_INACTIVE          0        /* Nothing received */
-#define RX_PACKET_READY          1        /* Packet received */
+#define RX_RUP_INACTIVE          0	/* Nothing received */
+#define RX_PACKET_READY          1	/* Packet received */
 
-#define RUP_NO_OWNER             0xff     /* RUP not owned by any process */
+#define RUP_NO_OWNER             0xff	/* RUP not owned by any process */
 
 struct RUP {
-             PKT_ptr    txpkt;            /* Outgoing packet */
-             PKT_ptr    rxpkt;            /* Incoming packet */
-             WORD       link;             /* Which link to send down? */
-             BYTE       rup_dest_unit[2]; /* Destination unit */
-             WORD       handshake;        /* For handshaking */
-             WORD       timeout;          /* Timeout */
-             WORD       status;           /* Status */
-             WORD       txcontrol;        /* Transmit control */
-             WORD       rxcontrol;        /* Receive control */
-           };
- 
+	PKT_ptr txpkt;		/* Outgoing packet */
+	PKT_ptr rxpkt;		/* Incoming packet */
+	WORD link;		/* Which link to send down? */
+	BYTE rup_dest_unit[2];	/* Destination unit */
+	WORD handshake;		/* For handshaking */
+	WORD timeout;		/* Timeout */
+	WORD status;		/* Status */
+	WORD txcontrol;		/* Transmit control */
+	WORD rxcontrol;		/* Receive control */
+};
+
 #endif
 
 /*********** end of file ***********/
-
diff --git a/drivers/char/rio/rupstat.h b/drivers/char/rio/rupstat.h
index b4aafaf..56d828c 100644
--- a/drivers/char/rio/rupstat.h
+++ b/drivers/char/rio/rupstat.h
@@ -39,7 +39,7 @@
 
 #ifndef lint
 #ifdef SCCS_LABELS
-static char *_rio_rupstat_h_sccs = "@(#)rupstat.h	1.1" ;
+static char *_rio_rupstat_h_sccs = "@(#)rupstat.h	1.1";
 #endif
 #endif
 
@@ -48,4 +48,3 @@
 #define    STATUS_TOPOLOGY    2
 
 #endif
-
diff --git a/drivers/char/rio/sam.h b/drivers/char/rio/sam.h
index c1accb8..3149405 100644
--- a/drivers/char/rio/sam.h
+++ b/drivers/char/rio/sam.h
@@ -60,15 +60,12 @@
 #define RX    FALSE
 
 
-typedef struct FREE_LIST FREE_LIST ;
-struct FREE_LIST   {
-                       FREE_LIST_ptr next ;
-                       FREE_LIST_ptr prev ;
-                   } ;
+typedef struct FREE_LIST FREE_LIST;
+struct FREE_LIST {
+	FREE_LIST_ptr next;
+	FREE_LIST_ptr prev;
+};
 
 
 #endif
 /*********** end of file ***********/
-
-
-
diff --git a/drivers/char/rio/selftest.h b/drivers/char/rio/selftest.h
index deae487..7a3dba3 100644
--- a/drivers/char/rio/selftest.h
+++ b/drivers/char/rio/selftest.h
@@ -38,36 +38,36 @@
 ** selftest on a booting RTA.
 */
 typedef struct {
-    short		magic;			/* Identifies packet type */
-    int			test;			/* Test number, see below */
-    unsigned int	result;			/* Result value */
-    unsigned int	dataIn;
-    unsigned int	dataOut;
-}selftestStruct;
+	short magic;		/* Identifies packet type */
+	int test;		/* Test number, see below */
+	unsigned int result;	/* Result value */
+	unsigned int dataIn;
+	unsigned int dataOut;
+} selftestStruct;
 
 /*
 ** The different tests are identified by the following data values.
 */
 enum test {
-    TESTS_COMPLETE	= 0x00,
-    MEMTEST_ADDR	= 0x01,
-    MEMTEST_BIT		= 0x02,
-    MEMTEST_FILL	= 0x03,
-    MEMTEST_DATABUS	= 0x04,
-    MEMTEST_ADDRBUS	= 0x05,
-    CD1400_INIT		= 0x10,
-    CD1400_LOOP		= 0x11,
-    CD1400_INTERRUPT    = 0x12
+	TESTS_COMPLETE = 0x00,
+	MEMTEST_ADDR = 0x01,
+	MEMTEST_BIT = 0x02,
+	MEMTEST_FILL = 0x03,
+	MEMTEST_DATABUS = 0x04,
+	MEMTEST_ADDRBUS = 0x05,
+	CD1400_INIT = 0x10,
+	CD1400_LOOP = 0x11,
+	CD1400_INTERRUPT = 0x12
 };
 
 enum result {
-    E_PORT		= 0x10,
-    E_TX		= 0x11,
-    E_RX		= 0x12,
-    E_EXCEPT		= 0x13,
-    E_COMPARE		= 0x14,
-    E_MODEM		= 0x15,
-    E_TIMEOUT		= 0x16,
-    E_INTERRUPT         = 0x17
+	E_PORT = 0x10,
+	E_TX = 0x11,
+	E_RX = 0x12,
+	E_EXCEPT = 0x13,
+	E_COMPARE = 0x14,
+	E_MODEM = 0x15,
+	E_TIMEOUT = 0x16,
+	E_INTERRUPT = 0x17
 };
-#endif	/* _selftests_h_ */
+#endif				/* _selftests_h_ */
diff --git a/drivers/char/rio/space.h b/drivers/char/rio/space.h
index 72398d3..1f12690 100644
--- a/drivers/char/rio/space.h
+++ b/drivers/char/rio/space.h
@@ -42,4 +42,4 @@
 extern int rio_limits[];
 extern int rio_vects[];
 
-#endif /* __rio_space_h__ */
+#endif				/* __rio_space_h__ */
diff --git a/drivers/char/rio/sysmap.h b/drivers/char/rio/sysmap.h
index fdc7313..e1c6f11 100644
--- a/drivers/char/rio/sysmap.h
+++ b/drivers/char/rio/sysmap.h
@@ -37,27 +37,26 @@
 
 #ifndef lint
 #ifdef SCCS_LABELS
-static char *_rio_sysmap_h_sccs = "@(#)sysmap.h	1.1" ;
+static char *_rio_sysmap_h_sccs = "@(#)sysmap.h	1.1";
 #endif
 #endif
 
-#define SYSTEM_MAP_LEN     64           /* Len of System Map array */
+#define SYSTEM_MAP_LEN     64	/* Len of System Map array */
 
 
-typedef struct SYS_MAP        SYS_MAP ;
-typedef struct SYS_MAP_LINK   SYS_MAP_LINK ;
+typedef struct SYS_MAP SYS_MAP;
+typedef struct SYS_MAP_LINK SYS_MAP_LINK;
 
 struct SYS_MAP_LINK {
-                        short id ;          /* Unit Id */
-                        short link ;        /* Id's Link */
-                        short been_here ;   /* Used by map_gen */
-                    } ;
+	short id;		/* Unit Id */
+	short link;		/* Id's Link */
+	short been_here;	/* Used by map_gen */
+};
 
 struct SYS_MAP {
-                   char         serial_num[4] ;
-                   SYS_MAP_LINK link[4] ;
-               } ;
+	char serial_num[4];
+	SYS_MAP_LINK link[4];
+};
 
 
 /*********** end of file ***********/
-
diff --git a/drivers/char/rio/timeouts.h b/drivers/char/rio/timeouts.h
index 11b3133..a8b5be3 100644
--- a/drivers/char/rio/timeouts.h
+++ b/drivers/char/rio/timeouts.h
@@ -37,15 +37,14 @@
 
 #ifndef lint
 #ifdef SCCS_LABELS
-static char *_rio_defaults_h_sccs = "@(#)timeouts.h	1.3" ;
+static char *_rio_defaults_h_sccs = "@(#)timeouts.h	1.3";
 #endif
 #endif
 
-#define MILLISECOND           (int) (1000/64)   /* 15.625 low ticks */
-#define SECOND                (int) 15625       /* Low priority ticks */
+#define MILLISECOND           (int) (1000/64)	/* 15.625 low ticks */
+#define SECOND                (int) 15625	/* Low priority ticks */
 
 #define TX_TIMEOUT          (int) (200 * MILLISECOND)
 
 
 /*********** end of file ***********/
-
diff --git a/drivers/char/rio/top.h b/drivers/char/rio/top.h
index 255c40d..d15a11d 100644
--- a/drivers/char/rio/top.h
+++ b/drivers/char/rio/top.h
@@ -40,10 +40,9 @@
 /*
 ** Topology information
 */
-struct Top
-{
-    uchar Unit;
-    uchar Link;
+struct Top {
+	uchar Unit;
+	uchar Link;
 };
 
-#endif /* __rio_top_h__ */
+#endif				/* __rio_top_h__ */
diff --git a/drivers/char/rio/typdef.h b/drivers/char/rio/typdef.h
index 2cb9dd6..185b889 100644
--- a/drivers/char/rio/typdef.h
+++ b/drivers/char/rio/typdef.h
@@ -45,11 +45,11 @@
 ** These types are ONLY to be used for refering to data structures
 ** on the RIO Host card!
 */
-typedef	volatile unsigned char	BYTE;
-typedef volatile unsigned short	WORD;
-typedef volatile unsigned int	DWORD;
-typedef	volatile unsigned short RIOP;
-typedef	volatile short          NUMBER;
+typedef volatile unsigned char BYTE;
+typedef volatile unsigned short WORD;
+typedef volatile unsigned int DWORD;
+typedef volatile unsigned short RIOP;
+typedef volatile short NUMBER;
 
 
 /*
@@ -59,13 +59,13 @@
 ** are here only to make the source compile.
 */
 /* typedef unsigned int	uint; */
-typedef unsigned long	ulong_t;
-typedef unsigned short	ushort_t;
-typedef unsigned char	uchar_t;
-typedef unsigned char	queue_t;
-typedef unsigned char	mblk_t;
-typedef	unsigned int 	paddr_t;
-typedef unsigned char   uchar;
+typedef unsigned long ulong_t;
+typedef unsigned short ushort_t;
+typedef unsigned char uchar_t;
+typedef unsigned char queue_t;
+typedef unsigned char mblk_t;
+typedef unsigned int paddr_t;
+typedef unsigned char uchar;
 
 #define	TPNULL	((ushort)(0x8000))
 
@@ -73,10 +73,10 @@
 /*
 ** RIO structures defined in other include files.
 */
-typedef struct PKT	 	PKT;
-typedef struct LPB	 	LPB;
-typedef struct RUP	 	RUP;
-typedef struct Port		Port;
-typedef struct DpRam		DpRam;
+typedef struct PKT PKT;
+typedef struct LPB LPB;
+typedef struct RUP RUP;
+typedef struct Port Port;
+typedef struct DpRam DpRam;
 
-#endif /* __rio_typdef_h__ */
+#endif				/* __rio_typdef_h__ */
diff --git a/drivers/char/rio/unixrup.h b/drivers/char/rio/unixrup.h
index eddf862..a126c7c 100644
--- a/drivers/char/rio/unixrup.h
+++ b/drivers/char/rio/unixrup.h
@@ -41,16 +41,15 @@
 **    UnixRup data structure. This contains pointers to actual RUPs on the
 **    host card, and all the command/boot control stuff.
 */
-struct    UnixRup
-{
-    struct CmdBlk    *CmdsWaitingP;	/* Commands waiting to be done */
-    struct CmdBlk    *CmdPendingP;	/* The command currently being sent */
-    struct RUP       *RupP;		/* the Rup to send it to */
-    uint             Id;		/* Id number */
-    uint             BaseSysPort;	/* SysPort of first tty on this RTA */
-    uint             ModTypes;		/* Modules on this RTA */
-    spinlock_t	     RupLock;		/* Lock structure for MPX */
-/*    struct lockb     RupLock;	*/	/* Lock structure for MPX */
+struct UnixRup {
+	struct CmdBlk *CmdsWaitingP;	/* Commands waiting to be done */
+	struct CmdBlk *CmdPendingP;	/* The command currently being sent */
+	struct RUP *RupP;	/* the Rup to send it to */
+	uint Id;		/* Id number */
+	uint BaseSysPort;	/* SysPort of first tty on this RTA */
+	uint ModTypes;		/* Modules on this RTA */
+	spinlock_t RupLock;	/* Lock structure for MPX */
+	/*    struct lockb     RupLock;	*//* Lock structure for MPX */
 };
 
-#endif /* __rio_unixrup_h__ */
+#endif				/* __rio_unixrup_h__ */
diff --git a/drivers/char/riscom8.c b/drivers/char/riscom8.c
index 55a3a01..050e70e 100644
--- a/drivers/char/riscom8.c
+++ b/drivers/char/riscom8.c
@@ -46,6 +46,7 @@
 #include <linux/major.h>
 #include <linux/init.h>
 #include <linux/delay.h>
+#include <linux/tty_flip.h>
 
 #include <asm/uaccess.h>
 
@@ -107,15 +108,15 @@
 
 /* RISCom/8 I/O ports addresses (without address translation) */
 static unsigned short rc_ioport[] =  {
-#if 1	
+#if 1
 	0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c,
-#else	
+#else
 	0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0c, 0x10,
 	0x11, 0x12, 0x18, 0x28, 0x31, 0x32, 0x39, 0x3a, 0x40, 0x41, 0x61, 0x62,
 	0x63, 0x64, 0x6b, 0x70, 0x71, 0x78, 0x7a, 0x7b, 0x7f, 0x100, 0x101
-#endif	
+#endif
 };
-#define RC_NIOPORT	(sizeof(rc_ioport) / sizeof(rc_ioport[0]))
+#define RC_NIOPORT	ARRAY_SIZE(rc_ioport)
 
 
 static inline int rc_paranoia_check(struct riscom_port const * port,
@@ -354,28 +355,17 @@
 	struct riscom_port *port;
 	struct tty_struct *tty;
 	unsigned char status;
-	unsigned char ch;
+	unsigned char ch, flag;
 	
 	if (!(port = rc_get_port(bp, "Receive")))
 		return;
 
 	tty = port->tty;
-	if (tty->flip.count >= TTY_FLIPBUF_SIZE)  {
-		printk(KERN_WARNING "rc%d: port %d: Working around flip "
-				    "buffer overflow.\n",
-		       board_No(bp), port_No(port));
-		return;
-	}
 	
 #ifdef RC_REPORT_OVERRUN	
 	status = rc_in(bp, CD180_RCSR);
-	if (status & RCSR_OE)  {
+	if (status & RCSR_OE)
 		port->overrun++;
-#if 0		
-		printk(KERN_ERR "rc%d: port %d: Overrun. Total %ld overruns\n", 
-		       board_No(bp), port_No(port), port->overrun);
-#endif		
-	}
 	status &= port->mark_mask;
 #else	
 	status = rc_in(bp, CD180_RCSR) & port->mark_mask;
@@ -393,25 +383,24 @@
 	} else if (status & RCSR_BREAK)  {
 		printk(KERN_INFO "rc%d: port %d: Handling break...\n",
 		       board_No(bp), port_No(port));
-		*tty->flip.flag_buf_ptr++ = TTY_BREAK;
+		flag = TTY_BREAK;
 		if (port->flags & ASYNC_SAK)
 			do_SAK(tty);
 		
 	} else if (status & RCSR_PE) 
-		*tty->flip.flag_buf_ptr++ = TTY_PARITY;
+		flag = TTY_PARITY;
 	
 	else if (status & RCSR_FE) 
-		*tty->flip.flag_buf_ptr++ = TTY_FRAME;
+		flag = TTY_FRAME;
 	
         else if (status & RCSR_OE)
-		*tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
+		flag = TTY_OVERRUN;
 	
 	else
-		*tty->flip.flag_buf_ptr++ = 0;
+		flag = TTY_NORMAL;
 	
-	*tty->flip.char_buf_ptr++ = ch;
-	tty->flip.count++;
-	schedule_delayed_work(&tty->flip.work, 1);
+	tty_insert_flip_char(tty, ch, flag);
+	tty_flip_buffer_push(tty);
 }
 
 static inline void rc_receive(struct riscom_board const * bp)
@@ -432,17 +421,15 @@
 #endif	
 	
 	while (count--)  {
-		if (tty->flip.count >= TTY_FLIPBUF_SIZE)  {
+		if (tty_buffer_request_room(tty, 1) == 0)  {
 			printk(KERN_WARNING "rc%d: port %d: Working around "
 					    "flip buffer overflow.\n",
 			       board_No(bp), port_No(port));
 			break;
 		}
-		*tty->flip.char_buf_ptr++ = rc_in(bp, CD180_RDR);
-		*tty->flip.flag_buf_ptr++ = 0;
-		tty->flip.count++;
+		tty_insert_flip_char(tty, rc_in(bp, CD180_RDR), TTY_NORMAL);
 	}
-	schedule_delayed_work(&tty->flip.work, 1);
+	tty_flip_buffer_push(tty);
 }
 
 static inline void rc_transmit(struct riscom_board const * bp)
diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
index d3bc731..0949dce 100644
--- a/drivers/char/rocket.c
+++ b/drivers/char/rocket.c
@@ -325,19 +325,16 @@
 {
 	unsigned int CharNStat;
 	int ToRecv, wRecv, space = 0, count;
-	unsigned char *cbuf;
-	char *fbuf;
+	unsigned char *cbuf, *chead;
+	char *fbuf, *fhead;
 	struct tty_ldisc *ld;
 
 	ld = tty_ldisc_ref(tty);
 
 	ToRecv = sGetRxCnt(cp);
-	if (ld)
-		space = ld->receive_room(tty);
+	space = tty->receive_room;
 	if (space > 2 * TTY_FLIPBUF_SIZE)
 		space = 2 * TTY_FLIPBUF_SIZE;
-	cbuf = tty->flip.char_buf;
-	fbuf = tty->flip.flag_buf;
 	count = 0;
 #ifdef ROCKET_DEBUG_INTR
 	printk(KERN_INFO "rp_do_receive(%d, %d)...", ToRecv, space);
@@ -350,9 +347,13 @@
 	if (ToRecv > space)
 		ToRecv = space;
 
+	ToRecv = tty_prepare_flip_string_flags(tty, &chead, &fhead, ToRecv);
 	if (ToRecv <= 0)
 		goto done;
 
+	cbuf = chead;
+	fbuf = fhead;
+
 	/*
 	 * if status indicates there are errored characters in the
 	 * FIFO, then enter status mode (a word in FIFO holds
@@ -399,7 +400,7 @@
 			else if (CharNStat & STMRCVROVRH)
 				*fbuf++ = TTY_OVERRUN;
 			else
-				*fbuf++ = 0;
+				*fbuf++ = TTY_NORMAL;
 			*cbuf++ = CharNStat & 0xff;
 			count++;
 			ToRecv--;
@@ -426,13 +427,13 @@
 			sInStrW(sGetTxRxDataIO(cp), (unsigned short *) cbuf, wRecv);
 		if (ToRecv & 1)
 			cbuf[ToRecv - 1] = sInB(sGetTxRxDataIO(cp));
-		memset(fbuf, 0, ToRecv);
+		memset(fbuf, TTY_NORMAL, ToRecv);
 		cbuf += ToRecv;
 		fbuf += ToRecv;
 		count += ToRecv;
 	}
 	/*  Push the data up to the tty layer */
-	ld->receive_buf(tty, tty->flip.char_buf, tty->flip.flag_buf, count);
+	ld->receive_buf(tty, cbuf, fbuf, count);
 done:
 	tty_ldisc_deref(ld);
 }
diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c
index a7f099f..7cac6d0 100644
--- a/drivers/char/rtc.c
+++ b/drivers/char/rtc.c
@@ -46,10 +46,10 @@
  *      1.11a   Daniele Bellucci: Audit create_proc_read_entry in rtc_init
  *	1.12	Venkatesh Pallipadi: Hooks for emulating rtc on HPET base-timer
  *		CONFIG_HPET_EMULATE_RTC
- *
+ *	1.12ac	Alan Cox: Allow read access to the day of week register
  */
 
-#define RTC_VERSION		"1.12"
+#define RTC_VERSION		"1.12ac"
 
 #define RTC_IO_EXTENT	0x8
 
@@ -1250,9 +1250,9 @@
 
 	/*
 	 * Only the values that we read from the RTC are set. We leave
-	 * tm_wday, tm_yday and tm_isdst untouched. Even though the
-	 * RTC has RTC_DAY_OF_WEEK, we ignore it, as it is only updated
-	 * by the RTC when initially set to a non-zero value.
+	 * tm_wday, tm_yday and tm_isdst untouched. Note that while the
+	 * RTC has RTC_DAY_OF_WEEK, we should usually ignore it, as it is
+	 * only updated by the RTC when initially set to a non-zero value.
 	 */
 	spin_lock_irq(&rtc_lock);
 	rtc_tm->tm_sec = CMOS_READ(RTC_SECONDS);
@@ -1261,6 +1261,9 @@
 	rtc_tm->tm_mday = CMOS_READ(RTC_DAY_OF_MONTH);
 	rtc_tm->tm_mon = CMOS_READ(RTC_MONTH);
 	rtc_tm->tm_year = CMOS_READ(RTC_YEAR);
+	/* Only set from 2.6.16 onwards */
+	rtc_tm->tm_wday = CMOS_READ(RTC_DAY_OF_WEEK);
+
 #ifdef CONFIG_MACH_DECSTATION
 	real_year = CMOS_READ(RTC_DEC_YEAR);
 #endif
@@ -1275,6 +1278,7 @@
 		BCD_TO_BIN(rtc_tm->tm_mday);
 		BCD_TO_BIN(rtc_tm->tm_mon);
 		BCD_TO_BIN(rtc_tm->tm_year);
+		BCD_TO_BIN(rtc_tm->tm_wday);
 	}
 
 #ifdef CONFIG_MACH_DECSTATION
diff --git a/drivers/char/scc.h b/drivers/char/scc.h
index 51810f7..93998f5 100644
--- a/drivers/char/scc.h
+++ b/drivers/char/scc.h
@@ -399,7 +399,7 @@
 		__asm__ __volatile__ ( "tstb %0" : : "g" (*_scc_del) : "cc" );\
     } while (0)
 
-extern unsigned char scc_shadow[2][16];
+static unsigned char scc_shadow[2][16];
 
 /* The following functions should relax the somehow complicated
  * register access of the SCC. _SCCwrite() stores all written values
diff --git a/drivers/char/selection.c b/drivers/char/selection.c
index 5b187c8..71093a9 100644
--- a/drivers/char/selection.c
+++ b/drivers/char/selection.c
@@ -275,7 +275,8 @@
 int paste_selection(struct tty_struct *tty)
 {
 	struct vc_data *vc = (struct vc_data *)tty->driver_data;
-	int	pasted = 0, count;
+	int	pasted = 0;
+	unsigned int count;
 	struct  tty_ldisc *ld;
 	DECLARE_WAITQUEUE(wait, current);
 
@@ -293,7 +294,7 @@
 			continue;
 		}
 		count = sel_buffer_lth - pasted;
-		count = min(count, tty->ldisc.receive_room(tty));
+		count = min(count, tty->receive_room);
 		tty->ldisc.receive_buf(tty, sel_buffer + pasted, NULL, count);
 		pasted += count;
 	}
diff --git a/drivers/char/ser_a2232.c b/drivers/char/ser_a2232.c
index dda30e4..80a5b84 100644
--- a/drivers/char/ser_a2232.c
+++ b/drivers/char/ser_a2232.c
@@ -194,11 +194,6 @@
 */
 	struct tty_struct *tty = port->gs.tty;
 
-	if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-		return;
-
-	tty->flip.count++;
-
 #if 0
 	switch(err) {
 	case TTY_BREAK:
@@ -212,8 +207,7 @@
 	}
 #endif
 
-	*tty->flip.flag_buf_ptr++ = err;
-	*tty->flip.char_buf_ptr++ = ch;
+	tty_insert_flip_char(tty, ch, err);
 	tty_flip_buffer_push(tty);
 }
 
diff --git a/drivers/char/serial167.c b/drivers/char/serial167.c
index c2deac9..f36342a 100644
--- a/drivers/char/serial167.c
+++ b/drivers/char/serial167.c
@@ -117,7 +117,7 @@
         {-1 },      /* ttyS2 */
         {-1 },      /* ttyS3 */
 };
-#define NR_PORTS        (sizeof(cy_port)/sizeof(struct cyclades_port))
+#define NR_PORTS        ARRAY_SIZE(cy_port)
 
 /*
  * tmp_buf is used as a temporary buffer by serial_write.  We need to
@@ -422,45 +422,35 @@
 	    base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
 	    return IRQ_HANDLED;
 	}
-	if (tty->flip.count < TTY_FLIPBUF_SIZE){
-	    tty->flip.count++;
+	if (tty_buffer_request_room(tty, 1) != 0){
 	    if (err & info->read_status_mask){
 		if(err & CyBREAK){
-		    *tty->flip.flag_buf_ptr++ = TTY_BREAK;
-		    *tty->flip.char_buf_ptr++ = data;
+		    tty_insert_flip_char(tty, data, TTY_BREAK);
 		    if (info->flags & ASYNC_SAK){
 			do_SAK(tty);
 		    }
 		}else if(err & CyFRAME){
-		    *tty->flip.flag_buf_ptr++ = TTY_FRAME;
-		    *tty->flip.char_buf_ptr++ = data;
+		    tty_insert_flip_char(tty, data, TTY_FRAME);
 		}else if(err & CyPARITY){
-		    *tty->flip.flag_buf_ptr++ = TTY_PARITY;
-		    *tty->flip.char_buf_ptr++ = data;
+		    tty_insert_flip_char(tty, data, TTY_PARITY);
 		}else if(err & CyOVERRUN){
-		    *tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
-		    *tty->flip.char_buf_ptr++ = 0;
+		    tty_insert_flip_char(tty, 0, TTY_OVERRUN);
 		    /*
 		       If the flip buffer itself is
 		       overflowing, we still loose
 		       the next incoming character.
 		     */
-		    if(tty->flip.count < TTY_FLIPBUF_SIZE){
-			tty->flip.count++;
-			*tty->flip.flag_buf_ptr++ = TTY_NORMAL;
-			*tty->flip.char_buf_ptr++ = data;
-		    }
+		    tty_insert_flip_char(tty, data, TTY_NORMAL);
+		}
 		/* These two conditions may imply */
 		/* a normal read should be done. */
 		/* else if(data & CyTIMEOUT) */
 		/* else if(data & CySPECHAR) */
 		}else{
-		    *tty->flip.flag_buf_ptr++ = 0;
-		    *tty->flip.char_buf_ptr++ = 0;
+		    tty_insert_flip_char(tty, 0, TTY_NORMAL);
 		}
 	    }else{
-		*tty->flip.flag_buf_ptr++ = 0;
-		*tty->flip.char_buf_ptr++ = 0;
+		    tty_insert_flip_char(tty, data, TTY_NORMAL);
 	    }
 	}else{
 	    /* there was a software buffer overrun
@@ -692,12 +682,7 @@
 #endif
 	while(char_count--){
 	    data = base_addr[CyRDR];
-	    if (tty->flip.count >= TTY_FLIPBUF_SIZE){
-		continue;
-	    }
-	    tty->flip.count++;
-	    *tty->flip.flag_buf_ptr++ = TTY_NORMAL;
-	    *tty->flip.char_buf_ptr++ = data;
+	    tty_insert_flip_char(tty, data, TTY_NORMAL);
 #ifdef CYCLOM_16Y_HACK
 	    udelay(10L);
 #endif
diff --git a/drivers/char/specialix.c b/drivers/char/specialix.c
index 0bbfce4..0a574bd 100644
--- a/drivers/char/specialix.c
+++ b/drivers/char/specialix.c
@@ -85,6 +85,7 @@
 #include <linux/interrupt.h>
 #include <linux/errno.h>
 #include <linux/tty.h>
+#include <linux/tty_flip.h>
 #include <linux/mm.h>
 #include <linux/serial.h>
 #include <linux/fcntl.h>
@@ -665,7 +666,7 @@
 	struct specialix_port *port;
 	struct tty_struct *tty;
 	unsigned char status;
-	unsigned char ch;
+	unsigned char ch, flag;
 
 	func_enter();
 
@@ -676,8 +677,6 @@
 		return;
 	}
 	tty = port->tty;
-	dprintk (SX_DEBUG_RX, "port: %p count: %d BUFF_SIZE: %d\n",
-		 port,  tty->flip.count, TTY_FLIPBUF_SIZE);
 
 	status = sx_in(bp, CD186x_RCSR);
 
@@ -691,7 +690,7 @@
 
 	/* This flip buffer check needs to be below the reading of the
 	   status register to reset the chip's IRQ.... */
-	if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
+	if (tty_buffer_request_room(tty, 1) == 0) {
 		dprintk(SX_DEBUG_FIFO, "sx%d: port %d: Working around flip buffer overflow.\n",
 		       board_No(bp), port_No(port));
 		func_exit();
@@ -712,26 +711,24 @@
 	} else if (status & RCSR_BREAK) {
 		dprintk(SX_DEBUG_RX, "sx%d: port %d: Handling break...\n",
 		       board_No(bp), port_No(port));
-		*tty->flip.flag_buf_ptr++ = TTY_BREAK;
+		flag = TTY_BREAK;
 		if (port->flags & ASYNC_SAK)
 			do_SAK(tty);
 
 	} else if (status & RCSR_PE)
-		*tty->flip.flag_buf_ptr++ = TTY_PARITY;
+		flag = TTY_PARITY;
 
 	else if (status & RCSR_FE)
-		*tty->flip.flag_buf_ptr++ = TTY_FRAME;
+		flag = TTY_FRAME;
 
 	else if (status & RCSR_OE)
-		*tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
+		flag = TTY_OVERRUN;
 
 	else
-		*tty->flip.flag_buf_ptr++ = 0;
+		flag = TTY_NORMAL;
 
-	*tty->flip.char_buf_ptr++ = ch;
-	tty->flip.count++;
-	schedule_delayed_work(&tty->flip.work, 1);
-
+	if(tty_insert_flip_char(tty, ch, flag))
+		tty_flip_buffer_push(tty);
 	func_exit();
 }
 
@@ -755,18 +752,11 @@
 	dprintk (SX_DEBUG_RX, "port: %p: count: %d\n", port, count);
 	port->hits[count > 8 ? 9 : count]++;
 
-	while (count--) {
-		if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
-			printk(KERN_INFO "sx%d: port %d: Working around flip buffer overflow.\n",
-			       board_No(bp), port_No(port));
-			break;
-		}
-		*tty->flip.char_buf_ptr++ = sx_in(bp, CD186x_RDR);
-		*tty->flip.flag_buf_ptr++ = 0;
-		tty->flip.count++;
-	}
-	schedule_delayed_work(&tty->flip.work, 1);
+	tty_buffer_request_room(tty, count);
 
+	while (count--)
+		tty_insert_flip_char(tty, sx_in(bp, CD186x_RDR), TTY_NORMAL);
+	tty_flip_buffer_push(tty);
 	func_exit();
 }
 
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
index 95af2a9..0e20780 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -103,7 +103,7 @@
 	/*{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },*/
 };
 
-static int	stl_nrbrds = sizeof(stl_brdconf) / sizeof(stlconf_t);
+static int	stl_nrbrds = ARRAY_SIZE(stl_brdconf);
 
 /*****************************************************************************/
 
@@ -424,7 +424,7 @@
 	{ PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
 };
 
-static int	stl_nrpcibrds = sizeof(stl_pcibrds) / sizeof(stlpcibrd_t);
+static int	stl_nrpcibrds = ARRAY_SIZE(stl_pcibrds);
 
 #endif
 
@@ -704,7 +704,7 @@
 	230400, 460800, 921600
 };
 
-#define	SC26198_NRBAUDS		(sizeof(sc26198_baudtable) / sizeof(unsigned int))
+#define	SC26198_NRBAUDS		ARRAY_SIZE(sc26198_baudtable)
 
 /*****************************************************************************/
 
@@ -901,7 +901,7 @@
 static int stl_parsebrd(stlconf_t *confp, char **argp)
 {
 	char	*sp;
-	int	nrbrdnames, i;
+	int	i;
 
 #ifdef DEBUG
 	printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
@@ -913,14 +913,13 @@
 	for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
 		*sp = TOLOWER(*sp);
 
-	nrbrdnames = sizeof(stl_brdstr) / sizeof(stlbrdtype_t);
-	for (i = 0; (i < nrbrdnames); i++) {
+	for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++) {
 		if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
 			break;
 	}
-	if (i >= nrbrdnames) {
+	if (i == ARRAY_SIZE(stl_brdstr)) {
 		printk("STALLION: unknown board name, %s?\n", argp[0]);
-		return(0);
+		return 0;
 	}
 
 	confp->brdtype = stl_brdstr[i].type;
@@ -2902,7 +2901,8 @@
 	if (portp->tty != (struct tty_struct *) NULL) {
 		if (portp->tty->driver_data == portp) {
 			portp->stats.ttystate = portp->tty->flags;
-			portp->stats.rxbuffered = portp->tty->flip.count;
+			/* No longer available as a statistic */
+			portp->stats.rxbuffered = 1; /*portp->tty->flip.count; */
 			if (portp->tty->termios != (struct termios *) NULL) {
 				portp->stats.cflags = portp->tty->termios->c_cflag;
 				portp->stats.iflags = portp->tty->termios->c_iflag;
@@ -4046,9 +4046,7 @@
 	if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
 		outb((RDCR + portp->uartaddr), ioaddr);
 		len = inb(ioaddr + EREG_DATA);
-		if ((tty == (struct tty_struct *) NULL) ||
-		    (tty->flip.char_buf_ptr == (char *) NULL) ||
-		    ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
+		if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
 			len = MIN(len, sizeof(stl_unwanted));
 			outb((RDSR + portp->uartaddr), ioaddr);
 			insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
@@ -4057,12 +4055,10 @@
 		} else {
 			len = MIN(len, buflen);
 			if (len > 0) {
+				unsigned char *ptr;
 				outb((RDSR + portp->uartaddr), ioaddr);
-				insb((ioaddr + EREG_DATA), tty->flip.char_buf_ptr, len);
-				memset(tty->flip.flag_buf_ptr, 0, len);
-				tty->flip.flag_buf_ptr += len;
-				tty->flip.char_buf_ptr += len;
-				tty->flip.count += len;
+				tty_prepare_flip_string(tty, &ptr, len);
+				insb((ioaddr + EREG_DATA), ptr, len);
 				tty_schedule_flip(tty);
 				portp->stats.rxtotal += len;
 			}
@@ -4086,8 +4082,7 @@
 				portp->stats.txxoff++;
 			goto stl_rxalldone;
 		}
-		if ((tty != (struct tty_struct *) NULL) &&
-		    ((portp->rxignoremsk & status) == 0)) {
+		if (tty != NULL && (portp->rxignoremsk & status) == 0) {
 			if (portp->rxmarkmsk & status) {
 				if (status & ST_BREAK) {
 					status = TTY_BREAK;
@@ -4107,14 +4102,8 @@
 			} else {
 				status = 0;
 			}
-			if (tty->flip.char_buf_ptr != (char *) NULL) {
-				if (tty->flip.count < TTY_FLIPBUF_SIZE) {
-					*tty->flip.flag_buf_ptr++ = status;
-					*tty->flip.char_buf_ptr++ = ch;
-					tty->flip.count++;
-				}
-				tty_schedule_flip(tty);
-			}
+			tty_insert_flip_char(tty, ch, status);
+			tty_schedule_flip(tty);
 		}
 	} else {
 		printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
@@ -5013,9 +5002,7 @@
 	len = inb(ioaddr + XP_DATA) + 1;
 
 	if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
-		if ((tty == (struct tty_struct *) NULL) ||
-		    (tty->flip.char_buf_ptr == (char *) NULL) ||
-		    ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
+		if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
 			len = MIN(len, sizeof(stl_unwanted));
 			outb(GRXFIFO, (ioaddr + XP_ADDR));
 			insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
@@ -5024,12 +5011,10 @@
 		} else {
 			len = MIN(len, buflen);
 			if (len > 0) {
+				unsigned char *ptr;
 				outb(GRXFIFO, (ioaddr + XP_ADDR));
-				insb((ioaddr + XP_DATA), tty->flip.char_buf_ptr, len);
-				memset(tty->flip.flag_buf_ptr, 0, len);
-				tty->flip.flag_buf_ptr += len;
-				tty->flip.char_buf_ptr += len;
-				tty->flip.count += len;
+				tty_prepare_flip_string(tty, &ptr, len);
+				insb((ioaddr + XP_DATA), ptr, len);
 				tty_schedule_flip(tty);
 				portp->stats.rxtotal += len;
 			}
@@ -5097,14 +5082,8 @@
 			status = 0;
 		}
 
-		if (tty->flip.char_buf_ptr != (char *) NULL) {
-			if (tty->flip.count < TTY_FLIPBUF_SIZE) {
-				*tty->flip.flag_buf_ptr++ = status;
-				*tty->flip.char_buf_ptr++ = ch;
-				tty->flip.count++;
-			}
-			tty_schedule_flip(tty);
-		}
+		tty_insert_flip_char(tty, ch, status);
+		tty_schedule_flip(tty);
 
 		if (status == 0)
 			portp->stats.rxtotal++;
diff --git a/drivers/char/sx.c b/drivers/char/sx.c
index 3ad758a..64bf89c 100644
--- a/drivers/char/sx.c
+++ b/drivers/char/sx.c
@@ -345,9 +345,9 @@
                               0xc8000, 0xd8000, 0xe8000, 0xa0000};
 static int si1_probe_addrs[]= { 0xd0000};
 
-#define NR_SX_ADDRS (sizeof(sx_probe_addrs)/sizeof (int))
-#define NR_SI_ADDRS (sizeof(si_probe_addrs)/sizeof (int))
-#define NR_SI1_ADDRS (sizeof(si1_probe_addrs)/sizeof (int))
+#define NR_SX_ADDRS ARRAY_SIZE(sx_probe_addrs)
+#define NR_SI_ADDRS ARRAY_SIZE(si_probe_addrs)
+#define NR_SI1_ADDRS ARRAY_SIZE(si1_probe_addrs)
 
 
 /* Set the mask to all-ones. This alas, only supports 32 interrupts. 
@@ -1085,6 +1085,7 @@
 	int rx_op;
 	struct tty_struct *tty;
 	int copied=0;
+	unsigned char *rp;
 
 	func_enter2 ();
 	tty = port->gs.tty;
@@ -1095,8 +1096,8 @@
 		sx_dprintk (SX_DEBUG_RECEIVE, "rxop=%d, c = %d.\n", rx_op, c); 
 
 		/* Don't copy more bytes than there is room for in the buffer */
-		if (tty->flip.count + c > TTY_FLIPBUF_SIZE) 
-			c = TTY_FLIPBUF_SIZE - tty->flip.count;
+
+		c = tty_prepare_flip_string(tty, &rp, c);
 
 		sx_dprintk (SX_DEBUG_RECEIVE, "c = %d.\n", c); 
 
@@ -1111,14 +1112,8 @@
 		sx_dprintk (SX_DEBUG_RECEIVE , "Copying over %d chars. First is %d at %lx\n", c, 
 		            read_sx_byte (port->board, CHAN_OFFSET(port,hi_rxbuf) + rx_op),
 		            CHAN_OFFSET(port, hi_rxbuf)); 
-		memcpy_fromio (tty->flip.char_buf_ptr, 
+		memcpy_fromio (rp,
 		               port->board->base + CHAN_OFFSET(port,hi_rxbuf) + rx_op, c);
-		memset(tty->flip.flag_buf_ptr, TTY_NORMAL, c);
-
-		/* Update the kernel buffer end */
-		tty->flip.count += c;
-		tty->flip.char_buf_ptr += c;
-		tty->flip.flag_buf_ptr += c;
 
 		/* This one last. ( Not essential.)
 		   It allows the card to start putting more data into the buffer! 
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c
index 62aa0e5..9f1b466 100644
--- a/drivers/char/synclink.c
+++ b/drivers/char/synclink.c
@@ -1467,6 +1467,7 @@
 {
 	int Fifocount;
 	u16 status;
+	int work = 0;
 	unsigned char DataByte;
  	struct tty_struct *tty = info->tty;
  	struct	mgsl_icount *icount = &info->icount;
@@ -1487,6 +1488,8 @@
 	/* flush the receive FIFO */
 
 	while( (Fifocount = (usc_InReg(info,RICR) >> 8)) ) {
+		int flag;
+
 		/* read one byte from RxFIFO */
 		outw( (inw(info->io_base + CCAR) & 0x0780) | (RDR+LSBONLY),
 		      info->io_base + CCAR );
@@ -1498,13 +1501,9 @@
 				RXSTATUS_OVERRUN + RXSTATUS_BREAK_RECEIVED) )
 			usc_UnlatchRxstatusBits(info,RXSTATUS_ALL);
 		
-		if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-			continue;
-			
-		*tty->flip.char_buf_ptr = DataByte;
 		icount->rx++;
 		
-		*tty->flip.flag_buf_ptr = 0;
+		flag = 0;
 		if ( status & (RXSTATUS_FRAMING_ERROR + RXSTATUS_PARITY_ERROR +
 				RXSTATUS_OVERRUN + RXSTATUS_BREAK_RECEIVED) ) {
 			printk("rxerr=%04X\n",status);					
@@ -1530,41 +1529,31 @@
 			status &= info->read_status_mask;
 		
 			if (status & RXSTATUS_BREAK_RECEIVED) {
-				*tty->flip.flag_buf_ptr = TTY_BREAK;
+				flag = TTY_BREAK;
 				if (info->flags & ASYNC_SAK)
 					do_SAK(tty);
 			} else if (status & RXSTATUS_PARITY_ERROR)
-				*tty->flip.flag_buf_ptr = TTY_PARITY;
+				flag = TTY_PARITY;
 			else if (status & RXSTATUS_FRAMING_ERROR)
-				*tty->flip.flag_buf_ptr = TTY_FRAME;
-			if (status & RXSTATUS_OVERRUN) {
-				/* Overrun is special, since it's
-				 * reported immediately, and doesn't
-				 * affect the current character
-				 */
-				if (tty->flip.count < TTY_FLIPBUF_SIZE) {
-					tty->flip.count++;
-					tty->flip.flag_buf_ptr++;
-					tty->flip.char_buf_ptr++;
-					*tty->flip.flag_buf_ptr = TTY_OVERRUN;
-				}
-			}
+				flag = TTY_FRAME;
 		}	/* end of if (error) */
-		
-		tty->flip.flag_buf_ptr++;
-		tty->flip.char_buf_ptr++;
-		tty->flip.count++;
+		tty_insert_flip_char(tty, DataByte, flag);
+		if (status & RXSTATUS_OVERRUN) {
+			/* Overrun is special, since it's
+			 * reported immediately, and doesn't
+			 * affect the current character
+			 */
+			work += tty_insert_flip_char(tty, 0, TTY_OVERRUN);
+		}
 	}
 
 	if ( debug_level >= DEBUG_LEVEL_ISR ) {
-		printk("%s(%d):mgsl_isr_receive_data flip count=%d\n",
-			__FILE__,__LINE__,tty->flip.count);
 		printk("%s(%d):rx=%d brk=%d parity=%d frame=%d overrun=%d\n",
 			__FILE__,__LINE__,icount->rx,icount->brk,
 			icount->parity,icount->frame,icount->overrun);
 	}
 			
-	if ( tty->flip.count )
+	if(work)
 		tty_flip_buffer_push(tty);
 }
 
@@ -7058,7 +7047,7 @@
 {
 	static unsigned short BitPatterns[] =
 		{ 0x0000, 0xffff, 0xaaaa, 0x5555, 0x1234, 0x6969, 0x9696, 0x0f0f };
-	static unsigned int Patterncount = sizeof(BitPatterns)/sizeof(unsigned short);
+	static unsigned int Patterncount = ARRAY_SIZE(BitPatterns);
 	unsigned int i;
 	BOOLEAN rc = TRUE;
 	unsigned long flags;
@@ -7501,9 +7490,9 @@
  */
 static BOOLEAN mgsl_memory_test( struct mgsl_struct *info )
 {
-	static unsigned long BitPatterns[] = { 0x0, 0x55555555, 0xaaaaaaaa,
-											0x66666666, 0x99999999, 0xffffffff, 0x12345678 };
-	unsigned long Patterncount = sizeof(BitPatterns)/sizeof(unsigned long);
+	static unsigned long BitPatterns[] =
+		{ 0x0, 0x55555555, 0xaaaaaaaa, 0x66666666, 0x99999999, 0xffffffff, 0x12345678 };
+	unsigned long Patterncount = ARRAY_SIZE(BitPatterns);
 	unsigned long i;
 	unsigned long TestLimit = SHARED_MEM_ADDRESS_SIZE/sizeof(unsigned long);
 	unsigned long * TestAddr;
diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c
index 2b9cde9..07c9be6 100644
--- a/drivers/char/synclink_gt.c
+++ b/drivers/char/synclink_gt.c
@@ -1,5 +1,5 @@
 /*
- * $Id: synclink_gt.c,v 4.20 2005/11/08 19:51:55 paulkf Exp $
+ * $Id: synclink_gt.c,v 4.22 2006/01/09 20:16:06 paulkf Exp $
  *
  * Device driver for Microgate SyncLink GT serial adapters.
  *
@@ -75,7 +75,6 @@
 #include <linux/workqueue.h>
 #include <linux/hdlc.h>
 
-#include <asm/serial.h>
 #include <asm/system.h>
 #include <asm/io.h>
 #include <asm/irq.h>
@@ -93,7 +92,7 @@
  * module identification
  */
 static char *driver_name     = "SyncLink GT";
-static char *driver_version  = "$Revision: 4.20 $";
+static char *driver_version  = "$Revision: 4.22 $";
 static char *tty_driver_name = "synclink_gt";
 static char *tty_dev_prefix  = "ttySLG";
 MODULE_LICENSE("GPL");
@@ -289,7 +288,6 @@
 
 	unsigned char __iomem * reg_addr;  /* memory mapped registers address */
 	u32 phys_reg_addr;
-	u32 reg_offset;
 	int reg_addr_requested;
 
 	MGSL_PARAMS params;       /* communications parameters */
@@ -1750,6 +1748,9 @@
 	unsigned char status;
 	struct slgt_desc *bufs = info->rbufs;
 	int i, count;
+	int chars = 0;
+	int stat;
+	unsigned char ch;
 
 	start = end = info->rbuf_current;
 
@@ -1761,16 +1762,15 @@
 		DBGDATA(info, p, count, "rx");
 
 		for(i=0 ; i < count; i+=2, p+=2) {
-			if (tty) {
-				if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-					tty_flip_buffer_push(tty);
-				if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-					break;
-				*tty->flip.char_buf_ptr = *p;
-				*tty->flip.flag_buf_ptr = 0;
+			if (tty && chars) {
+				tty_flip_buffer_push(tty);
+				chars = 0;
 			}
+			ch = *p;
 			icount->rx++;
 
+			stat = 0;
+
 			if ((status = *(p+1) & (BIT9 + BIT8))) {
 				if (status & BIT9)
 					icount->parity++;
@@ -1779,17 +1779,14 @@
 				/* discard char if tty control flags say so */
 				if (status & info->ignore_status_mask)
 					continue;
-				if (tty) {
-					if (status & BIT9)
-						*tty->flip.flag_buf_ptr = TTY_PARITY;
-					else if (status & BIT8)
-						*tty->flip.flag_buf_ptr = TTY_FRAME;
-				}
+				if (status & BIT9)
+					stat = TTY_PARITY;
+				else if (status & BIT8)
+					stat = TTY_FRAME;
 			}
 			if (tty) {
-				tty->flip.flag_buf_ptr++;
-				tty->flip.char_buf_ptr++;
-				tty->flip.count++;
+				tty_insert_flip_char(tty, ch, stat);
+				chars++;
 			}
 		}
 
@@ -1812,7 +1809,7 @@
 			break;
 	}
 
-	if (tty && tty->flip.count)
+	if (tty && chars)
 		tty_flip_buffer_push(tty);
 }
 
@@ -2030,7 +2027,7 @@
 			if (info->tty) {
 				if (!(status & info->ignore_status_mask)) {
 					if (info->read_status_mask & MASK_BREAK) {
-						*info->tty->flip.flag_buf_ptr = TTY_BREAK;
+						tty_insert_flip_char(info->tty, 0, TTY_BREAK);
 						if (info->flags & ASYNC_SAK)
 							do_SAK(info->tty);
 					}
@@ -2978,14 +2975,13 @@
 	else
 		info->reg_addr_requested = 1;
 
-	info->reg_addr = ioremap(info->phys_reg_addr, PAGE_SIZE);
+	info->reg_addr = ioremap(info->phys_reg_addr, SLGT_REG_SIZE);
 	if (!info->reg_addr) {
 		DBGERR(("%s cant map device registers, addr=%08X\n",
 			info->device_name, info->phys_reg_addr));
 		info->init_error = DiagStatus_CantAssignPciResources;
 		goto errout;
 	}
-	info->reg_addr += info->reg_offset;
 	return 0;
 
 errout:
@@ -3006,7 +3002,7 @@
 	}
 
 	if (info->reg_addr) {
-		iounmap(info->reg_addr - info->reg_offset);
+		iounmap(info->reg_addr);
 		info->reg_addr = NULL;
 	}
 }
@@ -3110,12 +3106,6 @@
 		info->irq_level = pdev->irq;
 		info->phys_reg_addr = pci_resource_start(pdev,0);
 
-		/* veremap works on page boundaries
-		 * map full page starting at the page boundary
-		 */
-		info->reg_offset    = info->phys_reg_addr & (PAGE_SIZE-1);
-		info->phys_reg_addr &= ~(PAGE_SIZE-1);
-
 		info->bus_type = MGSL_BUS_TYPE_PCI;
 		info->irq_flags = SA_SHIRQ;
 
diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c
index ee5a40b..960adb2 100644
--- a/drivers/char/synclinkmp.c
+++ b/drivers/char/synclinkmp.c
@@ -2196,7 +2196,7 @@
 			if ( tty ) {
 				if (!(status & info->ignore_status_mask1)) {
 					if (info->read_status_mask1 & BRKD) {
-						*tty->flip.flag_buf_ptr = TTY_BREAK;
+						tty_insert_flip_char(tty, 0, TTY_BREAK);
 						if (info->flags & ASYNC_SAK)
 							do_SAK(tty);
 					}
@@ -2240,16 +2240,10 @@
 
 	while((status = read_reg(info,CST0)) & BIT0)
 	{
+		int flag = 0;
+		int over = 0;
 		DataByte = read_reg(info,TRB);
 
-		if ( tty ) {
-			if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-				continue;
-
-			*tty->flip.char_buf_ptr = DataByte;
-			*tty->flip.flag_buf_ptr = 0;
-		}
-
 		icount->rx++;
 
 		if ( status & (PE + FRME + OVRN) ) {
@@ -2272,42 +2266,34 @@
 
 			if ( tty ) {
 				if (status & PE)
-					*tty->flip.flag_buf_ptr = TTY_PARITY;
+					flag = TTY_PARITY;
 				else if (status & FRME)
-					*tty->flip.flag_buf_ptr = TTY_FRAME;
+					flag = TTY_FRAME;
 				if (status & OVRN) {
 					/* Overrun is special, since it's
 					 * reported immediately, and doesn't
 					 * affect the current character
 					 */
-					if (tty->flip.count < TTY_FLIPBUF_SIZE) {
-						tty->flip.count++;
-						tty->flip.flag_buf_ptr++;
-						tty->flip.char_buf_ptr++;
-						*tty->flip.flag_buf_ptr = TTY_OVERRUN;
-					}
+					over = 1;
 				}
 			}
 		}	/* end of if (error) */
 
 		if ( tty ) {
-			tty->flip.flag_buf_ptr++;
-			tty->flip.char_buf_ptr++;
-			tty->flip.count++;
+			tty_insert_flip_char(tty, DataByte, flag);
+			if (over)
+				tty_insert_flip_char(tty, 0, TTY_OVERRUN);
 		}
 	}
 
 	if ( debug_level >= DEBUG_LEVEL_ISR ) {
-		printk("%s(%d):%s isr_rxrdy() flip count=%d\n",
-			__FILE__,__LINE__,info->device_name,
-			tty ? tty->flip.count : 0);
 		printk("%s(%d):%s rx=%d brk=%d parity=%d frame=%d overrun=%d\n",
 			__FILE__,__LINE__,info->device_name,
 			icount->rx,icount->brk,icount->parity,
 			icount->frame,icount->overrun);
 	}
 
-	if ( tty && tty->flip.count )
+	if ( tty )
 		tty_flip_buffer_push(tty);
 }
 
@@ -5104,7 +5090,7 @@
 int register_test(SLMP_INFO *info)
 {
 	static unsigned char testval[] = {0x00, 0xff, 0xaa, 0x55, 0x69, 0x96};
-	static unsigned int count = sizeof(testval)/sizeof(unsigned char);
+	static unsigned int count = ARRAY_SIZE(testval);
 	unsigned int i;
 	int rc = TRUE;
 	unsigned long flags;
@@ -5422,7 +5408,7 @@
 {
 	static unsigned long testval[] = { 0x0, 0x55555555, 0xaaaaaaaa,
 		0x66666666, 0x99999999, 0xffffffff, 0x12345678 };
-	unsigned long count = sizeof(testval)/sizeof(unsigned long);
+	unsigned long count = ARRAY_SIZE(testval);
 	unsigned long i;
 	unsigned long limit = SCA_MEM_SIZE/sizeof(unsigned long);
 	unsigned long * addr = (unsigned long *)info->memory_base;
diff --git a/drivers/char/tb0219.c b/drivers/char/tb0219.c
index b3d411a..ac2a297 100644
--- a/drivers/char/tb0219.c
+++ b/drivers/char/tb0219.c
@@ -1,7 +1,7 @@
 /*
  *  Driver for TANBAC TB0219 base board.
  *
- *  Copyright (C) 2005  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2005  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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
@@ -27,7 +27,7 @@
 #include <asm/vr41xx/giu.h>
 #include <asm/vr41xx/tb0219.h>
 
-MODULE_AUTHOR("Yoichi Yuasa <yuasa@hh.iij4u.or.jp>");
+MODULE_AUTHOR("Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>");
 MODULE_DESCRIPTION("TANBAC TB0219 base board driver");
 MODULE_LICENSE("GPL");
 
diff --git a/drivers/char/tlclk.c b/drivers/char/tlclk.c
index 12167c0..bc56df8a 100644
--- a/drivers/char/tlclk.c
+++ b/drivers/char/tlclk.c
@@ -211,7 +211,7 @@
 	result = request_irq(telclk_interrupt, &tlclk_interrupt,
 			     SA_INTERRUPT, "telco_clock", tlclk_interrupt);
 	if (result == -EBUSY) {
-		printk(KERN_ERR "telco_clock: Interrupt can't be reserved!\n");
+		printk(KERN_ERR "tlclk: Interrupt can't be reserved.\n");
 		return -EBUSY;
 	}
 	inb(TLCLK_REG6);	/* Clear interrupt events */
@@ -741,7 +741,7 @@
 
 	ret = register_chrdev(tlclk_major, "telco_clock", &tlclk_fops);
 	if (ret < 0) {
-		printk(KERN_ERR "telco_clock: can't get major! %d\n", tlclk_major);
+		printk(KERN_ERR "tlclk: can't get major %d.\n", tlclk_major);
 		return ret;
 	}
 	alarm_events = kzalloc( sizeof(struct tlclk_alarms), GFP_KERNEL);
@@ -750,7 +750,7 @@
 
 	/* Read telecom clock IRQ number (Set by BIOS) */
 	if (!request_region(TLCLK_BASE, 8, "telco_clock")) {
-		printk(KERN_ERR "tlclk: request_region failed! 0x%X\n",
+		printk(KERN_ERR "tlclk: request_region 0x%X failed.\n",
 			TLCLK_BASE);
 		ret = -EBUSY;
 		goto out2;
@@ -758,7 +758,7 @@
 	telclk_interrupt = (inb(TLCLK_REG7) & 0x0f);
 
 	if (0x0F == telclk_interrupt ) { /* not MCPBL0010 ? */
-		printk(KERN_ERR "telclk_interrup = 0x%x non-mcpbl0010 hw\n",
+		printk(KERN_ERR "telclk_interrup = 0x%x non-mcpbl0010 hw.\n",
 			telclk_interrupt);
 		ret = -ENXIO;
 		goto out3;
@@ -768,7 +768,7 @@
 
 	ret = misc_register(&tlclk_miscdev);
 	if (ret < 0) {
-		printk(KERN_ERR " misc_register retruns %d\n", ret);
+		printk(KERN_ERR "tlclk: misc_register returns %d.\n", ret);
 		ret = -EBUSY;
 		goto out3;
 	}
@@ -776,8 +776,7 @@
 	tlclk_device = platform_device_register_simple("telco_clock",
 				-1, NULL, 0);
 	if (!tlclk_device) {
-		printk(KERN_ERR " platform_device_register retruns 0x%X\n",
-			(unsigned int) tlclk_device);
+		printk(KERN_ERR "tlclk: platform_device_register failed.\n");
 		ret = -EBUSY;
 		goto out4;
 	}
@@ -785,7 +784,7 @@
 	ret = sysfs_create_group(&tlclk_device->dev.kobj,
 			&tlclk_attribute_group);
 	if (ret) {
-		printk(KERN_ERR "failed to create sysfs device attributes\n");
+		printk(KERN_ERR "tlclk: failed to create sysfs device attributes.\n");
 		sysfs_remove_group(&tlclk_device->dev.kobj,
 			&tlclk_attribute_group);
 		goto out5;
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 4b1eef5..eb8b5be 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -166,9 +166,12 @@
 	return tty;
 }
 
+static void tty_buffer_free_all(struct tty_struct *);
+
 static inline void free_tty_struct(struct tty_struct *tty)
 {
 	kfree(tty->write_buf);
+	tty_buffer_free_all(tty);
 	kfree(tty);
 }
 
@@ -231,6 +234,200 @@
 }
 
 /*
+ * Tty buffer allocation management
+ */
+
+static void tty_buffer_free_all(struct tty_struct *tty)
+{
+	struct tty_buffer *thead;
+	while((thead = tty->buf.head) != NULL) {
+		tty->buf.head = thead->next;
+		kfree(thead);
+	}
+	while((thead = tty->buf.free) != NULL) {
+		tty->buf.free = thead->next;
+		kfree(thead);
+	}
+	tty->buf.tail = NULL;
+}
+
+static void tty_buffer_init(struct tty_struct *tty)
+{
+	tty->buf.head = NULL;
+	tty->buf.tail = NULL;
+	tty->buf.free = NULL;
+}
+
+static struct tty_buffer *tty_buffer_alloc(size_t size)
+{
+	struct tty_buffer *p = kmalloc(sizeof(struct tty_buffer) + 2 * size, GFP_ATOMIC);
+	if(p == NULL)
+		return NULL;
+	p->used = 0;
+	p->size = size;
+	p->next = NULL;
+	p->char_buf_ptr = (char *)(p->data);
+	p->flag_buf_ptr = (unsigned char *)p->char_buf_ptr + size;
+/* 	printk("Flip create %p\n", p); */
+	return p;
+}
+
+/* Must be called with the tty_read lock held. This needs to acquire strategy
+   code to decide if we should kfree or relink a given expired buffer */
+
+static void tty_buffer_free(struct tty_struct *tty, struct tty_buffer *b)
+{
+	/* Dumb strategy for now - should keep some stats */
+/* 	printk("Flip dispose %p\n", b); */
+	if(b->size >= 512)
+		kfree(b);
+	else {
+		b->next = tty->buf.free;
+		tty->buf.free = b;
+	}
+}
+
+static struct tty_buffer *tty_buffer_find(struct tty_struct *tty, size_t size)
+{
+	struct tty_buffer **tbh = &tty->buf.free;
+	while((*tbh) != NULL) {
+		struct tty_buffer *t = *tbh;
+		if(t->size >= size) {
+			*tbh = t->next;
+			t->next = NULL;
+			t->used = 0;
+			/* DEBUG ONLY */
+			memset(t->data, '*', size);
+/* 			printk("Flip recycle %p\n", t); */
+			return t;
+		}
+		tbh = &((*tbh)->next);
+	}
+	/* Round the buffer size out */
+	size = (size + 0xFF) & ~ 0xFF;
+	return tty_buffer_alloc(size);
+	/* Should possibly check if this fails for the largest buffer we
+	   have queued and recycle that ? */
+}
+
+int tty_buffer_request_room(struct tty_struct *tty, size_t size)
+{
+	struct tty_buffer *b = tty->buf.tail, *n;
+	int left = 0;
+
+	/* OPTIMISATION: We could keep a per tty "zero" sized buffer to
+	   remove this conditional if its worth it. This would be invisible
+	   to the callers */
+	if(b != NULL)
+		left = b->size - b->used;
+	if(left >= size)
+		return size;
+	/* This is the slow path - looking for new buffers to use */
+	n = tty_buffer_find(tty, size);
+	if(n == NULL)
+		return left;
+	if(b != NULL)
+		b->next = n;
+	else
+		tty->buf.head = n;
+	tty->buf.tail = n;
+	return size;
+}
+
+EXPORT_SYMBOL_GPL(tty_buffer_request_room);
+
+int tty_insert_flip_string(struct tty_struct *tty, unsigned char *chars, size_t size)
+{
+	int copied = 0;
+	do {
+		int space = tty_buffer_request_room(tty, size - copied);
+		struct tty_buffer *tb = tty->buf.tail;
+		/* If there is no space then tb may be NULL */
+		if(unlikely(space == 0))
+			break;
+		memcpy(tb->char_buf_ptr + tb->used, chars, space);
+		memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space);
+		tb->used += space;
+		copied += space;
+		chars += space;
+/* 		printk("Flip insert %d.\n", space); */
+	}
+	/* There is a small chance that we need to split the data over
+	   several buffers. If this is the case we must loop */
+	while (unlikely(size > copied));
+	return copied;
+}
+
+EXPORT_SYMBOL_GPL(tty_insert_flip_string);
+
+int tty_insert_flip_string_flags(struct tty_struct *tty, unsigned char *chars, char *flags, size_t size)
+{
+	int copied = 0;
+	do {
+		int space = tty_buffer_request_room(tty, size - copied);
+		struct tty_buffer *tb = tty->buf.tail;
+		/* If there is no space then tb may be NULL */
+		if(unlikely(space == 0))
+			break;
+		memcpy(tb->char_buf_ptr + tb->used, chars, space);
+		memcpy(tb->flag_buf_ptr + tb->used, flags, space);
+		tb->used += space;
+		copied += space;
+		chars += space;
+		flags += space;
+	}
+	/* There is a small chance that we need to split the data over
+	   several buffers. If this is the case we must loop */
+	while (unlikely(size > copied));
+	return copied;
+}
+
+EXPORT_SYMBOL_GPL(tty_insert_flip_string_flags);
+
+
+/*
+ *	Prepare a block of space in the buffer for data. Returns the length
+ *	available and buffer pointer to the space which is now allocated and
+ *	accounted for as ready for normal characters. This is used for drivers
+ *	that need their own block copy routines into the buffer. There is no
+ *	guarantee the buffer is a DMA target!
+ */
+
+int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **chars, size_t size)
+{
+	int space = tty_buffer_request_room(tty, size);
+	struct tty_buffer *tb = tty->buf.tail;
+	*chars = tb->char_buf_ptr + tb->used;
+	memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space);
+	tb->used += space;
+	return space;
+}
+
+EXPORT_SYMBOL_GPL(tty_prepare_flip_string);
+
+/*
+ *	Prepare a block of space in the buffer for data. Returns the length
+ *	available and buffer pointer to the space which is now allocated and
+ *	accounted for as ready for characters. This is used for drivers
+ *	that need their own block copy routines into the buffer. There is no
+ *	guarantee the buffer is a DMA target!
+ */
+
+int tty_prepare_flip_string_flags(struct tty_struct *tty, unsigned char **chars, char **flags, size_t size)
+{
+	int space = tty_buffer_request_room(tty, size);
+	struct tty_buffer *tb = tty->buf.tail;
+	*chars = tb->char_buf_ptr + tb->used;
+	*flags = tb->flag_buf_ptr + tb->used;
+	tb->used += space;
+	return space;
+}
+
+EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags);
+
+
+
+/*
  *	This is probably overkill for real world processors but
  *	they are not on hot paths so a little discipline won't do 
  *	any harm.
@@ -492,6 +689,17 @@
 	if (ld == NULL)
 		return -EINVAL;
 
+	/*
+	 *	No more input please, we are switching. The new ldisc
+	 *	will update this value in the ldisc open function
+	 */
+
+	tty->receive_room = 0;
+
+	/*
+	 *	Problem: What do we do if this blocks ?
+	 */
+
 	tty_wait_until_sent(tty, 0);
 
 	if (tty->ldisc.num == ldisc) {
@@ -560,9 +768,9 @@
 	 *	we say so later on.
 	 */
 
-	work = cancel_delayed_work(&tty->flip.work);
+	work = cancel_delayed_work(&tty->buf.work);
 	/*
-	 * Wait for ->hangup_work and ->flip.work handlers to terminate
+	 * Wait for ->hangup_work and ->buf.work handlers to terminate
 	 */
 	 
 	flush_scheduled_work();
@@ -616,7 +824,7 @@
 	/* Restart it in case no characters kick it off. Safe if
 	   already running */
 	if (work)
-		schedule_delayed_work(&tty->flip.work, 1);
+		schedule_delayed_work(&tty->buf.work, 1);
 	return retval;
 }
 
@@ -1721,10 +1929,10 @@
 	 */
 	clear_bit(TTY_LDISC, &tty->flags);
 	clear_bit(TTY_DONT_FLIP, &tty->flags);
-	cancel_delayed_work(&tty->flip.work);
+	cancel_delayed_work(&tty->buf.work);
 
 	/*
-	 * Wait for ->hangup_work and ->flip.work handlers to terminate
+	 * Wait for ->hangup_work and ->buf.work handlers to terminate
 	 */
 	 
 	flush_scheduled_work();
@@ -2518,17 +2726,15 @@
 
 /*
  * This routine is called out of the software interrupt to flush data
- * from the flip buffer to the line discipline. 
+ * from the buffer chain to the line discipline.
  */
  
 static void flush_to_ldisc(void *private_)
 {
 	struct tty_struct *tty = (struct tty_struct *) private_;
-	unsigned char	*cp;
-	char		*fp;
-	int		count;
 	unsigned long 	flags;
 	struct tty_ldisc *disc;
+	struct tty_buffer *tbuf;
 
 	disc = tty_ldisc_ref(tty);
 	if (disc == NULL)	/*  !TTY_LDISC */
@@ -2538,28 +2744,23 @@
 		/*
 		 * Do it after the next timer tick:
 		 */
-		schedule_delayed_work(&tty->flip.work, 1);
+		schedule_delayed_work(&tty->buf.work, 1);
 		goto out;
 	}
 	spin_lock_irqsave(&tty->read_lock, flags);
-	if (tty->flip.buf_num) {
-		cp = tty->flip.char_buf + TTY_FLIPBUF_SIZE;
-		fp = tty->flip.flag_buf + TTY_FLIPBUF_SIZE;
-		tty->flip.buf_num = 0;
-		tty->flip.char_buf_ptr = tty->flip.char_buf;
-		tty->flip.flag_buf_ptr = tty->flip.flag_buf;
-	} else {
-		cp = tty->flip.char_buf;
-		fp = tty->flip.flag_buf;
-		tty->flip.buf_num = 1;
-		tty->flip.char_buf_ptr = tty->flip.char_buf + TTY_FLIPBUF_SIZE;
-		tty->flip.flag_buf_ptr = tty->flip.flag_buf + TTY_FLIPBUF_SIZE;
+	while((tbuf = tty->buf.head) != NULL) {
+		tty->buf.head = tbuf->next;
+		if (tty->buf.head == NULL)
+			tty->buf.tail = NULL;
+		spin_unlock_irqrestore(&tty->read_lock, flags);
+		/* printk("Process buffer %p for %d\n", tbuf, tbuf->used); */
+		disc->receive_buf(tty, tbuf->char_buf_ptr,
+				       tbuf->flag_buf_ptr,
+				       tbuf->used);
+		spin_lock_irqsave(&tty->read_lock, flags);
+		tty_buffer_free(tty, tbuf);
 	}
-	count = tty->flip.count;
-	tty->flip.count = 0;
 	spin_unlock_irqrestore(&tty->read_lock, flags);
-
-	disc->receive_buf(tty, cp, fp, count);
 out:
 	tty_ldisc_deref(disc);
 }
@@ -2654,11 +2855,12 @@
 	if (tty->low_latency)
 		flush_to_ldisc((void *) tty);
 	else
-		schedule_delayed_work(&tty->flip.work, 1);
+		schedule_delayed_work(&tty->buf.work, 1);
 }
 
 EXPORT_SYMBOL(tty_flip_buffer_push);
 
+
 /*
  * This subroutine initializes a tty structure.
  */
@@ -2669,10 +2871,10 @@
 	tty_ldisc_assign(tty, tty_ldisc_get(N_TTY));
 	tty->pgrp = -1;
 	tty->overrun_time = jiffies;
-	tty->flip.char_buf_ptr = tty->flip.char_buf;
-	tty->flip.flag_buf_ptr = tty->flip.flag_buf;
-	INIT_WORK(&tty->flip.work, flush_to_ldisc, tty);
-	init_MUTEX(&tty->flip.pty_sem);
+	tty->buf.head = tty->buf.tail = NULL;
+	tty_buffer_init(tty);
+	INIT_WORK(&tty->buf.work, flush_to_ldisc, tty);
+	init_MUTEX(&tty->buf.pty_sem);
 	init_MUTEX(&tty->termios_sem);
 	init_waitqueue_head(&tty->write_wait);
 	init_waitqueue_head(&tty->read_wait);
diff --git a/drivers/char/viocons.c b/drivers/char/viocons.c
index 4d75c26..4e53603 100644
--- a/drivers/char/viocons.c
+++ b/drivers/char/viocons.c
@@ -131,7 +131,7 @@
 
 static struct tty_driver *viotty_driver;
 
-void hvlog(char *fmt, ...)
+static void hvlog(char *fmt, ...)
 {
 	int i;
 	unsigned long flags;
@@ -147,7 +147,7 @@
 	spin_unlock_irqrestore(&consoleloglock, flags);
 }
 
-void hvlogOutput(const char *buf, int count)
+static void hvlogOutput(const char *buf, int count)
 {
 	unsigned long flags;
 	int begin;
@@ -476,19 +476,19 @@
  */
 static void initDataEvent(struct viocharlpevent *viochar, HvLpIndex lp)
 {
+	struct HvLpEvent *hev = &viochar->event;
+
 	memset(viochar, 0, sizeof(struct viocharlpevent));
 
-	viochar->event.xFlags.xValid = 1;
-	viochar->event.xFlags.xFunction = HvLpEvent_Function_Int;
-	viochar->event.xFlags.xAckInd = HvLpEvent_AckInd_NoAck;
-	viochar->event.xFlags.xAckType = HvLpEvent_AckType_DeferredAck;
-	viochar->event.xType = HvLpEvent_Type_VirtualIo;
-	viochar->event.xSubtype = viomajorsubtype_chario | viochardata;
-	viochar->event.xSourceLp = HvLpConfig_getLpIndex();
-	viochar->event.xTargetLp = lp;
-	viochar->event.xSizeMinus1 = sizeof(struct viocharlpevent);
-	viochar->event.xSourceInstanceId = viopath_sourceinst(lp);
-	viochar->event.xTargetInstanceId = viopath_targetinst(lp);
+	hev->flags = HV_LP_EVENT_VALID | HV_LP_EVENT_DEFERRED_ACK |
+		HV_LP_EVENT_INT;
+	hev->xType = HvLpEvent_Type_VirtualIo;
+	hev->xSubtype = viomajorsubtype_chario | viochardata;
+	hev->xSourceLp = HvLpConfig_getLpIndex();
+	hev->xTargetLp = lp;
+	hev->xSizeMinus1 = sizeof(struct viocharlpevent);
+	hev->xSourceInstanceId = viopath_sourceinst(lp);
+	hev->xTargetInstanceId = viopath_targetinst(lp);
 }
 
 /*
@@ -752,7 +752,7 @@
 	struct port_info *pi;
 	int reject = 0;
 
-	if (event->xFlags.xFunction == HvLpEvent_Function_Ack) {
+	if (hvlpevent_is_ack(event)) {
 		if (port >= VTTY_PORTS)
 			return;
 
@@ -788,7 +788,7 @@
 	}
 
 	/* This had better require an ack, otherwise complain */
-	if (event->xFlags.xAckInd != HvLpEvent_AckInd_DoAck) {
+	if (!hvlpevent_need_ack(event)) {
 		printk(VIOCONS_KERN_WARN "viocharopen without ack bit!\n");
 		return;
 	}
@@ -856,7 +856,7 @@
 	struct viocharlpevent *cevent = (struct viocharlpevent *)event;
 	u8 port = cevent->virtual_device;
 
-	if (event->xFlags.xFunction == HvLpEvent_Function_Int) {
+	if (hvlpevent_is_int(event)) {
 		if (port >= VTTY_PORTS) {
 			printk(VIOCONS_KERN_WARN
 					"close message from invalid virtual device.\n");
@@ -904,6 +904,7 @@
 	struct viocharlpevent *cevent = (struct viocharlpevent *)event;
 	struct port_info *pi;
 	int index;
+	int num_pushed;
 	u8 port = cevent->virtual_device;
 
 	if (port >= VTTY_PORTS) {
@@ -964,6 +965,7 @@
 	 * functionality will only work if built into the kernel and
 	 * then only if sysrq is enabled through the proc filesystem.
 	 */
+	num_pushed = 0;
 	for (index = 0; index < cevent->len; index++) {
 #ifdef CONFIG_MAGIC_SYSRQ
 		if (sysrq_enabled) {
@@ -993,16 +995,14 @@
 		 * Don't attempt to copy more data into the buffer than we
 		 * have room for because it would fail without indication.
 		 */
-		if ((tty->flip.count + 1) > TTY_FLIPBUF_SIZE) {
+		if(tty_insert_flip_char(tty, cevent->data[index], TTY_NORMAL) == 0) {
 			printk(VIOCONS_KERN_WARN "input buffer overflow!\n");
 			break;
 		}
-		tty_insert_flip_char(tty, cevent->data[index], TTY_NORMAL);
+		num_pushed++;
 	}
 
-	/* if cevent->len == 0 then no data was added to the buffer and flip.count == 0 */
-	if (tty->flip.count)
-		/* The next call resets flip.count when the data is flushed. */
+	if (num_pushed)
 		tty_flip_buffer_push(tty);
 }
 
@@ -1056,8 +1056,7 @@
 		vioHandleConfig(event);
 		break;
 	default:
-		if ((event->xFlags.xFunction == HvLpEvent_Function_Int) &&
-		    (event->xFlags.xAckInd == HvLpEvent_AckInd_DoAck)) {
+		if (hvlpevent_is_int(event) && hvlpevent_need_ack(event)) {
 			event->xRc = HvLpEvent_Rc_InvalidSubtype;
 			HvCallEvent_ackLpEvent(event);
 		}
diff --git a/drivers/char/vme_scc.c b/drivers/char/vme_scc.c
index 19ba836..d932528 100644
--- a/drivers/char/vme_scc.c
+++ b/drivers/char/vme_scc.c
@@ -434,13 +434,7 @@
 		SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
 		return IRQ_HANDLED;
 	}
-	if (tty->flip.count < TTY_FLIPBUF_SIZE) {
-		*tty->flip.char_buf_ptr = ch;
-		*tty->flip.flag_buf_ptr = 0;
-		tty->flip.flag_buf_ptr++;
-		tty->flip.char_buf_ptr++;
-		tty->flip.count++;
-	}
+	tty_insert_flip_char(tty, ch, 0);
 
 	/* Check if another character is already ready; in that case, the
 	 * spcond_int() function must be used, because this character may have an
@@ -487,13 +481,7 @@
 		else
 			err = 0;
 
-		if (tty->flip.count < TTY_FLIPBUF_SIZE) {
-			*tty->flip.char_buf_ptr = ch;
-			*tty->flip.flag_buf_ptr = err;
-			tty->flip.flag_buf_ptr++;
-			tty->flip.char_buf_ptr++;
-			tty->flip.count++;
-		}
+		tty_insert_flip_char(tty, ch, err);
 
 		/* ++TeSche: *All* errors have to be cleared manually,
 		 * else the condition persists for the next chars
@@ -875,13 +863,13 @@
 		local_irq_save(flags);
 #if defined(CONFIG_MVME147_SCC) || defined(CONFIG_MVME162_SCC)
 		if (MACH_IS_MVME147 || MACH_IS_MVME16x) {
-			for (i=0; i<sizeof(mvme_init_tab)/sizeof(*mvme_init_tab); ++i)
+			for (i = 0; i < ARRAY_SIZE(mvme_init_tab); ++i)
 				SCCwrite(mvme_init_tab[i].reg, mvme_init_tab[i].val);
 		}
 #endif
 #if defined(CONFIG_BVME6000_SCC)
 		if (MACH_IS_BVME6000) {
-			for (i=0; i<sizeof(bvme_init_tab)/sizeof(*bvme_init_tab); ++i)
+			for (i = 0; i < ARRAY_SIZE(bvme_init_tab); ++i)
 				SCCwrite(bvme_init_tab[i].reg, bvme_init_tab[i].val);
 		}
 #endif
diff --git a/drivers/char/vr41xx_giu.c b/drivers/char/vr41xx_giu.c
index a5b18e0..2267c7b 100644
--- a/drivers/char/vr41xx_giu.c
+++ b/drivers/char/vr41xx_giu.c
@@ -3,7 +3,7 @@
  *
  *  Copyright (C) 2002 MontaVista Software Inc.
  *	Author: Yoichi Yuasa <yyuasa@mvista.com or source@mvista.com>
- *  Copyright (C) 2003-2005  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2003-2005  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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
@@ -35,7 +35,7 @@
 #include <asm/vr41xx/giu.h>
 #include <asm/vr41xx/vr41xx.h>
 
-MODULE_AUTHOR("Yoichi Yuasa <yuasa@hh.iij4u.or.jp>");
+MODULE_AUTHOR("Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>");
 MODULE_DESCRIPTION("NEC VR4100 series General-purpose I/O Unit driver");
 MODULE_LICENSE("GPL");
 
diff --git a/drivers/char/vr41xx_rtc.c b/drivers/char/vr41xx_rtc.c
index 435b307..bc1b4a1 100644
--- a/drivers/char/vr41xx_rtc.c
+++ b/drivers/char/vr41xx_rtc.c
@@ -1,7 +1,7 @@
 /*
  *  Driver for NEC VR4100 series  Real Time Clock unit.
  *
- *  Copyright (C) 2003-2005  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2003-2005  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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
@@ -37,7 +37,7 @@
 #include <asm/uaccess.h>
 #include <asm/vr41xx/vr41xx.h>
 
-MODULE_AUTHOR("Yoichi Yuasa <yuasa@hh.iij4u.or.jp>");
+MODULE_AUTHOR("Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>");
 MODULE_DESCRIPTION("NEC VR4100 series RTC driver");
 MODULE_LICENSE("GPL");
 
@@ -127,8 +127,6 @@
 		.flags	= IORESOURCE_MEM,	},
 };
 
-#define RTC_NUM_RESOURCES	sizeof(rtc_resource) / sizeof(struct resource)
-
 static inline unsigned long read_elapsed_second(void)
 {
 	unsigned long first_low, first_mid, first_high;
@@ -686,7 +684,8 @@
 		break;
 	}
 
-	rtc_platform_device = platform_device_register_simple("RTC", -1, rtc_resource, RTC_NUM_RESOURCES);
+	rtc_platform_device = platform_device_register_simple("RTC", -1,
+			      rtc_resource, ARRAY_SIZE(rtc_resource));
 	if (IS_ERR(rtc_platform_device))
 		return PTR_ERR(rtc_platform_device);
 
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index e91268e..f1d9cb7 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -2758,29 +2758,6 @@
     vesa_blank_mode = (mode < 4) ? mode : 0;
 }
 
-/*
- * This is called by a timer handler
- */
-static void vesa_powerdown(void)
-{
-    struct vc_data *c = vc_cons[fg_console].d;
-    /*
-     *  Power down if currently suspended (1 or 2),
-     *  suspend if currently blanked (0),
-     *  else do nothing (i.e. already powered down (3)).
-     *  Called only if powerdown features are allowed.
-     */
-    switch (vesa_blank_mode) {
-    case VESA_NO_BLANKING:
-	    c->vc_sw->con_blank(c, VESA_VSYNC_SUSPEND+1, 0);
-	    break;
-    case VESA_VSYNC_SUSPEND:
-    case VESA_HSYNC_SUSPEND:
-	    c->vc_sw->con_blank(c, VESA_POWERDOWN+1, 0);
-	    break;
-    }
-}
-
 void do_blank_screen(int entering_gfx)
 {
 	struct vc_data *vc = vc_cons[fg_console].d;
@@ -2791,8 +2768,7 @@
 	if (console_blanked) {
 		if (blank_state == blank_vesa_wait) {
 			blank_state = blank_off;
-			vesa_powerdown();
-
+			vc->vc_sw->con_blank(vc, vesa_blank_mode + 1, 0);
 		}
 		return;
 	}
@@ -2822,7 +2798,7 @@
 
 	save_screen(vc);
 	/* In case we need to reset origin, blanking hook returns 1 */
-	i = vc->vc_sw->con_blank(vc, 1, 0);
+	i = vc->vc_sw->con_blank(vc, vesa_off_interval ? 1 : (vesa_blank_mode + 1), 0);
 	console_blanked = fg_console + 1;
 	if (i)
 		set_origin(vc);
@@ -2830,13 +2806,10 @@
 	if (console_blank_hook && console_blank_hook(1))
 		return;
 
-	if (vesa_off_interval) {
+	if (vesa_off_interval && vesa_blank_mode) {
 		blank_state = blank_vesa_wait;
 		mod_timer(&console_timer, jiffies + vesa_off_interval);
 	}
-
-    	if (vesa_blank_mode)
-		vc->vc_sw->con_blank(vc, vesa_blank_mode + 1, 0);
 }
 EXPORT_SYMBOL(do_blank_screen);
 
diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c
index 385e529..4b4d7db 100644
--- a/drivers/connector/cn_proc.c
+++ b/drivers/connector/cn_proc.c
@@ -24,6 +24,7 @@
 
 #include <linux/module.h>
 #include <linux/kernel.h>
+#include <linux/ktime.h>
 #include <linux/init.h>
 #include <asm/atomic.h>
 
@@ -56,7 +57,7 @@
 	msg = (struct cn_msg*)buffer;
 	ev = (struct proc_event*)msg->data;
 	get_seq(&msg->seq, &ev->cpu);
-	getnstimestamp(&ev->timestamp);
+	ktime_get_ts(&ev->timestamp); /* get high res monotonic timestamp */
 	ev->what = PROC_EVENT_FORK;
 	ev->event_data.fork.parent_pid = task->real_parent->pid;
 	ev->event_data.fork.parent_tgid = task->real_parent->tgid;
@@ -82,7 +83,7 @@
 	msg = (struct cn_msg*)buffer;
 	ev = (struct proc_event*)msg->data;
 	get_seq(&msg->seq, &ev->cpu);
-	getnstimestamp(&ev->timestamp);
+	ktime_get_ts(&ev->timestamp);
 	ev->what = PROC_EVENT_EXEC;
 	ev->event_data.exec.process_pid = task->pid;
 	ev->event_data.exec.process_tgid = task->tgid;
@@ -116,7 +117,7 @@
 	} else
 	     	return;
 	get_seq(&msg->seq, &ev->cpu);
-	getnstimestamp(&ev->timestamp);
+	ktime_get_ts(&ev->timestamp);
 
 	memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
 	msg->ack = 0; /* not used */
@@ -136,7 +137,7 @@
 	msg = (struct cn_msg*)buffer;
 	ev = (struct proc_event*)msg->data;
 	get_seq(&msg->seq, &ev->cpu);
-	getnstimestamp(&ev->timestamp);
+	ktime_get_ts(&ev->timestamp);
 	ev->what = PROC_EVENT_EXIT;
 	ev->event_data.exit.process_pid = task->pid;
 	ev->event_data.exit.process_tgid = task->tgid;
@@ -169,7 +170,7 @@
 	msg = (struct cn_msg*)buffer;
 	ev = (struct proc_event*)msg->data;
 	msg->seq = rcvd_seq;
-	getnstimestamp(&ev->timestamp);
+	ktime_get_ts(&ev->timestamp);
 	ev->cpu = -1;
 	ev->what = PROC_EVENT_NONE;
 	ev->event_data.ack.err = err;
diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index bda5bce..343379f 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -65,11 +65,11 @@
  *   v0.01 release to linux-ia64@linuxia64.org
  */
 
+#include <linux/capability.h>
 #include <linux/config.h>
 #include <linux/types.h>
 #include <linux/errno.h>
 #include <linux/init.h>
-#include <linux/sched.h>		/* for capable() */
 #include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/string.h>
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index e4d55ad..9b2ebd2 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -2895,6 +2895,8 @@
 		devinfo->mask |= CDC_CLOSE_TRAY;
 	if (!CDROM_CONFIG_FLAGS(drive)->mo_drive)
 		devinfo->mask |= CDC_MO_DRIVE;
+	if (!CDROM_CONFIG_FLAGS(drive)->ram)
+		devinfo->mask |= CDC_RAM;
 
 	devinfo->disk = info->disk;
 	return register_cdrom(devinfo);
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index dea2d4d..8d50df4 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -55,22 +55,9 @@
 #include <asm/io.h>
 #include <asm/bitops.h>
 
-void ide_softirq_done(struct request *rq)
-{
-	request_queue_t *q = rq->q;
-
-	add_disk_randomness(rq->rq_disk);
-	end_that_request_chunk(rq, rq->errors, rq->data_len);
-
-	spin_lock_irq(q->queue_lock);
-	end_that_request_last(rq, rq->errors);
-	spin_unlock_irq(q->queue_lock);
-}
-
 int __ide_end_request(ide_drive_t *drive, struct request *rq, int uptodate,
 		      int nr_sectors)
 {
-	unsigned int nbytes;
 	int ret = 1;
 
 	BUG_ON(!(rq->flags & REQ_STARTED));
@@ -94,26 +81,12 @@
 		HWGROUP(drive)->hwif->ide_dma_on(drive);
 	}
 
-	/*
-	 * For partial completions (or non fs/pc requests), use the regular
-	 * direct completion path.
-	 */
-	nbytes = nr_sectors << 9;
-	if (rq_all_done(rq, nbytes)) {
-		rq->errors = uptodate;
-		rq->data_len = nbytes;
+	if (!end_that_request_first(rq, uptodate, nr_sectors)) {
+		add_disk_randomness(rq->rq_disk);
 		blkdev_dequeue_request(rq);
 		HWGROUP(drive)->rq = NULL;
-		blk_complete_request(rq);
+		end_that_request_last(rq, uptodate);
 		ret = 0;
-	} else {
-		if (!end_that_request_first(rq, uptodate, nr_sectors)) {
-			add_disk_randomness(rq->rq_disk);
-			blkdev_dequeue_request(rq);
-			HWGROUP(drive)->rq = NULL;
-			end_that_request_last(rq, uptodate);
-			ret = 0;
-		}
 	}
 
 	return ret;
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 7cb2d86..e742554 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -1011,8 +1011,6 @@
 	blk_queue_max_hw_segments(q, max_sg_entries);
 	blk_queue_max_phys_segments(q, max_sg_entries);
 
-	blk_queue_softirq_done(q, ide_softirq_done);
-
 	/* assign drive queue */
 	drive->queue = q;
 
diff --git a/drivers/ide/pci/pdc202xx_new.c b/drivers/ide/pci/pdc202xx_new.c
index 211641a..fe06ebb 100644
--- a/drivers/ide/pci/pdc202xx_new.c
+++ b/drivers/ide/pci/pdc202xx_new.c
@@ -39,7 +39,7 @@
 
 #define PDC202_DEBUG_CABLE	0
 
-const static char *pdc_quirk_drives[] = {
+static const char *pdc_quirk_drives[] = {
 	"QUANTUM FIREBALLlct08 08",
 	"QUANTUM FIREBALLP KA6.4",
 	"QUANTUM FIREBALLP KA9.1",
diff --git a/drivers/ide/pci/via82cxxx.c b/drivers/ide/pci/via82cxxx.c
index 86fb1e0..c85b87c 100644
--- a/drivers/ide/pci/via82cxxx.c
+++ b/drivers/ide/pci/via82cxxx.c
@@ -439,7 +439,7 @@
 	hwif->speedproc = &via_set_drive;
 
 
-#if defined(CONFIG_PPC_MULTIPLATFORM) && defined(CONFIG_PPC32)
+#if defined(CONFIG_PPC_CHRP) && defined(CONFIG_PPC32)
 	if(_machine == _MACH_chrp && _chrp_type == _CHRP_Pegasos) {
 		hwif->irq = hwif->channel ? 15 : 14;
 	}
diff --git a/drivers/ieee1394/amdtp.c b/drivers/ieee1394/amdtp.c
index 7589750..17390d7 100644
--- a/drivers/ieee1394/amdtp.c
+++ b/drivers/ieee1394/amdtp.c
@@ -80,7 +80,6 @@
 #include <linux/pci.h>
 #include <linux/interrupt.h>
 #include <linux/poll.h>
-#include <linux/ioctl32.h>
 #include <linux/compat.h>
 #include <linux/cdev.h>
 #include <asm/uaccess.h>
diff --git a/drivers/ieee1394/dv1394.c b/drivers/ieee1394/dv1394.c
index 196db74..efeaa94 100644
--- a/drivers/ieee1394/dv1394.c
+++ b/drivers/ieee1394/dv1394.c
@@ -108,7 +108,6 @@
 #include <linux/types.h>
 #include <linux/vmalloc.h>
 #include <linux/string.h>
-#include <linux/ioctl32.h>
 #include <linux/compat.h>
 #include <linux/cdev.h>
 
diff --git a/drivers/ieee1394/video1394.c b/drivers/ieee1394/video1394.c
index 608479b..39fb883 100644
--- a/drivers/ieee1394/video1394.c
+++ b/drivers/ieee1394/video1394.c
@@ -48,7 +48,6 @@
 #include <linux/vmalloc.h>
 #include <linux/timex.h>
 #include <linux/mm.h>
-#include <linux/ioctl32.h>
 #include <linux/compat.h>
 #include <linux/cdev.h>
 
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index f7490a015..745979f 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -154,10 +154,12 @@
 	__s32 value;
 };
 
+/* Note to the author of this code: did it ever occur to
+   you why the ifdefs are needed? Think about it again. -AK */
 #ifdef CONFIG_X86_64
-#  define COMPAT_TEST test_thread_flag(TIF_IA32)
+#  define COMPAT_TEST is_compat_task()
 #elif defined(CONFIG_IA64)
-#  define COMPAT_TEST IS_IA32_PROCESS(ia64_task_regs(current))
+#  define COMPAT_TEST IS_IA32_PROCESS(task_pt_regs(current))
 #elif defined(CONFIG_S390)
 #  define COMPAT_TEST test_thread_flag(TIF_31BIT)
 #elif defined(CONFIG_MIPS)
diff --git a/drivers/input/input.c b/drivers/input/input.c
index ef5824c..fe33ff3 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -477,8 +477,8 @@
 
 	entry->owner = THIS_MODULE;
 	input_fileops = *entry->proc_fops;
+	input_fileops.poll = input_devices_poll;
 	entry->proc_fops = &input_fileops;
-	entry->proc_fops->poll = input_devices_poll;
 
 	entry = create_proc_read_entry("handlers", 0, proc_bus_input_dir, input_handlers_read, NULL);
 	if (!entry)
diff --git a/drivers/input/joystick/amijoy.c b/drivers/input/joystick/amijoy.c
index 8558a99..ec55a29 100644
--- a/drivers/input/joystick/amijoy.c
+++ b/drivers/input/joystick/amijoy.c
@@ -64,8 +64,8 @@
 		if (amijoy[i]) {
 
 			switch (i) {
-				case 0: data = ~custom.joy0dat; button = (~ciaa.pra >> 6) & 1; break;
-				case 1: data = ~custom.joy1dat; button = (~ciaa.pra >> 7) & 1; break;
+				case 0: data = ~amiga_custom.joy0dat; button = (~ciaa.pra >> 6) & 1; break;
+				case 1: data = ~amiga_custom.joy1dat; button = (~ciaa.pra >> 7) & 1; break;
 			}
 
 			input_regs(amijoy_dev[i], fp);
diff --git a/drivers/input/joystick/grip_mp.c b/drivers/input/joystick/grip_mp.c
index 51a9122..6243894 100644
--- a/drivers/input/joystick/grip_mp.c
+++ b/drivers/input/joystick/grip_mp.c
@@ -53,17 +53,8 @@
 struct grip_mp {
 	struct gameport *gameport;
 	struct grip_port *port[GRIP_MAX_PORTS];
-//	struct input_dev *dev[4];
-//	int mode[4];
-//	int registered[4];
 	int reads;
 	int bads;
-
-	/* individual gamepad states */
-//	int buttons[4];
-//	int xaxes[4];
-//	int yaxes[4];
-//	int dirty[4];     /* has the state been updated? */
 };
 
 /*
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 4a91774..3b0ac3b 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -143,16 +143,6 @@
 	  To compile this driver as a module, choose M here: the
 	  module will be called spitzkbd.
 
-config KEYBOARD_MAPLE
-	tristate "Maple bus keyboard"
-	depends on SH_DREAMCAST && MAPLE
-	help
-	  Say Y here if you have a DreamCast console running Linux and have
-	  a keyboard attached to its Maple bus.
-
-	  To compile this driver as a module, choose M here: the
-	  module will be called maple_keyb.
-
 config KEYBOARD_AMIGA
 	tristate "Amiga keyboard"
 	depends on AMIGA
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index 9ce0b87..6e0afbb 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -5,7 +5,6 @@
 # Each configuration option enables a list of files.
 
 obj-$(CONFIG_KEYBOARD_ATKBD)		+= atkbd.o
-obj-$(CONFIG_KEYBOARD_MAPLE)		+= maple_keyb.o
 obj-$(CONFIG_KEYBOARD_SUNKBD)		+= sunkbd.o
 obj-$(CONFIG_KEYBOARD_LKKBD)		+= lkkbd.o
 obj-$(CONFIG_KEYBOARD_XTKBD)		+= xtkbd.o
diff --git a/drivers/input/misc/wistron_btns.c b/drivers/input/misc/wistron_btns.c
index a05b855..4b415d9b 100644
--- a/drivers/input/misc/wistron_btns.c
+++ b/drivers/input/misc/wistron_btns.c
@@ -92,11 +92,11 @@
 	preempt_enable();
 }
 
-static size_t __init locate_wistron_bios(void __iomem *base)
+static ssize_t __init locate_wistron_bios(void __iomem *base)
 {
 	static const unsigned char __initdata signature[] =
 		{ 0x42, 0x21, 0x55, 0x30 };
-	size_t offset;
+	ssize_t offset;
 
 	for (offset = 0; offset < 0x10000; offset += 0x10) {
 		if (check_signature(base + offset, signature,
@@ -109,7 +109,7 @@
 static int __init map_bios(void)
 {
 	void __iomem *base;
-	size_t offset;
+	ssize_t offset;
 	u32 entry_point;
 
 	base = ioremap(0xF0000, 0x10000); /* Can't fail */
diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
index 574b18a..f15ccf7 100644
--- a/drivers/input/mouse/Kconfig
+++ b/drivers/input/mouse/Kconfig
@@ -86,16 +86,6 @@
 	  To compile this driver as a module, choose M here: the
 	  module will be called pc110pad.
 
-config MOUSE_MAPLE
-	tristate "Maple bus mouse"
-	depends on SH_DREAMCAST && MAPLE
-	help
-	  Say Y if you have a DreamCast console and a mouse attached to
-	  its Maple bus.
-
-	  To compile this driver as a module, choose M here: the
-	  module will be called maplemouse.
-
 config MOUSE_AMIGA
 	tristate "Amiga mouse"
 	depends on AMIGA
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
index 82b330b..21a1de6 100644
--- a/drivers/input/mouse/Makefile
+++ b/drivers/input/mouse/Makefile
@@ -8,7 +8,6 @@
 obj-$(CONFIG_MOUSE_RISCPC)	+= rpcmouse.o
 obj-$(CONFIG_MOUSE_INPORT)	+= inport.o
 obj-$(CONFIG_MOUSE_LOGIBM)	+= logibm.o
-obj-$(CONFIG_MOUSE_MAPLE)	+= maplemouse.o
 obj-$(CONFIG_MOUSE_PC110PAD)	+= pc110pad.o
 obj-$(CONFIG_MOUSE_PS2)		+= psmouse.o
 obj-$(CONFIG_MOUSE_SERIAL)	+= sermouse.o
diff --git a/drivers/input/mouse/amimouse.c b/drivers/input/mouse/amimouse.c
index d13d4c8..c8b2cc9 100644
--- a/drivers/input/mouse/amimouse.c
+++ b/drivers/input/mouse/amimouse.c
@@ -41,7 +41,7 @@
 	unsigned short joy0dat, potgor;
 	int nx, ny, dx, dy;
 
-	joy0dat = custom.joy0dat;
+	joy0dat = amiga_custom.joy0dat;
 
 	nx = joy0dat & 0xff;
 	ny = joy0dat >> 8;
@@ -57,7 +57,7 @@
 	amimouse_lastx = nx;
 	amimouse_lasty = ny;
 
-	potgor = custom.potgor;
+	potgor = amiga_custom.potgor;
 
 	input_regs(amimouse_dev, fp);
 
@@ -77,7 +77,7 @@
 {
 	unsigned short joy0dat;
 
-	joy0dat = custom.joy0dat;
+	joy0dat = amiga_custom.joy0dat;
 
 	amimouse_lastx = joy0dat & 0xff;
 	amimouse_lasty = joy0dat >> 8;
diff --git a/drivers/input/mouse/maplemouse.c b/drivers/input/mouse/maplemouse.c
deleted file mode 100644
index b5b34fe..0000000
--- a/drivers/input/mouse/maplemouse.c
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- *	$Id: maplemouse.c,v 1.2 2004/03/22 01:18:15 lethal Exp $
- *	SEGA Dreamcast mouse driver
- *	Based on drivers/usb/usbmouse.c
- */
-
-#include <linux/kernel.h>
-#include <linux/slab.h>
-#include <linux/input.h>
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/timer.h>
-#include <linux/maple.h>
-
-MODULE_AUTHOR("YAEGASHI Takeshi <t@keshi.org>");
-MODULE_DESCRIPTION("SEGA Dreamcast mouse driver");
-
-static void dc_mouse_callback(struct mapleq *mq)
-{
-	int buttons, relx, rely, relz;
-	struct maple_device *mapledev = mq->dev;
-	struct input_dev *dev = mapledev->private_data;
-	unsigned char *res = mq->recvbuf;
-
-	buttons = ~res[8];
-	relx = *(unsigned short *)(res + 12) - 512;
-	rely = *(unsigned short *)(res + 14) - 512;
-	relz = *(unsigned short *)(res + 16) - 512;
-
-	input_report_key(dev, BTN_LEFT,   buttons & 4);
-	input_report_key(dev, BTN_MIDDLE, buttons & 9);
-	input_report_key(dev, BTN_RIGHT,  buttons & 2);
-	input_report_rel(dev, REL_X,      relx);
-	input_report_rel(dev, REL_Y,      rely);
-	input_report_rel(dev, REL_WHEEL,  relz);
-	input_sync(dev);
-}
-
-static int dc_mouse_connect(struct maple_device *dev)
-{
-	unsigned long data = be32_to_cpu(dev->devinfo.function_data[0]);
-	struct input_dev *input_dev;
-
-	dev->private_data = input_dev = input_allocate_device();
-	if (!input_dev)
-		return -ENOMEM;
-
-	dev->private_data = input_dev;
-
-	input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
-	input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
-	input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL);
-
-	input_dev->name = dev->product_name;
-	input_dev->id.bustype = BUS_MAPLE;
-
-	input_register_device(input_dev);
-
-	maple_getcond_callback(dev, dc_mouse_callback, 1, MAPLE_FUNC_MOUSE);
-
-	return 0;
-}
-
-
-static void dc_mouse_disconnect(struct maple_device *dev)
-{
-	struct input_dev *input_dev = dev->private_data;
-
-	input_unregister_device(input_dev);
-}
-
-
-static struct maple_driver dc_mouse_driver = {
-	.function =	MAPLE_FUNC_MOUSE,
-	.name =		"Dreamcast mouse",
-	.connect =	dc_mouse_connect,
-	.disconnect =	dc_mouse_disconnect,
-};
-
-
-static int __init dc_mouse_init(void)
-{
-	maple_register_driver(&dc_mouse_driver);
-	return 0;
-}
-
-
-static void __exit dc_mouse_exit(void)
-{
-	maple_unregister_driver(&dc_mouse_driver);
-}
-
-
-module_init(dc_mouse_init);
-module_exit(dc_mouse_exit);
-
-/*
- * Local variables:
- * c-basic-offset: 8
- * End:
- */
diff --git a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c
index 1bd88fc..54a680c 100644
--- a/drivers/input/serio/serport.c
+++ b/drivers/input/serio/serport.c
@@ -96,6 +96,7 @@
 	init_waitqueue_head(&serport->wait);
 
 	tty->disc_data = serport;
+	tty->receive_room = 256;
 	set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
 
 	return 0;
@@ -140,17 +141,6 @@
 }
 
 /*
- * serport_ldisc_room() reports how much room we do have for receiving data.
- * Although we in fact have infinite room, we need to specify some value
- * here, and 256 seems to be reasonable.
- */
-
-static int serport_ldisc_room(struct tty_struct *tty)
-{
-	return 256;
-}
-
-/*
  * serport_ldisc_read() just waits indefinitely if everything goes well.
  * However, when the serio driver closes the serio port, it finishes,
  * returning 0 characters.
@@ -237,7 +227,6 @@
 	.read =		serport_ldisc_read,
 	.ioctl =	serport_ldisc_ioctl,
 	.receive_buf =	serport_ldisc_receive,
-	.receive_room =	serport_ldisc_room,
 	.write_wakeup =	serport_ldisc_write_wakeup
 };
 
diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index 11ae0fd..623adbb 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -463,8 +463,7 @@
 #endif
 		goto bad;
 	}
-	if (ld->receive_room &&
-	    ld->receive_room(mp->tty) < datalen) {
+	if (mp->tty->receive_room < datalen) {
 #if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS)
 		printk(KERN_DEBUG "capi: no room in tty\n");
 #endif
diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
index 4643df0..22759c0 100644
--- a/drivers/isdn/i4l/isdn_common.c
+++ b/drivers/isdn/i4l/isdn_common.c
@@ -857,6 +857,118 @@
 	return count;
 }
 
+/*
+ * isdn_readbchan_tty() tries to get data from the read-queue.
+ * It MUST be called with interrupts off.
+ *
+ * Be aware that this is not an atomic operation when sleep != 0, even though
+ * interrupts are turned off! Well, like that we are currently only called
+ * on behalf of a read system call on raw device files (which are documented
+ * to be dangerous and for for debugging purpose only). The inode semaphore
+ * takes care that this is not called for the same minor device number while
+ * we are sleeping, but access is not serialized against simultaneous read()
+ * from the corresponding ttyI device. Can other ugly events, like changes
+ * of the mapping (di,ch)<->minor, happen during the sleep? --he
+ */
+int
+isdn_readbchan_tty(int di, int channel, struct tty_struct *tty, int cisco_hack)
+{
+	int count;
+	int count_pull;
+	int count_put;
+	int dflag;
+	struct sk_buff *skb;
+	char last = 0;
+	int len;
+
+	if (!dev->drv[di])
+		return 0;
+	if (skb_queue_empty(&dev->drv[di]->rpqueue[channel]))
+			return 0;
+
+	len = tty_buffer_request_room(tty, dev->drv[di]->rcvcount[channel]);
+	if(len == 0)
+		return len;
+
+	count = 0;
+	while (len) {
+		if (!(skb = skb_peek(&dev->drv[di]->rpqueue[channel])))
+			break;
+#ifdef CONFIG_ISDN_AUDIO
+		if (ISDN_AUDIO_SKB_LOCK(skb))
+			break;
+		ISDN_AUDIO_SKB_LOCK(skb) = 1;
+		if ((ISDN_AUDIO_SKB_DLECOUNT(skb)) || (dev->drv[di]->DLEflag & (1 << channel))) {
+			char *p = skb->data;
+			unsigned long DLEmask = (1 << channel);
+
+			dflag = 0;
+			count_pull = count_put = 0;
+			while ((count_pull < skb->len) && (len > 0)) {
+				len--;
+				if (dev->drv[di]->DLEflag & DLEmask) {
+					last = DLE;
+					dev->drv[di]->DLEflag &= ~DLEmask;
+				} else {
+					last = *p;
+					if (last == DLE) {
+						dev->drv[di]->DLEflag |= DLEmask;
+						(ISDN_AUDIO_SKB_DLECOUNT(skb))--;
+					}
+					p++;
+					count_pull++;
+				}
+				count_put++;
+			}
+			if (count_pull >= skb->len)
+				dflag = 1;
+		} else {
+#endif
+			/* No DLE's in buff, so simply copy it */
+			dflag = 1;
+			if ((count_pull = skb->len) > len) {
+				count_pull = len;
+				dflag = 0;
+			}
+			count_put = count_pull;
+			if(count_put > 1)
+				tty_insert_flip_string(tty, skb->data, count_put - 1);
+			last = skb->data[count_put] - 1;
+			len -= count_put;
+#ifdef CONFIG_ISDN_AUDIO
+		}
+#endif
+		count += count_put;
+		if (dflag) {
+			/* We got all the data in this buff.
+			 * Now we can dequeue it.
+			 */
+			if(cisco_hack)
+				tty_insert_flip_char(tty, last, 0xFF);
+			else
+				tty_insert_flip_char(tty, last, TTY_NORMAL);
+#ifdef CONFIG_ISDN_AUDIO
+			ISDN_AUDIO_SKB_LOCK(skb) = 0;
+#endif
+			skb = skb_dequeue(&dev->drv[di]->rpqueue[channel]);
+			dev_kfree_skb(skb);
+		} else {
+			tty_insert_flip_char(tty, last, TTY_NORMAL);
+			/* Not yet emptied this buff, so it
+			 * must stay in the queue, for further calls
+			 * but we pull off the data we got until now.
+			 */
+			skb_pull(skb, count_pull);
+#ifdef CONFIG_ISDN_AUDIO
+			ISDN_AUDIO_SKB_LOCK(skb) = 0;
+#endif
+		}
+		dev->drv[di]->rcvcount[channel] -= count_put;
+	}
+	return count;
+}
+
+
 static __inline int
 isdn_minor2drv(int minor)
 {
diff --git a/drivers/isdn/i4l/isdn_common.h b/drivers/isdn/i4l/isdn_common.h
index e27e9c3..082735d 100644
--- a/drivers/isdn/i4l/isdn_common.h
+++ b/drivers/isdn/i4l/isdn_common.h
@@ -37,6 +37,7 @@
 extern void isdn_unexclusive_channel(int di, int ch);
 extern int  isdn_getnum(char **);
 extern int  isdn_readbchan(int, int, u_char *, u_char *, int, wait_queue_head_t *);
+extern int  isdn_readbchan_tty(int, int, struct tty_struct *, int);
 extern int  isdn_get_free_channel(int, int, int, int, int, char *);
 extern int  isdn_writebuf_skb_stub(int, int, int, struct sk_buff *);
 extern int  register_isdn(isdn_if * i);
diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
index 8c404b4..f190a99 100644
--- a/drivers/isdn/i4l/isdn_tty.c
+++ b/drivers/isdn/i4l/isdn_tty.c
@@ -64,37 +64,42 @@
 	int c;
 	int len;
 	struct tty_struct *tty;
+	char last;
 
 	if (info->online) {
 		if ((tty = info->tty)) {
 			if (info->mcr & UART_MCR_RTS) {
-				c = TTY_FLIPBUF_SIZE - tty->flip.count;
 				len = skb->len
 #ifdef CONFIG_ISDN_AUDIO
 					+ ISDN_AUDIO_SKB_DLECOUNT(skb)
 #endif
 					;
+
+				c = tty_buffer_request_room(tty, len);
 				if (c >= len) {
 #ifdef CONFIG_ISDN_AUDIO
-					if (ISDN_AUDIO_SKB_DLECOUNT(skb))
-						while (skb->len--) {
+					if (ISDN_AUDIO_SKB_DLECOUNT(skb)) {
+						int l = skb->len;
+						unsigned char *dp = skb->data;
+						while (--l) {
 							if (*skb->data == DLE)
 								tty_insert_flip_char(tty, DLE, 0);
-							tty_insert_flip_char(tty, *skb->data++, 0);
+							tty_insert_flip_char(tty, *dp++, 0);
+						}
+						last = *dp;
 					} else {
 #endif
-						memcpy(tty->flip.char_buf_ptr,
-						       skb->data, len);
-						tty->flip.count += len;
-						tty->flip.char_buf_ptr += len;
-						memset(tty->flip.flag_buf_ptr, 0, len);
-						tty->flip.flag_buf_ptr += len;
+						if(len > 1)
+							tty_insert_flip_string(tty, skb->data, len - 1);
+						last = skb->data[len - 1];
 #ifdef CONFIG_ISDN_AUDIO
 					}
 #endif
 					if (info->emu.mdmreg[REG_CPPP] & BIT_CPPP)
-						tty->flip.flag_buf_ptr[len - 1] = 0xff;
-					schedule_delayed_work(&tty->flip.work, 1);
+						tty_insert_flip_char(tty, last, 0xFF);
+					else
+						tty_insert_flip_char(tty, last, TTY_NORMAL);
+					tty_flip_buffer_push(tty);
 					kfree_skb(skb);
 					return 1;
 				}
@@ -114,7 +119,6 @@
 	int resched = 0;
 	int midx;
 	int i;
-	int c;
 	int r;
 	struct tty_struct *tty;
 	modem_info *info;
@@ -131,20 +135,13 @@
 #endif
 				if ((tty = info->tty)) {
 					if (info->mcr & UART_MCR_RTS) {
-						c = TTY_FLIPBUF_SIZE - tty->flip.count;
-						if (c > 0) {
-							r = isdn_readbchan(info->isdn_driver, info->isdn_channel,
-									   tty->flip.char_buf_ptr,
-									   tty->flip.flag_buf_ptr, c, NULL);
-							/* CISCO AsyncPPP Hack */
-							if (!(info->emu.mdmreg[REG_CPPP] & BIT_CPPP))
-								memset(tty->flip.flag_buf_ptr, 0, r);
-							tty->flip.count += r;
-							tty->flip.flag_buf_ptr += r;
-							tty->flip.char_buf_ptr += r;
-							if (r)
-								schedule_delayed_work(&tty->flip.work, 1);
-						}
+						/* CISCO AsyncPPP Hack */
+						if (!(info->emu.mdmreg[REG_CPPP] & BIT_CPPP))
+							r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 0);
+						else
+							r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 1);
+						if (r)
+							tty_flip_buffer_push(tty);
 					} else
 						r = 1;
 				} else
@@ -249,7 +246,7 @@
 	}
 #endif
 #endif
-	/* Try to deliver directly via tty-flip-buf if queue is empty */
+	/* Try to deliver directly via tty-buf if queue is empty */
 	spin_lock_irqsave(&info->readlock, flags);
 	if (skb_queue_empty(&dev->drv[di]->rpqueue[channel]))
 		if (isdn_tty_try_read(info, skb)) {
@@ -534,7 +531,7 @@
 /* The next routine is called once from within timer-interrupt
  * triggered within isdn_tty_modem_ncarrier(). It calls
  * isdn_tty_modem_result() to stuff a "NO CARRIER" Message
- * into the tty's flip-buffer.
+ * into the tty's buffer.
  */
 static void
 isdn_tty_modem_do_ncarrier(unsigned long data)
@@ -2347,6 +2344,7 @@
 	u_long flags;
 	struct sk_buff *skb = NULL;
 	char *sp = NULL;
+	int l = strlen(msg);
 
 	if (!msg) {
 		printk(KERN_WARNING "isdn_tty: Null-Message in isdn_tty_at_cout\n");
@@ -2359,16 +2357,16 @@
 		return;
 	}
 
-	/* use queue instead of direct flip, if online and */
-	/* data is in queue or flip buffer is full */
-	if ((info->online) && (((tty->flip.count + strlen(msg)) >= TTY_FLIPBUF_SIZE) ||
-	    (!skb_queue_empty(&dev->drv[info->isdn_driver]->rpqueue[info->isdn_channel])))) {
-		skb = alloc_skb(strlen(msg), GFP_ATOMIC);
+	/* use queue instead of direct, if online and */
+	/* data is in queue or buffer is full */
+	if ((info->online && tty_buffer_request_room(tty, l) < l) ||
+	    (!skb_queue_empty(&dev->drv[info->isdn_driver]->rpqueue[info->isdn_channel]))) {
+		skb = alloc_skb(l, GFP_ATOMIC);
 		if (!skb) {
 			spin_unlock_irqrestore(&info->readlock, flags);
 			return;
 		}
-		sp = skb_put(skb, strlen(msg));
+		sp = skb_put(skb, l);
 #ifdef CONFIG_ISDN_AUDIO
 		ISDN_AUDIO_SKB_DLECOUNT(skb) = 0;
 		ISDN_AUDIO_SKB_LOCK(skb) = 0;
@@ -2392,9 +2390,8 @@
 		if (skb) {
 			*sp++ = c;
 		} else {
-			if (tty->flip.count >= TTY_FLIPBUF_SIZE)
+			if(tty_insert_flip_char(tty, c, TTY_NORMAL) == 0)
 				break;
-			tty_insert_flip_char(tty, c, 0);
 		}
 	}
 	if (skb) {
@@ -2402,12 +2399,12 @@
 		dev->drv[info->isdn_driver]->rcvcount[info->isdn_channel] += skb->len;
 		spin_unlock_irqrestore(&info->readlock, flags);
 		/* Schedule dequeuing */
-		if ((dev->modempoll) && (info->rcvsched))
+		if (dev->modempoll && info->rcvsched)
 			isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 1);
 
 	} else {
 		spin_unlock_irqrestore(&info->readlock, flags);
-		schedule_delayed_work(&tty->flip.work, 1);
+		tty_flip_buffer_push(tty);
 	}
 }
 
diff --git a/drivers/macintosh/adb-iop.c b/drivers/macintosh/adb-iop.c
index 71aeb91..d56d400 100644
--- a/drivers/macintosh/adb-iop.c
+++ b/drivers/macintosh/adb-iop.c
@@ -239,7 +239,7 @@
 
 	local_irq_save(flags);
 
-	req->next = 0;
+	req->next = NULL;
 	req->sent = 0;
 	req->complete = 0;
 	req->reply_len = 0;
diff --git a/drivers/macintosh/via-macii.c b/drivers/macintosh/via-macii.c
index e9a159a..2a2ffe0 100644
--- a/drivers/macintosh/via-macii.c
+++ b/drivers/macintosh/via-macii.c
@@ -260,7 +260,7 @@
 		return -EINVAL;
 	}
 	
-	req->next = 0;
+	req->next = NULL;
 	req->sent = 0;
 	req->complete = 0;
 	req->reply_len = 0;
@@ -295,7 +295,7 @@
 	unsigned long flags;
 
 	local_irq_save(flags);
-	if (via[IFR] & SR_INT) macii_interrupt(0, 0, 0);
+	if (via[IFR] & SR_INT) macii_interrupt(0, NULL, NULL);
 	local_irq_restore(flags);
 }
 
diff --git a/drivers/macintosh/via-maciisi.c b/drivers/macintosh/via-maciisi.c
index a196697..0129fcc 100644
--- a/drivers/macintosh/via-maciisi.c
+++ b/drivers/macintosh/via-maciisi.c
@@ -294,6 +294,24 @@
 		printk(KERN_ERR "maciisi_send_request: poll timed out!\n");
 }
 
+int
+maciisi_request(struct adb_request *req, void (*done)(struct adb_request *),
+	    int nbytes, ...)
+{
+	va_list list;
+	int i;
+
+	req->nbytes = nbytes;
+	req->done = done;
+	req->reply_expected = 0;
+	va_start(list, nbytes);
+	for (i = 0; i < nbytes; i++)
+		req->data[i++] = va_arg(list, int);
+	va_end(list);
+
+	return maciisi_send_request(req, 1);
+}
+
 /* Enqueue a request, and run the queue if possible */
 static int
 maciisi_write(struct adb_request* req)
@@ -308,7 +326,7 @@
 		req->complete = 1;
 		return -EINVAL;
 	}
-	req->next = 0;
+	req->next = NULL;
 	req->sent = 0;
 	req->complete = 0;
 	req->reply_len = 0;
@@ -403,7 +421,7 @@
 
 	local_irq_save(flags);
 	if (via[IFR] & SR_INT) {
-		maciisi_interrupt(0, 0, 0);
+		maciisi_interrupt(0, NULL, NULL);
 	}
 	else /* avoid calling this function too quickly in a loop */
 		udelay(ADB_DELAY);
diff --git a/drivers/macintosh/via-pmu68k.c b/drivers/macintosh/via-pmu68k.c
index 6f80d76..f08e52f 100644
--- a/drivers/macintosh/via-pmu68k.c
+++ b/drivers/macintosh/via-pmu68k.c
@@ -493,7 +493,7 @@
 		return -EINVAL;
 	}
 
-	req->next = 0;
+	req->next = NULL;
 	req->sent = 0;
 	req->complete = 0;
 	local_irq_save(flags);
@@ -717,7 +717,7 @@
 				printk(KERN_ERR "PMU: extra ADB reply\n");
 				return;
 			}
-			req_awaiting_reply = 0;
+			req_awaiting_reply = NULL;
 			if (len <= 2)
 				req->reply_len = 0;
 			else {
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 5c210b0..097d1e54 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -768,6 +768,7 @@
 	md->queue->backing_dev_info.congested_fn = dm_any_congested;
 	md->queue->backing_dev_info.congested_data = md;
 	blk_queue_make_request(md->queue, dm_request);
+	blk_queue_bounce_limit(md->queue, BLK_BOUNCE_ANY);
 	md->queue->unplug_fn = dm_unplug_all;
 	md->queue->issue_flush_fn = dm_flush_all;
 
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 0302723f..1778104e 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1238,6 +1238,7 @@
 	mdk_rdev_t *same_pdev;
 	char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE];
 	struct kobject *ko;
+	char *s;
 
 	if (rdev->mddev) {
 		MD_BUG();
@@ -1277,6 +1278,8 @@
 	bdevname(rdev->bdev,b);
 	if (kobject_set_name(&rdev->kobj, "dev-%s", b) < 0)
 		return -ENOMEM;
+	while ( (s=strchr(rdev->kobj.k_name, '/')) != NULL)
+		*s = '!';
 			
 	list_add(&rdev->same_set, &mddev->disks);
 	rdev->mddev = mddev;
diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index e6aa309..96f7af4 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -303,6 +303,7 @@
 static int multipath_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
 {
 	multipath_conf_t *conf = mddev->private;
+	struct request_queue *q;
 	int found = 0;
 	int path;
 	struct multipath_info *p;
@@ -311,8 +312,8 @@
 
 	for (path=0; path<mddev->raid_disks; path++) 
 		if ((p=conf->multipaths+path)->rdev == NULL) {
-			blk_queue_stack_limits(mddev->queue,
-					       rdev->bdev->bd_disk->queue);
+			q = rdev->bdev->bd_disk->queue;
+			blk_queue_stack_limits(mddev->queue, q);
 
 		/* as we don't honour merge_bvec_fn, we must never risk
 		 * violating it, so limit ->max_sector to one PAGE, as
@@ -320,7 +321,7 @@
 		 * (Note: it is very unlikely that a device with
 		 * merge_bvec_fn will be involved in multipath.)
 		 */
-			if (rdev->bdev->bd_disk->queue->merge_bvec_fn &&
+			if (q->merge_bvec_fn &&
 			    mddev->queue->max_sectors > (PAGE_SIZE>>9))
 				blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9);
 
diff --git a/drivers/media/common/saa7146_core.c b/drivers/media/common/saa7146_core.c
index 2899d34..04c1938 100644
--- a/drivers/media/common/saa7146_core.c
+++ b/drivers/media/common/saa7146_core.c
@@ -109,10 +109,9 @@
 	struct page *pg;
 	int i;
 
-	sglist = kmalloc(sizeof(struct scatterlist)*nr_pages, GFP_KERNEL);
+	sglist = kcalloc(nr_pages, sizeof(struct scatterlist), GFP_KERNEL);
 	if (NULL == sglist)
 		return NULL;
-	memset(sglist,0,sizeof(struct scatterlist)*nr_pages);
 	for (i = 0; i < nr_pages; i++, virt += PAGE_SIZE) {
 		pg = vmalloc_to_page(virt);
 		if (NULL == pg)
@@ -306,15 +305,13 @@
 	struct saa7146_dev *dev;
 	int err = -ENOMEM;
 
-	dev = kmalloc(sizeof(struct saa7146_dev), GFP_KERNEL);
+	/* clear out mem for sure */
+	dev = kzalloc(sizeof(struct saa7146_dev), GFP_KERNEL);
 	if (!dev) {
 		ERR(("out of memory.\n"));
 		goto out;
 	}
 
-	/* clear out mem for sure */
-	memset(dev, 0x0, sizeof(struct saa7146_dev));
-
 	DEB_EE(("pci:%p\n",pci));
 
 	err = pci_enable_device(pci);
diff --git a/drivers/media/common/saa7146_fops.c b/drivers/media/common/saa7146_fops.c
index b614612..f8cf73e 100644
--- a/drivers/media/common/saa7146_fops.c
+++ b/drivers/media/common/saa7146_fops.c
@@ -239,13 +239,12 @@
 	}
 
 	/* allocate per open data */
-	fh = kmalloc(sizeof(*fh),GFP_KERNEL);
+	fh = kzalloc(sizeof(*fh),GFP_KERNEL);
 	if (NULL == fh) {
 		DEB_S(("cannot allocate memory for per open data.\n"));
 		result = -ENOMEM;
 		goto out;
 	}
-	memset(fh,0,sizeof(*fh));
 
 	file->private_data = fh;
 	fh->dev = dev;
@@ -464,12 +463,11 @@
 
 int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv)
 {
-	struct saa7146_vv *vv = kmalloc (sizeof(struct saa7146_vv),GFP_KERNEL);
+	struct saa7146_vv *vv = kzalloc (sizeof(struct saa7146_vv),GFP_KERNEL);
 	if( NULL == vv ) {
 		ERR(("out of memory. aborting.\n"));
 		return -1;
 	}
-	memset(vv, 0x0, sizeof(*vv));
 
 	DEB_EE(("dev:%p\n",dev));
 
diff --git a/drivers/media/dvb/b2c2/flexcop.c b/drivers/media/dvb/b2c2/flexcop.c
index 123ed96..56ba524 100644
--- a/drivers/media/dvb/b2c2/flexcop.c
+++ b/drivers/media/dvb/b2c2/flexcop.c
@@ -220,20 +220,18 @@
 struct flexcop_device *flexcop_device_kmalloc(size_t bus_specific_len)
 {
 	void *bus;
-	struct flexcop_device *fc = kmalloc(sizeof(struct flexcop_device), GFP_KERNEL);
+	struct flexcop_device *fc = kzalloc(sizeof(struct flexcop_device), GFP_KERNEL);
 	if (!fc) {
 		err("no memory");
 		return NULL;
 	}
-	memset(fc, 0, sizeof(struct flexcop_device));
 
-	bus = kmalloc(bus_specific_len, GFP_KERNEL);
+	bus = kzalloc(bus_specific_len, GFP_KERNEL);
 	if (!bus) {
 		err("no memory");
 		kfree(fc);
 		return NULL;
 	}
-	memset(bus, 0, bus_specific_len);
 
 	fc->bus_specific = bus;
 
diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.c b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
index 01b4e0a..f65f64b 100644
--- a/drivers/media/dvb/bt8xx/dvb-bt8xx.c
+++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
@@ -786,10 +786,9 @@
 	struct pci_dev* bttv_pci_dev;
 	int ret;
 
-	if (!(card = kmalloc(sizeof(struct dvb_bt8xx_card), GFP_KERNEL)))
+	if (!(card = kzalloc(sizeof(struct dvb_bt8xx_card), GFP_KERNEL)))
 		return -ENOMEM;
 
-	memset(card, 0, sizeof(*card));
 	init_MUTEX(&card->lock);
 	card->bttv_nr = sub->core->nr;
 	strncpy(card->card_name, sub->core->name, sizeof(sub->core->name));
diff --git a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
index 4bb779a..00347a7 100644
--- a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
+++ b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
@@ -1649,21 +1649,17 @@
 		return -EINVAL;
 
 	/* initialise the system data */
-	if ((ca =
-	     (struct dvb_ca_private *) kmalloc(sizeof(struct dvb_ca_private),
-					       GFP_KERNEL)) == NULL) {
+	if ((ca = kzalloc(sizeof(struct dvb_ca_private), GFP_KERNEL)) == NULL) {
 		ret = -ENOMEM;
 		goto error;
 	}
-	memset(ca, 0, sizeof(struct dvb_ca_private));
 	ca->pub = pubca;
 	ca->flags = flags;
 	ca->slot_count = slot_count;
-	if ((ca->slot_info = kmalloc(sizeof(struct dvb_ca_slot) * slot_count, GFP_KERNEL)) == NULL) {
+	if ((ca->slot_info = kcalloc(slot_count, sizeof(struct dvb_ca_slot), GFP_KERNEL)) == NULL) {
 		ret = -ENOMEM;
 		goto error;
 	}
-	memset(ca->slot_info, 0, sizeof(struct dvb_ca_slot) * slot_count);
 	init_waitqueue_head(&ca->wait_queue);
 	ca->thread_pid = 0;
 	init_waitqueue_head(&ca->thread_queue);
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.c b/drivers/media/dvb/dvb-core/dvb_frontend.c
index 4a08c4a..771f32d 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.c
@@ -1024,13 +1024,12 @@
 	if (down_interruptible (&frontend_mutex))
 		return -ERESTARTSYS;
 
-	fe->frontend_priv = kmalloc(sizeof(struct dvb_frontend_private), GFP_KERNEL);
+	fe->frontend_priv = kzalloc(sizeof(struct dvb_frontend_private), GFP_KERNEL);
 	if (fe->frontend_priv == NULL) {
 		up(&frontend_mutex);
 		return -ENOMEM;
 	}
 	fepriv = fe->frontend_priv;
-	memset(fe->frontend_priv, 0, sizeof(struct dvb_frontend_private));
 
 	init_MUTEX (&fepriv->sem);
 	init_waitqueue_head (&fepriv->wait_queue);
diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
index 358ed15..18d1698 100644
--- a/drivers/media/dvb/dvb-usb/cxusb.c
+++ b/drivers/media/dvb/dvb-usb/cxusb.c
@@ -253,6 +253,26 @@
 	return 0;
 }
 
+static int cxusb_mt352_demod_init(struct dvb_frontend* fe)
+{	/* used in both lgz201 and th7579 */
+	static u8 clock_config []  = { CLOCK_CTL,  0x38, 0x39 };
+	static u8 reset []         = { RESET,      0x80 };
+	static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };
+	static u8 agc_cfg []       = { AGC_TARGET, 0x24, 0x20 };
+	static u8 gpp_ctl_cfg []   = { GPP_CTL,    0x33 };
+	static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
+
+	mt352_write(fe, clock_config,   sizeof(clock_config));
+	udelay(200);
+	mt352_write(fe, reset,          sizeof(reset));
+	mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
+
+	mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
+	mt352_write(fe, gpp_ctl_cfg,    sizeof(gpp_ctl_cfg));
+	mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
+	return 0;
+}
+
 struct cx22702_config cxusb_cx22702_config = {
 	.demod_address = 0x63,
 
@@ -274,6 +294,13 @@
 	.pll_set       = dvb_usb_pll_set,
 };
 
+struct mt352_config cxusb_mt352_config = {
+	/* used in both lgz201 and th7579 */
+	.demod_address = 0x0f,
+	.demod_init    = cxusb_mt352_demod_init,
+	.pll_set       = dvb_usb_pll_set,
+};
+
 /* Callbacks for DVB USB */
 static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_device *d)
 {
@@ -302,6 +329,20 @@
 	return 0;
 }
 
+static int cxusb_lgz201_tuner_attach(struct dvb_usb_device *d)
+{
+	d->pll_addr = 0x61;
+	d->pll_desc = &dvb_pll_lg_z201;
+	return 0;
+}
+
+static int cxusb_dtt7579_tuner_attach(struct dvb_usb_device *d)
+{
+	d->pll_addr = 0x60;
+	d->pll_desc = &dvb_pll_thomson_dtt7579;
+	return 0;
+}
+
 static int cxusb_cx22702_frontend_attach(struct dvb_usb_device *d)
 {
 	u8 b;
@@ -329,6 +370,19 @@
 	return -EIO;
 }
 
+static int cxusb_mt352_frontend_attach(struct dvb_usb_device *d)
+{	/* used in both lgz201 and th7579 */
+	if (usb_set_interface(d->udev,0,0) < 0)
+		err("set interface failed");
+
+	cxusb_ctrl_msg(d,CMD_DIGITAL, NULL, 0, NULL, 0);
+
+	if ((d->fe = mt352_attach(&cxusb_mt352_config, &d->i2c_adap)) != NULL)
+		return 0;
+
+	return -EIO;
+}
+
 static int cxusb_dee1601_frontend_attach(struct dvb_usb_device *d)
 {
 	if (usb_set_interface(d->udev,0,0) < 0)
@@ -370,13 +424,17 @@
 static struct dvb_usb_properties cxusb_medion_properties;
 static struct dvb_usb_properties cxusb_bluebird_lgh064f_properties;
 static struct dvb_usb_properties cxusb_bluebird_dee1601_properties;
+static struct dvb_usb_properties cxusb_bluebird_lgz201_properties;
+static struct dvb_usb_properties cxusb_bluebird_dtt7579_properties;
 
 static int cxusb_probe(struct usb_interface *intf,
 		const struct usb_device_id *id)
 {
 	if (dvb_usb_device_init(intf,&cxusb_medion_properties,THIS_MODULE,NULL) == 0 ||
 		dvb_usb_device_init(intf,&cxusb_bluebird_lgh064f_properties,THIS_MODULE,NULL) == 0 ||
-		dvb_usb_device_init(intf,&cxusb_bluebird_dee1601_properties,THIS_MODULE,NULL) == 0) {
+		dvb_usb_device_init(intf,&cxusb_bluebird_dee1601_properties,THIS_MODULE,NULL) == 0 ||
+		dvb_usb_device_init(intf,&cxusb_bluebird_lgz201_properties,THIS_MODULE,NULL) == 0 ||
+		dvb_usb_device_init(intf,&cxusb_bluebird_dtt7579_properties,THIS_MODULE,NULL) == 0) {
 		return 0;
 	}
 
@@ -389,6 +447,12 @@
 		{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_WARM) },
 		{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DEE1601_COLD) },
 		{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DEE1601_WARM) },
+		{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LGZ201_COLD) },
+		{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LGZ201_WARM) },
+		{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_TH7579_COLD) },
+		{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_TH7579_WARM) },
+		{ USB_DEVICE(USB_VID_DVICO, USB_PID_DIGITALNOW_BLUEBIRD_DEE1601_COLD) },
+		{ USB_DEVICE(USB_VID_DVICO, USB_PID_DIGITALNOW_BLUEBIRD_DEE1601_WARM) },
 		{}		/* Terminating entry */
 };
 MODULE_DEVICE_TABLE (usb, cxusb_table);
@@ -505,12 +569,96 @@
 		}
 	},
 
-	.num_device_descs = 1,
+	.num_device_descs = 2,
 	.devices = {
 		{   "DViCO FusionHDTV DVB-T Dual USB",
 			{ &cxusb_table[3], NULL },
 			{ &cxusb_table[4], NULL },
 		},
+		{   "DigitalNow DVB-T Dual USB",
+			{ &cxusb_table[9],  NULL },
+			{ &cxusb_table[10], NULL },
+		},
+	}
+};
+
+static struct dvb_usb_properties cxusb_bluebird_lgz201_properties = {
+	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
+
+	.usb_ctrl          = DEVICE_SPECIFIC,
+	.firmware          = "dvb-usb-bluebird-01.fw",
+	.download_firmware = bluebird_patch_dvico_firmware_download,
+	/* use usb alt setting 0 for EP4 transfer (dvb-t),
+	   use usb alt setting 7 for EP2 transfer (atsc) */
+
+	.size_of_priv     = sizeof(struct cxusb_state),
+
+	.streaming_ctrl   = cxusb_streaming_ctrl,
+	.power_ctrl       = cxusb_power_ctrl,
+	.frontend_attach  = cxusb_mt352_frontend_attach,
+	.tuner_attach     = cxusb_lgz201_tuner_attach,
+
+	.i2c_algo         = &cxusb_i2c_algo,
+
+	.generic_bulk_ctrl_endpoint = 0x01,
+	/* parameter for the MPEG2-data transfer */
+	.urb = {
+		.type = DVB_USB_BULK,
+		.count = 5,
+		.endpoint = 0x04,
+		.u = {
+			.bulk = {
+				.buffersize = 8192,
+			}
+		}
+	},
+
+	.num_device_descs = 1,
+	.devices = {
+		{   "DViCO FusionHDTV DVB-T USB (LGZ201)",
+			{ &cxusb_table[5], NULL },
+			{ &cxusb_table[6], NULL },
+		},
+	}
+};
+
+static struct dvb_usb_properties cxusb_bluebird_dtt7579_properties = {
+	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
+
+	.usb_ctrl          = DEVICE_SPECIFIC,
+	.firmware          = "dvb-usb-bluebird-01.fw",
+	.download_firmware = bluebird_patch_dvico_firmware_download,
+	/* use usb alt setting 0 for EP4 transfer (dvb-t),
+	   use usb alt setting 7 for EP2 transfer (atsc) */
+
+	.size_of_priv     = sizeof(struct cxusb_state),
+
+	.streaming_ctrl   = cxusb_streaming_ctrl,
+	.power_ctrl       = cxusb_power_ctrl,
+	.frontend_attach  = cxusb_mt352_frontend_attach,
+	.tuner_attach     = cxusb_dtt7579_tuner_attach,
+
+	.i2c_algo         = &cxusb_i2c_algo,
+
+	.generic_bulk_ctrl_endpoint = 0x01,
+	/* parameter for the MPEG2-data transfer */
+	.urb = {
+		.type = DVB_USB_BULK,
+		.count = 5,
+		.endpoint = 0x04,
+		.u = {
+			.bulk = {
+				.buffersize = 8192,
+			}
+		}
+	},
+
+	.num_device_descs = 1,
+	.devices = {
+		{   "DViCO FusionHDTV DVB-T USB (TH7579)",
+			{ &cxusb_table[7], NULL },
+			{ &cxusb_table[8], NULL },
+		},
 	}
 };
 
diff --git a/drivers/media/dvb/dvb-usb/dtt200u-fe.c b/drivers/media/dvb/dvb-usb/dtt200u-fe.c
index 0a94ec2..cd21ddb 100644
--- a/drivers/media/dvb/dvb-usb/dtt200u-fe.c
+++ b/drivers/media/dvb/dvb-usb/dtt200u-fe.c
@@ -156,10 +156,9 @@
 	struct dtt200u_fe_state* state = NULL;
 
 	/* allocate memory for the internal state */
-	state = (struct dtt200u_fe_state*) kmalloc(sizeof(struct dtt200u_fe_state), GFP_KERNEL);
+	state = kzalloc(sizeof(struct dtt200u_fe_state), GFP_KERNEL);
 	if (state == NULL)
 		goto error;
-	memset(state,0,sizeof(struct dtt200u_fe_state));
 
 	deb_info("attaching frontend dtt200u\n");
 
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
index d229343..4a1b9e77 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
@@ -95,6 +95,8 @@
 #define USB_PID_DVICO_BLUEBIRD_TH7579_WARM		0xdb11
 #define USB_PID_DVICO_BLUEBIRD_DEE1601_COLD		0xdb50
 #define USB_PID_DVICO_BLUEBIRD_DEE1601_WARM		0xdb51
+#define USB_PID_DIGITALNOW_BLUEBIRD_DEE1601_COLD	0xdb54
+#define USB_PID_DIGITALNOW_BLUEBIRD_DEE1601_WARM	0xdb55
 #define USB_PID_MEDION_MD95700				0x0932
 #define USB_PID_KYE_DVB_T_COLD				0x701e
 #define USB_PID_KYE_DVB_T_WARM				0x701f
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-init.c b/drivers/media/dvb/dvb-usb/dvb-usb-init.c
index 2e23060..716f8bf 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-init.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-init.c
@@ -154,12 +154,11 @@
 	}
 
 	info("found a '%s' in warm state.",desc->name);
-	d = kmalloc(sizeof(struct dvb_usb_device),GFP_KERNEL);
+		d = kzalloc(sizeof(struct dvb_usb_device),GFP_KERNEL);
 	if (d == NULL) {
 		err("no memory for 'struct dvb_usb_device'");
 		return ret;
 	}
-	memset(d,0,sizeof(struct dvb_usb_device));
 
 	d->udev = udev;
 	memcpy(&d->props,props,sizeof(struct dvb_usb_properties));
@@ -167,13 +166,12 @@
 	d->owner = owner;
 
 	if (d->props.size_of_priv > 0) {
-		d->priv = kmalloc(d->props.size_of_priv,GFP_KERNEL);
+			d->priv = kzalloc(d->props.size_of_priv,GFP_KERNEL);
 		if (d->priv == NULL) {
 			err("no memory for priv in 'struct dvb_usb_device'");
 			kfree(d);
 			return -ENOMEM;
 		}
-		memset(d->priv,0,d->props.size_of_priv);
 	}
 
 	usb_set_intfdata(intf, d);
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-urb.c b/drivers/media/dvb/dvb-usb/dvb-usb-urb.c
index 36b7048..ee82197 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-urb.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-urb.c
@@ -175,15 +175,13 @@
 
 	deb_mem("all in all I will use %lu bytes for streaming\n",num*size);
 
-	if ((d->buf_list = kmalloc(num*sizeof(u8 *), GFP_ATOMIC)) == NULL)
+	if ((d->buf_list = kcalloc(num, sizeof(u8 *), GFP_ATOMIC)) == NULL)
 		return -ENOMEM;
 
-	if ((d->dma_addr = kmalloc(num*sizeof(dma_addr_t), GFP_ATOMIC)) == NULL) {
+	if ((d->dma_addr = kcalloc(num, sizeof(dma_addr_t), GFP_ATOMIC)) == NULL) {
 		kfree(d->buf_list);
 		return -ENOMEM;
 	}
-	memset(d->buf_list,0,num*sizeof(u8 *));
-	memset(d->dma_addr,0,num*sizeof(dma_addr_t));
 
 	d->state |= DVB_USB_STATE_URB_BUF;
 
@@ -285,10 +283,9 @@
 	usb_clear_halt(d->udev,usb_rcvbulkpipe(d->udev,d->props.urb.endpoint));
 
 	/* allocate the array for the data transfer URBs */
-	d->urb_list = kmalloc(d->props.urb.count * sizeof(struct urb *),GFP_KERNEL);
+	d->urb_list = kzalloc(d->props.urb.count * sizeof(struct urb *),GFP_KERNEL);
 	if (d->urb_list == NULL)
 		return -ENOMEM;
-	memset(d->urb_list,0,d->props.urb.count * sizeof(struct urb *));
 	d->state |= DVB_USB_STATE_URB_LIST;
 
 	switch (d->props.urb.type) {
diff --git a/drivers/media/dvb/dvb-usb/vp702x-fe.c b/drivers/media/dvb/dvb-usb/vp702x-fe.c
index 0885d9f..b6d95e1 100644
--- a/drivers/media/dvb/dvb-usb/vp702x-fe.c
+++ b/drivers/media/dvb/dvb-usb/vp702x-fe.c
@@ -281,10 +281,9 @@
 
 struct dvb_frontend * vp702x_fe_attach(struct dvb_usb_device *d)
 {
-	struct vp702x_fe_state *s = kmalloc(sizeof(struct vp702x_fe_state), GFP_KERNEL);
+	struct vp702x_fe_state *s = kzalloc(sizeof(struct vp702x_fe_state), GFP_KERNEL);
 	if (s == NULL)
 		goto error;
-	memset(s,0,sizeof(struct vp702x_fe_state));
 
 	s->d = d;
 	s->fe.ops = &vp702x_fe_ops;
diff --git a/drivers/media/dvb/dvb-usb/vp7045-fe.c b/drivers/media/dvb/dvb-usb/vp7045-fe.c
index 83f1de1..5242cca 100644
--- a/drivers/media/dvb/dvb-usb/vp7045-fe.c
+++ b/drivers/media/dvb/dvb-usb/vp7045-fe.c
@@ -145,10 +145,9 @@
 
 struct dvb_frontend * vp7045_fe_attach(struct dvb_usb_device *d)
 {
-	struct vp7045_fe_state *s = kmalloc(sizeof(struct vp7045_fe_state), GFP_KERNEL);
+	struct vp7045_fe_state *s = kzalloc(sizeof(struct vp7045_fe_state), GFP_KERNEL);
 	if (s == NULL)
 		goto error;
-	memset(s,0,sizeof(struct vp7045_fe_state));
 
 	s->d = d;
 	s->fe.ops = &vp7045_fe_ops;
diff --git a/drivers/media/dvb/frontends/bcm3510.c b/drivers/media/dvb/frontends/bcm3510.c
index 3b132ba..caaee89 100644
--- a/drivers/media/dvb/frontends/bcm3510.c
+++ b/drivers/media/dvb/frontends/bcm3510.c
@@ -782,10 +782,9 @@
 	bcm3510_register_value v;
 
 	/* allocate memory for the internal state */
-	state = kmalloc(sizeof(struct bcm3510_state), GFP_KERNEL);
+	state = kzalloc(sizeof(struct bcm3510_state), GFP_KERNEL);
 	if (state == NULL)
 		goto error;
-	memset(state,0,sizeof(struct bcm3510_state));
 
 	/* setup the state */
 
diff --git a/drivers/media/dvb/frontends/dib3000mb.c b/drivers/media/dvb/frontends/dib3000mb.c
index 6b05536..ae589ad 100644
--- a/drivers/media/dvb/frontends/dib3000mb.c
+++ b/drivers/media/dvb/frontends/dib3000mb.c
@@ -700,10 +700,9 @@
 	struct dib3000_state* state = NULL;
 
 	/* allocate memory for the internal state */
-	state = kmalloc(sizeof(struct dib3000_state), GFP_KERNEL);
+	state = kzalloc(sizeof(struct dib3000_state), GFP_KERNEL);
 	if (state == NULL)
 		goto error;
-	memset(state,0,sizeof(struct dib3000_state));
 
 	/* setup the state */
 	state->i2c = i2c;
diff --git a/drivers/media/dvb/frontends/dib3000mc.c b/drivers/media/dvb/frontends/dib3000mc.c
index c024fad..3b303db 100644
--- a/drivers/media/dvb/frontends/dib3000mc.c
+++ b/drivers/media/dvb/frontends/dib3000mc.c
@@ -832,10 +832,9 @@
 	u16 devid;
 
 	/* allocate memory for the internal state */
-	state = kmalloc(sizeof(struct dib3000_state), GFP_KERNEL);
+	state = kzalloc(sizeof(struct dib3000_state), GFP_KERNEL);
 	if (state == NULL)
 		goto error;
-	memset(state,0,sizeof(struct dib3000_state));
 
 	/* setup the state */
 	state->i2c = i2c;
diff --git a/drivers/media/dvb/frontends/dvb-pll.c b/drivers/media/dvb/frontends/dvb-pll.c
index a3d57ce..757075f 100644
--- a/drivers/media/dvb/frontends/dvb-pll.c
+++ b/drivers/media/dvb/frontends/dvb-pll.c
@@ -345,6 +345,23 @@
 };
 EXPORT_SYMBOL(dvb_pll_tbmv30111in);
 
+/*
+ * Philips SD1878 Tuner.
+ */
+struct dvb_pll_desc dvb_pll_philips_sd1878_tda8261 = {
+	.name  = "Philips SD1878",
+	.min   =  950000,
+	.max   = 2150000,
+	.count = 4,
+	.entries = {
+		{ 1250000, 499, 500, 0xc4, 0x00},
+		{ 1550000, 499, 500, 0xc4, 0x40},
+		{ 2050000, 499, 500, 0xc4, 0x80},
+		{ 2150000, 499, 500, 0xc4, 0xc0},
+	},
+};
+EXPORT_SYMBOL(dvb_pll_philips_sd1878_tda8261);
+
 /* ----------------------------------------------------------- */
 /* code                                                        */
 
diff --git a/drivers/media/dvb/frontends/dvb-pll.h b/drivers/media/dvb/frontends/dvb-pll.h
index 24d4d2e..f682c09 100644
--- a/drivers/media/dvb/frontends/dvb-pll.h
+++ b/drivers/media/dvb/frontends/dvb-pll.h
@@ -39,6 +39,7 @@
 extern struct dvb_pll_desc dvb_pll_tuv1236d;
 extern struct dvb_pll_desc dvb_pll_tdhu2;
 extern struct dvb_pll_desc dvb_pll_tbmv30111in;
+extern struct dvb_pll_desc dvb_pll_philips_sd1878_tda8261;
 
 int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf,
 		      u32 freq, int bandwidth);
diff --git a/drivers/media/dvb/frontends/lgdt330x.c b/drivers/media/dvb/frontends/lgdt330x.c
index 9d21464..4691ac5 100644
--- a/drivers/media/dvb/frontends/lgdt330x.c
+++ b/drivers/media/dvb/frontends/lgdt330x.c
@@ -714,10 +714,9 @@
 	u8 buf[1];
 
 	/* Allocate memory for the internal state */
-	state = (struct lgdt330x_state*) kmalloc(sizeof(struct lgdt330x_state), GFP_KERNEL);
+	state = kzalloc(sizeof(struct lgdt330x_state), GFP_KERNEL);
 	if (state == NULL)
 		goto error;
-	memset(state,0,sizeof(*state));
 
 	/* Setup the state */
 	state->config = config;
diff --git a/drivers/media/dvb/frontends/mt352.c b/drivers/media/dvb/frontends/mt352.c
index f0c610f..aaaec90 100644
--- a/drivers/media/dvb/frontends/mt352.c
+++ b/drivers/media/dvb/frontends/mt352.c
@@ -535,9 +535,8 @@
 	struct mt352_state* state = NULL;
 
 	/* allocate memory for the internal state */
-	state = kmalloc(sizeof(struct mt352_state), GFP_KERNEL);
+	state = kzalloc(sizeof(struct mt352_state), GFP_KERNEL);
 	if (state == NULL) goto error;
-	memset(state,0,sizeof(*state));
 
 	/* setup the state */
 	state->i2c = i2c;
diff --git a/drivers/media/dvb/frontends/nxt200x.c b/drivers/media/dvb/frontends/nxt200x.c
index aeafef4..78d2b93 100644
--- a/drivers/media/dvb/frontends/nxt200x.c
+++ b/drivers/media/dvb/frontends/nxt200x.c
@@ -1110,10 +1110,9 @@
 	u8 buf [] = {0,0,0,0,0};
 
 	/* allocate memory for the internal state */
-	state = (struct nxt200x_state*) kmalloc(sizeof(struct nxt200x_state), GFP_KERNEL);
+	state = kzalloc(sizeof(struct nxt200x_state), GFP_KERNEL);
 	if (state == NULL)
 		goto error;
-	memset(state,0,sizeof(*state));
 
 	/* setup the state */
 	state->config = config;
diff --git a/drivers/media/dvb/pluto2/pluto2.c b/drivers/media/dvb/pluto2/pluto2.c
index bbebd1c..1c5316e 100644
--- a/drivers/media/dvb/pluto2/pluto2.c
+++ b/drivers/media/dvb/pluto2/pluto2.c
@@ -584,11 +584,10 @@
 	struct dmx_demux *dmx;
 	int ret = -ENOMEM;
 
-	pluto = kmalloc(sizeof(struct pluto), GFP_KERNEL);
+	pluto = kzalloc(sizeof(struct pluto), GFP_KERNEL);
 	if (!pluto)
 		goto out;
 
-	memset(pluto, 0, sizeof(struct pluto));
 	pluto->pdev = pdev;
 
 	ret = pci_enable_device(pdev);
diff --git a/drivers/media/dvb/ttpci/av7110.c b/drivers/media/dvb/ttpci/av7110.c
index 8ce4146..327a808 100644
--- a/drivers/media/dvb/ttpci/av7110.c
+++ b/drivers/media/dvb/ttpci/av7110.c
@@ -2565,14 +2565,12 @@
 	}
 
 	/* prepare the av7110 device struct */
-	av7110 = kmalloc(sizeof(struct av7110), GFP_KERNEL);
+	av7110 = kzalloc(sizeof(struct av7110), GFP_KERNEL);
 	if (!av7110) {
 		dprintk(1, "out of memory\n");
 		return -ENOMEM;
 	}
 
-	memset(av7110, 0, sizeof(struct av7110));
-
 	av7110->card_name = (char*) pci_ext->ext_priv;
 	av7110->dev = dev;
 	dev->ext_priv = av7110;
diff --git a/drivers/media/dvb/ttpci/budget-av.c b/drivers/media/dvb/ttpci/budget-av.c
index f9d0045..1465c04 100644
--- a/drivers/media/dvb/ttpci/budget-av.c
+++ b/drivers/media/dvb/ttpci/budget-av.c
@@ -37,6 +37,7 @@
 #include "stv0299.h"
 #include "tda10021.h"
 #include "tda1004x.h"
+#include "dvb-pll.h"
 #include <media/saa7146_vv.h>
 #include <linux/module.h>
 #include <linux/errno.h>
@@ -864,8 +865,117 @@
 	.request_firmware = philips_tu1216_request_firmware,
 };
 
+static u8 philips_sd1878_inittab[] = {
+	0x01, 0x15,
+	0x02, 0x30,
+	0x03, 0x00,
+	0x04, 0x7d,
+	0x05, 0x35,
+	0x06, 0x40,
+	0x07, 0x00,
+	0x08, 0x43,
+	0x09, 0x02,
+	0x0C, 0x51,
+	0x0D, 0x82,
+	0x0E, 0x23,
+	0x10, 0x3f,
+	0x11, 0x84,
+	0x12, 0xb9,
+	0x15, 0xc9,
+	0x16, 0x19,
+	0x17, 0x8c,
+	0x18, 0x59,
+	0x19, 0xf8,
+	0x1a, 0xfe,
+	0x1c, 0x7f,
+	0x1d, 0x00,
+	0x1e, 0x00,
+	0x1f, 0x50,
+	0x20, 0x00,
+	0x21, 0x00,
+	0x22, 0x00,
+	0x23, 0x00,
+	0x28, 0x00,
+	0x29, 0x28,
+	0x2a, 0x14,
+	0x2b, 0x0f,
+	0x2c, 0x09,
+	0x2d, 0x09,
+	0x31, 0x1f,
+	0x32, 0x19,
+	0x33, 0xfc,
+	0x34, 0x93,
+	0xff, 0xff
+};
 
+static int philips_sd1878_tda8261_pll_set(struct dvb_frontend *fe,
+		struct i2c_adapter *i2c,
+		struct dvb_frontend_parameters *params)
+{
+	u8              buf[4];
+	int             rc;
+	struct i2c_msg  tuner_msg = {.addr=0x60,.flags=0,.buf=buf,.len=sizeof(buf)};
 
+	if((params->frequency < 950000) || (params->frequency > 2150000))
+		return -EINVAL;
+
+	rc=dvb_pll_configure(&dvb_pll_philips_sd1878_tda8261, buf,
+			params->frequency, 0);
+	if(rc < 0) return rc;
+
+	if(i2c_transfer(i2c, &tuner_msg, 1) != 1)
+		return -EIO;
+
+    return 0;
+}
+
+static int philips_sd1878_ci_set_symbol_rate(struct dvb_frontend *fe,
+		u32 srate, u32 ratio)
+{
+	u8 aclk = 0;
+	u8 bclk = 0;
+	u8 m1;
+
+	aclk = 0xb5;
+	if (srate < 2000000)
+		bclk = 0x86;
+	else if (srate < 5000000)
+		bclk = 0x89;
+	else if (srate < 15000000)
+		bclk = 0x8f;
+	else if (srate < 45000000)
+		bclk = 0x95;
+
+	m1 = 0x14;
+	if (srate < 4000000)
+		m1 = 0x10;
+
+	stv0299_writereg(fe, 0x0e, 0x23);
+	stv0299_writereg(fe, 0x0f, 0x94);
+	stv0299_writereg(fe, 0x10, 0x39);
+	stv0299_writereg(fe, 0x13, aclk);
+	stv0299_writereg(fe, 0x14, bclk);
+	stv0299_writereg(fe, 0x15, 0xc9);
+	stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
+	stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
+	stv0299_writereg(fe, 0x21, (ratio) & 0xf0);
+	stv0299_writereg(fe, 0x0f, 0x80 | m1);
+
+	return 0;
+}
+
+static struct stv0299_config philips_sd1878_config = {
+	.demod_address = 0x68,
+	.inittab = philips_sd1878_inittab,
+	.mclk = 88000000UL,
+	.invert = 0,
+	.skip_reinit = 0,
+	.lock_output = STV0229_LOCKOUTPUT_1,
+	.volt13_op0_op1 = STV0299_VOLT13_OP0,
+	.min_delay_ms = 100,
+	.set_symbol_rate = philips_sd1878_ci_set_symbol_rate,
+	.pll_set = philips_sd1878_tda8261_pll_set,
+};
 
 static u8 read_pwm(struct budget_av *budget_av)
 {
@@ -886,7 +996,10 @@
 #define SUBID_DVBS_KNC1_PLUS	0x0011
 #define SUBID_DVBS_TYPHOON	0x4f56
 #define SUBID_DVBS_CINERGY1200	0x1154
+#define SUBID_DVBS_CYNERGY1200N 0x1155
 
+#define SUBID_DVBS_TV_STAR	0x0014
+#define SUBID_DVBS_TV_STAR_CI	0x0016
 #define SUBID_DVBC_KNC1		0x0020
 #define SUBID_DVBC_KNC1_PLUS	0x0021
 #define SUBID_DVBC_CINERGY1200	0x1156
@@ -922,6 +1035,13 @@
 		}
 		break;
 
+	case SUBID_DVBS_TV_STAR:
+	case SUBID_DVBS_TV_STAR_CI:
+	case SUBID_DVBS_CYNERGY1200N:
+		fe = stv0299_attach(&philips_sd1878_config,
+				&budget_av->budget.i2c_adap);
+		break;
+
 	case SUBID_DVBS_KNC1_PLUS:
 	case SUBID_DVBS_TYPHOON:
 		fe = stv0299_attach(&typhoon_config,
@@ -1027,11 +1147,9 @@
 
 	dprintk(2, "dev: %p\n", dev);
 
-	if (!(budget_av = kmalloc(sizeof(struct budget_av), GFP_KERNEL)))
+	if (!(budget_av = kzalloc(sizeof(struct budget_av), GFP_KERNEL)))
 		return -ENOMEM;
 
-	memset(budget_av, 0, sizeof(struct budget_av));
-
 	budget_av->has_saa7113 = 0;
 	budget_av->budget.ci_present = 0;
 
@@ -1166,10 +1284,12 @@
 MAKE_BUDGET_INFO(knc1s, "KNC1 DVB-S", BUDGET_KNC1S);
 MAKE_BUDGET_INFO(knc1c, "KNC1 DVB-C", BUDGET_KNC1C);
 MAKE_BUDGET_INFO(knc1t, "KNC1 DVB-T", BUDGET_KNC1T);
+MAKE_BUDGET_INFO(kncxs, "KNC TV STAR DVB-S", BUDGET_TVSTAR);
 MAKE_BUDGET_INFO(knc1sp, "KNC1 DVB-S Plus", BUDGET_KNC1SP);
 MAKE_BUDGET_INFO(knc1cp, "KNC1 DVB-C Plus", BUDGET_KNC1CP);
 MAKE_BUDGET_INFO(knc1tp, "KNC1 DVB-T Plus", BUDGET_KNC1TP);
 MAKE_BUDGET_INFO(cin1200s, "TerraTec Cinergy 1200 DVB-S", BUDGET_CIN1200S);
+MAKE_BUDGET_INFO(cin1200sn, "TerraTec Cinergy 1200 DVB-S", BUDGET_CIN1200S);
 MAKE_BUDGET_INFO(cin1200c, "Terratec Cinergy 1200 DVB-C", BUDGET_CIN1200C);
 MAKE_BUDGET_INFO(cin1200t, "Terratec Cinergy 1200 DVB-T", BUDGET_CIN1200T);
 
@@ -1178,11 +1298,14 @@
 	MAKE_EXTENSION_PCI(knc1s, 0x1131, 0x0010),
 	MAKE_EXTENSION_PCI(knc1s, 0x1894, 0x0010),
 	MAKE_EXTENSION_PCI(knc1sp, 0x1131, 0x0011),
+	MAKE_EXTENSION_PCI(kncxs, 0x1894, 0x0014),
+	MAKE_EXTENSION_PCI(kncxs, 0x1894, 0x0016),
 	MAKE_EXTENSION_PCI(knc1c, 0x1894, 0x0020),
 	MAKE_EXTENSION_PCI(knc1cp, 0x1894, 0x0021),
 	MAKE_EXTENSION_PCI(knc1t, 0x1894, 0x0030),
 	MAKE_EXTENSION_PCI(knc1tp, 0x1894, 0x0031),
 	MAKE_EXTENSION_PCI(cin1200s, 0x153b, 0x1154),
+	MAKE_EXTENSION_PCI(cin1200sn, 0x153b, 0x1155),
 	MAKE_EXTENSION_PCI(cin1200c, 0x153b, 0x1156),
 	MAKE_EXTENSION_PCI(cin1200t, 0x153b, 0x1157),
 	{
diff --git a/drivers/media/dvb/ttpci/budget.h b/drivers/media/dvb/ttpci/budget.h
index c8d48cf..c7bb63c 100644
--- a/drivers/media/dvb/ttpci/budget.h
+++ b/drivers/media/dvb/ttpci/budget.h
@@ -95,6 +95,7 @@
 #define BUDGET_KNC1SP		   11
 #define BUDGET_KNC1CP		   12
 #define BUDGET_KNC1TP		   13
+#define BUDGET_TVSTAR		   14
 
 #define BUDGET_VIDEO_PORTA         0
 #define BUDGET_VIDEO_PORTB         1
diff --git a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
index 104df61..5a13c47 100644
--- a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
+++ b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
@@ -1489,11 +1489,9 @@
 
 	if (intf->altsetting->desc.bInterfaceNumber != 1) return -ENODEV;
 
-	if (!(ttusb = kmalloc(sizeof(struct ttusb), GFP_KERNEL)))
+	if (!(ttusb = kzalloc(sizeof(struct ttusb), GFP_KERNEL)))
 		return -ENOMEM;
 
-	memset(ttusb, 0, sizeof(struct ttusb));
-
 	ttusb->dev = udev;
 	ttusb->c = 0;
 	ttusb->mux_state = 0;
diff --git a/drivers/media/dvb/ttusb-dec/ttusb_dec.c b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
index d8966d1..df83117 100644
--- a/drivers/media/dvb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
@@ -1606,15 +1606,13 @@
 
 	udev = interface_to_usbdev(intf);
 
-	if (!(dec = kmalloc(sizeof(struct ttusb_dec), GFP_KERNEL))) {
+	if (!(dec = kzalloc(sizeof(struct ttusb_dec), GFP_KERNEL))) {
 		printk("%s: couldn't allocate memory.\n", __FUNCTION__);
 		return -ENOMEM;
 	}
 
 	usb_set_intfdata(intf, (void *)dec);
 
-	memset(dec, 0, sizeof(struct ttusb_dec));
-
 	switch (le16_to_cpu(id->idProduct)) {
 	case 0x1006:
 		ttusb_dec_set_model(dec, TTUSB_DEC3000S);
diff --git a/drivers/media/radio/radio-gemtek-pci.c b/drivers/media/radio/radio-gemtek-pci.c
index 69ac8aa..8e499b8 100644
--- a/drivers/media/radio/radio-gemtek-pci.c
+++ b/drivers/media/radio/radio-gemtek-pci.c
@@ -318,11 +318,10 @@
 	struct gemtek_pci_card *card;
 	struct video_device *devradio;
 
-	if ( (card = kmalloc( sizeof( struct gemtek_pci_card ), GFP_KERNEL )) == NULL ) {
+	if ( (card = kzalloc( sizeof( struct gemtek_pci_card ), GFP_KERNEL )) == NULL ) {
 		printk( KERN_ERR "gemtek_pci: out of memory\n" );
 		return -ENOMEM;
 	}
-	memset( card, 0, sizeof( struct gemtek_pci_card ) );
 
 	if ( pci_enable_device( pci_dev ) ) 
 		goto err_pci;
diff --git a/drivers/media/radio/radio-maestro.c b/drivers/media/radio/radio-maestro.c
index c30effd..36c9f5b 100644
--- a/drivers/media/radio/radio-maestro.c
+++ b/drivers/media/radio/radio-maestro.c
@@ -27,34 +27,30 @@
 #include <linux/pci.h>
 #include <linux/videodev.h>
 
-#define DRIVER_VERSION	"0.04"
+#define DRIVER_VERSION	"0.05"
 
-#define PCI_VENDOR_ESS                  0x125D
-#define PCI_DEVICE_ID_ESS_ESS1968       0x1968          /* Maestro 2    */
-#define PCI_DEVICE_ID_ESS_ESS1978       0x1978          /* Maestro 2E   */
-
-#define GPIO_DATA       0x60   /* port offset from ESS_IO_BASE */
+#define GPIO_DATA	0x60   /* port offset from ESS_IO_BASE */
 
 #define IO_MASK		4      /* mask      register offset from GPIO_DATA
 				bits 1=unmask write to given bit */
 #define IO_DIR		8      /* direction register offset from GPIO_DATA
 				bits 0/1=read/write direction */
 
-#define GPIO6           0x0040 /* mask bits for GPIO lines */
-#define GPIO7           0x0080
-#define GPIO8           0x0100
-#define GPIO9           0x0200
+#define GPIO6		0x0040 /* mask bits for GPIO lines */
+#define GPIO7		0x0080
+#define GPIO8		0x0100
+#define GPIO9		0x0200
 
-#define STR_DATA        GPIO6  /* radio TEA5757 pins and GPIO bits */
-#define STR_CLK         GPIO7
-#define STR_WREN        GPIO8
-#define STR_MOST        GPIO9
+#define STR_DATA	GPIO6  /* radio TEA5757 pins and GPIO bits */
+#define STR_CLK		GPIO7
+#define STR_WREN	GPIO8
+#define STR_MOST	GPIO9
 
 #define FREQ_LO		 50*16000
 #define FREQ_HI		150*16000
 
-#define FREQ_IF         171200 /* 10.7*16000   */
-#define FREQ_STEP       200    /* 12.5*16      */
+#define FREQ_IF		171200 /* 10.7*16000   */
+#define FREQ_STEP	200    /* 12.5*16      */
 
 #define FREQ2BITS(x)	((((unsigned int)(x)+FREQ_IF+(FREQ_STEP<<1))\
 			/(FREQ_STEP<<2))<<2) /* (x==fmhz*16*1000) -> bits */
@@ -65,7 +61,27 @@
 module_param(radio_nr, int, 0);
 
 static int radio_ioctl(struct inode *inode, struct file *file,
-		       unsigned int cmd, unsigned long arg);
+	unsigned int cmd, unsigned long arg);
+static int maestro_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
+static void maestro_remove(struct pci_dev *pdev);
+
+static struct pci_device_id maestro_r_pci_tbl[] = {
+	{ PCI_DEVICE(PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_ESS1968),
+		.class = PCI_CLASS_MULTIMEDIA_AUDIO << 8,
+		.class_mask = 0xffff00 },
+	{ PCI_DEVICE(PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_ESS1978),
+		.class = PCI_CLASS_MULTIMEDIA_AUDIO << 8,
+		.class_mask = 0xffff00 },
+	{ 0 }
+};
+MODULE_DEVICE_TABLE(pci, maestro_r_pci_tbl);
+
+static struct pci_driver maestro_r_driver = {
+	.name		= "maestro_radio",
+	.id_table	= maestro_r_pci_tbl,
+	.probe		= maestro_probe,
+	.remove		= __devexit_p(maestro_remove),
+};
 
 static struct file_operations maestro_fops = {
 	.owner		= THIS_MODULE,
@@ -76,29 +92,27 @@
 	.llseek         = no_llseek,
 };
 
-static struct video_device maestro_radio=
-{
-	.owner		= THIS_MODULE,
+static struct video_device maestro_radio = {
 	.name		= "Maestro radio",
 	.type		= VID_TYPE_TUNER,
 	.hardware	= VID_HARDWARE_SF16MI,
-	.fops           = &maestro_fops,
+	.fops		= &maestro_fops,
 };
 
-static struct radio_device
-{
-	__u16	io,	/* base of Maestro card radio io (GPIO_DATA)*/
+struct radio_device {
+	u16	io,	/* base of Maestro card radio io (GPIO_DATA)*/
 		muted,	/* VIDEO_AUDIO_MUTE */
 		stereo,	/* VIDEO_TUNER_STEREO_ON */	
 		tuned;	/* signal strength (0 or 0xffff) */
-	struct  semaphore lock;
-} radio_unit = {0, 0, 0, 0, };
+	struct	semaphore lock;
+};
 
-static __u32 radio_bits_get(struct radio_device *dev)
+static u32 radio_bits_get(struct radio_device *dev)
 {
-	register __u16 io=dev->io, l, rdata;
-	register __u32 data=0;
-	__u16 omask;
+	register u16 io=dev->io, l, rdata;
+	register u32 data=0;
+	u16 omask;
+
 	omask = inw(io + IO_MASK);
 	outw(~(STR_CLK | STR_WREN), io + IO_MASK);
 	outw(0, io);
@@ -121,17 +135,21 @@
 				data++;
 		udelay(2);
 	}
+
 	if(dev->muted)
 		outw(STR_WREN, io);
+
 	udelay(4);
 	outw(omask, io + IO_MASK);
+
 	return data & 0x3ffe;
 }
 
-static void radio_bits_set(struct radio_device *dev, __u32 data)
+static void radio_bits_set(struct radio_device *dev, u32 data)
 {
-	register __u16 io=dev->io, l, bits;
-	__u16 omask, odir;
+	register u16 io=dev->io, l, bits;
+	u16 omask, odir;
+
 	omask = inw(io + IO_MASK);
 	odir  = (inw(io + IO_DIR) & ~STR_DATA) | (STR_CLK | STR_WREN);
 	outw(odir | STR_DATA, io + IO_DIR);
@@ -147,8 +165,10 @@
 		outw(bits, io);			/* LO level */
 		udelay(4);
 	}
+
 	if(!dev->muted)
 		outw(0, io);
+
 	udelay(4);
 	outw(omask, io + IO_MASK);
 	outw(odir, io + IO_DIR);
@@ -156,141 +176,103 @@
 }
 
 static inline int radio_function(struct inode *inode, struct file *file,
-				 unsigned int cmd, void *arg)
+	unsigned int cmd, void *arg)
 {
 	struct video_device *dev = video_devdata(file);
-	struct radio_device *card=dev->priv;
-	
-	switch(cmd) {
-		case VIDIOCGCAP: {
-			struct video_capability *v = arg;
-			memset(v,0,sizeof(*v));
-			strcpy(v->name, "Maestro radio");
-			v->type=VID_TYPE_TUNER;
-			v->channels=v->audios=1;
+	struct radio_device *card = video_get_drvdata(dev);
+
+	switch (cmd) {
+	case VIDIOCGCAP: {
+		struct video_capability *v = arg;
+		memset(v, 0, sizeof(*v));
+		strcpy(v->name, "Maestro radio");
+		v->type = VID_TYPE_TUNER;
+		v->channels = v->audios = 1;
+		return 0;
+	} case VIDIOCGTUNER: {
+		struct video_tuner *v = arg;
+		if (v->tuner)
+			return -EINVAL;
+		(void)radio_bits_get(card);
+		v->flags = VIDEO_TUNER_LOW | card->stereo;
+		v->signal = card->tuned;
+		strcpy(v->name, "FM");
+		v->rangelow = FREQ_LO;
+		v->rangehigh = FREQ_HI;
+		v->mode = VIDEO_MODE_AUTO;
+		return 0;
+	} case VIDIOCSTUNER: {
+		struct video_tuner *v = arg;
+		if (v->tuner != 0)
+			return -EINVAL;
+		return 0;
+	} case VIDIOCGFREQ: {
+		unsigned long *freq = arg;
+		*freq = BITS2FREQ(radio_bits_get(card));
+		return 0;
+	} case VIDIOCSFREQ: {
+		unsigned long *freq = arg;
+		if (*freq < FREQ_LO || *freq > FREQ_HI)
+			return -EINVAL;
+		radio_bits_set(card, FREQ2BITS(*freq));
+		return 0;
+	} case VIDIOCGAUDIO: {
+		struct video_audio *v = arg;
+		memset(v, 0, sizeof(*v));
+		strcpy(v->name, "Radio");
+		v->flags = VIDEO_AUDIO_MUTABLE | card->muted;
+		v->mode = VIDEO_SOUND_STEREO;
+		return 0;
+	} case VIDIOCSAUDIO: {
+		struct video_audio *v = arg;
+		if (v->audio)
+			return -EINVAL;
+		{
+			register u16 io = card->io;
+			register u16 omask = inw(io + IO_MASK);
+			outw(~STR_WREN, io + IO_MASK);
+			outw((card->muted = v->flags & VIDEO_AUDIO_MUTE) ?
+				STR_WREN : 0, io);
+			udelay(4);
+			outw(omask, io + IO_MASK);
+			msleep(125);
 			return 0;
 		}
-		case VIDIOCGTUNER: {
-			struct video_tuner *v = arg;
-			if(v->tuner)
-				return -EINVAL;
-			(void)radio_bits_get(card);
-			v->flags = VIDEO_TUNER_LOW | card->stereo;
-			v->signal = card->tuned;
-			strcpy(v->name, "FM");
-			v->rangelow = FREQ_LO;
-			v->rangehigh = FREQ_HI;
-			v->mode = VIDEO_MODE_AUTO;
-		        return 0;
-		}
-		case VIDIOCSTUNER: {
-			struct video_tuner *v = arg;
-			if(v->tuner!=0)
-				return -EINVAL;
-			return 0;
-		}
-		case VIDIOCGFREQ: {
-			unsigned long *freq = arg;
-			*freq = BITS2FREQ(radio_bits_get(card));
-			return 0;
-		}
-		case VIDIOCSFREQ: {
-			unsigned long *freq = arg;
-			if (*freq<FREQ_LO || *freq>FREQ_HI )
-				return -EINVAL;
-			radio_bits_set(card, FREQ2BITS(*freq));
-			return 0;
-		}
-		case VIDIOCGAUDIO: {	
-			struct video_audio *v = arg;
-			memset(v,0,sizeof(*v));
-			strcpy(v->name, "Radio");
-			v->flags=VIDEO_AUDIO_MUTABLE | card->muted;
-			v->mode=VIDEO_SOUND_STEREO;
-			return 0;		
-		}
-		case VIDIOCSAUDIO: {
-			struct video_audio *v = arg;
-			if(v->audio)
-				return -EINVAL;
-			{
-				register __u16 io=card->io;
-				register __u16 omask = inw(io + IO_MASK);
-				outw(~STR_WREN, io + IO_MASK);
-				outw((card->muted = v->flags & VIDEO_AUDIO_MUTE)
-				     ? STR_WREN : 0, io);
-				udelay(4);
-				outw(omask, io + IO_MASK);
-				msleep(125);
-				return 0;
-			}
-		}
-		case VIDIOCGUNIT: {
-			struct video_unit *v = arg;
-			v->video=VIDEO_NO_UNIT;
-			v->vbi=VIDEO_NO_UNIT;
-			v->radio=dev->minor;
-			v->audio=0;
-			v->teletext=VIDEO_NO_UNIT;
-			return 0;		
-		}
-		default: return -ENOIOCTLCMD;
+	} case VIDIOCGUNIT: {
+		struct video_unit *v = arg;
+		v->video = VIDEO_NO_UNIT;
+		v->vbi = VIDEO_NO_UNIT;
+		v->radio = dev->minor;
+		v->audio = 0;
+		v->teletext = VIDEO_NO_UNIT;
+		return 0;
+	} default:
+		return -ENOIOCTLCMD;
 	}
 }
 
 static int radio_ioctl(struct inode *inode, struct file *file,
-		       unsigned int cmd, unsigned long arg)
+	unsigned int cmd, unsigned long arg)
 {
 	struct video_device *dev = video_devdata(file);
-	struct radio_device *card=dev->priv;
+	struct radio_device *card = video_get_drvdata(dev);
 	int ret;
 
 	down(&card->lock);
 	ret = video_usercopy(inode, file, cmd, arg, radio_function);
 	up(&card->lock);
+
 	return ret;
 }
 
-static __u16 radio_install(struct pci_dev *pcidev);
-
-MODULE_AUTHOR("Adam Tlalka, atlka@pg.gda.pl");
-MODULE_DESCRIPTION("Radio driver for the Maestro PCI sound card radio.");
-MODULE_LICENSE("GPL");
-
-static void __exit maestro_radio_exit(void)
+static u16 __devinit radio_power_on(struct radio_device *dev)
 {
-	video_unregister_device(&maestro_radio);
-}
+	register u16 io = dev->io;
+	register u32 ofreq;
+	u16 omask, odir;
 
-static int __init maestro_radio_init(void)
-{
-	register __u16 found=0;
-	struct pci_dev *pcidev = NULL;
-	while(!found && (pcidev = pci_find_device(PCI_VENDOR_ESS, 
-						  PCI_DEVICE_ID_ESS_ESS1968,
-						  pcidev)))
-		found |= radio_install(pcidev);
-	while(!found && (pcidev = pci_find_device(PCI_VENDOR_ESS,
-						  PCI_DEVICE_ID_ESS_ESS1978, 
-						  pcidev)))
-		found |= radio_install(pcidev);
-	if(!found) {
-		printk(KERN_INFO "radio-maestro: no devices found.\n");
-		return -ENODEV;
-	}
-	return 0;
-}
-
-module_init(maestro_radio_init);
-module_exit(maestro_radio_exit);
-
-static inline __u16 radio_power_on(struct radio_device *dev)
-{
-	register __u16 io=dev->io;
-	register __u32 ofreq;
-	__u16 omask, odir;
 	omask = inw(io + IO_MASK);
-	odir  = (inw(io + IO_DIR) & ~STR_DATA) | (STR_CLK | STR_WREN);
+	odir = (inw(io + IO_DIR) & ~STR_DATA) | (STR_CLK | STR_WREN);
 	outw(odir & ~STR_WREN, io + IO_DIR);
 	dev->muted = inw(io) & STR_WREN ? 0 : VIDEO_AUDIO_MUTE;
 	outw(odir, io + IO_DIR);
@@ -299,35 +281,101 @@
 	udelay(16);
 	outw(omask, io + IO_MASK);
 	ofreq = radio_bits_get(dev);
-	if((ofreq<FREQ2BITS(FREQ_LO)) || (ofreq>FREQ2BITS(FREQ_HI)))
+
+	if ((ofreq < FREQ2BITS(FREQ_LO)) || (ofreq > FREQ2BITS(FREQ_HI)))
 		ofreq = FREQ2BITS(FREQ_LO);
 	radio_bits_set(dev, ofreq);
+
 	return (ofreq == radio_bits_get(dev));
 }
 
-static __u16 radio_install(struct pci_dev *pcidev)
+static int __devinit maestro_probe(struct pci_dev *pdev,
+	const struct pci_device_id *ent)
 {
-	if(((pcidev->class >> 8) & 0xffff) != PCI_CLASS_MULTIMEDIA_AUDIO)
-		return 0;
-	
-	radio_unit.io = pcidev->resource[0].start + GPIO_DATA;
-	maestro_radio.priv = &radio_unit;
-	init_MUTEX(&radio_unit.lock);
-	
-	if(radio_power_on(&radio_unit)) {
-		if(video_register_device(&maestro_radio, VFL_TYPE_RADIO, radio_nr)==-1) {
-			printk("radio-maestro: can't register device!");
-			return 0;
-		}
-		printk(KERN_INFO "radio-maestro: version "
-		       DRIVER_VERSION 
-		       " time " 
-		       __TIME__ "  "
-		       __DATE__
-		       "\n");
-		printk(KERN_INFO "radio-maestro: radio chip initialized\n");
-		return 1;
-	} else
-		return 0;   
+	struct radio_device *radio_unit;
+	struct video_device *maestro_radio_inst;
+	int retval;
+
+	retval = pci_enable_device(pdev);
+	if (retval) {
+		dev_err(&pdev->dev, "enabling pci device failed!\n");
+		goto err;
+	}
+
+	retval = -ENOMEM;
+
+	radio_unit = kzalloc(sizeof(*radio_unit), GFP_KERNEL);
+	if (radio_unit == NULL) {
+		dev_err(&pdev->dev, "not enough memory\n");
+		goto err;
+	}
+
+	radio_unit->io = pci_resource_start(pdev, 0) + GPIO_DATA;
+	init_MUTEX(&radio_unit->lock);
+
+	maestro_radio_inst = video_device_alloc();
+	if (maestro_radio_inst == NULL) {
+		dev_err(&pdev->dev, "not enough memory\n");
+		goto errfr;
+	}
+
+	memcpy(maestro_radio_inst, &maestro_radio, sizeof(maestro_radio));
+	video_set_drvdata(maestro_radio_inst, radio_unit);
+	pci_set_drvdata(pdev, maestro_radio_inst);
+
+	retval = video_register_device(maestro_radio_inst, VFL_TYPE_RADIO,
+		radio_nr);
+	if (retval) {
+		printk(KERN_ERR "can't register video device!\n");
+		goto errfr1;
+	}
+
+	if (!radio_power_on(radio_unit)) {
+		retval = -EIO;
+		goto errunr;
+	}
+
+	dev_info(&pdev->dev, "version " DRIVER_VERSION " time " __TIME__ "  "
+		 __DATE__ "\n");
+	dev_info(&pdev->dev, "radio chip initialized\n");
+
+	return 0;
+errunr:
+	video_unregister_device(maestro_radio_inst);
+errfr1:
+	kfree(maestro_radio_inst);
+errfr:
+	kfree(radio_unit);
+err:
+	return retval;
+
 }
 
+static void __devexit maestro_remove(struct pci_dev *pdev)
+{
+	struct video_device *vdev = pci_get_drvdata(pdev);
+
+	video_unregister_device(vdev);
+}
+
+static int __init maestro_radio_init(void)
+{
+	int retval = pci_register_driver(&maestro_r_driver);
+
+	if (retval)
+		printk(KERN_ERR "error during registration pci driver\n");
+
+	return retval;
+}
+
+static void __exit maestro_radio_exit(void)
+{
+	pci_unregister_driver(&maestro_r_driver);
+}
+
+module_init(maestro_radio_init);
+module_exit(maestro_radio_exit);
+
+MODULE_AUTHOR("Adam Tlalka, atlka@pg.gda.pl");
+MODULE_DESCRIPTION("Radio driver for the Maestro PCI sound card radio.");
+MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 2fe260f..d82c8a3 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -183,7 +183,7 @@
 	help
 	  Say Y here to enable support for the Stradis 4:2:2 MPEG-2 video
 	  driver for PCI.  There is a product page at
-	  <http://www.stradis.com/decoder.html>.
+	  <http://www.stradis.com/>.
 
 config VIDEO_ZORAN
 	tristate "Zoran ZR36057/36067 Video For Linux"
diff --git a/drivers/media/video/adv7170.c b/drivers/media/video/adv7170.c
index e61003d..4ce07ae 100644
--- a/drivers/media/video/adv7170.c
+++ b/drivers/media/video/adv7170.c
@@ -413,10 +413,9 @@
 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
 		return 0;
 
-	client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
+	client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
 	if (client == 0)
 		return -ENOMEM;
-	memset(client, 0, sizeof(struct i2c_client));
 	client->addr = address;
 	client->adapter = adapter;
 	client->driver = &i2c_driver_adv7170;
@@ -433,12 +432,11 @@
 	}
 	strlcpy(I2C_NAME(client), dname, sizeof(I2C_NAME(client)));
 
-	encoder = kmalloc(sizeof(struct adv7170), GFP_KERNEL);
+	encoder = kzalloc(sizeof(struct adv7170), GFP_KERNEL);
 	if (encoder == NULL) {
 		kfree(client);
 		return -ENOMEM;
 	}
-	memset(encoder, 0, sizeof(struct adv7170));
 	encoder->norm = VIDEO_MODE_NTSC;
 	encoder->input = 0;
 	encoder->enable = 1;
diff --git a/drivers/media/video/adv7175.c b/drivers/media/video/adv7175.c
index 6d9536a..4e218f2 100644
--- a/drivers/media/video/adv7175.c
+++ b/drivers/media/video/adv7175.c
@@ -463,10 +463,9 @@
 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
 		return 0;
 
-	client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
+	client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
 	if (client == 0)
 		return -ENOMEM;
-	memset(client, 0, sizeof(struct i2c_client));
 	client->addr = address;
 	client->adapter = adapter;
 	client->driver = &i2c_driver_adv7175;
@@ -483,12 +482,11 @@
 	}
 	strlcpy(I2C_NAME(client), dname, sizeof(I2C_NAME(client)));
 
-	encoder = kmalloc(sizeof(struct adv7175), GFP_KERNEL);
+	encoder = kzalloc(sizeof(struct adv7175), GFP_KERNEL);
 	if (encoder == NULL) {
 		kfree(client);
 		return -ENOMEM;
 	}
-	memset(encoder, 0, sizeof(struct adv7175));
 	encoder->norm = VIDEO_MODE_PAL;
 	encoder->input = 0;
 	encoder->enable = 1;
diff --git a/drivers/media/video/bt819.c b/drivers/media/video/bt819.c
index 560b998..d644779 100644
--- a/drivers/media/video/bt819.c
+++ b/drivers/media/video/bt819.c
@@ -528,21 +528,18 @@
 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
 		return 0;
 
-	client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
+	client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
 	if (client == 0)
 		return -ENOMEM;
-	memset(client, 0, sizeof(struct i2c_client));
 	client->addr = address;
 	client->adapter = adapter;
 	client->driver = &i2c_driver_bt819;
 
-	decoder = kmalloc(sizeof(struct bt819), GFP_KERNEL);
+	decoder = kzalloc(sizeof(struct bt819), GFP_KERNEL);
 	if (decoder == NULL) {
 		kfree(client);
 		return -ENOMEM;
 	}
-
-	memset(decoder, 0, sizeof(struct bt819));
 	decoder->norm = VIDEO_MODE_NTSC;
 	decoder->input = 0;
 	decoder->enable = 1;
diff --git a/drivers/media/video/bt832.c b/drivers/media/video/bt832.c
index dda4aa6..07c78f1 100644
--- a/drivers/media/video/bt832.c
+++ b/drivers/media/video/bt832.c
@@ -75,13 +75,13 @@
 
 	if(debug>1) {
 		int i;
-		v4l_dbg(2,i2c_client_s,"hexdump:");
+		v4l_dbg(2, debug,i2c_client_s,"hexdump:");
 		for(i=1;i<65;i++) {
 			if(i!=1) {
 				if(((i-1)%8)==0) printk(" ");
 				if(((i-1)%16)==0) {
 					printk("\n");
-					v4l_dbg(2,i2c_client_s,"hexdump:");
+					v4l_dbg(2, debug,i2c_client_s,"hexdump:");
 				}
 			}
 			printk(" %02x",buf[i]);
@@ -167,9 +167,8 @@
 	client_template.adapter = adap;
 	client_template.addr    = addr;
 
-	if (NULL == (t = kmalloc(sizeof(*t), GFP_KERNEL)))
+	if (NULL == (t = kzalloc(sizeof(*t), GFP_KERNEL)))
 		return -ENOMEM;
-	memset(t,0,sizeof(*t));
 	t->client = client_template;
 	i2c_set_clientdata(&t->client, t);
 	i2c_attach_client(&t->client);
diff --git a/drivers/media/video/bt856.c b/drivers/media/video/bt856.c
index 6050806..909b593 100644
--- a/drivers/media/video/bt856.c
+++ b/drivers/media/video/bt856.c
@@ -316,21 +316,19 @@
 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
 		return 0;
 
-	client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
+	client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
 	if (client == 0)
 		return -ENOMEM;
-	memset(client, 0, sizeof(struct i2c_client));
 	client->addr = address;
 	client->adapter = adapter;
 	client->driver = &i2c_driver_bt856;
 	strlcpy(I2C_NAME(client), "bt856", sizeof(I2C_NAME(client)));
 
-	encoder = kmalloc(sizeof(struct bt856), GFP_KERNEL);
+	encoder = kzalloc(sizeof(struct bt856), GFP_KERNEL);
 	if (encoder == NULL) {
 		kfree(client);
 		return -ENOMEM;
 	}
-	memset(encoder, 0, sizeof(struct bt856));
 	encoder->norm = VIDEO_MODE_NTSC;
 	encoder->enable = 1;
 	i2c_set_clientdata(client, encoder);
diff --git a/drivers/media/video/bttv-cards.c b/drivers/media/video/bttv-cards.c
index 1621ab1..65323e7 100644
--- a/drivers/media/video/bttv-cards.c
+++ b/drivers/media/video/bttv-cards.c
@@ -321,7 +321,7 @@
 		.audio_inputs	= 1,
 		.tuner		= 0,
 		.svhs		= 2,
-		.muxsel		= { 2, 3, 1, 0},
+		.muxsel		= { 2, 3, 1, 0 },
 		.tuner_type	= -1,
 		.tuner_addr	= ADDR_UNSET,
 		.radio_addr     = ADDR_UNSET,
@@ -333,8 +333,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 15,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= { 2, 0, 0, 0, 10},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 2, 0, 0, 0, 10 },
 		.needs_tvaudio	= 1,
 		.tuner_type	= -1,
 		.tuner_addr	= ADDR_UNSET,
@@ -347,8 +347,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 7,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= { 0, 1, 2, 3, 4},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 0, 1, 2, 3, 4 },
 		.needs_tvaudio	= 1,
 		.tuner_type	= -1,
 		.tuner_addr	= ADDR_UNSET,
@@ -361,8 +361,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 7,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= { 4, 0, 2, 3, 1},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 4, 0, 2, 3, 1 },
 		.no_msp34xx	= 1,
 		.needs_tvaudio	= 1,
 		.tuner_type     = TUNER_PHILIPS_NTSC,
@@ -380,7 +380,7 @@
 		.tuner		= -1,
 		.svhs		= 2,
 		.gpiomask	= 0,
-		.muxsel		= { 2, 3, 1, 1},
+		.muxsel		= { 2, 3, 1, 1 },
 		.audiomux	= { 0 },
 		.needs_tvaudio	= 0,
 		.tuner_type	= 4,
@@ -394,8 +394,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 3,
-		.muxsel		= { 2, 3, 1, 0},
-		.audiomux	= { 0, 1, 0, 1, 3},
+		.muxsel		= { 2, 3, 1, 0 },
+		.audiomux	= { 0, 1, 0, 1, 3 },
 		.needs_tvaudio	= 1,
 		.tuner_type	= -1,
 		.tuner_addr	= ADDR_UNSET,
@@ -407,9 +407,9 @@
 		.audio_inputs	= 1,
 		.tuner		= 0,
 		.svhs		= 3,
-		.muxsel		= { 2, 3, 1, 1},
+		.muxsel		= { 2, 3, 1, 1 },
 		.gpiomask	= 0x0f,
-		.audiomux	= { 0x0c, 0x04, 0x08, 0x04, 0},
+		.audiomux	= { 0x0c, 0x04, 0x08, 0x04, 0 },
 		/*                0x04 for some cards ?? */
 		.needs_tvaudio	= 1,
 		.tuner_type	= -1,
@@ -425,8 +425,8 @@
 		.tuner		= -1,
 		.svhs		= 3,
 		.gpiomask	= 0,
-		.muxsel		= { 2, 3, 1, 0, 0},
-		.audiomux	= {0 },
+		.muxsel		= { 2, 3, 1, 0, 0 },
+		.audiomux	= { 0 },
 		.needs_tvaudio	= 1,
 		.tuner_type	= -1,
 		.tuner_addr	= ADDR_UNSET,
@@ -441,8 +441,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0xc00,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= { 0, 0xc00, 0x800, 0x400, 0xc00, 0},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 0, 0xc00, 0x800, 0x400, 0xc00, 0 },
 		.needs_tvaudio	= 1,
 		.pll		= PLL_28,
 		.tuner_type	= -1,
@@ -456,8 +456,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 3,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= { 1, 1, 2, 3, 0},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 1, 1, 2, 3, 0 },
 		.needs_tvaudio	= 0,
 		.pll		= PLL_28,
 		.tuner_type	= TUNER_TEMIC_PAL,
@@ -471,8 +471,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0x0f, /* old: 7 */
-		.muxsel		= { 2, 0, 1, 1},
-		.audiomux	= { 0, 1, 2, 3, 4},
+		.muxsel		= { 2, 0, 1, 1 },
+		.audiomux	= { 0, 1, 2, 3, 4 },
 		.needs_tvaudio	= 1,
 		.pll		= PLL_28,
 		.tuner_type	= -1,
@@ -486,8 +486,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0x3014f,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= { 0x20001,0x10001, 0, 0,10},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 0x20001,0x10001, 0, 0,10 },
 		.needs_tvaudio	= 1,
 		.tuner_type	= -1,
 		.tuner_addr	= ADDR_UNSET,
@@ -502,8 +502,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 15,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= { 13, 14, 11, 7, 0, 0},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 13, 14, 11, 7, 0, 0 },
 		.needs_tvaudio	= 1,
 		.tuner_type	= -1,
 		.tuner_addr	= ADDR_UNSET,
@@ -516,8 +516,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 15,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= { 13, 14, 11, 7, 0, 0},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 13, 14, 11, 7, 0, 0 },
 		.needs_tvaudio	= 1,
 		.msp34xx_alt    = 1,
 		.pll		= PLL_28,
@@ -534,8 +534,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 7,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= { 0, 2, 1, 3, 4}, /* old: { 0, 1, 2, 3, 4} */
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 0, 2, 1, 3, 4 }, /* old: {0, 1, 2, 3, 4} */
 		.needs_tvaudio	= 1,
 		.pll		= PLL_28,
 		.tuner_type	= -1,
@@ -549,8 +549,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 15,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= {0 , 0, 1 , 0, 10},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 0 , 0, 1 , 0, 10 },
 		.needs_tvaudio	= 1,
 		.tuner_type	= -1,
 		.tuner_addr	= ADDR_UNSET,
@@ -565,7 +565,7 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0x01fe00,
-		.muxsel		= { 2, 3, 1, 1},
+		.muxsel		= { 2, 3, 1, 1 },
 	#if 0
 		/* old */
 		.audiomux	= { 0x01c000, 0, 0x018000, 0x014000, 0x002000, 0 },
@@ -584,8 +584,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0x8300f8,
-		.muxsel		= { 2, 3, 1, 1,0},
-		.audiomux	= { 0x4fa007,0xcfa007,0xcfa007,0xcfa007,0xcfa007,0xcfa007},
+		.muxsel		= { 2, 3, 1, 1,0 },
+		.audiomux	= { 0x4fa007,0xcfa007,0xcfa007,0xcfa007,0xcfa007,0xcfa007 },
 		.needs_tvaudio	= 1,
 		.tuner_type	= -1,
 		.tuner_addr	= ADDR_UNSET,
@@ -600,8 +600,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0,
-		.muxsel		= {2, 3, 1, 1},
-		.audiomux	= {1, 0, 0, 0, 0},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 1, 0, 0, 0, 0 },
 		.needs_tvaudio	= 1,
 		.tuner_type	= -1,
 		.tuner_addr	= ADDR_UNSET,
@@ -614,7 +614,7 @@
 		.tuner		= -1,
 		.svhs		= -1,
 		.gpiomask	= 0x8dff00,
-		.muxsel		= { 2, 3, 1, 1},
+		.muxsel		= { 2, 3, 1, 1 },
 		.audiomux	= { 0 },
 		.no_msp34xx	= 1,
 		.tuner_type	= -1,
@@ -629,7 +629,7 @@
 		.audio_inputs	= 3,
 		.tuner		= 0,
 		.svhs		= 2,
-		.muxsel		= {2, 3, 1, 1},
+		.muxsel		= { 2, 3, 1, 1 },
 		.tuner_type	= -1,
 		.tuner_addr	= ADDR_UNSET,
 		.radio_addr     = ADDR_UNSET,
@@ -641,8 +641,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0x1800,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= { 0, 0x800, 0x1000, 0x1000, 0x1800},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 0, 0x800, 0x1000, 0x1000, 0x1800 },
 		.pll		= PLL_28,
 		.tuner_type	= TUNER_PHILIPS_PAL_I,
 		.tuner_addr	= ADDR_UNSET,
@@ -655,8 +655,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0xc00,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= {0, 1, 0x800, 0x400, 0xc00, 0},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 0, 1, 0x800, 0x400, 0xc00, 0 },
 		.needs_tvaudio	= 1,
 		.pll		= PLL_28,
 		.tuner_type	= -1,
@@ -688,8 +688,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0xe00,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= {0x400, 0x400, 0x400, 0x400, 0xc00},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= {0x400, 0x400, 0x400, 0x400, 0xc00 },
 		.needs_tvaudio	= 1,
 		.pll		= PLL_28,
 		.tuner_type	= -1,
@@ -704,8 +704,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask       = 0x1f0fff,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux       = { 0x20000, 0x30000, 0x10000, 0, 0x40000},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux       = { 0x20000, 0x30000, 0x10000, 0, 0x40000 },
 		.needs_tvaudio	= 0,
 		.tuner_type	= TUNER_PHILIPS_PAL,
 		.tuner_addr	= ADDR_UNSET,
@@ -719,8 +719,8 @@
 		.tuner		= 0,
 		.svhs		= 3,
 		.gpiomask	= 7,
-		.muxsel		= { 2, 0, 1, 1},
-		.audiomux	= { 0, 1, 2, 3, 4},
+		.muxsel		= { 2, 0, 1, 1 },
+		.audiomux	= { 0, 1, 2, 3, 4 },
 		.needs_tvaudio	= 1,
 		.tuner_type	= -1,
 		.tuner_addr	= ADDR_UNSET,
@@ -733,8 +733,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0x1800,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= { 0, 0x800, 0x1000, 0x1000, 0x1800},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 0, 0x800, 0x1000, 0x1000, 0x1800 },
 		.pll            = PLL_28,
 		.tuner_type	= TUNER_PHILIPS_SECAM,
 		.tuner_addr	= ADDR_UNSET,
@@ -749,8 +749,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0x1f0fff,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= { 0x20000, 0x30000, 0x10000, 0x00000, 0x40000},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 0x20000, 0x30000, 0x10000, 0x00000, 0x40000 },
 		.needs_tvaudio	= 0,
 		.tuner_type	= TUNER_PHILIPS_PAL,
 		.tuner_addr	= ADDR_UNSET,
@@ -812,7 +812,7 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0x1800,  /* 0x8dfe00 */
-		.muxsel		= { 2, 3, 1, 1},
+		.muxsel		= { 2, 3, 1, 1 },
 		.audiomux	= { 0, 0x0800, 0x1000, 0x1000, 0x1800, 0 },
 		.pll            = PLL_28,
 		.tuner_type	= -1,
@@ -826,7 +826,7 @@
 		.tuner		= 0,
 		.svhs		= 3,
 		.gpiomask	= 1,
-		.muxsel		= { 2, 3, 1, 1},
+		.muxsel		= { 2, 3, 1, 1 },
 		.audiomux	= { 1, 0, 0, 0, 0 },
 		.pll            = PLL_28,
 		.tuner_type	= TUNER_PHILIPS_PAL,
@@ -842,7 +842,7 @@
 		.tuner		= -1,
 		.svhs		= 2,
 		.gpiomask	= 0,
-		.muxsel		= { 2, 3, 1, 1},
+		.muxsel		= { 2, 3, 1, 1 },
 		.audiomux	= { 0 },
 		.needs_tvaudio	= 0,
 		.tuner_type	= 4,
@@ -856,8 +856,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0xffff00,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= { 0x500, 0, 0x300, 0x900, 0x900},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 0x500, 0, 0x300, 0x900, 0x900 },
 		.needs_tvaudio	= 1,
 		.pll		= PLL_28,
 		.tuner_type	= TUNER_PHILIPS_PAL,
@@ -870,7 +870,7 @@
 		.audio_inputs	= 1,
 		.tuner		= 0,
 		.svhs		= 2,
-		.muxsel		= { 2, 3, 1, 1, 0}, /* TV, CVid, SVid, CVid over SVid connector */
+		.muxsel		= { 2, 3, 1, 1, 0 }, /* TV, CVid, SVid, CVid over SVid connector */
 	#if 0
 		.gpiomask	= 0xc33000,
 		.audiomux	= { 0x422000,0x1000,0x0000,0x620000,0x800000 },
@@ -906,8 +906,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0x1800,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= { 0, 0x800, 0x1000, 0x1000, 0x1800},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 0, 0x800, 0x1000, 0x1000, 0x1800 },
 		.pll		= PLL_28,
 		.tuner_type	= -1,
 		.tuner_addr	= ADDR_UNSET,
@@ -922,7 +922,7 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0x1800,
-		.muxsel		= { 2, 3, 1, 1},
+		.muxsel		= { 2, 3, 1, 1 },
 		.audiomux	= { 0, 0x800, 0x1000, 0x1000, 0x1800, 0 },
 		.pll		= PLL_28,
 		.tuner_type	= -1,
@@ -952,7 +952,7 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0x551e00,
-		.muxsel		= { 2, 3, 1, 0},
+		.muxsel		= { 2, 3, 1, 0 },
 		.audiomux	= { 0x551400, 0x551200, 0, 0, 0x551c00, 0x551200 },
 		.needs_tvaudio	= 1,
 		.pll		= PLL_28,
@@ -968,8 +968,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0x03000F,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= { 2, 0xd0001, 0, 0, 1},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 2, 0xd0001, 0, 0, 1 },
 		.needs_tvaudio	= 0,
 		.pll		= PLL_28,
 		.tuner_type	= -1,
@@ -985,8 +985,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 7,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= { 4, 0, 2, 3, 1},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 4, 0, 2, 3, 1 },
 		.no_msp34xx	= 1,
 		.needs_tvaudio	= 1,
 		.tuner_type     = TUNER_PHILIPS_NTSC,
@@ -1002,8 +1002,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 15,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= { 13, 4, 11, 7, 0, 0},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 13, 4, 11, 7, 0, 0 },
 		.needs_tvaudio	= 1,
 		.pll		= PLL_28,
 		.tuner_type	= -1,
@@ -1035,8 +1035,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0xe00b,
-		.muxsel		= {2, 3, 1, 1},
-		.audiomux	= {0xff9ff6, 0xff9ff6, 0xff1ff7, 0, 0xff3ffc},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 0xff9ff6, 0xff9ff6, 0xff1ff7, 0, 0xff3ffc },
 		.no_msp34xx	= 1,
 		.tuner_type	= -1,
 		.tuner_addr	= ADDR_UNSET,
@@ -1051,8 +1051,8 @@
 		.tuner		= 0,
 		.svhs		= -1,
 		.gpiomask	= 3,
-		.muxsel		= {2, 3, 1, 1},
-		.audiomux	= {1, 1, 0, 2, 3},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 1, 1, 0, 2, 3 },
 		.no_msp34xx	= 1,
 		.pll		= PLL_NONE,
 		.tuner_type	= -1,
@@ -1066,8 +1066,8 @@
 		.tuner		= -1,
 		.svhs		= 3,
 		.gpiomask	= 0,
-		.muxsel		= { 2, 3, 1, 0, 0},
-		.audiomux	= {0 },
+		.muxsel		= { 2, 3, 1, 0, 0 },
+		.audiomux	= { 0 },
 		.no_msp34xx	= 1,
 		.pll		= PLL_28,
 		.tuner_type	= -1,
@@ -1081,8 +1081,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0xbcf03f,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= { 0xbc803f, 0xbc903f, 0xbcb03f, 0, 0xbcb03f},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 0xbc803f, 0xbc903f, 0xbcb03f, 0, 0xbcb03f },
 		.no_msp34xx	= 1,
 		.pll		= PLL_28,
 		.tuner_type	= 21,
@@ -1096,7 +1096,7 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0x70000,
-		.muxsel		= { 2, 3, 1, 1},
+		.muxsel		= { 2, 3, 1, 1 },
 		.audiomux	= { 0x20000, 0x30000, 0x10000, 0, 0x40000, 0x20000 },
 		.needs_tvaudio	= 1,
 		.no_msp34xx	= 1,
@@ -1115,8 +1115,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 15,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= {2,0,0,0,1},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= {2,0,0,0,1 },
 		.needs_tvaudio	= 1,
 		.pll		= PLL_28,
 		.tuner_type	= -1,
@@ -1130,8 +1130,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0x010f00,
-		.muxsel		= {2, 3, 0, 0},
-		.audiomux	= {0x10000, 0, 0x10000, 0, 0, 0},
+		.muxsel		= {2, 3, 0, 0 },
+		.audiomux	= {0x10000, 0, 0x10000, 0, 0, 0 },
 		.no_msp34xx	= 1,
 		.pll		= PLL_28,
 		.tuner_type	= TUNER_ALPS_TSHC6_NTSC,
@@ -1172,8 +1172,8 @@
 		.tuner          = 0,
 		.svhs           = 2,
 		.gpiomask       = 7,
-		.muxsel         = { 2, 0, 1, 1},
-		.audiomux       = { 0, 1, 2, 3, 4},
+		.muxsel         = { 2, 0, 1, 1 },
+		.audiomux       = { 0, 1, 2, 3, 4 },
 		.pll            = PLL_28,
 		.tuner_type     = -1 /* TUNER_ALPS_TMDH2_NTSC */,
 		.tuner_addr	= ADDR_UNSET,
@@ -1189,8 +1189,8 @@
 		.tuner          = 0,
 		.svhs           = 3,
 		.gpiomask       = 0x03000F,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= { 1, 0xd0001, 0, 0, 10},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 1, 0xd0001, 0, 0, 10 },
 				/* sound path (5 sources):
 				MUX1 (mask 0x03), Enable Pin 0x08 (0=enable, 1=disable)
 					0= ext. Audio IN
@@ -1215,7 +1215,7 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0x1c,
-		.muxsel		= { 2, 3, 1, 1},
+		.muxsel		= { 2, 3, 1, 1 },
 		.audiomux	= { 0, 0, 0x10, 8, 4 },
 		.needs_tvaudio	= 1,
 		.pll		= PLL_28,
@@ -1236,7 +1236,7 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0x18e0,
-		.muxsel		= { 2, 3, 1, 1},
+		.muxsel		= { 2, 3, 1, 1 },
 		.audiomux	= { 0x0000,0x0800,0x1000,0x1000,0x18e0 },
 			/* For cards with tda9820/tda9821:
 				0x0000: Tuner normal stereo
@@ -1256,8 +1256,8 @@
 		.tuner          = 0,
 		.svhs           = 2,
 		.gpiomask       = 0xF,
-		.muxsel         = { 2, 3, 1, 0},
-		.audiomux       = { 2, 0, 0, 0, 10},
+		.muxsel         = { 2, 3, 1, 0 },
+		.audiomux       = { 2, 0, 0, 0, 10 },
 		.needs_tvaudio  = 0,
 		.pll		= PLL_28,
 		.tuner_type	= TUNER_TEMIC_PAL,
@@ -1274,7 +1274,7 @@
 		.tuner          = 0,
 		.svhs           = 2,
 		.gpiomask       = 0x1800,
-		.muxsel         = { 2, 3, 1, 1},
+		.muxsel         = { 2, 3, 1, 1 },
 		.audiomux       = { 0, 0x800, 0x1000, 0x1000, 0x1800, 0 },
 		.pll            = PLL_28,
 		.tuner_type     = 5,
@@ -1324,8 +1324,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask       = 0x03000F,
-		.muxsel		= { 2, 3, 1, 0},
-		.audiomux       = { 2,0,0,0,1 },
+		.muxsel		= { 2, 3, 1, 0 },
+		.audiomux       = { 2, 0, 0, 0, 1 },
 		.pll            = PLL_28,
 		.tuner_type	= 0,
 		.tuner_addr	= ADDR_UNSET,
@@ -1341,8 +1341,8 @@
 		.tuner		= 0,
 		.svhs		= -1,
 		.gpiomask       = 11,
-		.muxsel         = { 2, 3, 1, 1},
-		.audiomux       = { 2, 0, 0, 1, 8},
+		.muxsel         = { 2, 3, 1, 1 },
+		.audiomux       = { 2, 0, 0, 1, 8 },
 		.pll            = PLL_35,
 		.tuner_type     = TUNER_TEMIC_PAL,
 		.tuner_addr	= ADDR_UNSET,
@@ -1356,7 +1356,7 @@
 		.tuner		= -1,
 		.svhs		= 1,
 		.gpiomask       = 0xF,
-		.muxsel		= { 2, 2},
+		.muxsel		= { 2, 2 },
 		.audiomux       = { },
 		.no_msp34xx     = 1,
 		.needs_tvaudio  = 0,
@@ -1375,8 +1375,8 @@
 		.tuner          = 0,
 		.svhs           = 2,
 		.gpiomask       = 0xFF,
-		.muxsel         = { 2, 3, 1, 0},
-		.audiomux       = { 1, 0, 4, 4, 9},
+		.muxsel         = { 2, 3, 1, 0 },
+		.audiomux       = { 1, 0, 4, 4, 9 },
 		.needs_tvaudio  = 0,
 		.pll		= PLL_28,
 		.tuner_type	= TUNER_PHILIPS_PAL,
@@ -1392,7 +1392,7 @@
 		.svhs		= 2,
 		.gpiomask	= 0xf03f,
 		.muxsel		= { 2, 3, 1, 0 },
-		.audiomux	= { 0xbffe, 0, 0xbfff, 0, 0xbffe},
+		.audiomux	= { 0xbffe, 0, 0xbfff, 0, 0xbffe },
 		.pll		= PLL_28,
 		.tuner_type	= TUNER_TEMIC_4006FN5_MULTI_PAL,
 		.tuner_addr	= ADDR_UNSET,
@@ -1408,8 +1408,8 @@
 		.tuner		= 0,
 		.svhs		= -1,
 		.gpiomask	= 1,
-		.muxsel		= { 2, 3, 0, 1},
-		.audiomux	= { 0, 0, 1, 0, 0},
+		.muxsel		= { 2, 3, 0, 1 },
+		.audiomux	= { 0, 0, 1, 0, 0 },
 		.no_msp34xx	= 1,
 		.pll		= PLL_28,
 		.tuner_type	= TUNER_TEMIC_4006FN5_MULTI_PAL,
@@ -1424,7 +1424,7 @@
 		.tuner          = 0,
 		.svhs           = 2,
 		.gpiomask	= 0x18e0,
-		.muxsel		= { 2, 3, 0, 1},
+		.muxsel		= { 2, 3, 0, 1 },
 				/* Radio changed from 1e80 to 0x800 to make
 				FlyVideo2000S in .hu happy (gm)*/
 				/* -dk-???: set mute=0x1800 for tda9874h daughterboard */
@@ -1445,8 +1445,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0xffff00,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= { 0x500, 0x500, 0x300, 0x900, 0x900},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 0x500, 0x500, 0x300, 0x900, 0x900 },
 		.needs_tvaudio	= 1,
 		.pll		= PLL_28,
 		.tuner_type	= TUNER_PHILIPS_PAL,
@@ -1462,8 +1462,8 @@
 		.tuner          = 0,
 		.svhs           = 2,
 		.gpiomask       = 0x010f00,
-		.muxsel         = {2, 3, 0, 0},
-		.audiomux       = {0x10000, 0, 0x10000, 0, 0, 0},
+		.muxsel         = {2, 3, 0, 0 },
+		.audiomux       = {0x10000, 0, 0x10000, 0, 0, 0 },
 		.no_msp34xx     = 1,
 		.pll            = PLL_28,
 		.tuner_type     = TUNER_SHARP_2U5JF5540_NTSC,
@@ -1487,7 +1487,7 @@
 		.audiomux       = {0x947fff, 0x987fff,0x947fff,0x947fff, 0x947fff},
 		/* tvtuner, radio,   external,internal, mute,  stereo
 		* tuner, Composit, SVid, Composit-on-Svid-adapter */
-		.muxsel         = { 2, 3 ,0 ,1},
+		.muxsel         = { 2, 3 ,0 ,1 },
 		.tuner_type     = TUNER_MT2032,
 		.tuner_addr	= ADDR_UNSET,
 		.radio_addr     = ADDR_UNSET,
@@ -1515,8 +1515,8 @@
 		.tuner          = 0,
 		.svhs           = 2,
 		.gpiomask       = 15,
-		.muxsel         = { 2, 3, 1, 1},
-		.audiomux       = { 0, 0, 11, 7, 13, 0}, /* TV and Radio with same GPIO ! */
+		.muxsel         = { 2, 3, 1, 1 },
+		.audiomux       = { 0, 0, 11, 7, 13, 0 }, /* TV and Radio with same GPIO ! */
 		.needs_tvaudio  = 1,
 		.pll            = PLL_28,
 		.tuner_type     = 25,
@@ -1537,7 +1537,7 @@
 		.audio_inputs   = 0,
 		.tuner		= -1,
 		.svhs		= 2,
-		.muxsel		= { 2, 3, 1, 1}, /* AV1, AV2, SVHS, CVid adapter on SVHS */
+		.muxsel		= { 2, 3, 1, 1 }, /* AV1, AV2, SVHS, CVid adapter on SVHS */
 		.pll		= PLL_28,
 		.no_msp34xx	= 1,
 		.tuner_type	= UNSET,
@@ -1583,7 +1583,7 @@
 		.tuner          = -1,
 		.svhs           = 4,
 		.gpiomask       = 0,
-		.muxsel         = { 2, 3, 1, 0, 0},
+		.muxsel         = { 2, 3, 1, 0, 0 },
 		.audiomux       = { 0 },
 		.needs_tvaudio  = 0,
 		.tuner_type     = -1,
@@ -1696,7 +1696,7 @@
 		.name           = "DSP Design TCVIDEO",
 		.video_inputs   = 4,
 		.svhs           = -1,
-		.muxsel         = { 2, 3, 1, 0},
+		.muxsel         = { 2, 3, 1, 0 },
 		.pll            = PLL_28,
 		.tuner_type     = -1,
 		.tuner_addr	= ADDR_UNSET,
@@ -1710,7 +1710,7 @@
 		.audio_inputs   = 1,
 		.tuner          = 0,
 		.svhs           = 2,
-		.muxsel         = { 2, 0, 1, 1},
+		.muxsel         = { 2, 0, 1, 1 },
 		.needs_tvaudio  = 1,
 		.pll            = PLL_28,
 		.tuner_type     = -1,
@@ -1727,7 +1727,7 @@
 		.tuner          = 0,
 		.svhs           = 2,
 		.gpiomask       = 0x0f0f80,
-		.muxsel         = {2, 3, 1, 0},
+		.muxsel         = {2, 3, 1, 0 },
 		.audiomux       = {0x030000, 0x010000, 0, 0, 0x020000, 0},
 		.no_msp34xx     = 1,
 		.pll            = PLL_28,
@@ -1944,7 +1944,7 @@
 		.no_msp34xx     = 1,
 		.no_tda9875     = 1,
 		.no_tda7432     = 1,
-		.muxsel         = { 3, 0, 1, 2},
+		.muxsel         = { 3, 0, 1, 2 },
 		.pll            = PLL_28,
 		.no_gpioirq     = 1,
 		.has_dvb        = 1,
@@ -1957,7 +1957,7 @@
 		.svhs           = 3,
 		.gpiomask       = 2,
 		/* TV, Comp1, Composite over SVID con, SVID */
-		.muxsel         = { 2, 3, 1, 1},
+		.muxsel         = { 2, 3, 1, 1 },
 		.audiomux       = { 2, 2, 0, 0, 0 },
 		.pll            = PLL_28,
 		.has_radio      = 1,
@@ -2074,7 +2074,7 @@
 		.audio_inputs   = 1,
 		.tuner          = 0,
 		.svhs           = 2,
-		.muxsel         = { 2, 3, 1, 1}, /* Tuner, CVid, SVid, CVid over SVid connector */
+		.muxsel         = { 2, 3, 1, 1 }, /* Tuner, CVid, SVid, CVid over SVid connector */
 		.gpiomask       = 0,
 		.no_tda9875     = 1,
 		.no_tda7432     = 1,
@@ -2128,7 +2128,7 @@
 		.video_inputs   = 1,
 		.tuner          = -1,
 		.svhs           = -1,
-		.muxsel         = { 2, 3, 1, 0},
+		.muxsel         = { 2, 3, 1, 0 },
 		.no_msp34xx     = 1,
 		.no_tda9875     = 1,
 		.no_tda7432     = 1,
@@ -2166,7 +2166,7 @@
 		.tuner          = -1, /* card has no tuner */
 		.svhs           = 3,
 		.gpiomask       = 0x00,
-		.muxsel         = { 2, 3, 1, 0},
+		.muxsel         = { 2, 3, 1, 0 },
 		.audiomux       = { 0, 0, 0, 0, 0, 0 }, /* card has no audio */
 		.needs_tvaudio  = 1,
 		.pll            = PLL_28,
@@ -2181,7 +2181,7 @@
 		.tuner          = -1, /* card has no tuner */
 		.svhs           = 3,
 		.gpiomask       = 0x00,
-		.muxsel         = { 2, 3, 1, 1},
+		.muxsel         = { 2, 3, 1, 1 },
 		.audiomux       = { 0, 0, 0, 0, 0, 0 }, /* card has no audio */
 		.needs_tvaudio  = 1,
 		.pll            = PLL_28,
@@ -2268,7 +2268,7 @@
 		.audio_inputs   = 1,
 		.tuner          = 0,
 		.svhs           = 2,
-		.muxsel         = { 2, 3, 1, 0},
+		.muxsel         = { 2, 3, 1, 0 },
 		.tuner_type     = TUNER_PHILIPS_ATSC,
 		.tuner_addr	= ADDR_UNSET,
 		.radio_addr     = ADDR_UNSET,
@@ -2291,7 +2291,7 @@
 		.audio_inputs   = 0,
 		.svhs           = 1,
 		.tuner          = -1,
-		.muxsel         = { 3, 1, 1, 3}, /* Vid In, SVid In, Vid over SVid in connector */
+		.muxsel         = { 3, 1, 1, 3 }, /* Vid In, SVid In, Vid over SVid in connector */
 		.no_msp34xx     = 1,
 		.no_tda9875     = 1,
 		.no_tda7432     = 1,
@@ -2307,8 +2307,8 @@
 		.tuner          = 0,
 		.svhs           = 2,
 		.gpiomask       = 3,
-		.muxsel         = { 2, 3, 1, 1},
-		.audiomux       = { 1, 1, 1, 1, 0},
+		.muxsel         = { 2, 3, 1, 1 },
+		.audiomux       = { 1, 1, 1, 1, 0 },
 		.needs_tvaudio  = 1,
 		.tuner_type     = TUNER_PHILIPS_PAL,
 		.tuner_addr	= ADDR_UNSET,
@@ -2327,7 +2327,7 @@
 		.tuner_addr	= ADDR_UNSET,
 		.radio_addr     = ADDR_UNSET,
 		.pll            = PLL_28,
-		.muxsel         = { 2, 2, 2, 2},
+		.muxsel         = { 2, 2, 2, 2 },
 		.gpiomask       = 0x3F,
 		.muxsel_hook    = gvc1100_muxsel,
 	},
@@ -2338,8 +2338,8 @@
 		.tuner          = 0,
 		.svhs           = 2,
 		.gpiomask       = 0x008007,
-		.muxsel         = {2, 3, 0, 0},
-		.audiomux       = {0, 0, 0, 0, 0x000003, 0},
+		.muxsel         = { 2, 3, 0, 0 },
+		.audiomux       = { 0, 0, 0, 0, 0x000003, 0 },
 		.pll            = PLL_28,
 		.tuner_type     = TUNER_PHILIPS_PAL,
 		.tuner_addr	= ADDR_UNSET,
@@ -2374,7 +2374,7 @@
 		.svhs           = 2,
 		.needs_tvaudio  = 0,
 		.gpiomask       = 0x68,
-		.muxsel         = { 2, 3, 1},
+		.muxsel         = { 2, 3, 1 },
 		.audiomux       = { 0x68, 0x68, 0x61, 0x61, 0x00 },
 		.pll            = PLL_28,
 	},
@@ -2433,7 +2433,7 @@
 		.svhs           = 2,
 		.gpiomask       = 0x0000000f,
 		.muxsel         = { 2, 1, 1 },
-		.audiomux       = { 0x02, 0x00, 0x00, 0x00, 0x00},
+		.audiomux       = { 0x02, 0x00, 0x00, 0x00, 0x00 },
 		.tuner_type     = TUNER_TEMIC_PAL,
 		.tuner_addr	= ADDR_UNSET,
 		.radio_addr     = ADDR_UNSET,
@@ -2466,7 +2466,7 @@
 		.video_inputs   = 2,
 		.tuner          = -1,
 		.svhs           = 1,
-		.muxsel         = { 3, 1, 2, 0}, /* Comp0, S-Video, ?, ? */
+		.muxsel         = { 3, 1, 2, 0 }, /* Comp0, S-Video, ?, ? */
 		.no_msp34xx     = 1,
 		.no_tda9875     = 1,
 		.no_tda7432     = 1,
@@ -2523,8 +2523,8 @@
 		.tuner          = 0,
 		.svhs           = -1,
 		.gpiomask       = 0xFF,
-		.muxsel         = { 2, 3, 1, 1},
-		.audiomux       = { 2, 0, 0, 0, 10},
+		.muxsel         = { 2, 3, 1, 1 },
+		.audiomux       = { 2, 0, 0, 0, 10 },
 		.needs_tvaudio  = 0,
 		.pll            = PLL_28,
 		.tuner_type     = TUNER_PHILIPS_PAL,
@@ -2557,8 +2557,8 @@
 		.tuner          = 0,
 		.svhs           = 2,
 		.gpiomask       = 0x3f,
-		.muxsel         = {2, 3, 1, 0},
-		.audiomux       = {0x31, 0x31, 0x31, 0x31, 0x31, 0x31},
+		.muxsel         = {2, 3, 1, 0 },
+		.audiomux       = {0x31, 0x31, 0x31, 0x31, 0x31, 0x31 },
 		.no_msp34xx     = 1,
 		.pll            = PLL_28,
 		.tuner_type     = TUNER_PHILIPS_NTSC_M,
@@ -2576,12 +2576,12 @@
 		.audio_inputs   = 1,
 		.tuner          = 0,
 		.svhs           = 2,
-		.muxsel         = { 2, 3, 1, 0},
+		.muxsel         = { 2, 3, 1, 0 },
 		.tuner_type     = TUNER_PHILIPS_NTSC,
 		.tuner_addr	= ADDR_UNSET,
 		.radio_addr     = ADDR_UNSET,
 		.gpiomask       = 0x008007,
-		.audiomux       = { 0, 0x000001,0,0, 0},
+		.audiomux       = { 0, 0x000001,0,0, 0 },
 		.needs_tvaudio  = 1,
 		.has_radio      = 1,
 	},
@@ -2672,7 +2672,7 @@
 		.audio_inputs   = 1,
 		.tuner          = 0,
 		.svhs           = 2,
-		.muxsel         = { 2, 3, 1, 0},
+		.muxsel         = { 2, 3, 1, 0 },
 		.tuner_type     = -1,
 		.tuner_addr	= ADDR_UNSET,
 		.radio_addr     = ADDR_UNSET,
@@ -2706,7 +2706,7 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0x01fe00,
-		.muxsel		= { 2, 3, 1, 1},
+		.muxsel		= { 2, 3, 1, 1 },
 		.audiomux       = { 0x001e00, 0, 0x018000, 0x014000, 0x002000, 0 },
 		.needs_tvaudio	= 1,
 		.pll		= PLL_28,
@@ -2794,8 +2794,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 15,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= {2,0,0,0,1},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 2, 0, 0, 0, 1 },
 		.needs_tvaudio	= 1,
 		.pll		= PLL_28,
 		.tuner_type	= 2,
@@ -2810,8 +2810,8 @@
 		.tuner		= 0,
 		.svhs		= 2,
 		.gpiomask	= 0x108007,
-		.muxsel		= { 2, 3, 1, 1},
-		.audiomux	= { 100000, 100002, 100002, 100000},
+		.muxsel		= { 2, 3, 1, 1 },
+		.audiomux	= { 100000, 100002, 100002, 100000 },
 		.no_msp34xx	= 1,
 		.no_tda9875     = 1,
 		.no_tda7432     = 1,
@@ -2828,7 +2828,7 @@
 		.tuner		= -1,
 		.svhs		= -1,
 		.gpiomask	= 0x0f, /* old: 7 */
-		.muxsel		= { 0, 1, 3, 2}, /* Composite 0-3 */
+		.muxsel		= { 0, 1, 3, 2 }, /* Composite 0-3 */
 		.no_msp34xx	= 1,
 		.no_tda9875     = 1,
 		.no_tda7432     = 1,
@@ -2836,6 +2836,29 @@
 		.tuner_addr	= ADDR_UNSET,
 		.radio_addr     = ADDR_UNSET,
 	},
+	[BTTV_BOARD_MACHTV_MAGICTV] = {
+		/* Julian Calaby <julian.calaby@gmail.com>
+		 * Slightly different from original MachTV definition (0x60)
+
+		 * FIXME: RegSpy says gpiomask should be "0x001c800f", but it
+		 * stuffs up remote chip. Bug is a pin on the jaecs is not set
+		 * properly (methinks) causing no keyup bits being set */
+
+		.name           = "MagicTV", /* rebranded MachTV */
+		.video_inputs   = 3,
+		.audio_inputs   = 1,
+		.tuner          = 0,
+		.svhs           = 2,
+		.gpiomask       = 7,
+		.muxsel         = { 2, 3, 1, 1 },
+		.audiomux       = { 0, 1, 2, 3, 4 },
+		.tuner_type     = TUNER_TEMIC_4009FR5_PAL,
+		.tuner_addr     = ADDR_UNSET,
+		.radio_addr     = ADDR_UNSET,
+		.pll            = PLL_28,
+		.has_radio      = 1,
+		.has_remote     = 1,
+	},
 };
 
 static const unsigned int bttv_num_tvcards = ARRAY_SIZE(bttv_tvcards);
diff --git a/drivers/media/video/bttv-gpio.c b/drivers/media/video/bttv-gpio.c
index 575ce8b..d64accc 100644
--- a/drivers/media/video/bttv-gpio.c
+++ b/drivers/media/video/bttv-gpio.c
@@ -64,10 +64,9 @@
 	struct bttv_sub_device *sub;
 	int err;
 
-	sub = kmalloc(sizeof(*sub),GFP_KERNEL);
+	sub = kzalloc(sizeof(*sub),GFP_KERNEL);
 	if (NULL == sub)
 		return -ENOMEM;
-	memset(sub,0,sizeof(*sub));
 
 	sub->core        = core;
 	sub->dev.parent  = &core->pci->dev;
diff --git a/drivers/media/video/bttv-input.c b/drivers/media/video/bttv-input.c
index 12197f1..221b36e 100644
--- a/drivers/media/video/bttv-input.c
+++ b/drivers/media/video/bttv-input.c
@@ -583,6 +583,12 @@
 		btv->custom_irq = bttv_rc5_irq;
 		ir->rc5_gpio = 1;
 		break;
+	case BTTV_BOARD_MACHTV_MAGICTV:
+		ir_codes         = ir_codes_apac_viewcomp;
+		ir->mask_keycode = 0x001F00;
+		ir->mask_keyup   = 0x004000;
+		ir->polling      = 50; /* ms */
+		break;
 	}
 	if (NULL == ir_codes) {
 		dprintk(KERN_INFO "Ooops: IR config error [card=%d]\n",btv->c.type);
diff --git a/drivers/media/video/bttv.h b/drivers/media/video/bttv.h
index 9feaa6b..e370d74 100644
--- a/drivers/media/video/bttv.h
+++ b/drivers/media/video/bttv.h
@@ -166,6 +166,7 @@
 #define BTTV_BOARD_ASOUND_SKYEYE	   0x8d
 #define BTTV_BOARD_SABRENT_TVFM   	   0x8e
 #define BTTV_BOARD_HAUPPAUGE_IMPACTVCB     0x8f
+#define BTTV_BOARD_MACHTV_MAGICTV          0x90
 
 /* i2c address list */
 #define I2C_TSA5522        0xc2
diff --git a/drivers/media/video/compat_ioctl32.c b/drivers/media/video/compat_ioctl32.c
index 6194b01..297c32a 100644
--- a/drivers/media/video/compat_ioctl32.c
+++ b/drivers/media/video/compat_ioctl32.c
@@ -18,8 +18,11 @@
 #include <linux/videodev2.h>
 #include <linux/module.h>
 #include <linux/smp_lock.h>
+#include <media/v4l2-common.h>
 
 #ifdef CONFIG_COMPAT
+
+
 struct video_tuner32 {
 	compat_int_t tuner;
 	char name[32];
@@ -30,27 +33,29 @@
 
 static int get_video_tuner32(struct video_tuner *kp, struct video_tuner32 __user *up)
 {
-	if(get_user(kp->tuner, &up->tuner))
+	if(!access_ok(VERIFY_READ, up, sizeof(struct video_tuner32)) ||
+		get_user(kp->tuner, &up->tuner) ||
+		copy_from_user(kp->name, up->name, 32) ||
+		get_user(kp->rangelow, &up->rangelow) ||
+		get_user(kp->rangehigh, &up->rangehigh) ||
+		get_user(kp->flags, &up->flags) ||
+		get_user(kp->mode, &up->mode) ||
+		get_user(kp->signal, &up->signal))
 		return -EFAULT;
-	__copy_from_user(kp->name, up->name, 32);
-	__get_user(kp->rangelow, &up->rangelow);
-	__get_user(kp->rangehigh, &up->rangehigh);
-	__get_user(kp->flags, &up->flags);
-	__get_user(kp->mode, &up->mode);
-	__get_user(kp->signal, &up->signal);
 	return 0;
 }
 
 static int put_video_tuner32(struct video_tuner *kp, struct video_tuner32 __user *up)
 {
-	if(put_user(kp->tuner, &up->tuner))
-		return -EFAULT;
-	__copy_to_user(up->name, kp->name, 32);
-	__put_user(kp->rangelow, &up->rangelow);
-	__put_user(kp->rangehigh, &up->rangehigh);
-	__put_user(kp->flags, &up->flags);
-	__put_user(kp->mode, &up->mode);
-	__put_user(kp->signal, &up->signal);
+	if(!access_ok(VERIFY_WRITE, up, sizeof(struct video_tuner32)) ||
+		put_user(kp->tuner, &up->tuner) ||
+		copy_to_user(up->name, kp->name, 32) ||
+		put_user(kp->rangelow, &up->rangelow) ||
+		put_user(kp->rangehigh, &up->rangehigh) ||
+		put_user(kp->flags, &up->flags) ||
+		put_user(kp->mode, &up->mode) ||
+		put_user(kp->signal, &up->signal))
+			return -EFAULT;
 	return 0;
 }
 
@@ -63,18 +68,19 @@
 {
 	u32 tmp;
 
-	if (get_user(tmp, &up->base))
-		return -EFAULT;
+	if (!access_ok(VERIFY_READ, up, sizeof(struct video_buffer32)) ||
+		get_user(tmp, &up->base) ||
+		get_user(kp->height, &up->height) ||
+		get_user(kp->width, &up->width) ||
+		get_user(kp->depth, &up->depth) ||
+		get_user(kp->bytesperline, &up->bytesperline))
+			return -EFAULT;
 
 	/* This is actually a physical address stored
 	 * as a void pointer.
 	 */
 	kp->base = (void *)(unsigned long) tmp;
 
-	__get_user(kp->height, &up->height);
-	__get_user(kp->width, &up->width);
-	__get_user(kp->depth, &up->depth);
-	__get_user(kp->bytesperline, &up->bytesperline);
 	return 0;
 }
 
@@ -82,12 +88,13 @@
 {
 	u32 tmp = (u32)((unsigned long)kp->base);
 
-	if(put_user(tmp, &up->base))
-		return -EFAULT;
-	__put_user(kp->height, &up->height);
-	__put_user(kp->width, &up->width);
-	__put_user(kp->depth, &up->depth);
-	__put_user(kp->bytesperline, &up->bytesperline);
+	if(!access_ok(VERIFY_WRITE, up, sizeof(struct video_buffer32)) ||
+		put_user(tmp, &up->base) ||
+		put_user(kp->height, &up->height) ||
+		put_user(kp->width, &up->width) ||
+		put_user(kp->depth, &up->depth) ||
+		put_user(kp->bytesperline, &up->bytesperline))
+			return -EFAULT;
 	return 0;
 }
 
@@ -121,14 +128,15 @@
 /* You get back everything except the clips... */
 static int put_video_window32(struct video_window *kp, struct video_window32 __user *up)
 {
-	if(put_user(kp->x, &up->x))
-		return -EFAULT;
-	__put_user(kp->y, &up->y);
-	__put_user(kp->width, &up->width);
-	__put_user(kp->height, &up->height);
-	__put_user(kp->chromakey, &up->chromakey);
-	__put_user(kp->flags, &up->flags);
-	__put_user(kp->clipcount, &up->clipcount);
+	if(!access_ok(VERIFY_WRITE, up, sizeof(struct video_window32)) ||
+		put_user(kp->x, &up->x) ||
+		put_user(kp->y, &up->y) ||
+		put_user(kp->width, &up->width) ||
+		put_user(kp->height, &up->height) ||
+		put_user(kp->chromakey, &up->chromakey) ||
+		put_user(kp->flags, &up->flags) ||
+		put_user(kp->clipcount, &up->clipcount))
+			return -EFAULT;
 	return 0;
 }
 
@@ -150,11 +158,12 @@
 
 static int get_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 __user *up)
 {
-	if (copy_from_user(&kp->w, &up->w, sizeof(up->w)))
-		return -EFAULT;
-	__get_user(kp->field, &up->field);
-	__get_user(kp->chromakey, &up->chromakey);
-	__get_user(kp->clipcount, &up->clipcount);
+	if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_window32)) ||
+		copy_from_user(&kp->w, &up->w, sizeof(up->w)) ||
+		get_user(kp->field, &up->field) ||
+		get_user(kp->chromakey, &up->chromakey) ||
+		get_user(kp->clipcount, &up->clipcount))
+			return -EFAULT;
 	if (kp->clipcount > 2048)
 		return -EINVAL;
 	if (kp->clipcount) {
@@ -165,7 +174,9 @@
 		kclips = compat_alloc_user_space(n * sizeof(struct v4l2_clip));
 		kp->clips = kclips;
 		while (--n >= 0) {
-			copy_from_user(&kclips->c, &uclips->c, sizeof(uclips->c));
+			if (!access_ok(VERIFY_READ, &uclips->c, sizeof(uclips->c)) ||
+				copy_from_user(&kclips->c, &uclips->c, sizeof(uclips->c)))
+				return -EFAULT;
 			kclips->next = n ? kclips + 1 : 0;
 			uclips += 1;
 			kclips += 1;
@@ -177,32 +188,45 @@
 
 static int put_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 __user *up)
 {
-	if (copy_to_user(&up->w, &kp->w, sizeof(up->w)))
-		return -EFAULT;
-	__put_user(kp->field, &up->field);
-	__put_user(kp->chromakey, &up->chromakey);
-	__put_user(kp->clipcount, &up->clipcount);
+	if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_window32)) ||
+		copy_to_user(&up->w, &kp->w, sizeof(up->w)) ||
+		put_user(kp->field, &up->field) ||
+		put_user(kp->chromakey, &up->chromakey) ||
+		put_user(kp->clipcount, &up->clipcount))
+			return -EFAULT;
 	return 0;
 }
 
 static inline int get_v4l2_pix_format(struct v4l2_pix_format *kp, struct v4l2_pix_format __user *up)
 {
-	return copy_from_user(kp, up, sizeof(struct v4l2_pix_format));
+	if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_pix_format)) ||
+		copy_from_user(kp, up, sizeof(struct v4l2_pix_format)))
+			return -EFAULT;
+	return 0;
 }
 
 static inline int put_v4l2_pix_format(struct v4l2_pix_format *kp, struct v4l2_pix_format __user *up)
 {
-	return copy_to_user(up, kp, sizeof(struct v4l2_pix_format));
+	if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_pix_format)) ||
+		copy_to_user(up, kp, sizeof(struct v4l2_pix_format)))
+			return -EFAULT;
+	return 0;
 }
 
 static inline int get_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct v4l2_vbi_format __user *up)
 {
-	return copy_from_user(kp, up, sizeof(struct v4l2_vbi_format));
+	if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_vbi_format)) ||
+		copy_from_user(kp, up, sizeof(struct v4l2_vbi_format)))
+			return -EFAULT;
+	return 0;
 }
 
 static inline int put_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct v4l2_vbi_format __user *up)
 {
-	return copy_to_user(up, kp, sizeof(struct v4l2_vbi_format));
+	if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_vbi_format)) ||
+		copy_to_user(up, kp, sizeof(struct v4l2_vbi_format)))
+			return -EFAULT;
+	return 0;
 }
 
 struct v4l2_format32
@@ -219,8 +243,9 @@
 
 static int get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)
 {
-	if(get_user(kp->type, &up->type))
-		return -EFAULT;
+	if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_format32)) ||
+			get_user(kp->type, &up->type))
+			return -EFAULT;
 	switch (kp->type) {
 	case V4L2_BUF_TYPE_VIDEO_CAPTURE:
 		return get_v4l2_pix_format(&kp->fmt.pix, &up->fmt.pix);
@@ -237,7 +262,8 @@
 
 static int put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)
 {
-	if(put_user(kp->type, &up->type))
+	if(!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_format32)) ||
+		put_user(kp->type, &up->type))
 		return -EFAULT;
 	switch (kp->type) {
 	case V4L2_BUF_TYPE_VIDEO_CAPTURE:
@@ -251,6 +277,23 @@
 	}
 }
 
+static inline int get_v4l2_standard(struct v4l2_standard *kp, struct v4l2_standard __user *up)
+{
+	if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_standard)) ||
+		copy_from_user(kp, up, sizeof(struct v4l2_standard)))
+			return -EFAULT;
+	return 0;
+
+}
+
+static inline int put_v4l2_standard(struct v4l2_standard *kp, struct v4l2_standard __user *up)
+{
+	if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_standard)) ||
+		copy_to_user(up, kp, sizeof(struct v4l2_standard)))
+			return -EFAULT;
+	return 0;
+}
+
 struct v4l2_standard32
 {
 	__u32		     index;
@@ -264,18 +307,39 @@
 static int get_v4l2_standard32(struct v4l2_standard *kp, struct v4l2_standard32 __user *up)
 {
 	/* other fields are not set by the user, nor used by the driver */
-	return get_user(kp->index, &up->index);
+	if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_standard32)) ||
+		get_user(kp->index, &up->index))
+		return -EFAULT;
+	return 0;
 }
 
 static int put_v4l2_standard32(struct v4l2_standard *kp, struct v4l2_standard32 __user *up)
 {
-	if(put_user(kp->index, &up->index))
-		return -EFAULT;
-	__copy_to_user(up->id, &kp->id, sizeof(__u64));
-	__copy_to_user(up->name, kp->name, 24);
-	__put_user(kp->frameperiod, &up->frameperiod);
-	__put_user(kp->framelines, &up->framelines);
-	__copy_to_user(up->reserved, kp->reserved, 4 * sizeof(__u32));
+	if(!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_standard32)) ||
+		put_user(kp->index, &up->index) ||
+		copy_to_user(up->id, &kp->id, sizeof(__u64)) ||
+		copy_to_user(up->name, kp->name, 24) ||
+		copy_to_user(&up->frameperiod, &kp->frameperiod, sizeof(kp->frameperiod)) ||
+		put_user(kp->framelines, &up->framelines) ||
+		copy_to_user(up->reserved, kp->reserved, 4 * sizeof(__u32)))
+			return -EFAULT;
+	return 0;
+}
+
+static inline int get_v4l2_tuner(struct v4l2_tuner *kp, struct v4l2_tuner __user *up)
+{
+	if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_tuner)) ||
+		copy_from_user(kp, up, sizeof(struct v4l2_tuner)))
+			return -EFAULT;
+	return 0;
+
+}
+
+static inline int put_v4l2_tuner(struct v4l2_tuner *kp, struct v4l2_tuner __user *up)
+{
+	if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_tuner)) ||
+		copy_to_user(up, kp, sizeof(struct v4l2_tuner)))
+			return -EFAULT;
 	return 0;
 }
 
@@ -304,12 +368,13 @@
 static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user *up)
 {
 
-	if (get_user(kp->index, &up->index))
-		return -EFAULT;
-	__get_user(kp->type, &up->type);
-	__get_user(kp->flags, &up->flags);
-	__get_user(kp->memory, &up->memory);
-	__get_user(kp->input, &up->input);
+	if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_buffer32)) ||
+		get_user(kp->index, &up->index) ||
+		get_user(kp->type, &up->type) ||
+		get_user(kp->flags, &up->flags) ||
+		get_user(kp->memory, &up->memory) ||
+		get_user(kp->input, &up->input))
+			return -EFAULT;
 	switch(kp->memory) {
 	case V4L2_MEMORY_MMAP:
 		break;
@@ -317,12 +382,14 @@
 		{
 		unsigned long tmp = (unsigned long)compat_ptr(up->m.userptr);
 
-		__get_user(kp->length, &up->length);
-		__get_user(kp->m.userptr, &tmp);
+		if(get_user(kp->length, &up->length) ||
+			get_user(kp->m.userptr, &tmp))
+				return -EFAULT;
 		}
 		break;
 	case V4L2_MEMORY_OVERLAY:
-		__get_user(kp->m.offset, &up->m.offset);
+		if(get_user(kp->m.offset, &up->m.offset))
+			return -EFAULT;
 		break;
 	}
 	return 0;
@@ -330,32 +397,37 @@
 
 static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user *up)
 {
-	if (put_user(kp->index, &up->index))
-		return -EFAULT;
-	__put_user(kp->type, &up->type);
-	__put_user(kp->flags, &up->flags);
-	__put_user(kp->memory, &up->memory);
-	__put_user(kp->input, &up->input);
+	if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_buffer32)) ||
+		put_user(kp->index, &up->index) ||
+		put_user(kp->type, &up->type) ||
+		put_user(kp->flags, &up->flags) ||
+		put_user(kp->memory, &up->memory) ||
+		put_user(kp->input, &up->input))
+			return -EFAULT;
 	switch(kp->memory) {
 	case V4L2_MEMORY_MMAP:
-		__put_user(kp->length, &up->length);
-		__put_user(kp->m.offset, &up->m.offset);
+		if (put_user(kp->length, &up->length) ||
+			put_user(kp->m.offset, &up->m.offset))
+			return -EFAULT;
 		break;
 	case V4L2_MEMORY_USERPTR:
-		__put_user(kp->length, &up->length);
-		__put_user(kp->m.userptr, &up->m.userptr);
+		if (put_user(kp->length, &up->length) ||
+			put_user(kp->m.userptr, &up->m.userptr))
+			return -EFAULT;
 		break;
 	case V4L2_MEMORY_OVERLAY:
-		__put_user(kp->m.offset, &up->m.offset);
+		if (put_user(kp->m.offset, &up->m.offset))
+			return -EFAULT;
 		break;
 	}
-	__put_user(kp->bytesused, &up->bytesused);
-	__put_user(kp->field, &up->field);
-	__put_user(kp->timestamp.tv_sec, &up->timestamp.tv_sec);
-	__put_user(kp->timestamp.tv_usec, &up->timestamp.tv_usec);
-	__copy_to_user(&up->timecode, &kp->timecode, sizeof(struct v4l2_timecode));
-	__put_user(kp->sequence, &up->sequence);
-	__put_user(kp->reserved, &up->reserved);
+	if (put_user(kp->bytesused, &up->bytesused) ||
+		put_user(kp->field, &up->field) ||
+		put_user(kp->timestamp.tv_sec, &up->timestamp.tv_sec) ||
+		put_user(kp->timestamp.tv_usec, &up->timestamp.tv_usec) ||
+		copy_to_user(&up->timecode, &kp->timecode, sizeof(struct v4l2_timecode)) ||
+		put_user(kp->sequence, &up->sequence) ||
+		put_user(kp->reserved, &up->reserved))
+			return -EFAULT;
 	return 0;
 }
 
@@ -371,11 +443,12 @@
 {
 	u32 tmp;
 
-	if (get_user(tmp, &up->base))
-		return -EFAULT;
+	if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_framebuffer32)) ||
+		get_user(tmp, &up->base) ||
+		get_user(kp->capability, &up->capability) ||
+		get_user(kp->flags, &up->flags))
+			return -EFAULT;
 	kp->base = compat_ptr(tmp);
-	__get_user(kp->capability, &up->capability);
-	__get_user(kp->flags, &up->flags);
 	get_v4l2_pix_format(&kp->fmt, &up->fmt);
 	return 0;
 }
@@ -384,25 +457,46 @@
 {
 	u32 tmp = (u32)((unsigned long)kp->base);
 
-	if(put_user(tmp, &up->base))
-		return -EFAULT;
-	__put_user(kp->capability, &up->capability);
-	__put_user(kp->flags, &up->flags);
+	if(!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_framebuffer32)) ||
+		put_user(tmp, &up->base) ||
+		put_user(kp->capability, &up->capability) ||
+		put_user(kp->flags, &up->flags))
+			return -EFAULT;
 	put_v4l2_pix_format(&kp->fmt, &up->fmt);
 	return 0;
 }
 
-struct v4l2_input32 	/* identical layout, but different size */
+static inline int get_v4l2_input32(struct v4l2_input *kp, struct v4l2_input __user *up)
 {
-	__u32	     index;		/*  Which input */
-	__u8	     name[32];		/*  Label */
-	__u32	     type;		/*  Type of input */
-	__u32	     audioset;		/*  Associated audios (bitfield) */
-	__u32        tuner;             /*  Associated tuner */
-	__u32	     std[2];		/* __u64 would get the padding wrong */
-	__u32	     status;
-	__u32	     reserved[4];
-};
+	if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_input) - 4) ||
+		copy_from_user(kp, up, sizeof(struct v4l2_input) - 4))
+			return -EFAULT;
+	return 0;
+}
+
+static inline int put_v4l2_input32(struct v4l2_input *kp, struct v4l2_input __user *up)
+{
+	if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_input) - 4) ||
+		copy_to_user(up, kp, sizeof(struct v4l2_input) - 4))
+			return -EFAULT;
+	return 0;
+}
+
+static inline int get_v4l2_input(struct v4l2_input *kp, struct v4l2_input __user *up)
+{
+	if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_input)) ||
+		copy_from_user(kp, up, sizeof(struct v4l2_input)))
+			return -EFAULT;
+	return 0;
+}
+
+static inline int put_v4l2_input(struct v4l2_input *kp, struct v4l2_input __user *up)
+{
+	if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_input)) ||
+		copy_to_user(up, kp, sizeof(struct v4l2_input)))
+			return -EFAULT;
+	return 0;
+}
 
 #define VIDIOCGTUNER32		_IOWR('v',4, struct video_tuner32)
 #define VIDIOCSTUNER32		_IOW('v',5, struct video_tuner32)
@@ -413,6 +507,8 @@
 #define VIDIOCGFREQ32		_IOR('v',14, u32)
 #define VIDIOCSFREQ32		_IOW('v',15, u32)
 
+/* VIDIOC_ENUMINPUT32 is VIDIOC_ENUMINPUT minus 4 bytes of padding alignement */
+#define VIDIOC_ENUMINPUT32	VIDIOC_ENUMINPUT - _IOC(0, 0, 0, 4)
 #define VIDIOC_G_FMT32		_IOWR ('V',  4, struct v4l2_format32)
 #define VIDIOC_S_FMT32		_IOWR ('V',  5, struct v4l2_format32)
 #define VIDIOC_QUERYBUF32	_IOWR ('V',  9, struct v4l2_buffer32)
@@ -425,7 +521,6 @@
 #define VIDIOC_STREAMON32	_IOW  ('V', 18, compat_int_t)
 #define VIDIOC_STREAMOFF32	_IOW  ('V', 19, compat_int_t)
 #define VIDIOC_ENUMSTD32	_IOWR ('V', 25, struct v4l2_standard32)
-#define VIDIOC_ENUMINPUT32	_IOWR ('V', 26, struct v4l2_input32)
 /* VIDIOC_S_CTRL is now _IOWR, but was _IOW */
 #define VIDIOC_S_CTRL32		_IOW  ('V', 28, struct v4l2_control)
 #define VIDIOC_G_INPUT32	_IOR  ('V', 38, compat_int_t)
@@ -444,6 +539,9 @@
 	int nclips;
 	u32 n;
 
+	if (!access_ok(VERIFY_READ, up, sizeof(struct video_window32)))
+		return -EFAULT;
+
 	if (get_user(nclips, &up->clipcount))
 		return -EFAULT;
 
@@ -476,7 +574,9 @@
 			return -EINVAL;
 		for (i = 0; i < nclips; i++, u++, p++) {
 			s32 v;
-			if (get_user(v, &u->x) ||
+			if (!access_ok(VERIFY_READ, u, sizeof(struct video_clip32)) ||
+			    !access_ok(VERIFY_WRITE, p, sizeof(struct video_clip32)) ||
+			    get_user(v, &u->x) ||
 			    put_user(v, &p->x) ||
 			    get_user(v, &u->y) ||
 			    put_user(v, &p->y) ||
@@ -502,11 +602,14 @@
 		struct v4l2_buffer v2b;
 		struct v4l2_framebuffer v2fb;
 		struct v4l2_standard v2s;
+		struct v4l2_input v2i;
+		struct v4l2_tuner v2t;
 		unsigned long vx;
 	} karg;
 	void __user *up = compat_ptr(arg);
 	int compatible_arg = 1;
 	int err = 0;
+	int realcmd = cmd;
 
 	/* First, convert the command. */
 	switch(cmd) {
@@ -527,8 +630,8 @@
 	case VIDIOC_G_FBUF32: cmd = VIDIOC_G_FBUF; break;
 	case VIDIOC_S_FBUF32: cmd = VIDIOC_S_FBUF; break;
 	case VIDIOC_OVERLAY32: cmd = VIDIOC_OVERLAY; break;
-	case VIDIOC_ENUMSTD32: cmd = VIDIOC_ENUMSTD; break;
-	case VIDIOC_ENUMINPUT32: cmd = VIDIOC_ENUMINPUT; break;
+	case VIDIOC_ENUMSTD32: realcmd = VIDIOC_ENUMSTD; break;
+	case VIDIOC_ENUMINPUT32: realcmd = VIDIOC_ENUMINPUT; break;
 	case VIDIOC_S_CTRL32: cmd = VIDIOC_S_CTRL; break;
 	case VIDIOC_G_INPUT32: cmd = VIDIOC_G_INPUT; break;
 	case VIDIOC_S_INPUT32: cmd = VIDIOC_S_INPUT; break;
@@ -577,10 +680,31 @@
 		break;
 
 	case VIDIOC_ENUMSTD:
+		err = get_v4l2_standard(&karg.v2s, up);
+		compatible_arg = 0;
+		break;
+
+	case VIDIOC_ENUMSTD32:
 		err = get_v4l2_standard32(&karg.v2s, up);
 		compatible_arg = 0;
 		break;
 
+	case VIDIOC_ENUMINPUT:
+		err = get_v4l2_input(&karg.v2i, up);
+		compatible_arg = 0;
+		break;
+
+	case VIDIOC_ENUMINPUT32:
+		err = get_v4l2_input32(&karg.v2i, up);
+		compatible_arg = 0;
+		break;
+
+	case VIDIOC_G_TUNER:
+	case VIDIOC_S_TUNER:
+		err = get_v4l2_tuner(&karg.v2t, up);
+		compatible_arg = 0;
+		break;
+
 	case VIDIOCGWIN:
 	case VIDIOCGFBUF:
 	case VIDIOCGFREQ:
@@ -593,12 +717,12 @@
 		goto out;
 
 	if(compatible_arg)
-		err = native_ioctl(file, cmd, (unsigned long)up);
+		err = native_ioctl(file, realcmd, (unsigned long)up);
 	else {
 		mm_segment_t old_fs = get_fs();
 
 		set_fs(KERNEL_DS);
-		err = native_ioctl(file, cmd, (unsigned long)&karg);
+		err = native_ioctl(file, realcmd, (unsigned long)&karg);
 		set_fs(old_fs);
 	}
 	if(err == 0) {
@@ -632,9 +756,26 @@
 			break;
 
 		case VIDIOC_ENUMSTD:
+			err = put_v4l2_standard(&karg.v2s, up);
+			break;
+
+		case VIDIOC_ENUMSTD32:
 			err = put_v4l2_standard32(&karg.v2s, up);
 			break;
 
+		case VIDIOC_G_TUNER:
+		case VIDIOC_S_TUNER:
+			err = put_v4l2_tuner(&karg.v2t, up);
+			break;
+
+		case VIDIOC_ENUMINPUT:
+			err = put_v4l2_input(&karg.v2i, up);
+			break;
+
+		case VIDIOC_ENUMINPUT32:
+			err = put_v4l2_input32(&karg.v2i, up);
+			break;
+
 		case VIDIOCGFREQ:
 		case VIDIOC_G_INPUT:
 			err = put_user(((u32)karg.vx), (u32 __user *)up);
@@ -679,7 +820,11 @@
 	case VIDIOC_G_PARM:
 	case VIDIOC_G_STD:
 	case VIDIOC_S_STD:
+	case VIDIOC_G_TUNER:
+	case VIDIOC_S_TUNER:
+	case VIDIOC_ENUMSTD:
 	case VIDIOC_ENUMSTD32:
+	case VIDIOC_ENUMINPUT:
 	case VIDIOC_ENUMINPUT32:
 	case VIDIOC_G_CTRL:
 	case VIDIOC_S_CTRL32:
@@ -718,6 +863,8 @@
 	case _IOR('v' , BASE_VIDIOCPRIVATE+7, int):
 		ret = native_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
 		break;
+	default:
+		v4l_print_ioctl("compat_ioctl32", cmd);
 	}
 	return ret;
 }
diff --git a/drivers/media/video/cpia_pp.c b/drivers/media/video/cpia_pp.c
index 6861d40..74cff62 100644
--- a/drivers/media/video/cpia_pp.c
+++ b/drivers/media/video/cpia_pp.c
@@ -702,12 +702,11 @@
 		return -ENXIO;
 	}
 
-	cam = kmalloc(sizeof(struct pp_cam_entry), GFP_KERNEL);
+	cam = kzalloc(sizeof(struct pp_cam_entry), GFP_KERNEL);
 	if (cam == NULL) {
 		LOG("failed to allocate camera structure\n");
 		return -ENOMEM;
 	}
-	memset(cam,0,sizeof(struct pp_cam_entry));
 	
 	pdev = parport_register_device(port, "cpia_pp", NULL, NULL,
 	                               NULL, 0, cam);
diff --git a/drivers/media/video/cpia_usb.c b/drivers/media/video/cpia_usb.c
index 1439cb7..03275c3 100644
--- a/drivers/media/video/cpia_usb.c
+++ b/drivers/media/video/cpia_usb.c
@@ -499,14 +499,12 @@
 
 	printk(KERN_INFO "USB CPiA camera found\n");
 
-	ucpia = kmalloc(sizeof(*ucpia), GFP_KERNEL);
+	ucpia = kzalloc(sizeof(*ucpia), GFP_KERNEL);
 	if (!ucpia) {
 		printk(KERN_ERR "couldn't kmalloc cpia struct\n");
 		return -ENOMEM;
 	}
 
-	memset(ucpia, 0, sizeof(*ucpia));
-
 	ucpia->dev = udev;
 	ucpia->iface = interface->desc.bInterfaceNumber;
 	init_waitqueue_head(&ucpia->wq_stream);
diff --git a/drivers/media/video/cs53l32a.c b/drivers/media/video/cs53l32a.c
index b421068..8739c64 100644
--- a/drivers/media/video/cs53l32a.c
+++ b/drivers/media/video/cs53l32a.c
@@ -141,11 +141,10 @@
 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
 		return 0;
 
-	client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
+	client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
 	if (client == 0)
 		return -ENOMEM;
 
-	memset(client, 0, sizeof(struct i2c_client));
 	client->addr = address;
 	client->adapter = adapter;
 	client->driver = &i2c_driver;
@@ -156,7 +155,7 @@
 	for (i = 1; i <= 7; i++) {
 		u8 v = cs53l32a_read(client, i);
 
-		v4l_dbg(1, client, "Read Reg %d %02x\n", i, v);
+		v4l_dbg(1, debug, client, "Read Reg %d %02x\n", i, v);
 	}
 
 	/* Set cs53l32a internal register for Adaptec 2010/2410 setup */
@@ -174,7 +173,7 @@
 	for (i = 1; i <= 7; i++) {
 		u8 v = cs53l32a_read(client, i);
 
-		v4l_dbg(1, client, "Read Reg %d %02x\n", i, v);
+		v4l_dbg(1, debug, client, "Read Reg %d %02x\n", i, v);
 	}
 
 	i2c_attach_client(client);
diff --git a/drivers/media/video/cx25840/cx25840-core.c b/drivers/media/video/cx25840/cx25840-core.c
index d45237d..1d75a42 100644
--- a/drivers/media/video/cx25840/cx25840-core.c
+++ b/drivers/media/video/cx25840/cx25840-core.c
@@ -43,9 +43,9 @@
 static unsigned short normal_i2c[] = { 0x88 >> 1, I2C_CLIENT_END };
 
 
-int debug = 0;
+int cx25840_debug = 0;
 
-module_param(debug, bool, 0644);
+module_param_named(debug,cx25840_debug, int, 0644);
 
 MODULE_PARM_DESC(debug, "Debugging messages [0=Off (default) 1=On]");
 
@@ -265,7 +265,7 @@
 			   vid_input <= CX25840_COMPOSITE8);
 	u8 reg;
 
-	v4l_dbg(1, client, "decoder set video input %d, audio input %d\n",
+	v4l_dbg(1, cx25840_debug, client, "decoder set video input %d, audio input %d\n",
 			vid_input, aud_input);
 
 	if (is_composite) {
@@ -533,7 +533,7 @@
 		else
 			filter = 3;
 
-		v4l_dbg(1, client, "decoder set size %dx%d -> scale  %ux%u\n",
+		v4l_dbg(1, cx25840_debug, client, "decoder set size %dx%d -> scale  %ux%u\n",
 			    pix->width, pix->height, HSC, VSC);
 
 		/* HSCALE=HSC */
@@ -687,13 +687,13 @@
 		return cx25840_audio(client, cmd, arg);
 
 	case VIDIOC_STREAMON:
-		v4l_dbg(1, client, "enable output\n");
+		v4l_dbg(1, cx25840_debug, client, "enable output\n");
 		cx25840_write(client, 0x115, 0x8c);
 		cx25840_write(client, 0x116, 0x07);
 		break;
 
 	case VIDIOC_STREAMOFF:
-		v4l_dbg(1, client, "disable output\n");
+		v4l_dbg(1, cx25840_debug, client, "disable output\n");
 		cx25840_write(client, 0x115, 0x00);
 		cx25840_write(client, 0x116, 0x00);
 		break;
@@ -862,17 +862,16 @@
 	if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
 		return 0;
 
-	client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
+	client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
 	if (client == 0)
 		return -ENOMEM;
 
-	memset(client, 0, sizeof(struct i2c_client));
 	client->addr = address;
 	client->adapter = adapter;
 	client->driver = &i2c_driver_cx25840;
 	snprintf(client->name, sizeof(client->name) - 1, "cx25840");
 
-	v4l_dbg(1, client, "detecting cx25840 client on address 0x%x\n", address << 1);
+	v4l_dbg(1, cx25840_debug, client, "detecting cx25840 client on address 0x%x\n", address << 1);
 
 	device_id = cx25840_read(client, 0x101) << 8;
 	device_id |= cx25840_read(client, 0x100);
@@ -880,7 +879,7 @@
 	/* The high byte of the device ID should be
 	 * 0x84 if chip is present */
 	if ((device_id & 0xff00) != 0x8400) {
-		v4l_dbg(1, client, "cx25840 not found\n");
+		v4l_dbg(1, cx25840_debug, client, "cx25840 not found\n");
 		kfree(client);
 		return 0;
 	}
diff --git a/drivers/media/video/cx88/cx88-blackbird.c b/drivers/media/video/cx88/cx88-blackbird.c
index a490621..a502a4d 100644
--- a/drivers/media/video/cx88/cx88-blackbird.c
+++ b/drivers/media/video/cx88/cx88-blackbird.c
@@ -1539,10 +1539,9 @@
 	dprintk(1,"open minor=%d\n",minor);
 
 	/* allocate + initialize per filehandle data */
-	fh = kmalloc(sizeof(*fh),GFP_KERNEL);
+	fh = kzalloc(sizeof(*fh),GFP_KERNEL);
 	if (NULL == fh)
 		return -ENOMEM;
-	memset(fh,0,sizeof(*fh));
 	file->private_data = fh;
 	fh->dev      = dev;
 
@@ -1678,10 +1677,9 @@
 		goto fail_core;
 
 	err = -ENOMEM;
-	dev = kmalloc(sizeof(*dev),GFP_KERNEL);
+	dev = kzalloc(sizeof(*dev),GFP_KERNEL);
 	if (NULL == dev)
 		goto fail_core;
-	memset(dev,0,sizeof(*dev));
 	dev->pci = pci_dev;
 	dev->core = core;
 	dev->width = 720;
diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c
index a76d545..ad2f565 100644
--- a/drivers/media/video/cx88/cx88-cards.c
+++ b/drivers/media/video/cx88/cx88-cards.c
@@ -1244,6 +1244,11 @@
 		.subvendor = 0x18ac,
 		.subdevice = 0xdb50,
 		.card      = CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL,
+	},{
+		.subvendor = 0x18ac,
+		.subdevice = 0xdb11,
+		.card      = CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS,
+		/* Re-branded DViCO: UltraView DVB-T Plus */
 	},
 };
 const unsigned int cx88_idcount = ARRAY_SIZE(cx88_subids);
diff --git a/drivers/media/video/cx88/cx88-core.c b/drivers/media/video/cx88/cx88-core.c
index 9975be1..194446f 100644
--- a/drivers/media/video/cx88/cx88-core.c
+++ b/drivers/media/video/cx88/cx88-core.c
@@ -1050,11 +1050,10 @@
 		up(&devlist);
 		return core;
 	}
-	core = kmalloc(sizeof(*core),GFP_KERNEL);
+	core = kzalloc(sizeof(*core),GFP_KERNEL);
 	if (NULL == core)
 		goto fail_unlock;
 
-	memset(core,0,sizeof(*core));
 	atomic_inc(&core->refcount);
 	core->pci_bus  = pci->bus->number;
 	core->pci_slot = PCI_SLOT(pci->devfn);
diff --git a/drivers/media/video/cx88/cx88-dvb.c b/drivers/media/video/cx88/cx88-dvb.c
index 42c012a..e48aa3f 100644
--- a/drivers/media/video/cx88/cx88-dvb.c
+++ b/drivers/media/video/cx88/cx88-dvb.c
@@ -657,10 +657,9 @@
 		goto fail_core;
 
 	err = -ENOMEM;
-	dev = kmalloc(sizeof(*dev),GFP_KERNEL);
+	dev = kzalloc(sizeof(*dev),GFP_KERNEL);
 	if (NULL == dev)
 		goto fail_core;
-	memset(dev,0,sizeof(*dev));
 	dev->pci = pci_dev;
 	dev->core = core;
 
diff --git a/drivers/media/video/cx88/cx88-input.c b/drivers/media/video/cx88/cx88-input.c
index 286c85b..da2ad5c 100644
--- a/drivers/media/video/cx88/cx88-input.c
+++ b/drivers/media/video/cx88/cx88-input.c
@@ -697,6 +697,7 @@
 	case CX88_BOARD_HAUPPAUGE_DVB_T1:
 	case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
 	case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
+	case CX88_BOARD_HAUPPAUGE_HVR1100:
 		ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7);
 		ir_dprintk("biphase decoded: %x\n", ircode);
 		if ((ircode & 0xfffff000) != 0x3000)
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index 9a02515..073494c 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -750,10 +750,9 @@
 		minor,radio,v4l2_type_names[type]);
 
 	/* allocate + initialize per filehandle data */
-	fh = kmalloc(sizeof(*fh),GFP_KERNEL);
+	fh = kzalloc(sizeof(*fh),GFP_KERNEL);
 	if (NULL == fh)
 		return -ENOMEM;
-	memset(fh,0,sizeof(*fh));
 	file->private_data = fh;
 	fh->dev      = dev;
 	fh->radio    = radio;
@@ -1809,10 +1808,9 @@
 	struct cx88_core *core;
 	int err;
 
-	dev = kmalloc(sizeof(*dev),GFP_KERNEL);
+	dev = kzalloc(sizeof(*dev),GFP_KERNEL);
 	if (NULL == dev)
 		return -ENOMEM;
-	memset(dev,0,sizeof(*dev));
 
 	/* pci init */
 	dev->pci = pci_dev;
diff --git a/drivers/media/video/dpc7146.c b/drivers/media/video/dpc7146.c
index da94811..2831bdd 100644
--- a/drivers/media/video/dpc7146.c
+++ b/drivers/media/video/dpc7146.c
@@ -94,12 +94,11 @@
 	struct i2c_client *client;
 	struct list_head *item;
 
-	dpc = (struct dpc*)kmalloc(sizeof(struct dpc), GFP_KERNEL);
+	dpc = kzalloc(sizeof(struct dpc), GFP_KERNEL);
 	if( NULL == dpc ) {
 		printk("dpc_v4l2.o: dpc_probe: not enough kernel memory.\n");
 		return -ENOMEM;
 	}
-	memset(dpc, 0x0, sizeof(struct dpc));	
 
 	/* FIXME: enable i2c-port pins, video-port-pins
 	   video port pins should be enabled here ?! */
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index fdc25591..3323dff 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -1861,12 +1861,11 @@
 	}
 
 	/* allocate memory for our device state and initialize it */
-	dev = kmalloc(sizeof(*dev), GFP_KERNEL);
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
 	if (dev == NULL) {
 		em28xx_err(DRIVER_NAME ": out of memory!\n");
 		return -ENOMEM;
 	}
-	memset(dev, 0, sizeof(*dev));
 
 	/* compute alternate max packet sizes */
 	uif = udev->actconfig->interface[0];
diff --git a/drivers/media/video/hexium_gemini.c b/drivers/media/video/hexium_gemini.c
index c9b00ea..e7bbeb1 100644
--- a/drivers/media/video/hexium_gemini.c
+++ b/drivers/media/video/hexium_gemini.c
@@ -240,12 +240,11 @@
 
 	DEB_EE((".\n"));
 
-	hexium = (struct hexium *) kmalloc(sizeof(struct hexium), GFP_KERNEL);
+	hexium = kzalloc(sizeof(struct hexium), GFP_KERNEL);
 	if (NULL == hexium) {
 		printk("hexium_gemini: not enough kernel memory in hexium_attach().\n");
 		return -ENOMEM;
 	}
-	memset(hexium, 0x0, sizeof(struct hexium));
 	dev->ext_priv = hexium;
 
 	/* enable i2c-port pins */
diff --git a/drivers/media/video/hexium_orion.c b/drivers/media/video/hexium_orion.c
index 42a9414..0b6c209 100644
--- a/drivers/media/video/hexium_orion.c
+++ b/drivers/media/video/hexium_orion.c
@@ -224,12 +224,11 @@
 		return -EFAULT;
 	}
 
-	hexium = (struct hexium *) kmalloc(sizeof(struct hexium), GFP_KERNEL);
+	hexium = kzalloc(sizeof(struct hexium), GFP_KERNEL);
 	if (NULL == hexium) {
 		printk("hexium_orion: hexium_probe: not enough kernel memory.\n");
 		return -ENOMEM;
 	}
-	memset(hexium, 0x0, sizeof(struct hexium));
 
 	/* enable i2c-port pins */
 	saa7146_write(dev, MC1, (MASK_08 | MASK_24 | MASK_10 | MASK_26));
diff --git a/drivers/media/video/indycam.c b/drivers/media/video/indycam.c
index bb5cbec..7420b79 100644
--- a/drivers/media/video/indycam.c
+++ b/drivers/media/video/indycam.c
@@ -289,18 +289,15 @@
 	printk(KERN_INFO "SGI IndyCam driver version %s\n",
 	       INDYCAM_MODULE_VERSION);
 
-	client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
+	client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
 	if (!client)
 		return -ENOMEM;
-	camera = kmalloc(sizeof(struct indycam), GFP_KERNEL);
+	camera = kzalloc(sizeof(struct indycam), GFP_KERNEL);
 	if (!camera) {
 		err = -ENOMEM;
 		goto out_free_client;
 	}
 
-	memset(client, 0, sizeof(struct i2c_client));
-	memset(camera, 0, sizeof(struct indycam));
-
 	client->addr = addr;
 	client->adapter = adap;
 	client->driver = &i2c_driver_indycam;
diff --git a/drivers/media/video/msp3400-driver.c b/drivers/media/video/msp3400-driver.c
index aa8c556..9b05a0a 100644
--- a/drivers/media/video/msp3400-driver.c
+++ b/drivers/media/video/msp3400-driver.c
@@ -66,26 +66,26 @@
 
 /* module parameters */
 static int opmode   = OPMODE_AUTO;
-int debug    = 0;    /* debug output */
-int once     = 0;    /* no continous stereo monitoring */
-int amsound  = 0;    /* hard-wire AM sound at 6.5 Hz (france),
+int msp_debug    = 0;    /* msp_debug output */
+int msp_once     = 0;    /* no continous stereo monitoring */
+int msp_amsound  = 0;    /* hard-wire AM sound at 6.5 Hz (france),
 			       the autoscan seems work well only with FM... */
-int standard = 1;    /* Override auto detect of audio standard, if needed. */
-int dolby    = 0;
+int msp_standard = 1;    /* Override auto detect of audio msp_standard, if needed. */
+int msp_dolby    = 0;
 
-int stereo_threshold = 0x190; /* a2 threshold for stereo/bilingual
+int msp_stereo_thresh = 0x190; /* a2 threshold for stereo/bilingual
 					(msp34xxg only) 0x00a0-0x03c0 */
 
 /* read-only */
 module_param(opmode,           int, 0444);
 
 /* read-write */
-module_param(once,             bool, 0644);
-module_param(debug,            int, 0644);
-module_param(stereo_threshold, int, 0644);
-module_param(standard,         int, 0644);
-module_param(amsound,          bool, 0644);
-module_param(dolby,            bool, 0644);
+module_param_named(once,msp_once,                      bool, 0644);
+module_param_named(debug,msp_debug,                    int,  0644);
+module_param_named(stereo_threshold,msp_stereo_thresh, int,  0644);
+module_param_named(standard,msp_standard,              int,  0644);
+module_param_named(amsound,msp_amsound,                bool, 0644);
+module_param_named(dolby,msp_dolby,                    bool, 0644);
 
 MODULE_PARM_DESC(opmode, "Forces a MSP3400 opmode. 0=Manual, 1=Autodetect, 2=Autodetect and autoselect");
 MODULE_PARM_DESC(once, "No continuous stereo monitoring");
@@ -127,7 +127,7 @@
 		{ client->addr, I2C_M_RD, 2, read  },
 	};
 
-	v4l_dbg(3, client, "msp_reset\n");
+	v4l_dbg(3, msp_debug, client, "msp_reset\n");
 	if (i2c_transfer(client->adapter, &reset[0], 1) != 1 ||
 	    i2c_transfer(client->adapter, &reset[1], 1) != 1 ||
 	    i2c_transfer(client->adapter, test, 2) != 2) {
@@ -165,7 +165,7 @@
 		return -1;
 	}
 	retval = read[0] << 8 | read[1];
-	v4l_dbg(3, client, "msp_read(0x%x, 0x%x): 0x%x\n", dev, addr, retval);
+	v4l_dbg(3, msp_debug, client, "msp_read(0x%x, 0x%x): 0x%x\n", dev, addr, retval);
 	return retval;
 }
 
@@ -190,7 +190,7 @@
 	buffer[3] = val  >> 8;
 	buffer[4] = val  &  0xff;
 
-	v4l_dbg(3, client, "msp_write(0x%x, 0x%x, 0x%x)\n", dev, addr, val);
+	v4l_dbg(3, msp_debug, client, "msp_write(0x%x, 0x%x, 0x%x)\n", dev, addr, val);
 	for (err = 0; err < 3; err++) {
 		if (i2c_master_send(client, buffer, 5) == 5)
 			break;
@@ -273,7 +273,7 @@
 	} else
 		state->acb = 0xf60; /* Mute Input and SCART 1 Output */
 
-	v4l_dbg(1, client, "scart switch: %s => %d (ACB=0x%04x)\n",
+	v4l_dbg(1, msp_debug, client, "scart switch: %s => %d (ACB=0x%04x)\n",
 						scart_names[in], out, state->acb);
 	msp_write_dsp(client, 0x13, state->acb);
 
@@ -285,7 +285,7 @@
 {
 	struct msp_state *state = i2c_get_clientdata(client);
 
-	v4l_dbg(1, client, "mute audio\n");
+	v4l_dbg(1, msp_debug, client, "mute audio\n");
 	msp_write_dsp(client, 0x0000, 0);
 	msp_write_dsp(client, 0x0007, 1);
 	if (state->has_scart2_out_volume)
@@ -303,7 +303,7 @@
 	if (!state->muted)
 		val = (state->volume * 0x7f / 65535) << 8;
 
-	v4l_dbg(1, client, "mute=%s volume=%d\n",
+	v4l_dbg(1, msp_debug, client, "mute=%s volume=%d\n",
 		state->muted ? "on" : "off", state->volume);
 
 	msp_write_dsp(client, 0x0000, val);
@@ -321,7 +321,7 @@
 	treble = ((state->treble - 32768) * 0x60 / 65535) << 8;
 	loudness = state->loudness ? ((5 * 4) << 8) : 0;
 
-	v4l_dbg(1, client, "balance=%d bass=%d treble=%d loudness=%d\n",
+	v4l_dbg(1, msp_debug, client, "balance=%d bass=%d treble=%d loudness=%d\n",
 		state->balance, state->bass, state->treble, state->loudness);
 
 	msp_write_dsp(client, 0x0001, bal << 8);
@@ -341,12 +341,12 @@
 	struct msp_state *state = i2c_get_clientdata(client);
 
 	if (state->radio) {
-		v4l_dbg(1, client, "video mode selected to Radio\n");
+		v4l_dbg(1, msp_debug, client, "video mode selected to Radio\n");
 		return 0x0003;
 	}
 
 	if (state->v4l2_std & V4L2_STD_PAL) {
-		v4l_dbg(1, client, "video mode selected to PAL\n");
+		v4l_dbg(1, msp_debug, client, "video mode selected to PAL\n");
 
 #if 1
 		/* experimental: not sure this works with all chip versions */
@@ -357,11 +357,11 @@
 #endif
 	}
 	if (state->v4l2_std & V4L2_STD_NTSC) {
-		v4l_dbg(1, client, "video mode selected to NTSC\n");
+		v4l_dbg(1, msp_debug, client, "video mode selected to NTSC\n");
 		return 0x2003;
 	}
 	if (state->v4l2_std & V4L2_STD_SECAM) {
-		v4l_dbg(1, client, "video mode selected to SECAM\n");
+		v4l_dbg(1, msp_debug, client, "video mode selected to SECAM\n");
 		return 0x0003;
 	}
 	return 0x0003;
@@ -619,7 +619,7 @@
 	u16 *sarg = arg;
 	int scart = 0;
 
-	if (debug >= 2)
+	if (msp_debug >= 2)
 		v4l_i2c_print_ioctl(client, cmd);
 
 	switch (cmd) {
@@ -666,7 +666,7 @@
 		if (state->radio)
 			return 0;
 		state->radio = 1;
-		v4l_dbg(1, client, "switching to radio mode\n");
+		v4l_dbg(1, msp_debug, client, "switching to radio mode\n");
 		state->watch_stereo = 0;
 		switch (state->opmode) {
 		case OPMODE_MANUAL:
@@ -937,7 +937,7 @@
 		if (a->index < 0 || a->index > 2)
 			return -EINVAL;
 
-		v4l_dbg(1, client, "Setting audio out on msp34xx to input %i\n", a->index);
+		v4l_dbg(1, msp_debug, client, "Setting audio out on msp34xx to input %i\n", a->index);
 		msp_set_scart(client, state->in_scart, a->index + 1);
 
 		break;
@@ -947,7 +947,7 @@
 	{
 		u32 *a = (u32 *)arg;
 
-		v4l_dbg(1, client, "Setting I2S speed to %d\n", *a);
+		v4l_dbg(1, msp_debug, client, "Setting I2S speed to %d\n", *a);
 
 		switch (*a) {
 			case 1024000:
@@ -1041,7 +1041,7 @@
 {
 	struct i2c_client *client = container_of(dev, struct i2c_client, dev);
 
-	v4l_dbg(1, client, "suspend\n");
+	v4l_dbg(1, msp_debug, client, "suspend\n");
 	msp_reset(client);
 	return 0;
 }
@@ -1050,7 +1050,7 @@
 {
 	struct i2c_client *client = container_of(dev, struct i2c_client, dev);
 
-	v4l_dbg(1, client, "resume\n");
+	v4l_dbg(1, msp_debug, client, "resume\n");
 	msp_wake_thread(client);
 	return 0;
 }
@@ -1080,7 +1080,7 @@
 	snprintf(client->name, sizeof(client->name) - 1, "msp3400");
 
 	if (msp_reset(client) == -1) {
-		v4l_dbg(1, client, "msp3400 not found\n");
+		v4l_dbg(1, msp_debug, client, "msp3400 not found\n");
 		kfree(client);
 		return -1;
 	}
@@ -1107,9 +1107,9 @@
 	state->rev1 = msp_read_dsp(client, 0x1e);
 	if (state->rev1 != -1)
 		state->rev2 = msp_read_dsp(client, 0x1f);
-	v4l_dbg(1, client, "rev1=0x%04x, rev2=0x%04x\n", state->rev1, state->rev2);
+	v4l_dbg(1, msp_debug, client, "rev1=0x%04x, rev2=0x%04x\n", state->rev1, state->rev2);
 	if (state->rev1 == -1 || (state->rev1 == 0 && state->rev2 == 0)) {
-		v4l_dbg(1, client, "not an msp3400 (cannot read chip version)\n");
+		v4l_dbg(1, msp_debug, client, "not an msp3400 (cannot read chip version)\n");
 		kfree(state);
 		kfree(client);
 		return -1;
diff --git a/drivers/media/video/msp3400-kthreads.c b/drivers/media/video/msp3400-kthreads.c
index 2b59b68..2072c3e 100644
--- a/drivers/media/video/msp3400-kthreads.c
+++ b/drivers/media/video/msp3400-kthreads.c
@@ -168,7 +168,7 @@
 	struct msp_state *state = i2c_get_clientdata(client);
 	int i;
 
-	v4l_dbg(1, client, "setmode: %d\n", type);
+	v4l_dbg(1, msp_debug, client, "setmode: %d\n", type);
 	state->mode       = type;
 	state->audmode    = V4L2_TUNER_MODE_MONO;
 	state->rxsubchans = V4L2_TUNER_SUB_MONO;
@@ -191,7 +191,7 @@
 
 	msp_write_dem(client, 0x0056, 0); /*LOAD_REG_1/2*/
 
-	if (dolby) {
+	if (msp_dolby) {
 		msp_write_dsp(client, 0x0008, 0x0520); /* I2S1 */
 		msp_write_dsp(client, 0x0009, 0x0620); /* I2S2 */
 		msp_write_dsp(client, 0x000b, msp3400c_init_data[type].dsp_src);
@@ -221,7 +221,7 @@
 		/* this method would break everything, let's make sure
 		 * it's never called
 		 */
-		v4l_dbg(1, client, "setstereo called with mode=%d instead of set_source (ignored)\n",
+		v4l_dbg(1, msp_debug, client, "setstereo called with mode=%d instead of set_source (ignored)\n",
 		     mode);
 		return;
 	}
@@ -229,7 +229,7 @@
 	/* switch demodulator */
 	switch (state->mode) {
 	case MSP_MODE_FM_TERRA:
-		v4l_dbg(1, client, "FM setstereo: %s\n", strmode[mode]);
+		v4l_dbg(1, msp_debug, client, "FM setstereo: %s\n", strmode[mode]);
 		msp3400c_setcarrier(client, state->second, state->main);
 		switch (mode) {
 		case V4L2_TUNER_MODE_STEREO:
@@ -243,7 +243,7 @@
 		}
 		break;
 	case MSP_MODE_FM_SAT:
-		v4l_dbg(1, client, "SAT setstereo: %s\n", strmode[mode]);
+		v4l_dbg(1, msp_debug, client, "SAT setstereo: %s\n", strmode[mode]);
 		switch (mode) {
 		case V4L2_TUNER_MODE_MONO:
 			msp3400c_setcarrier(client, MSP_CARRIER(6.5), MSP_CARRIER(6.5));
@@ -262,24 +262,24 @@
 	case MSP_MODE_FM_NICAM1:
 	case MSP_MODE_FM_NICAM2:
 	case MSP_MODE_AM_NICAM:
-		v4l_dbg(1, client, "NICAM setstereo: %s\n",strmode[mode]);
+		v4l_dbg(1, msp_debug, client, "NICAM setstereo: %s\n",strmode[mode]);
 		msp3400c_setcarrier(client,state->second,state->main);
 		if (state->nicam_on)
 			nicam=0x0100;
 		break;
 	case MSP_MODE_BTSC:
-		v4l_dbg(1, client, "BTSC setstereo: %s\n",strmode[mode]);
+		v4l_dbg(1, msp_debug, client, "BTSC setstereo: %s\n",strmode[mode]);
 		nicam=0x0300;
 		break;
 	case MSP_MODE_EXTERN:
-		v4l_dbg(1, client, "extern setstereo: %s\n",strmode[mode]);
+		v4l_dbg(1, msp_debug, client, "extern setstereo: %s\n",strmode[mode]);
 		nicam = 0x0200;
 		break;
 	case MSP_MODE_FM_RADIO:
-		v4l_dbg(1, client, "FM-Radio setstereo: %s\n",strmode[mode]);
+		v4l_dbg(1, msp_debug, client, "FM-Radio setstereo: %s\n",strmode[mode]);
 		break;
 	default:
-		v4l_dbg(1, client, "mono setstereo\n");
+		v4l_dbg(1, msp_debug, client, "mono setstereo\n");
 		return;
 	}
 
@@ -290,7 +290,7 @@
 		break;
 	case V4L2_TUNER_MODE_MONO:
 		if (state->mode == MSP_MODE_AM_NICAM) {
-			v4l_dbg(1, client, "switching to AM mono\n");
+			v4l_dbg(1, msp_debug, client, "switching to AM mono\n");
 			/* AM mono decoding is handled by tuner, not MSP chip */
 			/* SCART switching control register */
 			msp_set_scart(client, SCART_MONO, 0);
@@ -304,9 +304,9 @@
 		src = 0x0010 | nicam;
 		break;
 	}
-	v4l_dbg(1, client, "setstereo final source/matrix = 0x%x\n", src);
+	v4l_dbg(1, msp_debug, client, "setstereo final source/matrix = 0x%x\n", src);
 
-	if (dolby) {
+	if (msp_dolby) {
 		msp_write_dsp(client, 0x0008, 0x0520);
 		msp_write_dsp(client, 0x0009, 0x0620);
 		msp_write_dsp(client, 0x000a, src);
@@ -327,20 +327,20 @@
 	struct msp_state *state = i2c_get_clientdata(client);
 
 	if (state->main == state->second) {
-		v4l_dbg(1, client, "mono sound carrier: %d.%03d MHz\n",
+		v4l_dbg(1, msp_debug, client, "mono sound carrier: %d.%03d MHz\n",
 		       state->main / 910000, (state->main / 910) % 1000);
 	} else {
-		v4l_dbg(1, client, "main sound carrier: %d.%03d MHz\n",
+		v4l_dbg(1, msp_debug, client, "main sound carrier: %d.%03d MHz\n",
 		       state->main / 910000, (state->main / 910) % 1000);
 	}
 	if (state->mode == MSP_MODE_FM_NICAM1 || state->mode == MSP_MODE_FM_NICAM2)
-		v4l_dbg(1, client, "NICAM/FM carrier  : %d.%03d MHz\n",
+		v4l_dbg(1, msp_debug, client, "NICAM/FM carrier  : %d.%03d MHz\n",
 		       state->second / 910000, (state->second/910) % 1000);
 	if (state->mode == MSP_MODE_AM_NICAM)
-		v4l_dbg(1, client, "NICAM/AM carrier  : %d.%03d MHz\n",
+		v4l_dbg(1, msp_debug, client, "NICAM/AM carrier  : %d.%03d MHz\n",
 		       state->second / 910000, (state->second / 910) % 1000);
 	if (state->mode == MSP_MODE_FM_TERRA && state->main != state->second) {
-		v4l_dbg(1, client, "FM-stereo carrier : %d.%03d MHz\n",
+		v4l_dbg(1, msp_debug, client, "FM-stereo carrier : %d.%03d MHz\n",
 		       state->second / 910000, (state->second / 910) % 1000);
 	}
 }
@@ -360,7 +360,7 @@
 		val = msp_read_dsp(client, 0x18);
 		if (val > 32767)
 			val -= 65536;
-		v4l_dbg(2, client, "stereo detect register: %d\n", val);
+		v4l_dbg(2, msp_debug, client, "stereo detect register: %d\n", val);
 		if (val > 4096) {
 			rxsubchans = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_MONO;
 		} else if (val < -4096) {
@@ -374,7 +374,7 @@
 	case MSP_MODE_FM_NICAM2:
 	case MSP_MODE_AM_NICAM:
 		val = msp_read_dem(client, 0x23);
-		v4l_dbg(2, client, "nicam sync=%d, mode=%d\n",
+		v4l_dbg(2, msp_debug, client, "nicam sync=%d, mode=%d\n",
 			val & 1, (val & 0x1e) >> 1);
 
 		if (val & 1) {
@@ -407,7 +407,7 @@
 		break;
 	case MSP_MODE_BTSC:
 		val = msp_read_dem(client, 0x200);
-		v4l_dbg(2, client, "status=0x%x (pri=%s, sec=%s, %s%s%s)\n",
+		v4l_dbg(2, msp_debug, client, "status=0x%x (pri=%s, sec=%s, %s%s%s)\n",
 			val,
 			(val & 0x0002) ? "no"     : "yes",
 			(val & 0x0004) ? "no"     : "yes",
@@ -421,13 +421,13 @@
 	}
 	if (rxsubchans != state->rxsubchans) {
 		update = 1;
-		v4l_dbg(1, client, "watch: rxsubchans %d => %d\n",
+		v4l_dbg(1, msp_debug, client, "watch: rxsubchans %d => %d\n",
 			state->rxsubchans,rxsubchans);
 		state->rxsubchans = rxsubchans;
 	}
 	if (newnicam != state->nicam_on) {
 		update = 1;
-		v4l_dbg(1, client, "watch: nicam %d => %d\n",
+		v4l_dbg(1, msp_debug, client, "watch: nicam %d => %d\n",
 			state->nicam_on,newnicam);
 		state->nicam_on = newnicam;
 	}
@@ -452,7 +452,7 @@
 			msp3400c_setstereo(client, V4L2_TUNER_MODE_MONO);
 	}
 
-	if (once)
+	if (msp_once)
 		state->watch_stereo = 0;
 }
 
@@ -464,21 +464,21 @@
 	int count, max1,max2,val1,val2, val,this;
 
 
-	v4l_dbg(1, client, "msp3400 daemon started\n");
+	v4l_dbg(1, msp_debug, client, "msp3400 daemon started\n");
 	for (;;) {
-		v4l_dbg(2, client, "msp3400 thread: sleep\n");
+		v4l_dbg(2, msp_debug, client, "msp3400 thread: sleep\n");
 		msp_sleep(state, -1);
-		v4l_dbg(2, client, "msp3400 thread: wakeup\n");
+		v4l_dbg(2, msp_debug, client, "msp3400 thread: wakeup\n");
 
 	restart:
-		v4l_dbg(1, client, "thread: restart scan\n");
+		v4l_dbg(1, msp_debug, client, "thread: restart scan\n");
 		state->restart = 0;
 		if (kthread_should_stop())
 			break;
 
 		if (state->radio || MSP_MODE_EXTERN == state->mode) {
 			/* no carrier scan, just unmute */
-			v4l_dbg(1, client, "thread: no carrier scan\n");
+			v4l_dbg(1, msp_debug, client, "thread: no carrier scan\n");
 			msp_set_audio(client);
 			continue;
 		}
@@ -498,11 +498,11 @@
 		cd = msp3400c_carrier_detect_main;
 		count = ARRAY_SIZE(msp3400c_carrier_detect_main);
 
-		if (amsound && (state->v4l2_std & V4L2_STD_SECAM)) {
+		if (msp_amsound && (state->v4l2_std & V4L2_STD_SECAM)) {
 			/* autodetect doesn't work well with AM ... */
 			max1 = 3;
 			count = 0;
-			v4l_dbg(1, client, "AM sound override\n");
+			v4l_dbg(1, msp_debug, client, "AM sound override\n");
 		}
 
 		for (this = 0; this < count; this++) {
@@ -514,7 +514,7 @@
 				val -= 65536;
 			if (val1 < val)
 				val1 = val, max1 = this;
-			v4l_dbg(1, client, "carrier1 val: %5d / %s\n", val,cd[this].name);
+			v4l_dbg(1, msp_debug, client, "carrier1 val: %5d / %s\n", val,cd[this].name);
 		}
 
 		/* carrier detect pass #2 -- second (stereo) carrier */
@@ -535,7 +535,7 @@
 			break;
 		}
 
-		if (amsound && (state->v4l2_std & V4L2_STD_SECAM)) {
+		if (msp_amsound && (state->v4l2_std & V4L2_STD_SECAM)) {
 			/* autodetect doesn't work well with AM ... */
 			cd = NULL;
 			count = 0;
@@ -550,7 +550,7 @@
 				val -= 65536;
 			if (val2 < val)
 				val2 = val, max2 = this;
-			v4l_dbg(1, client, "carrier2 val: %5d / %s\n", val,cd[this].name);
+			v4l_dbg(1, msp_debug, client, "carrier2 val: %5d / %s\n", val,cd[this].name);
 		}
 
 		/* program the msp3400 according to the results */
@@ -627,7 +627,7 @@
 		/* unmute */
 		msp_set_audio(client);
 
-		if (debug)
+		if (msp_debug)
 			msp3400c_print_mode(client);
 
 		/* monitor tv audio mode */
@@ -637,7 +637,7 @@
 			watch_stereo(client);
 		}
 	}
-	v4l_dbg(1, client, "thread: exit\n");
+	v4l_dbg(1, msp_debug, client, "thread: exit\n");
 	return 0;
 }
 
@@ -648,22 +648,22 @@
 	struct msp_state *state = i2c_get_clientdata(client);
 	int val, i, std;
 
-	v4l_dbg(1, client, "msp3410 daemon started\n");
+	v4l_dbg(1, msp_debug, client, "msp3410 daemon started\n");
 
 	for (;;) {
-		v4l_dbg(2, client, "msp3410 thread: sleep\n");
+		v4l_dbg(2, msp_debug, client, "msp3410 thread: sleep\n");
 		msp_sleep(state,-1);
-		v4l_dbg(2, client, "msp3410 thread: wakeup\n");
+		v4l_dbg(2, msp_debug, client, "msp3410 thread: wakeup\n");
 
 	restart:
-		v4l_dbg(1, client, "thread: restart scan\n");
+		v4l_dbg(1, msp_debug, client, "thread: restart scan\n");
 		state->restart = 0;
 		if (kthread_should_stop())
 			break;
 
 		if (state->mode == MSP_MODE_EXTERN) {
 			/* no carrier scan needed, just unmute */
-			v4l_dbg(1, client, "thread: no carrier scan\n");
+			v4l_dbg(1, msp_debug, client, "thread: no carrier scan\n");
 			msp_set_audio(client);
 			continue;
 		}
@@ -682,8 +682,8 @@
 			std = (state->v4l2_std & V4L2_STD_NTSC) ? 0x20 : 1;
 		state->watch_stereo = 0;
 
-		if (debug)
-			v4l_dbg(1, client, "setting standard: %s (0x%04x)\n",
+		if (msp_debug)
+			v4l_dbg(1, msp_debug, client, "setting standard: %s (0x%04x)\n",
 			       msp_standard_std_name(std), std);
 
 		if (std != 1) {
@@ -700,22 +700,22 @@
 				val = msp_read_dem(client, 0x7e);
 				if (val < 0x07ff)
 					break;
-				v4l_dbg(1, client, "detection still in progress\n");
+				v4l_dbg(1, msp_debug, client, "detection still in progress\n");
 			}
 		}
 		for (i = 0; msp_stdlist[i].name != NULL; i++)
 			if (msp_stdlist[i].retval == val)
 				break;
-		v4l_dbg(1, client, "current standard: %s (0x%04x)\n",
+		v4l_dbg(1, msp_debug, client, "current standard: %s (0x%04x)\n",
 			msp_standard_std_name(val), val);
 		state->main   = msp_stdlist[i].main;
 		state->second = msp_stdlist[i].second;
 		state->std = val;
 
-		if (amsound && !state->radio && (state->v4l2_std & V4L2_STD_SECAM) &&
+		if (msp_amsound && !state->radio && (state->v4l2_std & V4L2_STD_SECAM) &&
 				(val != 0x0009)) {
 			/* autodetection has failed, let backup */
-			v4l_dbg(1, client, "autodetection failed,"
+			v4l_dbg(1, msp_debug, client, "autodetection failed,"
 				" switching to backup standard: %s (0x%04x)\n",
 				msp_stdlist[8].name ? msp_stdlist[8].name : "unknown",val);
 			val = 0x0009;
@@ -798,13 +798,13 @@
 			watch_stereo(client);
 		}
 	}
-	v4l_dbg(1, client, "thread: exit\n");
+	v4l_dbg(1, msp_debug, client, "thread: exit\n");
 	return 0;
 }
 
 /* ----------------------------------------------------------------------- */
 
-/* msp34xxG + (autoselect no-thread)                                          */
+/* msp34xxG + (autoselect no-thread)                                       */
 /* this one uses both automatic standard detection and automatic sound     */
 /* select which are available in the newer G versions                      */
 /* struct msp: only norm, acb and source are really used in this mode      */
@@ -825,7 +825,7 @@
 	 */
 	int value = (source & 0x07) << 8 | (source == 0 ? 0x30 : 0x20);
 
-	v4l_dbg(1, client, "set source to %d (0x%x)\n", source, value);
+	v4l_dbg(1, msp_debug, client, "set source to %d (0x%x)\n", source, value);
 	/* Loudspeaker Output */
 	msp_write_dsp(client, 0x08, value);
 	/* SCART1 DA Output */
@@ -840,7 +840,7 @@
 	 * 0x7f0 = forced mono mode
 	 */
 	/* a2 threshold for stereo/bilingual */
-	msp_write_dem(client, 0x22, stereo_threshold);
+	msp_write_dem(client, 0x22, msp_stereo_thresh);
 	state->source = source;
 }
 
@@ -897,28 +897,28 @@
 	struct msp_state *state = i2c_get_clientdata(client);
 	int val, std, i;
 
-	v4l_dbg(1, client, "msp34xxg daemon started\n");
+	v4l_dbg(1, msp_debug, client, "msp34xxg daemon started\n");
 
 	state->source = 1; /* default */
 	for (;;) {
-		v4l_dbg(2, client, "msp34xxg thread: sleep\n");
+		v4l_dbg(2, msp_debug, client, "msp34xxg thread: sleep\n");
 		msp_sleep(state, -1);
-		v4l_dbg(2, client, "msp34xxg thread: wakeup\n");
+		v4l_dbg(2, msp_debug, client, "msp34xxg thread: wakeup\n");
 
 	restart:
-		v4l_dbg(1, client, "thread: restart scan\n");
+		v4l_dbg(1, msp_debug, client, "thread: restart scan\n");
 		state->restart = 0;
 		if (kthread_should_stop())
 			break;
 
 		/* setup the chip*/
 		msp34xxg_reset(client);
-		std = standard;
+		std = msp_standard;
 		if (std != 0x01)
 			goto unmute;
 
 		/* watch autodetect */
-		v4l_dbg(1, client, "triggered autodetect, waiting for result\n");
+		v4l_dbg(1, msp_debug, client, "triggered autodetect, waiting for result\n");
 		for (i = 0; i < 10; i++) {
 			if (msp_sleep(state, 100))
 				goto restart;
@@ -929,16 +929,16 @@
 				std = val;
 				break;
 			}
-			v4l_dbg(2, client, "detection still in progress\n");
+			v4l_dbg(2, msp_debug, client, "detection still in progress\n");
 		}
 		if (std == 1) {
-			v4l_dbg(1, client, "detection still in progress after 10 tries. giving up.\n");
+			v4l_dbg(1, msp_debug, client, "detection still in progress after 10 tries. giving up.\n");
 			continue;
 		}
 
 	unmute:
 		state->std = std;
-		v4l_dbg(1, client, "current standard: %s (0x%04x)\n",
+		v4l_dbg(1, msp_debug, client, "current standard: %s (0x%04x)\n",
 			msp_standard_std_name(std), std);
 
 		/* unmute: dispatch sound to scart output, set scart volume */
@@ -950,7 +950,7 @@
 
 		msp_write_dem(client, 0x40, state->i2s_mode);
 	}
-	v4l_dbg(1, client, "thread: exit\n");
+	v4l_dbg(1, msp_debug, client, "thread: exit\n");
 	return 0;
 }
 
@@ -976,7 +976,7 @@
 		 * this is a problem, I'll handle SAP just like lang1/lang2.
 		 */
 	}
-	v4l_dbg(1, client, "status=0x%x, stereo=%d, bilingual=%d -> rxsubchans=%d\n",
+	v4l_dbg(1, msp_debug, client, "status=0x%x, stereo=%d, bilingual=%d -> rxsubchans=%d\n",
 		status, is_stereo, is_bilingual, state->rxsubchans);
 }
 
diff --git a/drivers/media/video/msp3400.h b/drivers/media/video/msp3400.h
index 8a05cf5..70a5ef8 100644
--- a/drivers/media/video/msp3400.h
+++ b/drivers/media/video/msp3400.h
@@ -48,12 +48,12 @@
 #define OPMODE_AUTOSELECT  2   /* use autodetect & autoselect (>= msp34xxG)   */
 
 /* module parameters */
-extern int debug;
-extern int once;
-extern int amsound;
-extern int standard;
-extern int dolby;
-extern int stereo_threshold;
+extern int msp_debug;
+extern int msp_once;
+extern int msp_amsound;
+extern int msp_standard;
+extern int msp_dolby;
+extern int msp_stereo_thresh;
 
 struct msp_state {
 	int rev1, rev2;
diff --git a/drivers/media/video/mt20xx.c b/drivers/media/video/mt20xx.c
index 2c19c95..0bf1caa 100644
--- a/drivers/media/video/mt20xx.c
+++ b/drivers/media/video/mt20xx.c
@@ -21,7 +21,7 @@
 module_param(radio_antenna,     int, 0644);
 
 /* from tuner-core.c */
-extern int debug;
+extern int tuner_debug;
 
 /* ---------------------------------------------------------------------- */
 
@@ -404,7 +404,7 @@
 	div2a=(lo2/8)-1;
 	div2b=lo2-(div2a+1)*8;
 
-	if (debug > 1) {
+	if (tuner_debug > 1) {
 		tuner_dbg("lo1 lo2 = %d %d\n", lo1, lo2);
 		tuner_dbg("num1 num2 div1a div1b div2a div2b= %x %x %x %x %x %x\n",
 			  num1,num2,div1a,div1b,div2a,div2b);
@@ -420,7 +420,7 @@
 	buf[5]=div2a;
 	if(num2!=0) buf[5]=buf[5]|0x40;
 
-	if (debug > 1) {
+	if (tuner_debug > 1) {
 		int i;
 		tuner_dbg("bufs is: ");
 		for(i=0;i<6;i++)
@@ -508,7 +508,7 @@
 
 	i2c_master_send(c,buf,1);
 	i2c_master_recv(c,buf,21);
-	if (debug) {
+	if (tuner_debug) {
 		int i;
 		tuner_dbg("MT20xx hexdump:");
 		for(i=0;i<21;i++) {
diff --git a/drivers/media/video/mxb.c b/drivers/media/video/mxb.c
index 91681aa..8416cef 100644
--- a/drivers/media/video/mxb.c
+++ b/drivers/media/video/mxb.c
@@ -177,12 +177,11 @@
 		return -ENODEV;
 	}
 
-	mxb = (struct mxb*)kmalloc(sizeof(struct mxb), GFP_KERNEL);
+	mxb = kzalloc(sizeof(struct mxb), GFP_KERNEL);
 	if( NULL == mxb ) {
 		DEB_D(("not enough kernel memory.\n"));
 		return -ENOMEM;
 	}
-	memset(mxb, 0x0, sizeof(struct mxb));	
 
 	mxb->i2c_adapter = (struct i2c_adapter) {
 		.class = I2C_CLASS_TV_ANALOG,
diff --git a/drivers/media/video/ovcamchip/ov6x20.c b/drivers/media/video/ovcamchip/ov6x20.c
index b3f4d26..c04130d 100644
--- a/drivers/media/video/ovcamchip/ov6x20.c
+++ b/drivers/media/video/ovcamchip/ov6x20.c
@@ -178,10 +178,9 @@
 	if (rc < 0)
 		return rc;
 
-	ov->spriv = s = kmalloc(sizeof *s, GFP_KERNEL);
+	ov->spriv = s = kzalloc(sizeof *s, GFP_KERNEL);
 	if (!s)
 		return -ENOMEM;
-	memset(s, 0, sizeof *s);
 
 	s->auto_brt = 1;
 	s->auto_exp = 1;
diff --git a/drivers/media/video/ovcamchip/ov6x30.c b/drivers/media/video/ovcamchip/ov6x30.c
index 6eab458..73b94f51 100644
--- a/drivers/media/video/ovcamchip/ov6x30.c
+++ b/drivers/media/video/ovcamchip/ov6x30.c
@@ -141,10 +141,9 @@
 	if (rc < 0)
 		return rc;
 
-	ov->spriv = s = kmalloc(sizeof *s, GFP_KERNEL);
+	ov->spriv = s = kzalloc(sizeof *s, GFP_KERNEL);
 	if (!s)
 		return -ENOMEM;
-	memset(s, 0, sizeof *s);
 
 	s->auto_brt = 1;
 	s->auto_exp = 1;
diff --git a/drivers/media/video/ovcamchip/ov76be.c b/drivers/media/video/ovcamchip/ov76be.c
index 29bbdc0..11f6be9 100644
--- a/drivers/media/video/ovcamchip/ov76be.c
+++ b/drivers/media/video/ovcamchip/ov76be.c
@@ -105,10 +105,9 @@
 	if (rc < 0)
 		return rc;
 
-	ov->spriv = s = kmalloc(sizeof *s, GFP_KERNEL);
+	ov->spriv = s = kzalloc(sizeof *s, GFP_KERNEL);
 	if (!s)
 		return -ENOMEM;
-	memset(s, 0, sizeof *s);
 
 	s->auto_brt = 1;
 	s->auto_exp = 1;
diff --git a/drivers/media/video/ovcamchip/ov7x10.c b/drivers/media/video/ovcamchip/ov7x10.c
index 6c383d4..5206e79 100644
--- a/drivers/media/video/ovcamchip/ov7x10.c
+++ b/drivers/media/video/ovcamchip/ov7x10.c
@@ -115,10 +115,9 @@
 	if (rc < 0)
 		return rc;
 
-	ov->spriv = s = kmalloc(sizeof *s, GFP_KERNEL);
+	ov->spriv = s = kzalloc(sizeof *s, GFP_KERNEL);
 	if (!s)
 		return -ENOMEM;
-	memset(s, 0, sizeof *s);
 
 	s->auto_brt = 1;
 	s->auto_exp = 1;
diff --git a/drivers/media/video/ovcamchip/ov7x20.c b/drivers/media/video/ovcamchip/ov7x20.c
index 3c8c48f..8e26ae3 100644
--- a/drivers/media/video/ovcamchip/ov7x20.c
+++ b/drivers/media/video/ovcamchip/ov7x20.c
@@ -232,10 +232,9 @@
 	if (rc < 0)
 		return rc;
 
-	ov->spriv = s = kmalloc(sizeof *s, GFP_KERNEL);
+	ov->spriv = s = kzalloc(sizeof *s, GFP_KERNEL);
 	if (!s)
 		return -ENOMEM;
-	memset(s, 0, sizeof *s);
 
 	s->auto_brt = 1;
 	s->auto_exp = DFL_AUTO_EXP;
diff --git a/drivers/media/video/ovcamchip/ovcamchip_core.c b/drivers/media/video/ovcamchip/ovcamchip_core.c
index 428f1bb..e76b53d 100644
--- a/drivers/media/video/ovcamchip/ovcamchip_core.c
+++ b/drivers/media/video/ovcamchip/ovcamchip_core.c
@@ -316,12 +316,11 @@
 	c->adapter = adap;
 	strcpy(c->name, "OV????");
 
-	ov = kmalloc(sizeof *ov, GFP_KERNEL);
+	ov = kzalloc(sizeof *ov, GFP_KERNEL);
 	if (!ov) {
 		rc = -ENOMEM;
 		goto no_ov;
 	}
-	memset(ov, 0, sizeof *ov);
 	i2c_set_clientdata(c, ov);
 
 	rc = ovcamchip_detect(c);
diff --git a/drivers/media/video/saa5246a.c b/drivers/media/video/saa5246a.c
index 0aa9e72..2ce0102 100644
--- a/drivers/media/video/saa5246a.c
+++ b/drivers/media/video/saa5246a.c
@@ -83,13 +83,12 @@
 	client_template.adapter = adap;
 	client_template.addr = addr;
 	memcpy(client, &client_template, sizeof(*client));
-	t = kmalloc(sizeof(*t), GFP_KERNEL);
+	t = kzalloc(sizeof(*t), GFP_KERNEL);
 	if(t==NULL)
 	{
 		kfree(client);
 		return -ENOMEM;
 	}
-	memset(t, 0, sizeof(*t));
 	strlcpy(client->name, IF_NAME, I2C_NAME_SIZE);
 	init_MUTEX(&t->lock);
 
diff --git a/drivers/media/video/saa5249.c b/drivers/media/video/saa5249.c
index 73b4f0e..5694eb5 100644
--- a/drivers/media/video/saa5249.c
+++ b/drivers/media/video/saa5249.c
@@ -151,13 +151,12 @@
         client_template.adapter = adap;
         client_template.addr = addr;
 	memcpy(client, &client_template, sizeof(*client));
-	t = kmalloc(sizeof(*t), GFP_KERNEL);
+	t = kzalloc(sizeof(*t), GFP_KERNEL);
 	if(t==NULL)
 	{
 		kfree(client);
 		return -ENOMEM;
 	}
-	memset(t, 0, sizeof(*t));
 	strlcpy(client->name, IF_NAME, I2C_NAME_SIZE);
 	init_MUTEX(&t->lock);
 	
@@ -165,7 +164,7 @@
 	 *	Now create a video4linux device
 	 */
 	 
-	vd = (struct video_device *)kmalloc(sizeof(struct video_device), GFP_KERNEL);
+	vd = kmalloc(sizeof(struct video_device), GFP_KERNEL);
 	if(vd==NULL)
 	{
 		kfree(t);
diff --git a/drivers/media/video/saa7110.c b/drivers/media/video/saa7110.c
index 619ff0b..7bb85a7 100644
--- a/drivers/media/video/saa7110.c
+++ b/drivers/media/video/saa7110.c
@@ -494,21 +494,19 @@
 	     I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
 		return 0;
 
-	client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
+	client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
 	if (client == 0)
 		return -ENOMEM;
-	memset(client, 0, sizeof(struct i2c_client));
 	client->addr = address;
 	client->adapter = adapter;
 	client->driver = &i2c_driver_saa7110;
 	strlcpy(I2C_NAME(client), "saa7110", sizeof(I2C_NAME(client)));
 
-	decoder = kmalloc(sizeof(struct saa7110), GFP_KERNEL);
+	decoder = kzalloc(sizeof(struct saa7110), GFP_KERNEL);
 	if (decoder == 0) {
 		kfree(client);
 		return -ENOMEM;
 	}
-	memset(decoder, 0, sizeof(struct saa7110));
 	decoder->norm = VIDEO_MODE_PAL;
 	decoder->input = 0;
 	decoder->enable = 1;
diff --git a/drivers/media/video/saa7111.c b/drivers/media/video/saa7111.c
index acaeee5..8c06592 100644
--- a/drivers/media/video/saa7111.c
+++ b/drivers/media/video/saa7111.c
@@ -511,21 +511,19 @@
 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
 		return 0;
 
-	client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
+	client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
 	if (client == 0)
 		return -ENOMEM;
-	memset(client, 0, sizeof(struct i2c_client));
 	client->addr = address;
 	client->adapter = adapter;
 	client->driver = &i2c_driver_saa7111;
 	strlcpy(I2C_NAME(client), "saa7111", sizeof(I2C_NAME(client)));
 
-	decoder = kmalloc(sizeof(struct saa7111), GFP_KERNEL);
+	decoder = kzalloc(sizeof(struct saa7111), GFP_KERNEL);
 	if (decoder == NULL) {
 		kfree(client);
 		return -ENOMEM;
 	}
-	memset(decoder, 0, sizeof(struct saa7111));
 	decoder->norm = VIDEO_MODE_NTSC;
 	decoder->input = 0;
 	decoder->enable = 1;
diff --git a/drivers/media/video/saa7114.c b/drivers/media/video/saa7114.c
index b7ac012..fd0a4b4 100644
--- a/drivers/media/video/saa7114.c
+++ b/drivers/media/video/saa7114.c
@@ -852,21 +852,19 @@
 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
 		return 0;
 
-	client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
+	client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
 	if (client == 0)
 		return -ENOMEM;
-	memset(client, 0, sizeof(struct i2c_client));
 	client->addr = address;
 	client->adapter = adapter;
 	client->driver = &i2c_driver_saa7114;
 	strlcpy(I2C_NAME(client), "saa7114", sizeof(I2C_NAME(client)));
 
-	decoder = kmalloc(sizeof(struct saa7114), GFP_KERNEL);
+	decoder = kzalloc(sizeof(struct saa7114), GFP_KERNEL);
 	if (decoder == NULL) {
 		kfree(client);
 		return -ENOMEM;
 	}
-	memset(decoder, 0, sizeof(struct saa7114));
 	decoder->norm = VIDEO_MODE_NTSC;
 	decoder->input = -1;
 	decoder->enable = 1;
diff --git a/drivers/media/video/saa7115.c b/drivers/media/video/saa7115.c
index 4a4bc69..048d000 100644
--- a/drivers/media/video/saa7115.c
+++ b/drivers/media/video/saa7115.c
@@ -549,7 +549,7 @@
 	u32 hz;
 	u64 f;
 
-	v4l_dbg(1, client, "set audio clock freq: %d\n", freq);
+	v4l_dbg(1, debug, client, "set audio clock freq: %d\n", freq);
 
 	/* sanity check */
 	if (freq < 32000 || freq > 48000)
@@ -670,10 +670,10 @@
 
 	// This works for NTSC-M, SECAM-L and the 50Hz PAL variants.
 	if (std & V4L2_STD_525_60) {
-		v4l_dbg(1, client, "decoder set standard 60 Hz\n");
+		v4l_dbg(1, debug, client, "decoder set standard 60 Hz\n");
 		saa7115_writeregs(client, saa7115_cfg_60hz_video);
 	} else {
-		v4l_dbg(1, client, "decoder set standard 50 Hz\n");
+		v4l_dbg(1, debug, client, "decoder set standard 50 Hz\n");
 		saa7115_writeregs(client, saa7115_cfg_50hz_video);
 	}
 
@@ -863,7 +863,7 @@
 
 	pix = &(fmt->fmt.pix);
 
-	v4l_dbg(1, client, "decoder set size\n");
+	v4l_dbg(1, debug, client, "decoder set size\n");
 
 	/* FIXME need better bounds checking here */
 	if ((pix->width < 1) || (pix->width > 1440))
@@ -889,7 +889,7 @@
 		HPSC = HPSC ? HPSC : 1;
 		HFSC = (int)((1024 * 720) / (HPSC * pix->width));
 
-		v4l_dbg(1, client, "Hpsc: 0x%05x, Hfsc: 0x%05x\n", HPSC, HFSC);
+		v4l_dbg(1, debug, client, "Hpsc: 0x%05x, Hfsc: 0x%05x\n", HPSC, HFSC);
 		/* FIXME hardcodes to "Task B"
 		 * write H prescaler integer */
 		saa7115_write(client, 0xd0, (u8) (HPSC & 0x3f));
@@ -903,10 +903,10 @@
 		saa7115_write(client, 0xDD, (u8) ((HFSC >> 9) & 0xff));
 	} else {
 		if (is_50hz) {
-			v4l_dbg(1, client, "Setting full 50hz width\n");
+			v4l_dbg(1, debug, client, "Setting full 50hz width\n");
 			saa7115_writeregs(client, saa7115_cfg_50hz_fullres_x);
 		} else {
-			v4l_dbg(1, client, "Setting full 60hz width\n");
+			v4l_dbg(1, debug, client, "Setting full 60hz width\n");
 			saa7115_writeregs(client, saa7115_cfg_60hz_fullres_x);
 		}
 	}
@@ -915,7 +915,7 @@
 
 	if (pix->height != Vsrc) {
 		VSCY = (int)((1024 * Vsrc) / pix->height);
-		v4l_dbg(1, client, "Vsrc: %d, Vscy: 0x%05x\n", Vsrc, VSCY);
+		v4l_dbg(1, debug, client, "Vsrc: %d, Vscy: 0x%05x\n", Vsrc, VSCY);
 
 		/* Correct Contrast and Luminance */
 		saa7115_write(client, 0xd5, (u8) (64 * 1024 / VSCY));
@@ -929,10 +929,10 @@
 		saa7115_write(client, 0xe3, (u8) ((VSCY >> 8) & 0xff));
 	} else {
 		if (is_50hz) {
-			v4l_dbg(1, client, "Setting full 50Hz height\n");
+			v4l_dbg(1, debug, client, "Setting full 50Hz height\n");
 			saa7115_writeregs(client, saa7115_cfg_50hz_fullres_y);
 		} else {
-			v4l_dbg(1, client, "Setting full 60hz height\n");
+			v4l_dbg(1, debug, client, "Setting full 60hz height\n");
 			saa7115_writeregs(client, saa7115_cfg_60hz_fullres_y);
 		}
 	}
@@ -1079,7 +1079,7 @@
 			break;
 		status = saa7115_read(client, 0x1f);
 
-		v4l_dbg(1, client, "status: 0x%02x\n", status);
+		v4l_dbg(1, debug, client, "status: 0x%02x\n", status);
 		vt->signal = ((status & (1 << 6)) == 0) ? 0xffff : 0x0;
 		break;
 	}
@@ -1125,7 +1125,7 @@
 		break;
 
 	case VIDIOC_S_INPUT:
-		v4l_dbg(1, client, "decoder set input %d\n", *iarg);
+		v4l_dbg(1, debug, client, "decoder set input %d\n", *iarg);
 		/* inputs from 0-9 are available */
 		if (*iarg < 0 || *iarg > 9) {
 			return -EINVAL;
@@ -1133,7 +1133,7 @@
 
 		if (state->input == *iarg)
 			break;
-		v4l_dbg(1, client, "now setting %s input\n",
+		v4l_dbg(1, debug, client, "now setting %s input\n",
 			*iarg >= 6 ? "S-Video" : "Composite");
 		state->input = *iarg;
 
@@ -1150,7 +1150,7 @@
 
 	case VIDIOC_STREAMON:
 	case VIDIOC_STREAMOFF:
-		v4l_dbg(1, client, "%s output\n",
+		v4l_dbg(1, debug, client, "%s output\n",
 			(cmd == VIDIOC_STREAMON) ? "enable" : "disable");
 
 		if (state->enable != (cmd == VIDIOC_STREAMON)) {
@@ -1164,7 +1164,7 @@
 		break;
 
 	case VIDIOC_INT_RESET:
-		v4l_dbg(1, client, "decoder RESET\n");
+		v4l_dbg(1, debug, client, "decoder RESET\n");
 		saa7115_writeregs(client, saa7115_cfg_reset_scaler);
 		break;
 
@@ -1249,21 +1249,20 @@
 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
 		return 0;
 
-	client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
+	client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
 	if (client == 0)
 		return -ENOMEM;
-	memset(client, 0, sizeof(struct i2c_client));
 	client->addr = address;
 	client->adapter = adapter;
 	client->driver = &i2c_driver_saa7115;
 	snprintf(client->name, sizeof(client->name) - 1, "saa7115");
 
-	v4l_dbg(1, client, "detecting saa7115 client on address 0x%x\n", address << 1);
+	v4l_dbg(1, debug, client, "detecting saa7115 client on address 0x%x\n", address << 1);
 
 	saa7115_write(client, 0, 5);
 	chip_id = saa7115_read(client, 0) & 0x0f;
 	if (chip_id != 4 && chip_id != 5) {
-		v4l_dbg(1, client, "saa7115 not found\n");
+		v4l_dbg(1, debug, client, "saa7115 not found\n");
 		kfree(client);
 		return 0;
 	}
@@ -1272,13 +1271,12 @@
 	}
 	v4l_info(client, "saa711%d found @ 0x%x (%s)\n", chip_id, address << 1, adapter->name);
 
-	state = kmalloc(sizeof(struct saa7115_state), GFP_KERNEL);
+	state = kzalloc(sizeof(struct saa7115_state), GFP_KERNEL);
 	i2c_set_clientdata(client, state);
 	if (state == NULL) {
 		kfree(client);
 		return -ENOMEM;
 	}
-	memset(state, 0, sizeof(struct saa7115_state));
 	state->std = V4L2_STD_NTSC;
 	state->input = -1;
 	state->enable = 1;
@@ -1290,7 +1288,7 @@
 	state->ident = (chip_id == 4) ? V4L2_IDENT_SAA7114 : V4L2_IDENT_SAA7115;
 	state->audclk_freq = 48000;
 
-	v4l_dbg(1, client, "writing init values\n");
+	v4l_dbg(1, debug, client, "writing init values\n");
 
 	/* init to 60hz/48khz */
 	saa7115_writeregs(client, saa7115_init_auto_input);
@@ -1303,7 +1301,7 @@
 
 	i2c_attach_client(client);
 
-	v4l_dbg(1, client, "status: (1E) 0x%02x, (1F) 0x%02x\n",
+	v4l_dbg(1, debug, client, "status: (1E) 0x%02x, (1F) 0x%02x\n",
 		saa7115_read(client, 0x1e), saa7115_read(client, 0x1f));
 
 	return 0;
diff --git a/drivers/media/video/saa711x.c b/drivers/media/video/saa711x.c
index f39a7be..ae53063 100644
--- a/drivers/media/video/saa711x.c
+++ b/drivers/media/video/saa711x.c
@@ -487,20 +487,18 @@
 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
 		return 0;
 
-	client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
+	client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
 	if (client == 0)
 		return -ENOMEM;
-	memset(client, 0, sizeof(struct i2c_client));
 	client->addr = address;
 	client->adapter = adapter;
 	client->driver = &i2c_driver_saa711x;
 	strlcpy(I2C_NAME(client), "saa711x", sizeof(I2C_NAME(client)));
-	decoder = kmalloc(sizeof(struct saa711x), GFP_KERNEL);
+	decoder = kzalloc(sizeof(struct saa711x), GFP_KERNEL);
 	if (decoder == NULL) {
 		kfree(client);
 		return -ENOMEM;
 	}
-	memset(decoder, 0, sizeof(struct saa711x));
 	decoder->norm = VIDEO_MODE_NTSC;
 	decoder->input = 0;
 	decoder->enable = 1;
diff --git a/drivers/media/video/saa7127.c b/drivers/media/video/saa7127.c
index 2009c1b..992c717 100644
--- a/drivers/media/video/saa7127.c
+++ b/drivers/media/video/saa7127.c
@@ -338,7 +338,7 @@
 	if (enable && (data->field != 0 || data->line != 16))
 		return -EINVAL;
 	if (state->vps_enable != enable) {
-		v4l_dbg(1, client, "Turn VPS Signal %s\n", enable ? "on" : "off");
+		v4l_dbg(1, debug, client, "Turn VPS Signal %s\n", enable ? "on" : "off");
 		saa7127_write(client, 0x54, enable << 7);
 		state->vps_enable = enable;
 	}
@@ -350,7 +350,7 @@
 	state->vps_data[2] = data->data[11];
 	state->vps_data[3] = data->data[12];
 	state->vps_data[4] = data->data[13];
-	v4l_dbg(1, client, "Set VPS data %02x %02x %02x %02x %02x\n",
+	v4l_dbg(1, debug, client, "Set VPS data %02x %02x %02x %02x %02x\n",
 		state->vps_data[0], state->vps_data[1],
 		state->vps_data[2], state->vps_data[3],
 		state->vps_data[4]);
@@ -373,7 +373,7 @@
 	if (enable && (data->field != 0 || data->line != 21))
 		return -EINVAL;
 	if (state->cc_enable != enable) {
-		v4l_dbg(1, client, "Turn CC %s\n", enable ? "on" : "off");
+		v4l_dbg(1, debug, client, "Turn CC %s\n", enable ? "on" : "off");
 		saa7127_write(client, SAA7127_REG_CLOSED_CAPTION,
 				(state->xds_enable << 7) | (enable << 6) | 0x11);
 		state->cc_enable = enable;
@@ -381,7 +381,7 @@
 	if (!enable)
 		return 0;
 
-	v4l_dbg(2, client, "CC data: %04x\n", cc);
+	v4l_dbg(2, debug, client, "CC data: %04x\n", cc);
 	saa7127_write(client, SAA7127_REG_LINE_21_ODD_0, cc & 0xff);
 	saa7127_write(client, SAA7127_REG_LINE_21_ODD_1, cc >> 8);
 	state->cc_data = cc;
@@ -399,7 +399,7 @@
 	if (enable && (data->field != 1 || data->line != 21))
 		return -EINVAL;
 	if (state->xds_enable != enable) {
-		v4l_dbg(1, client, "Turn XDS %s\n", enable ? "on" : "off");
+		v4l_dbg(1, debug, client, "Turn XDS %s\n", enable ? "on" : "off");
 		saa7127_write(client, SAA7127_REG_CLOSED_CAPTION,
 				(enable << 7) | (state->cc_enable << 6) | 0x11);
 		state->xds_enable = enable;
@@ -407,7 +407,7 @@
 	if (!enable)
 		return 0;
 
-	v4l_dbg(2, client, "XDS data: %04x\n", xds);
+	v4l_dbg(2, debug, client, "XDS data: %04x\n", xds);
 	saa7127_write(client, SAA7127_REG_LINE_21_EVEN_0, xds & 0xff);
 	saa7127_write(client, SAA7127_REG_LINE_21_EVEN_1, xds >> 8);
 	state->xds_data = xds;
@@ -424,7 +424,7 @@
 	if (enable && (data->field != 0 || data->line != 23))
 		return -EINVAL;
 	if (state->wss_enable != enable) {
-		v4l_dbg(1, client, "Turn WSS %s\n", enable ? "on" : "off");
+		v4l_dbg(1, debug, client, "Turn WSS %s\n", enable ? "on" : "off");
 		saa7127_write(client, 0x27, enable << 7);
 		state->wss_enable = enable;
 	}
@@ -433,7 +433,7 @@
 
 	saa7127_write(client, 0x26, data->data[0]);
 	saa7127_write(client, 0x27, 0x80 | (data->data[1] & 0x3f));
-	v4l_dbg(1, client, "WSS mode: %s\n", wss_strs[data->data[0] & 0xf]);
+	v4l_dbg(1, debug, client, "WSS mode: %s\n", wss_strs[data->data[0] & 0xf]);
 	state->wss_mode = (data->data[1] & 0x3f) << 8 | data->data[0];
 	return 0;
 }
@@ -445,11 +445,11 @@
 	struct saa7127_state *state = i2c_get_clientdata(client);
 
 	if (enable) {
-		v4l_dbg(1, client, "Enable Video Output\n");
+		v4l_dbg(1, debug, client, "Enable Video Output\n");
 		saa7127_write(client, 0x2d, state->reg_2d);
 		saa7127_write(client, 0x61, state->reg_61);
 	} else {
-		v4l_dbg(1, client, "Disable Video Output\n");
+		v4l_dbg(1, debug, client, "Disable Video Output\n");
 		saa7127_write(client, 0x2d, (state->reg_2d & 0xf0));
 		saa7127_write(client, 0x61, (state->reg_61 | 0xc0));
 	}
@@ -465,11 +465,11 @@
 	const struct i2c_reg_value *inittab;
 
 	if (std & V4L2_STD_525_60) {
-		v4l_dbg(1, client, "Selecting 60 Hz video Standard\n");
+		v4l_dbg(1, debug, client, "Selecting 60 Hz video Standard\n");
 		inittab = saa7127_init_config_60hz;
 		state->reg_61 = SAA7127_60HZ_DAC_CONTROL;
 	} else {
-		v4l_dbg(1, client, "Selecting 50 Hz video Standard\n");
+		v4l_dbg(1, debug, client, "Selecting 50 Hz video Standard\n");
 		inittab = saa7127_init_config_50hz;
 		state->reg_61 = SAA7127_50HZ_DAC_CONTROL;
 	}
@@ -520,7 +520,7 @@
 	default:
 		return -EINVAL;
 	}
-	v4l_dbg(1, client, "Selecting %s output type\n", output_strs[output]);
+	v4l_dbg(1, debug, client, "Selecting %s output type\n", output_strs[output]);
 
 	/* Configure Encoder */
 	saa7127_write(client, 0x2d, state->reg_2d);
@@ -537,12 +537,12 @@
 
 	switch (input) {
 	case SAA7127_INPUT_TYPE_NORMAL:	/* avia */
-		v4l_dbg(1, client, "Selecting Normal Encoder Input\n");
+		v4l_dbg(1, debug, client, "Selecting Normal Encoder Input\n");
 		state->reg_3a_cb = 0;
 		break;
 
 	case SAA7127_INPUT_TYPE_TEST_IMAGE:	/* color bar */
-		v4l_dbg(1, client, "Selecting Color Bar generator\n");
+		v4l_dbg(1, debug, client, "Selecting Color Bar generator\n");
 		state->reg_3a_cb = 0x80;
 		break;
 
@@ -689,17 +689,16 @@
 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
 		return 0;
 
-	client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
+	client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
 	if (client == 0)
 		return -ENOMEM;
 
-	memset(client, 0, sizeof(struct i2c_client));
 	client->addr = address;
 	client->adapter = adapter;
 	client->driver = &i2c_driver_saa7127;
 	snprintf(client->name, sizeof(client->name) - 1, "saa7127");
 
-	v4l_dbg(1, client, "detecting saa7127 client on address 0x%x\n", address << 1);
+	v4l_dbg(1, debug, client, "detecting saa7127 client on address 0x%x\n", address << 1);
 
 	/* First test register 0: Bits 5-7 are a version ID (should be 0),
 	   and bit 2 should also be 0.
@@ -708,11 +707,11 @@
 	   0x1d after a reset and not expected to ever change. */
 	if ((saa7127_read(client, 0) & 0xe4) != 0 ||
 			(saa7127_read(client, 0x29) & 0x3f) != 0x1d) {
-		v4l_dbg(1, client, "saa7127 not found\n");
+		v4l_dbg(1, debug, client, "saa7127 not found\n");
 		kfree(client);
 		return 0;
 	}
-	state = kmalloc(sizeof(struct saa7127_state), GFP_KERNEL);
+	state = kzalloc(sizeof(struct saa7127_state), GFP_KERNEL);
 
 	if (state == NULL) {
 		kfree(client);
@@ -720,11 +719,10 @@
 	}
 
 	i2c_set_clientdata(client, state);
-	memset(state, 0, sizeof(struct saa7127_state));
 
 	/* Configure Encoder */
 
-	v4l_dbg(1, client, "Configuring encoder\n");
+	v4l_dbg(1, debug, client, "Configuring encoder\n");
 	saa7127_write_inittab(client, saa7127_init_config_common);
 	saa7127_set_std(client, V4L2_STD_NTSC);
 	saa7127_set_output_type(client, SAA7127_OUTPUT_TYPE_BOTH);
diff --git a/drivers/media/video/saa7134/Kconfig b/drivers/media/video/saa7134/Kconfig
index 8a5c3e7..86671a4 100644
--- a/drivers/media/video/saa7134/Kconfig
+++ b/drivers/media/video/saa7134/Kconfig
@@ -15,7 +15,7 @@
 config VIDEO_SAA7134_ALSA
 	tristate "Philips SAA7134 DMA audio support"
 	depends on VIDEO_SAA7134 && SND
-	select SND_PCM_OSS
+	select SND_PCM
 	---help---
 	  This is a video4linux driver for direct (DMA) audio in
 	  Philips SAA713x based TV cards using ALSA
diff --git a/drivers/media/video/saa7134/saa6752hs.c b/drivers/media/video/saa7134/saa6752hs.c
index ad73c4a6..0e0ba50 100644
--- a/drivers/media/video/saa7134/saa6752hs.c
+++ b/drivers/media/video/saa7134/saa6752hs.c
@@ -511,9 +511,8 @@
 	struct saa6752hs_state *h;
 
 
-	if (NULL == (h = kmalloc(sizeof(*h), GFP_KERNEL)))
+	if (NULL == (h = kzalloc(sizeof(*h), GFP_KERNEL)))
 		return -ENOMEM;
-	memset(h,0,sizeof(*h));
 	h->client = client_template;
 	h->params = param_defaults;
 	h->client.adapter = adap;
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index 77e5be9..275d06a 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -1666,7 +1666,7 @@
 		.radio_type     = UNSET,
 		.tuner_addr	= ADDR_UNSET,
 		.radio_addr	= ADDR_UNSET,
-		.tda9887_conf   = TDA9887_PRESENT | TDA9887_INTERCARRIER,
+		.tda9887_conf   = TDA9887_PRESENT | TDA9887_INTERCARRIER | TDA9887_PORT2_ACTIVE,
 		.mpeg           = SAA7134_MPEG_DVB,
 		.inputs         = {{
 			.name = name_tv,
diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c
index accbc32..3983a65 100644
--- a/drivers/media/video/saa7134/saa7134-core.c
+++ b/drivers/media/video/saa7134/saa7134-core.c
@@ -803,10 +803,9 @@
 	struct saa7134_mpeg_ops *mops;
 	int err;
 
-	dev = kmalloc(sizeof(*dev),GFP_KERNEL);
+	dev = kzalloc(sizeof(*dev),GFP_KERNEL);
 	if (NULL == dev)
 		return -ENOMEM;
-	memset(dev,0,sizeof(*dev));
 
 	/* pci init */
 	dev->pci = pci_dev;
diff --git a/drivers/media/video/saa7134/saa7134-video.c b/drivers/media/video/saa7134/saa7134-video.c
index adfa8fe..e97426b 100644
--- a/drivers/media/video/saa7134/saa7134-video.c
+++ b/drivers/media/video/saa7134/saa7134-video.c
@@ -1264,10 +1264,9 @@
 		v4l2_type_names[type]);
 
 	/* allocate + initialize per filehandle data */
-	fh = kmalloc(sizeof(*fh),GFP_KERNEL);
+	fh = kzalloc(sizeof(*fh),GFP_KERNEL);
 	if (NULL == fh)
 		return -ENOMEM;
-	memset(fh,0,sizeof(*fh));
 	file->private_data = fh;
 	fh->dev      = dev;
 	fh->radio    = radio;
diff --git a/drivers/media/video/saa7146.h b/drivers/media/video/saa7146.h
index f305ec8..756963f 100644
--- a/drivers/media/video/saa7146.h
+++ b/drivers/media/video/saa7146.h
@@ -73,7 +73,6 @@
         unsigned int nr;
 	unsigned long irq;          /* IRQ used by SAA7146 card */
 	unsigned short id;
-	struct pci_dev *dev;
 	unsigned char revision;
 	unsigned char boardcfg[64];	/* 64 bytes of config from eeprom */
 	unsigned long saa7146_adr;   /* bus address of IO mem from PCI BIOS */
diff --git a/drivers/media/video/saa7185.c b/drivers/media/video/saa7185.c
index f72a9f7..3ed0edb 100644
--- a/drivers/media/video/saa7185.c
+++ b/drivers/media/video/saa7185.c
@@ -408,21 +408,19 @@
 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
 		return 0;
 
-	client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
+	client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
 	if (client == 0)
 		return -ENOMEM;
-	memset(client, 0, sizeof(struct i2c_client));
 	client->addr = address;
 	client->adapter = adapter;
 	client->driver = &i2c_driver_saa7185;
 	strlcpy(I2C_NAME(client), "saa7185", sizeof(I2C_NAME(client)));
 
-	encoder = kmalloc(sizeof(struct saa7185), GFP_KERNEL);
+	encoder = kzalloc(sizeof(struct saa7185), GFP_KERNEL);
 	if (encoder == NULL) {
 		kfree(client);
 		return -ENOMEM;
 	}
-	memset(encoder, 0, sizeof(struct saa7185));
 	encoder->norm = VIDEO_MODE_NTSC;
 	encoder->enable = 1;
 	i2c_set_clientdata(client, encoder);
diff --git a/drivers/media/video/saa7191.c b/drivers/media/video/saa7191.c
index 41f6f05..746cadb 100644
--- a/drivers/media/video/saa7191.c
+++ b/drivers/media/video/saa7191.c
@@ -571,18 +571,15 @@
 	printk(KERN_INFO "Philips SAA7191 driver version %s\n",
 	       SAA7191_MODULE_VERSION);
 
-	client = kmalloc(sizeof(*client), GFP_KERNEL);
+	client = kzalloc(sizeof(*client), GFP_KERNEL);
 	if (!client)
 		return -ENOMEM;
-	decoder = kmalloc(sizeof(*decoder), GFP_KERNEL);
+	decoder = kzalloc(sizeof(*decoder), GFP_KERNEL);
 	if (!decoder) {
 		err = -ENOMEM;
 		goto out_free_client;
 	}
 
-	memset(client, 0, sizeof(struct i2c_client));
-	memset(decoder, 0, sizeof(struct saa7191));
-
 	client->addr = addr;
 	client->adapter = adap;
 	client->driver = &i2c_driver_saa7191;
diff --git a/drivers/media/video/stradis.c b/drivers/media/video/stradis.c
index 6ee54a4..54fc330 100644
--- a/drivers/media/video/stradis.c
+++ b/drivers/media/video/stradis.c
@@ -49,9 +49,9 @@
 #include "saa7121.h"
 #include "cs8420.h"
 
-#define DEBUG(x) 		/* debug driver */
-#undef  IDEBUG	 		/* debug irq handler */
-#undef  MDEBUG	 		/* debug memory management */
+#define DEBUG(x)		/* debug driver */
+#undef  IDEBUG			/* debug irq handler */
+#undef  MDEBUG			/* debug memory management */
 
 #define SAA7146_MAX 6
 
@@ -63,7 +63,6 @@
 module_param(video_nr, int, 0);
 MODULE_LICENSE("GPL");
 
-
 #define nDebNormal	0x00480000
 #define nDebNoInc	0x00480000
 #define nDebVideo	0xd0480000
@@ -99,7 +98,12 @@
 
 #ifdef USE_RESCUE_EEPROM_SDM275
 static unsigned char rescue_eeprom[64] = {
-0x00,0x01,0x04,0x13,0x26,0x0f,0x10,0x00,0x00,0x00,0x43,0x63,0x22,0x01,0x29,0x15,0x73,0x00,0x1f, 'd', 'e', 'c', 'x', 'l', 'd', 'v', 'a',0x02,0x00,0x01,0x00,0xcc,0xa4,0x63,0x09,0xe2,0x10,0x00,0x0a,0x00,0x02,0x02, 'd', 'e', 'c', 'x', 'l', 'a',0x00,0x00,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+	0x00, 0x01, 0x04, 0x13, 0x26, 0x0f, 0x10, 0x00, 0x00, 0x00, 0x43, 0x63,
+	0x22, 0x01, 0x29, 0x15, 0x73, 0x00, 0x1f,  'd',  'e',  'c',  'x',  'l',
+	 'd',  'v',  'a', 0x02, 0x00, 0x01, 0x00, 0xcc, 0xa4, 0x63, 0x09, 0xe2,
+	0x10, 0x00, 0x0a, 0x00, 0x02, 0x02,  'd',  'e',  'c',  'x',  'l',  'a',
+	0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00,
 };
 #endif
 
@@ -140,17 +144,18 @@
 
 	if (saaread(SAA7146_I2C_STATUS) & 0x3c)
 		I2CWipe(saa);
-	for (i = 0; i < 1000 &&
-	     (saaread(SAA7146_I2C_STATUS) & SAA7146_I2C_BUSY); i++)
+	for (i = 0;
+		i < 1000 && (saaread(SAA7146_I2C_STATUS) & SAA7146_I2C_BUSY);
+		i++)
 		schedule();
 	if (i == 1000)
 		I2CWipe(saa);
 	if (dosub)
 		saawrite(((addr & 0xfe) << 24) | (((addr | 1) & 0xff) << 8) |
-		  ((subaddr & 0xff) << 16) | 0xed, SAA7146_I2C_TRANSFER);
+			((subaddr & 0xff) << 16) | 0xed, SAA7146_I2C_TRANSFER);
 	else
 		saawrite(((addr & 0xfe) << 24) | (((addr | 1) & 0xff) << 16) |
-			 0xf1, SAA7146_I2C_TRANSFER);
+			0xf1, SAA7146_I2C_TRANSFER);
 	saawrite((SAA7146_MC2_UPLD_I2C << 16) |
 		 SAA7146_MC2_UPLD_I2C, SAA7146_MC2);
 	/* wait for i2c registers to be programmed */
@@ -163,7 +168,7 @@
 		schedule();
 	if (saaread(SAA7146_I2C_STATUS) & SAA7146_I2C_ERR)
 		return -1;
-	if (i == 1000) 
+	if (i == 1000)
 		printk("i2c setup read timeout\n");
 	saawrite(0x41, SAA7146_I2C_TRANSFER);
 	saawrite((SAA7146_MC2_UPLD_I2C << 16) |
@@ -178,7 +183,7 @@
 		schedule();
 	if (saaread(SAA7146_I2C_TRANSFER) & SAA7146_I2C_ERR)
 		return -1;
-	if (i == 1000) 
+	if (i == 1000)
 		printk("i2c read timeout\n");
 	return ((saaread(SAA7146_I2C_TRANSFER) >> 24) & 0xff);
 }
@@ -213,20 +218,22 @@
 {
 	int i;
 
-	DEBUG(printk(KERN_DEBUG "stradis%d: i2c: device found=%02x\n", saa->nr, id));
-	if (id == 0xa0)	{ /* we have rev2 or later board, fill in info */
+	DEBUG(printk(KERN_DEBUG "stradis%d: i2c: device found=%02x\n", saa->nr,
+		id));
+	if (id == 0xa0) {	/* we have rev2 or later board, fill in info */
 		for (i = 0; i < 64; i++)
 			saa->boardcfg[i] = I2CRead(saa, 0xa0, i, 1);
 #ifdef USE_RESCUE_EEPROM_SDM275
 		if (saa->boardcfg[0] != 0) {
-			printk("stradis%d: WARNING: EEPROM STORED VALUES HAVE BEEN IGNORED\n", saa->nr);
+			printk("stradis%d: WARNING: EEPROM STORED VALUES HAVE "
+				"BEEN IGNORED\n", saa->nr);
 			for (i = 0; i < 64; i++)
 				saa->boardcfg[i] = rescue_eeprom[i];
 		}
 #endif
 		printk("stradis%d: config =", saa->nr);
 		for (i = 0; i < 51; i++) {
-			printk(" %02x",saa->boardcfg[i]);
+			printk(" %02x", saa->boardcfg[i]);
 		}
 		printk("\n");
 	}
@@ -254,17 +261,19 @@
 	for (i = 0; i < 500000 &&
 	     (saaread(SAA7146_PSR) & SAA7146_PSR_DEBI_S); i++)
 		saaread(SAA7146_MC2);
+
 	if (i > debiwait_maxwait)
 		printk("wait-for-debi-done maxwait: %d\n",
 			debiwait_maxwait = i);
-	
+
 	if (i == 500000)
 		return -1;
+
 	return 0;
 }
 
 static int debiwrite(struct saa7146 *saa, u32 config, int addr,
-		      u32 val, int count)
+	u32 val, int count)
 {
 	u32 cmd;
 	if (count <= 0 || count > 32764)
@@ -309,41 +318,6 @@
 	return result;
 }
 
-#if 0 /* unused */
-/* MUST be a multiple of 8 bytes and 8-byte aligned and < 32768 bytes */
-/* data copied into saa->dmadebi buffer, caller must re-enable interrupts */
-static void ibm_block_dram_read(struct saa7146 *saa, int address, int bytes)
-{
-	int i, j;
-	u32 *buf;
-	buf = (u32 *) saa->dmadebi;
-	if (bytes > 0x7000)
-		bytes = 0x7000;
-	saawrite(0, SAA7146_IER);	/* disable interrupts */
-	for (i=0; i < 10000 &&
-		(debiread(saa, debNormal, IBM_MP2_DRAM_CMD_STAT, 2)
-		& 0x8000); i++)
-		saaread(SAA7146_MC2);
-	if (i == 10000)
-		printk(KERN_ERR "stradis%d: dram_busy never cleared\n",
-			saa->nr);
-	debiwrite(saa, debNormal, IBM_MP2_SRC_ADDR, (address<<16) |
-		(address>>16), 4);
-	debiwrite(saa, debNormal, IBM_MP2_BLOCK_SIZE, bytes, 2);
-	debiwrite(saa, debNormal, IBM_MP2_CMD_STAT, 0x8a10, 2);
-	for (j = 0; j < bytes/4; j++) {
-		for (i = 0; i < 10000 &&
-			(!(debiread(saa, debNormal, IBM_MP2_DRAM_CMD_STAT, 2)
-			& 0x4000)); i++)
-			saaread(SAA7146_MC2);
-		if (i == 10000)
-			printk(KERN_ERR "stradis%d: dram_ready never set\n",
-				saa->nr);
-		buf[j] = debiread(saa, debNormal, IBM_MP2_DRAM_DATA, 4);
-	}
-}
-#endif /* unused */
-
 static void do_irq_send_data(struct saa7146 *saa)
 {
 	int split, audbytes, vidbytes;
@@ -365,16 +339,15 @@
 		return;
 	}
 	/* if at least 1 block audio waiting and audio fifo isn't full */
-	if (audbytes >= 2048 && (debiread(saa, debNormal,
-		IBM_MP2_AUD_FIFO, 2) & 0xff) < 60) {
+	if (audbytes >= 2048 && (debiread(saa, debNormal, IBM_MP2_AUD_FIFO, 2)
+			& 0xff) < 60) {
 		if (saa->audhead > saa->audtail)
 			split = 65536 - saa->audhead;
 		else
 			split = 0;
 		audbytes = 2048;
 		if (split > 0 && split < 2048) {
-			memcpy(saa->dmadebi, saa->audbuf + saa->audhead,
-				split);
+			memcpy(saa->dmadebi, saa->audbuf + saa->audhead, split);
 			saa->audhead = 0;
 			audbytes -= split;
 		} else
@@ -383,20 +356,19 @@
 			audbytes);
 		saa->audhead += audbytes;
 		saa->audhead &= 0xffff;
-		debiwrite(saa, debAudio, (NewCard? IBM_MP2_AUD_FIFO :
-			  IBM_MP2_AUD_FIFOW), 0, 2048);
+		debiwrite(saa, debAudio, (NewCard ? IBM_MP2_AUD_FIFO :
+			IBM_MP2_AUD_FIFOW), 0, 2048);
 		wake_up_interruptible(&saa->audq);
-	/* if at least 1 block video waiting and video fifo isn't full */
+		/* if at least 1 block video waiting and video fifo isn't full */
 	} else if (vidbytes >= 30720 && (debiread(saa, debNormal,
-		IBM_MP2_FIFO, 2)) < 16384) {
+						  IBM_MP2_FIFO, 2)) < 16384) {
 		if (saa->vidhead > saa->vidtail)
 			split = 524288 - saa->vidhead;
 		else
 			split = 0;
 		vidbytes = 30720;
 		if (split > 0 && split < 30720) {
-			memcpy(saa->dmadebi, saa->vidbuf + saa->vidhead,
-				split);
+			memcpy(saa->dmadebi, saa->vidbuf + saa->vidhead, split);
 			saa->vidhead = 0;
 			vidbytes -= split;
 		} else
@@ -406,7 +378,7 @@
 		saa->vidhead += vidbytes;
 		saa->vidhead &= 0x7ffff;
 		debiwrite(saa, debVideo, (NewCard ? IBM_MP2_FIFO :
-			  IBM_MP2_FIFOW), 0, 30720);
+					  IBM_MP2_FIFOW), 0, 30720);
 		wake_up_interruptible(&saa->vidq);
 	}
 	saawrite(SAA7146_PSR_DEBI_S | SAA7146_PSR_PIN1, SAA7146_IER);
@@ -418,10 +390,10 @@
 	if (size > 30720)
 		size = 30720;
 	/* ensure some multiple of 8 bytes is transferred */
-	size = 8 * ((size + 8)>>3);
+	size = 8 * ((size + 8) >> 3);
 	if (size) {
 		debiwrite(saa, debNormal, IBM_MP2_OSD_ADDR,
-			  (saa->osdhead>>3), 2);
+			  (saa->osdhead >> 3), 2);
 		memcpy(saa->dmadebi, &saa->osdbuf[saa->osdhead], size);
 		saa->osdhead += size;
 		/* block transfer of next 8 bytes to ~32k bytes */
@@ -435,7 +407,7 @@
 
 static irqreturn_t saa7146_irq(int irq, void *dev_id, struct pt_regs *regs)
 {
-	struct saa7146 *saa = (struct saa7146 *) dev_id;
+	struct saa7146 *saa = dev_id;
 	u32 stat, astat;
 	int count;
 	int handled = 0;
@@ -484,7 +456,7 @@
 				saa->vidinfo.v_size = 480;
 #if 0
 				if (saa->endmarkhead != saa->endmarktail) {
-					saa->audhead = 
+					saa->audhead =
 						saa->endmark[saa->endmarkhead];
 					saa->endmarkhead++;
 					if (saa->endmarkhead >= MAX_MARKS)
@@ -494,7 +466,7 @@
 			}
 			if (istat & 0x4000) {	/* Sequence Error Code */
 				if (saa->endmarkhead != saa->endmarktail) {
-					saa->audhead = 
+					saa->audhead =
 						saa->endmark[saa->endmarkhead];
 					saa->endmarkhead++;
 					if (saa->endmarkhead >= MAX_MARKS)
@@ -613,7 +585,7 @@
 	int i;
 
 	if (chain)
-		debiwrite(saa, debNormal, IBM_MP2_COMMAND, (command << 1) | 1, 2);
+		debiwrite(saa, debNormal, IBM_MP2_COMMAND, (command << 1)| 1,2);
 	else
 		debiwrite(saa, debNormal, IBM_MP2_COMMAND, command << 1, 2);
 	debiwrite(saa, debNormal, IBM_MP2_CMD_DATA, data, 2);
@@ -663,11 +635,9 @@
 	else
 		sequence = mode8420con;
 	for (i = 0; i < INIT8420LEN; i++)
-		I2CWrite(saa, 0x20, init8420[i * 2],
-			 init8420[i * 2 + 1], 2);
+		I2CWrite(saa, 0x20, init8420[i * 2], init8420[i * 2 + 1], 2);
 	for (i = 0; i < MODE8420LEN; i++)
-		I2CWrite(saa, 0x20, sequence[i * 2],
-			 sequence[i * 2 + 1], 2);
+		I2CWrite(saa, 0x20, sequence[i * 2], sequence[i * 2 + 1], 2);
 	printk("stradis%d: CS8420 initialized\n", saa->nr);
 }
 
@@ -683,35 +653,36 @@
 	/* initialize PAL/NTSC video encoder */
 	for (i = 0; i < INIT7121LEN; i++) {
 		if (NewCard) {	/* handle new card encoder differences */
-			if (sequence[i*2] == 0x3a)
+			if (sequence[i * 2] == 0x3a)
 				I2CWrite(saa, 0x88, 0x3a, 0x13, 2);
-			else if (sequence[i*2] == 0x6b)
+			else if (sequence[i * 2] == 0x6b)
 				I2CWrite(saa, 0x88, 0x6b, 0x20, 2);
-			else if (sequence[i*2] == 0x6c)
+			else if (sequence[i * 2] == 0x6c)
 				I2CWrite(saa, 0x88, 0x6c,
 					 dopal ? 0x09 : 0xf5, 2);
-			else if (sequence[i*2] == 0x6d)
+			else if (sequence[i * 2] == 0x6d)
 				I2CWrite(saa, 0x88, 0x6d,
 					 dopal ? 0x20 : 0x00, 2);
-			else if (sequence[i*2] == 0x7a)
+			else if (sequence[i * 2] == 0x7a)
 				I2CWrite(saa, 0x88, 0x7a,
 					 dopal ? (PALFirstActive - 1) :
 					 (NTSCFirstActive - 4), 2);
-			else if (sequence[i*2] == 0x7b)
+			else if (sequence[i * 2] == 0x7b)
 				I2CWrite(saa, 0x88, 0x7b,
 					 dopal ? PALLastActive :
 					 NTSCLastActive, 2);
-			else I2CWrite(saa, 0x88, sequence[i * 2],
-				 sequence[i * 2 + 1], 2);
+			else
+				I2CWrite(saa, 0x88, sequence[i * 2],
+					 sequence[i * 2 + 1], 2);
 		} else {
-			if (sequence[i*2] == 0x6b && mod)
-				I2CWrite(saa, 0x88, 0x6b, 
-					(sequence[i * 2 + 1] ^ 0x09), 2);
-			else if (sequence[i*2] == 0x7a)
+			if (sequence[i * 2] == 0x6b && mod)
+				I2CWrite(saa, 0x88, 0x6b,
+					 (sequence[i * 2 + 1] ^ 0x09), 2);
+			else if (sequence[i * 2] == 0x7a)
 				I2CWrite(saa, 0x88, 0x7a,
 					 dopal ? (PALFirstActive - 1) :
 					 (NTSCFirstActive - 4), 2);
-			else if (sequence[i*2] == 0x7b)
+			else if (sequence[i * 2] == 0x7b)
 				I2CWrite(saa, 0x88, 0x7b,
 					 dopal ? PALLastActive :
 					 NTSCLastActive, 2);
@@ -735,7 +706,8 @@
 	nCode = noffset + 0x100;
 	if (nCode == 1)
 		nCode = 0x401;
-	else if (nCode < 1) nCode = 0x400 + PixelsPerLine + nCode;
+	else if (nCode < 1)
+		nCode = 0x400 + PixelsPerLine + nCode;
 	debiwrite(saa, debNormal, XILINX_GLDELAY, nCode, 2);
 }
 
@@ -745,33 +717,31 @@
 	saa->boardcfg[2] = mode;
 	/* do not adjust analog video parameters here, use saa7121 init */
 	/* you will affect the SDI output on the new card */
-	if (mode == VIDEO_MODE_PAL) {		/* PAL */
+	if (mode == VIDEO_MODE_PAL) {	/* PAL */
 		debiwrite(saa, debNormal, XILINX_CTL0, 0x0808, 2);
 		mdelay(50);
 		saawrite(0x012002c0, SAA7146_NUM_LINE_BYTE1);
 		if (NewCard) {
-			debiwrite(saa, debNormal, IBM_MP2_DISP_MODE,
-				  0xe100, 2);
+			debiwrite(saa, debNormal, IBM_MP2_DISP_MODE, 0xe100, 2);
 			mdelay(50);
 		}
 		debiwrite(saa, debNormal, IBM_MP2_DISP_MODE,
-			  NewCard ? 0xe500: 0x6500, 2);
+			  NewCard ? 0xe500 : 0x6500, 2);
 		debiwrite(saa, debNormal, IBM_MP2_DISP_DLY,
 			  (1 << 8) |
-			  (NewCard ? PALFirstActive : PALFirstActive-6), 2);
+			  (NewCard ? PALFirstActive : PALFirstActive - 6), 2);
 	} else {		/* NTSC */
 		debiwrite(saa, debNormal, XILINX_CTL0, 0x0800, 2);
 		mdelay(50);
 		saawrite(0x00f002c0, SAA7146_NUM_LINE_BYTE1);
 		debiwrite(saa, debNormal, IBM_MP2_DISP_MODE,
-			  NewCard ? 0xe100: 0x6100, 2);
+			  NewCard ? 0xe100 : 0x6100, 2);
 		debiwrite(saa, debNormal, IBM_MP2_DISP_DLY,
 			  (1 << 8) |
-			  (NewCard ? NTSCFirstActive : NTSCFirstActive-6), 2);
+			  (NewCard ? NTSCFirstActive : NTSCFirstActive - 6), 2);
 	}
 }
 
-
 /* Intialize bitmangler to map from a byte value to the mangled word that
  * must be output to program the Xilinx part through the DEBI port.
  * Xilinx Data Bit->DEBI Bit: 0->15 1->7 2->6 3->12 4->11 5->2 6->1 7->0
@@ -799,43 +769,41 @@
 	for (num = 0; num < saa_num; num++) {
 		saa = &saa7146s[num];
 		if (saa->boardcfg[0] > 20)
-				continue;	/* card was programmed */
+			continue;	/* card was programmed */
 		loadtwo = (saa->boardcfg[18] & 0x10);
 		if (!NewCard)	/* we have an old board */
 			for (i = 0; i < 256; i++)
-			    bitmangler[i] = ((i & 0x01) << 15) |
-				((i & 0x02) << 6) | ((i & 0x04) << 4) |
-				((i & 0x08) << 9) | ((i & 0x10) << 7) |
-				((i & 0x20) >> 3) | ((i & 0x40) >> 5) |
-				((i & 0x80) >> 7);
-		else	/* else we have a new board */
+				bitmangler[i] = ((i & 0x01) << 15) |
+					((i & 0x02) << 6) | ((i & 0x04) << 4) |
+					((i & 0x08) << 9) | ((i & 0x10) << 7) |
+					((i & 0x20) >> 3) | ((i & 0x40) >> 5) |
+					((i & 0x80) >> 7);
+		else		/* else we have a new board */
 			for (i = 0; i < 256; i++)
-			    bitmangler[i] = ((i & 0x01) << 7) |
-				((i & 0x02) << 5) | ((i & 0x04) << 3) |
-				((i & 0x08) << 1) | ((i & 0x10) >> 1) |
-				((i & 0x20) >> 3) | ((i & 0x40) >> 5) |
-				((i & 0x80) >> 7);
+				bitmangler[i] = ((i & 0x01) << 7) |
+					((i & 0x02) << 5) | ((i & 0x04) << 3) |
+					((i & 0x08) << 1) | ((i & 0x10) >> 1) |
+					((i & 0x20) >> 3) | ((i & 0x40) >> 5) |
+					((i & 0x80) >> 7);
 
 		dmabuf = (u16 *) saa->dmadebi;
 		newdma = (u8 *) saa->dmadebi;
 		if (NewCard) {	/* SDM2xxx */
 			if (!strncmp(bitdata->loadwhat, "decoder2", 8))
 				continue;	/* fpga not for this card */
-			if (!strncmp(&saa->boardcfg[42],
-				     bitdata->loadwhat, 8)) {
+			if (!strncmp(&saa->boardcfg[42], bitdata->loadwhat, 8))
 				loadfile = 1;
-			} else if (loadtwo && !strncmp(&saa->boardcfg[19],
-				   bitdata->loadwhat, 8)) {
+			else if (loadtwo && !strncmp(&saa->boardcfg[19],
+				       bitdata->loadwhat, 8))
 				loadfile = 2;
-			} else if (!saa->boardcfg[42] &&	/* special */
-				   !strncmp("decxl", bitdata->loadwhat, 8)) {
-				loadfile = 1;
-			} else
+			else if (!saa->boardcfg[42] && !strncmp("decxl",
+					bitdata->loadwhat, 8))
+				loadfile = 1;	/* special */
+			else
 				continue;	/* fpga not for this card */
-			if (loadfile != 1 && loadfile != 2) {
+			if (loadfile != 1 && loadfile != 2)
 				continue;	/* skip to next card */
-			}
-			if (saa->boardcfg[0] && loadfile == 1 )
+			if (saa->boardcfg[0] && loadfile == 1)
 				continue;	/* skip to next card */
 			if (saa->boardcfg[0] != 1 && loadfile == 2)
 				continue;	/* skip to next card */
@@ -870,8 +838,9 @@
 		/* Release Xilinx INIT signal (WS2) */
 		saawrite(0x00000000, SAA7146_GPIO_CTRL);
 		/* Wait for the INIT to go High */
-		for (i = 0; i < 10000 &&
-		     !(saaread(SAA7146_PSR) & SAA7146_PSR_PIN2); i++)
+		for (i = 0;
+			i < 10000 && !(saaread(SAA7146_PSR) & SAA7146_PSR_PIN2);
+			i++)
 			schedule();
 		if (i == 1000) {
 			printk(KERN_INFO "stradis%d: no fpga INIT\n", saa->nr);
@@ -881,17 +850,13 @@
 		if (NewCard) {
 			for (i = startindex; i < bitdata->datasize; i++)
 				newdma[i - startindex] =
-					bitmangler[bitdata->data[i]];
+				    bitmangler[bitdata->data[i]];
 			debiwrite(saa, 0x01420000, 0, 0,
 				((bitdata->datasize - startindex) + 5));
-			if (loadtwo) {
-				if (loadfile == 1) {
-					printk("stradis%d: "
-						"awaiting 2nd FPGA bitfile\n",
-						saa->nr);
-					continue;	/* skip to next card */
-				}
-
+			if (loadtwo && loadfile == 1) {
+				printk("stradis%d: awaiting 2nd FPGA bitfile\n",
+				       saa->nr);
+				continue;	/* skip to next card */
 			}
 		} else {
 			for (i = startindex; i < bitdata->datasize; i++)
@@ -900,8 +865,9 @@
 			debiwrite(saa, 0x014a0000, 0, 0,
 				((bitdata->datasize - startindex) + 5) * 2);
 		}
-		for (i = 0; i < 1000 &&
-		     !(saaread(SAA7146_PSR) & SAA7146_PSR_PIN2); i++)
+		for (i = 0;
+			i < 1000 && !(saaread(SAA7146_PSR) & SAA7146_PSR_PIN2);
+			i++)
 			schedule();
 		if (i == 1000) {
 			printk(KERN_INFO "stradis%d: FPGA load failed\n",
@@ -925,14 +891,14 @@
 			/* mute CS3310 */
 			if (HaveCS3310)
 				debiwrite(saa, debNormal, XILINX_CS3310_CMPLT,
-					  0, 2);
+					0, 2);
 			/* set VXCO to PWM mode, release reset, blank on */
 			debiwrite(saa, debNormal, XILINX_CTL0, 0xffc4, 2);
 			mdelay(10);
 			/* unmute CS3310 */
 			if (HaveCS3310)
 				debiwrite(saa, debNormal, XILINX_CTL0,
-					  0x2020, 2);
+					0x2020, 2);
 		}
 		/* set source Black */
 		debiwrite(saa, debNormal, XILINX_CTL0, 0x1707, 2);
@@ -958,10 +924,10 @@
 			/* we must init CS8420 first since rev b pulls i2s */
 			/* master clock low and CS4341 needs i2s master to */
 			/* run the i2c port. */
-			if (HaveCS8420) {
+			if (HaveCS8420)
 				/* 0=consumer, 1=pro */
 				initialize_cs8420(saa, 0);
-			}
+
 			mdelay(5);
 			if (HaveCS4341)
 				initialize_cs4341(saa);
@@ -981,6 +947,7 @@
 		debiwrite(saa, debNormal, XILINX_CTL0, 0x8080, 2);
 #endif
 	}
+
 	return failure;
 }
 
@@ -1021,10 +988,10 @@
 		/* we must init CS8420 first since rev b pulls i2s */
 		/* master clock low and CS4341 needs i2s master to */
 		/* run the i2c port. */
-		if (HaveCS8420) {
+		if (HaveCS8420)
 			/* 0=consumer, 1=pro */
 			initialize_cs8420(saa, 1);
-		}
+
 		mdelay(5);
 		if (HaveCS4341)
 			initialize_cs4341(saa);
@@ -1039,12 +1006,12 @@
 	debiwrite(saa, debNormal, IBM_MP2_OSD_SIZE, 0x2000, 2);
 	debiwrite(saa, debNormal, IBM_MP2_AUD_CTL, 0x4552, 2);
 	if (ibm_send_command(saa, IBM_MP2_CONFIG_DECODER,
-		(ChipControl == 0x43 ? 0xe800 : 0xe000), 1)) {
+			(ChipControl == 0x43 ? 0xe800 : 0xe000), 1)) {
 		printk(KERN_ERR "stradis%d: IBM config failed\n", saa->nr);
 	}
 	if (HaveCS3310) {
 		int i = CS3310MaxLvl;
-		debiwrite(saa, debNormal, XILINX_CS3310_CMPLT, ((i<<8)|i), 2);
+		debiwrite(saa, debNormal, XILINX_CS3310_CMPLT, ((i << 8)| i),2);
 	}
 	/* start video decoder */
 	debiwrite(saa, debNormal, IBM_MP2_CHIP_CONTROL, ChipControl, 2);
@@ -1057,6 +1024,7 @@
 	/* clear pending interrupts */
 	debiread(saa, debNormal, IBM_MP2_HOST_INT, 2);
 	debiwrite(saa, debNormal, XILINX_CTL0, 0x1711, 2);
+
 	return 0;
 }
 
@@ -1070,8 +1038,8 @@
 		saa = &saa7146s[num];
 		/* check that FPGA is loaded */
 		debiwrite(saa, debNormal, IBM_MP2_OSD_SIZE, 0xa55a, 2);
-		if ((i = debiread(saa, debNormal, IBM_MP2_OSD_SIZE, 2)) !=
-		     0xa55a) {
+		i = debiread(saa, debNormal, IBM_MP2_OSD_SIZE, 2);
+		if (i != 0xa55a) {
 			printk(KERN_INFO "stradis%d: %04x != 0xa55a\n",
 				saa->nr, i);
 #if 0
@@ -1082,17 +1050,17 @@
 			if (saa->boardcfg[0] > 27)
 				continue;	/* skip to next card */
 			/* load video control store */
-			saa->boardcfg[1] = 0x13;  /* no-sync default */
+			saa->boardcfg[1] = 0x13;	/* no-sync default */
 			debiwrite(saa, debNormal, IBM_MP2_WR_PROT, 1, 2);
 			debiwrite(saa, debNormal, IBM_MP2_PROC_IADDR, 0, 2);
 			for (i = 0; i < microcode->datasize / 2; i++)
 				debiwrite(saa, debNormal, IBM_MP2_PROC_IDATA,
 					(microcode->data[i * 2] << 8) |
-					 microcode->data[i * 2 + 1], 2);
+					microcode->data[i * 2 + 1], 2);
 			debiwrite(saa, debNormal, IBM_MP2_PROC_IADDR, 0, 2);
 			debiwrite(saa, debNormal, IBM_MP2_WR_PROT, 0, 2);
 			debiwrite(saa, debNormal, IBM_MP2_CHIP_CONTROL,
-				  ChipControl, 2);
+				ChipControl, 2);
 			saa->boardcfg[0] = 28;
 		}
 		if (!strncmp(microcode->loadwhat, "decoder.aud", 11)) {
@@ -1109,34 +1077,32 @@
 			debiwrite(saa, debNormal, IBM_MP2_OSD_SIZE, 0x2000, 2);
 			debiwrite(saa, debNormal, IBM_MP2_AUD_CTL, 0x4552, 2);
 			if (ibm_send_command(saa, IBM_MP2_CONFIG_DECODER,
-			    0xe000, 1)) {
-				printk(KERN_ERR
-				       "stradis%d: IBM config failed\n",
-				       saa->nr);
+					0xe000, 1)) {
+				printk(KERN_ERR "stradis%d: IBM config "
+					"failed\n", saa->nr);
 				return -1;
 			}
 			/* set PWM to center value */
 			if (NewCard) {
 				debiwrite(saa, debNormal, XILINX_PWM,
-					  saa->boardcfg[14] +
-					  (saa->boardcfg[13]<<8), 2);
+					saa->boardcfg[14] +
+					(saa->boardcfg[13] << 8), 2);
 			} else
-				debiwrite(saa, debNormal, XILINX_PWM,
-					  0x46, 2);
+				debiwrite(saa, debNormal, XILINX_PWM, 0x46, 2);
+
 			if (HaveCS3310) {
 				i = CS3310MaxLvl;
-				debiwrite(saa, debNormal,
-					XILINX_CS3310_CMPLT, ((i<<8)|i), 2);
+				debiwrite(saa, debNormal, XILINX_CS3310_CMPLT,
+					(i << 8) | i, 2);
 			}
-			printk(KERN_INFO
-			       "stradis%d: IBM MPEGCD%d Initialized\n",
-			       saa->nr, 18 + (debiread(saa, debNormal,
-			       IBM_MP2_CHIP_CONTROL, 2) >> 12));
+			printk(KERN_INFO "stradis%d: IBM MPEGCD%d Inited\n",
+				saa->nr, 18 + (debiread(saa, debNormal,
+				IBM_MP2_CHIP_CONTROL, 2) >> 12));
 			/* start video decoder */
 			debiwrite(saa, debNormal, IBM_MP2_CHIP_CONTROL,
 				ChipControl, 2);
-			debiwrite(saa, debNormal, IBM_MP2_RB_THRESHOLD,
-				0x4037, 2);	/* 256k vid, 3520 bytes aud */
+			debiwrite(saa, debNormal, IBM_MP2_RB_THRESHOLD, 0x4037,
+				2);	/* 256k vid, 3520 bytes aud */
 			debiwrite(saa, debNormal, IBM_MP2_AUD_CTL, 0x4573, 2);
 			ibm_send_command(saa, IBM_MP2_PLAY, 0, 0);
 			/* enable buffer threshold irq */
@@ -1149,52 +1115,48 @@
 			saa->boardcfg[0] = 37;
 		}
 	}
+
 	return 0;
 }
 
-static u32 palette2fmt[] =
-{				/* some of these YUV translations are wrong */
-  0xffffffff, 0x86000000, 0x87000000, 0x80000000, 0x8100000, 0x82000000,
-  0x83000000, 0x00000000, 0x03000000, 0x03000000, 0x0a00000, 0x03000000,
-  0x06000000, 0x00000000, 0x03000000, 0x0a000000, 0x0300000
+static u32 palette2fmt[] = {	/* some of these YUV translations are wrong */
+	0xffffffff, 0x86000000, 0x87000000, 0x80000000, 0x8100000, 0x82000000,
+	0x83000000, 0x00000000, 0x03000000, 0x03000000, 0x0a00000, 0x03000000,
+	0x06000000, 0x00000000, 0x03000000, 0x0a000000, 0x0300000
 };
-static int bpp2fmt[4] =
-{
+static int bpp2fmt[4] = {
 	VIDEO_PALETTE_HI240, VIDEO_PALETTE_RGB565, VIDEO_PALETTE_RGB24,
 	VIDEO_PALETTE_RGB32
 };
 
 /* I wish I could find a formula to calculate these... */
-static u32 h_prescale[64] =
-{
-  0x10000000, 0x18040202, 0x18080000, 0x380c0606, 0x38100204, 0x38140808,
-  0x38180000, 0x381c0000, 0x3820161c, 0x38242a3b, 0x38281230, 0x382c4460,
-  0x38301040, 0x38340080, 0x38380000, 0x383c0000, 0x3840fefe, 0x3844ee9f,
-  0x3848ee9f, 0x384cee9f, 0x3850ee9f, 0x38542a3b, 0x38581230, 0x385c0000,
-  0x38600000, 0x38640000, 0x38680000, 0x386c0000, 0x38700000, 0x38740000,
-  0x38780000, 0x387c0000, 0x30800000, 0x38840000, 0x38880000, 0x388c0000,
-  0x38900000, 0x38940000, 0x38980000, 0x389c0000, 0x38a00000, 0x38a40000,
-  0x38a80000, 0x38ac0000, 0x38b00000, 0x38b40000, 0x38b80000, 0x38bc0000,
-  0x38c00000, 0x38c40000, 0x38c80000, 0x38cc0000, 0x38d00000, 0x38d40000,
-  0x38d80000, 0x38dc0000, 0x38e00000, 0x38e40000, 0x38e80000, 0x38ec0000,
-  0x38f00000, 0x38f40000, 0x38f80000, 0x38fc0000,
+static u32 h_prescale[64] = {
+	0x10000000, 0x18040202, 0x18080000, 0x380c0606, 0x38100204, 0x38140808,
+	0x38180000, 0x381c0000, 0x3820161c, 0x38242a3b, 0x38281230, 0x382c4460,
+	0x38301040, 0x38340080, 0x38380000, 0x383c0000, 0x3840fefe, 0x3844ee9f,
+	0x3848ee9f, 0x384cee9f, 0x3850ee9f, 0x38542a3b, 0x38581230, 0x385c0000,
+	0x38600000, 0x38640000, 0x38680000, 0x386c0000, 0x38700000, 0x38740000,
+	0x38780000, 0x387c0000, 0x30800000, 0x38840000, 0x38880000, 0x388c0000,
+	0x38900000, 0x38940000, 0x38980000, 0x389c0000, 0x38a00000, 0x38a40000,
+	0x38a80000, 0x38ac0000, 0x38b00000, 0x38b40000, 0x38b80000, 0x38bc0000,
+	0x38c00000, 0x38c40000, 0x38c80000, 0x38cc0000, 0x38d00000, 0x38d40000,
+	0x38d80000, 0x38dc0000, 0x38e00000, 0x38e40000, 0x38e80000, 0x38ec0000,
+	0x38f00000, 0x38f40000, 0x38f80000, 0x38fc0000,
 };
-static u32 v_gain[64] =
-{
-  0x016000ff, 0x016100ff, 0x016100ff, 0x016200ff, 0x016200ff, 0x016200ff,
-  0x016200ff, 0x016300ff, 0x016300ff, 0x016300ff, 0x016300ff, 0x016300ff,
-  0x016300ff, 0x016300ff, 0x016300ff, 0x016400ff, 0x016400ff, 0x016400ff,
-  0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
-  0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
-  0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
-  0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
-  0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
-  0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
-  0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
-  0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
+static u32 v_gain[64] = {
+	0x016000ff, 0x016100ff, 0x016100ff, 0x016200ff, 0x016200ff, 0x016200ff,
+	0x016200ff, 0x016300ff, 0x016300ff, 0x016300ff, 0x016300ff, 0x016300ff,
+	0x016300ff, 0x016300ff, 0x016300ff, 0x016400ff, 0x016400ff, 0x016400ff,
+	0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
+	0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
+	0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
+	0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
+	0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
+	0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
+	0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
+	0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
 };
 
-
 static void saa7146_set_winsize(struct saa7146 *saa)
 {
 	u32 format;
@@ -1209,24 +1171,23 @@
 	saawrite(saa->win.vidadr + saa->win.bpl * saa->win.sheight,
 		 SAA7146_PROT_ADDR1);
 	saawrite(0, SAA7146_PAGE1);
-	saawrite(format|0x60, SAA7146_CLIP_FORMAT_CTRL);
+	saawrite(format | 0x60, SAA7146_CLIP_FORMAT_CTRL);
 	offset = (704 / (saa->win.width - 1)) & 0x3f;
 	saawrite(h_prescale[offset], SAA7146_HPS_H_PRESCALE);
 	offset = (720896 / saa->win.width) / (offset + 1);
-	saawrite((offset<<12)|0x0c, SAA7146_HPS_H_SCALE);
+	saawrite((offset << 12) | 0x0c, SAA7146_HPS_H_SCALE);
 	if (CurrentMode == VIDEO_MODE_NTSC) {
-		yacl = /*(480 / saa->win.height - 1) & 0x3f*/ 0;
+		yacl = /*(480 / saa->win.height - 1) & 0x3f */ 0;
 		ysci = 1024 - (saa->win.height * 1024 / 480);
 	} else {
-		yacl = /*(576 / saa->win.height - 1) & 0x3f*/ 0;
+		yacl = /*(576 / saa->win.height - 1) & 0x3f */ 0;
 		ysci = 1024 - (saa->win.height * 1024 / 576);
 	}
-	saawrite((1<<31)|(ysci<<21)|(yacl<<15), SAA7146_HPS_V_SCALE);
+	saawrite((1 << 31) | (ysci << 21) | (yacl << 15), SAA7146_HPS_V_SCALE);
 	saawrite(v_gain[yacl], SAA7146_HPS_V_GAIN);
 	saawrite(((SAA7146_MC2_UPLD_DMA1 | SAA7146_MC2_UPLD_HPS_V |
-		   SAA7146_MC2_UPLD_HPS_H) << 16) | (SAA7146_MC2_UPLD_DMA1 |
-		   SAA7146_MC2_UPLD_HPS_V | SAA7146_MC2_UPLD_HPS_H),
-		   SAA7146_MC2);
+		SAA7146_MC2_UPLD_HPS_H) << 16) | (SAA7146_MC2_UPLD_DMA1 |
+		SAA7146_MC2_UPLD_HPS_V | SAA7146_MC2_UPLD_HPS_H), SAA7146_MC2);
 }
 
 /* clip_draw_rectangle(cm,x,y,w,h) -- handle clipping an area
@@ -1261,8 +1222,8 @@
 	startword = (x >> 5);
 	endword = ((x + w) >> 5);
 	bitsleft = (0xffffffff >> (x & 31));
-	bitsright = (0xffffffff << (~((x + w) - (endword<<5))));
-	temp = &clipmap[(y<<5) + startword];
+	bitsright = (0xffffffff << (~((x + w) - (endword << 5))));
+	temp = &clipmap[(y << 5) + startword];
 	w = endword - startword;
 	if (!w) {
 		bitsleft |= bitsright;
@@ -1287,13 +1248,13 @@
 	u32 *clipmap;
 
 	clipmap = saa->dmavid2;
-	if((width=saa->win.width)>1023)
-		width = 1023;		/* sanity check */
-	if((height=saa->win.height)>640)
-		height = 639;		/* sanity check */
-	if (ncr > 0) {	/* rectangles pased */
+	if ((width = saa->win.width) > 1023)
+		width = 1023;	/* sanity check */
+	if ((height = saa->win.height) > 640)
+		height = 639;	/* sanity check */
+	if (ncr > 0) {		/* rectangles pased */
 		/* convert rectangular clips to a bitmap */
-		memset(clipmap, 0, VIDEO_CLIPMAP_SIZE); /* clear map */
+		memset(clipmap, 0, VIDEO_CLIPMAP_SIZE);	/* clear map */
 		for (i = 0; i < ncr; i++)
 			clip_draw_rectangle(clipmap, cr[i].x, cr[i].y,
 				cr[i].width, cr[i].height);
@@ -1301,14 +1262,15 @@
 	/* clip against viewing window AND screen 
 	   so we do not have to rely on the user program
 	 */
-	clip_draw_rectangle(clipmap,(saa->win.x+width>saa->win.swidth) ?
-		(saa->win.swidth-saa->win.x) : width, 0, 1024, 768);
-	clip_draw_rectangle(clipmap,0,(saa->win.y+height>saa->win.sheight) ?
-		(saa->win.sheight-saa->win.y) : height,1024,768);
-	if (saa->win.x<0)
-		clip_draw_rectangle(clipmap, 0, 0, -(saa->win.x), 768);
-	if (saa->win.y<0)
-		clip_draw_rectangle(clipmap, 0, 0, 1024, -(saa->win.y));
+	clip_draw_rectangle(clipmap, (saa->win.x + width > saa->win.swidth) ?
+		(saa->win.swidth - saa->win.x) : width, 0, 1024, 768);
+	clip_draw_rectangle(clipmap, 0,
+		(saa->win.y + height > saa->win.sheight) ?
+		(saa->win.sheight - saa->win.y) : height, 1024, 768);
+	if (saa->win.x < 0)
+		clip_draw_rectangle(clipmap, 0, 0, -saa->win.x, 768);
+	if (saa->win.y < 0)
+		clip_draw_rectangle(clipmap, 0, 0, 1024, -saa->win.y);
 }
 
 static int saa_ioctl(struct inode *inode, struct file *file,
@@ -1322,11 +1284,9 @@
 		{
 			struct video_capability b;
 			strcpy(b.name, saa->video_dev.name);
-			b.type = VID_TYPE_CAPTURE |
-			    VID_TYPE_OVERLAY |
-			    VID_TYPE_CLIPPING |
-			    VID_TYPE_FRAMERAM |
-			    VID_TYPE_SCALES;
+			b.type = VID_TYPE_CAPTURE | VID_TYPE_OVERLAY |
+				VID_TYPE_CLIPPING | VID_TYPE_FRAMERAM |
+				VID_TYPE_SCALES;
 			b.channels = 1;
 			b.audios = 1;
 			b.maxwidth = 768;
@@ -1363,17 +1323,18 @@
 			if (p.palette < sizeof(palette2fmt) / sizeof(u32)) {
 				format = palette2fmt[p.palette];
 				saa->win.color_fmt = format;
-				saawrite(format|0x60, SAA7146_CLIP_FORMAT_CTRL);
+				saawrite(format | 0x60,
+					SAA7146_CLIP_FORMAT_CTRL);
 			}
 			saawrite(((p.brightness & 0xff00) << 16) |
-				 ((p.contrast & 0xfe00) << 7) |
-			     ((p.colour & 0xfe00) >> 9), SAA7146_BCS_CTRL);
+				((p.contrast & 0xfe00) << 7) |
+				((p.colour & 0xfe00) >> 9), SAA7146_BCS_CTRL);
 			saa->picture = p;
 			/* upload changed registers */
 			saawrite(((SAA7146_MC2_UPLD_HPS_H |
-				 SAA7146_MC2_UPLD_HPS_V) << 16) |
-				SAA7146_MC2_UPLD_HPS_H | SAA7146_MC2_UPLD_HPS_V,
-				 SAA7146_MC2);
+				SAA7146_MC2_UPLD_HPS_V) << 16) |
+				SAA7146_MC2_UPLD_HPS_H |
+				SAA7146_MC2_UPLD_HPS_V, SAA7146_MC2);
 			return 0;
 		}
 	case VIDIOCSWIN:
@@ -1384,11 +1345,14 @@
 			if (copy_from_user(&vw, arg, sizeof(vw)))
 				return -EFAULT;
 
-			if (vw.flags || vw.width < 16 || vw.height < 16) {	/* stop capture */
-				saawrite((SAA7146_MC1_TR_E_1 << 16), SAA7146_MC1);
+			/* stop capture */
+			if (vw.flags || vw.width < 16 || vw.height < 16) {
+				saawrite((SAA7146_MC1_TR_E_1 << 16),
+					SAA7146_MC1);
 				return -EINVAL;
 			}
-			if (saa->win.bpp < 4) {		/* 32-bit align start and adjust width */
+			/* 32-bit align start and adjust width */
+			if (saa->win.bpp < 4) {
 				int i = vw.x;
 				vw.x = (vw.x + 3) & ~3;
 				i = vw.x - i;
@@ -1417,23 +1381,24 @@
 			 */
 			if (vw.clipcount < 0) {
 				if (copy_from_user(saa->dmavid2, vw.clips,
-						   VIDEO_CLIPMAP_SIZE))
+						VIDEO_CLIPMAP_SIZE))
 					return -EFAULT;
-			}
-			else if (vw.clipcount > 16384) {
+			} else if (vw.clipcount > 16384) {
 				return -EINVAL;
 			} else if (vw.clipcount > 0) {
-				if ((vcp = vmalloc(sizeof(struct video_clip) *
-					        (vw.clipcount))) == NULL)
-					 return -ENOMEM;
+				vcp = vmalloc(sizeof(struct video_clip) *
+					vw.clipcount);
+				if (vcp == NULL)
+					return -ENOMEM;
 				if (copy_from_user(vcp, vw.clips,
-					      sizeof(struct video_clip) *
-						   vw.clipcount)) {
+						sizeof(struct video_clip) *
+						vw.clipcount)) {
 					vfree(vcp);
 					return -EFAULT;
 				}
 			} else	/* nothing clipped */
 				memset(saa->dmavid2, 0, VIDEO_CLIPMAP_SIZE);
+
 			make_clip_tab(saa, vcp, vw.clipcount);
 			if (vw.clipcount > 0)
 				vfree(vcp);
@@ -1466,21 +1431,21 @@
 			if (v == 0) {
 				saa->cap &= ~1;
 				saawrite((SAA7146_MC1_TR_E_1 << 16),
-					 SAA7146_MC1);
+					SAA7146_MC1);
 			} else {
 				if (saa->win.vidadr == 0 || saa->win.width == 0
-				    || saa->win.height == 0)
+						|| saa->win.height == 0)
 					return -EINVAL;
 				saa->cap |= 1;
 				saawrite((SAA7146_MC1_TR_E_1 << 16) | 0xffff,
-					 SAA7146_MC1);
+					SAA7146_MC1);
 			}
 			return 0;
 		}
 	case VIDIOCGFBUF:
 		{
 			struct video_buffer v;
-			v.base = (void *) saa->win.vidadr;
+			v.base = (void *)saa->win.vidadr;
 			v.height = saa->win.sheight;
 			v.width = saa->win.swidth;
 			v.depth = saa->win.depth;
@@ -1498,19 +1463,20 @@
 			if (copy_from_user(&v, arg, sizeof(v)))
 				return -EFAULT;
 			if (v.depth != 8 && v.depth != 15 && v.depth != 16 &&
-			v.depth != 24 && v.depth != 32 && v.width > 16 &&
+			    v.depth != 24 && v.depth != 32 && v.width > 16 &&
 			    v.height > 16 && v.bytesperline > 16)
 				return -EINVAL;
 			if (v.base)
-				saa->win.vidadr = (unsigned long) v.base;
+				saa->win.vidadr = (unsigned long)v.base;
 			saa->win.sheight = v.height;
 			saa->win.swidth = v.width;
 			saa->win.bpp = ((v.depth + 7) & 0x38) / 8;
 			saa->win.depth = v.depth;
 			saa->win.bpl = v.bytesperline;
 
-			DEBUG(printk("Display at %p is %d by %d, bytedepth %d, bpl %d\n",
-				     v.base, v.width, v.height, saa->win.bpp, saa->win.bpl));
+			DEBUG(printk("Display at %p is %d by %d, bytedepth %d, "
+					"bpl %d\n", v.base, v.width, v.height,
+					saa->win.bpp, saa->win.bpl));
 			saa7146_set_winsize(saa);
 			return 0;
 		}
@@ -1538,21 +1504,18 @@
 			int i;
 			if (copy_from_user(&v, arg, sizeof(v)))
 				return -EFAULT;
-			i = (~(v.volume>>8))&0xff;
+			i = (~(v.volume >> 8)) & 0xff;
 			if (!HaveCS4341) {
-				if (v.flags & VIDEO_AUDIO_MUTE) {
+				if (v.flags & VIDEO_AUDIO_MUTE)
 					debiwrite(saa, debNormal,
-						IBM_MP2_FRNT_ATTEN,
-						0xffff, 2);
-				}
+						IBM_MP2_FRNT_ATTEN, 0xffff, 2);
 				if (!(v.flags & VIDEO_AUDIO_MUTE))
 					debiwrite(saa, debNormal,
-						IBM_MP2_FRNT_ATTEN,
-						  0x0000, 2);
+						IBM_MP2_FRNT_ATTEN, 0x0000, 2);
 				if (v.flags & VIDEO_AUDIO_VOLUME)
 					debiwrite(saa, debNormal,
 						IBM_MP2_FRNT_ATTEN,
-						(i<<8)|i, 2);
+						(i << 8) | i, 2);
 			} else {
 				if (v.flags & VIDEO_AUDIO_MUTE)
 					cs4341_setlevel(saa, 0xff, 0xff);
@@ -1580,163 +1543,138 @@
 	case VIDIOCSPLAYMODE:
 		{
 			struct video_play_mode pmode;
-			if (copy_from_user((void *) &pmode, arg,
-				sizeof(struct video_play_mode)))
+			if (copy_from_user((void *)&pmode, arg,
+					sizeof(struct video_play_mode)))
 				return -EFAULT;
 			switch (pmode.mode) {
-				case VID_PLAY_VID_OUT_MODE:
-					if (pmode.p1 != VIDEO_MODE_NTSC &&
+			case VID_PLAY_VID_OUT_MODE:
+				if (pmode.p1 != VIDEO_MODE_NTSC &&
 						pmode.p1 != VIDEO_MODE_PAL)
+					return -EINVAL;
+				set_out_format(saa, pmode.p1);
+				return 0;
+			case VID_PLAY_GENLOCK:
+				debiwrite(saa, debNormal, XILINX_CTL0,
+					pmode.p1 ? 0x8000 : 0x8080, 2);
+				if (NewCard)
+					set_genlock_offset(saa, pmode.p2);
+				return 0;
+			case VID_PLAY_NORMAL:
+				debiwrite(saa, debNormal,
+					IBM_MP2_CHIP_CONTROL, ChipControl, 2);
+				ibm_send_command(saa, IBM_MP2_PLAY, 0, 0);
+				saa->playmode = pmode.mode;
+				return 0;
+			case VID_PLAY_PAUSE:
+				/* IBM removed the PAUSE command */
+				/* they say use SINGLE_FRAME now */
+			case VID_PLAY_SINGLE_FRAME:
+				ibm_send_command(saa, IBM_MP2_SINGLE_FRAME,0,0);
+				if (saa->playmode == pmode.mode) {
+					debiwrite(saa, debNormal,
+						IBM_MP2_CHIP_CONTROL,
+						ChipControl, 2);
+				}
+				saa->playmode = pmode.mode;
+				return 0;
+			case VID_PLAY_FAST_FORWARD:
+				ibm_send_command(saa, IBM_MP2_FAST_FORWARD,0,0);
+				saa->playmode = pmode.mode;
+				return 0;
+			case VID_PLAY_SLOW_MOTION:
+				ibm_send_command(saa, IBM_MP2_SLOW_MOTION,
+					pmode.p1, 0);
+				saa->playmode = pmode.mode;
+				return 0;
+			case VID_PLAY_IMMEDIATE_NORMAL:
+				/* ensure transfers resume */
+				debiwrite(saa, debNormal,
+					IBM_MP2_CHIP_CONTROL, ChipControl, 2);
+				ibm_send_command(saa, IBM_MP2_IMED_NORM_PLAY,
+					0, 0);
+				saa->playmode = VID_PLAY_NORMAL;
+				return 0;
+			case VID_PLAY_SWITCH_CHANNELS:
+				saa->audhead = saa->audtail = 0;
+				saa->vidhead = saa->vidtail = 0;
+				ibm_send_command(saa, IBM_MP2_FREEZE_FRAME,0,1);
+				ibm_send_command(saa, IBM_MP2_RESET_AUD_RATE,
+					0, 1);
+				debiwrite(saa, debNormal, IBM_MP2_CHIP_CONTROL,
+					0, 2);
+				ibm_send_command(saa, IBM_MP2_CHANNEL_SWITCH,
+					0, 1);
+				debiwrite(saa, debNormal, IBM_MP2_CHIP_CONTROL,
+					ChipControl, 2);
+				ibm_send_command(saa, IBM_MP2_PLAY, 0, 0);
+				saa->playmode = VID_PLAY_NORMAL;
+				return 0;
+			case VID_PLAY_FREEZE_FRAME:
+				ibm_send_command(saa, IBM_MP2_FREEZE_FRAME,0,0);
+				saa->playmode = pmode.mode;
+				return 0;
+			case VID_PLAY_STILL_MODE:
+				ibm_send_command(saa, IBM_MP2_SET_STILL_MODE,
+					0, 0);
+				saa->playmode = pmode.mode;
+				return 0;
+			case VID_PLAY_MASTER_MODE:
+				if (pmode.p1 == VID_PLAY_MASTER_NONE)
+					saa->boardcfg[1] = 0x13;
+				else if (pmode.p1 == VID_PLAY_MASTER_VIDEO)
+					saa->boardcfg[1] = 0x23;
+				else if (pmode.p1 == VID_PLAY_MASTER_AUDIO)
+					saa->boardcfg[1] = 0x43;
+				else
+					return -EINVAL;
+				debiwrite(saa, debNormal,
+					  IBM_MP2_CHIP_CONTROL, ChipControl, 2);
+				return 0;
+			case VID_PLAY_ACTIVE_SCANLINES:
+				if (CurrentMode == VIDEO_MODE_PAL) {
+					if (pmode.p1 < 1 || pmode.p2 > 625)
 						return -EINVAL;
-					set_out_format(saa, pmode.p1);
-					return 0;
-				case VID_PLAY_GENLOCK:
-					debiwrite(saa, debNormal,
-						  XILINX_CTL0,
-						  (pmode.p1 ? 0x8000 : 0x8080),
-						  2);
-					if (NewCard)
-						set_genlock_offset(saa,
-							pmode.p2);
-					return 0;
-				case VID_PLAY_NORMAL:
-					debiwrite(saa, debNormal,
-						IBM_MP2_CHIP_CONTROL,
-						ChipControl, 2);
-					ibm_send_command(saa,
-						IBM_MP2_PLAY, 0, 0);
-					saa->playmode = pmode.mode;
-					return 0;
-				case VID_PLAY_PAUSE:
-					/* IBM removed the PAUSE command */
-					/* they say use SINGLE_FRAME now */
-				case VID_PLAY_SINGLE_FRAME:
-					ibm_send_command(saa,
-							IBM_MP2_SINGLE_FRAME,
-							0, 0);
-					if (saa->playmode == pmode.mode) {
-						debiwrite(saa, debNormal,
-							IBM_MP2_CHIP_CONTROL,
-							ChipControl, 2);
-					}
-					saa->playmode = pmode.mode;
-					return 0;
-				case VID_PLAY_FAST_FORWARD:
-					ibm_send_command(saa,
-						IBM_MP2_FAST_FORWARD, 0, 0);
-					saa->playmode = pmode.mode;
-					return 0;
-				case VID_PLAY_SLOW_MOTION:
-					ibm_send_command(saa,
-						IBM_MP2_SLOW_MOTION,
-						pmode.p1, 0);
-					saa->playmode = pmode.mode;
-					return 0;
-				case VID_PLAY_IMMEDIATE_NORMAL:
-					/* ensure transfers resume */
-					debiwrite(saa, debNormal,
-						IBM_MP2_CHIP_CONTROL,
-						ChipControl, 2);
-					ibm_send_command(saa,
-						IBM_MP2_IMED_NORM_PLAY, 0, 0);
-					saa->playmode = VID_PLAY_NORMAL;
-					return 0;
-				case VID_PLAY_SWITCH_CHANNELS:
-					saa->audhead = saa->audtail = 0;
-					saa->vidhead = saa->vidtail = 0;
-					ibm_send_command(saa,
-						IBM_MP2_FREEZE_FRAME, 0, 1);
-					ibm_send_command(saa,
-						IBM_MP2_RESET_AUD_RATE, 0, 1);
-					debiwrite(saa, debNormal,
-						IBM_MP2_CHIP_CONTROL, 0, 2);
-					ibm_send_command(saa,
-						IBM_MP2_CHANNEL_SWITCH, 0, 1);
-					debiwrite(saa, debNormal,
-						IBM_MP2_CHIP_CONTROL,
-						ChipControl, 2);
-					ibm_send_command(saa,
-						IBM_MP2_PLAY, 0, 0);
-					saa->playmode = VID_PLAY_NORMAL;
-					return 0;
-				case VID_PLAY_FREEZE_FRAME:
-					ibm_send_command(saa,
-						IBM_MP2_FREEZE_FRAME, 0, 0);
-					saa->playmode = pmode.mode;
-					return 0;
-				case VID_PLAY_STILL_MODE:
-					ibm_send_command(saa,
-						IBM_MP2_SET_STILL_MODE, 0, 0);
-					saa->playmode = pmode.mode;
-					return 0;
-				case VID_PLAY_MASTER_MODE:
-					if (pmode.p1 == VID_PLAY_MASTER_NONE)
-						saa->boardcfg[1] = 0x13;
-					else if (pmode.p1 ==
-						VID_PLAY_MASTER_VIDEO)
-						saa->boardcfg[1] = 0x23;
-					else if (pmode.p1 ==
-						VID_PLAY_MASTER_AUDIO)
-						saa->boardcfg[1] = 0x43;
-					else
+					saa->boardcfg[5] = pmode.p1;
+					saa->boardcfg[55] = (pmode.p1 +
+						(pmode.p2 / 2) - 1) & 0xff;
+				} else {
+					if (pmode.p1 < 4 || pmode.p2 > 525)
 						return -EINVAL;
-					debiwrite(saa, debNormal,
-						IBM_MP2_CHIP_CONTROL,
-						ChipControl, 2);
-					return 0;
-				case VID_PLAY_ACTIVE_SCANLINES:
-					if (CurrentMode == VIDEO_MODE_PAL) {
-						if (pmode.p1 < 1 ||
-							pmode.p2 > 625)
-							return -EINVAL;
-						saa->boardcfg[5] = pmode.p1;
-						saa->boardcfg[55] = (pmode.p1 +
-							(pmode.p2/2) - 1) &	
-							0xff;
-					} else {
-						if (pmode.p1 < 4 ||
-							pmode.p2 > 525)
-							return -EINVAL;
-						saa->boardcfg[4] = pmode.p1;
-						saa->boardcfg[54] = (pmode.p1 +
-							(pmode.p2/2) - 4) &
-							0xff;
-					}
-					set_out_format(saa, CurrentMode);
-				case VID_PLAY_RESET:
-					return do_ibm_reset(saa);
-				case VID_PLAY_END_MARK:
-					if (saa->endmarktail <  
-						saa->endmarkhead) {
-						if (saa->endmarkhead -
+					saa->boardcfg[4] = pmode.p1;
+					saa->boardcfg[54] = (pmode.p1 +
+						(pmode.p2 / 2) - 4) & 0xff;
+				}
+				set_out_format(saa, CurrentMode);
+			case VID_PLAY_RESET:
+				return do_ibm_reset(saa);
+			case VID_PLAY_END_MARK:
+				if (saa->endmarktail < saa->endmarkhead) {
+					if (saa->endmarkhead -
 							saa->endmarktail < 2)
-							return -ENOSPC;
-					} else if (saa->endmarkhead <=
-						saa->endmarktail) {
-						if (saa->endmarktail -
-							saa->endmarkhead >
-							(MAX_MARKS - 2))
-							return -ENOSPC;
-					} else
 						return -ENOSPC;
-					saa->endmark[saa->endmarktail] =
-						saa->audtail;
-					saa->endmarktail++;
-					if (saa->endmarktail >= MAX_MARKS)
-						saa->endmarktail = 0;
+				} else if (saa->endmarkhead <=saa->endmarktail){
+					if (saa->endmarktail - saa->endmarkhead
+							> (MAX_MARKS - 2))
+						return -ENOSPC;
+				} else
+					return -ENOSPC;
+				saa->endmark[saa->endmarktail] = saa->audtail;
+				saa->endmarktail++;
+				if (saa->endmarktail >= MAX_MARKS)
+					saa->endmarktail = 0;
 			}
 			return -EINVAL;
 		}
 	case VIDIOCSWRITEMODE:
 		{
 			int mode;
-			if (copy_from_user((void *) &mode, arg, sizeof(int)))
-				 return -EFAULT;
+			if (copy_from_user((void *)&mode, arg, sizeof(int)))
+				return -EFAULT;
 			if (mode == VID_WRITE_MPEG_AUD ||
-			    mode == VID_WRITE_MPEG_VID ||
-			    mode == VID_WRITE_CC ||
-			    mode == VID_WRITE_TTX ||
-			    mode == VID_WRITE_OSD) {
+					mode == VID_WRITE_MPEG_VID ||
+					mode == VID_WRITE_CC ||
+					mode == VID_WRITE_TTX ||
+					mode == VID_WRITE_OSD) {
 				saa->writemode = mode;
 				return 0;
 			}
@@ -1750,7 +1688,7 @@
 			if (copy_from_user(&ucode, arg, sizeof(ucode)))
 				return -EFAULT;
 			if (ucode.datasize > 65536 || ucode.datasize < 1024 ||
-			    strncmp(ucode.loadwhat, "dec", 3))
+					strncmp(ucode.loadwhat, "dec", 3))
 				return -EINVAL;
 			if ((udata = vmalloc(ucode.datasize)) == NULL)
 				return -ENOMEM;
@@ -1759,8 +1697,8 @@
 				return -EFAULT;
 			}
 			ucode.data = udata;
-			if (!strncmp(ucode.loadwhat, "decoder.aud", 11)
-				|| !strncmp(ucode.loadwhat, "decoder.vid", 11))
+			if (!strncmp(ucode.loadwhat, "decoder.aud", 11) ||
+				!strncmp(ucode.loadwhat, "decoder.vid", 11))
 				i = initialize_ibmmpeg2(&ucode);
 			else
 				i = initialize_fpga(&ucode);
@@ -1805,14 +1743,14 @@
 	return -EINVAL;
 }
 
-static ssize_t saa_read(struct file *file, char __user *buf,
-			size_t count, loff_t *ppos)
+static ssize_t saa_read(struct file *file, char __user * buf,
+	size_t count, loff_t * ppos)
 {
 	return -EINVAL;
 }
 
-static ssize_t saa_write(struct file *file, const char __user *buf,
-			 size_t count, loff_t *ppos)
+static ssize_t saa_write(struct file *file, const char __user * buf,
+	size_t count, loff_t * ppos)
 {
 	struct saa7146 *saa = file->private_data;
 	unsigned long todo = count;
@@ -1823,20 +1761,22 @@
 		if (saa->writemode == VID_WRITE_MPEG_AUD) {
 			spin_lock_irqsave(&saa->lock, flags);
 			if (saa->audhead <= saa->audtail)
-				blocksize = 65536-(saa->audtail - saa->audhead);
+				blocksize = 65536 -
+					(saa->audtail - saa->audhead);
 			else
 				blocksize = saa->audhead - saa->audtail;
 			spin_unlock_irqrestore(&saa->lock, flags);
 			if (blocksize < 16384) {
 				saawrite(SAA7146_PSR_DEBI_S |
-					 SAA7146_PSR_PIN1, SAA7146_IER);
+					SAA7146_PSR_PIN1, SAA7146_IER);
 				saawrite(SAA7146_PSR_PIN1, SAA7146_PSR);
 				/* wait for buffer space to open */
 				interruptible_sleep_on(&saa->audq);
 			}
 			spin_lock_irqsave(&saa->lock, flags);
 			if (saa->audhead <= saa->audtail) {
-				blocksize = 65536-(saa->audtail - saa->audhead);
+				blocksize = 65536 -
+					(saa->audtail - saa->audhead);
 				split = 65536 - saa->audtail;
 			} else {
 				blocksize = saa->audhead - saa->audtail;
@@ -1851,7 +1791,7 @@
 				return -ENOSPC;
 			if (split < blocksize) {
 				if (copy_from_user(saa->audbuf +
-					saa->audtail, buf, split)) 
+						saa->audtail, buf, split))
 					return -EFAULT;
 				buf += split;
 				todo -= split;
@@ -1859,7 +1799,7 @@
 				saa->audtail = 0;
 			}
 			if (copy_from_user(saa->audbuf + saa->audtail, buf,
-				blocksize)) 
+					blocksize))
 				return -EFAULT;
 			saa->audtail += blocksize;
 			todo -= blocksize;
@@ -1868,20 +1808,22 @@
 		} else if (saa->writemode == VID_WRITE_MPEG_VID) {
 			spin_lock_irqsave(&saa->lock, flags);
 			if (saa->vidhead <= saa->vidtail)
-				blocksize=524288-(saa->vidtail - saa->vidhead);
+				blocksize = 524288 -
+					(saa->vidtail - saa->vidhead);
 			else
 				blocksize = saa->vidhead - saa->vidtail;
 			spin_unlock_irqrestore(&saa->lock, flags);
 			if (blocksize < 65536) {
 				saawrite(SAA7146_PSR_DEBI_S |
-					 SAA7146_PSR_PIN1, SAA7146_IER);
+					SAA7146_PSR_PIN1, SAA7146_IER);
 				saawrite(SAA7146_PSR_PIN1, SAA7146_PSR);
 				/* wait for buffer space to open */
 				interruptible_sleep_on(&saa->vidq);
 			}
 			spin_lock_irqsave(&saa->lock, flags);
 			if (saa->vidhead <= saa->vidtail) {
-				blocksize=524288-(saa->vidtail - saa->vidhead);
+				blocksize = 524288 -
+					(saa->vidtail - saa->vidhead);
 				split = 524288 - saa->vidtail;
 			} else {
 				blocksize = saa->vidhead - saa->vidtail;
@@ -1896,7 +1838,7 @@
 				return -ENOSPC;
 			if (split < blocksize) {
 				if (copy_from_user(saa->vidbuf +
-					saa->vidtail, buf, split)) 
+						saa->vidtail, buf, split))
 					return -EFAULT;
 				buf += split;
 				todo -= split;
@@ -1904,7 +1846,7 @@
 				saa->vidtail = 0;
 			}
 			if (copy_from_user(saa->vidbuf + saa->vidtail, buf,
-				blocksize)) 
+					blocksize))
 				return -EFAULT;
 			saa->vidtail += blocksize;
 			todo -= blocksize;
@@ -1922,8 +1864,8 @@
 			debiwrite(saa, debNormal, IBM_MP2_OSD_LINK_ADDR, 0, 2);
 			debiwrite(saa, debNormal, IBM_MP2_MASK0, 0xc00d, 2);
 			debiwrite(saa, debNormal, IBM_MP2_DISP_MODE,
-				  debiread(saa, debNormal,
-				  IBM_MP2_DISP_MODE, 2) | 1, 2);
+				debiread(saa, debNormal,
+					IBM_MP2_DISP_MODE, 2) | 1, 2);
 			/* trigger osd data transfer */
 			saawrite(SAA7146_PSR_DEBI_S |
 				 SAA7146_PSR_PIN1, SAA7146_IER);
@@ -1935,21 +1877,11 @@
 
 static int saa_open(struct inode *inode, struct file *file)
 {
-	struct saa7146 *saa = NULL;
-	unsigned int minor = iminor(inode);
-	int i;
+	struct video_device *vdev = video_devdata(file);
+	struct saa7146 *saa = container_of(vdev, struct saa7146, video_dev);
 
-	for (i = 0; i < SAA7146_MAX; i++) {
-		if (saa7146s[i].video_dev.minor == minor) {
-			saa = &saa7146s[i];
-		}
-	}
-	if (saa == NULL) {
-		return -ENODEV;
-	}
 	file->private_data = saa;
 
-	//saa->video_dev.busy = 0; /* old hack to support multiple open */
 	saa->user++;
 	if (saa->user > 1)
 		return 0;	/* device open already, don't reset */
@@ -1961,43 +1893,39 @@
 {
 	struct saa7146 *saa = file->private_data;
 	saa->user--;
-	//saa->video_dev.busy = 0; /* old hack to support multiple open */
+
 	if (saa->user > 0)	/* still someone using device */
 		return 0;
 	saawrite(0x007f0000, SAA7146_MC1);	/* stop all overlay dma */
 	return 0;
 }
 
-static struct file_operations saa_fops =
-{
-	.owner		= THIS_MODULE,
-	.open		= saa_open,
-	.release	= saa_release,
-	.ioctl		= saa_ioctl,
-	.compat_ioctl	= v4l_compat_ioctl32,
-	.read		= saa_read,
-	.llseek		= no_llseek,
-	.write		= saa_write,
-	.mmap		= saa_mmap,
+static struct file_operations saa_fops = {
+	.owner = THIS_MODULE,
+	.open = saa_open,
+	.release = saa_release,
+	.ioctl = saa_ioctl,
+	.compat_ioctl = v4l_compat_ioctl32,
+	.read = saa_read,
+	.llseek = no_llseek,
+	.write = saa_write,
+	.mmap = saa_mmap,
 };
 
 /* template for video_device-structure */
-static struct video_device saa_template =
-{
-	.name		= "SAA7146A",
-	.type		= VID_TYPE_CAPTURE | VID_TYPE_OVERLAY,
-	.hardware	= VID_HARDWARE_SAA7146,
-	.fops		= &saa_fops,
-	.minor		= -1,
+static struct video_device saa_template = {
+	.name = "SAA7146A",
+	.type = VID_TYPE_CAPTURE | VID_TYPE_OVERLAY,
+	.hardware = VID_HARDWARE_SAA7146,
+	.fops = &saa_fops,
+	.minor = -1,
 };
 
-static int configure_saa7146(struct pci_dev *dev, int num)
+static int __devinit configure_saa7146(struct pci_dev *pdev, int num)
 {
-	int result;
-	struct saa7146 *saa;
+	int retval;
+	struct saa7146 *saa = pci_get_drvdata(pdev);
 
-	saa = &saa7146s[num];
-	
 	saa->endmarkhead = saa->endmarktail = 0;
 	saa->win.x = saa->win.y = 0;
 	saa->win.width = saa->win.cropwidth = 720;
@@ -2013,7 +1941,6 @@
 	saa->picture.contrast = 38768;
 	saa->picture.colour = 32768;
 	saa->cap = 0;
-	saa->dev = dev;
 	saa->nr = num;
 	saa->playmode = VID_PLAY_NORMAL;
 	memset(saa->boardcfg, 0, 64);	/* clear board config area */
@@ -2033,45 +1960,59 @@
 	init_waitqueue_head(&saa->vidq);
 	spin_lock_init(&saa->lock);
 
-	if (pci_enable_device(dev))
-		return -EIO;
-	
-	saa->id = dev->device;
-	saa->irq = dev->irq;
+	retval = pci_enable_device(pdev);
+	if (retval) {
+		dev_err(&pdev->dev, "%d: pci_enable_device failed!\n", num);
+		goto err;
+	}
+
+	saa->id = pdev->device;
+	saa->irq = pdev->irq;
 	saa->video_dev.minor = -1;
-	saa->saa7146_adr = pci_resource_start(dev, 0);
-	pci_read_config_byte(dev, PCI_CLASS_REVISION, &saa->revision);
+	saa->saa7146_adr = pci_resource_start(pdev, 0);
+	pci_read_config_byte(pdev, PCI_CLASS_REVISION, &saa->revision);
 
 	saa->saa7146_mem = ioremap(saa->saa7146_adr, 0x200);
-	if (!saa->saa7146_mem)
-		return -EIO;
+	if (saa->saa7146_mem == NULL) {
+		dev_err(&pdev->dev, "%d: ioremap failed!\n", num);
+		retval = -EIO;
+		goto err;
+	}
 
 	memcpy(&saa->video_dev, &saa_template, sizeof(saa_template));
 	saawrite(0, SAA7146_IER);	/* turn off all interrupts */
-	result = request_irq(saa->irq, saa7146_irq,
-		       SA_SHIRQ | SA_INTERRUPT, "stradis", (void *) saa);
-	if (result == -EINVAL)
-		printk(KERN_ERR "stradis%d: Bad irq number or handler\n",
-		       num);
-	if (result == -EBUSY)
-		printk(KERN_ERR "stradis%d: IRQ %ld busy, change your PnP"
-		       " config in BIOS\n", num, saa->irq);
-	if (result < 0) {
-		iounmap(saa->saa7146_mem);
-		return result;
+
+	retval = request_irq(saa->irq, saa7146_irq, SA_SHIRQ | SA_INTERRUPT,
+		"stradis", saa);
+	if (retval == -EINVAL)
+		dev_err(&pdev->dev, "%d: Bad irq number or handler\n", num);
+	else if (retval == -EBUSY)
+		dev_err(&pdev->dev, "%d: IRQ %ld busy, change your PnP config "
+			"in BIOS\n", num, saa->irq);
+	if (retval < 0)
+		goto errio;
+
+	pci_set_master(pdev);
+	retval = video_register_device(&saa->video_dev, VFL_TYPE_GRABBER,
+		video_nr);
+	if (retval < 0) {
+		dev_err(&pdev->dev, "%d: error in registering video device!\n",
+			num);
+		goto errio;
 	}
-	pci_set_master(dev);
-	if (video_register_device(&saa->video_dev, VFL_TYPE_GRABBER, video_nr) < 0) {
-		iounmap(saa->saa7146_mem);
-		return -1;
-	}
+
 	return 0;
+errio:
+	iounmap(saa->saa7146_mem);
+err:
+	return retval;
 }
 
-static int init_saa7146(int i)
+static int __devinit init_saa7146(struct pci_dev *pdev)
 {
-	struct saa7146 *saa = &saa7146s[i];
+	struct saa7146 *saa = pci_get_drvdata(pdev);
 
+	memset(saa, 0, sizeof(*saa));
 	saa->user = 0;
 	/* reset the saa7146 */
 	saawrite(0xffff0000, SAA7146_MC1);
@@ -2089,23 +2030,23 @@
 	saawrite(0x00000000, SAA7146_DD1_STREAM_A);
 	saawrite(0x00000000, SAA7146_BRS_CTRL);
 	saawrite(0x80400040, SAA7146_BCS_CTRL);
-	saawrite(0x0000e000 /*| (1<<29)*/, SAA7146_HPS_CTRL);
+	saawrite(0x0000e000 /*| (1<<29) */ , SAA7146_HPS_CTRL);
 	saawrite(0x00000060, SAA7146_CLIP_FORMAT_CTRL);
 	saawrite(0x00000000, SAA7146_ACON1);
 	saawrite(0x00000000, SAA7146_ACON2);
 	saawrite(0x00000600, SAA7146_I2C_STATUS);
 	saawrite(((SAA7146_MC2_UPLD_D1_B | SAA7146_MC2_UPLD_D1_A |
-		   SAA7146_MC2_UPLD_BRS | SAA7146_MC2_UPLD_HPS_H |
-		   SAA7146_MC2_UPLD_HPS_V | SAA7146_MC2_UPLD_DMA2 |
-	   SAA7146_MC2_UPLD_DMA1 | SAA7146_MC2_UPLD_I2C) << 16) | 0xffff,
-		 SAA7146_MC2);
+		SAA7146_MC2_UPLD_BRS | SAA7146_MC2_UPLD_HPS_H |
+		SAA7146_MC2_UPLD_HPS_V | SAA7146_MC2_UPLD_DMA2 |
+		SAA7146_MC2_UPLD_DMA1 | SAA7146_MC2_UPLD_I2C) << 16) | 0xffff,
+		SAA7146_MC2);
 	/* setup arbitration control registers */
 	saawrite(0x1412121a, SAA7146_PCI_BT_V1);
 
 	/* allocate 32k dma buffer + 4k for page table */
 	if ((saa->dmadebi = kmalloc(32768 + 4096, GFP_KERNEL)) == NULL) {
-		printk(KERN_ERR "stradis%d: debi kmalloc failed\n", i);
-		return -1;
+		dev_err(&pdev->dev, "%d: debi kmalloc failed\n", saa->nr);
+		goto err;
 	}
 #if 0
 	saa->pagedebi = saa->dmadebi + 32768;	/* top 4k is for mmu */
@@ -2115,133 +2056,162 @@
 #endif
 	saa->audhead = saa->vidhead = saa->osdhead = 0;
 	saa->audtail = saa->vidtail = saa->osdtail = 0;
-	if (saa->vidbuf == NULL)
-		if ((saa->vidbuf = vmalloc(524288)) == NULL) {
-			printk(KERN_ERR "stradis%d: malloc failed\n", saa->nr);
-			return -ENOMEM;
-		}
-	if (saa->audbuf == NULL)
-		if ((saa->audbuf = vmalloc(65536)) == NULL) {
-			printk(KERN_ERR "stradis%d: malloc failed\n", saa->nr);
-			vfree(saa->vidbuf);
-			saa->vidbuf = NULL;
-			return -ENOMEM;
-		}
-	if (saa->osdbuf == NULL)
-		if ((saa->osdbuf = vmalloc(131072)) == NULL) {
-			printk(KERN_ERR "stradis%d: malloc failed\n", saa->nr);
-			vfree(saa->vidbuf);
-			vfree(saa->audbuf);
-			saa->vidbuf = saa->audbuf = NULL;
-			return -ENOMEM;
-		}
-	/* allocate 81920 byte buffer for clipping */
-	if ((saa->dmavid2 = kmalloc(VIDEO_CLIPMAP_SIZE, GFP_KERNEL)) == NULL) {
-		printk(KERN_ERR "stradis%d: clip kmalloc failed\n", saa->nr);
-		vfree(saa->vidbuf);
-		vfree(saa->audbuf);
-		vfree(saa->osdbuf);
-		saa->vidbuf = saa->audbuf = saa->osdbuf = NULL;
-		saa->dmavid2 = NULL;
-		return -1;
+	if (saa->vidbuf == NULL && (saa->vidbuf = vmalloc(524288)) == NULL) {
+		dev_err(&pdev->dev, "%d: malloc failed\n", saa->nr);
+		goto err;
 	}
-	memset(saa->dmavid2, 0x00, VIDEO_CLIPMAP_SIZE);	/* clip everything */
+	if (saa->audbuf == NULL && (saa->audbuf = vmalloc(65536)) == NULL) {
+		dev_err(&pdev->dev, "%d: malloc failed\n", saa->nr);
+		goto errvid;
+	}
+	if (saa->osdbuf == NULL && (saa->osdbuf = vmalloc(131072)) == NULL) {
+		dev_err(&pdev->dev, "%d: malloc failed\n", saa->nr);
+		goto erraud;
+	}
+	/* allocate 81920 byte buffer for clipping */
+	if ((saa->dmavid2 = kzalloc(VIDEO_CLIPMAP_SIZE, GFP_KERNEL)) == NULL) {
+		dev_err(&pdev->dev, "%d: clip kmalloc failed\n", saa->nr);
+		goto errosd;
+	}
 	/* setup clipping registers */
 	saawrite(virt_to_bus(saa->dmavid2), SAA7146_BASE_EVEN2);
 	saawrite(virt_to_bus(saa->dmavid2) + 128, SAA7146_BASE_ODD2);
 	saawrite(virt_to_bus(saa->dmavid2) + VIDEO_CLIPMAP_SIZE,
-		SAA7146_PROT_ADDR2);
+		 SAA7146_PROT_ADDR2);
 	saawrite(256, SAA7146_PITCH2);
-	saawrite(4, SAA7146_PAGE2); /* dma direction: read, no byteswap */
+	saawrite(4, SAA7146_PAGE2);	/* dma direction: read, no byteswap */
 	saawrite(((SAA7146_MC2_UPLD_DMA2) << 16) | SAA7146_MC2_UPLD_DMA2,
 		 SAA7146_MC2);
 	I2CBusScan(saa);
+
 	return 0;
+errosd:
+	vfree(saa->osdbuf);
+	saa->osdbuf = NULL;
+erraud:
+	vfree(saa->audbuf);
+	saa->audbuf = NULL;
+errvid:
+	vfree(saa->vidbuf);
+	saa->vidbuf = NULL;
+err:
+	return -ENOMEM;
 }
 
-static void release_saa(void)
+static void stradis_release_saa(struct pci_dev *pdev)
 {
 	u8 command;
-	int i;
-	struct saa7146 *saa;
+	struct saa7146 *saa = pci_get_drvdata(pdev);
 
-	for (i = 0; i < saa_num; i++) {
-		saa = &saa7146s[i];
+	/* turn off all capturing, DMA and IRQs */
+	saawrite(0xffff0000, SAA7146_MC1);	/* reset chip */
+	saawrite(0, SAA7146_MC2);
+	saawrite(0, SAA7146_IER);
+	saawrite(0xffffffffUL, SAA7146_ISR);
 
-		/* turn off all capturing, DMA and IRQs */
-		saawrite(0xffff0000, SAA7146_MC1);	/* reset chip */
-		saawrite(0, SAA7146_MC2);
-		saawrite(0, SAA7146_IER);
-		saawrite(0xffffffffUL, SAA7146_ISR);
+	/* disable PCI bus-mastering */
+	pci_read_config_byte(pdev, PCI_COMMAND, &command);
+	command &= ~PCI_COMMAND_MASTER;
+	pci_write_config_byte(pdev, PCI_COMMAND, command);
 
-		/* disable PCI bus-mastering */
-		pci_read_config_byte(saa->dev, PCI_COMMAND, &command);
-		command &= ~PCI_COMMAND_MASTER;
-		pci_write_config_byte(saa->dev, PCI_COMMAND, command);
-
-		/* unmap and free memory */
-		saa->audhead = saa->audtail = saa->osdhead = 0;
-		saa->vidhead = saa->vidtail = saa->osdtail = 0;
-		vfree(saa->vidbuf);
-		vfree(saa->audbuf);
-		vfree(saa->osdbuf);
-		kfree(saa->dmavid2);
-		saa->audbuf = saa->vidbuf = saa->osdbuf = NULL;
-		saa->dmavid2 = NULL;
-		kfree(saa->dmadebi);
-		kfree(saa->dmavid1);
-		kfree(saa->dmavid3);
-		kfree(saa->dmaa1in);
-		kfree(saa->dmaa1out);
-		kfree(saa->dmaa2in);
-		kfree(saa->dmaa2out);
-		kfree(saa->dmaRPS1);
-		kfree(saa->dmaRPS2);
-		free_irq(saa->irq, saa);
-		if (saa->saa7146_mem)
-			iounmap(saa->saa7146_mem);
-		if (saa->video_dev.minor != -1)
-			video_unregister_device(&saa->video_dev);
-	}
+	/* unmap and free memory */
+	saa->audhead = saa->audtail = saa->osdhead = 0;
+	saa->vidhead = saa->vidtail = saa->osdtail = 0;
+	vfree(saa->vidbuf);
+	vfree(saa->audbuf);
+	vfree(saa->osdbuf);
+	kfree(saa->dmavid2);
+	saa->audbuf = saa->vidbuf = saa->osdbuf = NULL;
+	saa->dmavid2 = NULL;
+	kfree(saa->dmadebi);
+	kfree(saa->dmavid1);
+	kfree(saa->dmavid3);
+	kfree(saa->dmaa1in);
+	kfree(saa->dmaa1out);
+	kfree(saa->dmaa2in);
+	kfree(saa->dmaa2out);
+	kfree(saa->dmaRPS1);
+	kfree(saa->dmaRPS2);
+	free_irq(saa->irq, saa);
+	if (saa->saa7146_mem)
+		iounmap(saa->saa7146_mem);
+	if (saa->video_dev.minor != -1)
+		video_unregister_device(&saa->video_dev);
 }
 
-
-static int __init stradis_init (void)
+static int __devinit stradis_probe(struct pci_dev *pdev,
+	const struct pci_device_id *ent)
 {
-	struct pci_dev *dev = NULL;
-	int result = 0, i;
+	int retval = -EINVAL;
+
+	if (saa_num >= SAA7146_MAX)
+		goto err;
+
+	if (!pdev->subsystem_vendor)
+		dev_info(&pdev->dev, "%d: rev1 decoder\n", saa_num);
+	else
+		dev_info(&pdev->dev, "%d: SDM2xx found\n", saa_num);
+
+	pci_set_drvdata(pdev, &saa7146s[saa_num]);
+
+	retval = configure_saa7146(pdev, saa_num);
+	if (retval) {
+		dev_err(&pdev->dev, "%d: error in configuring\n", saa_num);
+		goto err;
+	}
+
+	if (init_saa7146(pdev) < 0) {
+		dev_err(&pdev->dev, "%d: error in initialization\n", saa_num);
+		retval = -EIO;
+		goto errrel;
+	}
+
+	saa_num++;
+
+	return 0;
+errrel:
+	stradis_release_saa(pdev);
+err:
+	return retval;
+}
+
+static void __devexit stradis_remove(struct pci_dev *pdev)
+{
+	stradis_release_saa(pdev);
+}
+
+static struct pci_device_id stradis_pci_tbl[] = {
+	{ PCI_DEVICE(PCI_VENDOR_ID_PHILIPS, PCI_DEVICE_ID_PHILIPS_SAA7146) },
+	{ 0 }
+};
+
+MODULE_DEVICE_TABLE(pci, stradis_pci_tbl);
+
+static struct pci_driver stradis_driver = {
+	.name = "stradis",
+	.id_table = stradis_pci_tbl,
+	.probe = stradis_probe,
+	.remove = __devexit_p(stradis_remove)
+};
+
+int __init stradis_init(void)
+{
+	int retval;
 
 	saa_num = 0;
 
-	while ((dev = pci_find_device(PCI_VENDOR_ID_PHILIPS, PCI_DEVICE_ID_PHILIPS_SAA7146, dev))) {
-		if (!dev->subsystem_vendor)
-			printk(KERN_INFO "stradis%d: rev1 decoder\n", saa_num);
-		else
-			printk(KERN_INFO "stradis%d: SDM2xx found\n", saa_num); 
-		result = configure_saa7146(dev, saa_num++);
-		if (result)
-			return result;
-	}
-	if (saa_num)
-		printk(KERN_INFO "stradis: %d card(s) found.\n", saa_num);
-	else
-		return -EINVAL;
-	for (i = 0; i < saa_num; i++)
-		if (init_saa7146(i) < 0) {
-			release_saa();
-			return -EIO;
-		}
-	return 0;
+	retval = pci_register_driver(&stradis_driver);
+	if (retval)
+		printk(KERN_ERR "stradis: Unable to register pci driver.\n");
+
+	return retval;
 }
 
-
-static void __exit stradis_exit (void)
+void __exit stradis_exit(void)
 {
-	release_saa();
+	pci_unregister_driver(&stradis_driver);
 	printk(KERN_INFO "stradis: module cleanup complete\n");
 }
 
-
 module_init(stradis_init);
 module_exit(stradis_exit);
-
diff --git a/drivers/media/video/tda7432.c b/drivers/media/video/tda7432.c
index 99261f1..fc3d5824 100644
--- a/drivers/media/video/tda7432.c
+++ b/drivers/media/video/tda7432.c
@@ -227,8 +227,8 @@
 static int tda7432_write(struct i2c_client *client, int subaddr, int val)
 {
 	unsigned char buffer[2];
-	v4l_dbg(2,client,"In tda7432_write\n");
-	v4l_dbg(1,client,"Writing %d 0x%x\n", subaddr, val);
+	v4l_dbg(2, debug,client,"In tda7432_write\n");
+	v4l_dbg(1, debug,client,"Writing %d 0x%x\n", subaddr, val);
 	buffer[0] = subaddr;
 	buffer[1] = val;
 	if (2 != i2c_master_send(client,buffer,2)) {
@@ -245,9 +245,9 @@
 {
 	struct tda7432 *t = i2c_get_clientdata(client);
 	unsigned char buf[16];
-	v4l_dbg(2,client,"In tda7432_set\n");
+	v4l_dbg(2, debug,client,"In tda7432_set\n");
 
-	v4l_dbg(1,client,
+	v4l_dbg(1, debug,client,
 		"tda7432: 7432_set(0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x)\n",
 		t->input,t->volume,t->bass,t->treble,t->lf,t->lr,t->rf,t->rr,t->loud);
 	buf[0]  = TDA7432_IN;
@@ -271,7 +271,7 @@
 static void do_tda7432_init(struct i2c_client *client)
 {
 	struct tda7432 *t = i2c_get_clientdata(client);
-	v4l_dbg(2,client,"In tda7432_init\n");
+	v4l_dbg(2, debug,client,"In tda7432_init\n");
 
 	t->input  = TDA7432_STEREO_IN |  /* Main (stereo) input   */
 		    TDA7432_BASS_SYM  |  /* Symmetric bass cut    */
@@ -300,10 +300,9 @@
 	struct tda7432 *t;
 	struct i2c_client *client;
 
-	t = kmalloc(sizeof *t,GFP_KERNEL);
+	t = kzalloc(sizeof *t,GFP_KERNEL);
 	if (!t)
 		return -ENOMEM;
-	memset(t,0,sizeof *t);
 
 	client = &t->c;
 	memcpy(client,&client_template,sizeof(struct i2c_client));
@@ -340,7 +339,7 @@
 			   unsigned int cmd, void *arg)
 {
 	struct tda7432 *t = i2c_get_clientdata(client);
-	v4l_dbg(2,client,"In tda7432_command\n");
+	v4l_dbg(2, debug,client,"In tda7432_command\n");
 	if (debug>1)
 		v4l_i2c_print_ioctl(client,cmd);
 
diff --git a/drivers/media/video/tda9875.c b/drivers/media/video/tda9875.c
index 299393b..ef98c49 100644
--- a/drivers/media/video/tda9875.c
+++ b/drivers/media/video/tda9875.c
@@ -232,10 +232,9 @@
 	struct i2c_client *client;
 	dprintk("In tda9875_attach\n");
 
-	t = kmalloc(sizeof *t,GFP_KERNEL);
+	t = kzalloc(sizeof *t,GFP_KERNEL);
 	if (!t)
 		return -ENOMEM;
-	memset(t,0,sizeof *t);
 
 	client = &t->c;
 	memcpy(client,&client_template,sizeof(struct i2c_client));
diff --git a/drivers/media/video/tda9887.c b/drivers/media/video/tda9887.c
index 9cf47dc..5815649 100644
--- a/drivers/media/video/tda9887.c
+++ b/drivers/media/video/tda9887.c
@@ -696,9 +696,8 @@
 	client_template.adapter = adap;
 	client_template.addr    = addr;
 
-	if (NULL == (t = kmalloc(sizeof(*t), GFP_KERNEL)))
+	if (NULL == (t = kzalloc(sizeof(*t), GFP_KERNEL)))
 		return -ENOMEM;
-	memset(t,0,sizeof(*t));
 
 	t->client      = client_template;
 	t->std         = 0;
diff --git a/drivers/media/video/tea5767.c b/drivers/media/video/tea5767.c
index 261b7a3..921fe72 100644
--- a/drivers/media/video/tea5767.c
+++ b/drivers/media/video/tea5767.c
@@ -18,7 +18,7 @@
 #define PREFIX "TEA5767 "
 
 /* from tuner-core.c */
-extern int debug;
+extern int tuner_debug;
 
 /*****************************************************************************/
 
@@ -249,7 +249,7 @@
 	if (5 != (rc = i2c_master_send(c, buffer, 5)))
 		tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc);
 
-	if (debug) {
+	if (tuner_debug) {
 		if (5 != (rc = i2c_master_recv(c, buffer, 5)))
 			tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc);
 		else
diff --git a/drivers/media/video/tea6420.c b/drivers/media/video/tea6420.c
index c4ba374..4dcba5a 100644
--- a/drivers/media/video/tea6420.c
+++ b/drivers/media/video/tea6420.c
@@ -99,11 +99,10 @@
 	}
 
 	/* allocate memory for client structure */
-	client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
+	client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
 	if (0 == client) {
 		return -ENOMEM;
 	}
-	memset(client, 0x0, sizeof(struct i2c_client));
 
 	/* fill client structure */
 	memcpy(client, &client_template, sizeof(struct i2c_client));
diff --git a/drivers/media/video/tuner-3036.c b/drivers/media/video/tuner-3036.c
index d97f668..c4a78e7 100644
--- a/drivers/media/video/tuner-3036.c
+++ b/drivers/media/video/tuner-3036.c
@@ -193,8 +193,7 @@
 static int __init
 tuner3036_init(void)
 {
-	i2c_add_driver(&i2c_driver_tuner);
-	return 0;
+	return i2c_add_driver(&i2c_driver_tuner);
 }
 
 static void __exit
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index 57bc585..f30ef79d 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -41,8 +41,8 @@
 static unsigned int show_i2c = 0;
 
 /* insmod options used at runtime => read/write */
-static unsigned int tuner_debug = 0;
-int debug = 0;
+static unsigned int tuner_debug_old = 0;
+int tuner_debug = 0;
 
 static unsigned int tv_range[2] = { 44, 958 };
 static unsigned int radio_range[2] = { 65, 108 };
@@ -51,13 +51,13 @@
 static char secam[] = "--";
 static char ntsc[] = "-";
 
+
 module_param(addr, int, 0444);
 module_param(no_autodetect, int, 0444);
 module_param(show_i2c, int, 0444);
 /* Note: tuner_debug is deprecated and will be removed in 2.6.17 */
-module_param(tuner_debug, int, 0444);
-module_param(debug, int, 0644);
-
+module_param_named(tuner_debug,tuner_debug_old, int, 0444);
+module_param_named(debug,tuner_debug, int, 0644);
 module_param_string(pal, pal, sizeof(pal), 0644);
 module_param_string(secam, secam, sizeof(secam), 0644);
 module_param_string(ntsc, ntsc, sizeof(ntsc), 0644);
@@ -410,18 +410,17 @@
 	client_template.adapter = adap;
 	client_template.addr = addr;
 
-	t = kmalloc(sizeof(struct tuner), GFP_KERNEL);
+	t = kzalloc(sizeof(struct tuner), GFP_KERNEL);
 	if (NULL == t)
 		return -ENOMEM;
-	memset(t, 0, sizeof(struct tuner));
 	memcpy(&t->i2c, &client_template, sizeof(struct i2c_client));
 	i2c_set_clientdata(&t->i2c, t);
 	t->type = UNSET;
 	t->radio_if2 = 10700 * 1000;	/* 10.7MHz - FM radio */
 	t->audmode = V4L2_TUNER_MODE_STEREO;
 	t->mode_mask = T_UNINITIALIZED;
-	if (tuner_debug) {
-		debug = tuner_debug;
+	if (tuner_debug_old) {
+		tuner_debug = tuner_debug_old;
 		printk(KERN_ERR "tuner: tuner_debug is deprecated and will be removed in 2.6.17.\n");
 		printk(KERN_ERR "tuner: use the debug option instead.\n");
 	}
@@ -552,7 +551,7 @@
 {
 	struct tuner *t = i2c_get_clientdata(client);
 
-	if (debug>1)
+	if (tuner_debug>1)
 		v4l_i2c_print_ioctl(&(t->i2c),cmd);
 
 	switch (cmd) {
diff --git a/drivers/media/video/tvaudio.c b/drivers/media/video/tvaudio.c
index b582943..6d03b9b0 100644
--- a/drivers/media/video/tvaudio.c
+++ b/drivers/media/video/tvaudio.c
@@ -159,7 +159,7 @@
 	unsigned char buffer[2];
 
 	if (-1 == subaddr) {
-		v4l_dbg(1, &chip->c, "%s: chip_write: 0x%x\n",
+		v4l_dbg(1, debug, &chip->c, "%s: chip_write: 0x%x\n",
 			chip->c.name, val);
 		chip->shadow.bytes[1] = val;
 		buffer[0] = val;
@@ -169,7 +169,7 @@
 			return -1;
 		}
 	} else {
-		v4l_dbg(1, &chip->c, "%s: chip_write: reg%d=0x%x\n",
+		v4l_dbg(1, debug, &chip->c, "%s: chip_write: reg%d=0x%x\n",
 			chip->c.name, subaddr, val);
 		chip->shadow.bytes[subaddr+1] = val;
 		buffer[0] = subaddr;
@@ -204,7 +204,7 @@
 		chip->c.name);
 		return -1;
 	}
-	v4l_dbg(1, &chip->c, "%s: chip_read: 0x%x\n",chip->c.name, buffer);
+	v4l_dbg(1, debug, &chip->c, "%s: chip_read: 0x%x\n",chip->c.name, buffer);
 	return buffer;
 }
 
@@ -222,7 +222,7 @@
 		v4l_warn(&chip->c, "%s: I/O error (read2)\n", chip->c.name);
 		return -1;
 	}
-	v4l_dbg(1, &chip->c, "%s: chip_read2: reg%d=0x%x\n",
+	v4l_dbg(1, debug, &chip->c, "%s: chip_read2: reg%d=0x%x\n",
 		chip->c.name, subaddr,read[0]);
 	return read[0];
 }
@@ -235,7 +235,7 @@
 		return 0;
 
 	/* update our shadow register set; print bytes if (debug > 0) */
-	v4l_dbg(1, &chip->c, "%s: chip_cmd(%s): reg=%d, data:",
+	v4l_dbg(1, debug, &chip->c, "%s: chip_cmd(%s): reg=%d, data:",
 		chip->c.name, name,cmd->bytes[0]);
 	for (i = 1; i < cmd->count; i++) {
 		if (debug)
@@ -274,7 +274,7 @@
 
 	daemonize("%s", chip->c.name);
 	allow_signal(SIGTERM);
-	v4l_dbg(1, &chip->c, "%s: thread started\n", chip->c.name);
+	v4l_dbg(1, debug, &chip->c, "%s: thread started\n", chip->c.name);
 
 	for (;;) {
 		add_wait_queue(&chip->wq, &wait);
@@ -286,7 +286,7 @@
 		try_to_freeze();
 		if (chip->done || signal_pending(current))
 			break;
-		v4l_dbg(1, &chip->c, "%s: thread wakeup\n", chip->c.name);
+		v4l_dbg(1, debug, &chip->c, "%s: thread wakeup\n", chip->c.name);
 
 		/* don't do anything for radio or if mode != auto */
 		if (chip->radio || chip->mode != 0)
@@ -299,7 +299,7 @@
 		mod_timer(&chip->wt, jiffies+2*HZ);
 	}
 
-	v4l_dbg(1, &chip->c, "%s: thread exiting\n", chip->c.name);
+	v4l_dbg(1, debug, &chip->c, "%s: thread exiting\n", chip->c.name);
 	complete_and_exit(&chip->texit, 0);
 	return 0;
 }
@@ -312,7 +312,7 @@
 	if (mode == chip->prevmode)
 	return;
 
-	v4l_dbg(1, &chip->c, "%s: thread checkmode\n", chip->c.name);
+	v4l_dbg(1, debug, &chip->c, "%s: thread checkmode\n", chip->c.name);
 	chip->prevmode = mode;
 
 	if (mode & VIDEO_SOUND_STEREO)
@@ -359,7 +359,7 @@
 	if (val & TDA9840_ST_STEREO)
 		mode |= VIDEO_SOUND_STEREO;
 
-	v4l_dbg(1, &chip->c, "tda9840_getmode(): raw chip read: %d, return: %d\n",
+	v4l_dbg(1, debug, &chip->c, "tda9840_getmode(): raw chip read: %d, return: %d\n",
 		val, mode);
 	return mode;
 }
@@ -655,7 +655,7 @@
 		mode |= VIDEO_SOUND_STEREO;
 	if (val & TDA9873_DUAL)
 		mode |= VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
-	v4l_dbg(1, &chip->c, "tda9873_getmode(): raw chip read: %d, return: %d\n",
+	v4l_dbg(1, debug, &chip->c, "tda9873_getmode(): raw chip read: %d, return: %d\n",
 		val, mode);
 	return mode;
 }
@@ -666,12 +666,12 @@
 	/*	int adj_data = chip->shadow.bytes[TDA9873_AD+1] ; */
 
 	if ((sw_data & TDA9873_INP_MASK) != TDA9873_INTERNAL) {
-		v4l_dbg(1, &chip->c, "tda9873_setmode(): external input\n");
+		v4l_dbg(1, debug, &chip->c, "tda9873_setmode(): external input\n");
 		return;
 	}
 
-	v4l_dbg(1, &chip->c, "tda9873_setmode(): chip->shadow.bytes[%d] = %d\n", TDA9873_SW+1, chip->shadow.bytes[TDA9873_SW+1]);
-	v4l_dbg(1, &chip->c, "tda9873_setmode(): sw_data  = %d\n", sw_data);
+	v4l_dbg(1, debug, &chip->c, "tda9873_setmode(): chip->shadow.bytes[%d] = %d\n", TDA9873_SW+1, chip->shadow.bytes[TDA9873_SW+1]);
+	v4l_dbg(1, debug, &chip->c, "tda9873_setmode(): sw_data  = %d\n", sw_data);
 
 	switch (mode) {
 	case VIDEO_SOUND_MONO:
@@ -692,7 +692,7 @@
 	}
 
 	chip_write(chip, TDA9873_SW, sw_data);
-	v4l_dbg(1, &chip->c, "tda9873_setmode(): req. mode %d; chip_write: %d\n",
+	v4l_dbg(1, debug, &chip->c, "tda9873_setmode(): req. mode %d; chip_write: %d\n",
 		mode, sw_data);
 }
 
@@ -831,7 +831,7 @@
 		chip_write(chip, TDA9874A_SDACOSR, (tda9874a_mode) ? 0x81:0x80);
 		chip_write(chip, TDA9874A_AOSR, 0x00); /* or 0x10 */
 	}
-	v4l_dbg(1, &chip->c, "tda9874a_setup(): %s [0x%02X].\n",
+	v4l_dbg(1, debug, &chip->c, "tda9874a_setup(): %s [0x%02X].\n",
 		tda9874a_modelist[tda9874a_STD].name,tda9874a_STD);
 	return 1;
 }
@@ -874,7 +874,7 @@
 			mode |= VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
 	}
 
-	v4l_dbg(1, &chip->c, "tda9874a_getmode(): DSR=0x%X, NSR=0x%X, NECR=0x%X, return: %d.\n",
+	v4l_dbg(1, debug, &chip->c, "tda9874a_getmode(): DSR=0x%X, NSR=0x%X, NECR=0x%X, return: %d.\n",
 		 dsr, nsr, necr, mode);
 	return mode;
 }
@@ -920,7 +920,7 @@
 		chip_write(chip, TDA9874A_AOSR, aosr);
 		chip_write(chip, TDA9874A_MDACOSR, mdacosr);
 
-		v4l_dbg(1, &chip->c, "tda9874a_setmode(): req. mode %d; AOSR=0x%X, MDACOSR=0x%X.\n",
+		v4l_dbg(1, debug, &chip->c, "tda9874a_setmode(): req. mode %d; AOSR=0x%X, MDACOSR=0x%X.\n",
 			mode, aosr, mdacosr);
 
 	} else { /* dic == 0x07 */
@@ -955,7 +955,7 @@
 		chip_write(chip, TDA9874A_FMMR, fmmr);
 		chip_write(chip, TDA9874A_AOSR, aosr);
 
-		v4l_dbg(1, &chip->c, "tda9874a_setmode(): req. mode %d; FMMR=0x%X, AOSR=0x%X.\n",
+		v4l_dbg(1, debug, &chip->c, "tda9874a_setmode(): req. mode %d; FMMR=0x%X, AOSR=0x%X.\n",
 			mode, fmmr, aosr);
 	}
 }
@@ -969,7 +969,7 @@
 	if(-1 == (sic = chip_read2(chip,TDA9874A_SIC)))
 		return 0;
 
-	v4l_dbg(1, &chip->c, "tda9874a_checkit(): DIC=0x%X, SIC=0x%X.\n", dic, sic);
+	v4l_dbg(1, debug, &chip->c, "tda9874a_checkit(): DIC=0x%X, SIC=0x%X.\n", dic, sic);
 
 	if((dic == 0x11)||(dic == 0x07)) {
 		v4l_info(&chip->c, "found tda9874%s.\n", (dic == 0x11) ? "a":"h");
@@ -1184,7 +1184,7 @@
 	}else if (!(val & TA8874Z_B0)){
 		mode |= VIDEO_SOUND_STEREO;
 	}
-	/* v4l_dbg(1, &chip->c, "ta8874z_getmode(): raw chip read: 0x%02x, return: 0x%02x\n", val, mode); */
+	/* v4l_dbg(1, debug, &chip->c, "ta8874z_getmode(): raw chip read: 0x%02x, return: 0x%02x\n", val, mode); */
 	return mode;
 }
 
@@ -1197,7 +1197,7 @@
 {
 	int update = 1;
 	audiocmd *t = NULL;
-	v4l_dbg(1, &chip->c, "ta8874z_setmode(): mode: 0x%02x\n", mode);
+	v4l_dbg(1, debug, &chip->c, "ta8874z_setmode(): mode: 0x%02x\n", mode);
 
 	switch(mode){
 	case VIDEO_SOUND_MONO:
@@ -1468,17 +1468,16 @@
 	struct CHIPSTATE *chip;
 	struct CHIPDESC  *desc;
 
-	chip = kmalloc(sizeof(*chip),GFP_KERNEL);
+	chip = kzalloc(sizeof(*chip),GFP_KERNEL);
 	if (!chip)
 		return -ENOMEM;
-	memset(chip,0,sizeof(*chip));
 	memcpy(&chip->c,&client_template,sizeof(struct i2c_client));
 	chip->c.adapter = adap;
 	chip->c.addr = addr;
 	i2c_set_clientdata(&chip->c, chip);
 
 	/* find description for the chip */
-	v4l_dbg(1, &chip->c, "chip found @ 0x%x\n", addr<<1);
+	v4l_dbg(1, debug, &chip->c, "chip found @ 0x%x\n", addr<<1);
 	for (desc = chiplist; desc->name != NULL; desc++) {
 		if (0 == *(desc->insmodopt))
 			continue;
@@ -1490,12 +1489,12 @@
 		break;
 	}
 	if (desc->name == NULL) {
-		v4l_dbg(1, &chip->c, "no matching chip description found\n");
+		v4l_dbg(1, debug, &chip->c, "no matching chip description found\n");
 		return -EIO;
 	}
 	v4l_info(&chip->c, "%s found @ 0x%x (%s)\n", desc->name, addr<<1, adap->name);
 	if (desc->flags) {
-		v4l_dbg(1, &chip->c, "matches:%s%s%s.\n",
+		v4l_dbg(1, debug, &chip->c, "matches:%s%s%s.\n",
 			(desc->flags & CHIP_HAS_VOLUME)     ? " volume"      : "",
 			(desc->flags & CHIP_HAS_BASSTREBLE) ? " bass/treble" : "",
 			(desc->flags & CHIP_HAS_INPUTSEL)   ? " audiomux"    : "");
@@ -1583,7 +1582,7 @@
 	struct CHIPSTATE *chip = i2c_get_clientdata(client);
 	struct CHIPDESC  *desc = chiplist + chip->type;
 
-	v4l_dbg(1, &chip->c, "%s: chip_command 0x%x\n", chip->c.name, cmd);
+	v4l_dbg(1, debug, &chip->c, "%s: chip_command 0x%x\n", chip->c.name, cmd);
 
 	switch (cmd) {
 	case AUDC_SET_INPUT:
diff --git a/drivers/media/video/tveeprom.c b/drivers/media/video/tveeprom.c
index fd0acc5..5e71a35 100644
--- a/drivers/media/video/tveeprom.c
+++ b/drivers/media/video/tveeprom.c
@@ -719,8 +719,7 @@
 
 	switch (cmd) {
 	case 0:
-		buf = kmalloc(256,GFP_KERNEL);
-		memset(buf,0,256);
+		buf = kzalloc(256,GFP_KERNEL);
 		tveeprom_read(client,buf,256);
 		tveeprom_hauppauge_analog(client, &eeprom,buf);
 		kfree(buf);
@@ -743,10 +742,9 @@
 {
 	struct i2c_client *client;
 
-	client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
+	client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
 	if (NULL == client)
 		return -ENOMEM;
-	memset(client, 0, sizeof(struct i2c_client));
 	client->addr = address;
 	client->adapter = adapter;
 	client->driver = &i2c_driver_tveeprom;
diff --git a/drivers/media/video/tvp5150.c b/drivers/media/video/tvp5150.c
index c35b804..e86b522 100644
--- a/drivers/media/video/tvp5150.c
+++ b/drivers/media/video/tvp5150.c
@@ -1074,12 +1074,11 @@
 		return -ENOMEM;
 	memcpy(c, &client_template, sizeof(struct i2c_client));
 
-	core = kmalloc(sizeof(struct tvp5150), GFP_KERNEL);
+	core = kzalloc(sizeof(struct tvp5150), GFP_KERNEL);
 	if (core == 0) {
 		kfree(c);
 		return -ENOMEM;
 	}
-	memset(core, 0, sizeof(struct tvp5150));
 	i2c_set_clientdata(c, core);
 
 	rv = i2c_attach_client(c);
diff --git a/drivers/media/video/v4l1-compat.c b/drivers/media/video/v4l1-compat.c
index 2ab5b40..474a29b 100644
--- a/drivers/media/video/v4l1-compat.c
+++ b/drivers/media/video/v4l1-compat.c
@@ -305,9 +305,8 @@
 	{
 		struct video_capability *cap = arg;
 
-		cap2 = kmalloc(sizeof(*cap2),GFP_KERNEL);
+		cap2 = kzalloc(sizeof(*cap2),GFP_KERNEL);
 		memset(cap, 0, sizeof(*cap));
-		memset(cap2, 0, sizeof(*cap2));
 		memset(&fbuf2, 0, sizeof(fbuf2));
 
 		err = drv(inode, file, VIDIOC_QUERYCAP, cap2);
@@ -422,9 +421,8 @@
 	{
 		struct video_window	*win = arg;
 
-		fmt2 = kmalloc(sizeof(*fmt2),GFP_KERNEL);
+		fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
 		memset(win,0,sizeof(*win));
-		memset(fmt2,0,sizeof(*fmt2));
 
 		fmt2->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
 		err = drv(inode, file, VIDIOC_G_FMT, fmt2);
@@ -461,8 +459,7 @@
 		struct video_window	*win = arg;
 		int err1,err2;
 
-		fmt2 = kmalloc(sizeof(*fmt2),GFP_KERNEL);
-		memset(fmt2,0,sizeof(*fmt2));
+		fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
 		fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 		drv(inode, file, VIDIOC_STREAMOFF, &fmt2->type);
 		err1 = drv(inode, file, VIDIOC_G_FMT, fmt2);
@@ -595,8 +592,7 @@
 		pict->whiteness = get_v4l_control(inode, file,
 						  V4L2_CID_WHITENESS, drv);
 
-		fmt2 = kmalloc(sizeof(*fmt2),GFP_KERNEL);
-		memset(fmt2,0,sizeof(*fmt2));
+		fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
 		fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 		err = drv(inode, file, VIDIOC_G_FMT, fmt2);
 		if (err < 0) {
@@ -622,8 +618,7 @@
 		set_v4l_control(inode, file,
 				V4L2_CID_WHITENESS, pict->whiteness, drv);
 
-		fmt2 = kmalloc(sizeof(*fmt2),GFP_KERNEL);
-		memset(fmt2,0,sizeof(*fmt2));
+		fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
 		fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 		err = drv(inode, file, VIDIOC_G_FMT, fmt2);
 		if (err < 0)
@@ -846,9 +841,8 @@
 	{
 		struct video_mmap	*mm = arg;
 
-		fmt2 = kmalloc(sizeof(*fmt2),GFP_KERNEL);
+		fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
 		memset(&buf2,0,sizeof(buf2));
-		memset(fmt2,0,sizeof(*fmt2));
 
 		fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 		err = drv(inode, file, VIDIOC_G_FMT, fmt2);
@@ -942,8 +936,7 @@
 	{
 		struct vbi_format      *fmt = arg;
 
-		fmt2 = kmalloc(sizeof(*fmt2),GFP_KERNEL);
-		memset(fmt2, 0, sizeof(*fmt2));
+		fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
 		fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
 
 		err = drv(inode, file, VIDIOC_G_FMT, fmt2);
@@ -975,8 +968,7 @@
 			break;
 		}
 
-		fmt2 = kmalloc(sizeof(*fmt2),GFP_KERNEL);
-		memset(fmt2, 0, sizeof(*fmt2));
+		fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
 
 		fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
 		fmt2->fmt.vbi.samples_per_line = fmt->samples_per_line;
diff --git a/drivers/media/video/video-buf.c b/drivers/media/video/video-buf.c
index 9a6bf28..9ef4775 100644
--- a/drivers/media/video/video-buf.c
+++ b/drivers/media/video/video-buf.c
@@ -52,10 +52,9 @@
 	struct page *pg;
 	int i;
 
-	sglist = kmalloc(sizeof(struct scatterlist)*nr_pages, GFP_KERNEL);
+	sglist = kcalloc(nr_pages, sizeof(struct scatterlist), GFP_KERNEL);
 	if (NULL == sglist)
 		return NULL;
-	memset(sglist,0,sizeof(struct scatterlist)*nr_pages);
 	for (i = 0; i < nr_pages; i++, virt += PAGE_SIZE) {
 		pg = vmalloc_to_page(virt);
 		if (NULL == pg)
@@ -80,10 +79,9 @@
 
 	if (NULL == pages[0])
 		return NULL;
-	sglist = kmalloc(sizeof(*sglist) * nr_pages, GFP_KERNEL);
+	sglist = kcalloc(nr_pages, sizeof(*sglist), GFP_KERNEL);
 	if (NULL == sglist)
 		return NULL;
-	memset(sglist, 0, sizeof(*sglist) * nr_pages);
 
 	if (NULL == pages[0])
 		goto nopage;
@@ -284,9 +282,8 @@
 {
 	struct videobuf_buffer *vb;
 
-	vb = kmalloc(size,GFP_KERNEL);
+	vb = kzalloc(size,GFP_KERNEL);
 	if (NULL != vb) {
-		memset(vb,0,size);
 		videobuf_dma_init(&vb->dma);
 		init_waitqueue_head(&vb->done);
 		vb->magic     = MAGIC_BUFFER;
diff --git a/drivers/media/video/videocodec.c b/drivers/media/video/videocodec.c
index 839db62..8f271de 100644
--- a/drivers/media/video/videocodec.c
+++ b/drivers/media/video/videocodec.c
@@ -124,17 +124,13 @@
 			if (res == 0) {
 				dprintk(3, "videocodec_attach '%s'\n",
 					codec->name);
-				ptr = (struct attached_list *)
-				    kmalloc(sizeof(struct attached_list),
-					    GFP_KERNEL);
+				ptr = kzalloc(sizeof(struct attached_list), GFP_KERNEL);
 				if (!ptr) {
 					dprintk(1,
 						KERN_ERR
 						"videocodec_attach: no memory\n");
 					goto out_kfree;
 				}
-				memset(ptr, 0,
-				       sizeof(struct attached_list));
 				ptr->codec = codec;
 
 				a = h->list;
@@ -249,14 +245,11 @@
 		"videocodec: register '%s', type: %x, flags %lx, magic %lx\n",
 		codec->name, codec->type, codec->flags, codec->magic);
 
-	ptr =
-	    (struct codec_list *) kmalloc(sizeof(struct codec_list),
-					  GFP_KERNEL);
+	ptr = kzalloc(sizeof(struct codec_list), GFP_KERNEL);
 	if (!ptr) {
 		dprintk(1, KERN_ERR "videocodec_register: no memory\n");
 		return -ENOMEM;
 	}
-	memset(ptr, 0, sizeof(struct codec_list));
 	ptr->codec = codec;
 
 	if (!h) {
diff --git a/drivers/media/video/videodev.c b/drivers/media/video/videodev.c
index 9a9902c..d5be259 100644
--- a/drivers/media/video/videodev.c
+++ b/drivers/media/video/videodev.c
@@ -52,10 +52,7 @@
 {
 	struct video_device *vfd;
 
-	vfd = kmalloc(sizeof(*vfd),GFP_KERNEL);
-	if (NULL == vfd)
-		return NULL;
-	memset(vfd,0,sizeof(*vfd));
+	vfd = kzalloc(sizeof(*vfd),GFP_KERNEL);
 	return vfd;
 }
 
diff --git a/drivers/media/video/vino.c b/drivers/media/video/vino.c
index 71b28e9..c8fd823 100644
--- a/drivers/media/video/vino.c
+++ b/drivers/media/video/vino.c
@@ -4499,13 +4499,11 @@
 	dma_addr_t dma_dummy_address;
 	int i;
 
-	vino_drvdata = (struct vino_settings *)
-		kmalloc(sizeof(struct vino_settings), GFP_KERNEL);
+	vino_drvdata = kzalloc(sizeof(struct vino_settings), GFP_KERNEL);
 	if (!vino_drvdata) {
 		vino_module_cleanup(vino_init_stage);
 		return -ENOMEM;
 	}
-	memset(vino_drvdata, 0, sizeof(struct vino_settings));
 	vino_init_stage++;
 
 	/* create a dummy dma descriptor */
diff --git a/drivers/media/video/vpx3220.c b/drivers/media/video/vpx3220.c
index 8dcee8b..d0a1e72 100644
--- a/drivers/media/video/vpx3220.c
+++ b/drivers/media/video/vpx3220.c
@@ -621,13 +621,11 @@
 	    (adapter, I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))
 		return 0;
 
-	client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
+	client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
 	if (client == NULL) {
 		return -ENOMEM;
 	}
 
-	memset(client, 0, sizeof(struct i2c_client));
-
 	client->addr = address;
 	client->adapter = adapter;
 	client->driver = &vpx3220_i2c_driver;
@@ -675,12 +673,11 @@
 			sizeof(I2C_NAME(client)));
 	}
 
-	decoder = kmalloc(sizeof(struct vpx3220), GFP_KERNEL);
+	decoder = kzalloc(sizeof(struct vpx3220), GFP_KERNEL);
 	if (decoder == NULL) {
 		kfree(client);
 		return -ENOMEM;
 	}
-	memset(decoder, 0, sizeof(struct vpx3220));
 	decoder->norm = VIDEO_MODE_PAL;
 	decoder->input = 0;
 	decoder->enable = 1;
diff --git a/drivers/media/video/wm8775.c b/drivers/media/video/wm8775.c
index c2e6d2e..8cb64f8 100644
--- a/drivers/media/video/wm8775.c
+++ b/drivers/media/video/wm8775.c
@@ -166,11 +166,10 @@
 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
 		return 0;
 
-	client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
+	client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
 	if (client == 0)
 		return -ENOMEM;
 
-	memset(client, 0, sizeof(struct i2c_client));
 	client->addr = address;
 	client->adapter = adapter;
 	client->driver = &i2c_driver;
diff --git a/drivers/media/video/zoran_card.c b/drivers/media/video/zoran_card.c
index 39a0d23..ea32886 100644
--- a/drivers/media/video/zoran_card.c
+++ b/drivers/media/video/zoran_card.c
@@ -1050,7 +1050,7 @@
 	/* allocate memory *before* doing anything to the hardware
 	 * in case allocation fails */
 	mem_needed = BUZ_NUM_STAT_COM * 4;
-	mem = (unsigned long) kmalloc(mem_needed, GFP_KERNEL);
+	mem = kzalloc(mem_needed, GFP_KERNEL);
 	vdev = (void *) kmalloc(sizeof(struct video_device), GFP_KERNEL);
 	if (!mem || !vdev) {
 		dprintk(1,
@@ -1061,7 +1061,6 @@
 		kfree((void *)mem);
 		return -ENOMEM;
 	}
-	memset((void *) mem, 0, mem_needed);
 	zr->stat_com = (u32 *) mem;
 	for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
 		zr->stat_com[j] = 1;	/* mark as unavailable to zr36057 */
diff --git a/drivers/media/video/zoran_driver.c b/drivers/media/video/zoran_driver.c
index 15283f4..485553b 100644
--- a/drivers/media/video/zoran_driver.c
+++ b/drivers/media/video/zoran_driver.c
@@ -1345,7 +1345,7 @@
 		ZR_DEVNAME(zr), current->comm, current->pid, zr->user);
 
 	/* now, create the open()-specific file_ops struct */
-	fh = kmalloc(sizeof(struct zoran_fh), GFP_KERNEL);
+	fh = kzalloc(sizeof(struct zoran_fh), GFP_KERNEL);
 	if (!fh) {
 		dprintk(1,
 			KERN_ERR
@@ -1354,7 +1354,6 @@
 		res = -ENOMEM;
 		goto open_unlock_and_return;
 	}
-	memset(fh, 0, sizeof(struct zoran_fh));
 	/* used to be BUZ_MAX_WIDTH/HEIGHT, but that gives overflows
 	 * on norm-change! */
 	fh->overlay_mask =
diff --git a/drivers/media/video/zr36016.c b/drivers/media/video/zr36016.c
index 4ed8985..10130ef 100644
--- a/drivers/media/video/zr36016.c
+++ b/drivers/media/video/zr36016.c
@@ -451,12 +451,11 @@
 		return -ENOSPC;
 	}
 	//mem structure init
-	codec->data = ptr = kmalloc(sizeof(struct zr36016), GFP_KERNEL);
+	codec->data = ptr = kzalloc(sizeof(struct zr36016), GFP_KERNEL);
 	if (NULL == ptr) {
 		dprintk(1, KERN_ERR "zr36016: Can't get enough memory!\n");
 		return -ENOMEM;
 	}
-	memset(ptr, 0, sizeof(struct zr36016));
 
 	snprintf(ptr->name, sizeof(ptr->name), "zr36016[%d]",
 		 zr36016_codecs);
diff --git a/drivers/media/video/zr36050.c b/drivers/media/video/zr36050.c
index 0144576..bd0cd28 100644
--- a/drivers/media/video/zr36050.c
+++ b/drivers/media/video/zr36050.c
@@ -813,12 +813,11 @@
 		return -ENOSPC;
 	}
 	//mem structure init
-	codec->data = ptr = kmalloc(sizeof(struct zr36050), GFP_KERNEL);
+	codec->data = ptr = kzalloc(sizeof(struct zr36050), GFP_KERNEL);
 	if (NULL == ptr) {
 		dprintk(1, KERN_ERR "zr36050: Can't get enough memory!\n");
 		return -ENOMEM;
 	}
-	memset(ptr, 0, sizeof(struct zr36050));
 
 	snprintf(ptr->name, sizeof(ptr->name), "zr36050[%d]",
 		 zr36050_codecs);
diff --git a/drivers/media/video/zr36060.c b/drivers/media/video/zr36060.c
index 129744a..28fa31a 100644
--- a/drivers/media/video/zr36060.c
+++ b/drivers/media/video/zr36060.c
@@ -919,12 +919,11 @@
 		return -ENOSPC;
 	}
 	//mem structure init
-	codec->data = ptr = kmalloc(sizeof(struct zr36060), GFP_KERNEL);
+	codec->data = ptr = kzalloc(sizeof(struct zr36060), GFP_KERNEL);
 	if (NULL == ptr) {
 		dprintk(1, KERN_ERR "zr36060: Can't get enough memory!\n");
 		return -ENOMEM;
 	}
-	memset(ptr, 0, sizeof(struct zr36060));
 
 	snprintf(ptr->name, sizeof(ptr->name), "zr36060[%d]",
 		 zr36060_codecs);
diff --git a/drivers/message/fusion/mptctl.c b/drivers/message/fusion/mptctl.c
index 959d2c59..7c34024 100644
--- a/drivers/message/fusion/mptctl.c
+++ b/drivers/message/fusion/mptctl.c
@@ -2585,8 +2585,6 @@
 
 #ifdef CONFIG_COMPAT
 
-#include <linux/ioctl32.h>
-
 static int
 compat_mptfwxfer_ioctl(struct file *filp, unsigned int cmd,
 			unsigned long arg)
diff --git a/drivers/mfd/ucb1x00-core.c b/drivers/mfd/ucb1x00-core.c
index b42e0fb..aff83f9 100644
--- a/drivers/mfd/ucb1x00-core.c
+++ b/drivers/mfd/ucb1x00-core.c
@@ -24,13 +24,14 @@
 #include <linux/errno.h>
 #include <linux/interrupt.h>
 #include <linux/device.h>
+#include <linux/mutex.h>
 
 #include <asm/dma.h>
 #include <asm/hardware.h>
 
 #include "ucb1x00.h"
 
-static DECLARE_MUTEX(ucb1x00_sem);
+static DEFINE_MUTEX(ucb1x00_mutex);
 static LIST_HEAD(ucb1x00_drivers);
 static LIST_HEAD(ucb1x00_devices);
 
@@ -521,12 +522,12 @@
 		goto err_irq;
 
 	INIT_LIST_HEAD(&ucb->devs);
-	down(&ucb1x00_sem);
+	mutex_lock(&ucb1x00_mutex);
 	list_add(&ucb->node, &ucb1x00_devices);
 	list_for_each_entry(drv, &ucb1x00_drivers, node) {
 		ucb1x00_add_dev(ucb, drv);
 	}
-	up(&ucb1x00_sem);
+	mutex_unlock(&ucb1x00_mutex);
 	goto out;
 
  err_irq:
@@ -544,13 +545,13 @@
 	struct ucb1x00 *ucb = mcp_get_drvdata(mcp);
 	struct list_head *l, *n;
 
-	down(&ucb1x00_sem);
+	mutex_lock(&ucb1x00_mutex);
 	list_del(&ucb->node);
 	list_for_each_safe(l, n, &ucb->devs) {
 		struct ucb1x00_dev *dev = list_entry(l, struct ucb1x00_dev, dev_node);
 		ucb1x00_remove_dev(dev);
 	}
-	up(&ucb1x00_sem);
+	mutex_unlock(&ucb1x00_mutex);
 
 	free_irq(ucb->irq, ucb);
 	class_device_unregister(&ucb->cdev);
@@ -561,12 +562,12 @@
 	struct ucb1x00 *ucb;
 
 	INIT_LIST_HEAD(&drv->devs);
-	down(&ucb1x00_sem);
+	mutex_lock(&ucb1x00_mutex);
 	list_add(&drv->node, &ucb1x00_drivers);
 	list_for_each_entry(ucb, &ucb1x00_devices, node) {
 		ucb1x00_add_dev(ucb, drv);
 	}
-	up(&ucb1x00_sem);
+	mutex_unlock(&ucb1x00_mutex);
 	return 0;
 }
 
@@ -574,13 +575,13 @@
 {
 	struct list_head *n, *l;
 
-	down(&ucb1x00_sem);
+	mutex_lock(&ucb1x00_mutex);
 	list_del(&drv->node);
 	list_for_each_safe(l, n, &drv->devs) {
 		struct ucb1x00_dev *dev = list_entry(l, struct ucb1x00_dev, drv_node);
 		ucb1x00_remove_dev(dev);
 	}
-	up(&ucb1x00_sem);
+	mutex_unlock(&ucb1x00_mutex);
 }
 
 static int ucb1x00_suspend(struct mcp *mcp, pm_message_t state)
@@ -588,12 +589,12 @@
 	struct ucb1x00 *ucb = mcp_get_drvdata(mcp);
 	struct ucb1x00_dev *dev;
 
-	down(&ucb1x00_sem);
+	mutex_lock(&ucb1x00_mutex);
 	list_for_each_entry(dev, &ucb->devs, dev_node) {
 		if (dev->drv->suspend)
 			dev->drv->suspend(dev, state);
 	}
-	up(&ucb1x00_sem);
+	mutex_unlock(&ucb1x00_mutex);
 	return 0;
 }
 
@@ -602,12 +603,12 @@
 	struct ucb1x00 *ucb = mcp_get_drvdata(mcp);
 	struct ucb1x00_dev *dev;
 
-	down(&ucb1x00_sem);
+	mutex_lock(&ucb1x00_mutex);
 	list_for_each_entry(dev, &ucb->devs, dev_node) {
 		if (dev->drv->resume)
 			dev->drv->resume(dev);
 	}
-	up(&ucb1x00_sem);
+	mutex_unlock(&ucb1x00_mutex);
 	return 0;
 }
 
diff --git a/drivers/misc/ibmasm/remote.c b/drivers/misc/ibmasm/remote.c
index 1abd0c5..0f9e3aa 100644
--- a/drivers/misc/ibmasm/remote.c
+++ b/drivers/misc/ibmasm/remote.c
@@ -270,6 +270,7 @@
 
  err_unregister_mouse_dev:
 	input_unregister_device(mouse_dev);
+	mouse_dev = NULL; /* so we don't try to free it again below */
  err_free_devices:
 	input_free_device(mouse_dev);
 	input_free_device(keybd_dev);
diff --git a/drivers/mmc/mmc_block.c b/drivers/mmc/mmc_block.c
index f2c42b1..9b7c37e 100644
--- a/drivers/mmc/mmc_block.c
+++ b/drivers/mmc/mmc_block.c
@@ -28,6 +28,7 @@
 #include <linux/kdev_t.h>
 #include <linux/blkdev.h>
 #include <linux/devfs_fs_kernel.h>
+#include <linux/mutex.h>
 
 #include <linux/mmc/card.h>
 #include <linux/mmc/protocol.h>
@@ -57,33 +58,33 @@
 	unsigned int	read_only;
 };
 
-static DECLARE_MUTEX(open_lock);
+static DEFINE_MUTEX(open_lock);
 
 static struct mmc_blk_data *mmc_blk_get(struct gendisk *disk)
 {
 	struct mmc_blk_data *md;
 
-	down(&open_lock);
+	mutex_lock(&open_lock);
 	md = disk->private_data;
 	if (md && md->usage == 0)
 		md = NULL;
 	if (md)
 		md->usage++;
-	up(&open_lock);
+	mutex_unlock(&open_lock);
 
 	return md;
 }
 
 static void mmc_blk_put(struct mmc_blk_data *md)
 {
-	down(&open_lock);
+	mutex_lock(&open_lock);
 	md->usage--;
 	if (md->usage == 0) {
 		put_disk(md->disk);
 		mmc_cleanup_queue(&md->queue);
 		kfree(md);
 	}
-	up(&open_lock);
+	mutex_unlock(&open_lock);
 }
 
 static int mmc_blk_open(struct inode *inode, struct file *filp)
diff --git a/drivers/mtd/nand/au1550nd.c b/drivers/mtd/nand/au1550nd.c
index 9c5945d..201e136 100644
--- a/drivers/mtd/nand/au1550nd.c
+++ b/drivers/mtd/nand/au1550nd.c
@@ -43,7 +43,7 @@
 /*
  * Define partitions for flash device
  */
-const static struct mtd_partition partition_info[] = {
+static const struct mtd_partition partition_info[] = {
 	{
 		.name 	= "NAND FS 0",
 	  	.offset = 0,
diff --git a/drivers/mtd/nand/rtc_from4.c b/drivers/mtd/nand/rtc_from4.c
index 3a5841c..4129c03 100644
--- a/drivers/mtd/nand/rtc_from4.c
+++ b/drivers/mtd/nand/rtc_from4.c
@@ -96,7 +96,7 @@
  */
 static void __iomem *rtc_from4_fio_base = (void *)P2SEGADDR(RTC_FROM4_FIO_BASE);
 
-const static struct mtd_partition partition_info[] = {
+static const struct mtd_partition partition_info[] = {
         {
                 .name   = "Renesas flash partition 1",
                 .offset = 0,
diff --git a/drivers/mtd/nand/spia.c b/drivers/mtd/nand/spia.c
index 32541cb..9cf1ce7 100644
--- a/drivers/mtd/nand/spia.c
+++ b/drivers/mtd/nand/spia.c
@@ -67,7 +67,7 @@
 /*
  * Define partitions for flash device
  */
-const static struct mtd_partition partition_info[] = {
+static const struct mtd_partition partition_info[] = {
 	{
 		.name	= "SPIA flash partition 1",
 		.offset	= 0,
diff --git a/drivers/net/8139too.c b/drivers/net/8139too.c
index d2102a2..adfba44 100644
--- a/drivers/net/8139too.c
+++ b/drivers/net/8139too.c
@@ -505,7 +505,7 @@
 #define HW_REVID_MASK	HW_REVID(1, 1, 1, 1, 1, 1, 1)
 
 /* directly indexed by chip_t, above */
-const static struct {
+static const struct {
 	const char *name;
 	u32 version; /* from RTL8139C/RTL8139D docs */
 	u32 flags;
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 4959800..5c15f3e 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -1397,7 +1397,7 @@
 
 	  To compile this driver as a module, choose M here and read
 	  <file:Documentation/networking/net-modules.txt>.  The module will be
-	  called cs89x.
+	  called cs89x0.
 
 config TC35815
 	tristate "TOSHIBA TC35815 Ethernet support"
@@ -1804,7 +1804,7 @@
 
 config FEC
 	bool "FEC ethernet controller (of ColdFire CPUs)"
-	depends on M523x || M527x || M5272 || M528x
+	depends on M523x || M527x || M5272 || M528x || M520x
 	help
 	  Say Y here if you want to use the built-in 10/100 Fast ethernet
 	  controller on some Motorola ColdFire processors.
diff --git a/drivers/net/cs89x0.c b/drivers/net/cs89x0.c
index 907c010..e2cfde7 100644
--- a/drivers/net/cs89x0.c
+++ b/drivers/net/cs89x0.c
@@ -100,7 +100,7 @@
  * Note that even if DMA is turned off we still support the 'dma' and  'use_dma'
  * module options so we don't break any startup scripts.
  */
-#ifndef CONFIG_ARCH_IXDP2X01
+#ifndef CONFIG_ISA_DMA_API
 #define ALLOW_DMA	0
 #else
 #define ALLOW_DMA	1
diff --git a/drivers/net/gianfar_sysfs.c b/drivers/net/gianfar_sysfs.c
index 10d34cb..51ef181 100644
--- a/drivers/net/gianfar_sysfs.c
+++ b/drivers/net/gianfar_sysfs.c
@@ -7,7 +7,7 @@
  * Based on 8260_io/fcc_enet.c
  *
  * Author: Andy Fleming
- * Maintainer: Kumar Gala (kumar.gala@freescale.com)
+ * Maintainer: Kumar Gala (galak@kernel.crashing.org)
  *
  * Copyright (c) 2002-2005 Freescale Semiconductor, Inc.
  *
diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
index 9099986..102c1f0 100644
--- a/drivers/net/hamradio/6pack.c
+++ b/drivers/net/hamradio/6pack.c
@@ -456,11 +456,6 @@
 
 /* ----------------------------------------------------------------------- */
 
-static int sixpack_receive_room(struct tty_struct *tty)
-{
-	return 65536;  /* We can handle an infinite amount of data. :-) */
-}
-
 /*
  * Handle the 'receiver data ready' interrupt.
  * This function is called by the 'tty_io' module in the kernel when
@@ -671,6 +666,7 @@
 
 	/* Done.  We have linked the TTY line to a channel. */
 	tty->disc_data = sp;
+	tty->receive_room = 65536;
 
 	/* Now we're ready to register. */
 	if (register_netdev(dev))
@@ -802,7 +798,6 @@
 	.close		= sixpack_close,
 	.ioctl		= sixpack_ioctl,
 	.receive_buf	= sixpack_receive_buf,
-	.receive_room	= sixpack_receive_room,
 	.write_wakeup	= sixpack_write_wakeup,
 };
 
diff --git a/drivers/net/hamradio/mkiss.c b/drivers/net/hamradio/mkiss.c
index f4424cf..dc5e9d5 100644
--- a/drivers/net/hamradio/mkiss.c
+++ b/drivers/net/hamradio/mkiss.c
@@ -753,6 +753,7 @@
 
 	ax->tty = tty;
 	tty->disc_data = ax;
+	tty->receive_room = 65535;
 
 	if (tty->driver->flush_buffer)
 		tty->driver->flush_buffer(tty);
@@ -940,11 +941,6 @@
 		tty->driver->unthrottle(tty);
 }
 
-static int mkiss_receive_room(struct tty_struct *tty)
-{
-	return 65536;  /* We can handle an infinite amount of data. :-) */
-}
-
 /*
  * Called by the driver when there's room for more data.  If we have
  * more packets to send, we send them here.
@@ -983,7 +979,6 @@
 	.close		= mkiss_close,
 	.ioctl		= mkiss_ioctl,
 	.receive_buf	= mkiss_receive_buf,
-	.receive_room	= mkiss_receive_room,
 	.write_wakeup	= mkiss_write_wakeup
 };
 
diff --git a/drivers/net/hplance.c b/drivers/net/hplance.c
index 08703d6..d841063 100644
--- a/drivers/net/hplance.c
+++ b/drivers/net/hplance.c
@@ -150,7 +150,7 @@
         lp->lance.name = (char*)d->name;                /* discards const, shut up gcc */
         lp->lance.base = va;
         lp->lance.init_block = (struct lance_init_block *)(va + HPLANCE_MEMOFF); /* CPU addr */
-        lp->lance.lance_init_block = 0;                 /* LANCE addr of same RAM */
+        lp->lance.lance_init_block = NULL;              /* LANCE addr of same RAM */
         lp->lance.busmaster_regval = LE_C3_BSWP;        /* we're bigendian */
         lp->lance.irq = d->ipl;
         lp->lance.writerap = hplance_writerap;
diff --git a/drivers/net/irda/Kconfig b/drivers/net/irda/Kconfig
index d54156f..7a08134 100644
--- a/drivers/net/irda/Kconfig
+++ b/drivers/net/irda/Kconfig
@@ -1,4 +1,3 @@
-
 menu "Infrared-port device drivers"
 	depends on IRDA!=n
 
@@ -156,7 +155,7 @@
 
 config DONGLE_OLD
 	bool "Old Serial dongle support"
-	depends on (IRTTY_OLD || IRPORT_SIR) && BROKEN_ON_SMP
+	depends on IRPORT_SIR && BROKEN_ON_SMP
 	help
 	  Say Y here if you have an infrared device that connects to your
 	  computer's serial port. These devices are called dongles. Then say Y
diff --git a/drivers/net/irda/Makefile b/drivers/net/irda/Makefile
index e7a8b7f..72cbfdc 100644
--- a/drivers/net/irda/Makefile
+++ b/drivers/net/irda/Makefile
@@ -45,4 +45,4 @@
 obj-$(CONFIG_MA600_DONGLE)	+= ma600-sir.o
 
 # The SIR helper module
-sir-dev-objs := sir_core.o sir_dev.o sir_dongle.o sir_kthread.o
+sir-dev-objs := sir_dev.o sir_dongle.o sir_kthread.o
diff --git a/drivers/net/irda/irport.c b/drivers/net/irda/irport.c
index 3d016a4..6070195 100644
--- a/drivers/net/irda/irport.c
+++ b/drivers/net/irda/irport.c
@@ -285,19 +285,6 @@
 }
 
 /*
- * Function irport_probe (void)
- *
- *    Start IO port 
- *
- */
-int irport_probe(int iobase)
-{
-	IRDA_DEBUG(4, "%s(), iobase=%#x\n", __FUNCTION__, iobase);
-
-	return 0;
-}
-
-/*
  * Function irport_get_fcr (speed)
  *
  *    Compute value of fcr
@@ -382,7 +369,7 @@
  *    we cannot use schedule_timeout() when we are in interrupt context
  *
  */
-int __irport_change_speed(struct irda_task *task)
+static int __irport_change_speed(struct irda_task *task)
 {
 	struct irport_cb *self;
 	__u32 speed = (__u32) task->param;
diff --git a/drivers/net/irda/irtty-sir.c b/drivers/net/irda/irtty-sir.c
index b8d1123..101750b 100644
--- a/drivers/net/irda/irtty-sir.c
+++ b/drivers/net/irda/irtty-sir.c
@@ -289,22 +289,6 @@
 }
 
 /*
- * Function irtty_receive_room (tty)
- *
- *    Used by the TTY to find out how much data we can receive at a time
- * 
-*/
-static int irtty_receive_room(struct tty_struct *tty) 
-{
-	struct sirtty_cb *priv = tty->disc_data;
-
-	IRDA_ASSERT(priv != NULL, return 0;);
-	IRDA_ASSERT(priv->magic == IRTTY_MAGIC, return 0;);
-
-	return 65536;  /* We can handle an infinite amount of data. :-) */
-}
-
-/*
  * Function irtty_write_wakeup (tty)
  *
  *    Called by the driver when there's room for more data.  If we have
@@ -534,6 +518,7 @@
 
 	dev->priv = priv;
 	tty->disc_data = priv;
+	tty->receive_room = 65536;
 
 	up(&irtty_sem);
 
@@ -605,7 +590,6 @@
 	.ioctl		= irtty_ioctl,
  	.poll		= NULL,
 	.receive_buf	= irtty_receive_buf,
-	.receive_room	= irtty_receive_room,
 	.write_wakeup	= irtty_write_wakeup,
 	.owner		= THIS_MODULE,
 };
diff --git a/drivers/net/irda/sir-dev.h b/drivers/net/irda/sir-dev.h
index f0b8bc3..f69fb4c 100644
--- a/drivers/net/irda/sir-dev.h
+++ b/drivers/net/irda/sir-dev.h
@@ -133,8 +133,6 @@
 
 extern void sirdev_enable_rx(struct sir_dev *dev);
 extern int sirdev_schedule_request(struct sir_dev *dev, int state, unsigned param);
-extern int __init irda_thread_create(void);
-extern void __exit irda_thread_join(void);
 
 /* inline helpers */
 
diff --git a/drivers/net/irda/sir_core.c b/drivers/net/irda/sir_core.c
deleted file mode 100644
index a49f910..0000000
--- a/drivers/net/irda/sir_core.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*********************************************************************
- *
- *	sir_core.c:	module core for irda-sir abstraction layer
- *
- *	Copyright (c) 2002 Martin Diehl
- * 
- *	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.
- *
- ********************************************************************/    
-
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/init.h>
-
-#include <net/irda/irda.h>
-
-#include "sir-dev.h"
-
-/***************************************************************************/
-
-MODULE_AUTHOR("Martin Diehl <info@mdiehl.de>");
-MODULE_DESCRIPTION("IrDA SIR core");
-MODULE_LICENSE("GPL");
-
-/***************************************************************************/
-
-EXPORT_SYMBOL(irda_register_dongle);
-EXPORT_SYMBOL(irda_unregister_dongle);
-
-EXPORT_SYMBOL(sirdev_get_instance);
-EXPORT_SYMBOL(sirdev_put_instance);
-
-EXPORT_SYMBOL(sirdev_set_dongle);
-EXPORT_SYMBOL(sirdev_write_complete);
-EXPORT_SYMBOL(sirdev_receive);
-
-EXPORT_SYMBOL(sirdev_raw_write);
-EXPORT_SYMBOL(sirdev_raw_read);
-EXPORT_SYMBOL(sirdev_set_dtr_rts);
-
-static int __init sir_core_init(void)
-{
-	return irda_thread_create();
-}
-
-static void __exit sir_core_exit(void)
-{
-	irda_thread_join();
-}
-
-module_init(sir_core_init);
-module_exit(sir_core_exit);
-
diff --git a/drivers/net/irda/sir_dev.c b/drivers/net/irda/sir_dev.c
index df22b8b..ea7c946 100644
--- a/drivers/net/irda/sir_dev.c
+++ b/drivers/net/irda/sir_dev.c
@@ -60,6 +60,7 @@
 	up(&dev->fsm.sem);
 	return err;
 }
+EXPORT_SYMBOL(sirdev_set_dongle);
 
 /* used by dongle drivers for dongle programming */
 
@@ -94,6 +95,7 @@
 	spin_unlock_irqrestore(&dev->tx_lock, flags);
 	return ret;
 }
+EXPORT_SYMBOL(sirdev_raw_write);
 
 /* seems some dongle drivers may need this */
 
@@ -116,6 +118,7 @@
 
 	return count;
 }
+EXPORT_SYMBOL(sirdev_raw_read);
 
 int sirdev_set_dtr_rts(struct sir_dev *dev, int dtr, int rts)
 {
@@ -124,7 +127,8 @@
 		ret =  dev->drv->set_dtr_rts(dev, dtr, rts);
 	return ret;
 }
-	
+EXPORT_SYMBOL(sirdev_set_dtr_rts);
+
 /**********************************************************************/
 
 /* called from client driver - likely with bh-context - to indicate
@@ -227,6 +231,7 @@
 done:
 	spin_unlock_irqrestore(&dev->tx_lock, flags);
 }
+EXPORT_SYMBOL(sirdev_write_complete);
 
 /* called from client driver - likely with bh-context - to give us
  * some more received bytes. We put them into the rx-buffer,
@@ -279,6 +284,7 @@
 
 	return 0;
 }
+EXPORT_SYMBOL(sirdev_receive);
 
 /**********************************************************************/
 
@@ -641,6 +647,7 @@
 out:
 	return NULL;
 }
+EXPORT_SYMBOL(sirdev_get_instance);
 
 int sirdev_put_instance(struct sir_dev *dev)
 {
@@ -673,4 +680,5 @@
 
 	return 0;
 }
+EXPORT_SYMBOL(sirdev_put_instance);
 
diff --git a/drivers/net/irda/sir_dongle.c b/drivers/net/irda/sir_dongle.c
index c5b7674..8d22592 100644
--- a/drivers/net/irda/sir_dongle.c
+++ b/drivers/net/irda/sir_dongle.c
@@ -50,6 +50,7 @@
 	up(&dongle_list_lock);
 	return 0;
 }
+EXPORT_SYMBOL(irda_register_dongle);
 
 int irda_unregister_dongle(struct dongle_driver *drv)
 {
@@ -58,6 +59,7 @@
 	up(&dongle_list_lock);
 	return 0;
 }
+EXPORT_SYMBOL(irda_unregister_dongle);
 
 int sirdev_get_dongle(struct sir_dev *dev, IRDA_DONGLE type)
 {
diff --git a/drivers/net/irda/sir_kthread.c b/drivers/net/irda/sir_kthread.c
index c650543..e3904d6 100644
--- a/drivers/net/irda/sir_kthread.c
+++ b/drivers/net/irda/sir_kthread.c
@@ -466,7 +466,7 @@
 	return 0;
 }
 
-int __init irda_thread_create(void)
+static int __init irda_thread_create(void)
 {
 	struct completion startup;
 	int pid;
@@ -488,7 +488,7 @@
 	return 0;
 }
 
-void __exit irda_thread_join(void) 
+static void __exit irda_thread_join(void)
 {
 	if (irda_rq_queue.thread) {
 		flush_irda_queue();
@@ -499,3 +499,10 @@
 	}
 }
 
+module_init(irda_thread_create);
+module_exit(irda_thread_join);
+
+MODULE_AUTHOR("Martin Diehl <info@mdiehl.de>");
+MODULE_DESCRIPTION("IrDA SIR core");
+MODULE_LICENSE("GPL");
+
diff --git a/drivers/net/iseries_veth.c b/drivers/net/iseries_veth.c
index 77eadf8..f0f04be 100644
--- a/drivers/net/iseries_veth.c
+++ b/drivers/net/iseries_veth.c
@@ -590,9 +590,9 @@
 {
 	struct veth_lpevent *veth_event = (struct veth_lpevent *)event;
 
-	if (event->xFlags.xFunction == HvLpEvent_Function_Ack)
+	if (hvlpevent_is_ack(event))
 		veth_handle_ack(veth_event);
-	else if (event->xFlags.xFunction == HvLpEvent_Function_Int)
+	else
 		veth_handle_int(veth_event);
 }
 
diff --git a/drivers/net/mac8390.c b/drivers/net/mac8390.c
index d8c99f0..06cb460 100644
--- a/drivers/net/mac8390.c
+++ b/drivers/net/mac8390.c
@@ -559,55 +559,52 @@
 /* directly from daynaport.c by Alan Cox */
 static void dayna_memcpy_fromcard(struct net_device *dev, void *to, int from, int count)
 {
-	volatile unsigned short *ptr;
-	unsigned short *target=to;
+	volatile unsigned char *ptr;
+	unsigned char *target=to;
 	from<<=1;	/* word, skip overhead */
-	ptr=(unsigned short *)(dev->mem_start+from);
+	ptr=(unsigned char *)(dev->mem_start+from);
 	/* Leading byte? */
 	if (from&2) {
-		*((char *)target)++ = *(((char *)ptr++)-1);
+		*target++ = ptr[-1];
+		ptr += 2;
 		count--;
 	}
 	while(count>=2)
 	{
-		*target++=*ptr++;	/* Copy and */
-		ptr++;			/* skip cruft */
+		*(unsigned short *)target = *(unsigned short volatile *)ptr;
+		ptr += 4;			/* skip cruft */
+		target += 2;
 		count-=2;
 	}
 	/* Trailing byte? */
 	if(count)
-	{
-		/* Big endian */
-		unsigned short v=*ptr;
-		*((char *)target)=v>>8;
-	}
+		*target = *ptr;
 }
 
 static void dayna_memcpy_tocard(struct net_device *dev, int to, const void *from, int count)
 {
 	volatile unsigned short *ptr;
-	const unsigned short *src=from;
+	const unsigned char *src=from;
 	to<<=1;	/* word, skip overhead */
 	ptr=(unsigned short *)(dev->mem_start+to);
 	/* Leading byte? */
 	if (to&2) { /* avoid a byte write (stomps on other data) */
-		ptr[-1] = (ptr[-1]&0xFF00)|*((unsigned char *)src)++;
+		ptr[-1] = (ptr[-1]&0xFF00)|*src++;
 		ptr++;
 		count--;
 	}
 	while(count>=2)
 	{
-		*ptr++=*src++;		/* Copy and */
+		*ptr++=*(unsigned short *)src;		/* Copy and */
 		ptr++;			/* skip cruft */
+		src += 2;
 		count-=2;
 	}
 	/* Trailing byte? */
 	if(count)
 	{
-		/* Big endian */
-		unsigned short v=*src;
 		/* card doesn't like byte writes */
-		*ptr=(*ptr&0x00FF)|(v&0xFF00);
+		*ptr=(*ptr&0x00FF)|(*src << 8);
 	}
 }
 
diff --git a/drivers/net/pci-skeleton.c b/drivers/net/pci-skeleton.c
index a1ac4bd..a7bb54d 100644
--- a/drivers/net/pci-skeleton.c
+++ b/drivers/net/pci-skeleton.c
@@ -415,7 +415,7 @@
 
 
 /* directly indexed by chip_t, above */
-const static struct {
+static const struct {
 	const char *name;
 	u8 version; /* from RTL8139C docs */
 	u32 RxConfigMask; /* should clear the bits supported by this chip */
diff --git a/drivers/net/ppp_async.c b/drivers/net/ppp_async.c
index 400f652..aa6540b 100644
--- a/drivers/net/ppp_async.c
+++ b/drivers/net/ppp_async.c
@@ -189,7 +189,7 @@
 		goto out_free;
 
 	tty->disc_data = ap;
-
+	tty->receive_room = 65536;
 	return 0;
 
  out_free:
@@ -343,12 +343,6 @@
 	return 0;
 }
 
-static int
-ppp_asynctty_room(struct tty_struct *tty)
-{
-	return 65535;
-}
-
 /*
  * This can now be called from hard interrupt level as well
  * as soft interrupt level or mainline.
@@ -398,7 +392,6 @@
 	.write	= ppp_asynctty_write,
 	.ioctl	= ppp_asynctty_ioctl,
 	.poll	= ppp_asynctty_poll,
-	.receive_room = ppp_asynctty_room,
 	.receive_buf = ppp_asynctty_receive,
 	.write_wakeup = ppp_asynctty_wakeup,
 };
diff --git a/drivers/net/ppp_synctty.c b/drivers/net/ppp_synctty.c
index 4d51c0c..33cb825 100644
--- a/drivers/net/ppp_synctty.c
+++ b/drivers/net/ppp_synctty.c
@@ -237,7 +237,7 @@
 		goto out_free;
 
 	tty->disc_data = ap;
-
+	tty->receive_room = 65536;
 	return 0;
 
  out_free:
@@ -384,12 +384,6 @@
 	return 0;
 }
 
-static int
-ppp_sync_room(struct tty_struct *tty)
-{
-	return 65535;
-}
-
 /*
  * This can now be called from hard interrupt level as well
  * as soft interrupt level or mainline.
@@ -439,7 +433,6 @@
 	.write	= ppp_sync_write,
 	.ioctl	= ppp_synctty_ioctl,
 	.poll	= ppp_sync_poll,
-	.receive_room = ppp_sync_room,
 	.receive_buf = ppp_sync_receive,
 	.write_wakeup = ppp_sync_wakeup,
 };
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index 14a76f7..2e1bed15 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -170,7 +170,7 @@
 #define _R(NAME,MAC,MASK) \
 	{ .name = NAME, .mac_version = MAC, .RxConfigMask = MASK }
 
-const static struct {
+static const struct {
 	const char *name;
 	u8 mac_version;
 	u32 RxConfigMask;	/* Clears the bits supported by this chip */
diff --git a/drivers/net/sis190.c b/drivers/net/sis190.c
index 478791e..b420182 100644
--- a/drivers/net/sis190.c
+++ b/drivers/net/sis190.c
@@ -329,7 +329,7 @@
 	{ NULL, }
 };
 
-const static struct {
+static const struct {
 	const char *name;
 } sis_chip_info[] = {
 	{ "SiS 190 PCI Fast Ethernet adapter" },
diff --git a/drivers/net/slip.c b/drivers/net/slip.c
index 404ea42..b2e18d2 100644
--- a/drivers/net/slip.c
+++ b/drivers/net/slip.c
@@ -651,11 +651,6 @@
  ******************************************/
 
 
-static int slip_receive_room(struct tty_struct *tty)
-{
-	return 65536;  /* We can handle an infinite amount of data. :-) */
-}
-
 /*
  * Handle the 'receiver data ready' interrupt.
  * This function is called by the 'tty_io' module in the kernel when
@@ -869,10 +864,6 @@
 	sl->line = tty_devnum(tty);
 	sl->pid = current->pid;
 	
-	/* FIXME: already done before we were called - seems this can go */
-	if (tty->driver->flush_buffer)
-		tty->driver->flush_buffer(tty);
-		
 	if (!test_bit(SLF_INUSE, &sl->flags)) {
 		/* Perform the low-level SLIP initialization. */
 		if ((err = sl_alloc_bufs(sl, SL_MTU)) != 0)
@@ -897,6 +888,7 @@
 
 	/* Done.  We have linked the TTY line to a channel. */
 	rtnl_unlock();
+	tty->receive_room = 65536;	/* We don't flow control */
 	return sl->dev->base_addr;
 
 err_free_bufs:
@@ -1329,7 +1321,6 @@
 	.close	 	= slip_close,
 	.ioctl		= slip_ioctl,
 	.receive_buf	= slip_receive_buf,
-	.receive_room	= slip_receive_room,
 	.write_wakeup	= slip_write_wakeup,
 };
 
diff --git a/drivers/net/sun3lance.c b/drivers/net/sun3lance.c
index 5c8fcd4..01bdb233 100644
--- a/drivers/net/sun3lance.c
+++ b/drivers/net/sun3lance.c
@@ -389,7 +389,7 @@
 	dev->stop = &lance_close;
 	dev->get_stats = &lance_get_stats;
 	dev->set_multicast_list = &set_multicast_list;
-	dev->set_mac_address = 0;
+	dev->set_mac_address = NULL;
 //	KLUDGE -- REMOVE ME
 	set_bit(__LINK_STATE_PRESENT, &dev->state);
 
diff --git a/drivers/net/wan/pc300_tty.c b/drivers/net/wan/pc300_tty.c
index 52f26b9..931cbdf6 100644
--- a/drivers/net/wan/pc300_tty.c
+++ b/drivers/net/wan/pc300_tty.c
@@ -689,7 +689,7 @@
 					}
 				}	
 				cpc_tty->buf_rx.first = cpc_tty->buf_rx.first->next;
-				kfree(buf);
+				kfree((void *)buf);
 				buf = cpc_tty->buf_rx.first;
 				flg_rx = 1;
 			}
diff --git a/drivers/net/wan/x25_asy.c b/drivers/net/wan/x25_asy.c
index bdf672c..9c3ccc6 100644
--- a/drivers/net/wan/x25_asy.c
+++ b/drivers/net/wan/x25_asy.c
@@ -515,11 +515,6 @@
 	return 0;
 }
 
-static int x25_asy_receive_room(struct tty_struct *tty)
-{
-	return 65536;  /* We can handle an infinite amount of data. :-) */
-}
-
 /*
  * Handle the 'receiver data ready' interrupt.
  * This function is called by the 'tty_io' module in the kernel when
@@ -573,6 +568,7 @@
 
 	sl->tty = tty;
 	tty->disc_data = sl;
+	tty->receive_room = 65536;
 	if (tty->driver->flush_buffer)  {
 		tty->driver->flush_buffer(tty);
 	}
@@ -779,7 +775,6 @@
 	.close		= x25_asy_close_tty,
 	.ioctl		= x25_asy_ioctl,
 	.receive_buf	= x25_asy_receive_buf,
-	.receive_room	= x25_asy_receive_room,
 	.write_wakeup	= x25_asy_write_wakeup,
 };
 
diff --git a/drivers/net/wireless/strip.c b/drivers/net/wireless/strip.c
index d25264b..18baacf 100644
--- a/drivers/net/wireless/strip.c
+++ b/drivers/net/wireless/strip.c
@@ -1675,11 +1675,6 @@
 /************************************************************************/
 /* Receiving routines							*/
 
-static int strip_receive_room(struct tty_struct *tty)
-{
-	return 0x10000;		/* We can handle an infinite amount of data. :-) */
-}
-
 /*
  * This function parses the response to the ATS300? command,
  * extracting the radio version and serial number.
@@ -2424,7 +2419,7 @@
 /*
  * Here's the order things happen:
  * When the user runs "slattach -p strip ..."
- *  1. The TTY module calls strip_open
+ *  1. The TTY module calls strip_open;;
  *  2. strip_open calls strip_alloc
  *  3.                  strip_alloc calls register_netdev
  *  4.                  register_netdev calls strip_dev_init
@@ -2652,6 +2647,8 @@
 
 	strip_info->tty = tty;
 	tty->disc_data = strip_info;
+	tty->receive_room = 65536;
+
 	if (tty->driver->flush_buffer)
 		tty->driver->flush_buffer(tty);
 
@@ -2762,7 +2759,6 @@
 	.close = strip_close,
 	.ioctl = strip_ioctl,
 	.receive_buf = strip_receive_buf,
-	.receive_room = strip_receive_room,
 	.write_wakeup = strip_write_some_more,
 };
 
diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
index 166bca7..b80318f 100644
--- a/drivers/oprofile/event_buffer.c
+++ b/drivers/oprofile/event_buffer.c
@@ -15,6 +15,7 @@
 #include <linux/vmalloc.h>
 #include <linux/oprofile.h>
 #include <linux/sched.h>
+#include <linux/capability.h>
 #include <linux/dcookies.h>
 #include <linux/fs.h>
 #include <asm/uaccess.h>
diff --git a/drivers/parisc/dino.c b/drivers/parisc/dino.c
index 5ab7533..216d1d8 100644
--- a/drivers/parisc/dino.c
+++ b/drivers/parisc/dino.c
@@ -83,7 +83,8 @@
 ** bus number for each dino.
 */
 
-#define is_card_dino(id) ((id)->hw_type == HPHW_A_DMA)
+#define is_card_dino(id)	((id)->hw_type == HPHW_A_DMA)
+#define is_cujo(id)		((id)->hversion == 0x682)
 
 #define DINO_IAR0		0x004
 #define DINO_IODC_ADDR		0x008
@@ -124,6 +125,7 @@
 
 #define DINO_IRQS 11		/* bits 0-10 are architected */
 #define DINO_IRR_MASK	0x5ff	/* only 10 bits are implemented */
+#define DINO_LOCAL_IRQS (DINO_IRQS+1)
 
 #define DINO_MASK_IRQ(x)	(1<<(x))
 
@@ -146,7 +148,7 @@
 	unsigned long		txn_addr; /* EIR addr to generate interrupt */ 
 	u32			txn_data; /* EIR data assign to each dino */ 
 	u32 			imr;	  /* IRQ's which are enabled */ 
-	int			global_irq[12]; /* map IMR bit to global irq */
+	int			global_irq[DINO_LOCAL_IRQS]; /* map IMR bit to global irq */
 #ifdef DINO_DEBUG
 	unsigned int		dino_irr0; /* save most recent IRQ line stat */
 #endif
@@ -297,7 +299,7 @@
 static void dino_disable_irq(unsigned int irq)
 {
 	struct dino_device *dino_dev = irq_desc[irq].handler_data;
-	int local_irq = gsc_find_local_irq(irq, dino_dev->global_irq, irq);
+	int local_irq = gsc_find_local_irq(irq, dino_dev->global_irq, DINO_LOCAL_IRQS);
 
 	DBG(KERN_WARNING "%s(0x%p, %d)\n", __FUNCTION__, dino_dev, irq);
 
@@ -309,7 +311,7 @@
 static void dino_enable_irq(unsigned int irq)
 {
 	struct dino_device *dino_dev = irq_desc[irq].handler_data;
-	int local_irq = gsc_find_local_irq(irq, dino_dev->global_irq, irq);
+	int local_irq = gsc_find_local_irq(irq, dino_dev->global_irq, DINO_LOCAL_IRQS);
 	u32 tmp;
 
 	DBG(KERN_WARNING "%s(0x%p, %d)\n", __FUNCTION__, dino_dev, irq);
@@ -435,6 +437,21 @@
 	dino_assign_irq(dino, irq, &dev->irq);
 }
 
+
+/*
+ * Cirrus 6832 Cardbus reports wrong irq on RDI Tadpole PARISC Laptop (deller@gmx.de)
+ * (the irqs are off-by-one, not sure yet if this is a cirrus, dino-hardware or dino-driver problem...)
+ */
+static void __devinit quirk_cirrus_cardbus(struct pci_dev *dev)
+{
+	u8 new_irq = dev->irq - 1;
+	printk(KERN_INFO "PCI: Cirrus Cardbus IRQ fixup for %s, from %d to %d\n",
+			pci_name(dev), dev->irq, new_irq);
+	dev->irq = new_irq;
+}
+DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_6832, quirk_cirrus_cardbus );
+
+
 static void __init
 dino_bios_init(void)
 {
@@ -666,7 +683,6 @@
 			printk(KERN_WARNING "Device %s has unassigned IRQ\n", pci_name(dev));
 #endif
 		} else {
-
 			/* Adjust INT_LINE for that busses region */
 			dino_assign_irq(dino_dev, dev->irq, &dev->irq);
 		}
@@ -872,7 +888,7 @@
 
 	/* allocate I/O Port resource region */
 	res = &dino_dev->hba.io_space;
-	if (dev->id.hversion == 0x680 || is_card_dino(&dev->id)) {
+	if (!is_cujo(&dev->id)) {
 		res->name = "Dino I/O Port";
 	} else {
 		res->name = "Cujo I/O Port";
@@ -927,7 +943,7 @@
 	if (is_card_dino(&dev->id)) {
 		version = "3.x (card mode)";
 	} else {
-		if(dev->id.hversion == 0x680) {
+		if (!is_cujo(&dev->id)) {
 			if (dev->id.hversion_rev < 4) {
 				version = dino_vers[dev->id.hversion_rev];
 			}
diff --git a/drivers/parisc/eisa.c b/drivers/parisc/eisa.c
index 6362bf9..3d94d86 100644
--- a/drivers/parisc/eisa.c
+++ b/drivers/parisc/eisa.c
@@ -57,7 +57,7 @@
 
 static DEFINE_SPINLOCK(eisa_irq_lock);
 
-void __iomem *eisa_eeprom_addr;
+void __iomem *eisa_eeprom_addr __read_mostly;
 
 /* We can only have one EISA adapter in the system because neither
  * implementation can be flexed.
@@ -141,7 +141,7 @@
  * in the furure. 
  */
 /* irq 13,8,2,1,0 must be edge */
-static unsigned int eisa_irq_level; /* default to edge triggered */
+static unsigned int eisa_irq_level __read_mostly; /* default to edge triggered */
 
 
 /* called by free irq */
diff --git a/drivers/parisc/eisa_eeprom.c b/drivers/parisc/eisa_eeprom.c
index 3a1b482..e13aafa 100644
--- a/drivers/parisc/eisa_eeprom.c
+++ b/drivers/parisc/eisa_eeprom.c
@@ -48,7 +48,7 @@
 }
 
 static ssize_t eisa_eeprom_read(struct file * file,
-			      char *buf, size_t count, loff_t *ppos )
+			      char __user *buf, size_t count, loff_t *ppos )
 {
 	unsigned char *tmp;
 	ssize_t ret;
diff --git a/drivers/parisc/lasi.c b/drivers/parisc/lasi.c
index a8c2039..2b3ba1d 100644
--- a/drivers/parisc/lasi.c
+++ b/drivers/parisc/lasi.c
@@ -150,7 +150,7 @@
  * 
  */
 
-static unsigned long lasi_power_off_hpa;
+static unsigned long lasi_power_off_hpa __read_mostly;
 
 static void lasi_power_off(void)
 {
diff --git a/drivers/parisc/lba_pci.c b/drivers/parisc/lba_pci.c
index 5e495dc..cbae8c8 100644
--- a/drivers/parisc/lba_pci.c
+++ b/drivers/parisc/lba_pci.c
@@ -167,7 +167,7 @@
 
 /* non-postable I/O port space, densely packed */
 #define LBA_PORT_BASE	(PCI_F_EXTEND | 0xfee00000UL)
-static void __iomem *astro_iop_base;
+static void __iomem *astro_iop_base __read_mostly;
 
 #define ELROY_HVERS	0x782
 #define MERCURY_HVERS	0x783
@@ -695,12 +695,72 @@
 		}
 	}
 }
-#else
-#define lba_claim_dev_resources(dev)
-#endif
 
 
 /*
+ * truncate_pat_collision:  Deal with overlaps or outright collisions
+ *			between PAT PDC reported ranges.
+ *
+ *   Broken PA8800 firmware will report lmmio range that
+ *   overlaps with CPU HPA. Just truncate the lmmio range.
+ *
+ *   BEWARE: conflicts with this lmmio range may be an
+ *   elmmio range which is pointing down another rope.
+ *
+ *  FIXME: only deals with one collision per range...theoretically we
+ *  could have several. Supporting more than one collision will get messy.
+ */
+static unsigned long
+truncate_pat_collision(struct resource *root, struct resource *new)
+{
+	unsigned long start = new->start;
+	unsigned long end = new->end;
+	struct resource *tmp = root->child;
+
+	if (end <= start || start < root->start || !tmp)
+		return 0;
+
+	/* find first overlap */
+	while (tmp && tmp->end < start)
+		tmp = tmp->sibling;
+
+	/* no entries overlap */
+	if (!tmp)  return 0;
+
+	/* found one that starts behind the new one
+	** Don't need to do anything.
+	*/
+	if (tmp->start >= end) return 0;
+
+	if (tmp->start <= start) {
+		/* "front" of new one overlaps */
+		new->start = tmp->end + 1;
+
+		if (tmp->end >= end) {
+			/* AACCKK! totally overlaps! drop this range. */
+			return 1;
+		}
+	} 
+
+	if (tmp->end < end ) {
+		/* "end" of new one overlaps */
+		new->end = tmp->start - 1;
+	}
+
+	printk(KERN_WARNING "LBA: Truncating lmmio_space [%lx/%lx] "
+					"to [%lx,%lx]\n",
+			start, end,
+			new->start, new->end );
+
+	return 0;	/* truncation successful */
+}
+
+#else
+#define lba_claim_dev_resources(dev) do { } while (0)
+#define truncate_pat_collision(r,n)  (0)
+#endif
+
+/*
 ** The algorithm is generic code.
 ** But it needs to access local data structures to get the IRQ base.
 ** Could make this a "pci_fixup_irq(bus, region)" but not sure
@@ -747,6 +807,9 @@
 			lba_dump_res(&ioport_resource, 2);
 			BUG();
 		}
+		/* advertize Host bridge resources to PCI bus */
+		bus->resource[0] = &(ldev->hba.io_space);
+		i = 1;
 
 		if (ldev->hba.elmmio_space.start) {
 			err = request_resource(&iomem_resource,
@@ -760,23 +823,35 @@
 
 				/* lba_dump_res(&iomem_resource, 2); */
 				/* BUG(); */
-			}
+			} else
+				bus->resource[i++] = &(ldev->hba.elmmio_space);
 		}
 
-		err = request_resource(&iomem_resource, &(ldev->hba.lmmio_space));
-		if (err < 0) {
-			/*   FIXME  overlaps with elmmio will fail here.
-			 *   Need to prune (or disable) the distributed range.
-			 *
-			 *   BEWARE: conflicts with this lmmio range may be
-			 *   elmmio range which is pointing down another rope.
-			 */
 
-			printk("FAILED: lba_fixup_bus() request for "
+		/*   Overlaps with elmmio can (and should) fail here.
+		 *   We will prune (or ignore) the distributed range.
+		 *
+		 *   FIXME: SBA code should register all elmmio ranges first.
+		 *      that would take care of elmmio ranges routed
+		 *	to a different rope (already discovered) from
+		 *	getting registered *after* LBA code has already
+		 *	registered it's distributed lmmio range.
+		 */
+		if (truncate_pat_collision(&iomem_resource,
+				       	&(ldev->hba.lmmio_space))) {
+
+			printk(KERN_WARNING "LBA: lmmio_space [%lx/%lx] duplicate!\n",
+					ldev->hba.lmmio_space.start,
+					ldev->hba.lmmio_space.end);
+		} else {
+			err = request_resource(&iomem_resource, &(ldev->hba.lmmio_space));
+			if (err < 0) {
+				printk(KERN_ERR "FAILED: lba_fixup_bus() request for "
 					"lmmio_space [%lx/%lx]\n",
 					ldev->hba.lmmio_space.start,
 					ldev->hba.lmmio_space.end);
-			/* lba_dump_res(&iomem_resource, 2); */
+			} else
+				bus->resource[i++] = &(ldev->hba.lmmio_space);
 		}
 
 #ifdef CONFIG_64BIT
@@ -791,18 +866,10 @@
 				lba_dump_res(&iomem_resource, 2);
 				BUG();
 			}
+			bus->resource[i++] = &(ldev->hba.gmmio_space);
 		}
 #endif
 
-		/* advertize Host bridge resources to PCI bus */
-		bus->resource[0] = &(ldev->hba.io_space);
-		bus->resource[1] = &(ldev->hba.lmmio_space);
-		i=2;
-		if (ldev->hba.elmmio_space.start)
-			bus->resource[i++] = &(ldev->hba.elmmio_space);
-		if (ldev->hba.gmmio_space.start)
-			bus->resource[i++] = &(ldev->hba.gmmio_space);
-			
 	}
 
 	list_for_each(ln, &bus->devices) {
diff --git a/drivers/parisc/led.c b/drivers/parisc/led.c
index 315be47..3627a2d 100644
--- a/drivers/parisc/led.c
+++ b/drivers/parisc/led.c
@@ -3,7 +3,7 @@
  *
  *      (c) Copyright 2000 Red Hat Software
  *      (c) Copyright 2000 Helge Deller <hdeller@redhat.com>
- *      (c) Copyright 2001-2004 Helge Deller <deller@gmx.de>
+ *      (c) Copyright 2001-2005 Helge Deller <deller@gmx.de>
  *      (c) Copyright 2001 Randolph Chung <tausq@debian.org>
  *
  *      This program is free software; you can redistribute it and/or modify
@@ -30,6 +30,7 @@
 #include <linux/types.h>
 #include <linux/ioport.h>
 #include <linux/utsname.h>
+#include <linux/capability.h>
 #include <linux/delay.h>
 #include <linux/netdevice.h>
 #include <linux/inetdevice.h>
@@ -56,13 +57,13 @@
    relatively large amount of CPU time, some of the calculations can be 
    turned off with the following variables (controlled via procfs) */
 
-static int led_type = -1;
+static int led_type __read_mostly = -1;
 static unsigned char lastleds;	/* LED state from most recent update */
-static unsigned int led_heartbeat = 1;
-static unsigned int led_diskio = 1;
-static unsigned int led_lanrxtx = 1;
-static char lcd_text[32];
-static char lcd_text_default[32];
+static unsigned int led_heartbeat __read_mostly = 1;
+static unsigned int led_diskio    __read_mostly = 1;
+static unsigned int led_lanrxtx   __read_mostly = 1;
+static char lcd_text[32]          __read_mostly;
+static char lcd_text_default[32]  __read_mostly;
 
 
 static struct workqueue_struct *led_wq;
@@ -108,7 +109,7 @@
 /* lcd_info is pre-initialized to the values needed to program KittyHawk LCD's 
  * HP seems to have used Sharp/Hitachi HD44780 LCDs most of the time. */
 static struct pdc_chassis_lcd_info_ret_block
-lcd_info __attribute__((aligned(8))) =
+lcd_info __attribute__((aligned(8))) __read_mostly =
 {
 	.model =		DISPLAY_MODEL_LCD,
 	.lcd_width =		16,
@@ -144,7 +145,7 @@
 device_initcall(start_task);
 
 /* ptr to LCD/LED-specific function */
-static void (*led_func_ptr) (unsigned char);
+static void (*led_func_ptr) (unsigned char) __read_mostly;
 
 #ifdef CONFIG_PROC_FS
 static int led_proc_read(char *page, char **start, off_t off, int count, 
diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
index 273a741..42a3c54 100644
--- a/drivers/parisc/pdc_stable.c
+++ b/drivers/parisc/pdc_stable.c
@@ -42,9 +42,9 @@
 
 #include <linux/module.h>
 #include <linux/init.h>
-#include <linux/sched.h>		/* for capable() */
 #include <linux/kernel.h>
 #include <linux/string.h>
+#include <linux/capability.h>
 #include <linux/ctype.h>
 #include <linux/sysfs.h>
 #include <linux/kobject.h>
@@ -56,7 +56,7 @@
 #include <asm/uaccess.h>
 #include <asm/hardware.h>
 
-#define PDCS_VERSION	"0.09"
+#define PDCS_VERSION	"0.10"
 
 #define PDCS_ADDR_PPRI	0x00
 #define PDCS_ADDR_OSID	0x40
@@ -70,7 +70,7 @@
 MODULE_LICENSE("GPL");
 MODULE_VERSION(PDCS_VERSION);
 
-static unsigned long pdcs_size = 0;
+static unsigned long pdcs_size __read_mostly;
 
 /* This struct defines what we need to deal with a parisc pdc path entry */
 struct pdcspath_entry {
@@ -194,7 +194,8 @@
 		return -EIO;
 	}
 		
-	entry->ready = 1;
+	/* kobject is already registered */
+	entry->ready = 2;
 	
 	DPRINTK("%s: device: 0x%p\n", __func__, entry->dev);
 	
@@ -653,15 +654,21 @@
 {
 	unsigned short i;
 	struct pdcspath_entry *entry;
+	int err;
 	
 	for (i = 0; (entry = pdcspath_entries[i]); i++) {
 		if (pdcspath_fetch(entry) < 0)
 			continue;
 
-		kobject_set_name(&entry->kobj, "%s", entry->name);
+		if ((err = kobject_set_name(&entry->kobj, "%s", entry->name)))
+			return err;
 		kobj_set_kset_s(entry, paths_subsys);
-		kobject_register(&entry->kobj);
-
+		if ((err = kobject_register(&entry->kobj)))
+			return err;
+		
+		/* kobject is now registered */
+		entry->ready = 2;
+		
 		if (!entry->dev)
 			continue;
 
@@ -675,14 +682,14 @@
 /**
  * pdcs_unregister_pathentries - Routine called when unregistering the module.
  */
-static inline void __exit
+static inline void
 pdcs_unregister_pathentries(void)
 {
 	unsigned short i;
 	struct pdcspath_entry *entry;
 	
 	for (i = 0; (entry = pdcspath_entries[i]); i++)
-		if (entry->ready)
+		if (entry->ready >= 2)
 			kobject_unregister(&entry->kobj);	
 }
 
@@ -704,7 +711,7 @@
 
 	/* For now we'll register the pdc subsys within this driver */
 	if ((rc = firmware_register(&pdc_subsys)))
-		return rc;
+		goto fail_firmreg;
 
 	/* Don't forget the info entry */
 	for (i = 0; (attr = pdcs_subsys_attrs[i]) && !error; i++)
@@ -713,12 +720,25 @@
 	
 	/* register the paths subsys as a subsystem of pdc subsys */
 	kset_set_kset_s(&paths_subsys, pdc_subsys);
-	subsystem_register(&paths_subsys);
+	if ((rc= subsystem_register(&paths_subsys)))
+		goto fail_subsysreg;
 
 	/* now we create all "files" for the paths subsys */
-	pdcs_register_pathentries();
+	if ((rc = pdcs_register_pathentries()))
+		goto fail_pdcsreg;
+
+	return rc;
 	
-	return 0;
+fail_pdcsreg:
+	pdcs_unregister_pathentries();
+	subsystem_unregister(&paths_subsys);
+	
+fail_subsysreg:
+	firmware_unregister(&pdc_subsys);
+	
+fail_firmreg:
+	printk(KERN_INFO "PDC Stable Storage bailing out\n");
+	return rc;
 }
 
 static void __exit
diff --git a/drivers/parisc/power.c b/drivers/parisc/power.c
index ff75e92..54b2b7f 100644
--- a/drivers/parisc/power.c
+++ b/drivers/parisc/power.c
@@ -2,7 +2,7 @@
  * linux/arch/parisc/kernel/power.c
  * HP PARISC soft power switch support driver
  *
- * Copyright (c) 2001-2002 Helge Deller <deller@gmx.de>
+ * Copyright (c) 2001-2005 Helge Deller <deller@gmx.de>
  * All rights reserved.
  *
  *
@@ -102,7 +102,7 @@
 
 static void poweroff(void)
 {
-	static int powering_off;
+	static int powering_off __read_mostly;
 
 	if (powering_off)
 		return;
@@ -113,7 +113,7 @@
 
 
 /* local time-counter for shutdown */
-static int shutdown_timer;
+static int shutdown_timer __read_mostly;
 
 /* check, give feedback and start shutdown after one second */
 static void process_shutdown(void)
@@ -139,7 +139,7 @@
 DECLARE_TASKLET_DISABLED(power_tasklet, NULL, 0);
 
 /* soft power switch enabled/disabled */
-int pwrsw_enabled = 1;
+int pwrsw_enabled __read_mostly = 1;
 
 /*
  * On gecko style machines (e.g. 712/xx and 715/xx) 
@@ -149,7 +149,7 @@
  */
 static void gecko_tasklet_func(unsigned long unused)
 {
-	if (!pwrsw_enabled)
+	if (unlikely(!pwrsw_enabled))
 		return;
 
 	if (__getDIAG(25) & 0x80000000) {
@@ -173,7 +173,7 @@
 {
         unsigned long current_status;
 	
-	if (!pwrsw_enabled)
+	if (unlikely(!pwrsw_enabled))
 		return;
 
 	current_status = gsc_readl(soft_power_reg);
diff --git a/drivers/parport/Kconfig b/drivers/parport/Kconfig
index a665951..f605dea 100644
--- a/drivers/parport/Kconfig
+++ b/drivers/parport/Kconfig
@@ -121,6 +121,7 @@
 	tristate
 	default GSC
 	depends on PARPORT
+	select PARPORT_NOT_PC
 
 config PARPORT_SUNBPP
 	tristate "Sparc hardware (EXPERIMENTAL)"
diff --git a/drivers/pcmcia/vrc4171_card.c b/drivers/pcmcia/vrc4171_card.c
index 24c547e..0574efd 100644
--- a/drivers/pcmcia/vrc4171_card.c
+++ b/drivers/pcmcia/vrc4171_card.c
@@ -1,7 +1,7 @@
 /*
  * vrc4171_card.c, NEC VRC4171 Card Controller driver for Socket Services.
  *
- * Copyright (C) 2003-2005  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ * Copyright (C) 2003-2005  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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
@@ -33,7 +33,7 @@
 #include "i82365.h"
 
 MODULE_DESCRIPTION("NEC VRC4171 Card Controllers driver for Socket Services");
-MODULE_AUTHOR("Yoichi Yuasa <yuasa@hh.iij4u.or.jp>");
+MODULE_AUTHOR("Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>");
 MODULE_LICENSE("GPL");
 
 #define CARD_MAX_SLOTS		2
diff --git a/drivers/pcmcia/vrc4173_cardu.c b/drivers/pcmcia/vrc4173_cardu.c
index b502db2..57f38db 100644
--- a/drivers/pcmcia/vrc4173_cardu.c
+++ b/drivers/pcmcia/vrc4173_cardu.c
@@ -6,7 +6,7 @@
  * 	NEC VRC4173 CARDU driver for Socket Services
  *	(This device doesn't support CardBus. it is supporting only 16bit PC Card.)
  *
- * Copyright 2002,2003 Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ * Copyright 2002,2003 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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
@@ -41,7 +41,7 @@
 #include "vrc4173_cardu.h"
 
 MODULE_DESCRIPTION("NEC VRC4173 CARDU driver for Socket Services");
-MODULE_AUTHOR("Yoichi Yuasa <yuasa@hh.iij4u.or.jp>");
+MODULE_AUTHOR("Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>");
 MODULE_LICENSE("GPL");
 
 static int vrc4173_cardu_slots;
diff --git a/drivers/pcmcia/vrc4173_cardu.h b/drivers/pcmcia/vrc4173_cardu.h
index 113726f..7d77c74 100644
--- a/drivers/pcmcia/vrc4173_cardu.h
+++ b/drivers/pcmcia/vrc4173_cardu.h
@@ -5,7 +5,7 @@
  * BRIEF MODULE DESCRIPTION
  *	Include file for NEC VRC4173 CARDU.
  *
- * Copyright 2002 Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ * Copyright 2002 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index 2472fa1..9c25654 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -1751,6 +1751,7 @@
 	.open		= dasd_open,
 	.release	= dasd_release,
 	.ioctl		= dasd_ioctl,
+	.compat_ioctl	= dasd_compat_ioctl,
 	.getgeo		= dasd_getgeo,
 };
 
diff --git a/drivers/s390/block/dasd_int.h b/drivers/s390/block/dasd_int.h
index 2fb05c4..e4b4015 100644
--- a/drivers/s390/block/dasd_int.h
+++ b/drivers/s390/block/dasd_int.h
@@ -527,6 +527,7 @@
 int  dasd_ioctl_no_register(struct module *, int, dasd_ioctl_fn_t);
 int  dasd_ioctl_no_unregister(struct module *, int, dasd_ioctl_fn_t);
 int  dasd_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
+long dasd_compat_ioctl(struct file *, unsigned int, unsigned long);
 
 /* externals in dasd_proc.c */
 int dasd_proc_init(void);
diff --git a/drivers/s390/block/dasd_ioctl.c b/drivers/s390/block/dasd_ioctl.c
index 8e4dcd5..9396fca 100644
--- a/drivers/s390/block/dasd_ioctl.c
+++ b/drivers/s390/block/dasd_ioctl.c
@@ -118,6 +118,18 @@
 	return -EINVAL;
 }
 
+long
+dasd_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
+{
+	int rval;
+
+	lock_kernel();
+	rval = dasd_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
+	unlock_kernel();
+
+	return (rval == -EINVAL) ? -ENOIOCTLCMD : rval;
+}
+
 static int
 dasd_ioctl_api_version(struct block_device *bdev, int no, long args)
 {
diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
index 75419cf..1f06091 100644
--- a/drivers/s390/char/con3215.c
+++ b/drivers/s390/char/con3215.c
@@ -16,6 +16,7 @@
 #include <linux/types.h>
 #include <linux/kdev_t.h>
 #include <linux/tty.h>
+#include <linux/tty_flip.h>
 #include <linux/vt_kern.h>
 #include <linux/init.h>
 #include <linux/console.h>
@@ -432,8 +433,6 @@
 				if (count > slen)
 					count = slen;
 			} else
-			if (count >= TTY_FLIPBUF_SIZE - tty->flip.count)
-				count = TTY_FLIPBUF_SIZE - tty->flip.count - 1;
 			EBCASC(raw->inbuf, count);
 			cchar = ctrlchar_handle(raw->inbuf, count, tty);
 			switch (cchar & CTRLCHAR_MASK) {
@@ -441,28 +440,20 @@
 				break;
 
 			case CTRLCHAR_CTRL:
-				tty->flip.count++;
-				*tty->flip.flag_buf_ptr++ = TTY_NORMAL;
-				*tty->flip.char_buf_ptr++ = cchar;
+				tty_insert_flip_char(tty, cchar, TTY_NORMAL);
 				tty_flip_buffer_push(raw->tty);
 				break;
 
 			case CTRLCHAR_NONE:
-				memcpy(tty->flip.char_buf_ptr,
-				       raw->inbuf, count);
 				if (count < 2 ||
-				    (strncmp(raw->inbuf+count-2, "^n", 2) &&
-				    strncmp(raw->inbuf+count-2, "\252n", 2)) ) {
-					/* don't add the auto \n */
-					tty->flip.char_buf_ptr[count] = '\n';
-					memset(tty->flip.flag_buf_ptr,
-					       TTY_NORMAL, count + 1);
+				    (strncmp(raw->inbuf+count-2, "\252n", 2) &&
+				     strncmp(raw->inbuf+count-2, "^n", 2)) ) {
+					/* add the auto \n */
+					raw->inbuf[count] = '\n';
 					count++;
 				} else
-					count-=2;
-				tty->flip.char_buf_ptr += count;
-				tty->flip.flag_buf_ptr += count;
-				tty->flip.count += count;
+					count -= 2;
+				tty_insert_flip_string(tty, raw->inbuf, count);
 				tty_flip_buffer_push(raw->tty);
 				break;
 			}
diff --git a/drivers/s390/char/fs3270.c b/drivers/s390/char/fs3270.c
index 735a7fc..5f6fa4c 100644
--- a/drivers/s390/char/fs3270.c
+++ b/drivers/s390/char/fs3270.c
@@ -319,9 +319,8 @@
 /*
  * process ioctl commands for the tube driver
  */
-static int
-fs3270_ioctl(struct inode *inode, struct file *filp,
-	     unsigned int cmd, unsigned long arg)
+static long
+fs3270_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
 	struct fs3270 *fp;
 	struct raw3270_iocb iocb;
@@ -331,6 +330,7 @@
 	if (!fp)
 		return -ENODEV;
 	rc = 0;
+	lock_kernel();
 	switch (cmd) {
 	case TUBICMD:
 		fp->read_command = arg;
@@ -356,6 +356,7 @@
 			rc = -EFAULT;
 		break;
 	}
+	unlock_kernel();
 	return rc;
 }
 
@@ -491,12 +492,13 @@
 }
 
 static struct file_operations fs3270_fops = {
-	.owner	 = THIS_MODULE,		/* owner */
-	.read	 = fs3270_read,		/* read */
-	.write	 = fs3270_write,	/* write */
-	.ioctl	 = fs3270_ioctl,	/* ioctl */
-	.open	 = fs3270_open,		/* open */
-	.release = fs3270_close,	/* release */
+	.owner		 = THIS_MODULE,		/* owner */
+	.read		 = fs3270_read,		/* read */
+	.write		 = fs3270_write,	/* write */
+	.unlocked_ioctl	 = fs3270_ioctl,	/* ioctl */
+	.compat_ioctl	 = fs3270_ioctl,	/* ioctl */
+	.open	 	= fs3270_open,		/* open */
+	.release 	= fs3270_close,		/* release */
 };
 
 /*
diff --git a/drivers/s390/char/sclp_tty.c b/drivers/s390/char/sclp_tty.c
index a20d7c89..6cbf067 100644
--- a/drivers/s390/char/sclp_tty.c
+++ b/drivers/s390/char/sclp_tty.c
@@ -13,6 +13,7 @@
 #include <linux/kmod.h>
 #include <linux/tty.h>
 #include <linux/tty_driver.h>
+#include <linux/tty_flip.h>
 #include <linux/sched.h>
 #include <linux/wait.h>
 #include <linux/slab.h>
@@ -496,25 +497,19 @@
 	case CTRLCHAR_SYSRQ:
 		break;
 	case CTRLCHAR_CTRL:
-		sclp_tty->flip.count++;
-		*sclp_tty->flip.flag_buf_ptr++ = TTY_NORMAL;
-		*sclp_tty->flip.char_buf_ptr++ = cchar;
+		tty_insert_flip_char(sclp_tty, cchar, TTY_NORMAL);
 		tty_flip_buffer_push(sclp_tty);
 		break;
 	case CTRLCHAR_NONE:
 		/* send (normal) input to line discipline */
-		memcpy(sclp_tty->flip.char_buf_ptr, buf, count);
 		if (count < 2 ||
-		    (strncmp ((const char *) buf + count - 2, "^n", 2) &&
-		     strncmp ((const char *) buf + count - 2, "\0252n", 2))) {
-			sclp_tty->flip.char_buf_ptr[count] = '\n';
-			count++;
+		    (strncmp((const char *) buf + count - 2, "^n", 2) &&
+		     strncmp((const char *) buf + count - 2, "\252n", 2))) {
+			/* add the auto \n */
+			tty_insert_flip_string(sclp_tty, buf, count);
+			tty_insert_flip_char(sclp_tty, '\n', TTY_NORMAL);
 		} else
-			count -= 2;
-		memset(sclp_tty->flip.flag_buf_ptr, TTY_NORMAL, count);
-		sclp_tty->flip.char_buf_ptr += count;
-		sclp_tty->flip.flag_buf_ptr += count;
-		sclp_tty->flip.count += count;
+			tty_insert_flip_string(sclp_tty, buf, count - 2);
 		tty_flip_buffer_push(sclp_tty);
 		break;
 	}
diff --git a/drivers/s390/char/sclp_vt220.c b/drivers/s390/char/sclp_vt220.c
index 06bd858..9e02625 100644
--- a/drivers/s390/char/sclp_vt220.c
+++ b/drivers/s390/char/sclp_vt220.c
@@ -16,6 +16,7 @@
 #include <linux/kernel.h>
 #include <linux/tty.h>
 #include <linux/tty_driver.h>
+#include <linux/tty_flip.h>
 #include <linux/sched.h>
 #include <linux/errno.h>
 #include <linux/mm.h>
@@ -482,16 +483,7 @@
 		/* Send input to line discipline */
 		buffer++;
 		count--;
-		/* Prevent buffer overrun by discarding input. Note that
-		 * because buffer_push works asynchronously, we cannot wait
-		 * for the buffer to be emptied. */
-		if (count + sclp_vt220_tty->flip.count > TTY_FLIPBUF_SIZE)
-			count = TTY_FLIPBUF_SIZE - sclp_vt220_tty->flip.count;
-		memcpy(sclp_vt220_tty->flip.char_buf_ptr, buffer, count);
-		memset(sclp_vt220_tty->flip.flag_buf_ptr, TTY_NORMAL, count);
-		sclp_vt220_tty->flip.char_buf_ptr += count;
-		sclp_vt220_tty->flip.flag_buf_ptr += count;
-		sclp_vt220_tty->flip.count += count;
+		tty_insert_flip_string(sclp_vt220_tty, buffer, count);
 		tty_flip_buffer_push(sclp_vt220_tty);
 		break;
 	}
diff --git a/drivers/s390/char/tape_char.c b/drivers/s390/char/tape_char.c
index 86262a1..5ce7ca3 100644
--- a/drivers/s390/char/tape_char.c
+++ b/drivers/s390/char/tape_char.c
@@ -37,6 +37,8 @@
 static int tapechar_release(struct inode *,struct file *);
 static int tapechar_ioctl(struct inode *, struct file *, unsigned int,
 			  unsigned long);
+static long tapechar_compat_ioctl(struct file *, unsigned int,
+			  unsigned long);
 
 static struct file_operations tape_fops =
 {
@@ -44,6 +46,7 @@
 	.read = tapechar_read,
 	.write = tapechar_write,
 	.ioctl = tapechar_ioctl,
+	.compat_ioctl = tapechar_compat_ioctl,
 	.open = tapechar_open,
 	.release = tapechar_release,
 };
@@ -463,6 +466,23 @@
 	return device->discipline->ioctl_fn(device, no, data);
 }
 
+static long
+tapechar_compat_ioctl(struct file *filp, unsigned int no, unsigned long data)
+{
+	struct tape_device *device = filp->private_data;
+	int rval = -ENOIOCTLCMD;
+
+	if (device->discipline->ioctl_fn) {
+		lock_kernel();
+		rval = device->discipline->ioctl_fn(device, no, data);
+		unlock_kernel();
+		if (rval == -EINVAL)
+			rval = -ENOIOCTLCMD;
+	}
+
+	return rval;
+}
+
 /*
  * Initialize character device frontend.
  */
diff --git a/drivers/s390/crypto/z90main.c b/drivers/s390/crypto/z90main.c
index 135ae04..2f54d03 100644
--- a/drivers/s390/crypto/z90main.c
+++ b/drivers/s390/crypto/z90main.c
@@ -30,7 +30,6 @@
 #include <linux/delay.h>       // mdelay
 #include <linux/init.h>
 #include <linux/interrupt.h>   // for tasklets
-#include <linux/ioctl32.h>
 #include <linux/miscdevice.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
diff --git a/drivers/s390/net/ctctty.c b/drivers/s390/net/ctctty.c
index 968f2c1..93d1725 100644
--- a/drivers/s390/net/ctctty.c
+++ b/drivers/s390/net/ctctty.c
@@ -25,6 +25,7 @@
 #include <linux/config.h>
 #include <linux/module.h>
 #include <linux/tty.h>
+#include <linux/tty_flip.h>
 #include <linux/serial_reg.h>
 #include <linux/interrupt.h>
 #include <linux/delay.h>
@@ -101,25 +102,17 @@
 static int
 ctc_tty_try_read(ctc_tty_info * info, struct sk_buff *skb)
 {
-	int c;
 	int len;
 	struct tty_struct *tty;
 
 	DBF_TEXT(trace, 5, __FUNCTION__);
 	if ((tty = info->tty)) {
 		if (info->mcr & UART_MCR_RTS) {
-			c = TTY_FLIPBUF_SIZE - tty->flip.count;
 			len = skb->len;
-			if (c >= len) {
-				memcpy(tty->flip.char_buf_ptr, skb->data, len);
-				memset(tty->flip.flag_buf_ptr, 0, len);
-				tty->flip.count += len;
-				tty->flip.char_buf_ptr += len;
-				tty->flip.flag_buf_ptr += len;
-				tty_flip_buffer_push(tty);
-				kfree_skb(skb);
-				return 1;
-			}
+			tty_insert_flip_string(tty, skb->data, len);
+			tty_flip_buffer_push(tty);
+			kfree_skb(skb);
+			return 1;
 		}
 	}
 	return 0;
@@ -138,19 +131,12 @@
 	DBF_TEXT(trace, 5, __FUNCTION__);
 	if ((tty = info->tty)) {
 		if (info->mcr & UART_MCR_RTS) {
-			int c = TTY_FLIPBUF_SIZE - tty->flip.count;
 			struct sk_buff *skb;
 			
-			if ((c > 0) && (skb = skb_dequeue(&info->rx_queue))) {
+			if ((skb = skb_dequeue(&info->rx_queue))) {
 				int len = skb->len;
-				if (len > c)
-					len = c;
-				memcpy(tty->flip.char_buf_ptr, skb->data, len);
+				tty_insert_flip_string(tty, skb->data, len);
 				skb_pull(skb, len);
-				memset(tty->flip.flag_buf_ptr, 0, len);
-				tty->flip.count += len;
-				tty->flip.char_buf_ptr += len;
-				tty->flip.flag_buf_ptr += len;
 				tty_flip_buffer_push(tty);
 				if (skb->len > 0)
 					skb_queue_head(&info->rx_queue, skb);
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index f062ea0..6e0c059 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -45,7 +45,7 @@
 obj-$(CONFIG_BLZ2060_SCSI)	+= NCR53C9x.o	blz2060.o
 obj-$(CONFIG_BLZ1230_SCSI)	+= NCR53C9x.o	blz1230.o
 obj-$(CONFIG_FASTLANE_SCSI)	+= NCR53C9x.o	fastlane.o
-obj-$(CONFIG_OKTAGON_SCSI)	+= NCR53C9x.o	oktagon_esp.o	oktagon_io.o
+obj-$(CONFIG_OKTAGON_SCSI)	+= NCR53C9x.o	oktagon_esp_mod.o
 obj-$(CONFIG_ATARI_SCSI)	+= atari_scsi.o
 obj-$(CONFIG_MAC_SCSI)		+= mac_scsi.o
 obj-$(CONFIG_SCSI_MAC_ESP)	+= mac_esp.o	NCR53C9x.o
@@ -164,6 +164,7 @@
 zalon7xx-objs	:= zalon.o ncr53c8xx.o
 NCR_Q720_mod-objs	:= NCR_Q720.o ncr53c8xx.o
 libata-objs	:= libata-core.o libata-scsi.o
+oktagon_esp_mod-objs	:= oktagon_esp.o oktagon_io.o
 
 # Files generated that shall be removed upon make clean
 clean-files :=	53c7xx_d.h 53c700_d.h	\
diff --git a/drivers/scsi/NCR53C9x.c b/drivers/scsi/NCR53C9x.c
index 640590b..c7dd015 100644
--- a/drivers/scsi/NCR53C9x.c
+++ b/drivers/scsi/NCR53C9x.c
@@ -1799,6 +1799,7 @@
 		 */
 		int oldphase, i = 0; /* or where we left off last time ?? esp->current_data ?? */
 		int fifocnt = 0;
+		unsigned char *p = phys_to_virt((unsigned long)SCptr->SCp.ptr);
 
 		oldphase = esp_read(eregs->esp_status) & ESP_STAT_PMASK;
 
@@ -1860,7 +1861,7 @@
 
 				/* read fifo */
 				for(j=0;j<fifocnt;j++)
-					SCptr->SCp.ptr[i++] = esp_read(eregs->esp_fdata);
+					p[i++] = esp_read(eregs->esp_fdata);
 
 				ESPDATA(("(%d) ", i));
 
@@ -1882,7 +1883,7 @@
 
 				/* fill fifo */
 				for(j=0;j<this_count;j++)
-					esp_write(eregs->esp_fdata, SCptr->SCp.ptr[i++]);
+					esp_write(eregs->esp_fdata, p[i++]);
 
 				/* how many left if this goes out ?? */
 				hmuch -= this_count;
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index 3cb68af..9b9062f 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -46,7 +46,6 @@
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/syscalls.h>
-#include <linux/ioctl32.h>
 #include <linux/delay.h>
 #include <linux/smp_lock.h>
 #include <asm/semaphore.h>
diff --git a/drivers/scsi/blz1230.c b/drivers/scsi/blz1230.c
index 763e409..3867ac2 100644
--- a/drivers/scsi/blz1230.c
+++ b/drivers/scsi/blz1230.c
@@ -224,7 +224,7 @@
 static void dma_dump_state(struct NCR_ESP *esp)
 {
 	ESPLOG(("intreq:<%04x>, intena:<%04x>\n",
-		custom.intreqr, custom.intenar));
+		amiga_custom.intreqr, amiga_custom.intenar));
 }
 
 void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length)
@@ -298,7 +298,7 @@
 
 static int dma_ports_p(struct NCR_ESP *esp)
 {
-	return ((custom.intenar) & IF_PORTS);
+	return ((amiga_custom.intenar) & IF_PORTS);
 }
 
 static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
diff --git a/drivers/scsi/blz2060.c b/drivers/scsi/blz2060.c
index d72d05f..4ebe69e 100644
--- a/drivers/scsi/blz2060.c
+++ b/drivers/scsi/blz2060.c
@@ -190,7 +190,7 @@
 static void dma_dump_state(struct NCR_ESP *esp)
 {
 	ESPLOG(("intreq:<%04x>, intena:<%04x>\n",
-		custom.intreqr, custom.intenar));
+		amiga_custom.intreqr, amiga_custom.intenar));
 }
 
 static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length)
@@ -251,7 +251,7 @@
 
 static int dma_ports_p(struct NCR_ESP *esp)
 {
-	return ((custom.intenar) & IF_PORTS);
+	return ((amiga_custom.intenar) & IF_PORTS);
 }
 
 static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index 0920220..4299fab 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -20,7 +20,6 @@
 #include <linux/interrupt.h>
 #include <linux/blkdev.h>
 #include <linux/completion.h>
-#include <linux/ioctl32.h>
 #include <linux/compat.h>
 #include <linux/chio.h>			/* here are all the ioctls */
 
diff --git a/drivers/scsi/cyberstorm.c b/drivers/scsi/cyberstorm.c
index f9b940e..a4a4fac 100644
--- a/drivers/scsi/cyberstorm.c
+++ b/drivers/scsi/cyberstorm.c
@@ -223,7 +223,7 @@
 		esp->esp_id, ((struct cyber_dma_registers *)
 			      (esp->dregs))->cond_reg));
 	ESPLOG(("intreq:<%04x>, intena:<%04x>\n",
-		custom.intreqr, custom.intenar));
+		amiga_custom.intreqr, amiga_custom.intenar));
 }
 
 static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length)
@@ -322,7 +322,7 @@
 
 static int dma_ports_p(struct NCR_ESP *esp)
 {
-	return ((custom.intenar) & IF_PORTS);
+	return ((amiga_custom.intenar) & IF_PORTS);
 }
 
 static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
diff --git a/drivers/scsi/cyberstormII.c b/drivers/scsi/cyberstormII.c
index a3caabf..3a803d7 100644
--- a/drivers/scsi/cyberstormII.c
+++ b/drivers/scsi/cyberstormII.c
@@ -200,7 +200,7 @@
 		esp->esp_id, ((struct cyberII_dma_registers *)
 			      (esp->dregs))->cond_reg));
 	ESPLOG(("intreq:<%04x>, intena:<%04x>\n",
-		custom.intreqr, custom.intenar));
+		amiga_custom.intreqr, amiga_custom.intenar));
 }
 
 static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length)
@@ -259,7 +259,7 @@
 
 static int dma_ports_p(struct NCR_ESP *esp)
 {
-	return ((custom.intenar) & IF_PORTS);
+	return ((amiga_custom.intenar) & IF_PORTS);
 }
 
 static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
diff --git a/drivers/scsi/fastlane.c b/drivers/scsi/fastlane.c
index ccee68b..8ae9c40 100644
--- a/drivers/scsi/fastlane.c
+++ b/drivers/scsi/fastlane.c
@@ -268,7 +268,7 @@
 		esp->esp_id, ((struct fastlane_dma_registers *)
 			      (esp->dregs))->cond_reg));
 	ESPLOG(("intreq:<%04x>, intena:<%04x>\n",
-		custom.intreqr, custom.intenar));
+		amiga_custom.intreqr, amiga_custom.intenar));
 }
 
 static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length)
@@ -368,7 +368,7 @@
 
 static int dma_ports_p(struct NCR_ESP *esp)
 {
-	return ((custom.intenar) & IF_PORTS);
+	return ((amiga_custom.intenar) & IF_PORTS);
 }
 
 static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
diff --git a/drivers/scsi/megaraid/megaraid_mm.h b/drivers/scsi/megaraid/megaraid_mm.h
index eb8c390..3d9e67d 100644
--- a/drivers/scsi/megaraid/megaraid_mm.h
+++ b/drivers/scsi/megaraid/megaraid_mm.h
@@ -22,7 +22,6 @@
 #include <linux/moduleparam.h>
 #include <linux/pci.h>
 #include <linux/list.h>
-#include <linux/ioctl32.h>
 
 #include "mbox_defs.h"
 #include "megaraid_ioctl.h"
diff --git a/drivers/scsi/oktagon_esp.c b/drivers/scsi/oktagon_esp.c
index 5d9c9ad..dee426f 100644
--- a/drivers/scsi/oktagon_esp.c
+++ b/drivers/scsi/oktagon_esp.c
@@ -490,7 +490,7 @@
 
 static int dma_ports_p(struct NCR_ESP *esp)
 {
-	return ((custom.intenar) & IF_PORTS);
+	return ((amiga_custom.intenar) & IF_PORTS);
 }
 
 static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
diff --git a/drivers/scsi/wd33c93.c b/drivers/scsi/wd33c93.c
index fd63add..fb53eea 100644
--- a/drivers/scsi/wd33c93.c
+++ b/drivers/scsi/wd33c93.c
@@ -465,7 +465,7 @@
 	 */
 
 	cmd = (struct scsi_cmnd *) hostdata->input_Q;
-	prev = 0;
+	prev = NULL;
 	while (cmd) {
 		if (!(hostdata->busy[cmd->device->id] & (1 << cmd->device->lun)))
 			break;
@@ -1569,7 +1569,7 @@
  */
 
 	tmp = (struct scsi_cmnd *) hostdata->input_Q;
-	prev = 0;
+	prev = NULL;
 	while (tmp) {
 		if (tmp == cmd) {
 			if (prev)
diff --git a/drivers/serial/21285.c b/drivers/serial/21285.c
index b5cf394..221999b 100644
--- a/drivers/serial/21285.c
+++ b/drivers/serial/21285.c
@@ -94,15 +94,6 @@
 
 	status = *CSR_UARTFLG;
 	while (!(status & 0x10) && max_count--) {
-		if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
-			if (tty->low_latency)
-				tty_flip_buffer_push(tty);
-			/*
-			 * If this failed then we will throw away the
-			 * bytes but must do so to clear interrupts
-			 */
-		}
-
 		ch = *CSR_UARTDR;
 		flag = TTY_NORMAL;
 		port->icount.rx++;
diff --git a/drivers/serial/68328serial.c b/drivers/serial/68328serial.c
index 67e9afa..4dd5c3f 100644
--- a/drivers/serial/68328serial.c
+++ b/drivers/serial/68328serial.c
@@ -294,7 +294,7 @@
 {
 	struct tty_struct *tty = info->tty;
 	m68328_uart *uart = &uart_addr[info->line];
-	unsigned char ch;
+	unsigned char ch, flag;
 
 	/*
 	 * This do { } while() loop will get ALL chars out of Rx FIFO 
@@ -332,26 +332,24 @@
 		/*
 		 * Make sure that we do not overflow the buffer
 		 */
-		if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
+		if (tty_request_buffer_room(tty, 1) == 0) {
 			schedule_work(&tty->flip.work);
 			return;
 		}
 
+		flag = TTY_NORMAL;
+
 		if(rx & URX_PARITY_ERROR) {
-			*tty->flip.flag_buf_ptr++ = TTY_PARITY;
+			flag = TTY_PARITY;
 			status_handle(info, rx);
 		} else if(rx & URX_OVRUN) {
-			*tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
+			flag = TTY_OVERRUN;
 			status_handle(info, rx);
 		} else if(rx & URX_FRAME_ERROR) {
-			*tty->flip.flag_buf_ptr++ = TTY_FRAME;
+			flag = TTY_FRAME;
 			status_handle(info, rx);
-		} else {
-			*tty->flip.flag_buf_ptr++ = 0; /* XXX */
 		}
-                *tty->flip.char_buf_ptr++ = ch;
-		tty->flip.count++;
-
+		tty_insert_flip_char(tty, ch, flag);
 #ifndef CONFIG_XCOPILOT_BUGS
 	} while((rx = uart->urx.w) & URX_DATA_READY);
 #endif
diff --git a/drivers/serial/68360serial.c b/drivers/serial/68360serial.c
index 170c9d2..60f5a5d 100644
--- a/drivers/serial/68360serial.c
+++ b/drivers/serial/68360serial.c
@@ -394,7 +394,7 @@
 static _INLINE_ void receive_chars(ser_info_t *info)
 {
 	struct tty_struct *tty = info->tty;
-	unsigned char ch, *cp;
+	unsigned char ch, flag, *cp;
 	/*int	ignored = 0;*/
 	int	i;
 	ushort	status;
@@ -438,24 +438,15 @@
 		cp = (char *)bdp->buf;
 		status = bdp->status;
 
-		/* Check to see if there is room in the tty buffer for
-		 * the characters in our BD buffer.  If not, we exit
-		 * now, leaving the BD with the characters.  We'll pick
-		 * them up again on the next receive interrupt (which could
-		 * be a timeout).
-		 */
-		if ((tty->flip.count + i) >= TTY_FLIPBUF_SIZE)
-			break;
-
 		while (i-- > 0) {
 			ch = *cp++;
-			*tty->flip.char_buf_ptr = ch;
 			icount->rx++;
 
 #ifdef SERIAL_DEBUG_INTR
 			printk("DR%02x:%02x...", ch, status);
 #endif
-			*tty->flip.flag_buf_ptr = 0;
+			flag = TTY_NORMAL;
+
 			if (status & (BD_SC_BR | BD_SC_FR |
 				       BD_SC_PR | BD_SC_OV)) {
 				/*
@@ -490,30 +481,18 @@
 					if (info->flags & ASYNC_SAK)
 						do_SAK(tty);
 				} else if (status & BD_SC_PR)
-					*tty->flip.flag_buf_ptr = TTY_PARITY;
+					flag = TTY_PARITY;
 				else if (status & BD_SC_FR)
-					*tty->flip.flag_buf_ptr = TTY_FRAME;
-				if (status & BD_SC_OV) {
-					/*
-					 * Overrun is special, since it's
-					 * reported immediately, and doesn't
-					 * affect the current character
-					 */
-					if (tty->flip.count < TTY_FLIPBUF_SIZE) {
-						tty->flip.count++;
-						tty->flip.flag_buf_ptr++;
-						tty->flip.char_buf_ptr++;
-						*tty->flip.flag_buf_ptr =
-								TTY_OVERRUN;
-					}
-				}
+					flag = TTY_FRAME;
 			}
-			if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-				break;
-
-			tty->flip.flag_buf_ptr++;
-			tty->flip.char_buf_ptr++;
-			tty->flip.count++;
+			tty_insert_flip_char(tty, ch, flag);
+			if (status & BD_SC_OV)
+				/*
+				 * Overrun is special, since it's
+				 * reported immediately, and doesn't
+				 * affect the current character
+				 */
+				tty_insert_flip_char(tty, 0, TTY_OVERRUN);
 		}
 
 		/* This BD is ready to be used again.  Clear status.
@@ -541,12 +520,7 @@
 	/* Check to see if there is room in the tty buffer for
 	 * the break.  If not, we exit now, losing the break.  FIXME
 	 */
-	if ((tty->flip.count + 1) >= TTY_FLIPBUF_SIZE)
-		return;
-	*(tty->flip.flag_buf_ptr++) = TTY_BREAK;
-	*(tty->flip.char_buf_ptr++) = 0;
-	tty->flip.count++;
-
+	tty_insert_flip_char(tty, 0, TTY_BREAK);
 	schedule_work(&tty->flip.work);
 }
 
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index e845461..fb610c3 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -41,6 +41,7 @@
 #include <linux/serial.h>
 #include <linux/serial_8250.h>
 #include <linux/nmi.h>
+#include <linux/mutex.h>
 
 #include <asm/io.h>
 #include <asm/irq.h>
@@ -1142,19 +1143,6 @@
 	char flag;
 
 	do {
-		/* The following is not allowed by the tty layer and
-		   unsafe. It should be fixed ASAP */
-		if (unlikely(tty->flip.count >= TTY_FLIPBUF_SIZE)) {
-			if (tty->low_latency) {
-				spin_unlock(&up->port.lock);
-				tty_flip_buffer_push(tty);
-				spin_lock(&up->port.lock);
-			}
-			/*
-			 * If this failed then we will throw away the
-			 * bytes but must do so to clear interrupts
-			 */
-		}
 		ch = serial_inp(up, UART_RX);
 		flag = TTY_NORMAL;
 		up->port.icount.rx++;
@@ -2480,7 +2468,7 @@
  * 16x50 serial ports to be configured at run-time, to support PCMCIA
  * modems and PCI multiport cards.
  */
-static DECLARE_MUTEX(serial_sem);
+static DEFINE_MUTEX(serial_mutex);
 
 static struct uart_8250_port *serial8250_find_match_or_unused(struct uart_port *port)
 {
@@ -2535,7 +2523,7 @@
 	if (port->uartclk == 0)
 		return -EINVAL;
 
-	down(&serial_sem);
+	mutex_lock(&serial_mutex);
 
 	uart = serial8250_find_match_or_unused(port);
 	if (uart) {
@@ -2557,7 +2545,7 @@
 		if (ret == 0)
 			ret = uart->port.line;
 	}
-	up(&serial_sem);
+	mutex_unlock(&serial_mutex);
 
 	return ret;
 }
@@ -2574,7 +2562,7 @@
 {
 	struct uart_8250_port *uart = &serial8250_ports[line];
 
-	down(&serial_sem);
+	mutex_lock(&serial_mutex);
 	uart_remove_one_port(&serial8250_reg, &uart->port);
 	if (serial8250_isa_devs) {
 		uart->port.flags &= ~UPF_BOOT_AUTOCONF;
@@ -2584,7 +2572,7 @@
 	} else {
 		uart->port.dev = NULL;
 	}
-	up(&serial_sem);
+	mutex_unlock(&serial_mutex);
 }
 EXPORT_SYMBOL(serial8250_unregister_port);
 
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index a256a02..8437172 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -894,7 +894,7 @@
 
 config SERIAL_JSM
         tristate "Digi International NEO PCI Support"
-	depends on PCI
+	depends on PCI && BROKEN
         select SERIAL_CORE
         help
           This is a driver for Digi International's Neo series
diff --git a/drivers/serial/amba-pl010.c b/drivers/serial/amba-pl010.c
index 48f6e87..3490022 100644
--- a/drivers/serial/amba-pl010.c
+++ b/drivers/serial/amba-pl010.c
@@ -154,15 +154,6 @@
 
 	status = UART_GET_FR(port);
 	while (UART_RX_DATA(status) && max_count--) {
-		if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
-			if (tty->low_latency)
-				tty_flip_buffer_push(tty);
-			/*
-			 * If this failed then we will throw away the
-			 * bytes but must do so to clear interrupts.
-			 */
-		}
-
 		ch = UART_GET_CHAR(port);
 		flag = TTY_NORMAL;
 
diff --git a/drivers/serial/amba-pl011.c b/drivers/serial/amba-pl011.c
index 1296705..034a029 100644
--- a/drivers/serial/amba-pl011.c
+++ b/drivers/serial/amba-pl011.c
@@ -120,15 +120,6 @@
 
 	status = readw(uap->port.membase + UART01x_FR);
 	while ((status & UART01x_FR_RXFE) == 0 && max_count--) {
-		if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
-			if (tty->low_latency)
-				tty_flip_buffer_push(tty);
-			/*
-			 * If this failed then we will throw away the
-			 * bytes but must do so to clear interrupts
-			 */
-		}
-
 		ch = readw(uap->port.membase + UART01x_DR) | UART_DUMMY_DR_RX;
 		flag = TTY_NORMAL;
 		uap->port.icount.rx++;
diff --git a/drivers/serial/au1x00_uart.c b/drivers/serial/au1x00_uart.c
index a274ebf..ceb5d7f 100644
--- a/drivers/serial/au1x00_uart.c
+++ b/drivers/serial/au1x00_uart.c
@@ -241,18 +241,12 @@
 receive_chars(struct uart_8250_port *up, int *status, struct pt_regs *regs)
 {
 	struct tty_struct *tty = up->port.info->tty;
-	unsigned char ch;
+	unsigned char ch, flag;
 	int max_count = 256;
 
 	do {
-		if (unlikely(tty->flip.count >= TTY_FLIPBUF_SIZE)) {
-			tty->flip.work.func((void *)tty);
-			if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-				return; // if TTY_DONT_FLIP is set
-		}
 		ch = serial_inp(up, UART_RX);
-		*tty->flip.char_buf_ptr = ch;
-		*tty->flip.flag_buf_ptr = TTY_NORMAL;
+		flag = TTY_NORMAL;
 		up->port.icount.rx++;
 
 		if (unlikely(*status & (UART_LSR_BI | UART_LSR_PE |
@@ -292,30 +286,23 @@
 #endif
 			if (*status & UART_LSR_BI) {
 				DEBUG_INTR("handling break....");
-				*tty->flip.flag_buf_ptr = TTY_BREAK;
+				flag = TTY_BREAK;
 			} else if (*status & UART_LSR_PE)
-				*tty->flip.flag_buf_ptr = TTY_PARITY;
+				flag = TTY_PARITY;
 			else if (*status & UART_LSR_FE)
-				*tty->flip.flag_buf_ptr = TTY_FRAME;
+				flag = TTY_FRAME;
 		}
 		if (uart_handle_sysrq_char(&up->port, ch, regs))
 			goto ignore_char;
-		if ((*status & up->port.ignore_status_mask) == 0) {
-			tty->flip.flag_buf_ptr++;
-			tty->flip.char_buf_ptr++;
-			tty->flip.count++;
-		}
-		if ((*status & UART_LSR_OE) &&
-		    tty->flip.count < TTY_FLIPBUF_SIZE) {
+		if ((*status & up->port.ignore_status_mask) == 0)
+			tty_insert_flip_char(tty, ch, flag);
+		if (*status & UART_LSR_OE)
 			/*
 			 * Overrun is special, since it's reported
 			 * immediately, and doesn't affect the current
 			 * character.
 			 */
-			*tty->flip.flag_buf_ptr = TTY_OVERRUN;
-			tty->flip.flag_buf_ptr++;
-			tty->flip.char_buf_ptr++;
-			tty->flip.count++;
+			tty_insert_flip_char(tty, 0, TTY_OVERRUN);
 		}
 	ignore_char:
 		*status = serial_inp(up, UART_LSR);
diff --git a/drivers/serial/clps711x.c b/drivers/serial/clps711x.c
index 87ef368..8ef9994 100644
--- a/drivers/serial/clps711x.c
+++ b/drivers/serial/clps711x.c
@@ -104,8 +104,6 @@
 	while (!(status & SYSFLG_URXFE)) {
 		ch = clps_readl(UARTDR(port));
 
-		if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-			goto ignore_char;
 		port->icount.rx++;
 
 		flg = TTY_NORMAL;
diff --git a/drivers/serial/crisv10.c b/drivers/serial/crisv10.c
index 08c42c0..be12623 100644
--- a/drivers/serial/crisv10.c
+++ b/drivers/serial/crisv10.c
@@ -442,6 +442,7 @@
 #include <linux/init.h>
 #include <asm/uaccess.h>
 #include <linux/kernel.h>
+#include <linux/mutex.h>
 
 #include <asm/io.h>
 #include <asm/irq.h>
@@ -1315,11 +1316,7 @@
  * memory if large numbers of serial ports are open.
  */
 static unsigned char *tmp_buf;
-#ifdef DECLARE_MUTEX
-static DECLARE_MUTEX(tmp_buf_sem);
-#else
-static struct semaphore tmp_buf_sem = MUTEX;
-#endif
+static DEFINE_MUTEX(tmp_buf_mutex);
 
 /* Calculate the chartime depending on baudrate, numbor of bits etc. */
 static void update_char_time(struct e100_serial * info)
@@ -3661,7 +3658,7 @@
 	 * design.
 	 */
 	if (from_user) {
-		down(&tmp_buf_sem);
+		mutex_lock(&tmp_buf_mutex);
 		while (1) {
 			int c1;
 			c = CIRC_SPACE_TO_END(info->xmit.head,
@@ -3692,7 +3689,7 @@
 			count -= c;
 			ret += c;
 		}
-		up(&tmp_buf_sem);
+		mutex_unlock(&tmp_buf_mutex);
 	} else {
 		cli();
 		while (count) {
diff --git a/drivers/serial/dz.c b/drivers/serial/dz.c
index 4d8516d..a64ba26 100644
--- a/drivers/serial/dz.c
+++ b/drivers/serial/dz.c
@@ -216,8 +216,6 @@
 
 		if (!tty)
 			break;
-		if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-			break;
 
 		icount->rx++;
 
diff --git a/drivers/serial/icom.c b/drivers/serial/icom.c
index eb31125..144a7a3 100644
--- a/drivers/serial/icom.c
+++ b/drivers/serial/icom.c
@@ -729,19 +729,20 @@
 	unsigned short int status;
 	struct uart_icount *icount;
 	unsigned long offset;
+	unsigned char flag;
 
 	trace(icom_port, "RCV_COMPLETE", 0);
 	rcv_buff = icom_port->next_rcv;
 
 	status = cpu_to_le16(icom_port->statStg->rcv[rcv_buff].flags);
 	while (status & SA_FL_RCV_DONE) {
+		int first = -1;
 
 		trace(icom_port, "FID_STATUS", status);
 		count = cpu_to_le16(icom_port->statStg->rcv[rcv_buff].leLength);
 
+                count = tty_buffer_request_room(tty, count);
 		trace(icom_port, "RCV_COUNT", count);
-		if (count > (TTY_FLIPBUF_SIZE - tty->flip.count))
-			count = TTY_FLIPBUF_SIZE - tty->flip.count;
 
 		trace(icom_port, "REAL_COUNT", count);
 
@@ -749,15 +750,10 @@
 			cpu_to_le32(icom_port->statStg->rcv[rcv_buff].leBuffer) -
 			icom_port->recv_buf_pci;
 
-		memcpy(tty->flip.char_buf_ptr,(unsigned char *)
-		       ((unsigned long)icom_port->recv_buf + offset), count);
-
+		/* Block copy all but the last byte as this may have status */
 		if (count > 0) {
-			tty->flip.count += count - 1;
-			tty->flip.char_buf_ptr += count - 1;
-
-			memset(tty->flip.flag_buf_ptr, 0, count);
-			tty->flip.flag_buf_ptr += count - 1;
+			first = icom_port->recv_buf[offset];
+			tty_insert_flip_string(tty, icom_port->recv_buf + offset, count - 1);
 		}
 
 		icount = &icom_port->uart_port.icount;
@@ -765,12 +761,14 @@
 
 		/* Break detect logic */
 		if ((status & SA_FLAGS_FRAME_ERROR)
-		    && (tty->flip.char_buf_ptr[0] == 0x00)) {
+		    && first == 0) {
 			status &= ~SA_FLAGS_FRAME_ERROR;
 			status |= SA_FLAGS_BREAK_DET;
 			trace(icom_port, "BREAK_DET", 0);
 		}
 
+		flag = TTY_NORMAL;
+
 		if (status &
 		    (SA_FLAGS_BREAK_DET | SA_FLAGS_PARITY_ERROR |
 		     SA_FLAGS_FRAME_ERROR | SA_FLAGS_OVERRUN)) {
@@ -797,33 +795,26 @@
 			status &= icom_port->read_status_mask;
 
 			if (status & SA_FLAGS_BREAK_DET) {
-				*tty->flip.flag_buf_ptr = TTY_BREAK;
+				flag = TTY_BREAK;
 			} else if (status & SA_FLAGS_PARITY_ERROR) {
 				trace(icom_port, "PARITY_ERROR", 0);
-				*tty->flip.flag_buf_ptr = TTY_PARITY;
+				flag = TTY_PARITY;
 			} else if (status & SA_FLAGS_FRAME_ERROR)
-				*tty->flip.flag_buf_ptr = TTY_FRAME;
+				flag = TTY_FRAME;
 
-			if (status & SA_FLAGS_OVERRUN) {
-				/*
-				 * Overrun is special, since it's
-				 * reported immediately, and doesn't
-				 * affect the current character
-				 */
-				if (tty->flip.count < TTY_FLIPBUF_SIZE) {
-					tty->flip.count++;
-					tty->flip.flag_buf_ptr++;
-					tty->flip.char_buf_ptr++;
-					*tty->flip.flag_buf_ptr = TTY_OVERRUN;
-				}
-			}
 		}
 
-		tty->flip.flag_buf_ptr++;
-		tty->flip.char_buf_ptr++;
-		tty->flip.count++;
-		ignore_char:
-			icom_port->statStg->rcv[rcv_buff].flags = 0;
+		tty_insert_flip_char(tty, *(icom_port->recv_buf + offset + count - 1), flag);
+
+		if (status & SA_FLAGS_OVERRUN)
+			/*
+			 * Overrun is special, since it's
+			 * reported immediately, and doesn't
+			 * affect the current character
+			 */
+			tty_insert_flip_char(tty, 0, TTY_OVERRUN);
+ignore_char:
+		icom_port->statStg->rcv[rcv_buff].flags = 0;
 		icom_port->statStg->rcv[rcv_buff].leLength = 0;
 		icom_port->statStg->rcv[rcv_buff].WorkingLength =
 			(unsigned short int) cpu_to_le16(RCV_BUFF_SZ);
diff --git a/drivers/serial/imx.c b/drivers/serial/imx.c
index 83c4c12..5c098be 100644
--- a/drivers/serial/imx.c
+++ b/drivers/serial/imx.c
@@ -256,9 +256,6 @@
 	error_return:
 		tty_insert_flip_char(tty, rx, flg);
 
-		if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-			goto out;
-
 	ignore_char:
 		rx = URXD0((u32)sport->port.membase);
 	} while(rx & URXD_CHARRDY);
diff --git a/drivers/serial/ioc4_serial.c b/drivers/serial/ioc4_serial.c
index 771676a..1d85533 100644
--- a/drivers/serial/ioc4_serial.c
+++ b/drivers/serial/ioc4_serial.c
@@ -2327,19 +2327,13 @@
 	spin_lock_irqsave(&the_port->lock, pflags);
 	tty = info->tty;
 
-	if (request_count > TTY_FLIPBUF_SIZE - tty->flip.count)
-		request_count = TTY_FLIPBUF_SIZE - tty->flip.count;
+	request_count = tty_buffer_request_room(tty, IOC4_MAX_CHARS - 2);
 
 	if (request_count > 0) {
 		icount = &the_port->icount;
 		read_count = do_read(the_port, ch, request_count);
 		if (read_count > 0) {
-			flip = 1;
-			memcpy(tty->flip.char_buf_ptr, ch, read_count);
-			memset(tty->flip.flag_buf_ptr, TTY_NORMAL, read_count);
-			tty->flip.char_buf_ptr += read_count;
-			tty->flip.flag_buf_ptr += read_count;
-			tty->flip.count += read_count;
+			tty_insert_flip_string(tty, ch, read_count);
 			icount->rx += read_count;
 		}
 	}
diff --git a/drivers/serial/ip22zilog.c b/drivers/serial/ip22zilog.c
index ef13234..66f117d 100644
--- a/drivers/serial/ip22zilog.c
+++ b/drivers/serial/ip22zilog.c
@@ -259,13 +259,7 @@
 	struct tty_struct *tty = up->port.info->tty;	/* XXX info==NULL? */
 
 	while (1) {
-		unsigned char ch, r1;
-
-		if (unlikely(tty->flip.count >= TTY_FLIPBUF_SIZE)) {
-			tty->flip.work.func((void *)tty);
-			if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-				return;		/* XXX Ignores SysRq when we need it most. Fix. */
-		}
+		unsigned char ch, r1, flag;
 
 		r1 = read_zsreg(channel, R1);
 		if (r1 & (PAR_ERR | Rx_OVR | CRC_ERR)) {
@@ -303,8 +297,7 @@
 		}
 
 		/* A real serial line, record the character and status.  */
-		*tty->flip.char_buf_ptr = ch;
-		*tty->flip.flag_buf_ptr = TTY_NORMAL;
+		flag = TTY_NORMAL;
 		up->port.icount.rx++;
 		if (r1 & (BRK_ABRT | PAR_ERR | Rx_OVR | CRC_ERR)) {
 			if (r1 & BRK_ABRT) {
@@ -321,28 +314,21 @@
 				up->port.icount.overrun++;
 			r1 &= up->port.read_status_mask;
 			if (r1 & BRK_ABRT)
-				*tty->flip.flag_buf_ptr = TTY_BREAK;
+				flag = TTY_BREAK;
 			else if (r1 & PAR_ERR)
-				*tty->flip.flag_buf_ptr = TTY_PARITY;
+				flag = TTY_PARITY;
 			else if (r1 & CRC_ERR)
-				*tty->flip.flag_buf_ptr = TTY_FRAME;
+				flag = TTY_FRAME;
 		}
 		if (uart_handle_sysrq_char(&up->port, ch, regs))
 			goto next_char;
 
 		if (up->port.ignore_status_mask == 0xff ||
-		    (r1 & up->port.ignore_status_mask) == 0) {
-			tty->flip.flag_buf_ptr++;
-			tty->flip.char_buf_ptr++;
-			tty->flip.count++;
-		}
-		if ((r1 & Rx_OVR) &&
-		    tty->flip.count < TTY_FLIPBUF_SIZE) {
-			*tty->flip.flag_buf_ptr = TTY_OVERRUN;
-			tty->flip.flag_buf_ptr++;
-			tty->flip.char_buf_ptr++;
-			tty->flip.count++;
-		}
+		    (r1 & up->port.ignore_status_mask) == 0)
+		    	tty_insert_flip_char(tty, ch, flag);
+
+		if (r1 & Rx_OVR)
+			tty_insert_flip_char(tty, 0, TTY_OVERRUN);
 	next_char:
 		ch = readb(&channel->control);
 		ZSDELAY();
diff --git a/drivers/serial/m32r_sio.c b/drivers/serial/m32r_sio.c
index b0ecc75..b48066a 100644
--- a/drivers/serial/m32r_sio.c
+++ b/drivers/serial/m32r_sio.c
@@ -331,17 +331,12 @@
 {
 	struct tty_struct *tty = up->port.info->tty;
 	unsigned char ch;
+	unsigned char flag;
 	int max_count = 256;
 
 	do {
-		if (unlikely(tty->flip.count >= TTY_FLIPBUF_SIZE)) {
-			tty->flip.work.func((void *)tty);
-			if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-				return; // if TTY_DONT_FLIP is set
-		}
 		ch = sio_in(up, SIORXB);
-		*tty->flip.char_buf_ptr = ch;
-		*tty->flip.flag_buf_ptr = TTY_NORMAL;
+		flag = TTY_NORMAL;
 		up->port.icount.rx++;
 
 		if (unlikely(*status & (UART_LSR_BI | UART_LSR_PE |
@@ -380,30 +375,24 @@
 
 			if (*status & UART_LSR_BI) {
 				DEBUG_INTR("handling break....");
-				*tty->flip.flag_buf_ptr = TTY_BREAK;
+				flag = TTY_BREAK;
 			} else if (*status & UART_LSR_PE)
-				*tty->flip.flag_buf_ptr = TTY_PARITY;
+				flag = TTY_PARITY;
 			else if (*status & UART_LSR_FE)
-				*tty->flip.flag_buf_ptr = TTY_FRAME;
+				flag = TTY_FRAME;
 		}
 		if (uart_handle_sysrq_char(&up->port, ch, regs))
 			goto ignore_char;
-		if ((*status & up->port.ignore_status_mask) == 0) {
-			tty->flip.flag_buf_ptr++;
-			tty->flip.char_buf_ptr++;
-			tty->flip.count++;
-		}
-		if ((*status & UART_LSR_OE) &&
-		    tty->flip.count < TTY_FLIPBUF_SIZE) {
+		if ((*status & up->port.ignore_status_mask) == 0)
+			tty_insert_flip_char(tty, ch, flag);
+
+		if (*status & UART_LSR_OE) {
 			/*
 			 * Overrun is special, since it's reported
 			 * immediately, and doesn't affect the current
 			 * character.
 			 */
-			*tty->flip.flag_buf_ptr = TTY_OVERRUN;
-			tty->flip.flag_buf_ptr++;
-			tty->flip.char_buf_ptr++;
-			tty->flip.count++;
+			tty_insert_flip_char(tty, 0, TTY_OVERRUN);
 		}
 	ignore_char:
 		*status = serial_in(up, UART_LSR);
diff --git a/drivers/serial/mcfserial.c b/drivers/serial/mcfserial.c
index 47f7404..d957a3a 100644
--- a/drivers/serial/mcfserial.c
+++ b/drivers/serial/mcfserial.c
@@ -313,7 +313,7 @@
 {
 	volatile unsigned char	*uartp;
 	struct tty_struct	*tty = info->tty;
-	unsigned char		status, ch;
+	unsigned char		status, ch, flag;
 
 	if (!tty)
 		return;
@@ -321,10 +321,6 @@
 	uartp = info->addr;
 
 	while ((status = uartp[MCFUART_USR]) & MCFUART_USR_RXREADY) {
-
-		if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-			break;
-
 		ch = uartp[MCFUART_URB];
 		info->stats.rx++;
 
@@ -335,29 +331,24 @@
 		}
 #endif
 
-		tty->flip.count++;
+		flag = TTY_NORMAL;
 		if (status & MCFUART_USR_RXERR) {
 			uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETERR;
 			if (status & MCFUART_USR_RXBREAK) {
 				info->stats.rxbreak++;
-				*tty->flip.flag_buf_ptr++ = TTY_BREAK;
+				flag = TTY_BREAK;
 			} else if (status & MCFUART_USR_RXPARITY) {
 				info->stats.rxparity++;
-				*tty->flip.flag_buf_ptr++ = TTY_PARITY;
+				flag = TTY_PARITY;
 			} else if (status & MCFUART_USR_RXOVERRUN) {
 				info->stats.rxoverrun++;
-				*tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
+				flag = TTY_OVERRUN;
 			} else if (status & MCFUART_USR_RXFRAMING) {
 				info->stats.rxframing++;
-				*tty->flip.flag_buf_ptr++ = TTY_FRAME;
-			} else {
-				/* This should never happen... */
-				*tty->flip.flag_buf_ptr++ = 0;
+				flag = TTY_FRAME;
 			}
-		} else {
-			*tty->flip.flag_buf_ptr++ = 0;
 		}
-		*tty->flip.char_buf_ptr++ = ch;
+		tty_insert_flip_char(tty, ch, flag);
 	}
 
 	schedule_work(&tty->flip.work);
@@ -1525,7 +1516,7 @@
 
 	icrp = (volatile unsigned char *) (MCF_MBAR + MCFICM_INTC0 +
 		MCFINTC_ICR0 + MCFINT_UART0 + info->line);
-	*icrp = 0x33; /* UART0 with level 6, priority 3 */
+	*icrp = 0x30 + info->line; /* level 6, line based priority */
 
 	imrp = (volatile unsigned long *) (MCF_MBAR + MCFICM_INTC0 +
 		MCFINTC_IMRL);
diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
index 1288d62..61dd17d 100644
--- a/drivers/serial/mpc52xx_uart.c
+++ b/drivers/serial/mpc52xx_uart.c
@@ -405,17 +405,13 @@
 mpc52xx_uart_int_rx_chars(struct uart_port *port, struct pt_regs *regs)
 {
 	struct tty_struct *tty = port->info->tty;
-	unsigned char ch;
+	unsigned char ch, flag;
 	unsigned short status;
 
 	/* While we can read, do so ! */
 	while ( (status = in_be16(&PSC(port)->mpc52xx_psc_status)) &
 	        MPC52xx_PSC_SR_RXRDY) {
 
-		/* If we are full, just stop reading */
-		if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-			break;
-		
 		/* Get the char */
 		ch = in_8(&PSC(port)->mpc52xx_psc_buffer_8);
 
@@ -428,45 +424,35 @@
 #endif
 
 		/* Store it */
-		*tty->flip.char_buf_ptr = ch;
-		*tty->flip.flag_buf_ptr = 0;
+
+		flag = TTY_NORMAL;
 		port->icount.rx++;
 	
 		if ( status & (MPC52xx_PSC_SR_PE |
 		               MPC52xx_PSC_SR_FE |
-		               MPC52xx_PSC_SR_RB |
-		               MPC52xx_PSC_SR_OE) ) {
+		               MPC52xx_PSC_SR_RB) ) {
 			
 			if (status & MPC52xx_PSC_SR_RB) {
-				*tty->flip.flag_buf_ptr = TTY_BREAK;
+				flag = TTY_BREAK;
 				uart_handle_break(port);
 			} else if (status & MPC52xx_PSC_SR_PE)
-				*tty->flip.flag_buf_ptr = TTY_PARITY;
+				flag = TTY_PARITY;
 			else if (status & MPC52xx_PSC_SR_FE)
-				*tty->flip.flag_buf_ptr = TTY_FRAME;
-			if (status & MPC52xx_PSC_SR_OE) {
-				/*
-				 * Overrun is special, since it's
-				 * reported immediately, and doesn't
-				 * affect the current character
-				 */
-				if (tty->flip.count < (TTY_FLIPBUF_SIZE-1)) {
-					tty->flip.flag_buf_ptr++;
-					tty->flip.char_buf_ptr++;
-					tty->flip.count++;
-				}
-				*tty->flip.flag_buf_ptr = TTY_OVERRUN;
-			}
+				flag = TTY_FRAME;
 
 			/* Clear error condition */
 			out_8(&PSC(port)->command,MPC52xx_PSC_RST_ERR_STAT);
 
 		}
-
-		tty->flip.char_buf_ptr++;
-		tty->flip.flag_buf_ptr++;
-		tty->flip.count++;
-
+		tty_insert_flip_char(tty, ch, flag);
+		if (status & MPC52xx_PSC_SR_OE) {
+			/*
+			 * Overrun is special, since it's
+			 * reported immediately, and doesn't
+			 * affect the current character
+			 */
+			tty_insert_flip_char(tty, 0, TTY_OVERRUN);
+		}
 	}
 
 	tty_flip_buffer_push(tty);
diff --git a/drivers/serial/mpsc.c b/drivers/serial/mpsc.c
index 8f83e40..0ca83ac 100644
--- a/drivers/serial/mpsc.c
+++ b/drivers/serial/mpsc.c
@@ -769,12 +769,12 @@
 		bytes_in = be16_to_cpu(rxre->bytecnt);
 
 		/* Following use of tty struct directly is deprecated */
-		if (unlikely((tty->flip.count + bytes_in) >= TTY_FLIPBUF_SIZE)){
+		if (unlikely(tty_buffer_request_room(tty, bytes_in) < bytes_in)) {
 			if (tty->low_latency)
 				tty_flip_buffer_push(tty);
 			/*
-			 * If this failed then we will throw awa the bytes
-			 * but mst do so to clear interrupts.
+			 * If this failed then we will throw away the bytes
+			 * but must do so to clear interrupts.
 			 */
 		}
 
diff --git a/drivers/serial/mux.c b/drivers/serial/mux.c
index 7633132..4e49168 100644
--- a/drivers/serial/mux.c
+++ b/drivers/serial/mux.c
@@ -223,11 +223,6 @@
 		if (MUX_EOFIFO(data))
 			break;
 
-		if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-			continue;
-
-		*tty->flip.char_buf_ptr = data & 0xffu;
-		*tty->flip.flag_buf_ptr = TTY_NORMAL;
 		port->icount.rx++;
 
 		if (MUX_BREAK(data)) {
@@ -239,9 +234,7 @@
 		if (uart_handle_sysrq_char(port, data & 0xffu, NULL))
 			continue;
 
-		tty->flip.flag_buf_ptr++;
-		tty->flip.char_buf_ptr++;
-		tty->flip.count++;
+		tty_insert_flip_char(tty, data & 0xFF, TTY_NORMAL);
 	}
 	
 	if (start_count != port->icount.rx) {
diff --git a/drivers/serial/pmac_zilog.c b/drivers/serial/pmac_zilog.c
index ea24129..5f52883 100644
--- a/drivers/serial/pmac_zilog.c
+++ b/drivers/serial/pmac_zilog.c
@@ -60,6 +60,7 @@
 #include <linux/pmu.h>
 #include <linux/bitops.h>
 #include <linux/sysrq.h>
+#include <linux/mutex.h>
 #include <asm/sections.h>
 #include <asm/io.h>
 #include <asm/irq.h>
@@ -96,7 +97,7 @@
  */
 static struct uart_pmac_port	pmz_ports[MAX_ZS_PORTS];
 static int			pmz_ports_count;
-static DECLARE_MUTEX(pmz_irq_sem);
+static DEFINE_MUTEX(pmz_irq_mutex);
 
 static struct uart_driver pmz_uart_reg = {
 	.owner		=	THIS_MODULE,
@@ -210,10 +211,9 @@
 					    struct pt_regs *regs)
 {
 	struct tty_struct *tty = NULL;
-	unsigned char ch, r1, drop, error;
+	unsigned char ch, r1, drop, error, flag;
 	int loops = 0;
 
- retry:
 	/* The interrupt can be enabled when the port isn't open, typically
 	 * that happens when using one port is open and the other closed (stale
 	 * interrupt) or when one port is used as a console.
@@ -246,20 +246,6 @@
 		error = 0;
 		drop = 0;
 
-		if (unlikely(tty->flip.count >= TTY_FLIPBUF_SIZE)) {
-			/* Have to drop the lock here */
-			pmz_debug("pmz: flip overflow\n");
-			spin_unlock(&uap->port.lock);
-			tty->flip.work.func((void *)tty);
-			spin_lock(&uap->port.lock);
-			if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-				drop = 1;
-			if (ZS_IS_ASLEEP(uap))
-				return NULL;
-			if (!ZS_IS_OPEN(uap))
-				goto retry;
-		}
-
 		r1 = read_zsreg(uap, R1);
 		ch = read_zsdata(uap);
 
@@ -295,8 +281,7 @@
 		if (drop)
 			goto next_char;
 
-		*tty->flip.char_buf_ptr = ch;
-		*tty->flip.flag_buf_ptr = TTY_NORMAL;
+		flag = TTY_NORMAL;
 		uap->port.icount.rx++;
 
 		if (r1 & (PAR_ERR | Rx_OVR | CRC_ERR | BRK_ABRT)) {
@@ -316,26 +301,19 @@
 				uap->port.icount.overrun++;
 			r1 &= uap->port.read_status_mask;
 			if (r1 & BRK_ABRT)
-				*tty->flip.flag_buf_ptr = TTY_BREAK;
+				flag = TTY_BREAK;
 			else if (r1 & PAR_ERR)
-				*tty->flip.flag_buf_ptr = TTY_PARITY;
+				flag = TTY_PARITY;
 			else if (r1 & CRC_ERR)
-				*tty->flip.flag_buf_ptr = TTY_FRAME;
+				flag = TTY_FRAME;
 		}
 
 		if (uap->port.ignore_status_mask == 0xff ||
 		    (r1 & uap->port.ignore_status_mask) == 0) {
-			tty->flip.flag_buf_ptr++;
-			tty->flip.char_buf_ptr++;
-			tty->flip.count++;
+		    	tty_insert_flip_char(tty, ch, flag);
 		}
-		if ((r1 & Rx_OVR) &&
-		    tty->flip.count < TTY_FLIPBUF_SIZE) {
-			*tty->flip.flag_buf_ptr = TTY_OVERRUN;
-			tty->flip.flag_buf_ptr++;
-			tty->flip.char_buf_ptr++;
-			tty->flip.count++;
-		}
+		if (r1 & Rx_OVR)
+			tty_insert_flip_char(tty, 0, TTY_OVERRUN);
 	next_char:
 		/* We can get stuck in an infinite loop getting char 0 when the
 		 * line is in a wrong HW state, we break that here.
@@ -945,7 +923,7 @@
 	if (uap->node == NULL)
 		return -ENODEV;
 
-	down(&pmz_irq_sem);
+	mutex_lock(&pmz_irq_mutex);
 
 	uap->flags |= PMACZILOG_FLAG_IS_OPEN;
 
@@ -963,11 +941,11 @@
 		dev_err(&uap->dev->ofdev.dev,
 			"Unable to register zs interrupt handler.\n");
 		pmz_set_scc_power(uap, 0);
-		up(&pmz_irq_sem);
+		mutex_unlock(&pmz_irq_mutex);
 		return -ENXIO;
 	}
 
-	up(&pmz_irq_sem);
+	mutex_unlock(&pmz_irq_mutex);
 
 	/* Right now, we deal with delay by blocking here, I'll be
 	 * smarter later on
@@ -1004,7 +982,7 @@
 	if (uap->node == NULL)
 		return;
 
-	down(&pmz_irq_sem);
+	mutex_lock(&pmz_irq_mutex);
 
 	/* Release interrupt handler */
        	free_irq(uap->port.irq, uap);
@@ -1025,7 +1003,7 @@
 
 	if (ZS_IS_CONS(uap) || ZS_IS_ASLEEP(uap)) {
 		spin_unlock_irqrestore(&port->lock, flags);
-		up(&pmz_irq_sem);
+		mutex_unlock(&pmz_irq_mutex);
 		return;
 	}
 
@@ -1042,7 +1020,7 @@
 
 	spin_unlock_irqrestore(&port->lock, flags);
 
-	up(&pmz_irq_sem);
+	mutex_unlock(&pmz_irq_mutex);
 
 	pmz_debug("pmz: shutdown() done.\n");
 }
@@ -1614,7 +1592,7 @@
 
 	state = pmz_uart_reg.state + uap->port.line;
 
-	down(&pmz_irq_sem);
+	mutex_lock(&pmz_irq_mutex);
 	down(&state->sem);
 
 	spin_lock_irqsave(&uap->port.lock, flags);
@@ -1647,7 +1625,7 @@
 	pmz_set_scc_power(uap, 0);
 
 	up(&state->sem);
-	up(&pmz_irq_sem);
+	mutex_unlock(&pmz_irq_mutex);
 
 	pmz_debug("suspend, switching complete\n");
 
@@ -1674,7 +1652,7 @@
 
 	state = pmz_uart_reg.state + uap->port.line;
 
-	down(&pmz_irq_sem);
+	mutex_lock(&pmz_irq_mutex);
 	down(&state->sem);
 
 	spin_lock_irqsave(&uap->port.lock, flags);
@@ -1708,7 +1686,7 @@
 
  bail:
 	up(&state->sem);
-	up(&pmz_irq_sem);
+	mutex_unlock(&pmz_irq_mutex);
 
 	/* Right now, we deal with delay by blocking here, I'll be
 	 * smarter later on
diff --git a/drivers/serial/pxa.c b/drivers/serial/pxa.c
index cc998b9..10535f0 100644
--- a/drivers/serial/pxa.c
+++ b/drivers/serial/pxa.c
@@ -107,14 +107,6 @@
 	int max_count = 256;
 
 	do {
-		if (unlikely(tty->flip.count >= TTY_FLIPBUF_SIZE)) {
-			if (tty->low_latency)
-				tty_flip_buffer_push(tty);
-			/*
-			 * If this failed then we will throw away the
-			 * bytes but must do so to clear interrupts
-			 */
-		}
 		ch = serial_in(up, UART_RX);
 		flag = TTY_NORMAL;
 		up->port.icount.rx++;
diff --git a/drivers/serial/s3c2410.c b/drivers/serial/s3c2410.c
index fe83ce6..eb4883e 100644
--- a/drivers/serial/s3c2410.c
+++ b/drivers/serial/s3c2410.c
@@ -323,16 +323,6 @@
 		if (s3c24xx_serial_rx_fifocnt(ourport, ufstat) == 0)
 			break;
 
-		if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
-			if (tty->low_latency)
-				tty_flip_buffer_push(tty);
-
-			/*
-			 * If this failed then we will throw away the
-			 * bytes but must do so to clear interrupts
-			 */
-		}
-
 		uerstat = rd_regl(port, S3C2410_UERSTAT);
 		ch = rd_regb(port, S3C2410_URXH);
 
diff --git a/drivers/serial/sa1100.c b/drivers/serial/sa1100.c
index 25a0864..1bd9316 100644
--- a/drivers/serial/sa1100.c
+++ b/drivers/serial/sa1100.c
@@ -201,8 +201,6 @@
 	while (status & UTSR1_TO_SM(UTSR1_RNE)) {
 		ch = UART_GET_CHAR(sport);
 
-		if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-			goto ignore_char;
 		sport->port.icount.rx++;
 
 		flg = TTY_NORMAL;
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index 9589509..2ca6209 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -33,6 +33,7 @@
 #include <linux/device.h>
 #include <linux/serial.h> /* for serial_state and serial_icounter_struct */
 #include <linux/delay.h>
+#include <linux/mutex.h>
 
 #include <asm/irq.h>
 #include <asm/uaccess.h>
@@ -47,7 +48,7 @@
 /*
  * This is used to lock changes in serial line configuration.
  */
-static DECLARE_MUTEX(port_sem);
+static DEFINE_MUTEX(port_mutex);
 
 #define HIGH_BITS_OFFSET	((sizeof(long)-sizeof(int))*8)
 
@@ -1472,7 +1473,7 @@
 {
 	struct uart_state *state;
 
-	down(&port_sem);
+	mutex_lock(&port_mutex);
 	state = drv->state + line;
 	if (down_interruptible(&state->sem)) {
 		state = ERR_PTR(-ERESTARTSYS);
@@ -1509,7 +1510,7 @@
 	}
 
  out:
-	up(&port_sem);
+	mutex_unlock(&port_mutex);
 	return state;
 }
 
@@ -2219,7 +2220,7 @@
 
 	state = drv->state + port->line;
 
-	down(&port_sem);
+	mutex_lock(&port_mutex);
 	if (state->port) {
 		ret = -EINVAL;
 		goto out;
@@ -2255,7 +2256,7 @@
 		register_console(port->cons);
 
  out:
-	up(&port_sem);
+	mutex_unlock(&port_mutex);
 
 	return ret;
 }
@@ -2279,7 +2280,7 @@
 		printk(KERN_ALERT "Removing wrong port: %p != %p\n",
 			state->port, port);
 
-	down(&port_sem);
+	mutex_lock(&port_mutex);
 
 	/*
 	 * Remove the devices from devfs
@@ -2288,7 +2289,7 @@
 
 	uart_unconfigure_port(drv, state);
 	state->port = NULL;
-	up(&port_sem);
+	mutex_unlock(&port_mutex);
 
 	return 0;
 }
diff --git a/drivers/serial/serial_lh7a40x.c b/drivers/serial/serial_lh7a40x.c
index d01dbe5..d4a1f0e 100644
--- a/drivers/serial/serial_lh7a40x.c
+++ b/drivers/serial/serial_lh7a40x.c
@@ -148,15 +148,6 @@
 	unsigned int data, flag;/* Received data and status */
 
 	while (!(UR (port, UART_R_STATUS) & nRxRdy) && --cbRxMax) {
-		if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
-			if (tty->low_latency)
-				tty_flip_buffer_push(tty);
-			/*
-			 * If this failed then we will throw away the
-			 * bytes but must do so to clear interrupts
-			 */
-		}
-
 		data = UR (port, UART_R_DATA);
 		flag = TTY_NORMAL;
 		++port->icount.rx;
diff --git a/drivers/serial/serial_txx9.c b/drivers/serial/serial_txx9.c
index 995d9dd..ee98a86 100644
--- a/drivers/serial/serial_txx9.c
+++ b/drivers/serial/serial_txx9.c
@@ -52,6 +52,7 @@
 #include <linux/tty_flip.h>
 #include <linux/serial_core.h>
 #include <linux/serial.h>
+#include <linux/mutex.h>
 
 #include <asm/io.h>
 #include <asm/irq.h>
@@ -303,17 +304,6 @@
 	char flag;
 
 	do {
-		/* The following is not allowed by the tty layer and
-		   unsafe. It should be fixed ASAP */
-		if (unlikely(tty->flip.count >= TTY_FLIPBUF_SIZE)) {
-			if (tty->low_latency) {
-				spin_unlock(&up->port.lock);
-				tty_flip_buffer_push(tty);
-				spin_lock(&up->port.lock);
-			}
-			/* If this failed then we will throw away the
-			   bytes but must do so to clear interrupts */
-		}
 		ch = sio_in(up, TXX9_SIRFIFO);
 		flag = TTY_NORMAL;
 		up->port.icount.rx++;
@@ -1029,7 +1019,7 @@
 	uart_resume_port(&serial_txx9_reg, &serial_txx9_ports[line].port);
 }
 
-static DECLARE_MUTEX(serial_txx9_sem);
+static DEFINE_MUTEX(serial_txx9_mutex);
 
 /**
  *	serial_txx9_register_port - register a serial port
@@ -1048,7 +1038,7 @@
 	struct uart_txx9_port *uart;
 	int ret = -ENOSPC;
 
-	down(&serial_txx9_sem);
+	mutex_lock(&serial_txx9_mutex);
 	for (i = 0; i < UART_NR; i++) {
 		uart = &serial_txx9_ports[i];
 		if (uart->port.type == PORT_UNKNOWN)
@@ -1069,7 +1059,7 @@
 		if (ret == 0)
 			ret = uart->port.line;
 	}
-	up(&serial_txx9_sem);
+	mutex_unlock(&serial_txx9_mutex);
 	return ret;
 }
 
@@ -1084,7 +1074,7 @@
 {
 	struct uart_txx9_port *uart = &serial_txx9_ports[line];
 
-	down(&serial_txx9_sem);
+	mutex_lock(&serial_txx9_mutex);
 	uart_remove_one_port(&serial_txx9_reg, &uart->port);
 	uart->port.flags = 0;
 	uart->port.type = PORT_UNKNOWN;
@@ -1093,7 +1083,7 @@
 	uart->port.membase = 0;
 	uart->port.dev = NULL;
 	uart_add_one_port(&serial_txx9_reg, &uart->port);
-	up(&serial_txx9_sem);
+	mutex_unlock(&serial_txx9_mutex);
 }
 
 /*
diff --git a/drivers/serial/sh-sci.c b/drivers/serial/sh-sci.c
index 430754e..a9e0707 100644
--- a/drivers/serial/sh-sci.c
+++ b/drivers/serial/sh-sci.c
@@ -482,6 +482,7 @@
 	struct tty_struct *tty = port->info->tty;
 	int i, count, copied = 0;
 	unsigned short status;
+	unsigned char flag;
 
 	status = sci_in(port, SCxSR);
 	if (!(status & SCxSR_RDxF(port)))
@@ -499,8 +500,7 @@
 #endif
 
 		/* Don't copy more bytes than there is room for in the buffer */
-		if (tty->flip.count + count > TTY_FLIPBUF_SIZE)
-			count = TTY_FLIPBUF_SIZE - tty->flip.count;
+		count = tty_buffer_request_room(tty, count);
 
 		/* If for any reason we can't copy more data, we're done! */
 		if (count == 0)
@@ -512,8 +512,7 @@
 			    || uart_handle_sysrq_char(port, c, regs)) {
 				count = 0;
 			} else {
-			    tty->flip.char_buf_ptr[0] = c;
-			    tty->flip.flag_buf_ptr[0] = TTY_NORMAL;
+			    tty_insert_flip_char(tty, c, TTY_NORMAL);
 			}
 		} else {
 			for (i=0; i<count; i++) {
@@ -542,26 +541,21 @@
 				}
 
 				/* Store data and status */
-				tty->flip.char_buf_ptr[i] = c;
 				if (status&SCxSR_FER(port)) {
-					tty->flip.flag_buf_ptr[i] = TTY_FRAME;
+					flag = TTY_FRAME;
 					pr_debug("sci: frame error\n");
 				} else if (status&SCxSR_PER(port)) {
-					tty->flip.flag_buf_ptr[i] = TTY_PARITY;
+					flag = TTY_PARITY;
 					pr_debug("sci: parity error\n");
-				} else {
-					tty->flip.flag_buf_ptr[i] = TTY_NORMAL;
-				}
+				} else
+					flag = TTY_NORMAL;
+				tty_insert_flip_char(tty, c, flag);
 			}
 		}
 
 		sci_in(port, SCxSR); /* dummy read */
 		sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
 
-		/* Update the kernel buffer end */
-		tty->flip.count += count;
-		tty->flip.char_buf_ptr += count;
-		tty->flip.flag_buf_ptr += count;
 		copied += count;
 		port->icount.rx += count;
 	}
@@ -608,48 +602,45 @@
 	unsigned short status = sci_in(port, SCxSR);
 	struct tty_struct *tty = port->info->tty;
 
-	if (status&SCxSR_ORER(port) && tty->flip.count<TTY_FLIPBUF_SIZE) {
+	if (status&SCxSR_ORER(port)) {
 		/* overrun error */
-		copied++;
-		*tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
+		if(tty_insert_flip_char(tty, 0, TTY_OVERRUN))
+			copied++;
 		pr_debug("sci: overrun error\n");
 	}
 
-	if (status&SCxSR_FER(port) && tty->flip.count<TTY_FLIPBUF_SIZE) {
+	if (status&SCxSR_FER(port)) {
 		if (sci_rxd_in(port) == 0) {
 			/* Notify of BREAK */
 			struct sci_port * sci_port = (struct sci_port *)port;
-                       if(!sci_port->break_flag) {
-	                        sci_port->break_flag = 1;
-                               sci_schedule_break_timer((struct sci_port *)port);
+			if(!sci_port->break_flag) {
+	                	sci_port->break_flag = 1;
+	                	sci_schedule_break_timer((struct sci_port *)port);
 				/* Do sysrq handling. */
-				if(uart_handle_break(port)) {
+				if(uart_handle_break(port))
 					return 0;
-				}
 			        pr_debug("sci: BREAK detected\n");
-			        copied++;
-			        *tty->flip.flag_buf_ptr++ = TTY_BREAK;
+			        if(tty_insert_flip_char(tty, 0, TTY_BREAK))
+				        copied++;
                        }
 		}
 		else {
 			/* frame error */
-			copied++;
-			*tty->flip.flag_buf_ptr++ = TTY_FRAME;
+			if(tty_insert_flip_char(tty, 0, TTY_FRAME))
+				copied++;
 			pr_debug("sci: frame error\n");
 		}
 	}
 
-	if (status&SCxSR_PER(port) && tty->flip.count<TTY_FLIPBUF_SIZE) {
+	if (status&SCxSR_PER(port)) {
+		if(tty_insert_flip_char(tty, 0, TTY_PARITY))
+			copied++;
 		/* parity error */
-		copied++;
-		*tty->flip.flag_buf_ptr++ = TTY_PARITY;
 		pr_debug("sci: parity error\n");
 	}
 
-	if (copied) {
-		tty->flip.count += copied;
+	if (copied)
 		tty_flip_buffer_push(tty);
-	}
 
 	return copied;
 }
@@ -661,15 +652,14 @@
 	struct tty_struct *tty = port->info->tty;
 	struct sci_port *s = &sci_ports[port->line];
 
-	if (!s->break_flag && status & SCxSR_BRK(port) &&
-	    tty->flip.count < TTY_FLIPBUF_SIZE) {
+	if (!s->break_flag && status & SCxSR_BRK(port))
 #if defined(CONFIG_CPU_SH3)
 		/* Debounce break */
 		s->break_flag = 1;
 #endif
 		/* Notify of BREAK */
-		copied++;
-		*tty->flip.flag_buf_ptr++ = TTY_BREAK;
+		if(tty_insert_flip_char(tty, 0, TTY_BREAK))
+			copied++;
 		pr_debug("sci: BREAK detected\n");
 	}
 
@@ -677,19 +667,15 @@
 	/* XXX: Handle SCIF overrun error */
 	if (port->type == PORT_SCIF && (sci_in(port, SCLSR) & SCIF_ORER) != 0) {
 		sci_out(port, SCLSR, 0);
-		if(tty->flip.count<TTY_FLIPBUF_SIZE) {
+		if(tty_insert_flip_char(tty, 0, TTY_OVERRUN)) {
 			copied++;
-			*tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
 			pr_debug("sci: overrun error\n");
 		}
 	}
 #endif
 
-	if (copied) {
-		tty->flip.count += copied;
+	if (copied)
 		tty_flip_buffer_push(tty);
-	}
-
 	return copied;
 }
 
@@ -732,12 +718,9 @@
 			struct tty_struct *tty = port->info->tty;
 
 			sci_out(port, SCLSR, 0);
-			if(tty->flip.count<TTY_FLIPBUF_SIZE) {
-				*tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
-				tty->flip.count++;
-				tty_flip_buffer_push(tty);
-				pr_debug("scif: overrun error\n");
-			}
+			tty_insert_flip_char(tty, 0, TTY_OVERRUN);
+			tty_flip_buffer_push(tty);
+			pr_debug("scif: overrun error\n");
 		}
 #endif
 		sci_rx_interrupt(irq, ptr, regs);
diff --git a/drivers/serial/sn_console.c b/drivers/serial/sn_console.c
index 313f9df..5468e5a 100644
--- a/drivers/serial/sn_console.c
+++ b/drivers/serial/sn_console.c
@@ -519,11 +519,7 @@
 
 		/* record the character to pass up to the tty layer */
 		if (tty) {
-			*tty->flip.char_buf_ptr = ch;
-			*tty->flip.flag_buf_ptr = TTY_NORMAL;
-			tty->flip.char_buf_ptr++;
-			tty->flip.count++;
-			if (tty->flip.count == TTY_FLIPBUF_SIZE)
+			if(tty_insert_flip_char(tty, ch, TTY_NORMAL) == 0)
 				break;
 		}
 		port->sc_port.icount.rx++;
diff --git a/drivers/serial/sunsab.c b/drivers/serial/sunsab.c
index ba9381f..7e773ff 100644
--- a/drivers/serial/sunsab.c
+++ b/drivers/serial/sunsab.c
@@ -159,21 +159,14 @@
 		saw_console_brk = 1;
 
 	for (i = 0; i < count; i++) {
-		unsigned char ch = buf[i];
+		unsigned char ch = buf[i], flag;
 
 		if (tty == NULL) {
 			uart_handle_sysrq_char(&up->port, ch, regs);
 			continue;
 		}
 
-		if (unlikely(tty->flip.count >= TTY_FLIPBUF_SIZE)) {
-			tty->flip.work.func((void *)tty);
-			if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-				return tty; // if TTY_DONT_FLIP is set
-		}
-
-		*tty->flip.char_buf_ptr = ch;
-		*tty->flip.flag_buf_ptr = TTY_NORMAL;
+		flag = TTY_NORMAL;
 		up->port.icount.rx++;
 
 		if (unlikely(stat->sreg.isr0 & (SAB82532_ISR0_PERR |
@@ -209,34 +202,21 @@
 			stat->sreg.isr1 &= ((up->port.read_status_mask >> 8) & 0xff);
 
 			if (stat->sreg.isr1 & SAB82532_ISR1_BRK) {
-				*tty->flip.flag_buf_ptr = TTY_BREAK;
+				flag = TTY_BREAK;
 			} else if (stat->sreg.isr0 & SAB82532_ISR0_PERR)
-				*tty->flip.flag_buf_ptr = TTY_PARITY;
+				flag = TTY_PARITY;
 			else if (stat->sreg.isr0 & SAB82532_ISR0_FERR)
-				*tty->flip.flag_buf_ptr = TTY_FRAME;
+				flag = TTY_FRAME;
 		}
 
 		if (uart_handle_sysrq_char(&up->port, ch, regs))
 			continue;
 
 		if ((stat->sreg.isr0 & (up->port.ignore_status_mask & 0xff)) == 0 &&
-		    (stat->sreg.isr1 & ((up->port.ignore_status_mask >> 8) & 0xff)) == 0){
-			tty->flip.flag_buf_ptr++;
-			tty->flip.char_buf_ptr++;
-			tty->flip.count++;
-		}
-		if ((stat->sreg.isr0 & SAB82532_ISR0_RFO) &&
-		    tty->flip.count < TTY_FLIPBUF_SIZE) {
-			/*
-			 * Overrun is special, since it's reported
-			 * immediately, and doesn't affect the current
-			 * character.
-			 */
-			*tty->flip.flag_buf_ptr = TTY_OVERRUN;
-			tty->flip.flag_buf_ptr++;
-			tty->flip.char_buf_ptr++;
-			tty->flip.count++;
-		}
+		    (stat->sreg.isr1 & ((up->port.ignore_status_mask >> 8) & 0xff)) == 0)
+			tty_insert_flip_char(tty, ch, flag);
+		if (stat->sreg.isr0 & SAB82532_ISR0_RFO)
+			tty_insert_flip_char(tty, 0, TTY_OVERRUN);
 	}
 
 	if (saw_console_brk)
diff --git a/drivers/serial/sunsu.c b/drivers/serial/sunsu.c
index f073853..9a3665b 100644
--- a/drivers/serial/sunsu.c
+++ b/drivers/serial/sunsu.c
@@ -323,19 +323,13 @@
 receive_chars(struct uart_sunsu_port *up, unsigned char *status, struct pt_regs *regs)
 {
 	struct tty_struct *tty = up->port.info->tty;
-	unsigned char ch;
+	unsigned char ch, flag;
 	int max_count = 256;
 	int saw_console_brk = 0;
 
 	do {
-		if (unlikely(tty->flip.count >= TTY_FLIPBUF_SIZE)) {
-			tty->flip.work.func((void *)tty);
-			if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-				return tty; // if TTY_DONT_FLIP is set
-		}
 		ch = serial_inp(up, UART_RX);
-		*tty->flip.char_buf_ptr = ch;
-		*tty->flip.flag_buf_ptr = TTY_NORMAL;
+		flag = TTY_NORMAL;
 		up->port.icount.rx++;
 
 		if (unlikely(*status & (UART_LSR_BI | UART_LSR_PE |
@@ -377,31 +371,23 @@
 			}
 
 			if (*status & UART_LSR_BI) {
-				*tty->flip.flag_buf_ptr = TTY_BREAK;
+				flag = TTY_BREAK;
 			} else if (*status & UART_LSR_PE)
-				*tty->flip.flag_buf_ptr = TTY_PARITY;
+				flag = TTY_PARITY;
 			else if (*status & UART_LSR_FE)
-				*tty->flip.flag_buf_ptr = TTY_FRAME;
+				flag = TTY_FRAME;
 		}
 		if (uart_handle_sysrq_char(&up->port, ch, regs))
 			goto ignore_char;
-		if ((*status & up->port.ignore_status_mask) == 0) {
-			tty->flip.flag_buf_ptr++;
-			tty->flip.char_buf_ptr++;
-			tty->flip.count++;
-		}
-		if ((*status & UART_LSR_OE) &&
-		    tty->flip.count < TTY_FLIPBUF_SIZE) {
+		if ((*status & up->port.ignore_status_mask) == 0)
+			tty_insert_flip_char(tty, ch, flag);
+		if (*status & UART_LSR_OE)
 			/*
 			 * Overrun is special, since it's reported
 			 * immediately, and doesn't affect the current
 			 * character.
 			 */
-			*tty->flip.flag_buf_ptr = TTY_OVERRUN;
-			tty->flip.flag_buf_ptr++;
-			tty->flip.char_buf_ptr++;
-			tty->flip.count++;
-		}
+			 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
 	ignore_char:
 		*status = serial_inp(up, UART_LSR);
 	} while ((*status & UART_LSR_DR) && (max_count-- > 0));
diff --git a/drivers/serial/sunzilog.c b/drivers/serial/sunzilog.c
index 7653d6c..3c72484 100644
--- a/drivers/serial/sunzilog.c
+++ b/drivers/serial/sunzilog.c
@@ -319,7 +319,7 @@
 		       struct pt_regs *regs)
 {
 	struct tty_struct *tty;
-	unsigned char ch, r1;
+	unsigned char ch, r1, flag;
 
 	tty = NULL;
 	if (up->port.info != NULL &&		/* Unopened serial console */
@@ -362,19 +362,8 @@
 			continue;
 		}
 
-		if (unlikely(tty->flip.count >= TTY_FLIPBUF_SIZE)) {
-			tty->flip.work.func((void *)tty);
-			/*
-			 * The 8250 bails out of the loop here,
-			 * but we need to read everything, or die.
-			 */
-			if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-				continue;
-		}
-
 		/* A real serial line, record the character and status.  */
-		*tty->flip.char_buf_ptr = ch;
-		*tty->flip.flag_buf_ptr = TTY_NORMAL;
+		flag = TTY_NORMAL;
 		up->port.icount.rx++;
 		if (r1 & (BRK_ABRT | PAR_ERR | Rx_OVR | CRC_ERR)) {
 			if (r1 & BRK_ABRT) {
@@ -391,28 +380,21 @@
 				up->port.icount.overrun++;
 			r1 &= up->port.read_status_mask;
 			if (r1 & BRK_ABRT)
-				*tty->flip.flag_buf_ptr = TTY_BREAK;
+				flag = TTY_BREAK;
 			else if (r1 & PAR_ERR)
-				*tty->flip.flag_buf_ptr = TTY_PARITY;
+				flag = TTY_PARITY;
 			else if (r1 & CRC_ERR)
-				*tty->flip.flag_buf_ptr = TTY_FRAME;
+				flag = TTY_FRAME;
 		}
 		if (uart_handle_sysrq_char(&up->port, ch, regs))
 			continue;
 
 		if (up->port.ignore_status_mask == 0xff ||
 		    (r1 & up->port.ignore_status_mask) == 0) {
-			tty->flip.flag_buf_ptr++;
-			tty->flip.char_buf_ptr++;
-			tty->flip.count++;
+		    	tty_insert_flip_char(tty, ch, flag);
 		}
-		if ((r1 & Rx_OVR) &&
-		    tty->flip.count < TTY_FLIPBUF_SIZE) {
-			*tty->flip.flag_buf_ptr = TTY_OVERRUN;
-			tty->flip.flag_buf_ptr++;
-			tty->flip.char_buf_ptr++;
-			tty->flip.count++;
-		}
+		if (r1 & Rx_OVR)
+			tty_insert_flip_char(tty, 0, TTY_OVERRUN);
 	}
 
 	return tty;
diff --git a/drivers/serial/vr41xx_siu.c b/drivers/serial/vr41xx_siu.c
index 865d4de..d61494d 100644
--- a/drivers/serial/vr41xx_siu.c
+++ b/drivers/serial/vr41xx_siu.c
@@ -1,7 +1,7 @@
 /*
  *  Driver for NEC VR4100 series Serial Interface Unit.
  *
- *  Copyright (C) 2004-2005  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2004-2005  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  Based on drivers/serial/8250.c, by Russell King.
  *
@@ -371,11 +371,6 @@
 	lsr = *status;
 
 	do {
-		if (unlikely(tty->flip.count >= TTY_FLIPBUF_SIZE)) {
-			if (tty->low_latency)
-				tty_flip_buffer_push(tty);
-		}
-
 		ch = siu_read(port, UART_RX);
 		port->icount.rx++;
 		flag = TTY_NORMAL;
diff --git a/drivers/usb/atm/speedtch.c b/drivers/usb/atm/speedtch.c
index b283361..c1b47d7 100644
--- a/drivers/usb/atm/speedtch.c
+++ b/drivers/usb/atm/speedtch.c
@@ -532,9 +532,9 @@
 	int ret = int_urb->status;
 
 	/* The magic interrupt for "up state" */
-	const static unsigned char up_int[6]   = { 0xa1, 0x00, 0x01, 0x00, 0x00, 0x00 };
+	static const unsigned char up_int[6]   = { 0xa1, 0x00, 0x01, 0x00, 0x00, 0x00 };
 	/* The magic interrupt for "down state" */
-	const static unsigned char down_int[6] = { 0xa1, 0x00, 0x00, 0x00, 0x00, 0x00 };
+	static const unsigned char down_int[6] = { 0xa1, 0x00, 0x00, 0x00, 0x00, 0x00 };
 
 	atm_dbg(usbatm, "%s entered\n", __func__);
 
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 248279e..b9fd39f 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -335,14 +335,9 @@
 
 	dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d\n", buf, buf->size);
 
-	for (i = 0; i < buf->size && !acm->throttle; i++) {
-		/* if we insert more than TTY_FLIPBUF_SIZE characters,
-		   we drop them. */
-		if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
-			tty_flip_buffer_push(tty);
- 		}
-		tty_insert_flip_char(tty, buf->base[i], 0);
- 	}
+	tty_buffer_request_room(tty, buf->size);
+	if (!acm->throttle)
+		tty_insert_flip_string(tty, buf->base, buf->size);
 	tty_flip_buffer_push(tty);
 
 	spin_lock(&acm->throttle_lock);
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index 65e084a..2e6926b 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -1271,6 +1271,7 @@
 	unsigned int len;
 	struct gs_port *port;
 	int ret;
+	struct tty_struct *tty;
 
 	/* TEMPORARY -- only port 0 is supported right now */
 	port = dev->dev_port[0];
@@ -1290,7 +1291,10 @@
 		goto exit;
 	}
 
-	if (port->port_tty == NULL) {
+
+	tty = port->port_tty;
+
+	if (tty == NULL) {
 		printk(KERN_ERR "gs_recv_packet: port=%d, NULL tty pointer\n",
 			port->port_num);
 		ret = -EIO;
@@ -1304,20 +1308,13 @@
 		goto exit;
 	}
 
-	len = (unsigned int)(TTY_FLIPBUF_SIZE - port->port_tty->flip.count);
-	if (len < size)
-		size = len;
-
-	if (size > 0) {
-		memcpy(port->port_tty->flip.char_buf_ptr, packet, size);
-		port->port_tty->flip.char_buf_ptr += size;
-		port->port_tty->flip.count += size;
+	len = tty_buffer_request_room(tty, size);
+	if (len > 0) {
+		tty_insert_flip_string(tty, packet, len);
 		tty_flip_buffer_push(port->port_tty);
 		wake_up_interruptible(&port->port_tty->read_wait);
 	}
-
 	ret = 0;
-
 exit:
 	spin_unlock(&port->port_lock);
 	return ret;
diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c
index 458f2ac..28538db 100644
--- a/drivers/usb/image/microtek.c
+++ b/drivers/usb/image/microtek.c
@@ -674,7 +674,7 @@
 
 
 /* These are taken from the msmUSB.inf file on the Windows driver CD */
-const static struct vendor_product mts_supported_products[] =
+static const struct vendor_product mts_supported_products[] =
 {
 	{ "Phantom 336CX",	mts_sup_unknown},
 	{ "Phantom 336CX",	mts_sup_unknown},
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
index 14f55fd..be5dc80 100644
--- a/drivers/usb/serial/Kconfig
+++ b/drivers/usb/serial/Kconfig
@@ -84,7 +84,7 @@
 
 config USB_SERIAL_WHITEHEAT
 	tristate "USB ConnectTech WhiteHEAT Serial Driver"
-	depends on USB_SERIAL && BROKEN_ON_SMP
+	depends on USB_SERIAL
 	help
 	  Say Y here if you want to use a ConnectTech WhiteHEAT 4 port
 	  USB to serial converter device.
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index 6d18d4e..2357b1d 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -364,7 +364,6 @@
 	struct tty_struct *tty;
 	unsigned char *data = urb->transfer_buffer;
 	short todo;
-	int i;
 	int result;
 
 	dbg("%s - port %d", __FUNCTION__, port->number);
@@ -381,14 +380,8 @@
 		return;
 	}
 	if (urb->actual_length) {
-		for (i = 0; i < urb->actual_length ; ++i) {
-			/* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */
-			if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
-				tty_flip_buffer_push(tty);
-			}
-			/* this doesn't actually push the data through unless tty->low_latency is set */
-			tty_insert_flip_char(tty, data[i], 0);
-		}
+		tty_buffer_request_room(tty, urb->actual_length);
+		tty_insert_flip_string(tty, data, urb->actual_length);
 	  	tty_flip_buffer_push(tty);
 	}
 
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index 4e9637e..68067fe 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -1263,12 +1263,10 @@
 
 	/* process read if there is data other than line status */
 	if (tty && (bytes > i)) {
+		bytes = tty_buffer_request_room(tty, bytes);
 		for (; i < bytes ; ++i) {
 			dbg("pushing byte number %d - %d - %c", i, data[i],
 					data[i]);
-			if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
-				tty_flip_buffer_push(tty);
-			}
 			tty_insert_flip_char(tty, data[i], tty_flag);
 		}
 		tty_flip_buffer_push(port->tty);
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
index 8fc414b..b3f776a 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -946,13 +946,10 @@
 	spin_lock_irqsave( &priv->dp_port_lock, flags );
 
 	/* send any buffered chars from throttle time on to tty subsystem */
-	len = min(priv->dp_in_buf_len, TTY_FLIPBUF_SIZE - tty->flip.count );
+
+	len = tty_buffer_request_room(tty, priv->dp_in_buf_len);
 	if( len > 0 ) {
-		memcpy( tty->flip.char_buf_ptr, priv->dp_in_buf, len );
-		memcpy( tty->flip.flag_buf_ptr, priv->dp_in_flag_buf, len );
-		tty->flip.char_buf_ptr += len;
-		tty->flip.flag_buf_ptr += len;
-		tty->flip.count += len;
+		tty_insert_flip_string_flags(tty, priv->dp_in_buf, priv->dp_in_flag_buf, len);
 		tty_flip_buffer_push( tty );
 	}
 
@@ -1827,6 +1824,7 @@
 	int status = ((unsigned char *)urb->transfer_buffer)[2];
 	unsigned char *data = ((unsigned char *)urb->transfer_buffer)+3;
 	int flag,throttled;
+	int i;
 
 	/* do not process callbacks on closed ports */
 	/* but do continue the read chain */
@@ -1885,20 +1883,18 @@
 			}
 
 		} else {
-
-			len = min( len, TTY_FLIPBUF_SIZE - tty->flip.count );
-
+			len = tty_buffer_request_room(tty, len);
 			if( len > 0 ) {
-				memcpy( tty->flip.char_buf_ptr, data, len );
-				memset( tty->flip.flag_buf_ptr, flag, len );
-				tty->flip.char_buf_ptr += len;
-				tty->flip.flag_buf_ptr += len;
-				tty->flip.count += len;
+				/* Hot path */
+				if(flag == TTY_NORMAL)
+					tty_insert_flip_string(tty, data, len);
+				else {
+					for(i = 0; i < len; i++)
+						tty_insert_flip_char(tty, data[i], flag);
+				}
 				tty_flip_buffer_push( tty );
 			}
-
 		}
-
 	}
 
 	spin_unlock( &priv->dp_port_lock );
diff --git a/drivers/usb/serial/empeg.c b/drivers/usb/serial/empeg.c
index 79a766e..63f7c78 100644
--- a/drivers/usb/serial/empeg.c
+++ b/drivers/usb/serial/empeg.c
@@ -344,7 +344,6 @@
 	struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
 	struct tty_struct *tty;
 	unsigned char *data = urb->transfer_buffer;
-	int i;
 	int result;
 
 	dbg("%s - port %d", __FUNCTION__, port->number);
@@ -359,19 +358,8 @@
 	tty = port->tty;
 
 	if (urb->actual_length) {
-		for (i = 0; i < urb->actual_length ; ++i) {
-			/* gb - 2000/11/13
-			 * If we insert too many characters we'll overflow the buffer.
-			 * This means we'll lose bytes - Decidedly bad.
-			 */
-			if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
-				tty_flip_buffer_push(tty);
-				}
-			tty_insert_flip_char(tty, data[i], 0);
-		}
-		/* gb - 2000/11/13
-		 * Goes straight through instead of scheduling - if tty->low_latency is set.
-		 */
+		tty_buffer_request_room(tty, urb->actual_length);
+		tty_insert_flip_string(tty, data, urb->actual_length);
 		tty_flip_buffer_push(tty);
 		bytes_in += urb->actual_length;
 	}
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index eb863b3..10bc1bf 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -1610,24 +1610,11 @@
 			length = 0;
 		}
 
-		/* have to make sure we don't overflow the buffer
-		   with tty_insert_flip_char's */
-		if (tty->flip.count+length > TTY_FLIPBUF_SIZE) {
-			tty_flip_buffer_push(tty);
-			need_flip = 0;
-
-			if (tty->flip.count != 0) {
-				/* flip didn't work, this happens when ftdi_process_read() is
-				 * called from ftdi_unthrottle, because TTY_DONT_FLIP is set */
-				dbg("%s - flip buffer push failed", __FUNCTION__);
-				break;
-			}
-		}
 		if (priv->rx_flags & THROTTLED) {
 			dbg("%s - throttled", __FUNCTION__);
 			break;
 		}
-		if (tty->ldisc.receive_room(tty)-tty->flip.count < length) {
+		if (tty_buffer_request_room(tty, length) < length) {
 			/* break out & wait for throttling/unthrottling to happen */
 			dbg("%s - receive room low", __FUNCTION__);
 			break;
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c
index 452efce..d6f55e9 100644
--- a/drivers/usb/serial/garmin_gps.c
+++ b/drivers/usb/serial/garmin_gps.c
@@ -275,23 +275,14 @@
                         char *data, unsigned int actual_length)
 {
 	struct tty_struct *tty = port->tty;
-	int i;
 
 	if (tty && actual_length) {
 
 		usb_serial_debug_data(debug, &port->dev, 
 					__FUNCTION__, actual_length, data);
 
-		for (i = 0; i < actual_length ; ++i) {
-			/* if we insert more than TTY_FLIPBUF_SIZE characters,
-			   we drop them. */
-			if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
-				tty_flip_buffer_push(tty);
-			}
-			/* this doesn't actually push the data through unless
-			   tty->low_latency is set */
-			tty_insert_flip_char(tty, data[i], 0);
-		}
+		tty_buffer_request_room(tty, actual_length);
+		tty_insert_flip_string(tty, data, actual_length);
 		tty_flip_buffer_push(tty);
 	}
 }
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 4ddac62..476cda1 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -254,7 +254,6 @@
 	struct usb_serial *serial = port->serial;
 	struct tty_struct *tty;
 	unsigned char *data = urb->transfer_buffer;
-	int i;
 	int result;
 
 	dbg("%s - port %d", __FUNCTION__, port->number);
@@ -268,14 +267,8 @@
 
 	tty = port->tty;
 	if (tty && urb->actual_length) {
-		for (i = 0; i < urb->actual_length ; ++i) {
-			/* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */
-			if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
-				tty_flip_buffer_push(tty);
-			}
-			/* this doesn't actually push the data through unless tty->low_latency is set */
-			tty_insert_flip_char(tty, data[i], 0);
-		}
+		tty_buffer_request_room(tty, urb->actual_length);
+		tty_insert_flip_string(tty, data, urb->actual_length);
 	  	tty_flip_buffer_push(tty);
 	}
 
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index faedbeb..3f29e6b0 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -1965,20 +1965,14 @@
 	int cnt;
 
 	do {
-		if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
-			tty_flip_buffer_push(tty);
-			if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
-				dev_err(dev, "%s - dropping data, %d bytes lost\n",
-					__FUNCTION__, length);
-				return;
-			}
+		cnt = tty_buffer_request_room(tty, length);
+		if (cnt < length) {
+			dev_err(dev, "%s - dropping data, %d bytes lost\n",
+					__FUNCTION__, length - cnt);
+			if(cnt == 0)
+				break;
 		}
-		cnt = min(length, TTY_FLIPBUF_SIZE - tty->flip.count);
-		memcpy(tty->flip.char_buf_ptr, data, cnt);
-		memset(tty->flip.flag_buf_ptr, 0, cnt);
-		tty->flip.char_buf_ptr += cnt;
-		tty->flip.flag_buf_ptr += cnt;
-		tty->flip.count += cnt;
+		tty_insert_flip_string(tty, data, cnt);
 		data += cnt;
 		length -= cnt;
 	} while (length > 0);
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index 2edf9cab..afc0f34 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -1865,20 +1865,14 @@
 	int cnt;
 
 	do {
-		if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
-			tty_flip_buffer_push(tty);
-			if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
-				dev_err(dev, "%s - dropping data, %d bytes lost\n",
-					__FUNCTION__, length);
-				return;
-			}
+		cnt = tty_buffer_request_room(tty, length);
+		if (cnt < length) {
+			dev_err(dev, "%s - dropping data, %d bytes lost\n",
+				__FUNCTION__, length - cnt);
+			if(cnt == 0)
+				break;
 		}
-		cnt = min(length, TTY_FLIPBUF_SIZE - tty->flip.count);
-		memcpy(tty->flip.char_buf_ptr, data, cnt);
-		memset(tty->flip.flag_buf_ptr, 0, cnt);
-		tty->flip.char_buf_ptr += cnt;
-		tty->flip.flag_buf_ptr += cnt;
-		tty->flip.count += cnt;
+		tty_insert_flip_string(tty, data, cnt);
 		data += cnt;
 		length -= cnt;
 	} while (length > 0);
diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c
index 06d07ce..9a5c979 100644
--- a/drivers/usb/serial/ipaq.c
+++ b/drivers/usb/serial/ipaq.c
@@ -711,7 +711,7 @@
 	struct usb_serial_port	*port = (struct usb_serial_port *)urb->context;
 	struct tty_struct	*tty;
 	unsigned char		*data = urb->transfer_buffer;
-	int			i, result;
+	int			result;
 
 	dbg("%s - port %d", __FUNCTION__, port->number);
 
@@ -724,14 +724,8 @@
 
 	tty = port->tty;
 	if (tty && urb->actual_length) {
-		for (i = 0; i < urb->actual_length ; ++i) {
-			/* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */
-			if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
-				tty_flip_buffer_push(tty);
-			}
-			/* this doesn't actually push the data through unless tty->low_latency is set */
-			tty_insert_flip_char(tty, data[i], 0);
-		}
+		tty_buffer_request_room(tty, urb->actual_length);
+		tty_insert_flip_string(tty, data, urb->actual_length);
 		tty_flip_buffer_push(tty);
 		bytes_in += urb->actual_length;
 	}
diff --git a/drivers/usb/serial/ipw.c b/drivers/usb/serial/ipw.c
index 2dd191f..e760a70 100644
--- a/drivers/usb/serial/ipw.c
+++ b/drivers/usb/serial/ipw.c
@@ -166,7 +166,6 @@
 	struct usb_serial_port *port = urb->context;
 	unsigned char *data = urb->transfer_buffer;
 	struct tty_struct *tty;
-	int i;
 	int result;
 
 	dbg("%s - port %d", __FUNCTION__, port->number);
@@ -180,14 +179,8 @@
 
 	tty = port->tty;
 	if (tty && urb->actual_length) {
-		for (i = 0; i < urb->actual_length ; ++i) {
-			/* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */
-			if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
-				tty_flip_buffer_push(tty);
-			}
-			/* this doesn't actually push the data through unless tty->low_latency is set */
-			tty_insert_flip_char(tty, data[i], 0);
-		}
+		tty_buffer_request_room(tty, urb->actual_length);
+		tty_insert_flip_string(tty, data, urb->actual_length);
 		tty_flip_buffer_push(tty);
 	}
 
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index 4e2f7df..78335a5 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -648,7 +648,6 @@
 		usb_serial_debug_data(debug, &port->dev, __FUNCTION__,
 				      urb->actual_length, data);
 	} else {
-		int i;
 		int bytes_sent = ((__u8 *) data)[0] +
 				 ((unsigned int) ((__u8 *) data)[1] << 8);
 		tty = port->tty;
@@ -669,16 +668,8 @@
 			bytes_sent = urb->actual_length - 2;
 		}
 
-		for (i = 2; i < 2+bytes_sent; i++) {
-			/* if we insert more than TTY_FLIPBUF_SIZE characters,
-			 * we drop them. */
-			if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
-				tty_flip_buffer_push(tty);
-			}
-			/* this doesn't actually push the data through unless 
-			 * tty->low_latency is set */
-			tty_insert_flip_char(tty, ((__u8*) data)[i], 0);
-		}
+		tty_buffer_request_room(tty, bytes_sent);
+		tty_insert_flip_string(tty, data + 2, bytes_sent);
 		tty_flip_buffer_push(tty);
 
 		/* again lockless, but debug info only */
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index d9c21e2..b8b2131 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -365,7 +365,6 @@
 
 static void kobil_read_int_callback( struct urb *purb, struct pt_regs *regs)
 {
-	int i;
 	int result;
 	struct usb_serial_port *port = (struct usb_serial_port *) purb->context;
 	struct tty_struct *tty;
@@ -397,14 +396,8 @@
 		*/
 		// END DEBUG
 
-		for (i = 0; i < purb->actual_length; ++i) {
-			// if we insert more than TTY_FLIPBUF_SIZE characters, we drop them.
-			if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
-				tty_flip_buffer_push(tty);
-			}
-			// this doesn't actually push the data through unless tty->low_latency is set
-			tty_insert_flip_char(tty, data[i], 0);
-		}
+		tty_buffer_request_room(tty, purb->actual_length);
+		tty_insert_flip_string(tty, data, purb->actual_length);
 		tty_flip_buffer_push(tty);
 	}
 
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 3fd2405..52bdf6f 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -321,7 +321,7 @@
 
 static void option_indat_callback(struct urb *urb, struct pt_regs *regs)
 {
-	int i, err;
+	int err;
 	int endpoint;
 	struct usb_serial_port *port;
 	struct tty_struct *tty;
@@ -338,11 +338,8 @@
 	} else {
 		tty = port->tty;
 		if (urb->actual_length) {
-			for (i = 0; i < urb->actual_length ; ++i) {
-				if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-					tty_flip_buffer_push(tty);
-				tty_insert_flip_char(tty, data[i], 0);
-			}
+			tty_buffer_request_room(tty, urb->actual_length);
+			tty_insert_flip_string(tty, data, urb->actual_length);
 			tty_flip_buffer_push(tty);
 		} else {
 			dbg("%s: empty read urb received", __FUNCTION__);
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index f037210..9ffff19 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -924,16 +924,12 @@
 
 	tty = port->tty;
 	if (tty && urb->actual_length) {
+		tty_buffer_request_room(tty, urb->actual_length + 1);
 		/* overrun is special, not associated with a char */
 		if (status & UART_OVERRUN_ERROR)
 			tty_insert_flip_char(tty, 0, TTY_OVERRUN);
-
-		for (i = 0; i < urb->actual_length; ++i) {
-			if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
-				tty_flip_buffer_push(tty);
-			}
+		for (i = 0; i < urb->actual_length; ++i)
 			tty_insert_flip_char (tty, data[i], tty_flag);
-		}
 		tty_flip_buffer_push (tty);
 	}
 
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index abb830c..c18db32 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -1280,24 +1280,18 @@
 	int cnt;
 
 	do {
-		if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
-			tty_flip_buffer_push(tty);
-			if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
-				dev_err(dev, "%s - dropping data, %d bytes lost\n", __FUNCTION__, length);
-				return;
-			}
+		cnt = tty_buffer_request_room(tty, length);
+		if (cnt < length) {
+			dev_err(dev, "%s - dropping data, %d bytes lost\n", __FUNCTION__, length - cnt);
+			if(cnt == 0)
+				break;
 		}
-		cnt = min(length, TTY_FLIPBUF_SIZE - tty->flip.count);
-		memcpy(tty->flip.char_buf_ptr, data, cnt);
-		memset(tty->flip.flag_buf_ptr, 0, cnt);
-		tty->flip.char_buf_ptr += cnt;
-		tty->flip.flag_buf_ptr += cnt;
-		tty->flip.count += cnt;
+		tty_insert_flip_string(tty, data, cnt);
+		tty_flip_buffer_push(tty);
 		data += cnt;
 		length -= cnt;
 	} while (length > 0);
 
-	tty_flip_buffer_push(tty);
 }
 
 
diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c
index 49b1fbe..bce3d55 100644
--- a/drivers/usb/serial/visor.c
+++ b/drivers/usb/serial/visor.c
@@ -488,7 +488,6 @@
 	unsigned char *data = urb->transfer_buffer;
 	struct tty_struct *tty;
 	unsigned long flags;
-	int i;
 	int throttled;
 	int result;
 
@@ -503,14 +502,8 @@
 
 	tty = port->tty;
 	if (tty && urb->actual_length) {
-		for (i = 0; i < urb->actual_length ; ++i) {
-			/* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */
-			if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
-				tty_flip_buffer_push(tty);
-			}
-			/* this doesn't actually push the data through unless tty->low_latency is set */
-			tty_insert_flip_char(tty, data[i], 0);
-		}
+		tty_buffer_request_room(tty, urb->actual_length);
+		tty_insert_flip_string(tty, data, urb->actual_length);
 		tty_flip_buffer_push(tty);
 	}
 	spin_lock_irqsave(&priv->lock, flags);
diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c
index a7c3c47..557411c 100644
--- a/drivers/usb/serial/whiteheat.c
+++ b/drivers/usb/serial/whiteheat.c
@@ -1434,7 +1434,9 @@
 		urb = wrap->urb;
 
 		if (tty && urb->actual_length) {
-			if (urb->actual_length > TTY_FLIPBUF_SIZE - tty->flip.count) {
+			int len = tty_buffer_request_room(tty, urb->actual_length);
+			/* This stuff can go away now I suspect */
+			if (unlikely(len < urb->actual_length)) {
 				spin_lock_irqsave(&info->lock, flags);
 				list_add(tmp, &info->rx_urb_q);
 				spin_unlock_irqrestore(&info->lock, flags);
@@ -1442,11 +1444,8 @@
 				schedule_work(&info->rx_work);
 				return;
 			}
-
-			memcpy(tty->flip.char_buf_ptr, urb->transfer_buffer, urb->actual_length);
-			tty->flip.char_buf_ptr += urb->actual_length;
-			tty->flip.count += urb->actual_length;
-			sent += urb->actual_length;
+			tty_insert_flip_string(tty, urb->transfer_buffer, len);
+			sent += len;
 		}
 
 		urb->dev = port->serial->dev;
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 3f04427..3e153d3 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -993,12 +993,6 @@
 	  Say Y if you have a laptop with an ATI Rage LT PRO, Rage Mobility,
 	  Rage XC, or Rage XL chipset.
 
-config FB_ATY_XL_INIT
-	bool "Rage XL No-BIOS Init support"
-	depends on FB_ATY_CT
-	help
-	  Say Y here to support booting a Rage XL without BIOS support.
-
 config FB_ATY_GX
 	bool "Mach64 GX support" if PCI
 	depends on FB_ATY
@@ -1376,7 +1370,7 @@
 
 	  This driver is also available as a module ( = code which can be
 	  inserted and removed from the running kernel whenever you want). The
-	  module will be called vfb. If you want to compile it as a module,
+	  module will be called pxafb. If you want to compile it as a module,
 	  say M here and read <file:Documentation/modules.txt>.
 
 	  If unsure, say N.
@@ -1409,7 +1403,7 @@
 
 	  This driver is also available as a module ( = code which can be
 	  inserted and removed from the running kernel whenever you want). The
-	  module will be called vfb. If you want to compile it as a module,
+	  module will be called w100fb. If you want to compile it as a module,
 	  say M here and read <file:Documentation/modules.txt>.
 
 	  If unsure, say N.
diff --git a/drivers/video/amifb.c b/drivers/video/amifb.c
index d549e21..2c42a81 100644
--- a/drivers/video/amifb.c
+++ b/drivers/video/amifb.c
@@ -590,6 +590,8 @@
 #define highw(x)	((u_long)(x)>>16 & 0xffff)
 #define loww(x)		((u_long)(x) & 0xffff)
 
+#define custom		amiga_custom
+
 #define VBlankOn()	custom.intena = IF_SETCLR|IF_COPER
 #define VBlankOff()	custom.intena = IF_COPER
 
@@ -1164,8 +1166,8 @@
 static void ami_init_display(void);
 static void ami_do_blank(void);
 static int ami_get_fix_cursorinfo(struct fb_fix_cursorinfo *fix);
-static int ami_get_var_cursorinfo(struct fb_var_cursorinfo *var, u_char *data);
-static int ami_set_var_cursorinfo(struct fb_var_cursorinfo *var, u_char *data);
+static int ami_get_var_cursorinfo(struct fb_var_cursorinfo *var, u_char __user *data);
+static int ami_set_var_cursorinfo(struct fb_var_cursorinfo *var, u_char __user *data);
 static int ami_get_cursorstate(struct fb_cursorstate *state);
 static int ami_set_cursorstate(struct fb_cursorstate *state);
 static void ami_set_sprite(void);
@@ -2179,6 +2181,7 @@
 		struct fb_var_cursorinfo var;
 		struct fb_cursorstate state;
 	} crsr;
+	void __user *argp = (void __user *)arg;
 	int i;
 
 	switch (cmd) {
@@ -2186,33 +2189,32 @@
 			i = ami_get_fix_cursorinfo(&crsr.fix);
 			if (i)
 				return i;
-			return copy_to_user((void *)arg, &crsr.fix,
+			return copy_to_user(argp, &crsr.fix,
 					    sizeof(crsr.fix)) ? -EFAULT : 0;
 
 		case FBIOGET_VCURSORINFO:
 			i = ami_get_var_cursorinfo(&crsr.var,
-				((struct fb_var_cursorinfo *)arg)->data);
+				((struct fb_var_cursorinfo __user *)arg)->data);
 			if (i)
 				return i;
-			return copy_to_user((void *)arg, &crsr.var,
+			return copy_to_user(argp, &crsr.var,
 					    sizeof(crsr.var)) ? -EFAULT : 0;
 
 		case FBIOPUT_VCURSORINFO:
-			if (copy_from_user(&crsr.var, (void *)arg,
-					   sizeof(crsr.var)))
+			if (copy_from_user(&crsr.var, argp, sizeof(crsr.var)))
 				return -EFAULT;
 			return ami_set_var_cursorinfo(&crsr.var,
-				((struct fb_var_cursorinfo *)arg)->data);
+				((struct fb_var_cursorinfo __user *)arg)->data);
 
 		case FBIOGET_CURSORSTATE:
 			i = ami_get_cursorstate(&crsr.state);
 			if (i)
 				return i;
-			return copy_to_user((void *)arg, &crsr.state,
+			return copy_to_user(argp, &crsr.state,
 					    sizeof(crsr.state)) ? -EFAULT : 0;
 
 		case FBIOPUT_CURSORSTATE:
-			if (copy_from_user(&crsr.state, (void *)arg,
+			if (copy_from_user(&crsr.state, argp,
 					   sizeof(crsr.state)))
 				return -EFAULT;
 			return ami_set_cursorstate(&crsr.state);
@@ -3325,7 +3327,7 @@
 	return 0;
 }
 
-static int ami_get_var_cursorinfo(struct fb_var_cursorinfo *var, u_char *data)
+static int ami_get_var_cursorinfo(struct fb_var_cursorinfo *var, u_char __user *data)
 {
 	struct amifb_par *par = &currentpar;
 	register u_short *lspr, *sspr;
@@ -3347,14 +3349,14 @@
 	var->yspot = par->crsr.spot_y;
 	if (size > var->height*var->width)
 		return -ENAMETOOLONG;
-	if (!access_ok(VERIFY_WRITE, (void *)data, size))
+	if (!access_ok(VERIFY_WRITE, data, size))
 		return -EFAULT;
 	delta = 1<<par->crsr.fmode;
 	lspr = lofsprite + (delta<<1);
 	if (par->bplcon0 & BPC0_LACE)
 		sspr = shfsprite + (delta<<1);
 	else
-		sspr = 0;
+		sspr = NULL;
 	for (height = (short)var->height-1; height >= 0; height--) {
 		bits = 0; words = delta; datawords = 0;
 		for (width = (short)var->width-1; width >= 0; width--) {
@@ -3400,7 +3402,7 @@
 	return 0;
 }
 
-static int ami_set_var_cursorinfo(struct fb_var_cursorinfo *var, u_char *data)
+static int ami_set_var_cursorinfo(struct fb_var_cursorinfo *var, u_char __user *data)
 {
 	struct amifb_par *par = &currentpar;
 	register u_short *lspr, *sspr;
@@ -3427,7 +3429,7 @@
 		return -EINVAL;
 	if (!var->height)
 		return -EINVAL;
-	if (!access_ok(VERIFY_READ, (void *)data, var->width*var->height))
+	if (!access_ok(VERIFY_READ, data, var->width*var->height))
 		return -EFAULT;
 	delta = 1<<fmode;
 	lofsprite = shfsprite = (u_short *)spritememory;
@@ -3442,13 +3444,13 @@
 		if (((var->height+2)<<fmode<<2) > SPRITEMEMSIZE)
 			return -EINVAL;
 		memset(lspr, 0, (var->height+2)<<fmode<<2);
-		sspr = 0;
+		sspr = NULL;
 	}
 	for (height = (short)var->height-1; height >= 0; height--) {
 		bits = 16; words = delta; datawords = 0;
 		for (width = (short)var->width-1; width >= 0; width--) {
 			unsigned long tdata = 0;
-			get_user(tdata, (char *)data);
+			get_user(tdata, data);
 			data++;
 #ifdef __mc68000__
 			asm volatile (
diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
index 2784f0a..89060b2 100644
--- a/drivers/video/arcfb.c
+++ b/drivers/video/arcfb.c
@@ -366,7 +366,8 @@
 	}
 }
 
-void arcfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
+static void arcfb_fillrect(struct fb_info *info,
+			   const struct fb_fillrect *rect)
 {
 	struct arcfb_par *par = info->par;
 
@@ -376,7 +377,8 @@
 	arcfb_lcd_update(par, rect->dx, rect->dy, rect->width, rect->height);
 }
 
-void arcfb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
+static void arcfb_copyarea(struct fb_info *info,
+			   const struct fb_copyarea *area)
 {
 	struct arcfb_par *par = info->par;
 
@@ -386,7 +388,7 @@
 	arcfb_lcd_update(par, area->dx, area->dy, area->width, area->height);
 }
 
-void arcfb_imageblit(struct fb_info *info, const struct fb_image *image)
+static void arcfb_imageblit(struct fb_info *info, const struct fb_image *image)
 {
 	struct arcfb_par *par = info->par;
 
diff --git a/drivers/video/asiliantfb.c b/drivers/video/asiliantfb.c
index c64de59..69f7554 100644
--- a/drivers/video/asiliantfb.c
+++ b/drivers/video/asiliantfb.c
@@ -549,7 +549,7 @@
 	if (!request_mem_region(addr, size, "asiliantfb"))
 		return -EBUSY;
 
-	p = framebuffer_alloc(sizeof(u32) * 256, &dp->dev);
+	p = framebuffer_alloc(sizeof(u32) * 16, &dp->dev);
 	if (!p)	{
 		release_mem_region(addr, size);
 		return -ENOMEM;
diff --git a/drivers/video/aty/Makefile b/drivers/video/aty/Makefile
index 9dec962..1852139 100644
--- a/drivers/video/aty/Makefile
+++ b/drivers/video/aty/Makefile
@@ -5,7 +5,6 @@
 atyfb-y				:= atyfb_base.o mach64_accel.o mach64_cursor.o
 atyfb-$(CONFIG_FB_ATY_GX)	+= mach64_gx.o
 atyfb-$(CONFIG_FB_ATY_CT)	+= mach64_ct.o
-atyfb-$(CONFIG_FB_ATY_XL_INIT)  += xlinit.o
 
 atyfb-objs			:= $(atyfb-y)
 
diff --git a/drivers/video/aty/atyfb.h b/drivers/video/aty/atyfb.h
index 09de173..e9b7a64 100644
--- a/drivers/video/aty/atyfb.h
+++ b/drivers/video/aty/atyfb.h
@@ -50,6 +50,7 @@
 	int sclk, mclk, mclk_pm, xclk;
 	int ref_div;
 	int ref_clk;
+	int ecp_max;
 };
 
 typedef struct {
@@ -354,6 +355,5 @@
 
 extern void aty_reset_engine(const struct atyfb_par *par);
 extern void aty_init_engine(struct atyfb_par *par, struct fb_info *info);
-extern int  atyfb_xl_init(struct fb_info *info);
 extern void aty_st_pll_ct(int offset, u8 val, const struct atyfb_par *par);
 extern u8   aty_ld_pll_ct(int offset, const struct atyfb_par *par);
diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
index 3fefdb0c..ed81005 100644
--- a/drivers/video/aty/atyfb_base.c
+++ b/drivers/video/aty/atyfb_base.c
@@ -109,9 +109,18 @@
 #define GUI_RESERVE	(1 * PAGE_SIZE)
 
 /* FIXME: remove the FAIL definition */
-#define FAIL(msg) do { printk(KERN_CRIT "atyfb: " msg "\n"); return -EINVAL; } while (0)
-#define FAIL_MAX(msg, x, _max_) do { if(x > _max_) { printk(KERN_CRIT "atyfb: " msg " %x(%x)\n", x, _max_); return -EINVAL; } } while (0)
-
+#define FAIL(msg) do { \
+	if (!(var->activate & FB_ACTIVATE_TEST)) \
+		printk(KERN_CRIT "atyfb: " msg "\n"); \
+	return -EINVAL; \
+} while (0)
+#define FAIL_MAX(msg, x, _max_) do { \
+	if (x > _max_) { \
+		if (!(var->activate & FB_ACTIVATE_TEST)) \
+			printk(KERN_CRIT "atyfb: " msg " %x(%x)\n", x, _max_); \
+		return -EINVAL; \
+	} \
+} while (0)
 #ifdef DEBUG
 #define DPRINTK(fmt, args...)	printk(KERN_DEBUG "atyfb: " fmt, ## args)
 #else
@@ -340,6 +349,7 @@
 #define ATI_CHIP_264VT3    (M64F_VT | M64F_INTEGRATED | M64F_VT_BUS | M64F_GTB_DSP | M64F_SDRAM_MAGIC_PLL)
 #define ATI_CHIP_264VT4    (M64F_VT | M64F_INTEGRATED               | M64F_GTB_DSP)
 
+/* FIXME what is this chip? */
 #define ATI_CHIP_264LT     (M64F_GT | M64F_INTEGRATED               | M64F_GTB_DSP)
 
 /* make sets shorter */
@@ -359,58 +369,60 @@
 static struct {
 	u16 pci_id;
 	const char *name;
-	int pll, mclk, xclk;
+	int pll, mclk, xclk, ecp_max;
 	u32 features;
 } aty_chips[] __devinitdata = {
 #ifdef CONFIG_FB_ATY_GX
 	/* Mach64 GX */
-	{ PCI_CHIP_MACH64GX, "ATI888GX00 (Mach64 GX)", 135, 50, 50, ATI_CHIP_88800GX },
-	{ PCI_CHIP_MACH64CX, "ATI888CX00 (Mach64 CX)", 135, 50, 50, ATI_CHIP_88800CX },
+	{ PCI_CHIP_MACH64GX, "ATI888GX00 (Mach64 GX)", 135, 50, 50, 0, ATI_CHIP_88800GX },
+	{ PCI_CHIP_MACH64CX, "ATI888CX00 (Mach64 CX)", 135, 50, 50, 0, ATI_CHIP_88800CX },
 #endif /* CONFIG_FB_ATY_GX */
 
 #ifdef CONFIG_FB_ATY_CT
-	{ PCI_CHIP_MACH64CT, "ATI264CT (Mach64 CT)", 135, 60, 60, ATI_CHIP_264CT },
-	{ PCI_CHIP_MACH64ET, "ATI264ET (Mach64 ET)", 135, 60, 60, ATI_CHIP_264ET },
-	{ PCI_CHIP_MACH64VT, "ATI264VT? (Mach64 VT)", 170, 67, 67, ATI_CHIP_264VT },
-	{ PCI_CHIP_MACH64GT, "3D RAGE (Mach64 GT)", 135, 63, 63, ATI_CHIP_264GT },
-	/* FIXME { ...ATI_264GU, maybe ATI_CHIP_264GTDVD }, */
-	{ PCI_CHIP_MACH64GU, "3D RAGE II+ (Mach64 GTB)", 200, 67, 67, ATI_CHIP_264GTB  },
-	{ PCI_CHIP_MACH64VU, "ATI264VTB (Mach64 VU)", 200, 67, 67, ATI_CHIP_264VT3 },
+	{ PCI_CHIP_MACH64CT, "ATI264CT (Mach64 CT)", 135, 60, 60, 0, ATI_CHIP_264CT },
+	{ PCI_CHIP_MACH64ET, "ATI264ET (Mach64 ET)", 135, 60, 60, 0, ATI_CHIP_264ET },
 
-	{ PCI_CHIP_MACH64LT, "3D RAGE LT (Mach64 LT)", 135, 63, 63, ATI_CHIP_264LT },
-	 /* FIXME chipset maybe ATI_CHIP_264LTPRO ? */
-	{ PCI_CHIP_MACH64LG, "3D RAGE LT-G (Mach64 LG)", 230, 63, 63, ATI_CHIP_264LTG | M64F_LT_LCD_REGS | M64F_G3_PB_1024x768 },
+	/* FIXME what is this chip? */
+	{ PCI_CHIP_MACH64LT, "ATI264LT (Mach64 LT)", 135, 63, 63, 0, ATI_CHIP_264LT },
 
-	{ PCI_CHIP_MACH64VV, "ATI264VT4 (Mach64 VV)", 230, 83, 83, ATI_CHIP_264VT4 },
+	{ PCI_CHIP_MACH64VT, "ATI264VT (Mach64 VT)", 170, 67, 67, 80, ATI_CHIP_264VT },
+	{ PCI_CHIP_MACH64GT, "3D RAGE (Mach64 GT)", 135, 63, 63, 80, ATI_CHIP_264GT },
 
-	{ PCI_CHIP_MACH64GV, "3D RAGE IIC (Mach64 GV, PCI)", 230, 83, 83, ATI_CHIP_264GT2C },
-	{ PCI_CHIP_MACH64GW, "3D RAGE IIC (Mach64 GW, AGP)", 230, 83, 83, ATI_CHIP_264GT2C },
-	{ PCI_CHIP_MACH64GY, "3D RAGE IIC (Mach64 GY, PCI)", 230, 83, 83, ATI_CHIP_264GT2C },
-	{ PCI_CHIP_MACH64GZ, "3D RAGE IIC (Mach64 GZ, AGP)", 230, 83, 83, ATI_CHIP_264GT2C },
+	{ PCI_CHIP_MACH64VU, "ATI264VT3 (Mach64 VU)", 200, 67, 67, 80, ATI_CHIP_264VT3 },
+	{ PCI_CHIP_MACH64GU, "3D RAGE II+ (Mach64 GU)", 200, 67, 67, 100, ATI_CHIP_264GTB },
 
-	{ PCI_CHIP_MACH64GB, "3D RAGE PRO (Mach64 GB, BGA, AGP)", 230, 100, 100, ATI_CHIP_264GTPRO },
-	{ PCI_CHIP_MACH64GD, "3D RAGE PRO (Mach64 GD, BGA, AGP 1x)", 230, 100, 100, ATI_CHIP_264GTPRO },
-	{ PCI_CHIP_MACH64GI, "3D RAGE PRO (Mach64 GI, BGA, PCI)", 230, 100, 100, ATI_CHIP_264GTPRO | M64F_MAGIC_VRAM_SIZE },
-	{ PCI_CHIP_MACH64GP, "3D RAGE PRO (Mach64 GP, PQFP, PCI)", 230, 100, 100, ATI_CHIP_264GTPRO },
-	{ PCI_CHIP_MACH64GQ, "3D RAGE PRO (Mach64 GQ, PQFP, PCI, limited 3D)", 230, 100, 100, ATI_CHIP_264GTPRO },
+	{ PCI_CHIP_MACH64LG, "3D RAGE LT (Mach64 LG)", 230, 63, 63, 100, ATI_CHIP_264LTG | M64F_LT_LCD_REGS | M64F_G3_PB_1024x768 },
 
-	{ PCI_CHIP_MACH64LB, "3D RAGE LT PRO (Mach64 LB, AGP)", 236, 75, 100, ATI_CHIP_264LTPRO },
-	{ PCI_CHIP_MACH64LD, "3D RAGE LT PRO (Mach64 LD, AGP)", 230, 100, 100, ATI_CHIP_264LTPRO },
-	{ PCI_CHIP_MACH64LI, "3D RAGE LT PRO (Mach64 LI, PCI)", 230, 100, 100, ATI_CHIP_264LTPRO | M64F_G3_PB_1_1 | M64F_G3_PB_1024x768 },
-	{ PCI_CHIP_MACH64LP, "3D RAGE LT PRO (Mach64 LP, PCI)", 230, 100, 100, ATI_CHIP_264LTPRO },
-	{ PCI_CHIP_MACH64LQ, "3D RAGE LT PRO (Mach64 LQ, PCI)", 230, 100, 100, ATI_CHIP_264LTPRO },
+	{ PCI_CHIP_MACH64VV, "ATI264VT4 (Mach64 VV)", 230, 83, 83, 100, ATI_CHIP_264VT4 },
 
-	{ PCI_CHIP_MACH64GM, "3D RAGE XL (Mach64 GM, AGP)", 230, 83, 63, ATI_CHIP_264XL },
-	{ PCI_CHIP_MACH64GN, "3D RAGE XL (Mach64 GN, AGP)", 230, 83, 63, ATI_CHIP_264XL },
-	{ PCI_CHIP_MACH64GO, "3D RAGE XL (Mach64 GO, PCI-66/BGA)", 230, 83, 63, ATI_CHIP_264XL },
-	{ PCI_CHIP_MACH64GR, "3D RAGE XL (Mach64 GR, PCI-33MHz)", 235, 83, 63, ATI_CHIP_264XL | M64F_SDRAM_MAGIC_PLL },
-	{ PCI_CHIP_MACH64GL, "3D RAGE XL (Mach64 GL, PCI)", 230, 83, 63, ATI_CHIP_264XL },
-	{ PCI_CHIP_MACH64GS, "3D RAGE XL (Mach64 GS, PCI)", 230, 83, 63, ATI_CHIP_264XL },
+	{ PCI_CHIP_MACH64GV, "3D RAGE IIC (Mach64 GV, PCI)", 230, 83, 83, 100, ATI_CHIP_264GT2C },
+	{ PCI_CHIP_MACH64GW, "3D RAGE IIC (Mach64 GW, AGP)", 230, 83, 83, 100, ATI_CHIP_264GT2C },
+	{ PCI_CHIP_MACH64GY, "3D RAGE IIC (Mach64 GY, PCI)", 230, 83, 83, 100, ATI_CHIP_264GT2C },
+	{ PCI_CHIP_MACH64GZ, "3D RAGE IIC (Mach64 GZ, AGP)", 230, 83, 83, 100, ATI_CHIP_264GT2C },
 
-	{ PCI_CHIP_MACH64LM, "3D RAGE Mobility P/M (Mach64 LM, AGP 2x)", 230, 83, 125, ATI_CHIP_MOBILITY },
-	{ PCI_CHIP_MACH64LN, "3D RAGE Mobility L (Mach64 LN, AGP 2x)", 230, 83, 125, ATI_CHIP_MOBILITY },
-	{ PCI_CHIP_MACH64LR, "3D RAGE Mobility P/M (Mach64 LR, PCI)", 230, 83, 125, ATI_CHIP_MOBILITY },
-	{ PCI_CHIP_MACH64LS, "3D RAGE Mobility L (Mach64 LS, PCI)", 230, 83, 125, ATI_CHIP_MOBILITY },
+	{ PCI_CHIP_MACH64GB, "3D RAGE PRO (Mach64 GB, BGA, AGP)", 230, 100, 100, 125, ATI_CHIP_264GTPRO },
+	{ PCI_CHIP_MACH64GD, "3D RAGE PRO (Mach64 GD, BGA, AGP 1x)", 230, 100, 100, 125, ATI_CHIP_264GTPRO },
+	{ PCI_CHIP_MACH64GI, "3D RAGE PRO (Mach64 GI, BGA, PCI)", 230, 100, 100, 125, ATI_CHIP_264GTPRO | M64F_MAGIC_VRAM_SIZE },
+	{ PCI_CHIP_MACH64GP, "3D RAGE PRO (Mach64 GP, PQFP, PCI)", 230, 100, 100, 125, ATI_CHIP_264GTPRO },
+	{ PCI_CHIP_MACH64GQ, "3D RAGE PRO (Mach64 GQ, PQFP, PCI, limited 3D)", 230, 100, 100, 125, ATI_CHIP_264GTPRO },
+
+	{ PCI_CHIP_MACH64LB, "3D RAGE LT PRO (Mach64 LB, AGP)", 236, 75, 100, 135, ATI_CHIP_264LTPRO },
+	{ PCI_CHIP_MACH64LD, "3D RAGE LT PRO (Mach64 LD, AGP)", 230, 100, 100, 135, ATI_CHIP_264LTPRO },
+	{ PCI_CHIP_MACH64LI, "3D RAGE LT PRO (Mach64 LI, PCI)", 230, 100, 100, 135, ATI_CHIP_264LTPRO | M64F_G3_PB_1_1 | M64F_G3_PB_1024x768 },
+	{ PCI_CHIP_MACH64LP, "3D RAGE LT PRO (Mach64 LP, PCI)", 230, 100, 100, 135, ATI_CHIP_264LTPRO },
+	{ PCI_CHIP_MACH64LQ, "3D RAGE LT PRO (Mach64 LQ, PCI)", 230, 100, 100, 135, ATI_CHIP_264LTPRO },
+
+	{ PCI_CHIP_MACH64GM, "3D RAGE XL (Mach64 GM, AGP 2x)", 230, 83, 63, 135, ATI_CHIP_264XL },
+	{ PCI_CHIP_MACH64GN, "3D RAGE XC (Mach64 GN, AGP 2x)", 230, 83, 63, 135, ATI_CHIP_264XL },
+	{ PCI_CHIP_MACH64GO, "3D RAGE XL (Mach64 GO, PCI-66)", 230, 83, 63, 135, ATI_CHIP_264XL },
+	{ PCI_CHIP_MACH64GL, "3D RAGE XC (Mach64 GL, PCI-66)", 230, 83, 63, 135, ATI_CHIP_264XL },
+	{ PCI_CHIP_MACH64GR, "3D RAGE XL (Mach64 GR, PCI-33)", 230, 83, 63, 135, ATI_CHIP_264XL | M64F_SDRAM_MAGIC_PLL },
+	{ PCI_CHIP_MACH64GS, "3D RAGE XC (Mach64 GS, PCI-33)", 230, 83, 63, 135, ATI_CHIP_264XL },
+
+	{ PCI_CHIP_MACH64LM, "3D RAGE Mobility P/M (Mach64 LM, AGP 2x)", 230, 83, 125, 135, ATI_CHIP_MOBILITY },
+	{ PCI_CHIP_MACH64LN, "3D RAGE Mobility L (Mach64 LN, AGP 2x)", 230, 83, 125, 135, ATI_CHIP_MOBILITY },
+	{ PCI_CHIP_MACH64LR, "3D RAGE Mobility P/M (Mach64 LR, PCI)", 230, 83, 125, 135, ATI_CHIP_MOBILITY },
+	{ PCI_CHIP_MACH64LS, "3D RAGE Mobility L (Mach64 LS, PCI)", 230, 83, 125, 135, ATI_CHIP_MOBILITY },
 #endif /* CONFIG_FB_ATY_CT */
 };
 
@@ -431,6 +443,7 @@
 	par->pll_limits.pll_max = aty_chips[i].pll;
 	par->pll_limits.mclk = aty_chips[i].mclk;
 	par->pll_limits.xclk = aty_chips[i].xclk;
+	par->pll_limits.ecp_max = aty_chips[i].ecp_max;
 	par->features = aty_chips[i].features;
 
 	chip_id = aty_ld_le32(CONFIG_CHIP_ID, par);
@@ -450,39 +463,63 @@
 #endif
 #ifdef CONFIG_FB_ATY_CT
 	case PCI_CHIP_MACH64VT:
-		rev &= 0xc7;
-		if(rev == 0x00) {
-			name = "ATI264VTA3 (Mach64 VT)";
-			par->pll_limits.pll_max = 170;
-			par->pll_limits.mclk = 67;
-			par->pll_limits.xclk = 67;
-			par->features = ATI_CHIP_264VT;
-		} else if(rev == 0x40) {
-			name = "ATI264VTA4 (Mach64 VT)";
+		switch (rev & 0x07) {
+		case 0x00:
+			switch (rev & 0xc0) {
+			case 0x00:
+				name = "ATI264VT (A3) (Mach64 VT)";
+				par->pll_limits.pll_max = 170;
+				par->pll_limits.mclk = 67;
+				par->pll_limits.xclk = 67;
+				par->pll_limits.ecp_max = 80;
+				par->features = ATI_CHIP_264VT;
+				break;
+			case 0x40:
+				name = "ATI264VT2 (A4) (Mach64 VT)";
+				par->pll_limits.pll_max = 200;
+				par->pll_limits.mclk = 67;
+				par->pll_limits.xclk = 67;
+				par->pll_limits.ecp_max = 80;
+				par->features = ATI_CHIP_264VT | M64F_MAGIC_POSTDIV;
+				break;
+			}
+			break;
+		case 0x01:
+			name = "ATI264VT3 (B1) (Mach64 VT)";
 			par->pll_limits.pll_max = 200;
 			par->pll_limits.mclk = 67;
 			par->pll_limits.xclk = 67;
-			par->features = ATI_CHIP_264VT | M64F_MAGIC_POSTDIV;
-		} else {
-			name = "ATI264VTB (Mach64 VT)";
-			par->pll_limits.pll_max = 200;
-			par->pll_limits.mclk = 67;
-			par->pll_limits.xclk = 67;
+			par->pll_limits.ecp_max = 80;
 			par->features = ATI_CHIP_264VTB;
+			break;
+		case 0x02:
+			name = "ATI264VT3 (B2) (Mach64 VT)";
+			par->pll_limits.pll_max = 200;
+			par->pll_limits.mclk = 67;
+			par->pll_limits.xclk = 67;
+			par->pll_limits.ecp_max = 80;
+			par->features = ATI_CHIP_264VT3;
+			break;
 		}
 		break;
 	case PCI_CHIP_MACH64GT:
-		rev &= 0x07;
-		if(rev == 0x01) {
+		switch (rev & 0x07) {
+		case 0x01:
+			name = "3D RAGE II (Mach64 GT)";
 			par->pll_limits.pll_max = 170;
 			par->pll_limits.mclk = 67;
 			par->pll_limits.xclk = 67;
+			par->pll_limits.ecp_max = 80;
 			par->features = ATI_CHIP_264GTB;
-		} else if(rev == 0x02) {
+			break;
+		case 0x02:
+			name = "3D RAGE II+ (Mach64 GT)";
 			par->pll_limits.pll_max = 200;
 			par->pll_limits.mclk = 67;
 			par->pll_limits.xclk = 67;
+			par->pll_limits.ecp_max = 100;
 			par->features = ATI_CHIP_264GTB;
+			break;
 		}
 		break;
 #endif
@@ -692,7 +729,7 @@
 		aty_st_lcd(LCD_GEN_CNTL, (crtc->lcd_gen_cntl & ~CRTC_RW_SELECT) |
 			(SHADOW_EN | SHADOW_RW_EN), par);
 
-		DPRINTK("set secondary CRT to %ix%i %c%c\n",
+		DPRINTK("set shadow CRT to %ix%i %c%c\n",
 		    ((((crtc->shadow_h_tot_disp>>16) & 0xff) + 1)<<3), (((crtc->shadow_v_tot_disp>>16) & 0x7ff) + 1),
 		    (crtc->shadow_h_sync_strt_wid & 0x200000)?'N':'P', (crtc->shadow_v_sync_strt_wid & 0x200000)?'N':'P');
 
@@ -840,11 +877,14 @@
 			   know if one is connected. So it's better to fail then.
 			 */
 			if (crtc->lcd_gen_cntl & CRT_ON) {
-				PRINTKI("Disable lcd panel, because video mode does not fit.\n");
+				if (!(var->activate & FB_ACTIVATE_TEST))
+					PRINTKI("Disable LCD panel, because video mode does not fit.\n");
 				crtc->lcd_gen_cntl &= ~LCD_ON;
 				/*aty_st_lcd(LCD_GEN_CNTL, crtc->lcd_gen_cntl, par);*/
 			} else {
-				FAIL("Video mode exceeds size of lcd panel.\nConnect this computer to a conventional monitor if you really need this mode.");
+				if (!(var->activate & FB_ACTIVATE_TEST))
+					PRINTKE("Video mode exceeds size of LCD panel.\nConnect this computer to a conventional monitor if you really need this mode.\n");
+				return -EINVAL;
 			}
 		}
 	}
@@ -858,9 +898,9 @@
 		vmode &= ~(FB_VMODE_DOUBLE | FB_VMODE_INTERLACED);
 
 		/* This is horror! When we simulate, say 640x480 on an 800x600
-		   lcd monitor, the CRTC should be programmed 800x600 values for
+		   LCD monitor, the CRTC should be programmed 800x600 values for
 		   the non visible part, but 640x480 for the visible part.
-		   This code has been tested on a laptop with it's 1400x1050 lcd
+		   This code has been tested on a laptop with it's 1400x1050 LCD
 		   monitor and a conventional monitor both switched on.
 		   Tested modes: 1280x1024, 1152x864, 1024x768, 800x600,
 		    works with little glitches also with DOUBLESCAN modes
@@ -955,16 +995,6 @@
 		vdisplay = yres;
 		if(vmode & FB_VMODE_DOUBLE)
 			vdisplay <<= 1;
-		if(vmode & FB_VMODE_INTERLACED) {
-			vdisplay >>= 1;
-
-			/* The prefered mode for the lcd is not interlaced, so disable it if
-			   it was enabled. For doublescan there is no problem, because we can
-			   compensate for it in the hardware stretching (we stretch half as much)
-			 */
-			vmode &= ~FB_VMODE_INTERLACED;
-			/*crtc->gen_cntl &= ~CRTC_INTERLACE_EN;*/
-		}
 		crtc->gen_cntl &= ~(CRTC2_EN | CRTC2_PIX_WIDTH);
 		crtc->lcd_gen_cntl &= ~(HORZ_DIVBY2_EN | DIS_HOR_CRT_DIVBY2 |
 			/*TVCLK_PM_EN | VCLK_DAC_PM_EN |*/
@@ -980,7 +1010,7 @@
 		crtc->horz_stretching &=
 			~(HORZ_STRETCH_RATIO | HORZ_STRETCH_LOOP | AUTO_HORZ_RATIO |
 			HORZ_STRETCH_MODE | HORZ_STRETCH_EN);
-		if (xres < par->lcd_width) {
+		if (xres < par->lcd_width && crtc->lcd_gen_cntl & LCD_ON) {
 			do {
 				/*
 				* The horizontal blender misbehaves when HDisplay is less than a
@@ -1042,7 +1072,7 @@
 			} while (0);
 		}
 
-		if (vdisplay < par->lcd_height) {
+		if (vdisplay < par->lcd_height && crtc->lcd_gen_cntl & LCD_ON) {
 			crtc->vert_stretching = (VERT_STRETCH_USE0 | VERT_STRETCH_EN |
 				(((vdisplay * (VERT_STRETCH_RATIO0 + 1)) / par->lcd_height) & VERT_STRETCH_RATIO0));
 
@@ -1065,9 +1095,8 @@
 #endif /* CONFIG_FB_ATY_GENERIC_LCD */
 
 	if (M64_HAS(MAGIC_FIFO)) {
-		/* Not VTB/GTB */
-		/* FIXME: magic FIFO values */
-		crtc->gen_cntl |= (aty_ld_le32(CRTC_GEN_CNTL, par) & CRTC2_PIX_WIDTH);
+		/* FIXME: display FIFO low watermark values */
+		crtc->gen_cntl |= (aty_ld_le32(CRTC_GEN_CNTL, par) & CRTC_FIFO_LWM);
 	}
 	crtc->dp_pix_width = dp_pix_width;
 	crtc->dp_chain_mask = dp_chain_mask;
@@ -1184,7 +1213,8 @@
 		var->transp.length = 8;
 		break;
 	default:
-		FAIL("Invalid pixel width");
+		PRINTKE("Invalid pixel width\n");
+		return -EINVAL;
 	}
 
 	/* output */
@@ -1241,7 +1271,8 @@
 	pixclock = atyfb_get_pixclock(var, par);
 
 	if (pixclock == 0) {
-		FAIL("Invalid pixclock");
+		PRINTKE("Invalid pixclock\n");
+		return -EINVAL;
 	} else {
 		if((err = par->pll_ops->var_to_pll(info, pixclock, var->bits_per_pixel, &par->pll)))
 			return err;
@@ -1446,7 +1477,9 @@
 	pixclock = atyfb_get_pixclock(var, par);
 
 	if (pixclock == 0) {
-		FAIL("Invalid pixclock");
+		if (!(var->activate & FB_ACTIVATE_TEST))
+			PRINTKE("Invalid pixclock\n");
+		return -EINVAL;
 	} else {
 		if((err = par->pll_ops->var_to_pll(info, pixclock, var->bits_per_pixel, &pll)))
 			return err;
@@ -2291,10 +2324,6 @@
 		par->dac_ops = &aty_dac_ct;
 		par->pll_ops = &aty_pll_ct;
 		par->bus_type = PCI;
-#ifdef CONFIG_FB_ATY_XL_INIT
-		if (IS_XL(par->pci_id))
-			atyfb_xl_init(info);
-#endif
 		par->ram_type = (aty_ld_le32(CONFIG_STAT0, par) & 0x07);
 		ramname = aty_ct_ram[par->ram_type];
 		/* for many chips, the mclk is 67 MHz for SDRAM, 63 MHz otherwise */
@@ -2638,16 +2667,16 @@
 static int atyfb_blank(int blank, struct fb_info *info)
 {
 	struct atyfb_par *par = (struct atyfb_par *) info->par;
-	u8 gen_cntl;
+	u32 gen_cntl;
 
 	if (par->lock_blank || par->asleep)
 		return 0;
 
 #ifdef CONFIG_PMAC_BACKLIGHT
-	if ((_machine == _MACH_Pmac) && blank)
+	if ((_machine == _MACH_Pmac) && blank > FB_BLANK_NORMAL)
 		set_backlight_enable(0);
 #elif defined(CONFIG_FB_ATY_GENERIC_LCD)
-	if (par->lcd_table && blank &&
+	if (par->lcd_table && blank > FB_BLANK_NORMAL &&
 	    (aty_ld_lcd(LCD_GEN_CNTL, par) & LCD_ON)) {
 		u32 pm = aty_ld_lcd(POWER_MANAGEMENT, par);
 		pm &= ~PWR_BLON;
@@ -2655,31 +2684,31 @@
 	}
 #endif
 
-	gen_cntl = aty_ld_8(CRTC_GEN_CNTL, par);
+	gen_cntl = aty_ld_le32(CRTC_GEN_CNTL, par);
 	switch (blank) {
         	case FB_BLANK_UNBLANK:
-			gen_cntl &= ~(0x4c);
+			gen_cntl &= ~0x400004c;
 			break;
 		case FB_BLANK_NORMAL:
-			gen_cntl |= 0x40;
+			gen_cntl |= 0x4000040;
 			break;
 		case FB_BLANK_VSYNC_SUSPEND:
-			gen_cntl |= 0x8;
+			gen_cntl |= 0x4000048;
 			break;
 		case FB_BLANK_HSYNC_SUSPEND:
-			gen_cntl |= 0x4;
+			gen_cntl |= 0x4000044;
 			break;
 		case FB_BLANK_POWERDOWN:
-			gen_cntl |= 0x4c;
+			gen_cntl |= 0x400004c;
 			break;
 	}
-	aty_st_8(CRTC_GEN_CNTL, gen_cntl, par);
+	aty_st_le32(CRTC_GEN_CNTL, gen_cntl, par);
 
 #ifdef CONFIG_PMAC_BACKLIGHT
-	if ((_machine == _MACH_Pmac) && !blank)
+	if ((_machine == _MACH_Pmac) && blank <= FB_BLANK_NORMAL)
 		set_backlight_enable(1);
 #elif defined(CONFIG_FB_ATY_GENERIC_LCD)
-	if (par->lcd_table && !blank &&
+	if (par->lcd_table && blank <= FB_BLANK_NORMAL &&
 	    (aty_ld_lcd(LCD_GEN_CNTL, par) & LCD_ON)) {
 		u32 pm = aty_ld_lcd(POWER_MANAGEMENT, par);
 		pm |= PWR_BLON;
@@ -3157,15 +3186,15 @@
 			refresh_rates_buf, lcd_refresh_rates[default_refresh_rate]);
 		par->lcd_refreshrate = lcd_refresh_rates[default_refresh_rate];
 		/* We now need to determine the crtc parameters for the
-		 * lcd monitor. This is tricky, because they are not stored
+		 * LCD monitor. This is tricky, because they are not stored
 		 * individually in the BIOS. Instead, the BIOS contains a
 		 * table of display modes that work for this monitor.
 		 *
 		 * The idea is that we search for a mode of the same dimensions
-		 * as the dimensions of the lcd monitor. Say our lcd monitor
+		 * as the dimensions of the LCD monitor. Say our LCD monitor
 		 * is 800x600 pixels, we search for a 800x600 monitor.
 		 * The CRTC parameters we find here are the ones that we need
-		 * to use to simulate other resolutions on the lcd screen.
+		 * to use to simulate other resolutions on the LCD screen.
 		 */
 		lcdmodeptr = (u16 *)(par->lcd_table + 64);
 		while (*lcdmodeptr != 0) {
@@ -3472,7 +3501,7 @@
 
 static int __devinit atyfb_atari_probe(void)
 {
-	struct aty_par *par;
+	struct atyfb_par *par;
 	struct fb_info *info;
 	int m64_num;
 	u32 clock_r;
@@ -3692,9 +3721,7 @@
     atyfb_setup(option);
 #endif
 
-#ifdef CONFIG_PCI
     pci_register_driver(&atyfb_driver);
-#endif
 #ifdef CONFIG_ATARI
     atyfb_atari_probe();
 #endif
@@ -3703,9 +3730,7 @@
 
 static void __exit atyfb_exit(void)
 {
-#ifdef CONFIG_PCI
 	pci_unregister_driver(&atyfb_driver);
-#endif
 }
 
 module_init(atyfb_init);
diff --git a/drivers/video/aty/mach64_ct.c b/drivers/video/aty/mach64_ct.c
index 9bdb2aa..e705693 100644
--- a/drivers/video/aty/mach64_ct.c
+++ b/drivers/video/aty/mach64_ct.c
@@ -206,9 +206,7 @@
 {
 	u32 q;
 	struct atyfb_par *par = (struct atyfb_par *) info->par;
-#ifdef DEBUG
 	int pllvclk;
-#endif
 
 	/* FIXME: use the VTB/GTB /{3,6,12} post dividers if they're better suited */
 	q = par->ref_clk_per * pll->pll_ref_div * 4 / vclk_per;
@@ -223,13 +221,26 @@
 	pll->vclk_post_div_real = postdividers[pll->vclk_post_div];
 	//    pll->vclk_post_div <<= 6;
 	pll->vclk_fb_div = q * pll->vclk_post_div_real / 8;
-#ifdef DEBUG
 	pllvclk = (1000000 * 2 * pll->vclk_fb_div) /
 		(par->ref_clk_per * pll->pll_ref_div);
+#ifdef DEBUG
 	printk("atyfb(%s): pllvclk=%d MHz, vclk=%d MHz\n",
 		__FUNCTION__, pllvclk, pllvclk / pll->vclk_post_div_real);
 #endif
 	pll->pll_vclk_cntl = 0x03; /* VCLK = PLL_VCLK/VCLKx_POST */
+
+	/* Set ECP (scaler/overlay clock) divider */
+	if (par->pll_limits.ecp_max) {
+		int ecp = pllvclk / pll->vclk_post_div_real;
+		int ecp_div = 0;
+
+		while (ecp > par->pll_limits.ecp_max && ecp_div < 2) {
+			ecp >>= 1;
+			ecp_div++;
+		}
+		pll->pll_vclk_cntl |= ecp_div << 4;
+	}
+
 	return 0;
 }
 
diff --git a/drivers/video/aty/xlinit.c b/drivers/video/aty/xlinit.c
deleted file mode 100644
index a085cbf..0000000
--- a/drivers/video/aty/xlinit.c
+++ /dev/null
@@ -1,359 +0,0 @@
-/*
- *  ATI Rage XL Initialization. Support for Xpert98 and Victoria
- *  PCI cards.
- *
- *  Copyright (C) 2002 MontaVista Software Inc.
- *  Author: MontaVista Software, Inc.
- *         	stevel@mvista.com or source@mvista.com
- *
- *  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  SOFTWARE  IS PROVIDED   ``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  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.
- *
- *  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.
- */
-#include <linux/config.h>
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/errno.h>
-#include <linux/string.h>
-#include <linux/mm.h> 
-#include <linux/slab.h>
-#include <linux/vmalloc.h>
-#include <linux/delay.h>
-#include <linux/fb.h>
-#include <linux/init.h>
-#include <linux/pci.h>
-#include <asm/io.h>
-#include <video/mach64.h>
-#include "atyfb.h"
-
-#define MPLL_GAIN       0xad
-#define VPLL_GAIN       0xd5
-
-enum {
-	VICTORIA = 0,
-	XPERT98,
-	NUM_XL_CARDS
-};
-
-extern const struct aty_pll_ops aty_pll_ct;
-
-#define DEFAULT_CARD XPERT98
-static int xl_card = DEFAULT_CARD;
-
-static const struct xl_card_cfg_t {
-	int ref_crystal; // 10^4 Hz
-	int mem_type;
-	int mem_size;
-	u32 mem_cntl;
-	u32 ext_mem_cntl;
-	u32 mem_addr_config;
-	u32 bus_cntl;
-	u32 dac_cntl;
-	u32 hw_debug;
-	u32 custom_macro_cntl;
-	u8  dll2_cntl;
-	u8  pll_yclk_cntl;
-} card_cfg[NUM_XL_CARDS] = {
-	// VICTORIA
-	{	2700, SDRAM, 0x800000,
-		0x10757A3B, 0x64000C81, 0x00110202, 0x7b33A040,
-		0x82010102, 0x48803800, 0x005E0179,
-		0x50, 0x25
-	},
-	// XPERT98
-	{	1432,  WRAM, 0x800000,
-		0x00165A2B, 0xE0000CF1, 0x00200213, 0x7333A001,
-		0x8000000A, 0x48833800, 0x007F0779,
-		0x10, 0x19
-	}
-};
-	  
-typedef struct {
-	u8 lcd_reg;
-	u32 val;
-} lcd_tbl_t;
-
-static const lcd_tbl_t lcd_tbl[] = {
-	{ 0x01,	0x000520C0 },
-	{ 0x08,	0x02000408 },
-	{ 0x03,	0x00000F00 },
-	{ 0x00,	0x00000000 },
-	{ 0x02,	0x00000000 },
-	{ 0x04,	0x00000000 },
-	{ 0x05,	0x00000000 },
-	{ 0x06,	0x00000000 },
-	{ 0x33,	0x00000000 },
-	{ 0x34,	0x00000000 },
-	{ 0x35,	0x00000000 },
-	{ 0x36,	0x00000000 },
-	{ 0x37,	0x00000000 }
-};
-
-static void reset_gui(struct atyfb_par *par)
-{
-	aty_st_8(GEN_TEST_CNTL+1, 0x01, par);
-	aty_st_8(GEN_TEST_CNTL+1, 0x00, par);
-	aty_st_8(GEN_TEST_CNTL+1, 0x02, par);
-	mdelay(5);
-}
-
-static void reset_sdram(struct atyfb_par *par)
-{
-	u8 temp;
-
-	temp = aty_ld_8(EXT_MEM_CNTL, par);
-	temp |= 0x02;
-	aty_st_8(EXT_MEM_CNTL, temp, par); // MEM_SDRAM_RESET = 1b
-	temp |= 0x08;
-	aty_st_8(EXT_MEM_CNTL, temp, par); // MEM_CYC_TEST    = 10b
-	temp |= 0x0c;
-	aty_st_8(EXT_MEM_CNTL, temp, par); // MEM_CYC_TEST    = 11b
-	mdelay(5);
-	temp &= 0xf3;
-	aty_st_8(EXT_MEM_CNTL, temp, par); // MEM_CYC_TEST    = 00b
-	temp &= 0xfd;
-	aty_st_8(EXT_MEM_CNTL, temp, par); // MEM_SDRAM_REST  = 0b
-	mdelay(5);
-}
-
-static void init_dll(struct atyfb_par *par)
-{
-	// enable DLL
-	aty_st_pll_ct(PLL_GEN_CNTL,
-		   aty_ld_pll_ct(PLL_GEN_CNTL, par) & 0x7f,
-		   par);
-
-	// reset DLL
-	aty_st_pll_ct(DLL_CNTL, 0x82, par);
-	aty_st_pll_ct(DLL_CNTL, 0xE2, par);
-	mdelay(5);
-	aty_st_pll_ct(DLL_CNTL, 0x82, par);
-	mdelay(6);
-}
-
-static void reset_clocks(struct atyfb_par *par, struct pll_ct *pll,
-			 int hsync_enb)
-{
-	reset_gui(par);
-	aty_st_pll_ct(MCLK_FB_DIV, pll->mclk_fb_div, par);
-	aty_st_pll_ct(SCLK_FB_DIV, pll->sclk_fb_div, par);
-
-	mdelay(15);
-	init_dll(par);
-	aty_st_8(GEN_TEST_CNTL+1, 0x00, par);
-	mdelay(5);
-	aty_st_8(CRTC_GEN_CNTL+3, 0x04, par);
-	mdelay(6);
-	reset_sdram(par);
-	aty_st_8(CRTC_GEN_CNTL+3,
-		 hsync_enb ? 0x00 : 0x04, par);
-
-	aty_st_pll_ct(SPLL_CNTL2, pll->spll_cntl2, par);
-	aty_st_pll_ct(PLL_GEN_CNTL, pll->pll_gen_cntl, par);
-	aty_st_pll_ct(PLL_VCLK_CNTL, pll->pll_vclk_cntl, par);
-}
-
-int atyfb_xl_init(struct fb_info *info)
-{
-	const struct xl_card_cfg_t * card = &card_cfg[xl_card];
-	struct atyfb_par *par = (struct atyfb_par *) info->par;
-	union aty_pll pll;
-	int err;
-	u32 temp;
-	
-	aty_st_8(CONFIG_STAT0, 0x85, par);
-	mdelay(10);
-
-	/*
-	 * The following needs to be set before the call
-	 * to var_to_pll() below. They'll be re-set again
-	 * to the same values in aty_init().
-	 */
-	par->ref_clk_per = 100000000UL/card->ref_crystal;
-	par->ram_type = card->mem_type;
-	info->fix.smem_len = card->mem_size;
-	if (xl_card == VICTORIA) {
-		// the MCLK, XCLK are 120MHz on victoria card
-		par->mclk_per = 1000000/120;
-		par->xclk_per = 1000000/120;
-		par->features &= ~M64F_MFB_FORCE_4;
-	}
-	
-	/*
-	 * Calculate mclk and xclk dividers, etc. The passed
-	 * pixclock and bpp values don't matter yet, the vclk
-	 * isn't programmed until later.
-	 */
-	if ((err = aty_pll_ct.var_to_pll(info, 39726, 8, &pll)))
-		return err;
-
-	aty_st_pll_ct(LVDS_CNTL0, 0x00, par);
-	aty_st_pll_ct(DLL2_CNTL, card->dll2_cntl, par);
-	aty_st_pll_ct(V2PLL_CNTL, 0x10, par);
-	aty_st_pll_ct(MPLL_CNTL, MPLL_GAIN, par);
-	aty_st_pll_ct(VPLL_CNTL, VPLL_GAIN, par);
-	aty_st_pll_ct(PLL_VCLK_CNTL, 0x00, par);
-	aty_st_pll_ct(VFC_CNTL, 0x1B, par);
-	aty_st_pll_ct(PLL_REF_DIV, pll.ct.pll_ref_div, par);
-	aty_st_pll_ct(PLL_EXT_CNTL, pll.ct.pll_ext_cntl, par);
-	aty_st_pll_ct(SPLL_CNTL2, 0x03, par);
-	aty_st_pll_ct(PLL_GEN_CNTL, 0x44, par);
-
-	reset_clocks(par, &pll.ct, 0);
-	mdelay(10);
-
-	aty_st_pll_ct(VCLK_POST_DIV, 0x03, par);
-	aty_st_pll_ct(VCLK0_FB_DIV, 0xDA, par);
-	aty_st_pll_ct(VCLK_POST_DIV, 0x0F, par);
-	aty_st_pll_ct(VCLK1_FB_DIV, 0xF5, par);
-	aty_st_pll_ct(VCLK_POST_DIV, 0x3F, par);
-	aty_st_pll_ct(PLL_EXT_CNTL, 0x40 | pll.ct.pll_ext_cntl, par);
-	aty_st_pll_ct(VCLK2_FB_DIV, 0x00, par);
-	aty_st_pll_ct(VCLK_POST_DIV, 0xFF, par);
-	aty_st_pll_ct(PLL_EXT_CNTL, 0xC0 | pll.ct.pll_ext_cntl, par);
-	aty_st_pll_ct(VCLK3_FB_DIV, 0x00, par);
-
-	aty_st_8(BUS_CNTL, 0x01, par);
-	aty_st_le32(BUS_CNTL, card->bus_cntl | 0x08000000, par);
-
-	aty_st_le32(CRTC_GEN_CNTL, 0x04000200, par);
-	aty_st_le16(CONFIG_STAT0, 0x0020, par);
-	aty_st_le32(MEM_CNTL, 0x10151A33, par);
-	aty_st_le32(EXT_MEM_CNTL, 0xE0000C01, par);
-	aty_st_le16(CRTC_GEN_CNTL+2, 0x0000, par);
-	aty_st_le32(DAC_CNTL, card->dac_cntl, par);
-	aty_st_le16(GEN_TEST_CNTL, 0x0100, par);
-	aty_st_le32(CUSTOM_MACRO_CNTL, 0x003C0171, par);
-	aty_st_le32(MEM_BUF_CNTL, 0x00382848, par);
-
-	aty_st_le32(HW_DEBUG, card->hw_debug, par);
-	aty_st_le16(MEM_ADDR_CONFIG, 0x0000, par);
-	aty_st_le16(GP_IO+2, 0x0000, par);
-	aty_st_le16(GEN_TEST_CNTL, 0x0000, par);
-	aty_st_le16(EXT_DAC_REGS+2, 0x0000, par);
-	aty_st_le32(CRTC_INT_CNTL, 0x00000000, par);
-	aty_st_le32(TIMER_CONFIG, 0x00000000, par);
-	aty_st_le32(0xEC, 0x00000000, par);
-	aty_st_le32(0xFC, 0x00000000, par);
-
-#if defined (CONFIG_FB_ATY_GENERIC_LCD)
-	{
-		int i;
-
-		for (i = 0; i < ARRAY_SIZE(lcd_tbl); i++)
-			aty_st_lcd(lcd_tbl[i].lcd_reg, lcd_tbl[i].val, par);
-	}
-#endif
-
-	aty_st_le16(CONFIG_STAT0, 0x00A4, par);
-	mdelay(10);
-
-	aty_st_8(BUS_CNTL+1, 0xA0, par);
-	mdelay(10);
-	
-	reset_clocks(par, &pll.ct, 1);
-	mdelay(10);
-
-	// something about power management
-	aty_st_8(LCD_INDEX, 0x08, par);
-	aty_st_8(LCD_DATA, 0x0A, par);
-	aty_st_8(LCD_INDEX, 0x08, par);
-	aty_st_8(LCD_DATA+3, 0x02, par);
-	aty_st_8(LCD_INDEX, 0x08, par);
-	aty_st_8(LCD_DATA, 0x0B, par);
-	mdelay(2);
-	
-	// enable display requests, enable CRTC
-	aty_st_8(CRTC_GEN_CNTL+3, 0x02, par);
-	// disable display
-	aty_st_8(CRTC_GEN_CNTL, 0x40, par);
-	// disable display requests, disable CRTC
-	aty_st_8(CRTC_GEN_CNTL+3, 0x04, par);
-	mdelay(10);
-
-	aty_st_pll_ct(PLL_YCLK_CNTL, 0x25, par);
-
-	aty_st_le16(CUSTOM_MACRO_CNTL, 0x0179, par);
-	aty_st_le16(CUSTOM_MACRO_CNTL+2, 0x005E, par);
-	aty_st_le16(CUSTOM_MACRO_CNTL+2, card->custom_macro_cntl>>16, par);
-	aty_st_8(CUSTOM_MACRO_CNTL+1,
-		 (card->custom_macro_cntl>>8) & 0xff, par);
-
-	aty_st_le32(MEM_ADDR_CONFIG, card->mem_addr_config, par);
-	aty_st_le32(MEM_CNTL, card->mem_cntl, par);
-	aty_st_le32(EXT_MEM_CNTL, card->ext_mem_cntl, par);
-
-	aty_st_8(CONFIG_STAT0, 0xA0 | card->mem_type, par);
-
-	aty_st_pll_ct(PLL_YCLK_CNTL, 0x01, par);
-	mdelay(15);
-	aty_st_pll_ct(PLL_YCLK_CNTL, card->pll_yclk_cntl, par);
-	mdelay(1);
-	
-	reset_clocks(par, &pll.ct, 0);
-	mdelay(50);
-	reset_clocks(par, &pll.ct, 0);
-	mdelay(50);
-
-	// enable extended register block
-	aty_st_8(BUS_CNTL+3, 0x7B, par);
-	mdelay(1);
-	// disable extended register block
-	aty_st_8(BUS_CNTL+3, 0x73, par);
-
-	aty_st_8(CONFIG_STAT0, 0x80 | card->mem_type, par);
-
-	// disable display requests, disable CRTC
-	aty_st_8(CRTC_GEN_CNTL+3, 0x04, par);
-	// disable mapping registers in VGA aperture
-	aty_st_8(CONFIG_CNTL, aty_ld_8(CONFIG_CNTL, par) & ~0x04, par);
-	mdelay(50);
-	// enable display requests, enable CRTC
-	aty_st_8(CRTC_GEN_CNTL+3, 0x02, par);
-
-	// make GPIO's 14,15,16 all inputs
-	aty_st_8(LCD_INDEX, 0x07, par);
-	aty_st_8(LCD_DATA+3, 0x00, par);
-
-	// enable the display
-	aty_st_8(CRTC_GEN_CNTL, 0x00, par);
-	mdelay(17);
-	// reset the memory controller
-	aty_st_8(GEN_TEST_CNTL+1, 0x02, par);
-	mdelay(15);
-	aty_st_8(GEN_TEST_CNTL+1, 0x00, par);
-	mdelay(30);
-
-	// enable extended register block
-	aty_st_8(BUS_CNTL+3,
-		 (u8)(aty_ld_8(BUS_CNTL+3, par) | 0x08),
-		 par);
-	// set FIFO size to 512 (PIO)
-	aty_st_le32(GUI_CNTL,
-		    aty_ld_le32(GUI_CNTL, par) & ~0x3,
-		    par);
-
-	// enable CRT and disable lcd
-	aty_st_8(LCD_INDEX, 0x01, par);
-	temp = aty_ld_le32(LCD_DATA, par);
-	temp = (temp | 0x01) & ~0x02;
-	aty_st_le32(LCD_DATA, temp, par);
-	return 0;
-}
-
diff --git a/drivers/video/console/bitblit.c b/drivers/video/console/bitblit.c
index e65fc3e..eea422e 100644
--- a/drivers/video/console/bitblit.c
+++ b/drivers/video/console/bitblit.c
@@ -234,14 +234,14 @@
 	}
 }
 
-static void bit_cursor(struct vc_data *vc, struct fb_info *info,
-		       struct display *p, int mode, int softback_lines, int fg, int bg)
+static void bit_cursor(struct vc_data *vc, struct fb_info *info, int mode,
+		       int softback_lines, int fg, int bg)
 {
 	struct fb_cursor cursor;
-	struct fbcon_ops *ops = (struct fbcon_ops *) info->fbcon_par;
+	struct fbcon_ops *ops = info->fbcon_par;
 	unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
 	int w = (vc->vc_font.width + 7) >> 3, c;
-	int y = real_y(p, vc->vc_y);
+	int y = real_y(ops->p, vc->vc_y);
 	int attribute, use_sw = (vc->vc_cursor_type & 0x10);
 	int err = 1;
 	char *src;
@@ -310,7 +310,7 @@
 	}
 
 	if (cursor.set & FB_CUR_SETSIZE ||
-	    vc->vc_cursor_type != p->cursor_shape ||
+	    vc->vc_cursor_type != ops->p->cursor_shape ||
 	    ops->cursor_state.mask == NULL ||
 	    ops->cursor_reset) {
 		char *mask = kmalloc(w*vc->vc_font.height, GFP_ATOMIC);
@@ -323,10 +323,10 @@
 		kfree(ops->cursor_state.mask);
 		ops->cursor_state.mask = mask;
 
-		p->cursor_shape = vc->vc_cursor_type;
+		ops->p->cursor_shape = vc->vc_cursor_type;
 		cursor.set |= FB_CUR_SETSHAPE;
 
-		switch (p->cursor_shape & CUR_HWMASK) {
+		switch (ops->p->cursor_shape & CUR_HWMASK) {
 		case CUR_NONE:
 			cur_height = 0;
 			break;
diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
index 50e4c4e..041d069 100644
--- a/drivers/video/console/fbcon.c
+++ b/drivers/video/console/fbcon.c
@@ -209,13 +209,13 @@
 #endif
 
 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
-static inline void fbcon_set_rotation(struct fb_info *info, struct display *p)
+static inline void fbcon_set_rotation(struct fb_info *info)
 {
 	struct fbcon_ops *ops = info->fbcon_par;
 
 	if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
-	    p->con_rotate < 4)
-		ops->rotate = p->con_rotate;
+	    ops->p->con_rotate < 4)
+		ops->rotate = ops->p->con_rotate;
 	else
 		ops->rotate = 0;
 }
@@ -265,7 +265,7 @@
 	fbcon_set_all_vcs(info);
 }
 #else
-static inline void fbcon_set_rotation(struct fb_info *info, struct display *p)
+static inline void fbcon_set_rotation(struct fb_info *info)
 {
 	struct fbcon_ops *ops = info->fbcon_par;
 
@@ -402,7 +402,7 @@
 	c = scr_readw((u16 *) vc->vc_pos);
 	mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
 		CM_ERASE : CM_DRAW;
-	ops->cursor(vc, info, p, mode, softback_lines, get_color(vc, info, c, 1),
+	ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
 		    get_color(vc, info, c, 0));
 	release_console_sem();
 }
@@ -647,29 +647,27 @@
 }
 
 #ifdef CONFIG_FB_TILEBLITTING
-static void set_blitting_type(struct vc_data *vc, struct fb_info *info,
-			      struct display *p)
+static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
 {
 	struct fbcon_ops *ops = info->fbcon_par;
 
-	ops->p = (p) ? p : &fb_display[vc->vc_num];
+	ops->p = &fb_display[vc->vc_num];
 
 	if ((info->flags & FBINFO_MISC_TILEBLITTING))
-		fbcon_set_tileops(vc, info, p, ops);
+		fbcon_set_tileops(vc, info);
 	else {
-		fbcon_set_rotation(info, ops->p);
+		fbcon_set_rotation(info);
 		fbcon_set_bitops(ops);
 	}
 }
 #else
-static void set_blitting_type(struct vc_data *vc, struct fb_info *info,
-			      struct display *p)
+static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
 {
 	struct fbcon_ops *ops = info->fbcon_par;
 
 	info->flags &= ~FBINFO_MISC_TILEBLITTING;
-	ops->p = (p) ? p : &fb_display[vc->vc_num];
-	fbcon_set_rotation(info, ops->p);
+	ops->p = &fb_display[vc->vc_num];
+	fbcon_set_rotation(info);
 	fbcon_set_bitops(ops);
 }
 #endif /* CONFIG_MISC_TILEBLITTING */
@@ -689,15 +687,14 @@
 		err = -ENODEV;
 
 	if (!err) {
-		ops = kmalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
+		ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
 		if (!ops)
 			err = -ENOMEM;
 	}
 
 	if (!err) {
-		memset(ops, 0, sizeof(struct fbcon_ops));
 		info->fbcon_par = ops;
-		set_blitting_type(vc, info, NULL);
+		set_blitting_type(vc, info);
 	}
 
 	if (err) {
@@ -921,19 +918,18 @@
 		return NULL;
 	}
 
-	ops = kmalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
+	ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
 	if (!ops) {
 		module_put(owner);
 		return NULL;
 	}
 
-	memset(ops, 0, sizeof(struct fbcon_ops));
 	ops->currcon = -1;
 	ops->graphics = 1;
 	ops->cur_rotate = -1;
 	info->fbcon_par = ops;
 	p->con_rotate = rotate;
-	set_blitting_type(vc, info, NULL);
+	set_blitting_type(vc, info);
 
 	if (info->fix.type != FB_TYPE_TEXT) {
 		if (fbcon_softback_size) {
@@ -1093,7 +1089,7 @@
 
 	ops = info->fbcon_par;
 	p->con_rotate = rotate;
-	set_blitting_type(vc, info, NULL);
+	set_blitting_type(vc, info);
 
 	cols = vc->vc_cols;
 	rows = vc->vc_rows;
@@ -1141,9 +1137,9 @@
 	if (vc == svc && softback_buf)
 		fbcon_update_softback(vc);
 
-	if (ops->rotate_font && ops->rotate_font(info, vc, p)) {
+	if (ops->rotate_font && ops->rotate_font(info, vc)) {
 		ops->rotate = FB_ROTATE_UR;
-		set_blitting_type(vc, info, p);
+		set_blitting_type(vc, info);
 	}
 
 }
@@ -1243,7 +1239,6 @@
 {
 	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
 	struct fbcon_ops *ops = info->fbcon_par;
-	struct display *p = &fb_display[vc->vc_num];
 	int y;
  	int c = scr_readw((u16 *) vc->vc_pos);
 
@@ -1260,7 +1255,7 @@
 		y = 0;
 	}
 
-	ops->cursor(vc, info, p, mode, y, get_color(vc, info, c, 1),
+	ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
 		    get_color(vc, info, c, 0));
 	vbl_cursor_cnt = CURSOR_DRAW_DELAY;
 }
@@ -1411,16 +1406,13 @@
 	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
 	struct fbcon_ops *ops = info->fbcon_par;
 	struct display *p = &fb_display[vc->vc_num];
-	int redraw = 0;
 
 	p->yscroll += count;
+
 	if (p->yscroll > p->vrows - vc->vc_rows) {
 		p->yscroll -= p->vrows - vc->vc_rows;
-		redraw = 1;
-	}
-
-	if (redraw)
 		fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
+	}
 
 	ops->var.xoffset = 0;
 	ops->var.yoffset = p->yscroll * vc->vc_font.height;
@@ -1462,16 +1454,13 @@
 	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
 	struct fbcon_ops *ops = info->fbcon_par;
 	struct display *p = &fb_display[vc->vc_num];
-	int redraw = 0;
 
 	p->yscroll -= count;
+
 	if (p->yscroll < 0) {
 		p->yscroll += p->vrows - vc->vc_rows;
-		redraw = 1;
-	}
-
-	if (redraw)
 		fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
+	}
 
 	ops->var.xoffset = 0;
 	ops->var.yoffset = p->yscroll * vc->vc_font.height;
@@ -1968,7 +1957,8 @@
 		divides(ypan, vc->vc_font.height) && vyres > yres;
 	int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
 		divides(ywrap, vc->vc_font.height) &&
-		divides(vc->vc_font.height, vyres);
+		divides(vc->vc_font.height, vyres) &&
+		divides(vc->vc_font.height, yres);
 	int reading_fast = cap & FBINFO_READS_FAST;
 	int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
 		!(cap & FBINFO_HWACCEL_DISABLED);
@@ -2107,16 +2097,19 @@
 				 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
 		if (info->fbops->fb_set_par)
 			info->fbops->fb_set_par(info);
-		fbcon_del_cursor_timer(old_info);
-		fbcon_add_cursor_timer(info);
+
+		if (old_info != info) {
+			fbcon_del_cursor_timer(old_info);
+			fbcon_add_cursor_timer(info);
+		}
 	}
 
-	set_blitting_type(vc, info, p);
+	set_blitting_type(vc, info);
 	ops->cursor_reset = 1;
 
-	if (ops->rotate_font && ops->rotate_font(info, vc, p)) {
+	if (ops->rotate_font && ops->rotate_font(info, vc)) {
 		ops->rotate = FB_ROTATE_UR;
-		set_blitting_type(vc, info, p);
+		set_blitting_type(vc, info);
 	}
 
 	vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
@@ -2739,7 +2732,7 @@
 		return;
 
 	p = &fb_display[vc->vc_num];
-	set_blitting_type(vc, info, p);
+	set_blitting_type(vc, info);
 
 	if (CON_IS_VISIBLE(vc)) {
 		var_to_display(p, &info->var, info);
@@ -2781,7 +2774,7 @@
 			continue;
 
 		p = &fb_display[vc->vc_num];
-		set_blitting_type(vc, info, p);
+		set_blitting_type(vc, info);
 		var_to_display(p, &info->var, info);
 		cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
 		rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
@@ -2806,6 +2799,8 @@
 				fbcon_update_softback(vc);
 		}
 	}
+
+	ops->p = &fb_display[ops->currcon];
 }
 
 static int fbcon_mode_deleted(struct fb_info *info,
diff --git a/drivers/video/console/fbcon.h b/drivers/video/console/fbcon.h
index 6892e7f..c38c3d8 100644
--- a/drivers/video/console/fbcon.h
+++ b/drivers/video/console/fbcon.h
@@ -62,12 +62,10 @@
 		      int fg, int bg);
 	void (*clear_margins)(struct vc_data *vc, struct fb_info *info,
 			      int bottom_only);
-	void (*cursor)(struct vc_data *vc, struct fb_info *info,
-		       struct display *p, int mode, int softback_lines,
-		       int fg, int bg);
+	void (*cursor)(struct vc_data *vc, struct fb_info *info, int mode,
+		       int softback_lines, int fg, int bg);
 	int  (*update_start)(struct fb_info *info);
-	int  (*rotate_font)(struct fb_info *info, struct vc_data *vc,
-			    struct display *p);
+	int  (*rotate_font)(struct fb_info *info, struct vc_data *vc);
 	struct fb_var_screeninfo var;  /* copy of the current fb_var_screeninfo */
 	struct timer_list cursor_timer; /* Cursor timer */
 	struct fb_cursor cursor_state;
@@ -173,8 +171,7 @@
 #define SCROLL_PAN_REDRAW  0x005
 
 #ifdef CONFIG_FB_TILEBLITTING
-extern void fbcon_set_tileops(struct vc_data *vc, struct fb_info *info,
-			      struct display *p, struct fbcon_ops *ops);
+extern void fbcon_set_tileops(struct vc_data *vc, struct fb_info *info);
 #endif
 extern void fbcon_set_bitops(struct fbcon_ops *ops);
 extern int  soft_cursor(struct fb_info *info, struct fb_cursor *cursor);
diff --git a/drivers/video/console/fbcon_ccw.c b/drivers/video/console/fbcon_ccw.c
index 4952b66..990289a 100644
--- a/drivers/video/console/fbcon_ccw.c
+++ b/drivers/video/console/fbcon_ccw.c
@@ -219,19 +219,18 @@
 	}
 }
 
-static void ccw_cursor(struct vc_data *vc, struct fb_info *info,
-		      struct display *p, int mode, int softback_lines,
-		      int fg, int bg)
+static void ccw_cursor(struct vc_data *vc, struct fb_info *info, int mode,
+		       int softback_lines, int fg, int bg)
 {
 	struct fb_cursor cursor;
-	struct fbcon_ops *ops = (struct fbcon_ops *) info->fbcon_par;
+	struct fbcon_ops *ops = info->fbcon_par;
 	unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
 	int w = (vc->vc_font.height + 7) >> 3, c;
-	int y = real_y(p, vc->vc_y);
+	int y = real_y(ops->p, vc->vc_y);
 	int attribute, use_sw = (vc->vc_cursor_type & 0x10);
 	int err = 1, dx, dy;
 	char *src;
-	u32 vyres = GETVYRES(p->scrollmode, info);
+	u32 vyres = GETVYRES(ops->p->scrollmode, info);
 
 	if (!ops->fontbuffer)
 		return;
@@ -303,7 +302,7 @@
 	}
 
 	if (cursor.set & FB_CUR_SETSIZE ||
-	    vc->vc_cursor_type != p->cursor_shape ||
+	    vc->vc_cursor_type != ops->p->cursor_shape ||
 	    ops->cursor_state.mask == NULL ||
 	    ops->cursor_reset) {
 		char *tmp, *mask = kmalloc(w*vc->vc_font.width, GFP_ATOMIC);
@@ -323,10 +322,10 @@
 		kfree(ops->cursor_state.mask);
 		ops->cursor_state.mask = mask;
 
-		p->cursor_shape = vc->vc_cursor_type;
+		ops->p->cursor_shape = vc->vc_cursor_type;
 		cursor.set |= FB_CUR_SETSHAPE;
 
-		switch (p->cursor_shape & CUR_HWMASK) {
+		switch (ops->p->cursor_shape & CUR_HWMASK) {
 		case CUR_NONE:
 			cur_height = 0;
 			break;
diff --git a/drivers/video/console/fbcon_cw.c b/drivers/video/console/fbcon_cw.c
index 6d92b84..d44c5fa 100644
--- a/drivers/video/console/fbcon_cw.c
+++ b/drivers/video/console/fbcon_cw.c
@@ -203,19 +203,18 @@
 	}
 }
 
-static void cw_cursor(struct vc_data *vc, struct fb_info *info,
-		      struct display *p, int mode, int softback_lines,
-		      int fg, int bg)
+static void cw_cursor(struct vc_data *vc, struct fb_info *info, int mode,
+		      int softback_lines, int fg, int bg)
 {
 	struct fb_cursor cursor;
-	struct fbcon_ops *ops = (struct fbcon_ops *) info->fbcon_par;
+	struct fbcon_ops *ops = info->fbcon_par;
 	unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
 	int w = (vc->vc_font.height + 7) >> 3, c;
-	int y = real_y(p, vc->vc_y);
+	int y = real_y(ops->p, vc->vc_y);
 	int attribute, use_sw = (vc->vc_cursor_type & 0x10);
 	int err = 1, dx, dy;
 	char *src;
-	u32 vxres = GETVXRES(p->scrollmode, info);
+	u32 vxres = GETVXRES(ops->p->scrollmode, info);
 
 	if (!ops->fontbuffer)
 		return;
@@ -287,7 +286,7 @@
 	}
 
 	if (cursor.set & FB_CUR_SETSIZE ||
-	    vc->vc_cursor_type != p->cursor_shape ||
+	    vc->vc_cursor_type != ops->p->cursor_shape ||
 	    ops->cursor_state.mask == NULL ||
 	    ops->cursor_reset) {
 		char *tmp, *mask = kmalloc(w*vc->vc_font.width, GFP_ATOMIC);
@@ -307,10 +306,10 @@
 		kfree(ops->cursor_state.mask);
 		ops->cursor_state.mask = mask;
 
-		p->cursor_shape = vc->vc_cursor_type;
+		ops->p->cursor_shape = vc->vc_cursor_type;
 		cursor.set |= FB_CUR_SETSHAPE;
 
-		switch (p->cursor_shape & CUR_HWMASK) {
+		switch (ops->p->cursor_shape & CUR_HWMASK) {
 		case CUR_NONE:
 			cur_height = 0;
 			break;
diff --git a/drivers/video/console/fbcon_rotate.c b/drivers/video/console/fbcon_rotate.c
index ec0dd8f..2dc091f 100644
--- a/drivers/video/console/fbcon_rotate.c
+++ b/drivers/video/console/fbcon_rotate.c
@@ -18,8 +18,7 @@
 #include "fbcon.h"
 #include "fbcon_rotate.h"
 
-static int fbcon_rotate_font(struct fb_info *info, struct vc_data *vc,
-			     struct display *p)
+static int fbcon_rotate_font(struct fb_info *info, struct vc_data *vc)
 {
 	struct fbcon_ops *ops = info->fbcon_par;
 	int len, err = 0;
@@ -28,12 +27,12 @@
 	u8 *dst;
 
 	if (vc->vc_font.data == ops->fontdata &&
-	    p->con_rotate == ops->cur_rotate)
+	    ops->p->con_rotate == ops->cur_rotate)
 		goto finished;
 
 	src = ops->fontdata = vc->vc_font.data;
-	ops->cur_rotate = p->con_rotate;
-	len = (!p->userfont) ? 256 : FNTCHARCNT(src);
+	ops->cur_rotate = ops->p->con_rotate;
+	len = (!ops->p->userfont) ? 256 : FNTCHARCNT(src);
 	s_cellsize = ((vc->vc_font.width + 7)/8) *
 		vc->vc_font.height;
 	d_cellsize = s_cellsize;
diff --git a/drivers/video/console/fbcon_rotate.h b/drivers/video/console/fbcon_rotate.h
index 1b8f92f..75be5ce 100644
--- a/drivers/video/console/fbcon_rotate.h
+++ b/drivers/video/console/fbcon_rotate.h
@@ -11,8 +11,6 @@
 #ifndef _FBCON_ROTATE_H
 #define _FBCON_ROTATE_H
 
-#define FNTCHARCNT(fd)	(((int *)(fd))[-3])
-
 #define GETVYRES(s,i) ({                           \
         (s == SCROLL_REDRAW || s == SCROLL_MOVE) ? \
         (i)->var.yres : (i)->var.yres_virtual; })
diff --git a/drivers/video/console/fbcon_ud.c b/drivers/video/console/fbcon_ud.c
index 9dd059e..f56ed06 100644
--- a/drivers/video/console/fbcon_ud.c
+++ b/drivers/video/console/fbcon_ud.c
@@ -249,20 +249,19 @@
 	}
 }
 
-static void ud_cursor(struct vc_data *vc, struct fb_info *info,
-		      struct display *p, int mode, int softback_lines,
-		      int fg, int bg)
+static void ud_cursor(struct vc_data *vc, struct fb_info *info, int mode,
+		      int softback_lines, int fg, int bg)
 {
 	struct fb_cursor cursor;
-	struct fbcon_ops *ops = (struct fbcon_ops *) info->fbcon_par;
+	struct fbcon_ops *ops = info->fbcon_par;
 	unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
 	int w = (vc->vc_font.width + 7) >> 3, c;
-	int y = real_y(p, vc->vc_y);
+	int y = real_y(ops->p, vc->vc_y);
 	int attribute, use_sw = (vc->vc_cursor_type & 0x10);
 	int err = 1, dx, dy;
 	char *src;
-	u32 vyres = GETVYRES(p->scrollmode, info);
-	u32 vxres = GETVXRES(p->scrollmode, info);
+	u32 vyres = GETVYRES(ops->p->scrollmode, info);
+	u32 vxres = GETVXRES(ops->p->scrollmode, info);
 
 	if (!ops->fontbuffer)
 		return;
@@ -334,7 +333,7 @@
 	}
 
 	if (cursor.set & FB_CUR_SETSIZE ||
-	    vc->vc_cursor_type != p->cursor_shape ||
+	    vc->vc_cursor_type != ops->p->cursor_shape ||
 	    ops->cursor_state.mask == NULL ||
 	    ops->cursor_reset) {
 		char *mask = kmalloc(w*vc->vc_font.height, GFP_ATOMIC);
@@ -347,10 +346,10 @@
 		kfree(ops->cursor_state.mask);
 		ops->cursor_state.mask = mask;
 
-		p->cursor_shape = vc->vc_cursor_type;
+		ops->p->cursor_shape = vc->vc_cursor_type;
 		cursor.set |= FB_CUR_SETSHAPE;
 
-		switch (p->cursor_shape & CUR_HWMASK) {
+		switch (ops->p->cursor_shape & CUR_HWMASK) {
 		case CUR_NONE:
 			cur_height = 0;
 			break;
diff --git a/drivers/video/console/softcursor.c b/drivers/video/console/softcursor.c
index 8529bf0..3957fc7 100644
--- a/drivers/video/console/softcursor.c
+++ b/drivers/video/console/softcursor.c
@@ -17,6 +17,8 @@
 #include <asm/uaccess.h>
 #include <asm/io.h>
 
+#include "fbcon.h"
+
 int soft_cursor(struct fb_info *info, struct fb_cursor *cursor)
 {
 	unsigned int scan_align = info->pixmap.scan_align - 1;
diff --git a/drivers/video/console/tileblit.c b/drivers/video/console/tileblit.c
index cb25324..153352c 100644
--- a/drivers/video/console/tileblit.c
+++ b/drivers/video/console/tileblit.c
@@ -80,9 +80,8 @@
 	return;
 }
 
-static void tile_cursor(struct vc_data *vc, struct fb_info *info,
-			struct display *p, int mode, int softback_lines,
-			int fg, int bg)
+static void tile_cursor(struct vc_data *vc, struct fb_info *info, int mode,
+			int softback_lines, int fg, int bg)
 {
 	struct fb_tilecursor cursor;
 	int use_sw = (vc->vc_cursor_type & 0x01);
@@ -130,10 +129,10 @@
 	return err;
 }
 
-void fbcon_set_tileops(struct vc_data *vc, struct fb_info *info,
-		       struct display *p, struct fbcon_ops *ops)
+void fbcon_set_tileops(struct vc_data *vc, struct fb_info *info)
 {
 	struct fb_tilemap map;
+	struct fbcon_ops *ops = info->fbcon_par;
 
 	ops->bmove = tile_bmove;
 	ops->clear = tile_clear;
@@ -142,13 +141,13 @@
 	ops->cursor = tile_cursor;
 	ops->update_start = tile_update_start;
 
-	if (p) {
+	if (ops->p) {
 		map.width = vc->vc_font.width;
 		map.height = vc->vc_font.height;
 		map.depth = 1;
-		map.length = (p->userfont) ?
-			FNTCHARCNT(p->fontdata) : 256;
-		map.data = p->fontdata;
+		map.length = (ops->p->userfont) ?
+			FNTCHARCNT(ops->p->fontdata) : 256;
+		map.data = ops->p->fontdata;
 		info->tileops->fb_settile(info, &map);
 	}
 }
diff --git a/drivers/video/fbcvt.c b/drivers/video/fbcvt.c
index 0b6af00..ac90883 100644
--- a/drivers/video/fbcvt.c
+++ b/drivers/video/fbcvt.c
@@ -214,12 +214,11 @@
 {
 	u32 pixcount, pixcount_mod;
 	int cnt = 255, offset = 0, read = 0;
-	u8 *buf = kmalloc(256, GFP_KERNEL);
+	u8 *buf = kzalloc(256, GFP_KERNEL);
 
 	if (!buf)
 		return;
 
-	memset(buf, 0, 256);
 	pixcount = (cvt->xres * (cvt->yres/cvt->interlace))/1000000;
 	pixcount_mod = (cvt->xres * (cvt->yres/cvt->interlace)) % 1000000;
 	pixcount_mod /= 1000;
diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
index 10dfdf0..32a9b69 100644
--- a/drivers/video/fbmem.c
+++ b/drivers/video/fbmem.c
@@ -589,17 +589,19 @@
 		return info->fbops->fb_read(file, buf, count, ppos);
 	
 	total_size = info->screen_size;
+
 	if (total_size == 0)
 		total_size = info->fix.smem_len;
 
 	if (p >= total_size)
-	    return 0;
+		return 0;
+
 	if (count >= total_size)
-	    count = total_size;
+		count = total_size;
+
 	if (count + p > total_size)
 		count = total_size - p;
 
-	cnt = 0;
 	buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count,
 			 GFP_KERNEL);
 	if (!buffer)
@@ -636,6 +638,7 @@
 	}
 
 	kfree(buffer);
+
 	return (err) ? err : cnt;
 }
 
@@ -648,7 +651,7 @@
 	struct fb_info *info = registered_fb[fbidx];
 	u32 *buffer, *src;
 	u32 __iomem *dst;
-	int c, i, cnt = 0, err;
+	int c, i, cnt = 0, err = 0;
 	unsigned long total_size;
 
 	if (!info || !info->screen_base)
@@ -661,19 +664,19 @@
 		return info->fbops->fb_write(file, buf, count, ppos);
 	
 	total_size = info->screen_size;
+
 	if (total_size == 0)
 		total_size = info->fix.smem_len;
 
 	if (p > total_size)
-	    return -ENOSPC;
+		return 0;
+
 	if (count >= total_size)
-	    count = total_size;
-	err = 0;
-	if (count + p > total_size) {
-	    count = total_size - p;
-	    err = -ENOSPC;
-	}
-	cnt = 0;
+		count = total_size;
+
+	if (count + p > total_size)
+		count = total_size - p;
+
 	buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count,
 			 GFP_KERNEL);
 	if (!buffer)
@@ -687,12 +690,15 @@
 	while (count) {
 		c = (count > PAGE_SIZE) ? PAGE_SIZE : count;
 		src = buffer;
+
 		if (copy_from_user(src, buf, c)) {
 			err = -EFAULT;
 			break;
 		}
+
 		for (i = c >> 2; i--; )
 			fb_writel(*src++, dst++);
+
 		if (c & 3) {
 			u8 *src8 = (u8 *) src;
 			u8 __iomem *dst8 = (u8 __iomem *) dst;
@@ -702,11 +708,13 @@
 
 			dst = (u32 __iomem *) dst8;
 		}
+
 		*ppos += c;
 		buf += c;
 		cnt += c;
 		count -= c;
 	}
+
 	kfree(buffer);
 
 	return (err) ? err : cnt;
@@ -1226,6 +1234,7 @@
 		return -ENODEV;
 	if (!try_module_get(info->fbops->owner))
 		return -ENODEV;
+	file->private_data = info;
 	if (info->fbops->fb_open) {
 		res = info->fbops->fb_open(info,1);
 		if (res)
@@ -1237,11 +1246,9 @@
 static int 
 fb_release(struct inode *inode, struct file *file)
 {
-	int fbidx = iminor(inode);
-	struct fb_info *info;
+	struct fb_info * const info = file->private_data;
 
 	lock_kernel();
-	info = registered_fb[fbidx];
 	if (info->fbops->fb_release)
 		info->fbops->fb_release(info,1);
 	module_put(info->fbops->owner);
diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index fc7965b..7c74e73 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -317,26 +317,29 @@
 static void calc_mode_timings(int xres, int yres, int refresh,
 			      struct fb_videomode *mode)
 {
-	struct fb_var_screeninfo var;
-	struct fb_info info;
+	struct fb_var_screeninfo *var;
 	
-	memset(&var, 0, sizeof(struct fb_var_screeninfo));
-	var.xres = xres;
-	var.yres = yres;
-	fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 
-		    refresh, &var, &info);
-	mode->xres = xres;
-	mode->yres = yres;
-	mode->pixclock = var.pixclock;
-	mode->refresh = refresh;
-	mode->left_margin = var.left_margin;
-	mode->right_margin = var.right_margin;
-	mode->upper_margin = var.upper_margin;
-	mode->lower_margin = var.lower_margin;
-	mode->hsync_len = var.hsync_len;
-	mode->vsync_len = var.vsync_len;
-	mode->vmode = 0;
-	mode->sync = 0;
+	var = kzalloc(sizeof(struct fb_var_screeninfo), GFP_KERNEL);
+
+	if (var) {
+		var->xres = xres;
+		var->yres = yres;
+		fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON,
+			    refresh, var, NULL);
+		mode->xres = xres;
+		mode->yres = yres;
+		mode->pixclock = var->pixclock;
+		mode->refresh = refresh;
+		mode->left_margin = var->left_margin;
+		mode->right_margin = var->right_margin;
+		mode->upper_margin = var->upper_margin;
+		mode->lower_margin = var->lower_margin;
+		mode->hsync_len = var->hsync_len;
+		mode->vsync_len = var->vsync_len;
+		mode->vmode = 0;
+		mode->sync = 0;
+		kfree(var);
+	}
 }
 
 static int get_est_timing(unsigned char *block, struct fb_videomode *mode)
@@ -525,10 +528,9 @@
 	unsigned char *block;
 	int num = 0, i;
 
-	mode = kmalloc(50 * sizeof(struct fb_videomode), GFP_KERNEL);
+	mode = kzalloc(50 * sizeof(struct fb_videomode), GFP_KERNEL);
 	if (mode == NULL)
 		return NULL;
-	memset(mode, 0, 50 * sizeof(struct fb_videomode));
 
 	if (edid == NULL || !edid_checksum(edid) || 
 	    !edid_check_header(edid)) {
@@ -1105,15 +1107,21 @@
  */ 
 int fb_get_mode(int flags, u32 val, struct fb_var_screeninfo *var, struct fb_info *info)
 {
-	struct __fb_timings timings;
+	struct __fb_timings *timings;
 	u32 interlace = 1, dscan = 1;
-	u32 hfmin, hfmax, vfmin, vfmax, dclkmin, dclkmax;
+	u32 hfmin, hfmax, vfmin, vfmax, dclkmin, dclkmax, err = 0;
+
+
+	timings = kzalloc(sizeof(struct __fb_timings), GFP_KERNEL);
+
+	if (!timings)
+		return -ENOMEM;
 
 	/* 
 	 * If monspecs are invalid, use values that are enough
 	 * for 640x480@60
 	 */
-	if (!info->monspecs.hfmax || !info->monspecs.vfmax ||
+	if (!info || !info->monspecs.hfmax || !info->monspecs.vfmax ||
 	    !info->monspecs.dclkmax ||
 	    info->monspecs.hfmax < info->monspecs.hfmin ||
 	    info->monspecs.vfmax < info->monspecs.vfmin ||
@@ -1130,65 +1138,66 @@
 		dclkmax = info->monspecs.dclkmax;
 	}
 
-	memset(&timings, 0, sizeof(struct __fb_timings));
-	timings.hactive = var->xres;
-	timings.vactive = var->yres;
+	timings->hactive = var->xres;
+	timings->vactive = var->yres;
 	if (var->vmode & FB_VMODE_INTERLACED) { 
-		timings.vactive /= 2;
+		timings->vactive /= 2;
 		interlace = 2;
 	}
 	if (var->vmode & FB_VMODE_DOUBLE) {
-		timings.vactive *= 2;
+		timings->vactive *= 2;
 		dscan = 2;
 	}
 
 	switch (flags & ~FB_IGNOREMON) {
 	case FB_MAXTIMINGS: /* maximize refresh rate */
-		timings.hfreq = hfmax;
-		fb_timings_hfreq(&timings);
-		if (timings.vfreq > vfmax) {
-			timings.vfreq = vfmax;
-			fb_timings_vfreq(&timings);
+		timings->hfreq = hfmax;
+		fb_timings_hfreq(timings);
+		if (timings->vfreq > vfmax) {
+			timings->vfreq = vfmax;
+			fb_timings_vfreq(timings);
 		}
-		if (timings.dclk > dclkmax) {
-			timings.dclk = dclkmax;
-			fb_timings_dclk(&timings);
+		if (timings->dclk > dclkmax) {
+			timings->dclk = dclkmax;
+			fb_timings_dclk(timings);
 		}
 		break;
 	case FB_VSYNCTIMINGS: /* vrefresh driven */
-		timings.vfreq = val;
-		fb_timings_vfreq(&timings);
+		timings->vfreq = val;
+		fb_timings_vfreq(timings);
 		break;
 	case FB_HSYNCTIMINGS: /* hsync driven */
-		timings.hfreq = val;
-		fb_timings_hfreq(&timings);
+		timings->hfreq = val;
+		fb_timings_hfreq(timings);
 		break;
 	case FB_DCLKTIMINGS: /* pixelclock driven */
-		timings.dclk = PICOS2KHZ(val) * 1000;
-		fb_timings_dclk(&timings);
+		timings->dclk = PICOS2KHZ(val) * 1000;
+		fb_timings_dclk(timings);
 		break;
 	default:
-		return -EINVAL;
+		err = -EINVAL;
 		
 	} 
 	
-	if (!(flags & FB_IGNOREMON) && 
-	    (timings.vfreq < vfmin || timings.vfreq > vfmax || 
-	     timings.hfreq < hfmin || timings.hfreq > hfmax ||
-	     timings.dclk < dclkmin || timings.dclk > dclkmax))
-		return -EINVAL;
-
-	var->pixclock = KHZ2PICOS(timings.dclk/1000);
-	var->hsync_len = (timings.htotal * 8)/100;
-	var->right_margin = (timings.hblank/2) - var->hsync_len;
-	var->left_margin = timings.hblank - var->right_margin - var->hsync_len;
+	if (err || (!(flags & FB_IGNOREMON) &&
+	    (timings->vfreq < vfmin || timings->vfreq > vfmax ||
+	     timings->hfreq < hfmin || timings->hfreq > hfmax ||
+	     timings->dclk < dclkmin || timings->dclk > dclkmax))) {
+		err = -EINVAL;
+	} else {
+		var->pixclock = KHZ2PICOS(timings->dclk/1000);
+		var->hsync_len = (timings->htotal * 8)/100;
+		var->right_margin = (timings->hblank/2) - var->hsync_len;
+		var->left_margin = timings->hblank - var->right_margin -
+			var->hsync_len;
+		var->vsync_len = (3 * interlace)/dscan;
+		var->lower_margin = (1 * interlace)/dscan;
+		var->upper_margin = (timings->vblank * interlace)/dscan -
+			(var->vsync_len + var->lower_margin);
+	}
 	
-	var->vsync_len = (3 * interlace)/dscan;
-	var->lower_margin = (1 * interlace)/dscan;
-	var->upper_margin = (timings.vblank * interlace)/dscan - 
-		(var->vsync_len + var->lower_margin);
-	
-	return 0;
+	kfree(timings);
+	return err;
 }
 #else
 int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
diff --git a/drivers/video/fbsysfs.c b/drivers/video/fbsysfs.c
index 08dac95..6d26057 100644
--- a/drivers/video/fbsysfs.c
+++ b/drivers/video/fbsysfs.c
@@ -43,10 +43,11 @@
 	if (size)
 		fb_info_size += PADDING;
 
-	p = kmalloc(fb_info_size + size, GFP_KERNEL);
+	p = kzalloc(fb_info_size + size, GFP_KERNEL);
+
 	if (!p)
 		return NULL;
-	memset(p, 0, fb_info_size + size);
+
 	info = (struct fb_info *) p;
 
 	if (size)
@@ -106,8 +107,7 @@
 static ssize_t store_mode(struct class_device *class_device, const char * buf,
 			  size_t count)
 {
-	struct fb_info *fb_info =
-		(struct fb_info *)class_get_devdata(class_device);
+	struct fb_info *fb_info = class_get_devdata(class_device);
 	char mstr[100];
 	struct fb_var_screeninfo var;
 	struct fb_modelist *modelist;
@@ -137,8 +137,7 @@
 
 static ssize_t show_mode(struct class_device *class_device, char *buf)
 {
-	struct fb_info *fb_info =
-		(struct fb_info *)class_get_devdata(class_device);
+	struct fb_info *fb_info = class_get_devdata(class_device);
 
 	if (!fb_info->mode)
 		return 0;
@@ -149,8 +148,7 @@
 static ssize_t store_modes(struct class_device *class_device, const char * buf,
 			   size_t count)
 {
-	struct fb_info *fb_info =
-		(struct fb_info *)class_get_devdata(class_device);
+	struct fb_info *fb_info = class_get_devdata(class_device);
 	LIST_HEAD(old_list);
 	int i = count / sizeof(struct fb_videomode);
 
@@ -174,8 +172,7 @@
 
 static ssize_t show_modes(struct class_device *class_device, char *buf)
 {
-	struct fb_info *fb_info =
-		(struct fb_info *)class_get_devdata(class_device);
+	struct fb_info *fb_info = class_get_devdata(class_device);
 	unsigned int i;
 	struct list_head *pos;
 	struct fb_modelist *modelist;
@@ -193,8 +190,7 @@
 static ssize_t store_bpp(struct class_device *class_device, const char * buf,
 			 size_t count)
 {
-	struct fb_info *fb_info =
-		(struct fb_info *)class_get_devdata(class_device);
+	struct fb_info *fb_info = class_get_devdata(class_device);
 	struct fb_var_screeninfo var;
 	char ** last = NULL;
 	int err;
@@ -208,8 +204,7 @@
 
 static ssize_t show_bpp(struct class_device *class_device, char *buf)
 {
-	struct fb_info *fb_info =
-		(struct fb_info *)class_get_devdata(class_device);
+	struct fb_info *fb_info = class_get_devdata(class_device);
 	return snprintf(buf, PAGE_SIZE, "%d\n", fb_info->var.bits_per_pixel);
 }
 
@@ -280,8 +275,7 @@
 static ssize_t store_virtual(struct class_device *class_device,
 			     const char * buf, size_t count)
 {
-	struct fb_info *fb_info =
-		(struct fb_info *)class_get_devdata(class_device);
+	struct fb_info *fb_info = class_get_devdata(class_device);
 	struct fb_var_screeninfo var;
 	char *last = NULL;
 	int err;
@@ -300,16 +294,14 @@
 
 static ssize_t show_virtual(struct class_device *class_device, char *buf)
 {
-	struct fb_info *fb_info =
-		(struct fb_info *)class_get_devdata(class_device);
+	struct fb_info *fb_info = class_get_devdata(class_device);
 	return snprintf(buf, PAGE_SIZE, "%d,%d\n", fb_info->var.xres_virtual,
 			fb_info->var.yres_virtual);
 }
 
 static ssize_t show_stride(struct class_device *class_device, char *buf)
 {
-	struct fb_info *fb_info =
-		(struct fb_info *)class_get_devdata(class_device);
+	struct fb_info *fb_info = class_get_devdata(class_device);
 	return snprintf(buf, PAGE_SIZE, "%d\n", fb_info->fix.line_length);
 }
 
@@ -320,7 +312,7 @@
 static ssize_t store_cmap(struct class_device *class_device, const char *buf,
 			  size_t count)
 {
-	struct fb_info *fb_info = (struct fb_info *)class_get_devdata(class_device);
+	struct fb_info *fb_info = class_get_devdata(class_device);
 	int rc, i, start, length, transp = 0;
 
 	if ((count > PAGE_SIZE) || ((count % 16) != 0))
@@ -380,8 +372,7 @@
 
 static ssize_t show_cmap(struct class_device *class_device, char *buf)
 {
-	struct fb_info *fb_info =
-		(struct fb_info *)class_get_devdata(class_device);
+	struct fb_info *fb_info = class_get_devdata(class_device);
 	unsigned int i;
 
 	if (!fb_info->cmap.red || !fb_info->cmap.blue ||
@@ -405,8 +396,7 @@
 static ssize_t store_blank(struct class_device *class_device, const char * buf,
 			   size_t count)
 {
-	struct fb_info *fb_info =
-		(struct fb_info *)class_get_devdata(class_device);
+	struct fb_info *fb_info = class_get_devdata(class_device);
 	char *last = NULL;
 	int err;
 
@@ -422,41 +412,40 @@
 
 static ssize_t show_blank(struct class_device *class_device, char *buf)
 {
-//	struct fb_info *fb_info = (struct fb_info *)class_get_devdata(class_device);
+//	struct fb_info *fb_info = class_get_devdata(class_device);
 	return 0;
 }
 
 static ssize_t store_console(struct class_device *class_device,
 			     const char * buf, size_t count)
 {
-//	struct fb_info *fb_info = (struct fb_info *)class_get_devdata(class_device);
+//	struct fb_info *fb_info = class_get_devdata(class_device);
 	return 0;
 }
 
 static ssize_t show_console(struct class_device *class_device, char *buf)
 {
-//	struct fb_info *fb_info = (struct fb_info *)class_get_devdata(class_device);
+//	struct fb_info *fb_info = class_get_devdata(class_device);
 	return 0;
 }
 
 static ssize_t store_cursor(struct class_device *class_device,
 			    const char * buf, size_t count)
 {
-//	struct fb_info *fb_info = (struct fb_info *)class_get_devdata(class_device);
+//	struct fb_info *fb_info = class_get_devdata(class_device);
 	return 0;
 }
 
 static ssize_t show_cursor(struct class_device *class_device, char *buf)
 {
-//	struct fb_info *fb_info = (struct fb_info *)class_get_devdata(class_device);
+//	struct fb_info *fb_info = class_get_devdata(class_device);
 	return 0;
 }
 
 static ssize_t store_pan(struct class_device *class_device, const char * buf,
 			 size_t count)
 {
-	struct fb_info *fb_info =
-		(struct fb_info *)class_get_devdata(class_device);
+	struct fb_info *fb_info = class_get_devdata(class_device);
 	struct fb_var_screeninfo var;
 	char *last = NULL;
 	int err;
@@ -479,19 +468,40 @@
 
 static ssize_t show_pan(struct class_device *class_device, char *buf)
 {
-	struct fb_info *fb_info =
-		(struct fb_info *)class_get_devdata(class_device);
+	struct fb_info *fb_info = class_get_devdata(class_device);
 	return snprintf(buf, PAGE_SIZE, "%d,%d\n", fb_info->var.xoffset,
 			fb_info->var.xoffset);
 }
 
 static ssize_t show_name(struct class_device *class_device, char *buf)
 {
-	struct fb_info *fb_info = (struct fb_info *)class_get_devdata(class_device);
+	struct fb_info *fb_info = class_get_devdata(class_device);
 
 	return snprintf(buf, PAGE_SIZE, "%s\n", fb_info->fix.id);
 }
 
+static ssize_t store_fbstate(struct class_device *class_device,
+			const char *buf, size_t count)
+{
+	struct fb_info *fb_info = class_get_devdata(class_device);
+	u32 state;
+	char *last = NULL;
+
+	state = simple_strtoul(buf, &last, 0);
+
+	acquire_console_sem();
+	fb_set_suspend(fb_info, (int)state);
+	release_console_sem();
+
+	return count;
+}
+
+static ssize_t show_fbstate(struct class_device *class_device, char *buf)
+{
+	struct fb_info *fb_info = class_get_devdata(class_device);
+	return snprintf(buf, PAGE_SIZE, "%d\n", fb_info->state);
+}
+
 static struct class_device_attribute class_device_attrs[] = {
 	__ATTR(bits_per_pixel, S_IRUGO|S_IWUSR, show_bpp, store_bpp),
 	__ATTR(blank, S_IRUGO|S_IWUSR, show_blank, store_blank),
@@ -507,6 +517,7 @@
 	__ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
 	__ATTR(con_rotate, S_IRUGO|S_IWUSR, show_con_rotate, store_con_rotate),
 	__ATTR(con_rotate_all, S_IWUSR, NULL, store_con_rotate_all),
+	__ATTR(state, S_IRUGO|S_IWUSR, show_fbstate, store_fbstate),
 };
 
 int fb_init_class_device(struct fb_info *fb_info)
diff --git a/drivers/video/hgafb.c b/drivers/video/hgafb.c
index b37cea7..4e39035 100644
--- a/drivers/video/hgafb.c
+++ b/drivers/video/hgafb.c
@@ -42,6 +42,7 @@
 #include <linux/fb.h>
 #include <linux/init.h>
 #include <linux/ioport.h>
+#include <linux/platform_device.h>
 #include <asm/io.h>
 #include <asm/vga.h>
 
@@ -107,7 +108,7 @@
 
 /* Framebuffer driver structures */
 
-static struct fb_var_screeninfo hga_default_var = {
+static struct fb_var_screeninfo __initdata hga_default_var = {
 	.xres		= 720,
 	.yres 		= 348,
 	.xres_virtual 	= 720,
@@ -121,7 +122,7 @@
 	.width 		= -1,
 };
 
-static struct fb_fix_screeninfo hga_fix = {
+static struct fb_fix_screeninfo __initdata hga_fix = {
 	.id 		= "HGA",
 	.type 		= FB_TYPE_PACKED_PIXELS,	/* (not sure) */
 	.visual 	= FB_VISUAL_MONO10,
@@ -131,8 +132,6 @@
 	.accel 		= FB_ACCEL_NONE
 };
 
-static struct fb_info fb_info;
-
 /* Don't assume that tty1 will be the initial current console. */
 static int release_io_port = 0;
 static int release_io_ports = 0;
@@ -549,10 +548,9 @@
 	 *  Initialization
 	 */
 
-static int __init hgafb_init(void)
+static int __init hgafb_probe(struct device *device)
 {
-	if (fb_get_options("hgafb", NULL))
-		return -ENODEV;
+	struct fb_info *info;
 
 	if (! hga_card_detect()) {
 		printk(KERN_INFO "hgafb: HGA card not detected.\n");
@@ -564,41 +562,95 @@
 	printk(KERN_INFO "hgafb: %s with %ldK of memory detected.\n",
 		hga_type_name, hga_vram_len/1024);
 
+	info = framebuffer_alloc(0, NULL);
+	if (!info) {
+		iounmap(hga_vram);
+		return -ENOMEM;
+	}
+
 	hga_fix.smem_start = (unsigned long)hga_vram;
 	hga_fix.smem_len = hga_vram_len;
 
-	fb_info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
-	fb_info.var = hga_default_var;
-	fb_info.fix = hga_fix;
-	fb_info.monspecs.hfmin = 0;
-	fb_info.monspecs.hfmax = 0;
-	fb_info.monspecs.vfmin = 10000;
-	fb_info.monspecs.vfmax = 10000;
-	fb_info.monspecs.dpms = 0;
-	fb_info.fbops = &hgafb_ops;
-	fb_info.screen_base = hga_vram;
+	info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
+	info->var = hga_default_var;
+	info->fix = hga_fix;
+	info->monspecs.hfmin = 0;
+	info->monspecs.hfmax = 0;
+	info->monspecs.vfmin = 10000;
+	info->monspecs.vfmax = 10000;
+	info->monspecs.dpms = 0;
+	info->fbops = &hgafb_ops;
+	info->screen_base = hga_vram;
 
-        if (register_framebuffer(&fb_info) < 0) {
+        if (register_framebuffer(info) < 0) {
+		framebuffer_release(info);
 		iounmap(hga_vram);
 		return -EINVAL;
 	}
 
         printk(KERN_INFO "fb%d: %s frame buffer device\n",
-               fb_info.node, fb_info.fix.id);
+               info->node, info->fix.id);
+	dev_set_drvdata(device, info);
 	return 0;
 }
 
-#ifdef MODULE
-static void __exit hgafb_exit(void)
+static int hgafb_remove(struct device *device)
 {
+	struct fb_info *info = dev_get_drvdata(device);
+
 	hga_txt_mode();
 	hga_clear_screen();
-	unregister_framebuffer(&fb_info);
+
+	if (info) {
+		unregister_framebuffer(info);
+		framebuffer_release(info);
+	}
+
 	iounmap(hga_vram);
-	if (release_io_ports) release_region(0x3b0, 12);
-	if (release_io_port) release_region(0x3bf, 1);
+
+	if (release_io_ports)
+		release_region(0x3b0, 12);
+
+	if (release_io_port)
+		release_region(0x3bf, 1);
+
+	return 0;
 }
-#endif
+
+static struct device_driver hgafb_driver = {
+	.name = "hgafb",
+	.bus  = &platform_bus_type,
+	.probe = hgafb_probe,
+	.remove = hgafb_remove,
+};
+
+static struct platform_device hgafb_device = {
+	.name = "hgafb",
+};
+
+static int __init hgafb_init(void)
+{
+	int ret;
+
+	if (fb_get_options("hgafb", NULL))
+		return -ENODEV;
+
+	ret = driver_register(&hgafb_driver);
+
+	if (!ret) {
+		ret = platform_device_register(&hgafb_device);
+		if (ret)
+			driver_unregister(&hgafb_driver);
+	}
+
+	return ret;
+}
+
+static void __exit hgafb_exit(void)
+{
+	platform_device_unregister(&hgafb_device);
+	driver_unregister(&hgafb_driver);
+}
 
 /* -------------------------------------------------------------------------
  *
@@ -613,7 +665,4 @@
 module_param(nologo, bool, 0);
 MODULE_PARM_DESC(nologo, "Disables startup logo if != 0 (default=0)");
 module_init(hgafb_init);
-
-#ifdef MODULE
 module_exit(hgafb_exit);
-#endif
diff --git a/drivers/video/i810/i810-i2c.c b/drivers/video/i810/i810-i2c.c
index c61bad0..bd410e0 100644
--- a/drivers/video/i810/i810-i2c.c
+++ b/drivers/video/i810/i810-i2c.c
@@ -17,6 +17,7 @@
 #include <linux/fb.h>
 #include "i810.h"
 #include "i810_regs.h"
+#include "i810_main.h"
 #include "../edid.h"
 
 #define I810_DDC 0x50
@@ -42,7 +43,7 @@
 
 static void i810i2c_setscl(void *data, int state)
 {
-        struct i810fb_i2c_chan    *chan = (struct i810fb_i2c_chan *)data;
+        struct i810fb_i2c_chan    *chan = data;
         struct i810fb_par         *par = chan->par;
 	u8                        __iomem *mmio = par->mmio_start_virtual;
 
diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
index 64cd1c8..76764ea 100644
--- a/drivers/video/i810/i810_accel.c
+++ b/drivers/video/i810/i810_accel.c
@@ -14,6 +14,7 @@
 
 #include "i810_regs.h"
 #include "i810.h"
+#include "i810_main.h"
 
 static u32 i810fb_rop[] = {
 	COLOR_COPY_ROP, /* ROP_COPY */
@@ -57,7 +58,7 @@
  */	
 static inline int wait_for_space(struct fb_info *info, u32 space)
 {
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 	u32 head, count = WAIT_COUNT, tail;
 	u8 __iomem *mmio = par->mmio_start_virtual;
 
@@ -88,7 +89,7 @@
  */
 static inline int wait_for_engine_idle(struct fb_info *info)
 {
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 	u8 __iomem *mmio = par->mmio_start_virtual;
 	int count = WAIT_COUNT;
 
@@ -116,7 +117,7 @@
  */ 
 static inline u32 begin_iring(struct fb_info *info, u32 space)
 {
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 
 	if (par->dev_flags & ALWAYS_SYNC) 
 		wait_for_engine_idle(info);
@@ -161,7 +162,7 @@
 				    int xdir, int src, int dest, int rop, 
 				    int blit_bpp, struct fb_info *info)
 {
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 
 	if (begin_iring(info, 24 + IRING_PAD)) return;
 
@@ -195,7 +196,7 @@
 			      int rop, int what, int blit_bpp, 
 			      struct fb_info *info)
 {
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 
 	if (begin_iring(info, 24 + IRING_PAD)) return;
 
@@ -236,7 +237,7 @@
 					  int dest, const u32 *src, int bg,
 					  int fg, struct fb_info *info)
 {
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 
 	if (begin_iring(info, 24 + (dsize << 2) + IRING_PAD)) return;
 
@@ -254,7 +255,7 @@
 
 static inline void load_front(int offset, struct fb_info *info)
 {
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 
 	if (begin_iring(info, 8 + IRING_PAD)) return;
 
@@ -296,7 +297,7 @@
 
 void i810fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
 {
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 	u32 dx, dy, width, height, dest, rop = 0, color = 0;
 
 	if (!info->var.accel_flags || par->dev_flags & LOCKUP ||
@@ -322,7 +323,7 @@
 	
 void i810fb_copyarea(struct fb_info *info, const struct fb_copyarea *region) 
 {
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 	u32 sx, sy, dx, dy, pitch, width, height, src, dest, xdir;
 
 	if (!info->var.accel_flags || par->dev_flags & LOCKUP ||
@@ -361,7 +362,7 @@
 
 void i810fb_imageblit(struct fb_info *info, const struct fb_image *image)
 {
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 	u32 fg = 0, bg = 0, size, dst;
 	
 	if (!info->var.accel_flags || par->dev_flags & LOCKUP ||
@@ -397,7 +398,7 @@
 
 int i810fb_sync(struct fb_info *info)
 {
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 	
 	if (!info->var.accel_flags || par->dev_flags & LOCKUP)
 		return 0;
@@ -407,7 +408,7 @@
 
 void i810fb_load_front(u32 offset, struct fb_info *info)
 {
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 	u8 __iomem *mmio = par->mmio_start_virtual;
 
 	if (!info->var.accel_flags || par->dev_flags & LOCKUP)
@@ -427,7 +428,7 @@
  */
 void i810fb_init_ringbuffer(struct fb_info *info)
 {
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 	u32 tmp1, tmp2;
 	u8 __iomem *mmio = par->mmio_start_virtual;
 	
diff --git a/drivers/video/i810/i810_gtf.c b/drivers/video/i810/i810_gtf.c
index 64f087a..9743d51 100644
--- a/drivers/video/i810/i810_gtf.c
+++ b/drivers/video/i810/i810_gtf.c
@@ -14,6 +14,7 @@
 
 #include "i810_regs.h"
 #include "i810.h"
+#include "i810_main.h"
 
 /*
  * FIFO and Watermark tables - based almost wholly on i810_wmark.c in 
diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
index c0c974b..266d0ab 100644
--- a/drivers/video/i810/i810_main.c
+++ b/drivers/video/i810/i810_main.c
@@ -42,20 +42,62 @@
 #include <linux/pci_ids.h>
 #include <linux/resource.h>
 #include <linux/unistd.h>
+#include <linux/console.h>
 
 #include <asm/io.h>
 #include <asm/div64.h>
-
-#ifdef CONFIG_MTRR
-#include <asm/mtrr.h>
-#endif 
-
 #include <asm/page.h>
 
 #include "i810_regs.h"
 #include "i810.h"
 #include "i810_main.h"
 
+/*
+ * voffset - framebuffer offset in MiB from aperture start address.  In order for
+ * the driver to work with X, we must try to use memory holes left untouched by X. The
+ * following table lists where X's different surfaces start at.
+ *
+ * ---------------------------------------------
+ * :                :  64 MiB     : 32 MiB      :
+ * ----------------------------------------------
+ * : FrontBuffer    :   0         :  0          :
+ * : DepthBuffer    :   48        :  16         :
+ * : BackBuffer     :   56        :  24         :
+ * ----------------------------------------------
+ *
+ * So for chipsets with 64 MiB Aperture sizes, 32 MiB for v_offset is okay, allowing up to
+ * 15 + 1 MiB of Framebuffer memory.  For 32 MiB Aperture sizes, a v_offset of 8 MiB should
+ * work, allowing 7 + 1 MiB of Framebuffer memory.
+ * Note, the size of the hole may change depending on how much memory you allocate to X,
+ * and how the memory is split up between these surfaces.
+ *
+ * Note: Anytime the DepthBuffer or FrontBuffer is overlapped, X would still run but with
+ * DRI disabled.  But if the Frontbuffer is overlapped, X will fail to load.
+ *
+ * Experiment with v_offset to find out which works best for you.
+ */
+static u32 v_offset_default __initdata; /* For 32 MiB Aper size, 8 should be the default */
+static u32 voffset          __initdata = 0;
+
+static int i810fb_cursor(struct fb_info *info, struct fb_cursor *cursor);
+static int  __devinit i810fb_init_pci (struct pci_dev *dev,
+				       const struct pci_device_id *entry);
+static void __exit i810fb_remove_pci(struct pci_dev *dev);
+static int i810fb_resume(struct pci_dev *dev);
+static int i810fb_suspend(struct pci_dev *dev, pm_message_t state);
+
+/* Chipset Specific Functions */
+static int i810fb_set_par    (struct fb_info *info);
+static int i810fb_getcolreg  (u8 regno, u8 *red, u8 *green, u8 *blue,
+			      u8 *transp, struct fb_info *info);
+static int i810fb_setcolreg  (unsigned regno, unsigned red, unsigned green, unsigned blue,
+			      unsigned transp, struct fb_info *info);
+static int i810fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info);
+static int i810fb_blank      (int blank_mode, struct fb_info *info);
+
+/* Initialization */
+static void i810fb_release_resource       (struct fb_info *info, struct i810fb_par *par);
+
 /* PCI */
 static const char *i810_pci_list[] __devinitdata = {
 	"Intel(R) 810 Framebuffer Device"                                 ,
@@ -776,7 +818,7 @@
 
 static void i810_load_cursor_colors(int fg, int bg, struct fb_info *info)
 {
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 	u8 __iomem *mmio = par->mmio_start_virtual;
 	u8 red, green, blue, trans, temp;
 
@@ -949,7 +991,7 @@
 static int i810_check_params(struct fb_var_screeninfo *var, 
 			     struct fb_info *info)
 {
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 	int line_length, vidmem, mode_valid = 0, retval = 0;
 	u32 vyres = var->yres_virtual, vxres = var->xres_virtual;
 	/*
@@ -1043,7 +1085,7 @@
  */
 static int encode_fix(struct fb_fix_screeninfo *fix, struct fb_info *info)
 {
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 
     	memset(fix, 0, sizeof(struct fb_fix_screeninfo));
 
@@ -1154,7 +1196,7 @@
 static int i810fb_getcolreg(u8 regno, u8 *red, u8 *green, u8 *blue, 
 			    u8 *transp, struct fb_info *info)
 {
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 	u8 __iomem *mmio = par->mmio_start_virtual;
 	u8 temp;
 
@@ -1193,7 +1235,7 @@
 
 static int i810fb_open(struct fb_info *info, int user)
 {
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 	u32 count = atomic_read(&par->use_count);
 	
 	if (count == 0) {
@@ -1212,7 +1254,7 @@
 
 static int i810fb_release(struct fb_info *info, int user)
 {
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 	u32 count;
 	
 	count = atomic_read(&par->use_count);
@@ -1234,7 +1276,7 @@
 			    unsigned blue, unsigned transp, 
 			    struct fb_info *info)
 {
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 	u8 __iomem *mmio = par->mmio_start_virtual;
 	u8 temp;
 	int i;
@@ -1328,7 +1370,7 @@
 static int i810fb_pan_display(struct fb_var_screeninfo *var, 
 			      struct fb_info *info)
 {
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 	u32 total;
 	
 	total = var->xoffset * par->depth + 
@@ -1340,7 +1382,7 @@
 
 static int i810fb_blank (int blank_mode, struct fb_info *info)
 {
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 	u8 __iomem *mmio = par->mmio_start_virtual;
 	int mode = 0, pwr, scr_off = 0;
 	
@@ -1385,7 +1427,7 @@
 
 static int i810fb_set_par(struct fb_info *info)
 {
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 
 	decode_var(&info->var, par);
 	i810_load_regs(par);
@@ -1429,7 +1471,7 @@
 
 static int i810fb_cursor(struct fb_info *info, struct fb_cursor *cursor)
 {
-	struct i810fb_par *par = (struct i810fb_par *)info->par;
+	struct i810fb_par *par = info->par;
 	u8 __iomem *mmio = par->mmio_start_virtual;
 
 	if (!par->dev_flags & LOCKUP)
@@ -1516,36 +1558,29 @@
 static int i810fb_suspend(struct pci_dev *dev, pm_message_t state)
 {
 	struct fb_info *info = pci_get_drvdata(dev);
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
-	int blank = 0, prev_state = par->cur_state;
-
-	if (state.event == prev_state)
-		return 0;
+	struct i810fb_par *par = info->par;
 
 	par->cur_state = state.event;
 
-	switch (state.event) {
-	case 1:
-		blank = VESA_VSYNC_SUSPEND;
-		break;
-	case 2:
-		blank = VESA_HSYNC_SUSPEND;
-		break;
-	case 3:
-		blank = VESA_POWERDOWN;
-		break;
-	default:
-		return -EINVAL;
+	if (state.event == PM_EVENT_FREEZE) {
+		dev->dev.power.power_state = state;
+		return 0;
 	}
-	info->fbops->fb_blank(blank, info);
 
-	if (!prev_state) { 
-		agp_unbind_memory(par->i810_gtt.i810_fb_memory);
-		agp_unbind_memory(par->i810_gtt.i810_cursor_memory);
-		pci_disable_device(dev);
-	}
+	acquire_console_sem();
+	fb_set_suspend(info, 1);
+
+	if (info->fbops->fb_sync)
+		info->fbops->fb_sync(info);
+
+	i810fb_blank(FB_BLANK_POWERDOWN, info);
+	agp_unbind_memory(par->i810_gtt.i810_fb_memory);
+	agp_unbind_memory(par->i810_gtt.i810_cursor_memory);
+
 	pci_save_state(dev);
+	pci_disable_device(dev);
 	pci_set_power_state(dev, pci_choose_state(dev, state));
+	release_console_sem();
 
 	return 0;
 }
@@ -1553,23 +1588,29 @@
 static int i810fb_resume(struct pci_dev *dev) 
 {
 	struct fb_info *info = pci_get_drvdata(dev);
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
+	int cur_state = par->cur_state;
 
-	if (par->cur_state == 0)
+	par->cur_state = PM_EVENT_ON;
+
+	if (cur_state == PM_EVENT_FREEZE) {
+		pci_set_power_state(dev, PCI_D0);
 		return 0;
+	}
 
-	pci_restore_state(dev);
+	acquire_console_sem();
 	pci_set_power_state(dev, PCI_D0);
+	pci_restore_state(dev);
 	pci_enable_device(dev);
+	pci_set_master(dev);
 	agp_bind_memory(par->i810_gtt.i810_fb_memory,
 			par->fb.offset);
 	agp_bind_memory(par->i810_gtt.i810_cursor_memory,
 			par->cursor_heap.offset);
-
+	i810fb_set_par(info);
+	fb_set_suspend (info, 0);
 	info->fbops->fb_blank(VESA_NO_BLANKING, info);
-
-	par->cur_state = 0;
-
+	release_console_sem();
 	return 0;
 }
 /***********************************************************************
@@ -1610,7 +1651,7 @@
 
 static int __devinit i810_alloc_agp_mem(struct fb_info *info)
 {
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 	int size;
 	struct agp_bridge_data *bridge;
 	
@@ -2074,7 +2115,7 @@
 static void __exit i810fb_remove_pci(struct pci_dev *dev)
 {
 	struct fb_info *info = pci_get_drvdata(dev);
-	struct i810fb_par *par = (struct i810fb_par *) info->par;
+	struct i810fb_par *par = info->par;
 
 	unregister_framebuffer(info);  
 	i810fb_release_resource(info, par);
diff --git a/drivers/video/i810/i810_main.h b/drivers/video/i810/i810_main.h
index 06072a6..51d4f3d 100644
--- a/drivers/video/i810/i810_main.h
+++ b/drivers/video/i810/i810_main.h
@@ -14,55 +14,6 @@
 #ifndef __I810_MAIN_H__
 #define __I810_MAIN_H__
 
-static int  __devinit i810fb_init_pci (struct pci_dev *dev, 
-				       const struct pci_device_id *entry);
-static void __exit i810fb_remove_pci(struct pci_dev *dev);
-static int i810fb_resume(struct pci_dev *dev);
-static int i810fb_suspend(struct pci_dev *dev, pm_message_t state);
-
-/*
- * voffset - framebuffer offset in MiB from aperture start address.  In order for
- * the driver to work with X, we must try to use memory holes left untouched by X. The 
- * following table lists where X's different surfaces start at.  
- * 
- * ---------------------------------------------
- * :                :  64 MiB     : 32 MiB      :
- * ----------------------------------------------
- * : FrontBuffer    :   0         :  0          :
- * : DepthBuffer    :   48        :  16         :
- * : BackBuffer     :   56        :  24         :
- * ----------------------------------------------
- *
- * So for chipsets with 64 MiB Aperture sizes, 32 MiB for v_offset is okay, allowing up to
- * 15 + 1 MiB of Framebuffer memory.  For 32 MiB Aperture sizes, a v_offset of 8 MiB should
- * work, allowing 7 + 1 MiB of Framebuffer memory.
- * Note, the size of the hole may change depending on how much memory you allocate to X,
- * and how the memory is split up between these surfaces.  
- *
- * Note: Anytime the DepthBuffer or FrontBuffer is overlapped, X would still run but with
- * DRI disabled.  But if the Frontbuffer is overlapped, X will fail to load.
- * 
- * Experiment with v_offset to find out which works best for you.
- */
-static u32 v_offset_default __initdata; /* For 32 MiB Aper size, 8 should be the default */
-static u32 voffset          __initdata = 0;
-
-static int i810fb_cursor(struct fb_info *info, struct fb_cursor *cursor);
-
-/* Chipset Specific Functions */
-static int i810fb_set_par    (struct fb_info *info);
-static int i810fb_getcolreg  (u8 regno, u8 *red, u8 *green, u8 *blue,
-			      u8 *transp, struct fb_info *info);
-static int i810fb_setcolreg  (unsigned regno, unsigned red, unsigned green, unsigned blue,
-			      unsigned transp, struct fb_info *info);
-static int i810fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info);
-static int i810fb_blank      (int blank_mode, struct fb_info *info);
-
-/* Initialization */
-static void i810fb_release_resource       (struct fb_info *info, struct i810fb_par *par);
-extern int __init agp_intel_init(void);
-
-
 /* Video Timings */
 extern void round_off_xres         (u32 *xres);
 extern void round_off_yres         (u32 *xres, u32 *yres);
@@ -101,7 +52,7 @@
 
 /* Conditionals */
 #ifdef CONFIG_X86
-inline void flush_cache(void)
+static inline void flush_cache(void)
 {
 	asm volatile ("wbinvd":::"memory");
 }
@@ -110,7 +61,9 @@
 #endif 
 
 #ifdef CONFIG_MTRR
-#define KERNEL_HAS_MTRR 1
+
+#include <asm/mtrr.h>
+
 static inline void __devinit set_mtrr(struct i810fb_par *par)
 {
 	par->mtrr_reg = mtrr_add((u32) par->aperture.physical, 
@@ -128,7 +81,6 @@
 			 par->aperture.size); 
 }
 #else
-#define KERNEL_HAS_MTRR 0
 #define set_mtrr(x) printk("set_mtrr: MTRR is disabled in the kernel\n")
 
 #define unset_mtrr(x) do { } while (0)
diff --git a/drivers/video/imsttfb.c b/drivers/video/imsttfb.c
index 7fbe242..a5d8130 100644
--- a/drivers/video/imsttfb.c
+++ b/drivers/video/imsttfb.c
@@ -323,6 +323,7 @@
 	unsigned long cmap_regs_phys;
 	__u8 *cmap_regs;
 	__u32 ramdac;
+	__u32 palette[16];
 };
  
 enum {
@@ -657,7 +658,7 @@
 static void
 set_imstt_regvals (struct fb_info *info, u_int bpp)
 {
-	struct imstt_par *par = (struct imstt_par *) info->par;
+	struct imstt_par *par = info->par;
 	struct imstt_regvals *init = &par->init;
 	__u32 ctl, pitch, byteswap, scr;
 
@@ -749,7 +750,7 @@
 static inline void
 set_offset (struct fb_var_screeninfo *var, struct fb_info *info)
 {
-	struct imstt_par *par = (struct imstt_par *) info->par;
+	struct imstt_par *par = info->par;
 	__u32 off = var->yoffset * (info->fix.line_length >> 3)
 		    + ((var->xoffset * (var->bits_per_pixel >> 3)) >> 3);
 	write_reg_le32(par->dc_regs, SSR, off);
@@ -863,7 +864,7 @@
 static int
 imsttfb_set_par(struct fb_info *info) 
 {
-	struct imstt_par *par = (struct imstt_par *) info->par;
+	struct imstt_par *par = info->par;
 		
 	if (!compute_imstt_regvals(par, info->var.xres, info->var.yres))
 		return -EINVAL;
@@ -881,7 +882,7 @@
 imsttfb_setcolreg (u_int regno, u_int red, u_int green, u_int blue,
 		   u_int transp, struct fb_info *info)
 {
-	struct imstt_par *par = (struct imstt_par *) info->par;
+	struct imstt_par *par = info->par;
 	u_int bpp = info->var.bits_per_pixel;
 
 	if (regno > 255)
@@ -905,14 +906,17 @@
 	if (regno < 16)
 		switch (bpp) {
 			case 16:
-				((u16 *)info->pseudo_palette)[regno] = (regno << (info->var.green.length == 5 ? 10 : 11)) | (regno << 5) | regno;
+				par->palette[regno] =
+					(regno << (info->var.green.length ==
+					5 ? 10 : 11)) | (regno << 5) | regno;
 				break;
 			case 24:
-				((u32 *)info->pseudo_palette)[regno] = (regno << 16) | (regno << 8) | regno;
+				par->palette[regno] =
+					(regno << 16) | (regno << 8) | regno;
 				break;
 			case 32: {
 				int i = (regno << 8) | regno;
-				((u32 *)info->pseudo_palette)[regno] = (i << 16) | i;
+				par->palette[regno] = (i << 16) |i;
 				break;
 			}
 		}
@@ -935,7 +939,7 @@
 static int 
 imsttfb_blank(int blank, struct fb_info *info)
 {
-	struct imstt_par *par = (struct imstt_par *) info->par;
+	struct imstt_par *par = info->par;
 	__u32 ctrl;
 
 	ctrl = read_reg_le32(par->dc_regs, STGCTL);
@@ -989,7 +993,7 @@
 static void
 imsttfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
 { 
-	struct imstt_par *par = (struct imstt_par *) info->par;
+	struct imstt_par *par = info->par;
 	__u32 Bpp, line_pitch, bgc, dx, dy, width, height;
 
 	bgc = rect->color;
@@ -1033,7 +1037,7 @@
 static void
 imsttfb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
 {
-	struct imstt_par *par = (struct imstt_par *) info->par;
+	struct imstt_par *par = info->par;
 	__u32 Bpp, line_pitch, fb_offset_old, fb_offset_new, sp, dp_octl;
  	__u32 cnt, bltctl, sx, sy, dx, dy, height, width;
 
@@ -1195,7 +1199,7 @@
 static int 
 imsttfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
 {
-	struct imstt_par *par = (struct imstt_par *) info->par;
+	struct imstt_par *par = info->par;
         u32 flags = cursor->set, fg, bg, xx, yy;
 
 	if (cursor->dest == NULL && cursor->rop == ROP_XOR)
@@ -1266,7 +1270,7 @@
 imsttfb_ioctl(struct inode *inode, struct file *file, u_int cmd,
 	      u_long arg, struct fb_info *info)
 {
-	struct imstt_par *par = (struct imstt_par *) info->par;
+	struct imstt_par *par = info->par;
 	void __user *argp = (void __user *)arg;
 	__u32 reg[2];
 	__u8 idx[2];
@@ -1350,7 +1354,7 @@
 static void __devinit
 init_imstt(struct fb_info *info)
 {
-	struct imstt_par *par = (struct imstt_par *) info->par;
+	struct imstt_par *par = info->par;
 	__u32 i, tmp, *ip, *end;
 
 	tmp = read_reg_le32(par->dc_regs, PRC);
@@ -1413,7 +1417,7 @@
 	if ((info->var.xres * info->var.yres) * (info->var.bits_per_pixel >> 3) > info->fix.smem_len
 	    || !(compute_imstt_regvals(par, info->var.xres, info->var.yres))) {
 		printk("imsttfb: %ux%ux%u not supported\n", info->var.xres, info->var.yres, info->var.bits_per_pixel);
-		kfree(info);
+		framebuffer_release(info);
 		return;
 	}
 
@@ -1449,7 +1453,7 @@
 	fb_alloc_cmap(&info->cmap, 0, 0);
 
 	if (register_framebuffer(info) < 0) {
-		kfree(info);
+		framebuffer_release(info);
 		return;
 	}
 
@@ -1474,26 +1478,21 @@
 		printk(KERN_ERR "imsttfb: no OF node for pci device\n");
 #endif /* CONFIG_PPC_OF */
 
-	size = sizeof(struct fb_info) + sizeof(struct imstt_par) +
-		sizeof(u32) * 16;
-
-	info = kmalloc(size, GFP_KERNEL);
+	info = framebuffer_alloc(sizeof(struct imstt_par), &pdev->dev);
 
 	if (!info) {
 		printk(KERN_ERR "imsttfb: Can't allocate memory\n");
 		return -ENOMEM;
 	}
 
-	memset(info, 0, size);
-
-	par = (struct imstt_par *) (info + 1);
+	par = info->par;
 
 	addr = pci_resource_start (pdev, 0);
 	size = pci_resource_len (pdev, 0);
 
 	if (!request_mem_region(addr, size, "imsttfb")) {
 		printk(KERN_ERR "imsttfb: Can't reserve memory region\n");
-		kfree(info);
+		framebuffer_release(info);
 		return -ENODEV;
 	}
 
@@ -1516,14 +1515,13 @@
 	}
 
 	info->fix.smem_start = addr;
-	info->screen_base = (__u8 *)ioremap(addr, par->ramdac == IBM ? 0x400000 : 0x800000);
+	info->screen_base = (__u8 *)ioremap(addr, par->ramdac == IBM ?
+					    0x400000 : 0x800000);
 	info->fix.mmio_start = addr + 0x800000;
 	par->dc_regs = ioremap(addr + 0x800000, 0x1000);
 	par->cmap_regs_phys = addr + 0x840000;
 	par->cmap_regs = (__u8 *)ioremap(addr + 0x840000, 0x1000);
-	info->par = par;
-	info->pseudo_palette = (void *) (par + 1);
-	info->device = &pdev->dev;
+	info->pseudo_palette = par->palette;
 	init_imstt(info);
 
 	pci_set_drvdata(pdev, info);
@@ -1534,7 +1532,7 @@
 imsttfb_remove(struct pci_dev *pdev)
 {
 	struct fb_info *info = pci_get_drvdata(pdev);
-	struct imstt_par *par = (struct imstt_par *) info->par;
+	struct imstt_par *par = info->par;
 	int size = pci_resource_len(pdev, 0);
 
 	unregister_framebuffer(info);
@@ -1542,7 +1540,7 @@
 	iounmap(par->dc_regs);
 	iounmap(info->screen_base);
 	release_mem_region(info->fix.smem_start, size);
-	kfree(info);
+	framebuffer_release(info);
 }
 
 #ifndef MODULE
diff --git a/drivers/video/kyro/STG4000InitDevice.c b/drivers/video/kyro/STG4000InitDevice.c
index 7e33cd30..ab5285a 100644
--- a/drivers/video/kyro/STG4000InitDevice.c
+++ b/drivers/video/kyro/STG4000InitDevice.c
@@ -15,6 +15,7 @@
 #include <linux/pci.h>
 
 #include "STG4000Reg.h"
+#include "STG4000Interface.h"
 
 /* SDRAM fixed settings */
 #define SDRAM_CFG_0   0x49A1
diff --git a/drivers/video/kyro/STG4000Interface.h b/drivers/video/kyro/STG4000Interface.h
index e75b3b4..b7c83d5 100644
--- a/drivers/video/kyro/STG4000Interface.h
+++ b/drivers/video/kyro/STG4000Interface.h
@@ -11,7 +11,8 @@
 #ifndef _STG4000INTERFACE_H
 #define _STG4000INTERFACE_H
 
-struct pci_dev;
+#include <linux/pci.h>
+#include <video/kyro.h>
 
 /*
  * Ramdac Setup
diff --git a/drivers/video/kyro/STG4000OverlayDevice.c b/drivers/video/kyro/STG4000OverlayDevice.c
index 2ae9baf..a8c9713 100644
--- a/drivers/video/kyro/STG4000OverlayDevice.c
+++ b/drivers/video/kyro/STG4000OverlayDevice.c
@@ -14,6 +14,7 @@
 #include <linux/types.h>
 
 #include "STG4000Reg.h"
+#include "STG4000Interface.h"
 
 /* HW Defines */
 
diff --git a/drivers/video/kyro/fbdev.c b/drivers/video/kyro/fbdev.c
index 5eb4d5c..bcd359b 100644
--- a/drivers/video/kyro/fbdev.c
+++ b/drivers/video/kyro/fbdev.c
@@ -73,8 +73,6 @@
 	.vmode		= FB_VMODE_NONINTERLACED,
 };
 
-static struct kyrofb_info *currentpar;
-
 typedef struct {
 	STG4000REG __iomem *pSTGReg;	/* Virtual address of PCI register region */
 	u32 ulNextFreeVidMem;	/* Offset from start of vid mem to next free region */
@@ -309,7 +307,7 @@
 /* Accessors */
 static int kyro_dev_video_mode_set(struct fb_info *info)
 {
-	struct kyrofb_info *par = (struct kyrofb_info *)info->par;
+	struct kyrofb_info *par = info->par;
 
 	/* Turn off display */
 	StopVTG(deviceInfo.pSTGReg);
@@ -402,7 +400,7 @@
 
 static int kyrofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
 {
-	struct kyrofb_info *par = (struct kyrofb_info *)info->par;
+	struct kyrofb_info *par = info->par;
 
 	if (var->bits_per_pixel != 16 && var->bits_per_pixel != 32) {
 		printk(KERN_WARNING "kyrofb: depth not supported: %u\n", var->bits_per_pixel);
@@ -478,7 +476,7 @@
 
 static int kyrofb_set_par(struct fb_info *info)
 {
-	struct kyrofb_info *par = (struct kyrofb_info *)info->par;
+	struct kyrofb_info *par = info->par;
 	unsigned long lineclock;
 	unsigned long frameclock;
 
@@ -536,20 +534,22 @@
 static int kyrofb_setcolreg(u_int regno, u_int red, u_int green,
 			    u_int blue, u_int transp, struct fb_info *info)
 {
+	struct kyrofb_info *par = info->par;
+
 	if (regno > 255)
 		return 1;	/* Invalid register */
 
 	if (regno < 16) {
 		switch (info->var.bits_per_pixel) {
 		case 16:
-			((u16*)(info->pseudo_palette))[regno] =
+			par->palette[regno] =
 			     (red   & 0xf800) |
 			    ((green & 0xfc00) >> 5) |
 			    ((blue  & 0xf800) >> 11);
 			break;
 		case 32:
 			red >>= 8; green >>= 8; blue >>= 8; transp >>= 8;
-			((u32*)(info->pseudo_palette))[regno] =
+			par->palette[regno] =
 			    (transp << 24) | (red << 16) | (green << 8) | blue;
 			break;
 		}
@@ -675,6 +675,7 @@
 				  const struct pci_device_id *ent)
 {
 	struct fb_info *info;
+	struct kyrofb_info *currentpar;
 	unsigned long size;
 	int err;
 
@@ -683,14 +684,11 @@
 		return err;
 	}
 
-	size = sizeof(struct fb_info) + sizeof(struct kyrofb_info) + 16 * sizeof(u32);
-	info = kmalloc(size, GFP_KERNEL);
+	info = framebuffer_alloc(sizeof(struct kyrofb_info), &pdev->dev);
 	if (!info)
 		return -ENOMEM;
 
-	memset(info, 0, size);
-
-	currentpar = (struct kyrofb_info *)(info + 1);
+	currentpar = info->par;
 
 	kyro_fix.smem_start = pci_resource_start(pdev, 0);
 	kyro_fix.smem_len   = pci_resource_len(pdev, 0);
@@ -716,8 +714,7 @@
 
 	info->fbops		= &kyrofb_ops;
 	info->fix		= kyro_fix;
-	info->par		= currentpar;
-	info->pseudo_palette	= (void *)(currentpar + 1);
+	info->pseudo_palette	= currentpar->palette;
 	info->flags		= FBINFO_DEFAULT;
 
 	SetCoreClockPLL(deviceInfo.pSTGReg, pdev);
@@ -741,7 +738,6 @@
 
 	fb_memset(info->screen_base, 0, size);
 
-	info->device = &pdev->dev;
 	if (register_framebuffer(info) < 0)
 		goto out_unmap;
 
@@ -757,7 +753,7 @@
 out_unmap:
 	iounmap(currentpar->regbase);
 	iounmap(info->screen_base);
-	kfree(info);
+	framebuffer_release(info);
 
 	return -EINVAL;
 }
@@ -765,7 +761,7 @@
 static void __devexit kyrofb_remove(struct pci_dev *pdev)
 {
 	struct fb_info *info = pci_get_drvdata(pdev);
-	struct kyrofb_info *par = (struct kyrofb_info *)info->par;
+	struct kyrofb_info *par = info->par;
 
 	/* Reset the board */
 	StopVTG(deviceInfo.pSTGReg);
@@ -789,7 +785,7 @@
 
 	unregister_framebuffer(info);
 	pci_set_drvdata(pdev, NULL);
-	kfree(info);
+	framebuffer_release(info);
 }
 
 static int __init kyrofb_init(void)
diff --git a/drivers/video/macfb.c b/drivers/video/macfb.c
index cfc748e..e6cbd9d 100644
--- a/drivers/video/macfb.c
+++ b/drivers/video/macfb.c
@@ -609,18 +609,19 @@
 	}
 }
 
-void __init macfb_init(void)
+static int __init macfb_init(void)
 {
 	int video_cmap_len, video_is_nubus = 0;
 	struct nubus_dev* ndev = NULL;
 	char *option = NULL;
+	int err;
 
 	if (fb_get_options("macfb", &option))
 		return -ENODEV;
 	macfb_setup(option);
 
 	if (!MACH_IS_MAC) 
-		return;
+		return -ENODEV;
 
 	/* There can only be one internal video controller anyway so
 	   we're not too worried about this */
@@ -958,11 +959,11 @@
 
 	fb_alloc_cmap(&fb_info.cmap, video_cmap_len, 0);
 	
-	if (register_framebuffer(&fb_info) < 0)
-		return;
-
-	printk("fb%d: %s frame buffer device\n",
-	       fb_info.node, fb_info.fix.id);
+	err = register_framebuffer(&fb_info);
+	if (!err)
+		printk("fb%d: %s frame buffer device\n",
+		       fb_info.node, fb_info.fix.id);
+	return err;
 }
 
 module_init(macfb_init);
diff --git a/drivers/video/matrox/matroxfb_base.h b/drivers/video/matrox/matroxfb_base.h
index a8c47ad..3a3e180 100644
--- a/drivers/video/matrox/matroxfb_base.h
+++ b/drivers/video/matrox/matroxfb_base.h
@@ -50,8 +50,6 @@
 #include <asm/mtrr.h>
 #endif
 
-#include "../console/fbcon.h"
-
 #if defined(CONFIG_PPC_PMAC)
 #include <asm/prom.h>
 #include <asm/pci-bridge.h>
@@ -351,8 +349,6 @@
 		      } output;
 };
 
-extern struct display fb_display[];
-
 struct matrox_switch;
 struct matroxfb_driver;
 struct matroxfb_dh_fb_info;
diff --git a/drivers/video/matrox/matroxfb_g450.c b/drivers/video/matrox/matroxfb_g450.c
index 35008af..c122d87 100644
--- a/drivers/video/matrox/matroxfb_g450.c
+++ b/drivers/video/matrox/matroxfb_g450.c
@@ -20,6 +20,8 @@
 #include <asm/uaccess.h>
 #include <asm/div64.h>
 
+#include "matroxfb_g450.h"
+
 /* Definition of the various controls */
 struct mctl {
 	struct v4l2_queryctrl desc;
diff --git a/drivers/video/matrox/matroxfb_misc.c b/drivers/video/matrox/matroxfb_misc.c
index d9d3e9f..455a46c 100644
--- a/drivers/video/matrox/matroxfb_misc.c
+++ b/drivers/video/matrox/matroxfb_misc.c
@@ -192,11 +192,8 @@
 	unsigned int wd;
 	unsigned int divider;
 	int i;
-	int fwidth;
 	struct matrox_hw_state * const hw = &ACCESS_FBINFO(hw);
 
-	fwidth = 8;
-
 	DBG(__FUNCTION__)
 
 	hw->SEQ[0] = 0x00;
@@ -235,10 +232,7 @@
 	hw->ATTR[16] = 0x41;
 	hw->ATTR[17] = 0xFF;
 	hw->ATTR[18] = 0x0F;
-	if (fwidth == 9)
-		hw->ATTR[19] = 0x08;
-	else
-		hw->ATTR[19] = 0x00;
+	hw->ATTR[19] = 0x00;
 	hw->ATTR[20] = 0x00;
 
 	hd = m->HDisplay >> 3;
diff --git a/drivers/video/neofb.c b/drivers/video/neofb.c
index 8486e77..e18c9f9 100644
--- a/drivers/video/neofb.c
+++ b/drivers/video/neofb.c
@@ -485,7 +485,7 @@
  */
 static inline int neo2200_sync(struct fb_info *info)
 {
-	struct neofb_par *par = (struct neofb_par *) info->par;
+	struct neofb_par *par = info->par;
 	int waitcycles;
 
 	while (readl(&par->neo2200->bltStat) & 1)
@@ -525,7 +525,7 @@
 static inline void neo2200_accel_init(struct fb_info *info,
 				      struct fb_var_screeninfo *var)
 {
-	struct neofb_par *par = (struct neofb_par *) info->par;
+	struct neofb_par *par = info->par;
 	Neo2200 __iomem *neo2200 = par->neo2200;
 	u32 bltMod, pitch;
 
@@ -560,7 +560,7 @@
 static int
 neofb_open(struct fb_info *info, int user)
 {
-	struct neofb_par *par = (struct neofb_par *) info->par;
+	struct neofb_par *par = info->par;
 	int cnt = atomic_read(&par->ref_count);
 
 	if (!cnt) {
@@ -575,7 +575,7 @@
 static int
 neofb_release(struct fb_info *info, int user)
 {
-	struct neofb_par *par = (struct neofb_par *) info->par;
+	struct neofb_par *par = info->par;
 	int cnt = atomic_read(&par->ref_count);
 
 	if (!cnt)
@@ -590,7 +590,7 @@
 static int
 neofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
 {
-	struct neofb_par *par = (struct neofb_par *) info->par;
+	struct neofb_par *par = info->par;
 	unsigned int pixclock = var->pixclock;
 	struct xtimings timings;
 	int memlen, vramlen;
@@ -757,7 +757,7 @@
 
 static int neofb_set_par(struct fb_info *info)
 {
-	struct neofb_par *par = (struct neofb_par *) info->par;
+	struct neofb_par *par = info->par;
 	struct xtimings timings;
 	unsigned char temp;
 	int i, clock_hi = 0;
@@ -1216,7 +1216,7 @@
 static void neofb_update_start(struct fb_info *info,
 			       struct fb_var_screeninfo *var)
 {
-	struct neofb_par *par = (struct neofb_par *) info->par;
+	struct neofb_par *par = info->par;
 	struct vgastate *state = &par->state;
 	int oldExtCRTDispAddr;
 	int Base;
@@ -1331,7 +1331,7 @@
 	 *  wms...Enable VESA DPMS compatible powerdown mode
 	 *  run "setterm -powersave powerdown" to take advantage
 	 */
-	struct neofb_par *par = (struct neofb_par *)info->par;
+	struct neofb_par *par = info->par;
 	int seqflags, lcdflags, dpmsflags, reg;
 
 	switch (blank_mode) {
@@ -1404,7 +1404,7 @@
 static void
 neo2200_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
 {
-	struct neofb_par *par = (struct neofb_par *) info->par;
+	struct neofb_par *par = info->par;
 	u_long dst, rop;
 
 	dst = rect->dx + rect->dy * info->var.xres_virtual;
@@ -1440,7 +1440,7 @@
 neo2200_copyarea(struct fb_info *info, const struct fb_copyarea *area)
 {
 	u32 sx = area->sx, sy = area->sy, dx = area->dx, dy = area->dy;
-	struct neofb_par *par = (struct neofb_par *) info->par;
+	struct neofb_par *par = info->par;
 	u_long src, dst, bltCntl;
 
 	bltCntl = NEO_BC3_FIFO_EN | NEO_BC3_SKIP_MAPPING | 0x0C0000;
@@ -1472,7 +1472,7 @@
 static void
 neo2200_imageblit(struct fb_info *info, const struct fb_image *image)
 {
-	struct neofb_par *par = (struct neofb_par *) info->par;
+	struct neofb_par *par = info->par;
 	int s_pitch = (image->width * image->depth + 7) >> 3;
 	int scan_align = info->pixmap.scan_align - 1;
 	int buf_align = info->pixmap.buf_align - 1;
@@ -1686,7 +1686,7 @@
 static int __devinit neo_map_mmio(struct fb_info *info,
 				  struct pci_dev *dev)
 {
-	struct neofb_par *par = (struct neofb_par *) info->par;
+	struct neofb_par *par = info->par;
 
 	DBG("neo_map_mmio");
 
@@ -1733,7 +1733,7 @@
 
 static void neo_unmap_mmio(struct fb_info *info)
 {
-	struct neofb_par *par = (struct neofb_par *) info->par;
+	struct neofb_par *par = info->par;
 
 	DBG("neo_unmap_mmio");
 
@@ -1796,7 +1796,7 @@
 
 #ifdef CONFIG_MTRR
 	{
-		struct neofb_par *par = (struct neofb_par *) info->par;
+		struct neofb_par *par = info->par;
 
 		mtrr_del(par->mtrr, info->fix.smem_start,
 			 info->fix.smem_len);
@@ -1811,7 +1811,7 @@
 
 static int __devinit neo_scan_monitor(struct fb_info *info)
 {
-	struct neofb_par *par = (struct neofb_par *) info->par;
+	struct neofb_par *par = info->par;
 	unsigned char type, display;
 	int w;
 
@@ -1890,7 +1890,7 @@
 
 static int __devinit neo_init_hw(struct fb_info *info)
 {
-	struct neofb_par *par = (struct neofb_par *) info->par;
+	struct neofb_par *par = info->par;
 	int videoRam = 896;
 	int maxClock = 65000;
 	int CursorMem = 1024;
@@ -2014,7 +2014,7 @@
 	struct fb_info *info;
 	struct neofb_par *par;
 
-	info = framebuffer_alloc(sizeof(struct neofb_par) + sizeof(u32) * 256, &dev->dev);
+	info = framebuffer_alloc(sizeof(struct neofb_par), &dev->dev);
 
 	if (!info)
 		return NULL;
@@ -2081,7 +2081,7 @@
 	info->fix.accel = id->driver_data;
 
 	info->fbops = &neofb_ops;
-	info->pseudo_palette = (void *) (par + 1);
+	info->pseudo_palette = par->palette;
 	return info;
 }
 
diff --git a/drivers/video/nvidia/nv_hw.c b/drivers/video/nvidia/nv_hw.c
index b989358..99c3a8e 100644
--- a/drivers/video/nvidia/nv_hw.c
+++ b/drivers/video/nvidia/nv_hw.c
@@ -52,6 +52,7 @@
 #include <linux/pci.h>
 #include "nv_type.h"
 #include "nv_local.h"
+#include "nv_proto.h"
 
 void NVLockUnlock(struct nvidia_par *par, int Lock)
 {
@@ -848,7 +849,7 @@
 		    int width,
 		    int hDisplaySize, int height, int dotClock, int flags)
 {
-	int pixelDepth, VClk;
+	int pixelDepth, VClk = 0;
 	/*
 	 * Save mode parameters.
 	 */
@@ -938,15 +939,24 @@
 
 	if (par->Architecture == NV_ARCH_04) {
 		NV_WR32(par->PFB, 0x0200, state->config);
-	} else if ((par->Chipset & 0xfff0) == 0x0090) {
-		for (i = 0; i < 15; i++) {
-			NV_WR32(par->PFB, 0x0600 + (i * 0x10), 0);
-			NV_WR32(par->PFB, 0x0604 + (i * 0x10), par->FbMapSize - 1);
-		}
-	} else {
+	} else if ((par->Architecture < NV_ARCH_40) ||
+		   (par->Chipset & 0xfff0) == 0x0040) {
 		for (i = 0; i < 8; i++) {
 			NV_WR32(par->PFB, 0x0240 + (i * 0x10), 0);
-			NV_WR32(par->PFB, 0x0244 + (i * 0x10), par->FbMapSize - 1);
+			NV_WR32(par->PFB, 0x0244 + (i * 0x10),
+				par->FbMapSize - 1);
+		}
+	} else {
+		int regions = 12;
+
+		if (((par->Chipset & 0xfff0) == 0x0090) ||
+		    ((par->Chipset & 0xfff0) == 0x01D0) ||
+		    ((par->Chipset & 0xfff0) == 0x0290))
+			regions = 15;
+		for(i = 0; i < regions; i++) {
+			NV_WR32(par->PFB, 0x0600 + (i * 0x10), 0);
+			NV_WR32(par->PFB, 0x0604 + (i * 0x10),
+				par->FbMapSize - 1);
 		}
 	}
 
@@ -1182,11 +1192,17 @@
 			NV_WR32(par->PGRAPH, 0x0608, 0xFFFFFFFF);
 		} else {
 			if (par->Architecture >= NV_ARCH_40) {
+				u32 tmp;
+
 				NV_WR32(par->PGRAPH, 0x0084, 0x401287c0);
 				NV_WR32(par->PGRAPH, 0x008C, 0x60de8051);
 				NV_WR32(par->PGRAPH, 0x0090, 0x00008000);
 				NV_WR32(par->PGRAPH, 0x0610, 0x00be3c5f);
 
+				tmp = NV_RD32(par->REGS, 0x1540) & 0xff;
+				for(i = 0; tmp && !(tmp & 1); tmp >>= 1, i++);
+				NV_WR32(par->PGRAPH, 0x5000, i);
+
 				if ((par->Chipset & 0xfff0) == 0x0040) {
 					NV_WR32(par->PGRAPH, 0x09b0,
 						0x83280fff);
@@ -1211,6 +1227,7 @@
 						0xffff7fff);
 					break;
 				case 0x00C0:
+				case 0x0120:
 					NV_WR32(par->PGRAPH, 0x0828,
 						0x007596ff);
 					NV_WR32(par->PGRAPH, 0x082C,
@@ -1245,6 +1262,7 @@
 						0x00100000);
 					break;
 				case 0x0090:
+				case 0x0290:
 					NV_WR32(par->PRAMDAC, 0x0608,
 						NV_RD32(par->PRAMDAC, 0x0608) |
 						0x00100000);
@@ -1310,14 +1328,44 @@
 				}
 			}
 
-			if ((par->Chipset & 0xfff0) == 0x0090) {
-				for (i = 0; i < 60; i++)
-					NV_WR32(par->PGRAPH, 0x0D00 + i,
-						NV_RD32(par->PFB, 0x0600 + i));
+			if ((par->Architecture < NV_ARCH_40) ||
+			    ((par->Chipset & 0xfff0) == 0x0040)) {
+				for (i = 0; i < 32; i++) {
+					NV_WR32(par->PGRAPH, 0x0900 + i*4,
+						NV_RD32(par->PFB, 0x0240 +i*4));
+					NV_WR32(par->PGRAPH, 0x6900 + i*4,
+						NV_RD32(par->PFB, 0x0240 +i*4));
+				}
 			} else {
-				for (i = 0; i < 32; i++)
-					NV_WR32(par->PGRAPH, 0x0900 + i,
-						NV_RD32(par->PFB, 0x0240 + i));
+				if (((par->Chipset & 0xfff0) == 0x0090) ||
+				    ((par->Chipset & 0xfff0) == 0x01D0) ||
+				    ((par->Chipset & 0xfff0) == 0x0290)) {
+					for (i = 0; i < 60; i++) {
+						NV_WR32(par->PGRAPH,
+							0x0D00 + i*4,
+							NV_RD32(par->PFB,
+								0x0600 + i*4));
+						NV_WR32(par->PGRAPH,
+							0x6900 + i*4,
+							NV_RD32(par->PFB,
+								0x0600 + i*4));
+					}
+				} else {
+					for (i = 0; i < 48; i++) {
+						NV_WR32(par->PGRAPH,
+							0x0900 + i*4,
+							NV_RD32(par->PFB,
+								0x0600 + i*4));
+						if(((par->Chipset & 0xfff0)
+						    != 0x0160) &&
+						   ((par->Chipset & 0xfff0)
+						    != 0x0220))
+							NV_WR32(par->PGRAPH,
+								0x6900 + i*4,
+								NV_RD32(par->PFB,
+									0x0600 + i*4));
+					}
+				}
 			}
 
 			if (par->Architecture >= NV_ARCH_40) {
@@ -1338,7 +1386,9 @@
 					NV_WR32(par->PGRAPH, 0x0868,
 						par->FbMapSize - 1);
 				} else {
-					if((par->Chipset & 0xfff0) == 0x0090) {
+					if ((par->Chipset & 0xfff0) == 0x0090 ||
+					    (par->Chipset & 0xfff0) == 0x01D0 ||
+					    (par->Chipset & 0xfff0) == 0x0290) {
 						NV_WR32(par->PGRAPH, 0x0DF0,
 							NV_RD32(par->PFB, 0x0200));
 						NV_WR32(par->PGRAPH, 0x0DF4,
diff --git a/drivers/video/nvidia/nv_i2c.c b/drivers/video/nvidia/nv_i2c.c
index 12f2884..bd9eca0 100644
--- a/drivers/video/nvidia/nv_i2c.c
+++ b/drivers/video/nvidia/nv_i2c.c
@@ -46,7 +46,7 @@
 
 static void nvidia_gpio_setsda(void *data, int state)
 {
-	struct nvidia_i2c_chan *chan = (struct nvidia_i2c_chan *)data;
+	struct nvidia_i2c_chan *chan = data;
 	struct nvidia_par *par = chan->par;
 	u32 val;
 
@@ -64,7 +64,7 @@
 
 static int nvidia_gpio_getscl(void *data)
 {
-	struct nvidia_i2c_chan *chan = (struct nvidia_i2c_chan *)data;
+	struct nvidia_i2c_chan *chan = data;
 	struct nvidia_par *par = chan->par;
 	u32 val = 0;
 
@@ -79,7 +79,7 @@
 
 static int nvidia_gpio_getsda(void *data)
 {
-	struct nvidia_i2c_chan *chan = (struct nvidia_i2c_chan *)data;
+	struct nvidia_i2c_chan *chan = data;
 	struct nvidia_par *par = chan->par;
 	u32 val = 0;
 
@@ -136,13 +136,13 @@
 	par->chan[2].par = par;
 
 	par->chan[0].ddc_base = 0x3e;
-	nvidia_setup_i2c_bus(&par->chan[0], "BUS1");
+	nvidia_setup_i2c_bus(&par->chan[0], "nvidia #0");
 
 	par->chan[1].ddc_base = 0x36;
-	nvidia_setup_i2c_bus(&par->chan[1], "BUS2");
+	nvidia_setup_i2c_bus(&par->chan[1], "nvidia #1");
 
 	par->chan[2].ddc_base = 0x50;
-	nvidia_setup_i2c_bus(&par->chan[2], "BUS3");
+	nvidia_setup_i2c_bus(&par->chan[2], "nvidia #2");
 }
 
 void nvidia_delete_i2c_busses(struct nvidia_par *par)
diff --git a/drivers/video/nvidia/nv_proto.h b/drivers/video/nvidia/nv_proto.h
index 3353103..b149a69 100644
--- a/drivers/video/nvidia/nv_proto.h
+++ b/drivers/video/nvidia/nv_proto.h
@@ -4,7 +4,7 @@
 #define __NV_PROTO_H__
 
 /* in nv_setup.c */
-void NVCommonSetup(struct fb_info *info);
+int NVCommonSetup(struct fb_info *info);
 void NVWriteCrtc(struct nvidia_par *par, u8 index, u8 value);
 u8 NVReadCrtc(struct nvidia_par *par, u8 index);
 void NVWriteGr(struct nvidia_par *par, u8 index, u8 value);
diff --git a/drivers/video/nvidia/nv_setup.c b/drivers/video/nvidia/nv_setup.c
index 1f06a9f..a18a9ae 100644
--- a/drivers/video/nvidia/nv_setup.c
+++ b/drivers/video/nvidia/nv_setup.c
@@ -285,28 +285,34 @@
 			par->CrystalFreqKHz = 27000;
 	}
 
-	par->CursorStart = (par->RamAmountKBytes - 96) * 1024;
 	par->CURSOR = NULL;	/* can't set this here */
 	par->MinVClockFreqKHz = 12000;
 	par->MaxVClockFreqKHz = par->twoStagePLL ? 400000 : 350000;
 }
 
-void NVCommonSetup(struct fb_info *info)
+int NVCommonSetup(struct fb_info *info)
 {
 	struct nvidia_par *par = info->par;
-	struct fb_var_screeninfo var;
+	struct fb_var_screeninfo *var;
 	u16 implementation = par->Chipset & 0x0ff0;
 	u8 *edidA = NULL, *edidB = NULL;
-	struct fb_monspecs monitorA, monitorB;
+	struct fb_monspecs *monitorA, *monitorB;
 	struct fb_monspecs *monA = NULL, *monB = NULL;
 	int mobile = 0;
 	int tvA = 0;
 	int tvB = 0;
 	int FlatPanel = -1;	/* really means the CRTC is slaved */
 	int Television = 0;
+	int err = 0;
 
-	memset(&monitorA, 0, sizeof(struct fb_monspecs));
-	memset(&monitorB, 0, sizeof(struct fb_monspecs));
+	var = kzalloc(sizeof(struct fb_var_screeninfo), GFP_KERNEL);
+	monitorA = kzalloc(sizeof(struct fb_monspecs), GFP_KERNEL);
+	monitorB = kzalloc(sizeof(struct fb_monspecs), GFP_KERNEL);
+
+	if (!var || !monitorA || !monitorB) {
+		err = -ENOMEM;
+		goto done;
+	}
 
 	par->PRAMIN = par->REGS + (0x00710000 / 4);
 	par->PCRTC0 = par->REGS + (0x00600000 / 4);
@@ -382,6 +388,8 @@
 	case 0x0146:
 	case 0x0147:
 	case 0x0148:
+	case 0x0098:
+	case 0x0099:
 		mobile = 1;
 		break;
 	default:
@@ -406,9 +414,9 @@
 		par->CRTCnumber = 0;
 		if (nvidia_probe_i2c_connector(info, 1, &edidA))
 			nvidia_probe_of_connector(info, 1, &edidA);
-		if (edidA && !fb_parse_edid(edidA, &var)) {
+		if (edidA && !fb_parse_edid(edidA, var)) {
 			printk("nvidiafb: EDID found from BUS1\n");
-			monA = &monitorA;
+			monA = monitorA;
 			fb_edid_to_monspecs(edidA, monA);
 			FlatPanel = (monA->input & FB_DISP_DDI) ? 1 : 0;
 
@@ -494,17 +502,17 @@
 
 		if (nvidia_probe_i2c_connector(info, 1, &edidA))
 			nvidia_probe_of_connector(info, 1, &edidA);
-		if (edidA && !fb_parse_edid(edidA, &var)) {
+		if (edidA && !fb_parse_edid(edidA, var)) {
 			printk("nvidiafb: EDID found from BUS1\n");
-			monA = &monitorA;
+			monA = monitorA;
 			fb_edid_to_monspecs(edidA, monA);
 		}
 
 		if (nvidia_probe_i2c_connector(info, 2, &edidB))
 			nvidia_probe_of_connector(info, 2, &edidB);
-		if (edidB && !fb_parse_edid(edidB, &var)) {
+		if (edidB && !fb_parse_edid(edidB, var)) {
 			printk("nvidiafb: EDID found from BUS2\n");
-			monB = &monitorB;
+			monB = monitorB;
 			fb_edid_to_monspecs(edidB, monB);
 		}
 
@@ -639,4 +647,9 @@
 
 	kfree(edidA);
 	kfree(edidB);
+done:
+	kfree(var);
+	kfree(monitorA);
+	kfree(monitorB);
+	return err;
 }
diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
index bee09c6..dbcb896 100644
--- a/drivers/video/nvidia/nvidia.c
+++ b/drivers/video/nvidia/nvidia.c
@@ -284,6 +284,16 @@
 	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 	{PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_GEFORCE_6200,
 	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
+	{PCI_VENDOR_ID_NVIDIA, PCIE_DEVICE_ID_NVIDIA_GEFORCE_6800_ALT1,
+	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
+	{PCI_VENDOR_ID_NVIDIA, PCIE_DEVICE_ID_NVIDIA_GEFORCE_6600_ALT1,
+	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
+	{PCI_VENDOR_ID_NVIDIA, PCIE_DEVICE_ID_NVIDIA_GEFORCE_6600_ALT2,
+	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
+	{PCI_VENDOR_ID_NVIDIA, PCIE_DEVICE_ID_NVIDIA_GEFORCE_6200_ALT1,
+	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
+	{PCI_VENDOR_ID_NVIDIA, PCIE_DEVICE_ID_NVIDIA_GEFORCE_6800_GT,
+	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 	{PCI_VENDOR_ID_NVIDIA, 0x0252,
 	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 	{PCI_VENDOR_ID_NVIDIA, 0x0313,
@@ -418,6 +428,7 @@
 static int noscale __devinitdata = 0;
 static int paneltweak __devinitdata = 0;
 static int vram __devinitdata = 0;
+static int bpp __devinitdata = 8;
 #ifdef CONFIG_MTRR
 static int nomtrr __devinitdata = 0;
 #endif
@@ -485,7 +496,7 @@
 
 static int nvidia_set_backlight_enable(int on, int level, void *data)
 {
-	struct nvidia_par *par = (struct nvidia_par *)data;
+	struct nvidia_par *par = data;
 	u32 tmp_pcrt, tmp_pmc, fpcontrol;
 
 	tmp_pmc = NV_RD32(par->PMC, 0x10F0) & 0x0000FFFF;
@@ -1382,24 +1393,36 @@
 				 info->monspecs.modedb_len, &info->modelist);
 	fb_var_to_videomode(&modedb, &nvidiafb_default_var);
 
+	switch (bpp) {
+	case 0 ... 8:
+		bpp = 8;
+		break;
+	case 9 ... 16:
+		bpp = 16;
+		break;
+	default:
+		bpp = 32;
+		break;
+	}
+
 	if (specs->modedb != NULL) {
 		struct fb_videomode *modedb;
 
 		modedb = fb_find_best_display(specs, &info->modelist);
 		fb_videomode_to_var(&nvidiafb_default_var, modedb);
-		nvidiafb_default_var.bits_per_pixel = 8;
+		nvidiafb_default_var.bits_per_pixel = bpp;
 	} else if (par->fpWidth && par->fpHeight) {
 		char buf[16];
 
 		memset(buf, 0, 16);
 		snprintf(buf, 15, "%dx%dMR", par->fpWidth, par->fpHeight);
 		fb_find_mode(&nvidiafb_default_var, info, buf, specs->modedb,
-			     specs->modedb_len, &modedb, 8);
+			     specs->modedb_len, &modedb, bpp);
 	}
 
 	if (mode_option)
 		fb_find_mode(&nvidiafb_default_var, info, mode_option,
-			     specs->modedb, specs->modedb_len, &modedb, 8);
+			     specs->modedb, specs->modedb_len, &modedb, bpp);
 
 	info->var = nvidiafb_default_var;
 	info->fix.visual = (info->var.bits_per_pixel == 8) ?
@@ -1448,11 +1471,34 @@
 	return nvidiafb_check_var(&info->var, info);
 }
 
-static u32 __devinit nvidia_get_arch(struct pci_dev *pd)
+static u32 __devinit nvidia_get_chipset(struct fb_info *info)
 {
+	struct nvidia_par *par = info->par;
+	u32 id = (par->pci_dev->vendor << 16) | par->pci_dev->device;
+
+	printk("nvidiafb: PCI id - %x\n", id);
+	if ((id & 0xfff0) == 0x00f0) {
+		/* pci-e */
+		printk("nvidiafb: PCI-E card\n");
+		id = NV_RD32(par->REGS, 0x1800);
+
+		if ((id & 0x0000ffff) == 0x000010DE)
+			id = 0x10DE0000 | (id >> 16);
+		else if ((id & 0xffff0000) == 0xDE100000) /* wrong endian */
+			id = 0x10DE0000 | ((id << 8) & 0x0000ff00) |
+                            ((id >> 8) & 0x000000ff);
+	}
+
+	printk("nvidiafb: Actual id - %x\n", id);
+	return id;
+}
+
+static u32 __devinit nvidia_get_arch(struct fb_info *info)
+{
+	struct nvidia_par *par = info->par;
 	u32 arch = 0;
 
-	switch (pd->device & 0x0ff0) {
+	switch (par->Chipset & 0x0ff0) {
 	case 0x0100:		/* GeForce 256 */
 	case 0x0110:		/* GeForce2 MX */
 	case 0x0150:		/* GeForce2 */
@@ -1485,6 +1531,8 @@
 	case 0x0210:
 	case 0x0220:
 	case 0x0230:
+	case 0x0290:
+	case 0x0390:
 		arch = NV_ARCH_40;
 		break;
 	case 0x0020:		/* TNT, TNT2 */
@@ -1513,7 +1561,7 @@
 	if (!info)
 		goto err_out;
 
-	par = (struct nvidia_par *)info->par;
+	par = info->par;
 	par->pci_dev = pd;
 
 	info->pixmap.addr = kmalloc(8 * 1024, GFP_KERNEL);
@@ -1533,18 +1581,6 @@
 		goto err_out_request;
 	}
 
-	par->Architecture = nvidia_get_arch(pd);
-
-	par->Chipset = (pd->vendor << 16) | pd->device;
-	printk(KERN_INFO PFX "nVidia device/chipset %X\n", par->Chipset);
-
-	if (par->Architecture == 0) {
-		printk(KERN_ERR PFX "unknown NV_ARCH\n");
-		goto err_out_free_base0;
-	}
-
-	sprintf(nvidiafb_fix.id, "NV%x", (pd->device & 0x0ff0) >> 4);
-
 	par->FlatPanel = flatpanel;
 	if (flatpanel == 1)
 		printk(KERN_INFO PFX "flatpanel support enabled\n");
@@ -1570,7 +1606,19 @@
 		goto err_out_free_base0;
 	}
 
-	NVCommonSetup(info);
+	par->Chipset = nvidia_get_chipset(info);
+	printk(KERN_INFO PFX "nVidia device/chipset %X\n", par->Chipset);
+	par->Architecture = nvidia_get_arch(info);
+
+	if (par->Architecture == 0) {
+		printk(KERN_ERR PFX "unknown NV_ARCH\n");
+		goto err_out_arch;
+	}
+
+	sprintf(nvidiafb_fix.id, "NV%x", (pd->device & 0x0ff0) >> 4);
+
+	if (NVCommonSetup(info))
+		goto err_out_arch;
 
 	par->FbAddress = nvidiafb_fix.smem_start;
 	par->FbMapSize = par->RamAmountKBytes * 1024;
@@ -1581,10 +1629,15 @@
 	if (par->FbMapSize > 64 * 1024 * 1024)
 		par->FbMapSize = 64 * 1024 * 1024;
 
-	par->FbUsableSize = par->FbMapSize - (128 * 1024);
+	if(par->Architecture >= NV_ARCH_40)
+  	        par->FbUsableSize = par->FbMapSize - (560 * 1024);
+	else
+		par->FbUsableSize = par->FbMapSize - (128 * 1024);
 	par->ScratchBufferSize = (par->Architecture < NV_ARCH_10) ? 8 * 1024 :
 	    16 * 1024;
 	par->ScratchBufferStart = par->FbUsableSize - par->ScratchBufferSize;
+	par->CursorStart = par->FbUsableSize + (32 * 1024);
+
 	info->screen_base = ioremap(nvidiafb_fix.smem_start, par->FbMapSize);
 	info->screen_size = par->FbUsableSize;
 	nvidiafb_fix.smem_len = par->RamAmountKBytes * 1024;
@@ -1640,21 +1693,22 @@
 	NVTRACE_LEAVE();
 	return 0;
 
-      err_out_iounmap_fb:
+err_out_iounmap_fb:
 	iounmap(info->screen_base);
-      err_out_free_base1:
+err_out_free_base1:
 	fb_destroy_modedb(info->monspecs.modedb);
 	nvidia_delete_i2c_busses(par);
+err_out_arch:
 	iounmap(par->REGS);
-      err_out_free_base0:
+err_out_free_base0:
 	pci_release_regions(pd);
-      err_out_request:
+err_out_request:
 	pci_disable_device(pd);
-      err_out_enable:
+err_out_enable:
 	kfree(info->pixmap.addr);
-      err_out_kfree:
+err_out_kfree:
 	framebuffer_release(info);
-      err_out:
+err_out:
 	return -ENODEV;
 }
 
@@ -1729,6 +1783,8 @@
 #endif
 		} else if (!strncmp(this_opt, "fpdither:", 9)) {
 			fpdither = simple_strtol(this_opt+9, NULL, 0);
+		} else if (!strncmp(this_opt, "bpp:", 4)) {
+			bpp = simple_strtoul(this_opt+4, NULL, 0);
 		} else
 			mode_option = this_opt;
 	}
@@ -1804,6 +1860,11 @@
 MODULE_PARM_DESC(vram,
 		 "amount of framebuffer memory to remap in MiB"
 		 "(default=0 - remap entire memory)");
+module_param(mode_option, charp, 0);
+MODULE_PARM_DESC(mode_option, "Specify initial video mode");
+module_param(bpp, int, 0);
+MODULE_PARM_DESC(bpp, "pixel width in bits"
+		 "(default=8)");
 #ifdef CONFIG_MTRR
 module_param(nomtrr, bool, 0);
 MODULE_PARM_DESC(nomtrr, "Disables MTRR support (0 or 1=disabled) "
diff --git a/drivers/video/pm2fb.c b/drivers/video/pm2fb.c
index 0277ce0..5fe1979 100644
--- a/drivers/video/pm2fb.c
+++ b/drivers/video/pm2fb.c
@@ -91,6 +91,7 @@
 	u32		mem_config;	/* MemConfig reg at probe */
 	u32		mem_control;	/* MemControl reg at probe */
 	u32		boot_address;	/* BootAddress reg at probe */
+	u32             palette[16];
 };
 
 /*
@@ -674,7 +675,7 @@
  */
 static int pm2fb_set_par(struct fb_info *info)
 {
-	struct pm2fb_par *par = (struct pm2fb_par *) info->par;
+	struct pm2fb_par *par = info->par;
 	u32 pixclock;
 	u32 width, height, depth;
 	u32 hsstart, hsend, hbend, htotal;
@@ -854,7 +855,7 @@
 			   unsigned blue, unsigned transp,
 			   struct fb_info *info)
 {
-	struct pm2fb_par *par = (struct pm2fb_par *) info->par;
+	struct pm2fb_par *par = info->par;
 
 	if (regno >= info->cmap.len)  /* no. of hw registers */
 		return 1;
@@ -929,7 +930,7 @@
    		case 16:
 		case 24:
 		case 32:	
-           		((u32*)(info->pseudo_palette))[regno] = v;
+           		par->palette[regno] = v;
 			break;
 		}
 		return 0;
@@ -955,7 +956,7 @@
 static int pm2fb_pan_display(struct fb_var_screeninfo *var,
 			     struct fb_info *info)
 {
-	struct pm2fb_par *p = (struct pm2fb_par *) info->par;
+	struct pm2fb_par *p = info->par;
 	u32 base;
 	u32 depth;
 	u32 xres;
@@ -987,7 +988,7 @@
  */
 static int pm2fb_blank(int blank_mode, struct fb_info *info)
 {
-	struct pm2fb_par *par = (struct pm2fb_par *) info->par;
+	struct pm2fb_par *par = info->par;
 	u32 video = par->video;
 
 	DPRINTK("blank_mode %d\n", blank_mode);
@@ -1054,8 +1055,7 @@
 {
 	struct pm2fb_par *default_par;
 	struct fb_info *info;
-	int size, err;
-	int err_retval = -ENXIO;
+	int err, err_retval = -ENXIO;
 
 	err = pci_enable_device(pdev);
 	if ( err ) {
@@ -1063,11 +1063,10 @@
 		return err;
 	}
 
-	size = sizeof(struct pm2fb_par) + 256 * sizeof(u32);
-	info = framebuffer_alloc(size, &pdev->dev);
+	info = framebuffer_alloc(sizeof(struct pm2fb_par), &pdev->dev);
 	if ( !info )
 		return -ENOMEM;
-	default_par = (struct pm2fb_par *) info->par;
+	default_par = info->par;
 
 	switch (pdev->device) {
 	case  PCI_DEVICE_ID_TI_TVP4020:
@@ -1171,7 +1170,7 @@
 
 	info->fbops		= &pm2fb_ops;
 	info->fix		= pm2fb_fix; 	
-	info->pseudo_palette	= (void *)(default_par + 1); 
+	info->pseudo_palette	= default_par->palette;
 	info->flags		= FBINFO_DEFAULT |
                                   FBINFO_HWACCEL_YPAN;
 
diff --git a/drivers/video/riva/fbdev.c b/drivers/video/riva/fbdev.c
index 3e9f96e..6c19ab6 100644
--- a/drivers/video/riva/fbdev.c
+++ b/drivers/video/riva/fbdev.c
@@ -630,7 +630,7 @@
 	int bpp, width, hDisplaySize, hDisplay, hStart,
 	    hEnd, hTotal, height, vDisplay, vStart, vEnd, vTotal, dotClock;
 	int hBlankStart, hBlankEnd, vBlankStart, vBlankEnd;
-	struct riva_par *par = (struct riva_par *) info->par;
+	struct riva_par *par = info->par;
 	struct riva_regs newmode;
 	
 	NVTRACE_ENTER();
@@ -925,7 +925,7 @@
 
 static void riva_setup_accel(struct fb_info *info)
 {
-	struct riva_par *par = (struct riva_par *) info->par;
+	struct riva_par *par = info->par;
 
 	RIVA_FIFO_FREE(par->riva, Clip, 2);
 	NV_WR32(&par->riva.Clip->TopLeft, 0, 0x0);
@@ -979,7 +979,7 @@
 #ifdef CONFIG_PMAC_BACKLIGHT
 static int riva_set_backlight_enable(int on, int level, void *data)
 {
-	struct riva_par *par = (struct riva_par *)data;
+	struct riva_par *par = data;
 	U032 tmp_pcrt, tmp_pmc;
 
 	tmp_pmc = par->riva.PMC[0x10F0/4] & 0x0000FFFF;
@@ -1008,7 +1008,7 @@
 
 static int rivafb_open(struct fb_info *info, int user)
 {
-	struct riva_par *par = (struct riva_par *) info->par;
+	struct riva_par *par = info->par;
 	int cnt = atomic_read(&par->ref_count);
 
 	NVTRACE_ENTER();
@@ -1034,7 +1034,7 @@
 
 static int rivafb_release(struct fb_info *info, int user)
 {
-	struct riva_par *par = (struct riva_par *) info->par;
+	struct riva_par *par = info->par;
 	int cnt = atomic_read(&par->ref_count);
 
 	NVTRACE_ENTER();
@@ -1057,7 +1057,7 @@
 static int rivafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
 {
 	struct fb_videomode *mode;
-	struct riva_par *par = (struct riva_par *) info->par;
+	struct riva_par *par = info->par;
 	int nom, den;		/* translating from pixels->bytes */
 	int mode_valid = 0;
 	
@@ -1166,7 +1166,7 @@
 
 static int rivafb_set_par(struct fb_info *info)
 {
-	struct riva_par *par = (struct riva_par *) info->par;
+	struct riva_par *par = info->par;
 
 	NVTRACE_ENTER();
 	/* vgaHWunlock() + riva unlock (0x7F) */
@@ -1205,43 +1205,19 @@
 static int rivafb_pan_display(struct fb_var_screeninfo *var,
 			      struct fb_info *info)
 {
-	struct riva_par *par = (struct riva_par *)info->par;
+	struct riva_par *par = info->par;
 	unsigned int base;
 
 	NVTRACE_ENTER();
-	if (var->xoffset > (var->xres_virtual - var->xres))
-		return -EINVAL;
-	if (var->yoffset > (var->yres_virtual - var->yres))
-		return -EINVAL;
-
-	if (var->vmode & FB_VMODE_YWRAP) {
-		if (var->yoffset < 0
-		    || var->yoffset >= info->var.yres_virtual
-		    || var->xoffset) return -EINVAL;
-	} else {
-		if (var->xoffset + info->var.xres > info->var.xres_virtual ||
-		    var->yoffset + info->var.yres > info->var.yres_virtual)
-			return -EINVAL;
-	}
-
 	base = var->yoffset * info->fix.line_length + var->xoffset;
-
 	par->riva.SetStartAddress(&par->riva, base);
-
-	info->var.xoffset = var->xoffset;
-	info->var.yoffset = var->yoffset;
-
-	if (var->vmode & FB_VMODE_YWRAP)
-		info->var.vmode |= FB_VMODE_YWRAP;
-	else
-		info->var.vmode &= ~FB_VMODE_YWRAP;
 	NVTRACE_LEAVE();
 	return 0;
 }
 
 static int rivafb_blank(int blank, struct fb_info *info)
 {
-	struct riva_par *par= (struct riva_par *)info->par;
+	struct riva_par *par= info->par;
 	unsigned char tmp, vesa;
 
 	tmp = SEQin(par, 0x01) & ~0x20;	/* screen on/off */
@@ -1304,7 +1280,7 @@
 			  unsigned blue, unsigned transp,
 			  struct fb_info *info)
 {
-	struct riva_par *par = (struct riva_par *)info->par;
+	struct riva_par *par = info->par;
 	RIVA_HW_INST *chip = &par->riva;
 	int i;
 
@@ -1393,7 +1369,7 @@
  */
 static void rivafb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
 {
-	struct riva_par *par = (struct riva_par *) info->par;
+	struct riva_par *par = info->par;
 	u_int color, rop = 0;
 
 	if ((info->flags & FBINFO_HWACCEL_DISABLED)) {
@@ -1449,7 +1425,7 @@
  */
 static void rivafb_copyarea(struct fb_info *info, const struct fb_copyarea *region)
 {
-	struct riva_par *par = (struct riva_par *) info->par;
+	struct riva_par *par = info->par;
 
 	if ((info->flags & FBINFO_HWACCEL_DISABLED)) {
 		cfb_copyarea(info, region);
@@ -1495,7 +1471,7 @@
 static void rivafb_imageblit(struct fb_info *info, 
 			     const struct fb_image *image)
 {
-	struct riva_par *par = (struct riva_par *) info->par;
+	struct riva_par *par = info->par;
 	u32 fgx = 0, bgx = 0, width, tmp;
 	u8 *cdat = (u8 *) image->data;
 	volatile u32 __iomem *d;
@@ -1580,7 +1556,7 @@
  */
 static int rivafb_cursor(struct fb_info *info, struct fb_cursor *cursor)
 {
-	struct riva_par *par = (struct riva_par *) info->par;
+	struct riva_par *par = info->par;
 	u8 data[MAX_CURS * MAX_CURS/8];
 	int i, set = cursor->set;
 	u16 fg, bg;
@@ -1664,7 +1640,7 @@
 
 static int rivafb_sync(struct fb_info *info)
 {
-	struct riva_par *par = (struct riva_par *)info->par;
+	struct riva_par *par = info->par;
 
 	wait_for_idle(par);
 	return 0;
@@ -1696,7 +1672,7 @@
 static int __devinit riva_set_fbinfo(struct fb_info *info)
 {
 	unsigned int cmap_len;
-	struct riva_par *par = (struct riva_par *) info->par;
+	struct riva_par *par = info->par;
 
 	NVTRACE_ENTER();
 	info->flags = FBINFO_DEFAULT
@@ -1733,7 +1709,7 @@
 #ifdef CONFIG_PPC_OF
 static int __devinit riva_get_EDID_OF(struct fb_info *info, struct pci_dev *pd)
 {
-	struct riva_par *par = (struct riva_par *) info->par;
+	struct riva_par *par = info->par;
 	struct device_node *dp;
 	unsigned char *pedid = NULL;
 	unsigned char *disptype = NULL;
@@ -1767,7 +1743,7 @@
 #if defined(CONFIG_FB_RIVA_I2C) && !defined(CONFIG_PPC_OF)
 static int __devinit riva_get_EDID_i2c(struct fb_info *info)
 {
-	struct riva_par *par = (struct riva_par *) info->par;
+	struct riva_par *par = info->par;
 	struct fb_var_screeninfo var;
 	int i;
 
@@ -1837,7 +1813,7 @@
 static void __devinit riva_get_edidinfo(struct fb_info *info)
 {
 	struct fb_var_screeninfo *var = &rivafb_default_var;
-	struct riva_par *par = (struct riva_par *) info->par;
+	struct riva_par *par = info->par;
 
 	fb_edid_to_monspecs(par->EDID, &info->monspecs);
 	fb_videomode_to_modelist(info->monspecs.modedb, info->monspecs.modedb_len,
@@ -1909,7 +1885,7 @@
 		ret = -ENOMEM;
 		goto err_ret;
 	}
-	default_par = (struct riva_par *) info->par;
+	default_par = info->par;
 	default_par->pdev = pd;
 
 	info->pixmap.addr = kmalloc(8 * 1024, GFP_KERNEL);
@@ -2070,7 +2046,7 @@
 
 err_iounmap_screen_base:
 #ifdef CONFIG_FB_RIVA_I2C
-	riva_delete_i2c_busses((struct riva_par *) info->par);
+	riva_delete_i2c_busses(info->par);
 #endif
 	iounmap(info->screen_base);
 err_iounmap_pramin:
@@ -2093,7 +2069,7 @@
 static void __exit rivafb_remove(struct pci_dev *pd)
 {
 	struct fb_info *info = pci_get_drvdata(pd);
-	struct riva_par *par = (struct riva_par *) info->par;
+	struct riva_par *par = info->par;
 	
 	NVTRACE_ENTER();
 	if (!info)
diff --git a/drivers/video/riva/rivafb-i2c.c b/drivers/video/riva/rivafb-i2c.c
index 77151d8..8b1967f 100644
--- a/drivers/video/riva/rivafb-i2c.c
+++ b/drivers/video/riva/rivafb-i2c.c
@@ -30,7 +30,7 @@
 
 static void riva_gpio_setscl(void* data, int state)
 {
-	struct riva_i2c_chan 	*chan = (struct riva_i2c_chan *)data;
+	struct riva_i2c_chan 	*chan = data;
 	struct riva_par 	*par = chan->par;
 	u32			val;
 
@@ -48,7 +48,7 @@
 
 static void riva_gpio_setsda(void* data, int state)
 {
-	struct riva_i2c_chan 	*chan = (struct riva_i2c_chan *)data;
+	struct riva_i2c_chan 	*chan = data;
 	struct riva_par 	*par = chan->par;
 	u32			val;
 
@@ -66,7 +66,7 @@
 
 static int riva_gpio_getscl(void* data)
 {
-	struct riva_i2c_chan 	*chan = (struct riva_i2c_chan *)data;
+	struct riva_i2c_chan 	*chan = data;
 	struct riva_par 	*par = chan->par;
 	u32			val = 0;
 
@@ -81,7 +81,7 @@
 
 static int riva_gpio_getsda(void* data)
 {
-	struct riva_i2c_chan 	*chan = (struct riva_i2c_chan *)data;
+	struct riva_i2c_chan 	*chan = data;
 	struct riva_par 	*par = chan->par;
 	u32			val = 0;
 
diff --git a/drivers/video/s3c2410fb.c b/drivers/video/s3c2410fb.c
index fe99d17..d574dd3 100644
--- a/drivers/video/s3c2410fb.c
+++ b/drivers/video/s3c2410fb.c
@@ -552,7 +552,7 @@
  * s3c2410fb_init_registers - Initialise all LCD-related registers
  */
 
-int s3c2410fb_init_registers(struct s3c2410fb_info *fbi)
+static int s3c2410fb_init_registers(struct s3c2410fb_info *fbi)
 {
 	unsigned long flags;
 
@@ -634,7 +634,7 @@
 
 static char driver_name[]="s3c2410fb";
 
-int __init s3c2410fb_probe(struct platform_device *pdev)
+static int __init s3c2410fb_probe(struct platform_device *pdev)
 {
 	struct s3c2410fb_info *info;
 	struct fb_info	   *fbinfo;
@@ -667,8 +667,6 @@
 	info->fb = fbinfo;
 	platform_set_drvdata(pdev, fbinfo);
 
-	s3c2410fb_init_registers(info);
-
 	dprintk("devinit\n");
 
 	strcpy(fbinfo->fix.id, driver_name);
@@ -701,8 +699,8 @@
 	fbinfo->var.yres_virtual    = mach_info->yres.defval;
 	fbinfo->var.bits_per_pixel  = mach_info->bpp.defval;
 
-	fbinfo->var.upper_margin    = S3C2410_LCDCON2_GET_VBPD(mregs->lcdcon2) +1;
-	fbinfo->var.lower_margin    = S3C2410_LCDCON2_GET_VFPD(mregs->lcdcon2) +1;
+	fbinfo->var.upper_margin    = S3C2410_LCDCON2_GET_VBPD(mregs->lcdcon2) + 1;
+	fbinfo->var.lower_margin    = S3C2410_LCDCON2_GET_VFPD(mregs->lcdcon2) + 1;
 	fbinfo->var.vsync_len	    = S3C2410_LCDCON2_GET_VSPW(mregs->lcdcon2) + 1;
 
 	fbinfo->var.left_margin	    = S3C2410_LCDCON3_GET_HFPD(mregs->lcdcon3) + 1;
diff --git a/drivers/video/savage/savagefb-i2c.c b/drivers/video/savage/savagefb-i2c.c
index 3c98457..00719a9 100644
--- a/drivers/video/savage/savagefb-i2c.c
+++ b/drivers/video/savage/savagefb-i2c.c
@@ -49,7 +49,7 @@
 
 static void savage4_gpio_setscl(void *data, int val)
 {
-	struct savagefb_i2c_chan *chan = (struct savagefb_i2c_chan *)data;
+	struct savagefb_i2c_chan *chan = data;
 	unsigned int r;
 
 	r = readl(chan->ioaddr + chan->reg);
@@ -63,7 +63,7 @@
 
 static void savage4_gpio_setsda(void *data, int val)
 {
-	struct savagefb_i2c_chan *chan = (struct savagefb_i2c_chan *)data;
+	struct savagefb_i2c_chan *chan = data;
 
 	unsigned int r;
 	r = readl(chan->ioaddr + chan->reg);
@@ -77,21 +77,21 @@
 
 static int savage4_gpio_getscl(void *data)
 {
-	struct savagefb_i2c_chan *chan = (struct savagefb_i2c_chan *)data;
+	struct savagefb_i2c_chan *chan = data;
 
 	return (0 != (readl(chan->ioaddr + chan->reg) & SAVAGE4_I2C_SCL_IN));
 }
 
 static int savage4_gpio_getsda(void *data)
 {
-	struct savagefb_i2c_chan *chan = (struct savagefb_i2c_chan *)data;
+	struct savagefb_i2c_chan *chan = data;
 
 	return (0 != (readl(chan->ioaddr + chan->reg) & SAVAGE4_I2C_SDA_IN));
 }
 
 static void prosavage_gpio_setscl(void* data, int val)
 {
-	struct savagefb_i2c_chan *chan = (struct savagefb_i2c_chan *)data;
+	struct savagefb_i2c_chan *chan = data;
 	u32			  r;
 
 	SET_CR_IX(chan->ioaddr, chan->reg);
@@ -107,7 +107,7 @@
 
 static void prosavage_gpio_setsda(void* data, int val)
 {
-	struct savagefb_i2c_chan *chan = (struct savagefb_i2c_chan *)data;
+	struct savagefb_i2c_chan *chan = data;
 	unsigned int r;
 
 	SET_CR_IX(chan->ioaddr, chan->reg);
@@ -123,7 +123,7 @@
 
 static int prosavage_gpio_getscl(void* data)
 {
-	struct savagefb_i2c_chan *chan = (struct savagefb_i2c_chan *)data;
+	struct savagefb_i2c_chan *chan = data;
 
 	SET_CR_IX(chan->ioaddr, chan->reg);
 	return (0 != (GET_CR_DATA(chan->ioaddr) & PROSAVAGE_I2C_SCL_IN));
@@ -131,7 +131,7 @@
 
 static int prosavage_gpio_getsda(void* data)
 {
-	struct savagefb_i2c_chan *chan = (struct savagefb_i2c_chan *)data;
+	struct savagefb_i2c_chan *chan = data;
 
 	SET_CR_IX(chan->ioaddr, chan->reg);
 	return (0 != (GET_CR_DATA(chan->ioaddr) & PROSAVAGE_I2C_SDA_IN));
@@ -140,10 +140,9 @@
 static int savage_setup_i2c_bus(struct savagefb_i2c_chan *chan,
 				const char *name)
 {
-	int (*add_bus)(struct i2c_adapter *) = symbol_get(i2c_bit_add_bus);
 	int rc = 0;
 
-	if (add_bus && chan->par) {
+	if (chan->par) {
 		strcpy(chan->adapter.name, name);
 		chan->adapter.owner		= THIS_MODULE;
 		chan->adapter.id		= I2C_HW_B_SAVAGE;
@@ -161,7 +160,7 @@
 		chan->algo.setscl(chan, 1);
 		udelay(20);
 
-		rc = add_bus(&chan->adapter);
+		rc = i2c_bit_add_bus(&chan->adapter);
 
 		if (rc == 0)
 			dev_dbg(&chan->par->pcidev->dev,
@@ -169,8 +168,6 @@
 		else
 			dev_warn(&chan->par->pcidev->dev,
 				 "Failed to register I2C bus %s.\n", name);
-
-		symbol_put(i2c_bit_add_bus);
 	} else
 		chan->par = NULL;
 
@@ -179,7 +176,7 @@
 
 void savagefb_create_i2c_busses(struct fb_info *info)
 {
-	struct savagefb_par *par = (struct savagefb_par *)info->par;
+	struct savagefb_par *par = info->par;
 	par->chan.par	= par;
 
 	switch(info->fix.accel) {
@@ -193,6 +190,7 @@
 		par->chan.algo.getscl = prosavage_gpio_getscl;
 		break;
 	case FB_ACCEL_SAVAGE4:
+	case FB_ACCEL_SAVAGE2000:
 		par->chan.reg         = 0xff20;
 		par->chan.ioaddr      = par->mmio.vbase;
 		par->chan.algo.setsda = savage4_gpio_setsda;
@@ -209,14 +207,10 @@
 
 void savagefb_delete_i2c_busses(struct fb_info *info)
 {
-	struct savagefb_par *par = (struct savagefb_par *)info->par;
-	int (*del_bus)(struct i2c_adapter *) =
-		symbol_get(i2c_bit_del_bus);
+	struct savagefb_par *par = info->par;
 
-	if (del_bus && par->chan.par) {
-		del_bus(&par->chan.adapter);
-		symbol_put(i2c_bit_del_bus);
-	}
+	if (par->chan.par)
+		i2c_bit_del_bus(&par->chan.adapter);
 
 	par->chan.par = NULL;
 }
@@ -224,8 +218,6 @@
 static u8 *savage_do_probe_i2c_edid(struct savagefb_i2c_chan *chan)
 {
 	u8 start = 0x0;
-	int (*transfer)(struct i2c_adapter *, struct i2c_msg *, int) =
-		symbol_get(i2c_transfer);
 	struct i2c_msg msgs[] = {
 		{
 			.addr	= SAVAGE_DDC,
@@ -239,21 +231,19 @@
 	};
 	u8 *buf = NULL;
 
-	if (transfer && chan->par) {
+	if (chan->par) {
 		buf = kmalloc(EDID_LENGTH, GFP_KERNEL);
 
 		if (buf) {
 			msgs[1].buf = buf;
 
-			if (transfer(&chan->adapter, msgs, 2) != 2) {
+			if (i2c_transfer(&chan->adapter, msgs, 2) != 2) {
 				dev_dbg(&chan->par->pcidev->dev,
 					"Unable to read EDID block.\n");
 				kfree(buf);
 				buf = NULL;
 			}
 		}
-
-		symbol_put(i2c_transfer);
 	}
 
 	return buf;
diff --git a/drivers/video/savage/savagefb_accel.c b/drivers/video/savage/savagefb_accel.c
index bac8ea3..bbcc055 100644
--- a/drivers/video/savage/savagefb_accel.c
+++ b/drivers/video/savage/savagefb_accel.c
@@ -21,7 +21,7 @@
 
 int savagefb_sync(struct fb_info *info)
 {
-	struct savagefb_par *par = (struct savagefb_par *)info->par;
+	struct savagefb_par *par = info->par;
 
 	par->SavageWaitIdle(par);
 	return 0;
@@ -29,7 +29,7 @@
 
 void savagefb_copyarea(struct fb_info *info, const struct fb_copyarea *region)
 {
-	struct savagefb_par *par = (struct savagefb_par *)info->par;
+	struct savagefb_par *par = info->par;
 	int sx = region->sx, dx = region->dx;
 	int sy = region->sy, dy = region->dy;
 	int cmd;
@@ -63,7 +63,7 @@
 
 void savagefb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
 {
-	struct savagefb_par *par = (struct savagefb_par *)info->par;
+	struct savagefb_par *par = info->par;
 	int cmd, color;
 
 	if (!rect->width || !rect->height)
@@ -90,7 +90,7 @@
 
 void savagefb_imageblit(struct fb_info *info, const struct fb_image *image)
 {
-	struct savagefb_par *par = (struct savagefb_par *)info->par;
+	struct savagefb_par *par = info->par;
 	int fg, bg, size, i, width;
 	int cmd;
 	u32 *src = (u32 *) image->data;
diff --git a/drivers/video/savage/savagefb_driver.c b/drivers/video/savage/savagefb_driver.c
index 09e2f28..ab727ea 100644
--- a/drivers/video/savage/savagefb_driver.c
+++ b/drivers/video/savage/savagefb_driver.c
@@ -686,7 +686,7 @@
 static int savagefb_check_var (struct fb_var_screeninfo   *var,
 			       struct fb_info *info)
 {
-	struct savagefb_par *par = (struct savagefb_par *)info->par;
+	struct savagefb_par *par = info->par;
 	int memlen, vramlen, mode_valid = 0;
 
 	DBG("savagefb_check_var");
@@ -1025,7 +1025,7 @@
 			      unsigned        transp,
 			      struct fb_info *info)
 {
-	struct savagefb_par *par = (struct savagefb_par *)info->par;
+	struct savagefb_par *par = info->par;
 
 	if (regno >= NR_PALETTE)
 		return -EINVAL;
@@ -1328,7 +1328,7 @@
 #if defined(CONFIG_FB_SAVAGE_ACCEL)
 static void savagefb_set_clip(struct fb_info *info)
 {
-    struct savagefb_par *par = (struct savagefb_par *)info->par;
+    struct savagefb_par *par = info->par;
     int cmd;
 
     cmd = BCI_CMD_NOP | BCI_CMD_CLIP_NEW;
@@ -1342,7 +1342,7 @@
 
 static int savagefb_set_par (struct fb_info *info)
 {
-	struct savagefb_par *par = (struct savagefb_par *)info->par;
+	struct savagefb_par *par = info->par;
 	struct fb_var_screeninfo *var = &info->var;
 	int err;
 
@@ -1381,29 +1381,9 @@
 static int savagefb_pan_display (struct fb_var_screeninfo *var,
 				 struct fb_info           *info)
 {
-	struct savagefb_par *par = (struct savagefb_par *)info->par;
-	u_int y_bottom;
-
-	y_bottom = var->yoffset;
-
-	if (!(var->vmode & FB_VMODE_YWRAP))
-		y_bottom += var->yres;
-
-	if (var->xoffset > (var->xres_virtual - var->xres))
-		return -EINVAL;
-	if (y_bottom > info->var.yres_virtual)
-		return -EINVAL;
+	struct savagefb_par *par = info->par;
 
 	savagefb_update_start (par, var);
-
-	info->var.xoffset = var->xoffset;
-	info->var.yoffset = var->yoffset;
-
-	if (var->vmode & FB_VMODE_YWRAP)
-		info->var.vmode |= FB_VMODE_YWRAP;
-	else
-		info->var.vmode &= ~FB_VMODE_YWRAP;
-
 	return 0;
 }
 
@@ -1534,7 +1514,7 @@
 
 static int __devinit savage_map_mmio (struct fb_info *info)
 {
-	struct savagefb_par *par = (struct savagefb_par *)info->par;
+	struct savagefb_par *par = info->par;
 	DBG ("savage_map_mmio");
 
 	if (S3_SAVAGE3D_SERIES (par->chip))
@@ -1567,7 +1547,7 @@
 
 static void __devinit savage_unmap_mmio (struct fb_info *info)
 {
-	struct savagefb_par *par = (struct savagefb_par *)info->par;
+	struct savagefb_par *par = info->par;
 	DBG ("savage_unmap_mmio");
 
 	savage_disable_mmio(par);
@@ -1581,7 +1561,7 @@
 static int __devinit savage_map_video (struct fb_info *info,
 				       int video_len)
 {
-	struct savagefb_par *par = (struct savagefb_par *)info->par;
+	struct savagefb_par *par = info->par;
 	int resource;
 
 	DBG("savage_map_video");
@@ -1619,7 +1599,7 @@
 
 static void __devinit savage_unmap_video (struct fb_info *info)
 {
-	struct savagefb_par *par = (struct savagefb_par *)info->par;
+	struct savagefb_par *par = info->par;
 
 	DBG("savage_unmap_video");
 
@@ -1869,7 +1849,7 @@
 					  struct pci_dev *dev,
 					  const struct pci_device_id *id)
 {
-	struct savagefb_par *par = (struct savagefb_par *)info->par;
+	struct savagefb_par *par = info->par;
 	int err = 0;
 
 	par->pcidev  = dev;
@@ -2139,8 +2119,7 @@
 
 static void __devexit savagefb_remove (struct pci_dev *dev)
 {
-	struct fb_info *info =
-		(struct fb_info *)pci_get_drvdata(dev);
+	struct fb_info *info = pci_get_drvdata(dev);
 
 	DBG("savagefb_remove");
 
@@ -2174,9 +2153,8 @@
 
 static int savagefb_suspend (struct pci_dev* dev, pm_message_t state)
 {
-	struct fb_info *info =
-		(struct fb_info *)pci_get_drvdata(dev);
-	struct savagefb_par *par = (struct savagefb_par *)info->par;
+	struct fb_info *info = pci_get_drvdata(dev);
+	struct savagefb_par *par = info->par;
 
 	DBG("savagefb_suspend");
 
@@ -2210,9 +2188,8 @@
 
 static int savagefb_resume (struct pci_dev* dev)
 {
-	struct fb_info *info =
-		(struct fb_info *)pci_get_drvdata(dev);
-	struct savagefb_par *par = (struct savagefb_par *)info->par;
+	struct fb_info *info = pci_get_drvdata(dev);
+	struct savagefb_par *par = info->par;
 	int cur_state = par->pm_state;
 
 	DBG("savage_resume");
diff --git a/drivers/video/skeletonfb.c b/drivers/video/skeletonfb.c
index a01e7ecc..9b70777 100644
--- a/drivers/video/skeletonfb.c
+++ b/drivers/video/skeletonfb.c
@@ -115,7 +115,8 @@
     /*
      *  If your driver supports multiple boards or it supports multiple 
      *  framebuffers, you should make these arrays, or allocate them 
-     *  dynamically (using kmalloc()). 
+     *  dynamically using framebuffer_alloc() and free them with
+     *  framebuffer_release().
      */ 
 static struct fb_info info;
 
@@ -179,18 +180,31 @@
  *	intent to only test a mode and not actually set it. The stuff in 
  *	modedb.c is a example of this. If the var passed in is slightly 
  *	off by what the hardware can support then we alter the var PASSED in
- *	to what we can do. If the hardware doesn't support mode change 
- * 	a -EINVAL will be returned by the upper layers. You don't need to 
- *	implement this function then. If you hardware doesn't support 
- *	changing the resolution then this function is not needed. In this
- *	case the driver woudl just provide a var that represents the static
- *	state the screen is in.
+ *	to what we can do.
+ *
+ *      For values that are off, this function must round them _up_ to the
+ *      next value that is supported by the hardware.  If the value is
+ *      greater than the highest value supported by the hardware, then this
+ *      function must return -EINVAL.
+ *
+ *      Exception to the above rule:  Some drivers have a fixed mode, ie,
+ *      the hardware is already set at boot up, and cannot be changed.  In
+ *      this case, it is more acceptable that this function just return
+ *      a copy of the currently working var (info->var). Better is to not
+ *      implement this function, as the upper layer will do the copying
+ *      of the current var for you.
+ *
+ *      Note:  This is the only function where the contents of var can be
+ *      freely adjusted after the driver has been registered. If you find
+ *      that you have code outside of this function that alters the content
+ *      of var, then you are doing something wrong.  Note also that the
+ *      contents of info->var must be left untouched at all times after
+ *      driver registration.
  *
  *	Returns negative errno on error, or zero on success.
  */
 static int xxxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
 {
-    const struct xxx_par *par = (const struct xxx_par *) info->par;
     /* ... */
     return 0;	   	
 }
@@ -204,14 +218,39 @@
  *	fb_fix_screeninfo stored in fb_info. It doesn't not alter var in 
  *	fb_info since we are using that data. This means we depend on the
  *	data in var inside fb_info to be supported by the hardware. 
- *	xxxfb_check_var is always called before xxxfb_set_par to ensure this.
+ *
+ *      This function is also used to recover/restore the hardware to a
+ *      known working state.
+ *
+ *	xxxfb_check_var is always called before xxxfb_set_par to ensure that
+ *      the contents of var is always valid.
+ *
  *	Again if you can't change the resolution you don't need this function.
  *
+ *      However, even if your hardware does not support mode changing,
+ *      a set_par might be needed to at least initialize the hardware to
+ *      a known working state, especially if it came back from another
+ *      process that also modifies the same hardware, such as X.
+ *
+ *      If this is the case, a combination such as the following should work:
+ *
+ *      static int xxxfb_check_var(struct fb_var_screeninfo *var,
+ *                                struct fb_info *info)
+ *      {
+ *              *var = info->var;
+ *              return 0;
+ *      }
+ *
+ *      static int xxxfb_set_par(struct fb_info *info)
+ *      {
+ *              init your hardware here
+ *      }
+ *
  *	Returns negative errno on error, or zero on success.
  */
 static int xxxfb_set_par(struct fb_info *info)
 {
-    struct xxx_par *par = (struct xxx_par *) info->par;
+    struct xxx_par *par = info->par;
     /* ... */
     return 0;	
 }
@@ -258,70 +297,110 @@
      *   var->{color}.offset contains start of bitfield
      *   var->{color}.length contains length of bitfield
      *   {hardwarespecific} contains width of DAC
-     *   cmap[X] is programmed to (X << red.offset) | (X << green.offset) | (X << blue.offset)
+     *   pseudo_palette[X] is programmed to (X << red.offset) |
+     *                                      (X << green.offset) |
+     *                                      (X << blue.offset)
      *   RAMDAC[X] is programmed to (red, green, blue)
+     *   color depth = SUM(var->{color}.length)
      *
      * Pseudocolor:
-     *    uses offset = 0 && length = DAC register width.
      *    var->{color}.offset is 0
-     *    var->{color}.length contains widht of DAC
-     *    cmap is not used
-     *    DAC[X] is programmed to (red, green, blue)
+     *    var->{color}.length contains width of DAC or the number of unique
+     *                        colors available (color depth)
+     *    pseudo_palette is not used
+     *    RAMDAC[X] is programmed to (red, green, blue)
+     *    color depth = var->{color}.length
+     *
+     * Static pseudocolor:
+     *    same as Pseudocolor, but the RAMDAC is not programmed (read-only)
+     *
+     * Mono01/Mono10:
+     *    Has only 2 values, black on white or white on black (fg on bg),
+     *    var->{color}.offset is 0
+     *    white = (1 << var->{color}.length) - 1, black = 0
+     *    pseudo_palette is not used
+     *    RAMDAC does not exist
+     *    color depth is always 2
+     *
      * Truecolor:
      *    does not use RAMDAC (usually has 3 of them).
      *    var->{color}.offset contains start of bitfield
      *    var->{color}.length contains length of bitfield
-     *    cmap is programmed to (red << red.offset) | (green << green.offset) |
-     *                      (blue << blue.offset) | (transp << transp.offset)
+     *    pseudo_palette is programmed to (red << red.offset) |
+     *                                    (green << green.offset) |
+     *                                    (blue << blue.offset) |
+     *                                    (transp << transp.offset)
      *    RAMDAC does not exist
+     *    color depth = SUM(var->{color}.length})
+     *
+     *  The color depth is used by fbcon for choosing the logo and also
+     *  for color palette transformation if color depth < 4
+     *
+     *  As can be seen from the above, the field bits_per_pixel is _NOT_
+     *  a criteria for describing the color visual.
+     *
+     *  A common mistake is assuming that bits_per_pixel <= 8 is pseudocolor,
+     *  and higher than that, true/directcolor.  This is incorrect, one needs
+     *  to look at the fix->visual.
+     *
+     *  Another common mistake is using bits_per_pixel to calculate the color
+     *  depth.  The bits_per_pixel field does not directly translate to color
+     *  depth. You have to compute for the color depth (using the color
+     *  bitfields) and fix->visual as seen above.
+     */
+
+    /*
+     * This is the point where the color is converted to something that
+     * is acceptable by the hardware.
      */
 #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
-    switch (info->fix.visual) {
-       case FB_VISUAL_TRUECOLOR:
-       case FB_VISUAL_PSEUDOCOLOR:
-               red = CNVT_TOHW(red, info->var.red.length);
-               green = CNVT_TOHW(green, info->var.green.length);
-               blue = CNVT_TOHW(blue, info->var.blue.length);
-               transp = CNVT_TOHW(transp, info->var.transp.length);
-               break;
-       case FB_VISUAL_DIRECTCOLOR:
-	       /* example here assumes 8 bit DAC. Might be different 
-		* for your hardware */	
-               red = CNVT_TOHW(red, 8);       
-               green = CNVT_TOHW(green, 8);
-               blue = CNVT_TOHW(blue, 8);
-               /* hey, there is bug in transp handling... */
-               transp = CNVT_TOHW(transp, 8);
-               break;
-    }
+    red = CNVT_TOHW(red, info->var.red.length);
+    green = CNVT_TOHW(green, info->var.green.length);
+    blue = CNVT_TOHW(blue, info->var.blue.length);
+    transp = CNVT_TOHW(transp, info->var.transp.length);
 #undef CNVT_TOHW
-    /* Truecolor has hardware independent palette */
-    if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
-       u32 v;
+    /*
+     * This is the point where the function feeds the color to the hardware
+     * palette after converting the colors to something acceptable by
+     * the hardware. Note, only FB_VISUAL_DIRECTCOLOR and
+     * FB_VISUAL_PSEUDOCOLOR visuals need to write to the hardware palette.
+     * If you have code that writes to the hardware CLUT, and it's not
+     * any of the above visuals, then you are doing something wrong.
+     */
+    if (info->fix.visual == FB_VISUAL_DIRECTCOLOR ||
+	info->fix.visual == FB_VISUAL_TRUECOLOR)
+	    write_{red|green|blue|transp}_to_clut();
 
-       if (regno >= 16)
-           return -EINVAL;
+    /* This is the point were you need to fill up the contents of
+     * info->pseudo_palette. This structure is used _only_ by fbcon, thus
+     * it only contains 16 entries to match the number of colors supported
+     * by the console. The pseudo_palette is used only if the visual is
+     * in directcolor or truecolor mode.  With other visuals, the
+     * pseudo_palette is not used. (This might change in the future.)
+     *
+     * The contents of the pseudo_palette is in raw pixel format.  Ie, each
+     * entry can be written directly to the framebuffer without any conversion.
+     * The pseudo_palette is (void *).  However, if using the generic
+     * drawing functions (cfb_imageblit, cfb_fillrect), the pseudo_palette
+     * must be casted to (u32 *) _regardless_ of the bits per pixel. If the
+     * driver is using its own drawing functions, then it can use whatever
+     * size it wants.
+     */
+    if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
+	info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
+	    u32 v;
 
-       v = (red << info->var.red.offset) |
-           (green << info->var.green.offset) |
-           (blue << info->var.blue.offset) |
-           (transp << info->var.transp.offset);
+	    if (regno >= 16)
+		    return -EINVAL;
 
-       switch (info->var.bits_per_pixel) {
-		case 8:
-			/* Yes some hand held devices have this. */ 
-           		((u8*)(info->pseudo_palette))[regno] = v;
-			break;	
-   		case 16:
-           		((u16*)(info->pseudo_palette))[regno] = v;
-			break;
-		case 24:
-		case 32:	
-           		((u32*)(info->pseudo_palette))[regno] = v;
-			break;
-       }
-       return 0;
+	    v = (red << info->var.red.offset) |
+		    (green << info->var.green.offset) |
+		    (blue << info->var.blue.offset) |
+		    (transp << info->var.transp.offset);
+
+	    ((u32*)(info->pseudo_palette))[regno] = v;
     }
+
     /* ... */
     return 0;
 }
@@ -340,6 +419,17 @@
 static int xxxfb_pan_display(struct fb_var_screeninfo *var,
 			     const struct fb_info *info)
 {
+    /*
+     * If your hardware does not support panning, _do_ _not_ implement this
+     * function. Creating a dummy function will just confuse user apps.
+     */
+
+    /*
+     * Note that even if this function is fully functional, a setting of
+     * 0 in both xpanstep and ypanstep means that this function will never
+     * get called.
+     */
+
     /* ... */
     return 0;
 }
@@ -349,15 +439,20 @@
  *      @blank_mode: the blank mode we want. 
  *      @info: frame buffer structure that represents a single frame buffer
  *
- *      Blank the screen if blank_mode != 0, else unblank. Return 0 if
- *      blanking succeeded, != 0 if un-/blanking failed due to e.g. a 
- *      video mode which doesn't support it. Implements VESA suspend
- *      and powerdown modes on hardware that supports disabling hsync/vsync:
- *      blank_mode == 2: suspend vsync
- *      blank_mode == 3: suspend hsync
- *      blank_mode == 4: powerdown
+ *      Blank the screen if blank_mode != FB_BLANK_UNBLANK, else unblank.
+ *      Return 0 if blanking succeeded, != 0 if un-/blanking failed due to
+ *      e.g. a video mode which doesn't support it.
  *
- *      Returns negative errno on error, or zero on success.
+ *      Implements VESA suspend and powerdown modes on hardware that supports
+ *      disabling hsync/vsync:
+ *
+ *      FB_BLANK_NORMAL = display is blanked, syncs are on.
+ *      FB_BLANK_HSYNC_SUSPEND = hsync off
+ *      FB_BLANK_VSYNC_SUSPEND = vsync off
+ *      FB_BLANK_POWERDOWN =  hsync and vsync off
+ *
+ *      If implementing this function, at least support FB_BLANK_UNBLANK.
+ *      Return !0 for any modes that are unimplemented.
  *
  */
 static int xxxfb_blank(int blank_mode, const struct fb_info *info)
@@ -454,6 +549,14 @@
  *	@data: The actual data used to construct the image on the display.
  *	@cmap: The colormap used for color images.   
  */
+
+/*
+ * The generic function, cfb_imageblit, expects that the bitmap scanlines are
+ * padded to the next byte.  Most hardware accelerators may require padding to
+ * the next u16 or the next u32.  If that is the case, the driver can specify
+ * this by setting info->pixmap.scan_align = 2 or 4.  See a more
+ * comprehensive description of the pixmap below.
+ */
 }
 
 /**
@@ -517,6 +620,7 @@
  */
 void xxxfb_rotate(struct fb_info *info, int angle)
 {
+/* Will be deprecated */
 }
 
 /**
@@ -540,6 +644,9 @@
  *		     so we can have consistent display output. 
  *
  *      @info: frame buffer structure that represents a single frame buffer
+ *
+ *      If the driver has implemented its own hardware-based drawing function,
+ *      implementing this function is highly recommended.
  */
 void xxxfb_sync(struct fb_info *info)
 {
@@ -549,20 +656,25 @@
      *  Initialization
      */
 
-int __init xxxfb_init(void)
+/* static int __init xxfb_probe (struct device *device) -- for platform devs */
+static int __init xxxfb_probe(struct pci_dev *dev,
+			      const_struct pci_device_id *ent)
 {
+    struct fb_info *info;
+    struct xxx_par *par;
+    struct device = &dev->dev; /* for pci drivers */
     int cmap_len, retval;	
    
     /*
-     *  For kernel boot options (in 'video=xxxfb:<options>' format)
+     * Dynamically allocate info and par
      */
-#ifndef MODULE
-    char *option = NULL;
+    info = framebuffer_alloc(sizeof(struct xxx_par), device);
 
-    if (fb_get_options("xxxfb", &option))
-	    return -ENODEV;
-    xxxfb_setup(option);
-#endif
+    if (!info) {
+	    /* goto error path */
+    }
+
+    par = info->par;
 
     /* 
      * Here we set the screen_base to the virtual memory address
@@ -570,18 +682,87 @@
      * from the bus layer and then translate it to virtual memory
      * space via ioremap. Consult ioport.h. 
      */
-    info.screen_base = framebuffer_virtual_memory;	
-    info.fbops = &xxxfb_ops;
-    info.fix = xxxfb_fix;
-    info.pseudo_palette = pseudo_palette;
-
+    info->screen_base = framebuffer_virtual_memory;
+    info->fbops = &xxxfb_ops;
+    info->fix = xxxfb_fix; /* this will be the only time xxxfb_fix will be
+			    * used, so mark it as __initdata
+			    */
+    info->pseudo_palette = pseudo_palette; /* The pseudopalette is an
+					    * 16-member array
+					    */
     /*
      * Set up flags to indicate what sort of acceleration your
      * driver can provide (pan/wrap/copyarea/etc.) and whether it
      * is a module -- see FBINFO_* in include/linux/fb.h
+     *
+     * If your hardware can support any of the hardware accelerated functions
+     * fbcon performance will improve if info->flags is set properly.
+     *
+     * FBINFO_HWACCEL_COPYAREA - hardware moves
+     * FBINFO_HWACCEL_FILLRECT - hardware fills
+     * FBINFO_HWACCEL_IMAGEBLIT - hardware mono->color expansion
+     * FBINFO_HWACCEL_YPAN - hardware can pan display in y-axis
+     * FBINFO_HWACCEL_YWRAP - hardware can wrap display in y-axis
+     * FBINFO_HWACCEL_DISABLED - supports hardware accels, but disabled
+     * FBINFO_READS_FAST - if set, prefer moves over mono->color expansion
+     * FBINFO_MISC_TILEBLITTING - hardware can do tile blits
+     *
+     * NOTE: These are for fbcon use only.
      */
-    info.flags = FBINFO_DEFAULT;
-    info.par = current_par;
+    info->flags = FBINFO_DEFAULT;
+
+/********************* This stage is optional ******************************/
+     /*
+     * The struct pixmap is a scratch pad for the drawing functions. This
+     * is where the monochrome bitmap is constructed by the higher layers
+     * and then passed to the accelerator.  For drivers that uses
+     * cfb_imageblit, you can skip this part.  For those that have a more
+     * rigorous requirement, this stage is needed
+     */
+
+    /* PIXMAP_SIZE should be small enough to optimize drawing, but not
+     * large enough that memory is wasted.  A safe size is
+     * (max_xres * max_font_height/8). max_xres is driver dependent,
+     * max_font_height is 32.
+     */
+    info->pixmap.addr = kmalloc(PIXMAP_SIZE, GFP_KERNEL);
+    if (!info->pixmap.addr) {
+	    /* goto error */
+    }
+
+    info->pixmap.size = PIXMAP_SIZE;
+
+    /*
+     * FB_PIXMAP_SYSTEM - memory is in system ram
+     * FB_PIXMAP_IO     - memory is iomapped
+     * FB_PIXMAP_SYNC   - if set, will call fb_sync() per access to pixmap,
+     *                    usually if FB_PIXMAP_IO is set.
+     *
+     * Currently, FB_PIXMAP_IO is unimplemented.
+     */
+    info->pixmap.flags = FB_PIXMAP_SYSTEM;
+
+    /*
+     * scan_align is the number of padding for each scanline.  It is in bytes.
+     * Thus for accelerators that need padding to the next u32, put 4 here.
+     */
+    info->pixmap.scan_align = 4;
+
+    /*
+     * buf_align is the amount to be padded for the buffer. For example,
+     * the i810fb needs a scan_align of 2 but expects it to be fed with
+     * dwords, so a buf_align = 4 is required.
+     */
+    info->pixmap.buf_align = 4;
+
+    /* access_align is how many bits can be accessed from the framebuffer
+     * ie. some epson cards allow 16-bit access only.  Most drivers will
+     * be safe with u32 here.
+     *
+     * NOTE: This field is currently unused.
+     */
+    info->pixmap.scan_align = 32
+/***************************** End optional stage ***************************/
 
     /*
      * This should give a reasonable default video mode. The following is
@@ -590,43 +771,146 @@
     if (!mode_option)
 	mode_option = "640x480@60";	 	
 
-    retval = fb_find_mode(&info.var, &info, mode_option, NULL, 0, NULL, 8);
+    retval = fb_find_mode(info->var, info, mode_option, NULL, 0, NULL, 8);
   
     if (!retval || retval == 4)
 	return -EINVAL;			
 
     /* This has to been done !!! */	
-    fb_alloc_cmap(&info.cmap, cmap_len, 0);
+    fb_alloc_cmap(info->cmap, cmap_len, 0);
 	
     /* 
      * The following is done in the case of having hardware with a static 
      * mode. If we are setting the mode ourselves we don't call this. 
      */	
-    info.var = xxxfb_var;
-	
-    if (register_framebuffer(&info) < 0)
+    info->var = xxxfb_var;
+
+    /*
+     * For drivers that can...
+     */
+    xxxfb_check_var(&info->var, info);
+
+    /*
+     * Does a call to fb_set_par() before register_framebuffer needed?  This
+     * will depend on you and the hardware.  If you are sure that your driver
+     * is the only device in the system, a call to fb_set_par() is safe.
+     *
+     * Hardware in x86 systems has a VGA core.  Calling set_par() at this
+     * point will corrupt the VGA console, so it might be safer to skip a
+     * call to set_par here and just allow fbcon to do it for you.
+     */
+    /* xxxfb_set_par(info); */
+
+    if (register_framebuffer(info) < 0)
 	return -EINVAL;
-    printk(KERN_INFO "fb%d: %s frame buffer device\n", info.node,
-	   info.fix.id);
+    printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
+	   info->fix.id);
+    pci_set_drvdata(dev, info); /* or dev_set_drvdata(device, info) */
     return 0;
 }
 
     /*
      *  Cleanup
      */
-
-static void __exit xxxfb_cleanup(void)
+/* static void __exit xxxfb_remove(struct device *device) */
+static void __exit xxxfb_remove(struct pci_dev *dev)
 {
-    /*
-     *  If your driver supports multiple boards, you should unregister and
-     *  clean up all instances.
-     */
+	struct fb_info *info = pci_get_drv_data(dev);
+	/* or dev_get_drv_data(device); */
 
-    unregister_framebuffer(info);
-    fb_dealloc_cmap(&info.cmap);
-    /* ... */
+	if (info) {
+		unregister_framebuffer(info);
+		fb_dealloc_cmap(&info.cmap);
+		/* ... */
+		framebuffer_release(info);
+	}
+
+	return 0;
 }
 
+#if CONFIG_PCI
+/* For PCI drivers */
+static struct pci_driver xxxfb_driver = {
+	.name =		"xxxfb",
+	.id_table =	xxxfb_devices,
+	.probe =	xxxfb_probe,
+	.remove =	__devexit_p(xxxfb_remove),
+	.suspend =      xxxfb_suspend, /* optional */
+	.resume =       xxxfb_resume,  /* optional */
+};
+
+static int __init xxxfb_init(void)
+{
+	/*
+	 *  For kernel boot options (in 'video=xxxfb:<options>' format)
+	 */
+#ifndef MODULE
+	char *option = NULL;
+
+	if (fb_get_options("xxxfb", &option))
+		return -ENODEV;
+	xxxfb_setup(option);
+#endif
+
+	return pci_register_driver(&xxxfb_driver);
+}
+
+static void __exit xxxfb_exit(void)
+{
+	pci_unregister_driver(&xxxfb_driver);
+}
+#else
+#include <linux/platform_device.h>
+/* for platform devices */
+static struct device_driver xxxfb_driver = {
+	.name = "xxxfb",
+	.bus  = &platform_bus_type,
+	.probe = xxxfb_probe,
+	.remove = xxxfb_remove,
+	.suspend = xxxfb_suspend, /* optional */
+	.resume = xxxfb_resume,   /* optional */
+};
+
+static struct platform_device xxxfb_device = {
+	.name = "xxxfb",
+};
+
+static int __init xxxfb_init(void)
+{
+	int ret;
+	/*
+	 *  For kernel boot options (in 'video=xxxfb:<options>' format)
+	 */
+#ifndef MODULE
+	char *option = NULL;
+
+	if (fb_get_options("xxxfb", &option))
+		return -ENODEV;
+	xxxfb_setup(option);
+#endif
+	ret = driver_register(&xxxfb_driver);
+
+	if (!ret) {
+		ret = platform_device_register(&xxxfb_device);
+		if (ret)
+			driver_unregister(&xxxfb_driver);
+	}
+
+	return ret;
+}
+
+static void __exit xxxfb_exit(void)
+{
+	platform_device_unregister(&xxxfb_device);
+	driver_unregister(&xxxfb_driver);
+}
+#endif
+
+MODULE_LICENSE("GPL");
+module_init(xxxfb_init);
+module_exit(xxxfb_exit);
+
+
     /*
      *  Setup
      */
diff --git a/drivers/video/sstfb.c b/drivers/video/sstfb.c
index e0f14df..8a5ce21 100644
--- a/drivers/video/sstfb.c
+++ b/drivers/video/sstfb.c
@@ -382,7 +382,7 @@
 static int sstfb_check_var(struct fb_var_screeninfo *var,
 		struct fb_info *info)
 {
-	struct sstfb_par *par = (struct sstfb_par *) info->par;
+	struct sstfb_par *par = info->par;
 	int hSyncOff   = var->xres + var->right_margin + var->left_margin;
 	int vSyncOff   = var->yres + var->lower_margin + var->upper_margin;
 	int vBackPorch = var->left_margin, yDim = var->yres;
@@ -542,7 +542,7 @@
  */
 static int sstfb_set_par(struct fb_info *info)
 {
-	struct sstfb_par *par = (struct sstfb_par *) info->par;
+	struct sstfb_par *par = info->par;
 	u32 lfbmode, fbiinit1, fbiinit2, fbiinit3, fbiinit5, fbiinit6=0;
 	struct pci_dev *sst_dev = par->dev;
 	unsigned int freq;
@@ -748,13 +748,14 @@
 static int sstfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
                            u_int transp, struct fb_info *info)
 {
+	struct sstfb_par *par = info->par;
 	u32 col;
 
 	f_dddprintk("sstfb_setcolreg\n");
 	f_dddprintk("%-2d rgbt: %#x, %#x, %#x, %#x\n",
 	            regno, red, green, blue, transp);
-	if (regno >= 16)
-		return -EINVAL;
+	if (regno > 15)
+		return 0;
 
 	red    >>= (16 - info->var.red.length);
 	green  >>= (16 - info->var.green.length);
@@ -765,7 +766,7 @@
 	    | (blue  << info->var.blue.offset)
 	    | (transp << info->var.transp.offset);
 	
-	((u32 *)info->pseudo_palette)[regno] = col;
+	par->palette[regno] = col;
 
 	return 0;
 }
@@ -773,7 +774,7 @@
 static int sstfb_ioctl(struct inode *inode, struct file *file,
                        u_int cmd, u_long arg, struct fb_info *info )
 {
-	struct sstfb_par *par = (struct sstfb_par *) info->par;
+	struct sstfb_par *par = info->par;
 	struct pci_dev *sst_dev = par->dev;
 	u32 fbiinit0, tmp, val;
 	u_long p;
@@ -830,7 +831,7 @@
 #if 0
 static void sstfb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
 {
-	struct sstfb_par *par = (struct sstfb_par *) info->par;
+	struct sstfb_par *par = info->par;
 	u32 stride = info->fix.line_length;
    
 	if (!IS_VOODOO2(par))
@@ -855,7 +856,7 @@
  */
 static void sstfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect) 
 {
-	struct sstfb_par *par = (struct sstfb_par *) info->par;
+	struct sstfb_par *par = info->par;
 	u32 stride = info->fix.line_length;
 
 	if (!IS_VOODOO2(par))
@@ -925,7 +926,7 @@
 
 static int __devinit sst_detect_att(struct fb_info *info)
 {
-	struct sstfb_par *par = (struct sstfb_par *) info->par;
+	struct sstfb_par *par = info->par;
 	int i, mir, dir;
 
 	for (i=0; i<3; i++) {
@@ -950,7 +951,7 @@
 
 static int __devinit sst_detect_ti(struct fb_info *info)
 {
-	struct sstfb_par *par = (struct sstfb_par *) info->par;
+	struct sstfb_par *par = info->par;
 	int i, mir, dir;
 
 	for (i = 0; i<3; i++) {
@@ -986,7 +987,7 @@
  */
 static int __devinit sst_detect_ics(struct fb_info *info)
 {
-	struct sstfb_par *par = (struct sstfb_par *) info->par;
+	struct sstfb_par *par = info->par;
 	int m_clk0_1, m_clk0_7, m_clk1_b;
 	int n_clk0_1, n_clk0_7, n_clk1_b;
 	int i;
@@ -1023,7 +1024,7 @@
 static int sst_set_pll_att_ti(struct fb_info *info, 
 		const struct pll_timing *t, const int clock)
 {
-	struct sstfb_par *par = (struct sstfb_par *) info->par;
+	struct sstfb_par *par = info->par;
 	u8 cr0, cc;
 
 	/* enable indexed mode */
@@ -1077,7 +1078,7 @@
 static int sst_set_pll_ics(struct fb_info *info,
 		const struct pll_timing *t, const int clock)
 {
-	struct sstfb_par *par = (struct sstfb_par *) info->par;
+	struct sstfb_par *par = info->par;
 	u8 pll_ctrl;
 
 	sst_dac_write(DACREG_ICS_PLLRMA, DACREG_ICS_PLL_CTRL);
@@ -1114,7 +1115,7 @@
 
 static void sst_set_vidmod_att_ti(struct fb_info *info, const int bpp)
 {
-	struct sstfb_par *par = (struct sstfb_par *) info->par;
+	struct sstfb_par *par = info->par;
 	u8 cr0;
 
 	sst_dac_write(DACREG_WMA, 0); 	/* backdoor */
@@ -1149,7 +1150,7 @@
 
 static void sst_set_vidmod_ics(struct fb_info *info, const int bpp)
 {
-	struct sstfb_par *par = (struct sstfb_par *) info->par;
+	struct sstfb_par *par = info->par;
 
 	switch(bpp) {
 	case 16:
@@ -1308,7 +1309,7 @@
 
 static void  __devexit sst_shutdown(struct fb_info *info)
 {
-	struct sstfb_par *par = (struct sstfb_par *) info->par;
+	struct sstfb_par *par = info->par;
 	struct pci_dev *dev = par->dev;
 	struct pll_timing gfx_timings;
 	int Fout;
@@ -1394,12 +1395,6 @@
 	struct sst_spec *spec;
 	int err;
 
-	struct all_info {
-		struct fb_info info;
-		struct sstfb_par par;
-		u32 pseudo_palette[16];
-	} *all;
-	
 	/* Enable device in PCI config. */
 	if ((err=pci_enable_device(pdev))) {
 		eprintk("cannot enable device\n");
@@ -1407,14 +1402,13 @@
 	}
 
 	/* Allocate the fb and par structures.  */
-	all = kmalloc(sizeof(*all), GFP_KERNEL);
-	if (!all)
+	info = framebuffer_alloc(sizeof(struct sstfb_par), &pdev->dev);
+	if (!info)
 		return -ENOMEM;
-	memset(all, 0, sizeof(*all));
-	pci_set_drvdata(pdev, all);
+
+	pci_set_drvdata(pdev, info);
 	
-	info = &all->info;
-	par  = info->par = &all->par;
+	par  = info->par;
 	fix  = &info->fix;
 	
 	par->type = id->driver_data;
@@ -1471,7 +1465,7 @@
 
 	info->flags	= FBINFO_DEFAULT;
 	info->fbops	= &sstfb_ops;
-	info->pseudo_palette = &all->pseudo_palette;
+	info->pseudo_palette = par->palette;
 
 	fix->type	= FB_TYPE_PACKED_PIXELS;
 	fix->visual	= FB_VISUAL_TRUECOLOR;
@@ -1527,7 +1521,7 @@
 fail_fb_mem:
 	release_mem_region(fix->mmio_start, info->fix.mmio_len);
 fail_mmio_mem:
-	kfree(info);
+	framebuffer_release(info);
 	return -ENXIO; 	/* no voodoo detected */
 }
 
@@ -1537,7 +1531,7 @@
 	struct fb_info *info;
 
 	info = pci_get_drvdata(pdev);
-	par = (struct sstfb_par *) info->par;
+	par = info->par;
 	
 	sst_shutdown(info);
 	unregister_framebuffer(info);
@@ -1545,7 +1539,7 @@
 	iounmap(par->mmio_vbase);
 	release_mem_region(info->fix.smem_start, 0x400000);
 	release_mem_region(info->fix.mmio_start, info->fix.mmio_len);
-	kfree(info);
+	framebuffer_release(info);
 }
 
 
@@ -1613,7 +1607,7 @@
 
 	const int pci_s = sizeof(pci_regs)/sizeof(pci_regs[0]);
 	const int sst_s = sizeof(sst_regs)/sizeof(sst_regs[0]);
-	struct sstfb_par *par = (struct sstfb_par *) info->par;
+	struct sstfb_par *par = info->par;
 	struct pci_dev *dev = par->dev;
 	u32 pci_res[pci_s];
 	u32 sst_res[sst_s];
diff --git a/drivers/video/stifb.c b/drivers/video/stifb.c
index fbb1733..56d71d6 100644
--- a/drivers/video/stifb.c
+++ b/drivers/video/stifb.c
@@ -3,7 +3,7 @@
  * Low level Frame buffer driver for HP workstations with 
  * STI (standard text interface) video firmware.
  *
- * Copyright (C) 2001-2004 Helge Deller <deller@gmx.de>
+ * Copyright (C) 2001-2005 Helge Deller <deller@gmx.de>
  * Portions Copyright (C) 2001 Thomas Bogendoerfer <tsbogend@alpha.franken.de>
  * 
  * Based on:
@@ -73,16 +73,13 @@
 #include "sticore.h"
 
 /* REGION_BASE(fb_info, index) returns the virtual address for region <index> */
-#ifdef __LP64__
-  #define REGION_BASE(fb_info, index) \
-	(fb_info->sti->glob_cfg->region_ptrs[index] | 0xffffffff00000000)
-#else
-  #define REGION_BASE(fb_info, index) \
-	fb_info->sti->glob_cfg->region_ptrs[index]
-#endif
+#define REGION_BASE(fb_info, index) \
+	F_EXTEND(fb_info->sti->glob_cfg->region_ptrs[index])
 
 #define NGLEDEVDEPROM_CRT_REGION 1
 
+#define NR_PALETTE 256
+
 typedef struct {
 	__s32	video_config_reg;
 	__s32	misc_video_start;
@@ -112,7 +109,7 @@
 	ngle_rom_t ngle_rom;
 	struct sti_struct *sti;
 	int deviceSpecificConfig;
-	u32 pseudo_palette[256];
+	u32 pseudo_palette[16];
 };
 
 static int __initdata stifb_bpp_pref[MAX_STI_ROMS];
@@ -352,10 +349,10 @@
 #define IS_888_DEVICE(fb) \
 	(!(IS_24_DEVICE(fb)))
 
-#define GET_FIFO_SLOTS(fb, cnt, numslots)			\
-{	while (cnt < numslots) 					\
+#define GET_FIFO_SLOTS(fb, cnt, numslots)	\
+{	while (cnt < numslots) 			\
 		cnt = READ_WORD(fb, REG_34);	\
-	cnt -= numslots;					\
+	cnt -= numslots;			\
 }
 
 #define	    IndexedDcd	0	/* Pixel data is indexed (pseudo) color */
@@ -995,7 +992,7 @@
 	struct stifb_info *fb = (struct stifb_info *) info;
 	u32 color;
 
-	if (regno >= 256)  /* no. of hw registers */
+	if (regno >= NR_PALETTE)
 		return 1;
 
 	red   >>= 8;
@@ -1005,8 +1002,8 @@
 	DEBUG_OFF();
 
 	START_IMAGE_COLORMAP_ACCESS(fb);
-	
-	if (fb->info.var.grayscale) {
+
+	if (unlikely(fb->info.var.grayscale)) {
 		/* gray = 0.30*R + 0.59*G + 0.11*B */
 		color = ((red * 77) +
 			 (green * 151) +
@@ -1017,17 +1014,17 @@
 			 (blue));
 	}
 
-	if (info->var.bits_per_pixel == 32) {
-		((u32 *)(info->pseudo_palette))[regno] =
-			(red   << info->var.red.offset)   |
-			(green << info->var.green.offset) |
-			(blue  << info->var.blue.offset);
-	} else {
-		((u32 *)(info->pseudo_palette))[regno] = regno;
+	if (fb->info.fix.visual == FB_VISUAL_DIRECTCOLOR) {
+		struct fb_var_screeninfo *var = &fb->info.var;
+		if (regno < 16)
+			((u32 *)fb->info.pseudo_palette)[regno] =
+				regno << var->red.offset |
+				regno << var->green.offset |
+				regno << var->blue.offset;
 	}
 
 	WRITE_IMAGE_COLOR(fb, regno, color);
-	
+
 	if (fb->id == S9000_ID_HCRX) {
 		NgleLutBltCtl lutBltCtl;
 
@@ -1066,9 +1063,9 @@
 	case S9000_ID_HCRX:
 		HYPER_ENABLE_DISABLE_DISPLAY(fb, enable);
 		break;
-	case S9000_ID_A1659A:;	/* fall through */
-	case S9000_ID_TIMBER:;
-	case CRX24_OVERLAY_PLANES:;
+	case S9000_ID_A1659A:	/* fall through */
+	case S9000_ID_TIMBER:
+	case CRX24_OVERLAY_PLANES:
 	default:
 		ENABLE_DISABLE_DISPLAY(fb, enable);
 		break;
@@ -1250,12 +1247,10 @@
 		memset(&fb->ngle_rom, 0, sizeof(fb->ngle_rom));
 		if ((fb->sti->regions_phys[0] & 0xfc000000) ==
 		    (fb->sti->regions_phys[2] & 0xfc000000))
-			sti_rom_address = fb->sti->regions_phys[0];
+			sti_rom_address = F_EXTEND(fb->sti->regions_phys[0]);
 		else
-			sti_rom_address = fb->sti->regions_phys[1];
-#ifdef __LP64__
-	        sti_rom_address |= 0xffffffff00000000;
-#endif
+			sti_rom_address = F_EXTEND(fb->sti->regions_phys[1]);
+
 		fb->deviceSpecificConfig = gsc_readl(sti_rom_address);
 		if (IS_24_DEVICE(fb)) {
 			if (bpp_pref == 8 || bpp_pref == 32)
@@ -1315,7 +1310,7 @@
 		break;
 	    case 32:
 		fix->type = FB_TYPE_PACKED_PIXELS;
-		fix->visual = FB_VISUAL_TRUECOLOR;
+		fix->visual = FB_VISUAL_DIRECTCOLOR;
 		var->red.length = var->green.length = var->blue.length = var->transp.length = 8;
 		var->blue.offset = 0;
 		var->green.offset = 8;
@@ -1337,7 +1332,7 @@
 	info->pseudo_palette = &fb->pseudo_palette;
 
 	/* This has to been done !!! */
-	fb_alloc_cmap(&info->cmap, 256, 0);
+	fb_alloc_cmap(&info->cmap, NR_PALETTE, 0);
 	stifb_init_display(fb);
 
 	if (!request_mem_region(fix->smem_start, fix->smem_len, "stifb fb")) {
@@ -1488,7 +1483,3 @@
 MODULE_AUTHOR("Helge Deller <deller@gmx.de>, Thomas Bogendoerfer <tsbogend@alpha.franken.de>");
 MODULE_DESCRIPTION("Framebuffer driver for HP's NGLE series graphics cards in HP PARISC machines");
 MODULE_LICENSE("GPL v2");
-
-MODULE_PARM(bpp, "i");
-MODULE_PARM_DESC(mem, "Bits per pixel (default: 8)");
-
diff --git a/drivers/video/tdfxfb.c b/drivers/video/tdfxfb.c
index 9d53387..3e7baf4 100644
--- a/drivers/video/tdfxfb.c
+++ b/drivers/video/tdfxfb.c
@@ -291,7 +291,7 @@
  
 static int banshee_wait_idle(struct fb_info *info)
 {
-	struct tdfx_par *par = (struct tdfx_par *) info->par; 
+	struct tdfx_par *par = info->par;
 	int i = 0;
 
 	banshee_make_room(par, 1);
@@ -364,7 +364,7 @@
 
 static void do_write_regs(struct fb_info *info, struct banshee_reg* reg) 
 {
-	struct tdfx_par *par = (struct tdfx_par *) info->par; 
+	struct tdfx_par *par = info->par;
 	int i;
 
 	banshee_wait_idle(info);
@@ -469,7 +469,7 @@
 
 static int tdfxfb_check_var(struct fb_var_screeninfo *var,struct fb_info *info) 
 {
-	struct tdfx_par *par = (struct tdfx_par *) info->par; 
+	struct tdfx_par *par = info->par;
 	u32 lpitch;
 
 	if (var->bits_per_pixel != 8  && var->bits_per_pixel != 16 &&
@@ -558,7 +558,7 @@
 
 static int tdfxfb_set_par(struct fb_info *info)
 {
-	struct tdfx_par *par = (struct tdfx_par *) info->par;	
+	struct tdfx_par *par = info->par;
 	u32 hdispend, hsyncsta, hsyncend, htotal;
 	u32 hd, hs, he, ht, hbs, hbe;
 	u32 vd, vs, ve, vt, vbs, vbe;
@@ -780,7 +780,7 @@
 static int tdfxfb_setcolreg(unsigned regno, unsigned red, unsigned green,  
 			    unsigned blue,unsigned transp,struct fb_info *info) 
 {
-	struct tdfx_par *par = (struct tdfx_par *) info->par;
+	struct tdfx_par *par = info->par;
 	u32 rgbcol;
    
 	if (regno >= info->cmap.len || regno > 255) return 1;
@@ -794,11 +794,15 @@
 			break;
 		/* Truecolor has no hardware color palettes. */
 		case FB_VISUAL_TRUECOLOR:
-			rgbcol = (CNVT_TOHW( red, info->var.red.length) << info->var.red.offset) |
-				 (CNVT_TOHW( green, info->var.green.length) << info->var.green.offset) |
-				 (CNVT_TOHW( blue, info->var.blue.length) << info->var.blue.offset) |
-				 (CNVT_TOHW( transp, info->var.transp.length) << info->var.transp.offset);
-				((u32*)(info->pseudo_palette))[regno] = rgbcol;
+			rgbcol = (CNVT_TOHW( red, info->var.red.length) <<
+				  info->var.red.offset) |
+				 (CNVT_TOHW( green, info->var.green.length) <<
+				  info->var.green.offset) |
+				 (CNVT_TOHW( blue, info->var.blue.length) <<
+				  info->var.blue.offset) |
+				 (CNVT_TOHW( transp, info->var.transp.length) <<
+				  info->var.transp.offset);
+				par->palette[regno] = rgbcol;
 			break;
 		default:
 			DPRINTK("bad depth %u\n", info->var.bits_per_pixel);
@@ -810,7 +814,7 @@
 /* 0 unblank, 1 blank, 2 no vsync, 3 no hsync, 4 off */
 static int tdfxfb_blank(int blank, struct fb_info *info)
 { 
-	struct tdfx_par *par = (struct tdfx_par *) info->par;
+	struct tdfx_par *par = info->par;
 	u32 dacmode, state = 0, vgablank = 0;
 
 	dacmode = tdfx_inl(par, DACMODE);
@@ -855,7 +859,7 @@
 static int tdfxfb_pan_display(struct fb_var_screeninfo *var,
 			      struct fb_info *info) 
 {
-	struct tdfx_par *par = (struct tdfx_par *) info->par;
+	struct tdfx_par *par = info->par;
 	u32 addr;  	
 
 	if (nopan || var->xoffset || (var->yoffset > var->yres_virtual))
@@ -878,7 +882,7 @@
  */
 static void tdfxfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect) 
 {
-	struct tdfx_par *par = (struct tdfx_par *) info->par;
+	struct tdfx_par *par = info->par;
 	u32 bpp = info->var.bits_per_pixel;
 	u32 stride = info->fix.line_length;
 	u32 fmt= stride | ((bpp+((bpp==8) ? 0 : 8)) << 13); 
@@ -894,7 +898,7 @@
 	if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR) {
 		tdfx_outl(par,	COLORFORE, rect->color);
 	} else { /* FB_VISUAL_TRUECOLOR */
-		tdfx_outl(par, COLORFORE, ((u32*)(info->pseudo_palette))[rect->color]);
+		tdfx_outl(par, COLORFORE, par->palette[rect->color]);
 	}
 	tdfx_outl(par,	COMMAND_2D, COMMAND_2D_FILLRECT | (tdfx_rop << 24));
 	tdfx_outl(par,	DSTSIZE,    rect->width | (rect->height << 16));
@@ -906,7 +910,7 @@
  */
 static void tdfxfb_copyarea(struct fb_info *info, const struct fb_copyarea *area)  
 {
-	struct tdfx_par *par = (struct tdfx_par *) info->par;
+	struct tdfx_par *par = info->par;
    	u32 sx = area->sx, sy = area->sy, dx = area->dx, dy = area->dy;
 	u32 bpp = info->var.bits_per_pixel;
 	u32 stride = info->fix.line_length;
@@ -938,7 +942,7 @@
 
 static void tdfxfb_imageblit(struct fb_info *info, const struct fb_image *image) 
 {
-	struct tdfx_par *par = (struct tdfx_par *) info->par;
+	struct tdfx_par *par = info->par;
 	int size = image->height * ((image->width * image->depth + 7)>>3);
 	int fifo_free;
 	int i, stride = info->fix.line_length;
@@ -961,8 +965,10 @@
 				break;
 			case FB_VISUAL_TRUECOLOR:
 			default:
-				tdfx_outl(par, COLORFORE, ((u32*)(info->pseudo_palette))[image->fg_color]);
-				tdfx_outl(par, COLORBACK, ((u32*)(info->pseudo_palette))[image->bg_color]);
+				tdfx_outl(par, COLORFORE,
+					  par->palette[image->fg_color]);
+				tdfx_outl(par, COLORBACK,
+					  par->palette[image->bg_color]);
 		}
 #ifdef __BIG_ENDIAN
 		srcfmt = 0x400000 | BIT(20);
@@ -1007,7 +1013,7 @@
 #ifdef TDFX_HARDWARE_CURSOR
 static int tdfxfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
 {
-	struct tdfx_par *par = (struct tdfx_par *) info->par;
+	struct tdfx_par *par = info->par;
 	unsigned long flags;
 
 	/*
@@ -1157,18 +1163,17 @@
 {
 	struct tdfx_par *default_par;
 	struct fb_info *info;
-	int size, err, lpitch;
+	int err, lpitch;
 
 	if ((err = pci_enable_device(pdev))) {
 		printk(KERN_WARNING "tdfxfb: Can't enable pdev: %d\n", err);
 		return err;
 	}
 
-	size = sizeof(struct tdfx_par)+256*sizeof(u32);
+	info = framebuffer_alloc(sizeof(struct tdfx_par), &pdev->dev);
 
-	info = framebuffer_alloc(size, &pdev->dev);
-
-	if (!info)	return -ENOMEM;
+	if (!info)
+		return -ENOMEM;
 		
 	default_par = info->par;
  
@@ -1248,7 +1253,7 @@
    
 	info->fbops		= &tdfxfb_ops;
 	info->fix		= tdfx_fix; 	
-	info->pseudo_palette	= (void *)(default_par + 1); 
+	info->pseudo_palette	= default_par->palette;
 	info->flags		= FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
 #ifdef CONFIG_FB_3DFX_ACCEL
 	info->flags             |= FBINFO_HWACCEL_FILLRECT |
@@ -1307,7 +1312,7 @@
 }
 
 #ifndef MODULE
-void tdfxfb_setup(char *options)
+static void tdfxfb_setup(char *options)
 {
 	char* this_opt;
 
@@ -1340,7 +1345,7 @@
 static void __devexit tdfxfb_remove(struct pci_dev *pdev)
 {
 	struct fb_info *info = pci_get_drvdata(pdev);
-	struct tdfx_par *par = (struct tdfx_par *) info->par;
+	struct tdfx_par *par = info->par;
 
 	unregister_framebuffer(info);
 	iounmap(par->regbase_virt);
diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
index 3e58ddc..8982e54 100644
--- a/drivers/video/vesafb.c
+++ b/drivers/video/vesafb.c
@@ -57,7 +57,6 @@
 static void            (*pmi_start)(void);
 static void            (*pmi_pal)(void);
 static int             depth;
-static int             vga_compat;
 
 /* --------------------------------------------------------------------- */
 
@@ -67,15 +66,6 @@
 #ifdef __i386__
 	int offset;
 
-	if (!ypan)
-		return -EINVAL;
-	if (var->xoffset)
-		return -EINVAL;
-	if (var->yoffset > var->yres_virtual)
-		return -EINVAL;
-	if ((ypan==1) && var->yoffset+var->yres > var->yres_virtual)
-		return -EINVAL;
-
 	offset = (var->yoffset * info->fix.line_length + var->xoffset) / 4;
 
         __asm__ __volatile__(
@@ -90,37 +80,6 @@
 	return 0;
 }
 
-static int vesafb_blank(int blank, struct fb_info *info)
-{
-	int err = 1;
-
-	if (vga_compat) {
-		int loop = 10000;
-		u8 seq = 0, crtc17 = 0;
-
-		if (blank == FB_BLANK_POWERDOWN) {
-			seq = 0x20;
-			crtc17 = 0x00;
-			err = 0;
-		} else {
-			seq = 0x00;
-			crtc17 = 0x80;
-			err = (blank == FB_BLANK_UNBLANK) ? 0 : -EINVAL;
-		}
-
-		vga_wseq(NULL, 0x00, 0x01);
-		seq |= vga_rseq(NULL, 0x01) & ~0x20;
-		vga_wseq(NULL, 0x00, seq);
-
-		crtc17 |= vga_rcrt(NULL, 0x17) & ~0x80;
-		while (loop--);
-		vga_wcrt(NULL, 0x17, crtc17);
-		vga_wseq(NULL, 0x00, 0x03);
-	}
-
-	return err;
-}
-
 static void vesa_setpalette(int regno, unsigned red, unsigned green,
 			    unsigned blue)
 {
@@ -205,7 +164,6 @@
 	.owner		= THIS_MODULE,
 	.fb_setcolreg	= vesafb_setcolreg,
 	.fb_pan_display	= vesafb_pan_display,
-	.fb_blank       = vesafb_blank,
 	.fb_fillrect	= cfb_fillrect,
 	.fb_copyarea	= cfb_copyarea,
 	.fb_imageblit	= cfb_imageblit,
@@ -459,9 +417,8 @@
 	info->flags = FBINFO_FLAG_DEFAULT |
 		(ypan) ? FBINFO_HWACCEL_YPAN : 0;
 
-	vga_compat = (screen_info.capabilities & 2) ? 0 : 1;
-	printk("vesafb: Mode is %sVGA compatible\n",
-	       (vga_compat) ? "" : "not ");
+	if (!ypan)
+		info->fbops->fb_pan_display = NULL;
 
 	if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
 		err = -ENOMEM;
diff --git a/drivers/video/vga16fb.c b/drivers/video/vga16fb.c
index 226ae8a..f3f16fd 100644
--- a/drivers/video/vga16fb.c
+++ b/drivers/video/vga16fb.c
@@ -705,15 +705,7 @@
 static int vga16fb_pan_display(struct fb_var_screeninfo *var,
 			       struct fb_info *info) 
 {
-	if (var->xoffset + info->var.xres > info->var.xres_virtual ||
-	    var->yoffset + info->var.yres > info->var.yres_virtual)
-		return -EINVAL;
-
 	vga16fb_pan_var(info, var);
-
-	info->var.xoffset = var->xoffset;
-	info->var.yoffset = var->yoffset;
-	info->var.vmode &= ~FB_VMODE_YWRAP;
 	return 0;
 }
 
diff --git a/drivers/video/vgastate.c b/drivers/video/vgastate.c
index d9e01da..15179ec 100644
--- a/drivers/video/vgastate.c
+++ b/drivers/video/vgastate.c
@@ -356,10 +356,11 @@
 {
 	struct regstate *saved;
 
-	saved = kmalloc(sizeof(struct regstate), GFP_KERNEL);
+	saved = kzalloc(sizeof(struct regstate), GFP_KERNEL);
+
 	if (saved == NULL)
 		return 1;
-	memset (saved, 0, sizeof(struct regstate));
+
 	state->vidstate = (void *)saved;
 		
 	if (state->flags & VGA_SAVE_CMAP) {
diff --git a/drivers/zorro/proc.c b/drivers/zorro/proc.c
index 1a409c2..7aa2d3d 100644
--- a/drivers/zorro/proc.c
+++ b/drivers/zorro/proc.c
@@ -45,7 +45,7 @@
 }
 
 static ssize_t
-proc_bus_zorro_read(struct file *file, char *buf, size_t nbytes, loff_t *ppos)
+proc_bus_zorro_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
 {
 	struct inode *ino = file->f_dentry->d_inode;
 	struct proc_dir_entry *dp = PDE(ino);
diff --git a/fs/9p/vfs_super.c b/fs/9p/vfs_super.c
index ae0f06b..2c4fa75 100644
--- a/fs/9p/vfs_super.c
+++ b/fs/9p/vfs_super.c
@@ -91,7 +91,7 @@
 	sb->s_op = &v9fs_super_ops;
 
 	sb->s_flags = flags | MS_ACTIVE | MS_SYNCHRONOUS | MS_DIRSYNC |
-	    MS_NODIRATIME | MS_NOATIME;
+	    MS_NOATIME;
 }
 
 /**
diff --git a/fs/Kconfig b/fs/Kconfig
index 382e3b2..ef78e3a 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -798,7 +798,7 @@
 
 config PROC_VMCORE
         bool "/proc/vmcore support (EXPERIMENTAL)"
-        depends on PROC_FS && EMBEDDED && EXPERIMENTAL && CRASH_DUMP
+        depends on PROC_FS && EXPERIMENTAL && CRASH_DUMP
         help
         Exports the dump image of crashed kernel in ELF format.
 
diff --git a/fs/Makefile b/fs/Makefile
index 35e9aec..1db7113 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -14,7 +14,7 @@
 
 obj-$(CONFIG_INOTIFY)		+= inotify.o
 obj-$(CONFIG_EPOLL)		+= eventpoll.o
-obj-$(CONFIG_COMPAT)		+= compat.o
+obj-$(CONFIG_COMPAT)		+= compat.o compat_ioctl.o
 
 nfsd-$(CONFIG_NFSD)		:= nfsctl.o
 obj-y				+= $(nfsd-y) $(nfsd-m)
diff --git a/fs/afs/cmservice.c b/fs/afs/cmservice.c
index 0a57fd7..9eef6bf 100644
--- a/fs/afs/cmservice.c
+++ b/fs/afs/cmservice.c
@@ -118,7 +118,7 @@
 	_SRXAFSCM_xxxx_t func;
 	int die;
 
-	printk("kAFS: Started kafscmd %d\n", current->pid);
+	printk(KERN_INFO "kAFS: Started kafscmd %d\n", current->pid);
 
 	daemonize("kafscmd");
 
diff --git a/fs/attr.c b/fs/attr.c
index b347325..97de946 100644
--- a/fs/attr.c
+++ b/fs/attr.c
@@ -10,11 +10,11 @@
 #include <linux/mm.h>
 #include <linux/string.h>
 #include <linux/smp_lock.h>
+#include <linux/capability.h>
 #include <linux/fsnotify.h>
 #include <linux/fcntl.h>
 #include <linux/quotaops.h>
 #include <linux/security.h>
-#include <linux/time.h>
 
 /* Taken over from the old code... */
 
diff --git a/fs/autofs/root.c b/fs/autofs/root.c
index 808134a..870e2cf3 100644
--- a/fs/autofs/root.c
+++ b/fs/autofs/root.c
@@ -10,6 +10,7 @@
  *
  * ------------------------------------------------------------------------- */
 
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/stat.h>
 #include <linux/param.h>
diff --git a/fs/autofs4/root.c b/fs/autofs4/root.c
index 541b19e..e93a7ae 100644
--- a/fs/autofs4/root.c
+++ b/fs/autofs4/root.c
@@ -12,6 +12,7 @@
  *
  * ------------------------------------------------------------------------- */
 
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/stat.h>
 #include <linux/param.h>
@@ -86,7 +87,7 @@
 
 /* Update usage from here to top of tree, so that scan of
    top-level directories will give a useful result */
-static void autofs4_update_usage(struct dentry *dentry)
+static void autofs4_update_usage(struct vfsmount *mnt, struct dentry *dentry)
 {
 	struct dentry *top = dentry->d_sb->s_root;
 
@@ -95,7 +96,7 @@
 		struct autofs_info *ino = autofs4_dentry_ino(dentry);
 
 		if (ino) {
-			update_atime(dentry->d_inode);
+			touch_atime(mnt, dentry);
 			ino->last_used = jiffies;
 		}
 	}
@@ -289,10 +290,10 @@
 	return autofs4_dcache_readdir(file, dirent, filldir);
 }
 
-static int try_to_fill_dentry(struct dentry *dentry, 
-			      struct super_block *sb,
-			      struct autofs_sb_info *sbi, int flags)
+static int try_to_fill_dentry(struct vfsmount *mnt, struct dentry *dentry, int flags)
 {
+	struct super_block *sb = mnt->mnt_sb;
+	struct autofs_sb_info *sbi = autofs4_sbi(sb);
 	struct autofs_info *de_info = autofs4_dentry_ino(dentry);
 	int status = 0;
 
@@ -367,7 +368,7 @@
 	/* We don't update the usages for the autofs daemon itself, this
 	   is necessary for recursive autofs mounts */
 	if (!autofs4_oz_mode(sbi))
-		autofs4_update_usage(dentry);
+		autofs4_update_usage(mnt, dentry);
 
 	spin_lock(&dentry->d_lock);
 	dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
@@ -392,7 +393,7 @@
 	/* Pending dentry */
 	if (autofs4_ispending(dentry)) {
 		if (!oz_mode)
-			status = try_to_fill_dentry(dentry, dir->i_sb, sbi, flags);
+			status = try_to_fill_dentry(nd->mnt, dentry, flags);
 		return status;
 	}
 
@@ -409,14 +410,14 @@
 			 dentry, dentry->d_name.len, dentry->d_name.name);
 		spin_unlock(&dcache_lock);
 		if (!oz_mode)
-			status = try_to_fill_dentry(dentry, dir->i_sb, sbi, flags);
+			status = try_to_fill_dentry(nd->mnt, dentry, flags);
 		return status;
 	}
 	spin_unlock(&dcache_lock);
 
 	/* Update the usage list */
 	if (!oz_mode)
-		autofs4_update_usage(dentry);
+		autofs4_update_usage(nd->mnt, dentry);
 
 	return 1;
 }
diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
index 7201182..f312103 100644
--- a/fs/binfmt_aout.c
+++ b/fs/binfmt_aout.c
@@ -33,8 +33,6 @@
 static int load_aout_library(struct file*);
 static int aout_core_dump(long signr, struct pt_regs * regs, struct file *file);
 
-extern void dump_thread(struct pt_regs *, struct user *);
-
 static struct linux_binfmt aout_format = {
 	.module		= THIS_MODULE,
 	.load_binary	= load_aout_binary,
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 80ca932..f979ebb 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -622,7 +622,7 @@
 				goto out_free_file;
 
 			retval = -ENOMEM;
-			elf_interpreter = (char *) kmalloc(elf_ppnt->p_filesz,
+			elf_interpreter = kmalloc(elf_ppnt->p_filesz,
 							   GFP_KERNEL);
 			if (!elf_interpreter)
 				goto out_free_file;
@@ -1634,17 +1634,17 @@
 	ELF_CORE_WRITE_EXTRA_DATA;
 #endif
 
-	if ((off_t) file->f_pos != offset) {
+	if ((off_t)file->f_pos != offset) {
 		/* Sanity check */
-		printk("elf_core_dump: file->f_pos (%ld) != offset (%ld)\n",
-		       (off_t) file->f_pos, offset);
+		printk(KERN_WARNING "elf_core_dump: file->f_pos (%ld) != offset (%ld)\n",
+		       (off_t)file->f_pos, offset);
 	}
 
 end_coredump:
 	set_fs(fs);
 
 cleanup:
-	while(!list_empty(&thread_list)) {
+	while (!list_empty(&thread_list)) {
 		struct list_head *tmp = thread_list.next;
 		list_del(tmp);
 		kfree(list_entry(tmp, struct elf_thread_status, list));
diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index e0344f6..5b3076e 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -187,7 +187,7 @@
 				goto error;
 
 			/* read the name of the interpreter into memory */
-			interpreter_name = (char *) kmalloc(phdr->p_filesz, GFP_KERNEL);
+			interpreter_name = kmalloc(phdr->p_filesz, GFP_KERNEL);
 			if (!interpreter_name)
 				goto error;
 
diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
index 9d66258..108d56bb 100644
--- a/fs/binfmt_flat.c
+++ b/fs/binfmt_flat.c
@@ -77,8 +77,6 @@
 static int load_flat_binary(struct linux_binprm *, struct pt_regs * regs);
 static int flat_core_dump(long signr, struct pt_regs * regs, struct file *file);
 
-extern void dump_thread(struct pt_regs *, struct user *);
-
 static struct linux_binfmt flat_format = {
 	.module		= THIS_MODULE,
 	.load_binary	= load_flat_binary,
@@ -444,19 +442,22 @@
 	flags     = ntohl(hdr->flags);
 	rev       = ntohl(hdr->rev);
 
-	if (flags & FLAT_FLAG_KTRACE)
-		printk("BINFMT_FLAT: Loading file: %s\n", bprm->filename);
-
-	if (strncmp(hdr->magic, "bFLT", 4) ||
-			(rev != FLAT_VERSION && rev != OLD_FLAT_VERSION)) {
+	if (strncmp(hdr->magic, "bFLT", 4)) {
 		/*
 		 * because a lot of people do not manage to produce good
 		 * flat binaries,  we leave this printk to help them realise
 		 * the problem.  We only print the error if its not a script file
 		 */
 		if (strncmp(hdr->magic, "#!", 2))
-			printk("BINFMT_FLAT: bad magic/rev (0x%x, need 0x%x)\n",
-					rev, (int) FLAT_VERSION);
+			printk("BINFMT_FLAT: bad header magic\n");
+		return -ENOEXEC;
+	}
+
+	if (flags & FLAT_FLAG_KTRACE)
+		printk("BINFMT_FLAT: Loading file: %s\n", bprm->filename);
+
+	if (rev != FLAT_VERSION && rev != OLD_FLAT_VERSION) {
+		printk("BINFMT_FLAT: bad flat file version 0x%x (supported 0x%x and 0x%x)\n", rev, FLAT_VERSION, OLD_FLAT_VERSION);
 		return -ENOEXEC;
 	}
 	
diff --git a/fs/buffer.c b/fs/buffer.c
index 6466bc8a..b9bb7ad 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -26,6 +26,7 @@
 #include <linux/percpu.h>
 #include <linux/slab.h>
 #include <linux/smp_lock.h>
+#include <linux/capability.h>
 #include <linux/blkdev.h>
 #include <linux/file.h>
 #include <linux/quotaops.h>
diff --git a/fs/cifs/cifs_uniupr.h b/fs/cifs/cifs_uniupr.h
index decd138..da2ad5b 100644
--- a/fs/cifs/cifs_uniupr.h
+++ b/fs/cifs/cifs_uniupr.h
@@ -242,7 +242,7 @@
 /*
  * Lower Case Range
  */
-const static struct UniCaseRange CifsUniLowerRange[] = {
+static const struct UniCaseRange CifsUniLowerRange[] = {
 	0x0380, 0x03ab, UniCaseRangeL0380,
 	0x0400, 0x042f, UniCaseRangeL0400,
 	0x0490, 0x04cb, UniCaseRangeL0490,
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index 55d9a3a..5dd0207 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -10,11 +10,11 @@
  * ioctls.
  */
 
-#ifdef INCLUDES
 #include <linux/config.h>
 #include <linux/types.h>
 #include <linux/compat.h>
 #include <linux/kernel.h>
+#include <linux/capability.h>
 #include <linux/compiler.h>
 #include <linux/sched.h>
 #include <linux/smp.h>
@@ -81,13 +81,9 @@
 #include <linux/capi.h>
 
 #include <scsi/scsi.h>
-/* Ugly hack. */
-#undef __KERNEL__
 #include <scsi/scsi_ioctl.h>
-#define __KERNEL__
 #include <scsi/sg.h>
 
-#include <asm/types.h>
 #include <asm/uaccess.h>
 #include <linux/ethtool.h>
 #include <linux/mii.h>
@@ -95,7 +91,6 @@
 #include <linux/watchdog.h>
 #include <linux/dm-ioctl.h>
 
-#include <asm/module.h>
 #include <linux/soundcard.h>
 #include <linux/lp.h>
 #include <linux/ppdev.h>
@@ -127,11 +122,7 @@
 #include <linux/dvb/dmx.h>
 #include <linux/dvb/frontend.h>
 #include <linux/dvb/video.h>
-
-#undef INCLUDES
-#endif
-
-#ifdef CODE
+#include <linux/lp.h>
 
 /* Aiee. Someone does not find a difference between int and long */
 #define EXT2_IOC32_GETFLAGS               _IOR('f', 1, int)
@@ -148,6 +139,12 @@
 #define EXT2_IOC32_GETVERSION             _IOR('v', 1, int)
 #define EXT2_IOC32_SETVERSION             _IOW('v', 2, int)
 
+static int do_ioctl32_pointer(unsigned int fd, unsigned int cmd,
+			      unsigned long arg, struct file *f)
+{
+	return sys_ioctl(fd, cmd, (unsigned long)compat_ptr(arg));
+}
+
 static int w_long(unsigned int fd, unsigned int cmd, unsigned long arg)
 {
 	mm_segment_t old_fs = get_fs();
@@ -920,6 +917,40 @@
 	return err;
 }
 
+struct compat_sg_req_info { /* used by SG_GET_REQUEST_TABLE ioctl() */
+	char req_state;
+	char orphan;
+	char sg_io_owned;
+	char problem;
+	int pack_id;
+	compat_uptr_t usr_ptr;
+	unsigned int duration;
+	int unused;
+};
+
+static int sg_grt_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
+{
+	int err, i;
+	sg_req_info_t *r;
+	struct compat_sg_req_info *o = (struct compat_sg_req_info *)arg;
+	r = compat_alloc_user_space(sizeof(sg_req_info_t)*SG_MAX_QUEUE);
+	err = sys_ioctl(fd,cmd,(unsigned long)r);
+	if (err < 0)
+		return err;
+	for (i = 0; i < SG_MAX_QUEUE; i++) {
+		void __user *ptr;
+		int d;
+
+		if (copy_in_user(o + i, r + i, offsetof(sg_req_info_t, usr_ptr)) ||
+		    get_user(ptr, &r[i].usr_ptr) ||
+		    get_user(d, &r[i].duration) ||
+		    put_user((u32)(unsigned long)(ptr), &o[i].usr_ptr) ||
+		    put_user(d, &o[i].duration))
+			return -EFAULT;
+	}
+	return err;
+}
+
 struct sock_fprog32 {
 	unsigned short	len;
 	compat_caddr_t	filter;
@@ -2475,6 +2506,49 @@
 	return -EINVAL;
 }
 
+#define RTC_IRQP_READ32		_IOR('p', 0x0b, compat_ulong_t)
+#define RTC_IRQP_SET32		_IOW('p', 0x0c, compat_ulong_t)
+#define RTC_EPOCH_READ32	_IOR('p', 0x0d, compat_ulong_t)
+#define RTC_EPOCH_SET32		_IOW('p', 0x0e, compat_ulong_t)
+
+static int rtc_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
+{
+	mm_segment_t oldfs = get_fs();
+	compat_ulong_t val32;
+	unsigned long kval;
+	int ret;
+
+	switch (cmd) {
+	case RTC_IRQP_READ32:
+	case RTC_EPOCH_READ32:
+		set_fs(KERNEL_DS);
+		ret = sys_ioctl(fd, (cmd == RTC_IRQP_READ32) ?
+					RTC_IRQP_READ : RTC_EPOCH_READ,
+					(unsigned long)&kval);
+		set_fs(oldfs);
+		if (ret)
+			return ret;
+		val32 = kval;
+		return put_user(val32, (unsigned int __user *)arg);
+	case RTC_IRQP_SET32:
+	case RTC_EPOCH_SET32:
+		ret = get_user(val32, (unsigned int __user *)arg);
+		if (ret)
+			return ret;
+		kval = val32;
+
+		set_fs(KERNEL_DS);
+		ret = sys_ioctl(fd, (cmd == RTC_IRQP_SET32) ?
+				RTC_IRQP_SET : RTC_EPOCH_SET,
+				(unsigned long)&kval);
+		set_fs(oldfs);
+		return ret;
+	default:
+		/* unreached */
+		return -ENOIOCTLCMD;
+	}
+}
+
 #if defined(CONFIG_NCP_FS) || defined(CONFIG_NCP_FS_MODULE)
 struct ncp_ioctl_request_32 {
 	u32 function;
@@ -2662,10 +2736,34 @@
 }
 #endif
 
-#undef CODE
-#endif
+static int
+lp_timeout_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
+{
+	struct compat_timeval *tc = (struct compat_timeval *)arg;
+	struct timeval *tn = compat_alloc_user_space(sizeof(struct timeval));
+	struct timeval ts;
+	if (get_user(ts.tv_sec, &tc->tv_sec) ||
+	    get_user(ts.tv_usec, &tc->tv_usec) ||
+	    put_user(ts.tv_sec, &tn->tv_sec) ||
+	    put_user(ts.tv_usec, &tn->tv_usec))
+		return -EFAULT;
+	return sys_ioctl(fd, cmd, (unsigned long)tn);
+}
 
-#ifdef DECLARES
+#define HANDLE_IOCTL(cmd,handler) \
+	{ (cmd), (ioctl_trans_handler_t)(handler) },
+
+/* pointer to compatible structure or no argument */
+#define COMPATIBLE_IOCTL(cmd) \
+	{ (cmd), do_ioctl32_pointer },
+
+/* argument is an unsigned long integer, not a pointer */
+#define ULONG_IOCTL(cmd) \
+	{ (cmd), (ioctl_trans_handler_t)sys_ioctl },
+
+
+struct ioctl_trans ioctl_start[] = {
+#include <linux/compat_ioctl.h>
 HANDLE_IOCTL(MEMREADOOB32, mtd_rw_oob)
 HANDLE_IOCTL(MEMWRITEOOB32, mtd_rw_oob)
 #ifdef CONFIG_NET
@@ -2745,6 +2843,7 @@
 HANDLE_IOCTL(FDGETFDCSTAT32, fd_ioctl_trans)
 HANDLE_IOCTL(FDWERRORGET32, fd_ioctl_trans)
 HANDLE_IOCTL(SG_IO,sg_ioctl_trans)
+HANDLE_IOCTL(SG_GET_REQUEST_TABLE, sg_grt_trans)
 HANDLE_IOCTL(PPPIOCGIDLE32, ppp_ioctl_trans)
 HANDLE_IOCTL(PPPIOCSCOMPRESS32, ppp_ioctl_trans)
 HANDLE_IOCTL(PPPIOCSPASS32, ppp_sock_fprog_ioctl_trans)
@@ -2858,6 +2957,10 @@
 HANDLE_IOCTL(SIOCGIWENCODE, do_wireless_ioctl)
 HANDLE_IOCTL(SIOCSIFBR, old_bridge_ioctl)
 HANDLE_IOCTL(SIOCGIFBR, old_bridge_ioctl)
+HANDLE_IOCTL(RTC_IRQP_READ32, rtc_ioctl)
+HANDLE_IOCTL(RTC_IRQP_SET32, rtc_ioctl)
+HANDLE_IOCTL(RTC_EPOCH_READ32, rtc_ioctl)
+HANDLE_IOCTL(RTC_EPOCH_SET32, rtc_ioctl)
 
 #if defined(CONFIG_NCP_FS) || defined(CONFIG_NCP_FS_MODULE)
 HANDLE_IOCTL(NCP_IOC_NCPREQUEST_32, do_ncp_ncprequest)
@@ -2875,5 +2978,19 @@
 HANDLE_IOCTL(VIDEO_STILLPICTURE, do_video_stillpicture)
 HANDLE_IOCTL(VIDEO_SET_SPU_PALETTE, do_video_set_spu_palette)
 
-#undef DECLARES
-#endif
+/* parport */
+COMPATIBLE_IOCTL(LPTIME)
+COMPATIBLE_IOCTL(LPCHAR)
+COMPATIBLE_IOCTL(LPABORTOPEN)
+COMPATIBLE_IOCTL(LPCAREFUL)
+COMPATIBLE_IOCTL(LPWAIT)
+COMPATIBLE_IOCTL(LPSETIRQ)
+COMPATIBLE_IOCTL(LPGETSTATUS)
+COMPATIBLE_IOCTL(LPGETSTATUS)
+COMPATIBLE_IOCTL(LPRESET)
+/*LPGETSTATS not implemented, but no kernels seem to compile it in anyways*/
+COMPATIBLE_IOCTL(LPGETFLAGS)
+HANDLE_IOCTL(LPSETTIMEOUT, lp_timeout_trans)
+};
+
+int ioctl_table_size = ARRAY_SIZE(ioctl_start);
diff --git a/fs/dcache.c b/fs/dcache.c
index 1536f15..134d677 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -808,10 +808,14 @@
  *
  * Fill in inode information in the entry. On success, it returns NULL.
  * If an unhashed alias of "entry" already exists, then we return the
- * aliased dentry instead.
+ * aliased dentry instead and drop one reference to inode.
  *
  * Note that in order to avoid conflicts with rename() etc, the caller
  * had better be holding the parent directory semaphore.
+ *
+ * This also assumes that the inode count has been incremented
+ * (or otherwise set) by the caller to indicate that it is now
+ * in use by the dcache.
  */
 struct dentry *d_instantiate_unique(struct dentry *entry, struct inode *inode)
 {
@@ -838,6 +842,7 @@
 		dget_locked(alias);
 		spin_unlock(&dcache_lock);
 		BUG_ON(!d_unhashed(alias));
+		iput(inode);
 		return alias;
 	}
 	list_add(&entry->d_alias, &inode->i_dentry);
diff --git a/fs/dcookies.c b/fs/dcookies.c
index 02aa0dd..f8274a8 100644
--- a/fs/dcookies.c
+++ b/fs/dcookies.c
@@ -18,6 +18,7 @@
 #include <linux/slab.h>
 #include <linux/list.h>
 #include <linux/mount.h>
+#include <linux/capability.h>
 #include <linux/dcache.h>
 #include <linux/mm.h>
 #include <linux/errno.h>
diff --git a/fs/dquot.c b/fs/dquot.c
index cb6d5bf..1966c89 100644
--- a/fs/dquot.c
+++ b/fs/dquot.c
@@ -77,6 +77,7 @@
 #include <linux/kmod.h>
 #include <linux/namei.h>
 #include <linux/buffer_head.h>
+#include <linux/capability.h>
 #include <linux/quotaops.h>
 
 #include <asm/uaccess.h>
diff --git a/fs/exec.c b/fs/exec.c
index fd02ea4a..b5bcf1a 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -632,10 +632,10 @@
 		 * synchronize with any firing (by calling del_timer_sync)
 		 * before we can safely let the old group leader die.
 		 */
-		sig->real_timer.data = (unsigned long)current;
+		sig->real_timer.data = current;
 		spin_unlock_irq(lock);
-		if (del_timer_sync(&sig->real_timer))
-			add_timer(&sig->real_timer);
+		if (hrtimer_cancel(&sig->real_timer))
+			hrtimer_restart(&sig->real_timer);
 		spin_lock_irq(lock);
 	}
 	while (atomic_read(&sig->count) > count) {
diff --git a/fs/ext2/acl.c b/fs/ext2/acl.c
index 239133d..35acc43 100644
--- a/fs/ext2/acl.c
+++ b/fs/ext2/acl.c
@@ -4,6 +4,7 @@
  * Copyright (C) 2001-2003 Andreas Gruenbacher, <agruen@suse.de>
  */
 
+#include <linux/capability.h>
 #include <linux/init.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
index bb69080..2c00953 100644
--- a/fs/ext2/balloc.c
+++ b/fs/ext2/balloc.c
@@ -16,6 +16,7 @@
 #include <linux/quotaops.h>
 #include <linux/sched.h>
 #include <linux/buffer_head.h>
+#include <linux/capability.h>
 
 /*
  * balloc.c contains the blocks allocation and deallocation routines
diff --git a/fs/ext2/bitmap.c b/fs/ext2/bitmap.c
index 20145b7..e9983a0 100644
--- a/fs/ext2/bitmap.c
+++ b/fs/ext2/bitmap.c
@@ -7,8 +7,12 @@
  * Universite Pierre et Marie Curie (Paris VI)
  */
 
+#ifdef EXT2FS_DEBUG
+
 #include <linux/buffer_head.h>
 
+#include "ext2.h"
+
 static int nibblemap[] = {4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0};
 
 unsigned long ext2_count_free (struct buffer_head * map, unsigned int numchars)
@@ -23,3 +27,6 @@
 			nibblemap[(map->b_data[i] >> 4) & 0xf];
 	return (sum);
 }
+
+#endif  /*  EXT2FS_DEBUG  */
+
diff --git a/fs/ext2/dir.c b/fs/ext2/dir.c
index 5b5f528..7442bdd 100644
--- a/fs/ext2/dir.c
+++ b/fs/ext2/dir.c
@@ -592,7 +592,7 @@
 		goto fail;
 	}
 	kaddr = kmap_atomic(page, KM_USER0);
-       memset(kaddr, 0, chunk_size);
+	memset(kaddr, 0, chunk_size);
 	de = (struct ext2_dir_entry_2 *)kaddr;
 	de->name_len = 1;
 	de->rec_len = cpu_to_le16(EXT2_DIR_REC_LEN(1));
diff --git a/fs/ext2/ioctl.c b/fs/ext2/ioctl.c
index 709d867..3ca9afd 100644
--- a/fs/ext2/ioctl.c
+++ b/fs/ext2/ioctl.c
@@ -8,6 +8,7 @@
  */
 
 #include "ext2.h"
+#include <linux/capability.h>
 #include <linux/time.h>
 #include <linux/sched.h>
 #include <asm/current.h>
diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
index f7a3b5f..a2ca310 100644
--- a/fs/ext2/xattr.c
+++ b/fs/ext2/xattr.c
@@ -389,10 +389,6 @@
 	ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld",
 		  name_index, name, value, (long)value_len);
 
-	if (IS_RDONLY(inode))
-		return -EROFS;
-	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
-		return -EPERM;
 	if (value == NULL)
 		value_len = 0;
 	if (name == NULL)
diff --git a/fs/ext2/xattr_trusted.c b/fs/ext2/xattr_trusted.c
index 52b30ee..f28a6a4 100644
--- a/fs/ext2/xattr_trusted.c
+++ b/fs/ext2/xattr_trusted.c
@@ -7,6 +7,7 @@
 
 #include <linux/module.h>
 #include <linux/string.h>
+#include <linux/capability.h>
 #include <linux/fs.h>
 #include <linux/smp_lock.h>
 #include <linux/ext2_fs.h>
@@ -38,8 +39,6 @@
 {
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
-	if (!capable(CAP_SYS_ADMIN))
-		return -EPERM;
 	return ext2_xattr_get(inode, EXT2_XATTR_INDEX_TRUSTED, name,
 			      buffer, size);
 }
@@ -50,8 +49,6 @@
 {
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
-	if (!capable(CAP_SYS_ADMIN))
-		return -EPERM;
 	return ext2_xattr_set(inode, EXT2_XATTR_INDEX_TRUSTED, name,
 			      value, size, flags);
 }
diff --git a/fs/ext2/xattr_user.c b/fs/ext2/xattr_user.c
index 0c03ea1..f383e7c 100644
--- a/fs/ext2/xattr_user.c
+++ b/fs/ext2/xattr_user.c
@@ -35,16 +35,10 @@
 ext2_xattr_user_get(struct inode *inode, const char *name,
 		    void *buffer, size_t size)
 {
-	int error;
-
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
 	if (!test_opt(inode->i_sb, XATTR_USER))
 		return -EOPNOTSUPP;
-	error = permission(inode, MAY_READ, NULL);
-	if (error)
-		return error;
-
 	return ext2_xattr_get(inode, EXT2_XATTR_INDEX_USER, name, buffer, size);
 }
 
@@ -52,18 +46,10 @@
 ext2_xattr_user_set(struct inode *inode, const char *name,
 		    const void *value, size_t size, int flags)
 {
-	int error;
-
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
 	if (!test_opt(inode->i_sb, XATTR_USER))
 		return -EOPNOTSUPP;
-	if ( !S_ISREG(inode->i_mode) &&
-	    (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
-		return -EPERM;
-	error = permission(inode, MAY_WRITE, NULL);
-	if (error)
-		return error;
 
 	return ext2_xattr_set(inode, EXT2_XATTR_INDEX_USER, name,
 			      value, size, flags);
diff --git a/fs/ext3/acl.c b/fs/ext3/acl.c
index 9ed132c..47a9da2 100644
--- a/fs/ext3/acl.c
+++ b/fs/ext3/acl.c
@@ -7,6 +7,7 @@
 #include <linux/init.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
+#include <linux/capability.h>
 #include <linux/fs.h>
 #include <linux/ext3_jbd.h>
 #include <linux/ext3_fs.h>
diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
index ae1148c..6250fcd 100644
--- a/fs/ext3/balloc.c
+++ b/fs/ext3/balloc.c
@@ -13,6 +13,7 @@
 
 #include <linux/config.h>
 #include <linux/time.h>
+#include <linux/capability.h>
 #include <linux/fs.h>
 #include <linux/jbd.h>
 #include <linux/ext3_fs.h>
@@ -20,8 +21,6 @@
 #include <linux/quotaops.h>
 #include <linux/buffer_head.h>
 
-#include "bitmap.h"
-
 /*
  * balloc.c contains the blocks allocation and deallocation routines
  */
diff --git a/fs/ext3/bitmap.c b/fs/ext3/bitmap.c
index 5b4ba3e..cb16b4c 100644
--- a/fs/ext3/bitmap.c
+++ b/fs/ext3/bitmap.c
@@ -7,8 +7,11 @@
  * Universite Pierre et Marie Curie (Paris VI)
  */
 
+#ifdef EXT3FS_DEBUG
+
 #include <linux/buffer_head.h>
-#include "bitmap.h"
+
+#include "ext3_fs.h"
 
 static int nibblemap[] = {4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0};
 
@@ -24,3 +27,6 @@
 			nibblemap[(map->b_data[i] >> 4) & 0xf];
 	return (sum);
 }
+
+#endif  /*  EXT3FS_DEBUG  */
+
diff --git a/fs/ext3/bitmap.h b/fs/ext3/bitmap.h
deleted file mode 100644
index 6ee503a..0000000
--- a/fs/ext3/bitmap.h
+++ /dev/null
@@ -1,8 +0,0 @@
-/*  linux/fs/ext3/bitmap.c
- *
- * Copyright (C) 2005 Simtec Electronics
- *	Ben Dooks <ben@simtec.co.uk>
- *
-*/
-
-extern unsigned long ext3_count_free (struct buffer_head *, unsigned int );
diff --git a/fs/ext3/ialloc.c b/fs/ext3/ialloc.c
index 6907807..dc82646 100644
--- a/fs/ext3/ialloc.c
+++ b/fs/ext3/ialloc.c
@@ -26,7 +26,6 @@
 
 #include <asm/byteorder.h>
 
-#include "bitmap.h"
 #include "xattr.h"
 #include "acl.h"
 
diff --git a/fs/ext3/ioctl.c b/fs/ext3/ioctl.c
index 706d686..556cd55 100644
--- a/fs/ext3/ioctl.c
+++ b/fs/ext3/ioctl.c
@@ -9,6 +9,7 @@
 
 #include <linux/fs.h>
 #include <linux/jbd.h>
+#include <linux/capability.h>
 #include <linux/ext3_fs.h>
 #include <linux/ext3_jbd.h>
 #include <linux/time.h>
diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
index 238199d..e8d60bf 100644
--- a/fs/ext3/xattr.c
+++ b/fs/ext3/xattr.c
@@ -946,10 +946,6 @@
 	};
 	int error;
 
-	if (IS_RDONLY(inode))
-		return -EROFS;
-	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
-		return -EPERM;
 	if (!name)
 		return -EINVAL;
 	if (strlen(name) > 255)
diff --git a/fs/ext3/xattr_trusted.c b/fs/ext3/xattr_trusted.c
index f68bfd1..86d91f1 100644
--- a/fs/ext3/xattr_trusted.c
+++ b/fs/ext3/xattr_trusted.c
@@ -7,6 +7,7 @@
 
 #include <linux/module.h>
 #include <linux/string.h>
+#include <linux/capability.h>
 #include <linux/fs.h>
 #include <linux/smp_lock.h>
 #include <linux/ext3_jbd.h>
@@ -39,8 +40,6 @@
 {
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
-	if (!capable(CAP_SYS_ADMIN))
-		return -EPERM;
 	return ext3_xattr_get(inode, EXT3_XATTR_INDEX_TRUSTED, name,
 			      buffer, size);
 }
@@ -51,8 +50,6 @@
 {
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
-	if (!capable(CAP_SYS_ADMIN))
-		return -EPERM;
 	return ext3_xattr_set(inode, EXT3_XATTR_INDEX_TRUSTED, name,
 			      value, size, flags);
 }
diff --git a/fs/ext3/xattr_user.c b/fs/ext3/xattr_user.c
index e907cae..a85a0a1 100644
--- a/fs/ext3/xattr_user.c
+++ b/fs/ext3/xattr_user.c
@@ -37,16 +37,10 @@
 ext3_xattr_user_get(struct inode *inode, const char *name,
 		    void *buffer, size_t size)
 {
-	int error;
-
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
 	if (!test_opt(inode->i_sb, XATTR_USER))
 		return -EOPNOTSUPP;
-	error = permission(inode, MAY_READ, NULL);
-	if (error)
-		return error;
-
 	return ext3_xattr_get(inode, EXT3_XATTR_INDEX_USER, name, buffer, size);
 }
 
@@ -54,19 +48,10 @@
 ext3_xattr_user_set(struct inode *inode, const char *name,
 		    const void *value, size_t size, int flags)
 {
-	int error;
-
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
 	if (!test_opt(inode->i_sb, XATTR_USER))
 		return -EOPNOTSUPP;
-	if ( !S_ISREG(inode->i_mode) &&
-	    (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
-		return -EPERM;
-	error = permission(inode, MAY_WRITE, NULL);
-	if (error)
-		return error;
-
 	return ext3_xattr_set(inode, EXT3_XATTR_INDEX_USER, name,
 			      value, size, flags);
 }
diff --git a/fs/fat/file.c b/fs/fat/file.c
index d30876c..e99c5a7 100644
--- a/fs/fat/file.c
+++ b/fs/fat/file.c
@@ -6,6 +6,7 @@
  *  regular file handling primitives for fat-based filesystems
  */
 
+#include <linux/capability.h>
 #include <linux/module.h>
 #include <linux/time.h>
 #include <linux/msdos_fs.h>
diff --git a/fs/fcntl.c b/fs/fcntl.c
index 9903bde..d0767fe 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -9,6 +9,7 @@
 #include <linux/mm.h>
 #include <linux/fs.h>
 #include <linux/file.h>
+#include <linux/capability.h>
 #include <linux/dnotify.h>
 #include <linux/smp_lock.h>
 #include <linux/slab.h>
diff --git a/fs/file_table.c b/fs/file_table.c
index 6142250..768b581 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -16,6 +16,7 @@
 #include <linux/eventpoll.h>
 #include <linux/rcupdate.h>
 #include <linux/mount.h>
+#include <linux/capability.h>
 #include <linux/cdev.h>
 #include <linux/fsnotify.h>
 
diff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h
index df16fcb..0fa1ab6 100644
--- a/fs/hfsplus/hfsplus_fs.h
+++ b/fs/hfsplus/hfsplus_fs.h
@@ -143,9 +143,6 @@
 
 	unsigned long flags;
 
-	atomic_t inode_cnt;
-	u32 last_inode_cnt;
-
 	struct hlist_head rsrc_inodes;
 };
 
diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
index 983bcd0..7acff6c 100644
--- a/fs/hfsplus/inode.c
+++ b/fs/hfsplus/inode.c
@@ -182,11 +182,6 @@
 	igrab(dir);
 	hlist_add_head(&inode->i_hash, &HFSPLUS_SB(sb).rsrc_inodes);
 	mark_inode_dirty(inode);
-	{
-	void hfsplus_inode_check(struct super_block *sb);
-	atomic_inc(&HFSPLUS_SB(sb).inode_cnt);
-	hfsplus_inode_check(sb);
-	}
 out:
 	d_add(dentry, inode);
 	return NULL;
@@ -317,11 +312,6 @@
 	if (!inode)
 		return NULL;
 
-	{
-	void hfsplus_inode_check(struct super_block *sb);
-	atomic_inc(&HFSPLUS_SB(sb).inode_cnt);
-	hfsplus_inode_check(sb);
-	}
 	inode->i_ino = HFSPLUS_SB(sb).next_cnid++;
 	inode->i_mode = mode;
 	inode->i_uid = current->fsuid;
diff --git a/fs/hfsplus/ioctl.c b/fs/hfsplus/ioctl.c
index e07aa09..13cf848 100644
--- a/fs/hfsplus/ioctl.c
+++ b/fs/hfsplus/ioctl.c
@@ -12,6 +12,7 @@
  * hfsplus ioctls
  */
 
+#include <linux/capability.h>
 #include <linux/fs.h>
 #include <linux/sched.h>
 #include <linux/xattr.h>
diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
index 6daaf7c..d791780 100644
--- a/fs/hfsplus/super.c
+++ b/fs/hfsplus/super.c
@@ -22,29 +22,12 @@
 
 #include "hfsplus_fs.h"
 
-void hfsplus_inode_check(struct super_block *sb)
-{
-#if 0
-	u32 cnt = atomic_read(&HFSPLUS_SB(sb).inode_cnt);
-	u32 last_cnt = HFSPLUS_SB(sb).last_inode_cnt;
-
-	if (cnt <= (last_cnt / 2) ||
-	    cnt >= (last_cnt * 2)) {
-		HFSPLUS_SB(sb).last_inode_cnt = cnt;
-		printk("inode_check: %u,%u,%u\n", cnt, last_cnt,
-			HFSPLUS_SB(sb).cat_tree ? HFSPLUS_SB(sb).cat_tree->node_hash_cnt : 0);
-	}
-#endif
-}
-
 static void hfsplus_read_inode(struct inode *inode)
 {
 	struct hfs_find_data fd;
 	struct hfsplus_vh *vhdr;
 	int err;
 
-	atomic_inc(&HFSPLUS_SB(inode->i_sb).inode_cnt);
-	hfsplus_inode_check(inode->i_sb);
 	INIT_LIST_HEAD(&HFSPLUS_I(inode).open_dir_list);
 	init_MUTEX(&HFSPLUS_I(inode).extents_lock);
 	HFSPLUS_I(inode).flags = 0;
@@ -155,12 +138,10 @@
 static void hfsplus_clear_inode(struct inode *inode)
 {
 	dprint(DBG_INODE, "hfsplus_clear_inode: %lu\n", inode->i_ino);
-	atomic_dec(&HFSPLUS_SB(inode->i_sb).inode_cnt);
 	if (HFSPLUS_IS_RSRC(inode)) {
 		HFSPLUS_I(HFSPLUS_I(inode).rsrc_inode).rsrc_inode = NULL;
 		iput(HFSPLUS_I(inode).rsrc_inode);
 	}
-	hfsplus_inode_check(inode->i_sb);
 }
 
 static void hfsplus_write_super(struct super_block *sb)
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index ff1b7d1..ab4c3a9 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -18,6 +18,7 @@
 #include <linux/highmem.h>
 #include <linux/init.h>
 #include <linux/string.h>
+#include <linux/capability.h>
 #include <linux/backing-dev.h>
 #include <linux/hugetlb.h>
 #include <linux/pagevec.h>
diff --git a/fs/inode.c b/fs/inode.c
index e08767f..108138d 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -22,6 +22,7 @@
 #include <linux/cdev.h>
 #include <linux/bootmem.h>
 #include <linux/inotify.h>
+#include <linux/mount.h>
 
 /*
  * This is needed for the following functions:
@@ -1176,24 +1177,35 @@
 EXPORT_SYMBOL(bmap);
 
 /**
- *	update_atime	-	update the access time
+ *	touch_atime	-	update the access time
+ *	@mnt: mount the inode is accessed on
  *	@inode: inode accessed
  *
  *	Update the accessed time on an inode and mark it for writeback.
  *	This function automatically handles read only file systems and media,
  *	as well as the "noatime" flag and inode specific "noatime" markers.
  */
-void update_atime(struct inode *inode)
+void touch_atime(struct vfsmount *mnt, struct dentry *dentry)
 {
+	struct inode *inode = dentry->d_inode;
 	struct timespec now;
 
-	if (IS_NOATIME(inode))
-		return;
-	if (IS_NODIRATIME(inode) && S_ISDIR(inode->i_mode))
-		return;
 	if (IS_RDONLY(inode))
 		return;
 
+	if ((inode->i_flags & S_NOATIME) ||
+	    (inode->i_sb->s_flags & MS_NOATIME) ||
+	    ((inode->i_sb->s_flags & MS_NODIRATIME) && S_ISDIR(inode->i_mode)))
+		return;
+
+	/*
+	 * We may have a NULL vfsmount when coming from NFSD
+	 */
+	if (mnt &&
+	    ((mnt->mnt_flags & MNT_NOATIME) ||
+	     ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode))))
+		return;
+
 	now = current_fs_time(inode->i_sb);
 	if (!timespec_equal(&inode->i_atime, &now)) {
 		inode->i_atime = now;
@@ -1201,19 +1213,23 @@
 	}
 }
 
-EXPORT_SYMBOL(update_atime);
+EXPORT_SYMBOL(touch_atime);
 
 /**
- *	inode_update_time	-	update mtime and ctime time
- *	@inode: inode accessed
- *	@ctime_too: update ctime too
+ *	file_update_time	-	update mtime and ctime time
+ *	@file: file accessed
  *
- *	Update the mtime time on an inode and mark it for writeback.
- *	When ctime_too is specified update the ctime too.
+ *	Update the mtime and ctime members of an inode and mark the inode
+ *	for writeback.  Note that this function is meant exclusively for
+ *	usage in the file write path of filesystems, and filesystems may
+ *	choose to explicitly ignore update via this function with the
+ *	S_NOCTIME inode flag, e.g. for network filesystem where these
+ *	timestamps are handled by the server.
  */
 
-void inode_update_time(struct inode *inode, int ctime_too)
+void file_update_time(struct file *file)
 {
+	struct inode *inode = file->f_dentry->d_inode;
 	struct timespec now;
 	int sync_it = 0;
 
@@ -1227,16 +1243,15 @@
 		sync_it = 1;
 	inode->i_mtime = now;
 
-	if (ctime_too) {
-		if (!timespec_equal(&inode->i_ctime, &now))
-			sync_it = 1;
-		inode->i_ctime = now;
-	}
+	if (!timespec_equal(&inode->i_ctime, &now))
+		sync_it = 1;
+	inode->i_ctime = now;
+
 	if (sync_it)
 		mark_inode_dirty_sync(inode);
 }
 
-EXPORT_SYMBOL(inode_update_time);
+EXPORT_SYMBOL(file_update_time);
 
 int inode_needs_sync(struct inode *inode)
 {
diff --git a/fs/ioctl.c b/fs/ioctl.c
index 5692091..f8aeec3 100644
--- a/fs/ioctl.c
+++ b/fs/ioctl.c
@@ -8,6 +8,7 @@
 #include <linux/syscalls.h>
 #include <linux/mm.h>
 #include <linux/smp_lock.h>
+#include <linux/capability.h>
 #include <linux/file.h>
 #include <linux/fs.h>
 #include <linux/security.h>
diff --git a/fs/ioprio.c b/fs/ioprio.c
index 4bf1c63..ca77008 100644
--- a/fs/ioprio.c
+++ b/fs/ioprio.c
@@ -22,6 +22,7 @@
 #include <linux/kernel.h>
 #include <linux/ioprio.h>
 #include <linux/blkdev.h>
+#include <linux/capability.h>
 #include <linux/syscalls.h>
 
 static int set_task_ioprio(struct task_struct *task, int ioprio)
diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c
index d0fcc5f..09e5d10 100644
--- a/fs/jffs2/fs.c
+++ b/fs/jffs2/fs.c
@@ -11,6 +11,7 @@
  *
  */
 
+#include <linux/capability.h>
 #include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
diff --git a/fs/jfs/xattr.c b/fs/jfs/xattr.c
index 23aa506..f23048f 100644
--- a/fs/jfs/xattr.c
+++ b/fs/jfs/xattr.c
@@ -17,6 +17,7 @@
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#include <linux/capability.h>
 #include <linux/fs.h>
 #include <linux/xattr.h>
 #include <linux/posix_acl_xattr.h>
@@ -83,21 +84,6 @@
 #define EA_NEW		0x0004
 #define EA_MALLOC	0x0008
 
-/* Namespaces */
-#define XATTR_SYSTEM_PREFIX "system."
-#define XATTR_SYSTEM_PREFIX_LEN (sizeof (XATTR_SYSTEM_PREFIX) - 1)
-
-#define XATTR_USER_PREFIX "user."
-#define XATTR_USER_PREFIX_LEN (sizeof (XATTR_USER_PREFIX) - 1)
-
-#define XATTR_OS2_PREFIX "os2."
-#define XATTR_OS2_PREFIX_LEN (sizeof (XATTR_OS2_PREFIX) - 1)
-
-/* XATTR_SECURITY_PREFIX is defined in include/linux/xattr.h */
-#define XATTR_SECURITY_PREFIX_LEN (sizeof (XATTR_SECURITY_PREFIX) - 1)
-
-#define XATTR_TRUSTED_PREFIX "trusted."
-#define XATTR_TRUSTED_PREFIX_LEN (sizeof (XATTR_TRUSTED_PREFIX) - 1)
 
 /*
  * These three routines are used to recognize on-disk extended attributes
@@ -773,36 +759,23 @@
 static int can_set_xattr(struct inode *inode, const char *name,
 			 const void *value, size_t value_len)
 {
-	if (IS_RDONLY(inode))
-		return -EROFS;
-
-	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
-		return -EPERM;
-
-	if(strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN) == 0)
-		/*
-		 * "system.*"
-		 */
+	if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
 		return can_set_system_xattr(inode, name, value, value_len);
 
-	if(strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0)
-		return (capable(CAP_SYS_ADMIN) ? 0 : -EPERM);
-
-#ifdef CONFIG_JFS_SECURITY
-	if (strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN)
-	    == 0)
-		return 0;	/* Leave it to the security module */
-#endif
-		
-	if((strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) != 0) &&
-	   (strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) != 0))
+	/*
+	 * Don't allow setting an attribute in an unknown namespace.
+	 */
+	if (strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) &&
+	    strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) &&
+	    strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) &&
+	    strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN))
 		return -EOPNOTSUPP;
 
 	if (!S_ISREG(inode->i_mode) &&
 	    (!S_ISDIR(inode->i_mode) || inode->i_mode &S_ISVTX))
 		return -EPERM;
 
-	return permission(inode, MAY_WRITE, NULL);
+	return 0;
 }
 
 int __jfs_setxattr(tid_t tid, struct inode *inode, const char *name,
@@ -972,22 +945,6 @@
 	return rc;
 }
 
-static int can_get_xattr(struct inode *inode, const char *name)
-{
-#ifdef CONFIG_JFS_SECURITY
-	if(strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) == 0)
-		return 0;
-#endif
-
-	if(strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0)
-		return (capable(CAP_SYS_ADMIN) ? 0 : -EPERM);
-
-	if(strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN) == 0)
-		return 0;
-
-	return permission(inode, MAY_READ, NULL);
-}
-
 ssize_t __jfs_getxattr(struct inode *inode, const char *name, void *data,
 		       size_t buf_size)
 {
@@ -998,12 +955,8 @@
 	ssize_t size;
 	int namelen = strlen(name);
 	char *os2name = NULL;
-	int rc;
 	char *value;
 
-	if ((rc = can_get_xattr(inode, name)))
-		return rc;
-
 	if (strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) {
 		os2name = kmalloc(namelen - XATTR_OS2_PREFIX_LEN + 1,
 				  GFP_KERNEL);
diff --git a/fs/namei.c b/fs/namei.c
index 0a8f073..1e5746e 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -28,6 +28,7 @@
 #include <linux/syscalls.h>
 #include <linux/mount.h>
 #include <linux/audit.h>
+#include <linux/capability.h>
 #include <linux/file.h>
 #include <asm/namei.h>
 #include <asm/uaccess.h>
diff --git a/fs/namespace.c b/fs/namespace.c
index f0e353f..8bc15b3 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -16,6 +16,7 @@
 #include <linux/init.h>
 #include <linux/quotaops.h>
 #include <linux/acct.h>
+#include <linux/capability.h>
 #include <linux/module.h>
 #include <linux/seq_file.h>
 #include <linux/namespace.h>
@@ -355,14 +356,14 @@
 		{ MS_SYNCHRONOUS, ",sync" },
 		{ MS_DIRSYNC, ",dirsync" },
 		{ MS_MANDLOCK, ",mand" },
-		{ MS_NOATIME, ",noatime" },
-		{ MS_NODIRATIME, ",nodiratime" },
 		{ 0, NULL }
 	};
 	static struct proc_fs_info mnt_info[] = {
 		{ MNT_NOSUID, ",nosuid" },
 		{ MNT_NODEV, ",nodev" },
 		{ MNT_NOEXEC, ",noexec" },
+		{ MNT_NOATIME, ",noatime" },
+		{ MNT_NODIRATIME, ",nodiratime" },
 		{ 0, NULL }
 	};
 	struct proc_fs_info *fs_infop;
@@ -1286,7 +1287,13 @@
 		mnt_flags |= MNT_NODEV;
 	if (flags & MS_NOEXEC)
 		mnt_flags |= MNT_NOEXEC;
-	flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE);
+	if (flags & MS_NOATIME)
+		mnt_flags |= MNT_NOATIME;
+	if (flags & MS_NODIRATIME)
+		mnt_flags |= MNT_NODIRATIME;
+
+	flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
+		   MS_NOATIME | MS_NODIRATIME);
 
 	/* ... and get the mountpoint */
 	retval = path_lookup(dir_name, LOOKUP_FOLLOW, &nd);
diff --git a/fs/ncpfs/file.c b/fs/ncpfs/file.c
index 4947d9b..973b444 100644
--- a/fs/ncpfs/file.c
+++ b/fs/ncpfs/file.c
@@ -262,7 +262,7 @@
 	}
 	vfree(bouncebuffer);
 
-	inode_update_time(inode, 1);
+	file_update_time(file);
 
 	*ppos = pos;
 
diff --git a/fs/ncpfs/ioctl.c b/fs/ncpfs/ioctl.c
index fd3efdc..d6e0c08 100644
--- a/fs/ncpfs/ioctl.c
+++ b/fs/ncpfs/ioctl.c
@@ -10,6 +10,7 @@
 #include <linux/config.h>
 
 #include <asm/uaccess.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/fs.h>
 #include <linux/ioctl.h>
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 3e4ba9c..a77ee95 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -950,11 +950,20 @@
 
 	/* Flush out writes to the server in order to update c/mtime */
 	nfs_sync_inode(inode, 0, 0, FLUSH_WAIT|FLUSH_NOCOMMIT);
-	if (__IS_FLG(inode, MS_NOATIME))
+
+	/*
+	 * We may force a getattr if the user cares about atime.
+	 *
+	 * Note that we only have to check the vfsmount flags here:
+	 *  - NFS always sets S_NOATIME by so checking it would give a
+	 *    bogus result
+	 *  - NFS never sets MS_NOATIME or MS_NODIRATIME so there is
+	 *    no point in checking those.
+	 */
+ 	if ((mnt->mnt_flags & MNT_NOATIME) ||
+ 	    ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode)))
 		need_atime = 0;
-	else if (__IS_FLG(inode, MS_NODIRATIME) && S_ISDIR(inode->i_mode))
-		need_atime = 0;
-	/* We may force a getattr if the user cares about atime */
+
 	if (need_atime)
 		err = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
 	else
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index bb36b43..eef0576 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -48,8 +48,8 @@
 #include <linux/fsnotify.h>
 #include <linux/posix_acl.h>
 #include <linux/posix_acl_xattr.h>
-#ifdef CONFIG_NFSD_V4
 #include <linux/xattr.h>
+#ifdef CONFIG_NFSD_V4
 #include <linux/nfs4.h>
 #include <linux/nfs4_acl.h>
 #include <linux/nfsd_idmap.h>
@@ -365,8 +365,30 @@
 	goto out;
 }
 
-#if defined(CONFIG_NFSD_V4)
+#if defined(CONFIG_NFSD_V2_ACL) || \
+    defined(CONFIG_NFSD_V3_ACL) || \
+    defined(CONFIG_NFSD_V4)
+static ssize_t nfsd_getxattr(struct dentry *dentry, char *key, void **buf)
+{
+	ssize_t buflen;
+	int error;
 
+	buflen = vfs_getxattr(dentry, key, NULL, 0);
+	if (buflen <= 0)
+		return buflen;
+
+	*buf = kmalloc(buflen, GFP_KERNEL);
+	if (!*buf)
+		return -ENOMEM;
+
+	error = vfs_getxattr(dentry, key, *buf, buflen);
+	if (error < 0)
+		return error;
+	return buflen;
+}
+#endif
+
+#if defined(CONFIG_NFSD_V4)
 static int
 set_nfsv4_acl_one(struct dentry *dentry, struct posix_acl *pacl, char *key)
 {
@@ -374,7 +396,6 @@
 	size_t buflen;
 	char *buf = NULL;
 	int error = 0;
-	struct inode *inode = dentry->d_inode;
 
 	buflen = posix_acl_xattr_size(pacl->a_count);
 	buf = kmalloc(buflen, GFP_KERNEL);
@@ -388,15 +409,7 @@
 		goto out;
 	}
 
-	error = -EOPNOTSUPP;
-	if (inode->i_op && inode->i_op->setxattr) {
-		mutex_lock(&inode->i_mutex);
-		security_inode_setxattr(dentry, key, buf, len, 0);
-		error = inode->i_op->setxattr(dentry, key, buf, len, 0);
-		if (!error)
-			security_inode_post_setxattr(dentry, key, buf, len, 0);
-		mutex_unlock(&inode->i_mutex);
-	}
+	error = vfs_setxattr(dentry, key, buf, len, 0);
 out:
 	kfree(buf);
 	return error;
@@ -455,44 +468,19 @@
 static struct posix_acl *
 _get_posix_acl(struct dentry *dentry, char *key)
 {
-	struct inode *inode = dentry->d_inode;
-	char *buf = NULL;
-	int buflen, error = 0;
+	void *buf = NULL;
 	struct posix_acl *pacl = NULL;
+	int buflen;
 
-	error = -EOPNOTSUPP;
-	if (inode->i_op == NULL)
-		goto out_err;
-	if (inode->i_op->getxattr == NULL)
-		goto out_err;
-
-	error = security_inode_getxattr(dentry, key);
-	if (error)
-		goto out_err;
-
-	buflen = inode->i_op->getxattr(dentry, key, NULL, 0);
-	if (buflen <= 0) {
-		error = buflen < 0 ? buflen : -ENODATA;
-		goto out_err;
-	}
-
-	buf = kmalloc(buflen, GFP_KERNEL);
-	if (buf == NULL) {
-		error = -ENOMEM;
-		goto out_err;
-	}
-
-	error = inode->i_op->getxattr(dentry, key, buf, buflen);
-	if (error < 0)
-		goto out_err;
+	buflen = nfsd_getxattr(dentry, key, &buf);
+	if (!buflen)
+		buflen = -ENODATA;
+	if (buflen <= 0)
+		return ERR_PTR(buflen);
 
 	pacl = posix_acl_from_xattr(buf, buflen);
- out:
 	kfree(buf);
 	return pacl;
- out_err:
-	pacl = ERR_PTR(error);
-	goto out;
 }
 
 int
@@ -1884,39 +1872,25 @@
 	ssize_t size;
 	struct posix_acl *acl;
 
-	if (!IS_POSIXACL(inode) || !inode->i_op || !inode->i_op->getxattr)
+	if (!IS_POSIXACL(inode))
 		return ERR_PTR(-EOPNOTSUPP);
-	switch(type) {
-		case ACL_TYPE_ACCESS:
-			name = POSIX_ACL_XATTR_ACCESS;
-			break;
-		case ACL_TYPE_DEFAULT:
-			name = POSIX_ACL_XATTR_DEFAULT;
-			break;
-		default:
-			return ERR_PTR(-EOPNOTSUPP);
+
+	switch (type) {
+	case ACL_TYPE_ACCESS:
+		name = POSIX_ACL_XATTR_ACCESS;
+		break;
+	case ACL_TYPE_DEFAULT:
+		name = POSIX_ACL_XATTR_DEFAULT;
+		break;
+	default:
+		return ERR_PTR(-EOPNOTSUPP);
 	}
 
-	size = inode->i_op->getxattr(fhp->fh_dentry, name, NULL, 0);
+	size = nfsd_getxattr(fhp->fh_dentry, name, &value);
+	if (size < 0)
+		return ERR_PTR(size);
 
-	if (size < 0) {
-		acl = ERR_PTR(size);
-		goto getout;
-	} else if (size > 0) {
-		value = kmalloc(size, GFP_KERNEL);
-		if (!value) {
-			acl = ERR_PTR(-ENOMEM);
-			goto getout;
-		}
-		size = inode->i_op->getxattr(fhp->fh_dentry, name, value, size);
-		if (size < 0) {
-			acl = ERR_PTR(size);
-			goto getout;
-		}
-	}
 	acl = posix_acl_from_xattr(value, size);
-
-getout:
 	kfree(value);
 	return acl;
 }
@@ -1957,16 +1931,13 @@
 	} else
 		size = 0;
 
-	if (!fhp->fh_locked)
-		fh_lock(fhp);  /* unlocking is done automatically */
 	if (size)
-		error = inode->i_op->setxattr(fhp->fh_dentry, name,
-					      value, size, 0);
+		error = vfs_setxattr(fhp->fh_dentry, name, value, size, 0);
 	else {
 		if (!S_ISDIR(inode->i_mode) && type == ACL_TYPE_DEFAULT)
 			error = 0;
 		else {
-			error = inode->i_op->removexattr(fhp->fh_dentry, name);
+			error = vfs_removexattr(fhp->fh_dentry, name);
 			if (error == -ENODATA)
 				error = 0;
 		}
diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
index 30f71ac..fb413d3 100644
--- a/fs/ntfs/file.c
+++ b/fs/ntfs/file.c
@@ -2173,7 +2173,7 @@
 	err = remove_suid(file->f_dentry);
 	if (err)
 		goto out;
-	inode_update_time(inode, 1);
+	file_update_time(file);
 	written = ntfs_file_buffered_write(iocb, iov, nr_segs, pos, ppos,
 			count);
 out:
diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c
index bda7a08..ea1bd3f 100644
--- a/fs/ntfs/inode.c
+++ b/fs/ntfs/inode.c
@@ -2767,7 +2767,25 @@
 	up_write(&ni->runlist.lock);
 done:
 	/* Update the mtime and ctime on the base inode. */
-	inode_update_time(VFS_I(base_ni), 1);
+	/* normally ->truncate shouldn't update ctime or mtime,
+	 * but ntfs did before so it got a copy & paste version
+	 * of file_update_time.  one day someone should fix this
+	 * for real.
+	 */
+	if (!IS_NOCMTIME(VFS_I(base_ni)) && !IS_RDONLY(VFS_I(base_ni))) {
+		struct timespec now = current_fs_time(VFS_I(base_ni)->i_sb);
+		int sync_it = 0;
+
+		if (!timespec_equal(&VFS_I(base_ni)->i_mtime, &now) ||
+		    !timespec_equal(&VFS_I(base_ni)->i_ctime, &now))
+			sync_it = 1;
+		VFS_I(base_ni)->i_mtime = now;
+		VFS_I(base_ni)->i_ctime = now;
+
+		if (sync_it)
+			mark_inode_dirty_sync(VFS_I(base_ni));
+	}
+
 	if (likely(!err)) {
 		NInoClearTruncateFailed(ni);
 		ntfs_debug("Done.");
diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
index 280e383..c3a3f1a 100644
--- a/fs/ntfs/super.c
+++ b/fs/ntfs/super.c
@@ -443,8 +443,8 @@
 
 	ntfs_debug("Entering with remount options string: %s", opt);
 #ifndef NTFS_RW
-	/* For read-only compiled driver, enforce all read-only flags. */
-	*flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+	/* For read-only compiled driver, enforce read-only flag. */
+	*flags |= MS_RDONLY;
 #else /* NTFS_RW */
 	/*
 	 * For the read-write compiled driver, if we are remounting read-write,
@@ -1721,7 +1721,7 @@
 						es3);
 				goto iput_mirr_err_out;
 			}
-			sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+			sb->s_flags |= MS_RDONLY;
 			ntfs_error(sb, "%s.  Mounting read-only%s",
 					!vol->mftmirr_ino ? es1 : es2, es3);
 		} else
@@ -1837,7 +1837,7 @@
 						es1, es2);
 				goto iput_vol_err_out;
 			}
-			sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+			sb->s_flags |= MS_RDONLY;
 			ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
 		} else
 			ntfs_warning(sb, "%s.  Will not be able to remount "
@@ -1874,7 +1874,7 @@
 				}
 				goto iput_logfile_err_out;
 			}
-			sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+			sb->s_flags |= MS_RDONLY;
 			ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
 		} else
 			ntfs_warning(sb, "%s.  Will not be able to remount "
@@ -1919,7 +1919,7 @@
 						es1, es2);
 				goto iput_root_err_out;
 			}
-			sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+			sb->s_flags |= MS_RDONLY;
 			ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
 		} else
 			ntfs_warning(sb, "%s.  Will not be able to remount "
@@ -1943,7 +1943,7 @@
 			goto iput_root_err_out;
 		}
 		ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
-		sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+		sb->s_flags |= MS_RDONLY;
 		/*
 		 * Do not set NVolErrors() because ntfs_remount() might manage
 		 * to set the dirty flag in which case all would be well.
@@ -1970,7 +1970,7 @@
 			goto iput_root_err_out;
 		}
 		ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
-		sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+		sb->s_flags |= MS_RDONLY;
 		NVolSetErrors(vol);
 	}
 #endif
@@ -1989,7 +1989,7 @@
 			goto iput_root_err_out;
 		}
 		ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
-		sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+		sb->s_flags |= MS_RDONLY;
 		NVolSetErrors(vol);
 	}
 #endif /* NTFS_RW */
@@ -2030,7 +2030,7 @@
 						es1, es2);
 				goto iput_quota_err_out;
 			}
-			sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+			sb->s_flags |= MS_RDONLY;
 			ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
 		} else
 			ntfs_warning(sb, "%s.  Will not be able to remount "
@@ -2053,7 +2053,7 @@
 			goto iput_quota_err_out;
 		}
 		ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
-		sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+		sb->s_flags |= MS_RDONLY;
 		NVolSetErrors(vol);
 	}
 	/*
@@ -2074,7 +2074,7 @@
 						es1, es2);
 				goto iput_usnjrnl_err_out;
 			}
-			sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+			sb->s_flags |= MS_RDONLY;
 			ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
 		} else
 			ntfs_warning(sb, "%s.  Will not be able to remount "
@@ -2097,7 +2097,7 @@
 			goto iput_usnjrnl_err_out;
 		}
 		ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
-		sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+		sb->s_flags |= MS_RDONLY;
 		NVolSetErrors(vol);
 	}
 #endif /* NTFS_RW */
@@ -2689,7 +2689,7 @@
 
 	ntfs_debug("Entering.");
 #ifndef NTFS_RW
-	sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+	sb->s_flags |= MS_RDONLY;
 #endif /* ! NTFS_RW */
 	/* Allocate a new ntfs_volume and place it in sb->s_fs_info. */
 	sb->s_fs_info = kmalloc(sizeof(ntfs_volume), GFP_NOFS);
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index ca5f9f9..eaf33ca 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -23,6 +23,7 @@
  * Boston, MA 021110-1307, USA.
  */
 
+#include <linux/capability.h>
 #include <linux/fs.h>
 #include <linux/types.h>
 #include <linux/slab.h>
diff --git a/fs/ocfs2/mmap.c b/fs/ocfs2/mmap.c
index afdeec4..843cf9d 100644
--- a/fs/ocfs2/mmap.c
+++ b/fs/ocfs2/mmap.c
@@ -80,12 +80,8 @@
 	.nopage = ocfs2_nopage,
 };
 
-int ocfs2_mmap(struct file *file,
-	       struct vm_area_struct *vma)
+int ocfs2_mmap(struct file *file, struct vm_area_struct *vma)
 {
-	struct address_space *mapping = file->f_dentry->d_inode->i_mapping;
-	struct inode *inode = mapping->host;
-
 	/* We don't want to support shared writable mappings yet. */
 	if (((vma->vm_flags & VM_SHARED) || (vma->vm_flags & VM_MAYSHARE))
 	    && ((vma->vm_flags & VM_WRITE) || (vma->vm_flags & VM_MAYWRITE))) {
@@ -95,7 +91,7 @@
 		return -EINVAL;
 	}
 
-	update_atime(inode);
+	file_accessed(file);
 	vma->vm_ops = &ocfs2_file_vm_ops;
 	return 0;
 }
diff --git a/fs/open.c b/fs/open.c
index a3b3a9b..8e20c1f 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -16,6 +16,7 @@
 #include <linux/tty.h>
 #include <linux/namei.h>
 #include <linux/backing-dev.h>
+#include <linux/capability.h>
 #include <linux/security.h>
 #include <linux/mount.h>
 #include <linux/vfs.h>
diff --git a/fs/pipe.c b/fs/pipe.c
index acb030b..eef0f29 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -347,7 +347,7 @@
 		kill_fasync(PIPE_FASYNC_READERS(*inode), SIGIO, POLL_IN);
 	}
 	if (ret > 0)
-		inode_update_time(inode, 1);	/* mtime and ctime */
+		file_update_time(filp);
 	return ret;
 }
 
diff --git a/fs/proc/array.c b/fs/proc/array.c
index 5e9251f6..7eb1bd7 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -330,7 +330,7 @@
 	unsigned long  min_flt = 0,  maj_flt = 0;
 	cputime_t cutime, cstime, utime, stime;
 	unsigned long rsslim = 0;
-	unsigned long it_real_value = 0;
+	DEFINE_KTIME(it_real_value);
 	struct task_struct *t;
 	char tcomm[sizeof(task->comm)];
 
@@ -386,7 +386,7 @@
 			utime = cputime_add(utime, task->signal->utime);
 			stime = cputime_add(stime, task->signal->stime);
 		}
-		it_real_value = task->signal->it_real_value;
+		it_real_value = task->signal->real_timer.expires;
 	}
 	ppid = pid_alive(task) ? task->group_leader->real_parent->tgid : 0;
 	read_unlock(&tasklist_lock);
@@ -435,7 +435,7 @@
 		priority,
 		nice,
 		num_threads,
-		jiffies_to_clock_t(it_real_value),
+		(long) ktime_to_clock_t(it_real_value),
 		start_time,
 		vsize,
 		mm ? get_mm_rss(mm) : 0,
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 634355e..20feb75 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -55,6 +55,7 @@
 #include <linux/proc_fs.h>
 #include <linux/stat.h>
 #include <linux/init.h>
+#include <linux/capability.h>
 #include <linux/file.h>
 #include <linux/string.h>
 #include <linux/seq_file.h>
diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
index 1c7da98..adc2cd9 100644
--- a/fs/proc/kcore.c
+++ b/fs/proc/kcore.c
@@ -14,6 +14,7 @@
 #include <linux/proc_fs.h>
 #include <linux/user.h>
 #include <linux/a.out.h>
+#include <linux/capability.h>
 #include <linux/elf.h>
 #include <linux/elfcore.h>
 #include <linux/vmalloc.h>
diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
index 3b2e7b69..4063fb3 100644
--- a/fs/proc/vmcore.c
+++ b/fs/proc/vmcore.c
@@ -14,7 +14,6 @@
 #include <linux/a.out.h>
 #include <linux/elf.h>
 #include <linux/elfcore.h>
-#include <linux/proc_fs.h>
 #include <linux/highmem.h>
 #include <linux/bootmem.h>
 #include <linux/init.h>
@@ -35,11 +34,14 @@
 /* Total size of vmcore file. */
 static u64 vmcore_size;
 
+/* Stores the physical address of elf header of crash image. */
+unsigned long long elfcorehdr_addr = ELFCORE_ADDR_MAX;
+
 struct proc_dir_entry *proc_vmcore = NULL;
 
 /* Reads a page from the oldmem device from given offset. */
 static ssize_t read_from_oldmem(char *buf, size_t count,
-			     loff_t *ppos, int userbuf)
+				u64 *ppos, int userbuf)
 {
 	unsigned long pfn, offset;
 	size_t nr_bytes;
diff --git a/fs/quota.c b/fs/quota.c
index d14d872..ba9e0bf 100644
--- a/fs/quota.c
+++ b/fs/quota.c
@@ -15,6 +15,7 @@
 #include <linux/security.h>
 #include <linux/syscalls.h>
 #include <linux/buffer_head.h>
+#include <linux/capability.h>
 #include <linux/quotaops.h>
 
 /* Check validity of generic quotactl commands */
diff --git a/fs/reiserfs/file.c b/fs/reiserfs/file.c
index 127e7d2..ad6fa96 100644
--- a/fs/reiserfs/file.c
+++ b/fs/reiserfs/file.c
@@ -1360,7 +1360,7 @@
 	if (res)
 		goto out;
 
-	inode_update_time(inode, 1);	/* Both mtime and ctime */
+	file_update_time(file);
 
 	// Ok, we are done with all the checks.
 
diff --git a/fs/reiserfs/ioctl.c b/fs/reiserfs/ioctl.c
index ba8bf8d..745c881 100644
--- a/fs/reiserfs/ioctl.c
+++ b/fs/reiserfs/ioctl.c
@@ -2,6 +2,7 @@
  * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
  */
 
+#include <linux/capability.h>
 #include <linux/fs.h>
 #include <linux/reiserfs_fs.h>
 #include <linux/time.h>
diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
index 3f17ef8..4491fcf 100644
--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -3925,10 +3925,13 @@
 		flush = 1;
 	}
 #ifdef REISERFS_PREALLOCATE
-	/* quota ops might need to nest, setup the journal_info pointer for them */
+	/* quota ops might need to nest, setup the journal_info pointer for them
+	 * and raise the refcount so that it is > 0. */
 	current->journal_info = th;
+	th->t_refcount++;
 	reiserfs_discard_all_prealloc(th);	/* it should not involve new blocks into
 						 * the transaction */
+	th->t_refcount--;
 	current->journal_info = th->t_handle_save;
 #endif
 
diff --git a/fs/reiserfs/xattr.c b/fs/reiserfs/xattr.c
index f1895f0..cc061bf 100644
--- a/fs/reiserfs/xattr.c
+++ b/fs/reiserfs/xattr.c
@@ -30,6 +30,7 @@
  */
 
 #include <linux/reiserfs_fs.h>
+#include <linux/capability.h>
 #include <linux/dcache.h>
 #include <linux/namei.h>
 #include <linux/errno.h>
@@ -497,12 +498,6 @@
 	struct iattr newattrs;
 	__u32 xahash = 0;
 
-	if (IS_RDONLY(inode))
-		return -EROFS;
-
-	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
-		return -EPERM;
-
 	if (get_inode_sd_version(inode) == STAT_DATA_V1)
 		return -EOPNOTSUPP;
 
@@ -758,9 +753,6 @@
 	struct dentry *dir;
 	int err;
 
-	if (IS_RDONLY(inode))
-		return -EROFS;
-
 	dir = open_xa_dir(inode, FL_READONLY);
 	if (IS_ERR(dir)) {
 		err = PTR_ERR(dir);
@@ -984,12 +976,6 @@
 	    get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
 		return -EOPNOTSUPP;
 
-	if (IS_RDONLY(dentry->d_inode))
-		return -EROFS;
-
-	if (IS_IMMUTABLE(dentry->d_inode) || IS_APPEND(dentry->d_inode))
-		return -EROFS;
-
 	reiserfs_write_lock_xattr_i(dentry->d_inode);
 	lock = !has_xattr_dir(dentry->d_inode);
 	if (lock)
@@ -1019,12 +1005,6 @@
 	    get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
 		return -EOPNOTSUPP;
 
-	if (IS_RDONLY(dentry->d_inode))
-		return -EROFS;
-
-	if (IS_IMMUTABLE(dentry->d_inode) || IS_APPEND(dentry->d_inode))
-		return -EPERM;
-
 	reiserfs_write_lock_xattr_i(dentry->d_inode);
 	reiserfs_read_lock_xattrs(dentry->d_sb);
 
diff --git a/fs/reiserfs/xattr_acl.c b/fs/reiserfs/xattr_acl.c
index 2dc9535..43de3ba 100644
--- a/fs/reiserfs/xattr_acl.c
+++ b/fs/reiserfs/xattr_acl.c
@@ -1,3 +1,4 @@
+#include <linux/capability.h>
 #include <linux/fs.h>
 #include <linux/posix_acl.h>
 #include <linux/reiserfs_fs.h>
diff --git a/fs/reiserfs/xattr_trusted.c b/fs/reiserfs/xattr_trusted.c
index 2501f7e..024a938 100644
--- a/fs/reiserfs/xattr_trusted.c
+++ b/fs/reiserfs/xattr_trusted.c
@@ -1,4 +1,5 @@
 #include <linux/reiserfs_fs.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/fs.h>
 #include <linux/pagemap.h>
diff --git a/fs/reiserfs/xattr_user.c b/fs/reiserfs/xattr_user.c
index 5145804..073f393 100644
--- a/fs/reiserfs/xattr_user.c
+++ b/fs/reiserfs/xattr_user.c
@@ -16,18 +16,10 @@
 user_get(struct inode *inode, const char *name, void *buffer, size_t size)
 {
 
-	int error;
-
 	if (strlen(name) < sizeof(XATTR_USER_PREFIX))
 		return -EINVAL;
-
 	if (!reiserfs_xattrs_user(inode->i_sb))
 		return -EOPNOTSUPP;
-
-	error = reiserfs_permission_locked(inode, MAY_READ, NULL);
-	if (error)
-		return error;
-
 	return reiserfs_xattr_get(inode, name, buffer, size);
 }
 
@@ -36,43 +28,21 @@
 	 size_t size, int flags)
 {
 
-	int error;
-
 	if (strlen(name) < sizeof(XATTR_USER_PREFIX))
 		return -EINVAL;
 
 	if (!reiserfs_xattrs_user(inode->i_sb))
 		return -EOPNOTSUPP;
-
-	if (!S_ISREG(inode->i_mode) &&
-	    (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
-		return -EPERM;
-
-	error = reiserfs_permission_locked(inode, MAY_WRITE, NULL);
-	if (error)
-		return error;
-
 	return reiserfs_xattr_set(inode, name, buffer, size, flags);
 }
 
 static int user_del(struct inode *inode, const char *name)
 {
-	int error;
-
 	if (strlen(name) < sizeof(XATTR_USER_PREFIX))
 		return -EINVAL;
 
 	if (!reiserfs_xattrs_user(inode->i_sb))
 		return -EOPNOTSUPP;
-
-	if (!S_ISREG(inode->i_mode) &&
-	    (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
-		return -EPERM;
-
-	error = reiserfs_permission_locked(inode, MAY_WRITE, NULL);
-	if (error)
-		return error;
-
 	return 0;
 }
 
diff --git a/fs/smbfs/proc.c b/fs/smbfs/proc.c
index d6baec0..b1b878b 100644
--- a/fs/smbfs/proc.c
+++ b/fs/smbfs/proc.c
@@ -8,6 +8,7 @@
  */
 
 #include <linux/types.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/slab.h>
 #include <linux/fs.h>
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
index c313321..689f7bc 100644
--- a/fs/sysfs/inode.c
+++ b/fs/sysfs/inode.c
@@ -11,6 +11,7 @@
 #include <linux/pagemap.h>
 #include <linux/namei.h>
 #include <linux/backing-dev.h>
+#include <linux/capability.h>
 #include "sysfs.h"
 
 extern struct super_block * sysfs_sb;
diff --git a/fs/udf/file.c b/fs/udf/file.c
index 8a38828..a6f2acc 100644
--- a/fs/udf/file.c
+++ b/fs/udf/file.c
@@ -31,6 +31,7 @@
 #include <asm/uaccess.h>
 #include <linux/kernel.h>
 #include <linux/string.h> /* memset */
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/smp_lock.h>
 #include <linux/pagemap.h>
diff --git a/fs/ufs/balloc.c b/fs/ufs/balloc.c
index faf1512..a9f4421 100644
--- a/fs/ufs/balloc.c
+++ b/fs/ufs/balloc.c
@@ -13,6 +13,7 @@
 #include <linux/string.h>
 #include <linux/quotaops.h>
 #include <linux/buffer_head.h>
+#include <linux/capability.h>
 #include <linux/sched.h>
 #include <linux/bitops.h>
 #include <asm/byteorder.h>
diff --git a/fs/xattr.c b/fs/xattr.c
index 386a532..80eca7d 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -19,6 +19,149 @@
 #include <linux/fsnotify.h>
 #include <asm/uaccess.h>
 
+
+/*
+ * Check permissions for extended attribute access.  This is a bit complicated
+ * because different namespaces have very different rules.
+ */
+static int
+xattr_permission(struct inode *inode, const char *name, int mask)
+{
+	/*
+	 * We can never set or remove an extended attribute on a read-only
+	 * filesystem  or on an immutable / append-only inode.
+	 */
+	if (mask & MAY_WRITE) {
+		if (IS_RDONLY(inode))
+			return -EROFS;
+		if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
+			return -EPERM;
+	}
+
+	/*
+	 * No restriction for security.* and system.* from the VFS.  Decision
+	 * on these is left to the underlying filesystem / security module.
+	 */
+	if (!strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) ||
+	    !strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
+		return 0;
+
+	/*
+	 * The trusted.* namespace can only accessed by a privilegued user.
+	 */
+	if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN))
+		return (capable(CAP_SYS_ADMIN) ? 0 : -EPERM);
+
+	if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
+		if (!S_ISREG(inode->i_mode) &&
+		    (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
+			return -EPERM;
+	}
+
+	return permission(inode, mask, NULL);
+}
+
+int
+vfs_setxattr(struct dentry *dentry, char *name, void *value,
+		size_t size, int flags)
+{
+	struct inode *inode = dentry->d_inode;
+	int error;
+
+	error = xattr_permission(inode, name, MAY_WRITE);
+	if (error)
+		return error;
+
+	mutex_lock(&inode->i_mutex);
+	error = security_inode_setxattr(dentry, name, value, size, flags);
+	if (error)
+		goto out;
+	error = -EOPNOTSUPP;
+	if (inode->i_op->setxattr) {
+		error = inode->i_op->setxattr(dentry, name, value, size, flags);
+		if (!error) {
+			fsnotify_xattr(dentry);
+			security_inode_post_setxattr(dentry, name, value,
+						     size, flags);
+		}
+	} else if (!strncmp(name, XATTR_SECURITY_PREFIX,
+				XATTR_SECURITY_PREFIX_LEN)) {
+		const char *suffix = name + XATTR_SECURITY_PREFIX_LEN;
+		error = security_inode_setsecurity(inode, suffix, value,
+						   size, flags);
+		if (!error)
+			fsnotify_xattr(dentry);
+	}
+out:
+	mutex_unlock(&inode->i_mutex);
+	return error;
+}
+EXPORT_SYMBOL_GPL(vfs_setxattr);
+
+ssize_t
+vfs_getxattr(struct dentry *dentry, char *name, void *value, size_t size)
+{
+	struct inode *inode = dentry->d_inode;
+	int error;
+
+	error = xattr_permission(inode, name, MAY_READ);
+	if (error)
+		return error;
+
+	error = security_inode_getxattr(dentry, name);
+	if (error)
+		return error;
+
+	if (inode->i_op->getxattr)
+		error = inode->i_op->getxattr(dentry, name, value, size);
+	else
+		error = -EOPNOTSUPP;
+
+	if (!strncmp(name, XATTR_SECURITY_PREFIX,
+				XATTR_SECURITY_PREFIX_LEN)) {
+		const char *suffix = name + XATTR_SECURITY_PREFIX_LEN;
+		int ret = security_inode_getsecurity(inode, suffix, value,
+						     size, error);
+		/*
+		 * Only overwrite the return value if a security module
+		 * is actually active.
+		 */
+		if (ret != -EOPNOTSUPP)
+			error = ret;
+	}
+
+	return error;
+}
+EXPORT_SYMBOL_GPL(vfs_getxattr);
+
+int
+vfs_removexattr(struct dentry *dentry, char *name)
+{
+	struct inode *inode = dentry->d_inode;
+	int error;
+
+	if (!inode->i_op->removexattr)
+		return -EOPNOTSUPP;
+
+	error = xattr_permission(inode, name, MAY_WRITE);
+	if (error)
+		return error;
+
+	error = security_inode_removexattr(dentry, name);
+	if (error)
+		return error;
+
+	mutex_lock(&inode->i_mutex);
+	error = inode->i_op->removexattr(dentry, name);
+	mutex_unlock(&inode->i_mutex);
+
+	if (!error)
+		fsnotify_xattr(dentry);
+	return error;
+}
+EXPORT_SYMBOL_GPL(vfs_removexattr);
+
+
 /*
  * Extended attribute SET operations
  */
@@ -51,29 +194,7 @@
 		}
 	}
 
-	mutex_lock(&d->d_inode->i_mutex);
-	error = security_inode_setxattr(d, kname, kvalue, size, flags);
-	if (error)
-		goto out;
-	error = -EOPNOTSUPP;
-	if (d->d_inode->i_op && d->d_inode->i_op->setxattr) {
-		error = d->d_inode->i_op->setxattr(d, kname, kvalue,
-						   size, flags);
-		if (!error) {
-			fsnotify_xattr(d);
-			security_inode_post_setxattr(d, kname, kvalue,
-						     size, flags);
-		}
-	} else if (!strncmp(kname, XATTR_SECURITY_PREFIX,
-			    sizeof XATTR_SECURITY_PREFIX - 1)) {
-		const char *suffix = kname + sizeof XATTR_SECURITY_PREFIX - 1;
-		error = security_inode_setsecurity(d->d_inode, suffix, kvalue,
-						   size, flags);
-		if (!error)
-			fsnotify_xattr(d);
-	}
-out:
-	mutex_unlock(&d->d_inode->i_mutex);
+	error = vfs_setxattr(d, kname, kvalue, size, flags);
 	kfree(kvalue);
 	return error;
 }
@@ -147,22 +268,7 @@
 			return -ENOMEM;
 	}
 
-	error = security_inode_getxattr(d, kname);
-	if (error)
-		goto out;
-	error = -EOPNOTSUPP;
-	if (d->d_inode->i_op && d->d_inode->i_op->getxattr)
-		error = d->d_inode->i_op->getxattr(d, kname, kvalue, size);
-
-	if (!strncmp(kname, XATTR_SECURITY_PREFIX,
-		     sizeof XATTR_SECURITY_PREFIX - 1)) {
-		const char *suffix = kname + sizeof XATTR_SECURITY_PREFIX - 1;
-		int rv = security_inode_getsecurity(d->d_inode, suffix, kvalue,
-						    size, error);
-		/* Security module active: overwrite error value */
-		if (rv != -EOPNOTSUPP)
-			error = rv;
-	}
+	error = vfs_getxattr(d, kname, kvalue, size);
 	if (error > 0) {
 		if (size && copy_to_user(value, kvalue, error))
 			error = -EFAULT;
@@ -171,7 +277,6 @@
 		   than XATTR_SIZE_MAX bytes. Not possible. */
 		error = -E2BIG;
 	}
-out:
 	kfree(kvalue);
 	return error;
 }
@@ -318,19 +423,7 @@
 	if (error < 0)
 		return error;
 
-	error = -EOPNOTSUPP;
-	if (d->d_inode->i_op && d->d_inode->i_op->removexattr) {
-		error = security_inode_removexattr(d, kname);
-		if (error)
-			goto out;
-		mutex_lock(&d->d_inode->i_mutex);
-		error = d->d_inode->i_op->removexattr(d, kname);
-		mutex_unlock(&d->d_inode->i_mutex);
-		if (!error)
-			fsnotify_xattr(d);
-	}
-out:
-	return error;
+	return vfs_removexattr(d, kname);
 }
 
 asmlinkage long
diff --git a/fs/xfs/Kbuild b/fs/xfs/Kbuild
new file mode 100644
index 0000000..2566e96
--- /dev/null
+++ b/fs/xfs/Kbuild
@@ -0,0 +1,6 @@
+#
+# The xfs people like to share Makefile with 2.6 and 2.4.
+# Utilise file named Kbuild file which has precedence over Makefile.
+#
+
+include $(srctree)/$(obj)/Makefile-linux-2.6
diff --git a/fs/xfs/linux-2.6/xfs_aops.c b/fs/xfs/linux-2.6/xfs_aops.c
index 94d3cdf..d1db8c1 100644
--- a/fs/xfs/linux-2.6/xfs_aops.c
+++ b/fs/xfs/linux-2.6/xfs_aops.c
@@ -40,11 +40,10 @@
 #include "xfs_rw.h"
 #include "xfs_iomap.h"
 #include <linux/mpage.h>
+#include <linux/pagevec.h>
 #include <linux/writeback.h>
 
 STATIC void xfs_count_page_state(struct page *, int *, int *, int *);
-STATIC void xfs_convert_page(struct inode *, struct page *, xfs_iomap_t *,
-		struct writeback_control *wbc, void *, int, int);
 
 #if defined(XFS_RW_TRACE)
 void
@@ -55,17 +54,15 @@
 	int		mask)
 {
 	xfs_inode_t	*ip;
-	bhv_desc_t	*bdp;
 	vnode_t		*vp = LINVFS_GET_VP(inode);
 	loff_t		isize = i_size_read(inode);
-	loff_t		offset = (loff_t)page->index << PAGE_CACHE_SHIFT;
+	loff_t		offset = page_offset(page);
 	int		delalloc = -1, unmapped = -1, unwritten = -1;
 
 	if (page_has_buffers(page))
 		xfs_count_page_state(page, &delalloc, &unmapped, &unwritten);
 
-	bdp = vn_bhv_lookup(VN_BHV_HEAD(vp), &xfs_vnodeops);
-	ip = XFS_BHVTOI(bdp);
+	ip = xfs_vtoi(vp);
 	if (!ip->i_rwtrace)
 		return;
 
@@ -103,15 +100,56 @@
 		queue_work(xfsdatad_workqueue, &ioend->io_work);
 }
 
+/*
+ * We're now finished for good with this ioend structure.
+ * Update the page state via the associated buffer_heads,
+ * release holds on the inode and bio, and finally free
+ * up memory.  Do not use the ioend after this.
+ */
 STATIC void
 xfs_destroy_ioend(
 	xfs_ioend_t		*ioend)
 {
+	struct buffer_head	*bh, *next;
+
+	for (bh = ioend->io_buffer_head; bh; bh = next) {
+		next = bh->b_private;
+		bh->b_end_io(bh, ioend->io_uptodate);
+	}
+
 	vn_iowake(ioend->io_vnode);
 	mempool_free(ioend, xfs_ioend_pool);
 }
 
 /*
+ * Buffered IO write completion for delayed allocate extents.
+ * TODO: Update ondisk isize now that we know the file data
+ * has been flushed (i.e. the notorious "NULL file" problem).
+ */
+STATIC void
+xfs_end_bio_delalloc(
+	void			*data)
+{
+	xfs_ioend_t		*ioend = data;
+
+	xfs_destroy_ioend(ioend);
+}
+
+/*
+ * Buffered IO write completion for regular, written extents.
+ */
+STATIC void
+xfs_end_bio_written(
+	void			*data)
+{
+	xfs_ioend_t		*ioend = data;
+
+	xfs_destroy_ioend(ioend);
+}
+
+/*
+ * IO write completion for unwritten extents.
+ *
  * Issue transactions to convert a buffer range from unwritten
  * to written extents.
  */
@@ -123,21 +161,10 @@
 	vnode_t			*vp = ioend->io_vnode;
 	xfs_off_t		offset = ioend->io_offset;
 	size_t			size = ioend->io_size;
-	struct buffer_head	*bh, *next;
 	int			error;
 
 	if (ioend->io_uptodate)
 		VOP_BMAP(vp, offset, size, BMAPI_UNWRITTEN, NULL, NULL, error);
-
-	/* ioend->io_buffer_head is only non-NULL for buffered I/O */
-	for (bh = ioend->io_buffer_head; bh; bh = next) {
-		next = bh->b_private;
-
-		bh->b_end_io = NULL;
-		clear_buffer_unwritten(bh);
-		end_buffer_async_write(bh, ioend->io_uptodate);
-	}
-
 	xfs_destroy_ioend(ioend);
 }
 
@@ -149,7 +176,8 @@
  */
 STATIC xfs_ioend_t *
 xfs_alloc_ioend(
-	struct inode		*inode)
+	struct inode		*inode,
+	unsigned int		type)
 {
 	xfs_ioend_t		*ioend;
 
@@ -162,45 +190,25 @@
 	 */
 	atomic_set(&ioend->io_remaining, 1);
 	ioend->io_uptodate = 1; /* cleared if any I/O fails */
+	ioend->io_list = NULL;
+	ioend->io_type = type;
 	ioend->io_vnode = LINVFS_GET_VP(inode);
 	ioend->io_buffer_head = NULL;
+	ioend->io_buffer_tail = NULL;
 	atomic_inc(&ioend->io_vnode->v_iocount);
 	ioend->io_offset = 0;
 	ioend->io_size = 0;
 
-	INIT_WORK(&ioend->io_work, xfs_end_bio_unwritten, ioend);
+	if (type == IOMAP_UNWRITTEN)
+		INIT_WORK(&ioend->io_work, xfs_end_bio_unwritten, ioend);
+	else if (type == IOMAP_DELAY)
+		INIT_WORK(&ioend->io_work, xfs_end_bio_delalloc, ioend);
+	else
+		INIT_WORK(&ioend->io_work, xfs_end_bio_written, ioend);
 
 	return ioend;
 }
 
-void
-linvfs_unwritten_done(
-	struct buffer_head	*bh,
-	int			uptodate)
-{
-	xfs_ioend_t		*ioend = bh->b_private;
-	static spinlock_t	unwritten_done_lock = SPIN_LOCK_UNLOCKED;
-	unsigned long		flags;
-
-	ASSERT(buffer_unwritten(bh));
-	bh->b_end_io = NULL;
-
-	if (!uptodate)
-		ioend->io_uptodate = 0;
-
-	/*
-	 * Deep magic here.  We reuse b_private in the buffer_heads to build
-	 * a chain for completing the I/O from user context after we've issued
-	 * a transaction to convert the unwritten extent.
-	 */
-	spin_lock_irqsave(&unwritten_done_lock, flags);
-	bh->b_private = ioend->io_buffer_head;
-	ioend->io_buffer_head = bh;
-	spin_unlock_irqrestore(&unwritten_done_lock, flags);
-
-	xfs_finish_ioend(ioend);
-}
-
 STATIC int
 xfs_map_blocks(
 	struct inode		*inode,
@@ -218,138 +226,260 @@
 	return -error;
 }
 
-/*
- * Finds the corresponding mapping in block @map array of the
- * given @offset within a @page.
- */
-STATIC xfs_iomap_t *
-xfs_offset_to_map(
-	struct page		*page,
+STATIC inline int
+xfs_iomap_valid(
 	xfs_iomap_t		*iomapp,
-	unsigned long		offset)
+	loff_t			offset)
 {
-	loff_t			full_offset;	/* offset from start of file */
+	return offset >= iomapp->iomap_offset &&
+		offset < iomapp->iomap_offset + iomapp->iomap_bsize;
+}
 
-	ASSERT(offset < PAGE_CACHE_SIZE);
+/*
+ * BIO completion handler for buffered IO.
+ */
+STATIC int
+xfs_end_bio(
+	struct bio		*bio,
+	unsigned int		bytes_done,
+	int			error)
+{
+	xfs_ioend_t		*ioend = bio->bi_private;
 
-	full_offset = page->index;		/* NB: using 64bit number */
-	full_offset <<= PAGE_CACHE_SHIFT;	/* offset from file start */
-	full_offset += offset;			/* offset from page start */
+	if (bio->bi_size)
+		return 1;
 
-	if (full_offset < iomapp->iomap_offset)
-		return NULL;
-	if (iomapp->iomap_offset + (iomapp->iomap_bsize -1) >= full_offset)
-		return iomapp;
-	return NULL;
+	ASSERT(ioend);
+	ASSERT(atomic_read(&bio->bi_cnt) >= 1);
+
+	/* Toss bio and pass work off to an xfsdatad thread */
+	if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
+		ioend->io_uptodate = 0;
+	bio->bi_private = NULL;
+	bio->bi_end_io = NULL;
+
+	bio_put(bio);
+	xfs_finish_ioend(ioend);
+	return 0;
+}
+
+STATIC void
+xfs_submit_ioend_bio(
+	xfs_ioend_t	*ioend,
+	struct bio	*bio)
+{
+	atomic_inc(&ioend->io_remaining);
+
+	bio->bi_private = ioend;
+	bio->bi_end_io = xfs_end_bio;
+
+	submit_bio(WRITE, bio);
+	ASSERT(!bio_flagged(bio, BIO_EOPNOTSUPP));
+	bio_put(bio);
+}
+
+STATIC struct bio *
+xfs_alloc_ioend_bio(
+	struct buffer_head	*bh)
+{
+	struct bio		*bio;
+	int			nvecs = bio_get_nr_vecs(bh->b_bdev);
+
+	do {
+		bio = bio_alloc(GFP_NOIO, nvecs);
+		nvecs >>= 1;
+	} while (!bio);
+
+	ASSERT(bio->bi_private == NULL);
+	bio->bi_sector = bh->b_blocknr * (bh->b_size >> 9);
+	bio->bi_bdev = bh->b_bdev;
+	bio_get(bio);
+	return bio;
+}
+
+STATIC void
+xfs_start_buffer_writeback(
+	struct buffer_head	*bh)
+{
+	ASSERT(buffer_mapped(bh));
+	ASSERT(buffer_locked(bh));
+	ASSERT(!buffer_delay(bh));
+	ASSERT(!buffer_unwritten(bh));
+
+	mark_buffer_async_write(bh);
+	set_buffer_uptodate(bh);
+	clear_buffer_dirty(bh);
+}
+
+STATIC void
+xfs_start_page_writeback(
+	struct page		*page,
+	struct writeback_control *wbc,
+	int			clear_dirty,
+	int			buffers)
+{
+	ASSERT(PageLocked(page));
+	ASSERT(!PageWriteback(page));
+	set_page_writeback(page);
+	if (clear_dirty)
+		clear_page_dirty(page);
+	unlock_page(page);
+	if (!buffers) {
+		end_page_writeback(page);
+		wbc->pages_skipped++;	/* We didn't write this page */
+	}
+}
+
+static inline int bio_add_buffer(struct bio *bio, struct buffer_head *bh)
+{
+	return bio_add_page(bio, bh->b_page, bh->b_size, bh_offset(bh));
+}
+
+/*
+ * Submit all of the bios for all of the ioends we have saved up,
+ * covering the initial writepage page and also any probed pages.
+ */
+STATIC void
+xfs_submit_ioend(
+	xfs_ioend_t		*ioend)
+{
+	xfs_ioend_t		*next;
+	struct buffer_head	*bh;
+	struct bio		*bio;
+	sector_t		lastblock = 0;
+
+	do {
+		next = ioend->io_list;
+		bio = NULL;
+
+		for (bh = ioend->io_buffer_head; bh; bh = bh->b_private) {
+			xfs_start_buffer_writeback(bh);
+
+			if (!bio) {
+ retry:
+				bio = xfs_alloc_ioend_bio(bh);
+			} else if (bh->b_blocknr != lastblock + 1) {
+				xfs_submit_ioend_bio(ioend, bio);
+				goto retry;
+			}
+
+			if (bio_add_buffer(bio, bh) != bh->b_size) {
+				xfs_submit_ioend_bio(ioend, bio);
+				goto retry;
+			}
+
+			lastblock = bh->b_blocknr;
+		}
+		if (bio)
+			xfs_submit_ioend_bio(ioend, bio);
+		xfs_finish_ioend(ioend);
+	} while ((ioend = next) != NULL);
+}
+
+/*
+ * Cancel submission of all buffer_heads so far in this endio.
+ * Toss the endio too.  Only ever called for the initial page
+ * in a writepage request, so only ever one page.
+ */
+STATIC void
+xfs_cancel_ioend(
+	xfs_ioend_t		*ioend)
+{
+	xfs_ioend_t		*next;
+	struct buffer_head	*bh, *next_bh;
+
+	do {
+		next = ioend->io_list;
+		bh = ioend->io_buffer_head;
+		do {
+			next_bh = bh->b_private;
+			clear_buffer_async_write(bh);
+			unlock_buffer(bh);
+		} while ((bh = next_bh) != NULL);
+
+		vn_iowake(ioend->io_vnode);
+		mempool_free(ioend, xfs_ioend_pool);
+	} while ((ioend = next) != NULL);
+}
+
+/*
+ * Test to see if we've been building up a completion structure for
+ * earlier buffers -- if so, we try to append to this ioend if we
+ * can, otherwise we finish off any current ioend and start another.
+ * Return true if we've finished the given ioend.
+ */
+STATIC void
+xfs_add_to_ioend(
+	struct inode		*inode,
+	struct buffer_head	*bh,
+	xfs_off_t		offset,
+	unsigned int		type,
+	xfs_ioend_t		**result,
+	int			need_ioend)
+{
+	xfs_ioend_t		*ioend = *result;
+
+	if (!ioend || need_ioend || type != ioend->io_type) {
+		xfs_ioend_t	*previous = *result;
+
+		ioend = xfs_alloc_ioend(inode, type);
+		ioend->io_offset = offset;
+		ioend->io_buffer_head = bh;
+		ioend->io_buffer_tail = bh;
+		if (previous)
+			previous->io_list = ioend;
+		*result = ioend;
+	} else {
+		ioend->io_buffer_tail->b_private = bh;
+		ioend->io_buffer_tail = bh;
+	}
+
+	bh->b_private = NULL;
+	ioend->io_size += bh->b_size;
 }
 
 STATIC void
 xfs_map_at_offset(
-	struct page		*page,
 	struct buffer_head	*bh,
-	unsigned long		offset,
+	loff_t			offset,
 	int			block_bits,
 	xfs_iomap_t		*iomapp)
 {
 	xfs_daddr_t		bn;
-	loff_t			delta;
 	int			sector_shift;
 
 	ASSERT(!(iomapp->iomap_flags & IOMAP_HOLE));
 	ASSERT(!(iomapp->iomap_flags & IOMAP_DELAY));
 	ASSERT(iomapp->iomap_bn != IOMAP_DADDR_NULL);
 
-	delta = page->index;
-	delta <<= PAGE_CACHE_SHIFT;
-	delta += offset;
-	delta -= iomapp->iomap_offset;
-	delta >>= block_bits;
-
 	sector_shift = block_bits - BBSHIFT;
-	bn = iomapp->iomap_bn >> sector_shift;
-	bn += delta;
-	BUG_ON(!bn && !(iomapp->iomap_flags & IOMAP_REALTIME));
+	bn = (iomapp->iomap_bn >> sector_shift) +
+	      ((offset - iomapp->iomap_offset) >> block_bits);
+
+	ASSERT(bn || (iomapp->iomap_flags & IOMAP_REALTIME));
 	ASSERT((bn << sector_shift) >= iomapp->iomap_bn);
 
 	lock_buffer(bh);
 	bh->b_blocknr = bn;
-	bh->b_bdev = iomapp->iomap_target->pbr_bdev;
+	bh->b_bdev = iomapp->iomap_target->bt_bdev;
 	set_buffer_mapped(bh);
 	clear_buffer_delay(bh);
+	clear_buffer_unwritten(bh);
 }
 
 /*
- * Look for a page at index which is unlocked and contains our
- * unwritten extent flagged buffers at its head.  Returns page
- * locked and with an extra reference count, and length of the
- * unwritten extent component on this page that we can write,
- * in units of filesystem blocks.
- */
-STATIC struct page *
-xfs_probe_unwritten_page(
-	struct address_space	*mapping,
-	pgoff_t			index,
-	xfs_iomap_t		*iomapp,
-	xfs_ioend_t		*ioend,
-	unsigned long		max_offset,
-	unsigned long		*fsbs,
-	unsigned int            bbits)
-{
-	struct page		*page;
-
-	page = find_trylock_page(mapping, index);
-	if (!page)
-		return NULL;
-	if (PageWriteback(page))
-		goto out;
-
-	if (page->mapping && page_has_buffers(page)) {
-		struct buffer_head	*bh, *head;
-		unsigned long		p_offset = 0;
-
-		*fsbs = 0;
-		bh = head = page_buffers(page);
-		do {
-			if (!buffer_unwritten(bh) || !buffer_uptodate(bh))
-				break;
-			if (!xfs_offset_to_map(page, iomapp, p_offset))
-				break;
-			if (p_offset >= max_offset)
-				break;
-			xfs_map_at_offset(page, bh, p_offset, bbits, iomapp);
-			set_buffer_unwritten_io(bh);
-			bh->b_private = ioend;
-			p_offset += bh->b_size;
-			(*fsbs)++;
-		} while ((bh = bh->b_this_page) != head);
-
-		if (p_offset)
-			return page;
-	}
-
-out:
-	unlock_page(page);
-	return NULL;
-}
-
-/*
- * Look for a page at index which is unlocked and not mapped
- * yet - clustering for mmap write case.
+ * Look for a page at index that is suitable for clustering.
  */
 STATIC unsigned int
-xfs_probe_unmapped_page(
-	struct address_space	*mapping,
-	pgoff_t			index,
-	unsigned int		pg_offset)
+xfs_probe_page(
+	struct page		*page,
+	unsigned int		pg_offset,
+	int			mapped)
 {
-	struct page		*page;
 	int			ret = 0;
 
-	page = find_trylock_page(mapping, index);
-	if (!page)
-		return 0;
 	if (PageWriteback(page))
-		goto out;
+		return 0;
 
 	if (page->mapping && PageDirty(page)) {
 		if (page_has_buffers(page)) {
@@ -357,79 +487,101 @@
 
 			bh = head = page_buffers(page);
 			do {
-				if (buffer_mapped(bh) || !buffer_uptodate(bh))
+				if (!buffer_uptodate(bh))
+					break;
+				if (mapped != buffer_mapped(bh))
 					break;
 				ret += bh->b_size;
 				if (ret >= pg_offset)
 					break;
 			} while ((bh = bh->b_this_page) != head);
 		} else
-			ret = PAGE_CACHE_SIZE;
+			ret = mapped ? 0 : PAGE_CACHE_SIZE;
 	}
 
-out:
-	unlock_page(page);
 	return ret;
 }
 
-STATIC unsigned int
-xfs_probe_unmapped_cluster(
+STATIC size_t
+xfs_probe_cluster(
 	struct inode		*inode,
 	struct page		*startpage,
 	struct buffer_head	*bh,
-	struct buffer_head	*head)
+	struct buffer_head	*head,
+	int			mapped)
 {
+	struct pagevec		pvec;
 	pgoff_t			tindex, tlast, tloff;
-	unsigned int		pg_offset, len, total = 0;
-	struct address_space	*mapping = inode->i_mapping;
+	size_t			total = 0;
+	int			done = 0, i;
 
 	/* First sum forwards in this page */
 	do {
-		if (buffer_mapped(bh))
-			break;
+		if (mapped != buffer_mapped(bh))
+			return total;
 		total += bh->b_size;
 	} while ((bh = bh->b_this_page) != head);
 
-	/* If we reached the end of the page, sum forwards in
-	 * following pages.
-	 */
-	if (bh == head) {
-		tlast = i_size_read(inode) >> PAGE_CACHE_SHIFT;
-		/* Prune this back to avoid pathological behavior */
-		tloff = min(tlast, startpage->index + 64);
-		for (tindex = startpage->index + 1; tindex < tloff; tindex++) {
-			len = xfs_probe_unmapped_page(mapping, tindex,
-							PAGE_CACHE_SIZE);
-			if (!len)
-				return total;
+	/* if we reached the end of the page, sum forwards in following pages */
+	tlast = i_size_read(inode) >> PAGE_CACHE_SHIFT;
+	tindex = startpage->index + 1;
+
+	/* Prune this back to avoid pathological behavior */
+	tloff = min(tlast, startpage->index + 64);
+
+	pagevec_init(&pvec, 0);
+	while (!done && tindex <= tloff) {
+		unsigned len = min_t(pgoff_t, PAGEVEC_SIZE, tlast - tindex + 1);
+
+		if (!pagevec_lookup(&pvec, inode->i_mapping, tindex, len))
+			break;
+
+		for (i = 0; i < pagevec_count(&pvec); i++) {
+			struct page *page = pvec.pages[i];
+			size_t pg_offset, len = 0;
+
+			if (tindex == tlast) {
+				pg_offset =
+				    i_size_read(inode) & (PAGE_CACHE_SIZE - 1);
+				if (!pg_offset) {
+					done = 1;
+					break;
+				}
+			} else
+				pg_offset = PAGE_CACHE_SIZE;
+
+			if (page->index == tindex && !TestSetPageLocked(page)) {
+				len = xfs_probe_page(page, pg_offset, mapped);
+				unlock_page(page);
+			}
+
+			if (!len) {
+				done = 1;
+				break;
+			}
+
 			total += len;
+			tindex++;
 		}
-		if (tindex == tlast &&
-		    (pg_offset = i_size_read(inode) & (PAGE_CACHE_SIZE - 1))) {
-			total += xfs_probe_unmapped_page(mapping,
-							tindex, pg_offset);
-		}
+
+		pagevec_release(&pvec);
+		cond_resched();
 	}
+
 	return total;
 }
 
 /*
- * Probe for a given page (index) in the inode and test if it is delayed
- * and without unwritten buffers.  Returns page locked and with an extra
- * reference count.
+ * Test if a given page is suitable for writing as part of an unwritten
+ * or delayed allocate extent.
  */
-STATIC struct page *
-xfs_probe_delalloc_page(
-	struct inode		*inode,
-	pgoff_t			index)
+STATIC int
+xfs_is_delayed_page(
+	struct page		*page,
+	unsigned int		type)
 {
-	struct page		*page;
-
-	page = find_trylock_page(inode->i_mapping, index);
-	if (!page)
-		return NULL;
 	if (PageWriteback(page))
-		goto out;
+		return 0;
 
 	if (page->mapping && page_has_buffers(page)) {
 		struct buffer_head	*bh, *head;
@@ -437,243 +589,156 @@
 
 		bh = head = page_buffers(page);
 		do {
-			if (buffer_unwritten(bh)) {
-				acceptable = 0;
+			if (buffer_unwritten(bh))
+				acceptable = (type == IOMAP_UNWRITTEN);
+			else if (buffer_delay(bh))
+				acceptable = (type == IOMAP_DELAY);
+			else if (buffer_mapped(bh))
+				acceptable = (type == 0);
+			else
 				break;
-			} else if (buffer_delay(bh)) {
-				acceptable = 1;
-			}
 		} while ((bh = bh->b_this_page) != head);
 
 		if (acceptable)
-			return page;
+			return 1;
 	}
 
-out:
-	unlock_page(page);
-	return NULL;
-}
-
-STATIC int
-xfs_map_unwritten(
-	struct inode		*inode,
-	struct page		*start_page,
-	struct buffer_head	*head,
-	struct buffer_head	*curr,
-	unsigned long		p_offset,
-	int			block_bits,
-	xfs_iomap_t		*iomapp,
-	struct writeback_control *wbc,
-	int			startio,
-	int			all_bh)
-{
-	struct buffer_head	*bh = curr;
-	xfs_iomap_t		*tmp;
-	xfs_ioend_t		*ioend;
-	loff_t			offset;
-	unsigned long		nblocks = 0;
-
-	offset = start_page->index;
-	offset <<= PAGE_CACHE_SHIFT;
-	offset += p_offset;
-
-	ioend = xfs_alloc_ioend(inode);
-
-	/* First map forwards in the page consecutive buffers
-	 * covering this unwritten extent
-	 */
-	do {
-		if (!buffer_unwritten(bh))
-			break;
-		tmp = xfs_offset_to_map(start_page, iomapp, p_offset);
-		if (!tmp)
-			break;
-		xfs_map_at_offset(start_page, bh, p_offset, block_bits, iomapp);
-		set_buffer_unwritten_io(bh);
-		bh->b_private = ioend;
-		p_offset += bh->b_size;
-		nblocks++;
-	} while ((bh = bh->b_this_page) != head);
-
-	atomic_add(nblocks, &ioend->io_remaining);
-
-	/* If we reached the end of the page, map forwards in any
-	 * following pages which are also covered by this extent.
-	 */
-	if (bh == head) {
-		struct address_space	*mapping = inode->i_mapping;
-		pgoff_t			tindex, tloff, tlast;
-		unsigned long		bs;
-		unsigned int		pg_offset, bbits = inode->i_blkbits;
-		struct page		*page;
-
-		tlast = i_size_read(inode) >> PAGE_CACHE_SHIFT;
-		tloff = (iomapp->iomap_offset + iomapp->iomap_bsize) >> PAGE_CACHE_SHIFT;
-		tloff = min(tlast, tloff);
-		for (tindex = start_page->index + 1; tindex < tloff; tindex++) {
-			page = xfs_probe_unwritten_page(mapping,
-						tindex, iomapp, ioend,
-						PAGE_CACHE_SIZE, &bs, bbits);
-			if (!page)
-				break;
-			nblocks += bs;
-			atomic_add(bs, &ioend->io_remaining);
-			xfs_convert_page(inode, page, iomapp, wbc, ioend,
-							startio, all_bh);
-			/* stop if converting the next page might add
-			 * enough blocks that the corresponding byte
-			 * count won't fit in our ulong page buf length */
-			if (nblocks >= ((ULONG_MAX - PAGE_SIZE) >> block_bits))
-				goto enough;
-		}
-
-		if (tindex == tlast &&
-		    (pg_offset = (i_size_read(inode) & (PAGE_CACHE_SIZE - 1)))) {
-			page = xfs_probe_unwritten_page(mapping,
-							tindex, iomapp, ioend,
-							pg_offset, &bs, bbits);
-			if (page) {
-				nblocks += bs;
-				atomic_add(bs, &ioend->io_remaining);
-				xfs_convert_page(inode, page, iomapp, wbc, ioend,
-							startio, all_bh);
-				if (nblocks >= ((ULONG_MAX - PAGE_SIZE) >> block_bits))
-					goto enough;
-			}
-		}
-	}
-
-enough:
-	ioend->io_size = (xfs_off_t)nblocks << block_bits;
-	ioend->io_offset = offset;
-	xfs_finish_ioend(ioend);
 	return 0;
 }
 
-STATIC void
-xfs_submit_page(
-	struct page		*page,
-	struct writeback_control *wbc,
-	struct buffer_head	*bh_arr[],
-	int			bh_count,
-	int			probed_page,
-	int			clear_dirty)
-{
-	struct buffer_head	*bh;
-	int			i;
-
-	BUG_ON(PageWriteback(page));
-	if (bh_count)
-		set_page_writeback(page);
-	if (clear_dirty)
-		clear_page_dirty(page);
-	unlock_page(page);
-
-	if (bh_count) {
-		for (i = 0; i < bh_count; i++) {
-			bh = bh_arr[i];
-			mark_buffer_async_write(bh);
-			if (buffer_unwritten(bh))
-				set_buffer_unwritten_io(bh);
-			set_buffer_uptodate(bh);
-			clear_buffer_dirty(bh);
-		}
-
-		for (i = 0; i < bh_count; i++)
-			submit_bh(WRITE, bh_arr[i]);
-
-		if (probed_page && clear_dirty)
-			wbc->nr_to_write--;	/* Wrote an "extra" page */
-	}
-}
-
 /*
  * Allocate & map buffers for page given the extent map. Write it out.
  * except for the original page of a writepage, this is called on
  * delalloc/unwritten pages only, for the original page it is possible
  * that the page has no mapping at all.
  */
-STATIC void
+STATIC int
 xfs_convert_page(
 	struct inode		*inode,
 	struct page		*page,
-	xfs_iomap_t		*iomapp,
+	loff_t			tindex,
+	xfs_iomap_t		*mp,
+	xfs_ioend_t		**ioendp,
 	struct writeback_control *wbc,
-	void			*private,
 	int			startio,
 	int			all_bh)
 {
-	struct buffer_head	*bh_arr[MAX_BUF_PER_PAGE], *bh, *head;
-	xfs_iomap_t		*mp = iomapp, *tmp;
-	unsigned long		offset, end_offset;
-	int			index = 0;
+	struct buffer_head	*bh, *head;
+	xfs_off_t		end_offset;
+	unsigned long		p_offset;
+	unsigned int		type;
 	int			bbits = inode->i_blkbits;
 	int			len, page_dirty;
+	int			count = 0, done = 0, uptodate = 1;
+ 	xfs_off_t		offset = page_offset(page);
 
-	end_offset = (i_size_read(inode) & (PAGE_CACHE_SIZE - 1));
+	if (page->index != tindex)
+		goto fail;
+	if (TestSetPageLocked(page))
+		goto fail;
+	if (PageWriteback(page))
+		goto fail_unlock_page;
+	if (page->mapping != inode->i_mapping)
+		goto fail_unlock_page;
+	if (!xfs_is_delayed_page(page, (*ioendp)->io_type))
+		goto fail_unlock_page;
 
 	/*
 	 * page_dirty is initially a count of buffers on the page before
 	 * EOF and is decrememted as we move each into a cleanable state.
+	 *
+	 * Derivation:
+	 *
+	 * End offset is the highest offset that this page should represent.
+	 * If we are on the last page, (end_offset & (PAGE_CACHE_SIZE - 1))
+	 * will evaluate non-zero and be less than PAGE_CACHE_SIZE and
+	 * hence give us the correct page_dirty count. On any other page,
+	 * it will be zero and in that case we need page_dirty to be the
+	 * count of buffers on the page.
 	 */
-	len = 1 << inode->i_blkbits;
-	end_offset = max(end_offset, PAGE_CACHE_SIZE);
-	end_offset = roundup(end_offset, len);
-	page_dirty = end_offset / len;
+	end_offset = min_t(unsigned long long,
+			(xfs_off_t)(page->index + 1) << PAGE_CACHE_SHIFT,
+			i_size_read(inode));
 
-	offset = 0;
+	len = 1 << inode->i_blkbits;
+	p_offset = min_t(unsigned long, end_offset & (PAGE_CACHE_SIZE - 1),
+					PAGE_CACHE_SIZE);
+	p_offset = p_offset ? roundup(p_offset, len) : PAGE_CACHE_SIZE;
+	page_dirty = p_offset / len;
+
 	bh = head = page_buffers(page);
 	do {
 		if (offset >= end_offset)
 			break;
-		if (!(PageUptodate(page) || buffer_uptodate(bh)))
-			continue;
-		if (buffer_mapped(bh) && all_bh &&
-		    !(buffer_unwritten(bh) || buffer_delay(bh))) {
-			if (startio) {
-				lock_buffer(bh);
-				bh_arr[index++] = bh;
-				page_dirty--;
-			}
+		if (!buffer_uptodate(bh))
+			uptodate = 0;
+		if (!(PageUptodate(page) || buffer_uptodate(bh))) {
+			done = 1;
 			continue;
 		}
-		tmp = xfs_offset_to_map(page, mp, offset);
-		if (!tmp)
-			continue;
-		ASSERT(!(tmp->iomap_flags & IOMAP_HOLE));
-		ASSERT(!(tmp->iomap_flags & IOMAP_DELAY));
 
-		/* If this is a new unwritten extent buffer (i.e. one
-		 * that we haven't passed in private data for, we must
-		 * now map this buffer too.
-		 */
-		if (buffer_unwritten(bh) && !bh->b_end_io) {
-			ASSERT(tmp->iomap_flags & IOMAP_UNWRITTEN);
-			xfs_map_unwritten(inode, page, head, bh, offset,
-					bbits, tmp, wbc, startio, all_bh);
-		} else if (! (buffer_unwritten(bh) && buffer_locked(bh))) {
-			xfs_map_at_offset(page, bh, offset, bbits, tmp);
-			if (buffer_unwritten(bh)) {
-				set_buffer_unwritten_io(bh);
-				bh->b_private = private;
-				ASSERT(private);
+		if (buffer_unwritten(bh) || buffer_delay(bh)) {
+			if (buffer_unwritten(bh))
+				type = IOMAP_UNWRITTEN;
+			else
+				type = IOMAP_DELAY;
+
+			if (!xfs_iomap_valid(mp, offset)) {
+				done = 1;
+				continue;
+			}
+
+			ASSERT(!(mp->iomap_flags & IOMAP_HOLE));
+			ASSERT(!(mp->iomap_flags & IOMAP_DELAY));
+
+			xfs_map_at_offset(bh, offset, bbits, mp);
+			if (startio) {
+				xfs_add_to_ioend(inode, bh, offset,
+						type, ioendp, done);
+			} else {
+				set_buffer_dirty(bh);
+				unlock_buffer(bh);
+				mark_buffer_dirty(bh);
+			}
+			page_dirty--;
+			count++;
+		} else {
+			type = 0;
+			if (buffer_mapped(bh) && all_bh && startio) {
+				lock_buffer(bh);
+				xfs_add_to_ioend(inode, bh, offset,
+						type, ioendp, done);
+				count++;
+				page_dirty--;
+			} else {
+				done = 1;
 			}
 		}
-		if (startio) {
-			bh_arr[index++] = bh;
-		} else {
-			set_buffer_dirty(bh);
-			unlock_buffer(bh);
-			mark_buffer_dirty(bh);
-		}
-		page_dirty--;
 	} while (offset += len, (bh = bh->b_this_page) != head);
 
-	if (startio && index) {
-		xfs_submit_page(page, wbc, bh_arr, index, 1, !page_dirty);
-	} else {
-		unlock_page(page);
+	if (uptodate && bh == head)
+		SetPageUptodate(page);
+
+	if (startio) {
+		if (count) {
+			struct backing_dev_info *bdi;
+
+			bdi = inode->i_mapping->backing_dev_info;
+			if (bdi_write_congested(bdi)) {
+				wbc->encountered_congestion = 1;
+				done = 1;
+			} else if (--wbc->nr_to_write <= 0) {
+				done = 1;
+			}
+		}
+		xfs_start_page_writeback(page, wbc, !page_dirty, count);
 	}
+
+	return done;
+ fail_unlock_page:
+	unlock_page(page);
+ fail:
+	return 1;
 }
 
 /*
@@ -685,19 +750,31 @@
 	struct inode		*inode,
 	pgoff_t			tindex,
 	xfs_iomap_t		*iomapp,
+	xfs_ioend_t		**ioendp,
 	struct writeback_control *wbc,
 	int			startio,
 	int			all_bh,
 	pgoff_t			tlast)
 {
-	struct page		*page;
+	struct pagevec		pvec;
+	int			done = 0, i;
 
-	for (; tindex <= tlast; tindex++) {
-		page = xfs_probe_delalloc_page(inode, tindex);
-		if (!page)
+	pagevec_init(&pvec, 0);
+	while (!done && tindex <= tlast) {
+		unsigned len = min_t(pgoff_t, PAGEVEC_SIZE, tlast - tindex + 1);
+
+		if (!pagevec_lookup(&pvec, inode->i_mapping, tindex, len))
 			break;
-		xfs_convert_page(inode, page, iomapp, wbc, NULL,
-				startio, all_bh);
+
+		for (i = 0; i < pagevec_count(&pvec); i++) {
+			done = xfs_convert_page(inode, pvec.pages[i], tindex++,
+					iomapp, ioendp, wbc, startio, all_bh);
+			if (done)
+				break;
+		}
+
+		pagevec_release(&pvec);
+		cond_resched();
 	}
 }
 
@@ -728,18 +805,22 @@
 	int		startio,
 	int		unmapped) /* also implies page uptodate */
 {
-	struct buffer_head	*bh_arr[MAX_BUF_PER_PAGE], *bh, *head;
-	xfs_iomap_t		*iomp, iomap;
+	struct buffer_head	*bh, *head;
+	xfs_iomap_t		iomap;
+	xfs_ioend_t		*ioend = NULL, *iohead = NULL;
 	loff_t			offset;
 	unsigned long           p_offset = 0;
+	unsigned int		type;
 	__uint64_t              end_offset;
 	pgoff_t                 end_index, last_index, tlast;
-	int			len, err, i, cnt = 0, uptodate = 1;
-	int			flags;
-	int			page_dirty;
+	ssize_t			size, len;
+	int			flags, err, iomap_valid = 0, uptodate = 1;
+	int			page_dirty, count = 0, trylock_flag = 0;
+	int			all_bh = unmapped;
 
 	/* wait for other IO threads? */
-	flags = (startio && wbc->sync_mode != WB_SYNC_NONE) ? 0 : BMAPI_TRYLOCK;
+	if (startio && (wbc->sync_mode == WB_SYNC_NONE && wbc->nonblocking))
+		trylock_flag |= BMAPI_TRYLOCK;
 
 	/* Is this page beyond the end of the file? */
 	offset = i_size_read(inode);
@@ -754,161 +835,173 @@
 		}
 	}
 
-	end_offset = min_t(unsigned long long,
-			(loff_t)(page->index + 1) << PAGE_CACHE_SHIFT, offset);
-	offset = (loff_t)page->index << PAGE_CACHE_SHIFT;
-
 	/*
 	 * page_dirty is initially a count of buffers on the page before
 	 * EOF and is decrememted as we move each into a cleanable state.
-	 */
+	 *
+	 * Derivation:
+	 *
+	 * End offset is the highest offset that this page should represent.
+	 * If we are on the last page, (end_offset & (PAGE_CACHE_SIZE - 1))
+	 * will evaluate non-zero and be less than PAGE_CACHE_SIZE and
+	 * hence give us the correct page_dirty count. On any other page,
+	 * it will be zero and in that case we need page_dirty to be the
+	 * count of buffers on the page.
+ 	 */
+	end_offset = min_t(unsigned long long,
+			(xfs_off_t)(page->index + 1) << PAGE_CACHE_SHIFT, offset);
 	len = 1 << inode->i_blkbits;
-	p_offset = max(p_offset, PAGE_CACHE_SIZE);
-	p_offset = roundup(p_offset, len);
+	p_offset = min_t(unsigned long, end_offset & (PAGE_CACHE_SIZE - 1),
+					PAGE_CACHE_SIZE);
+	p_offset = p_offset ? roundup(p_offset, len) : PAGE_CACHE_SIZE;
 	page_dirty = p_offset / len;
 
-	iomp = NULL;
-	p_offset = 0;
 	bh = head = page_buffers(page);
+	offset = page_offset(page);
+	flags = -1;
+	type = 0;
+
+	/* TODO: cleanup count and page_dirty */
 
 	do {
 		if (offset >= end_offset)
 			break;
 		if (!buffer_uptodate(bh))
 			uptodate = 0;
-		if (!(PageUptodate(page) || buffer_uptodate(bh)) && !startio)
+		if (!(PageUptodate(page) || buffer_uptodate(bh)) && !startio) {
+			/*
+			 * the iomap is actually still valid, but the ioend
+			 * isn't.  shouldn't happen too often.
+			 */
+			iomap_valid = 0;
 			continue;
-
-		if (iomp) {
-			iomp = xfs_offset_to_map(page, &iomap, p_offset);
 		}
 
+		if (iomap_valid)
+			iomap_valid = xfs_iomap_valid(&iomap, offset);
+
 		/*
 		 * First case, map an unwritten extent and prepare for
 		 * extent state conversion transaction on completion.
-		 */
-		if (buffer_unwritten(bh)) {
-			if (!startio)
-				continue;
-			if (!iomp) {
-				err = xfs_map_blocks(inode, offset, len, &iomap,
-						BMAPI_WRITE|BMAPI_IGNSTATE);
-				if (err) {
-					goto error;
-				}
-				iomp = xfs_offset_to_map(page, &iomap,
-								p_offset);
-			}
-			if (iomp) {
-				if (!bh->b_end_io) {
-					err = xfs_map_unwritten(inode, page,
-							head, bh, p_offset,
-							inode->i_blkbits, iomp,
-							wbc, startio, unmapped);
-					if (err) {
-						goto error;
-					}
-				} else {
-					set_bit(BH_Lock, &bh->b_state);
-				}
-				BUG_ON(!buffer_locked(bh));
-				bh_arr[cnt++] = bh;
-				page_dirty--;
-			}
-		/*
+		 *
 		 * Second case, allocate space for a delalloc buffer.
 		 * We can return EAGAIN here in the release page case.
-		 */
-		} else if (buffer_delay(bh)) {
-			if (!iomp) {
-				err = xfs_map_blocks(inode, offset, len, &iomap,
-						BMAPI_ALLOCATE | flags);
-				if (err) {
-					goto error;
-				}
-				iomp = xfs_offset_to_map(page, &iomap,
-								p_offset);
+		 *
+		 * Third case, an unmapped buffer was found, and we are
+		 * in a path where we need to write the whole page out.
+ 		 */
+		if (buffer_unwritten(bh) || buffer_delay(bh) ||
+		    ((buffer_uptodate(bh) || PageUptodate(page)) &&
+		     !buffer_mapped(bh) && (unmapped || startio))) {
+		     	/*
+			 * Make sure we don't use a read-only iomap
+			 */
+		     	if (flags == BMAPI_READ)
+				iomap_valid = 0;
+
+			if (buffer_unwritten(bh)) {
+				type = IOMAP_UNWRITTEN;
+				flags = BMAPI_WRITE|BMAPI_IGNSTATE;
+			} else if (buffer_delay(bh)) {
+				type = IOMAP_DELAY;
+				flags = BMAPI_ALLOCATE;
+				if (!startio)
+					flags |= trylock_flag;
+			} else {
+				type = IOMAP_NEW;
+				flags = BMAPI_WRITE|BMAPI_MMAP;
 			}
-			if (iomp) {
-				xfs_map_at_offset(page, bh, p_offset,
-						inode->i_blkbits, iomp);
+
+			if (!iomap_valid) {
+				if (type == IOMAP_NEW) {
+					size = xfs_probe_cluster(inode,
+							page, bh, head, 0);
+				} else {
+					size = len;
+				}
+
+				err = xfs_map_blocks(inode, offset, size,
+						&iomap, flags);
+				if (err)
+					goto error;
+				iomap_valid = xfs_iomap_valid(&iomap, offset);
+			}
+			if (iomap_valid) {
+				xfs_map_at_offset(bh, offset,
+						inode->i_blkbits, &iomap);
 				if (startio) {
-					bh_arr[cnt++] = bh;
+					xfs_add_to_ioend(inode, bh, offset,
+							type, &ioend,
+							!iomap_valid);
 				} else {
 					set_buffer_dirty(bh);
 					unlock_buffer(bh);
 					mark_buffer_dirty(bh);
 				}
 				page_dirty--;
+				count++;
+			}
+		} else if (buffer_uptodate(bh) && startio) {
+			/*
+			 * we got here because the buffer is already mapped.
+			 * That means it must already have extents allocated
+			 * underneath it. Map the extent by reading it.
+			 */
+			if (!iomap_valid || type != 0) {
+				flags = BMAPI_READ;
+				size = xfs_probe_cluster(inode, page, bh,
+								head, 1);
+				err = xfs_map_blocks(inode, offset, size,
+						&iomap, flags);
+				if (err)
+					goto error;
+				iomap_valid = xfs_iomap_valid(&iomap, offset);
+			}
+
+			type = 0;
+			if (!test_and_set_bit(BH_Lock, &bh->b_state)) {
+				ASSERT(buffer_mapped(bh));
+				if (iomap_valid)
+					all_bh = 1;
+				xfs_add_to_ioend(inode, bh, offset, type,
+						&ioend, !iomap_valid);
+				page_dirty--;
+				count++;
+			} else {
+				iomap_valid = 0;
 			}
 		} else if ((buffer_uptodate(bh) || PageUptodate(page)) &&
 			   (unmapped || 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 (!iomp) {
-					size = xfs_probe_unmapped_cluster(
-							inode, page, bh, head);
-					err = xfs_map_blocks(inode, offset,
-							size, &iomap,
-							BMAPI_WRITE|BMAPI_MMAP);
-					if (err) {
-						goto error;
-					}
-					iomp = xfs_offset_to_map(page, &iomap,
-								     p_offset);
-				}
-				if (iomp) {
-					xfs_map_at_offset(page,
-							bh, p_offset,
-							inode->i_blkbits, iomp);
-					if (startio) {
-						bh_arr[cnt++] = bh;
-					} else {
-						set_buffer_dirty(bh);
-						unlock_buffer(bh);
-						mark_buffer_dirty(bh);
-					}
-					page_dirty--;
-				}
-			} else if (startio) {
-				if (buffer_uptodate(bh) &&
-				    !test_and_set_bit(BH_Lock, &bh->b_state)) {
-					bh_arr[cnt++] = bh;
-					page_dirty--;
-				}
-			}
+			iomap_valid = 0;
 		}
-	} while (offset += len, p_offset += len,
-		((bh = bh->b_this_page) != head));
+
+		if (!iohead)
+			iohead = ioend;
+
+	} while (offset += len, ((bh = bh->b_this_page) != head));
 
 	if (uptodate && bh == head)
 		SetPageUptodate(page);
 
-	if (startio) {
-		xfs_submit_page(page, wbc, bh_arr, cnt, 0, !page_dirty);
-	}
+	if (startio)
+		xfs_start_page_writeback(page, wbc, 1, count);
 
-	if (iomp) {
-		offset = (iomp->iomap_offset + iomp->iomap_bsize - 1) >>
+	if (ioend && iomap_valid) {
+		offset = (iomap.iomap_offset + iomap.iomap_bsize - 1) >>
 					PAGE_CACHE_SHIFT;
 		tlast = min_t(pgoff_t, offset, last_index);
-		xfs_cluster_write(inode, page->index + 1, iomp, wbc,
-					startio, unmapped, tlast);
+		xfs_cluster_write(inode, page->index + 1, &iomap, &ioend,
+					wbc, startio, all_bh, tlast);
 	}
 
+	if (iohead)
+		xfs_submit_ioend(iohead);
+
 	return page_dirty;
 
 error:
-	for (i = 0; i < cnt; i++) {
-		unlock_buffer(bh_arr[i]);
-	}
+	if (iohead)
+		xfs_cancel_ioend(iohead);
 
 	/*
 	 * If it's delalloc and we have nowhere to put it,
@@ -916,9 +1009,8 @@
 	 * us to try again.
 	 */
 	if (err != -EAGAIN) {
-		if (!unmapped) {
+		if (!unmapped)
 			block_invalidatepage(page, 0);
-		}
 		ClearPageUptodate(page);
 	}
 	return err;
@@ -982,7 +1074,7 @@
 	}
 
 	/* If this is a realtime file, data might be on a new device */
-	bh_result->b_bdev = iomap.iomap_target->pbr_bdev;
+	bh_result->b_bdev = iomap.iomap_target->bt_bdev;
 
 	/* If we previously allocated a block out beyond eof and
 	 * we are now coming back to use it then we will need to
@@ -1094,10 +1186,10 @@
 	if (error)
 		return -error;
 
-	iocb->private = xfs_alloc_ioend(inode);
+	iocb->private = xfs_alloc_ioend(inode, IOMAP_UNWRITTEN);
 
 	ret = blockdev_direct_IO_own_locking(rw, iocb, inode,
-		iomap.iomap_target->pbr_bdev,
+		iomap.iomap_target->bt_bdev,
 		iov, offset, nr_segs,
 		linvfs_get_blocks_direct,
 		linvfs_end_io_direct);
diff --git a/fs/xfs/linux-2.6/xfs_aops.h b/fs/xfs/linux-2.6/xfs_aops.h
index 4720758..55339dd 100644
--- a/fs/xfs/linux-2.6/xfs_aops.h
+++ b/fs/xfs/linux-2.6/xfs_aops.h
@@ -23,14 +23,24 @@
 
 typedef void (*xfs_ioend_func_t)(void *);
 
+/*
+ * xfs_ioend struct manages large extent writes for XFS.
+ * It can manage several multi-page bio's at once.
+ */
 typedef struct xfs_ioend {
+	struct xfs_ioend	*io_list;	/* next ioend in chain */
+	unsigned int		io_type;	/* delalloc / unwritten */
 	unsigned int		io_uptodate;	/* I/O status register */
 	atomic_t		io_remaining;	/* hold count */
 	struct vnode		*io_vnode;	/* file being written to */
 	struct buffer_head	*io_buffer_head;/* buffer linked list head */
+	struct buffer_head	*io_buffer_tail;/* buffer linked list tail */
 	size_t			io_size;	/* size of the extent */
 	xfs_off_t		io_offset;	/* offset in the file */
 	struct work_struct	io_work;	/* xfsdatad work queue */
 } xfs_ioend_t;
 
+extern struct address_space_operations linvfs_aops;
+extern int linvfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
+
 #endif /* __XFS_IOPS_H__ */
diff --git a/fs/xfs/linux-2.6/xfs_buf.c b/fs/xfs/linux-2.6/xfs_buf.c
index 6fe21d2..e44b7c1 100644
--- a/fs/xfs/linux-2.6/xfs_buf.c
+++ b/fs/xfs/linux-2.6/xfs_buf.c
@@ -31,76 +31,77 @@
 #include <linux/kthread.h>
 #include "xfs_linux.h"
 
-STATIC kmem_cache_t *pagebuf_zone;
-STATIC kmem_shaker_t pagebuf_shake;
+STATIC kmem_zone_t *xfs_buf_zone;
+STATIC kmem_shaker_t xfs_buf_shake;
+STATIC int xfsbufd(void *);
 STATIC int xfsbufd_wakeup(int, gfp_t);
-STATIC void pagebuf_delwri_queue(xfs_buf_t *, int);
+STATIC void xfs_buf_delwri_queue(xfs_buf_t *, int);
 
 STATIC struct workqueue_struct *xfslogd_workqueue;
 struct workqueue_struct *xfsdatad_workqueue;
 
-#ifdef PAGEBUF_TRACE
+#ifdef XFS_BUF_TRACE
 void
-pagebuf_trace(
-	xfs_buf_t	*pb,
+xfs_buf_trace(
+	xfs_buf_t	*bp,
 	char		*id,
 	void		*data,
 	void		*ra)
 {
-	ktrace_enter(pagebuf_trace_buf,
-		pb, id,
-		(void *)(unsigned long)pb->pb_flags,
-		(void *)(unsigned long)pb->pb_hold.counter,
-		(void *)(unsigned long)pb->pb_sema.count.counter,
+	ktrace_enter(xfs_buf_trace_buf,
+		bp, id,
+		(void *)(unsigned long)bp->b_flags,
+		(void *)(unsigned long)bp->b_hold.counter,
+		(void *)(unsigned long)bp->b_sema.count.counter,
 		(void *)current,
 		data, ra,
-		(void *)(unsigned long)((pb->pb_file_offset>>32) & 0xffffffff),
-		(void *)(unsigned long)(pb->pb_file_offset & 0xffffffff),
-		(void *)(unsigned long)pb->pb_buffer_length,
+		(void *)(unsigned long)((bp->b_file_offset>>32) & 0xffffffff),
+		(void *)(unsigned long)(bp->b_file_offset & 0xffffffff),
+		(void *)(unsigned long)bp->b_buffer_length,
 		NULL, NULL, NULL, NULL, NULL);
 }
-ktrace_t *pagebuf_trace_buf;
-#define PAGEBUF_TRACE_SIZE	4096
-#define PB_TRACE(pb, id, data)	\
-	pagebuf_trace(pb, id, (void *)data, (void *)__builtin_return_address(0))
+ktrace_t *xfs_buf_trace_buf;
+#define XFS_BUF_TRACE_SIZE	4096
+#define XB_TRACE(bp, id, data)	\
+	xfs_buf_trace(bp, id, (void *)data, (void *)__builtin_return_address(0))
 #else
-#define PB_TRACE(pb, id, data)	do { } while (0)
+#define XB_TRACE(bp, id, data)	do { } while (0)
 #endif
 
-#ifdef PAGEBUF_LOCK_TRACKING
-# define PB_SET_OWNER(pb)	((pb)->pb_last_holder = current->pid)
-# define PB_CLEAR_OWNER(pb)	((pb)->pb_last_holder = -1)
-# define PB_GET_OWNER(pb)	((pb)->pb_last_holder)
+#ifdef XFS_BUF_LOCK_TRACKING
+# define XB_SET_OWNER(bp)	((bp)->b_last_holder = current->pid)
+# define XB_CLEAR_OWNER(bp)	((bp)->b_last_holder = -1)
+# define XB_GET_OWNER(bp)	((bp)->b_last_holder)
 #else
-# define PB_SET_OWNER(pb)	do { } while (0)
-# define PB_CLEAR_OWNER(pb)	do { } while (0)
-# define PB_GET_OWNER(pb)	do { } while (0)
+# define XB_SET_OWNER(bp)	do { } while (0)
+# define XB_CLEAR_OWNER(bp)	do { } while (0)
+# define XB_GET_OWNER(bp)	do { } while (0)
 #endif
 
-#define pb_to_gfp(flags) \
-	((((flags) & PBF_READ_AHEAD) ? __GFP_NORETRY : \
-	  ((flags) & PBF_DONT_BLOCK) ? GFP_NOFS : GFP_KERNEL) | __GFP_NOWARN)
+#define xb_to_gfp(flags) \
+	((((flags) & XBF_READ_AHEAD) ? __GFP_NORETRY : \
+	  ((flags) & XBF_DONT_BLOCK) ? GFP_NOFS : GFP_KERNEL) | __GFP_NOWARN)
 
-#define pb_to_km(flags) \
-	 (((flags) & PBF_DONT_BLOCK) ? KM_NOFS : KM_SLEEP)
+#define xb_to_km(flags) \
+	 (((flags) & XBF_DONT_BLOCK) ? KM_NOFS : KM_SLEEP)
 
-#define pagebuf_allocate(flags) \
-	kmem_zone_alloc(pagebuf_zone, pb_to_km(flags))
-#define pagebuf_deallocate(pb) \
-	kmem_zone_free(pagebuf_zone, (pb));
+#define xfs_buf_allocate(flags) \
+	kmem_zone_alloc(xfs_buf_zone, xb_to_km(flags))
+#define xfs_buf_deallocate(bp) \
+	kmem_zone_free(xfs_buf_zone, (bp));
 
 /*
- * Page Region interfaces.
+ *	Page Region interfaces.
  *
- * For pages in filesystems where the blocksize is smaller than the
- * pagesize, we use the page->private field (long) to hold a bitmap
- * of uptodate regions within the page.
+ *	For pages in filesystems where the blocksize is smaller than the
+ *	pagesize, we use the page->private field (long) to hold a bitmap
+ * 	of uptodate regions within the page.
  *
- * Each such region is "bytes per page / bits per long" bytes long.
+ *	Each such region is "bytes per page / bits per long" bytes long.
  *
- * NBPPR == number-of-bytes-per-page-region
- * BTOPR == bytes-to-page-region (rounded up)
- * BTOPRT == bytes-to-page-region-truncated (rounded down)
+ *	NBPPR == number-of-bytes-per-page-region
+ *	BTOPR == bytes-to-page-region (rounded up)
+ *	BTOPRT == bytes-to-page-region-truncated (rounded down)
  */
 #if (BITS_PER_LONG == 32)
 #define PRSHIFT		(PAGE_CACHE_SHIFT - 5)	/* (32 == 1<<5) */
@@ -159,7 +160,7 @@
 }
 
 /*
- * Mapping of multi-page buffers into contiguous virtual space
+ *	Mapping of multi-page buffers into contiguous virtual space
  */
 
 typedef struct a_list {
@@ -172,7 +173,7 @@
 STATIC DEFINE_SPINLOCK(as_lock);
 
 /*
- * Try to batch vunmaps because they are costly.
+ *	Try to batch vunmaps because they are costly.
  */
 STATIC void
 free_address(
@@ -215,83 +216,83 @@
 }
 
 /*
- *	Internal pagebuf object manipulation
+ *	Internal xfs_buf_t object manipulation
  */
 
 STATIC void
-_pagebuf_initialize(
-	xfs_buf_t		*pb,
+_xfs_buf_initialize(
+	xfs_buf_t		*bp,
 	xfs_buftarg_t		*target,
-	loff_t			range_base,
+	xfs_off_t		range_base,
 	size_t			range_length,
-	page_buf_flags_t	flags)
+	xfs_buf_flags_t		flags)
 {
 	/*
-	 * We don't want certain flags to appear in pb->pb_flags.
+	 * We don't want certain flags to appear in b_flags.
 	 */
-	flags &= ~(PBF_LOCK|PBF_MAPPED|PBF_DONT_BLOCK|PBF_READ_AHEAD);
+	flags &= ~(XBF_LOCK|XBF_MAPPED|XBF_DONT_BLOCK|XBF_READ_AHEAD);
 
-	memset(pb, 0, sizeof(xfs_buf_t));
-	atomic_set(&pb->pb_hold, 1);
-	init_MUTEX_LOCKED(&pb->pb_iodonesema);
-	INIT_LIST_HEAD(&pb->pb_list);
-	INIT_LIST_HEAD(&pb->pb_hash_list);
-	init_MUTEX_LOCKED(&pb->pb_sema); /* held, no waiters */
-	PB_SET_OWNER(pb);
-	pb->pb_target = target;
-	pb->pb_file_offset = range_base;
+	memset(bp, 0, sizeof(xfs_buf_t));
+	atomic_set(&bp->b_hold, 1);
+	init_MUTEX_LOCKED(&bp->b_iodonesema);
+	INIT_LIST_HEAD(&bp->b_list);
+	INIT_LIST_HEAD(&bp->b_hash_list);
+	init_MUTEX_LOCKED(&bp->b_sema); /* held, no waiters */
+	XB_SET_OWNER(bp);
+	bp->b_target = target;
+	bp->b_file_offset = range_base;
 	/*
 	 * Set buffer_length and count_desired to the same value initially.
 	 * I/O routines should use count_desired, which will be the same in
 	 * most cases but may be reset (e.g. XFS recovery).
 	 */
-	pb->pb_buffer_length = pb->pb_count_desired = range_length;
-	pb->pb_flags = flags;
-	pb->pb_bn = XFS_BUF_DADDR_NULL;
-	atomic_set(&pb->pb_pin_count, 0);
-	init_waitqueue_head(&pb->pb_waiters);
+	bp->b_buffer_length = bp->b_count_desired = range_length;
+	bp->b_flags = flags;
+	bp->b_bn = XFS_BUF_DADDR_NULL;
+	atomic_set(&bp->b_pin_count, 0);
+	init_waitqueue_head(&bp->b_waiters);
 
-	XFS_STATS_INC(pb_create);
-	PB_TRACE(pb, "initialize", target);
+	XFS_STATS_INC(xb_create);
+	XB_TRACE(bp, "initialize", target);
 }
 
 /*
- * Allocate a page array capable of holding a specified number
- * of pages, and point the page buf at it.
+ *	Allocate a page array capable of holding a specified number
+ *	of pages, and point the page buf at it.
  */
 STATIC int
-_pagebuf_get_pages(
-	xfs_buf_t		*pb,
+_xfs_buf_get_pages(
+	xfs_buf_t		*bp,
 	int			page_count,
-	page_buf_flags_t	flags)
+	xfs_buf_flags_t		flags)
 {
 	/* Make sure that we have a page list */
-	if (pb->pb_pages == NULL) {
-		pb->pb_offset = page_buf_poff(pb->pb_file_offset);
-		pb->pb_page_count = page_count;
-		if (page_count <= PB_PAGES) {
-			pb->pb_pages = pb->pb_page_array;
+	if (bp->b_pages == NULL) {
+		bp->b_offset = xfs_buf_poff(bp->b_file_offset);
+		bp->b_page_count = page_count;
+		if (page_count <= XB_PAGES) {
+			bp->b_pages = bp->b_page_array;
 		} else {
-			pb->pb_pages = kmem_alloc(sizeof(struct page *) *
-					page_count, pb_to_km(flags));
-			if (pb->pb_pages == NULL)
+			bp->b_pages = kmem_alloc(sizeof(struct page *) *
+					page_count, xb_to_km(flags));
+			if (bp->b_pages == NULL)
 				return -ENOMEM;
 		}
-		memset(pb->pb_pages, 0, sizeof(struct page *) * page_count);
+		memset(bp->b_pages, 0, sizeof(struct page *) * page_count);
 	}
 	return 0;
 }
 
 /*
- *	Frees pb_pages if it was malloced.
+ *	Frees b_pages if it was allocated.
  */
 STATIC void
-_pagebuf_free_pages(
+_xfs_buf_free_pages(
 	xfs_buf_t	*bp)
 {
-	if (bp->pb_pages != bp->pb_page_array) {
-		kmem_free(bp->pb_pages,
-			  bp->pb_page_count * sizeof(struct page *));
+	if (bp->b_pages != bp->b_page_array) {
+		kmem_free(bp->b_pages,
+			  bp->b_page_count * sizeof(struct page *));
 	}
 }
 
@@ -299,79 +300,79 @@
  *	Releases the specified buffer.
  *
  * 	The modification state of any associated pages is left unchanged.
- * 	The buffer most not be on any hash - use pagebuf_rele instead for
+ * 	The buffer most not be on any hash - use xfs_buf_rele instead for
  * 	hashed and refcounted buffers
  */
 void
-pagebuf_free(
+xfs_buf_free(
 	xfs_buf_t		*bp)
 {
-	PB_TRACE(bp, "free", 0);
+	XB_TRACE(bp, "free", 0);
 
-	ASSERT(list_empty(&bp->pb_hash_list));
+	ASSERT(list_empty(&bp->b_hash_list));
 
-	if (bp->pb_flags & _PBF_PAGE_CACHE) {
+	if (bp->b_flags & _XBF_PAGE_CACHE) {
 		uint		i;
 
-		if ((bp->pb_flags & PBF_MAPPED) && (bp->pb_page_count > 1))
-			free_address(bp->pb_addr - bp->pb_offset);
+		if ((bp->b_flags & XBF_MAPPED) && (bp->b_page_count > 1))
+			free_address(bp->b_addr - bp->b_offset);
 
-		for (i = 0; i < bp->pb_page_count; i++)
-			page_cache_release(bp->pb_pages[i]);
-		_pagebuf_free_pages(bp);
-	} else if (bp->pb_flags & _PBF_KMEM_ALLOC) {
+		for (i = 0; i < bp->b_page_count; i++)
+			page_cache_release(bp->b_pages[i]);
+		_xfs_buf_free_pages(bp);
+	} else if (bp->b_flags & _XBF_KMEM_ALLOC) {
 		 /*
-		  * XXX(hch): bp->pb_count_desired might be incorrect (see
-		  * pagebuf_associate_memory for details), but fortunately
+		  * XXX(hch): bp->b_count_desired might be incorrect (see
+		  * xfs_buf_associate_memory for details), but fortunately
 		  * the Linux version of kmem_free ignores the len argument..
 		  */
-		kmem_free(bp->pb_addr, bp->pb_count_desired);
-		_pagebuf_free_pages(bp);
+		kmem_free(bp->b_addr, bp->b_count_desired);
+		_xfs_buf_free_pages(bp);
 	}
 
-	pagebuf_deallocate(bp);
+	xfs_buf_deallocate(bp);
 }
 
 /*
  *	Finds all pages for buffer in question and builds it's page list.
  */
 STATIC int
-_pagebuf_lookup_pages(
+_xfs_buf_lookup_pages(
 	xfs_buf_t		*bp,
 	uint			flags)
 {
-	struct address_space	*mapping = bp->pb_target->pbr_mapping;
-	size_t			blocksize = bp->pb_target->pbr_bsize;
-	size_t			size = bp->pb_count_desired;
+	struct address_space	*mapping = bp->b_target->bt_mapping;
+	size_t			blocksize = bp->b_target->bt_bsize;
+	size_t			size = bp->b_count_desired;
 	size_t			nbytes, offset;
-	gfp_t			gfp_mask = pb_to_gfp(flags);
+	gfp_t			gfp_mask = xb_to_gfp(flags);
 	unsigned short		page_count, i;
 	pgoff_t			first;
-	loff_t			end;
+	xfs_off_t		end;
 	int			error;
 
-	end = bp->pb_file_offset + bp->pb_buffer_length;
-	page_count = page_buf_btoc(end) - page_buf_btoct(bp->pb_file_offset);
+	end = bp->b_file_offset + bp->b_buffer_length;
+	page_count = xfs_buf_btoc(end) - xfs_buf_btoct(bp->b_file_offset);
 
-	error = _pagebuf_get_pages(bp, page_count, flags);
+	error = _xfs_buf_get_pages(bp, page_count, flags);
 	if (unlikely(error))
 		return error;
-	bp->pb_flags |= _PBF_PAGE_CACHE;
+	bp->b_flags |= _XBF_PAGE_CACHE;
 
-	offset = bp->pb_offset;
-	first = bp->pb_file_offset >> PAGE_CACHE_SHIFT;
+	offset = bp->b_offset;
+	first = bp->b_file_offset >> PAGE_CACHE_SHIFT;
 
-	for (i = 0; i < bp->pb_page_count; i++) {
+	for (i = 0; i < bp->b_page_count; i++) {
 		struct page	*page;
 		uint		retries = 0;
 
 	      retry:
 		page = find_or_create_page(mapping, first + i, gfp_mask);
 		if (unlikely(page == NULL)) {
-			if (flags & PBF_READ_AHEAD) {
-				bp->pb_page_count = i;
-				for (i = 0; i < bp->pb_page_count; i++)
-					unlock_page(bp->pb_pages[i]);
+			if (flags & XBF_READ_AHEAD) {
+				bp->b_page_count = i;
+				for (i = 0; i < bp->b_page_count; i++)
+					unlock_page(bp->b_pages[i]);
 				return -ENOMEM;
 			}
 
@@ -387,13 +388,13 @@
 					"deadlock in %s (mode:0x%x)\n",
 					__FUNCTION__, gfp_mask);
 
-			XFS_STATS_INC(pb_page_retries);
+			XFS_STATS_INC(xb_page_retries);
 			xfsbufd_wakeup(0, gfp_mask);
 			blk_congestion_wait(WRITE, HZ/50);
 			goto retry;
 		}
 
-		XFS_STATS_INC(pb_page_found);
+		XFS_STATS_INC(xb_page_found);
 
 		nbytes = min_t(size_t, size, PAGE_CACHE_SIZE - offset);
 		size -= nbytes;
@@ -401,27 +402,27 @@
 		if (!PageUptodate(page)) {
 			page_count--;
 			if (blocksize >= PAGE_CACHE_SIZE) {
-				if (flags & PBF_READ)
-					bp->pb_locked = 1;
+				if (flags & XBF_READ)
+					bp->b_locked = 1;
 			} else if (!PagePrivate(page)) {
 				if (test_page_region(page, offset, nbytes))
 					page_count++;
 			}
 		}
 
-		bp->pb_pages[i] = page;
+		bp->b_pages[i] = page;
 		offset = 0;
 	}
 
-	if (!bp->pb_locked) {
-		for (i = 0; i < bp->pb_page_count; i++)
-			unlock_page(bp->pb_pages[i]);
+	if (!bp->b_locked) {
+		for (i = 0; i < bp->b_page_count; i++)
+			unlock_page(bp->b_pages[i]);
 	}
 
-	if (page_count == bp->pb_page_count)
-		bp->pb_flags |= PBF_DONE;
+	if (page_count == bp->b_page_count)
+		bp->b_flags |= XBF_DONE;
 
-	PB_TRACE(bp, "lookup_pages", (long)page_count);
+	XB_TRACE(bp, "lookup_pages", (long)page_count);
 	return error;
 }
 
@@ -429,23 +430,23 @@
  *	Map buffer into kernel address-space if nessecary.
  */
 STATIC int
-_pagebuf_map_pages(
+_xfs_buf_map_pages(
 	xfs_buf_t		*bp,
 	uint			flags)
 {
 	/* A single page buffer is always mappable */
-	if (bp->pb_page_count == 1) {
-		bp->pb_addr = page_address(bp->pb_pages[0]) + bp->pb_offset;
-		bp->pb_flags |= PBF_MAPPED;
-	} else if (flags & PBF_MAPPED) {
+	if (bp->b_page_count == 1) {
+		bp->b_addr = page_address(bp->b_pages[0]) + bp->b_offset;
+		bp->b_flags |= XBF_MAPPED;
+	} else if (flags & XBF_MAPPED) {
 		if (as_list_len > 64)
 			purge_addresses();
-		bp->pb_addr = vmap(bp->pb_pages, bp->pb_page_count,
-				VM_MAP, PAGE_KERNEL);
-		if (unlikely(bp->pb_addr == NULL))
+		bp->b_addr = vmap(bp->b_pages, bp->b_page_count,
+					VM_MAP, PAGE_KERNEL);
+		if (unlikely(bp->b_addr == NULL))
 			return -ENOMEM;
-		bp->pb_addr += bp->pb_offset;
-		bp->pb_flags |= PBF_MAPPED;
+		bp->b_addr += bp->b_offset;
+		bp->b_flags |= XBF_MAPPED;
 	}
 
 	return 0;
@@ -456,9 +457,7 @@
  */
 
 /*
- *	_pagebuf_find
- *
- *	Looks up, and creates if absent, a lockable buffer for
+ *	Look up, and creates if absent, a lockable buffer for
  *	a given range of an inode.  The buffer is returned
  *	locked.	 If other overlapping buffers exist, they are
  *	released before the new buffer is created and locked,
@@ -466,55 +465,55 @@
  *	are unlocked.  No I/O is implied by this call.
  */
 xfs_buf_t *
-_pagebuf_find(
+_xfs_buf_find(
 	xfs_buftarg_t		*btp,	/* block device target		*/
-	loff_t			ioff,	/* starting offset of range	*/
+	xfs_off_t		ioff,	/* starting offset of range	*/
 	size_t			isize,	/* length of range		*/
-	page_buf_flags_t	flags,	/* PBF_TRYLOCK			*/
-	xfs_buf_t		*new_pb)/* newly allocated buffer	*/
+	xfs_buf_flags_t		flags,
+	xfs_buf_t		*new_bp)
 {
-	loff_t			range_base;
+	xfs_off_t		range_base;
 	size_t			range_length;
 	xfs_bufhash_t		*hash;
-	xfs_buf_t		*pb, *n;
+	xfs_buf_t		*bp, *n;
 
 	range_base = (ioff << BBSHIFT);
 	range_length = (isize << BBSHIFT);
 
 	/* Check for IOs smaller than the sector size / not sector aligned */
-	ASSERT(!(range_length < (1 << btp->pbr_sshift)));
-	ASSERT(!(range_base & (loff_t)btp->pbr_smask));
+	ASSERT(!(range_length < (1 << btp->bt_sshift)));
+	ASSERT(!(range_base & (xfs_off_t)btp->bt_smask));
 
 	hash = &btp->bt_hash[hash_long((unsigned long)ioff, btp->bt_hashshift)];
 
 	spin_lock(&hash->bh_lock);
 
-	list_for_each_entry_safe(pb, n, &hash->bh_list, pb_hash_list) {
-		ASSERT(btp == pb->pb_target);
-		if (pb->pb_file_offset == range_base &&
-		    pb->pb_buffer_length == range_length) {
+	list_for_each_entry_safe(bp, n, &hash->bh_list, b_hash_list) {
+		ASSERT(btp == bp->b_target);
+		if (bp->b_file_offset == range_base &&
+		    bp->b_buffer_length == range_length) {
 			/*
-			 * If we look at something bring it to the
+			 * If we look at something, bring it to the
 			 * front of the list for next time.
 			 */
-			atomic_inc(&pb->pb_hold);
-			list_move(&pb->pb_hash_list, &hash->bh_list);
+			atomic_inc(&bp->b_hold);
+			list_move(&bp->b_hash_list, &hash->bh_list);
 			goto found;
 		}
 	}
 
 	/* No match found */
-	if (new_pb) {
-		_pagebuf_initialize(new_pb, btp, range_base,
+	if (new_bp) {
+		_xfs_buf_initialize(new_bp, btp, range_base,
 				range_length, flags);
-		new_pb->pb_hash = hash;
-		list_add(&new_pb->pb_hash_list, &hash->bh_list);
+		new_bp->b_hash = hash;
+		list_add(&new_bp->b_hash_list, &hash->bh_list);
 	} else {
-		XFS_STATS_INC(pb_miss_locked);
+		XFS_STATS_INC(xb_miss_locked);
 	}
 
 	spin_unlock(&hash->bh_lock);
-	return new_pb;
+	return new_bp;
 
 found:
 	spin_unlock(&hash->bh_lock);
@@ -523,74 +522,72 @@
 	 * if this does not work then we need to drop the
 	 * spinlock and do a hard attempt on the semaphore.
 	 */
-	if (down_trylock(&pb->pb_sema)) {
-		if (!(flags & PBF_TRYLOCK)) {
+	if (down_trylock(&bp->b_sema)) {
+		if (!(flags & XBF_TRYLOCK)) {
 			/* wait for buffer ownership */
-			PB_TRACE(pb, "get_lock", 0);
-			pagebuf_lock(pb);
-			XFS_STATS_INC(pb_get_locked_waited);
+			XB_TRACE(bp, "get_lock", 0);
+			xfs_buf_lock(bp);
+			XFS_STATS_INC(xb_get_locked_waited);
 		} else {
 			/* We asked for a trylock and failed, no need
 			 * to look at file offset and length here, we
-			 * know that this pagebuf at least overlaps our
-			 * pagebuf and is locked, therefore our buffer
-			 * either does not exist, or is this buffer
+			 * know that this buffer at least overlaps our
+			 * buffer and is locked, therefore our buffer
+			 * either does not exist, or is this buffer.
 			 */
-
-			pagebuf_rele(pb);
-			XFS_STATS_INC(pb_busy_locked);
-			return (NULL);
+			xfs_buf_rele(bp);
+			XFS_STATS_INC(xb_busy_locked);
+			return NULL;
 		}
 	} else {
 		/* trylock worked */
-		PB_SET_OWNER(pb);
+		XB_SET_OWNER(bp);
 	}
 
-	if (pb->pb_flags & PBF_STALE) {
-		ASSERT((pb->pb_flags & _PBF_DELWRI_Q) == 0);
-		pb->pb_flags &= PBF_MAPPED;
+	if (bp->b_flags & XBF_STALE) {
+		ASSERT((bp->b_flags & _XBF_DELWRI_Q) == 0);
+		bp->b_flags &= XBF_MAPPED;
 	}
-	PB_TRACE(pb, "got_lock", 0);
-	XFS_STATS_INC(pb_get_locked);
-	return (pb);
+	XB_TRACE(bp, "got_lock", 0);
+	XFS_STATS_INC(xb_get_locked);
+	return bp;
 }
 
 /*
- *	xfs_buf_get_flags assembles a buffer covering the specified range.
- *
+ *	Assembles a buffer covering the specified range.
  *	Storage in memory for all portions of the buffer will be allocated,
  *	although backing storage may not be.
  */
 xfs_buf_t *
-xfs_buf_get_flags(			/* allocate a buffer		*/
+xfs_buf_get_flags(
 	xfs_buftarg_t		*target,/* target for buffer		*/
-	loff_t			ioff,	/* starting offset of range	*/
+	xfs_off_t		ioff,	/* starting offset of range	*/
 	size_t			isize,	/* length of range		*/
-	page_buf_flags_t	flags)	/* PBF_TRYLOCK			*/
+	xfs_buf_flags_t		flags)
 {
-	xfs_buf_t		*pb, *new_pb;
+	xfs_buf_t		*bp, *new_bp;
 	int			error = 0, i;
 
-	new_pb = pagebuf_allocate(flags);
-	if (unlikely(!new_pb))
+	new_bp = xfs_buf_allocate(flags);
+	if (unlikely(!new_bp))
 		return NULL;
 
-	pb = _pagebuf_find(target, ioff, isize, flags, new_pb);
-	if (pb == new_pb) {
-		error = _pagebuf_lookup_pages(pb, flags);
+	bp = _xfs_buf_find(target, ioff, isize, flags, new_bp);
+	if (bp == new_bp) {
+		error = _xfs_buf_lookup_pages(bp, flags);
 		if (error)
 			goto no_buffer;
 	} else {
-		pagebuf_deallocate(new_pb);
-		if (unlikely(pb == NULL))
+		xfs_buf_deallocate(new_bp);
+		if (unlikely(bp == NULL))
 			return NULL;
 	}
 
-	for (i = 0; i < pb->pb_page_count; i++)
-		mark_page_accessed(pb->pb_pages[i]);
+	for (i = 0; i < bp->b_page_count; i++)
+		mark_page_accessed(bp->b_pages[i]);
 
-	if (!(pb->pb_flags & PBF_MAPPED)) {
-		error = _pagebuf_map_pages(pb, flags);
+	if (!(bp->b_flags & XBF_MAPPED)) {
+		error = _xfs_buf_map_pages(bp, flags);
 		if (unlikely(error)) {
 			printk(KERN_WARNING "%s: failed to map pages\n",
 					__FUNCTION__);
@@ -598,97 +595,97 @@
 		}
 	}
 
-	XFS_STATS_INC(pb_get);
+	XFS_STATS_INC(xb_get);
 
 	/*
 	 * Always fill in the block number now, the mapped cases can do
 	 * their own overlay of this later.
 	 */
-	pb->pb_bn = ioff;
-	pb->pb_count_desired = pb->pb_buffer_length;
+	bp->b_bn = ioff;
+	bp->b_count_desired = bp->b_buffer_length;
 
-	PB_TRACE(pb, "get", (unsigned long)flags);
-	return pb;
+	XB_TRACE(bp, "get", (unsigned long)flags);
+	return bp;
 
  no_buffer:
-	if (flags & (PBF_LOCK | PBF_TRYLOCK))
-		pagebuf_unlock(pb);
-	pagebuf_rele(pb);
+	if (flags & (XBF_LOCK | XBF_TRYLOCK))
+		xfs_buf_unlock(bp);
+	xfs_buf_rele(bp);
 	return NULL;
 }
 
 xfs_buf_t *
 xfs_buf_read_flags(
 	xfs_buftarg_t		*target,
-	loff_t			ioff,
+	xfs_off_t		ioff,
 	size_t			isize,
-	page_buf_flags_t	flags)
+	xfs_buf_flags_t		flags)
 {
-	xfs_buf_t		*pb;
+	xfs_buf_t		*bp;
 
-	flags |= PBF_READ;
+	flags |= XBF_READ;
 
-	pb = xfs_buf_get_flags(target, ioff, isize, flags);
-	if (pb) {
-		if (!XFS_BUF_ISDONE(pb)) {
-			PB_TRACE(pb, "read", (unsigned long)flags);
-			XFS_STATS_INC(pb_get_read);
-			pagebuf_iostart(pb, flags);
-		} else if (flags & PBF_ASYNC) {
-			PB_TRACE(pb, "read_async", (unsigned long)flags);
+	bp = xfs_buf_get_flags(target, ioff, isize, flags);
+	if (bp) {
+		if (!XFS_BUF_ISDONE(bp)) {
+			XB_TRACE(bp, "read", (unsigned long)flags);
+			XFS_STATS_INC(xb_get_read);
+			xfs_buf_iostart(bp, flags);
+		} else if (flags & XBF_ASYNC) {
+			XB_TRACE(bp, "read_async", (unsigned long)flags);
 			/*
 			 * Read ahead call which is already satisfied,
 			 * drop the buffer
 			 */
 			goto no_buffer;
 		} else {
-			PB_TRACE(pb, "read_done", (unsigned long)flags);
+			XB_TRACE(bp, "read_done", (unsigned long)flags);
 			/* We do not want read in the flags */
-			pb->pb_flags &= ~PBF_READ;
+			bp->b_flags &= ~XBF_READ;
 		}
 	}
 
-	return pb;
+	return bp;
 
  no_buffer:
-	if (flags & (PBF_LOCK | PBF_TRYLOCK))
-		pagebuf_unlock(pb);
-	pagebuf_rele(pb);
+	if (flags & (XBF_LOCK | XBF_TRYLOCK))
+		xfs_buf_unlock(bp);
+	xfs_buf_rele(bp);
 	return NULL;
 }
 
 /*
- * If we are not low on memory then do the readahead in a deadlock
- * safe manner.
+ *	If we are not low on memory then do the readahead in a deadlock
+ *	safe manner.
  */
 void
-pagebuf_readahead(
+xfs_buf_readahead(
 	xfs_buftarg_t		*target,
-	loff_t			ioff,
+	xfs_off_t		ioff,
 	size_t			isize,
-	page_buf_flags_t	flags)
+	xfs_buf_flags_t		flags)
 {
 	struct backing_dev_info *bdi;
 
-	bdi = target->pbr_mapping->backing_dev_info;
+	bdi = target->bt_mapping->backing_dev_info;
 	if (bdi_read_congested(bdi))
 		return;
 
-	flags |= (PBF_TRYLOCK|PBF_ASYNC|PBF_READ_AHEAD);
+	flags |= (XBF_TRYLOCK|XBF_ASYNC|XBF_READ_AHEAD);
 	xfs_buf_read_flags(target, ioff, isize, flags);
 }
 
 xfs_buf_t *
-pagebuf_get_empty(
+xfs_buf_get_empty(
 	size_t			len,
 	xfs_buftarg_t		*target)
 {
-	xfs_buf_t		*pb;
+	xfs_buf_t		*bp;
 
-	pb = pagebuf_allocate(0);
-	if (pb)
-		_pagebuf_initialize(pb, target, 0, len, 0);
-	return pb;
+	bp = xfs_buf_allocate(0);
+	if (bp)
+		_xfs_buf_initialize(bp, target, 0, len, 0);
+	return bp;
 }
 
 static inline struct page *
@@ -704,8 +701,8 @@
 }
 
 int
-pagebuf_associate_memory(
-	xfs_buf_t		*pb,
+xfs_buf_associate_memory(
+	xfs_buf_t		*bp,
 	void			*mem,
 	size_t			len)
 {
@@ -722,40 +719,40 @@
 		page_count++;
 
 	/* Free any previous set of page pointers */
-	if (pb->pb_pages)
-		_pagebuf_free_pages(pb);
+	if (bp->b_pages)
+		_xfs_buf_free_pages(bp);
 
-	pb->pb_pages = NULL;
-	pb->pb_addr = mem;
+	bp->b_pages = NULL;
+	bp->b_addr = mem;
 
-	rval = _pagebuf_get_pages(pb, page_count, 0);
+	rval = _xfs_buf_get_pages(bp, page_count, 0);
 	if (rval)
 		return rval;
 
-	pb->pb_offset = offset;
+	bp->b_offset = offset;
 	ptr = (size_t) mem & PAGE_CACHE_MASK;
 	end = PAGE_CACHE_ALIGN((size_t) mem + len);
 	end_cur = end;
 	/* set up first page */
-	pb->pb_pages[0] = mem_to_page(mem);
+	bp->b_pages[0] = mem_to_page(mem);
 
 	ptr += PAGE_CACHE_SIZE;
-	pb->pb_page_count = ++i;
+	bp->b_page_count = ++i;
 	while (ptr < end) {
-		pb->pb_pages[i] = mem_to_page((void *)ptr);
-		pb->pb_page_count = ++i;
+		bp->b_pages[i] = mem_to_page((void *)ptr);
+		bp->b_page_count = ++i;
 		ptr += PAGE_CACHE_SIZE;
 	}
-	pb->pb_locked = 0;
+	bp->b_locked = 0;
 
-	pb->pb_count_desired = pb->pb_buffer_length = len;
-	pb->pb_flags |= PBF_MAPPED;
+	bp->b_count_desired = bp->b_buffer_length = len;
+	bp->b_flags |= XBF_MAPPED;
 
 	return 0;
 }
 
 xfs_buf_t *
-pagebuf_get_no_daddr(
+xfs_buf_get_noaddr(
 	size_t			len,
 	xfs_buftarg_t		*target)
 {
@@ -764,10 +761,10 @@
 	void			*data;
 	int			error;
 
-	bp = pagebuf_allocate(0);
+	bp = xfs_buf_allocate(0);
 	if (unlikely(bp == NULL))
 		goto fail;
-	_pagebuf_initialize(bp, target, 0, len, 0);
+	_xfs_buf_initialize(bp, target, 0, len, 0);
 
  try_again:
 	data = kmem_alloc(malloc_len, KM_SLEEP | KM_MAYFAIL);
@@ -776,78 +773,73 @@
 
 	/* check whether alignment matches.. */
 	if ((__psunsigned_t)data !=
-	    ((__psunsigned_t)data & ~target->pbr_smask)) {
+	    ((__psunsigned_t)data & ~target->bt_smask)) {
 		/* .. else double the size and try again */
 		kmem_free(data, malloc_len);
 		malloc_len <<= 1;
 		goto try_again;
 	}
 
-	error = pagebuf_associate_memory(bp, data, len);
+	error = xfs_buf_associate_memory(bp, data, len);
 	if (error)
 		goto fail_free_mem;
-	bp->pb_flags |= _PBF_KMEM_ALLOC;
+	bp->b_flags |= _XBF_KMEM_ALLOC;
 
-	pagebuf_unlock(bp);
+	xfs_buf_unlock(bp);
 
-	PB_TRACE(bp, "no_daddr", data);
+	XB_TRACE(bp, "no_daddr", data);
 	return bp;
  fail_free_mem:
 	kmem_free(data, malloc_len);
  fail_free_buf:
-	pagebuf_free(bp);
+	xfs_buf_free(bp);
  fail:
 	return NULL;
 }
 
 /*
- *	pagebuf_hold
- *
  *	Increment reference count on buffer, to hold the buffer concurrently
  *	with another thread which may release (free) the buffer asynchronously.
- *
  *	Must hold the buffer already to call this function.
  */
 void
-pagebuf_hold(
-	xfs_buf_t		*pb)
+xfs_buf_hold(
+	xfs_buf_t		*bp)
 {
-	atomic_inc(&pb->pb_hold);
-	PB_TRACE(pb, "hold", 0);
+	atomic_inc(&bp->b_hold);
+	XB_TRACE(bp, "hold", 0);
 }
 
 /*
- *	pagebuf_rele
- *
- *	pagebuf_rele releases a hold on the specified buffer.  If the
- *	the hold count is 1, pagebuf_rele calls pagebuf_free.
+ *	Releases a hold on the specified buffer.  If the
+ *	the hold count is 1, calls xfs_buf_free.
  */
 void
-pagebuf_rele(
-	xfs_buf_t		*pb)
+xfs_buf_rele(
+	xfs_buf_t		*bp)
 {
-	xfs_bufhash_t		*hash = pb->pb_hash;
+	xfs_bufhash_t		*hash = bp->b_hash;
 
-	PB_TRACE(pb, "rele", pb->pb_relse);
+	XB_TRACE(bp, "rele", bp->b_relse);
 
-	if (atomic_dec_and_lock(&pb->pb_hold, &hash->bh_lock)) {
-		if (pb->pb_relse) {
-			atomic_inc(&pb->pb_hold);
+	if (atomic_dec_and_lock(&bp->b_hold, &hash->bh_lock)) {
+		if (bp->b_relse) {
+			atomic_inc(&bp->b_hold);
 			spin_unlock(&hash->bh_lock);
-			(*(pb->pb_relse)) (pb);
-		} else if (pb->pb_flags & PBF_FS_MANAGED) {
+			(*(bp->b_relse)) (bp);
+		} else if (bp->b_flags & XBF_FS_MANAGED) {
 			spin_unlock(&hash->bh_lock);
 		} else {
-			ASSERT(!(pb->pb_flags & (PBF_DELWRI|_PBF_DELWRI_Q)));
-			list_del_init(&pb->pb_hash_list);
+			ASSERT(!(bp->b_flags & (XBF_DELWRI|_XBF_DELWRI_Q)));
+			list_del_init(&bp->b_hash_list);
 			spin_unlock(&hash->bh_lock);
-			pagebuf_free(pb);
+			xfs_buf_free(bp);
 		}
 	} else {
 		/*
 		 * Catch reference count leaks
 		 */
-		ASSERT(atomic_read(&pb->pb_hold) >= 0);
+		ASSERT(atomic_read(&bp->b_hold) >= 0);
 	}
 }
 
@@ -863,168 +855,122 @@
  */
 
 /*
- *	pagebuf_cond_lock
- *
- *	pagebuf_cond_lock locks a buffer object, if it is not already locked.
- *	Note that this in no way
- *	locks the underlying pages, so it is only useful for synchronizing
- *	concurrent use of page buffer objects, not for synchronizing independent
- *	access to the underlying pages.
+ *	Locks a buffer object, if it is not already locked.
+ *	Note that this in no way locks the underlying pages, so it is only
+ *	useful for synchronizing concurrent use of buffer objects, not for
+ *	synchronizing independent access to the underlying pages.
  */
 int
-pagebuf_cond_lock(			/* lock buffer, if not locked	*/
-					/* returns -EBUSY if locked)	*/
-	xfs_buf_t		*pb)
+xfs_buf_cond_lock(
+	xfs_buf_t		*bp)
 {
 	int			locked;
 
-	locked = down_trylock(&pb->pb_sema) == 0;
+	locked = down_trylock(&bp->b_sema) == 0;
 	if (locked) {
-		PB_SET_OWNER(pb);
+		XB_SET_OWNER(bp);
 	}
-	PB_TRACE(pb, "cond_lock", (long)locked);
-	return(locked ? 0 : -EBUSY);
+	XB_TRACE(bp, "cond_lock", (long)locked);
+	return locked ? 0 : -EBUSY;
 }
 
 #if defined(DEBUG) || defined(XFS_BLI_TRACE)
-/*
- *	pagebuf_lock_value
- *
- *	Return lock value for a pagebuf
- */
 int
-pagebuf_lock_value(
-	xfs_buf_t		*pb)
+xfs_buf_lock_value(
+	xfs_buf_t		*bp)
 {
-	return(atomic_read(&pb->pb_sema.count));
+	return atomic_read(&bp->b_sema.count);
 }
 #endif
 
 /*
- *	pagebuf_lock
- *
- *	pagebuf_lock locks a buffer object.  Note that this in no way
- *	locks the underlying pages, so it is only useful for synchronizing
- *	concurrent use of page buffer objects, not for synchronizing independent
- *	access to the underlying pages.
+ *	Locks a buffer object.
+ *	Note that this in no way locks the underlying pages, so it is only
+ *	useful for synchronizing concurrent use of buffer objects, not for
+ *	synchronizing independent access to the underlying pages.
  */
-int
-pagebuf_lock(
-	xfs_buf_t		*pb)
+void
+xfs_buf_lock(
+	xfs_buf_t		*bp)
 {
-	PB_TRACE(pb, "lock", 0);
-	if (atomic_read(&pb->pb_io_remaining))
-		blk_run_address_space(pb->pb_target->pbr_mapping);
-	down(&pb->pb_sema);
-	PB_SET_OWNER(pb);
-	PB_TRACE(pb, "locked", 0);
-	return 0;
+	XB_TRACE(bp, "lock", 0);
+	if (atomic_read(&bp->b_io_remaining))
+		blk_run_address_space(bp->b_target->bt_mapping);
+	down(&bp->b_sema);
+	XB_SET_OWNER(bp);
+	XB_TRACE(bp, "locked", 0);
 }
 
 /*
- *	pagebuf_unlock
- *
- *	pagebuf_unlock releases the lock on the buffer object created by
- *	pagebuf_lock or pagebuf_cond_lock (not any pinning of underlying pages
- *	created by pagebuf_pin).
- *
+ *	Releases the lock on the buffer object.
  *	If the buffer is marked delwri but is not queued, do so before we
- *	unlock the buffer as we need to set flags correctly. We also need to
+ *	unlock the buffer as we need to set flags correctly.  We also need to
  *	take a reference for the delwri queue because the unlocker is going to
  *	drop their's and they don't know we just queued it.
  */
 void
-pagebuf_unlock(				/* unlock buffer		*/
-	xfs_buf_t		*pb)	/* buffer to unlock		*/
+xfs_buf_unlock(
+	xfs_buf_t		*bp)
 {
-	if ((pb->pb_flags & (PBF_DELWRI|_PBF_DELWRI_Q)) == PBF_DELWRI) {
-		atomic_inc(&pb->pb_hold);
-		pb->pb_flags |= PBF_ASYNC;
-		pagebuf_delwri_queue(pb, 0);
+	if ((bp->b_flags & (XBF_DELWRI|_XBF_DELWRI_Q)) == XBF_DELWRI) {
+		atomic_inc(&bp->b_hold);
+		bp->b_flags |= XBF_ASYNC;
+		xfs_buf_delwri_queue(bp, 0);
 	}
 
-	PB_CLEAR_OWNER(pb);
-	up(&pb->pb_sema);
-	PB_TRACE(pb, "unlock", 0);
+	XB_CLEAR_OWNER(bp);
+	up(&bp->b_sema);
+	XB_TRACE(bp, "unlock", 0);
 }
 
 
 /*
  *	Pinning Buffer Storage in Memory
- */
-
-/*
- *	pagebuf_pin
- *
- *	pagebuf_pin locks all of the memory represented by a buffer in
- *	memory.  Multiple calls to pagebuf_pin and pagebuf_unpin, for
- *	the same or different buffers affecting a given page, will
- *	properly count the number of outstanding "pin" requests.  The
- *	buffer may be released after the pagebuf_pin and a different
- *	buffer used when calling pagebuf_unpin, if desired.
- *	pagebuf_pin should be used by the file system when it wants be
- *	assured that no attempt will be made to force the affected
- *	memory to disk.	 It does not assure that a given logical page
- *	will not be moved to a different physical page.
+ *	Ensure that no attempt to force a buffer to disk will succeed.
  */
 void
-pagebuf_pin(
-	xfs_buf_t		*pb)
+xfs_buf_pin(
+	xfs_buf_t		*bp)
 {
-	atomic_inc(&pb->pb_pin_count);
-	PB_TRACE(pb, "pin", (long)pb->pb_pin_count.counter);
+	atomic_inc(&bp->b_pin_count);
+	XB_TRACE(bp, "pin", (long)bp->b_pin_count.counter);
 }
 
-/*
- *	pagebuf_unpin
- *
- *	pagebuf_unpin reverses the locking of memory performed by
- *	pagebuf_pin.  Note that both functions affected the logical
- *	pages associated with the buffer, not the buffer itself.
- */
 void
-pagebuf_unpin(
-	xfs_buf_t		*pb)
+xfs_buf_unpin(
+	xfs_buf_t		*bp)
 {
-	if (atomic_dec_and_test(&pb->pb_pin_count)) {
-		wake_up_all(&pb->pb_waiters);
-	}
-	PB_TRACE(pb, "unpin", (long)pb->pb_pin_count.counter);
+	if (atomic_dec_and_test(&bp->b_pin_count))
+		wake_up_all(&bp->b_waiters);
+	XB_TRACE(bp, "unpin", (long)bp->b_pin_count.counter);
 }
 
 int
-pagebuf_ispin(
-	xfs_buf_t		*pb)
+xfs_buf_ispin(
+	xfs_buf_t		*bp)
 {
-	return atomic_read(&pb->pb_pin_count);
+	return atomic_read(&bp->b_pin_count);
 }
 
-/*
- *	pagebuf_wait_unpin
- *
- *	pagebuf_wait_unpin waits until all of the memory associated
- *	with the buffer is not longer locked in memory.  It returns
- *	immediately if none of the affected pages are locked.
- */
-static inline void
-_pagebuf_wait_unpin(
-	xfs_buf_t		*pb)
+STATIC void
+xfs_buf_wait_unpin(
+	xfs_buf_t		*bp)
 {
 	DECLARE_WAITQUEUE	(wait, current);
 
-	if (atomic_read(&pb->pb_pin_count) == 0)
+	if (atomic_read(&bp->b_pin_count) == 0)
 		return;
 
-	add_wait_queue(&pb->pb_waiters, &wait);
+	add_wait_queue(&bp->b_waiters, &wait);
 	for (;;) {
 		set_current_state(TASK_UNINTERRUPTIBLE);
-		if (atomic_read(&pb->pb_pin_count) == 0)
+		if (atomic_read(&bp->b_pin_count) == 0)
 			break;
-		if (atomic_read(&pb->pb_io_remaining))
-			blk_run_address_space(pb->pb_target->pbr_mapping);
+		if (atomic_read(&bp->b_io_remaining))
+			blk_run_address_space(bp->b_target->bt_mapping);
 		schedule();
 	}
-	remove_wait_queue(&pb->pb_waiters, &wait);
+	remove_wait_queue(&bp->b_waiters, &wait);
 	set_current_state(TASK_RUNNING);
 }
 
@@ -1032,241 +978,216 @@
  *	Buffer Utility Routines
  */
 
-/*
- *	pagebuf_iodone
- *
- *	pagebuf_iodone marks a buffer for which I/O is in progress
- *	done with respect to that I/O.	The pb_iodone routine, if
- *	present, will be called as a side-effect.
- */
 STATIC void
-pagebuf_iodone_work(
+xfs_buf_iodone_work(
 	void			*v)
 {
 	xfs_buf_t		*bp = (xfs_buf_t *)v;
 
-	if (bp->pb_iodone)
-		(*(bp->pb_iodone))(bp);
-	else if (bp->pb_flags & PBF_ASYNC)
+	if (bp->b_iodone)
+		(*(bp->b_iodone))(bp);
+	else if (bp->b_flags & XBF_ASYNC)
 		xfs_buf_relse(bp);
 }
 
 void
-pagebuf_iodone(
-	xfs_buf_t		*pb,
+xfs_buf_ioend(
+	xfs_buf_t		*bp,
 	int			schedule)
 {
-	pb->pb_flags &= ~(PBF_READ | PBF_WRITE);
-	if (pb->pb_error == 0)
-		pb->pb_flags |= PBF_DONE;
+	bp->b_flags &= ~(XBF_READ | XBF_WRITE);
+	if (bp->b_error == 0)
+		bp->b_flags |= XBF_DONE;
 
-	PB_TRACE(pb, "iodone", pb->pb_iodone);
+	XB_TRACE(bp, "iodone", bp->b_iodone);
 
-	if ((pb->pb_iodone) || (pb->pb_flags & PBF_ASYNC)) {
+	if ((bp->b_iodone) || (bp->b_flags & XBF_ASYNC)) {
 		if (schedule) {
-			INIT_WORK(&pb->pb_iodone_work, pagebuf_iodone_work, pb);
-			queue_work(xfslogd_workqueue, &pb->pb_iodone_work);
+			INIT_WORK(&bp->b_iodone_work, xfs_buf_iodone_work, bp);
+			queue_work(xfslogd_workqueue, &bp->b_iodone_work);
 		} else {
-			pagebuf_iodone_work(pb);
+			xfs_buf_iodone_work(bp);
 		}
 	} else {
-		up(&pb->pb_iodonesema);
+		up(&bp->b_iodonesema);
 	}
 }
 
-/*
- *	pagebuf_ioerror
- *
- *	pagebuf_ioerror sets the error code for a buffer.
- */
 void
-pagebuf_ioerror(			/* mark/clear buffer error flag */
-	xfs_buf_t		*pb,	/* buffer to mark		*/
-	int			error)	/* error to store (0 if none)	*/
+xfs_buf_ioerror(
+	xfs_buf_t		*bp,
+	int			error)
 {
 	ASSERT(error >= 0 && error <= 0xffff);
-	pb->pb_error = (unsigned short)error;
-	PB_TRACE(pb, "ioerror", (unsigned long)error);
+	bp->b_error = (unsigned short)error;
+	XB_TRACE(bp, "ioerror", (unsigned long)error);
 }
 
 /*
- *	pagebuf_iostart
- *
- *	pagebuf_iostart initiates I/O on a buffer, based on the flags supplied.
- *	If necessary, it will arrange for any disk space allocation required,
- *	and it will break up the request if the block mappings require it.
- *	The pb_iodone routine in the buffer supplied will only be called
+ *	Initiate I/O on a buffer, based on the flags supplied.
+ *	The b_iodone routine in the buffer supplied will only be called
  *	when all of the subsidiary I/O requests, if any, have been completed.
- *	pagebuf_iostart calls the pagebuf_ioinitiate routine or
- *	pagebuf_iorequest, if the former routine is not defined, to start
- *	the I/O on a given low-level request.
  */
 int
-pagebuf_iostart(			/* start I/O on a buffer	  */
-	xfs_buf_t		*pb,	/* buffer to start		  */
-	page_buf_flags_t	flags)	/* PBF_LOCK, PBF_ASYNC, PBF_READ, */
-					/* PBF_WRITE, PBF_DELWRI,	  */
-					/* PBF_DONT_BLOCK		  */
+xfs_buf_iostart(
+	xfs_buf_t		*bp,
+	xfs_buf_flags_t		flags)
 {
 	int			status = 0;
 
-	PB_TRACE(pb, "iostart", (unsigned long)flags);
+	XB_TRACE(bp, "iostart", (unsigned long)flags);
 
-	if (flags & PBF_DELWRI) {
-		pb->pb_flags &= ~(PBF_READ | PBF_WRITE | PBF_ASYNC);
-		pb->pb_flags |= flags & (PBF_DELWRI | PBF_ASYNC);
-		pagebuf_delwri_queue(pb, 1);
+	if (flags & XBF_DELWRI) {
+		bp->b_flags &= ~(XBF_READ | XBF_WRITE | XBF_ASYNC);
+		bp->b_flags |= flags & (XBF_DELWRI | XBF_ASYNC);
+		xfs_buf_delwri_queue(bp, 1);
 		return status;
 	}
 
-	pb->pb_flags &= ~(PBF_READ | PBF_WRITE | PBF_ASYNC | PBF_DELWRI | \
-			PBF_READ_AHEAD | _PBF_RUN_QUEUES);
-	pb->pb_flags |= flags & (PBF_READ | PBF_WRITE | PBF_ASYNC | \
-			PBF_READ_AHEAD | _PBF_RUN_QUEUES);
+	bp->b_flags &= ~(XBF_READ | XBF_WRITE | XBF_ASYNC | XBF_DELWRI | \
+			XBF_READ_AHEAD | _XBF_RUN_QUEUES);
+	bp->b_flags |= flags & (XBF_READ | XBF_WRITE | XBF_ASYNC | \
+			XBF_READ_AHEAD | _XBF_RUN_QUEUES);
 
-	BUG_ON(pb->pb_bn == XFS_BUF_DADDR_NULL);
+	BUG_ON(bp->b_bn == XFS_BUF_DADDR_NULL);
 
 	/* For writes allow an alternate strategy routine to precede
 	 * the actual I/O request (which may not be issued at all in
 	 * a shutdown situation, for example).
 	 */
-	status = (flags & PBF_WRITE) ?
-		pagebuf_iostrategy(pb) : pagebuf_iorequest(pb);
+	status = (flags & XBF_WRITE) ?
+		xfs_buf_iostrategy(bp) : xfs_buf_iorequest(bp);
 
 	/* Wait for I/O if we are not an async request.
 	 * Note: async I/O request completion will release the buffer,
 	 * and that can already be done by this point.  So using the
 	 * buffer pointer from here on, after async I/O, is invalid.
 	 */
-	if (!status && !(flags & PBF_ASYNC))
-		status = pagebuf_iowait(pb);
+	if (!status && !(flags & XBF_ASYNC))
+		status = xfs_buf_iowait(bp);
 
 	return status;
 }
 
-/*
- * Helper routine for pagebuf_iorequest
- */
-
 STATIC __inline__ int
-_pagebuf_iolocked(
-	xfs_buf_t		*pb)
+_xfs_buf_iolocked(
+	xfs_buf_t		*bp)
 {
-	ASSERT(pb->pb_flags & (PBF_READ|PBF_WRITE));
-	if (pb->pb_flags & PBF_READ)
-		return pb->pb_locked;
+	ASSERT(bp->b_flags & (XBF_READ | XBF_WRITE));
+	if (bp->b_flags & XBF_READ)
+		return bp->b_locked;
 	return 0;
 }
 
 STATIC __inline__ void
-_pagebuf_iodone(
-	xfs_buf_t		*pb,
+_xfs_buf_ioend(
+	xfs_buf_t		*bp,
 	int			schedule)
 {
-	if (atomic_dec_and_test(&pb->pb_io_remaining) == 1) {
-		pb->pb_locked = 0;
-		pagebuf_iodone(pb, schedule);
+	if (atomic_dec_and_test(&bp->b_io_remaining) == 1) {
+		bp->b_locked = 0;
+		xfs_buf_ioend(bp, schedule);
 	}
 }
 
 STATIC int
-bio_end_io_pagebuf(
+xfs_buf_bio_end_io(
 	struct bio		*bio,
 	unsigned int		bytes_done,
 	int			error)
 {
-	xfs_buf_t		*pb = (xfs_buf_t *)bio->bi_private;
-	unsigned int		blocksize = pb->pb_target->pbr_bsize;
+	xfs_buf_t		*bp = (xfs_buf_t *)bio->bi_private;
+	unsigned int		blocksize = bp->b_target->bt_bsize;
 	struct bio_vec		*bvec = bio->bi_io_vec + bio->bi_vcnt - 1;
 
 	if (bio->bi_size)
 		return 1;
 
 	if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
-		pb->pb_error = EIO;
+		bp->b_error = EIO;
 
 	do {
 		struct page	*page = bvec->bv_page;
 
-		if (unlikely(pb->pb_error)) {
-			if (pb->pb_flags & PBF_READ)
+		if (unlikely(bp->b_error)) {
+			if (bp->b_flags & XBF_READ)
 				ClearPageUptodate(page);
 			SetPageError(page);
-		} else if (blocksize == PAGE_CACHE_SIZE) {
+		} else if (blocksize >= PAGE_CACHE_SIZE) {
 			SetPageUptodate(page);
 		} else if (!PagePrivate(page) &&
-				(pb->pb_flags & _PBF_PAGE_CACHE)) {
+				(bp->b_flags & _XBF_PAGE_CACHE)) {
 			set_page_region(page, bvec->bv_offset, bvec->bv_len);
 		}
 
 		if (--bvec >= bio->bi_io_vec)
 			prefetchw(&bvec->bv_page->flags);
 
-		if (_pagebuf_iolocked(pb)) {
+		if (_xfs_buf_iolocked(bp)) {
 			unlock_page(page);
 		}
 	} while (bvec >= bio->bi_io_vec);
 
-	_pagebuf_iodone(pb, 1);
+	_xfs_buf_ioend(bp, 1);
 	bio_put(bio);
 	return 0;
 }
 
 STATIC void
-_pagebuf_ioapply(
-	xfs_buf_t		*pb)
+_xfs_buf_ioapply(
+	xfs_buf_t		*bp)
 {
 	int			i, rw, map_i, total_nr_pages, nr_pages;
 	struct bio		*bio;
-	int			offset = pb->pb_offset;
-	int			size = pb->pb_count_desired;
-	sector_t		sector = pb->pb_bn;
-	unsigned int		blocksize = pb->pb_target->pbr_bsize;
-	int			locking = _pagebuf_iolocked(pb);
+	int			offset = bp->b_offset;
+	int			size = bp->b_count_desired;
+	sector_t		sector = bp->b_bn;
+	unsigned int		blocksize = bp->b_target->bt_bsize;
+	int			locking = _xfs_buf_iolocked(bp);
 
-	total_nr_pages = pb->pb_page_count;
+	total_nr_pages = bp->b_page_count;
 	map_i = 0;
 
-	if (pb->pb_flags & _PBF_RUN_QUEUES) {
-		pb->pb_flags &= ~_PBF_RUN_QUEUES;
-		rw = (pb->pb_flags & PBF_READ) ? READ_SYNC : WRITE_SYNC;
+	if (bp->b_flags & _XBF_RUN_QUEUES) {
+		bp->b_flags &= ~_XBF_RUN_QUEUES;
+		rw = (bp->b_flags & XBF_READ) ? READ_SYNC : WRITE_SYNC;
 	} else {
-		rw = (pb->pb_flags & PBF_READ) ? READ : WRITE;
+		rw = (bp->b_flags & XBF_READ) ? READ : WRITE;
 	}
 
-	if (pb->pb_flags & PBF_ORDERED) {
-		ASSERT(!(pb->pb_flags & PBF_READ));
+	if (bp->b_flags & XBF_ORDERED) {
+		ASSERT(!(bp->b_flags & XBF_READ));
 		rw = WRITE_BARRIER;
 	}
 
-	/* Special code path for reading a sub page size pagebuf in --
+	/* Special code path for reading a sub page size buffer in --
 	 * we populate up the whole page, and hence the other metadata
 	 * in the same page.  This optimization is only valid when the
-	 * filesystem block size and the page size are equal.
+	 * filesystem block size is not smaller than the page size.
 	 */
-	if ((pb->pb_buffer_length < PAGE_CACHE_SIZE) &&
-	    (pb->pb_flags & PBF_READ) && locking &&
-	    (blocksize == PAGE_CACHE_SIZE)) {
+	if ((bp->b_buffer_length < PAGE_CACHE_SIZE) &&
+	    (bp->b_flags & XBF_READ) && locking &&
+	    (blocksize >= PAGE_CACHE_SIZE)) {
 		bio = bio_alloc(GFP_NOIO, 1);
 
-		bio->bi_bdev = pb->pb_target->pbr_bdev;
+		bio->bi_bdev = bp->b_target->bt_bdev;
 		bio->bi_sector = sector - (offset >> BBSHIFT);
-		bio->bi_end_io = bio_end_io_pagebuf;
-		bio->bi_private = pb;
+		bio->bi_end_io = xfs_buf_bio_end_io;
+		bio->bi_private = bp;
 
-		bio_add_page(bio, pb->pb_pages[0], PAGE_CACHE_SIZE, 0);
+		bio_add_page(bio, bp->b_pages[0], PAGE_CACHE_SIZE, 0);
 		size = 0;
 
-		atomic_inc(&pb->pb_io_remaining);
+		atomic_inc(&bp->b_io_remaining);
 
 		goto submit_io;
 	}
 
 	/* Lock down the pages which we need to for the request */
-	if (locking && (pb->pb_flags & PBF_WRITE) && (pb->pb_locked == 0)) {
+	if (locking && (bp->b_flags & XBF_WRITE) && (bp->b_locked == 0)) {
 		for (i = 0; size; i++) {
 			int		nbytes = PAGE_CACHE_SIZE - offset;
-			struct page	*page = pb->pb_pages[i];
+			struct page	*page = bp->b_pages[i];
 
 			if (nbytes > size)
 				nbytes = size;
@@ -1276,30 +1197,30 @@
 			size -= nbytes;
 			offset = 0;
 		}
-		offset = pb->pb_offset;
-		size = pb->pb_count_desired;
+		offset = bp->b_offset;
+		size = bp->b_count_desired;
 	}
 
 next_chunk:
-	atomic_inc(&pb->pb_io_remaining);
+	atomic_inc(&bp->b_io_remaining);
 	nr_pages = BIO_MAX_SECTORS >> (PAGE_SHIFT - BBSHIFT);
 	if (nr_pages > total_nr_pages)
 		nr_pages = total_nr_pages;
 
 	bio = bio_alloc(GFP_NOIO, nr_pages);
-	bio->bi_bdev = pb->pb_target->pbr_bdev;
+	bio->bi_bdev = bp->b_target->bt_bdev;
 	bio->bi_sector = sector;
-	bio->bi_end_io = bio_end_io_pagebuf;
-	bio->bi_private = pb;
+	bio->bi_end_io = xfs_buf_bio_end_io;
+	bio->bi_private = bp;
 
 	for (; size && nr_pages; nr_pages--, map_i++) {
-		int	nbytes = PAGE_CACHE_SIZE - offset;
+		int	rbytes, nbytes = PAGE_CACHE_SIZE - offset;
 
 		if (nbytes > size)
 			nbytes = size;
 
-		if (bio_add_page(bio, pb->pb_pages[map_i],
-					nbytes, offset) < nbytes)
+		rbytes = bio_add_page(bio, bp->b_pages[map_i], nbytes, offset);
+		if (rbytes < nbytes)
 			break;
 
 		offset = 0;
@@ -1315,107 +1236,102 @@
 			goto next_chunk;
 	} else {
 		bio_put(bio);
-		pagebuf_ioerror(pb, EIO);
+		xfs_buf_ioerror(bp, EIO);
 	}
 }
 
-/*
- *	pagebuf_iorequest -- the core I/O request routine.
- */
 int
-pagebuf_iorequest(			/* start real I/O		*/
-	xfs_buf_t		*pb)	/* buffer to convey to device	*/
+xfs_buf_iorequest(
+	xfs_buf_t		*bp)
 {
-	PB_TRACE(pb, "iorequest", 0);
+	XB_TRACE(bp, "iorequest", 0);
 
-	if (pb->pb_flags & PBF_DELWRI) {
-		pagebuf_delwri_queue(pb, 1);
+	if (bp->b_flags & XBF_DELWRI) {
+		xfs_buf_delwri_queue(bp, 1);
 		return 0;
 	}
 
-	if (pb->pb_flags & PBF_WRITE) {
-		_pagebuf_wait_unpin(pb);
+	if (bp->b_flags & XBF_WRITE) {
+		xfs_buf_wait_unpin(bp);
 	}
 
-	pagebuf_hold(pb);
+	xfs_buf_hold(bp);
 
 	/* Set the count to 1 initially, this will stop an I/O
 	 * completion callout which happens before we have started
-	 * all the I/O from calling pagebuf_iodone too early.
+	 * all the I/O from calling xfs_buf_ioend too early.
 	 */
-	atomic_set(&pb->pb_io_remaining, 1);
-	_pagebuf_ioapply(pb);
-	_pagebuf_iodone(pb, 0);
+	atomic_set(&bp->b_io_remaining, 1);
+	_xfs_buf_ioapply(bp);
+	_xfs_buf_ioend(bp, 0);
 
-	pagebuf_rele(pb);
+	xfs_buf_rele(bp);
 	return 0;
 }
 
 /*
- *	pagebuf_iowait
- *
- *	pagebuf_iowait waits for I/O to complete on the buffer supplied.
- *	It returns immediately if no I/O is pending.  In any case, it returns
- *	the error code, if any, or 0 if there is no error.
+ *	Waits for I/O to complete on the buffer supplied.
+ *	It returns immediately if no I/O is pending.
+ *	It returns the I/O error code, if any, or 0 if there was no error.
  */
 int
-pagebuf_iowait(
-	xfs_buf_t		*pb)
+xfs_buf_iowait(
+	xfs_buf_t		*bp)
 {
-	PB_TRACE(pb, "iowait", 0);
-	if (atomic_read(&pb->pb_io_remaining))
-		blk_run_address_space(pb->pb_target->pbr_mapping);
-	down(&pb->pb_iodonesema);
-	PB_TRACE(pb, "iowaited", (long)pb->pb_error);
-	return pb->pb_error;
+	XB_TRACE(bp, "iowait", 0);
+	if (atomic_read(&bp->b_io_remaining))
+		blk_run_address_space(bp->b_target->bt_mapping);
+	down(&bp->b_iodonesema);
+	XB_TRACE(bp, "iowaited", (long)bp->b_error);
+	return bp->b_error;
 }
 
-caddr_t
-pagebuf_offset(
-	xfs_buf_t		*pb,
+xfs_caddr_t
+xfs_buf_offset(
+	xfs_buf_t		*bp,
 	size_t			offset)
 {
 	struct page		*page;
 
-	offset += pb->pb_offset;
+	if (bp->b_flags & XBF_MAPPED)
+		return XFS_BUF_PTR(bp) + offset;
 
-	page = pb->pb_pages[offset >> PAGE_CACHE_SHIFT];
-	return (caddr_t) page_address(page) + (offset & (PAGE_CACHE_SIZE - 1));
+	offset += bp->b_offset;
+	page = bp->b_pages[offset >> PAGE_CACHE_SHIFT];
+	return (xfs_caddr_t)page_address(page) + (offset & (PAGE_CACHE_SIZE-1));
 }
 
 /*
- *	pagebuf_iomove
- *
  *	Move data into or out of a buffer.
  */
 void
-pagebuf_iomove(
-	xfs_buf_t		*pb,	/* buffer to process		*/
+xfs_buf_iomove(
+	xfs_buf_t		*bp,	/* buffer to process		*/
 	size_t			boff,	/* starting buffer offset	*/
 	size_t			bsize,	/* length to copy		*/
 	caddr_t			data,	/* data address			*/
-	page_buf_rw_t		mode)	/* read/write flag		*/
+	xfs_buf_rw_t		mode)	/* read/write/zero flag		*/
 {
 	size_t			bend, cpoff, csize;
 	struct page		*page;
 
 	bend = boff + bsize;
 	while (boff < bend) {
-		page = pb->pb_pages[page_buf_btoct(boff + pb->pb_offset)];
-		cpoff = page_buf_poff(boff + pb->pb_offset);
+		page = bp->b_pages[xfs_buf_btoct(boff + bp->b_offset)];
+		cpoff = xfs_buf_poff(boff + bp->b_offset);
 		csize = min_t(size_t,
-			      PAGE_CACHE_SIZE-cpoff, pb->pb_count_desired-boff);
+			      PAGE_CACHE_SIZE-cpoff, bp->b_count_desired-boff);
 
 		ASSERT(((csize + cpoff) <= PAGE_CACHE_SIZE));
 
 		switch (mode) {
-		case PBRW_ZERO:
+		case XBRW_ZERO:
 			memset(page_address(page) + cpoff, 0, csize);
 			break;
-		case PBRW_READ:
+		case XBRW_READ:
 			memcpy(data, page_address(page) + cpoff, csize);
 			break;
-		case PBRW_WRITE:
+		case XBRW_WRITE:
 			memcpy(page_address(page) + cpoff, data, csize);
 		}
 
@@ -1425,12 +1341,12 @@
 }
 
 /*
- *	Handling of buftargs.
+ *	Handling of buffer targets (buftargs).
  */
 
 /*
- * Wait for any bufs with callbacks that have been submitted but
- * have not yet returned... walk the hash list for the target.
+ *	Wait for any bufs with callbacks that have been submitted but
+ *	have not yet returned... walk the hash list for the target.
  */
 void
 xfs_wait_buftarg(
@@ -1444,15 +1360,15 @@
 		hash = &btp->bt_hash[i];
 again:
 		spin_lock(&hash->bh_lock);
-		list_for_each_entry_safe(bp, n, &hash->bh_list, pb_hash_list) {
-			ASSERT(btp == bp->pb_target);
-			if (!(bp->pb_flags & PBF_FS_MANAGED)) {
+		list_for_each_entry_safe(bp, n, &hash->bh_list, b_hash_list) {
+			ASSERT(btp == bp->b_target);
+			if (!(bp->b_flags & XBF_FS_MANAGED)) {
 				spin_unlock(&hash->bh_lock);
 				/*
 				 * Catch superblock reference count leaks
 				 * immediately
 				 */
-				BUG_ON(bp->pb_bn == 0);
+				BUG_ON(bp->b_bn == 0);
 				delay(100);
 				goto again;
 			}
@@ -1462,9 +1378,9 @@
 }
 
 /*
- * Allocate buffer hash table for a given target.
- * For devices containing metadata (i.e. not the log/realtime devices)
- * we need to allocate a much larger hash table.
+ *	Allocate buffer hash table for a given target.
+ *	For devices containing metadata (i.e. not the log/realtime devices)
+ *	we need to allocate a much larger hash table.
  */
 STATIC void
 xfs_alloc_bufhash(
@@ -1487,11 +1403,34 @@
 xfs_free_bufhash(
 	xfs_buftarg_t		*btp)
 {
-	kmem_free(btp->bt_hash,
-			(1 << btp->bt_hashshift) * sizeof(xfs_bufhash_t));
+	kmem_free(btp->bt_hash, (1<<btp->bt_hashshift) * sizeof(xfs_bufhash_t));
 	btp->bt_hash = NULL;
 }
 
+/*
+ *	buftarg list for delwrite queue processing
+ */
+STATIC LIST_HEAD(xfs_buftarg_list);
+STATIC DEFINE_SPINLOCK(xfs_buftarg_lock);
+
+STATIC void
+xfs_register_buftarg(
+	xfs_buftarg_t           *btp)
+{
+	spin_lock(&xfs_buftarg_lock);
+	list_add(&btp->bt_list, &xfs_buftarg_list);
+	spin_unlock(&xfs_buftarg_lock);
+}
+
+STATIC void
+xfs_unregister_buftarg(
+	xfs_buftarg_t           *btp)
+{
+	spin_lock(&xfs_buftarg_lock);
+	list_del(&btp->bt_list);
+	spin_unlock(&xfs_buftarg_lock);
+}
+
 void
 xfs_free_buftarg(
 	xfs_buftarg_t		*btp,
@@ -1499,9 +1438,16 @@
 {
 	xfs_flush_buftarg(btp, 1);
 	if (external)
-		xfs_blkdev_put(btp->pbr_bdev);
+		xfs_blkdev_put(btp->bt_bdev);
 	xfs_free_bufhash(btp);
-	iput(btp->pbr_mapping->host);
+	iput(btp->bt_mapping->host);
+
+	/* Unregister the buftarg first so that we don't get a
+	 * wakeup finding a non-existent task
+	 */
+	xfs_unregister_buftarg(btp);
+	kthread_stop(btp->bt_task);
+
 	kmem_free(btp, sizeof(*btp));
 }
 
@@ -1512,11 +1458,11 @@
 	unsigned int		sectorsize,
 	int			verbose)
 {
-	btp->pbr_bsize = blocksize;
-	btp->pbr_sshift = ffs(sectorsize) - 1;
-	btp->pbr_smask = sectorsize - 1;
+	btp->bt_bsize = blocksize;
+	btp->bt_sshift = ffs(sectorsize) - 1;
+	btp->bt_smask = sectorsize - 1;
 
-	if (set_blocksize(btp->pbr_bdev, sectorsize)) {
+	if (set_blocksize(btp->bt_bdev, sectorsize)) {
 		printk(KERN_WARNING
 			"XFS: Cannot set_blocksize to %u on device %s\n",
 			sectorsize, XFS_BUFTARG_NAME(btp));
@@ -1536,10 +1482,10 @@
 }
 
 /*
-* When allocating the initial buffer target we have not yet
-* read in the superblock, so don't know what sized sectors
-* are being used is at this early stage.  Play safe.
-*/
+ *	When allocating the initial buffer target we have not yet
+ *	read in the superblock, so don't know what sized sectors
+ *	are being used is at this early stage.  Play safe.
+ */
 STATIC int
 xfs_setsize_buftarg_early(
 	xfs_buftarg_t		*btp,
@@ -1587,10 +1533,30 @@
 	mapping->a_ops = &mapping_aops;
 	mapping->backing_dev_info = bdi;
 	mapping_set_gfp_mask(mapping, GFP_NOFS);
-	btp->pbr_mapping = mapping;
+	btp->bt_mapping = mapping;
 	return 0;
 }
 
+STATIC int
+xfs_alloc_delwrite_queue(
+	xfs_buftarg_t		*btp)
+{
+	int	error = 0;
+
+	INIT_LIST_HEAD(&btp->bt_list);
+	INIT_LIST_HEAD(&btp->bt_delwrite_queue);
+	spinlock_init(&btp->bt_delwrite_lock, "delwri_lock");
+	btp->bt_flags = 0;
+	btp->bt_task = kthread_run(xfsbufd, btp, "xfsbufd");
+	if (IS_ERR(btp->bt_task)) {
+		error = PTR_ERR(btp->bt_task);
+		goto out_error;
+	}
+	xfs_register_buftarg(btp);
+out_error:
+	return error;
+}
+
 xfs_buftarg_t *
 xfs_alloc_buftarg(
 	struct block_device	*bdev,
@@ -1600,12 +1566,14 @@
 
 	btp = kmem_zalloc(sizeof(*btp), KM_SLEEP);
 
-	btp->pbr_dev =  bdev->bd_dev;
-	btp->pbr_bdev = bdev;
+	btp->bt_dev =  bdev->bd_dev;
+	btp->bt_bdev = bdev;
 	if (xfs_setsize_buftarg_early(btp, bdev))
 		goto error;
 	if (xfs_mapping_buftarg(btp, bdev))
 		goto error;
+	if (xfs_alloc_delwrite_queue(btp))
+		goto error;
 	xfs_alloc_bufhash(btp, external);
 	return btp;
 
@@ -1616,83 +1584,81 @@
 
 
 /*
- * Pagebuf delayed write buffer handling
+ *	Delayed write buffer handling
  */
-
-STATIC LIST_HEAD(pbd_delwrite_queue);
-STATIC DEFINE_SPINLOCK(pbd_delwrite_lock);
-
 STATIC void
-pagebuf_delwri_queue(
-	xfs_buf_t		*pb,
+xfs_buf_delwri_queue(
+	xfs_buf_t		*bp,
 	int			unlock)
 {
-	PB_TRACE(pb, "delwri_q", (long)unlock);
-	ASSERT((pb->pb_flags & (PBF_DELWRI|PBF_ASYNC)) ==
-					(PBF_DELWRI|PBF_ASYNC));
+	struct list_head	*dwq = &bp->b_target->bt_delwrite_queue;
+	spinlock_t		*dwlk = &bp->b_target->bt_delwrite_lock;
 
-	spin_lock(&pbd_delwrite_lock);
+	XB_TRACE(bp, "delwri_q", (long)unlock);
+	ASSERT((bp->b_flags&(XBF_DELWRI|XBF_ASYNC)) == (XBF_DELWRI|XBF_ASYNC));
+
+	spin_lock(dwlk);
 	/* If already in the queue, dequeue and place at tail */
-	if (!list_empty(&pb->pb_list)) {
-		ASSERT(pb->pb_flags & _PBF_DELWRI_Q);
-		if (unlock) {
-			atomic_dec(&pb->pb_hold);
-		}
-		list_del(&pb->pb_list);
+	if (!list_empty(&bp->b_list)) {
+		ASSERT(bp->b_flags & _XBF_DELWRI_Q);
+		if (unlock)
+			atomic_dec(&bp->b_hold);
+		list_del(&bp->b_list);
 	}
 
-	pb->pb_flags |= _PBF_DELWRI_Q;
-	list_add_tail(&pb->pb_list, &pbd_delwrite_queue);
-	pb->pb_queuetime = jiffies;
-	spin_unlock(&pbd_delwrite_lock);
+	bp->b_flags |= _XBF_DELWRI_Q;
+	list_add_tail(&bp->b_list, dwq);
+	bp->b_queuetime = jiffies;
+	spin_unlock(dwlk);
 
 	if (unlock)
-		pagebuf_unlock(pb);
+		xfs_buf_unlock(bp);
 }
 
 void
-pagebuf_delwri_dequeue(
-	xfs_buf_t		*pb)
+xfs_buf_delwri_dequeue(
+	xfs_buf_t		*bp)
 {
+	spinlock_t		*dwlk = &bp->b_target->bt_delwrite_lock;
 	int			dequeued = 0;
 
-	spin_lock(&pbd_delwrite_lock);
-	if ((pb->pb_flags & PBF_DELWRI) && !list_empty(&pb->pb_list)) {
-		ASSERT(pb->pb_flags & _PBF_DELWRI_Q);
-		list_del_init(&pb->pb_list);
+	spin_lock(dwlk);
+	if ((bp->b_flags & XBF_DELWRI) && !list_empty(&bp->b_list)) {
+		ASSERT(bp->b_flags & _XBF_DELWRI_Q);
+		list_del_init(&bp->b_list);
 		dequeued = 1;
 	}
-	pb->pb_flags &= ~(PBF_DELWRI|_PBF_DELWRI_Q);
-	spin_unlock(&pbd_delwrite_lock);
+	bp->b_flags &= ~(XBF_DELWRI|_XBF_DELWRI_Q);
+	spin_unlock(dwlk);
 
 	if (dequeued)
-		pagebuf_rele(pb);
+		xfs_buf_rele(bp);
 
-	PB_TRACE(pb, "delwri_dq", (long)dequeued);
+	XB_TRACE(bp, "delwri_dq", (long)dequeued);
 }
 
 STATIC void
-pagebuf_runall_queues(
+xfs_buf_runall_queues(
 	struct workqueue_struct	*queue)
 {
 	flush_workqueue(queue);
 }
 
-/* Defines for pagebuf daemon */
-STATIC struct task_struct *xfsbufd_task;
-STATIC int xfsbufd_force_flush;
-STATIC int xfsbufd_force_sleep;
-
 STATIC int
 xfsbufd_wakeup(
 	int			priority,
 	gfp_t			mask)
 {
-	if (xfsbufd_force_sleep)
-		return 0;
-	xfsbufd_force_flush = 1;
-	barrier();
-	wake_up_process(xfsbufd_task);
+	xfs_buftarg_t		*btp;
+
+	spin_lock(&xfs_buftarg_lock);
+	list_for_each_entry(btp, &xfs_buftarg_list, bt_list) {
+		if (test_bit(XBT_FORCE_SLEEP, &btp->bt_flags))
+			continue;
+		set_bit(XBT_FORCE_FLUSH, &btp->bt_flags);
+		wake_up_process(btp->bt_task);
+	}
+	spin_unlock(&xfs_buftarg_lock);
 	return 0;
 }
 
@@ -1702,67 +1668,70 @@
 {
 	struct list_head	tmp;
 	unsigned long		age;
-	xfs_buftarg_t		*target;
-	xfs_buf_t		*pb, *n;
+	xfs_buftarg_t		*target = (xfs_buftarg_t *)data;
+	xfs_buf_t		*bp, *n;
+	struct list_head	*dwq = &target->bt_delwrite_queue;
+	spinlock_t		*dwlk = &target->bt_delwrite_lock;
 
 	current->flags |= PF_MEMALLOC;
 
 	INIT_LIST_HEAD(&tmp);
 	do {
 		if (unlikely(freezing(current))) {
-			xfsbufd_force_sleep = 1;
+			set_bit(XBT_FORCE_SLEEP, &target->bt_flags);
 			refrigerator();
 		} else {
-			xfsbufd_force_sleep = 0;
+			clear_bit(XBT_FORCE_SLEEP, &target->bt_flags);
 		}
 
 		schedule_timeout_interruptible(
 			xfs_buf_timer_centisecs * msecs_to_jiffies(10));
 
 		age = xfs_buf_age_centisecs * msecs_to_jiffies(10);
-		spin_lock(&pbd_delwrite_lock);
-		list_for_each_entry_safe(pb, n, &pbd_delwrite_queue, pb_list) {
-			PB_TRACE(pb, "walkq1", (long)pagebuf_ispin(pb));
-			ASSERT(pb->pb_flags & PBF_DELWRI);
+		spin_lock(dwlk);
+		list_for_each_entry_safe(bp, n, dwq, b_list) {
+			XB_TRACE(bp, "walkq1", (long)xfs_buf_ispin(bp));
+			ASSERT(bp->b_flags & XBF_DELWRI);
 
-			if (!pagebuf_ispin(pb) && !pagebuf_cond_lock(pb)) {
-				if (!xfsbufd_force_flush &&
+			if (!xfs_buf_ispin(bp) && !xfs_buf_cond_lock(bp)) {
+				if (!test_bit(XBT_FORCE_FLUSH,
+						&target->bt_flags) &&
 				    time_before(jiffies,
-						pb->pb_queuetime + age)) {
-					pagebuf_unlock(pb);
+						bp->b_queuetime + age)) {
+					xfs_buf_unlock(bp);
 					break;
 				}
 
-				pb->pb_flags &= ~(PBF_DELWRI|_PBF_DELWRI_Q);
-				pb->pb_flags |= PBF_WRITE;
-				list_move(&pb->pb_list, &tmp);
+				bp->b_flags &= ~(XBF_DELWRI|_XBF_DELWRI_Q);
+				bp->b_flags |= XBF_WRITE;
+				list_move(&bp->b_list, &tmp);
 			}
 		}
-		spin_unlock(&pbd_delwrite_lock);
+		spin_unlock(dwlk);
 
 		while (!list_empty(&tmp)) {
-			pb = list_entry(tmp.next, xfs_buf_t, pb_list);
-			target = pb->pb_target;
+			bp = list_entry(tmp.next, xfs_buf_t, b_list);
+			ASSERT(target == bp->b_target);
 
-			list_del_init(&pb->pb_list);
-			pagebuf_iostrategy(pb);
+			list_del_init(&bp->b_list);
+			xfs_buf_iostrategy(bp);
 
-			blk_run_address_space(target->pbr_mapping);
+			blk_run_address_space(target->bt_mapping);
 		}
 
 		if (as_list_len > 0)
 			purge_addresses();
 
-		xfsbufd_force_flush = 0;
+		clear_bit(XBT_FORCE_FLUSH, &target->bt_flags);
 	} while (!kthread_should_stop());
 
 	return 0;
 }
 
 /*
- * Go through all incore buffers, and release buffers if they belong to
- * the given device. This is used in filesystem error handling to
- * preserve the consistency of its metadata.
+ *	Go through all incore buffers, and release buffers if they belong to
+ *	the given device. This is used in filesystem error handling to
+ *	preserve the consistency of its metadata.
  */
 int
 xfs_flush_buftarg(
@@ -1770,73 +1739,72 @@
 	int			wait)
 {
 	struct list_head	tmp;
-	xfs_buf_t		*pb, *n;
+	xfs_buf_t		*bp, *n;
 	int			pincount = 0;
+	struct list_head	*dwq = &target->bt_delwrite_queue;
+	spinlock_t		*dwlk = &target->bt_delwrite_lock;
 
-	pagebuf_runall_queues(xfsdatad_workqueue);
-	pagebuf_runall_queues(xfslogd_workqueue);
+	xfs_buf_runall_queues(xfsdatad_workqueue);
+	xfs_buf_runall_queues(xfslogd_workqueue);
 
 	INIT_LIST_HEAD(&tmp);
-	spin_lock(&pbd_delwrite_lock);
-	list_for_each_entry_safe(pb, n, &pbd_delwrite_queue, pb_list) {
-
-		if (pb->pb_target != target)
-			continue;
-
-		ASSERT(pb->pb_flags & (PBF_DELWRI|_PBF_DELWRI_Q));
-		PB_TRACE(pb, "walkq2", (long)pagebuf_ispin(pb));
-		if (pagebuf_ispin(pb)) {
+	spin_lock(dwlk);
+	list_for_each_entry_safe(bp, n, dwq, b_list) {
+		ASSERT(bp->b_target == target);
+		ASSERT(bp->b_flags & (XBF_DELWRI | _XBF_DELWRI_Q));
+		XB_TRACE(bp, "walkq2", (long)xfs_buf_ispin(bp));
+		if (xfs_buf_ispin(bp)) {
 			pincount++;
 			continue;
 		}
 
-		list_move(&pb->pb_list, &tmp);
+		list_move(&bp->b_list, &tmp);
 	}
-	spin_unlock(&pbd_delwrite_lock);
+	spin_unlock(dwlk);
 
 	/*
 	 * Dropped the delayed write list lock, now walk the temporary list
 	 */
-	list_for_each_entry_safe(pb, n, &tmp, pb_list) {
-		pagebuf_lock(pb);
-		pb->pb_flags &= ~(PBF_DELWRI|_PBF_DELWRI_Q);
-		pb->pb_flags |= PBF_WRITE;
+	list_for_each_entry_safe(bp, n, &tmp, b_list) {
+		xfs_buf_lock(bp);
+		bp->b_flags &= ~(XBF_DELWRI|_XBF_DELWRI_Q);
+		bp->b_flags |= XBF_WRITE;
 		if (wait)
-			pb->pb_flags &= ~PBF_ASYNC;
+			bp->b_flags &= ~XBF_ASYNC;
 		else
-			list_del_init(&pb->pb_list);
+			list_del_init(&bp->b_list);
 
-		pagebuf_iostrategy(pb);
+		xfs_buf_iostrategy(bp);
 	}
 
 	/*
 	 * Remaining list items must be flushed before returning
 	 */
 	while (!list_empty(&tmp)) {
-		pb = list_entry(tmp.next, xfs_buf_t, pb_list);
+		bp = list_entry(tmp.next, xfs_buf_t, b_list);
 
-		list_del_init(&pb->pb_list);
-		xfs_iowait(pb);
-		xfs_buf_relse(pb);
+		list_del_init(&bp->b_list);
+		xfs_iowait(bp);
+		xfs_buf_relse(bp);
 	}
 
 	if (wait)
-		blk_run_address_space(target->pbr_mapping);
+		blk_run_address_space(target->bt_mapping);
 
 	return pincount;
 }
 
 int __init
-pagebuf_init(void)
+xfs_buf_init(void)
 {
 	int		error = -ENOMEM;
 
-#ifdef PAGEBUF_TRACE
-	pagebuf_trace_buf = ktrace_alloc(PAGEBUF_TRACE_SIZE, KM_SLEEP);
+#ifdef XFS_BUF_TRACE
+	xfs_buf_trace_buf = ktrace_alloc(XFS_BUF_TRACE_SIZE, KM_SLEEP);
 #endif
 
-	pagebuf_zone = kmem_zone_init(sizeof(xfs_buf_t), "xfs_buf");
-	if (!pagebuf_zone)
+	xfs_buf_zone = kmem_zone_init(sizeof(xfs_buf_t), "xfs_buf");
+	if (!xfs_buf_zone)
 		goto out_free_trace_buf;
 
 	xfslogd_workqueue = create_workqueue("xfslogd");
@@ -1847,42 +1815,33 @@
 	if (!xfsdatad_workqueue)
 		goto out_destroy_xfslogd_workqueue;
 
-	xfsbufd_task = kthread_run(xfsbufd, NULL, "xfsbufd");
-	if (IS_ERR(xfsbufd_task)) {
-		error = PTR_ERR(xfsbufd_task);
+	xfs_buf_shake = kmem_shake_register(xfsbufd_wakeup);
+	if (!xfs_buf_shake)
 		goto out_destroy_xfsdatad_workqueue;
-	}
-
-	pagebuf_shake = kmem_shake_register(xfsbufd_wakeup);
-	if (!pagebuf_shake)
-		goto out_stop_xfsbufd;
 
 	return 0;
 
- out_stop_xfsbufd:
-	kthread_stop(xfsbufd_task);
  out_destroy_xfsdatad_workqueue:
 	destroy_workqueue(xfsdatad_workqueue);
  out_destroy_xfslogd_workqueue:
 	destroy_workqueue(xfslogd_workqueue);
  out_free_buf_zone:
-	kmem_zone_destroy(pagebuf_zone);
+	kmem_zone_destroy(xfs_buf_zone);
  out_free_trace_buf:
-#ifdef PAGEBUF_TRACE
-	ktrace_free(pagebuf_trace_buf);
+#ifdef XFS_BUF_TRACE
+	ktrace_free(xfs_buf_trace_buf);
 #endif
 	return error;
 }
 
 void
-pagebuf_terminate(void)
+xfs_buf_terminate(void)
 {
-	kmem_shake_deregister(pagebuf_shake);
-	kthread_stop(xfsbufd_task);
+	kmem_shake_deregister(xfs_buf_shake);
 	destroy_workqueue(xfsdatad_workqueue);
 	destroy_workqueue(xfslogd_workqueue);
-	kmem_zone_destroy(pagebuf_zone);
-#ifdef PAGEBUF_TRACE
-	ktrace_free(pagebuf_trace_buf);
+	kmem_zone_destroy(xfs_buf_zone);
+#ifdef XFS_BUF_TRACE
+	ktrace_free(xfs_buf_trace_buf);
 #endif
 }
diff --git a/fs/xfs/linux-2.6/xfs_buf.h b/fs/xfs/linux-2.6/xfs_buf.h
index 237a35b..4dd6592 100644
--- a/fs/xfs/linux-2.6/xfs_buf.h
+++ b/fs/xfs/linux-2.6/xfs_buf.h
@@ -32,44 +32,47 @@
  *	Base types
  */
 
-#define XFS_BUF_DADDR_NULL ((xfs_daddr_t) (-1LL))
+#define XFS_BUF_DADDR_NULL	((xfs_daddr_t) (-1LL))
 
-#define page_buf_ctob(pp)	((pp) * PAGE_CACHE_SIZE)
-#define page_buf_btoc(dd)	(((dd) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT)
-#define page_buf_btoct(dd)	((dd) >> PAGE_CACHE_SHIFT)
-#define page_buf_poff(aa)	((aa) & ~PAGE_CACHE_MASK)
+#define xfs_buf_ctob(pp)	((pp) * PAGE_CACHE_SIZE)
+#define xfs_buf_btoc(dd)	(((dd) + PAGE_CACHE_SIZE-1) >> PAGE_CACHE_SHIFT)
+#define xfs_buf_btoct(dd)	((dd) >> PAGE_CACHE_SHIFT)
+#define xfs_buf_poff(aa)	((aa) & ~PAGE_CACHE_MASK)
 
-typedef enum page_buf_rw_e {
-	PBRW_READ = 1,			/* transfer into target memory */
-	PBRW_WRITE = 2,			/* transfer from target memory */
-	PBRW_ZERO = 3			/* Zero target memory */
-} page_buf_rw_t;
+typedef enum {
+	XBRW_READ = 1,			/* transfer into target memory */
+	XBRW_WRITE = 2,			/* transfer from target memory */
+	XBRW_ZERO = 3,			/* Zero target memory */
+} xfs_buf_rw_t;
 
-
-typedef enum page_buf_flags_e {		/* pb_flags values */
-	PBF_READ = (1 << 0),	/* buffer intended for reading from device */
-	PBF_WRITE = (1 << 1),	/* buffer intended for writing to device   */
-	PBF_MAPPED = (1 << 2),  /* buffer mapped (pb_addr valid)           */
-	PBF_ASYNC = (1 << 4),   /* initiator will not wait for completion  */
-	PBF_DONE = (1 << 5),    /* all pages in the buffer uptodate	   */
-	PBF_DELWRI = (1 << 6),  /* buffer has dirty pages                  */
-	PBF_STALE = (1 << 7),	/* buffer has been staled, do not find it  */
-	PBF_FS_MANAGED = (1 << 8),  /* filesystem controls freeing memory  */
- 	PBF_ORDERED = (1 << 11),    /* use ordered writes		   */
-	PBF_READ_AHEAD = (1 << 12), /* asynchronous read-ahead		   */
+typedef enum {
+	XBF_READ = (1 << 0),	/* buffer intended for reading from device */
+	XBF_WRITE = (1 << 1),	/* buffer intended for writing to device   */
+	XBF_MAPPED = (1 << 2),  /* buffer mapped (b_addr valid)            */
+	XBF_ASYNC = (1 << 4),   /* initiator will not wait for completion  */
+	XBF_DONE = (1 << 5),    /* all pages in the buffer uptodate	   */
+	XBF_DELWRI = (1 << 6),  /* buffer has dirty pages                  */
+	XBF_STALE = (1 << 7),	/* buffer has been staled, do not find it  */
+	XBF_FS_MANAGED = (1 << 8),  /* filesystem controls freeing memory  */
+ 	XBF_ORDERED = (1 << 11),    /* use ordered writes		   */
+	XBF_READ_AHEAD = (1 << 12), /* asynchronous read-ahead		   */
 
 	/* flags used only as arguments to access routines */
-	PBF_LOCK = (1 << 14),       /* lock requested			   */
-	PBF_TRYLOCK = (1 << 15),    /* lock requested, but do not wait	   */
-	PBF_DONT_BLOCK = (1 << 16), /* do not block in current thread	   */
+	XBF_LOCK = (1 << 14),       /* lock requested			   */
+	XBF_TRYLOCK = (1 << 15),    /* lock requested, but do not wait	   */
+	XBF_DONT_BLOCK = (1 << 16), /* do not block in current thread	   */
 
 	/* flags used only internally */
-	_PBF_PAGE_CACHE = (1 << 17),/* backed by pagecache		   */
-	_PBF_KMEM_ALLOC = (1 << 18),/* backed by kmem_alloc()		   */
-	_PBF_RUN_QUEUES = (1 << 19),/* run block device task queue	   */
-	_PBF_DELWRI_Q = (1 << 21),   /* buffer on delwri queue		   */
-} page_buf_flags_t;
+	_XBF_PAGE_CACHE = (1 << 17),/* backed by pagecache		   */
+	_XBF_KMEM_ALLOC = (1 << 18),/* backed by kmem_alloc()		   */
+	_XBF_RUN_QUEUES = (1 << 19),/* run block device task queue	   */
+	_XBF_DELWRI_Q = (1 << 21),   /* buffer on delwri queue		   */
+} xfs_buf_flags_t;
 
+typedef enum {
+	XBT_FORCE_SLEEP = (0 << 1),
+	XBT_FORCE_FLUSH = (1 << 1),
+} xfs_buftarg_flags_t;
 
 typedef struct xfs_bufhash {
 	struct list_head	bh_list;
@@ -77,477 +80,350 @@
 } xfs_bufhash_t;
 
 typedef struct xfs_buftarg {
-	dev_t			pbr_dev;
-	struct block_device	*pbr_bdev;
-	struct address_space	*pbr_mapping;
-	unsigned int		pbr_bsize;
-	unsigned int		pbr_sshift;
-	size_t			pbr_smask;
+	dev_t			bt_dev;
+	struct block_device	*bt_bdev;
+	struct address_space	*bt_mapping;
+	unsigned int		bt_bsize;
+	unsigned int		bt_sshift;
+	size_t			bt_smask;
 
-	/* per-device buffer hash table */
+	/* per device buffer hash table */
 	uint			bt_hashmask;
 	uint			bt_hashshift;
 	xfs_bufhash_t		*bt_hash;
+
+	/* per device delwri queue */
+	struct task_struct	*bt_task;
+	struct list_head	bt_list;
+	struct list_head	bt_delwrite_queue;
+	spinlock_t		bt_delwrite_lock;
+	unsigned long		bt_flags;
 } xfs_buftarg_t;
 
 /*
- *	xfs_buf_t:  Buffer structure for page cache-based buffers
+ *	xfs_buf_t:  Buffer structure for pagecache-based buffers
  *
- * This buffer structure is used by the page cache buffer management routines
- * to refer to an assembly of pages forming a logical buffer.  The actual I/O
- * is performed with buffer_head structures, as required by drivers.
- * 
- * The buffer structure is used on temporary basis only, and discarded when
- * released.  The real data storage is recorded in the page cache.  Metadata is
+ * This buffer structure is used by the pagecache buffer management routines
+ * to refer to an assembly of pages forming a logical buffer.
+ *
+ * The buffer structure is used on a temporary basis only, and discarded when
+ * released.  The real data storage is recorded in the pagecache. Buffers are
  * hashed to the block device on which the file system resides.
  */
 
 struct xfs_buf;
+typedef void (*xfs_buf_iodone_t)(struct xfs_buf *);
+typedef void (*xfs_buf_relse_t)(struct xfs_buf *);
+typedef int (*xfs_buf_bdstrat_t)(struct xfs_buf *);
 
-/* call-back function on I/O completion */
-typedef void (*page_buf_iodone_t)(struct xfs_buf *);
-/* call-back function on I/O completion */
-typedef void (*page_buf_relse_t)(struct xfs_buf *);
-/* pre-write function */
-typedef int (*page_buf_bdstrat_t)(struct xfs_buf *);
-
-#define PB_PAGES	2
+#define XB_PAGES	2
 
 typedef struct xfs_buf {
-	struct semaphore	pb_sema;	/* semaphore for lockables  */
-	unsigned long		pb_queuetime;	/* time buffer was queued   */
-	atomic_t		pb_pin_count;	/* pin count		    */
-	wait_queue_head_t	pb_waiters;	/* unpin waiters	    */
-	struct list_head	pb_list;
-	page_buf_flags_t	pb_flags;	/* status flags */
-	struct list_head	pb_hash_list;	/* hash table list */
-	xfs_bufhash_t		*pb_hash;	/* hash table list start */
-	xfs_buftarg_t		*pb_target;	/* buffer target (device) */
-	atomic_t		pb_hold;	/* reference count */
-	xfs_daddr_t		pb_bn;		/* block number for I/O */
-	loff_t			pb_file_offset;	/* offset in file */
-	size_t			pb_buffer_length; /* size of buffer in bytes */
-	size_t			pb_count_desired; /* desired transfer size */
-	void			*pb_addr;	/* virtual address of buffer */
-	struct work_struct	pb_iodone_work;
-	atomic_t		pb_io_remaining;/* #outstanding I/O requests */
-	page_buf_iodone_t	pb_iodone;	/* I/O completion function */
-	page_buf_relse_t	pb_relse;	/* releasing function */
-	page_buf_bdstrat_t	pb_strat;	/* pre-write function */
-	struct semaphore	pb_iodonesema;	/* Semaphore for I/O waiters */
-	void			*pb_fspriv;
-	void			*pb_fspriv2;
-	void			*pb_fspriv3;
-	unsigned short		pb_error;	/* error code on I/O */
- 	unsigned short		pb_locked;	/* page array is locked */
- 	unsigned int		pb_page_count;	/* size of page array */
-	unsigned int		pb_offset;	/* page offset in first page */
-	struct page		**pb_pages;	/* array of page pointers */
-	struct page		*pb_page_array[PB_PAGES]; /* inline pages */
-#ifdef PAGEBUF_LOCK_TRACKING
-	int			pb_last_holder;
+	struct semaphore	b_sema;		/* semaphore for lockables */
+	unsigned long		b_queuetime;	/* time buffer was queued */
+	atomic_t		b_pin_count;	/* pin count */
+	wait_queue_head_t	b_waiters;	/* unpin waiters */
+	struct list_head	b_list;
+	xfs_buf_flags_t		b_flags;	/* status flags */
+	struct list_head	b_hash_list;	/* hash table list */
+	xfs_bufhash_t		*b_hash;	/* hash table list start */
+	xfs_buftarg_t		*b_target;	/* buffer target (device) */
+	atomic_t		b_hold;		/* reference count */
+	xfs_daddr_t		b_bn;		/* block number for I/O */
+	xfs_off_t		b_file_offset;	/* offset in file */
+	size_t			b_buffer_length;/* size of buffer in bytes */
+	size_t			b_count_desired;/* desired transfer size */
+	void			*b_addr;	/* virtual address of buffer */
+	struct work_struct	b_iodone_work;
+	atomic_t		b_io_remaining;	/* #outstanding I/O requests */
+	xfs_buf_iodone_t	b_iodone;	/* I/O completion function */
+	xfs_buf_relse_t		b_relse;	/* releasing function */
+	xfs_buf_bdstrat_t	b_strat;	/* pre-write function */
+	struct semaphore	b_iodonesema;	/* Semaphore for I/O waiters */
+	void			*b_fspriv;
+	void			*b_fspriv2;
+	void			*b_fspriv3;
+	unsigned short		b_error;	/* error code on I/O */
+	unsigned short		b_locked;	/* page array is locked */
+	unsigned int		b_page_count;	/* size of page array */
+	unsigned int		b_offset;	/* page offset in first page */
+	struct page		**b_pages;	/* array of page pointers */
+	struct page		*b_page_array[XB_PAGES]; /* inline pages */
+#ifdef XFS_BUF_LOCK_TRACKING
+	int			b_last_holder;
 #endif
 } xfs_buf_t;
 
 
 /* Finding and Reading Buffers */
-
-extern xfs_buf_t *_pagebuf_find(	/* find buffer for block if	*/
-					/* the block is in memory	*/
-		xfs_buftarg_t *,	/* inode for block		*/
-		loff_t,			/* starting offset of range	*/
-		size_t,			/* length of range		*/
-		page_buf_flags_t,	/* PBF_LOCK			*/
-	        xfs_buf_t *);		/* newly allocated buffer	*/
-
+extern xfs_buf_t *_xfs_buf_find(xfs_buftarg_t *, xfs_off_t, size_t,
+				xfs_buf_flags_t, xfs_buf_t *);
 #define xfs_incore(buftarg,blkno,len,lockit) \
-	_pagebuf_find(buftarg, blkno ,len, lockit, NULL)
+	_xfs_buf_find(buftarg, blkno ,len, lockit, NULL)
 
-extern xfs_buf_t *xfs_buf_get_flags(	/* allocate a buffer		*/
-		xfs_buftarg_t *,	/* inode for buffer		*/
-		loff_t,			/* starting offset of range     */
-		size_t,			/* length of range              */
-		page_buf_flags_t);	/* PBF_LOCK, PBF_READ,		*/
-					/* PBF_ASYNC			*/
-
+extern xfs_buf_t *xfs_buf_get_flags(xfs_buftarg_t *, xfs_off_t, size_t,
+				xfs_buf_flags_t);
 #define xfs_buf_get(target, blkno, len, flags) \
-	xfs_buf_get_flags((target), (blkno), (len), PBF_LOCK | PBF_MAPPED)
+	xfs_buf_get_flags((target), (blkno), (len), XBF_LOCK | XBF_MAPPED)
 
-extern xfs_buf_t *xfs_buf_read_flags(	/* allocate and read a buffer	*/
-		xfs_buftarg_t *,	/* inode for buffer		*/
-		loff_t,			/* starting offset of range	*/
-		size_t,			/* length of range		*/
-		page_buf_flags_t);	/* PBF_LOCK, PBF_ASYNC		*/
-
+extern xfs_buf_t *xfs_buf_read_flags(xfs_buftarg_t *, xfs_off_t, size_t,
+				xfs_buf_flags_t);
 #define xfs_buf_read(target, blkno, len, flags) \
-	xfs_buf_read_flags((target), (blkno), (len), PBF_LOCK | PBF_MAPPED)
+	xfs_buf_read_flags((target), (blkno), (len), XBF_LOCK | XBF_MAPPED)
 
-extern xfs_buf_t *pagebuf_get_empty(	/* allocate pagebuf struct with	*/
-					/*  no memory or disk address	*/
-		size_t len,
-		xfs_buftarg_t *);	/* mount point "fake" inode	*/
-
-extern xfs_buf_t *pagebuf_get_no_daddr(/* allocate pagebuf struct	*/
-					/* without disk address		*/
-		size_t len,
-		xfs_buftarg_t *);	/* mount point "fake" inode	*/
-
-extern int pagebuf_associate_memory(
-		xfs_buf_t *,
-		void *,
-		size_t);
-
-extern void pagebuf_hold(		/* increment reference count	*/
-		xfs_buf_t *);		/* buffer to hold		*/
-
-extern void pagebuf_readahead(		/* read ahead into cache	*/
-		xfs_buftarg_t  *,	/* target for buffer (or NULL)	*/
-		loff_t,			/* starting offset of range     */
-		size_t,			/* length of range              */
-		page_buf_flags_t);	/* additional read flags	*/
+extern xfs_buf_t *xfs_buf_get_empty(size_t, xfs_buftarg_t *);
+extern xfs_buf_t *xfs_buf_get_noaddr(size_t, xfs_buftarg_t *);
+extern int xfs_buf_associate_memory(xfs_buf_t *, void *, size_t);
+extern void xfs_buf_hold(xfs_buf_t *);
+extern void xfs_buf_readahead(xfs_buftarg_t *, xfs_off_t, size_t,
+				xfs_buf_flags_t);
 
 /* Releasing Buffers */
-
-extern void pagebuf_free(		/* deallocate a buffer		*/
-		xfs_buf_t *);		/* buffer to deallocate		*/
-
-extern void pagebuf_rele(		/* release hold on a buffer	*/
-		xfs_buf_t *);		/* buffer to release		*/
+extern void xfs_buf_free(xfs_buf_t *);
+extern void xfs_buf_rele(xfs_buf_t *);
 
 /* Locking and Unlocking Buffers */
-
-extern int pagebuf_cond_lock(		/* lock buffer, if not locked	*/
-					/* (returns -EBUSY if locked)	*/
-		xfs_buf_t *);		/* buffer to lock		*/
-
-extern int pagebuf_lock_value(		/* return count on lock		*/
-		xfs_buf_t *);          /* buffer to check              */
-
-extern int pagebuf_lock(		/* lock buffer                  */
-		xfs_buf_t *);          /* buffer to lock               */
-
-extern void pagebuf_unlock(		/* unlock buffer		*/
-		xfs_buf_t *);		/* buffer to unlock		*/
+extern int xfs_buf_cond_lock(xfs_buf_t *);
+extern int xfs_buf_lock_value(xfs_buf_t *);
+extern void xfs_buf_lock(xfs_buf_t *);
+extern void xfs_buf_unlock(xfs_buf_t *);
 
 /* Buffer Read and Write Routines */
+extern void xfs_buf_ioend(xfs_buf_t *,	int);
+extern void xfs_buf_ioerror(xfs_buf_t *, int);
+extern int xfs_buf_iostart(xfs_buf_t *, xfs_buf_flags_t);
+extern int xfs_buf_iorequest(xfs_buf_t *);
+extern int xfs_buf_iowait(xfs_buf_t *);
+extern void xfs_buf_iomove(xfs_buf_t *, size_t, size_t, xfs_caddr_t,
+				xfs_buf_rw_t);
 
-extern void pagebuf_iodone(		/* mark buffer I/O complete	*/
-		xfs_buf_t *,		/* buffer to mark		*/
-		int);			/* run completion locally, or in
-					 * a helper thread.		*/
-
-extern void pagebuf_ioerror(		/* mark buffer in error	(or not) */
-		xfs_buf_t *,		/* buffer to mark		*/
-		int);			/* error to store (0 if none)	*/
-
-extern int pagebuf_iostart(		/* start I/O on a buffer	*/
-		xfs_buf_t *,		/* buffer to start		*/
-		page_buf_flags_t);	/* PBF_LOCK, PBF_ASYNC,		*/
-					/* PBF_READ, PBF_WRITE,		*/
-					/* PBF_DELWRI			*/
-
-extern int pagebuf_iorequest(		/* start real I/O		*/
-		xfs_buf_t *);		/* buffer to convey to device	*/
-
-extern int pagebuf_iowait(		/* wait for buffer I/O done	*/
-		xfs_buf_t *);		/* buffer to wait on		*/
-
-extern void pagebuf_iomove(		/* move data in/out of pagebuf	*/
-		xfs_buf_t *,		/* buffer to manipulate		*/
-		size_t,			/* starting buffer offset	*/
-		size_t,			/* length in buffer		*/
-		caddr_t,		/* data pointer			*/
-		page_buf_rw_t);		/* direction			*/
-
-static inline int pagebuf_iostrategy(xfs_buf_t *pb)
+static inline int xfs_buf_iostrategy(xfs_buf_t *bp)
 {
-	return pb->pb_strat ? pb->pb_strat(pb) : pagebuf_iorequest(pb);
+	return bp->b_strat ? bp->b_strat(bp) : xfs_buf_iorequest(bp);
 }
 
-static inline int pagebuf_geterror(xfs_buf_t *pb)
+static inline int xfs_buf_geterror(xfs_buf_t *bp)
 {
-	return pb ? pb->pb_error : ENOMEM;
+	return bp ? bp->b_error : ENOMEM;
 }
 
 /* Buffer Utility Routines */
-
-extern caddr_t pagebuf_offset(		/* pointer at offset in buffer	*/
-		xfs_buf_t *,		/* buffer to offset into	*/
-		size_t);		/* offset			*/
+extern xfs_caddr_t xfs_buf_offset(xfs_buf_t *, size_t);
 
 /* Pinning Buffer Storage in Memory */
-
-extern void pagebuf_pin(		/* pin buffer in memory		*/
-		xfs_buf_t *);		/* buffer to pin		*/
-
-extern void pagebuf_unpin(		/* unpin buffered data		*/
-		xfs_buf_t *);		/* buffer to unpin		*/
-
-extern int pagebuf_ispin(		/* check if buffer is pinned	*/
-		xfs_buf_t *);		/* buffer to check		*/
+extern void xfs_buf_pin(xfs_buf_t *);
+extern void xfs_buf_unpin(xfs_buf_t *);
+extern int xfs_buf_ispin(xfs_buf_t *);
 
 /* Delayed Write Buffer Routines */
-
-extern void pagebuf_delwri_dequeue(xfs_buf_t *);
+extern void xfs_buf_delwri_dequeue(xfs_buf_t *);
 
 /* Buffer Daemon Setup Routines */
+extern int xfs_buf_init(void);
+extern void xfs_buf_terminate(void);
 
-extern int pagebuf_init(void);
-extern void pagebuf_terminate(void);
-
-
-#ifdef PAGEBUF_TRACE
-extern ktrace_t *pagebuf_trace_buf;
-extern void pagebuf_trace(
-		xfs_buf_t *,		/* buffer being traced		*/
-		char *,			/* description of operation	*/
-		void *,			/* arbitrary diagnostic value	*/
-		void *);		/* return address		*/
+#ifdef XFS_BUF_TRACE
+extern ktrace_t *xfs_buf_trace_buf;
+extern void xfs_buf_trace(xfs_buf_t *, char *, void *, void *);
 #else
-# define pagebuf_trace(pb, id, ptr, ra)	do { } while (0)
+#define xfs_buf_trace(bp,id,ptr,ra)	do { } while (0)
 #endif
 
-#define pagebuf_target_name(target)	\
-	({ char __b[BDEVNAME_SIZE]; bdevname((target)->pbr_bdev, __b); __b; })
+#define xfs_buf_target_name(target)	\
+	({ char __b[BDEVNAME_SIZE]; bdevname((target)->bt_bdev, __b); __b; })
 
 
+#define XFS_B_ASYNC		XBF_ASYNC
+#define XFS_B_DELWRI		XBF_DELWRI
+#define XFS_B_READ		XBF_READ
+#define XFS_B_WRITE		XBF_WRITE
+#define XFS_B_STALE		XBF_STALE
 
-/* 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_BUF_TRYLOCK		XBF_TRYLOCK
+#define XFS_INCORE_TRYLOCK	XBF_TRYLOCK
+#define XFS_BUF_LOCK		XBF_LOCK
+#define XFS_BUF_MAPPED		XBF_MAPPED
 
-#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		XBF_DONT_BLOCK
 
-#define BUF_BUSY		PBF_DONT_BLOCK
+#define XFS_BUF_BFLAGS(bp)	((bp)->b_flags)
+#define XFS_BUF_ZEROFLAGS(bp)	\
+	((bp)->b_flags &= ~(XBF_READ|XBF_WRITE|XBF_ASYNC|XBF_DELWRI))
 
-#define XFS_BUF_BFLAGS(x)	((x)->pb_flags)
-#define XFS_BUF_ZEROFLAGS(x)	\
-	((x)->pb_flags &= ~(PBF_READ|PBF_WRITE|PBF_ASYNC|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)	do {				\
-					XFS_BUF_STALE(x);	\
-					pagebuf_delwri_dequeue(x);	\
-					XFS_BUF_DONE(x);	\
+#define XFS_BUF_STALE(bp)	((bp)->b_flags |= XFS_B_STALE)
+#define XFS_BUF_UNSTALE(bp)	((bp)->b_flags &= ~XFS_B_STALE)
+#define XFS_BUF_ISSTALE(bp)	((bp)->b_flags & XFS_B_STALE)
+#define XFS_BUF_SUPER_STALE(bp)	do {				\
+					XFS_BUF_STALE(bp);	\
+					xfs_buf_delwri_dequeue(bp);	\
+					XFS_BUF_DONE(bp);	\
 				} while (0)
 
-#define XFS_BUF_MANAGE		PBF_FS_MANAGED
-#define XFS_BUF_UNMANAGE(x)	((x)->pb_flags &= ~PBF_FS_MANAGED)
+#define XFS_BUF_MANAGE		XBF_FS_MANAGED
+#define XFS_BUF_UNMANAGE(bp)	((bp)->b_flags &= ~XBF_FS_MANAGED)
 
-#define XFS_BUF_DELAYWRITE(x)	 ((x)->pb_flags |= PBF_DELWRI)
-#define XFS_BUF_UNDELAYWRITE(x)	 pagebuf_delwri_dequeue(x)
-#define XFS_BUF_ISDELAYWRITE(x)	 ((x)->pb_flags & PBF_DELWRI)
+#define XFS_BUF_DELAYWRITE(bp)		((bp)->b_flags |= XBF_DELWRI)
+#define XFS_BUF_UNDELAYWRITE(bp)	xfs_buf_delwri_dequeue(bp)
+#define XFS_BUF_ISDELAYWRITE(bp)	((bp)->b_flags & XBF_DELWRI)
 
-#define XFS_BUF_ERROR(x,no)	 pagebuf_ioerror(x,no)
-#define XFS_BUF_GETERROR(x)	 pagebuf_geterror(x)
-#define XFS_BUF_ISERROR(x)	 (pagebuf_geterror(x)?1:0)
+#define XFS_BUF_ERROR(bp,no)	xfs_buf_ioerror(bp,no)
+#define XFS_BUF_GETERROR(bp)	xfs_buf_geterror(bp)
+#define XFS_BUF_ISERROR(bp)	(xfs_buf_geterror(bp) ? 1 : 0)
 
-#define XFS_BUF_DONE(x)		 ((x)->pb_flags |= PBF_DONE)
-#define XFS_BUF_UNDONE(x)	 ((x)->pb_flags &= ~PBF_DONE)
-#define XFS_BUF_ISDONE(x)	 ((x)->pb_flags & PBF_DONE)
+#define XFS_BUF_DONE(bp)	((bp)->b_flags |= XBF_DONE)
+#define XFS_BUF_UNDONE(bp)	((bp)->b_flags &= ~XBF_DONE)
+#define XFS_BUF_ISDONE(bp)	((bp)->b_flags & XBF_DONE)
 
-#define XFS_BUF_BUSY(x)		 do { } while (0)
-#define XFS_BUF_UNBUSY(x)	 do { } while (0)
-#define XFS_BUF_ISBUSY(x)	 (1)
+#define XFS_BUF_BUSY(bp)	do { } while (0)
+#define XFS_BUF_UNBUSY(bp)	do { } while (0)
+#define XFS_BUF_ISBUSY(bp)	(1)
 
-#define XFS_BUF_ASYNC(x)	 ((x)->pb_flags |= PBF_ASYNC)
-#define XFS_BUF_UNASYNC(x)	 ((x)->pb_flags &= ~PBF_ASYNC)
-#define XFS_BUF_ISASYNC(x)	 ((x)->pb_flags & PBF_ASYNC)
+#define XFS_BUF_ASYNC(bp)	((bp)->b_flags |= XBF_ASYNC)
+#define XFS_BUF_UNASYNC(bp)	((bp)->b_flags &= ~XBF_ASYNC)
+#define XFS_BUF_ISASYNC(bp)	((bp)->b_flags & XBF_ASYNC)
 
-#define XFS_BUF_ORDERED(x)	 ((x)->pb_flags |= PBF_ORDERED)
-#define XFS_BUF_UNORDERED(x)	 ((x)->pb_flags &= ~PBF_ORDERED)
-#define XFS_BUF_ISORDERED(x)	 ((x)->pb_flags & PBF_ORDERED)
+#define XFS_BUF_ORDERED(bp)	((bp)->b_flags |= XBF_ORDERED)
+#define XFS_BUF_UNORDERED(bp)	((bp)->b_flags &= ~XBF_ORDERED)
+#define XFS_BUF_ISORDERED(bp)	((bp)->b_flags & XBF_ORDERED)
 
-#define XFS_BUF_SHUT(x)		 printk("XFS_BUF_SHUT not implemented yet\n")
-#define XFS_BUF_UNSHUT(x)	 printk("XFS_BUF_UNSHUT not implemented yet\n")
-#define XFS_BUF_ISSHUT(x)	 (0)
+#define XFS_BUF_SHUT(bp)	do { } while (0)
+#define XFS_BUF_UNSHUT(bp)	do { } while (0)
+#define XFS_BUF_ISSHUT(bp)	(0)
 
-#define XFS_BUF_HOLD(x)		pagebuf_hold(x)
-#define XFS_BUF_READ(x)		((x)->pb_flags |= PBF_READ)
-#define XFS_BUF_UNREAD(x)	((x)->pb_flags &= ~PBF_READ)
-#define XFS_BUF_ISREAD(x)	((x)->pb_flags & PBF_READ)
+#define XFS_BUF_HOLD(bp)	xfs_buf_hold(bp)
+#define XFS_BUF_READ(bp)	((bp)->b_flags |= XBF_READ)
+#define XFS_BUF_UNREAD(bp)	((bp)->b_flags &= ~XBF_READ)
+#define XFS_BUF_ISREAD(bp)	((bp)->b_flags & XBF_READ)
 
-#define XFS_BUF_WRITE(x)	((x)->pb_flags |= PBF_WRITE)
-#define XFS_BUF_UNWRITE(x)	((x)->pb_flags &= ~PBF_WRITE)
-#define XFS_BUF_ISWRITE(x)	((x)->pb_flags & PBF_WRITE)
+#define XFS_BUF_WRITE(bp)	((bp)->b_flags |= XBF_WRITE)
+#define XFS_BUF_UNWRITE(bp)	((bp)->b_flags &= ~XBF_WRITE)
+#define XFS_BUF_ISWRITE(bp)	((bp)->b_flags & XBF_WRITE)
 
-#define XFS_BUF_ISUNINITIAL(x)	 (0)
-#define XFS_BUF_UNUNINITIAL(x)	 (0)
+#define XFS_BUF_ISUNINITIAL(bp)	(0)
+#define XFS_BUF_UNUNINITIAL(bp)	(0)
 
-#define XFS_BUF_BP_ISMAPPED(bp)	 1
+#define XFS_BUF_BP_ISMAPPED(bp)	(1)
 
-#define XFS_BUF_IODONE_FUNC(buf)	(buf)->pb_iodone
-#define XFS_BUF_SET_IODONE_FUNC(buf, func)	\
-			(buf)->pb_iodone = (func)
-#define XFS_BUF_CLR_IODONE_FUNC(buf)		\
-			(buf)->pb_iodone = NULL
-#define XFS_BUF_SET_BDSTRAT_FUNC(buf, func)	\
-			(buf)->pb_strat = (func)
-#define XFS_BUF_CLR_BDSTRAT_FUNC(buf)		\
-			(buf)->pb_strat = NULL
+#define XFS_BUF_IODONE_FUNC(bp)			((bp)->b_iodone)
+#define XFS_BUF_SET_IODONE_FUNC(bp, func)	((bp)->b_iodone = (func))
+#define XFS_BUF_CLR_IODONE_FUNC(bp)		((bp)->b_iodone = NULL)
+#define XFS_BUF_SET_BDSTRAT_FUNC(bp, func)	((bp)->b_strat = (func))
+#define XFS_BUF_CLR_BDSTRAT_FUNC(bp)		((bp)->b_strat = NULL)
 
-#define XFS_BUF_FSPRIVATE(buf, type)		\
-			((type)(buf)->pb_fspriv)
-#define XFS_BUF_SET_FSPRIVATE(buf, value)	\
-			(buf)->pb_fspriv = (void *)(value)
-#define XFS_BUF_FSPRIVATE2(buf, type)		\
-			((type)(buf)->pb_fspriv2)
-#define XFS_BUF_SET_FSPRIVATE2(buf, value)	\
-			(buf)->pb_fspriv2 = (void *)(value)
-#define XFS_BUF_FSPRIVATE3(buf, type)		\
-			((type)(buf)->pb_fspriv3)
-#define XFS_BUF_SET_FSPRIVATE3(buf, value)	\
-			(buf)->pb_fspriv3  = (void *)(value)
-#define XFS_BUF_SET_START(buf)
+#define XFS_BUF_FSPRIVATE(bp, type)		((type)(bp)->b_fspriv)
+#define XFS_BUF_SET_FSPRIVATE(bp, val)		((bp)->b_fspriv = (void*)(val))
+#define XFS_BUF_FSPRIVATE2(bp, type)		((type)(bp)->b_fspriv2)
+#define XFS_BUF_SET_FSPRIVATE2(bp, val)		((bp)->b_fspriv2 = (void*)(val))
+#define XFS_BUF_FSPRIVATE3(bp, type)		((type)(bp)->b_fspriv3)
+#define XFS_BUF_SET_FSPRIVATE3(bp, val)		((bp)->b_fspriv3 = (void*)(val))
+#define XFS_BUF_SET_START(bp)			do { } while (0)
+#define XFS_BUF_SET_BRELSE_FUNC(bp, func)	((bp)->b_relse = (func))
 
-#define XFS_BUF_SET_BRELSE_FUNC(buf, value) \
-			(buf)->pb_relse = (value)
+#define XFS_BUF_PTR(bp)			(xfs_caddr_t)((bp)->b_addr)
+#define XFS_BUF_SET_PTR(bp, val, cnt)	xfs_buf_associate_memory(bp, val, cnt)
+#define XFS_BUF_ADDR(bp)		((bp)->b_bn)
+#define XFS_BUF_SET_ADDR(bp, bno)	((bp)->b_bn = (xfs_daddr_t)(bno))
+#define XFS_BUF_OFFSET(bp)		((bp)->b_file_offset)
+#define XFS_BUF_SET_OFFSET(bp, off)	((bp)->b_file_offset = (off))
+#define XFS_BUF_COUNT(bp)		((bp)->b_count_desired)
+#define XFS_BUF_SET_COUNT(bp, cnt)	((bp)->b_count_desired = (cnt))
+#define XFS_BUF_SIZE(bp)		((bp)->b_buffer_length)
+#define XFS_BUF_SET_SIZE(bp, cnt)	((bp)->b_buffer_length = (cnt))
 
-#define XFS_BUF_PTR(bp)		(xfs_caddr_t)((bp)->pb_addr)
+#define XFS_BUF_SET_VTYPE_REF(bp, type, ref)	do { } while (0)
+#define XFS_BUF_SET_VTYPE(bp, type)		do { } while (0)
+#define XFS_BUF_SET_REF(bp, ref)		do { } while (0)
 
-static inline xfs_caddr_t xfs_buf_offset(xfs_buf_t *bp, size_t offset)
+#define XFS_BUF_ISPINNED(bp)	xfs_buf_ispin(bp)
+
+#define XFS_BUF_VALUSEMA(bp)	xfs_buf_lock_value(bp)
+#define XFS_BUF_CPSEMA(bp)	(xfs_buf_cond_lock(bp) == 0)
+#define XFS_BUF_VSEMA(bp)	xfs_buf_unlock(bp)
+#define XFS_BUF_PSEMA(bp,x)	xfs_buf_lock(bp)
+#define XFS_BUF_V_IODONESEMA(bp) up(&bp->b_iodonesema);
+
+#define XFS_BUF_SET_TARGET(bp, target)	((bp)->b_target = (target))
+#define XFS_BUF_TARGET(bp)		((bp)->b_target)
+#define XFS_BUFTARG_NAME(target)	xfs_buf_target_name(target)
+
+static inline int xfs_bawrite(void *mp, xfs_buf_t *bp)
 {
-	if (bp->pb_flags & PBF_MAPPED)
-		return XFS_BUF_PTR(bp) + offset;
-	return (xfs_caddr_t) pagebuf_offset(bp, offset);
+	bp->b_fspriv3 = mp;
+	bp->b_strat = xfs_bdstrat_cb;
+	xfs_buf_delwri_dequeue(bp);
+	return xfs_buf_iostart(bp, XBF_WRITE | XBF_ASYNC | _XBF_RUN_QUEUES);
 }
 
-#define XFS_BUF_SET_PTR(bp, val, count)		\
-				pagebuf_associate_memory(bp, val, count)
-#define XFS_BUF_ADDR(bp)	((bp)->pb_bn)
-#define XFS_BUF_SET_ADDR(bp, blk)		\
-			((bp)->pb_bn = (xfs_daddr_t)(blk))
-#define XFS_BUF_OFFSET(bp)	((bp)->pb_file_offset)
-#define XFS_BUF_SET_OFFSET(bp, off)		\
-			((bp)->pb_file_offset = (off))
-#define XFS_BUF_COUNT(bp)	((bp)->pb_count_desired)
-#define XFS_BUF_SET_COUNT(bp, cnt)		\
-			((bp)->pb_count_desired = (cnt))
-#define XFS_BUF_SIZE(bp)	((bp)->pb_buffer_length)
-#define XFS_BUF_SET_SIZE(bp, cnt)		\
-			((bp)->pb_buffer_length = (cnt))
-#define XFS_BUF_SET_VTYPE_REF(bp, type, ref)
-#define XFS_BUF_SET_VTYPE(bp, type)
-#define XFS_BUF_SET_REF(bp, ref)
-
-#define XFS_BUF_ISPINNED(bp)	pagebuf_ispin(bp)
-
-#define XFS_BUF_VALUSEMA(bp)	pagebuf_lock_value(bp)
-#define XFS_BUF_CPSEMA(bp)	(pagebuf_cond_lock(bp) == 0)
-#define XFS_BUF_VSEMA(bp)	pagebuf_unlock(bp)
-#define XFS_BUF_PSEMA(bp,x)	pagebuf_lock(bp)
-#define XFS_BUF_V_IODONESEMA(bp) up(&bp->pb_iodonesema);
-
-/* setup the buffer target from a buftarg structure */
-#define XFS_BUF_SET_TARGET(bp, target)	\
-		(bp)->pb_target = (target)
-#define XFS_BUF_TARGET(bp)	((bp)->pb_target)
-#define XFS_BUFTARG_NAME(target)	\
-		pagebuf_target_name(target)
-
-#define XFS_BUF_SET_VTYPE_REF(bp, type, ref)
-#define XFS_BUF_SET_VTYPE(bp, type)
-#define XFS_BUF_SET_REF(bp, ref)
-
-static inline int	xfs_bawrite(void *mp, xfs_buf_t *bp)
+static inline void xfs_buf_relse(xfs_buf_t *bp)
 {
-	bp->pb_fspriv3 = mp;
-	bp->pb_strat = xfs_bdstrat_cb;
-	pagebuf_delwri_dequeue(bp);
-	return pagebuf_iostart(bp, PBF_WRITE | PBF_ASYNC | _PBF_RUN_QUEUES);
+	if (!bp->b_relse)
+		xfs_buf_unlock(bp);
+	xfs_buf_rele(bp);
 }
 
-static inline void	xfs_buf_relse(xfs_buf_t *bp)
-{
-	if (!bp->pb_relse)
-		pagebuf_unlock(bp);
-	pagebuf_rele(bp);
-}
-
-#define xfs_bpin(bp)		pagebuf_pin(bp)
-#define xfs_bunpin(bp)		pagebuf_unpin(bp)
+#define xfs_bpin(bp)		xfs_buf_pin(bp)
+#define xfs_bunpin(bp)		xfs_buf_unpin(bp)
 
 #define xfs_buftrace(id, bp)	\
-	    pagebuf_trace(bp, id, NULL, (void *)__builtin_return_address(0))
+	    xfs_buf_trace(bp, id, NULL, (void *)__builtin_return_address(0))
 
-#define xfs_biodone(pb)		    \
-	    pagebuf_iodone(pb, 0)
+#define xfs_biodone(bp)		xfs_buf_ioend(bp, 0)
 
-#define xfs_biomove(pb, off, len, data, rw) \
-	    pagebuf_iomove((pb), (off), (len), (data), \
-		((rw) == XFS_B_WRITE) ? PBRW_WRITE : PBRW_READ)
+#define xfs_biomove(bp, off, len, data, rw) \
+	    xfs_buf_iomove((bp), (off), (len), (data), \
+		((rw) == XFS_B_WRITE) ? XBRW_WRITE : XBRW_READ)
 
-#define xfs_biozero(pb, off, len) \
-	    pagebuf_iomove((pb), (off), (len), NULL, PBRW_ZERO)
+#define xfs_biozero(bp, off, len) \
+	    xfs_buf_iomove((bp), (off), (len), NULL, XBRW_ZERO)
 
 
-static inline int	XFS_bwrite(xfs_buf_t *pb)
+static inline int XFS_bwrite(xfs_buf_t *bp)
 {
-	int	iowait = (pb->pb_flags & PBF_ASYNC) == 0;
+	int	iowait = (bp->b_flags & XBF_ASYNC) == 0;
 	int	error = 0;
 
 	if (!iowait)
-		pb->pb_flags |= _PBF_RUN_QUEUES;
+		bp->b_flags |= _XBF_RUN_QUEUES;
 
-	pagebuf_delwri_dequeue(pb);
-	pagebuf_iostrategy(pb);
+	xfs_buf_delwri_dequeue(bp);
+	xfs_buf_iostrategy(bp);
 	if (iowait) {
-		error = pagebuf_iowait(pb);
-		xfs_buf_relse(pb);
+		error = xfs_buf_iowait(bp);
+		xfs_buf_relse(bp);
 	}
 	return error;
 }
 
-#define XFS_bdwrite(pb)		     \
-	    pagebuf_iostart(pb, PBF_DELWRI | PBF_ASYNC)
+#define XFS_bdwrite(bp)		xfs_buf_iostart(bp, XBF_DELWRI | XBF_ASYNC)
 
 static inline int xfs_bdwrite(void *mp, xfs_buf_t *bp)
 {
-	bp->pb_strat = xfs_bdstrat_cb;
-	bp->pb_fspriv3 = mp;
-
-	return pagebuf_iostart(bp, PBF_DELWRI | PBF_ASYNC);
+	bp->b_strat = xfs_bdstrat_cb;
+	bp->b_fspriv3 = mp;
+	return xfs_buf_iostart(bp, XBF_DELWRI | XBF_ASYNC);
 }
 
-#define XFS_bdstrat(bp) pagebuf_iorequest(bp)
+#define XFS_bdstrat(bp) xfs_buf_iorequest(bp)
 
-#define xfs_iowait(pb)	pagebuf_iowait(pb)
+#define xfs_iowait(bp)	xfs_buf_iowait(bp)
 
 #define xfs_baread(target, rablkno, ralen)  \
-	pagebuf_readahead((target), (rablkno), (ralen), PBF_DONT_BLOCK)
-
-#define xfs_buf_get_empty(len, target)	pagebuf_get_empty((len), (target))
-#define xfs_buf_get_noaddr(len, target)	pagebuf_get_no_daddr((len), (target))
-#define xfs_buf_free(bp)		pagebuf_free(bp)
+	xfs_buf_readahead((target), (rablkno), (ralen), XBF_DONT_BLOCK)
 
 
 /*
  *	Handling of buftargs.
  */
-
 extern xfs_buftarg_t *xfs_alloc_buftarg(struct block_device *, int);
 extern void xfs_free_buftarg(xfs_buftarg_t *, int);
 extern void xfs_wait_buftarg(xfs_buftarg_t *);
 extern int xfs_setsize_buftarg(xfs_buftarg_t *, unsigned int, unsigned int);
 extern int xfs_flush_buftarg(xfs_buftarg_t *, int);
 
-#define xfs_getsize_buftarg(buftarg) \
-	block_size((buftarg)->pbr_bdev)
-#define xfs_readonly_buftarg(buftarg) \
-	bdev_read_only((buftarg)->pbr_bdev)
-#define xfs_binval(buftarg) \
-	xfs_flush_buftarg(buftarg, 1)
-#define XFS_bflush(buftarg) \
-	xfs_flush_buftarg(buftarg, 1)
+#define xfs_getsize_buftarg(buftarg)	block_size((buftarg)->bt_bdev)
+#define xfs_readonly_buftarg(buftarg)	bdev_read_only((buftarg)->bt_bdev)
+
+#define xfs_binval(buftarg)		xfs_flush_buftarg(buftarg, 1)
+#define XFS_bflush(buftarg)		xfs_flush_buftarg(buftarg, 1)
 
 #endif	/* __XFS_BUF_H__ */
diff --git a/fs/xfs/linux-2.6/xfs_cred.h b/fs/xfs/linux-2.6/xfs_cred.h
index 4af4910..e7f3da6 100644
--- a/fs/xfs/linux-2.6/xfs_cred.h
+++ b/fs/xfs/linux-2.6/xfs_cred.h
@@ -18,6 +18,8 @@
 #ifndef __XFS_CRED_H__
 #define __XFS_CRED_H__
 
+#include <linux/capability.h>
+
 /*
  * Credentials
  */
@@ -27,7 +29,7 @@
 
 extern struct cred *sys_cred;
 
-/* this is a hack.. (assums sys_cred is the only cred_t in the system) */
+/* this is a hack.. (assumes sys_cred is the only cred_t in the system) */
 static __inline int capable_cred(cred_t *cr, int cid)
 {
 	return (cr == sys_cred) ? 1 : capable(cid);
diff --git a/fs/xfs/linux-2.6/xfs_file.c b/fs/xfs/linux-2.6/xfs_file.c
index 06111d0..ced4404 100644
--- a/fs/xfs/linux-2.6/xfs_file.c
+++ b/fs/xfs/linux-2.6/xfs_file.c
@@ -509,16 +509,14 @@
 	vnode_t		*vp = LINVFS_GET_VP(inode);
 	xfs_mount_t	*mp = XFS_VFSTOM(vp->v_vfsp);
 	int		error = 0;
-	bhv_desc_t	*bdp;
 	xfs_inode_t	*ip;
 
 	if (vp->v_vfsp->vfs_flag & VFS_DMI) {
-		bdp = vn_bhv_lookup(VN_BHV_HEAD(vp), &xfs_vnodeops);
-		if (!bdp) {
+		ip = xfs_vtoi(vp);
+		if (!ip) {
 			error = -EINVAL;
 			goto open_exec_out;
 		}
-		ip = XFS_BHVTOI(bdp);
 		if (DM_EVENT_ENABLED(vp->v_vfsp, ip, DM_EVENT_READ)) {
 			error = -XFS_SEND_DATA(mp, DM_EVENT_READ, vp,
 					       0, 0, 0, NULL);
diff --git a/fs/xfs/linux-2.6/xfs_ioctl.c b/fs/xfs/linux-2.6/xfs_ioctl.c
index b78b5eb..4db4779 100644
--- a/fs/xfs/linux-2.6/xfs_ioctl.c
+++ b/fs/xfs/linux-2.6/xfs_ioctl.c
@@ -52,6 +52,7 @@
 #include "xfs_dfrag.h"
 #include "xfs_fsops.h"
 
+#include <linux/capability.h>
 #include <linux/dcache.h>
 #include <linux/mount.h>
 #include <linux/namei.h>
@@ -145,13 +146,10 @@
 
 	if (cmd != XFS_IOC_PATH_TO_FSHANDLE) {
 		xfs_inode_t	*ip;
-		bhv_desc_t	*bhv;
 		int		lock_mode;
 
 		/* need to get access to the xfs_inode to read the generation */
-		bhv = vn_bhv_lookup_unlocked(VN_BHV_HEAD(vp), &xfs_vnodeops);
-		ASSERT(bhv);
-		ip = XFS_BHVTOI(bhv);
+		ip = xfs_vtoi(vp);
 		ASSERT(ip);
 		lock_mode = xfs_ilock_map_shared(ip);
 
@@ -530,6 +528,8 @@
 	char			*kbuf;
 	int			error = EFAULT;
 
+	if (IS_RDONLY(&vp->v_inode))
+		return -EROFS;
 	if (IS_IMMUTABLE(&vp->v_inode) || IS_APPEND(&vp->v_inode))
 		return EPERM;
 	if (len > XATTR_SIZE_MAX)
@@ -557,6 +557,9 @@
 {
 	int			error;
 
+
+	if (IS_RDONLY(&vp->v_inode))
+		return -EROFS;
 	if (IS_IMMUTABLE(&vp->v_inode) || IS_APPEND(&vp->v_inode))
 		return EPERM;
 
@@ -745,9 +748,8 @@
 			(ip->i_d.di_flags & XFS_DIFLAG_REALTIME) ?
 			mp->m_rtdev_targp : mp->m_ddev_targp;
 
-		da.d_mem = da.d_miniosz = 1 << target->pbr_sshift;
-		/* The size dio will do in one go */
-		da.d_maxiosz = 64 * PAGE_CACHE_SIZE;
+		da.d_mem = da.d_miniosz = 1 << target->bt_sshift;
+		da.d_maxiosz = INT_MAX & ~(da.d_miniosz - 1);
 
 		if (copy_to_user(arg, &da, sizeof(da)))
 			return -XFS_ERROR(EFAULT);
diff --git a/fs/xfs/linux-2.6/xfs_ioctl32.c b/fs/xfs/linux-2.6/xfs_ioctl32.c
index c83ae15..a7c9ba1 100644
--- a/fs/xfs/linux-2.6/xfs_ioctl32.c
+++ b/fs/xfs/linux-2.6/xfs_ioctl32.c
@@ -19,7 +19,6 @@
 #include <linux/compat.h>
 #include <linux/init.h>
 #include <linux/ioctl.h>
-#include <linux/ioctl32.h>
 #include <linux/syscalls.h>
 #include <linux/types.h>
 #include <linux/fs.h>
diff --git a/fs/xfs/linux-2.6/xfs_iops.c b/fs/xfs/linux-2.6/xfs_iops.c
index 41c478b..4bd3d03 100644
--- a/fs/xfs/linux-2.6/xfs_iops.c
+++ b/fs/xfs/linux-2.6/xfs_iops.c
@@ -51,8 +51,47 @@
 #include "xfs_buf_item.h"
 #include "xfs_utils.h"
 
+#include <linux/capability.h>
 #include <linux/xattr.h>
 #include <linux/namei.h>
+#include <linux/security.h>
+
+#define IS_NOATIME(inode) ((inode->i_sb->s_flags & MS_NOATIME) ||	\
+	(S_ISDIR(inode->i_mode) && inode->i_sb->s_flags & MS_NODIRATIME))
+
+/*
+ * Get a XFS inode from a given vnode.
+ */
+xfs_inode_t *
+xfs_vtoi(
+	struct vnode	*vp)
+{
+	bhv_desc_t      *bdp;
+
+	bdp = bhv_lookup_range(VN_BHV_HEAD(vp),
+			VNODE_POSITION_XFS, VNODE_POSITION_XFS);
+	if (unlikely(bdp == NULL))
+		return NULL;
+	return XFS_BHVTOI(bdp);
+}
+
+/*
+ * Bring the atime in the XFS inode uptodate.
+ * Used before logging the inode to disk or when the Linux inode goes away.
+ */
+void
+xfs_synchronize_atime(
+	xfs_inode_t	*ip)
+{
+	vnode_t		*vp;
+
+	vp = XFS_ITOV_NULL(ip);
+	if (vp) {
+		struct inode *inode = &vp->v_inode;
+		ip->i_d.di_atime.t_sec = (__int32_t)inode->i_atime.tv_sec;
+		ip->i_d.di_atime.t_nsec = (__int32_t)inode->i_atime.tv_nsec;
+	}
+}
 
 /*
  * Change the requested timestamp in the given inode.
@@ -73,23 +112,6 @@
 	struct inode	*inode = LINVFS_GET_IP(XFS_ITOV(ip));
 	timespec_t	tv;
 
-	/*
-	 * We're not supposed to change timestamps in readonly-mounted
-	 * filesystems.  Throw it away if anyone asks us.
-	 */
-	if (unlikely(IS_RDONLY(inode)))
-		return;
-
-	/*
-	 * Don't update access timestamps on reads if mounted "noatime".
-	 * Throw it away if anyone asks us.
-	 */
-	if (unlikely(
-	    (ip->i_mount->m_flags & XFS_MOUNT_NOATIME || IS_NOATIME(inode)) &&
-	    (flags & (XFS_ICHGTIME_ACC|XFS_ICHGTIME_MOD|XFS_ICHGTIME_CHG)) ==
-			XFS_ICHGTIME_ACC))
-		return;
-
 	nanotime(&tv);
 	if (flags & XFS_ICHGTIME_MOD) {
 		inode->i_mtime = tv;
@@ -126,8 +148,6 @@
  * Variant on the above which avoids querying the system clock
  * in situations where we know the Linux inode timestamps have
  * just been updated (and so we can update our inode cheaply).
- * We also skip the readonly and noatime checks here, they are
- * also catered for already.
  */
 void
 xfs_ichgtime_fast(
@@ -138,32 +158,23 @@
 	timespec_t	*tvp;
 
 	/*
+	 * Atime updates for read() & friends are handled lazily now, and
+	 * explicit updates must go through xfs_ichgtime()
+	 */
+	ASSERT((flags & XFS_ICHGTIME_ACC) == 0);
+
+	/*
 	 * We're not supposed to change timestamps in readonly-mounted
 	 * filesystems.  Throw it away if anyone asks us.
 	 */
 	if (unlikely(IS_RDONLY(inode)))
 		return;
 
-	/*
-	 * Don't update access timestamps on reads if mounted "noatime".
-	 * Throw it away if anyone asks us.
-	 */
-	if (unlikely(
-	    (ip->i_mount->m_flags & XFS_MOUNT_NOATIME || IS_NOATIME(inode)) &&
-	    ((flags & (XFS_ICHGTIME_ACC|XFS_ICHGTIME_MOD|XFS_ICHGTIME_CHG)) ==
-			XFS_ICHGTIME_ACC)))
-		return;
-
 	if (flags & XFS_ICHGTIME_MOD) {
 		tvp = &inode->i_mtime;
 		ip->i_d.di_mtime.t_sec = (__int32_t)tvp->tv_sec;
 		ip->i_d.di_mtime.t_nsec = (__int32_t)tvp->tv_nsec;
 	}
-	if (flags & XFS_ICHGTIME_ACC) {
-		tvp = &inode->i_atime;
-		ip->i_d.di_atime.t_sec = (__int32_t)tvp->tv_sec;
-		ip->i_d.di_atime.t_nsec = (__int32_t)tvp->tv_nsec;
-	}
 	if (flags & XFS_ICHGTIME_CHG) {
 		tvp = &inode->i_ctime;
 		ip->i_d.di_ctime.t_sec = (__int32_t)tvp->tv_sec;
@@ -210,6 +221,39 @@
 }
 
 /*
+ * Hook in SELinux.  This is not quite correct yet, what we really need
+ * here (as we do for default ACLs) is a mechanism by which creation of
+ * these attrs can be journalled at inode creation time (along with the
+ * inode, of course, such that log replay can't cause these to be lost).
+ */
+STATIC int
+linvfs_init_security(
+	struct vnode	*vp,
+	struct inode	*dir)
+{
+	struct inode	*ip = LINVFS_GET_IP(vp);
+	size_t		length;
+	void		*value;
+	char		*name;
+	int		error;
+
+	error = security_inode_init_security(ip, dir, &name, &value, &length);
+	if (error) {
+		if (error == -EOPNOTSUPP)
+			return 0;
+		return -error;
+	}
+
+	VOP_ATTR_SET(vp, name, value, length, ATTR_SECURE, NULL, error);
+	if (!error)
+		VMODIFY(vp);
+
+	kfree(name);
+	kfree(value);
+	return error;
+}
+
+/*
  * Determine whether a process has a valid fs_struct (kernel daemons
  * like knfsd don't have an fs_struct).
  *
@@ -274,6 +318,9 @@
 		break;
 	}
 
+	if (!error)
+		error = linvfs_init_security(vp, dir);
+
 	if (default_acl) {
 		if (!error) {
 			error = _ACL_INHERIT(vp, &va, default_acl);
@@ -290,8 +337,6 @@
 				teardown.d_inode = ip = LINVFS_GET_IP(vp);
 				teardown.d_name = dentry->d_name;
 
-				vn_mark_bad(vp);
-				
 				if (S_ISDIR(mode))
 					VOP_RMDIR(dvp, &teardown, NULL, err2);
 				else
@@ -502,7 +547,7 @@
 	ASSERT(dentry);
 	ASSERT(nd);
 
-	link = (char *)kmalloc(MAXNAMELEN+1, GFP_KERNEL);
+	link = (char *)kmalloc(MAXPATHLEN+1, GFP_KERNEL);
 	if (!link) {
 		nd_set_link(nd, ERR_PTR(-ENOMEM));
 		return NULL;
@@ -518,12 +563,12 @@
 	vp = LINVFS_GET_VP(dentry->d_inode);
 
 	iov.iov_base = link;
-	iov.iov_len = MAXNAMELEN;
+	iov.iov_len = MAXPATHLEN;
 
 	uio->uio_iov = &iov;
 	uio->uio_offset = 0;
 	uio->uio_segflg = UIO_SYSSPACE;
-	uio->uio_resid = MAXNAMELEN;
+	uio->uio_resid = MAXPATHLEN;
 	uio->uio_iovcnt = 1;
 
 	VOP_READLINK(vp, uio, 0, NULL, error);
@@ -531,7 +576,7 @@
 		kfree(link);
 		link = ERR_PTR(-error);
 	} else {
-		link[MAXNAMELEN - uio->uio_resid] = '\0';
+		link[MAXPATHLEN - uio->uio_resid] = '\0';
 	}
 	kfree(uio);
 
diff --git a/fs/xfs/linux-2.6/xfs_iops.h b/fs/xfs/linux-2.6/xfs_iops.h
index ee784b6..6899a6b 100644
--- a/fs/xfs/linux-2.6/xfs_iops.h
+++ b/fs/xfs/linux-2.6/xfs_iops.h
@@ -26,11 +26,6 @@
 extern struct file_operations linvfs_invis_file_operations;
 extern struct file_operations linvfs_dir_operations;
 
-extern struct address_space_operations linvfs_aops;
-
-extern int linvfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
-extern void linvfs_unwritten_done(struct buffer_head *, int);
-
 extern int xfs_ioctl(struct bhv_desc *, struct inode *, struct file *,
                         int, unsigned int, void __user *);
 
diff --git a/fs/xfs/linux-2.6/xfs_linux.h b/fs/xfs/linux-2.6/xfs_linux.h
index d8e21ba..67389b7 100644
--- a/fs/xfs/linux-2.6/xfs_linux.h
+++ b/fs/xfs/linux-2.6/xfs_linux.h
@@ -110,10 +110,6 @@
  * delalloc and these ondisk-uninitialised buffers.
  */
 BUFFER_FNS(PrivateStart, unwritten);
-static inline void set_buffer_unwritten_io(struct buffer_head *bh)
-{
-	bh->b_end_io = linvfs_unwritten_done;
-}
 
 #define restricted_chown	xfs_params.restrict_chown.val
 #define irix_sgid_inherit	xfs_params.sgid_inherit.val
@@ -232,7 +228,7 @@
 #define xfs_itruncate_data(ip, off)	\
 	(-vmtruncate(LINVFS_GET_IP(XFS_ITOV(ip)), (off)))
 #define xfs_statvfs_fsid(statp, mp)	\
-	({ u64 id = huge_encode_dev((mp)->m_dev);	\
+	({ u64 id = huge_encode_dev((mp)->m_ddev_targp->bt_dev); \
 	   __kernel_fsid_t *fsid = &(statp)->f_fsid;	\
 	(fsid->val[0] = (u32)id, fsid->val[1] = (u32)(id >> 32)); })
 
diff --git a/fs/xfs/linux-2.6/xfs_lrw.c b/fs/xfs/linux-2.6/xfs_lrw.c
index 5675117..e0ab45f 100644
--- a/fs/xfs/linux-2.6/xfs_lrw.c
+++ b/fs/xfs/linux-2.6/xfs_lrw.c
@@ -233,8 +233,8 @@
 		xfs_buftarg_t	*target =
 			(ip->i_d.di_flags & XFS_DIFLAG_REALTIME) ?
 				mp->m_rtdev_targp : mp->m_ddev_targp;
-		if ((*offset & target->pbr_smask) ||
-		    (size & target->pbr_smask)) {
+		if ((*offset & target->bt_smask) ||
+		    (size & target->bt_smask)) {
 			if (*offset == ip->i_d.di_size) {
 				return (0);
 			}
@@ -281,9 +281,6 @@
 
 	xfs_iunlock(ip, XFS_IOLOCK_SHARED);
 
-	if (likely(!(ioflags & IO_INVIS)))
-		xfs_ichgtime_fast(ip, inode, XFS_ICHGTIME_ACC);
-
 unlock_isem:
 	if (unlikely(ioflags & IO_ISDIRECT))
 		mutex_unlock(&inode->i_mutex);
@@ -346,9 +343,6 @@
 	if (ret > 0)
 		XFS_STATS_ADD(xs_read_bytes, ret);
 
-	if (likely(!(ioflags & IO_INVIS)))
-		xfs_ichgtime_fast(ip, LINVFS_GET_IP(vp), XFS_ICHGTIME_ACC);
-
 	return ret;
 }
 
@@ -362,7 +356,6 @@
 xfs_zero_last_block(
 	struct inode	*ip,
 	xfs_iocore_t	*io,
-	xfs_off_t	offset,
 	xfs_fsize_t	isize,
 	xfs_fsize_t	end_size)
 {
@@ -371,19 +364,16 @@
 	int		nimaps;
 	int		zero_offset;
 	int		zero_len;
-	int		isize_fsb_offset;
 	int		error = 0;
 	xfs_bmbt_irec_t	imap;
 	loff_t		loff;
-	size_t		lsize;
 
 	ASSERT(ismrlocked(io->io_lock, MR_UPDATE) != 0);
-	ASSERT(offset > isize);
 
 	mp = io->io_mount;
 
-	isize_fsb_offset = XFS_B_FSB_OFFSET(mp, isize);
-	if (isize_fsb_offset == 0) {
+	zero_offset = XFS_B_FSB_OFFSET(mp, isize);
+	if (zero_offset == 0) {
 		/*
 		 * There are no extra bytes in the last block on disk to
 		 * zero, so return.
@@ -413,10 +403,8 @@
 	 */
 	XFS_IUNLOCK(mp, io, XFS_ILOCK_EXCL| XFS_EXTSIZE_RD);
 	loff = XFS_FSB_TO_B(mp, last_fsb);
-	lsize = XFS_FSB_TO_B(mp, 1);
 
-	zero_offset = isize_fsb_offset;
-	zero_len = mp->m_sb.sb_blocksize - isize_fsb_offset;
+	zero_len = mp->m_sb.sb_blocksize - zero_offset;
 
 	error = xfs_iozero(ip, loff + zero_offset, zero_len, end_size);
 
@@ -447,20 +435,17 @@
 	struct inode	*ip = LINVFS_GET_IP(vp);
 	xfs_fileoff_t	start_zero_fsb;
 	xfs_fileoff_t	end_zero_fsb;
-	xfs_fileoff_t	prev_zero_fsb;
 	xfs_fileoff_t	zero_count_fsb;
 	xfs_fileoff_t	last_fsb;
 	xfs_extlen_t	buf_len_fsb;
-	xfs_extlen_t	prev_zero_count;
 	xfs_mount_t	*mp;
 	int		nimaps;
 	int		error = 0;
 	xfs_bmbt_irec_t	imap;
-	loff_t		loff;
-	size_t		lsize;
 
 	ASSERT(ismrlocked(io->io_lock, MR_UPDATE));
 	ASSERT(ismrlocked(io->io_iolock, MR_UPDATE));
+	ASSERT(offset > isize);
 
 	mp = io->io_mount;
 
@@ -468,7 +453,7 @@
 	 * First handle zeroing the block on which isize resides.
 	 * We only zero a part of that block so it is handled specially.
 	 */
-	error = xfs_zero_last_block(ip, io, offset, isize, end_size);
+	error = xfs_zero_last_block(ip, io, isize, end_size);
 	if (error) {
 		ASSERT(ismrlocked(io->io_lock, MR_UPDATE));
 		ASSERT(ismrlocked(io->io_iolock, MR_UPDATE));
@@ -496,8 +481,6 @@
 	}
 
 	ASSERT(start_zero_fsb <= end_zero_fsb);
-	prev_zero_fsb = NULLFILEOFF;
-	prev_zero_count = 0;
 	while (start_zero_fsb <= end_zero_fsb) {
 		nimaps = 1;
 		zero_count_fsb = end_zero_fsb - start_zero_fsb + 1;
@@ -519,10 +502,7 @@
 			 * that sits on a hole and sets the page as P_HOLE
 			 * and calls remapf if it is a mapped file.
 			 */
-			prev_zero_fsb = NULLFILEOFF;
-			prev_zero_count = 0;
-			start_zero_fsb = imap.br_startoff +
-					 imap.br_blockcount;
+			start_zero_fsb = imap.br_startoff + imap.br_blockcount;
 			ASSERT(start_zero_fsb <= (end_zero_fsb + 1));
 			continue;
 		}
@@ -543,17 +523,15 @@
 		 */
 		XFS_IUNLOCK(mp, io, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
 
-		loff = XFS_FSB_TO_B(mp, start_zero_fsb);
-		lsize = XFS_FSB_TO_B(mp, buf_len_fsb);
-
-		error = xfs_iozero(ip, loff, lsize, end_size);
+		error = xfs_iozero(ip,
+				   XFS_FSB_TO_B(mp, start_zero_fsb),
+				   XFS_FSB_TO_B(mp, buf_len_fsb),
+				   end_size);
 
 		if (error) {
 			goto out_lock;
 		}
 
-		prev_zero_fsb = start_zero_fsb;
-		prev_zero_count = buf_len_fsb;
 		start_zero_fsb = imap.br_startoff + buf_len_fsb;
 		ASSERT(start_zero_fsb <= (end_zero_fsb + 1));
 
@@ -640,7 +618,7 @@
 			(xip->i_d.di_flags & XFS_DIFLAG_REALTIME) ?
 				mp->m_rtdev_targp : mp->m_ddev_targp;
 
-		if ((pos & target->pbr_smask) || (count & target->pbr_smask))
+		if ((pos & target->bt_smask) || (count & target->bt_smask))
 			return XFS_ERROR(-EINVAL);
 
 		if (!VN_CACHED(vp) && pos < i_size_read(inode))
@@ -713,7 +691,7 @@
 	}
 
 	if (likely(!(ioflags & IO_INVIS))) {
-		inode_update_time(inode, 1);
+		file_update_time(file);
 		xfs_ichgtime_fast(xip, inode,
 				  XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
 	}
@@ -831,6 +809,10 @@
 		goto retry;
 	}
 
+	isize = i_size_read(inode);
+	if (unlikely(ret < 0 && ret != -EFAULT && *offset > isize))
+		*offset = isize;
+
 	if (*offset > xip->i_d.di_size) {
 		xfs_ilock(xip, XFS_ILOCK_EXCL);
 		if (*offset > xip->i_d.di_size) {
@@ -956,7 +938,7 @@
 
 	mp = XFS_BUF_FSPRIVATE3(bp, xfs_mount_t *);
 	if (!XFS_FORCED_SHUTDOWN(mp)) {
-		pagebuf_iorequest(bp);
+		xfs_buf_iorequest(bp);
 		return 0;
 	} else {
 		xfs_buftrace("XFS__BDSTRAT IOERROR", bp);
@@ -1009,7 +991,7 @@
 		 * if (XFS_BUF_IS_GRIO(bp)) {
 		 */
 
-		pagebuf_iorequest(bp);
+		xfs_buf_iorequest(bp);
 		return 0;
 	}
 
diff --git a/fs/xfs/linux-2.6/xfs_stats.c b/fs/xfs/linux-2.6/xfs_stats.c
index 6c40a74..8955720 100644
--- a/fs/xfs/linux-2.6/xfs_stats.c
+++ b/fs/xfs/linux-2.6/xfs_stats.c
@@ -34,7 +34,7 @@
 	__uint64_t	xs_write_bytes = 0;
 	__uint64_t	xs_read_bytes = 0;
 
-	static struct xstats_entry {
+	static const struct xstats_entry {
 		char	*desc;
 		int	endpoint;
 	} xstats[] = {
diff --git a/fs/xfs/linux-2.6/xfs_stats.h b/fs/xfs/linux-2.6/xfs_stats.h
index 50027c4..8ba7a2f 100644
--- a/fs/xfs/linux-2.6/xfs_stats.h
+++ b/fs/xfs/linux-2.6/xfs_stats.h
@@ -109,15 +109,15 @@
 	__uint32_t		vn_remove;	/* # times vn_remove called */
 	__uint32_t		vn_free;	/* # times vn_free called */
 #define XFSSTAT_END_BUF			(XFSSTAT_END_VNODE_OPS+9)
-	__uint32_t		pb_get;
-	__uint32_t		pb_create;
-	__uint32_t		pb_get_locked;
-	__uint32_t		pb_get_locked_waited;
-	__uint32_t		pb_busy_locked;
-	__uint32_t		pb_miss_locked;
-	__uint32_t		pb_page_retries;
-	__uint32_t		pb_page_found;
-	__uint32_t		pb_get_read;
+	__uint32_t		xb_get;
+	__uint32_t		xb_create;
+	__uint32_t		xb_get_locked;
+	__uint32_t		xb_get_locked_waited;
+	__uint32_t		xb_busy_locked;
+	__uint32_t		xb_miss_locked;
+	__uint32_t		xb_page_retries;
+	__uint32_t		xb_page_found;
+	__uint32_t		xb_get_read;
 /* Extra precision counters */
 	__uint64_t		xs_xstrat_bytes;
 	__uint64_t		xs_write_bytes;
diff --git a/fs/xfs/linux-2.6/xfs_super.c b/fs/xfs/linux-2.6/xfs_super.c
index 6116b5b..f22e426 100644
--- a/fs/xfs/linux-2.6/xfs_super.c
+++ b/fs/xfs/linux-2.6/xfs_super.c
@@ -306,13 +306,15 @@
 		xfs_fs_cmn_err(CE_NOTE, mp,
 		  "Disabling barriers, not supported with external log device");
 		mp->m_flags &= ~XFS_MOUNT_BARRIER;
+		return;
 	}
 
-	if (mp->m_ddev_targp->pbr_bdev->bd_disk->queue->ordered ==
+	if (mp->m_ddev_targp->bt_bdev->bd_disk->queue->ordered ==
 					QUEUE_ORDERED_NONE) {
 		xfs_fs_cmn_err(CE_NOTE, mp,
 		  "Disabling barriers, not supported by the underlying device");
 		mp->m_flags &= ~XFS_MOUNT_BARRIER;
+		return;
 	}
 
 	error = xfs_barrier_test(mp);
@@ -320,6 +322,7 @@
 		xfs_fs_cmn_err(CE_NOTE, mp,
 		  "Disabling barriers, trial barrier write failed");
 		mp->m_flags &= ~XFS_MOUNT_BARRIER;
+		return;
 	}
 }
 
@@ -327,7 +330,7 @@
 xfs_blkdev_issue_flush(
 	xfs_buftarg_t		*buftarg)
 {
-	blkdev_issue_flush(buftarg->pbr_bdev, NULL);
+	blkdev_issue_flush(buftarg->bt_bdev, NULL);
 }
 
 STATIC struct inode *
@@ -576,7 +579,7 @@
 		timeleft = schedule_timeout_interruptible(timeleft);
 		/* swsusp */
 		try_to_freeze();
-		if (kthread_should_stop())
+		if (kthread_should_stop() && list_empty(&vfsp->vfs_sync_list))
 			break;
 
 		spin_lock(&vfsp->vfs_sync_lock);
@@ -966,9 +969,9 @@
 	if (error < 0)
 		goto undo_zones;
 
-	error = pagebuf_init();
+	error = xfs_buf_init();
 	if (error < 0)
-		goto undo_pagebuf;
+		goto undo_buffers;
 
 	vn_init();
 	xfs_init();
@@ -982,9 +985,9 @@
 	return 0;
 
 undo_register:
-	pagebuf_terminate();
+	xfs_buf_terminate();
 
-undo_pagebuf:
+undo_buffers:
 	linvfs_destroy_zones();
 
 undo_zones:
@@ -998,7 +1001,7 @@
 	XFS_DM_EXIT(&xfs_fs_type);
 	unregister_filesystem(&xfs_fs_type);
 	xfs_cleanup();
-	pagebuf_terminate();
+	xfs_buf_terminate();
 	linvfs_destroy_zones();
 	ktrace_uninit();
 }
diff --git a/fs/xfs/linux-2.6/xfs_vnode.c b/fs/xfs/linux-2.6/xfs_vnode.c
index e9bbcb4..260dd84 100644
--- a/fs/xfs/linux-2.6/xfs_vnode.c
+++ b/fs/xfs/linux-2.6/xfs_vnode.c
@@ -106,7 +106,6 @@
 	inode->i_blocks	    = vap->va_nblocks;
 	inode->i_mtime	    = vap->va_mtime;
 	inode->i_ctime	    = vap->va_ctime;
-	inode->i_atime	    = vap->va_atime;
 	inode->i_blksize    = vap->va_blocksize;
 	if (vap->va_xflags & XFS_XFLAG_IMMUTABLE)
 		inode->i_flags |= S_IMMUTABLE;
diff --git a/fs/xfs/linux-2.6/xfs_vnode.h b/fs/xfs/linux-2.6/xfs_vnode.h
index f2bbb32..0fe2419 100644
--- a/fs/xfs/linux-2.6/xfs_vnode.h
+++ b/fs/xfs/linux-2.6/xfs_vnode.h
@@ -566,6 +566,25 @@
 }
 
 /*
+ * Extracting atime values in various formats
+ */
+static inline void vn_atime_to_bstime(struct vnode *vp, xfs_bstime_t *bs_atime)
+{
+	bs_atime->tv_sec = vp->v_inode.i_atime.tv_sec;
+	bs_atime->tv_nsec = vp->v_inode.i_atime.tv_nsec;
+}
+
+static inline void vn_atime_to_timespec(struct vnode *vp, struct timespec *ts)
+{
+	*ts = vp->v_inode.i_atime;
+}
+
+static inline void vn_atime_to_time_t(struct vnode *vp, time_t *tt)
+{
+	*tt = vp->v_inode.i_atime.tv_sec;
+}
+
+/*
  * Some useful predicates.
  */
 #define VN_MAPPED(vp)	mapping_mapped(LINVFS_GET_IP(vp)->i_mapping)
diff --git a/fs/xfs/quota/xfs_dquot_item.c b/fs/xfs/quota/xfs_dquot_item.c
index 2f69822..2ec6b44 100644
--- a/fs/xfs/quota/xfs_dquot_item.c
+++ b/fs/xfs/quota/xfs_dquot_item.c
@@ -239,7 +239,7 @@
 	 * trying to duplicate our effort.
 	 */
 	ASSERT(qip->qli_pushbuf_flag != 0);
-	ASSERT(qip->qli_push_owner == get_thread_id());
+	ASSERT(qip->qli_push_owner == current_pid());
 
 	/*
 	 * If flushlock isn't locked anymore, chances are that the
@@ -333,7 +333,7 @@
 			qip->qli_pushbuf_flag = 1;
 			ASSERT(qip->qli_format.qlf_blkno == dqp->q_blkno);
 #ifdef DEBUG
-			qip->qli_push_owner = get_thread_id();
+			qip->qli_push_owner = current_pid();
 #endif
 			/*
 			 * The dquot is left locked.
diff --git a/fs/xfs/quota/xfs_qm.c b/fs/xfs/quota/xfs_qm.c
index bb6991a..7dcdd06 100644
--- a/fs/xfs/quota/xfs_qm.c
+++ b/fs/xfs/quota/xfs_qm.c
@@ -1392,11 +1392,12 @@
 {
 	xfs_trans_t	*tp;
 	int		error;
-	unsigned long s;
+	unsigned long	s;
 	cred_t		zerocr;
+	xfs_inode_t	zeroino;
 	int		committed;
 
-	tp = xfs_trans_alloc(mp,XFS_TRANS_QM_QINOCREATE);
+	tp = xfs_trans_alloc(mp, XFS_TRANS_QM_QINOCREATE);
 	if ((error = xfs_trans_reserve(tp,
 				      XFS_QM_QINOCREATE_SPACE_RES(mp),
 				      XFS_CREATE_LOG_RES(mp), 0,
@@ -1406,8 +1407,9 @@
 		return (error);
 	}
 	memset(&zerocr, 0, sizeof(zerocr));
+	memset(&zeroino, 0, sizeof(zeroino));
 
-	if ((error = xfs_dir_ialloc(&tp, mp->m_rootip, S_IFREG, 1, 0,
+	if ((error = xfs_dir_ialloc(&tp, &zeroino, S_IFREG, 1, 0,
 				   &zerocr, 0, 1, ip, &committed))) {
 		xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES |
 				 XFS_TRANS_ABORT);
@@ -1918,9 +1920,7 @@
 	 * at this point (because we intentionally didn't in dqget_noattach).
 	 */
 	if (error) {
-		xfs_qm_dqpurge_all(mp,
-				   XFS_QMOPT_UQUOTA|XFS_QMOPT_GQUOTA|
-				   XFS_QMOPT_PQUOTA|XFS_QMOPT_QUOTAOFF);
+		xfs_qm_dqpurge_all(mp, XFS_QMOPT_QUOTALL | XFS_QMOPT_QUOTAOFF);
 		goto error_return;
 	}
 	/*
@@ -2743,6 +2743,7 @@
 		xfs_dqunlock(udqp);
 		ASSERT(ip->i_udquot == NULL);
 		ip->i_udquot = udqp;
+		ASSERT(XFS_IS_UQUOTA_ON(tp->t_mountp));
 		ASSERT(ip->i_d.di_uid == be32_to_cpu(udqp->q_core.d_id));
 		xfs_trans_mod_dquot(tp, udqp, XFS_TRANS_DQ_ICOUNT, 1);
 	}
@@ -2752,7 +2753,10 @@
 		xfs_dqunlock(gdqp);
 		ASSERT(ip->i_gdquot == NULL);
 		ip->i_gdquot = gdqp;
-		ASSERT(ip->i_d.di_gid == be32_to_cpu(gdqp->q_core.d_id));
+		ASSERT(XFS_IS_OQUOTA_ON(tp->t_mountp));
+		ASSERT((XFS_IS_GQUOTA_ON(tp->t_mountp) ?
+			ip->i_d.di_gid : ip->i_d.di_projid) ==
+				be32_to_cpu(gdqp->q_core.d_id));
 		xfs_trans_mod_dquot(tp, gdqp, XFS_TRANS_DQ_ICOUNT, 1);
 	}
 }
diff --git a/fs/xfs/quota/xfs_qm_syscalls.c b/fs/xfs/quota/xfs_qm_syscalls.c
index 86a1d09..6768843 100644
--- a/fs/xfs/quota/xfs_qm_syscalls.c
+++ b/fs/xfs/quota/xfs_qm_syscalls.c
@@ -15,6 +15,9 @@
  * along with this program; if not, write the Free Software Foundation,
  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
+
+#include <linux/capability.h>
+
 #include "xfs.h"
 #include "xfs_fs.h"
 #include "xfs_bit.h"
diff --git a/fs/xfs/support/debug.c b/fs/xfs/support/debug.c
index bb6dc91..b08b3d9 100644
--- a/fs/xfs/support/debug.c
+++ b/fs/xfs/support/debug.c
@@ -27,45 +27,12 @@
 /* Translate from CE_FOO to KERN_FOO, err_level(CE_FOO) == KERN_FOO */
 #define XFS_MAX_ERR_LEVEL	7
 #define XFS_ERR_MASK		((1 << 3) - 1)
-static char		*err_level[XFS_MAX_ERR_LEVEL+1] =
+static const char * const	err_level[XFS_MAX_ERR_LEVEL+1] =
 					{KERN_EMERG, KERN_ALERT, KERN_CRIT,
 					 KERN_ERR, KERN_WARNING, KERN_NOTICE,
 					 KERN_INFO, KERN_DEBUG};
 
 void
-assfail(char *a, char *f, int l)
-{
-    printk("XFS assertion failed: %s, file: %s, line: %d\n", a, f, l);
-    BUG();
-}
-
-#if ((defined(DEBUG) || defined(INDUCE_IO_ERRROR)) && !defined(NO_WANT_RANDOM))
-
-unsigned long
-random(void)
-{
-	static unsigned long	RandomValue = 1;
-	/* cycles pseudo-randomly through all values between 1 and 2^31 - 2 */
-	register long	rv = RandomValue;
-	register long	lo;
-	register long	hi;
-
-	hi = rv / 127773;
-	lo = rv % 127773;
-	rv = 16807 * lo - 2836 * hi;
-	if( rv <= 0 ) rv += 2147483647;
-	return( RandomValue = rv );
-}
-
-int
-get_thread_id(void)
-{
-	return current->pid;
-}
-
-#endif /* DEBUG || INDUCE_IO_ERRROR || !NO_WANT_RANDOM */
-
-void
 cmn_err(register int level, char *fmt, ...)
 {
 	char	*fp = fmt;
@@ -90,7 +57,6 @@
 		BUG();
 }
 
-
 void
 icmn_err(register int level, char *fmt, va_list ap)
 {
@@ -109,3 +75,27 @@
 	if (level == CE_PANIC)
 		BUG();
 }
+
+void
+assfail(char *expr, char *file, int line)
+{
+	printk("Assertion failed: %s, file: %s, line: %d\n", expr, file, line);
+	BUG();
+}
+
+#if ((defined(DEBUG) || defined(INDUCE_IO_ERRROR)) && !defined(NO_WANT_RANDOM))
+unsigned long random(void)
+{
+	static unsigned long	RandomValue = 1;
+	/* cycles pseudo-randomly through all values between 1 and 2^31 - 2 */
+	register long	rv = RandomValue;
+	register long	lo;
+	register long	hi;
+
+	hi = rv / 127773;
+	lo = rv % 127773;
+	rv = 16807 * lo - 2836 * hi;
+	if (rv <= 0) rv += 2147483647;
+	return RandomValue = rv;
+}
+#endif /* DEBUG || INDUCE_IO_ERRROR || !NO_WANT_RANDOM */
diff --git a/fs/xfs/support/debug.h b/fs/xfs/support/debug.h
index aff5586..e3bf581 100644
--- a/fs/xfs/support/debug.h
+++ b/fs/xfs/support/debug.h
@@ -31,24 +31,23 @@
 	__attribute__ ((format (printf, 2, 0)));
 extern void cmn_err(int, char *, ...)
 	__attribute__ ((format (printf, 2, 3)));
+extern void assfail(char *expr, char *f, int l);
+
+#define prdev(fmt,targ,args...) \
+	printk("Device %s - " fmt "\n", XFS_BUFTARG_NAME(targ), ## args)
+
+#define ASSERT_ALWAYS(expr)	\
+	(unlikely((expr) != 0) ? (void)0 : assfail(#expr, __FILE__, __LINE__))
+
+#ifndef DEBUG
+# define ASSERT(expr)	((void)0)
+#else
+# define ASSERT(expr)	ASSERT_ALWAYS(expr)
+extern unsigned long random(void);
+#endif
 
 #ifndef STATIC
 # define STATIC static
 #endif
 
-#ifdef DEBUG
-# define ASSERT(EX)	((EX) ? ((void)0) : assfail(#EX, __FILE__, __LINE__))
-#else
-# define ASSERT(x)	((void)0)
-#endif
-
-extern void assfail(char *, char *, int);
-#ifdef DEBUG
-extern unsigned long random(void);
-extern int get_thread_id(void);
-#endif
-
-#define ASSERT_ALWAYS(EX)  ((EX)?((void)0):assfail(#EX, __FILE__, __LINE__))
-#define	debug_stop_all_cpus(param)	/* param is "cpumask_t *" */
-
 #endif  /* __XFS_SUPPORT_DEBUG_H__ */
diff --git a/fs/xfs/support/uuid.c b/fs/xfs/support/uuid.c
index 69ec4f5..a3d565a 100644
--- a/fs/xfs/support/uuid.c
+++ b/fs/xfs/support/uuid.c
@@ -27,6 +27,16 @@
 	mutex_init(&uuid_monitor);
 }
 
+
+/* IRIX interpretation of an uuid_t */
+typedef struct {
+	__be32	uu_timelow;
+	__be16	uu_timemid;
+	__be16	uu_timehi;
+	__be16	uu_clockseq;
+	__be16	uu_node[3];
+} xfs_uu_t;
+
 /*
  * uuid_getnodeuniq - obtain the node unique fields of a UUID.
  *
@@ -36,16 +46,11 @@
 void
 uuid_getnodeuniq(uuid_t *uuid, int fsid [2])
 {
-	char	*uu = (char *)uuid;
+	xfs_uu_t *uup = (xfs_uu_t *)uuid;
 
-	/* on IRIX, this function assumes big-endian fields within
-	 * the uuid, so we use INT_GET to get the same result on
-	 * little-endian systems
-	 */
-
-	fsid[0] = (INT_GET(*(u_int16_t*)(uu+8), ARCH_CONVERT) << 16) +
-		   INT_GET(*(u_int16_t*)(uu+4), ARCH_CONVERT);
-	fsid[1] =  INT_GET(*(u_int32_t*)(uu  ), ARCH_CONVERT);
+	fsid[0] = (be16_to_cpu(uup->uu_clockseq) << 16) |
+		   be16_to_cpu(uup->uu_timemid);
+	fsid[1] = be16_to_cpu(uup->uu_timelow);
 }
 
 void
diff --git a/fs/xfs/xfs_acl.c b/fs/xfs/xfs_acl.c
index cc9c91b..4ff0f4e 100644
--- a/fs/xfs/xfs_acl.c
+++ b/fs/xfs/xfs_acl.c
@@ -36,6 +36,7 @@
 #include "xfs_mac.h"
 #include "xfs_attr.h"
 
+#include <linux/capability.h>
 #include <linux/posix_acl_xattr.h>
 
 STATIC int	xfs_acl_setmode(vnode_t *, xfs_acl_t *, int *);
diff --git a/fs/xfs/xfs_arch.h b/fs/xfs/xfs_arch.h
index 68e5051..c483689 100644
--- a/fs/xfs/xfs_arch.h
+++ b/fs/xfs/xfs_arch.h
@@ -40,6 +40,22 @@
 #undef XFS_NATIVE_HOST
 #endif
 
+#ifdef XFS_NATIVE_HOST
+#define cpu_to_be16(val)	((__be16)(val))
+#define cpu_to_be32(val)	((__be32)(val))
+#define cpu_to_be64(val)	((__be64)(val))
+#define be16_to_cpu(val)	((__uint16_t)(val))
+#define be32_to_cpu(val)	((__uint32_t)(val))
+#define be64_to_cpu(val)	((__uint64_t)(val))
+#else
+#define cpu_to_be16(val)	(__swab16((__uint16_t)(val)))
+#define cpu_to_be32(val)	(__swab32((__uint32_t)(val)))
+#define cpu_to_be64(val)	(__swab64((__uint64_t)(val)))
+#define be16_to_cpu(val)	(__swab16((__be16)(val)))
+#define be32_to_cpu(val)	(__swab32((__be32)(val)))
+#define be64_to_cpu(val)	(__swab64((__be64)(val)))
+#endif
+
 #endif	/* __KERNEL__ */
 
 /* do we need conversion? */
@@ -186,7 +202,7 @@
  */ 
 
 #define XFS_GET_DIR_INO4(di) \
-	(((u32)(di).i[0] << 24) | ((di).i[1] << 16) | ((di).i[2] << 8) | ((di).i[3]))
+	(((__u32)(di).i[0] << 24) | ((di).i[1] << 16) | ((di).i[2] << 8) | ((di).i[3]))
 
 #define XFS_PUT_DIR_INO4(from, di) \
 do { \
@@ -197,9 +213,9 @@
 } while (0)
 
 #define XFS_DI_HI(di) \
-	(((u32)(di).i[1] << 16) | ((di).i[2] << 8) | ((di).i[3]))
+	(((__u32)(di).i[1] << 16) | ((di).i[2] << 8) | ((di).i[3]))
 #define XFS_DI_LO(di) \
-	(((u32)(di).i[4] << 24) | ((di).i[5] << 16) | ((di).i[6] << 8) | ((di).i[7]))
+	(((__u32)(di).i[4] << 24) | ((di).i[5] << 16) | ((di).i[6] << 8) | ((di).i[7]))
 
 #define XFS_GET_DIR_INO8(di)        \
 	(((xfs_ino_t)XFS_DI_LO(di) & 0xffffffffULL) | \
diff --git a/fs/xfs/xfs_attr.c b/fs/xfs/xfs_attr.c
index 5484eeb..e5e91e9 100644
--- a/fs/xfs/xfs_attr.c
+++ b/fs/xfs/xfs_attr.c
@@ -15,6 +15,9 @@
  * along with this program; if not, write the Free Software Foundation,
  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
+
+#include <linux/capability.h>
+
 #include "xfs.h"
 #include "xfs_fs.h"
 #include "xfs_types.h"
@@ -117,11 +120,6 @@
 	     ip->i_d.di_anextents == 0))
 		return(ENOATTR);
 
-	if (!(flags & (ATTR_KERNACCESS|ATTR_SECURE))) {
-		if ((error = xfs_iaccess(ip, S_IRUSR, cred)))
-			return(XFS_ERROR(error));
-	}
-
 	/*
 	 * Fill in the arg structure for this request.
 	 */
@@ -425,7 +423,7 @@
 	     struct cred *cred)
 {
 	xfs_inode_t	*dp;
-	int             namelen, error;
+	int             namelen;
 
 	namelen = strlen(name);
 	if (namelen >= MAXNAMELEN)
@@ -437,14 +435,6 @@
 	if (XFS_FORCED_SHUTDOWN(dp->i_mount))
 		return (EIO);
 
-	xfs_ilock(dp, XFS_ILOCK_SHARED);
-	if (!(flags & ATTR_SECURE) &&
-	     (error = xfs_iaccess(dp, S_IWUSR, cred))) {
-		xfs_iunlock(dp, XFS_ILOCK_SHARED);
-		return(XFS_ERROR(error));
-	}
-	xfs_iunlock(dp, XFS_ILOCK_SHARED);
-
 	return xfs_attr_set_int(dp, name, namelen, value, valuelen, flags);
 }
 
@@ -579,7 +569,7 @@
 xfs_attr_remove(bhv_desc_t *bdp, const char *name, int flags, struct cred *cred)
 {
 	xfs_inode_t         *dp;
-	int                 namelen, error;
+	int                 namelen;
 
 	namelen = strlen(name);
 	if (namelen >= MAXNAMELEN)
@@ -592,11 +582,7 @@
 		return (EIO);
 
 	xfs_ilock(dp, XFS_ILOCK_SHARED);
-	if (!(flags & ATTR_SECURE) &&
-	     (error = xfs_iaccess(dp, S_IWUSR, cred))) {
-		xfs_iunlock(dp, XFS_ILOCK_SHARED);
-		return(XFS_ERROR(error));
-	} else if (XFS_IFORK_Q(dp) == 0 ||
+	if (XFS_IFORK_Q(dp) == 0 ||
 		   (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
 		    dp->i_d.di_anextents == 0)) {
 		xfs_iunlock(dp, XFS_ILOCK_SHARED);
@@ -668,12 +654,6 @@
 		return (EIO);
 
 	xfs_ilock(dp, XFS_ILOCK_SHARED);
-	if (!(flags & ATTR_SECURE) &&
-	     (error = xfs_iaccess(dp, S_IRUSR, cred))) {
-		xfs_iunlock(dp, XFS_ILOCK_SHARED);
-		return(XFS_ERROR(error));
-	}
-
 	/*
 	 * Decide on what work routines to call based on the inode size.
 	 */
diff --git a/fs/xfs/xfs_attr_leaf.c b/fs/xfs/xfs_attr_leaf.c
index 1c74218..fe91eac 100644
--- a/fs/xfs/xfs_attr_leaf.c
+++ b/fs/xfs/xfs_attr_leaf.c
@@ -128,7 +128,7 @@
 		return (offset >= minforkoff) ? minforkoff : 0;
 	}
 
-	if (unlikely(mp->m_flags & XFS_MOUNT_COMPAT_ATTR)) {
+	if (!(mp->m_flags & XFS_MOUNT_ATTR2)) {
 		if (bytes <= XFS_IFORK_ASIZE(dp))
 			return mp->m_attroffset >> 3;
 		return 0;
@@ -157,7 +157,7 @@
 {
 	unsigned long s;
 
-	if (!(mp->m_flags & XFS_MOUNT_COMPAT_ATTR) &&
+	if ((mp->m_flags & XFS_MOUNT_ATTR2) &&
 	    !(XFS_SB_VERSION_HASATTR2(&mp->m_sb))) {
 		s = XFS_SB_LOCK(mp);
 		if (!XFS_SB_VERSION_HASATTR2(&mp->m_sb)) {
@@ -311,7 +311,7 @@
 	 */
 	totsize -= size;
 	if (totsize == sizeof(xfs_attr_sf_hdr_t) && !args->addname &&
-	    !(mp->m_flags & XFS_MOUNT_COMPAT_ATTR)) {
+	    (mp->m_flags & XFS_MOUNT_ATTR2)) {
 		/*
 		 * Last attribute now removed, revert to original
 		 * inode format making all literal area available
@@ -330,7 +330,7 @@
 		dp->i_d.di_forkoff = xfs_attr_shortform_bytesfit(dp, totsize);
 		ASSERT(dp->i_d.di_forkoff);
 		ASSERT(totsize > sizeof(xfs_attr_sf_hdr_t) || args->addname ||
-			(mp->m_flags & XFS_MOUNT_COMPAT_ATTR));
+			!(mp->m_flags & XFS_MOUNT_ATTR2));
 		dp->i_afp->if_ext_max =
 			XFS_IFORK_ASIZE(dp) / (uint)sizeof(xfs_bmbt_rec_t);
 		dp->i_df.if_ext_max =
@@ -739,7 +739,7 @@
 				+ name_loc->namelen
 				+ INT_GET(name_loc->valuelen, ARCH_CONVERT);
 	}
-	if (!(dp->i_mount->m_flags & XFS_MOUNT_COMPAT_ATTR) &&
+	if ((dp->i_mount->m_flags & XFS_MOUNT_ATTR2) &&
 	    (bytes == sizeof(struct xfs_attr_sf_hdr)))
 		return(-1);
 	return(xfs_attr_shortform_bytesfit(dp, bytes));
@@ -778,7 +778,7 @@
 		goto out;
 
 	if (forkoff == -1) {
-		ASSERT(!(dp->i_mount->m_flags & XFS_MOUNT_COMPAT_ATTR));
+		ASSERT(dp->i_mount->m_flags & XFS_MOUNT_ATTR2);
 
 		/*
 		 * Last attribute was removed, revert to original
diff --git a/fs/xfs/xfs_attr_leaf.h b/fs/xfs/xfs_attr_leaf.h
index f6143ff..541e3410 100644
--- a/fs/xfs/xfs_attr_leaf.h
+++ b/fs/xfs/xfs_attr_leaf.h
@@ -63,7 +63,7 @@
  * the leaf_entry.  The namespaces are independent only because we also look
  * at the namespace bit when we are looking for a matching attribute name.
  *
- * We also store a "incomplete" bit in the leaf_entry.  It shows that an
+ * We also store an "incomplete" bit in the leaf_entry.  It shows that an
  * attribute is in the middle of being created and should not be shown to
  * the user if we crash during the time that the bit is set.  We clear the
  * bit when we have finished setting up the attribute.  We do this because
@@ -72,42 +72,48 @@
  */
 #define XFS_ATTR_LEAF_MAPSIZE	3	/* how many freespace slots */
 
+typedef struct xfs_attr_leaf_map {	/* RLE map of free bytes */
+	__uint16_t	base;	 	/* base of free region */
+	__uint16_t	size;	  	/* length of free region */
+} xfs_attr_leaf_map_t;
+
+typedef struct xfs_attr_leaf_hdr {	/* constant-structure header block */
+	xfs_da_blkinfo_t info;		/* block type, links, etc. */
+	__uint16_t	count;		/* count of active leaf_entry's */
+	__uint16_t	usedbytes;	/* num bytes of names/values stored */
+	__uint16_t	firstused;	/* first used byte in name area */
+	__uint8_t	holes;		/* != 0 if blk needs compaction */
+	__uint8_t	pad1;
+	xfs_attr_leaf_map_t freemap[XFS_ATTR_LEAF_MAPSIZE];
+					/* N largest free regions */
+} xfs_attr_leaf_hdr_t;
+
+typedef struct xfs_attr_leaf_entry {	/* sorted on key, not name */
+	xfs_dahash_t	hashval;	/* hash value of name */
+	__uint16_t	nameidx;	/* index into buffer of name/value */
+	__uint8_t	flags;		/* LOCAL/ROOT/SECURE/INCOMPLETE flag */
+	__uint8_t	pad2;		/* unused pad byte */
+} xfs_attr_leaf_entry_t;
+
+typedef struct xfs_attr_leaf_name_local {
+	__uint16_t	valuelen;	/* number of bytes in value */
+	__uint8_t	namelen;	/* length of name bytes */
+	__uint8_t	nameval[1];	/* name/value bytes */
+} xfs_attr_leaf_name_local_t;
+
+typedef struct xfs_attr_leaf_name_remote {
+	xfs_dablk_t	valueblk;	/* block number of value bytes */
+	__uint32_t	valuelen;	/* number of bytes in value */
+	__uint8_t	namelen;	/* length of name bytes */
+	__uint8_t	name[1];	/* name bytes */
+} xfs_attr_leaf_name_remote_t;
+
 typedef struct xfs_attr_leafblock {
-	struct xfs_attr_leaf_hdr {	/* constant-structure header block */
-		xfs_da_blkinfo_t info;	/* block type, links, etc. */
-		__uint16_t count;	/* count of active leaf_entry's */
-		__uint16_t usedbytes;	/* num bytes of names/values stored */
-		__uint16_t firstused;	/* first used byte in name area */
-		__uint8_t  holes;	/* != 0 if blk needs compaction */
-		__uint8_t  pad1;
-		struct xfs_attr_leaf_map {	  /* RLE map of free bytes */
-			__uint16_t base;	  /* base of free region */
-			__uint16_t size;	  /* length of free region */
-		} freemap[XFS_ATTR_LEAF_MAPSIZE]; /* N largest free regions */
-	} hdr;
-	struct xfs_attr_leaf_entry {	/* sorted on key, not name */
-		xfs_dahash_t hashval;	/* hash value of name */
-		__uint16_t nameidx;	/* index into buffer of name/value */
-		__uint8_t flags;	/* LOCAL/ROOT/SECURE/INCOMPLETE flag */
-		__uint8_t pad2;		/* unused pad byte */
-	} entries[1];			/* variable sized array */
-	struct xfs_attr_leaf_name_local {
-		__uint16_t valuelen;	/* number of bytes in value */
-		__uint8_t namelen;	/* length of name bytes */
-		__uint8_t nameval[1];	/* name/value bytes */
-	} namelist;			/* grows from bottom of buf */
-	struct xfs_attr_leaf_name_remote {
-		xfs_dablk_t valueblk;	/* block number of value bytes */
-		__uint32_t valuelen;	/* number of bytes in value */
-		__uint8_t namelen;	/* length of name bytes */
-		__uint8_t name[1];	/* name bytes */
-	} valuelist;			/* grows from bottom of buf */
+	xfs_attr_leaf_hdr_t	hdr;	/* constant-structure header block */
+	xfs_attr_leaf_entry_t	entries[1];	/* sorted on key, not name */
+	xfs_attr_leaf_name_local_t namelist;	/* grows from bottom of buf */
+	xfs_attr_leaf_name_remote_t valuelist;	/* grows from bottom of buf */
 } xfs_attr_leafblock_t;
-typedef struct xfs_attr_leaf_hdr xfs_attr_leaf_hdr_t;
-typedef struct xfs_attr_leaf_map xfs_attr_leaf_map_t;
-typedef struct xfs_attr_leaf_entry xfs_attr_leaf_entry_t;
-typedef struct xfs_attr_leaf_name_local xfs_attr_leaf_name_local_t;
-typedef struct xfs_attr_leaf_name_remote xfs_attr_leaf_name_remote_t;
 
 /*
  * Flags used in the leaf_entry[i].flags field.
@@ -150,7 +156,8 @@
 		(leafp))[INT_GET((leafp)->entries[idx].nameidx, ARCH_CONVERT)];
 }
 
-#define XFS_ATTR_LEAF_NAME(leafp,idx)		xfs_attr_leaf_name(leafp,idx)
+#define XFS_ATTR_LEAF_NAME(leafp,idx)		\
+	xfs_attr_leaf_name(leafp,idx)
 static inline char *xfs_attr_leaf_name(xfs_attr_leafblock_t *leafp, int idx)
 {
 	return (&((char *)
diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
index e415a46..70625e5 100644
--- a/fs/xfs/xfs_bmap.c
+++ b/fs/xfs/xfs_bmap.c
@@ -2146,13 +2146,176 @@
 	return 0; /* keep gcc quite */
 }
 
+/*
+ * Adjust the size of the new extent based on di_extsize and rt extsize.
+ */
+STATIC int
+xfs_bmap_extsize_align(
+	xfs_mount_t	*mp,
+	xfs_bmbt_irec_t	*gotp,		/* next extent pointer */
+	xfs_bmbt_irec_t	*prevp,		/* previous extent pointer */
+	xfs_extlen_t	extsz,		/* align to this extent size */
+	int		rt,		/* is this a realtime inode? */
+	int		eof,		/* is extent at end-of-file? */
+	int		delay,		/* creating delalloc extent? */
+	int		convert,	/* overwriting unwritten extent? */
+	xfs_fileoff_t	*offp,		/* in/out: aligned offset */
+	xfs_extlen_t	*lenp)		/* in/out: aligned length */
+{
+	xfs_fileoff_t	orig_off;	/* original offset */
+	xfs_extlen_t	orig_alen;	/* original length */
+	xfs_fileoff_t	orig_end;	/* original off+len */
+	xfs_fileoff_t	nexto;		/* next file offset */
+	xfs_fileoff_t	prevo;		/* previous file offset */
+	xfs_fileoff_t	align_off;	/* temp for offset */
+	xfs_extlen_t	align_alen;	/* temp for length */
+	xfs_extlen_t	temp;		/* temp for calculations */
+
+	if (convert)
+		return 0;
+
+	orig_off = align_off = *offp;
+	orig_alen = align_alen = *lenp;
+	orig_end = orig_off + orig_alen;
+
+	/*
+	 * If this request overlaps an existing extent, then don't
+	 * attempt to perform any additional alignment.
+	 */
+	if (!delay && !eof &&
+	    (orig_off >= gotp->br_startoff) &&
+	    (orig_end <= gotp->br_startoff + gotp->br_blockcount)) {
+		return 0;
+	}
+
+	/*
+	 * If the file offset is unaligned vs. the extent size
+	 * we need to align it.  This will be possible unless
+	 * the file was previously written with a kernel that didn't
+	 * perform this alignment, or if a truncate shot us in the
+	 * foot.
+	 */
+	temp = do_mod(orig_off, extsz);
+	if (temp) {
+		align_alen += temp;
+		align_off -= temp;
+	}
+	/*
+	 * Same adjustment for the end of the requested area.
+	 */
+	if ((temp = (align_alen % extsz))) {
+		align_alen += extsz - temp;
+	}
+	/*
+	 * If the previous block overlaps with this proposed allocation
+	 * then move the start forward without adjusting the length.
+	 */
+	if (prevp->br_startoff != NULLFILEOFF) {
+		if (prevp->br_startblock == HOLESTARTBLOCK)
+			prevo = prevp->br_startoff;
+		else
+			prevo = prevp->br_startoff + prevp->br_blockcount;
+	} else
+		prevo = 0;
+	if (align_off != orig_off && align_off < prevo)
+		align_off = prevo;
+	/*
+	 * If the next block overlaps with this proposed allocation
+	 * then move the start back without adjusting the length,
+	 * but not before offset 0.
+	 * This may of course make the start overlap previous block,
+	 * and if we hit the offset 0 limit then the next block
+	 * can still overlap too.
+	 */
+	if (!eof && gotp->br_startoff != NULLFILEOFF) {
+		if ((delay && gotp->br_startblock == HOLESTARTBLOCK) ||
+		    (!delay && gotp->br_startblock == DELAYSTARTBLOCK))
+			nexto = gotp->br_startoff + gotp->br_blockcount;
+		else
+			nexto = gotp->br_startoff;
+	} else
+		nexto = NULLFILEOFF;
+	if (!eof &&
+	    align_off + align_alen != orig_end &&
+	    align_off + align_alen > nexto)
+		align_off = nexto > align_alen ? nexto - align_alen : 0;
+	/*
+	 * If we're now overlapping the next or previous extent that
+	 * means we can't fit an extsz piece in this hole.  Just move
+	 * the start forward to the first valid spot and set
+	 * the length so we hit the end.
+	 */
+	if (align_off != orig_off && align_off < prevo)
+		align_off = prevo;
+	if (align_off + align_alen != orig_end &&
+	    align_off + align_alen > nexto &&
+	    nexto != NULLFILEOFF) {
+		ASSERT(nexto > prevo);
+		align_alen = nexto - align_off;
+	}
+
+	/*
+	 * If realtime, and the result isn't a multiple of the realtime
+	 * extent size we need to remove blocks until it is.
+	 */
+	if (rt && (temp = (align_alen % mp->m_sb.sb_rextsize))) {
+		/*
+		 * We're not covering the original request, or
+		 * we won't be able to once we fix the length.
+		 */
+		if (orig_off < align_off ||
+		    orig_end > align_off + align_alen ||
+		    align_alen - temp < orig_alen)
+			return XFS_ERROR(EINVAL);
+		/*
+		 * Try to fix it by moving the start up.
+		 */
+		if (align_off + temp <= orig_off) {
+			align_alen -= temp;
+			align_off += temp;
+		}
+		/*
+		 * Try to fix it by moving the end in.
+		 */
+		else if (align_off + align_alen - temp >= orig_end)
+			align_alen -= temp;
+		/*
+		 * Set the start to the minimum then trim the length.
+		 */
+		else {
+			align_alen -= orig_off - align_off;
+			align_off = orig_off;
+			align_alen -= align_alen % mp->m_sb.sb_rextsize;
+		}
+		/*
+		 * Result doesn't cover the request, fail it.
+		 */
+		if (orig_off < align_off || orig_end > align_off + align_alen)
+			return XFS_ERROR(EINVAL);
+	} else {
+		ASSERT(orig_off >= align_off);
+		ASSERT(orig_end <= align_off + align_alen);
+	}
+
+#ifdef DEBUG
+	if (!eof && gotp->br_startoff != NULLFILEOFF)
+		ASSERT(align_off + align_alen <= gotp->br_startoff);
+	if (prevp->br_startoff != NULLFILEOFF)
+		ASSERT(align_off >= prevp->br_startoff + prevp->br_blockcount);
+#endif
+
+	*lenp = align_alen;
+	*offp = align_off;
+	return 0;
+}
+
 #define XFS_ALLOC_GAP_UNITS	4
 
 /*
  * xfs_bmap_alloc is called by xfs_bmapi to allocate an extent for a file.
  * It figures out where to ask the underlying allocator to put the new extent.
  */
-STATIC int				/* error */
+STATIC int
 xfs_bmap_alloc(
 	xfs_bmalloca_t	*ap)		/* bmap alloc argument struct */
 {
@@ -2163,10 +2326,10 @@
 	xfs_mount_t	*mp;		/* mount point structure */
 	int		nullfb;		/* true if ap->firstblock isn't set */
 	int		rt;		/* true if inode is realtime */
-#ifdef __KERNEL__
-	xfs_extlen_t	prod=0;		/* product factor for allocators */
-	xfs_extlen_t	ralen=0;	/* realtime allocation length */
-#endif
+	xfs_extlen_t	prod = 0;	/* product factor for allocators */
+	xfs_extlen_t	ralen = 0;	/* realtime allocation length */
+	xfs_extlen_t	align;		/* minimum allocation alignment */
+	xfs_rtblock_t	rtx;
 
 #define	ISVALID(x,y)	\
 	(rt ? \
@@ -2182,125 +2345,25 @@
 	nullfb = ap->firstblock == NULLFSBLOCK;
 	rt = XFS_IS_REALTIME_INODE(ap->ip) && ap->userdata;
 	fb_agno = nullfb ? NULLAGNUMBER : XFS_FSB_TO_AGNO(mp, ap->firstblock);
-#ifdef __KERNEL__
 	if (rt) {
-		xfs_extlen_t	extsz;		/* file extent size for rt */
-		xfs_fileoff_t	nexto;		/* next file offset */
-		xfs_extlen_t	orig_alen;	/* original ap->alen */
-		xfs_fileoff_t	orig_end;	/* original off+len */
-		xfs_fileoff_t	orig_off;	/* original ap->off */
-		xfs_extlen_t	mod_off;	/* modulus calculations */
-		xfs_fileoff_t	prevo;		/* previous file offset */
-		xfs_rtblock_t	rtx;		/* realtime extent number */
-		xfs_extlen_t	temp;		/* temp for rt calculations */
+		align = ap->ip->i_d.di_extsize ?
+			ap->ip->i_d.di_extsize : mp->m_sb.sb_rextsize;
+		/* Set prod to match the extent size */
+		prod = align / mp->m_sb.sb_rextsize;
 
-		/*
-		 * Set prod to match the realtime extent size.
-		 */
-		if (!(extsz = ap->ip->i_d.di_extsize))
-			extsz = mp->m_sb.sb_rextsize;
-		prod = extsz / mp->m_sb.sb_rextsize;
-		orig_off = ap->off;
-		orig_alen = ap->alen;
-		orig_end = orig_off + orig_alen;
-		/*
-		 * If the file offset is unaligned vs. the extent size
-		 * we need to align it.  This will be possible unless
-		 * the file was previously written with a kernel that didn't
-		 * perform this alignment.
-		 */
-		mod_off = do_mod(orig_off, extsz);
-		if (mod_off) {
-			ap->alen += mod_off;
-			ap->off -= mod_off;
-		}
-		/*
-		 * Same adjustment for the end of the requested area.
-		 */
-		if ((temp = (ap->alen % extsz)))
-			ap->alen += extsz - temp;
-		/*
-		 * If the previous block overlaps with this proposed allocation
-		 * then move the start forward without adjusting the length.
-		 */
-		prevo =
-			ap->prevp->br_startoff == NULLFILEOFF ?
-				0 :
-				(ap->prevp->br_startoff +
-				 ap->prevp->br_blockcount);
-		if (ap->off != orig_off && ap->off < prevo)
-			ap->off = prevo;
-		/*
-		 * If the next block overlaps with this proposed allocation
-		 * then move the start back without adjusting the length,
-		 * but not before offset 0.
-		 * This may of course make the start overlap previous block,
-		 * and if we hit the offset 0 limit then the next block
-		 * can still overlap too.
-		 */
-		nexto = (ap->eof || ap->gotp->br_startoff == NULLFILEOFF) ?
-			NULLFILEOFF : ap->gotp->br_startoff;
-		if (!ap->eof &&
-		    ap->off + ap->alen != orig_end &&
-		    ap->off + ap->alen > nexto)
-			ap->off = nexto > ap->alen ? nexto - ap->alen : 0;
-		/*
-		 * If we're now overlapping the next or previous extent that
-		 * means we can't fit an extsz piece in this hole.  Just move
-		 * the start forward to the first valid spot and set
-		 * the length so we hit the end.
-		 */
-		if ((ap->off != orig_off && ap->off < prevo) ||
-		    (ap->off + ap->alen != orig_end &&
-		     ap->off + ap->alen > nexto)) {
-			ap->off = prevo;
-			ap->alen = nexto - prevo;
-		}
-		/*
-		 * If the result isn't a multiple of rtextents we need to
-		 * remove blocks until it is.
-		 */
-		if ((temp = (ap->alen % mp->m_sb.sb_rextsize))) {
-			/*
-			 * We're not covering the original request, or
-			 * we won't be able to once we fix the length.
-			 */
-			if (orig_off < ap->off ||
-			    orig_end > ap->off + ap->alen ||
-			    ap->alen - temp < orig_alen)
-				return XFS_ERROR(EINVAL);
-			/*
-			 * Try to fix it by moving the start up.
-			 */
-			if (ap->off + temp <= orig_off) {
-				ap->alen -= temp;
-				ap->off += temp;
-			}
-			/*
-			 * Try to fix it by moving the end in.
-			 */
-			else if (ap->off + ap->alen - temp >= orig_end)
-				ap->alen -= temp;
-			/*
-			 * Set the start to the minimum then trim the length.
-			 */
-			else {
-				ap->alen -= orig_off - ap->off;
-				ap->off = orig_off;
-				ap->alen -= ap->alen % mp->m_sb.sb_rextsize;
-			}
-			/*
-			 * Result doesn't cover the request, fail it.
-			 */
-			if (orig_off < ap->off || orig_end > ap->off + ap->alen)
-				return XFS_ERROR(EINVAL);
-		}
+		error = xfs_bmap_extsize_align(mp, ap->gotp, ap->prevp,
+						align, rt, ap->eof, 0,
+						ap->conv, &ap->off, &ap->alen);
+		if (error)
+			return error;
+		ASSERT(ap->alen);
 		ASSERT(ap->alen % mp->m_sb.sb_rextsize == 0);
+
 		/*
 		 * If the offset & length are not perfectly aligned
 		 * then kill prod, it will just get us in trouble.
 		 */
-		if (do_mod(ap->off, extsz) || ap->alen % extsz)
+		if (do_mod(ap->off, align) || ap->alen % align)
 			prod = 1;
 		/*
 		 * Set ralen to be the actual requested length in rtextents.
@@ -2326,15 +2389,24 @@
 			ap->rval = rtx * mp->m_sb.sb_rextsize;
 		} else
 			ap->rval = 0;
+	} else {
+		align = (ap->userdata && ap->ip->i_d.di_extsize &&
+			(ap->ip->i_d.di_flags & XFS_DIFLAG_EXTSIZE)) ?
+			ap->ip->i_d.di_extsize : 0;
+		if (unlikely(align)) {
+			error = xfs_bmap_extsize_align(mp, ap->gotp, ap->prevp,
+							align, rt,
+							ap->eof, 0, ap->conv,
+							&ap->off, &ap->alen);
+			ASSERT(!error);
+			ASSERT(ap->alen);
+		}
+		if (nullfb)
+			ap->rval = XFS_INO_TO_FSB(mp, ap->ip->i_ino);
+		else
+			ap->rval = ap->firstblock;
 	}
-#else
-	if (rt)
-		ap->rval = 0;
-#endif	/* __KERNEL__ */
-	else if (nullfb)
-		ap->rval = XFS_INO_TO_FSB(mp, ap->ip->i_ino);
-	else
-		ap->rval = ap->firstblock;
+
 	/*
 	 * If allocating at eof, and there's a previous real block,
 	 * try to use it's last block as our starting point.
@@ -2598,11 +2670,12 @@
 			args.total = ap->total;
 			args.minlen = ap->minlen;
 		}
-		if (ap->ip->i_d.di_extsize) {
+		if (unlikely(ap->userdata && ap->ip->i_d.di_extsize &&
+			    (ap->ip->i_d.di_flags & XFS_DIFLAG_EXTSIZE))) {
 			args.prod = ap->ip->i_d.di_extsize;
 			if ((args.mod = (xfs_extlen_t)do_mod(ap->off, args.prod)))
 				args.mod = (xfs_extlen_t)(args.prod - args.mod);
-		} else if (mp->m_sb.sb_blocksize >= NBPP) {
+		} else if (unlikely(mp->m_sb.sb_blocksize >= NBPP)) {
 			args.prod = 1;
 			args.mod = 0;
 		} else {
@@ -3580,14 +3653,16 @@
 
 	ep = xfs_bmap_do_search_extents(base, lastx, nextents, bno, eofp,
 					  lastxp, gotp, prevp);
-	rt = ip->i_d.di_flags & XFS_DIFLAG_REALTIME;
-	if(!rt && !gotp->br_startblock && (*lastxp != NULLEXTNUM)) {
+	rt = (whichfork == XFS_DATA_FORK) && XFS_IS_REALTIME_INODE(ip);
+	if (unlikely(!rt && !gotp->br_startblock && (*lastxp != NULLEXTNUM))) {
                 cmn_err(CE_PANIC,"Access to block zero: fs: <%s> inode: %lld "
 			"start_block : %llx start_off : %llx blkcnt : %llx "
 			"extent-state : %x \n",
-			(ip->i_mount)->m_fsname,(long long)ip->i_ino,
-			gotp->br_startblock, gotp->br_startoff,
-			gotp->br_blockcount,gotp->br_state);
+			(ip->i_mount)->m_fsname, (long long)ip->i_ino,
+			(unsigned long long)gotp->br_startblock,
+			(unsigned long long)gotp->br_startoff,
+			(unsigned long long)gotp->br_blockcount,
+			gotp->br_state);
         }
         return ep;
 }
@@ -3875,7 +3950,7 @@
 		ip->i_d.di_forkoff = xfs_attr_shortform_bytesfit(ip, size);
 		if (!ip->i_d.di_forkoff)
 			ip->i_d.di_forkoff = mp->m_attroffset >> 3;
-		else if (!(mp->m_flags & XFS_MOUNT_COMPAT_ATTR))
+		else if (mp->m_flags & XFS_MOUNT_ATTR2)
 			version = 2;
 		break;
 	default:
@@ -4023,13 +4098,13 @@
 	 */
 	if (whichfork == XFS_DATA_FORK) {
 		maxleafents = MAXEXTNUM;
-		sz = (mp->m_flags & XFS_MOUNT_COMPAT_ATTR) ?
-			mp->m_attroffset : XFS_BMDR_SPACE_CALC(MINDBTPTRS);
+		sz = (mp->m_flags & XFS_MOUNT_ATTR2) ?
+			XFS_BMDR_SPACE_CALC(MINDBTPTRS) : mp->m_attroffset;
 	} else {
 		maxleafents = MAXAEXTNUM;
-		sz = (mp->m_flags & XFS_MOUNT_COMPAT_ATTR) ?
-			mp->m_sb.sb_inodesize - mp->m_attroffset :
-			XFS_BMDR_SPACE_CALC(MINABTPTRS);
+		sz = (mp->m_flags & XFS_MOUNT_ATTR2) ?
+			XFS_BMDR_SPACE_CALC(MINABTPTRS) :
+			mp->m_sb.sb_inodesize - mp->m_attroffset;
 	}
 	maxrootrecs = (int)XFS_BTREE_BLOCK_MAXRECS(sz, xfs_bmdr, 0);
 	minleafrecs = mp->m_bmap_dmnr[0];
@@ -4418,8 +4493,8 @@
 		num_recs = be16_to_cpu(block->bb_numrecs);
 		if (unlikely(i + num_recs > room)) {
 			ASSERT(i + num_recs <= room);
-			xfs_fs_cmn_err(CE_WARN, ip->i_mount,
-				"corrupt dinode %Lu, (btree extents).  Unmount and run xfs_repair.",
+			xfs_fs_repair_cmn_err(CE_WARN, ip->i_mount,
+				"corrupt dinode %Lu, (btree extents).",
 				(unsigned long long) ip->i_ino);
 			XFS_ERROR_REPORT("xfs_bmap_read_extents(1)",
 					 XFS_ERRLEVEL_LOW,
@@ -4590,6 +4665,7 @@
 	char		contig;		/* allocation must be one extent */
 	char		delay;		/* this request is for delayed alloc */
 	char		exact;		/* don't do all of wasdelayed extent */
+	char		convert;	/* unwritten extent I/O completion */
 	xfs_bmbt_rec_t	*ep;		/* extent list entry pointer */
 	int		error;		/* error return */
 	xfs_bmbt_irec_t	got;		/* current extent list record */
@@ -4643,7 +4719,7 @@
 	}
 	if (XFS_FORCED_SHUTDOWN(mp))
 		return XFS_ERROR(EIO);
-	rt = XFS_IS_REALTIME_INODE(ip);
+	rt = (whichfork == XFS_DATA_FORK) && XFS_IS_REALTIME_INODE(ip);
 	ifp = XFS_IFORK_PTR(ip, whichfork);
 	ASSERT(ifp->if_ext_max ==
 	       XFS_IFORK_SIZE(ip, whichfork) / (uint)sizeof(xfs_bmbt_rec_t));
@@ -4654,6 +4730,7 @@
 	delay = (flags & XFS_BMAPI_DELAY) != 0;
 	trim = (flags & XFS_BMAPI_ENTIRE) == 0;
 	userdata = (flags & XFS_BMAPI_METADATA) == 0;
+	convert = (flags & XFS_BMAPI_CONVERT) != 0;
 	exact = (flags & XFS_BMAPI_EXACT) != 0;
 	rsvd = (flags & XFS_BMAPI_RSVBLOCKS) != 0;
 	contig = (flags & XFS_BMAPI_CONTIG) != 0;
@@ -4748,15 +4825,25 @@
 			}
 			minlen = contig ? alen : 1;
 			if (delay) {
-				xfs_extlen_t	extsz = 0;
+				xfs_extlen_t	extsz;
 
 				/* Figure out the extent size, adjust alen */
 				if (rt) {
 					if (!(extsz = ip->i_d.di_extsize))
 						extsz = mp->m_sb.sb_rextsize;
-					alen = roundup(alen, extsz);
-					extsz = alen / mp->m_sb.sb_rextsize;
+				} else {
+					extsz = ip->i_d.di_extsize;
 				}
+				if (extsz) {
+					error = xfs_bmap_extsize_align(mp,
+							&got, &prev, extsz,
+							rt, eof, delay, convert,
+							&aoff, &alen);
+					ASSERT(!error);
+				}
+
+				if (rt)
+					extsz = alen / mp->m_sb.sb_rextsize;
 
 				/*
 				 * Make a transaction-less quota reservation for
@@ -4785,32 +4872,33 @@
 					xfs_bmap_worst_indlen(ip, alen);
 				ASSERT(indlen > 0);
 
-				if (rt)
+				if (rt) {
 					error = xfs_mod_incore_sb(mp,
 							XFS_SBS_FREXTENTS,
 							-(extsz), rsvd);
-				else
+				} else {
 					error = xfs_mod_incore_sb(mp,
 							XFS_SBS_FDBLOCKS,
 							-(alen), rsvd);
+				}
 				if (!error) {
 					error = xfs_mod_incore_sb(mp,
 							XFS_SBS_FDBLOCKS,
 							-(indlen), rsvd);
-					if (error && rt) {
-						xfs_mod_incore_sb(ip->i_mount,
+					if (error && rt)
+						xfs_mod_incore_sb(mp,
 							XFS_SBS_FREXTENTS,
 							extsz, rsvd);
-					} else if (error) {
-						xfs_mod_incore_sb(ip->i_mount,
+					else if (error)
+						xfs_mod_incore_sb(mp,
 							XFS_SBS_FDBLOCKS,
 							alen, rsvd);
-					}
 				}
 
 				if (error) {
-					if (XFS_IS_QUOTA_ON(ip->i_mount))
+					if (XFS_IS_QUOTA_ON(mp))
 						/* unreserve the blocks now */
+						(void)
 						XFS_TRANS_UNRESERVE_QUOTA_NBLKS(
 							mp, NULL, ip,
 							(long)alen, 0, rt ?
@@ -4849,6 +4937,7 @@
 				bma.firstblock = *firstblock;
 				bma.alen = alen;
 				bma.off = aoff;
+				bma.conv = convert;
 				bma.wasdel = wasdelay;
 				bma.minlen = minlen;
 				bma.low = flist->xbf_low;
@@ -5270,8 +5359,7 @@
 		return 0;
 	}
 	XFS_STATS_INC(xs_blk_unmap);
-	isrt = (whichfork == XFS_DATA_FORK) &&
-	       (ip->i_d.di_flags & XFS_DIFLAG_REALTIME);
+	isrt = (whichfork == XFS_DATA_FORK) && XFS_IS_REALTIME_INODE(ip);
 	start = bno;
 	bno = start + len - 1;
 	ep = xfs_bmap_search_extents(ip, bno, whichfork, &eof, &lastx, &got,
@@ -5443,7 +5531,7 @@
 		}
 		if (wasdel) {
 			ASSERT(STARTBLOCKVAL(del.br_startblock) > 0);
-			/* Update realtim/data freespace, unreserve quota */
+			/* Update realtime/data freespace, unreserve quota */
 			if (isrt) {
 				xfs_filblks_t rtexts;
 
@@ -5451,14 +5539,14 @@
 				do_div(rtexts, mp->m_sb.sb_rextsize);
 				xfs_mod_incore_sb(mp, XFS_SBS_FREXTENTS,
 						(int)rtexts, rsvd);
-				XFS_TRANS_RESERVE_QUOTA_NBLKS(mp, NULL, ip,
-					-((long)del.br_blockcount), 0,
+				(void)XFS_TRANS_RESERVE_QUOTA_NBLKS(mp,
+					NULL, ip, -((long)del.br_blockcount), 0,
 					XFS_QMOPT_RES_RTBLKS);
 			} else {
 				xfs_mod_incore_sb(mp, XFS_SBS_FDBLOCKS,
 						(int)del.br_blockcount, rsvd);
-				XFS_TRANS_RESERVE_QUOTA_NBLKS(mp, NULL, ip,
-					-((long)del.br_blockcount), 0,
+				(void)XFS_TRANS_RESERVE_QUOTA_NBLKS(mp,
+					NULL, ip, -((long)del.br_blockcount), 0,
 					XFS_QMOPT_RES_REGBLKS);
 			}
 			ip->i_delayed_blks -= del.br_blockcount;
@@ -5652,7 +5740,9 @@
 		   ip->i_d.di_format != XFS_DINODE_FMT_LOCAL)
 		return XFS_ERROR(EINVAL);
 	if (whichfork == XFS_DATA_FORK) {
-		if (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC) {
+		if ((ip->i_d.di_extsize && (ip->i_d.di_flags &
+				(XFS_DIFLAG_REALTIME|XFS_DIFLAG_EXTSIZE))) ||
+		    ip->i_d.di_flags & (XFS_DIFLAG_PREALLOC|XFS_DIFLAG_APPEND)){
 			prealloced = 1;
 			fixlen = XFS_MAXIOFFSET(mp);
 		} else {
diff --git a/fs/xfs/xfs_bmap.h b/fs/xfs/xfs_bmap.h
index 2e0717a..12cc63d 100644
--- a/fs/xfs/xfs_bmap.h
+++ b/fs/xfs/xfs_bmap.h
@@ -62,6 +62,10 @@
 #define	XFS_BMAPI_IGSTATE	0x200	/* Ignore state - */
 					/* combine contig. space */
 #define	XFS_BMAPI_CONTIG	0x400	/* must allocate only one extent */
+/*	XFS_BMAPI_DIRECT_IO	0x800	*/
+#define XFS_BMAPI_CONVERT	0x1000	/* unwritten extent conversion - */
+					/* need write cache flushing and no */
+					/* additional allocation alignments */
 
 #define	XFS_BMAPI_AFLAG(w)	xfs_bmapi_aflag(w)
 static inline int xfs_bmapi_aflag(int w)
@@ -101,7 +105,8 @@
 	char			wasdel;	/* replacing a delayed allocation */
 	char			userdata;/* set if is user data */
 	char			low;	/* low on space, using seq'l ags */
-	char			aeof;   /* allocated space at eof */
+	char			aeof;	/* allocated space at eof */
+	char			conv;	/* overwriting unwritten extents */
 } xfs_bmalloca_t;
 
 #ifdef __KERNEL__
diff --git a/fs/xfs/xfs_clnt.h b/fs/xfs/xfs_clnt.h
index 328a528..f57cc9a 100644
--- a/fs/xfs/xfs_clnt.h
+++ b/fs/xfs/xfs_clnt.h
@@ -57,7 +57,7 @@
 /*
  * XFS mount option flags -- args->flags1
  */
-#define	XFSMNT_COMPAT_ATTR	0x00000001	/* do not use ATTR2 format */
+#define	XFSMNT_ATTR2		0x00000001	/* allow ATTR2 EA format */
 #define	XFSMNT_WSYNC		0x00000002	/* safe mode nfs mount
 						 * compatible */
 #define	XFSMNT_INO64		0x00000004	/* move inode numbers up
diff --git a/fs/xfs/xfs_dfrag.c b/fs/xfs/xfs_dfrag.c
index 070259a..c6191d0 100644
--- a/fs/xfs/xfs_dfrag.c
+++ b/fs/xfs/xfs_dfrag.c
@@ -60,8 +60,6 @@
 	xfs_bstat_t	*sbp;
 	struct file	*fp = NULL, *tfp = NULL;
 	vnode_t		*vp, *tvp;
-	bhv_desc_t      *bdp, *tbdp;
-	vn_bhv_head_t   *bhp, *tbhp;
 	static uint	lock_flags = XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL;
 	int		ilf_fields, tilf_fields;
 	int		error = 0;
@@ -90,13 +88,10 @@
 		goto error0;
 	}
 
-	bhp = VN_BHV_HEAD(vp);
-	bdp = vn_bhv_lookup(bhp, &xfs_vnodeops);
-	if (bdp == NULL) {
+	ip = xfs_vtoi(vp);
+	if (ip == NULL) {
 		error = XFS_ERROR(EBADF);
 		goto error0;
-	} else {
-		ip = XFS_BHVTOI(bdp);
 	}
 
 	if (((tfp = fget((int)sxp->sx_fdtmp)) == NULL) ||
@@ -105,13 +100,10 @@
 		goto error0;
 	}
 
-	tbhp = VN_BHV_HEAD(tvp);
-	tbdp = vn_bhv_lookup(tbhp, &xfs_vnodeops);
-	if (tbdp == NULL) {
+	tip = xfs_vtoi(tvp);
+	if (tip == NULL) {
 		error = XFS_ERROR(EBADF);
 		goto error0;
-	} else {
-		tip = XFS_BHVTOI(tbdp);
 	}
 
 	if (ip->i_mount != tip->i_mount) {
diff --git a/fs/xfs/xfs_dinode.h b/fs/xfs/xfs_dinode.h
index c5a0e53..79d0d9e 100644
--- a/fs/xfs/xfs_dinode.h
+++ b/fs/xfs/xfs_dinode.h
@@ -199,10 +199,16 @@
 
 #define XFS_DFORK_DSIZE(dip,mp) \
 	XFS_CFORK_DSIZE_DISK(&(dip)->di_core, mp)
+#define XFS_DFORK_DSIZE_HOST(dip,mp) \
+	XFS_CFORK_DSIZE(&(dip)->di_core, mp)
 #define XFS_DFORK_ASIZE(dip,mp) \
 	XFS_CFORK_ASIZE_DISK(&(dip)->di_core, mp)
+#define XFS_DFORK_ASIZE_HOST(dip,mp) \
+	XFS_CFORK_ASIZE(&(dip)->di_core, mp)
 #define	XFS_DFORK_SIZE(dip,mp,w) \
 	XFS_CFORK_SIZE_DISK(&(dip)->di_core, mp, w)
+#define	XFS_DFORK_SIZE_HOST(dip,mp,w) \
+	XFS_CFORK_SIZE(&(dip)->di_core, mp, w)
 
 #define	XFS_DFORK_Q(dip)                    XFS_CFORK_Q_DISK(&(dip)->di_core)
 #define	XFS_DFORK_BOFF(dip)		    XFS_CFORK_BOFF_DISK(&(dip)->di_core)
@@ -216,6 +222,7 @@
 #define	XFS_CFORK_FMT_SET(dcp,w,n) \
 	((w) == XFS_DATA_FORK ? \
 		((dcp)->di_format = (n)) : ((dcp)->di_aformat = (n)))
+#define	XFS_DFORK_FORMAT(dip,w) XFS_CFORK_FORMAT(&(dip)->di_core, w)
 
 #define	XFS_CFORK_NEXTENTS_DISK(dcp,w) \
 	((w) == XFS_DATA_FORK ? \
@@ -223,13 +230,13 @@
 	 	INT_GET((dcp)->di_anextents, ARCH_CONVERT))
 #define XFS_CFORK_NEXTENTS(dcp,w) \
 	((w) == XFS_DATA_FORK ? (dcp)->di_nextents : (dcp)->di_anextents)
+#define	XFS_DFORK_NEXTENTS(dip,w) XFS_CFORK_NEXTENTS_DISK(&(dip)->di_core, w)
+#define	XFS_DFORK_NEXTENTS_HOST(dip,w) XFS_CFORK_NEXTENTS(&(dip)->di_core, w)
 
 #define	XFS_CFORK_NEXT_SET(dcp,w,n) \
 	((w) == XFS_DATA_FORK ? \
 		((dcp)->di_nextents = (n)) : ((dcp)->di_anextents = (n)))
 
-#define	XFS_DFORK_NEXTENTS(dip,w) XFS_CFORK_NEXTENTS_DISK(&(dip)->di_core, w)
-
 #define	XFS_BUF_TO_DINODE(bp)	((xfs_dinode_t *)XFS_BUF_PTR(bp))
 
 /*
@@ -246,8 +253,10 @@
 #define XFS_DIFLAG_NOATIME_BIT   6	/* do not update atime */
 #define XFS_DIFLAG_NODUMP_BIT    7	/* do not dump */
 #define XFS_DIFLAG_RTINHERIT_BIT 8	/* create with realtime bit set */
-#define XFS_DIFLAG_PROJINHERIT_BIT  9	/* create with parents projid */
-#define XFS_DIFLAG_NOSYMLINKS_BIT  10	/* disallow symlink creation */
+#define XFS_DIFLAG_PROJINHERIT_BIT   9	/* create with parents projid */
+#define XFS_DIFLAG_NOSYMLINKS_BIT   10	/* disallow symlink creation */
+#define XFS_DIFLAG_EXTSIZE_BIT      11	/* inode extent size allocator hint */
+#define XFS_DIFLAG_EXTSZINHERIT_BIT 12	/* inherit inode extent size */
 #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
 #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
 #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
@@ -259,11 +268,14 @@
 #define XFS_DIFLAG_RTINHERIT     (1 << XFS_DIFLAG_RTINHERIT_BIT)
 #define XFS_DIFLAG_PROJINHERIT   (1 << XFS_DIFLAG_PROJINHERIT_BIT)
 #define XFS_DIFLAG_NOSYMLINKS    (1 << XFS_DIFLAG_NOSYMLINKS_BIT)
+#define XFS_DIFLAG_EXTSIZE       (1 << XFS_DIFLAG_EXTSIZE_BIT)
+#define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
 
 #define XFS_DIFLAG_ANY \
 	(XFS_DIFLAG_REALTIME | XFS_DIFLAG_PREALLOC | XFS_DIFLAG_NEWRTBM | \
 	 XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
 	 XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
-	 XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS)
+	 XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
+	 XFS_DIFLAG_EXTSZINHERIT)
 
 #endif	/* __XFS_DINODE_H__ */
diff --git a/fs/xfs/xfs_dir.c b/fs/xfs/xfs_dir.c
index 3dd3039..bb87d2a 100644
--- a/fs/xfs/xfs_dir.c
+++ b/fs/xfs/xfs_dir.c
@@ -176,7 +176,7 @@
 	uint shortcount, leafcount, count;
 
 	mp->m_dirversion = 1;
-	if (mp->m_flags & XFS_MOUNT_COMPAT_ATTR) {
+	if (!(mp->m_flags & XFS_MOUNT_ATTR2)) {
 		shortcount = (mp->m_attroffset -
 				(uint)sizeof(xfs_dir_sf_hdr_t)) /
 				 (uint)sizeof(xfs_dir_sf_entry_t);
diff --git a/fs/xfs/xfs_dir.h b/fs/xfs/xfs_dir.h
index 488defe..8cc8afb 100644
--- a/fs/xfs/xfs_dir.h
+++ b/fs/xfs/xfs_dir.h
@@ -135,6 +135,8 @@
 	((mp)->m_dirops.xd_shortform_to_single(args))
 
 #define	XFS_DIR_IS_V1(mp)	((mp)->m_dirversion == 1)
+#define	XFS_DIR_IS_V2(mp)	((mp)->m_dirversion == 2)
 extern xfs_dirops_t xfsv1_dirops;
+extern xfs_dirops_t xfsv2_dirops;
 
 #endif	/* __XFS_DIR_H__ */
diff --git a/fs/xfs/xfs_dir2.h b/fs/xfs/xfs_dir2.h
index 7e24ffe..3158f5d 100644
--- a/fs/xfs/xfs_dir2.h
+++ b/fs/xfs/xfs_dir2.h
@@ -72,9 +72,6 @@
 	struct uio	*uio;		/* uio control structure */
 } xfs_dir2_put_args_t;
 
-#define	XFS_DIR_IS_V2(mp)	((mp)->m_dirversion == 2)
-extern xfs_dirops_t	xfsv2_dirops;
-
 /*
  * Other interfaces used by the rest of the dir v2 code.
  */
diff --git a/fs/xfs/xfs_dir_leaf.h b/fs/xfs/xfs_dir_leaf.h
index ab6b09e..eb8cd9a 100644
--- a/fs/xfs/xfs_dir_leaf.h
+++ b/fs/xfs/xfs_dir_leaf.h
@@ -67,34 +67,38 @@
  */
 #define XFS_DIR_LEAF_MAPSIZE	3	/* how many freespace slots */
 
+typedef struct xfs_dir_leaf_map {	/* RLE map of free bytes */
+	__uint16_t	base;	 	/* base of free region */
+	__uint16_t	size; 		/* run length of free region */
+} xfs_dir_leaf_map_t;
+
+typedef struct xfs_dir_leaf_hdr {	/* constant-structure header block */
+	xfs_da_blkinfo_t info;		/* block type, links, etc. */
+	__uint16_t	count;		/* count of active leaf_entry's */
+	__uint16_t	namebytes;	/* num bytes of name strings stored */
+	__uint16_t	firstused;	/* first used byte in name area */
+	__uint8_t	holes;		/* != 0 if blk needs compaction */
+	__uint8_t	pad1;
+	xfs_dir_leaf_map_t freemap[XFS_DIR_LEAF_MAPSIZE];
+} xfs_dir_leaf_hdr_t;
+
+typedef struct xfs_dir_leaf_entry {	/* sorted on key, not name */
+	xfs_dahash_t	hashval;	/* hash value of name */
+	__uint16_t	nameidx;	/* index into buffer of name */
+	__uint8_t	namelen;	/* length of name string */
+	__uint8_t	pad2;
+} xfs_dir_leaf_entry_t;
+
+typedef struct xfs_dir_leaf_name {
+	xfs_dir_ino_t	inumber;	/* inode number for this key */
+	__uint8_t	name[1];	/* name string itself */
+} xfs_dir_leaf_name_t;
+
 typedef struct xfs_dir_leafblock {
-	struct xfs_dir_leaf_hdr {	/* constant-structure header block */
-		xfs_da_blkinfo_t info;	/* block type, links, etc. */
-		__uint16_t count;	/* count of active leaf_entry's */
-		__uint16_t namebytes;	/* num bytes of name strings stored */
-		__uint16_t firstused;	/* first used byte in name area */
-		__uint8_t  holes;	/* != 0 if blk needs compaction */
-		__uint8_t  pad1;
-		struct xfs_dir_leaf_map {/* RLE map of free bytes */
-			__uint16_t base; /* base of free region */
-			__uint16_t size; /* run length of free region */
-		} freemap[XFS_DIR_LEAF_MAPSIZE]; /* N largest free regions */
-	} hdr;
-	struct xfs_dir_leaf_entry {	/* sorted on key, not name */
-		xfs_dahash_t hashval;	/* hash value of name */
-		__uint16_t nameidx;	/* index into buffer of name */
-		__uint8_t namelen;	/* length of name string */
-		__uint8_t pad2;
-	} entries[1];			/* var sized array */
-	struct xfs_dir_leaf_name {
-		xfs_dir_ino_t inumber;	/* inode number for this key */
-		__uint8_t name[1];	/* name string itself */
-	} namelist[1];			/* grows from bottom of buf */
+	xfs_dir_leaf_hdr_t	hdr;	/* constant-structure header block */
+	xfs_dir_leaf_entry_t	entries[1];	/* var sized array */
+	xfs_dir_leaf_name_t	namelist[1];	/* grows from bottom of buf */
 } xfs_dir_leafblock_t;
-typedef struct xfs_dir_leaf_hdr xfs_dir_leaf_hdr_t;
-typedef struct xfs_dir_leaf_map xfs_dir_leaf_map_t;
-typedef struct xfs_dir_leaf_entry xfs_dir_leaf_entry_t;
-typedef struct xfs_dir_leaf_name xfs_dir_leaf_name_t;
 
 /*
  * Length of name for which a 512-byte block filesystem
@@ -126,11 +130,10 @@
 #define	XFS_PUT_COOKIE(c,mp,bno,entry,hash)	\
 	((c).s.be = XFS_DA_MAKE_BNOENTRY(mp, bno, entry), (c).s.h = (hash))
 
-typedef struct xfs_dir_put_args
-{
+typedef struct xfs_dir_put_args {
 	xfs_dircook_t	cook;		/* cookie of (next) entry */
 	xfs_intino_t	ino;		/* inode number */
-	struct xfs_dirent	*dbp;		/* buffer pointer */
+	struct xfs_dirent *dbp;		/* buffer pointer */
 	char		*name;		/* directory entry name */
 	int		namelen;	/* length of name */
 	int		done;		/* output: set if value was stored */
@@ -138,7 +141,8 @@
 	struct uio	*uio;		/* uio control structure */
 } xfs_dir_put_args_t;
 
-#define XFS_DIR_LEAF_ENTSIZE_BYNAME(len)	xfs_dir_leaf_entsize_byname(len)
+#define XFS_DIR_LEAF_ENTSIZE_BYNAME(len)	\
+	xfs_dir_leaf_entsize_byname(len)
 static inline int xfs_dir_leaf_entsize_byname(int len)
 {
 	return (uint)sizeof(xfs_dir_leaf_name_t)-1 + len;
diff --git a/fs/xfs/xfs_error.c b/fs/xfs/xfs_error.c
index d7b6b5d..2a21c50 100644
--- a/fs/xfs/xfs_error.c
+++ b/fs/xfs/xfs_error.c
@@ -54,7 +54,6 @@
 		if (e != xfs_etrap[i])
 			continue;
 		cmn_err(CE_NOTE, "xfs_error_trap: error %d", e);
-		debug_stop_all_cpus((void *)-1LL);
 		BUG();
 		break;
 	}
diff --git a/fs/xfs/xfs_error.h b/fs/xfs/xfs_error.h
index 06d8a84..26b8e70 100644
--- a/fs/xfs/xfs_error.h
+++ b/fs/xfs/xfs_error.h
@@ -18,9 +18,6 @@
 #ifndef	__XFS_ERROR_H__
 #define	__XFS_ERROR_H__
 
-#define prdev(fmt,targ,args...) \
-	printk("XFS: device %s - " fmt "\n", XFS_BUFTARG_NAME(targ), ## args)
-
 #define XFS_ERECOVER	1	/* Failure to recover log */
 #define XFS_ELOGSTAT	2	/* Failure to stat log in user space */
 #define XFS_ENOLOGSPACE	3	/* Reservation too large */
@@ -182,8 +179,11 @@
 struct xfs_mount;
 /* PRINTFLIKE4 */
 extern void xfs_cmn_err(int panic_tag, int level, struct xfs_mount *mp,
-			    char *fmt, ...);
+			char *fmt, ...);
 /* PRINTFLIKE3 */
 extern void xfs_fs_cmn_err(int level, struct xfs_mount *mp, char *fmt, ...);
 
+#define xfs_fs_repair_cmn_err(level, mp, fmt, args...) \
+	xfs_fs_cmn_err(level, mp, fmt "  Unmount and run xfs_repair.", ## args)
+
 #endif	/* __XFS_ERROR_H__ */
diff --git a/fs/xfs/xfs_fs.h b/fs/xfs/xfs_fs.h
index ba096f8..14010f1 100644
--- a/fs/xfs/xfs_fs.h
+++ b/fs/xfs/xfs_fs.h
@@ -3,15 +3,15 @@
  * 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.
+ * modify it under the terms of the GNU Lesser 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.  See the
- * GNU General Public License for more details.
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
+ * You should have received a copy of the GNU Lesser General Public License
  * along with this program; if not, write the Free Software Foundation,
  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
@@ -65,6 +65,8 @@
 #define XFS_XFLAG_RTINHERIT	0x00000100	/* create with rt bit set */
 #define XFS_XFLAG_PROJINHERIT	0x00000200	/* create with parents projid */
 #define XFS_XFLAG_NOSYMLINKS	0x00000400	/* disallow symlink creation */
+#define XFS_XFLAG_EXTSIZE	0x00000800	/* extent size allocator hint */
+#define XFS_XFLAG_EXTSZINHERIT	0x00001000	/* inherit inode extent size */
 #define XFS_XFLAG_HASATTR	0x80000000	/* no DIFLAG for this	*/
 
 /*
diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c
index d1236d6..163031c 100644
--- a/fs/xfs/xfs_fsops.c
+++ b/fs/xfs/xfs_fsops.c
@@ -540,6 +540,32 @@
 	return(0);
 }
 
+void
+xfs_fs_log_dummy(xfs_mount_t *mp)
+{
+	xfs_trans_t *tp;
+	xfs_inode_t *ip;
+
+
+	tp = _xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
+	atomic_inc(&mp->m_active_trans);
+	if (xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0)) {
+		xfs_trans_cancel(tp, 0);
+		return;
+	}
+
+	ip = mp->m_rootip;
+	xfs_ilock(ip, XFS_ILOCK_EXCL);
+
+	xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
+	xfs_trans_ihold(tp, ip);
+	xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
+	xfs_trans_set_sync(tp);
+	xfs_trans_commit(tp, 0, NULL);
+
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+}
+
 int
 xfs_fs_goingdown(
 	xfs_mount_t	*mp,
diff --git a/fs/xfs/xfs_fsops.h b/fs/xfs/xfs_fsops.h
index f32713f..300d0c9 100644
--- a/fs/xfs/xfs_fsops.h
+++ b/fs/xfs/xfs_fsops.h
@@ -25,5 +25,6 @@
 extern int xfs_reserve_blocks(xfs_mount_t *mp, __uint64_t *inval,
 				xfs_fsop_resblks_t *outval);
 extern int xfs_fs_goingdown(xfs_mount_t *mp, __uint32_t inflags);
+extern void xfs_fs_log_dummy(xfs_mount_t *mp);
 
 #endif	/* __XFS_FSOPS_H__ */
diff --git a/fs/xfs/xfs_iget.c b/fs/xfs/xfs_iget.c
index fc19eed..8e380a1 100644
--- a/fs/xfs/xfs_iget.c
+++ b/fs/xfs/xfs_iget.c
@@ -493,7 +493,6 @@
 
 retry:
 	if ((inode = iget_locked(XFS_MTOVFS(mp)->vfs_super, ino))) {
-		bhv_desc_t	*bdp;
 		xfs_inode_t	*ip;
 
 		vp = LINVFS_GET_VP(inode);
@@ -517,14 +516,12 @@
 			 * to wait for the inode to go away.
 			 */
 			if (is_bad_inode(inode) ||
-			    ((bdp = vn_bhv_lookup(VN_BHV_HEAD(vp),
-						  &xfs_vnodeops)) == NULL)) {
+			    ((ip = xfs_vtoi(vp)) == NULL)) {
 				iput(inode);
 				delay(1);
 				goto retry;
 			}
 
-			ip = XFS_BHVTOI(bdp);
 			if (lock_flags != 0)
 				xfs_ilock(ip, lock_flags);
 			XFS_STATS_INC(xs_ig_found);
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index df0d457..1d7f5a7 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -404,9 +404,8 @@
 	    INT_GET(dip->di_core.di_nextents, ARCH_CONVERT) +
 		INT_GET(dip->di_core.di_anextents, ARCH_CONVERT) >
 	    INT_GET(dip->di_core.di_nblocks, ARCH_CONVERT))) {
-		xfs_fs_cmn_err(CE_WARN, ip->i_mount,
-			"corrupt dinode %Lu, extent total = %d, nblocks = %Lu."
-			"  Unmount and run xfs_repair.",
+		xfs_fs_repair_cmn_err(CE_WARN, ip->i_mount,
+			"corrupt dinode %Lu, extent total = %d, nblocks = %Lu.",
 			(unsigned long long)ip->i_ino,
 			(int)(INT_GET(dip->di_core.di_nextents, ARCH_CONVERT)
 			    + INT_GET(dip->di_core.di_anextents, ARCH_CONVERT)),
@@ -418,9 +417,8 @@
 	}
 
 	if (unlikely(INT_GET(dip->di_core.di_forkoff, ARCH_CONVERT) > ip->i_mount->m_sb.sb_inodesize)) {
-		xfs_fs_cmn_err(CE_WARN, ip->i_mount,
-			"corrupt dinode %Lu, forkoff = 0x%x."
-			"  Unmount and run xfs_repair.",
+		xfs_fs_repair_cmn_err(CE_WARN, ip->i_mount,
+			"corrupt dinode %Lu, forkoff = 0x%x.",
 			(unsigned long long)ip->i_ino,
 			(int)(INT_GET(dip->di_core.di_forkoff, ARCH_CONVERT)));
 		XFS_CORRUPTION_ERROR("xfs_iformat(2)", XFS_ERRLEVEL_LOW,
@@ -451,8 +449,9 @@
 			 * no local regular files yet
 			 */
 			if (unlikely((INT_GET(dip->di_core.di_mode, ARCH_CONVERT) & S_IFMT) == S_IFREG)) {
-				xfs_fs_cmn_err(CE_WARN, ip->i_mount,
-					"corrupt inode (local format for regular file) %Lu.  Unmount and run xfs_repair.",
+				xfs_fs_repair_cmn_err(CE_WARN, ip->i_mount,
+					"corrupt inode %Lu "
+					"(local format for regular file).",
 					(unsigned long long) ip->i_ino);
 				XFS_CORRUPTION_ERROR("xfs_iformat(4)",
 						     XFS_ERRLEVEL_LOW,
@@ -462,8 +461,9 @@
 
 			di_size = INT_GET(dip->di_core.di_size, ARCH_CONVERT);
 			if (unlikely(di_size > XFS_DFORK_DSIZE(dip, ip->i_mount))) {
-				xfs_fs_cmn_err(CE_WARN, ip->i_mount,
-					"corrupt inode %Lu (bad size %Ld for local inode).  Unmount and run xfs_repair.",
+				xfs_fs_repair_cmn_err(CE_WARN, ip->i_mount,
+					"corrupt inode %Lu "
+					"(bad size %Ld for local inode).",
 					(unsigned long long) ip->i_ino,
 					(long long) di_size);
 				XFS_CORRUPTION_ERROR("xfs_iformat(5)",
@@ -551,8 +551,9 @@
 	 * kmem_alloc() or memcpy() below.
 	 */
 	if (unlikely(size > XFS_DFORK_SIZE(dip, ip->i_mount, whichfork))) {
-		xfs_fs_cmn_err(CE_WARN, ip->i_mount,
-			"corrupt inode %Lu (bad size %d for local fork, size = %d).  Unmount and run xfs_repair.",
+		xfs_fs_repair_cmn_err(CE_WARN, ip->i_mount,
+			"corrupt inode %Lu "
+			"(bad size %d for local fork, size = %d).",
 			(unsigned long long) ip->i_ino, size,
 			XFS_DFORK_SIZE(dip, ip->i_mount, whichfork));
 		XFS_CORRUPTION_ERROR("xfs_iformat_local", XFS_ERRLEVEL_LOW,
@@ -610,8 +611,8 @@
 	 * kmem_alloc() or memcpy() below.
 	 */
 	if (unlikely(size < 0 || size > XFS_DFORK_SIZE(dip, ip->i_mount, whichfork))) {
-		xfs_fs_cmn_err(CE_WARN, ip->i_mount,
-			"corrupt inode %Lu ((a)extents = %d).  Unmount and run xfs_repair.",
+		xfs_fs_repair_cmn_err(CE_WARN, ip->i_mount,
+			"corrupt inode %Lu ((a)extents = %d).",
 			(unsigned long long) ip->i_ino, nex);
 		XFS_CORRUPTION_ERROR("xfs_iformat_extents(1)", XFS_ERRLEVEL_LOW,
 				     ip->i_mount, dip);
@@ -692,8 +693,8 @@
 	    || XFS_BMDR_SPACE_CALC(nrecs) >
 			XFS_DFORK_SIZE(dip, ip->i_mount, whichfork)
 	    || XFS_IFORK_NEXTENTS(ip, whichfork) > ip->i_d.di_nblocks)) {
-		xfs_fs_cmn_err(CE_WARN, ip->i_mount,
-			"corrupt inode %Lu (btree).  Unmount and run xfs_repair.",
+		xfs_fs_repair_cmn_err(CE_WARN, ip->i_mount,
+			"corrupt inode %Lu (btree).",
 			(unsigned long long) ip->i_ino);
 		XFS_ERROR_REPORT("xfs_iformat_btree", XFS_ERRLEVEL_LOW,
 				 ip->i_mount);
@@ -809,6 +810,10 @@
 			flags |= XFS_XFLAG_PROJINHERIT;
 		if (di_flags & XFS_DIFLAG_NOSYMLINKS)
 			flags |= XFS_XFLAG_NOSYMLINKS;
+		if (di_flags & XFS_DIFLAG_EXTSIZE)
+			flags |= XFS_XFLAG_EXTSIZE;
+		if (di_flags & XFS_DIFLAG_EXTSZINHERIT)
+			flags |= XFS_XFLAG_EXTSZINHERIT;
 	}
 
 	return flags;
@@ -1192,11 +1197,19 @@
 			if ((mode & S_IFMT) == S_IFDIR) {
 				if (pip->i_d.di_flags & XFS_DIFLAG_RTINHERIT)
 					di_flags |= XFS_DIFLAG_RTINHERIT;
-			} else {
+				if (pip->i_d.di_flags & XFS_DIFLAG_EXTSZINHERIT) {
+					di_flags |= XFS_DIFLAG_EXTSZINHERIT;
+					ip->i_d.di_extsize = pip->i_d.di_extsize;
+				}
+			} else if ((mode & S_IFMT) == S_IFREG) {
 				if (pip->i_d.di_flags & XFS_DIFLAG_RTINHERIT) {
 					di_flags |= XFS_DIFLAG_REALTIME;
 					ip->i_iocore.io_flags |= XFS_IOCORE_RT;
 				}
+				if (pip->i_d.di_flags & XFS_DIFLAG_EXTSZINHERIT) {
+					di_flags |= XFS_DIFLAG_EXTSIZE;
+					ip->i_d.di_extsize = pip->i_d.di_extsize;
+				}
 			}
 			if ((pip->i_d.di_flags & XFS_DIFLAG_NOATIME) &&
 			    xfs_inherit_noatime)
@@ -1262,7 +1275,7 @@
 	if ((ip->i_d.di_mode & S_IFMT) != S_IFREG)
 		return;
 
-	if ( ip->i_d.di_flags & XFS_DIFLAG_REALTIME )
+	if (ip->i_d.di_flags & (XFS_DIFLAG_REALTIME | XFS_DIFLAG_EXTSIZE))
 		return;
 
 	nimaps = 2;
@@ -1765,22 +1778,19 @@
 	xfs_fsize_t	new_size,
 	cred_t		*credp)
 {
-	xfs_fsize_t	isize;
 	int		error;
 
 	ASSERT(ismrlocked(&(ip->i_lock), MR_UPDATE) != 0);
 	ASSERT(ismrlocked(&(ip->i_iolock), MR_UPDATE) != 0);
 	ASSERT(new_size > ip->i_d.di_size);
 
-	error = 0;
-	isize = ip->i_d.di_size;
 	/*
 	 * Zero any pages that may have been created by
 	 * xfs_write_file() beyond the end of the file
 	 * and any blocks between the old and new file sizes.
 	 */
-	error = xfs_zero_eof(XFS_ITOV(ip), &ip->i_iocore, new_size, isize,
-				new_size);
+	error = xfs_zero_eof(XFS_ITOV(ip), &ip->i_iocore, new_size,
+			     ip->i_d.di_size, new_size);
 	return error;
 }
 
@@ -3355,6 +3365,11 @@
 	ip->i_update_core = 0;
 	SYNCHRONIZE();
 
+	/*
+	 * Make sure to get the latest atime from the Linux inode.
+	 */
+	xfs_synchronize_atime(ip);
+
 	if (XFS_TEST_ERROR(INT_GET(dip->di_core.di_magic,ARCH_CONVERT) != XFS_DINODE_MAGIC,
 			       mp, XFS_ERRTAG_IFLUSH_1, XFS_RANDOM_IFLUSH_1)) {
 		xfs_cmn_err(XFS_PTAG_IFLUSH, CE_ALERT, mp,
diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h
index 124d30e..1cfbcf1 100644
--- a/fs/xfs/xfs_inode.h
+++ b/fs/xfs/xfs_inode.h
@@ -436,6 +436,10 @@
 xfs_fsize_t	xfs_file_last_byte(xfs_inode_t *);
 void		xfs_lock_inodes(xfs_inode_t **, int, int, uint);
 
+xfs_inode_t	*xfs_vtoi(struct vnode *vp);
+
+void		xfs_synchronize_atime(xfs_inode_t *);
+
 #define xfs_ipincount(ip)	((unsigned int) atomic_read(&ip->i_pincount))
 
 #ifdef DEBUG
diff --git a/fs/xfs/xfs_inode_item.c b/fs/xfs/xfs_inode_item.c
index 7f3363c..36aa1fc 100644
--- a/fs/xfs/xfs_inode_item.c
+++ b/fs/xfs/xfs_inode_item.c
@@ -271,6 +271,11 @@
 	if (ip->i_update_size)
 		ip->i_update_size = 0;
 
+	/*
+	 * Make sure to get the latest atime from the Linux inode.
+	 */
+	xfs_synchronize_atime(ip);
+
 	vecp->i_addr = (xfs_caddr_t)&ip->i_d;
 	vecp->i_len  = sizeof(xfs_dinode_core_t);
 	XLOG_VEC_SET_TYPE(vecp, XLOG_REG_TYPE_ICORE);
@@ -603,7 +608,7 @@
 		if (iip->ili_pushbuf_flag == 0) {
 			iip->ili_pushbuf_flag = 1;
 #ifdef DEBUG
-			iip->ili_push_owner = get_thread_id();
+			iip->ili_push_owner = current_pid();
 #endif
 			/*
 			 * Inode is left locked in shared mode.
@@ -782,7 +787,7 @@
 	 * trying to duplicate our effort.
 	 */
 	ASSERT(iip->ili_pushbuf_flag != 0);
-	ASSERT(iip->ili_push_owner == get_thread_id());
+	ASSERT(iip->ili_push_owner == current_pid());
 
 	/*
 	 * If flushlock isn't locked anymore, chances are that the
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index 45a77a3..788917f3 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -40,7 +40,6 @@
 #include "xfs_ialloc.h"
 #include "xfs_btree.h"
 #include "xfs_bmap.h"
-#include "xfs_bit.h"
 #include "xfs_rtalloc.h"
 #include "xfs_error.h"
 #include "xfs_itable.h"
@@ -263,7 +262,7 @@
 	case BMAPI_WRITE:
 		/* If we found an extent, return it */
 		if (nimaps &&
-		    (imap.br_startblock != HOLESTARTBLOCK) && 
+		    (imap.br_startblock != HOLESTARTBLOCK) &&
 		    (imap.br_startblock != DELAYSTARTBLOCK)) {
 			xfs_iomap_map_trace(XFS_IOMAP_WRITE_MAP, io,
 					offset, count, iomapp, &imap, flags);
@@ -318,6 +317,58 @@
 }
 
 STATIC int
+xfs_iomap_eof_align_last_fsb(
+	xfs_mount_t	*mp,
+	xfs_iocore_t	*io,
+	xfs_fsize_t	isize,
+	xfs_extlen_t	extsize,
+	xfs_fileoff_t	*last_fsb)
+{
+	xfs_fileoff_t	new_last_fsb = 0;
+	xfs_extlen_t	align;
+	int		eof, error;
+
+	if (io->io_flags & XFS_IOCORE_RT)
+		;
+	/*
+	 * If mounted with the "-o swalloc" option, roundup the allocation
+	 * request to a stripe width boundary if the file size is >=
+	 * stripe width and we are allocating past the allocation eof.
+	 */
+	else if (mp->m_swidth && (mp->m_flags & XFS_MOUNT_SWALLOC) &&
+	        (isize >= XFS_FSB_TO_B(mp, mp->m_swidth)))
+		new_last_fsb = roundup_64(*last_fsb, mp->m_swidth);
+	/*
+	 * Roundup the allocation request to a stripe unit (m_dalign) boundary
+	 * if the file size is >= stripe unit size, and we are allocating past
+	 * the allocation eof.
+	 */
+	else if (mp->m_dalign && (isize >= XFS_FSB_TO_B(mp, mp->m_dalign)))
+		new_last_fsb = roundup_64(*last_fsb, mp->m_dalign);
+
+	/*
+	 * Always round up the allocation request to an extent boundary
+	 * (when file on a real-time subvolume or has di_extsize hint).
+	 */
+	if (extsize) {
+		if (new_last_fsb)
+			align = roundup_64(new_last_fsb, extsize);
+		else
+			align = extsize;
+		new_last_fsb = roundup_64(*last_fsb, align);
+	}
+
+	if (new_last_fsb) {
+		error = XFS_BMAP_EOF(mp, io, new_last_fsb, XFS_DATA_FORK, &eof);
+		if (error)
+			return error;
+		if (eof)
+			*last_fsb = new_last_fsb;
+	}
+	return 0;
+}
+
+STATIC int
 xfs_flush_space(
 	xfs_inode_t	*ip,
 	int		*fsynced,
@@ -363,19 +414,20 @@
 	xfs_iocore_t	*io = &ip->i_iocore;
 	xfs_fileoff_t	offset_fsb;
 	xfs_fileoff_t	last_fsb;
-	xfs_filblks_t	count_fsb;
+	xfs_filblks_t	count_fsb, resaligned;
 	xfs_fsblock_t	firstfsb;
+	xfs_extlen_t	extsz, temp;
+	xfs_fsize_t	isize;
 	int		nimaps;
-	int		error;
 	int		bmapi_flag;
 	int		quota_flag;
 	int		rt;
 	xfs_trans_t	*tp;
 	xfs_bmbt_irec_t imap;
 	xfs_bmap_free_t free_list;
-	xfs_filblks_t	qblocks, resblks;
+	uint		qblocks, resblks, resrtextents;
 	int		committed;
-	int		resrtextents;
+	int		error;
 
 	/*
 	 * Make sure that the dquots are there. This doesn't hold
@@ -385,38 +437,53 @@
 	if (error)
 		return XFS_ERROR(error);
 
-	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);
-	}
-
-	/*
-	 * Determine if reserving space on the data or realtime partition.
-	 */
-	if ((rt = XFS_IS_REALTIME_INODE(ip))) {
-		xfs_extlen_t	extsz;
-
+	rt = XFS_IS_REALTIME_INODE(ip);
+	if (unlikely(rt)) {
 		if (!(extsz = ip->i_d.di_extsize))
 			extsz = mp->m_sb.sb_rextsize;
-		resrtextents = qblocks = (count_fsb + extsz - 1);
-		do_div(resrtextents, mp->m_sb.sb_rextsize);
-		resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0);
-		quota_flag = XFS_QMOPT_RES_RTBLKS;
 	} else {
-		resrtextents = 0;
-		resblks = qblocks = XFS_DIOSTRAT_SPACE_RES(mp, count_fsb);
-		quota_flag = XFS_QMOPT_RES_REGBLKS;
+		extsz = ip->i_d.di_extsize;
 	}
 
+	isize = ip->i_d.di_size;
+	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)));
+	if ((offset + count) > isize) {
+		error = xfs_iomap_eof_align_last_fsb(mp, io, isize, extsz,
+							&last_fsb);
+		if (error)
+			goto error_out;
+	} else {
+		if (found && (ret_imap->br_startblock == HOLESTARTBLOCK))
+			last_fsb = MIN(last_fsb, (xfs_fileoff_t)
+					ret_imap->br_blockcount +
+					ret_imap->br_startoff);
+	}
+	count_fsb = last_fsb - offset_fsb;
+	ASSERT(count_fsb > 0);
+
+	resaligned = count_fsb;
+	if (unlikely(extsz)) {
+		if ((temp = do_mod(offset_fsb, extsz)))
+			resaligned += temp;
+		if ((temp = do_mod(resaligned, extsz)))
+			resaligned += extsz - temp;
+	}
+
+	if (unlikely(rt)) {
+		resrtextents = qblocks = resaligned;
+		resrtextents /= mp->m_sb.sb_rextsize;
+  		resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0);
+  		quota_flag = XFS_QMOPT_RES_RTBLKS;
+  	} else {
+  		resrtextents = 0;
+		resblks = qblocks = XFS_DIOSTRAT_SPACE_RES(mp, resaligned);
+  		quota_flag = XFS_QMOPT_RES_REGBLKS;
+  	}
+
 	/*
 	 * Allocate and setup the transaction
 	 */
@@ -426,7 +493,6 @@
 			XFS_WRITE_LOG_RES(mp), resrtextents,
 			XFS_TRANS_PERM_LOG_RES,
 			XFS_WRITE_LOG_COUNT);
-
 	/*
 	 * Check for running out of space, note: need lock to return
 	 */
@@ -436,20 +502,20 @@
 	if (error)
 		goto error_out;
 
-	if (XFS_TRANS_RESERVE_QUOTA_NBLKS(mp, tp, ip, qblocks, 0, quota_flag)) {
-		error = (EDQUOT);
+	error = XFS_TRANS_RESERVE_QUOTA_NBLKS(mp, tp, ip,
+					      qblocks, 0, quota_flag);
+	if (error)
 		goto error1;
-	}
 
-	bmapi_flag = XFS_BMAPI_WRITE;
 	xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
 	xfs_trans_ihold(tp, ip);
 
-	if (!(flags & BMAPI_MMAP) && (offset < ip->i_d.di_size || rt))
+	bmapi_flag = XFS_BMAPI_WRITE;
+	if ((flags & BMAPI_DIRECT) && (offset < ip->i_d.di_size || extsz))
 		bmapi_flag |= XFS_BMAPI_PREALLOC;
 
 	/*
-	 * Issue the bmapi() call to allocate the blocks
+	 * Issue the xfs_bmapi() call to allocate the blocks
 	 */
 	XFS_BMAP_INIT(&free_list, &firstfsb);
 	nimaps = 1;
@@ -484,8 +550,10 @@
                         "extent-state : %x \n",
                         (ip->i_mount)->m_fsname,
                         (long long)ip->i_ino,
-                        ret_imap->br_startblock, ret_imap->br_startoff,
-                        ret_imap->br_blockcount,ret_imap->br_state);
+                        (unsigned long long)ret_imap->br_startblock,
+			(unsigned long long)ret_imap->br_startoff,
+                        (unsigned long long)ret_imap->br_blockcount,
+			ret_imap->br_state);
         }
 	return 0;
 
@@ -501,6 +569,63 @@
 	return XFS_ERROR(error);
 }
 
+/*
+ * If the caller is doing a write at the end of the file,
+ * then extend the allocation out to the file system's write
+ * iosize.  We clean up any extra space left over when the
+ * file is closed in xfs_inactive().
+ *
+ * For sync writes, we are flushing delayed allocate space to
+ * try to make additional space available for allocation near
+ * the filesystem full boundary - preallocation hurts in that
+ * situation, of course.
+ */
+STATIC int
+xfs_iomap_eof_want_preallocate(
+	xfs_mount_t	*mp,
+	xfs_iocore_t	*io,
+	xfs_fsize_t	isize,
+	xfs_off_t	offset,
+	size_t		count,
+	int		ioflag,
+	xfs_bmbt_irec_t *imap,
+	int		nimaps,
+	int		*prealloc)
+{
+	xfs_fileoff_t   start_fsb;
+	xfs_filblks_t   count_fsb;
+	xfs_fsblock_t	firstblock;
+	int		n, error, imaps;
+
+	*prealloc = 0;
+	if ((ioflag & BMAPI_SYNC) || (offset + count) <= isize)
+		return 0;
+
+	/*
+	 * If there are any real blocks past eof, then don't
+	 * do any speculative allocation.
+	 */
+	start_fsb = XFS_B_TO_FSBT(mp, ((xfs_ufsize_t)(offset + count - 1)));
+	count_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)XFS_MAXIOFFSET(mp));
+	while (count_fsb > 0) {
+		imaps = nimaps;
+		firstblock = NULLFSBLOCK;
+		error = XFS_BMAPI(mp, NULL, io, start_fsb, count_fsb,
+				  0, &firstblock, 0, imap, &imaps, NULL);
+		if (error)
+			return error;
+		for (n = 0; n < imaps; n++) {
+			if ((imap[n].br_startblock != HOLESTARTBLOCK) &&
+			    (imap[n].br_startblock != DELAYSTARTBLOCK))
+				return 0;
+			start_fsb += imap[n].br_blockcount;
+			count_fsb -= imap[n].br_blockcount;
+		}
+	}
+	*prealloc = 1;
+	return 0;
+}
+
 int
 xfs_iomap_write_delay(
 	xfs_inode_t	*ip,
@@ -514,13 +639,15 @@
 	xfs_iocore_t	*io = &ip->i_iocore;
 	xfs_fileoff_t	offset_fsb;
 	xfs_fileoff_t	last_fsb;
-	xfs_fsize_t	isize;
+	xfs_off_t	aligned_offset;
+	xfs_fileoff_t	ioalign;
 	xfs_fsblock_t	firstblock;
+	xfs_extlen_t	extsz;
+	xfs_fsize_t	isize;
 	int		nimaps;
-	int		error;
 	xfs_bmbt_irec_t imap[XFS_WRITE_IMAPS];
-	int		aeof;
-	int		fsynced = 0;
+	int		prealloc, fsynced = 0;
+	int		error;
 
 	ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE) != 0);
 
@@ -528,152 +655,57 @@
 	 * Make sure that the dquots are there. This doesn't hold
 	 * the ilock across a disk read.
 	 */
-
 	error = XFS_QM_DQATTACH(mp, ip, XFS_QMOPT_ILOCKED);
 	if (error)
 		return XFS_ERROR(error);
 
+	if (XFS_IS_REALTIME_INODE(ip)) {
+		if (!(extsz = ip->i_d.di_extsize))
+			extsz = mp->m_sb.sb_rextsize;
+	} else {
+		extsz = ip->i_d.di_extsize;
+	}
+
+	offset_fsb = XFS_B_TO_FSBT(mp, offset);
+
 retry:
 	isize = ip->i_d.di_size;
-	if (io->io_new_size > isize) {
+	if (io->io_new_size > isize)
 		isize = io->io_new_size;
-	}
 
-	aeof = 0;
-	offset_fsb = XFS_B_TO_FSBT(mp, offset);
-	last_fsb = XFS_B_TO_FSB(mp, ((xfs_ufsize_t)(offset + count)));
-	/*
-	 * If the caller is doing a write at the end of the file,
-	 * 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().
-	 *
-	 * For sync writes, we are flushing delayed allocate space to
-	 * try to make additional space available for allocation near
-	 * the filesystem full boundary - preallocation hurts in that
-	 * situation, of course.
-	 */
-	if (!(ioflag & BMAPI_SYNC) && ((offset + count) > ip->i_d.di_size)) {
-		xfs_off_t	aligned_offset;
-		xfs_filblks_t   count_fsb;
-		unsigned int	iosize;
-		xfs_fileoff_t	ioalign;
-		int		n;
-		xfs_fileoff_t   start_fsb;
+	error = xfs_iomap_eof_want_preallocate(mp, io, isize, offset, count,
+				ioflag, imap, XFS_WRITE_IMAPS, &prealloc);
+	if (error)
+		return error;
 
-		/*
-		 * If there are any real blocks past eof, then don't
-		 * do any speculative allocation.
-		 */
-		start_fsb = XFS_B_TO_FSBT(mp,
-					((xfs_ufsize_t)(offset + count - 1)));
-		count_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)XFS_MAXIOFFSET(mp));
-		while (count_fsb > 0) {
-			nimaps = XFS_WRITE_IMAPS;
-			error = XFS_BMAPI(mp, NULL, io, start_fsb, count_fsb,
-					0, &firstblock, 0, imap, &nimaps, NULL);
-			if (error) {
-				return error;
-			}
-			for (n = 0; n < nimaps; n++) {
-				if ( !(io->io_flags & XFS_IOCORE_RT)  && 
-					!imap[n].br_startblock) {
-					cmn_err(CE_PANIC,"Access to block "
-						"zero:  fs <%s> inode: %lld "
-						"start_block : %llx start_off "
-						": %llx blkcnt : %llx "
-						"extent-state : %x \n",
-						(ip->i_mount)->m_fsname,
-						(long long)ip->i_ino,
-						imap[n].br_startblock,
-						imap[n].br_startoff,
-						imap[n].br_blockcount,
-						imap[n].br_state);
-        			}
-				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;
-			}
-		}
-		iosize = mp->m_writeio_blocks;
+	if (prealloc) {
 		aligned_offset = XFS_WRITEIO_ALIGN(mp, (offset + count - 1));
 		ioalign = XFS_B_TO_FSBT(mp, aligned_offset);
-		last_fsb = ioalign + iosize;
-		aeof = 1;
+		last_fsb = ioalign + mp->m_writeio_blocks;
+	} else {
+		last_fsb = XFS_B_TO_FSB(mp, ((xfs_ufsize_t)(offset + count)));
 	}
-write_map:
+
+	if (prealloc || extsz) {
+		error = xfs_iomap_eof_align_last_fsb(mp, io, isize, extsz,
+							&last_fsb);
+		if (error)
+			return error;
+	}
+
 	nimaps = XFS_WRITE_IMAPS;
 	firstblock = NULLFSBLOCK;
-
-	/*
-	 * If mounted with the "-o swalloc" option, roundup the allocation
-	 * request to a stripe width boundary if the file size is >=
-	 * stripe width and we are allocating past the allocation eof.
-	 */
-	if (!(io->io_flags & XFS_IOCORE_RT) && mp->m_swidth 
-	    && (mp->m_flags & XFS_MOUNT_SWALLOC)
-	    && (isize >= XFS_FSB_TO_B(mp, mp->m_swidth)) && aeof) {
-		int eof;
-		xfs_fileoff_t new_last_fsb;
-
-		new_last_fsb = roundup_64(last_fsb, mp->m_swidth);
-		error = xfs_bmap_eof(ip, new_last_fsb, XFS_DATA_FORK, &eof);
-		if (error) {
-			return error;
-		}
-		if (eof) {
-			last_fsb = new_last_fsb;
-		}
-	/*
-	 * Roundup the allocation request to a stripe unit (m_dalign) boundary
-	 * if the file size is >= stripe unit size, and we are allocating past
-	 * the allocation eof.
-	 */
-	} else if (!(io->io_flags & XFS_IOCORE_RT) && mp->m_dalign &&
-		   (isize >= XFS_FSB_TO_B(mp, 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(ip, new_last_fsb, XFS_DATA_FORK, &eof);
-		if (error) {
-			return error;
-		}
-		if (eof) {
-			last_fsb = new_last_fsb;
-		}
-	/*
-	 * Round up the allocation request to a real-time extent boundary
-	 * if the file is on the real-time subvolume.
-	 */
-	} else if (io->io_flags & XFS_IOCORE_RT && aeof) {
-		int eof;
-		xfs_fileoff_t new_last_fsb;
-
-		new_last_fsb = roundup_64(last_fsb, mp->m_sb.sb_rextsize);
-		error = XFS_BMAP_EOF(mp, io, new_last_fsb, XFS_DATA_FORK, &eof);
-		if (error) {
-			return error;
-		}
-		if (eof)
-			last_fsb = new_last_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,
 			  &nimaps, NULL);
-	/*
-	 * This can be EDQUOT, if nimaps == 0
-	 */
-	if (error && (error != ENOSPC)) {
+	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.
+	 * then we must have run out of space - flush delalloc, and retry..
 	 */
 	if (nimaps == 0) {
 		xfs_iomap_enter_trace(XFS_IOMAP_WRITE_NOSPACE,
@@ -685,17 +717,21 @@
 		goto retry;
 	}
 
-	*ret_imap = imap[0];
-	*nmaps = 1;
-	if ( !(io->io_flags & XFS_IOCORE_RT)  && !ret_imap->br_startblock) {
+	if (!(io->io_flags & XFS_IOCORE_RT)  && !ret_imap->br_startblock) {
 		cmn_err(CE_PANIC,"Access to block zero:  fs <%s> inode: %lld "
                         "start_block : %llx start_off : %llx blkcnt : %llx "
                         "extent-state : %x \n",
                         (ip->i_mount)->m_fsname,
                         (long long)ip->i_ino,
-                        ret_imap->br_startblock, ret_imap->br_startoff,
-                        ret_imap->br_blockcount,ret_imap->br_state);
+                        (unsigned long long)ret_imap->br_startblock,
+			(unsigned long long)ret_imap->br_startoff,
+                        (unsigned long long)ret_imap->br_blockcount,
+			ret_imap->br_state);
 	}
+
+	*ret_imap = imap[0];
+	*nmaps = 1;
+
 	return 0;
 }
 
@@ -821,17 +857,21 @@
 		 */
 
 		for (i = 0; i < nimaps; i++) {
-			if ( !(io->io_flags & XFS_IOCORE_RT)  && 
-				!imap[i].br_startblock) {
+			if (!(io->io_flags & XFS_IOCORE_RT)  &&
+			    !imap[i].br_startblock) {
 				cmn_err(CE_PANIC,"Access to block zero:  "
 					"fs <%s> inode: %lld "
-					"start_block : %llx start_off : %llx " 
+					"start_block : %llx start_off : %llx "
 					"blkcnt : %llx extent-state : %x \n",
 					(ip->i_mount)->m_fsname,
 					(long long)ip->i_ino,
-					imap[i].br_startblock,
-					imap[i].br_startoff,
-				        imap[i].br_blockcount,imap[i].br_state);
+					(unsigned long long)
+						imap[i].br_startblock,
+					(unsigned long long)
+						imap[i].br_startoff,
+					(unsigned long long)
+				        	imap[i].br_blockcount,
+					imap[i].br_state);
                         }
 			if ((offset_fsb >= imap[i].br_startoff) &&
 			    (offset_fsb < (imap[i].br_startoff +
@@ -868,17 +908,17 @@
 {
 	xfs_mount_t	*mp = ip->i_mount;
 	xfs_iocore_t    *io = &ip->i_iocore;
-	xfs_trans_t	*tp;
 	xfs_fileoff_t	offset_fsb;
 	xfs_filblks_t	count_fsb;
 	xfs_filblks_t	numblks_fsb;
-	xfs_bmbt_irec_t	imap;
+	xfs_fsblock_t	firstfsb;
+	int		nimaps;
+	xfs_trans_t	*tp;
+	xfs_bmbt_irec_t imap;
+	xfs_bmap_free_t free_list;
+	uint		resblks;
 	int		committed;
 	int		error;
-	int		nres;
-	int		nimaps;
-	xfs_fsblock_t	firstfsb;
-	xfs_bmap_free_t	free_list;
 
 	xfs_iomap_enter_trace(XFS_IOMAP_UNWRITTEN,
 				&ip->i_iocore, offset, count);
@@ -887,9 +927,9 @@
 	count_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + count);
 	count_fsb = (xfs_filblks_t)(count_fsb - offset_fsb);
 
-	do {
-		nres = XFS_DIOSTRAT_SPACE_RES(mp, 0);
+	resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0) << 1;
 
+	do {
 		/*
 		 * set up a transaction to convert the range of extents
 		 * from unwritten to real. Do allocations in a loop until
@@ -897,7 +937,7 @@
 		 */
 
 		tp = xfs_trans_alloc(mp, XFS_TRANS_STRAT_WRITE);
-		error = xfs_trans_reserve(tp, nres,
+		error = xfs_trans_reserve(tp, resblks,
 				XFS_WRITE_LOG_RES(mp), 0,
 				XFS_TRANS_PERM_LOG_RES,
 				XFS_WRITE_LOG_COUNT);
@@ -916,7 +956,7 @@
 		XFS_BMAP_INIT(&free_list, &firstfsb);
 		nimaps = 1;
 		error = xfs_bmapi(tp, ip, offset_fsb, count_fsb,
-				  XFS_BMAPI_WRITE, &firstfsb,
+				  XFS_BMAPI_WRITE|XFS_BMAPI_CONVERT, &firstfsb,
 				  1, &imap, &nimaps, &free_list);
 		if (error)
 			goto error_on_bmapi_transaction;
@@ -930,15 +970,17 @@
 		xfs_iunlock(ip, XFS_ILOCK_EXCL);
 		if (error)
 			goto error0;
-		
+
 		if ( !(io->io_flags & XFS_IOCORE_RT)  && !imap.br_startblock) {
 			cmn_err(CE_PANIC,"Access to block zero:  fs <%s> "
 				"inode: %lld start_block : %llx start_off : "
 				"%llx blkcnt : %llx extent-state : %x \n",
 				(ip->i_mount)->m_fsname,
 				(long long)ip->i_ino,
-				imap.br_startblock,imap.br_startoff,
-				imap.br_blockcount,imap.br_state);
+				(unsigned long long)imap.br_startblock,
+				(unsigned long long)imap.br_startoff,
+				(unsigned long long)imap.br_blockcount,
+				imap.br_state);
         	}
 
 		if ((numblks_fsb = imap.br_blockcount) == 0) {
diff --git a/fs/xfs/xfs_itable.c b/fs/xfs/xfs_itable.c
index f63646e..c59450e 100644
--- a/fs/xfs/xfs_itable.c
+++ b/fs/xfs/xfs_itable.c
@@ -56,6 +56,7 @@
 {
 	xfs_dinode_core_t *dic;		/* dinode core info pointer */
 	xfs_inode_t	*ip;		/* incore inode pointer */
+	vnode_t		*vp;
 	int		error;
 
 	error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, bno);
@@ -72,6 +73,7 @@
 		goto out_iput;
 	}
 
+	vp = XFS_ITOV(ip);
 	dic = &ip->i_d;
 
 	/* xfs_iget returns the following without needing
@@ -84,8 +86,7 @@
 	buf->bs_uid = dic->di_uid;
 	buf->bs_gid = dic->di_gid;
 	buf->bs_size = dic->di_size;
-	buf->bs_atime.tv_sec = dic->di_atime.t_sec;
-	buf->bs_atime.tv_nsec = dic->di_atime.t_nsec;
+	vn_atime_to_bstime(vp, &buf->bs_atime);
 	buf->bs_mtime.tv_sec = dic->di_mtime.t_sec;
 	buf->bs_mtime.tv_nsec = dic->di_mtime.t_nsec;
 	buf->bs_ctime.tv_sec = dic->di_ctime.t_sec;
diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c
index 29af512..3d9a36e 100644
--- a/fs/xfs/xfs_log.c
+++ b/fs/xfs/xfs_log.c
@@ -178,6 +178,83 @@
 #define	xlog_trace_iclog(iclog,state)
 #endif /* XFS_LOG_TRACE */
 
+
+static void
+xlog_ins_ticketq(struct xlog_ticket **qp, struct xlog_ticket *tic)
+{
+	if (*qp) {
+		tic->t_next	    = (*qp);
+		tic->t_prev	    = (*qp)->t_prev;
+		(*qp)->t_prev->t_next = tic;
+		(*qp)->t_prev	    = tic;
+	} else {
+		tic->t_prev = tic->t_next = tic;
+		*qp = tic;
+	}
+
+	tic->t_flags |= XLOG_TIC_IN_Q;
+}
+
+static void
+xlog_del_ticketq(struct xlog_ticket **qp, struct xlog_ticket *tic)
+{
+	if (tic == tic->t_next) {
+		*qp = NULL;
+	} else {
+		*qp = tic->t_next;
+		tic->t_next->t_prev = tic->t_prev;
+		tic->t_prev->t_next = tic->t_next;
+	}
+
+	tic->t_next = tic->t_prev = NULL;
+	tic->t_flags &= ~XLOG_TIC_IN_Q;
+}
+
+static void
+xlog_grant_sub_space(struct log *log, int bytes)
+{
+	log->l_grant_write_bytes -= bytes;
+	if (log->l_grant_write_bytes < 0) {
+		log->l_grant_write_bytes += log->l_logsize;
+		log->l_grant_write_cycle--;
+	}
+
+	log->l_grant_reserve_bytes -= bytes;
+	if ((log)->l_grant_reserve_bytes < 0) {
+		log->l_grant_reserve_bytes += log->l_logsize;
+		log->l_grant_reserve_cycle--;
+	}
+
+}
+
+static void
+xlog_grant_add_space_write(struct log *log, int bytes)
+{
+	log->l_grant_write_bytes += bytes;
+	if (log->l_grant_write_bytes > log->l_logsize) {
+		log->l_grant_write_bytes -= log->l_logsize;
+		log->l_grant_write_cycle++;
+	}
+}
+
+static void
+xlog_grant_add_space_reserve(struct log *log, int bytes)
+{
+	log->l_grant_reserve_bytes += bytes;
+	if (log->l_grant_reserve_bytes > log->l_logsize) {
+		log->l_grant_reserve_bytes -= log->l_logsize;
+		log->l_grant_reserve_cycle++;
+	}
+}
+
+static inline void
+xlog_grant_add_space(struct log *log, int bytes)
+{
+	xlog_grant_add_space_write(log, bytes);
+	xlog_grant_add_space_reserve(log, bytes);
+}
+
+
 /*
  * NOTES:
  *
@@ -428,7 +505,7 @@
 		if (readonly)
 			vfsp->vfs_flag &= ~VFS_RDONLY;
 
-		error = xlog_recover(mp->m_log, readonly);
+		error = xlog_recover(mp->m_log);
 
 		if (readonly)
 			vfsp->vfs_flag |= VFS_RDONLY;
@@ -1320,8 +1397,7 @@
 
 	/* move grant heads by roundoff in sync */
 	s = GRANT_LOCK(log);
-	XLOG_GRANT_ADD_SPACE(log, roundoff, 'w');
-	XLOG_GRANT_ADD_SPACE(log, roundoff, 'r');
+	xlog_grant_add_space(log, roundoff);
 	GRANT_UNLOCK(log, s);
 
 	/* put cycle number in every block */
@@ -1515,7 +1591,6 @@
  * print out info relating to regions written which consume
  * the reservation
  */
-#if defined(XFS_LOG_RES_DEBUG)
 STATIC void
 xlog_print_tic_res(xfs_mount_t *mp, xlog_ticket_t *ticket)
 {
@@ -1605,11 +1680,11 @@
 			ticket->t_res_arr_sum, ticket->t_res_o_flow,
 			ticket->t_res_num_ophdrs, ophdr_spc,
 			ticket->t_res_arr_sum + 
-			  ticket->t_res_o_flow + ophdr_spc,
+			ticket->t_res_o_flow + ophdr_spc,
 			ticket->t_res_num);
 
 	for (i = 0; i < ticket->t_res_num; i++) {
-	   	uint r_type = ticket->t_res_arr[i].r_type; 
+		uint r_type = ticket->t_res_arr[i].r_type; 
 		cmn_err(CE_WARN,
 			    "region[%u]: %s - %u bytes\n",
 			    i, 
@@ -1618,9 +1693,6 @@
 			    ticket->t_res_arr[i].r_len);
 	}
 }
-#else
-#define xlog_print_tic_res(mp, ticket)
-#endif
 
 /*
  * Write some region out to in-core log
@@ -2389,7 +2461,7 @@
 
 	/* something is already sleeping; insert new transaction at end */
 	if (log->l_reserve_headq) {
-		XLOG_INS_TICKETQ(log->l_reserve_headq, tic);
+		xlog_ins_ticketq(&log->l_reserve_headq, tic);
 		xlog_trace_loggrant(log, tic,
 				    "xlog_grant_log_space: sleep 1");
 		/*
@@ -2422,7 +2494,7 @@
 				     log->l_grant_reserve_bytes);
 	if (free_bytes < need_bytes) {
 		if ((tic->t_flags & XLOG_TIC_IN_Q) == 0)
-			XLOG_INS_TICKETQ(log->l_reserve_headq, tic);
+			xlog_ins_ticketq(&log->l_reserve_headq, tic);
 		xlog_trace_loggrant(log, tic,
 				    "xlog_grant_log_space: sleep 2");
 		XFS_STATS_INC(xs_sleep_logspace);
@@ -2439,11 +2511,10 @@
 		s = GRANT_LOCK(log);
 		goto redo;
 	} else if (tic->t_flags & XLOG_TIC_IN_Q)
-		XLOG_DEL_TICKETQ(log->l_reserve_headq, tic);
+		xlog_del_ticketq(&log->l_reserve_headq, tic);
 
 	/* we've got enough space */
-	XLOG_GRANT_ADD_SPACE(log, need_bytes, 'w');
-	XLOG_GRANT_ADD_SPACE(log, need_bytes, 'r');
+	xlog_grant_add_space(log, need_bytes);
 #ifdef DEBUG
 	tail_lsn = log->l_tail_lsn;
 	/*
@@ -2464,7 +2535,7 @@
 
  error_return:
 	if (tic->t_flags & XLOG_TIC_IN_Q)
-		XLOG_DEL_TICKETQ(log->l_reserve_headq, tic);
+		xlog_del_ticketq(&log->l_reserve_headq, tic);
 	xlog_trace_loggrant(log, tic, "xlog_grant_log_space: err_ret");
 	/*
 	 * If we are failing, make sure the ticket doesn't have any
@@ -2533,7 +2604,7 @@
 
 		if (ntic != log->l_write_headq) {
 			if ((tic->t_flags & XLOG_TIC_IN_Q) == 0)
-				XLOG_INS_TICKETQ(log->l_write_headq, tic);
+				xlog_ins_ticketq(&log->l_write_headq, tic);
 
 			xlog_trace_loggrant(log, tic,
 				    "xlog_regrant_write_log_space: sleep 1");
@@ -2565,7 +2636,7 @@
 				     log->l_grant_write_bytes);
 	if (free_bytes < need_bytes) {
 		if ((tic->t_flags & XLOG_TIC_IN_Q) == 0)
-			XLOG_INS_TICKETQ(log->l_write_headq, tic);
+			xlog_ins_ticketq(&log->l_write_headq, tic);
 		XFS_STATS_INC(xs_sleep_logspace);
 		sv_wait(&tic->t_sema, PINOD|PLTWAIT, &log->l_grant_lock, s);
 
@@ -2581,9 +2652,10 @@
 		s = GRANT_LOCK(log);
 		goto redo;
 	} else if (tic->t_flags & XLOG_TIC_IN_Q)
-		XLOG_DEL_TICKETQ(log->l_write_headq, tic);
+		xlog_del_ticketq(&log->l_write_headq, tic);
 
-	XLOG_GRANT_ADD_SPACE(log, need_bytes, 'w'); /* we've got enough space */
+	/* we've got enough space */
+	xlog_grant_add_space_write(log, need_bytes);
 #ifdef DEBUG
 	tail_lsn = log->l_tail_lsn;
 	if (CYCLE_LSN(tail_lsn) != log->l_grant_write_cycle) {
@@ -2600,7 +2672,7 @@
 
  error_return:
 	if (tic->t_flags & XLOG_TIC_IN_Q)
-		XLOG_DEL_TICKETQ(log->l_reserve_headq, tic);
+		xlog_del_ticketq(&log->l_reserve_headq, tic);
 	xlog_trace_loggrant(log, tic, "xlog_regrant_write_log_space: err_ret");
 	/*
 	 * If we are failing, make sure the ticket doesn't have any
@@ -2633,8 +2705,7 @@
 		ticket->t_cnt--;
 
 	s = GRANT_LOCK(log);
-	XLOG_GRANT_SUB_SPACE(log, ticket->t_curr_res, 'w');
-	XLOG_GRANT_SUB_SPACE(log, ticket->t_curr_res, 'r');
+	xlog_grant_sub_space(log, ticket->t_curr_res);
 	ticket->t_curr_res = ticket->t_unit_res;
 	XLOG_TIC_RESET_RES(ticket);
 	xlog_trace_loggrant(log, ticket,
@@ -2647,7 +2718,7 @@
 		return;
 	}
 
-	XLOG_GRANT_ADD_SPACE(log, ticket->t_unit_res, 'r');
+	xlog_grant_add_space_reserve(log, ticket->t_unit_res);
 	xlog_trace_loggrant(log, ticket,
 			    "xlog_regrant_reserve_log_space: exit");
 	xlog_verify_grant_head(log, 0);
@@ -2683,8 +2754,7 @@
 	s = GRANT_LOCK(log);
 	xlog_trace_loggrant(log, ticket, "xlog_ungrant_log_space: enter");
 
-	XLOG_GRANT_SUB_SPACE(log, ticket->t_curr_res, 'w');
-	XLOG_GRANT_SUB_SPACE(log, ticket->t_curr_res, 'r');
+	xlog_grant_sub_space(log, ticket->t_curr_res);
 
 	xlog_trace_loggrant(log, ticket, "xlog_ungrant_log_space: sub current");
 
@@ -2693,8 +2763,7 @@
 	 */
 	if (ticket->t_cnt > 0) {
 		ASSERT(ticket->t_flags & XLOG_TIC_PERM_RESERV);
-		XLOG_GRANT_SUB_SPACE(log, ticket->t_unit_res*ticket->t_cnt,'w');
-		XLOG_GRANT_SUB_SPACE(log, ticket->t_unit_res*ticket->t_cnt,'r');
+		xlog_grant_sub_space(log, ticket->t_unit_res*ticket->t_cnt);
 	}
 
 	xlog_trace_loggrant(log, ticket, "xlog_ungrant_log_space: exit");
diff --git a/fs/xfs/xfs_log.h b/fs/xfs/xfs_log.h
index f40d439..4b2ac88 100644
--- a/fs/xfs/xfs_log.h
+++ b/fs/xfs/xfs_log.h
@@ -96,7 +96,6 @@
 
 
 /* Region types for iovec's i_type */
-#if defined(XFS_LOG_RES_DEBUG)
 #define XLOG_REG_TYPE_BFORMAT		1
 #define XLOG_REG_TYPE_BCHUNK		2
 #define XLOG_REG_TYPE_EFI_FORMAT	3
@@ -117,21 +116,13 @@
 #define XLOG_REG_TYPE_COMMIT		18
 #define XLOG_REG_TYPE_TRANSHDR		19
 #define XLOG_REG_TYPE_MAX		19
-#endif
 
-#if defined(XFS_LOG_RES_DEBUG)
 #define XLOG_VEC_SET_TYPE(vecp, t) ((vecp)->i_type = (t))
-#else
-#define XLOG_VEC_SET_TYPE(vecp, t)
-#endif
-
 
 typedef struct xfs_log_iovec {
 	xfs_caddr_t		i_addr;		/* beginning address of region */
 	int		i_len;		/* length in bytes of region */
-#if defined(XFS_LOG_RES_DEBUG)
- 	uint		i_type;		/* type of region */
-#endif
+	uint		i_type;		/* type of region */
 } xfs_log_iovec_t;
 
 typedef void* xfs_log_ticket_t;
diff --git a/fs/xfs/xfs_log_priv.h b/fs/xfs/xfs_log_priv.h
index 4518b18..34bcbf5 100644
--- a/fs/xfs/xfs_log_priv.h
+++ b/fs/xfs/xfs_log_priv.h
@@ -253,7 +253,6 @@
 
 
 /* Ticket reservation region accounting */ 
-#if defined(XFS_LOG_RES_DEBUG)
 #define XLOG_TIC_LEN_MAX	15
 #define XLOG_TIC_RESET_RES(t) ((t)->t_res_num = \
 				(t)->t_res_arr_sum = (t)->t_res_num_ophdrs = 0)
@@ -278,15 +277,9 @@
  * we don't care about.
  */
 typedef struct xlog_res {
-	uint	r_len;
-	uint	r_type;
+	uint	r_len;	/* region length		:4 */
+	uint	r_type;	/* region's transaction type	:4 */
 } xlog_res_t;
-#else
-#define XLOG_TIC_RESET_RES(t)
-#define XLOG_TIC_ADD_OPHDR(t)
-#define XLOG_TIC_ADD_REGION(t, len, type)
-#endif
-
 
 typedef struct xlog_ticket {
 	sv_t		   t_sema;	 /* sleep on this semaphore      : 20 */
@@ -301,14 +294,12 @@
 	char		   t_flags;	 /* properties of reservation	 : 1  */
 	uint		   t_trans_type; /* transaction type             : 4  */
 
-#if defined (XFS_LOG_RES_DEBUG)
         /* reservation array fields */
 	uint		   t_res_num;                    /* num in array : 4 */
-	xlog_res_t	   t_res_arr[XLOG_TIC_LEN_MAX];  /* array of res : X */ 
 	uint		   t_res_num_ophdrs;		 /* num op hdrs  : 4 */
 	uint		   t_res_arr_sum;		 /* array sum    : 4 */
 	uint		   t_res_o_flow;		 /* sum overflow : 4 */
-#endif
+	xlog_res_t	   t_res_arr[XLOG_TIC_LEN_MAX];  /* array of res : 8 * 15 */ 
 } xlog_ticket_t;
 
 #endif
@@ -494,71 +485,13 @@
 
 #define XLOG_FORCED_SHUTDOWN(log)	((log)->l_flags & XLOG_IO_ERROR)
 
-#define XLOG_GRANT_SUB_SPACE(log,bytes,type)				\
-    {									\
-	if (type == 'w') {						\
-		(log)->l_grant_write_bytes -= (bytes);			\
-		if ((log)->l_grant_write_bytes < 0) {			\
-			(log)->l_grant_write_bytes += (log)->l_logsize;	\
-			(log)->l_grant_write_cycle--;			\
-		}							\
-	} else {							\
-		(log)->l_grant_reserve_bytes -= (bytes);		\
-		if ((log)->l_grant_reserve_bytes < 0) {			\
-			(log)->l_grant_reserve_bytes += (log)->l_logsize;\
-			(log)->l_grant_reserve_cycle--;			\
-		}							\
-	 }								\
-    }
-#define XLOG_GRANT_ADD_SPACE(log,bytes,type)				\
-    {									\
-	if (type == 'w') {						\
-		(log)->l_grant_write_bytes += (bytes);			\
-		if ((log)->l_grant_write_bytes > (log)->l_logsize) {	\
-			(log)->l_grant_write_bytes -= (log)->l_logsize;	\
-			(log)->l_grant_write_cycle++;			\
-		}							\
-	} else {							\
-		(log)->l_grant_reserve_bytes += (bytes);		\
-		if ((log)->l_grant_reserve_bytes > (log)->l_logsize) {	\
-			(log)->l_grant_reserve_bytes -= (log)->l_logsize;\
-			(log)->l_grant_reserve_cycle++;			\
-		}							\
-	 }								\
-    }
-#define XLOG_INS_TICKETQ(q, tic)			\
-    {							\
-	if (q) {					\
-		(tic)->t_next	    = (q);		\
-		(tic)->t_prev	    = (q)->t_prev;	\
-		(q)->t_prev->t_next = (tic);		\
-		(q)->t_prev	    = (tic);		\
-	} else {					\
-		(tic)->t_prev = (tic)->t_next = (tic);	\
-		(q) = (tic);				\
-	}						\
-	(tic)->t_flags |= XLOG_TIC_IN_Q;		\
-    }
-#define XLOG_DEL_TICKETQ(q, tic)			\
-    {							\
-	if ((tic) == (tic)->t_next) {			\
-		(q) = NULL;				\
-	} else {					\
-		(q) = (tic)->t_next;			\
-		(tic)->t_next->t_prev = (tic)->t_prev;	\
-		(tic)->t_prev->t_next = (tic)->t_next;	\
-	}						\
-	(tic)->t_next = (tic)->t_prev = NULL;		\
-	(tic)->t_flags &= ~XLOG_TIC_IN_Q;		\
-    }
 
 /* common routines */
 extern xfs_lsn_t xlog_assign_tail_lsn(struct xfs_mount *mp);
 extern int	 xlog_find_tail(xlog_t	*log,
 				xfs_daddr_t *head_blk,
-				xfs_daddr_t *tail_blk,
-				int readonly);
-extern int	 xlog_recover(xlog_t *log, int readonly);
+				xfs_daddr_t *tail_blk);
+extern int	 xlog_recover(xlog_t *log);
 extern int	 xlog_recover_finish(xlog_t *log, int mfsi_flags);
 extern void	 xlog_pack_data(xlog_t *log, xlog_in_core_t *iclog, int);
 extern void	 xlog_recover_process_iunlinks(xlog_t *log);
diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c
index 8ab7df7..7d46cbd 100644
--- a/fs/xfs/xfs_log_recover.c
+++ b/fs/xfs/xfs_log_recover.c
@@ -783,8 +783,7 @@
 xlog_find_tail(
 	xlog_t			*log,
 	xfs_daddr_t		*head_blk,
-	xfs_daddr_t		*tail_blk,
-	int			readonly)
+	xfs_daddr_t		*tail_blk)
 {
 	xlog_rec_header_t	*rhead;
 	xlog_op_header_t	*op_head;
@@ -2563,10 +2562,12 @@
 
 	/*
 	 * The logitem format's flag tells us if this was user quotaoff,
-	 * group quotaoff or both.
+	 * group/project quotaoff or both.
 	 */
 	if (qoff_f->qf_flags & XFS_UQUOTA_ACCT)
 		log->l_quotaoffs_flag |= XFS_DQ_USER;
+	if (qoff_f->qf_flags & XFS_PQUOTA_ACCT)
+		log->l_quotaoffs_flag |= XFS_DQ_PROJ;
 	if (qoff_f->qf_flags & XFS_GQUOTA_ACCT)
 		log->l_quotaoffs_flag |= XFS_DQ_GROUP;
 
@@ -3890,14 +3891,13 @@
  */
 int
 xlog_recover(
-	xlog_t		*log,
-	int		readonly)
+	xlog_t		*log)
 {
 	xfs_daddr_t	head_blk, tail_blk;
 	int		error;
 
 	/* find the tail of the log */
-	if ((error = xlog_find_tail(log, &head_blk, &tail_blk, readonly)))
+	if ((error = xlog_find_tail(log, &head_blk, &tail_blk)))
 		return error;
 
 	if (tail_blk != head_blk) {
diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
index 303af86..6088e14 100644
--- a/fs/xfs/xfs_mount.c
+++ b/fs/xfs/xfs_mount.c
@@ -51,7 +51,7 @@
 STATIC void	xfs_uuid_unmount(xfs_mount_t *mp);
 STATIC void	xfs_unmountfs_wait(xfs_mount_t *);
 
-static struct {
+static const struct {
     short offset;
     short type;     /* 0 = integer
 		* 1 = binary / string (no translation)
@@ -1077,8 +1077,7 @@
 
 	xfs_iflush_all(mp);
 
-	XFS_QM_DQPURGEALL(mp,
-		XFS_QMOPT_UQUOTA | XFS_QMOPT_GQUOTA | XFS_QMOPT_UMOUNTING);
+	XFS_QM_DQPURGEALL(mp, XFS_QMOPT_QUOTALL | XFS_QMOPT_UMOUNTING);
 
 	/*
 	 * Flush out the log synchronously so that we know for sure
diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h
index 3432fd5..cd3cf96 100644
--- a/fs/xfs/xfs_mount.h
+++ b/fs/xfs/xfs_mount.h
@@ -308,7 +308,6 @@
 	xfs_buftarg_t		*m_ddev_targp;	/* saves taking the address */
 	xfs_buftarg_t		*m_logdev_targp;/* ptr to log device */
 	xfs_buftarg_t		*m_rtdev_targp;	/* ptr to rt device */
-#define m_dev		m_ddev_targp->pbr_dev
 	__uint8_t		m_dircook_elog;	/* log d-cookie entry bits */
 	__uint8_t		m_blkbit_log;	/* blocklog + NBBY */
 	__uint8_t		m_blkbb_log;	/* blocklog - BBSHIFT */
@@ -393,7 +392,7 @@
 						   user */
 #define XFS_MOUNT_NOALIGN	(1ULL << 7)	/* turn off stripe alignment
 						   allocations */
-#define XFS_MOUNT_COMPAT_ATTR	(1ULL << 8)	/* do not use attr2 format */
+#define XFS_MOUNT_ATTR2		(1ULL << 8)	/* allow use of attr2 format */
 			     /*	(1ULL << 9)	-- currently unused */
 #define XFS_MOUNT_NORECOVERY	(1ULL << 10)	/* no recovery - dirty fs */
 #define XFS_MOUNT_SHARED	(1ULL << 11)	/* shared mount */
diff --git a/fs/xfs/xfs_rename.c b/fs/xfs/xfs_rename.c
index 4d4e8f4..81a05cf 100644
--- a/fs/xfs/xfs_rename.c
+++ b/fs/xfs/xfs_rename.c
@@ -243,7 +243,6 @@
 	xfs_inode_t	*inodes[4];
 	int		target_ip_dropped = 0;	/* dropped target_ip link? */
 	vnode_t		*src_dir_vp;
-	bhv_desc_t	*target_dir_bdp;
 	int		spaceres;
 	int		target_link_zero = 0;
 	int		num_inodes;
@@ -260,14 +259,12 @@
 	 * Find the XFS behavior descriptor for the target directory
 	 * vnode since it was not handed to us.
 	 */
-	target_dir_bdp = vn_bhv_lookup_unlocked(VN_BHV_HEAD(target_dir_vp),
-						&xfs_vnodeops);
-	if (target_dir_bdp == NULL) {
+	target_dp = xfs_vtoi(target_dir_vp);
+	if (target_dp == NULL) {
 		return XFS_ERROR(EXDEV);
 	}
 
 	src_dp = XFS_BHVTOI(src_dir_bdp);
-	target_dp = XFS_BHVTOI(target_dir_bdp);
 	mp = src_dp->i_mount;
 
 	if (DM_EVENT_ENABLED(src_dir_vp->v_vfsp, src_dp, DM_EVENT_RENAME) ||
diff --git a/fs/xfs/xfs_rw.c b/fs/xfs/xfs_rw.c
index c4b2087..a59c102 100644
--- a/fs/xfs/xfs_rw.c
+++ b/fs/xfs/xfs_rw.c
@@ -238,6 +238,7 @@
 	}
 	return (EIO);
 }
+
 /*
  * Prints out an ALERT message about I/O error.
  */
@@ -252,11 +253,9 @@
  "I/O error in filesystem (\"%s\") meta-data dev %s block 0x%llx"
  "       (\"%s\") error %d buf count %zd",
 		(!mp || !mp->m_fsname) ? "(fs name not set)" : mp->m_fsname,
-		XFS_BUFTARG_NAME(bp->pb_target),
-		(__uint64_t)blkno,
-		func,
-		XFS_BUF_GETERROR(bp),
-		XFS_BUF_COUNT(bp));
+		XFS_BUFTARG_NAME(XFS_BUF_TARGET(bp)),
+		(__uint64_t)blkno, func,
+		XFS_BUF_GETERROR(bp), XFS_BUF_COUNT(bp));
 }
 
 /*
diff --git a/fs/xfs/xfs_sb.h b/fs/xfs/xfs_sb.h
index 4a17d33..bf168a9 100644
--- a/fs/xfs/xfs_sb.h
+++ b/fs/xfs/xfs_sb.h
@@ -68,18 +68,6 @@
 	(XFS_SB_VERSION_NUMBITS | \
 	 XFS_SB_VERSION_OKREALFBITS | \
 	 XFS_SB_VERSION_OKSASHFBITS)
-#define XFS_SB_VERSION_MKFS(ia,dia,extflag,dirv2,na,sflag,morebits)	\
-	(((ia) || (dia) || (extflag) || (dirv2) || (na) || (sflag) || \
-	  (morebits)) ? \
-		(XFS_SB_VERSION_4 | \
-		 ((ia) ? XFS_SB_VERSION_ALIGNBIT : 0) | \
-		 ((dia) ? XFS_SB_VERSION_DALIGNBIT : 0) | \
-		 ((extflag) ? XFS_SB_VERSION_EXTFLGBIT : 0) | \
-		 ((dirv2) ? XFS_SB_VERSION_DIRV2BIT : 0) | \
-		 ((na) ? XFS_SB_VERSION_LOGV2BIT : 0) | \
-		 ((sflag) ? XFS_SB_VERSION_SECTORBIT : 0) | \
-		 ((morebits) ? XFS_SB_VERSION_MOREBITSBIT : 0)) : \
-		XFS_SB_VERSION_1)
 
 /*
  * There are two words to hold XFS "feature" bits: the original
@@ -105,11 +93,6 @@
 	(XFS_SB_VERSION2_OKREALFBITS |	\
 	 XFS_SB_VERSION2_OKSASHFBITS )
 
-/*
- * mkfs macro to set up sb_features2 word
- */
-#define	XFS_SB_VERSION2_MKFS(resvd1, sbcntr)	0
-
 typedef struct xfs_sb
 {
 	__uint32_t	sb_magicnum;	/* magic number == XFS_SB_MAGIC */
diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c
index 279e043..d3d714e 100644
--- a/fs/xfs/xfs_trans.c
+++ b/fs/xfs/xfs_trans.c
@@ -1014,6 +1014,7 @@
 	xfs_log_item_t		*lip;
 	int			i;
 #endif
+	xfs_mount_t		*mp = tp->t_mountp;
 
 	/*
 	 * See if the caller is being too lazy to figure out if
@@ -1026,9 +1027,10 @@
 	 * filesystem.  This happens in paths where we detect
 	 * corruption and decide to give up.
 	 */
-	if ((tp->t_flags & XFS_TRANS_DIRTY) &&
-	    !XFS_FORCED_SHUTDOWN(tp->t_mountp))
-		xfs_force_shutdown(tp->t_mountp, XFS_CORRUPT_INCORE);
+	if ((tp->t_flags & XFS_TRANS_DIRTY) && !XFS_FORCED_SHUTDOWN(mp)) {
+		XFS_ERROR_REPORT("xfs_trans_cancel", XFS_ERRLEVEL_LOW, mp);
+		xfs_force_shutdown(mp, XFS_CORRUPT_INCORE);
+	}
 #ifdef DEBUG
 	if (!(flags & XFS_TRANS_ABORT)) {
 		licp = &(tp->t_items);
@@ -1040,7 +1042,7 @@
 				}
 
 				lip = lidp->lid_item;
-				if (!XFS_FORCED_SHUTDOWN(tp->t_mountp))
+				if (!XFS_FORCED_SHUTDOWN(mp))
 					ASSERT(!(lip->li_type == XFS_LI_EFD));
 			}
 			licp = licp->lic_next;
@@ -1048,7 +1050,7 @@
 	}
 #endif
 	xfs_trans_unreserve_and_mod_sb(tp);
-	XFS_TRANS_UNRESERVE_AND_MOD_DQUOTS(tp->t_mountp, tp);
+	XFS_TRANS_UNRESERVE_AND_MOD_DQUOTS(mp, tp);
 
 	if (tp->t_ticket) {
 		if (flags & XFS_TRANS_RELEASE_LOG_RES) {
@@ -1057,7 +1059,7 @@
 		} else {
 			log_flags = 0;
 		}
-		xfs_log_done(tp->t_mountp, tp->t_ticket, NULL, log_flags);
+		xfs_log_done(mp, tp->t_ticket, NULL, log_flags);
 	}
 
 	/* mark this thread as no longer being in a transaction */
diff --git a/fs/xfs/xfs_trans.h b/fs/xfs/xfs_trans.h
index a889963f..d77901c 100644
--- a/fs/xfs/xfs_trans.h
+++ b/fs/xfs/xfs_trans.h
@@ -973,7 +973,6 @@
 void		xfs_trans_bhold_release(xfs_trans_t *, struct xfs_buf *);
 void		xfs_trans_binval(xfs_trans_t *, struct xfs_buf *);
 void		xfs_trans_inode_buf(xfs_trans_t *, struct xfs_buf *);
-void		xfs_trans_inode_buf(xfs_trans_t *, struct xfs_buf *);
 void		xfs_trans_stale_inode_buf(xfs_trans_t *, struct xfs_buf *);
 void		xfs_trans_dquot_buf(xfs_trans_t *, struct xfs_buf *, uint);
 void		xfs_trans_inode_alloc_buf(xfs_trans_t *, struct xfs_buf *);
diff --git a/fs/xfs/xfs_utils.c b/fs/xfs/xfs_utils.c
index fefe1d6..34654ec 100644
--- a/fs/xfs/xfs_utils.c
+++ b/fs/xfs/xfs_utils.c
@@ -55,16 +55,13 @@
 	xfs_inode_t	**ipp)
 {
 	vnode_t		*vp;
-	bhv_desc_t	*bdp;
 
 	vp = VNAME_TO_VNODE(dentry);
-	bdp = vn_bhv_lookup_unlocked(VN_BHV_HEAD(vp), &xfs_vnodeops);
-	if (!bdp) {
-		*ipp = NULL;
+
+	*ipp = xfs_vtoi(vp);
+	if (!*ipp)
 		return XFS_ERROR(ENOENT);
-	}
 	VN_HOLD(vp);
-	*ipp = XFS_BHVTOI(bdp);
 	return 0;
 }
 
diff --git a/fs/xfs/xfs_vfsops.c b/fs/xfs/xfs_vfsops.c
index 7bdbd99..b6ad370 100644
--- a/fs/xfs/xfs_vfsops.c
+++ b/fs/xfs/xfs_vfsops.c
@@ -53,6 +53,7 @@
 #include "xfs_acl.h"
 #include "xfs_attr.h"
 #include "xfs_clnt.h"
+#include "xfs_fsops.h"
 
 STATIC int xfs_sync(bhv_desc_t *, int, cred_t *);
 
@@ -290,8 +291,8 @@
 		mp->m_flags |= XFS_MOUNT_IDELETE;
 	if (ap->flags & XFSMNT_DIRSYNC)
 		mp->m_flags |= XFS_MOUNT_DIRSYNC;
-	if (ap->flags & XFSMNT_COMPAT_ATTR)
-		mp->m_flags |= XFS_MOUNT_COMPAT_ATTR;
+	if (ap->flags & XFSMNT_ATTR2)
+		mp->m_flags |= XFS_MOUNT_ATTR2;
 
 	if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
 		mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
@@ -312,6 +313,8 @@
 		mp->m_flags |= XFS_MOUNT_NOUUID;
 	if (ap->flags & XFSMNT_BARRIER)
 		mp->m_flags |= XFS_MOUNT_BARRIER;
+	else
+		mp->m_flags &= ~XFS_MOUNT_BARRIER;
 
 	return 0;
 }
@@ -330,10 +333,11 @@
 
 	/* Fail a mount where the logbuf is smaller then the log stripe */
 	if (XFS_SB_VERSION_HASLOGV2(&mp->m_sb)) {
-		if ((ap->logbufsize == -1) &&
+		if ((ap->logbufsize <= 0) &&
 		    (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
 			mp->m_logbsize = mp->m_sb.sb_logsunit;
-		} else if (ap->logbufsize < mp->m_sb.sb_logsunit) {
+		} else if (ap->logbufsize > 0 &&
+			   ap->logbufsize < mp->m_sb.sb_logsunit) {
 			cmn_err(CE_WARN,
 	"XFS: logbuf size must be greater than or equal to log stripe size");
 			return XFS_ERROR(EINVAL);
@@ -347,6 +351,10 @@
 		}
 	}
 
+	if (XFS_SB_VERSION_HASATTR2(&mp->m_sb)) {
+		mp->m_flags |= XFS_MOUNT_ATTR2;
+	}
+
 	/*
 	 * prohibit r/w mounts of read-only filesystems
 	 */
@@ -382,10 +390,6 @@
 			return XFS_ERROR(EINVAL);
 	}
 
-	if (XFS_SB_VERSION_HASATTR2(&mp->m_sb)) {
-		mp->m_flags &= ~XFS_MOUNT_COMPAT_ATTR;
-	}
-
 	return 0;
 }
 
@@ -504,13 +508,13 @@
 	if (error)
 		goto error2;
 
+	if ((mp->m_flags & XFS_MOUNT_BARRIER) && !(vfsp->vfs_flag & VFS_RDONLY))
+		xfs_mountfs_check_barriers(mp);
+
 	error = XFS_IOINIT(vfsp, args, flags);
 	if (error)
 		goto error2;
 
-	if ((args->flags & XFSMNT_BARRIER) &&
-	    !(XFS_MTOVFS(mp)->vfs_flag & VFS_RDONLY))
-		xfs_mountfs_check_barriers(mp);
 	return 0;
 
 error2:
@@ -655,6 +659,11 @@
 	else
 		mp->m_flags &= ~XFS_MOUNT_NOATIME;
 
+	if (args->flags & XFSMNT_BARRIER)
+		mp->m_flags |= XFS_MOUNT_BARRIER;
+	else
+		mp->m_flags &= ~XFS_MOUNT_BARRIER;
+
 	if ((vfsp->vfs_flag & VFS_RDONLY) &&
 	    !(*flags & MS_RDONLY)) {
 		vfsp->vfs_flag &= ~VFS_RDONLY;
@@ -1634,6 +1643,7 @@
 #define MNTOPT_NORECOVERY   "norecovery"   /* don't run XFS recovery */
 #define MNTOPT_BARRIER	"barrier"	/* use writer barriers for log write and
 					 * unwritten extent conversion */
+#define MNTOPT_NOBARRIER "nobarrier"	/* .. disable */
 #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
 #define MNTOPT_64BITINODE   "inode64"	/* inodes can be allocated anywhere */
 #define MNTOPT_IKEEP	"ikeep"		/* do not free empty inode clusters */
@@ -1680,7 +1690,6 @@
 	int			iosize;
 
 	args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
-	args->flags |= XFSMNT_COMPAT_ATTR;
 
 #if 0	/* XXX: off by default, until some remaining issues ironed out */
 	args->flags |= XFSMNT_IDELETE; /* default to on */
@@ -1806,6 +1815,8 @@
 			args->flags |= XFSMNT_NOUUID;
 		} else if (!strcmp(this_char, MNTOPT_BARRIER)) {
 			args->flags |= XFSMNT_BARRIER;
+		} else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
+			args->flags &= ~XFSMNT_BARRIER;
 		} else if (!strcmp(this_char, MNTOPT_IKEEP)) {
 			args->flags &= ~XFSMNT_IDELETE;
 		} else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
@@ -1815,9 +1826,9 @@
 		} else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
 			args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
 		} else if (!strcmp(this_char, MNTOPT_ATTR2)) {
-			args->flags &= ~XFSMNT_COMPAT_ATTR;
+			args->flags |= XFSMNT_ATTR2;
 		} else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
-			args->flags |= XFSMNT_COMPAT_ATTR;
+			args->flags &= ~XFSMNT_ATTR2;
 		} else if (!strcmp(this_char, "osyncisdsync")) {
 			/* no-op, this is now the default */
 printk("XFS: osyncisdsync is now the default, option is deprecated.\n");
@@ -1892,7 +1903,6 @@
 		{ XFS_MOUNT_NOUUID,		"," MNTOPT_NOUUID },
 		{ XFS_MOUNT_NORECOVERY,		"," MNTOPT_NORECOVERY },
 		{ XFS_MOUNT_OSYNCISOSYNC,	"," MNTOPT_OSYNCISOSYNC },
-		{ XFS_MOUNT_BARRIER,		"," MNTOPT_BARRIER },
 		{ XFS_MOUNT_IDELETE,		"," MNTOPT_NOIKEEP },
 		{ 0, NULL }
 	};
@@ -1914,33 +1924,28 @@
 
 	if (mp->m_logbufs > 0)
 		seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
-
 	if (mp->m_logbsize > 0)
 		seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
 
 	if (mp->m_logname)
 		seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
-
 	if (mp->m_rtname)
 		seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
 
 	if (mp->m_dalign > 0)
 		seq_printf(m, "," MNTOPT_SUNIT "=%d",
 				(int)XFS_FSB_TO_BB(mp, mp->m_dalign));
-
 	if (mp->m_swidth > 0)
 		seq_printf(m, "," MNTOPT_SWIDTH "=%d",
 				(int)XFS_FSB_TO_BB(mp, mp->m_swidth));
 
-	if (!(mp->m_flags & XFS_MOUNT_COMPAT_ATTR))
-		seq_printf(m, "," MNTOPT_ATTR2);
-
 	if (!(mp->m_flags & XFS_MOUNT_COMPAT_IOSIZE))
 		seq_printf(m, "," MNTOPT_LARGEIO);
+	if (mp->m_flags & XFS_MOUNT_BARRIER)
+		seq_printf(m, "," MNTOPT_BARRIER);
 
 	if (!(vfsp->vfs_flag & VFS_32BITINODES))
 		seq_printf(m, "," MNTOPT_64BITINODE);
-
 	if (vfsp->vfs_flag & VFS_GRPID)
 		seq_printf(m, "," MNTOPT_GRPID);
 
@@ -1959,6 +1964,7 @@
 	/* Push the superblock and write an unmount record */
 	xfs_log_unmount_write(mp);
 	xfs_unmountfs_writesb(mp);
+	xfs_fs_log_dummy(mp);
 }
 
 
diff --git a/fs/xfs/xfs_vnodeops.c b/fs/xfs/xfs_vnodeops.c
index e03fa2a..8076cc9 100644
--- a/fs/xfs/xfs_vnodeops.c
+++ b/fs/xfs/xfs_vnodeops.c
@@ -15,6 +15,9 @@
  * along with this program; if not, write the Free Software Foundation,
  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
+
+#include <linux/capability.h>
+
 #include "xfs.h"
 #include "xfs_fs.h"
 #include "xfs_types.h"
@@ -182,8 +185,7 @@
 		break;
 	}
 
-	vap->va_atime.tv_sec = ip->i_d.di_atime.t_sec;
-	vap->va_atime.tv_nsec = ip->i_d.di_atime.t_nsec;
+	vn_atime_to_timespec(vp, &vap->va_atime);
 	vap->va_mtime.tv_sec = ip->i_d.di_mtime.t_sec;
 	vap->va_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
 	vap->va_ctime.tv_sec = ip->i_d.di_ctime.t_sec;
@@ -541,24 +543,6 @@
 		}
 
 		/*
-		 * Can't set extent size unless the file is marked, or
-		 * about to be marked as a realtime file.
-		 *
-		 * This check will be removed when fixed size extents
-		 * with buffered data writes is implemented.
-		 *
-		 */
-		if ((mask & XFS_AT_EXTSIZE)			&&
-		    ((ip->i_d.di_extsize << mp->m_sb.sb_blocklog) !=
-		     vap->va_extsize) &&
-		    (!((ip->i_d.di_flags & XFS_DIFLAG_REALTIME) ||
-		       ((mask & XFS_AT_XFLAGS) &&
-			(vap->va_xflags & XFS_XFLAG_REALTIME))))) {
-			code = XFS_ERROR(EINVAL);
-			goto error_return;
-		}
-
-		/*
 		 * Can't change realtime flag if any extents are allocated.
 		 */
 		if ((ip->i_d.di_nextents || ip->i_delayed_blks) &&
@@ -820,13 +804,17 @@
 					di_flags |= XFS_DIFLAG_RTINHERIT;
 				if (vap->va_xflags & XFS_XFLAG_NOSYMLINKS)
 					di_flags |= XFS_DIFLAG_NOSYMLINKS;
-			} else {
+				if (vap->va_xflags & XFS_XFLAG_EXTSZINHERIT)
+					di_flags |= XFS_DIFLAG_EXTSZINHERIT;
+			} else if ((ip->i_d.di_mode & S_IFMT) == S_IFREG) {
 				if (vap->va_xflags & XFS_XFLAG_REALTIME) {
 					di_flags |= XFS_DIFLAG_REALTIME;
 					ip->i_iocore.io_flags |= XFS_IOCORE_RT;
 				} else {
 					ip->i_iocore.io_flags &= ~XFS_IOCORE_RT;
 				}
+				if (vap->va_xflags & XFS_XFLAG_EXTSIZE)
+					di_flags |= XFS_DIFLAG_EXTSIZE;
 			}
 			ip->i_d.di_flags = di_flags;
 		}
@@ -996,10 +984,6 @@
 		goto error_return;
 	}
 
-	if (!(ioflags & IO_INVIS)) {
-		xfs_ichgtime(ip, XFS_ICHGTIME_ACC);
-	}
-
 	/*
 	 * See if the symlink is stored inline.
 	 */
@@ -1231,7 +1215,8 @@
 	xfs_iunlock(ip, XFS_ILOCK_SHARED);
 
 	if (!error && (nimaps != 0) &&
-	    (imap.br_startblock != HOLESTARTBLOCK)) {
+	    (imap.br_startblock != HOLESTARTBLOCK ||
+	     ip->i_delayed_blks)) {
 		/*
 		 * Attach the dquots to the inode up front.
 		 */
@@ -1566,9 +1551,11 @@
 
 	if (ip->i_d.di_nlink != 0) {
 		if ((((ip->i_d.di_mode & S_IFMT) == S_IFREG) &&
-		     ((ip->i_d.di_size > 0) || (VN_CACHED(vp) > 0)) &&
+		     ((ip->i_d.di_size > 0) || (VN_CACHED(vp) > 0 ||
+		       ip->i_delayed_blks > 0)) &&
 		     (ip->i_df.if_flags & XFS_IFEXTENTS))  &&
-		    (!(ip->i_d.di_flags & (XFS_DIFLAG_PREALLOC|XFS_DIFLAG_APPEND)))) {
+		    (!(ip->i_d.di_flags &
+				(XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)))) {
 			if ((error = xfs_inactive_free_eofblocks(mp, ip)))
 				return (error);
 			/* Update linux inode block count after free above */
@@ -1625,7 +1612,8 @@
 	 * only one with a reference to the inode.
 	 */
 	truncate = ((ip->i_d.di_nlink == 0) &&
-	    ((ip->i_d.di_size != 0) || (ip->i_d.di_nextents > 0)) &&
+            ((ip->i_d.di_size != 0) || (ip->i_d.di_nextents > 0) ||
+             (ip->i_delayed_blks > 0)) &&
 	    ((ip->i_d.di_mode & S_IFMT) == S_IFREG));
 
 	mp = ip->i_mount;
@@ -1643,10 +1631,12 @@
 
 	if (ip->i_d.di_nlink != 0) {
 		if ((((ip->i_d.di_mode & S_IFMT) == S_IFREG) &&
-		     ((ip->i_d.di_size > 0) || (VN_CACHED(vp) > 0)) &&
-		     (ip->i_df.if_flags & XFS_IFEXTENTS))  &&
-		    (!(ip->i_d.di_flags & (XFS_DIFLAG_PREALLOC|XFS_DIFLAG_APPEND)) ||
-		     (ip->i_delayed_blks != 0))) {
+                     ((ip->i_d.di_size > 0) || (VN_CACHED(vp) > 0 ||
+                       ip->i_delayed_blks > 0)) &&
+		      (ip->i_df.if_flags & XFS_IFEXTENTS) &&
+		     (!(ip->i_d.di_flags &
+				(XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)) ||
+		      (ip->i_delayed_blks != 0)))) {
 			if ((error = xfs_inactive_free_eofblocks(mp, ip)))
 				return (VN_INACTIVE_CACHE);
 			/* Update linux inode block count after free above */
@@ -2590,7 +2580,6 @@
 	int			cancel_flags;
 	int			committed;
 	vnode_t			*target_dir_vp;
-	bhv_desc_t		*src_bdp;
 	int			resblks;
 	char			*target_name = VNAME(dentry);
 	int			target_namelen;
@@ -2603,8 +2592,7 @@
 	if (VN_ISDIR(src_vp))
 		return XFS_ERROR(EPERM);
 
-	src_bdp = vn_bhv_lookup_unlocked(VN_BHV_HEAD(src_vp), &xfs_vnodeops);
-	sip = XFS_BHVTOI(src_bdp);
+	sip = xfs_vtoi(src_vp);
 	tdp = XFS_BHVTOI(target_dir_bdp);
 	mp = tdp->i_mount;
 	if (XFS_FORCED_SHUTDOWN(mp))
@@ -3237,7 +3225,6 @@
 	xfs_trans_t	*tp = NULL;
 	int		error = 0;
 	uint		lock_mode;
-	xfs_off_t	start_offset;
 
 	vn_trace_entry(BHV_TO_VNODE(dir_bdp), __FUNCTION__,
 					       (inst_t *)__return_address);
@@ -3248,11 +3235,7 @@
 	}
 
 	lock_mode = xfs_ilock_map_shared(dp);
-	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;
 }
@@ -3829,7 +3812,12 @@
 	vn_iowait(vp);
 
 	ASSERT(XFS_FORCED_SHUTDOWN(ip->i_mount) || ip->i_delayed_blks == 0);
-	ASSERT(VN_CACHED(vp) == 0);
+
+	/*
+	 * Make sure the atime in the XFS inode is correct before freeing the
+	 * Linux inode.
+	 */
+	xfs_synchronize_atime(ip);
 
 	/* If we have nothing to flush with this inode then complete the
 	 * teardown now, otherwise break the link between the xfs inode
@@ -3999,42 +3987,36 @@
 	int			alloc_type,
 	int			attr_flags)
 {
+	xfs_mount_t		*mp = ip->i_mount;
+	xfs_off_t		count;
 	xfs_filblks_t		allocated_fsb;
 	xfs_filblks_t		allocatesize_fsb;
-	int			committed;
-	xfs_off_t		count;
-	xfs_filblks_t		datablocks;
-	int			error;
-	xfs_fsblock_t		firstfsb;
-	xfs_bmap_free_t		free_list;
-	xfs_bmbt_irec_t		*imapp;
-	xfs_bmbt_irec_t		imaps[1];
-	xfs_mount_t		*mp;
-	int			numrtextents;
-	int			reccount;
-	uint			resblks;
-	int			rt;
-	int			rtextsize;
+	xfs_extlen_t		extsz, temp;
 	xfs_fileoff_t		startoffset_fsb;
+	xfs_fsblock_t		firstfsb;
+	int			nimaps;
+	int			bmapi_flag;
+	int			quota_flag;
+	int			rt;
 	xfs_trans_t		*tp;
-	int			xfs_bmapi_flags;
+	xfs_bmbt_irec_t		imaps[1], *imapp;
+	xfs_bmap_free_t		free_list;
+	uint			qblocks, resblks, resrtextents;
+	int			committed;
+	int			error;
 
 	vn_trace_entry(XFS_ITOV(ip), __FUNCTION__, (inst_t *)__return_address);
-	mp = ip->i_mount;
 
 	if (XFS_FORCED_SHUTDOWN(mp))
 		return XFS_ERROR(EIO);
 
-	/*
-	 * determine if this is a realtime file
-	 */
-	if ((rt = XFS_IS_REALTIME_INODE(ip)) != 0) {
-		if (ip->i_d.di_extsize)
-			rtextsize = ip->i_d.di_extsize;
-		else
-			rtextsize = mp->m_sb.sb_rextsize;
-	} else
-		rtextsize = 0;
+	rt = XFS_IS_REALTIME_INODE(ip);
+	if (unlikely(rt)) {
+		if (!(extsz = ip->i_d.di_extsize))
+			extsz = mp->m_sb.sb_rextsize;
+	} else {
+		extsz = ip->i_d.di_extsize;
+	}
 
 	if ((error = XFS_QM_DQATTACH(mp, ip, 0)))
 		return error;
@@ -4045,8 +4027,8 @@
 	count = len;
 	error = 0;
 	imapp = &imaps[0];
-	reccount = 1;
-	xfs_bmapi_flags = XFS_BMAPI_WRITE | (alloc_type ? XFS_BMAPI_PREALLOC : 0);
+	nimaps = 1;
+	bmapi_flag = XFS_BMAPI_WRITE | (alloc_type ? XFS_BMAPI_PREALLOC : 0);
 	startoffset_fsb	= XFS_B_TO_FSBT(mp, offset);
 	allocatesize_fsb = XFS_B_TO_FSB(mp, count);
 
@@ -4067,43 +4049,51 @@
 	}
 
 	/*
-	 * allocate file space until done or until there is an error
+	 * Allocate file space until done or until there is an error
 	 */
 retry:
 	while (allocatesize_fsb && !error) {
-		/*
-		 * determine if reserving space on
-		 * the data or realtime partition.
-		 */
-		if (rt) {
-			xfs_fileoff_t s, e;
+		xfs_fileoff_t	s, e;
 
+		/*
+		 * Determine space reservations for data/realtime.
+		 */
+		if (unlikely(extsz)) {
 			s = startoffset_fsb;
-			do_div(s, rtextsize);
-			s *= rtextsize;
-			e = roundup_64(startoffset_fsb + allocatesize_fsb,
-				rtextsize);
-			numrtextents = (int)(e - s) / mp->m_sb.sb_rextsize;
-			datablocks = 0;
+			do_div(s, extsz);
+			s *= extsz;
+			e = startoffset_fsb + allocatesize_fsb;
+			if ((temp = do_mod(startoffset_fsb, extsz)))
+				e += temp;
+			if ((temp = do_mod(e, extsz)))
+				e += extsz - temp;
 		} else {
-			datablocks = allocatesize_fsb;
-			numrtextents = 0;
+			s = 0;
+			e = allocatesize_fsb;
+		}
+
+		if (unlikely(rt)) {
+			resrtextents = qblocks = (uint)(e - s);
+			resrtextents /= mp->m_sb.sb_rextsize;
+			resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0);
+			quota_flag = XFS_QMOPT_RES_RTBLKS;
+		} else {
+			resrtextents = 0;
+			resblks = qblocks = \
+				XFS_DIOSTRAT_SPACE_RES(mp, (uint)(e - s));
+			quota_flag = XFS_QMOPT_RES_REGBLKS;
 		}
 
 		/*
-		 * allocate and setup the transaction
+		 * Allocate and setup the transaction.
 		 */
 		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,
+		error = xfs_trans_reserve(tp, resblks,
+					  XFS_WRITE_LOG_RES(mp), resrtextents,
 					  XFS_TRANS_PERM_LOG_RES,
 					  XFS_WRITE_LOG_COUNT);
-
 		/*
-		 * check for running out of space
+		 * Check for running out of space
 		 */
 		if (error) {
 			/*
@@ -4114,8 +4104,8 @@
 			break;
 		}
 		xfs_ilock(ip, XFS_ILOCK_EXCL);
-		error = XFS_TRANS_RESERVE_QUOTA(mp, tp,
-				ip->i_udquot, ip->i_gdquot, resblks, 0, 0);
+		error = XFS_TRANS_RESERVE_QUOTA_NBLKS(mp, tp, ip,
+						      qblocks, 0, quota_flag);
 		if (error)
 			goto error1;
 
@@ -4123,19 +4113,19 @@
 		xfs_trans_ihold(tp, ip);
 
 		/*
-		 * issue the bmapi() call to allocate the blocks
+		 * Issue the xfs_bmapi() call to allocate the blocks
 		 */
 		XFS_BMAP_INIT(&free_list, &firstfsb);
 		error = xfs_bmapi(tp, ip, startoffset_fsb,
-				  allocatesize_fsb, xfs_bmapi_flags,
-				  &firstfsb, 0, imapp, &reccount,
+				  allocatesize_fsb, bmapi_flag,
+				  &firstfsb, 0, imapp, &nimaps,
 				  &free_list);
 		if (error) {
 			goto error0;
 		}
 
 		/*
-		 * complete the transaction
+		 * Complete the transaction
 		 */
 		error = xfs_bmap_finish(&tp, &free_list, firstfsb, &committed);
 		if (error) {
@@ -4150,7 +4140,7 @@
 
 		allocated_fsb = imapp->br_blockcount;
 
-		if (reccount == 0) {
+		if (nimaps == 0) {
 			error = XFS_ERROR(ENOSPC);
 			break;
 		}
@@ -4173,9 +4163,11 @@
 
 	return error;
 
- error0:
+error0:	/* Cancel bmap, unlock inode, unreserve quota blocks, cancel trans */
 	xfs_bmap_cancel(&free_list);
- error1:
+	XFS_TRANS_UNRESERVE_QUOTA_NBLKS(mp, tp, ip, qblocks, 0, quota_flag);
+
+error1:	/* Just cancel transaction */
 	xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES | XFS_TRANS_ABORT);
 	xfs_iunlock(ip, XFS_ILOCK_EXCL);
 	goto dmapi_enospc_check;
@@ -4420,8 +4412,8 @@
 		}
 		xfs_ilock(ip, XFS_ILOCK_EXCL);
 		error = XFS_TRANS_RESERVE_QUOTA(mp, tp,
-				ip->i_udquot, ip->i_gdquot, resblks, 0, rt ?
-				XFS_QMOPT_RES_RTBLKS : XFS_QMOPT_RES_REGBLKS);
+				ip->i_udquot, ip->i_gdquot, resblks, 0,
+				XFS_QMOPT_RES_REGBLKS);
 		if (error)
 			goto error1;
 
diff --git a/include/asm-alpha/mmu_context.h b/include/asm-alpha/mmu_context.h
index a714d0c..6f92482 100644
--- a/include/asm-alpha/mmu_context.h
+++ b/include/asm-alpha/mmu_context.h
@@ -156,7 +156,7 @@
 	/* Always update the PCB ASN.  Another thread may have allocated
 	   a new mm->context (via flush_tlb_mm) without the ASN serial
 	   number wrapping.  We have no way to detect when this is needed.  */
-	next->thread_info->pcb.asn = mmc & HARDWARE_ASN_MASK;
+	task_thread_info(next)->pcb.asn = mmc & HARDWARE_ASN_MASK;
 }
 
 __EXTERN_INLINE void
@@ -235,7 +235,7 @@
 		if (cpu_online(i))
 			mm->context[i] = 0;
 	if (tsk != current)
-		tsk->thread_info->pcb.ptbr
+		task_thread_info(tsk)->pcb.ptbr
 		  = ((unsigned long)mm->pgd - IDENT_ADDR) >> PAGE_SHIFT;
 	return 0;
 }
@@ -249,7 +249,7 @@
 static inline void
 enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
 {
-	tsk->thread_info->pcb.ptbr
+	task_thread_info(tsk)->pcb.ptbr
 	  = ((unsigned long)mm->pgd - IDENT_ADDR) >> PAGE_SHIFT;
 }
 
diff --git a/include/asm-alpha/processor.h b/include/asm-alpha/processor.h
index bb1a7a3..425b7b6 100644
--- a/include/asm-alpha/processor.h
+++ b/include/asm-alpha/processor.h
@@ -52,19 +52,10 @@
 
 unsigned long get_wchan(struct task_struct *p);
 
-/* See arch/alpha/kernel/ptrace.c for details.  */
-#define PT_REG(reg) \
-  (PAGE_SIZE*2 - sizeof(struct pt_regs) + offsetof(struct pt_regs, reg))
-
-#define SW_REG(reg) \
- (PAGE_SIZE*2 - sizeof(struct pt_regs) - sizeof(struct switch_stack) \
-  + offsetof(struct switch_stack, reg))
-
-#define KSTK_EIP(tsk) \
-  (*(unsigned long *)(PT_REG(pc) + (unsigned long) ((tsk)->thread_info)))
+#define KSTK_EIP(tsk) (task_pt_regs(tsk)->pc)
 
 #define KSTK_ESP(tsk) \
-  ((tsk) == current ? rdusp() : (tsk)->thread_info->pcb.usp)
+  ((tsk) == current ? rdusp() : task_thread_info(tsk)->pcb.usp)
 
 #define cpu_relax()	barrier()
 
diff --git a/include/asm-alpha/ptrace.h b/include/asm-alpha/ptrace.h
index 072375c..9933b8b 100644
--- a/include/asm-alpha/ptrace.h
+++ b/include/asm-alpha/ptrace.h
@@ -75,10 +75,10 @@
 #define profile_pc(regs) instruction_pointer(regs)
 extern void show_regs(struct pt_regs *);
 
-#define alpha_task_regs(task) \
-  ((struct pt_regs *) ((long) (task)->thread_info + 2*PAGE_SIZE) - 1)
+#define task_pt_regs(task) \
+  ((struct pt_regs *) (task_stack_page(task) + 2*PAGE_SIZE) - 1)
 
-#define force_successful_syscall_return() (alpha_task_regs(current)->r0 = 0)
+#define force_successful_syscall_return() (task_pt_regs(current)->r0 = 0)
 
 #endif
 
diff --git a/include/asm-alpha/system.h b/include/asm-alpha/system.h
index 050e86d..cc9c7e8 100644
--- a/include/asm-alpha/system.h
+++ b/include/asm-alpha/system.h
@@ -131,15 +131,25 @@
 extern void halt(void) __attribute__((noreturn));
 #define __halt() __asm__ __volatile__ ("call_pal %0 #halt" : : "i" (PAL_halt))
 
-#define switch_to(P,N,L)						\
-  do {									\
-    (L) = alpha_switch_to(virt_to_phys(&(N)->thread_info->pcb), (P));	\
-    check_mmu_context();						\
+#define switch_to(P,N,L)						 \
+  do {									 \
+    (L) = alpha_switch_to(virt_to_phys(&task_thread_info(N)->pcb), (P)); \
+    check_mmu_context();						 \
   } while (0)
 
 struct task_struct;
 extern struct task_struct *alpha_switch_to(unsigned long, struct task_struct*);
 
+/*
+ * On SMP systems, when the scheduler does migration-cost autodetection,
+ * it needs a way to flush as much of the CPU's caches as possible.
+ *
+ * TODO: fill this in!
+ */
+static inline void sched_cacheflush(void)
+{
+}
+
 #define imb() \
 __asm__ __volatile__ ("call_pal %0 #imb" : : "i" (PAL_imb) : "memory")
 
diff --git a/include/asm-alpha/thread_info.h b/include/asm-alpha/thread_info.h
index d51491e..69ffd93 100644
--- a/include/asm-alpha/thread_info.h
+++ b/include/asm-alpha/thread_info.h
@@ -54,8 +54,6 @@
 #define alloc_thread_info(tsk) \
   ((struct thread_info *) __get_free_pages(GFP_KERNEL,1))
 #define free_thread_info(ti) free_pages((unsigned long) (ti), 1)
-#define get_thread_info(ti) get_task_struct((ti)->task)
-#define put_thread_info(ti) put_task_struct((ti)->task)
 
 #endif /* __ASSEMBLY__ */
 
diff --git a/include/asm-arm/ioctl.h b/include/asm-arm/ioctl.h
index 2cbb7d0..b279fe0 100644
--- a/include/asm-arm/ioctl.h
+++ b/include/asm-arm/ioctl.h
@@ -1,74 +1 @@
-/*
- * linux/ioctl.h for Linux by H.H. Bergman.
- */
-
-#ifndef _ASMARM_IOCTL_H
-#define _ASMARM_IOCTL_H
-
-/* ioctl command encoding: 32 bits total, command in lower 16 bits,
- * size of the parameter structure in the lower 14 bits of the
- * upper 16 bits.
- * Encoding the size of the parameter structure in the ioctl request
- * is useful for catching programs compiled with old versions
- * and to avoid overwriting user space outside the user buffer area.
- * The highest 2 bits are reserved for indicating the ``access mode''.
- * NOTE: This limits the max parameter size to 16kB -1 !
- */
-
-/*
- * The following is for compatibility across the various Linux
- * platforms.  The i386 ioctl numbering scheme doesn't really enforce
- * a type field.  De facto, however, the top 8 bits of the lower 16
- * bits are indeed used as a type field, so we might just as well make
- * this explicit here.  Please be sure to use the decoding macros
- * below from now on.
- */
-#define _IOC_NRBITS	8
-#define _IOC_TYPEBITS	8
-#define _IOC_SIZEBITS	14
-#define _IOC_DIRBITS	2
-
-#define _IOC_NRMASK	((1 << _IOC_NRBITS)-1)
-#define _IOC_TYPEMASK	((1 << _IOC_TYPEBITS)-1)
-#define _IOC_SIZEMASK	((1 << _IOC_SIZEBITS)-1)
-#define _IOC_DIRMASK	((1 << _IOC_DIRBITS)-1)
-
-#define _IOC_NRSHIFT	0
-#define _IOC_TYPESHIFT	(_IOC_NRSHIFT+_IOC_NRBITS)
-#define _IOC_SIZESHIFT	(_IOC_TYPESHIFT+_IOC_TYPEBITS)
-#define _IOC_DIRSHIFT	(_IOC_SIZESHIFT+_IOC_SIZEBITS)
-
-/*
- * Direction bits.
- */
-#define _IOC_NONE	0U
-#define _IOC_WRITE	1U
-#define _IOC_READ	2U
-
-#define _IOC(dir,type,nr,size) \
-	(((dir)  << _IOC_DIRSHIFT) | \
-	 ((type) << _IOC_TYPESHIFT) | \
-	 ((nr)   << _IOC_NRSHIFT) | \
-	 ((size) << _IOC_SIZESHIFT))
-
-/* used to create numbers */
-#define _IO(type,nr)		_IOC(_IOC_NONE,(type),(nr),0)
-#define _IOR(type,nr,size)	_IOC(_IOC_READ,(type),(nr),sizeof(size))
-#define _IOW(type,nr,size)	_IOC(_IOC_WRITE,(type),(nr),sizeof(size))
-#define _IOWR(type,nr,size)	_IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
-
-/* used to decode ioctl numbers.. */
-#define _IOC_DIR(nr)		(((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
-#define _IOC_TYPE(nr)		(((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
-#define _IOC_NR(nr)		(((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
-#define _IOC_SIZE(nr)		(((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
-
-/* ...and for the drivers/sound files... */
-
-#define IOC_IN		(_IOC_WRITE << _IOC_DIRSHIFT)
-#define IOC_OUT		(_IOC_READ << _IOC_DIRSHIFT)
-#define IOC_INOUT	((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
-#define IOCSIZE_MASK	(_IOC_SIZEMASK << _IOC_SIZESHIFT)
-#define IOCSIZE_SHIFT	(_IOC_SIZESHIFT)
-
-#endif /* _ASMARM_IOCTL_H */
+#include <asm-generic/ioctl.h>
diff --git a/include/asm-arm/processor.h b/include/asm-arm/processor.h
index 7d4118e..3129069 100644
--- a/include/asm-arm/processor.h
+++ b/include/asm-arm/processor.h
@@ -85,9 +85,11 @@
  */
 extern int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
 
-#define KSTK_REGS(tsk)	(((struct pt_regs *)(THREAD_START_SP + (unsigned long)(tsk)->thread_info)) - 1)
-#define KSTK_EIP(tsk)	KSTK_REGS(tsk)->ARM_pc
-#define KSTK_ESP(tsk)	KSTK_REGS(tsk)->ARM_sp
+#define task_pt_regs(p) \
+	((struct pt_regs *)(THREAD_START_SP + task_stack_page(p)) - 1)
+
+#define KSTK_EIP(tsk)	task_pt_regs(tsk)->ARM_pc
+#define KSTK_ESP(tsk)	task_pt_regs(tsk)->ARM_sp
 
 /*
  * Prefetching support - only ARMv5.
diff --git a/include/asm-arm/system.h b/include/asm-arm/system.h
index 5621d61..eb2de8c 100644
--- a/include/asm-arm/system.h
+++ b/include/asm-arm/system.h
@@ -168,10 +168,20 @@
 
 #define switch_to(prev,next,last)					\
 do {									\
-	last = __switch_to(prev,prev->thread_info,next->thread_info);	\
+	last = __switch_to(prev,task_thread_info(prev), task_thread_info(next));	\
 } while (0)
 
 /*
+ * On SMP systems, when the scheduler does migration-cost autodetection,
+ * it needs a way to flush as much of the CPU's caches as possible.
+ *
+ * TODO: fill this in!
+ */
+static inline void sched_cacheflush(void)
+{
+}
+
+/*
  * CPU interrupt mask handling.
  */
 #if __LINUX_ARM_ARCH__ >= 6
diff --git a/include/asm-arm/thread_info.h b/include/asm-arm/thread_info.h
index 7c98557..33a33cb 100644
--- a/include/asm-arm/thread_info.h
+++ b/include/asm-arm/thread_info.h
@@ -96,13 +96,10 @@
 extern struct thread_info *alloc_thread_info(struct task_struct *task);
 extern void free_thread_info(struct thread_info *);
 
-#define get_thread_info(ti)	get_task_struct((ti)->task)
-#define put_thread_info(ti)	put_task_struct((ti)->task)
-
 #define thread_saved_pc(tsk)	\
-	((unsigned long)(pc_pointer((tsk)->thread_info->cpu_context.pc)))
+	((unsigned long)(pc_pointer(task_thread_info(tsk)->cpu_context.pc)))
 #define thread_saved_fp(tsk)	\
-	((unsigned long)((tsk)->thread_info->cpu_context.fp))
+	((unsigned long)(task_thread_info(tsk)->cpu_context.fp))
 
 extern void iwmmxt_task_disable(struct thread_info *);
 extern void iwmmxt_task_copy(struct thread_info *, void *);
diff --git a/include/asm-arm26/ioctl.h b/include/asm-arm26/ioctl.h
index 2cbb7d0..b279fe0 100644
--- a/include/asm-arm26/ioctl.h
+++ b/include/asm-arm26/ioctl.h
@@ -1,74 +1 @@
-/*
- * linux/ioctl.h for Linux by H.H. Bergman.
- */
-
-#ifndef _ASMARM_IOCTL_H
-#define _ASMARM_IOCTL_H
-
-/* ioctl command encoding: 32 bits total, command in lower 16 bits,
- * size of the parameter structure in the lower 14 bits of the
- * upper 16 bits.
- * Encoding the size of the parameter structure in the ioctl request
- * is useful for catching programs compiled with old versions
- * and to avoid overwriting user space outside the user buffer area.
- * The highest 2 bits are reserved for indicating the ``access mode''.
- * NOTE: This limits the max parameter size to 16kB -1 !
- */
-
-/*
- * The following is for compatibility across the various Linux
- * platforms.  The i386 ioctl numbering scheme doesn't really enforce
- * a type field.  De facto, however, the top 8 bits of the lower 16
- * bits are indeed used as a type field, so we might just as well make
- * this explicit here.  Please be sure to use the decoding macros
- * below from now on.
- */
-#define _IOC_NRBITS	8
-#define _IOC_TYPEBITS	8
-#define _IOC_SIZEBITS	14
-#define _IOC_DIRBITS	2
-
-#define _IOC_NRMASK	((1 << _IOC_NRBITS)-1)
-#define _IOC_TYPEMASK	((1 << _IOC_TYPEBITS)-1)
-#define _IOC_SIZEMASK	((1 << _IOC_SIZEBITS)-1)
-#define _IOC_DIRMASK	((1 << _IOC_DIRBITS)-1)
-
-#define _IOC_NRSHIFT	0
-#define _IOC_TYPESHIFT	(_IOC_NRSHIFT+_IOC_NRBITS)
-#define _IOC_SIZESHIFT	(_IOC_TYPESHIFT+_IOC_TYPEBITS)
-#define _IOC_DIRSHIFT	(_IOC_SIZESHIFT+_IOC_SIZEBITS)
-
-/*
- * Direction bits.
- */
-#define _IOC_NONE	0U
-#define _IOC_WRITE	1U
-#define _IOC_READ	2U
-
-#define _IOC(dir,type,nr,size) \
-	(((dir)  << _IOC_DIRSHIFT) | \
-	 ((type) << _IOC_TYPESHIFT) | \
-	 ((nr)   << _IOC_NRSHIFT) | \
-	 ((size) << _IOC_SIZESHIFT))
-
-/* used to create numbers */
-#define _IO(type,nr)		_IOC(_IOC_NONE,(type),(nr),0)
-#define _IOR(type,nr,size)	_IOC(_IOC_READ,(type),(nr),sizeof(size))
-#define _IOW(type,nr,size)	_IOC(_IOC_WRITE,(type),(nr),sizeof(size))
-#define _IOWR(type,nr,size)	_IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
-
-/* used to decode ioctl numbers.. */
-#define _IOC_DIR(nr)		(((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
-#define _IOC_TYPE(nr)		(((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
-#define _IOC_NR(nr)		(((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
-#define _IOC_SIZE(nr)		(((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
-
-/* ...and for the drivers/sound files... */
-
-#define IOC_IN		(_IOC_WRITE << _IOC_DIRSHIFT)
-#define IOC_OUT		(_IOC_READ << _IOC_DIRSHIFT)
-#define IOC_INOUT	((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
-#define IOCSIZE_MASK	(_IOC_SIZEMASK << _IOC_SIZESHIFT)
-#define IOCSIZE_SHIFT	(_IOC_SIZESHIFT)
-
-#endif /* _ASMARM_IOCTL_H */
+#include <asm-generic/ioctl.h>
diff --git a/include/asm-arm26/system.h b/include/asm-arm26/system.h
index f23fac1..ca4ccfc 100644
--- a/include/asm-arm26/system.h
+++ b/include/asm-arm26/system.h
@@ -111,10 +111,20 @@
 
 #define switch_to(prev,next,last)					\
 do {									\
-	last = __switch_to(prev,prev->thread_info,next->thread_info);	\
+	last = __switch_to(prev,task_thread_info(prev),task_thread_info(next));	\
 } while (0)
 
 /*
+ * On SMP systems, when the scheduler does migration-cost autodetection,
+ * it needs a way to flush as much of the CPU's caches as possible.
+ *
+ * TODO: fill this in!
+ */
+static inline void sched_cacheflush(void)
+{
+}
+
+/*
  * Save the current interrupt enable state & disable IRQs
  */
 #define local_irq_save(x)                               \
diff --git a/include/asm-arm26/thread_info.h b/include/asm-arm26/thread_info.h
index aff3e56..a65e58a 100644
--- a/include/asm-arm26/thread_info.h
+++ b/include/asm-arm26/thread_info.h
@@ -82,18 +82,15 @@
 
 /* FIXME - PAGE_SIZE < 32K */
 #define THREAD_SIZE		(8*32768) // FIXME - this needs attention (see kernel/fork.c which gets a nice div by zero if this is lower than 8*32768
-#define __get_user_regs(x) (((struct pt_regs *)((unsigned long)(x) + THREAD_SIZE - 8)) - 1)
+#define task_pt_regs(task) ((struct pt_regs *)(task_stack_page(task) + THREAD_SIZE - 8) - 1)
 
 extern struct thread_info *alloc_thread_info(struct task_struct *task);
 extern void free_thread_info(struct thread_info *);
 
-#define get_thread_info(ti)	get_task_struct((ti)->task)
-#define put_thread_info(ti)	put_task_struct((ti)->task)
-
 #define thread_saved_pc(tsk)	\
-	((unsigned long)(pc_pointer((tsk)->thread_info->cpu_context.pc)))
+	((unsigned long)(pc_pointer(task_thread_info(tsk)->cpu_context.pc)))
 #define thread_saved_fp(tsk)	\
-	((unsigned long)((tsk)->thread_info->cpu_context.fp))
+	((unsigned long)(task_thread_info(tsk)->cpu_context.fp))
 
 #else /* !__ASSEMBLY__ */
 
diff --git a/include/asm-cris/arch-v10/processor.h b/include/asm-cris/arch-v10/processor.h
index e23df8d..cc692c7 100644
--- a/include/asm-cris/arch-v10/processor.h
+++ b/include/asm-cris/arch-v10/processor.h
@@ -40,7 +40,7 @@
 #define KSTK_EIP(tsk)	\
 ({			\
 	unsigned long eip = 0;   \
-	unsigned long regs = (unsigned long)user_regs(tsk); \
+	unsigned long regs = (unsigned long)task_pt_regs(tsk); \
 	if (regs > PAGE_SIZE && \
 		virt_addr_valid(regs)) \
 	eip = ((struct pt_regs *)regs)->irp; \
diff --git a/include/asm-cris/arch-v32/processor.h b/include/asm-cris/arch-v32/processor.h
index 8c939bf..32bf2e5 100644
--- a/include/asm-cris/arch-v32/processor.h
+++ b/include/asm-cris/arch-v32/processor.h
@@ -36,7 +36,7 @@
 #define KSTK_EIP(tsk)		\
 ({				\
 	unsigned long eip = 0;	\
-	unsigned long regs = (unsigned long)user_regs(tsk); \
+	unsigned long regs = (unsigned long)task_pt_regs(tsk); \
 	if (regs > PAGE_SIZE && virt_addr_valid(regs))	    \
 		eip = ((struct pt_regs *)regs)->erp;	    \
 	eip; \
diff --git a/include/asm-cris/ioctl.h b/include/asm-cris/ioctl.h
index be2d8f6..b279fe0 100644
--- a/include/asm-cris/ioctl.h
+++ b/include/asm-cris/ioctl.h
@@ -1,83 +1 @@
-/*
- * linux/ioctl.h for Linux by H.H. Bergman.
- *
- * This is the same as the i386 version.
- */
-
-#ifndef _ASMCRIS_IOCTL_H
-#define _ASMCRIS_IOCTL_H
-
-/* ioctl command encoding: 32 bits total, command in lower 16 bits,
- * size of the parameter structure in the lower 14 bits of the
- * upper 16 bits.
- * Encoding the size of the parameter structure in the ioctl request
- * is useful for catching programs compiled with old versions
- * and to avoid overwriting user space outside the user buffer area.
- * The highest 2 bits are reserved for indicating the ``access mode''.
- * NOTE: This limits the max parameter size to 16kB -1 !
- */
-
-/*
- * The following is for compatibility across the various Linux
- * platforms.  The i386 ioctl numbering scheme doesn't really enforce
- * a type field.  De facto, however, the top 8 bits of the lower 16
- * bits are indeed used as a type field, so we might just as well make
- * this explicit here.  Please be sure to use the decoding macros
- * below from now on.
- */
-#define _IOC_NRBITS	8
-#define _IOC_TYPEBITS	8
-#define _IOC_SIZEBITS	14
-#define _IOC_DIRBITS	2
-
-#define _IOC_NRMASK	((1 << _IOC_NRBITS)-1)
-#define _IOC_TYPEMASK	((1 << _IOC_TYPEBITS)-1)
-#define _IOC_SIZEMASK	((1 << _IOC_SIZEBITS)-1)
-#define _IOC_DIRMASK	((1 << _IOC_DIRBITS)-1)
-
-#define _IOC_NRSHIFT	0
-#define _IOC_TYPESHIFT	(_IOC_NRSHIFT+_IOC_NRBITS)
-#define _IOC_SIZESHIFT	(_IOC_TYPESHIFT+_IOC_TYPEBITS)
-#define _IOC_DIRSHIFT	(_IOC_SIZESHIFT+_IOC_SIZEBITS)
-
-/*
- * Direction bits.
- */
-#define _IOC_NONE	0U
-#define _IOC_WRITE	1U
-#define _IOC_READ	2U
-
-#define _IOC(dir,type,nr,size) \
-	(((dir)  << _IOC_DIRSHIFT) | \
-	 ((type) << _IOC_TYPESHIFT) | \
-	 ((nr)   << _IOC_NRSHIFT) | \
-	 ((size) << _IOC_SIZESHIFT))
-
-/* provoke compile error for invalid uses of size argument */
-extern int __invalid_size_argument_for_IOC;
-#define _IOC_TYPECHECK(t) \
-	((sizeof(t) == sizeof(t[1]) && \
-	  sizeof(t) < (1 << _IOC_SIZEBITS)) ? \
-	  sizeof(t) : __invalid_size_argument_for_IOC)
-
-/* used to create numbers */
-#define _IO(type,nr)		_IOC(_IOC_NONE,(type),(nr),0)
-#define _IOR(type,nr,size)	_IOC(_IOC_READ,(type),(nr),(_IOC_TYPECHECK(size)))
-#define _IOW(type,nr,size)	_IOC(_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
-#define _IOWR(type,nr,size)	_IOC(_IOC_READ|_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
-
-/* used to decode ioctl numbers.. */
-#define _IOC_DIR(nr)		(((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
-#define _IOC_TYPE(nr)		(((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
-#define _IOC_NR(nr)		(((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
-#define _IOC_SIZE(nr)		(((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
-
-/* ...and for the drivers/sound files... */
-
-#define IOC_IN		(_IOC_WRITE << _IOC_DIRSHIFT)
-#define IOC_OUT		(_IOC_READ << _IOC_DIRSHIFT)
-#define IOC_INOUT	((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
-#define IOCSIZE_MASK	(_IOC_SIZEMASK << _IOC_SIZESHIFT)
-#define IOCSIZE_SHIFT	(_IOC_SIZESHIFT)
-
-#endif /* _ASMCRIS_IOCTL_H */
+#include <asm-generic/ioctl.h>
diff --git a/include/asm-cris/processor.h b/include/asm-cris/processor.h
index dce4100..961e2bc 100644
--- a/include/asm-cris/processor.h
+++ b/include/asm-cris/processor.h
@@ -45,7 +45,8 @@
  * Dito but for the currently running task
  */
 
-#define current_regs() user_regs(current->thread_info)
+#define task_pt_regs(task) user_regs(task_thread_info(task))
+#define current_regs() task_pt_regs(current)
 
 static inline void prepare_to_copy(struct task_struct *tsk)
 {
diff --git a/include/asm-cris/thread_info.h b/include/asm-cris/thread_info.h
index cef0140..7ad853c 100644
--- a/include/asm-cris/thread_info.h
+++ b/include/asm-cris/thread_info.h
@@ -69,8 +69,6 @@
 /* thread information allocation */
 #define alloc_thread_info(tsk) ((struct thread_info *) __get_free_pages(GFP_KERNEL,1))
 #define free_thread_info(ti) free_pages((unsigned long) (ti), 1)
-#define get_thread_info(ti) get_task_struct((ti)->task)
-#define put_thread_info(ti) put_task_struct((ti)->task)
 
 #endif /* !__ASSEMBLY__ */
 
diff --git a/include/asm-frv/ioctl.h b/include/asm-frv/ioctl.h
index 8aee769..b279fe0 100644
--- a/include/asm-frv/ioctl.h
+++ b/include/asm-frv/ioctl.h
@@ -1,80 +1 @@
-/*
- * linux/ioctl.h for Linux by H.H. Bergman.
- */
-
-#ifndef _ASM_IOCTL_H
-#define _ASM_IOCTL_H
-
-/* ioctl command encoding: 32 bits total, command in lower 16 bits,
- * size of the parameter structure in the lower 14 bits of the
- * upper 16 bits.
- * Encoding the size of the parameter structure in the ioctl request
- * is useful for catching programs compiled with old versions
- * and to avoid overwriting user space outside the user buffer area.
- * The highest 2 bits are reserved for indicating the ``access mode''.
- * NOTE: This limits the max parameter size to 16kB -1 !
- */
-
-/*
- * I don't really have any idea about what this should look like, so
- * for the time being, this is heavily based on the PC definitions.
- */
-
-/*
- * The following is for compatibility across the various Linux
- * platforms.  The i386 ioctl numbering scheme doesn't really enforce
- * a type field.  De facto, however, the top 8 bits of the lower 16
- * bits are indeed used as a type field, so we might just as well make
- * this explicit here.  Please be sure to use the decoding macros
- * below from now on.
- */
-#define _IOC_NRBITS	8
-#define _IOC_TYPEBITS	8
-#define _IOC_SIZEBITS	14
-#define _IOC_DIRBITS	2
-
-#define _IOC_NRMASK	((1 << _IOC_NRBITS)-1)
-#define _IOC_TYPEMASK	((1 << _IOC_TYPEBITS)-1)
-#define _IOC_SIZEMASK	((1 << _IOC_SIZEBITS)-1)
-#define _IOC_DIRMASK	((1 << _IOC_DIRBITS)-1)
-
-#define _IOC_NRSHIFT	0
-#define _IOC_TYPESHIFT	(_IOC_NRSHIFT+_IOC_NRBITS)
-#define _IOC_SIZESHIFT	(_IOC_TYPESHIFT+_IOC_TYPEBITS)
-#define _IOC_DIRSHIFT	(_IOC_SIZESHIFT+_IOC_SIZEBITS)
-
-/*
- * Direction bits.
- */
-#define _IOC_NONE	0U
-#define _IOC_WRITE	1U
-#define _IOC_READ	2U
-
-#define _IOC(dir,type,nr,size) \
-	(((dir)  << _IOC_DIRSHIFT) | \
-	 ((type) << _IOC_TYPESHIFT) | \
-	 ((nr)   << _IOC_NRSHIFT) | \
-	 ((size) << _IOC_SIZESHIFT))
-
-/* used to create numbers */
-#define _IO(type,nr)		_IOC(_IOC_NONE,(type),(nr),0)
-#define _IOR(type,nr,size)	_IOC(_IOC_READ,(type),(nr),sizeof(size))
-#define _IOW(type,nr,size)	_IOC(_IOC_WRITE,(type),(nr),sizeof(size))
-#define _IOWR(type,nr,size)	_IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
-
-/* used to decode ioctl numbers.. */
-#define _IOC_DIR(nr)		(((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
-#define _IOC_TYPE(nr)		(((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
-#define _IOC_NR(nr)		(((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
-#define _IOC_SIZE(nr)		(((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
-
-/* ...and for the drivers/sound files... */
-
-#define IOC_IN		(_IOC_WRITE << _IOC_DIRSHIFT)
-#define IOC_OUT		(_IOC_READ << _IOC_DIRSHIFT)
-#define IOC_INOUT	((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
-#define IOCSIZE_MASK	(_IOC_SIZEMASK << _IOC_SIZESHIFT)
-#define IOCSIZE_SHIFT	(_IOC_SIZESHIFT)
-
-#endif /* _ASM_IOCTL_H */
-
+#include <asm-generic/ioctl.h>
diff --git a/include/asm-frv/thread_info.h b/include/asm-frv/thread_info.h
index 60f6b2a..a5576e0 100644
--- a/include/asm-frv/thread_info.h
+++ b/include/asm-frv/thread_info.h
@@ -110,8 +110,6 @@
 #endif
 
 #define free_thread_info(info)	kfree(info)
-#define get_thread_info(ti)	get_task_struct((ti)->task)
-#define put_thread_info(ti)	put_task_struct((ti)->task)
 
 #else /* !__ASSEMBLY__ */
 
diff --git a/include/asm-generic/ioctl.h b/include/asm-generic/ioctl.h
new file mode 100644
index 0000000..cd02729
--- /dev/null
+++ b/include/asm-generic/ioctl.h
@@ -0,0 +1,80 @@
+#ifndef _ASM_GENERIC_IOCTL_H
+#define _ASM_GENERIC_IOCTL_H
+
+/* ioctl command encoding: 32 bits total, command in lower 16 bits,
+ * size of the parameter structure in the lower 14 bits of the
+ * upper 16 bits.
+ * Encoding the size of the parameter structure in the ioctl request
+ * is useful for catching programs compiled with old versions
+ * and to avoid overwriting user space outside the user buffer area.
+ * The highest 2 bits are reserved for indicating the ``access mode''.
+ * NOTE: This limits the max parameter size to 16kB -1 !
+ */
+
+/*
+ * The following is for compatibility across the various Linux
+ * platforms.  The generic ioctl numbering scheme doesn't really enforce
+ * a type field.  De facto, however, the top 8 bits of the lower 16
+ * bits are indeed used as a type field, so we might just as well make
+ * this explicit here.  Please be sure to use the decoding macros
+ * below from now on.
+ */
+#define _IOC_NRBITS	8
+#define _IOC_TYPEBITS	8
+#define _IOC_SIZEBITS	14
+#define _IOC_DIRBITS	2
+
+#define _IOC_NRMASK	((1 << _IOC_NRBITS)-1)
+#define _IOC_TYPEMASK	((1 << _IOC_TYPEBITS)-1)
+#define _IOC_SIZEMASK	((1 << _IOC_SIZEBITS)-1)
+#define _IOC_DIRMASK	((1 << _IOC_DIRBITS)-1)
+
+#define _IOC_NRSHIFT	0
+#define _IOC_TYPESHIFT	(_IOC_NRSHIFT+_IOC_NRBITS)
+#define _IOC_SIZESHIFT	(_IOC_TYPESHIFT+_IOC_TYPEBITS)
+#define _IOC_DIRSHIFT	(_IOC_SIZESHIFT+_IOC_SIZEBITS)
+
+/*
+ * Direction bits.
+ */
+#define _IOC_NONE	0U
+#define _IOC_WRITE	1U
+#define _IOC_READ	2U
+
+#define _IOC(dir,type,nr,size) \
+	(((dir)  << _IOC_DIRSHIFT) | \
+	 ((type) << _IOC_TYPESHIFT) | \
+	 ((nr)   << _IOC_NRSHIFT) | \
+	 ((size) << _IOC_SIZESHIFT))
+
+/* provoke compile error for invalid uses of size argument */
+extern unsigned int __invalid_size_argument_for_IOC;
+#define _IOC_TYPECHECK(t) \
+	((sizeof(t) == sizeof(t[1]) && \
+	  sizeof(t) < (1 << _IOC_SIZEBITS)) ? \
+	  sizeof(t) : __invalid_size_argument_for_IOC)
+
+/* used to create numbers */
+#define _IO(type,nr)		_IOC(_IOC_NONE,(type),(nr),0)
+#define _IOR(type,nr,size)	_IOC(_IOC_READ,(type),(nr),(_IOC_TYPECHECK(size)))
+#define _IOW(type,nr,size)	_IOC(_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
+#define _IOWR(type,nr,size)	_IOC(_IOC_READ|_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
+#define _IOR_BAD(type,nr,size)	_IOC(_IOC_READ,(type),(nr),sizeof(size))
+#define _IOW_BAD(type,nr,size)	_IOC(_IOC_WRITE,(type),(nr),sizeof(size))
+#define _IOWR_BAD(type,nr,size)	_IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
+
+/* used to decode ioctl numbers.. */
+#define _IOC_DIR(nr)		(((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
+#define _IOC_TYPE(nr)		(((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
+#define _IOC_NR(nr)		(((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
+#define _IOC_SIZE(nr)		(((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
+
+/* ...and for the drivers/sound files... */
+
+#define IOC_IN		(_IOC_WRITE << _IOC_DIRSHIFT)
+#define IOC_OUT		(_IOC_READ << _IOC_DIRSHIFT)
+#define IOC_INOUT	((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
+#define IOCSIZE_MASK	(_IOC_SIZEMASK << _IOC_SIZESHIFT)
+#define IOCSIZE_SHIFT	(_IOC_SIZESHIFT)
+
+#endif /* _ASM_GENERIC_IOCTL_H */
diff --git a/include/asm-generic/mutex-dec.h b/include/asm-generic/mutex-dec.h
index 74b18cd..40c6d1f 100644
--- a/include/asm-generic/mutex-dec.h
+++ b/include/asm-generic/mutex-dec.h
@@ -97,7 +97,7 @@
 	 * the mutex state would be.
 	 */
 #ifdef __HAVE_ARCH_CMPXCHG
-	if (likely(atomic_cmpxchg(count, 1, 0)) == 1) {
+	if (likely(atomic_cmpxchg(count, 1, 0) == 1)) {
 		smp_mb();
 		return 1;
 	}
diff --git a/include/asm-h8300/ioctl.h b/include/asm-h8300/ioctl.h
index 031c623..b279fe0 100644
--- a/include/asm-h8300/ioctl.h
+++ b/include/asm-h8300/ioctl.h
@@ -1,80 +1 @@
-/* $Id: ioctl.h,v 1.1 2002/11/19 02:09:26 gerg Exp $
- *
- * linux/ioctl.h for Linux by H.H. Bergman.
- */
-
-#ifndef _H8300_IOCTL_H
-#define _H8300_IOCTL_H
-
-/* ioctl command encoding: 32 bits total, command in lower 16 bits,
- * size of the parameter structure in the lower 14 bits of the
- * upper 16 bits.
- * Encoding the size of the parameter structure in the ioctl request
- * is useful for catching programs compiled with old versions
- * and to avoid overwriting user space outside the user buffer area.
- * The highest 2 bits are reserved for indicating the ``access mode''.
- * NOTE: This limits the max parameter size to 16kB -1 !
- */
-
-/*
- * I don't really have any idea about what this should look like, so
- * for the time being, this is heavily based on the PC definitions.
- */
-
-/*
- * The following is for compatibility across the various Linux
- * platforms.  The i386 ioctl numbering scheme doesn't really enforce
- * a type field.  De facto, however, the top 8 bits of the lower 16
- * bits are indeed used as a type field, so we might just as well make
- * this explicit here.  Please be sure to use the decoding macros
- * below from now on.
- */
-#define _IOC_NRBITS	8
-#define _IOC_TYPEBITS	8
-#define _IOC_SIZEBITS	14
-#define _IOC_DIRBITS	2
-
-#define _IOC_NRMASK	((1 << _IOC_NRBITS)-1)
-#define _IOC_TYPEMASK	((1 << _IOC_TYPEBITS)-1)
-#define _IOC_SIZEMASK	((1 << _IOC_SIZEBITS)-1)
-#define _IOC_DIRMASK	((1 << _IOC_DIRBITS)-1)
-
-#define _IOC_NRSHIFT	0
-#define _IOC_TYPESHIFT	(_IOC_NRSHIFT+_IOC_NRBITS)
-#define _IOC_SIZESHIFT	(_IOC_TYPESHIFT+_IOC_TYPEBITS)
-#define _IOC_DIRSHIFT	(_IOC_SIZESHIFT+_IOC_SIZEBITS)
-
-/*
- * Direction bits.
- */
-#define _IOC_NONE	0U
-#define _IOC_WRITE	1U
-#define _IOC_READ	2U
-
-#define _IOC(dir,type,nr,size) \
-	(((dir)  << _IOC_DIRSHIFT) | \
-	 ((type) << _IOC_TYPESHIFT) | \
-	 ((nr)   << _IOC_NRSHIFT) | \
-	 ((size) << _IOC_SIZESHIFT))
-
-/* used to create numbers */
-#define _IO(type,nr)		_IOC(_IOC_NONE,(type),(nr),0)
-#define _IOR(type,nr,size)	_IOC(_IOC_READ,(type),(nr),sizeof(size))
-#define _IOW(type,nr,size)	_IOC(_IOC_WRITE,(type),(nr),sizeof(size))
-#define _IOWR(type,nr,size)	_IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
-
-/* used to decode ioctl numbers.. */
-#define _IOC_DIR(nr)		(((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
-#define _IOC_TYPE(nr)		(((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
-#define _IOC_NR(nr)		(((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
-#define _IOC_SIZE(nr)		(((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
-
-/* ...and for the drivers/sound files... */
-
-#define IOC_IN		(_IOC_WRITE << _IOC_DIRSHIFT)
-#define IOC_OUT		(_IOC_READ << _IOC_DIRSHIFT)
-#define IOC_INOUT	((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
-#define IOCSIZE_MASK	(_IOC_SIZEMASK << _IOC_SIZESHIFT)
-#define IOCSIZE_SHIFT	(_IOC_SIZESHIFT)
-
-#endif /* _H8300_IOCTL_H */
+#include <asm-generic/ioctl.h>
diff --git a/include/asm-h8300/page.h b/include/asm-h8300/page.h
index e8c02b8..cd35b1c 100644
--- a/include/asm-h8300/page.h
+++ b/include/asm-h8300/page.h
@@ -13,12 +13,6 @@
 
 #include <asm/setup.h>
 
-#if !defined(CONFIG_SMALL_TASKS) && PAGE_SHIFT < 13
-#define KTHREAD_SIZE (8192)
-#else
-#define KTHREAD_SIZE PAGE_SIZE
-#endif
- 
 #ifndef __ASSEMBLY__
  
 #define get_user_page(vaddr)		__get_free_page(GFP_KERNEL)
diff --git a/include/asm-h8300/thread_info.h b/include/asm-h8300/thread_info.h
index bfcc755..45f09dc 100644
--- a/include/asm-h8300/thread_info.h
+++ b/include/asm-h8300/thread_info.h
@@ -69,8 +69,6 @@
 #define alloc_thread_info(tsk) ((struct thread_info *) \
 				__get_free_pages(GFP_KERNEL, 1))
 #define free_thread_info(ti)	free_pages((unsigned long) (ti), 1)
-#define get_thread_info(ti)	get_task_struct((ti)->task)
-#define put_thread_info(ti)	put_task_struct((ti)->task)
 #endif /* __ASSEMBLY__ */
 
 /*
diff --git a/include/asm-i386/apic.h b/include/asm-i386/apic.h
index 8c454aa..d30b857 100644
--- a/include/asm-i386/apic.h
+++ b/include/asm-i386/apic.h
@@ -132,6 +132,11 @@
 
 extern int disable_timer_pin_1;
 
+void smp_send_timer_broadcast_ipi(struct pt_regs *regs);
+void switch_APIC_timer_to_ipi(void *cpumask);
+void switch_ipi_to_APIC_timer(void *cpumask);
+#define ARCH_APICTIMER_STOPS_ON_C3	1
+
 #else /* !CONFIG_X86_LOCAL_APIC */
 static inline void lapic_shutdown(void) { }
 
diff --git a/include/asm-i386/bitops.h b/include/asm-i386/bitops.h
index 65679ac..fe0819f 100644
--- a/include/asm-i386/bitops.h
+++ b/include/asm-i386/bitops.h
@@ -43,7 +43,7 @@
 {
 	__asm__ __volatile__( LOCK_PREFIX
 		"btsl %1,%0"
-		:"=m" (ADDR)
+		:"+m" (ADDR)
 		:"Ir" (nr));
 }
 
@@ -60,7 +60,7 @@
 {
 	__asm__(
 		"btsl %1,%0"
-		:"=m" (ADDR)
+		:"+m" (ADDR)
 		:"Ir" (nr));
 }
 
@@ -78,7 +78,7 @@
 {
 	__asm__ __volatile__( LOCK_PREFIX
 		"btrl %1,%0"
-		:"=m" (ADDR)
+		:"+m" (ADDR)
 		:"Ir" (nr));
 }
 
@@ -86,7 +86,7 @@
 {
 	__asm__ __volatile__(
 		"btrl %1,%0"
-		:"=m" (ADDR)
+		:"+m" (ADDR)
 		:"Ir" (nr));
 }
 #define smp_mb__before_clear_bit()	barrier()
@@ -105,7 +105,7 @@
 {
 	__asm__ __volatile__(
 		"btcl %1,%0"
-		:"=m" (ADDR)
+		:"+m" (ADDR)
 		:"Ir" (nr));
 }
 
@@ -123,7 +123,7 @@
 {
 	__asm__ __volatile__( LOCK_PREFIX
 		"btcl %1,%0"
-		:"=m" (ADDR)
+		:"+m" (ADDR)
 		:"Ir" (nr));
 }
 
@@ -142,7 +142,7 @@
 
 	__asm__ __volatile__( LOCK_PREFIX
 		"btsl %2,%1\n\tsbbl %0,%0"
-		:"=r" (oldbit),"=m" (ADDR)
+		:"=r" (oldbit),"+m" (ADDR)
 		:"Ir" (nr) : "memory");
 	return oldbit;
 }
@@ -162,7 +162,7 @@
 
 	__asm__(
 		"btsl %2,%1\n\tsbbl %0,%0"
-		:"=r" (oldbit),"=m" (ADDR)
+		:"=r" (oldbit),"+m" (ADDR)
 		:"Ir" (nr));
 	return oldbit;
 }
@@ -182,7 +182,7 @@
 
 	__asm__ __volatile__( LOCK_PREFIX
 		"btrl %2,%1\n\tsbbl %0,%0"
-		:"=r" (oldbit),"=m" (ADDR)
+		:"=r" (oldbit),"+m" (ADDR)
 		:"Ir" (nr) : "memory");
 	return oldbit;
 }
@@ -202,7 +202,7 @@
 
 	__asm__(
 		"btrl %2,%1\n\tsbbl %0,%0"
-		:"=r" (oldbit),"=m" (ADDR)
+		:"=r" (oldbit),"+m" (ADDR)
 		:"Ir" (nr));
 	return oldbit;
 }
@@ -214,7 +214,7 @@
 
 	__asm__ __volatile__(
 		"btcl %2,%1\n\tsbbl %0,%0"
-		:"=r" (oldbit),"=m" (ADDR)
+		:"=r" (oldbit),"+m" (ADDR)
 		:"Ir" (nr) : "memory");
 	return oldbit;
 }
@@ -233,7 +233,7 @@
 
 	__asm__ __volatile__( LOCK_PREFIX
 		"btcl %2,%1\n\tsbbl %0,%0"
-		:"=r" (oldbit),"=m" (ADDR)
+		:"=r" (oldbit),"+m" (ADDR)
 		:"Ir" (nr) : "memory");
 	return oldbit;
 }
diff --git a/include/asm-i386/cpufeature.h b/include/asm-i386/cpufeature.h
index ff1187e..c4ec2a4 100644
--- a/include/asm-i386/cpufeature.h
+++ b/include/asm-i386/cpufeature.h
@@ -69,6 +69,7 @@
 #define X86_FEATURE_K7		(3*32+ 5) /* Athlon */
 #define X86_FEATURE_P3		(3*32+ 6) /* P3 */
 #define X86_FEATURE_P4		(3*32+ 7) /* P4 */
+#define X86_FEATURE_CONSTANT_TSC (3*32+ 8) /* TSC ticks at a constant rate */
 
 /* Intel-defined CPU features, CPUID level 0x00000001 (ecx), word 4 */
 #define X86_FEATURE_XMM3	(4*32+ 0) /* Streaming SIMD Extensions-3 */
diff --git a/include/asm-i386/dma-mapping.h b/include/asm-i386/dma-mapping.h
index 6c37a9a..9cf20ca 100644
--- a/include/asm-i386/dma-mapping.h
+++ b/include/asm-i386/dma-mapping.h
@@ -6,6 +6,7 @@
 #include <asm/cache.h>
 #include <asm/io.h>
 #include <asm/scatterlist.h>
+#include <asm/bug.h>
 
 #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
@@ -20,7 +21,9 @@
 dma_map_single(struct device *dev, void *ptr, size_t size,
 	       enum dma_data_direction direction)
 {
-	BUG_ON(direction == DMA_NONE);
+	if (direction == DMA_NONE)
+		BUG();
+	WARN_ON(size == 0);
 	flush_write_buffers();
 	return virt_to_phys(ptr);
 }
@@ -29,7 +32,8 @@
 dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
 		 enum dma_data_direction direction)
 {
-	BUG_ON(direction == DMA_NONE);
+	if (direction == DMA_NONE)
+		BUG();
 }
 
 static inline int
@@ -38,7 +42,9 @@
 {
 	int i;
 
-	BUG_ON(direction == DMA_NONE);
+	if (direction == DMA_NONE)
+		BUG();
+	WARN_ON(nents == 0 || sg[0].length == 0);
 
 	for (i = 0; i < nents; i++ ) {
 		BUG_ON(!sg[i].page);
diff --git a/include/asm-i386/i387.h b/include/asm-i386/i387.h
index 6747006..152d0ba 100644
--- a/include/asm-i386/i387.h
+++ b/include/asm-i386/i387.h
@@ -49,19 +49,19 @@
 		X86_FEATURE_FXSR,
 		"m" (tsk->thread.i387.fxsave)
 		:"memory");
-	tsk->thread_info->status &= ~TS_USEDFPU;
+	task_thread_info(tsk)->status &= ~TS_USEDFPU;
 }
 
 #define __unlazy_fpu( tsk ) do { \
-	if ((tsk)->thread_info->status & TS_USEDFPU) \
+	if (task_thread_info(tsk)->status & TS_USEDFPU) \
 		save_init_fpu( tsk ); \
 } while (0)
 
 #define __clear_fpu( tsk )					\
 do {								\
-	if ((tsk)->thread_info->status & TS_USEDFPU) {		\
+	if (task_thread_info(tsk)->status & TS_USEDFPU) {		\
 		asm volatile("fnclex ; fwait");				\
-		(tsk)->thread_info->status &= ~TS_USEDFPU;	\
+		task_thread_info(tsk)->status &= ~TS_USEDFPU;	\
 		stts();						\
 	}							\
 } while (0)
diff --git a/include/asm-i386/io.h b/include/asm-i386/io.h
index 7babb97..03233c2 100644
--- a/include/asm-i386/io.h
+++ b/include/asm-i386/io.h
@@ -131,6 +131,11 @@
 extern void *bt_ioremap(unsigned long offset, unsigned long size);
 extern void bt_iounmap(void *addr, unsigned long size);
 
+/* Use early IO mappings for DMI because it's initialized early */
+#define dmi_ioremap bt_ioremap
+#define dmi_iounmap bt_iounmap
+#define dmi_alloc alloc_bootmem
+
 /*
  * ISA I/O bus memory addresses are 1:1 with the physical address.
  */
diff --git a/include/asm-i386/ioctl.h b/include/asm-i386/ioctl.h
index 543f784..b279fe0 100644
--- a/include/asm-i386/ioctl.h
+++ b/include/asm-i386/ioctl.h
@@ -1,85 +1 @@
-/* $Id: ioctl.h,v 1.5 1993/07/19 21:53:50 root Exp root $
- *
- * linux/ioctl.h for Linux by H.H. Bergman.
- */
-
-#ifndef _ASMI386_IOCTL_H
-#define _ASMI386_IOCTL_H
-
-/* ioctl command encoding: 32 bits total, command in lower 16 bits,
- * size of the parameter structure in the lower 14 bits of the
- * upper 16 bits.
- * Encoding the size of the parameter structure in the ioctl request
- * is useful for catching programs compiled with old versions
- * and to avoid overwriting user space outside the user buffer area.
- * The highest 2 bits are reserved for indicating the ``access mode''.
- * NOTE: This limits the max parameter size to 16kB -1 !
- */
-
-/*
- * The following is for compatibility across the various Linux
- * platforms.  The i386 ioctl numbering scheme doesn't really enforce
- * a type field.  De facto, however, the top 8 bits of the lower 16
- * bits are indeed used as a type field, so we might just as well make
- * this explicit here.  Please be sure to use the decoding macros
- * below from now on.
- */
-#define _IOC_NRBITS	8
-#define _IOC_TYPEBITS	8
-#define _IOC_SIZEBITS	14
-#define _IOC_DIRBITS	2
-
-#define _IOC_NRMASK	((1 << _IOC_NRBITS)-1)
-#define _IOC_TYPEMASK	((1 << _IOC_TYPEBITS)-1)
-#define _IOC_SIZEMASK	((1 << _IOC_SIZEBITS)-1)
-#define _IOC_DIRMASK	((1 << _IOC_DIRBITS)-1)
-
-#define _IOC_NRSHIFT	0
-#define _IOC_TYPESHIFT	(_IOC_NRSHIFT+_IOC_NRBITS)
-#define _IOC_SIZESHIFT	(_IOC_TYPESHIFT+_IOC_TYPEBITS)
-#define _IOC_DIRSHIFT	(_IOC_SIZESHIFT+_IOC_SIZEBITS)
-
-/*
- * Direction bits.
- */
-#define _IOC_NONE	0U
-#define _IOC_WRITE	1U
-#define _IOC_READ	2U
-
-#define _IOC(dir,type,nr,size) \
-	(((dir)  << _IOC_DIRSHIFT) | \
-	 ((type) << _IOC_TYPESHIFT) | \
-	 ((nr)   << _IOC_NRSHIFT) | \
-	 ((size) << _IOC_SIZESHIFT))
-
-/* provoke compile error for invalid uses of size argument */
-extern unsigned int __invalid_size_argument_for_IOC;
-#define _IOC_TYPECHECK(t) \
-	((sizeof(t) == sizeof(t[1]) && \
-	  sizeof(t) < (1 << _IOC_SIZEBITS)) ? \
-	  sizeof(t) : __invalid_size_argument_for_IOC)
-
-/* used to create numbers */
-#define _IO(type,nr)		_IOC(_IOC_NONE,(type),(nr),0)
-#define _IOR(type,nr,size)	_IOC(_IOC_READ,(type),(nr),(_IOC_TYPECHECK(size)))
-#define _IOW(type,nr,size)	_IOC(_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
-#define _IOWR(type,nr,size)	_IOC(_IOC_READ|_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
-#define _IOR_BAD(type,nr,size)	_IOC(_IOC_READ,(type),(nr),sizeof(size))
-#define _IOW_BAD(type,nr,size)	_IOC(_IOC_WRITE,(type),(nr),sizeof(size))
-#define _IOWR_BAD(type,nr,size)	_IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
-
-/* used to decode ioctl numbers.. */
-#define _IOC_DIR(nr)		(((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
-#define _IOC_TYPE(nr)		(((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
-#define _IOC_NR(nr)		(((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
-#define _IOC_SIZE(nr)		(((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
-
-/* ...and for the drivers/sound files... */
-
-#define IOC_IN		(_IOC_WRITE << _IOC_DIRSHIFT)
-#define IOC_OUT		(_IOC_READ << _IOC_DIRSHIFT)
-#define IOC_INOUT	((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
-#define IOCSIZE_MASK	(_IOC_SIZEMASK << _IOC_SIZESHIFT)
-#define IOCSIZE_SHIFT	(_IOC_SIZESHIFT)
-
-#endif /* _ASMI386_IOCTL_H */
+#include <asm-generic/ioctl.h>
diff --git a/include/asm-i386/kexec.h b/include/asm-i386/kexec.h
index 6ed2a03..53f0e06 100644
--- a/include/asm-i386/kexec.h
+++ b/include/asm-i386/kexec.h
@@ -2,6 +2,8 @@
 #define _I386_KEXEC_H
 
 #include <asm/fixmap.h>
+#include <asm/ptrace.h>
+#include <asm/string.h>
 
 /*
  * KEXEC_SOURCE_MEMORY_LIMIT maximum page get_free_page can return.
@@ -26,8 +28,49 @@
 #define KEXEC_ARCH KEXEC_ARCH_386
 
 #define MAX_NOTE_BYTES 1024
-typedef u32 note_buf_t[MAX_NOTE_BYTES/4];
 
-extern note_buf_t crash_notes[];
+/* CPU does not save ss and esp on stack if execution is already
+ * running in kernel mode at the time of NMI occurrence. This code
+ * fixes it.
+ */
+static inline void crash_fixup_ss_esp(struct pt_regs *newregs,
+					struct pt_regs *oldregs)
+{
+	memcpy(newregs, oldregs, sizeof(*newregs));
+	newregs->esp = (unsigned long)&(oldregs->esp);
+	__asm__ __volatile__(
+			"xorl %%eax, %%eax\n\t"
+			"movw %%ss, %%ax\n\t"
+			:"=a"(newregs->xss));
+}
+
+/*
+ * This function is responsible for capturing register states if coming
+ * via panic otherwise just fix up the ss and esp if coming via kernel
+ * mode exception.
+ */
+static inline void crash_setup_regs(struct pt_regs *newregs,
+                                       struct pt_regs *oldregs)
+{
+       if (oldregs)
+               crash_fixup_ss_esp(newregs, oldregs);
+       else {
+               __asm__ __volatile__("movl %%ebx,%0" : "=m"(newregs->ebx));
+               __asm__ __volatile__("movl %%ecx,%0" : "=m"(newregs->ecx));
+               __asm__ __volatile__("movl %%edx,%0" : "=m"(newregs->edx));
+               __asm__ __volatile__("movl %%esi,%0" : "=m"(newregs->esi));
+               __asm__ __volatile__("movl %%edi,%0" : "=m"(newregs->edi));
+               __asm__ __volatile__("movl %%ebp,%0" : "=m"(newregs->ebp));
+               __asm__ __volatile__("movl %%eax,%0" : "=m"(newregs->eax));
+               __asm__ __volatile__("movl %%esp,%0" : "=m"(newregs->esp));
+               __asm__ __volatile__("movw %%ss, %%ax;" :"=a"(newregs->xss));
+               __asm__ __volatile__("movw %%cs, %%ax;" :"=a"(newregs->xcs));
+               __asm__ __volatile__("movw %%ds, %%ax;" :"=a"(newregs->xds));
+               __asm__ __volatile__("movw %%es, %%ax;" :"=a"(newregs->xes));
+               __asm__ __volatile__("pushfl; popl %0" :"=m"(newregs->eflags));
+
+               newregs->eip = (unsigned long)current_text_addr();
+       }
+}
 
 #endif /* _I386_KEXEC_H */
diff --git a/include/asm-i386/kprobes.h b/include/asm-i386/kprobes.h
index ca916a8..27cac05 100644
--- a/include/asm-i386/kprobes.h
+++ b/include/asm-i386/kprobes.h
@@ -40,6 +40,7 @@
 
 #define JPROBE_ENTRY(pentry)	(kprobe_opcode_t *)pentry
 #define ARCH_SUPPORTS_KRETPROBES
+#define arch_remove_kprobe(p)	do {} while (0)
 
 void kretprobe_trampoline(void);
 
@@ -76,14 +77,6 @@
 		local_irq_enable();
 }
 
-#ifdef CONFIG_KPROBES
 extern int kprobe_exceptions_notify(struct notifier_block *self,
 				    unsigned long val, void *data);
-#else				/* !CONFIG_KPROBES */
-static inline int kprobe_exceptions_notify(struct notifier_block *self,
-					   unsigned long val, void *data)
-{
-	return 0;
-}
-#endif
 #endif				/* _ASM_KPROBES_H */
diff --git a/include/asm-i386/mach-default/mach_ipi.h b/include/asm-i386/mach-default/mach_ipi.h
index cc756a6..a1d0072 100644
--- a/include/asm-i386/mach-default/mach_ipi.h
+++ b/include/asm-i386/mach-default/mach_ipi.h
@@ -15,11 +15,9 @@
 {
 	if (no_broadcast) {
 		cpumask_t mask = cpu_online_map;
-		int this_cpu = get_cpu();
 
-		cpu_clear(this_cpu, mask);
+		cpu_clear(smp_processor_id(), mask);
 		send_IPI_mask(mask, vector);
-		put_cpu();
 	} else
 		__send_IPI_shortcut(APIC_DEST_ALLBUT, vector);
 }
diff --git a/include/asm-i386/mutex.h b/include/asm-i386/mutex.h
index 4e5e3de..9b2199e 100644
--- a/include/asm-i386/mutex.h
+++ b/include/asm-i386/mutex.h
@@ -28,7 +28,13 @@
 									\
 	__asm__ __volatile__(						\
 		LOCK	"   decl (%%eax)	\n"			\
-			"   js "#fail_fn"	\n"			\
+			"   js 2f		\n"			\
+			"1:			\n"			\
+									\
+		LOCK_SECTION_START("")					\
+			"2: call "#fail_fn"	\n"			\
+			"   jmp 1b		\n"			\
+		LOCK_SECTION_END					\
 									\
 		:"=a" (dummy)						\
 		: "a" (count)						\
@@ -78,7 +84,13 @@
 									\
 	__asm__ __volatile__(						\
 		LOCK	"   incl (%%eax)	\n"			\
-			"   jle "#fail_fn"	\n"			\
+			"   jle 2f		\n"			\
+			"1:			\n"			\
+									\
+		LOCK_SECTION_START("")					\
+			"2: call "#fail_fn"	\n"			\
+			"   jmp 1b		\n"			\
+		LOCK_SECTION_END					\
 									\
 		:"=a" (dummy)						\
 		: "a" (count)						\
@@ -113,7 +125,7 @@
 	 * the mutex state would be.
 	 */
 #ifdef __HAVE_ARCH_CMPXCHG
-	if (likely(atomic_cmpxchg(count, 1, 0)) == 1)
+	if (likely(atomic_cmpxchg(count, 1, 0) == 1))
 		return 1;
 	return 0;
 #else
diff --git a/include/asm-i386/processor.h b/include/asm-i386/processor.h
index 5c96cf6..feca5d9 100644
--- a/include/asm-i386/processor.h
+++ b/include/asm-i386/processor.h
@@ -61,9 +61,11 @@
 	int 	x86_cache_size;  /* in KB - valid for CPUS which support this
 				    call  */
 	int 	x86_cache_alignment;	/* In bytes */
-	int	fdiv_bug;
-	int	f00f_bug;
-	int	coma_bug;
+	char	fdiv_bug;
+	char	f00f_bug;
+	char	coma_bug;
+	char	pad0;
+	int	x86_power;
 	unsigned long loops_per_jiffy;
 	unsigned char x86_max_cores;	/* cpuid returned max cores value */
 	unsigned char booted_cores;	/* number of cores as seen by OS */
@@ -279,9 +281,11 @@
 	outb((data), 0x23); \
 } while (0)
 
-static inline void serialize_cpu(void)
+/* Stop speculative execution */
+static inline void sync_core(void)
 {
-	 __asm__ __volatile__ ("cpuid" : : : "ax", "bx", "cx", "dx");
+	int tmp;
+	asm volatile("cpuid" : "=a" (tmp) : "0" (1) : "ebx","ecx","edx","memory");
 }
 
 static inline void __monitor(const void *eax, unsigned long ecx,
@@ -557,10 +561,20 @@
        (unsigned long)(&__ptr[THREAD_SIZE_LONGS]);                     \
 })
 
+/*
+ * The below -8 is to reserve 8 bytes on top of the ring0 stack.
+ * This is necessary to guarantee that the entire "struct pt_regs"
+ * is accessable even if the CPU haven't stored the SS/ESP registers
+ * on the stack (interrupt gate does not save these registers
+ * when switching to the same priv ring).
+ * Therefore beware: accessing the xss/esp fields of the
+ * "struct pt_regs" is possible, but they may contain the
+ * completely wrong values.
+ */
 #define task_pt_regs(task)                                             \
 ({                                                                     \
        struct pt_regs *__regs__;                                       \
-       __regs__ = (struct pt_regs *)KSTK_TOP((task)->thread_info);     \
+       __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
        __regs__ - 1;                                                   \
 })
 
diff --git a/include/asm-i386/system.h b/include/asm-i386/system.h
index 9c0593b..36a92ed 100644
--- a/include/asm-i386/system.h
+++ b/include/asm-i386/system.h
@@ -548,6 +548,15 @@
 extern int es7000_plat;
 void cpu_idle_wait(void);
 
+/*
+ * On SMP systems, when the scheduler does migration-cost autodetection,
+ * it needs a way to flush as much of the CPU's caches as possible:
+ */
+static inline void sched_cacheflush(void)
+{
+	wbinvd();
+}
+
 extern unsigned long arch_align_stack(unsigned long sp);
 
 #endif
diff --git a/include/asm-i386/thread_info.h b/include/asm-i386/thread_info.h
index 8fbf791..2493e77 100644
--- a/include/asm-i386/thread_info.h
+++ b/include/asm-i386/thread_info.h
@@ -111,8 +111,6 @@
 #endif
 
 #define free_thread_info(info)	kfree(info)
-#define get_thread_info(ti) get_task_struct((ti)->task)
-#define put_thread_info(ti) put_task_struct((ti)->task)
 
 #else /* !__ASSEMBLY__ */
 
diff --git a/include/asm-i386/topology.h b/include/asm-i386/topology.h
index 0ec27c9..d7e19eb 100644
--- a/include/asm-i386/topology.h
+++ b/include/asm-i386/topology.h
@@ -72,7 +72,6 @@
 	.max_interval		= 32,			\
 	.busy_factor		= 32,			\
 	.imbalance_pct		= 125,			\
-	.cache_hot_time		= (10*1000000),		\
 	.cache_nice_tries	= 1,			\
 	.busy_idx		= 3,			\
 	.idle_idx		= 1,			\
diff --git a/include/asm-ia64/compat.h b/include/asm-ia64/compat.h
index aaf11f4..c0b1910 100644
--- a/include/asm-ia64/compat.h
+++ b/include/asm-ia64/compat.h
@@ -192,7 +192,7 @@
 static __inline__ void __user *
 compat_alloc_user_space (long len)
 {
-	struct pt_regs *regs = ia64_task_regs(current);
+	struct pt_regs *regs = task_pt_regs(current);
 	return (void __user *) (((regs->r12 & 0xffffffff) & -16) - len);
 }
 
diff --git a/include/asm-ia64/ioctl.h b/include/asm-ia64/ioctl.h
index be9cc24..b279fe0 100644
--- a/include/asm-ia64/ioctl.h
+++ b/include/asm-ia64/ioctl.h
@@ -1,77 +1 @@
-#ifndef _ASM_IA64_IOCTL_H
-#define _ASM_IA64_IOCTL_H
-
-/*
- * Based on <asm-i386/ioctl.h>.
- *
- * Modified 1998, 1999
- *	David Mosberger-Tang <davidm@hpl.hp.com>, Hewlett-Packard Co
- */
-
-/* ioctl command encoding: 32 bits total, command in lower 16 bits,
- * size of the parameter structure in the lower 14 bits of the
- * upper 16 bits.
- * Encoding the size of the parameter structure in the ioctl request
- * is useful for catching programs compiled with old versions
- * and to avoid overwriting user space outside the user buffer area.
- * The highest 2 bits are reserved for indicating the ``access mode''.
- * NOTE: This limits the max parameter size to 16kB -1 !
- */
-
-/*
- * The following is for compatibility across the various Linux
- * platforms.  The ia64 ioctl numbering scheme doesn't really enforce
- * a type field.  De facto, however, the top 8 bits of the lower 16
- * bits are indeed used as a type field, so we might just as well make
- * this explicit here.  Please be sure to use the decoding macros
- * below from now on.
- */
-#define _IOC_NRBITS	8
-#define _IOC_TYPEBITS	8
-#define _IOC_SIZEBITS	14
-#define _IOC_DIRBITS	2
-
-#define _IOC_NRMASK	((1 << _IOC_NRBITS)-1)
-#define _IOC_TYPEMASK	((1 << _IOC_TYPEBITS)-1)
-#define _IOC_SIZEMASK	((1 << _IOC_SIZEBITS)-1)
-#define _IOC_DIRMASK	((1 << _IOC_DIRBITS)-1)
-
-#define _IOC_NRSHIFT	0
-#define _IOC_TYPESHIFT	(_IOC_NRSHIFT+_IOC_NRBITS)
-#define _IOC_SIZESHIFT	(_IOC_TYPESHIFT+_IOC_TYPEBITS)
-#define _IOC_DIRSHIFT	(_IOC_SIZESHIFT+_IOC_SIZEBITS)
-
-/*
- * Direction bits.
- */
-#define _IOC_NONE	0U
-#define _IOC_WRITE	1U
-#define _IOC_READ	2U
-
-#define _IOC(dir,type,nr,size) \
-	(((dir)  << _IOC_DIRSHIFT) | \
-	 ((type) << _IOC_TYPESHIFT) | \
-	 ((nr)   << _IOC_NRSHIFT) | \
-	 ((size) << _IOC_SIZESHIFT))
-
-/* used to create numbers */
-#define _IO(type,nr)		_IOC(_IOC_NONE,(type),(nr),0)
-#define _IOR(type,nr,size)	_IOC(_IOC_READ,(type),(nr),sizeof(size))
-#define _IOW(type,nr,size)	_IOC(_IOC_WRITE,(type),(nr),sizeof(size))
-#define _IOWR(type,nr,size)	_IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
-
-/* used to decode ioctl numbers.. */
-#define _IOC_DIR(nr)		(((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
-#define _IOC_TYPE(nr)		(((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
-#define _IOC_NR(nr)		(((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
-#define _IOC_SIZE(nr)		(((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
-
-/* ...and for the drivers/sound files... */
-
-#define IOC_IN		(_IOC_WRITE << _IOC_DIRSHIFT)
-#define IOC_OUT		(_IOC_READ << _IOC_DIRSHIFT)
-#define IOC_INOUT	((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
-#define IOCSIZE_MASK	(_IOC_SIZEMASK << _IOC_SIZESHIFT)
-#define IOCSIZE_SHIFT	(_IOC_SIZESHIFT)
-
-#endif /* _ASM_IA64_IOCTL_H */
+#include <asm-generic/ioctl.h>
diff --git a/include/asm-ia64/kprobes.h b/include/asm-ia64/kprobes.h
index 592abb0..a74b681 100644
--- a/include/asm-ia64/kprobes.h
+++ b/include/asm-ia64/kprobes.h
@@ -89,6 +89,7 @@
 #define IP_RELATIVE_PREDICT_OPCODE	(7)
 #define LONG_BRANCH_OPCODE		(0xC)
 #define LONG_CALL_OPCODE		(0xD)
+#define arch_remove_kprobe(p)		do {} while (0)
 
 typedef struct kprobe_opcode {
 	bundle_t bundle;
@@ -110,12 +111,6 @@
  	unsigned short target_br_reg;
 };
 
-/* ia64 does not need this */
-static inline void arch_copy_kprobe(struct kprobe *p)
-{
-}
-
-#ifdef CONFIG_KPROBES
 extern int kprobe_exceptions_notify(struct notifier_block *self,
 				    unsigned long val, void *data);
 
@@ -124,11 +119,4 @@
 {
 }
 
-#else				/* !CONFIG_KPROBES */
-static inline int kprobe_exceptions_notify(struct notifier_block *self,
-					   unsigned long val, void *data)
-{
-	return 0;
-}
-#endif
 #endif				/* _ASM_KPROBES_H */
diff --git a/include/asm-ia64/processor.h b/include/asm-ia64/processor.h
index 94e07e7..8c648bf 100644
--- a/include/asm-ia64/processor.h
+++ b/include/asm-ia64/processor.h
@@ -352,7 +352,7 @@
 /* Return instruction pointer of blocked task TSK.  */
 #define KSTK_EIP(tsk)					\
   ({							\
-	struct pt_regs *_regs = ia64_task_regs(tsk);	\
+	struct pt_regs *_regs = task_pt_regs(tsk);	\
 	_regs->cr_iip + ia64_psr(_regs)->ri;		\
   })
 
diff --git a/include/asm-ia64/ptrace.h b/include/asm-ia64/ptrace.h
index 2c703d6..9471cdc 100644
--- a/include/asm-ia64/ptrace.h
+++ b/include/asm-ia64/ptrace.h
@@ -248,7 +248,7 @@
 })
 
   /* given a pointer to a task_struct, return the user's pt_regs */
-# define ia64_task_regs(t)		(((struct pt_regs *) ((char *) (t) + IA64_STK_OFFSET)) - 1)
+# define task_pt_regs(t)		(((struct pt_regs *) ((char *) (t) + IA64_STK_OFFSET)) - 1)
 # define ia64_psr(regs)			((struct ia64_psr *) &(regs)->cr_ipsr)
 # define user_mode(regs)		(((struct ia64_psr *) &(regs)->cr_ipsr)->cpl != 0)
 # define user_stack(task,regs)	((long) regs - (long) task == IA64_STK_OFFSET - sizeof(*regs))
@@ -271,7 +271,7 @@
    *
    * On ia64, we can clear the user's pt_regs->r8 to force a successful syscall.
    */
-# define force_successful_syscall_return()	(ia64_task_regs(current)->r8 = 0)
+# define force_successful_syscall_return()	(task_pt_regs(current)->r8 = 0)
 
   struct task_struct;			/* forward decl */
   struct unw_frame_info;		/* forward decl */
diff --git a/include/asm-ia64/system.h b/include/asm-ia64/system.h
index 635235f..80c5a23 100644
--- a/include/asm-ia64/system.h
+++ b/include/asm-ia64/system.h
@@ -219,14 +219,14 @@
 
 #define IA64_HAS_EXTRA_STATE(t)							\
 	((t)->thread.flags & (IA64_THREAD_DBG_VALID|IA64_THREAD_PM_VALID)	\
-	 || IS_IA32_PROCESS(ia64_task_regs(t)) || PERFMON_IS_SYSWIDE())
+	 || IS_IA32_PROCESS(task_pt_regs(t)) || PERFMON_IS_SYSWIDE())
 
 #define __switch_to(prev,next,last) do {							 \
 	if (IA64_HAS_EXTRA_STATE(prev))								 \
 		ia64_save_extra(prev);								 \
 	if (IA64_HAS_EXTRA_STATE(next))								 \
 		ia64_load_extra(next);								 \
-	ia64_psr(ia64_task_regs(next))->dfh = !ia64_is_local_fpu_owner(next);			 \
+	ia64_psr(task_pt_regs(next))->dfh = !ia64_is_local_fpu_owner(next);			 \
 	(last) = ia64_switch_to((next));							 \
 } while (0)
 
@@ -238,8 +238,8 @@
  * the latest fph state from another CPU.  In other words: eager save, lazy restore.
  */
 # define switch_to(prev,next,last) do {						\
-	if (ia64_psr(ia64_task_regs(prev))->mfh && ia64_is_local_fpu_owner(prev)) {				\
-		ia64_psr(ia64_task_regs(prev))->mfh = 0;			\
+	if (ia64_psr(task_pt_regs(prev))->mfh && ia64_is_local_fpu_owner(prev)) {				\
+		ia64_psr(task_pt_regs(prev))->mfh = 0;			\
 		(prev)->thread.flags |= IA64_THREAD_FPH_VALID;			\
 		__ia64_save_fpu((prev)->thread.fph);				\
 	}									\
@@ -279,6 +279,7 @@
 #define ia64_platform_is(x) (strcmp(x, platform_name) == 0)
 
 void cpu_idle_wait(void);
+void sched_cacheflush(void);
 
 #define arch_align_stack(x) (x)
 
diff --git a/include/asm-ia64/thread_info.h b/include/asm-ia64/thread_info.h
index 171b220..653bb7f 100644
--- a/include/asm-ia64/thread_info.h
+++ b/include/asm-ia64/thread_info.h
@@ -57,11 +57,20 @@
 /* how to get the thread information struct from C */
 #define current_thread_info()	((struct thread_info *) ((char *) current + IA64_TASK_SIZE))
 #define alloc_thread_info(tsk)	((struct thread_info *) ((char *) (tsk) + IA64_TASK_SIZE))
+#define task_thread_info(tsk)	((struct thread_info *) ((char *) (tsk) + IA64_TASK_SIZE))
 #else
 #define current_thread_info()	((struct thread_info *) 0)
 #define alloc_thread_info(tsk)	((struct thread_info *) 0)
+#define task_thread_info(tsk)	((struct thread_info *) 0)
 #endif
 #define free_thread_info(ti)	/* nothing */
+#define task_stack_page(tsk)	((void *)(tsk))
+
+#define __HAVE_THREAD_FUNCTIONS
+#define setup_thread_stack(p, org) \
+	*task_thread_info(p) = *task_thread_info(org); \
+	task_thread_info(p)->task = (p);
+#define end_of_stack(p) (unsigned long *)((void *)(p) + IA64_RBS_OFFSET)
 
 #define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
 #define alloc_task_struct()	((task_t *)__get_free_pages(GFP_KERNEL, KERNEL_STACK_SIZE_ORDER))
diff --git a/include/asm-ia64/topology.h b/include/asm-ia64/topology.h
index f7c3304..d8aae4d 100644
--- a/include/asm-ia64/topology.h
+++ b/include/asm-ia64/topology.h
@@ -55,7 +55,6 @@
 	.max_interval		= 4,			\
 	.busy_factor		= 64,			\
 	.imbalance_pct		= 125,			\
-	.cache_hot_time		= (10*1000000),		\
 	.per_cpu_gain		= 100,			\
 	.cache_nice_tries	= 2,			\
 	.busy_idx		= 2,			\
@@ -81,7 +80,6 @@
 	.max_interval		= 8*(min(num_online_cpus(), 32)), \
 	.busy_factor		= 64,			\
 	.imbalance_pct		= 125,			\
-	.cache_hot_time		= (10*1000000),		\
 	.cache_nice_tries	= 2,			\
 	.busy_idx		= 3,			\
 	.idle_idx		= 2,			\
diff --git a/include/asm-m32r/ioctl.h b/include/asm-m32r/ioctl.h
index 87d8f7d..b279fe0 100644
--- a/include/asm-m32r/ioctl.h
+++ b/include/asm-m32r/ioctl.h
@@ -1,78 +1 @@
-#ifndef _ASM_M32R_IOCTL_H
-#define _ASM_M32R_IOCTL_H
-
-/* $Id$ */
-
-/* orig : i386 2.4.18 */
-
-/*
- * linux/ioctl.h for Linux by H.H. Bergman.
- */
-
-/* ioctl command encoding: 32 bits total, command in lower 16 bits,
- * size of the parameter structure in the lower 14 bits of the
- * upper 16 bits.
- * Encoding the size of the parameter structure in the ioctl request
- * is useful for catching programs compiled with old versions
- * and to avoid overwriting user space outside the user buffer area.
- * The highest 2 bits are reserved for indicating the ``access mode''.
- * NOTE: This limits the max parameter size to 16kB -1 !
- */
-
-/*
- * The following is for compatibility across the various Linux
- * platforms.  The i386 ioctl numbering scheme doesn't really enforce
- * a type field.  De facto, however, the top 8 bits of the lower 16
- * bits are indeed used as a type field, so we might just as well make
- * this explicit here.  Please be sure to use the decoding macros
- * below from now on.
- */
-#define _IOC_NRBITS	8
-#define _IOC_TYPEBITS	8
-#define _IOC_SIZEBITS	14
-#define _IOC_DIRBITS	2
-
-#define _IOC_NRMASK	((1 << _IOC_NRBITS)-1)
-#define _IOC_TYPEMASK	((1 << _IOC_TYPEBITS)-1)
-#define _IOC_SIZEMASK	((1 << _IOC_SIZEBITS)-1)
-#define _IOC_DIRMASK	((1 << _IOC_DIRBITS)-1)
-
-#define _IOC_NRSHIFT	0
-#define _IOC_TYPESHIFT	(_IOC_NRSHIFT+_IOC_NRBITS)
-#define _IOC_SIZESHIFT	(_IOC_TYPESHIFT+_IOC_TYPEBITS)
-#define _IOC_DIRSHIFT	(_IOC_SIZESHIFT+_IOC_SIZEBITS)
-
-/*
- * Direction bits.
- */
-#define _IOC_NONE	0U
-#define _IOC_WRITE	1U
-#define _IOC_READ	2U
-
-#define _IOC(dir,type,nr,size) \
-	(((dir)  << _IOC_DIRSHIFT) | \
-	 ((type) << _IOC_TYPESHIFT) | \
-	 ((nr)   << _IOC_NRSHIFT) | \
-	 ((size) << _IOC_SIZESHIFT))
-
-/* used to create numbers */
-#define _IO(type,nr)		_IOC(_IOC_NONE,(type),(nr),0)
-#define _IOR(type,nr,size)	_IOC(_IOC_READ,(type),(nr),sizeof(size))
-#define _IOW(type,nr,size)	_IOC(_IOC_WRITE,(type),(nr),sizeof(size))
-#define _IOWR(type,nr,size)	_IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
-
-/* used to decode ioctl numbers.. */
-#define _IOC_DIR(nr)		(((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
-#define _IOC_TYPE(nr)		(((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
-#define _IOC_NR(nr)		(((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
-#define _IOC_SIZE(nr)		(((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
-
-/* ...and for the drivers/sound files... */
-
-#define IOC_IN		(_IOC_WRITE << _IOC_DIRSHIFT)
-#define IOC_OUT		(_IOC_READ << _IOC_DIRSHIFT)
-#define IOC_INOUT	((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
-#define IOCSIZE_MASK	(_IOC_SIZEMASK << _IOC_SIZESHIFT)
-#define IOCSIZE_SHIFT	(_IOC_SIZESHIFT)
-
-#endif /* _ASM_M32R_IOCTL_H */
+#include <asm-generic/ioctl.h>
diff --git a/include/asm-m32r/ptrace.h b/include/asm-m32r/ptrace.h
index 55cd7ec..0d058b2 100644
--- a/include/asm-m32r/ptrace.h
+++ b/include/asm-m32r/ptrace.h
@@ -163,6 +163,9 @@
 
 extern void withdraw_debug_trap(struct pt_regs *regs);
 
+#define task_pt_regs(task) \
+        ((struct pt_regs *)(task_stack_page(task) + THREAD_SIZE) - 1)
+
 #endif /* __KERNEL */
 
 #endif /* _ASM_M32R_PTRACE_H */
diff --git a/include/asm-m32r/system.h b/include/asm-m32r/system.h
index dcf619a..06c12a0 100644
--- a/include/asm-m32r/system.h
+++ b/include/asm-m32r/system.h
@@ -68,6 +68,16 @@
 	last = __last; \
 } while(0)
 
+/*
+ * On SMP systems, when the scheduler does migration-cost autodetection,
+ * it needs a way to flush as much of the CPU's caches as possible.
+ *
+ * TODO: fill this in!
+ */
+static inline void sched_cacheflush(void)
+{
+}
+
 /* Interrupt Control */
 #if !defined(CONFIG_CHIP_M32102) && !defined(CONFIG_CHIP_M32104)
 #define local_irq_enable() \
diff --git a/include/asm-m32r/thread_info.h b/include/asm-m32r/thread_info.h
index 0f58936..22aff32 100644
--- a/include/asm-m32r/thread_info.h
+++ b/include/asm-m32r/thread_info.h
@@ -110,8 +110,6 @@
 #endif
 
 #define free_thread_info(info) kfree(info)
-#define get_thread_info(ti) get_task_struct((ti)->task)
-#define put_thread_info(ti) put_task_struct((ti)->task)
 
 #define TI_FLAG_FAULT_CODE_SHIFT	28
 
diff --git a/include/asm-m68k/amigahw.h b/include/asm-m68k/amigahw.h
index 3ae5d8d..a16fe4e 100644
--- a/include/asm-m68k/amigahw.h
+++ b/include/asm-m68k/amigahw.h
@@ -274,7 +274,7 @@
 #define ZTWO_VADDR(x) (((unsigned long)(x))+zTwoBase)
 
 #define CUSTOM_PHYSADDR     (0xdff000)
-#define custom ((*(volatile struct CUSTOM *)(zTwoBase+CUSTOM_PHYSADDR)))
+#define amiga_custom ((*(volatile struct CUSTOM *)(zTwoBase+CUSTOM_PHYSADDR)))
 
 #define CIAA_PHYSADDR	  (0xbfe001)
 #define CIAB_PHYSADDR	  (0xbfd000)
@@ -294,12 +294,12 @@
 {
 	if (amiga_chipset == CS_ECS || amiga_chipset == CS_AGA) {
 		/* program Denise/Lisa for a higher maximum play rate */
-		custom.htotal = 113;        /* 31 kHz */
-		custom.vtotal = 223;        /* 70 Hz */
-		custom.beamcon0 = 0x4390;   /* HARDDIS, VAR{BEAM,VSY,HSY,CSY}EN */
+		amiga_custom.htotal = 113;        /* 31 kHz */
+		amiga_custom.vtotal = 223;        /* 70 Hz */
+		amiga_custom.beamcon0 = 0x4390;   /* HARDDIS, VAR{BEAM,VSY,HSY,CSY}EN */
 		/* suspend the monitor */
-		custom.hsstrt = custom.hsstop = 116;
-		custom.vsstrt = custom.vsstop = 226;
+		amiga_custom.hsstrt = amiga_custom.hsstop = 116;
+		amiga_custom.vsstrt = amiga_custom.vsstop = 226;
 		amiga_audio_min_period = 57;
 	}
 }
diff --git a/include/asm-m68k/amigaints.h b/include/asm-m68k/amigaints.h
index 2aff4cf..aa968d0 100644
--- a/include/asm-m68k/amigaints.h
+++ b/include/asm-m68k/amigaints.h
@@ -109,8 +109,6 @@
 extern void amiga_do_irq(int irq, struct pt_regs *fp);
 extern void amiga_do_irq_list(int irq, struct pt_regs *fp);
 
-extern unsigned short amiga_intena_vals[];
-
 /* CIA interrupt control register bits */
 
 #define CIA_ICR_TA	0x01
diff --git a/include/asm-m68k/checksum.h b/include/asm-m68k/checksum.h
index 78860c2..17280ef 100644
--- a/include/asm-m68k/checksum.h
+++ b/include/asm-m68k/checksum.h
@@ -25,7 +25,7 @@
  * better 64-bit) boundary
  */
 
-extern unsigned int csum_partial_copy_from_user(const unsigned char *src,
+extern unsigned int csum_partial_copy_from_user(const unsigned char __user *src,
 						unsigned char *dst,
 						int len, int sum,
 						int *csum_err);
diff --git a/include/asm-m68k/dsp56k.h b/include/asm-m68k/dsp56k.h
index ab3dd33..2d8c0c9 100644
--- a/include/asm-m68k/dsp56k.h
+++ b/include/asm-m68k/dsp56k.h
@@ -13,7 +13,7 @@
 /* Used for uploading DSP binary code */
 struct dsp56k_upload {
 	int len;
-	char *bin;
+	char __user *bin;
 };
 
 /* For the DSP host flags */
diff --git a/include/asm-m68k/floppy.h b/include/asm-m68k/floppy.h
index c6e708d..63a05ed 100644
--- a/include/asm-m68k/floppy.h
+++ b/include/asm-m68k/floppy.h
@@ -46,7 +46,7 @@
 
 static int virtual_dma_count=0;
 static int virtual_dma_residue=0;
-static char *virtual_dma_addr=0;
+static char *virtual_dma_addr=NULL;
 static int virtual_dma_mode=0;
 static int doing_pdma=0;
 
diff --git a/include/asm-m68k/hardirq.h b/include/asm-m68k/hardirq.h
index 728318b..5e1c5826 100644
--- a/include/asm-m68k/hardirq.h
+++ b/include/asm-m68k/hardirq.h
@@ -14,13 +14,4 @@
 
 #define HARDIRQ_BITS	8
 
-/*
- * The hardirq mask has to be large enough to have
- * space for potentially all IRQ sources in the system
- * nesting on a single CPU:
- */
-#if (1 << HARDIRQ_BITS) < NR_IRQS
-# error HARDIRQ_BITS is too low!
-#endif
-
 #endif
diff --git a/include/asm-m68k/io.h b/include/asm-m68k/io.h
index 6bb8b0d..dcfaa35 100644
--- a/include/asm-m68k/io.h
+++ b/include/asm-m68k/io.h
@@ -24,6 +24,7 @@
 #ifdef __KERNEL__
 
 #include <linux/config.h>
+#include <linux/compiler.h>
 #include <asm/raw_io.h>
 #include <asm/virtconvert.h>
 
@@ -120,68 +121,68 @@
  * be compiled in so the case statement will be optimised away
  */
 
-static inline u8 *isa_itb(unsigned long addr)
+static inline u8 __iomem *isa_itb(unsigned long addr)
 {
   switch(ISA_TYPE)
     {
 #ifdef CONFIG_Q40
-    case Q40_ISA: return (u8 *)Q40_ISA_IO_B(addr);
+    case Q40_ISA: return (u8 __iomem *)Q40_ISA_IO_B(addr);
 #endif
 #ifdef CONFIG_GG2
-    case GG2_ISA: return (u8 *)GG2_ISA_IO_B(addr);
+    case GG2_ISA: return (u8 __iomem *)GG2_ISA_IO_B(addr);
 #endif
 #ifdef CONFIG_AMIGA_PCMCIA
-    case AG_ISA: return (u8 *)AG_ISA_IO_B(addr);
+    case AG_ISA: return (u8 __iomem *)AG_ISA_IO_B(addr);
 #endif
-    default: return 0; /* avoid warnings, just in case */
+    default: return NULL; /* avoid warnings, just in case */
     }
 }
-static inline u16 *isa_itw(unsigned long addr)
+static inline u16 __iomem *isa_itw(unsigned long addr)
 {
   switch(ISA_TYPE)
     {
 #ifdef CONFIG_Q40
-    case Q40_ISA: return (u16 *)Q40_ISA_IO_W(addr);
+    case Q40_ISA: return (u16 __iomem *)Q40_ISA_IO_W(addr);
 #endif
 #ifdef CONFIG_GG2
-    case GG2_ISA: return (u16 *)GG2_ISA_IO_W(addr);
+    case GG2_ISA: return (u16 __iomem *)GG2_ISA_IO_W(addr);
 #endif
 #ifdef CONFIG_AMIGA_PCMCIA
-    case AG_ISA: return (u16 *)AG_ISA_IO_W(addr);
+    case AG_ISA: return (u16 __iomem *)AG_ISA_IO_W(addr);
 #endif
-    default: return 0; /* avoid warnings, just in case */
+    default: return NULL; /* avoid warnings, just in case */
     }
 }
-static inline u8 *isa_mtb(unsigned long addr)
+static inline u8 __iomem *isa_mtb(unsigned long addr)
 {
   switch(ISA_TYPE)
     {
 #ifdef CONFIG_Q40
-    case Q40_ISA: return (u8 *)Q40_ISA_MEM_B(addr);
+    case Q40_ISA: return (u8 __iomem *)Q40_ISA_MEM_B(addr);
 #endif
 #ifdef CONFIG_GG2
-    case GG2_ISA: return (u8 *)GG2_ISA_MEM_B(addr);
+    case GG2_ISA: return (u8 __iomem *)GG2_ISA_MEM_B(addr);
 #endif
 #ifdef CONFIG_AMIGA_PCMCIA
-    case AG_ISA: return (u8 *)addr;
+    case AG_ISA: return (u8 __iomem *)addr;
 #endif
-    default: return 0; /* avoid warnings, just in case */
+    default: return NULL; /* avoid warnings, just in case */
     }
 }
-static inline u16 *isa_mtw(unsigned long addr)
+static inline u16 __iomem *isa_mtw(unsigned long addr)
 {
   switch(ISA_TYPE)
     {
 #ifdef CONFIG_Q40
-    case Q40_ISA: return (u16 *)Q40_ISA_MEM_W(addr);
+    case Q40_ISA: return (u16 __iomem *)Q40_ISA_MEM_W(addr);
 #endif
 #ifdef CONFIG_GG2
-    case GG2_ISA: return (u16 *)GG2_ISA_MEM_W(addr);
+    case GG2_ISA: return (u16 __iomem *)GG2_ISA_MEM_W(addr);
 #endif
 #ifdef CONFIG_AMIGA_PCMCIA
-    case AG_ISA: return (u16 *)addr;
+    case AG_ISA: return (u16 __iomem *)addr;
 #endif
-    default: return 0; /* avoid warnings, just in case */
+    default: return NULL; /* avoid warnings, just in case */
     }
 }
 
@@ -326,20 +327,20 @@
 
 #define mmiowb()
 
-static inline void *ioremap(unsigned long physaddr, unsigned long size)
+static inline void __iomem *ioremap(unsigned long physaddr, unsigned long size)
 {
 	return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
 }
-static inline void *ioremap_nocache(unsigned long physaddr, unsigned long size)
+static inline void __iomem *ioremap_nocache(unsigned long physaddr, unsigned long size)
 {
 	return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
 }
-static inline void *ioremap_writethrough(unsigned long physaddr,
+static inline void __iomem *ioremap_writethrough(unsigned long physaddr,
 					 unsigned long size)
 {
 	return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
 }
-static inline void *ioremap_fullcache(unsigned long physaddr,
+static inline void __iomem *ioremap_fullcache(unsigned long physaddr,
 				      unsigned long size)
 {
 	return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
diff --git a/include/asm-m68k/ioctl.h b/include/asm-m68k/ioctl.h
index fd68914..b279fe0 100644
--- a/include/asm-m68k/ioctl.h
+++ b/include/asm-m68k/ioctl.h
@@ -1,80 +1 @@
-/* $Id: ioctl.h,v 1.3 1997/04/16 15:10:07 jes Exp $
- *
- * linux/ioctl.h for Linux by H.H. Bergman.
- */
-
-#ifndef _M68K_IOCTL_H
-#define _M68K_IOCTL_H
-
-/* ioctl command encoding: 32 bits total, command in lower 16 bits,
- * size of the parameter structure in the lower 14 bits of the
- * upper 16 bits.
- * Encoding the size of the parameter structure in the ioctl request
- * is useful for catching programs compiled with old versions
- * and to avoid overwriting user space outside the user buffer area.
- * The highest 2 bits are reserved for indicating the ``access mode''.
- * NOTE: This limits the max parameter size to 16kB -1 !
- */
-
-/*
- * I don't really have any idea about what this should look like, so
- * for the time being, this is heavily based on the PC definitions.
- */
-
-/*
- * The following is for compatibility across the various Linux
- * platforms.  The i386 ioctl numbering scheme doesn't really enforce
- * a type field.  De facto, however, the top 8 bits of the lower 16
- * bits are indeed used as a type field, so we might just as well make
- * this explicit here.  Please be sure to use the decoding macros
- * below from now on.
- */
-#define _IOC_NRBITS	8
-#define _IOC_TYPEBITS	8
-#define _IOC_SIZEBITS	14
-#define _IOC_DIRBITS	2
-
-#define _IOC_NRMASK	((1 << _IOC_NRBITS)-1)
-#define _IOC_TYPEMASK	((1 << _IOC_TYPEBITS)-1)
-#define _IOC_SIZEMASK	((1 << _IOC_SIZEBITS)-1)
-#define _IOC_DIRMASK	((1 << _IOC_DIRBITS)-1)
-
-#define _IOC_NRSHIFT	0
-#define _IOC_TYPESHIFT	(_IOC_NRSHIFT+_IOC_NRBITS)
-#define _IOC_SIZESHIFT	(_IOC_TYPESHIFT+_IOC_TYPEBITS)
-#define _IOC_DIRSHIFT	(_IOC_SIZESHIFT+_IOC_SIZEBITS)
-
-/*
- * Direction bits.
- */
-#define _IOC_NONE	0U
-#define _IOC_WRITE	1U
-#define _IOC_READ	2U
-
-#define _IOC(dir,type,nr,size) \
-	(((dir)  << _IOC_DIRSHIFT) | \
-	 ((type) << _IOC_TYPESHIFT) | \
-	 ((nr)   << _IOC_NRSHIFT) | \
-	 ((size) << _IOC_SIZESHIFT))
-
-/* used to create numbers */
-#define _IO(type,nr)		_IOC(_IOC_NONE,(type),(nr),0)
-#define _IOR(type,nr,size)	_IOC(_IOC_READ,(type),(nr),sizeof(size))
-#define _IOW(type,nr,size)	_IOC(_IOC_WRITE,(type),(nr),sizeof(size))
-#define _IOWR(type,nr,size)	_IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
-
-/* used to decode ioctl numbers.. */
-#define _IOC_DIR(nr)		(((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
-#define _IOC_TYPE(nr)		(((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
-#define _IOC_NR(nr)		(((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
-#define _IOC_SIZE(nr)		(((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
-
-/* ...and for the drivers/sound files... */
-
-#define IOC_IN		(_IOC_WRITE << _IOC_DIRSHIFT)
-#define IOC_OUT		(_IOC_READ << _IOC_DIRSHIFT)
-#define IOC_INOUT	((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
-#define IOCSIZE_MASK	(_IOC_SIZEMASK << _IOC_SIZESHIFT)
-#define IOCSIZE_SHIFT	(_IOC_SIZESHIFT)
-
-#endif /* _M68K_IOCTL_H */
+#include <asm-generic/ioctl.h>
diff --git a/include/asm-m68k/irq.h b/include/asm-m68k/irq.h
index 127ad19..325c86f 100644
--- a/include/asm-m68k/irq.h
+++ b/include/asm-m68k/irq.h
@@ -23,6 +23,15 @@
 #endif
 
 /*
+ * The hardirq mask has to be large enough to have
+ * space for potentially all IRQ sources in the system
+ * nesting on a single CPU:
+ */
+#if (1 << HARDIRQ_BITS) < NR_IRQS
+# error HARDIRQ_BITS is too low!
+#endif
+
+/*
  * Interrupt source definitions
  * General interrupt sources are the level 1-7.
  * Adding an interrupt service routine for one of these sources
diff --git a/include/asm-m68k/machdep.h b/include/asm-m68k/machdep.h
index a0dd5c4..7d3fee3 100644
--- a/include/asm-m68k/machdep.h
+++ b/include/asm-m68k/machdep.h
@@ -34,7 +34,6 @@
 extern unsigned long (*mach_hd_init) (unsigned long, unsigned long);
 extern void (*mach_hd_setup)(char *, int *);
 extern long mach_max_dma_address;
-extern void (*mach_floppy_setup)(char *, int *);
 extern void (*mach_heartbeat) (int);
 extern void (*mach_l2_flush) (int);
 extern void (*mach_beep) (unsigned int, unsigned int);
diff --git a/include/asm-m68k/raw_io.h b/include/asm-m68k/raw_io.h
index 041f0a8..5439bca 100644
--- a/include/asm-m68k/raw_io.h
+++ b/include/asm-m68k/raw_io.h
@@ -19,9 +19,9 @@
 #define IOMAP_NOCACHE_NONSER		2
 #define IOMAP_WRITETHROUGH		3
 
-extern void iounmap(void *addr);
+extern void iounmap(void __iomem *addr);
 
-extern void *__ioremap(unsigned long physaddr, unsigned long size,
+extern void __iomem *__ioremap(unsigned long physaddr, unsigned long size,
 		       int cacheflag);
 extern void __iounmap(void *addr, unsigned long size);
 
@@ -30,21 +30,21 @@
  * two accesses to memory, which may be undesirable for some devices.
  */
 #define in_8(addr) \
-    ({ u8 __v = (*(volatile u8 *) (addr)); __v; })
+    ({ u8 __v = (*(__force volatile u8 *) (addr)); __v; })
 #define in_be16(addr) \
-    ({ u16 __v = (*(volatile u16 *) (addr)); __v; })
+    ({ u16 __v = (*(__force volatile u16 *) (addr)); __v; })
 #define in_be32(addr) \
-    ({ u32 __v = (*(volatile u32 *) (addr)); __v; })
+    ({ u32 __v = (*(__force volatile u32 *) (addr)); __v; })
 #define in_le16(addr) \
-    ({ u16 __v = le16_to_cpu(*(volatile u16 *) (addr)); __v; })
+    ({ u16 __v = le16_to_cpu(*(__force volatile u16 *) (addr)); __v; })
 #define in_le32(addr) \
-    ({ u32 __v = le32_to_cpu(*(volatile u32 *) (addr)); __v; })
+    ({ u32 __v = le32_to_cpu(*(__force volatile u32 *) (addr)); __v; })
 
-#define out_8(addr,b) (void)((*(volatile u8 *) (addr)) = (b))
-#define out_be16(addr,w) (void)((*(volatile u16 *) (addr)) = (w))
-#define out_be32(addr,l) (void)((*(volatile u32 *) (addr)) = (l))
-#define out_le16(addr,w) (void)((*(volatile u16 *) (addr)) = cpu_to_le16(w))
-#define out_le32(addr,l) (void)((*(volatile u32 *) (addr)) = cpu_to_le32(l))
+#define out_8(addr,b) (void)((*(__force volatile u8 *) (addr)) = (b))
+#define out_be16(addr,w) (void)((*(__force volatile u16 *) (addr)) = (w))
+#define out_be32(addr,l) (void)((*(__force volatile u32 *) (addr)) = (l))
+#define out_le16(addr,w) (void)((*(__force volatile u16 *) (addr)) = cpu_to_le16(w))
+#define out_le32(addr,l) (void)((*(__force volatile u32 *) (addr)) = cpu_to_le32(l))
 
 #define raw_inb in_8
 #define raw_inw in_be16
@@ -54,7 +54,7 @@
 #define raw_outw(val,port) out_be16((port),(val))
 #define raw_outl(val,port) out_be32((port),(val))
 
-static inline void raw_insb(volatile u8 *port, u8 *buf, unsigned int len)
+static inline void raw_insb(volatile u8 __iomem *port, u8 *buf, unsigned int len)
 {
 	unsigned int i;
 
@@ -62,7 +62,7 @@
 		*buf++ = in_8(port);
 }
 
-static inline void raw_outsb(volatile u8 *port, const u8 *buf,
+static inline void raw_outsb(volatile u8 __iomem *port, const u8 *buf,
 			     unsigned int len)
 {
 	unsigned int i;
@@ -71,7 +71,7 @@
 		out_8(port, *buf++);
 }
 
-static inline void raw_insw(volatile u16 *port, u16 *buf, unsigned int nr)
+static inline void raw_insw(volatile u16 __iomem *port, u16 *buf, unsigned int nr)
 {
 	unsigned int tmp;
 
@@ -110,7 +110,7 @@
 	}
 }
 
-static inline void raw_outsw(volatile u16 *port, const u16 *buf,
+static inline void raw_outsw(volatile u16 __iomem *port, const u16 *buf,
 			     unsigned int nr)
 {
 	unsigned int tmp;
@@ -150,7 +150,7 @@
 	}
 }
 
-static inline void raw_insl(volatile u32 *port, u32 *buf, unsigned int nr)
+static inline void raw_insl(volatile u32 __iomem *port, u32 *buf, unsigned int nr)
 {
 	unsigned int tmp;
 
@@ -189,7 +189,7 @@
 	}
 }
 
-static inline void raw_outsl(volatile u32 *port, const u32 *buf,
+static inline void raw_outsl(volatile u32 __iomem *port, const u32 *buf,
 			     unsigned int nr)
 {
 	unsigned int tmp;
@@ -230,7 +230,7 @@
 }
 
 
-static inline void raw_insw_swapw(volatile u16 *port, u16 *buf,
+static inline void raw_insw_swapw(volatile u16 __iomem *port, u16 *buf,
 				  unsigned int nr)
 {
     if ((nr) % 8)
@@ -283,7 +283,7 @@
 		: "d0", "a0", "a1", "d6");
 }
 
-static inline void raw_outsw_swapw(volatile u16 *port, const u16 *buf,
+static inline void raw_outsw_swapw(volatile u16 __iomem *port, const u16 *buf,
 				   unsigned int nr)
 {
     if ((nr) % 8)
diff --git a/include/asm-m68k/signal.h b/include/asm-m68k/signal.h
index a0cdf90..b7b7ea2 100644
--- a/include/asm-m68k/signal.h
+++ b/include/asm-m68k/signal.h
@@ -144,7 +144,7 @@
 #endif /* __KERNEL__ */
 
 typedef struct sigaltstack {
-	void *ss_sp;
+	void __user *ss_sp;
 	int ss_flags;
 	size_t ss_size;
 } stack_t;
diff --git a/include/asm-m68k/sun3_pgtable.h b/include/asm-m68k/sun3_pgtable.h
index e974bb0..5156a28 100644
--- a/include/asm-m68k/sun3_pgtable.h
+++ b/include/asm-m68k/sun3_pgtable.h
@@ -211,7 +211,7 @@
 	return pte.pte & SUN3_PAGE_PGNUM_MASK;
 }
 
-static inline pte_t pgoff_to_pte(inline unsigned off)
+static inline pte_t pgoff_to_pte(unsigned off)
 {
 	pte_t pte = { off + SUN3_PAGE_ACCESSED };
 	return pte;
diff --git a/include/asm-m68k/sun3ints.h b/include/asm-m68k/sun3ints.h
index fd838eb..bd038fc 100644
--- a/include/asm-m68k/sun3ints.h
+++ b/include/asm-m68k/sun3ints.h
@@ -31,7 +31,6 @@
 		    );
 extern void sun3_init_IRQ (void);
 extern irqreturn_t (*sun3_default_handler[]) (int, void *, struct pt_regs *);
-extern irqreturn_t (*sun3_inthandler[]) (int, void *, struct pt_regs *);
 extern void sun3_free_irq (unsigned int irq, void *dev_id);
 extern void sun3_enable_interrupts (void);
 extern void sun3_disable_interrupts (void);
diff --git a/include/asm-m68k/sun3xflop.h b/include/asm-m68k/sun3xflop.h
index fda1ecc..98a9f79 100644
--- a/include/asm-m68k/sun3xflop.h
+++ b/include/asm-m68k/sun3xflop.h
@@ -208,7 +208,7 @@
 
 	if(!once) {
 		once = 1;
-		error = request_irq(FLOPPY_IRQ, sun3xflop_hardint, SA_INTERRUPT, "floppy", 0);
+		error = request_irq(FLOPPY_IRQ, sun3xflop_hardint, SA_INTERRUPT, "floppy", NULL);
 		return ((error == 0) ? 0 : -1);
 	} else return 0;
 }
@@ -238,7 +238,7 @@
 	*sun3x_fdc.fcr_r = 0;
 
 	/* Success... */
-	floppy_set_flags(0, 1, FD_BROKEN_DCL); // I don't know how to detect this.
+	floppy_set_flags(NULL, 1, FD_BROKEN_DCL); // I don't know how to detect this.
 	allowed_drive_mask = 0x01;
 	return (int) SUN3X_FDC;
 }
diff --git a/include/asm-m68k/thread_info.h b/include/asm-m68k/thread_info.h
index 9532ca3..c4d622a 100644
--- a/include/asm-m68k/thread_info.h
+++ b/include/asm-m68k/thread_info.h
@@ -37,6 +37,7 @@
 #define init_stack		(init_thread_union.stack)
 
 #define task_thread_info(tsk)	(&(tsk)->thread.info)
+#define task_stack_page(tsk)	((void *)(tsk)->thread_info)
 #define current_thread_info()	task_thread_info(current)
 
 #define __HAVE_THREAD_FUNCTIONS
diff --git a/include/asm-m68k/uaccess.h b/include/asm-m68k/uaccess.h
index f5cedf1..2ffd87b 100644
--- a/include/asm-m68k/uaccess.h
+++ b/include/asm-m68k/uaccess.h
@@ -42,6 +42,7 @@
 ({							\
     int __pu_err;					\
     typeof(*(ptr)) __pu_val = (x);			\
+    __chk_user_ptr(ptr);				\
     switch (sizeof (*(ptr))) {				\
     case 1:						\
 	__put_user_asm(__pu_err, __pu_val, ptr, b);	\
@@ -91,6 +92,7 @@
 ({								\
     int __gu_err;						\
     typeof(*(ptr)) __gu_val;					\
+    __chk_user_ptr(ptr);					\
     switch (sizeof(*(ptr))) {					\
     case 1:							\
 	__get_user_asm(__gu_err, __gu_val, ptr, b, "=d");	\
@@ -105,7 +107,7 @@
         __gu_err = __constant_copy_from_user(&__gu_val, ptr, 8);  \
         break;                                                  \
     default:							\
-	__gu_val = 0;						\
+	__gu_val = (typeof(*(ptr)))0;				\
 	__gu_err = __get_user_bad();				\
 	break;							\
     }								\
@@ -134,7 +136,7 @@
      : "m"(*(ptr)), "i" (-EFAULT), "0"(0))
 
 static inline unsigned long
-__generic_copy_from_user(void *to, const void *from, unsigned long n)
+__generic_copy_from_user(void *to, const void __user *from, unsigned long n)
 {
     unsigned long tmp;
     __asm__ __volatile__
@@ -189,7 +191,7 @@
 }
 
 static inline unsigned long
-__generic_copy_to_user(void *to, const void *from, unsigned long n)
+__generic_copy_to_user(void __user *to, const void *from, unsigned long n)
 {
     unsigned long tmp;
     __asm__ __volatile__
@@ -264,7 +266,7 @@
 	 : "d0", "memory")
 
 static inline unsigned long
-__constant_copy_from_user(void *to, const void *from, unsigned long n)
+__constant_copy_from_user(void *to, const void __user *from, unsigned long n)
 {
     switch (n) {
     case 0:
@@ -520,7 +522,7 @@
 #define __copy_from_user_inatomic __copy_from_user
 
 static inline unsigned long
-__constant_copy_to_user(void *to, const void *from, unsigned long n)
+__constant_copy_to_user(void __user *to, const void *from, unsigned long n)
 {
     switch (n) {
     case 0:
@@ -766,7 +768,7 @@
  */
 
 static inline long
-strncpy_from_user(char *dst, const char *src, long count)
+strncpy_from_user(char *dst, const char __user *src, long count)
 {
     long res;
     if (count == 0) return count;
@@ -799,11 +801,11 @@
  *
  * Return 0 on exception, a value greater than N if too long
  */
-static inline long strnlen_user(const char *src, long n)
+static inline long strnlen_user(const char __user *src, long n)
 {
 	long res;
 
-	res = -(long)src;
+	res = -(unsigned long)src;
 	__asm__ __volatile__
 		("1:\n"
 		 "   tstl %2\n"
@@ -842,7 +844,7 @@
  */
 
 static inline unsigned long
-clear_user(void *to, unsigned long n)
+clear_user(void __user *to, unsigned long n)
 {
     __asm__ __volatile__
 	("   tstl %1\n"
diff --git a/include/asm-m68k/zorro.h b/include/asm-m68k/zorro.h
index cf81658..5ce97c2 100644
--- a/include/asm-m68k/zorro.h
+++ b/include/asm-m68k/zorro.h
@@ -15,24 +15,24 @@
 #define z_memcpy_fromio(a,b,c)	memcpy((a),(void *)(b),(c))
 #define z_memcpy_toio(a,b,c)	memcpy((void *)(a),(b),(c))
 
-static inline void *z_remap_nocache_ser(unsigned long physaddr,
+static inline void __iomem *z_remap_nocache_ser(unsigned long physaddr,
 					unsigned long size)
 {
 	return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
 }
 
-static inline void *z_remap_nocache_nonser(unsigned long physaddr,
+static inline void __iomem *z_remap_nocache_nonser(unsigned long physaddr,
 					   unsigned long size)
 {
 	return __ioremap(physaddr, size, IOMAP_NOCACHE_NONSER);
 }
 
-static inline void *z_remap_writethrough(unsigned long physaddr,
+static inline void __iomem *z_remap_writethrough(unsigned long physaddr,
 					 unsigned long size)
 {
 	return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
 }
-static inline void *z_remap_fullcache(unsigned long physaddr,
+static inline void __iomem *z_remap_fullcache(unsigned long physaddr,
 				      unsigned long size)
 {
 	return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
diff --git a/include/asm-m68knommu/bitops.h b/include/asm-m68knommu/bitops.h
index 4058dd0..25d8a3c 100644
--- a/include/asm-m68knommu/bitops.h
+++ b/include/asm-m68knommu/bitops.h
@@ -290,7 +290,7 @@
 	tmp = *p;
 
 found_first:
-	tmp |= ~0UL >> size;
+	tmp |= ~0UL << size;
 found_middle:
 	return result + ffz(tmp);
 }
diff --git a/include/asm-m68knommu/ioctl.h b/include/asm-m68knommu/ioctl.h
index cff72f3..b279fe0 100644
--- a/include/asm-m68knommu/ioctl.h
+++ b/include/asm-m68knommu/ioctl.h
@@ -1 +1 @@
-#include <asm-m68k/ioctl.h>
+#include <asm-generic/ioctl.h>
diff --git a/include/asm-m68knommu/machdep.h b/include/asm-m68knommu/machdep.h
index 5a9f9c29..27c90af 100644
--- a/include/asm-m68knommu/machdep.h
+++ b/include/asm-m68knommu/machdep.h
@@ -38,7 +38,6 @@
 extern unsigned long (*mach_hd_init) (unsigned long, unsigned long);
 extern void (*mach_hd_setup)(char *, int *);
 extern long mach_max_dma_address;
-extern void (*mach_floppy_setup)(char *, int *);
 extern void (*mach_floppy_eject)(void);
 extern void (*mach_heartbeat) (int);
 extern void (*mach_l2_flush) (int);
diff --git a/include/asm-m68knommu/sigcontext.h b/include/asm-m68knommu/sigcontext.h
index 84bf36d..36c293f 100644
--- a/include/asm-m68knommu/sigcontext.h
+++ b/include/asm-m68knommu/sigcontext.h
@@ -8,6 +8,7 @@
 	unsigned long  sc_d1;
 	unsigned long  sc_a0;
 	unsigned long  sc_a1;
+	unsigned long  sc_a5;
 	unsigned short sc_sr;
 	unsigned long  sc_pc;
 	unsigned short sc_formatvec;
diff --git a/include/asm-m68knommu/thread_info.h b/include/asm-m68knommu/thread_info.h
index 7b9a3fa..b8f009e 100644
--- a/include/asm-m68knommu/thread_info.h
+++ b/include/asm-m68knommu/thread_info.h
@@ -75,8 +75,6 @@
 #define alloc_thread_info(tsk) ((struct thread_info *) \
 				__get_free_pages(GFP_KERNEL, THREAD_SIZE_ORDER))
 #define free_thread_info(ti)	free_pages((unsigned long) (ti), THREAD_SIZE_ORDER)
-#define get_thread_info(ti)	get_task_struct((ti)->task)
-#define put_thread_info(ti)	put_task_struct((ti)->task)
 #endif /* __ASSEMBLY__ */
 
 #define	PREEMPT_ACTIVE	0x4000000
diff --git a/include/asm-mips/atomic.h b/include/asm-mips/atomic.h
index 94a9587..654b97d 100644
--- a/include/asm-mips/atomic.h
+++ b/include/asm-mips/atomic.h
@@ -24,10 +24,9 @@
 #define _ASM_ATOMIC_H
 
 #include <asm/cpu-features.h>
+#include <asm/interrupt.h>
 #include <asm/war.h>
 
-extern spinlock_t atomic_lock;
-
 typedef struct { volatile int counter; } atomic_t;
 
 #define ATOMIC_INIT(i)    { (i) }
@@ -85,9 +84,9 @@
 	} else {
 		unsigned long flags;
 
-		spin_lock_irqsave(&atomic_lock, flags);
+		local_irq_save(flags);
 		v->counter += i;
-		spin_unlock_irqrestore(&atomic_lock, flags);
+		local_irq_restore(flags);
 	}
 }
 
@@ -127,9 +126,9 @@
 	} else {
 		unsigned long flags;
 
-		spin_lock_irqsave(&atomic_lock, flags);
+		local_irq_save(flags);
 		v->counter -= i;
-		spin_unlock_irqrestore(&atomic_lock, flags);
+		local_irq_restore(flags);
 	}
 }
 
@@ -173,11 +172,11 @@
 	} else {
 		unsigned long flags;
 
-		spin_lock_irqsave(&atomic_lock, flags);
+		local_irq_save(flags);
 		result = v->counter;
 		result += i;
 		v->counter = result;
-		spin_unlock_irqrestore(&atomic_lock, flags);
+		local_irq_restore(flags);
 	}
 
 	return result;
@@ -220,11 +219,11 @@
 	} else {
 		unsigned long flags;
 
-		spin_lock_irqsave(&atomic_lock, flags);
+		local_irq_save(flags);
 		result = v->counter;
 		result -= i;
 		v->counter = result;
-		spin_unlock_irqrestore(&atomic_lock, flags);
+		local_irq_restore(flags);
 	}
 
 	return result;
@@ -277,12 +276,12 @@
 	} else {
 		unsigned long flags;
 
-		spin_lock_irqsave(&atomic_lock, flags);
+		local_irq_save(flags);
 		result = v->counter;
 		result -= i;
 		if (result >= 0)
 			v->counter = result;
-		spin_unlock_irqrestore(&atomic_lock, flags);
+		local_irq_restore(flags);
 	}
 
 	return result;
@@ -433,9 +432,9 @@
 	} else {
 		unsigned long flags;
 
-		spin_lock_irqsave(&atomic_lock, flags);
+		local_irq_save(flags);
 		v->counter += i;
-		spin_unlock_irqrestore(&atomic_lock, flags);
+		local_irq_restore(flags);
 	}
 }
 
@@ -475,9 +474,9 @@
 	} else {
 		unsigned long flags;
 
-		spin_lock_irqsave(&atomic_lock, flags);
+		local_irq_save(flags);
 		v->counter -= i;
-		spin_unlock_irqrestore(&atomic_lock, flags);
+		local_irq_restore(flags);
 	}
 }
 
@@ -521,11 +520,11 @@
 	} else {
 		unsigned long flags;
 
-		spin_lock_irqsave(&atomic_lock, flags);
+		local_irq_save(flags);
 		result = v->counter;
 		result += i;
 		v->counter = result;
-		spin_unlock_irqrestore(&atomic_lock, flags);
+		local_irq_restore(flags);
 	}
 
 	return result;
@@ -568,11 +567,11 @@
 	} else {
 		unsigned long flags;
 
-		spin_lock_irqsave(&atomic_lock, flags);
+		local_irq_save(flags);
 		result = v->counter;
 		result -= i;
 		v->counter = result;
-		spin_unlock_irqrestore(&atomic_lock, flags);
+		local_irq_restore(flags);
 	}
 
 	return result;
@@ -625,12 +624,12 @@
 	} else {
 		unsigned long flags;
 
-		spin_lock_irqsave(&atomic_lock, flags);
+		local_irq_save(flags);
 		result = v->counter;
 		result -= i;
 		if (result >= 0)
 			v->counter = result;
-		spin_unlock_irqrestore(&atomic_lock, flags);
+		local_irq_restore(flags);
 	}
 
 	return result;
diff --git a/include/asm-mips/cpu-features.h b/include/asm-mips/cpu-features.h
index 03627cfb..78c9cc2 100644
--- a/include/asm-mips/cpu-features.h
+++ b/include/asm-mips/cpu-features.h
@@ -116,6 +116,27 @@
 #endif
 #endif
 
+# ifndef cpu_has_mips32r1
+# define cpu_has_mips32r1	(cpu_data[0].isa_level & MIPS_CPU_ISA_M32R1)
+# endif
+# ifndef cpu_has_mips32r2
+# define cpu_has_mips32r2	(cpu_data[0].isa_level & MIPS_CPU_ISA_M32R2)
+# endif
+# ifndef cpu_has_mips64r1
+# define cpu_has_mips64r1	(cpu_data[0].isa_level & MIPS_CPU_ISA_M64R1)
+# endif
+# ifndef cpu_has_mips64r2
+# define cpu_has_mips64r2	(cpu_data[0].isa_level & MIPS_CPU_ISA_M64R2)
+# endif
+
+/*
+ * Shortcuts ...
+ */
+#define cpu_has_mips32	(cpu_has_mips32r1 | cpu_has_mips32r2)
+#define cpu_has_mips64	(cpu_has_mips64r1 | cpu_has_mips64r2)
+#define cpu_has_mips_r1	(cpu_has_mips32r1 | cpu_has_mips64r1)
+#define cpu_has_mips_r2	(cpu_has_mips32r2 | cpu_has_mips64r2)
+
 #ifndef cpu_has_dsp
 #define cpu_has_dsp		(cpu_data[0].ases & MIPS_ASE_DSP)
 #endif
diff --git a/include/asm-mips/cpu.h b/include/asm-mips/cpu.h
index 48eac296..934e063 100644
--- a/include/asm-mips/cpu.h
+++ b/include/asm-mips/cpu.h
@@ -204,16 +204,18 @@
  */
 #define MIPS_CPU_ISA_I		0x00000001
 #define MIPS_CPU_ISA_II		0x00000002
-#define MIPS_CPU_ISA_III	0x00008003
-#define MIPS_CPU_ISA_IV		0x00008004
-#define MIPS_CPU_ISA_V		0x00008005
-#define MIPS_CPU_ISA_M32	0x00000020
-#define MIPS_CPU_ISA_M64	0x00008040
+#define MIPS_CPU_ISA_III	0x00000003
+#define MIPS_CPU_ISA_IV		0x00000004
+#define MIPS_CPU_ISA_V		0x00000005
+#define MIPS_CPU_ISA_M32R1	0x00000020
+#define MIPS_CPU_ISA_M32R2	0x00000040
+#define MIPS_CPU_ISA_M64R1	0x00000080
+#define MIPS_CPU_ISA_M64R2	0x00000100
 
-/*
- * Bit 15 encodes if an ISA level supports 64-bit operations.
- */
-#define MIPS_CPU_ISA_64BIT	0x00008000
+#define MIPS_CPU_ISA_32BIT (MIPS_CPU_ISA_I | MIPS_CPU_ISA_II | \
+	MIPS_CPU_ISA_M32R1 | MIPS_CPU_ISA_M32R2 )
+#define MIPS_CPU_ISA_64BIT (MIPS_CPU_ISA_III | MIPS_CPU_ISA_IV | \
+	MIPS_CPU_ISA_V | MIPS_CPU_ISA_M64R1 | MIPS_CPU_ISA_M64R2)
 
 /*
  * CPU Option encodings
diff --git a/include/asm-mips/delay.h b/include/asm-mips/delay.h
index 48d00cc..64dd451 100644
--- a/include/asm-mips/delay.h
+++ b/include/asm-mips/delay.h
@@ -52,13 +52,11 @@
 	unsigned long lo;
 
 	/*
-	 * The common rates of 1000 and 128 are rounded wrongly by the
-	 * catchall case for 64-bit.  Excessive precission?  Probably ...
+	 * The rates of 128 is rounded wrongly by the catchall case
+	 * for 64-bit.  Excessive precission?  Probably ...
 	 */
 #if defined(CONFIG_64BIT) && (HZ == 128)
 	usecs *= 0x0008637bd05af6c7UL;		/* 2**64 / (1000000 / HZ) */
-#elif defined(CONFIG_64BIT) && (HZ == 1000)
-	usecs *= 0x004189374BC6A7f0UL;		/* 2**64 / (1000000 / HZ) */
 #elif defined(CONFIG_64BIT)
 	usecs *= (0x8000000000000000UL / (500000 / HZ));
 #else /* 32-bit junk follows here */
diff --git a/include/asm-mips/dsp.h b/include/asm-mips/dsp.h
index 50f556b..e9bfc08 100644
--- a/include/asm-mips/dsp.h
+++ b/include/asm-mips/dsp.h
@@ -16,7 +16,7 @@
 #include <asm/mipsregs.h>
 
 #define DSP_DEFAULT	0x00000000
-#define DSP_MASK	0x1f
+#define DSP_MASK	0x3ff
 
 #define __enable_dsp_hazard()						\
 do {									\
@@ -48,6 +48,7 @@
 	tsk->thread.dsp.dspr[3] = mflo2();				\
 	tsk->thread.dsp.dspr[4] = mfhi3();				\
 	tsk->thread.dsp.dspr[5] = mflo3();				\
+	tsk->thread.dsp.dspcontrol = rddsp(DSP_MASK);			\
 } while (0)
 
 #define save_dsp(tsk)							\
@@ -64,6 +65,7 @@
 	mtlo2(tsk->thread.dsp.dspr[3]);					\
 	mthi3(tsk->thread.dsp.dspr[4]);					\
 	mtlo3(tsk->thread.dsp.dspr[5]);					\
+	wrdsp(tsk->thread.dsp.dspcontrol, DSP_MASK);			\
 } while (0)
 
 #define restore_dsp(tsk)						\
diff --git a/include/asm-mips/elf.h b/include/asm-mips/elf.h
index d2c9a25..851f013 100644
--- a/include/asm-mips/elf.h
+++ b/include/asm-mips/elf.h
@@ -277,12 +277,12 @@
 
 struct task_struct;
 
-extern void dump_regs(elf_greg_t *, struct pt_regs *regs);
+extern void elf_dump_regs(elf_greg_t *, struct pt_regs *regs);
 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_REGS(elf_regs, regs)			\
-	dump_regs((elf_greg_t *)&(elf_regs), regs);
+	elf_dump_regs((elf_greg_t *)&(elf_regs), regs);
 #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)
diff --git a/include/asm-mips/hazards.h b/include/asm-mips/hazards.h
index 7517189..2fc9063 100644
--- a/include/asm-mips/hazards.h
+++ b/include/asm-mips/hazards.h
@@ -233,15 +233,25 @@
 #endif
 
 #ifdef CONFIG_CPU_MIPSR2
+/*
+ * gcc has a tradition of misscompiling the previous construct using the
+ * address of a label as argument to inline assembler.  Gas otoh has the
+ * annoying difference between la and dla which are only usable for 32-bit
+ * rsp. 64-bit code, so can't be used without conditional compilation.
+ * The alterantive is switching the assembler to 64-bit code which happens
+ * to work right even for 32-bit code ...
+ */
 #define instruction_hazard()						\
 do {									\
-__label__ __next;							\
+	unsigned long tmp;						\
+									\
 	__asm__ __volatile__(						\
+	"	.set	mips64r2				\n"	\
+	"	dla	%0, 1f					\n"	\
 	"	jr.hb	%0					\n"	\
-	:								\
-	: "r" (&&__next));						\
-__next:									\
-	;								\
+	"	.set	mips0					\n"	\
+	"1:							\n"	\
+	: "=r" (tmp));							\
 } while (0)
 
 #else
diff --git a/include/asm-mips/interrupt.h b/include/asm-mips/interrupt.h
index a573576..abdf54e 100644
--- a/include/asm-mips/interrupt.h
+++ b/include/asm-mips/interrupt.h
@@ -93,6 +93,7 @@
 	"	.set	noat						\n"
 #ifdef CONFIG_CPU_MIPSR2
 	"	di	\\result					\n"
+	"	andi	\\result, 1					\n"
 #else
 	"	mfc0	\\result, $12					\n"
 	"	ori	$1, \\result, 1					\n"
diff --git a/include/asm-mips/mach-au1x00/au1000.h b/include/asm-mips/mach-au1x00/au1000.h
index 8327ec3..8e1d7ed 100644
--- a/include/asm-mips/mach-au1x00/au1000.h
+++ b/include/asm-mips/mach-au1x00/au1000.h
@@ -838,6 +838,7 @@
 #define UART3_ADDR                0xB1400000
 
 #define USB_OHCI_BASE             0x14020000 // phys addr for ioremap
+#define USB_OHCI_LEN              0x00060000
 #define USB_HOST_CONFIG           0xB4027ffc
 
 #define AU1550_ETH0_BASE      0xB0500000
@@ -1017,10 +1018,12 @@
   #define I2S_CONTROL_D         (1<<1)
   #define I2S_CONTROL_CE        (1<<0)
 
-#ifndef CONFIG_SOC_AU1200
-
 /* USB Host Controller */
+#ifndef USB_OHCI_LEN
 #define USB_OHCI_LEN              0x00100000
+#endif
+
+#ifndef CONFIG_SOC_AU1200
 
 /* USB Device Controller */
 #define USBD_EP0RD                0xB0200000
diff --git a/include/asm-mips/mach-ip22/cpu-feature-overrides.h b/include/asm-mips/mach-ip22/cpu-feature-overrides.h
index ab97146..2a37bed 100644
--- a/include/asm-mips/mach-ip22/cpu-feature-overrides.h
+++ b/include/asm-mips/mach-ip22/cpu-feature-overrides.h
@@ -34,4 +34,9 @@
 #define cpu_has_nofpuex		0
 #define cpu_has_64bits		1
 
+#define cpu_has_mips32r1	0
+#define cpu_has_mips32r2	0
+#define cpu_has_mips64r1	0
+#define cpu_has_mips64r2	0
+
 #endif /* __ASM_MACH_IP22_CPU_FEATURE_OVERRIDES_H */
diff --git a/include/asm-mips/mach-ip27/cpu-feature-overrides.h b/include/asm-mips/mach-ip27/cpu-feature-overrides.h
index 4c8a900..2d2f5b9 100644
--- a/include/asm-mips/mach-ip27/cpu-feature-overrides.h
+++ b/include/asm-mips/mach-ip27/cpu-feature-overrides.h
@@ -37,4 +37,9 @@
 #define cpu_icache_line_size()	64
 #define cpu_scache_line_size()	128
 
+#define cpu_has_mips32r1	0
+#define cpu_has_mips32r2	0
+#define cpu_has_mips64r1	0
+#define cpu_has_mips64r2	0
+
 #endif /* __ASM_MACH_IP27_CPU_FEATURE_OVERRIDES_H */
diff --git a/include/asm-mips/mach-ip27/topology.h b/include/asm-mips/mach-ip27/topology.h
index 82141c7..59d26b5 100644
--- a/include/asm-mips/mach-ip27/topology.h
+++ b/include/asm-mips/mach-ip27/topology.h
@@ -27,7 +27,6 @@
 	.max_interval		= 32,			\
 	.busy_factor		= 32,			\
 	.imbalance_pct		= 125,			\
-	.cache_hot_time		= (10*1000),		\
 	.cache_nice_tries	= 1,			\
 	.per_cpu_gain		= 100,			\
 	.flags			= SD_LOAD_BALANCE	\
diff --git a/include/asm-mips/mach-ip32/cpu-feature-overrides.h b/include/asm-mips/mach-ip32/cpu-feature-overrides.h
index ab37fc1..b80c307 100644
--- a/include/asm-mips/mach-ip32/cpu-feature-overrides.h
+++ b/include/asm-mips/mach-ip32/cpu-feature-overrides.h
@@ -39,4 +39,9 @@
 #define cpu_has_ic_fills_f_dc	0
 #define cpu_has_dsp		0
 
+#define cpu_has_mips32r1	0
+#define cpu_has_mips32r2	0
+#define cpu_has_mips64r1	0
+#define cpu_has_mips64r2	0
+
 #endif /* __ASM_MACH_IP32_CPU_FEATURE_OVERRIDES_H */
diff --git a/include/asm-mips/mach-ja/cpu-feature-overrides.h b/include/asm-mips/mach-ja/cpu-feature-overrides.h
index a0fde40..90ff087 100644
--- a/include/asm-mips/mach-ja/cpu-feature-overrides.h
+++ b/include/asm-mips/mach-ja/cpu-feature-overrides.h
@@ -37,4 +37,9 @@
 #define cpu_icache_line_size()	32
 #define cpu_scache_line_size()	32
 
+#define cpu_has_mips32r1	0
+#define cpu_has_mips32r2	0
+#define cpu_has_mips64r1	0
+#define cpu_has_mips64r2	0
+
 #endif /* __ASM_MACH_JA_CPU_FEATURE_OVERRIDES_H */
diff --git a/include/asm-mips/mach-ocelot3/cpu-feature-overrides.h b/include/asm-mips/mach-ocelot3/cpu-feature-overrides.h
index 825c5f6..782b986 100644
--- a/include/asm-mips/mach-ocelot3/cpu-feature-overrides.h
+++ b/include/asm-mips/mach-ocelot3/cpu-feature-overrides.h
@@ -40,4 +40,9 @@
 #define cpu_icache_line_size()	32
 #define cpu_scache_line_size()	32
 
+#define cpu_has_mips32r1	0
+#define cpu_has_mips32r2	0
+#define cpu_has_mips64r1	0
+#define cpu_has_mips64r2	0
+
 #endif /* __ASM_MACH_JA_CPU_FEATURE_OVERRIDES_H */
diff --git a/include/asm-mips/mach-rm200/cpu-feature-overrides.h b/include/asm-mips/mach-rm200/cpu-feature-overrides.h
index 79f9b06..91e7cf5 100644
--- a/include/asm-mips/mach-rm200/cpu-feature-overrides.h
+++ b/include/asm-mips/mach-rm200/cpu-feature-overrides.h
@@ -40,4 +40,9 @@
 #define cpu_icache_line_size()	32
 #define cpu_scache_line_size()	0	/* No S-cache on R5000 I think ...  */
 
+#define cpu_has_mips32r1	0
+#define cpu_has_mips32r2	0
+#define cpu_has_mips64r1	0
+#define cpu_has_mips64r2	0
+
 #endif /* __ASM_MACH_RM200_CPU_FEATURE_OVERRIDES_H */
diff --git a/include/asm-mips/mach-yosemite/cpu-feature-overrides.h b/include/asm-mips/mach-yosemite/cpu-feature-overrides.h
index 463d051..3073542 100644
--- a/include/asm-mips/mach-yosemite/cpu-feature-overrides.h
+++ b/include/asm-mips/mach-yosemite/cpu-feature-overrides.h
@@ -37,4 +37,9 @@
 #define cpu_icache_line_size()	32
 #define cpu_scache_line_size()	32
 
+#define cpu_has_mips32r1	0
+#define cpu_has_mips32r2	0
+#define cpu_has_mips64r1	0
+#define cpu_has_mips64r2	0
+
 #endif /* __ASM_MACH_YOSEMITE_CPU_FEATURE_OVERRIDES_H */
diff --git a/include/asm-mips/mipsregs.h b/include/asm-mips/mipsregs.h
index 80370e0..035ba0a 100644
--- a/include/asm-mips/mipsregs.h
+++ b/include/asm-mips/mipsregs.h
@@ -1059,7 +1059,7 @@
 	"	.set	noat					\n"	\
 	"	move	$1, %0					\n"	\
 	"	# wrdsp $1, %x1					\n"	\
-	"	.word	0x7c2004f8 | (%x1 << 15)		\n"	\
+	"	.word	0x7c2004f8 | (%x1 << 11)		\n"	\
 	"	.set	pop					\n"	\
         :								\
 	: "r" (val), "i" (mask));					\
diff --git a/include/asm-mips/processor.h b/include/asm-mips/processor.h
index f1980c6..39d2bd5 100644
--- a/include/asm-mips/processor.h
+++ b/include/asm-mips/processor.h
@@ -103,7 +103,6 @@
 struct mips_dsp_state {
 	dspreg_t        dspr[NUM_DSP_REGS];
 	unsigned int    dspcontrol;
-	unsigned short	used_dsp;
 };
 
 #define INIT_DSP {{0,},}
@@ -201,11 +200,11 @@
 
 unsigned long get_wchan(struct task_struct *p);
 
-#define __PT_REG(reg) ((long)&((struct pt_regs *)0)->reg - sizeof(struct pt_regs))
-#define __KSTK_TOS(tsk) ((unsigned long)(tsk->thread_info) + THREAD_SIZE - 32)
-#define KSTK_EIP(tsk) (*(unsigned long *)(__KSTK_TOS(tsk) + __PT_REG(cp0_epc)))
-#define KSTK_ESP(tsk) (*(unsigned long *)(__KSTK_TOS(tsk) + __PT_REG(regs[29])))
-#define KSTK_STATUS(tsk) (*(unsigned long *)(__KSTK_TOS(tsk) + __PT_REG(cp0_status)))
+#define __KSTK_TOS(tsk) ((unsigned long)task_stack_page(tsk) + THREAD_SIZE - 32)
+#define task_pt_regs(tsk) ((struct pt_regs *)__KSTK_TOS(tsk) - 1)
+#define KSTK_EIP(tsk) (task_pt_regs(tsk)->cp0_epc)
+#define KSTK_ESP(tsk) (task_pt_regs(tsk)->regs[29])
+#define KSTK_STATUS(tsk) (task_pt_regs(tsk)->cp0_status)
 
 #define cpu_relax()	barrier()
 
diff --git a/include/asm-mips/system.h b/include/asm-mips/system.h
index 330c4e4..e8e5d41 100644
--- a/include/asm-mips/system.h
+++ b/include/asm-mips/system.h
@@ -159,11 +159,21 @@
 do {									\
 	if (cpu_has_dsp)						\
 		__save_dsp(prev);					\
-	(last) = resume(prev, next, next->thread_info);			\
+	(last) = resume(prev, next, task_thread_info(next));		\
 	if (cpu_has_dsp)						\
 		__restore_dsp(current);					\
 } while(0)
 
+/*
+ * On SMP systems, when the scheduler does migration-cost autodetection,
+ * it needs a way to flush as much of the CPU's caches as possible.
+ *
+ * TODO: fill this in!
+ */
+static inline void sched_cacheflush(void)
+{
+}
+
 static inline unsigned long __xchg_u32(volatile int * m, unsigned int val)
 {
 	__u32 retval;
diff --git a/include/asm-mips/thread_info.h b/include/asm-mips/thread_info.h
index e6c2447..1612b3f 100644
--- a/include/asm-mips/thread_info.h
+++ b/include/asm-mips/thread_info.h
@@ -97,8 +97,6 @@
 #endif
 
 #define free_thread_info(info) kfree(info)
-#define get_thread_info(ti) get_task_struct((ti)->task)
-#define put_thread_info(ti) put_task_struct((ti)->task)
 
 #endif /* !__ASSEMBLY__ */
 
diff --git a/include/asm-mips/vr41xx/capcella.h b/include/asm-mips/vr41xx/capcella.h
index 5b55083..d10ffda5 100644
--- a/include/asm-mips/vr41xx/capcella.h
+++ b/include/asm-mips/vr41xx/capcella.h
@@ -1,7 +1,7 @@
 /*
  *  capcella.h, Include file for ZAO Networks Capcella.
  *
- *  Copyright (C) 2002-2004  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2002-2004  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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 --git a/include/asm-mips/vr41xx/e55.h b/include/asm-mips/vr41xx/e55.h
index ea37b56..558f226 100644
--- a/include/asm-mips/vr41xx/e55.h
+++ b/include/asm-mips/vr41xx/e55.h
@@ -1,7 +1,7 @@
 /*
  *  e55.h, Include file for CASIO CASSIOPEIA E-10/15/55/65.
  *
- *  Copyright (C) 2002-2004  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2002-2004  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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 --git a/include/asm-mips/vr41xx/giu.h b/include/asm-mips/vr41xx/giu.h
index 8590885..8109cda 100644
--- a/include/asm-mips/vr41xx/giu.h
+++ b/include/asm-mips/vr41xx/giu.h
@@ -1,7 +1,7 @@
 /*
  *  Include file for NEC VR4100 series General-purpose I/O Unit.
  *
- *  Copyright (C) 2005  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2005  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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 --git a/include/asm-mips/vr41xx/mpc30x.h b/include/asm-mips/vr41xx/mpc30x.h
index e6ac3c8..a6cbe4d 100644
--- a/include/asm-mips/vr41xx/mpc30x.h
+++ b/include/asm-mips/vr41xx/mpc30x.h
@@ -1,7 +1,7 @@
 /*
  *  mpc30x.h, Include file for Victor MP-C303/304.
  *
- *  Copyright (C) 2002-2004  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2002-2004  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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 --git a/include/asm-mips/vr41xx/pci.h b/include/asm-mips/vr41xx/pci.h
index c473aa7..6fc01ce 100644
--- a/include/asm-mips/vr41xx/pci.h
+++ b/include/asm-mips/vr41xx/pci.h
@@ -1,7 +1,7 @@
 /*
  *  Include file for NEC VR4100 series PCI Control Unit.
  *
- *  Copyright (C) 2004-2005  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2004-2005  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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 --git a/include/asm-mips/vr41xx/siu.h b/include/asm-mips/vr41xx/siu.h
index 865cc07..1fcf6e8 100644
--- a/include/asm-mips/vr41xx/siu.h
+++ b/include/asm-mips/vr41xx/siu.h
@@ -1,7 +1,7 @@
 /*
  *  Include file for NEC VR4100 series Serial Interface Unit.
  *
- *  Copyright (C) 2005  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2005  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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 --git a/include/asm-mips/vr41xx/tb0219.h b/include/asm-mips/vr41xx/tb0219.h
index 273c639..b318b96 100644
--- a/include/asm-mips/vr41xx/tb0219.h
+++ b/include/asm-mips/vr41xx/tb0219.h
@@ -1,7 +1,7 @@
 /*
  *  tb0219.h, Include file for TANBAC TB0219.
  *
- *  Copyright (C) 2002-2004  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2002-2004  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  Modified for TANBAC TB0219:
  *  Copyright (C) 2003 Megasolution Inc.  <matsu@megasolution.jp>
diff --git a/include/asm-mips/vr41xx/tb0226.h b/include/asm-mips/vr41xx/tb0226.h
index 0ff9a60..2513f45 100644
--- a/include/asm-mips/vr41xx/tb0226.h
+++ b/include/asm-mips/vr41xx/tb0226.h
@@ -1,7 +1,7 @@
 /*
  *  tb0226.h, Include file for TANBAC TB0226.
  *
- *  Copyright (C) 2002-2004  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2002-2004  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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 --git a/include/asm-mips/vr41xx/vr41xx.h b/include/asm-mips/vr41xx/vr41xx.h
index bd2723c..70828d5 100644
--- a/include/asm-mips/vr41xx/vr41xx.h
+++ b/include/asm-mips/vr41xx/vr41xx.h
@@ -7,7 +7,7 @@
  * Copyright (C) 2001, 2002 Paul Mundt
  * Copyright (C) 2002 MontaVista Software, Inc.
  * Copyright (C) 2002 TimeSys Corp.
- * Copyright (C) 2003-2005 Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ * Copyright (C) 2003-2005 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  * 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
diff --git a/include/asm-mips/vr41xx/vrc4173.h b/include/asm-mips/vr41xx/vrc4173.h
index bb7a85c..4d41a9c 100644
--- a/include/asm-mips/vr41xx/vrc4173.h
+++ b/include/asm-mips/vr41xx/vrc4173.h
@@ -4,7 +4,7 @@
  *  Copyright (C) 2000  Michael R. McDonald
  *  Copyright (C) 2001-2003 Montavista Software Inc.
  *    Author: Yoichi Yuasa <yyuasa@mvista.com, or source@mvista.com>
- *  Copyright (C) 2004  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2004  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *  Copyright (C) 2005 Ralf Baechle (ralf@linux-mips.org)
  *
  *  This program is free software; you can redistribute it and/or modify
diff --git a/include/asm-mips/vr41xx/workpad.h b/include/asm-mips/vr41xx/workpad.h
index dfe01b4..6bfa9c0 100644
--- a/include/asm-mips/vr41xx/workpad.h
+++ b/include/asm-mips/vr41xx/workpad.h
@@ -1,7 +1,7 @@
 /*
  *  workpad.h, Include file for IBM WorkPad z50.
  *
- *  Copyright (C) 2002-2004  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
+ *  Copyright (C) 2002-2004  Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  *
  *  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 --git a/include/asm-parisc/cache.h b/include/asm-parisc/cache.h
index 38d201b..93f179f 100644
--- a/include/asm-parisc/cache.h
+++ b/include/asm-parisc/cache.h
@@ -29,14 +29,14 @@
 
 #define SMP_CACHE_BYTES L1_CACHE_BYTES
 
-extern void flush_data_cache_local(void);  /* flushes local data-cache only */
-extern void flush_instruction_cache_local(void); /* flushes local code-cache only */
+extern void flush_data_cache_local(void *);  /* flushes local data-cache only */
+extern void flush_instruction_cache_local(void *); /* flushes local code-cache only */
 #ifdef CONFIG_SMP
 extern void flush_data_cache(void); /* flushes data-cache only (all processors) */
 extern void flush_instruction_cache(void); /* flushes i-cache only (all processors) */
 #else
-#define flush_data_cache flush_data_cache_local
-#define flush_instruction_cache flush_instruction_cache_local
+#define flush_data_cache() flush_data_cache_local(NULL)
+#define flush_instruction_cache() flush_instruction_cache_local(NULL)
 #endif
 
 extern void parisc_cache_init(void);	/* initializes cache-flushing */
diff --git a/include/asm-parisc/io.h b/include/asm-parisc/io.h
index b9bb594..0db00ad 100644
--- a/include/asm-parisc/io.h
+++ b/include/asm-parisc/io.h
@@ -41,7 +41,7 @@
 #define __raw_check_addr(addr)					\
 	if (((unsigned long)addr >> NYBBLE_SHIFT) != 0xe)	\
 		__raw_bad_addr(addr);			\
-	addr = (void *)((unsigned long)addr | (0xfUL << NYBBLE_SHIFT));
+	addr = (void __iomem *)((unsigned long)addr | (0xfUL << NYBBLE_SHIFT));
 #else
 #define gsc_check_addr(addr)
 #define __raw_check_addr(addr)
diff --git a/include/asm-parisc/page.h b/include/asm-parisc/page.h
index 44eae9f..4a6752b 100644
--- a/include/asm-parisc/page.h
+++ b/include/asm-parisc/page.h
@@ -135,6 +135,13 @@
 #define pfn_valid(pfn)		((pfn) < max_mapnr)
 #endif /* CONFIG_DISCONTIGMEM */
 
+#ifdef CONFIG_HUGETLB_PAGE
+#define HPAGE_SHIFT		22	/* 4MB (is this fixed?) */
+#define HPAGE_SIZE      	((1UL) << HPAGE_SHIFT)
+#define HPAGE_MASK		(~(HPAGE_SIZE - 1))
+#define HUGETLB_PAGE_ORDER	(HPAGE_SHIFT - PAGE_SHIFT)
+#endif
+
 #define virt_addr_valid(kaddr)	pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
 
 #define page_to_phys(page)	(page_to_pfn(page) << PAGE_SHIFT)
diff --git a/include/asm-parisc/pci.h b/include/asm-parisc/pci.h
index fa39d07..f277254 100644
--- a/include/asm-parisc/pci.h
+++ b/include/asm-parisc/pci.h
@@ -84,11 +84,17 @@
 /*
 ** Convert between PCI (IO_VIEW) addresses and processor (PA_VIEW) addresses.
 ** See pcibios.c for more conversions used by Generic PCI code.
+**
+** Platform characteristics/firmware guarantee that
+**	(1) PA_VIEW - IO_VIEW = lmmio_offset for both LMMIO and ELMMIO
+**	(2) PA_VIEW == IO_VIEW for GMMIO
 */
 #define PCI_BUS_ADDR(hba,a)	(PCI_IS_LMMIO(hba,a)	\
 		?  ((a) - hba->lmmio_space_offset)	/* mangle LMMIO */ \
 		: (a))					/* GMMIO */
-#define PCI_HOST_ADDR(hba,a)	((a) + hba->lmmio_space_offset)
+#define PCI_HOST_ADDR(hba,a)	(((a) & PCI_F_EXTEND) == 0 \
+		? (a) + hba->lmmio_space_offset \
+		: (a))
 
 #else	/* !CONFIG_64BIT */
 
diff --git a/include/asm-parisc/processor.h b/include/asm-parisc/processor.h
index aae40e8..89f2f1c 100644
--- a/include/asm-parisc/processor.h
+++ b/include/asm-parisc/processor.h
@@ -144,16 +144,16 @@
         })
 
 #define INIT_THREAD { \
-	regs:	{	gr: { 0, }, \
-			fr: { 0, }, \
-			sr: { 0, }, \
-			iasq: { 0, }, \
-			iaoq: { 0, }, \
-			cr27: 0, \
+	.regs = {	.gr	= { 0, }, \
+			.fr	= { 0, }, \
+			.sr	= { 0, }, \
+			.iasq	= { 0, }, \
+			.iaoq	= { 0, }, \
+			.cr27	= 0, \
 		}, \
-	task_size:      DEFAULT_TASK_SIZE, \
-	map_base:       DEFAULT_MAP_BASE, \
-	flags:          0 \
+	.task_size	= DEFAULT_TASK_SIZE, \
+	.map_base	= DEFAULT_MAP_BASE, \
+	.flags		= 0 \
 	}
 
 /*
diff --git a/include/asm-parisc/system.h b/include/asm-parisc/system.h
index f3928d3..a5a973c 100644
--- a/include/asm-parisc/system.h
+++ b/include/asm-parisc/system.h
@@ -49,6 +49,15 @@
 	(last) = _switch_to(prev, next);			\
 } while(0)
 
+/*
+ * On SMP systems, when the scheduler does migration-cost autodetection,
+ * it needs a way to flush as much of the CPU's caches as possible.
+ *
+ * TODO: fill this in!
+ */
+static inline void sched_cacheflush(void)
+{
+}
 
 
 /* interrupt control */
diff --git a/include/asm-parisc/thread_info.h b/include/asm-parisc/thread_info.h
index 57bbb76..ac32f14 100644
--- a/include/asm-parisc/thread_info.h
+++ b/include/asm-parisc/thread_info.h
@@ -43,9 +43,6 @@
 #define alloc_thread_info(tsk) ((struct thread_info *) \
 			__get_free_pages(GFP_KERNEL, THREAD_ORDER))
 #define free_thread_info(ti)    free_pages((unsigned long) (ti), THREAD_ORDER)
-#define get_thread_info(ti)     get_task_struct((ti)->task)
-#define put_thread_info(ti)     put_task_struct((ti)->task)
-
 
 /* how to get the thread information struct from C */
 #define current_thread_info()	((struct thread_info *)mfctl(30))
diff --git a/include/asm-parisc/tlbflush.h b/include/asm-parisc/tlbflush.h
index c9ec39c..825994a 100644
--- a/include/asm-parisc/tlbflush.h
+++ b/include/asm-parisc/tlbflush.h
@@ -22,6 +22,7 @@
 #define purge_tlb_end(x) spin_unlock(&pa_tlb_lock)
 
 extern void flush_tlb_all(void);
+extern void flush_tlb_all_local(void *);
 
 /*
  * flush_tlb_mm()
diff --git a/include/asm-powerpc/eeh.h b/include/asm-powerpc/eeh.h
index 4395b7b..b263fb2 100644
--- a/include/asm-powerpc/eeh.h
+++ b/include/asm-powerpc/eeh.h
@@ -34,9 +34,11 @@
 extern int eeh_subsystem_enabled;
 
 /* Values for eeh_mode bits in device_node */
-#define EEH_MODE_SUPPORTED	(1<<0)
-#define EEH_MODE_NOCHECK	(1<<1)
-#define EEH_MODE_ISOLATED	(1<<2)
+#define EEH_MODE_SUPPORTED     (1<<0)
+#define EEH_MODE_NOCHECK       (1<<1)
+#define EEH_MODE_ISOLATED      (1<<2)
+#define EEH_MODE_RECOVERING    (1<<3)
+#define EEH_MODE_IRQ_DISABLED  (1<<4)
 
 /* Max number of EEH freezes allowed before we consider the device
  * to be permanently disabled. */
diff --git a/include/asm-powerpc/eeh_event.h b/include/asm-powerpc/eeh_event.h
index 5e11a00..93d55a2 100644
--- a/include/asm-powerpc/eeh_event.h
+++ b/include/asm-powerpc/eeh_event.h
@@ -30,7 +30,7 @@
 	struct list_head     list;
 	struct device_node 	*dn;   /* struct device node */
 	struct pci_dev       *dev;  /* affected device */
-	int                  state;
+	enum pci_channel_state state; /* PCI bus state for the affected device */
 	int time_unavail;    /* milliseconds until device might be available */
 };
 
@@ -47,8 +47,11 @@
  */
 int eeh_send_failure_event (struct device_node *dn,
                             struct pci_dev *dev,
-                            int reset_state,
+                            enum pci_channel_state state,
                             int time_unavail);
 
+/* Main recovery function */
+void handle_eeh_events (struct eeh_event *);
+
 #endif /* __KERNEL__ */
 #endif /* ASM_PPC64_EEH_EVENT_H */
diff --git a/include/asm-powerpc/elf.h b/include/asm-powerpc/elf.h
index c5a635d..45f2af6 100644
--- a/include/asm-powerpc/elf.h
+++ b/include/asm-powerpc/elf.h
@@ -92,7 +92,6 @@
  * as published by the Free Software Foundation; either version
  * 2 of the License, or (at your option) any later version.
  */
-#include <asm/ptrace.h>
 
 #define ELF_NGREG	48	/* includes nip, msr, lr, etc. */
 #define ELF_NFPREG	33	/* includes fpscr */
diff --git a/include/asm-powerpc/iommu.h b/include/asm-powerpc/iommu.h
index 8a8393e..d5677cb 100644
--- a/include/asm-powerpc/iommu.h
+++ b/include/asm-powerpc/iommu.h
@@ -64,25 +64,6 @@
 
 #endif /* CONFIG_PPC_MULTIPLATFORM */
 
-#ifdef CONFIG_PPC_PSERIES
-
-/* Creates table for an individual device node */
-extern void iommu_devnode_init_pSeries(struct device_node *dn);
-
-#endif /* CONFIG_PPC_PSERIES */
-
-#ifdef CONFIG_PPC_ISERIES
-
-/* Creates table for an individual device node */
-extern void iommu_devnode_init_iSeries(struct device_node *dn);
-/* Get table parameters from HV */
-extern void iommu_table_getparms_iSeries(unsigned long busno,
-					 unsigned char slotno,
-					 unsigned char virtbus,
-					 struct iommu_table* tbl);
-
-#endif /* CONFIG_PPC_ISERIES */
-
 /* Initializes an iommu_table based in values set in the passed-in
  * structure
  */
diff --git a/include/asm-powerpc/iseries/hv_call.h b/include/asm-powerpc/iseries/hv_call.h
index e9f831c..162d653 100644
--- a/include/asm-powerpc/iseries/hv_call.h
+++ b/include/asm-powerpc/iseries/hv_call.h
@@ -1,5 +1,4 @@
 /*
- * HvCall.h
  * Copyright (C) 2001  Mike Corrigan IBM Corporation
  *
  * This program is free software; you can redistribute it and/or modify
@@ -15,8 +14,7 @@
  * 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
- */
-/*
+ *
  * This file contains the "hypervisor call" interface which is used to
  * drive the hypervisor from the OS.
  */
diff --git a/include/asm-powerpc/iseries/hv_call_event.h b/include/asm-powerpc/iseries/hv_call_event.h
index 46763a3..4cec476 100644
--- a/include/asm-powerpc/iseries/hv_call_event.h
+++ b/include/asm-powerpc/iseries/hv_call_event.h
@@ -1,5 +1,4 @@
 /*
- * HvCallEvent.h
  * Copyright (C) 2001  Mike Corrigan IBM Corporation
  *
  * This program is free software; you can redistribute it and/or modify
@@ -15,8 +14,7 @@
  * 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
- */
-/*
+ *
  * This file contains the "hypervisor call" interface which is used to
  * drive the hypervisor from the OS.
  */
@@ -33,32 +31,9 @@
 typedef u8 HvLpEvent_AckInd;
 typedef u8 HvLpEvent_AckType;
 
-struct	HvCallEvent_PackedParms {
-	u8		xAckType:1;
-	u8		xAckInd:1;
-	u8		xRsvd:1;
-	u8		xTargetLp:5;
-	u8		xType;
-	u16		xSubtype;
-	HvLpInstanceId	xSourceInstId;
-	HvLpInstanceId	xTargetInstId;
-};
-
 typedef u8 HvLpDma_Direction;
 typedef u8 HvLpDma_AddressType;
 
-struct	HvCallEvent_PackedDmaParms {
-	u8		xDirection:1;
-	u8		xLocalAddrType:1;
-	u8		xRemoteAddrType:1;
-	u8		xRsvd1:5;
-	HvLpIndex	xRemoteLp;
-	u8		xType;
-	u8		xRsvd2;
-	HvLpInstanceId	xLocalInstId;
-	HvLpInstanceId	xRemoteInstId;
-};
-
 typedef u64 HvLpEvent_Rc;
 typedef u64 HvLpDma_Rc;
 
@@ -92,11 +67,8 @@
 static inline void HvCallEvent_setLpEventStack(u8 queueIndex,
 		char *eventStackAddr, u32 eventStackSize)
 {
-	u64 abs_addr;
-
-	abs_addr = virt_to_abs(eventStackAddr);
-	HvCall3(HvCallEventSetLpEventStack, queueIndex, abs_addr,
-			eventStackSize);
+	HvCall3(HvCallEventSetLpEventStack, queueIndex,
+			virt_to_abs(eventStackAddr), eventStackSize);
 }
 
 static inline void HvCallEvent_setLpEventQueueInterruptProc(u8 queueIndex,
@@ -108,14 +80,7 @@
 
 static inline HvLpEvent_Rc HvCallEvent_signalLpEvent(struct HvLpEvent *event)
 {
-	u64 abs_addr;
-
-#ifdef DEBUG_SENDEVENT
-	printk("HvCallEvent_signalLpEvent: *event = %016lx\n ",
-			(unsigned long)event);
-#endif
-	abs_addr = virt_to_abs(event);
-	return HvCall1(HvCallEventSignalLpEvent, abs_addr);
+	return HvCall1(HvCallEventSignalLpEvent, virt_to_abs(event));
 }
 
 static inline HvLpEvent_Rc HvCallEvent_signalLpEventFast(HvLpIndex targetLp,
@@ -127,17 +92,21 @@
 {
 	/* Pack the misc bits into a single Dword to pass to PLIC */
 	union {
-		struct HvCallEvent_PackedParms	parms;
+		struct {
+			u8		ack_and_target;
+			u8		type;
+			u16		subtype;
+			HvLpInstanceId	src_inst;
+			HvLpInstanceId	target_inst;
+		} parms;
 		u64		dword;
 	} packed;
-	packed.parms.xAckType	= ackType;
-	packed.parms.xAckInd	= ackInd;
-	packed.parms.xRsvd	= 0;
-	packed.parms.xTargetLp	= targetLp;
-	packed.parms.xType	= type;
-	packed.parms.xSubtype	= subtype;
-	packed.parms.xSourceInstId	= sourceInstanceId;
-	packed.parms.xTargetInstId	= targetInstanceId;
+
+	packed.parms.ack_and_target = (ackType << 7) | (ackInd << 6) | targetLp;
+	packed.parms.type = type;
+	packed.parms.subtype = subtype;
+	packed.parms.src_inst = sourceInstanceId;
+	packed.parms.target_inst = targetInstanceId;
 
 	return HvCall7(HvCallEventSignalLpEventParms, packed.dword,
 			correlationToken, eventData1, eventData2,
@@ -146,18 +115,12 @@
 
 static inline HvLpEvent_Rc HvCallEvent_ackLpEvent(struct HvLpEvent *event)
 {
-	u64 abs_addr;
-
-	abs_addr = virt_to_abs(event);
-	return HvCall1(HvCallEventAckLpEvent, abs_addr);
+	return HvCall1(HvCallEventAckLpEvent, virt_to_abs(event));
 }
 
 static inline HvLpEvent_Rc HvCallEvent_cancelLpEvent(struct HvLpEvent *event)
 {
-	u64 abs_addr;
-
-	abs_addr = virt_to_abs(event);
-	return HvCall1(HvCallEventCancelLpEvent, abs_addr);
+	return HvCall1(HvCallEventCancelLpEvent, virt_to_abs(event));
 }
 
 static inline HvLpInstanceId HvCallEvent_getSourceLpInstanceId(
@@ -195,59 +158,34 @@
 {
 	/* Pack the misc bits into a single Dword to pass to PLIC */
 	union {
-		struct HvCallEvent_PackedDmaParms	parms;
+		struct {
+			u8		flags;
+			HvLpIndex	remote;
+			u8		type;
+			u8		reserved;
+			HvLpInstanceId	local_inst;
+			HvLpInstanceId	remote_inst;
+		} parms;
 		u64		dword;
 	} packed;
 
-	packed.parms.xDirection		= direction;
-	packed.parms.xLocalAddrType	= localAddressType;
-	packed.parms.xRemoteAddrType	= remoteAddressType;
-	packed.parms.xRsvd1		= 0;
-	packed.parms.xRemoteLp		= remoteLp;
-	packed.parms.xType		= type;
-	packed.parms.xRsvd2		= 0;
-	packed.parms.xLocalInstId	= localInstanceId;
-	packed.parms.xRemoteInstId	= remoteInstanceId;
+	packed.parms.flags = (direction << 7) |
+		(localAddressType << 6) | (remoteAddressType << 5);
+	packed.parms.remote = remoteLp;
+	packed.parms.type = type;
+	packed.parms.reserved = 0;
+	packed.parms.local_inst = localInstanceId;
+	packed.parms.remote_inst = remoteInstanceId;
 
 	return HvCall4(HvCallEventDmaBufList, packed.dword, localBufList,
 			remoteBufList, transferLength);
 }
 
-static inline HvLpDma_Rc HvCallEvent_dmaSingle(HvLpEvent_Type type,
-		HvLpIndex remoteLp, HvLpDma_Direction direction,
-		HvLpInstanceId localInstanceId,
-		HvLpInstanceId remoteInstanceId,
-		HvLpDma_AddressType localAddressType,
-		HvLpDma_AddressType remoteAddressType,
-		u64 localAddrOrTce, u64 remoteAddrOrTce, u32 transferLength)
-{
-	/* Pack the misc bits into a single Dword to pass to PLIC */
-	union {
-		struct HvCallEvent_PackedDmaParms	parms;
-		u64		dword;
-	} packed;
-
-	packed.parms.xDirection		= direction;
-	packed.parms.xLocalAddrType	= localAddressType;
-	packed.parms.xRemoteAddrType	= remoteAddressType;
-	packed.parms.xRsvd1		= 0;
-	packed.parms.xRemoteLp		= remoteLp;
-	packed.parms.xType		= type;
-	packed.parms.xRsvd2		= 0;
-	packed.parms.xLocalInstId	= localInstanceId;
-	packed.parms.xRemoteInstId	= remoteInstanceId;
-
-	return (HvLpDma_Rc)HvCall4(HvCallEventDmaSingle, packed.dword,
-			localAddrOrTce, remoteAddrOrTce, transferLength);
-}
-
 static inline HvLpDma_Rc HvCallEvent_dmaToSp(void *local, u32 remote,
 		u32 length, HvLpDma_Direction dir)
 {
-	u64 abs_addr;
-
-	abs_addr = virt_to_abs(local);
-	return HvCall4(HvCallEventDmaToSp, abs_addr, remote, length, dir);
+	return HvCall4(HvCallEventDmaToSp, virt_to_abs(local), remote,
+			length, dir);
 }
 
 #endif /* _ASM_POWERPC_ISERIES_HV_CALL_EVENT_H */
diff --git a/include/asm-powerpc/iseries/hv_call_sc.h b/include/asm-powerpc/iseries/hv_call_sc.h
index dec7e9d..f5d2109 100644
--- a/include/asm-powerpc/iseries/hv_call_sc.h
+++ b/include/asm-powerpc/iseries/hv_call_sc.h
@@ -1,5 +1,4 @@
 /*
- * HvCallSc.h
  * Copyright (C) 2001  Mike Corrigan IBM Corporation
  *
  * This program is free software; you can redistribute it and/or modify
diff --git a/include/asm-powerpc/iseries/hv_lp_config.h b/include/asm-powerpc/iseries/hv_lp_config.h
index bc00f03..df8b207 100644
--- a/include/asm-powerpc/iseries/hv_lp_config.h
+++ b/include/asm-powerpc/iseries/hv_lp_config.h
@@ -1,5 +1,4 @@
 /*
- * HvLpConfig.h
  * Copyright (C) 2001  Mike Corrigan IBM Corporation
  *
  * This program is free software; you can redistribute it and/or modify
diff --git a/include/asm-powerpc/iseries/hv_lp_event.h b/include/asm-powerpc/iseries/hv_lp_event.h
index 499ab1a..4065a4d 100644
--- a/include/asm-powerpc/iseries/hv_lp_event.h
+++ b/include/asm-powerpc/iseries/hv_lp_event.h
@@ -1,5 +1,4 @@
 /*
- * HvLpEvent.h
  * Copyright (C) 2001  Mike Corrigan IBM Corporation
  *
  * This program is free software; you can redistribute it and/or modify
@@ -32,17 +31,8 @@
  * partitions through PLIC.
  */
 
-struct HvEventFlags {
-	u8	xValid:1;	/* Indicates a valid request	x00-x00 */
-	u8	xRsvd1:4;	/* Reserved			... */
-	u8	xAckType:1;	/* Immediate or deferred	... */
-	u8	xAckInd:1;	/* Indicates if ACK required	... */
-	u8	xFunction:1;	/* Interrupt or Acknowledge	... */
-};
-
-
 struct HvLpEvent {
-	struct HvEventFlags xFlags;	/* Event flags		      x00-x00 */
+	u8	flags;			/* Event flags		      x00-x00 */
 	u8	xType;			/* Type of message	      x01-x01 */
 	u16	xSubtype;		/* Subtype for event	      x02-x03 */
 	u8	xSourceLp;		/* Source LP		      x04-x04 */
@@ -126,6 +116,11 @@
 #define HvLpEvent_AckType_ImmediateAck 0
 #define HvLpEvent_AckType_DeferredAck 1
 
+#define HV_LP_EVENT_INT			0x01
+#define HV_LP_EVENT_DO_ACK		0x02
+#define HV_LP_EVENT_DEFERRED_ACK	0x04
+#define HV_LP_EVENT_VALID		0x80
+
 #define HvLpDma_Direction_LocalToRemote 0
 #define HvLpDma_Direction_RemoteToLocal 1
 
@@ -139,4 +134,29 @@
 #define HvLpDma_Rc_InvalidAddress 4
 #define HvLpDma_Rc_InvalidLength 5
 
+static inline int hvlpevent_is_valid(struct HvLpEvent *h)
+{
+	return h->flags & HV_LP_EVENT_VALID;
+}
+
+static inline void hvlpevent_invalidate(struct HvLpEvent *h)
+{
+	h->flags &= ~ HV_LP_EVENT_VALID;
+}
+
+static inline int hvlpevent_is_int(struct HvLpEvent *h)
+{
+	return h->flags & HV_LP_EVENT_INT;
+}
+
+static inline int hvlpevent_is_ack(struct HvLpEvent *h)
+{
+	return !hvlpevent_is_int(h);
+}
+
+static inline int hvlpevent_need_ack(struct HvLpEvent *h)
+{
+	return h->flags & HV_LP_EVENT_DO_ACK;
+}
+
 #endif /* _ASM_POWERPC_ISERIES_HV_LP_EVENT_H */
diff --git a/include/asm-powerpc/iseries/hv_types.h b/include/asm-powerpc/iseries/hv_types.h
index c38f7e3..c3e6d2a 100644
--- a/include/asm-powerpc/iseries/hv_types.h
+++ b/include/asm-powerpc/iseries/hv_types.h
@@ -1,5 +1,4 @@
 /*
- * HvTypes.h
  * Copyright (C) 2001  Mike Corrigan IBM Corporation
  *
  * This program is free software; you can redistribute it and/or modify
diff --git a/include/asm-powerpc/iseries/iseries_io.h b/include/asm-powerpc/iseries/iseries_io.h
index 56b2113..496aa85 100644
--- a/include/asm-powerpc/iseries/iseries_io.h
+++ b/include/asm-powerpc/iseries/iseries_io.h
@@ -6,7 +6,7 @@
 #ifdef CONFIG_PPC_ISERIES
 #include <linux/types.h>
 /*
- * File iSeries_io.h created by Allan Trautman on Thu Dec 28 2000.
+ * Created by Allan Trautman on Thu Dec 28 2000.
  *
  * Remaps the io.h for the iSeries Io
  * Copyright (C) 2000  Allan H Trautman, IBM Corporation
@@ -32,6 +32,7 @@
  * End Change Activity
  */
 
+#ifdef CONFIG_PCI
 extern u8   iSeries_Read_Byte(const volatile void __iomem * IoAddress);
 extern u16  iSeries_Read_Word(const volatile void __iomem * IoAddress);
 extern u32  iSeries_Read_Long(const volatile void __iomem * IoAddress);
@@ -44,6 +45,17 @@
 		size_t n);
 extern void iSeries_memcpy_fromio(void *dest,
 		const volatile void __iomem *source, size_t n);
+#else
+static inline u8 iSeries_Read_Byte(const volatile void __iomem *IoAddress)
+{
+	return 0xff;
+}
+
+static inline void iSeries_Write_Byte(u8 IoData,
+		volatile void __iomem *IoAddress)
+{
+}
+#endif	/* CONFIG_PCI */
 
 #endif /* CONFIG_PPC_ISERIES */
 #endif /* _ASM_POWERPC_ISERIES_ISERIES_IO_H */
diff --git a/include/asm-powerpc/iseries/it_exp_vpd_panel.h b/include/asm-powerpc/iseries/it_exp_vpd_panel.h
index 66a17a2..304a609 100644
--- a/include/asm-powerpc/iseries/it_exp_vpd_panel.h
+++ b/include/asm-powerpc/iseries/it_exp_vpd_panel.h
@@ -1,5 +1,4 @@
 /*
- * ItExtVpdPanel.h
  * Copyright (C) 2002  Dave Boutcher IBM Corporation
  *
  * This program is free software; you can redistribute it and/or modify
diff --git a/include/asm-powerpc/iseries/it_lp_naca.h b/include/asm-powerpc/iseries/it_lp_naca.h
index c3ef1de..4fdcf05 100644
--- a/include/asm-powerpc/iseries/it_lp_naca.h
+++ b/include/asm-powerpc/iseries/it_lp_naca.h
@@ -1,5 +1,4 @@
 /*
- * ItLpNaca.h
  * Copyright (C) 2001  Mike Corrigan IBM Corporation
  *
  * This program is free software; you can redistribute it and/or modify
@@ -37,17 +36,13 @@
 	u8	xLpIndex;		// LP Index			x0B-x0B
 	u16	xMaxLpQueues;		// Number of allocated queues	x0C-x0D
 	u16	xLpQueueOffset;		// Offset to start of LP queues	x0E-x0F
-	u8	xPirEnvironMode:8;	// Piranha or hardware		x10-x10
-	u8	xPirConsoleMode:8;	// Piranha console indicator	x11-x11
-	u8	xPirDasdMode:8;		// Piranha dasd indicator	x12-x12
+	u8	xPirEnvironMode;	// Piranha or hardware		x10-x10
+	u8	xPirConsoleMode;	// Piranha console indicator	x11-x11
+	u8	xPirDasdMode;		// Piranha dasd indicator	x12-x12
 	u8	xRsvd1_0[5];		// Reserved for Piranha related	x13-x17
-	u8	xLparInstalled:1;	// Is LPAR installed on system	x18-x1F
-	u8	xSysPartitioned:1;	// Is the system partitioned	...
-	u8	xHwSyncedTBs:1;		// Hardware synced TBs		...
-	u8	xIntProcUtilHmt:1;	// Utilize HMT for interrupts	...
-	u8	xRsvd1_1:4;		// Reserved			...
-	u8	xSpVpdFormat:8;		// VPD areas are in CSP format	...
-	u8	xIntProcRatio:8;	// Ratio of int procs to procs	...
+	u8	flags;			// flags, see below		x18-x1F
+	u8	xSpVpdFormat;		// VPD areas are in CSP format	...
+	u8	xIntProcRatio;		// Ratio of int procs to procs	...
 	u8	xRsvd1_2[5];		// Reserved			...
 	u16	xRsvd1_3;		// Reserved			x20-x21
 	u16	xPlicVrmIndex;		// VRM index of PLIC		x22-x23
@@ -77,4 +72,9 @@
 
 extern struct ItLpNaca		itLpNaca;
 
+#define ITLPNACA_LPAR		0x80	/* Is LPAR installed on the system */
+#define ITLPNACA_PARTITIONED	0x40	/* Is the system partitioned */
+#define ITLPNACA_HWSYNCEDTBS	0x20	/* Hardware synced TBs */
+#define ITLPNACA_HMTINT		0x10	/* Utilize MHT for interrupts */
+
 #endif /* _ASM_POWERPC_ISERIES_IT_LP_NACA_H */
diff --git a/include/asm-powerpc/iseries/it_lp_queue.h b/include/asm-powerpc/iseries/it_lp_queue.h
index a60d03a..b7c6fc1 100644
--- a/include/asm-powerpc/iseries/it_lp_queue.h
+++ b/include/asm-powerpc/iseries/it_lp_queue.h
@@ -1,5 +1,4 @@
 /*
- * ItLpQueue.h
  * Copyright (C) 2001  Mike Corrigan IBM Corporation
  *
  * This program is free software; you can redistribute it and/or modify
diff --git a/include/asm-powerpc/iseries/it_lp_reg_save.h b/include/asm-powerpc/iseries/it_lp_reg_save.h
index 81824e1..5403b75 100644
--- a/include/asm-powerpc/iseries/it_lp_reg_save.h
+++ b/include/asm-powerpc/iseries/it_lp_reg_save.h
@@ -1,5 +1,4 @@
 /*
- * ItLpRegSave.h
  * Copyright (C) 2001  Mike Corrigan IBM Corporation
  *
  * This program is free software; you can redistribute it and/or modify
@@ -83,4 +82,4 @@
 
 extern struct ItLpRegSave iseries_reg_save[];
 
-#endif /* _ITLPREGSAVE_H */
+#endif /* _ASM_POWERPC_ISERIES_IT_LP_REG_SAVE_H */
diff --git a/include/asm-powerpc/iseries/lpar_map.h b/include/asm-powerpc/iseries/lpar_map.h
index 84fc321..2ec384d 100644
--- a/include/asm-powerpc/iseries/lpar_map.h
+++ b/include/asm-powerpc/iseries/lpar_map.h
@@ -1,5 +1,4 @@
 /*
- * LparMap.h
  * Copyright (C) 2001  Mike Corrigan IBM Corporation
  *
  * This program is free software; you can redistribute it and/or modify
diff --git a/include/asm-powerpc/iseries/mf.h b/include/asm-powerpc/iseries/mf.h
index e7bd57a..857e520 100644
--- a/include/asm-powerpc/iseries/mf.h
+++ b/include/asm-powerpc/iseries/mf.h
@@ -1,5 +1,4 @@
 /*
- * mf.h
  * Copyright (C) 2001  Troy D. Armstrong IBM Corporation
  * Copyright (C) 2004  Stephen Rothwell IBM Corporation
  *
diff --git a/include/asm-powerpc/iseries/vio.h b/include/asm-powerpc/iseries/vio.h
index 7e3a469..72a97d3 100644
--- a/include/asm-powerpc/iseries/vio.h
+++ b/include/asm-powerpc/iseries/vio.h
@@ -1,5 +1,4 @@
 /* -*- linux-c -*-
- *  drivers/char/vio.h
  *
  *  iSeries Virtual I/O Message Path header
  *
diff --git a/include/asm-powerpc/kexec.h b/include/asm-powerpc/kexec.h
index 4263af3..fffdf69 100644
--- a/include/asm-powerpc/kexec.h
+++ b/include/asm-powerpc/kexec.h
@@ -38,9 +38,6 @@
 #ifdef CONFIG_KEXEC
 
 #define MAX_NOTE_BYTES 1024
-typedef u32 note_buf_t[MAX_NOTE_BYTES / sizeof(u32)];
-
-extern note_buf_t crash_notes[];
 
 #ifdef __powerpc64__
 extern void kexec_smp_wait(void);	/* get and clear naca physid, wait for
@@ -58,6 +55,12 @@
 
 #endif /* !CONFIG_KEXEC */
 
+/*
+ * Provide a dummy definition to avoid build failures. Will remain
+ * empty till crash dump support is enabled.
+ */
+static inline void crash_setup_regs(struct pt_regs *newregs,
+					struct pt_regs *oldregs) { }
 #endif /* ! __ASSEMBLY__ */
 #endif /* __KERNEL__ */
 #endif /* _ASM_POWERPC_KEXEC_H */
diff --git a/include/asm-powerpc/kprobes.h b/include/asm-powerpc/kprobes.h
index 0654f79..f466bc8 100644
--- a/include/asm-powerpc/kprobes.h
+++ b/include/asm-powerpc/kprobes.h
@@ -30,7 +30,10 @@
 #include <linux/ptrace.h>
 #include <linux/percpu.h>
 
+#define  __ARCH_WANT_KPROBES_INSN_SLOT
+
 struct pt_regs;
+struct kprobe;
 
 typedef unsigned int kprobe_opcode_t;
 #define BREAKPOINT_INSTRUCTION	0x7fe00008	/* trap */
@@ -48,6 +51,7 @@
 
 #define ARCH_SUPPORTS_KRETPROBES
 void kretprobe_trampoline(void);
+extern void arch_remove_kprobe(struct kprobe *p);
 
 /* Architecture specific copy of original instruction */
 struct arch_specific_insn {
@@ -69,15 +73,7 @@
 	struct prev_kprobe prev_kprobe;
 };
 
-#ifdef CONFIG_KPROBES
 extern int kprobe_exceptions_notify(struct notifier_block *self,
-				    unsigned long val, void *data);
-#else				/* !CONFIG_KPROBES */
-static inline int kprobe_exceptions_notify(struct notifier_block *self,
-					   unsigned long val, void *data)
-{
-	return 0;
-}
-#endif
+					unsigned long val, void *data);
 #endif /* __KERNEL__ */
 #endif	/* _ASM_POWERPC_KPROBES_H */
diff --git a/include/asm-powerpc/paca.h b/include/asm-powerpc/paca.h
index 3ae52d9..a64b4d4 100644
--- a/include/asm-powerpc/paca.h
+++ b/include/asm-powerpc/paca.h
@@ -65,6 +65,7 @@
 	u64 stab_real;			/* Absolute address of segment table */
 	u64 stab_addr;			/* Virtual address of segment table */
 	void *emergency_sp;		/* pointer to emergency stack */
+	u64 data_offset;		/* per cpu data offset */
 	s16 hw_cpu_id;			/* Physical processor number */
 	u8 cpu_start;			/* At startup, processor spins until */
 					/* this becomes non-zero. */
diff --git a/include/asm-powerpc/page.h b/include/asm-powerpc/page.h
index 76d7cb4..0b82df4 100644
--- a/include/asm-powerpc/page.h
+++ b/include/asm-powerpc/page.h
@@ -178,7 +178,7 @@
 #define pmd_val(x)	(x)
 #define __pmd(x)	(x)
 
-#ifndef CONFIG_PPC_64K_PAGES
+#if defined(CONFIG_PPC64) && !defined(CONFIG_PPC_64K_PAGES)
 typedef unsigned long pud_t;
 #define pud_val(x)	(x)
 #define __pud(x)	(x)
diff --git a/include/asm-powerpc/parport.h b/include/asm-powerpc/parport.h
index 897e49a..3fca21d 100644
--- a/include/asm-powerpc/parport.h
+++ b/include/asm-powerpc/parport.h
@@ -10,10 +10,34 @@
 #define _ASM_POWERPC_PARPORT_H
 #ifdef __KERNEL__
 
-static int __devinit parport_pc_find_isa_ports (int autoirq, int autodma);
+#include <asm/prom.h>
+
+extern struct parport *parport_pc_probe_port (unsigned long int base,
+                                              unsigned long int base_hi,
+                                              int irq, int dma,
+                                              struct pci_dev *dev);
+
 static int __devinit parport_pc_find_nonpci_ports (int autoirq, int autodma)
 {
-	return parport_pc_find_isa_ports (autoirq, autodma);
+	struct device_node *np;
+	u32 *prop;
+	u32 io1, io2;
+	int propsize;
+	int count = 0;
+	for (np = NULL; (np = of_find_compatible_node(np,
+						      "parallel",
+						      "pnpPNP,400")) != NULL;) {
+		prop = (u32 *)get_property(np, "reg", &propsize);
+		if (!prop || propsize > 6*sizeof(u32))
+			continue;
+		io1 = prop[1]; io2 = prop[2];
+		prop = (u32 *)get_property(np, "interrupts", NULL);
+		if (!prop)
+			continue;
+		if (parport_pc_probe_port(io1, io2, prop[0], autodma, NULL) != NULL)
+			count++;
+	}
+	return count;
 }
 
 #endif /* __KERNEL__ */
diff --git a/include/asm-powerpc/pci-bridge.h b/include/asm-powerpc/pci-bridge.h
index 1a08860..38de92d 100644
--- a/include/asm-powerpc/pci-bridge.h
+++ b/include/asm-powerpc/pci-bridge.h
@@ -61,16 +61,17 @@
 struct iommu_table;
 
 struct pci_dn {
-	int	busno;			/* for pci devices */
-	int	bussubno;		/* for pci devices */
-	int	devfn;			/* for pci devices */
+	int	busno;			/* pci bus number */
+	int	bussubno;		/* pci subordinate bus number */
+	int	devfn;			/* pci device and function number */
+	int	class_code;		/* pci device class */
 
 #ifdef CONFIG_PPC_PSERIES
 	int	eeh_mode;		/* See eeh.h for possible EEH_MODEs */
 	int	eeh_config_addr;
+	int	eeh_pe_config_addr; /* new-style partition endpoint address */
 	int 	eeh_check_count;	/* # times driver ignored error */
 	int 	eeh_freeze_count;	/* # times this device froze up. */
-	int	eeh_is_bridge;		/* device is pci-to-pci bridge */
 #endif
 	int	pci_ext_config_space;	/* for pci devices */
 	struct  pci_controller *phb;	/* for pci devices */
@@ -141,8 +142,6 @@
 
 extern int pcibios_remove_root_bus(struct pci_controller *phb);
 
-extern void phbs_remap_io(void);
-
 static inline struct pci_controller *pci_bus_to_host(struct pci_bus *bus)
 {
 	struct device_node *busdn = bus->sysdata;
diff --git a/include/asm-powerpc/percpu.h b/include/asm-powerpc/percpu.h
index 06a959d..e31922c 100644
--- a/include/asm-powerpc/percpu.h
+++ b/include/asm-powerpc/percpu.h
@@ -1 +1,57 @@
+#ifndef _ASM_POWERPC_PERCPU_H_
+#define _ASM_POWERPC_PERCPU_H_
+#ifdef __powerpc64__
+#include <linux/compiler.h>
+
+/*
+ * Same as asm-generic/percpu.h, except that we store the per cpu offset
+ * in the paca. Based on the x86-64 implementation.
+ */
+
+#ifdef CONFIG_SMP
+
+#include <asm/paca.h>
+
+#define __per_cpu_offset(cpu) (paca[cpu].data_offset)
+#define __my_cpu_offset() get_paca()->data_offset
+
+/* Separate out the type, so (int[3], foo) works. */
+#define DEFINE_PER_CPU(type, name) \
+    __attribute__((__section__(".data.percpu"))) __typeof__(type) per_cpu__##name
+
+/* var is in discarded region: offset to particular copy we want */
+#define per_cpu(var, cpu) (*RELOC_HIDE(&per_cpu__##var, __per_cpu_offset(cpu)))
+#define __get_cpu_var(var) (*RELOC_HIDE(&per_cpu__##var, __my_cpu_offset()))
+
+/* A macro to avoid #include hell... */
+#define percpu_modcopy(pcpudst, src, size)			\
+do {								\
+	unsigned int __i;					\
+	for (__i = 0; __i < NR_CPUS; __i++)			\
+		if (cpu_possible(__i))				\
+			memcpy((pcpudst)+__per_cpu_offset(__i),	\
+			       (src), (size));			\
+} while (0)
+
+extern void setup_per_cpu_areas(void);
+
+#else /* ! SMP */
+
+#define DEFINE_PER_CPU(type, name) \
+    __typeof__(type) per_cpu__##name
+
+#define per_cpu(var, cpu)			(*((void)(cpu), &per_cpu__##var))
+#define __get_cpu_var(var)			per_cpu__##var
+
+#endif	/* SMP */
+
+#define DECLARE_PER_CPU(type, name) extern __typeof__(type) per_cpu__##name
+
+#define EXPORT_PER_CPU_SYMBOL(var) EXPORT_SYMBOL(per_cpu__##var)
+#define EXPORT_PER_CPU_SYMBOL_GPL(var) EXPORT_SYMBOL_GPL(per_cpu__##var)
+
+#else
 #include <asm-generic/percpu.h>
+#endif
+
+#endif /* _ASM_POWERPC_PERCPU_H_ */
diff --git a/include/asm-powerpc/ppc-pci.h b/include/asm-powerpc/ppc-pci.h
index bdef312..f80482c 100644
--- a/include/asm-powerpc/ppc-pci.h
+++ b/include/asm-powerpc/ppc-pci.h
@@ -52,6 +52,21 @@
 
 /* ---- EEH internal-use-only related routines ---- */
 #ifdef CONFIG_EEH
+
+void pci_addr_cache_insert_device(struct pci_dev *dev);
+void pci_addr_cache_remove_device(struct pci_dev *dev);
+void pci_addr_cache_build(void);
+struct pci_dev *pci_get_device_by_addr(unsigned long addr);
+
+/**
+ * eeh_slot_error_detail -- record and EEH error condition to the log
+ * @severity: 1 if temporary, 2 if permanent failure.
+ *
+ * Obtains the the EEH error details from the RTAS subsystem,
+ * and then logs these details with the RTAS error log system.
+ */
+void eeh_slot_error_detail (struct pci_dn *pdn, int severity);
+
 /**
  * rtas_set_slot_reset -- unfreeze a frozen slot
  *
@@ -59,8 +74,10 @@
  * does this by asserting the PCI #RST line for 1/8th of
  * a second; this routine will sleep while the adapter is
  * being reset.
+ *
+ * Returns a non-zero value if the reset failed.
  */
-void rtas_set_slot_reset (struct pci_dn *);
+int rtas_set_slot_reset (struct pci_dn *);
 
 /** 
  * eeh_restore_bars - Restore device configuration info.
@@ -84,6 +101,7 @@
 void rtas_configure_bridge(struct pci_dn *);
 
 int rtas_write_config(struct pci_dn *, int where, int size, u32 val);
+int rtas_read_config(struct pci_dn *, int where, int size, u32 *val);
 
 /**
  * mark and clear slots: find "partition endpoint" PE and set or 
@@ -92,6 +110,9 @@
 void eeh_mark_slot (struct device_node *dn, int mode_flag);
 void eeh_clear_slot (struct device_node *dn, int mode_flag);
 
+/* Find the associated "Partiationable Endpoint" PE */
+struct device_node * find_device_pe(struct device_node *dn);
+
 #endif
 
 #endif /* __KERNEL__ */
diff --git a/include/asm-powerpc/rtas.h b/include/asm-powerpc/rtas.h
index 3428889..f43c683 100644
--- a/include/asm-powerpc/rtas.h
+++ b/include/asm-powerpc/rtas.h
@@ -161,7 +161,6 @@
 extern void enter_rtas(unsigned long);
 extern int rtas_token(const char *service);
 extern int rtas_call(int token, int, int, int *, ...);
-extern void call_rtas_display_status(unsigned char);
 extern void rtas_restart(char *cmd);
 extern void rtas_power_off(void);
 extern void rtas_halt(void);
diff --git a/include/asm-powerpc/serial.h b/include/asm-powerpc/serial.h
index 6dc9546..3e8589b 100644
--- a/include/asm-powerpc/serial.h
+++ b/include/asm-powerpc/serial.h
@@ -15,6 +15,10 @@
 /* Default baud base if not found in device-tree */
 #define BASE_BAUD ( 1843200 / 16 )
 
+#ifdef CONFIG_PPC_UDBG_16550
 extern void find_legacy_serial_ports(void);
+#else
+#define find_legacy_serial_ports()	do { } while (0)
+#endif
 
 #endif /* _PPC64_SERIAL_H */
diff --git a/include/asm-powerpc/system.h b/include/asm-powerpc/system.h
index 0c58e32..9b822af 100644
--- a/include/asm-powerpc/system.h
+++ b/include/asm-powerpc/system.h
@@ -133,6 +133,14 @@
 extern void cvt_fd(float *from, double *to, struct thread_struct *thread);
 extern void cvt_df(double *from, float *to, struct thread_struct *thread);
 
+#ifndef CONFIG_SMP
+extern void discard_lazy_cpu_state(void);
+#else
+static inline void discard_lazy_cpu_state(void)
+{
+}
+#endif
+
 #ifdef CONFIG_ALTIVEC
 extern void flush_altivec_to_thread(struct task_struct *);
 #else
@@ -175,6 +183,16 @@
 extern struct task_struct *_switch(struct thread_struct *prev,
 				   struct thread_struct *next);
 
+/*
+ * On SMP systems, when the scheduler does migration-cost autodetection,
+ * it needs a way to flush as much of the CPU's caches as possible.
+ *
+ * TODO: fill this in!
+ */
+static inline void sched_cacheflush(void)
+{
+}
+
 extern unsigned int rtas_data;
 extern int mem_init_done;	/* set on boot once kmalloc can be called */
 extern unsigned long memory_limit;
diff --git a/include/asm-powerpc/thread_info.h b/include/asm-powerpc/thread_info.h
index ac1e80e..7e09d7c 100644
--- a/include/asm-powerpc/thread_info.h
+++ b/include/asm-powerpc/thread_info.h
@@ -89,9 +89,6 @@
 
 #endif /* THREAD_SHIFT < PAGE_SHIFT */
 
-#define get_thread_info(ti)	get_task_struct((ti)->task)
-#define put_thread_info(ti)	put_task_struct((ti)->task)
-
 /* how to get the thread information struct from C */
 static inline struct thread_info *current_thread_info(void)
 {
diff --git a/include/asm-powerpc/topology.h b/include/asm-powerpc/topology.h
index 9f3d4da..1e19cd0 100644
--- a/include/asm-powerpc/topology.h
+++ b/include/asm-powerpc/topology.h
@@ -39,7 +39,6 @@
 	.max_interval		= 32,			\
 	.busy_factor		= 32,			\
 	.imbalance_pct		= 125,			\
-	.cache_hot_time		= (10*1000000),		\
 	.cache_nice_tries	= 1,			\
 	.per_cpu_gain		= 100,			\
 	.busy_idx		= 3,			\
diff --git a/include/asm-powerpc/udbg.h b/include/asm-powerpc/udbg.h
index 479f2d8..5c4236c3 100644
--- a/include/asm-powerpc/udbg.h
+++ b/include/asm-powerpc/udbg.h
@@ -1,5 +1,5 @@
 /*
- * c 2001 PPC 64 Team, IBM Corp
+ * (c) 2001, 2006 IBM Corporation.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -36,5 +36,12 @@
 extern int udbg_adb_init(int force_btext);
 extern void udbg_adb_init_early(void);
 
+extern void __init udbg_early_init(void);
+extern void __init udbg_init_debug_lpar(void);
+extern void __init udbg_init_pmac_realmode(void);
+extern void __init udbg_init_maple_realmode(void);
+extern void __init udbg_init_iseries(void);
+extern void __init udbg_init_rtas(void);
+
 #endif /* __KERNEL__ */
 #endif /* _ASM_POWERPC_UDBG_H */
diff --git a/include/asm-ppc/system.h b/include/asm-ppc/system.h
index bd99cb5..fb49c0c 100644
--- a/include/asm-ppc/system.h
+++ b/include/asm-ppc/system.h
@@ -4,7 +4,6 @@
 #ifndef __PPC_SYSTEM_H
 #define __PPC_SYSTEM_H
 
-#include <linux/config.h>
 #include <linux/kernel.h>
 
 #include <asm/atomic.h>
@@ -39,7 +38,7 @@
 #ifdef CONFIG_SMP
 #define smp_mb()	mb()
 #define smp_rmb()	rmb()
-#define smp_wmb()	wmb()
+#define smp_wmb()	__asm__ __volatile__ ("eieio" : : : "memory")
 #define smp_read_barrier_depends()	read_barrier_depends()
 #else
 #define smp_mb()	barrier()
@@ -74,6 +73,7 @@
 extern void read_rtc_time(void);
 extern void pmac_find_display(void);
 extern void giveup_fpu(struct task_struct *);
+extern void disable_kernel_fp(void);
 extern void enable_kernel_fp(void);
 extern void flush_fp_to_thread(struct task_struct *);
 extern void enable_kernel_altivec(void);
@@ -86,6 +86,14 @@
 extern void cvt_fd(float *from, double *to, struct thread_struct *thread);
 extern void cvt_df(double *from, float *to, struct thread_struct *thread);
 
+#ifndef CONFIG_SMP
+extern void discard_lazy_cpu_state(void);
+#else
+static inline void discard_lazy_cpu_state(void)
+{
+}
+#endif
+
 #ifdef CONFIG_ALTIVEC
 extern void flush_altivec_to_thread(struct task_struct *);
 #else
@@ -123,6 +131,16 @@
 	struct task_struct *);
 #define switch_to(prev, next, last)	((last) = __switch_to((prev), (next)))
 
+/*
+ * On SMP systems, when the scheduler does migration-cost autodetection,
+ * it needs a way to flush as much of the CPU's caches as possible.
+ *
+ * TODO: fill this in!
+ */
+static inline void sched_cacheflush(void)
+{
+}
+
 struct thread_struct;
 extern struct task_struct *_switch(struct thread_struct *prev,
 				   struct thread_struct *next);
diff --git a/include/asm-s390/elf.h b/include/asm-s390/elf.h
index 372d51c..710646e 100644
--- a/include/asm-s390/elf.h
+++ b/include/asm-s390/elf.h
@@ -163,7 +163,7 @@
 
 static inline int dump_task_regs(struct task_struct *tsk, elf_gregset_t *regs)
 {
-	struct pt_regs *ptregs = __KSTK_PTREGS(tsk);
+	struct pt_regs *ptregs = task_pt_regs(tsk);
 	memcpy(&regs->psw, &ptregs->psw, sizeof(regs->psw)+sizeof(regs->gprs));
 	memcpy(regs->acrs, tsk->thread.acrs, sizeof(regs->acrs));
 	regs->orig_gpr2 = ptregs->orig_gpr2;
diff --git a/include/asm-s390/ioctl.h b/include/asm-s390/ioctl.h
index df73943..b279fe0 100644
--- a/include/asm-s390/ioctl.h
+++ b/include/asm-s390/ioctl.h
@@ -1,88 +1 @@
-/*
- *  include/asm-s390/ioctl.h
- *
- *  S390 version
- *
- *  Derived from "include/asm-i386/ioctl.h"
- */
-
-#ifndef _S390_IOCTL_H
-#define _S390_IOCTL_H
-
-/* ioctl command encoding: 32 bits total, command in lower 16 bits,
- * size of the parameter structure in the lower 14 bits of the
- * upper 16 bits.
- * Encoding the size of the parameter structure in the ioctl request
- * is useful for catching programs compiled with old versions
- * and to avoid overwriting user space outside the user buffer area.
- * The highest 2 bits are reserved for indicating the ``access mode''.
- * NOTE: This limits the max parameter size to 16kB -1 !
- */
-
-/*
- * The following is for compatibility across the various Linux
- * platforms.  The i386 ioctl numbering scheme doesn't really enforce
- * a type field.  De facto, however, the top 8 bits of the lower 16
- * bits are indeed used as a type field, so we might just as well make
- * this explicit here.  Please be sure to use the decoding macros
- * below from now on.
- */
-#define _IOC_NRBITS	8
-#define _IOC_TYPEBITS	8
-#define _IOC_SIZEBITS	14
-#define _IOC_DIRBITS	2
-
-#define _IOC_NRMASK	((1 << _IOC_NRBITS)-1)
-#define _IOC_TYPEMASK	((1 << _IOC_TYPEBITS)-1)
-#define _IOC_SIZEMASK	((1 << _IOC_SIZEBITS)-1)
-#define _IOC_DIRMASK	((1 << _IOC_DIRBITS)-1)
-
-#define _IOC_NRSHIFT	0
-#define _IOC_TYPESHIFT	(_IOC_NRSHIFT+_IOC_NRBITS)
-#define _IOC_SIZESHIFT	(_IOC_TYPESHIFT+_IOC_TYPEBITS)
-#define _IOC_DIRSHIFT	(_IOC_SIZESHIFT+_IOC_SIZEBITS)
-
-/*
- * Direction bits.
- */
-#define _IOC_NONE	0U
-#define _IOC_WRITE	1U
-#define _IOC_READ	2U
-
-#define _IOC(dir,type,nr,size) \
-	(((dir)  << _IOC_DIRSHIFT) | \
-	 ((type) << _IOC_TYPESHIFT) | \
-	 ((nr)   << _IOC_NRSHIFT) | \
-	 ((size) << _IOC_SIZESHIFT))
-
-/* provoke compile error for invalid uses of size argument */
-extern unsigned long __invalid_size_argument_for_IOC;
-#define _IOC_TYPECHECK(t) \
-	((sizeof(t) == sizeof(t[1]) && \
-	  sizeof(t) < (1 << _IOC_SIZEBITS)) ? \
-	  sizeof(t) : __invalid_size_argument_for_IOC)
-
-/* used to create numbers */
-#define _IO(type,nr)		_IOC(_IOC_NONE,(type),(nr),0)
-#define _IOR(type,nr,size)	_IOC(_IOC_READ,(type),(nr),(_IOC_TYPECHECK(size)))
-#define _IOW(type,nr,size)	_IOC(_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
-#define _IOWR(type,nr,size)	_IOC(_IOC_READ|_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
-#define _IOR_BAD(type,nr,size)	_IOC(_IOC_READ,(type),(nr),sizeof(size))
-#define _IOW_BAD(type,nr,size)	_IOC(_IOC_WRITE,(type),(nr),sizeof(size))
-#define _IOWR_BAD(type,nr,size)	_IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
-
-/* used to decode ioctl numbers.. */
-#define _IOC_DIR(nr)		(((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
-#define _IOC_TYPE(nr)		(((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
-#define _IOC_NR(nr)		(((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
-#define _IOC_SIZE(nr)		(((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
-
-/* ...and for the drivers/sound files... */
-
-#define IOC_IN		(_IOC_WRITE << _IOC_DIRSHIFT)
-#define IOC_OUT		(_IOC_READ << _IOC_DIRSHIFT)
-#define IOC_INOUT	((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
-#define IOCSIZE_MASK	(_IOC_SIZEMASK << _IOC_SIZESHIFT)
-#define IOCSIZE_SHIFT	(_IOC_SIZESHIFT)
-
-#endif /* _S390_IOCTL_H */
+#include <asm-generic/ioctl.h>
diff --git a/include/asm-s390/kexec.h b/include/asm-s390/kexec.h
index 54cf7d9..ce28ddd 100644
--- a/include/asm-s390/kexec.h
+++ b/include/asm-s390/kexec.h
@@ -35,8 +35,9 @@
 #define KEXEC_ARCH KEXEC_ARCH_S390
 
 #define MAX_NOTE_BYTES 1024
-typedef u32 note_buf_t[MAX_NOTE_BYTES/4];
 
-extern note_buf_t crash_notes[];
+/* Provide a dummy definition to avoid build failures. */
+static inline void crash_setup_regs(struct pt_regs *newregs,
+					struct pt_regs *oldregs) { }
 
 #endif /*_S390_KEXEC_H */
diff --git a/include/asm-s390/processor.h b/include/asm-s390/processor.h
index 4ec652e..c5cbc4b 100644
--- a/include/asm-s390/processor.h
+++ b/include/asm-s390/processor.h
@@ -191,10 +191,10 @@
 extern void show_trace(struct task_struct *task, unsigned long *sp);
 
 unsigned long get_wchan(struct task_struct *p);
-#define __KSTK_PTREGS(tsk) ((struct pt_regs *) \
-        ((unsigned long) tsk->thread_info + THREAD_SIZE - sizeof(struct pt_regs)))
-#define KSTK_EIP(tsk)	(__KSTK_PTREGS(tsk)->psw.addr)
-#define KSTK_ESP(tsk)	(__KSTK_PTREGS(tsk)->gprs[15])
+#define task_pt_regs(tsk) ((struct pt_regs *) \
+        (task_stack_page(tsk) + THREAD_SIZE) - 1)
+#define KSTK_EIP(tsk)	(task_pt_regs(tsk)->psw.addr)
+#define KSTK_ESP(tsk)	(task_pt_regs(tsk)->gprs[15])
 
 /*
  * Give up the time slice of the virtual PU.
diff --git a/include/asm-s390/system.h b/include/asm-s390/system.h
index 864cae7..c7c3a9a 100644
--- a/include/asm-s390/system.h
+++ b/include/asm-s390/system.h
@@ -104,6 +104,16 @@
 	prev = __switch_to(prev,next);					     \
 } while (0)
 
+/*
+ * On SMP systems, when the scheduler does migration-cost autodetection,
+ * it needs a way to flush as much of the CPU's caches as possible.
+ *
+ * TODO: fill this in!
+ */
+static inline void sched_cacheflush(void)
+{
+}
+
 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
 extern void account_user_vtime(struct task_struct *);
 extern void account_system_vtime(struct task_struct *);
diff --git a/include/asm-s390/thread_info.h b/include/asm-s390/thread_info.h
index 6c18a3f..f3797a5 100644
--- a/include/asm-s390/thread_info.h
+++ b/include/asm-s390/thread_info.h
@@ -81,8 +81,6 @@
 #define alloc_thread_info(tsk) ((struct thread_info *) \
 	__get_free_pages(GFP_KERNEL,THREAD_ORDER))
 #define free_thread_info(ti) free_pages((unsigned long) (ti),THREAD_ORDER)
-#define get_thread_info(ti) get_task_struct((ti)->task)
-#define put_thread_info(ti) put_task_struct((ti)->task)
 
 #endif
 
diff --git a/include/asm-sh/ioctl.h b/include/asm-sh/ioctl.h
index 524700e..b279fe0 100644
--- a/include/asm-sh/ioctl.h
+++ b/include/asm-sh/ioctl.h
@@ -1,75 +1 @@
-/* $Id: ioctl.h,v 1.1.1.1 2001/10/15 20:45:09 mrbrown Exp $
- *
- * linux/ioctl.h for Linux by H.H. Bergman.
- */
-
-#ifndef __ASM_SH_IOCTL_H
-#define __ASM_SH_IOCTL_H
-
-/* ioctl command encoding: 32 bits total, command in lower 16 bits,
- * size of the parameter structure in the lower 14 bits of the
- * upper 16 bits.
- * Encoding the size of the parameter structure in the ioctl request
- * is useful for catching programs compiled with old versions
- * and to avoid overwriting user space outside the user buffer area.
- * The highest 2 bits are reserved for indicating the ``access mode''.
- * NOTE: This limits the max parameter size to 16kB -1 !
- */
-
-/*
- * The following is for compatibility across the various Linux
- * platforms.  The i386 ioctl numbering scheme doesn't really enforce
- * a type field.  De facto, however, the top 8 bits of the lower 16
- * bits are indeed used as a type field, so we might just as well make
- * this explicit here.  Please be sure to use the decoding macros
- * below from now on.
- */
-#define _IOC_NRBITS	8
-#define _IOC_TYPEBITS	8
-#define _IOC_SIZEBITS	14
-#define _IOC_DIRBITS	2
-
-#define _IOC_NRMASK	((1 << _IOC_NRBITS)-1)
-#define _IOC_TYPEMASK	((1 << _IOC_TYPEBITS)-1)
-#define _IOC_SIZEMASK	((1 << _IOC_SIZEBITS)-1)
-#define _IOC_DIRMASK	((1 << _IOC_DIRBITS)-1)
-
-#define _IOC_NRSHIFT	0
-#define _IOC_TYPESHIFT	(_IOC_NRSHIFT+_IOC_NRBITS)
-#define _IOC_SIZESHIFT	(_IOC_TYPESHIFT+_IOC_TYPEBITS)
-#define _IOC_DIRSHIFT	(_IOC_SIZESHIFT+_IOC_SIZEBITS)
-
-/*
- * Direction bits.
- */
-#define _IOC_NONE	0U
-#define _IOC_WRITE	1U
-#define _IOC_READ	2U
-
-#define _IOC(dir,type,nr,size) \
-	(((dir)  << _IOC_DIRSHIFT) | \
-	 ((type) << _IOC_TYPESHIFT) | \
-	 ((nr)   << _IOC_NRSHIFT) | \
-	 ((size) << _IOC_SIZESHIFT))
-
-/* used to create numbers */
-#define _IO(type,nr)		_IOC(_IOC_NONE,(type),(nr),0)
-#define _IOR(type,nr,size)	_IOC(_IOC_READ,(type),(nr),sizeof(size))
-#define _IOW(type,nr,size)	_IOC(_IOC_WRITE,(type),(nr),sizeof(size))
-#define _IOWR(type,nr,size)	_IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
-
-/* used to decode ioctl numbers.. */
-#define _IOC_DIR(nr)		(((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
-#define _IOC_TYPE(nr)		(((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
-#define _IOC_NR(nr)		(((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
-#define _IOC_SIZE(nr)		(((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
-
-/* ...and for the drivers/sound files... */
-
-#define IOC_IN		(_IOC_WRITE << _IOC_DIRSHIFT)
-#define IOC_OUT		(_IOC_READ << _IOC_DIRSHIFT)
-#define IOC_INOUT	((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
-#define IOCSIZE_MASK	(_IOC_SIZEMASK << _IOC_SIZESHIFT)
-#define IOCSIZE_SHIFT	(_IOC_SIZESHIFT)
-
-#endif /* __ASM_SH_IOCTL_H */
+#include <asm-generic/ioctl.h>
diff --git a/include/asm-sh/ptrace.h b/include/asm-sh/ptrace.h
index 0f75e16..792fc35 100644
--- a/include/asm-sh/ptrace.h
+++ b/include/asm-sh/ptrace.h
@@ -91,6 +91,16 @@
 #define instruction_pointer(regs) ((regs)->pc)
 extern void show_regs(struct pt_regs *);
 
+#ifdef CONFIG_SH_DSP
+#define task_pt_regs(task) \
+	((struct pt_regs *) (task_stack_page(task) + THREAD_SIZE \
+		 - sizeof(struct pt_dspregs) - sizeof(unsigned long)) - 1)
+#else
+#define task_pt_regs(task) \
+	((struct pt_regs *) (task_stack_page(task) + THREAD_SIZE \
+		 - sizeof(unsigned long)) - 1)
+#endif
+
 static inline unsigned long profile_pc(struct pt_regs *regs)
 {
 	unsigned long pc = instruction_pointer(regs);
diff --git a/include/asm-sh/system.h b/include/asm-sh/system.h
index 28a3c2d..bb03304 100644
--- a/include/asm-sh/system.h
+++ b/include/asm-sh/system.h
@@ -57,6 +57,16 @@
 	last = __last;							\
 } while (0)
 
+/*
+ * On SMP systems, when the scheduler does migration-cost autodetection,
+ * it needs a way to flush as much of the CPU's caches as possible.
+ *
+ * TODO: fill this in!
+ */
+static inline void sched_cacheflush(void)
+{
+}
+
 #define nop() __asm__ __volatile__ ("nop")
 
 
diff --git a/include/asm-sh/thread_info.h b/include/asm-sh/thread_info.h
index 46080ce..85f0c11 100644
--- a/include/asm-sh/thread_info.h
+++ b/include/asm-sh/thread_info.h
@@ -60,8 +60,6 @@
 #define THREAD_SIZE (2*PAGE_SIZE)
 #define alloc_thread_info(ti) ((struct thread_info *) __get_free_pages(GFP_KERNEL,1))
 #define free_thread_info(ti) free_pages((unsigned long) (ti), 1)
-#define get_thread_info(ti) get_task_struct((ti)->task)
-#define put_thread_info(ti) put_task_struct((ti)->task)
 
 #else /* !__ASSEMBLY__ */
 
diff --git a/include/asm-sh64/io.h b/include/asm-sh64/io.h
index cfafaa7..dee4f77 100644
--- a/include/asm-sh64/io.h
+++ b/include/asm-sh64/io.h
@@ -143,12 +143,12 @@
  * Change virtual addresses to physical addresses and vv.
  * These are trivial on the 1:1 Linux/SuperH mapping
  */
-extern __inline__ unsigned long virt_to_phys(volatile void * address)
+static inline unsigned long virt_to_phys(volatile void * address)
 {
 	return __pa(address);
 }
 
-extern __inline__ void * phys_to_virt(unsigned long address)
+static inline void * phys_to_virt(unsigned long address)
 {
 	return __va(address);
 }
@@ -156,12 +156,12 @@
 extern void * __ioremap(unsigned long phys_addr, unsigned long size,
 			unsigned long flags);
 
-extern __inline__ void * ioremap(unsigned long phys_addr, unsigned long size)
+static inline void * ioremap(unsigned long phys_addr, unsigned long size)
 {
 	return __ioremap(phys_addr, size, 1);
 }
 
-extern __inline__ void * ioremap_nocache (unsigned long phys_addr, unsigned long size)
+static inline void * ioremap_nocache (unsigned long phys_addr, unsigned long size)
 {
 	return __ioremap(phys_addr, size, 0);
 }
diff --git a/include/asm-sh64/ioctl.h b/include/asm-sh64/ioctl.h
index c089a6f..b279fe0 100644
--- a/include/asm-sh64/ioctl.h
+++ b/include/asm-sh64/ioctl.h
@@ -1,83 +1 @@
-#ifndef __ASM_SH64_IOCTL_H
-#define __ASM_SH64_IOCTL_H
-
-/*
- * 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.
- *
- * include/asm-sh64/ioctl.h
- *
- * Copyright (C) 2000, 2001  Paolo Alberelli
- *
- * linux/ioctl.h for Linux by H.H. Bergman.
- *
- */
-
-/* ioctl command encoding: 32 bits total, command in lower 16 bits,
- * size of the parameter structure in the lower 14 bits of the
- * upper 16 bits.
- * Encoding the size of the parameter structure in the ioctl request
- * is useful for catching programs compiled with old versions
- * and to avoid overwriting user space outside the user buffer area.
- * The highest 2 bits are reserved for indicating the ``access mode''.
- * NOTE: This limits the max parameter size to 16kB -1 !
- */
-
-/*
- * The following is for compatibility across the various Linux
- * platforms.  The i386 ioctl numbering scheme doesn't really enforce
- * a type field.  De facto, however, the top 8 bits of the lower 16
- * bits are indeed used as a type field, so we might just as well make
- * this explicit here.  Please be sure to use the decoding macros
- * below from now on.
- */
-#define _IOC_NRBITS	8
-#define _IOC_TYPEBITS	8
-#define _IOC_SIZEBITS	14
-#define _IOC_DIRBITS	2
-
-#define _IOC_NRMASK	((1 << _IOC_NRBITS)-1)
-#define _IOC_TYPEMASK	((1 << _IOC_TYPEBITS)-1)
-#define _IOC_SIZEMASK	((1 << _IOC_SIZEBITS)-1)
-#define _IOC_DIRMASK	((1 << _IOC_DIRBITS)-1)
-
-#define _IOC_NRSHIFT	0
-#define _IOC_TYPESHIFT	(_IOC_NRSHIFT+_IOC_NRBITS)
-#define _IOC_SIZESHIFT	(_IOC_TYPESHIFT+_IOC_TYPEBITS)
-#define _IOC_DIRSHIFT	(_IOC_SIZESHIFT+_IOC_SIZEBITS)
-
-/*
- * Direction bits.
- */
-#define _IOC_NONE	0U
-#define _IOC_WRITE	1U
-#define _IOC_READ	2U
-
-#define _IOC(dir,type,nr,size) \
-	(((dir)  << _IOC_DIRSHIFT) | \
-	 ((type) << _IOC_TYPESHIFT) | \
-	 ((nr)   << _IOC_NRSHIFT) | \
-	 ((size) << _IOC_SIZESHIFT))
-
-/* used to create numbers */
-#define _IO(type,nr)		_IOC(_IOC_NONE,(type),(nr),0)
-#define _IOR(type,nr,size)	_IOC(_IOC_READ,(type),(nr),sizeof(size))
-#define _IOW(type,nr,size)	_IOC(_IOC_WRITE,(type),(nr),sizeof(size))
-#define _IOWR(type,nr,size)	_IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
-
-/* used to decode ioctl numbers.. */
-#define _IOC_DIR(nr)		(((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
-#define _IOC_TYPE(nr)		(((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
-#define _IOC_NR(nr)		(((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
-#define _IOC_SIZE(nr)		(((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
-
-/* ...and for the drivers/sound files... */
-
-#define IOC_IN		(_IOC_WRITE << _IOC_DIRSHIFT)
-#define IOC_OUT		(_IOC_READ << _IOC_DIRSHIFT)
-#define IOC_INOUT	((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
-#define IOCSIZE_MASK	(_IOC_SIZEMASK << _IOC_SIZESHIFT)
-#define IOCSIZE_SHIFT	(_IOC_SIZESHIFT)
-
-#endif /* __ASM_SH64_IOCTL_H */
+#include <asm-generic/ioctl.h>
diff --git a/include/asm-sh64/mmu_context.h b/include/asm-sh64/mmu_context.h
index f062e15..991cfda 100644
--- a/include/asm-sh64/mmu_context.h
+++ b/include/asm-sh64/mmu_context.h
@@ -50,7 +50,7 @@
  */
 #define MMU_VPN_MASK	0xfffff000
 
-extern __inline__ void
+static inline void
 get_new_mmu_context(struct mm_struct *mm)
 {
 	extern void flush_tlb_all(void);
diff --git a/include/asm-sh64/pgalloc.h b/include/asm-sh64/pgalloc.h
index b25f5df..678251a 100644
--- a/include/asm-sh64/pgalloc.h
+++ b/include/asm-sh64/pgalloc.h
@@ -38,14 +38,14 @@
  * if any.
  */
 
-extern __inline__ pgd_t *get_pgd_slow(void)
+static inline pgd_t *get_pgd_slow(void)
 {
 	unsigned int pgd_size = (USER_PTRS_PER_PGD * sizeof(pgd_t));
 	pgd_t *ret = (pgd_t *)kmalloc(pgd_size, GFP_KERNEL);
 	return ret;
 }
 
-extern __inline__ pgd_t *get_pgd_fast(void)
+static inline pgd_t *get_pgd_fast(void)
 {
 	unsigned long *ret;
 
@@ -62,14 +62,14 @@
 	return (pgd_t *)ret;
 }
 
-extern __inline__ void free_pgd_fast(pgd_t *pgd)
+static inline void free_pgd_fast(pgd_t *pgd)
 {
 	*(unsigned long *)pgd = (unsigned long) pgd_quicklist;
 	pgd_quicklist = (unsigned long *) pgd;
 	pgtable_cache_size++;
 }
 
-extern __inline__ void free_pgd_slow(pgd_t *pgd)
+static inline void free_pgd_slow(pgd_t *pgd)
 {
 	kfree((void *)pgd);
 }
@@ -77,7 +77,7 @@
 extern pte_t *get_pte_slow(pmd_t *pmd, unsigned long address_preadjusted);
 extern pte_t *get_pte_kernel_slow(pmd_t *pmd, unsigned long address_preadjusted);
 
-extern __inline__ pte_t *get_pte_fast(void)
+static inline pte_t *get_pte_fast(void)
 {
 	unsigned long *ret;
 
@@ -89,7 +89,7 @@
 	return (pte_t *)ret;
 }
 
-extern __inline__ void free_pte_fast(pte_t *pte)
+static inline void free_pte_fast(pte_t *pte)
 {
 	*(unsigned long *)pte = (unsigned long) pte_quicklist;
 	pte_quicklist = (unsigned long *) pte;
@@ -167,7 +167,7 @@
 
 extern int do_check_pgt_cache(int, int);
 
-extern inline void set_pgdir(unsigned long address, pgd_t entry)
+static inline void set_pgdir(unsigned long address, pgd_t entry)
 {
 	struct task_struct * p;
 	pgd_t *pgd;
diff --git a/include/asm-sh64/pgtable.h b/include/asm-sh64/pgtable.h
index a1906a7..57af6b3 100644
--- a/include/asm-sh64/pgtable.h
+++ b/include/asm-sh64/pgtable.h
@@ -421,18 +421,18 @@
 static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; }
 static inline int pte_write(pte_t pte){ return pte_val(pte) & _PAGE_WRITE; }
 
-extern inline pte_t pte_rdprotect(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_READ)); return pte; }
-extern inline pte_t pte_wrprotect(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_WRITE)); return pte; }
-extern inline pte_t pte_exprotect(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_EXECUTE)); return pte; }
-extern inline pte_t pte_mkclean(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_DIRTY)); return pte; }
-extern inline pte_t pte_mkold(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_ACCESSED)); return pte; }
+static inline pte_t pte_rdprotect(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_READ)); return pte; }
+static inline pte_t pte_wrprotect(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_WRITE)); return pte; }
+static inline pte_t pte_exprotect(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_EXECUTE)); return pte; }
+static inline pte_t pte_mkclean(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_DIRTY)); return pte; }
+static inline pte_t pte_mkold(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_ACCESSED)); return pte; }
 
-extern inline pte_t pte_mkread(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) | _PAGE_READ)); return pte; }
-extern inline pte_t pte_mkwrite(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) | _PAGE_WRITE)); return pte; }
-extern inline pte_t pte_mkexec(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) | _PAGE_EXECUTE)); return pte; }
-extern inline pte_t pte_mkdirty(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) | _PAGE_DIRTY)); return pte; }
-extern inline pte_t pte_mkyoung(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) | _PAGE_ACCESSED)); return pte; }
-extern inline pte_t pte_mkhuge(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) | _PAGE_SZHUGE)); return pte; }
+static inline pte_t pte_mkread(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) | _PAGE_READ)); return pte; }
+static inline pte_t pte_mkwrite(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) | _PAGE_WRITE)); return pte; }
+static inline pte_t pte_mkexec(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) | _PAGE_EXECUTE)); return pte; }
+static inline pte_t pte_mkdirty(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) | _PAGE_DIRTY)); return pte; }
+static inline pte_t pte_mkyoung(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) | _PAGE_ACCESSED)); return pte; }
+static inline pte_t pte_mkhuge(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) | _PAGE_SZHUGE)); return pte; }
 
 
 /*
@@ -456,7 +456,7 @@
 #define mk_pte_phys(physpage, pgprot) \
 ({ pte_t __pte; set_pte(&__pte, __pte(physpage | pgprot_val(pgprot))); __pte; })
 
-extern inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
+static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
 { set_pte(&pte, __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot))); return pte; }
 
 typedef pte_t *pte_addr_t;
diff --git a/include/asm-sh64/processor.h b/include/asm-sh64/processor.h
index a51bd41..1bf252d 100644
--- a/include/asm-sh64/processor.h
+++ b/include/asm-sh64/processor.h
@@ -228,7 +228,7 @@
  * FPU lazy state save handling.
  */
 
-extern __inline__ void release_fpu(void)
+static inline void release_fpu(void)
 {
 	unsigned long long __dummy;
 
@@ -240,7 +240,7 @@
 			     : "r" (SR_FD));
 }
 
-extern __inline__ void grab_fpu(void)
+static inline void grab_fpu(void)
 {
 	unsigned long long __dummy;
 
diff --git a/include/asm-sh64/system.h b/include/asm-sh64/system.h
index 42510e4..3002e988 100644
--- a/include/asm-sh64/system.h
+++ b/include/asm-sh64/system.h
@@ -132,7 +132,7 @@
 	(flags != 0);			\
 })
 
-extern __inline__ unsigned long xchg_u32(volatile int * m, unsigned long val)
+static inline unsigned long xchg_u32(volatile int * m, unsigned long val)
 {
 	unsigned long flags, retval;
 
@@ -143,7 +143,7 @@
 	return retval;
 }
 
-extern __inline__ unsigned long xchg_u8(volatile unsigned char * m, unsigned long val)
+static inline unsigned long xchg_u8(volatile unsigned char * m, unsigned long val)
 {
 	unsigned long flags, retval;
 
diff --git a/include/asm-sh64/thread_info.h b/include/asm-sh64/thread_info.h
index 10f024c..1f825cb 100644
--- a/include/asm-sh64/thread_info.h
+++ b/include/asm-sh64/thread_info.h
@@ -66,8 +66,6 @@
 
 #define alloc_thread_info(ti) ((struct thread_info *) __get_free_pages(GFP_KERNEL,1))
 #define free_thread_info(ti) free_pages((unsigned long) (ti), 1)
-#define get_thread_info(ti) get_task_struct((ti)->task)
-#define put_thread_info(ti) put_task_struct((ti)->task)
 
 #endif /* __ASSEMBLY__ */
 
diff --git a/include/asm-sh64/tlbflush.h b/include/asm-sh64/tlbflush.h
index 15c0719..e45bead 100644
--- a/include/asm-sh64/tlbflush.h
+++ b/include/asm-sh64/tlbflush.h
@@ -20,7 +20,7 @@
 extern void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
 			    unsigned long end);
 extern void flush_tlb_page(struct vm_area_struct *vma, unsigned long page);
-extern inline void flush_tlb_pgtables(struct mm_struct *mm,
+static inline void flush_tlb_pgtables(struct mm_struct *mm,
 				      unsigned long start, unsigned long end)
 {
 }
diff --git a/include/asm-sh64/uaccess.h b/include/asm-sh64/uaccess.h
index 56aa3cf..f4936d8 100644
--- a/include/asm-sh64/uaccess.h
+++ b/include/asm-sh64/uaccess.h
@@ -287,7 +287,7 @@
  */
 extern long __strnlen_user(const char *__s, long __n);
 
-extern __inline__ long strnlen_user(const char *s, long n)
+static inline long strnlen_user(const char *s, long n)
 {
 	if (!__addr_ok(s))
 		return 0;
diff --git a/include/asm-sparc/system.h b/include/asm-sparc/system.h
index 1f6b71f..58dd162 100644
--- a/include/asm-sparc/system.h
+++ b/include/asm-sparc/system.h
@@ -155,7 +155,7 @@
 	"here:\n"									\
         : "=&r" (last)									\
         : "r" (&(current_set[hard_smp_processor_id()])),	\
-	  "r" ((next)->thread_info),				\
+	  "r" (task_thread_info(next)),				\
 	  "i" (TI_KPSR),					\
 	  "i" (TI_KSP),						\
 	  "i" (TI_TASK)						\
@@ -166,6 +166,16 @@
 	} while(0)
 
 /*
+ * On SMP systems, when the scheduler does migration-cost autodetection,
+ * it needs a way to flush as much of the CPU's caches as possible.
+ *
+ * TODO: fill this in!
+ */
+static inline void sched_cacheflush(void)
+{
+}
+
+/*
  * Changing the IRQ level on the Sparc.
  */
 extern void local_irq_restore(unsigned long);
diff --git a/include/asm-sparc/thread_info.h b/include/asm-sparc/thread_info.h
index ff6ccb3..65f060b 100644
--- a/include/asm-sparc/thread_info.h
+++ b/include/asm-sparc/thread_info.h
@@ -92,9 +92,6 @@
 BTFIXUPDEF_CALL(void, free_thread_info, struct thread_info *)
 #define free_thread_info(ti) BTFIXUP_CALL(free_thread_info)(ti)
 
-#define get_thread_info(ti)	get_task_struct((ti)->task)
-#define put_thread_info(ti)	put_task_struct((ti)->task)
-
 #endif /* __ASSEMBLY__ */
 
 /*
diff --git a/include/asm-sparc64/elf.h b/include/asm-sparc64/elf.h
index 9145811..69539a8 100644
--- a/include/asm-sparc64/elf.h
+++ b/include/asm-sparc64/elf.h
@@ -119,7 +119,7 @@
 #endif
 
 #define ELF_CORE_COPY_TASK_REGS(__tsk, __elf_regs)	\
-	({ ELF_CORE_COPY_REGS((*(__elf_regs)), (__tsk)->thread_info->kregs); 1; })
+	({ ELF_CORE_COPY_REGS((*(__elf_regs)), task_pt_regs(__tsk)); 1; })
 
 /*
  * This is used to ensure we don't load something for the wrong architecture.
diff --git a/include/asm-sparc64/kprobes.h b/include/asm-sparc64/kprobes.h
index 7ba8453..e4efe65 100644
--- a/include/asm-sparc64/kprobes.h
+++ b/include/asm-sparc64/kprobes.h
@@ -12,6 +12,7 @@
 #define MAX_INSN_SIZE 2
 
 #define JPROBE_ENTRY(pentry)	(kprobe_opcode_t *)pentry
+#define arch_remove_kprobe(p)	do {} while (0)
 
 /* Architecture specific copy of original instruction*/
 struct arch_specific_insn {
@@ -38,15 +39,6 @@
 	struct prev_kprobe prev_kprobe;
 };
 
-#ifdef CONFIG_KPROBES
 extern int kprobe_exceptions_notify(struct notifier_block *self,
 				    unsigned long val, void *data);
-#else				/* !CONFIG_KPROBES */
-static inline int kprobe_exceptions_notify(struct notifier_block *self,
-					   unsigned long val, void *data)
-{
-	return 0;
-}
-#endif
-
 #endif /* _SPARC64_KPROBES_H */
diff --git a/include/asm-sparc64/mmu_context.h b/include/asm-sparc64/mmu_context.h
index 08ba72d..57ee7b3 100644
--- a/include/asm-sparc64/mmu_context.h
+++ b/include/asm-sparc64/mmu_context.h
@@ -60,7 +60,7 @@
 	register unsigned long pgd_cache asm("o4"); \
 	paddr = __pa((__mm)->pgd); \
 	pgd_cache = 0UL; \
-	if ((__tsk)->thread_info->flags & _TIF_32BIT) \
+	if (task_thread_info(__tsk)->flags & _TIF_32BIT) \
 		pgd_cache = get_pgd_cache((__mm)->pgd); \
 	__asm__ __volatile__("wrpr	%%g0, 0x494, %%pstate\n\t" \
 			     "mov	%3, %%g4\n\t" \
diff --git a/include/asm-sparc64/processor.h b/include/asm-sparc64/processor.h
index 3169f3e..cd8d9b4 100644
--- a/include/asm-sparc64/processor.h
+++ b/include/asm-sparc64/processor.h
@@ -186,8 +186,9 @@
 
 extern unsigned long get_wchan(struct task_struct *task);
 
-#define KSTK_EIP(tsk)  ((tsk)->thread_info->kregs->tpc)
-#define KSTK_ESP(tsk)  ((tsk)->thread_info->kregs->u_regs[UREG_FP])
+#define task_pt_regs(tsk) (task_thread_info(tsk)->kregs)
+#define KSTK_EIP(tsk)  (task_pt_regs(tsk)->tpc)
+#define KSTK_ESP(tsk)  (task_pt_regs(tsk)->u_regs[UREG_FP])
 
 #define cpu_relax()	barrier()
 
diff --git a/include/asm-sparc64/system.h b/include/asm-sparc64/system.h
index 309f146..af254e5 100644
--- a/include/asm-sparc64/system.h
+++ b/include/asm-sparc64/system.h
@@ -208,7 +208,7 @@
 	/* If you are tempted to conditionalize the following */	\
 	/* so that ASI is only written if it changes, think again. */	\
 	__asm__ __volatile__("wr %%g0, %0, %%asi"			\
-	: : "r" (__thread_flag_byte_ptr(next->thread_info)[TI_FLAG_BYTE_CURRENT_DS]));\
+	: : "r" (__thread_flag_byte_ptr(task_thread_info(next))[TI_FLAG_BYTE_CURRENT_DS]));\
 	__asm__ __volatile__(						\
 	"mov	%%g4, %%g7\n\t"						\
 	"wrpr	%%g0, 0x95, %%pstate\n\t"				\
@@ -238,7 +238,7 @@
 	"b,a ret_from_syscall\n\t"					\
 	"1:\n\t"							\
 	: "=&r" (last)							\
-	: "0" (next->thread_info),					\
+	: "0" (task_thread_info(next)),					\
 	  "i" (TI_WSTATE), "i" (TI_KSP), "i" (TI_NEW_CHILD),            \
 	  "i" (TI_CWP), "i" (TI_TASK)					\
 	: "cc",								\
@@ -253,6 +253,16 @@
 	}								\
 } while(0)
 
+/*
+ * On SMP systems, when the scheduler does migration-cost autodetection,
+ * it needs a way to flush as much of the CPU's caches as possible.
+ *
+ * TODO: fill this in!
+ */
+static inline void sched_cacheflush(void)
+{
+}
+
 static inline unsigned long xchg32(__volatile__ unsigned int *m, unsigned int val)
 {
 	unsigned long tmp1, tmp2;
diff --git a/include/asm-um/processor-generic.h b/include/asm-um/processor-generic.h
index 075771c..da07a69 100644
--- a/include/asm-um/processor-generic.h
+++ b/include/asm-um/processor-generic.h
@@ -89,7 +89,6 @@
 
 extern void release_thread(struct task_struct *);
 extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
-extern void dump_thread(struct pt_regs *regs, struct user *u);
 
 static inline void prepare_to_copy(struct task_struct *tsk)
 {
diff --git a/include/asm-um/thread_info.h b/include/asm-um/thread_info.h
index 97267f0..705c719 100644
--- a/include/asm-um/thread_info.h
+++ b/include/asm-um/thread_info.h
@@ -56,9 +56,6 @@
 	((struct thread_info *) kmalloc(THREAD_SIZE, GFP_KERNEL))
 #define free_thread_info(ti) kfree(ti)
 
-#define get_thread_info(ti) get_task_struct((ti)->task)
-#define put_thread_info(ti) put_task_struct((ti)->task)
-
 #endif
 
 #define PREEMPT_ACTIVE		0x10000000
diff --git a/include/asm-v850/ioctl.h b/include/asm-v850/ioctl.h
index 1765df6..b279fe0 100644
--- a/include/asm-v850/ioctl.h
+++ b/include/asm-v850/ioctl.h
@@ -1,80 +1 @@
-/* $Id: ioctl.h,v 1.1 2002/09/28 14:58:41 gerg Exp $
- *
- * linux/ioctl.h for Linux by H.H. Bergman.
- */
-
-#ifndef _V850_IOCTL_H
-#define _V850_IOCTL_H
-
-/* ioctl command encoding: 32 bits total, command in lower 16 bits,
- * size of the parameter structure in the lower 14 bits of the
- * upper 16 bits.
- * Encoding the size of the parameter structure in the ioctl request
- * is useful for catching programs compiled with old versions
- * and to avoid overwriting user space outside the user buffer area.
- * The highest 2 bits are reserved for indicating the ``access mode''.
- * NOTE: This limits the max parameter size to 16kB -1 !
- */
-
-/*
- * I don't really have any idea about what this should look like, so
- * for the time being, this is heavily based on the PC definitions.
- */
-
-/*
- * The following is for compatibility across the various Linux
- * platforms.  The i386 ioctl numbering scheme doesn't really enforce
- * a type field.  De facto, however, the top 8 bits of the lower 16
- * bits are indeed used as a type field, so we might just as well make
- * this explicit here.  Please be sure to use the decoding macros
- * below from now on.
- */
-#define _IOC_NRBITS	8
-#define _IOC_TYPEBITS	8
-#define _IOC_SIZEBITS	14
-#define _IOC_DIRBITS	2
-
-#define _IOC_NRMASK	((1 << _IOC_NRBITS)-1)
-#define _IOC_TYPEMASK	((1 << _IOC_TYPEBITS)-1)
-#define _IOC_SIZEMASK	((1 << _IOC_SIZEBITS)-1)
-#define _IOC_DIRMASK	((1 << _IOC_DIRBITS)-1)
-
-#define _IOC_NRSHIFT	0
-#define _IOC_TYPESHIFT	(_IOC_NRSHIFT+_IOC_NRBITS)
-#define _IOC_SIZESHIFT	(_IOC_TYPESHIFT+_IOC_TYPEBITS)
-#define _IOC_DIRSHIFT	(_IOC_SIZESHIFT+_IOC_SIZEBITS)
-
-/*
- * Direction bits.
- */
-#define _IOC_NONE	0U
-#define _IOC_WRITE	1U
-#define _IOC_READ	2U
-
-#define _IOC(dir,type,nr,size) \
-	(((dir)  << _IOC_DIRSHIFT) | \
-	 ((type) << _IOC_TYPESHIFT) | \
-	 ((nr)   << _IOC_NRSHIFT) | \
-	 ((size) << _IOC_SIZESHIFT))
-
-/* used to create numbers */
-#define _IO(type,nr)		_IOC(_IOC_NONE,(type),(nr),0)
-#define _IOR(type,nr,size)	_IOC(_IOC_READ,(type),(nr),sizeof(size))
-#define _IOW(type,nr,size)	_IOC(_IOC_WRITE,(type),(nr),sizeof(size))
-#define _IOWR(type,nr,size)	_IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
-
-/* used to decode ioctl numbers.. */
-#define _IOC_DIR(nr)		(((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
-#define _IOC_TYPE(nr)		(((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
-#define _IOC_NR(nr)		(((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
-#define _IOC_SIZE(nr)		(((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
-
-/* ...and for the drivers/sound files... */
-
-#define IOC_IN		(_IOC_WRITE << _IOC_DIRSHIFT)
-#define IOC_OUT		(_IOC_READ << _IOC_DIRSHIFT)
-#define IOC_INOUT	((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
-#define IOCSIZE_MASK	(_IOC_SIZEMASK << _IOC_SIZESHIFT)
-#define IOCSIZE_SHIFT	(_IOC_SIZESHIFT)
-
-#endif /* __V850_IOCTL_H__ */
+#include <asm-generic/ioctl.h>
diff --git a/include/asm-v850/processor.h b/include/asm-v850/processor.h
index 98f9294..2d31308 100644
--- a/include/asm-v850/processor.h
+++ b/include/asm-v850/processor.h
@@ -98,10 +98,10 @@
 
 
 /* Return some info about the user process TASK.  */
-#define task_tos(task)	((unsigned long)(task)->thread_info + THREAD_SIZE)
-#define task_regs(task) ((struct pt_regs *)task_tos (task) - 1)
-#define task_sp(task)	(task_regs (task)->gpr[GPR_SP])
-#define task_pc(task)	(task_regs (task)->pc)
+#define task_tos(task)	((unsigned long)task_stack_page(task) + THREAD_SIZE)
+#define task_pt_regs(task) ((struct pt_regs *)task_tos (task) - 1)
+#define task_sp(task)	(task_pt_regs (task)->gpr[GPR_SP])
+#define task_pc(task)	(task_pt_regs (task)->pc)
 /* Grotty old names for some.  */
 #define KSTK_EIP(task)	task_pc (task)
 #define KSTK_ESP(task)	task_sp (task)
diff --git a/include/asm-v850/thread_info.h b/include/asm-v850/thread_info.h
index e4cfad9..82b8f28 100644
--- a/include/asm-v850/thread_info.h
+++ b/include/asm-v850/thread_info.h
@@ -58,8 +58,6 @@
 #define alloc_thread_info(tsk) ((struct thread_info *) \
 				__get_free_pages(GFP_KERNEL, 1))
 #define free_thread_info(ti)	free_pages((unsigned long) (ti), 1)
-#define get_thread_info(ti)	get_task_struct((ti)->task)
-#define put_thread_info(ti)	put_task_struct((ti)->task)
 
 #endif /* __ASSEMBLY__ */
 
diff --git a/include/asm-x86_64/apic.h b/include/asm-x86_64/apic.h
index 5647b7d..4f6a4dc 100644
--- a/include/asm-x86_64/apic.h
+++ b/include/asm-x86_64/apic.h
@@ -42,11 +42,6 @@
 	*((volatile unsigned int *)(APIC_BASE+reg)) = v;
 }
 
-static __inline void apic_write_atomic(unsigned long reg, unsigned int v)
-{
-	xchg((volatile unsigned int *)(APIC_BASE+reg), v);
-}
-
 static __inline unsigned int apic_read(unsigned long reg)
 {
 	return *((volatile unsigned int *)(APIC_BASE+reg));
@@ -57,10 +52,6 @@
 	while ( apic_read( APIC_ICR ) & APIC_ICR_BUSY );
 }
 
-#define FORCE_READ_AROUND_WRITE 0
-#define apic_read_around(x)
-#define apic_write_around(x,y) apic_write((x),(y))
-
 static inline void ack_APIC_irq(void)
 {
 	/*
@@ -71,7 +62,7 @@
 	 */
 
 	/* Docs say use 0 for future compatibility */
-	apic_write_around(APIC_EOI, 0);
+	apic_write(APIC_EOI, 0);
 }
 
 extern int get_maxlvt (void);
@@ -113,6 +104,12 @@
 
 extern void setup_threshold_lvt(unsigned long lvt_off);
 
+void smp_send_timer_broadcast_ipi(void);
+void switch_APIC_timer_to_ipi(void *cpumask);
+void switch_ipi_to_APIC_timer(void *cpumask);
+
+#define ARCH_APICTIMER_STOPS_ON_C3	1
+
 #endif /* CONFIG_X86_LOCAL_APIC */
 
 extern unsigned boot_cpu_id;
diff --git a/include/asm-x86_64/apicdef.h b/include/asm-x86_64/apicdef.h
index fb1c99a..decaa2d 100644
--- a/include/asm-x86_64/apicdef.h
+++ b/include/asm-x86_64/apicdef.h
@@ -13,6 +13,7 @@
 #define		APIC_ID		0x20
 #define			APIC_ID_MASK		(0xFFu<<24)
 #define			GET_APIC_ID(x)		(((x)>>24)&0xFFu)
+#define			SET_APIC_ID(x)		(((x)<<24))
 #define		APIC_LVR	0x30
 #define			APIC_LVR_MASK		0xFF00FF
 #define			GET_APIC_VERSION(x)	((x)&0xFFu)
diff --git a/include/asm-x86_64/atomic.h b/include/asm-x86_64/atomic.h
index 6b54023..4b5cd55 100644
--- a/include/asm-x86_64/atomic.h
+++ b/include/asm-x86_64/atomic.h
@@ -2,6 +2,7 @@
 #define __ARCH_X86_64_ATOMIC__
 
 #include <linux/config.h>
+#include <asm/types.h>
 
 /* atomic_t should be 32 bit signed type */
 
diff --git a/include/asm-x86_64/bitops.h b/include/asm-x86_64/bitops.h
index a4d5d09..eb4df23 100644
--- a/include/asm-x86_64/bitops.h
+++ b/include/asm-x86_64/bitops.h
@@ -29,7 +29,7 @@
 {
 	__asm__ __volatile__( LOCK_PREFIX
 		"btsl %1,%0"
-		:"=m" (ADDR)
+		:"+m" (ADDR)
 		:"dIr" (nr) : "memory");
 }
 
@@ -46,7 +46,7 @@
 {
 	__asm__ volatile(
 		"btsl %1,%0"
-		:"=m" (ADDR)
+		:"+m" (ADDR)
 		:"dIr" (nr) : "memory");
 }
 
@@ -64,7 +64,7 @@
 {
 	__asm__ __volatile__( LOCK_PREFIX
 		"btrl %1,%0"
-		:"=m" (ADDR)
+		:"+m" (ADDR)
 		:"dIr" (nr));
 }
 
@@ -72,7 +72,7 @@
 {
 	__asm__ __volatile__(
 		"btrl %1,%0"
-		:"=m" (ADDR)
+		:"+m" (ADDR)
 		:"dIr" (nr));
 }
 
@@ -92,7 +92,7 @@
 {
 	__asm__ __volatile__(
 		"btcl %1,%0"
-		:"=m" (ADDR)
+		:"+m" (ADDR)
 		:"dIr" (nr));
 }
 
@@ -109,7 +109,7 @@
 {
 	__asm__ __volatile__( LOCK_PREFIX
 		"btcl %1,%0"
-		:"=m" (ADDR)
+		:"+m" (ADDR)
 		:"dIr" (nr));
 }
 
@@ -127,7 +127,7 @@
 
 	__asm__ __volatile__( LOCK_PREFIX
 		"btsl %2,%1\n\tsbbl %0,%0"
-		:"=r" (oldbit),"=m" (ADDR)
+		:"=r" (oldbit),"+m" (ADDR)
 		:"dIr" (nr) : "memory");
 	return oldbit;
 }
@@ -147,7 +147,7 @@
 
 	__asm__(
 		"btsl %2,%1\n\tsbbl %0,%0"
-		:"=r" (oldbit),"=m" (ADDR)
+		:"=r" (oldbit),"+m" (ADDR)
 		:"dIr" (nr));
 	return oldbit;
 }
@@ -166,7 +166,7 @@
 
 	__asm__ __volatile__( LOCK_PREFIX
 		"btrl %2,%1\n\tsbbl %0,%0"
-		:"=r" (oldbit),"=m" (ADDR)
+		:"=r" (oldbit),"+m" (ADDR)
 		:"dIr" (nr) : "memory");
 	return oldbit;
 }
@@ -186,7 +186,7 @@
 
 	__asm__(
 		"btrl %2,%1\n\tsbbl %0,%0"
-		:"=r" (oldbit),"=m" (ADDR)
+		:"=r" (oldbit),"+m" (ADDR)
 		:"dIr" (nr));
 	return oldbit;
 }
@@ -198,7 +198,7 @@
 
 	__asm__ __volatile__(
 		"btcl %2,%1\n\tsbbl %0,%0"
-		:"=r" (oldbit),"=m" (ADDR)
+		:"=r" (oldbit),"+m" (ADDR)
 		:"dIr" (nr) : "memory");
 	return oldbit;
 }
@@ -217,7 +217,7 @@
 
 	__asm__ __volatile__( LOCK_PREFIX
 		"btcl %2,%1\n\tsbbl %0,%0"
-		:"=r" (oldbit),"=m" (ADDR)
+		:"=r" (oldbit),"+m" (ADDR)
 		:"dIr" (nr) : "memory");
 	return oldbit;
 }
@@ -397,6 +397,22 @@
 }
 
 /**
+ * fls - find last bit set
+ * @x: the word to search
+ *
+ * This is defined the same way as ffs.
+ */
+static __inline__ int fls(int x)
+{
+	int r;
+
+	__asm__("bsrl %1,%0\n\t"
+		"cmovzl %2,%0"
+		: "=&r" (r) : "rm" (x), "rm" (-1));
+	return r+1;
+}
+
+/**
  * hweightN - returns the hamming weight of a N-bit word
  * @x: the word to weigh
  *
@@ -434,9 +450,6 @@
 #define minix_find_first_zero_bit(addr,size) \
 	find_first_zero_bit((void*)addr,size)
 
-/* find last set bit */
-#define fls(x) generic_fls(x)
-
 #endif /* __KERNEL__ */
 
 #endif /* _X86_64_BITOPS_H */
diff --git a/include/asm-x86_64/cache.h b/include/asm-x86_64/cache.h
index b4a2401..263f0a2 100644
--- a/include/asm-x86_64/cache.h
+++ b/include/asm-x86_64/cache.h
@@ -10,4 +10,16 @@
 #define L1_CACHE_SHIFT	(CONFIG_X86_L1_CACHE_SHIFT)
 #define L1_CACHE_BYTES	(1 << L1_CACHE_SHIFT)
 
+#ifdef CONFIG_X86_VSMP
+
+/* vSMP Internode cacheline shift */
+#define INTERNODE_CACHE_SHIFT (12)
+#ifdef CONFIG_SMP
+#define __cacheline_aligned_in_smp					\
+       __attribute__((__aligned__(1 << (INTERNODE_CACHE_SHIFT))))         \
+       __attribute__((__section__(".data.page_aligned")))
+#endif
+
+#endif
+
 #endif
diff --git a/include/asm-x86_64/compat.h b/include/asm-x86_64/compat.h
index f0155c3..b37ab82 100644
--- a/include/asm-x86_64/compat.h
+++ b/include/asm-x86_64/compat.h
@@ -198,8 +198,13 @@
 
 static __inline__ void __user *compat_alloc_user_space(long len)
 {
-	struct pt_regs *regs = (void *)current->thread.rsp0 - sizeof(struct pt_regs); 
+	struct pt_regs *regs = task_pt_regs(current);
 	return (void __user *)regs->rsp - len; 
 }
 
+static inline int is_compat_task(void)
+{
+	return current_thread_info()->status & TS_COMPAT;
+}
+
 #endif /* _ASM_X86_64_COMPAT_H */
diff --git a/include/asm-x86_64/cpufeature.h b/include/asm-x86_64/cpufeature.h
index aea308c..41c0ac8 100644
--- a/include/asm-x86_64/cpufeature.h
+++ b/include/asm-x86_64/cpufeature.h
@@ -61,8 +61,9 @@
 #define X86_FEATURE_K6_MTRR	(3*32+ 1) /* AMD K6 nonstandard MTRRs */
 #define X86_FEATURE_CYRIX_ARR	(3*32+ 2) /* Cyrix ARRs (= MTRRs) */
 #define X86_FEATURE_CENTAUR_MCR	(3*32+ 3) /* Centaur MCRs (= MTRRs) */
-#define X86_FEATURE_K8_C	(3*32+ 4) /* C stepping K8 */
+/* 4 free */
 #define X86_FEATURE_CONSTANT_TSC (3*32+5) /* TSC runs at constant rate */
+#define X86_FEATURE_SYNC_RDTSC  (3*32+6)  /* RDTSC syncs CPU core */
 
 /* Intel-defined CPU features, CPUID level 0x00000001 (ecx), word 4 */
 #define X86_FEATURE_XMM3	(4*32+ 0) /* Streaming SIMD Extensions-3 */
diff --git a/include/asm-x86_64/desc.h b/include/asm-x86_64/desc.h
index 3376486..eb7723a 100644
--- a/include/asm-x86_64/desc.h
+++ b/include/asm-x86_64/desc.h
@@ -25,7 +25,7 @@
 	unsigned int a,b;
 }; 	
 
-extern struct desc_struct cpu_gdt_table[NR_CPUS][GDT_ENTRIES];
+extern struct desc_struct cpu_gdt_table[GDT_ENTRIES];
 
 enum { 
 	GATE_INTERRUPT = 0xE, 
@@ -79,6 +79,9 @@
 extern struct gate_struct idt_table[]; 
 extern struct desc_ptr cpu_gdt_descr[];
 
+/* the cpu gdt accessor */
+#define cpu_gdt(_cpu) ((struct desc_struct *)cpu_gdt_descr[_cpu].address)
+
 static inline void _set_gate(void *adr, unsigned type, unsigned long func, unsigned dpl, unsigned ist)  
 {
 	struct gate_struct s; 	
@@ -114,6 +117,11 @@
 	_set_gate(&idt_table[nr], GATE_INTERRUPT, (unsigned long) func, 3, 0); 
 } 
 
+static inline void set_system_gate_ist(int nr, void *func, unsigned ist)
+{
+	_set_gate(&idt_table[nr], GATE_INTERRUPT, (unsigned long) func, 3, ist);
+}
+
 static inline void set_tssldt_descriptor(void *ptr, unsigned long tss, unsigned type, 
 					 unsigned size) 
 { 
@@ -139,20 +147,20 @@
 	 * -1? seg base+limit should be pointing to the address of the
 	 * last valid byte
 	 */
-	set_tssldt_descriptor(&cpu_gdt_table[cpu][GDT_ENTRY_TSS],
+	set_tssldt_descriptor(&cpu_gdt(cpu)[GDT_ENTRY_TSS],
 		(unsigned long)addr, DESC_TSS,
 		IO_BITMAP_OFFSET + IO_BITMAP_BYTES + sizeof(unsigned long) - 1);
 } 
 
 static inline void set_ldt_desc(unsigned cpu, void *addr, int size)
 { 
-	set_tssldt_descriptor(&cpu_gdt_table[cpu][GDT_ENTRY_LDT], (unsigned long)addr, 
+	set_tssldt_descriptor(&cpu_gdt(cpu)[GDT_ENTRY_LDT], (unsigned long)addr,
 			      DESC_LDT, size * 8 - 1);
 }
 
 static inline void set_seg_base(unsigned cpu, int entry, void *base)
 { 
-	struct desc_struct *d = &cpu_gdt_table[cpu][entry];
+	struct desc_struct *d = &cpu_gdt(cpu)[entry];
 	u32 addr = (u32)(u64)base;
 	BUG_ON((u64)base >> 32); 
 	d->base0 = addr & 0xffff;
@@ -194,7 +202,7 @@
 
 static inline void load_TLS(struct thread_struct *t, unsigned int cpu)
 {
-	u64 *gdt = (u64 *)(cpu_gdt_table[cpu] + GDT_ENTRY_TLS_MIN);
+	u64 *gdt = (u64 *)(cpu_gdt(cpu) + GDT_ENTRY_TLS_MIN);
 	gdt[0] = t->tls_array[0];
 	gdt[1] = t->tls_array[1];
 	gdt[2] = t->tls_array[2];
diff --git a/include/asm-x86_64/dma-mapping.h b/include/asm-x86_64/dma-mapping.h
index 36d16df..49a81a6 100644
--- a/include/asm-x86_64/dma-mapping.h
+++ b/include/asm-x86_64/dma-mapping.h
@@ -12,155 +12,176 @@
 #include <asm/io.h>
 #include <asm/swiotlb.h>
 
+struct dma_mapping_ops {
+	int             (*mapping_error)(dma_addr_t dma_addr);
+	void*           (*alloc_coherent)(struct device *dev, size_t size,
+                                dma_addr_t *dma_handle, gfp_t gfp);
+	void            (*free_coherent)(struct device *dev, size_t size,
+                                void *vaddr, dma_addr_t dma_handle);
+	dma_addr_t      (*map_single)(struct device *hwdev, void *ptr,
+                                size_t size, int direction);
+	/* like map_single, but doesn't check the device mask */
+	dma_addr_t      (*map_simple)(struct device *hwdev, char *ptr,
+                                size_t size, int direction);
+	void            (*unmap_single)(struct device *dev, dma_addr_t addr,
+		                size_t size, int direction);
+	void            (*sync_single_for_cpu)(struct device *hwdev,
+		                dma_addr_t dma_handle, size_t size,
+				int direction);
+	void            (*sync_single_for_device)(struct device *hwdev,
+                                dma_addr_t dma_handle, size_t size,
+				int direction);
+	void            (*sync_single_range_for_cpu)(struct device *hwdev,
+                                dma_addr_t dma_handle, unsigned long offset,
+		                size_t size, int direction);
+	void            (*sync_single_range_for_device)(struct device *hwdev,
+				dma_addr_t dma_handle, unsigned long offset,
+		                size_t size, int direction);
+	void            (*sync_sg_for_cpu)(struct device *hwdev,
+                                struct scatterlist *sg, int nelems,
+				int direction);
+	void            (*sync_sg_for_device)(struct device *hwdev,
+				struct scatterlist *sg, int nelems,
+				int direction);
+	int             (*map_sg)(struct device *hwdev, struct scatterlist *sg,
+		                int nents, int direction);
+	void            (*unmap_sg)(struct device *hwdev,
+				struct scatterlist *sg, int nents,
+				int direction);
+	int             (*dma_supported)(struct device *hwdev, u64 mask);
+	int		is_phys;
+};
+
 extern dma_addr_t bad_dma_address;
-#define dma_mapping_error(x) \
-	(swiotlb ? swiotlb_dma_mapping_error(x) : ((x) == bad_dma_address))
+extern struct dma_mapping_ops* dma_ops;
+extern int iommu_merge;
 
-void *dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
-			 gfp_t gfp);
-void dma_free_coherent(struct device *dev, size_t size, void *vaddr,
-			 dma_addr_t dma_handle);
-
-#ifdef CONFIG_GART_IOMMU
-
-extern dma_addr_t dma_map_single(struct device *hwdev, void *ptr, size_t size,
-				 int direction);
-extern void dma_unmap_single(struct device *dev, dma_addr_t addr,size_t size,
-			     int direction);
-
-#else
-
-/* No IOMMU */
-
-static inline dma_addr_t dma_map_single(struct device *hwdev, void *ptr,
-					size_t size, int direction)
+static inline int dma_mapping_error(dma_addr_t dma_addr)
 {
-	dma_addr_t addr;
+	if (dma_ops->mapping_error)
+		return dma_ops->mapping_error(dma_addr);
 
-	if (direction == DMA_NONE)
-		out_of_line_bug();
-	addr = virt_to_bus(ptr);
-
-	if ((addr+size) & ~*hwdev->dma_mask)
-		out_of_line_bug();
-	return addr;
+	return (dma_addr == bad_dma_address);
 }
 
-static inline void dma_unmap_single(struct device *hwdev, dma_addr_t dma_addr,
-				    size_t size, int direction)
+extern void *dma_alloc_coherent(struct device *dev, size_t size,
+				dma_addr_t *dma_handle, gfp_t gfp);
+extern 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 *hwdev, void *ptr, size_t size,
+	       int direction)
 {
-	if (direction == DMA_NONE)
-		out_of_line_bug();
-	/* Nothing to do */
+	return dma_ops->map_single(hwdev, ptr, size, direction);
 }
 
-#endif
+static inline void
+dma_unmap_single(struct device *dev, dma_addr_t addr,size_t size,
+		 int direction)
+{
+	dma_ops->unmap_single(dev, addr, size, direction);
+}
 
 #define dma_map_page(dev,page,offset,size,dir) \
 	dma_map_single((dev), page_address(page)+(offset), (size), (dir))
 
-static inline void dma_sync_single_for_cpu(struct device *hwdev,
-					       dma_addr_t dma_handle,
-					       size_t size, int direction)
-{
-	if (direction == DMA_NONE)
-		out_of_line_bug();
-
-	if (swiotlb)
-		return swiotlb_sync_single_for_cpu(hwdev,dma_handle,size,direction);
-
-	flush_write_buffers();
-}
-
-static inline void dma_sync_single_for_device(struct device *hwdev,
-						  dma_addr_t dma_handle,
-						  size_t size, int direction)
-{
-        if (direction == DMA_NONE)
-		out_of_line_bug();
-
-	if (swiotlb)
-		return swiotlb_sync_single_for_device(hwdev,dma_handle,size,direction);
-
-	flush_write_buffers();
-}
-
-static inline void dma_sync_single_range_for_cpu(struct device *hwdev,
-						 dma_addr_t dma_handle,
-						 unsigned long offset,
-						 size_t size, int direction)
-{
-	if (direction == DMA_NONE)
-		out_of_line_bug();
-
-	if (swiotlb)
-		return swiotlb_sync_single_range_for_cpu(hwdev,dma_handle,offset,size,direction);
-
-	flush_write_buffers();
-}
-
-static inline void dma_sync_single_range_for_device(struct device *hwdev,
-						    dma_addr_t dma_handle,
-						    unsigned long offset,
-						    size_t size, int direction)
-{
-        if (direction == DMA_NONE)
-		out_of_line_bug();
-
-	if (swiotlb)
-		return swiotlb_sync_single_range_for_device(hwdev,dma_handle,offset,size,direction);
-
-	flush_write_buffers();
-}
-
-static inline void dma_sync_sg_for_cpu(struct device *hwdev,
-				       struct scatterlist *sg,
-				       int nelems, int direction)
-{
-	if (direction == DMA_NONE)
-		out_of_line_bug();
-
-	if (swiotlb)
-		return swiotlb_sync_sg_for_cpu(hwdev,sg,nelems,direction);
-
-	flush_write_buffers();
-}
-
-static inline void dma_sync_sg_for_device(struct device *hwdev,
-					  struct scatterlist *sg,
-					  int nelems, int direction)
-{
-	if (direction == DMA_NONE)
-		out_of_line_bug();
-
-	if (swiotlb)
-		return swiotlb_sync_sg_for_device(hwdev,sg,nelems,direction);
-
-	flush_write_buffers();
-}
-
-extern int dma_map_sg(struct device *hwdev, struct scatterlist *sg,
-		      int nents, int direction);
-extern void dma_unmap_sg(struct device *hwdev, struct scatterlist *sg,
-			 int nents, int direction);
-
 #define dma_unmap_page dma_unmap_single
 
-extern int dma_supported(struct device *hwdev, u64 mask);
-extern int dma_get_cache_alignment(void);
-#define dma_is_consistent(h) 1
-
-static inline int dma_set_mask(struct device *dev, u64 mask)
+static inline void
+dma_sync_single_for_cpu(struct device *hwdev, dma_addr_t dma_handle,
+			size_t size, int direction)
 {
-	if (!dev->dma_mask || !dma_supported(dev, mask))
-		return -EIO;
-	*dev->dma_mask = mask;
-	return 0;
+	if (dma_ops->sync_single_for_cpu)
+		dma_ops->sync_single_for_cpu(hwdev, dma_handle, size,
+					     direction);
+	flush_write_buffers();
 }
 
-static inline void dma_cache_sync(void *vaddr, size_t size, enum dma_data_direction dir)
+static inline void
+dma_sync_single_for_device(struct device *hwdev, dma_addr_t dma_handle,
+			   size_t size, int direction)
+{
+	if (dma_ops->sync_single_for_device)
+		dma_ops->sync_single_for_device(hwdev, dma_handle, size,
+						direction);
+	flush_write_buffers();
+}
+
+static inline void
+dma_sync_single_range_for_cpu(struct device *hwdev, dma_addr_t dma_handle,
+			      unsigned long offset, size_t size, int direction)
+{
+	if (dma_ops->sync_single_range_for_cpu) {
+		dma_ops->sync_single_range_for_cpu(hwdev, dma_handle, offset, size, direction);
+	}
+
+	flush_write_buffers();
+}
+
+static inline void
+dma_sync_single_range_for_device(struct device *hwdev, dma_addr_t dma_handle,
+				 unsigned long offset, size_t size, int direction)
+{
+	if (dma_ops->sync_single_range_for_device)
+		dma_ops->sync_single_range_for_device(hwdev, dma_handle,
+						      offset, size, direction);
+
+	flush_write_buffers();
+}
+
+static inline void
+dma_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg,
+		    int nelems, int direction)
+{
+	if (dma_ops->sync_sg_for_cpu)
+		dma_ops->sync_sg_for_cpu(hwdev, sg, nelems, direction);
+	flush_write_buffers();
+}
+
+static inline void
+dma_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
+		       int nelems, int direction)
+{
+	if (dma_ops->sync_sg_for_device) {
+		dma_ops->sync_sg_for_device(hwdev, sg, nelems, direction);
+	}
+
+	flush_write_buffers();
+}
+
+static inline int
+dma_map_sg(struct device *hwdev, struct scatterlist *sg, int nents, int direction)
+{
+	return dma_ops->map_sg(hwdev, sg, nents, direction);
+}
+
+static inline void
+dma_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nents,
+	     int direction)
+{
+	dma_ops->unmap_sg(hwdev, sg, nents, direction);
+}
+
+extern int dma_supported(struct device *hwdev, u64 mask);
+
+/* same for gart, swiotlb, and nommu */
+static inline int dma_get_cache_alignment(void)
+{
+	return boot_cpu_data.x86_clflush_size;
+}
+
+#define dma_is_consistent(h) 1
+
+extern int dma_set_mask(struct device *dev, u64 mask);
+
+static inline void
+dma_cache_sync(void *vaddr, size_t size, enum dma_data_direction dir)
 {
 	flush_write_buffers();
 }
 
-#endif
+extern struct device fallback_dev;
+extern int panic_on_overflow;
+
+#endif /* _X8664_DMA_MAPPING_H */
diff --git a/include/asm-x86_64/dwarf2.h b/include/asm-x86_64/dwarf2.h
index 582757f..07654bd 100644
--- a/include/asm-x86_64/dwarf2.h
+++ b/include/asm-x86_64/dwarf2.h
@@ -14,7 +14,7 @@
    away for older version. 
  */
 
-#ifdef CONFIG_DEBUG_INFO
+#ifdef CONFIG_UNWIND_INFO
 
 #define CFI_STARTPROC .cfi_startproc
 #define CFI_ENDPROC .cfi_endproc
@@ -28,6 +28,7 @@
 #define CFI_RESTORE .cfi_restore
 #define CFI_REMEMBER_STATE .cfi_remember_state
 #define CFI_RESTORE_STATE .cfi_restore_state
+#define CFI_UNDEFINED .cfi_undefined
 
 #else
 
@@ -44,6 +45,7 @@
 #define CFI_RESTORE	#
 #define CFI_REMEMBER_STATE	#
 #define CFI_RESTORE_STATE	#
+#define CFI_UNDEFINED	#
 
 #endif
 
diff --git a/include/asm-x86_64/e820.h b/include/asm-x86_64/e820.h
index e682edc..8dcc326 100644
--- a/include/asm-x86_64/e820.h
+++ b/include/asm-x86_64/e820.h
@@ -55,6 +55,7 @@
 				    unsigned long end_pfn);
 
 extern void __init parse_memopt(char *p, char **end);
+extern void __init parse_memmapopt(char *p, char **end);
 
 extern struct e820map e820;
 #endif/*!__ASSEMBLY__*/
diff --git a/include/asm-x86_64/gart-mapping.h b/include/asm-x86_64/gart-mapping.h
new file mode 100644
index 0000000..ada497b
--- /dev/null
+++ b/include/asm-x86_64/gart-mapping.h
@@ -0,0 +1,16 @@
+#ifndef _X8664_GART_MAPPING_H
+#define _X8664_GART_MAPPING_H 1
+
+#include <linux/types.h>
+#include <asm/types.h>
+
+struct device;
+
+extern void*
+gart_alloc_coherent(struct device *dev, size_t size,
+        dma_addr_t *dma_handle, gfp_t gfp);
+
+extern int
+gart_dma_supported(struct device *hwdev, u64 mask);
+
+#endif /* _X8664_GART_MAPPING_H */
diff --git a/include/asm-x86_64/hw_irq.h b/include/asm-x86_64/hw_irq.h
index c14a8c7..0df1715 100644
--- a/include/asm-x86_64/hw_irq.h
+++ b/include/asm-x86_64/hw_irq.h
@@ -46,18 +46,18 @@
  *  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-0xf9 are free (reserved for future Linux use).
  */
 #define SPURIOUS_APIC_VECTOR	0xff
 #define ERROR_APIC_VECTOR	0xfe
 #define RESCHEDULE_VECTOR	0xfd
 #define CALL_FUNCTION_VECTOR	0xfc
-#define KDB_VECTOR		0xfb	/* reserved for KDB */
+/* fb free - please don't readd KDB here because it's useless
+   (hint - think what a NMI bit does to a vector) */
 #define THERMAL_APIC_VECTOR	0xfa
 #define THRESHOLD_APIC_VECTOR   0xf9
-#define INVALIDATE_TLB_VECTOR_END	0xf8
-#define INVALIDATE_TLB_VECTOR_START	0xf0	/* f0-f8 used for TLB flush */
+/* f8 free */
+#define INVALIDATE_TLB_VECTOR_END	0xf7
+#define INVALIDATE_TLB_VECTOR_START	0xf0	/* f0-f7 used for TLB flush */
 
 #define NUM_INVALIDATE_TLB_VECTORS	8
 
diff --git a/include/asm-x86_64/i387.h b/include/asm-x86_64/i387.h
index aa39cfd..876eb9a 100644
--- a/include/asm-x86_64/i387.h
+++ b/include/asm-x86_64/i387.h
@@ -30,7 +30,7 @@
  */
 
 #define unlazy_fpu(tsk) do { \
-	if ((tsk)->thread_info->status & TS_USEDFPU) \
+	if (task_thread_info(tsk)->status & TS_USEDFPU) \
 		save_init_fpu(tsk); \
 } while (0)
 
@@ -46,9 +46,9 @@
 }
 
 #define clear_fpu(tsk) do { \
-	if ((tsk)->thread_info->status & TS_USEDFPU) {		\
+	if (task_thread_info(tsk)->status & TS_USEDFPU) {	\
 		tolerant_fwait();				\
-		(tsk)->thread_info->status &= ~TS_USEDFPU;	\
+		task_thread_info(tsk)->status &= ~TS_USEDFPU;	\
 		stts();						\
 	}							\
 } while (0)
@@ -75,7 +75,8 @@
 static inline int restore_fpu_checking(struct i387_fxsave_struct *fx) 
 { 
 	int err;
-	asm volatile("1:  rex64 ; fxrstor (%[fx])\n\t"
+
+	asm volatile("1:  rex64/fxrstor (%[fx])\n\t"
 		     "2:\n"
 		     ".section .fixup,\"ax\"\n"
 		     "3:  movl $-1,%[err]\n"
@@ -86,7 +87,11 @@
 		     "   .quad  1b,3b\n"
 		     ".previous"
 		     : [err] "=r" (err)
-		     : [fx] "r" (fx), "0" (0)); 
+#if 0 /* See comment in __fxsave_clear() below. */
+		     : [fx] "r" (fx), "m" (*fx), "0" (0));
+#else
+		     : [fx] "cdaSDb" (fx), "m" (*fx), "0" (0));
+#endif
 	if (unlikely(err))
 		init_fpu(current);
 	return err;
@@ -95,7 +100,8 @@
 static inline int save_i387_checking(struct i387_fxsave_struct __user *fx) 
 { 
 	int err;
-	asm volatile("1:  rex64 ; fxsave (%[fx])\n\t"
+
+	asm volatile("1:  rex64/fxsave (%[fx])\n\t"
 		     "2:\n"
 		     ".section .fixup,\"ax\"\n"
 		     "3:  movl $-1,%[err]\n"
@@ -105,20 +111,53 @@
 		     "   .align 8\n"
 		     "   .quad  1b,3b\n"
 		     ".previous"
-		     : [err] "=r" (err)
-		     : [fx] "r" (fx), "0" (0)); 
+		     : [err] "=r" (err), "=m" (*fx)
+#if 0 /* See comment in __fxsave_clear() below. */
+		     : [fx] "r" (fx), "0" (0));
+#else
+		     : [fx] "cdaSDb" (fx), "0" (0));
+#endif
 	if (unlikely(err))
 		__clear_user(fx, sizeof(struct i387_fxsave_struct));
 	return err;
 } 
 
+static inline void __fxsave_clear(struct task_struct *tsk)
+{
+	/* Using "rex64; fxsave %0" is broken because, if the memory operand
+	   uses any extended registers for addressing, a second REX prefix
+	   will be generated (to the assembler, rex64 followed by semicolon
+	   is a separate instruction), and hence the 64-bitness is lost. */
+#if 0
+	/* Using "fxsaveq %0" would be the ideal choice, but is only supported
+	   starting with gas 2.16. */
+	__asm__ __volatile__("fxsaveq %0"
+			     : "=m" (tsk->thread.i387.fxsave));
+#elif 0
+	/* Using, as a workaround, the properly prefixed form below isn't
+	   accepted by any binutils version so far released, complaining that
+	   the same type of prefix is used twice if an extended register is
+	   needed for addressing (fix submitted to mainline 2005-11-21). */
+	__asm__ __volatile__("rex64/fxsave %0"
+			     : "=m" (tsk->thread.i387.fxsave));
+#else
+	/* This, however, we can work around by forcing the compiler to select
+	   an addressing mode that doesn't require extended registers. */
+	__asm__ __volatile__("rex64/fxsave %P2(%1)"
+			     : "=m" (tsk->thread.i387.fxsave)
+			     : "cdaSDb" (tsk),
+				"i" (offsetof(__typeof__(*tsk),
+					      thread.i387.fxsave)));
+#endif
+	__asm__ __volatile__("fnclex");
+}
+
 static inline void kernel_fpu_begin(void)
 {
 	struct thread_info *me = current_thread_info();
 	preempt_disable();
-	if (me->status & TS_USEDFPU) { 
-		asm volatile("rex64 ; fxsave %0 ; fnclex"
-			      : "=m" (me->task->thread.i387.fxsave));
+	if (me->status & TS_USEDFPU) {
+		__fxsave_clear(me->task);
 		me->status &= ~TS_USEDFPU;
 		return;
 	}
@@ -131,11 +170,10 @@
 	preempt_enable();
 }
 
-static inline void save_init_fpu( struct task_struct *tsk )
+static inline void save_init_fpu(struct task_struct *tsk)
 {
-	asm volatile( "rex64 ; fxsave %0 ; fnclex"
-		      : "=m" (tsk->thread.i387.fxsave));
-	tsk->thread_info->status &= ~TS_USEDFPU;
+ 	__fxsave_clear(tsk);
+	task_thread_info(tsk)->status &= ~TS_USEDFPU;
 	stts();
 }
 
diff --git a/include/asm-x86_64/idle.h b/include/asm-x86_64/idle.h
new file mode 100644
index 0000000..6bd47dc
--- /dev/null
+++ b/include/asm-x86_64/idle.h
@@ -0,0 +1,14 @@
+#ifndef _ASM_X86_64_IDLE_H
+#define _ASM_X86_64_IDLE_H 1
+
+#define IDLE_START 1
+#define IDLE_END 2
+
+struct notifier_block;
+void idle_notifier_register(struct notifier_block *n);
+void idle_notifier_unregister(struct notifier_block *n);
+
+void enter_idle(void);
+void exit_idle(void);
+
+#endif
diff --git a/include/asm-x86_64/io.h b/include/asm-x86_64/io.h
index 52ff269..9dac18db 100644
--- a/include/asm-x86_64/io.h
+++ b/include/asm-x86_64/io.h
@@ -143,6 +143,11 @@
 extern void __iomem * ioremap_nocache (unsigned long offset, unsigned long size);
 extern void iounmap(volatile void __iomem *addr);
 
+/* Use normal IO mappings for DMI */
+#define dmi_ioremap ioremap
+#define dmi_iounmap(x,l) iounmap(x)
+#define dmi_alloc(l) kmalloc(l, GFP_ATOMIC)
+
 /*
  * ISA I/O bus memory addresses are 1:1 with the physical address.
  */
diff --git a/include/asm-x86_64/ioctl.h b/include/asm-x86_64/ioctl.h
index 609b663..b279fe0 100644
--- a/include/asm-x86_64/ioctl.h
+++ b/include/asm-x86_64/ioctl.h
@@ -1,75 +1 @@
-/* $Id: ioctl.h,v 1.2 2001/07/04 09:08:13 ak Exp $
- *
- * linux/ioctl.h for Linux by H.H. Bergman.
- */
-
-#ifndef _ASMX8664_IOCTL_H
-#define _ASMX8664_IOCTL_H
-
-/* ioctl command encoding: 32 bits total, command in lower 16 bits,
- * size of the parameter structure in the lower 14 bits of the
- * upper 16 bits.
- * Encoding the size of the parameter structure in the ioctl request
- * is useful for catching programs compiled with old versions
- * and to avoid overwriting user space outside the user buffer area.
- * The highest 2 bits are reserved for indicating the ``access mode''.
- * NOTE: This limits the max parameter size to 16kB -1 !
- */
-
-/*
- * The following is for compatibility across the various Linux
- * platforms.  The i386 ioctl numbering scheme doesn't really enforce
- * a type field.  De facto, however, the top 8 bits of the lower 16
- * bits are indeed used as a type field, so we might just as well make
- * this explicit here.  Please be sure to use the decoding macros
- * below from now on.
- */
-#define _IOC_NRBITS	8
-#define _IOC_TYPEBITS	8
-#define _IOC_SIZEBITS	14
-#define _IOC_DIRBITS	2
-
-#define _IOC_NRMASK	((1 << _IOC_NRBITS)-1)
-#define _IOC_TYPEMASK	((1 << _IOC_TYPEBITS)-1)
-#define _IOC_SIZEMASK	((1 << _IOC_SIZEBITS)-1)
-#define _IOC_DIRMASK	((1 << _IOC_DIRBITS)-1)
-
-#define _IOC_NRSHIFT	0
-#define _IOC_TYPESHIFT	(_IOC_NRSHIFT+_IOC_NRBITS)
-#define _IOC_SIZESHIFT	(_IOC_TYPESHIFT+_IOC_TYPEBITS)
-#define _IOC_DIRSHIFT	(_IOC_SIZESHIFT+_IOC_SIZEBITS)
-
-/*
- * Direction bits.
- */
-#define _IOC_NONE	0U
-#define _IOC_WRITE	1U
-#define _IOC_READ	2U
-
-#define _IOC(dir,type,nr,size) \
-	(((dir)  << _IOC_DIRSHIFT) | \
-	 ((type) << _IOC_TYPESHIFT) | \
-	 ((nr)   << _IOC_NRSHIFT) | \
-	 ((size) << _IOC_SIZESHIFT))
-
-/* used to create numbers */
-#define _IO(type,nr)		_IOC(_IOC_NONE,(type),(nr),0)
-#define _IOR(type,nr,size)	_IOC(_IOC_READ,(type),(nr),sizeof(size))
-#define _IOW(type,nr,size)	_IOC(_IOC_WRITE,(type),(nr),sizeof(size))
-#define _IOWR(type,nr,size)	_IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
-
-/* used to decode ioctl numbers.. */
-#define _IOC_DIR(nr)		(((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
-#define _IOC_TYPE(nr)		(((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
-#define _IOC_NR(nr)		(((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
-#define _IOC_SIZE(nr)		(((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
-
-/* ...and for the drivers/sound files... */
-
-#define IOC_IN		(_IOC_WRITE << _IOC_DIRSHIFT)
-#define IOC_OUT		(_IOC_READ << _IOC_DIRSHIFT)
-#define IOC_INOUT	((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
-#define IOCSIZE_MASK	(_IOC_SIZEMASK << _IOC_SIZESHIFT)
-#define IOCSIZE_SHIFT	(_IOC_SIZESHIFT)
-
-#endif /* _ASMX8664_IOCTL_H */
+#include <asm-generic/ioctl.h>
diff --git a/include/asm-x86_64/ipi.h b/include/asm-x86_64/ipi.h
index 022e9d3..2a5c162 100644
--- a/include/asm-x86_64/ipi.h
+++ b/include/asm-x86_64/ipi.h
@@ -38,10 +38,6 @@
 		icr |= APIC_DM_FIXED | vector;
 		break;
 	case NMI_VECTOR:
-		/*
-		 * Setup KDB IPI to be delivered as an NMI
-		 */
-	case KDB_VECTOR:
 		icr |= APIC_DM_NMI;
 		break;
 	}
diff --git a/include/asm-x86_64/kdebug.h b/include/asm-x86_64/kdebug.h
index f604e84..b9ed4c0 100644
--- a/include/asm-x86_64/kdebug.h
+++ b/include/asm-x86_64/kdebug.h
@@ -35,9 +35,16 @@
 	DIE_PAGE_FAULT,
 }; 
 	
-static inline int notify_die(enum die_val val,char *str,struct pt_regs *regs,long err,int trap, int sig)
-{ 
-	struct die_args args = { .regs=regs, .str=str, .err=err, .trapnr=trap,.signr=sig }; 
+static inline int notify_die(enum die_val val, const char *str,
+			struct pt_regs *regs, long err, int trap, int sig)
+{
+	struct die_args args = {
+		.regs = regs,
+		.str = str,
+		.err = err,
+		.trapnr = trap,
+		.signr = sig
+	};
 	return notifier_call_chain(&die_chain, val, &args); 
 } 
 
diff --git a/include/asm-x86_64/kexec.h b/include/asm-x86_64/kexec.h
index 42d2ff1..ae28cd4 100644
--- a/include/asm-x86_64/kexec.h
+++ b/include/asm-x86_64/kexec.h
@@ -3,6 +3,7 @@
 
 #include <asm/page.h>
 #include <asm/proto.h>
+#include <asm/ptrace.h>
 
 /*
  * KEXEC_SOURCE_MEMORY_LIMIT maximum page get_free_page can return.
@@ -26,8 +27,40 @@
 #define KEXEC_ARCH KEXEC_ARCH_X86_64
 
 #define MAX_NOTE_BYTES 1024
-typedef u32 note_buf_t[MAX_NOTE_BYTES/4];
 
-extern note_buf_t crash_notes[];
+/*
+ * Saving the registers of the cpu on which panic occured in
+ * crash_kexec to save a valid sp. The registers of other cpus
+ * will be saved in machine_crash_shutdown while shooting down them.
+ */
 
+static inline void crash_setup_regs(struct pt_regs *newregs,
+						struct pt_regs *oldregs)
+{
+	if (oldregs)
+		memcpy(newregs, oldregs, sizeof(*newregs));
+	else {
+		__asm__ __volatile__("movq %%rbx,%0" : "=m"(newregs->rbx));
+		__asm__ __volatile__("movq %%rcx,%0" : "=m"(newregs->rcx));
+		__asm__ __volatile__("movq %%rdx,%0" : "=m"(newregs->rdx));
+		__asm__ __volatile__("movq %%rsi,%0" : "=m"(newregs->rsi));
+		__asm__ __volatile__("movq %%rdi,%0" : "=m"(newregs->rdi));
+		__asm__ __volatile__("movq %%rbp,%0" : "=m"(newregs->rbp));
+		__asm__ __volatile__("movq %%rax,%0" : "=m"(newregs->rax));
+		__asm__ __volatile__("movq %%rsp,%0" : "=m"(newregs->rsp));
+		__asm__ __volatile__("movq %%r8,%0" : "=m"(newregs->r8));
+		__asm__ __volatile__("movq %%r9,%0" : "=m"(newregs->r9));
+		__asm__ __volatile__("movq %%r10,%0" : "=m"(newregs->r10));
+		__asm__ __volatile__("movq %%r11,%0" : "=m"(newregs->r11));
+		__asm__ __volatile__("movq %%r12,%0" : "=m"(newregs->r12));
+		__asm__ __volatile__("movq %%r13,%0" : "=m"(newregs->r13));
+		__asm__ __volatile__("movq %%r14,%0" : "=m"(newregs->r14));
+		__asm__ __volatile__("movq %%r15,%0" : "=m"(newregs->r15));
+		__asm__ __volatile__("movl %%ss, %%eax;" :"=a"(newregs->ss));
+		__asm__ __volatile__("movl %%cs, %%eax;" :"=a"(newregs->cs));
+		__asm__ __volatile__("pushfq; popq %0" :"=m"(newregs->eflags));
+
+		newregs->rip = (unsigned long)current_text_addr();
+	}
+}
 #endif /* _X86_64_KEXEC_H */
diff --git a/include/asm-x86_64/kprobes.h b/include/asm-x86_64/kprobes.h
index 4dd7a7e..98a1e95d 100644
--- a/include/asm-x86_64/kprobes.h
+++ b/include/asm-x86_64/kprobes.h
@@ -27,7 +27,10 @@
 #include <linux/ptrace.h>
 #include <linux/percpu.h>
 
+#define  __ARCH_WANT_KPROBES_INSN_SLOT
+
 struct pt_regs;
+struct kprobe;
 
 typedef u8 kprobe_opcode_t;
 #define BREAKPOINT_INSTRUCTION	0xcc
@@ -42,6 +45,7 @@
 #define ARCH_SUPPORTS_KRETPROBES
 
 void kretprobe_trampoline(void);
+extern void arch_remove_kprobe(struct kprobe *p);
 
 /* Architecture specific copy of original instruction*/
 struct arch_specific_insn {
diff --git a/include/asm-x86_64/mmu_context.h b/include/asm-x86_64/mmu_context.h
index b630d52..16e4be4 100644
--- a/include/asm-x86_64/mmu_context.h
+++ b/include/asm-x86_64/mmu_context.h
@@ -15,18 +15,13 @@
 int init_new_context(struct task_struct *tsk, struct mm_struct *mm);
 void destroy_context(struct mm_struct *mm);
 
-#ifdef CONFIG_SMP
-
 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
 {
+#ifdef CONFIG_SMP
 	if (read_pda(mmu_state) == TLBSTATE_OK) 
 		write_pda(mmu_state, TLBSTATE_LAZY);
-}
-#else
-static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
-{
-}
 #endif
+}
 
 static inline void load_cr3(pgd_t *pgd)
 {
diff --git a/include/asm-x86_64/mmzone.h b/include/asm-x86_64/mmzone.h
index 69baaa8..972c935 100644
--- a/include/asm-x86_64/mmzone.h
+++ b/include/asm-x86_64/mmzone.h
@@ -36,22 +36,12 @@
 				 NODE_DATA(nid)->node_spanned_pages)
 
 #ifdef CONFIG_DISCONTIGMEM
-
 #define pfn_to_nid(pfn) phys_to_nid((unsigned long)(pfn) << PAGE_SHIFT)
 #define kvaddr_to_nid(kaddr)	phys_to_nid(__pa(kaddr))
 
-/* Requires pfn_valid(pfn) to be true */
-#define pfn_to_page(pfn) ({ \
-	int nid = phys_to_nid(((unsigned long)(pfn)) << PAGE_SHIFT); 	\
-	((pfn) - node_start_pfn(nid)) + NODE_DATA(nid)->node_mem_map;	\
-})
-
-#define page_to_pfn(page) \
-	(long)(((page) - page_zone(page)->zone_mem_map) + page_zone(page)->zone_start_pfn)
-
-#define pfn_valid(pfn) ((pfn) >= num_physpages ? 0 : \
-			({ u8 nid__ = pfn_to_nid(pfn); \
-			   nid__ != 0xff && (pfn) >= node_start_pfn(nid__) && (pfn) < node_end_pfn(nid__); }))
+extern struct page *pfn_to_page(unsigned long pfn);
+extern unsigned long page_to_pfn(struct page *page);
+extern int pfn_valid(unsigned long pfn);
 #endif
 
 #define local_mapnr(kvaddr) \
diff --git a/include/asm-x86_64/mutex.h b/include/asm-x86_64/mutex.h
index 818abfd..11fbee2 100644
--- a/include/asm-x86_64/mutex.h
+++ b/include/asm-x86_64/mutex.h
@@ -104,7 +104,7 @@
 static inline int
 __mutex_fastpath_trylock(atomic_t *count, int (*fail_fn)(atomic_t *))
 {
-	if (likely(atomic_cmpxchg(count, 1, 0)) == 1)
+	if (likely(atomic_cmpxchg(count, 1, 0) == 1))
 		return 1;
 	else
 		return 0;
diff --git a/include/asm-x86_64/numa.h b/include/asm-x86_64/numa.h
index d51e56f..34e434c 100644
--- a/include/asm-x86_64/numa.h
+++ b/include/asm-x86_64/numa.h
@@ -20,6 +20,11 @@
 extern void numa_set_node(int cpu, int node);
 
 extern unsigned char apicid_to_node[256];
+#ifdef CONFIG_NUMA
+extern void __init init_cpu_to_node(void);
+#else
+#define init_cpu_to_node() do {} while (0)
+#endif
 
 #define NUMA_NO_NODE 0xff
 
diff --git a/include/asm-x86_64/page.h b/include/asm-x86_64/page.h
index 06e489f..dcbb4fc 100644
--- a/include/asm-x86_64/page.h
+++ b/include/asm-x86_64/page.h
@@ -14,13 +14,18 @@
 #define PHYSICAL_PAGE_MASK	(~(PAGE_SIZE-1) & __PHYSICAL_MASK)
 
 #define THREAD_ORDER 1 
-#ifdef __ASSEMBLY__
-#define THREAD_SIZE  (1 << (PAGE_SHIFT + THREAD_ORDER))
-#else
-#define THREAD_SIZE  (1UL << (PAGE_SHIFT + THREAD_ORDER))
-#endif
+#define THREAD_SIZE  (PAGE_SIZE << THREAD_ORDER)
 #define CURRENT_MASK (~(THREAD_SIZE-1))
 
+#define EXCEPTION_STACK_ORDER 0
+#define EXCEPTION_STKSZ (PAGE_SIZE << EXCEPTION_STACK_ORDER)
+
+#define DEBUG_STACK_ORDER EXCEPTION_STACK_ORDER
+#define DEBUG_STKSZ (PAGE_SIZE << DEBUG_STACK_ORDER)
+
+#define IRQSTACK_ORDER 2
+#define IRQSTACKSIZE (PAGE_SIZE << IRQSTACK_ORDER)
+
 #define LARGE_PAGE_MASK (~(LARGE_PAGE_SIZE-1))
 #define LARGE_PAGE_SIZE (1UL << PMD_SHIFT)
 
diff --git a/include/asm-x86_64/pci.h b/include/asm-x86_64/pci.h
index eeb3088..fd03e15 100644
--- a/include/asm-x86_64/pci.h
+++ b/include/asm-x86_64/pci.h
@@ -42,18 +42,20 @@
 #include <asm/scatterlist.h>
 #include <linux/string.h>
 #include <asm/page.h>
+#include <linux/dma-mapping.h> /* for have_iommu */
 
 extern int iommu_setup(char *opt);
 
-#ifdef CONFIG_GART_IOMMU
 /* The PCI address space does equal the physical memory
  * address space.  The networking and block device layers use
  * this boolean for bounce buffer decisions
  *
- * On AMD64 it mostly equals, but we set it to zero to tell some subsystems
- * that an IOMMU is available.
+ * On AMD64 it mostly equals, but we set it to zero if a hardware
+ * IOMMU (gart) of sotware IOMMU (swiotlb) is available.
  */
-#define PCI_DMA_BUS_IS_PHYS	(no_iommu ? 1 : 0)
+#define PCI_DMA_BUS_IS_PHYS (dma_ops->is_phys)
+
+#ifdef CONFIG_GART_IOMMU
 
 /*
  * x86-64 always supports DAC, but sometimes it is useful to force
@@ -79,7 +81,6 @@
 #else
 /* No IOMMU */
 
-#define PCI_DMA_BUS_IS_PHYS	1
 #define pci_dac_dma_supported(pci_dev, mask)    1
 
 #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME)
diff --git a/include/asm-x86_64/pda.h b/include/asm-x86_64/pda.h
index 8733ccf..c7ab38a 100644
--- a/include/asm-x86_64/pda.h
+++ b/include/asm-x86_64/pda.h
@@ -5,6 +5,7 @@
 #include <linux/stddef.h>
 #include <linux/types.h>
 #include <linux/cache.h>
+#include <asm/page.h>
 
 /* Per processor datastructure. %gs points to it while the kernel runs */ 
 struct x8664_pda {
@@ -12,6 +13,9 @@
 	unsigned long data_offset;	/* Per cpu data offset from linker address */
 	unsigned long kernelstack;  /* top of kernel stack for current */ 
 	unsigned long oldrsp; 	    /* user rsp for system call */
+#if DEBUG_STKSZ > EXCEPTION_STKSZ
+	unsigned long debugstack;   /* #DB/#BP stack. */
+#endif
         int irqcount;		    /* Irq nesting counter. Starts with -1 */  	
 	int cpunumber;		    /* Logical CPU number */
 	char *irqstackptr;	/* top of irqstack */
@@ -23,11 +27,10 @@
 	unsigned apic_timer_irqs;
 } ____cacheline_aligned_in_smp;
 
+extern struct x8664_pda *_cpu_pda[];
+extern struct x8664_pda boot_cpu_pda[];
 
-#define IRQSTACK_ORDER 2
-#define IRQSTACKSIZE (PAGE_SIZE << IRQSTACK_ORDER) 
-
-extern struct x8664_pda cpu_pda[];
+#define cpu_pda(i) (_cpu_pda[i])
 
 /* 
  * There is no fast way to get the base address of the PDA, all the accesses
diff --git a/include/asm-x86_64/percpu.h b/include/asm-x86_64/percpu.h
index 9c71855..29a6b04 100644
--- a/include/asm-x86_64/percpu.h
+++ b/include/asm-x86_64/percpu.h
@@ -11,7 +11,7 @@
 
 #include <asm/pda.h>
 
-#define __per_cpu_offset(cpu) (cpu_pda[cpu].data_offset)
+#define __per_cpu_offset(cpu) (cpu_pda(cpu)->data_offset)
 #define __my_cpu_offset() read_pda(data_offset)
 
 /* Separate out the type, so (int[3], foo) works. */
diff --git a/include/asm-x86_64/pgtable.h b/include/asm-x86_64/pgtable.h
index 02888d7..8fbf4dd 100644
--- a/include/asm-x86_64/pgtable.h
+++ b/include/asm-x86_64/pgtable.h
@@ -267,25 +267,25 @@
  */
 #define __LARGE_PTE (_PAGE_PSE|_PAGE_PRESENT)
 static inline int pte_user(pte_t pte)		{ return pte_val(pte) & _PAGE_USER; }
-extern inline int pte_read(pte_t pte)		{ return pte_val(pte) & _PAGE_USER; }
-extern inline int pte_exec(pte_t pte)		{ return pte_val(pte) & _PAGE_USER; }
-extern inline int pte_dirty(pte_t pte)		{ return pte_val(pte) & _PAGE_DIRTY; }
-extern inline int pte_young(pte_t pte)		{ return pte_val(pte) & _PAGE_ACCESSED; }
-extern inline int pte_write(pte_t pte)		{ return pte_val(pte) & _PAGE_RW; }
+static inline int pte_read(pte_t pte)		{ return pte_val(pte) & _PAGE_USER; }
+static inline int pte_exec(pte_t pte)		{ return pte_val(pte) & _PAGE_USER; }
+static inline int pte_dirty(pte_t pte)		{ return pte_val(pte) & _PAGE_DIRTY; }
+static inline int pte_young(pte_t pte)		{ return pte_val(pte) & _PAGE_ACCESSED; }
+static inline int pte_write(pte_t pte)		{ return pte_val(pte) & _PAGE_RW; }
 static inline int pte_file(pte_t pte)		{ return pte_val(pte) & _PAGE_FILE; }
 static inline int pte_huge(pte_t pte)		{ return (pte_val(pte) & __LARGE_PTE) == __LARGE_PTE; }
 
-extern inline pte_t pte_rdprotect(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_USER)); return pte; }
-extern inline pte_t pte_exprotect(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_USER)); return pte; }
-extern inline pte_t pte_mkclean(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_DIRTY)); return pte; }
-extern inline pte_t pte_mkold(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_ACCESSED)); return pte; }
-extern inline pte_t pte_wrprotect(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_RW)); return pte; }
-extern inline pte_t pte_mkread(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) | _PAGE_USER)); return pte; }
-extern inline pte_t pte_mkexec(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) | _PAGE_USER)); return pte; }
-extern inline pte_t pte_mkdirty(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) | _PAGE_DIRTY)); return pte; }
-extern inline pte_t pte_mkyoung(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) | _PAGE_ACCESSED)); return pte; }
-extern inline pte_t pte_mkwrite(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) | _PAGE_RW)); return pte; }
-extern inline pte_t pte_mkhuge(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) | __LARGE_PTE)); return pte; }
+static inline pte_t pte_rdprotect(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_USER)); return pte; }
+static inline pte_t pte_exprotect(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_USER)); return pte; }
+static inline pte_t pte_mkclean(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_DIRTY)); return pte; }
+static inline pte_t pte_mkold(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_ACCESSED)); return pte; }
+static inline pte_t pte_wrprotect(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_RW)); return pte; }
+static inline pte_t pte_mkread(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) | _PAGE_USER)); return pte; }
+static inline pte_t pte_mkexec(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) | _PAGE_USER)); return pte; }
+static inline pte_t pte_mkdirty(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) | _PAGE_DIRTY)); return pte; }
+static inline pte_t pte_mkyoung(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) | _PAGE_ACCESSED)); return pte; }
+static inline pte_t pte_mkwrite(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) | _PAGE_RW)); return pte; }
+static inline pte_t pte_mkhuge(pte_t pte)	{ set_pte(&pte, __pte(pte_val(pte) | __LARGE_PTE)); return pte; }
 
 struct vm_area_struct;
 
diff --git a/include/asm-x86_64/processor.h b/include/asm-x86_64/processor.h
index 4861246..87a282b 100644
--- a/include/asm-x86_64/processor.h
+++ b/include/asm-x86_64/processor.h
@@ -227,7 +227,13 @@
 extern struct cpuinfo_x86 boot_cpu_data;
 DECLARE_PER_CPU(struct tss_struct,init_tss);
 
+#ifdef CONFIG_X86_VSMP
+#define ARCH_MIN_TASKALIGN	(1 << INTERNODE_CACHE_SHIFT)
+#define ARCH_MIN_MMSTRUCT_ALIGN	(1 << INTERNODE_CACHE_SHIFT)
+#else
 #define ARCH_MIN_TASKALIGN	16
+#define ARCH_MIN_MMSTRUCT_ALIGN	0
+#endif
 
 struct thread_struct {
 	unsigned long	rsp0;
@@ -273,8 +279,6 @@
 #define DEBUG_STACK 4 
 #define MCE_STACK 5
 #define N_EXCEPTION_STACKS 5  /* hw limit: 7 */
-#define EXCEPTION_STKSZ (PAGE_SIZE << EXCEPTION_STACK_ORDER)
-#define EXCEPTION_STACK_ORDER 0 
 
 #define start_thread(regs,new_rip,new_rsp) do { \
 	asm volatile("movl %0,%%fs; movl %0,%%es; movl %0,%%ds": :"r" (0));	 \
@@ -317,8 +321,8 @@
 #define thread_saved_pc(t) (*(unsigned long *)((t)->thread.rsp - 8))
 
 extern unsigned long get_wchan(struct task_struct *p);
-#define KSTK_EIP(tsk) \
-	(((struct pt_regs *)(tsk->thread.rsp0 - sizeof(struct pt_regs)))->rip)
+#define task_pt_regs(tsk) ((struct pt_regs *)(tsk)->thread.rsp0 - 1)
+#define KSTK_EIP(tsk) (task_pt_regs(tsk)->rip)
 #define KSTK_ESP(tsk) -1 /* sorry. doesn't work for syscall. */
 
 
diff --git a/include/asm-x86_64/proto.h b/include/asm-x86_64/proto.h
index 3450108..115e496 100644
--- a/include/asm-x86_64/proto.h
+++ b/include/asm-x86_64/proto.h
@@ -67,8 +67,6 @@
 
 extern unsigned long end_pfn_map; 
 
-extern cpumask_t cpu_initialized;
-
 extern void show_trace(unsigned long * rsp);
 extern void show_registers(struct pt_regs *regs);
 
@@ -91,8 +89,12 @@
 
 extern int unhandled_signal(struct task_struct *tsk, int sig);
 
+extern int unsynchronized_tsc(void);
+
 extern void select_idle_routine(const struct cpuinfo_x86 *c);
-extern void swiotlb_init(void);
+
+extern void gart_parse_options(char *);
+extern void __init no_iommu_init(void);
 
 extern unsigned long table_start, table_end;
 
@@ -106,12 +108,17 @@
 extern int acpi_ht;
 extern int acpi_disabled;
 
+#ifdef CONFIG_GART_IOMMU
 extern int fallback_aper_order;
 extern int fallback_aper_force;
 extern int iommu_aperture;
-extern int iommu_aperture_disabled;
 extern int iommu_aperture_allowed;
+extern int iommu_aperture_disabled;
 extern int fix_aperture;
+#else
+#define iommu_aperture 0
+#define iommu_aperture_allowed 0
+#endif
 extern int force_iommu;
 
 extern int reboot_force;
diff --git a/include/asm-x86_64/segment.h b/include/asm-x86_64/segment.h
index 44adaf1..d4bed33 100644
--- a/include/asm-x86_64/segment.h
+++ b/include/asm-x86_64/segment.h
@@ -19,15 +19,13 @@
 #define __USER_DS     0x2b   /* 5*8+3 */ 
 #define __USER_CS     0x33   /* 6*8+3 */ 
 #define __USER32_DS	__USER_DS 
-#define __KERNEL16_CS	(GDT_ENTRY_KERNELCS16 * 8)
-#define __KERNEL_COMPAT32_CS   0x8
 
 #define GDT_ENTRY_TLS 1
 #define GDT_ENTRY_TSS 8	/* needs two entries */
 #define GDT_ENTRY_LDT 10 /* needs two entries */
 #define GDT_ENTRY_TLS_MIN 12
 #define GDT_ENTRY_TLS_MAX 14
-#define GDT_ENTRY_KERNELCS16 15
+/* 15 free */
 
 #define GDT_ENTRY_TLS_ENTRIES 3
 
diff --git a/include/asm-x86_64/smp.h b/include/asm-x86_64/smp.h
index d030409..9ccbb2c 100644
--- a/include/asm-x86_64/smp.h
+++ b/include/asm-x86_64/smp.h
@@ -35,6 +35,7 @@
 extern cpumask_t cpu_possible_map;
 extern cpumask_t cpu_online_map;
 extern cpumask_t cpu_callout_map;
+extern cpumask_t cpu_initialized;
 
 /*
  * Private routines/data
diff --git a/include/asm-x86_64/swiotlb.h b/include/asm-x86_64/swiotlb.h
index dddf1b2..60757ef 100644
--- a/include/asm-x86_64/swiotlb.h
+++ b/include/asm-x86_64/swiotlb.h
@@ -3,10 +3,14 @@
 
 #include <linux/config.h>
 
+#include <asm/dma-mapping.h>
+
 /* SWIOTLB interface */
 
-extern dma_addr_t swiotlb_map_single(struct device *hwdev, void *ptr, size_t size,
-				      int dir);
+extern dma_addr_t swiotlb_map_single(struct device *hwdev, void *ptr,
+				     size_t size, int dir);
+extern void *swiotlb_alloc_coherent(struct device *hwdev, size_t size,
+                       dma_addr_t *dma_handle, gfp_t flags);
 extern void swiotlb_unmap_single(struct device *hwdev, dma_addr_t dev_addr,
 				  size_t size, int dir);
 extern void swiotlb_sync_single_for_cpu(struct device *hwdev,
@@ -34,10 +38,10 @@
 extern void swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sg,
 			 int nents, int direction);
 extern int swiotlb_dma_mapping_error(dma_addr_t dma_addr);
-extern void *swiotlb_alloc_coherent (struct device *hwdev, size_t size,
-				     dma_addr_t *dma_handle, gfp_t flags);
 extern void swiotlb_free_coherent (struct device *hwdev, size_t size,
 				   void *vaddr, dma_addr_t dma_handle);
+extern int swiotlb_dma_supported(struct device *hwdev, u64 mask);
+extern void swiotlb_init(void);
 
 #ifdef CONFIG_SWIOTLB
 extern int swiotlb;
@@ -45,4 +49,6 @@
 #define swiotlb 0
 #endif
 
-#endif
+extern void pci_swiotlb_init(void);
+
+#endif /* _ASM_SWTIOLB_H */
diff --git a/include/asm-x86_64/system.h b/include/asm-x86_64/system.h
index b34cc2e..0eacbef 100644
--- a/include/asm-x86_64/system.h
+++ b/include/asm-x86_64/system.h
@@ -20,8 +20,8 @@
 #define __RESTORE(reg,offset) "movq (14-" #offset ")*8(%%rsp),%%" #reg "\n\t"
 
 /* frame pointer must be last for get_wchan */
-#define SAVE_CONTEXT    "pushfq ; pushq %%rbp ; movq %%rsi,%%rbp\n\t"
-#define RESTORE_CONTEXT "movq %%rbp,%%rsi ; popq %%rbp ; popfq\n\t" 
+#define SAVE_CONTEXT    "pushq %%rbp ; movq %%rsi,%%rbp\n\t"
+#define RESTORE_CONTEXT "movq %%rbp,%%rsi ; popq %%rbp\n\t"
 
 #define __EXTRA_CLOBBER  \
 	,"rcx","rbx","rdx","r8","r9","r10","r11","r12","r13","r14","r15"
@@ -137,6 +137,21 @@
 		      "663:\n\t" newinstr "\n664:\n"   /* replacement */ \
 		      ".previous" :: "i" (feature), ##input)
 
+/* Like alternative_input, but with a single output argument */
+#define alternative_io(oldinstr, newinstr, feature, output, input...) \
+	asm volatile ("661:\n\t" oldinstr "\n662:\n"			\
+		      ".section .altinstructions,\"a\"\n"		\
+		      "  .align 8\n"					\
+		      "  .quad 661b\n"            /* label */		\
+		      "  .quad 663f\n"		  /* new instruction */	\
+		      "  .byte %c[feat]\n"        /* feature bit */	\
+		      "  .byte 662b-661b\n"       /* sourcelen */	\
+		      "  .byte 664f-663f\n"       /* replacementlen */	\
+		      ".previous\n"					\
+		      ".section .altinstr_replacement,\"ax\"\n"		\
+		      "663:\n\t" newinstr "\n664:\n"   /* replacement */ \
+		      ".previous" : output : [feat] "i" (feature), ##input)
+
 /*
  * Clear and set 'TS' bit respectively
  */
@@ -178,6 +193,15 @@
 #define wbinvd() \
 	__asm__ __volatile__ ("wbinvd": : :"memory");
 
+/*
+ * On SMP systems, when the scheduler does migration-cost autodetection,
+ * it needs a way to flush as much of the CPU's caches as possible.
+ */
+static inline void sched_cacheflush(void)
+{
+	wbinvd();
+}
+
 #endif	/* __KERNEL__ */
 
 #define nop() __asm__ __volatile__ ("nop")
@@ -311,8 +335,25 @@
 /* interrupt control.. */
 #define local_save_flags(x)	do { warn_if_not_ulong(x); __asm__ __volatile__("# save_flags \n\t pushfq ; popq %q0":"=g" (x): /* no input */ :"memory"); } while (0)
 #define local_irq_restore(x) 	__asm__ __volatile__("# restore_flags \n\t pushq %0 ; popfq": /* no output */ :"g" (x):"memory", "cc")
+
+#ifdef CONFIG_X86_VSMP
+/* Interrupt control for VSMP  architecture */
+#define local_irq_disable()	do { unsigned long flags; local_save_flags(flags); local_irq_restore((flags & ~(1 << 9)) | (1 << 18)); } while (0)
+#define local_irq_enable()	do { unsigned long flags; local_save_flags(flags); local_irq_restore((flags | (1 << 9)) & ~(1 << 18)); } while (0)
+
+#define irqs_disabled()					\
+({							\
+	unsigned long flags;				\
+	local_save_flags(flags);			\
+	(flags & (1<<18)) || !(flags & (1<<9));		\
+})
+
+/* For spinlocks etc */
+#define local_irq_save(x)	do { local_save_flags(x); local_irq_restore((x & ~(1 << 9)) | (1 << 18)); } while (0)
+#else  /* CONFIG_X86_VSMP */
 #define local_irq_disable() 	__asm__ __volatile__("cli": : :"memory")
 #define local_irq_enable()	__asm__ __volatile__("sti": : :"memory")
+
 /* used in the idle loop; sti takes one instruction cycle to complete */
 #define safe_halt()		__asm__ __volatile__("sti; hlt": : :"memory")
 /* used when interrupts are already enabled or to shutdown the processor */
@@ -327,16 +368,10 @@
 
 /* For spinlocks etc */
 #define local_irq_save(x) 	do { warn_if_not_ulong(x); __asm__ __volatile__("# local_irq_save \n\t pushfq ; popq %0 ; cli":"=g" (x): /* no input */ :"memory"); } while (0)
+#endif
 
 void cpu_idle_wait(void);
 
-/*
- * disable hlt during certain critical i/o operations
- */
-#define HAVE_DISABLE_HLT
-void disable_hlt(void);
-void enable_hlt(void);
-
 extern unsigned long arch_align_stack(unsigned long sp);
 
 #endif
diff --git a/include/asm-x86_64/thread_info.h b/include/asm-x86_64/thread_info.h
index 08eb6e4..4ac0e0a 100644
--- a/include/asm-x86_64/thread_info.h
+++ b/include/asm-x86_64/thread_info.h
@@ -76,8 +76,6 @@
 #define alloc_thread_info(tsk) \
 	((struct thread_info *) __get_free_pages(GFP_KERNEL,THREAD_ORDER))
 #define free_thread_info(ti) free_pages((unsigned long) (ti), THREAD_ORDER)
-#define get_thread_info(ti) get_task_struct((ti)->task)
-#define put_thread_info(ti) put_task_struct((ti)->task)
 
 #else /* !__ASSEMBLY__ */
 
@@ -138,6 +136,7 @@
  * have to worry about atomic accesses.
  */
 #define TS_USEDFPU		0x0001	/* FPU was used by this task this quantum (SMP) */
+#define TS_COMPAT		0x0002	/* 32bit syscall active */
 
 #endif /* __KERNEL__ */
 
diff --git a/include/asm-x86_64/timex.h b/include/asm-x86_64/timex.h
index f971f45..f18443f 100644
--- a/include/asm-x86_64/timex.h
+++ b/include/asm-x86_64/timex.h
@@ -10,6 +10,9 @@
 #include <asm/msr.h>
 #include <asm/vsyscall.h>
 #include <asm/hpet.h>
+#include <asm/system.h>
+#include <asm/processor.h>
+#include <linux/compiler.h>
 
 #define CLOCK_TICK_RATE	PIT_TICK_RATE	/* Underlying HZ */
 
@@ -23,6 +26,19 @@
 	return ret;
 }
 
+/* Like get_cycles, but make sure the CPU is synchronized. */
+static __always_inline cycles_t get_cycles_sync(void)
+{
+	unsigned long long ret;
+	unsigned eax;
+	/* Don't do an additional sync on CPUs where we know
+	   RDTSC is already synchronous. */
+	alternative_io(ASM_NOP2, "cpuid", X86_FEATURE_SYNC_RDTSC,
+			  "=a" (eax), "0" (1) : "ebx","ecx","edx","memory");
+	rdtscll(ret);
+	return ret;
+}
+
 extern unsigned int cpu_khz;
 
 extern int read_current_timer(unsigned long *timer_value);
diff --git a/include/asm-x86_64/topology.h b/include/asm-x86_64/topology.h
index 7d82bc5..2fa7f27 100644
--- a/include/asm-x86_64/topology.h
+++ b/include/asm-x86_64/topology.h
@@ -39,7 +39,6 @@
 	.max_interval		= 32,			\
 	.busy_factor		= 32,			\
 	.imbalance_pct		= 125,			\
-	.cache_hot_time		= (10*1000000),		\
 	.cache_nice_tries	= 2,			\
 	.busy_idx		= 3,			\
 	.idle_idx		= 2,			\
diff --git a/include/asm-x86_64/uaccess.h b/include/asm-x86_64/uaccess.h
index 1bb8b8a..2892c4b 100644
--- a/include/asm-x86_64/uaccess.h
+++ b/include/asm-x86_64/uaccess.h
@@ -348,6 +348,7 @@
 long strncpy_from_user(char *dst, const char __user *src, long count);
 long __strncpy_from_user(char *dst, const char __user *src, long count);
 long strnlen_user(const char __user *str, long n);
+long __strnlen_user(const char __user *str, long n);
 long strlen_user(const char __user *str);
 unsigned long clear_user(void __user *mem, unsigned long len);
 unsigned long __clear_user(void __user *mem, unsigned long len);
diff --git a/include/asm-x86_64/vsyscall.h b/include/asm-x86_64/vsyscall.h
index 438a3f5..a85e16f 100644
--- a/include/asm-x86_64/vsyscall.h
+++ b/include/asm-x86_64/vsyscall.h
@@ -36,8 +36,8 @@
 	int mode;
 };
 
-#define hpet_readl(a)           readl((void *)fix_to_virt(FIX_HPET_BASE) + a)
-#define hpet_writel(d,a)        writel(d, (void *)fix_to_virt(FIX_HPET_BASE) + a)
+#define hpet_readl(a)           readl((const void __iomem *)fix_to_virt(FIX_HPET_BASE) + a)
+#define hpet_writel(d,a)        writel(d, (void __iomem *)fix_to_virt(FIX_HPET_BASE) + a)
 
 /* vsyscall space (readonly) */
 extern struct vxtime_data __vxtime;
diff --git a/include/asm-xtensa/ioctl.h b/include/asm-xtensa/ioctl.h
index 856c605..b279fe0 100644
--- a/include/asm-xtensa/ioctl.h
+++ b/include/asm-xtensa/ioctl.h
@@ -1,83 +1 @@
-/*
- * include/asm-xtensa/ioctl.h
- *
- * 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) 2003 - 2005 Tensilica Inc.
- *
- * Derived from "include/asm-i386/ioctl.h"
- */
-
-#ifndef _XTENSA_IOCTL_H
-#define _XTENSA_IOCTL_H
-
-
-/* ioctl command encoding: 32 bits total, command in lower 16 bits,
- * size of the parameter structure in the lower 14 bits of the
- * upper 16 bits.
- * Encoding the size of the parameter structure in the ioctl request
- * is useful for catching programs compiled with old versions
- * and to avoid overwriting user space outside the user buffer area.
- * The highest 2 bits are reserved for indicating the ``access mode''.
- * NOTE: This limits the max parameter size to 16kB -1 !
- */
-
-/*
- * The following is for compatibility across the various Linux
- * platforms.  The i386 ioctl numbering scheme doesn't really enforce
- * a type field.  De facto, however, the top 8 bits of the lower 16
- * bits are indeed used as a type field, so we might just as well make
- * this explicit here.  Please be sure to use the decoding macros
- * below from now on.
- */
-#define _IOC_NRBITS	8
-#define _IOC_TYPEBITS	8
-#define _IOC_SIZEBITS	14
-#define _IOC_DIRBITS	2
-
-#define _IOC_NRMASK	((1 << _IOC_NRBITS)-1)
-#define _IOC_TYPEMASK	((1 << _IOC_TYPEBITS)-1)
-#define _IOC_SIZEMASK	((1 << _IOC_SIZEBITS)-1)
-#define _IOC_DIRMASK	((1 << _IOC_DIRBITS)-1)
-
-#define _IOC_NRSHIFT	0
-#define _IOC_TYPESHIFT	(_IOC_NRSHIFT+_IOC_NRBITS)
-#define _IOC_SIZESHIFT	(_IOC_TYPESHIFT+_IOC_TYPEBITS)
-#define _IOC_DIRSHIFT	(_IOC_SIZESHIFT+_IOC_SIZEBITS)
-
-/*
- * Direction bits.
- */
-#define _IOC_NONE	0U
-#define _IOC_WRITE	1U
-#define _IOC_READ	2U
-
-#define _IOC(dir,type,nr,size) \
-	(((dir)  << _IOC_DIRSHIFT) | \
-	 ((type) << _IOC_TYPESHIFT) | \
-	 ((nr)   << _IOC_NRSHIFT) | \
-	 ((size) << _IOC_SIZESHIFT))
-
-/* used to create numbers */
-#define _IO(type,nr)		_IOC(_IOC_NONE,(type),(nr),0)
-#define _IOR(type,nr,size)	_IOC(_IOC_READ,(type),(nr),sizeof(size))
-#define _IOW(type,nr,size)	_IOC(_IOC_WRITE,(type),(nr),sizeof(size))
-#define _IOWR(type,nr,size)	_IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
-
-/* used to decode ioctl numbers.. */
-#define _IOC_DIR(nr)		(((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
-#define _IOC_TYPE(nr)		(((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
-#define _IOC_NR(nr)		(((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
-#define _IOC_SIZE(nr)		(((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
-
-/* ...and for the drivers/sound files... */
-
-#define IOC_IN		(_IOC_WRITE << _IOC_DIRSHIFT)
-#define IOC_OUT		(_IOC_READ << _IOC_DIRSHIFT)
-#define IOC_INOUT	((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
-#define IOCSIZE_MASK	(_IOC_SIZEMASK << _IOC_SIZESHIFT)
-#define IOCSIZE_SHIFT	(_IOC_SIZESHIFT)
-
-#endif
+#include <asm-generic/ioctl.h>
diff --git a/include/asm-xtensa/processor.h b/include/asm-xtensa/processor.h
index 9cab5e4..d1d72ad 100644
--- a/include/asm-xtensa/processor.h
+++ b/include/asm-xtensa/processor.h
@@ -184,12 +184,12 @@
 #define release_segments(mm)	do { } while(0)
 #define forget_segments()	do { } while (0)
 
-#define thread_saved_pc(tsk)	(xtensa_pt_regs(tsk)->pc)
+#define thread_saved_pc(tsk)	(task_pt_regs(tsk)->pc)
 
 extern unsigned long get_wchan(struct task_struct *p);
 
-#define KSTK_EIP(tsk)		(xtensa_pt_regs(tsk)->pc)
-#define KSTK_ESP(tsk)		(xtensa_pt_regs(tsk)->areg[1])
+#define KSTK_EIP(tsk)		(task_pt_regs(tsk)->pc)
+#define KSTK_ESP(tsk)		(task_pt_regs(tsk)->areg[1])
 
 #define cpu_relax()  do { } while (0)
 
diff --git a/include/asm-xtensa/ptrace.h b/include/asm-xtensa/ptrace.h
index aa4fd7f..a5ac71a 100644
--- a/include/asm-xtensa/ptrace.h
+++ b/include/asm-xtensa/ptrace.h
@@ -113,8 +113,8 @@
 };
 
 #ifdef __KERNEL__
-# define xtensa_pt_regs(tsk) ((struct pt_regs*) \
-  (((long)(tsk)->thread_info + KERNEL_STACK_SIZE - (XCHAL_NUM_AREGS-16)*4)) - 1)
+# define task_pt_regs(tsk) ((struct pt_regs*) \
+  (task_stack_page(tsk) + KERNEL_STACK_SIZE - (XCHAL_NUM_AREGS-16)*4) - 1)
 # define user_mode(regs) (((regs)->ps & 0x00000020)!=0)
 # define instruction_pointer(regs) ((regs)->pc)
 extern void show_regs(struct pt_regs *);
diff --git a/include/asm-xtensa/thread_info.h b/include/asm-xtensa/thread_info.h
index af208d4..5ae34ab 100644
--- a/include/asm-xtensa/thread_info.h
+++ b/include/asm-xtensa/thread_info.h
@@ -93,8 +93,6 @@
 /* thread information allocation */
 #define alloc_thread_info(tsk) ((struct thread_info *) __get_free_pages(GFP_KERNEL,1))
 #define free_thread_info(ti) free_pages((unsigned long) (ti), 1)
-#define get_thread_info(ti) get_task_struct((ti)->task)
-#define put_thread_info(ti) put_task_struct((ti)->task)
 
 #else /* !__ASSEMBLY__ */
 
diff --git a/include/linux/cache.h b/include/linux/cache.h
index ffe5221..d22e632 100644
--- a/include/linux/cache.h
+++ b/include/linux/cache.h
@@ -13,7 +13,7 @@
 #define SMP_CACHE_BYTES L1_CACHE_BYTES
 #endif
 
-#if defined(CONFIG_X86) || defined(CONFIG_SPARC64) || defined(CONFIG_IA64)
+#if defined(CONFIG_X86) || defined(CONFIG_SPARC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC)
 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
 #else
 #define __read_mostly
diff --git a/include/linux/calc64.h b/include/linux/calc64.h
new file mode 100644
index 0000000..ebf4b8f
--- /dev/null
+++ b/include/linux/calc64.h
@@ -0,0 +1,49 @@
+#ifndef _LINUX_CALC64_H
+#define _LINUX_CALC64_H
+
+#include <linux/types.h>
+#include <asm/div64.h>
+
+/*
+ * This is a generic macro which is used when the architecture
+ * specific div64.h does not provide a optimized one.
+ *
+ * The 64bit dividend is divided by the divisor (data type long), the
+ * result is returned and the remainder stored in the variable
+ * referenced by remainder (data type long *). In contrast to the
+ * do_div macro the dividend is kept intact.
+ */
+#ifndef div_long_long_rem
+#define div_long_long_rem(dividend, divisor, remainder)	\
+	do_div_llr((dividend), divisor, remainder)
+
+static inline unsigned long do_div_llr(const long long dividend,
+				       const long divisor, long *remainder)
+{
+	u64 result = dividend;
+
+	*(remainder) = do_div(result, divisor);
+	return (unsigned long) result;
+}
+#endif
+
+/*
+ * Sign aware variation of the above. On some architectures a
+ * negative dividend leads to an divide overflow exception, which
+ * is avoided by the sign check.
+ */
+static inline long div_long_long_rem_signed(const long long dividend,
+					    const long divisor, long *remainder)
+{
+	long res;
+
+	if (unlikely(dividend < 0)) {
+		res = -div_long_long_rem(-dividend, divisor, remainder);
+		*remainder = -(*remainder);
+	} else
+		res = div_long_long_rem(dividend, divisor, remainder);
+
+	return res;
+}
+
+#endif
diff --git a/include/linux/capability.h b/include/linux/capability.h
index 6b46189..5a23ce7 100644
--- a/include/linux/capability.h
+++ b/include/linux/capability.h
@@ -43,6 +43,7 @@
 #ifdef __KERNEL__
 
 #include <linux/spinlock.h>
+#include <asm/current.h>
 
 /* #define STRICT_CAP_T_TYPECHECKS */
 
@@ -356,6 +357,8 @@
 
 #define cap_is_fs_cap(c)     (CAP_TO_MASK(c) & CAP_FS_MASK)
 
+extern int capable(int cap);
+
 #endif /* __KERNEL__ */
 
 #endif /* !_LINUX_CAPABILITY_H */
diff --git a/include/linux/compat_ioctl.h b/include/linux/compat_ioctl.h
index 3398789..8fad50f 100644
--- a/include/linux/compat_ioctl.h
+++ b/include/linux/compat_ioctl.h
@@ -2,14 +2,6 @@
  * compatible types passed or none at all... Please include
  * only stuff that is compatible on *all architectures*.
  */
-#ifndef COMPATIBLE_IOCTL /* pointer to compatible structure or no argument */
-#define COMPATIBLE_IOCTL(cmd)  HANDLE_IOCTL((cmd),(ioctl_trans_handler_t)sys_ioctl)
-#endif
-
-#ifndef ULONG_IOCTL /* argument is an unsigned long integer, not a pointer */
-#define ULONG_IOCTL(cmd)  HANDLE_IOCTL((cmd),(ioctl_trans_handler_t)sys_ioctl)
-#endif
-
 
 COMPATIBLE_IOCTL(0x4B50)   /* KDGHWCLK - not in the kernel, but don't complain */
 COMPATIBLE_IOCTL(0x4B51)   /* KDSHWCLK - not in the kernel, but don't complain */
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 2e05e1e..6e1c44a 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -11,9 +11,15 @@
 
 /* This macro obfuscates arithmetic on a variable address so that gcc
    shouldn't recognize the original var, and make assumptions about it */
+/*
+ * Versions of the ppc64 compiler before 4.1 had a bug where use of
+ * RELOC_HIDE could trash r30. The bug can be worked around by changing
+ * the inline assembly constraint from =g to =r, in this particular
+ * case either is valid.
+ */
 #define RELOC_HIDE(ptr, off)					\
   ({ unsigned long __ptr;					\
-    __asm__ ("" : "=g"(__ptr) : "0"(ptr));		\
+    __asm__ ("" : "=r"(__ptr) : "0"(ptr));		\
     (typeof(ptr)) (__ptr + (off)); })
 
 
diff --git a/include/linux/dmi.h b/include/linux/dmi.h
index 05f4132..2e6bbe0 100644
--- a/include/linux/dmi.h
+++ b/include/linux/dmi.h
@@ -2,6 +2,7 @@
 #define __DMI_H__
 
 #include <linux/list.h>
+#include <linux/config.h>
 
 enum dmi_field {
 	DMI_NONE,
@@ -60,12 +61,14 @@
 	void *device_data;	/* Type specific data */
 };
 
-#if defined(CONFIG_X86_32)
+#ifdef CONFIG_DMI
 
 extern int dmi_check_system(struct dmi_system_id *list);
 extern char * dmi_get_system_info(int field);
 extern struct dmi_device * dmi_find_device(int type, const char *name,
 	struct dmi_device *from);
+extern void dmi_scan_machine(void);
+
 #else
 
 static inline int dmi_check_system(struct dmi_system_id *list) { return 0; }
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 92ae3e2..d1e370d 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -114,8 +114,7 @@
 /*
  * Superblock flags that can be altered by MS_REMOUNT
  */
-#define MS_RMT_MASK	(MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_NOATIME|\
-			 MS_NODIRATIME)
+#define MS_RMT_MASK	(MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK)
 
 /*
  * Old magic mount flag and mask
@@ -161,8 +160,6 @@
 #define IS_NOQUOTA(inode)	((inode)->i_flags & S_NOQUOTA)
 #define IS_APPEND(inode)	((inode)->i_flags & S_APPEND)
 #define IS_IMMUTABLE(inode)	((inode)->i_flags & S_IMMUTABLE)
-#define IS_NOATIME(inode)	(__IS_FLG(inode, MS_NOATIME) || ((inode)->i_flags & S_NOATIME))
-#define IS_NODIRATIME(inode)	__IS_FLG(inode, MS_NODIRATIME)
 #define IS_POSIXACL(inode)	__IS_FLG(inode, MS_POSIXACL)
 
 #define IS_DEADDIR(inode)	((inode)->i_flags & S_DEAD)
@@ -235,9 +232,6 @@
 struct vm_area_struct;
 struct vfsmount;
 
-/* Used to be a macro which just called the function, now just a function */
-extern void update_atime (struct inode *);
-
 extern void __init inode_init(unsigned long);
 extern void __init inode_init_early(void);
 extern void __init mnt_init(unsigned long);
@@ -1118,12 +1112,7 @@
 	__mark_inode_dirty(inode, I_DIRTY_SYNC);
 }
 
-static inline void touch_atime(struct vfsmount *mnt, struct dentry *dentry)
-{
-	/* per-mountpoint checks will go here */
-	update_atime(dentry->d_inode);
-}
-
+extern void touch_atime(struct vfsmount *mnt, struct dentry *dentry);
 static inline void file_accessed(struct file *file)
 {
 	if (!(file->f_flags & O_NOATIME))
@@ -1716,7 +1705,7 @@
 extern int inode_change_ok(struct inode *, struct iattr *);
 extern int __must_check inode_setattr(struct inode *, struct iattr *);
 
-extern void inode_update_time(struct inode *inode, int ctime_too);
+extern void file_update_time(struct file *file);
 
 static inline ino_t parent_ino(struct dentry *dentry)
 {
diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index 8b2eab9..20f9148 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -57,6 +57,7 @@
 			__GFP_NOFAIL|__GFP_NORETRY|__GFP_NO_GROW|__GFP_COMP| \
 			__GFP_NOMEMALLOC|__GFP_HARDWALL)
 
+/* GFP_ATOMIC means both !wait (__GFP_WAIT not set) and use emergency pool */
 #define GFP_ATOMIC	(__GFP_HIGH)
 #define GFP_NOIO	(__GFP_WAIT)
 #define GFP_NOFS	(__GFP_WAIT | __GFP_IO)
@@ -109,6 +110,10 @@
 	if (unlikely(order >= MAX_ORDER))
 		return NULL;
 
+	/* Unknown node is current node */
+	if (nid < 0)
+		nid = numa_node_id();
+
 	return __alloc_pages(gfp_mask, order,
 		NODE_DATA(nid)->node_zonelists + gfp_zone(gfp_mask));
 }
diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
new file mode 100644
index 0000000..089bfb1
--- /dev/null
+++ b/include/linux/hrtimer.h
@@ -0,0 +1,139 @@
+/*
+ *  include/linux/hrtimer.h
+ *
+ *  hrtimers - High-resolution kernel timers
+ *
+ *   Copyright(C) 2005, Thomas Gleixner <tglx@linutronix.de>
+ *   Copyright(C) 2005, Red Hat, Inc., Ingo Molnar
+ *
+ *  data type definitions, declarations, prototypes
+ *
+ *  Started by: Thomas Gleixner and Ingo Molnar
+ *
+ *  For licencing details see kernel-base/COPYING
+ */
+#ifndef _LINUX_HRTIMER_H
+#define _LINUX_HRTIMER_H
+
+#include <linux/rbtree.h>
+#include <linux/ktime.h>
+#include <linux/init.h>
+#include <linux/list.h>
+#include <linux/wait.h>
+
+/*
+ * Mode arguments of xxx_hrtimer functions:
+ */
+enum hrtimer_mode {
+	HRTIMER_ABS,	/* Time value is absolute */
+	HRTIMER_REL,	/* Time value is relative to now */
+};
+
+enum hrtimer_restart {
+	HRTIMER_NORESTART,
+	HRTIMER_RESTART,
+};
+
+/*
+ * Timer states:
+ */
+enum hrtimer_state {
+	HRTIMER_INACTIVE,	/* Timer is inactive */
+	HRTIMER_EXPIRED,		/* Timer is expired */
+	HRTIMER_PENDING,		/* Timer is pending */
+};
+
+struct hrtimer_base;
+
+/**
+ * struct hrtimer - the basic hrtimer structure
+ *
+ * @node:	red black tree node for time ordered insertion
+ * @expires:	the absolute expiry time in the hrtimers internal
+ *		representation. The time is related to the clock on
+ *		which the timer is based.
+ * @state:	state of the timer
+ * @function:	timer expiry callback function
+ * @data:	argument for the callback function
+ * @base:	pointer to the timer base (per cpu and per clock)
+ *
+ * The hrtimer structure must be initialized by init_hrtimer_#CLOCKTYPE()
+ */
+struct hrtimer {
+	struct rb_node		node;
+	ktime_t			expires;
+	enum hrtimer_state	state;
+	int			(*function)(void *);
+	void			*data;
+	struct hrtimer_base	*base;
+};
+
+/**
+ * struct hrtimer_base - the timer base for a specific clock
+ *
+ * @index:	clock type index for per_cpu support when moving a timer
+ *		to a base on another cpu.
+ * @lock:	lock protecting the base and associated timers
+ * @active:	red black tree root node for the active timers
+ * @first:	pointer to the timer node which expires first
+ * @resolution:	the resolution of the clock, in nanoseconds
+ * @get_time:	function to retrieve the current time of the clock
+ * @curr_timer:	the timer which is executing a callback right now
+ */
+struct hrtimer_base {
+	clockid_t		index;
+	spinlock_t		lock;
+	struct rb_root		active;
+	struct rb_node		*first;
+	ktime_t			resolution;
+	ktime_t			(*get_time)(void);
+	struct hrtimer		*curr_timer;
+};
+
+/*
+ * clock_was_set() is a NOP for non- high-resolution systems. The
+ * time-sorted order guarantees that a timer does not expire early and
+ * is expired in the next softirq when the clock was advanced.
+ */
+#define clock_was_set()		do { } while (0)
+
+/* Exported timer functions: */
+
+/* Initialize timers: */
+extern void hrtimer_init(struct hrtimer *timer, const clockid_t which_clock);
+extern void hrtimer_rebase(struct hrtimer *timer, const clockid_t which_clock);
+
+
+/* Basic timer operations: */
+extern int hrtimer_start(struct hrtimer *timer, ktime_t tim,
+			 const enum hrtimer_mode mode);
+extern int hrtimer_cancel(struct hrtimer *timer);
+extern int hrtimer_try_to_cancel(struct hrtimer *timer);
+
+#define hrtimer_restart(timer) hrtimer_start((timer), (timer)->expires, HRTIMER_ABS)
+
+/* Query timers: */
+extern ktime_t hrtimer_get_remaining(const struct hrtimer *timer);
+extern int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp);
+
+static inline int hrtimer_active(const struct hrtimer *timer)
+{
+	return timer->state == HRTIMER_PENDING;
+}
+
+/* Forward a hrtimer so it expires after now: */
+extern unsigned long hrtimer_forward(struct hrtimer *timer, ktime_t interval);
+
+/* Precise sleep: */
+extern long hrtimer_nanosleep(struct timespec *rqtp,
+			      struct timespec __user *rmtp,
+			      const enum hrtimer_mode mode,
+			      const clockid_t clockid);
+
+/* Soft interrupt function to run the hrtimer queues: */
+extern void hrtimer_run_queues(void);
+
+/* Bootup initialization: */
+extern void __init hrtimers_init(void);
+
+#endif
diff --git a/include/linux/ide.h b/include/linux/ide.h
index 9a8c05d..f2e1b5b 100644
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -1002,7 +1002,6 @@
 
 extern int ide_end_request (ide_drive_t *drive, int uptodate, int nrsecs);
 extern int __ide_end_request (ide_drive_t *drive, struct request *rq, int uptodate, int nrsecs);
-extern void ide_softirq_done(struct request *rq);
 
 /*
  * This is used on exit from the driver to designate the next irq handler
diff --git a/include/linux/isicom.h b/include/linux/isicom.h
index 7c6eae7..45b3d48 100644
--- a/include/linux/isicom.h
+++ b/include/linux/isicom.h
@@ -4,47 +4,12 @@
 /*#define		ISICOM_DEBUG*/
 /*#define		ISICOM_DEBUG_DTR_RTS*/
 
-
-/*
- *	Firmware Loader definitions ...
- */
- 
-#define		__MultiTech		('M'<<8)
-#define		MIOCTL_LOAD_FIRMWARE	(__MultiTech | 0x01)
-#define         MIOCTL_READ_FIRMWARE    (__MultiTech | 0x02)
-#define         MIOCTL_XFER_CTRL	(__MultiTech | 0x03)
-#define         MIOCTL_RESET_CARD	(__MultiTech | 0x04)
-
-#define		DATA_SIZE	16
-
-typedef	struct	{
-		unsigned short	exec_segment;
-		unsigned short	exec_addr;
-}	exec_record;
-
-typedef	struct	{
-		int		board;		/* Board to load */
-		unsigned short	addr;
-		unsigned short	count;
-}	bin_header;
-
-typedef	struct	{
-		int		board;		/* Board to load */
-		unsigned short	addr;
-		unsigned short	count;
-		unsigned short	segment;
-		unsigned char	bin_data[DATA_SIZE];
-}	bin_frame;
-
 #ifdef __KERNEL__
 
 #define		YES	1
 #define		NO	0
 
-#define		ISILOAD_MISC_MINOR	155	/* /dev/isctl */
-#define		ISILOAD_NAME		"ISILoad"
-
-/*	
+/*
  *  ISICOM Driver definitions ...
  *
  */
@@ -55,8 +20,8 @@
  *      PCI definitions
  */
 
- #define        DEVID_COUNT     9
- #define        VENDOR_ID       0x10b5
+#define		DEVID_COUNT	9
+#define		VENDOR_ID	0x10b5
 
 /*
  *	These are now officially allocated numbers
@@ -66,9 +31,9 @@
 #define		ISICOM_CMAJOR	113	/* callout */
 #define		ISICOM_MAGIC	(('M' << 8) | 'T')
 
-#define		WAKEUP_CHARS	256	/* hard coded for now	*/ 
-#define		TX_SIZE		254 
- 
+#define		WAKEUP_CHARS	256	/* hard coded for now	*/
+#define		TX_SIZE		254
+
 #define		BOARD_COUNT	4
 #define		PORT_COUNT	(BOARD_COUNT*16)
 
@@ -98,18 +63,15 @@
 #define		ISICOM_INITIATE_XONXOFF	0x04
 #define		ISICOM_RESPOND_XONXOFF	0x08
 
-#define InterruptTheCard(base) (outw(0,(base)+0xc)) 
-#define ClearInterrupt(base) (inw((base)+0x0a))	
-
 #define	BOARD(line)  (((line) >> 4) & 0x3)
 
 	/*	isi kill queue bitmap	*/
-	
+
 #define		ISICOM_KILLTX		0x01
 #define		ISICOM_KILLRX		0x02
 
 	/* isi_board status bitmap */
-	
+
 #define		FIRMWARE_LOADED		0x0001
 #define		BOARD_ACTIVE		0x0002
 
@@ -123,9 +85,8 @@
 #define		ISI_RTS			0x0200
 
 
-#define		ISI_TXOK		0x0001 
- 
+#define		ISI_TXOK		0x0001
+
 #endif	/*	__KERNEL__	*/
 
 #endif	/*	ISICOM_H	*/
-
diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
index 6acfdbb..99905e1 100644
--- a/include/linux/jiffies.h
+++ b/include/linux/jiffies.h
@@ -1,21 +1,12 @@
 #ifndef _LINUX_JIFFIES_H
 #define _LINUX_JIFFIES_H
 
+#include <linux/calc64.h>
 #include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/time.h>
 #include <linux/timex.h>
 #include <asm/param.h>			/* for HZ */
-#include <asm/div64.h>
-
-#ifndef div_long_long_rem
-#define div_long_long_rem(dividend,divisor,remainder) \
-({							\
-	u64 result = dividend;				\
-	*remainder = do_div(result,divisor);		\
-	result;						\
-})
-#endif
 
 /*
  * The following defines establish the engineering parameters of the PLL
@@ -373,8 +364,11 @@
 	 * one divide.
 	 */
 	u64 nsec = (u64)jiffies * TICK_NSEC;
-	value->tv_sec = div_long_long_rem(nsec, NSEC_PER_SEC, &value->tv_usec);
-	value->tv_usec /= NSEC_PER_USEC;
+	long tv_usec;
+
+	value->tv_sec = div_long_long_rem(nsec, NSEC_PER_SEC, &tv_usec);
+	tv_usec /= NSEC_PER_USEC;
+	value->tv_usec = tv_usec;
 }
 
 /*
diff --git a/include/linux/kbd_kern.h b/include/linux/kbd_kern.h
index 7428198..45f625d 100644
--- a/include/linux/kbd_kern.h
+++ b/include/linux/kbd_kern.h
@@ -151,7 +151,7 @@
 
 static inline void con_schedule_flip(struct tty_struct *t)
 {
-	schedule_work(&t->flip.work);
+	schedule_work(&t->buf.work);
 }
 
 #endif
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index d0e6ca3..e6ee2d9 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -47,6 +47,8 @@
 #define default_console_loglevel (console_printk[3])
 
 struct completion;
+struct pt_regs;
+struct user;
 
 /**
  * might_sleep - annotation for functions that can sleep
@@ -123,6 +125,8 @@
 extern int kernel_text_address(unsigned long addr);
 extern int session_of_pgrp(int pgrp);
 
+extern void dump_thread(struct pt_regs *regs, struct user *dump);
+
 #ifdef CONFIG_PRINTK
 asmlinkage int vprintk(const char *fmt, va_list args)
 	__attribute__ ((format (printf, 1, 0)));
diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index c846847..94abc07 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -41,7 +41,7 @@
 #define IND_DONE         0x4
 #define IND_SOURCE       0x8
 
-#define KEXEC_SEGMENT_MAX 8
+#define KEXEC_SEGMENT_MAX 16
 struct kexec_segment {
 	void __user *buf;
 	size_t bufsz;
@@ -125,6 +125,8 @@
 /* Location of a reserved region to hold the crash kernel.
  */
 extern struct resource crashk_res;
+typedef u32 note_buf_t[MAX_NOTE_BYTES/4];
+extern note_buf_t *crash_notes;
 
 #else /* !CONFIG_KEXEC */
 struct pt_regs;
diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
index c03f2dc..669756b 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -68,6 +68,9 @@
 	/* list of kprobes for multi-handler support */
 	struct list_head list;
 
+	/* Indicates that the corresponding module has been ref counted */
+	unsigned int mod_refcounted;
+
 	/*count the number of times this probe was temporarily disarmed */
 	unsigned long nmissed;
 
@@ -149,11 +152,10 @@
 };
 
 extern spinlock_t kretprobe_lock;
+extern struct semaphore kprobe_mutex;
 extern int arch_prepare_kprobe(struct kprobe *p);
-extern void arch_copy_kprobe(struct kprobe *p);
 extern void arch_arm_kprobe(struct kprobe *p);
 extern void arch_disarm_kprobe(struct kprobe *p);
-extern void arch_remove_kprobe(struct kprobe *p);
 extern int arch_init_kprobes(void);
 extern void show_registers(struct pt_regs *regs);
 extern kprobe_opcode_t *get_insn_slot(void);
diff --git a/include/linux/ktime.h b/include/linux/ktime.h
new file mode 100644
index 0000000..1bd6552
--- /dev/null
+++ b/include/linux/ktime.h
@@ -0,0 +1,284 @@
+/*
+ *  include/linux/ktime.h
+ *
+ *  ktime_t - nanosecond-resolution time format.
+ *
+ *   Copyright(C) 2005, Thomas Gleixner <tglx@linutronix.de>
+ *   Copyright(C) 2005, Red Hat, Inc., Ingo Molnar
+ *
+ *  data type definitions, declarations, prototypes and macros.
+ *
+ *  Started by: Thomas Gleixner and Ingo Molnar
+ *
+ *  For licencing details see kernel-base/COPYING
+ */
+#ifndef _LINUX_KTIME_H
+#define _LINUX_KTIME_H
+
+#include <linux/time.h>
+#include <linux/jiffies.h>
+
+/*
+ * ktime_t:
+ *
+ * On 64-bit CPUs a single 64-bit variable is used to store the hrtimers
+ * internal representation of time values in scalar nanoseconds. The
+ * design plays out best on 64-bit CPUs, where most conversions are
+ * NOPs and most arithmetic ktime_t operations are plain arithmetic
+ * operations.
+ *
+ * On 32-bit CPUs an optimized representation of the timespec structure
+ * is used to avoid expensive conversions from and to timespecs. The
+ * endian-aware order of the tv struct members is choosen to allow
+ * mathematical operations on the tv64 member of the union too, which
+ * for certain operations produces better code.
+ *
+ * For architectures with efficient support for 64/32-bit conversions the
+ * plain scalar nanosecond based representation can be selected by the
+ * config switch CONFIG_KTIME_SCALAR.
+ */
+typedef union {
+	s64	tv64;
+#if BITS_PER_LONG != 64 && !defined(CONFIG_KTIME_SCALAR)
+	struct {
+# ifdef __BIG_ENDIAN
+	s32	sec, nsec;
+# else
+	s32	nsec, sec;
+# endif
+	} tv;
+#endif
+} ktime_t;
+
+#define KTIME_MAX			(~((u64)1 << 63))
+
+/*
+ * ktime_t definitions when using the 64-bit scalar representation:
+ */
+
+#if (BITS_PER_LONG == 64) || defined(CONFIG_KTIME_SCALAR)
+
+/* Define a ktime_t variable and initialize it to zero: */
+#define DEFINE_KTIME(kt)		ktime_t kt = { .tv64 = 0 }
+
+/**
+ * ktime_set - Set a ktime_t variable from a seconds/nanoseconds value
+ *
+ * @secs:	seconds to set
+ * @nsecs:	nanoseconds to set
+ *
+ * Return the ktime_t representation of the value
+ */
+static inline ktime_t ktime_set(const long secs, const unsigned long nsecs)
+{
+	return (ktime_t) { .tv64 = (s64)secs * NSEC_PER_SEC + (s64)nsecs };
+}
+
+/* Subtract two ktime_t variables. rem = lhs -rhs: */
+#define ktime_sub(lhs, rhs) \
+		({ (ktime_t){ .tv64 = (lhs).tv64 - (rhs).tv64 }; })
+
+/* Add two ktime_t variables. res = lhs + rhs: */
+#define ktime_add(lhs, rhs) \
+		({ (ktime_t){ .tv64 = (lhs).tv64 + (rhs).tv64 }; })
+
+/*
+ * Add a ktime_t variable and a scalar nanosecond value.
+ * res = kt + nsval:
+ */
+#define ktime_add_ns(kt, nsval) \
+		({ (ktime_t){ .tv64 = (kt).tv64 + (nsval) }; })
+
+/* convert a timespec to ktime_t format: */
+#define timespec_to_ktime(ts)		ktime_set((ts).tv_sec, (ts).tv_nsec)
+
+/* convert a timeval to ktime_t format: */
+#define timeval_to_ktime(tv)		ktime_set((tv).tv_sec, (tv).tv_usec * 1000)
+
+/* Map the ktime_t to timespec conversion to ns_to_timespec function */
+#define ktime_to_timespec(kt)		ns_to_timespec((kt).tv64)
+
+/* Map the ktime_t to timeval conversion to ns_to_timeval function */
+#define ktime_to_timeval(kt)		ns_to_timeval((kt).tv64)
+
+/* Map the ktime_t to clock_t conversion to the inline in jiffies.h: */
+#define ktime_to_clock_t(kt)		nsec_to_clock_t((kt).tv64)
+
+/* Convert ktime_t to nanoseconds - NOP in the scalar storage format: */
+#define ktime_to_ns(kt)			((kt).tv64)
+
+#else
+
+/*
+ * Helper macros/inlines to get the ktime_t math right in the timespec
+ * representation. The macros are sometimes ugly - their actual use is
+ * pretty okay-ish, given the circumstances. We do all this for
+ * performance reasons. The pure scalar nsec_t based code was nice and
+ * simple, but created too many 64-bit / 32-bit conversions and divisions.
+ *
+ * Be especially aware that negative values are represented in a way
+ * that the tv.sec field is negative and the tv.nsec field is greater
+ * or equal to zero but less than nanoseconds per second. This is the
+ * same representation which is used by timespecs.
+ *
+ *   tv.sec < 0 and 0 >= tv.nsec < NSEC_PER_SEC
+ */
+
+/* Define a ktime_t variable and initialize it to zero: */
+#define DEFINE_KTIME(kt)		ktime_t kt = { .tv64 = 0 }
+
+/* Set a ktime_t variable to a value in sec/nsec representation: */
+static inline ktime_t ktime_set(const long secs, const unsigned long nsecs)
+{
+	return (ktime_t) { .tv = { .sec = secs, .nsec = nsecs } };
+}
+
+/**
+ * ktime_sub - subtract two ktime_t variables
+ *
+ * @lhs:	minuend
+ * @rhs:	subtrahend
+ *
+ * Returns the remainder of the substraction
+ */
+static inline ktime_t ktime_sub(const ktime_t lhs, const ktime_t rhs)
+{
+	ktime_t res;
+
+	res.tv64 = lhs.tv64 - rhs.tv64;
+	if (res.tv.nsec < 0)
+		res.tv.nsec += NSEC_PER_SEC;
+
+	return res;
+}
+
+/**
+ * ktime_add - add two ktime_t variables
+ *
+ * @add1:	addend1
+ * @add2:	addend2
+ *
+ * Returns the sum of addend1 and addend2
+ */
+static inline ktime_t ktime_add(const ktime_t add1, const ktime_t add2)
+{
+	ktime_t res;
+
+	res.tv64 = add1.tv64 + add2.tv64;
+	/*
+	 * performance trick: the (u32) -NSEC gives 0x00000000Fxxxxxxx
+	 * so we subtract NSEC_PER_SEC and add 1 to the upper 32 bit.
+	 *
+	 * it's equivalent to:
+	 *   tv.nsec -= NSEC_PER_SEC
+	 *   tv.sec ++;
+	 */
+	if (res.tv.nsec >= NSEC_PER_SEC)
+		res.tv64 += (u32)-NSEC_PER_SEC;
+
+	return res;
+}
+
+/**
+ * ktime_add_ns - Add a scalar nanoseconds value to a ktime_t variable
+ *
+ * @kt:		addend
+ * @nsec:	the scalar nsec value to add
+ *
+ * Returns the sum of kt and nsec in ktime_t format
+ */
+extern ktime_t ktime_add_ns(const ktime_t kt, u64 nsec);
+
+/**
+ * timespec_to_ktime - convert a timespec to ktime_t format
+ *
+ * @ts:		the timespec variable to convert
+ *
+ * Returns a ktime_t variable with the converted timespec value
+ */
+static inline ktime_t timespec_to_ktime(const struct timespec ts)
+{
+	return (ktime_t) { .tv = { .sec = (s32)ts.tv_sec,
+			   	   .nsec = (s32)ts.tv_nsec } };
+}
+
+/**
+ * timeval_to_ktime - convert a timeval to ktime_t format
+ *
+ * @tv:		the timeval variable to convert
+ *
+ * Returns a ktime_t variable with the converted timeval value
+ */
+static inline ktime_t timeval_to_ktime(const struct timeval tv)
+{
+	return (ktime_t) { .tv = { .sec = (s32)tv.tv_sec,
+				   .nsec = (s32)tv.tv_usec * 1000 } };
+}
+
+/**
+ * ktime_to_timespec - convert a ktime_t variable to timespec format
+ *
+ * @kt:		the ktime_t variable to convert
+ *
+ * Returns the timespec representation of the ktime value
+ */
+static inline struct timespec ktime_to_timespec(const ktime_t kt)
+{
+	return (struct timespec) { .tv_sec = (time_t) kt.tv.sec,
+				   .tv_nsec = (long) kt.tv.nsec };
+}
+
+/**
+ * ktime_to_timeval - convert a ktime_t variable to timeval format
+ *
+ * @kt:		the ktime_t variable to convert
+ *
+ * Returns the timeval representation of the ktime value
+ */
+static inline struct timeval ktime_to_timeval(const ktime_t kt)
+{
+	return (struct timeval) {
+		.tv_sec = (time_t) kt.tv.sec,
+		.tv_usec = (suseconds_t) (kt.tv.nsec / NSEC_PER_USEC) };
+}
+
+/**
+ * ktime_to_clock_t - convert a ktime_t variable to clock_t format
+ * @kt:		the ktime_t variable to convert
+ *
+ * Returns a clock_t variable with the converted value
+ */
+static inline clock_t ktime_to_clock_t(const ktime_t kt)
+{
+	return nsec_to_clock_t( (u64) kt.tv.sec * NSEC_PER_SEC + kt.tv.nsec);
+}
+
+/**
+ * ktime_to_ns - convert a ktime_t variable to scalar nanoseconds
+ * @kt:		the ktime_t variable to convert
+ *
+ * Returns the scalar nanoseconds representation of kt
+ */
+static inline u64 ktime_to_ns(const ktime_t kt)
+{
+	return (u64) kt.tv.sec * NSEC_PER_SEC + kt.tv.nsec;
+}
+
+#endif
+
+/*
+ * The resolution of the clocks. The resolution value is returned in
+ * the clock_getres() system call to give application programmers an
+ * idea of the (in)accuracy of timers. Timer values are rounded up to
+ * this resolution values.
+ */
+#define KTIME_REALTIME_RES	(ktime_t){ .tv64 = TICK_NSEC }
+#define KTIME_MONOTONIC_RES	(ktime_t){ .tv64 = TICK_NSEC }
+
+/* Get the monotonic time in timespec format: */
+extern void ktime_get_ts(struct timespec *ts);
+
+/* Get the real (wall-) time in timespec format: */
+#define ktime_get_real_ts(ts)	getnstimeofday(ts)
+
+#endif
diff --git a/include/linux/list.h b/include/linux/list.h
index 8e33882..945daa1 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -436,6 +436,20 @@
 	     pos = n, n = list_entry(n->member.next, typeof(*n), member))
 
 /**
+ * list_for_each_entry_safe_reverse - iterate backwards over list of given type safe against
+ *				      removal of list entry
+ * @pos:	the type * to use as a loop counter.
+ * @n:		another type * to use as temporary storage
+ * @head:	the head for your list.
+ * @member:	the name of the list_struct within the struct.
+ */
+#define list_for_each_entry_safe_reverse(pos, n, head, member)		\
+	for (pos = list_entry((head)->prev, typeof(*pos), member),	\
+		n = list_entry(pos->member.prev, typeof(*pos), member);	\
+	     &pos->member != (head); 					\
+	     pos = n, n = list_entry(n->member.prev, typeof(*n), member))
+
+/**
  * list_for_each_rcu	-	iterate over an rcu-protected list
  * @pos:	the &struct list_head to use as a loop counter.
  * @head:	the head for your list.
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 3f1fafc..c643016 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -3,6 +3,7 @@
 
 #include <linux/sched.h>
 #include <linux/errno.h>
+#include <linux/capability.h>
 
 #ifdef __KERNEL__
 
@@ -1027,7 +1028,7 @@
 {
 	if (!PageHighMem(page) && !enable)
 		mutex_debug_check_no_locks_freed(page_address(page),
-						 page_address(page + numpages));
+						 numpages * PAGE_SIZE);
 }
 #endif
 
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 7e4ae6a..34cbefd 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -98,7 +98,7 @@
 
 /*
  * On machines where it is needed (eg PCs) we divide physical memory
- * into multiple physical zones. On a PC we have 4 zones:
+ * into multiple physical zones. On a 32bit PC we have 4 zones:
  *
  * ZONE_DMA	  < 16 MB	ISA DMA capable memory
  * ZONE_DMA32	     0 MB 	Empty
diff --git a/include/linux/mount.h b/include/linux/mount.h
index b98a709..b7472ae 100644
--- a/include/linux/mount.h
+++ b/include/linux/mount.h
@@ -20,10 +20,12 @@
 #define MNT_NOSUID	0x01
 #define MNT_NODEV	0x02
 #define MNT_NOEXEC	0x04
-#define MNT_SHARED	0x10	/* if the vfsmount is a shared mount */
-#define MNT_UNBINDABLE	0x20	/* if the vfsmount is a unbindable mount */
+#define MNT_NOATIME	0x08
+#define MNT_NODIRATIME	0x10
 
-#define MNT_PNODE_MASK	(MNT_SHARED | MNT_UNBINDABLE)
+#define MNT_SHARED	0x1000	/* if the vfsmount is a shared mount */
+#define MNT_UNBINDABLE	0x2000	/* if the vfsmount is a unbindable mount */
+#define MNT_PNODE_MASK	0x3000	/* propogation flag mask */
 
 struct vfsmount {
 	struct list_head mnt_hash;
diff --git a/include/linux/mutex-debug.h b/include/linux/mutex-debug.h
index 0ccd8f9..8b5769f 100644
--- a/include/linux/mutex-debug.h
+++ b/include/linux/mutex-debug.h
@@ -1,6 +1,8 @@
 #ifndef __LINUX_MUTEX_DEBUG_H
 #define __LINUX_MUTEX_DEBUG_H
 
+#include <linux/linkage.h>
+
 /*
  * Mutexes - debugging helpers:
  */
@@ -16,6 +18,6 @@
 extern void mutex_debug_show_all_locks(void);
 extern void mutex_debug_show_held_locks(struct task_struct *filter);
 extern void mutex_debug_check_no_locks_held(struct task_struct *task);
-extern void mutex_debug_check_no_locks_freed(const void *from, const void *to);
+extern void mutex_debug_check_no_locks_freed(const void *from, unsigned long len);
 
 #endif
diff --git a/include/linux/mutex.h b/include/linux/mutex.h
index 9bce0fe..f1ac507 100644
--- a/include/linux/mutex.h
+++ b/include/linux/mutex.h
@@ -12,6 +12,7 @@
 
 #include <linux/list.h>
 #include <linux/spinlock_types.h>
+#include <linux/linkage.h>
 
 #include <asm/atomic.h>
 
@@ -78,7 +79,7 @@
 # define mutex_debug_show_all_locks()			do { } while (0)
 # define mutex_debug_show_held_locks(p)			do { } while (0)
 # define mutex_debug_check_no_locks_held(task)		do { } while (0)
-# define mutex_debug_check_no_locks_freed(from, to)	do { } while (0)
+# define mutex_debug_check_no_locks_freed(from, len)	do { } while (0)
 #endif
 
 #define __MUTEX_INITIALIZER(lockname) \
diff --git a/include/linux/namei.h b/include/linux/namei.h
index 455660e..b699e42 100644
--- a/include/linux/namei.h
+++ b/include/linux/namei.h
@@ -74,7 +74,7 @@
 extern void release_open_intent(struct nameidata *);
 
 extern struct dentry * lookup_one_len(const char *, struct dentry *, int);
-extern struct dentry * lookup_hash(struct nameidata *);
+extern __deprecated_for_modules struct dentry * lookup_hash(struct nameidata *);
 
 extern int follow_down(struct vfsmount **, struct dentry **);
 extern int follow_up(struct vfsmount **, struct dentry **);
diff --git a/include/linux/netfilter_ipv4/ip_nat_protocol.h b/include/linux/netfilter_ipv4/ip_nat_protocol.h
index ef63aa9..612a436 100644
--- a/include/linux/netfilter_ipv4/ip_nat_protocol.h
+++ b/include/linux/netfilter_ipv4/ip_nat_protocol.h
@@ -42,13 +42,6 @@
 			    enum ip_nat_manip_type maniptype,
 			    const struct ip_conntrack *conntrack);
 
-	unsigned int (*print)(char *buffer,
-			      const struct ip_conntrack_tuple *match,
-			      const struct ip_conntrack_tuple *mask);
-
-	unsigned int (*print_range)(char *buffer,
-				    const struct ip_nat_range *range);
-
 	int (*range_to_nfattr)(struct sk_buff *skb,
 			       const struct ip_nat_range *range);
 
diff --git a/include/linux/netfilter_ipv6.h b/include/linux/netfilter_ipv6.h
index 53b2983..14f2bd0 100644
--- a/include/linux/netfilter_ipv6.h
+++ b/include/linux/netfilter_ipv6.h
@@ -72,7 +72,12 @@
 	NF_IP6_PRI_LAST = INT_MAX,
 };
 
+#ifdef CONFIG_NETFILTER
 extern int ipv6_netfilter_init(void);
 extern void ipv6_netfilter_fini(void);
+#else /* CONFIG_NETFILTER */
+static inline int ipv6_netfilter_init(void) { return 0; }
+static inline void ipv6_netfilter_fini(void) { return; }
+#endif /* CONFIG_NETFILTER */
 
 #endif /*__LINUX_IP6_NETFILTER_H*/
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index c3caa93..7fb397e 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -377,6 +377,7 @@
 #define PCI_DEVICE_ID_NS_87560_USB	0x0012
 #define PCI_DEVICE_ID_NS_83815		0x0020
 #define PCI_DEVICE_ID_NS_83820		0x0022
+#define PCI_DEVICE_ID_NS_CS5535_ISA	0x002b
 #define PCI_DEVICE_ID_NS_CS5535_IDE	0x002d
 #define PCI_DEVICE_ID_NS_CS5535_AUDIO	0x002e
 #define PCI_DEVICE_ID_NS_CS5535_USB	0x002f
@@ -500,6 +501,14 @@
 #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_DEVICE_ID_AMD_CS5536_ISA    0x2090
+#define PCI_DEVICE_ID_AMD_CS5536_FLASH  0x2091
+#define PCI_DEVICE_ID_AMD_CS5536_AUDIO  0x2093
+#define PCI_DEVICE_ID_AMD_CS5536_OHC    0x2094
+#define PCI_DEVICE_ID_AMD_CS5536_EHC    0x2095
+#define PCI_DEVICE_ID_AMD_CS5536_UDC    0x2096
+#define PCI_DEVICE_ID_AMD_CS5536_UOC    0x2097
+#define PCI_DEVICE_ID_AMD_CS5536_IDE    0x209A
 
 #define PCI_DEVICE_ID_AMD_CS5536_IDE	0x209A
 
@@ -1041,6 +1050,11 @@
 #define PCI_DEVICE_ID_NVIDIA_NVENET_6		0x00e6
 #define PCI_DEVICE_ID_NVIDIA_CK8S_AUDIO		0x00ea
 #define PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA2	0x00ee
+#define PCIE_DEVICE_ID_NVIDIA_GEFORCE_6800_ALT1 0x00f0
+#define PCIE_DEVICE_ID_NVIDIA_GEFORCE_6600_ALT1 0x00f1
+#define PCIE_DEVICE_ID_NVIDIA_GEFORCE_6600_ALT2 0x00f2
+#define PCIE_DEVICE_ID_NVIDIA_GEFORCE_6200_ALT1 0x00f3
+#define PCIE_DEVICE_ID_NVIDIA_GEFORCE_6800_GT   0x00f9
 #define PCI_DEVICE_ID_NVIDIA_GEFORCE_SDR	0x0100
 #define PCI_DEVICE_ID_NVIDIA_GEFORCE_DDR	0x0101
 #define PCI_DEVICE_ID_NVIDIA_QUADRO		0x0103
@@ -2138,6 +2152,9 @@
 #define PCI_DEVICE_ID_INTEL_IXP2800	0x9004
 #define PCI_DEVICE_ID_INTEL_S21152BB	0xb152
 
+#define PCI_VENDOR_ID_SCALEMP		0x8686
+#define PCI_DEVICE_ID_SCALEMP_VSMP_CTL	0x1010
+
 #define PCI_VENDOR_ID_COMPUTONE		0x8e0e
 #define PCI_DEVICE_ID_COMPUTONE_IP2EX	0x0291
 #define PCI_DEVICE_ID_COMPUTONE_PG	0x0302
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index f942e2b..54faf52 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -42,7 +42,7 @@
 	timer_t it_id;			/* timer id */
 	int it_overrun;			/* overrun on pending signal  */
 	int it_overrun_last;		/* overrun on last delivered signal */
-	int it_requeue_pending;         /* waiting to requeue this timer */
+	int it_requeue_pending;		/* waiting to requeue this timer */
 #define REQUEUE_PENDING 1
 	int it_sigev_notify;		/* notify word of sigevent struct */
 	int it_sigev_signo;		/* signo word of sigevent struct */
@@ -51,10 +51,8 @@
 	struct sigqueue *sigq;		/* signal queue entry. */
 	union {
 		struct {
-			struct timer_list timer;
-			struct list_head abs_timer_entry; /* clock abs_timer_list */
-			struct timespec wall_to_prev;   /* wall_to_monotonic used when set */
-			unsigned long incr; /* interval in jiffies */
+			struct hrtimer timer;
+			ktime_t interval;
 		} real;
 		struct cpu_timer_list cpu;
 		struct {
@@ -66,18 +64,14 @@
 	} it;
 };
 
-struct k_clock_abs {
-	struct list_head list;
-	spinlock_t lock;
-};
 struct k_clock {
-	int res;		/* in nano seconds */
-	int (*clock_getres) (clockid_t which_clock, struct timespec *tp);
-	struct k_clock_abs *abs_struct;
-	int (*clock_set) (clockid_t which_clock, struct timespec * tp);
-	int (*clock_get) (clockid_t which_clock, struct timespec * tp);
+	int res;		/* in nanoseconds */
+	int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
+	int (*clock_set) (const clockid_t which_clock, struct timespec * tp);
+	int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
 	int (*timer_create) (struct k_itimer *timer);
-	int (*nsleep) (clockid_t which_clock, int flags, struct timespec *);
+	int (*nsleep) (const clockid_t which_clock, int flags,
+		       struct timespec *, struct timespec __user *);
 	int (*timer_set) (struct k_itimer * timr, int flags,
 			  struct itimerspec * new_setting,
 			  struct itimerspec * old_setting);
@@ -87,53 +81,35 @@
 			   struct itimerspec * cur_setting);
 };
 
-void register_posix_clock(clockid_t clock_id, struct k_clock *new_clock);
+void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock);
 
-/* Error handlers for timer_create, nanosleep and settime */
+/* error handlers for timer_create, nanosleep and settime */
 int do_posix_clock_notimer_create(struct k_itimer *timer);
-int do_posix_clock_nonanosleep(clockid_t, int flags, struct timespec *);
-int do_posix_clock_nosettime(clockid_t, struct timespec *tp);
+int do_posix_clock_nonanosleep(const clockid_t, int flags, struct timespec *,
+			       struct timespec __user *);
+int do_posix_clock_nosettime(const clockid_t, struct timespec *tp);
 
 /* function to call to trigger timer event */
 int posix_timer_event(struct k_itimer *timr, int si_private);
 
-struct now_struct {
-	unsigned long jiffies;
-};
+int posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *ts);
+int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *ts);
+int posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *ts);
+int posix_cpu_timer_create(struct k_itimer *timer);
+int posix_cpu_nsleep(const clockid_t which_clock, int flags,
+		     struct timespec *rqtp, struct timespec __user *rmtp);
+int posix_cpu_timer_set(struct k_itimer *timer, int flags,
+			struct itimerspec *new, struct itimerspec *old);
+int posix_cpu_timer_del(struct k_itimer *timer);
+void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp);
 
-#define posix_get_now(now) (now)->jiffies = jiffies;
-#define posix_time_before(timer, now) \
-                      time_before((timer)->expires, (now)->jiffies)
+void posix_cpu_timer_schedule(struct k_itimer *timer);
 
-#define posix_bump_timer(timr, now)					\
-         do {								\
-              long delta, orun;						\
-	      delta = now.jiffies - (timr)->it.real.timer.expires;	\
-              if (delta >= 0) {						\
-	           orun = 1 + (delta / (timr)->it.real.incr);		\
-	          (timr)->it.real.timer.expires +=			\
-			 orun * (timr)->it.real.incr;			\
-                  (timr)->it_overrun += orun;				\
-              }								\
-            }while (0)
+void run_posix_cpu_timers(struct task_struct *task);
+void posix_cpu_timers_exit(struct task_struct *task);
+void posix_cpu_timers_exit_group(struct task_struct *task);
 
-int posix_cpu_clock_getres(clockid_t which_clock, struct timespec *);
-int posix_cpu_clock_get(clockid_t which_clock, struct timespec *);
-int posix_cpu_clock_set(clockid_t which_clock, const struct timespec *tp);
-int posix_cpu_timer_create(struct k_itimer *);
-int posix_cpu_nsleep(clockid_t, int, struct timespec *);
-int posix_cpu_timer_set(struct k_itimer *, int,
-			struct itimerspec *, struct itimerspec *);
-int posix_cpu_timer_del(struct k_itimer *);
-void posix_cpu_timer_get(struct k_itimer *, struct itimerspec *);
-
-void posix_cpu_timer_schedule(struct k_itimer *);
-
-void run_posix_cpu_timers(struct task_struct *);
-void posix_cpu_timers_exit(struct task_struct *);
-void posix_cpu_timers_exit_group(struct task_struct *);
-
-void set_process_cpu_timer(struct task_struct *, unsigned int,
-			   cputime_t *, cputime_t *);
+void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx,
+			   cputime_t *newval, cputime_t *oldval);
 
 #endif
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index a1d26cb..981f9aa 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -65,6 +65,10 @@
 	long	cur;		/* Current batch number.                      */
 	long	completed;	/* Number of the last completed batch         */
 	int	next_pending;	/* Is the next batch already waiting?         */
+
+	spinlock_t	lock	____cacheline_internodealigned_in_smp;
+	cpumask_t	cpumask; /* CPUs that need to switch in order    */
+	                         /* for current batch to proceed.        */
 } ____cacheline_internodealigned_in_smp;
 
 /* Is batch a before batch b ? */
diff --git a/include/linux/rio_drv.h b/include/linux/rio_drv.h
index 157d7e3..f54772d 100644
--- a/include/linux/rio_drv.h
+++ b/include/linux/rio_drv.h
@@ -337,8 +337,8 @@
 
 /**
  * RIO_DEVICE - macro used to describe a specific RIO device
- * @vid: the 16 bit RIO vendor ID
- * @did: the 16 bit RIO device ID
+ * @dev: the 16 bit RIO device ID
+ * @ven: the 16 bit RIO vendor ID
  *
  * This macro is used to create a struct rio_device_id that matches a
  * specific device.  The assembly vendor and assembly device fields
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 85b53f8..a72e171 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -105,6 +105,7 @@
 #include <linux/param.h>
 #include <linux/resource.h>
 #include <linux/timer.h>
+#include <linux/hrtimer.h>
 
 #include <asm/processor.h>
 
@@ -398,8 +399,8 @@
 	struct list_head posix_timers;
 
 	/* ITIMER_REAL timer for the process */
-	struct timer_list real_timer;
-	unsigned long it_real_value, it_real_incr;
+	struct hrtimer real_timer;
+	ktime_t it_real_incr;
 
 	/* ITIMER_PROF and ITIMER_VIRTUAL timers for the process */
 	cputime_t it_prof_expires, it_virt_expires;
@@ -630,7 +631,14 @@
 
 extern void partition_sched_domains(cpumask_t *partition1,
 				    cpumask_t *partition2);
-#endif /* CONFIG_SMP */
+
+/*
+ * Maximum cache size the migration-costs auto-tuning code will
+ * search from:
+ */
+extern unsigned int max_cache_size;
+
+#endif	/* CONFIG_SMP */
 
 
 struct io_context;			/* See blkdev.h */
@@ -688,9 +696,12 @@
 
 	int lock_depth;		/* BKL lock depth */
 
-#if defined(CONFIG_SMP) && defined(__ARCH_WANT_UNLOCKED_CTXSW)
+#if defined(CONFIG_SMP)
+	int last_waker_cpu;	/* CPU that last woke this task up */
+#if defined(__ARCH_WANT_UNLOCKED_CTXSW)
 	int oncpu;
 #endif
+#endif
 	int prio, static_prio;
 	struct list_head run_list;
 	prio_array_t *array;
@@ -1111,21 +1122,6 @@
 		: on_sig_stack(sp) ? SS_ONSTACK : 0);
 }
 
-
-#ifdef CONFIG_SECURITY
-/* code is in security.c */
-extern int capable(int cap);
-#else
-static inline int capable(int cap)
-{
-	if (cap_raised(current->cap_effective, cap)) {
-		current->flags |= PF_SUPERPRIV;
-		return 1;
-	}
-	return 0;
-}
-#endif
-
 /*
  * Routines for handling mm_structs
  */
@@ -1244,6 +1240,7 @@
 #ifndef __HAVE_THREAD_FUNCTIONS
 
 #define task_thread_info(task) (task)->thread_info
+#define task_stack_page(task) ((void*)((task)->thread_info))
 
 static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org)
 {
@@ -1389,12 +1386,8 @@
 extern long sched_setaffinity(pid_t pid, cpumask_t new_mask);
 extern long sched_getaffinity(pid_t pid, cpumask_t *mask);
 
-#ifdef CONFIG_MAGIC_SYSRQ
-
 extern void normalize_rt_tasks(void);
 
-#endif
-
 #ifdef CONFIG_PM
 /*
  * Check if a process has been frozen
diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
index 76850b7..6336987 100644
--- a/include/linux/screen_info.h
+++ b/include/linux/screen_info.h
@@ -41,8 +41,7 @@
 	u16 vesapm_off;		/* 0x30 */
 	u16 pages;		/* 0x32 */
 	u16 vesa_attributes;	/* 0x34 */
-	u32  capabilities;      /* 0x36 */
-				/* 0x3a -- 0x3f reserved for future expansion */
+				/* 0x36 -- 0x3f reserved for future expansion */
 };
 
 extern struct screen_info screen_info;
diff --git a/include/linux/time.h b/include/linux/time.h
index 797ccd8..f2aca7e 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -4,7 +4,7 @@
 #include <linux/types.h>
 
 #ifdef __KERNEL__
-#include <linux/seqlock.h>
+# include <linux/seqlock.h>
 #endif
 
 #ifndef _STRUCT_TIMESPEC
@@ -13,7 +13,7 @@
 	time_t	tv_sec;		/* seconds */
 	long	tv_nsec;	/* nanoseconds */
 };
-#endif /* _STRUCT_TIMESPEC */
+#endif
 
 struct timeval {
 	time_t		tv_sec;		/* seconds */
@@ -27,93 +27,103 @@
 
 #ifdef __KERNEL__
 
-/* Parameters used to convert the timespec values */
-#define MSEC_PER_SEC (1000L)
-#define USEC_PER_SEC (1000000L)
-#define NSEC_PER_SEC (1000000000L)
-#define NSEC_PER_USEC (1000L)
+/* Parameters used to convert the timespec values: */
+#define MSEC_PER_SEC		1000L
+#define USEC_PER_SEC		1000000L
+#define NSEC_PER_SEC		1000000000L
+#define NSEC_PER_USEC		1000L
 
-static __inline__ int timespec_equal(struct timespec *a, struct timespec *b) 
-{ 
-	return (a->tv_sec == b->tv_sec) && (a->tv_nsec == b->tv_nsec);
-} 
-
-/* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
- * Assumes input in normal date format, i.e. 1980-12-31 23:59:59
- * => year=1980, mon=12, day=31, hour=23, min=59, sec=59.
- *
- * [For the Julian calendar (which was used in Russia before 1917,
- * Britain & colonies before 1752, anywhere else before 1582,
- * and is still in use by some communities) leave out the
- * -year/100+year/400 terms, and add 10.]
- *
- * This algorithm was first published by Gauss (I think).
- *
- * WARNING: this function will overflow on 2106-02-07 06:28:16 on
- * machines were long is 32-bit! (However, as time_t is signed, we
- * will already get problems at other places on 2038-01-19 03:14:08)
- */
-static inline unsigned long
-mktime (unsigned int year, unsigned int mon,
-	unsigned int day, unsigned int hour,
-	unsigned int min, unsigned int sec)
+static __inline__ int timespec_equal(struct timespec *a, struct timespec *b)
 {
-	if (0 >= (int) (mon -= 2)) {	/* 1..12 -> 11,12,1..10 */
-		mon += 12;		/* Puts Feb last since it has leap day */
-		year -= 1;
-	}
-
-	return (((
-		(unsigned long) (year/4 - year/100 + year/400 + 367*mon/12 + day) +
-			year*365 - 719499
-	    )*24 + hour /* now have hours */
-	  )*60 + min /* now have minutes */
-	)*60 + sec; /* finally seconds */
+	return (a->tv_sec == b->tv_sec) && (a->tv_nsec == b->tv_nsec);
 }
 
+extern unsigned long mktime(const unsigned int year, const unsigned int mon,
+			    const unsigned int day, const unsigned int hour,
+			    const unsigned int min, const unsigned int sec);
+
+extern void set_normalized_timespec(struct timespec *ts, time_t sec, long nsec);
+
+/*
+ * Returns true if the timespec is norm, false if denorm:
+ */
+#define timespec_valid(ts) \
+	(((ts)->tv_sec >= 0) && (((unsigned) (ts)->tv_nsec) < NSEC_PER_SEC))
+
+/*
+ * 64-bit nanosec type. Large enough to span 292+ years in nanosecond
+ * resolution. Ought to be enough for a while.
+ */
+typedef s64 nsec_t;
+
 extern struct timespec xtime;
 extern struct timespec wall_to_monotonic;
 extern seqlock_t xtime_lock;
 
 static inline unsigned long get_seconds(void)
-{ 
+{
 	return xtime.tv_sec;
 }
 
 struct timespec current_kernel_time(void);
 
-#define CURRENT_TIME (current_kernel_time())
-#define CURRENT_TIME_SEC ((struct timespec) { xtime.tv_sec, 0 })
+#define CURRENT_TIME		(current_kernel_time())
+#define CURRENT_TIME_SEC	((struct timespec) { xtime.tv_sec, 0 })
 
 extern void do_gettimeofday(struct timeval *tv);
 extern int do_settimeofday(struct timespec *tv);
 extern int do_sys_settimeofday(struct timespec *tv, struct timezone *tz);
-extern void clock_was_set(void); // call when ever the clock is set
-extern int do_posix_clock_monotonic_gettime(struct timespec *tp);
-extern long do_utimes(char __user * filename, struct timeval * times);
+#define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts)
+extern long do_utimes(char __user *filename, struct timeval *times);
 struct itimerval;
-extern int do_setitimer(int which, struct itimerval *value, struct itimerval *ovalue);
+extern int do_setitimer(int which, struct itimerval *value,
+			struct itimerval *ovalue);
 extern int do_getitimer(int which, struct itimerval *value);
-extern void getnstimeofday (struct timespec *tv);
-extern void getnstimestamp(struct timespec *ts);
+extern void getnstimeofday(struct timespec *tv);
 
 extern struct timespec timespec_trunc(struct timespec t, unsigned gran);
 
-static inline void
-set_normalized_timespec (struct timespec *ts, time_t sec, long nsec)
+/**
+ * timespec_to_ns - Convert timespec to nanoseconds
+ * @ts:		pointer to the timespec variable to be converted
+ *
+ * Returns the scalar nanosecond representation of the timespec
+ * parameter.
+ */
+static inline nsec_t timespec_to_ns(const struct timespec *ts)
 {
-	while (nsec >= NSEC_PER_SEC) {
-		nsec -= NSEC_PER_SEC;
-		++sec;
-	}
-	while (nsec < 0) {
-		nsec += NSEC_PER_SEC;
-		--sec;
-	}
-	ts->tv_sec = sec;
-	ts->tv_nsec = nsec;
+	return ((nsec_t) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec;
 }
 
+/**
+ * timeval_to_ns - Convert timeval to nanoseconds
+ * @ts:		pointer to the timeval variable to be converted
+ *
+ * Returns the scalar nanosecond representation of the timeval
+ * parameter.
+ */
+static inline nsec_t timeval_to_ns(const struct timeval *tv)
+{
+	return ((nsec_t) tv->tv_sec * NSEC_PER_SEC) +
+		tv->tv_usec * NSEC_PER_USEC;
+}
+
+/**
+ * ns_to_timespec - Convert nanoseconds to timespec
+ * @nsec:	the nanoseconds value to be converted
+ *
+ * Returns the timespec representation of the nsec parameter.
+ */
+extern struct timespec ns_to_timespec(const nsec_t nsec);
+
+/**
+ * ns_to_timeval - Convert nanoseconds to timeval
+ * @nsec:	the nanoseconds value to be converted
+ *
+ * Returns the timeval representation of the nsec parameter.
+ */
+extern struct timeval ns_to_timeval(const nsec_t nsec);
+
 #endif /* __KERNEL__ */
 
 #define NFDBITS			__NFDBITS
@@ -126,49 +136,41 @@
 
 /*
  * Names of the interval timers, and structure
- * defining a timer setting.
+ * defining a timer setting:
  */
-#define	ITIMER_REAL	0
-#define	ITIMER_VIRTUAL	1
-#define	ITIMER_PROF	2
+#define	ITIMER_REAL		0
+#define	ITIMER_VIRTUAL		1
+#define	ITIMER_PROF		2
 
-struct  itimerspec {
-        struct  timespec it_interval;    /* timer period */
-        struct  timespec it_value;       /* timer expiration */
+struct itimerspec {
+	struct timespec it_interval;	/* timer period */
+	struct timespec it_value;	/* timer expiration */
 };
 
-struct	itimerval {
-	struct	timeval it_interval;	/* timer interval */
-	struct	timeval it_value;	/* current value */
+struct itimerval {
+	struct timeval it_interval;	/* timer interval */
+	struct timeval it_value;	/* current value */
 };
 
+/*
+ * The IDs of the various system clocks (for POSIX.1b interval timers):
+ */
+#define CLOCK_REALTIME			0
+#define CLOCK_MONOTONIC			1
+#define CLOCK_PROCESS_CPUTIME_ID	2
+#define CLOCK_THREAD_CPUTIME_ID		3
 
 /*
- * The IDs of the various system clocks (for POSIX.1b interval timers).
+ * The IDs of various hardware clocks:
  */
-#define CLOCK_REALTIME		  0
-#define CLOCK_MONOTONIC	  1
-#define CLOCK_PROCESS_CPUTIME_ID 2
-#define CLOCK_THREAD_CPUTIME_ID	 3
-#define CLOCK_REALTIME_HR	 4
-#define CLOCK_MONOTONIC_HR	  5
+#define CLOCK_SGI_CYCLE			10
+#define MAX_CLOCKS			16
+#define CLOCKS_MASK			(CLOCK_REALTIME | CLOCK_MONOTONIC)
+#define CLOCKS_MONO			CLOCK_MONOTONIC
 
 /*
- * The IDs of various hardware clocks
+ * The various flags for setting POSIX.1b interval timers:
  */
-
-
-#define CLOCK_SGI_CYCLE 10
-#define MAX_CLOCKS 16
-#define CLOCKS_MASK  (CLOCK_REALTIME | CLOCK_MONOTONIC | \
-                     CLOCK_REALTIME_HR | CLOCK_MONOTONIC_HR)
-#define CLOCKS_MONO (CLOCK_MONOTONIC & CLOCK_MONOTONIC_HR)
-
-/*
- * The various flags for setting POSIX.1b interval timers.
- */
-
-#define TIMER_ABSTIME 0x01
-
+#define TIMER_ABSTIME			0x01
 
 #endif
diff --git a/include/linux/timer.h b/include/linux/timer.h
index 72f3a77..9b9877f 100644
--- a/include/linux/timer.h
+++ b/include/linux/timer.h
@@ -96,6 +96,6 @@
 
 extern void init_timers(void);
 extern void run_local_timers(void);
-extern void it_real_fn(unsigned long);
+extern int it_real_fn(void *);
 
 #endif
diff --git a/include/linux/topology.h b/include/linux/topology.h
index 3df1d47..315a516 100644
--- a/include/linux/topology.h
+++ b/include/linux/topology.h
@@ -86,7 +86,6 @@
 	.max_interval		= 2,			\
 	.busy_factor		= 8,			\
 	.imbalance_pct		= 110,			\
-	.cache_hot_time		= 0,			\
 	.cache_nice_tries	= 0,			\
 	.per_cpu_gain		= 25,			\
 	.busy_idx		= 0,			\
@@ -117,7 +116,6 @@
 	.max_interval		= 4,			\
 	.busy_factor		= 64,			\
 	.imbalance_pct		= 125,			\
-	.cache_hot_time		= (5*1000000/2),	\
 	.cache_nice_tries	= 1,			\
 	.per_cpu_gain		= 100,			\
 	.busy_idx		= 2,			\
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 5744970..3787102 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -51,16 +51,22 @@
  */
 #define TTY_FLIPBUF_SIZE 512
 
-struct tty_flip_buffer {
+struct tty_buffer {
+	struct tty_buffer *next;
+	char *char_buf_ptr;
+	unsigned char *flag_buf_ptr;
+	int used;
+	int size;
+	/* Data points here */
+	unsigned long data[0];
+};
+
+struct tty_bufhead {
 	struct work_struct		work;
 	struct semaphore pty_sem;
-	char		*char_buf_ptr;
-	unsigned char	*flag_buf_ptr;
-	int		count;
-	int		buf_num;
-	unsigned char	char_buf[2*TTY_FLIPBUF_SIZE];
-	char		flag_buf[2*TTY_FLIPBUF_SIZE];
-	unsigned char	slop[4]; /* N.B. bug overwrites buffer by 1 */
+	struct tty_buffer *head;	/* Queue head */
+	struct tty_buffer *tail;	/* Active buffer */
+	struct tty_buffer *free;	/* Free queue head */
 };
 /*
  * The pty uses char_buf and flag_buf as a contiguous buffer
@@ -186,10 +192,11 @@
 	unsigned char stopped:1, hw_stopped:1, flow_stopped:1, packet:1;
 	unsigned char low_latency:1, warned:1;
 	unsigned char ctrl_status;
+	unsigned int receive_room;	/* Bytes free for queue */
 
 	struct tty_struct *link;
 	struct fasync_struct *fasync;
-	struct tty_flip_buffer flip;
+	struct tty_bufhead buf;
 	int max_flip_cnt;
 	int alt_speed;		/* For magic substitution of 38400 bps */
 	wait_queue_head_t write_wait;
diff --git a/include/linux/tty_flip.h b/include/linux/tty_flip.h
index abe9bfc..be1400e 100644
--- a/include/linux/tty_flip.h
+++ b/include/linux/tty_flip.h
@@ -1,25 +1,33 @@
 #ifndef _LINUX_TTY_FLIP_H
 #define _LINUX_TTY_FLIP_H
 
+extern int tty_buffer_request_room(struct tty_struct *tty, size_t size);
+extern int tty_insert_flip_string(struct tty_struct *tty, unsigned char *chars, size_t size);
+extern int tty_insert_flip_string_flags(struct tty_struct *tty, unsigned char *chars, char *flags, size_t size);
+extern int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **chars, size_t size);
+extern int tty_prepare_flip_string_flags(struct tty_struct *tty, unsigned char **chars, char **flags, size_t size);
+
 #ifdef INCLUDE_INLINE_FUNCS
 #define _INLINE_ extern
 #else
 #define _INLINE_ static __inline__
 #endif
 
-_INLINE_ void tty_insert_flip_char(struct tty_struct *tty,
+_INLINE_ int tty_insert_flip_char(struct tty_struct *tty,
 				   unsigned char ch, char flag)
 {
-	if (tty->flip.count < TTY_FLIPBUF_SIZE) {
-		tty->flip.count++;
-		*tty->flip.flag_buf_ptr++ = flag;
-		*tty->flip.char_buf_ptr++ = ch;
+	struct tty_buffer *tb = tty->buf.tail;
+	if (tb && tb->used < tb->size) {
+		tb->flag_buf_ptr[tb->used] = flag;
+		tb->char_buf_ptr[tb->used++] = ch;
+		return 1;
 	}
+	return tty_insert_flip_string_flags(tty, &ch, &flag, 1);
 }
 
 _INLINE_ void tty_schedule_flip(struct tty_struct *tty)
 {
-	schedule_delayed_work(&tty->flip.work, 1);
+	schedule_delayed_work(&tty->buf.work, 1);
 }
 
 #undef _INLINE_
diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
index 6066afd..83c6e6c 100644
--- a/include/linux/tty_ldisc.h
+++ b/include/linux/tty_ldisc.h
@@ -81,14 +81,6 @@
  * 	pointer of flag bytes which indicate whether a character was
  * 	received with a parity error, etc.
  * 
- * int	(*receive_room)(struct tty_struct *);
- *
- * 	This function is called by the low-level tty driver to
- * 	determine how many characters the line discpline can accept.
- * 	The low-level driver must not send more characters than was
- * 	indicated by receive_room, or the line discpline may drop
- * 	those characters.
- * 
  * void	(*write_wakeup)(struct tty_struct *);
  *
  * 	This function is called by the low-level tty driver to signal
@@ -136,7 +128,6 @@
 	 */
 	void	(*receive_buf)(struct tty_struct *, const unsigned char *cp,
 			       char *fp, int count);
-	int	(*receive_room)(struct tty_struct *);
 	void	(*write_wakeup)(struct tty_struct *);
 
 	struct  module *owner;
diff --git a/include/linux/xattr.h b/include/linux/xattr.h
index 23f9c61..cda8a96 100644
--- a/include/linux/xattr.h
+++ b/include/linux/xattr.h
@@ -13,7 +13,22 @@
 #define XATTR_CREATE	0x1	/* set value, fail if attr already exists */
 #define XATTR_REPLACE	0x2	/* set value, fail if attr does not exist */
 
+/* Namespaces */
+#define XATTR_OS2_PREFIX "os2."
+#define XATTR_OS2_PREFIX_LEN (sizeof (XATTR_OS2_PREFIX) - 1)
+
 #define XATTR_SECURITY_PREFIX	"security."
+#define XATTR_SECURITY_PREFIX_LEN (sizeof (XATTR_SECURITY_PREFIX) - 1)
+
+#define XATTR_SYSTEM_PREFIX "system."
+#define XATTR_SYSTEM_PREFIX_LEN (sizeof (XATTR_SYSTEM_PREFIX) - 1)
+
+#define XATTR_TRUSTED_PREFIX "trusted."
+#define XATTR_TRUSTED_PREFIX_LEN (sizeof (XATTR_TRUSTED_PREFIX) - 1)
+
+#define XATTR_USER_PREFIX "user."
+#define XATTR_USER_PREFIX_LEN (sizeof (XATTR_USER_PREFIX) - 1)
+
 
 struct xattr_handler {
 	char *prefix;
@@ -25,6 +40,10 @@
 		   size_t size, int flags);
 };
 
+ssize_t vfs_getxattr(struct dentry *, char *, void *, size_t);
+int vfs_setxattr(struct dentry *, char *, void *, size_t, int);
+int vfs_removexattr(struct dentry *, char *);
+
 ssize_t generic_getxattr(struct dentry *dentry, const char *name, void *buffer, size_t size);
 ssize_t generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size);
 int generic_setxattr(struct dentry *dentry, const char *name, const void *value, size_t size, int flags);
diff --git a/include/linux/zlib.h b/include/linux/zlib.h
index 74f7b78..4fa32f0 100644
--- a/include/linux/zlib.h
+++ b/include/linux/zlib.h
@@ -442,9 +442,11 @@
    not perform any compression: this will be done by deflate().
 */
                             
+#if 0
 extern int zlib_deflateSetDictionary (z_streamp strm,
 						     const Byte *dictionary,
 						     uInt  dictLength);
+#endif
 /*
      Initializes the compression dictionary from the given byte sequence
    without producing any compressed output. This function must be called
@@ -478,7 +480,10 @@
    perform any compression: this will be done by deflate().
 */
 
+#if 0
 extern int zlib_deflateCopy (z_streamp dest, z_streamp source);
+#endif
+
 /*
      Sets the destination stream as a complete copy of the source stream.
 
@@ -511,7 +516,9 @@
 	return s + ((s + 7) >> 3) + ((s + 63) >> 6) + 11;
 }
 
+#if 0
 extern int zlib_deflateParams (z_streamp strm, int level, int strategy);
+#endif
 /*
      Dynamically update the compression level and compression strategy.  The
    interpretation of level and strategy is as in deflateInit2.  This can be
@@ -571,7 +578,9 @@
    inflate().
 */
 
+#if 0
 extern int zlib_inflateSync (z_streamp strm);
+#endif
 /* 
     Skips invalid compressed data until a full flush point (see above the
   description of deflate with Z_FULL_FLUSH) can be found, or until all
@@ -636,7 +645,9 @@
 #endif
 
 extern const char  * zlib_zError           (int err);
+#if 0
 extern int           zlib_inflateSyncPoint (z_streamp z);
+#endif
 extern const uLong * zlib_get_crc_table    (void);
 
 #endif /* _ZLIB_H */
diff --git a/include/media/tuner.h b/include/media/tuner.h
index 7674b12..27cbf08 100644
--- a/include/media/tuner.h
+++ b/include/media/tuner.h
@@ -218,8 +218,8 @@
 	printk(KERN_INFO "%s %d-%04x: " fmt, t->i2c.driver->driver.name, \
 			i2c_adapter_id(t->i2c.adapter), t->i2c.addr , ##arg); } while (0)
 #define tuner_dbg(fmt, arg...) do {\
-	extern int debug; \
-	if (debug) \
+	extern int tuner_debug; \
+	if (tuner_debug) \
 		printk(KERN_DEBUG "%s %d-%04x: " fmt, t->i2c.driver->driver.name, \
 			i2c_adapter_id(t->i2c.adapter), t->i2c.addr , ##arg); } while (0)
 
diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h
index 3cc3132..c74052a 100644
--- a/include/media/v4l2-common.h
+++ b/include/media/v4l2-common.h
@@ -49,9 +49,8 @@
 
 /* These three macros assume that the debug level is set with a module
    parameter called 'debug'. */
-#define v4l_dbg(level, client, fmt, arg...)				     \
+#define v4l_dbg(level, debug, client, fmt, arg...)			     \
 	do { 								     \
-		extern int debug;					     \
 		if (debug >= (level))					     \
 			v4l_client_printk(KERN_DEBUG, client, fmt , ## arg); \
 	} while (0)
diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
index 50234fa..fa587c9 100644
--- a/include/net/inet_connection_sock.h
+++ b/include/net/inet_connection_sock.h
@@ -83,8 +83,8 @@
  	struct timer_list	  icsk_delack_timer;
 	__u32			  icsk_rto;
 	__u32			  icsk_pmtu_cookie;
-	struct tcp_congestion_ops *icsk_ca_ops;
-	struct inet_connection_sock_af_ops *icsk_af_ops;
+	const struct tcp_congestion_ops *icsk_ca_ops;
+	const struct inet_connection_sock_af_ops *icsk_af_ops;
 	unsigned int		  (*icsk_sync_mss)(struct sock *sk, u32 pmtu);
 	__u8			  icsk_ca_state;
 	__u8			  icsk_retransmits;
diff --git a/include/sound/core.h b/include/sound/core.h
index 90ac613..3093e3d 100644
--- a/include/sound/core.h
+++ b/include/sound/core.h
@@ -317,7 +317,7 @@
 #ifdef CONFIG_SND_VERBOSE_PRINTK
 /**
  * snd_printd - debug printk
- * @format: format string
+ * @fmt: format string
  *
  * Compiled only when Works like snd_printk() for debugging purpose.
  * Ignored when CONFIG_SND_DEBUG is not set.
@@ -331,7 +331,6 @@
 /**
  * snd_assert - run-time assertion macro
  * @expr: expression
- * @args...: the action
  *
  * This macro checks the expression in run-time and invokes the commands
  * given in the rest arguments if the assertion is failed.
diff --git a/include/video/kyro.h b/include/video/kyro.h
index 1bed37c..dba7de2 100644
--- a/include/video/kyro.h
+++ b/include/video/kyro.h
@@ -15,6 +15,7 @@
 struct kyrofb_info {
 	void __iomem *regbase;
 
+	u32 palette[16];
 	u32 HTot;	/* Hor Total Time    */
 	u32 HFP;	/* Hor Front Porch   */
 	u32 HST;	/* Hor Sync Time     */
diff --git a/include/video/neomagic.h b/include/video/neomagic.h
index bdaee70..1d69049 100644
--- a/include/video/neomagic.h
+++ b/include/video/neomagic.h
@@ -196,6 +196,7 @@
 	int internal_display;
 	int external_display;
 	int libretto;
+	u32 palette[16];
 };
 
 typedef struct {
diff --git a/include/video/newport.h b/include/video/newport.h
index 812dac5..1f5ebea 100644
--- a/include/video/newport.h
+++ b/include/video/newport.h
@@ -382,7 +382,8 @@
 #define VC2_IREG_CONTROL       0x10
 #define VC2_IREG_CONFIG        0x20
 
-extern __inline__ void newport_vc2_set(struct newport_regs *regs, unsigned char vc2ireg,
+static inline void newport_vc2_set(struct newport_regs *regs,
+				   unsigned char vc2ireg,
 				   unsigned short val)
 {
 	regs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_INDEX | NPORT_DMODE_W3 |
@@ -390,7 +391,7 @@
 	regs->set.dcbdata0.byword = (vc2ireg << 24) | (val << 8);
 }
 
-extern __inline__ unsigned short newport_vc2_get(struct newport_regs *regs,
+static inline unsigned short newport_vc2_get(struct newport_regs *regs,
 					     unsigned char vc2ireg)
 {
 	regs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_INDEX | NPORT_DMODE_W1 |
diff --git a/include/video/sstfb.h b/include/video/sstfb.h
index 0d77b52..3570f9c 100644
--- a/include/video/sstfb.h
+++ b/include/video/sstfb.h
@@ -334,6 +334,7 @@
 };
 
 struct sstfb_par {
+	u32 palette[16];
 	unsigned int yDim;
 	unsigned int hSyncOn;	/* hsync_len */
 	unsigned int hSyncOff;	/* left_margin + xres + right_margin */
diff --git a/include/video/tdfx.h b/include/video/tdfx.h
index 0423767..c1cc94b 100644
--- a/include/video/tdfx.h
+++ b/include/video/tdfx.h
@@ -140,52 +140,52 @@
 #ifdef __KERNEL__
 
 struct banshee_reg {
-  /* VGA rubbish */
-  unsigned char att[21];
-  unsigned char crt[25];
-  unsigned char gra[ 9];
-  unsigned char misc[1];
-  unsigned char seq[ 5];
+	/* VGA rubbish */
+	unsigned char att[21];
+	unsigned char crt[25];
+	unsigned char gra[ 9];
+	unsigned char misc[1];
+	unsigned char seq[ 5];
 
-  /* Banshee extensions */
-  unsigned char ext[2];
-  unsigned long vidcfg;
-  unsigned long vidpll;
-  unsigned long mempll;
-  unsigned long gfxpll;
-  unsigned long dacmode;
-  unsigned long vgainit0;
-  unsigned long vgainit1;
-  unsigned long screensize;
-  unsigned long stride;
-  unsigned long cursloc;
-  unsigned long curspataddr;
-  unsigned long cursc0;
-  unsigned long cursc1;
-  unsigned long startaddr;
-  unsigned long clip0min;
-  unsigned long clip0max;
-  unsigned long clip1min;
-  unsigned long clip1max;
-  unsigned long srcbase;
-  unsigned long dstbase;
-  unsigned long miscinit0;	
+	/* Banshee extensions */
+	unsigned char ext[2];
+	unsigned long vidcfg;
+	unsigned long vidpll;
+	unsigned long mempll;
+	unsigned long gfxpll;
+	unsigned long dacmode;
+	unsigned long vgainit0;
+	unsigned long vgainit1;
+	unsigned long screensize;
+	unsigned long stride;
+	unsigned long cursloc;
+	unsigned long curspataddr;
+	unsigned long cursc0;
+	unsigned long cursc1;
+	unsigned long startaddr;
+	unsigned long clip0min;
+	unsigned long clip0max;
+	unsigned long clip1min;
+	unsigned long clip1max;
+	unsigned long srcbase;
+	unsigned long dstbase;
+	unsigned long miscinit0;
 };
 
 struct tdfx_par {
-  u32 max_pixclock;
+	u32 max_pixclock;
+	u32 palette[16];
+	void __iomem *regbase_virt;
+	unsigned long iobase;
+	u32 baseline;
 
-  void __iomem *regbase_virt;
-  unsigned long iobase;
-  u32 baseline;
+	struct {
+		int w,u,d;
+		unsigned long enable,disable;
+		struct timer_list timer;
+	} hwcursor;
 
-  struct {
-     int w,u,d;
-     unsigned long enable,disable;
-     struct timer_list timer;
-  } hwcursor; 
-
-  spinlock_t DAClock;
+	spinlock_t DAClock;
 };
 
 #endif /* __KERNEL__ */
diff --git a/init/Kconfig b/init/Kconfig
index f8f6929..25f4d74 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -230,9 +230,7 @@
 
 config UID16
 	bool "Enable 16-bit UID system calls" if EMBEDDED
-	depends !ALPHA && !PPC && !PPC64 && !PARISC && !V850 && !ARCH_S390X
-	depends !X86_64 || IA32_EMULATION
-	depends !SPARC64 || SPARC32_COMPAT
+	depends on ARM || CRIS || FRV || H8300 || X86_32 || M68K || (S390 && !64BIT) || SUPERH || SPARC32 || (SPARC64 && SPARC32_COMPAT) || UML || (X86_64 && IA32_EMULATION)
 	default y
 	help
 	  This enables the legacy 16-bit UID syscall wrappers.
@@ -328,15 +326,6 @@
           option for embedded systems with no facilities for reporting errors.
           Just say Y.
 
-config DOUBLEFAULT
-	depends X86
-	default y if X86
-	bool "Enable doublefault exception handler" if EMBEDDED
-	help
-          This option allows trapping of rare doublefault exceptions that
-          would otherwise cause a system to silently reboot. Disabling this
-          option saves about 4k.
-
 config ELF_CORE
 	default y
 	bool "Enable ELF core dumps" if EMBEDDED
diff --git a/init/main.c b/init/main.c
index 8342c28..e092b19 100644
--- a/init/main.c
+++ b/init/main.c
@@ -485,6 +485,7 @@
 	init_IRQ();
 	pidhash_init();
 	init_timers();
+	hrtimers_init();
 	softirq_init();
 	time_init();
 
diff --git a/ipc/mqueue.c b/ipc/mqueue.c
index a8aa615..4e776f9 100644
--- a/ipc/mqueue.c
+++ b/ipc/mqueue.c
@@ -11,6 +11,7 @@
  * This file is released under the GPL.
  */
 
+#include <linux/capability.h>
 #include <linux/init.h>
 #include <linux/pagemap.h>
 #include <linux/file.h>
diff --git a/ipc/msg.c b/ipc/msg.c
index d035bd2..a91b647 100644
--- a/ipc/msg.c
+++ b/ipc/msg.c
@@ -15,6 +15,7 @@
  * (c) 1999 Manfred Spraul <manfreds@colorfullife.com>
  */
 
+#include <linux/capability.h>
 #include <linux/config.h>
 #include <linux/slab.h>
 #include <linux/msg.h>
diff --git a/ipc/sem.c b/ipc/sem.c
index cb5bb2a..46bb8a6 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -73,6 +73,7 @@
 #include <linux/security.h>
 #include <linux/syscalls.h>
 #include <linux/audit.h>
+#include <linux/capability.h>
 #include <linux/seq_file.h>
 #include <asm/uaccess.h>
 #include "util.h"
diff --git a/ipc/shm.c b/ipc/shm.c
index 0b92e87..4c28d2d 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -27,6 +27,7 @@
 #include <linux/security.h>
 #include <linux/syscalls.h>
 #include <linux/audit.h>
+#include <linux/capability.h>
 #include <linux/ptrace.h>
 #include <linux/seq_file.h>
 
diff --git a/ipc/util.c b/ipc/util.c
index 23f1cec..38b9a0a 100644
--- a/ipc/util.c
+++ b/ipc/util.c
@@ -20,6 +20,7 @@
 #include <linux/smp_lock.h>
 #include <linux/vmalloc.h>
 #include <linux/slab.h>
+#include <linux/capability.h>
 #include <linux/highuid.h>
 #include <linux/security.h>
 #include <linux/rcupdate.h>
diff --git a/kernel/Makefile b/kernel/Makefile
index a940bac..3551266 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -7,7 +7,8 @@
 	    sysctl.o capability.o ptrace.o timer.o user.o \
 	    signal.o sys.o kmod.o workqueue.o pid.o \
 	    rcupdate.o intermodule.o extable.o params.o posix-timers.o \
-	    kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o
+	    kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \
+	    hrtimer.o
 
 obj-$(CONFIG_DEBUG_MUTEXES) += mutex-debug.o
 obj-$(CONFIG_FUTEX) += futex.o
@@ -30,7 +31,6 @@
 obj-$(CONFIG_SYSFS) += ksysfs.o
 obj-$(CONFIG_DETECT_SOFTLOCKUP) += softlockup.o
 obj-$(CONFIG_GENERIC_HARDIRQS) += irq/
-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
 obj-$(CONFIG_SECCOMP) += seccomp.o
 obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o
 
diff --git a/kernel/acct.c b/kernel/acct.c
index 38d57fa..065d8b4 100644
--- a/kernel/acct.c
+++ b/kernel/acct.c
@@ -47,6 +47,7 @@
 #include <linux/mm.h>
 #include <linux/slab.h>
 #include <linux/acct.h>
+#include <linux/capability.h>
 #include <linux/file.h>
 #include <linux/tty.h>
 #include <linux/security.h>
diff --git a/kernel/capability.c b/kernel/capability.c
index 8986a37..bfa3c92 100644
--- a/kernel/capability.c
+++ b/kernel/capability.c
@@ -7,6 +7,7 @@
  * 30 May 2002:	Cleanup, Robert M. Love <rml@tech9.net>
  */ 
 
+#include <linux/capability.h>
 #include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/security.h>
diff --git a/kernel/compat.c b/kernel/compat.c
index 102296e..256e5d9 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -514,6 +514,24 @@
 	return 0;
 } 
 
+long compat_sys_timer_create(clockid_t which_clock,
+			struct compat_sigevent __user *timer_event_spec,
+			timer_t __user *created_timer_id)
+{
+	struct sigevent __user *event = NULL;
+
+	if (timer_event_spec) {
+		struct sigevent kevent;
+
+		event = compat_alloc_user_space(sizeof(*event));
+		if (get_compat_sigevent(&kevent, timer_event_spec) ||
+		    copy_to_user(event, &kevent, sizeof(*event)))
+			return -EFAULT;
+	}
+
+	return sys_timer_create(which_clock, event, created_timer_id);
+}
+
 long compat_sys_timer_settime(timer_t timer_id, int flags,
 			  struct compat_itimerspec __user *new, 
 			  struct compat_itimerspec __user *old)
@@ -649,8 +667,6 @@
 		? -EFAULT : 0;
 }
 
-/* timer_create is architecture specific because it needs sigevent conversion */
-
 long compat_get_bitmap(unsigned long *mask, compat_ulong_t __user *umask,
 		       unsigned long bitmap_size)
 {
diff --git a/kernel/exit.c b/kernel/exit.c
index 309a46f..f8e609f 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -10,6 +10,7 @@
 #include <linux/interrupt.h>
 #include <linux/smp_lock.h>
 #include <linux/module.h>
+#include <linux/capability.h>
 #include <linux/completion.h>
 #include <linux/personality.h>
 #include <linux/tty.h>
@@ -842,7 +843,7 @@
 	}
 	group_dead = atomic_dec_and_test(&tsk->signal->live);
 	if (group_dead) {
- 		del_timer_sync(&tsk->signal->real_timer);
+ 		hrtimer_cancel(&tsk->signal->real_timer);
 		exit_itimers(tsk->signal);
 		acct_process(code);
 	}
@@ -1071,6 +1072,9 @@
 	}
 
 	if (likely(p->real_parent == p->parent) && likely(p->signal)) {
+		struct signal_struct *psig;
+		struct signal_struct *sig;
+
 		/*
 		 * The resource counters for the group leader are in its
 		 * own task_struct.  Those for dead threads in the group
@@ -1087,24 +1091,26 @@
 		 * here reaping other children at the same time.
 		 */
 		spin_lock_irq(&p->parent->sighand->siglock);
-		p->parent->signal->cutime =
-			cputime_add(p->parent->signal->cutime,
+		psig = p->parent->signal;
+		sig = p->signal;
+		psig->cutime =
+			cputime_add(psig->cutime,
 			cputime_add(p->utime,
-			cputime_add(p->signal->utime,
-				    p->signal->cutime)));
-		p->parent->signal->cstime =
-			cputime_add(p->parent->signal->cstime,
+			cputime_add(sig->utime,
+				    sig->cutime)));
+		psig->cstime =
+			cputime_add(psig->cstime,
 			cputime_add(p->stime,
-			cputime_add(p->signal->stime,
-				    p->signal->cstime)));
-		p->parent->signal->cmin_flt +=
-			p->min_flt + p->signal->min_flt + p->signal->cmin_flt;
-		p->parent->signal->cmaj_flt +=
-			p->maj_flt + p->signal->maj_flt + p->signal->cmaj_flt;
-		p->parent->signal->cnvcsw +=
-			p->nvcsw + p->signal->nvcsw + p->signal->cnvcsw;
-		p->parent->signal->cnivcsw +=
-			p->nivcsw + p->signal->nivcsw + p->signal->cnivcsw;
+			cputime_add(sig->stime,
+				    sig->cstime)));
+		psig->cmin_flt +=
+			p->min_flt + sig->min_flt + sig->cmin_flt;
+		psig->cmaj_flt +=
+			p->maj_flt + sig->maj_flt + sig->cmaj_flt;
+		psig->cnvcsw +=
+			p->nvcsw + sig->nvcsw + sig->cnvcsw;
+		psig->cnivcsw +=
+			p->nivcsw + sig->nivcsw + sig->cnivcsw;
 		spin_unlock_irq(&p->parent->sighand->siglock);
 	}
 
diff --git a/kernel/fork.c b/kernel/fork.c
index b18d645..4ae8cfc 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -28,6 +28,7 @@
 #include <linux/binfmts.h>
 #include <linux/mman.h>
 #include <linux/fs.h>
+#include <linux/capability.h>
 #include <linux/cpu.h>
 #include <linux/cpuset.h>
 #include <linux/security.h>
@@ -801,10 +802,10 @@
 	init_sigpending(&sig->shared_pending);
 	INIT_LIST_HEAD(&sig->posix_timers);
 
-	sig->it_real_value = sig->it_real_incr = 0;
+	hrtimer_init(&sig->real_timer, CLOCK_MONOTONIC);
+	sig->it_real_incr.tv64 = 0;
 	sig->real_timer.function = it_real_fn;
-	sig->real_timer.data = (unsigned long) tsk;
-	init_timer(&sig->real_timer);
+	sig->real_timer.data = tsk;
 
 	sig->it_virt_expires = cputime_zero;
 	sig->it_virt_incr = cputime_zero;
@@ -1297,6 +1298,10 @@
 	return pid;
 }
 
+#ifndef ARCH_MIN_MMSTRUCT_ALIGN
+#define ARCH_MIN_MMSTRUCT_ALIGN 0
+#endif
+
 void __init proc_caches_init(void)
 {
 	sighand_cachep = kmem_cache_create("sighand_cache",
@@ -1315,6 +1320,6 @@
 			sizeof(struct vm_area_struct), 0,
 			SLAB_PANIC, NULL, NULL);
 	mm_cachep = kmem_cache_create("mm_struct",
-			sizeof(struct mm_struct), 0,
+			sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
 			SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
 }
diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
new file mode 100644
index 0000000..04ccab0
--- /dev/null
+++ b/kernel/hrtimer.c
@@ -0,0 +1,825 @@
+/*
+ *  linux/kernel/hrtimer.c
+ *
+ *  Copyright(C) 2005, Thomas Gleixner <tglx@linutronix.de>
+ *  Copyright(C) 2005, Red Hat, Inc., Ingo Molnar
+ *
+ *  High-resolution kernel timers
+ *
+ *  In contrast to the low-resolution timeout API implemented in
+ *  kernel/timer.c, hrtimers provide finer resolution and accuracy
+ *  depending on system configuration and capabilities.
+ *
+ *  These timers are currently used for:
+ *   - itimers
+ *   - POSIX timers
+ *   - nanosleep
+ *   - precise in-kernel timing
+ *
+ *  Started by: Thomas Gleixner and Ingo Molnar
+ *
+ *  Credits:
+ *	based on kernel/timer.c
+ *
+ *  For licencing details see kernel-base/COPYING
+ */
+
+#include <linux/cpu.h>
+#include <linux/module.h>
+#include <linux/percpu.h>
+#include <linux/hrtimer.h>
+#include <linux/notifier.h>
+#include <linux/syscalls.h>
+#include <linux/interrupt.h>
+
+#include <asm/uaccess.h>
+
+/**
+ * ktime_get - get the monotonic time in ktime_t format
+ *
+ * returns the time in ktime_t format
+ */
+static ktime_t ktime_get(void)
+{
+	struct timespec now;
+
+	ktime_get_ts(&now);
+
+	return timespec_to_ktime(now);
+}
+
+/**
+ * ktime_get_real - get the real (wall-) time in ktime_t format
+ *
+ * returns the time in ktime_t format
+ */
+static ktime_t ktime_get_real(void)
+{
+	struct timespec now;
+
+	getnstimeofday(&now);
+
+	return timespec_to_ktime(now);
+}
+
+EXPORT_SYMBOL_GPL(ktime_get_real);
+
+/*
+ * The timer bases:
+ */
+
+#define MAX_HRTIMER_BASES 2
+
+static DEFINE_PER_CPU(struct hrtimer_base, hrtimer_bases[MAX_HRTIMER_BASES]) =
+{
+	{
+		.index = CLOCK_REALTIME,
+		.get_time = &ktime_get_real,
+		.resolution = KTIME_REALTIME_RES,
+	},
+	{
+		.index = CLOCK_MONOTONIC,
+		.get_time = &ktime_get,
+		.resolution = KTIME_MONOTONIC_RES,
+	},
+};
+
+/**
+ * ktime_get_ts - get the monotonic clock in timespec format
+ *
+ * @ts:		pointer to timespec variable
+ *
+ * The function calculates the monotonic clock from the realtime
+ * clock and the wall_to_monotonic offset and stores the result
+ * in normalized timespec format in the variable pointed to by ts.
+ */
+void ktime_get_ts(struct timespec *ts)
+{
+	struct timespec tomono;
+	unsigned long seq;
+
+	do {
+		seq = read_seqbegin(&xtime_lock);
+		getnstimeofday(ts);
+		tomono = wall_to_monotonic;
+
+	} while (read_seqretry(&xtime_lock, seq));
+
+	set_normalized_timespec(ts, ts->tv_sec + tomono.tv_sec,
+				ts->tv_nsec + tomono.tv_nsec);
+}
+EXPORT_SYMBOL_GPL(ktime_get_ts);
+
+/*
+ * Functions and macros which are different for UP/SMP systems are kept in a
+ * single place
+ */
+#ifdef CONFIG_SMP
+
+#define set_curr_timer(b, t)		do { (b)->curr_timer = (t); } while (0)
+
+/*
+ * We are using hashed locking: holding per_cpu(hrtimer_bases)[n].lock
+ * means that all timers which are tied to this base via timer->base are
+ * locked, and the base itself is locked too.
+ *
+ * So __run_timers/migrate_timers can safely modify all timers which could
+ * be found on the lists/queues.
+ *
+ * When the timer's base is locked, and the timer removed from list, it is
+ * possible to set timer->base = NULL and drop the lock: the timer remains
+ * locked.
+ */
+static struct hrtimer_base *lock_hrtimer_base(const struct hrtimer *timer,
+					      unsigned long *flags)
+{
+	struct hrtimer_base *base;
+
+	for (;;) {
+		base = timer->base;
+		if (likely(base != NULL)) {
+			spin_lock_irqsave(&base->lock, *flags);
+			if (likely(base == timer->base))
+				return base;
+			/* The timer has migrated to another CPU: */
+			spin_unlock_irqrestore(&base->lock, *flags);
+		}
+		cpu_relax();
+	}
+}
+
+/*
+ * Switch the timer base to the current CPU when possible.
+ */
+static inline struct hrtimer_base *
+switch_hrtimer_base(struct hrtimer *timer, struct hrtimer_base *base)
+{
+	struct hrtimer_base *new_base;
+
+	new_base = &__get_cpu_var(hrtimer_bases[base->index]);
+
+	if (base != new_base) {
+		/*
+		 * We are trying to schedule the timer on the local CPU.
+		 * However we can't change timer's base while it is running,
+		 * so we keep it on the same CPU. No hassle vs. reprogramming
+		 * the event source in the high resolution case. The softirq
+		 * code will take care of this when the timer function has
+		 * completed. There is no conflict as we hold the lock until
+		 * the timer is enqueued.
+		 */
+		if (unlikely(base->curr_timer == timer))
+			return base;
+
+		/* See the comment in lock_timer_base() */
+		timer->base = NULL;
+		spin_unlock(&base->lock);
+		spin_lock(&new_base->lock);
+		timer->base = new_base;
+	}
+	return new_base;
+}
+
+#else /* CONFIG_SMP */
+
+#define set_curr_timer(b, t)		do { } while (0)
+
+static inline struct hrtimer_base *
+lock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags)
+{
+	struct hrtimer_base *base = timer->base;
+
+	spin_lock_irqsave(&base->lock, *flags);
+
+	return base;
+}
+
+#define switch_hrtimer_base(t, b)	(b)
+
+#endif	/* !CONFIG_SMP */
+
+/*
+ * Functions for the union type storage format of ktime_t which are
+ * too large for inlining:
+ */
+#if BITS_PER_LONG < 64
+# ifndef CONFIG_KTIME_SCALAR
+/**
+ * ktime_add_ns - Add a scalar nanoseconds value to a ktime_t variable
+ *
+ * @kt:		addend
+ * @nsec:	the scalar nsec value to add
+ *
+ * Returns the sum of kt and nsec in ktime_t format
+ */
+ktime_t ktime_add_ns(const ktime_t kt, u64 nsec)
+{
+	ktime_t tmp;
+
+	if (likely(nsec < NSEC_PER_SEC)) {
+		tmp.tv64 = nsec;
+	} else {
+		unsigned long rem = do_div(nsec, NSEC_PER_SEC);
+
+		tmp = ktime_set((long)nsec, rem);
+	}
+
+	return ktime_add(kt, tmp);
+}
+
+#else /* CONFIG_KTIME_SCALAR */
+
+# endif /* !CONFIG_KTIME_SCALAR */
+
+/*
+ * Divide a ktime value by a nanosecond value
+ */
+static unsigned long ktime_divns(const ktime_t kt, nsec_t div)
+{
+	u64 dclc, inc, dns;
+	int sft = 0;
+
+	dclc = dns = ktime_to_ns(kt);
+	inc = div;
+	/* Make sure the divisor is less than 2^32: */
+	while (div >> 32) {
+		sft++;
+		div >>= 1;
+	}
+	dclc >>= sft;
+	do_div(dclc, (unsigned long) div);
+
+	return (unsigned long) dclc;
+}
+
+#else /* BITS_PER_LONG < 64 */
+# define ktime_divns(kt, div)		(unsigned long)((kt).tv64 / (div))
+#endif /* BITS_PER_LONG >= 64 */
+
+/*
+ * Counterpart to lock_timer_base above:
+ */
+static inline
+void unlock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags)
+{
+	spin_unlock_irqrestore(&timer->base->lock, *flags);
+}
+
+/**
+ * hrtimer_forward - forward the timer expiry
+ *
+ * @timer:	hrtimer to forward
+ * @interval:	the interval to forward
+ *
+ * Forward the timer expiry so it will expire in the future.
+ * The number of overruns is added to the overrun field.
+ */
+unsigned long
+hrtimer_forward(struct hrtimer *timer, ktime_t interval)
+{
+	unsigned long orun = 1;
+	ktime_t delta, now;
+
+	now = timer->base->get_time();
+
+	delta = ktime_sub(now, timer->expires);
+
+	if (delta.tv64 < 0)
+		return 0;
+
+	if (interval.tv64 < timer->base->resolution.tv64)
+		interval.tv64 = timer->base->resolution.tv64;
+
+	if (unlikely(delta.tv64 >= interval.tv64)) {
+		nsec_t incr = ktime_to_ns(interval);
+
+		orun = ktime_divns(delta, incr);
+		timer->expires = ktime_add_ns(timer->expires, incr * orun);
+		if (timer->expires.tv64 > now.tv64)
+			return orun;
+		/*
+		 * This (and the ktime_add() below) is the
+		 * correction for exact:
+		 */
+		orun++;
+	}
+	timer->expires = ktime_add(timer->expires, interval);
+
+	return orun;
+}
+
+/*
+ * enqueue_hrtimer - internal function to (re)start a timer
+ *
+ * The timer is inserted in expiry order. Insertion into the
+ * red black tree is O(log(n)). Must hold the base lock.
+ */
+static void enqueue_hrtimer(struct hrtimer *timer, struct hrtimer_base *base)
+{
+	struct rb_node **link = &base->active.rb_node;
+	struct rb_node *parent = NULL;
+	struct hrtimer *entry;
+
+	/*
+	 * Find the right place in the rbtree:
+	 */
+	while (*link) {
+		parent = *link;
+		entry = rb_entry(parent, struct hrtimer, node);
+		/*
+		 * We dont care about collisions. Nodes with
+		 * the same expiry time stay together.
+		 */
+		if (timer->expires.tv64 < entry->expires.tv64)
+			link = &(*link)->rb_left;
+		else
+			link = &(*link)->rb_right;
+	}
+
+	/*
+	 * Insert the timer to the rbtree and check whether it
+	 * replaces the first pending timer
+	 */
+	rb_link_node(&timer->node, parent, link);
+	rb_insert_color(&timer->node, &base->active);
+
+	timer->state = HRTIMER_PENDING;
+
+	if (!base->first || timer->expires.tv64 <
+	    rb_entry(base->first, struct hrtimer, node)->expires.tv64)
+		base->first = &timer->node;
+}
+
+/*
+ * __remove_hrtimer - internal function to remove a timer
+ *
+ * Caller must hold the base lock.
+ */
+static void __remove_hrtimer(struct hrtimer *timer, struct hrtimer_base *base)
+{
+	/*
+	 * Remove the timer from the rbtree and replace the
+	 * first entry pointer if necessary.
+	 */
+	if (base->first == &timer->node)
+		base->first = rb_next(&timer->node);
+	rb_erase(&timer->node, &base->active);
+}
+
+/*
+ * remove hrtimer, called with base lock held
+ */
+static inline int
+remove_hrtimer(struct hrtimer *timer, struct hrtimer_base *base)
+{
+	if (hrtimer_active(timer)) {
+		__remove_hrtimer(timer, base);
+		timer->state = HRTIMER_INACTIVE;
+		return 1;
+	}
+	return 0;
+}
+
+/**
+ * hrtimer_start - (re)start an relative timer on the current CPU
+ *
+ * @timer:	the timer to be added
+ * @tim:	expiry time
+ * @mode:	expiry mode: absolute (HRTIMER_ABS) or relative (HRTIMER_REL)
+ *
+ * Returns:
+ *  0 on success
+ *  1 when the timer was active
+ */
+int
+hrtimer_start(struct hrtimer *timer, ktime_t tim, const enum hrtimer_mode mode)
+{
+	struct hrtimer_base *base, *new_base;
+	unsigned long flags;
+	int ret;
+
+	base = lock_hrtimer_base(timer, &flags);
+
+	/* Remove an active timer from the queue: */
+	ret = remove_hrtimer(timer, base);
+
+	/* Switch the timer base, if necessary: */
+	new_base = switch_hrtimer_base(timer, base);
+
+	if (mode == HRTIMER_REL)
+		tim = ktime_add(tim, new_base->get_time());
+	timer->expires = tim;
+
+	enqueue_hrtimer(timer, new_base);
+
+	unlock_hrtimer_base(timer, &flags);
+
+	return ret;
+}
+
+/**
+ * hrtimer_try_to_cancel - try to deactivate a timer
+ *
+ * @timer:	hrtimer to stop
+ *
+ * Returns:
+ *  0 when the timer was not active
+ *  1 when the timer was active
+ * -1 when the timer is currently excuting the callback function and
+ *    can not be stopped
+ */
+int hrtimer_try_to_cancel(struct hrtimer *timer)
+{
+	struct hrtimer_base *base;
+	unsigned long flags;
+	int ret = -1;
+
+	base = lock_hrtimer_base(timer, &flags);
+
+	if (base->curr_timer != timer)
+		ret = remove_hrtimer(timer, base);
+
+	unlock_hrtimer_base(timer, &flags);
+
+	return ret;
+
+}
+
+/**
+ * hrtimer_cancel - cancel a timer and wait for the handler to finish.
+ *
+ * @timer:	the timer to be cancelled
+ *
+ * Returns:
+ *  0 when the timer was not active
+ *  1 when the timer was active
+ */
+int hrtimer_cancel(struct hrtimer *timer)
+{
+	for (;;) {
+		int ret = hrtimer_try_to_cancel(timer);
+
+		if (ret >= 0)
+			return ret;
+	}
+}
+
+/**
+ * hrtimer_get_remaining - get remaining time for the timer
+ *
+ * @timer:	the timer to read
+ */
+ktime_t hrtimer_get_remaining(const struct hrtimer *timer)
+{
+	struct hrtimer_base *base;
+	unsigned long flags;
+	ktime_t rem;
+
+	base = lock_hrtimer_base(timer, &flags);
+	rem = ktime_sub(timer->expires, timer->base->get_time());
+	unlock_hrtimer_base(timer, &flags);
+
+	return rem;
+}
+
+/**
+ * hrtimer_rebase - rebase an initialized hrtimer to a different base
+ *
+ * @timer:	the timer to be rebased
+ * @clock_id:	the clock to be used
+ */
+void hrtimer_rebase(struct hrtimer *timer, const clockid_t clock_id)
+{
+	struct hrtimer_base *bases;
+
+	bases = per_cpu(hrtimer_bases, raw_smp_processor_id());
+	timer->base = &bases[clock_id];
+}
+
+/**
+ * hrtimer_init - initialize a timer to the given clock
+ *
+ * @timer:	the timer to be initialized
+ * @clock_id:	the clock to be used
+ */
+void hrtimer_init(struct hrtimer *timer, const clockid_t clock_id)
+{
+	memset(timer, 0, sizeof(struct hrtimer));
+	hrtimer_rebase(timer, clock_id);
+}
+
+/**
+ * hrtimer_get_res - get the timer resolution for a clock
+ *
+ * @which_clock: which clock to query
+ * @tp:		 pointer to timespec variable to store the resolution
+ *
+ * Store the resolution of the clock selected by which_clock in the
+ * variable pointed to by tp.
+ */
+int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp)
+{
+	struct hrtimer_base *bases;
+
+	bases = per_cpu(hrtimer_bases, raw_smp_processor_id());
+	*tp = ktime_to_timespec(bases[which_clock].resolution);
+
+	return 0;
+}
+
+/*
+ * Expire the per base hrtimer-queue:
+ */
+static inline void run_hrtimer_queue(struct hrtimer_base *base)
+{
+	ktime_t now = base->get_time();
+	struct rb_node *node;
+
+	spin_lock_irq(&base->lock);
+
+	while ((node = base->first)) {
+		struct hrtimer *timer;
+		int (*fn)(void *);
+		int restart;
+		void *data;
+
+		timer = rb_entry(node, struct hrtimer, node);
+		if (now.tv64 <= timer->expires.tv64)
+			break;
+
+		fn = timer->function;
+		data = timer->data;
+		set_curr_timer(base, timer);
+		__remove_hrtimer(timer, base);
+		spin_unlock_irq(&base->lock);
+
+		/*
+		 * fn == NULL is special case for the simplest timer
+		 * variant - wake up process and do not restart:
+		 */
+		if (!fn) {
+			wake_up_process(data);
+			restart = HRTIMER_NORESTART;
+		} else
+			restart = fn(data);
+
+		spin_lock_irq(&base->lock);
+
+		if (restart == HRTIMER_RESTART)
+			enqueue_hrtimer(timer, base);
+		else
+			timer->state = HRTIMER_EXPIRED;
+	}
+	set_curr_timer(base, NULL);
+	spin_unlock_irq(&base->lock);
+}
+
+/*
+ * Called from timer softirq every jiffy, expire hrtimers:
+ */
+void hrtimer_run_queues(void)
+{
+	struct hrtimer_base *base = __get_cpu_var(hrtimer_bases);
+	int i;
+
+	for (i = 0; i < MAX_HRTIMER_BASES; i++)
+		run_hrtimer_queue(&base[i]);
+}
+
+/*
+ * Sleep related functions:
+ */
+
+/**
+ * schedule_hrtimer - sleep until timeout
+ *
+ * @timer:	hrtimer variable initialized with the correct clock base
+ * @mode:	timeout value is abs/rel
+ *
+ * Make the current task sleep until @timeout is
+ * elapsed.
+ *
+ * You can set the task state as follows -
+ *
+ * %TASK_UNINTERRUPTIBLE - at least @timeout is guaranteed to
+ * pass before the routine returns. The routine will return 0
+ *
+ * %TASK_INTERRUPTIBLE - the routine may return early if a signal is
+ * delivered to the current task. In this case the remaining time
+ * will be returned
+ *
+ * The current task state is guaranteed to be TASK_RUNNING when this
+ * routine returns.
+ */
+static ktime_t __sched
+schedule_hrtimer(struct hrtimer *timer, const enum hrtimer_mode mode)
+{
+	/* fn stays NULL, meaning single-shot wakeup: */
+	timer->data = current;
+
+	hrtimer_start(timer, timer->expires, mode);
+
+	schedule();
+	hrtimer_cancel(timer);
+
+	/* Return the remaining time: */
+	if (timer->state != HRTIMER_EXPIRED)
+		return ktime_sub(timer->expires, timer->base->get_time());
+	else
+		return (ktime_t) {.tv64 = 0 };
+}
+
+static inline ktime_t __sched
+schedule_hrtimer_interruptible(struct hrtimer *timer,
+			       const enum hrtimer_mode mode)
+{
+	set_current_state(TASK_INTERRUPTIBLE);
+
+	return schedule_hrtimer(timer, mode);
+}
+
+static long __sched
+nanosleep_restart(struct restart_block *restart, clockid_t clockid)
+{
+	struct timespec __user *rmtp, tu;
+	void *rfn_save = restart->fn;
+	struct hrtimer timer;
+	ktime_t rem;
+
+	restart->fn = do_no_restart_syscall;
+
+	hrtimer_init(&timer, clockid);
+
+	timer.expires.tv64 = ((u64)restart->arg1 << 32) | (u64) restart->arg0;
+
+	rem = schedule_hrtimer_interruptible(&timer, HRTIMER_ABS);
+
+	if (rem.tv64 <= 0)
+		return 0;
+
+	rmtp = (struct timespec __user *) restart->arg2;
+	tu = ktime_to_timespec(rem);
+	if (rmtp && copy_to_user(rmtp, &tu, sizeof(tu)))
+		return -EFAULT;
+
+	restart->fn = rfn_save;
+
+	/* The other values in restart are already filled in */
+	return -ERESTART_RESTARTBLOCK;
+}
+
+static long __sched nanosleep_restart_mono(struct restart_block *restart)
+{
+	return nanosleep_restart(restart, CLOCK_MONOTONIC);
+}
+
+static long __sched nanosleep_restart_real(struct restart_block *restart)
+{
+	return nanosleep_restart(restart, CLOCK_REALTIME);
+}
+
+long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
+		       const enum hrtimer_mode mode, const clockid_t clockid)
+{
+	struct restart_block *restart;
+	struct hrtimer timer;
+	struct timespec tu;
+	ktime_t rem;
+
+	hrtimer_init(&timer, clockid);
+
+	timer.expires = timespec_to_ktime(*rqtp);
+
+	rem = schedule_hrtimer_interruptible(&timer, mode);
+	if (rem.tv64 <= 0)
+		return 0;
+
+	/* Absolute timers do not update the rmtp value: */
+	if (mode == HRTIMER_ABS)
+		return -ERESTARTNOHAND;
+
+	tu = ktime_to_timespec(rem);
+
+	if (rmtp && copy_to_user(rmtp, &tu, sizeof(tu)))
+		return -EFAULT;
+
+	restart = &current_thread_info()->restart_block;
+	restart->fn = (clockid == CLOCK_MONOTONIC) ?
+		nanosleep_restart_mono : nanosleep_restart_real;
+	restart->arg0 = timer.expires.tv64 & 0xFFFFFFFF;
+	restart->arg1 = timer.expires.tv64 >> 32;
+	restart->arg2 = (unsigned long) rmtp;
+
+	return -ERESTART_RESTARTBLOCK;
+}
+
+asmlinkage long
+sys_nanosleep(struct timespec __user *rqtp, struct timespec __user *rmtp)
+{
+	struct timespec tu;
+
+	if (copy_from_user(&tu, rqtp, sizeof(tu)))
+		return -EFAULT;
+
+	if (!timespec_valid(&tu))
+		return -EINVAL;
+
+	return hrtimer_nanosleep(&tu, rmtp, HRTIMER_REL, CLOCK_MONOTONIC);
+}
+
+/*
+ * Functions related to boot-time initialization:
+ */
+static void __devinit init_hrtimers_cpu(int cpu)
+{
+	struct hrtimer_base *base = per_cpu(hrtimer_bases, cpu);
+	int i;
+
+	for (i = 0; i < MAX_HRTIMER_BASES; i++) {
+		spin_lock_init(&base->lock);
+		base++;
+	}
+}
+
+#ifdef CONFIG_HOTPLUG_CPU
+
+static void migrate_hrtimer_list(struct hrtimer_base *old_base,
+				struct hrtimer_base *new_base)
+{
+	struct hrtimer *timer;
+	struct rb_node *node;
+
+	while ((node = rb_first(&old_base->active))) {
+		timer = rb_entry(node, struct hrtimer, node);
+		__remove_hrtimer(timer, old_base);
+		timer->base = new_base;
+		enqueue_hrtimer(timer, new_base);
+	}
+}
+
+static void migrate_hrtimers(int cpu)
+{
+	struct hrtimer_base *old_base, *new_base;
+	int i;
+
+	BUG_ON(cpu_online(cpu));
+	old_base = per_cpu(hrtimer_bases, cpu);
+	new_base = get_cpu_var(hrtimer_bases);
+
+	local_irq_disable();
+
+	for (i = 0; i < MAX_HRTIMER_BASES; i++) {
+
+		spin_lock(&new_base->lock);
+		spin_lock(&old_base->lock);
+
+		BUG_ON(old_base->curr_timer);
+
+		migrate_hrtimer_list(old_base, new_base);
+
+		spin_unlock(&old_base->lock);
+		spin_unlock(&new_base->lock);
+		old_base++;
+		new_base++;
+	}
+
+	local_irq_enable();
+	put_cpu_var(hrtimer_bases);
+}
+#endif /* CONFIG_HOTPLUG_CPU */
+
+static int __devinit hrtimer_cpu_notify(struct notifier_block *self,
+					unsigned long action, void *hcpu)
+{
+	long cpu = (long)hcpu;
+
+	switch (action) {
+
+	case CPU_UP_PREPARE:
+		init_hrtimers_cpu(cpu);
+		break;
+
+#ifdef CONFIG_HOTPLUG_CPU
+	case CPU_DEAD:
+		migrate_hrtimers(cpu);
+		break;
+#endif
+
+	default:
+		break;
+	}
+
+	return NOTIFY_OK;
+}
+
+static struct notifier_block __devinitdata hrtimers_nb = {
+	.notifier_call = hrtimer_cpu_notify,
+};
+
+void __init hrtimers_init(void)
+{
+	hrtimer_cpu_notify(&hrtimers_nb, (unsigned long)CPU_UP_PREPARE,
+			  (void *)(long)smp_processor_id());
+	register_cpu_notifier(&hrtimers_nb);
+}
+
diff --git a/kernel/itimer.c b/kernel/itimer.c
index 7c1b25e..c2c05c4 100644
--- a/kernel/itimer.c
+++ b/kernel/itimer.c
@@ -12,36 +12,46 @@
 #include <linux/syscalls.h>
 #include <linux/time.h>
 #include <linux/posix-timers.h>
+#include <linux/hrtimer.h>
 
 #include <asm/uaccess.h>
 
-static unsigned long it_real_value(struct signal_struct *sig)
+/**
+ * itimer_get_remtime - get remaining time for the timer
+ *
+ * @timer: the timer to read
+ *
+ * Returns the delta between the expiry time and now, which can be
+ * less than zero or 1usec for an pending expired timer
+ */
+static struct timeval itimer_get_remtime(struct hrtimer *timer)
 {
-	unsigned long val = 0;
-	if (timer_pending(&sig->real_timer)) {
-		val = sig->real_timer.expires - jiffies;
+	ktime_t rem = hrtimer_get_remaining(timer);
 
-		/* look out for negative/zero itimer.. */
-		if ((long) val <= 0)
-			val = 1;
-	}
-	return val;
+	/*
+	 * Racy but safe: if the itimer expires after the above
+	 * hrtimer_get_remtime() call but before this condition
+	 * then we return 0 - which is correct.
+	 */
+	if (hrtimer_active(timer)) {
+		if (rem.tv64 <= 0)
+			rem.tv64 = NSEC_PER_USEC;
+	} else
+		rem.tv64 = 0;
+
+	return ktime_to_timeval(rem);
 }
 
 int do_getitimer(int which, struct itimerval *value)
 {
 	struct task_struct *tsk = current;
-	unsigned long interval, val;
 	cputime_t cinterval, cval;
 
 	switch (which) {
 	case ITIMER_REAL:
-		spin_lock_irq(&tsk->sighand->siglock);
-		interval = tsk->signal->it_real_incr;
-		val = it_real_value(tsk->signal);
-		spin_unlock_irq(&tsk->sighand->siglock);
-		jiffies_to_timeval(val, &value->it_value);
-		jiffies_to_timeval(interval, &value->it_interval);
+		value->it_value = itimer_get_remtime(&tsk->signal->real_timer);
+		value->it_interval =
+			ktime_to_timeval(tsk->signal->it_real_incr);
 		break;
 	case ITIMER_VIRTUAL:
 		read_lock(&tasklist_lock);
@@ -113,59 +123,45 @@
 }
 
 
-void it_real_fn(unsigned long __data)
+/*
+ * The timer is automagically restarted, when interval != 0
+ */
+int it_real_fn(void *data)
 {
-	struct task_struct * p = (struct task_struct *) __data;
-	unsigned long inc = p->signal->it_real_incr;
+	struct task_struct *tsk = (struct task_struct *) data;
 
-	send_group_sig_info(SIGALRM, SEND_SIG_PRIV, p);
+	send_group_sig_info(SIGALRM, SEND_SIG_PRIV, tsk);
 
-	/*
-	 * Now restart the timer if necessary.  We don't need any locking
-	 * here because do_setitimer makes sure we have finished running
-	 * before it touches anything.
-	 * Note, we KNOW we are (or should be) at a jiffie edge here so
-	 * we don't need the +1 stuff.  Also, we want to use the prior
-	 * expire value so as to not "slip" a jiffie if we are late.
-	 * Deal with requesting a time prior to "now" here rather than
-	 * in add_timer.
-	 */
-	if (!inc)
-		return;
-	while (time_before_eq(p->signal->real_timer.expires, jiffies))
-		p->signal->real_timer.expires += inc;
-	add_timer(&p->signal->real_timer);
+	if (tsk->signal->it_real_incr.tv64 != 0) {
+		hrtimer_forward(&tsk->signal->real_timer,
+			       tsk->signal->it_real_incr);
+
+		return HRTIMER_RESTART;
+	}
+	return HRTIMER_NORESTART;
 }
 
 int do_setitimer(int which, struct itimerval *value, struct itimerval *ovalue)
 {
 	struct task_struct *tsk = current;
- 	unsigned long val, interval, expires;
+	struct hrtimer *timer;
+	ktime_t expires;
 	cputime_t cval, cinterval, nval, ninterval;
 
 	switch (which) {
 	case ITIMER_REAL:
-again:
-		spin_lock_irq(&tsk->sighand->siglock);
-		interval = tsk->signal->it_real_incr;
-		val = it_real_value(tsk->signal);
-		/* We are sharing ->siglock with it_real_fn() */
-		if (try_to_del_timer_sync(&tsk->signal->real_timer) < 0) {
-			spin_unlock_irq(&tsk->sighand->siglock);
-			goto again;
+		timer = &tsk->signal->real_timer;
+		hrtimer_cancel(timer);
+		if (ovalue) {
+			ovalue->it_value = itimer_get_remtime(timer);
+			ovalue->it_interval
+				= ktime_to_timeval(tsk->signal->it_real_incr);
 		}
 		tsk->signal->it_real_incr =
-			timeval_to_jiffies(&value->it_interval);
-		expires = timeval_to_jiffies(&value->it_value);
-		if (expires)
-			mod_timer(&tsk->signal->real_timer,
-				  jiffies + 1 + expires);
-		spin_unlock_irq(&tsk->sighand->siglock);
-		if (ovalue) {
-			jiffies_to_timeval(val, &ovalue->it_value);
-			jiffies_to_timeval(interval,
-					   &ovalue->it_interval);
-		}
+			timeval_to_ktime(value->it_interval);
+		expires = timeval_to_ktime(value->it_value);
+		if (expires.tv64 != 0)
+			hrtimer_start(timer, expires, HRTIMER_REL);
 		break;
 	case ITIMER_VIRTUAL:
 		nval = timeval_to_cputime(&value->it_value);
diff --git a/kernel/kexec.c b/kernel/kexec.c
index 2c95848..bf39d28 100644
--- a/kernel/kexec.c
+++ b/kernel/kexec.c
@@ -6,6 +6,7 @@
  * Version 2.  See the file COPYING for more details.
  */
 
+#include <linux/capability.h>
 #include <linux/mm.h>
 #include <linux/file.h>
 #include <linux/slab.h>
@@ -26,6 +27,9 @@
 #include <asm/system.h>
 #include <asm/semaphore.h>
 
+/* Per cpu memory for storing cpu states in case of system crash. */
+note_buf_t* crash_notes;
+
 /* Location of the reserved area for the crash kernel */
 struct resource crashk_res = {
 	.name  = "Crash kernel",
@@ -1054,9 +1058,24 @@
 	if (!locked) {
 		image = xchg(&kexec_crash_image, NULL);
 		if (image) {
-			machine_crash_shutdown(regs);
+			struct pt_regs fixed_regs;
+			crash_setup_regs(&fixed_regs, regs);
+			machine_crash_shutdown(&fixed_regs);
 			machine_kexec(image);
 		}
 		xchg(&kexec_lock, 0);
 	}
 }
+
+static int __init crash_notes_memory_init(void)
+{
+	/* Allocate memory for saving cpu registers. */
+	crash_notes = alloc_percpu(note_buf_t);
+	if (!crash_notes) {
+		printk("Kexec: Memory allocation for saving cpu register"
+		" states failed\n");
+		return -ENOMEM;
+	}
+	return 0;
+}
+module_init(crash_notes_memory_init)
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 3bb71e6..3ea6325 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -48,10 +48,11 @@
 static struct hlist_head kprobe_table[KPROBE_TABLE_SIZE];
 static struct hlist_head kretprobe_inst_table[KPROBE_TABLE_SIZE];
 
-static DEFINE_SPINLOCK(kprobe_lock);	/* Protects kprobe_table */
+DECLARE_MUTEX(kprobe_mutex);		/* Protects kprobe_table */
 DEFINE_SPINLOCK(kretprobe_lock);	/* Protects kretprobe_inst_table */
 static DEFINE_PER_CPU(struct kprobe *, kprobe_instance) = NULL;
 
+#ifdef __ARCH_WANT_KPROBES_INSN_SLOT
 /*
  * kprobe->ainsn.insn points to the copy of the instruction to be
  * single-stepped. x86_64, POWER4 and above have no-exec support and
@@ -151,6 +152,7 @@
 		}
 	}
 }
+#endif
 
 /* We have preemption disabled.. so it is safe to use __ versions */
 static inline void set_kprobe_instance(struct kprobe *kp)
@@ -165,7 +167,7 @@
 
 /*
  * This routine is called either:
- * 	- under the kprobe_lock spinlock - during kprobe_[un]register()
+ * 	- under the kprobe_mutex - during kprobe_[un]register()
  * 				OR
  * 	- with preemption disabled - from arch/xxx/kernel/kprobes.c
  */
@@ -418,7 +420,6 @@
 /*
  * This is the second or subsequent kprobe at the address - handle
  * the intricacies
- * TODO: Move kcalloc outside the spin_lock
  */
 static int __kprobes register_aggr_kprobe(struct kprobe *old_p,
 					  struct kprobe *p)
@@ -430,7 +431,7 @@
 		copy_kprobe(old_p, p);
 		ret = add_new_kprobe(old_p, p);
 	} else {
-		ap = kcalloc(1, sizeof(struct kprobe), GFP_ATOMIC);
+		ap = kzalloc(sizeof(struct kprobe), GFP_KERNEL);
 		if (!ap)
 			return -ENOMEM;
 		add_aggr_kprobe(ap, old_p);
@@ -440,25 +441,6 @@
 	return ret;
 }
 
-/* kprobe removal house-keeping routines */
-static inline void cleanup_kprobe(struct kprobe *p, unsigned long flags)
-{
-	arch_disarm_kprobe(p);
-	hlist_del_rcu(&p->hlist);
-	spin_unlock_irqrestore(&kprobe_lock, flags);
-	arch_remove_kprobe(p);
-}
-
-static inline void cleanup_aggr_kprobe(struct kprobe *old_p,
-		struct kprobe *p, unsigned long flags)
-{
-	list_del_rcu(&p->list);
-	if (list_empty(&old_p->list))
-		cleanup_kprobe(old_p, flags);
-	else
-		spin_unlock_irqrestore(&kprobe_lock, flags);
-}
-
 static int __kprobes in_kprobes_functions(unsigned long addr)
 {
 	if (addr >= (unsigned long)__kprobes_text_start
@@ -467,33 +449,44 @@
 	return 0;
 }
 
-int __kprobes register_kprobe(struct kprobe *p)
+static int __kprobes __register_kprobe(struct kprobe *p,
+	unsigned long called_from)
 {
 	int ret = 0;
-	unsigned long flags = 0;
 	struct kprobe *old_p;
-	struct module *mod;
+	struct module *probed_mod;
 
 	if ((!kernel_text_address((unsigned long) p->addr)) ||
 		in_kprobes_functions((unsigned long) p->addr))
 		return -EINVAL;
 
-	if ((mod = module_text_address((unsigned long) p->addr)) &&
-			(unlikely(!try_module_get(mod))))
-		return -EINVAL;
-
-	if ((ret = arch_prepare_kprobe(p)) != 0)
-		goto rm_kprobe;
+	p->mod_refcounted = 0;
+	/* Check are we probing a module */
+	if ((probed_mod = module_text_address((unsigned long) p->addr))) {
+		struct module *calling_mod = module_text_address(called_from);
+		/* We must allow modules to probe themself and
+		 * in this case avoid incrementing the module refcount,
+		 * so as to allow unloading of self probing modules.
+		 */
+		if (calling_mod && (calling_mod != probed_mod)) {
+			if (unlikely(!try_module_get(probed_mod)))
+				return -EINVAL;
+			p->mod_refcounted = 1;
+		} else
+			probed_mod = NULL;
+	}
 
 	p->nmissed = 0;
-	spin_lock_irqsave(&kprobe_lock, flags);
+	down(&kprobe_mutex);
 	old_p = get_kprobe(p->addr);
 	if (old_p) {
 		ret = register_aggr_kprobe(old_p, p);
 		goto out;
 	}
 
-	arch_copy_kprobe(p);
+	if ((ret = arch_prepare_kprobe(p)) != 0)
+		goto out;
+
 	INIT_HLIST_NODE(&p->hlist);
 	hlist_add_head_rcu(&p->hlist,
 		       &kprobe_table[hash_ptr(p->addr, KPROBE_HASH_BITS)]);
@@ -501,40 +494,66 @@
   	arch_arm_kprobe(p);
 
 out:
-	spin_unlock_irqrestore(&kprobe_lock, flags);
-rm_kprobe:
-	if (ret == -EEXIST)
-		arch_remove_kprobe(p);
-	if (ret && mod)
-		module_put(mod);
+	up(&kprobe_mutex);
+
+	if (ret && probed_mod)
+		module_put(probed_mod);
 	return ret;
 }
 
+int __kprobes register_kprobe(struct kprobe *p)
+{
+	return __register_kprobe(p,
+		(unsigned long)__builtin_return_address(0));
+}
+
 void __kprobes unregister_kprobe(struct kprobe *p)
 {
-	unsigned long flags;
-	struct kprobe *old_p;
 	struct module *mod;
+	struct kprobe *old_p, *list_p;
+	int cleanup_p;
 
-	spin_lock_irqsave(&kprobe_lock, flags);
+	down(&kprobe_mutex);
 	old_p = get_kprobe(p->addr);
-	if (old_p) {
-		/* cleanup_*_kprobe() does the spin_unlock_irqrestore */
-		if (old_p->pre_handler == aggr_pre_handler)
-			cleanup_aggr_kprobe(old_p, p, flags);
-		else
-			cleanup_kprobe(p, flags);
+	if (unlikely(!old_p)) {
+		up(&kprobe_mutex);
+		return;
+	}
+	if (p != old_p) {
+		list_for_each_entry_rcu(list_p, &old_p->list, list)
+			if (list_p == p)
+			/* kprobe p is a valid probe */
+				goto valid_p;
+		up(&kprobe_mutex);
+		return;
+	}
+valid_p:
+	if ((old_p == p) || ((old_p->pre_handler == aggr_pre_handler) &&
+		(p->list.next == &old_p->list) &&
+		(p->list.prev == &old_p->list))) {
+		/* Only probe on the hash list */
+		arch_disarm_kprobe(p);
+		hlist_del_rcu(&old_p->hlist);
+		cleanup_p = 1;
+	} else {
+		list_del_rcu(&p->list);
+		cleanup_p = 0;
+	}
 
-		synchronize_sched();
+	up(&kprobe_mutex);
 
-		if ((mod = module_text_address((unsigned long)p->addr)))
-			module_put(mod);
+	synchronize_sched();
+	if (p->mod_refcounted &&
+	    (mod = module_text_address((unsigned long)p->addr)))
+		module_put(mod);
 
-		if (old_p->pre_handler == aggr_pre_handler &&
-				list_empty(&old_p->list))
+	if (cleanup_p) {
+		if (p != old_p) {
+			list_del_rcu(&p->list);
 			kfree(old_p);
-	} else
-		spin_unlock_irqrestore(&kprobe_lock, flags);
+		}
+		arch_remove_kprobe(p);
+	}
 }
 
 static struct notifier_block kprobe_exceptions_nb = {
@@ -548,7 +567,8 @@
 	jp->kp.pre_handler = setjmp_pre_handler;
 	jp->kp.break_handler = longjmp_break_handler;
 
-	return register_kprobe(&jp->kp);
+	return __register_kprobe(&jp->kp,
+		(unsigned long)__builtin_return_address(0));
 }
 
 void __kprobes unregister_jprobe(struct jprobe *jp)
@@ -588,7 +608,8 @@
 
 	rp->nmissed = 0;
 	/* Establish function entry probe point */
-	if ((ret = register_kprobe(&rp->kp)) != 0)
+	if ((ret = __register_kprobe(&rp->kp,
+		(unsigned long)__builtin_return_address(0))) != 0)
 		free_rp_inst(rp);
 	return ret;
 }
diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
index 99af8b0..d5eeae0 100644
--- a/kernel/ksysfs.c
+++ b/kernel/ksysfs.c
@@ -51,16 +51,6 @@
 KERNEL_ATTR_RW(uevent_helper);
 #endif
 
-#ifdef CONFIG_KEXEC
-#include <asm/kexec.h>
-
-static ssize_t crash_notes_show(struct subsystem *subsys, char *page)
-{
-	return sprintf(page, "%p\n", (void *)crash_notes);
-}
-KERNEL_ATTR_RO(crash_notes);
-#endif
-
 decl_subsys(kernel, NULL, NULL);
 EXPORT_SYMBOL_GPL(kernel_subsys);
 
@@ -69,9 +59,6 @@
 	&uevent_seqnum_attr.attr,
 	&uevent_helper_attr.attr,
 #endif
-#ifdef CONFIG_KEXEC
-	&crash_notes_attr.attr,
-#endif
 	NULL
 };
 
diff --git a/kernel/module.c b/kernel/module.c
index e427604..618ed6e 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -28,6 +28,7 @@
 #include <linux/syscalls.h>
 #include <linux/fcntl.h>
 #include <linux/rcupdate.h>
+#include <linux/capability.h>
 #include <linux/cpu.h>
 #include <linux/moduleparam.h>
 #include <linux/errno.h>
diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
index 4fcb051..f4913c3 100644
--- a/kernel/mutex-debug.c
+++ b/kernel/mutex-debug.c
@@ -20,8 +20,6 @@
 #include <linux/kallsyms.h>
 #include <linux/interrupt.h>
 
-#include <asm/mutex.h>
-
 #include "mutex-debug.h"
 
 /*
@@ -335,9 +333,10 @@
  * is destroyed or reinitialized - this code checks whether there is
  * any held lock in the memory range of <from> to <to>:
  */
-void mutex_debug_check_no_locks_freed(const void *from, const void *to)
+void mutex_debug_check_no_locks_freed(const void *from, unsigned long len)
 {
 	struct list_head *curr, *next;
+	const void *to = from + len;
 	unsigned long flags;
 	struct mutex *lock;
 	void *lock_addr;
@@ -439,7 +438,7 @@
 	/*
 	 * Make sure we are not reinitializing a held lock:
 	 */
-	mutex_debug_check_no_locks_freed((void *)lock, (void *)(lock + 1));
+	mutex_debug_check_no_locks_freed((void *)lock, sizeof(*lock));
 	lock->owner = NULL;
 	INIT_LIST_HEAD(&lock->held_list);
 	lock->name = name;
@@ -461,4 +460,3 @@
 }
 
 EXPORT_SYMBOL_GPL(mutex_destroy);
-
diff --git a/kernel/mutex.c b/kernel/mutex.c
index 7eb9606..5449b21 100644
--- a/kernel/mutex.c
+++ b/kernel/mutex.c
@@ -81,15 +81,10 @@
  */
 void fastcall __sched mutex_lock(struct mutex *lock)
 {
+	might_sleep();
 	/*
 	 * The locking fastpath is the 1->0 transition from
 	 * 'unlocked' into 'locked' state.
-	 *
-	 * NOTE: if asm/mutex.h is included, then some architectures
-	 * rely on mutex_lock() having _no other code_ here but this
-	 * fastpath. That allows the assembly fastpath to do
-	 * tail-merging optimizations. (If you want to put testcode
-	 * here, do it under #ifndef CONFIG_MUTEX_DEBUG.)
 	 */
 	__mutex_fastpath_lock(&lock->count, __mutex_lock_slowpath);
 }
@@ -115,8 +110,6 @@
 	/*
 	 * The unlocking fastpath is the 0->1 transition from 'locked'
 	 * into 'unlocked' state:
-	 *
-	 * NOTE: no other code must be here - see mutex_lock() .
 	 */
 	__mutex_fastpath_unlock(&lock->count, __mutex_unlock_slowpath);
 }
@@ -209,7 +202,7 @@
 static fastcall noinline void
 __mutex_unlock_slowpath(atomic_t *lock_count __IP_DECL__)
 {
-        struct mutex *lock = container_of(lock_count, struct mutex, count);
+	struct mutex *lock = container_of(lock_count, struct mutex, count);
 
 	DEBUG_WARN_ON(lock->owner != current_thread_info());
 
@@ -261,7 +254,7 @@
  */
 int fastcall __sched mutex_lock_interruptible(struct mutex *lock)
 {
-	/* NOTE: no other code must be here - see mutex_lock() */
+	might_sleep();
 	return __mutex_fastpath_lock_retval
 			(&lock->count, __mutex_lock_interruptible_slowpath);
 }
@@ -320,6 +313,3 @@
 }
 
 EXPORT_SYMBOL(mutex_trylock);
-
-
-
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
index 4c68edf..520f6c5 100644
--- a/kernel/posix-cpu-timers.c
+++ b/kernel/posix-cpu-timers.c
@@ -7,7 +7,7 @@
 #include <asm/uaccess.h>
 #include <linux/errno.h>
 
-static int check_clock(clockid_t which_clock)
+static int check_clock(const clockid_t which_clock)
 {
 	int error = 0;
 	struct task_struct *p;
@@ -31,7 +31,7 @@
 }
 
 static inline union cpu_time_count
-timespec_to_sample(clockid_t which_clock, const struct timespec *tp)
+timespec_to_sample(const clockid_t which_clock, const struct timespec *tp)
 {
 	union cpu_time_count ret;
 	ret.sched = 0;		/* high half always zero when .cpu used */
@@ -43,7 +43,7 @@
 	return ret;
 }
 
-static void sample_to_timespec(clockid_t which_clock,
+static void sample_to_timespec(const clockid_t which_clock,
 			       union cpu_time_count cpu,
 			       struct timespec *tp)
 {
@@ -55,7 +55,7 @@
 	}
 }
 
-static inline int cpu_time_before(clockid_t which_clock,
+static inline int cpu_time_before(const clockid_t which_clock,
 				  union cpu_time_count now,
 				  union cpu_time_count then)
 {
@@ -65,7 +65,7 @@
 		return cputime_lt(now.cpu, then.cpu);
 	}
 }
-static inline void cpu_time_add(clockid_t which_clock,
+static inline void cpu_time_add(const clockid_t which_clock,
 				union cpu_time_count *acc,
 			        union cpu_time_count val)
 {
@@ -75,7 +75,7 @@
 		acc->cpu = cputime_add(acc->cpu, val.cpu);
 	}
 }
-static inline union cpu_time_count cpu_time_sub(clockid_t which_clock,
+static inline union cpu_time_count cpu_time_sub(const clockid_t which_clock,
 						union cpu_time_count a,
 						union cpu_time_count b)
 {
@@ -151,7 +151,7 @@
 	return (p == current) ? current_sched_time(p) : p->sched_time;
 }
 
-int posix_cpu_clock_getres(clockid_t which_clock, struct timespec *tp)
+int posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *tp)
 {
 	int error = check_clock(which_clock);
 	if (!error) {
@@ -169,7 +169,7 @@
 	return error;
 }
 
-int posix_cpu_clock_set(clockid_t which_clock, const struct timespec *tp)
+int posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *tp)
 {
 	/*
 	 * You can never reset a CPU clock, but we check for other errors
@@ -186,7 +186,7 @@
 /*
  * Sample a per-thread clock for the given task.
  */
-static int cpu_clock_sample(clockid_t which_clock, struct task_struct *p,
+static int cpu_clock_sample(const clockid_t which_clock, struct task_struct *p,
 			    union cpu_time_count *cpu)
 {
 	switch (CPUCLOCK_WHICH(which_clock)) {
@@ -248,7 +248,7 @@
  * Sample a process (thread group) clock for the given group_leader task.
  * Must be called with tasklist_lock held for reading.
  */
-static int cpu_clock_sample_group(clockid_t which_clock,
+static int cpu_clock_sample_group(const clockid_t which_clock,
 				  struct task_struct *p,
 				  union cpu_time_count *cpu)
 {
@@ -262,7 +262,7 @@
 }
 
 
-int posix_cpu_clock_get(clockid_t which_clock, struct timespec *tp)
+int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *tp)
 {
 	const pid_t pid = CPUCLOCK_PID(which_clock);
 	int error = -EINVAL;
@@ -1399,8 +1399,8 @@
 
 static long posix_cpu_clock_nanosleep_restart(struct restart_block *);
 
-int posix_cpu_nsleep(clockid_t which_clock, int flags,
-		     struct timespec *rqtp)
+int posix_cpu_nsleep(const clockid_t which_clock, int flags,
+		     struct timespec *rqtp, struct timespec __user *rmtp)
 {
 	struct restart_block *restart_block =
 	    &current_thread_info()->restart_block;
@@ -1425,7 +1425,6 @@
 	error = posix_cpu_timer_create(&timer);
 	timer.it_process = current;
 	if (!error) {
-		struct timespec __user *rmtp;
 		static struct itimerspec zero_it;
 		struct itimerspec it = { .it_value = *rqtp,
 					 .it_interval = {} };
@@ -1472,7 +1471,6 @@
 		/*
 		 * Report back to the user the time still remaining.
 		 */
-		rmtp = (struct timespec __user *) restart_block->arg1;
 		if (rmtp != NULL && !(flags & TIMER_ABSTIME) &&
 		    copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
 			return -EFAULT;
@@ -1480,6 +1478,7 @@
 		restart_block->fn = posix_cpu_clock_nanosleep_restart;
 		/* Caller already set restart_block->arg1 */
 		restart_block->arg0 = which_clock;
+		restart_block->arg1 = (unsigned long) rmtp;
 		restart_block->arg2 = rqtp->tv_sec;
 		restart_block->arg3 = rqtp->tv_nsec;
 
@@ -1493,21 +1492,28 @@
 posix_cpu_clock_nanosleep_restart(struct restart_block *restart_block)
 {
 	clockid_t which_clock = restart_block->arg0;
-	struct timespec t = { .tv_sec = restart_block->arg2,
-			      .tv_nsec = restart_block->arg3 };
+	struct timespec __user *rmtp;
+	struct timespec t;
+
+	rmtp = (struct timespec __user *) restart_block->arg1;
+	t.tv_sec = restart_block->arg2;
+	t.tv_nsec = restart_block->arg3;
+
 	restart_block->fn = do_no_restart_syscall;
-	return posix_cpu_nsleep(which_clock, TIMER_ABSTIME, &t);
+	return posix_cpu_nsleep(which_clock, TIMER_ABSTIME, &t, rmtp);
 }
 
 
 #define PROCESS_CLOCK	MAKE_PROCESS_CPUCLOCK(0, CPUCLOCK_SCHED)
 #define THREAD_CLOCK	MAKE_THREAD_CPUCLOCK(0, CPUCLOCK_SCHED)
 
-static int process_cpu_clock_getres(clockid_t which_clock, struct timespec *tp)
+static int process_cpu_clock_getres(const clockid_t which_clock,
+				    struct timespec *tp)
 {
 	return posix_cpu_clock_getres(PROCESS_CLOCK, tp);
 }
-static int process_cpu_clock_get(clockid_t which_clock, struct timespec *tp)
+static int process_cpu_clock_get(const clockid_t which_clock,
+				 struct timespec *tp)
 {
 	return posix_cpu_clock_get(PROCESS_CLOCK, tp);
 }
@@ -1516,16 +1522,19 @@
 	timer->it_clock = PROCESS_CLOCK;
 	return posix_cpu_timer_create(timer);
 }
-static int process_cpu_nsleep(clockid_t which_clock, int flags,
-			      struct timespec *rqtp)
+static int process_cpu_nsleep(const clockid_t which_clock, int flags,
+			      struct timespec *rqtp,
+			      struct timespec __user *rmtp)
 {
-	return posix_cpu_nsleep(PROCESS_CLOCK, flags, rqtp);
+	return posix_cpu_nsleep(PROCESS_CLOCK, flags, rqtp, rmtp);
 }
-static int thread_cpu_clock_getres(clockid_t which_clock, struct timespec *tp)
+static int thread_cpu_clock_getres(const clockid_t which_clock,
+				   struct timespec *tp)
 {
 	return posix_cpu_clock_getres(THREAD_CLOCK, tp);
 }
-static int thread_cpu_clock_get(clockid_t which_clock, struct timespec *tp)
+static int thread_cpu_clock_get(const clockid_t which_clock,
+				struct timespec *tp)
 {
 	return posix_cpu_clock_get(THREAD_CLOCK, tp);
 }
@@ -1534,8 +1543,8 @@
 	timer->it_clock = THREAD_CLOCK;
 	return posix_cpu_timer_create(timer);
 }
-static int thread_cpu_nsleep(clockid_t which_clock, int flags,
-			      struct timespec *rqtp)
+static int thread_cpu_nsleep(const clockid_t which_clock, int flags,
+			      struct timespec *rqtp, struct timespec __user *rmtp)
 {
 	return -EINVAL;
 }
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index 5870efb..9e66e61 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -48,21 +48,6 @@
 #include <linux/workqueue.h>
 #include <linux/module.h>
 
-#ifndef div_long_long_rem
-#include <asm/div64.h>
-
-#define div_long_long_rem(dividend,divisor,remainder) ({ \
-		       u64 result = dividend;		\
-		       *remainder = do_div(result,divisor); \
-		       result; })
-
-#endif
-#define CLOCK_REALTIME_RES TICK_NSEC  /* In nano seconds. */
-
-static inline u64  mpy_l_X_l_ll(unsigned long mpy1,unsigned long mpy2)
-{
-	return (u64)mpy1 * mpy2;
-}
 /*
  * Management arrays for POSIX timers.	 Timers are kept in slab memory
  * Timer ids are allocated by an external routine that keeps track of the
@@ -148,18 +133,18 @@
  */
 
 static struct k_clock posix_clocks[MAX_CLOCKS];
-/*
- * We only have one real clock that can be set so we need only one abs list,
- * even if we should want to have several clocks with differing resolutions.
- */
-static struct k_clock_abs abs_list = {.list = LIST_HEAD_INIT(abs_list.list),
-				      .lock = SPIN_LOCK_UNLOCKED};
 
-static void posix_timer_fn(unsigned long);
-static u64 do_posix_clock_monotonic_gettime_parts(
-	struct timespec *tp, struct timespec *mo);
-int do_posix_clock_monotonic_gettime(struct timespec *tp);
-static int do_posix_clock_monotonic_get(clockid_t, struct timespec *tp);
+/*
+ * These ones are defined below.
+ */
+static int common_nsleep(const clockid_t, int flags, struct timespec *t,
+			 struct timespec __user *rmtp);
+static void common_timer_get(struct k_itimer *, struct itimerspec *);
+static int common_timer_set(struct k_itimer *, int,
+			    struct itimerspec *, struct itimerspec *);
+static int common_timer_del(struct k_itimer *timer);
+
+static int posix_timer_fn(void *data);
 
 static struct k_itimer *lock_timer(timer_t timer_id, unsigned long *flags);
 
@@ -184,7 +169,7 @@
  * the function pointer CALL in struct k_clock.
  */
 
-static inline int common_clock_getres(clockid_t which_clock,
+static inline int common_clock_getres(const clockid_t which_clock,
 				      struct timespec *tp)
 {
 	tp->tv_sec = 0;
@@ -192,39 +177,33 @@
 	return 0;
 }
 
-static inline int common_clock_get(clockid_t which_clock, struct timespec *tp)
+/*
+ * Get real time for posix timers
+ */
+static int common_clock_get(clockid_t which_clock, struct timespec *tp)
 {
-	getnstimeofday(tp);
+	ktime_get_real_ts(tp);
 	return 0;
 }
 
-static inline int common_clock_set(clockid_t which_clock, struct timespec *tp)
+static inline int common_clock_set(const clockid_t which_clock,
+				   struct timespec *tp)
 {
 	return do_sys_settimeofday(tp, NULL);
 }
 
 static inline int common_timer_create(struct k_itimer *new_timer)
 {
-	INIT_LIST_HEAD(&new_timer->it.real.abs_timer_entry);
-	init_timer(&new_timer->it.real.timer);
-	new_timer->it.real.timer.data = (unsigned long) new_timer;
+	hrtimer_init(&new_timer->it.real.timer, new_timer->it_clock);
+	new_timer->it.real.timer.data = new_timer;
 	new_timer->it.real.timer.function = posix_timer_fn;
 	return 0;
 }
 
 /*
- * These ones are defined below.
+ * Return nonzero if we know a priori this clockid_t value is bogus.
  */
-static int common_nsleep(clockid_t, int flags, struct timespec *t);
-static void common_timer_get(struct k_itimer *, struct itimerspec *);
-static int common_timer_set(struct k_itimer *, int,
-			    struct itimerspec *, struct itimerspec *);
-static int common_timer_del(struct k_itimer *timer);
-
-/*
- * Return nonzero iff we know a priori this clockid_t value is bogus.
- */
-static inline int invalid_clockid(clockid_t which_clock)
+static inline int invalid_clockid(const clockid_t which_clock)
 {
 	if (which_clock < 0)	/* CPU clock, posix_cpu_* will check it */
 		return 0;
@@ -232,26 +211,32 @@
 		return 1;
 	if (posix_clocks[which_clock].clock_getres != NULL)
 		return 0;
-#ifndef CLOCK_DISPATCH_DIRECT
 	if (posix_clocks[which_clock].res != 0)
 		return 0;
-#endif
 	return 1;
 }
 
+/*
+ * Get monotonic time for posix timers
+ */
+static int posix_ktime_get_ts(clockid_t which_clock, struct timespec *tp)
+{
+	ktime_get_ts(tp);
+	return 0;
+}
 
 /*
  * Initialize everything, well, just everything in Posix clocks/timers ;)
  */
 static __init int init_posix_timers(void)
 {
-	struct k_clock clock_realtime = {.res = CLOCK_REALTIME_RES,
-					 .abs_struct = &abs_list
+	struct k_clock clock_realtime = {
+		.clock_getres = hrtimer_get_res,
 	};
-	struct k_clock clock_monotonic = {.res = CLOCK_REALTIME_RES,
-		.abs_struct = NULL,
-		.clock_get = do_posix_clock_monotonic_get,
-		.clock_set = do_posix_clock_nosettime
+	struct k_clock clock_monotonic = {
+		.clock_getres = hrtimer_get_res,
+		.clock_get = posix_ktime_get_ts,
+		.clock_set = do_posix_clock_nosettime,
 	};
 
 	register_posix_clock(CLOCK_REALTIME, &clock_realtime);
@@ -265,117 +250,17 @@
 
 __initcall(init_posix_timers);
 
-static void tstojiffie(struct timespec *tp, int res, u64 *jiff)
-{
-	long sec = tp->tv_sec;
-	long nsec = tp->tv_nsec + res - 1;
-
-	if (nsec >= NSEC_PER_SEC) {
-		sec++;
-		nsec -= NSEC_PER_SEC;
-	}
-
-	/*
-	 * The scaling constants are defined in <linux/time.h>
-	 * The difference between there and here is that we do the
-	 * res rounding and compute a 64-bit result (well so does that
-	 * but it then throws away the high bits).
-  	 */
-	*jiff =  (mpy_l_X_l_ll(sec, SEC_CONVERSION) +
-		  (mpy_l_X_l_ll(nsec, NSEC_CONVERSION) >> 
-		   (NSEC_JIFFIE_SC - SEC_JIFFIE_SC))) >> SEC_JIFFIE_SC;
-}
-
-/*
- * This function adjusts the timer as needed as a result of the clock
- * being set.  It should only be called for absolute timers, and then
- * under the abs_list lock.  It computes the time difference and sets
- * the new jiffies value in the timer.  It also updates the timers
- * reference wall_to_monotonic value.  It is complicated by the fact
- * that tstojiffies() only handles positive times and it needs to work
- * with both positive and negative times.  Also, for negative offsets,
- * we need to defeat the res round up.
- *
- * Return is true if there is a new time, else false.
- */
-static long add_clockset_delta(struct k_itimer *timr,
-			       struct timespec *new_wall_to)
-{
-	struct timespec delta;
-	int sign = 0;
-	u64 exp;
-
-	set_normalized_timespec(&delta,
-				new_wall_to->tv_sec -
-				timr->it.real.wall_to_prev.tv_sec,
-				new_wall_to->tv_nsec -
-				timr->it.real.wall_to_prev.tv_nsec);
-	if (likely(!(delta.tv_sec | delta.tv_nsec)))
-		return 0;
-	if (delta.tv_sec < 0) {
-		set_normalized_timespec(&delta,
-					-delta.tv_sec,
-					1 - delta.tv_nsec -
-					posix_clocks[timr->it_clock].res);
-		sign++;
-	}
-	tstojiffie(&delta, posix_clocks[timr->it_clock].res, &exp);
-	timr->it.real.wall_to_prev = *new_wall_to;
-	timr->it.real.timer.expires += (sign ? -exp : exp);
-	return 1;
-}
-
-static void remove_from_abslist(struct k_itimer *timr)
-{
-	if (!list_empty(&timr->it.real.abs_timer_entry)) {
-		spin_lock(&abs_list.lock);
-		list_del_init(&timr->it.real.abs_timer_entry);
-		spin_unlock(&abs_list.lock);
-	}
-}
-
 static void schedule_next_timer(struct k_itimer *timr)
 {
-	struct timespec new_wall_to;
-	struct now_struct now;
-	unsigned long seq;
-
-	/*
-	 * Set up the timer for the next interval (if there is one).
-	 * Note: this code uses the abs_timer_lock to protect
-	 * it.real.wall_to_prev and must hold it until exp is set, not exactly
-	 * obvious...
-
-	 * This function is used for CLOCK_REALTIME* and
-	 * CLOCK_MONOTONIC* timers.  If we ever want to handle other
-	 * CLOCKs, the calling code (do_schedule_next_timer) would need
-	 * to pull the "clock" info from the timer and dispatch the
-	 * "other" CLOCKs "next timer" code (which, I suppose should
-	 * also be added to the k_clock structure).
-	 */
-	if (!timr->it.real.incr)
+	if (timr->it.real.interval.tv64 == 0)
 		return;
 
-	do {
-		seq = read_seqbegin(&xtime_lock);
-		new_wall_to =	wall_to_monotonic;
-		posix_get_now(&now);
-	} while (read_seqretry(&xtime_lock, seq));
-
-	if (!list_empty(&timr->it.real.abs_timer_entry)) {
-		spin_lock(&abs_list.lock);
-		add_clockset_delta(timr, &new_wall_to);
-
-		posix_bump_timer(timr, now);
-
-		spin_unlock(&abs_list.lock);
-	} else {
-		posix_bump_timer(timr, now);
-	}
+	timr->it_overrun += hrtimer_forward(&timr->it.real.timer,
+					    timr->it.real.interval);
 	timr->it_overrun_last = timr->it_overrun;
 	timr->it_overrun = -1;
 	++timr->it_requeue_pending;
-	add_timer(&timr->it.real.timer);
+	hrtimer_restart(&timr->it.real.timer);
 }
 
 /*
@@ -396,31 +281,23 @@
 
 	timr = lock_timer(info->si_tid, &flags);
 
-	if (!timr || timr->it_requeue_pending != info->si_sys_private)
-		goto exit;
+	if (timr && timr->it_requeue_pending == info->si_sys_private) {
+		if (timr->it_clock < 0)
+			posix_cpu_timer_schedule(timr);
+		else
+			schedule_next_timer(timr);
 
-	if (timr->it_clock < 0)	/* CPU clock */
-		posix_cpu_timer_schedule(timr);
-	else
-		schedule_next_timer(timr);
-	info->si_overrun = timr->it_overrun_last;
-exit:
-	if (timr)
-		unlock_timer(timr, flags);
+		info->si_overrun = timr->it_overrun_last;
+	}
+
+	unlock_timer(timr, flags);
 }
 
 int posix_timer_event(struct k_itimer *timr,int si_private)
 {
 	memset(&timr->sigq->info, 0, sizeof(siginfo_t));
 	timr->sigq->info.si_sys_private = si_private;
-	/*
-	 * Send signal to the process that owns this timer.
-
-	 * This code assumes that all the possible abs_lists share the
-	 * same lock (there is only one list at this time). If this is
-	 * not the case, the CLOCK info would need to be used to find
-	 * the proper abs list lock.
-	 */
+	/* Send signal to the process that owns this timer.*/
 
 	timr->sigq->info.si_signo = timr->it_sigev_signo;
 	timr->sigq->info.si_errno = 0;
@@ -454,65 +331,36 @@
 
  * This code is for CLOCK_REALTIME* and CLOCK_MONOTONIC* timers.
  */
-static void posix_timer_fn(unsigned long __data)
+static int posix_timer_fn(void *data)
 {
-	struct k_itimer *timr = (struct k_itimer *) __data;
+	struct k_itimer *timr = data;
 	unsigned long flags;
-	unsigned long seq;
-	struct timespec delta, new_wall_to;
-	u64 exp = 0;
-	int do_notify = 1;
+	int si_private = 0;
+	int ret = HRTIMER_NORESTART;
 
 	spin_lock_irqsave(&timr->it_lock, flags);
-	if (!list_empty(&timr->it.real.abs_timer_entry)) {
-		spin_lock(&abs_list.lock);
-		do {
-			seq = read_seqbegin(&xtime_lock);
-			new_wall_to =	wall_to_monotonic;
-		} while (read_seqretry(&xtime_lock, seq));
-		set_normalized_timespec(&delta,
-					new_wall_to.tv_sec -
-					timr->it.real.wall_to_prev.tv_sec,
-					new_wall_to.tv_nsec -
-					timr->it.real.wall_to_prev.tv_nsec);
-		if (likely((delta.tv_sec | delta.tv_nsec ) == 0)) {
-			/* do nothing, timer is on time */
-		} else if (delta.tv_sec < 0) {
-			/* do nothing, timer is already late */
-		} else {
-			/* timer is early due to a clock set */
-			tstojiffie(&delta,
-				   posix_clocks[timr->it_clock].res,
-				   &exp);
-			timr->it.real.wall_to_prev = new_wall_to;
-			timr->it.real.timer.expires += exp;
-			add_timer(&timr->it.real.timer);
-			do_notify = 0;
+
+	if (timr->it.real.interval.tv64 != 0)
+		si_private = ++timr->it_requeue_pending;
+
+	if (posix_timer_event(timr, si_private)) {
+		/*
+		 * signal was not sent because of sig_ignor
+		 * we will not get a call back to restart it AND
+		 * it should be restarted.
+		 */
+		if (timr->it.real.interval.tv64 != 0) {
+			timr->it_overrun +=
+				hrtimer_forward(&timr->it.real.timer,
+						timr->it.real.interval);
+			ret = HRTIMER_RESTART;
 		}
-		spin_unlock(&abs_list.lock);
-
 	}
-	if (do_notify)  {
-		int si_private=0;
 
-		if (timr->it.real.incr)
-			si_private = ++timr->it_requeue_pending;
-		else {
-			remove_from_abslist(timr);
-		}
-
-		if (posix_timer_event(timr, si_private))
-			/*
-			 * signal was not sent because of sig_ignor
-			 * we will not get a call back to restart it AND
-			 * it should be restarted.
-			 */
-			schedule_next_timer(timr);
-	}
-	unlock_timer(timr, flags); /* hold thru abs lock to keep irq off */
+	unlock_timer(timr, flags);
+	return ret;
 }
 
-
 static inline struct task_struct * good_sigevent(sigevent_t * event)
 {
 	struct task_struct *rtn = current->group_leader;
@@ -530,7 +378,7 @@
 	return rtn;
 }
 
-void register_posix_clock(clockid_t clock_id, struct k_clock *new_clock)
+void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock)
 {
 	if ((unsigned) clock_id >= MAX_CLOCKS) {
 		printk("POSIX clock register failed for clock_id %d\n",
@@ -576,7 +424,7 @@
 /* Create a POSIX.1b interval timer. */
 
 asmlinkage long
-sys_timer_create(clockid_t which_clock,
+sys_timer_create(const clockid_t which_clock,
 		 struct sigevent __user *timer_event_spec,
 		 timer_t __user * created_timer_id)
 {
@@ -602,8 +450,7 @@
 		goto out;
 	}
 	spin_lock_irq(&idr_lock);
-	error = idr_get_new(&posix_timers_id,
-			    (void *) new_timer,
+	error = idr_get_new(&posix_timers_id, (void *) new_timer,
 			    &new_timer_id);
 	spin_unlock_irq(&idr_lock);
 	if (error == -EAGAIN)
@@ -704,27 +551,6 @@
 }
 
 /*
- * good_timespec
- *
- * This function checks the elements of a timespec structure.
- *
- * Arguments:
- * ts	     : Pointer to the timespec structure to check
- *
- * Return value:
- * If a NULL pointer was passed in, or the tv_nsec field was less than 0
- * or greater than NSEC_PER_SEC, or the tv_sec field was less than 0,
- * this function returns 0. Otherwise it returns 1.
- */
-static int good_timespec(const struct timespec *ts)
-{
-	if ((!ts) || (ts->tv_sec < 0) ||
-			((unsigned) ts->tv_nsec >= NSEC_PER_SEC))
-		return 0;
-	return 1;
-}
-
-/*
  * Locking issues: We need to protect the result of the id look up until
  * we get the timer locked down so it is not deleted under us.  The
  * removal is done under the idr spinlock so we use that here to bridge
@@ -776,39 +602,39 @@
 static void
 common_timer_get(struct k_itimer *timr, struct itimerspec *cur_setting)
 {
-	unsigned long expires;
-	struct now_struct now;
+	ktime_t remaining;
+	struct hrtimer *timer = &timr->it.real.timer;
 
-	do
-		expires = timr->it.real.timer.expires;
-	while ((volatile long) (timr->it.real.timer.expires) != expires);
+	memset(cur_setting, 0, sizeof(struct itimerspec));
+	remaining = hrtimer_get_remaining(timer);
 
-	posix_get_now(&now);
-
-	if (expires &&
-	    ((timr->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE) &&
-	    !timr->it.real.incr &&
-	    posix_time_before(&timr->it.real.timer, &now))
-		timr->it.real.timer.expires = expires = 0;
-	if (expires) {
-		if (timr->it_requeue_pending & REQUEUE_PENDING ||
-		    (timr->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE) {
-			posix_bump_timer(timr, now);
-			expires = timr->it.real.timer.expires;
-		}
-		else
-			if (!timer_pending(&timr->it.real.timer))
-				expires = 0;
-		if (expires)
-			expires -= now.jiffies;
+	/* Time left ? or timer pending */
+	if (remaining.tv64 > 0 || hrtimer_active(timer))
+		goto calci;
+	/* interval timer ? */
+	if (timr->it.real.interval.tv64 == 0)
+		return;
+	/*
+	 * When a requeue is pending or this is a SIGEV_NONE timer
+	 * move the expiry time forward by intervals, so expiry is >
+	 * now.
+	 */
+	if (timr->it_requeue_pending & REQUEUE_PENDING ||
+	    (timr->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE) {
+		timr->it_overrun +=
+			hrtimer_forward(timer, timr->it.real.interval);
+		remaining = hrtimer_get_remaining(timer);
 	}
-	jiffies_to_timespec(expires, &cur_setting->it_value);
-	jiffies_to_timespec(timr->it.real.incr, &cur_setting->it_interval);
-
-	if (cur_setting->it_value.tv_sec < 0) {
+ calci:
+	/* interval timer ? */
+	if (timr->it.real.interval.tv64 != 0)
+		cur_setting->it_interval =
+			ktime_to_timespec(timr->it.real.interval);
+	/* Return 0 only, when the timer is expired and not pending */
+	if (remaining.tv64 <= 0)
 		cur_setting->it_value.tv_nsec = 1;
-		cur_setting->it_value.tv_sec = 0;
-	}
+	else
+		cur_setting->it_value = ktime_to_timespec(remaining);
 }
 
 /* Get the time remaining on a POSIX.1b interval timer. */
@@ -832,6 +658,7 @@
 
 	return 0;
 }
+
 /*
  * Get the number of overruns of a POSIX.1b interval timer.  This is to
  * be the overrun of the timer last delivered.  At the same time we are
@@ -841,7 +668,6 @@
  * the call back to do_schedule_next_timer().  So all we need to do is
  * to pick up the frozen overrun.
  */
-
 asmlinkage long
 sys_timer_getoverrun(timer_t timer_id)
 {
@@ -858,84 +684,6 @@
 
 	return overrun;
 }
-/*
- * Adjust for absolute time
- *
- * If absolute time is given and it is not CLOCK_MONOTONIC, we need to
- * adjust for the offset between the timer clock (CLOCK_MONOTONIC) and
- * what ever clock he is using.
- *
- * If it is relative time, we need to add the current (CLOCK_MONOTONIC)
- * time to it to get the proper time for the timer.
- */
-static int adjust_abs_time(struct k_clock *clock, struct timespec *tp, 
-			   int abs, u64 *exp, struct timespec *wall_to)
-{
-	struct timespec now;
-	struct timespec oc = *tp;
-	u64 jiffies_64_f;
-	int rtn =0;
-
-	if (abs) {
-		/*
-		 * The mask pick up the 4 basic clocks 
-		 */
-		if (!((clock - &posix_clocks[0]) & ~CLOCKS_MASK)) {
-			jiffies_64_f = do_posix_clock_monotonic_gettime_parts(
-				&now,  wall_to);
-			/*
-			 * If we are doing a MONOTONIC clock
-			 */
-			if((clock - &posix_clocks[0]) & CLOCKS_MONO){
-				now.tv_sec += wall_to->tv_sec;
-				now.tv_nsec += wall_to->tv_nsec;
-			}
-		} else {
-			/*
-			 * Not one of the basic clocks
-			 */
-			clock->clock_get(clock - posix_clocks, &now);
-			jiffies_64_f = get_jiffies_64();
-		}
-		/*
-		 * Take away now to get delta and normalize
-		 */
-		set_normalized_timespec(&oc, oc.tv_sec - now.tv_sec,
-					oc.tv_nsec - now.tv_nsec);
-	}else{
-		jiffies_64_f = get_jiffies_64();
-	}
-	/*
-	 * Check if the requested time is prior to now (if so set now)
-	 */
-	if (oc.tv_sec < 0)
-		oc.tv_sec = oc.tv_nsec = 0;
-
-	if (oc.tv_sec | oc.tv_nsec)
-		set_normalized_timespec(&oc, oc.tv_sec,
-					oc.tv_nsec + clock->res);
-	tstojiffie(&oc, clock->res, exp);
-
-	/*
-	 * Check if the requested time is more than the timer code
-	 * can handle (if so we error out but return the value too).
-	 */
-	if (*exp > ((u64)MAX_JIFFY_OFFSET))
-			/*
-			 * This is a considered response, not exactly in
-			 * line with the standard (in fact it is silent on
-			 * possible overflows).  We assume such a large 
-			 * value is ALMOST always a programming error and
-			 * try not to compound it by setting a really dumb
-			 * value.
-			 */
-			rtn = -EINVAL;
-	/*
-	 * return the actual jiffies expire time, full 64 bits
-	 */
-	*exp += jiffies_64_f;
-	return rtn;
-}
 
 /* Set a POSIX.1b interval timer. */
 /* timr->it_lock is taken. */
@@ -943,68 +691,48 @@
 common_timer_set(struct k_itimer *timr, int flags,
 		 struct itimerspec *new_setting, struct itimerspec *old_setting)
 {
-	struct k_clock *clock = &posix_clocks[timr->it_clock];
-	u64 expire_64;
+	struct hrtimer *timer = &timr->it.real.timer;
 
 	if (old_setting)
 		common_timer_get(timr, old_setting);
 
 	/* disable the timer */
-	timr->it.real.incr = 0;
+	timr->it.real.interval.tv64 = 0;
 	/*
 	 * careful here.  If smp we could be in the "fire" routine which will
 	 * be spinning as we hold the lock.  But this is ONLY an SMP issue.
 	 */
-	if (try_to_del_timer_sync(&timr->it.real.timer) < 0) {
-#ifdef CONFIG_SMP
-		/*
-		 * It can only be active if on an other cpu.  Since
-		 * we have cleared the interval stuff above, it should
-		 * clear once we release the spin lock.  Of course once
-		 * we do that anything could happen, including the
-		 * complete melt down of the timer.  So return with
-		 * a "retry" exit status.
-		 */
+	if (hrtimer_try_to_cancel(timer) < 0)
 		return TIMER_RETRY;
-#endif
-	}
-
-	remove_from_abslist(timr);
 
 	timr->it_requeue_pending = (timr->it_requeue_pending + 2) & 
 		~REQUEUE_PENDING;
 	timr->it_overrun_last = 0;
-	timr->it_overrun = -1;
-	/*
-	 *switch off the timer when it_value is zero
-	 */
-	if (!new_setting->it_value.tv_sec && !new_setting->it_value.tv_nsec) {
-		timr->it.real.timer.expires = 0;
+
+	/* switch off the timer when it_value is zero */
+	if (!new_setting->it_value.tv_sec && !new_setting->it_value.tv_nsec)
 		return 0;
-	}
 
-	if (adjust_abs_time(clock,
-			    &new_setting->it_value, flags & TIMER_ABSTIME, 
-			    &expire_64, &(timr->it.real.wall_to_prev))) {
-		return -EINVAL;
-	}
-	timr->it.real.timer.expires = (unsigned long)expire_64;
-	tstojiffie(&new_setting->it_interval, clock->res, &expire_64);
-	timr->it.real.incr = (unsigned long)expire_64;
-
-	/*
-	 * We do not even queue SIGEV_NONE timers!  But we do put them
-	 * in the abs list so we can do that right.
+	/* Posix madness. Only absolute CLOCK_REALTIME timers
+	 * are affected by clock sets. So we must reiniatilize
+	 * the timer.
 	 */
-	if (((timr->it_sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE))
-		add_timer(&timr->it.real.timer);
+	if (timr->it_clock == CLOCK_REALTIME && (flags & TIMER_ABSTIME))
+		hrtimer_rebase(timer, CLOCK_REALTIME);
+	else
+		hrtimer_rebase(timer, CLOCK_MONOTONIC);
 
-	if (flags & TIMER_ABSTIME && clock->abs_struct) {
-		spin_lock(&clock->abs_struct->lock);
-		list_add_tail(&(timr->it.real.abs_timer_entry),
-			      &(clock->abs_struct->list));
-		spin_unlock(&clock->abs_struct->lock);
-	}
+	timer->expires = timespec_to_ktime(new_setting->it_value);
+
+	/* Convert interval */
+	timr->it.real.interval = timespec_to_ktime(new_setting->it_interval);
+
+	/* SIGEV_NONE timers are not queued ! See common_timer_get */
+	if (((timr->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE))
+		return 0;
+
+	hrtimer_start(timer, timer->expires, (flags & TIMER_ABSTIME) ?
+		      HRTIMER_ABS : HRTIMER_REL);
 	return 0;
 }
 
@@ -1026,8 +754,8 @@
 	if (copy_from_user(&new_spec, new_setting, sizeof (new_spec)))
 		return -EFAULT;
 
-	if ((!good_timespec(&new_spec.it_interval)) ||
-	    (!good_timespec(&new_spec.it_value)))
+	if (!timespec_valid(&new_spec.it_interval) ||
+	    !timespec_valid(&new_spec.it_value))
 		return -EINVAL;
 retry:
 	timr = lock_timer(timer_id, &flag);
@@ -1043,8 +771,8 @@
 		goto retry;
 	}
 
-	if (old_setting && !error && copy_to_user(old_setting,
-						  &old_spec, sizeof (old_spec)))
+	if (old_setting && !error &&
+	    copy_to_user(old_setting, &old_spec, sizeof (old_spec)))
 		error = -EFAULT;
 
 	return error;
@@ -1052,24 +780,10 @@
 
 static inline int common_timer_del(struct k_itimer *timer)
 {
-	timer->it.real.incr = 0;
+	timer->it.real.interval.tv64 = 0;
 
-	if (try_to_del_timer_sync(&timer->it.real.timer) < 0) {
-#ifdef CONFIG_SMP
-		/*
-		 * It can only be active if on an other cpu.  Since
-		 * we have cleared the interval stuff above, it should
-		 * clear once we release the spin lock.  Of course once
-		 * we do that anything could happen, including the
-		 * complete melt down of the timer.  So return with
-		 * a "retry" exit status.
-		 */
+	if (hrtimer_try_to_cancel(&timer->it.real.timer) < 0)
 		return TIMER_RETRY;
-#endif
-	}
-
-	remove_from_abslist(timer);
-
 	return 0;
 }
 
@@ -1085,24 +799,16 @@
 	struct k_itimer *timer;
 	long flags;
 
-#ifdef CONFIG_SMP
-	int error;
 retry_delete:
-#endif
 	timer = lock_timer(timer_id, &flags);
 	if (!timer)
 		return -EINVAL;
 
-#ifdef CONFIG_SMP
-	error = timer_delete_hook(timer);
-
-	if (error == TIMER_RETRY) {
+	if (timer_delete_hook(timer) == TIMER_RETRY) {
 		unlock_timer(timer, flags);
 		goto retry_delete;
 	}
-#else
-	timer_delete_hook(timer);
-#endif
+
 	spin_lock(&current->sighand->siglock);
 	list_del(&timer->list);
 	spin_unlock(&current->sighand->siglock);
@@ -1119,6 +825,7 @@
 	release_posix_timer(timer, IT_ID_SET);
 	return 0;
 }
+
 /*
  * return timer owned by the process, used by exit_itimers
  */
@@ -1126,22 +833,13 @@
 {
 	unsigned long flags;
 
-#ifdef CONFIG_SMP
-	int error;
 retry_delete:
-#endif
 	spin_lock_irqsave(&timer->it_lock, flags);
 
-#ifdef CONFIG_SMP
-	error = timer_delete_hook(timer);
-
-	if (error == TIMER_RETRY) {
+	if (timer_delete_hook(timer) == TIMER_RETRY) {
 		unlock_timer(timer, flags);
 		goto retry_delete;
 	}
-#else
-	timer_delete_hook(timer);
-#endif
 	list_del(&timer->list);
 	/*
 	 * This keeps any tasks waiting on the spin lock from thinking
@@ -1170,57 +868,8 @@
 	}
 }
 
-/*
- * And now for the "clock" calls
- *
- * These functions are called both from timer functions (with the timer
- * spin_lock_irq() held and from clock calls with no locking.	They must
- * use the save flags versions of locks.
- */
-
-/*
- * We do ticks here to avoid the irq lock ( they take sooo long).
- * The seqlock is great here.  Since we a reader, we don't really care
- * if we are interrupted since we don't take lock that will stall us or
- * any other cpu. Voila, no irq lock is needed.
- *
- */
-
-static u64 do_posix_clock_monotonic_gettime_parts(
-	struct timespec *tp, struct timespec *mo)
-{
-	u64 jiff;
-	unsigned int seq;
-
-	do {
-		seq = read_seqbegin(&xtime_lock);
-		getnstimeofday(tp);
-		*mo = wall_to_monotonic;
-		jiff = jiffies_64;
-
-	} while(read_seqretry(&xtime_lock, seq));
-
-	return jiff;
-}
-
-static int do_posix_clock_monotonic_get(clockid_t clock, struct timespec *tp)
-{
-	struct timespec wall_to_mono;
-
-	do_posix_clock_monotonic_gettime_parts(tp, &wall_to_mono);
-
-	set_normalized_timespec(tp, tp->tv_sec + wall_to_mono.tv_sec,
-				tp->tv_nsec + wall_to_mono.tv_nsec);
-
-	return 0;
-}
-
-int do_posix_clock_monotonic_gettime(struct timespec *tp)
-{
-	return do_posix_clock_monotonic_get(CLOCK_MONOTONIC, tp);
-}
-
-int do_posix_clock_nosettime(clockid_t clockid, struct timespec *tp)
+/* Not available / possible... functions */
+int do_posix_clock_nosettime(const clockid_t clockid, struct timespec *tp)
 {
 	return -EINVAL;
 }
@@ -1232,7 +881,8 @@
 }
 EXPORT_SYMBOL_GPL(do_posix_clock_notimer_create);
 
-int do_posix_clock_nonanosleep(clockid_t clock, int flags, struct timespec *t)
+int do_posix_clock_nonanosleep(const clockid_t clock, int flags,
+			       struct timespec *t, struct timespec __user *r)
 {
 #ifndef ENOTSUP
 	return -EOPNOTSUPP;	/* aka ENOTSUP in userland for POSIX */
@@ -1242,8 +892,8 @@
 }
 EXPORT_SYMBOL_GPL(do_posix_clock_nonanosleep);
 
-asmlinkage long
-sys_clock_settime(clockid_t which_clock, const struct timespec __user *tp)
+asmlinkage long sys_clock_settime(const clockid_t which_clock,
+				  const struct timespec __user *tp)
 {
 	struct timespec new_tp;
 
@@ -1256,7 +906,7 @@
 }
 
 asmlinkage long
-sys_clock_gettime(clockid_t which_clock, struct timespec __user *tp)
+sys_clock_gettime(const clockid_t which_clock, struct timespec __user *tp)
 {
 	struct timespec kernel_tp;
 	int error;
@@ -1273,7 +923,7 @@
 }
 
 asmlinkage long
-sys_clock_getres(clockid_t which_clock, struct timespec __user *tp)
+sys_clock_getres(const clockid_t which_clock, struct timespec __user *tp)
 {
 	struct timespec rtn_tp;
 	int error;
@@ -1292,117 +942,34 @@
 }
 
 /*
- * The standard says that an absolute nanosleep call MUST wake up at
- * the requested time in spite of clock settings.  Here is what we do:
- * For each nanosleep call that needs it (only absolute and not on
- * CLOCK_MONOTONIC* (as it can not be set)) we thread a little structure
- * into the "nanosleep_abs_list".  All we need is the task_struct pointer.
- * When ever the clock is set we just wake up all those tasks.	 The rest
- * is done by the while loop in clock_nanosleep().
- *
- * On locking, clock_was_set() is called from update_wall_clock which
- * holds (or has held for it) a write_lock_irq( xtime_lock) and is
- * called from the timer bh code.  Thus we need the irq save locks.
- *
- * Also, on the call from update_wall_clock, that is done as part of a
- * softirq thing.  We don't want to delay the system that much (possibly
- * long list of timers to fix), so we defer that work to keventd.
+ * nanosleep for monotonic and realtime clocks
  */
-
-static DECLARE_WAIT_QUEUE_HEAD(nanosleep_abs_wqueue);
-static DECLARE_WORK(clock_was_set_work, (void(*)(void*))clock_was_set, NULL);
-
-static DECLARE_MUTEX(clock_was_set_lock);
-
-void clock_was_set(void)
+static int common_nsleep(const clockid_t which_clock, int flags,
+			 struct timespec *tsave, struct timespec __user *rmtp)
 {
-	struct k_itimer *timr;
-	struct timespec new_wall_to;
-	LIST_HEAD(cws_list);
-	unsigned long seq;
+	int mode = flags & TIMER_ABSTIME ? HRTIMER_ABS : HRTIMER_REL;
+	int clockid = which_clock;
 
-
-	if (unlikely(in_interrupt())) {
-		schedule_work(&clock_was_set_work);
-		return;
+	switch (which_clock) {
+	case CLOCK_REALTIME:
+		/* Posix madness. Only absolute timers on clock realtime
+		   are affected by clock set. */
+		if (mode != HRTIMER_ABS)
+			clockid = CLOCK_MONOTONIC;
+	case CLOCK_MONOTONIC:
+		break;
+	default:
+		return -EINVAL;
 	}
-	wake_up_all(&nanosleep_abs_wqueue);
-
-	/*
-	 * Check if there exist TIMER_ABSTIME timers to correct.
-	 *
-	 * Notes on locking: This code is run in task context with irq
-	 * on.  We CAN be interrupted!  All other usage of the abs list
-	 * lock is under the timer lock which holds the irq lock as
-	 * well.  We REALLY don't want to scan the whole list with the
-	 * interrupt system off, AND we would like a sequence lock on
-	 * this code as well.  Since we assume that the clock will not
-	 * be set often, it seems ok to take and release the irq lock
-	 * for each timer.  In fact add_timer will do this, so this is
-	 * not an issue.  So we know when we are done, we will move the
-	 * whole list to a new location.  Then as we process each entry,
-	 * we will move it to the actual list again.  This way, when our
-	 * copy is empty, we are done.  We are not all that concerned
-	 * about preemption so we will use a semaphore lock to protect
-	 * aginst reentry.  This way we will not stall another
-	 * processor.  It is possible that this may delay some timers
-	 * that should have expired, given the new clock, but even this
-	 * will be minimal as we will always update to the current time,
-	 * even if it was set by a task that is waiting for entry to
-	 * this code.  Timers that expire too early will be caught by
-	 * the expire code and restarted.
-
-	 * Absolute timers that repeat are left in the abs list while
-	 * waiting for the task to pick up the signal.  This means we
-	 * may find timers that are not in the "add_timer" list, but are
-	 * in the abs list.  We do the same thing for these, save
-	 * putting them back in the "add_timer" list.  (Note, these are
-	 * left in the abs list mainly to indicate that they are
-	 * ABSOLUTE timers, a fact that is used by the re-arm code, and
-	 * for which we have no other flag.)
-
-	 */
-
-	down(&clock_was_set_lock);
-	spin_lock_irq(&abs_list.lock);
-	list_splice_init(&abs_list.list, &cws_list);
-	spin_unlock_irq(&abs_list.lock);
-	do {
-		do {
-			seq = read_seqbegin(&xtime_lock);
-			new_wall_to =	wall_to_monotonic;
-		} while (read_seqretry(&xtime_lock, seq));
-
-		spin_lock_irq(&abs_list.lock);
-		if (list_empty(&cws_list)) {
-			spin_unlock_irq(&abs_list.lock);
-			break;
-		}
-		timr = list_entry(cws_list.next, struct k_itimer,
-				  it.real.abs_timer_entry);
-
-		list_del_init(&timr->it.real.abs_timer_entry);
-		if (add_clockset_delta(timr, &new_wall_to) &&
-		    del_timer(&timr->it.real.timer))  /* timer run yet? */
-			add_timer(&timr->it.real.timer);
-		list_add(&timr->it.real.abs_timer_entry, &abs_list.list);
-		spin_unlock_irq(&abs_list.lock);
-	} while (1);
-
-	up(&clock_was_set_lock);
+	return hrtimer_nanosleep(tsave, rmtp, mode, clockid);
 }
 
-long clock_nanosleep_restart(struct restart_block *restart_block);
-
 asmlinkage long
-sys_clock_nanosleep(clockid_t which_clock, int flags,
+sys_clock_nanosleep(const clockid_t which_clock, int flags,
 		    const struct timespec __user *rqtp,
 		    struct timespec __user *rmtp)
 {
 	struct timespec t;
-	struct restart_block *restart_block =
-	    &(current_thread_info()->restart_block);
-	int ret;
 
 	if (invalid_clockid(which_clock))
 		return -EINVAL;
@@ -1410,125 +977,9 @@
 	if (copy_from_user(&t, rqtp, sizeof (struct timespec)))
 		return -EFAULT;
 
-	if ((unsigned) t.tv_nsec >= NSEC_PER_SEC || t.tv_sec < 0)
+	if (!timespec_valid(&t))
 		return -EINVAL;
 
-	/*
-	 * Do this here as nsleep function does not have the real address.
-	 */
-	restart_block->arg1 = (unsigned long)rmtp;
-
-	ret = CLOCK_DISPATCH(which_clock, nsleep, (which_clock, flags, &t));
-
-	if ((ret == -ERESTART_RESTARTBLOCK) && rmtp &&
-					copy_to_user(rmtp, &t, sizeof (t)))
-		return -EFAULT;
-	return ret;
-}
-
-
-static int common_nsleep(clockid_t which_clock,
-			 int flags, struct timespec *tsave)
-{
-	struct timespec t, dum;
-	DECLARE_WAITQUEUE(abs_wqueue, current);
-	u64 rq_time = (u64)0;
-	s64 left;
-	int abs;
-	struct restart_block *restart_block =
-	    &current_thread_info()->restart_block;
-
-	abs_wqueue.flags = 0;
-	abs = flags & TIMER_ABSTIME;
-
-	if (restart_block->fn == clock_nanosleep_restart) {
-		/*
-		 * Interrupted by a non-delivered signal, pick up remaining
-		 * time and continue.  Remaining time is in arg2 & 3.
-		 */
-		restart_block->fn = do_no_restart_syscall;
-
-		rq_time = restart_block->arg3;
-		rq_time = (rq_time << 32) + restart_block->arg2;
-		if (!rq_time)
-			return -EINTR;
-		left = rq_time - get_jiffies_64();
-		if (left <= (s64)0)
-			return 0;	/* Already passed */
-	}
-
-	if (abs && (posix_clocks[which_clock].clock_get !=
-			    posix_clocks[CLOCK_MONOTONIC].clock_get))
-		add_wait_queue(&nanosleep_abs_wqueue, &abs_wqueue);
-
-	do {
-		t = *tsave;
-		if (abs || !rq_time) {
-			adjust_abs_time(&posix_clocks[which_clock], &t, abs,
-					&rq_time, &dum);
-		}
-
-		left = rq_time - get_jiffies_64();
-		if (left >= (s64)MAX_JIFFY_OFFSET)
-			left = (s64)MAX_JIFFY_OFFSET;
-		if (left < (s64)0)
-			break;
-
-		schedule_timeout_interruptible(left);
-
-		left = rq_time - get_jiffies_64();
-	} while (left > (s64)0 && !test_thread_flag(TIF_SIGPENDING));
-
-	if (abs_wqueue.task_list.next)
-		finish_wait(&nanosleep_abs_wqueue, &abs_wqueue);
-
-	if (left > (s64)0) {
-
-		/*
-		 * Always restart abs calls from scratch to pick up any
-		 * clock shifting that happened while we are away.
-		 */
-		if (abs)
-			return -ERESTARTNOHAND;
-
-		left *= TICK_NSEC;
-		tsave->tv_sec = div_long_long_rem(left, 
-						  NSEC_PER_SEC, 
-						  &tsave->tv_nsec);
-		/*
-		 * Restart works by saving the time remaing in 
-		 * arg2 & 3 (it is 64-bits of jiffies).  The other
-		 * info we need is the clock_id (saved in arg0). 
-		 * The sys_call interface needs the users 
-		 * timespec return address which _it_ saves in arg1.
-		 * Since we have cast the nanosleep call to a clock_nanosleep
-		 * both can be restarted with the same code.
-		 */
-		restart_block->fn = clock_nanosleep_restart;
-		restart_block->arg0 = which_clock;
-		/*
-		 * Caller sets arg1
-		 */
-		restart_block->arg2 = rq_time & 0xffffffffLL;
-		restart_block->arg3 = rq_time >> 32;
-
-		return -ERESTART_RESTARTBLOCK;
-	}
-
-	return 0;
-}
-/*
- * This will restart clock_nanosleep.
- */
-long
-clock_nanosleep_restart(struct restart_block *restart_block)
-{
-	struct timespec t;
-	int ret = common_nsleep(restart_block->arg0, 0, &t);
-
-	if ((ret == -ERESTART_RESTARTBLOCK) && restart_block->arg1 &&
-	    copy_to_user((struct timespec __user *)(restart_block->arg1), &t,
-			 sizeof (t)))
-		return -EFAULT;
-	return ret;
+	return CLOCK_DISPATCH(which_clock, nsleep,
+			      (which_clock, flags, &t, rmtp));
 }
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index cceaf09..5f33cdb 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -7,6 +7,7 @@
  * to continually duplicate across every architecture.
  */
 
+#include <linux/capability.h>
 #include <linux/module.h>
 #include <linux/sched.h>
 #include <linux/errno.h>
diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
index 05ee483..0cf8146 100644
--- a/kernel/rcupdate.c
+++ b/kernel/rcupdate.c
@@ -49,22 +49,18 @@
 #include <linux/cpu.h>
 
 /* Definition for rcupdate control block. */
-struct rcu_ctrlblk rcu_ctrlblk = 
-	{ .cur = -300, .completed = -300 };
-struct rcu_ctrlblk rcu_bh_ctrlblk =
-	{ .cur = -300, .completed = -300 };
-
-/* Bookkeeping of the progress of the grace period */
-struct rcu_state {
-	spinlock_t	lock; /* Guard this struct and writes to rcu_ctrlblk */
-	cpumask_t	cpumask; /* CPUs that need to switch in order    */
-	                              /* for current batch to proceed.        */
+struct rcu_ctrlblk rcu_ctrlblk = {
+	.cur = -300,
+	.completed = -300,
+	.lock = SPIN_LOCK_UNLOCKED,
+	.cpumask = CPU_MASK_NONE,
 };
-
-static struct rcu_state rcu_state ____cacheline_internodealigned_in_smp =
-	  {.lock = SPIN_LOCK_UNLOCKED, .cpumask = CPU_MASK_NONE };
-static struct rcu_state rcu_bh_state ____cacheline_internodealigned_in_smp =
-	  {.lock = SPIN_LOCK_UNLOCKED, .cpumask = CPU_MASK_NONE };
+struct rcu_ctrlblk rcu_bh_ctrlblk = {
+	.cur = -300,
+	.completed = -300,
+	.lock = SPIN_LOCK_UNLOCKED,
+	.cpumask = CPU_MASK_NONE,
+};
 
 DEFINE_PER_CPU(struct rcu_data, rcu_data) = { 0L };
 DEFINE_PER_CPU(struct rcu_data, rcu_bh_data) = { 0L };
@@ -220,13 +216,13 @@
  *   This is done by rcu_start_batch. The start is not broadcasted to
  *   all cpus, they must pick this up by comparing rcp->cur with
  *   rdp->quiescbatch. All cpus are recorded  in the
- *   rcu_state.cpumask bitmap.
+ *   rcu_ctrlblk.cpumask bitmap.
  * - All cpus must go through a quiescent state.
  *   Since the start of the grace period is not broadcasted, at least two
  *   calls to rcu_check_quiescent_state are required:
  *   The first call just notices that a new grace period is running. The
  *   following calls check if there was a quiescent state since the beginning
- *   of the grace period. If so, it updates rcu_state.cpumask. If
+ *   of the grace period. If so, it updates rcu_ctrlblk.cpumask. If
  *   the bitmap is empty, then the grace period is completed.
  *   rcu_check_quiescent_state calls rcu_start_batch(0) to start the next grace
  *   period (if necessary).
@@ -234,9 +230,9 @@
 /*
  * Register a new batch of callbacks, and start it up if there is currently no
  * active batch and the batch to be registered has not already occurred.
- * Caller must hold rcu_state.lock.
+ * Caller must hold rcu_ctrlblk.lock.
  */
-static void rcu_start_batch(struct rcu_ctrlblk *rcp, struct rcu_state *rsp)
+static void rcu_start_batch(struct rcu_ctrlblk *rcp)
 {
 	if (rcp->next_pending &&
 			rcp->completed == rcp->cur) {
@@ -251,11 +247,11 @@
 		/*
 		 * Accessing nohz_cpu_mask before incrementing rcp->cur needs a
 		 * Barrier  Otherwise it can cause tickless idle CPUs to be
-		 * included in rsp->cpumask, which will extend graceperiods
+		 * included in rcp->cpumask, which will extend graceperiods
 		 * unnecessarily.
 		 */
 		smp_mb();
-		cpus_andnot(rsp->cpumask, cpu_online_map, nohz_cpu_mask);
+		cpus_andnot(rcp->cpumask, cpu_online_map, nohz_cpu_mask);
 
 	}
 }
@@ -265,13 +261,13 @@
  * Clear it from the cpu mask and complete the grace period if it was the last
  * cpu. Start another grace period if someone has further entries pending
  */
-static void cpu_quiet(int cpu, struct rcu_ctrlblk *rcp, struct rcu_state *rsp)
+static void cpu_quiet(int cpu, struct rcu_ctrlblk *rcp)
 {
-	cpu_clear(cpu, rsp->cpumask);
-	if (cpus_empty(rsp->cpumask)) {
+	cpu_clear(cpu, rcp->cpumask);
+	if (cpus_empty(rcp->cpumask)) {
 		/* batch completed ! */
 		rcp->completed = rcp->cur;
-		rcu_start_batch(rcp, rsp);
+		rcu_start_batch(rcp);
 	}
 }
 
@@ -281,7 +277,7 @@
  * quiescent cycle, then indicate that it has done so.
  */
 static void rcu_check_quiescent_state(struct rcu_ctrlblk *rcp,
-			struct rcu_state *rsp, struct rcu_data *rdp)
+					struct rcu_data *rdp)
 {
 	if (rdp->quiescbatch != rcp->cur) {
 		/* start new grace period: */
@@ -306,15 +302,15 @@
 		return;
 	rdp->qs_pending = 0;
 
-	spin_lock(&rsp->lock);
+	spin_lock(&rcp->lock);
 	/*
 	 * rdp->quiescbatch/rcp->cur and the cpu bitmap can come out of sync
 	 * during cpu startup. Ignore the quiescent state.
 	 */
 	if (likely(rdp->quiescbatch == rcp->cur))
-		cpu_quiet(rdp->cpu, rcp, rsp);
+		cpu_quiet(rdp->cpu, rcp);
 
-	spin_unlock(&rsp->lock);
+	spin_unlock(&rcp->lock);
 }
 
 
@@ -335,28 +331,29 @@
 }
 
 static void __rcu_offline_cpu(struct rcu_data *this_rdp,
-	struct rcu_ctrlblk *rcp, struct rcu_state *rsp, struct rcu_data *rdp)
+				struct rcu_ctrlblk *rcp, struct rcu_data *rdp)
 {
 	/* if the cpu going offline owns the grace period
 	 * we can block indefinitely waiting for it, so flush
 	 * it here
 	 */
-	spin_lock_bh(&rsp->lock);
+	spin_lock_bh(&rcp->lock);
 	if (rcp->cur != rcp->completed)
-		cpu_quiet(rdp->cpu, rcp, rsp);
-	spin_unlock_bh(&rsp->lock);
+		cpu_quiet(rdp->cpu, rcp);
+	spin_unlock_bh(&rcp->lock);
 	rcu_move_batch(this_rdp, rdp->curlist, rdp->curtail);
 	rcu_move_batch(this_rdp, rdp->nxtlist, rdp->nxttail);
-
+	rcu_move_batch(this_rdp, rdp->donelist, rdp->donetail);
 }
+
 static void rcu_offline_cpu(int cpu)
 {
 	struct rcu_data *this_rdp = &get_cpu_var(rcu_data);
 	struct rcu_data *this_bh_rdp = &get_cpu_var(rcu_bh_data);
 
-	__rcu_offline_cpu(this_rdp, &rcu_ctrlblk, &rcu_state,
+	__rcu_offline_cpu(this_rdp, &rcu_ctrlblk,
 					&per_cpu(rcu_data, cpu));
-	__rcu_offline_cpu(this_bh_rdp, &rcu_bh_ctrlblk, &rcu_bh_state,
+	__rcu_offline_cpu(this_bh_rdp, &rcu_bh_ctrlblk,
 					&per_cpu(rcu_bh_data, cpu));
 	put_cpu_var(rcu_data);
 	put_cpu_var(rcu_bh_data);
@@ -375,7 +372,7 @@
  * This does the RCU processing work from tasklet context. 
  */
 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp,
-			struct rcu_state *rsp, struct rcu_data *rdp)
+					struct rcu_data *rdp)
 {
 	if (rdp->curlist && !rcu_batch_before(rcp->completed, rdp->batch)) {
 		*rdp->donetail = rdp->curlist;
@@ -405,25 +402,23 @@
 
 		if (!rcp->next_pending) {
 			/* and start it/schedule start if it's a new batch */
-			spin_lock(&rsp->lock);
+			spin_lock(&rcp->lock);
 			rcp->next_pending = 1;
-			rcu_start_batch(rcp, rsp);
-			spin_unlock(&rsp->lock);
+			rcu_start_batch(rcp);
+			spin_unlock(&rcp->lock);
 		}
 	} else {
 		local_irq_enable();
 	}
-	rcu_check_quiescent_state(rcp, rsp, rdp);
+	rcu_check_quiescent_state(rcp, rdp);
 	if (rdp->donelist)
 		rcu_do_batch(rdp);
 }
 
 static void rcu_process_callbacks(unsigned long unused)
 {
-	__rcu_process_callbacks(&rcu_ctrlblk, &rcu_state,
-				&__get_cpu_var(rcu_data));
-	__rcu_process_callbacks(&rcu_bh_ctrlblk, &rcu_bh_state,
-				&__get_cpu_var(rcu_bh_data));
+	__rcu_process_callbacks(&rcu_ctrlblk, &__get_cpu_var(rcu_data));
+	__rcu_process_callbacks(&rcu_bh_ctrlblk, &__get_cpu_var(rcu_bh_data));
 }
 
 static int __rcu_pending(struct rcu_ctrlblk *rcp, struct rcu_data *rdp)
diff --git a/kernel/resource.c b/kernel/resource.c
index 92285d8..e3080fc 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -464,7 +464,7 @@
 
 EXPORT_SYMBOL(__request_region);
 
-int __deprecated __check_region(struct resource *parent, unsigned long start, unsigned long n)
+int __check_region(struct resource *parent, unsigned long start, unsigned long n)
 {
 	struct resource * res;
 
diff --git a/kernel/sched.c b/kernel/sched.c
index 34a945b..c9dec2a 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -27,12 +27,14 @@
 #include <linux/smp_lock.h>
 #include <asm/mmu_context.h>
 #include <linux/interrupt.h>
+#include <linux/capability.h>
 #include <linux/completion.h>
 #include <linux/kernel_stat.h>
 #include <linux/security.h>
 #include <linux/notifier.h>
 #include <linux/profile.h>
 #include <linux/suspend.h>
+#include <linux/vmalloc.h>
 #include <linux/blkdev.h>
 #include <linux/delay.h>
 #include <linux/smp.h>
@@ -1288,6 +1290,9 @@
 		}
 	}
 
+	if (p->last_waker_cpu != this_cpu)
+		goto out_set_cpu;
+
 	if (unlikely(!cpu_isset(this_cpu, p->cpus_allowed)))
 		goto out_set_cpu;
 
@@ -1358,6 +1363,8 @@
 		cpu = task_cpu(p);
 	}
 
+	p->last_waker_cpu = this_cpu;
+
 out_activate:
 #endif /* CONFIG_SMP */
 	if (old_state == TASK_UNINTERRUPTIBLE) {
@@ -1439,9 +1446,12 @@
 #ifdef CONFIG_SCHEDSTATS
 	memset(&p->sched_info, 0, sizeof(p->sched_info));
 #endif
-#if defined(CONFIG_SMP) && defined(__ARCH_WANT_UNLOCKED_CTXSW)
+#if defined(CONFIG_SMP)
+	p->last_waker_cpu = cpu;
+#if defined(__ARCH_WANT_UNLOCKED_CTXSW)
 	p->oncpu = 0;
 #endif
+#endif
 #ifdef CONFIG_PREEMPT
 	/* Want to start with kernel preemption disabled. */
 	task_thread_info(p)->preempt_count = 1;
@@ -3979,12 +3989,12 @@
  * method, such as ACPI for e.g.
  */
 
-cpumask_t cpu_present_map;
+cpumask_t cpu_present_map __read_mostly;
 EXPORT_SYMBOL(cpu_present_map);
 
 #ifndef CONFIG_SMP
-cpumask_t cpu_online_map = CPU_MASK_ALL;
-cpumask_t cpu_possible_map = CPU_MASK_ALL;
+cpumask_t cpu_online_map __read_mostly = CPU_MASK_ALL;
+cpumask_t cpu_possible_map __read_mostly = CPU_MASK_ALL;
 #endif
 
 long sched_getaffinity(pid_t pid, cpumask_t *mask)
@@ -5081,7 +5091,470 @@
 
 #define SD_NODES_PER_DOMAIN 16
 
+/*
+ * Self-tuning task migration cost measurement between source and target CPUs.
+ *
+ * This is done by measuring the cost of manipulating buffers of varying
+ * sizes. For a given buffer-size here are the steps that are taken:
+ *
+ * 1) the source CPU reads+dirties a shared buffer
+ * 2) the target CPU reads+dirties the same shared buffer
+ *
+ * We measure how long they take, in the following 4 scenarios:
+ *
+ *  - source: CPU1, target: CPU2 | cost1
+ *  - source: CPU2, target: CPU1 | cost2
+ *  - source: CPU1, target: CPU1 | cost3
+ *  - source: CPU2, target: CPU2 | cost4
+ *
+ * We then calculate the cost3+cost4-cost1-cost2 difference - this is
+ * the cost of migration.
+ *
+ * We then start off from a small buffer-size and iterate up to larger
+ * buffer sizes, in 5% steps - measuring each buffer-size separately, and
+ * doing a maximum search for the cost. (The maximum cost for a migration
+ * normally occurs when the working set size is around the effective cache
+ * size.)
+ */
+#define SEARCH_SCOPE		2
+#define MIN_CACHE_SIZE		(64*1024U)
+#define DEFAULT_CACHE_SIZE	(5*1024*1024U)
+#define ITERATIONS		2
+#define SIZE_THRESH		130
+#define COST_THRESH		130
+
+/*
+ * The migration cost is a function of 'domain distance'. Domain
+ * distance is the number of steps a CPU has to iterate down its
+ * domain tree to share a domain with the other CPU. The farther
+ * two CPUs are from each other, the larger the distance gets.
+ *
+ * Note that we use the distance only to cache measurement results,
+ * the distance value is not used numerically otherwise. When two
+ * CPUs have the same distance it is assumed that the migration
+ * cost is the same. (this is a simplification but quite practical)
+ */
+#define MAX_DOMAIN_DISTANCE 32
+
+static unsigned long long migration_cost[MAX_DOMAIN_DISTANCE] =
+		{ [ 0 ... MAX_DOMAIN_DISTANCE-1 ] = -1LL };
+
+/*
+ * Allow override of migration cost - in units of microseconds.
+ * E.g. migration_cost=1000,2000,3000 will set up a level-1 cost
+ * of 1 msec, level-2 cost of 2 msecs and level3 cost of 3 msecs:
+ */
+static int __init migration_cost_setup(char *str)
+{
+	int ints[MAX_DOMAIN_DISTANCE+1], i;
+
+	str = get_options(str, ARRAY_SIZE(ints), ints);
+
+	printk("#ints: %d\n", ints[0]);
+	for (i = 1; i <= ints[0]; i++) {
+		migration_cost[i-1] = (unsigned long long)ints[i]*1000;
+		printk("migration_cost[%d]: %Ld\n", i-1, migration_cost[i-1]);
+	}
+	return 1;
+}
+
+__setup ("migration_cost=", migration_cost_setup);
+
+/*
+ * Global multiplier (divisor) for migration-cutoff values,
+ * in percentiles. E.g. use a value of 150 to get 1.5 times
+ * longer cache-hot cutoff times.
+ *
+ * (We scale it from 100 to 128 to long long handling easier.)
+ */
+
+#define MIGRATION_FACTOR_SCALE 128
+
+static unsigned int migration_factor = MIGRATION_FACTOR_SCALE;
+
+static int __init setup_migration_factor(char *str)
+{
+	get_option(&str, &migration_factor);
+	migration_factor = migration_factor * MIGRATION_FACTOR_SCALE / 100;
+	return 1;
+}
+
+__setup("migration_factor=", setup_migration_factor);
+
+/*
+ * Estimated distance of two CPUs, measured via the number of domains
+ * we have to pass for the two CPUs to be in the same span:
+ */
+static unsigned long domain_distance(int cpu1, int cpu2)
+{
+	unsigned long distance = 0;
+	struct sched_domain *sd;
+
+	for_each_domain(cpu1, sd) {
+		WARN_ON(!cpu_isset(cpu1, sd->span));
+		if (cpu_isset(cpu2, sd->span))
+			return distance;
+		distance++;
+	}
+	if (distance >= MAX_DOMAIN_DISTANCE) {
+		WARN_ON(1);
+		distance = MAX_DOMAIN_DISTANCE-1;
+	}
+
+	return distance;
+}
+
+static unsigned int migration_debug;
+
+static int __init setup_migration_debug(char *str)
+{
+	get_option(&str, &migration_debug);
+	return 1;
+}
+
+__setup("migration_debug=", setup_migration_debug);
+
+/*
+ * Maximum cache-size that the scheduler should try to measure.
+ * Architectures with larger caches should tune this up during
+ * bootup. Gets used in the domain-setup code (i.e. during SMP
+ * bootup).
+ */
+unsigned int max_cache_size;
+
+static int __init setup_max_cache_size(char *str)
+{
+	get_option(&str, &max_cache_size);
+	return 1;
+}
+
+__setup("max_cache_size=", setup_max_cache_size);
+
+/*
+ * Dirty a big buffer in a hard-to-predict (for the L2 cache) way. This
+ * is the operation that is timed, so we try to generate unpredictable
+ * cachemisses that still end up filling the L2 cache:
+ */
+static void touch_cache(void *__cache, unsigned long __size)
+{
+	unsigned long size = __size/sizeof(long), chunk1 = size/3,
+			chunk2 = 2*size/3;
+	unsigned long *cache = __cache;
+	int i;
+
+	for (i = 0; i < size/6; i += 8) {
+		switch (i % 6) {
+			case 0: cache[i]++;
+			case 1: cache[size-1-i]++;
+			case 2: cache[chunk1-i]++;
+			case 3: cache[chunk1+i]++;
+			case 4: cache[chunk2-i]++;
+			case 5: cache[chunk2+i]++;
+		}
+	}
+}
+
+/*
+ * Measure the cache-cost of one task migration. Returns in units of nsec.
+ */
+static unsigned long long measure_one(void *cache, unsigned long size,
+				      int source, int target)
+{
+	cpumask_t mask, saved_mask;
+	unsigned long long t0, t1, t2, t3, cost;
+
+	saved_mask = current->cpus_allowed;
+
+	/*
+	 * Flush source caches to RAM and invalidate them:
+	 */
+	sched_cacheflush();
+
+	/*
+	 * Migrate to the source CPU:
+	 */
+	mask = cpumask_of_cpu(source);
+	set_cpus_allowed(current, mask);
+	WARN_ON(smp_processor_id() != source);
+
+	/*
+	 * Dirty the working set:
+	 */
+	t0 = sched_clock();
+	touch_cache(cache, size);
+	t1 = sched_clock();
+
+	/*
+	 * Migrate to the target CPU, dirty the L2 cache and access
+	 * the shared buffer. (which represents the working set
+	 * of a migrated task.)
+	 */
+	mask = cpumask_of_cpu(target);
+	set_cpus_allowed(current, mask);
+	WARN_ON(smp_processor_id() != target);
+
+	t2 = sched_clock();
+	touch_cache(cache, size);
+	t3 = sched_clock();
+
+	cost = t1-t0 + t3-t2;
+
+	if (migration_debug >= 2)
+		printk("[%d->%d]: %8Ld %8Ld %8Ld => %10Ld.\n",
+			source, target, t1-t0, t1-t0, t3-t2, cost);
+	/*
+	 * Flush target caches to RAM and invalidate them:
+	 */
+	sched_cacheflush();
+
+	set_cpus_allowed(current, saved_mask);
+
+	return cost;
+}
+
+/*
+ * Measure a series of task migrations and return the average
+ * result. Since this code runs early during bootup the system
+ * is 'undisturbed' and the average latency makes sense.
+ *
+ * The algorithm in essence auto-detects the relevant cache-size,
+ * so it will properly detect different cachesizes for different
+ * cache-hierarchies, depending on how the CPUs are connected.
+ *
+ * Architectures can prime the upper limit of the search range via
+ * max_cache_size, otherwise the search range defaults to 20MB...64K.
+ */
+static unsigned long long
+measure_cost(int cpu1, int cpu2, void *cache, unsigned int size)
+{
+	unsigned long long cost1, cost2;
+	int i;
+
+	/*
+	 * Measure the migration cost of 'size' bytes, over an
+	 * average of 10 runs:
+	 *
+	 * (We perturb the cache size by a small (0..4k)
+	 *  value to compensate size/alignment related artifacts.
+	 *  We also subtract the cost of the operation done on
+	 *  the same CPU.)
+	 */
+	cost1 = 0;
+
+	/*
+	 * dry run, to make sure we start off cache-cold on cpu1,
+	 * and to get any vmalloc pagefaults in advance:
+	 */
+	measure_one(cache, size, cpu1, cpu2);
+	for (i = 0; i < ITERATIONS; i++)
+		cost1 += measure_one(cache, size - i*1024, cpu1, cpu2);
+
+	measure_one(cache, size, cpu2, cpu1);
+	for (i = 0; i < ITERATIONS; i++)
+		cost1 += measure_one(cache, size - i*1024, cpu2, cpu1);
+
+	/*
+	 * (We measure the non-migrating [cached] cost on both
+	 *  cpu1 and cpu2, to handle CPUs with different speeds)
+	 */
+	cost2 = 0;
+
+	measure_one(cache, size, cpu1, cpu1);
+	for (i = 0; i < ITERATIONS; i++)
+		cost2 += measure_one(cache, size - i*1024, cpu1, cpu1);
+
+	measure_one(cache, size, cpu2, cpu2);
+	for (i = 0; i < ITERATIONS; i++)
+		cost2 += measure_one(cache, size - i*1024, cpu2, cpu2);
+
+	/*
+	 * Get the per-iteration migration cost:
+	 */
+	do_div(cost1, 2*ITERATIONS);
+	do_div(cost2, 2*ITERATIONS);
+
+	return cost1 - cost2;
+}
+
+static unsigned long long measure_migration_cost(int cpu1, int cpu2)
+{
+	unsigned long long max_cost = 0, fluct = 0, avg_fluct = 0;
+	unsigned int max_size, size, size_found = 0;
+	long long cost = 0, prev_cost;
+	void *cache;
+
+	/*
+	 * Search from max_cache_size*5 down to 64K - the real relevant
+	 * cachesize has to lie somewhere inbetween.
+	 */
+	if (max_cache_size) {
+		max_size = max(max_cache_size * SEARCH_SCOPE, MIN_CACHE_SIZE);
+		size = max(max_cache_size / SEARCH_SCOPE, MIN_CACHE_SIZE);
+	} else {
+		/*
+		 * Since we have no estimation about the relevant
+		 * search range
+		 */
+		max_size = DEFAULT_CACHE_SIZE * SEARCH_SCOPE;
+		size = MIN_CACHE_SIZE;
+	}
+
+	if (!cpu_online(cpu1) || !cpu_online(cpu2)) {
+		printk("cpu %d and %d not both online!\n", cpu1, cpu2);
+		return 0;
+	}
+
+	/*
+	 * Allocate the working set:
+	 */
+	cache = vmalloc(max_size);
+	if (!cache) {
+		printk("could not vmalloc %d bytes for cache!\n", 2*max_size);
+		return 1000000; // return 1 msec on very small boxen
+	}
+
+	while (size <= max_size) {
+		prev_cost = cost;
+		cost = measure_cost(cpu1, cpu2, cache, size);
+
+		/*
+		 * Update the max:
+		 */
+		if (cost > 0) {
+			if (max_cost < cost) {
+				max_cost = cost;
+				size_found = size;
+			}
+		}
+		/*
+		 * Calculate average fluctuation, we use this to prevent
+		 * noise from triggering an early break out of the loop:
+		 */
+		fluct = abs(cost - prev_cost);
+		avg_fluct = (avg_fluct + fluct)/2;
+
+		if (migration_debug)
+			printk("-> [%d][%d][%7d] %3ld.%ld [%3ld.%ld] (%ld): (%8Ld %8Ld)\n",
+				cpu1, cpu2, size,
+				(long)cost / 1000000,
+				((long)cost / 100000) % 10,
+				(long)max_cost / 1000000,
+				((long)max_cost / 100000) % 10,
+				domain_distance(cpu1, cpu2),
+				cost, avg_fluct);
+
+		/*
+		 * If we iterated at least 20% past the previous maximum,
+		 * and the cost has dropped by more than 20% already,
+		 * (taking fluctuations into account) then we assume to
+		 * have found the maximum and break out of the loop early:
+		 */
+		if (size_found && (size*100 > size_found*SIZE_THRESH))
+			if (cost+avg_fluct <= 0 ||
+				max_cost*100 > (cost+avg_fluct)*COST_THRESH) {
+
+				if (migration_debug)
+					printk("-> found max.\n");
+				break;
+			}
+		/*
+		 * Increase the cachesize in 5% steps:
+		 */
+		size = size * 20 / 19;
+	}
+
+	if (migration_debug)
+		printk("[%d][%d] working set size found: %d, cost: %Ld\n",
+			cpu1, cpu2, size_found, max_cost);
+
+	vfree(cache);
+
+	/*
+	 * A task is considered 'cache cold' if at least 2 times
+	 * the worst-case cost of migration has passed.
+	 *
+	 * (this limit is only listened to if the load-balancing
+	 * situation is 'nice' - if there is a large imbalance we
+	 * ignore it for the sake of CPU utilization and
+	 * processing fairness.)
+	 */
+	return 2 * max_cost * migration_factor / MIGRATION_FACTOR_SCALE;
+}
+
+static void calibrate_migration_costs(const cpumask_t *cpu_map)
+{
+	int cpu1 = -1, cpu2 = -1, cpu, orig_cpu = raw_smp_processor_id();
+	unsigned long j0, j1, distance, max_distance = 0;
+	struct sched_domain *sd;
+
+	j0 = jiffies;
+
+	/*
+	 * First pass - calculate the cacheflush times:
+	 */
+	for_each_cpu_mask(cpu1, *cpu_map) {
+		for_each_cpu_mask(cpu2, *cpu_map) {
+			if (cpu1 == cpu2)
+				continue;
+			distance = domain_distance(cpu1, cpu2);
+			max_distance = max(max_distance, distance);
+			/*
+			 * No result cached yet?
+			 */
+			if (migration_cost[distance] == -1LL)
+				migration_cost[distance] =
+					measure_migration_cost(cpu1, cpu2);
+		}
+	}
+	/*
+	 * Second pass - update the sched domain hierarchy with
+	 * the new cache-hot-time estimations:
+	 */
+	for_each_cpu_mask(cpu, *cpu_map) {
+		distance = 0;
+		for_each_domain(cpu, sd) {
+			sd->cache_hot_time = migration_cost[distance];
+			distance++;
+		}
+	}
+	/*
+	 * Print the matrix:
+	 */
+	if (migration_debug)
+		printk("migration: max_cache_size: %d, cpu: %d MHz:\n",
+			max_cache_size,
+#ifdef CONFIG_X86
+			cpu_khz/1000
+#else
+			-1
+#endif
+		);
+	printk("migration_cost=");
+	for (distance = 0; distance <= max_distance; distance++) {
+		if (distance)
+			printk(",");
+		printk("%ld", (long)migration_cost[distance] / 1000);
+	}
+	printk("\n");
+	j1 = jiffies;
+	if (migration_debug)
+		printk("migration: %ld seconds\n", (j1-j0)/HZ);
+
+	/*
+	 * Move back to the original CPU. NUMA-Q gets confused
+	 * if we migrate to another quad during bootup.
+	 */
+	if (raw_smp_processor_id() != orig_cpu) {
+		cpumask_t mask = cpumask_of_cpu(orig_cpu),
+			saved_mask = current->cpus_allowed;
+
+		set_cpus_allowed(current, mask);
+		set_cpus_allowed(current, saved_mask);
+	}
+}
+
 #ifdef CONFIG_NUMA
+
 /**
  * find_next_best_node - find the next node to include in a sched_domain
  * @node: node whose sched_domain we're building
@@ -5447,6 +5920,10 @@
 #endif
 		cpu_attach_domain(sd, i);
 	}
+	/*
+	 * Tune cache-hot values:
+	 */
+	calibrate_migration_costs(cpu_map);
 }
 /*
  * Set up scheduler domains and groups.  Callers must hold the hotplug lock.
diff --git a/kernel/signal.c b/kernel/signal.c
index 08aa5b2..1da2e74 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -25,6 +25,7 @@
 #include <linux/posix-timers.h>
 #include <linux/signal.h>
 #include <linux/audit.h>
+#include <linux/capability.h>
 #include <asm/param.h>
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
index b3d4dc8..dcfb5d7 100644
--- a/kernel/stop_machine.c
+++ b/kernel/stop_machine.c
@@ -87,13 +87,9 @@
 {
 	int i, ret = 0;
 	struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
-	mm_segment_t old_fs = get_fs();
 
 	/* One high-prio thread per cpu.  We'll do this one. */
-	set_fs(KERNEL_DS);
-	sys_sched_setscheduler(current->pid, SCHED_FIFO,
-				(struct sched_param __user *)&param);
-	set_fs(old_fs);
+	sched_setscheduler(current, SCHED_FIFO, &param);
 
 	atomic_set(&stopmachine_thread_ack, 0);
 	stopmachine_num_threads = 0;
diff --git a/kernel/sys.c b/kernel/sys.c
index b6941e0..d09cac2 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -19,6 +19,7 @@
 #include <linux/kernel.h>
 #include <linux/kexec.h>
 #include <linux/workqueue.h>
+#include <linux/capability.h>
 #include <linux/device.h>
 #include <linux/key.h>
 #include <linux/times.h>
@@ -223,6 +224,18 @@
 
 EXPORT_SYMBOL(unregister_reboot_notifier);
 
+#ifndef CONFIG_SECURITY
+int capable(int cap)
+{
+        if (cap_raised(current->cap_effective, cap)) {
+	       current->flags |= PF_SUPERPRIV;
+	       return 1;
+        }
+        return 0;
+}
+EXPORT_SYMBOL(capable);
+#endif
+
 static int set_one_prio(struct task_struct *p, int niceval, int error)
 {
 	int no_nice;
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 03b0598..62d4d95 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -25,6 +25,7 @@
 #include <linux/slab.h>
 #include <linux/sysctl.h>
 #include <linux/proc_fs.h>
+#include <linux/capability.h>
 #include <linux/ctype.h>
 #include <linux/utsname.h>
 #include <linux/capability.h>
diff --git a/kernel/time.c b/kernel/time.c
index b94bfa8..7477b1d 100644
--- a/kernel/time.c
+++ b/kernel/time.c
@@ -29,6 +29,7 @@
 
 #include <linux/module.h>
 #include <linux/timex.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/smp_lock.h>
 #include <linux/syscalls.h>
@@ -154,6 +155,9 @@
 	static int firsttime = 1;
 	int error = 0;
 
+	if (!timespec_valid(tv))
+		return -EINVAL;
+
 	error = security_settime(tv, tz);
 	if (error)
 		return error;
@@ -561,27 +565,107 @@
 EXPORT_SYMBOL_GPL(getnstimeofday);
 #endif
 
-void getnstimestamp(struct timespec *ts)
+/* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
+ * Assumes input in normal date format, i.e. 1980-12-31 23:59:59
+ * => year=1980, mon=12, day=31, hour=23, min=59, sec=59.
+ *
+ * [For the Julian calendar (which was used in Russia before 1917,
+ * Britain & colonies before 1752, anywhere else before 1582,
+ * and is still in use by some communities) leave out the
+ * -year/100+year/400 terms, and add 10.]
+ *
+ * This algorithm was first published by Gauss (I think).
+ *
+ * WARNING: this function will overflow on 2106-02-07 06:28:16 on
+ * machines were long is 32-bit! (However, as time_t is signed, we
+ * will already get problems at other places on 2038-01-19 03:14:08)
+ */
+unsigned long
+mktime(const unsigned int year0, const unsigned int mon0,
+       const unsigned int day, const unsigned int hour,
+       const unsigned int min, const unsigned int sec)
 {
-	unsigned int seq;
-	struct timespec wall2mono;
+	unsigned int mon = mon0, year = year0;
 
-	/* synchronize with settimeofday() changes */
-	do {
-		seq = read_seqbegin(&xtime_lock);
-		getnstimeofday(ts);
-		wall2mono = wall_to_monotonic;
-	} while(unlikely(read_seqretry(&xtime_lock, seq)));
-
-	/* adjust to monotonicaly-increasing values */
-	ts->tv_sec += wall2mono.tv_sec;
-	ts->tv_nsec += wall2mono.tv_nsec;
-	while (unlikely(ts->tv_nsec >= NSEC_PER_SEC)) {
-		ts->tv_nsec -= NSEC_PER_SEC;
-		ts->tv_sec++;
+	/* 1..12 -> 11,12,1..10 */
+	if (0 >= (int) (mon -= 2)) {
+		mon += 12;	/* Puts Feb last since it has leap day */
+		year -= 1;
 	}
+
+	return ((((unsigned long)
+		  (year/4 - year/100 + year/400 + 367*mon/12 + day) +
+		  year*365 - 719499
+	    )*24 + hour /* now have hours */
+	  )*60 + min /* now have minutes */
+	)*60 + sec; /* finally seconds */
 }
-EXPORT_SYMBOL_GPL(getnstimestamp);
+
+EXPORT_SYMBOL(mktime);
+
+/**
+ * set_normalized_timespec - set timespec sec and nsec parts and normalize
+ *
+ * @ts:		pointer to timespec variable to be set
+ * @sec:	seconds to set
+ * @nsec:	nanoseconds to set
+ *
+ * Set seconds and nanoseconds field of a timespec variable and
+ * normalize to the timespec storage format
+ *
+ * Note: The tv_nsec part is always in the range of
+ * 	0 <= tv_nsec < NSEC_PER_SEC
+ * For negative values only the tv_sec field is negative !
+ */
+void set_normalized_timespec(struct timespec *ts, time_t sec, long nsec)
+{
+	while (nsec >= NSEC_PER_SEC) {
+		nsec -= NSEC_PER_SEC;
+		++sec;
+	}
+	while (nsec < 0) {
+		nsec += NSEC_PER_SEC;
+		--sec;
+	}
+	ts->tv_sec = sec;
+	ts->tv_nsec = nsec;
+}
+
+/**
+ * ns_to_timespec - Convert nanoseconds to timespec
+ * @nsec:       the nanoseconds value to be converted
+ *
+ * Returns the timespec representation of the nsec parameter.
+ */
+inline struct timespec ns_to_timespec(const nsec_t nsec)
+{
+	struct timespec ts;
+
+	if (nsec)
+		ts.tv_sec = div_long_long_rem_signed(nsec, NSEC_PER_SEC,
+						     &ts.tv_nsec);
+	else
+		ts.tv_sec = ts.tv_nsec = 0;
+
+	return ts;
+}
+
+/**
+ * ns_to_timeval - Convert nanoseconds to timeval
+ * @nsec:       the nanoseconds value to be converted
+ *
+ * Returns the timeval representation of the nsec parameter.
+ */
+struct timeval ns_to_timeval(const nsec_t nsec)
+{
+	struct timespec ts = ns_to_timespec(nsec);
+	struct timeval tv;
+
+	tv.tv_sec = ts.tv_sec;
+	tv.tv_usec = (suseconds_t) ts.tv_nsec / 1000;
+
+	return tv;
+}
 
 #if (BITS_PER_LONG < 64)
 u64 get_jiffies_64(void)
diff --git a/kernel/timer.c b/kernel/timer.c
index 074b4bd..4f1cb0a 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -858,6 +858,7 @@
 {
 	tvec_base_t *base = &__get_cpu_var(tvec_bases);
 
+ 	hrtimer_run_queues();
 	if (time_after_eq(jiffies, base->timer_jiffies))
 		__run_timers(base);
 }
@@ -1119,62 +1120,6 @@
 	return current->pid;
 }
 
-static long __sched nanosleep_restart(struct restart_block *restart)
-{
-	unsigned long expire = restart->arg0, now = jiffies;
-	struct timespec __user *rmtp = (struct timespec __user *) restart->arg1;
-	long ret;
-
-	/* Did it expire while we handled signals? */
-	if (!time_after(expire, now))
-		return 0;
-
-	expire = schedule_timeout_interruptible(expire - now);
-
-	ret = 0;
-	if (expire) {
-		struct timespec t;
-		jiffies_to_timespec(expire, &t);
-
-		ret = -ERESTART_RESTARTBLOCK;
-		if (rmtp && copy_to_user(rmtp, &t, sizeof(t)))
-			ret = -EFAULT;
-		/* The 'restart' block is already filled in */
-	}
-	return ret;
-}
-
-asmlinkage long sys_nanosleep(struct timespec __user *rqtp, struct timespec __user *rmtp)
-{
-	struct timespec t;
-	unsigned long expire;
-	long ret;
-
-	if (copy_from_user(&t, rqtp, sizeof(t)))
-		return -EFAULT;
-
-	if ((t.tv_nsec >= 1000000000L) || (t.tv_nsec < 0) || (t.tv_sec < 0))
-		return -EINVAL;
-
-	expire = timespec_to_jiffies(&t) + (t.tv_sec || t.tv_nsec);
-	expire = schedule_timeout_interruptible(expire);
-
-	ret = 0;
-	if (expire) {
-		struct restart_block *restart;
-		jiffies_to_timespec(expire, &t);
-		if (rmtp && copy_to_user(rmtp, &t, sizeof(t)))
-			return -EFAULT;
-
-		restart = &current_thread_info()->restart_block;
-		restart->fn = nanosleep_restart;
-		restart->arg0 = jiffies + expire;
-		restart->arg1 = (unsigned long) rmtp;
-		ret = -ERESTART_RESTARTBLOCK;
-	}
-	return ret;
-}
-
 /*
  * sys_sysinfo - fill in sysinfo struct
  */ 
diff --git a/kernel/uid16.c b/kernel/uid16.c
index f669941..aa25605 100644
--- a/kernel/uid16.c
+++ b/kernel/uid16.c
@@ -10,6 +10,7 @@
 #include <linux/notifier.h>
 #include <linux/reboot.h>
 #include <linux/prctl.h>
+#include <linux/capability.h>
 #include <linux/init.h>
 #include <linux/highuid.h>
 #include <linux/security.h>
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 1fcd856..a609235 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -9,15 +9,9 @@
 	  in kernel startup.
 
 
-config DEBUG_KERNEL
-	bool "Kernel debugging"
-	help
-	  Say Y here if you are developing drivers or trying to debug and
-	  identify kernel problems.
-
 config MAGIC_SYSRQ
 	bool "Magic SysRq key"
-	depends on DEBUG_KERNEL && !UML
+	depends on !UML
 	help
 	  If you say Y here, you will have some control over the system even
 	  if the system crashes for example during kernel debugging (e.g., you
@@ -29,6 +23,12 @@
 	  keys are documented in <file:Documentation/sysrq.txt>. Don't say Y
 	  unless you really know what this hack does.
 
+config DEBUG_KERNEL
+	bool "Kernel debugging"
+	help
+	  Say Y here if you are developing drivers or trying to debug and
+	  identify kernel problems.
+
 config LOG_BUF_SHIFT
 	int "Kernel log buffer size (16 => 64KB, 17 => 128KB)" if DEBUG_KERNEL
 	range 12 21
diff --git a/lib/spinlock_debug.c b/lib/spinlock_debug.c
index dcd4be9..c8bb8cc 100644
--- a/lib/spinlock_debug.c
+++ b/lib/spinlock_debug.c
@@ -19,10 +19,11 @@
 	if (xchg(&print_once, 0)) {
 		if (lock->owner && lock->owner != SPINLOCK_OWNER_INIT)
 			owner = lock->owner;
-		printk("BUG: spinlock %s on CPU#%d, %s/%d\n",
+		printk(KERN_EMERG "BUG: spinlock %s on CPU#%d, %s/%d\n",
 			msg, raw_smp_processor_id(),
 			current->comm, current->pid);
-		printk(" lock: %p, .magic: %08x, .owner: %s/%d, .owner_cpu: %d\n",
+		printk(KERN_EMERG " lock: %p, .magic: %08x, .owner: %s/%d, "
+				".owner_cpu: %d\n",
 			lock, lock->magic,
 			owner ? owner->comm : "<none>",
 			owner ? owner->pid : -1,
@@ -78,7 +79,8 @@
 		/* lockup suspected: */
 		if (print_once) {
 			print_once = 0;
-			printk("BUG: spinlock lockup on CPU#%d, %s/%d, %p\n",
+			printk(KERN_EMERG "BUG: spinlock lockup on CPU#%d, "
+					"%s/%d, %p\n",
 				raw_smp_processor_id(), current->comm,
 				current->pid, lock);
 			dump_stack();
@@ -120,8 +122,8 @@
 	static long print_once = 1;
 
 	if (xchg(&print_once, 0)) {
-		printk("BUG: rwlock %s on CPU#%d, %s/%d, %p\n", msg,
-			raw_smp_processor_id(), current->comm,
+		printk(KERN_EMERG "BUG: rwlock %s on CPU#%d, %s/%d, %p\n",
+			msg, raw_smp_processor_id(), current->comm,
 			current->pid, lock);
 		dump_stack();
 #ifdef CONFIG_SMP
@@ -149,7 +151,8 @@
 		/* lockup suspected: */
 		if (print_once) {
 			print_once = 0;
-			printk("BUG: read-lock lockup on CPU#%d, %s/%d, %p\n",
+			printk(KERN_EMERG "BUG: read-lock lockup on CPU#%d, "
+					"%s/%d, %p\n",
 				raw_smp_processor_id(), current->comm,
 				current->pid, lock);
 			dump_stack();
@@ -221,7 +224,8 @@
 		/* lockup suspected: */
 		if (print_once) {
 			print_once = 0;
-			printk("BUG: write-lock lockup on CPU#%d, %s/%d, %p\n",
+			printk(KERN_EMERG "BUG: write-lock lockup on CPU#%d, "
+					"%s/%d, %p\n",
 				raw_smp_processor_id(), current->comm,
 				current->pid, lock);
 			dump_stack();
diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index 3b48205..0af497b 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -463,7 +463,7 @@
 		 */
 		dma_addr_t handle;
 		handle = swiotlb_map_single(NULL, NULL, size, DMA_FROM_DEVICE);
-		if (dma_mapping_error(handle))
+		if (swiotlb_dma_mapping_error(handle))
 			return NULL;
 
 		ret = phys_to_virt(handle);
diff --git a/lib/zlib_deflate/deflate.c b/lib/zlib_deflate/deflate.c
index ad9a1bf..1653dd9 100644
--- a/lib/zlib_deflate/deflate.c
+++ b/lib/zlib_deflate/deflate.c
@@ -255,6 +255,7 @@
 }
 
 /* ========================================================================= */
+#if 0
 int zlib_deflateSetDictionary(
 	z_streamp strm,
 	const Byte *dictionary,
@@ -297,6 +298,7 @@
     if (hash_head) hash_head = 0;  /* to make compiler happy */
     return Z_OK;
 }
+#endif  /*  0  */
 
 /* ========================================================================= */
 int zlib_deflateReset(
@@ -330,6 +332,7 @@
 }
 
 /* ========================================================================= */
+#if 0
 int zlib_deflateParams(
 	z_streamp strm,
 	int level,
@@ -365,6 +368,7 @@
     s->strategy = strategy;
     return err;
 }
+#endif  /*  0  */
 
 /* =========================================================================
  * Put a short in the pending buffer. The 16-bit value is put in MSB order.
@@ -572,6 +576,7 @@
 /* =========================================================================
  * Copy the source state to the destination state.
  */
+#if 0
 int zlib_deflateCopy (
 	z_streamp dest,
 	z_streamp source
@@ -624,6 +629,7 @@
     return Z_OK;
 #endif
 }
+#endif  /*  0  */
 
 /* ===========================================================================
  * Read a new buffer from the current input stream, update the adler32
diff --git a/lib/zlib_deflate/deflate_syms.c b/lib/zlib_deflate/deflate_syms.c
index 5985b28..767b573 100644
--- a/lib/zlib_deflate/deflate_syms.c
+++ b/lib/zlib_deflate/deflate_syms.c
@@ -16,6 +16,4 @@
 EXPORT_SYMBOL(zlib_deflateInit2_);
 EXPORT_SYMBOL(zlib_deflateEnd);
 EXPORT_SYMBOL(zlib_deflateReset);
-EXPORT_SYMBOL(zlib_deflateCopy);
-EXPORT_SYMBOL(zlib_deflateParams);
 MODULE_LICENSE("GPL");
diff --git a/lib/zlib_inflate/infblock.c b/lib/zlib_inflate/infblock.c
index 50f21ca4..c16cdef 100644
--- a/lib/zlib_inflate/infblock.c
+++ b/lib/zlib_inflate/infblock.c
@@ -338,6 +338,7 @@
 }
 
 
+#if 0
 void zlib_inflate_set_dictionary(
 	inflate_blocks_statef *s,
 	const Byte *d,
@@ -347,15 +348,18 @@
   memcpy(s->window, d, n);
   s->read = s->write = s->window + n;
 }
+#endif  /*  0  */
 
 
 /* Returns true if inflate is currently at the end of a block generated
  * by Z_SYNC_FLUSH or Z_FULL_FLUSH. 
  * IN assertion: s != NULL
  */
+#if 0
 int zlib_inflate_blocks_sync_point(
 	inflate_blocks_statef *s
 )
 {
   return s->mode == LENS;
 }
+#endif  /*  0  */
diff --git a/lib/zlib_inflate/infblock.h b/lib/zlib_inflate/infblock.h
index f5221dd..ceee60b 100644
--- a/lib/zlib_inflate/infblock.h
+++ b/lib/zlib_inflate/infblock.h
@@ -33,12 +33,16 @@
     inflate_blocks_statef *,
     z_streamp);
 
+#if 0
 extern void zlib_inflate_set_dictionary (
     inflate_blocks_statef *s,
     const Byte *d,  /* dictionary */
     uInt  n);       /* dictionary length */
+#endif  /*  0  */
 
+#if 0
 extern int zlib_inflate_blocks_sync_point (
     inflate_blocks_statef *s);
+#endif  /*  0  */
 
 #endif /* _INFBLOCK_H */
diff --git a/lib/zlib_inflate/inflate_syms.c b/lib/zlib_inflate/inflate_syms.c
index aa1b081..ef49738 100644
--- a/lib/zlib_inflate/inflate_syms.c
+++ b/lib/zlib_inflate/inflate_syms.c
@@ -15,8 +15,6 @@
 EXPORT_SYMBOL(zlib_inflateInit_);
 EXPORT_SYMBOL(zlib_inflateInit2_);
 EXPORT_SYMBOL(zlib_inflateEnd);
-EXPORT_SYMBOL(zlib_inflateSync);
 EXPORT_SYMBOL(zlib_inflateReset);
-EXPORT_SYMBOL(zlib_inflateSyncPoint);
 EXPORT_SYMBOL(zlib_inflateIncomp); 
 MODULE_LICENSE("GPL");
diff --git a/lib/zlib_inflate/inflate_sync.c b/lib/zlib_inflate/inflate_sync.c
index e07bdb2..61411ff 100644
--- a/lib/zlib_inflate/inflate_sync.c
+++ b/lib/zlib_inflate/inflate_sync.c
@@ -7,6 +7,7 @@
 #include "infblock.h"
 #include "infutil.h"
 
+#if 0
 int zlib_inflateSync(
 	z_streamp z
 )
@@ -57,6 +58,7 @@
   z->state->mode = BLOCKS;
   return Z_OK;
 }
+#endif  /*  0  */
 
 
 /* Returns true if inflate is currently at the end of a block generated
@@ -66,6 +68,7 @@
  * decompressing, PPP checks that at the end of input packet, inflate is
  * waiting for these length bytes.
  */
+#if 0
 int zlib_inflateSyncPoint(
 	z_streamp z
 )
@@ -74,6 +77,7 @@
     return Z_STREAM_ERROR;
   return zlib_inflate_blocks_sync_point(z->state->blocks);
 }
+#endif  /*  0  */
 
 /*
  * This subroutine adds the data at next_in/avail_in to the output history
diff --git a/mm/filemap.c b/mm/filemap.c
index 5fca273..a965b6b 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -15,6 +15,7 @@
 #include <linux/compiler.h>
 #include <linux/fs.h>
 #include <linux/aio.h>
+#include <linux/capability.h>
 #include <linux/kernel_stat.h>
 #include <linux/mm.h>
 #include <linux/swap.h>
@@ -2108,7 +2109,7 @@
 	if (err)
 		goto out;
 
-	inode_update_time(inode, 1);
+	file_update_time(file);
 
 	/* coalesce the iovecs and go direct-to-BIO for O_DIRECT */
 	if (unlikely(file->f_flags & O_DIRECT)) {
diff --git a/mm/filemap_xip.c b/mm/filemap_xip.c
index e2b34e9..b960ac8 100644
--- a/mm/filemap_xip.c
+++ b/mm/filemap_xip.c
@@ -383,7 +383,7 @@
 	if (ret)
 		goto out_backing;
 
-	inode_update_time(inode, 1);
+	file_update_time(filp);
 
 	ret = __xip_file_write (filp, buf, count, pos, ppos);
 
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 1850d0a..b62cab5 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -208,6 +208,8 @@
 		page = vm_normal_page(vma, addr, *pte);
 		if (!page)
 			continue;
+		if (PageReserved(page))
+			continue;
 		nid = page_to_nid(page);
 		if (node_isset(nid, *nodes) == !!(flags & MPOL_MF_INVERT))
 			continue;
@@ -290,7 +292,7 @@
 static inline int vma_migratable(struct vm_area_struct *vma)
 {
 	if (vma->vm_flags & (
-		VM_LOCKED|VM_IO|VM_HUGETLB|VM_PFNMAP))
+		VM_LOCKED|VM_IO|VM_HUGETLB|VM_PFNMAP|VM_RESERVED))
 		return 0;
 	return 1;
 }
diff --git a/mm/mlock.c b/mm/mlock.c
index 4ae3a46f..b90c595 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -5,6 +5,7 @@
  *  (C) Copyright 2002 Christoph Hellwig
  */
 
+#include <linux/capability.h>
 #include <linux/mman.h>
 #include <linux/mm.h>
 #include <linux/mempolicy.h>
diff --git a/mm/mmap.c b/mm/mmap.c
index 64ba4db..47556d2 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -13,6 +13,7 @@
 #include <linux/pagemap.h>
 #include <linux/swap.h>
 #include <linux/syscalls.h>
+#include <linux/capability.h>
 #include <linux/init.h>
 #include <linux/file.h>
 #include <linux/fs.h>
diff --git a/mm/mremap.c b/mm/mremap.c
index ddaeee9..1903bdf 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -13,6 +13,7 @@
 #include <linux/shm.h>
 #include <linux/mman.h>
 #include <linux/swap.h>
+#include <linux/capability.h>
 #include <linux/fs.h>
 #include <linux/highmem.h>
 #include <linux/security.h>
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index a5e6891..8c960b4 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -137,9 +137,9 @@
 static void bad_page(struct page *page)
 {
 	printk(KERN_EMERG "Bad page state in process '%s'\n"
-		"page:%p flags:0x%0*lx mapping:%p mapcount:%d count:%d\n"
-		"Trying to fix it up, but a reboot is needed\n"
-		"Backtrace:\n",
+		KERN_EMERG "page:%p flags:0x%0*lx mapping:%p mapcount:%d count:%d\n"
+		KERN_EMERG "Trying to fix it up, but a reboot is needed\n"
+		KERN_EMERG "Backtrace:\n",
 		current->comm, page, (int)(2*sizeof(unsigned long)),
 		(unsigned long)page->flags, page->mapping,
 		page_mapcount(page), page_count(page));
@@ -417,7 +417,7 @@
 	arch_free_page(page, order);
 	if (!PageHighMem(page))
 		mutex_debug_check_no_locks_freed(page_address(page),
-			page_address(page+(1<<order)));
+						 PAGE_SIZE<<order);
 
 #ifndef CONFIG_MMU
 	for (i = 1 ; i < (1 << order) ; ++i)
@@ -931,7 +931,8 @@
 	 *
 	 * The caller may dip into page reserves a bit more if the caller
 	 * cannot run direct reclaim, or if the caller has realtime scheduling
-	 * policy.
+	 * policy or is asking for __GFP_HIGH memory.  GFP_ATOMIC requests will
+	 * set both ALLOC_HARDER (!wait) and ALLOC_HIGH (__GFP_HIGH).
 	 */
 	alloc_flags = ALLOC_WMARK_MIN;
 	if ((unlikely(rt_task(p)) && !in_interrupt()) || !wait)
@@ -1741,7 +1742,7 @@
 	unsigned long end_pfn = start_pfn + size;
 	unsigned long pfn;
 
-	for (pfn = start_pfn; pfn < end_pfn; pfn++, page++) {
+	for (pfn = start_pfn; pfn < end_pfn; pfn++) {
 		if (!early_pfn_valid(pfn))
 			continue;
 		page = pfn_to_page(pfn);
diff --git a/mm/slab.c b/mm/slab.c
index 33aab34..9374293 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -3071,7 +3071,7 @@
 	local_irq_save(flags);
 	kfree_debugcheck(objp);
 	c = page_get_cache(virt_to_page(objp));
-	mutex_debug_check_no_locks_freed(objp, objp+obj_reallen(c));
+	mutex_debug_check_no_locks_freed(objp, obj_reallen(c));
 	__cache_free(c, (void *)objp);
 	local_irq_restore(flags);
 }
diff --git a/mm/swap.c b/mm/swap.c
index ee6d71c..cbb48e7 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -384,6 +384,8 @@
 	return pagevec_count(pvec);
 }
 
+EXPORT_SYMBOL(pagevec_lookup);
+
 unsigned pagevec_lookup_tag(struct pagevec *pvec, struct address_space *mapping,
 		pgoff_t *index, int tag, unsigned nr_pages)
 {
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 6544565..957fef4 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -25,6 +25,7 @@
 #include <linux/rmap.h>
 #include <linux/security.h>
 #include <linux/backing-dev.h>
+#include <linux/capability.h>
 #include <linux/syscalls.h>
 
 #include <asm/pgtable.h>
@@ -1442,7 +1443,7 @@
 	else if (!memcmp("SWAPSPACE2",swap_header->magic.magic,10))
 		swap_header_version = 2;
 	else {
-		printk("Unable to find swap-space signature\n");
+		printk(KERN_ERR "Unable to find swap-space signature\n");
 		error = -EINVAL;
 		goto bad_swap;
 	}
diff --git a/mm/tiny-shmem.c b/mm/tiny-shmem.c
index cdc6d43..f9d6a9c 100644
--- a/mm/tiny-shmem.c
+++ b/mm/tiny-shmem.c
@@ -90,7 +90,7 @@
 	file->f_mode = FMODE_WRITE | FMODE_READ;
 
 	/* notify everyone as to the change of file size */
-	error = do_truncate(dentry, size, file);
+	error = do_truncate(dentry, size, 0, file);
 	if (error < 0)
 		goto close_file;
 
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index 67465b6..fa76220 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -19,6 +19,7 @@
  */
 
 #include <asm/uaccess.h> /* for copy_from_user */
+#include <linux/capability.h>
 #include <linux/module.h>
 #include <linux/netdevice.h>
 #include <linux/skbuff.h>
diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c
index f2a8750..0f604d22 100644
--- a/net/8021q/vlan_dev.c
+++ b/net/8021q/vlan_dev.c
@@ -214,7 +214,7 @@
 		 * This allows the VLAN to have a different MAC than the underlying
 		 * device, and still route correctly.
 		 */
-		if (memcmp(eth_hdr(skb)->h_dest, skb->dev->dev_addr, ETH_ALEN) == 0) {
+		if (!compare_ether_addr(eth_hdr(skb)->h_dest, skb->dev->dev_addr)) {
 			/* It is for our (changed) MAC-address! */
 			skb->pkt_type = PACKET_HOST;
 		}
diff --git a/net/appletalk/ddp.c b/net/appletalk/ddp.c
index a5144e4..697ac55e 100644
--- a/net/appletalk/ddp.c
+++ b/net/appletalk/ddp.c
@@ -52,6 +52,7 @@
  */
 
 #include <linux/config.h>
+#include <linux/capability.h>
 #include <linux/module.h>
 #include <linux/if_arp.h>
 #include <linux/termios.h>	/* For TIOCOUTQ/INQ */
diff --git a/net/atm/br2684.c b/net/atm/br2684.c
index bdb4d89..680ccb1 100644
--- a/net/atm/br2684.c
+++ b/net/atm/br2684.c
@@ -18,6 +18,7 @@
 #include <net/arp.h>
 #include <linux/atm.h>
 #include <linux/atmdev.h>
+#include <linux/capability.h>
 #include <linux/seq_file.h>
 
 #include <linux/atmbr2684.h>
@@ -296,13 +297,13 @@
 	eth = eth_hdr(skb);
 
 	if (is_multicast_ether_addr(eth->h_dest)) {
-		if (memcmp(eth->h_dest, dev->broadcast, ETH_ALEN) == 0)
+		if (!compare_ether_addr(eth->h_dest, dev->broadcast))
 			skb->pkt_type = PACKET_BROADCAST;
 		else
 			skb->pkt_type = PACKET_MULTICAST;
 	}
 
-	else if (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN))
+	else if (compare_ether_addr(eth->h_dest, dev->dev_addr))
 		skb->pkt_type = PACKET_OTHERHOST;
 
 	if (ntohs(eth->h_proto) >= 1536)
diff --git a/net/atm/clip.c b/net/atm/clip.c
index 4f54c9a..73370de 100644
--- a/net/atm/clip.c
+++ b/net/atm/clip.c
@@ -19,6 +19,7 @@
 #include <linux/atmdev.h>
 #include <linux/atmclip.h>
 #include <linux/atmarp.h>
+#include <linux/capability.h>
 #include <linux/ip.h> /* for net/route.h */
 #include <linux/in.h> /* for struct sockaddr_in */
 #include <linux/if.h> /* for IFF_UP */
diff --git a/net/atm/ioctl.c b/net/atm/ioctl.c
index a150198..eb109af 100644
--- a/net/atm/ioctl.c
+++ b/net/atm/ioctl.c
@@ -12,6 +12,7 @@
 #include <linux/atmdev.h>
 #include <linux/atmclip.h>	/* CLIP_*ENCAP */
 #include <linux/atmarp.h>	/* manifest constants */
+#include <linux/capability.h>
 #include <linux/sonet.h>	/* for ioctls */
 #include <linux/atmsvc.h>
 #include <linux/atmmpc.h>
diff --git a/net/atm/lec.c b/net/atm/lec.c
index ad840b9..c4fc722 100644
--- a/net/atm/lec.c
+++ b/net/atm/lec.c
@@ -7,6 +7,7 @@
 #include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/bitops.h>
+#include <linux/capability.h>
 
 /* We are ethernet device */
 #include <linux/if_ether.h>
@@ -1321,7 +1322,7 @@
         struct sk_buff *skb;
         struct lec_priv *priv = (struct lec_priv*)dev->priv;
 
-        if ( memcmp(lan_dst, dev->dev_addr, ETH_ALEN) != 0 )
+        if (compare_ether_addr(lan_dst, dev->dev_addr))
                 return (0);       /* not our mac address */
 
         kfree(priv->tlvs); /* NULL if there was no previous association */
@@ -1798,7 +1799,7 @@
   
         to_return = priv->lec_arp_tables[place];
         while(to_return) {
-                if (memcmp(mac_addr, to_return->mac_addr, ETH_ALEN) == 0) {
+                if (!compare_ether_addr(mac_addr, to_return->mac_addr)) {
                         return to_return;
                 }
                 to_return = to_return->next;
@@ -1811,8 +1812,7 @@
 {
         struct lec_arp_table *to_return;
 
-        to_return = (struct lec_arp_table *) kmalloc(sizeof(struct lec_arp_table),
-						     GFP_ATOMIC);
+        to_return = kmalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
         if (!to_return) {
                 printk("LEC: Arp entry kmalloc failed\n");
                 return NULL;
@@ -2002,7 +2002,7 @@
                         return priv->mcast_vcc;
                         break;
                 case 2:  /* LANE2 wants arp for multicast addresses */
-                        if ( memcmp(mac_to_find, bus_mac, ETH_ALEN) == 0)
+                        if (!compare_ether_addr(mac_to_find, bus_mac))
                                 return priv->mcast_vcc;
                         break;
                 default:
diff --git a/net/atm/mpc.c b/net/atm/mpc.c
index 526d953..c304ef1 100644
--- a/net/atm/mpc.c
+++ b/net/atm/mpc.c
@@ -3,6 +3,7 @@
 #include <linux/timer.h>
 #include <linux/init.h>
 #include <linux/bitops.h>
+#include <linux/capability.h>
 #include <linux/seq_file.h>
 
 /* We are an ethernet device */
@@ -552,7 +553,7 @@
 		goto non_ip; /* Multi-Protocol Over ATM :-) */
 
 	while (i < mpc->number_of_mps_macs) {
-		if (memcmp(eth->h_dest, (mpc->mps_macs + i*ETH_ALEN), ETH_ALEN) == 0)
+		if (!compare_ether_addr(eth->h_dest, (mpc->mps_macs + i*ETH_ALEN)))
 			if ( send_via_shortcut(skb, mpc) == 0 )           /* try shortcut */
 				return 0;                                 /* success!     */
 		i++;
diff --git a/net/atm/pppoatm.c b/net/atm/pppoatm.c
index 58f4a2b..1489067 100644
--- a/net/atm/pppoatm.c
+++ b/net/atm/pppoatm.c
@@ -39,6 +39,7 @@
 #include <linux/skbuff.h>
 #include <linux/atm.h>
 #include <linux/atmdev.h>
+#include <linux/capability.h>
 #include <linux/ppp_defs.h>
 #include <linux/if_ppp.h>
 #include <linux/ppp_channel.h>
diff --git a/net/atm/raw.c b/net/atm/raw.c
index 4a0466e..3e57b17 100644
--- a/net/atm/raw.c
+++ b/net/atm/raw.c
@@ -6,6 +6,7 @@
 #include <linux/module.h>
 #include <linux/sched.h>
 #include <linux/atmdev.h>
+#include <linux/capability.h>
 #include <linux/kernel.h>
 #include <linux/skbuff.h>
 #include <linux/mm.h>
diff --git a/net/atm/resources.c b/net/atm/resources.c
index c8c459f..2241905 100644
--- a/net/atm/resources.c
+++ b/net/atm/resources.c
@@ -16,6 +16,7 @@
 #include <linux/kernel.h> /* for barrier */
 #include <linux/module.h>
 #include <linux/bitops.h>
+#include <linux/capability.h>
 #include <linux/delay.h>
 #include <net/sock.h>	 /* for struct sock */
 
diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c
index e8753c7..dbf9b47 100644
--- a/net/ax25/af_ax25.c
+++ b/net/ax25/af_ax25.c
@@ -14,6 +14,7 @@
  * Copyright (C) Frederic Rible F1OAT (frible@teaser.fr)
  */
 #include <linux/config.h>
+#include <linux/capability.h>
 #include <linux/module.h>
 #include <linux/errno.h>
 #include <linux/types.h>
diff --git a/net/ax25/ax25_route.c b/net/ax25/ax25_route.c
index b1e945bd..f04f863 100644
--- a/net/ax25/ax25_route.c
+++ b/net/ax25/ax25_route.c
@@ -11,6 +11,8 @@
  * Copyright (C) Hans-Joachim Hetscher DD8NE (dd8ne@bnv-bamberg.de)
  * Copyright (C) Frederic Rible F1OAT (frible@teaser.fr)
  */
+
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/types.h>
 #include <linux/socket.h>
diff --git a/net/ax25/ax25_uid.c b/net/ax25/ax25_uid.c
index d53cc86..b8b5854 100644
--- a/net/ax25/ax25_uid.c
+++ b/net/ax25/ax25_uid.c
@@ -6,6 +6,8 @@
  *
  * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
  */
+
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/types.h>
 #include <linux/socket.h>
diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
index 682bf20..cbb20c3 100644
--- a/net/bluetooth/bnep/core.c
+++ b/net/bluetooth/bnep/core.c
@@ -75,7 +75,7 @@
 
 	list_for_each(p, &bnep_session_list) {
 		s = list_entry(p, struct bnep_session, list);	
-		if (!memcmp(dst, s->eh.h_source, ETH_ALEN))
+		if (!compare_ether_addr(dst, s->eh.h_source))
 			return s;
 	}
 	return NULL;
@@ -420,10 +420,10 @@
 	iv[il++] = (struct kvec) { &type, 1 };
 	len++;
 
-	if (!memcmp(eh->h_dest, s->eh.h_source, ETH_ALEN))
+	if (!compare_ether_addr(eh->h_dest, s->eh.h_source))
 		type |= 0x01;
 
-	if (!memcmp(eh->h_source, s->eh.h_dest, ETH_ALEN))
+	if (!compare_ether_addr(eh->h_source, s->eh.h_dest))
 		type |= 0x02;
 
 	if (type)
diff --git a/net/bluetooth/bnep/sock.c b/net/bluetooth/bnep/sock.c
index ccbaf69..2bfe796 100644
--- a/net/bluetooth/bnep/sock.c
+++ b/net/bluetooth/bnep/sock.c
@@ -32,6 +32,7 @@
 #include <linux/module.h>
 
 #include <linux/types.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
diff --git a/net/bluetooth/cmtp/sock.c b/net/bluetooth/cmtp/sock.c
index 5e22343..8f8fad2 100644
--- a/net/bluetooth/cmtp/sock.c
+++ b/net/bluetooth/cmtp/sock.c
@@ -24,6 +24,7 @@
 #include <linux/module.h>
 
 #include <linux/types.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index a31244e..f812ed1 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -403,7 +403,7 @@
 
 	size = sizeof(req) + req.conn_num * sizeof(*ci);
 
-	if (!(cl = (void *) kmalloc(size, GFP_KERNEL)))
+	if (!(cl = kmalloc(size, GFP_KERNEL)))
 		return -ENOMEM;
 
 	if (!(hdev = hci_dev_get(req.dev_id))) {
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 84e6c93..bdb6458 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -28,6 +28,7 @@
 #include <linux/module.h>
 
 #include <linux/types.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
diff --git a/net/bluetooth/hidp/sock.c b/net/bluetooth/hidp/sock.c
index 8f8dd93..b8f6776 100644
--- a/net/bluetooth/hidp/sock.c
+++ b/net/bluetooth/hidp/sock.c
@@ -24,6 +24,7 @@
 #include <linux/module.h>
 
 #include <linux/types.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
index 7f0781e..f6b4a80 100644
--- a/net/bluetooth/l2cap.c
+++ b/net/bluetooth/l2cap.c
@@ -28,6 +28,7 @@
 #include <linux/module.h>
 
 #include <linux/types.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index 158a9c4..74368f7 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -34,6 +34,7 @@
 #include <linux/tty_driver.h>
 #include <linux/tty_flip.h>
 
+#include <linux/capability.h>
 #include <linux/slab.h>
 #include <linux/skbuff.h>
 
@@ -480,13 +481,8 @@
 	BT_DBG("dlc %p tty %p len %d", dlc, tty, skb->len);
 
 	if (test_bit(TTY_DONT_FLIP, &tty->flags)) {
-		register int i;
-		for (i = 0; i < skb->len; i++) {
-			if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-				tty_flip_buffer_push(tty);
-
-			tty_insert_flip_char(tty, skb->data[i], 0);
-		}
+		tty_buffer_request_room(tty, skb->len);
+		tty_insert_flip_string(tty, skb->data, skb->len);
 		tty_flip_buffer_push(tty);
 	} else
 		tty->ldisc.receive_buf(tty, skb->data, NULL, skb->len);
diff --git a/net/bridge/br_ioctl.c b/net/bridge/br_ioctl.c
index b8ce14b..159fb84 100644
--- a/net/bridge/br_ioctl.c
+++ b/net/bridge/br_ioctl.c
@@ -13,6 +13,7 @@
  *	2 of the License, or (at your option) any later version.
  */
 
+#include <linux/capability.h>
 #include <linux/kernel.h>
 #include <linux/if_bridge.h>
 #include <linux/netdevice.h>
diff --git a/net/bridge/br_sysfs_br.c b/net/bridge/br_sysfs_br.c
index 98cf53c..6f577f1 100644
--- a/net/bridge/br_sysfs_br.c
+++ b/net/bridge/br_sysfs_br.c
@@ -11,6 +11,7 @@
  *	2 of the License, or (at your option) any later version.
  */
 
+#include <linux/capability.h>
 #include <linux/kernel.h>
 #include <linux/netdevice.h>
 #include <linux/if_bridge.h>
diff --git a/net/bridge/br_sysfs_if.c b/net/bridge/br_sysfs_if.c
index 2ebdc23..0ac0355 100644
--- a/net/bridge/br_sysfs_if.c
+++ b/net/bridge/br_sysfs_if.c
@@ -11,6 +11,7 @@
  *	2 of the License, or (at your option) any later version.
  */
 
+#include <linux/capability.h>
 #include <linux/kernel.h>
 #include <linux/netdevice.h>
 #include <linux/if_bridge.h>
diff --git a/net/bridge/netfilter/ebt_ip.c b/net/bridge/netfilter/ebt_ip.c
index 7323805..f158fe6 100644
--- a/net/bridge/netfilter/ebt_ip.c
+++ b/net/bridge/netfilter/ebt_ip.c
@@ -15,6 +15,7 @@
 #include <linux/netfilter_bridge/ebtables.h>
 #include <linux/netfilter_bridge/ebt_ip.h>
 #include <linux/ip.h>
+#include <net/ip.h>
 #include <linux/in.h>
 #include <linux/module.h>
 
@@ -51,6 +52,8 @@
 		if (!(info->bitmask & EBT_IP_DPORT) &&
 		    !(info->bitmask & EBT_IP_SPORT))
 			return EBT_MATCH;
+		if (ntohs(ih->frag_off) & IP_OFFSET)
+			return EBT_NOMATCH;
 		pptr = skb_header_pointer(skb, ih->ihl*4,
 					  sizeof(_ports), &_ports);
 		if (pptr == NULL)
diff --git a/net/bridge/netfilter/ebt_stp.c b/net/bridge/netfilter/ebt_stp.c
index f8a8cde..0248c67 100644
--- a/net/bridge/netfilter/ebt_stp.c
+++ b/net/bridge/netfilter/ebt_stp.c
@@ -10,6 +10,7 @@
 
 #include <linux/netfilter_bridge/ebtables.h>
 #include <linux/netfilter_bridge/ebt_stp.h>
+#include <linux/etherdevice.h>
 #include <linux/module.h>
 
 #define BPDU_TYPE_CONFIG 0
@@ -164,8 +165,8 @@
 	if (datalen != len)
 		return -EINVAL;
 	/* Make sure the match only receives stp frames */
-	if (memcmp(e->destmac, bridge_ula, ETH_ALEN) ||
-	    memcmp(e->destmsk, msk, ETH_ALEN) || !(e->bitmask & EBT_DESTMAC))
+	if (compare_ether_addr(e->destmac, bridge_ula) ||
+	    compare_ether_addr(e->destmsk, msk) || !(e->bitmask & EBT_DESTMAC))
 		return -EINVAL;
 
 	return 0;
diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
index f8ffbf6..00729b3 100644
--- a/net/bridge/netfilter/ebtables.c
+++ b/net/bridge/netfilter/ebtables.c
@@ -944,7 +944,7 @@
 	if (countersize)
 		memset(newinfo->counters, 0, countersize);
 
-	newinfo->entries = (char *)vmalloc(tmp.entries_size);
+	newinfo->entries = vmalloc(tmp.entries_size);
 	if (!newinfo->entries) {
 		ret = -ENOMEM;
 		goto free_newinfo;
@@ -1146,7 +1146,7 @@
 	if (!newinfo)
 		return -ENOMEM;
 
-	newinfo->entries = (char *)vmalloc(table->table->entries_size);
+	newinfo->entries = vmalloc(table->table->entries_size);
 	if (!(newinfo->entries))
 		goto free_newinfo;
 
diff --git a/net/core/dev.c b/net/core/dev.c
index bf66b11..fd070a0 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -75,6 +75,7 @@
 #include <asm/uaccess.h>
 #include <asm/system.h>
 #include <linux/bitops.h>
+#include <linux/capability.h>
 #include <linux/config.h>
 #include <linux/cpu.h>
 #include <linux/types.h>
diff --git a/net/core/dev_mcast.c b/net/core/dev_mcast.c
index cb530ee..05d60850 100644
--- a/net/core/dev_mcast.c
+++ b/net/core/dev_mcast.c
@@ -158,7 +158,7 @@
 	int err = 0;
 	struct dev_mc_list *dmi, *dmi1;
 
-	dmi1 = (struct dev_mc_list *)kmalloc(sizeof(*dmi), GFP_ATOMIC);
+	dmi1 = kmalloc(sizeof(*dmi), GFP_ATOMIC);
 
 	spin_lock_bh(&dev->xmit_lock);
 	for (dmi = dev->mc_list; dmi != NULL; dmi = dmi->next) {
diff --git a/net/core/dv.c b/net/core/dv.c
index 3f25f4a..cf58140 100644
--- a/net/core/dv.c
+++ b/net/core/dv.c
@@ -24,6 +24,7 @@
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
 #include <linux/skbuff.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/init.h>
 #include <net/dst.h>
@@ -457,7 +458,7 @@
 	unsigned char			*skb_data_end = skb->data + skb->len;
 
 	/* Packet is already aimed at us, return */
-	if (!memcmp(eth, skb->dev->dev_addr, ETH_ALEN))
+	if (!compare_ether_addr(eth->h_dest, skb->dev->dev_addr))
 		return;
 	
 	/* proto is not IP, do nothing */
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index 0350586..e6f7610 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -11,6 +11,7 @@
 
 #include <linux/module.h>
 #include <linux/types.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/ethtool.h>
 #include <linux/netdevice.h>
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index e1da81d..e8b2acb 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -9,6 +9,7 @@
  *	2 of the License, or (at your option) any later version.
  */
 
+#include <linux/capability.h>
 #include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/netdevice.h>
@@ -16,6 +17,7 @@
 #include <net/sock.h>
 #include <linux/rtnetlink.h>
 #include <linux/wireless.h>
+#include <net/iw_handler.h>
 
 #define to_class_dev(obj) container_of(obj,struct class_device,kobj)
 #define to_net_dev(class) container_of(class, struct net_device, class_dev)
@@ -294,13 +296,19 @@
 					       char *))
 {
 	struct net_device *dev = to_net_dev(cd);
-	const struct iw_statistics *iw;
+	const struct iw_statistics *iw = NULL;
 	ssize_t ret = -EINVAL;
 	
 	read_lock(&dev_base_lock);
-	if (dev_isalive(dev) && dev->get_wireless_stats 
-	    && (iw = dev->get_wireless_stats(dev)) != NULL) 
-		ret = (*format)(iw, buf);
+	if (dev_isalive(dev)) {
+		if(dev->wireless_handlers &&
+		   dev->wireless_handlers->get_wireless_stats)
+			iw = dev->wireless_handlers->get_wireless_stats(dev);
+		else if (dev->get_wireless_stats)
+			iw = dev->get_wireless_stats(dev);
+		if (iw != NULL)
+			ret = (*format)(iw, buf);
+	}
 	read_unlock(&dev_base_lock);
 
 	return ret;
@@ -402,7 +410,8 @@
 		sysfs_remove_group(&class_dev->kobj, &netstat_group);
 
 #ifdef WIRELESS_EXT
-	if (net->get_wireless_stats)
+	if (net->get_wireless_stats || (net->wireless_handlers &&
+			net->wireless_handlers->get_wireless_stats))
 		sysfs_remove_group(&class_dev->kobj, &wireless_group);
 #endif
 	class_device_del(class_dev);
@@ -427,10 +436,12 @@
 		goto out_unreg; 
 
 #ifdef WIRELESS_EXT
-	if (net->get_wireless_stats &&
-	    (ret = sysfs_create_group(&class_dev->kobj, &wireless_group)))
-		goto out_cleanup; 
-
+	if (net->get_wireless_stats || (net->wireless_handlers &&
+			net->wireless_handlers->get_wireless_stats)) {
+		ret = sysfs_create_group(&class_dev->kobj, &wireless_group);
+		if (ret)
+			goto out_cleanup;
+	}
 	return 0;
 out_cleanup:
 	if (net->get_stats)
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 631056d..3906312 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -116,13 +116,13 @@
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
-#include <linux/sched.h>
 #include <linux/unistd.h>
 #include <linux/string.h>
 #include <linux/ptrace.h>
 #include <linux/errno.h>
 #include <linux/ioport.h>
 #include <linux/interrupt.h>
+#include <linux/capability.h>
 #include <linux/delay.h>
 #include <linux/timer.h>
 #include <linux/init.h>
diff --git a/net/core/scm.c b/net/core/scm.c
index e887d19..649d01e 100644
--- a/net/core/scm.c
+++ b/net/core/scm.c
@@ -11,6 +11,7 @@
 
 #include <linux/module.h>
 #include <linux/signal.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/sched.h>
 #include <linux/mm.h>
diff --git a/net/core/sock.c b/net/core/sock.c
index 6465b0e..6e00811 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -91,6 +91,7 @@
  *		2 of the License, or (at your option) any later version.
  */
 
+#include <linux/capability.h>
 #include <linux/config.h>
 #include <linux/errno.h>
 #include <linux/types.h>
diff --git a/net/core/wireless.c b/net/core/wireless.c
index 271ddb3..2add7ed 100644
--- a/net/core/wireless.c
+++ b/net/core/wireless.c
@@ -78,6 +78,7 @@
 #include <linux/seq_file.h>
 #include <linux/init.h>			/* for __init */
 #include <linux/if_arp.h>		/* ARPHRD_ETHER */
+#include <linux/etherdevice.h>		/* compare_ether_addr */
 
 #include <linux/wireless.h>		/* Pretty obvious */
 #include <net/iw_handler.h>		/* New driver API */
@@ -1506,7 +1507,7 @@
 
 	/* Update all records that match */
 	for(i = 0; i < spydata->spy_number; i++)
-		if(!memcmp(address, spydata->spy_address[i], ETH_ALEN)) {
+		if(!compare_ether_addr(address, spydata->spy_address[i])) {
 			memcpy(&(spydata->spy_stat[i]), wstats,
 			       sizeof(struct iw_quality));
 			match = i;
diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
index 78ec534..ce4aaf9 100644
--- a/net/decnet/af_decnet.c
+++ b/net/decnet/af_decnet.c
@@ -122,6 +122,7 @@
 #include <net/flow.h>
 #include <asm/system.h>
 #include <asm/ioctls.h>
+#include <linux/capability.h>
 #include <linux/mm.h>
 #include <linux/interrupt.h>
 #include <linux/proc_fs.h>
diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
index 5610bb1..efbead8 100644
--- a/net/decnet/dn_dev.c
+++ b/net/decnet/dn_dev.c
@@ -25,6 +25,7 @@
  */
 
 #include <linux/config.h>
+#include <linux/capability.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/init.h>
diff --git a/net/decnet/netfilter/dn_rtmsg.c b/net/decnet/netfilter/dn_rtmsg.c
index 1ab94c6..16a5a31 100644
--- a/net/decnet/netfilter/dn_rtmsg.c
+++ b/net/decnet/netfilter/dn_rtmsg.c
@@ -26,8 +26,6 @@
 #include <net/dn.h>
 #include <net/dn_route.h>
 
-#include <linux/netfilter_decnet.h>
-
 static struct sock *dnrmg = NULL;
 
 
diff --git a/net/ieee80211/ieee80211_rx.c b/net/ieee80211/ieee80211_rx.c
index 4cc6f41..5e33803 100644
--- a/net/ieee80211/ieee80211_rx.c
+++ b/net/ieee80211/ieee80211_rx.c
@@ -76,8 +76,8 @@
 
 		if (entry->skb != NULL && entry->seq == seq &&
 		    (entry->last_frag + 1 == frag || frag == -1) &&
-		    memcmp(entry->src_addr, src, ETH_ALEN) == 0 &&
-		    memcmp(entry->dst_addr, dst, ETH_ALEN) == 0)
+		    !compare_ether_addr(entry->src_addr, src) &&
+		    !compare_ether_addr(entry->dst_addr, dst))
 			return entry;
 	}
 
@@ -243,12 +243,12 @@
 	/* check that the frame is unicast frame to us */
 	if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
 	    IEEE80211_FCTL_TODS &&
-	    memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 &&
-	    memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
+	    !compare_ether_addr(hdr->addr1, dev->dev_addr) &&
+	    !compare_ether_addr(hdr->addr3, dev->dev_addr)) {
 		/* ToDS frame with own addr BSSID and DA */
 	} else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
 		   IEEE80211_FCTL_FROMDS &&
-		   memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
+		   !compare_ether_addr(hdr->addr1, dev->dev_addr)) {
 		/* FromDS frame with own addr as DA */
 	} else
 		return 0;
@@ -505,7 +505,7 @@
 	if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
 	    (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
 	    IEEE80211_FCTL_FROMDS && ieee->stadev
-	    && memcmp(hdr->addr2, ieee->assoc_ap_addr, ETH_ALEN) == 0) {
+	    && !compare_ether_addr(hdr->addr2, ieee->assoc_ap_addr)) {
 		/* Frame from BSSID of the AP for which we are a client */
 		skb->dev = dev = ieee->stadev;
 		stats = hostap_get_stats(dev);
@@ -1231,7 +1231,7 @@
 	 * as one network */
 	return ((src->ssid_len == dst->ssid_len) &&
 		(src->channel == dst->channel) &&
-		!memcmp(src->bssid, dst->bssid, ETH_ALEN) &&
+		!compare_ether_addr(src->bssid, dst->bssid) &&
 		!memcmp(src->ssid, dst->ssid, src->ssid_len));
 }
 
diff --git a/net/ipv4/Makefile b/net/ipv4/Makefile
index c54edd7..35e5f59 100644
--- a/net/ipv4/Makefile
+++ b/net/ipv4/Makefile
@@ -9,7 +9,7 @@
 	     tcp.o tcp_input.o tcp_output.o tcp_timer.o tcp_ipv4.o \
 	     tcp_minisocks.o tcp_cong.o \
 	     datagram.o raw.o udp.o arp.o icmp.o devinet.o af_inet.o igmp.o \
-	     sysctl_net_ipv4.o fib_frontend.o fib_semantics.o netfilter.o
+	     sysctl_net_ipv4.o fib_frontend.o fib_semantics.o
 
 obj-$(CONFIG_IP_FIB_HASH) += fib_hash.o
 obj-$(CONFIG_IP_FIB_TRIE) += fib_trie.o
@@ -28,7 +28,7 @@
 obj-$(CONFIG_IP_ROUTE_MULTIPATH_RANDOM) += multipath_random.o
 obj-$(CONFIG_IP_ROUTE_MULTIPATH_WRANDOM) += multipath_wrandom.o
 obj-$(CONFIG_IP_ROUTE_MULTIPATH_DRR) += multipath_drr.o
-obj-$(CONFIG_NETFILTER)	+= netfilter/
+obj-$(CONFIG_NETFILTER)	+= netfilter.o netfilter/
 obj-$(CONFIG_IP_VS) += ipvs/
 obj-$(CONFIG_INET_DIAG) += inet_diag.o 
 obj-$(CONFIG_IP_ROUTE_MULTIPATH_CACHED) += multipath.o
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 966a071..97c276f 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -79,6 +79,7 @@
 #include <linux/string.h>
 #include <linux/sockios.h>
 #include <linux/net.h>
+#include <linux/capability.h>
 #include <linux/fcntl.h>
 #include <linux/mm.h>
 #include <linux/interrupt.h>
diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c
index 3743208..accdefe 100644
--- a/net/ipv4/arp.c
+++ b/net/ipv4/arp.c
@@ -79,6 +79,7 @@
 #include <linux/string.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
+#include <linux/capability.h>
 #include <linux/config.h>
 #include <linux/socket.h>
 #include <linux/sockios.h>
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 7b9bb28..95b9d81 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -32,6 +32,7 @@
 #include <asm/uaccess.h>
 #include <asm/system.h>
 #include <linux/bitops.h>
+#include <linux/capability.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index 18f5e50..5b25fc0d 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -20,6 +20,7 @@
 #include <asm/uaccess.h>
 #include <asm/system.h>
 #include <linux/bitops.h>
+#include <linux/capability.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index 3475811..192092b 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -975,7 +975,7 @@
 	 * for deleted items allows change reports to use common code with
 	 * non-deleted or query-response MCA's.
 	 */
-	pmc = (struct ip_mc_list *)kmalloc(sizeof(*pmc), GFP_KERNEL);
+	pmc = kmalloc(sizeof(*pmc), GFP_KERNEL);
 	if (!pmc)
 		return;
 	memset(pmc, 0, sizeof(*pmc));
@@ -1155,7 +1155,7 @@
 		}
 	}
 
-	im = (struct ip_mc_list *)kmalloc(sizeof(*im), GFP_KERNEL);
+	im = kmalloc(sizeof(*im), GFP_KERNEL);
 	if (!im)
 		goto out;
 
@@ -1476,7 +1476,7 @@
 		psf_prev = psf;
 	}
 	if (!psf) {
-		psf = (struct ip_sf_list *)kmalloc(sizeof(*psf), GFP_ATOMIC);
+		psf = kmalloc(sizeof(*psf), GFP_ATOMIC);
 		if (!psf)
 			return -ENOBUFS;
 		memset(psf, 0, sizeof(*psf));
@@ -1659,7 +1659,7 @@
 	err = -ENOBUFS;
 	if (count >= sysctl_igmp_max_memberships)
 		goto done;
-	iml = (struct ip_mc_socklist *)sock_kmalloc(sk,sizeof(*iml),GFP_KERNEL);
+	iml = sock_kmalloc(sk,sizeof(*iml),GFP_KERNEL);
 	if (iml == NULL)
 		goto done;
 
@@ -1823,8 +1823,7 @@
 
 		if (psl)
 			count += psl->sl_max;
-		newpsl = (struct ip_sf_socklist *)sock_kmalloc(sk,
-			IP_SFLSIZE(count), GFP_KERNEL);
+		newpsl = sock_kmalloc(sk, IP_SFLSIZE(count), GFP_KERNEL);
 		if (!newpsl) {
 			err = -ENOBUFS;
 			goto done;
@@ -1907,8 +1906,8 @@
 		goto done;
 	}
 	if (msf->imsf_numsrc) {
-		newpsl = (struct ip_sf_socklist *)sock_kmalloc(sk,
-				IP_SFLSIZE(msf->imsf_numsrc), GFP_KERNEL);
+		newpsl = sock_kmalloc(sk, IP_SFLSIZE(msf->imsf_numsrc),
+							   GFP_KERNEL);
 		if (!newpsl) {
 			err = -ENOBUFS;
 			goto done;
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index 1e93eaf..abe2392 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -10,6 +10,7 @@
  *
  */
 
+#include <linux/capability.h>
 #include <linux/config.h>
 #include <linux/module.h>
 #include <linux/types.h>
diff --git a/net/ipv4/ip_options.c b/net/ipv4/ip_options.c
index d3f6c46..9bebad0 100644
--- a/net/ipv4/ip_options.c
+++ b/net/ipv4/ip_options.c
@@ -11,6 +11,7 @@
  *		
  */
 
+#include <linux/capability.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <asm/uaccess.h>
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index 6986e11d..2bf8d78 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -621,7 +621,7 @@
 				err = -ENOBUFS;
 				break;
 			}
-			msf = (struct ip_msfilter *)kmalloc(optlen, GFP_KERNEL);
+			msf = kmalloc(optlen, GFP_KERNEL);
 			if (msf == 0) {
 				err = -ENOBUFS;
 				break;
@@ -778,7 +778,7 @@
 				err = -ENOBUFS;
 				break;
 			}
-			gsf = (struct group_filter *)kmalloc(optlen,GFP_KERNEL);
+			gsf = kmalloc(optlen,GFP_KERNEL);
 			if (gsf == 0) {
 				err = -ENOBUFS;
 				break;
@@ -798,7 +798,7 @@
 				goto mc_msf_out;
 			}
 			msize = IP_MSFILTER_SIZE(gsf->gf_numsrc);
-			msf = (struct ip_msfilter *)kmalloc(msize,GFP_KERNEL);
+			msf = kmalloc(msize,GFP_KERNEL);
 			if (msf == 0) {
 				err = -ENOBUFS;
 				goto mc_msf_out;
diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
index bc5ca23..e5cbe72 100644
--- a/net/ipv4/ipip.c
+++ b/net/ipv4/ipip.c
@@ -93,6 +93,7 @@
  */
 
  
+#include <linux/capability.h>
 #include <linux/config.h>
 #include <linux/module.h>
 #include <linux/types.h>
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index f58ac98..5c94c22 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -33,6 +33,7 @@
 #include <asm/uaccess.h>
 #include <linux/types.h>
 #include <linux/sched.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/timer.h>
 #include <linux/mm.h>
diff --git a/net/ipv4/ipvs/ip_vs_ctl.c b/net/ipv4/ipvs/ip_vs_ctl.c
index c935c50..7f0288b 100644
--- a/net/ipv4/ipvs/ip_vs_ctl.c
+++ b/net/ipv4/ipvs/ip_vs_ctl.c
@@ -23,6 +23,7 @@
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/types.h>
+#include <linux/capability.h>
 #include <linux/fs.h>
 #include <linux/sysctl.h>
 #include <linux/proc_fs.h>
diff --git a/net/ipv4/netfilter.c b/net/ipv4/netfilter.c
index 3321092..52a3d7c 100644
--- a/net/ipv4/netfilter.c
+++ b/net/ipv4/netfilter.c
@@ -1,16 +1,8 @@
 /* IPv4 specific functions of netfilter core */
-
-#include <linux/config.h>
-#ifdef CONFIG_NETFILTER
-
 #include <linux/kernel.h>
 #include <linux/netfilter.h>
 #include <linux/netfilter_ipv4.h>
-
 #include <linux/ip.h>
-#include <linux/tcp.h>
-#include <linux/udp.h>
-#include <linux/icmp.h>
 #include <net/route.h>
 #include <net/xfrm.h>
 #include <net/ip.h>
@@ -146,5 +138,3 @@
 
 module_init(init);
 module_exit(fini);
-
-#endif /* CONFIG_NETFILTER */
diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
index bba1563..b6d5284 100644
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -13,6 +13,7 @@
 #include <linux/kernel.h>
 #include <linux/skbuff.h>
 #include <linux/netdevice.h>
+#include <linux/capability.h>
 #include <linux/if_arp.h>
 #include <linux/kmod.h>
 #include <linux/vmalloc.h>
diff --git a/net/ipv4/netfilter/ip_conntrack_helper_pptp.c b/net/ipv4/netfilter/ip_conntrack_helper_pptp.c
index 4108a5e..d716bba 100644
--- a/net/ipv4/netfilter/ip_conntrack_helper_pptp.c
+++ b/net/ipv4/netfilter/ip_conntrack_helper_pptp.c
@@ -762,7 +762,7 @@
 	.help = conntrack_pptp_help
 };
 
-extern void __exit ip_ct_proto_gre_fini(void);
+extern void ip_ct_proto_gre_fini(void);
 extern int __init ip_ct_proto_gre_init(void);
 
 /* ip_conntrack_pptp initialization */
diff --git a/net/ipv4/netfilter/ip_conntrack_proto_generic.c b/net/ipv4/netfilter/ip_conntrack_proto_generic.c
index 88c3712..f891308 100644
--- a/net/ipv4/netfilter/ip_conntrack_proto_generic.c
+++ b/net/ipv4/netfilter/ip_conntrack_proto_generic.c
@@ -12,7 +12,7 @@
 #include <linux/netfilter.h>
 #include <linux/netfilter_ipv4/ip_conntrack_protocol.h>
 
-unsigned long ip_ct_generic_timeout = 600*HZ;
+unsigned int ip_ct_generic_timeout = 600*HZ;
 
 static int generic_pkt_to_tuple(const struct sk_buff *skb,
 				unsigned int dataoff,
diff --git a/net/ipv4/netfilter/ip_conntrack_proto_gre.c b/net/ipv4/netfilter/ip_conntrack_proto_gre.c
index 57956de..c777abf 100644
--- a/net/ipv4/netfilter/ip_conntrack_proto_gre.c
+++ b/net/ipv4/netfilter/ip_conntrack_proto_gre.c
@@ -309,7 +309,10 @@
 	return ip_conntrack_protocol_register(&gre);
 }
 
-void __exit ip_ct_proto_gre_fini(void)
+/* This cannot be __exit, as it is invoked from ip_conntrack_helper_pptp.c's
+ * init() code on errors.
+ */
+void ip_ct_proto_gre_fini(void)
 {
 	struct list_head *pos, *n;
 
diff --git a/net/ipv4/netfilter/ip_conntrack_proto_icmp.c b/net/ipv4/netfilter/ip_conntrack_proto_icmp.c
index 30fc21d..3021af0 100644
--- a/net/ipv4/netfilter/ip_conntrack_proto_icmp.c
+++ b/net/ipv4/netfilter/ip_conntrack_proto_icmp.c
@@ -16,13 +16,12 @@
 #include <linux/skbuff.h>
 #include <net/ip.h>
 #include <net/checksum.h>
-#include <linux/netfilter.h>
 #include <linux/netfilter_ipv4.h>
 #include <linux/netfilter_ipv4/ip_conntrack.h>
 #include <linux/netfilter_ipv4/ip_conntrack_core.h>
 #include <linux/netfilter_ipv4/ip_conntrack_protocol.h>
 
-unsigned long ip_ct_icmp_timeout = 30*HZ;
+unsigned int ip_ct_icmp_timeout = 30*HZ;
 
 #if 0
 #define DEBUGP printk
diff --git a/net/ipv4/netfilter/ip_conntrack_proto_sctp.c b/net/ipv4/netfilter/ip_conntrack_proto_sctp.c
index 0b25050..be602e8 100644
--- a/net/ipv4/netfilter/ip_conntrack_proto_sctp.c
+++ b/net/ipv4/netfilter/ip_conntrack_proto_sctp.c
@@ -58,15 +58,15 @@
 #define HOURS * 60 MINS
 #define DAYS  * 24 HOURS
 
-static unsigned long ip_ct_sctp_timeout_closed            =  10 SECS;
-static unsigned long ip_ct_sctp_timeout_cookie_wait       =   3 SECS;
-static unsigned long ip_ct_sctp_timeout_cookie_echoed     =   3 SECS;
-static unsigned long ip_ct_sctp_timeout_established       =   5 DAYS;
-static unsigned long ip_ct_sctp_timeout_shutdown_sent     = 300 SECS / 1000;
-static unsigned long ip_ct_sctp_timeout_shutdown_recd     = 300 SECS / 1000;
-static unsigned long ip_ct_sctp_timeout_shutdown_ack_sent =   3 SECS;
+static unsigned int ip_ct_sctp_timeout_closed            =  10 SECS;
+static unsigned int ip_ct_sctp_timeout_cookie_wait       =   3 SECS;
+static unsigned int ip_ct_sctp_timeout_cookie_echoed     =   3 SECS;
+static unsigned int ip_ct_sctp_timeout_established       =   5 DAYS;
+static unsigned int ip_ct_sctp_timeout_shutdown_sent     = 300 SECS / 1000;
+static unsigned int ip_ct_sctp_timeout_shutdown_recd     = 300 SECS / 1000;
+static unsigned int ip_ct_sctp_timeout_shutdown_ack_sent =   3 SECS;
 
-static const unsigned long * sctp_timeouts[]
+static const unsigned int * sctp_timeouts[]
 = { NULL,                                  /* SCTP_CONNTRACK_NONE  */
     &ip_ct_sctp_timeout_closed,	           /* SCTP_CONNTRACK_CLOSED */
     &ip_ct_sctp_timeout_cookie_wait,       /* SCTP_CONNTRACK_COOKIE_WAIT */
diff --git a/net/ipv4/netfilter/ip_conntrack_proto_tcp.c b/net/ipv4/netfilter/ip_conntrack_proto_tcp.c
index 77f3046..e0dc370 100644
--- a/net/ipv4/netfilter/ip_conntrack_proto_tcp.c
+++ b/net/ipv4/netfilter/ip_conntrack_proto_tcp.c
@@ -32,7 +32,6 @@
 
 #include <net/tcp.h>
 
-#include <linux/netfilter.h>
 #include <linux/netfilter_ipv4.h>
 #include <linux/netfilter_ipv4/ip_conntrack.h>
 #include <linux/netfilter_ipv4/ip_conntrack_protocol.h>
@@ -85,21 +84,21 @@
 #define HOURS * 60 MINS
 #define DAYS * 24 HOURS
 
-unsigned long ip_ct_tcp_timeout_syn_sent =      2 MINS;
-unsigned long ip_ct_tcp_timeout_syn_recv =     60 SECS;
-unsigned long ip_ct_tcp_timeout_established =   5 DAYS;
-unsigned long ip_ct_tcp_timeout_fin_wait =      2 MINS;
-unsigned long ip_ct_tcp_timeout_close_wait =   60 SECS;
-unsigned long ip_ct_tcp_timeout_last_ack =     30 SECS;
-unsigned long ip_ct_tcp_timeout_time_wait =     2 MINS;
-unsigned long ip_ct_tcp_timeout_close =        10 SECS;
+unsigned int ip_ct_tcp_timeout_syn_sent =      2 MINS;
+unsigned int ip_ct_tcp_timeout_syn_recv =     60 SECS;
+unsigned int ip_ct_tcp_timeout_established =   5 DAYS;
+unsigned int ip_ct_tcp_timeout_fin_wait =      2 MINS;
+unsigned int ip_ct_tcp_timeout_close_wait =   60 SECS;
+unsigned int ip_ct_tcp_timeout_last_ack =     30 SECS;
+unsigned int ip_ct_tcp_timeout_time_wait =     2 MINS;
+unsigned int ip_ct_tcp_timeout_close =        10 SECS;
 
 /* RFC1122 says the R2 limit should be at least 100 seconds.
    Linux uses 15 packets as limit, which corresponds 
    to ~13-30min depending on RTO. */
-unsigned long ip_ct_tcp_timeout_max_retrans =     5 MINS;
+unsigned int ip_ct_tcp_timeout_max_retrans =     5 MINS;
  
-static const unsigned long * tcp_timeouts[]
+static const unsigned int * tcp_timeouts[]
 = { NULL,                              /*      TCP_CONNTRACK_NONE */
     &ip_ct_tcp_timeout_syn_sent,       /*      TCP_CONNTRACK_SYN_SENT, */
     &ip_ct_tcp_timeout_syn_recv,       /*      TCP_CONNTRACK_SYN_RECV, */
diff --git a/net/ipv4/netfilter/ip_conntrack_proto_udp.c b/net/ipv4/netfilter/ip_conntrack_proto_udp.c
index 46becbe..55b7d32 100644
--- a/net/ipv4/netfilter/ip_conntrack_proto_udp.c
+++ b/net/ipv4/netfilter/ip_conntrack_proto_udp.c
@@ -15,12 +15,11 @@
 #include <linux/udp.h>
 #include <linux/seq_file.h>
 #include <net/checksum.h>
-#include <linux/netfilter.h>
 #include <linux/netfilter_ipv4.h>
 #include <linux/netfilter_ipv4/ip_conntrack_protocol.h>
 
-unsigned long ip_ct_udp_timeout = 30*HZ;
-unsigned long ip_ct_udp_timeout_stream = 180*HZ;
+unsigned int ip_ct_udp_timeout = 30*HZ;
+unsigned int ip_ct_udp_timeout_stream = 180*HZ;
 
 static int udp_pkt_to_tuple(const struct sk_buff *skb,
 			     unsigned int dataoff,
diff --git a/net/ipv4/netfilter/ip_conntrack_standalone.c b/net/ipv4/netfilter/ip_conntrack_standalone.c
index 7ba9778..9dec129 100644
--- a/net/ipv4/netfilter/ip_conntrack_standalone.c
+++ b/net/ipv4/netfilter/ip_conntrack_standalone.c
@@ -544,28 +544,28 @@
 extern unsigned int ip_conntrack_htable_size;
 
 /* From ip_conntrack_proto_tcp.c */
-extern unsigned long ip_ct_tcp_timeout_syn_sent;
-extern unsigned long ip_ct_tcp_timeout_syn_recv;
-extern unsigned long ip_ct_tcp_timeout_established;
-extern unsigned long ip_ct_tcp_timeout_fin_wait;
-extern unsigned long ip_ct_tcp_timeout_close_wait;
-extern unsigned long ip_ct_tcp_timeout_last_ack;
-extern unsigned long ip_ct_tcp_timeout_time_wait;
-extern unsigned long ip_ct_tcp_timeout_close;
-extern unsigned long ip_ct_tcp_timeout_max_retrans;
+extern unsigned int ip_ct_tcp_timeout_syn_sent;
+extern unsigned int ip_ct_tcp_timeout_syn_recv;
+extern unsigned int ip_ct_tcp_timeout_established;
+extern unsigned int ip_ct_tcp_timeout_fin_wait;
+extern unsigned int ip_ct_tcp_timeout_close_wait;
+extern unsigned int ip_ct_tcp_timeout_last_ack;
+extern unsigned int ip_ct_tcp_timeout_time_wait;
+extern unsigned int ip_ct_tcp_timeout_close;
+extern unsigned int ip_ct_tcp_timeout_max_retrans;
 extern int ip_ct_tcp_loose;
 extern int ip_ct_tcp_be_liberal;
 extern int ip_ct_tcp_max_retrans;
 
 /* From ip_conntrack_proto_udp.c */
-extern unsigned long ip_ct_udp_timeout;
-extern unsigned long ip_ct_udp_timeout_stream;
+extern unsigned int ip_ct_udp_timeout;
+extern unsigned int ip_ct_udp_timeout_stream;
 
 /* From ip_conntrack_proto_icmp.c */
-extern unsigned long ip_ct_icmp_timeout;
+extern unsigned int ip_ct_icmp_timeout;
 
 /* From ip_conntrack_proto_icmp.c */
-extern unsigned long ip_ct_generic_timeout;
+extern unsigned int ip_ct_generic_timeout;
 
 /* Log invalid packets of a given protocol */
 static int log_invalid_proto_min = 0;
diff --git a/net/ipv4/netfilter/ip_nat_helper_pptp.c b/net/ipv4/netfilter/ip_nat_helper_pptp.c
index e546203..ac004895 100644
--- a/net/ipv4/netfilter/ip_nat_helper_pptp.c
+++ b/net/ipv4/netfilter/ip_nat_helper_pptp.c
@@ -148,14 +148,14 @@
 {
 	struct ip_ct_pptp_master *ct_pptp_info = &ct->help.ct_pptp_info;
 	struct ip_nat_pptp *nat_pptp_info = &ct->nat.help.nat_pptp_info;
-
-	u_int16_t msg, *cid = NULL, new_callid;
+	u_int16_t msg, new_callid;
+	unsigned int cid_off;
 
 	new_callid = htons(ct_pptp_info->pns_call_id);
 	
 	switch (msg = ntohs(ctlh->messageType)) {
 		case PPTP_OUT_CALL_REQUEST:
-			cid = &pptpReq->ocreq.callID;
+			cid_off = offsetof(union pptp_ctrl_union, ocreq.callID);
 			/* FIXME: ideally we would want to reserve a call ID
 			 * here.  current netfilter NAT core is not able to do
 			 * this :( For now we use TCP source port. This breaks
@@ -172,10 +172,10 @@
 			ct_pptp_info->pns_call_id = ntohs(new_callid);
 			break;
 		case PPTP_IN_CALL_REPLY:
-			cid = &pptpReq->icreq.callID;
+			cid_off = offsetof(union pptp_ctrl_union, icreq.callID);
 			break;
 		case PPTP_CALL_CLEAR_REQUEST:
-			cid = &pptpReq->clrreq.callID;
+			cid_off = offsetof(union pptp_ctrl_union, clrreq.callID);
 			break;
 		default:
 			DEBUGP("unknown outbound packet 0x%04x:%s\n", msg,
@@ -197,18 +197,15 @@
 
 	/* only OUT_CALL_REQUEST, IN_CALL_REPLY, CALL_CLEAR_REQUEST pass
 	 * down to here */
-
-	IP_NF_ASSERT(cid);
-
 	DEBUGP("altering call id from 0x%04x to 0x%04x\n",
-		ntohs(*cid), ntohs(new_callid));
+		ntohs(*(u_int16_t *)pptpReq + cid_off), ntohs(new_callid));
 
 	/* mangle packet */
 	if (ip_nat_mangle_tcp_packet(pskb, ct, ctinfo,
-		(void *)cid - ((void *)ctlh - sizeof(struct pptp_pkt_hdr)),
-				 	sizeof(new_callid), 
-					(char *)&new_callid,
-				 	sizeof(new_callid)) == 0)
+	                             cid_off + sizeof(struct pptp_pkt_hdr) +
+	                             sizeof(struct PptpControlHeader),
+	                             sizeof(new_callid), (char *)&new_callid,
+	                             sizeof(new_callid)) == 0)
 		return NF_DROP;
 
 	return NF_ACCEPT;
@@ -299,31 +296,30 @@
 		 union pptp_ctrl_union *pptpReq)
 {
 	struct ip_nat_pptp *nat_pptp_info = &ct->nat.help.nat_pptp_info;
-	u_int16_t msg, new_cid = 0, new_pcid, *pcid = NULL, *cid = NULL;
-
-	int ret = NF_ACCEPT, rv;
+	u_int16_t msg, new_cid = 0, new_pcid;
+	unsigned int pcid_off, cid_off = 0;
 
 	new_pcid = htons(nat_pptp_info->pns_call_id);
 
 	switch (msg = ntohs(ctlh->messageType)) {
 	case PPTP_OUT_CALL_REPLY:
-		pcid = &pptpReq->ocack.peersCallID;	
-		cid = &pptpReq->ocack.callID;
+		pcid_off = offsetof(union pptp_ctrl_union, ocack.peersCallID);
+		cid_off = offsetof(union pptp_ctrl_union, ocack.callID);
 		break;
 	case PPTP_IN_CALL_CONNECT:
-		pcid = &pptpReq->iccon.peersCallID;
+		pcid_off = offsetof(union pptp_ctrl_union, iccon.peersCallID);
 		break;
 	case PPTP_IN_CALL_REQUEST:
 		/* only need to nat in case PAC is behind NAT box */
-		break;
+		return NF_ACCEPT;
 	case PPTP_WAN_ERROR_NOTIFY:
-		pcid = &pptpReq->wanerr.peersCallID;
+		pcid_off = offsetof(union pptp_ctrl_union, wanerr.peersCallID);
 		break;
 	case PPTP_CALL_DISCONNECT_NOTIFY:
-		pcid = &pptpReq->disc.callID;
+		pcid_off = offsetof(union pptp_ctrl_union, disc.callID);
 		break;
 	case PPTP_SET_LINK_INFO:
-		pcid = &pptpReq->setlink.peersCallID;
+		pcid_off = offsetof(union pptp_ctrl_union, setlink.peersCallID);
 		break;
 
 	default:
@@ -345,35 +341,26 @@
 	 * WAN_ERROR_NOTIFY, CALL_DISCONNECT_NOTIFY pass down here */
 
 	/* mangle packet */
-	IP_NF_ASSERT(pcid);
 	DEBUGP("altering peer call id from 0x%04x to 0x%04x\n",
-		ntohs(*pcid), ntohs(new_pcid));
-	
-	rv = ip_nat_mangle_tcp_packet(pskb, ct, ctinfo, 
-				      (void *)pcid - ((void *)ctlh - sizeof(struct pptp_pkt_hdr)),
-				      sizeof(new_pcid), (char *)&new_pcid, 
-				      sizeof(new_pcid));
-	if (rv != NF_ACCEPT) 
-		return rv;
+		ntohs(*(u_int16_t *)pptpReq + pcid_off), ntohs(new_pcid));
+
+	if (ip_nat_mangle_tcp_packet(pskb, ct, ctinfo,
+	                             pcid_off + sizeof(struct pptp_pkt_hdr) +
+				     sizeof(struct PptpControlHeader),
+				     sizeof(new_pcid), (char *)&new_pcid,
+				     sizeof(new_pcid)) == 0)
+		return NF_DROP;
 
 	if (new_cid) {
-		IP_NF_ASSERT(cid);
 		DEBUGP("altering call id from 0x%04x to 0x%04x\n",
-			ntohs(*cid), ntohs(new_cid));
-		rv = ip_nat_mangle_tcp_packet(pskb, ct, ctinfo, 
-					      (void *)cid - ((void *)ctlh - sizeof(struct pptp_pkt_hdr)), 
-					      sizeof(new_cid),
-					      (char *)&new_cid, 
-					      sizeof(new_cid));
-		if (rv != NF_ACCEPT)
-			return rv;
+			ntohs(*(u_int16_t *)pptpReq + cid_off), ntohs(new_cid));
+		if (ip_nat_mangle_tcp_packet(pskb, ct, ctinfo,
+		                             cid_off + sizeof(struct pptp_pkt_hdr) +
+					     sizeof(struct PptpControlHeader),
+					     sizeof(new_cid), (char *)&new_cid,
+					     sizeof(new_cid)) == 0)
+			return NF_DROP;
 	}
-
-	/* check for earlier return value of 'switch' above */
-	if (ret != NF_ACCEPT)
-		return ret;
-
-	/* great, at least we don't need to resize packets */
 	return NF_ACCEPT;
 }
 
diff --git a/net/ipv4/netfilter/ip_nat_proto_gre.c b/net/ipv4/netfilter/ip_nat_proto_gre.c
index f7cad7c..6c4899d 100644
--- a/net/ipv4/netfilter/ip_nat_proto_gre.c
+++ b/net/ipv4/netfilter/ip_nat_proto_gre.c
@@ -151,42 +151,6 @@
 	return 1;
 }
 
-/* print out a nat tuple */
-static unsigned int 
-gre_print(char *buffer, 
-	  const struct ip_conntrack_tuple *match,
-	  const struct ip_conntrack_tuple *mask)
-{
-	unsigned int len = 0;
-
-	if (mask->src.u.gre.key)
-		len += sprintf(buffer + len, "srckey=0x%x ", 
-				ntohl(match->src.u.gre.key));
-
-	if (mask->dst.u.gre.key)
-		len += sprintf(buffer + len, "dstkey=0x%x ",
-				ntohl(match->src.u.gre.key));
-
-	return len;
-}
-
-/* print a range of keys */
-static unsigned int 
-gre_print_range(char *buffer, const struct ip_nat_range *range)
-{
-	if (range->min.gre.key != 0 
-	    || range->max.gre.key != 0xFFFF) {
-		if (range->min.gre.key == range->max.gre.key)
-			return sprintf(buffer, "key 0x%x ",
-					ntohl(range->min.gre.key));
-		else
-			return sprintf(buffer, "keys 0x%u-0x%u ",
-					ntohl(range->min.gre.key),
-					ntohl(range->max.gre.key));
-	} else
-		return 0;
-}
-
 /* nat helper struct */
 static struct ip_nat_protocol gre = { 
 	.name		= "GRE", 
@@ -194,8 +158,6 @@
 	.manip_pkt	= gre_manip_pkt,
 	.in_range	= gre_in_range,
 	.unique_tuple	= gre_unique_tuple,
-	.print		= gre_print,
-	.print_range	= gre_print_range,
 #if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \
     defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE)
 	.range_to_nfattr	= ip_nat_port_range_to_nfattr,
diff --git a/net/ipv4/netfilter/ip_nat_proto_icmp.c b/net/ipv4/netfilter/ip_nat_proto_icmp.c
index 9387190..31a3f4c 100644
--- a/net/ipv4/netfilter/ip_nat_proto_icmp.c
+++ b/net/ipv4/netfilter/ip_nat_proto_icmp.c
@@ -74,38 +74,6 @@
 	return 1;
 }
 
-static unsigned int
-icmp_print(char *buffer,
-	   const struct ip_conntrack_tuple *match,
-	   const struct ip_conntrack_tuple *mask)
-{
-	unsigned int len = 0;
-
-	if (mask->src.u.icmp.id)
-		len += sprintf(buffer + len, "id=%u ",
-			       ntohs(match->src.u.icmp.id));
-
-	if (mask->dst.u.icmp.type)
-		len += sprintf(buffer + len, "type=%u ",
-			       ntohs(match->dst.u.icmp.type));
-
-	if (mask->dst.u.icmp.code)
-		len += sprintf(buffer + len, "code=%u ",
-			       ntohs(match->dst.u.icmp.code));
-
-	return len;
-}
-
-static unsigned int
-icmp_print_range(char *buffer, const struct ip_nat_range *range)
-{
-	if (range->min.icmp.id != 0 || range->max.icmp.id != 0xFFFF)
-		return sprintf(buffer, "id %u-%u ",
-			       ntohs(range->min.icmp.id),
-			       ntohs(range->max.icmp.id));
-	else return 0;
-}
-
 struct ip_nat_protocol ip_nat_protocol_icmp = {
 	.name			= "ICMP",
 	.protonum		= IPPROTO_ICMP,
@@ -113,8 +81,6 @@
 	.manip_pkt		= icmp_manip_pkt,
 	.in_range		= icmp_in_range,
 	.unique_tuple		= icmp_unique_tuple,
-	.print			= icmp_print,
-	.print_range		= icmp_print_range,
 #if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \
     defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE)
 	.range_to_nfattr	= ip_nat_port_range_to_nfattr,
diff --git a/net/ipv4/netfilter/ip_nat_proto_tcp.c b/net/ipv4/netfilter/ip_nat_proto_tcp.c
index 1d381bf..a3d1407 100644
--- a/net/ipv4/netfilter/ip_nat_proto_tcp.c
+++ b/net/ipv4/netfilter/ip_nat_proto_tcp.c
@@ -136,40 +136,6 @@
 	return 1;
 }
 
-static unsigned int
-tcp_print(char *buffer,
-	  const struct ip_conntrack_tuple *match,
-	  const struct ip_conntrack_tuple *mask)
-{
-	unsigned int len = 0;
-
-	if (mask->src.u.tcp.port)
-		len += sprintf(buffer + len, "srcpt=%u ",
-			       ntohs(match->src.u.tcp.port));
-
-
-	if (mask->dst.u.tcp.port)
-		len += sprintf(buffer + len, "dstpt=%u ",
-			       ntohs(match->dst.u.tcp.port));
-
-	return len;
-}
-
-static unsigned int
-tcp_print_range(char *buffer, const struct ip_nat_range *range)
-{
-	if (range->min.tcp.port != 0 || range->max.tcp.port != 0xFFFF) {
-		if (range->min.tcp.port == range->max.tcp.port)
-			return sprintf(buffer, "port %u ",
-				       ntohs(range->min.tcp.port));
-		else
-			return sprintf(buffer, "ports %u-%u ",
-				       ntohs(range->min.tcp.port),
-				       ntohs(range->max.tcp.port));
-	}
-	else return 0;
-}
-
 struct ip_nat_protocol ip_nat_protocol_tcp = {
 	.name			= "TCP",
 	.protonum		= IPPROTO_TCP,
@@ -177,8 +143,6 @@
 	.manip_pkt		= tcp_manip_pkt,
 	.in_range		= tcp_in_range,
 	.unique_tuple		= tcp_unique_tuple,
-	.print			= tcp_print,
-	.print_range		= tcp_print_range,
 #if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \
     defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE)
 	.range_to_nfattr	= ip_nat_port_range_to_nfattr,
diff --git a/net/ipv4/netfilter/ip_nat_proto_udp.c b/net/ipv4/netfilter/ip_nat_proto_udp.c
index c4906e1..ec6053f 100644
--- a/net/ipv4/netfilter/ip_nat_proto_udp.c
+++ b/net/ipv4/netfilter/ip_nat_proto_udp.c
@@ -122,40 +122,6 @@
 	return 1;
 }
 
-static unsigned int
-udp_print(char *buffer,
-	  const struct ip_conntrack_tuple *match,
-	  const struct ip_conntrack_tuple *mask)
-{
-	unsigned int len = 0;
-
-	if (mask->src.u.udp.port)
-		len += sprintf(buffer + len, "srcpt=%u ",
-			       ntohs(match->src.u.udp.port));
-
-
-	if (mask->dst.u.udp.port)
-		len += sprintf(buffer + len, "dstpt=%u ",
-			       ntohs(match->dst.u.udp.port));
-
-	return len;
-}
-
-static unsigned int
-udp_print_range(char *buffer, const struct ip_nat_range *range)
-{
-	if (range->min.udp.port != 0 || range->max.udp.port != 0xFFFF) {
-		if (range->min.udp.port == range->max.udp.port)
-			return sprintf(buffer, "port %u ",
-				       ntohs(range->min.udp.port));
-		else
-			return sprintf(buffer, "ports %u-%u ",
-				       ntohs(range->min.udp.port),
-				       ntohs(range->max.udp.port));
-	}
-	else return 0;
-}
-
 struct ip_nat_protocol ip_nat_protocol_udp = {
 	.name			= "UDP",
 	.protonum		= IPPROTO_UDP,
@@ -163,8 +129,6 @@
 	.manip_pkt		= udp_manip_pkt,
 	.in_range		= udp_in_range,
 	.unique_tuple		= udp_unique_tuple,
-	.print			= udp_print,
-	.print_range		= udp_print_range,
 #if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \
     defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE)
 	.range_to_nfattr	= ip_nat_port_range_to_nfattr,
diff --git a/net/ipv4/netfilter/ip_nat_proto_unknown.c b/net/ipv4/netfilter/ip_nat_proto_unknown.c
index f0099a6..3bf0495 100644
--- a/net/ipv4/netfilter/ip_nat_proto_unknown.c
+++ b/net/ipv4/netfilter/ip_nat_proto_unknown.c
@@ -46,26 +46,10 @@
 	return 1;
 }
 
-static unsigned int
-unknown_print(char *buffer,
-	      const struct ip_conntrack_tuple *match,
-	      const struct ip_conntrack_tuple *mask)
-{
-	return 0;
-}
-
-static unsigned int
-unknown_print_range(char *buffer, const struct ip_nat_range *range)
-{
-	return 0;
-}
-
 struct ip_nat_protocol ip_nat_unknown_protocol = {
 	.name			= "unknown",
 	/* .me isn't set: getting a ref to this cannot fail. */
 	.manip_pkt		= unknown_manip_pkt,
 	.in_range		= unknown_in_range,
 	.unique_tuple		= unknown_unique_tuple,
-	.print			= unknown_print,
-	.print_range		= unknown_print_range
 };
diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index 2a26d16..877bc96 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -14,6 +14,7 @@
  */
 #include <linux/config.h>
 #include <linux/cache.h>
+#include <linux/capability.h>
 #include <linux/skbuff.h>
 #include <linux/kmod.h>
 #include <linux/vmalloc.h>
diff --git a/net/ipv4/netfilter/ipt_mac.c b/net/ipv4/netfilter/ipt_mac.c
index 11a459e..1b9bb45 100644
--- a/net/ipv4/netfilter/ipt_mac.c
+++ b/net/ipv4/netfilter/ipt_mac.c
@@ -11,6 +11,7 @@
 #include <linux/module.h>
 #include <linux/skbuff.h>
 #include <linux/if_ether.h>
+#include <linux/etherdevice.h>
 
 #include <linux/netfilter_ipv4/ipt_mac.h>
 #include <linux/netfilter_ipv4/ip_tables.h>
@@ -33,8 +34,8 @@
     return (skb->mac.raw >= skb->head
 	    && (skb->mac.raw + ETH_HLEN) <= skb->data
 	    /* If so, compare... */
-	    && ((memcmp(eth_hdr(skb)->h_source, info->srcaddr, ETH_ALEN)
-		== 0) ^ info->invert));
+	    && ((!compare_ether_addr(eth_hdr(skb)->h_source, info->srcaddr))
+		^ info->invert));
 }
 
 static int
diff --git a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
index 9bdbb77..0c56c52a 100644
--- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
+++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
@@ -277,7 +277,7 @@
 
 #ifdef CONFIG_SYSCTL
 /* From nf_conntrack_proto_icmp.c */
-extern unsigned long nf_ct_icmp_timeout;
+extern unsigned int nf_ct_icmp_timeout;
 static struct ctl_table_header *nf_ct_ipv4_sysctl_header;
 
 static ctl_table nf_ct_sysctl_table[] = {
diff --git a/net/ipv6/Makefile b/net/ipv6/Makefile
index 9601fd7..41877ab 100644
--- a/net/ipv6/Makefile
+++ b/net/ipv6/Makefile
@@ -8,11 +8,11 @@
 		route.o ip6_fib.o ipv6_sockglue.o ndisc.o udp.o raw.o \
 		protocol.o icmp.o mcast.o reassembly.o tcp_ipv6.o \
 		exthdrs.o sysctl_net_ipv6.o datagram.o proc.o \
-		ip6_flowlabel.o ipv6_syms.o netfilter.o \
-		inet6_connection_sock.o
+		ip6_flowlabel.o ipv6_syms.o inet6_connection_sock.o
 
 ipv6-$(CONFIG_XFRM) += xfrm6_policy.o xfrm6_state.o xfrm6_input.o \
 	xfrm6_output.o
+ipv6-$(CONFIG_NETFILTER) += netfilter.o
 ipv6-objs += $(ipv6-y)
 
 obj-$(CONFIG_INET6_AH) += ah6.o
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index e53e421..7129d42 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -58,6 +58,7 @@
 #ifdef CONFIG_SYSCTL
 #include <linux/sysctl.h>
 #endif
+#include <linux/capability.h>
 #include <linux/delay.h>
 #include <linux/notifier.h>
 #include <linux/string.h>
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index 25c3fe5..064ffab 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -22,6 +22,7 @@
 
 
 #include <linux/module.h>
+#include <linux/capability.h>
 #include <linux/config.h>
 #include <linux/errno.h>
 #include <linux/types.h>
diff --git a/net/ipv6/anycast.c b/net/ipv6/anycast.c
index 6b72940..65e73ac 100644
--- a/net/ipv6/anycast.c
+++ b/net/ipv6/anycast.c
@@ -13,6 +13,7 @@
  *      2 of the License, or (at your option) any later version.
  */
 
+#include <linux/capability.h>
 #include <linux/config.h>
 #include <linux/module.h>
 #include <linux/errno.h>
diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
index c4a3a99..99a6eb2 100644
--- a/net/ipv6/datagram.c
+++ b/net/ipv6/datagram.c
@@ -13,6 +13,7 @@
  *      2 of the License, or (at your option) any later version.
  */
 
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
diff --git a/net/ipv6/ip6_flowlabel.c b/net/ipv6/ip6_flowlabel.c
index 89d12b4..964ad9d 100644
--- a/net/ipv6/ip6_flowlabel.c
+++ b/net/ipv6/ip6_flowlabel.c
@@ -9,6 +9,7 @@
  *	Authors:	Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
  */
 
+#include <linux/capability.h>
 #include <linux/config.h>
 #include <linux/errno.h>
 #include <linux/types.h>
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index c3c2bf6..92ead3c 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -21,6 +21,7 @@
 
 #include <linux/config.h>
 #include <linux/module.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/types.h>
 #include <linux/sockios.h>
diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
index c63868d..f7142ba 100644
--- a/net/ipv6/ipv6_sockglue.c
+++ b/net/ipv6/ipv6_sockglue.c
@@ -26,6 +26,7 @@
  */
 
 #include <linux/module.h>
+#include <linux/capability.h>
 #include <linux/config.h>
 #include <linux/errno.h>
 #include <linux/types.h>
@@ -549,7 +550,7 @@
 			retv = -ENOBUFS;
 			break;
 		}
-		gsf = (struct group_filter *)kmalloc(optlen,GFP_KERNEL);
+		gsf = kmalloc(optlen,GFP_KERNEL);
 		if (gsf == 0) {
 			retv = -ENOBUFS;
 			break;
diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
index 1cf305a..cc3e9f5 100644
--- a/net/ipv6/mcast.c
+++ b/net/ipv6/mcast.c
@@ -449,8 +449,7 @@
 
 		if (psl)
 			count += psl->sl_max;
-		newpsl = (struct ip6_sf_socklist *)sock_kmalloc(sk,
-			IP6_SFLSIZE(count), GFP_ATOMIC);
+		newpsl = sock_kmalloc(sk, IP6_SFLSIZE(count), GFP_ATOMIC);
 		if (!newpsl) {
 			err = -ENOBUFS;
 			goto done;
@@ -535,8 +534,8 @@
 		goto done;
 	}
 	if (gsf->gf_numsrc) {
-		newpsl = (struct ip6_sf_socklist *)sock_kmalloc(sk,
-				IP6_SFLSIZE(gsf->gf_numsrc), GFP_ATOMIC);
+		newpsl = sock_kmalloc(sk, IP6_SFLSIZE(gsf->gf_numsrc),
+							  GFP_ATOMIC);
 		if (!newpsl) {
 			err = -ENOBUFS;
 			goto done;
@@ -768,7 +767,7 @@
 	 * for deleted items allows change reports to use common code with
 	 * non-deleted or query-response MCA's.
 	 */
-	pmc = (struct ifmcaddr6 *)kmalloc(sizeof(*pmc), GFP_ATOMIC);
+	pmc = kmalloc(sizeof(*pmc), GFP_ATOMIC);
 	if (!pmc)
 		return;
 	memset(pmc, 0, sizeof(*pmc));
@@ -1937,7 +1936,7 @@
 		psf_prev = psf;
 	}
 	if (!psf) {
-		psf = (struct ip6_sf_list *)kmalloc(sizeof(*psf), GFP_ATOMIC);
+		psf = kmalloc(sizeof(*psf), GFP_ATOMIC);
 		if (!psf)
 			return -ENOBUFS;
 		memset(psf, 0, sizeof(*psf));
diff --git a/net/ipv6/netfilter.c b/net/ipv6/netfilter.c
index b636783..d750cfc 100644
--- a/net/ipv6/netfilter.c
+++ b/net/ipv6/netfilter.c
@@ -1,9 +1,5 @@
-#include <linux/config.h>
-#include <linux/init.h>
-
-#ifdef CONFIG_NETFILTER
-
 #include <linux/kernel.h>
+#include <linux/init.h>
 #include <linux/ipv6.h>
 #include <linux/netfilter.h>
 #include <linux/netfilter_ipv6.h>
@@ -94,18 +90,10 @@
 	return nf_register_queue_rerouter(PF_INET6, &ip6_reroute);
 }
 
+/* This can be called from inet6_init() on errors, so it cannot
+ * be marked __exit. -DaveM
+ */
 void ipv6_netfilter_fini(void)
 {
 	nf_unregister_queue_rerouter(PF_INET6);
 }
-
-#else /* CONFIG_NETFILTER */
-int __init ipv6_netfilter_init(void)
-{
-	return 0;
-}
-
-void ipv6_netfilter_fini(void)
-{
-}
-#endif /* CONFIG_NETFILTER */
diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
index 925b42d4..1390370 100644
--- a/net/ipv6/netfilter/ip6_tables.c
+++ b/net/ipv6/netfilter/ip6_tables.c
@@ -14,6 +14,8 @@
  * 06 Jun 2002 Andras Kis-Szabo <kisza@sch.bme.hu>
  *      - new extension header parser code
  */
+
+#include <linux/capability.h>
 #include <linux/config.h>
 #include <linux/in.h>
 #include <linux/skbuff.h>
diff --git a/net/ipv6/netfilter/ip6t_mac.c b/net/ipv6/netfilter/ip6t_mac.c
index 526d43e..c848152 100644
--- a/net/ipv6/netfilter/ip6t_mac.c
+++ b/net/ipv6/netfilter/ip6t_mac.c
@@ -11,6 +11,7 @@
 #include <linux/module.h>
 #include <linux/skbuff.h>
 #include <linux/if_ether.h>
+#include <linux/etherdevice.h>
 
 #include <linux/netfilter_ipv6/ip6t_mac.h>
 #include <linux/netfilter_ipv6/ip6_tables.h>
@@ -34,8 +35,8 @@
     return (skb->mac.raw >= skb->head
 	    && (skb->mac.raw + ETH_HLEN) <= skb->data
 	    /* If so, compare... */
-	    && ((memcmp(eth_hdr(skb)->h_source, info->srcaddr, ETH_ALEN)
-		== 0) ^ info->invert));
+	    && ((!compare_ether_addr(eth_hdr(skb)->h_source, info->srcaddr))
+		^ info->invert));
 }
 
 static int
diff --git a/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c b/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c
index 704fbbe..e57d6fc 100644
--- a/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c
+++ b/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c
@@ -335,10 +335,10 @@
 #ifdef CONFIG_SYSCTL
 
 /* From nf_conntrack_proto_icmpv6.c */
-extern unsigned long nf_ct_icmpv6_timeout;
+extern unsigned int nf_ct_icmpv6_timeout;
 
 /* From nf_conntrack_frag6.c */
-extern unsigned long nf_ct_frag6_timeout;
+extern unsigned int nf_ct_frag6_timeout;
 extern unsigned int nf_ct_frag6_low_thresh;
 extern unsigned int nf_ct_frag6_high_thresh;
 
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 66140f1..e0d3ad0 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -24,6 +24,7 @@
  *		reachable.  otherwise, round-robin the list.
  */
 
+#include <linux/capability.h>
 #include <linux/config.h>
 #include <linux/errno.h>
 #include <linux/types.h>
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index 0dae48a..c2d3e17 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -20,6 +20,7 @@
 
 #include <linux/config.h>
 #include <linux/module.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/types.h>
 #include <linux/socket.h>
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index a25f4e8..66d0400 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -67,6 +67,9 @@
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 
+/* Socket used for sending RSTs and ACKs */
+static struct socket *tcp6_socket;
+
 static void	tcp_v6_send_reset(struct sk_buff *skb);
 static void	tcp_v6_reqsk_send_ack(struct sk_buff *skb, struct request_sock *req);
 static void	tcp_v6_send_check(struct sock *sk, int len, 
@@ -611,7 +614,7 @@
 	if (!ip6_dst_lookup(NULL, &buff->dst, &fl)) {
 
 		if (xfrm_lookup(&buff->dst, &fl, NULL, 0) >= 0) {
-			ip6_xmit(NULL, buff, &fl, NULL, 0);
+			ip6_xmit(tcp6_socket->sk, buff, &fl, NULL, 0);
 			TCP_INC_STATS_BH(TCP_MIB_OUTSEGS);
 			TCP_INC_STATS_BH(TCP_MIB_OUTRSTS);
 			return;
@@ -675,7 +678,7 @@
 
 	if (!ip6_dst_lookup(NULL, &buff->dst, &fl)) {
 		if (xfrm_lookup(&buff->dst, &fl, NULL, 0) >= 0) {
-			ip6_xmit(NULL, buff, &fl, NULL, 0);
+			ip6_xmit(tcp6_socket->sk, buff, &fl, NULL, 0);
 			TCP_INC_STATS_BH(TCP_MIB_OUTSEGS);
 			return;
 		}
@@ -1600,8 +1603,21 @@
 
 void __init tcpv6_init(void)
 {
+	int err;
+
 	/* register inet6 protocol */
 	if (inet6_add_protocol(&tcpv6_protocol, IPPROTO_TCP) < 0)
 		printk(KERN_ERR "tcpv6_init: Could not register protocol\n");
 	inet6_register_protosw(&tcpv6_protosw);
+
+	err = sock_create_kern(PF_INET6, SOCK_RAW, IPPROTO_TCP, &tcp6_socket);
+	if (err < 0)
+		panic("Failed to create the TCPv6 control socket.\n");
+	tcp6_socket->sk->sk_allocation = GFP_ATOMIC;
+
+	/* Unhash it so that IP input processing does not even
+	 * see it, we do not wish this socket to see incoming
+	 * packets.
+	 */
+	tcp6_socket->sk->sk_prot->unhash(tcp6_socket->sk);
 }
diff --git a/net/ipx/af_ipx.c b/net/ipx/af_ipx.c
index 0dc519b..0fb513a 100644
--- a/net/ipx/af_ipx.c
+++ b/net/ipx/af_ipx.c
@@ -29,6 +29,7 @@
  */
 
 #include <linux/config.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/if_arp.h>
 #include <linux/if_ether.h>
diff --git a/net/irda/af_irda.c b/net/irda/af_irda.c
index fbfa967..7594456 100644
--- a/net/irda/af_irda.c
+++ b/net/irda/af_irda.c
@@ -43,6 +43,7 @@
  ********************************************************************/
 
 #include <linux/config.h>
+#include <linux/capability.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/socket.h>
diff --git a/net/irda/irda_device.c b/net/irda/irda_device.c
index 70543d8..890bac0 100644
--- a/net/irda/irda_device.c
+++ b/net/irda/irda_device.c
@@ -33,6 +33,7 @@
 #include <linux/string.h>
 #include <linux/proc_fs.h>
 #include <linux/skbuff.h>
+#include <linux/capability.h>
 #include <linux/if.h>
 #include <linux/if_ether.h>
 #include <linux/if_arp.h>
diff --git a/net/irda/irias_object.c b/net/irda/irias_object.c
index 75f2666..c6d169f 100644
--- a/net/irda/irias_object.c
+++ b/net/irda/irias_object.c
@@ -82,8 +82,7 @@
 
 	IRDA_DEBUG( 4, "%s()\n", __FUNCTION__);
 
-	obj = (struct ias_object *) kmalloc(sizeof(struct ias_object),
-					    GFP_ATOMIC);
+	obj = kmalloc(sizeof(struct ias_object), GFP_ATOMIC);
 	if (obj == NULL) {
 		IRDA_WARNING("%s(), Unable to allocate object!\n",
 			     __FUNCTION__);
@@ -348,8 +347,7 @@
 	IRDA_ASSERT(obj->magic == IAS_OBJECT_MAGIC, return;);
 	IRDA_ASSERT(name != NULL, return;);
 
-	attrib = (struct ias_attrib *) kmalloc(sizeof(struct ias_attrib),
-					       GFP_ATOMIC);
+	attrib = kmalloc(sizeof(struct ias_attrib), GFP_ATOMIC);
 	if (attrib == NULL) {
 		IRDA_WARNING("%s: Unable to allocate attribute!\n",
 			     __FUNCTION__);
@@ -385,8 +383,7 @@
 	IRDA_ASSERT(name != NULL, return;);
 	IRDA_ASSERT(octets != NULL, return;);
 
-	attrib = (struct ias_attrib *) kmalloc(sizeof(struct ias_attrib),
-					       GFP_ATOMIC);
+	attrib = kmalloc(sizeof(struct ias_attrib), GFP_ATOMIC);
 	if (attrib == NULL) {
 		IRDA_WARNING("%s: Unable to allocate attribute!\n",
 			     __FUNCTION__);
@@ -420,8 +417,7 @@
 	IRDA_ASSERT(name != NULL, return;);
 	IRDA_ASSERT(value != NULL, return;);
 
-	attrib = (struct ias_attrib *) kmalloc(sizeof( struct ias_attrib),
-					       GFP_ATOMIC);
+	attrib = kmalloc(sizeof( struct ias_attrib), GFP_ATOMIC);
 	if (attrib == NULL) {
 		IRDA_WARNING("%s: Unable to allocate attribute!\n",
 			     __FUNCTION__);
diff --git a/net/irda/irnet/irnet.h b/net/irda/irnet/irnet.h
index b391cb3..e4fe1e8 100644
--- a/net/irda/irnet/irnet.h
+++ b/net/irda/irnet/irnet.h
@@ -248,6 +248,7 @@
 #include <linux/netdevice.h>
 #include <linux/miscdevice.h>
 #include <linux/poll.h>
+#include <linux/capability.h>
 #include <linux/config.h>
 #include <linux/ctype.h>	/* isspace() */
 #include <asm/uaccess.h>
diff --git a/net/key/af_key.c b/net/key/af_key.c
index 4c2f6d6..43f1ce7 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -15,6 +15,7 @@
  */
 
 #include <linux/config.h>
+#include <linux/capability.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/socket.h>
diff --git a/net/netfilter/nf_conntrack_proto_generic.c b/net/netfilter/nf_conntrack_proto_generic.c
index 36425f6..46bc27e 100644
--- a/net/netfilter/nf_conntrack_proto_generic.c
+++ b/net/netfilter/nf_conntrack_proto_generic.c
@@ -17,7 +17,7 @@
 #include <linux/netfilter.h>
 #include <net/netfilter/nf_conntrack_protocol.h>
 
-unsigned long nf_ct_generic_timeout = 600*HZ;
+unsigned int nf_ct_generic_timeout = 600*HZ;
 
 static int generic_pkt_to_tuple(const struct sk_buff *skb,
 				unsigned int dataoff,
diff --git a/net/netfilter/nf_conntrack_proto_sctp.c b/net/netfilter/nf_conntrack_proto_sctp.c
index 3a600f7..cf798e6 100644
--- a/net/netfilter/nf_conntrack_proto_sctp.c
+++ b/net/netfilter/nf_conntrack_proto_sctp.c
@@ -62,15 +62,15 @@
 #define HOURS * 60 MINS
 #define DAYS  * 24 HOURS
 
-static unsigned long nf_ct_sctp_timeout_closed            =  10 SECS;
-static unsigned long nf_ct_sctp_timeout_cookie_wait       =   3 SECS;
-static unsigned long nf_ct_sctp_timeout_cookie_echoed     =   3 SECS;
-static unsigned long nf_ct_sctp_timeout_established       =   5 DAYS;
-static unsigned long nf_ct_sctp_timeout_shutdown_sent     = 300 SECS / 1000;
-static unsigned long nf_ct_sctp_timeout_shutdown_recd     = 300 SECS / 1000;
-static unsigned long nf_ct_sctp_timeout_shutdown_ack_sent =   3 SECS;
+static unsigned int nf_ct_sctp_timeout_closed            =  10 SECS;
+static unsigned int nf_ct_sctp_timeout_cookie_wait       =   3 SECS;
+static unsigned int nf_ct_sctp_timeout_cookie_echoed     =   3 SECS;
+static unsigned int nf_ct_sctp_timeout_established       =   5 DAYS;
+static unsigned int nf_ct_sctp_timeout_shutdown_sent     = 300 SECS / 1000;
+static unsigned int nf_ct_sctp_timeout_shutdown_recd     = 300 SECS / 1000;
+static unsigned int nf_ct_sctp_timeout_shutdown_ack_sent =   3 SECS;
 
-static unsigned long * sctp_timeouts[]
+static unsigned int * sctp_timeouts[]
 = { NULL,                                  /* SCTP_CONNTRACK_NONE  */
     &nf_ct_sctp_timeout_closed,	           /* SCTP_CONNTRACK_CLOSED */
     &nf_ct_sctp_timeout_cookie_wait,       /* SCTP_CONNTRACK_COOKIE_WAIT */
diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c
index 9a1348a..df99138 100644
--- a/net/netfilter/nf_conntrack_proto_tcp.c
+++ b/net/netfilter/nf_conntrack_proto_tcp.c
@@ -93,21 +93,21 @@
 #define HOURS * 60 MINS
 #define DAYS * 24 HOURS
 
-unsigned long nf_ct_tcp_timeout_syn_sent =      2 MINS;
-unsigned long nf_ct_tcp_timeout_syn_recv =     60 SECS;
-unsigned long nf_ct_tcp_timeout_established =   5 DAYS;
-unsigned long nf_ct_tcp_timeout_fin_wait =      2 MINS;
-unsigned long nf_ct_tcp_timeout_close_wait =   60 SECS;
-unsigned long nf_ct_tcp_timeout_last_ack =     30 SECS;
-unsigned long nf_ct_tcp_timeout_time_wait =     2 MINS;
-unsigned long nf_ct_tcp_timeout_close =        10 SECS;
+unsigned int nf_ct_tcp_timeout_syn_sent =      2 MINS;
+unsigned int nf_ct_tcp_timeout_syn_recv =     60 SECS;
+unsigned int nf_ct_tcp_timeout_established =   5 DAYS;
+unsigned int nf_ct_tcp_timeout_fin_wait =      2 MINS;
+unsigned int nf_ct_tcp_timeout_close_wait =   60 SECS;
+unsigned int nf_ct_tcp_timeout_last_ack =     30 SECS;
+unsigned int nf_ct_tcp_timeout_time_wait =     2 MINS;
+unsigned int nf_ct_tcp_timeout_close =        10 SECS;
 
 /* RFC1122 says the R2 limit should be at least 100 seconds.
    Linux uses 15 packets as limit, which corresponds 
    to ~13-30min depending on RTO. */
-unsigned long nf_ct_tcp_timeout_max_retrans =     5 MINS;
+unsigned int nf_ct_tcp_timeout_max_retrans =     5 MINS;
  
-static unsigned long * tcp_timeouts[]
+static unsigned int * tcp_timeouts[]
 = { NULL,                              /* TCP_CONNTRACK_NONE */
     &nf_ct_tcp_timeout_syn_sent,       /* TCP_CONNTRACK_SYN_SENT, */
     &nf_ct_tcp_timeout_syn_recv,       /* TCP_CONNTRACK_SYN_RECV, */
diff --git a/net/netfilter/nf_conntrack_proto_udp.c b/net/netfilter/nf_conntrack_proto_udp.c
index 1a592a5..4264dd0 100644
--- a/net/netfilter/nf_conntrack_proto_udp.c
+++ b/net/netfilter/nf_conntrack_proto_udp.c
@@ -27,8 +27,8 @@
 #include <linux/netfilter_ipv6.h>
 #include <net/netfilter/nf_conntrack_protocol.h>
 
-unsigned long nf_ct_udp_timeout = 30*HZ;
-unsigned long nf_ct_udp_timeout_stream = 180*HZ;
+unsigned int nf_ct_udp_timeout = 30*HZ;
+unsigned int nf_ct_udp_timeout_stream = 180*HZ;
 
 static int udp_pkt_to_tuple(const struct sk_buff *skb,
 			     unsigned int dataoff,
diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
index d17e42b..3531d14 100644
--- a/net/netfilter/nf_conntrack_standalone.c
+++ b/net/netfilter/nf_conntrack_standalone.c
@@ -431,25 +431,25 @@
 extern unsigned int nf_conntrack_htable_size;
 
 /* From nf_conntrack_proto_tcp.c */
-extern unsigned long nf_ct_tcp_timeout_syn_sent;
-extern unsigned long nf_ct_tcp_timeout_syn_recv;
-extern unsigned long nf_ct_tcp_timeout_established;
-extern unsigned long nf_ct_tcp_timeout_fin_wait;
-extern unsigned long nf_ct_tcp_timeout_close_wait;
-extern unsigned long nf_ct_tcp_timeout_last_ack;
-extern unsigned long nf_ct_tcp_timeout_time_wait;
-extern unsigned long nf_ct_tcp_timeout_close;
-extern unsigned long nf_ct_tcp_timeout_max_retrans;
+extern unsigned int nf_ct_tcp_timeout_syn_sent;
+extern unsigned int nf_ct_tcp_timeout_syn_recv;
+extern unsigned int nf_ct_tcp_timeout_established;
+extern unsigned int nf_ct_tcp_timeout_fin_wait;
+extern unsigned int nf_ct_tcp_timeout_close_wait;
+extern unsigned int nf_ct_tcp_timeout_last_ack;
+extern unsigned int nf_ct_tcp_timeout_time_wait;
+extern unsigned int nf_ct_tcp_timeout_close;
+extern unsigned int nf_ct_tcp_timeout_max_retrans;
 extern int nf_ct_tcp_loose;
 extern int nf_ct_tcp_be_liberal;
 extern int nf_ct_tcp_max_retrans;
 
 /* From nf_conntrack_proto_udp.c */
-extern unsigned long nf_ct_udp_timeout;
-extern unsigned long nf_ct_udp_timeout_stream;
+extern unsigned int nf_ct_udp_timeout;
+extern unsigned int nf_ct_udp_timeout_stream;
 
 /* From nf_conntrack_proto_generic.c */
-extern unsigned long nf_ct_generic_timeout;
+extern unsigned int nf_ct_generic_timeout;
 
 /* Log invalid packets of a given protocol */
 static int log_invalid_proto_min = 0;
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index a67f1b4..2101b45 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -24,6 +24,7 @@
 #include <linux/config.h>
 #include <linux/module.h>
 
+#include <linux/capability.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/signal.h>
@@ -1422,7 +1423,7 @@
 	while (skb->len >= nlmsg_total_size(0)) {
 		nlh = (struct nlmsghdr *) skb->data;
 
-		if (skb->len < nlh->nlmsg_len)
+		if (nlh->nlmsg_len < NLMSG_HDRLEN || skb->len < nlh->nlmsg_len)
 			return 0;
 
 		total_len = min(NLMSG_ALIGN(nlh->nlmsg_len), skb->len);
diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
index 63b0e4a..d44981f 100644
--- a/net/netrom/af_netrom.c
+++ b/net/netrom/af_netrom.c
@@ -11,6 +11,7 @@
 #include <linux/config.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/types.h>
 #include <linux/socket.h>
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index f69e5ed..ee93abc 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -53,6 +53,7 @@
 #include <linux/types.h>
 #include <linux/sched.h>
 #include <linux/mm.h>
+#include <linux/capability.h>
 #include <linux/fcntl.h>
 #include <linux/socket.h>
 #include <linux/in.h>
@@ -1237,7 +1238,7 @@
 		goto done;
 
 	err = -ENOBUFS;
-	i = (struct packet_mclist *)kmalloc(sizeof(*i), GFP_KERNEL);
+	i = kmalloc(sizeof(*i), GFP_KERNEL);
 	if (i == NULL)
 		goto done;
 
diff --git a/net/rose/af_rose.c b/net/rose/af_rose.c
index 63090be..ea65396 100644
--- a/net/rose/af_rose.c
+++ b/net/rose/af_rose.c
@@ -9,7 +9,9 @@
  * Copyright (C) Terry Dawson VK2KTJ (terry@animats.net)
  * Copyright (C) Tomi Manninen OH2BNS (oh2bns@sral.fi)
  */
+
 #include <linux/config.h>
+#include <linux/capability.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/init.h>
diff --git a/net/rxrpc/connection.c b/net/rxrpc/connection.c
index 2ba14a7..0e0a455 100644
--- a/net/rxrpc/connection.c
+++ b/net/rxrpc/connection.c
@@ -220,6 +220,7 @@
 {
 	struct rxrpc_connection *conn, *candidate = NULL;
 	struct list_head *_p;
+	struct sk_buff *pkt = msg->pkt;
 	int ret, fresh = 0;
 	__be32 x_epoch, x_connid;
 	__be16 x_port, x_servid;
@@ -229,10 +230,10 @@
 	_enter("%p{{%hu}},%u,%hu",
 	       peer,
 	       peer->trans->port,
-	       ntohs(msg->pkt->h.uh->source),
+	       ntohs(pkt->h.uh->source),
 	       ntohs(msg->hdr.serviceId));
 
-	x_port		= msg->pkt->h.uh->source;
+	x_port		= pkt->h.uh->source;
 	x_epoch		= msg->hdr.epoch;
 	x_clflag	= msg->hdr.flags & RXRPC_CLIENT_INITIATED;
 	x_connid	= htonl(ntohl(msg->hdr.cid) & RXRPC_CIDMASK);
@@ -267,7 +268,7 @@
 		/* fill in the specifics */
 		candidate->addr.sin_family	= AF_INET;
 		candidate->addr.sin_port	= x_port;
-		candidate->addr.sin_addr.s_addr = msg->pkt->nh.iph->saddr;
+		candidate->addr.sin_addr.s_addr = pkt->nh.iph->saddr;
 		candidate->in_epoch		= x_epoch;
 		candidate->out_epoch		= x_epoch;
 		candidate->in_clientflag	= RXRPC_CLIENT_INITIATED;
@@ -675,6 +676,7 @@
 				   struct rxrpc_message *msg)
 {
 	struct rxrpc_message *pmsg;
+	struct dst_entry *dst;
 	struct list_head *_p;
 	unsigned cix, seq;
 	int ret = 0;
@@ -710,10 +712,10 @@
 
 	call->pkt_rcv_count++;
 
-	if (msg->pkt->dst && msg->pkt->dst->dev)
+	dst = msg->pkt->dst;
+	if (dst && dst->dev)
 		conn->peer->if_mtu =
-			msg->pkt->dst->dev->mtu -
-			msg->pkt->dst->dev->hard_header_len;
+			dst->dev->mtu - dst->dev->hard_header_len;
 
 	/* queue on the call in seq order */
 	rxrpc_get_message(msg);
diff --git a/net/sched/Kconfig b/net/sched/Kconfig
index 55cd532..8a260d4 100644
--- a/net/sched/Kconfig
+++ b/net/sched/Kconfig
@@ -411,7 +411,7 @@
 	tristate "Metadata"
 	depends on NET_EMATCH
 	---help---
-	  Say Y here if you want to be ablt to classify packets based on
+	  Say Y here if you want to be able to classify packets based on
 	  metadata such as load average, netfilter attributes, socket
 	  attributes and routing decisions.
 
diff --git a/net/sched/ematch.c b/net/sched/ematch.c
index 64b047c..5cb956b 100644
--- a/net/sched/ematch.c
+++ b/net/sched/ematch.c
@@ -92,7 +92,6 @@
 #include <linux/rtnetlink.h>
 #include <linux/skbuff.h>
 #include <net/pkt_cls.h>
-#include <config/net/ematch/stack.h>
 
 static LIST_HEAD(ematch_ops);
 static DEFINE_RWLOCK(ematch_mod_lock);
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index f9573eb..556c495 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -1287,7 +1287,7 @@
 			- (bodysize % SCTP_COOKIE_MULTIPLE);
 	*cookie_len = headersize + bodysize;
 
-	retval = (sctp_cookie_param_t *)kmalloc(*cookie_len, GFP_ATOMIC);
+	retval = kmalloc(*cookie_len, GFP_ATOMIC);
 
 	if (!retval) {
 		*cookie_len = 0;
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index fc04d18..c98ee375 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -63,6 +63,7 @@
 #include <linux/wait.h>
 #include <linux/time.h>
 #include <linux/ip.h>
+#include <linux/capability.h>
 #include <linux/fcntl.h>
 #include <linux/poll.h>
 #include <linux/init.h>
@@ -860,7 +861,7 @@
 		return -EFAULT;
 
 	/* Alloc space for the address array in kernel memory.  */
-	kaddrs = (struct sockaddr *)kmalloc(addrs_size, GFP_KERNEL);
+	kaddrs = kmalloc(addrs_size, GFP_KERNEL);
 	if (unlikely(!kaddrs))
 		return -ENOMEM;
 
@@ -1150,7 +1151,7 @@
 		return -EFAULT;
 
 	/* Alloc space for the address array in kernel memory.  */
-	kaddrs = (struct sockaddr *)kmalloc(addrs_size, GFP_KERNEL);
+	kaddrs = kmalloc(addrs_size, GFP_KERNEL);
 	if (unlikely(!kaddrs))
 		return -ENOMEM;
 
diff --git a/net/socket.c b/net/socket.c
index 06fa217..b38a263 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -993,7 +993,7 @@
 
 	if (on)
 	{
-		fna=(struct fasync_struct *)kmalloc(sizeof(struct fasync_struct), GFP_KERNEL);
+		fna = kmalloc(sizeof(struct fasync_struct), GFP_KERNEL);
 		if(fna==NULL)
 			return -ENOMEM;
 	}
diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
index 8c77560..9ac1b8c2 100644
--- a/net/sunrpc/auth.c
+++ b/net/sunrpc/auth.c
@@ -94,7 +94,7 @@
 	struct rpc_cred_cache *new;
 	int i;
 
-	new = (struct rpc_cred_cache *)kmalloc(sizeof(*new), GFP_KERNEL);
+	new = kmalloc(sizeof(*new), GFP_KERNEL);
 	if (!new)
 		return -ENOMEM;
 	for (i = 0; i < RPC_CREDCACHE_NR; i++)
diff --git a/net/sunrpc/auth_unix.c b/net/sunrpc/auth_unix.c
index 890fb5e..1b3ed4f 100644
--- a/net/sunrpc/auth_unix.c
+++ b/net/sunrpc/auth_unix.c
@@ -70,7 +70,7 @@
 	dprintk("RPC:      allocating UNIX cred for uid %d gid %d\n",
 				acred->uid, acred->gid);
 
-	if (!(cred = (struct unx_cred *) kmalloc(sizeof(*cred), GFP_KERNEL)))
+	if (!(cred = kmalloc(sizeof(*cred), GFP_KERNEL)))
 		return ERR_PTR(-ENOMEM);
 
 	atomic_set(&cred->uc_count, 1);
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index 5530ac8..d2f0550 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -118,7 +118,7 @@
 		goto out_err;
 
 	err = -ENOMEM;
-	clnt = (struct rpc_clnt *) kmalloc(sizeof(*clnt), GFP_KERNEL);
+	clnt = kmalloc(sizeof(*clnt), GFP_KERNEL);
 	if (!clnt)
 		goto out_err;
 	memset(clnt, 0, sizeof(*clnt));
@@ -225,7 +225,7 @@
 {
 	struct rpc_clnt *new;
 
-	new = (struct rpc_clnt *)kmalloc(sizeof(*new), GFP_KERNEL);
+	new = kmalloc(sizeof(*new), GFP_KERNEL);
 	if (!new)
 		goto out_no_clnt;
 	memcpy(new, clnt, sizeof(*new));
@@ -268,7 +268,8 @@
 		clnt->cl_oneshot = 0;
 		clnt->cl_dead = 0;
 		rpc_killall_tasks(clnt);
-		sleep_on_timeout(&destroy_wait, 1*HZ);
+		wait_event_timeout(destroy_wait,
+			!atomic_read(&clnt->cl_users), 1*HZ);
 	}
 
 	if (atomic_read(&clnt->cl_users) < 0) {
diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
index b19cc26..b08419e 100644
--- a/net/sunrpc/svc.c
+++ b/net/sunrpc/svc.c
@@ -32,7 +32,7 @@
 	int vers;
 	unsigned int xdrsize;
 
-	if (!(serv = (struct svc_serv *) kmalloc(sizeof(*serv), GFP_KERNEL)))
+	if (!(serv = kmalloc(sizeof(*serv), GFP_KERNEL)))
 		return NULL;
 	memset(serv, 0, sizeof(*serv));
 	serv->sv_name      = prog->pg_name;
@@ -166,8 +166,8 @@
 	memset(rqstp, 0, sizeof(*rqstp));
 	init_waitqueue_head(&rqstp->rq_wait);
 
-	if (!(rqstp->rq_argp = (u32 *) kmalloc(serv->sv_xdrsize, GFP_KERNEL))
-	 || !(rqstp->rq_resp = (u32 *) kmalloc(serv->sv_xdrsize, GFP_KERNEL))
+	if (!(rqstp->rq_argp = kmalloc(serv->sv_xdrsize, GFP_KERNEL))
+	 || !(rqstp->rq_resp = kmalloc(serv->sv_xdrsize, GFP_KERNEL))
 	 || !svc_init_buffer(rqstp, serv->sv_bufsz))
 		goto out_thread;
 
diff --git a/net/wanrouter/af_wanpipe.c b/net/wanrouter/af_wanpipe.c
index 7a43ae4..8b9bf4a 100644
--- a/net/wanrouter/af_wanpipe.c
+++ b/net/wanrouter/af_wanpipe.c
@@ -36,6 +36,7 @@
 #include <linux/types.h>
 #include <linux/sched.h>
 #include <linux/mm.h>
+#include <linux/capability.h>
 #include <linux/fcntl.h>
 #include <linux/socket.h>
 #include <linux/in.h>
diff --git a/net/wanrouter/wanmain.c b/net/wanrouter/wanmain.c
index bcf7b3f..c34833d 100644
--- a/net/wanrouter/wanmain.c
+++ b/net/wanrouter/wanmain.c
@@ -44,6 +44,7 @@
 
 #include <linux/config.h>
 #include <linux/stddef.h>	/* offsetof(), etc. */
+#include <linux/capability.h>
 #include <linux/errno.h>	/* return codes */
 #include <linux/kernel.h>
 #include <linux/init.h>
diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c
index bfabaf9..72b6ff3 100644
--- a/net/x25/af_x25.c
+++ b/net/x25/af_x25.c
@@ -37,6 +37,7 @@
 
 #include <linux/config.h>
 #include <linux/module.h>
+#include <linux/capability.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index db3c708..0168d6c 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -3,6 +3,7 @@
 
 # Convinient variables
 comma   := ,
+squote  := '
 empty   :=
 space   := $(empty) $(empty)
 
@@ -12,6 +13,10 @@
 depfile = $(subst $(comma),_,$(@D)/.$(@F).d)
 
 ###
+# Escape single quote for use in echo statements
+escsq = $(subst $(squote),'\$(squote)',$1)
+
+###
 # filechk is used to check if the content of a generated file is updated.
 # Sample usage:
 # define filechk_sample
@@ -47,7 +52,7 @@
 
 # If quiet is set, only print short version of command
 cmd = @$(if $($(quiet)cmd_$(1)),\
-      echo '  $(subst ','\'',$($(quiet)cmd_$(1)))' &&) $(cmd_$(1))
+      echo '  $(call escsq,$($(quiet)cmd_$(1)))' &&) $(cmd_$(1))
 
 # Add $(obj)/ for paths that is not absolute
 objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o)))
@@ -68,7 +73,7 @@
 
 # echo command. Short version is $(quiet) equals quiet, otherwise full command
 echo-cmd = $(if $($(quiet)cmd_$(1)), \
-	echo '  $(subst ','\'',$($(quiet)cmd_$(1)))';)
+	echo '  $(call escsq,$($(quiet)cmd_$(1)))';)
 
 # function to only execute the passed command if necessary
 # >'< substitution is for echo to work, >$< substitution to preserve $ when reloading .cmd file
@@ -78,7 +83,7 @@
 	@set -e; \
 	$(echo-cmd) \
 	$(cmd_$(1)); \
-	echo 'cmd_$@ := $(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).cmd)
+	echo 'cmd_$@ := $(subst $$,$$$$,$(call escsq,$(cmd_$(1))))' > $(@D)/.$(@F).cmd)
 
 # execute the command and also postprocess generated .d dependencies
 # file
@@ -87,7 +92,7 @@
 	@set -e; \
 	$(echo-cmd) \
 	$(cmd_$(1)); \
-	scripts/basic/fixdep $(depfile) $@ '$(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).tmp; \
+	scripts/basic/fixdep $(depfile) $@ '$(subst $$,$$$$,$(call escsq,$(cmd_$(1))))' > $(@D)/.$(@F).tmp; \
 	rm -f $(depfile); \
 	mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd)
 
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 506e3f3..c33e62b 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -179,10 +179,10 @@
 define rule_cc_o_c
 	$(if $($(quiet)cmd_checksrc),echo '  $($(quiet)cmd_checksrc)';)   \
 	$(cmd_checksrc)							  \
-	$(if $($(quiet)cmd_cc_o_c),echo '  $(subst ','\'',$($(quiet)cmd_cc_o_c))';)  \
+	$(if $($(quiet)cmd_cc_o_c),echo '  $(call escsq,$($(quiet)cmd_cc_o_c))';)  \
 	$(cmd_cc_o_c);							  \
 	$(cmd_modversions)						  \
-	scripts/basic/fixdep $(depfile) $@ '$(subst ','\'',$(cmd_cc_o_c))' > $(@D)/.$(@F).tmp;  \
+	scripts/basic/fixdep $(depfile) $@ '$(call escsq,$(cmd_cc_o_c))' > $(@D)/.$(@F).tmp;  \
 	rm -f $(depfile);						  \
 	mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd
 endef
diff --git a/scripts/kconfig/lxdialog/Makefile b/scripts/kconfig/lxdialog/Makefile
index a45a13f..8f41d9a 100644
--- a/scripts/kconfig/lxdialog/Makefile
+++ b/scripts/kconfig/lxdialog/Makefile
@@ -1,42 +1,18 @@
-HOST_EXTRACFLAGS := -DLOCALE 
-ifeq ($(shell uname),SunOS)
-HOST_LOADLIBES   := -lcurses
-else
-HOST_LOADLIBES   := -lncurses
-endif
+# Makefile to build lxdialog package
+#
 
-ifeq (/usr/include/ncurses/ncurses.h, $(wildcard /usr/include/ncurses/ncurses.h))
-        HOST_EXTRACFLAGS += -I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>"
-else
-ifeq (/usr/include/ncurses/curses.h, $(wildcard /usr/include/ncurses/curses.h))
-        HOST_EXTRACFLAGS += -I/usr/include/ncurses -DCURSES_LOC="<ncurses/curses.h>"
-else
-ifeq (/usr/include/ncurses.h, $(wildcard /usr/include/ncurses.h))
-        HOST_EXTRACFLAGS += -DCURSES_LOC="<ncurses.h>"
-else
-	HOST_EXTRACFLAGS += -DCURSES_LOC="<curses.h>"
-endif
-endif
-endif
+check-lxdialog   := $(srctree)/$(src)/check-lxdialog.sh
+HOST_EXTRACFLAGS := $(shell $(CONFIG_SHELL) $(check-lxdialog) -ccflags)
+HOST_LOADLIBES   := $(shell $(CONFIG_SHELL) $(check-lxdialog) -ldflags)
+ 
+HOST_EXTRACFLAGS += -DLOCALE 
+
+.PHONY: dochecklxdialog
+$(obj)/dochecklxdialog:
+	$(Q)$(CONFIG_SHELL) $(check-lxdialog) -check $(HOSTCC) $(HOST_LOADLIBES)
 
 hostprogs-y	:= lxdialog
-always		:= ncurses $(hostprogs-y)
+always		:= $(hostprogs-y) dochecklxdialog
 
 lxdialog-objs := checklist.o menubox.o textbox.o yesno.o inputbox.o \
 		 util.o lxdialog.o msgbox.o
-
-.PHONY: $(obj)/ncurses
-$(obj)/ncurses:
-	@echo "main() {}" > lxtemp.c
-	@if $(HOSTCC) lxtemp.c  $(HOST_LOADLIBES); then \
-		rm -f lxtemp.c a.out; \
-	else \
-		rm -f lxtemp.c; \
-		echo -e "\007" ;\
-		echo ">> Unable to find the Ncurses libraries." ;\
-		echo ">>" ;\
-		echo ">> You must install ncurses-devel in order" ;\
-		echo ">> to use 'make menuconfig'" ;\
-		echo ;\
-		exit 1 ;\
-	fi
diff --git a/scripts/kconfig/lxdialog/check-lxdialog.sh b/scripts/kconfig/lxdialog/check-lxdialog.sh
new file mode 100644
index 0000000..a3c141b
--- /dev/null
+++ b/scripts/kconfig/lxdialog/check-lxdialog.sh
@@ -0,0 +1,67 @@
+#!/bin/sh
+# Check ncurses compatibility
+
+# What library to link
+ldflags()
+{
+	if [ `uname` == SunOS ]; then
+		echo '-lcurses'
+	else
+		echo '-lncurses'
+	fi
+}
+
+# Where is ncurses.h?
+ccflags()
+{
+	if [ -f /usr/include/ncurses/ncurses.h ]; then
+		echo '-I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>"'
+	elif [ -f /usr/include/ncurses/curses.h ]; then
+		echo '-I/usr/include/ncurses -DCURSES_LOC="<ncurses/curses.h>"'
+	elif [ -f /usr/include/ncurses.h ]; then
+		echo '-DCURSES_LOC="<ncurses.h>"'
+	else
+		echo '-DCURSES_LOC="<curses.h>"'
+	fi
+}
+
+compiler=""
+# Check if we can link to ncurses
+check() {
+	echo "main() {}" | $compiler -xc -
+	if [ $? != 0 ]; then
+		echo " *** Unable to find the ncurses libraries."          1>&2
+		echo " *** make menuconfig require the ncurses libraries"  1>&2
+		echo " *** "                                               1>&2
+		echo " *** Install ncurses (ncurses-devel) and try again"  1>&2
+		echo " *** "                                               1>&2
+		exit 1
+	fi
+}
+
+usage() {
+	printf "Usage: $0 [-check compiler options|-header|-library]\n"
+}
+
+if [ $# == 0 ]; then
+	usage
+	exit 1
+fi
+
+case "$1" in
+	"-check")
+		shift
+		compiler="$@"
+		check
+		;;
+	"-ccflags")
+		ccflags
+		;;
+	"-ldflags")
+		ldflags
+		;;
+	"*")
+		usage
+		exit 1
+		;;
+esac
diff --git a/scripts/kernel-doc b/scripts/kernel-doc
index 2f45fd2..9fd5f5b 100755
--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -1405,6 +1405,7 @@
     my $type;
     my $param;
 
+    # temporarily replace commas inside function pointer definition
     while ($args =~ /(\([^\),]+),/) {
         $args =~ s/(\([^\),]+),/$1#/g;
     }
@@ -1465,11 +1466,10 @@
 	my $param_name = $param;
 	$param_name =~ s/\[.*//;
 
-	if ($type eq "" && $param eq "...")
+	if ($type eq "" && $param =~ /\.\.\.$/)
 	{
 	    $type="";
-	    $param="...";
-	    $parameterdescs{"..."} = "variable arguments";
+	    $parameterdescs{$param} = "variable arguments";
 	}
 	elsif ($type eq "" && ($param eq "" or $param eq "void"))
 	{
@@ -1477,7 +1477,11 @@
 	    $param="void";
 	    $parameterdescs{void} = "no arguments";
 	}
-	if (defined $type && $type && !defined $parameterdescs{$param_name}) {
+	# warn if parameter has no description
+	# (but ignore ones starting with # as these are no parameters
+	# but inline preprocessor statements
+	if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
+
 	    $parameterdescs{$param_name} = $undescribed;
 
 	    if (($type eq 'function') || ($type eq 'enum')) {
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index e0eedff..be97caf 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -417,7 +417,7 @@
 		do_input(alias, id->sndbit, 0, SND_MAX);
 	sprintf(alias + strlen(alias), "f*");
 	if (id->flags&INPUT_DEVICE_ID_MATCH_FFBIT)
-		do_input(alias, id->ffbit, 0, SND_MAX);
+		do_input(alias, id->ffbit, 0, FF_MAX);
 	sprintf(alias + strlen(alias), "w*");
 	if (id->flags&INPUT_DEVICE_ID_MATCH_SWBIT)
 		do_input(alias, id->swbit, 0, SW_MAX);
diff --git a/scripts/reference_discarded.pl b/scripts/reference_discarded.pl
index c2d5414..4ee6ab2 100644
--- a/scripts/reference_discarded.pl
+++ b/scripts/reference_discarded.pl
@@ -71,6 +71,11 @@
 # printf("ignoring %d conglomerate(s)\n", $ignore);
 
 # printf("Scanning objects\n");
+
+# Keith Ownes <kaos@sgi.com> commented:
+# For our future {in}sanity, add a comment that this is the ppc .opd
+# section, not the ia64 .opd section.
+# ia64 .opd should not point to discarded sections.
 $errorcount = 0;
 foreach $object (keys(%object)) {
 	my $from;
@@ -88,6 +93,7 @@
 		    ($from !~ /\.text\.exit$/ &&
 		     $from !~ /\.exit\.text$/ &&
 		     $from !~ /\.data\.exit$/ &&
+		     $from !~ /\.opd$/ &&
 		     $from !~ /\.exit\.data$/ &&
 		     $from !~ /\.altinstructions$/ &&
 		     $from !~ /\.pdr$/ &&
diff --git a/scripts/setlocalversion b/scripts/setlocalversion
index f54dac8..9a23825 100644
--- a/scripts/setlocalversion
+++ b/scripts/setlocalversion
@@ -17,6 +17,6 @@
 
 	# Are there uncommitted changes?
 	if git diff-files | read dummy; then
-		printf '%s' -git_dirty
+		printf '%s' -dirty
 	fi
 fi
diff --git a/security/commoncap.c b/security/commoncap.c
index 04c12f5..8a6e097 100644
--- a/security/commoncap.c
+++ b/security/commoncap.c
@@ -7,6 +7,7 @@
  *
  */
 
+#include <linux/capability.h>
 #include <linux/config.h>
 #include <linux/module.h>
 #include <linux/init.h>
diff --git a/security/dummy.c b/security/dummy.c
index a15c547..f1a5bd9 100644
--- a/security/dummy.c
+++ b/security/dummy.c
@@ -14,6 +14,7 @@
 
 #undef DEBUG
 
+#include <linux/capability.h>
 #include <linux/config.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
index 3d2ebae..90db5c7 100644
--- a/security/keys/keyctl.c
+++ b/security/keys/keyctl.c
@@ -16,6 +16,7 @@
 #include <linux/syscalls.h>
 #include <linux/keyctl.h>
 #include <linux/fs.h>
+#include <linux/capability.h>
 #include <linux/err.h>
 #include <asm/uaccess.h>
 #include "internal.h"
diff --git a/security/security.c b/security/security.c
index ed5fb80..f693e1f 100644
--- a/security/security.c
+++ b/security/security.c
@@ -11,6 +11,7 @@
  *	(at your option) any later version.
  */
 
+#include <linux/capability.h>
 #include <linux/config.h>
 #include <linux/module.h>
 #include <linux/init.h>
diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
index 44eb4d7..8a76492 100644
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -1712,11 +1712,11 @@
 		goto out;
 	}
 
-	*names = (char**)kcalloc(*len, sizeof(char*), GFP_ATOMIC);
+       *names = kcalloc(*len, sizeof(char*), GFP_ATOMIC);
 	if (!*names)
 		goto err;
 
-	*values = (int*)kcalloc(*len, sizeof(int), GFP_ATOMIC);
+       *values = kcalloc(*len, sizeof(int), GFP_ATOMIC);
 	if (!*values)
 		goto err;
 
@@ -1724,7 +1724,7 @@
 		size_t name_len;
 		(*values)[i] = policydb.bool_val_to_struct[i]->state;
 		name_len = strlen(policydb.p_bool_val_to_name[i]) + 1;
-		(*names)[i] = (char*)kmalloc(sizeof(char) * name_len, GFP_ATOMIC);
+               (*names)[i] = kmalloc(sizeof(char) * name_len, GFP_ATOMIC);
 		if (!(*names)[i])
 			goto err;
 		strncpy((*names)[i], policydb.p_bool_val_to_name[i], name_len);
diff --git a/sound/oss/dmasound/dmasound.h b/sound/oss/dmasound/dmasound.h
index 222014caf..a1b0b92 100644
--- a/sound/oss/dmasound/dmasound.h
+++ b/sound/oss/dmasound/dmasound.h
@@ -270,7 +270,6 @@
 #define SW_INPUT_VOLUME_SCALE	4
 #define SW_INPUT_VOLUME_DEFAULT	(128 / SW_INPUT_VOLUME_SCALE)
 
-extern int expand_bal;	/* Balance factor for expanding (not volume!) */
 extern int expand_read_bal;	/* Balance factor for reading */
 extern uint software_input_volume; /* software implemented recording volume! */
 
diff --git a/sound/oss/dmasound/dmasound_atari.c b/sound/oss/dmasound/dmasound_atari.c
index 59eb53f..dc31373 100644
--- a/sound/oss/dmasound/dmasound_atari.c
+++ b/sound/oss/dmasound/dmasound_atari.c
@@ -67,46 +67,46 @@
  * ++geert: split in even more functions (one per format)
  */
 
-static ssize_t ata_ct_law(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ct_law(const u_char __user *userPtr, size_t userCount,
 			  u_char frame[], ssize_t *frameUsed,
 			  ssize_t frameLeft);
-static ssize_t ata_ct_s8(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ct_s8(const u_char __user *userPtr, size_t userCount,
 			 u_char frame[], ssize_t *frameUsed,
 			 ssize_t frameLeft);
-static ssize_t ata_ct_u8(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ct_u8(const u_char __user *userPtr, size_t userCount,
 			 u_char frame[], ssize_t *frameUsed,
 			 ssize_t frameLeft);
-static ssize_t ata_ct_s16be(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ct_s16be(const u_char __user *userPtr, size_t userCount,
 			    u_char frame[], ssize_t *frameUsed,
 			    ssize_t frameLeft);
-static ssize_t ata_ct_u16be(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ct_u16be(const u_char __user *userPtr, size_t userCount,
 			    u_char frame[], ssize_t *frameUsed,
 			    ssize_t frameLeft);
-static ssize_t ata_ct_s16le(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ct_s16le(const u_char __user *userPtr, size_t userCount,
 			    u_char frame[], ssize_t *frameUsed,
 			    ssize_t frameLeft);
-static ssize_t ata_ct_u16le(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ct_u16le(const u_char __user *userPtr, size_t userCount,
 			    u_char frame[], ssize_t *frameUsed,
 			    ssize_t frameLeft);
-static ssize_t ata_ctx_law(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ctx_law(const u_char __user *userPtr, size_t userCount,
 			   u_char frame[], ssize_t *frameUsed,
 			   ssize_t frameLeft);
-static ssize_t ata_ctx_s8(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ctx_s8(const u_char __user *userPtr, size_t userCount,
 			  u_char frame[], ssize_t *frameUsed,
 			  ssize_t frameLeft);
-static ssize_t ata_ctx_u8(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ctx_u8(const u_char __user *userPtr, size_t userCount,
 			  u_char frame[], ssize_t *frameUsed,
 			  ssize_t frameLeft);
-static ssize_t ata_ctx_s16be(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ctx_s16be(const u_char __user *userPtr, size_t userCount,
 			     u_char frame[], ssize_t *frameUsed,
 			     ssize_t frameLeft);
-static ssize_t ata_ctx_u16be(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ctx_u16be(const u_char __user *userPtr, size_t userCount,
 			     u_char frame[], ssize_t *frameUsed,
 			     ssize_t frameLeft);
-static ssize_t ata_ctx_s16le(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ctx_s16le(const u_char __user *userPtr, size_t userCount,
 			     u_char frame[], ssize_t *frameUsed,
 			     ssize_t frameLeft);
-static ssize_t ata_ctx_u16le(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ctx_u16le(const u_char __user *userPtr, size_t userCount,
 			     u_char frame[], ssize_t *frameUsed,
 			     ssize_t frameLeft);
 
@@ -151,7 +151,7 @@
 /*** Translations ************************************************************/
 
 
-static ssize_t ata_ct_law(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ct_law(const u_char __user *userPtr, size_t userCount,
 			  u_char frame[], ssize_t *frameUsed,
 			  ssize_t frameLeft)
 {
@@ -176,7 +176,7 @@
 }
 
 
-static ssize_t ata_ct_s8(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ct_s8(const u_char __user *userPtr, size_t userCount,
 			 u_char frame[], ssize_t *frameUsed,
 			 ssize_t frameLeft)
 {
@@ -194,7 +194,7 @@
 }
 
 
-static ssize_t ata_ct_u8(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ct_u8(const u_char __user *userPtr, size_t userCount,
 			 u_char frame[], ssize_t *frameUsed,
 			 ssize_t frameLeft)
 {
@@ -217,8 +217,9 @@
 		used = count*2;
 		while (count > 0) {
 			u_short data;
-			if (get_user(data, ((u_short *)userPtr)++))
+			if (get_user(data, (u_short __user *)userPtr))
 				return -EFAULT;
+			userPtr += 2;
 			*p++ = data ^ 0x8080;
 			count--;
 		}
@@ -228,7 +229,7 @@
 }
 
 
-static ssize_t ata_ct_s16be(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ct_s16be(const u_char __user *userPtr, size_t userCount,
 			    u_char frame[], ssize_t *frameUsed,
 			    ssize_t frameLeft)
 {
@@ -240,8 +241,9 @@
 		used = count*2;
 		while (count > 0) {
 			u_short data;
-			if (get_user(data, ((u_short *)userPtr)++))
+			if (get_user(data, (u_short __user *)userPtr))
 				return -EFAULT;
+			userPtr += 2;
 			*p++ = data;
 			*p++ = data;
 			count--;
@@ -259,7 +261,7 @@
 }
 
 
-static ssize_t ata_ct_u16be(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ct_u16be(const u_char __user *userPtr, size_t userCount,
 			    u_char frame[], ssize_t *frameUsed,
 			    ssize_t frameLeft)
 {
@@ -271,8 +273,9 @@
 		used = count*2;
 		while (count > 0) {
 			u_short data;
-			if (get_user(data, ((u_short *)userPtr)++))
+			if (get_user(data, (u_short __user *)userPtr))
 				return -EFAULT;
+			userPtr += 2;
 			data ^= 0x8000;
 			*p++ = data;
 			*p++ = data;
@@ -284,9 +287,10 @@
 		count = min_t(unsigned long, userCount, frameLeft)>>2;
 		used = count*4;
 		while (count > 0) {
-			u_long data;
-			if (get_user(data, ((u_int *)userPtr)++))
+			u_int data;
+			if (get_user(data, (u_int __user *)userPtr))
 				return -EFAULT;
+			userPtr += 4;
 			*p++ = data ^ 0x80008000;
 			count--;
 		}
@@ -296,7 +300,7 @@
 }
 
 
-static ssize_t ata_ct_s16le(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ct_s16le(const u_char __user *userPtr, size_t userCount,
 			    u_char frame[], ssize_t *frameUsed,
 			    ssize_t frameLeft)
 {
@@ -309,8 +313,9 @@
 		used = count*2;
 		while (count > 0) {
 			u_short data;
-			if (get_user(data, ((u_short *)userPtr)++))
+			if (get_user(data, (u_short __user *)userPtr))
 				return -EFAULT;
+			userPtr += 2;
 			data = le2be16(data);
 			*p++ = data;
 			*p++ = data;
@@ -323,8 +328,9 @@
 		used = count*4;
 		while (count > 0) {
 			u_long data;
-			if (get_user(data, ((u_int *)userPtr)++))
+			if (get_user(data, (u_int __user *)userPtr))
 				return -EFAULT;
+			userPtr += 4;
 			data = le2be16dbl(data);
 			*p++ = data;
 			count--;
@@ -335,7 +341,7 @@
 }
 
 
-static ssize_t ata_ct_u16le(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ct_u16le(const u_char __user *userPtr, size_t userCount,
 			    u_char frame[], ssize_t *frameUsed,
 			    ssize_t frameLeft)
 {
@@ -348,8 +354,9 @@
 		used = count*2;
 		while (count > 0) {
 			u_short data;
-			if (get_user(data, ((u_short *)userPtr)++))
+			if (get_user(data, (u_short __user *)userPtr))
 				return -EFAULT;
+			userPtr += 2;
 			data = le2be16(data) ^ 0x8000;
 			*p++ = data;
 			*p++ = data;
@@ -361,8 +368,9 @@
 		used = count;
 		while (count > 0) {
 			u_long data;
-			if (get_user(data, ((u_int *)userPtr)++))
+			if (get_user(data, (u_int __user *)userPtr))
 				return -EFAULT;
+			userPtr += 4;
 			data = le2be16dbl(data) ^ 0x80008000;
 			*p++ = data;
 			count--;
@@ -373,7 +381,7 @@
 }
 
 
-static ssize_t ata_ctx_law(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ctx_law(const u_char __user *userPtr, size_t userCount,
 			   u_char frame[], ssize_t *frameUsed,
 			   ssize_t frameLeft)
 {
@@ -435,7 +443,7 @@
 }
 
 
-static ssize_t ata_ctx_s8(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ctx_s8(const u_char __user *userPtr, size_t userCount,
 			  u_char frame[], ssize_t *frameUsed,
 			  ssize_t frameLeft)
 {
@@ -470,8 +478,9 @@
 			if (bal < 0) {
 				if (userCount < 2)
 					break;
-				if (get_user(data, ((u_short *)userPtr)++))
+				if (get_user(data, (u_short __user *)userPtr))
 					return -EFAULT;
+				userPtr += 2;
 				userCount -= 2;
 				bal += hSpeed;
 			}
@@ -488,7 +497,7 @@
 }
 
 
-static ssize_t ata_ctx_u8(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ctx_u8(const u_char __user *userPtr, size_t userCount,
 			  u_char frame[], ssize_t *frameUsed,
 			  ssize_t frameLeft)
 {
@@ -524,8 +533,9 @@
 			if (bal < 0) {
 				if (userCount < 2)
 					break;
-				if (get_user(data, ((u_short *)userPtr)++))
+				if (get_user(data, (u_short __user *)userPtr))
 					return -EFAULT;
+				userPtr += 2;
 				data ^= 0x8080;
 				userCount -= 2;
 				bal += hSpeed;
@@ -543,7 +553,7 @@
 }
 
 
-static ssize_t ata_ctx_s16be(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ctx_s16be(const u_char __user *userPtr, size_t userCount,
 			     u_char frame[], ssize_t *frameUsed,
 			     ssize_t frameLeft)
 {
@@ -561,8 +571,9 @@
 			if (bal < 0) {
 				if (userCount < 2)
 					break;
-				if (get_user(data, ((u_short *)userPtr)++))
+				if (get_user(data, (u_short __user *)userPtr))
 					return -EFAULT;
+				userPtr += 2;
 				userCount -= 2;
 				bal += hSpeed;
 			}
@@ -579,8 +590,9 @@
 			if (bal < 0) {
 				if (userCount < 4)
 					break;
-				if (get_user(data, ((u_int *)userPtr)++))
+				if (get_user(data, (u_int __user *)userPtr))
 					return -EFAULT;
+				userPtr += 4;
 				userCount -= 4;
 				bal += hSpeed;
 			}
@@ -597,7 +609,7 @@
 }
 
 
-static ssize_t ata_ctx_u16be(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ctx_u16be(const u_char __user *userPtr, size_t userCount,
 			     u_char frame[], ssize_t *frameUsed,
 			     ssize_t frameLeft)
 {
@@ -615,8 +627,9 @@
 			if (bal < 0) {
 				if (userCount < 2)
 					break;
-				if (get_user(data, ((u_short *)userPtr)++))
+				if (get_user(data, (u_short __user *)userPtr))
 					return -EFAULT;
+				userPtr += 2;
 				data ^= 0x8000;
 				userCount -= 2;
 				bal += hSpeed;
@@ -634,8 +647,9 @@
 			if (bal < 0) {
 				if (userCount < 4)
 					break;
-				if (get_user(data, ((u_int *)userPtr)++))
+				if (get_user(data, (u_int __user *)userPtr))
 					return -EFAULT;
+				userPtr += 4;
 				data ^= 0x80008000;
 				userCount -= 4;
 				bal += hSpeed;
@@ -653,7 +667,7 @@
 }
 
 
-static ssize_t ata_ctx_s16le(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ctx_s16le(const u_char __user *userPtr, size_t userCount,
 			     u_char frame[], ssize_t *frameUsed,
 			     ssize_t frameLeft)
 {
@@ -671,8 +685,9 @@
 			if (bal < 0) {
 				if (userCount < 2)
 					break;
-				if (get_user(data, ((u_short *)userPtr)++))
+				if (get_user(data, (u_short __user *)userPtr))
 					return -EFAULT;
+				userPtr += 2;
 				data = le2be16(data);
 				userCount -= 2;
 				bal += hSpeed;
@@ -690,8 +705,9 @@
 			if (bal < 0) {
 				if (userCount < 4)
 					break;
-				if (get_user(data, ((u_int *)userPtr)++))
+				if (get_user(data, (u_int __user *)userPtr))
 					return -EFAULT;
+				userPtr += 4;
 				data = le2be16dbl(data);
 				userCount -= 4;
 				bal += hSpeed;
@@ -709,7 +725,7 @@
 }
 
 
-static ssize_t ata_ctx_u16le(const u_char *userPtr, size_t userCount,
+static ssize_t ata_ctx_u16le(const u_char __user *userPtr, size_t userCount,
 			     u_char frame[], ssize_t *frameUsed,
 			     ssize_t frameLeft)
 {
@@ -727,8 +743,9 @@
 			if (bal < 0) {
 				if (userCount < 2)
 					break;
-				if (get_user(data, ((u_short *)userPtr)++))
+				if (get_user(data, (u_short __user *)userPtr))
 					return -EFAULT;
+				userPtr += 2;
 				data = le2be16(data) ^ 0x8000;
 				userCount -= 2;
 				bal += hSpeed;
@@ -746,8 +763,9 @@
 			if (bal < 0) {
 				if (userCount < 4)
 					break;
-				if (get_user(data, ((u_int *)userPtr)++))
+				if (get_user(data, (u_int __user *)userPtr))
 					return -EFAULT;
+				userPtr += 4;
 				data = le2be16dbl(data) ^ 0x80008000;
 				userCount -= 4;
 				bal += hSpeed;
diff --git a/sound/oss/dmasound/dmasound_paula.c b/sound/oss/dmasound/dmasound_paula.c
index d59f60b..494070a 100644
--- a/sound/oss/dmasound/dmasound_paula.c
+++ b/sound/oss/dmasound/dmasound_paula.c
@@ -34,6 +34,7 @@
 #define DMASOUND_PAULA_REVISION 0
 #define DMASOUND_PAULA_EDITION 4
 
+#define custom amiga_custom
    /*
     *	The minimum period for audio depends on htotal (for OCS/ECS/AGA)
     *	(Imported from arch/m68k/amiga/amisound.c)
@@ -156,7 +157,7 @@
      *  Native format
      */
 
-static ssize_t ami_ct_s8(const u_char *userPtr, size_t userCount,
+static ssize_t ami_ct_s8(const u_char __user *userPtr, size_t userCount,
 			 u_char frame[], ssize_t *frameUsed, ssize_t frameLeft)
 {
 	ssize_t count, used;
@@ -189,7 +190,7 @@
      */
 
 #define GENERATE_AMI_CT8(funcname, convsample)				\
-static ssize_t funcname(const u_char *userPtr, size_t userCount,	\
+static ssize_t funcname(const u_char __user *userPtr, size_t userCount,	\
 			u_char frame[], ssize_t *frameUsed,		\
 			ssize_t frameLeft)				\
 {									\
@@ -240,10 +241,11 @@
      */
 
 #define GENERATE_AMI_CT_16(funcname, convsample)			\
-static ssize_t funcname(const u_char *userPtr, size_t userCount,	\
+static ssize_t funcname(const u_char __user *userPtr, size_t userCount,	\
 			u_char frame[], ssize_t *frameUsed,		\
 			ssize_t frameLeft)				\
 {									\
+	const u_short __user *ptr = (const u_short __user *)userPtr;	\
 	ssize_t count, used;						\
 	u_short data;							\
 									\
@@ -253,7 +255,7 @@
 		count = min_t(size_t, userCount, frameLeft)>>1 & ~1;	\
 		used = count*2;						\
 		while (count > 0) {					\
-			if (get_user(data, ((u_short *)userPtr)++))	\
+			if (get_user(data, ptr++))			\
 				return -EFAULT;				\
 			data = convsample(data);			\
 			*high++ = data>>8;				\
@@ -268,12 +270,12 @@
 		count = min_t(size_t, userCount, frameLeft)>>2 & ~1;	\
 		used = count*4;						\
 		while (count > 0) {					\
-			if (get_user(data, ((u_short *)userPtr)++))	\
+			if (get_user(data, ptr++))			\
 				return -EFAULT;				\
 			data = convsample(data);			\
 			*lefth++ = data>>8;				\
 			*leftl++ = (data>>2) & 0x3f;			\
-			if (get_user(data, ((u_short *)userPtr)++))	\
+			if (get_user(data, ptr++))			\
 				return -EFAULT;				\
 			data = convsample(data);			\
 			*righth++ = data>>8;				\
diff --git a/sound/oss/dmasound/dmasound_q40.c b/sound/oss/dmasound/dmasound_q40.c
index 1ddaa62..e2081f3 100644
--- a/sound/oss/dmasound/dmasound_q40.c
+++ b/sound/oss/dmasound/dmasound_q40.c
@@ -58,7 +58,7 @@
 
 
 /* userCount, frameUsed, frameLeft == byte counts */
-static ssize_t q40_ct_law(const u_char *userPtr, size_t userCount,
+static ssize_t q40_ct_law(const u_char __user *userPtr, size_t userCount,
 			   u_char frame[], ssize_t *frameUsed,
 			   ssize_t frameLeft)
 {
@@ -79,7 +79,7 @@
 }
 
 
-static ssize_t q40_ct_s8(const u_char *userPtr, size_t userCount,
+static ssize_t q40_ct_s8(const u_char __user *userPtr, size_t userCount,
 			  u_char frame[], ssize_t *frameUsed,
 			  ssize_t frameLeft)
 {
@@ -98,7 +98,7 @@
 	return used;
 }
 
-static ssize_t q40_ct_u8(const u_char *userPtr, size_t userCount,
+static ssize_t q40_ct_u8(const u_char __user *userPtr, size_t userCount,
 			  u_char frame[], ssize_t *frameUsed,
 			  ssize_t frameLeft)
 {
@@ -114,7 +114,7 @@
 
 
 /* a bit too complicated to optimise right now ..*/
-static ssize_t q40_ctx_law(const u_char *userPtr, size_t userCount,
+static ssize_t q40_ctx_law(const u_char __user *userPtr, size_t userCount,
 			    u_char frame[], ssize_t *frameUsed,
 			    ssize_t frameLeft)
 {
@@ -152,7 +152,7 @@
 }
 
 
-static ssize_t q40_ctx_s8(const u_char *userPtr, size_t userCount,
+static ssize_t q40_ctx_s8(const u_char __user *userPtr, size_t userCount,
 			   u_char frame[], ssize_t *frameUsed,
 			   ssize_t frameLeft)
 {
@@ -189,7 +189,7 @@
 }
 
 
-static ssize_t q40_ctx_u8(const u_char *userPtr, size_t userCount,
+static ssize_t q40_ctx_u8(const u_char __user *userPtr, size_t userCount,
 			   u_char frame[], ssize_t *frameUsed,
 			   ssize_t frameLeft)
 {
@@ -224,7 +224,7 @@
 }
 
 /* compressing versions */
-static ssize_t q40_ctc_law(const u_char *userPtr, size_t userCount,
+static ssize_t q40_ctc_law(const u_char __user *userPtr, size_t userCount,
 			    u_char frame[], ssize_t *frameUsed,
 			    ssize_t frameLeft)
 {
@@ -265,7 +265,7 @@
 }
 
 
-static ssize_t q40_ctc_s8(const u_char *userPtr, size_t userCount,
+static ssize_t q40_ctc_s8(const u_char __user *userPtr, size_t userCount,
 			   u_char frame[], ssize_t *frameUsed,
 			   ssize_t frameLeft)
 {
@@ -304,7 +304,7 @@
 }
 
 
-static ssize_t q40_ctc_u8(const u_char *userPtr, size_t userCount,
+static ssize_t q40_ctc_u8(const u_char __user *userPtr, size_t userCount,
 			   u_char frame[], ssize_t *frameUsed,
 			   ssize_t frameLeft)
 {
diff --git a/sound/oss/dmasound/trans_16.c b/sound/oss/dmasound/trans_16.c
index 23562e9..ca973ac 100644
--- a/sound/oss/dmasound/trans_16.c
+++ b/sound/oss/dmasound/trans_16.c
@@ -17,6 +17,7 @@
 #include <asm/uaccess.h>
 #include "dmasound.h"
 
+extern int expand_bal;	/* Balance factor for expanding (not volume!) */
 static short dmasound_alaw2dma16[] ;
 static short dmasound_ulaw2dma16[] ;
 
diff --git a/sound/oss/harmony.c b/sound/oss/harmony.c
index bee9d34..591683c 100644
--- a/sound/oss/harmony.c
+++ b/sound/oss/harmony.c
@@ -1236,7 +1236,7 @@
 	}
 
 	/* Set the HPA of harmony */
-	harmony.hpa = (struct harmony_hpa *)dev->hpa;
+	harmony.hpa = (struct harmony_hpa *)dev->hpa.start;
 	harmony.dev = dev;
 
 	/* Grab the ID and revision from the device */
@@ -1250,7 +1250,7 @@
 
 	printk(KERN_INFO "Lasi Harmony Audio driver " HARMONY_VERSION ", "
 			"h/w id %i, rev. %i at 0x%lx, IRQ %i\n",
-			id, rev, dev->hpa, harmony.dev->irq);
+			id, rev, dev->hpa.start, harmony.dev->irq);
 	
 	/* Make sure the control bit isn't set, although I don't think it 
 	   ever is. */
diff --git a/sound/oss/i810_audio.c b/sound/oss/i810_audio.c
index 4600cd6..abc242a 100644
--- a/sound/oss/i810_audio.c
+++ b/sound/oss/i810_audio.c
@@ -312,7 +312,8 @@
 	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, INTELICH4},
 	{PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_18,
 	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, INTELICH4},
-
+	{PCI_VENDOR_ID_NVIDIA,  PCI_DEVICE_ID_NVIDIA_CK804_AUDIO,
+	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, NVIDIA_NFORCE},
 	{0,}
 };
 
@@ -3427,7 +3428,6 @@
 		release_mem_region(card->ac97base_mmio_phys, 512);
 		release_mem_region(card->iobase_mmio_phys, 256);
 	}
-out_pio:	
 	release_region(card->ac97base, 256);
 out_region2:
 	release_region(card->iobase, 64);
diff --git a/sound/pci/cs5535audio/cs5535audio.c b/sound/pci/cs5535audio/cs5535audio.c
index 202c7cf..f36ede8 100644
--- a/sound/pci/cs5535audio/cs5535audio.c
+++ b/sound/pci/cs5535audio/cs5535audio.c
@@ -385,7 +385,7 @@
 
 static int __init alsa_card_cs5535audio_init(void)
 {
-	return pci_module_init(&driver);
+	return pci_register_driver(&driver);
 }
 
 static void __exit alsa_card_cs5535audio_exit(void)
diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c
index 1a90339..5098372 100644
--- a/sound/pci/emu10k1/emufx.c
+++ b/sound/pci/emu10k1/emufx.c
@@ -27,6 +27,7 @@
 
 #include <sound/driver.h>
 #include <linux/pci.h>
+#include <linux/capability.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>