^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef LINUX_VIRTIO_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define LINUX_VIRTIO_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/scatterlist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) struct device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) void *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) struct virtio_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) struct device dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) u64 features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) struct list_head vqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) spinlock_t vqs_list_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct virtqueue {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) void (*callback)(struct virtqueue *vq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct virtio_device *vdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) unsigned int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) unsigned int num_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) void *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /* Interfaces exported by virtio_ring. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) int virtqueue_add_sgs(struct virtqueue *vq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct scatterlist *sgs[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) unsigned int out_sgs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) unsigned int in_sgs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) int virtqueue_add_outbuf(struct virtqueue *vq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct scatterlist sg[], unsigned int num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) int virtqueue_add_inbuf(struct virtqueue *vq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct scatterlist sg[], unsigned int num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) bool virtqueue_kick(struct virtqueue *vq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) void virtqueue_disable_cb(struct virtqueue *vq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) bool virtqueue_enable_cb(struct virtqueue *vq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) bool virtqueue_enable_cb_delayed(struct virtqueue *vq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) void *virtqueue_detach_unused_buf(struct virtqueue *vq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct virtqueue *vring_new_virtqueue(unsigned int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) unsigned int num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) unsigned int vring_align,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct virtio_device *vdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) bool weak_barriers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) bool ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) void *pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) bool (*notify)(struct virtqueue *vq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) void (*callback)(struct virtqueue *vq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) const char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) void vring_del_virtqueue(struct virtqueue *vq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #endif