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 XenWatchList XenWatchList
;
18 typedef struct XenWatch XenWatch
;
19 typedef struct XenEventChannel XenEventChannel
;
21 typedef struct XenDevice
{
25 struct xs_handle
*xsh
;
26 XenWatchList
*watch_list
;
27 char *backend_path
, *frontend_path
;
28 enum xenbus_state backend_state
, frontend_state
;
30 XenWatch
*backend_state_watch
, *frontend_state_watch
;
32 XenWatch
*backend_online_watch
;
33 xengnttab_handle
*xgth
;
34 bool feature_grant_copy
;
36 QLIST_HEAD(, XenEventChannel
) event_channels
;
37 QLIST_ENTRY(XenDevice
) list
;
40 typedef char *(*XenDeviceGetName
)(XenDevice
*xendev
, Error
**errp
);
41 typedef void (*XenDeviceRealize
)(XenDevice
*xendev
, Error
**errp
);
42 typedef void (*XenDeviceFrontendChanged
)(XenDevice
*xendev
,
43 enum xenbus_state frontend_state
,
45 typedef void (*XenDeviceUnrealize
)(XenDevice
*xendev
);
47 typedef struct XenDeviceClass
{
49 DeviceClass parent_class
;
53 XenDeviceGetName get_name
;
54 XenDeviceRealize realize
;
55 XenDeviceFrontendChanged frontend_changed
;
56 XenDeviceUnrealize unrealize
;
59 #define TYPE_XEN_DEVICE "xen-device"
60 #define XEN_DEVICE(obj) \
61 OBJECT_CHECK(XenDevice, (obj), TYPE_XEN_DEVICE)
62 #define XEN_DEVICE_CLASS(class) \
63 OBJECT_CLASS_CHECK(XenDeviceClass, (class), TYPE_XEN_DEVICE)
64 #define XEN_DEVICE_GET_CLASS(obj) \
65 OBJECT_GET_CLASS(XenDeviceClass, (obj), TYPE_XEN_DEVICE)
67 typedef struct XenBus
{
70 struct xs_handle
*xsh
;
71 XenWatchList
*watch_list
;
72 XenWatch
*backend_watch
;
73 QLIST_HEAD(, XenDevice
) inactive_devices
;
76 typedef struct XenBusClass
{
78 BusClass parent_class
;
81 #define TYPE_XEN_BUS "xen-bus"
82 #define XEN_BUS(obj) \
83 OBJECT_CHECK(XenBus, (obj), TYPE_XEN_BUS)
84 #define XEN_BUS_CLASS(class) \
85 OBJECT_CLASS_CHECK(XenBusClass, (class), TYPE_XEN_BUS)
86 #define XEN_BUS_GET_CLASS(obj) \
87 OBJECT_GET_CLASS(XenBusClass, (obj), TYPE_XEN_BUS)
89 void xen_bus_init(void);
91 void xen_device_backend_set_state(XenDevice
*xendev
,
92 enum xenbus_state state
);
93 enum xenbus_state
xen_device_backend_get_state(XenDevice
*xendev
);
95 void xen_device_backend_printf(XenDevice
*xendev
, const char *key
,
98 void xen_device_frontend_printf(XenDevice
*xendev
, const char *key
,
102 int xen_device_frontend_scanf(XenDevice
*xendev
, const char *key
,
103 const char *fmt
, ...);
105 void xen_device_set_max_grant_refs(XenDevice
*xendev
, unsigned int nr_refs
,
107 void *xen_device_map_grant_refs(XenDevice
*xendev
, uint32_t *refs
,
108 unsigned int nr_refs
, int prot
,
110 void xen_device_unmap_grant_refs(XenDevice
*xendev
, void *map
,
111 unsigned int nr_refs
, Error
**errp
);
113 typedef struct XenDeviceGrantCopySegment
{
122 } XenDeviceGrantCopySegment
;
124 void xen_device_copy_grant_refs(XenDevice
*xendev
, bool to_domain
,
125 XenDeviceGrantCopySegment segs
[],
126 unsigned int nr_segs
, Error
**errp
);
128 typedef bool (*XenEventHandler
)(void *opaque
);
130 XenEventChannel
*xen_device_bind_event_channel(XenDevice
*xendev
,
132 XenEventHandler handler
,
133 void *opaque
, Error
**errp
);
134 void xen_device_set_event_channel_context(XenDevice
*xendev
,
135 XenEventChannel
*channel
,
138 void xen_device_notify_event_channel(XenDevice
*xendev
,
139 XenEventChannel
*channel
,
141 void xen_device_unbind_event_channel(XenDevice
*xendev
,
142 XenEventChannel
*channel
,
145 #endif /* HW_XEN_BUS_H */