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