From 145f8ab6194c5d3325088dc7aa471c569d865c7f Mon Sep 17 00:00:00 2001
From: Britney Fransen <brfransen@gmail.com>
Date: Wed, 25 Apr 2018 20:35:12 +0000
Subject: nvidia & nvidia-utils: update to 390.48

---
 abs/core/nvidia-utils/PKGBUILD                    | 29 +++++++++-----------
 abs/core/nvidia-utils/nvidia-drm-outputclass.conf |  1 +
 abs/core/nvidia-utils/nvidia-utils.install        |  3 ---
 abs/core/nvidia-utils/nvidia-utils.sysusers       |  1 +
 abs/core/nvidia/PKGBUILD                          | 22 ++++++++++-----
 abs/core/nvidia/fix-abi.patch                     | 12 ---------
 abs/core/nvidia/kernel-4.16.patch                 | 33 +++++++++++++++++++++++
 7 files changed, 64 insertions(+), 37 deletions(-)
 create mode 100644 abs/core/nvidia-utils/nvidia-utils.sysusers
 delete mode 100644 abs/core/nvidia/fix-abi.patch
 create mode 100644 abs/core/nvidia/kernel-4.16.patch

diff --git a/abs/core/nvidia-utils/PKGBUILD b/abs/core/nvidia-utils/PKGBUILD
index 6a47564..9f45a98 100644
--- a/abs/core/nvidia-utils/PKGBUILD
+++ b/abs/core/nvidia-utils/PKGBUILD
@@ -5,28 +5,24 @@
 
 pkgbase=nvidia-utils
 pkgname=('nvidia-utils' 'opencl-nvidia')
-pkgver=387.22
+pkgver=390.48
 pkgrel=1
 arch=('x86_64')
 url="http://www.nvidia.com/"
 license=('custom')
 options=('!strip')
-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=('abdbb3c813e52148f7435308121e6a37')
-md5sums_x86_64=('b21f9bafb20409b337505c9b1d362c34')
-sha512sums=('cfea06a816ac4a8b728b1ec728d667cdcca604abb038e8b5313b434021caad06a586856b8b3a6c79f8c925629360f5a051ca3de5ab46a42af76b9d0615d2bbbe')
-sha512sums_i686=('865c5024957ade2c8361b198cbc6600f469612fe0336e3a0bfaf56e4240999367f2066837c0b354af4821ab2531d05eddf3f2a0957eacc2eca0dd7cada4929b4')
-sha512sums_x86_64=('f304f5b6d4c7e0ba5f19cf9f84ecab1c911e17d25193b527bf9c45200dda942011cb7632555e5351ed8fc212dcb59ea3d791b971073a8b09cb96af790e0c30ff')
-
-[[ "$CARCH" = "i686" ]] && _pkg="NVIDIA-Linux-x86-${pkgver}"
-[[ "$CARCH" = "x86_64" ]] && _pkg="NVIDIA-Linux-x86_64-${pkgver}-no-compat32"
+source=('nvidia-drm-outputclass.conf'
+        'nvidia-utils.sysusers'
+        "http://us.download.nvidia.com/XFree86/Linux-x86_64/${pkgver}/NVIDIA-Linux-x86_64-${pkgver}-no-compat32.run")
+sha512sums=('c49d246a519731bfab9d22afa5c2dd2d366db06d80182738b84881e93cd697c783f16ee04819275c05597bb063451a5d6102fbc562cd078d2a374533a23cea48'
+            '4b3ad73f5076ba90fe0b3a2e712ac9cde76f469cd8070280f960c3ce7dc502d1927f525ae18d008075c8f08ea432f7be0a6c3a7a6b49c361126dcf42f97ec499'
+            '40e1f991d931d5ea1eccda68bffa7bd872eb75c158c6a54f84b5a24274112b9a26e68caeecf6ca0e543edcec917a5ed717bd83281c4a86ac649d3c73f1386966')
+
+_pkg="NVIDIA-Linux-x86_64-${pkgver}-no-compat32"
 
 create_links() {
     # create soname links
-    for _lib in $(find "${pkgdir}" -name '*.so*' | grep -v 'xorg/'); do
+    find "$pkgdir" -type f -name '*.so*' ! -path '*xorg/*' -print0 | while read -d $'\0' _lib; do
         _soname=$(dirname "${_lib}")/$(readelf -d "${_lib}" | grep -Po 'SONAME.*: \[\K[^]]*' || true)
         _base=$(echo ${_soname} | sed -r 's/(.*).so.*/\1.so/')
         [[ -e "${_soname}" ]] || ln -s $(basename "${_lib}") "${_soname}"
@@ -162,8 +158,7 @@ package_nvidia-utils() {
     install -D -m644 nvidia-application-profiles-${pkgver}-rc "${pkgdir}/usr/share/nvidia/nvidia-application-profiles-${pkgver}-rc"
     install -D -m644 nvidia-application-profiles-${pkgver}-key-documentation "${pkgdir}/usr/share/nvidia/nvidia-application-profiles-${pkgver}-key-documentation"
 
-    install -D -m644 LICENSE "${pkgdir}/usr/share/licenses/nvidia/LICENSE"
-    ln -s nvidia "${pkgdir}/usr/share/licenses/nvidia-utils"
+    install -D -m644 LICENSE "${pkgdir}/usr/share/licenses/nvidia-utils/LICENSE"
     install -D -m644 README.txt "${pkgdir}/usr/share/doc/nvidia/README"
     install -D -m644 NVIDIA_Changelog "${pkgdir}/usr/share/doc/nvidia/NVIDIA_Changelog"
     cp -r html "${pkgdir}/usr/share/doc/nvidia/"
@@ -172,5 +167,7 @@ package_nvidia-utils() {
     # distro specific files must be installed in /usr/share/X11/xorg.conf.d
     install -D -m644 "${srcdir}/nvidia-drm-outputclass.conf" "${pkgdir}/usr/share/X11/xorg.conf.d/10-nvidia-drm-outputclass.conf"
 
+    install -Dm644 "${srcdir}/nvidia-utils.sysusers" "${pkgdir}/usr/lib/sysusers.d/$pkgname.conf"
+
     create_links
 }
diff --git a/abs/core/nvidia-utils/nvidia-drm-outputclass.conf b/abs/core/nvidia-utils/nvidia-drm-outputclass.conf
index b6003d3..dd2936c 100644
--- a/abs/core/nvidia-utils/nvidia-drm-outputclass.conf
+++ b/abs/core/nvidia-utils/nvidia-drm-outputclass.conf
@@ -11,4 +11,5 @@ Section "OutputClass"
     Option "AllowEmptyInitialConfiguration"
     Option "PrimaryGPU" "yes"
     ModulePath "/usr/lib/nvidia/xorg"
+    ModulePath "/usr/lib/xorg/modules"
 EndSection
diff --git a/abs/core/nvidia-utils/nvidia-utils.install b/abs/core/nvidia-utils/nvidia-utils.install
index 1955c64..47847c7 100644
--- a/abs/core/nvidia-utils/nvidia-utils.install
+++ b/abs/core/nvidia-utils/nvidia-utils.install
@@ -3,8 +3,5 @@ post_upgrade() {
 }
 
 post_install() {
-  getent group nvidia-persistenced &>/dev/null || groupadd -g 143 nvidia-persistenced
-  getent passwd nvidia-persistenced &>/dev/null || useradd -c 'NVIDIA Persistence Daemon' -u 143 -g nvidia-persistenced -d '/' -s /sbin/nologin nvidia-persistenced
-
   post_upgrade
 }
diff --git a/abs/core/nvidia-utils/nvidia-utils.sysusers b/abs/core/nvidia-utils/nvidia-utils.sysusers
new file mode 100644
index 0000000..71c0608
--- /dev/null
+++ b/abs/core/nvidia-utils/nvidia-utils.sysusers
@@ -0,0 +1 @@
+u nvidia-persistenced 143 'NVIDIA Persistence Daemon'
diff --git a/abs/core/nvidia/PKGBUILD b/abs/core/nvidia/PKGBUILD
index 21247b9..7d3fe9c 100644
--- a/abs/core/nvidia/PKGBUILD
+++ b/abs/core/nvidia/PKGBUILD
@@ -5,17 +5,19 @@
 
 pkgbase=nvidia
 pkgname=(nvidia nvidia-dkms)
-pkgver=387.22
+pkgver=390.48
 _extramodules=extramodules-4.9-ARCH
-pkgrel=9
+pkgrel=10
 pkgdesc="NVIDIA drivers for linux"
 arch=('x86_64')
 url="http://www.nvidia.com/"
 makedepends=('nvidia-libgl' "nvidia-utils=${pkgver}" 'linux' 'linux-headers>=4.9' 'linux-headers<4.10')
 license=('custom')
 options=('!strip')
-source=("http://us.download.nvidia.com/XFree86/Linux-x86_64/${pkgver}/NVIDIA-Linux-x86_64-${pkgver}-no-compat32.run")
-sha256sums=('2056b386f619ed096ee3c2267c495c6b00d1a2a4c933f0635befcf4e69c3856c')
+source=("http://us.download.nvidia.com/XFree86/Linux-x86_64/${pkgver}/NVIDIA-Linux-x86_64-${pkgver}-no-compat32.run"
+        kernel-4.16.patch)
+sha256sums=('2d4bf72801f101a85df6fd1464021380ad51f5a30df05dadaf1fb546a175a441'
+            '622ac792ec200b2239cb663c0010392118b78c9904973d82cd261165c16d6385')
 
 _pkg="NVIDIA-Linux-x86_64-${pkgver}-no-compat32"
 
@@ -23,6 +25,10 @@ prepare() {
     sh "${_pkg}.run" --extract-only
     cd "${_pkg}"
 
+    # Restore phys_to_dma support (still needed for 396.18)
+    # https://bugs.archlinux.org/task/58074
+    patch -Np1 -i ../kernel-4.16.patch
+
     cp -a kernel kernel-dkms
     cd kernel-dkms
     sed -i "s/__VERSION_STRING/${pkgver}/" dkms.conf
@@ -58,7 +64,9 @@ package_nvidia() {
     find "${pkgdir}" -name '*.ko' -exec gzip -n {} +
 
     echo "blacklist nouveau" |
-      install -Dm644 /dev/stdin "${pkgdir}/usr/lib/modprobe.d/nvidia.conf"
+        install -Dm644 /dev/stdin "${pkgdir}/usr/lib/modprobe.d/${pkgname}.conf"
+
+    install -Dt "${pkgdir}/usr/share/licenses/${pkgname}" -m644 "${srcdir}/${_pkg}/LICENSE"
 }
 
 package_nvidia-dkms() {
@@ -74,5 +82,7 @@ package_nvidia-dkms() {
     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"
+        install -Dm644 /dev/stdin "${pkgdir}/usr/lib/modprobe.d/${pkgname}.conf"
+
+    install -Dt "${pkgdir}/usr/share/licenses/${pkgname}" -m644 "${srcdir}/${_pkg}/LICENSE"
 }
diff --git a/abs/core/nvidia/fix-abi.patch b/abs/core/nvidia/fix-abi.patch
deleted file mode 100644
index 5a3f8df..0000000
--- a/abs/core/nvidia/fix-abi.patch
+++ /dev/null
@@ -1,12 +0,0 @@
-diff -u -r kernel/nvidia-drm/nvidia-drm-fence.c kernel-patched/nvidia-drm/nvidia-drm-fence.c
---- kernel/nvidia-drm/nvidia-drm-fence.c	2016-08-09 01:43:19.000000000 +0200
-+++ kernel-patched/nvidia-drm/nvidia-drm-fence.c	2016-08-25 14:31:34.419655564 +0200
-@@ -325,7 +325,7 @@
-     struct nvidia_drm_gem_object *nv_gem;
- };
- 
--static void nvidia_drm_gem_prime_soft_fence_event
-+static void NVKMS_KAPI_CALL nvidia_drm_gem_prime_soft_fence_event
- (
-     void *dataPtr,
-     NvU32 dataU32
diff --git a/abs/core/nvidia/kernel-4.16.patch b/abs/core/nvidia/kernel-4.16.patch
new file mode 100644
index 0000000..6717281
--- /dev/null
+++ b/abs/core/nvidia/kernel-4.16.patch
@@ -0,0 +1,33 @@
+diff --git a/kernel/common/inc/nv-linux.h b/kernel/common/inc/nv-linux.h
+index 10fc418..22ef968 100644
+--- a/kernel/common/inc/nv-linux.h
++++ b/kernel/common/inc/nv-linux.h
+@@ -175,7 +175,11 @@ static inline uid_t __kuid_val(kuid_t uid)
+ 
+ #if defined(NV_VM_INSERT_PAGE_PRESENT)
+ #include <linux/pagemap.h>
++#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 16, 0)
+ #include <linux/dma-mapping.h>
++#else
++#include <linux/dma-direct.h>
++#endif
+ #endif
+ 
+ #if defined(CONFIG_SWIOTLB) && defined(NVCPU_AARCH64)
+diff --git a/kernel/conftest.sh b/kernel/conftest.sh
+index b23dbb4..42dc576 100755
+--- a/kernel/conftest.sh
++++ b/kernel/conftest.sh
+@@ -1906,7 +1906,12 @@ compile_test() {
+             # Determine if the phys_to_dma function is present.
+             #
+             CODE="
++            #include <linux/version.h>
++#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 16, 0)
+             #include <linux/dma-mapping.h>
++#else
++            #include <linux/dma-direct.h>
++#endif
+             void conftest_phys_to_dma(void) {
+                 phys_to_dma();
+             }"
-- 
cgit v0.12