From 0127f0bc868ca524a0e76c62a03da0d4996c10a4 Mon Sep 17 00:00:00 2001 From: HikariKnight <2557889+HikariKnight@users.noreply.github.com> Date: Mon, 28 Feb 2022 19:28:06 +0100 Subject: [PATCH] remove the need to manually type in hardware ids, just grab all hardware ids in the IOMMU group --- lib/get_GPU_GROUP.sh | 19 ++++++++++++------- lib/get_USB_CTL_GROUP.sh | 15 ++++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/get_GPU_GROUP.sh b/lib/get_GPU_GROUP.sh index 5f453ee..1f0e05b 100755 --- a/lib/get_GPU_GROUP.sh +++ b/lib/get_GPU_GROUP.sh @@ -21,27 +21,32 @@ Optionally it may also include: echo "#------------------------------------------#" printf " -To use these devices for passthrough please type in ALL their device ids in the format (without brackets or quotes) --> \"xxxx:yyyy,xxxx:yyyy\" -NOTE: The device ID is the part inside the last [] brackets, example: [1002:aaf0] +To use any of these devices for passthrough ALL of them has to be passed through to the VMs\ -To return to the previous page just press ENTER without typing in any ids +To return to the previous page just press ENTER without typing in anything. " -read -p "Enter the ids for all devices you want to passthrough: " GPU_DEVID +read -p "Do you want to use these devices for passthrough? [y/N]: " YESNO -if [[ $GPU_DEVID =~ : ]]; +if [[ ${YESNO} =~ [Yy]* ]]; then + # Get the hardware ids from the selected group + local GPU_DEVID=$($SCRIPTDIR/utils/ls-iommu | grep -i "group $1" | perl -pe "s/.+\[([0-9a-f]{4}:[0-9a-f]{4})\].+/\1/" | perl -pe "s/\n/,/" | perl -pe "s/,$/\n/") + # Get the PCI ids local PCI_ID=$($SCRIPTDIR/utils/ls-iommu | grep -i "group $1" | cut -d " " -f 4 | perl -pe "s/\n/ /" | perl -pe "s/\s$//") # Write the GPU_PCI_IDs to the config that quickemu might make use of in the future printf "GPU_PCI_ID=($PCI_ID) -USB_CTL_ID=\"\" +USB_CTL_ID=() " > "$SCRIPTDIR/$QUICKEMU/qemu-vfio_vars.conf" # Get the PCI_ID local ROM_PCI_ID=$($SCRIPTDIR/utils/ls-iommu | grep -i "vga" | grep -i "group $1" | cut -d " " -f 4) - "$SCRIPTDIR/lib/get_GPU_ROM.sh" "$ROM_PCI_ID" + # Get the GPU ROM + "$SCRIPTDIR/lib/get_GPU_ROM.sh" "$ROM_PCI_ID" + + # Start setting up modules exec "$SCRIPTDIR/lib/set_MODULES.sh" $GPU_DEVID else exec "$SCRIPTDIR/lib/get_GPU.sh" diff --git a/lib/get_USB_CTL_GROUP.sh b/lib/get_USB_CTL_GROUP.sh index 3d0f512..ca7d2f9 100755 --- a/lib/get_USB_CTL_GROUP.sh +++ b/lib/get_USB_CTL_GROUP.sh @@ -7,6 +7,8 @@ function get_USB_CTL_GROUP () { printf " For this USB controller device to be passthrough-able, it must be the ONLY device in this group! +Passing through more than just the USB controller can in some cases cause system issues +if you do not know what you are doing. " echo "#------------------------------------------#" @@ -14,20 +16,19 @@ For this USB controller device to be passthrough-able, it must be the ONLY devic echo "#------------------------------------------#" printf " -To use this device for passthrough please type in the device id in the format (without brackets or quotes) --> \"xxxx:yyyy\" -NOTE: The device ID is the part inside the last [] brackets, example: [1002:aaf0] +To use any of the devices shown for passthrough, all of them have to be passed through -To return to the previous page just press ENTER without typing in any ids +To return to the previous page just press ENTER. " -read -p "Enter the id for the device you want to passthrough: " USB_CTL_DEVID +read -p "Do you want to use the displayed devices for passthrough? [y/N]: " YESNO -if [[ $USB_CTL_DEVID =~ : ]]; +if [[ ${YESNO} =~ [Yy]* ]]; then # Get the PCI ids - local PCI_ID=$($SCRIPTDIR/utils/ls-iommu | grep -i "group $1" | cut -d " " -f 4) + local PCI_ID=$($SCRIPTDIR/utils/ls-iommu | grep -i "group $1" | cut -d " " -f 4 | perl -pe "s/\n/ /" | perl -pe "s/\s$//") # Replace the blank USB_CTL_ID with the PCI_ID for the usb controller the user wants to pass through - perl -pi -e "s/USB_CTL_ID=\"\"/USB_CTL_ID=\"$PCI_ID\"/" "$SCRIPTDIR/$QUICKEMU/qemu-vfio_vars.conf" + perl -pi -e "s/USB_CTL_ID=\(\)/USB_CTL_ID=\($PCI_ID\)/" "$SCRIPTDIR/$QUICKEMU/qemu-vfio_vars.conf" exec "$SCRIPTDIR/lib/set_CMDLINE.sh" else exec "$SCRIPTDIR/lib/get_USB_CTL.sh"