code:
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/licenses/gpl.txt

from pisi.actionsapi import get
from pisi.actionsapi import autotools
from pisi.actionsapi import pisitools
from pisi.actionsapi import shelltools
from pisi.actionsapi import kerneltools

WorkDir = "."
KDIR = kerneltools.getKernelVersion()
NoStrip = ["/lib/modules"]

version = get.srcVERSION()
driver_dir_name = "nvidia-current"
datadir = "/usr/share/%s" % driver_dir_name
libdir = "/usr/lib32" if get.buildTYPE() == 'emul32' else "/usr/lib"
arch = "x86"  if get.buildTYPE() == 'emul32' else get.ARCH().replace("i6", "x")
nvlibdir = "%s/%s" % (libdir, driver_dir_name)
xorglibdir= "%s/xorg" % libdir

def setup():
    shelltools.system("sh NVIDIA-Linux-%s-%s.run -x --target tmp"
                      % (arch, get.srcVERSION()))
    shelltools.move("tmp/*", ".")

    # Our libc is TLS enabled so use TLS library
    #shelltools.unlink("*-tls.so*")
    #shelltools.move("tls/*", ".")

    # xorg-server provides libwfb.so
    shelltools.unlink("libnvidia-wfb.so.*")

    shelltools.echo("ld.so.conf", nvlibdir)
    shelltools.echo("XvMCConfig", "%s/libXvMCNVIDIA.so" % nvlibdir)

def build():
    # We don't need kernel module for emul32 build
    if get.buildTYPE() == 'emul32':
        return

    shelltools.export("SYSSRC", "/lib/modules/%s/build" % KDIR)
    shelltools.cd("kernel")

    autotools.make("module")

    #shelltools.cd("uvm")
    #autotools.make("module")

def install():

    if not get.buildTYPE() == 'emul32':
        # Kernel driver
        pisitools.insinto("/lib/modules/%s/extra" % KDIR,
                          "kernel/nvidia.ko")

        pisitools.insinto("/lib/modules/%s/extra" % KDIR,
                          "kernel/nvidia-uvm.ko")

        pisitools.insinto("/lib/modules/%s/extra" % KDIR,
                          "kernel/nvidia-modeset.ko")

        # Command line tools and their man pages
        pisitools.dobin("nvidia-smi")
        pisitools.doman("nvidia-smi.1.gz")
        pisitools.dobin("nvidia-debugdump")
        pisitools.dobin("nvidia-xconfig")
        pisitools.doman("nvidia-xconfig.1.gz")
        pisitools.dobin("nvidia-bug-report.sh")
        pisitools.dobin("nvidia-cuda-mps-server")
        pisitools.dobin("nvidia-cuda-mps-control")
        pisitools.doman("nvidia-cuda-mps-control.1.gz")
        pisitools.dobin("nvidia-modprobe")
        pisitools.doman("nvidia-modprobe.1.gz")
        pisitools.dobin("nvidia-persistenced")
        pisitools.doman("nvidia-persistenced.1.gz")
        pisitools.dobin("nvidia-settings")
        pisitools.doman("nvidia-settings.1.gz")

    ###  Libraries
    # OpenGl library
    pisitools.dolib("libGL.so.%s" % version, nvlibdir)
    pisitools.dosym("libGL.so.%s" % version, "%s/libGL.so.1.2.0" % nvlibdir)
    pisitools.dolib("libGL.so.%s" % version, libdir)

    pisitools.dolib("libEGL.so.1", nvlibdir)
    pisitools.dolib("libEGL_nvidia.so.%s" % version, libdir)
    pisitools.dolib("libGLESv1_CM_nvidia.so.%s" % version, libdir)
    pisitools.dolib("libGLESv2_nvidia.so.%s" % version, libdir)

    # OpenCL
    pisitools.insinto("/etc/OpenCL/vendors", "nvidia.icd")
    pisitools.dolib("libnvidia-compiler.so.%s" % version, libdir)
    pisitools.dosym("libnvidia-compiler.so.%s" % version, "%s/libnvidia-compiler.so.1" % libdir)

    pisitools.dolib("libOpenCL.so.1.0.0", libdir)
    pisitools.dosym("libOpenCL.so.1.0.0", "%s/libOpenCL.so.1.0" % libdir)
    pisitools.dosym("libOpenCL.so.1.0", "%s/libOpenCL.so.1" % libdir)

    pisitools.dolib("libnvidia-opencl.so.%s" % version, libdir)
    pisitools.dosym("libnvidia-opencl.so.%s" % version, "%s/libnvidia-opencl.so.1" % libdir)
    pisitools.dosym("libnvidia-opencl.so.1", "%s/libnvidia-opencl.so" % libdir)

    # CUDA
    pisitools.dolib("libcuda.so.%s" % version, libdir)
    pisitools.dosym("libcuda.so.%s" % version, "%s/libcuda.so.1" % libdir)
    pisitools.dosym("libcuda.so.1", "%s/libcuda.so" % libdir)

    pisitools.dolib("libnvcuvid.so.%s" % version, libdir)
    pisitools.dosym("libnvcuvid.so.%s" % version, "%s/libnvcuvid.so.1" % libdir)
    pisitools.dosym("libnvcuvid.so.1", "%s/libnvcuvid.so" % libdir)

    # NVML
    # Provides programmatic access to static information and monitoring
    # data for NVIDIA GPUs, as well as limited managment capabilities
    pisitools.dolib("libnvidia-ml.so.%s" % version, libdir)
    pisitools.dosym("libnvidia-ml.so.%s" % version, "%s/libnvidia-ml.so.1" % libdir)

    pisitools.dolib("libnvidia-cfg.so.%s" % version, libdir)
    pisitools.dosym("libnvidia-cfg.so.%s" % version, "%s/libnvidia-cfg.so.1" % libdir)

    # OpenGL core library and others
    for lib in ("glcore", "tls", "encode", "fbc", "glsi", "ifr", "eglcore"):
        pisitools.dolib("libnvidia-%s.so.%s" % (lib, version), libdir)
        pisitools.dosym("libnvidia-%s.so.%s" % (lib, version), "%s/libnvidia-%s.so.1" %(libdir, lib))

    # VDPAU driver
    pisitools.dolib("libvdpau_nvidia.so.%s" % version, "%s/vdpau" % libdir)
    pisitools.dosym("libvdpau_nvidia.so.%s" % version, "%s/libvdpau_nvidia.so" % libdir)

    # nvidia-tls library
    pisitools.dolib("libnvidia-tls.so.%s" % version, libdir)
    pisitools.dolib("tls/libnvidia-tls.so.%s" % version, "%s/tls" % libdir)

    # X modules
    pisitools.dolib("nvidia_drv.so", "%s/modules/drivers" % xorglibdir)
    pisitools.dolib("libglx.so.%s" % version, "%s/modules/extensions" % xorglibdir)
    pisitools.dosym("libglx.so.%s" % version, "%s/modules/extensions/libglx.so.1" % xorglibdir)

    pisitools.dolib("libGLX_nvidia.so.%s" % version, libdir)
    pisitools.dosym("libGLX_nvidia.so.%s" % version, "%s/libGLX_indirect.so.0" % libdir)

    # PTX JIT Compiler (Parallel Thread Execution (PTX) is a pseudo-assembly language for CUDA)
    pisitools.dolib("libnvidia-ptxjitcompiler.so.%s" % version, libdir)

    # Fat (multiarchitecture) binary loader
    pisitools.dolib("libnvidia-fatbinaryloader.so.%s" % version, libdir)

    pisitools.insinto("/usr/share/X11/xorg.conf.d", "nvidia-drm-outputclass.conf")
  #  pisitools.insinto("/usr/share/nvidia", "nvidia-application-profiles-367.27-rc")
   # pisitools.insinto("/usr/share/nvidia", "nvidia-application-profiles-367.27-key-documentation")
    pisitools.insinto("/usr/share/pixmaps", "nvidia-settings.png")

    pisitools.dolib("libnvidia-gtk2.so.%s" % version, libdir)
    pisitools.dolib("libnvidia-gtk3.so.%s" % version, libdir)

    # Exit time for emul32 build
    if get.buildTYPE() == 'emul32':
        pisitools.insinto(datadir, "ld.so.conf", "32bit-ld.so.conf")
        return

    pisitools.insinto(datadir, "ld.so.conf")
    pisitools.insinto(datadir, "XvMCConfig")

    # Documentation
    docdir = "xorg-video-%s" % driver_dir_name
    pisitools.dodoc("LICENSE", "NVIDIA_Changelog", "README.txt", destDir=docdir)
    pisitools.dohtml("html/*", destDir=docdir)

    ### Note
    # This package includes nvidia-setting and nvidia-xconfig binaries. However
    # we have seperate packages for each of them. Nvidia provides tarballs for
    # these binaries. Don't forget to update these package with each NVIDIA
    # driver update.


code:
#!/usr/bin/python

import os

driver_dir_name = "nvidia-current"
libdir = "/usr/lib32/%s" % driver_dir_name
datadir = "/usr/share/%s" % driver_dir_name

def postInstall(fromVersion, fromRelease, toVersion, toRelease):
    os.system(" /usr/sbin/alternatives \
                --install   /usr/lib32/libGL.so.1.2.0               libGL-32bit                  %(libdir)s/libGL.so.1.2.0     50 \
                --slave     /usr/lib32/xorg/modules/volatile        xorg-modules-volatile-32bit  %(libdir)s/modules"
                % {"libdir": libdir, "datadir": datadir})
#                --slave     /etc/ld.so.conf.d/10-nvidia-32bit.conf  nvidia-ldsoconf-32bit        %(datadir)s/32bit-ld.so.conf"

    # If this driver is in use, refresh links after installation.
    if os.readlink("/etc/alternatives/libGL-32bit") == "%s/libGL.so.1.2.0" % libdir:
        os.system("/usr/sbin/alternatives --set libGL-32bit %s/libGL.so.1.2.0" % libdir)
        os.system("/sbin/ldconfig -X")

def preRemove():
    # FIXME This is not needed when upgrading package; but pisi does not
    #       provide a way to learn operation type.
    #os.system("/usr/sbin/alternatives --remove libGL-32bit %s/libGL.so.1.2.0" % libdir)
    pass

repo_name: ayhanyalcinsoy/main


code:
#!/usr/bin/python

import os

driver_dir_name = "nvidia-current"
libdir = "/usr/lib/%s" % driver_dir_name
datadir = "/usr/share/%s" % driver_dir_name

def postInstall(fromVersion, fromRelease, toVersion, toRelease):
    os.system(" /usr/sbin/alternatives \
                --install   /usr/lib/libGL.so.1.2.0                 libGL                   %(libdir)s/libGL.so.1.2.0     50 \
                --slave     /usr/lib/xorg/modules/volatile          xorg-modules-volatile   %(libdir)s/modules"
                % {"libdir": libdir, "datadir": datadir})
#                --slave     /etc/X11/XvMCConfig                     XvMCConfig              %(datadir)s/XvMCConfig \
#                --slave     /etc/ld.so.conf.d/10-nvidia.conf        nvidia-ldsoconf         %(datadir)s/ld.so.conf"

    # If this driver is in use, refresh links after installation.
    if os.readlink("/etc/alternatives/libGL") == "%s/libGL.so.1.2.0" % libdir:
        os.system("/usr/sbin/alternatives --set libGL %s/libGL.so.1.2.0" % libdir)
        os.system("/sbin/ldconfig -X")

def preRemove():
    # FIXME This is not needed when upgrading package; but pisi does not
    #       provide a way to learn operation type.
    #os.system("/usr/sbin/alternatives --remove libGL %s/libGL.so.1.2.0" % libdir)
    pass


code:
blacklist nouveau
options nouveau modeset=0


code:
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=NVIDIA X Server Settings
Comment=Configure NVIDIA X Server Settings
Exec=/usr/bin/nvidia-settings
Icon=/usr/share/pixmaps/nvidia-settings.png
Categories=Application;Settings;


code:
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pisilinux.org/projeler/pisi/pisi-spec.dtd">
<PISI>
    <Source>
        <Name>module-nvidia-current</Name>
        <Homepage>http://www.nvidia.com</Homepage>
        <Packager>
            <Name>Marcin Bojara</Name>
            <Email>marcin@pisilinux.org</Email>
        </Packager>
        <License>NVIDIA</License>
        NVIDIA drivers for GeForce 6xxx and newer GPUs
        <Description>NVIDIA graphics drivers provide optimized 2D/3D performance.</Description>
        <Archive sha1sum="7ec5ee96ec61faae1c20177c32aa79ad2296c253" type="binary">http://download.nvidia.com/XFree86/Linux-x86/387.34/NVIDIA-Linux-x86-387.34.run</Archive>
        <Archive sha1sum="6ebb8a3992d93642c30684abc03cae7bb82ca220" type="binary">http://download.nvidia.com/XFree86/Linux-x86_64/387.34/NVIDIA-Linux-x86_64-387.34.run</Archive>
        <BuildDependencies>
            <Dependency version="4.9.75">kernel-module-headers</Dependency>
            <Dependency>libX11-devel</Dependency>
            <Dependency>gtk2-devel</Dependency>
            <Dependency>gtk3-devel</Dependency>
        </BuildDependencies>
    </Source>

    <Package>
        <Name>module-nvidia-current</Name>
        <IsA>driver</IsA>
        Kernel module for current NVIDIA graphics driver releases
        <RuntimeDependencies>
            <Dependency version="4.9.75">kernel</Dependency>

        </RuntimeDependencies>
        <Files>
            <Path fileType="library" permanent="true">/lib/modules</Path>
            <Path fileType="data">/etc/modprobe.d</Path>
        </Files>
        <AdditionalFiles>
            <AdditionalFile owner="root" permission="0644" target="/etc/modprobe.d/blacklist-nouveau.conf">modprobe.conf</AdditionalFile>
        </AdditionalFiles>
        <BuildFlags>
            <Flag>noDelta</Flag>
        </BuildFlags>
    </Package>

    <Package>
        <Name>nvidia-settings</Name>
        <IsA>app:gui</IsA>
        <PartOf>hardware.graphics</PartOf>
        Settings for nvidia-current kernel driver
        <RuntimeDependencies>
            <Dependency>atk</Dependency>
            <Dependency>gtk2</Dependency>
            <Dependency>gtk3</Dependency>
            <Dependency>cairo</Dependency>
            <Dependency>glib2</Dependency>
            <Dependency>pango</Dependency>
            <Dependency>libX11</Dependency>
            <Dependency>libXext</Dependency>
            <Dependency>gdk-pixbuf</Dependency>
            <Dependency version="current">module-nvidia-current</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="executable">/usr/bin/nvidia-settings</Path>
            <Path fileType="man">/usr/share/man/man1/nvidia-settings.1</Path>
            <Path fileType="library">/usr/lib/libnvidia-gtk*</Path>
            <Path fileType="data">/usr/share/applications</Path>
            <Path fileType="data">/usr/share/pixmaps</Path>
            <Path fileType="data">/usr/share/nvidia</Path>
        </Files>
        <AdditionalFiles>
            <AdditionalFile owner="root" permission="0644" target="/usr/share/applications/nvidia-settings.desktop">nvidia-settings.desktop</AdditionalFile>
        </AdditionalFiles>
    </Package>

    <Package>
        <Name>nvidia-xconfig</Name>
        <IsA>app:console</IsA>
        <PartOf>hardware.graphics</PartOf>
        Xconfig file for nvidia-current kernel driver
        <RuntimeDependencies>
            <Dependency version="current">module-nvidia-current</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="executable">/usr/bin/nvidia-xconfig</Path>
            <Path fileType="man">/usr/share/man/man1/nvidia-xconfig.1</Path>
        </Files>
    </Package>

    <Package>
        <Name>xorg-video-nvidia-current</Name>
        <IsA>driver</IsA>
        <PartOf>x11.driver</PartOf>
        <RuntimeDependencies>
            <Dependency>libXext</Dependency>
            <Dependency>libX11</Dependency>
            <Dependency>mesa</Dependency>
            <Dependency>xorg-server</Dependency>
            <Dependency version="current">module-nvidia-current</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="data">/etc/OpenCL</Path>
            <Path fileType="executable">/usr/bin</Path>
            <Path fileType="library">/usr/lib</Path>
            <Path fileType="data">/usr/share/X11</Path>
            <Path fileType="data">/usr/share/nvidia-current</Path>
            <Path fileType="doc">/usr/share/doc</Path>
            <Path fileType="man">/usr/share/man</Path>
        </Files>
        <Provides>
            <COMAR script="package.py">System.Package</COMAR>
        </Provides>
        <BuildFlags>
            <Flag>noDelta</Flag>
        </BuildFlags>
    </Package>

    <Package>
        <Name>xorg-video-nvidia-current-32bit</Name>
        <PartOf>emul32</PartOf>
        32-bit shared libraries for xorg-video-nvidia-current
        <BuildType>emul32</BuildType>
        <BuildDependencies>
            <Dependency>libvdpau-32bit</Dependency>
        </BuildDependencies>
        <RuntimeDependencies>
            <Dependency>zlib-32bit</Dependency>
            <Dependency>mesa-32bit</Dependency>
            <Dependency>libX11-32bit</Dependency>
            <Dependency>libXext-32bit</Dependency>
            <Dependency release="current">xorg-video-nvidia-current</Dependency>
            <Dependency>atk</Dependency>
            <Dependency>gtk2</Dependency>
            <Dependency>gtk3</Dependency>
            <Dependency>cairo</Dependency>
            <Dependency>glib2</Dependency>
            <Dependency>pango</Dependency>
            <Dependency>gdk-pixbuf</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="library">/usr/lib32</Path>
            <Path fileType="library">/usr/share/nvidia-current/32bit-ld.so.conf</Path>
        </Files>
        <Provides>
            <COMAR script="package-emul32.py">System.Package</COMAR>
        </Provides>
        <BuildFlags>
            <Flag>noDelta</Flag>
        </BuildFlags>
    </Package>

    <History>
        <Update release="14">
            <Date>2018-01-06</Date>
            <Version>387.34</Version>
            <Comment>Rebuild for new kernel</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>muscnsl@gmail.com</Email>
        </Update>
        <Update release="13">
            <Date>2017-12-20</Date>
            <Version>387.34</Version>
            <Comment>Rebuild for new kernel.</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>muscnsl@gmail.com</Email>
        </Update>
        <Update release="12">
            <Date>2017-12-06</Date>
            <Version>387.34</Version>
            <Comment>Version Bump.</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>muscnsl@gmail.com</Email>
        </Update>
        <Update release="12">
            <Date>2017-11-23</Date>
            <Version>384.59</Version>
            <Comment>Rebuild.</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>muscnsl@gmail.com</Email>
        </Update>
        <Update release="11">
            <Date>2017-08-22</Date>
            <Version>384.59</Version>
            <Comment>Version Bump</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="10">
            <Date>2017-07-08</Date>
            <Version>381.22</Version>
            <Comment>Version Bump</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="9">
            <Date>2017-03-11</Date>
            <Version>378.13</Version>
            <Comment>Version Bump</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="8">
            <Date>2017-01-31</Date>
            <Version>375.26</Version>
            <Comment>Version Bump</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="7">
            <Date>2016-12-11</Date>
            <Version>375.20</Version>
            <Comment>Version Bump</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="6">
            <Date>2016-11-05</Date>
            <Version>375.10</Version>
            <Comment>Version Bump</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="5">
            <Date>2016-08-28</Date>
            <Version>370.23</Version>
            <Comment>Version Bump</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="4">
            <Date>2016-08-06</Date>
            <Version>367.27</Version>
            <Comment>Rebuild for kernel4.7.0</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="3">
            <Date>2016-04-30</Date>
            <Version>367.27</Version>
            <Comment>Rebuild for new kernel, ver. bump</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="2">
            <Date>2016-04-30</Date>
            <Version>361.28</Version>
            <Comment>Rebuild for new kernel</Comment>
            <Name>Alihan Öztürk</Name>
            <Email>alihan@pisilinux.org</Email>
        </Update>
        <Update release="1">
            <Date>2016-03-06</Date>
            <Version>361.28</Version>
            <Comment>First release</Comment>
            <Name>Alihan Öztürk</Name>
            <Email>alihan@pisilinux.org</Email>
        </Update>
    </History>
</PISI>


code:
<?xml version="1.0" ?>
<PISI>
    <Source>
        <Name>module-nvidia-current</Name>
        GeForce 6xxx ve daha yeni NVIDIA ekran kartları için sürücüler
        <Description xml:lang="tr">NVIDIA grafik sürücüleri daha iyi 2B/3B başarımı sağlar.</Description>
        <Description xml:lang="es">Controladores de kernel nVIDIA y glx para rendimiento optimizado 2d/3d en Linux (Para NV3X o mejor).</Description>
        Controladores nVIDIA  de kernel y glx para tarjetas NV3 o mejor (Geforce FX o mejor)
    </Source>

    <Package>
        <Name>module-nvidia-current</Name>
        Güncel NVIDIA grafik sürücüleri için çekirdek modülü
    </Package>

    <Package>
        <Name>xorg-video-nvidia-current</Name>
        Güncel NVIDIA userspace sürücüleri ve ikili dosyaları
    </Package>

    <Package>
        <Name>xorg-video-nvidia-current-32bit</Name>
        xorg-video-nvidia-current için 32-bit paylaşımlı kitaplıklar
    </Package>
</PISI>


code:
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/licenses/gpl.txt

from pisi.actionsapi import kerneltools
from pisi.actionsapi import shelltools
from pisi.actionsapi import autotools
from pisi.actionsapi import pisitools
from pisi.actionsapi import get

WorkDir = "."
KDIR = kerneltools.getKernelVersion()
NoStrip = ["/lib/modules"]

version = get.srcVERSION()
driver_dir_name = "nvidia304"
datadir = "/usr/share/%s" % driver_dir_name

if get.buildTYPE() == 'emul32':
    arch = "x86"
    nvlibdir = "/usr/lib32/%s" % driver_dir_name
    libdir = "/usr/lib32"
else:
    arch = get.ARCH().replace("i686", "x86")
    nvlibdir = "/usr/lib/%s" % driver_dir_name
    libdir = "/usr/lib"

def setup():
    shelltools.system("sh NVIDIA-Linux-%s-%s.run -x --target tmp"
                      % (arch, get.srcVERSION()))
    shelltools.move("tmp/*", ".")

    #shelltools.system("patch -p1 < linux-4.6.patch")
    #shelltools.system("patch -p0 < nv-drm.patch")

    # Our libc is TLS enabled so use TLS library
    shelltools.unlink("*-tls.so*")
    shelltools.move("tls/*", ".")

    # xorg-server provides libwfb.so
    shelltools.unlink("libnvidia-wfb.so.*")

    shelltools.echo("ld.so.conf", nvlibdir)
    shelltools.echo("XvMCConfig", "%s/libXvMCNVIDIA.so" % nvlibdir)

def build():
    # We don't need kernel module for emul32 build
    if get.buildTYPE() == 'emul32':
        return

    shelltools.export("SYSSRC", "/lib/modules/%s/build" % KDIR)
    shelltools.cd("kernel")

    autotools.make("module")

def install():

    if not get.buildTYPE() == 'emul32':
    # Kernel driver
        pisitools.insinto("/lib/modules/%s/extra/nvidia" % KDIR,
                          "kernel/nvidia.ko")

        # Command line tools and their man pages
        pisitools.dobin("nvidia-smi")
        pisitools.doman("nvidia-smi.1.gz")

    ###  Libraries
    # OpenGl library
    pisitools.dolib("libGL.so.%s" % version, nvlibdir)
    pisitools.dosym("libGL.so.%s" % version, "%s/libGL.so.1.2.0" % nvlibdir)

    # OpenCL
    pisitools.dolib("libOpenCL.so.1.0.0", libdir)
    pisitools.dosym("libOpenCL.so.1.0.0", "%s/libOpenCL.so.1.0" % libdir)
    pisitools.dosym("libOpenCL.so.1.0", "%s/libOpenCL.so.1" % libdir)

    # CUDA
    pisitools.dolib("libcuda.so.%s" % version, libdir)
    pisitools.dosym("libcuda.so.%s" % version, "%s/libcuda.so.1" % libdir)
    pisitools.dosym("libcuda.so.1", "%s/libcuda.so" % libdir)

    pisitools.dolib("libnvcuvid.so.%s" % version, libdir)
    pisitools.dosym("libnvcuvid.so.%s" % version, "%s/libnvcuvid.so.1" % libdir)
    pisitools.dosym("libnvcuvid.so.1", "%s/libnvcuvid.so" % libdir)

    # NVML
    # Provides programmatic access to static information and monitoring
    # data for NVIDIA GPUs, as well as limited managment capabilities
    pisitools.dolib("libnvidia-ml.so.%s" % version, libdir)
    pisitools.dosym("libnvidia-ml.so.%s" % version, "%s/libnvidia-ml.so.1" % libdir)

    pisitools.dolib("libnvidia-cfg.so.%s" % version, libdir)
    pisitools.dosym("libnvidia-cfg.so.%s" % version, "%s/libnvidia-cfg.so.1" % libdir)

    pisitools.dolib("libnvidia-compiler.so.%s" % version, libdir)
    pisitools.dosym("libnvidia-compiler.so.%s" % version, "%s/libnvidia-compiler.so.1" % libdir)

    # OpenGL cpre library
    for lib in ("glcore", "tls"):
        pisitools.dolib("libnvidia-%s.so.%s" % (lib, version), libdir)

    # VDPAU driver
    pisitools.dolib("libvdpau_nvidia.so.%s" % version, "%s/vdpau" % nvlibdir)
    pisitools.dosym("../nvidia-current/vdpau/libvdpau_nvidia.so.%s" % version, "%s/vdpau/libvdpau_nvidia.so.1" % nvlibdir.strip(driver_dir_name))

    # X modules
    pisitools.dolib("nvidia_drv.so", "%s/modules/drivers" % nvlibdir)
    pisitools.dolib("libglx.so.%s" % version, "%s/modules/extensions" % nvlibdir)
    pisitools.dosym("libglx.so.%s" % version, "%s/modules/extensions/libglx.so" % nvlibdir)

    # Exit time for emul32 build
    if get.buildTYPE() == 'emul32':
        pisitools.insinto(datadir, "ld.so.conf", "32bit-ld.so.conf")
        return

    pisitools.insinto("/etc/OpenCL/vendors", "nvidia.icd")

    pisitools.insinto(datadir, "ld.so.conf")
    pisitools.insinto(datadir, "XvMCConfig")

    # Documentation
    docdir = "xorg-video-%s" % driver_dir_name
    pisitools.dodoc("LICENSE", "NVIDIA_Changelog", "README.txt", destDir=docdir)
    pisitools.dohtml("html/*", destDir=docdir)

    ### Note
    # This package includes nvidia-setting and nvidia-xconfig binaries. However
    # we have seperate packages for each of them. Nvidia provides tarballs for
    # these binaries. Don't forget to update these package with each NVIDIA
    # driver update.

    # Nvidia-bug-report
    # Comes with our own nvidia-xcfonig package
    # pisitools.dobin("nvidia-bug-report.sh")


code:
#!/usr/bin/python

import os

driver_dir_name = "nvidia304"
libdir = "/usr/lib/%s" % driver_dir_name
datadir = "/usr/share/%s" % driver_dir_name

def postInstall(fromVersion, fromRelease, toVersion, toRelease):
    os.system("/usr/sbin/alternatives \
                --install   /usr/lib/libGL.so.1.2.0                 libGL                   %(libdir)s/libGL.so.1.2.0   40 \
                --slave     /usr/lib/xorg/modules/volatile          xorg-modules-volatile   %(libdir)s/modules \
                --slave     /etc/X11/XvMCConfig                     XvMCConfig              %(datadir)s/XvMCConfig \
                --slave     /etc/ld.so.conf.d/10-nvidia.conf        nvidia-ldsoconf         %(datadir)s/ld.so.conf"
                % {"libdir": libdir, "datadir": datadir})

    # If this driver is in use, refresh links after installation.
    if os.readlink("/etc/alternatives/libGL") == "%s/libGL.so.1.2.0" % libdir:
        os.system("/usr/sbin/alternatives --set libGL %s/libGL.so.1.2.0" % libdir)
        os.system("/sbin/ldconfig -X")

def preRemove():
    # FIXME This is not needed when upgrading package; but pisi does not
    #       provide a way to learn operation type.
    #os.system("/usr/sbin/alternatives --remove libGL %s/libGL.so.1.2" % libdir)
    pass


code:
Adapt for kernel 3.19

Signed-off-by: Thomas Backlund <tmb@mageia.org>

diff -Nurp NVIDIA-Linux-x86_64-304.125.orig/kernel/nv.c NVIDIA-Linux-x86_64-304.125/kernel/nv.c
--- NVIDIA-Linux-x86_64-304.125.orig/kernel/nv.c	2014-12-02 05:58:34.000000000 +0200
+++ NVIDIA-Linux-x86_64-304.125/kernel/nv.c	2015-01-25 19:14:21.009109856 +0200
@@ -2026,7 +2026,11 @@ long nv_kern_unlocked_ioctl(
     unsigned long i_arg
 )
 {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+    return nv_kern_ioctl(file->f_path.dentry->d_inode, file, cmd, i_arg);
+#else
     return nv_kern_ioctl(file->f_dentry->d_inode, file, cmd, i_arg);
+#endif
 }

 long nv_kern_compat_ioctl(
@@ -2035,7 +2039,11 @@ long nv_kern_compat_ioctl(
     unsigned long i_arg
 )
 {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
+    return nv_kern_ioctl(file->f_path.dentry->d_inode, file, cmd, i_arg);
+#else
     return nv_kern_ioctl(file->f_dentry->d_inode, file, cmd, i_arg);
+#endif
 }

 /*


code:
--- /dev/null
+++ b/kernel/nv-mm.h
@@ -0,0 +1,55 @@
+/*******************************************************************************
+    Copyright (c) 2016 NVIDIA Corporation
+
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to
+    deal in the Software without restriction, including without limitation the
+    rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+    sell copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+
+        The above copyright notice and this permission notice shall be
+        included in all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+    DEALINGS IN THE SOFTWARE.
+
+*******************************************************************************/
+#ifndef __NV_MM_H__
+#define __NV_MM_H__
+
+/*  get_user_pages_remote() was added by:
+ *    2016 Feb 12: 1e9877902dc7e11d2be038371c6fbf2dfcd469d7
+ *
+ *  The very next commit (cde70140fed8429acf7a14e2e2cbd3e329036653)
+ *  deprecated the 8-argument version of get_user_pages for the
+ *  non-remote case (calling get_user_pages with current and current->mm).
+ *
+ *  The guidelines are: call NV_GET_USER_PAGES_REMOTE if you need the 8-argument
+ *  version that uses something other than current and current->mm. Use
+ *  NV_GET_USER_PAGES if you are refering to current and current->mm.
+ *
+*  Note that get_user_pages_remote() requires the caller to hold a reference on
+*  the task_struct (if non-NULL) and the mm_struct. This will always be true
+*  when using current and current->mm. If the kernel passes the driver a vma
+*  via driver callback, the kernel holds a reference on vma->vm_mm over that
+*  callback.
+ */
+
+#if defined(NV_GET_USER_PAGES_REMOTE_PRESENT)
+    #define NV_GET_USER_PAGES           get_user_pages
+    #define NV_GET_USER_PAGES_REMOTE    get_user_pages_remote
+#else
+    #define NV_GET_USER_PAGES(start, nr_pages, write, force, pages, vmas) \
+        get_user_pages(current, current->mm, start, nr_pages, write, force, pages, vmas)
+
+    #define NV_GET_USER_PAGES_REMOTE    get_user_pages
+#endif
+
+
+#endif // __NV_MM_H__
--- a/kernel/nv-mlock.c
+++ b/kernel/nv-mlock.c
@@ -13,6 +13,7 @@

 #include "os-interface.h"
 #include "nv-linux.h"
+#include "nv-mm.h"

 RM_STATUS NV_API_CALL nv_lock_user_pages(
     nv_state_t *nv,
@@ -49,7 +50,7 @@ RM_STATUS NV_API_CALL os_lock_user_pages(
     }

     down_read(&mm->mmap_sem);
-    ret = get_user_pages(current, mm, (unsigned long)address,
+    ret = NV_GET_USER_PAGES((unsigned long)address,
             page_count, write, force, user_pages, NULL);
     up_read(&mm->mmap_sem);
     pinned = ret;
@@ -62,7 +62,7 @@ RM_STATUS NV_API_CALL os_lock_user_pages(
     else if (pinned < page_count)
     {
         for (i = 0; i < pinned; i++)
-            page_cache_release(user_pages[i]);
+            put_page(user_pages[i]);
         os_free_mem(user_pages);
         return RM_ERR_INVALID_ADDRESS;
     }
@@ -81,7 +81,7 @@ RM_STATUS NV_API_CALL os_lock_user_pages(
             {
                 pci_unmap_page(dev, pte_array[j],
                         PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
-                page_cache_release(user_pages[j]);
+                put_page(user_pages[j]);
             }
             os_free_mem(user_pages);
             return RM_ERR_OPERATING_SYSTEM;
@@ -114,7 +114,7 @@ RM_STATUS NV_API_CALL os_unlock_user_pages(
                 PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
         if (write)
             set_page_dirty_lock(user_pages[i]);
-        page_cache_release(user_pages[i]);
+        put_page(user_pages[i]);
     }

     os_free_mem(user_pages);
diff --git a/kernel/conftest.sh.orig b/kernel/conftest.sh
index d01488b..308ea8a 100755
--- a/kernel/conftest.sh
+++ b/kernel/conftest.sh
@@ -1525,6 +1525,23 @@ compile_test() {

             compile_check_conftest "$CODE" "NV_NODE_END_PFN_PRESENT" "" "functions"
         ;;
+
+        get_user_pages_remote)
+            #
+            # Determine if the function get_user_pages_remote() is
+            # present.
+            #
+            # get_user_pages_remote() was added by:
+            #   2016 Feb 12: 1e9877902dc7e11d2be038371c6fbf2dfcd469d7
+            #
+            CODE="
+            #include <linux/mm.h>
+            int conftest_get_user_pages_remote(void) {
+                get_user_pages_remote();
+            }"
+
+            compile_check_conftest "$CODE" "NV_GET_USER_PAGES_REMOTE_PRESENT" "" "functions"
+        ;;
     esac
 }

--- a/kernel/Makefile.kbuild
+++ b/kernel/Makefile.kbuild
@@ -187,7 +187,8 @@ COMPILE_TESTS = \
 	drm_pci_set_busid \
 	write_cr4 \
 	for_each_online_node \
-	node_end_pfn
+	node_end_pfn \
+	get_user_pages_remote

 #
 # CFLAGS dependent on the type of builds (e.g. single/muliple module, debug)


code:
--- kernel/nv-drm.c~ 2014-09-12 00:33:06.000000000 +0200
+++ kernel/nv-drm.c 2014-10-14 11:35:52.854400737 +0200
@@ -18,6 +18,11 @@

 #include <drm/drmP.h>

+/* 3.18-rc0+ */
+#ifndef drm_gem_object
+#include <drm/drm_gem.h>
+#endif
+
 extern nv_linux_state_t *nv_linux_devices;

 struct nv_gem_object {
diff --git a/kernel/nv-drm.c~ b/kernel/nv-drm.c
index ecc982a..60d7aae 100644
--- kernel/nv-drm.c~
+++ kernel/nv-drm.c
@@ -129,6 +129,8 @@ static struct drm_driver nv_drm_driver = {
     .gem_prime_vmap = nv_gem_prime_vmap,
     .gem_prime_vunmap = nv_gem_prime_vunmap,

+    .set_busid = drm_pci_set_busid,
+
     .name = "nvidia-drm",
     .desc = "NVIDIA DRM driver",
     .date = "20130102",


code:
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pisilinux.org/projeler/pisi/pisi-spec.dtd">
<PISI>
    <Source>
        <Name>module-nvidia304</Name>
        <Homepage>http://www.nvidia.com</Homepage>
        <Packager>
            <Name>PisiLinux Community</Name>
            <Email>admins@pisilinux.org</Email>
        </Packager>
        <License>NVIDIA</License>
        <IsA>driver</IsA>
        NVIDIA drivers for GeForce 5-7 series GPUs
        <Description>NVIDIA graphics drivers provide optimized 2D/3D performance.</Description>
        <Archive sha1sum="5b110db57f617aadacb86aa4974847c2954aa1b3" type="binary">http://http.download.nvidia.com/XFree86/Linux-x86/304.137/NVIDIA-Linux-x86-304.137.run</Archive>
        <Archive sha1sum="8e4bd0aee5f5667aa00c38b8ecf520494d0a9d02" type="binary">http://http.download.nvidia.com/XFree86/Linux-x86_64/304.137/NVIDIA-Linux-x86_64-304.137.run</Archive>
        <AdditionalFiles>

        </AdditionalFiles>
        <BuildDependencies>
            <Dependency version="4.9.75">kernel-module-headers</Dependency>
        </BuildDependencies>
    </Source>

    <Package>
        <Name>module-nvidia304</Name>
        Kernel module for NVIDIA driver 304.xx releases
        <RuntimeDependencies>
            <Dependency version="4.9.75">kernel</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="library" permanent="true">/lib/modules</Path>
        </Files>
        <BuildFlags>
            <Flag>noDelta</Flag>
        </BuildFlags>
    </Package>

    <Package>
        <Name>xorg-video-nvidia304</Name>
        <PartOf>x11.driver</PartOf>
        <RuntimeDependencies>
            <Dependency version="current">module-nvidia304</Dependency>
            <Dependency>libXext</Dependency>
            <Dependency>xorg-server</Dependency>
            <Dependency>zlib</Dependency>
            <Dependency>libX11</Dependency>
            <Dependency>libgcc</Dependency>
        </RuntimeDependencies>
        <Conflicts>
            <Package>xorg-video-nvidia-current</Package>
        </Conflicts>
        <Files>
            <Path fileType="data">/etc/OpenCL</Path>
            <Path fileType="executable">/usr/bin</Path>
            <Path fileType="library">/usr/lib</Path>
            <Path fileType="data">/usr/share</Path>
            <Path fileType="doc">/usr/share/doc</Path>
        </Files>
        <Provides>
            <COMAR script="package.py">System.Package</COMAR>
        </Provides>
        <BuildFlags>
            <Flag>noDelta</Flag>
        </BuildFlags>
    </Package>

    <History>
        <Update release="15">
            <Date>2018-01-06</Date>
            <Version>304.137</Version>
            <Comment>Rebuild for new kernel.</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>muscnsl@gmail.com</Email>
        </Update>
        <Update release="14">
            <Date>2017-12-20</Date>
            <Version>304.137</Version>
            <Comment>Rebuild for new kernel.</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>muscnsl@gmail.com</Email>
        </Update>
        <Update release="13">
            <Date>2017-12-06</Date>
            <Version>304.137</Version>
            <Comment>Version bump</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>muscnsl@gmail.com</Email>
        </Update>
        <Update release="12">
            <Date>2017-11-23</Date>
            <Version>304.135</Version>
            <Comment>Rebuild</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>muscnsl@gmail.com</Email>
        </Update>
        <Update release="11">
            <Date>2017-08-22</Date>
            <Version>304.135</Version>
            <Comment>Rebuild</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="10">
            <Date>2017-07-07</Date>
            <Version>304.135</Version>
            <Comment>Version bump.</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="9">
            <Date>2017-03-11</Date>
            <Version>304.134</Version>
            <Comment>Rebuild.</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="8">
            <Date>2017-01-31</Date>
            <Version>304.134</Version>
            <Comment>Version bump</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="7">
            <Date>2016-12-11</Date>
            <Version>304.132</Version>
            <Comment>Rebuild for kernel 4.8.13</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="6">
            <Date>2016-11-04</Date>
            <Version>304.132</Version>
            <Comment>Version bump</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="5">
            <Date>2016-08-28</Date>
            <Version>304.131</Version>
            <Comment>Rebuild for kernel4.7.0</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="4">
            <Date>2016-08-06</Date>
            <Version>304.131</Version>
            <Comment>Rebuild for kernel4.7.0</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="3">
            <Date>2016-07-17</Date>
            <Version>304.131</Version>
            <Comment>Rebuild for kernel4.6.3</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="2">
            <Date>2016-04-30</Date>
            <Version>304.131</Version>
            <Comment>Rebuild for new kernel</Comment>
            <Name>Ertuğrul Erata</Name>
            <Email>ertugrulerata@gmail.com</Email>
        </Update>
        <Update release="1">
            <Date>2016-03-06</Date>
            <Version>304.131</Version>
            <Comment>First release</Comment>
            <Name>Ertuğrul Erata</Name>
            <Email>ertugrulerata@gmail.com</Email>
        </Update>
    </History>
</PISI>


code:
<?xml version="1.0" ?>
<PISI>
    <Source>
        <Name>module-nvidia304</Name>
        NVIDIA GeForce 6-7 serisi ekran kartları için grafik sürücüleri
        <Description xml:lang="tr">NVIDIA grafik sürücüleri daha iyi 2B/3B başarımı sağlar.</Description>
        Controladores nVIDIA  de kernel y glx para tarjetas NV3 o mejor (Geforce FX o mejor)
        <Description xml:lang="es">Controladores de kernel nVIDIA y glx para rendimiento optimizado 2d/3d en Linux (Para NV3X o mejor).</Description>
    </Source>

    <Package>
        <Name>module-nvidia304</Name>
        NVIDIA sürücüsü 304.xx sürümleri için çekirdek modülü
    </Package>

    <Package>
        <Name>module-nvidia304-userspace</Name>
        nvidia304 çekirdek sürücüsü için kullanıcı tarafı belgeler, araçlar, udev ve modprobe kuralları
    </Package>
</PISI>


code:
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/licenses/gpl.txt

from pisi.actionsapi import get
from pisi.actionsapi import autotools
from pisi.actionsapi import pisitools
from pisi.actionsapi import shelltools
from pisi.actionsapi import kerneltools

WorkDir = "."
KDIR = kerneltools.getKernelVersion()
NoStrip = ["/lib/modules"]

version = get.srcVERSION()
driver_dir_name = "nvidia340"
datadir = "/usr/share/%s" % driver_dir_name
libdir = "/usr/lib32" if get.buildTYPE() == 'emul32' else "/usr/lib"
arch = "x86"  if get.buildTYPE() == 'emul32' else get.ARCH().replace("i6", "x")
nvlibdir = "%s/%s" % (libdir, driver_dir_name)
xorglibdir= "%s/xorg" % libdir

def setup():
    shelltools.system("sh NVIDIA-Linux-%s-%s.run -x --target tmp"
                      % (arch, get.srcVERSION()))

    shelltools.move("tmp/*", ".")

    # Our libc is TLS enabled so use TLS library
    shelltools.unlink("*-tls.so*")
    shelltools.move("tls/*", ".")

    # xorg-server provides libwfb.so
    shelltools.unlink("libnvidia-wfb.so.*")

    shelltools.echo("ld.so.conf", nvlibdir)
    shelltools.echo("XvMCConfig", "%s/libXvMCNVIDIA.so" % nvlibdir)
    #shelltools.system("patch -p1 < linux-4.6.patch")

def build():
    # We don't need kernel module for emul32 build
    if get.buildTYPE() == 'emul32':
        return

    shelltools.export("SYSSRC", "/lib/modules/%s/build" % KDIR)

    shelltools.cd("kernel")

    autotools.make("module")

    shelltools.cd("uvm")

    autotools.make("module")

def install():

    if not get.buildTYPE() == 'emul32':
        # Kernel driver
        pisitools.insinto("/lib/modules/%s/extra/nvidia" % KDIR,
                           "kernel/nvidia.ko")

        pisitools.insinto("/lib/modules/%s/extra/nvidia" % KDIR,
                            "kernel/uvm/nvidia-uvm.ko")

        # Command line tools and their man pages
        pisitools.dobin("nvidia-smi")
        pisitools.doman("nvidia-smi.1.gz")

        pisitools.dobin("nvidia-persistenced")

    ###  Libraries
    # OpenGl library
    pisitools.dolib("libGL.so.%s" % version, nvlibdir)
    pisitools.dosym("libGL.so.%s" % version, "%s/libGL.so.1.2.0" % nvlibdir)

    # OpenCL
    pisitools.dolib("libOpenCL.so.1.0.0", libdir)
    pisitools.dosym("libOpenCL.so.1.0.0", "%s/libOpenCL.so.1.0" % libdir)
    pisitools.dosym("libOpenCL.so.1.0", "%s/libOpenCL.so.1" % libdir)

    pisitools.dolib("libnvidia-opencl.so.%s" % version, libdir)
    pisitools.dosym("libnvidia-opencl.so.%s" % version, "%s/libnvidia-opencl.so.1" % libdir)
    pisitools.dosym("libnvidia-opencl.so.1", "%s/libnvidia-opencl.so" % libdir)

    # CUDA
    pisitools.dolib("libcuda.so.%s" % version, libdir)
    pisitools.dosym("libcuda.so.%s" % version, "%s/libcuda.so.1" % libdir)
    pisitools.dosym("libcuda.so.1", "%s/libcuda.so" % libdir)

    pisitools.dolib("libnvcuvid.so.%s" % version, libdir)
    pisitools.dosym("libnvcuvid.so.%s" % version, "%s/libnvcuvid.so.1" % libdir)
    pisitools.dosym("libnvcuvid.so.1", "%s/libnvcuvid.so" % libdir)

    # NVML
    # Provides programmatic access to static information and monitoring
    # data for NVIDIA GPUs, as well as limited managment capabilities
    pisitools.dolib("libnvidia-ml.so.%s" % version, libdir)
    pisitools.dosym("libnvidia-ml.so.%s" % version, "%s/libnvidia-ml.so.1" % libdir)

    pisitools.dolib("libnvidia-cfg.so.%s" % version, libdir)
    pisitools.dosym("libnvidia-cfg.so.%s" % version, "%s/libnvidia-cfg.so.1" % libdir)

    pisitools.dolib("libnvidia-compiler.so.%s" % version, libdir)
    pisitools.dosym("libnvidia-compiler.so.%s" % version, "%s/libnvidia-compiler.so.1" % libdir)

    # OpenGL core library and others
    for lib in ("glcore", "tls", "encode", "fbc", "glsi", "ifr", "eglcore"):
        pisitools.dolib("libnvidia-%s.so.%s" % (lib, version), libdir)
        pisitools.dosym("libnvidia-%s.so.%s" % (lib, version), "%s/libnvidia-%s.so.1" %(libdir, lib))

    # VDPAU driver
    pisitools.dolib("libvdpau_nvidia.so.%s" % version, "%s/vdpau" % nvlibdir)
    pisitools.dosym("../nvidia340/vdpau/libvdpau_nvidia.so.%s" % version, "%s/vdpau/libvdpau_nvidia.so.1" % nvlibdir.strip(driver_dir_name))

    # X modules
    pisitools.dolib("nvidia_drv.so", "%s/modules/drivers" % nvlibdir)
    pisitools.dosym("%s/modules/drivers/nvidia_drv.so" % nvlibdir, "%s/modules/drivers/nvidia_drv.so" % xorglibdir)
    pisitools.dolib("libglx.so.%s" % version, "%s/modules/extensions" % nvlibdir)
    pisitools.dosym("libglx.so.%s" % version, "%s/modules/extensions/libglx.so" % nvlibdir)

    # Exit time for emul32 build
    if get.buildTYPE() == 'emul32':
        pisitools.insinto(datadir, "ld.so.conf", "32bit-ld.so.conf")
        return

    pisitools.insinto("/etc/OpenCL/vendors", "nvidia.icd")

    pisitools.insinto(datadir, "ld.so.conf")
    pisitools.insinto(datadir, "XvMCConfig")

    # Documentation
    docdir = "xorg-video-%s" % driver_dir_name
    pisitools.dodoc("LICENSE", "NVIDIA_Changelog", "README.txt", destDir=docdir)
    pisitools.dohtml("html/*", destDir=docdir)

    ### Note
    # This package includes nvidia-setting and nvidia-xconfig binaries. However
    # we have seperate packages for each of them. Nvidia provides tarballs for
    # these binaries. Don't forget to update these package with each NVIDIA
    # driver update.

    # Nvidia-bug-report
    # Comes with our own nvidia-xcfonig package
    # pisitools.dobin("nvidia-bug-report.sh")


code:
#!/usr/bin/python

import os

driver_dir_name = "nvidia340"
libdir = "/usr/lib32/%s" % driver_dir_name
datadir = "/usr/share/%s" % driver_dir_name

def postInstall(fromVersion, fromRelease, toVersion, toRelease):
    os.system(" /usr/sbin/alternatives \
                --install   /usr/lib32/libGL.so.1.2.0               libGL-32bit                  %(libdir)s/libGL.so.1.2.0     50 \
                --slave     /usr/lib32/xorg/modules/volatile        xorg-modules-volatile-32bit  %(libdir)s/modules"
                % {"libdir": libdir, "datadir": datadir})
#                --slave     /etc/ld.so.conf.d/10-nvidia-32bit.conf  nvidia-ldsoconf-32bit        %(datadir)s/32bit-ld.so.conf"

    # If this driver is in use, refresh links after installation.
    if os.readlink("/etc/alternatives/libGL-32bit") == "%s/libGL.so.1.2.0" % libdir:
        os.system("/usr/sbin/alternatives --set libGL-32bit %s/libGL.so.1.2.0" % libdir)
        os.system("/sbin/ldconfig -X")

def preRemove():
    # FIXME This is not needed when upgrading package; but pisi does not
    #       provide a way to learn operation type.
    #os.system("/usr/sbin/alternatives --remove libGL-32bit %s/libGL.so.1.2.0" % libdir)
    pass


code:
#!/usr/bin/python

import os

driver_dir_name = "nvidia340"
libdir = "/usr/lib/%s" % driver_dir_name
datadir = "/usr/share/%s" % driver_dir_name

def postInstall(fromVersion, fromRelease, toVersion, toRelease):
    os.system(" /usr/sbin/alternatives \
                --install   /usr/lib/libGL.so.1.2.0                 libGL                   %(libdir)s/libGL.so.1.2.0     50 \
                --slave     /usr/lib/xorg/modules/volatile          xorg-modules-volatile   %(libdir)s/modules"
                % {"libdir": libdir, "datadir": datadir})
#                --slave     /etc/X11/XvMCConfig                     XvMCConfig              %(datadir)s/XvMCConfig \
#                --slave     /etc/ld.so.conf.d/10-nvidia.conf        nvidia-ldsoconf         %(datadir)s/ld.so.conf"

    # If this driver is in use, refresh links after installation.
    if os.readlink("/etc/alternatives/libGL") == "%s/libGL.so.1.2.0" % libdir:
        os.system("/usr/sbin/alternatives --set libGL %s/libGL.so.1.2.0" % libdir)
        os.system("/sbin/ldconfig -X")

def preRemove():
    # FIXME This is not needed when upgrading package; but pisi does not
    #       provide a way to learn operation type.
    #os.system("/usr/sbin/alternatives --remove libGL %s/libGL.so.1.2.0" % libdir)
    pass


code:
--- kernel/nv-drm.c	2016-12-15 12:41:26.000000000 +0100
+++ kernel/nv-drm.c	2016-12-15 12:58:48.000000000 +0100
@@ -115,7 +115,11 @@
 };

 static struct drm_driver nv_drm_driver = {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
+    .driver_features = DRIVER_GEM | DRIVER_PRIME | DRIVER_LEGACY,
+#else
     .driver_features = DRIVER_GEM | DRIVER_PRIME,
+#endif
     .load = nv_drm_load,
     .unload = nv_drm_unload,
     .fops = &nv_drm_fops,


code:
--- /dev/null
+++ b/kernel/nv-mm.h
@@ -0,0 +1,55 @@
+/*******************************************************************************
+    Copyright (c) 2016 NVIDIA Corporation
+
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to
+    deal in the Software without restriction, including without limitation the
+    rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+    sell copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+
+        The above copyright notice and this permission notice shall be
+        included in all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+    DEALINGS IN THE SOFTWARE.
+
+*******************************************************************************/
+#ifndef __NV_MM_H__
+#define __NV_MM_H__
+
+/*  get_user_pages_remote() was added by:
+ *    2016 Feb 12: 1e9877902dc7e11d2be038371c6fbf2dfcd469d7
+ *
+ *  The very next commit (cde70140fed8429acf7a14e2e2cbd3e329036653)
+ *  deprecated the 8-argument version of get_user_pages for the
+ *  non-remote case (calling get_user_pages with current and current->mm).
+ *
+ *  The guidelines are: call NV_GET_USER_PAGES_REMOTE if you need the 8-argument
+ *  version that uses something other than current and current->mm. Use
+ *  NV_GET_USER_PAGES if you are refering to current and current->mm.
+ *
+*  Note that get_user_pages_remote() requires the caller to hold a reference on
+*  the task_struct (if non-NULL) and the mm_struct. This will always be true
+*  when using current and current->mm. If the kernel passes the driver a vma
+*  via driver callback, the kernel holds a reference on vma->vm_mm over that
+*  callback.
+ */
+
+#if defined(NV_GET_USER_PAGES_REMOTE_PRESENT)
+    #define NV_GET_USER_PAGES           get_user_pages
+    #define NV_GET_USER_PAGES_REMOTE    get_user_pages_remote
+#else
+    #define NV_GET_USER_PAGES(start, nr_pages, write, force, pages, vmas) \
+        get_user_pages(current, current->mm, start, nr_pages, write, force, pages, vmas)
+
+    #define NV_GET_USER_PAGES_REMOTE    get_user_pages
+#endif
+
+
+#endif // __NV_MM_H__
--- a/kernel/os-mlock.c
+++ b/kernel/os-mlock.c
@@ -13,6 +13,7 @@

 #include "os-interface.h"
 #include "nv-linux.h"
+#include "nv-mm.h"

 RM_STATUS NV_API_CALL os_lock_user_pages(
     void   *address,
@@ -45,7 +46,7 @@ RM_STATUS NV_API_CALL os_lock_user_pages(
     }

     down_read(&mm->mmap_sem);
-    ret = get_user_pages(current, mm, (unsigned long)address,
+    ret = NV_GET_USER_PAGES((unsigned long)address,
             page_count, write, force, user_pages, NULL);
     up_read(&mm->mmap_sem);
     pinned = ret;
@@ -59,7 +59,7 @@ RM_STATUS NV_API_CALL os_lock_user_pages(
     else if (pinned < page_count)
     {
         for (i = 0; i < pinned; i++)
-            page_cache_release(user_pages[i]);
+            put_page(user_pages[i]);
         os_free_mem(user_pages);
         return RM_ERR_INVALID_ADDRESS;
     }
@@ -86,7 +86,7 @@ RM_STATUS NV_API_CALL os_unlock_user_pages(
     {
         if (write)
             set_page_dirty_lock(user_pages[i]);
-        page_cache_release(user_pages[i]);
+        put_page(user_pages[i]);
     }

     os_free_mem(user_pages);
diff --git a/kernel/conftest.sh.orig b/kernel/conftest.sh
index d01488b..308ea8a 100755
--- a/kernel/conftest.sh
+++ b/kernel/conftest.sh
@@ -1669,6 +1669,23 @@ compile_test() {

             compile_check_conftest "$CODE" "NV_NODE_END_PFN_PRESENT" "" "functions"
         ;;
+
+        get_user_pages_remote)
+            #
+            # Determine if the function get_user_pages_remote() is
+            # present.
+            #
+            # get_user_pages_remote() was added by:
+            #   2016 Feb 12: 1e9877902dc7e11d2be038371c6fbf2dfcd469d7
+            #
+            CODE="
+            #include <linux/mm.h>
+            int conftest_get_user_pages_remote(void) {
+                get_user_pages_remote();
+            }"
+
+            compile_check_conftest "$CODE" "NV_GET_USER_PAGES_REMOTE_PRESENT" "" "functions"
+        ;;
     esac
 }

diff --git a/kernel/Makefile.orig b/kernel/Makefile
index 438d487..c52a36c 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -139,7 +139,8 @@ COMPILE_TESTS = \
 	drm_pci_set_busid \
 	write_cr4 \
 	for_each_online_node \
-	node_end_pfn
+	node_end_pfn \
+	get_user_pages_remote

 #
 # CFLAGS dependent on the type of builds (e.g. single/muliple module, debug)
diff --git a/kernel/uvm/nvidia_uvm_lite.c.orig b/kernel/uvm/nvidia_uvm_lite.c
index 442a0a8..695f092 100644
--- a/kernel/uvm/nvidia_uvm_lite.c
+++ b/kernel/uvm/nvidia_uvm_lite.c
@@ -785,7 +785,7 @@ int _fault_common(struct vm_area_struct *vma, unsigned long vaddr,
         // a reference so that the fault handling logic is correct:
         //
         get_page(pTracking->uvmPage);
-        retValue = VM_FAULT_MINOR;
+        retValue = 0;
     }

     pRecord->isMapped = NV_TRUE;


code:
# Blacklist by default since nvidia* modules have the same aliases
blacklist nvidia340

# Fail if nouveau loaded
install nvidia340 if /bin/grep -qw "^nouveau" /proc/modules; then /bin/false; else /sbin/modprobe -i nvidia340 $CMDLINE_OPTS; fi

# Load the right module when requested with the name "nvidia"
install nvidia M=$(/bin/readlink /etc/alternatives/libGL | /usr/bin/cut -d/ -f4 | /bin/grep nvidia) && /sbin/modprobe $M $CMDLINE_OPTS


code:
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pisilinux.org/projeler/pisi/pisi-spec.dtd">
<PISI>
    <Source>
        <Name>module-nvidia340</Name>
        <Homepage>http://www.nvidia.com</Homepage>
        <Packager>
            <Name>Pisi Linux Community</Name>
            <Email>admins@pisilinux.org</Email>
        </Packager>
        <License>NVIDIA</License>
        NVIDIA drivers for GeForce 6xxx and newer GPUs
        <Description>NVIDIA graphics drivers provide optimized 2D/3D performance.</Description>
        <Archive sha1sum="17e654b2cf7732dfe7a8047f5ab753b43d968d28" type="binary">http://http.download.nvidia.com/XFree86/Linux-x86/340.104/NVIDIA-Linux-x86-340.104.run</Archive>
        <Archive sha1sum="90ce4ba9c40c64823d7d545ddc2789817c706963" type="binary">http://http.download.nvidia.com/XFree86/Linux-x86_64/340.104/NVIDIA-Linux-x86_64-340.104.run</Archive>
        <AdditionalFiles>

        </AdditionalFiles>
        <BuildDependencies>
            <Dependency version="4.9.75">kernel-module-headers</Dependency>
        </BuildDependencies>
    </Source>

    <Package>
        <Name>module-nvidia340</Name>
        <IsA>driver</IsA>
        Kernel module for NVIDIA driver 340.xx releases
        <RuntimeDependencies>
            <Dependency version="4.9.75">kernel</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="library" permanent="true">/lib/modules</Path>
        </Files>
        <BuildFlags>
            <Flag>noDelta</Flag>
        </BuildFlags>
    </Package>

    <Package>
        <Name>xorg-video-nvidia340</Name>
        <IsA>driver</IsA>
        <PartOf>x11.driver</PartOf>
        <RuntimeDependencies>
            <Dependency>libXext</Dependency>
            <Dependency>xorg-server</Dependency>
            <Dependency version="current">module-nvidia340</Dependency>
            <Dependency>libX11</Dependency>
        </RuntimeDependencies>
        <Conflicts>
            <Package>xorg-video-nvidia-current</Package>
            <Package>xorg-video-nvidia304</Package>
        </Conflicts>
        <Files>
            <Path fileType="data">/etc/OpenCL</Path>
            <Path fileType="executable">/usr/bin</Path>
            <Path fileType="library">/usr/lib</Path>
            <Path fileType="data">/usr/share</Path>
            <Path fileType="doc">/usr/share/doc</Path>
            <Path fileType="man">/usr/share/man</Path>
        </Files>
        <Provides>
            <COMAR script="package.py">System.Package</COMAR>
        </Provides>
        <BuildFlags>
            <Flag>noDelta</Flag>
        </BuildFlags>
    </Package>

    <Package>
        <Name>xorg-video-nvidia340-32bit</Name>
        <PartOf>emul32</PartOf>
        32-bit shared libraries for xorg-video-nvidia340
        <BuildType>emul32</BuildType>
        <BuildDependencies>
            <Dependency>libvdpau-32bit</Dependency>
        </BuildDependencies>
        <RuntimeDependencies>
            <Dependency>zlib-32bit</Dependency>
            <Dependency>libX11-32bit</Dependency>
            <Dependency>libXext-32bit</Dependency>
            <Dependency release="current">xorg-video-nvidia340</Dependency>
        </RuntimeDependencies>
        <Conflicts>
            <Package>xorg-video-nvidia-current-32bit</Package>
            <Package>xorg-video-nvidia304-32bit</Package>
        </Conflicts>
        <Files>
            <Path fileType="library">/usr/lib32</Path>
            <Path fileType="library">/usr/share/nvidia-current/32bit-ld.so.conf</Path>
        </Files>
        <Provides>
            <COMAR script="package-emul32.py">System.Package</COMAR>
        </Provides>
        <BuildFlags>
            <Flag>noDelta</Flag>
        </BuildFlags>
    </Package>

    <History>
        <Update release="15">
            <Date>2018-01-06</Date>
            <Version>340.104</Version>
            <Comment>Rebuild for new kernel.</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>muscnsl@gmail.com</Email>
        </Update>
        <Update release="14">
            <Date>2017-12-20</Date>
            <Version>340.104</Version>
            <Comment>Rebuild for new kernel.</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>muscnsl@gmail.com</Email>
        </Update>
        <Update release="13">
            <Date>2017-12-06</Date>
            <Version>340.104</Version>
            <Comment>Version bump</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>muscnsl@gmail.com</Email>
        </Update>
        <Update release="12">
            <Date>2017-11-24</Date>
            <Version>340.102</Version>
            <Comment>Rebuild</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>muscnsl@gmail.com</Email>
        </Update>
        <Update release="11">
            <Date>2017-08-22</Date>
            <Version>340.102</Version>
            <Comment>Rebuild.</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="10">
            <Date>2017-07-07</Date>
            <Version>340.102</Version>
            <Comment>Version bump.</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="9">
            <Date>2017-03-11</Date>
            <Version>340.101</Version>
            <Comment>Rebuild.</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="8">
            <Date>2017-01-31</Date>
            <Version>340.101</Version>
            <Comment>Version bump</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="7">
            <Date>2016-12-11</Date>
            <Version>340.98</Version>
            <Comment>Rebuild for kernel 4.8.13</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="6">
            <Date>2016-11-05</Date>
            <Version>340.98</Version>
            <Comment>Version bump</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="5">
            <Date>2016-08-28</Date>
            <Version>340.96</Version>
            <Comment>Rebuild for kernel 4.7.2</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="4">
            <Date>2016-08-06</Date>
            <Version>340.96</Version>
            <Comment>Rebuild for kernel 4.7.0</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="3">
            <Date>2016-07-17</Date>
            <Version>340.96</Version>
            <Comment>Rebuild for new kernel</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="2">
            <Date>2016-04-30</Date>
            <Version>340.96</Version>
            <Comment>Rebuild for new kernel</Comment>
            <Name>Ertuğrul Erata</Name>
            <Email>ertugrulerata@gmail.com</Email>
        </Update>
        <Update release="1">
            <Date>2016-03-06</Date>
            <Version>340.96</Version>
            <Comment>First release</Comment>
            <Name>Ertuğrul Erata</Name>
            <Email>ertugrulerata@gmail.com</Email>
        </Update>
    </History>
</PISI>


code:
<PISI>
    <Name>kernel.tools</Name>
</PISI>


code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/licenses/gpl.txt

from pisi.actionsapi import autotools
from pisi.actionsapi import pisitools
from pisi.actionsapi import shelltools
from pisi.actionsapi import get

shelltools.export("PYTHONDONTWRITEBYTECODE", "1")

def build():
    shelltools.cd("tools/perf")
    autotools.make("JOBS=5 WERROR=0 perf HAVE_CPLUS_DEMANGLE=1")

def install():
    shelltools.cd("tools/perf")
    # Build and install the new 'perf' tool
    #pisitools.insinto("/usr/bin", "tools/perf/perf", "perf.%s-%s" % (get.srcNAME(), get.srcVERSION()))
    autotools.install("JOBS=5 WERROR=0 perf HAVE_CPLUS_DEMANGLE=1")

    pisitools.domove("/usr/etc/bash_completion.d/perf", "/etc/bash_completion.d")
    pisitools.removeDir("/usr/etc")

    #pisitools.domove("/usr/lib64/libperf-gtk.so", "/usr/lib/")
    pisitools.removeDir("/usr/lib64")


code:
diff -Nuar linux-4.9.orig/fs/aufs/posix_acl.c linux-4.9/fs/aufs/posix_acl.c
--- linux-4.9.orig/fs/aufs/posix_acl.c	2017-04-09 09:33:00.155052337 +0300
+++ linux-4.9/fs/aufs/posix_acl.c	2017-04-09 09:34:03.760053849 +0300
@@ -1,5 +1,18 @@
 /*
  * Copyright (C) 2014-2016 Junjiro R. Okajima
+ *
+ * This program, aufs is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */

 /*
@@ -36,6 +49,8 @@

 	/* always topmost only */
 	acl = get_acl(h_inode, type);
+	if (!IS_ERR_OR_NULL(acl))
+		set_cached_acl(inode, type, acl);

 out:
 	ii_read_unlock(inode);
@@ -77,8 +92,10 @@
 	ssz = au_sxattr(dentry, inode, &arg);
 	dput(dentry);
 	err = ssz;
-	if (ssz >= 0)
+	if (ssz >= 0) {
 		err = 0;
+		set_cached_acl(inode, type, acl);
+	}

 out:
 	return err;
diff -Nuar linux-4.9.orig/fs/aufs/xattr.c linux-4.9/fs/aufs/xattr.c
--- linux-4.9.orig/fs/aufs/xattr.c	2017-04-09 09:33:00.160052337 +0300
+++ linux-4.9/fs/aufs/xattr.c	2017-04-09 09:34:08.757053967 +0300
@@ -1,11 +1,26 @@
 /*
  * Copyright (C) 2014-2016 Junjiro R. Okajima
+ *
+ * This program, aufs is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */

 /*
  * handling xattr functions
  */

+#include <linux/fs.h>
+#include <linux/posix_acl_xattr.h>
 #include <linux/xattr.h>
 #include "aufs.h"

@@ -309,7 +324,11 @@
 };

 static const struct xattr_handler *au_xattr_handlers[] = {
-	&au_xattr_handler,
+#ifdef CONFIG_FS_POSIX_ACL
+	&posix_acl_access_xattr_handler,
+	&posix_acl_default_xattr_handler,
+#endif
+	&au_xattr_handler, /* must be last */
 	NULL
 };


code:
 3rdparty/mkbuild.pl        |   92 +++++++++++++++++++++++++++++++++++++++++++++
 Documentation/3rdparty.txt |   76 +++++++++++++++++++++++++++++++++++++
 2 files changed, 168 insertions(+)

diff -Nurp linux-2.6.37/3rdparty/mkbuild.pl linux-2.6.37.3rdparty/3rdparty/mkbuild.pl
--- linux-2.6.37/3rdparty/mkbuild.pl	1970-01-01 02:00:00.000000000 +0200
+++ linux-2.6.37.3rdparty/3rdparty/mkbuild.pl	2004-04-23 14:59:03.000000000 +0300
@@ -0,0 +1,92 @@
+#!/usr/bin/perl -w
+#
+# Version 1.0
+#
+# Copyright 2001 Jeff Garzik <jgarzik@mandrakesoft.com>
+# Copyright 2002 Juan Quintela <quintela@mandrakesoft.com>
+# Copyright 2003 Nicolas Planel <nplanel@mandrakesoft.com>
+#
+# This software may be used and distributed according to the terms
+# of the GNU General Public License, incorporated herein by reference.
+#
+#
+# Run "mkbuild.pl"
+#
+# This program generates the following files
+#	Makefile
+#	Makefile.drivers
+#	Config.in
+# using the information in the subdirs of this directory.
+#
+# subdirs need to have:
+# 	a Config.in file
+#	a Makefile with a O_TARGET/L_TARGET targets
+#	The config.in should set a CONFIG_<module_dir_name> to m/y.
+
+use strict;
+
+opendir(THISDIR, ".");
+# get dirs without . and .. garbage
+my (@modules) = grep(!/\.\.?$/,grep(-d, readdir(THISDIR)));
+closedir(THISDIR);
+
+generate_kconfig(@modules);
+generate_makefile(@modules);
+exit(0);
+
+##########################################################################
+
+sub generate_makefile {
+    my (@modules) = @_;
+
+    local *F;
+    open F, "> Makefile" or die "Cannot create new Makefile: $!\n";
+    print F <<'EOM';
+#
+# THIS IS AN AUTOMATICALLY GENERATED FILE.  DO NOT EDIT.
+#
+
+EOM
+    printf F "obj- := 3rdparty.o  # Dummy rule to force built-in.o to be made\n";
+    printf F "obj-\$(%s) += %s\n", to_CONFIG($_), $_ . '/' foreach @modules;
+}
+
+sub generate_kconfig {
+    my (@modules) = @_;
+
+    local *F;
+    open F, "> Kconfig" or die "Cannot create Kconfig: $!\n";
+    print F <<"EOM";
+#
+# THIS IS AN AUTOMATICALLY GENERATED FILE.  DO NOT EDIT.
+#
+
+menu "Unofficial 3rd party kernel additions"
+
+EOM
+
+    foreach (@modules) {
+	die "No Kconfig in $_.\n" if ! -r "$_/Kconfig";
+	print F "source 3rdparty/$_/Kconfig\n";
+    }
+    print F "\n\nendmenu\n";
+}
+
+sub to_CONFIG {
+    local $_ = $_[0];
+    tr/a-z/A-Z/;
+    s/[\-\. ]/_/g;
+    "CONFIG_$_";
+}
+
+sub find_target {
+	my ($module_dir) = @_;
+
+	local *F;
+	open(F, "$module_dir/Makefile") or die "$module_dir/Makefile: $!\n";
+	while (<F>) {
+		chomp;
+		return $1 if (/[LO]_TARGET.*:=\s+(\S+)/);
+	}
+}
+
diff -Nurp linux-2.6.37/Documentation/3rdparty.txt linux-2.6.37.3rdparty/Documentation/3rdparty.txt
--- linux-2.6.37/Documentation/3rdparty.txt	1970-01-01 02:00:00.000000000 +0200
+++ linux-2.6.37.3rdparty/Documentation/3rdparty.txt	2003-11-22 01:07:26.000000000 +0200
@@ -0,0 +1,76 @@
+
+Third-Party Kernel Source Module Support, or
+an easy way to add modules to your kernel build.
+
+
+
+Vendors quite often add additional drivers and features to the kernel
+which require nothing more than modifying Kconfig, Makefile, and
+adding one or more files to a sub-directory.  As a single discrete task,
+this is not a problem.  However, using patches to add modules to the
+kernel very often results in patch conflicts, resulting in needless time
+wastage as developers regenerate an otherwise working kernel patch.
+
+This is designed as a solution to these problems.  It is NOT designed as
+a replacement for the kernel build system, but merely as a tool for
+vendors and system administrators to ease the pain of patch management.
+
+The key feature of this system is the distinct lack of patches.  Drivers
+are installed via unpacking a tarball.
+
+
+
+Adding a directory to the build (usually from a tarball)
+--------------------------------------------------------
+If a directory exists inside the 3rdparty sub-directory that contains a
+proper Makefile, it can be added to the build.  It also needs a
+Kconfig file.
+
+	cd /usr/src/linux-2.4.3/3rdparty
+	bzcat /tmp/my-driver2.tar.bz2 | tar xf - # creates "my2" dir
+
+
+Limitations
+-----------
+There are some limitations to this system.  This system is only
+designed to support a very common case.  If you find yourself running
+into limitations (kernel build experts can spot them right off),
+then you should probably be patching the kernel instead of using
+mkbuild.pl for that particular module.
+
+FIXME: actually list the limitations
+
+
+
+Other notes
+-----------
+Link order is controlled by the order of mkbuild.pl executions.
+
+"make mrproper" will erase Makefile.meta, and empty Kconfig, Makefile,
+and Makefile.drivers.
+
+IMPORTANT NOTE: Because this feature modifies the kernel's makefiles and
+configuration system, you MUST complete all mkbuild.pl runs before
+running any "make" command.
+
+Building in the 3rdparty dir
+----------------------------
+
+If you use modules that:
+	- are contained in one subdir with the name of the module
+	- has a Makefile
+	- has a Kconfig file
+
+The system calls the ./mkbuild.pl script.  It will search for
+subdirectories, and will try to build each of them as a module.
+Things to note:
+
+       The dependencies will be done in a module called:
+
+       3rdparty/<module_dir_name>/<module_name>
+
+depending of CONFIG_<module_name_in_uppercase>.
+
+<module_name> is the value of O_TARGET/L_TARGET.
+
+


code:
Include 3rdparty directory into the main build-system.

Original author is unknown.
(Was either Juan Quintela or Jeff Garzik)

Signed-off-by: Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br>
Signed-off-by: Herton Ronaldo Krzesinski <herton@mandriva.com.br>
Signed-off-by: Thomas Backlund <tmb@mageia.org>

 Makefile                 |    2 +-
 arch/alpha/Kconfig       |    1 +
 arch/ia64/Kconfig        |    2 ++
 arch/mips/Kconfig        |    2 ++
 arch/powerpc/Kconfig     |    2 ++
 arch/sparc/Kconfig       |    2 ++
 arch/x86/Kconfig         |    2 ++
 scripts/kconfig/Makefile |   33 ++++++++++++++++++---------------
 8 files changed, 30 insertions(+), 16 deletions(-)

diff -Nurp linux-4.2.2/arch/alpha/Kconfig linux-4.2.2-3rd/arch/alpha/Kconfig
--- linux-4.2.2/arch/alpha/Kconfig	2015-08-30 21:34:09.000000000 +0300
+++ linux-4.2.2-3rd/arch/alpha/Kconfig	2015-09-29 23:02:44.024347272 +0300
@@ -750,3 +750,4 @@ source "crypto/Kconfig"

 source "lib/Kconfig"

+source "3rdparty/Kconfig"
diff -Nurp linux-4.2.2/arch/ia64/Kconfig linux-4.2.2-3rd/arch/ia64/Kconfig
--- linux-4.2.2/arch/ia64/Kconfig	2015-08-30 21:34:09.000000000 +0300
+++ linux-4.2.2-3rd/arch/ia64/Kconfig	2015-09-29 23:02:44.024347272 +0300
@@ -613,3 +613,5 @@ source "lib/Kconfig"

 config IOMMU_HELPER
 	def_bool (IA64_HP_ZX1 || IA64_HP_ZX1_SWIOTLB || IA64_GENERIC || SWIOTLB)
+
+source "3rdparty/Kconfig"
diff -Nurp linux-4.2.2/arch/mips/Kconfig linux-4.2.2-3rd/arch/mips/Kconfig
--- linux-4.2.2/arch/mips/Kconfig	2015-08-30 21:34:09.000000000 +0300
+++ linux-4.2.2-3rd/arch/mips/Kconfig	2015-09-29 23:02:44.024347272 +0300
@@ -2944,3 +2944,5 @@ source "crypto/Kconfig"
 source "lib/Kconfig"

 source "arch/mips/kvm/Kconfig"
+
+source "3rdparty/Kconfig"
diff -Nurp linux-4.2.2/arch/powerpc/Kconfig linux-4.2.2-3rd/arch/powerpc/Kconfig
--- linux-4.2.2/arch/powerpc/Kconfig	2015-08-30 21:34:09.000000000 +0300
+++ linux-4.2.2-3rd/arch/powerpc/Kconfig	2015-09-29 23:02:44.025347276 +0300
@@ -1112,3 +1112,5 @@ config PPC_LIB_RHEAP
 source "arch/powerpc/kvm/Kconfig"

 source "kernel/livepatch/Kconfig"
+
+source "3rdparty/Kconfig"
diff -Nurp linux-4.2.2/arch/sparc/Kconfig linux-4.2.2-3rd/arch/sparc/Kconfig
--- linux-4.2.2/arch/sparc/Kconfig	2015-08-30 21:34:09.000000000 +0300
+++ linux-4.2.2-3rd/arch/sparc/Kconfig	2015-09-29 23:02:44.025347276 +0300
@@ -569,3 +569,5 @@ source "security/Kconfig"
 source "crypto/Kconfig"

 source "lib/Kconfig"
+
+source "3rdparty/Kconfig"
diff -Nurp linux-4.2.2/arch/x86/Kconfig linux-4.2.2-3rd/arch/x86/Kconfig
--- linux-4.2.2/arch/x86/Kconfig	2015-08-30 21:34:09.000000000 +0300
+++ linux-4.2.2-3rd/arch/x86/Kconfig	2015-09-29 23:02:44.025347276 +0300
@@ -2601,3 +2601,5 @@ source "crypto/Kconfig"
 source "arch/x86/kvm/Kconfig"

 source "lib/Kconfig"
+
+source "3rdparty/Kconfig"
diff -Nurp linux-4.2.2/Makefile linux-4.2.2-3rd/Makefile
--- linux-4.2.2/Makefile	2015-09-29 22:13:44.743650710 +0300
+++ linux-4.2.2-3rd/Makefile	2015-09-29 23:02:44.026347280 +0300
@@ -546,7 +546,7 @@ scripts: scripts_basic include/config/au

 # Objects we will link into vmlinux / subdirs we need to visit
 init-y		:= init/
-drivers-y	:= drivers/ sound/ firmware/
+drivers-y	:= drivers/ sound/ firmware/ 3rdparty/
 net-y		:= net/
 libs-y		:= lib/
 core-y		:= usr/
diff -Nurp linux-4.9/scripts/kconfig/Makefile linux-4.9-3rd/scripts/kconfig/Makefile
--- linux-4.9/scripts/kconfig/Makefile
+++ linux-4.9-3rd/scripts/kconfig/Makefile
@@ -18,28 +18,28 @@ endif
 # We need this, in case the user has it in its environment
 unexport CONFIG_

-xconfig: $(obj)/qconf
+xconfig: $(obj)/qconf 3rdparty/Makefile
 	$< $(silent) $(Kconfig)

-gconfig: $(obj)/gconf
+gconfig: $(obj)/gconf 3rdparty/Makefile
 	$< $(silent) $(Kconfig)

-menuconfig: $(obj)/mconf
+menuconfig: $(obj)/mconf 3rdparty/Makefile
 	$< $(silent) $(Kconfig)

-config: $(obj)/conf
+config: $(obj)/conf 3rdparty/Makefile
 	$< $(silent) --oldaskconfig $(Kconfig)

-nconfig: $(obj)/nconf
+nconfig: $(obj)/nconf 3rdparty/Makefile
 	$< $(silent) $(Kconfig)

-silentoldconfig: $(obj)/conf
+silentoldconfig: $(obj)/conf 3rdparty/Makefile
 	$(Q)mkdir -p include/config include/generated
 	$(Q)test -e include/generated/autoksyms.h || \
 	    touch   include/generated/autoksyms.h
 	$< $(silent) --$@ $(Kconfig)

-localyesconfig localmodconfig: $(obj)/streamline_config.pl $(obj)/conf
+localyesconfig localmodconfig: $(obj)/streamline_config.pl $(obj)/conf 3rdparty/Makefile
 	$(Q)mkdir -p include/config include/generated
 	$(Q)perl $< --$@ $(srctree) $(Kconfig) > .tmp.config
 	$(Q)if [ -f .config ]; then 					\
@@ -82,7 +82,7 @@ simple-targets := oldconfig allnoconfig
 	alldefconfig randconfig listnewconfig olddefconfig
 PHONY += $(simple-targets)

-$(simple-targets): $(obj)/conf
+$(simple-targets): $(obj)/conf 3rdparty/Makefile
 	$< $(silent) --$@ $(Kconfig)

 PHONY += oldnoconfig savedefconfig defconfig
@@ -90,12 +90,12 @@ PHONY += oldnoconfig savedefconfig defco
 # oldnoconfig is an alias of olddefconfig, because people already are dependent
 # on its behavior (sets new symbols to their default value but not 'n') with the
 # counter-intuitive name.
-oldnoconfig: olddefconfig
+oldnoconfig: olddefconfig 3rdparty/Makefile

-savedefconfig: $(obj)/conf
+savedefconfig: $(obj)/conf 3rdparty/Makefile
 	$< $(silent) --$@=defconfig $(Kconfig)

-defconfig: $(obj)/conf
+defconfig: $(obj)/conf 3rdparty/Makefile
 ifeq ($(KBUILD_DEFCONFIG),)
 	$< $(silent) --defconfig $(Kconfig)
 else
@@ -108,26 +108,26 @@ else
 endif
 endif

-%_defconfig: $(obj)/conf
+%_defconfig: $(obj)/conf 3rdparty/Makefile
 	$(Q)$< $(silent) --defconfig=arch/$(SRCARCH)/configs/$@ $(Kconfig)

 configfiles=$(wildcard $(srctree)/kernel/configs/$@ $(srctree)/arch/$(SRCARCH)/configs/$@)

-%.config: $(obj)/conf
+%.config: $(obj)/conf 3rdparty/Makefile
 	$(if $(call configfiles),, $(error No configuration exists for this target on this architecture))
 	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/kconfig/merge_config.sh -m .config $(configfiles)
 	+$(Q)yes "" | $(MAKE) -f $(srctree)/Makefile oldconfig

 PHONY += kvmconfig
-kvmconfig: kvm_guest.config
+kvmconfig: kvm_guest.config 3rdparty/Makefile
 	@:

 PHONY += xenconfig
-xenconfig: xen.config
+xenconfig: xen.config 3rdparty/Makefile
 	@:

 PHONY += tinyconfig
-tinyconfig:
+tinyconfig:
 	$(Q)$(MAKE) -f $(srctree)/Makefile allnoconfig tiny.config

 # Help text used by make help
@@ -190,6 +190,9 @@ gconf-objs	:= gconf.o zconf.tab.o

 hostprogs-y := conf nconf mconf kxgettext qconf gconf

+3rdparty/Makefile:
+	pushd $(srctree)/3rdparty ; $(PERL) ./mkbuild.pl ; popd
+
 clean-files	:= qconf.moc .tmp_qtcheck .tmp_gtkcheck
 clean-files	+= zconf.tab.c zconf.lex.c zconf.hash.c gconf.glade.h
 clean-files     += config.pot linux.pot