single-gpu-passthrough/polaris-vfio-startup.sh

79 lines
2.0 KiB
Bash
Raw Normal View History

2020-04-25 04:32:07 +00:00
#!/bin/bash
# Helpful to read output when debugging
set -x
long_delay=10
medium_delay=5
short_delay=1
echo "Beginning of startup!"
2020-04-25 04:32:07 +00:00
2020-10-04 01:05:49 +00:00
function stop_display_manager_if_running {
if systemctl is-active --quiet $1 ; then
echo $1 >> /tmp/vfio-store-display-manager
systemctl stop $1
fi
while systemctl is-active --quiet $1 ; do
sleep "${short_delay}"
done
}
function unload_module_if_loaded {
if lsmod | grep $1 &> /dev/null ; then
modprobe -r $1
echo $1 >> /tmp/vfio-loaded-gpu-modules
fi
while lsmod | grep $1 &> /dev/null ; do
sleep 1
done
}
# Stop currently running display manager
if test -e "/tmp/vfio-store-display-manager" ; then
rm -f /tmp/vfio-store-display-manager
fi
2020-10-04 01:05:49 +00:00
stop_display_manager_if_running sddm.service
stop_display_manager_if_running gdm.service
stop_display_manager_if_running lightdm.service
stop_display_manager_if_running lxdm.service
stop_display_manager_if_running xdm.service
2020-04-25 04:32:07 +00:00
# Unbind VTconsoles if currently bound
if test -e "/sys/class/vtconsole/vtcon0/bind" ; then
echo 0 > /sys/class/vtconsole/vtcon0/bind
sleep "${long_delay}"
fi
if test -e "/sys/class/vtconsole/vtcon1/bind" ; then
echo 0 > /sys/class/vtconsole/vtcon1/bind
sleep "${long_delay}"
fi
2020-04-25 04:32:07 +00:00
#Unbind EFI-Framebuffer if currently bound
2020-10-04 01:05:49 +00:00
# if test -e "/sys/bus/platform/drivers/efi-framebuffer/unbind" ; then
# echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
# sleep "${medium_delay}"
# else
# echo "Could not find framebuffer to unload!"
# fi
# Unload loaded GPU drivers
if test -e "/tmp/vfio-loaded-gpu-modules" ; then
rm -f /tmp/vfio-loaded-gpu-modules
fi
2020-10-04 01:05:49 +00:00
unload_module_if_loaded amdgpu
unload_module_if_loaded nvidia_drm
unload_module_if_loaded nvidia_modeset
unload_module_if_loaded nvidia_uvm
unload_module_if_loaded nvidia
unload_module_if_loaded ipmi_devintf
2020-04-25 04:32:07 +00:00
# Unbind the GPU from display driver
virsh nodedev-detach pci_0000_01_00_0
virsh nodedev-detach pci_0000_01_00_1
# Load VFIO kernel module
modprobe vfio-pci
echo "End of startup!"