mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
libxl: add pvusb API
Add pvusb APIs, including: - attach/detach (create/destroy) virtual usb controller. - attach/detach usb device - list usb controller and usb devices - some other helper functions Signed-off-by: Simon Cao <caobosimon@gmail.com> Signed-off-by: George Dunlap <george.dunlap@citrix.com> Signed-off-by: Chunyan Liu <cyliu@suse.com> Reviewed-by: George Dunlap <george.dunlap@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
This commit is contained in:
1 parent
127b37578c
commit
bf7628f087
11 files changed
+1822
-2
No files matched your search
@@ -105,7 +105,8 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \
|
||||
libxl_stream_read.o libxl_stream_write.o \
|
||||
libxl_save_callout.o _libxl_save_msgs_callout.o \
|
||||
libxl_qmp.o libxl_event.o libxl_fork.o \
|
||||
libxl_dom_suspend.o libxl_dom_save.o $(LIBXL_OBJS-y)
|
||||
libxl_dom_suspend.o libxl_dom_save.o libxl_pvusb.o \
|
||||
$(LIBXL_OBJS-y)
|
||||
LIBXL_OBJS += libxl_genid.o
|
||||
LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
|
||||
|
||||
|
||||
@@ -4102,6 +4102,8 @@ out:
|
||||
* libxl_device_vkb_destroy
|
||||
* libxl_device_vfb_remove
|
||||
* libxl_device_vfb_destroy
|
||||
* libxl_device_usbctrl_remove
|
||||
* libxl_device_usbctrl_destroy
|
||||
*/
|
||||
#define DEFINE_DEVICE_REMOVE_EXT(type, remtype, removedestroy, f) \
|
||||
int libxl_device_##type##_##removedestroy(libxl_ctx *ctx, \
|
||||
@@ -4159,6 +4161,10 @@ DEFINE_DEVICE_REMOVE(vfb, destroy, 1)
|
||||
DEFINE_DEVICE_REMOVE(vtpm, remove, 0)
|
||||
DEFINE_DEVICE_REMOVE(vtpm, destroy, 1)
|
||||
|
||||
/* usbctrl */
|
||||
DEFINE_DEVICE_REMOVE_CUSTOM(usbctrl, remove, 0)
|
||||
DEFINE_DEVICE_REMOVE_CUSTOM(usbctrl, destroy, 1)
|
||||
|
||||
/* channel/console hotunplug is not implemented. There are 2 possibilities:
|
||||
* 1. add support for secondary consoles to xenconsoled
|
||||
* 2. dynamically add/remove qemu chardevs via qmp messages. */
|
||||
@@ -4174,6 +4180,8 @@ DEFINE_DEVICE_REMOVE(vtpm, destroy, 1)
|
||||
* libxl_device_disk_add
|
||||
* libxl_device_nic_add
|
||||
* libxl_device_vtpm_add
|
||||
* libxl_device_usbctrl_add
|
||||
* libxl_device_usbdev_add
|
||||
*/
|
||||
|
||||
#define DEFINE_DEVICE_ADD(type) \
|
||||
@@ -4205,6 +4213,12 @@ DEFINE_DEVICE_ADD(nic)
|
||||
/* vtpm */
|
||||
DEFINE_DEVICE_ADD(vtpm)
|
||||
|
||||
/* usbctrl */
|
||||
DEFINE_DEVICE_ADD(usbctrl)
|
||||
|
||||
/* usb */
|
||||
DEFINE_DEVICE_ADD(usbdev)
|
||||
|
||||
#undef DEFINE_DEVICE_ADD
|
||||
|
||||
/******************************************************************************/
|
||||
@@ -6750,6 +6764,10 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid,
|
||||
|
||||
MERGE(pci, pcidevs, COMPARE_PCI, {});
|
||||
|
||||
MERGE(usbctrl, usbctrls, COMPARE_USBCTRL, {});
|
||||
|
||||
MERGE(usbdev, usbdevs, COMPARE_USB, {});
|
||||
|
||||
/* Take care of removable device. We maintain invariant in the
|
||||
* insert / remove operation so that:
|
||||
* 1. if xenstore is "empty" while JSON is not, the result
|
||||
|
||||
@@ -122,6 +122,12 @@
|
||||
*/
|
||||
#define LIBXL_HAVE_DOMAIN_NODEAFFINITY 1
|
||||
|
||||
/*
|
||||
* LIBXL_HAVE_PVUSB indicates functions for plugging in USB devices
|
||||
* through pvusb -- both hotplug and at domain creation time..
|
||||
*/
|
||||
#define LIBXL_HAVE_PVUSB 1
|
||||
|
||||
/*
|
||||
* LIBXL_HAVE_BUILDINFO_HVM_VENDOR_DEVICE indicates that the
|
||||
* libxl_vendor_device field is present in the hvm sections of
|
||||
@@ -1530,6 +1536,77 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk,
|
||||
const libxl_asyncop_how *ao_how)
|
||||
LIBXL_EXTERNAL_CALLERS_ONLY;
|
||||
|
||||
/*
|
||||
* USB
|
||||
*
|
||||
* For each device removed or added, one of these protocols is available:
|
||||
* - PV (i.e., PVUSB)
|
||||
* - DEVICEMODEL (i.e, qemu)
|
||||
*
|
||||
* PV is available for either PV or HVM domains. DEVICEMODEL is only
|
||||
* available for HVM domains. The caller can additionally specify
|
||||
* "AUTO", in which case the library will try to determine the best
|
||||
* protocol automatically.
|
||||
*
|
||||
* At the moment, the only protocol implemented is PV.
|
||||
*
|
||||
* One can add/remove USB controllers to/from guest, and attach/detach USB
|
||||
* devices to/from USB controllers.
|
||||
*
|
||||
* To add USB controllers and USB devices, one can adding USB controllers
|
||||
* first and then attaching USB devices to some USB controller, or adding
|
||||
* USB devices to guest directly, it will automatically create a USB
|
||||
* controller for USB devices to attach.
|
||||
*
|
||||
* To remove USB controllers or USB devices, one can remove USB devices
|
||||
* under USB controller one by one and then remove USB controller, or
|
||||
* remove USB controller directly, it will remove all USB devices under
|
||||
* it automatically.
|
||||
*
|
||||
*/
|
||||
/* USB Controllers*/
|
||||
int libxl_device_usbctrl_add(libxl_ctx *ctx, uint32_t domid,
|
||||
libxl_device_usbctrl *usbctrl,
|
||||
const libxl_asyncop_how *ao_how)
|
||||
LIBXL_EXTERNAL_CALLERS_ONLY;
|
||||
|
||||
int libxl_device_usbctrl_remove(libxl_ctx *ctx, uint32_t domid,
|
||||
libxl_device_usbctrl *usbctrl,
|
||||
const libxl_asyncop_how *ao_how)
|
||||
LIBXL_EXTERNAL_CALLERS_ONLY;
|
||||
|
||||
int libxl_device_usbctrl_destroy(libxl_ctx *ctx, uint32_t domid,
|
||||
libxl_device_usbctrl *usbctrl,
|
||||
const libxl_asyncop_how *ao_how)
|
||||
LIBXL_EXTERNAL_CALLERS_ONLY;
|
||||
|
||||
libxl_device_usbctrl *libxl_device_usbctrl_list(libxl_ctx *ctx,
|
||||
uint32_t domid, int *num);
|
||||
|
||||
void libxl_device_usbctrl_list_free(libxl_device_usbctrl *list, int nr);
|
||||
|
||||
|
||||
int libxl_device_usbctrl_getinfo(libxl_ctx *ctx, uint32_t domid,
|
||||
libxl_device_usbctrl *usbctrl,
|
||||
libxl_usbctrlinfo *usbctrlinfo);
|
||||
|
||||
/* USB Devices */
|
||||
|
||||
int libxl_device_usbdev_add(libxl_ctx *ctx, uint32_t domid,
|
||||
libxl_device_usbdev *usbdev,
|
||||
const libxl_asyncop_how *ao_how)
|
||||
LIBXL_EXTERNAL_CALLERS_ONLY;
|
||||
|
||||
int libxl_device_usbdev_remove(libxl_ctx *ctx, uint32_t domid,
|
||||
libxl_device_usbdev *usbdev,
|
||||
const libxl_asyncop_how *ao_how)
|
||||
LIBXL_EXTERNAL_CALLERS_ONLY;
|
||||
|
||||
libxl_device_usbdev *
|
||||
libxl_device_usbdev_list(libxl_ctx *ctx, uint32_t domid, int *num);
|
||||
|
||||
void libxl_device_usbdev_list_free(libxl_device_usbdev *list, int nr);
|
||||
|
||||
/* Network Interfaces */
|
||||
int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic,
|
||||
const libxl_asyncop_how *ao_how)
|
||||
|
||||
@@ -676,7 +676,10 @@ void libxl__devices_destroy(libxl__egc *egc, libxl__devices_remove_state *drs)
|
||||
aodev->action = LIBXL__DEVICE_ACTION_REMOVE;
|
||||
aodev->dev = dev;
|
||||
aodev->force = drs->force;
|
||||
libxl__initiate_device_generic_remove(egc, aodev);
|
||||
if (dev->backend_kind == LIBXL__DEVICE_KIND_VUSB)
|
||||
libxl__initiate_device_usbctrl_remove(egc, aodev);
|
||||
else
|
||||
libxl__initiate_device_generic_remove(egc, aodev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2585,6 +2585,14 @@ _hidden void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid,
|
||||
libxl_device_vtpm *vtpm,
|
||||
libxl__ao_device *aodev);
|
||||
|
||||
_hidden void libxl__device_usbctrl_add(libxl__egc *egc, uint32_t domid,
|
||||
libxl_device_usbctrl *usbctrl,
|
||||
libxl__ao_device *aodev);
|
||||
|
||||
_hidden void libxl__device_usbdev_add(libxl__egc *egc, uint32_t domid,
|
||||
libxl_device_usbdev *usbdev,
|
||||
libxl__ao_device *aodev);
|
||||
|
||||
/* Internal function to connect a vkb device */
|
||||
_hidden int libxl__device_vkb_add(libxl__gc *gc, uint32_t domid,
|
||||
libxl_device_vkb *vkb);
|
||||
@@ -2617,6 +2625,13 @@ _hidden void libxl__wait_device_connection(libxl__egc*,
|
||||
_hidden void libxl__initiate_device_generic_remove(libxl__egc *egc,
|
||||
libxl__ao_device *aodev);
|
||||
|
||||
_hidden int libxl__device_from_usbctrl(libxl__gc *gc, uint32_t domid,
|
||||
libxl_device_usbctrl *usbctrl,
|
||||
libxl__device *device);
|
||||
|
||||
_hidden void libxl__initiate_device_usbctrl_remove(libxl__egc *egc,
|
||||
libxl__ao_device *aodev);
|
||||
|
||||
/*
|
||||
* libxl__get_hotplug_script_info returns the args and env that should
|
||||
* be passed to the hotplug script for the requested device.
|
||||
@@ -4012,6 +4027,9 @@ static inline void libxl__update_config_vtpm(libxl__gc *gc,
|
||||
#define COMPARE_PCI(a, b) ((a)->func == (b)->func && \
|
||||
(a)->bus == (b)->bus && \
|
||||
(a)->dev == (b)->dev)
|
||||
#define COMPARE_USB(a, b) ((a)->ctrl == (b)->ctrl && \
|
||||
(a)->port == (b)->port)
|
||||
#define COMPARE_USBCTRL(a, b) ((a)->devid == (b)->devid)
|
||||
|
||||
/* DEVICE_ADD
|
||||
*
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#if defined(__NetBSD__)
|
||||
#define SYSFS_USB_DEV "/sys/bus/usb/devices"
|
||||
#define SYSFS_USBBACK_DRIVER "/kern/xen/usb"
|
||||
#define SYSFS_PCI_DEV "/sys/bus/pci/devices"
|
||||
#define SYSFS_PCIBACK_DRIVER "/kern/xen/pci"
|
||||
#define NETBACK_NIC_NAME "xvif%ui%d"
|
||||
@@ -31,6 +33,8 @@
|
||||
#elif defined(__OpenBSD__)
|
||||
#include <util.h>
|
||||
#elif defined(__linux__)
|
||||
#define SYSFS_USB_DEV "/sys/bus/usb/devices"
|
||||
#define SYSFS_USBBACK_DRIVER "/sys/bus/usb/drivers/usbback"
|
||||
#define SYSFS_PCI_DEV "/sys/bus/pci/devices"
|
||||
#define SYSFS_PCIBACK_DRIVER "/sys/bus/pci/drivers/pciback"
|
||||
#define NETBACK_NIC_NAME "vif%u.%d"
|
||||
@@ -38,6 +42,8 @@
|
||||
#elif defined(__sun__)
|
||||
#include <stropts.h>
|
||||
#elif defined(__FreeBSD__)
|
||||
#define SYSFS_USB_DEV "/dev/null"
|
||||
#define SYSFS_USBBACK_DRIVER "/dev/null"
|
||||
#define SYSFS_PCI_DEV "/dev/null"
|
||||
#define SYSFS_PCIBACK_DRIVER "/dev/null"
|
||||
#define NETBACK_NIC_NAME "xnb%u.%d"
|
||||
@@ -45,6 +51,13 @@
|
||||
#include <sys/endian.h>
|
||||
#endif
|
||||
|
||||
#ifndef SYSFS_USBBACK_DRIVER
|
||||
#error define SYSFS_USBBACK_DRIVER for your platform
|
||||
#endif
|
||||
#ifndef SYSFS_USB_DEV
|
||||
#error define SYSFS_USB_DEV for your platform
|
||||
#endif
|
||||
|
||||
#ifndef SYSFS_PCIBACK_DRIVER
|
||||
#error define SYSFS_PCIBACK_DRIVER for your platform
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -613,6 +613,35 @@ libxl_device_rdm = Struct("device_rdm", [
|
||||
("policy", libxl_rdm_reserve_policy),
|
||||
])
|
||||
|
||||
libxl_usbctrl_type = Enumeration("usbctrl_type", [
|
||||
(0, "AUTO"),
|
||||
(1, "PV"),
|
||||
(2, "DEVICEMODEL"),
|
||||
])
|
||||
|
||||
libxl_usbdev_type = Enumeration("usbdev_type", [
|
||||
(1, "hostdev"),
|
||||
])
|
||||
|
||||
libxl_device_usbctrl = Struct("device_usbctrl", [
|
||||
("type", libxl_usbctrl_type),
|
||||
("devid", libxl_devid),
|
||||
("version", integer),
|
||||
("ports", integer),
|
||||
("backend_domid", libxl_domid),
|
||||
("backend_domname", string),
|
||||
])
|
||||
|
||||
libxl_device_usbdev = Struct("device_usbdev", [
|
||||
("ctrl", libxl_devid),
|
||||
("port", integer),
|
||||
("u", KeyedUnion(None, libxl_usbdev_type, "type",
|
||||
[("hostdev", Struct(None, [
|
||||
("hostbus", uint8),
|
||||
("hostaddr", uint8)])),
|
||||
])),
|
||||
])
|
||||
|
||||
libxl_device_dtdev = Struct("device_dtdev", [
|
||||
("path", string),
|
||||
])
|
||||
@@ -651,6 +680,8 @@ libxl_domain_config = Struct("domain_config", [
|
||||
# a channel manifests as a console with a name,
|
||||
# see docs/misc/channels.txt
|
||||
("channels", Array(libxl_device_channel, "num_channels")),
|
||||
("usbctrls", Array(libxl_device_usbctrl, "num_usbctrls")),
|
||||
("usbdevs", Array(libxl_device_usbdev, "num_usbdevs")),
|
||||
|
||||
("on_poweroff", libxl_action_on_shutdown),
|
||||
("on_reboot", libxl_action_on_shutdown),
|
||||
@@ -694,6 +725,21 @@ libxl_vtpminfo = Struct("vtpminfo", [
|
||||
("uuid", libxl_uuid),
|
||||
], dir=DIR_OUT)
|
||||
|
||||
libxl_usbctrlinfo = Struct("usbctrlinfo", [
|
||||
("type", libxl_usbctrl_type),
|
||||
("devid", libxl_devid),
|
||||
("version", integer),
|
||||
("ports", integer),
|
||||
("backend", string),
|
||||
("backend_id", uint32),
|
||||
("frontend", string),
|
||||
("frontend_id", uint32),
|
||||
("state", integer),
|
||||
("evtch", integer),
|
||||
("ref_urb", integer),
|
||||
("ref_conn", integer),
|
||||
], dir=DIR_OUT)
|
||||
|
||||
libxl_vcpuinfo = Struct("vcpuinfo", [
|
||||
("vcpuid", uint32),
|
||||
("cpu", uint32),
|
||||
|
||||
@@ -22,6 +22,7 @@ libxl__device_kind = Enumeration("device_kind", [
|
||||
(6, "VKBD"),
|
||||
(7, "CONSOLE"),
|
||||
(8, "VTPM"),
|
||||
(9, "VUSB"),
|
||||
])
|
||||
|
||||
libxl__console_backend = Enumeration("console_backend", [
|
||||
|
||||
@@ -1311,6 +1311,24 @@ int libxl__random_bytes(libxl__gc *gc, uint8_t *buf, size_t len)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void libxl_device_usbctrl_list_free(libxl_device_usbctrl *list, int nr)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nr; i++)
|
||||
libxl_device_usbctrl_dispose(&list[i]);
|
||||
free(list);
|
||||
}
|
||||
|
||||
void libxl_device_usbdev_list_free(libxl_device_usbdev *list, int nr)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nr; i++)
|
||||
libxl_device_usbdev_dispose(&list[i]);
|
||||
free(list);
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* mode: C
|
||||
|
||||
@@ -76,6 +76,11 @@ int libxl_uuid_to_device_vtpm(libxl_ctx *ctx, uint32_t domid,
|
||||
libxl_uuid *uuid, libxl_device_vtpm *vtpm);
|
||||
int libxl_devid_to_device_vtpm(libxl_ctx *ctx, uint32_t domid,
|
||||
int devid, libxl_device_vtpm *vtpm);
|
||||
int libxl_devid_to_device_usbctrl(libxl_ctx *ctx, uint32_t domid,
|
||||
int devid, libxl_device_usbctrl *usbctrl);
|
||||
int libxl_ctrlport_to_device_usbdev(libxl_ctx *ctx, uint32_t domid,
|
||||
int ctrl, int port,
|
||||
libxl_device_usbdev *usbdev);
|
||||
|
||||
int libxl_bitmap_alloc(libxl_ctx *ctx, libxl_bitmap *bitmap, int n_bits);
|
||||
/* Allocated bimap is from malloc, libxl_bitmap_dispose() to be
|
||||
|
||||