.. | .. |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
---|
1 | 2 | /* |
---|
2 | 3 | * Linux host-side vring helpers; for when the kernel needs to access |
---|
3 | 4 | * someone else's vring. |
---|
4 | 5 | * |
---|
5 | 6 | * Copyright IBM Corporation, 2013. |
---|
6 | 7 | * Parts taken from drivers/vhost/vhost.c Copyright 2009 Red Hat, Inc. |
---|
7 | | - * |
---|
8 | | - * This program is free software; you can redistribute it and/or modify |
---|
9 | | - * it under the terms of the GNU General Public License as published by |
---|
10 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
11 | | - * (at your option) any later version. |
---|
12 | | - * |
---|
13 | | - * This program is distributed in the hope that it will be useful, |
---|
14 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | | - * GNU General Public License for more details. |
---|
17 | | - * |
---|
18 | | - * You should have received a copy of the GNU General Public License |
---|
19 | | - * along with this program; if not, write to the Free Software |
---|
20 | | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
21 | 8 | * |
---|
22 | 9 | * Written by: Rusty Russell <rusty@rustcorp.com.au> |
---|
23 | 10 | */ |
---|
.. | .. |
---|
27 | 14 | #include <linux/virtio_byteorder.h> |
---|
28 | 15 | #include <linux/uio.h> |
---|
29 | 16 | #include <linux/slab.h> |
---|
| 17 | +#if IS_REACHABLE(CONFIG_VHOST_IOTLB) |
---|
| 18 | +#include <linux/dma-direction.h> |
---|
| 19 | +#include <linux/vhost_iotlb.h> |
---|
| 20 | +#endif |
---|
30 | 21 | #include <asm/barrier.h> |
---|
31 | 22 | |
---|
32 | 23 | /* virtio_ring with information needed for host access. */ |
---|
.. | .. |
---|
51 | 42 | |
---|
52 | 43 | /* The vring (note: it may contain user pointers!) */ |
---|
53 | 44 | struct vring vring; |
---|
| 45 | + |
---|
| 46 | + /* IOTLB for this vring */ |
---|
| 47 | + struct vhost_iotlb *iotlb; |
---|
54 | 48 | |
---|
55 | 49 | /* The function to call to notify the guest about added buffers */ |
---|
56 | 50 | void (*notify)(struct vringh *); |
---|
.. | .. |
---|
111 | 105 | /* Helpers for userspace vrings. */ |
---|
112 | 106 | int vringh_init_user(struct vringh *vrh, u64 features, |
---|
113 | 107 | unsigned int num, bool weak_barriers, |
---|
114 | | - struct vring_desc __user *desc, |
---|
115 | | - struct vring_avail __user *avail, |
---|
116 | | - struct vring_used __user *used); |
---|
| 108 | + vring_desc_t __user *desc, |
---|
| 109 | + vring_avail_t __user *avail, |
---|
| 110 | + vring_used_t __user *used); |
---|
117 | 111 | |
---|
118 | 112 | static inline void vringh_iov_init(struct vringh_iov *iov, |
---|
119 | 113 | struct iovec *iovec, unsigned num) |
---|
.. | .. |
---|
261 | 255 | { |
---|
262 | 256 | return __cpu_to_virtio64(vringh_is_little_endian(vrh), val); |
---|
263 | 257 | } |
---|
| 258 | + |
---|
| 259 | +#if IS_REACHABLE(CONFIG_VHOST_IOTLB) |
---|
| 260 | + |
---|
| 261 | +void vringh_set_iotlb(struct vringh *vrh, struct vhost_iotlb *iotlb); |
---|
| 262 | + |
---|
| 263 | +int vringh_init_iotlb(struct vringh *vrh, u64 features, |
---|
| 264 | + unsigned int num, bool weak_barriers, |
---|
| 265 | + struct vring_desc *desc, |
---|
| 266 | + struct vring_avail *avail, |
---|
| 267 | + struct vring_used *used); |
---|
| 268 | + |
---|
| 269 | +int vringh_getdesc_iotlb(struct vringh *vrh, |
---|
| 270 | + struct vringh_kiov *riov, |
---|
| 271 | + struct vringh_kiov *wiov, |
---|
| 272 | + u16 *head, |
---|
| 273 | + gfp_t gfp); |
---|
| 274 | + |
---|
| 275 | +ssize_t vringh_iov_pull_iotlb(struct vringh *vrh, |
---|
| 276 | + struct vringh_kiov *riov, |
---|
| 277 | + void *dst, size_t len); |
---|
| 278 | +ssize_t vringh_iov_push_iotlb(struct vringh *vrh, |
---|
| 279 | + struct vringh_kiov *wiov, |
---|
| 280 | + const void *src, size_t len); |
---|
| 281 | + |
---|
| 282 | +void vringh_abandon_iotlb(struct vringh *vrh, unsigned int num); |
---|
| 283 | + |
---|
| 284 | +int vringh_complete_iotlb(struct vringh *vrh, u16 head, u32 len); |
---|
| 285 | + |
---|
| 286 | +bool vringh_notify_enable_iotlb(struct vringh *vrh); |
---|
| 287 | +void vringh_notify_disable_iotlb(struct vringh *vrh); |
---|
| 288 | + |
---|
| 289 | +int vringh_need_notify_iotlb(struct vringh *vrh); |
---|
| 290 | + |
---|
| 291 | +#endif /* CONFIG_VHOST_IOTLB */ |
---|
| 292 | + |
---|
264 | 293 | #endif /* _LINUX_VRINGH_H */ |
---|