mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-05-31 03:15:42 +00:00
DM USB: xHCI: remove old hub support code.
Previous design use bus and port(root hub port) for the identification to the native USB device. It cannot work properly under the multi-hub situation due to external USB hub is introduced. This patch removes old hub implementation code, and subsequent patches will be add support for mutiple hubs. Tracked-On: #1434 Signed-off-by: Liang Yang <liang3.yang@intel.com> Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com> Acked-by: Yu Wang <yu1.wang@intel.com>
This commit is contained in:
parent
8b5d357f92
commit
14bc961f03
85
devicemodel/hw/pci/xhci.c
Normal file → Executable file
85
devicemodel/hw/pci/xhci.c
Normal file → Executable file
@ -95,7 +95,7 @@
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "xHCI: "
|
||||
#define XHCI_MAX_DEVS 20 /* 10 root hub + 10 external hub */
|
||||
#define XHCI_MAX_DEVS 8 /* 4 USB3 + 4 USB2 devs */
|
||||
#define XHCI_MAX_SLOTS 64 /* min allowed by Windows drivers */
|
||||
|
||||
/*
|
||||
@ -396,7 +396,6 @@ struct pci_xhci_vdev {
|
||||
#define VPORT_ASSIGNED (1)
|
||||
#define VPORT_CONNECTED (2)
|
||||
#define VPORT_EMULATED (3)
|
||||
#define VPORT_HUB_CONNECTED (4)
|
||||
|
||||
/* helpers for get port mapping information */
|
||||
#define VPORT_NUM(state) (state & 0xFF)
|
||||
@ -482,27 +481,6 @@ static struct pci_xhci_option_elem xhci_option_table[] = {
|
||||
{"cap", pci_xhci_parse_extcap}
|
||||
};
|
||||
|
||||
static enum usb_native_dev_type
|
||||
pci_xhci_get_dev_type(struct pci_xhci_vdev *xdev, void *dev_data)
|
||||
{
|
||||
uint16_t port, bus;
|
||||
struct usb_native_devinfo *di;
|
||||
|
||||
assert(dev_data);
|
||||
|
||||
di = dev_data;
|
||||
if (usb_get_parent_dev_type(di->priv_data, &bus, &port) == USB_HUB) {
|
||||
if (VPORT_STATE(xdev->port_map_tbl[bus][port]) ==
|
||||
VPORT_HUB_CONNECTED) {
|
||||
di->port += PORT_HUB_BASE;
|
||||
return USB_VALID_SUB_DEV;
|
||||
} else
|
||||
return USB_INVALID_SUB_DEV;
|
||||
}
|
||||
|
||||
return USB_DEV;
|
||||
}
|
||||
|
||||
static int
|
||||
pci_xhci_get_free_rh_port(struct pci_xhci_vdev *xdev, struct usb_native_devinfo
|
||||
*di)
|
||||
@ -545,9 +523,6 @@ pci_xhci_native_usb_dev_conn_cb(void *hci_data, void *dev_data)
|
||||
struct usb_native_devinfo *di;
|
||||
int port;
|
||||
int need_intr = 1;
|
||||
enum usb_native_dev_type type;
|
||||
int state;
|
||||
int rc;
|
||||
|
||||
xdev = hci_data;
|
||||
|
||||
@ -562,37 +537,14 @@ pci_xhci_native_usb_dev_conn_cb(void *hci_data, void *dev_data)
|
||||
UPRINTF(LDBG, "%04x:%04x %d-%d connecting.\r\n",
|
||||
di->vid, di->pid, di->bus, di->port);
|
||||
|
||||
type = pci_xhci_get_dev_type(xdev, di);
|
||||
if (type == USB_DEV) {
|
||||
if (VPORT_STATE(xdev->port_map_tbl[di->bus][di->port]) ==
|
||||
VPORT_FREE) {
|
||||
UPRINTF(LDBG, "%04x:%04x %d-%d doesn't belong to this"
|
||||
" vm, bye.\r\n", di->vid, di->pid,
|
||||
di->bus, di->port);
|
||||
goto errout;
|
||||
}
|
||||
} else if (type == USB_INVALID_SUB_DEV)
|
||||
return 0;
|
||||
|
||||
state = VPORT_STATE(xdev->port_map_tbl[di->bus][di->port]);
|
||||
if (state == VPORT_CONNECTED || state == VPORT_EMULATED ||
|
||||
state == VPORT_HUB_CONNECTED) {
|
||||
UPRINTF(LFTL, "do not support multiple hubs currently, reject "
|
||||
"device %d-%d\r\n", di->bus, di->port);
|
||||
if (VPORT_STATE(xdev->port_map_tbl[di->bus][di->port]) ==
|
||||
VPORT_FREE) {
|
||||
UPRINTF(LDBG, "%04x:%04x %d-%d doesn't belong to this"
|
||||
" vm, bye.\r\n", di->vid, di->pid,
|
||||
di->bus, di->port);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
rc = usb_dev_is_hub(di->priv_data);
|
||||
if (rc == USB_HUB) {
|
||||
xdev->port_map_tbl[di->bus][di->port] =
|
||||
VPORT_NUM_STATE(VPORT_HUB_CONNECTED, 0);
|
||||
return 0;
|
||||
} else if (rc == USB_TYPE_INVALID) {
|
||||
UPRINTF(LWRN, "usb_dev_is_hub failed\r\n");
|
||||
goto errout;
|
||||
}
|
||||
|
||||
|
||||
UPRINTF(LDBG, "%04x:%04x %d-%d belong to this vm.\r\n", di->vid,
|
||||
di->pid, di->bus, di->port);
|
||||
|
||||
@ -647,11 +599,6 @@ pci_xhci_native_usb_dev_disconn_cb(void *hci_data, void *dev_data)
|
||||
}
|
||||
|
||||
status = xdev->port_map_tbl[di.bus][di.port];
|
||||
if (VPORT_STATE(status) == VPORT_HUB_CONNECTED) {
|
||||
xdev->port_map_tbl[di.bus][di.port] =
|
||||
VPORT_NUM_STATE(VPORT_ASSIGNED, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (port = 1; port <= XHCI_MAX_DEVS; ++port) {
|
||||
edev = xdev->devices[port];
|
||||
@ -659,24 +606,8 @@ pci_xhci_native_usb_dev_disconn_cb(void *hci_data, void *dev_data)
|
||||
continue;
|
||||
|
||||
udev = edev->dev_instance;
|
||||
if (udev->info.port == di.port) {
|
||||
int old_t, new_t;
|
||||
uint8_t old_ports[7]; /* max USB hub tiers are 7 */
|
||||
uint8_t new_ports[7];
|
||||
|
||||
/* get tiers and port info */
|
||||
old_t = libusb_get_port_numbers(udev->info.priv_data,
|
||||
old_ports, sizeof(old_ports));
|
||||
new_t = libusb_get_port_numbers(di.priv_data,
|
||||
new_ports, sizeof(new_ports));
|
||||
|
||||
if (old_t == new_t &&
|
||||
!memcmp(old_ports, new_ports, old_t)) {
|
||||
di = udev->info;
|
||||
break;
|
||||
}
|
||||
UPRINTF(LFTL, "multi-hub is not supported yet\r\n");
|
||||
}
|
||||
if (udev->info.port == di.port)
|
||||
break;
|
||||
}
|
||||
|
||||
if (port > XHCI_MAX_DEVS) {
|
||||
|
101
devicemodel/hw/platform/usb_pmapper.c
Normal file → Executable file
101
devicemodel/hw/platform/usb_pmapper.c
Normal file → Executable file
@ -38,36 +38,6 @@ usb_dev_scan_dev()
|
||||
if (num_devs < 0)
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < num_devs; ++i) {
|
||||
ldev = devlist[i];
|
||||
|
||||
memset(&di, 0, sizeof(di));
|
||||
|
||||
di.bus = libusb_get_bus_number(ldev);
|
||||
di.port = libusb_get_port_number(ldev);
|
||||
di.speed = libusb_get_device_speed(ldev);
|
||||
|
||||
rc = libusb_get_device_descriptor(ldev, &d);
|
||||
if (rc) {
|
||||
UPRINTF(LWRN, "fail to get descriptor for %d-%d\r\n",
|
||||
di.bus, di.port);
|
||||
continue;
|
||||
}
|
||||
|
||||
di.pid = d.idProduct;
|
||||
di.vid = d.idVendor;
|
||||
di.bcd = d.bcdUSB;
|
||||
di.priv_data = ldev;
|
||||
|
||||
if (di.port == 0)
|
||||
continue;
|
||||
if (d.bDeviceClass != LIBUSB_CLASS_HUB)
|
||||
continue;
|
||||
|
||||
if (g_ctx.conn_cb)
|
||||
g_ctx.conn_cb(g_ctx.hci_data, &di);
|
||||
}
|
||||
|
||||
for (i = 0; i < num_devs; ++i) {
|
||||
ldev = devlist[i];
|
||||
|
||||
@ -934,65 +904,6 @@ out:
|
||||
return xfer->status;
|
||||
}
|
||||
|
||||
int
|
||||
usb_dev_is_hub(void *pdata)
|
||||
{
|
||||
struct libusb_device *ldev;
|
||||
struct libusb_device_descriptor desc;
|
||||
int rc;
|
||||
|
||||
assert(pdata);
|
||||
|
||||
ldev = pdata;
|
||||
rc = libusb_get_device_descriptor(ldev, &desc);
|
||||
|
||||
if (rc)
|
||||
return USB_TYPE_INVALID;
|
||||
|
||||
if (desc.bDeviceClass == LIBUSB_CLASS_HUB)
|
||||
return USB_HUB;
|
||||
else
|
||||
return USB_DEV;
|
||||
|
||||
}
|
||||
|
||||
enum usb_native_dev_type
|
||||
usb_get_parent_dev_type(void *pdata, uint16_t *bus, uint16_t *port)
|
||||
{
|
||||
struct libusb_device *ldev;
|
||||
struct libusb_device *libdev;
|
||||
struct libusb_device_descriptor desc;
|
||||
int rc;
|
||||
|
||||
assert(pdata);
|
||||
assert(bus);
|
||||
assert(port);
|
||||
|
||||
ldev = pdata;
|
||||
libdev = libusb_get_parent(ldev);
|
||||
|
||||
if (libdev == NULL) {
|
||||
UPRINTF(LWRN, "libusb_get_parent return NULL\r\n");
|
||||
return USB_TYPE_INVALID;
|
||||
}
|
||||
|
||||
*bus = libusb_get_bus_number(libdev);
|
||||
*port = libusb_get_port_number(libdev);
|
||||
|
||||
rc = libusb_get_device_descriptor(libdev, &desc);
|
||||
if (rc) {
|
||||
UPRINTF(LWRN, "libusb_get_device_descriptor error %d\r\n", rc);
|
||||
return USB_TYPE_INVALID;
|
||||
}
|
||||
|
||||
if (*port == 0)
|
||||
return ROOT_HUB;
|
||||
if (desc.bDeviceClass == LIBUSB_CLASS_HUB)
|
||||
return USB_HUB;
|
||||
|
||||
return USB_TYPE_INVALID;
|
||||
}
|
||||
|
||||
void *
|
||||
usb_dev_init(void *pdata, char *opt)
|
||||
{
|
||||
@ -1166,6 +1077,9 @@ usb_dev_native_sys_conn_cb(struct libusb_context *ctx, struct libusb_device
|
||||
di.bcd = d.bcdUSB;
|
||||
di.priv_data = ldev;
|
||||
|
||||
if (d.bDeviceClass == LIBUSB_CLASS_HUB)
|
||||
return 0;
|
||||
|
||||
if (g_ctx.conn_cb)
|
||||
g_ctx.conn_cb(g_ctx.hci_data, &di);
|
||||
|
||||
@ -1178,9 +1092,6 @@ usb_dev_native_sys_disconn_cb(struct libusb_context *ctx, struct libusb_device
|
||||
{
|
||||
struct libusb_device_descriptor d;
|
||||
struct usb_native_devinfo di;
|
||||
uint16_t pport;
|
||||
uint16_t pbus;
|
||||
int rc;
|
||||
|
||||
UPRINTF(LDBG, "disconnect event\r\n");
|
||||
|
||||
@ -1200,12 +1111,8 @@ usb_dev_native_sys_disconn_cb(struct libusb_context *ctx, struct libusb_device
|
||||
di.bcd = d.bcdUSB;
|
||||
di.priv_data = ldev;
|
||||
|
||||
rc = usb_get_parent_dev_type(ldev, &pbus, &pport);
|
||||
if (rc == USB_TYPE_INVALID) {
|
||||
UPRINTF(LWRN, "usb_get_parent_dev_type return %d\r\n", rc);
|
||||
if (d.bDeviceClass == LIBUSB_CLASS_HUB)
|
||||
return 0;
|
||||
} else if (rc == USB_HUB)
|
||||
di.port += PORT_HUB_BASE;
|
||||
|
||||
if (g_ctx.disconn_cb)
|
||||
g_ctx.disconn_cb(g_ctx.hci_data, &di);
|
||||
|
@ -20,9 +20,6 @@
|
||||
#define USB_EP_NR(d) (USB_EP_ADDR(d) & 0xF)
|
||||
#define USB_EP_ERR_TYPE 0xFF
|
||||
|
||||
/* hub port start address */
|
||||
#define PORT_HUB_BASE 0x0A
|
||||
|
||||
enum {
|
||||
USB_INFO_VERSION,
|
||||
USB_INFO_SPEED,
|
||||
@ -32,15 +29,6 @@ enum {
|
||||
USB_INFO_PID
|
||||
};
|
||||
|
||||
enum usb_native_dev_type {
|
||||
ROOT_HUB,
|
||||
USB_HUB,
|
||||
USB_DEV,
|
||||
USB_VALID_SUB_DEV,
|
||||
USB_INVALID_SUB_DEV,
|
||||
USB_TYPE_INVALID
|
||||
};
|
||||
|
||||
struct usb_dev_ep {
|
||||
uint8_t pid;
|
||||
uint8_t type;
|
||||
@ -133,5 +121,4 @@ int usb_dev_reset(void *pdata);
|
||||
int usb_dev_data(void *pdata, struct usb_data_xfer *xfer, int dir, int epctx);
|
||||
enum usb_native_dev_type usb_get_parent_dev_type(void *pdata, uint16_t *bus,
|
||||
uint16_t *port);
|
||||
int usb_dev_is_hub(void *pdata);
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user