Commit 75fc5ca5 authored by TotallyNotElite's avatar TotallyNotElite Committed by Philip Müller

[nvidia] Driver 450 support

Who even cares about code duplication anymore, am I right?

In all honesty, some of this stuff needs to be moved to the 0300 script maybe?
parent 535c50a9
#!/bin/bash
VERSIONLIST=("340" "390" "418" "430" "435" "440" "450")
PRIORITY=0
# $1 template path
# $2 output path
# $3 version
# $4 priority
function generateConfigForVersion
{
[ ! -z "$4" ] && PRIORITY="$4"
local CONFLICTS=()
local CONFLICTS_64=()
local CONKMOD=()
# Generate conflicts for version
for i in "${VERSIONLIST[@]/$3}"
do
[ -z "$i" ] && continue
CONFLICTS+=("nvidia-${i}xx-utils")
CONFLICTS_64+=("lib32-nvidia-${i}xx-utils")
CONKMOD+=("nvidia-${i}xx")
done
CONFLICTS="${CONFLICTS[@]}"
CONFLICTS_64="${CONFLICTS_64[@]}"
CONKMOD="${CONKMOD[@]}"
mkdir "$2"
sed -e "s/%VERSION%/${3}/g; s/%PRIORITY%/${PRIORITY}/g; s/%CONFLICTS%/${CONFLICTS}/g; s/%CONFLICTS_64%/${CONFLICTS_64}/g; s/%CONKMOD%/${CONKMOD}/g" "$1" > "${2}/MHWDCONFIG"
let "PRIORITY++"
}
# disable nvidia on i686
[ "${CARCH}" = "i686" ] && exit 0
# Stock nvidia drivers
generateConfigForVersion templates/nvidia-xxxxx ./pci/graphic_drivers/nvidia-340xx 340 3
generateConfigForVersion templates/nvidia-xxxxx ./pci/graphic_drivers/nvidia-390xx 390
generateConfigForVersion templates/nvidia-xxxxx ./pci/graphic_drivers/nvidia-418xx 418
generateConfigForVersion templates/nvidia-xxxxx ./pci/graphic_drivers/nvidia-430xx 430
generateConfigForVersion templates/nvidia-xxxxx ./pci/graphic_drivers/nvidia-435xx 435
generateConfigForVersion templates/nvidia-xxxxx ./pci/graphic_drivers/nvidia-440xx 440
generateConfigForVersion templates/nvidia-xxxxx ./pci/graphic_drivers/nvidia-450xx 450 # 9
# Bumblebee
generateConfigForVersion templates/hybrid-intel-nvidia-xxxxx-bumblebee ./pci/graphic_drivers/hybrid-intel-nvidia-340xx-bumblebee 340 10
generateConfigForVersion templates/hybrid-intel-nvidia-xxxxx-bumblebee ./pci/graphic_drivers/hybrid-intel-nvidia-390xx-bumblebee 390
generateConfigForVersion templates/hybrid-intel-nvidia-xxxxx-bumblebee ./pci/graphic_drivers/hybrid-intel-nvidia-418xx-bumblebee 418
generateConfigForVersion templates/hybrid-intel-nvidia-xxxxx-bumblebee ./pci/graphic_drivers/hybrid-intel-nvidia-430xx-bumblebee 430 # 13
# Prime intel
generateConfigForVersion templates/hybrid-intel-nvidia-xxxxx-prime ./pci/graphic_drivers/hybrid-intel-nvidia-435xx-prime 435 15
generateConfigForVersion templates/hybrid-intel-nvidia-xxxxx-prime ./pci/graphic_drivers/hybrid-intel-nvidia-440xx-prime 440
generateConfigForVersion templates/hybrid-intel-nvidia-xxxxx-prime ./pci/graphic_drivers/hybrid-intel-nvidia-450xx-prime 450 # 17
# Prime amd
generateConfigForVersion templates/hybrid-amd-nvidia-xxxxx-prime ./pci/graphic_drivers/hybrid-amd-nvidia-435xx-prime 435 15
generateConfigForVersion templates/hybrid-amd-nvidia-xxxxx-prime ./pci/graphic_drivers/hybrid-amd-nvidia-440xx-prime 440
generateConfigForVersion templates/hybrid-amd-nvidia-xxxxx-prime ./pci/graphic_drivers/hybrid-amd-nvidia-450xx-prime 450 # 17
# mhwd Driver Config
NAME="video-hybrid-amd-nvidia-435xx-prime"
INFO="Hybrid prime solution for NVIDIA Optimus Technology - Closed source NVIDIA driver & open source amd driver."
VERSION="2020.03.26"
FREEDRIVER="false"
PRIORITY="20"
# NVIDIA cards
CLASSIDS="0300 0302"
VENDORIDS="10de"
DEVICEIDS=">/var/lib/mhwd/ids/pci/nvidia-435xx.ids"
# Amd cards
CLASSIDS="0300"
VENDORIDS="1002"
DEVICEIDS="*"
# Conflicts
CONFLICTS="nvidia-340xx-utils nvidia-390xx-utils nvidia-418xx-utils nvidia-430xx-utils nvidia-440xx-utils"
CONFLICTS_64="lib32-nvidia-340xx-utils lib32-nvidia-390xx-utils lib32-nvidia-418xx-utils lib32-nvidia-430xx-utils lib32-nvidia-440xx-utils"
CONKMOD="nvidia-340xx nvidia-390xx nvidia-418xx nvidia-430xx nvidia-440xx"
# Conflicts with other mhwd configs
MHWDCONFLICTS="video-hybrid-intel-nvidia-340xx-bumblebee video-hybrid-intel-nvidia-390xx-bumblebee video-hybrid-intel-nvidia-418xx-bumblebee video-hybrid-intel-nvidia-430xx-bumblebee video-hybrid-intel-nvidia-440xx-prime video-nvidia-340xx video-nvidia-390xx video-nvidia-418xx video-nvidia-430xx video-nvidia-435xx video-nvidia-440xx video-hybrid-intel-nvidia-435xx-prime video-hybrid-amd-nvidia-440xx-prime"
# Dependencies (nvidia-prime dependency is technically optional, but adds the prime-run command)
DEPENDS="nvidia-435xx-utils nvidia-prime xf86-video-amdgpu"
DEPENDS_64="lib32-nvidia-435xx-utils"
DEPKMOD="nvidia-435xx"
XORGFILE="/etc/X11/mhwd.d/nvidia.conf"
UDEVFILE="/lib/udev/rules.d/90-mhwd-prime-powermanagement.rules"
MHWDGPU_BLCKLSTNVIDIA="/etc/modprobe.d/mhwd-gpu.conf"
MHWDGPU_MODLDNVIDIA="/etc/modules-load.d/mhwd-gpu.conf"
_setup_nvidia_powermanagememnt()
{
cat <<EOF > "${UDEVFILE}"
# Remove NVIDIA USB xHCI Host Controller devices, if present
ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x0c0330", ATTR{remove}="1"
# Remove NVIDIA USB Type-C UCSI devices, if present
ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x0c8000", ATTR{remove}="1"
# Remove NVIDIA Audio devices, if present
ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x040300", ATTR{remove}="1"
# Enable runtime PM for NVIDIA VGA/3D controller devices on driver bind
ACTION=="bind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030000", TEST=="power/control", ATTR{power/control}="auto"
ACTION=="bind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030200", TEST=="power/control", ATTR{power/control}="auto"
# Disable runtime PM for NVIDIA VGA/3D controller devices on driver unbind
ACTION=="unbind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030000", TEST=="power/control", ATTR{power/control}="on"
ACTION=="unbind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030200", TEST=="power/control", ATTR{power/control}="on"
EOF
echo 'options nvidia "NVreg_DynamicPowerManagement=0x02"' > "${MHWDGPU_BLCKLSTNVIDIA}"
}
post_install()
{
# Create an empty Xorg config file, configuration is already provided by nvidia-*-utils
MHWD_HEADING "${XORGFILE}"
mhwd-gpu --setmod nvidia --setxorg "${XORGFILE}"
_setup_nvidia_powermanagememnt
# Without this 'glxgears' doesn't work in live-session
MODULES_LOAD="/etc/modules-load.d"
echo "nvidia-drm" >> "${MODULES_LOAD}/mhwd-gpu.conf"
if [ ! "$(pgrep X)" ]; then
modprobe nvidia-drm
fi
}
post_remove()
{
rm -f "${XORGFILE}"
rm -f "${UDEVFILE}"
if [ -f "${MHWDGPU_BLCKLSTNVIDIA}" ]; then
sed -i '/^blacklist nouveau/d' "${MHWDGPU_BLCKLSTNVIDIA}"
sed -i '/^blacklist ttm/d' "${MHWDGPU_BLCKLSTNVIDIA}"
sed -i '/^blacklist drm_kms_helper/d' "${MHWDGPU_BLCKLSTNVIDIA}"
sed -i '/^blacklist drm/d' "${MHWDGPU_BLCKLSTNVIDIA}"
sed -i '/^options nvidia "NVreg_DynamicPowerManagement=0x02"/d' "${MHWDGPU_BLCKLSTNVIDIA}"
fi
if [ -f "${MHWDGPU_MODLDNVIDIA}" ]; then
sed -i '/^nvidia/d' "${MHWDGPU_MODLDNVIDIA}"
fi
mhwd-gpu --check
}
# mhwd Driver Config
NAME="video-hybrid-intel-nvidia-340xx-bumblebee"
INFO="Hybrid bumblebee solution for NVIDIA Optimus Technology - Closed source NVIDIA legacy driver & open source intel driver."
VERSION="2019.10.25"
FREEDRIVER="false"
PRIORITY="9"
# NVIDIA cards
CLASSIDS="0300 0302"
VENDORIDS="10de"
DEVICEIDS=">/var/lib/mhwd/ids/pci/nvidia-340xx.ids"
# Intel cards
CLASSIDS="0300"
VENDORIDS="8086"
DEVICEIDS="*"
BLACKLISTEDDEVICEIDS="0be1 8108"
# Conflicts with other mhwd configs
MHWDCONFLICTS="video-hybrid-amd-nvidia-435xx-prime video-hybrid-amd-nvidia-440xx-prime video-hybrid-intel-nvidia-340xx-bumblebee video-hybrid-intel-nvidia-390xx-bumblebee video-hybrid-intel-nvidia-418xx-bumblebee video-hybrid-intel-nvidia-430xx-bumblebee video-hybrid-intel-nvidia-435xx-prime video-hybrid-intel-nvidia-440xx-prime video-nvidia-340xx video-nvidia-390xx video-nvidia-418xx video-nvidia-430xx video-nvidia-435xx video-nvidia-440xx [elite@elite-pc nvidia-440xx"
# Dependencies
DEPENDS="bumblebee nvidia-340xx-utils xf86-video-intel"
[[ -d /run/openrc ]] && DEPENDS="bumblebee-openrc nvidia-340xx-utils xf86-video-intel"
DEPENDS_64="lib32-primus lib32-nvidia-340xx-utils"
DEPKMOD="nvidia-340xx bbswitch"
XORGFILE="/etc/X11/mhwd.d/intel.conf"
BXORGFILE="/etc/bumblebee/xorg.conf.nvidia"
MODULESFILE="/etc/modprobe.d/mhwd-bbswitch.conf"
MODULESBLACKLIST="/etc/modprobe.d/mhwd-nvidia.conf"
make_bumblebee_xorg_config()
{
MHWD_HEADING "${BXORGFILE}"
echo 'Section "ServerLayout"' >> "${BXORGFILE}"
echo ' Identifier "Layout0"' >> "${BXORGFILE}"
echo ' Option "AutoAddDevices" "false"' >> "${BXORGFILE}"
echo 'EndSection' >> "${BXORGFILE}"
echo '' >> "${BXORGFILE}"
MHWD_ADD_DEVICE_SECTION_FOR_EACH_BUSID "nvidia" "${BXORGFILE}" 10de "VendorName \"NVIDIA Corporation\"|Option \"NoLogo\" \"true\"|Option \"UseEDID\" \"false\"|Option \"ConnectedMonitor\" \"DFP\""
}
post_install()
{
# Create intel xorg configuration with enabled sna acceleration method
MHWD_HEADING "${XORGFILE}"
MHWD_ADD_DEVICE_SECTION_FOR_EACH_BUSID "intel" "${XORGFILE}" 8086 "Option \"AccelMethod\" \"sna\""
MHWD_ADD_DRI "${XORGFILE}"
MHWD_ADD_COMPOSITING "${XORGFILE}"
MHWD_ADD_BACKSPACE "${XORGFILE}"
# Create nvidia bumblebee xorg configuration
make_bumblebee_xorg_config
MHWD_HEADING "${MODULESFILE}"
echo "options bbswitch load_state=0 unload_state=0" >> "${MODULESFILE}"
MHWD_HEADING "${MODULESBLACKLIST}"
echo "blacklist nouveau" >> "${MODULESBLACKLIST}"
echo "blacklist nvidia" >> "${MODULESBLACKLIST}"
echo "blacklist nvidia-modeset" >> "${MODULESBLACKLIST}"
echo "blacklist nvidia-uvm" >> "${MODULESBLACKLIST}"
echo "blacklist ttm" >> "${MODULESBLACKLIST}"
echo "blacklist drm_kms_helper" >> "${MODULESBLACKLIST}"
echo "blacklist drm" >> "${MODULESBLACKLIST}"
# Unload modules if X is not running
if [ ! "$(pgrep X)" ]; then
rmmod -f nouveau
rmmod -f nvidia
rmmod -f nvidia-modeset
rmmod -f nvidia-uvm
rmmod -f ttm
rmmod -f drm_kms_helper
rmmod -f drm
fi
modprobe bbswitch
set_bumblebee_driver "nvidia"
mhwd-gpu --setxorg "${XORGFILE}"
if [[ -d /run/openrc ]];then
rc-update add bumblebee default
rc-service bumblebee start
else
systemctl enable bumblebeed.service
systemctl start bumblebeed.service
fi
}
pre_remove()
{
modprobe -r bbswitch
if [[ -d /run/openrc ]];then
rc-update del bumblebee default
rc-service bumblebee stop
else
systemctl disable bumblebeed.service
systemctl stop bumblebeed.service
fi
}
post_remove()
{
if [ -e "${XORGFILE}" ]; then
rm "${XORGFILE}"
fi
if [ -e "${MODULESFILE}" ]; then
rm "${MODULESFILE}"
fi
if [ -e "${MODULESBLACKLIST}" ]; then
rm "${MODULESBLACKLIST}"
fi
mhwd-gpu --check
}
set_bumblebee_driver()
{
sed -i "/(#)/!s/^[ ]*Driver[ ]*=.*/Driver=$1/g" /etc/bumblebee/bumblebee.conf
}
# mhwd Driver Config
NAME="video-hybrid-intel-nvidia-418xx-bumblebee"
INFO="Hybrid bumblebee solution for NVIDIA Optimus Technology - Closed source NVIDIA driver & open source intel driver."
VERSION="2019.10.25"
FREEDRIVER="false"
PRIORITY="11"
# NVIDIA cards
CLASSIDS="0300 0302"
VENDORIDS="10de"
DEVICEIDS=">/var/lib/mhwd/ids/pci/nvidia-418xx.ids"
# Intel cards
CLASSIDS="0300"
VENDORIDS="8086"
DEVICEIDS="*"
BLACKLISTEDDEVICEIDS="0be1 8108"
# Conflicts with other mhwd configs
MHWDCONFLICTS="video-hybrid-amd-nvidia-435xx-prime video-hybrid-amd-nvidia-440xx-prime video-hybrid-intel-nvidia-340xx-bumblebee video-hybrid-intel-nvidia-390xx-bumblebee video-hybrid-intel-nvidia-418xx-bumblebee video-hybrid-intel-nvidia-430xx-bumblebee video-hybrid-intel-nvidia-435xx-prime video-hybrid-intel-nvidia-440xx-prime video-nvidia-340xx video-nvidia-390xx video-nvidia-418xx video-nvidia-430xx video-nvidia-435xx video-nvidia-440xx [elite@elite-pc nvidia-440xx"
# Dependencies
DEPENDS="bumblebee nvidia-418xx-utils xf86-video-intel"
[[ -d /run/openrc ]] && DEPENDS="bumblebee-openrc nvidia-utils xf86-video-intel"
DEPENDS_64="lib32-primus lib32-nvidia-418xx-utils"
DEPKMOD="nvidia-418xx bbswitch"
XORGFILE="/etc/X11/mhwd.d/intel.conf"
BXORGFILE="/etc/bumblebee/xorg.conf.nvidia"
MODULESFILE="/etc/modprobe.d/mhwd-bbswitch.conf"
MODULESBLACKLIST="/etc/modprobe.d/mhwd-nvidia.conf"
make_bumblebee_xorg_config()
{
MHWD_HEADING "${BXORGFILE}"
echo 'Section "ServerLayout"' >> "${BXORGFILE}"
echo ' Identifier "Layout0"' >> "${BXORGFILE}"
echo ' Option "AutoAddDevices" "false"' >> "${BXORGFILE}"
echo 'EndSection' >> "${BXORGFILE}"
echo '' >> "${BXORGFILE}"
MHWD_ADD_DEVICE_SECTION_FOR_EACH_BUSID "nvidia" "${BXORGFILE}" 10de "VendorName \"NVIDIA Corporation\"|Option \"NoLogo\" \"true\"|Option \"UseEDID\" \"false\"|Option \"ConnectedMonitor\" \"DFP\""
}
post_install()
{
# Create intel xorg configuration with enabled sna acceleration method
MHWD_HEADING "${XORGFILE}"
MHWD_ADD_DEVICE_SECTION_FOR_EACH_BUSID "intel" "${XORGFILE}" 8086 "Option \"AccelMethod\" \"sna\""
MHWD_ADD_DRI "${XORGFILE}"
MHWD_ADD_COMPOSITING "${XORGFILE}"
MHWD_ADD_BACKSPACE "${XORGFILE}"
# Create nvidia bumblebee xorg configuration
make_bumblebee_xorg_config
MHWD_HEADING "${MODULESFILE}"
echo "options bbswitch load_state=0 unload_state=0" >> "${MODULESFILE}"
MHWD_HEADING "${MODULESBLACKLIST}"
echo "blacklist nouveau" >> "${MODULESBLACKLIST}"
echo "blacklist nvidia" >> "${MODULESBLACKLIST}"
echo "blacklist nvidia-modeset" >> "${MODULESBLACKLIST}"
echo "blacklist nvidia-uvm" >> "${MODULESBLACKLIST}"
echo "blacklist ttm" >> "${MODULESBLACKLIST}"
echo "blacklist drm_kms_helper" >> "${MODULESBLACKLIST}"
echo "blacklist drm" >> "${MODULESBLACKLIST}"
# Unload modules if X is not running
if [ ! "$(pgrep X)" ]; then
rmmod -f nouveau
rmmod -f nvidia
rmmod -f nvidia-modeset
rmmod -f nvidia-uvm
rmmod -f ttm
rmmod -f drm_kms_helper
rmmod -f drm
fi
modprobe bbswitch
set_bumblebee_driver "nvidia"
mhwd-gpu --setxorg "${XORGFILE}"
if [[ -d /run/openrc ]];then
rc-update add bumblebee default
rc-service bumblebee start
else
systemctl enable bumblebeed.service
systemctl start bumblebeed.service
fi
}
pre_remove()
{
modprobe -r bbswitch
if [[ -d /run/openrc ]];then
rc-update del bumblebee default
rc-service bumblebee stop
else
systemctl disable bumblebeed.service
systemctl stop bumblebeed.service
fi
}
post_remove()
{
if [ -e "${XORGFILE}" ]; then
rm "${XORGFILE}"
fi
if [ -e "${MODULESFILE}" ]; then
rm "${MODULESFILE}"
fi
if [ -e "${MODULESBLACKLIST}" ]; then
rm "${MODULESBLACKLIST}"
fi
mhwd-gpu --check
}
set_bumblebee_driver()
{
sed -i "/(#)/!s/^[ ]*Driver[ ]*=.*/Driver=$1/g" /etc/bumblebee/bumblebee.conf
}
# mhwd Driver Config
NAME="video-hybrid-intel-nvidia-430xx-bumblebee"
INFO="Hybrid bumblebee solution for NVIDIA Optimus Technology - Closed source NVIDIA driver & open source intel driver."
VERSION="2019.10.25"
FREEDRIVER="false"
PRIORITY="12"
# NVIDIA cards
CLASSIDS="0300 0302"
VENDORIDS="10de"
DEVICEIDS=">/var/lib/mhwd/ids/pci/nvidia-430xx.ids"
# Intel cards
CLASSIDS="0300"
VENDORIDS="8086"
DEVICEIDS="*"
BLACKLISTEDDEVICEIDS="0be1 8108"
# Conflicts with other mhwd configs
MHWDCONFLICTS="video-hybrid-amd-nvidia-435xx-prime video-hybrid-amd-nvidia-440xx-prime video-hybrid-intel-nvidia-340xx-bumblebee video-hybrid-intel-nvidia-390xx-bumblebee video-hybrid-intel-nvidia-418xx-bumblebee video-hybrid-intel-nvidia-430xx-bumblebee video-hybrid-intel-nvidia-435xx-prime video-hybrid-intel-nvidia-440xx-prime video-nvidia-340xx video-nvidia-390xx video-nvidia-418xx video-nvidia-430xx video-nvidia-435xx video-nvidia-440xx [elite@elite-pc nvidia-440xx"
# Dependencies
DEPENDS="bumblebee nvidia-430xx-utils xf86-video-intel"
[[ -d /run/openrc ]] && DEPENDS="bumblebee-openrc nvidia-utils xf86-video-intel"
DEPENDS_64="lib32-primus lib32-nvidia-430xx-utils"
DEPKMOD="nvidia-430xx bbswitch"
XORGFILE="/etc/X11/mhwd.d/intel.conf"
BXORGFILE="/etc/bumblebee/xorg.conf.nvidia"
MODULESFILE="/etc/modprobe.d/mhwd-bbswitch.conf"
MODULESBLACKLIST="/etc/modprobe.d/mhwd-nvidia.conf"
make_bumblebee_xorg_config()
{
MHWD_HEADING "${BXORGFILE}"
echo 'Section "ServerLayout"' >> "${BXORGFILE}"
echo ' Identifier "Layout0"' >> "${BXORGFILE}"
echo ' Option "AutoAddDevices" "false"' >> "${BXORGFILE}"
echo 'EndSection' >> "${BXORGFILE}"
echo '' >> "${BXORGFILE}"
MHWD_ADD_DEVICE_SECTION_FOR_EACH_BUSID "nvidia" "${BXORGFILE}" 10de "VendorName \"NVIDIA Corporation\"|Option \"NoLogo\" \"true\"|Option \"UseEDID\" \"false\"|Option \"ConnectedMonitor\" \"DFP\""
}
post_install()
{
# Create intel xorg configuration with enabled sna acceleration method
MHWD_HEADING "${XORGFILE}"
MHWD_ADD_DEVICE_SECTION_FOR_EACH_BUSID "intel" "${XORGFILE}" 8086 "Option \"AccelMethod\" \"sna\""
MHWD_ADD_DRI "${XORGFILE}"
MHWD_ADD_COMPOSITING "${XORGFILE}"
MHWD_ADD_BACKSPACE "${XORGFILE}"
# Create nvidia bumblebee xorg configuration
make_bumblebee_xorg_config
MHWD_HEADING "${MODULESFILE}"
echo "options bbswitch load_state=0 unload_state=0" >> "${MODULESFILE}"
MHWD_HEADING "${MODULESBLACKLIST}"
echo "blacklist nouveau" >> "${MODULESBLACKLIST}"
echo "blacklist nvidia" >> "${MODULESBLACKLIST}"
echo "blacklist nvidia-modeset" >> "${MODULESBLACKLIST}"
echo "blacklist nvidia-uvm" >> "${MODULESBLACKLIST}"
echo "blacklist ttm" >> "${MODULESBLACKLIST}"
echo "blacklist drm_kms_helper" >> "${MODULESBLACKLIST}"
echo "blacklist drm" >> "${MODULESBLACKLIST}"
# Unload modules if X is not running
if [ ! "$(pgrep X)" ]; then
rmmod -f nouveau
rmmod -f nvidia
rmmod -f nvidia-modeset
rmmod -f nvidia-uvm
rmmod -f ttm
rmmod -f drm_kms_helper
rmmod -f drm
fi
modprobe bbswitch
set_bumblebee_driver "nvidia"
mhwd-gpu --setxorg "${XORGFILE}"
if [[ -d /run/openrc ]];then
rc-update add bumblebee default
rc-service bumblebee start
else
systemctl enable bumblebeed.service
systemctl start bumblebeed.service
fi
}
pre_remove()
{
modprobe -r bbswitch
if [[ -d /run/openrc ]];then
rc-update del bumblebee default
rc-service bumblebee stop
else
systemctl disable bumblebeed.service
systemctl stop bumblebeed.service
fi
}
post_remove()
{
if [ -e "${XORGFILE}" ]; then
rm "${XORGFILE}"
fi
if [ -e "${MODULESFILE}" ]; then
rm "${MODULESFILE}"
fi
if [ -e "${MODULESBLACKLIST}" ]; then
rm "${MODULESBLACKLIST}"
fi
mhwd-gpu --check
}
set_bumblebee_driver()
{
sed -i "/(#)/!s/^[ ]*Driver[ ]*=.*/Driver=$1/g" /etc/bumblebee/bumblebee.conf
}
# mhwd Driver Config
NAME="video-hybrid-intel-nvidia-435xx-prime"
INFO="Hybrid prime solution for NVIDIA Optimus Technology - Closed source NVIDIA driver & open source intel driver."
VERSION="2019.10.25"
FREEDRIVER="false"
PRIORITY="20"
# NVIDIA cards
CLASSIDS="0300 0302"
VENDORIDS="10de"
DEVICEIDS=">/var/lib/mhwd/ids/pci/nvidia-435xx.ids"
# Intel cards
CLASSIDS="0300"
VENDORIDS="8086"
DEVICEIDS="*"
BLACKLISTEDDEVICEIDS="0be1 8108"
# Conflicts
CONFLICTS="nvidia-340xx-utils nvidia-390xx-utils nvidia-418xx-utils nvidia-430xx-utils nvidia-440xx-utils"
CONFLICTS_64="lib32-nvidia-340xx-utils lib32-nvidia-390xx-utils lib32-nvidia-418xx-utils lib32-nvidia-430xx-utils lib32-nvidia-440xx-utils"
CONKMOD="nvidia-340xx nvidia-390xx nvidia-418xx nvidia-430xx nvidia-440xx"
# Conflicts with other mhwd configs
MHWDCONFLICTS="video-hybrid-amd-nvidia-435xx-prime video-hybrid-amd-nvidia-440xx-prime video-hybrid-intel-nvidia-340xx-bumblebee video-hybrid-intel-nvidia-390xx-bumblebee video-hybrid-intel-nvidia-418xx-bumblebee video-hybrid-intel-nvidia-430xx-bumblebee video-hybrid-intel-nvidia-435xx-prime video-hybrid-intel-nvidia-440xx-prime video-nvidia-340xx video-nvidia-390xx video-nvidia-418xx video-nvidia-430xx video-nvidia-435xx video-nvidia-440xx [elite@elite-pc nvidia-440xx"
# Dependencies (nvidia-prime dependency is technically optional, but adds the prime-run command)
DEPENDS="nvidia-435xx-utils nvidia-prime"
DEPENDS_64="lib32-nvidia-435xx-utils"
DEPKMOD="nvidia-435xx"
XORGFILE="/etc/X11/mhwd.d/nvidia.conf"
UDEVFILE="/lib/udev/rules.d/90-mhwd-prime-powermanagement.rules"
MHWDGPU_BLCKLSTNVIDIA="/etc/modprobe.d/mhwd-gpu.conf"
MHWDGPU_MODLDNVIDIA="/etc/modules-load.d/mhwd-gpu.conf"
_setup_nvidia_powermanagememnt()
{
cat <<EOF > "${UDEVFILE}"
# Remove NVIDIA USB xHCI Host Controller devices, if present
ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x0c0330", ATTR{remove}="1"
# Remove NVIDIA USB Type-C UCSI devices, if present
ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x0c8000", ATTR{remove}="1"
# Remove NVIDIA Audio devices, if present
ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x040300", ATTR{remove}="1"
# Enable runtime PM for NVIDIA VGA/3D controller devices on driver bind
ACTION=="bind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030000", TEST=="power/control", ATTR{power/control}="auto"
ACTION=="bind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030200", TEST=="power/control", ATTR{power/control}="auto"
# Disable runtime PM for NVIDIA VGA/3D controller devices on driver unbind
ACTION=="unbind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030000", TEST=="power/control", ATTR{power/control}="on"
ACTION=="unbind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030200", TEST=="power/control", ATTR{power/control}="on"
EOF
echo 'options nvidia "NVreg_DynamicPowerManagement=0x02"' > "${MHWDGPU_BLCKLSTNVIDIA}"
}
post_install()
{
# Create an empty Xorg config file, configuration is already provided by nvidia-*-utils
MHWD_HEADING "${XORGFILE}"
mhwd-gpu --setmod nvidia --setxorg "${XORGFILE}"
_setup_nvidia_powermanagememnt
# Without this 'glxgears' doesn't work in live-session
MODULES_LOAD="/etc/modules-load.d"
echo "nvidia-drm" >> "${MODULES_LOAD}/mhwd-gpu.conf"
if [ ! "$(pgrep X)" ]; then
modprobe nvidia-drm
fi
}
post_remove()
{
rm -f "${XORGFILE}"
rm -f "${UDEVFILE}"
if [ -f "${MHWDGPU_BLCKLSTNVIDIA}" ]; then
sed -i '/^blacklist nouveau/d' "${MHWDGPU_BLCKLSTNVIDIA}"
sed -i '/^blacklist ttm/d' "${MHWDGPU_BLCKLSTNVIDIA}"
sed -i '/^blacklist drm_kms_helper/d' "${MHWDGPU_BLCKLSTNVIDIA}"
sed -i '/^blacklist drm/d' "${MHWDGPU_BLCKLSTNVIDIA}"
sed -i '/^options nvidia "NVreg_DynamicPowerManagement=0x02"/d' "${MHWDGPU_BLCKLSTNVIDIA}"
fi
if [ -f "${MHWDGPU_MODLDNVIDIA}" ]; then
sed -i '/^nvidia/d' "${MHWDGPU_MODLDNVIDIA}"