Skip to content

Commit

Permalink
Add udev rules for node presence and runtime PM
Browse files Browse the repository at this point in the history
  • Loading branch information
Tk-Glitch committed Oct 1, 2021
1 parent 8789c27 commit 7c0bbf6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
10 changes: 7 additions & 3 deletions PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ fi

pkgname=("${_pkgname_array[@]}")
pkgver=$_driver_version
pkgrel=178
pkgrel=179
arch=('x86_64')
url="http://www.nvidia.com/"
license=('custom:NVIDIA')
Expand All @@ -252,6 +252,7 @@ fi
source=($_source_name
'10-nvidia-drm-outputclass.conf'
'nvidia-utils-tkg.sysusers'
'60-nvidia.rules'
'linux-version.diff' # include linux version
'01-ipmi-vm.diff' # ipmi & vm patch for older than 415.22 releases (2018.12.7) (396.xx)
'02-ipmi-vm.diff' # ipmi & vm patch for older than 415.22 releases (2018.12.7) (addon for 410+)
Expand Down Expand Up @@ -287,6 +288,7 @@ msg2 "Selected driver integrity check behavior (md5sum or SKIP): $_md5sum" # If
md5sums=("$_md5sum"
'cb27b0f4a78af78aa96c5aacae23256c'
'3d2894e71d81570bd00bce416d3e547d'
'3d32130235acc5ab514e1021f7f5c439'
'7a825f41ada7e106c8c0b713a49b3bfa'
'd961d1dce403c15743eecfe3201e4b6a'
'14460615a9d4e247c8d9bcae8776ed48'
Expand Down Expand Up @@ -1277,6 +1279,8 @@ nvidia-utils-tkg() {

install -Dm644 "$srcdir"/nvidia-utils-tkg.sysusers "$pkgdir"/usr/lib/sysusers.d/$pkgname.conf

install -Dm644 "$srcdir"/60-nvidia.rules "$pkgdir"/usr/lib/udev/rules.d/60-nvidia.rules

_create_links
}
package_nvidia-utils-tkg() {
Expand Down Expand Up @@ -1334,7 +1338,7 @@ if [ "$_dkms" = "false" ] || [ "$_dkms" = "full" ]; then
find "$pkgdir" -name '*.ko' -exec gzip -n {} +
done

echo "blacklist nouveau" |
echo -e "blacklist nouveau\nblacklist lbm-nouveau\nalias nouveau off\nalias lbm-nouveau off" |
install -Dm644 /dev/stdin "${pkgdir}/usr/lib/modprobe.d/${pkgname}.conf"
}
package_nvidia-tkg() {
Expand Down Expand Up @@ -1449,7 +1453,7 @@ if [ "$_dkms" = "true" ] || [ "$_dkms" = "full" ]; then
install -dm 755 "${pkgdir}"/usr/{lib/modprobe.d,src}
cp -dr --no-preserve='ownership' kernel-dkms "${pkgdir}/usr/src/nvidia-${pkgver}"

echo "blacklist nouveau" |
echo -e "blacklist nouveau\nblacklist lbm-nouveau\nalias nouveau off\nalias lbm-nouveau off" |
install -Dm644 /dev/stdin "${pkgdir}/usr/lib/modprobe.d/${pkgname}.conf"

install -Dt "${pkgdir}/usr/share/licenses/${pkgname}" -m644 "${srcdir}/${_pkg}/LICENSE"
Expand Down
24 changes: 24 additions & 0 deletions system/60-nvidia.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Make sure device nodes are present even when the DDX is not started for the Wayland/EGLStream case
KERNEL=="nvidia", RUN+="/usr/bin/bash -c '/usr/bin/mknod -Z -m 666 /dev/nvidiactl c $$(grep nvidia-frontend /proc/devices | cut -d \ -f 1) 255'"
KERNEL=="nvidia", RUN+="/usr/bin/bash -c 'for i in $$(cat /proc/driver/nvidia/gpus/*/information | grep Minor | cut -d \ -f 4); do /usr/bin/mknod -Z -m 666 /dev/nvidia$${i} c $$(grep nvidia-frontend /proc/devices | cut -d \ -f 1) $${i}; done'"
KERNEL=="nvidia_modeset", RUN+="/usr/bin/bash -c '/usr/bin/mknod -Z -m 666 /dev/nvidia-modeset c $$(grep nvidia-frontend /proc/devices | cut -d \ -f 1) 254'"
KERNEL=="nvidia_uvm", RUN+="/usr/bin/bash -c '/usr/bin/mknod -Z -m 666 /dev/nvidia-uvm c $$(grep nvidia-uvm /proc/devices | cut -d \ -f 1) 0'"
KERNEL=="nvidia_uvm", RUN+="/usr/bin/bash -c '/usr/bin/mknod -Z -m 666 /dev/nvidia-uvm-tools c $$(grep nvidia-uvm /proc/devices | cut -d \ -f 1) 1'"

# Enable runtime PM for NVIDIA VGA/3D controller devices
ACTION=="bind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x03[0-9]*", TEST=="power/control", ATTR{power/control}="auto"
# Enable runtime PM for NVIDIA Audio devices
ACTION=="bind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x040300", TEST=="power/control", ATTR{power/control}="auto"
# Enable runtime PM for NVIDIA USB xHCI Host Controller devices
ACTION=="bind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x0c0330", TEST=="power/control", ATTR{power/control}="auto"
# Enable runtime PM for NVIDIA USB Type-C UCSI devices
ACTION=="bind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x0c8000", TEST=="power/control", ATTR{power/control}="auto"

# Disable runtime PM for NVIDIA VGA/3D controller devices
ACTION=="unbind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x03[0-9]*", TEST=="power/control", ATTR{power/control}="on"
# Disable runtime PM for NVIDIA Audio devices
ACTION=="unbind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x040300", TEST=="power/control", ATTR{power/control}="on"
# Disable runtime PM for NVIDIA USB xHCI Host Controller devices
ACTION=="unbind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x0c0330", TEST=="power/control", ATTR{power/control}="on"
# Disable runtime PM for NVIDIA USB Type-C UCSI devices
ACTION=="unbind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x0c8000", TEST=="power/control", ATTR{power/control}="on"

6 comments on commit 7c0bbf6

@aufkrawall
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into it!
Unfortunately I still have to run nvidia-modprobe -u -c=0 to make RDR2 work in Wine. :(

@jeisom
Copy link

@jeisom jeisom commented on 7c0bbf6 Oct 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also still running into this and "nvidia-modprobe -u -c=0" fixes it. 470.74, RTX 2060

@jeisom
Copy link

@jeisom jeisom commented on 7c0bbf6 Oct 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After looking into this a bit more, the /dev/nvidia-uvm-tools & /dev/nvidia-uvm device nodes are still not created. The udev rules file is installed. This is on an up to date archlinux install.

@Cabopust
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeisom You can try the udev rules used in the Ubuntu PPA.

# Tag the device as master-of-seat so that logind is happy
# (see LP: #1365336)
SUBSYSTEM=="pci", ATTRS{vendor}=="0x10de", DRIVERS=="nvidia", TAG+="seat", TAG+="master-of-seat"

# Start and stop nvidia-persistenced on power on and power off
# respectively
ACTION=="add", DEVPATH=="/bus/pci/drivers/nvidia", TAG+="systemd", ENV{SYSTEMD_WANTS}="nvidia-persistenced.service"

# Load and unload nvidia-modeset module
ACTION=="add", DEVPATH=="/bus/pci/drivers/nvidia", RUN+="/sbin/modprobe nvidia-modeset"
ACTION=="remove", DEVPATH=="/bus/pci/drivers/nvidia", RUN+="/sbin/modprobe -r nvidia-modeset"

# Load and unload nvidia-drm module
ACTION=="add", DEVPATH=="/bus/pci/drivers/nvidia", RUN+="/sbin/modprobe nvidia-drm"
ACTION=="remove", DEVPATH=="/bus/pci/drivers/nvidia", RUN+="/sbin/modprobe -r nvidia-drm"

# Load and unload nvidia-uvm module
ACTION=="add", DEVPATH=="/bus/pci/drivers/nvidia", RUN+="/sbin/modprobe nvidia-uvm"
ACTION=="remove", DEVPATH=="/bus/pci/drivers/nvidia", RUN+="/sbin/modprobe -r nvidia-uvm"

# This will create the device nvidia device nodes
ACTION=="add", DEVPATH=="/bus/pci/drivers/nvidia", RUN+="/sbin/ub-device-create"

# Create the device node for the nvidia-uvm module
ACTION=="add", DEVPATH=="/module/nvidia_uvm", SUBSYSTEM=="module", RUN+="/sbin/ub-device-create"

# Enable runtime PM for NVIDIA VGA/3D controller devices
ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x03[0-9]*", TEST=="power/control", ATTR{power/control}="auto"

# Enable runtime PM for NVIDIA Audio devices
ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x040300", TEST=="power/control", ATTR{power/control}="auto"

# Enable runtime PM for NVIDIA USB xHCI Host Controller devices
ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x0c0330", TEST=="power/control", ATTR{power/control}="auto"

# Enable runtime PM fo NVIDIA USB Type-C UCSI devices
ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x0c8000", TEST=="power/control", ATTR{power/control}="auto"

@jeisom
Copy link

@jeisom jeisom commented on 7c0bbf6 Oct 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those rules don't help. The udev rules need to create the nvidia-uvm & nvidia-uvm-tools for it to work correctly. I am using the Ghostrunner demo as a test and selecting DX12 as the renderer. It complains the I don't have a DX12 compatible card if I don't have those nodes created. I don't know why the rules aren't being triggered as I don't know enough about udev rules themselves.

@jeisom
Copy link

@jeisom jeisom commented on 7c0bbf6 Oct 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I tracked down the problem. nvidia-uvm isn't loaded by default. I added a conf file in /etc/module-load.d/ to load it and it works fine. I am not sure what the "proper" fix is though.

Please sign in to comment.