2019-01-08 17:48:47 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Citrix Systems Inc.
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HW_XEN_BUS_H
|
|
|
|
#define HW_XEN_BUS_H
|
|
|
|
|
2019-01-08 17:48:49 +03:00
|
|
|
#include "hw/xen/xen_common.h"
|
2019-01-08 17:48:47 +03:00
|
|
|
#include "hw/sysbus.h"
|
2019-01-08 17:48:50 +03:00
|
|
|
#include "qemu/notify.h"
|
|
|
|
|
|
|
|
typedef void (*XenWatchHandler)(void *opaque);
|
|
|
|
|
|
|
|
typedef struct XenWatch XenWatch;
|
2019-04-08 18:16:15 +03:00
|
|
|
typedef struct XenEventChannel XenEventChannel;
|
2019-01-08 17:48:47 +03:00
|
|
|
|
|
|
|
typedef struct XenDevice {
|
|
|
|
DeviceState qdev;
|
2019-01-08 17:48:49 +03:00
|
|
|
domid_t frontend_id;
|
|
|
|
char *name;
|
|
|
|
char *backend_path, *frontend_path;
|
|
|
|
enum xenbus_state backend_state, frontend_state;
|
|
|
|
Notifier exit;
|
2019-01-08 17:48:59 +03:00
|
|
|
XenWatch *backend_state_watch, *frontend_state_watch;
|
|
|
|
bool backend_online;
|
|
|
|
XenWatch *backend_online_watch;
|
2019-01-08 17:48:51 +03:00
|
|
|
xengnttab_handle *xgth;
|
|
|
|
bool feature_grant_copy;
|
2019-04-08 18:16:15 +03:00
|
|
|
QLIST_HEAD(, XenEventChannel) event_channels;
|
2019-01-08 17:48:47 +03:00
|
|
|
} XenDevice;
|
|
|
|
|
2019-01-08 17:48:49 +03:00
|
|
|
typedef char *(*XenDeviceGetName)(XenDevice *xendev, Error **errp);
|
2019-01-08 17:48:47 +03:00
|
|
|
typedef void (*XenDeviceRealize)(XenDevice *xendev, Error **errp);
|
2019-01-08 17:48:50 +03:00
|
|
|
typedef void (*XenDeviceFrontendChanged)(XenDevice *xendev,
|
|
|
|
enum xenbus_state frontend_state,
|
|
|
|
Error **errp);
|
2019-01-08 17:48:47 +03:00
|
|
|
typedef void (*XenDeviceUnrealize)(XenDevice *xendev, Error **errp);
|
|
|
|
|
|
|
|
typedef struct XenDeviceClass {
|
|
|
|
/*< private >*/
|
|
|
|
DeviceClass parent_class;
|
|
|
|
/*< public >*/
|
2019-01-08 17:48:49 +03:00
|
|
|
const char *backend;
|
|
|
|
const char *device;
|
|
|
|
XenDeviceGetName get_name;
|
2019-01-08 17:48:47 +03:00
|
|
|
XenDeviceRealize realize;
|
2019-01-08 17:48:50 +03:00
|
|
|
XenDeviceFrontendChanged frontend_changed;
|
2019-01-08 17:48:47 +03:00
|
|
|
XenDeviceUnrealize unrealize;
|
|
|
|
} XenDeviceClass;
|
|
|
|
|
|
|
|
#define TYPE_XEN_DEVICE "xen-device"
|
|
|
|
#define XEN_DEVICE(obj) \
|
|
|
|
OBJECT_CHECK(XenDevice, (obj), TYPE_XEN_DEVICE)
|
|
|
|
#define XEN_DEVICE_CLASS(class) \
|
|
|
|
OBJECT_CLASS_CHECK(XenDeviceClass, (class), TYPE_XEN_DEVICE)
|
|
|
|
#define XEN_DEVICE_GET_CLASS(obj) \
|
|
|
|
OBJECT_GET_CLASS(XenDeviceClass, (obj), TYPE_XEN_DEVICE)
|
|
|
|
|
|
|
|
typedef struct XenBus {
|
|
|
|
BusState qbus;
|
2019-01-08 17:48:49 +03:00
|
|
|
domid_t backend_id;
|
|
|
|
struct xs_handle *xsh;
|
2019-01-08 17:48:50 +03:00
|
|
|
NotifierList watch_notifiers;
|
2019-01-08 17:49:00 +03:00
|
|
|
XenWatch *backend_watch;
|
2019-01-08 17:48:47 +03:00
|
|
|
} XenBus;
|
|
|
|
|
|
|
|
typedef struct XenBusClass {
|
|
|
|
/*< private >*/
|
|
|
|
BusClass parent_class;
|
|
|
|
} XenBusClass;
|
|
|
|
|
|
|
|
#define TYPE_XEN_BUS "xen-bus"
|
|
|
|
#define XEN_BUS(obj) \
|
|
|
|
OBJECT_CHECK(XenBus, (obj), TYPE_XEN_BUS)
|
|
|
|
#define XEN_BUS_CLASS(class) \
|
|
|
|
OBJECT_CLASS_CHECK(XenBusClass, (class), TYPE_XEN_BUS)
|
|
|
|
#define XEN_BUS_GET_CLASS(obj) \
|
|
|
|
OBJECT_GET_CLASS(XenBusClass, (obj), TYPE_XEN_BUS)
|
|
|
|
|
|
|
|
void xen_bus_init(void);
|
|
|
|
|
2019-01-08 17:48:50 +03:00
|
|
|
void xen_device_backend_set_state(XenDevice *xendev,
|
|
|
|
enum xenbus_state state);
|
|
|
|
enum xenbus_state xen_device_backend_get_state(XenDevice *xendev);
|
|
|
|
|
2019-01-08 17:48:59 +03:00
|
|
|
void xen_device_backend_printf(XenDevice *xendev, const char *key,
|
|
|
|
const char *fmt, ...)
|
|
|
|
GCC_FMT_ATTR(3, 4);
|
|
|
|
void xen_device_frontend_printf(XenDevice *xendev, const char *key,
|
|
|
|
const char *fmt, ...)
|
|
|
|
GCC_FMT_ATTR(3, 4);
|
|
|
|
|
|
|
|
int xen_device_frontend_scanf(XenDevice *xendev, const char *key,
|
|
|
|
const char *fmt, ...);
|
|
|
|
|
2019-01-08 17:48:51 +03:00
|
|
|
void xen_device_set_max_grant_refs(XenDevice *xendev, unsigned int nr_refs,
|
|
|
|
Error **errp);
|
|
|
|
void *xen_device_map_grant_refs(XenDevice *xendev, uint32_t *refs,
|
|
|
|
unsigned int nr_refs, int prot,
|
|
|
|
Error **errp);
|
|
|
|
void xen_device_unmap_grant_refs(XenDevice *xendev, void *map,
|
|
|
|
unsigned int nr_refs, Error **errp);
|
|
|
|
|
|
|
|
typedef struct XenDeviceGrantCopySegment {
|
|
|
|
union {
|
|
|
|
void *virt;
|
|
|
|
struct {
|
|
|
|
uint32_t ref;
|
|
|
|
off_t offset;
|
|
|
|
} foreign;
|
|
|
|
} source, dest;
|
|
|
|
size_t len;
|
|
|
|
} XenDeviceGrantCopySegment;
|
|
|
|
|
|
|
|
void xen_device_copy_grant_refs(XenDevice *xendev, bool to_domain,
|
|
|
|
XenDeviceGrantCopySegment segs[],
|
|
|
|
unsigned int nr_segs, Error **errp);
|
|
|
|
|
2019-04-08 18:16:17 +03:00
|
|
|
typedef bool (*XenEventHandler)(void *opaque);
|
2019-01-08 17:48:52 +03:00
|
|
|
|
|
|
|
XenEventChannel *xen_device_bind_event_channel(XenDevice *xendev,
|
2019-04-08 18:16:16 +03:00
|
|
|
AioContext *ctx,
|
2019-01-08 17:48:52 +03:00
|
|
|
unsigned int port,
|
|
|
|
XenEventHandler handler,
|
|
|
|
void *opaque, Error **errp);
|
|
|
|
void xen_device_notify_event_channel(XenDevice *xendev,
|
|
|
|
XenEventChannel *channel,
|
|
|
|
Error **errp);
|
|
|
|
void xen_device_unbind_event_channel(XenDevice *xendev,
|
|
|
|
XenEventChannel *channel,
|
|
|
|
Error **errp);
|
|
|
|
|
2019-01-08 17:48:47 +03:00
|
|
|
#endif /* HW_XEN_BUS_H */
|