Skip to content

Commit

Permalink
DM USB: xHCI: add xHCI de-initialization support
Browse files Browse the repository at this point in the history
add support for xHCI de-initialization when the guest
dose shutdown or reboot.

Change-Id: I3dfc1ed1a905b455ef455dff2065e872aa5c1ef8
Signed-off-by: Wu, Xiaoguang <xiaoguang.wu@intel.com>
Reviewed-by: Shuo Liu <shuo.a.liu@intel.com>
Reviewed-by: Yu Wang <yu1.wang@intel.com>
Reviewed-by: Zhao Yakui <yakui.zhao@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
  • Loading branch information
xiaoguangwu authored and lijinxia committed May 29, 2018
1 parent 048b2c7 commit 6449950
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
35 changes: 35 additions & 0 deletions devicemodel/hw/pci/xhci.c
Original file line number Diff line number Diff line change
Expand Up @@ -3321,9 +3321,44 @@ pci_xhci_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
return error;
}

static void
pci_xhci_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
{
int i;
struct pci_xhci_vdev *xdev;
struct pci_xhci_dev_emu *de;

assert(dev);
xdev = dev->arg;

UPRINTF(LINF, "de-initialization\r\n");
assert(xdev);
assert(xdev->devices);

for (i = 1; i <= XHCI_MAX_DEVS; ++i) {
de = xdev->devices[i];
if (de) {
xdev->devices[i] = NULL;
pci_xhci_dev_destroy(de);
xdev->ndevices--;
}
}

free(xdev->devices);
free(xdev->slots);
free(xdev->portregs);

usb_dev_sys_deinit();

pthread_mutex_destroy(&xdev->mtx);
free(xdev);
xhci_in_use = 0;
}

struct pci_vdev_ops pci_ops_xhci = {
.class_name = "xhci",
.vdev_init = pci_xhci_init,
.vdev_deinit = pci_xhci_deinit,
.vdev_barwrite = pci_xhci_write,
.vdev_barread = pci_xhci_read
};
Expand Down
23 changes: 23 additions & 0 deletions devicemodel/hw/platform/usb_pmapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,11 @@ usb_dev_sys_init(usb_dev_sys_cb conn_cb, usb_dev_sys_cb disconn_cb,
goto errout;
}

/* this is for guest rebooting purpose */
g_ctx.conn_handle = native_conn_handle;
g_ctx.disconn_handle = native_disconn_handle;
g_ctx.thread_exit = 0;

if (pthread_create(&g_ctx.thread, NULL, usb_dev_sys_thread, NULL)) {
libusb_hotplug_deregister_callback(g_ctx.libusb_ctx,
native_conn_handle);
Expand All @@ -953,3 +958,21 @@ usb_dev_sys_init(usb_dev_sys_cb conn_cb, usb_dev_sys_cb disconn_cb,
g_ctx.libusb_ctx = NULL;
return -1;
}

void
usb_dev_sys_deinit(void)
{
if (!g_ctx.libusb_ctx)
return;

UPRINTF(LINF, "port-mapper de-initialization\r\n");
libusb_hotplug_deregister_callback(g_ctx.libusb_ctx, g_ctx.conn_handle);
libusb_hotplug_deregister_callback(g_ctx.libusb_ctx,
g_ctx.disconn_handle);

g_ctx.thread_exit = 1;
pthread_join(g_ctx.thread, NULL);

libusb_exit(g_ctx.libusb_ctx);
g_ctx.libusb_ctx = NULL;
}
5 changes: 5 additions & 0 deletions devicemodel/include/usb_pmapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ struct usb_dev_sys_ctx_info {
pthread_t thread;
int thread_exit;

/* handles of callback */
libusb_hotplug_callback_handle conn_handle;
libusb_hotplug_callback_handle disconn_handle;

/*
* The following callback funtions will be registered by
* the code from HCD(eg: XHCI, EHCI...) emulation layer.
Expand All @@ -137,6 +141,7 @@ struct usb_dev_sys_ctx_info {
int usb_dev_sys_init(usb_dev_sys_cb conn_cb, usb_dev_sys_cb disconn_cb,
usb_dev_sys_cb notify_cb, usb_dev_sys_cb intr_cb,
void *hci_data, int log_level);
void usb_dev_sys_deinit(void);
void *usb_dev_init(void *pdata, char *opt);
void usb_dev_deinit(void *pdata);
int usb_dev_info(void *pdata, int type, void *value, int size);
Expand Down

0 comments on commit 6449950

Please sign in to comment.