Merge branch 'for-linus' of git://opensource.wolfsonmicro.com/regmap
[pandora-kernel.git] / drivers / vhost / vhost.h
index 8e03379..a801e28 100644 (file)
 #include <linux/uio.h>
 #include <linux/virtio_config.h>
 #include <linux/virtio_ring.h>
-#include <asm/atomic.h>
+#include <linux/atomic.h>
+
+/* This is for zerocopy, used buffer len is set to 1 when lower device DMA
+ * done */
+#define VHOST_DMA_DONE_LEN     1
+#define VHOST_DMA_CLEAR_LEN    0
 
 struct vhost_device;
 
@@ -50,6 +55,18 @@ struct vhost_log {
        u64 len;
 };
 
+struct vhost_virtqueue;
+
+struct vhost_ubuf_ref {
+       struct kref kref;
+       wait_queue_head_t wait;
+       struct vhost_virtqueue *vq;
+};
+
+struct vhost_ubuf_ref *vhost_ubuf_alloc(struct vhost_virtqueue *, bool zcopy);
+void vhost_ubuf_put(struct vhost_ubuf_ref *);
+void vhost_ubuf_put_and_wait(struct vhost_ubuf_ref *);
+
 /* The virtqueue structure describes a queue attached to a device. */
 struct vhost_virtqueue {
        struct vhost_dev *dev;
@@ -114,6 +131,16 @@ struct vhost_virtqueue {
        /* Log write descriptors */
        void __user *log_base;
        struct vhost_log *log;
+       /* vhost zerocopy support fields below: */
+       /* last used idx for outstanding DMA zerocopy buffers */
+       int upend_idx;
+       /* first used idx for DMA done zerocopy buffers */
+       int done_idx;
+       /* an array of userspace buffers info */
+       struct ubuf_info *ubuf_info;
+       /* Reference counting for outstanding ubufs.
+        * Protected by vq mutex. Writers must also take device mutex. */
+       struct vhost_ubuf_ref *ubufs;
 };
 
 struct vhost_dev {
@@ -147,6 +174,7 @@ int vhost_get_vq_desc(struct vhost_dev *, struct vhost_virtqueue *,
                      struct vhost_log *log, unsigned int *log_num);
 void vhost_discard_vq_desc(struct vhost_virtqueue *, int n);
 
+int vhost_init_used(struct vhost_virtqueue *);
 int vhost_add_used(struct vhost_virtqueue *, unsigned int head, int len);
 int vhost_add_used_n(struct vhost_virtqueue *, struct vring_used_elem *heads,
                     unsigned count);
@@ -160,6 +188,8 @@ bool vhost_enable_notify(struct vhost_dev *, struct vhost_virtqueue *);
 
 int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log,
                    unsigned int log_num, u64 len);
+void vhost_zerocopy_callback(void *arg);
+int vhost_zerocopy_signal_used(struct vhost_virtqueue *vq);
 
 #define vq_err(vq, fmt, ...) do {                                  \
                pr_debug(pr_fmt(fmt), ##__VA_ARGS__);       \
@@ -186,4 +216,6 @@ static inline int vhost_has_feature(struct vhost_dev *dev, int bit)
        return acked_features & (1 << bit);
 }
 
+void vhost_enable_zcopy(int vq);
+
 #endif