This source file includes following definitions.
- vringh_iov_init
- vringh_iov_reset
- vringh_iov_cleanup
- vringh_kiov_init
- vringh_kiov_reset
- vringh_kiov_cleanup
- vringh_notify
- vringh_is_little_endian
- vringh16_to_cpu
- cpu_to_vringh16
- vringh32_to_cpu
- cpu_to_vringh32
- vringh64_to_cpu
- cpu_to_vringh64
1
2
3
4
5
6
7
8
9
10
11 #ifndef _LINUX_VRINGH_H
12 #define _LINUX_VRINGH_H
13 #include <uapi/linux/virtio_ring.h>
14 #include <linux/virtio_byteorder.h>
15 #include <linux/uio.h>
16 #include <linux/slab.h>
17 #include <asm/barrier.h>
18
19
20 struct vringh {
21
22 bool little_endian;
23
24
25 bool event_indices;
26
27
28 bool weak_barriers;
29
30
31 u16 last_avail_idx;
32
33
34 u16 last_used_idx;
35
36
37 u32 completed;
38
39
40 struct vring vring;
41
42
43 void (*notify)(struct vringh *);
44 };
45
46
47
48
49
50
51
52
53
54
55
56
57 struct virtio_device;
58 typedef void vrh_callback_t(struct virtio_device *, struct vringh *);
59 struct vringh_config_ops {
60 int (*find_vrhs)(struct virtio_device *vdev, unsigned nhvrs,
61 struct vringh *vrhs[], vrh_callback_t *callbacks[]);
62 void (*del_vrhs)(struct virtio_device *vdev);
63 };
64
65
66 struct vringh_range {
67 u64 start, end_incl;
68 u64 offset;
69 };
70
71
72
73
74
75
76
77 struct vringh_iov {
78 struct iovec *iov;
79 size_t consumed;
80 unsigned i, used, max_num;
81 };
82
83
84
85
86
87
88
89 struct vringh_kiov {
90 struct kvec *iov;
91 size_t consumed;
92 unsigned i, used, max_num;
93 };
94
95
96 #define VRINGH_IOV_ALLOCATED 0x8000000
97
98
99 int vringh_init_user(struct vringh *vrh, u64 features,
100 unsigned int num, bool weak_barriers,
101 struct vring_desc __user *desc,
102 struct vring_avail __user *avail,
103 struct vring_used __user *used);
104
105 static inline void vringh_iov_init(struct vringh_iov *iov,
106 struct iovec *iovec, unsigned num)
107 {
108 iov->used = iov->i = 0;
109 iov->consumed = 0;
110 iov->max_num = num;
111 iov->iov = iovec;
112 }
113
114 static inline void vringh_iov_reset(struct vringh_iov *iov)
115 {
116 iov->iov[iov->i].iov_len += iov->consumed;
117 iov->iov[iov->i].iov_base -= iov->consumed;
118 iov->consumed = 0;
119 iov->i = 0;
120 }
121
122 static inline void vringh_iov_cleanup(struct vringh_iov *iov)
123 {
124 if (iov->max_num & VRINGH_IOV_ALLOCATED)
125 kfree(iov->iov);
126 iov->max_num = iov->used = iov->i = iov->consumed = 0;
127 iov->iov = NULL;
128 }
129
130
131 int vringh_getdesc_user(struct vringh *vrh,
132 struct vringh_iov *riov,
133 struct vringh_iov *wiov,
134 bool (*getrange)(struct vringh *vrh,
135 u64 addr, struct vringh_range *r),
136 u16 *head);
137
138
139 ssize_t vringh_iov_pull_user(struct vringh_iov *riov, void *dst, size_t len);
140
141
142 ssize_t vringh_iov_push_user(struct vringh_iov *wiov,
143 const void *src, size_t len);
144
145
146 int vringh_complete_user(struct vringh *vrh, u16 head, u32 len);
147 int vringh_complete_multi_user(struct vringh *vrh,
148 const struct vring_used_elem used[],
149 unsigned num_used);
150
151
152 void vringh_abandon_user(struct vringh *vrh, unsigned int num);
153
154
155 int vringh_need_notify_user(struct vringh *vrh);
156
157 bool vringh_notify_enable_user(struct vringh *vrh);
158 void vringh_notify_disable_user(struct vringh *vrh);
159
160
161 int vringh_init_kern(struct vringh *vrh, u64 features,
162 unsigned int num, bool weak_barriers,
163 struct vring_desc *desc,
164 struct vring_avail *avail,
165 struct vring_used *used);
166
167 static inline void vringh_kiov_init(struct vringh_kiov *kiov,
168 struct kvec *kvec, unsigned num)
169 {
170 kiov->used = kiov->i = 0;
171 kiov->consumed = 0;
172 kiov->max_num = num;
173 kiov->iov = kvec;
174 }
175
176 static inline void vringh_kiov_reset(struct vringh_kiov *kiov)
177 {
178 kiov->iov[kiov->i].iov_len += kiov->consumed;
179 kiov->iov[kiov->i].iov_base -= kiov->consumed;
180 kiov->consumed = 0;
181 kiov->i = 0;
182 }
183
184 static inline void vringh_kiov_cleanup(struct vringh_kiov *kiov)
185 {
186 if (kiov->max_num & VRINGH_IOV_ALLOCATED)
187 kfree(kiov->iov);
188 kiov->max_num = kiov->used = kiov->i = kiov->consumed = 0;
189 kiov->iov = NULL;
190 }
191
192 int vringh_getdesc_kern(struct vringh *vrh,
193 struct vringh_kiov *riov,
194 struct vringh_kiov *wiov,
195 u16 *head,
196 gfp_t gfp);
197
198 ssize_t vringh_iov_pull_kern(struct vringh_kiov *riov, void *dst, size_t len);
199 ssize_t vringh_iov_push_kern(struct vringh_kiov *wiov,
200 const void *src, size_t len);
201 void vringh_abandon_kern(struct vringh *vrh, unsigned int num);
202 int vringh_complete_kern(struct vringh *vrh, u16 head, u32 len);
203
204 bool vringh_notify_enable_kern(struct vringh *vrh);
205 void vringh_notify_disable_kern(struct vringh *vrh);
206
207 int vringh_need_notify_kern(struct vringh *vrh);
208
209
210 static inline void vringh_notify(struct vringh *vrh)
211 {
212 if (vrh->notify)
213 vrh->notify(vrh);
214 }
215
216 static inline bool vringh_is_little_endian(const struct vringh *vrh)
217 {
218 return vrh->little_endian ||
219 virtio_legacy_is_little_endian();
220 }
221
222 static inline u16 vringh16_to_cpu(const struct vringh *vrh, __virtio16 val)
223 {
224 return __virtio16_to_cpu(vringh_is_little_endian(vrh), val);
225 }
226
227 static inline __virtio16 cpu_to_vringh16(const struct vringh *vrh, u16 val)
228 {
229 return __cpu_to_virtio16(vringh_is_little_endian(vrh), val);
230 }
231
232 static inline u32 vringh32_to_cpu(const struct vringh *vrh, __virtio32 val)
233 {
234 return __virtio32_to_cpu(vringh_is_little_endian(vrh), val);
235 }
236
237 static inline __virtio32 cpu_to_vringh32(const struct vringh *vrh, u32 val)
238 {
239 return __cpu_to_virtio32(vringh_is_little_endian(vrh), val);
240 }
241
242 static inline u64 vringh64_to_cpu(const struct vringh *vrh, __virtio64 val)
243 {
244 return __virtio64_to_cpu(vringh_is_little_endian(vrh), val);
245 }
246
247 static inline __virtio64 cpu_to_vringh64(const struct vringh *vrh, u64 val)
248 {
249 return __cpu_to_virtio64(vringh_is_little_endian(vrh), val);
250 }
251 #endif