2 * Copyright (c) 2018 Citrix Systems Inc.
4 * This work is licensed under the terms of the GNU GPL, version 2 or later.
5 * See the COPYING file in the top-level directory.
11 #include "hw/xen/xen_backend_ops.h"
12 #include "hw/sysbus.h"
13 #include "qemu/notify.h"
14 #include "qom/object.h"
16 typedef struct XenEventChannel XenEventChannel
;
22 struct qemu_xs_handle
*xsh
;
23 char *backend_path
, *frontend_path
;
24 enum xenbus_state backend_state
, frontend_state
;
26 struct qemu_xs_watch
*backend_state_watch
, *frontend_state_watch
;
28 struct qemu_xs_watch
*backend_online_watch
;
29 xengnttab_handle
*xgth
;
31 QLIST_HEAD(, XenEventChannel
) event_channels
;
32 QLIST_ENTRY(XenDevice
) list
;
34 typedef struct XenDevice XenDevice
;
36 typedef char *(*XenDeviceGetFrontendPath
)(XenDevice
*xendev
, Error
**errp
);
37 typedef char *(*XenDeviceGetName
)(XenDevice
*xendev
, Error
**errp
);
38 typedef void (*XenDeviceRealize
)(XenDevice
*xendev
, Error
**errp
);
39 typedef void (*XenDeviceFrontendChanged
)(XenDevice
*xendev
,
40 enum xenbus_state frontend_state
,
42 typedef void (*XenDeviceUnrealize
)(XenDevice
*xendev
);
44 struct XenDeviceClass
{
46 DeviceClass parent_class
;
50 XenDeviceGetFrontendPath get_frontend_path
;
51 XenDeviceGetName get_name
;
52 XenDeviceRealize realize
;
53 XenDeviceFrontendChanged frontend_changed
;
54 XenDeviceUnrealize unrealize
;
57 #define TYPE_XEN_DEVICE "xen-device"
58 OBJECT_DECLARE_TYPE(XenDevice
, XenDeviceClass
, XEN_DEVICE
)
63 struct qemu_xs_handle
*xsh
;
64 unsigned int backend_types
;
65 struct qemu_xs_watch
**backend_watch
;
66 QLIST_HEAD(, XenDevice
) inactive_devices
;
71 BusClass parent_class
;
74 #define TYPE_XEN_BUS "xen-bus"
75 OBJECT_DECLARE_TYPE(XenBus
, XenBusClass
,
78 void xen_bus_init(void);
80 void xen_device_backend_set_state(XenDevice
*xendev
,
81 enum xenbus_state state
);
82 enum xenbus_state
xen_device_backend_get_state(XenDevice
*xendev
);
84 void xen_device_backend_printf(XenDevice
*xendev
, const char *key
,
87 void xen_device_frontend_printf(XenDevice
*xendev
, const char *key
,
91 int xen_device_frontend_scanf(XenDevice
*xendev
, const char *key
,
95 void xen_device_set_max_grant_refs(XenDevice
*xendev
, unsigned int nr_refs
,
97 void *xen_device_map_grant_refs(XenDevice
*xendev
, uint32_t *refs
,
98 unsigned int nr_refs
, int prot
,
100 void xen_device_unmap_grant_refs(XenDevice
*xendev
, void *map
, uint32_t *refs
,
101 unsigned int nr_refs
, Error
**errp
);
103 typedef struct XenDeviceGrantCopySegment
{
112 } XenDeviceGrantCopySegment
;
114 void xen_device_copy_grant_refs(XenDevice
*xendev
, bool to_domain
,
115 XenDeviceGrantCopySegment segs
[],
116 unsigned int nr_segs
, Error
**errp
);
118 typedef bool (*XenEventHandler
)(void *opaque
);
120 XenEventChannel
*xen_device_bind_event_channel(XenDevice
*xendev
,
122 XenEventHandler handler
,
123 void *opaque
, Error
**errp
);
124 void xen_device_set_event_channel_context(XenDevice
*xendev
,
125 XenEventChannel
*channel
,
128 void xen_device_notify_event_channel(XenDevice
*xendev
,
129 XenEventChannel
*channel
,
131 void xen_device_unbind_event_channel(XenDevice
*xendev
,
132 XenEventChannel
*channel
,
134 unsigned int xen_event_channel_get_local_port(XenEventChannel
*channel
);
136 #endif /* HW_XEN_BUS_H */