diff --git a/devicemodel/hw/pci/xhci.c b/devicemodel/hw/pci/xhci.c index 2d1697ec6..21adf2ba6 100644 --- a/devicemodel/hw/pci/xhci.c +++ b/devicemodel/hw/pci/xhci.c @@ -256,6 +256,7 @@ struct pci_xhci_vdev { int usb2_port_start; int usb3_port_start; + uint8_t *native_assign_ports[USB_NATIVE_NUM_BUS]; }; /* portregs and devices arrays are set up to start from idx=1 */ @@ -369,6 +370,26 @@ pci_xhci_native_usb_dev_conn_cb(void *hci_data, void *dev_data) UPRINTF(LDBG, "%X:%X %d-%d connecting.\r\n", native_vid, native_pid, native_bus, native_port); + /* FIXME: will support usb3 in future */ + if (xdev->native_assign_ports[native_bus] && + usb_native_is_ss_port(native_bus)) { + UPRINTF(LDBG, "%X:%X %d-%d not support usb3 device, exit.\r\n", + native_vid, native_pid, native_bus, + native_port); + goto errout; + } + + if (!xdev->native_assign_ports[native_bus] || + !xdev->native_assign_ports[native_bus][native_port]) { + UPRINTF(LDBG, "%X:%X %d-%d doesn't belong to this vm, bye.\r\n", + native_vid, native_pid, native_bus, + native_port); + goto errout; + } + + UPRINTF(LDBG, "%X:%X %d-%d belong to this vm.\r\n", native_vid, + native_pid, native_bus, native_port); + if (ue->ue_usbver == 2) port_start = xdev->usb2_port_start; else diff --git a/devicemodel/include/usb_core.h b/devicemodel/include/usb_core.h index a482df03e..b535bb7c2 100644 --- a/devicemodel/include/usb_core.h +++ b/devicemodel/include/usb_core.h @@ -199,6 +199,8 @@ enum USB_ERRCODE { #define NATIVE_USBSYS_DEVDIR "/sys/bus/usb/devices" #define NATIVE_USB2_SPEED "480" #define NATIVE_USB3_SPEED "5000" +#define USB_NATIVE_NUM_PORT 255 +#define USB_NATIVE_NUM_BUS 255 extern int usb_log_level; inline int usb_get_log_level(void) { return usb_log_level; }