Files
linux-apfs/drivers/vhost/vhost.h
T

180 lines
5.3 KiB
C
Raw Normal View History

2010-01-14 06:17:27 +00:00
#ifndef _VHOST_H
#define _VHOST_H
#include <linux/eventfd.h>
#include <linux/vhost.h>
#include <linux/mm.h>
#include <linux/mutex.h>
#include <linux/poll.h>
#include <linux/file.h>
#include <linux/uio.h>
#include <linux/virtio_config.h>
#include <linux/virtio_ring.h>
2011-07-26 16:09:06 -07:00
#include <linux/atomic.h>
2010-01-14 06:17:27 +00:00
struct vhost_device;
struct vhost_work;
typedef void (*vhost_work_fn_t)(struct vhost_work *work);
struct vhost_work {
struct list_head node;
vhost_work_fn_t fn;
wait_queue_head_t done;
int flushing;
unsigned queue_seq;
unsigned done_seq;
};
2010-01-14 06:17:27 +00:00
/* Poll a file (eventfd or socket) */
/* Note: there's nothing vhost specific about this structure. */
struct vhost_poll {
poll_table table;
wait_queue_head_t *wqh;
wait_queue_t wait;
struct vhost_work work;
2010-01-14 06:17:27 +00:00
unsigned long mask;
struct vhost_dev *dev;
2010-01-14 06:17:27 +00:00
};
2012-07-21 06:55:37 +00:00
void vhost_work_init(struct vhost_work *work, vhost_work_fn_t fn);
void vhost_work_queue(struct vhost_dev *dev, struct vhost_work *work);
void vhost_poll_init(struct vhost_poll *poll, vhost_work_fn_t fn,
unsigned long mask, struct vhost_dev *dev);
int vhost_poll_start(struct vhost_poll *poll, struct file *file);
2010-01-14 06:17:27 +00:00
void vhost_poll_stop(struct vhost_poll *poll);
void vhost_poll_flush(struct vhost_poll *poll);
void vhost_poll_queue(struct vhost_poll *poll);
2013-05-06 16:38:21 +08:00
void vhost_work_flush(struct vhost_dev *dev, struct vhost_work *work);
long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, void __user *argp);
2010-01-14 06:17:27 +00:00
struct vhost_log {
u64 addr;
u64 len;
};
2011-07-18 03:48:46 +00:00
struct vhost_virtqueue;
2010-01-14 06:17:27 +00:00
/* The virtqueue structure describes a queue attached to a device. */
struct vhost_virtqueue {
struct vhost_dev *dev;
/* The actual ring of buffers. */
struct mutex mutex;
unsigned int num;
struct vring_desc __user *desc;
struct vring_avail __user *avail;
struct vring_used __user *used;
struct file *kick;
struct file *call;
struct file *error;
struct eventfd_ctx *call_ctx;
struct eventfd_ctx *error_ctx;
struct eventfd_ctx *log_ctx;
struct vhost_poll poll;
/* The routine to call when the Guest pings us, or timeout. */
vhost_work_fn_t handle_kick;
2010-01-14 06:17:27 +00:00
/* Last available index we saw. */
u16 last_avail_idx;
/* Caches available index value from user. */
u16 avail_idx;
/* Last index we used. */
u16 last_used_idx;
/* Used flags */
u16 used_flags;
2011-05-20 02:10:54 +03:00
/* Last used index value we have signalled on */
u16 signalled_used;
/* Last used index value we have signalled on */
bool signalled_used_valid;
2010-01-14 06:17:27 +00:00
/* Log writes to used structure. */
bool log_used;
u64 log_addr;
2010-09-14 23:53:05 +08:00
struct iovec iov[UIO_MAXIOV];
struct iovec *indirect;
struct vring_used_elem *heads;
2013-05-07 14:54:36 +08:00
/* Protected by virtqueue mutex. */
2014-06-05 15:20:27 +03:00
struct vhost_memory *memory;
2013-05-07 14:54:36 +08:00
void *private_data;
2014-06-05 15:20:23 +03:00
unsigned acked_features;
2010-01-14 06:17:27 +00:00
/* Log write descriptors */
void __user *log_base;
2010-09-14 23:53:05 +08:00
struct vhost_log *log;
2010-01-14 06:17:27 +00:00
};
struct vhost_dev {
2014-06-05 15:20:27 +03:00
struct vhost_memory *memory;
2010-01-14 06:17:27 +00:00
struct mm_struct *mm;
struct mutex mutex;
2013-04-27 11:16:48 +08:00
struct vhost_virtqueue **vqs;
2010-01-14 06:17:27 +00:00
int nvqs;
struct file *log_file;
struct eventfd_ctx *log_ctx;
spinlock_t work_lock;
struct list_head work_list;
struct task_struct *worker;
2010-01-14 06:17:27 +00:00
};
2013-12-07 04:13:03 +08:00
void vhost_dev_init(struct vhost_dev *, struct vhost_virtqueue **vqs, int nvqs);
2013-05-06 11:15:59 +08:00
long vhost_dev_set_owner(struct vhost_dev *dev);
bool vhost_dev_has_owner(struct vhost_dev *dev);
2010-01-14 06:17:27 +00:00
long vhost_dev_check_owner(struct vhost_dev *);
struct vhost_memory *vhost_dev_reset_owner_prepare(void);
void vhost_dev_reset_owner(struct vhost_dev *, struct vhost_memory *);
2011-11-27 19:05:58 +02:00
void vhost_dev_cleanup(struct vhost_dev *, bool locked);
2012-11-01 09:16:46 +00:00
void vhost_dev_stop(struct vhost_dev *);
2012-12-06 14:03:34 +02:00
long vhost_dev_ioctl(struct vhost_dev *, unsigned int ioctl, void __user *argp);
long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, void __user *argp);
2010-01-14 06:17:27 +00:00
int vhost_vq_access_ok(struct vhost_virtqueue *vq);
int vhost_log_access_ok(struct vhost_dev *);
2014-06-05 15:20:27 +03:00
int vhost_get_vq_desc(struct vhost_virtqueue *,
2010-06-24 16:59:59 +03:00
struct iovec iov[], unsigned int iov_count,
unsigned int *out_num, unsigned int *in_num,
struct vhost_log *log, unsigned int *log_num);
2010-07-27 18:52:21 +03:00
void vhost_discard_vq_desc(struct vhost_virtqueue *, int n);
2010-01-14 06:17:27 +00:00
2011-06-21 18:04:27 +08:00
int vhost_init_used(struct vhost_virtqueue *);
2010-01-14 06:17:27 +00:00
int vhost_add_used(struct vhost_virtqueue *, unsigned int head, int len);
2010-07-27 18:52:21 +03:00
int vhost_add_used_n(struct vhost_virtqueue *, struct vring_used_elem *heads,
unsigned count);
2010-01-14 06:17:27 +00:00
void vhost_add_used_and_signal(struct vhost_dev *, struct vhost_virtqueue *,
2010-07-27 18:52:21 +03:00
unsigned int id, int len);
void vhost_add_used_and_signal_n(struct vhost_dev *, struct vhost_virtqueue *,
struct vring_used_elem *heads, unsigned count);
void vhost_signal(struct vhost_dev *, struct vhost_virtqueue *);
2011-05-20 02:10:54 +03:00
void vhost_disable_notify(struct vhost_dev *, struct vhost_virtqueue *);
bool vhost_enable_notify(struct vhost_dev *, struct vhost_virtqueue *);
2010-01-14 06:17:27 +00:00
int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log,
unsigned int log_num, u64 len);
#define vq_err(vq, fmt, ...) do { \
pr_debug(pr_fmt(fmt), ##__VA_ARGS__); \
if ((vq)->error_ctx) \
eventfd_signal((vq)->error_ctx, 1);\
} while (0)
enum {
2011-05-20 02:10:54 +03:00
VHOST_FEATURES = (1ULL << VIRTIO_F_NOTIFY_ON_EMPTY) |
(1ULL << VIRTIO_RING_F_INDIRECT_DESC) |
(1ULL << VIRTIO_RING_F_EVENT_IDX) |
(1ULL << VHOST_F_LOG_ALL),
2010-01-14 06:17:27 +00:00
};
2014-06-05 15:20:23 +03:00
static inline int vhost_has_feature(struct vhost_virtqueue *vq, int bit)
2010-01-14 06:17:27 +00:00
{
2014-06-05 15:20:23 +03:00
return vq->acked_features & (1 << bit);
2010-01-14 06:17:27 +00:00
}
#endif