forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 072de836f53be56a70cecf70b43ae43b7ce17376
kernel/drivers/vhost/vhost.h
....@@ -12,6 +12,8 @@
1212 #include <linux/virtio_config.h>
1313 #include <linux/virtio_ring.h>
1414 #include <linux/atomic.h>
15
+#include <linux/vhost_iotlb.h>
16
+#include <linux/irqbypass.h>
1517
1618 struct vhost_work;
1719 typedef void (*vhost_work_fn_t)(struct vhost_work *work);
....@@ -52,32 +54,16 @@
5254 u64 len;
5355 };
5456
55
-#define START(node) ((node)->start)
56
-#define LAST(node) ((node)->last)
57
-
58
-struct vhost_umem_node {
59
- struct rb_node rb;
60
- struct list_head link;
61
- __u64 start;
62
- __u64 last;
63
- __u64 size;
64
- __u64 userspace_addr;
65
- __u32 perm;
66
- __u32 flags_padding;
67
- __u64 __subtree_last;
68
-};
69
-
70
-struct vhost_umem {
71
- struct rb_root_cached umem_tree;
72
- struct list_head umem_list;
73
- int numem;
74
-};
75
-
7657 enum vhost_uaddr_type {
7758 VHOST_ADDR_DESC = 0,
7859 VHOST_ADDR_AVAIL = 1,
7960 VHOST_ADDR_USED = 2,
8061 VHOST_NUM_ADDRS = 3,
62
+};
63
+
64
+struct vhost_vring_call {
65
+ struct eventfd_ctx *ctx;
66
+ struct irq_bypass_producer producer;
8167 };
8268
8369 /* The virtqueue structure describes a queue attached to a device. */
....@@ -87,12 +73,12 @@
8773 /* The actual ring of buffers. */
8874 struct mutex mutex;
8975 unsigned int num;
90
- struct vring_desc __user *desc;
91
- struct vring_avail __user *avail;
92
- struct vring_used __user *used;
93
- const struct vhost_umem_node *meta_iotlb[VHOST_NUM_ADDRS];
76
+ vring_desc_t __user *desc;
77
+ vring_avail_t __user *avail;
78
+ vring_used_t __user *used;
79
+ const struct vhost_iotlb_map *meta_iotlb[VHOST_NUM_ADDRS];
9480 struct file *kick;
95
- struct eventfd_ctx *call_ctx;
81
+ struct vhost_vring_call call_ctx;
9682 struct eventfd_ctx *error_ctx;
9783 struct eventfd_ctx *log_ctx;
9884
....@@ -128,14 +114,15 @@
128114 struct iovec *indirect;
129115 struct vring_used_elem *heads;
130116 /* Protected by virtqueue mutex. */
131
- struct vhost_umem *umem;
132
- struct vhost_umem *iotlb;
117
+ struct vhost_iotlb *umem;
118
+ struct vhost_iotlb *iotlb;
133119 void *private_data;
134120 u64 acked_features;
135121 u64 acked_backend_features;
136122 /* Log write descriptors */
137123 void __user *log_base;
138124 struct vhost_log *log;
125
+ struct iovec log_iov[64];
139126
140127 /* Ring endianness. Defaults to legacy native endianness.
141128 * Set to true when starting a modern virtio device. */
....@@ -164,8 +151,8 @@
164151 struct eventfd_ctx *log_ctx;
165152 struct llist_head work_list;
166153 struct task_struct *worker;
167
- struct vhost_umem *umem;
168
- struct vhost_umem *iotlb;
154
+ struct vhost_iotlb *umem;
155
+ struct vhost_iotlb *iotlb;
169156 spinlock_t iotlb_lock;
170157 struct list_head read_list;
171158 struct list_head pending_list;
....@@ -174,16 +161,22 @@
174161 int weight;
175162 int byte_weight;
176163 u64 kcov_handle;
164
+ bool use_worker;
165
+ int (*msg_handler)(struct vhost_dev *dev,
166
+ struct vhost_iotlb_msg *msg);
177167 };
178168
179169 bool vhost_exceeds_weight(struct vhost_virtqueue *vq, int pkts, int total_len);
180170 void vhost_dev_init(struct vhost_dev *, struct vhost_virtqueue **vqs,
181
- int nvqs, int iov_limit, int weight, int byte_weight);
171
+ int nvqs, int iov_limit, int weight, int byte_weight,
172
+ bool use_worker,
173
+ int (*msg_handler)(struct vhost_dev *dev,
174
+ struct vhost_iotlb_msg *msg));
182175 long vhost_dev_set_owner(struct vhost_dev *dev);
183176 bool vhost_dev_has_owner(struct vhost_dev *dev);
184177 long vhost_dev_check_owner(struct vhost_dev *);
185
-struct vhost_umem *vhost_dev_reset_owner_prepare(void);
186
-void vhost_dev_reset_owner(struct vhost_dev *, struct vhost_umem *);
178
+struct vhost_iotlb *vhost_dev_reset_owner_prepare(void);
179
+void vhost_dev_reset_owner(struct vhost_dev *dev, struct vhost_iotlb *iotlb);
187180 void vhost_dev_cleanup(struct vhost_dev *);
188181 void vhost_dev_stop(struct vhost_dev *);
189182 long vhost_dev_ioctl(struct vhost_dev *, unsigned int ioctl, void __user *argp);
....@@ -197,6 +190,7 @@
197190 struct vhost_log *log, unsigned int *log_num);
198191 void vhost_discard_vq_desc(struct vhost_virtqueue *, int n);
199192
193
+bool vhost_vq_is_setup(struct vhost_virtqueue *vq);
200194 int vhost_vq_init_access(struct vhost_virtqueue *);
201195 int vhost_add_used(struct vhost_virtqueue *, unsigned int head, int len);
202196 int vhost_add_used_n(struct vhost_virtqueue *, struct vring_used_elem *heads,
....@@ -213,7 +207,7 @@
213207 int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log,
214208 unsigned int log_num, u64 len,
215209 struct iovec *iov, int count);
216
-int vq_iotlb_prefetch(struct vhost_virtqueue *vq);
210
+int vq_meta_prefetch(struct vhost_virtqueue *vq);
217211
218212 struct vhost_msg_node *vhost_new_msg(struct vhost_virtqueue *vq, int type);
219213 void vhost_enqueue_msg(struct vhost_dev *dev,
....@@ -221,6 +215,8 @@
221215 struct vhost_msg_node *node);
222216 struct vhost_msg_node *vhost_dequeue_msg(struct vhost_dev *dev,
223217 struct list_head *head);
218
+void vhost_set_backend_features(struct vhost_dev *dev, u64 features);
219
+
224220 __poll_t vhost_chr_poll(struct file *file, struct vhost_dev *dev,
225221 poll_table *wait);
226222 ssize_t vhost_chr_read_iter(struct vhost_dev *dev, struct iov_iter *to,
....@@ -228,6 +224,9 @@
228224 ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
229225 struct iov_iter *from);
230226 int vhost_init_device_iotlb(struct vhost_dev *d, bool enabled);
227
+
228
+void vhost_iotlb_map_free(struct vhost_iotlb *iotlb,
229
+ struct vhost_iotlb_map *map);
231230
232231 #define vq_err(vq, fmt, ...) do { \
233232 pr_debug(pr_fmt(fmt), ##__VA_ARGS__); \
....@@ -244,6 +243,33 @@
244243 (1ULL << VIRTIO_F_VERSION_1)
245244 };
246245
246
+/**
247
+ * vhost_vq_set_backend - Set backend.
248
+ *
249
+ * @vq Virtqueue.
250
+ * @private_data The private data.
251
+ *
252
+ * Context: Need to call with vq->mutex acquired.
253
+ */
254
+static inline void vhost_vq_set_backend(struct vhost_virtqueue *vq,
255
+ void *private_data)
256
+{
257
+ vq->private_data = private_data;
258
+}
259
+
260
+/**
261
+ * vhost_vq_get_backend - Get backend.
262
+ *
263
+ * @vq Virtqueue.
264
+ *
265
+ * Context: Need to call with vq->mutex acquired.
266
+ * Return: Private data previously set with vhost_vq_set_backend.
267
+ */
268
+static inline void *vhost_vq_get_backend(struct vhost_virtqueue *vq)
269
+{
270
+ return vq->private_data;
271
+}
272
+
247273 static inline bool vhost_has_feature(struct vhost_virtqueue *vq, int bit)
248274 {
249275 return vq->acked_features & (1ULL << bit);