Use USB vendor/product IDs instead of bus/dev IDs

This commit is contained in:
AlexSSD7 2023-08-27 18:07:51 +01:00
commit a8f5af7bd0
4 changed files with 23 additions and 15 deletions

View file

@ -10,8 +10,8 @@ import (
)
type USBDevicePassthroughConfig struct {
HostBus uint8
HostPort uint8
VendorID uint16
ProductID uint16
}
type PortForwardingRule struct {

View file

@ -4,13 +4,13 @@ import (
"bufio"
"bytes"
"context"
"encoding/hex"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"sync"
"sync/atomic"
"syscall"
@ -122,17 +122,18 @@ func NewVM(logger *slog.Logger, cfg VMConfig) (*VM, error) {
if !cfg.ShowDisplay {
cmdArgs = append(cmdArgs, "-display", "none")
if runtime.GOARCH == "arm64" {
// No video is configured by default in ARM. This will enable it.
cmdArgs = append(cmdArgs, "-device", "virtio-gpu-device")
}
} else if runtime.GOARCH == "arm64" {
// No video is configured by default in ARM. This will enable it.
// TODO: This doesn't really work on arm64. It just shows a blank viewer.
cmdArgs = append(cmdArgs, "-device", "virtio-gpu-device")
}
if len(cfg.USBDevices) != 0 {
cmdArgs = append(cmdArgs, "-usb", "-device", "nec-usb-xhci,id=xhci")
cmdArgs = append(cmdArgs, "-device", "nec-usb-xhci,id=xhci")
for _, dev := range cfg.USBDevices {
cmdArgs = append(cmdArgs, "-device", "usb-host,hostbus="+strconv.FormatUint(uint64(dev.HostBus), 10)+",hostport="+strconv.FormatUint(uint64(dev.HostPort), 10))
cmdArgs = append(cmdArgs, "-device", "usb-host,vendorid=0x"+hex.EncodeToString(utils.Uint16ToBytesBE(dev.VendorID))+",productid=0x"+hex.EncodeToString(utils.Uint16ToBytesBE(dev.ProductID)))
}
}