22 lines
431 B
Bash
Executable file
22 lines
431 B
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
BASE_PATH=/sys/bus/pci/
|
|
|
|
# sanitize variables
|
|
if [[ "${BASE_PATH: -1}" = '/' ]]; then
|
|
BASE_PATH="${BASE_PATH::${#BASE_PATH}-1}"
|
|
fi
|
|
|
|
vfio_rebind_device() {
|
|
local pci_id
|
|
|
|
pci_id="$1"
|
|
if [[ -e "$BASE_PATH/devices/$pci_id" ]]; then
|
|
echo "$pci_id" | sudo tee "$BASE_PATH/devices/$pci_id/driver/unbind"
|
|
echo "$pci_id" | sudo tee "$BASE_PATH/drivers/vfio-pci/bind"
|
|
fi
|
|
}
|
|
|
|
"$@"
|