blob: cd801838156f742e07e19a918fb14de21a8f76c7 [file] [log] [blame]
Michael S. Tsirkin4e53f782010-11-29 19:16:37 +02001#ifndef LINUX_VIRTIO_H
2#define LINUX_VIRTIO_H
Rusty Russell61d0b5a42013-03-18 13:22:19 +10303#include <linux/scatterlist.h>
4#include <linux/kernel.h>
Michael S. Tsirkin4e53f782010-11-29 19:16:37 +02005
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))
Rusty Russell61d0b5a42013-03-18 13:22:19 +103014
Michael S. Tsirkin4e53f782010-11-29 19:16:37 +020015/* 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}
Michael S. Tsirkin4e53f782010-11-29 19:16:37 +020029/* 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;
Michael S. Tsirkin73640c92013-03-18 13:22:18 +103043 unsigned int index;
44 unsigned int num_free;
Michael S. Tsirkin4e53f782010-11-29 19:16:37 +020045 void *priv;
46};
47
Michael S. Tsirkin4e53f782010-11-29 19:16:37 +020048#define MODULE_LICENSE(__MODULE_LICENSE_value) \
49 const char *__MODULE_LICENSE_name = __MODULE_LICENSE_value
50
Michael S. Tsirkin4e53f782010-11-29 19:16:37 +020051/* Interfaces exported by virtio_ring. */
Rusty Russell13816c72013-03-20 15:37:09 +103052int virtqueue_add_sgs(struct virtqueue *vq,
53 struct scatterlist *sgs[],
54 unsigned int out_sgs,
55 unsigned int in_sgs,
56 void *data,
57 gfp_t gfp);
58
Rusty Russelle538eba2013-03-20 15:44:26 +103059int virtqueue_add_outbuf(struct virtqueue *vq,
60 struct scatterlist sg[], unsigned int num,
61 void *data,
62 gfp_t gfp);
63
64int virtqueue_add_inbuf(struct virtqueue *vq,
65 struct scatterlist sg[], unsigned int num,
66 void *data,
67 gfp_t gfp);
68
Michael S. Tsirkin4e53f782010-11-29 19:16:37 +020069void virtqueue_kick(struct virtqueue *vq);
70
71void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len);
72
73void virtqueue_disable_cb(struct virtqueue *vq);
74
75bool virtqueue_enable_cb(struct virtqueue *vq);
Michael S. Tsirkin64d09882012-04-16 10:11:12 -040076bool virtqueue_enable_cb_delayed(struct virtqueue *vq);
Michael S. Tsirkin4e53f782010-11-29 19:16:37 +020077
78void *virtqueue_detach_unused_buf(struct virtqueue *vq);
Michael S. Tsirkin73640c92013-03-18 13:22:18 +103079struct virtqueue *vring_new_virtqueue(unsigned int index,
80 unsigned int num,
Michael S. Tsirkin4e53f782010-11-29 19:16:37 +020081 unsigned int vring_align,
82 struct virtio_device *vdev,
Rusty Russell7b21e342012-01-12 15:44:42 +103083 bool weak_barriers,
Michael S. Tsirkin4e53f782010-11-29 19:16:37 +020084 void *pages,
85 void (*notify)(struct virtqueue *vq),
86 void (*callback)(struct virtqueue *vq),
87 const char *name);
88void vring_del_virtqueue(struct virtqueue *vq);
89
90#endif