[PATCH] ACRN: DM: USB-hot patch


Long Liu
 

Signed-off-by: Liu Long <long.liu@...>
---
devicemodel/hw/pci/xhci.c | 1 +
devicemodel/hw/platform/usb_mouse.c | 1 +
devicemodel/hw/platform/usb_pmapper.c | 27 ++++++++++++++++++++++-----
3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/devicemodel/hw/pci/xhci.c b/devicemodel/hw/pci/xhci.c
index b5c1365ce..42dc8ef67 100644
--- a/devicemodel/hw/pci/xhci.c
+++ b/devicemodel/hw/pci/xhci.c
@@ -3025,6 +3025,7 @@ pci_xhci_try_usb_xfer(struct pci_xhci_vdev *xdev,
err = dev->dev_ue->ue_data(dev->dev_instance, xfer, epid & 0x1 ?
USB_XFER_IN : USB_XFER_OUT, epid/2);
if (err == USB_ERR_CANCELLED) {
+ printf("%s err == USB_ERR_CANCELLED.\n", __func__);
if (USB_DATA_GET_ERRCODE(&xfer->data[xfer->head]) ==
USB_NAK)
err = XHCI_TRB_ERROR_SUCCESS;
diff --git a/devicemodel/hw/platform/usb_mouse.c b/devicemodel/hw/platform/usb_mouse.c
index 475e3515d..33b3dd257 100644
--- a/devicemodel/hw/platform/usb_mouse.c
+++ b/devicemodel/hw/platform/usb_mouse.c
@@ -740,6 +740,7 @@ umouse_data_handler(void *scarg, struct usb_xfer *xfer, int dir,
err = USB_ERR_CANCELLED;
USB_DATA_SET_ERRCODE(&xfer->data[xfer->head], USB_NAK);
pthread_mutex_unlock(&dev->mtx);
+ printf("XXXXXXXXXXXXXXXXXXXXXXX umouse USB_ERR_CANCELLED.\n");
goto done;
}

diff --git a/devicemodel/hw/platform/usb_pmapper.c b/devicemodel/hw/platform/usb_pmapper.c
index d7ff2f6b4..e0a30710d 100644
--- a/devicemodel/hw/platform/usb_pmapper.c
+++ b/devicemodel/hw/platform/usb_pmapper.c
@@ -20,6 +20,7 @@
static struct usb_dev_sys_ctx_info g_ctx;
static uint16_t usb_dev_get_ep_maxp(struct usb_dev *udev, int pid, int epnum);

+int tracnf = 0;
static bool
usb_get_native_devinfo(struct libusb_device *ldev,
struct usb_native_devinfo *info,
@@ -324,6 +325,8 @@ cancel_out:
free(r);
free_transfer:
libusb_free_transfer(trn);
+ tracnf--;
+ printf("%s libusb_free_transfer %d.\n", __func__, tracnf);
}

static struct usb_dev_req *
@@ -359,8 +362,11 @@ usb_dev_alloc_req(struct usb_dev *udev, struct usb_xfer *xfer, int in,
errout:
if (req && req->buffer)
free(req->buffer);
- if (req && req->trn)
+ if (req && req->trn) {
+ tracnf--;
libusb_free_transfer(req->trn);
+ printf("%s libusb_free_transfer %d.\n", __func__, tracnf);
+ }
if (req)
free(req);
return NULL;
@@ -746,6 +752,7 @@ usb_dev_reset(void *pdata)
return rc;
}

+
int
usb_dev_data(void *pdata, struct usb_xfer *xfer, int dir, int epctx)
{
@@ -879,17 +886,22 @@ usb_dev_data(void *pdata, struct usb_xfer *xfer, int dir, int epctx)
UPRINTF(LFTL, "%s: wrong endpoint type %d\r\n", __func__, type);
if (r->buffer)
free(r->buffer);
- if (r->trn)
+ if (r->trn) {
libusb_free_transfer(r->trn);
+ tracnf--;
+ printf("%s libusb_free_transfer %d\n", __func__, tracnf);
+ }
free(r);
xfer->status = USB_ERR_INVAL;
}

rc = libusb_submit_transfer(r->trn);
+ tracnf++;
if (rc) {
xfer->status = USB_ERR_IOERROR;
- UPRINTF(LDBG, "libusb_submit_transfer fail: %d\n", rc);
- }
+ printf("libusb_submit_transfer fail: %d\n", rc);
+ } else
+ printf("XXXXXXXXXXXXXXXXX libusb_submit_transfer %d\n", tracnf);
done:
return xfer->status;
}
@@ -1124,7 +1136,9 @@ usb_dev_free_request(void *pdata)
struct libusb_transfer *trn;

trn = pdata;
+ tracnf--;
libusb_free_transfer(trn);
+ printf("%s libusb_free_transfer %d.\n", __func__, tracnf);
}

void
@@ -1288,12 +1302,14 @@ usb_dev_sys_init(usb_dev_sys_cb conn_cb, usb_dev_sys_cb disconn_cb,
return -1;
}

+ printf("XXXXXXXXX before libusb_init!\n");
rc = libusb_init(&g_ctx.libusb_ctx);
if (rc < 0) {
UPRINTF(LFTL, "libusb_init fails, rc:%d\r\n", rc);
return -1;
}

+ printf("xxxxxxxxx After libusb_init!\n");
g_ctx.hci_data = hci_data;
g_ctx.conn_cb = conn_cb;
g_ctx.disconn_cb = disconn_cb;
@@ -1303,7 +1319,7 @@ usb_dev_sys_init(usb_dev_sys_cb conn_cb, usb_dev_sys_cb disconn_cb,
g_ctx.unlock_ep_cb = unlock_ep_cb;

num_devs = usb_dev_scan_dev(&g_ctx.devlist);
- UPRINTF(LINF, "found %d devices before Guest OS booted\r\n", num_devs);
+ printf("found %d devices before Guest OS booted\r\n", num_devs);

native_conn_evt = LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED;
native_disconn_evt = LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT;
@@ -1330,6 +1346,7 @@ usb_dev_sys_init(usb_dev_sys_cb conn_cb, usb_dev_sys_cb disconn_cb,
goto errout;
}

+ printf("XXXXXXXXX After libusb_init!\n");
/* this is for guest rebooting purpose */
g_ctx.conn_handle = native_conn_handle;
g_ctx.disconn_handle = native_disconn_handle;
--
2.25.1

Join acrn-dev@lists.projectacrn.org to automatically receive all group messages.