1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#ifndef VRING_ACCESSORS_H
#define VRING_ACCESSORS_H
#include "standard-headers/linux/virtio_ring.h"
#include "hw/virtio/virtio.h"
#include "hw/virtio/virtio-access.h"
static inline uint16_t vring_get_used_idx(VirtIODevice *vdev, Vring *vring)
{
return virtio_tswap16(vdev, vring->vr.used->idx);
}
static inline void vring_set_used_idx(VirtIODevice *vdev, Vring *vring,
uint16_t idx)
{
vring->vr.used->idx = virtio_tswap16(vdev, idx);
}
static inline uint16_t vring_get_avail_idx(VirtIODevice *vdev, Vring *vring)
{
return virtio_tswap16(vdev, vring->vr.avail->idx);
}
static inline uint16_t vring_get_avail_ring(VirtIODevice *vdev, Vring *vring,
int i)
{
return virtio_tswap16(vdev, vring->vr.avail->ring[i]);
}
static inline void vring_set_used_ring_id(VirtIODevice *vdev, Vring *vring,
int i, uint32_t id)
{
vring->vr.used->ring[i].id = virtio_tswap32(vdev, id);
}
static inline void vring_set_used_ring_len(VirtIODevice *vdev, Vring *vring,
int i, uint32_t len)
{
vring->vr.used->ring[i].len = virtio_tswap32(vdev, len);
}
static inline uint16_t vring_get_used_flags(VirtIODevice *vdev, Vring *vring)
{
return virtio_tswap16(vdev, vring->vr.used->flags);
}
static inline uint16_t vring_get_avail_flags(VirtIODevice *vdev, Vring *vring)
{
return virtio_tswap16(vdev, vring->vr.avail->flags);
}
static inline void vring_set_used_flags(VirtIODevice *vdev, Vring *vring,
uint16_t flags)
{
vring->vr.used->flags |= virtio_tswap16(vdev, flags);
}
static inline void vring_clear_used_flags(VirtIODevice *vdev, Vring *vring,
uint16_t flags)
{
vring->vr.used->flags &= virtio_tswap16(vdev, ~flags);
}
static inline unsigned int vring_get_num(Vring *vring)
{
return vring->vr.num;
}
/* Are there more descriptors available? */
static inline bool vring_more_avail(VirtIODevice *vdev, Vring *vring)
{
return vring_get_avail_idx(vdev, vring) != vring->last_avail_idx;
}
#endif
|