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