[HOWTO] make a xzm module driver for NVIDIA video card

Post tutorials, HOWTO's and other useful resources here.
fulalas
DEV Team
DEV Team
Posts: 1454
Joined: 26 Oct 2016, 15:34
Distribution: Porteus
Location: Brazil

[HOWTO] make a xzm module driver for NVIDIA video card

Post#46 by fulalas » 17 Jul 2019, 15:19

@Blaze, I have a couple of suggestions to improve your script:

1- create a zip file with your script, blacklist and vdpau.sh (explained in item 4);
2- don't require the blacklist to be located at $PORTDIR, instead expect it to be in the same folder as the script;
3- don't require the driver to be located at /tmp, instead expect it to be in the same folder as the script;
4- create a copy of /etc/profile.d/vdpau.sh and uncomment the line related to Nvidia (i.e. remove # from the beginning of export VDPAU_DRIVER="nvidia") and pack it in the final module. This will allow videos to be hardware decoded, as explained here;
5- you recommend to answer 'no' to the question 'Install NVIDIA's 32-bit compatibility libraries?', but it all depends on what users will do, so if they want to play Windows games via Wine, for example, they will need to answer 'yes'. So my suggestion is to explain a bit better what this options is about;

P.S.: your script link is throwing a 404 :(

User avatar
Blaze
DEV Team
DEV Team
Posts: 2679
Joined: 28 Dec 2010, 11:31
Distribution: ⟰ Porteus current ☯ all DEs ☯
Location: ☭ Russian Federation, Lipetsk region, Dankov
Contact:

[HOWTO] make a xzm module driver for NVIDIA video card

Post#47 by Blaze » 17 Jul 2019, 19:13

fulalas, ok, when I will found some free time I try to apply your suggestions.
In this time I am fight with 0050-compat32-multilib-lite-x86_64
BTW, my latest version of my nvidia script is here
fulalas wrote:
17 Jul 2019, 15:19
your script link is throwing a 404
for me all ok. Do you able to open https://cloud.mail.ru ?

Thanks.
Linux 5.4.0-rc7-porteus #2 SMP Tue Nov 12 17:45:45 UTC 2019 x86_64 Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz GenuineIntel GNU/Linux
MS-7A12 » [AMD/ATI] Tobago PRO [Radeon R7 360 / R9 360 OEM] (rev 81) » Vengeance LPX 16GB DDR4 K2 3200MHz C16

fulalas
DEV Team
DEV Team
Posts: 1454
Joined: 26 Oct 2016, 15:34
Distribution: Porteus
Location: Brazil

[HOWTO] make a xzm module driver for NVIDIA video card

Post#48 by fulalas » 18 Jul 2019, 04:55

Here we go:

Code: Select all

#!/bin/bash
# Build of Nvidia video driver, cleaning and compressing to xzm module for Porteus
# You can use this script for both architectures i586 or x86_64

# Version 2019-07-18

# Written by Blaze <admin at ublaze.ru>
# Modified by fulalas <your email at zipmail.com.br>
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Root check
if [ `whoami` != "root" ]; then
	echo -e "\e[1m\e[31mOnly root can run this.\e[0m"
	exit 1
fi

# Creating installer variable and folder
MODULES_FOLDER=$(readlink -f /mnt/live/porteus/modules)
INSTALL_TEMP_FOLDER=/tmp/nvidia-$$
mkdir $INSTALL_TEMP_FOLDER

# Checking and extracting blacklist.xzm
if [ -f blacklist.xzm ]; then
	xzm2dir blacklist.xzm $INSTALL_TEMP_FOLDER &>/dev/null
elif [ -f "$PORTDIR/optional/blacklist.xzm" ]; then
	xzm2dir "$PORTDIR/optional/blacklist.xzm" $INSTALL_TEMP_FOLDER &>/dev/null
elif [ -f "$PORTDIR/base/blacklist.xzm" ]; then
	xzm2dir "$PORTDIR/base/blacklist.xzm" $INSTALL_TEMP_FOLDER &>/dev/null
else
    echo -e "\e[1m\e[31mblacklist.xzm couldn't be found.\e[0m"
	rm -rf $INSTALL_TEMP_FOLDER
    exit 1
fi

# Selective compression and extraction of memory changes
sync; echo 3 > /proc/sys/vm/drop_caches
echo -e '\n\033[1m\e[32m[*]\e[0m\033[1m Compression of memory changes to /tmp/nvidia.tar.gz...\033[0m'
tar czf /tmp/nvidia.tar.gz --exclude={"*/.*","*/.wh.*",".cache","dev","home","mnt","opt","root","run","tmp","var","etc/bootcmd.cfg","etc/ld.so.cache","etc/fstab","etc/random-seed","etc/cups","etc/udev","etc/profile.d","etc/porteus","etc/X11/xorg.conf.nvidia-xconfig-original","lib/firmware","lib/modules/*porteus/modules.*","usr/man","usr/src","usr/bin/gnome-keyring-daemon","usr/lib/gio","usr/lib/gtk-2.0","usr/lib/gtk-3.0","usr/lib/libXvMCgallium.so.1","usr/lib/libbrscandec2.so.1","usr/lib/libgsm.so.1","usr/lib/libudev.so.1","usr/lib/libunrar.so.5","usr/lib64/gio","usr/lib64/gtk-2.0","usr/lib64/gtk-3.0","usr/lib64/libXvMCgallium.so.1","usr/lib64/libbrscandec2.so.1","usr/lib64/libgsm.so.1","usr/lib64/libudev.so.1","usr/lib64/libunrar.so.5","usr/local","usr/share/glib-2.0","usr/share/mime","usr/share/pixmaps","usr/share/applications/mimeinfo.cache","usr/local/share/applications/mimeinfo.cache","usr/share/doc/NVIDIA_GLX-1.0/html","usr/share/doc/NVIDIA_GLX-1.0/sample","usr/share/doc/NVIDIA_GLX-1.0/LICENSE","usr/share/doc/NVIDIA_GLX-1.0/NVIDIA_Changelog","usr/share/doc/NVIDIA_GLX-1.0/README.txt"} -C /mnt/live/memory changes
echo -e "\n\033[1m\e[32m[*]\e[0m\033[1m Extraction of memory changes from /tmp/nvidia.tar.gz to $INSTALL_TEMP_FOLDER...\033[0m"
tar xf /tmp/nvidia.tar.gz --strip 1 -C $INSTALL_TEMP_FOLDER

# Сleaning driver
echo -e "\n\033[1m\e[32m[*]\e[0m\033[1m Cleaning of driver directory...\033[0m"
rm -rf $INSTALL_TEMP_FOLDER/{.cache,dev,home,mnt,opt,root,run,tmp,var}
find $INSTALL_TEMP_FOLDER -type f -maxdepth 1 -delete
find $INSTALL_TEMP_FOLDER -type l -maxdepth 1 -delete
find $INSTALL_TEMP_FOLDER/etc/ -type f -maxdepth 1 -delete
find $INSTALL_TEMP_FOLDER/etc/ -type d ! -iname 'modprobe.d' ! -iname 'OpenCL' ! -iname 'vulkan' ! -iname 'X11' ! -iname 'etc' -maxdepth 1 -exec rm -rf '{}' '+'
rm -f $INSTALL_TEMP_FOLDER/etc/X11/xorg.conf.nvidia-xconfig-original
rm -rf $INSTALL_TEMP_FOLDER/lib/firmware
rm -f $INSTALL_TEMP_FOLDER/lib/modules/*porteus/modules.*
rm -rf $INSTALL_TEMP_FOLDER/usr/{man,src}
rm -f $INSTALL_TEMP_FOLDER/usr/bin/gnome-keyring-daemon
rm -rf $INSTALL_TEMP_FOLDER/usr/lib/{gio,gtk-2.0,gtk-3.0}
rm -f $INSTALL_TEMP_FOLDER/usr/lib/{libXvMCgallium.so.1,libbrscandec2.so.1,libgsm.so.1,libudev.so.1,libunrar.so.5}
rm -rf $INSTALL_TEMP_FOLDER/usr/lib64/{gio,gtk-2.0,gtk-3.0}
rm -f $INSTALL_TEMP_FOLDER/usr/lib64/{libXvMCgallium.so.1,libbrscandec2.so.1,libgsm.so.1,libudev.so.1,libunrar.so.5}
rm -rf $INSTALL_TEMP_FOLDER/usr/local
rm -rf $INSTALL_TEMP_FOLDER/usr/share/{glib-2.0,mime,pixmaps}
rm -f $INSTALL_TEMP_FOLDER/usr/{,local/}share/applications/mimeinfo.cache
rm -rf $INSTALL_TEMP_FOLDER/usr/share/doc/NVIDIA_GLX-1.0/{html,sample,LICENSE,NVIDIA_Changelog,README.txt}
ls -la
# Adding vdpau hardware video decode rule
if [ -f vdpau.sh ]; then
	mkdir -p $INSTALL_TEMP_FOLDER/etc/profile.d
	cp vdpau.sh $INSTALL_TEMP_FOLDER/etc/profile.d
else
	echo -e "\n\e[1m\e[31mvdpau.sh couldn't be found. Hardware video decode won't work properly.\e[0m"
fi

# Getting driver version
case $(arch) in
	i486)	LIBDIR="/usr/lib"
			;;
	x86_64)	LIBDIR="/usr/lib64"
			;;
	*)		LIBDIRSUFFIX="/usr/lib"
			;;
esac
DRIVER_FILE=$(find $LIBDIR/libEGL_nvidia.so* \! -type l)
DRIVER_VERSION=${DRIVER_FILE: -6}

# Creating final module
MODULE_FILENAME=08-nvidia-$DRIVER_VERSION-k.$(uname -r)-$(cat /etc/porteus-version | cut -d '-' -f2)-$(arch).xzm
dir2xzm $INSTALL_TEMP_FOLDER/ /tmp/$MODULE_FILENAME 2>/dev/null
mv /tmp/$MODULE_FILENAME $MODULES_FOLDER

# Removing temporary files
rm -f /tmp/nvidia.tar.gz
rm -f /tmp/nvidia.xzm
rm -rf $INSTALL_TEMP_FOLDER

# Reboot
echo -e "\n\e[1m\e[32m[DONE]\e[0m \e[1mYou can find your Nvidia driver module in \e[96m$MODULES_FOLDER\e[0m"
echo -e "\e[1m>>> Now you can reboot Porteus via \e[92mreboot\e[0m \e[1mcommand <<<\e[0m\n"
Changes:
1- we don't need .run file anymore. I'm getting the driver version from the actual driver file;
2- adding vdpau rule;
3- I'm not removing blacklist.xzm because I don't like the idea of removing a file that the installer doesn't create;
4- minor changes that I can't remember; please check if you approve everything;

EDITED: I finally understood why $MODDIR and $PORTDIR variables can't be found on my machine. It turns out that this won't work if you call a script like this:

Code: Select all

sudo ./script.sh
I don't know why, but it seems some variables aren't exported if you don't call this before:

Code: Select all

sudo su
:unknown:

EDITED 2: I found a workaround. The script above was updated. :good:

User avatar
Rava
Contributor
Contributor
Posts: 2252
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 4.0 x86-64 XFCe
Location: Forests of Germany

[HOWTO] make a xzm module driver for NVIDIA video card

Post#49 by Rava » 18 Jul 2019, 05:44

fulalas wrote:
18 Jul 2019, 04:55
3- I'm not removing blacklist.xzm because I don't like the idea of removing a file that the installer doesn't create;
I agree. I have my blacklist.xzm renamed as XXXblacklist.xzm and all the other needed modules for Nvidia driver compile named XXX* as well - and put into optional/ - to be able to start this setup via the added kernel cheatcode

Code: Select all

load=XXX
which is only part of the setup for Nvidia driver compile and never part of any normal setup.
So, I sure not want the nvidia.sh to delete the file.

E.g. could be I only realized something went wrong after restarting the system with the new compiled Nvidia driver, and I have to compile it once again.
Cheers!
Yours Rava

User avatar
Blaze
DEV Team
DEV Team
Posts: 2679
Joined: 28 Dec 2010, 11:31
Distribution: ⟰ Porteus current ☯ all DEs ☯
Location: ☭ Russian Federation, Lipetsk region, Dankov
Contact:

[HOWTO] make a xzm module driver for NVIDIA video card

Post#50 by Blaze » 18 Jul 2019, 18:28

fulalas, well done :punk:
I updated the script header.
If you wish, you can add your email.

BTW, not bad to add name of process ID for

Code: Select all

INSTALL_TEMP_FOLDER=/tmp/nvidia
like this

Code: Select all

INSTALL_TEMP_FOLDER=/tmp/nvidia-$$
Thanks.
Linux 5.4.0-rc7-porteus #2 SMP Tue Nov 12 17:45:45 UTC 2019 x86_64 Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz GenuineIntel GNU/Linux
MS-7A12 » [AMD/ATI] Tobago PRO [Radeon R7 360 / R9 360 OEM] (rev 81) » Vengeance LPX 16GB DDR4 K2 3200MHz C16

fulalas
DEV Team
DEV Team
Posts: 1454
Joined: 26 Oct 2016, 15:34
Distribution: Porteus
Location: Brazil

[HOWTO] make a xzm module driver for NVIDIA video card

Post#51 by fulalas » 21 Jul 2019, 05:25

@Blaze, what if we update your first post with the new script? :)

User avatar
Blaze
DEV Team
DEV Team
Posts: 2679
Joined: 28 Dec 2010, 11:31
Distribution: ⟰ Porteus current ☯ all DEs ☯
Location: ☭ Russian Federation, Lipetsk region, Dankov
Contact:

[HOWTO] make a xzm module driver for NVIDIA video card

Post#52 by Blaze » 21 Jul 2019, 10:31

fulalas wrote:
21 Jul 2019, 05:25
what if we update your first post with the new script?
Done.
fulalas wrote:
17 Jul 2019, 15:19
2- don't require the blacklist to be located at $PORTDIR, instead expect it to be in the same folder as the script;
I don't agree with this, because if you don't placed blacklist.xzm to /porteus/base/ - you are not able to compile Nvidia driver in the Text mode.

Отправлено спустя 7 часов 45 минут 47 секунд:
I updated manual again. Please check it :)
Linux 5.4.0-rc7-porteus #2 SMP Tue Nov 12 17:45:45 UTC 2019 x86_64 Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz GenuineIntel GNU/Linux
MS-7A12 » [AMD/ATI] Tobago PRO [Radeon R7 360 / R9 360 OEM] (rev 81) » Vengeance LPX 16GB DDR4 K2 3200MHz C16

User avatar
Rava
Contributor
Contributor
Posts: 2252
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 4.0 x86-64 XFCe
Location: Forests of Germany

[HOWTO] make a xzm module driver for NVIDIA video card

Post#53 by Rava » 21 Jul 2019, 19:44

Blaze wrote:
21 Jul 2019, 18:17
I don't agree with this, because if you don't placed blacklist.xzm to /porteus/base/ - you are not able to compile Nvidia driver in the Text mode.
Blaze is right on that, wherever the blacklist module is located - base or optional - it needs to be activated during the bootup, the compiling will fail if you activate it after you started up the system, at least when you have started X.

Anyhow, was anyone able to compile for neko's kernel 5.1.17 the Nvidia 340.107 or 304.37 x86-64 drivers?

Or for his 5.1.18 kernel? Or for 5.2.2?

And please do tell us if the patches have been necessary for the drivers to work.

If so, please upload these to the net. :)
Cheers!
Yours Rava

User avatar
Blaze
DEV Team
DEV Team
Posts: 2679
Joined: 28 Dec 2010, 11:31
Distribution: ⟰ Porteus current ☯ all DEs ☯
Location: ☭ Russian Federation, Lipetsk region, Dankov
Contact:

[HOWTO] make a xzm module driver for NVIDIA video card

Post#54 by Blaze » 23 Jul 2019, 14:22

Today I got notebook with NVIDIA GeForce GT 740M and I builded 08-nvidia-418.74-k.5.2.2-porteus-v5.0-x86_64.xzm (32 bit libs are included too).
I had problems compiling the NVIDIA 418.74 driver on Kernel 5.2.2

Code: Select all

     CC [M]  /tmp/selfgz1423/NVIDIA-Linux-x86_64-418.74/kernel/nvidia-uvm/uvm8.o
     CC [M]  /tmp/selfgz1423/NVIDIA-Linux-x86_64-418.74/kernel/nvidia-uvm/uvm8_tools.o
     CC [M]  /tmp/selfgz1423/NVIDIA-Linux-x86_64-418.74/kernel/nvidia-uvm/uvm8_global.o
     CC [M]  /tmp/selfgz1423/NVIDIA-Linux-x86_64-418.74/kernel/nvidia-uvm/uvm8_gpu.o
     CC [M]  /tmp/selfgz1423/NVIDIA-Linux-x86_64-418.74/kernel/nvidia-uvm/uvm8_gpu_isr.o
     CC [M]  /tmp/selfgz1423/NVIDIA-Linux-x86_64-418.74/kernel/nvidia-uvm/uvm8_procfs.o
     CC [M]  /tmp/selfgz1423/NVIDIA-Linux-x86_64-418.74/kernel/nvidia-uvm/uvm8_va_space.o
     CC [M]  /tmp/selfgz1423/NVIDIA-Linux-x86_64-418.74/kernel/nvidia-uvm/uvm8_va_space_mm.o
   /tmp/selfgz1423/NVIDIA-Linux-x86_64-418.74/kernel/nvidia-uvm/uvm8_tools.c:209:13: error: conflicting types for ‘put_user_pages’
     209 | static void put_user_pages(struct page **pages, NvU64 page_count)
         |             ^~~~~~~~~~~~~~
   In file included from /tmp/selfgz1423/NVIDIA-Linux-x86_64-418.74/kernel/common/inc/nv-pgprot.h:17,
                    from /tmp/selfgz1423/NVIDIA-Linux-x86_64-418.74/kernel/common/inc/nv-linux.h:20,
                    from /tmp/selfgz1423/NVIDIA-Linux-x86_64-418.74/kernel/nvidia-uvm/uvm_linux.h:41,
                    from /tmp/selfgz1423/NVIDIA-Linux-x86_64-418.74/kernel/nvidia-uvm/uvm_common.h:48,
                    from /tmp/selfgz1423/NVIDIA-Linux-x86_64-418.74/kernel/nvidia-uvm/uvm8_tools.c:23:
   ./include/linux/mm.h:1075:6: note: previous declaration of ‘put_user_pages’ was here
    1075 | void put_user_pages(struct page **pages, unsigned long npages);
         |      ^~~~~~~~~~~~~~
   make[2]: *** [scripts/Makefile.build:279: /tmp/selfgz1423/NVIDIA-Linux-x86_64-418.74/kernel/nvidia-uvm/uvm8_tools.o] Error 1
but I found this solution https://garajau.com.br/2019/07/compilin ... -kernel-52
I successfully applied two patches https://github.com/kriansa/PKGBUILDs/tr ... nvidia-418
  • fs62142.patch

    Code: Select all

    diff --git a/kernel/nvidia/nv-dma.c b/kernel/nvidia/nv-dma.c
    index 73cdeed..e691014 100644
    --- a/kernel/nvidia/nv-dma.c
    +++ b/kernel/nvidia/nv-dma.c
    @@ -606,7 +606,7 @@ static NvBool nv_dma_is_map_resource_implemented
     #if defined(NV_DMA_MAP_RESOURCE_PRESENT)
         const struct dma_map_ops *ops = get_dma_ops(&nvl->dev->dev);
     
    -    return (ops->map_resource != NULL);
    +    return (ops && ops->map_resource);
     #else
         return NV_FALSE;
     #endif
  • kernel-52.patch

    Code: Select all

    --- a/kernel/nvidia-uvm/uvm8_tools.c
    +++ b/kernel/nvidia-uvm/uvm8_tools.c
    @@ -204,12 +204,14 @@ static bool tracker_is_counter(uvm_tools_event_tracker_t *event_tracker)
         return event_tracker != NULL && !event_tracker->is_queue;
     }
    
    +/*
     static void put_user_pages(struct page **pages, NvU64 page_count)
     {
         NvU64 i;
         for (i = 0; i < page_count; i++)
             put_page(pages[i]);
     }
    +*/
    
     static void unmap_user_pages(struct page **pages, void *addr, NvU64 size)
     {
this is manual:

Code: Select all

# Extract only
./NVIDIA-Linux-x86_64-418.74.run  --extract-only
cd NVIDIA-Linux-x86_64-418.74

# Fix https://bugs.archlinux.org/task/62142
patch -Np1 -i ../fs62142.patch

# Fix compilation for Kernel 5.2
patch -Np1 -i ../kernel-52.patch

# Install
./nvidia-installer
cd ..
./nvidia.sh
Linux 5.4.0-rc7-porteus #2 SMP Tue Nov 12 17:45:45 UTC 2019 x86_64 Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz GenuineIntel GNU/Linux
MS-7A12 » [AMD/ATI] Tobago PRO [Radeon R7 360 / R9 360 OEM] (rev 81) » Vengeance LPX 16GB DDR4 K2 3200MHz C16

fulalas
DEV Team
DEV Team
Posts: 1454
Joined: 26 Oct 2016, 15:34
Distribution: Porteus
Location: Brazil

[HOWTO] make a xzm module driver for NVIDIA video card

Post#55 by fulalas » 23 Jul 2019, 20:23

Wonderful! :)

User avatar
Rava
Contributor
Contributor
Posts: 2252
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 4.0 x86-64 XFCe
Location: Forests of Germany

[HOWTO] make a xzm module driver for NVIDIA video card

Post#56 by Rava » 23 Jul 2019, 23:21

For now I failed in compiling the 340.107 for Kernel 5.1.17.

Without patching I got this error:

Code: Select all

ERROR: Unable to build the NVIDIA kernel module.
And patching itself failed for now.

I wonder, do I need to apply the 4.11, 5.0 and 5.1 or only the 5.1 one when compiling a driver for 5.1.* kernel?

As example, here is the 5.1 patch:https://aur.archlinux.org/cgit/aur.git/ ... idia-340xx

Code: Select all

diff --git kernel/uvm/nvidia_uvm_lite.c kernel/uvm/nvidia_uvm_lite.c
index 65b9a4d..f5ea5d7 100644
--- kernel/uvm/nvidia_uvm_lite.c
+++ kernel/uvm/nvidia_uvm_lite.c
@@ -830,8 +830,10 @@ done:
 #if defined(NV_VM_OPERATIONS_STRUCT_HAS_FAULT)
 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0)
 int _fault(struct vm_area_struct *vma, struct vm_fault *vmf)
-#else 	
-int _fault(struct vm_fault *vmf) 	
+#elif LINUX_VERSION_CODE < KERNEL_VERSION(5, 1, 0)
+int _fault(struct vm_fault *vmf)
+#else
+vm_fault_t _fault(struct vm_fault *vmf)
 #endif
 {
 #if defined(NV_VM_FAULT_HAS_ADDRESS)
@@ -886,8 +888,10 @@ static struct vm_operations_struct uvmlite_vma_ops =
 #if defined(NV_VM_OPERATIONS_STRUCT_HAS_FAULT)
 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0)
 int _sigbus_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
-#else
+#elif LINUX_VERSION_CODE < KERNEL_VERSION(5, 1, 0)
 int _sigbus_fault(struct vm_fault *vmf)
+#else
+vm_fault_t _sigbus_fault(struct vm_fault *vmf)
 #endif
 {
     vmf->page = NULL;
diff --git kernel/nv-drm.c kernel/nv-drm.c
index 122ba7d..1be5733 100644
--- kernel/nv-drm.c
+++ kernel/nv-drm.c
@@ -146,7 +146,7 @@ static const struct file_operations nv_drm_fops = {
 };
 
 static struct drm_driver nv_drm_driver = {
-#if defined(DRIVER_LEGACY)
+#if defined(DRIVER_LEGACY) || LINUX_VERSION_CODE >= KERNEL_VERSION(5, 1, 0)
     .driver_features = DRIVER_GEM | DRIVER_PRIME | DRIVER_LEGACY,
 #else
     .driver_features = DRIVER_GEM | DRIVER_PRIME,
Cheers!
Yours Rava

User avatar
Rava
Contributor
Contributor
Posts: 2252
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 4.0 x86-64 XFCe
Location: Forests of Germany

[HOWTO] make a xzm module driver for NVIDIA video card

Post#57 by Rava » 24 Jul 2019, 20:29

Code: Select all

./NVIDIA-Linux-x86_64-340.107.run --extract-only
Creating directory NVIDIA-Linux-x86_64-340.107
Verifying archive integrity... OK
Uncompressing NVIDIA Accelerated Graphics Driver for Linux-x86_64 340.107...

cd NVIDIA-Linux-x86_64-340.107
So far, so easy. Patching seems the difficult thing:

Applying the 5.1 patch like Blaze applied his patches failes:

Code: Select all

patch -Np1 -i ../nvidia-340xx_kernel-5.1.patch 
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git kernel/uvm/nvidia_uvm_lite.c kernel/uvm/nvidia_uvm_lite.c
|index 65b9a4d..f5ea5d7 100644
|--- kernel/uvm/nvidia_uvm_lite.c
|+++ kernel/uvm/nvidia_uvm_lite.c
--------------------------
File to patch: ^C
The file itself patch complains about exists just fine:

Code: Select all

ls -o kernel/uvm/nvidia_uvm_lite.c 
-rw-r--r-- 1 root 85470 2018-05-25 06:16 kernel/uvm/nvidia_uvm_lite.c
file says about the patch file it being a "unified diff output, ASCII text"

Maybe Blaze' parameters "-Np1" are just not the correct one for this patch?
Cheers!
Yours Rava

User avatar
ncmprhnsbl
DEV Team
DEV Team
Posts: 2204
Joined: 20 Mar 2012, 03:42
Distribution: 5.0rc1-64bit all-DE+more
Location: australia
Contact:

[HOWTO] make a xzm module driver for NVIDIA video card

Post#58 by ncmprhnsbl » 24 Jul 2019, 23:07

Rava wrote:
24 Jul 2019, 20:29
Maybe Blaze' parameters "-Np1" are just not the correct one for this patch?
from: https://aur.archlinux.org/cgit/aur.git/ ... idia-340xx (where these patches originate)

Code: Select all

    patch -Np0 < "${srcdir}/kernel-4.11.patch"
    patch -Np0 < "${srcdir}/kernel-5.0.patch"
    patch -Np0 < "${srcdir}/kernel-5.1.patch"
of course, change ${srcdir} to whatever suits..
i would use all three ... because they might be incremental...
Forum Rules : https://forum.porteus.org/viewtopic.php?f=35&t=44

User avatar
Rava
Contributor
Contributor
Posts: 2252
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 4.0 x86-64 XFCe
Location: Forests of Germany

[HOWTO] make a xzm module driver for NVIDIA video card

Post#59 by Rava » 24 Jul 2019, 23:51

ncmprhnsbl wrote:
24 Jul 2019, 23:07
of course, change ${srcdir} to whatever suits..
i would use all three ... because they might be incremental...
Since the 4.11 patch failed, I deleted the folder with the extracted source and started once again.
But once again I get the very same error:

Code: Select all

# patch -Np0 < ../nvidia-340xx_kernel-4.11.patch 
patching file kernel/uvm/nvidia_uvm_lite.c
patch unexpectedly ends in middle of line
Hunk #3 succeeded at 874 with fuzz 1.
"patch unexpectedly ends in middle of line" is sure not meant to happen.

I just realized, I downloaded another smaller version of the 340.107 .run driver thingy, the one that aur.archlinux.org mentions, I just have to look where I have it, with all the different machines I use for going online and tons of USB thrumbdrives.

TerminatorVoice "I will be back."
Cheers!
Yours Rava

donald
Full of knowledge
Full of knowledge
Posts: 1539
Joined: 17 Jun 2013, 13:17
Distribution: Porteus 3.2.2 XFCE 32bit
Location: Germany

[HOWTO] make a xzm module driver for NVIDIA video card

Post#60 by donald » 25 Jul 2019, 00:51

@ Rava
Try this patch -- it's a combination of 3 patches i found at archlinux.
(used with the original NVIDIA-Linux-x86_64-340.107.run file)

Code: Select all

--- kernel/uvm/nvidia_uvm_lite.c	2017-09-27 13:50:46.334075042 +0200
+++ kernel/uvm/nvidia_uvm_lite.c	2017-09-27 13:56:06.358041280 +0200
@@ -818,7 +818,11 @@
 }
 
 #if defined(NV_VM_OPERATIONS_STRUCT_HAS_FAULT)
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0)
 int _fault(struct vm_area_struct *vma, struct vm_fault *vmf)
+#else 	
+int _fault(struct vm_fault *vmf) 	
+#endif
 {
 #if defined(NV_VM_FAULT_HAS_ADDRESS)
     unsigned long vaddr = vmf->address;
@@ -828,7 +832,11 @@
     struct page *page = NULL;
     int retval;
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0)
     retval = _fault_common(vma, vaddr, &page, vmf->flags);
+#else
+    retval = _fault_common(NULL, vaddr, &page, vmf->flags);
+#endif
 
     vmf->page = page;
 
@@ -866,7 +874,11 @@
 // it's dealing with anonymous mapping (see handle_pte_fault).
 //
 #if defined(NV_VM_OPERATIONS_STRUCT_HAS_FAULT)
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0)
 int _sigbus_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
+#else
+int _sigbus_fault(struct vm_fault *vmf)
+#endif
 {
     vmf->page = NULL;
     return VM_FAULT_SIGBUS;

--- kernel/nv-drm.c	2018-05-25 04:16:20.000000000 +0000
+++ kernel/nv-drm.c	2019-03-04 20:57:40.065280734 +0000
@@ -252,7 +252,11 @@
         goto done;
     }
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0)
     drm_gem_object_unreference_unlocked(&nv_obj->base);
+#else
+    drm_gem_object_put_unlocked(&nv_obj->base);
+#endif
 
     status = RM_OK;
 
--- kernel/os-interface.c	2018-05-25 04:16:20.000000000 +0000
+++ kernel/os-interface.c	2019-03-04 21:03:03.815854982 +0000
@@ -14,6 +14,16 @@
 #include "os-interface.h"
 #include "nv-linux.h"
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0)
+static inline void do_gettimeofday(struct timeval *tv)
+{
+    struct timespec64 now;
+    ktime_get_real_ts64(&now);
+    tv->tv_sec = now.tv_sec;
+    tv->tv_usec = now.tv_nsec/1000;
+}
+#endif
+
 RM_STATUS NV_API_CALL os_disable_console_access(void)
 {
     NV_ACQUIRE_CONSOLE_SEM();

--- kernel/uvm/nvidia_uvm_lite.c	2019-03-04 20:57:25.815255511 +0000
+++ kernel/uvm/nvidia_uvm_lite.c	2019-03-04 21:04:25.239333050 +0000
@@ -30,6 +30,16 @@
 #include "nvidia_uvm_lite_counters.h"
 #include "ctrl2080mc.h"
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0)
+static inline void do_gettimeofday(struct timeval *tv)
+{
+    struct timespec64 now;
+    ktime_get_real_ts64(&now);
+    tv->tv_sec = now.tv_sec;
+    tv->tv_usec = now.tv_nsec/1000;
+}
+#endif
+
 //
 // nvidia_uvm_lite.c
 // This file contains code that is specific to the UVM-Lite mode of operation.

--- kernel/uvm/nvidia_uvm_lite.c
+++ kernel/uvm/nvidia_uvm_lite.c
@@ -830,8 +830,10 @@ done:
 #if defined(NV_VM_OPERATIONS_STRUCT_HAS_FAULT)
 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0)
 int _fault(struct vm_area_struct *vma, struct vm_fault *vmf)
-#else 	
-int _fault(struct vm_fault *vmf) 	
+#elif LINUX_VERSION_CODE < KERNEL_VERSION(5, 1, 0)
+int _fault(struct vm_fault *vmf)
+#else
+vm_fault_t _fault(struct vm_fault *vmf)
 #endif
 {
 #if defined(NV_VM_FAULT_HAS_ADDRESS)
@@ -886,8 +888,10 @@ static struct vm_operations_struct uvmlite_vma_ops =
 #if defined(NV_VM_OPERATIONS_STRUCT_HAS_FAULT)
 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0)
 int _sigbus_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
-#else
+#elif LINUX_VERSION_CODE < KERNEL_VERSION(5, 1, 0)
 int _sigbus_fault(struct vm_fault *vmf)
+#else
+vm_fault_t _sigbus_fault(struct vm_fault *vmf)
 #endif
 {
     vmf->page = NULL;

--- kernel/nv-drm.c
+++ kernel/nv-drm.c
@@ -146,7 +146,7 @@ static const struct file_operations nv_drm_fops = {
 };
 
 static struct drm_driver nv_drm_driver = {
-#if defined(DRIVER_LEGACY)
+#if defined(DRIVER_LEGACY) || LINUX_VERSION_CODE >= KERNEL_VERSION(5, 1, 0)
     .driver_features = DRIVER_GEM | DRIVER_PRIME | DRIVER_LEGACY,
 #else
     .driver_features = DRIVER_GEM | DRIVER_PRIME,

Note
you do (normally) not need to extract the *.run file.
Patches can be applied by the run file itself.

./NVIDIA-Linux-x86_64-340.107.run --apply-patch nv.patch
(nv.patch is the name of my patch combination)

The patching works but i do not know if the resulting *custom.run will
successfully build the driver. -- I do not have a compatible g-card to test it.

Good luck

source of patches:
https://aur.archlinux.org/packages/nvidia-340xx/

Post Reply