]>
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 | ||
094a2239 | 11 | #include "hw/xen/xen_common.h" |
108f7bba | 12 | #include "hw/sysbus.h" |
82a29e30 PD |
13 | #include "qemu/notify.h" |
14 | ||
15 | typedef void (*XenWatchHandler)(void *opaque); | |
16 | ||
17 | typedef struct XenWatch XenWatch; | |
108f7bba PD |
18 | |
19 | typedef struct XenDevice { | |
20 | DeviceState qdev; | |
094a2239 PD |
21 | domid_t frontend_id; |
22 | char *name; | |
23 | char *backend_path, *frontend_path; | |
24 | enum xenbus_state backend_state, frontend_state; | |
25 | Notifier exit; | |
b6af8926 PD |
26 | XenWatch *backend_state_watch, *frontend_state_watch; |
27 | bool backend_online; | |
28 | XenWatch *backend_online_watch; | |
4b34b5b1 PD |
29 | xengnttab_handle *xgth; |
30 | bool feature_grant_copy; | |
a3d669c8 PD |
31 | xenevtchn_handle *xeh; |
32 | NotifierList event_notifiers; | |
108f7bba PD |
33 | } XenDevice; |
34 | ||
094a2239 | 35 | typedef char *(*XenDeviceGetName)(XenDevice *xendev, Error **errp); |
108f7bba | 36 | typedef void (*XenDeviceRealize)(XenDevice *xendev, Error **errp); |
82a29e30 PD |
37 | typedef void (*XenDeviceFrontendChanged)(XenDevice *xendev, |
38 | enum xenbus_state frontend_state, | |
39 | Error **errp); | |
108f7bba PD |
40 | typedef void (*XenDeviceUnrealize)(XenDevice *xendev, Error **errp); |
41 | ||
42 | typedef struct XenDeviceClass { | |
43 | /*< private >*/ | |
44 | DeviceClass parent_class; | |
45 | /*< public >*/ | |
094a2239 PD |
46 | const char *backend; |
47 | const char *device; | |
48 | XenDeviceGetName get_name; | |
108f7bba | 49 | XenDeviceRealize realize; |
82a29e30 | 50 | XenDeviceFrontendChanged frontend_changed; |
108f7bba PD |
51 | XenDeviceUnrealize unrealize; |
52 | } XenDeviceClass; | |
53 | ||
54 | #define TYPE_XEN_DEVICE "xen-device" | |
55 | #define XEN_DEVICE(obj) \ | |
56 | OBJECT_CHECK(XenDevice, (obj), TYPE_XEN_DEVICE) | |
57 | #define XEN_DEVICE_CLASS(class) \ | |
58 | OBJECT_CLASS_CHECK(XenDeviceClass, (class), TYPE_XEN_DEVICE) | |
59 | #define XEN_DEVICE_GET_CLASS(obj) \ | |
60 | OBJECT_GET_CLASS(XenDeviceClass, (obj), TYPE_XEN_DEVICE) | |
61 | ||
62 | typedef struct XenBus { | |
63 | BusState qbus; | |
094a2239 PD |
64 | domid_t backend_id; |
65 | struct xs_handle *xsh; | |
82a29e30 | 66 | NotifierList watch_notifiers; |
a783f8ad | 67 | XenWatch *backend_watch; |
108f7bba PD |
68 | } XenBus; |
69 | ||
70 | typedef struct XenBusClass { | |
71 | /*< private >*/ | |
72 | BusClass parent_class; | |
73 | } XenBusClass; | |
74 | ||
75 | #define TYPE_XEN_BUS "xen-bus" | |
76 | #define XEN_BUS(obj) \ | |
77 | OBJECT_CHECK(XenBus, (obj), TYPE_XEN_BUS) | |
78 | #define XEN_BUS_CLASS(class) \ | |
79 | OBJECT_CLASS_CHECK(XenBusClass, (class), TYPE_XEN_BUS) | |
80 | #define XEN_BUS_GET_CLASS(obj) \ | |
81 | OBJECT_GET_CLASS(XenBusClass, (obj), TYPE_XEN_BUS) | |
82 | ||
83 | void xen_bus_init(void); | |
84 | ||
82a29e30 PD |
85 | void xen_device_backend_set_state(XenDevice *xendev, |
86 | enum xenbus_state state); | |
87 | enum xenbus_state xen_device_backend_get_state(XenDevice *xendev); | |
88 | ||
b6af8926 PD |
89 | void xen_device_backend_printf(XenDevice *xendev, const char *key, |
90 | const char *fmt, ...) | |
91 | GCC_FMT_ATTR(3, 4); | |
92 | void xen_device_frontend_printf(XenDevice *xendev, const char *key, | |
93 | const char *fmt, ...) | |
94 | GCC_FMT_ATTR(3, 4); | |
95 | ||
96 | int xen_device_frontend_scanf(XenDevice *xendev, const char *key, | |
97 | const char *fmt, ...); | |
98 | ||
4b34b5b1 PD |
99 | void xen_device_set_max_grant_refs(XenDevice *xendev, unsigned int nr_refs, |
100 | Error **errp); | |
101 | void *xen_device_map_grant_refs(XenDevice *xendev, uint32_t *refs, | |
102 | unsigned int nr_refs, int prot, | |
103 | Error **errp); | |
104 | void xen_device_unmap_grant_refs(XenDevice *xendev, void *map, | |
105 | unsigned int nr_refs, Error **errp); | |
106 | ||
107 | typedef struct XenDeviceGrantCopySegment { | |
108 | union { | |
109 | void *virt; | |
110 | struct { | |
111 | uint32_t ref; | |
112 | off_t offset; | |
113 | } foreign; | |
114 | } source, dest; | |
115 | size_t len; | |
116 | } XenDeviceGrantCopySegment; | |
117 | ||
118 | void xen_device_copy_grant_refs(XenDevice *xendev, bool to_domain, | |
119 | XenDeviceGrantCopySegment segs[], | |
120 | unsigned int nr_segs, Error **errp); | |
121 | ||
a3d669c8 PD |
122 | typedef struct XenEventChannel XenEventChannel; |
123 | ||
124 | typedef void (*XenEventHandler)(void *opaque); | |
125 | ||
126 | XenEventChannel *xen_device_bind_event_channel(XenDevice *xendev, | |
127 | unsigned int port, | |
128 | XenEventHandler handler, | |
129 | void *opaque, 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 | ||
108f7bba | 137 | #endif /* HW_XEN_BUS_H */ |