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