root / hw / virtio.h @ 8cb310e1
History | View | Annotate | Download (5.7 kB)
1 | 967f97fa | aliguori | /*
|
---|---|---|---|
2 | 967f97fa | aliguori | * Virtio Support
|
3 | 967f97fa | aliguori | *
|
4 | 967f97fa | aliguori | * Copyright IBM, Corp. 2007
|
5 | 967f97fa | aliguori | *
|
6 | 967f97fa | aliguori | * Authors:
|
7 | 967f97fa | aliguori | * Anthony Liguori <aliguori@us.ibm.com>
|
8 | 967f97fa | aliguori | *
|
9 | 967f97fa | aliguori | * This work is licensed under the terms of the GNU GPL, version 2. See
|
10 | 967f97fa | aliguori | * the COPYING file in the top-level directory.
|
11 | 967f97fa | aliguori | *
|
12 | 967f97fa | aliguori | */
|
13 | 967f97fa | aliguori | |
14 | 967f97fa | aliguori | #ifndef _QEMU_VIRTIO_H
|
15 | 967f97fa | aliguori | #define _QEMU_VIRTIO_H
|
16 | 967f97fa | aliguori | |
17 | 967f97fa | aliguori | #include "hw.h" |
18 | 97b15621 | Gerd Hoffmann | #include "net.h" |
19 | 53c25cea | Paul Brook | #include "qdev.h" |
20 | d176c495 | Gerd Hoffmann | #include "sysemu.h" |
21 | 967f97fa | aliguori | |
22 | 967f97fa | aliguori | /* from Linux's linux/virtio_config.h */
|
23 | 967f97fa | aliguori | |
24 | 967f97fa | aliguori | /* Status byte for guest to report progress, and synchronize features. */
|
25 | 967f97fa | aliguori | /* We have seen device and processed generic fields (VIRTIO_CONFIG_F_VIRTIO) */
|
26 | 967f97fa | aliguori | #define VIRTIO_CONFIG_S_ACKNOWLEDGE 1 |
27 | 967f97fa | aliguori | /* We have found a driver for the device. */
|
28 | 967f97fa | aliguori | #define VIRTIO_CONFIG_S_DRIVER 2 |
29 | 967f97fa | aliguori | /* Driver has used its parts of the config, and is happy */
|
30 | 967f97fa | aliguori | #define VIRTIO_CONFIG_S_DRIVER_OK 4 |
31 | 967f97fa | aliguori | /* We've given up on this device. */
|
32 | 967f97fa | aliguori | #define VIRTIO_CONFIG_S_FAILED 0x80 |
33 | 967f97fa | aliguori | |
34 | d89c682f | Stefan Weil | /* We notify when the ring is completely used, even if the guest is suppressing
|
35 | 967f97fa | aliguori | * callbacks */
|
36 | 967f97fa | aliguori | #define VIRTIO_F_NOTIFY_ON_EMPTY 24 |
37 | efeea6d0 | Mark McLoughlin | /* We support indirect buffer descriptors */
|
38 | efeea6d0 | Mark McLoughlin | #define VIRTIO_RING_F_INDIRECT_DESC 28 |
39 | 8eca6b1b | aliguori | /* A guest should never accept this. It implies negotiation is broken. */
|
40 | 8eca6b1b | aliguori | #define VIRTIO_F_BAD_FEATURE 30 |
41 | 967f97fa | aliguori | |
42 | 967f97fa | aliguori | /* from Linux's linux/virtio_ring.h */
|
43 | 967f97fa | aliguori | |
44 | 967f97fa | aliguori | /* This marks a buffer as continuing via the next field. */
|
45 | 967f97fa | aliguori | #define VRING_DESC_F_NEXT 1 |
46 | 967f97fa | aliguori | /* This marks a buffer as write-only (otherwise read-only). */
|
47 | 967f97fa | aliguori | #define VRING_DESC_F_WRITE 2 |
48 | efeea6d0 | Mark McLoughlin | /* This means the buffer contains a list of buffer descriptors. */
|
49 | efeea6d0 | Mark McLoughlin | #define VRING_DESC_F_INDIRECT 4 |
50 | 967f97fa | aliguori | |
51 | 967f97fa | aliguori | /* This means don't notify other side when buffer added. */
|
52 | 967f97fa | aliguori | #define VRING_USED_F_NO_NOTIFY 1 |
53 | 967f97fa | aliguori | /* This means don't interrupt guest when buffer consumed. */
|
54 | 967f97fa | aliguori | #define VRING_AVAIL_F_NO_INTERRUPT 1 |
55 | 967f97fa | aliguori | |
56 | 967f97fa | aliguori | struct VirtQueue;
|
57 | 967f97fa | aliguori | |
58 | c227f099 | Anthony Liguori | static inline target_phys_addr_t vring_align(target_phys_addr_t addr, |
59 | f46f15bc | aliguori | unsigned long align) |
60 | f46f15bc | aliguori | { |
61 | f46f15bc | aliguori | return (addr + align - 1) & ~(align - 1); |
62 | f46f15bc | aliguori | } |
63 | f46f15bc | aliguori | |
64 | 967f97fa | aliguori | typedef struct VirtQueue VirtQueue; |
65 | 967f97fa | aliguori | typedef struct VirtIODevice VirtIODevice; |
66 | 967f97fa | aliguori | |
67 | 967f97fa | aliguori | #define VIRTQUEUE_MAX_SIZE 1024 |
68 | 967f97fa | aliguori | |
69 | 967f97fa | aliguori | typedef struct VirtQueueElement |
70 | 967f97fa | aliguori | { |
71 | 967f97fa | aliguori | unsigned int index; |
72 | 967f97fa | aliguori | unsigned int out_num; |
73 | 967f97fa | aliguori | unsigned int in_num; |
74 | c227f099 | Anthony Liguori | target_phys_addr_t in_addr[VIRTQUEUE_MAX_SIZE]; |
75 | 967f97fa | aliguori | struct iovec in_sg[VIRTQUEUE_MAX_SIZE];
|
76 | 967f97fa | aliguori | struct iovec out_sg[VIRTQUEUE_MAX_SIZE];
|
77 | 967f97fa | aliguori | } VirtQueueElement; |
78 | 967f97fa | aliguori | |
79 | 53c25cea | Paul Brook | typedef struct { |
80 | 7055e687 | Michael S. Tsirkin | void (*notify)(void * opaque, uint16_t vector); |
81 | ff24bd58 | Michael S. Tsirkin | void (*save_config)(void * opaque, QEMUFile *f); |
82 | ff24bd58 | Michael S. Tsirkin | void (*save_queue)(void * opaque, int n, QEMUFile *f); |
83 | ff24bd58 | Michael S. Tsirkin | int (*load_config)(void * opaque, QEMUFile *f); |
84 | ff24bd58 | Michael S. Tsirkin | int (*load_queue)(void * opaque, int n, QEMUFile *f); |
85 | 53c25cea | Paul Brook | } VirtIOBindings; |
86 | 53c25cea | Paul Brook | |
87 | 967f97fa | aliguori | #define VIRTIO_PCI_QUEUE_MAX 16 |
88 | 967f97fa | aliguori | |
89 | 7055e687 | Michael S. Tsirkin | #define VIRTIO_NO_VECTOR 0xffff |
90 | 7055e687 | Michael S. Tsirkin | |
91 | 967f97fa | aliguori | struct VirtIODevice
|
92 | 967f97fa | aliguori | { |
93 | 967f97fa | aliguori | const char *name; |
94 | 967f97fa | aliguori | uint8_t status; |
95 | 967f97fa | aliguori | uint8_t isr; |
96 | 967f97fa | aliguori | uint16_t queue_sel; |
97 | 967f97fa | aliguori | uint32_t features; |
98 | 967f97fa | aliguori | size_t config_len; |
99 | 967f97fa | aliguori | void *config;
|
100 | 7055e687 | Michael S. Tsirkin | uint16_t config_vector; |
101 | 7055e687 | Michael S. Tsirkin | int nvectors;
|
102 | 967f97fa | aliguori | uint32_t (*get_features)(VirtIODevice *vdev); |
103 | 8eca6b1b | aliguori | uint32_t (*bad_features)(VirtIODevice *vdev); |
104 | 967f97fa | aliguori | void (*set_features)(VirtIODevice *vdev, uint32_t val);
|
105 | 967f97fa | aliguori | void (*get_config)(VirtIODevice *vdev, uint8_t *config);
|
106 | 967f97fa | aliguori | void (*set_config)(VirtIODevice *vdev, const uint8_t *config); |
107 | 967f97fa | aliguori | void (*reset)(VirtIODevice *vdev);
|
108 | 967f97fa | aliguori | VirtQueue *vq; |
109 | 53c25cea | Paul Brook | const VirtIOBindings *binding;
|
110 | 53c25cea | Paul Brook | void *binding_opaque;
|
111 | 53c25cea | Paul Brook | uint16_t device_id; |
112 | 967f97fa | aliguori | }; |
113 | 967f97fa | aliguori | |
114 | 967f97fa | aliguori | VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,
|
115 | 967f97fa | aliguori | void (*handle_output)(VirtIODevice *,
|
116 | 967f97fa | aliguori | VirtQueue *)); |
117 | 967f97fa | aliguori | |
118 | 967f97fa | aliguori | void virtqueue_push(VirtQueue *vq, const VirtQueueElement *elem, |
119 | 967f97fa | aliguori | unsigned int len); |
120 | 967f97fa | aliguori | void virtqueue_flush(VirtQueue *vq, unsigned int count); |
121 | 967f97fa | aliguori | void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem, |
122 | 967f97fa | aliguori | unsigned int len, unsigned int idx); |
123 | 967f97fa | aliguori | |
124 | 967f97fa | aliguori | int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem);
|
125 | 967f97fa | aliguori | int virtqueue_avail_bytes(VirtQueue *vq, int in_bytes, int out_bytes); |
126 | 967f97fa | aliguori | |
127 | 967f97fa | aliguori | void virtio_notify(VirtIODevice *vdev, VirtQueue *vq);
|
128 | 967f97fa | aliguori | |
129 | 967f97fa | aliguori | void virtio_save(VirtIODevice *vdev, QEMUFile *f);
|
130 | 967f97fa | aliguori | |
131 | 7055e687 | Michael S. Tsirkin | int virtio_load(VirtIODevice *vdev, QEMUFile *f);
|
132 | 967f97fa | aliguori | |
133 | b946a153 | aliguori | void virtio_cleanup(VirtIODevice *vdev);
|
134 | b946a153 | aliguori | |
135 | 967f97fa | aliguori | void virtio_notify_config(VirtIODevice *vdev);
|
136 | 967f97fa | aliguori | |
137 | 967f97fa | aliguori | void virtio_queue_set_notification(VirtQueue *vq, int enable); |
138 | 967f97fa | aliguori | |
139 | 967f97fa | aliguori | int virtio_queue_ready(VirtQueue *vq);
|
140 | 967f97fa | aliguori | |
141 | 967f97fa | aliguori | int virtio_queue_empty(VirtQueue *vq);
|
142 | 967f97fa | aliguori | |
143 | 53c25cea | Paul Brook | /* Host binding interface. */
|
144 | 53c25cea | Paul Brook | |
145 | 53c25cea | Paul Brook | VirtIODevice *virtio_common_init(const char *name, uint16_t device_id, |
146 | 53c25cea | Paul Brook | size_t config_size, size_t struct_size); |
147 | 53c25cea | Paul Brook | uint32_t virtio_config_readb(VirtIODevice *vdev, uint32_t addr); |
148 | 53c25cea | Paul Brook | uint32_t virtio_config_readw(VirtIODevice *vdev, uint32_t addr); |
149 | 53c25cea | Paul Brook | uint32_t virtio_config_readl(VirtIODevice *vdev, uint32_t addr); |
150 | 53c25cea | Paul Brook | void virtio_config_writeb(VirtIODevice *vdev, uint32_t addr, uint32_t data);
|
151 | 53c25cea | Paul Brook | void virtio_config_writew(VirtIODevice *vdev, uint32_t addr, uint32_t data);
|
152 | 53c25cea | Paul Brook | void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data);
|
153 | c227f099 | Anthony Liguori | void virtio_queue_set_addr(VirtIODevice *vdev, int n, target_phys_addr_t addr); |
154 | c227f099 | Anthony Liguori | target_phys_addr_t virtio_queue_get_addr(VirtIODevice *vdev, int n);
|
155 | 53c25cea | Paul Brook | int virtio_queue_get_num(VirtIODevice *vdev, int n); |
156 | 53c25cea | Paul Brook | void virtio_queue_notify(VirtIODevice *vdev, int n); |
157 | 7055e687 | Michael S. Tsirkin | uint16_t virtio_queue_vector(VirtIODevice *vdev, int n);
|
158 | 7055e687 | Michael S. Tsirkin | void virtio_queue_set_vector(VirtIODevice *vdev, int n, uint16_t vector); |
159 | 53c25cea | Paul Brook | void virtio_reset(void *opaque); |
160 | 53c25cea | Paul Brook | void virtio_update_irq(VirtIODevice *vdev);
|
161 | 53c25cea | Paul Brook | |
162 | 53c25cea | Paul Brook | void virtio_bind_device(VirtIODevice *vdev, const VirtIOBindings *binding, |
163 | 53c25cea | Paul Brook | void *opaque);
|
164 | 53c25cea | Paul Brook | |
165 | 53c25cea | Paul Brook | /* Base devices. */
|
166 | d176c495 | Gerd Hoffmann | VirtIODevice *virtio_blk_init(DeviceState *dev, DriveInfo *dinfo); |
167 | 97b15621 | Gerd Hoffmann | VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf); |
168 | 53c25cea | Paul Brook | VirtIODevice *virtio_console_init(DeviceState *dev); |
169 | 53c25cea | Paul Brook | VirtIODevice *virtio_balloon_init(DeviceState *dev); |
170 | 53c25cea | Paul Brook | |
171 | 97b15621 | Gerd Hoffmann | void virtio_net_exit(VirtIODevice *vdev);
|
172 | 97b15621 | Gerd Hoffmann | |
173 | 967f97fa | aliguori | #endif |