Deleted Added
full compact
virtio_ring.h (228301) virtio_ring.h (234270)
1/*-
2 * Copyright Rusty Russell IBM Corporation 2007.
3 *
4 * This header is BSD licensed so anyone can use the definitions to implement
5 * compatible drivers/servers.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 13 unchanged lines hidden (view full) ---

22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
1/*-
2 * Copyright Rusty Russell IBM Corporation 2007.
3 *
4 * This header is BSD licensed so anyone can use the definitions to implement
5 * compatible drivers/servers.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 13 unchanged lines hidden (view full) ---

22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * $FreeBSD: head/sys/dev/virtio/virtio_ring.h 228301 2011-12-06 06:28:32Z grehan $
30 * $FreeBSD: head/sys/dev/virtio/virtio_ring.h 234270 2012-04-14 05:48:04Z grehan $
31 */
32
33#ifndef VIRTIO_RING_H
34#define VIRTIO_RING_H
35
36#include <sys/types.h>
37
38/* This marks a buffer as continuing via the next field. */

--- 59 unchanged lines hidden (view full) ---

98 * struct vring {
99 * // The actual descriptors (16 bytes each)
100 * struct vring_desc desc[num];
101 *
102 * // A ring of available descriptor heads with free-running index.
103 * __u16 avail_flags;
104 * __u16 avail_idx;
105 * __u16 available[num];
31 */
32
33#ifndef VIRTIO_RING_H
34#define VIRTIO_RING_H
35
36#include <sys/types.h>
37
38/* This marks a buffer as continuing via the next field. */

--- 59 unchanged lines hidden (view full) ---

98 * struct vring {
99 * // The actual descriptors (16 bytes each)
100 * struct vring_desc desc[num];
101 *
102 * // A ring of available descriptor heads with free-running index.
103 * __u16 avail_flags;
104 * __u16 avail_idx;
105 * __u16 available[num];
106 * __u16 used_event_idx;
106 *
107 * // Padding to the next align boundary.
108 * char pad[];
109 *
110 * // A ring of used descriptor heads with free-running index.
111 * __u16 used_flags;
112 * __u16 used_idx;
113 * struct vring_used_elem used[num];
107 *
108 * // Padding to the next align boundary.
109 * char pad[];
110 *
111 * // A ring of used descriptor heads with free-running index.
112 * __u16 used_flags;
113 * __u16 used_idx;
114 * struct vring_used_elem used[num];
115 * __u16 avail_event_idx;
114 * };
115 *
116 * NOTE: for VirtIO PCI, align is 4096.
117 */
118
116 * };
117 *
118 * NOTE: for VirtIO PCI, align is 4096.
119 */
120
121/*
122 * We publish the used event index at the end of the available ring, and vice
123 * versa. They are at the end for backwards compatibility.
124 */
125#define vring_used_event(vr) ((vr)->avail->ring[(vr)->num])
126#define vring_avail_event(vr) (*(uint16_t *)&(vr)->used->ring[(vr)->num])
127
119static inline int
120vring_size(unsigned int num, unsigned long align)
121{
122 int size;
123
124 size = num * sizeof(struct vring_desc);
125 size += sizeof(struct vring_avail) + (num * sizeof(uint16_t));
126 size = (size + align - 1) & ~(align - 1);

--- 8 unchanged lines hidden (view full) ---

135{
136 vr->num = num;
137 vr->desc = (struct vring_desc *) p;
138 vr->avail = (struct vring_avail *) (p +
139 num * sizeof(struct vring_desc));
140 vr->used = (void *)
141 (((unsigned long) &vr->avail->ring[num] + align-1) & ~(align-1));
142}
128static inline int
129vring_size(unsigned int num, unsigned long align)
130{
131 int size;
132
133 size = num * sizeof(struct vring_desc);
134 size += sizeof(struct vring_avail) + (num * sizeof(uint16_t));
135 size = (size + align - 1) & ~(align - 1);

--- 8 unchanged lines hidden (view full) ---

144{
145 vr->num = num;
146 vr->desc = (struct vring_desc *) p;
147 vr->avail = (struct vring_avail *) (p +
148 num * sizeof(struct vring_desc));
149 vr->used = (void *)
150 (((unsigned long) &vr->avail->ring[num] + align-1) & ~(align-1));
151}
152
153/*
154 * The following is used with VIRTIO_RING_F_EVENT_IDX.
155 *
156 * Assuming a given event_idx value from the other size, if we have
157 * just incremented index from old to new_idx, should we trigger an
158 * event?
159 */
160static inline int
161vring_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old)
162{
163
164 return (uint16_t)(new_idx - event_idx - 1) < (uint16_t)(new_idx - old);
165}
143#endif /* VIRTIO_RING_H */
166#endif /* VIRTIO_RING_H */