···11-#ifndef _LINUX_VIRTIO_CONFIG_H
22-#define _LINUX_VIRTIO_CONFIG_H
33-/* This header, excluding the #ifdef __KERNEL__ part, is BSD licensed so
44- * anyone can use the definitions to implement compatible drivers/servers.
55- *
66- * Redistribution and use in source and binary forms, with or without
77- * modification, are permitted provided that the following conditions
88- * are met:
99- * 1. Redistributions of source code must retain the above copyright
1010- * notice, this list of conditions and the following disclaimer.
1111- * 2. Redistributions in binary form must reproduce the above copyright
1212- * notice, this list of conditions and the following disclaimer in the
1313- * documentation and/or other materials provided with the distribution.
1414- * 3. Neither the name of IBM nor the names of its contributors
1515- * may be used to endorse or promote products derived from this software
1616- * without specific prior written permission.
1717- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
1818- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1919- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2020- * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
2121- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2222- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2323- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2424- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2525- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2626- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727- * SUCH DAMAGE. */
2828-2929-/* Virtio devices use a standardized configuration space to define their
3030- * features and pass configuration information, but each implementation can
3131- * store and access that space differently. */
3232-#include <linux/types.h>
3333-3434-/* Status byte for guest to report progress, and synchronize features. */
3535-/* We have seen device and processed generic fields (VIRTIO_CONFIG_F_VIRTIO) */
3636-#define VIRTIO_CONFIG_S_ACKNOWLEDGE 1
3737-/* We have found a driver for the device. */
3838-#define VIRTIO_CONFIG_S_DRIVER 2
3939-/* Driver has used its parts of the config, and is happy */
4040-#define VIRTIO_CONFIG_S_DRIVER_OK 4
4141-/* We've given up on this device. */
4242-#define VIRTIO_CONFIG_S_FAILED 0x80
4343-4444-/* Some virtio feature bits (currently bits 28 through 31) are reserved for the
4545- * transport being used (eg. virtio_ring), the rest are per-device feature
4646- * bits. */
4747-#define VIRTIO_TRANSPORT_F_START 28
4848-#define VIRTIO_TRANSPORT_F_END 32
4949-5050-/* Do we get callbacks when the ring is completely used, even if we've
5151- * suppressed them? */
5252-#define VIRTIO_F_NOTIFY_ON_EMPTY 24
5353-5454-/* Can the device handle any descriptor layout? */
5555-#define VIRTIO_F_ANY_LAYOUT 27
5656-5757-#endif /* _LINUX_VIRTIO_CONFIG_H */
11+#include "standard-headers/linux/virtio_config.h"
+1-163
linux-headers/linux/virtio_ring.h
···11-#ifndef _LINUX_VIRTIO_RING_H
22-#define _LINUX_VIRTIO_RING_H
33-/* An interface for efficient virtio implementation, currently for use by KVM
44- * and lguest, but hopefully others soon. Do NOT change this since it will
55- * break existing servers and clients.
66- *
77- * This header is BSD licensed so anyone can use the definitions to implement
88- * compatible drivers/servers.
99- *
1010- * Redistribution and use in source and binary forms, with or without
1111- * modification, are permitted provided that the following conditions
1212- * are met:
1313- * 1. Redistributions of source code must retain the above copyright
1414- * notice, this list of conditions and the following disclaimer.
1515- * 2. Redistributions in binary form must reproduce the above copyright
1616- * notice, this list of conditions and the following disclaimer in the
1717- * documentation and/or other materials provided with the distribution.
1818- * 3. Neither the name of IBM nor the names of its contributors
1919- * may be used to endorse or promote products derived from this software
2020- * without specific prior written permission.
2121- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
2222- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2323- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2424- * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
2525- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2626- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2727- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2828- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2929- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3030- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3131- * SUCH DAMAGE.
3232- *
3333- * Copyright Rusty Russell IBM Corporation 2007. */
3434-#include <linux/types.h>
3535-3636-/* This marks a buffer as continuing via the next field. */
3737-#define VRING_DESC_F_NEXT 1
3838-/* This marks a buffer as write-only (otherwise read-only). */
3939-#define VRING_DESC_F_WRITE 2
4040-/* This means the buffer contains a list of buffer descriptors. */
4141-#define VRING_DESC_F_INDIRECT 4
4242-4343-/* The Host uses this in used->flags to advise the Guest: don't kick me when
4444- * you add a buffer. It's unreliable, so it's simply an optimization. Guest
4545- * will still kick if it's out of buffers. */
4646-#define VRING_USED_F_NO_NOTIFY 1
4747-/* The Guest uses this in avail->flags to advise the Host: don't interrupt me
4848- * when you consume a buffer. It's unreliable, so it's simply an
4949- * optimization. */
5050-#define VRING_AVAIL_F_NO_INTERRUPT 1
5151-5252-/* We support indirect buffer descriptors */
5353-#define VIRTIO_RING_F_INDIRECT_DESC 28
5454-5555-/* The Guest publishes the used index for which it expects an interrupt
5656- * at the end of the avail ring. Host should ignore the avail->flags field. */
5757-/* The Host publishes the avail index for which it expects a kick
5858- * at the end of the used ring. Guest should ignore the used->flags field. */
5959-#define VIRTIO_RING_F_EVENT_IDX 29
6060-6161-/* Virtio ring descriptors: 16 bytes. These can chain together via "next". */
6262-struct vring_desc {
6363- /* Address (guest-physical). */
6464- __u64 addr;
6565- /* Length. */
6666- __u32 len;
6767- /* The flags as indicated above. */
6868- __u16 flags;
6969- /* We chain unused descriptors via this, too */
7070- __u16 next;
7171-};
7272-7373-struct vring_avail {
7474- __u16 flags;
7575- __u16 idx;
7676- __u16 ring[];
7777-};
7878-7979-/* u32 is used here for ids for padding reasons. */
8080-struct vring_used_elem {
8181- /* Index of start of used descriptor chain. */
8282- __u32 id;
8383- /* Total length of the descriptor chain which was used (written to) */
8484- __u32 len;
8585-};
8686-8787-struct vring_used {
8888- __u16 flags;
8989- __u16 idx;
9090- struct vring_used_elem ring[];
9191-};
9292-9393-struct vring {
9494- unsigned int num;
9595-9696- struct vring_desc *desc;
9797-9898- struct vring_avail *avail;
9999-100100- struct vring_used *used;
101101-};
102102-103103-/* The standard layout for the ring is a continuous chunk of memory which looks
104104- * like this. We assume num is a power of 2.
105105- *
106106- * struct vring
107107- * {
108108- * // The actual descriptors (16 bytes each)
109109- * struct vring_desc desc[num];
110110- *
111111- * // A ring of available descriptor heads with free-running index.
112112- * __u16 avail_flags;
113113- * __u16 avail_idx;
114114- * __u16 available[num];
115115- * __u16 used_event_idx;
116116- *
117117- * // Padding to the next align boundary.
118118- * char pad[];
119119- *
120120- * // A ring of used descriptor heads with free-running index.
121121- * __u16 used_flags;
122122- * __u16 used_idx;
123123- * struct vring_used_elem used[num];
124124- * __u16 avail_event_idx;
125125- * };
126126- */
127127-/* We publish the used event index at the end of the available ring, and vice
128128- * versa. They are at the end for backwards compatibility. */
129129-#define vring_used_event(vr) ((vr)->avail->ring[(vr)->num])
130130-#define vring_avail_event(vr) (*(__u16 *)&(vr)->used->ring[(vr)->num])
131131-132132-static __inline__ void vring_init(struct vring *vr, unsigned int num, void *p,
133133- unsigned long align)
134134-{
135135- vr->num = num;
136136- vr->desc = p;
137137- vr->avail = p + num*sizeof(struct vring_desc);
138138- vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + sizeof(__u16)
139139- + align-1) & ~(align - 1));
140140-}
141141-142142-static __inline__ unsigned vring_size(unsigned int num, unsigned long align)
143143-{
144144- return ((sizeof(struct vring_desc) * num + sizeof(__u16) * (3 + num)
145145- + align - 1) & ~(align - 1))
146146- + sizeof(__u16) * 3 + sizeof(struct vring_used_elem) * num;
147147-}
148148-149149-/* The following is used with USED_EVENT_IDX and AVAIL_EVENT_IDX */
150150-/* Assuming a given event_idx value from the other size, if
151151- * we have just incremented index from old to new_idx,
152152- * should we trigger an event? */
153153-static __inline__ int vring_need_event(__u16 event_idx, __u16 new_idx, __u16 old)
154154-{
155155- /* Note: Xen has similar logic for notification hold-off
156156- * in include/xen/interface/io/ring.h with req_event and req_prod
157157- * corresponding to event_idx + 1 and new_idx respectively.
158158- * Note also that req_event and req_prod in Xen start at 1,
159159- * event indexes in virtio start at 0. */
160160- return (__u16)(new_idx - event_idx - 1) < (__u16)(new_idx - old);
161161-}
162162-163163-#endif /* _LINUX_VIRTIO_RING_H */
11+#include "standard-headers/linux/virtio_ring.h"