1 #ifndef _LINUX_VIRTIO_RING_H
2 #define _LINUX_VIRTIO_RING_H
3 /* An interface for efficient virtio implementation, currently for use by KVM
4 * and lguest, but hopefully others soon. Do NOT change this since it will
5 * break existing servers and clients.
7 * This header is BSD licensed so anyone can use the definitions to implement
8 * compatible drivers/servers.
10 * Copyright Rusty Russell IBM Corporation 2007. */
11 #include <linux/types.h>
13 /* This marks a buffer as continuing via the next field. */
14 #define VRING_DESC_F_NEXT 1
15 /* This marks a buffer as write-only (otherwise read-only). */
16 #define VRING_DESC_F_WRITE 2
17 /* This means the buffer contains a list of buffer descriptors. */
18 #define VRING_DESC_F_INDIRECT 4
20 /* The Host uses this in used->flags to advise the Guest: don't kick me when
21 * you add a buffer. It's unreliable, so it's simply an optimization. Guest
22 * will still kick if it's out of buffers. */
23 #define VRING_USED_F_NO_NOTIFY 1
24 /* The Guest uses this in avail->flags to advise the Host: don't interrupt me
25 * when you consume a buffer. It's unreliable, so it's simply an
27 #define VRING_AVAIL_F_NO_INTERRUPT 1
29 /* We support indirect buffer descriptors */
30 #define VIRTIO_RING_F_INDIRECT_DESC 28
32 /* Virtio ring descriptors: 16 bytes. These can chain together via "next". */
35 /* Address (guest-physical). */
39 /* The flags as indicated above. */
41 /* We chain unused descriptors via this, too */
52 /* u32 is used here for ids for padding reasons. */
53 struct vring_used_elem
55 /* Index of start of used descriptor chain. */
57 /* Total length of the descriptor chain which was used (written to) */
65 struct vring_used_elem ring
[];
71 struct vring_desc
*desc
;
73 struct vring_avail
*avail
;
75 struct vring_used
*used
;
78 /* The standard layout for the ring is a continuous chunk of memory which looks
79 * like this. We assume num is a power of 2.
83 * // The actual descriptors (16 bytes each)
84 * struct vring_desc desc[num];
86 * // A ring of available descriptor heads with free-running index.
89 * __u16 available[num];
91 * // Padding to the next align boundary.
94 * // A ring of used descriptor heads with free-running index.
97 * struct vring_used_elem used[num];
100 static inline void vring_init(struct vring
*vr
, unsigned int num
, void *p
,
105 vr
->avail
= p
+ num
*sizeof(struct vring_desc
);
106 vr
->used
= (void *)(((unsigned long)&vr
->avail
->ring
[num
] + align
-1)
110 static inline unsigned vring_size(unsigned int num
, unsigned long align
)
112 return ((sizeof(struct vring_desc
) * num
+ sizeof(__u16
) * (2 + num
)
113 + align
- 1) & ~(align
- 1))
114 + sizeof(__u16
) * 2 + sizeof(struct vring_used_elem
) * num
;
118 #include <linux/irqreturn.h>
119 struct virtio_device
;
122 struct virtqueue
*vring_new_virtqueue(unsigned int num
,
123 unsigned int vring_align
,
124 struct virtio_device
*vdev
,
126 void (*notify
)(struct virtqueue
*vq
),
127 void (*callback
)(struct virtqueue
*vq
),
129 void vring_del_virtqueue(struct virtqueue
*vq
);
130 /* Filter out transport-specific feature bits. */
131 void vring_transport_features(struct virtio_device
*vdev
);
133 irqreturn_t
vring_interrupt(int irq
, void *_vq
);
134 #endif /* __KERNEL__ */
135 #endif /* _LINUX_VIRTIO_RING_H */