diff --git a/README.md b/README.md index 9f6feb6..eabd4d4 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,7 @@ However, you may not use this method as it is tedious and having two GPUs allows I keep more than one branch for multiple purposes. [There is a personal branch][1] where I have my actual configuration; [a testing branch][2] where I push changes while I am testing new things, it is **NOT stable**; and [a testing-auto branch][3] where I **try** to make everything work automatically. ## Known problems -Audio is not supported, yet. I use an external USB DAC. - -Performance is not important to me at this moment. There is a lot of things that you can do to get better performance. +Audio is not configured on this guide, yet. I use an external USB DAC. MacOS High Sierra does not like USB hubs, therefore anything connected to a hub won't work. Mojave works fine with hubs. diff --git a/scripts/qemu b/scripts/qemu new file mode 100755 index 0000000..2b7ad7a --- /dev/null +++ b/scripts/qemu @@ -0,0 +1,83 @@ +#!/bin/bash + +## IOMMU groups +IOMMU_GPU=06:00.0 +IOMMU_GPU_AUDIO=06:00.1 +IOMMU_USB=07:00.3 +IOMMU_AUDIO=08:00.3 + +## Virsh devices +VIRSH_GPU=pci_0000_06_00_0 +VIRSH_GPU_AUDIO=pci_0000_06_00_1 +VIRSH_USB=pci_0000_07_00_3 +VIRSH_AUDIO=pci_0000_08_00_3 + +## PCI BUS ID +videoid="10de 1184" +audioid="10de 0e0a" +videobusid="0000:${IOMMU_GPU}" +audiobusid="0000:${IOMMU_GPU_AUDIO}" + +## QEMU options +RAM=12G + +## Ulimit +ULIMIT=$(ulimit -a | grep "max locked memory" | awk '{print $6}') +ULIMIT_TARGET=$(( $(echo $RAM | tr -d 'G') * 1048576 + 100000 )) + +## Log file +LOG=/tmp/passthrough.log + +## Virtual interface name +VIRTNAME=virt1 + +if [[ $1 == "win10" ]]; then + if [[ $2 == "prepare" ]]; then + ## Memory lock limit + [[ $ULIMIT != $ULIMIT_TARGET ]] && ulimit -l $ULIMIT_TAGET + + ## Kill the Window Manager + killall i3 > /dev/null 2>&1 + sleep 5 + + ## Remove the framebuffer and console + echo 0 > /sys/class/vtconsole/vtcon0/bind + echo 0 > /sys/class/vtconsole/vtcon1/bind + echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind + + ## Detach the GPU and USB + virsh nodedev-detach $VIRSH_GPU >> $LOG 2>&1 + virsh nodedev-detach $VIRSH_GPU_AUDIO >> $LOG 2>&1 + virsh nodedev-detach $VIRSH_USB >> $LOG 2>&1 + + ## Load vfio + modprobe vfio-pci + + ## Start the network + if [[ $(virsh net-list --all | grep $VIRTNET | awk '{print $2}') != "active" ]]; then + virsh net-start $VIRTNET + fi + + fi + if [[ $2 == 'release' ]]; then + + ## Unload vfio module + modprobe -r vfio-pci + modprobe -r vfio_iommu_type1 + modprobe -r vfio + + ## Reattach the GPU and USB + virsh nodedev-reattach $VIRSH_USB >> $LOG 2>&1 + virsh nodedev-reattach $VIRSH_GPU_AUDIO >> $LOG 2>&1 + virsh nodedev-reattach $VIRSH_GPU >> $LOG 2>&1 + + ## Reload the framebuffer and console + echo 1 > /sys/class/vtconsole/vtcon0/bind + nvidia-xconfig --query-gpu-info > /dev/null 2>&1 + echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind + + ## Restore ulimit + ulimit -l $ULIMIT + + fi +fi