master
h 138 lines 4.73 KB
Raw
1 /*
2 * Copyright (c) 2018 Citrix Systems Inc.
3 *
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 */
7
8 #ifndef HW_XEN_BUS_H
9 #define HW_XEN_BUS_H
10
11 #include "hw/core/qdev.h"
12 #include "hw/xen/xen_backend_ops.h"
13 #include "qemu/notify.h"
14 #include "qemu/queue.h"
15 #include "qom/object.h"
16
17 typedef struct XenEventChannel XenEventChannel;
18
19 struct XenDevice {
20 DeviceState qdev;
21 domid_t frontend_id;
22 char *name;
23 struct qemu_xs_handle *xsh;
24 char *backend_path, *frontend_path;
25 enum xenbus_state backend_state, frontend_state;
26 Notifier exit;
27 struct qemu_xs_watch *backend_state_watch, *frontend_state_watch;
28 bool backend_online;
29 struct qemu_xs_watch *backend_online_watch;
30 xengnttab_handle *xgth;
31 bool inactive;
32 QLIST_HEAD(, XenEventChannel) event_channels;
33 QLIST_ENTRY(XenDevice) list;
34 };
35 typedef struct XenDevice XenDevice;
36
37 typedef char *(*XenDeviceGetFrontendPath)(XenDevice *xendev, Error **errp);
38 typedef char *(*XenDeviceGetName)(XenDevice *xendev, Error **errp);
39 typedef void (*XenDeviceRealize)(XenDevice *xendev, Error **errp);
40 typedef void (*XenDeviceFrontendChanged)(XenDevice *xendev,
41 enum xenbus_state frontend_state,
42 Error **errp);
43 typedef void (*XenDeviceUnrealize)(XenDevice *xendev);
44
45 struct XenDeviceClass {
46 /*< private >*/
47 DeviceClass parent_class;
48 /*< public >*/
49 const char *backend;
50 const char *device;
51 XenDeviceGetFrontendPath get_frontend_path;
52 XenDeviceGetName get_name;
53 XenDeviceRealize realize;
54 XenDeviceFrontendChanged frontend_changed;
55 XenDeviceUnrealize unrealize;
56 };
57
58 #define TYPE_XEN_DEVICE "xen-device"
59 OBJECT_DECLARE_TYPE(XenDevice, XenDeviceClass, XEN_DEVICE)
60
61 struct XenBus {
62 BusState qbus;
63 domid_t backend_id;
64 struct qemu_xs_handle *xsh;
65 unsigned int backend_types;
66 struct qemu_xs_watch **backend_watch;
67 QLIST_HEAD(, XenDevice) inactive_devices;
68 };
69
70 struct XenBusClass {
71 /*< private >*/
72 BusClass parent_class;
73 };
74
75 #define TYPE_XEN_BUS "xen-bus"
76 OBJECT_DECLARE_TYPE(XenBus, XenBusClass,
77 XEN_BUS)
78
79 void xen_bus_init(void);
80
81 void xen_device_backend_set_state(XenDevice *xendev,
82 enum xenbus_state state);
83 enum xenbus_state xen_device_backend_get_state(XenDevice *xendev);
84
85 void xen_device_backend_printf(XenDevice *xendev, const char *key,
86 const char *fmt, ...)
87 G_GNUC_PRINTF(3, 4);
88 void xen_device_frontend_printf(XenDevice *xendev, const char *key,
89 const char *fmt, ...)
90 G_GNUC_PRINTF(3, 4);
91
92 int xen_device_frontend_scanf(XenDevice *xendev, const char *key,
93 const char *fmt, ...)
94 G_GNUC_SCANF(3, 4);
95 char *xen_device_frontend_read(XenDevice *xendev, const char *key);
96
97 void xen_device_set_max_grant_refs(XenDevice *xendev, unsigned int nr_refs,
98 Error **errp);
99 void *xen_device_map_grant_refs(XenDevice *xendev, uint32_t *refs,
100 unsigned int nr_refs, int prot,
101 Error **errp);
102 void xen_device_unmap_grant_refs(XenDevice *xendev, void *map, uint32_t *refs,
103 unsigned int nr_refs, Error **errp);
104
105 typedef struct XenDeviceGrantCopySegment {
106 union {
107 void *virt;
108 struct {
109 uint32_t ref;
110 off_t offset;
111 } foreign;
112 } source, dest;
113 size_t len;
114 } XenDeviceGrantCopySegment;
115
116 void xen_device_copy_grant_refs(XenDevice *xendev, bool to_domain,
117 XenDeviceGrantCopySegment segs[],
118 unsigned int nr_segs, Error **errp);
119
120 typedef bool (*XenEventHandler)(void *opaque);
121
122 XenEventChannel *xen_device_bind_event_channel(XenDevice *xendev,
123 unsigned int port,
124 XenEventHandler handler,
125 void *opaque, Error **errp);
126 void xen_device_set_event_channel_context(XenDevice *xendev,
127 XenEventChannel *channel,
128 AioContext *ctx,
129 Error **errp);
130 void xen_device_notify_event_channel(XenDevice *xendev,
131 XenEventChannel *channel,
132 Error **errp);
133 void xen_device_unbind_event_channel(XenDevice *xendev,
134 XenEventChannel *channel,
135 Error **errp);
136 unsigned int xen_event_channel_get_local_port(XenEventChannel *channel);
137
138 #endif /* HW_XEN_BUS_H */