blob: e79a408389981e8bb0254aa6ba93cc4c265017e7 [file] [log] [blame]
Jason Wang0bbe3062020-03-26 22:01:19 +08001/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_VHOST_IOTLB_H
3#define _LINUX_VHOST_IOTLB_H
4
5#include <linux/interval_tree_generic.h>
6
7struct vhost_iotlb_map {
8 struct rb_node rb;
9 struct list_head link;
10 u64 start;
11 u64 last;
12 u64 size;
13 u64 addr;
14#define VHOST_MAP_RO 0x1
15#define VHOST_MAP_WO 0x2
16#define VHOST_MAP_RW 0x3
17 u32 perm;
18 u32 flags_padding;
19 u64 __subtree_last;
Xie Yongji59dfe4f2021-08-31 18:36:28 +080020 void *opaque;
Jason Wang0bbe3062020-03-26 22:01:19 +080021};
22
23#define VHOST_IOTLB_FLAG_RETIRE 0x1
24
25struct vhost_iotlb {
26 struct rb_root_cached root;
27 struct list_head list;
28 unsigned int limit;
29 unsigned int nmaps;
30 unsigned int flags;
31};
32
Xie Yongji59dfe4f2021-08-31 18:36:28 +080033int vhost_iotlb_add_range_ctx(struct vhost_iotlb *iotlb, u64 start, u64 last,
34 u64 addr, unsigned int perm, void *opaque);
Jason Wang0bbe3062020-03-26 22:01:19 +080035int vhost_iotlb_add_range(struct vhost_iotlb *iotlb, u64 start, u64 last,
36 u64 addr, unsigned int perm);
37void vhost_iotlb_del_range(struct vhost_iotlb *iotlb, u64 start, u64 last);
38
Gautam Dawar1cb10892022-03-30 23:33:48 +053039void vhost_iotlb_init(struct vhost_iotlb *iotlb, unsigned int limit,
40 unsigned int flags);
Jason Wang0bbe3062020-03-26 22:01:19 +080041struct vhost_iotlb *vhost_iotlb_alloc(unsigned int limit, unsigned int flags);
42void vhost_iotlb_free(struct vhost_iotlb *iotlb);
43void vhost_iotlb_reset(struct vhost_iotlb *iotlb);
44
45struct vhost_iotlb_map *
46vhost_iotlb_itree_first(struct vhost_iotlb *iotlb, u64 start, u64 last);
47struct vhost_iotlb_map *
48vhost_iotlb_itree_next(struct vhost_iotlb_map *map, u64 start, u64 last);
49
50void vhost_iotlb_map_free(struct vhost_iotlb *iotlb,
51 struct vhost_iotlb_map *map);
52#endif