blob: d8f534025b7f7bd3cb27d663f78de9b232fa85d3 [file] [log] [blame]
Michael S. Tsirkin4e53f782010-11-29 19:16:37 +02001#ifndef LINUX_VIRTIO_H
2#define LINUX_VIRTIO_H
Rusty Russell61d0b5a2013-03-18 13:22:19 +10303#include <linux/scatterlist.h>
4#include <linux/kernel.h>
Michael S. Tsirkin4e53f782010-11-29 19:16:37 +02005
Michael S. Tsirkin6be3ffa2016-08-15 04:50:55 +03006struct device {
7 void *parent;
8};
9
Michael S. Tsirkin4e53f782010-11-29 19:16:37 +020010struct virtio_device {
Michael S. Tsirkin6be3ffa2016-08-15 04:50:55 +030011 struct device dev;
Michael S. Tsirkind0254772014-10-07 16:39:43 +020012 u64 features;
Michael S. Tsirkin4e53f782010-11-29 19:16:37 +020013};
14
15struct virtqueue {
16 /* TODO: commented as list macros are empty stubs for now.
17 * Broken but enough for virtio_ring.c
18 * struct list_head list; */
19 void (*callback)(struct virtqueue *vq);
20 const char *name;
21 struct virtio_device *vdev;
Michael S. Tsirkin73640c92013-03-18 13:22:18 +103022 unsigned int index;
23 unsigned int num_free;
Michael S. Tsirkin4e53f782010-11-29 19:16:37 +020024 void *priv;
25};
26
Michael S. Tsirkin4e53f782010-11-29 19:16:37 +020027/* Interfaces exported by virtio_ring. */
Rusty Russell13816c72013-03-20 15:37:09 +103028int virtqueue_add_sgs(struct virtqueue *vq,
29 struct scatterlist *sgs[],
30 unsigned int out_sgs,
31 unsigned int in_sgs,
32 void *data,
33 gfp_t gfp);
34
Rusty Russelle538eba2013-03-20 15:44:26 +103035int virtqueue_add_outbuf(struct virtqueue *vq,
36 struct scatterlist sg[], unsigned int num,
37 void *data,
38 gfp_t gfp);
39
40int virtqueue_add_inbuf(struct virtqueue *vq,
41 struct scatterlist sg[], unsigned int num,
42 void *data,
43 gfp_t gfp);
44
Joel Stanleyd1b8c4c2014-02-13 15:03:44 +103045bool virtqueue_kick(struct virtqueue *vq);
Michael S. Tsirkin4e53f782010-11-29 19:16:37 +020046
47void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len);
48
49void virtqueue_disable_cb(struct virtqueue *vq);
50
51bool virtqueue_enable_cb(struct virtqueue *vq);
Michael S. Tsirkin64d09882012-04-16 10:11:12 -040052bool virtqueue_enable_cb_delayed(struct virtqueue *vq);
Michael S. Tsirkin4e53f782010-11-29 19:16:37 +020053
54void *virtqueue_detach_unused_buf(struct virtqueue *vq);
Michael S. Tsirkin73640c92013-03-18 13:22:18 +103055struct virtqueue *vring_new_virtqueue(unsigned int index,
56 unsigned int num,
Michael S. Tsirkin4e53f782010-11-29 19:16:37 +020057 unsigned int vring_align,
58 struct virtio_device *vdev,
Rusty Russell7b21e342012-01-12 15:44:42 +103059 bool weak_barriers,
Sekhar Nori0a12ae42017-04-17 16:42:15 +053060 bool ctx,
Michael S. Tsirkin4e53f782010-11-29 19:16:37 +020061 void *pages,
Joel Stanleyd1b8c4c2014-02-13 15:03:44 +103062 bool (*notify)(struct virtqueue *vq),
Michael S. Tsirkin4e53f782010-11-29 19:16:37 +020063 void (*callback)(struct virtqueue *vq),
64 const char *name);
65void vring_del_virtqueue(struct virtqueue *vq);
66
67#endif