#!/bin/sh
UNSUPPORTED=1
LEGACY=0
#CARDS="$(lspci -n|gawk '{sub("Class","")} $2 == "0300:" {print$3}')"
CARDS="$(lspci -n|perl -e 'while(<>){(push(@cards,$_)) if (s/^.+?\s*0300\:\s+(.+?)\s+.*$/$1/)} print join(" ",@cards);')"
for card in $CARDS; do
 VENDOR=${card%:*}
 DEVICE=${card#*:}
 case $VENDOR in
  1002)
   case $DEVICE in
    #strings /usr/lib/xorg/modules/drivers/fglrx_drv.so|awk '/^0x....$/{print tolower($1)}'|sed s/0x//|sort -u|tr '\n' '|'|sed 's/|$//'
    3150|3151|3152|3154|3e50|3e54|4144|4146|4147|4148|4149|4150|4151|4152|4153|4154|4155|4a48|4a49|4a4a|4a4b|4a4c|4a4d|4a4e|4a4f|4a50|4a54|4b48|4b49|4b4a|4b4b|4b4c|4e44|4e45|4e46|4e47|4e48|4e49|4e4a|4e4b|4e50|4e51|4e52|4e54|4e56|5460|5461|5462|5464|5548|5549|554a|554b|554c|554d|554e|554f|5550|5551|5554|5555|564a|564b|564f|5652|5653|5657|5854|5874|5954|5955|5974|5975|5a41|5a42|5a43|5a61|5a62|5a63|5b60|5b62|5b63|5b64|5b65|5b66|5d48|5d49|5d4a|5d4c|5d4d|5d4f|5d50|5d51|5d52|5d57|5e48|5e4a|5e4b|5e4c|5e4d|5e4f|7100|7101|7102|7103|7104|7105|7106|7108|7109|710a|710b|710c|710e|710f|7140|7141|7142|7143|7144|7145|7146|7147|7149|714a|714b|714c|714d|714e|714f|7151|7152|7153|715e|715f|7180|7181|7183|7186|7187|7188|718a|718b|718c|718d|718f|7193|7196|719b|719f|71c0|71c1|71c2|71c3|71c4|71c5|71c6|71c7|71cd|71ce|71d2|71d4|71d5|71d6|71da|71de|7200|7210|7211|7240|7243|7244|7245|7246|7247|7248|7249|724a|724b|724c|724d|724e|724f|7280|7281|7283|7284|7287|7288|7289|728b|728c|7290|7291|7293|7297|791e|791f|793f|7941|7942|796c|796d|796e|796f|9400|9401|9402|9403|9405|940a|940b|940f|9440|9441|9442|9443|9444|9446|9447|944a|944b|944c|944e|944f|9450|9452|9456|945a|945b|946a|946b|947a|947b|9480|9487|9488|9489|948f|9490|9498|949c|949e|949f|94c0|94c1|94c3|94c4|94c5|94c6|94c7|94c8|94c9|94cb|94cc|9500|9501|9504|9505|9506|9507|9508|9509|950f|9511|9513|9515|9517|9519|9540|9541|9542|954e|954f|9552|9553|9555|9580|9581|9583|9586|9587|9588|9589|958a|958b|958c|958d|958e|958f|9590|9591|9593|9595|9596|9597|9598|9599|959b|95c0|95c2|95c4|95c5|95c6|95c7|95c9|95cc|95cd|95ce|95cf|9610|9611|9612|9613|9614|9615|9616|9710|9711|9712|9713|9714) UNSUPPORTED=0 ;;
    4242|4966|4967|4c64|4c66|4c67|5148|514c|514d|5960|5961|5962|5964|5965|5c61|5c63) UNSUPPORTED=0;LEGACY=1 ;;
    5834|5835|728c|7834|7835) UNSUPPORTED=0;LEGACY=2 ;;
    3151|3154|3e54|4147|4154|4a4d|4e47|4e4b|4e54|5464|5550|5551|5554|5555|564a|564b|5b64|5b65|5d49|5d50|5d51|5e48|7103|7104|7105|7106|710e|710f|7144|7152|7153|719b|71c4|71d2|71d4|71da|728c) UNSUPPORTED=0;LEGACY=3 ;;
    *) UNSUPPORTED=1 ;;
   esac
   ;;
 esac
done
if [ ! -f /etc/kanotix-version ]; then
 echo Error: No KANOTIX found. Do not ask for support! >&2
fi
if [ ! -f /etc/debian_version ]; then
 echo Error: No Debian compatible system found. Do not ask for support! >&2
 exit 100
fi
if [ "$UNSUPPORTED" = "1" ]; then
 echo Error: No ATI RADEON/FIREGL adapter found. >&2
 exit 3
fi
if [ "$(id -u)" != 0 ]; then
 echo Error: You must be root to run this script! >&2
 exit 6
fi
LAPTOP=""
[ "$(find /proc/acpi/battery/ -mindepth 1 -type d 2>/dev/null)" ] && LAPTOP="yes"
[ -d /KNOPPIX -o -d /KANOTIX ] && INSTALLED="no" || INSTALLED="yes"
if [ -f /etc/default/distro ]; then
 . /etc/default/distro
 [ "$FLL_DISTRO_MODE" = "live" ] && INSTALLED="no"
fi
if [ "$INSTALLED" = "yes" ]; then
 if [ -n "$DISPLAY" ]; then
  echo Error: Can\`t be run within X! Use a text console \(ALT-CTRL-F1\) >&2
  exit 7
 fi
else
 if grep -q -e unionfs -e aufs /proc/mounts; then
  echo Unionfs found. >&2
 else
  echo Activating Unionfs now. >&2
  UNIONFS=unionfs
  modinfo aufs >/dev/null 2>&1 && UNIONFS=aufs
  AUFSOPT=""
  [ "$UNIONFS" = "aufs" ] && AUFSOPT="udba=reval,"
  mkdir -p /tmp/union
  UNION=/KNOPPIX
  [ -d /KANOTIX ] && UNION=/KANOTIX
  [ -d "$FLL_MOUNTPOINT" ] && UNION="$FLL_MOUNTPOINT"
  mount -t $UNIONFS -o ${AUFSOPT}dirs=/tmp/union/:$UNION none $UNION/ >/dev/null 2>&1
 fi
fi
X_CONF=XF86Config-4
if which Xorg >/dev/null; then
 [ -e /etc/X11/xorg.conf ] && X_CONF=xorg.conf
fi

unset UP

# create minimalistic xorg.conf when without Driver entry

if ! grep -v ^# /etc/X11/$X_CONF|grep Driver|grep -q -e ati -e fglrx -e radeon -e fbdev -e vesa; then
 echo Warning: /etc/X11/$X_CONF needs some modifications. Trying now. >&2
 if ! [ -x /usr/bin/patch ]; then
  apt-get update && UP=1
  apt-get install --allow-unauthenticated --yes patch
 fi
 if ! [ -x /usr/bin/patch ]; then
  echo Error: No patch tool installed - please install it and try again! >&2
  exit 7
 fi
 rm -f /etc/X11/$X_CONF.pure /etc/X11/$X_CONF.rej
 cp /etc/X11/$X_CONF /etc/X11/$X_CONF.pure
 if ! grep -q "Device.*Configured Video Device" /etc/X11/$X_CONF; then
  echo 'Warning: Adding "Configured Video Device" to "Screen" Section.' >&2
  perl -pi -e 's/(^\tMonitor\t\t"Configured Monitor"\n)/\1\tDevice\t\t"Configured Video Device"\n/' /etc/X11/$X_CONF
 fi
 patch --no-backup-if-mismatch /etc/X11/$X_CONF <<'EOT'
Index: xorg.conf
@@ -31,6 +31,7 @@
 
 Section "Device"
 	Identifier	"Configured Video Device"
+	Driver		"vesa"
 EndSection
 
 Section "Monitor"
@@ -41,6 +42,11 @@
 	Identifier	"Default Screen"
 	Monitor		"Configured Monitor"
 	Device		"Configured Video Device"
+	DefaultDepth	24
+	SubSection	"Display"
+		Depth	24
+		Modes
+	EndSubSection
 EndSection
 
 Section "ServerLayout"
EOT
 if [ $? -ne 0 ]; then
  echo Error: Unable to patch. Please manually fix file! >&2
  rm -f /etc/X11/$X_CONF
  mv /etc/X11/$X_CONF.pure /etc/X11/$X_CONF
  exit 8
 else
  echo Warning: Patch applied successfully. >&2
 fi
fi

cd /usr/src
KVER=$(uname -r)
KV=$(uname -r|cut -d. -f1-2)

RMML=0
SHELL=0
UPDATE=0
VER_FORCE=""
PRINT_VER=0
NO_X_KILL=0
PATCH=0
COMPOSITE=1
AUTO_RES=0
AUTO_SYNC=0
FIREGL=0

while getopts pabcfrsuv:yzh opt; do
 case $opt in
  p) PRINT_VER=1
     ;;
  a) AUTO_RES=1
     ;;
  b) AUTO_SYNC=1
     ;;
  c) COMPOSITE=0
     ;;
  f) FIREGL=1
     ;;
  r) RMML=1
     ;;
  s) SHELL=1
     ;;
  u) UPDATE=1
     ;;
  v) VER_FORCE="$OPTARG"
     ;;
  y) PATCH=1
     ;;
  z) NO_X_KILL=1
     ;;
  \?|h) echo "Usage $0 [options] " >&2
        echo "optional options are:" >&2
        echo " -a      Use Auto-Selection for screen res" >&2
        echo " -b      Use Auto-Selection for H/V sync" >&2
        echo " -c      Disable Composite extension" >&2
        echo " -r      Remove ModeLines" >&2
        echo " -v VER  Force use of specific driver version. Example: -v 8.29.6" >&2
        echo " -p      Print driver version to be installed and quit" >&2
	echo " -s      Run shell before ati-installer.sh (debug)" >&2
	echo " -u      Update package scripts (debug)" >&2
        echo " -y      Force patching. Special purpose only!" >&2
        echo " -z      No X kill/restart. Special purpose only!" >&2
        echo " -h      Show this help" >&2
        exit 6
        ;;
 esac
done

# check for pipe usage
[ "$0" = "sh" -o "$0" = "bash" ] && NO_X_KILL=1

# most DX8 cards
VER_LEGACY_1=8.28.8

# rest of DX8 cards
VER_LEGACY_2=8.29.6

# FireGL cards
VER_LEGACY_3=9.2

VER=9.2
#VER=9-1
#VER=8-12
#VER=8-11
#VER=8-10
#VER=8-9
#VER=8-8
#VER=8-7
#VER=8-6
#VER=8-5
#VER=8-4
#VER=8-3
#VER=8-02
#VER=8-01
#VER=8.443.1
#VER=7-11
#VER=8.42.3
#VER=8.41.7
#VER=8.40.4
# Google Earth does not run with 8.40.4
#VER=8.39.4
# first release 8.39.4 showed "AMD Testing use only" in down right corner ;)
#VER=8.38.7
#VER=8.38.6
#VER=8.37.6
#VER=8.36.5
# No modeline support for Xorg 7.2 - disabled
#VER=8.35.5
#VER=8.34.8
#VER=8.33.6
# 8.33.6 used 85 hz on 75 hz max setting with modelines
# 8.33.6 and newer required for Xorg 7.2
#VER=8.32.5
# 8.32.5 supports Xorg 7.2 RC2
#VER=8.31.5
#VER=8.30.3
# 8.30.3 does not work with 71c1|71d4|71d5
#VER=8.29.6
#VER=8.28.8
#VER=8.27.10
# 8.27.10 and newer required for Xorg 7.1
#VER=8.26.18
#VER=8.25.18
#VER=8.24.8
#VER=8.23.7
#VER=8.22.5

[ "$LEGACY" = "1" ] && VER=$VER_LEGACY_1
[ "$LEGACY" = "2" ] && VER=$VER_LEGACY_2
[ "$LEGACY" = "3" ] && VER=$VER_LEGACY_3

if [ -n "$VER_FORCE" ]; then
 if [ "${#VER_FORCE}" = "1" ]; then
  [ "$VER_FORCE" = "1" ] && VER=$VER_LEGACY_1
  [ "$VER_FORCE" = "2" ] && VER=$VER_LEGACY_2
  [ "$VER_FORCE" = "3" ] && VER=$VER_LEGACY_3
 else
  VER=$VER_FORCE
 fi
fi

X -version 2>&1|grep -q -e "X Window System Version 7.1" && case $VER in 8.22.5|8.23.7|8.24.8|8.25.18|8.26.18)
 echo Error: No Xorg 7.1 support in $VER >&2
 exit 8
 ;;
esac
X -version 2>&1|grep -q -e "X Window System Version 7.2" -e "X Window System Version 1.3" -e "X Server 1.4" && case $VER in 8.22.5|8.23.7|8.24.8|8.25.18|8.26.18|8.27.10|8.28.8|8.29.6|8.30.3|8.31.5|8.32.5)
 echo Error: No Xorg 7.2 support in $VER >&2
 case $VER in
  8.28.8|8.29.6|8.32.5)
   if [ "$PATCH" = "1" ]; then
    echo Warning: Only incomplete patch possible \(2d only\) >&2
   else
    echo Error: Only incomplete patch possible \(2d only\), use -y option to try >&2
    exit 9
   fi
   ;;
  *)
   exit 10
   ;;
 esac
esac
if X -version 2>&1|grep -q -e "X Window System Version 1.3" -e "X Server 1.4"; then
 case $VER in
  8.33.6|8.34.8|8.35.5|8.36.5)
   echo Error: No Xorg 1.3 support in $VER >&2
   PATCH=1
   ;;
  8.37.6|8.38.6|8.38.7|8.39.4|8.40.4|8.41.7|8.42.3|7-11|8.443.1|8-01|8-02|8.3|8-3|8-4|8-5|8-6|8-7|8-8|8-9|8-10|8-11|8-12|9-*|8.5*|8.6*|8.7*|8.8*|8.9*|9.*) # supports Xorg 1.3
   ;;
  *)
   if [ "$PATCH" = "0" ]; then
    echo Error: Unknown status of Xorg 1.3 support for this release, use -y to force. >&2
    exit 11
   fi
   ;;
 esac
fi

[ "$PATCH" = "1" ] && echo Warning: Patching driver to support any Xorg release >&2
#if [ "$VER" = "8.39.4" ]; then
# PATCH=1
# echo Warning: Brutally patching driver to disable logo >&2
#fi

case $VER in 
 8.38.7|8.38.6|8.37.6|8.36.5|8.35.5|8.34.8|8.33.6|8.32.5|8.31.5|8.30.3|8.29.6|8.28.8|8.27.10|8.26.18|8.25.18|8.24.8|8.23.7|8.22.5)
  if [ $(set -f ; IFS=.- ; set -- $KVER ; printf %d%.2d%.4d "$1" "$2" "$3") -ge 2060024 ]; then
   echo Error: No patches available to get selected driver release work with current kernel! >&2
   exit 12
  fi
  ;;
esac

if [ "$PRINT_VER" = "1" ]; then
 echo $VER
 exit
fi

CPU=$(uname -m)
if [ "$CPU" = "x86_64" ]; then
 ARCH="amd64"
else
 ARCH="i386"
fi

CPU="x86.x86_64" # since 8.31.5
if [ "$VER" = "8.22.5" -o "$VER" = "8.23.7" ]; then 
 if [ "$ARCH" = "i386" ]; then
  CPU="i386"
 else
  CPU="x86_64"
 fi
fi
case $VER in 
 8.24.8|8.25.18|8.26.18|8.27.10|8.28.8|8.29.6|8.30.3) CPU="x86" ;;
esac

unset X86
[ "$ARCH" = "amd64" ] && X86=64
unset BIT
[ "$ARCH" = "amd64" ] && BIT="64bit/"
[ "$VER" = "8-11" ] && BIT="64bit/"

case $VER in
 8.22.5|8.23.7|8.24.8|8.25.18|8.26.18|8.27.10) DRIVER=ati-driver-installer-$VER-$CPU.run ;;
 8.24.8|8.25.18|8.26.18|8.27.10|8.28.8|8.29.6|8.30.3) DRIVER=ati-driver-installer-$VER.run ;;
 *) DRIVER=ati-driver-installer-$VER-$CPU.run ;;
esac

if ! [ -e $DRIVER ]; then
 wget --referer=ati.com -Nc http://www2.ati.com/drivers/linux/${BIT}${DRIVER}
fi

GL=/usr/X11R6/lib/libGL.so.1.2

[ -x /usr/share/ati/fglrx-uninstall.sh ] && /usr/share/ati/fglrx-uninstall.sh
dpkg --purge fglrx${X86}-4-3-0 >/dev/null 2>&1
dpkg --purge fglrx${X86}-6-8-0 >/dev/null 2>&1
dpkg --purge fglrx-glc22 >/dev/null 2>&1
dpkg --purge fglrx >/dev/null 2>&1
for package in $(dpkg-divert --list|grep "diversion of $GL"|cut -f7 -d' '|grep -v -e fglrx-driver -e xorg-driver-fglrx); do 
 dpkg-divert --package $package --remove $GL
done
[ -f /var/lib/dpkg/info/xorg-driver-fglrx.postrm ] && sed -i 'sX> /dev/nullX||trueX' /var/lib/dpkg/info/xorg-driver-fglrx.postrm

if [ -e $GL.1st ]; then
 rm -f $GL
 mv $GL.1st $GL
fi

unset UP

# Ubuntu universe workaround
[ -r /etc/lsb-release ] && . /etc/lsb-release
if [ "$DISTRIB_ID" = "Ubuntu" ]; then
 if ! grep -Eq "^[[:space:]]*deb[[:space:]]+.*universe$" /etc/apt/sources.list; then
  grep -Eq "deb[[:space:]]+.*universe$" /etc/apt/sources.list && sed -i 's/^#\s*\(deb\s.*universe\)$/\1/' /etc/apt/sources.list
 fi
fi
# Ubuntu intrepid multiverse workaround
#if [ "$DISTRIB_ID" = "Ubuntu" -a "$DISTRIB_CODENAME" = "intrepid" ]; then
# if ! grep -Eq "^[[:space:]]*deb[[:space:]]+.*multiverse$" /etc/apt/sources.list; then
#  grep -Eq "deb[[:space:]]+.*multiverse$" /etc/apt/sources.list && sed -i 's/^#\s*\(deb\s.*multiverse\)$/\1/' /etc/apt/sources.list
#  unset UP
# fi
#fi

if ! [ -x /usr/bin/module-assistant ]; then
 apt-get update && UP=1
 apt-get install --allow-unauthenticated --yes module-assistant
fi

if ! [ -d /usr/share/build-essential ]; then
 [ -z "$UP" ] && apt-get update && UP=1
 apt-get install --allow-unauthenticated --yes build-essential
fi

if ! [ -x /usr/bin/fakeroot ]; then
 [ -z "$UP" ] && apt-get update && UP=1
 apt-get install --allow-unauthenticated --yes fakeroot
fi

if ! [ -x /usr/bin/dh_testdir ]; then
 [ -z "$UP" ] && apt-get update && UP=1
 apt-get install --allow-unauthenticated --yes debhelper
fi

if ! [ -x /bin/bzip2 ]; then
 [ -z "$UP" ] && apt-get update && UP=1
 apt-get install --allow-unauthenticated --yes bzip2
fi

if ! [ -f /usr/lib/libstdc++.so.5 ]; then
 [ -z "$UP" ] && apt-get update && UP=1
 apt-get install --allow-unauthenticated --yes libstdc++5
fi

if [ "$(uname -m)" = "x86_64" -a ! -d /usr/share/doc/ia32-libs ]; then
 [ -z "$UP" ] && apt-get update && UP=1
 apt-get install --allow-unauthenticated --yes ia32-libs
fi

if [ "$(uname -m)" = "x86_64" ] && ! [ -f /emul/ia32-linux/usr/lib/libXcursor.so.1 -o -f /usr/lib32/libXcursor.so.1 ]; then
 [ -z "$UP" ] && apt-get update && UP=1
 apt-get install --allow-unauthenticated --yes ia32-libs-gtk
fi

if ! [ -x /usr/bin/module-assistant ]; then
 echo "Error: module-assistant missing." >&2
 [ -r /etc/lsb-release ] && . /etc/lsb-release
 [ "$DISTRIB_ID" = "Ubuntu" ] && echo "Hint: Enable universe repository in /etc/apt/sources.list." >&2
 exit 1
fi

if ! [ -x /usr/sbin/dkms ]; then
 [ -z "$UP" ] && apt-get update && UP=1
 FROZEN=0
 [ -f /etc/frozen-rc.d ] && FROZEN=1
 [ -x /usr/sbin/unfreeze-rc.d ] && /usr/sbin/unfreeze-rc.d
 apt-get install --allow-unauthenticated --yes dkms
 [ "$FROZEN" = "1" -a -x /usr/sbin/freeze-rc.d ] && /usr/sbin/freeze-rc.d
fi

if ! [ -x /usr/sbin/dkms ]; then
 m-a -i prepare
 FROZEN=0
 [ -f /etc/frozen-rc.d ] && FROZEN=1
 [ -x /usr/sbin/unfreeze-rc.d ] && /usr/sbin/unfreeze-rc.d
 #DKMS_DEB=dkms_2.0.20.4-0ubuntu1_all.deb
 #wget -N http://linux.dell.com/dkms/$DKMS_DEB
 DKMS_DEB=dkms_2.0.20.4-0ubuntu3_all.deb
 wget -N http://kanotix.com/files/thorhammer/backports-ubuntu/dkms/$DKMS_DEB
 dpkg -i $DKMS_DEB
 [ "$FROZEN" = "1" -a -x /usr/sbin/freeze-rc.d ] && /usr/sbin/freeze-rc.d
fi

DKMS=0

if [ -x /usr/sbin/dkms -a ! -f /usr/share/cdbs/1/rules/debhelper.mk ]; then
 apt-get update && UP=1
 apt-get install --allow-unauthenticated --yes cdbs
fi

[ -x /usr/sbin/dkms -a -f /usr/share/cdbs/1/rules/debhelper.mk ] && DKMS=1

if [ -f /etc/modutils/1alsa ]; then
 mv /lib/modules/extra/alsa /lib/modules/$(uname -r)/
 rm -f /etc/modutils/1alsa
 depmod -a
fi

rm -rf fglrx-install /tmp/fglrx*
rm -f fglrx* 2>/dev/null
rm -f /tmp/xorg-driver-fglrx* xorg-driver-fglrx*
rm -f /etc/fglrxrc /etc/fglrxprofiles.csv
rm -rf /etc/ati

# Ubuntu workaround
[ -f /etc/default/linux-restricted-modules-common ] && perl -pi -e 's/^(DISABLED_MODULES)=.*/\1="fglrx"/' /etc/default/linux-restricted-modules-common
[ -x /sbin/lrm-manager ] && /sbin/lrm-manager

DISTRIB_ID=Debian
DISTRIB_CODENAME=etch
X -version 2>&1|grep -q -e "X Window System Version 6.9" -e "X Window System Version 7.0" && DISTRIB_CODENAME=sid
if [ -d /usr/lib/xorg/modules ]; then
 DISTRIB_ID=Ubuntu
 DISTRIB_CODENAME=dapper
fi
X -version 2>&1|grep -q -e "X Window System Version 7.1" -e "X Window System Version 7.2" -e "X Window System Version 1.3" -e "X Server 1.4" && [ "$VER" != "8.27.10" ] && DISTRIB_CODENAME=edgy

# Debian (and Ubuntu)
[ -f /etc/debian_version -a ! -f /etc/kanotix-version ] && m-a -i prepare

# Kanotix fallback
[ -f /etc/kanotix-version -a "$(readlink -e /lib/modules/$(uname -r)/build)" = "" ] && m-a -i prepare

#LC_ALL= LC_CTYPE= LC_MESSAGES= LANG= sh $DRIVER --buildpkg $DISTRIB_ID/$DISTRIB_CODENAME || (
LC_ALL= LC_CTYPE= LC_MESSAGES= LANG= sh $DRIVER --extract fglrx-install || (
 rm -f $DRIVER
 echo $DRIVER could not build Debian packages and has been deleted. >&2
 echo Please restart the script to try again. >&2
 exit 2
) || exit

cd fglrx-install

if [ ! -d packages/Ubuntu/dists/edgy ]; then
 DISTRIB_ID=Debian
 DISTRIB_CODENAME=etch
fi

if [ "$DKMS" = "1" -a -d packages/Ubuntu/dists/intrepid ]; then
 DISTRIB_ID=Ubuntu
 DISTRIB_CODENAME=intrepid
 if [ -d x740 ]; then
  X_VER=$(X -version 2>&1 | grep -E '(X Window System Version|X.Org X Server) [0-9]\.' | sed -e 's/^.*X Window System Version //;s/^.*X.Org X Server //' | cut -d' ' -f1)
  case $X_VER in
   1.5*|1.6*) ;; 
   *) DISTRIB_CODENAME=hardy;;
  esac
 fi
elif [ "$DKMS" = "1" -a -d packages/Ubuntu/dists/hardy ]; then
 DISTRIB_ID=Ubuntu
 DISTRIB_CODENAME=hardy
else
 DKMS=0
fi

[ "$VER" = "8.22.5" -o "$VER" = "8.23.7" ] && perl -pi -e 's/(XVERSIONMAX := )(\$\(basename \$\(XVERSION\)\).99)/${1}1:${2}/' packages/Debian/debian/rules
[ "$KV" = "2.6" ] && [ "$VER" = "8.22.5" -o "$VER" = "8.23.7" -o "$VER" = "8.24.8" ] && if [ "$(uname -r|grep -E '2.6.16|2.6.17')" != "" ]; then
 patch common/lib/modules/fglrx/build_mod/firegl_public.c <<EOT
Index: firegl_public.c
@@ -361,13 +361,15 @@
 } firegl_drm_stub_info_t;
 static firegl_drm_stub_info_t firegl_stub_info;
 
-#if LINUX_VERSION_CODE < 0x020400
+#if LINUX_VERSION_CODE > 0x02060F
 struct firegl_drm_stub_info_t *firegl_stub_pointer = NULL;
 #define inter_module_put(x)
 #define inter_module_unregister(x)
 #define inter_module_get_request(x,y)   firegl_stub_pointer
 #define inter_module_register(x,y,z)    do { firegl_stub_pointer = z; } while (0)
+#endif
 /* This is a kludge for backward compatibility that is only useful in DRM(stub_open) */
+#if LINUX_VERSION_CODE < 0x020400
 #define fops_put(fops)      MOD_DEC_USE_COUNT
 #define fops_get(fops)      (fops); MOD_INC_USE_COUNT
 #endif // LINUX_VERSION_CODE < 0x020400
@@ -2353,7 +2353,7 @@
 
 int ATI_API_CALL __ke_no_iommu(void)
 {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,1)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,1) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
 #ifdef CONFIG_GART_IOMMU
     return no_iommu;
 #else /* !CONFIG_GART_IOMMU */
EOT
 patch common/lib/modules/fglrx/build_mod/2.6.x/Makefile <<EOT
Index: Makefile
@@ -1,4 +1,4 @@
-GCC_VER_MAJ      = \$(shell \$(CC) --version | head -n 1 | sed -e 's/[^0-9. ]//g;s/^ *//;s/^\(.\)\..*\$\$/\1/')
+GCC_VER_MAJ      = \$(shell \$(CC) -dumpversion | cut -f1 -d.)
 
 obj-m           += fglrx.o
 fglrx-libs      += libfglrx_ip.a.GCC\$(GCC_VER_MAJ)
@@ -24,36 +24,18 @@
 # on first call from remote location we get into this path
 # whilst on second call all is managed by the embedding kernel makefile
 
-KVER            = \$(shell uname -r)
-# KVER            = 2.6.0-0.test1.1.26custom
-
-ifeq (1,1)
-KDIR            = /lib/modules/\$(KVER)/build
-else
-KDIR            = /usr/src/linux-\$(KVER)
-endif
-PWD             = \$(shell pwd)
 
 fglrx-cfiles    = \${fglrx-c-objs:.o=.c}
 
 # default:: kmod_build
 
 kmod_build:: \$(fglrx-libs) \$(fglrx-cfiles) \$(fglrx-hdrs) \$(drm-hdrs)
-	\$(MAKE) -C \$(KDIR) SUBDIRS=\$(PWD) modules
-
-%.c:
-	@ln -s ../\$@
-
-%.h:
-	@ln -s ../\$@
-
-%.GCC\$(GCC_VER_MAJ):
-	@ln -s ../\$@
+	\$(MAKE) -C \$(KDIR) SUBDIRS=\$(CURDIR) modules
 
 # distclean:: clean
 
 clean::
-	rm -f *.c *.h *.o *.ko *.GCC* .??*
+	rm -f *.o *.ko .*.cmd
 
 endif
 
EOT
fi
[ "$KV" = "2.6" ] && [ "$VER" = "8.27.10" -o "$VER" = "8.28.8" ] && if [ "$(uname -r|grep -E '2.6.18|2.6.19|2.6.20|2.6.21|2.6.22')" != "" ]; then
 patch common/lib/modules/fglrx/build_mod/firegl_public.c <<EOT
Index: firegl_public.c
@@ -23,6 +23,9 @@

 // ============================================================
 #include <linux/version.h>
+#ifndef UTS_RELEASE
+#include <linux/utsrelease.h>
+#endif
 #ifdef MODVERSIONS
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,71)
 #include <linux/modversions.h>
@@ -208,6 +211,10 @@ _syscall3( int, modify_ldt, int, func, v
 #define preempt_enable()
 #endif

+#ifndef VM_SHM
+#define VM_SHM (0)
+#endif
+
 // ============================================================
 /* globals */

EOT
fi
case $VER in 8.22.5|8.23.7|8.24.8|8.25.18|8.26.18|8.27.10|8.28.8|8.29.6|8.30.3|8.31.5|8.32.5|8.33.6)
 [ "$KV" = "2.6" ] && if [ "$(uname -r|grep -E '2.6.20|2.6.21|2.6.22')" != "" -a ! -f  packages/Fedora/ati-drivers-2.6.20.patch -a ! -f packages/Fedora/firegl_public.c.patch ]; then
 # http://mlau.at/fglrx-833-2620-fixes.patch
 patch common/lib/modules/fglrx/build_mod/firegl_public.c <<'EOT'
Index: firegl_public.c
@@ -194,6 +194,82 @@
 int errno;
 #endif // __ia64__
 
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,19)
+#if defined(__i386__)
+
+#define __syscall_return(type, res) \
+do { \
+	if ((unsigned long)(res) >= (unsigned long)(-MAX_ERRNO)) { \
+		errno = -(res); \
+		res = -1; \
+	} \
+	return (type) (res); \
+} while (0)
+
+#define _syscall2(type,name,type1,arg1,type2,arg2) \
+type name(type1 arg1,type2 arg2) \
+{ \
+long __res; \
+__asm__ volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \
+	: "=a" (__res) \
+	: "0" (__NR_##name),"ri" ((long)(arg1)),"c" ((long)(arg2)) \
+	: "memory"); \
+__syscall_return(type,__res); \
+}
+
+#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
+type name(type1 arg1,type2 arg2,type3 arg3) \
+{ \
+long __res; \
+__asm__ volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \
+	: "=a" (__res) \
+	: "0" (__NR_##name),"ri" ((long)(arg1)),"c" ((long)(arg2)), \
+		  "d" ((long)(arg3)) : "memory"); \
+__syscall_return(type,__res); \
+}
+
+#elif defined(__x86_64__)
+#define __syscall_clobber "r11","rcx","memory"
+
+#define __syscall_return(type, res) \
+do { \
+	if ((unsigned long)(res) >= (unsigned long)(-MAX_ERRNO)) { \
+		errno = -(res); \
+		res = -1; \
+	} \
+	return (type) (res); \
+} while (0)
+
+#define __syscall "syscall"
+
+#define _syscall2(type,name,type1,arg1,type2,arg2) \
+type name(type1 arg1,type2 arg2) \
+{ \
+long __res; \
+__asm__ volatile (__syscall \
+	: "=a" (__res) \
+	: "0" (__NR_##name),"D" ((long)(arg1)),"S" ((long)(arg2)) : __syscall_clobber ); \
+__syscall_return(type,__res); \
+}
+
+#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
+type name(type1 arg1,type2 arg2,type3 arg3) \
+{ \
+long __res; \
+__asm__ volatile (__syscall \
+	: "=a" (__res) \
+	: "0" (__NR_##name),"D" ((long)(arg1)),"S" ((long)(arg2)), \
+		  "d" ((long)(arg3)) : __syscall_clobber); \
+__syscall_return(type,__res); \
+}
+
+#else
+
+#error "please fix the fglrx syscall mess"
+
+#endif	/* __i386__ */
+#endif	/* 2.6.19 */
+
 // int mlock(const void *addr, size_t len);
 _syscall2(int, mlock, const void *, addr, size_t, len )
 // int munlock(const void *addr, size_t len);
@@ -2561,11 +2637,23 @@ void ATI_API_CALL __ke_free_irq(unsigned
 #else
 static void ATI_API_CALL (*irq_handler_func)(int, void*, void*); /* function pointer variable */
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
 static irqreturn_t ke_irq_handler_wrap(int irq, void *arg1, struct pt_regs *regs)
 {
     irq_handler_func(irq, arg1, regs);
     return IRQ_HANDLED;
 }
+#else
+static irqreturn_t ke_irq_handler_wrap(int irq, void *arg1)
+{
+    irq_handler_func(irq, arg1, get_irq_regs());
+    return IRQ_HANDLED;
+}
+#endif
+
+#ifndef SA_SHIRQ
+#define SA_SHIRQ IRQF_SHARED
+#endif
 
 int ATI_API_CALL __ke_request_irq(unsigned int irq, 
     void (*ATI_API_CALL handler)(int, void *, void *),
EOT
 fi
esac
[ "$KV" = "2.6" ] && if [ "$(uname -r|grep -E '2.6.20|2.6.21|2.6.22')" != "" -a -f packages/Fedora/ati-drivers-2.6.20.patch ]; then
 patch -p0 < packages/Fedora/ati-drivers-2.6.20.patch
fi
[ "$KV" = "2.6" ] && if [ "$(uname -r|grep -E '2.6.20|2.6.21|2.6.22')" != "" -a -f packages/Fedora/firegl_public.c.patch ]; then
 patch common/lib/modules/fglrx/build_mod/firegl_public.c packages/Fedora/firegl_public.c.patch
fi
case $VER in 8.22.5|8.23.7|8.24.8|8.25.18|8.26.18|8.27.10|8.28.8|8.29.6|8.30.3|8.31.5|8.32.5|8.33.6|8.34.8|8.35.5|8.36.5|8.37.6|8.38.6|8.38.7)
 [ "$KV" = "2.6" ] && if [ "$(uname -r|grep -E '2.6.22')" != "" -a "$(uname -m)" = "x86_64" ]; then
 patch common/lib/modules/fglrx/build_mod/firegl_public.c <<'EOT'
--- common/lib/modules/fglrx/build_mod/firegl_public.c	2007-02-20 13:23:07.000000000 -0500
+++ common/lib/modules/fglrx/build_mod/firegl_public.c	2007-05-15 16:55:34.000000000 -0400
@@ -145,11 +145,11 @@
 #endif
 
 #ifdef __x86_64__
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
-#include "linux/ioctl32.h"
-#else
-#include "asm/ioctl32.h"
-#endif
+//#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
+//#include "linux/ioctl32.h"
+//#else
+//#include "asm/ioctl32.h"
+//#endif
 
 #ifdef __x86_64__
 #include "asm/compat.h"
EOT
 fi
esac
case $VER in 
 8.22.5|8.23.7|8.24.8|8.25.18|8.26.18|8.27.10|8.28.8|8.29.6|8.30.3|8.31.5|8.32.5|8.33.6|8.34.8|8.35.5|8.36.5|8.37.6|8.38.6|8.38.7) ;;
 8.39.4) [ "$KV" = "2.6" ] && if [ "$(uname -r|grep -E '2.6.23|2.6.24')" != "" ]; then
   #http://mlau.at/files/fglrx-839-2624rc-fixes.patch
   patch common/lib/modules/fglrx/build_mod/firegl_public.c <<'EOT'
crude patch to get fglrx-8.39 to compile against 2.6.23/2.6.24-rc4/5.
Use at your own risk!	-- mlau

--- firegl_public.c.orig	2007-07-20 22:51:46.000000000 +0200
+++ firegl_public.c	2007-12-11 18:35:16.000000000 +0100
@@ -214,6 +214,56 @@
 #define preempt_enable()
 #endif
 
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,22)
+#if defined(__i386__)
+#define ptep_test_and_clear_dirty(vma, addr, ptep) ({                  \
+       int __ret = 0;                                                  \
+       if (pte_dirty(*(ptep)))                                         \
+               __ret = test_and_clear_bit(_PAGE_BIT_DIRTY,             \
+                                               &(ptep)->pte_low);      \
+       if (__ret)                                                      \
+               pte_update((vma)->vm_mm, addr, ptep);                   \
+       __ret;                                                          \
+})
+
+static inline int pte_read(pte_t pte)	{ return (pte).pte_low & _PAGE_USER; }
+static inline int pte_user(pte_t pte)	{ return (pte).pte_low & _PAGE_USER; }
+#ifdef CONFIG_X86_PAE
+/*
+ * Is the pte executable?
+ */
+static inline int pte_x(pte_t pte)
+{
+        return !(pte_val(pte) & _PAGE_NX);
+}
+ 
+/*
+ * All present user-pages with !NX bit are user-executable:
+ */
+static inline int pte_exec(pte_t pte)
+{
+        return pte_user(pte) && pte_x(pte);
+}
+#else
+static inline int pte_exec(pte_t pte)
+{
+        return pte_user(pte);
+}
+#endif	/* PAE */
+
+#elif defined(__x86_64__)
+static inline int ptep_test_and_clear_dirty(struct vm_area_struct *vma,
+					unsigned long addr, pte_t *ptep)
+{
+	if (!pte_dirty(*ptep))
+		return 0;
+	return test_and_clear_bit(_PAGE_BIT_DIRTY, &ptep->pte);
+}
+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_NX); }
+#endif
+#endif
+
 // ============================================================
 /* globals */
 
@@ -1831,7 +1881,7 @@ int ATI_API_CALL __ke_check_pci(int busn
 {
     struct pci_dev* pci_dev;
 
-    pci_dev = pci_find_slot(busnum, PCI_DEVFN(devnum, funcnum));
+    pci_dev = pci_get_slot(busnum, PCI_DEVFN(devnum, funcnum));
     if (!pci_dev)
         return 0;
 
@@ -1860,7 +1910,7 @@ int ATI_API_CALL __ke_pci_get_irq(__ke_p
 
 __ke_pci_dev_t* ATI_API_CALL __ke_pci_find_device (unsigned int vendor, unsigned int dev, __ke_pci_dev_t* from)
 {
-	return (__ke_pci_dev_t*)pci_find_device( vendor, dev, (struct pci_dev *)(void *)from );
+	return (__ke_pci_dev_t*)pci_get_device( vendor, dev, (struct pci_dev *)(void *)from );
 }
 
 void* ATI_API_CALL __ke_malloc(__ke_size_t size)
@@ -2333,7 +2383,7 @@ void ATI_API_CALL __ke_put_vm_page_table
 #ifndef ptep_clear_flush_dirty
 #define ptep_clear_flush_dirty(__vma, __address, __ptep) \
 ({							 \
-    int __dirty = ptep_test_and_clear_dirty(__ptep);	 \
+    int __dirty = ptep_test_and_clear_dirty(__vma, __address, __ptep);	 \
     if (__dirty)					 \
         flush_tlb_page(__vma, __address);		 \
     __dirty;						 \
@@ -2693,7 +2743,7 @@ int ATI_API_CALL __ke_pci_write_config_d
 
 __ke_pci_dev_t* ATI_API_CALL __ke_pci_find_slot(__ke_u32 bus, __ke_u32 slot)
 {
-    return (__ke_pci_dev_t*)pci_find_slot(bus, slot);
+    return (__ke_pci_dev_t*)pci_get_slot(bus, slot);
 }
 
 __ke_u8 ATI_API_CALL __ke_pci_get_busnr(__ke_pci_dev_t* pcidev)
@@ -2773,6 +2823,10 @@ void ATI_API_CALL __ke_disable_irq(int i
     disable_irq( irq );
 }
 
+#ifndef SA_SHIRQ
+#define SA_SHIRQ IRQF_SHARED
+#endif
+
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,71)
 int ATI_API_CALL __ke_request_irq(unsigned int irq, 
     void (*ATI_API_CALL handler)(int, void *, void *),
@@ -5277,7 +5331,7 @@ unsigned int ATI_API_CALL KAS_Spinlock_R
 /** \brief Type definition of the structure describing Slab Cache object */
 typedef struct tag_kasSlabCache_t
 {
-    kmem_cache_t* cache;        /* OS slab cache object */
+    struct kmem_cache *cache;	/* OS slab cache object */
     spinlock_t lock;            /* OS spinlock object protecting the cache */
     unsigned int routine_type;  /* Type of routine the cache might be accessed from */
     char name[14];              /* Cache object name (kernel 2.4 restricts its length to 19 chars) */
@@ -5323,7 +5377,7 @@ unsigned int ATI_API_CALL KAS_SlabCache_
     DBG_TRACE("creating slab object '%s'", slabcache_obj->name);
 
     if ((slabcache_obj->cache =
-            kmem_cache_create(slabcache_obj->name, iEntrySize, 0, 0, NULL, NULL)))
+            kmem_cache_create(slabcache_obj->name, iEntrySize, 0, 0, NULL)))
     {
         ret = 1;
     }

EOT
  fi
  ;;
 8.40.4|8.41.7|8.42.3) [ "$KV" = "2.6" ] && if [ "$(uname -r|grep -E '2.6.23|2.6.24')" != "" ]; then
   #http://mlau.at/files/fglrx-842-2623.patch
   patch common/lib/modules/fglrx/build_mod/firegl_public.c <<'EOT'
crude patch to make 8.42 compile against 2.6.23+.
The x64 version probably doesn't work.

Better get the patch from the ati-drivers sabayon overlay ;-)

--- firegl_public.c.orig	2007-10-23 19:31:26.000000000 +0200
+++ firegl_public.c	2007-10-23 19:32:07.000000000 +0200
@@ -217,6 +217,56 @@
 #define preempt_enable()
 #endif
 
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,22)
+#if defined(__i386__)
+#define ptep_test_and_clear_dirty(vma, addr, ptep) ({                  \
+       int __ret = 0;                                                  \
+       if (pte_dirty(*(ptep)))                                         \
+               __ret = test_and_clear_bit(_PAGE_BIT_DIRTY,             \
+                                               &(ptep)->pte_low);      \
+       if (__ret)                                                      \
+               pte_update((vma)->vm_mm, addr, ptep);                   \
+       __ret;                                                          \
+})
+
+static inline int pte_read(pte_t pte)	{ return (pte).pte_low & _PAGE_USER; }
+static inline int pte_user(pte_t pte)	{ return (pte).pte_low & _PAGE_USER; }
+#ifdef CONFIG_X86_PAE
+/*
+ * Is the pte executable?
+ */
+static inline int pte_x(pte_t pte)
+{
+        return !(pte_val(pte) & _PAGE_NX);
+}
+ 
+/*
+ * All present user-pages with !NX bit are user-executable:
+ */
+static inline int pte_exec(pte_t pte)
+{
+        return pte_user(pte) && pte_x(pte);
+}
+#else
+static inline int pte_exec(pte_t pte)
+{
+        return pte_user(pte);
+}
+#endif	/* PAE */
+
+#elif defined(__x86_64__)
+static inline int ptep_test_and_clear_dirty(struct vm_area_struct *vma,
+					unsigned long addr, pte_t *ptep)
+{
+	if (!pte_dirty(*ptep))
+		return 0;
+	return test_and_clear_bit(_PAGE_BIT_DIRTY, &ptep->pte);
+}
+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_NX); }
+#endif
+#endif
+
 // ============================================================
 /* globals */
 
@@ -2489,7 +2539,7 @@ void ATI_API_CALL __ke_put_vm_page_table
 #ifndef ptep_clear_flush_dirty
 #define ptep_clear_flush_dirty(__vma, __address, __ptep) \
 ({							 \
-    int __dirty = ptep_test_and_clear_dirty(__ptep);	 \
+    int __dirty = ptep_test_and_clear_dirty(__vma, __address, __ptep);	 \
     if (__dirty)					 \
         flush_tlb_page(__vma, __address);		 \
     __dirty;						 \
@@ -2936,7 +2986,7 @@ int ATI_API_CALL __ke_request_irq(unsign
 {
     return request_irq(irq,
         (void(*)(int, void *, struct pt_regs *))handler,
-        SA_SHIRQ, dev_name, dev_id);
+        IRQF_SHARED, dev_name, dev_id);
 }
 
 void ATI_API_CALL __ke_free_irq(unsigned int irq, void *dev_id)
@@ -2959,7 +3009,7 @@ int ATI_API_CALL __ke_request_irq(unsign
     irq_handler_func = handler;
     return request_irq(irq,
         ke_irq_handler_wrap,
-        SA_SHIRQ, dev_name, dev_id);
+        IRQF_SHARED, dev_name, dev_id);
 }
 
 void ATI_API_CALL __ke_free_irq(unsigned int irq, void *dev_id)
@@ -5436,7 +5486,7 @@ unsigned int ATI_API_CALL KAS_Spinlock_R
 /** \brief Type definition of the structure describing Slab Cache object */
 typedef struct tag_kasSlabCache_t
 {
-    kmem_cache_t* cache;        /* OS slab cache object */
+    struct kmem_cache *cache;	/* OS slab cache object */
     spinlock_t lock;            /* OS spinlock object protecting the cache */
     unsigned int routine_type;  /* Type of routine the cache might be accessed from */
     char name[14];              /* Cache object name (kernel 2.4 restricts its length to 19 chars) */
@@ -5482,7 +5532,7 @@ unsigned int ATI_API_CALL KAS_SlabCache_
     DBG_TRACE("creating slab object '%s'", slabcache_obj->name);
 
     if ((slabcache_obj->cache =
-            kmem_cache_create(slabcache_obj->name, iEntrySize, 0, 0, NULL, NULL)))
+            kmem_cache_create(slabcache_obj->name, iEntrySize, 0, 0, NULL)))
     {
         ret = 1;
     }

EOT
  fi
  ;;
esac

[ "$VER" = "8.42.3" ] && patch -p1 <<'EOT'
diff -Nru ati-8.42.3.orig/packages/Debian/ati-packager.sh ati-8.42.3/packages/Debian/ati-packager.sh
--- ati-8.42.3.orig/packages/Debian/ati-packager.sh	2007-10-22 18:30:02.000000000 +0200
+++ ati-8.42.3/packages/Debian/ati-packager.sh	2007-10-11 23:22:35.000000000 +0200
@@ -95,6 +95,11 @@
     cp -f -R ${InstallerRootDir}/arch/${ARCH_DIR}/* ${TmpDrvFilesDir}
     cp -f -R ${InstallerRootDir}/common/* ${TmpDrvFilesDir}
 
+    if [ "$ARCH" = "amd64" ]; then
+        cp -f -R ${InstallerRootDir}/arch/x86/usr/X11R6/lib \
+                ${TmpDrvFilesDir}/usr/X11R6/
+    fi
+
     # Merge package files from the appropriate directories
     chmod -R u+w ${AbsDistroDir}
 	cp -f -R ${AbsDistroDir}/dists/${X_NAME} ${TmpDrvFilesDir}/debian
diff -Nru ati-8.42.3.orig/packages/Ubuntu/ati-packager.sh ati-8.42.3/packages/Ubuntu/ati-packager.sh
--- ati-8.42.3.orig/packages/Ubuntu/ati-packager.sh	2007-10-22 18:30:02.000000000 +0200
+++ ati-8.42.3/packages/Ubuntu/ati-packager.sh	2007-10-11 23:22:35.000000000 +0200
@@ -69,7 +69,7 @@
         dapper|6.06) X_DIR=x690; X_NAME=dapper;;
         edgy|6.10)   X_DIR=x710; X_NAME=edgy;;
         feisty|7.04) X_DIR=x710; X_NAME=feisty;;
-        gutsy|7.10) X_DIR=x710; X_NAME=gutsy;;
+        gutsy|7.10)  X_DIR=x710; X_NAME=gutsy;;
         *) echo "Error: invalid package name passed to --buildpkg" ; exit 1 ;;
     esac
 
@@ -97,6 +97,11 @@
     cp -f -R ${InstallerRootDir}/arch/${ARCH_DIR}/* ${TmpDrvFilesDir}
     cp -f -R ${InstallerRootDir}/common/* ${TmpDrvFilesDir}
 
+    if [ "$ARCH" = "amd64" ]; then
+        cp -f -R ${InstallerRootDir}/arch/x86/usr/X11R6/lib \
+		${TmpDrvFilesDir}/usr/X11R6/
+    fi
+
     # Merge package files from the appropriate directories
 	chmod -R u+w ${AbsDistroDir}
 	cp -f -R ${AbsDistroDir}/dists/${X_NAME} ${TmpDrvFilesDir}/debian

EOT

if [ "$(uname -r|grep -E '2.6.25')" != "" -a "$VER" = "8-5" ]; then
 # http://sarah-a-happy.livejournal.com/90345.html
 patch -p0 <<'EOT'
--- common/lib/modules/fglrx/build_mod/firegl_public.c.orig     2008-04-06 01:20:21.000000000 -0300
+++ common/lib/modules/fglrx/build_mod/firegl_public.c  2008-04-06 01:17:58.000000000 -0300
@@ -1885,7 +1885,7 @@
  */
 KCL_TYPE_Cap ATI_API_CALL KCL_PosixSecurityCapGetEffectiveVector()
 {
-    return cap_t(current->cap_effective);
+    return (current->cap_effective).cap[0];
 }
 
 /** \brief Set vector of effective security caps for the current process
@@ -1893,7 +1893,7 @@
  */
 void ATI_API_CALL KCL_PosixSecurityCapSetEffectiveVector(KCL_TYPE_Cap cap)
 {
-    cap_t(current->cap_effective) = cap;
+    (current->cap_effective).cap[0] = cap;
 }
 
 /** \brief Get number of available RAM pages

--- common/lib/modules/fglrx/build_mod/firegl_public.c.orig     2008-04-06 02:10:13.000000000 -0300
+++ common/lib/modules/fglrx/build_mod/firegl_public.c  2008-04-06 02:23:05.000000000 -0300
@@ -120,6 +120,7 @@
 #include <asm/cpufeature.h>
 #ifdef CONFIG_MTRR
 #include <asm/mtrr.h>
+#include <asm/cacheflush.h>
 #endif
 #include <asm/delay.h>
 #include <linux/agp_backend.h>
@@ -1158,7 +1159,7 @@
 
 int ATI_API_CALL KCL_SetPageNoCache(void* virt, int pages)
 {
-    return change_page_attr(virt_to_page(virt), pages, PAGE_KERNEL_NOCACHE);
+    return set_pages_uc(virt_to_page(virt), pages);
 }
 
 /** /brief Call global kernel task/thread scheduler */

EOT
fi

if [ "$(uname -r|grep -E '2.6.26')" != "" ] && [ "$VER" = "8-5" -o "$VER" = "8-6" ]; then
 cd common/lib/modules/fglrx/build_mod
 # http://launchpadlibrarian.net/15305502/0001-Linux-2.6.25.x-kernels-support.patch
 patch -p1 <<'EOT'
From 0dd050cd65a7dfff6685f1b2066f49e7086a4520 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?=C5=BDilvinas=20Valinskas?= <zilvinas@wilibox.com>
Date: Fri, 13 Jun 2008 23:55:15 +0300
Subject: [PATCH] Linux 2.6.25.x kernels support.
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Žilvinas Valinskas <zilvinas@wilibox.com>
---
 firegl_public.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/firegl_public.c b/firegl_public.c
index f2bea44..0916436 100644
--- a/firegl_public.c
+++ b/firegl_public.c
@@ -4956,8 +4956,9 @@ static unsigned long kasSetExecutionLevel(unsigned long level)
 {
     unsigned long orig_level;
 
-    orig_level = __get_cpu_var(kasExecutionLevel);
+    orig_level = get_cpu_var(kasExecutionLevel);
     __get_cpu_var(kasExecutionLevel) = level;
+    put_cpu_var(kasExecutionLevel);
 
     return orig_level;
 }
@@ -4969,7 +4970,12 @@ static unsigned long kasSetExecutionLevel(unsigned long level)
  */
 static unsigned long kas_GetExecutionLevel(void)
 {
-    return __get_cpu_var(kasExecutionLevel);
+    unsigned long orig_level;
+
+    orig_level = get_cpu_var(kasExecutionLevel);
+    put_cpu_var(kasExecutionLevel);
+
+    return orig_level;
 }
 
 /** \brief Type definition for kas_spin_lock() parameter */
-- 
1.5.6.rc2.45.gdc92c
EOT
 # http://launchpadlibrarian.net/15305506/0002-Trivial-error-and-two-warnings-fixed.patch
 [ "$VER" = "8-5" ] && patch -p1 <<'EOT'
From 681d2406888fb07f584ecb83a921aca4bfd469a8 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?=C5=BDilvinas=20Valinskas?= <zilvinas@wilibox.com>
Date: Sat, 14 Jun 2008 02:07:38 +0300
Subject: [PATCH] Trivial error and two warnings fixed.
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Žilvinas Valinskas <zilvinas@wilibox.com>
---
 firegl_public.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/firegl_public.c b/firegl_public.c
index 0916436..664b38c 100644
--- a/firegl_public.c
+++ b/firegl_public.c
@@ -885,7 +885,7 @@ static struct pci_driver fglrx_pci_driver =
  * \return  count  -- number of devices found that this kernel module will support
  *
  */
-int count_drm_devices()
+int count_drm_devices(void)
 {
     int count = 0;
     struct pci_dev *pdev = NULL;
@@ -1681,7 +1681,7 @@ int ATI_API_CALL KCL_pci_enable_device_bars( __ke_pci_dev_t *dev)
 {
     u16 cmd;
 
-    pci_read_config_word(dev, PCI_COMMAND, &cmd);
+    pci_read_config_word((void *)dev, PCI_COMMAND, &cmd);
 
     if (!(cmd & PCI_COMMAND_IO))
     {
@@ -1693,7 +1693,7 @@ int ATI_API_CALL KCL_pci_enable_device_bars( __ke_pci_dev_t *dev)
         cmd |= PCI_COMMAND_MEMORY;
     }
 
-    pci_write_config_word(dev, PCI_COMMAND, cmd);
+    pci_write_config_word((struct pci_dev*)(void *)dev, PCI_COMMAND, cmd);
     return 0;
 }
 
-- 
1.5.6.rc2.45.gdc92c
EOT
 # http://launchpadlibrarian.net/15305508/0003-GCC-complains-return-with-a-value-in-function-ret.patch
 patch -p1 <<'EOT'
From a94e42382fbf70d88d71c473b392a2e0656dcf0c Mon Sep 17 00:00:00 2001
From: =?utf-8?q?=C5=BDilvinas=20Valinskas?= <zilvinas@wilibox.com>
Date: Sat, 14 Jun 2008 02:10:00 +0300
Subject: [PATCH] GCC complains `return' with a value, in function returning void
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Žilvinas Valinskas <zilvinas@wilibox.com>
---
 firegl_public.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/firegl_public.c b/firegl_public.c
index 664b38c..d71700d 100644
--- a/firegl_public.c
+++ b/firegl_public.c
@@ -3190,7 +3190,7 @@ int ATI_API_CALL __ke_register_ioctl32_conversion(unsigned int cmd, int (*handle
 void ATI_API_CALL __ke_unregister_ioctl32_conversion(unsigned int cmd)
 {
 #ifdef FIREGL_IOCTL_COMPAT
-    return 0;
+    return;
 #else
     unregister_ioctl32_conversion(cmd);
 #endif
-- 
1.5.6.rc2.45.gdc92c
EOT
 # http://launchpadlibrarian.net/15305524/0004-Linux-2.6.26.x-kernels-support.patch
 [ "$VER" = "8-5" ] && patch -p1 <<'EOT'
From d6ef03ff417eb001653c51112c79e709ba8eaec9 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?=C5=BDilvinas=20Valinskas?= <zilvinas@wilibox.com>
Date: Sat, 14 Jun 2008 03:54:38 +0300
Subject: [PATCH] Linux 2.6.26.x kernels support.
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

o trailing white spaces/tabs removed.
o VMA ->nopage() removed, go for ->fault()
o compiles with warnings ...
o most importantly ... WORKS on 2.6.26-rc6/amd64!

Signed-off-by: Žilvinas Valinskas <zilvinas@wilibox.com>
---
 firegl_public.c |  655 ++++++++++++++++++++++++-------------------------------
 firegl_public.h |    8 +-
 2 files changed, 288 insertions(+), 375 deletions(-)

diff --git a/firegl_public.c b/firegl_public.c
index d71700d..3c8e72a 100644
--- a/firegl_public.c
+++ b/firegl_public.c
@@ -24,13 +24,13 @@
 // ============================================================
 #include <linux/version.h>
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
 #error Kernel versions older than 2.6.0 are no longer supported by this module.
-#endif 
+#endif
 
 #include <linux/autoconf.h>
 
-#if !defined(CONFIG_X86_PC) 
+#if !defined(CONFIG_X86_PC)
 #if !defined(CONFIG_X86_64)
 #if !defined(CONFIG_X86_VOYAGER)
 #if !defined(CONFIG_X86_NUMAQ)
@@ -62,10 +62,10 @@
  * distribution would even include such a kernel patch. */
 #ifdef CONFIG_MEM_MIRROR
 /* Prevent asm/mm_track.h from being included in subsequent
- * kernel headers as that would redefine CONFIG_MEM_MIRROR. */ 
+ * kernel headers as that would redefine CONFIG_MEM_MIRROR. */
 #ifndef CONFIG_X86_64
 #define __I386_MMTRACK_H__
-#define mm_track(ptep)                 
+#define mm_track(ptep)
 #else
 #define __X86_64_MMTRACK_H__
 #define mm_track_pte(ptep)
@@ -93,7 +93,7 @@
 #include <linux/kernel.h>
 #include <linux/fs.h>
 #include <linux/proc_fs.h>
-#include <linux/init.h>
+//#include <linux/init.h>
 #include <linux/file.h>
 #include <linux/pci.h>
 #include <linux/wait.h>
@@ -151,8 +151,8 @@
 #include "linux/freezer.h"
 #endif
 
-//  For 2.6.18 or higher, the UTS_RELEASE is defined in the linux/utsrelease.h. 
-#ifndef UTS_RELEASE 
+//  For 2.6.18 or higher, the UTS_RELEASE is defined in the linux/utsrelease.h.
+#ifndef UTS_RELEASE
 #include <linux/utsrelease.h>
 #endif
 
@@ -210,7 +210,7 @@ char* firegl = NULL;
 int __ke_debuglevel = 0;
 int __ke_moduleflags = 0;
 
-static struct pci_device_id fglrx_pci_table[] = 
+static struct pci_device_id fglrx_pci_table[] =
 {
 #define FGL_ASIC_ID(x)                      \
    {                           \
@@ -278,7 +278,7 @@ const unsigned long __ke_PAE_State = 1;
 
 static int firegl_pat_enabled = 0;
 static unsigned long KCL_pat[2];
-static unsigned long KCL_orig_pat[2]; 
+static unsigned long KCL_orig_pat[2];
 
 static int ATI_API_CALL KCL_enable_pat(void);
 static void ATI_API_CALL KCL_disable_pat(void);
@@ -305,7 +305,7 @@ long ip_firegl_compat_ioctl(struct file* filp, unsigned int cmd, unsigned long a
 #endif
 
 __ke_ssize_t ip_firegl_read( struct file *filp,
-                         char *buf, 
+                         char *buf,
                          __ke_size_t size,
                          __ke_loff_t *off_ptr)
 {
@@ -313,7 +313,7 @@ __ke_ssize_t ip_firegl_read( struct file *filp,
 }
 
 __ke_ssize_t ip_firegl_write( struct file *filp,
-                          const char *buf, 
+                          const char *buf,
                           __ke_size_t size,
                           __ke_loff_t *off_ptr)
 {
@@ -449,34 +449,34 @@ READ_PROC_WRAP(firegl_debug_info)
 READ_PROC_WRAP(firegl_bios_version)
 READ_PROC_WRAP(firegl_interrupt_info)
 
-static int 
+static int
 firegl_interrupt_open_wrap(
-        struct inode *inode, 
-        struct file *file) 
+        struct inode *inode,
+        struct file *file)
 {
     return firegl_interrupt_open(inode, file);
 }
 
-static int 
+static int
 firegl_interrupt_release_wrap(
-        struct inode *inode, 
-        struct file *file) 
+        struct inode *inode,
+        struct file *file)
 {
     return firegl_interrupt_release(inode, file);
 }
 
-static ssize_t 
+static ssize_t
 firegl_interrupt_read_wrap(
-        struct file *user_file, 
-        char __user *user_buf, 
-        size_t user_buf_size, 
+        struct file *user_file,
+        char __user *user_buf,
+        size_t user_buf_size,
         loff_t *user_file_pos)
 {
     return (ssize_t) firegl_interrupt_read(user_file, user_buf, user_buf_size, user_file_pos);
 }
 
-static unsigned int 
-firegl_interrupt_poll_wrap(struct file *user_file, poll_table *pt) 
+static unsigned int
+firegl_interrupt_poll_wrap(struct file *user_file, poll_table *pt)
 {
     if(firegl_interrupt_poll(user_file, (__ke_poll_table*)pt))
     {
@@ -488,11 +488,11 @@ firegl_interrupt_poll_wrap(struct file *user_file, poll_table *pt)
     }
 }
 
-static ssize_t 
+static ssize_t
 firegl_interrupt_write_wrap(
-        struct file *user_file, 
-        const char __user *user_buf, 
-        size_t user_buf_size, 
+        struct file *user_file,
+        const char __user *user_buf,
+        size_t user_buf_size,
         loff_t *user_file_pos)
 {
     return (ssize_t) firegl_interrupt_write(user_file, user_buf, user_buf_size, user_file_pos);
@@ -502,7 +502,7 @@ firegl_interrupt_write_wrap(
  *  \param func function to be wrapped
  *  \return None */
 
-static void 
+static void
 firegl_smp_func_parameter_wrap(
 void *func)
 {
@@ -517,7 +517,7 @@ static struct file_operations firegl_interrupt_file_ops = {
     .write      = firegl_interrupt_write_wrap
 };
 
-__ke_proc_list_t firegl_proc_list[] = 
+__ke_proc_list_t firegl_proc_list[] =
 {
     { "name",           drm_name_info_wrap,         NULL},
     { "mem",            drm_mem_info_wrap,          NULL},
@@ -586,11 +586,11 @@ static struct proc_dir_entry *firegl_proc_init( device_t *dev,
         {
 		    ent->proc_fops = (struct file_operations*)list->fops;
         }
-       
+
         {
             ent->data = (dev->pubdev.signature == FGL_DEVICE_SIGNATURE)? firegl_find_device(minor) : (dev);
         }
-        
+
         list++;
 	}
 
@@ -623,7 +623,7 @@ static int firegl_proc_cleanup( int minor,
     {
         remove_proc_entry("dri", NULL);
         __KE_DEBUG("remove proc dri. \n");
-    }    
+    }
     return 0;
 }
 
@@ -661,12 +661,12 @@ static int firegl_stub_getminor(const char *name, struct file_operations *fops,
 {
 	int i;
         int count = 0;
-        
+
         __KE_DEBUG("firegl_stub_getminor: name=\"%s\"\n", name);
 
-	for( i = 0; i < FIREGL_STUB_MAXCARDS; i++ ) 
+	for( i = 0; i < FIREGL_STUB_MAXCARDS; i++ )
         {
-	    if( !firegl_stub_list[i].fops ) 
+	    if( !firegl_stub_list[i].fops )
             {
 		firegl_stub_list[i].name = name;
 		firegl_stub_list[i].fops = fops;
@@ -693,16 +693,16 @@ static int firegl_stub_putminor(int minor)
     if (minor < 0 || minor >= FIREGL_STUB_MAXCARDS)
     {
         return -1;
-    }    
+    }
     firegl_proc_cleanup(minor, firegl_stub_root, firegl_stub_list[minor].dev_root, firegl_stub_list[minor].proclist);
     firegl_stub_list[minor].name = NULL;
     firegl_stub_list[minor].fops = NULL;
     firegl_stub_list[minor].proclist = NULL;
 
-    if( minor == (firegl_minors-1) ) 
+    if( minor == (firegl_minors-1) )
     {
         unregister_chrdev(DRM_MAJOR, "drm");
-    }   
+    }
     return 0;
 }
 
@@ -726,7 +726,7 @@ static int __init firegl_stub_register(const char *name, struct file_operations
         return -1;
     } else if(err == -EBUSY) {
 
-        // the registering of the module's device has failed 
+        // the registering of the module's device has failed
         // because there was already some other drm module loaded.
         __KE_DEBUG("register_chrdev() failed with -EBUSY\n");
 	return -1;
@@ -758,7 +758,7 @@ static int fglrx_pci_probe(struct pci_dev *dev, const struct pci_device_id *id_t
 /* Starting from 2.6.14, kernel has new struct defined for pm_message_t,
    we have to handle this case separately.
    2.6.11/12/13 kernels have pm_message_t defined as int and older kernels
-   don't have pm_message_t defined. 
+   don't have pm_message_t defined.
  */
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
 static int fglrx_pci_suspend(struct pci_dev *pdev, pm_message_t pm_event)
@@ -794,9 +794,9 @@ static int fglrx_pci_suspend(struct pci_dev *pdev, u32 pm_event)
 
     if (!ret)
     {
-        
-    // since privdev->pcidev is acquired in X server, use pdev 
-    // directly here to allow suspend/resume without X server start. 
+
+    // since privdev->pcidev is acquired in X server, use pdev
+    // directly here to allow suspend/resume without X server start.
         firegl_pci_save_state((__ke_pci_dev_t*)pdev, privdev);
         pci_disable_device(pdev);
         PMSG_EVENT(pdev->dev.power.power_state) = state;
@@ -848,13 +848,13 @@ static int fglrx_pci_resume(struct pci_dev *pdev)
     // before pci_set_master!
     firegl_pci_restore_state((__ke_pci_dev_t*)pdev, privdev);
 
-    if (pci_enable_device(pdev)) 
+    if (pci_enable_device(pdev))
     {
         __KE_ERROR("Cannot enable PCI device.\n");
-    }    
+    }
 
     pci_set_master(pdev);
- 
+
     firegl_cail_powerup(privdev);
 
     if (PMSG_EVENT(pdev->dev.power.power_state) == PM_EVENT_SUSPEND)
@@ -865,7 +865,7 @@ static int fglrx_pci_resume(struct pci_dev *pdev)
     return 0;
 }
 
-static struct pci_driver fglrx_pci_driver = 
+static struct pci_driver fglrx_pci_driver =
 {
     .name           = "fglrx_pci",
     .id_table       = fglrx_pci_table,
@@ -921,10 +921,10 @@ static int firegl_init_devices(__ke_device_t *pubdev)
     {
         pid = (struct pci_device_id *) &fglrx_pci_table[i];
         pdev = NULL;
-        while (( pdev = pci_get_subsys(pid->vendor, 
-                                       pid->device, 
-                                       PCI_ANY_ID, 
-                                       PCI_ANY_ID, 
+        while (( pdev = pci_get_subsys(pid->vendor,
+                                       pid->device,
+                                       PCI_ANY_ID,
+                                       PCI_ANY_ID,
                                        pdev)) != NULL)
         {
             num_of_devices++;
@@ -934,7 +934,7 @@ static int firegl_init_devices(__ke_device_t *pubdev)
 
     if (firegl_init_device_heads(num_of_devices))
     {
-        return -ENOMEM;     
+        return -ENOMEM;
     }
 
     for (i=0; fglrx_pci_table[i].vendor != 0; i++)
@@ -942,15 +942,15 @@ static int firegl_init_devices(__ke_device_t *pubdev)
         pid = (struct pci_device_id *) &fglrx_pci_table[i];
 
         pdev = NULL;
-        while (( pdev = pci_get_subsys(pid->vendor, 
-                                       pid->device, 
-                                       PCI_ANY_ID, 
-                                       PCI_ANY_ID, 
+        while (( pdev = pci_get_subsys(pid->vendor,
+                                       pid->device,
+                                       PCI_ANY_ID,
+                                       PCI_ANY_ID,
                                        pdev)) != NULL)
         {
             if ((ret_code = firegl_get_dev(pubdev, pdev)))
             {
-                return ret_code; 
+                return ret_code;
             }
 
             j++;
@@ -983,7 +983,7 @@ static int __init firegl_init_module(void)
     // init global vars that are in fact constants
     __ke_HZ = HZ;
 
-#ifdef _KE_SERIAL_DEBUG  
+#ifdef _KE_SERIAL_DEBUG
     __ke_SetSerialPort();
 #endif
 
@@ -995,11 +995,11 @@ static int __init firegl_init_module(void)
         return retcode;
     }
 
-#ifdef FIREGL_CF_SUPPORT    
+#ifdef FIREGL_CF_SUPPORT
     adapter_chain_init();
     cf_object_init();
-#endif    
-     
+#endif
+
     // init DRM proc list
     drm_proclist = kmalloc((DRM_PROC_ENTRIES + 1) * sizeof(__ke_proc_list_t), GFP_KERNEL);
     if ( drm_proclist == NULL )
@@ -1087,7 +1087,7 @@ static int __init firegl_init_module(void)
 	        dev->pubdev.date,
 		    firegl_minors);
 
-    
+
 #ifdef FIREGL_POWER_MANAGEMENT
     if (pci_register_driver (&fglrx_pci_driver) < 0)
     {
@@ -1117,12 +1117,12 @@ static void __exit firegl_cleanup_module(void)
     {
        KCL_disable_pat();
        __KE_INFO("Disable PAT\n");
-    }   
+    }
 #endif // FIREGL_USWC_SUPPORT
 
     for (i = 0; i < count; i++)
     {
-        if ( firegl_stub_unregister(i) ) 
+        if ( firegl_stub_unregister(i) )
         {
             __KE_ERROR("Cannot unload module on minor: %d\n", i);
         }
@@ -1144,10 +1144,10 @@ static void __exit firegl_cleanup_module(void)
 	        dev->pubdev.patchlevel,
 	        dev->pubdev.date);
 
-#ifdef FIREGL_CF_SUPPORT    
+#ifdef FIREGL_CF_SUPPORT
     cf_object_cleanup();
-    adapter_chain_cleanup();    
-#endif // FIREGL_CF_SUPPORT   
+    adapter_chain_cleanup();
+#endif // FIREGL_CF_SUPPORT
 
     firegl_private_cleanup (&dev->pubdev);
 
@@ -1225,18 +1225,18 @@ void ATI_API_CALL __ke_add_wait_queue(__ke_wait_queue_head_t* queue_head, __ke_w
 void ATI_API_CALL __ke_remove_wait_queue(__ke_wait_queue_head_t* queue_head, __ke_wait_queue_t* entry)
 {
 //    current->state = TASK_RUNNING;
-    remove_wait_queue((wait_queue_head_t*)(void *)queue_head, 
+    remove_wait_queue((wait_queue_head_t*)(void *)queue_head,
 									(wait_queue_t*)(void *)entry);
 }
 
 void ATI_API_CALL __ke_init_waitqueue_head(__ke_wait_queue_head_t* queue_head)
 {
-    init_waitqueue_head((wait_queue_head_t*)(void *)queue_head); 
+    init_waitqueue_head((wait_queue_head_t*)(void *)queue_head);
 }
 
 void ATI_API_CALL __ke_wait_event_interruptible(__ke_wait_queue_head_t* queue_head, int condition)
 {
-    wait_event_interruptible(*((wait_queue_head_t*)(void *)queue_head), condition); 
+    wait_event_interruptible(*((wait_queue_head_t*)(void *)queue_head), condition);
 }
 
 void ATI_API_CALL __ke_poll_wait(struct file* filp, __ke_wait_queue_head_t* queue_head, __ke_poll_table* pt)
@@ -1247,13 +1247,13 @@ void ATI_API_CALL __ke_poll_wait(struct file* filp, __ke_wait_queue_head_t* queu
 void ATI_API_CALL *__ke_asyncio_alloc_sema()
 {
     int i;
-    
+
     for(i=0; i<FIREGL_ASYNCIO_MAX_SEMA; i++)
     {
         if(fireglAsyncioSemaphoreUsed[i] != 1)
         {
             fireglAsyncioSemaphoreUsed[i] = 1;
-            
+
             return &(fireglAsyncioSemaphore[i]);
         }
     }
@@ -1263,7 +1263,7 @@ void ATI_API_CALL *__ke_asyncio_alloc_sema()
 void ATI_API_CALL __ke_asyncio_free_sema(struct semaphore *pSema)
 {
     int i;
-    
+
     for(i=0; i<FIREGL_ASYNCIO_MAX_SEMA; i++)
     {
         if( &(fireglAsyncioSemaphore[i]) == pSema )
@@ -1277,15 +1277,15 @@ void ATI_API_CALL __ke_asyncio_free_sema(struct semaphore *pSema)
 void ATI_API_CALL __ke_asyncio_init_sema(void)
 {
     int i;
-    
+
     for(i=0; i<FIREGL_ASYNCIO_MAX_SEMA; i++)
     {
         fireglAsyncioSemaphoreUsed[i] = 0;
     }
-}    
+}
 
-int ATI_API_CALL __ke_fasync_helper( int fd, 
-                        struct file *filep, 
+int ATI_API_CALL __ke_fasync_helper( int fd,
+                        struct file *filep,
                         int mode,
                         struct fasync_struct **pasync_queue)
 {
@@ -1352,33 +1352,33 @@ unsigned int ATI_API_CALL KCL_ProcessIsTerminated(unsigned int pid)
 {
    struct task_struct *p;
    int process_terminated = 1;
-  
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)  
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
    rcu_read_lock();
-#else   
+#else
    read_lock(&tasklist_lock);
-#endif   
-   p = find_task_by_pid( pid );
-   if (p) 
+#endif
+   p = find_task_by_vpid( pid );
+   if (p)
    {
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10)
-      if (p->exit_state != EXIT_ZOMBIE && p->exit_state != EXIT_DEAD) 
+      if (p->exit_state != EXIT_ZOMBIE && p->exit_state != EXIT_DEAD)
 #else
-      if (!(p->flags & PF_EXITING)) 
+      if (!(p->flags & PF_EXITING))
 #endif
       {
          process_terminated = 0;
       }
-   }   
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)  
+   }
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
    rcu_read_unlock();
-#else   
+#else
    read_unlock(&tasklist_lock);
-#endif   
+#endif
    return process_terminated;
 }
 
-/** /brief Call global OS kernel task/thread scheduler 
+/** /brief Call global OS kernel task/thread scheduler
  *  /return Nonzero if a system call was awakened by a signal
  */
 int ATI_API_CALL KCL_GetSignalStatus(void)
@@ -1432,15 +1432,15 @@ void ATI_API_CALL __ke_unblock_all_signals(void)
     unblock_all_signals();
 }
 
-#if defined(__i386__) 
+#if defined(__i386__)
 #ifndef __HAVE_ARCH_CMPXCHG
-static inline 
-unsigned long __fgl_cmpxchg(volatile void *ptr, unsigned long old,            
-                        unsigned long new, int size)                      
-{                                                                                       
-    unsigned long prev;                                                             
-    switch (size) {                                                                 
-    case 1:                                                                         
+static inline
+unsigned long __fgl_cmpxchg(volatile void *ptr, unsigned long old,
+                        unsigned long new, int size)
+{
+    unsigned long prev;
+    switch (size) {
+    case 1:
         __asm__ __volatile__(LOCK_PREFIX "cmpxchgb %b1,%2"
                              : "=a"(prev)
                              : "q"(new), "m"(*__xg(ptr)), "0"(old)
@@ -1551,7 +1551,7 @@ struct inode* ATI_API_CALL __ke_get_file_inode(struct file* filp)
  */
 KCL_TYPE_Pid ATI_API_CALL KCL_GetPid(void)
 {
-    return current->pid; 
+    return current->pid;
 }
 
 /** /brief Return the current Thread Group ID
@@ -1559,7 +1559,7 @@ KCL_TYPE_Pid ATI_API_CALL KCL_GetPid(void)
  */
 KCL_TYPE_Pid ATI_API_CALL KCL_GetTgid(void)
 {
-    return current->tgid; 
+    return current->tgid;
 }
 
 /** /brief Return the effective user ID
@@ -1655,7 +1655,7 @@ static int KCL_MAP_KernelConfigParam[] =
     1
 #else
     0
-#endif 
+#endif
 };
 
 /** /brief Check whether a kernel configuration parameter is defined
@@ -1718,13 +1718,13 @@ unsigned long ATI_API_CALL __ke_get_resource_start(__ke_pci_dev_t *dev, unsigned
 #if defined(__x86_64__) || defined(__ia64__)
 void* ATI_API_CALL __ke_pci_alloc_consistent(__ke_pci_dev_t* dev, int size, void *dma_handle)
 {
-	return (pci_alloc_consistent( (struct pci_dev*)(void *)dev, size, dma_handle)); 
+	return (pci_alloc_consistent( (struct pci_dev*)(void *)dev, size, dma_handle));
 }
 
 void ATI_API_CALL __ke_pci_free_consistent(__ke_pci_dev_t* dev, int size, unsigned long cpu_addr,
 						 unsigned int dma_handle)
 {
-	pci_free_consistent( (struct pci_dev*)(void *)dev, size, (void *)cpu_addr, 
+	pci_free_consistent( (struct pci_dev*)(void *)dev, size, (void *)cpu_addr,
 		(unsigned long)dma_handle);
 }
 #endif // __ia64__
@@ -1748,7 +1748,7 @@ static int KCL_MAP_ErrorCode[] =
 
 /** \brief This function maps OS independent error conditions to OS defined error codes
  *  \param errcode OS independent error condition code
- *  \return OS kernel defined error code corresponding to the requested error condition 
+ *  \return OS kernel defined error code corresponding to the requested error condition
  */
 int ATI_API_CALL KCL_GetErrorCode(KCL_ENUM_ErrorCode errcode)
 {
@@ -1766,7 +1766,7 @@ int ATI_API_CALL KCL_GetErrorCode(KCL_ENUM_ErrorCode errcode)
 int ATI_API_CALL firegl_get_user_ptr(u32 *src, void **dst)
 {
   unsigned long temp;
-  int err = get_user(temp, src); 
+  int err = get_user(temp, src);
   *dst = (void*) temp;
   return err;
 }
@@ -1906,7 +1906,7 @@ void ATI_API_CALL __ke_atomic_set(void* v, int val)
 
 int ATI_API_CALL __ke_atomic_dec_and_test(void* v)
 {
-    return atomic_dec_and_test((atomic_t*)v); 
+    return atomic_dec_and_test((atomic_t*)v);
 }
 
 /*****************************************************************************/
@@ -2006,19 +2006,19 @@ void ATI_API_CALL __ke_print_debug(const char* fmt, ...)
 #endif
 
 #ifdef _KE_SERIAL_DEBUG
-// To enable serial port debug message dumping,just define _KE_SERIAL_DEBUG in firegl_public.h file. 
-// Connect two PC with a null modern serial cable. run Hyper ternimal on the remote machine. 
-// It's useful to debug resume if network not works properly and serial port is not recovered 
+// To enable serial port debug message dumping,just define _KE_SERIAL_DEBUG in firegl_public.h file.
+// Connect two PC with a null modern serial cable. run Hyper ternimal on the remote machine.
+// It's useful to debug resume if network not works properly and serial port is not recovered
 // properly when fglrx resume hook is called...
- 
- 
+
+
 #define SER_DATA_PORT       0x3f8
 #define SER_INT_CTRL_PORT   SER_DATA_PORT + 1
 #define SER_INT_STAT_PORT   SER_DATA_PORT + 2
 #define SER_LINE_CTRL_PORT  SER_DATA_PORT + 3
 #define SER_MODEM_CTRL_PORT SER_DATA_PORT + 4
 #define SER_LINE_STAT_PORT  SER_DATA_PORT + 5
-    
+
 void ATI_API_CALL __ke_printc(char c)
 {
      while((inb(SER_LINE_STAT_PORT) & 0x20) == 0 ); //wait until Transmitter Holding Register Empty
@@ -2028,7 +2028,7 @@ void ATI_API_CALL __ke_printc(char c)
 void ATI_API_CALL __ke_printstr(const char *str)
 {
     int len = strlen(str);
-    while(len--)__ke_printc(*str++);  
+    while(len--)__ke_printc(*str++);
 }
 
 int ATI_API_CALL __ke_SerPrint(const char *format, ...)
@@ -2041,26 +2041,26 @@ int ATI_API_CALL __ke_SerPrint(const char *format, ...)
     vsprintf(buffer, format, ap);
 
     va_end(ap);
-    
+
     __ke_printstr(buffer);
-    
+
     return 0;
 }
 void ATI_API_CALL __ke_SetSerialPort()
 {
     DRM_INFO("setup serial port\n");
-    outb(0x00,  SER_INT_CTRL_PORT);   // Turn off interrupts 
-
-    outb(0x80,  SER_LINE_CTRL_PORT);  // SET DLAB ON 
-    outb(0x01,  SER_DATA_PORT);  // Set Baud rate - Divisor Latch Low Byte 
-                             // 0x01 = 115,200 ,0x02 =  57,600,  0x06 =  19,200 BPS, 0x0C =   9,600 BPS  
-    outb(0x00,  SER_DATA_PORT + 1);  // Set Baud rate - Divisor Latch High Byte 
-    outb(0x03,  SER_LINE_CTRL_PORT); // reset DLAB ,8 Bits, No Parity, 1 Stop Bit 
-    outb(0xC7,  SER_DATA_PORT + 2);  // FIFO Control Register 
+    outb(0x00,  SER_INT_CTRL_PORT);   // Turn off interrupts
+
+    outb(0x80,  SER_LINE_CTRL_PORT);  // SET DLAB ON
+    outb(0x01,  SER_DATA_PORT);  // Set Baud rate - Divisor Latch Low Byte
+                             // 0x01 = 115,200 ,0x02 =  57,600,  0x06 =  19,200 BPS, 0x0C =   9,600 BPS
+    outb(0x00,  SER_DATA_PORT + 1);  // Set Baud rate - Divisor Latch High Byte
+    outb(0x03,  SER_LINE_CTRL_PORT); // reset DLAB ,8 Bits, No Parity, 1 Stop Bit
+    outb(0xC7,  SER_DATA_PORT + 2);  // FIFO Control Register
     outb(0x0b,  SER_DATA_PORT + 4);  // Turn on DTR, RTS, and OUT2
-  
+
     __ke_printstr("serial port 0x3f8 is set ready for message print out \n");
-}  
+}
 #endif
 
 /** \brief Get number of available RAM pages
@@ -2241,7 +2241,7 @@ void *ATI_API_CALL __ke_vmalloc_to_addr(void *vmalloc_addr)
     struct page *page = NULL;
 
     page = vmalloc_to_page(vmalloc_addr);
-    if(page == NULL) 
+    if(page == NULL)
     {
         __KE_ERROR("__ke_vmalloc_to_addr: invalid page!");
         return NULL;
@@ -2283,7 +2283,7 @@ int ATI_API_CALL __ke_do_munmap(unsigned long addr, unsigned long len)
     retcode = do_munmap(current->mm,
                         addr,
                         len);
-#endif                        
+#endif
     up_write(&current->mm->mmap_sem);
     return retcode;
 }
@@ -2327,10 +2327,10 @@ long long ATI_API_CALL __divdi3(long long n, long long base)
        minus = !minus;
     }
     else
-    {   
+    {
        ubase = base;
     }
-    
+
     do_div(un, ubase);
     return (minus? -un : un);
 }
@@ -2360,7 +2360,7 @@ long long ATI_API_CALL __moddi3(long long n, long long base)
     else
     {
        ubase = base;
-    }   
+    }
 
     rem = do_div(un, ubase);
     return (minus? -rem : rem);
@@ -2391,7 +2391,7 @@ void* ATI_API_CALL __ke_vmap(unsigned long *pagelist, unsigned int count)
     vaddr = (void *) vmap(pages, count);
 #else
 #ifdef VM_MAP
-    vaddr = (void *) vmap(pages, count, VM_MAP, PAGE_KERNEL); 
+    vaddr = (void *) vmap(pages, count, VM_MAP, PAGE_KERNEL);
 #else
     vaddr = (void *) vmap(pages, count, 0, PAGE_KERNEL);
 #endif
@@ -2447,7 +2447,7 @@ void ATI_API_CALL __ke_vunmap(void* addr)
 }
 #endif  // defined(VM_MAP) || defined(vunmap)
 
-/** \brief Reserve a memory page 
+/** \brief Reserve a memory page
  *
  * \param pt Kernel logical address of the page
  *
@@ -2459,7 +2459,7 @@ void ATI_API_CALL KCL_ReserveMemPage(void* pt)
     SetPageReserved(virt_to_page((unsigned long)pt));
 }
 
-/** \brief Unreserve a memory page 
+/** \brief Unreserve a memory page
  *
  * \param pt Kernel logical address of the page
  *
@@ -2471,7 +2471,7 @@ void ATI_API_CALL KCL_UnreserveMemPage(void* pt)
     ClearPageReserved(virt_to_page((unsigned long)pt));
 }
 
-/** \brief Lock a memory page 
+/** \brief Lock a memory page
  *
  * \param pt Kernel logical address of the page
  *
@@ -2480,14 +2480,14 @@ void ATI_API_CALL KCL_UnreserveMemPage(void* pt)
  */
 void ATI_API_CALL KCL_LockMemPage(void* pt)
 {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15) 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)
     SetPageReserved(virt_to_page((unsigned long)pt));
 #else
     lock_page(virt_to_page((unsigned long)pt));
 #endif
 }
 
-/** \brief Unlock a memory page 
+/** \brief Unlock a memory page
  *
  * \param pt Kernel logical address of the page
  *
@@ -2496,7 +2496,7 @@ void ATI_API_CALL KCL_LockMemPage(void* pt)
  */
 void ATI_API_CALL KCL_UnlockMemPage(void* pt)
 {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15) 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)
     ClearPageReserved(virt_to_page((unsigned long)pt));
 #else
     unlock_page(virt_to_page((unsigned long)pt));
@@ -2521,7 +2521,7 @@ void* ATI_API_CALL __ke_get_vmptr( struct _agp_memory* memory )
 	return memory->vmptr;
 }
 #endif
-                              
+
 void* ATI_API_CALL __ke_ioremap(unsigned long offset, unsigned long size)
 {
     return ioremap(offset, size);
@@ -2592,7 +2592,7 @@ void ATI_API_CALL KCL_flush_tlb_onepage(struct vm_area_struct * vma, unsigned lo
 {
 /*Some kernel developer removed the export of symbol "flush_tlb_page" on 2.6.25 x86_64 SMP kernel.
   Define a simple version here.*/
-#if defined(__x86_64__) && defined(__SMP__) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)) 
+#if defined(__x86_64__) && defined(__SMP__) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25))
     on_each_cpu(KCL_flush_tlb_one, &va, 1, 1);
 #else
     flush_tlb_page(vma, va);
@@ -2649,9 +2649,9 @@ void ATI_API_CALL __ke_put_vm_page_table(unsigned long page_addr)
 static inline int ptep_clear_flush_dirty(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep)
 {
     int ret = 0;
-    
+
     DBG_ENTER("0x%08X, 0x%08X, 0x%08X->0x%08X", vma, addr, ptep, *ptep);
-    
+
     if (pte_dirty(*ptep))
     {
 #ifdef __x86_64__
@@ -2666,19 +2666,19 @@ static inline int ptep_clear_flush_dirty(struct vm_area_struct *vma, unsigned lo
         {
             pte_update(vma->vm_mm, addr, ptep);
         }
-#endif        
+#endif
     }
 
     DBG_TRACE("0x%08X->0x%08X", ptep, *ptep);
-    
+
     // Flush Translation Lookaside Buffers
     if (ret)
     {
         KCL_flush_tlb_onepage(vma,addr);
     }
-    
+
     DBG_LEAVE("%d", ret);
-    
+
     return ret;
 }
 #endif
@@ -2705,7 +2705,7 @@ static inline int ptep_clear_flush_dirty(struct vm_area_struct *vma, unsigned lo
  * the virtual address
  *
  * \param mm Pointer to the memory descriptor structure
- * \param virtual_addr Virtual address 
+ * \param virtual_addr Virtual address
  *
  * \return Old value of the "dirty" flag on success or negative on error
  *
@@ -2961,7 +2961,7 @@ int ATI_API_CALL __ke_config_mtrr(void)
        return 0;
 #else
     return 1;
-#endif    
+#endif
 #else /* !CONFIG_MTRR */
     return 0;
 #endif /* !CONFIG_MTRR */
@@ -2987,7 +2987,7 @@ int ATI_API_CALL __ke_mtrr_del(int reg, unsigned long base, unsigned long size)
 
 int ATI_API_CALL __ke_has_vmap(void)
 {
-// We disable vmap for 2.4.x kernel to work around the big memory( > 4GB ) issue. 
+// We disable vmap for 2.4.x kernel to work around the big memory( > 4GB ) issue.
 #if defined(VM_MAP) || defined(vunmap)
     return 1;
 #else
@@ -3009,7 +3009,7 @@ int ATI_API_CALL __ke_no_iommu(void)
 {
     return 0;
 }
-#endif 
+#endif
 
 /*****************************************************************************/
 
@@ -3066,7 +3066,7 @@ unsigned int ATI_API_CALL __ke_pci_get_func(__ke_pci_dev_t* pcidev)
 {
     struct pci_dev* dev = (struct pci_dev*)pcidev;
     return PCI_FUNC(dev->devfn);
-}    
+}
 
 __ke_dma_addr_t ATI_API_CALL __ke_pci_map_single (__ke_pci_dev_t *pdev, void *buffer, __ke_size_t size, int direction)
 {
@@ -3153,7 +3153,7 @@ static irqreturn_t ke_irq_handler_wrap(int irq, void *arg1)
     return IRQ_HANDLED;
 }
 #endif
-            
+
 int ATI_API_CALL __ke_request_irq(unsigned int irq,
     void (*ATI_API_CALL handler)(int, void *, void *),
     const char *dev_name, void *dev_id)
@@ -3166,7 +3166,7 @@ int ATI_API_CALL __ke_request_irq(unsigned int irq,
         SA_SHIRQ,
 #else
         IRQF_SHARED,
-#endif                
+#endif
         dev_name,
         dev_id);
 }
@@ -3203,12 +3203,12 @@ int ATI_API_CALL __ke_agp_memory_get_page_count(struct _agp_memory* agpmem)
     return (int)(agpmem->page_count);
 }
 
-void ATI_API_CALL __ke_agp_memory_get_memory(struct _agp_memory* agpmem, 
+void ATI_API_CALL __ke_agp_memory_get_memory(struct _agp_memory* agpmem,
                                              unsigned long **memory_ptr)
 {
     __KE_DEBUG("[%s] agpmem=0x%016lx agpmem->memory=0x%016lx [0]=0x%016x",
-               __FUNCTION__, 
-               (unsigned long)agpmem, 
+               __FUNCTION__,
+               (unsigned long)agpmem,
                (unsigned long)agpmem->memory,
                (agpmem->memory)[0]);
 
@@ -3217,18 +3217,9 @@ void ATI_API_CALL __ke_agp_memory_get_memory(struct _agp_memory* agpmem,
 
 /*****************************************************************************/
 
-#ifndef NOPAGE_SIGBUS
-#define NOPAGE_SIGBUS 0
-#endif /* !NOPAGE_SIGBUS */
-
 typedef struct page mem_map_t;
 typedef mem_map_t *vm_nopage_ret_t;
 
-static __inline__ vm_nopage_ret_t do_vm_nopage(struct vm_area_struct* vma,
-                                                     unsigned long address)
-{
-    return 0;   /* Disallow mremap */
-}
 
 #ifdef __AGP__BUILTIN__
 #ifdef __ia64__
@@ -3253,19 +3244,20 @@ static __inline__ vm_nopage_ret_t do_vm_cant_nopage(struct vm_area_struct* vma,
 			return page;
 		}
 	}
-	return NOPAGE_SIGBUS;		/* Disallow mremap */
+	return VM_FAULT_SIGBUS;		/* Disallow mremap */
 }
 
 #endif /* __ia64__ */
 #endif /* __AGP__BUILTIN__ */
 
 
-static __inline__ vm_nopage_ret_t do_vm_shm_nopage(struct vm_area_struct* vma,
-                                                   unsigned long address)
+static __inline__ int do_vm_shm_nopage(struct vm_area_struct* vma,
+				       struct vm_fault *vmf)
 {
     pgd_t* pgd_p;
     pmd_t* pmd_p;
     pte_t  pte;
+    unsigned long address = (unsigned long)vmf->virtual_address;
     unsigned long vma_offset;
     unsigned long pte_linear;
     mem_map_t* pMmPage;
@@ -3294,7 +3286,7 @@ static __inline__ vm_nopage_ret_t do_vm_shm_nopage(struct vm_area_struct* vma,
             (unsigned long)__ke_vm_offset(vma));
 
     if (address > vma->vm_end)
-        return NOPAGE_SIGBUS; /* address is out of range */
+        return VM_FAULT_SIGBUS; /* address is out of range */
 
     /*  Calculate offset into VMA */
     vma_offset = address - vma->vm_start;
@@ -3306,7 +3298,7 @@ static __inline__ vm_nopage_ret_t do_vm_shm_nopage(struct vm_area_struct* vma,
     pte_linear = firegl_get_addr_from_vm(vma);
     if (!pte_linear)
     {
-        return NOPAGE_SIGBUS; /* bad address */
+        return VM_FAULT_SIGBUS; /* bad address */
     }
     pte_linear += vma_offset;
 
@@ -3334,7 +3326,9 @@ static __inline__ vm_nopage_ret_t do_vm_shm_nopage(struct vm_area_struct* vma,
 
     //  __KE_DEBUG3("vm-address 0x%08lx => kernel-page-address 0x%p\n",
     //    address, page_address(pMmPage));
-    return pMmPage;
+    vmf->page = pMmPage;
+
+    return 0;
 }
 
 /*
@@ -3343,8 +3337,10 @@ static __inline__ vm_nopage_ret_t do_vm_shm_nopage(struct vm_area_struct* vma,
       (which is one ore more pages in size)
 
 */
-static __inline__ vm_nopage_ret_t do_vm_dma_nopage(struct vm_area_struct* vma, unsigned long address)
+static __inline__ int do_vm_dma_nopage(struct vm_area_struct* vma,
+				       struct vm_fault *vmf)
 {
+    unsigned long address = (unsigned long) vmf->virtual_address;
     unsigned long kaddr;
     mem_map_t* pMmPage;
 
@@ -3360,7 +3356,7 @@ static __inline__ vm_nopage_ret_t do_vm_dma_nopage(struct vm_area_struct* vma, u
     kaddr = firegl_get_addr_from_vm(vma);
     if (!kaddr)
     {
-        return NOPAGE_SIGBUS; /* bad address */
+        return VM_FAULT_SIGBUS; /* bad address */
     }
     kaddr += (address - vma->vm_start);
 
@@ -3372,19 +3368,23 @@ static __inline__ vm_nopage_ret_t do_vm_dma_nopage(struct vm_area_struct* vma, u
     // with drm_alloc_pages, which marks all pages as reserved. Reserved
     // pages' usage count is not decremented by the kernel during unmap!!!
     //
-    // For kernel >= 2.6.15, We should reenable this, because the VM sub-system 
-    // will decrement the pages' usage count even for the pages marked as reserved 
+    // For kernel >= 2.6.15, We should reenable this, because the VM sub-system
+    // will decrement the pages' usage count even for the pages marked as reserved
     // 								- MC.
     get_page(pMmPage); /* inc usage count of page */
 #endif
 
     __KE_DEBUG3("vm-address 0x%08lx => kernel-page-address 0x%p\n",
         address, page_address(pMmPage));
-    return pMmPage;
+    vmf->page = pMmPage;
+
+    return 0;
 }
 
-static __inline__ vm_nopage_ret_t do_vm_kmap_nopage(struct vm_area_struct* vma, unsigned long address)
+static __inline__ int do_vm_kmap_nopage(struct vm_area_struct* vma,
+					struct vm_fault *vmf)
 {
+    unsigned long address = (unsigned long) vmf->virtual_address;
     unsigned long kaddr;
     mem_map_t* pMmPage;
 
@@ -3394,13 +3394,14 @@ static __inline__ vm_nopage_ret_t do_vm_kmap_nopage(struct vm_area_struct* vma,
     if ((pMmPage = (mem_map_t*) firegl_get_pagetable_page_from_vm(vma)))
     {
         get_page(pMmPage);
-        return pMmPage;
+	vmf->page = pMmPage;
+        return 0;
     }
 
     kaddr = firegl_get_addr_from_vm(vma);
     if (!kaddr)
     {
-        return NOPAGE_SIGBUS; /* bad address */
+        return VM_FAULT_SIGBUS; /* bad address */
     }
     kaddr += (address - vma->vm_start);
 
@@ -3413,50 +3414,52 @@ static __inline__ vm_nopage_ret_t do_vm_kmap_nopage(struct vm_area_struct* vma,
 
     __KE_DEBUG3("vm-address 0x%08lx => kernel-page-address 0x%p\n", address, page_address(pMmPage));
 
-    return pMmPage;
+    vmf->page = pMmPage;
+    return 0;
 }
 
-/** 
+/**
  **
- **  This routine is intented to locate the page table through the 
+ **  This routine is intented to locate the page table through the
  **  pagelist table created earlier in dev-> pcie
  **/
-static __inline__ vm_nopage_ret_t do_vm_pcie_nopage(struct vm_area_struct* vma,
-                                                         unsigned long address)
+static __inline__ int do_vm_pcie_nopage(struct vm_area_struct* vma,
+					struct vm_fault *vmf)
 {
 
+    unsigned long address = (unsigned long)vmf->virtual_address;
     unsigned long vma_offset;
-    unsigned long i; 
+    unsigned long i;
     mem_map_t* pMmPage;
     struct firegl_pcie_mem* pciemem;
     unsigned long* pagelist;
-    
+
     drm_device_t *dev = (drm_device_t *)firegl_get_dev_from_vm(vma);
     if (dev == NULL)
     {
         __KE_ERROR("dev is NULL\n");
-        return NOPAGE_SIGBUS;
+        return VM_FAULT_SIGBUS;
     }
 
     if (address > vma->vm_end)
     {
         __KE_ERROR("address out of range\n");
-        return NOPAGE_SIGBUS; /* address is out of range */
+        return VM_FAULT_SIGBUS; /* address is out of range */
     }
     pciemem = firegl_get_pciemem_from_addr ( vma, address);
     if (pciemem == NULL)
     {
         __KE_ERROR("No pciemem found! \n");
-        return NOPAGE_SIGBUS;
-    }    
+        return VM_FAULT_SIGBUS;
+    }
     pagelist = firegl_get_pagelist_from_vm(vma);
 
-    if (pagelist == NULL) 
+    if (pagelist == NULL)
     {
         __KE_ERROR("No pagelist! \n");
-        return NOPAGE_SIGBUS;
+        return VM_FAULT_SIGBUS;
     }
-     
+
     /** Find offset in  vma */
     vma_offset = address - vma->vm_start;
     /** Which entry in the pagelist */
@@ -3468,15 +3471,17 @@ static __inline__ vm_nopage_ret_t do_vm_pcie_nopage(struct vm_area_struct* vma,
     if (page_address(pMmPage) == 0x0)
     {
         __KE_ERROR("Invalid page address\n");
-        return NOPAGE_SIGBUS;
+        return VM_FAULT_SIGBUS;
     }
-    return pMmPage;
+
+    vmf->page = pMmPage;
+    return 0;
 }
 
-static __inline__ vm_nopage_ret_t do_vm_gart_nopage(struct vm_area_struct* vma,
-                                                    unsigned long address)
+static __inline__ int do_vm_gart_nopage(struct vm_area_struct* vma,
+					struct vm_fault *vmf)
 {
-
+    unsigned long address = (unsigned long) vmf->virtual_address;
     unsigned long page_addr;
     unsigned long offset;
     struct page *page;
@@ -3484,36 +3489,31 @@ static __inline__ vm_nopage_ret_t do_vm_gart_nopage(struct vm_area_struct* vma,
     if (address > vma->vm_end)
     {
         __KE_ERROR("Invalid virtual address\n");
-        return NOPAGE_SIGBUS;   /* Disallow mremap */
-    }          
+        return VM_FAULT_SIGBUS;   /* Disallow mremap */
+    }
 
     offset      = address - vma->vm_start;
-#ifdef FIREGL_CF_SUPPORT    
+#ifdef FIREGL_CF_SUPPORT
     page_addr   = mc_heap_get_page_addr(vma, offset);
 #else
     page_addr   = firegl_cmmqs_get_pageaddr_from_vm(vma, offset);
-#endif    
+#endif
     if( !page_addr)
     {
         __KE_ERROR("Invalid page address\n");
-        return NOPAGE_SIGBUS;   /* Disallow mremap */
+        return VM_FAULT_SIGBUS;   /* Disallow mremap */
     }
     page        = virt_to_page(page_addr);
     get_page(page);
 
-    return page;
+    vmf->page = page;
+    return 0;
 }
 
-
-
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
-
-static vm_nopage_ret_t vm_nopage(struct vm_area_struct* vma,
-                                 unsigned long address,
-                                 int *type)
+static int vm_nopage(struct vm_area_struct* vma,
+		     struct vm_fault *vmf)
 {
-    if (type) *type = VM_FAULT_MINOR;
-        return do_vm_nopage(vma, address);
+	return VM_FAULT_SIGBUS;
 }
 
 #ifdef __AGP__BUILTIN__
@@ -3545,91 +3545,10 @@ static vm_nopage_ret_t vm_cant_nopage(struct vm_area_struct* vma,
     (which is one or more pages in size)
 
  */
-static vm_nopage_ret_t vm_shm_nopage(struct vm_area_struct* vma,
-                                     unsigned long address,
-                                     int *type)
-{
-    if (type) *type = VM_FAULT_MINOR;
-        return do_vm_shm_nopage(vma, address);
-}
-
-/*
-
-    This routine is intended to remap addresses of a OpenGL context
-      (which is one ore more pages in size)
-
-*/
-static vm_nopage_ret_t vm_dma_nopage(struct vm_area_struct* vma,
-                                     unsigned long address,
-                                     int *type)
-{
-    if (type) *type = VM_FAULT_MINOR;
-        return do_vm_dma_nopage(vma, address);
-}
-
-static vm_nopage_ret_t vm_kmap_nopage(struct vm_area_struct* vma,
-                                     unsigned long address,
-                                     int *type)
-{
-    if (type) *type = VM_FAULT_MINOR;
-        return do_vm_kmap_nopage(vma, address);
-}
-
-static vm_nopage_ret_t vm_pcie_nopage(struct vm_area_struct* vma,
-                                     unsigned long address,
-                                     int *type)
-{  
-       return do_vm_pcie_nopage(vma, address);
-}
-
-static vm_nopage_ret_t vm_gart_nopage(struct vm_area_struct* vma,
-                                      unsigned long address, 
-                                      int *type)
-{
-       return do_vm_gart_nopage(vma, address);
-}
-
-#else   /* LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,0) */
-
-static vm_nopage_ret_t vm_nopage(struct vm_area_struct* vma,
-                                 unsigned long address,
-                                 int write_access)
-{
-    return do_vm_nopage(vma, address);
-}
-
-#ifdef __AGP__BUILTIN__
-#ifdef __ia64__
-
-
-static vm_nopage_ret_t vm_cant_nopage(struct vm_area_struct* vma,
-                                 unsigned long address,
-                                 int write_access)
-{
-    return do_vm_cant_nopage(vma, address);
-}
-#endif /* __ia64__ */
-#endif /* __AGP__BUILTIN__ */
-
-/*
-
-    This function is called when a page of a mmap()'ed area is not currently
-    visible in the specified VMA.
-    Return value is the associated physical address for the requested page.
-    (If not implemented, then the kernel default routine would allocate a new,
-     zeroed page for servicing us)
-
-    Possible errors: SIGBUS, OutOfMem
-
-    This routine is intended to remap addresses of SHM SAREA
-    (which is one or more pages in size)
-
- */
-static vm_nopage_ret_t vm_shm_nopage(struct vm_area_struct* vma,
-                                     unsigned long address,
-                                     int write_access)
+static int vm_shm_nopage(struct vm_area_struct* vma,
+			 struct vm_fault *vmf)
 {
-    return do_vm_shm_nopage(vma, address);
+        return do_vm_shm_nopage(vma, vmf);
 }
 
 /*
@@ -3638,37 +3557,30 @@ static vm_nopage_ret_t vm_shm_nopage(struct vm_area_struct* vma,
       (which is one ore more pages in size)
 
 */
-static vm_nopage_ret_t vm_dma_nopage(struct vm_area_struct* vma,
-                                     unsigned long address,
-                                     int write_access)
+static int vm_dma_nopage(struct vm_area_struct* vma,
+			 struct vm_fault *vmf)
 {
-     return do_vm_dma_nopage(vma, address);
+        return do_vm_dma_nopage(vma, vmf);
 }
 
-static vm_nopage_ret_t vm_kmap_nopage(struct vm_area_struct* vma,
-                                     unsigned long address,
-                                     int write_access)
+static int vm_kmap_nopage(struct vm_area_struct* vma,
+			  struct vm_fault *vmf)
 {
-     return do_vm_kmap_nopage(vma, address);
+        return do_vm_kmap_nopage(vma, vmf);
 }
 
-static vm_nopage_ret_t vm_pcie_nopage(struct vm_area_struct* vma,
-                                     unsigned long address,
-                                     int write_access)
+static int vm_pcie_nopage(struct vm_area_struct* vma,
+			  struct vm_fault *vmf)
 {
-        return do_vm_pcie_nopage(vma, address);
+	return do_vm_pcie_nopage(vma, vmf);
 }
 
-static vm_nopage_ret_t vm_gart_nopage(struct vm_area_struct* vma,
-                                      unsigned long address, 
-                                      int *type)
+static int vm_gart_nopage(struct vm_area_struct* vma,
+			  struct vm_fault *vmf)
 {
-       return do_vm_gart_nopage(vma, address);
+       return do_vm_gart_nopage(vma, vmf);
 }
 
-
-#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0) */
-
 void* ATI_API_CALL __ke_vma_file_priv(struct vm_area_struct* vma)
 {
     return vma->vm_file->private_data;
@@ -3718,7 +3630,7 @@ char* ATI_API_CALL __ke_vm_page_prot_str(struct vm_area_struct* vma, char* buf)
     *(buf + i++) = pgprot & _PAGE_DIRTY    ? 'd' : '-';
     *(buf + i++) = pgprot & _PAGE_PSE      ? 'm' : 'k';
     *(buf + i++) = pgprot & _PAGE_GLOBAL   ? 'g' : 'l';
-#endif /* __i386__ */		
+#endif /* __i386__ */
     *(buf + i++) = 0;
 
     return buf;
@@ -3747,9 +3659,9 @@ char *__ke_pte_phys_addr_str(pte_t pte, char *buf, __ke_dma_addr_t* phys_address
     return buf;
 }
 
-char* ATI_API_CALL __ke_vm_phys_addr_str(struct vm_area_struct* vma, 
-                            char* buf, 
-                            unsigned long virtual_addr, 
+char* ATI_API_CALL __ke_vm_phys_addr_str(struct vm_area_struct* vma,
+                            char* buf,
+                            unsigned long virtual_addr,
                             __ke_dma_addr_t* phys_address)
 {
     pgd_t* pgd_p;
@@ -3773,7 +3685,7 @@ void ip_drm_vm_close(struct vm_area_struct* vma)
 
 static struct vm_operations_struct vm_ops =
 {
-    nopage:  vm_nopage,
+    fault:   vm_nopage,
     open:    ip_drm_vm_open,
     close:   ip_drm_vm_close,
 };
@@ -3791,42 +3703,42 @@ static struct vm_operations_struct vm_cant_ops =
 
 static struct vm_operations_struct vm_shm_ops =
 {
-    nopage:  vm_shm_nopage,
+    fault:   do_vm_shm_nopage,
     open:    ip_drm_vm_open,
     close:   ip_drm_vm_close,
 };
 
 static struct vm_operations_struct vm_pci_bq_ops =
 {
-    nopage:  vm_dma_nopage,
+    fault:   vm_dma_nopage,
     open:    ip_drm_vm_open,
     close:   ip_drm_vm_close,
 };
 
 static struct vm_operations_struct vm_ctx_ops =
 {
-    nopage:  vm_dma_nopage,
+    fault:   vm_dma_nopage,
     open:    ip_drm_vm_open,
     close:   ip_drm_vm_close,
 };
 
-static struct vm_operations_struct vm_pcie_ops = 
+static struct vm_operations_struct vm_pcie_ops =
 {
-    nopage:  vm_pcie_nopage,
+    fault:   vm_pcie_nopage,
     open:    ip_drm_vm_open,
     close:   ip_drm_vm_close,
 };
 
 static struct vm_operations_struct vm_kmap_ops =
 {
-    nopage:  vm_kmap_nopage,
+    fault:   vm_kmap_nopage,
     open:    ip_drm_vm_open,
     close:   ip_drm_vm_close,
 };
 
 static struct vm_operations_struct vm_gart_ops =
 {
-    nopage:  vm_gart_nopage,
+    fault:   vm_gart_nopage,
     open:    ip_drm_vm_open,
     close:   ip_drm_vm_close,
 };
@@ -3835,14 +3747,14 @@ static struct vm_operations_struct vm_gart_ops =
 #ifndef __ia64__
 static struct vm_operations_struct vm_agp_bq_ops =
 {
-    nopage:  vm_nopage,
+    fault:   vm_nopage,
     open:    ip_drm_vm_open,
     close:   ip_drm_vm_close,
 };
-#else		
+#else
 static struct vm_operations_struct vm_cant_agp_bq_ops =
 {
-    nopage:  vm_cant_nopage,
+    fault:   vm_cant_nopage,
     open:    ip_drm_vm_open,
     close:   ip_drm_vm_close,
 };
@@ -3877,19 +3789,19 @@ int ATI_API_CALL __ke_vm_map(struct file* filp,
 #ifdef __i386__
                 if (boot_cpu_data.x86 > 3)
                 {
-#ifdef FIREGL_USWC_SUPPORT                
+#ifdef FIREGL_USWC_SUPPORT
                     if (!firegl_pat_enabled)
-#endif                    
+#endif
                     {
                         pgprot_val(vma->vm_page_prot) |= _PAGE_PCD;
                         pgprot_val(vma->vm_page_prot) &= ~_PAGE_PWT;
                     }
-#ifdef FIREGL_USWC_SUPPORT                    
+#ifdef FIREGL_USWC_SUPPORT
                     else
                     {
                         vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
-                    }    
-#endif                    
+                    }
+#endif
                 }
 #endif /* __i386__ */
 #ifdef __ia64__
@@ -3908,7 +3820,7 @@ int ATI_API_CALL __ke_vm_map(struct file* filp,
             }
 			break;
 
-#ifdef FIREGL_USWC_SUPPORT                
+#ifdef FIREGL_USWC_SUPPORT
         case __KE_ADPT_REG:
 			{
 #ifdef __ia64__
@@ -3928,7 +3840,7 @@ int ATI_API_CALL __ke_vm_map(struct file* filp,
                     }
                     else
                     {
-                        vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 
+                        vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
                     }
                 }
 #endif /* __i386__ */
@@ -3947,7 +3859,7 @@ int ATI_API_CALL __ke_vm_map(struct file* filp,
             vma->vm_ops = &vm_ops;
             }
 			break;
-#endif                    
+#endif
 
         case __KE_SHM:
             vma->vm_flags |= VM_SHM | VM_RESERVED; /* Don't swap */
@@ -3981,7 +3893,7 @@ int ATI_API_CALL __ke_vm_map(struct file* filp,
 
 #ifdef __AGP__BUILTIN__
         case __KE_AGP:
-            // if(dev->agp->cant_use_aperture == 1) 
+            // if(dev->agp->cant_use_aperture == 1)
 #ifdef __ia64__
             {
                 /*
@@ -4005,9 +3917,9 @@ int ATI_API_CALL __ke_vm_map(struct file* filp,
                     if( firegl_pat_enabled )
                     {
                         vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
-                    }    
+                    }
                 }
-#endif                
+#endif
 
                 if (REMAP_PAGE_RANGE(vma,offset))
                 {
@@ -4024,8 +3936,8 @@ int ATI_API_CALL __ke_vm_map(struct file* filp,
 #endif
             break;
         case __KE_AGP_BQS:
-            // if(dev->agp->cant_use_aperture == 1) 
-#ifdef __ia64__			
+            // if(dev->agp->cant_use_aperture == 1)
+#ifdef __ia64__
             {
                 /*
                  * On some systems we can't talk to bus dma address from
@@ -4048,9 +3960,9 @@ int ATI_API_CALL __ke_vm_map(struct file* filp,
                     if( firegl_pat_enabled )
                     {
                        vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
-                    }   
+                    }
                 }
-#endif                
+#endif
 
                 if (REMAP_PAGE_RANGE(vma,offset))
                 {
@@ -4079,15 +3991,15 @@ int ATI_API_CALL __ke_vm_map(struct file* filp,
             break;
 
          case __KE_GART_USWC:
-#ifdef FIREGL_USWC_SUPPORT         
+#ifdef FIREGL_USWC_SUPPORT
             if (boot_cpu_data.x86 > 3)
             {
                 if( firegl_pat_enabled )
                 {
                     vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
-                }    
+                }
             }
-#endif            
+#endif
             // fall through
          case __KE_GART_CACHEABLE:
              vma->vm_flags |= VM_RESERVED;
@@ -4137,7 +4049,7 @@ extern struct _agp_memory *_X(agp_allocate_memory_phys_list)(size_t, u32, u64 *)
 #define FIREGL_agp_backend_release  _X(agp_backend_release)
 #define FIREGL_agp_memory           _X(agp_memory)
 
-unsigned int __ke_firegl_agpgart_inuse = AGPGART_INUSE_NONE;				
+unsigned int __ke_firegl_agpgart_inuse = AGPGART_INUSE_NONE;
 
 #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
 /*****************************************************************************/
@@ -4252,7 +4164,7 @@ static
 int ATI_API_CALL __ke_agpgart_available(__ke_pci_dev_t *pcidev, int use_internal)
 {
     drm_agp_module_stub = &drm_agp;
-    __ke_firegl_agpgart_inuse = KERNEL26_AGPGART_INUSE;	
+    __ke_firegl_agpgart_inuse = KERNEL26_AGPGART_INUSE;
     {
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
         firegl_pci_device = (struct pci_dev*)(void*)pcidev;
@@ -4305,7 +4217,7 @@ int ATI_API_CALL __ke_agp_available(__ke_pci_dev_t *pcidev, int use_internal)
     } else {
          available = __ke_firegl_agpgart_available();
     }
-	
+
     return available;
 }
 
@@ -4410,7 +4322,7 @@ void ATI_API_CALL __ke_agp_copy_info(__ke_agp_kern_info_t* info)
 
     if (AGP_AVAILABLE(copy_info))
     {
-        struct agp_kern_info kern;    
+        struct agp_kern_info kern;
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
         if (firegl_agp_bridge == NULL)
@@ -4508,7 +4420,7 @@ int ATI_API_CALL __ke_agp_enable(unsigned long mode)
 
 int ATI_API_CALL __ke_read_agp_caps_registers(__ke_pci_dev_t* dev, unsigned int *caps)
 {
-    return -EINVAL;	
+    return -EINVAL;
 }
 
 int ATI_API_CALL __ke_agp_acquire(__ke_pci_dev_t* dev)
@@ -4550,9 +4462,9 @@ int ATI_API_CALL __ke_smp_processor_id(void)
 
 /** \brief Runs a function on all other CPUs
  *  \param func_to_call function to be called on all other cpus
- *  \return None 
+ *  \return None
  */
-void ATI_API_CALL KCL_CallFuncOnOtherCpus(firegl_void_routine_t func_to_call) 
+void ATI_API_CALL KCL_CallFuncOnOtherCpus(firegl_void_routine_t func_to_call)
 {
 #ifdef CONFIG_SMP
 	smp_call_function( firegl_smp_func_parameter_wrap, (void*)func_to_call, 0, 1 );
@@ -4659,7 +4571,7 @@ int ATI_API_CALL __ke_has_PSE(void)
 
 int ATI_API_CALL KCL_is_pat_enabled(void)
 {
-   return firegl_pat_enabled; 
+   return firegl_pat_enabled;
 }
 
 static int ATI_API_CALL KCL_has_pat(void)
@@ -4675,7 +4587,7 @@ static void KCL_setup_pat(void *info)
 {
     unsigned long cr0=0, cr4=0;
     unsigned long flags;
-  
+
     local_irq_save(flags);
     cr0 = read_cr0() | 0x40000000;
     write_cr0(cr0);
@@ -4706,7 +4618,7 @@ static void  KCL_restore_pat(void *info)
 {
     unsigned long cr0 = 0, cr4 = 0;
     unsigned long flags;
-  
+
     local_irq_save(flags);
     cr0 = read_cr0() | 0x40000000;
     write_cr0(cr0);
@@ -4718,7 +4630,7 @@ static void  KCL_restore_pat(void *info)
        write_cr4(cr4 & ~X86_CR4_PGE);
     }
      __flush_tlb();
-  
+
     wrmsr(MSR_IA32_CR_PAT,  KCL_orig_pat[0], KCL_orig_pat[1]);
 
     cr0 = read_cr0();
@@ -4741,7 +4653,7 @@ static int ATI_API_CALL KCL_enable_pat(void)
          __KE_INFO("USWC is disabled in module parameters\n");
          return 0;
      }
-     
+
      if (!KCL_has_pat())
      {
         return 0;
@@ -4751,13 +4663,13 @@ static int ATI_API_CALL KCL_enable_pat(void)
 
      for ( i = 0; i < 2; i++ )
      {
-        for (j = 0; j < 4; j ++)    
+        for (j = 0; j < 4; j ++)
         {
             if (((KCL_orig_pat[i] >> (j * 8)) & 0xFF) == 1)
-            { 
+            {
                __KE_ERROR("Pat entry %d is already configured\n", (i+1)*(j+1));
                return 0;
-            } 
+            }
         }
     }
 
@@ -4829,7 +4741,7 @@ typedef struct tag_kasContext_t
 } kasContext_t;
 
 /** \brief KAS context */
-static kasContext_t kasContext; 
+static kasContext_t kasContext;
 
 /** \brief Kernel support required to enable KAS */
 #if defined(cmpxchg)                        && \
@@ -5137,7 +5049,7 @@ unsigned int ATI_API_CALL KAS_Ih_Execute(KAS_IhRoutine_t ih_routine,
     DBG_TRACE("Interrupt handler returned 0x%08X", ret);
 
     kasSetExecutionLevel(orig_level);
-    spin_unlock(&kasContext.lock_ih); 
+    spin_unlock(&kasContext.lock_ih);
 
     DBG_LEAVE("%d", ret);
     return ret;
@@ -5412,7 +5324,7 @@ typedef struct tag_kasSlabCache_t
 #endif
     spinlock_t lock;            /* OS spinlock object protecting the cache */
     unsigned int routine_type;  /* Type of routine the cache might be accessed from */
-    char name[14];              /* Cache object name (kernel 2.4 restricts its length to 19 chars) */
+    char name[24];              /* Cache object name (kernel 2.4 restricts its length to 19 chars) */
 } kasSlabCache_t;
 
 /** \brief Return Slab Cache object size
@@ -5450,7 +5362,8 @@ unsigned int ATI_API_CALL KAS_SlabCache_Initialize(void* hSlabCache,
 
     slabcache_obj->routine_type = access_type;
     spin_lock_init(&(slabcache_obj->lock));
-    sprintf(slabcache_obj->name, "kas(%08X)", (unsigned int)slabcache_obj);
+    snprintf(slabcache_obj->name, sizeof(slabcache_obj->name),
+		"kas(%p)", slabcache_obj);
 
     DBG_TRACE("creating slab object '%s'", slabcache_obj->name);
 
@@ -6366,7 +6279,7 @@ unsigned int ATI_API_CALL KAS_AtomicAddInt(
 
     kas_xadd(puiDestination, iAdd, ret, "l");
 
-    return ret + iAdd; 
+    return ret + iAdd;
 #else
     return 0xDEADC0DE; /* To make compiler happy */
 #endif
@@ -6449,7 +6362,7 @@ long ATI_API_CALL KAS_ScheduleTimeout(long n_jiffies)
 #ifdef FIREGL_CF_SUPPORT
 
 void *ATI_API_CALL KCL_lock_init()
-{   
+{
     spinlock_t *lock;
 
     lock = kmalloc(sizeof(*lock), GFP_KERNEL);
@@ -6461,7 +6374,7 @@ void *ATI_API_CALL KCL_lock_init()
 }
 
 void ATI_API_CALL KCL_lock_deinit(void *plock)
-{   
+{
     if (plock == NULL)
     {
         __KE_ERROR("plock is NULL\n");
diff --git a/firegl_public.h b/firegl_public.h
index fc49d6e..8cc18ed 100644
--- a/firegl_public.h
+++ b/firegl_public.h
@@ -78,7 +78,7 @@ do { \
     if (!pgd_present(*(pgd_p)))	\
     { \
         __KE_ERROR("FATAL ERROR: User queue buffer not present! (pgd)\n"); \
-        return (unsigned long)NOPAGE_SIGBUS;   /* Something bad happened; generate SIGBUS */ \
+        return VM_FAULT_SIGBUS;   /* Something bad happened; generate SIGBUS */ \
         /* alternatively we could generate a NOPAGE_OOM "out of memory" */ \
     } \
 } while(0)
@@ -91,7 +91,7 @@ do { \
     if (!pud_present(*(pud_p)))	\
     { \
         __KE_ERROR("FATAL ERROR: User queue buffer not present! (pud)\n"); \
-        return (unsigned long)NOPAGE_SIGBUS;   /* Something bad happened; generate SIGBUS */ \
+        return VM_FAULT_SIGBUS;   /* Something bad happened; generate SIGBUS */ \
         /* alternatively we could generate a NOPAGE_OOM "out of memory" */ \
     } \
     pmd_p = pmd_offset(pud_p, pte_linear); \
@@ -111,7 +111,7 @@ do { \
     if (!pmd_present(*(pmd_p)))	\
     { \
         __KE_ERROR("FATAL ERROR: User queue buffer not present! (pmd)\n"); \
-        return (unsigned long)NOPAGE_SIGBUS;   /* Something bad happened; generate SIGBUS */ \
+        return VM_FAULT_SIGBUS;   /* Something bad happened; generate SIGBUS */ \
         /* alternatively we could generate a NOPAGE_OOM "out of memory" */ \
     } \
 } while(0)
@@ -157,7 +157,7 @@ do { \
     if (!pte_present(pte)) \
     { \
         __KE_ERROR("FATAL ERROR: User queue buffer not present! (pte)\n"); \
-        return (unsigned long)NOPAGE_SIGBUS;   /* Something bad happened; generate SIGBUS */ \
+        return VM_FAULT_SIGBUS;   /* Something bad happened; generate SIGBUS */ \
         /* alternatively we could generate a NOPAGE_OOM "out of memory" */ \
     } \
 } while(0)
-- 
1.5.6.rc2.45.gdc92c
EOT
 # http://launchpadlibrarian.net/15305524/0004-Linux-2.6.26.x-kernels-support.patch
 [ "$VER" = "8-6" ] && patch -p1 <<'EOT'
From d6ef03ff417eb001653c51112c79e709ba8eaec9 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?=C5=BDilvinas=20Valinskas?= <zilvinas@wilibox.com>
Date: Sat, 14 Jun 2008 03:54:38 +0300
Subject: [PATCH] Linux 2.6.26.x kernels support.
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

o trailing white spaces/tabs removed.
o VMA ->nopage() removed, go for ->fault()
o compiles with warnings ...
o most importantly ... WORKS on 2.6.26-rc6/amd64!

Signed-off-by: Žilvinas Valinskas <zilvinas@wilibox.com>
---
 firegl_public.c |  655 ++++++++++++++++++++++++-------------------------------
 firegl_public.h |    8 +-
 2 files changed, 288 insertions(+), 375 deletions(-)

diff --git a/firegl_public.c b/firegl_public.c
index d71700d..3c8e72a 100644
--- a/firegl_public.c
+++ b/firegl_public.c
@@ -24,13 +24,13 @@
 // ============================================================
 #include <linux/version.h>
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
 #error Kernel versions older than 2.6.0 are no longer supported by this module.
-#endif 
+#endif
 
 #include <linux/autoconf.h>
 
-#if !defined(CONFIG_X86_PC) 
+#if !defined(CONFIG_X86_PC)
 #if !defined(CONFIG_X86_64)
 #if !defined(CONFIG_X86_VOYAGER)
 #if !defined(CONFIG_X86_NUMAQ)
@@ -62,10 +62,10 @@
  * distribution would even include such a kernel patch. */
 #ifdef CONFIG_MEM_MIRROR
 /* Prevent asm/mm_track.h from being included in subsequent
- * kernel headers as that would redefine CONFIG_MEM_MIRROR. */ 
+ * kernel headers as that would redefine CONFIG_MEM_MIRROR. */
 #ifndef CONFIG_X86_64
 #define __I386_MMTRACK_H__
-#define mm_track(ptep)                 
+#define mm_track(ptep)
 #else
 #define __X86_64_MMTRACK_H__
 #define mm_track_pte(ptep)
@@ -93,7 +93,7 @@
 #include <linux/kernel.h>
 #include <linux/fs.h>
 #include <linux/proc_fs.h>
-#include <linux/init.h>
+//#include <linux/init.h>
 #include <linux/file.h>
 #include <linux/pci.h>
 #include <linux/wait.h>
@@ -151,8 +151,8 @@
 #include "linux/freezer.h"
 #endif
 
-//  For 2.6.18 or higher, the UTS_RELEASE is defined in the linux/utsrelease.h. 
-#ifndef UTS_RELEASE 
+//  For 2.6.18 or higher, the UTS_RELEASE is defined in the linux/utsrelease.h.
+#ifndef UTS_RELEASE
 #include <linux/utsrelease.h>
 #endif
 
@@ -210,7 +210,7 @@ char* firegl = NULL;
 int __ke_debuglevel = 0;
 int __ke_moduleflags = 0;
 
-static struct pci_device_id fglrx_pci_table[] = 
+static struct pci_device_id fglrx_pci_table[] =
 {
 #define FGL_ASIC_ID(x)                      \
    {                           \
@@ -278,7 +278,7 @@ const unsigned long __ke_PAE_State = 1;
 
 static int firegl_pat_enabled = 0;
 static unsigned long KCL_pat[2];
-static unsigned long KCL_orig_pat[2]; 
+static unsigned long KCL_orig_pat[2];
 
 static int ATI_API_CALL KCL_enable_pat(void);
 static void ATI_API_CALL KCL_disable_pat(void);
@@ -305,7 +305,7 @@ long ip_firegl_compat_ioctl(struct file* filp, unsigned int cmd, unsigned long a
 #endif
 
 __ke_ssize_t ip_firegl_read( struct file *filp,
-                         char *buf, 
+                         char *buf,
                          __ke_size_t size,
                          __ke_loff_t *off_ptr)
 {
@@ -313,7 +313,7 @@ __ke_ssize_t ip_firegl_read( struct file *filp,
 }
 
 __ke_ssize_t ip_firegl_write( struct file *filp,
-                          const char *buf, 
+                          const char *buf,
                           __ke_size_t size,
                           __ke_loff_t *off_ptr)
 {
@@ -449,34 +449,34 @@ READ_PROC_WRAP(firegl_debug_info)
 READ_PROC_WRAP(firegl_bios_version)
 READ_PROC_WRAP(firegl_interrupt_info)
 
-static int 
+static int
 firegl_interrupt_open_wrap(
-        struct inode *inode, 
-        struct file *file) 
+        struct inode *inode,
+        struct file *file)
 {
     return firegl_interrupt_open(inode, file);
 }
 
-static int 
+static int
 firegl_interrupt_release_wrap(
-        struct inode *inode, 
-        struct file *file) 
+        struct inode *inode,
+        struct file *file)
 {
     return firegl_interrupt_release(inode, file);
 }
 
-static ssize_t 
+static ssize_t
 firegl_interrupt_read_wrap(
-        struct file *user_file, 
-        char __user *user_buf, 
-        size_t user_buf_size, 
+        struct file *user_file,
+        char __user *user_buf,
+        size_t user_buf_size,
         loff_t *user_file_pos)
 {
     return (ssize_t) firegl_interrupt_read(user_file, user_buf, user_buf_size, user_file_pos);
 }
 
-static unsigned int 
-firegl_interrupt_poll_wrap(struct file *user_file, poll_table *pt) 
+static unsigned int
+firegl_interrupt_poll_wrap(struct file *user_file, poll_table *pt)
 {
     if(firegl_interrupt_poll(user_file, (__ke_poll_table*)pt))
     {
@@ -488,11 +488,11 @@ firegl_interrupt_poll_wrap(struct file *user_file, poll_table *pt)
     }
 }
 
-static ssize_t 
+static ssize_t
 firegl_interrupt_write_wrap(
-        struct file *user_file, 
-        const char __user *user_buf, 
-        size_t user_buf_size, 
+        struct file *user_file,
+        const char __user *user_buf,
+        size_t user_buf_size,
         loff_t *user_file_pos)
 {
     return (ssize_t) firegl_interrupt_write(user_file, user_buf, user_buf_size, user_file_pos);
@@ -502,7 +502,7 @@ firegl_interrupt_write_wrap(
  *  \param func function to be wrapped
  *  \return None */
 
-static void 
+static void
 firegl_smp_func_parameter_wrap(
 void *func)
 {
@@ -517,7 +517,7 @@ static struct file_operations firegl_interrupt_file_ops = {
     .write      = firegl_interrupt_write_wrap
 };
 
-__ke_proc_list_t firegl_proc_list[] = 
+__ke_proc_list_t firegl_proc_list[] =
 {
     { "name",           drm_name_info_wrap,         NULL},
     { "mem",            drm_mem_info_wrap,          NULL},
@@ -586,11 +586,11 @@ static struct proc_dir_entry *firegl_proc_init( device_t *dev,
         {
 		    ent->proc_fops = (struct file_operations*)list->fops;
         }
-       
+
         {
             ent->data = (dev->pubdev.signature == FGL_DEVICE_SIGNATURE)? firegl_find_device(minor) : (dev);
         }
-        
+
         list++;
 	}
 
@@ -623,7 +623,7 @@ static int firegl_proc_cleanup( int minor,
     {
         remove_proc_entry("dri", NULL);
         __KE_DEBUG("remove proc dri. \n");
-    }    
+    }
     return 0;
 }
 
@@ -661,12 +661,12 @@ static int firegl_stub_getminor(const char *name, struct file_operations *fops,
 {
 	int i;
         int count = 0;
-        
+
         __KE_DEBUG("firegl_stub_getminor: name=\"%s\"\n", name);
 
-	for( i = 0; i < FIREGL_STUB_MAXCARDS; i++ ) 
+	for( i = 0; i < FIREGL_STUB_MAXCARDS; i++ )
         {
-	    if( !firegl_stub_list[i].fops ) 
+	    if( !firegl_stub_list[i].fops )
             {
 		firegl_stub_list[i].name = name;
 		firegl_stub_list[i].fops = fops;
@@ -693,16 +693,16 @@ static int firegl_stub_putminor(int minor)
     if (minor < 0 || minor >= FIREGL_STUB_MAXCARDS)
     {
         return -1;
-    }    
+    }
     firegl_proc_cleanup(minor, firegl_stub_root, firegl_stub_list[minor].dev_root, firegl_stub_list[minor].proclist);
     firegl_stub_list[minor].name = NULL;
     firegl_stub_list[minor].fops = NULL;
     firegl_stub_list[minor].proclist = NULL;
 
-    if( minor == (firegl_minors-1) ) 
+    if( minor == (firegl_minors-1) )
     {
         unregister_chrdev(DRM_MAJOR, "drm");
-    }   
+    }
     return 0;
 }
 
@@ -726,7 +726,7 @@ static int __init firegl_stub_register(const char *name, struct file_operations
         return -1;
     } else if(err == -EBUSY) {
 
-        // the registering of the module's device has failed 
+        // the registering of the module's device has failed
         // because there was already some other drm module loaded.
         __KE_DEBUG("register_chrdev() failed with -EBUSY\n");
 	return -1;
@@ -758,7 +758,7 @@ static int fglrx_pci_probe(struct pci_dev *dev, const struct pci_device_id *id_t
 /* Starting from 2.6.14, kernel has new struct defined for pm_message_t,
    we have to handle this case separately.
    2.6.11/12/13 kernels have pm_message_t defined as int and older kernels
-   don't have pm_message_t defined. 
+   don't have pm_message_t defined.
  */
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
 static int fglrx_pci_suspend(struct pci_dev *pdev, pm_message_t pm_event)
@@ -794,9 +794,9 @@ static int fglrx_pci_suspend(struct pci_dev *pdev, u32 pm_event)
 
     if (!ret)
     {
-        
-    // since privdev->pcidev is acquired in X server, use pdev 
-    // directly here to allow suspend/resume without X server start. 
+
+    // since privdev->pcidev is acquired in X server, use pdev
+    // directly here to allow suspend/resume without X server start.
         firegl_pci_save_state((__ke_pci_dev_t*)pdev, privdev);
         pci_disable_device(pdev);
         PMSG_EVENT(pdev->dev.power.power_state) = state;
@@ -848,13 +848,13 @@ static int fglrx_pci_resume(struct pci_dev *pdev)
     // before pci_set_master!
     firegl_pci_restore_state((__ke_pci_dev_t*)pdev, privdev);
 
-    if (pci_enable_device(pdev)) 
+    if (pci_enable_device(pdev))
     {
         __KE_ERROR("Cannot enable PCI device.\n");
-    }    
+    }
 
     pci_set_master(pdev);
- 
+
     firegl_cail_powerup(privdev);
 
     if (PMSG_EVENT(pdev->dev.power.power_state) == PM_EVENT_SUSPEND)
@@ -865,7 +865,7 @@ static int fglrx_pci_resume(struct pci_dev *pdev)
     return 0;
 }
 
-static struct pci_driver fglrx_pci_driver = 
+static struct pci_driver fglrx_pci_driver =
 {
     .name           = "fglrx_pci",
     .id_table       = fglrx_pci_table,
@@ -921,10 +921,10 @@ static int firegl_init_devices(__ke_device_t *pubdev)
     {
         pid = (struct pci_device_id *) &fglrx_pci_table[i];
         pdev = NULL;
-        while (( pdev = pci_get_subsys(pid->vendor, 
-                                       pid->device, 
-                                       PCI_ANY_ID, 
-                                       PCI_ANY_ID, 
+        while (( pdev = pci_get_subsys(pid->vendor,
+                                       pid->device,
+                                       PCI_ANY_ID,
+                                       PCI_ANY_ID,
                                        pdev)) != NULL)
         {
             num_of_devices++;
@@ -934,7 +934,7 @@ static int firegl_init_devices(__ke_device_t *pubdev)
 
     if (firegl_init_device_heads(num_of_devices))
     {
-        return -ENOMEM;     
+        return -ENOMEM;
     }
 
     for (i=0; fglrx_pci_table[i].vendor != 0; i++)
@@ -942,15 +942,15 @@ static int firegl_init_devices(__ke_device_t *pubdev)
         pid = (struct pci_device_id *) &fglrx_pci_table[i];
 
         pdev = NULL;
-        while (( pdev = pci_get_subsys(pid->vendor, 
-                                       pid->device, 
-                                       PCI_ANY_ID, 
-                                       PCI_ANY_ID, 
+        while (( pdev = pci_get_subsys(pid->vendor,
+                                       pid->device,
+                                       PCI_ANY_ID,
+                                       PCI_ANY_ID,
                                        pdev)) != NULL)
         {
             if ((ret_code = firegl_get_dev(pubdev, pdev)))
             {
-                return ret_code; 
+                return ret_code;
             }
 
             j++;
@@ -983,7 +983,7 @@ static int __init firegl_init_module(void)
     // init global vars that are in fact constants
     __ke_HZ = HZ;
 
-#ifdef _KE_SERIAL_DEBUG  
+#ifdef _KE_SERIAL_DEBUG
     __ke_SetSerialPort();
 #endif
 
@@ -995,11 +995,11 @@ static int __init firegl_init_module(void)
         return retcode;
     }
 
-#ifdef FIREGL_CF_SUPPORT    
+#ifdef FIREGL_CF_SUPPORT
     adapter_chain_init();
     cf_object_init();
-#endif    
-     
+#endif
+
     // init DRM proc list
     drm_proclist = kmalloc((DRM_PROC_ENTRIES + 1) * sizeof(__ke_proc_list_t), GFP_KERNEL);
     if ( drm_proclist == NULL )
@@ -1087,7 +1087,7 @@ static int __init firegl_init_module(void)
 	        dev->pubdev.date,
 		    firegl_minors);
 
-    
+
 #ifdef FIREGL_POWER_MANAGEMENT
     if (pci_register_driver (&fglrx_pci_driver) < 0)
     {
@@ -1117,12 +1117,12 @@ static void __exit firegl_cleanup_module(void)
     {
        KCL_disable_pat();
        __KE_INFO("Disable PAT\n");
-    }   
+    }
 #endif // FIREGL_USWC_SUPPORT
 
     for (i = 0; i < count; i++)
     {
-        if ( firegl_stub_unregister(i) ) 
+        if ( firegl_stub_unregister(i) )
         {
             __KE_ERROR("Cannot unload module on minor: %d\n", i);
         }
@@ -1144,10 +1144,10 @@ static void __exit firegl_cleanup_module(void)
 	        dev->pubdev.patchlevel,
 	        dev->pubdev.date);
 
-#ifdef FIREGL_CF_SUPPORT    
+#ifdef FIREGL_CF_SUPPORT
     cf_object_cleanup();
-    adapter_chain_cleanup();    
-#endif // FIREGL_CF_SUPPORT   
+    adapter_chain_cleanup();
+#endif // FIREGL_CF_SUPPORT
 
     firegl_private_cleanup (&dev->pubdev);
 
@@ -1225,18 +1225,18 @@ void ATI_API_CALL __ke_add_wait_queue(__ke_wait_queue_head_t* queue_head, __ke_w
 void ATI_API_CALL __ke_remove_wait_queue(__ke_wait_queue_head_t* queue_head, __ke_wait_queue_t* entry)
 {
 //    current->state = TASK_RUNNING;
-    remove_wait_queue((wait_queue_head_t*)(void *)queue_head, 
+    remove_wait_queue((wait_queue_head_t*)(void *)queue_head,
 									(wait_queue_t*)(void *)entry);
 }
 
 void ATI_API_CALL __ke_init_waitqueue_head(__ke_wait_queue_head_t* queue_head)
 {
-    init_waitqueue_head((wait_queue_head_t*)(void *)queue_head); 
+    init_waitqueue_head((wait_queue_head_t*)(void *)queue_head);
 }
 
 void ATI_API_CALL __ke_wait_event_interruptible(__ke_wait_queue_head_t* queue_head, int condition)
 {
-    wait_event_interruptible(*((wait_queue_head_t*)(void *)queue_head), condition); 
+    wait_event_interruptible(*((wait_queue_head_t*)(void *)queue_head), condition);
 }
 
 void ATI_API_CALL __ke_poll_wait(struct file* filp, __ke_wait_queue_head_t* queue_head, __ke_poll_table* pt)
@@ -1247,13 +1247,13 @@ void ATI_API_CALL __ke_poll_wait(struct file* filp, __ke_wait_queue_head_t* queu
 void ATI_API_CALL *__ke_asyncio_alloc_sema()
 {
     int i;
-    
+
     for(i=0; i<FIREGL_ASYNCIO_MAX_SEMA; i++)
     {
         if(fireglAsyncioSemaphoreUsed[i] != 1)
         {
             fireglAsyncioSemaphoreUsed[i] = 1;
-            
+
             return &(fireglAsyncioSemaphore[i]);
         }
     }
@@ -1263,7 +1263,7 @@ void ATI_API_CALL *__ke_asyncio_alloc_sema()
 void ATI_API_CALL __ke_asyncio_free_sema(struct semaphore *pSema)
 {
     int i;
-    
+
     for(i=0; i<FIREGL_ASYNCIO_MAX_SEMA; i++)
     {
         if( &(fireglAsyncioSemaphore[i]) == pSema )
@@ -1277,15 +1277,15 @@ void ATI_API_CALL __ke_asyncio_free_sema(struct semaphore *pSema)
 void ATI_API_CALL __ke_asyncio_init_sema(void)
 {
     int i;
-    
+
     for(i=0; i<FIREGL_ASYNCIO_MAX_SEMA; i++)
     {
         fireglAsyncioSemaphoreUsed[i] = 0;
     }
-}    
+}
 
-int ATI_API_CALL __ke_fasync_helper( int fd, 
-                        struct file *filep, 
+int ATI_API_CALL __ke_fasync_helper( int fd,
+                        struct file *filep,
                         int mode,
                         struct fasync_struct **pasync_queue)
 {
@@ -1352,33 +1352,33 @@ unsigned int ATI_API_CALL KCL_ProcessIsTerminated(unsigned int pid)
 {
    struct task_struct *p;
    int process_terminated = 1;
-  
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)  
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
    rcu_read_lock();
-#else   
+#else
    read_lock(&tasklist_lock);
-#endif   
-   p = find_task_by_pid( pid );
-   if (p) 
+#endif
+   p = find_task_by_vpid( pid );
+   if (p)
    {
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10)
-      if (p->exit_state != EXIT_ZOMBIE && p->exit_state != EXIT_DEAD) 
+      if (p->exit_state != EXIT_ZOMBIE && p->exit_state != EXIT_DEAD)
 #else
-      if (!(p->flags & PF_EXITING)) 
+      if (!(p->flags & PF_EXITING))
 #endif
       {
          process_terminated = 0;
       }
-   }   
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)  
+   }
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
    rcu_read_unlock();
-#else   
+#else
    read_unlock(&tasklist_lock);
-#endif   
+#endif
    return process_terminated;
 }
 
-/** /brief Call global OS kernel task/thread scheduler 
+/** /brief Call global OS kernel task/thread scheduler
  *  /return Nonzero if a system call was awakened by a signal
  */
 int ATI_API_CALL KCL_GetSignalStatus(void)
@@ -1432,15 +1432,15 @@ void ATI_API_CALL __ke_unblock_all_signals(void)
     unblock_all_signals();
 }
 
-#if defined(__i386__) 
+#if defined(__i386__)
 #ifndef __HAVE_ARCH_CMPXCHG
-static inline 
-unsigned long __fgl_cmpxchg(volatile void *ptr, unsigned long old,            
-                        unsigned long new, int size)                      
-{                                                                                       
-    unsigned long prev;                                                             
-    switch (size) {                                                                 
-    case 1:                                                                         
+static inline
+unsigned long __fgl_cmpxchg(volatile void *ptr, unsigned long old,
+                        unsigned long new, int size)
+{
+    unsigned long prev;
+    switch (size) {
+    case 1:
         __asm__ __volatile__(LOCK_PREFIX "cmpxchgb %b1,%2"
                              : "=a"(prev)
                              : "q"(new), "m"(*__xg(ptr)), "0"(old)
@@ -1551,7 +1551,7 @@ struct inode* ATI_API_CALL __ke_get_file_inode(struct file* filp)
  */
 KCL_TYPE_Pid ATI_API_CALL KCL_GetPid(void)
 {
-    return current->pid; 
+    return current->pid;
 }
 
 /** /brief Return the current Thread Group ID
@@ -1559,7 +1559,7 @@ KCL_TYPE_Pid ATI_API_CALL KCL_GetPid(void)
  */
 KCL_TYPE_Pid ATI_API_CALL KCL_GetTgid(void)
 {
-    return current->tgid; 
+    return current->tgid;
 }
 
 /** /brief Return the effective user ID
@@ -1655,7 +1655,7 @@ static int KCL_MAP_KernelConfigParam[] =
     1
 #else
     0
-#endif 
+#endif
 };
 
 /** /brief Check whether a kernel configuration parameter is defined
@@ -1718,13 +1718,13 @@ unsigned long ATI_API_CALL __ke_get_resource_start(__ke_pci_dev_t *dev, unsigned
 #if defined(__x86_64__) || defined(__ia64__)
 void* ATI_API_CALL __ke_pci_alloc_consistent(__ke_pci_dev_t* dev, int size, void *dma_handle)
 {
-	return (pci_alloc_consistent( (struct pci_dev*)(void *)dev, size, dma_handle)); 
+	return (pci_alloc_consistent( (struct pci_dev*)(void *)dev, size, dma_handle));
 }
 
 void ATI_API_CALL __ke_pci_free_consistent(__ke_pci_dev_t* dev, int size, unsigned long cpu_addr,
 						 unsigned int dma_handle)
 {
-	pci_free_consistent( (struct pci_dev*)(void *)dev, size, (void *)cpu_addr, 
+	pci_free_consistent( (struct pci_dev*)(void *)dev, size, (void *)cpu_addr,
 		(unsigned long)dma_handle);
 }
 #endif // __ia64__
@@ -1748,7 +1748,7 @@ static int KCL_MAP_ErrorCode[] =
 
 /** \brief This function maps OS independent error conditions to OS defined error codes
  *  \param errcode OS independent error condition code
- *  \return OS kernel defined error code corresponding to the requested error condition 
+ *  \return OS kernel defined error code corresponding to the requested error condition
  */
 int ATI_API_CALL KCL_GetErrorCode(KCL_ENUM_ErrorCode errcode)
 {
@@ -1766,7 +1766,7 @@ int ATI_API_CALL KCL_GetErrorCode(KCL_ENUM_ErrorCode errcode)
 int ATI_API_CALL firegl_get_user_ptr(u32 *src, void **dst)
 {
   unsigned long temp;
-  int err = get_user(temp, src); 
+  int err = get_user(temp, src);
   *dst = (void*) temp;
   return err;
 }
@@ -1906,7 +1906,7 @@ void ATI_API_CALL __ke_atomic_set(void* v, int val)
 
 int ATI_API_CALL __ke_atomic_dec_and_test(void* v)
 {
-    return atomic_dec_and_test((atomic_t*)v); 
+    return atomic_dec_and_test((atomic_t*)v);
 }
 
 /*****************************************************************************/
@@ -2006,19 +2006,19 @@ void ATI_API_CALL __ke_print_debug(const char* fmt, ...)
 #endif
 
 #ifdef _KE_SERIAL_DEBUG
-// To enable serial port debug message dumping,just define _KE_SERIAL_DEBUG in firegl_public.h file. 
-// Connect two PC with a null modern serial cable. run Hyper ternimal on the remote machine. 
-// It's useful to debug resume if network not works properly and serial port is not recovered 
+// To enable serial port debug message dumping,just define _KE_SERIAL_DEBUG in firegl_public.h file.
+// Connect two PC with a null modern serial cable. run Hyper ternimal on the remote machine.
+// It's useful to debug resume if network not works properly and serial port is not recovered
 // properly when fglrx resume hook is called...
- 
- 
+
+
 #define SER_DATA_PORT       0x3f8
 #define SER_INT_CTRL_PORT   SER_DATA_PORT + 1
 #define SER_INT_STAT_PORT   SER_DATA_PORT + 2
 #define SER_LINE_CTRL_PORT  SER_DATA_PORT + 3
 #define SER_MODEM_CTRL_PORT SER_DATA_PORT + 4
 #define SER_LINE_STAT_PORT  SER_DATA_PORT + 5
-    
+
 void ATI_API_CALL __ke_printc(char c)
 {
      while((inb(SER_LINE_STAT_PORT) & 0x20) == 0 ); //wait until Transmitter Holding Register Empty
@@ -2028,7 +2028,7 @@ void ATI_API_CALL __ke_printc(char c)
 void ATI_API_CALL __ke_printstr(const char *str)
 {
     int len = strlen(str);
-    while(len--)__ke_printc(*str++);  
+    while(len--)__ke_printc(*str++);
 }
 
 int ATI_API_CALL __ke_SerPrint(const char *format, ...)
@@ -2041,26 +2041,26 @@ int ATI_API_CALL __ke_SerPrint(const char *format, ...)
     vsprintf(buffer, format, ap);
 
     va_end(ap);
-    
+
     __ke_printstr(buffer);
-    
+
     return 0;
 }
 void ATI_API_CALL __ke_SetSerialPort()
 {
     DRM_INFO("setup serial port\n");
-    outb(0x00,  SER_INT_CTRL_PORT);   // Turn off interrupts 
-
-    outb(0x80,  SER_LINE_CTRL_PORT);  // SET DLAB ON 
-    outb(0x01,  SER_DATA_PORT);  // Set Baud rate - Divisor Latch Low Byte 
-                             // 0x01 = 115,200 ,0x02 =  57,600,  0x06 =  19,200 BPS, 0x0C =   9,600 BPS  
-    outb(0x00,  SER_DATA_PORT + 1);  // Set Baud rate - Divisor Latch High Byte 
-    outb(0x03,  SER_LINE_CTRL_PORT); // reset DLAB ,8 Bits, No Parity, 1 Stop Bit 
-    outb(0xC7,  SER_DATA_PORT + 2);  // FIFO Control Register 
+    outb(0x00,  SER_INT_CTRL_PORT);   // Turn off interrupts
+
+    outb(0x80,  SER_LINE_CTRL_PORT);  // SET DLAB ON
+    outb(0x01,  SER_DATA_PORT);  // Set Baud rate - Divisor Latch Low Byte
+                             // 0x01 = 115,200 ,0x02 =  57,600,  0x06 =  19,200 BPS, 0x0C =   9,600 BPS
+    outb(0x00,  SER_DATA_PORT + 1);  // Set Baud rate - Divisor Latch High Byte
+    outb(0x03,  SER_LINE_CTRL_PORT); // reset DLAB ,8 Bits, No Parity, 1 Stop Bit
+    outb(0xC7,  SER_DATA_PORT + 2);  // FIFO Control Register
     outb(0x0b,  SER_DATA_PORT + 4);  // Turn on DTR, RTS, and OUT2
-  
+
     __ke_printstr("serial port 0x3f8 is set ready for message print out \n");
-}  
+}
 #endif
 
 /** \brief Get number of available RAM pages
@@ -2241,7 +2241,7 @@ void *ATI_API_CALL __ke_vmalloc_to_addr(void *vmalloc_addr)
     struct page *page = NULL;
 
     page = vmalloc_to_page(vmalloc_addr);
-    if(page == NULL) 
+    if(page == NULL)
     {
         __KE_ERROR("__ke_vmalloc_to_addr: invalid page!");
         return NULL;
@@ -2283,7 +2283,7 @@ int ATI_API_CALL __ke_do_munmap(unsigned long addr, unsigned long len)
     retcode = do_munmap(current->mm,
                         addr,
                         len);
-#endif                        
+#endif
     up_write(&current->mm->mmap_sem);
     return retcode;
 }
@@ -2327,10 +2327,10 @@ long long ATI_API_CALL __divdi3(long long n, long long base)
        minus = !minus;
     }
     else
-    {   
+    {
        ubase = base;
     }
-    
+
     do_div(un, ubase);
     return (minus? -un : un);
 }
@@ -2360,7 +2360,7 @@ long long ATI_API_CALL __moddi3(long long n, long long base)
     else
     {
        ubase = base;
-    }   
+    }
 
     rem = do_div(un, ubase);
     return (minus? -rem : rem);
@@ -2391,7 +2391,7 @@ void* ATI_API_CALL __ke_vmap(unsigned long *pagelist, unsigned int count)
     vaddr = (void *) vmap(pages, count);
 #else
 #ifdef VM_MAP
-    vaddr = (void *) vmap(pages, count, VM_MAP, PAGE_KERNEL); 
+    vaddr = (void *) vmap(pages, count, VM_MAP, PAGE_KERNEL);
 #else
     vaddr = (void *) vmap(pages, count, 0, PAGE_KERNEL);
 #endif
@@ -2447,7 +2447,7 @@ void ATI_API_CALL __ke_vunmap(void* addr)
 }
 #endif  // defined(VM_MAP) || defined(vunmap)
 
-/** \brief Reserve a memory page 
+/** \brief Reserve a memory page
  *
  * \param pt Kernel logical address of the page
  *
@@ -2459,7 +2459,7 @@ void ATI_API_CALL KCL_ReserveMemPage(void* pt)
     SetPageReserved(virt_to_page((unsigned long)pt));
 }
 
-/** \brief Unreserve a memory page 
+/** \brief Unreserve a memory page
  *
  * \param pt Kernel logical address of the page
  *
@@ -2471,7 +2471,7 @@ void ATI_API_CALL KCL_UnreserveMemPage(void* pt)
     ClearPageReserved(virt_to_page((unsigned long)pt));
 }
 
-/** \brief Lock a memory page 
+/** \brief Lock a memory page
  *
  * \param pt Kernel logical address of the page
  *
@@ -2480,14 +2480,14 @@ void ATI_API_CALL KCL_UnreserveMemPage(void* pt)
  */
 void ATI_API_CALL KCL_LockMemPage(void* pt)
 {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15) 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)
     SetPageReserved(virt_to_page((unsigned long)pt));
 #else
     lock_page(virt_to_page((unsigned long)pt));
 #endif
 }
 
-/** \brief Unlock a memory page 
+/** \brief Unlock a memory page
  *
  * \param pt Kernel logical address of the page
  *
@@ -2496,7 +2496,7 @@ void ATI_API_CALL KCL_LockMemPage(void* pt)
  */
 void ATI_API_CALL KCL_UnlockMemPage(void* pt)
 {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15) 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)
     ClearPageReserved(virt_to_page((unsigned long)pt));
 #else
     unlock_page(virt_to_page((unsigned long)pt));
@@ -2521,7 +2521,7 @@ void* ATI_API_CALL __ke_get_vmptr( struct _agp_memory* memory )
 	return memory->vmptr;
 }
 #endif
-                              
+
 void* ATI_API_CALL __ke_ioremap(unsigned long offset, unsigned long size)
 {
     return ioremap(offset, size);
@@ -2592,7 +2592,7 @@ void ATI_API_CALL KCL_flush_tlb_onepage(struct vm_area_struct * vma, unsigned lo
 {
 /*Some kernel developer removed the export of symbol "flush_tlb_page" on 2.6.25 x86_64 SMP kernel.
   Define a simple version here.*/
-#if defined(__x86_64__) && defined(__SMP__) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)) 
+#if defined(__x86_64__) && defined(__SMP__) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25))
     on_each_cpu(KCL_flush_tlb_one, &va, 1, 1);
 #else
     flush_tlb_page(vma, va);
@@ -2649,9 +2649,9 @@ void ATI_API_CALL __ke_put_vm_page_table(unsigned long page_addr)
 static inline int ptep_clear_flush_dirty(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep)
 {
     int ret = 0;
-    
+
     DBG_ENTER("0x%08X, 0x%08X, 0x%08X->0x%08X", vma, addr, ptep, *ptep);
-    
+
     if (pte_dirty(*ptep))
     {
 #ifdef __x86_64__
@@ -2666,19 +2666,19 @@ static inline int ptep_clear_flush_dirty(struct vm_area_struct *vma, unsigned lo
         {
             pte_update(vma->vm_mm, addr, ptep);
         }
-#endif        
+#endif
     }
 
     DBG_TRACE("0x%08X->0x%08X", ptep, *ptep);
-    
+
     // Flush Translation Lookaside Buffers
     if (ret)
     {
         KCL_flush_tlb_onepage(vma,addr);
     }
-    
+
     DBG_LEAVE("%d", ret);
-    
+
     return ret;
 }
 #endif
@@ -2705,7 +2705,7 @@ static inline int ptep_clear_flush_dirty(struct vm_area_struct *vma, unsigned lo
  * the virtual address
  *
  * \param mm Pointer to the memory descriptor structure
- * \param virtual_addr Virtual address 
+ * \param virtual_addr Virtual address
  *
  * \return Old value of the "dirty" flag on success or negative on error
  *
@@ -2961,7 +2961,7 @@ int ATI_API_CALL __ke_config_mtrr(void)
        return 0;
 #else
     return 1;
-#endif    
+#endif
 #else /* !CONFIG_MTRR */
     return 0;
 #endif /* !CONFIG_MTRR */
@@ -2987,7 +2987,7 @@ int ATI_API_CALL __ke_mtrr_del(int reg, unsigned long base, unsigned long size)
 
 int ATI_API_CALL __ke_has_vmap(void)
 {
-// We disable vmap for 2.4.x kernel to work around the big memory( > 4GB ) issue. 
+// We disable vmap for 2.4.x kernel to work around the big memory( > 4GB ) issue.
 #if defined(VM_MAP) || defined(vunmap)
     return 1;
 #else
@@ -3009,7 +3009,7 @@ int ATI_API_CALL __ke_no_iommu(void)
 {
     return 0;
 }
-#endif 
+#endif
 
 /*****************************************************************************/
 
@@ -3066,7 +3066,7 @@ unsigned int ATI_API_CALL __ke_pci_get_func(__ke_pci_dev_t* pcidev)
 {
     struct pci_dev* dev = (struct pci_dev*)pcidev;
     return PCI_FUNC(dev->devfn);
-}    
+}
 
 __ke_dma_addr_t ATI_API_CALL __ke_pci_map_single (__ke_pci_dev_t *pdev, void *buffer, __ke_size_t size, int direction)
 {
@@ -3153,7 +3153,7 @@ static irqreturn_t ke_irq_handler_wrap(int irq, void *arg1)
     return IRQ_HANDLED;
 }
 #endif
-            
+
 int ATI_API_CALL __ke_request_irq(unsigned int irq,
     void (*ATI_API_CALL handler)(int, void *, void *),
     const char *dev_name, void *dev_id)
@@ -3166,7 +3166,7 @@ int ATI_API_CALL __ke_request_irq(unsigned int irq,
         SA_SHIRQ,
 #else
         IRQF_SHARED,
-#endif                
+#endif
         dev_name,
         dev_id);
 }
@@ -3203,12 +3203,12 @@ int ATI_API_CALL __ke_agp_memory_get_page_count(struct _agp_memory* agpmem)
     return (int)(agpmem->page_count);
 }
 
-void ATI_API_CALL __ke_agp_memory_get_memory(struct _agp_memory* agpmem, 
+void ATI_API_CALL __ke_agp_memory_get_memory(struct _agp_memory* agpmem,
                                              unsigned long **memory_ptr)
 {
     __KE_DEBUG("[%s] agpmem=0x%016lx agpmem->memory=0x%016lx [0]=0x%016x",
-               __FUNCTION__, 
-               (unsigned long)agpmem, 
+               __FUNCTION__,
+               (unsigned long)agpmem,
                (unsigned long)agpmem->memory,
                (agpmem->memory)[0]);
 
@@ -3217,18 +3217,9 @@ void ATI_API_CALL __ke_agp_memory_get_memory(struct _agp_memory* agpmem,
 
 /*****************************************************************************/
 
-#ifndef NOPAGE_SIGBUS
-#define NOPAGE_SIGBUS 0
-#endif /* !NOPAGE_SIGBUS */
-
 typedef struct page mem_map_t;
 typedef mem_map_t *vm_nopage_ret_t;
 
-static __inline__ vm_nopage_ret_t do_vm_nopage(struct vm_area_struct* vma,
-                                                     unsigned long address)
-{
-    return 0;   /* Disallow mremap */
-}
 
 #ifdef __AGP__BUILTIN__
 #ifdef __ia64__
@@ -3253,19 +3244,20 @@ static __inline__ vm_nopage_ret_t do_vm_cant_nopage(struct vm_area_struct* vma,
 			return page;
 		}
 	}
-	return NOPAGE_SIGBUS;		/* Disallow mremap */
+	return VM_FAULT_SIGBUS;		/* Disallow mremap */
 }
 
 #endif /* __ia64__ */
 #endif /* __AGP__BUILTIN__ */
 
 
-static __inline__ vm_nopage_ret_t do_vm_shm_nopage(struct vm_area_struct* vma,
-                                                   unsigned long address)
+static __inline__ int do_vm_shm_nopage(struct vm_area_struct* vma,
+				       struct vm_fault *vmf)
 {
     pgd_t* pgd_p;
     pmd_t* pmd_p;
     pte_t  pte;
+    unsigned long address = (unsigned long)vmf->virtual_address;
     unsigned long vma_offset;
     unsigned long pte_linear;
     mem_map_t* pMmPage;
@@ -3294,7 +3286,7 @@ static __inline__ vm_nopage_ret_t do_vm_shm_nopage(struct vm_area_struct* vma,
             (unsigned long)__ke_vm_offset(vma));
 
     if (address > vma->vm_end)
-        return NOPAGE_SIGBUS; /* address is out of range */
+        return VM_FAULT_SIGBUS; /* address is out of range */
 
     /*  Calculate offset into VMA */
     vma_offset = address - vma->vm_start;
@@ -3306,7 +3298,7 @@ static __inline__ vm_nopage_ret_t do_vm_shm_nopage(struct vm_area_struct* vma,
     pte_linear = firegl_get_addr_from_vm(vma);
     if (!pte_linear)
     {
-        return NOPAGE_SIGBUS; /* bad address */
+        return VM_FAULT_SIGBUS; /* bad address */
     }
     pte_linear += vma_offset;
 
@@ -3334,7 +3326,9 @@ static __inline__ vm_nopage_ret_t do_vm_shm_nopage(struct vm_area_struct* vma,
 
     //  __KE_DEBUG3("vm-address 0x%08lx => kernel-page-address 0x%p\n",
     //    address, page_address(pMmPage));
-    return pMmPage;
+    vmf->page = pMmPage;
+
+    return 0;
 }
 
 /*
@@ -3343,8 +3337,10 @@ static __inline__ vm_nopage_ret_t do_vm_shm_nopage(struct vm_area_struct* vma,
       (which is one ore more pages in size)
 
 */
-static __inline__ vm_nopage_ret_t do_vm_dma_nopage(struct vm_area_struct* vma, unsigned long address)
+static __inline__ int do_vm_dma_nopage(struct vm_area_struct* vma,
+				       struct vm_fault *vmf)
 {
+    unsigned long address = (unsigned long) vmf->virtual_address;
     unsigned long kaddr;
     mem_map_t* pMmPage;
 
@@ -3360,7 +3356,7 @@ static __inline__ vm_nopage_ret_t do_vm_dma_nopage(struct vm_area_struct* vma, u
     kaddr = firegl_get_addr_from_vm(vma);
     if (!kaddr)
     {
-        return NOPAGE_SIGBUS; /* bad address */
+        return VM_FAULT_SIGBUS; /* bad address */
     }
     kaddr += (address - vma->vm_start);
 
@@ -3372,19 +3368,23 @@ static __inline__ vm_nopage_ret_t do_vm_dma_nopage(struct vm_area_struct* vma, u
     // with drm_alloc_pages, which marks all pages as reserved. Reserved
     // pages' usage count is not decremented by the kernel during unmap!!!
     //
-    // For kernel >= 2.6.15, We should reenable this, because the VM sub-system 
-    // will decrement the pages' usage count even for the pages marked as reserved 
+    // For kernel >= 2.6.15, We should reenable this, because the VM sub-system
+    // will decrement the pages' usage count even for the pages marked as reserved
     // 								- MC.
     get_page(pMmPage); /* inc usage count of page */
 #endif
 
     __KE_DEBUG3("vm-address 0x%08lx => kernel-page-address 0x%p\n",
         address, page_address(pMmPage));
-    return pMmPage;
+    vmf->page = pMmPage;
+
+    return 0;
 }
 
-static __inline__ vm_nopage_ret_t do_vm_kmap_nopage(struct vm_area_struct* vma, unsigned long address)
+static __inline__ int do_vm_kmap_nopage(struct vm_area_struct* vma,
+					struct vm_fault *vmf)
 {
+    unsigned long address = (unsigned long) vmf->virtual_address;
     unsigned long kaddr;
     mem_map_t* pMmPage;
 
@@ -3394,13 +3394,14 @@ static __inline__ vm_nopage_ret_t do_vm_kmap_nopage(struct vm_area_struct* vma,
     if ((pMmPage = (mem_map_t*) firegl_get_pagetable_page_from_vm(vma)))
     {
         get_page(pMmPage);
-        return pMmPage;
+	vmf->page = pMmPage;
+        return 0;
     }
 
     kaddr = firegl_get_addr_from_vm(vma);
     if (!kaddr)
     {
-        return NOPAGE_SIGBUS; /* bad address */
+        return VM_FAULT_SIGBUS; /* bad address */
     }
     kaddr += (address - vma->vm_start);
 
@@ -3413,50 +3414,52 @@ static __inline__ vm_nopage_ret_t do_vm_kmap_nopage(struct vm_area_struct* vma,
 
     __KE_DEBUG3("vm-address 0x%08lx => kernel-page-address 0x%p\n", address, page_address(pMmPage));
 
-    return pMmPage;
+    vmf->page = pMmPage;
+    return 0;
 }
 
-/** 
+/**
  **
- **  This routine is intented to locate the page table through the 
+ **  This routine is intented to locate the page table through the
  **  pagelist table created earlier in dev-> pcie
  **/
-static __inline__ vm_nopage_ret_t do_vm_pcie_nopage(struct vm_area_struct* vma,
-                                                         unsigned long address)
+static __inline__ int do_vm_pcie_nopage(struct vm_area_struct* vma,
+					struct vm_fault *vmf)
 {
 
+    unsigned long address = (unsigned long)vmf->virtual_address;
     unsigned long vma_offset;
-    unsigned long i; 
+    unsigned long i;
     mem_map_t* pMmPage;
     struct firegl_pcie_mem* pciemem;
     unsigned long* pagelist;
-    
+
     drm_device_t *dev = (drm_device_t *)firegl_get_dev_from_vm(vma);
     if (dev == NULL)
     {
         __KE_ERROR("dev is NULL\n");
-        return NOPAGE_SIGBUS;
+        return VM_FAULT_SIGBUS;
     }
 
     if (address > vma->vm_end)
     {
         __KE_ERROR("address out of range\n");
-        return NOPAGE_SIGBUS; /* address is out of range */
+        return VM_FAULT_SIGBUS; /* address is out of range */
     }
     pciemem = firegl_get_pciemem_from_addr ( vma, address);
     if (pciemem == NULL)
     {
         __KE_ERROR("No pciemem found! \n");
-        return NOPAGE_SIGBUS;
-    }    
+        return VM_FAULT_SIGBUS;
+    }
     pagelist = firegl_get_pagelist_from_vm(vma);
 
-    if (pagelist == NULL) 
+    if (pagelist == NULL)
     {
         __KE_ERROR("No pagelist! \n");
-        return NOPAGE_SIGBUS;
+        return VM_FAULT_SIGBUS;
     }
-     
+
     /** Find offset in  vma */
     vma_offset = address - vma->vm_start;
     /** Which entry in the pagelist */
@@ -3468,15 +3471,17 @@ static __inline__ vm_nopage_ret_t do_vm_pcie_nopage(struct vm_area_struct* vma,
     if (page_address(pMmPage) == 0x0)
     {
         __KE_ERROR("Invalid page address\n");
-        return NOPAGE_SIGBUS;
+        return VM_FAULT_SIGBUS;
     }
-    return pMmPage;
+
+    vmf->page = pMmPage;
+    return 0;
 }
 
-static __inline__ vm_nopage_ret_t do_vm_gart_nopage(struct vm_area_struct* vma,
-                                                    unsigned long address)
+static __inline__ int do_vm_gart_nopage(struct vm_area_struct* vma,
+					struct vm_fault *vmf)
 {
-
+    unsigned long address = (unsigned long) vmf->virtual_address;
     unsigned long page_addr;
     unsigned long offset;
     struct page *page;
@@ -3484,36 +3489,31 @@ static __inline__ vm_nopage_ret_t do_vm_gart_nopage(struct vm_area_struct* vma,
     if (address > vma->vm_end)
     {
         __KE_ERROR("Invalid virtual address\n");
-        return NOPAGE_SIGBUS;   /* Disallow mremap */
-    }          
+        return VM_FAULT_SIGBUS;   /* Disallow mremap */
+    }
 
     offset      = address - vma->vm_start;
-#ifdef FIREGL_CF_SUPPORT    
+#ifdef FIREGL_CF_SUPPORT
     page_addr   = mc_heap_get_page_addr(vma, offset);
 #else
     page_addr   = firegl_cmmqs_get_pageaddr_from_vm(vma, offset);
-#endif    
+#endif
     if( !page_addr)
     {
         __KE_ERROR("Invalid page address\n");
-        return NOPAGE_SIGBUS;   /* Disallow mremap */
+        return VM_FAULT_SIGBUS;   /* Disallow mremap */
     }
     page        = virt_to_page(page_addr);
     get_page(page);
 
-    return page;
+    vmf->page = page;
+    return 0;
 }
 
-
-
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
-
-static vm_nopage_ret_t vm_nopage(struct vm_area_struct* vma,
-                                 unsigned long address,
-                                 int *type)
+static int vm_nopage(struct vm_area_struct* vma,
+		     struct vm_fault *vmf)
 {
-    if (type) *type = VM_FAULT_MINOR;
-        return do_vm_nopage(vma, address);
+	return VM_FAULT_SIGBUS;
 }
 
 #ifdef __AGP__BUILTIN__
@@ -3545,91 +3545,10 @@ static vm_nopage_ret_t vm_cant_nopage(struct vm_area_struct* vma,
     (which is one or more pages in size)
 
  */
-static vm_nopage_ret_t vm_shm_nopage(struct vm_area_struct* vma,
-                                     unsigned long address,
-                                     int *type)
-{
-    if (type) *type = VM_FAULT_MINOR;
-        return do_vm_shm_nopage(vma, address);
-}
-
-/*
-
-    This routine is intended to remap addresses of a OpenGL context
-      (which is one ore more pages in size)
-
-*/
-static vm_nopage_ret_t vm_dma_nopage(struct vm_area_struct* vma,
-                                     unsigned long address,
-                                     int *type)
-{
-    if (type) *type = VM_FAULT_MINOR;
-        return do_vm_dma_nopage(vma, address);
-}
-
-static vm_nopage_ret_t vm_kmap_nopage(struct vm_area_struct* vma,
-                                     unsigned long address,
-                                     int *type)
-{
-    if (type) *type = VM_FAULT_MINOR;
-        return do_vm_kmap_nopage(vma, address);
-}
-
-static vm_nopage_ret_t vm_pcie_nopage(struct vm_area_struct* vma,
-                                     unsigned long address,
-                                     int *type)
-{  
-       return do_vm_pcie_nopage(vma, address);
-}
-
-static vm_nopage_ret_t vm_gart_nopage(struct vm_area_struct* vma,
-                                      unsigned long address, 
-                                      int *type)
-{
-       return do_vm_gart_nopage(vma, address);
-}
-
-#else   /* LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,0) */
-
-static vm_nopage_ret_t vm_nopage(struct vm_area_struct* vma,
-                                 unsigned long address,
-                                 int write_access)
-{
-    return do_vm_nopage(vma, address);
-}
-
-#ifdef __AGP__BUILTIN__
-#ifdef __ia64__
-
-
-static vm_nopage_ret_t vm_cant_nopage(struct vm_area_struct* vma,
-                                 unsigned long address,
-                                 int write_access)
-{
-    return do_vm_cant_nopage(vma, address);
-}
-#endif /* __ia64__ */
-#endif /* __AGP__BUILTIN__ */
-
-/*
-
-    This function is called when a page of a mmap()'ed area is not currently
-    visible in the specified VMA.
-    Return value is the associated physical address for the requested page.
-    (If not implemented, then the kernel default routine would allocate a new,
-     zeroed page for servicing us)
-
-    Possible errors: SIGBUS, OutOfMem
-
-    This routine is intended to remap addresses of SHM SAREA
-    (which is one or more pages in size)
-
- */
-static vm_nopage_ret_t vm_shm_nopage(struct vm_area_struct* vma,
-                                     unsigned long address,
-                                     int write_access)
+static int vm_shm_nopage(struct vm_area_struct* vma,
+			 struct vm_fault *vmf)
 {
-    return do_vm_shm_nopage(vma, address);
+        return do_vm_shm_nopage(vma, vmf);
 }
 
 /*
@@ -3638,37 +3557,30 @@ static vm_nopage_ret_t vm_shm_nopage(struct vm_area_struct* vma,
       (which is one ore more pages in size)
 
 */
-static vm_nopage_ret_t vm_dma_nopage(struct vm_area_struct* vma,
-                                     unsigned long address,
-                                     int write_access)
+static int vm_dma_nopage(struct vm_area_struct* vma,
+			 struct vm_fault *vmf)
 {
-     return do_vm_dma_nopage(vma, address);
+        return do_vm_dma_nopage(vma, vmf);
 }
 
-static vm_nopage_ret_t vm_kmap_nopage(struct vm_area_struct* vma,
-                                     unsigned long address,
-                                     int write_access)
+static int vm_kmap_nopage(struct vm_area_struct* vma,
+			  struct vm_fault *vmf)
 {
-     return do_vm_kmap_nopage(vma, address);
+        return do_vm_kmap_nopage(vma, vmf);
 }
 
-static vm_nopage_ret_t vm_pcie_nopage(struct vm_area_struct* vma,
-                                     unsigned long address,
-                                     int write_access)
+static int vm_pcie_nopage(struct vm_area_struct* vma,
+			  struct vm_fault *vmf)
 {
-        return do_vm_pcie_nopage(vma, address);
+	return do_vm_pcie_nopage(vma, vmf);
 }
 
-static vm_nopage_ret_t vm_gart_nopage(struct vm_area_struct* vma,
-                                      unsigned long address, 
-                                      int *type)
+static int vm_gart_nopage(struct vm_area_struct* vma,
+			  struct vm_fault *vmf)
 {
-       return do_vm_gart_nopage(vma, address);
+       return do_vm_gart_nopage(vma, vmf);
 }
 
-
-#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0) */
-
 void* ATI_API_CALL __ke_vma_file_priv(struct vm_area_struct* vma)
 {
     return vma->vm_file->private_data;
@@ -3718,7 +3630,7 @@ char* ATI_API_CALL __ke_vm_page_prot_str(struct vm_area_struct* vma, char* buf)
     *(buf + i++) = pgprot & _PAGE_DIRTY    ? 'd' : '-';
     *(buf + i++) = pgprot & _PAGE_PSE      ? 'm' : 'k';
     *(buf + i++) = pgprot & _PAGE_GLOBAL   ? 'g' : 'l';
-#endif /* __i386__ */		
+#endif /* __i386__ */
     *(buf + i++) = 0;
 
     return buf;
@@ -3747,9 +3659,9 @@ char *__ke_pte_phys_addr_str(pte_t pte, char *buf, __ke_dma_addr_t* phys_address
     return buf;
 }
 
-char* ATI_API_CALL __ke_vm_phys_addr_str(struct vm_area_struct* vma, 
-                            char* buf, 
-                            unsigned long virtual_addr, 
+char* ATI_API_CALL __ke_vm_phys_addr_str(struct vm_area_struct* vma,
+                            char* buf,
+                            unsigned long virtual_addr,
                             __ke_dma_addr_t* phys_address)
 {
     pgd_t* pgd_p;
@@ -3773,7 +3685,7 @@ void ip_drm_vm_close(struct vm_area_struct* vma)
 
 static struct vm_operations_struct vm_ops =
 {
-    nopage:  vm_nopage,
+    fault:   vm_nopage,
     open:    ip_drm_vm_open,
     close:   ip_drm_vm_close,
 };
@@ -3791,42 +3703,42 @@ static struct vm_operations_struct vm_cant_ops =
 
 static struct vm_operations_struct vm_shm_ops =
 {
-    nopage:  vm_shm_nopage,
+    fault:   do_vm_shm_nopage,
     open:    ip_drm_vm_open,
     close:   ip_drm_vm_close,
 };
 
 static struct vm_operations_struct vm_pci_bq_ops =
 {
-    nopage:  vm_dma_nopage,
+    fault:   vm_dma_nopage,
     open:    ip_drm_vm_open,
     close:   ip_drm_vm_close,
 };
 
 static struct vm_operations_struct vm_ctx_ops =
 {
-    nopage:  vm_dma_nopage,
+    fault:   vm_dma_nopage,
     open:    ip_drm_vm_open,
     close:   ip_drm_vm_close,
 };
 
-static struct vm_operations_struct vm_pcie_ops = 
+static struct vm_operations_struct vm_pcie_ops =
 {
-    nopage:  vm_pcie_nopage,
+    fault:   vm_pcie_nopage,
     open:    ip_drm_vm_open,
     close:   ip_drm_vm_close,
 };
 
 static struct vm_operations_struct vm_kmap_ops =
 {
-    nopage:  vm_kmap_nopage,
+    fault:   vm_kmap_nopage,
     open:    ip_drm_vm_open,
     close:   ip_drm_vm_close,
 };
 
 static struct vm_operations_struct vm_gart_ops =
 {
-    nopage:  vm_gart_nopage,
+    fault:   vm_gart_nopage,
     open:    ip_drm_vm_open,
     close:   ip_drm_vm_close,
 };
@@ -3835,14 +3747,14 @@ static struct vm_operations_struct vm_gart_ops =
 #ifndef __ia64__
 static struct vm_operations_struct vm_agp_bq_ops =
 {
-    nopage:  vm_nopage,
+    fault:   vm_nopage,
     open:    ip_drm_vm_open,
     close:   ip_drm_vm_close,
 };
-#else		
+#else
 static struct vm_operations_struct vm_cant_agp_bq_ops =
 {
-    nopage:  vm_cant_nopage,
+    fault:   vm_cant_nopage,
     open:    ip_drm_vm_open,
     close:   ip_drm_vm_close,
 };
@@ -3877,19 +3789,19 @@ int ATI_API_CALL __ke_vm_map(struct file* filp,
 #ifdef __i386__
                 if (boot_cpu_data.x86 > 3)
                 {
-#ifdef FIREGL_USWC_SUPPORT                
+#ifdef FIREGL_USWC_SUPPORT
                     if (!firegl_pat_enabled)
-#endif                    
+#endif
                     {
                         pgprot_val(vma->vm_page_prot) |= _PAGE_PCD;
                         pgprot_val(vma->vm_page_prot) &= ~_PAGE_PWT;
                     }
-#ifdef FIREGL_USWC_SUPPORT                    
+#ifdef FIREGL_USWC_SUPPORT
                     else
                     {
                         vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
-                    }    
-#endif                    
+                    }
+#endif
                 }
 #endif /* __i386__ */
 #ifdef __ia64__
@@ -3908,7 +3820,7 @@ int ATI_API_CALL __ke_vm_map(struct file* filp,
             }
 			break;
 
-#ifdef FIREGL_USWC_SUPPORT                
+#ifdef FIREGL_USWC_SUPPORT
         case __KE_ADPT_REG:
 			{
 #ifdef __ia64__
@@ -3928,7 +3840,7 @@ int ATI_API_CALL __ke_vm_map(struct file* filp,
                     }
                     else
                     {
-                        vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 
+                        vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
                     }
                 }
 #endif /* __i386__ */
@@ -3947,7 +3859,7 @@ int ATI_API_CALL __ke_vm_map(struct file* filp,
             vma->vm_ops = &vm_ops;
             }
 			break;
-#endif                    
+#endif
 
         case __KE_SHM:
             vma->vm_flags |= VM_SHM | VM_RESERVED; /* Don't swap */
@@ -3981,7 +3893,7 @@ int ATI_API_CALL __ke_vm_map(struct file* filp,
 
 #ifdef __AGP__BUILTIN__
         case __KE_AGP:
-            // if(dev->agp->cant_use_aperture == 1) 
+            // if(dev->agp->cant_use_aperture == 1)
 #ifdef __ia64__
             {
                 /*
@@ -4005,9 +3917,9 @@ int ATI_API_CALL __ke_vm_map(struct file* filp,
                     if( firegl_pat_enabled )
                     {
                         vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
-                    }    
+                    }
                 }
-#endif                
+#endif
 
                 if (REMAP_PAGE_RANGE(vma,offset))
                 {
@@ -4024,8 +3936,8 @@ int ATI_API_CALL __ke_vm_map(struct file* filp,
 #endif
             break;
         case __KE_AGP_BQS:
-            // if(dev->agp->cant_use_aperture == 1) 
-#ifdef __ia64__			
+            // if(dev->agp->cant_use_aperture == 1)
+#ifdef __ia64__
             {
                 /*
                  * On some systems we can't talk to bus dma address from
@@ -4048,9 +3960,9 @@ int ATI_API_CALL __ke_vm_map(struct file* filp,
                     if( firegl_pat_enabled )
                     {
                        vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
-                    }   
+                    }
                 }
-#endif                
+#endif
 
                 if (REMAP_PAGE_RANGE(vma,offset))
                 {
@@ -4079,15 +3991,15 @@ int ATI_API_CALL __ke_vm_map(struct file* filp,
             break;
 
          case __KE_GART_USWC:
-#ifdef FIREGL_USWC_SUPPORT         
+#ifdef FIREGL_USWC_SUPPORT
             if (boot_cpu_data.x86 > 3)
             {
                 if( firegl_pat_enabled )
                 {
                     vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
-                }    
+                }
             }
-#endif            
+#endif
             // fall through
          case __KE_GART_CACHEABLE:
              vma->vm_flags |= VM_RESERVED;
@@ -4137,7 +4049,7 @@ extern struct _agp_memory *_X(agp_allocate_memory_phys_list)(size_t, u32, u64 *)
 #define FIREGL_agp_backend_release  _X(agp_backend_release)
 #define FIREGL_agp_memory           _X(agp_memory)
 
-unsigned int __ke_firegl_agpgart_inuse = AGPGART_INUSE_NONE;				
+unsigned int __ke_firegl_agpgart_inuse = AGPGART_INUSE_NONE;
 
 #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
 /*****************************************************************************/
@@ -4252,7 +4164,7 @@ static
 int ATI_API_CALL __ke_agpgart_available(__ke_pci_dev_t *pcidev, int use_internal)
 {
     drm_agp_module_stub = &drm_agp;
-    __ke_firegl_agpgart_inuse = KERNEL26_AGPGART_INUSE;	
+    __ke_firegl_agpgart_inuse = KERNEL26_AGPGART_INUSE;
     {
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
         firegl_pci_device = (struct pci_dev*)(void*)pcidev;
@@ -4305,7 +4217,7 @@ int ATI_API_CALL __ke_agp_available(__ke_pci_dev_t *pcidev, int use_internal)
     } else {
          available = __ke_firegl_agpgart_available();
     }
-	
+
     return available;
 }
 
@@ -4410,7 +4322,7 @@ void ATI_API_CALL __ke_agp_copy_info(__ke_agp_kern_info_t* info)
 
     if (AGP_AVAILABLE(copy_info))
     {
-        struct agp_kern_info kern;    
+        struct agp_kern_info kern;
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
         if (firegl_agp_bridge == NULL)
@@ -4508,7 +4420,7 @@ int ATI_API_CALL __ke_agp_enable(unsigned long mode)
 
 int ATI_API_CALL __ke_read_agp_caps_registers(__ke_pci_dev_t* dev, unsigned int *caps)
 {
-    return -EINVAL;	
+    return -EINVAL;
 }
 
 int ATI_API_CALL __ke_agp_acquire(__ke_pci_dev_t* dev)
@@ -4550,9 +4462,9 @@ int ATI_API_CALL __ke_smp_processor_id(void)
 
 /** \brief Runs a function on all other CPUs
  *  \param func_to_call function to be called on all other cpus
- *  \return None 
+ *  \return None
  */
-void ATI_API_CALL KCL_CallFuncOnOtherCpus(firegl_void_routine_t func_to_call) 
+void ATI_API_CALL KCL_CallFuncOnOtherCpus(firegl_void_routine_t func_to_call)
 {
 #ifdef CONFIG_SMP
 	smp_call_function( firegl_smp_func_parameter_wrap, (void*)func_to_call, 0, 1 );
@@ -4659,7 +4571,7 @@ int ATI_API_CALL __ke_has_PSE(void)
 
 int ATI_API_CALL KCL_is_pat_enabled(void)
 {
-   return firegl_pat_enabled; 
+   return firegl_pat_enabled;
 }
 
 static int ATI_API_CALL KCL_has_pat(void)
@@ -4675,7 +4587,7 @@ static void KCL_setup_pat(void *info)
 {
     unsigned long cr0=0, cr4=0;
     unsigned long flags;
-  
+
     local_irq_save(flags);
     cr0 = read_cr0() | 0x40000000;
     write_cr0(cr0);
@@ -4706,7 +4618,7 @@ static void  KCL_restore_pat(void *info)
 {
     unsigned long cr0 = 0, cr4 = 0;
     unsigned long flags;
-  
+
     local_irq_save(flags);
     cr0 = read_cr0() | 0x40000000;
     write_cr0(cr0);
@@ -4718,7 +4630,7 @@ static void  KCL_restore_pat(void *info)
        write_cr4(cr4 & ~X86_CR4_PGE);
     }
      __flush_tlb();
-  
+
     wrmsr(MSR_IA32_CR_PAT,  KCL_orig_pat[0], KCL_orig_pat[1]);
 
     cr0 = read_cr0();
@@ -4741,7 +4653,7 @@ static int ATI_API_CALL KCL_enable_pat(void)
          __KE_INFO("USWC is disabled in module parameters\n");
          return 0;
      }
-     
+
      if (!KCL_has_pat())
      {
         return 0;
@@ -4751,13 +4663,13 @@ static int ATI_API_CALL KCL_enable_pat(void)
 
      for ( i = 0; i < 2; i++ )
      {
-        for (j = 0; j < 4; j ++)    
+        for (j = 0; j < 4; j ++)
         {
             if (((KCL_orig_pat[i] >> (j * 8)) & 0xFF) == 1)
-            { 
+            {
                __KE_ERROR("Pat entry %d is already configured\n", (i+1)*(j+1));
                return 0;
-            } 
+            }
         }
     }
 
@@ -4829,7 +4741,7 @@ typedef struct tag_kasContext_t
 } kasContext_t;
 
 /** \brief KAS context */
-static kasContext_t kasContext; 
+static kasContext_t kasContext;
 
 /** \brief Kernel support required to enable KAS */
 #if defined(cmpxchg)                        && \
@@ -5137,7 +5049,7 @@ unsigned int ATI_API_CALL KAS_Ih_Execute(KAS_IhRoutine_t ih_routine,
     DBG_TRACE("Interrupt handler returned 0x%08X", ret);
 
     kasSetExecutionLevel(orig_level);
-    spin_unlock(&kasContext.lock_ih); 
+    spin_unlock(&kasContext.lock_ih);
 
     DBG_LEAVE("%d", ret);
     return ret;
@@ -5412,7 +5324,7 @@ typedef struct tag_kasSlabCache_t
 #endif
     spinlock_t lock;            /* OS spinlock object protecting the cache */
     unsigned int routine_type;  /* Type of routine the cache might be accessed from */
-    char name[14];              /* Cache object name (kernel 2.4 restricts its length to 19 chars) */
+    char name[24];              /* Cache object name (kernel 2.4 restricts its length to 19 chars) */
 } kasSlabCache_t;
 
 /** \brief Return Slab Cache object size
@@ -5450,7 +5362,8 @@ unsigned int ATI_API_CALL KAS_SlabCache_Initialize(void* hSlabCache,
 
     slabcache_obj->routine_type = access_type;
     spin_lock_init(&(slabcache_obj->lock));
-    sprintf(slabcache_obj->name, "kas(%08lX)",(unsigned long)slabcache_obj);
+    snprintf(slabcache_obj->name, sizeof(slabcache_obj->name),
+		"kas(%p)", slabcache_obj);
 
     DBG_TRACE("creating slab object '%s'", slabcache_obj->name);
 
@@ -6366,7 +6279,7 @@ unsigned int ATI_API_CALL KAS_AtomicAddInt(
 
     kas_xadd(puiDestination, iAdd, ret, "l");
 
-    return ret + iAdd; 
+    return ret + iAdd;
 #else
     return 0xDEADC0DE; /* To make compiler happy */
 #endif
@@ -6449,7 +6362,7 @@ long ATI_API_CALL KAS_ScheduleTimeout(long n_jiffies)
 #ifdef FIREGL_CF_SUPPORT
 
 void *ATI_API_CALL KCL_lock_init()
-{   
+{
     spinlock_t *lock;
 
     lock = kmalloc(sizeof(*lock), GFP_KERNEL);
@@ -6461,7 +6374,7 @@ void *ATI_API_CALL KCL_lock_init()
 }
 
 void ATI_API_CALL KCL_lock_deinit(void *plock)
-{   
+{
     if (plock == NULL)
     {
         __KE_ERROR("plock is NULL\n");
diff --git a/firegl_public.h b/firegl_public.h
index fc49d6e..8cc18ed 100644
--- a/firegl_public.h
+++ b/firegl_public.h
@@ -78,7 +78,7 @@ do { \
     if (!pgd_present(*(pgd_p)))	\
     { \
         __KE_ERROR("FATAL ERROR: User queue buffer not present! (pgd)\n"); \
-        return (unsigned long)NOPAGE_SIGBUS;   /* Something bad happened; generate SIGBUS */ \
+        return VM_FAULT_SIGBUS;   /* Something bad happened; generate SIGBUS */ \
         /* alternatively we could generate a NOPAGE_OOM "out of memory" */ \
     } \
 } while(0)
@@ -91,7 +91,7 @@ do { \
     if (!pud_present(*(pud_p)))	\
     { \
         __KE_ERROR("FATAL ERROR: User queue buffer not present! (pud)\n"); \
-        return (unsigned long)NOPAGE_SIGBUS;   /* Something bad happened; generate SIGBUS */ \
+        return VM_FAULT_SIGBUS;   /* Something bad happened; generate SIGBUS */ \
         /* alternatively we could generate a NOPAGE_OOM "out of memory" */ \
     } \
     pmd_p = pmd_offset(pud_p, pte_linear); \
@@ -111,7 +111,7 @@ do { \
     if (!pmd_present(*(pmd_p)))	\
     { \
         __KE_ERROR("FATAL ERROR: User queue buffer not present! (pmd)\n"); \
-        return (unsigned long)NOPAGE_SIGBUS;   /* Something bad happened; generate SIGBUS */ \
+        return VM_FAULT_SIGBUS;   /* Something bad happened; generate SIGBUS */ \
         /* alternatively we could generate a NOPAGE_OOM "out of memory" */ \
     } \
 } while(0)
@@ -157,7 +157,7 @@ do { \
     if (!pte_present(pte)) \
     { \
         __KE_ERROR("FATAL ERROR: User queue buffer not present! (pte)\n"); \
-        return (unsigned long)NOPAGE_SIGBUS;   /* Something bad happened; generate SIGBUS */ \
+        return VM_FAULT_SIGBUS;   /* Something bad happened; generate SIGBUS */ \
         /* alternatively we could generate a NOPAGE_OOM "out of memory" */ \
     } \
 } while(0)
-- 
1.5.6.rc2.45.gdc92c
EOT
cd -
fi

[ "$VER" = "8-7" ] && patch -p1 <<'EOT'
diff -Nru 8-7/packages/Ubuntu/dists/intrepid/dkms.conf.in 8-7.hotfix/packages/Ubuntu/dists/intrepid/dkms.conf.in
--- 8-7/packages/Ubuntu/dists/intrepid/dkms.conf.in	2008-07-16 21:10:32.000000000 +0200
+++ 8-7.hotfix/packages/Ubuntu/dists/intrepid/dkms.conf.in	2008-08-18 23:29:24.000000000 +0200
@@ -5,3 +5,9 @@
 MAKE[0]="pushd ${dkms_tree}/fglrx/#CVERSION#/build; sh make.sh --nohints --uname_r=$kernelver; popd"
 DEST_MODULE_LOCATION[0]="/kernel/drivers/char/drm"
 AUTOINSTALL="yes"
+PATCH[0]="2.6.26_support.patch"
+PATCH_MATCH[0]="^2.6.2[6-9]"
+PATCH[1]="2.6.27_support.patch"
+PATCH_MATCH[1]="^2.6.2[7-9]"
+PATCH[2]="2.6.27_sysrq_key_disable.patch"
+PATCH_MATCH[2]="^2.6.2[7-9]"
diff -Nru 8-7/packages/Ubuntu/dists/intrepid/fglrx-kernel-source.install.in 8-7.hotfix/packages/Ubuntu/dists/intrepid/fglrx-kernel-source.install.in
--- 8-7/packages/Ubuntu/dists/intrepid/fglrx-kernel-source.install.in	2008-07-16 21:10:32.000000000 +0200
+++ 8-7.hotfix/packages/Ubuntu/dists/intrepid/fglrx-kernel-source.install.in	2008-08-18 23:28:18.000000000 +0200
@@ -9,3 +9,4 @@
 debian/replacements/*				usr/src/fglrx-#CVERSION#
 arch/#ARCH#/lib/modules/fglrx/build_mod/lib*    usr/src/fglrx-#CVERSION#
 debian/dkms.conf                                usr/src/fglrx-#CVERSION#
+debian/patches					usr/src/fglrx-#CVERSION#
diff -Nru 8-7/packages/Ubuntu/dists/intrepid/patches/2.6.26_support.patch 8-7.hotfix/packages/Ubuntu/dists/intrepid/patches/2.6.26_support.patch
--- 8-7/packages/Ubuntu/dists/intrepid/patches/2.6.26_support.patch	1970-01-01 01:00:00.000000000 +0100
+++ 8-7.hotfix/packages/Ubuntu/dists/intrepid/patches/2.6.26_support.patch	2008-08-18 23:28:18.000000000 +0200
@@ -0,0 +1,1632 @@
+#This patch enables 2.6.26 support until AMD officially supports it.
+#It is originally by   Zilvina Valinskas <zilvinas@ilibox.com>
+#and adapted for AMD's 8-6 driver by Mario Limonciello <Mario_Limonciello@Dell.com>
+
+diff -Nur -x '*.orig' -x '*~' fglrx-installer-8.512/lib/modules/fglrx/build_mod/firegl_public.c fglrx-installer-8.512.new/lib/modules/fglrx/build_mod/firegl_public.c
+--- build_mod/firegl_public.c	2008-07-21 14:32:08.000000000 -0400
++++ fglrx-installer-8.512.new/lib/modules/fglrx/build_mod/firegl_public.c	2008-07-21 14:31:48.000000000 -0400
+@@ -24,13 +24,13 @@
+ // ============================================================
+ #include <linux/version.h>
+ 
+-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) 
++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+ #error Kernel versions older than 2.6.0 are no longer supported by this module.
+-#endif 
++#endif
+ 
+ #include <linux/autoconf.h>
+ 
+-#if !defined(CONFIG_X86_PC) 
++#if !defined(CONFIG_X86_PC)
+ #if !defined(CONFIG_X86_64)
+ #if !defined(CONFIG_X86_VOYAGER)
+ #if !defined(CONFIG_X86_NUMAQ)
+@@ -62,10 +62,10 @@
+  * distribution would even include such a kernel patch. */
+ #ifdef CONFIG_MEM_MIRROR
+ /* Prevent asm/mm_track.h from being included in subsequent
+- * kernel headers as that would redefine CONFIG_MEM_MIRROR. */ 
++ * kernel headers as that would redefine CONFIG_MEM_MIRROR. */
+ #ifndef CONFIG_X86_64
+ #define __I386_MMTRACK_H__
+-#define mm_track(ptep)                 
++#define mm_track(ptep)
+ #else
+ #define __X86_64_MMTRACK_H__
+ #define mm_track_pte(ptep)
+@@ -93,7 +93,7 @@
+ #include <linux/kernel.h>
+ #include <linux/fs.h>
+ #include <linux/proc_fs.h>
+-#include <linux/init.h>
++//#include <linux/init.h>
+ #include <linux/file.h>
+ #include <linux/pci.h>
+ #include <linux/wait.h>
+@@ -151,8 +151,8 @@
+ #include "linux/freezer.h"
+ #endif
+ 
+-//  For 2.6.18 or higher, the UTS_RELEASE is defined in the linux/utsrelease.h. 
+-#ifndef UTS_RELEASE 
++//  For 2.6.18 or higher, the UTS_RELEASE is defined in the linux/utsrelease.h.
++#ifndef UTS_RELEASE
+ #include <linux/utsrelease.h>
+ #endif
+ 
+@@ -215,7 +215,7 @@
+ 
+ static void ATI_API_CALL __ke_printstr(const char *str);
+ 
+-static struct pci_device_id fglrx_pci_table[] = 
++static struct pci_device_id fglrx_pci_table[] =
+ {
+ #define FGL_ASIC_ID(x)                      \
+    {                           \
+@@ -283,7 +283,7 @@
+ 
+ static int firegl_pat_enabled = 0;
+ static unsigned long KCL_pat[2];
+-static unsigned long KCL_orig_pat[2]; 
++static unsigned long KCL_orig_pat[2];
+ 
+ static int ATI_API_CALL KCL_enable_pat(void);
+ static void ATI_API_CALL KCL_disable_pat(void);
+@@ -322,7 +322,7 @@
+ #endif
+ 
+ __ke_ssize_t ip_firegl_read( struct file *filp,
+-                         char *buf, 
++                         char *buf,
+                          __ke_size_t size,
+                          __ke_loff_t *off_ptr)
+ {
+@@ -334,7 +334,7 @@
+ }
+ 
+ __ke_ssize_t ip_firegl_write( struct file *filp,
+-                          const char *buf, 
++                          const char *buf,
+                           __ke_size_t size,
+                           __ke_loff_t *off_ptr)
+ {
+@@ -477,34 +477,34 @@
+     return firegl_debug_proc_write(file, buffer, count, data);     
+ }
+ 
+-static int 
++static int
+ firegl_interrupt_open_wrap(
+-        struct inode *inode, 
+-        struct file *file) 
++        struct inode *inode,
++        struct file *file)
+ {
+     return firegl_interrupt_open(inode, file);
+ }
+ 
+-static int 
++static int
+ firegl_interrupt_release_wrap(
+-        struct inode *inode, 
+-        struct file *file) 
++        struct inode *inode,
++        struct file *file)
+ {
+     return firegl_interrupt_release(inode, file);
+ }
+ 
+-static ssize_t 
++static ssize_t
+ firegl_interrupt_read_wrap(
+-        struct file *user_file, 
+-        char __user *user_buf, 
+-        size_t user_buf_size, 
++        struct file *user_file,
++        char __user *user_buf,
++        size_t user_buf_size,
+         loff_t *user_file_pos)
+ {
+     return (ssize_t) firegl_interrupt_read(user_file, user_buf, user_buf_size, user_file_pos);
+ }
+ 
+-static unsigned int 
+-firegl_interrupt_poll_wrap(struct file *user_file, poll_table *pt) 
++static unsigned int
++firegl_interrupt_poll_wrap(struct file *user_file, poll_table *pt)
+ {
+     if(firegl_interrupt_poll(user_file, (__ke_poll_table*)pt))
+     {
+@@ -516,11 +516,11 @@
+     }
+ }
+ 
+-static ssize_t 
++static ssize_t
+ firegl_interrupt_write_wrap(
+-        struct file *user_file, 
+-        const char __user *user_buf, 
+-        size_t user_buf_size, 
++        struct file *user_file,
++        const char __user *user_buf,
++        size_t user_buf_size,
+         loff_t *user_file_pos)
+ {
+     return (ssize_t) firegl_interrupt_write(user_file, user_buf, user_buf_size, user_file_pos);
+@@ -530,7 +530,7 @@
+  *  \param func function to be wrapped
+  *  \return None */
+ 
+-static void 
++static void
+ firegl_smp_func_parameter_wrap(
+ void *func)
+ {
+@@ -545,7 +545,7 @@
+     .write      = firegl_interrupt_write_wrap
+ };
+ 
+-__ke_proc_list_t firegl_proc_list[] = 
++__ke_proc_list_t firegl_proc_list[] =
+ {
+     { "name",           drm_name_info_wrap,         NULL},
+     { "mem",            drm_mem_info_wrap,          NULL},
+@@ -613,11 +613,11 @@
+         {
+ 		    ent->proc_fops = (struct file_operations*)list->fops;
+         }
+-       
++
+         {
+             ent->data = (dev->pubdev.signature == FGL_DEVICE_SIGNATURE)? firegl_find_device(minor) : (dev);
+         }
+-        
++
+         list++;
+ 	}
+ 
+@@ -663,7 +663,7 @@
+     {
+         remove_proc_entry("dri", NULL);
+         __KE_DEBUG("remove proc dri. \n");
+-    }    
++    }
+     return 0;
+ }
+ 
+@@ -701,12 +701,12 @@
+ {
+ 	int i;
+         int count = 0;
+-        
++
+         __KE_DEBUG("firegl_stub_getminor: name=\"%s\"\n", name);
+ 
+-	for( i = 0; i < FIREGL_STUB_MAXCARDS; i++ ) 
++	for( i = 0; i < FIREGL_STUB_MAXCARDS; i++ )
+         {
+-	    if( !firegl_stub_list[i].fops ) 
++	    if( !firegl_stub_list[i].fops )
+             {
+ 		firegl_stub_list[i].name = name;
+ 		firegl_stub_list[i].fops = fops;
+@@ -733,16 +733,16 @@
+     if (minor < 0 || minor >= FIREGL_STUB_MAXCARDS)
+     {
+         return -1;
+-    }    
++    }
+     firegl_proc_cleanup(minor, firegl_stub_root, firegl_stub_list[minor].dev_root, firegl_stub_list[minor].proclist);
+     firegl_stub_list[minor].name = NULL;
+     firegl_stub_list[minor].fops = NULL;
+     firegl_stub_list[minor].proclist = NULL;
+ 
+-    if( minor == (firegl_minors-1) ) 
++    if( minor == (firegl_minors-1) )
+     {
+         unregister_chrdev(DRM_MAJOR, "drm");
+-    }   
++    }
+     return 0;
+ }
+ 
+@@ -766,7 +766,7 @@
+         return -1;
+     } else if(err == -EBUSY) {
+ 
+-        // the registering of the module's device has failed 
++        // the registering of the module's device has failed
+         // because there was already some other drm module loaded.
+         __KE_DEBUG("register_chrdev() failed with -EBUSY\n");
+ 	return -1;
+@@ -798,7 +798,7 @@
+ /* Starting from 2.6.14, kernel has new struct defined for pm_message_t,
+    we have to handle this case separately.
+    2.6.11/12/13 kernels have pm_message_t defined as int and older kernels
+-   don't have pm_message_t defined. 
++   don't have pm_message_t defined.
+  */
+ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
+ static int fglrx_pci_suspend(struct pci_dev *pdev, pm_message_t pm_event)
+@@ -834,9 +834,9 @@
+ 
+     if (!ret)
+     {
+-        
+-    // since privdev->pcidev is acquired in X server, use pdev 
+-    // directly here to allow suspend/resume without X server start. 
++
++    // since privdev->pcidev is acquired in X server, use pdev
++    // directly here to allow suspend/resume without X server start.
+         firegl_pci_save_state((__ke_pci_dev_t*)pdev, privdev);
+         pci_disable_device(pdev);
+         PMSG_EVENT(pdev->dev.power.power_state) = state;
+@@ -888,13 +888,13 @@
+     // before pci_set_master!
+     firegl_pci_restore_state((__ke_pci_dev_t*)pdev, privdev);
+ 
+-    if (pci_enable_device(pdev)) 
++    if (pci_enable_device(pdev))
+     {
+         __KE_ERROR("Cannot enable PCI device.\n");
+-    }    
++    }
+ 
+     pci_set_master(pdev);
+- 
++
+     firegl_cail_powerup(privdev);
+ 
+     if (PMSG_EVENT(pdev->dev.power.power_state) == PM_EVENT_SUSPEND)
+@@ -905,7 +905,7 @@
+     return 0;
+ }
+ 
+-static struct pci_driver fglrx_pci_driver = 
++static struct pci_driver fglrx_pci_driver =
+ {
+     .name           = "fglrx_pci",
+     .id_table       = fglrx_pci_table,
+@@ -961,10 +961,10 @@
+     {
+         pid = (struct pci_device_id *) &fglrx_pci_table[i];
+         pdev = NULL;
+-        while (( pdev = pci_get_subsys(pid->vendor, 
+-                                       pid->device, 
+-                                       PCI_ANY_ID, 
+-                                       PCI_ANY_ID, 
++        while (( pdev = pci_get_subsys(pid->vendor,
++                                       pid->device,
++                                       PCI_ANY_ID,
++                                       PCI_ANY_ID,
+                                        pdev)) != NULL)
+         {
+             num_of_devices++;
+@@ -974,7 +974,7 @@
+ 
+     if (firegl_init_device_heads(num_of_devices))
+     {
+-        return -ENOMEM;     
++        return -ENOMEM;
+     }
+ 
+     for (i=0; fglrx_pci_table[i].vendor != 0; i++)
+@@ -982,15 +982,15 @@
+         pid = (struct pci_device_id *) &fglrx_pci_table[i];
+ 
+         pdev = NULL;
+-        while (( pdev = pci_get_subsys(pid->vendor, 
+-                                       pid->device, 
+-                                       PCI_ANY_ID, 
+-                                       PCI_ANY_ID, 
++        while (( pdev = pci_get_subsys(pid->vendor,
++                                       pid->device,
++                                       PCI_ANY_ID,
++                                       PCI_ANY_ID,
+                                        pdev)) != NULL)
+         {
+             if ((ret_code = firegl_get_dev(pubdev, pdev)))
+             {
+-                return ret_code; 
++                return ret_code;
+             }
+ 
+             j++;
+@@ -1023,7 +1023,7 @@
+     // init global vars that are in fact constants
+     __ke_HZ = HZ;
+ 
+-#ifdef _KE_SERIAL_DEBUG  
++#ifdef _KE_SERIAL_DEBUG
+     __ke_SetSerialPort();
+ #endif
+ 
+@@ -1035,11 +1035,11 @@
+         return retcode;
+     }
+ 
+-#ifdef FIREGL_CF_SUPPORT    
++#ifdef FIREGL_CF_SUPPORT
+     adapter_chain_init();
+     cf_object_init();
+-#endif    
+-     
++#endif
++
+     // init DRM proc list
+     drm_proclist = kmalloc((DRM_PROC_ENTRIES + 1) * sizeof(__ke_proc_list_t), GFP_KERNEL);
+     if ( drm_proclist == NULL )
+@@ -1127,7 +1127,7 @@
+ 	        dev->pubdev.date,
+ 		    firegl_minors);
+ 
+-    
++
+ #ifdef FIREGL_POWER_MANAGEMENT
+     if (pci_register_driver (&fglrx_pci_driver) < 0)
+     {
+@@ -1157,12 +1157,12 @@
+     {
+        KCL_disable_pat();
+        __KE_INFO("Disable PAT\n");
+-    }   
++    }
+ #endif // FIREGL_USWC_SUPPORT
+ 
+     for (i = 0; i < count; i++)
+     {
+-        if ( firegl_stub_unregister(i) ) 
++        if ( firegl_stub_unregister(i) )
+         {
+             __KE_ERROR("Cannot unload module on minor: %d\n", i);
+         }
+@@ -1184,10 +1184,10 @@
+ 	        dev->pubdev.patchlevel,
+ 	        dev->pubdev.date);
+ 
+-#ifdef FIREGL_CF_SUPPORT    
++#ifdef FIREGL_CF_SUPPORT
+     cf_object_cleanup();
+-    adapter_chain_cleanup();    
+-#endif // FIREGL_CF_SUPPORT   
++    adapter_chain_cleanup();
++#endif // FIREGL_CF_SUPPORT
+ 
+     firegl_private_cleanup (&dev->pubdev);
+ 
+@@ -1265,18 +1265,18 @@
+ void ATI_API_CALL __ke_remove_wait_queue(__ke_wait_queue_head_t* queue_head, __ke_wait_queue_t* entry)
+ {
+ //    current->state = TASK_RUNNING;
+-    remove_wait_queue((wait_queue_head_t*)(void *)queue_head, 
++    remove_wait_queue((wait_queue_head_t*)(void *)queue_head,
+ 									(wait_queue_t*)(void *)entry);
+ }
+ 
+ void ATI_API_CALL __ke_init_waitqueue_head(__ke_wait_queue_head_t* queue_head)
+ {
+-    init_waitqueue_head((wait_queue_head_t*)(void *)queue_head); 
++    init_waitqueue_head((wait_queue_head_t*)(void *)queue_head);
+ }
+ 
+ void ATI_API_CALL __ke_wait_event_interruptible(__ke_wait_queue_head_t* queue_head, int condition)
+ {
+-    wait_event_interruptible(*((wait_queue_head_t*)(void *)queue_head), condition); 
++    wait_event_interruptible(*((wait_queue_head_t*)(void *)queue_head), condition);
+ }
+ 
+ void ATI_API_CALL __ke_poll_wait(struct file* filp, __ke_wait_queue_head_t* queue_head, __ke_poll_table* pt)
+@@ -1287,13 +1287,13 @@
+ void ATI_API_CALL *__ke_asyncio_alloc_sema()
+ {
+     int i;
+-    
++
+     for(i=0; i<FIREGL_ASYNCIO_MAX_SEMA; i++)
+     {
+         if(fireglAsyncioSemaphoreUsed[i] != 1)
+         {
+             fireglAsyncioSemaphoreUsed[i] = 1;
+-            
++
+             return &(fireglAsyncioSemaphore[i]);
+         }
+     }
+@@ -1303,7 +1303,7 @@
+ void ATI_API_CALL __ke_asyncio_free_sema(struct semaphore *pSema)
+ {
+     int i;
+-    
++
+     for(i=0; i<FIREGL_ASYNCIO_MAX_SEMA; i++)
+     {
+         if( &(fireglAsyncioSemaphore[i]) == pSema )
+@@ -1317,15 +1317,15 @@
+ void ATI_API_CALL __ke_asyncio_init_sema(void)
+ {
+     int i;
+-    
++
+     for(i=0; i<FIREGL_ASYNCIO_MAX_SEMA; i++)
+     {
+         fireglAsyncioSemaphoreUsed[i] = 0;
+     }
+-}    
++}
+ 
+-int ATI_API_CALL __ke_fasync_helper( int fd, 
+-                        struct file *filep, 
++int ATI_API_CALL __ke_fasync_helper( int fd,
++                        struct file *filep,
+                         int mode,
+                         struct fasync_struct **pasync_queue)
+ {
+@@ -1403,33 +1403,33 @@
+ {
+    struct task_struct *p;
+    int process_terminated = 1;
+-  
+-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)  
++
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
+    rcu_read_lock();
+-#else   
++#else
+    read_lock(&tasklist_lock);
+-#endif   
+-   p = find_task_by_pid( pid );
+-   if (p) 
++#endif
++   p = find_task_by_vpid( pid );
++   if (p)
+    {
+ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10)
+-      if (p->exit_state != EXIT_ZOMBIE && p->exit_state != EXIT_DEAD) 
++      if (p->exit_state != EXIT_ZOMBIE && p->exit_state != EXIT_DEAD)
+ #else
+-      if (!(p->flags & PF_EXITING)) 
++      if (!(p->flags & PF_EXITING))
+ #endif
+       {
+          process_terminated = 0;
+       }
+-   }   
+-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)  
++   }
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
+    rcu_read_unlock();
+-#else   
++#else
+    read_unlock(&tasklist_lock);
+-#endif   
++#endif
+    return process_terminated;
+ }
+ 
+-/** /brief Call global OS kernel task/thread scheduler 
++/** /brief Call global OS kernel task/thread scheduler
+  *  /return Nonzero if a system call was awakened by a signal
+  */
+ int ATI_API_CALL KCL_GetSignalStatus(void)
+@@ -1483,15 +1483,15 @@
+     unblock_all_signals();
+ }
+ 
+-#if defined(__i386__) 
++#if defined(__i386__)
+ #ifndef __HAVE_ARCH_CMPXCHG
+-static inline 
+-unsigned long __fgl_cmpxchg(volatile void *ptr, unsigned long old,            
+-                        unsigned long new, int size)                      
+-{                                                                                       
+-    unsigned long prev;                                                             
+-    switch (size) {                                                                 
+-    case 1:                                                                         
++static inline
++unsigned long __fgl_cmpxchg(volatile void *ptr, unsigned long old,
++                        unsigned long new, int size)
++{
++    unsigned long prev;
++    switch (size) {
++    case 1:
+         __asm__ __volatile__(LOCK_PREFIX "cmpxchgb %b1,%2"
+                              : "=a"(prev)
+                              : "q"(new), "m"(*__xg(ptr)), "0"(old)
+@@ -1602,7 +1602,7 @@
+  */
+ KCL_TYPE_Pid ATI_API_CALL KCL_GetPid(void)
+ {
+-    return current->pid; 
++    return current->pid;
+ }
+ 
+ /** /brief Return the current Thread Group ID
+@@ -1610,7 +1610,7 @@
+  */
+ KCL_TYPE_Pid ATI_API_CALL KCL_GetTgid(void)
+ {
+-    return current->tgid; 
++    return current->tgid;
+ }
+ 
+ /** /brief Return the effective user ID
+@@ -1706,7 +1706,7 @@
+     1
+ #else
+     0
+-#endif 
++#endif
+ };
+ 
+ /** /brief Check whether a kernel configuration parameter is defined
+@@ -1792,13 +1792,13 @@
+ #if defined(__x86_64__) || defined(__ia64__)
+ void* ATI_API_CALL __ke_pci_alloc_consistent(__ke_pci_dev_t* dev, int size, void *dma_handle)
+ {
+-	return (pci_alloc_consistent( (struct pci_dev*)(void *)dev, size, dma_handle)); 
++	return (pci_alloc_consistent( (struct pci_dev*)(void *)dev, size, dma_handle));
+ }
+ 
+ void ATI_API_CALL __ke_pci_free_consistent(__ke_pci_dev_t* dev, int size, unsigned long cpu_addr,
+ 						 unsigned int dma_handle)
+ {
+-	pci_free_consistent( (struct pci_dev*)(void *)dev, size, (void *)cpu_addr, 
++	pci_free_consistent( (struct pci_dev*)(void *)dev, size, (void *)cpu_addr,
+ 		(unsigned long)dma_handle);
+ }
+ #endif // __ia64__
+@@ -1822,7 +1822,7 @@
+ 
+ /** \brief This function maps OS independent error conditions to OS defined error codes
+  *  \param errcode OS independent error condition code
+- *  \return OS kernel defined error code corresponding to the requested error condition 
++ *  \return OS kernel defined error code corresponding to the requested error condition
+  */
+ int ATI_API_CALL KCL_GetErrorCode(KCL_ENUM_ErrorCode errcode)
+ {
+@@ -1840,7 +1840,7 @@
+ int ATI_API_CALL firegl_get_user_ptr(u32 *src, void **dst)
+ {
+   unsigned long temp;
+-  int err = get_user(temp, src); 
++  int err = get_user(temp, src);
+   *dst = (void*) temp;
+   return err;
+ }
+@@ -2019,7 +2019,7 @@
+  */
+ int ATI_API_CALL KCL_AtomicDecAndTest(KCL_TYPE_Atomic* v)
+ {
+-    return atomic_dec_and_test((atomic_t*)v); 
++    return atomic_dec_and_test((atomic_t*)v);
+ }
+ 
+ /*****************************************************************************/
+@@ -2394,7 +2394,7 @@
+     struct page *page = NULL;
+ 
+     page = vmalloc_to_page(vmalloc_addr);
+-    if(page == NULL) 
++    if(page == NULL)
+     {
+         __KE_ERROR("__ke_vmalloc_to_addr: invalid page!");
+         return NULL;
+@@ -2436,7 +2436,7 @@
+     retcode = do_munmap(current->mm,
+                         addr,
+                         len);
+-#endif                        
++#endif
+     up_write(&current->mm->mmap_sem);
+     return retcode;
+ }
+@@ -2480,10 +2480,10 @@
+        minus = !minus;
+     }
+     else
+-    {   
++    {
+        ubase = base;
+     }
+-    
++
+     do_div(un, ubase);
+     return (minus? -un : un);
+ }
+@@ -2513,7 +2513,7 @@
+     else
+     {
+        ubase = base;
+-    }   
++    }
+ 
+     rem = do_div(un, ubase);
+     return (minus? -rem : rem);
+@@ -2544,7 +2544,7 @@
+     vaddr = (void *) vmap(pages, count);
+ #else
+ #ifdef VM_MAP
+-    vaddr = (void *) vmap(pages, count, VM_MAP, PAGE_KERNEL); 
++    vaddr = (void *) vmap(pages, count, VM_MAP, PAGE_KERNEL);
+ #else
+     vaddr = (void *) vmap(pages, count, 0, PAGE_KERNEL);
+ #endif
+@@ -2600,7 +2600,7 @@
+ }
+ #endif  // defined(VM_MAP) || defined(vunmap)
+ 
+-/** \brief Reserve a memory page 
++/** \brief Reserve a memory page
+  *
+  * \param pt Kernel logical address of the page
+  *
+@@ -2612,7 +2612,7 @@
+     SetPageReserved(virt_to_page((unsigned long)pt));
+ }
+ 
+-/** \brief Unreserve a memory page 
++/** \brief Unreserve a memory page
+  *
+  * \param pt Kernel logical address of the page
+  *
+@@ -2624,7 +2624,7 @@
+     ClearPageReserved(virt_to_page((unsigned long)pt));
+ }
+ 
+-/** \brief Lock a memory page 
++/** \brief Lock a memory page
+  *
+  * \param pt Kernel logical address of the page
+  *
+@@ -2633,14 +2633,14 @@
+  */
+ void ATI_API_CALL KCL_LockMemPage(void* pt)
+ {
+-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15) 
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)
+     SetPageReserved(virt_to_page((unsigned long)pt));
+ #else
+     lock_page(virt_to_page((unsigned long)pt));
+ #endif
+ }
+ 
+-/** \brief Unlock a memory page 
++/** \brief Unlock a memory page
+  *
+  * \param pt Kernel logical address of the page
+  *
+@@ -2649,7 +2649,7 @@
+  */
+ void ATI_API_CALL KCL_UnlockMemPage(void* pt)
+ {
+-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15) 
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)
+     ClearPageReserved(virt_to_page((unsigned long)pt));
+ #else
+     unlock_page(virt_to_page((unsigned long)pt));
+@@ -2674,7 +2674,7 @@
+ 	return memory->vmptr;
+ }
+ #endif
+-                              
++
+ void* ATI_API_CALL __ke_ioremap(unsigned long offset, unsigned long size)
+ {
+     return ioremap(offset, size);
+@@ -2724,7 +2724,7 @@
+ {
+ /*Some kernel developer removed the export of symbol "flush_tlb_page" on 2.6.25 x86_64 SMP kernel.
+   Define a simple version here.*/
+-#if defined(__x86_64__) && defined(__SMP__) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)) 
++#if defined(__x86_64__) && defined(__SMP__) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25))
+     on_each_cpu(KCL_flush_tlb_one, &va, 1, 1);
+ #else
+     flush_tlb_page(vma, va);
+@@ -2884,9 +2884,9 @@
+ static inline int ptep_clear_flush_dirty(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep)
+ {
+     int ret = 0;
+-    
++
+     DBG_ENTER("0x%08X, 0x%08X, 0x%08X->0x%08X", vma, addr, ptep, *ptep);
+-    
++
+     if (pte_dirty(*ptep))
+     {
+ #ifdef __x86_64__
+@@ -2901,19 +2901,19 @@
+         {
+             pte_update(vma->vm_mm, addr, ptep);
+         }
+-#endif        
++#endif
+     }
+ 
+     DBG_TRACE("0x%08X->0x%08X", ptep, *ptep);
+-    
++
+     // Flush Translation Lookaside Buffers
+     if (ret)
+     {
+         KCL_flush_tlb_onepage(vma,addr);
+     }
+-    
++
+     DBG_LEAVE("%d", ret);
+-    
++
+     return ret;
+ }
+ #endif
+@@ -3279,7 +3279,7 @@
+        return 0;
+ #else
+     return 1;
+-#endif    
++#endif
+ #else /* !CONFIG_MTRR */
+     return 0;
+ #endif /* !CONFIG_MTRR */
+@@ -3305,7 +3305,7 @@
+ 
+ int ATI_API_CALL __ke_has_vmap(void)
+ {
+-// We disable vmap for 2.4.x kernel to work around the big memory( > 4GB ) issue. 
++// We disable vmap for 2.4.x kernel to work around the big memory( > 4GB ) issue.
+ #if defined(VM_MAP) || defined(vunmap)
+     return 1;
+ #else
+@@ -3372,7 +3372,7 @@
+ {
+     struct pci_dev* dev = (struct pci_dev*)pcidev;
+     return PCI_FUNC(dev->devfn);
+-}    
++}
+ 
+ __ke_dma_addr_t ATI_API_CALL __ke_pci_map_single (__ke_pci_dev_t *pdev, void *buffer, __ke_size_t size, int direction)
+ {
+@@ -3525,12 +3525,12 @@
+     return (int)(agpmem->page_count);
+ }
+ 
+-void ATI_API_CALL __ke_agp_memory_get_memory(struct _agp_memory* agpmem, 
++void ATI_API_CALL __ke_agp_memory_get_memory(struct _agp_memory* agpmem,
+                                              unsigned long **memory_ptr)
+ {
+     __KE_DEBUG("[%s] agpmem=0x%016lx agpmem->memory=0x%016lx [0]=0x%016x",
+-               __FUNCTION__, 
+-               (unsigned long)agpmem, 
++               __FUNCTION__,
++               (unsigned long)agpmem,
+                (unsigned long)agpmem->memory,
+                (agpmem->memory)[0]);
+ 
+@@ -3539,18 +3539,9 @@
+ 
+ /*****************************************************************************/
+ 
+-#ifndef NOPAGE_SIGBUS
+-#define NOPAGE_SIGBUS 0
+-#endif /* !NOPAGE_SIGBUS */
+-
+ typedef struct page mem_map_t;
+ typedef mem_map_t *vm_nopage_ret_t;
+ 
+-static __inline__ vm_nopage_ret_t do_vm_nopage(struct vm_area_struct* vma,
+-                                                     unsigned long address)
+-{
+-    return 0;   /* Disallow mremap */
+-}
+ 
+ #ifdef __AGP__BUILTIN__
+ #ifdef __ia64__
+@@ -3575,19 +3566,20 @@
+ 			return page;
+ 		}
+ 	}
+-	return NOPAGE_SIGBUS;		/* Disallow mremap */
++	return VM_FAULT_SIGBUS;		/* Disallow mremap */
+ }
+ 
+ #endif /* __ia64__ */
+ #endif /* __AGP__BUILTIN__ */
+ 
+ 
+-static __inline__ vm_nopage_ret_t do_vm_shm_nopage(struct vm_area_struct* vma,
+-                                                   unsigned long address)
++static __inline__ int do_vm_shm_nopage(struct vm_area_struct* vma,
++				       struct vm_fault *vmf)
+ {
+     pgd_t* pgd_p;
+     pmd_t* pmd_p;
+     pte_t  pte;
++    unsigned long address = (unsigned long)vmf->virtual_address;
+     unsigned long vma_offset;
+     unsigned long pte_linear;
+     mem_map_t* pMmPage;
+@@ -3616,7 +3608,7 @@
+             (unsigned long)__ke_vm_offset(vma));
+ 
+     if (address > vma->vm_end)
+-        return NOPAGE_SIGBUS; /* address is out of range */
++        return VM_FAULT_SIGBUS; /* address is out of range */
+ 
+     /*  Calculate offset into VMA */
+     vma_offset = address - vma->vm_start;
+@@ -3628,7 +3620,7 @@
+     pte_linear = firegl_get_addr_from_vm(vma);
+     if (!pte_linear)
+     {
+-        return NOPAGE_SIGBUS; /* bad address */
++        return VM_FAULT_SIGBUS; /* bad address */
+     }
+     pte_linear += vma_offset;
+ 
+@@ -3656,7 +3648,9 @@
+ 
+     //  __KE_DEBUG3("vm-address 0x%08lx => kernel-page-address 0x%p\n",
+     //    address, page_address(pMmPage));
+-    return pMmPage;
++    vmf->page = pMmPage;
++
++    return 0;
+ }
+ 
+ /*
+@@ -3665,8 +3659,10 @@
+       (which is one ore more pages in size)
+ 
+ */
+-static __inline__ vm_nopage_ret_t do_vm_dma_nopage(struct vm_area_struct* vma, unsigned long address)
++static __inline__ int do_vm_dma_nopage(struct vm_area_struct* vma,
++				       struct vm_fault *vmf)
+ {
++    unsigned long address = (unsigned long) vmf->virtual_address;
+     unsigned long kaddr;
+     mem_map_t* pMmPage;
+ 
+@@ -3682,7 +3678,7 @@
+     kaddr = firegl_get_addr_from_vm(vma);
+     if (!kaddr)
+     {
+-        return NOPAGE_SIGBUS; /* bad address */
++        return VM_FAULT_SIGBUS; /* bad address */
+     }
+     kaddr += (address - vma->vm_start);
+ 
+@@ -3694,19 +3690,23 @@
+     // with drm_alloc_pages, which marks all pages as reserved. Reserved
+     // pages' usage count is not decremented by the kernel during unmap!!!
+     //
+-    // For kernel >= 2.6.15, We should reenable this, because the VM sub-system 
+-    // will decrement the pages' usage count even for the pages marked as reserved 
++    // For kernel >= 2.6.15, We should reenable this, because the VM sub-system
++    // will decrement the pages' usage count even for the pages marked as reserved
+     // 								- MC.
+     get_page(pMmPage); /* inc usage count of page */
+ #endif
+ 
+     __KE_DEBUG3("vm-address 0x%08lx => kernel-page-address 0x%p\n",
+         address, page_address(pMmPage));
+-    return pMmPage;
++    vmf->page = pMmPage;
++
++    return 0;
+ }
+ 
+-static __inline__ vm_nopage_ret_t do_vm_kmap_nopage(struct vm_area_struct* vma, unsigned long address)
++static __inline__ int do_vm_kmap_nopage(struct vm_area_struct* vma,
++					struct vm_fault *vmf)
+ {
++    unsigned long address = (unsigned long) vmf->virtual_address;
+     unsigned long kaddr;
+     mem_map_t* pMmPage;
+ 
+@@ -3716,13 +3716,14 @@
+     if ((pMmPage = (mem_map_t*) firegl_get_pagetable_page_from_vm(vma)))
+     {
+         get_page(pMmPage);
+-        return pMmPage;
++	vmf->page = pMmPage;
++        return 0;
+     }
+ 
+     kaddr = firegl_get_addr_from_vm(vma);
+     if (!kaddr)
+     {
+-        return NOPAGE_SIGBUS; /* bad address */
++        return VM_FAULT_SIGBUS; /* bad address */
+     }
+     kaddr += (address - vma->vm_start);
+ 
+@@ -3735,50 +3736,52 @@
+ 
+     __KE_DEBUG3("vm-address 0x%08lx => kernel-page-address 0x%p\n", address, page_address(pMmPage));
+ 
+-    return pMmPage;
++    vmf->page = pMmPage;
++    return 0;
+ }
+ 
+-/** 
++/**
+  **
+- **  This routine is intented to locate the page table through the 
++ **  This routine is intented to locate the page table through the
+  **  pagelist table created earlier in dev-> pcie
+  **/
+-static __inline__ vm_nopage_ret_t do_vm_pcie_nopage(struct vm_area_struct* vma,
+-                                                         unsigned long address)
++static __inline__ int do_vm_pcie_nopage(struct vm_area_struct* vma,
++					struct vm_fault *vmf)
+ {
+ 
++    unsigned long address = (unsigned long)vmf->virtual_address;
+     unsigned long vma_offset;
+-    unsigned long i; 
++    unsigned long i;
+     mem_map_t* pMmPage;
+     struct firegl_pcie_mem* pciemem;
+     unsigned long* pagelist;
+-    
++
+     drm_device_t *dev = (drm_device_t *)firegl_get_dev_from_vm(vma);
+     if (dev == NULL)
+     {
+         __KE_ERROR("dev is NULL\n");
+-        return NOPAGE_SIGBUS;
++        return VM_FAULT_SIGBUS;
+     }
+ 
+     if (address > vma->vm_end)
+     {
+         __KE_ERROR("address out of range\n");
+-        return NOPAGE_SIGBUS; /* address is out of range */
++        return VM_FAULT_SIGBUS; /* address is out of range */
+     }
+     pciemem = firegl_get_pciemem_from_addr ( vma, address);
+     if (pciemem == NULL)
+     {
+         __KE_ERROR("No pciemem found! \n");
+-        return NOPAGE_SIGBUS;
+-    }    
++        return VM_FAULT_SIGBUS;
++    }
+     pagelist = firegl_get_pagelist_from_vm(vma);
+ 
+-    if (pagelist == NULL) 
++    if (pagelist == NULL)
+     {
+         __KE_ERROR("No pagelist! \n");
+-        return NOPAGE_SIGBUS;
++        return VM_FAULT_SIGBUS;
+     }
+-     
++
+     /** Find offset in  vma */
+     vma_offset = address - vma->vm_start;
+     /** Which entry in the pagelist */
+@@ -3790,15 +3793,17 @@
+     if (page_address(pMmPage) == 0x0)
+     {
+         __KE_ERROR("Invalid page address\n");
+-        return NOPAGE_SIGBUS;
++        return VM_FAULT_SIGBUS;
+     }
+-    return pMmPage;
++
++    vmf->page = pMmPage;
++    return 0;
+ }
+ 
+-static __inline__ vm_nopage_ret_t do_vm_gart_nopage(struct vm_area_struct* vma,
+-                                                    unsigned long address)
++static __inline__ int do_vm_gart_nopage(struct vm_area_struct* vma,
++					struct vm_fault *vmf)
+ {
+-
++    unsigned long address = (unsigned long) vmf->virtual_address;
+     unsigned long page_addr;
+     unsigned long offset;
+     struct page *page;
+@@ -3806,36 +3811,31 @@
+     if (address > vma->vm_end)
+     {
+         __KE_ERROR("Invalid virtual address\n");
+-        return NOPAGE_SIGBUS;   /* Disallow mremap */
+-    }          
++        return VM_FAULT_SIGBUS;   /* Disallow mremap */
++    }
+ 
+     offset      = address - vma->vm_start;
+-#ifdef FIREGL_CF_SUPPORT    
++#ifdef FIREGL_CF_SUPPORT
+     page_addr   = mc_heap_get_page_addr(vma, offset);
+ #else
+     page_addr   = firegl_cmmqs_get_pageaddr_from_vm(vma, offset);
+-#endif    
++#endif
+     if( !page_addr)
+     {
+         __KE_ERROR("Invalid page address\n");
+-        return NOPAGE_SIGBUS;   /* Disallow mremap */
++        return VM_FAULT_SIGBUS;   /* Disallow mremap */
+     }
+     page        = virt_to_page(page_addr);
+     get_page(page);
+ 
+-    return page;
++    vmf->page = page;
++    return 0;
+ }
+ 
+-
+-
+-#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
+-
+-static vm_nopage_ret_t vm_nopage(struct vm_area_struct* vma,
+-                                 unsigned long address,
+-                                 int *type)
++static int vm_nopage(struct vm_area_struct* vma,
++		     struct vm_fault *vmf, int type)
+ {
+-    if (type) *type = VM_FAULT_MINOR;
+-        return do_vm_nopage(vma, address);
++	return VM_FAULT_SIGBUS;
+ }
+ 
+ #ifdef __AGP__BUILTIN__
+@@ -3867,12 +3867,10 @@
+     (which is one or more pages in size)
+ 
+  */
+-static vm_nopage_ret_t vm_shm_nopage(struct vm_area_struct* vma,
+-                                     unsigned long address,
+-                                     int *type)
++static int vm_shm_nopage(struct vm_area_struct* vma,
++			 struct vm_fault *vmf, int type)
+ {
+-    if (type) *type = VM_FAULT_MINOR;
+-        return do_vm_shm_nopage(vma, address);
++        return do_vm_shm_nopage(vma, vmf);
+ }
+ 
+ /*
+@@ -3881,115 +3879,29 @@
+       (which is one ore more pages in size)
+ 
+ */
+-static vm_nopage_ret_t vm_dma_nopage(struct vm_area_struct* vma,
+-                                     unsigned long address,
+-                                     int *type)
++static int vm_dma_nopage(struct vm_area_struct* vma,
++			 struct vm_fault *vmf, int type)
+ {
+-    if (type) *type = VM_FAULT_MINOR;
+-        return do_vm_dma_nopage(vma, address);
+-}
+-
+-static vm_nopage_ret_t vm_kmap_nopage(struct vm_area_struct* vma,
+-                                     unsigned long address,
+-                                     int *type)
+-{
+-    if (type) *type = VM_FAULT_MINOR;
+-        return do_vm_kmap_nopage(vma, address);
+-}
+-
+-static vm_nopage_ret_t vm_pcie_nopage(struct vm_area_struct* vma,
+-                                     unsigned long address,
+-                                     int *type)
+-{  
+-       return do_vm_pcie_nopage(vma, address);
++        return do_vm_dma_nopage(vma, vmf);
+ }
+ 
+-static vm_nopage_ret_t vm_gart_nopage(struct vm_area_struct* vma,
+-                                      unsigned long address, 
+-                                      int *type)
++static int vm_kmap_nopage(struct vm_area_struct* vma,
++			  struct vm_fault *vmf, int type)
+ {
+-       return do_vm_gart_nopage(vma, address);
++        return do_vm_kmap_nopage(vma, vmf);
+ }
+ 
+-#else   /* LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,0) */
+-
+-static vm_nopage_ret_t vm_nopage(struct vm_area_struct* vma,
+-                                 unsigned long address,
+-                                 int write_access)
++static int vm_pcie_nopage(struct vm_area_struct* vma,
++			  struct vm_fault *vmf, int type)
+ {
+-    return do_vm_nopage(vma, address);
++	return do_vm_pcie_nopage(vma, vmf);
+ }
+ 
+-#ifdef __AGP__BUILTIN__
+-#ifdef __ia64__
+-
+-
+-static vm_nopage_ret_t vm_cant_nopage(struct vm_area_struct* vma,
+-                                 unsigned long address,
+-                                 int write_access)
++static int vm_gart_nopage(struct vm_area_struct* vma,
++			  struct vm_fault *vmf, int type)
+ {
+-    return do_vm_cant_nopage(vma, address);
++       return do_vm_gart_nopage(vma, vmf);
+ }
+-#endif /* __ia64__ */
+-#endif /* __AGP__BUILTIN__ */
+-
+-/*
+-
+-    This function is called when a page of a mmap()'ed area is not currently
+-    visible in the specified VMA.
+-    Return value is the associated physical address for the requested page.
+-    (If not implemented, then the kernel default routine would allocate a new,
+-     zeroed page for servicing us)
+-
+-    Possible errors: SIGBUS, OutOfMem
+-
+-    This routine is intended to remap addresses of SHM SAREA
+-    (which is one or more pages in size)
+-
+- */
+-static vm_nopage_ret_t vm_shm_nopage(struct vm_area_struct* vma,
+-                                     unsigned long address,
+-                                     int write_access)
+-{
+-    return do_vm_shm_nopage(vma, address);
+-}
+-
+-/*
+-
+-    This routine is intended to remap addresses of a OpenGL context
+-      (which is one ore more pages in size)
+-
+-*/
+-static vm_nopage_ret_t vm_dma_nopage(struct vm_area_struct* vma,
+-                                     unsigned long address,
+-                                     int write_access)
+-{
+-     return do_vm_dma_nopage(vma, address);
+-}
+-
+-static vm_nopage_ret_t vm_kmap_nopage(struct vm_area_struct* vma,
+-                                     unsigned long address,
+-                                     int write_access)
+-{
+-     return do_vm_kmap_nopage(vma, address);
+-}
+-
+-static vm_nopage_ret_t vm_pcie_nopage(struct vm_area_struct* vma,
+-                                     unsigned long address,
+-                                     int write_access)
+-{
+-        return do_vm_pcie_nopage(vma, address);
+-}
+-
+-static vm_nopage_ret_t vm_gart_nopage(struct vm_area_struct* vma,
+-                                      unsigned long address, 
+-                                      int *type)
+-{
+-       return do_vm_gart_nopage(vma, address);
+-}
+-
+-
+-#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0) */
+ 
+ void* ATI_API_CALL __ke_vma_file_priv(struct vm_area_struct* vma)
+ {
+@@ -4040,7 +3952,7 @@
+     *(buf + i++) = pgprot & _PAGE_DIRTY    ? 'd' : '-';
+     *(buf + i++) = pgprot & _PAGE_PSE      ? 'm' : 'k';
+     *(buf + i++) = pgprot & _PAGE_GLOBAL   ? 'g' : 'l';
+-#endif /* __i386__ */		
++#endif /* __i386__ */
+     *(buf + i++) = 0;
+ 
+     return buf;
+@@ -4069,9 +3981,9 @@
+     return buf;
+ }
+ 
+-char* ATI_API_CALL __ke_vm_phys_addr_str(struct vm_area_struct* vma, 
+-                            char* buf, 
+-                            unsigned long virtual_addr, 
++char* ATI_API_CALL __ke_vm_phys_addr_str(struct vm_area_struct* vma,
++                            char* buf,
++                            unsigned long virtual_addr,
+                             __ke_dma_addr_t* phys_address)
+ {
+     pgd_t* pgd_p;
+@@ -4174,7 +4086,7 @@
+ 
+ static struct vm_operations_struct vm_ops =
+ {
+-    nopage:  ip_vm_nopage,
++    fault:  ip_vm_nopage,
+     open:    ip_drm_vm_open,
+     close:   ip_drm_vm_close,
+ };
+@@ -4183,7 +4095,7 @@
+ #ifdef __ia64__
+ static struct vm_operations_struct vm_cant_ops =
+ {
+-    nopage:  ip_vm_cant_nopage,
++    fault:  ip_vm_cant_nopage,
+     open:    ip_drm_vm_open,
+     close:   ip_drm_vm_close,
+ };
+@@ -4192,42 +4104,42 @@
+ 
+ static struct vm_operations_struct vm_shm_ops =
+ {
+-    nopage:  ip_vm_shm_nopage,
++    fault:  ip_vm_shm_nopage,
+     open:    ip_drm_vm_open,
+     close:   ip_drm_vm_close,
+ };
+ 
+ static struct vm_operations_struct vm_pci_bq_ops =
+ {
+-    nopage:  ip_vm_dma_nopage,
++    fault:  ip_vm_dma_nopage,
+     open:    ip_drm_vm_open,
+     close:   ip_drm_vm_close,
+ };
+ 
+ static struct vm_operations_struct vm_ctx_ops =
+ {
+-    nopage:  ip_vm_dma_nopage,
++    fault:  ip_vm_dma_nopage,
+     open:    ip_drm_vm_open,
+     close:   ip_drm_vm_close,
+ };
+ 
+ static struct vm_operations_struct vm_pcie_ops = 
+ {
+-    nopage:  ip_vm_pcie_nopage,
++    fault:  ip_vm_pcie_nopage,
+     open:    ip_drm_vm_open,
+     close:   ip_drm_vm_close,
+ };
+ 
+ static struct vm_operations_struct vm_kmap_ops =
+ {
+-    nopage:  ip_vm_kmap_nopage,
++    fault:  ip_vm_kmap_nopage,
+     open:    ip_drm_vm_open,
+     close:   ip_drm_vm_close,
+ };
+ 
+ static struct vm_operations_struct vm_gart_ops =
+ {
+-    nopage:  ip_vm_gart_nopage,
++    fault:  ip_vm_gart_nopage,
+     open:    ip_drm_vm_open,
+     close:   ip_drm_vm_close,
+ };
+@@ -4236,14 +4148,14 @@
+ #ifndef __ia64__
+ static struct vm_operations_struct vm_agp_bq_ops =
+ {
+-    nopage:  ip_vm_nopage,
++    fault:  ip_vm_nopage,
+     open:    ip_drm_vm_open,
+     close:   ip_drm_vm_close,
+ };
+ #else		
+ static struct vm_operations_struct vm_cant_agp_bq_ops =
+ {
+-    nopage:  ip_vm_cant_nopage,
++    fault:  ip_vm_cant_nopage,
+     open:    ip_drm_vm_open,
+     close:   ip_drm_vm_close,
+ };
+@@ -4298,7 +4210,7 @@
+             vma->vm_ops = &vm_ops;
+ 			break;
+ 
+-#ifdef FIREGL_USWC_SUPPORT                
++#ifdef FIREGL_USWC_SUPPORT
+         case __KE_ADPT_REG:
+ 			{
+ #ifdef __ia64__
+@@ -4318,7 +4230,7 @@
+                     }
+                     else
+                     {
+-                        vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 
++                        vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+                     }
+                 }
+ #endif /* __i386__ */
+@@ -4337,7 +4249,7 @@
+             vma->vm_ops = &vm_ops;
+             }
+ 			break;
+-#endif                    
++#endif
+ 
+         case __KE_SHM:
+             vma->vm_flags |= VM_SHM | VM_RESERVED; /* Don't swap */
+@@ -4371,7 +4283,7 @@
+ 
+ #ifdef __AGP__BUILTIN__
+         case __KE_AGP:
+-            // if(dev->agp->cant_use_aperture == 1) 
++            // if(dev->agp->cant_use_aperture == 1)
+ #ifdef __ia64__
+             {
+                 /*
+@@ -4395,9 +4307,9 @@
+                     if( firegl_pat_enabled )
+                     {
+                         vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
+-                    }    
++                    }
+                 }
+-#endif                
++#endif
+ 
+                 if (REMAP_PAGE_RANGE(vma,offset))
+                 {
+@@ -4414,8 +4326,8 @@
+ #endif
+             break;
+         case __KE_AGP_BQS:
+-            // if(dev->agp->cant_use_aperture == 1) 
+-#ifdef __ia64__			
++            // if(dev->agp->cant_use_aperture == 1)
++#ifdef __ia64__
+             {
+                 /*
+                  * On some systems we can't talk to bus dma address from
+@@ -4438,9 +4350,9 @@
+                     if( firegl_pat_enabled )
+                     {
+                        vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
+-                    }   
++                    }
+                 }
+-#endif                
++#endif
+ 
+                 if (REMAP_PAGE_RANGE(vma,offset))
+                 {
+@@ -4469,15 +4381,15 @@
+             break;
+ 
+          case __KE_GART_USWC:
+-#ifdef FIREGL_USWC_SUPPORT         
++#ifdef FIREGL_USWC_SUPPORT
+             if (boot_cpu_data.x86 > 3)
+             {
+                 if( firegl_pat_enabled )
+                 {
+                     vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
+-                }    
++                }
+             }
+-#endif            
++#endif
+             // fall through
+          case __KE_GART_CACHEABLE:
+              vma->vm_flags |= VM_RESERVED;
+@@ -4527,7 +4439,7 @@
+ #define FIREGL_agp_backend_release  _X(agp_backend_release)
+ #define FIREGL_agp_memory           _X(agp_memory)
+ 
+-unsigned int __ke_firegl_agpgart_inuse = AGPGART_INUSE_NONE;				
++unsigned int __ke_firegl_agpgart_inuse = AGPGART_INUSE_NONE;
+ 
+ #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
+ /*****************************************************************************/
+@@ -4642,7 +4554,7 @@
+ int ATI_API_CALL __ke_agpgart_available(__ke_pci_dev_t *pcidev)
+ {
+     drm_agp_module_stub = &drm_agp;
+-    __ke_firegl_agpgart_inuse = KERNEL26_AGPGART_INUSE;	
++    __ke_firegl_agpgart_inuse = KERNEL26_AGPGART_INUSE;
+     {
+ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
+         firegl_pci_device = (struct pci_dev*)(void*)pcidev;
+@@ -4778,7 +4690,7 @@
+ 
+     if (AGP_AVAILABLE(copy_info))
+     {
+-        struct agp_kern_info kern;    
++        struct agp_kern_info kern;
+ 
+ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
+         if (firegl_agp_bridge == NULL)
+@@ -4876,7 +4788,7 @@
+ 
+ int ATI_API_CALL __ke_read_agp_caps_registers(__ke_pci_dev_t* dev, unsigned int *caps)
+ {
+-    return -EINVAL;	
++    return -EINVAL;
+ }
+ 
+ int ATI_API_CALL __ke_agp_acquire(__ke_pci_dev_t* dev)
+@@ -4913,9 +4825,9 @@
+ 
+ /** \brief Runs a function on all other CPUs
+  *  \param func_to_call function to be called on all other cpus
+- *  \return None 
++ *  \return None
+  */
+-void ATI_API_CALL KCL_CallFuncOnOtherCpus(firegl_void_routine_t func_to_call) 
++void ATI_API_CALL KCL_CallFuncOnOtherCpus(firegl_void_routine_t func_to_call)
+ {
+ #ifdef CONFIG_SMP
+ 	smp_call_function( firegl_smp_func_parameter_wrap, (void*)func_to_call, 0, 1 );
+@@ -4926,7 +4838,7 @@
+ 
+ int ATI_API_CALL KCL_is_pat_enabled(void)
+ {
+-   return firegl_pat_enabled; 
++   return firegl_pat_enabled;
+ }
+ 
+ static int ATI_API_CALL KCL_has_pat(void)
+@@ -4942,7 +4854,7 @@
+ {
+     unsigned long cr0=0, cr4=0;
+     unsigned long flags;
+-  
++
+     local_irq_save(flags);
+     cr0 = read_cr0() | 0x40000000;
+     write_cr0(cr0);
+@@ -4973,7 +4885,7 @@
+ {
+     unsigned long cr0 = 0, cr4 = 0;
+     unsigned long flags;
+-  
++
+     local_irq_save(flags);
+     cr0 = read_cr0() | 0x40000000;
+     write_cr0(cr0);
+@@ -4985,7 +4897,7 @@
+        write_cr4(cr4 & ~X86_CR4_PGE);
+     }
+      __flush_tlb();
+-  
++
+     wrmsr(MSR_IA32_CR_PAT,  KCL_orig_pat[0], KCL_orig_pat[1]);
+ 
+     cr0 = read_cr0();
+@@ -5008,7 +4920,7 @@
+          __KE_INFO("USWC is disabled in module parameters\n");
+          return 0;
+      }
+-     
++
+      if (!KCL_has_pat())
+      {
+         return 0;
+@@ -5018,13 +4930,13 @@
+ 
+      for ( i = 0; i < 2; i++ )
+      {
+-        for (j = 0; j < 4; j ++)    
++        for (j = 0; j < 4; j ++)
+         {
+             if (((KCL_orig_pat[i] >> (j * 8)) & 0xFF) == 1)
+-            { 
++            {
+                __KE_ERROR("Pat entry %d is already configured\n", (i+1)*(j+1));
+                return 0;
+-            } 
++            }
+         }
+     }
+ 
+@@ -5096,7 +5008,7 @@
+ } kasContext_t;
+ 
+ /** \brief KAS context */
+-static kasContext_t kasContext; 
++static kasContext_t kasContext;
+ 
+ /** \brief Kernel support required to enable KAS */
+ #if defined(cmpxchg)                        && \
+@@ -5398,7 +5310,7 @@
+     DBG_TRACE("Interrupt handler returned 0x%08X", ret);
+ 
+     kasSetExecutionLevel(orig_level);
+-    spin_unlock(&kasContext.lock_ih); 
++    spin_unlock(&kasContext.lock_ih);
+ 
+     DBG_LEAVE("%d", ret);
+     return ret;
+@@ -5673,7 +5585,7 @@
+ #endif
+     spinlock_t lock;            /* OS spinlock object protecting the cache */
+     unsigned int routine_type;  /* Type of routine the cache might be accessed from */
+-    char name[14];              /* Cache object name (kernel 2.4 restricts its length to 19 chars) */
++    char name[24];              /* Cache object name (kernel 2.4 restricts its length to 19 chars) */
+ } kasSlabCache_t;
+ 
+ /** \brief Return Slab Cache object size
+@@ -5711,7 +5623,8 @@
+ 
+     slabcache_obj->routine_type = access_type;
+     spin_lock_init(&(slabcache_obj->lock));
+-    sprintf(slabcache_obj->name, "kas(%08lX)",(unsigned long)slabcache_obj);
++    snprintf(slabcache_obj->name, sizeof(slabcache_obj->name),
++               "kas(%p)", slabcache_obj);
+ 
+     DBG_TRACE("creating slab object '%s'", slabcache_obj->name);
+ 
+@@ -6627,7 +6540,7 @@
+ 
+     kas_xadd(puiDestination, iAdd, ret, "l");
+ 
+-    return ret + iAdd; 
++    return ret + iAdd;
+ #else
+     return 0xDEADC0DE; /* To make compiler happy */
+ #endif
+@@ -6710,7 +6623,7 @@
+ #ifdef FIREGL_CF_SUPPORT
+ 
+ void *ATI_API_CALL KCL_lock_init()
+-{   
++{
+     spinlock_t *lock;
+ 
+     lock = kmalloc(sizeof(*lock), GFP_KERNEL);
+@@ -6722,7 +6635,7 @@
+ }
+ 
+ void ATI_API_CALL KCL_lock_deinit(void *plock)
+-{   
++{
+     if (plock == NULL)
+     {
+         __KE_ERROR("plock is NULL\n");
+diff -Nur -x '*.orig' -x '*~' fglrx-installer-8.512/lib/modules/fglrx/build_mod/firegl_public.h fglrx-installer-8.512.new/lib/modules/fglrx/build_mod/firegl_public.h
+--- build_mod/firegl_public.h	2008-07-21 14:32:08.000000000 -0400
++++ fglrx-installer-8.512.new/lib/modules/fglrx/build_mod/firegl_public.h	2008-07-21 14:32:14.000000000 -0400
+@@ -78,7 +78,7 @@
+     if (!pgd_present(*(pgd_p)))	\
+     { \
+         __KE_ERROR("FATAL ERROR: User queue buffer not present! (pgd)\n"); \
+-        return (unsigned long)NOPAGE_SIGBUS;   /* Something bad happened; generate SIGBUS */ \
++        return VM_FAULT_SIGBUS;   /* Something bad happened; generate SIGBUS */ \
+         /* alternatively we could generate a NOPAGE_OOM "out of memory" */ \
+     } \
+ } while(0)
+@@ -91,7 +91,7 @@
+     if (!pud_present(*(pud_p)))	\
+     { \
+         __KE_ERROR("FATAL ERROR: User queue buffer not present! (pud)\n"); \
+-        return (unsigned long)NOPAGE_SIGBUS;   /* Something bad happened; generate SIGBUS */ \
++        return VM_FAULT_SIGBUS;   /* Something bad happened; generate SIGBUS */ \
+         /* alternatively we could generate a NOPAGE_OOM "out of memory" */ \
+     } \
+     pmd_p = pmd_offset(pud_p, pte_linear); \
+@@ -111,7 +111,7 @@
+     if (!pmd_present(*(pmd_p)))	\
+     { \
+         __KE_ERROR("FATAL ERROR: User queue buffer not present! (pmd)\n"); \
+-        return (unsigned long)NOPAGE_SIGBUS;   /* Something bad happened; generate SIGBUS */ \
++        return VM_FAULT_SIGBUS;   /* Something bad happened; generate SIGBUS */ \
+         /* alternatively we could generate a NOPAGE_OOM "out of memory" */ \
+     } \
+ } while(0)
+@@ -157,7 +157,7 @@
+     if (!pte_present(pte)) \
+     { \
+         __KE_ERROR("FATAL ERROR: User queue buffer not present! (pte)\n"); \
+-        return (unsigned long)NOPAGE_SIGBUS;   /* Something bad happened; generate SIGBUS */ \
++        return VM_FAULT_SIGBUS;   /* Something bad happened; generate SIGBUS */ \
+         /* alternatively we could generate a NOPAGE_OOM "out of memory" */ \
+     } \
+ } while(0)
diff -Nru 8-7/packages/Ubuntu/dists/intrepid/patches/2.6.27_support.patch 8-7.hotfix/packages/Ubuntu/dists/intrepid/patches/2.6.27_support.patch
--- 8-7/packages/Ubuntu/dists/intrepid/patches/2.6.27_support.patch	1970-01-01 01:00:00.000000000 +0100
+++ 8-7.hotfix/packages/Ubuntu/dists/intrepid/patches/2.6.27_support.patch	2008-08-18 23:28:18.000000000 +0200
@@ -0,0 +1,53 @@
+diff -Nru fglrx-8.512/firegl_public.c fix/fglrx-8.512/firegl_public.c
+--- fglrx-8.512/firegl_public.c	2008-07-21 21:17:45.000000000 +0200
++++ fix/fglrx-8.512/firegl_public.c	2008-08-10 12:16:29.000000000 +0200
+@@ -3235,7 +3235,7 @@
+ {
+ #ifdef __SMP__
+     /* write back invalidate all other CPUs (exported by kernel) */
+-	if (smp_call_function(deferred_flush, NULL, 1, 0) != 0)
++	if (smp_call_function(deferred_flush, NULL, 0) != 0)
+ 		panic("timed out waiting for the other CPUs!\n");
+ 
+     /* invalidate this CPU */
+@@ -4918,7 +4918,7 @@
+ void ATI_API_CALL KCL_CallFuncOnOtherCpus(firegl_void_routine_t func_to_call) 
+ {
+ #ifdef CONFIG_SMP
+-	smp_call_function( firegl_smp_func_parameter_wrap, (void*)func_to_call, 0, 1 );
++	smp_call_function( firegl_smp_func_parameter_wrap, (void*)func_to_call, 1);
+ #endif
+ }
+ 
+@@ -5029,7 +5029,7 @@
+     }
+ 
+ #ifdef CONFIG_SMP
+-    if (smp_call_function(KCL_setup_pat, NULL, 0, 1) != 0)
++    if (smp_call_function(KCL_setup_pat, NULL, 1) != 0)
+        return 0;
+ #endif
+     KCL_setup_pat(NULL);
+@@ -5047,7 +5047,7 @@
+     }
+ 
+ #ifdef CONFIG_SMP
+-    if (smp_call_function(KCL_restore_pat, NULL, 0, 1) != 0)
++    if (smp_call_function(KCL_restore_pat, NULL, 1) != 0)
+        return;
+ #endif
+     KCL_restore_pat(NULL);
+diff -Nru fglrx-8.512/Makefile fix/fglrx-8.512/Makefile
+--- fglrx-8.512/Makefile	2008-07-21 21:17:45.000000000 +0200
++++ fix/fglrx-8.512/Makefile	2008-08-10 12:29:20.000000000 +0200
+@@ -21,6 +21,10 @@
+                 -DFGL_LINUX253P1_VMA_API \
+                 -DPAGE_ATTR_FIX=$(PAGE_ATTR_FIX) \
+ 
++PV_CPU := $(shell grep "D pv_cpu_ops" /boot/System.map-$(shell uname -r) | colrm 9)
++PV_LOCK := $(shell grep "D pv_lock_ops" /boot/System.map-$(shell uname -r) | colrm 9)
++EXTRA_LDFLAGS := --defsym pv_cpu_ops=0x$(PV_CPU) --defsym pv_lock_ops=0x$(PV_LOCK)
++
+ ifeq ($(KERNELRELEASE),)
+ # on first call from remote location we get into this path
+ # whilst on second call all is managed by the embedding kernel makefile
diff -Nru 8-7/packages/Ubuntu/dists/intrepid/patches/2.6.27_sysrq_key_disable.patch 8-7.hotfix/packages/Ubuntu/dists/intrepid/patches/2.6.27_sysrq_key_disable.patch
--- 8-7/packages/Ubuntu/dists/intrepid/patches/2.6.27_sysrq_key_disable.patch	1970-01-01 01:00:00.000000000 +0100
+++ 8-7.hotfix/packages/Ubuntu/dists/intrepid/patches/2.6.27_sysrq_key_disable.patch	2008-08-18 23:03:43.000000000 +0200
@@ -0,0 +1,31 @@
+diff -Nru fglrx-8.512.orig/firegl_public.c fglrx-8.512/firegl_public.c
+--- fglrx-8.512.orig/firegl_public.c	2008-08-18 23:01:41.000000000 +0200
++++ fglrx-8.512/firegl_public.c	2008-08-18 22:54:48.000000000 +0200
+@@ -6774,11 +6774,11 @@
+ {
+     if(enable)
+     {
+-        register_sysrq_key('g', &sysrq_fgldbg_op);
++        //register_sysrq_key('g', &sysrq_fgldbg_op);
+     }     
+     else
+     {
+-        unregister_sysrq_key('g', &sysrq_fgldbg_op);
++        //unregister_sysrq_key('g', &sysrq_fgldbg_op);
+     }
+     return 0;
+ }
+@@ -6800,11 +6800,11 @@
+ {
+     if(enable)
+     {
+-        register_sysrq_key('l', &sysrq_fgldump_op);
++        //register_sysrq_key('l', &sysrq_fgldump_op);
+     }     
+     else
+     {
+-        unregister_sysrq_key('l', &sysrq_fgldump_op);
++        //unregister_sysrq_key('l', &sysrq_fgldump_op);
+     }
+     return 0;
+ }

EOT

[ "$VER" = "8-8" ] && patch -p1 <<'EOT'
diff -Nru 8-8/packages/Ubuntu/dists/intrepid/dkms.conf.in 8-8.hotfix/packages/Ubuntu/dists/intrepid/dkms.conf.in
--- 8-8/packages/Ubuntu/dists/intrepid/dkms.conf.in	2008-08-18 13:45:43.000000000 +0200
+++ 8-8.hotfix/packages/Ubuntu/dists/intrepid/dkms.conf.in	2008-08-23 13:35:46.000000000 +0200
@@ -5,3 +5,7 @@
 MAKE[0]="pushd ${dkms_tree}/fglrx/#CVERSION#/build; sh make.sh --nohints --uname_r=$kernelver; popd"
 DEST_MODULE_LOCATION[0]="/kernel/drivers/char/drm"
 AUTOINSTALL="yes"
+PATCH[0]="2.6.27_support.patch"
+PATCH_MATCH[0]="^2.6.2[7-9]"
+PATCH[1]="2.6.27_sysrq_key_disable.patch"
+PATCH_MATCH[1]="^2.6.2[7-9]"
diff -Nru 8-8/packages/Ubuntu/dists/intrepid/fglrx-kernel-source.install.in 8-8.hotfix/packages/Ubuntu/dists/intrepid/fglrx-kernel-source.install.in
--- 8-8/packages/Ubuntu/dists/intrepid/fglrx-kernel-source.install.in	2008-08-18 13:45:43.000000000 +0200
+++ 8-8.hotfix/packages/Ubuntu/dists/intrepid/fglrx-kernel-source.install.in	2008-08-23 12:09:29.000000000 +0200
@@ -9,3 +9,4 @@
 debian/replacements/*				usr/src/fglrx-#CVERSION#
 arch/#ARCH#/lib/modules/fglrx/build_mod/lib*    usr/src/fglrx-#CVERSION#
 debian/dkms.conf                                usr/src/fglrx-#CVERSION#
+debian/patches					usr/src/fglrx-#CVERSION#
diff -Nru 8-8/packages/Ubuntu/dists/intrepid/patches/2.6.27_support.patch 8-8.hotfix/packages/Ubuntu/dists/intrepid/patches/2.6.27_support.patch
--- 8-8/packages/Ubuntu/dists/intrepid/patches/2.6.27_support.patch	1970-01-01 01:00:00.000000000 +0100
+++ 8-8.hotfix/packages/Ubuntu/dists/intrepid/patches/2.6.27_support.patch	2008-08-23 12:25:53.000000000 +0200
@@ -0,0 +1,53 @@
+diff -Nru fglrx-8.522/firegl_public.c fglrx-8.522.fix/firegl_public.c
+--- fglrx-8.522/firegl_public.c	2008-08-20 18:29:50.000000000 +0200
++++ fglrx-8.522.fix/firegl_public.c	2008-08-23 12:24:54.000000000 +0200
+@@ -3077,7 +3077,7 @@
+ {
+ #ifdef __SMP__
+     /* write back invalidate all other CPUs (exported by kernel) */
+-	if (smp_call_function(deferred_flush, NULL, 1, 0) != 0)
++	if (smp_call_function(deferred_flush, NULL, 0) != 0)
+ 		panic("timed out waiting for the other CPUs!\n");
+ 
+     /* invalidate this CPU */
+@@ -4796,7 +4796,7 @@
+ void ATI_API_CALL KCL_CallFuncOnOtherCpus(firegl_void_routine_t func_to_call) 
+ {
+ #ifdef CONFIG_SMP
+-	smp_call_function( firegl_smp_func_parameter_wrap, (void*)func_to_call, 0, 1 );
++	smp_call_function( firegl_smp_func_parameter_wrap, (void*)func_to_call, 1);
+ #endif
+ }
+ 
+@@ -4910,7 +4910,7 @@
+    }
+ 
+ #ifdef CONFIG_SMP
+-   if (smp_call_function(KCL_setup_pat, NULL, 0, 1) != 0)
++   if (smp_call_function(KCL_setup_pat, NULL, 1) != 0)
+        return 0;
+ #endif
+    KCL_setup_pat(NULL);
+@@ -4929,7 +4929,7 @@
+     }
+ 
+ #ifdef CONFIG_SMP
+-    if (smp_call_function(KCL_restore_pat, NULL, 0, 1) != 0)
++    if (smp_call_function(KCL_restore_pat, NULL, 1) != 0)
+        return;
+ #endif
+     KCL_restore_pat(NULL);
+diff -Nru fglrx-8.522/Makefile fglrx-8.522.fix/Makefile
+--- fglrx-8.522/Makefile	2008-08-20 18:29:50.000000000 +0200
++++ fglrx-8.522.fix/Makefile	2008-08-23 12:20:30.000000000 +0200
+@@ -21,6 +21,10 @@
+                 -DFGL_LINUX253P1_VMA_API \
+                 -DPAGE_ATTR_FIX=$(PAGE_ATTR_FIX) \
+ 
++PV_CPU := $(shell grep "D pv_cpu_ops" /boot/System.map-$(shell uname -r) | colrm 9)
++PV_LOCK := $(shell grep "D pv_lock_ops" /boot/System.map-$(shell uname -r) | colrm 9)
++EXTRA_LDFLAGS := --defsym pv_cpu_ops=0x$(PV_CPU) --defsym pv_lock_ops=0x$(PV_LOCK)
++
+ ifeq ($(KERNELRELEASE),)
+ # on first call from remote location we get into this path
+ # whilst on second call all is managed by the embedding kernel makefile
diff -Nru 8-8/packages/Ubuntu/dists/intrepid/patches/2.6.27_sysrq_key_disable.patch 8-8.hotfix/packages/Ubuntu/dists/intrepid/patches/2.6.27_sysrq_key_disable.patch
--- 8-8/packages/Ubuntu/dists/intrepid/patches/2.6.27_sysrq_key_disable.patch	1970-01-01 01:00:00.000000000 +0100
+++ 8-8.hotfix/packages/Ubuntu/dists/intrepid/patches/2.6.27_sysrq_key_disable.patch	2008-08-23 12:09:29.000000000 +0200
@@ -0,0 +1,31 @@
+diff -Nru fglrx-8.512.orig/firegl_public.c fglrx-8.512/firegl_public.c
+--- fglrx-8.512.orig/firegl_public.c	2008-08-18 23:01:41.000000000 +0200
++++ fglrx-8.512/firegl_public.c	2008-08-18 22:54:48.000000000 +0200
+@@ -6774,11 +6774,11 @@
+ {
+     if(enable)
+     {
+-        register_sysrq_key('g', &sysrq_fgldbg_op);
++        //register_sysrq_key('g', &sysrq_fgldbg_op);
+     }     
+     else
+     {
+-        unregister_sysrq_key('g', &sysrq_fgldbg_op);
++        //unregister_sysrq_key('g', &sysrq_fgldbg_op);
+     }
+     return 0;
+ }
+@@ -6800,11 +6800,11 @@
+ {
+     if(enable)
+     {
+-        register_sysrq_key('l', &sysrq_fgldump_op);
++        //register_sysrq_key('l', &sysrq_fgldump_op);
+     }     
+     else
+     {
+-        unregister_sysrq_key('l', &sysrq_fgldump_op);
++        //unregister_sysrq_key('l', &sysrq_fgldump_op);
+     }
+     return 0;
+ }
diff -Nru 8-8/packages/Ubuntu/dists/intrepid/rules 8-8.hotfix/packages/Ubuntu/dists/intrepid/rules
--- 8-8/packages/Ubuntu/dists/intrepid/rules	2008-08-18 13:45:43.000000000 +0200
+++ 8-8.hotfix/packages/Ubuntu/dists/intrepid/rules	2008-08-23 13:45:01.000000000 +0200
@@ -13,7 +13,7 @@
 #Kernel patches for newer development release kernel
 #In case these break stuff, don't apply to stable
 ifeq ($(DISTRO),intrepid)
-	include /usr/share/cdbs/1/rules/simple-patchsys.mk
+#	include /usr/share/cdbs/1/rules/simple-patchsys.mk
 endif
 
 #Directory naming schemes

EOT

[ "$VER" = "8-9" -o "$VER" = "8-10" ] && patch -p1 <<'EOT'
diff -Nru 8-9/packages/Ubuntu/dists/intrepid/dkms.conf.in 8-9.hotfix/packages/Ubuntu/dists/intrepid/dkms.conf.in
--- 8-9/packages/Ubuntu/dists/intrepid/dkms.conf.in	2008-09-17 22:01:09.000000000 +0200
+++ 8-9.hotfix/packages/Ubuntu/dists/intrepid/dkms.conf.in	2008-09-22 19:14:24.000000000 +0200
@@ -5,3 +5,5 @@
 MAKE[0]="pushd ${dkms_tree}/fglrx/#CVERSION#/build; sh make.sh --nohints --uname_r=$kernelver; popd"
 DEST_MODULE_LOCATION[0]="/kernel/drivers/char/drm"
 AUTOINSTALL="yes"
+PATCH[0]="2.6.27_support.patch"
+PATCH_MATCH[0]="^2.6.2[7-9]"
diff -Nru 8-9/packages/Ubuntu/dists/intrepid/fglrx-kernel-source.install.in 8-9.hotfix/packages/Ubuntu/dists/intrepid/fglrx-kernel-source.install.in
--- 8-9/packages/Ubuntu/dists/intrepid/fglrx-kernel-source.install.in	2008-09-17 22:01:09.000000000 +0200
+++ 8-9.hotfix/packages/Ubuntu/dists/intrepid/fglrx-kernel-source.install.in	2008-09-22 19:14:24.000000000 +0200
@@ -9,3 +9,4 @@
 debian/replacements/*				usr/src/fglrx-#CVERSION#
 arch/#ARCH#/lib/modules/fglrx/build_mod/lib*    usr/src/fglrx-#CVERSION#
 debian/dkms.conf                                usr/src/fglrx-#CVERSION#
+debian/patches                                  usr/src/fglrx-#CVERSION#
diff -Nru 8-9/packages/Ubuntu/dists/intrepid/patches/2.6.27_support.patch 8-9.hotfix/packages/Ubuntu/dists/intrepid/patches/2.6.27_support.patch
--- 8-9/packages/Ubuntu/dists/intrepid/patches/2.6.27_support.patch	1970-01-01 01:00:00.000000000 +0100
+++ 8-9.hotfix/packages/Ubuntu/dists/intrepid/patches/2.6.27_support.patch	2008-09-22 19:08:48.000000000 +0200
@@ -0,0 +1,98 @@
+diff -Nru fglrx-8.532.orig/firegl_public.c fglrx-8.532/firegl_public.c
+--- fglrx-8.532.orig/firegl_public.c	2008-09-22 18:58:41.000000000 +0200
++++ fglrx-8.532/firegl_public.c	2008-09-22 19:08:15.000000000 +0200
+@@ -199,6 +199,12 @@
+ #define preempt_enable()
+ #endif
+ 
++/* Since 2.6.27 smp_call_function doesn't have a nonatomic/retry argument */
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
++#define SMP_CALL_FUNCTION(func, info, retry, wait) smp_call_function(func, info, wait)
++#else
++#define SMP_CALL_FUNCTION(func, info, retry, wait) smp_call_function(func, info, retry, wait)
++#endif
+ // ============================================================
+ /* globals */
+ 
+@@ -250,7 +256,7 @@
+ const char BUILD_KERNEL_HAS_MODVERSIONS_CLEARED;
+ #endif
+ 
+-#ifdef __SMP__
++#ifdef CONFIG_SMP
+ const unsigned long __ke_SMP_State = 1;
+ const char BUILD_KERNEL_HAS_SMP_SET;
+ #else
+@@ -2516,8 +2522,8 @@
+ {
+ /*Some kernel developer removed the export of symbol "flush_tlb_page" on 2.6.25 x86_64 SMP kernel.
+   Define a simple version here.*/
+-#if defined(__x86_64__) && defined(__SMP__) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)) 
+-    on_each_cpu(KCL_flush_tlb_one, &va, 1, 1);
++#if defined(__x86_64__) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)) 
++    on_each_cpu(KCL_flush_tlb_one, &va, 1);
+ #else
+     flush_tlb_page(vma, va);
+ #endif
+@@ -2902,7 +2908,7 @@
+ 
+ /*****************************************************************************/
+ 
+-#ifdef __SMP__
++#ifdef CONFIG_SMP
+ static atomic_t cpus_waiting;
+ 
+ static void deferred_flush(void* contextp)
+@@ -2918,13 +2924,13 @@
+ 	while (atomic_read(&cpus_waiting) > 0)
+ 		barrier();
+ }
+-#endif /* __SMP__ */
++#endif /* CONFIG_SMP */
+ 
+ int ATI_API_CALL __ke_flush_cache(void)
+ {
+-#ifdef __SMP__
++#ifdef CONFIG_SMP
+     /* write back invalidate all other CPUs (exported by kernel) */
+-	if (smp_call_function(deferred_flush, NULL, 1, 0) != 0)
++	if (SMP_CALL_FUNCTION(deferred_flush, NULL, 1, 0) != 0)
+ 		panic("timed out waiting for the other CPUs!\n");
+ 
+     /* invalidate this CPU */
+@@ -2938,7 +2944,7 @@
+ 
+ 	while (atomic_read(&cpus_waiting) > 0)
+ 		barrier();
+-#else /* !__SMP__ */
++#else /* !CONFIG_SMP */
+ #if defined(__i386__) || defined(__x86_64__)
+ 	asm volatile ("wbinvd":::"memory");
+ #elif defined(__alpha__) || defined(__sparc__)
+@@ -2946,7 +2952,7 @@
+ #else
+ #error "Please define flush_cache for your architecture."
+ #endif
+-#endif /* !__SMP__ */
++#endif /* !CONFIG_SMP */
+ 
+     //for kernel 2.6.25, tlb_flush has been included when calling set_pages_*.
+     #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
+@@ -4654,7 +4660,7 @@
+    }
+ 
+ #ifdef CONFIG_SMP
+-   if (smp_call_function(KCL_setup_pat, NULL, 0, 1) != 0)
++   if (SMP_CALL_FUNCTION(KCL_setup_pat, NULL, 0, 1) != 0)
+        return 0;
+ #endif
+    KCL_setup_pat(NULL);
+@@ -4673,7 +4679,7 @@
+     }
+ 
+ #ifdef CONFIG_SMP
+-    if (smp_call_function(KCL_restore_pat, NULL, 0, 1) != 0)
++    if (SMP_CALL_FUNCTION(KCL_restore_pat, NULL, 0, 1) != 0)
+        return;
+ #endif
+     KCL_restore_pat(NULL);
diff -Nru 8-9/packages/Ubuntu/dists/intrepid/rules 8-9.hotfix/packages/Ubuntu/dists/intrepid/rules
--- 8-9/packages/Ubuntu/dists/intrepid/rules	2008-09-17 22:01:09.000000000 +0200
+++ 8-9.hotfix/packages/Ubuntu/dists/intrepid/rules	2008-09-22 19:14:24.000000000 +0200
@@ -13,7 +13,7 @@
 #Kernel patches for newer development release kernel
 #In case these break stuff, don't apply to stable
 ifeq ($(DISTRO),intrepid)
-	include /usr/share/cdbs/1/rules/simple-patchsys.mk
+#	include /usr/share/cdbs/1/rules/simple-patchsys.mk
 endif
 
 #Directory naming schemes

EOT

[ "$VER" = "8-11" ] && patch -p1 <<'EOT'
diff -Nru 8-11.orig/packages/Ubuntu/ati-packager.sh 8-11/packages/Ubuntu/ati-packager.sh
--- 8-11.orig/packages/Ubuntu/ati-packager.sh	2008-11-11 17:18:16.000000000 +0100
+++ 8-11/packages/Ubuntu/ati-packager.sh	2008-11-24 06:09:43.000000000 +0100
@@ -209,7 +209,7 @@
     case ${X_NAME} in
         gutsy|7.10)  X_DIR=x710; X_NAME=gutsy;;
         hardy|8.04)  X_DIR=x710; X_NAME=hardy;;
-        intrepid|8.10) X_DIR=x710; X_NAME=intrepid;;
+        intrepid|8.10) X_DIR=x740; X_NAME=intrepid;;
         source) X_DIR=x710; X_NAME=intrepid;;
         *)
         #Automatically detect
diff -Nru 8-11.orig/packages/Ubuntu/dists/hardy/replacements/Makefile 8-11/packages/Ubuntu/dists/hardy/replacements/Makefile
--- 8-11.orig/packages/Ubuntu/dists/hardy/replacements/Makefile	2008-11-11 17:18:16.000000000 +0100
+++ 8-11/packages/Ubuntu/dists/hardy/replacements/Makefile	2008-11-24 05:12:12.000000000 +0100
@@ -1,17 +1,63 @@
+# Copyright (c) 2008 Advanced Micro Devices. All Rights Reserved.
+# 
+# Redistribution and  use  in  source  and  binary  forms,  with  or  without
+# modification, are permitted provided that the following conditions are met:
+# 
+# 1. Redistributions of source code must retain the above  copyright  notice,
+# this list of conditions and the following disclaimer.
+# 
+# 2. Redistributions in  binary  form  must  reproduce  the  above  copyright
+# notice, this list  of  conditions  and  the  following  disclaimer  in  the
+# documentation and/or other materials provided with the distribution.
+# 
+# 3. The name of the author may not be used to endorse  or  promote  products
+# derived from this software without specific prior written permission.
+# 
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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.
+
 GCC_VER_MAJ      = $(shell $(CC) --version | head -n 1 | sed -e 's/[^0-9. ]//g;s/^ *//;s/^\(.\)\..*$$/\1/')
 
 LIBIP_PREFIX	?= ..
 
 obj-m           += fglrx.o
 fglrx-libs      += libfglrx_ip.a.GCC$(GCC_VER_MAJ)
-fglrx-c-objs    += firegl_public.o
+
+fglrx-c-objs    += firegl_public.o      \
+                   kcl_acpi.o           \
+                   kcl_agp.o            \
+                   kcl_debug.o          \
+                   kcl_ioctl.o          \
+                   kcl_io.o             \
+                   kcl_pci.o            \
+                   kcl_str.o            \
+                   kcl_wait.o
+
 fglrx-objs      += $(fglrx-c-objs) $(fglrx-libs)
-fglrx-hdrs      += firegl_public.h fglrxko_pci_ids.h
-drm-hdrs        += drm.h drmP.h drm_os_linux.h drm_proc.h drm_compat.h
 
-ifeq ($(PAGE_ATTR_FIX),)
-PAGE_ATTR_FIX   =1
-endif
+fglrx-hdrs      += firegl_public.h      \
+                   fglrxko_pci_ids.h    \
+                   kcl_acpi.h           \
+                   kcl_agp.h            \
+                   kcl_config.h         \
+                   kcl_debug.h          \
+                   kcl_io.h             \
+                   kcl_ioctl.h          \
+                   kcl_osconfig.h       \
+                   kcl_pci.h            \
+                   kcl_str.h            \
+                   kcl_type.h           \
+                   kcl_wait.h
+                   
+drm-hdrs        += drm.h drmP.h drm_os_linux.h drm_proc.h drm_compat.h
 
 EXTRA_CFLAGS    += \
                 -I$(PWD) \
@@ -29,11 +75,7 @@
 KVER            = $(shell uname -r)
 endif
 
-ifeq (1,1)
 KDIR            = /lib/modules/$(KVER)/build
-else
-KDIR            = /usr/src/linux-$(KVER)
-endif
 PWD             = $(shell pwd)
 
 fglrx-cfiles    = ${fglrx-c-objs:.o=.c}
@@ -55,7 +97,7 @@
 # distclean:: clean
 
 clean::
-	rm -f *.c *.h *.o *.ko *.GCC* .??*
+	rm -rf *.c *.h *.o *.ko *.GCC* .??* *.symvers
 
 endif
 
diff -Nru 8-11.orig/packages/Ubuntu/dists/intrepid/replacements/Makefile 8-11/packages/Ubuntu/dists/intrepid/replacements/Makefile
--- 8-11.orig/packages/Ubuntu/dists/intrepid/replacements/Makefile	2008-11-11 17:18:16.000000000 +0100
+++ 8-11/packages/Ubuntu/dists/intrepid/replacements/Makefile	2008-11-24 05:12:12.000000000 +0100
@@ -1,17 +1,63 @@
+# Copyright (c) 2008 Advanced Micro Devices. All Rights Reserved.
+# 
+# Redistribution and  use  in  source  and  binary  forms,  with  or  without
+# modification, are permitted provided that the following conditions are met:
+# 
+# 1. Redistributions of source code must retain the above  copyright  notice,
+# this list of conditions and the following disclaimer.
+# 
+# 2. Redistributions in  binary  form  must  reproduce  the  above  copyright
+# notice, this list  of  conditions  and  the  following  disclaimer  in  the
+# documentation and/or other materials provided with the distribution.
+# 
+# 3. The name of the author may not be used to endorse  or  promote  products
+# derived from this software without specific prior written permission.
+# 
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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.
+
 GCC_VER_MAJ      = $(shell $(CC) --version | head -n 1 | sed -e 's/[^0-9. ]//g;s/^ *//;s/^\(.\)\..*$$/\1/')
 
 LIBIP_PREFIX	?= ..
 
 obj-m           += fglrx.o
 fglrx-libs      += libfglrx_ip.a.GCC$(GCC_VER_MAJ)
-fglrx-c-objs    += firegl_public.o
+
+fglrx-c-objs    += firegl_public.o      \
+                   kcl_acpi.o           \
+                   kcl_agp.o            \
+                   kcl_debug.o          \
+                   kcl_ioctl.o          \
+                   kcl_io.o             \
+                   kcl_pci.o            \
+                   kcl_str.o            \
+                   kcl_wait.o
+
 fglrx-objs      += $(fglrx-c-objs) $(fglrx-libs)
-fglrx-hdrs      += firegl_public.h fglrxko_pci_ids.h
-drm-hdrs        += drm.h drmP.h drm_os_linux.h drm_proc.h drm_compat.h
 
-ifeq ($(PAGE_ATTR_FIX),)
-PAGE_ATTR_FIX   =1
-endif
+fglrx-hdrs      += firegl_public.h      \
+                   fglrxko_pci_ids.h    \
+                   kcl_acpi.h           \
+                   kcl_agp.h            \
+                   kcl_config.h         \
+                   kcl_debug.h          \
+                   kcl_io.h             \
+                   kcl_ioctl.h          \
+                   kcl_osconfig.h       \
+                   kcl_pci.h            \
+                   kcl_str.h            \
+                   kcl_type.h           \
+                   kcl_wait.h
+                   
+drm-hdrs        += drm.h drmP.h drm_os_linux.h drm_proc.h drm_compat.h
 
 EXTRA_CFLAGS    += \
                 -I$(PWD) \
@@ -29,11 +75,7 @@
 KVER            = $(shell uname -r)
 endif
 
-ifeq (1,1)
 KDIR            = /lib/modules/$(KVER)/build
-else
-KDIR            = /usr/src/linux-$(KVER)
-endif
 PWD             = $(shell pwd)
 
 fglrx-cfiles    = ${fglrx-c-objs:.o=.c}
@@ -55,7 +97,7 @@
 # distclean:: clean
 
 clean::
-	rm -f *.c *.h *.o *.ko *.GCC* .??*
+	rm -rf *.c *.h *.o *.ko *.GCC* .??* *.symvers
 
 endif
 
diff -Nru 8-11.orig/packages/Ubuntu/dists/intrepid/rules 8-11/packages/Ubuntu/dists/intrepid/rules
--- 8-11.orig/packages/Ubuntu/dists/intrepid/rules	2008-11-11 17:18:16.000000000 +0100
+++ 8-11/packages/Ubuntu/dists/intrepid/rules	2008-11-24 06:03:48.000000000 +0100
@@ -23,11 +23,11 @@
 ifeq ($(DEB_BUILD_ARCH),amd64)
 	LIBDIR=lib64
 	ARCH=x86_64
-	XARCH=x710_64a
+	XARCH=x740_64a
 else
 	LIBDIR=lib
 	ARCH=x86
-	XARCH=x710
+	XARCH=x740
 endif
 
 # Package names
diff -Nru 8-11.orig/packages/Ubuntu/dists/intrepid/xorg-driver-fglrx.postrm 8-11/packages/Ubuntu/dists/intrepid/xorg-driver-fglrx.postrm
--- 8-11.orig/packages/Ubuntu/dists/intrepid/xorg-driver-fglrx.postrm	2008-11-11 17:18:16.000000000 +0100
+++ 8-11/packages/Ubuntu/dists/intrepid/xorg-driver-fglrx.postrm	2008-11-24 05:49:34.000000000 +0100
@@ -23,6 +23,7 @@
 	dpkg-divert --remove --rename --package $PKGNAME --divert /usr/lib/fglrx/libGL.so.1.2.xlibmesa /usr/lib/libGL.so.1.2 > /dev/null
 	dpkg-divert --remove --rename --package $PKGNAME --divert /usr/lib32/fglrx/libGL.so.1.2.xlibmesa /usr/lib32/libGL.so.1.2 > /dev/null
 	dpkg-divert --remove --rename --package $PKGNAME --divert /usr/lib/fglrx/libdri.so.xlibmesa /usr/lib/xorg/modules/extensions/libdri.so > /dev/null
+	dpkg-divert --remove --rename --package $PKGNAME --divert /usr/lib/fglrx/libglx.so.xlibmesa /usr/lib/xorg/modules/extensions/libglx.so > /dev/null
     ;;
     
     upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
diff -Nru 8-11.orig/packages/Ubuntu/dists/intrepid/xorg-driver-fglrx.preinst 8-11/packages/Ubuntu/dists/intrepid/xorg-driver-fglrx.preinst
--- 8-11.orig/packages/Ubuntu/dists/intrepid/xorg-driver-fglrx.preinst	2008-11-11 17:18:16.000000000 +0100
+++ 8-11/packages/Ubuntu/dists/intrepid/xorg-driver-fglrx.preinst	2008-11-24 05:50:45.000000000 +0100
@@ -68,6 +68,7 @@
 	fi
 	dpkg-divert --add --rename --package $PKGNAME --divert /usr/lib/fglrx/libGL.so.1.2.xlibmesa /usr/lib/libGL.so.1.2 > /dev/null
 	dpkg-divert --add --rename --package $PKGNAME --divert /usr/lib/fglrx/libdri.so.xlibmesa /usr/lib/xorg/modules/extensions/libdri.so > /dev/null
+	dpkg-divert --add --rename --package $PKGNAME --divert /usr/lib/fglrx/libglx.so.xlibmesa /usr/lib/xorg/modules/extensions/libglx.so > /dev/null
 
 	if [ -n "$HAS_LIB32" ]; then
 		if [ ! -d /usr/lib32/fglrx ]; then

EOT

[ "$VER" = "8-12" ] && sed -i 's/\.so*/./' packages/Ubuntu/dists/*/libamdxvba1.install.in

[ "$VER" = "9.2" ] && patch -p1 << 'EOT'
diff -Nru 9.2/packages/Ubuntu/dists/hardy/dkms/patches/2.6.29_support_headers.patch 9.2.fix/packages/Ubuntu/dists/hardy/dkms/2.6.29_support_headers.patch
--- 9.2/packages/Ubuntu/dists/hardy/dkms/patches/2.6.29_support_headers.patch	1970-01-01 01:00:00.000000000 +0100
+++ 9.2.fix/packages/Ubuntu/dists/hardy/dkms/patches/2.6.29_support_headers.patch	2009-03-19 00:18:10.000000000 +0100
@@ -0,0 +1,1754 @@
+  patch fglrx 9-2 aka 8.582 to work with linux 2.6.29
+	**** new version ****
+   
+   contains files from acpica.org
+
+	USE AT YOUR OWN RISK
+
+diff -Naurp a/2.6.x/Makefile b/2.6.x/Makefile
+--- a/2.6.x/Makefile	2009-02-28 21:53:58.000000000 +0100
++++ b/2.6.x/Makefile	2009-02-28 22:24:38.000000000 +0100
+@@ -55,7 +55,10 @@ fglrx-hdrs      += firegl_public.h      
+                    kcl_pci.h            \
+                    kcl_str.h            \
+                    kcl_type.h           \
+-                   kcl_wait.h
++                   kcl_wait.h		\
++		   acpica-acconfig.h    \
++		   acpica-aclocal.h     \
++		   acpica-acobject.h    
+                    
+ drm-hdrs        += drm.h drmP.h drm_os_linux.h drm_proc.h drm_compat.h
+ 
+diff -Naurp a/acpica-acconfig.h b/acpica-acconfig.h
+--- a/acpica-acconfig.h	1970-01-01 01:00:00.000000000 +0100
++++ b/acpica-acconfig.h	2009-02-28 22:24:01.000000000 +0100
+@@ -0,0 +1,217 @@
++/******************************************************************************
++ *
++ * Name: acconfig.h - Global configuration constants
++ *
++ *****************************************************************************/
++
++/*
++ * Copyright (C) 2000 - 2008, Intel Corp.
++ * All rights reserved.
++ *
++ * Redistribution and use in source and binary forms, with or without
++ * modification, are permitted provided that the following conditions
++ * are met:
++ * 1. Redistributions of source code must retain the above copyright
++ *    notice, this list of conditions, and the following disclaimer,
++ *    without modification.
++ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
++ *    substantially similar to the "NO WARRANTY" disclaimer below
++ *    ("Disclaimer") and any redistribution must be conditioned upon
++ *    including a substantially similar Disclaimer requirement for further
++ *    binary redistribution.
++ * 3. Neither the names of the above-listed copyright holders nor the names
++ *    of any contributors may be used to endorse or promote products derived
++ *    from this software without specific prior written permission.
++ *
++ * Alternatively, this software may be distributed under the terms of the
++ * GNU General Public License ("GPL") version 2 as published by the Free
++ * Software Foundation.
++ *
++ * NO WARRANTY
++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
++ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
++ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
++ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
++ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
++ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
++ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
++ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
++ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
++ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
++ * POSSIBILITY OF SUCH DAMAGES.
++ */
++
++#ifndef _ACCONFIG_H
++#define _ACCONFIG_H
++
++/******************************************************************************
++ *
++ * Configuration options
++ *
++ *****************************************************************************/
++
++/*
++ * ACPI_DEBUG_OUTPUT    - This switch enables all the debug facilities of the
++ *                        ACPI subsystem.  This includes the DEBUG_PRINT output
++ *                        statements.  When disabled, all DEBUG_PRINT
++ *                        statements are compiled out.
++ *
++ * ACPI_APPLICATION     - Use this switch if the subsystem is going to be run
++ *                        at the application level.
++ *
++ */
++
++/*
++ * OS name, used for the _OS object.  The _OS object is essentially obsolete,
++ * but there is a large base of ASL/AML code in existing machines that check
++ * for the string below.  The use of this string usually guarantees that
++ * the ASL will execute down the most tested code path.  Also, there is some
++ * code that will not execute the _OSI method unless _OS matches the string
++ * below.  Therefore, change this string at your own risk.
++ */
++#define ACPI_OS_NAME                    "Microsoft Windows NT"
++
++/* Maximum objects in the various object caches */
++
++#define ACPI_MAX_STATE_CACHE_DEPTH      96	/* State objects */
++#define ACPI_MAX_PARSE_CACHE_DEPTH      96	/* Parse tree objects */
++#define ACPI_MAX_EXTPARSE_CACHE_DEPTH   96	/* Parse tree objects */
++#define ACPI_MAX_OBJECT_CACHE_DEPTH     96	/* Interpreter operand objects */
++#define ACPI_MAX_NAMESPACE_CACHE_DEPTH  96	/* Namespace objects */
++
++/*
++ * Should the subsystem abort the loading of an ACPI table if the
++ * table checksum is incorrect?
++ */
++#define ACPI_CHECKSUM_ABORT             FALSE
++
++/******************************************************************************
++ *
++ * Subsystem Constants
++ *
++ *****************************************************************************/
++
++/* Version of ACPI supported */
++
++#define ACPI_CA_SUPPORT_LEVEL           3
++
++/* Maximum count for a semaphore object */
++
++#define ACPI_MAX_SEMAPHORE_COUNT        256
++
++/* Maximum object reference count (detects object deletion issues) */
++
++#define ACPI_MAX_REFERENCE_COUNT        0x1000
++
++/* Size of cached memory mapping for system memory operation region */
++
++#define ACPI_SYSMEM_REGION_WINDOW_SIZE  4096
++
++/* owner_id tracking. 8 entries allows for 255 owner_ids */
++
++#define ACPI_NUM_OWNERID_MASKS          8
++
++/* Size of the root table array is increased by this increment */
++
++#define ACPI_ROOT_TABLE_SIZE_INCREMENT  4
++
++/* Maximum number of While() loop iterations before forced abort */
++
++#define ACPI_MAX_LOOP_ITERATIONS        0xFFFF
++
++/******************************************************************************
++ *
++ * ACPI Specification constants (Do not change unless the specification changes)
++ *
++ *****************************************************************************/
++
++/* Number of distinct GPE register blocks and register width */
++
++#define ACPI_MAX_GPE_BLOCKS             2
++#define ACPI_GPE_REGISTER_WIDTH         8
++
++/* Method info (in WALK_STATE), containing local variables and argumetns */
++
++#define ACPI_METHOD_NUM_LOCALS          8
++#define ACPI_METHOD_MAX_LOCAL           7
++
++#define ACPI_METHOD_NUM_ARGS            7
++#define ACPI_METHOD_MAX_ARG             6
++
++/* Length of _HID, _UID, _CID, and UUID values */
++
++#define ACPI_DEVICE_ID_LENGTH           0x09
++#define ACPI_MAX_CID_LENGTH             48
++#define ACPI_UUID_LENGTH                16
++
++/*
++ * Operand Stack (in WALK_STATE), Must be large enough to contain METHOD_MAX_ARG
++ */
++#define ACPI_OBJ_NUM_OPERANDS           8
++#define ACPI_OBJ_MAX_OPERAND            7
++
++/* Number of elements in the Result Stack frame, can be an arbitrary value */
++
++#define ACPI_RESULTS_FRAME_OBJ_NUM      8
++
++/*
++ * Maximal number of elements the Result Stack can contain,
++ * it may be an arbitray value not exceeding the types of
++ * result_size and result_count (now u8).
++ */
++#define ACPI_RESULTS_OBJ_NUM_MAX        255
++
++/* Names within the namespace are 4 bytes long */
++
++#define ACPI_NAME_SIZE                  4
++#define ACPI_PATH_SEGMENT_LENGTH        5	/* 4 chars for name + 1 char for separator */
++#define ACPI_PATH_SEPARATOR             '.'
++
++/* Sizes for ACPI table headers */
++
++#define ACPI_OEM_ID_SIZE                6
++#define ACPI_OEM_TABLE_ID_SIZE          8
++
++/* Constants used in searching for the RSDP in low memory */
++
++#define ACPI_EBDA_PTR_LOCATION          0x0000040E	/* Physical Address */
++#define ACPI_EBDA_PTR_LENGTH            2
++#define ACPI_EBDA_WINDOW_SIZE           1024
++#define ACPI_HI_RSDP_WINDOW_BASE        0x000E0000	/* Physical Address */
++#define ACPI_HI_RSDP_WINDOW_SIZE        0x00020000
++#define ACPI_RSDP_SCAN_STEP             16
++
++/* Operation regions */
++
++#define ACPI_NUM_PREDEFINED_REGIONS     8
++#define ACPI_USER_REGION_BEGIN          0x80
++
++/* Maximum space_ids for Operation Regions */
++
++#define ACPI_MAX_ADDRESS_SPACE          255
++
++/* Array sizes.  Used for range checking also */
++
++#define ACPI_MAX_MATCH_OPCODE           5
++
++/* RSDP checksums */
++
++#define ACPI_RSDP_CHECKSUM_LENGTH       20
++#define ACPI_RSDP_XCHECKSUM_LENGTH      36
++
++/* SMBus bidirectional buffer size */
++
++#define ACPI_SMBUS_BUFFER_SIZE          34
++
++/******************************************************************************
++ *
++ * ACPI AML Debugger
++ *
++ *****************************************************************************/
++
++#define ACPI_DEBUGGER_MAX_ARGS          8	/* Must be max method args + 1 */
++
++#define ACPI_DEBUGGER_COMMAND_PROMPT    '-'
++#define ACPI_DEBUGGER_EXECUTE_PROMPT    '%'
++
++#endif				/* _ACCONFIG_H */
+diff -Naurp a/acpica-aclocal.h b/acpica-aclocal.h
+--- a/acpica-aclocal.h	1970-01-01 01:00:00.000000000 +0100
++++ b/acpica-aclocal.h	2009-02-28 21:35:32.000000000 +0100
+@@ -0,0 +1,990 @@
++/******************************************************************************
++ *
++ * Name: aclocal.h - Internal data types used across the ACPI subsystem
++ *
++ *****************************************************************************/
++
++/*
++ * Copyright (C) 2000 - 2008, Intel Corp.
++ * All rights reserved.
++ *
++ * Redistribution and use in source and binary forms, with or without
++ * modification, are permitted provided that the following conditions
++ * are met:
++ * 1. Redistributions of source code must retain the above copyright
++ *    notice, this list of conditions, and the following disclaimer,
++ *    without modification.
++ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
++ *    substantially similar to the "NO WARRANTY" disclaimer below
++ *    ("Disclaimer") and any redistribution must be conditioned upon
++ *    including a substantially similar Disclaimer requirement for further
++ *    binary redistribution.
++ * 3. Neither the names of the above-listed copyright holders nor the names
++ *    of any contributors may be used to endorse or promote products derived
++ *    from this software without specific prior written permission.
++ *
++ * Alternatively, this software may be distributed under the terms of the
++ * GNU General Public License ("GPL") version 2 as published by the Free
++ * Software Foundation.
++ *
++ * NO WARRANTY
++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
++ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
++ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
++ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
++ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
++ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
++ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
++ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
++ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
++ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
++ * POSSIBILITY OF SUCH DAMAGES.
++ */
++
++#ifndef __ACLOCAL_H__
++#define __ACLOCAL_H__
++
++/* acpisrc:struct_defs -- for acpisrc conversion */
++
++#define ACPI_SERIALIZED                 0xFF
++
++typedef u32 acpi_mutex_handle;
++#define ACPI_GLOBAL_LOCK                (acpi_semaphore) (-1)
++
++/* Total number of aml opcodes defined */
++
++#define AML_NUM_OPCODES                 0x7F
++
++/* Forward declarations */
++
++struct acpi_walk_state;
++struct acpi_obj_mutex;
++union acpi_parse_object;
++
++/*****************************************************************************
++ *
++ * Mutex typedefs and structs
++ *
++ ****************************************************************************/
++
++/*
++ * Predefined handles for the mutex objects used within the subsystem
++ * All mutex objects are automatically created by acpi_ut_mutex_initialize.
++ *
++ * The acquire/release ordering protocol is implied via this list. Mutexes
++ * with a lower value must be acquired before mutexes with a higher value.
++ *
++ * NOTE: any changes here must be reflected in the acpi_gbl_mutex_names
++ * table below also!
++ */
++#define ACPI_MTX_INTERPRETER            0	/* AML Interpreter, main lock */
++#define ACPI_MTX_NAMESPACE              1	/* ACPI Namespace */
++#define ACPI_MTX_TABLES                 2	/* Data for ACPI tables */
++#define ACPI_MTX_EVENTS                 3	/* Data for ACPI events */
++#define ACPI_MTX_CACHES                 4	/* Internal caches, general purposes */
++#define ACPI_MTX_MEMORY                 5	/* Debug memory tracking lists */
++#define ACPI_MTX_DEBUG_CMD_COMPLETE     6	/* AML debugger */
++#define ACPI_MTX_DEBUG_CMD_READY        7	/* AML debugger */
++
++#define ACPI_MAX_MUTEX                  7
++#define ACPI_NUM_MUTEX                  ACPI_MAX_MUTEX+1
++
++#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
++#ifdef DEFINE_ACPI_GLOBALS
++
++/* Debug names for the mutexes above */
++
++static char *acpi_gbl_mutex_names[ACPI_NUM_MUTEX] = {
++	"ACPI_MTX_Interpreter",
++	"ACPI_MTX_Namespace",
++	"ACPI_MTX_Tables",
++	"ACPI_MTX_Events",
++	"ACPI_MTX_Caches",
++	"ACPI_MTX_Memory",
++	"ACPI_MTX_CommandComplete",
++	"ACPI_MTX_CommandReady"
++};
++
++#endif
++#endif
++
++/*
++ * Predefined handles for spinlocks used within the subsystem.
++ * These spinlocks are created by acpi_ut_mutex_initialize
++ */
++#define ACPI_LOCK_GPES                  0
++#define ACPI_LOCK_HARDWARE              1
++
++#define ACPI_MAX_LOCK                   1
++#define ACPI_NUM_LOCK                   ACPI_MAX_LOCK+1
++
++/* This Thread ID means that the mutex is not in use (unlocked) */
++
++#define ACPI_MUTEX_NOT_ACQUIRED         (acpi_thread_id) 0
++
++/* Table for the global mutexes */
++
++struct acpi_mutex_info {
++	acpi_mutex mutex;
++	u32 use_count;
++	acpi_thread_id thread_id;
++};
++
++/* Lock flag parameter for various interfaces */
++
++#define ACPI_MTX_DO_NOT_LOCK            0
++#define ACPI_MTX_LOCK                   1
++
++/* Field access granularities */
++
++#define ACPI_FIELD_BYTE_GRANULARITY     1
++#define ACPI_FIELD_WORD_GRANULARITY     2
++#define ACPI_FIELD_DWORD_GRANULARITY    4
++#define ACPI_FIELD_QWORD_GRANULARITY    8
++
++#define ACPI_ENTRY_NOT_FOUND            NULL
++
++/*****************************************************************************
++ *
++ * Namespace typedefs and structs
++ *
++ ****************************************************************************/
++
++/* Operational modes of the AML interpreter/scanner */
++
++typedef enum {
++	ACPI_IMODE_LOAD_PASS1 = 0x01,
++	ACPI_IMODE_LOAD_PASS2 = 0x02,
++	ACPI_IMODE_EXECUTE = 0x03
++} acpi_interpreter_mode;
++
++/*
++ * The Namespace Node describes a named object that appears in the AML.
++ * descriptor_type is used to differentiate between internal descriptors.
++ *
++ * The node is optimized for both 32-bit and 64-bit platforms:
++ * 20 bytes for the 32-bit case, 32 bytes for the 64-bit case.
++ *
++ * Note: The descriptor_type and Type fields must appear in the identical
++ * position in both the struct acpi_namespace_node and union acpi_operand_object
++ * structures.
++ */
++struct acpi_namespace_node {
++	union acpi_operand_object *object;	/* Interpreter object */
++	u8 descriptor_type;	/* Differentiate object descriptor types */
++	u8 type;		/* ACPI Type associated with this name */
++	u8 flags;		/* Miscellaneous flags */
++	acpi_owner_id owner_id;	/* Node creator */
++	union acpi_name_union name;	/* ACPI Name, always 4 chars per ACPI spec */
++	struct acpi_namespace_node *child;	/* First child */
++	struct acpi_namespace_node *peer;	/* Peer. Parent if ANOBJ_END_OF_PEER_LIST set */
++
++	/*
++	 * The following fields are used by the ASL compiler and disassembler only
++	 */
++#ifdef ACPI_LARGE_NAMESPACE_NODE
++	union acpi_parse_object *op;
++	u32 value;
++	u32 length;
++#endif
++};
++
++/* Namespace Node flags */
++
++#define ANOBJ_END_OF_PEER_LIST          0x01	/* End-of-list, Peer field points to parent */
++#define ANOBJ_TEMPORARY                 0x02	/* Node is create by a method and is temporary */
++#define ANOBJ_METHOD_ARG                0x04	/* Node is a method argument */
++#define ANOBJ_METHOD_LOCAL              0x08	/* Node is a method local */
++#define ANOBJ_SUBTREE_HAS_INI           0x10	/* Used to optimize device initialization */
++#define ANOBJ_EVALUATED                 0x20	/* Set on first evaluation of node */
++
++#define ANOBJ_IS_EXTERNAL               0x08	/* i_aSL only: This object created via External() */
++#define ANOBJ_METHOD_NO_RETVAL          0x10	/* i_aSL only: Method has no return value */
++#define ANOBJ_METHOD_SOME_NO_RETVAL     0x20	/* i_aSL only: Method has at least one return value */
++#define ANOBJ_IS_BIT_OFFSET             0x40	/* i_aSL only: Reference is a bit offset */
++#define ANOBJ_IS_REFERENCED             0x80	/* i_aSL only: Object was referenced */
++
++/* One internal RSDT for table management */
++
++struct acpi_internal_rsdt {
++	struct acpi_table_desc *tables;
++	u32 count;
++	u32 size;
++	u8 flags;
++};
++
++/* Flags for above */
++
++#define ACPI_ROOT_ORIGIN_UNKNOWN        (0)	/* ~ORIGIN_ALLOCATED */
++#define ACPI_ROOT_ORIGIN_ALLOCATED      (1)
++#define ACPI_ROOT_ALLOW_RESIZE          (2)
++
++/* Predefined (fixed) table indexes */
++
++#define ACPI_TABLE_INDEX_DSDT           (0)
++#define ACPI_TABLE_INDEX_FACS           (1)
++
++struct acpi_find_context {
++	char *search_for;
++	acpi_handle *list;
++	u32 *count;
++};
++
++struct acpi_ns_search_data {
++	struct acpi_namespace_node *node;
++};
++
++/* Object types used during package copies */
++
++#define ACPI_COPY_TYPE_SIMPLE           0
++#define ACPI_COPY_TYPE_PACKAGE          1
++
++/* Info structure used to convert external<->internal namestrings */
++
++struct acpi_namestring_info {
++	const char *external_name;
++	const char *next_external_char;
++	char *internal_name;
++	u32 length;
++	u32 num_segments;
++	u32 num_carats;
++	u8 fully_qualified;
++};
++
++/* Field creation info */
++
++struct acpi_create_field_info {
++	struct acpi_namespace_node *region_node;
++	struct acpi_namespace_node *field_node;
++	struct acpi_namespace_node *register_node;
++	struct acpi_namespace_node *data_register_node;
++	u32 bank_value;
++	u32 field_bit_position;
++	u32 field_bit_length;
++	u8 field_flags;
++	u8 attribute;
++	u8 field_type;
++};
++
++typedef
++acpi_status(*ACPI_INTERNAL_METHOD) (struct acpi_walk_state * walk_state);
++
++/*
++ * Bitmapped ACPI types.  Used internally only
++ */
++#define ACPI_BTYPE_ANY                  0x00000000
++#define ACPI_BTYPE_INTEGER              0x00000001
++#define ACPI_BTYPE_STRING               0x00000002
++#define ACPI_BTYPE_BUFFER               0x00000004
++#define ACPI_BTYPE_PACKAGE              0x00000008
++#define ACPI_BTYPE_FIELD_UNIT           0x00000010
++#define ACPI_BTYPE_DEVICE               0x00000020
++#define ACPI_BTYPE_EVENT                0x00000040
++#define ACPI_BTYPE_METHOD               0x00000080
++#define ACPI_BTYPE_MUTEX                0x00000100
++#define ACPI_BTYPE_REGION               0x00000200
++#define ACPI_BTYPE_POWER                0x00000400
++#define ACPI_BTYPE_PROCESSOR            0x00000800
++#define ACPI_BTYPE_THERMAL              0x00001000
++#define ACPI_BTYPE_BUFFER_FIELD         0x00002000
++#define ACPI_BTYPE_DDB_HANDLE           0x00004000
++#define ACPI_BTYPE_DEBUG_OBJECT         0x00008000
++#define ACPI_BTYPE_REFERENCE            0x00010000
++#define ACPI_BTYPE_RESOURCE             0x00020000
++
++#define ACPI_BTYPE_COMPUTE_DATA         (ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER)
++
++#define ACPI_BTYPE_DATA                 (ACPI_BTYPE_COMPUTE_DATA  | ACPI_BTYPE_PACKAGE)
++#define ACPI_BTYPE_DATA_REFERENCE       (ACPI_BTYPE_DATA | ACPI_BTYPE_REFERENCE | ACPI_BTYPE_DDB_HANDLE)
++#define ACPI_BTYPE_DEVICE_OBJECTS       (ACPI_BTYPE_DEVICE | ACPI_BTYPE_THERMAL | ACPI_BTYPE_PROCESSOR)
++#define ACPI_BTYPE_OBJECTS_AND_REFS     0x0001FFFF	/* ARG or LOCAL */
++#define ACPI_BTYPE_ALL_OBJECTS          0x0000FFFF
++
++/*
++ * Information structure for ACPI predefined names.
++ * Each entry in the table contains the following items:
++ *
++ * Name                 - The ACPI reserved name
++ * param_count          - Number of arguments to the method
++ * expected_return_btypes - Allowed type(s) for the return value
++ */
++struct acpi_name_info {
++	char name[ACPI_NAME_SIZE];
++	u8 param_count;
++	u8 expected_btypes;
++};
++
++/*
++ * Secondary information structures for ACPI predefined objects that return
++ * package objects. This structure appears as the next entry in the table
++ * after the NAME_INFO structure above.
++ *
++ * The reason for this is to minimize the size of the predefined name table.
++ */
++
++/*
++ * Used for ACPI_PTYPE1_FIXED, ACPI_PTYPE1_VAR, ACPI_PTYPE2,
++ * ACPI_PTYPE2_MIN, ACPI_PTYPE2_PKG_COUNT, ACPI_PTYPE2_COUNT
++ */
++struct acpi_package_info {
++	u8 type;
++	u8 object_type1;
++	u8 count1;
++	u8 object_type2;
++	u8 count2;
++	u8 reserved;
++};
++
++/* Used for ACPI_PTYPE2_FIXED */
++
++struct acpi_package_info2 {
++	u8 type;
++	u8 count;
++	u8 object_type[4];
++};
++
++/* Used for ACPI_PTYPE1_OPTION */
++
++struct acpi_package_info3 {
++	u8 type;
++	u8 count;
++	u8 object_type[2];
++	u8 tail_object_type;
++	u8 reserved;
++};
++
++union acpi_predefined_info {
++	struct acpi_name_info info;
++	struct acpi_package_info ret_info;
++	struct acpi_package_info2 ret_info2;
++	struct acpi_package_info3 ret_info3;
++};
++
++/*
++ * Bitmapped return value types
++ * Note: the actual data types must be contiguous, a loop in nspredef.c
++ * depends on this.
++ */
++#define ACPI_RTYPE_ANY                  0x00
++#define ACPI_RTYPE_NONE                 0x01
++#define ACPI_RTYPE_INTEGER              0x02
++#define ACPI_RTYPE_STRING               0x04
++#define ACPI_RTYPE_BUFFER               0x08
++#define ACPI_RTYPE_PACKAGE              0x10
++#define ACPI_RTYPE_REFERENCE            0x20
++#define ACPI_RTYPE_ALL                  0x3F
++
++#define ACPI_NUM_RTYPES                 5	/* Number of actual object types */
++
++/*****************************************************************************
++ *
++ * Event typedefs and structs
++ *
++ ****************************************************************************/
++
++/* Dispatch info for each GPE -- either a method or handler, cannot be both */
++
++struct acpi_handler_info {
++	acpi_event_handler address;	/* Address of handler, if any */
++	void *context;		/* Context to be passed to handler */
++	struct acpi_namespace_node *method_node;	/* Method node for this GPE level (saved) */
++};
++
++union acpi_gpe_dispatch_info {
++	struct acpi_namespace_node *method_node;	/* Method node for this GPE level */
++	struct acpi_handler_info *handler;
++};
++
++/*
++ * Information about a GPE, one per each GPE in an array.
++ * NOTE: Important to keep this struct as small as possible.
++ */
++struct acpi_gpe_event_info {
++	union acpi_gpe_dispatch_info dispatch;	/* Either Method or Handler */
++	struct acpi_gpe_register_info *register_info;	/* Backpointer to register info */
++	u8 flags;		/* Misc info about this GPE */
++	u8 gpe_number;		/* This GPE */
++};
++
++/* Information about a GPE register pair, one per each status/enable pair in an array */
++
++struct acpi_gpe_register_info {
++	struct acpi_generic_address status_address;	/* Address of status reg */
++	struct acpi_generic_address enable_address;	/* Address of enable reg */
++	u8 enable_for_wake;	/* GPEs to keep enabled when sleeping */
++	u8 enable_for_run;	/* GPEs to keep enabled when running */
++	u8 base_gpe_number;	/* Base GPE number for this register */
++};
++
++/*
++ * Information about a GPE register block, one per each installed block --
++ * GPE0, GPE1, and one per each installed GPE Block Device.
++ */
++struct acpi_gpe_block_info {
++	struct acpi_namespace_node *node;
++	struct acpi_gpe_block_info *previous;
++	struct acpi_gpe_block_info *next;
++	struct acpi_gpe_xrupt_info *xrupt_block;	/* Backpointer to interrupt block */
++	struct acpi_gpe_register_info *register_info;	/* One per GPE register pair */
++	struct acpi_gpe_event_info *event_info;	/* One for each GPE */
++	struct acpi_generic_address block_address;	/* Base address of the block */
++	u32 register_count;	/* Number of register pairs in block */
++	u8 block_base_number;	/* Base GPE number for this block */
++};
++
++/* Information about GPE interrupt handlers, one per each interrupt level used for GPEs */
++
++struct acpi_gpe_xrupt_info {
++	struct acpi_gpe_xrupt_info *previous;
++	struct acpi_gpe_xrupt_info *next;
++	struct acpi_gpe_block_info *gpe_block_list_head;	/* List of GPE blocks for this xrupt */
++	u32 interrupt_number;	/* System interrupt number */
++};
++
++struct acpi_gpe_walk_info {
++	struct acpi_namespace_node *gpe_device;
++	struct acpi_gpe_block_info *gpe_block;
++};
++
++struct acpi_gpe_device_info {
++	u32 index;
++	u32 next_block_base_index;
++	acpi_status status;
++	struct acpi_namespace_node *gpe_device;
++};
++
++typedef acpi_status(*acpi_gpe_callback) (struct acpi_gpe_xrupt_info *gpe_xrupt_info,
++		struct acpi_gpe_block_info *gpe_block, void *context);
++
++/* Information about each particular fixed event */
++
++struct acpi_fixed_event_handler {
++	acpi_event_handler handler;	/* Address of handler. */
++	void *context;		/* Context to be passed to handler */
++};
++
++struct acpi_fixed_event_info {
++	u8 status_register_id;
++	u8 enable_register_id;
++	u16 status_bit_mask;
++	u16 enable_bit_mask;
++};
++
++/* Information used during field processing */
++
++struct acpi_field_info {
++	u8 skip_field;
++	u8 field_flag;
++	u32 pkg_length;
++};
++
++/*****************************************************************************
++ *
++ * Generic "state" object for stacks
++ *
++ ****************************************************************************/
++
++#define ACPI_CONTROL_NORMAL                  0xC0
++#define ACPI_CONTROL_CONDITIONAL_EXECUTING   0xC1
++#define ACPI_CONTROL_PREDICATE_EXECUTING     0xC2
++#define ACPI_CONTROL_PREDICATE_FALSE         0xC3
++#define ACPI_CONTROL_PREDICATE_TRUE          0xC4
++
++#define ACPI_STATE_COMMON \
++	void                            *next; \
++	u8                              descriptor_type; /* To differentiate various internal objs */\
++	u8                              flags; \
++	u16                             value; \
++	u16                             state;
++
++	/* There are 2 bytes available here until the next natural alignment boundary */
++
++struct acpi_common_state {
++ACPI_STATE_COMMON};
++
++/*
++ * Update state - used to traverse complex objects such as packages
++ */
++struct acpi_update_state {
++	ACPI_STATE_COMMON union acpi_operand_object *object;
++};
++
++/*
++ * Pkg state - used to traverse nested package structures
++ */
++struct acpi_pkg_state {
++	ACPI_STATE_COMMON u16 index;
++	union acpi_operand_object *source_object;
++	union acpi_operand_object *dest_object;
++	struct acpi_walk_state *walk_state;
++	void *this_target_obj;
++	u32 num_packages;
++};
++
++/*
++ * Control state - one per if/else and while constructs.
++ * Allows nesting of these constructs
++ */
++struct acpi_control_state {
++	ACPI_STATE_COMMON u16 opcode;
++	union acpi_parse_object *predicate_op;
++	u8 *aml_predicate_start;	/* Start of if/while predicate */
++	u8 *package_end;	/* End of if/while block */
++	u32 loop_count;		/* While() loop counter */
++};
++
++/*
++ * Scope state - current scope during namespace lookups
++ */
++struct acpi_scope_state {
++	ACPI_STATE_COMMON struct acpi_namespace_node *node;
++};
++
++struct acpi_pscope_state {
++	ACPI_STATE_COMMON u32 arg_count;	/* Number of fixed arguments */
++	union acpi_parse_object *op;	/* Current op being parsed */
++	u8 *arg_end;		/* Current argument end */
++	u8 *pkg_end;		/* Current package end */
++	u32 arg_list;		/* Next argument to parse */
++};
++
++/*
++ * Thread state - one per thread across multiple walk states.  Multiple walk
++ * states are created when there are nested control methods executing.
++ */
++struct acpi_thread_state {
++	ACPI_STATE_COMMON u8 current_sync_level;	/* Mutex Sync (nested acquire) level */
++	struct acpi_walk_state *walk_state_list;	/* Head of list of walk_states for this thread */
++	union acpi_operand_object *acquired_mutex_list;	/* List of all currently acquired mutexes */
++	acpi_thread_id thread_id;	/* Running thread ID */
++};
++
++/*
++ * Result values - used to accumulate the results of nested
++ * AML arguments
++ */
++struct acpi_result_values {
++	ACPI_STATE_COMMON
++	    union acpi_operand_object *obj_desc[ACPI_RESULTS_FRAME_OBJ_NUM];
++};
++
++typedef
++acpi_status(*acpi_parse_downwards) (struct acpi_walk_state * walk_state,
++				    union acpi_parse_object ** out_op);
++
++typedef acpi_status(*acpi_parse_upwards) (struct acpi_walk_state * walk_state);
++
++/*
++ * Notify info - used to pass info to the deferred notify
++ * handler/dispatcher.
++ */
++struct acpi_notify_info {
++	ACPI_STATE_COMMON struct acpi_namespace_node *node;
++	union acpi_operand_object *handler_obj;
++};
++
++/* Generic state is union of structs above */
++
++union acpi_generic_state {
++	struct acpi_common_state common;
++	struct acpi_control_state control;
++	struct acpi_update_state update;
++	struct acpi_scope_state scope;
++	struct acpi_pscope_state parse_scope;
++	struct acpi_pkg_state pkg;
++	struct acpi_thread_state thread;
++	struct acpi_result_values results;
++	struct acpi_notify_info notify;
++};
++
++/*****************************************************************************
++ *
++ * Interpreter typedefs and structs
++ *
++ ****************************************************************************/
++
++typedef acpi_status(*ACPI_EXECUTE_OP) (struct acpi_walk_state * walk_state);
++
++/*****************************************************************************
++ *
++ * Parser typedefs and structs
++ *
++ ****************************************************************************/
++
++/*
++ * AML opcode, name, and argument layout
++ */
++struct acpi_opcode_info {
++#if defined(ACPI_DISASSEMBLER) || defined(ACPI_DEBUG_OUTPUT)
++	char *name;		/* Opcode name (disassembler/debug only) */
++#endif
++	u32 parse_args;		/* Grammar/Parse time arguments */
++	u32 runtime_args;	/* Interpret time arguments */
++	u16 flags;		/* Misc flags */
++	u8 object_type;		/* Corresponding internal object type */
++	u8 class;		/* Opcode class */
++	u8 type;		/* Opcode type */
++};
++
++union acpi_parse_value {
++	acpi_integer integer;	/* Integer constant (Up to 64 bits) */
++	struct uint64_struct integer64;	/* Structure overlay for 2 32-bit Dwords */
++	u32 size;		/* bytelist or field size */
++	char *string;		/* NULL terminated string */
++	u8 *buffer;		/* buffer or string */
++	char *name;		/* NULL terminated string */
++	union acpi_parse_object *arg;	/* arguments and contained ops */
++};
++
++#ifdef ACPI_DISASSEMBLER
++#define ACPI_DISASM_ONLY_MEMBERS(a)     a;
++#else
++#define ACPI_DISASM_ONLY_MEMBERS(a)
++#endif
++
++#define ACPI_PARSE_COMMON \
++	union acpi_parse_object         *parent;        /* Parent op */\
++	u8                              descriptor_type; /* To differentiate various internal objs */\
++	u8                              flags;          /* Type of Op */\
++	u16                             aml_opcode;     /* AML opcode */\
++	u32                             aml_offset;     /* Offset of declaration in AML */\
++	union acpi_parse_object         *next;          /* Next op */\
++	struct acpi_namespace_node      *node;          /* For use by interpreter */\
++	union acpi_parse_value          value;          /* Value or args associated with the opcode */\
++	u8                              arg_list_length; /* Number of elements in the arg list */\
++	ACPI_DISASM_ONLY_MEMBERS (\
++	u8                              disasm_flags;   /* Used during AML disassembly */\
++	u8                              disasm_opcode;  /* Subtype used for disassembly */\
++	char                            aml_op_name[16])	/* Op name (debug only) */
++
++#define ACPI_DASM_BUFFER                0x00
++#define ACPI_DASM_RESOURCE              0x01
++#define ACPI_DASM_STRING                0x02
++#define ACPI_DASM_UNICODE               0x03
++#define ACPI_DASM_EISAID                0x04
++#define ACPI_DASM_MATCHOP               0x05
++#define ACPI_DASM_LNOT_PREFIX           0x06
++#define ACPI_DASM_LNOT_SUFFIX           0x07
++#define ACPI_DASM_IGNORE                0x08
++
++/*
++ * Generic operation (for example:  If, While, Store)
++ */
++struct acpi_parse_obj_common {
++ACPI_PARSE_COMMON};
++
++/*
++ * Extended Op for named ops (Scope, Method, etc.), deferred ops (Methods and op_regions),
++ * and bytelists.
++ */
++struct acpi_parse_obj_named {
++	ACPI_PARSE_COMMON u8 *path;
++	u8 *data;		/* AML body or bytelist data */
++	u32 length;		/* AML length */
++	u32 name;		/* 4-byte name or zero if no name */
++};
++
++/* This version is used by the i_aSL compiler only */
++
++#define ACPI_MAX_PARSEOP_NAME   20
++
++struct acpi_parse_obj_asl {
++	ACPI_PARSE_COMMON union acpi_parse_object *child;
++	union acpi_parse_object *parent_method;
++	char *filename;
++	char *external_name;
++	char *namepath;
++	char name_seg[4];
++	u32 extra_value;
++	u32 column;
++	u32 line_number;
++	u32 logical_line_number;
++	u32 logical_byte_offset;
++	u32 end_line;
++	u32 end_logical_line;
++	u32 acpi_btype;
++	u32 aml_length;
++	u32 aml_subtree_length;
++	u32 final_aml_length;
++	u32 final_aml_offset;
++	u32 compile_flags;
++	u16 parse_opcode;
++	u8 aml_opcode_length;
++	u8 aml_pkg_len_bytes;
++	u8 extra;
++	char parse_op_name[ACPI_MAX_PARSEOP_NAME];
++};
++
++union acpi_parse_object {
++	struct acpi_parse_obj_common common;
++	struct acpi_parse_obj_named named;
++	struct acpi_parse_obj_asl asl;
++};
++
++/*
++ * Parse state - one state per parser invocation and each control
++ * method.
++ */
++struct acpi_parse_state {
++	u8 *aml_start;		/* First AML byte */
++	u8 *aml;		/* Next AML byte */
++	u8 *aml_end;		/* (last + 1) AML byte */
++	u8 *pkg_start;		/* Current package begin */
++	u8 *pkg_end;		/* Current package end */
++	union acpi_parse_object *start_op;	/* Root of parse tree */
++	struct acpi_namespace_node *start_node;
++	union acpi_generic_state *scope;	/* Current scope */
++	union acpi_parse_object *start_scope;
++	u32 aml_size;
++};
++
++/* Parse object flags */
++
++#define ACPI_PARSEOP_GENERIC            0x01
++#define ACPI_PARSEOP_NAMED              0x02
++#define ACPI_PARSEOP_DEFERRED           0x04
++#define ACPI_PARSEOP_BYTELIST           0x08
++#define ACPI_PARSEOP_IN_STACK           0x10
++#define ACPI_PARSEOP_TARGET             0x20
++#define ACPI_PARSEOP_IN_CACHE           0x80
++
++/* Parse object disasm_flags */
++
++#define ACPI_PARSEOP_IGNORE             0x01
++#define ACPI_PARSEOP_PARAMLIST          0x02
++#define ACPI_PARSEOP_EMPTY_TERMLIST     0x04
++#define ACPI_PARSEOP_SPECIAL            0x10
++
++/*****************************************************************************
++ *
++ * Hardware (ACPI registers) and PNP
++ *
++ ****************************************************************************/
++
++struct acpi_bit_register_info {
++	u8 parent_register;
++	u8 bit_position;
++	u16 access_bit_mask;
++};
++
++/*
++ * Some ACPI registers have bits that must be ignored -- meaning that they
++ * must be preserved.
++ */
++#define ACPI_PM1_STATUS_PRESERVED_BITS          0x0800	/* Bit 11 */
++#define ACPI_PM1_CONTROL_PRESERVED_BITS         0x0200	/* Bit 9 (whatever) */
++
++/*
++ * Register IDs
++ * These are the full ACPI registers
++ */
++#define ACPI_REGISTER_PM1_STATUS                0x01
++#define ACPI_REGISTER_PM1_ENABLE                0x02
++#define ACPI_REGISTER_PM1_CONTROL               0x03
++#define ACPI_REGISTER_PM1A_CONTROL              0x04
++#define ACPI_REGISTER_PM1B_CONTROL              0x05
++#define ACPI_REGISTER_PM2_CONTROL               0x06
++#define ACPI_REGISTER_PM_TIMER                  0x07
++#define ACPI_REGISTER_PROCESSOR_BLOCK           0x08
++#define ACPI_REGISTER_SMI_COMMAND_BLOCK         0x09
++
++/* Masks used to access the bit_registers */
++
++#define ACPI_BITMASK_TIMER_STATUS               0x0001
++#define ACPI_BITMASK_BUS_MASTER_STATUS          0x0010
++#define ACPI_BITMASK_GLOBAL_LOCK_STATUS         0x0020
++#define ACPI_BITMASK_POWER_BUTTON_STATUS        0x0100
++#define ACPI_BITMASK_SLEEP_BUTTON_STATUS        0x0200
++#define ACPI_BITMASK_RT_CLOCK_STATUS            0x0400
++#define ACPI_BITMASK_PCIEXP_WAKE_STATUS         0x4000	/* ACPI 3.0 */
++#define ACPI_BITMASK_WAKE_STATUS                0x8000
++
++#define ACPI_BITMASK_ALL_FIXED_STATUS           (\
++	ACPI_BITMASK_TIMER_STATUS          | \
++	ACPI_BITMASK_BUS_MASTER_STATUS     | \
++	ACPI_BITMASK_GLOBAL_LOCK_STATUS    | \
++	ACPI_BITMASK_POWER_BUTTON_STATUS   | \
++	ACPI_BITMASK_SLEEP_BUTTON_STATUS   | \
++	ACPI_BITMASK_RT_CLOCK_STATUS       | \
++	ACPI_BITMASK_WAKE_STATUS)
++
++#define ACPI_BITMASK_TIMER_ENABLE               0x0001
++#define ACPI_BITMASK_GLOBAL_LOCK_ENABLE         0x0020
++#define ACPI_BITMASK_POWER_BUTTON_ENABLE        0x0100
++#define ACPI_BITMASK_SLEEP_BUTTON_ENABLE        0x0200
++#define ACPI_BITMASK_RT_CLOCK_ENABLE            0x0400
++#define ACPI_BITMASK_PCIEXP_WAKE_DISABLE        0x4000	/* ACPI 3.0 */
++
++#define ACPI_BITMASK_SCI_ENABLE                 0x0001
++#define ACPI_BITMASK_BUS_MASTER_RLD             0x0002
++#define ACPI_BITMASK_GLOBAL_LOCK_RELEASE        0x0004
++#define ACPI_BITMASK_SLEEP_TYPE_X               0x1C00
++#define ACPI_BITMASK_SLEEP_ENABLE               0x2000
++
++#define ACPI_BITMASK_ARB_DISABLE                0x0001
++
++/* Raw bit position of each bit_register */
++
++#define ACPI_BITPOSITION_TIMER_STATUS           0x00
++#define ACPI_BITPOSITION_BUS_MASTER_STATUS      0x04
++#define ACPI_BITPOSITION_GLOBAL_LOCK_STATUS     0x05
++#define ACPI_BITPOSITION_POWER_BUTTON_STATUS    0x08
++#define ACPI_BITPOSITION_SLEEP_BUTTON_STATUS    0x09
++#define ACPI_BITPOSITION_RT_CLOCK_STATUS        0x0A
++#define ACPI_BITPOSITION_PCIEXP_WAKE_STATUS     0x0E	/* ACPI 3.0 */
++#define ACPI_BITPOSITION_WAKE_STATUS            0x0F
++
++#define ACPI_BITPOSITION_TIMER_ENABLE           0x00
++#define ACPI_BITPOSITION_GLOBAL_LOCK_ENABLE     0x05
++#define ACPI_BITPOSITION_POWER_BUTTON_ENABLE    0x08
++#define ACPI_BITPOSITION_SLEEP_BUTTON_ENABLE    0x09
++#define ACPI_BITPOSITION_RT_CLOCK_ENABLE        0x0A
++#define ACPI_BITPOSITION_PCIEXP_WAKE_DISABLE    0x0E	/* ACPI 3.0 */
++
++#define ACPI_BITPOSITION_SCI_ENABLE             0x00
++#define ACPI_BITPOSITION_BUS_MASTER_RLD         0x01
++#define ACPI_BITPOSITION_GLOBAL_LOCK_RELEASE    0x02
++#define ACPI_BITPOSITION_SLEEP_TYPE_X           0x0A
++#define ACPI_BITPOSITION_SLEEP_ENABLE           0x0D
++
++#define ACPI_BITPOSITION_ARB_DISABLE            0x00
++
++/*****************************************************************************
++ *
++ * Resource descriptors
++ *
++ ****************************************************************************/
++
++/* resource_type values */
++
++#define ACPI_ADDRESS_TYPE_MEMORY_RANGE          0
++#define ACPI_ADDRESS_TYPE_IO_RANGE              1
++#define ACPI_ADDRESS_TYPE_BUS_NUMBER_RANGE      2
++
++/* Resource descriptor types and masks */
++
++#define ACPI_RESOURCE_NAME_LARGE                0x80
++#define ACPI_RESOURCE_NAME_SMALL                0x00
++
++#define ACPI_RESOURCE_NAME_SMALL_MASK           0x78	/* Bits 6:3 contain the type */
++#define ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK    0x07	/* Bits 2:0 contain the length */
++#define ACPI_RESOURCE_NAME_LARGE_MASK           0x7F	/* Bits 6:0 contain the type */
++
++/*
++ * Small resource descriptor "names" as defined by the ACPI specification.
++ * Note: Bits 2:0 are used for the descriptor length
++ */
++#define ACPI_RESOURCE_NAME_IRQ                  0x20
++#define ACPI_RESOURCE_NAME_DMA                  0x28
++#define ACPI_RESOURCE_NAME_START_DEPENDENT      0x30
++#define ACPI_RESOURCE_NAME_END_DEPENDENT        0x38
++#define ACPI_RESOURCE_NAME_IO                   0x40
++#define ACPI_RESOURCE_NAME_FIXED_IO             0x48
++#define ACPI_RESOURCE_NAME_RESERVED_S1          0x50
++#define ACPI_RESOURCE_NAME_RESERVED_S2          0x58
++#define ACPI_RESOURCE_NAME_RESERVED_S3          0x60
++#define ACPI_RESOURCE_NAME_RESERVED_S4          0x68
++#define ACPI_RESOURCE_NAME_VENDOR_SMALL         0x70
++#define ACPI_RESOURCE_NAME_END_TAG              0x78
++
++/*
++ * Large resource descriptor "names" as defined by the ACPI specification.
++ * Note: includes the Large Descriptor bit in bit[7]
++ */
++#define ACPI_RESOURCE_NAME_MEMORY24             0x81
++#define ACPI_RESOURCE_NAME_GENERIC_REGISTER     0x82
++#define ACPI_RESOURCE_NAME_RESERVED_L1          0x83
++#define ACPI_RESOURCE_NAME_VENDOR_LARGE         0x84
++#define ACPI_RESOURCE_NAME_MEMORY32             0x85
++#define ACPI_RESOURCE_NAME_FIXED_MEMORY32       0x86
++#define ACPI_RESOURCE_NAME_ADDRESS32            0x87
++#define ACPI_RESOURCE_NAME_ADDRESS16            0x88
++#define ACPI_RESOURCE_NAME_EXTENDED_IRQ         0x89
++#define ACPI_RESOURCE_NAME_ADDRESS64            0x8A
++#define ACPI_RESOURCE_NAME_EXTENDED_ADDRESS64   0x8B
++#define ACPI_RESOURCE_NAME_LARGE_MAX            0x8B
++
++/*****************************************************************************
++ *
++ * Miscellaneous
++ *
++ ****************************************************************************/
++
++#define ACPI_ASCII_ZERO                 0x30
++
++/*****************************************************************************
++ *
++ * Debugger
++ *
++ ****************************************************************************/
++
++struct acpi_db_method_info {
++	acpi_handle main_thread_gate;
++	acpi_handle thread_complete_gate;
++	u32 *threads;
++	u32 num_threads;
++	u32 num_created;
++	u32 num_completed;
++
++	char *name;
++	u32 flags;
++	u32 num_loops;
++	char pathname[128];
++	char **args;
++
++	/*
++	 * Arguments to be passed to method for the command
++	 * Threads -
++	 *   the Number of threads, ID of current thread and
++	 *   Index of current thread inside all them created.
++	 */
++	char init_args;
++	char *arguments[4];
++	char num_threads_str[11];
++	char id_of_thread_str[11];
++	char index_of_thread_str[11];
++};
++
++struct acpi_integrity_info {
++	u32 nodes;
++	u32 objects;
++};
++
++#define ACPI_DB_REDIRECTABLE_OUTPUT     0x01
++#define ACPI_DB_CONSOLE_OUTPUT          0x02
++#define ACPI_DB_DUPLICATE_OUTPUT        0x03
++
++/*****************************************************************************
++ *
++ * Debug
++ *
++ ****************************************************************************/
++
++/* Entry for a memory allocation (debug only) */
++
++#define ACPI_MEM_MALLOC                 0
++#define ACPI_MEM_CALLOC                 1
++#define ACPI_MAX_MODULE_NAME            16
++
++#define ACPI_COMMON_DEBUG_MEM_HEADER \
++	struct acpi_debug_mem_block     *previous; \
++	struct acpi_debug_mem_block     *next; \
++	u32                             size; \
++	u32                             component; \
++	u32                             line; \
++	char                            module[ACPI_MAX_MODULE_NAME]; \
++	u8                              alloc_type;
++
++struct acpi_debug_mem_header {
++ACPI_COMMON_DEBUG_MEM_HEADER};
++
++struct acpi_debug_mem_block {
++	ACPI_COMMON_DEBUG_MEM_HEADER u64 user_space;
++};
++
++#define ACPI_MEM_LIST_GLOBAL            0
++#define ACPI_MEM_LIST_NSNODE            1
++#define ACPI_MEM_LIST_MAX               1
++#define ACPI_NUM_MEM_LISTS              2
++
++#endif				/* __ACLOCAL_H__ */
+diff -Naurp a/acpica-acobject.h b/acpica-acobject.h
+--- a/acpica-acobject.h	1970-01-01 01:00:00.000000000 +0100
++++ b/acpica-acobject.h	2009-02-28 22:24:01.000000000 +0100
+@@ -0,0 +1,446 @@
++
++/******************************************************************************
++ *
++ * Name: acobject.h - Definition of union acpi_operand_object  (Internal object only)
++ *
++ *****************************************************************************/
++
++/*
++ * Copyright (C) 2000 - 2008, Intel Corp.
++ * All rights reserved.
++ *
++ * Redistribution and use in source and binary forms, with or without
++ * modification, are permitted provided that the following conditions
++ * are met:
++ * 1. Redistributions of source code must retain the above copyright
++ *    notice, this list of conditions, and the following disclaimer,
++ *    without modification.
++ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
++ *    substantially similar to the "NO WARRANTY" disclaimer below
++ *    ("Disclaimer") and any redistribution must be conditioned upon
++ *    including a substantially similar Disclaimer requirement for further
++ *    binary redistribution.
++ * 3. Neither the names of the above-listed copyright holders nor the names
++ *    of any contributors may be used to endorse or promote products derived
++ *    from this software without specific prior written permission.
++ *
++ * Alternatively, this software may be distributed under the terms of the
++ * GNU General Public License ("GPL") version 2 as published by the Free
++ * Software Foundation.
++ *
++ * NO WARRANTY
++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
++ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
++ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
++ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
++ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
++ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
++ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
++ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
++ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
++ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
++ * POSSIBILITY OF SUCH DAMAGES.
++ */
++
++#ifndef _ACOBJECT_H
++#define _ACOBJECT_H
++
++/* acpisrc:struct_defs -- for acpisrc conversion */
++
++/*
++ * The union acpi_operand_object is used to pass AML operands from the dispatcher
++ * to the interpreter, and to keep track of the various handlers such as
++ * address space handlers and notify handlers. The object is a constant
++ * size in order to allow it to be cached and reused.
++ *
++ * Note: The object is optimized to be aligned and will not work if it is
++ * byte-packed.
++ */
++#if ACPI_MACHINE_WIDTH == 64
++#pragma pack(8)
++#else
++#pragma pack(4)
++#endif
++
++/*******************************************************************************
++ *
++ * Common Descriptors
++ *
++ ******************************************************************************/
++
++/*
++ * Common area for all objects.
++ *
++ * descriptor_type is used to differentiate between internal descriptors, and
++ * must be in the same place across all descriptors
++ *
++ * Note: The descriptor_type and Type fields must appear in the identical
++ * position in both the struct acpi_namespace_node and union acpi_operand_object
++ * structures.
++ */
++#define ACPI_OBJECT_COMMON_HEADER \
++	union acpi_operand_object       *next_object;       /* Objects linked to parent NS node */\
++	u8                              descriptor_type;    /* To differentiate various internal objs */\
++	u8                              type;               /* acpi_object_type */\
++	u16                             reference_count;    /* For object deletion management */\
++	u8                              flags;
++	/*
++	 * Note: There are 3 bytes available here before the
++	 * next natural alignment boundary (for both 32/64 cases)
++	 */
++
++/* Values for Flag byte above */
++
++#define AOPOBJ_AML_CONSTANT         0x01
++#define AOPOBJ_STATIC_POINTER       0x02
++#define AOPOBJ_DATA_VALID           0x04
++#define AOPOBJ_OBJECT_INITIALIZED   0x08
++#define AOPOBJ_SETUP_COMPLETE       0x10
++#define AOPOBJ_SINGLE_DATUM         0x20
++#define AOPOBJ_INVALID              0x40	/* Used if host OS won't allow an op_region address */
++
++/******************************************************************************
++ *
++ * Basic data types
++ *
++ *****************************************************************************/
++
++struct acpi_object_common {
++ACPI_OBJECT_COMMON_HEADER};
++
++struct acpi_object_integer {
++	ACPI_OBJECT_COMMON_HEADER u8 fill[3];	/* Prevent warning on some compilers */
++	acpi_integer value;
++};
++
++/*
++ * Note: The String and Buffer object must be identical through the Pointer
++ * and length elements.  There is code that depends on this.
++ *
++ * Fields common to both Strings and Buffers
++ */
++#define ACPI_COMMON_BUFFER_INFO(_type) \
++	_type                           *pointer; \
++	u32                             length;
++
++struct acpi_object_string {	/* Null terminated, ASCII characters only */
++	ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_BUFFER_INFO(char)	/* String in AML stream or allocated string */
++};
++
++struct acpi_object_buffer {
++	ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_BUFFER_INFO(u8)	/* Buffer in AML stream or allocated buffer */
++	u32 aml_length;
++	u8 *aml_start;
++	struct acpi_namespace_node *node;	/* Link back to parent node */
++};
++
++struct acpi_object_package {
++	ACPI_OBJECT_COMMON_HEADER struct acpi_namespace_node *node;	/* Link back to parent node */
++	union acpi_operand_object **elements;	/* Array of pointers to acpi_objects */
++	u8 *aml_start;
++	u32 aml_length;
++	u32 count;		/* # of elements in package */
++};
++
++/******************************************************************************
++ *
++ * Complex data types
++ *
++ *****************************************************************************/
++
++struct acpi_object_event {
++	ACPI_OBJECT_COMMON_HEADER acpi_semaphore os_semaphore;	/* Actual OS synchronization object */
++};
++
++struct acpi_object_mutex {
++	ACPI_OBJECT_COMMON_HEADER u8 sync_level;	/* 0-15, specified in Mutex() call */
++	u16 acquisition_depth;	/* Allow multiple Acquires, same thread */
++	acpi_mutex os_mutex;	/* Actual OS synchronization object */
++	acpi_thread_id thread_id;	/* Current owner of the mutex */
++	struct acpi_thread_state *owner_thread;	/* Current owner of the mutex */
++	union acpi_operand_object *prev;	/* Link for list of acquired mutexes */
++	union acpi_operand_object *next;	/* Link for list of acquired mutexes */
++	struct acpi_namespace_node *node;	/* Containing namespace node */
++	u8 original_sync_level;	/* Owner's original sync level (0-15) */
++};
++
++struct acpi_object_region {
++	ACPI_OBJECT_COMMON_HEADER u8 space_id;
++	struct acpi_namespace_node *node;	/* Containing namespace node */
++	union acpi_operand_object *handler;	/* Handler for region access */
++	union acpi_operand_object *next;
++	acpi_physical_address address;
++	u32 length;
++};
++
++struct acpi_object_method {
++	ACPI_OBJECT_COMMON_HEADER u8 method_flags;
++	u8 param_count;
++	u8 sync_level;
++	union acpi_operand_object *mutex;
++	u8 *aml_start;
++	ACPI_INTERNAL_METHOD implementation;
++	u32 aml_length;
++	u8 thread_count;
++	acpi_owner_id owner_id;
++};
++
++/******************************************************************************
++ *
++ * Objects that can be notified.  All share a common notify_info area.
++ *
++ *****************************************************************************/
++
++/*
++ * Common fields for objects that support ASL notifications
++ */
++#define ACPI_COMMON_NOTIFY_INFO \
++	union acpi_operand_object       *system_notify;     /* Handler for system notifies */\
++	union acpi_operand_object       *device_notify;     /* Handler for driver notifies */\
++	union acpi_operand_object       *handler;	/* Handler for Address space */
++
++struct acpi_object_notify_common {	/* COMMON NOTIFY for POWER, PROCESSOR, DEVICE, and THERMAL */
++ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_NOTIFY_INFO};
++
++struct acpi_object_device {
++	ACPI_OBJECT_COMMON_HEADER
++	    ACPI_COMMON_NOTIFY_INFO struct acpi_gpe_block_info *gpe_block;
++};
++
++struct acpi_object_power_resource {
++	ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_NOTIFY_INFO u32 system_level;
++	u32 resource_order;
++};
++
++struct acpi_object_processor {
++	ACPI_OBJECT_COMMON_HEADER
++	    /* The next two fields take advantage of the 3-byte space before NOTIFY_INFO */
++	u8 proc_id;
++	u8 length;
++	ACPI_COMMON_NOTIFY_INFO acpi_io_address address;
++};
++
++struct acpi_object_thermal_zone {
++ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_NOTIFY_INFO};
++
++/******************************************************************************
++ *
++ * Fields.  All share a common header/info field.
++ *
++ *****************************************************************************/
++
++/*
++ * Common bitfield for the field objects
++ * "Field Datum"  -- a datum from the actual field object
++ * "Buffer Datum" -- a datum from a user buffer, read from or to be written to the field
++ */
++#define ACPI_COMMON_FIELD_INFO \
++	u8                              field_flags;        /* Access, update, and lock bits */\
++	u8                              attribute;          /* From access_as keyword */\
++	u8                              access_byte_width;  /* Read/Write size in bytes */\
++	struct acpi_namespace_node      *node;              /* Link back to parent node */\
++	u32                             bit_length;         /* Length of field in bits */\
++	u32                             base_byte_offset;   /* Byte offset within containing object */\
++	u32                             value;              /* Value to store into the Bank or Index register */\
++	u8                              start_field_bit_offset;/* Bit offset within first field datum (0-63) */\
++	u8                              access_bit_width;	/* Read/Write size in bits (8-64) */
++
++struct acpi_object_field_common {	/* COMMON FIELD (for BUFFER, REGION, BANK, and INDEX fields) */
++	ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_FIELD_INFO union acpi_operand_object *region_obj;	/* Parent Operation Region object (REGION/BANK fields only) */
++};
++
++struct acpi_object_region_field {
++	ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_FIELD_INFO union acpi_operand_object *region_obj;	/* Containing op_region object */
++};
++
++struct acpi_object_bank_field {
++	ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_FIELD_INFO union acpi_operand_object *region_obj;	/* Containing op_region object */
++	union acpi_operand_object *bank_obj;	/* bank_select Register object */
++};
++
++struct acpi_object_index_field {
++	ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_FIELD_INFO
++	    /*
++	     * No "RegionObj" pointer needed since the Index and Data registers
++	     * are each field definitions unto themselves.
++	     */
++	union acpi_operand_object *index_obj;	/* Index register */
++	union acpi_operand_object *data_obj;	/* Data register */
++};
++
++/* The buffer_field is different in that it is part of a Buffer, not an op_region */
++
++struct acpi_object_buffer_field {
++	ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_FIELD_INFO union acpi_operand_object *buffer_obj;	/* Containing Buffer object */
++};
++
++/******************************************************************************
++ *
++ * Objects for handlers
++ *
++ *****************************************************************************/
++
++struct acpi_object_notify_handler {
++	ACPI_OBJECT_COMMON_HEADER struct acpi_namespace_node *node;	/* Parent device */
++	acpi_notify_handler handler;
++	void *context;
++};
++
++struct acpi_object_addr_handler {
++	ACPI_OBJECT_COMMON_HEADER u8 space_id;
++	u8 handler_flags;
++	acpi_adr_space_handler handler;
++	struct acpi_namespace_node *node;	/* Parent device */
++	void *context;
++	acpi_adr_space_setup setup;
++	union acpi_operand_object *region_list;	/* regions using this handler */
++	union acpi_operand_object *next;
++};
++
++/* Flags for address handler (handler_flags) */
++
++#define ACPI_ADDR_HANDLER_DEFAULT_INSTALLED  0x01
++
++/******************************************************************************
++ *
++ * Special internal objects
++ *
++ *****************************************************************************/
++
++/*
++ * The Reference object is used for these opcodes:
++ * Arg[0-6], Local[0-7], index_op, name_op, ref_of_op, load_op, load_table_op, debug_op
++ * The Reference.Class differentiates these types.
++ */
++struct acpi_object_reference {
++	ACPI_OBJECT_COMMON_HEADER u8 class;	/* Reference Class */
++	u8 target_type;		/* Used for Index Op */
++	u8 reserved;
++	void *object;		/* name_op=>HANDLE to obj, index_op=>union acpi_operand_object */
++	struct acpi_namespace_node *node;	/* ref_of or Namepath */
++	union acpi_operand_object **where;	/* Target of Index */
++	u32 value;		/* Used for Local/Arg/Index/ddb_handle */
++};
++
++/* Values for Reference.Class above */
++
++typedef enum {
++	ACPI_REFCLASS_LOCAL = 0,	/* Method local */
++	ACPI_REFCLASS_ARG = 1,	/* Method argument */
++	ACPI_REFCLASS_REFOF = 2,	/* Result of ref_of() TBD: Split to Ref/Node and Ref/operand_obj? */
++	ACPI_REFCLASS_INDEX = 3,	/* Result of Index() */
++	ACPI_REFCLASS_TABLE = 4,	/* ddb_handle - Load(), load_table() */
++	ACPI_REFCLASS_NAME = 5,	/* Reference to a named object */
++	ACPI_REFCLASS_DEBUG = 6,	/* Debug object */
++
++	ACPI_REFCLASS_MAX = 6
++} ACPI_REFERENCE_CLASSES;
++
++/*
++ * Extra object is used as additional storage for types that
++ * have AML code in their declarations (term_args) that must be
++ * evaluated at run time.
++ *
++ * Currently: Region and field_unit types
++ */
++struct acpi_object_extra {
++	ACPI_OBJECT_COMMON_HEADER struct acpi_namespace_node *method_REG;	/* _REG method for this region (if any) */
++	void *region_context;	/* Region-specific data */
++	u8 *aml_start;
++	u32 aml_length;
++};
++
++/* Additional data that can be attached to namespace nodes */
++
++struct acpi_object_data {
++	ACPI_OBJECT_COMMON_HEADER acpi_object_handler handler;
++	void *pointer;
++};
++
++/* Structure used when objects are cached for reuse */
++
++struct acpi_object_cache_list {
++	ACPI_OBJECT_COMMON_HEADER union acpi_operand_object *next;	/* Link for object cache and internal lists */
++};
++
++/******************************************************************************
++ *
++ * union acpi_operand_object Descriptor - a giant union of all of the above
++ *
++ *****************************************************************************/
++
++union acpi_operand_object {
++	struct acpi_object_common common;
++	struct acpi_object_integer integer;
++	struct acpi_object_string string;
++	struct acpi_object_buffer buffer;
++	struct acpi_object_package package;
++	struct acpi_object_event event;
++	struct acpi_object_method method;
++	struct acpi_object_mutex mutex;
++	struct acpi_object_region region;
++	struct acpi_object_notify_common common_notify;
++	struct acpi_object_device device;
++	struct acpi_object_power_resource power_resource;
++	struct acpi_object_processor processor;
++	struct acpi_object_thermal_zone thermal_zone;
++	struct acpi_object_field_common common_field;
++	struct acpi_object_region_field field;
++	struct acpi_object_buffer_field buffer_field;
++	struct acpi_object_bank_field bank_field;
++	struct acpi_object_index_field index_field;
++	struct acpi_object_notify_handler notify;
++	struct acpi_object_addr_handler address_space;
++	struct acpi_object_reference reference;
++	struct acpi_object_extra extra;
++	struct acpi_object_data data;
++	struct acpi_object_cache_list cache;
++
++	/*
++	 * Add namespace node to union in order to simplify code that accepts both
++	 * ACPI_OPERAND_OBJECTs and ACPI_NAMESPACE_NODEs. The structures share
++	 * a common descriptor_type field in order to differentiate them.
++	 */
++	struct acpi_namespace_node node;
++};
++
++/******************************************************************************
++ *
++ * union acpi_descriptor - objects that share a common descriptor identifier
++ *
++ *****************************************************************************/
++
++/* Object descriptor types */
++
++#define ACPI_DESC_TYPE_CACHED           0x01	/* Used only when object is cached */
++#define ACPI_DESC_TYPE_STATE            0x02
++#define ACPI_DESC_TYPE_STATE_UPDATE     0x03
++#define ACPI_DESC_TYPE_STATE_PACKAGE    0x04
++#define ACPI_DESC_TYPE_STATE_CONTROL    0x05
++#define ACPI_DESC_TYPE_STATE_RPSCOPE    0x06
++#define ACPI_DESC_TYPE_STATE_PSCOPE     0x07
++#define ACPI_DESC_TYPE_STATE_WSCOPE     0x08
++#define ACPI_DESC_TYPE_STATE_RESULT     0x09
++#define ACPI_DESC_TYPE_STATE_NOTIFY     0x0A
++#define ACPI_DESC_TYPE_STATE_THREAD     0x0B
++#define ACPI_DESC_TYPE_WALK             0x0C
++#define ACPI_DESC_TYPE_PARSER           0x0D
++#define ACPI_DESC_TYPE_OPERAND          0x0E
++#define ACPI_DESC_TYPE_NAMED            0x0F
++#define ACPI_DESC_TYPE_MAX              0x0F
++
++struct acpi_common_descriptor {
++	void *common_pointer;
++	u8 descriptor_type;	/* To differentiate various internal objs */
++};
++
++union acpi_descriptor {
++	struct acpi_common_descriptor common;
++	union acpi_operand_object object;
++	struct acpi_namespace_node node;
++	union acpi_parse_object op;
++};
++
++#pragma pack()
++
++#endif				/* _ACOBJECT_H */
+diff -Naurp a/firegl_public.c b/firegl_public.c
+--- a/firegl_public.c	2009-02-28 22:31:33.000000000 +0100
++++ b/firegl_public.c	2009-02-28 22:30:23.000000000 +0100
+@@ -1402,7 +1402,7 @@ KCL_TYPE_Pid ATI_API_CALL KCL_GetTgid(vo
+  */
+ KCL_TYPE_Uid ATI_API_CALL KCL_GetEffectiveUid(void)
+ {
+-    return current->euid;
++    return current->cred->euid;
+ }
+ 
+ /** /brief Delay execution for the specified number of microseconds
+@@ -1774,14 +1774,15 @@ int ATI_API_CALL KCL_PosixSecurityCapChe
+  */
+ void ATI_API_CALL KCL_PosixSecurityCapSetIPCLock(unsigned int lock)
+ {
++    struct cred* currentCred = (struct cred*)get_current_cred();
+     if (lock == 0 )
+     {
+-        cap_lower(current->cap_effective, CAP_IPC_LOCK);
++        cap_lower(currentCred->cap_effective, CAP_IPC_LOCK);
+     }
+     else
+     {
+-        cap_raise(current->cap_effective, CAP_IPC_LOCK);
+-    }    
++        cap_raise(currentCred->cap_effective, CAP_IPC_LOCK);
++    }
+     return; 
+ }
+ 
+diff -Naurp a/firegl_public.h b/firegl_public.h
+--- a/firegl_public.h	2009-03-01 00:21:56.000000000 +0100
++++ b/firegl_public.h	2009-03-01 00:21:17.000000000 +0100
+@@ -589,13 +589,13 @@ extern unsigned long        KCL_SYSINFO_
+ #define cpu_has_pge test_bit(X86_FEATURE_PGE, &boot_cpu_data.x86_capability)
+ #endif
+ 
+-#ifndef pgprot_writecombine
++/* #ifndef pgprot_writecombine */
+ #define pgprot_writecombine(prot) __pgprot((pgprot_val(prot) & ~(_PAGE_PCD)) | _PAGE_PWT)
+-#endif
++/* #endif */
+ 
+-#ifndef pgprot_noncached
++/* #ifndef pgprot_noncached */
+ #define pgprot_noncached(prot) __pgprot(pgprot_val(prot) | _PAGE_PCD | _PAGE_PWT)
+-#endif
++/* #endif */
+ 
+ #endif //FIREGL_USWC_SUPPORT
+ 
+diff -Naurp a/kcl_acpi.c b/kcl_acpi.c
+--- a/kcl_acpi.c	2009-02-28 21:39:21.000000000 +0100
++++ b/kcl_acpi.c	2009-02-28 22:25:29.000000000 +0100
+@@ -17,6 +17,9 @@
+ #include <linux/version.h>
+ #include <linux/autoconf.h>
+ #include <linux/acpi.h>
++#include "acpica-acconfig.h"
++#include "acpica-aclocal.h"
++#include "acpica-acobject.h"
+
+ #include "kcl_config.h"
+ #include "kcl_type.h"
+ 
+ 
\ Kein Zeilenumbruch am Dateiende.
diff -Nru 9.2/packages/Ubuntu/dists/hardy/dkms.conf.in 9.2.fix/packages/Ubuntu/dists/hardy/dkms.conf.in
--- 9.2/packages/Ubuntu/dists/hardy/dkms.conf.in	2009-02-11 18:40:36.000000000 +0100
+++ 9.2.fix/packages/Ubuntu/dists/hardy/dkms.conf.in	2009-03-24 22:59:44.120323961 +0100
@@ -5,5 +5,5 @@
 MAKE[0]="pushd ${dkms_tree}/fglrx/#CVERSION#/build; sh make.sh --nohints --uname_r=$kernelver; popd"
 DEST_MODULE_LOCATION[0]="/kernel/drivers/char/drm"
 AUTOINSTALL="yes"
-PATCH[0]="fglrx-rt-compat.patch"
-PATCH_MATCH[0]="rt"
+PATCH[0]="2.6.29_support_headers.patch"
+PATCH_MATCH[0]="2.6.29"
diff -Nru 9.2/packages/Ubuntu/dists/intrepid/dkms/patches/2.6.29_support_headers.patch 9.2.fix/packages/Ubuntu/dists/intrepid/dkms/2.6.29_support_headers.patch
--- 9.2/packages/Ubuntu/dists/intrepid/dkms/patches/2.6.29_support_headers.patch	1970-01-01 01:00:00.000000000 +0100
+++ 9.2.fix/packages/Ubuntu/dists/intrepid/dkms/patches/2.6.29_support_headers.patch	2009-03-19 00:18:10.000000000 +0100
@@ -0,0 +1,1754 @@
+  patch fglrx 9-2 aka 8.582 to work with linux 2.6.29
+	**** new version ****
+   
+   contains files from acpica.org
+
+	USE AT YOUR OWN RISK
+
+diff -Naurp a/2.6.x/Makefile b/2.6.x/Makefile
+--- a/2.6.x/Makefile	2009-02-28 21:53:58.000000000 +0100
++++ b/2.6.x/Makefile	2009-02-28 22:24:38.000000000 +0100
+@@ -55,7 +55,10 @@ fglrx-hdrs      += firegl_public.h      
+                    kcl_pci.h            \
+                    kcl_str.h            \
+                    kcl_type.h           \
+-                   kcl_wait.h
++                   kcl_wait.h		\
++		   acpica-acconfig.h    \
++		   acpica-aclocal.h     \
++		   acpica-acobject.h    
+                    
+ drm-hdrs        += drm.h drmP.h drm_os_linux.h drm_proc.h drm_compat.h
+ 
+diff -Naurp a/acpica-acconfig.h b/acpica-acconfig.h
+--- a/acpica-acconfig.h	1970-01-01 01:00:00.000000000 +0100
++++ b/acpica-acconfig.h	2009-02-28 22:24:01.000000000 +0100
+@@ -0,0 +1,217 @@
++/******************************************************************************
++ *
++ * Name: acconfig.h - Global configuration constants
++ *
++ *****************************************************************************/
++
++/*
++ * Copyright (C) 2000 - 2008, Intel Corp.
++ * All rights reserved.
++ *
++ * Redistribution and use in source and binary forms, with or without
++ * modification, are permitted provided that the following conditions
++ * are met:
++ * 1. Redistributions of source code must retain the above copyright
++ *    notice, this list of conditions, and the following disclaimer,
++ *    without modification.
++ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
++ *    substantially similar to the "NO WARRANTY" disclaimer below
++ *    ("Disclaimer") and any redistribution must be conditioned upon
++ *    including a substantially similar Disclaimer requirement for further
++ *    binary redistribution.
++ * 3. Neither the names of the above-listed copyright holders nor the names
++ *    of any contributors may be used to endorse or promote products derived
++ *    from this software without specific prior written permission.
++ *
++ * Alternatively, this software may be distributed under the terms of the
++ * GNU General Public License ("GPL") version 2 as published by the Free
++ * Software Foundation.
++ *
++ * NO WARRANTY
++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
++ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
++ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
++ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
++ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
++ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
++ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
++ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
++ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
++ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
++ * POSSIBILITY OF SUCH DAMAGES.
++ */
++
++#ifndef _ACCONFIG_H
++#define _ACCONFIG_H
++
++/******************************************************************************
++ *
++ * Configuration options
++ *
++ *****************************************************************************/
++
++/*
++ * ACPI_DEBUG_OUTPUT    - This switch enables all the debug facilities of the
++ *                        ACPI subsystem.  This includes the DEBUG_PRINT output
++ *                        statements.  When disabled, all DEBUG_PRINT
++ *                        statements are compiled out.
++ *
++ * ACPI_APPLICATION     - Use this switch if the subsystem is going to be run
++ *                        at the application level.
++ *
++ */
++
++/*
++ * OS name, used for the _OS object.  The _OS object is essentially obsolete,
++ * but there is a large base of ASL/AML code in existing machines that check
++ * for the string below.  The use of this string usually guarantees that
++ * the ASL will execute down the most tested code path.  Also, there is some
++ * code that will not execute the _OSI method unless _OS matches the string
++ * below.  Therefore, change this string at your own risk.
++ */
++#define ACPI_OS_NAME                    "Microsoft Windows NT"
++
++/* Maximum objects in the various object caches */
++
++#define ACPI_MAX_STATE_CACHE_DEPTH      96	/* State objects */
++#define ACPI_MAX_PARSE_CACHE_DEPTH      96	/* Parse tree objects */
++#define ACPI_MAX_EXTPARSE_CACHE_DEPTH   96	/* Parse tree objects */
++#define ACPI_MAX_OBJECT_CACHE_DEPTH     96	/* Interpreter operand objects */
++#define ACPI_MAX_NAMESPACE_CACHE_DEPTH  96	/* Namespace objects */
++
++/*
++ * Should the subsystem abort the loading of an ACPI table if the
++ * table checksum is incorrect?
++ */
++#define ACPI_CHECKSUM_ABORT             FALSE
++
++/******************************************************************************
++ *
++ * Subsystem Constants
++ *
++ *****************************************************************************/
++
++/* Version of ACPI supported */
++
++#define ACPI_CA_SUPPORT_LEVEL           3
++
++/* Maximum count for a semaphore object */
++
++#define ACPI_MAX_SEMAPHORE_COUNT        256
++
++/* Maximum object reference count (detects object deletion issues) */
++
++#define ACPI_MAX_REFERENCE_COUNT        0x1000
++
++/* Size of cached memory mapping for system memory operation region */
++
++#define ACPI_SYSMEM_REGION_WINDOW_SIZE  4096
++
++/* owner_id tracking. 8 entries allows for 255 owner_ids */
++
++#define ACPI_NUM_OWNERID_MASKS          8
++
++/* Size of the root table array is increased by this increment */
++
++#define ACPI_ROOT_TABLE_SIZE_INCREMENT  4
++
++/* Maximum number of While() loop iterations before forced abort */
++
++#define ACPI_MAX_LOOP_ITERATIONS        0xFFFF
++
++/******************************************************************************
++ *
++ * ACPI Specification constants (Do not change unless the specification changes)
++ *
++ *****************************************************************************/
++
++/* Number of distinct GPE register blocks and register width */
++
++#define ACPI_MAX_GPE_BLOCKS             2
++#define ACPI_GPE_REGISTER_WIDTH         8
++
++/* Method info (in WALK_STATE), containing local variables and argumetns */
++
++#define ACPI_METHOD_NUM_LOCALS          8
++#define ACPI_METHOD_MAX_LOCAL           7
++
++#define ACPI_METHOD_NUM_ARGS            7
++#define ACPI_METHOD_MAX_ARG             6
++
++/* Length of _HID, _UID, _CID, and UUID values */
++
++#define ACPI_DEVICE_ID_LENGTH           0x09
++#define ACPI_MAX_CID_LENGTH             48
++#define ACPI_UUID_LENGTH                16
++
++/*
++ * Operand Stack (in WALK_STATE), Must be large enough to contain METHOD_MAX_ARG
++ */
++#define ACPI_OBJ_NUM_OPERANDS           8
++#define ACPI_OBJ_MAX_OPERAND            7
++
++/* Number of elements in the Result Stack frame, can be an arbitrary value */
++
++#define ACPI_RESULTS_FRAME_OBJ_NUM      8
++
++/*
++ * Maximal number of elements the Result Stack can contain,
++ * it may be an arbitray value not exceeding the types of
++ * result_size and result_count (now u8).
++ */
++#define ACPI_RESULTS_OBJ_NUM_MAX        255
++
++/* Names within the namespace are 4 bytes long */
++
++#define ACPI_NAME_SIZE                  4
++#define ACPI_PATH_SEGMENT_LENGTH        5	/* 4 chars for name + 1 char for separator */
++#define ACPI_PATH_SEPARATOR             '.'
++
++/* Sizes for ACPI table headers */
++
++#define ACPI_OEM_ID_SIZE                6
++#define ACPI_OEM_TABLE_ID_SIZE          8
++
++/* Constants used in searching for the RSDP in low memory */
++
++#define ACPI_EBDA_PTR_LOCATION          0x0000040E	/* Physical Address */
++#define ACPI_EBDA_PTR_LENGTH            2
++#define ACPI_EBDA_WINDOW_SIZE           1024
++#define ACPI_HI_RSDP_WINDOW_BASE        0x000E0000	/* Physical Address */
++#define ACPI_HI_RSDP_WINDOW_SIZE        0x00020000
++#define ACPI_RSDP_SCAN_STEP             16
++
++/* Operation regions */
++
++#define ACPI_NUM_PREDEFINED_REGIONS     8
++#define ACPI_USER_REGION_BEGIN          0x80
++
++/* Maximum space_ids for Operation Regions */
++
++#define ACPI_MAX_ADDRESS_SPACE          255
++
++/* Array sizes.  Used for range checking also */
++
++#define ACPI_MAX_MATCH_OPCODE           5
++
++/* RSDP checksums */
++
++#define ACPI_RSDP_CHECKSUM_LENGTH       20
++#define ACPI_RSDP_XCHECKSUM_LENGTH      36
++
++/* SMBus bidirectional buffer size */
++
++#define ACPI_SMBUS_BUFFER_SIZE          34
++
++/******************************************************************************
++ *
++ * ACPI AML Debugger
++ *
++ *****************************************************************************/
++
++#define ACPI_DEBUGGER_MAX_ARGS          8	/* Must be max method args + 1 */
++
++#define ACPI_DEBUGGER_COMMAND_PROMPT    '-'
++#define ACPI_DEBUGGER_EXECUTE_PROMPT    '%'
++
++#endif				/* _ACCONFIG_H */
+diff -Naurp a/acpica-aclocal.h b/acpica-aclocal.h
+--- a/acpica-aclocal.h	1970-01-01 01:00:00.000000000 +0100
++++ b/acpica-aclocal.h	2009-02-28 21:35:32.000000000 +0100
+@@ -0,0 +1,990 @@
++/******************************************************************************
++ *
++ * Name: aclocal.h - Internal data types used across the ACPI subsystem
++ *
++ *****************************************************************************/
++
++/*
++ * Copyright (C) 2000 - 2008, Intel Corp.
++ * All rights reserved.
++ *
++ * Redistribution and use in source and binary forms, with or without
++ * modification, are permitted provided that the following conditions
++ * are met:
++ * 1. Redistributions of source code must retain the above copyright
++ *    notice, this list of conditions, and the following disclaimer,
++ *    without modification.
++ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
++ *    substantially similar to the "NO WARRANTY" disclaimer below
++ *    ("Disclaimer") and any redistribution must be conditioned upon
++ *    including a substantially similar Disclaimer requirement for further
++ *    binary redistribution.
++ * 3. Neither the names of the above-listed copyright holders nor the names
++ *    of any contributors may be used to endorse or promote products derived
++ *    from this software without specific prior written permission.
++ *
++ * Alternatively, this software may be distributed under the terms of the
++ * GNU General Public License ("GPL") version 2 as published by the Free
++ * Software Foundation.
++ *
++ * NO WARRANTY
++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
++ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
++ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
++ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
++ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
++ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
++ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
++ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
++ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
++ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
++ * POSSIBILITY OF SUCH DAMAGES.
++ */
++
++#ifndef __ACLOCAL_H__
++#define __ACLOCAL_H__
++
++/* acpisrc:struct_defs -- for acpisrc conversion */
++
++#define ACPI_SERIALIZED                 0xFF
++
++typedef u32 acpi_mutex_handle;
++#define ACPI_GLOBAL_LOCK                (acpi_semaphore) (-1)
++
++/* Total number of aml opcodes defined */
++
++#define AML_NUM_OPCODES                 0x7F
++
++/* Forward declarations */
++
++struct acpi_walk_state;
++struct acpi_obj_mutex;
++union acpi_parse_object;
++
++/*****************************************************************************
++ *
++ * Mutex typedefs and structs
++ *
++ ****************************************************************************/
++
++/*
++ * Predefined handles for the mutex objects used within the subsystem
++ * All mutex objects are automatically created by acpi_ut_mutex_initialize.
++ *
++ * The acquire/release ordering protocol is implied via this list. Mutexes
++ * with a lower value must be acquired before mutexes with a higher value.
++ *
++ * NOTE: any changes here must be reflected in the acpi_gbl_mutex_names
++ * table below also!
++ */
++#define ACPI_MTX_INTERPRETER            0	/* AML Interpreter, main lock */
++#define ACPI_MTX_NAMESPACE              1	/* ACPI Namespace */
++#define ACPI_MTX_TABLES                 2	/* Data for ACPI tables */
++#define ACPI_MTX_EVENTS                 3	/* Data for ACPI events */
++#define ACPI_MTX_CACHES                 4	/* Internal caches, general purposes */
++#define ACPI_MTX_MEMORY                 5	/* Debug memory tracking lists */
++#define ACPI_MTX_DEBUG_CMD_COMPLETE     6	/* AML debugger */
++#define ACPI_MTX_DEBUG_CMD_READY        7	/* AML debugger */
++
++#define ACPI_MAX_MUTEX                  7
++#define ACPI_NUM_MUTEX                  ACPI_MAX_MUTEX+1
++
++#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
++#ifdef DEFINE_ACPI_GLOBALS
++
++/* Debug names for the mutexes above */
++
++static char *acpi_gbl_mutex_names[ACPI_NUM_MUTEX] = {
++	"ACPI_MTX_Interpreter",
++	"ACPI_MTX_Namespace",
++	"ACPI_MTX_Tables",
++	"ACPI_MTX_Events",
++	"ACPI_MTX_Caches",
++	"ACPI_MTX_Memory",
++	"ACPI_MTX_CommandComplete",
++	"ACPI_MTX_CommandReady"
++};
++
++#endif
++#endif
++
++/*
++ * Predefined handles for spinlocks used within the subsystem.
++ * These spinlocks are created by acpi_ut_mutex_initialize
++ */
++#define ACPI_LOCK_GPES                  0
++#define ACPI_LOCK_HARDWARE              1
++
++#define ACPI_MAX_LOCK                   1
++#define ACPI_NUM_LOCK                   ACPI_MAX_LOCK+1
++
++/* This Thread ID means that the mutex is not in use (unlocked) */
++
++#define ACPI_MUTEX_NOT_ACQUIRED         (acpi_thread_id) 0
++
++/* Table for the global mutexes */
++
++struct acpi_mutex_info {
++	acpi_mutex mutex;
++	u32 use_count;
++	acpi_thread_id thread_id;
++};
++
++/* Lock flag parameter for various interfaces */
++
++#define ACPI_MTX_DO_NOT_LOCK            0
++#define ACPI_MTX_LOCK                   1
++
++/* Field access granularities */
++
++#define ACPI_FIELD_BYTE_GRANULARITY     1
++#define ACPI_FIELD_WORD_GRANULARITY     2
++#define ACPI_FIELD_DWORD_GRANULARITY    4
++#define ACPI_FIELD_QWORD_GRANULARITY    8
++
++#define ACPI_ENTRY_NOT_FOUND            NULL
++
++/*****************************************************************************
++ *
++ * Namespace typedefs and structs
++ *
++ ****************************************************************************/
++
++/* Operational modes of the AML interpreter/scanner */
++
++typedef enum {
++	ACPI_IMODE_LOAD_PASS1 = 0x01,
++	ACPI_IMODE_LOAD_PASS2 = 0x02,
++	ACPI_IMODE_EXECUTE = 0x03
++} acpi_interpreter_mode;
++
++/*
++ * The Namespace Node describes a named object that appears in the AML.
++ * descriptor_type is used to differentiate between internal descriptors.
++ *
++ * The node is optimized for both 32-bit and 64-bit platforms:
++ * 20 bytes for the 32-bit case, 32 bytes for the 64-bit case.
++ *
++ * Note: The descriptor_type and Type fields must appear in the identical
++ * position in both the struct acpi_namespace_node and union acpi_operand_object
++ * structures.
++ */
++struct acpi_namespace_node {
++	union acpi_operand_object *object;	/* Interpreter object */
++	u8 descriptor_type;	/* Differentiate object descriptor types */
++	u8 type;		/* ACPI Type associated with this name */
++	u8 flags;		/* Miscellaneous flags */
++	acpi_owner_id owner_id;	/* Node creator */
++	union acpi_name_union name;	/* ACPI Name, always 4 chars per ACPI spec */
++	struct acpi_namespace_node *child;	/* First child */
++	struct acpi_namespace_node *peer;	/* Peer. Parent if ANOBJ_END_OF_PEER_LIST set */
++
++	/*
++	 * The following fields are used by the ASL compiler and disassembler only
++	 */
++#ifdef ACPI_LARGE_NAMESPACE_NODE
++	union acpi_parse_object *op;
++	u32 value;
++	u32 length;
++#endif
++};
++
++/* Namespace Node flags */
++
++#define ANOBJ_END_OF_PEER_LIST          0x01	/* End-of-list, Peer field points to parent */
++#define ANOBJ_TEMPORARY                 0x02	/* Node is create by a method and is temporary */
++#define ANOBJ_METHOD_ARG                0x04	/* Node is a method argument */
++#define ANOBJ_METHOD_LOCAL              0x08	/* Node is a method local */
++#define ANOBJ_SUBTREE_HAS_INI           0x10	/* Used to optimize device initialization */
++#define ANOBJ_EVALUATED                 0x20	/* Set on first evaluation of node */
++
++#define ANOBJ_IS_EXTERNAL               0x08	/* i_aSL only: This object created via External() */
++#define ANOBJ_METHOD_NO_RETVAL          0x10	/* i_aSL only: Method has no return value */
++#define ANOBJ_METHOD_SOME_NO_RETVAL     0x20	/* i_aSL only: Method has at least one return value */
++#define ANOBJ_IS_BIT_OFFSET             0x40	/* i_aSL only: Reference is a bit offset */
++#define ANOBJ_IS_REFERENCED             0x80	/* i_aSL only: Object was referenced */
++
++/* One internal RSDT for table management */
++
++struct acpi_internal_rsdt {
++	struct acpi_table_desc *tables;
++	u32 count;
++	u32 size;
++	u8 flags;
++};
++
++/* Flags for above */
++
++#define ACPI_ROOT_ORIGIN_UNKNOWN        (0)	/* ~ORIGIN_ALLOCATED */
++#define ACPI_ROOT_ORIGIN_ALLOCATED      (1)
++#define ACPI_ROOT_ALLOW_RESIZE          (2)
++
++/* Predefined (fixed) table indexes */
++
++#define ACPI_TABLE_INDEX_DSDT           (0)
++#define ACPI_TABLE_INDEX_FACS           (1)
++
++struct acpi_find_context {
++	char *search_for;
++	acpi_handle *list;
++	u32 *count;
++};
++
++struct acpi_ns_search_data {
++	struct acpi_namespace_node *node;
++};
++
++/* Object types used during package copies */
++
++#define ACPI_COPY_TYPE_SIMPLE           0
++#define ACPI_COPY_TYPE_PACKAGE          1
++
++/* Info structure used to convert external<->internal namestrings */
++
++struct acpi_namestring_info {
++	const char *external_name;
++	const char *next_external_char;
++	char *internal_name;
++	u32 length;
++	u32 num_segments;
++	u32 num_carats;
++	u8 fully_qualified;
++};
++
++/* Field creation info */
++
++struct acpi_create_field_info {
++	struct acpi_namespace_node *region_node;
++	struct acpi_namespace_node *field_node;
++	struct acpi_namespace_node *register_node;
++	struct acpi_namespace_node *data_register_node;
++	u32 bank_value;
++	u32 field_bit_position;
++	u32 field_bit_length;
++	u8 field_flags;
++	u8 attribute;
++	u8 field_type;
++};
++
++typedef
++acpi_status(*ACPI_INTERNAL_METHOD) (struct acpi_walk_state * walk_state);
++
++/*
++ * Bitmapped ACPI types.  Used internally only
++ */
++#define ACPI_BTYPE_ANY                  0x00000000
++#define ACPI_BTYPE_INTEGER              0x00000001
++#define ACPI_BTYPE_STRING               0x00000002
++#define ACPI_BTYPE_BUFFER               0x00000004
++#define ACPI_BTYPE_PACKAGE              0x00000008
++#define ACPI_BTYPE_FIELD_UNIT           0x00000010
++#define ACPI_BTYPE_DEVICE               0x00000020
++#define ACPI_BTYPE_EVENT                0x00000040
++#define ACPI_BTYPE_METHOD               0x00000080
++#define ACPI_BTYPE_MUTEX                0x00000100
++#define ACPI_BTYPE_REGION               0x00000200
++#define ACPI_BTYPE_POWER                0x00000400
++#define ACPI_BTYPE_PROCESSOR            0x00000800
++#define ACPI_BTYPE_THERMAL              0x00001000
++#define ACPI_BTYPE_BUFFER_FIELD         0x00002000
++#define ACPI_BTYPE_DDB_HANDLE           0x00004000
++#define ACPI_BTYPE_DEBUG_OBJECT         0x00008000
++#define ACPI_BTYPE_REFERENCE            0x00010000
++#define ACPI_BTYPE_RESOURCE             0x00020000
++
++#define ACPI_BTYPE_COMPUTE_DATA         (ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER)
++
++#define ACPI_BTYPE_DATA                 (ACPI_BTYPE_COMPUTE_DATA  | ACPI_BTYPE_PACKAGE)
++#define ACPI_BTYPE_DATA_REFERENCE       (ACPI_BTYPE_DATA | ACPI_BTYPE_REFERENCE | ACPI_BTYPE_DDB_HANDLE)
++#define ACPI_BTYPE_DEVICE_OBJECTS       (ACPI_BTYPE_DEVICE | ACPI_BTYPE_THERMAL | ACPI_BTYPE_PROCESSOR)
++#define ACPI_BTYPE_OBJECTS_AND_REFS     0x0001FFFF	/* ARG or LOCAL */
++#define ACPI_BTYPE_ALL_OBJECTS          0x0000FFFF
++
++/*
++ * Information structure for ACPI predefined names.
++ * Each entry in the table contains the following items:
++ *
++ * Name                 - The ACPI reserved name
++ * param_count          - Number of arguments to the method
++ * expected_return_btypes - Allowed type(s) for the return value
++ */
++struct acpi_name_info {
++	char name[ACPI_NAME_SIZE];
++	u8 param_count;
++	u8 expected_btypes;
++};
++
++/*
++ * Secondary information structures for ACPI predefined objects that return
++ * package objects. This structure appears as the next entry in the table
++ * after the NAME_INFO structure above.
++ *
++ * The reason for this is to minimize the size of the predefined name table.
++ */
++
++/*
++ * Used for ACPI_PTYPE1_FIXED, ACPI_PTYPE1_VAR, ACPI_PTYPE2,
++ * ACPI_PTYPE2_MIN, ACPI_PTYPE2_PKG_COUNT, ACPI_PTYPE2_COUNT
++ */
++struct acpi_package_info {
++	u8 type;
++	u8 object_type1;
++	u8 count1;
++	u8 object_type2;
++	u8 count2;
++	u8 reserved;
++};
++
++/* Used for ACPI_PTYPE2_FIXED */
++
++struct acpi_package_info2 {
++	u8 type;
++	u8 count;
++	u8 object_type[4];
++};
++
++/* Used for ACPI_PTYPE1_OPTION */
++
++struct acpi_package_info3 {
++	u8 type;
++	u8 count;
++	u8 object_type[2];
++	u8 tail_object_type;
++	u8 reserved;
++};
++
++union acpi_predefined_info {
++	struct acpi_name_info info;
++	struct acpi_package_info ret_info;
++	struct acpi_package_info2 ret_info2;
++	struct acpi_package_info3 ret_info3;
++};
++
++/*
++ * Bitmapped return value types
++ * Note: the actual data types must be contiguous, a loop in nspredef.c
++ * depends on this.
++ */
++#define ACPI_RTYPE_ANY                  0x00
++#define ACPI_RTYPE_NONE                 0x01
++#define ACPI_RTYPE_INTEGER              0x02
++#define ACPI_RTYPE_STRING               0x04
++#define ACPI_RTYPE_BUFFER               0x08
++#define ACPI_RTYPE_PACKAGE              0x10
++#define ACPI_RTYPE_REFERENCE            0x20
++#define ACPI_RTYPE_ALL                  0x3F
++
++#define ACPI_NUM_RTYPES                 5	/* Number of actual object types */
++
++/*****************************************************************************
++ *
++ * Event typedefs and structs
++ *
++ ****************************************************************************/
++
++/* Dispatch info for each GPE -- either a method or handler, cannot be both */
++
++struct acpi_handler_info {
++	acpi_event_handler address;	/* Address of handler, if any */
++	void *context;		/* Context to be passed to handler */
++	struct acpi_namespace_node *method_node;	/* Method node for this GPE level (saved) */
++};
++
++union acpi_gpe_dispatch_info {
++	struct acpi_namespace_node *method_node;	/* Method node for this GPE level */
++	struct acpi_handler_info *handler;
++};
++
++/*
++ * Information about a GPE, one per each GPE in an array.
++ * NOTE: Important to keep this struct as small as possible.
++ */
++struct acpi_gpe_event_info {
++	union acpi_gpe_dispatch_info dispatch;	/* Either Method or Handler */
++	struct acpi_gpe_register_info *register_info;	/* Backpointer to register info */
++	u8 flags;		/* Misc info about this GPE */
++	u8 gpe_number;		/* This GPE */
++};
++
++/* Information about a GPE register pair, one per each status/enable pair in an array */
++
++struct acpi_gpe_register_info {
++	struct acpi_generic_address status_address;	/* Address of status reg */
++	struct acpi_generic_address enable_address;	/* Address of enable reg */
++	u8 enable_for_wake;	/* GPEs to keep enabled when sleeping */
++	u8 enable_for_run;	/* GPEs to keep enabled when running */
++	u8 base_gpe_number;	/* Base GPE number for this register */
++};
++
++/*
++ * Information about a GPE register block, one per each installed block --
++ * GPE0, GPE1, and one per each installed GPE Block Device.
++ */
++struct acpi_gpe_block_info {
++	struct acpi_namespace_node *node;
++	struct acpi_gpe_block_info *previous;
++	struct acpi_gpe_block_info *next;
++	struct acpi_gpe_xrupt_info *xrupt_block;	/* Backpointer to interrupt block */
++	struct acpi_gpe_register_info *register_info;	/* One per GPE register pair */
++	struct acpi_gpe_event_info *event_info;	/* One for each GPE */
++	struct acpi_generic_address block_address;	/* Base address of the block */
++	u32 register_count;	/* Number of register pairs in block */
++	u8 block_base_number;	/* Base GPE number for this block */
++};
++
++/* Information about GPE interrupt handlers, one per each interrupt level used for GPEs */
++
++struct acpi_gpe_xrupt_info {
++	struct acpi_gpe_xrupt_info *previous;
++	struct acpi_gpe_xrupt_info *next;
++	struct acpi_gpe_block_info *gpe_block_list_head;	/* List of GPE blocks for this xrupt */
++	u32 interrupt_number;	/* System interrupt number */
++};
++
++struct acpi_gpe_walk_info {
++	struct acpi_namespace_node *gpe_device;
++	struct acpi_gpe_block_info *gpe_block;
++};
++
++struct acpi_gpe_device_info {
++	u32 index;
++	u32 next_block_base_index;
++	acpi_status status;
++	struct acpi_namespace_node *gpe_device;
++};
++
++typedef acpi_status(*acpi_gpe_callback) (struct acpi_gpe_xrupt_info *gpe_xrupt_info,
++		struct acpi_gpe_block_info *gpe_block, void *context);
++
++/* Information about each particular fixed event */
++
++struct acpi_fixed_event_handler {
++	acpi_event_handler handler;	/* Address of handler. */
++	void *context;		/* Context to be passed to handler */
++};
++
++struct acpi_fixed_event_info {
++	u8 status_register_id;
++	u8 enable_register_id;
++	u16 status_bit_mask;
++	u16 enable_bit_mask;
++};
++
++/* Information used during field processing */
++
++struct acpi_field_info {
++	u8 skip_field;
++	u8 field_flag;
++	u32 pkg_length;
++};
++
++/*****************************************************************************
++ *
++ * Generic "state" object for stacks
++ *
++ ****************************************************************************/
++
++#define ACPI_CONTROL_NORMAL                  0xC0
++#define ACPI_CONTROL_CONDITIONAL_EXECUTING   0xC1
++#define ACPI_CONTROL_PREDICATE_EXECUTING     0xC2
++#define ACPI_CONTROL_PREDICATE_FALSE         0xC3
++#define ACPI_CONTROL_PREDICATE_TRUE          0xC4
++
++#define ACPI_STATE_COMMON \
++	void                            *next; \
++	u8                              descriptor_type; /* To differentiate various internal objs */\
++	u8                              flags; \
++	u16                             value; \
++	u16                             state;
++
++	/* There are 2 bytes available here until the next natural alignment boundary */
++
++struct acpi_common_state {
++ACPI_STATE_COMMON};
++
++/*
++ * Update state - used to traverse complex objects such as packages
++ */
++struct acpi_update_state {
++	ACPI_STATE_COMMON union acpi_operand_object *object;
++};
++
++/*
++ * Pkg state - used to traverse nested package structures
++ */
++struct acpi_pkg_state {
++	ACPI_STATE_COMMON u16 index;
++	union acpi_operand_object *source_object;
++	union acpi_operand_object *dest_object;
++	struct acpi_walk_state *walk_state;
++	void *this_target_obj;
++	u32 num_packages;
++};
++
++/*
++ * Control state - one per if/else and while constructs.
++ * Allows nesting of these constructs
++ */
++struct acpi_control_state {
++	ACPI_STATE_COMMON u16 opcode;
++	union acpi_parse_object *predicate_op;
++	u8 *aml_predicate_start;	/* Start of if/while predicate */
++	u8 *package_end;	/* End of if/while block */
++	u32 loop_count;		/* While() loop counter */
++};
++
++/*
++ * Scope state - current scope during namespace lookups
++ */
++struct acpi_scope_state {
++	ACPI_STATE_COMMON struct acpi_namespace_node *node;
++};
++
++struct acpi_pscope_state {
++	ACPI_STATE_COMMON u32 arg_count;	/* Number of fixed arguments */
++	union acpi_parse_object *op;	/* Current op being parsed */
++	u8 *arg_end;		/* Current argument end */
++	u8 *pkg_end;		/* Current package end */
++	u32 arg_list;		/* Next argument to parse */
++};
++
++/*
++ * Thread state - one per thread across multiple walk states.  Multiple walk
++ * states are created when there are nested control methods executing.
++ */
++struct acpi_thread_state {
++	ACPI_STATE_COMMON u8 current_sync_level;	/* Mutex Sync (nested acquire) level */
++	struct acpi_walk_state *walk_state_list;	/* Head of list of walk_states for this thread */
++	union acpi_operand_object *acquired_mutex_list;	/* List of all currently acquired mutexes */
++	acpi_thread_id thread_id;	/* Running thread ID */
++};
++
++/*
++ * Result values - used to accumulate the results of nested
++ * AML arguments
++ */
++struct acpi_result_values {
++	ACPI_STATE_COMMON
++	    union acpi_operand_object *obj_desc[ACPI_RESULTS_FRAME_OBJ_NUM];
++};
++
++typedef
++acpi_status(*acpi_parse_downwards) (struct acpi_walk_state * walk_state,
++				    union acpi_parse_object ** out_op);
++
++typedef acpi_status(*acpi_parse_upwards) (struct acpi_walk_state * walk_state);
++
++/*
++ * Notify info - used to pass info to the deferred notify
++ * handler/dispatcher.
++ */
++struct acpi_notify_info {
++	ACPI_STATE_COMMON struct acpi_namespace_node *node;
++	union acpi_operand_object *handler_obj;
++};
++
++/* Generic state is union of structs above */
++
++union acpi_generic_state {
++	struct acpi_common_state common;
++	struct acpi_control_state control;
++	struct acpi_update_state update;
++	struct acpi_scope_state scope;
++	struct acpi_pscope_state parse_scope;
++	struct acpi_pkg_state pkg;
++	struct acpi_thread_state thread;
++	struct acpi_result_values results;
++	struct acpi_notify_info notify;
++};
++
++/*****************************************************************************
++ *
++ * Interpreter typedefs and structs
++ *
++ ****************************************************************************/
++
++typedef acpi_status(*ACPI_EXECUTE_OP) (struct acpi_walk_state * walk_state);
++
++/*****************************************************************************
++ *
++ * Parser typedefs and structs
++ *
++ ****************************************************************************/
++
++/*
++ * AML opcode, name, and argument layout
++ */
++struct acpi_opcode_info {
++#if defined(ACPI_DISASSEMBLER) || defined(ACPI_DEBUG_OUTPUT)
++	char *name;		/* Opcode name (disassembler/debug only) */
++#endif
++	u32 parse_args;		/* Grammar/Parse time arguments */
++	u32 runtime_args;	/* Interpret time arguments */
++	u16 flags;		/* Misc flags */
++	u8 object_type;		/* Corresponding internal object type */
++	u8 class;		/* Opcode class */
++	u8 type;		/* Opcode type */
++};
++
++union acpi_parse_value {
++	acpi_integer integer;	/* Integer constant (Up to 64 bits) */
++	struct uint64_struct integer64;	/* Structure overlay for 2 32-bit Dwords */
++	u32 size;		/* bytelist or field size */
++	char *string;		/* NULL terminated string */
++	u8 *buffer;		/* buffer or string */
++	char *name;		/* NULL terminated string */
++	union acpi_parse_object *arg;	/* arguments and contained ops */
++};
++
++#ifdef ACPI_DISASSEMBLER
++#define ACPI_DISASM_ONLY_MEMBERS(a)     a;
++#else
++#define ACPI_DISASM_ONLY_MEMBERS(a)
++#endif
++
++#define ACPI_PARSE_COMMON \
++	union acpi_parse_object         *parent;        /* Parent op */\
++	u8                              descriptor_type; /* To differentiate various internal objs */\
++	u8                              flags;          /* Type of Op */\
++	u16                             aml_opcode;     /* AML opcode */\
++	u32                             aml_offset;     /* Offset of declaration in AML */\
++	union acpi_parse_object         *next;          /* Next op */\
++	struct acpi_namespace_node      *node;          /* For use by interpreter */\
++	union acpi_parse_value          value;          /* Value or args associated with the opcode */\
++	u8                              arg_list_length; /* Number of elements in the arg list */\
++	ACPI_DISASM_ONLY_MEMBERS (\
++	u8                              disasm_flags;   /* Used during AML disassembly */\
++	u8                              disasm_opcode;  /* Subtype used for disassembly */\
++	char                            aml_op_name[16])	/* Op name (debug only) */
++
++#define ACPI_DASM_BUFFER                0x00
++#define ACPI_DASM_RESOURCE              0x01
++#define ACPI_DASM_STRING                0x02
++#define ACPI_DASM_UNICODE               0x03
++#define ACPI_DASM_EISAID                0x04
++#define ACPI_DASM_MATCHOP               0x05
++#define ACPI_DASM_LNOT_PREFIX           0x06
++#define ACPI_DASM_LNOT_SUFFIX           0x07
++#define ACPI_DASM_IGNORE                0x08
++
++/*
++ * Generic operation (for example:  If, While, Store)
++ */
++struct acpi_parse_obj_common {
++ACPI_PARSE_COMMON};
++
++/*
++ * Extended Op for named ops (Scope, Method, etc.), deferred ops (Methods and op_regions),
++ * and bytelists.
++ */
++struct acpi_parse_obj_named {
++	ACPI_PARSE_COMMON u8 *path;
++	u8 *data;		/* AML body or bytelist data */
++	u32 length;		/* AML length */
++	u32 name;		/* 4-byte name or zero if no name */
++};
++
++/* This version is used by the i_aSL compiler only */
++
++#define ACPI_MAX_PARSEOP_NAME   20
++
++struct acpi_parse_obj_asl {
++	ACPI_PARSE_COMMON union acpi_parse_object *child;
++	union acpi_parse_object *parent_method;
++	char *filename;
++	char *external_name;
++	char *namepath;
++	char name_seg[4];
++	u32 extra_value;
++	u32 column;
++	u32 line_number;
++	u32 logical_line_number;
++	u32 logical_byte_offset;
++	u32 end_line;
++	u32 end_logical_line;
++	u32 acpi_btype;
++	u32 aml_length;
++	u32 aml_subtree_length;
++	u32 final_aml_length;
++	u32 final_aml_offset;
++	u32 compile_flags;
++	u16 parse_opcode;
++	u8 aml_opcode_length;
++	u8 aml_pkg_len_bytes;
++	u8 extra;
++	char parse_op_name[ACPI_MAX_PARSEOP_NAME];
++};
++
++union acpi_parse_object {
++	struct acpi_parse_obj_common common;
++	struct acpi_parse_obj_named named;
++	struct acpi_parse_obj_asl asl;
++};
++
++/*
++ * Parse state - one state per parser invocation and each control
++ * method.
++ */
++struct acpi_parse_state {
++	u8 *aml_start;		/* First AML byte */
++	u8 *aml;		/* Next AML byte */
++	u8 *aml_end;		/* (last + 1) AML byte */
++	u8 *pkg_start;		/* Current package begin */
++	u8 *pkg_end;		/* Current package end */
++	union acpi_parse_object *start_op;	/* Root of parse tree */
++	struct acpi_namespace_node *start_node;
++	union acpi_generic_state *scope;	/* Current scope */
++	union acpi_parse_object *start_scope;
++	u32 aml_size;
++};
++
++/* Parse object flags */
++
++#define ACPI_PARSEOP_GENERIC            0x01
++#define ACPI_PARSEOP_NAMED              0x02
++#define ACPI_PARSEOP_DEFERRED           0x04
++#define ACPI_PARSEOP_BYTELIST           0x08
++#define ACPI_PARSEOP_IN_STACK           0x10
++#define ACPI_PARSEOP_TARGET             0x20
++#define ACPI_PARSEOP_IN_CACHE           0x80
++
++/* Parse object disasm_flags */
++
++#define ACPI_PARSEOP_IGNORE             0x01
++#define ACPI_PARSEOP_PARAMLIST          0x02
++#define ACPI_PARSEOP_EMPTY_TERMLIST     0x04
++#define ACPI_PARSEOP_SPECIAL            0x10
++
++/*****************************************************************************
++ *
++ * Hardware (ACPI registers) and PNP
++ *
++ ****************************************************************************/
++
++struct acpi_bit_register_info {
++	u8 parent_register;
++	u8 bit_position;
++	u16 access_bit_mask;
++};
++
++/*
++ * Some ACPI registers have bits that must be ignored -- meaning that they
++ * must be preserved.
++ */
++#define ACPI_PM1_STATUS_PRESERVED_BITS          0x0800	/* Bit 11 */
++#define ACPI_PM1_CONTROL_PRESERVED_BITS         0x0200	/* Bit 9 (whatever) */
++
++/*
++ * Register IDs
++ * These are the full ACPI registers
++ */
++#define ACPI_REGISTER_PM1_STATUS                0x01
++#define ACPI_REGISTER_PM1_ENABLE                0x02
++#define ACPI_REGISTER_PM1_CONTROL               0x03
++#define ACPI_REGISTER_PM1A_CONTROL              0x04
++#define ACPI_REGISTER_PM1B_CONTROL              0x05
++#define ACPI_REGISTER_PM2_CONTROL               0x06
++#define ACPI_REGISTER_PM_TIMER                  0x07
++#define ACPI_REGISTER_PROCESSOR_BLOCK           0x08
++#define ACPI_REGISTER_SMI_COMMAND_BLOCK         0x09
++
++/* Masks used to access the bit_registers */
++
++#define ACPI_BITMASK_TIMER_STATUS               0x0001
++#define ACPI_BITMASK_BUS_MASTER_STATUS          0x0010
++#define ACPI_BITMASK_GLOBAL_LOCK_STATUS         0x0020
++#define ACPI_BITMASK_POWER_BUTTON_STATUS        0x0100
++#define ACPI_BITMASK_SLEEP_BUTTON_STATUS        0x0200
++#define ACPI_BITMASK_RT_CLOCK_STATUS            0x0400
++#define ACPI_BITMASK_PCIEXP_WAKE_STATUS         0x4000	/* ACPI 3.0 */
++#define ACPI_BITMASK_WAKE_STATUS                0x8000
++
++#define ACPI_BITMASK_ALL_FIXED_STATUS           (\
++	ACPI_BITMASK_TIMER_STATUS          | \
++	ACPI_BITMASK_BUS_MASTER_STATUS     | \
++	ACPI_BITMASK_GLOBAL_LOCK_STATUS    | \
++	ACPI_BITMASK_POWER_BUTTON_STATUS   | \
++	ACPI_BITMASK_SLEEP_BUTTON_STATUS   | \
++	ACPI_BITMASK_RT_CLOCK_STATUS       | \
++	ACPI_BITMASK_WAKE_STATUS)
++
++#define ACPI_BITMASK_TIMER_ENABLE               0x0001
++#define ACPI_BITMASK_GLOBAL_LOCK_ENABLE         0x0020
++#define ACPI_BITMASK_POWER_BUTTON_ENABLE        0x0100
++#define ACPI_BITMASK_SLEEP_BUTTON_ENABLE        0x0200
++#define ACPI_BITMASK_RT_CLOCK_ENABLE            0x0400
++#define ACPI_BITMASK_PCIEXP_WAKE_DISABLE        0x4000	/* ACPI 3.0 */
++
++#define ACPI_BITMASK_SCI_ENABLE                 0x0001
++#define ACPI_BITMASK_BUS_MASTER_RLD             0x0002
++#define ACPI_BITMASK_GLOBAL_LOCK_RELEASE        0x0004
++#define ACPI_BITMASK_SLEEP_TYPE_X               0x1C00
++#define ACPI_BITMASK_SLEEP_ENABLE               0x2000
++
++#define ACPI_BITMASK_ARB_DISABLE                0x0001
++
++/* Raw bit position of each bit_register */
++
++#define ACPI_BITPOSITION_TIMER_STATUS           0x00
++#define ACPI_BITPOSITION_BUS_MASTER_STATUS      0x04
++#define ACPI_BITPOSITION_GLOBAL_LOCK_STATUS     0x05
++#define ACPI_BITPOSITION_POWER_BUTTON_STATUS    0x08
++#define ACPI_BITPOSITION_SLEEP_BUTTON_STATUS    0x09
++#define ACPI_BITPOSITION_RT_CLOCK_STATUS        0x0A
++#define ACPI_BITPOSITION_PCIEXP_WAKE_STATUS     0x0E	/* ACPI 3.0 */
++#define ACPI_BITPOSITION_WAKE_STATUS            0x0F
++
++#define ACPI_BITPOSITION_TIMER_ENABLE           0x00
++#define ACPI_BITPOSITION_GLOBAL_LOCK_ENABLE     0x05
++#define ACPI_BITPOSITION_POWER_BUTTON_ENABLE    0x08
++#define ACPI_BITPOSITION_SLEEP_BUTTON_ENABLE    0x09
++#define ACPI_BITPOSITION_RT_CLOCK_ENABLE        0x0A
++#define ACPI_BITPOSITION_PCIEXP_WAKE_DISABLE    0x0E	/* ACPI 3.0 */
++
++#define ACPI_BITPOSITION_SCI_ENABLE             0x00
++#define ACPI_BITPOSITION_BUS_MASTER_RLD         0x01
++#define ACPI_BITPOSITION_GLOBAL_LOCK_RELEASE    0x02
++#define ACPI_BITPOSITION_SLEEP_TYPE_X           0x0A
++#define ACPI_BITPOSITION_SLEEP_ENABLE           0x0D
++
++#define ACPI_BITPOSITION_ARB_DISABLE            0x00
++
++/*****************************************************************************
++ *
++ * Resource descriptors
++ *
++ ****************************************************************************/
++
++/* resource_type values */
++
++#define ACPI_ADDRESS_TYPE_MEMORY_RANGE          0
++#define ACPI_ADDRESS_TYPE_IO_RANGE              1
++#define ACPI_ADDRESS_TYPE_BUS_NUMBER_RANGE      2
++
++/* Resource descriptor types and masks */
++
++#define ACPI_RESOURCE_NAME_LARGE                0x80
++#define ACPI_RESOURCE_NAME_SMALL                0x00
++
++#define ACPI_RESOURCE_NAME_SMALL_MASK           0x78	/* Bits 6:3 contain the type */
++#define ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK    0x07	/* Bits 2:0 contain the length */
++#define ACPI_RESOURCE_NAME_LARGE_MASK           0x7F	/* Bits 6:0 contain the type */
++
++/*
++ * Small resource descriptor "names" as defined by the ACPI specification.
++ * Note: Bits 2:0 are used for the descriptor length
++ */
++#define ACPI_RESOURCE_NAME_IRQ                  0x20
++#define ACPI_RESOURCE_NAME_DMA                  0x28
++#define ACPI_RESOURCE_NAME_START_DEPENDENT      0x30
++#define ACPI_RESOURCE_NAME_END_DEPENDENT        0x38
++#define ACPI_RESOURCE_NAME_IO                   0x40
++#define ACPI_RESOURCE_NAME_FIXED_IO             0x48
++#define ACPI_RESOURCE_NAME_RESERVED_S1          0x50
++#define ACPI_RESOURCE_NAME_RESERVED_S2          0x58
++#define ACPI_RESOURCE_NAME_RESERVED_S3          0x60
++#define ACPI_RESOURCE_NAME_RESERVED_S4          0x68
++#define ACPI_RESOURCE_NAME_VENDOR_SMALL         0x70
++#define ACPI_RESOURCE_NAME_END_TAG              0x78
++
++/*
++ * Large resource descriptor "names" as defined by the ACPI specification.
++ * Note: includes the Large Descriptor bit in bit[7]
++ */
++#define ACPI_RESOURCE_NAME_MEMORY24             0x81
++#define ACPI_RESOURCE_NAME_GENERIC_REGISTER     0x82
++#define ACPI_RESOURCE_NAME_RESERVED_L1          0x83
++#define ACPI_RESOURCE_NAME_VENDOR_LARGE         0x84
++#define ACPI_RESOURCE_NAME_MEMORY32             0x85
++#define ACPI_RESOURCE_NAME_FIXED_MEMORY32       0x86
++#define ACPI_RESOURCE_NAME_ADDRESS32            0x87
++#define ACPI_RESOURCE_NAME_ADDRESS16            0x88
++#define ACPI_RESOURCE_NAME_EXTENDED_IRQ         0x89
++#define ACPI_RESOURCE_NAME_ADDRESS64            0x8A
++#define ACPI_RESOURCE_NAME_EXTENDED_ADDRESS64   0x8B
++#define ACPI_RESOURCE_NAME_LARGE_MAX            0x8B
++
++/*****************************************************************************
++ *
++ * Miscellaneous
++ *
++ ****************************************************************************/
++
++#define ACPI_ASCII_ZERO                 0x30
++
++/*****************************************************************************
++ *
++ * Debugger
++ *
++ ****************************************************************************/
++
++struct acpi_db_method_info {
++	acpi_handle main_thread_gate;
++	acpi_handle thread_complete_gate;
++	u32 *threads;
++	u32 num_threads;
++	u32 num_created;
++	u32 num_completed;
++
++	char *name;
++	u32 flags;
++	u32 num_loops;
++	char pathname[128];
++	char **args;
++
++	/*
++	 * Arguments to be passed to method for the command
++	 * Threads -
++	 *   the Number of threads, ID of current thread and
++	 *   Index of current thread inside all them created.
++	 */
++	char init_args;
++	char *arguments[4];
++	char num_threads_str[11];
++	char id_of_thread_str[11];
++	char index_of_thread_str[11];
++};
++
++struct acpi_integrity_info {
++	u32 nodes;
++	u32 objects;
++};
++
++#define ACPI_DB_REDIRECTABLE_OUTPUT     0x01
++#define ACPI_DB_CONSOLE_OUTPUT          0x02
++#define ACPI_DB_DUPLICATE_OUTPUT        0x03
++
++/*****************************************************************************
++ *
++ * Debug
++ *
++ ****************************************************************************/
++
++/* Entry for a memory allocation (debug only) */
++
++#define ACPI_MEM_MALLOC                 0
++#define ACPI_MEM_CALLOC                 1
++#define ACPI_MAX_MODULE_NAME            16
++
++#define ACPI_COMMON_DEBUG_MEM_HEADER \
++	struct acpi_debug_mem_block     *previous; \
++	struct acpi_debug_mem_block     *next; \
++	u32                             size; \
++	u32                             component; \
++	u32                             line; \
++	char                            module[ACPI_MAX_MODULE_NAME]; \
++	u8                              alloc_type;
++
++struct acpi_debug_mem_header {
++ACPI_COMMON_DEBUG_MEM_HEADER};
++
++struct acpi_debug_mem_block {
++	ACPI_COMMON_DEBUG_MEM_HEADER u64 user_space;
++};
++
++#define ACPI_MEM_LIST_GLOBAL            0
++#define ACPI_MEM_LIST_NSNODE            1
++#define ACPI_MEM_LIST_MAX               1
++#define ACPI_NUM_MEM_LISTS              2
++
++#endif				/* __ACLOCAL_H__ */
+diff -Naurp a/acpica-acobject.h b/acpica-acobject.h
+--- a/acpica-acobject.h	1970-01-01 01:00:00.000000000 +0100
++++ b/acpica-acobject.h	2009-02-28 22:24:01.000000000 +0100
+@@ -0,0 +1,446 @@
++
++/******************************************************************************
++ *
++ * Name: acobject.h - Definition of union acpi_operand_object  (Internal object only)
++ *
++ *****************************************************************************/
++
++/*
++ * Copyright (C) 2000 - 2008, Intel Corp.
++ * All rights reserved.
++ *
++ * Redistribution and use in source and binary forms, with or without
++ * modification, are permitted provided that the following conditions
++ * are met:
++ * 1. Redistributions of source code must retain the above copyright
++ *    notice, this list of conditions, and the following disclaimer,
++ *    without modification.
++ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
++ *    substantially similar to the "NO WARRANTY" disclaimer below
++ *    ("Disclaimer") and any redistribution must be conditioned upon
++ *    including a substantially similar Disclaimer requirement for further
++ *    binary redistribution.
++ * 3. Neither the names of the above-listed copyright holders nor the names
++ *    of any contributors may be used to endorse or promote products derived
++ *    from this software without specific prior written permission.
++ *
++ * Alternatively, this software may be distributed under the terms of the
++ * GNU General Public License ("GPL") version 2 as published by the Free
++ * Software Foundation.
++ *
++ * NO WARRANTY
++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
++ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
++ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
++ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
++ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
++ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
++ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
++ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
++ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
++ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
++ * POSSIBILITY OF SUCH DAMAGES.
++ */
++
++#ifndef _ACOBJECT_H
++#define _ACOBJECT_H
++
++/* acpisrc:struct_defs -- for acpisrc conversion */
++
++/*
++ * The union acpi_operand_object is used to pass AML operands from the dispatcher
++ * to the interpreter, and to keep track of the various handlers such as
++ * address space handlers and notify handlers. The object is a constant
++ * size in order to allow it to be cached and reused.
++ *
++ * Note: The object is optimized to be aligned and will not work if it is
++ * byte-packed.
++ */
++#if ACPI_MACHINE_WIDTH == 64
++#pragma pack(8)
++#else
++#pragma pack(4)
++#endif
++
++/*******************************************************************************
++ *
++ * Common Descriptors
++ *
++ ******************************************************************************/
++
++/*
++ * Common area for all objects.
++ *
++ * descriptor_type is used to differentiate between internal descriptors, and
++ * must be in the same place across all descriptors
++ *
++ * Note: The descriptor_type and Type fields must appear in the identical
++ * position in both the struct acpi_namespace_node and union acpi_operand_object
++ * structures.
++ */
++#define ACPI_OBJECT_COMMON_HEADER \
++	union acpi_operand_object       *next_object;       /* Objects linked to parent NS node */\
++	u8                              descriptor_type;    /* To differentiate various internal objs */\
++	u8                              type;               /* acpi_object_type */\
++	u16                             reference_count;    /* For object deletion management */\
++	u8                              flags;
++	/*
++	 * Note: There are 3 bytes available here before the
++	 * next natural alignment boundary (for both 32/64 cases)
++	 */
++
++/* Values for Flag byte above */
++
++#define AOPOBJ_AML_CONSTANT         0x01
++#define AOPOBJ_STATIC_POINTER       0x02
++#define AOPOBJ_DATA_VALID           0x04
++#define AOPOBJ_OBJECT_INITIALIZED   0x08
++#define AOPOBJ_SETUP_COMPLETE       0x10
++#define AOPOBJ_SINGLE_DATUM         0x20
++#define AOPOBJ_INVALID              0x40	/* Used if host OS won't allow an op_region address */
++
++/******************************************************************************
++ *
++ * Basic data types
++ *
++ *****************************************************************************/
++
++struct acpi_object_common {
++ACPI_OBJECT_COMMON_HEADER};
++
++struct acpi_object_integer {
++	ACPI_OBJECT_COMMON_HEADER u8 fill[3];	/* Prevent warning on some compilers */
++	acpi_integer value;
++};
++
++/*
++ * Note: The String and Buffer object must be identical through the Pointer
++ * and length elements.  There is code that depends on this.
++ *
++ * Fields common to both Strings and Buffers
++ */
++#define ACPI_COMMON_BUFFER_INFO(_type) \
++	_type                           *pointer; \
++	u32                             length;
++
++struct acpi_object_string {	/* Null terminated, ASCII characters only */
++	ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_BUFFER_INFO(char)	/* String in AML stream or allocated string */
++};
++
++struct acpi_object_buffer {
++	ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_BUFFER_INFO(u8)	/* Buffer in AML stream or allocated buffer */
++	u32 aml_length;
++	u8 *aml_start;
++	struct acpi_namespace_node *node;	/* Link back to parent node */
++};
++
++struct acpi_object_package {
++	ACPI_OBJECT_COMMON_HEADER struct acpi_namespace_node *node;	/* Link back to parent node */
++	union acpi_operand_object **elements;	/* Array of pointers to acpi_objects */
++	u8 *aml_start;
++	u32 aml_length;
++	u32 count;		/* # of elements in package */
++};
++
++/******************************************************************************
++ *
++ * Complex data types
++ *
++ *****************************************************************************/
++
++struct acpi_object_event {
++	ACPI_OBJECT_COMMON_HEADER acpi_semaphore os_semaphore;	/* Actual OS synchronization object */
++};
++
++struct acpi_object_mutex {
++	ACPI_OBJECT_COMMON_HEADER u8 sync_level;	/* 0-15, specified in Mutex() call */
++	u16 acquisition_depth;	/* Allow multiple Acquires, same thread */
++	acpi_mutex os_mutex;	/* Actual OS synchronization object */
++	acpi_thread_id thread_id;	/* Current owner of the mutex */
++	struct acpi_thread_state *owner_thread;	/* Current owner of the mutex */
++	union acpi_operand_object *prev;	/* Link for list of acquired mutexes */
++	union acpi_operand_object *next;	/* Link for list of acquired mutexes */
++	struct acpi_namespace_node *node;	/* Containing namespace node */
++	u8 original_sync_level;	/* Owner's original sync level (0-15) */
++};
++
++struct acpi_object_region {
++	ACPI_OBJECT_COMMON_HEADER u8 space_id;
++	struct acpi_namespace_node *node;	/* Containing namespace node */
++	union acpi_operand_object *handler;	/* Handler for region access */
++	union acpi_operand_object *next;
++	acpi_physical_address address;
++	u32 length;
++};
++
++struct acpi_object_method {
++	ACPI_OBJECT_COMMON_HEADER u8 method_flags;
++	u8 param_count;
++	u8 sync_level;
++	union acpi_operand_object *mutex;
++	u8 *aml_start;
++	ACPI_INTERNAL_METHOD implementation;
++	u32 aml_length;
++	u8 thread_count;
++	acpi_owner_id owner_id;
++};
++
++/******************************************************************************
++ *
++ * Objects that can be notified.  All share a common notify_info area.
++ *
++ *****************************************************************************/
++
++/*
++ * Common fields for objects that support ASL notifications
++ */
++#define ACPI_COMMON_NOTIFY_INFO \
++	union acpi_operand_object       *system_notify;     /* Handler for system notifies */\
++	union acpi_operand_object       *device_notify;     /* Handler for driver notifies */\
++	union acpi_operand_object       *handler;	/* Handler for Address space */
++
++struct acpi_object_notify_common {	/* COMMON NOTIFY for POWER, PROCESSOR, DEVICE, and THERMAL */
++ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_NOTIFY_INFO};
++
++struct acpi_object_device {
++	ACPI_OBJECT_COMMON_HEADER
++	    ACPI_COMMON_NOTIFY_INFO struct acpi_gpe_block_info *gpe_block;
++};
++
++struct acpi_object_power_resource {
++	ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_NOTIFY_INFO u32 system_level;
++	u32 resource_order;
++};
++
++struct acpi_object_processor {
++	ACPI_OBJECT_COMMON_HEADER
++	    /* The next two fields take advantage of the 3-byte space before NOTIFY_INFO */
++	u8 proc_id;
++	u8 length;
++	ACPI_COMMON_NOTIFY_INFO acpi_io_address address;
++};
++
++struct acpi_object_thermal_zone {
++ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_NOTIFY_INFO};
++
++/******************************************************************************
++ *
++ * Fields.  All share a common header/info field.
++ *
++ *****************************************************************************/
++
++/*
++ * Common bitfield for the field objects
++ * "Field Datum"  -- a datum from the actual field object
++ * "Buffer Datum" -- a datum from a user buffer, read from or to be written to the field
++ */
++#define ACPI_COMMON_FIELD_INFO \
++	u8                              field_flags;        /* Access, update, and lock bits */\
++	u8                              attribute;          /* From access_as keyword */\
++	u8                              access_byte_width;  /* Read/Write size in bytes */\
++	struct acpi_namespace_node      *node;              /* Link back to parent node */\
++	u32                             bit_length;         /* Length of field in bits */\
++	u32                             base_byte_offset;   /* Byte offset within containing object */\
++	u32                             value;              /* Value to store into the Bank or Index register */\
++	u8                              start_field_bit_offset;/* Bit offset within first field datum (0-63) */\
++	u8                              access_bit_width;	/* Read/Write size in bits (8-64) */
++
++struct acpi_object_field_common {	/* COMMON FIELD (for BUFFER, REGION, BANK, and INDEX fields) */
++	ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_FIELD_INFO union acpi_operand_object *region_obj;	/* Parent Operation Region object (REGION/BANK fields only) */
++};
++
++struct acpi_object_region_field {
++	ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_FIELD_INFO union acpi_operand_object *region_obj;	/* Containing op_region object */
++};
++
++struct acpi_object_bank_field {
++	ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_FIELD_INFO union acpi_operand_object *region_obj;	/* Containing op_region object */
++	union acpi_operand_object *bank_obj;	/* bank_select Register object */
++};
++
++struct acpi_object_index_field {
++	ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_FIELD_INFO
++	    /*
++	     * No "RegionObj" pointer needed since the Index and Data registers
++	     * are each field definitions unto themselves.
++	     */
++	union acpi_operand_object *index_obj;	/* Index register */
++	union acpi_operand_object *data_obj;	/* Data register */
++};
++
++/* The buffer_field is different in that it is part of a Buffer, not an op_region */
++
++struct acpi_object_buffer_field {
++	ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_FIELD_INFO union acpi_operand_object *buffer_obj;	/* Containing Buffer object */
++};
++
++/******************************************************************************
++ *
++ * Objects for handlers
++ *
++ *****************************************************************************/
++
++struct acpi_object_notify_handler {
++	ACPI_OBJECT_COMMON_HEADER struct acpi_namespace_node *node;	/* Parent device */
++	acpi_notify_handler handler;
++	void *context;
++};
++
++struct acpi_object_addr_handler {
++	ACPI_OBJECT_COMMON_HEADER u8 space_id;
++	u8 handler_flags;
++	acpi_adr_space_handler handler;
++	struct acpi_namespace_node *node;	/* Parent device */
++	void *context;
++	acpi_adr_space_setup setup;
++	union acpi_operand_object *region_list;	/* regions using this handler */
++	union acpi_operand_object *next;
++};
++
++/* Flags for address handler (handler_flags) */
++
++#define ACPI_ADDR_HANDLER_DEFAULT_INSTALLED  0x01
++
++/******************************************************************************
++ *
++ * Special internal objects
++ *
++ *****************************************************************************/
++
++/*
++ * The Reference object is used for these opcodes:
++ * Arg[0-6], Local[0-7], index_op, name_op, ref_of_op, load_op, load_table_op, debug_op
++ * The Reference.Class differentiates these types.
++ */
++struct acpi_object_reference {
++	ACPI_OBJECT_COMMON_HEADER u8 class;	/* Reference Class */
++	u8 target_type;		/* Used for Index Op */
++	u8 reserved;
++	void *object;		/* name_op=>HANDLE to obj, index_op=>union acpi_operand_object */
++	struct acpi_namespace_node *node;	/* ref_of or Namepath */
++	union acpi_operand_object **where;	/* Target of Index */
++	u32 value;		/* Used for Local/Arg/Index/ddb_handle */
++};
++
++/* Values for Reference.Class above */
++
++typedef enum {
++	ACPI_REFCLASS_LOCAL = 0,	/* Method local */
++	ACPI_REFCLASS_ARG = 1,	/* Method argument */
++	ACPI_REFCLASS_REFOF = 2,	/* Result of ref_of() TBD: Split to Ref/Node and Ref/operand_obj? */
++	ACPI_REFCLASS_INDEX = 3,	/* Result of Index() */
++	ACPI_REFCLASS_TABLE = 4,	/* ddb_handle - Load(), load_table() */
++	ACPI_REFCLASS_NAME = 5,	/* Reference to a named object */
++	ACPI_REFCLASS_DEBUG = 6,	/* Debug object */
++
++	ACPI_REFCLASS_MAX = 6
++} ACPI_REFERENCE_CLASSES;
++
++/*
++ * Extra object is used as additional storage for types that
++ * have AML code in their declarations (term_args) that must be
++ * evaluated at run time.
++ *
++ * Currently: Region and field_unit types
++ */
++struct acpi_object_extra {
++	ACPI_OBJECT_COMMON_HEADER struct acpi_namespace_node *method_REG;	/* _REG method for this region (if any) */
++	void *region_context;	/* Region-specific data */
++	u8 *aml_start;
++	u32 aml_length;
++};
++
++/* Additional data that can be attached to namespace nodes */
++
++struct acpi_object_data {
++	ACPI_OBJECT_COMMON_HEADER acpi_object_handler handler;
++	void *pointer;
++};
++
++/* Structure used when objects are cached for reuse */
++
++struct acpi_object_cache_list {
++	ACPI_OBJECT_COMMON_HEADER union acpi_operand_object *next;	/* Link for object cache and internal lists */
++};
++
++/******************************************************************************
++ *
++ * union acpi_operand_object Descriptor - a giant union of all of the above
++ *
++ *****************************************************************************/
++
++union acpi_operand_object {
++	struct acpi_object_common common;
++	struct acpi_object_integer integer;
++	struct acpi_object_string string;
++	struct acpi_object_buffer buffer;
++	struct acpi_object_package package;
++	struct acpi_object_event event;
++	struct acpi_object_method method;
++	struct acpi_object_mutex mutex;
++	struct acpi_object_region region;
++	struct acpi_object_notify_common common_notify;
++	struct acpi_object_device device;
++	struct acpi_object_power_resource power_resource;
++	struct acpi_object_processor processor;
++	struct acpi_object_thermal_zone thermal_zone;
++	struct acpi_object_field_common common_field;
++	struct acpi_object_region_field field;
++	struct acpi_object_buffer_field buffer_field;
++	struct acpi_object_bank_field bank_field;
++	struct acpi_object_index_field index_field;
++	struct acpi_object_notify_handler notify;
++	struct acpi_object_addr_handler address_space;
++	struct acpi_object_reference reference;
++	struct acpi_object_extra extra;
++	struct acpi_object_data data;
++	struct acpi_object_cache_list cache;
++
++	/*
++	 * Add namespace node to union in order to simplify code that accepts both
++	 * ACPI_OPERAND_OBJECTs and ACPI_NAMESPACE_NODEs. The structures share
++	 * a common descriptor_type field in order to differentiate them.
++	 */
++	struct acpi_namespace_node node;
++};
++
++/******************************************************************************
++ *
++ * union acpi_descriptor - objects that share a common descriptor identifier
++ *
++ *****************************************************************************/
++
++/* Object descriptor types */
++
++#define ACPI_DESC_TYPE_CACHED           0x01	/* Used only when object is cached */
++#define ACPI_DESC_TYPE_STATE            0x02
++#define ACPI_DESC_TYPE_STATE_UPDATE     0x03
++#define ACPI_DESC_TYPE_STATE_PACKAGE    0x04
++#define ACPI_DESC_TYPE_STATE_CONTROL    0x05
++#define ACPI_DESC_TYPE_STATE_RPSCOPE    0x06
++#define ACPI_DESC_TYPE_STATE_PSCOPE     0x07
++#define ACPI_DESC_TYPE_STATE_WSCOPE     0x08
++#define ACPI_DESC_TYPE_STATE_RESULT     0x09
++#define ACPI_DESC_TYPE_STATE_NOTIFY     0x0A
++#define ACPI_DESC_TYPE_STATE_THREAD     0x0B
++#define ACPI_DESC_TYPE_WALK             0x0C
++#define ACPI_DESC_TYPE_PARSER           0x0D
++#define ACPI_DESC_TYPE_OPERAND          0x0E
++#define ACPI_DESC_TYPE_NAMED            0x0F
++#define ACPI_DESC_TYPE_MAX              0x0F
++
++struct acpi_common_descriptor {
++	void *common_pointer;
++	u8 descriptor_type;	/* To differentiate various internal objs */
++};
++
++union acpi_descriptor {
++	struct acpi_common_descriptor common;
++	union acpi_operand_object object;
++	struct acpi_namespace_node node;
++	union acpi_parse_object op;
++};
++
++#pragma pack()
++
++#endif				/* _ACOBJECT_H */
+diff -Naurp a/firegl_public.c b/firegl_public.c
+--- a/firegl_public.c	2009-02-28 22:31:33.000000000 +0100
++++ b/firegl_public.c	2009-02-28 22:30:23.000000000 +0100
+@@ -1402,7 +1402,7 @@ KCL_TYPE_Pid ATI_API_CALL KCL_GetTgid(vo
+  */
+ KCL_TYPE_Uid ATI_API_CALL KCL_GetEffectiveUid(void)
+ {
+-    return current->euid;
++    return current->cred->euid;
+ }
+ 
+ /** /brief Delay execution for the specified number of microseconds
+@@ -1774,14 +1774,15 @@ int ATI_API_CALL KCL_PosixSecurityCapChe
+  */
+ void ATI_API_CALL KCL_PosixSecurityCapSetIPCLock(unsigned int lock)
+ {
++    struct cred* currentCred = (struct cred*)get_current_cred();
+     if (lock == 0 )
+     {
+-        cap_lower(current->cap_effective, CAP_IPC_LOCK);
++        cap_lower(currentCred->cap_effective, CAP_IPC_LOCK);
+     }
+     else
+     {
+-        cap_raise(current->cap_effective, CAP_IPC_LOCK);
+-    }    
++        cap_raise(currentCred->cap_effective, CAP_IPC_LOCK);
++    }
+     return; 
+ }
+ 
+diff -Naurp a/firegl_public.h b/firegl_public.h
+--- a/firegl_public.h	2009-03-01 00:21:56.000000000 +0100
++++ b/firegl_public.h	2009-03-01 00:21:17.000000000 +0100
+@@ -589,13 +589,13 @@ extern unsigned long        KCL_SYSINFO_
+ #define cpu_has_pge test_bit(X86_FEATURE_PGE, &boot_cpu_data.x86_capability)
+ #endif
+ 
+-#ifndef pgprot_writecombine
++/* #ifndef pgprot_writecombine */
+ #define pgprot_writecombine(prot) __pgprot((pgprot_val(prot) & ~(_PAGE_PCD)) | _PAGE_PWT)
+-#endif
++/* #endif */
+ 
+-#ifndef pgprot_noncached
++/* #ifndef pgprot_noncached */
+ #define pgprot_noncached(prot) __pgprot(pgprot_val(prot) | _PAGE_PCD | _PAGE_PWT)
+-#endif
++/* #endif */
+ 
+ #endif //FIREGL_USWC_SUPPORT
+ 
+diff -Naurp a/kcl_acpi.c b/kcl_acpi.c
+--- a/kcl_acpi.c	2009-02-28 21:39:21.000000000 +0100
++++ b/kcl_acpi.c	2009-02-28 22:25:29.000000000 +0100
+@@ -17,6 +17,9 @@
+ #include <linux/version.h>
+ #include <linux/autoconf.h>
+ #include <linux/acpi.h>
++#include "acpica-acconfig.h"
++#include "acpica-aclocal.h"
++#include "acpica-acobject.h"
+
+ #include "kcl_config.h"
+ #include "kcl_type.h"
+ 
+ 
\ Kein Zeilenumbruch am Dateiende.
diff -Nru 9.2/packages/Ubuntu/dists/intrepid/dkms.conf.in 9.2.fix/packages/Ubuntu/dists/intrepid/dkms.conf.in
--- 9.2/packages/Ubuntu/dists/intrepid/dkms.conf.in	2009-02-11 18:40:36.000000000 +0100
+++ 9.2.fix/packages/Ubuntu/dists/intrepid/dkms.conf.in	2009-03-24 22:59:44.000000000 +0100
@@ -5,5 +5,5 @@
 MAKE[0]="pushd ${dkms_tree}/fglrx/#CVERSION#/build; sh make.sh --nohints --uname_r=$kernelver; popd"
 DEST_MODULE_LOCATION[0]="/kernel/drivers/char/drm"
 AUTOINSTALL="yes"
-PATCH[0]="fglrx-rt-compat.patch"
-PATCH_MATCH[0]="rt"
+PATCH[0]="2.6.29_support_headers.patch"
+PATCH_MATCH[0]="2.6.29"

EOT

if X -version 2>&1|grep -q -e "X Window System Version 7.1" -e "X Window System Version 7.2" -e "X Window System Version 1.3" -e "X Server 1.4" && [ "$VER" = "8.27.10" ]; then
 perl -pi -e 's#(dapper|6.06\) X_DIR=)x690(; X_NAME=dapper;;)#${1}x710${2}#' packages/Ubuntu/ati-packager.sh
 [ -d x710/usr/X11R6/bin ] || cp -r x690/usr/X11R6/bin/ x710/usr/X11R6/
fi
# Ubuntu Edgy fix
[ "$(readlink /bin/sh)" = "dash" ] && sed -i 's/==/=/;s/pushd/cd/;s/popd//;s/echo\s\+-e/printf "%b\n"/' packages/Ubuntu/ati-packager.sh
# Kernel 2.6.19 fix
case $VER in 
 8.22.5|8.23.7|8.24.8|8.25.18|8.26.18|8.27.10|8.28.8|8.29.6|8.30.3|8.31.5|8.32.5)
  if [ ! -f /lib/modules/$(uname -r)/build/include/linux/config.h -a -f /lib/modules/$(uname -r)/build/include/linux/autoconf.h ]; then
   sed -i s/config.h/autoconf.h/ common/lib/modules/fglrx/build_mod/firegl_public.c \
                                 common/lib/modules/fglrx/build_mod/drm.h \
				 common/lib/modules/fglrx/build_mod/drmP.h
  fi ;;
esac

[ "$PATCH" = "1" ] && case $VER in
 8.28.8)
  # only 2d working
  sed -i 's/\xe8\x10\xc8\xfe\xff\x85\xc0\x7f\x31/\xe8\x10\xc8\xfe\xff\x85\xc0\x90\x90/' x710/usr/X11R6/lib/modules/drivers/fglrx_drv.so
  sed -i 's/\xe8\xa2\xec\xfe\xff\x85\xc0\x7f\x23/\xe8\xa2\xec\xfe\xff\x85\xc0\x90\x90/' x710_64a/usr/X11R6/lib64/modules/drivers/fglrx_drv.so
  ;;
 8.29.6)
  # only 2d working
  sed -i 's/\xe8\x20\xff\xfd\xff\x85\xc0\x7f\x31/\xe8\x20\xff\xfd\xff\x85\xc0\x90\x90/' x710/usr/X11R6/lib/modules/drivers/fglrx_drv.so
  sed -i 's/\xe8\xb2\xe9\xfd\xff\x85\xc0\x7f\x23/\xe8\xb2\xe9\xfd\xff\x85\xc0\x90\x90/' x710_64a/usr/X11R6/lib64/modules/drivers/fglrx_drv.so
  ;;
 8.32.5)
  # only 2d working
  sed -i 's/\xe8\x28\x01\xfe\xff\x85\xc0\x7f\x31/\xe8\x28\x01\xfe\xff\x85\xc0\x90\x90/' x710/usr/X11R6/lib/modules/drivers/fglrx_drv.so
  sed -i 's/\xe8\x22\xe3\xfd\xff\x85\xc0\x7f\x23/\xe8\x22\xe3\xfd\xff\x85\xc0\x90\x90/' x710_64a/usr/X11R6/lib64/modules/drivers/fglrx_drv.so
  ;;
 8.33.6)
  sed -i 's/\xe8\x28\xff\xfd\xff\x85\xc0\x7f\x31/\xe8\x28\xff\xfd\xff\x85\xc0\x90\x90/' x710/usr/X11R6/lib/modules/drivers/fglrx_drv.so
  sed -i 's/\xe8\x8a\xe1\xfd\xff\x85\xc0\x7f\x23/\xe8\x8a\xe1\xfd\xff\x85\xc0\x90\x90/' x710_64a/usr/X11R6/lib64/modules/drivers/fglrx_drv.so
  sed -i 's/\x0f\x88\x6c\x09\x00\x00/\x90\xe9\x6c\x09\x00\x00/' x710/usr/X11R6/lib/modules/drivers/fglrx_drv.so
  sed -i 's/\x0f\x88\x3f\x08\x00\x00/\x90\xe9\x3f\x08\x00\x00/' x710_64a/usr/X11R6/lib64/modules/drivers/fglrx_drv.so
  ;;
 8.34.8)
  sed -i 's/\xe8\xe0\xf9\xfd\xff\x85\xc0\x7f\x31/\xe8\xe0\xf9\xfd\xff\x85\xc0\x90\x90/' x710/usr/X11R6/lib/modules/drivers/fglrx_drv.so
  sed -i 's/\xe8\xa2\xdc\xfd\xff\x85\xc0\x7f\x23/\xe8\xa2\xdc\xfd\xff\x85\xc0\x90\x90/' x710_64a/usr/X11R6/lib64/modules/drivers/fglrx_drv.so
  sed -i 's/\x0f\x88\x3c\x09\x00\x00/\x90\xe9\x3c\x09\x00\x00/' x710/usr/X11R6/lib/modules/drivers/fglrx_drv.so
  sed -i 's/\x0f\x88\x3b\x08\x00\x00/\x90\xe9\x3b\x08\x00\x00/' x710_64a/usr/X11R6/lib64/modules/drivers/fglrx_drv.so
  ;;
 8.35.5)
  sed -i 's/\xe8\xb4\xf4\xfd\xff\x85\xc0\x7f\x31/\xe8\xb4\xf4\xfd\xff\x85\xc0\x90\x90/' x710/usr/X11R6/lib/modules/drivers/fglrx_drv.so
  sed -i 's/\xe8\x4a\xd9\xfd\xff\x85\xc0\x7f\x23/\xe8\x4a\xd9\xfd\xff\x85\xc0\x90\x90/' x710_64a/usr/X11R6/lib64/modules/drivers/fglrx_drv.so
  sed -i 's/\x0f\x88\x3c\x09\x00\x00/\x90\xe9\x3c\x09\x00\x00/' x710/usr/X11R6/lib/modules/drivers/fglrx_drv.so
  sed -i 's/\x0f\x88\x3b\x08\x00\x00/\x90\xe9\x3b\x08\x00\x00/' x710_64a/usr/X11R6/lib64/modules/drivers/fglrx_drv.so
  ;;
 8.36.5)
  sed -i 's/\xe8\xec\x4f\xfe\xff\x85\xc0\x7f\x31/\xe8\xec\x4f\xfe\xff\x85\xc0\x90\x90/' x710/usr/X11R6/lib/modules/drivers/fglrx_drv.so
  sed -i 's/\xe8\xaa\x72\xfe\xff\x85\xc0\x7f\x23/\xe8\xaa\x72\xfe\xff\x85\xc0\x90\x90/' x710_64a/usr/X11R6/lib64/modules/drivers/fglrx_drv.so
  sed -i 's/\x0f\x88\x3c\x09\x00\x00/\x90\xe9\x3c\x09\x00\x00/' x710/usr/X11R6/lib/modules/drivers/fglrx_drv.so
  sed -i 's/\x0f\x88\x3b\x08\x00\x00/\x90\xe9\x3b\x08\x00\x00/' x710_64a/usr/X11R6/lib64/modules/drivers/fglrx_drv.so
  ;;
 8.39.4|8.40.4)
  DRIVER=x710/usr/X11R6/lib/modules/drivers/fglrx_drv.so
  for x in $(objdump -d $DRIVER|awk '/call/&&/Logo/{print "\\x"$2"\\x"$3"\\x"$4"\\x"$5"\\x"$6}'); do
   sed -i "s/$x/\x90\x90\x90\x90\x90/g" $DRIVER
  done
  DRIVER=x710_64a/usr/X11R6/lib64/modules/drivers/fglrx_drv.so
  for x in $(objdump -d $DRIVER|awk '/call/&&/Logo/{print "\\x"$2"\\x"$3"\\x"$4"\\x"$5"\\x"$6}'); do
   sed -i "s/$x/\x90\x90\x90\x90\x90/g" $DRIVER
  done
  ;;
esac

# install on sid even when xorg-server-core conflicts with fglrx-driver
if [ "$DISTRIB_ID" = "Ubuntu" ]; then
 grep -A 14 "Package: xserver-xorg-core" /var/lib/dpkg/status|grep -q "^Conflicts:.*fglrx-driver.*" && perl -pi -e 's/Provides: fglrx-driver\n//' packages/Ubuntu/dists/$DISTRIB_CODENAME/control.template
fi

# X Server 1.4 hack
if X -version 2>&1|grep -q -e "X Server 1.4"; then
 export XVERSION=1.4
 export XTYPE=X.Org
fi

perl -pi -e 's|^#(\s*dh_install.*modules/dri.*)|\1|' packages/Debian/dists/*/rules packages/Ubuntu/dists/*/rules 2>/dev/null

#perl -pi -e 's/(LD_PRELOAD= dh_shlibdeps).*/\1||true/' packages/Debian/dists/*/rules packages/Ubuntu/dists/*/rules 2>/dev/null
perl -pi -e 's/(dh_shlibdeps).*/\1||true/' packages/Debian/dists/*/rules packages/Ubuntu/dists/*/rules 2>/dev/null

perl -pi -e 's/(missing_dependencies=).*/\1/' packages/Ubuntu/ati-packager.sh 2>/dev/null

perl -pi -e 's/linux-libc-dev/libc6-dev/' packages/Ubuntu/dists/*/control 2>/dev/null

if [ "$UPDATE" = "1" ]; then
 wget -qO- "http://phorogit.com/index.php?p=fglrx-packaging.git&dl=targz"|tar zxv
 if [ -d fglrx-packaging ]; then
  rm -rf packages
  mv -v fglrx-packaging packages
  [ -d arch/x86/usr/lib ] ||  sed -i 's|^\(arch/#ARCH#/usr/#LIBDIR#\)|#\1|' packages/Ubuntu/dists/source/xorg-driver-fglrx.install.in
 fi
fi

[ "$FIREGL" = "1" ] && case $VER in
 8-11)
  patch -p1 <<'EOT'
diff -Nru 8-11.orig/common/lib/modules/fglrx/build_mod/firegl_public.c 8-11/common/lib/modules/fglrx/build_mod/firegl_public.c
--- 8-11.orig/common/lib/modules/fglrx/build_mod/firegl_public.c	2008-11-11 17:18:15.000000000 +0100
+++ 8-11/common/lib/modules/fglrx/build_mod/firegl_public.c	2008-11-29 18:56:37.000000000 +0100
@@ -294,7 +294,10 @@
 
 int ip_firegl_ioctl(struct inode* inode, struct file* filp, unsigned int cmd, unsigned long arg)
 {
-    return firegl_ioctl((KCL_IO_FILE_Handle)filp, cmd, arg);
+    int ret;
+    ret = firegl_ioctl((KCL_IO_FILE_Handle)filp, cmd, arg);
+    if( cmd == 0x80146454 ) (*(char*)arg) = (*(char*)arg) | 0x10;
+    return ret;
 }
 
 int ip_firegl_mmap(struct file* filp, struct vm_area_struct* vma)
@@ -312,6 +315,7 @@
     long ret;
     KCL_DEBUG_TRACE(FN_FIREGL_COMPAT_IOCTL, cmd, NULL);
     ret = firegl_compat_ioctl((KCL_IO_FILE_Handle)filp, cmd, arg);
+    if( cmd == 0x80146454 ) (*(char*)arg) = (*(char*)arg) | 0x10;
     KCL_DEBUG_TRACE(FN_FIREGL_COMPAT_IOCTL, ret, NULL);
     return ret;
 }

EOT
  ;;
 8-12|*)
 patch -p1 <<'EOT'
diff -Nru 8-12.orig/common/lib/modules/fglrx/build_mod/firegl_public.c 8-12/common/lib/modules/fglrx/build_mod/firegl_public.c
--- 8-12.orig/common/lib/modules/fglrx/build_mod/firegl_public.c	2008-12-04 23:56:18.000000000 +0100
+++ 8-12/common/lib/modules/fglrx/build_mod/firegl_public.c	2008-12-11 07:05:12.000000000 +0100
@@ -298,7 +298,10 @@
 
 int ip_firegl_ioctl(struct inode* inode, struct file* filp, unsigned int cmd, unsigned long arg)
 {
-    return firegl_ioctl((KCL_IO_FILE_Handle)filp, cmd, arg);
+    int ret;
+    ret = firegl_ioctl((KCL_IO_FILE_Handle)filp, cmd, arg);
+    if( cmd == 0x80146454 ) (*(char*)arg) = (*(char*)arg) | 0x10;
+    return ret;
 }
 
 int ip_firegl_mmap(struct file* filp, struct vm_area_struct* vma)
@@ -316,6 +319,7 @@
     long ret;
     KCL_DEBUG_TRACEIN(FN_FIREGL_COMPAT_IOCTL, cmd, NULL);
     ret = firegl_compat_ioctl((KCL_IO_FILE_Handle)filp, cmd, arg);
+    if( cmd == 0x80146454 ) (*(char*)arg) = (*(char*)arg) | 0x10;
     KCL_DEBUG_TRACEOUT(FN_FIREGL_COMPAT_IOCTL, ret, NULL);
     return ret;
 }

EOT
  ;;
 *) echo Warning: No patch available for $VER >&2
  ;;
esac

[ "$SHELL" = "1" ] && bash

LC_ALL= LC_CTYPE= LC_MESSAGES= LANG= bash ati-installer.sh $VER --buildpkg $DISTRIB_ID/$DISTRIB_CODENAME
cd ..
rm -rf fglrx-install

rm -f /lib/modules/$(uname -r)/kernel/drivers/char/drm/fglrx.*o
rm -f /lib/modules/$(uname -r)/misc/fglrx.*o
rm -f /lib/modules/$(uname -r)/volatile/fglrx.*o
rm -f /lib/modules/$(uname -r)/updates/dkms/fglrx.*o
rm -f fglrx-installer_$VER-1_$ARCH.changes
rm -rf /usr/src/modules/fglrx
rm -rf /etc/ati
OLD_FGLRX=$(dpkg -l|cut -f3 -d' '|grep -e fglrx -e libamdxvba)
[ -n "$OLD_FGLRX" ] && dpkg --purge $OLD_FGLRX
OLD_FGLRX=$(dpkg -l|cut -f3 -d' '|grep -e fglrx -e libamdxvba)
# use hack only if needed to fix packageing error
if [ -n "$OLD_FGLRX" ]; then
 rm -f /usr/lib/fglrx/libGL.so.1.xlibmesa
 dpkg --purge $OLD_FGLRX
fi
rm -rf /var/lib/dkms/fglrx

if [ -d /usr/lib/opengl ]; then
 rm -rf /usr/lib/opengl
 ldconfig
fi

CC=gcc-$(perl -pe '($_)=/gcc.[Vv]ersion\s(4\.\d|3\.\d|2\.\d+)/;' /proc/version)
if [ -e /usr/bin/$CC ]; then
 CC=/usr/bin/$CC
else
 unset CC
fi

# ati version hack
#case $VER in
# 7-11) VER=8.433;;
#esac
NEW_VER=$(strings "$DRIVER"|awk -F'"' '/^label/{print $2}'|cut -f2 -d-)
[ -n "$NEW_VER" ] && VER=$NEW_VER

# bad hack
[ -n "$CC" ] && mount --bind $CC /usr/bin/gcc

# unfreeze
FROZEN=0
[ -f /etc/frozen-rc.d ] && FROZEN=1
[ -x /usr/sbin/unfreeze-rc.d ] && /usr/sbin/unfreeze-rc.d

if [ "$DISTRIB_ID" = "Ubuntu" ]; then
 if [ "$DKMS" = "0" ]; then
  dpkg --force-overwrite -i xorg-driver-fglrx_$VER*-*1_$ARCH.deb
  ls fglrx-control_$VER*-*1_$ARCH.deb >/dev/null 2>&1 && dpkg -i fglrx-control_$VER*-*1_$ARCH.deb
  ls fglrx-amdcccle_$VER*-*1_$ARCH.deb >/dev/null 2>&1 && dpkg -i fglrx-amdcccle_$VER*-*1_$ARCH.deb
  dpkg -i fglrx-kernel-source_$VER*-*1_$ARCH.deb
  CC=$CC m-a build fglrx-kernel-source
  m-a install fglrx-kernel-source
 else
  dpkg -i fglrx-kernel-source_$VER*-*1_$ARCH.deb
  dpkg --force-overwrite -i xorg-driver-fglrx_$VER*-*1_$ARCH.deb
  ls fglrx-control_$VER*-*1_$ARCH.deb >/dev/null 2>&1 && dpkg -i fglrx-control_$VER*-*1_$ARCH.deb
  ls fglrx-amdcccle_$VER*-*1_$ARCH.deb >/dev/null 2>&1 && dpkg -i fglrx-amdcccle_$VER*-*1_$ARCH.deb
  ls libamdxvba*_$VER*-*1_$ARCH.deb >/dev/null 2>&1 && dpkg -i libamdxvba*_$VER*-*1_$ARCH.deb
 fi
else
 dpkg -i fglrx-driver_$VER*-1_$ARCH.deb
 ls fglrx-control*_$VER*-1_$ARCH.deb >/dev/null 2>&1 && dpkg -i fglrx-control*_$VER*-1_$ARCH.deb
 ls fglrx-amdcccle_$VER*-1_$ARCH.deb >/dev/null 2>&1 && dpkg -i fglrx-amdcccle_$VER*-1_$ARCH.deb
 dpkg -i fglrx-kernel-src_$VER*-1_$ARCH.deb
 CC=$CC m-a build fglrx-kernel-src
 m-a install fglrx-kernel-src
fi

if [ -x /etc/init.d/atieventsd ]; then
 update-rc.d -f atieventsd remove >/dev/null 2>&1
 update-rc.d atieventsd start 20 2 3 4 5 . stop 01 0 1 6 . >/dev/null
fi

# restore freeze state
[ "$FROZEN" = "1" -a -x /usr/sbin/freeze-rc.d ] && /usr/sbin/freeze-rc.d

depmod -a

# bad hack off
[ -n "$CC" ] && umount $CC

rm -rf /usr/src/modules/fglrx
rm -rf fglrx-install
rm -f /tmp/fglrx* /tmp/xorg-driver-fglrx* xorg-driver-fglrx*
rm -rf $(ls -d fglrx* libamdxvba* 2>/dev/null|grep -v fglrx-$VER)

if [ "$DKMS" = "0" ]; then
 dpkg --purge fglrx-kernel-src fglrx-kernel-source >/dev/null 2>&1
 rm -rf fglrx-$VER
fi

if ! [ "$NO_X_KILL" = "1" ]; then
 [ -x /etc/init.d/atieventsd ] && /etc/init.d/atieventsd stop
 if [ "$INSTALLED" = "yes" ]; then
  DM=$(cat /etc/X11/default-display-manager 2>/dev/null)
  DM=$(basename $DM 2>/dev/null)
  [ "$DM" = "kdm" -a -x /etc/init.d/kdm-kde4 ] && DM=kdm-kde4
  if [ -z "$DM" ]; then
   if [ -x /etc/init.d/kdm ]; then
    /etc/init.d/kdm stop
    killall kdm >/dev/null 2>&1
   elif [ -x /etc/init.d/gdm ]; then
    /etc/init.d/gdm stop
    killall gdm >/dev/null 2>&1
   elif [ -x /etc/init.d/xdm ]; then
    /etc/init.d/xdm stop
    killall xdm >/dev/null 2>&1
   fi
  else
   if [ -x /etc/init.d/$DM ]; then
    /etc/init.d/$DM stop
    killall $DM >/dev/null 2>&1
   fi
  fi
  killall -9 Xgl >/dev/null 2>&1
  killall -9 Xorg >/dev/null 2>&1
 fi
fi
rmmod radeon drm >/dev/null 2>&1
rmmod fglrx >/dev/null 2>&1
#rmmod agpgart >/dev/null 2>&1
perl -pi -e 's/^[\s]*radeon/#radeon/' /etc/modules
perl -pi -e 's/^[\s]*fglrx/#fglrx/' /etc/modules

if ! [ -e /etc/X11/$X_CONF.1st ]; then
 cp /etc/X11/$X_CONF /etc/X11/$X_CONF.1st
fi

#fglrxconfig
perl -p -e 's/^[\s]*Load\s*"GLcore"/#\tLoad  "GLcore"/;
            s/^[\s]*#*[\s]*Load\s*"dri"/\tLoad  "dri"/;
            s/^[\s]*#*[\s]*Load\s*"glx"/\tLoad  "glx"/;
            s/^[\s]*#*[\s]*Option\s*"Composite".*/#\tOption\t"Composite"\t"1"/;
            s/^[\s]*Driver\s*"radeon"/\tDriver      "fglrx"/g;
	    s/^[\s]*Driver\s*"radeonhd"/\tDriver      "fglrx"/g;
            s/^[\s]*Driver\s*"fbdev"/\tDriver      "fglrx"/g;
            s/^[\s]*Driver\s*"vesa"/\tDriver      "fglrx"/g;
            s/^[\s]*Driver\s*"ati"/\tDriver      "fglrx"/g;
            s/DefaultColorDepth.*/DefaultColorDepth 24/;
	    s/DefaultDepth.*/DefaultDepth 24/;
            s/^[\s]*Option\s*"sw_cursor"/\t#Option     "sw_cursor"/;
            s/^([\s]*Load\s*"extmod")/#\1\n\tSubSection  "extmod"\n\t  Option  "omit xfree86-dga"\n\tEndSubSection/;
            s/^.*UseInternalAGPGART.*\n?//g;
            s/^.*VideoOverlay.*\n?//g;
            s/^.*OpenGLOverlay.*\n?//g;
            s/^.*MonitorLayout.*\n?//g;
            s/^([\s]*Driver\s*"fglrx")/\1\n\tOption      "UseInternalAGPGART" "yes"\n\t#Option      "VideoOverlay" "on"\n\t#Option      "OpenGLOverlay" "off"\n\tOption      "MonitorLayout" "AUTO, AUTO"/g' \
            < /etc/X11/$X_CONF.1st > /etc/X11/$X_CONF
lsmod|grep -q agpgart && perl -pi -e 's/^([\s]*Option\s*"UseInternalAGPGART").*/\1 "no"/g' /etc/X11/$X_CONF
[ "$CPU" = "x86_64" ] && perl -pi -e 's/^([\s]*Option\s*"UseInternalAGPGART").*/\1 "no"/g' /etc/X11/$X_CONF
[ "$LAPTOP" ] && perl -pi -e 's/^([\s]*Option\s*"MonitorLayout").*/\1 "LVDS, AUTO"/g' /etc/X11/$X_CONF
case $VER in 8.16.20|8.18.6|8.18.8|8.19.10|8.20.8|8.21.7|8.30.3|8.31.5|8.33.6|8.34.8|8.35.5|8.36.5|8.37.6|8.38.6|8.38.7|8.39.4|8.40.4|8.41.7|8.42.3|8.433|8.443.1|8.452.1|8.455.2|8.471|8.476|8.493|8.493.1|8.501) RMML=1 ;; esac
[ "$RMML" = "1" ] && perl -pi -e 's/^.*Mode.ine.*\n?//g' /etc/X11/$X_CONF
[ "$AUTO_RES" = "1" ] && perl -pi -e 's/(Modes).*/\1/' /etc/X11/$X_CONF
[ "$AUTO_SYNC" = "1" ] && perl -pi -e 's/(\s*)(HorizSync|VertRefresh)/\1##\2/' /etc/X11/$X_CONF

# Ubuntu Edgy workaround (Composite 1 is default there!)
if which Xorg >/dev/null; then
 if ! grep -q Extensions /etc/X11/$X_CONF; then
  printf "%b\n" '\nSection "Extensions"' >> /etc/X11/$X_CONF
  printf "%b\n" '\tOption\t"Composite"\t"1"' >> /etc/X11/$X_CONF
  printf "%b\n" '#\tOption\t"RENDER"\t"1"' >> /etc/X11/$X_CONF
  echo 'EndSection' >> /etc/X11/$X_CONF
 fi
 case $VER in 8.22.5|8.23.7|8.24.8|8.25.18|8.26.18|8.27.10|8.28.8|8.29.6|8.30.3|8.31.5|8.32.5|8.33.6|8.34.8|8.35.5|8.36.5|8.37.6|8.38.6|8.38.7|8.39.4|8.40.4|8.41.7)
  perl -pi -e 's/^[\s]*#*[\s]*Option\s*"Composite".*/\tOption\t"Composite"\t"0"/' /etc/X11/$X_CONF
  # fully disable AIGLX seems to help sometimes
  perl -pi -e 's/^[\s]*#*[\s]*Option\s*"AIGLX".*//;s/(^[\s]*Section\s*"ServerLayout".*)/\1\n\tOption\t"AIGLX"\t"0"/' /etc/X11/$X_CONF
  ;;
 *)
  perl -pi -e 's/^[\s]*#*[\s]*Option\s*"Composite".*/\tOption\t"Composite"\t"1"/' /etc/X11/$X_CONF
  perl -pi -e 's/^[\s]*#*[\s]*Option\s*"AIGLX".*//' /etc/X11/$X_CONF
  ;;
 esac
 # disable composite if -c option used
 if [ "$COMPOSITE" = "0" ]; then
  perl -pi -e 's/^[\s]*#*[\s]*Option\s*"Composite".*/\tOption\t"Composite"\t"0"/' /etc/X11/$X_CONF
  perl -pi -e 's/^[\s]*#*[\s]*Option\s*"AIGLX".*//;s/(^[\s]*Section\s*"ServerLayout".*)/\1\n\tOption\t"AIGLX"\t"0"/' /etc/X11/$X_CONF
 fi
fi
# added for 3.14.6 and above
if ! grep -q "/dev/shm tmpfs" /proc/mounts; then
 perl -pi -e 's|\n?$|\n|' /etc/fstab
 perl -pi -e 's|.*tmpfs.*[\n]*||' /etc/fstab
 echo tmpfs /dev/shm tmpfs defaults 0 0 >> /etc/fstab
 mount /dev/shm
fi
sync

# X Server 1.4 workaround
case $VER in 
 8.41.7|8.40.4|8.39.4|8.38.7|8.38.6|8.37.6|8.36.5|8.35.5|8.34.8|8.33.6|8.32.5|8.31.5|8.30.3|8.29.6|8.28.8|8.27.10|8.26.18|8.25.18|8.24.8|8.23.7|8.22.5) 
 if X -version 2>&1|grep -q -e "X Server 1.4"; then
  DDM=$(cat /etc/X11/default-display-manager 2>/dev/null|sed 's|.*/||')
  if [ -z "$DDM" ]; then
   for DDM in kdm gdm xdm; do
    [ -x /etc/init.d/$DDM ] && break
   done
  fi
  case $DDM in
   gdm)
    if ! grep -q [[]server-Standard[]] /etc/gdm/gdm.conf; then
     echo Warning: Using X Server 1.4 GDM workaround ! >&2
     echo [server-Standard] >> /etc/gdm/gdm.conf
     echo command=/usr/bin/X -audit 0 -ignoreABI >> /etc/gdm/gdm.conf
    fi
    ;;
   kdm)
    for k in 3 4; do
     if [ -f /etc/kde$k/kdm/kdmrc ] && ! grep -qe -ignoreABI /etc/kde$k/kdm/kdmrc; then
      echo "Warning: Using X Server 1.4 KDM (KDE$k) workaround !" >&2
      sed -i 's|^\(\s*ServerCmd=.*\)|\1 -ignoreABI|' /etc/kde$k/kdm/kdmrc
     fi
    done
    ;;
   xdm)
    if ! grep -qe -ignoreABI /etc/X11/xdm/Xservers; then
     echo Warning: Using X Server 1.4 XDM workaround ! >&2
     sed -i 's|^\(\s*:.*\)|\1 -ignoreABI|' /etc/X11/xdm/Xservers
    fi
    ;;
  esac
 fi
 ;;
esac

[ -x /etc/init.d/xsession ] && rm -f $(modinfo -F filename radeon)

if ! [ "$NO_X_KILL" = "1" ]; then
 if [ "$INSTALLED" = "yes" ]; then
  killall -9 Xorg >/dev/null 2>&1
  if [ -z "$DM" ]; then
   if [ -x /etc/init.d/kdm ]; then
    /etc/init.d/kdm start
   elif [ -x /etc/init.d/gdm ]; then
    /etc/init.d/gdm start
   elif [ -x /etc/init.d/xdm ]; then
    /etc/init.d/xdm start
   fi
  else
   [ -x /etc/init.d/$DM ] && /etc/init.d/$DM start
  fi
 else
  if [ -x /etc/init.d/xsession ]; then
   nohup sh -c "/etc/init.d/xsession stop; sleep 5; rmmod radeon drm fglrx 2>/dev/null; /etc/init.d/xsession start"
  else
   nohup sh -c "/etc/init.d/kdm stop; sleep 5; rmmod radeon drm fglrx 2>/dev/null; /etc/init.d/kdm start"
  fi
 fi
fi
