diff --git a/UEFI/README.md b/UEFI/README.md index be05c44..b82aba6 100644 --- a/UEFI/README.md +++ b/UEFI/README.md @@ -117,6 +117,53 @@ I am running Ubuntu 17.04 on Intel i5-6500 + ASUS Z170-AR motherboard + NVIDIA * To reuse the keyboard and mouse devices from the host, setup "Automatic login" in System Preferences in macOS and configure Synergy software. +### USB passthrough notes + +These steps will need to be adapted for your particular setup. + +* Isolate the passthrough PCIe devices with vfio-pci, with the help of `lspci + -nnk` command. + + ``` + $ lspci -nn + ... + 01:00.0 ... NVIDIA Corporation [GeForce GTX 1050 Ti] [10de:1c82] + 01:00.1 Audio device: NVIDIA Corporation Device [10de:0fb9] + 03:00.0 USB controller: ASMedia ASM1142 USB 3.1 Host Controller [1b21:1242] + ``` + + Add `1b21:1242` to `/etc/modprobe.d/vfio.conf` file in the required format. + +* Update initramfs, and then reboot. + + ``` + $ sudo update-initramfs -k all -u + ``` + +* Use the helper scripts to isolate the USB controller. + + ``` + $ scripts/lsgroup.sh + ### Group 7 ### + 00:1c.0 PCI bridge: Intel Corporation Sunrise ... + ### Group 15 ### + 06:00.0 Audio device: Creative Labs Sound Core3D ... + ### Group 5 ### + 00:17.0 SATA controller: Intel Corporation Sunrise ... + ### Group 13 ### + 03:00.0 USB controller: ASMedia ASM1142 USB 3.1 Host Controller + ``` + + ``` + $ scripts/vfio-group.sh 13 + ``` + +* Add `-device vfio-pci,host=03:00.0,bus=pcie.0 \` line to the + `boot-passthrough.sh` script. + +* Boot the VM, and devices attached to the ASMedia USB controller should just + work under macOS. + ### Synergy Notes * Get Synergy from https://sourceforge.net/projects/synergy-stable-builds. diff --git a/scripts/lsgroup.sh b/scripts/lsgroup.sh new file mode 100755 index 0000000..a3259d5 --- /dev/null +++ b/scripts/lsgroup.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# mafferri (https://bbs.archlinux.org) + +BASE="/sys/kernel/iommu_groups" + +for i in $(find $BASE -maxdepth 1 -mindepth 1 -type d); do + GROUP=$(basename $i) + echo "### Group $GROUP ###" + for j in $(find $i/devices -type l); do + DEV=$(basename $j) + echo -n " " + lspci -s $DEV + done +done diff --git a/scripts/vfio-group.sh b/scripts/vfio-group.sh new file mode 100755 index 0000000..bd1c10e --- /dev/null +++ b/scripts/vfio-group.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +# mafferri (https://bbs.archlinux.org) + +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 diff --git a/scripts/vfio-ungroup.sh b/scripts/vfio-ungroup.sh new file mode 100755 index 0000000..f837aeb --- /dev/null +++ b/scripts/vfio-ungroup.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# mafferri (https://bbs.archlinux.org) + +if [ ! -e /sys/kernel/iommu_groups/$1 ]; then + echo "IOMMU group $1 not found" + exit 1 +fi + +for i in $(ls /sys/kernel/iommu_groups/$1/devices/); do + 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/remove_id + echo $i | sudo tee \ + /sys/kernel/iommu_groups/$1/devices/$i/driver/unbind +done + +for i in $(ls /sys/kernel/iommu_groups/$1/devices/); do + echo $i | sudo tee /sys/bus/pci/drivers_probe +done