Skip to content

Commit

Permalink
feat: vfio-manager graphics mode
Browse files Browse the repository at this point in the history
Signed-off-by: Joji Mekkattuparamban <jojim@nvidia.com>
  • Loading branch information
jojimt committed Jul 2, 2024
1 parent 02c2e68 commit 7939359
Showing 1 changed file with 49 additions and 5 deletions.
54 changes: 49 additions & 5 deletions scripts/vfio-manage
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ unbind_device() {

echo "unbinding device $gpu"
unbind_from_driver $gpu
#for graphics mode, we need to unbind the auxiliary device as well
aux_dev=$(get_graphics_aux_dev "$gpu")
if [ "$aux_dev" != "NONE" ]; then
echo "gpu $gpu is in graphics mode aux_dev $aux_dev"
unbind_from_driver "$aux_dev"
fi
}

unbind_all() {
Expand All @@ -97,13 +103,9 @@ unbind_all() {
done
}

bind_device() {
bind_pci_device() {
local gpu=$1

if ! is_nvidia_gpu_device $gpu; then
return 0
fi

if ! is_bound_to_vfio $gpu; then
unbind_from_other_driver $gpu
echo "binding device $gpu"
Expand All @@ -114,6 +116,48 @@ bind_device() {
fi
}

get_graphics_aux_dev() {
local gpu=$1
device_class_file=$(readlink -f "/sys/bus/pci/devices/$gpu/class")
device_class=$(cat "$device_class_file")
if [ "$device_class" != "0x030000" ]; then
echo "NONE"
return
fi

if ls "/sys/bus/pci/devices/$gpu" | grep consumer >& /dev/null; then
aux_dev=$(ls "/sys/bus/pci/devices/$gpu" | grep consumer | awk -Fconsumer:pci: '{print $2}')
if [ "$aux_dev" == "" ]; then
echo "NONE"
return
fi

if ls "/sys/bus/pci/devices/$aux_dev/" >& /dev/null; then
echo "$aux_dev"
return
fi
fi

echo "NONE"
}

bind_device() {
local gpu=$1

if ! is_nvidia_gpu_device $gpu; then
echo "device $gpu is not a gpu!"
return 0
fi

bind_pci_device "$gpu"
#for graphics mode, we need to bind the auxiliary device as well
aux_dev=$(get_graphics_aux_dev "$gpu")
if [ "$aux_dev" != "NONE" ]; then
echo "gpu $gpu is in graphics mode aux_dev $aux_dev"
bind_pci_device "$aux_dev"
fi
}

bind_all() {
for dev in /sys/bus/pci/devices/*; do
read vendor < $dev/vendor
Expand Down

0 comments on commit 7939359

Please sign in to comment.