MAINTAINERS: Make section QOM cover hw/core/*bus.c as well
[qemu/armbru.git] / include / hw / xen / xen-bus.h
blob4ec0bb072ff43458dff21c2910cbebdf54e7fe16
1 /*
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.
6 */
8 #ifndef HW_XEN_BUS_H
9 #define HW_XEN_BUS_H
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 {
22 DeviceState qdev;
23 domid_t frontend_id;
24 char *name;
25 struct xs_handle *xsh;
26 XenWatchList *watch_list;
27 char *backend_path, *frontend_path;
28 enum xenbus_state backend_state, frontend_state;
29 Notifier exit;
30 XenWatch *backend_state_watch, *frontend_state_watch;
31 bool backend_online;
32 XenWatch *backend_online_watch;
33 xengnttab_handle *xgth;
34 bool feature_grant_copy;
35 bool inactive;
36 QLIST_HEAD(, XenEventChannel) event_channels;
37 QLIST_ENTRY(XenDevice) list;
38 } XenDevice;
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,
44 Error **errp);
45 typedef void (*XenDeviceUnrealize)(XenDevice *xendev);
47 typedef struct XenDeviceClass {
48 /*< private >*/
49 DeviceClass parent_class;
50 /*< public >*/
51 const char *backend;
52 const char *device;
53 XenDeviceGetName get_name;
54 XenDeviceRealize realize;
55 XenDeviceFrontendChanged frontend_changed;
56 XenDeviceUnrealize unrealize;
57 } XenDeviceClass;
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 {
68 BusState qbus;
69 domid_t backend_id;
70 struct xs_handle *xsh;
71 XenWatchList *watch_list;
72 XenWatch *backend_watch;
73 QLIST_HEAD(, XenDevice) inactive_devices;
74 } XenBus;
76 typedef struct XenBusClass {
77 /*< private >*/
78 BusClass parent_class;
79 } XenBusClass;
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,
96 const char *fmt, ...)
97 GCC_FMT_ATTR(3, 4);
98 void xen_device_frontend_printf(XenDevice *xendev, const char *key,
99 const char *fmt, ...)
100 GCC_FMT_ATTR(3, 4);
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,
106 Error **errp);
107 void *xen_device_map_grant_refs(XenDevice *xendev, uint32_t *refs,
108 unsigned int nr_refs, int prot,
109 Error **errp);
110 void xen_device_unmap_grant_refs(XenDevice *xendev, void *map,
111 unsigned int nr_refs, Error **errp);
113 typedef struct XenDeviceGrantCopySegment {
114 union {
115 void *virt;
116 struct {
117 uint32_t ref;
118 off_t offset;
119 } foreign;
120 } source, dest;
121 size_t len;
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,
131 unsigned int port,
132 XenEventHandler handler,
133 void *opaque, Error **errp);
134 void xen_device_set_event_channel_context(XenDevice *xendev,
135 XenEventChannel *channel,
136 AioContext *ctx,
137 Error **errp);
138 void xen_device_notify_event_channel(XenDevice *xendev,
139 XenEventChannel *channel,
140 Error **errp);
141 void xen_device_unbind_event_channel(XenDevice *xendev,
142 XenEventChannel *channel,
143 Error **errp);
145 #endif /* HW_XEN_BUS_H */