Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NVIDIA GPUs detection #139

Merged
merged 9 commits into from
Oct 4, 2024
1 change: 1 addition & 0 deletions ids/nouveau.ids
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
00cc 0141 0a68 01db 0410 0635 039c 0301 07e3 0095 0619 0625 0400 0174 0659 0648 062a 00c9 002d 07e5 0602 0865 014c 0152 0183 0150 0ca5 0653 0241 0628 06e3 00c1 0401 01dc 0395 0638 029f 00fd 00c8 039e 0282 017d 00fe 0040 0151 0604 0092 0194 0191 0644 00f9 0876 05eb 0323 0101 065b 0181 0295 0845 0111 0cbc 0402 0200 0182 06ea 01a0 014e 0140 0392 0a62 0342 0251 034c 0258 0041 0201 0162 01de 0173 0864 0211 0100 0185 0280 0652 0161 0867 0409 0649 0290 0292 0640 086f 06ff 0394 10d8 0646 10c3 10c0 0ff2 0160 0610 0168 05e3 0172 0399 0259 0cb0 0862 0caf 0cac 0ca9 0ca8 032a 0253 0613 0406 0ca7 0293 0245 0ca4 0218 06ec 0ca3 0344 087d 0298 0ca2 040a 02e3 0ca0 0a73 0179 00cd 0215 0a7a 0146 06e9 0171 0407 002c 0a75 0a63 0a74 0244 0308 08a0 0a72 004e 0403 0145 0348 0a71 0175 00f8 0a70 0289 065c 0a6f 0398 0651 00f2 03d5 0332 018c 0328 0a6e 0a6c 06fa 025b 031a 0615 0338 0170 0312 0178 0a67 029b 0408 0a66 0093 0a65 0309 0a64 0a60 0020 0a38 0a35 0612 062d 0a34 0046 0a32 0a2d 0611 0a2c 0428 05f9 019d 0626 0a2a 06fb 0623 0601 087e 0169 0a27 0a26 03d1 0a23 0044 0153 0a22 0193 086c 0a20 0603 05e6 00f3 08a4 0600 06f8 01da 08a3 08a2 031c 087f 0a28 087a 0874 0873 029d 05ff 0871 063a 062b 0147 017c 0870 11bf 0197 0103 086e 086d 040b 016a 086a 0869 0868 0866 02e2 033f 0863 018a 01d8 00f4 032c 0112 01df 014f 084c 028c 084d 084b 0311 01d0 00c2 0849 06e7 0848 0847 0846 0393 06f9 01d1 02e0 00f5 07e2 0221 0042 0250 06fd 0113 0043 0a29 0840 042e 06ef 0029 019e 040d 06eb 00f6 0a76 042b 06e8 0404 06e6 017a 0167 0861 0608 0347 061e 01d6 0286 0397 042d 02e4 0045 065a 07e0 0143 0048 053a 0656 0098 01dd 0281 0144 0166 00f1 01d7 0326 0165 064b 064a 084a 02e1 0176 0163 03d0 10c5 0247 031b 0645 062c 00c3 042a 0297 0188 0632 0641 0203 053b 0637 0643 0631 0630 0427 062e 0627 00fa 0a2b 0426 0622 0621 0334 014d 061d 061c 061b 061a 0618 0202 029e 05e1 060d 0333 0a6a 034e 0614 060f 05e0 060c 0142 060b 009d 0609 05fe 0327 0091 00c0 06e2 0322 0a7c 0605 0872 05fd 05f8 06f1 0423 05ea 05e7 08a5 018b 00a0 0302 0fef 05e2 0148 0533 0531 0405 042f 05ed 06e0 03d2 042c 0324 0090 01f0 084f 0222 0a3c 061f 0314 0425 029a 0341 0391 0099 0288 014a 01d2 053e 0028 0a78 07e1 0047 00ce 029c 0164 06e4 0212 0606 0654 0321 0240 0655 0658 0343 0110 00fc 0331 0149 03d6 0420 0294 060a 0325 0429 040f 0617 064c 0299 0647 0a69 0291 032b 0607 06e1 0cb1 0860 00fb 032d 038b 0390 0421 040e 0242 0330 0844 01d3 06e5 040c 0422 0177 0320 0424
1 change: 1 addition & 0 deletions ids/nvidia-390.ids
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
06cd 06c4 0de8 06ca 108b 06df 0df5 0f01 1086 0dec 0dd2 1251 0f03 0e31 1051 1056 1054 0de2 06da 1213 1091 1241 124d 124b 0dc6 0e22 1249 0de1 1248 0df6 1247 1246 1245 0dd3 0e30 105a 1210 1243 1200 0de4 1048 1244 1080 1049 1040 1042 0df4 1087 1208 1207 1082 0df3 0dfa 1203 1052 0e24 1055 06dc 06c0 06d9 1212 1084 0deb 0dee 06dd 109b 0e23 109a 06d8 0dd8 0df7 06de 1096 1094 1089 0df8 104b 1140 1088 1206 0df1 0de7 1081 107d 107c 105b 0e3a 1059 0df2 0dc0 104a 1058 1057 1201 0dc5 1050 0dfc 0def 0dd1 104c 1211 0de3 1205 0de9 0f00 06d2 0ded 0f02 06d1 0dce 0dea 0df0 0df9 0dda 0dcd 0dd6 0e3b 0dc4 0de0 0de5
1 change: 1 addition & 0 deletions ids/nvidia-470.ids
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0fd8 11b7 0fd4 0fd9 11c8 11cb 0fe0 118e 0fc9 11c5 0ff8 102d 119a 1288 1187 11a1 1183 118a 1001 0fd5 0fe9 11c4 11c0 12ba 1023 100a 12b9 11c6 11a2 0fd1 129a 1299 1298 1296 0ff6 1293 0ffc 11bc 1282 103c 1007 0fe4 1291 0ffd 1005 0fce 0fc8 0ff9 1289 11a7 0fcd 1287 1194 119e 1029 11be 11e3 1284 1281 11c2 1295 0ffb 11fc 11fa 128b 1004 11e1 11e0 11c3 0fd2 1180 1286 11a0 1184 118f 0fec 0fea 1189 119f 1008 0fe2 11b8 11b6 1024 11a3 11b4 0fe1 11ba 119d 1195 1199 0fee 1027 0ffe 0ffa 1028 0fd3 0fe3 0fc6 1021 1185 1280 0fff 1193 0fed 11e2 11bd 102a 1188 1022 1290 1292 1026 0fdf 100c 1198 103a
130 changes: 60 additions & 70 deletions profiles/pci/graphic_drivers/profiles.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,31 @@
desc = 'Open source NVIDIA drivers for Linux (Latest)'
class_ids = "0300 0302 0380"
vendor_ids = "10de"
device_ids = "*"
priority = 10
packages = 'nvidia-utils egl-wayland nvidia-settings opencl-nvidia lib32-opencl-nvidia lib32-nvidia-utils libva-nvidia-driver vulkan-icd-loader lib32-vulkan-icd-loader'
conditional_packages = """
kernels="$(pacman -Qqs "^linux-cachyos")"
modules=""
packages=""

for kernel in $kernels; do
case "$kernel" in
*-nvidia-open) modules+=" ${kernel}";;
*-headers|*-zfs|*-nvidia|*-dbg);;
*) modules+=" ${kernel}-nvidia-open";;
*) packages+=" ${kernel}-nvidia-open";;
esac
done

# Fallback if there are no kernels with pre-built modules
[ -z "$modules" ] && modules="nvidia-open-dkms"
[ -z "$packages" ] && packages="nvidia-open-dkms"

# Trying to determine the laptop
device_type="$(cat /sys/devices/virtual/dmi/id/chassis_type)"
if ((device_type >= 8 && device_type <= 11)); then
packages+=" nvidia-prime switcheroo-control"
fi

echo "$modules"
echo "$packages"

"""
post_install = """
Expand All @@ -47,35 +54,20 @@ MODULES+=(nvidia nvidia_modeset nvidia_uvm nvidia_drm)
EOF
mkinitcpio -P

# Add libva-nvidia-driver to profile
echo "export LIBVA_DRIVER_NAME=nvidia" > /etc/profile.d/nvidia-vaapi.sh
# Trying to determine the laptop
device_type="$(cat /sys/devices/virtual/dmi/id/chassis_type)"
if ((device_type >= 8 && device_type <= 11)); then
systemctl enable switcheroo-control
else
# Add libva-nvidia-driver to profile
echo "export LIBVA_DRIVER_NAME=nvidia" > /etc/profile.d/nvidia-vaapi.sh
fi
"""
post_remove = """
rm -f /etc/mkinitcpio.conf.d/10-chwd.conf
rm -f /etc/profile.d/nvidia-vaapi.sh
mkinitcpio -P
"""
device_name_pattern = '([A-Z]+[0-9]+[^M]*)\s.*'

[nvidia-open-dkms.prime]
desc = 'Open source NVIDIA drivers for Linux (Latest)'
class_ids = "0300 0302 0380"
device_name_pattern = '([A-Z]+[0-9]+[A-Z]*M)\s.*'
priority = 11
packages = 'nvidia-utils egl-wayland nvidia-settings opencl-nvidia lib32-opencl-nvidia lib32-nvidia-utils vulkan-icd-loader lib32-vulkan-icd-loader nvidia-prime switcheroo-control'
post_install = """
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
mkinitcpio -P
systemctl enable switcheroo-control
"""
post_remove = """
rm -f /etc/mkinitcpio.conf.d/10-chwd.conf
mkinitcpio -P
"""


[nvidia-dkms]
desc = 'Closed source NVIDIA drivers for Linux (Latest)'
Expand All @@ -85,20 +77,27 @@ priority = 12
packages = 'nvidia-utils egl-wayland nvidia-settings opencl-nvidia lib32-opencl-nvidia lib32-nvidia-utils libva-nvidia-driver vulkan-icd-loader lib32-vulkan-icd-loader'
conditional_packages = """
kernels="$(pacman -Qqs "^linux-cachyos")"
modules=""
packages=""

for kernel in $kernels; do
case "$kernel" in
*-headers|*-zfs|*-nvidia-open|*-dbg);;
*-nvidia) modules+=" ${kernel}";;
*) modules+=" ${kernel}-nvidia";;
*-nvidia) packages+=" ${kernel}";;
*) packages+=" ${kernel}-nvidia";;
esac
done

# Fallback if there are no kernels with pre-built modules
[ -z "$modules" ] && modules="nvidia-dkms"
[ -z "$packages" ] && packages="nvidia-dkms"


# Trying to determine the laptop
device_type="$(cat /sys/devices/virtual/dmi/id/chassis_type)"
if [[ "$device_type" -ge 8 && "$device_type" -le 11 ]]; then
packages+=" nvidia-prime switcheroo-control"
fi

echo "$modules"
echo "$packages"

"""
post_install = """
Expand All @@ -108,73 +107,64 @@ MODULES+=(nvidia nvidia_modeset nvidia_uvm nvidia_drm)
EOF
mkinitcpio -P

# Add libva-nvidia-driver to profile
echo "export LIBVA_DRIVER_NAME=nvidia" > /etc/profile.d/nvidia-vaapi.sh
# Trying to determine the laptop
device_type="$(cat /sys/devices/virtual/dmi/id/chassis_type)"
if ((device_type >= 8 && device_type <= 11)); then
systemctl enable switcheroo-control
else
# Add libva-nvidia-driver to profile
echo "export LIBVA_DRIVER_NAME=nvidia" > /etc/profile.d/nvidia-vaapi.sh
fi
"""
post_remove = """
rm -f /etc/mkinitcpio.conf.d/10-chwd.conf
rm -f /etc/profile.d/nvidia-vaapi.sh
mkinitcpio -P
"""
device_name_pattern = '((GM|GP)+[0-9]+[^M]*\s.*)'

[nvidia-dkms.prime]
desc = 'Closed source NVIDIA drivers for Linux (Latest)'
class_ids = "0300 0302 0380"
device_name_pattern = '((GM|GP)+[0-9]+[A-Z]*M\s.*)'
priority = 13
packages = 'nvidia-utils egl-wayland nvidia-settings opencl-nvidia lib32-opencl-nvidia lib32-nvidia-utils vulkan-icd-loader lib32-vulkan-icd-loader nvidia-prime switcheroo-control'
post_install = """
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
mkinitcpio -P
systemctl enable switcheroo-control
"""
post_remove = """
rm -f /etc/mkinitcpio.conf.d/10-chwd.conf
mkinitcpio -P
"""
device_name_pattern = '(GM|GP)\w+'

[nvidia-dkms-470xx]
desc = 'Closed source NVIDIA drivers for Linux (470xx branch, only for Kepler GPUs)'
priority = 14
class_ids = "0300 0380"
class_ids = "0300 0302 0380"
vendor_ids = "10de"
device_ids = '>/var/lib/chwd/ids/nvidia-470.ids'
packages = 'nvidia-470xx-dkms nvidia-470xx-utils nvidia-470xx-settings opencl-nvidia-470xx vulkan-icd-loader lib32-nvidia-470xx-utils lib32-opencl-nvidia-470xx lib32-vulkan-icd-loader libva-nvidia-driver'
device_name_pattern = '(GK)\w+'
conditional_packages = """
# Trying to determine the laptop
device_type="$(cat /sys/devices/virtual/dmi/id/chassis_type)"
if ((device_type >= 8 && device_type <= 11)); then
echo "nvidia-prime switcheroo-control"
fi
"""
post_install = """
# Add libva-nvidia-driver to profile
echo "export LIBVA_DRIVER_NAME=nvidia" > /etc/profile.d/nvidia-vaapi.sh
# Trying to determine the laptop
device_type="$(cat /sys/devices/virtual/dmi/id/chassis_type)"
if ((device_type >= 8 && device_type <= 11)); then
systemctl enable switcheroo-control
else
# Add libva-nvidia-driver to profile
echo "export LIBVA_DRIVER_NAME=nvidia" > /etc/profile.d/nvidia-vaapi.sh
fi
"""
post_remove = """
rm -f /etc/profile.d/nvidia-vaapi.sh
"""

[nvidia-dkms-470xx.prime]
desc = 'Closed source NVIDIA drivers for Linux (470xx branch, only for Kepler GPUs)'
priority = 15
class_ids = "0302"
packages = 'nvidia-470xx-dkms nvidia-470xx-utils nvidia-470xx-settings opencl-nvidia-470xx vulkan-icd-loader lib32-nvidia-470xx-utils lib32-opencl-nvidia-470xx lib32-vulkan-icd-loader switcheroo-control nvidia-prime'
device_name_pattern = '(GK)\w+'
post_install = """
systemctl enable switcheroo-control
"""

[nvidia-dkms-390xx]
desc = 'Closed source NVIDIA drivers for Linux (390xx branch, only for Fermi GPUs)'
priority = 16
vendor_ids = "10de"
class_ids = "0300 0302 0380"
packages = 'nvidia-390xx-dkms nvidia-390xx-utils nvidia-390xx-settings opencl-nvidia-390xx nvidia-390xx-utils nvidia-390xx-settings opencl-nvidia-390xx lib32-nvidia-390xx-utils lib32-opencl-nvidia-390xx'
device_name_pattern = '(GF)\w+'
device_ids = '>/var/lib/chwd/ids/nvidia-390.ids'

[nouveau]
desc = "Open Nouveau driver for NVIDIA graphics cards (Only for old GPUs)"
class_ids = "0300 0302"
vendor_ids = "10de"
priority = 9
device_ids = '>/var/lib/chwd/ids/nouveau.ids'
priority = 18
packages = 'mesa lib32-mesa libva-mesa-driver mesa-vdpau lib32-libva-mesa-driver vulkan-nouveau'
conditional_packages = """
if [ -z "$(lspci -d "10de:*:030x")" ]; then
Expand Down
110 changes: 110 additions & 0 deletions scripts/nvidia-pci-ids-dumper/nvidia-pci-ids-dumper
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/usr/bin/env lua
--[[
Copyright (C) 2024 Vasiliy Stelmachenok for CachyOS

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
--]]
local found, json = pcall(require, 'dkjson')

local code = 0

local function err(msg, ...)
print(msg:format(...))
code = 1
end

if not found then
err("lua-dkjson dependency is missing, please install it from repositories")
os.exit(1)
end

local function write(generations)
for driver, ids in pairs(generations) do
local fname = "nvidia-" .. driver:match("([^.]+)") .. ".ids"
if driver == "nouveau" then
fname = "nouveau.ids"
end

local devices = {}
for id in pairs(ids) do
devices[#devices+1] = id
end

local hwdb, errmsg = io.open(fname, "w+")
if hwdb then
local content = table.concat(devices, " ")
hwdb:write(content .. "\n")
else
err("Failed to write PCI ids: %s", errmsg)
end
end
end

local function parse(chips)
local drivers = {
["390.xx"] = {},
["470.xx"] = {},
["nouveau"] = {}
}
for _, chip in ipairs(chips) do
if chip.legacybranch then
local id = chip.devid:gsub("0x", ""):lower()
local branch = chip.legacybranch
if branch == "470.xx" then
drivers[branch][id] = true
elseif branch == "390.xx" then
drivers[branch][id] = true
else
drivers["nouveau"][id] = true
end
end
end

return drivers
end

local function main()
if #arg < 1 then
err("Specify path to the supported-gpu.json file")
vnepogodin marked this conversation as resolved.
Show resolved Hide resolved
os.exit(0)
end

local path = arg[1]
local file, errmsg = io.open(path, "r")

if file ~= nil then
local raw = file:read()

if raw then
local supported_gpus = json.decode(raw)

if supported_gpus.chips then
local generations = parse(supported_gpus.chips)
write(generations)
else
err("Failed to parse supported_gpus.json")
end
else
err("Failed to read file %s", path)
end

file:close()
else
err("Failed to open %s file: %s", path, errmsg)
end
end

main()
os.exit(code)
Loading