]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - tools/virtio/linux/virtio.h
virtio_ring: virtqueue_add_outbuf / virtqueue_add_inbuf.
[mirror_ubuntu-hirsute-kernel.git] / tools / virtio / linux / virtio.h
CommitLineData
4e53f78e
MT
1#ifndef LINUX_VIRTIO_H
2#define LINUX_VIRTIO_H
61d0b5a4
RR
3#include <linux/scatterlist.h>
4#include <linux/kernel.h>
4e53f78e
MT
5
6/* TODO: empty stubs for now. Broken but enough for virtio_ring.c */
7#define list_add_tail(a, b) do {} while (0)
8#define list_del(a) do {} while (0)
9
10#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
11#define BITS_PER_BYTE 8
12#define BITS_PER_LONG (sizeof(long) * BITS_PER_BYTE)
13#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
61d0b5a4 14
4e53f78e
MT
15/* TODO: Not atomic as it should be:
16 * we don't use this for anything important. */
17static inline void clear_bit(int nr, volatile unsigned long *addr)
18{
19 unsigned long mask = BIT_MASK(nr);
20 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
21
22 *p &= ~mask;
23}
24
25static inline int test_bit(int nr, const volatile unsigned long *addr)
26{
27 return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
28}
4e53f78e
MT
29/* end of stubs */
30
31struct virtio_device {
32 void *dev;
33 unsigned long features[1];
34};
35
36struct virtqueue {
37 /* TODO: commented as list macros are empty stubs for now.
38 * Broken but enough for virtio_ring.c
39 * struct list_head list; */
40 void (*callback)(struct virtqueue *vq);
41 const char *name;
42 struct virtio_device *vdev;
73640c99
MT
43 unsigned int index;
44 unsigned int num_free;
4e53f78e
MT
45 void *priv;
46};
47
4e53f78e
MT
48#define MODULE_LICENSE(__MODULE_LICENSE_value) \
49 const char *__MODULE_LICENSE_name = __MODULE_LICENSE_value
50
4e53f78e 51/* Interfaces exported by virtio_ring. */
f96fde41
RR
52int virtqueue_add_buf(struct virtqueue *vq,
53 struct scatterlist sg[],
54 unsigned int out_num,
55 unsigned int in_num,
56 void *data,
57 gfp_t gfp);
4e53f78e 58
13816c76
RR
59int virtqueue_add_sgs(struct virtqueue *vq,
60 struct scatterlist *sgs[],
61 unsigned int out_sgs,
62 unsigned int in_sgs,
63 void *data,
64 gfp_t gfp);
65
4e53f78e
MT
66void virtqueue_kick(struct virtqueue *vq);
67
68void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len);
69
70void virtqueue_disable_cb(struct virtqueue *vq);
71
72bool virtqueue_enable_cb(struct virtqueue *vq);
64d09888 73bool virtqueue_enable_cb_delayed(struct virtqueue *vq);
4e53f78e
MT
74
75void *virtqueue_detach_unused_buf(struct virtqueue *vq);
73640c99
MT
76struct virtqueue *vring_new_virtqueue(unsigned int index,
77 unsigned int num,
4e53f78e
MT
78 unsigned int vring_align,
79 struct virtio_device *vdev,
7b21e34f 80 bool weak_barriers,
4e53f78e
MT
81 void *pages,
82 void (*notify)(struct virtqueue *vq),
83 void (*callback)(struct virtqueue *vq),
84 const char *name);
85void vring_del_virtqueue(struct virtqueue *vq);
86
87#endif