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_common.h"
12 #include "hw/sysbus.h"
13 #include "qemu/notify.h"
15 typedef void (*XenWatchHandler
)(void *opaque
);
17 typedef struct XenWatch XenWatch
;
19 typedef struct XenDevice
{
23 char *backend_path
, *frontend_path
;
24 enum xenbus_state backend_state
, frontend_state
;
26 XenWatch
*backend_state_watch
, *frontend_state_watch
;
28 XenWatch
*backend_online_watch
;
29 xengnttab_handle
*xgth
;
30 bool feature_grant_copy
;
31 xenevtchn_handle
*xeh
;
32 NotifierList event_notifiers
;
35 typedef char *(*XenDeviceGetName
)(XenDevice
*xendev
, Error
**errp
);
36 typedef void (*XenDeviceRealize
)(XenDevice
*xendev
, Error
**errp
);
37 typedef void (*XenDeviceFrontendChanged
)(XenDevice
*xendev
,
38 enum xenbus_state frontend_state
,
40 typedef void (*XenDeviceUnrealize
)(XenDevice
*xendev
, Error
**errp
);
42 typedef struct XenDeviceClass
{
44 DeviceClass parent_class
;
48 XenDeviceGetName get_name
;
49 XenDeviceRealize realize
;
50 XenDeviceFrontendChanged frontend_changed
;
51 XenDeviceUnrealize unrealize
;
54 #define TYPE_XEN_DEVICE "xen-device"
55 #define XEN_DEVICE(obj) \
56 OBJECT_CHECK(XenDevice, (obj), TYPE_XEN_DEVICE)
57 #define XEN_DEVICE_CLASS(class) \
58 OBJECT_CLASS_CHECK(XenDeviceClass, (class), TYPE_XEN_DEVICE)
59 #define XEN_DEVICE_GET_CLASS(obj) \
60 OBJECT_GET_CLASS(XenDeviceClass, (obj), TYPE_XEN_DEVICE)
62 typedef struct XenBus
{
65 struct xs_handle
*xsh
;
66 NotifierList watch_notifiers
;
67 XenWatch
*backend_watch
;
70 typedef struct XenBusClass
{
72 BusClass parent_class
;
75 #define TYPE_XEN_BUS "xen-bus"
76 #define XEN_BUS(obj) \
77 OBJECT_CHECK(XenBus, (obj), TYPE_XEN_BUS)
78 #define XEN_BUS_CLASS(class) \
79 OBJECT_CLASS_CHECK(XenBusClass, (class), TYPE_XEN_BUS)
80 #define XEN_BUS_GET_CLASS(obj) \
81 OBJECT_GET_CLASS(XenBusClass, (obj), TYPE_XEN_BUS)
83 void xen_bus_init(void);
85 void xen_device_backend_set_state(XenDevice
*xendev
,
86 enum xenbus_state state
);
87 enum xenbus_state
xen_device_backend_get_state(XenDevice
*xendev
);
89 void xen_device_backend_printf(XenDevice
*xendev
, const char *key
,
92 void xen_device_frontend_printf(XenDevice
*xendev
, const char *key
,
96 int xen_device_frontend_scanf(XenDevice
*xendev
, const char *key
,
97 const char *fmt
, ...);
99 void xen_device_set_max_grant_refs(XenDevice
*xendev
, unsigned int nr_refs
,
101 void *xen_device_map_grant_refs(XenDevice
*xendev
, uint32_t *refs
,
102 unsigned int nr_refs
, int prot
,
104 void xen_device_unmap_grant_refs(XenDevice
*xendev
, void *map
,
105 unsigned int nr_refs
, Error
**errp
);
107 typedef struct XenDeviceGrantCopySegment
{
116 } XenDeviceGrantCopySegment
;
118 void xen_device_copy_grant_refs(XenDevice
*xendev
, bool to_domain
,
119 XenDeviceGrantCopySegment segs
[],
120 unsigned int nr_segs
, Error
**errp
);
122 typedef struct XenEventChannel XenEventChannel
;
124 typedef void (*XenEventHandler
)(void *opaque
);
126 XenEventChannel
*xen_device_bind_event_channel(XenDevice
*xendev
,
128 XenEventHandler handler
,
129 void *opaque
, Error
**errp
);
130 void xen_device_notify_event_channel(XenDevice
*xendev
,
131 XenEventChannel
*channel
,
133 void xen_device_unbind_event_channel(XenDevice
*xendev
,
134 XenEventChannel
*channel
,
137 #endif /* HW_XEN_BUS_H */