Created
April 10, 2016 14:41
-
-
Save TobleMiner/8c6f6e60a4599cf7f9155216f16ed83a to your computer and use it in GitHub Desktop.
VFIO binding service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
modprobe vfio-pci | |
for dev in "$@"; do | |
echo Handling device "$dev" | |
devpath="/sys/bus/pci/devices/$dev" | |
if ! [ -d $devpath ]; then | |
echo "$devpath doesn't exist" | |
exit 1 | |
fi | |
if [ -L $devpath/driver/module ]; then | |
module=`basename "$(readlink $devpath/driver/module)"` | |
if [ -n "`egrep ^vfio <<< $module`" ]; then | |
echo vfio driver already loaded. Skipping $dev | |
continue | |
fi | |
fi | |
vendor=$(cat $devpath/vendor) | |
device=$(cat $devpath/device) | |
echo "Vendor: $vendor Device: $device" | |
if [ -e /sys/bus/pci/devices/$dev/driver ]; then | |
echo $dev > $devpath/driver/unbind | |
echo Unbinding "$dev" | |
fi | |
echo $vendor $device > /sys/bus/pci/drivers/vfio-pci/new_id | |
echo "Bound $dev to vfio" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment