Skip to content

Instantly share code, notes, and snippets.

@EggieCode
Created April 17, 2016 20:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EggieCode/643d1a83286832f7170d77e3f0b293be to your computer and use it in GitHub Desktop.
Save EggieCode/643d1a83286832f7170d77e3f0b293be to your computer and use it in GitHub Desktop.
Bind iommu to vfio-pci
#!/bin/sh
if [ ! -e /sys/kernel/iommu_groups/$1 ]; then
echo "IOMMU group $1 not found"
exit 1
fi
if [ ! -e /sys/bus/pci/drivers/vfio-pci ]; then
sudo modprobe vfio-pci
fi
for i in $(ls /sys/kernel/iommu_groups/$1/devices/); do
if [ -e /sys/kernel/iommu_groups/$1/devices/$i/driver ]; then
if [ "$(basename $(readlink -f \
/sys/kernel/iommu_groups/$1/devices/$i/driver))" != \
"pcieport" ]; then
echo $i | sudo tee \
/sys/kernel/iommu_groups/$1/devices/$i/driver/unbind
fi
fi
done
for i in $(ls /sys/kernel/iommu_groups/$1/devices/); do
if [ ! -e /sys/kernel/iommu_groups/$1/devices/$i/driver ]; then
VEN=$(cat /sys/kernel/iommu_groups/$1/devices/$i/vendor)
DEV=$(cat /sys/kernel/iommu_groups/$1/devices/$i/device)
echo $VEN $DEV | sudo tee \
/sys/bus/pci/drivers/vfio-pci/new_id
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment