mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-07-07 20:39:14 +00:00
DM USB: introduce function usb_get_native_devinfo
There are many places in USB emulation implementation to get native USB device infomation, and the related codes are long and repeated many times. This patch introduces function usb_get_native_devinfo to remove redundent codes for the purpose mentioned above. Tracked-On: #1434 Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com> Signed-off-by: Liang Yang <liang3.yang@intel.com> Acked-by: Yu Wang <yu1.wang@intel.com>
This commit is contained in:
parent
e8f7b6fa74
commit
540ce05f27
@ -21,6 +21,41 @@ static struct usb_dev_sys_ctx_info g_ctx;
|
|||||||
static inline uint8_t usb_dev_get_ep_type(struct usb_dev *udev, int pid,
|
static inline uint8_t usb_dev_get_ep_type(struct usb_dev *udev, int pid,
|
||||||
int epnum);
|
int epnum);
|
||||||
|
|
||||||
|
static bool
|
||||||
|
usb_get_native_devinfo(struct libusb_device *ldev,
|
||||||
|
struct usb_native_devinfo *info,
|
||||||
|
struct libusb_device_descriptor *desc)
|
||||||
|
{
|
||||||
|
struct libusb_device_descriptor d;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
if (!ldev || !info)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
memset(info, 0, sizeof(*info));
|
||||||
|
info->speed = libusb_get_device_speed(ldev);
|
||||||
|
info->priv_data = ldev;
|
||||||
|
info->path.bus = libusb_get_bus_number(ldev);
|
||||||
|
info->path.depth = libusb_get_port_numbers(ldev, info->path.path,
|
||||||
|
USB_MAX_TIERS);
|
||||||
|
|
||||||
|
rc = libusb_get_device_descriptor(ldev, &d);
|
||||||
|
if (rc) {
|
||||||
|
UPRINTF(LWRN, "fail to get descriptor for %d-%s\r\n",
|
||||||
|
info->path.bus, usb_dev_path(&info->path));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
info->pid = d.idProduct;
|
||||||
|
info->vid = d.idVendor;
|
||||||
|
info->bcd = d.bcdUSB;
|
||||||
|
|
||||||
|
if (desc != NULL)
|
||||||
|
*desc = d;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
usb_dev_scan_dev()
|
usb_dev_scan_dev()
|
||||||
{
|
{
|
||||||
@ -29,7 +64,7 @@ usb_dev_scan_dev()
|
|||||||
struct libusb_device *ldev;
|
struct libusb_device *ldev;
|
||||||
struct usb_native_devinfo di;
|
struct usb_native_devinfo di;
|
||||||
struct libusb_device_descriptor d;
|
struct libusb_device_descriptor d;
|
||||||
int rc;
|
bool ret;
|
||||||
|
|
||||||
if (!g_ctx.libusb_ctx)
|
if (!g_ctx.libusb_ctx)
|
||||||
return -1;
|
return -1;
|
||||||
@ -41,24 +76,9 @@ usb_dev_scan_dev()
|
|||||||
for (i = 0; i < num_devs; ++i) {
|
for (i = 0; i < num_devs; ++i) {
|
||||||
ldev = devlist[i];
|
ldev = devlist[i];
|
||||||
|
|
||||||
memset(&di, 0, sizeof(di));
|
ret = usb_get_native_devinfo(ldev, &di, &d);
|
||||||
di.path.bus = libusb_get_bus_number(ldev);
|
if (ret == false)
|
||||||
di.path.depth = libusb_get_port_numbers(ldev, di.path.path,
|
|
||||||
USB_MAX_TIERS);
|
|
||||||
di.speed = libusb_get_device_speed(ldev);
|
|
||||||
|
|
||||||
rc = libusb_get_device_descriptor(ldev, &d);
|
|
||||||
if (rc) {
|
|
||||||
UPRINTF(LWRN, "fail to get descriptor for %d-%s\r\n",
|
|
||||||
di.path.bus, usb_dev_path(&di.path));
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
di.pid = d.idProduct;
|
|
||||||
di.vid = d.idVendor;
|
|
||||||
di.bcd = d.bcdUSB;
|
|
||||||
di.priv_data = ldev;
|
|
||||||
|
|
||||||
if (ROOTHUB_PORT(di.path) == 0)
|
if (ROOTHUB_PORT(di.path) == 0)
|
||||||
continue;
|
continue;
|
||||||
if (d.bDeviceClass == LIBUSB_CLASS_HUB)
|
if (d.bDeviceClass == LIBUSB_CLASS_HUB)
|
||||||
@ -1067,8 +1087,9 @@ static int
|
|||||||
usb_dev_native_sys_conn_cb(struct libusb_context *ctx, struct libusb_device
|
usb_dev_native_sys_conn_cb(struct libusb_context *ctx, struct libusb_device
|
||||||
*ldev, libusb_hotplug_event event, void *pdata)
|
*ldev, libusb_hotplug_event event, void *pdata)
|
||||||
{
|
{
|
||||||
struct libusb_device_descriptor d;
|
|
||||||
struct usb_native_devinfo di;
|
struct usb_native_devinfo di;
|
||||||
|
struct libusb_device_descriptor d;
|
||||||
|
bool ret;
|
||||||
|
|
||||||
UPRINTF(LDBG, "connect event\r\n");
|
UPRINTF(LDBG, "connect event\r\n");
|
||||||
|
|
||||||
@ -1077,15 +1098,9 @@ usb_dev_native_sys_conn_cb(struct libusb_context *ctx, struct libusb_device
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
libusb_get_device_descriptor(ldev, &d);
|
ret = usb_get_native_devinfo(ldev, &di, &d);
|
||||||
di.path.bus = libusb_get_bus_number(ldev);
|
if (ret == false)
|
||||||
di.path.depth = libusb_get_port_numbers(ldev, di.path.path,
|
return 0;
|
||||||
USB_MAX_TIERS);
|
|
||||||
di.speed = libusb_get_device_speed(ldev);
|
|
||||||
di.pid = d.idProduct;
|
|
||||||
di.vid = d.idVendor;
|
|
||||||
di.bcd = d.bcdUSB;
|
|
||||||
di.priv_data = ldev;
|
|
||||||
|
|
||||||
if (d.bDeviceClass == LIBUSB_CLASS_HUB)
|
if (d.bDeviceClass == LIBUSB_CLASS_HUB)
|
||||||
return 0;
|
return 0;
|
||||||
@ -1100,8 +1115,9 @@ static int
|
|||||||
usb_dev_native_sys_disconn_cb(struct libusb_context *ctx, struct libusb_device
|
usb_dev_native_sys_disconn_cb(struct libusb_context *ctx, struct libusb_device
|
||||||
*ldev, libusb_hotplug_event event, void *pdata)
|
*ldev, libusb_hotplug_event event, void *pdata)
|
||||||
{
|
{
|
||||||
struct libusb_device_descriptor d;
|
|
||||||
struct usb_native_devinfo di;
|
struct usb_native_devinfo di;
|
||||||
|
struct libusb_device_descriptor d;
|
||||||
|
bool ret;
|
||||||
|
|
||||||
UPRINTF(LDBG, "disconnect event\r\n");
|
UPRINTF(LDBG, "disconnect event\r\n");
|
||||||
|
|
||||||
@ -1110,16 +1126,9 @@ usb_dev_native_sys_disconn_cb(struct libusb_context *ctx, struct libusb_device
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
libusb_get_device_descriptor(ldev, &d);
|
ret = usb_get_native_devinfo(ldev, &di, &d);
|
||||||
di.path.bus = libusb_get_bus_number(ldev);
|
if (ret == false)
|
||||||
di.speed = libusb_get_device_speed(ldev);
|
return 0;
|
||||||
di.path.depth = libusb_get_port_numbers(ldev, di.path.path,
|
|
||||||
USB_MAX_TIERS);
|
|
||||||
|
|
||||||
di.pid = d.idProduct;
|
|
||||||
di.vid = d.idVendor;
|
|
||||||
di.bcd = d.bcdUSB;
|
|
||||||
di.priv_data = ldev;
|
|
||||||
|
|
||||||
if (d.bDeviceClass == LIBUSB_CLASS_HUB)
|
if (d.bDeviceClass == LIBUSB_CLASS_HUB)
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user