]> Git Repo - qemu.git/blame - tests/libqos/virtio.h
qapi: Separate type QNull from QObject
[qemu.git] / tests / libqos / virtio.h
CommitLineData
311e666a
MM
1/*
2 * libqos virtio definitions
3 *
4 * Copyright (c) 2014 Marc Marí
5 *
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
8 */
9
10#ifndef LIBQOS_VIRTIO_H
11#define LIBQOS_VIRTIO_H
12
bf3c63d2 13#include "libqos/malloc.h"
780b11a0 14#include "standard-headers/linux/virtio_ring.h"
bf3c63d2 15
1053587c 16#define QVIRTIO_F_BAD_FEATURE 0x40000000
f294b029 17
6b9cdf4c
LV
18typedef struct QVirtioBus QVirtioBus;
19
311e666a 20typedef struct QVirtioDevice {
6b9cdf4c 21 const QVirtioBus *bus;
311e666a
MM
22 /* Device type */
23 uint16_t device_type;
24} QVirtioDevice;
25
bf3c63d2 26typedef struct QVirtQueue {
780b11a0
SH
27 uint64_t desc; /* This points to an array of struct vring_desc */
28 uint64_t avail; /* This points to a struct vring_avail */
afbccba6 29 uint64_t used; /* This points to a struct vring_used */
bf3c63d2
MM
30 uint16_t index;
31 uint32_t size;
32 uint32_t free_head;
33 uint32_t num_free;
34 uint32_t align;
e77abbe9 35 uint16_t last_used_idx;
f294b029 36 bool indirect;
1053587c 37 bool event;
bf3c63d2
MM
38} QVirtQueue;
39
f294b029 40typedef struct QVRingIndirectDesc {
780b11a0 41 uint64_t desc; /* This points to an array fo struct vring_desc */
f294b029
MM
42 uint16_t index;
43 uint16_t elem;
44} QVRingIndirectDesc;
45
6b9cdf4c 46struct QVirtioBus {
728312b8
MM
47 uint8_t (*config_readb)(QVirtioDevice *d, uint64_t addr);
48 uint16_t (*config_readw)(QVirtioDevice *d, uint64_t addr);
49 uint32_t (*config_readl)(QVirtioDevice *d, uint64_t addr);
50 uint64_t (*config_readq)(QVirtioDevice *d, uint64_t addr);
46e0cf76 51
bf3c63d2
MM
52 /* Get features of the device */
53 uint32_t (*get_features)(QVirtioDevice *d);
54
f294b029 55 /* Set features of the device */
bf3c63d2
MM
56 void (*set_features)(QVirtioDevice *d, uint32_t features);
57
f294b029
MM
58 /* Get features of the guest */
59 uint32_t (*get_guest_features)(QVirtioDevice *d);
60
46e0cf76
MM
61 /* Get status of the device */
62 uint8_t (*get_status)(QVirtioDevice *d);
63
64 /* Set status of the device */
65 void (*set_status)(QVirtioDevice *d, uint8_t status);
bf3c63d2 66
58368113
MM
67 /* Get the queue ISR status of the device */
68 bool (*get_queue_isr_status)(QVirtioDevice *d, QVirtQueue *vq);
69
70 /* Get the configuration ISR status of the device */
71 bool (*get_config_isr_status)(QVirtioDevice *d);
bf3c63d2
MM
72
73 /* Select a queue to work on */
74 void (*queue_select)(QVirtioDevice *d, uint16_t index);
75
76 /* Get the size of the selected queue */
77 uint16_t (*get_queue_size)(QVirtioDevice *d);
78
79 /* Set the address of the selected queue */
80 void (*set_queue_address)(QVirtioDevice *d, uint32_t pfn);
81
82 /* Setup the virtqueue specified by index */
83 QVirtQueue *(*virtqueue_setup)(QVirtioDevice *d, QGuestAllocator *alloc,
84 uint16_t index);
85
f1d3b991
SH
86 /* Free virtqueue resources */
87 void (*virtqueue_cleanup)(QVirtQueue *vq, QGuestAllocator *alloc);
88
bf3c63d2
MM
89 /* Notify changes in virtqueue */
90 void (*virtqueue_kick)(QVirtioDevice *d, QVirtQueue *vq);
6b9cdf4c 91};
46e0cf76 92
8b4b80c3
LV
93static inline bool qvirtio_is_big_endian(QVirtioDevice *d)
94{
95 /* FIXME: virtio 1.0 is always little-endian */
96 return qtest_big_endian(global_qtest);
97}
98
bf3c63d2
MM
99static inline uint32_t qvring_size(uint32_t num, uint32_t align)
100{
780b11a0 101 return ((sizeof(struct vring_desc) * num + sizeof(uint16_t) * (3 + num)
bf3c63d2 102 + align - 1) & ~(align - 1))
780b11a0 103 + sizeof(uint16_t) * 3 + sizeof(struct vring_used_elem) * num;
bf3c63d2
MM
104}
105
6b9cdf4c
LV
106uint8_t qvirtio_config_readb(QVirtioDevice *d, uint64_t addr);
107uint16_t qvirtio_config_readw(QVirtioDevice *d, uint64_t addr);
108uint32_t qvirtio_config_readl(QVirtioDevice *d, uint64_t addr);
109uint64_t qvirtio_config_readq(QVirtioDevice *d, uint64_t addr);
110uint32_t qvirtio_get_features(QVirtioDevice *d);
111void qvirtio_set_features(QVirtioDevice *d, uint32_t features);
112
113void qvirtio_reset(QVirtioDevice *d);
114void qvirtio_set_acknowledge(QVirtioDevice *d);
115void qvirtio_set_driver(QVirtioDevice *d);
116void qvirtio_set_driver_ok(QVirtioDevice *d);
117
118void qvirtio_wait_queue_isr(QVirtioDevice *d,
70556264 119 QVirtQueue *vq, gint64 timeout_us);
6b9cdf4c 120uint8_t qvirtio_wait_status_byte_no_isr(QVirtioDevice *d,
e8c81b4d
SH
121 QVirtQueue *vq,
122 uint64_t addr,
123 gint64 timeout_us);
e77abbe9
SH
124void qvirtio_wait_used_elem(QVirtioDevice *d,
125 QVirtQueue *vq,
126 uint32_t desc_idx,
127 gint64 timeout_us);
6b9cdf4c
LV
128void qvirtio_wait_config_isr(QVirtioDevice *d, gint64 timeout_us);
129QVirtQueue *qvirtqueue_setup(QVirtioDevice *d,
130 QGuestAllocator *alloc, uint16_t index);
f1d3b991
SH
131void qvirtqueue_cleanup(const QVirtioBus *bus, QVirtQueue *vq,
132 QGuestAllocator *alloc);
bf3c63d2
MM
133
134void qvring_init(const QGuestAllocator *alloc, QVirtQueue *vq, uint64_t addr);
f294b029
MM
135QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d,
136 QGuestAllocator *alloc, uint16_t elem);
137void qvring_indirect_desc_add(QVRingIndirectDesc *indirect, uint64_t data,
138 uint32_t len, bool write);
bf3c63d2
MM
139uint32_t qvirtqueue_add(QVirtQueue *vq, uint64_t data, uint32_t len, bool write,
140 bool next);
f294b029 141uint32_t qvirtqueue_add_indirect(QVirtQueue *vq, QVRingIndirectDesc *indirect);
6b9cdf4c 142void qvirtqueue_kick(QVirtioDevice *d, QVirtQueue *vq, uint32_t free_head);
e77abbe9 143bool qvirtqueue_get_buf(QVirtQueue *vq, uint32_t *desc_idx);
46e0cf76 144
1053587c 145void qvirtqueue_set_used_event(QVirtQueue *vq, uint16_t idx);
311e666a 146#endif
This page took 0.198634 seconds and 4 git commands to generate.