From 76c05e2ee6e9d8c3a85f404a8cf4b907f92c220a Mon Sep 17 00:00:00 2001
From: Britney Fransen <brfransen@gmail.com>
Date: Wed, 22 Nov 2017 17:47:24 +0000
Subject: nvidia-304xx & nvidia-304xx-utils: update to 304.137

---
 abs/core/nvidia-304xx-utils/PKGBUILD          |  10 +--
 abs/core/nvidia-304xx/PKGBUILD                |  70 ++++++++---------
 abs/core/nvidia-304xx/drm-driver-legacy.patch |  20 -----
 abs/core/nvidia-304xx/kernel-4.14.patch       |  29 +++++++
 abs/core/nvidia-304xx/kernel_4.10.patch       | 105 --------------------------
 abs/core/nvidia-304xx/nvidia-304xx.install    |  13 ----
 6 files changed, 64 insertions(+), 183 deletions(-)
 delete mode 100644 abs/core/nvidia-304xx/drm-driver-legacy.patch
 create mode 100644 abs/core/nvidia-304xx/kernel-4.14.patch
 delete mode 100644 abs/core/nvidia-304xx/kernel_4.10.patch
 delete mode 100644 abs/core/nvidia-304xx/nvidia-304xx.install

diff --git a/abs/core/nvidia-304xx-utils/PKGBUILD b/abs/core/nvidia-304xx-utils/PKGBUILD
index 7f2c108..699a06d 100644
--- a/abs/core/nvidia-304xx-utils/PKGBUILD
+++ b/abs/core/nvidia-304xx-utils/PKGBUILD
@@ -4,9 +4,9 @@
 
 pkgbase=nvidia-304xx-utils
 pkgname=('nvidia-304xx-utils' 'opencl-nvidia-304xx')
-pkgver=304.135
-pkgrel=6
-arch=('i686' 'x86_64')
+pkgver=304.137
+pkgrel=1
+arch=('x86_64')
 url="http://www.nvidia.com/"
 license=('custom')
 makedepends=('zlib')
@@ -15,8 +15,8 @@ source=(nvidia-drm-outputclass.conf)
 source_i686=("http://us.download.nvidia.com/XFree86/Linux-x86/${pkgver}/NVIDIA-Linux-x86-${pkgver}.run")
 source_x86_64=("http://us.download.nvidia.com/XFree86/Linux-x86_64/${pkgver}/NVIDIA-Linux-x86_64-${pkgver}-no-compat32.run")
 md5sums=('a433deeb5f9cc661e537f42bde2f1df7')
-md5sums_i686=('0e2082ae8490b135eb306befe6db56e1')
-md5sums_x86_64=('8ee9bd0b020508bca9953181811422fa')
+md5sums_i686=('133098e70581f6b81c481338cc20f100')
+md5sums_x86_64=('485506ee6a7c54780488dacddf1d56b1')
 
 if [ "$CARCH" = "i686" ]; then
   _arch='x86'
diff --git a/abs/core/nvidia-304xx/PKGBUILD b/abs/core/nvidia-304xx/PKGBUILD
index 62d7950..cb0b9e9 100644
--- a/abs/core/nvidia-304xx/PKGBUILD
+++ b/abs/core/nvidia-304xx/PKGBUILD
@@ -4,78 +4,68 @@
 
 pkgbase=nvidia-304xx
 pkgname=(nvidia-304xx nvidia-304xx-dkms)
-pkgver=304.135
+pkgver=304.137
 _extramodules=extramodules-4.9-ARCH
-pkgrel=6
-arch=('i686' 'x86_64')
+pkgrel=8
+pkgdesc="NVIDIA drivers for linux, 304xx legacy branch"
+arch=('x86_64')
 url="http://www.nvidia.com/"
-makedepends=('linux' 'linux-headers>=4.9' 'linux-headers<4.10')
+makedepends=("nvidia-304xx-utils=${pkgver}" 'linux' 'linux-headers>=4.9' 'linux-headers<4.10')
 conflicts=('nvidia')
 license=('custom')
 options=('!strip')
-source=('disable-mtrr.patch'
-        'drm-driver-legacy.patch'
-        'kernel_4.10.patch'
-	'kernel_4.11.patch')
-source_i686+=("http://us.download.nvidia.com/XFree86/Linux-x86/${pkgver}/NVIDIA-Linux-x86-${pkgver}.run")
-source_x86_64+=("http://us.download.nvidia.com/XFree86/Linux-x86_64/${pkgver}/NVIDIA-Linux-x86_64-${pkgver}-no-compat32.run")
-sha512sums=('54e8825e523f11706890e09e476498f3a30f75ce4e350ff2ff8a1e1c3af574d9ccfb8903543766b6863d94cdfbf46e68cd3d33380867dd976cafc8dd2dd78774'
-            'fa39dee5c9f1ea98286c87165f683ee194b2cb4056aa6b556e822b9ee760dcf3683ea001c3704e79b9ac9712314d7df5690dc7f68440cda7a96791f94425455d'
-            '68dabbf6ad889c46bd0c01ebb697b80f4aa526ef1cdc53de008343a243adefc6ce7f2778be7005f2d79f3d23c0a3ff69f67ecdb9f97c0feb0ec99405a0c1046a'
-            'da3d1698af8b97e8fc3b6d3c690925e0258f8b6ad26a24f8d32c04a5a82701655208021f9f5af0ce44cb397a7422e2776a05193204bc7e4ac2b98f6e173984ea')
-sha512sums_i686=('c2645cc9a6f23641d8b6da51e72e203980068c05e365fcc73b32322a6875ce95e81f4e0d893276e14e84e93464488539c16db6b3be04f5324cf7d7a12bb557f8')
-sha512sums_x86_64=('a5aa48baa75eb267bd193e59328aa5fbc15d41045bb7e97aa1b96b918b9e68a1c1bf95624d9d494336256e0af2c41e188d30fe91be4967084de3387f50d3805c')
+source=("http://us.download.nvidia.com/XFree86/Linux-x86_64/${pkgver}/NVIDIA-Linux-x86_64-${pkgver}-no-compat32.run"
+        'disable-mtrr.patch' 'kernel-4.14.patch')
+sha512sums=('4ab648647e4f3e2c352b2eab6454c264fe4728d8eb1264fafee2a4ab1a4ce59516abcf8490044d31e35309ea951e564cc217e13f7139a48bbf650a4238c5b87c'
+            '54e8825e523f11706890e09e476498f3a30f75ce4e350ff2ff8a1e1c3af574d9ccfb8903543766b6863d94cdfbf46e68cd3d33380867dd976cafc8dd2dd78774'
+            'ccaa40e085d985ec4280003e36dd06e60958ed1408867379fd21a68a18d48aa4be311bf9ad1e804f7a7245c90be98e919d2ec30f45d290f1cdb19c866bdb8a8d')
 
-[[ "$CARCH" = "i686" ]] && _pkg="NVIDIA-Linux-x86-${pkgver}"
-[[ "$CARCH" = "x86_64" ]] && _pkg="NVIDIA-Linux-x86_64-${pkgver}-no-compat32"
+_pkg="NVIDIA-Linux-x86_64-${pkgver}-no-compat32"
 
 prepare() {
-    cd "${srcdir}"
     sh "${_pkg}.run" --extract-only
     cd "${_pkg}"
     # patches here
-    patch -Np1 --no-backup-if-mismatch -i ../kernel_4.10.patch
-    patch -Np1 --no-backup-if-mismatch -i ../kernel_4.11.patch
+
+    patch -Np1 --no-backup-if-mismatch < "${srcdir}/kernel-4.14.patch"
 
     # FS#47092
-    #(cd kernel; patch -p1 --no-backup-if-mismatch -i "$srcdir"/disable-mtrr.patch)
-    (cd kernel; patch -p1 --no-backup-if-mismatch -i "$srcdir"/drm-driver-legacy.patch)
+    #patch -d kernel -Np1 --no-backup-if-mismatch < "${srcdir}/disable-mtrr.patch"
 
     cp -a kernel kernel-dkms
 }
 
 build() {
     _kernver="$(cat /usr/lib/modules/${_extramodules}/version)"
-    cd "${_pkg}/kernel"
+    cd "${_pkg}"/kernel
     make SYSSRC=/usr/lib/modules/"${_kernver}/build" module
 }
 
 package_nvidia-304xx() {
     pkgdesc="NVIDIA drivers for linux, 304xx legacy branch"
-    depends=('linux>=4.9' 'linux<4.10' 'libgl' "nvidia-304xx-utils=${pkgver}")
-	conflicts+=('nvidia-304xx-dkms')
-    install=nvidia-304xx.install
+    depends=('linux>=4.9' 'linux<4.10' "nvidia-304xx-utils=${pkgver}" 'libgl')
+
+    install -Dt "${pkgdir}/usr/lib/modules/${_extramodules}" -m644 \
+      "${srcdir}/${_pkg}/kernel"/nvidia.ko
 
-    install -D -m644 "${srcdir}/${_pkg}/kernel/nvidia.ko" \
-        "${pkgdir}/usr/lib/modules/${_extramodules}/nvidia.ko"
-    install -d -m755 "${pkgdir}/usr/lib/modprobe.d"
-    echo "blacklist nouveau" >> "${pkgdir}/usr/lib/modprobe.d/nvidia.conf"
-    sed -i -e "s/EXTRAMODULES='.*'/EXTRAMODULES='${_extramodules}'/" "${startdir}/${pkgname}.install"
-    gzip "${pkgdir}/usr/lib/modules/${_extramodules}/nvidia.ko"
+    find "${pkgdir}" -name '*.ko' -exec gzip -n {} +
 
-    # the license file is part of nvidia-304xx-utils - the module depends on it, so we don't ship it another time.
+    echo "blacklist nouveau" |
+      install -Dm644 /dev/stdin "${pkgdir}/usr/lib/modprobe.d/nvidia.conf"
 }
 
 package_nvidia-304xx-dkms() {
     pkgdesc="NVIDIA driver sources for linux, 304xx legacy branch"
-    depends=('dkms' "nvidia-304xx-utils=$pkgver")
+    depends=('dkms' "nvidia-304xx-utils=$pkgver" 'libgl')
     optdepends=('linux-headers: Build the module for Arch kernel'
                 'linux-lts-headers: Build the module for LTS Arch kernel')
-	conflicts+=('nvidia-304xx')
+    conflicts+=('nvidia-304xx')
 
     cd ${_pkg}
-	make -C kernel clean
-    install -dm 755 "${pkgdir}"/usr/{lib/modprobe.d,src}
-    cp -dr --no-preserve='ownership' kernel-dkms "${pkgdir}"/usr/src/nvidia-${pkgver}
-    echo 'blacklist nouveau' > "${pkgdir}"/usr/lib/modprobe.d/nvidia.conf
+
+    install -dm 755 "${pkgdir}"/usr/src
+    cp -dr --no-preserve='ownership' kernel-dkms "${pkgdir}/usr/src/nvidia-${pkgver}"
+
+    echo "blacklist nouveau" |
+      install -Dm644 /dev/stdin "${pkgdir}/usr/lib/modprobe.d/nvidia.conf"
 }
diff --git a/abs/core/nvidia-304xx/drm-driver-legacy.patch b/abs/core/nvidia-304xx/drm-driver-legacy.patch
deleted file mode 100644
index 32ac75c..0000000
--- a/abs/core/nvidia-304xx/drm-driver-legacy.patch
+++ /dev/null
@@ -1,20 +0,0 @@
-Author: Luca Boccassi <luca.boccassi@gmail.com>
-Description: Fix kernel module load on 4.9 and greater
- From kernel 4.9 and newer (commit fa5386459f06) non-modesetting drivers have
- to use the DRM flag DRIVER_LEGACY. Without this flag the kernel module does
- not load correctly.
-
---- a/nv-drm.c
-+++ b/nv-drm.c
-@@ -71,7 +71,11 @@
- };
- 
- static struct drm_driver nv_drm_driver = {
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0)
-     .driver_features = 0,
-+#else
-+    .driver_features = DRIVER_LEGACY,
-+#endif
-     .load = nv_drm_load,
-     .unload = nv_drm_unload,
-     .fops = &nv_drm_fops,
diff --git a/abs/core/nvidia-304xx/kernel-4.14.patch b/abs/core/nvidia-304xx/kernel-4.14.patch
new file mode 100644
index 0000000..a38adbd
--- /dev/null
+++ b/abs/core/nvidia-304xx/kernel-4.14.patch
@@ -0,0 +1,29 @@
+diff -u -r NVIDIA-Linux-x86_64-340.104-no-compat32/kernel/nv-drm.c NVIDIA-Linux-x86_64-340.104-no-compat32-kernel4.14/kernel/nv-drm.c
+--- NVIDIA-Linux-x86_64-340.104-no-compat32/kernel/nv-drm.c	2017-09-15 01:16:51.000000000 +0200
++++ NVIDIA-Linux-x86_64-340.104-no-compat32-kernel4.14/kernel/nv-drm.c	2017-11-19 00:51:45.006654148 +0100
+@@ -173,8 +173,12 @@
+ {
+     int ret = 0;
+ #if defined(NV_DRM_AVAILABLE)
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
++    ret = drm_legacy_pci_init(&nv_drm_driver, pci_driver);
++#else
+     ret = drm_pci_init(&nv_drm_driver, pci_driver);
+ #endif
++#endif
+     return ret;
+ }
+ 
+@@ -183,8 +187,12 @@
+ )
+ {
+ #if defined(NV_DRM_AVAILABLE)
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
++    drm_legacy_pci_exit(&nv_drm_driver, pci_driver);
++#else
+     drm_pci_exit(&nv_drm_driver, pci_driver);
+ #endif
++#endif
+ }
+ 
+ RM_STATUS NV_API_CALL nv_alloc_os_descriptor_handle(
diff --git a/abs/core/nvidia-304xx/kernel_4.10.patch b/abs/core/nvidia-304xx/kernel_4.10.patch
deleted file mode 100644
index 1e98740..0000000
--- a/abs/core/nvidia-304xx/kernel_4.10.patch
+++ /dev/null
@@ -1,105 +0,0 @@
-From d270372bf8abcf45409b30cdb33069280527b0ff Mon Sep 17 00:00:00 2001
-From: Alberto Milone <alberto.milone@canonical.com>
-Date: Wed, 15 Feb 2017 18:01:02 +0100
-Subject: [PATCH 1/1] Add support for Linux 4.10
-
----
- nv-linux.h |  5 +++++
- nv-pat.c   | 40 ++++++++++++++++++++++++++++++++++++++++
- 2 files changed, 45 insertions(+)
-
-diff --git a/kernel/nv-linux.h b/kernel/nv-linux.h
-index b46e71f..3081c06 100644
---- a/kernel/nv-linux.h
-+++ b/kernel/nv-linux.h
-@@ -1895,8 +1895,13 @@ static inline NvU64 nv_node_end_pfn(int nid)
- 
-         #else
- 
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
-                return get_user_pages_remote(tsk, mm, start, nr_pages, flags,
-                                             pages, vmas);
-+#else
-+               return get_user_pages_remote(tsk, mm, start, nr_pages, flags,
-+                                            pages, vmas, NULL);
-+#endif
- 
-         #endif
- 
-diff --git a/kernel/nv-pat.c b/kernel/nv-pat.c
-index e71e81c..d742789 100644
---- a/kernel/nv-pat.c
-+++ b/kernel/nv-pat.c
-@@ -203,6 +203,7 @@ void nv_disable_pat_support(void)
- }
- 
- #if defined(NV_ENABLE_PAT_SUPPORT) && defined(NV_ENABLE_HOTPLUG_CPU)
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
- static int
- nv_kern_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
- {
-@@ -234,6 +235,34 @@ static struct notifier_block nv_hotcpu_nfb = {
-     .notifier_call = nv_kern_cpu_callback,
-     .priority = 0
- };
-+#else
-+static int nvidia_cpu_online(unsigned int hcpu)
-+{
-+    unsigned int cpu = get_cpu();
-+    if (cpu == hcpu)
-+        nv_setup_pat_entries(NULL);
-+    else
-+        NV_SMP_CALL_FUNCTION(nv_setup_pat_entries, (void *)(long int)hcpu, 1);
-+
-+    put_cpu();
-+
-+    return 0;
-+}
-+
-+static int nvidia_cpu_down_prep(unsigned int hcpu)
-+{
-+    unsigned int cpu = get_cpu();
-+    if (cpu == hcpu)
-+        nv_restore_pat_entries(NULL);
-+    else
-+        NV_SMP_CALL_FUNCTION(nv_restore_pat_entries, (void *)(long int)hcpu, 1);
-+
-+    put_cpu();
-+
-+    return 0;
-+}
-+#endif
-+
- #endif
- 
- int nv_init_pat_support(nv_stack_t *sp)
-@@ -255,7 +284,14 @@ int nv_init_pat_support(nv_stack_t *sp)
- #if defined(NV_ENABLE_PAT_SUPPORT) && defined(NV_ENABLE_HOTPLUG_CPU)
-         if (nv_pat_mode == NV_PAT_MODE_BUILTIN)
-         {
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
-             if (register_hotcpu_notifier(&nv_hotcpu_nfb) != 0)
-+#else
-+            if (cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
-+                                  "gpu/nvidia:online",
-+                                  nvidia_cpu_online,
-+                                  nvidia_cpu_down_prep) != 0)
-+#endif
-             {
-                 nv_disable_pat_support();
-                 nv_printf(NV_DBG_ERRORS,
-@@ -280,7 +316,11 @@ void nv_teardown_pat_support(void)
-     {
-         nv_disable_pat_support();
- #if defined(NV_ENABLE_PAT_SUPPORT) && defined(NV_ENABLE_HOTPLUG_CPU)
-+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
-         unregister_hotcpu_notifier(&nv_hotcpu_nfb);
-+#else
-+        cpuhp_remove_state_nocalls(CPUHP_AP_ONLINE_DYN);
-+#endif
- #endif
-     }
- }
--- 
-2.7.4
-
diff --git a/abs/core/nvidia-304xx/nvidia-304xx.install b/abs/core/nvidia-304xx/nvidia-304xx.install
deleted file mode 100644
index 9858d46..0000000
--- a/abs/core/nvidia-304xx/nvidia-304xx.install
+++ /dev/null
@@ -1,13 +0,0 @@
-post_install() {
-    EXTRAMODULES='extramodules-4.9-ARCH'
-    depmod $(cat /usr/lib/modules/$EXTRAMODULES/version)
-    echo 'In order to use nvidia module, reboot the system.'
-}
-
-post_upgrade() {
-    post_install
-}
-
-post_remove() {
-    post_install
-}
-- 
cgit v0.12

