qemu-vm/qemu-vm-pci
2024-05-13 19:14:45 +02:00

34 lines
814 B
Bash
Executable file

#!/bin/bash
set -euo pipefail
BASE_PATH=/sys/bus/pci/
# sanitize variables
if [[ "${BASE_PATH: -1}" = '/' ]]; then
BASE_PATH="${BASE_PATH::${#BASE_PATH}-1}"
fi
_="${SUDO:=sudo}"
vfio_override_device() {
local pci_id
pci_id="$1"
if [[ -e "$BASE_PATH/devices/$pci_id" ]]; then
echo "vfio-pci" | $SUDO tee \
"$BASE_PATH/devices/$pci_id/driver_override" > /dev/null
fi
}
vfio_rebind_device() {
local pci_id
pci_id="$1"
if [[ -e "$BASE_PATH/devices/$pci_id" ]]; then
[[ -e "$BASE_PATH/devices/$pci_id/driver/unbind" ]] \
&& echo "$pci_id" | $SUDO tee \
"$BASE_PATH/devices/$pci_id/driver/unbind" >/dev/null
echo "$pci_id" | $SUDO tee \
"$BASE_PATH/drivers/vfio-pci/bind" > /dev/null
fi
}
"$@"