Use USB vendor/product IDs instead of bus/dev IDs
This commit is contained in:
parent
8fd8def548
commit
a8f5af7bd0
4 changed files with 23 additions and 15 deletions
|
|
@ -10,8 +10,8 @@ import (
|
|||
)
|
||||
|
||||
type USBDevicePassthroughConfig struct {
|
||||
HostBus uint8
|
||||
HostPort uint8
|
||||
VendorID uint16
|
||||
ProductID uint16
|
||||
}
|
||||
|
||||
type PortForwardingRule struct {
|
||||
|
|
|
|||
15
vm/vm.go
15
vm/vm.go
|
|
@ -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)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue