Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions profiles/pci/graphic_drivers/profiles.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,34 @@ conditional_packages = """

"""
pre_install = """
cat <<EOF >/etc/mkinitcpio.conf.d/10-chwd.conf
# Enable early KMS for non-removable NVIDIA GPUs.
# Removable GPUs (Thunderbolt, USB4) aren't available during initramfs,
# so loading these modules early causes Xid errors and no display output.
for dev in /sys/bus/pci/devices/*; do
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think iterating over /sys/class/drm/*/device will be faster and allows to get rid of class id check in the loop.

Suggested change
for dev in /sys/bus/pci/devices/*; do
for dev in /sys/class/drm/*/device; do

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I don't think the device will be present in /sys/class/drm/ when the driver is not installed right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If NVIDIA driver is not installed, then kernel simply fallbacks to nouveau, which is still creates drm device. It is theoretically possible when no driver is loaded, but I am not sure if we should handle it here.

vendor="$(cat "$dev/vendor" 2>/dev/null)"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think 2>/dev/null is redudant here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It probably is, but i'd figured it wont hurt either.

class="$(cat "$dev/class" 2>/dev/null)"

# Only check NVIDIA (0x10de) display devices
if [ "$vendor" != "0x10de" ]; then
continue
fi

case "$class" in
0x0300*|0x0302*|0x0380*) ;; # VGA, 3D, or display controller
*) continue ;;
esac

# Skip removable GPUs (eGPU via Thunderbolt, USB4, etc.)
if [ "$(cat "$dev/removable" 2>/dev/null)" = "removable" ]; then
Comment thread
christophsanz marked this conversation as resolved.
Outdated
continue
fi

cat <<EOF >/etc/mkinitcpio.conf.d/10-chwd.conf
# This file is automatically generated by chwd. PLEASE DO NOT EDIT IT.
MODULES+=(nvidia nvidia_modeset nvidia_uvm nvidia_drm)
EOF
break
done

# Remove kms hook from mkinitcpio.conf on desktops
device_type="$(cat /sys/devices/virtual/dmi/id/chassis_type)"
Expand Down Expand Up @@ -126,10 +150,34 @@ conditional_packages = """

"""
pre_install = """
cat <<EOF >/etc/mkinitcpio.conf.d/10-chwd.conf
# Enable early KMS for non-removable NVIDIA GPUs.
# Removable GPUs (Thunderbolt, USB4) aren't available during initramfs,
# so loading these modules early causes Xid errors and no display output.
for dev in /sys/bus/pci/devices/*; do
vendor="$(cat "$dev/vendor" 2>/dev/null)"
class="$(cat "$dev/class" 2>/dev/null)"

# Only check NVIDIA (0x10de) display devices
if [ "$vendor" != "0x10de" ]; then
continue
fi

case "$class" in
0x0300*|0x0302*|0x0380*) ;; # VGA, 3D, or display controller
*) continue ;;
esac

# Skip removable GPUs (eGPU via Thunderbolt, USB4, etc.)
if [ "$(cat "$dev/removable" 2>/dev/null)" = "removable" ]; then
continue
fi

cat <<EOF >/etc/mkinitcpio.conf.d/10-chwd.conf
# This file is automatically generated by chwd. PLEASE DO NOT EDIT IT.
MODULES+=(nvidia nvidia_modeset nvidia_uvm nvidia_drm)
EOF
break
done

# Remove kms hook from mkinitcpio.conf on desktops
device_type="$(cat /sys/devices/virtual/dmi/id/chassis_type)"
Expand Down