4 * Copyright IBM, Corp. 2007
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
14 #ifndef _QEMU_VIRTIO_H
15 #define _QEMU_VIRTIO_H
21 /* from Linux's linux/virtio_config.h */
23 /* Status byte for guest to report progress, and synchronize features. */
24 /* We have seen device and processed generic fields (VIRTIO_CONFIG_F_VIRTIO) */
25 #define VIRTIO_CONFIG_S_ACKNOWLEDGE 1
26 /* We have found a driver for the device. */
27 #define VIRTIO_CONFIG_S_DRIVER 2
28 /* Driver has used its parts of the config, and is happy */
29 #define VIRTIO_CONFIG_S_DRIVER_OK 4
30 /* We've given up on this device. */
31 #define VIRTIO_CONFIG_S_FAILED 0x80
33 /* We notify when the ring is completely used, even if the guest is supressing
35 #define VIRTIO_F_NOTIFY_ON_EMPTY 24
37 /* from Linux's linux/virtio_ring.h */
39 /* This marks a buffer as continuing via the next field. */
40 #define VRING_DESC_F_NEXT 1
41 /* This marks a buffer as write-only (otherwise read-only). */
42 #define VRING_DESC_F_WRITE 2
44 /* This means don't notify other side when buffer added. */
45 #define VRING_USED_F_NO_NOTIFY 1
46 /* This means don't interrupt guest when buffer consumed. */
47 #define VRING_AVAIL_F_NO_INTERRUPT 1
49 typedef struct VirtQueue VirtQueue
;
50 typedef struct VirtIODevice VirtIODevice
;
52 typedef struct VRingDesc
60 typedef struct VRingAvail
67 typedef struct VRingUsedElem
73 typedef struct VRingUsed
77 VRingUsedElem ring
[0];
92 uint16_t last_avail_idx
;
94 void (*handle_output
)(VirtIODevice
*vdev
, VirtQueue
*vq
);
97 #define VIRTQUEUE_MAX_SIZE 1024
99 typedef struct VirtQueueElement
102 unsigned int out_num
;
104 struct iovec in_sg
[VIRTQUEUE_MAX_SIZE
];
105 struct iovec out_sg
[VIRTQUEUE_MAX_SIZE
];
108 #define VIRTIO_PCI_QUEUE_MAX 16
121 uint32_t (*get_features
)(VirtIODevice
*vdev
);
122 void (*set_features
)(VirtIODevice
*vdev
, uint32_t val
);
123 void (*update_config
)(VirtIODevice
*vdev
, uint8_t *config
);
124 void (*reset
)(VirtIODevice
*vdev
);
125 VirtQueue vq
[VIRTIO_PCI_QUEUE_MAX
];
128 VirtIODevice
*virtio_init_pci(PCIBus
*bus
, const char *name
,
129 uint16_t vendor
, uint16_t device
,
130 uint16_t subvendor
, uint16_t subdevice
,
131 uint8_t class_code
, uint8_t subclass_code
,
132 uint8_t pif
, size_t config_size
,
135 VirtQueue
*virtio_add_queue(VirtIODevice
*vdev
, int queue_size
,
136 void (*handle_output
)(VirtIODevice
*,
139 void virtqueue_push(VirtQueue
*vq
, const VirtQueueElement
*elem
,
142 int virtqueue_pop(VirtQueue
*vq
, VirtQueueElement
*elem
);
144 void virtio_notify(VirtIODevice
*vdev
, VirtQueue
*vq
);
146 void virtio_save(VirtIODevice
*vdev
, QEMUFile
*f
);
148 void virtio_load(VirtIODevice
*vdev
, QEMUFile
*f
);