]> git.proxmox.com Git - qemu.git/blame - hw/virtio.h
Virtio core support
[qemu.git] / hw / virtio.h
CommitLineData
967f97fa
AL
1/*
2 * Virtio Support
3 *
4 * Copyright IBM, Corp. 2007
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
11 *
12 */
13
14#ifndef _QEMU_VIRTIO_H
15#define _QEMU_VIRTIO_H
16
17#include <sys/uio.h>
18#include "hw.h"
19#include "pci.h"
20
21/* from Linux's linux/virtio_config.h */
22
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
32
33/* We notify when the ring is completely used, even if the guest is supressing
34 * callbacks */
35#define VIRTIO_F_NOTIFY_ON_EMPTY 24
36
37/* from Linux's linux/virtio_ring.h */
38
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
43
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
48
49struct VirtQueue;
50
51typedef struct VirtQueue VirtQueue;
52typedef struct VirtIODevice VirtIODevice;
53
54#define VIRTQUEUE_MAX_SIZE 1024
55
56typedef struct VirtQueueElement
57{
58 unsigned int index;
59 unsigned int out_num;
60 unsigned int in_num;
61 target_phys_addr_t in_addr[VIRTQUEUE_MAX_SIZE];
62 struct iovec in_sg[VIRTQUEUE_MAX_SIZE];
63 struct iovec out_sg[VIRTQUEUE_MAX_SIZE];
64} VirtQueueElement;
65
66#define VIRTIO_PCI_QUEUE_MAX 16
67
68struct VirtIODevice
69{
70 PCIDevice pci_dev;
71 const char *name;
72 uint32_t addr;
73 uint8_t status;
74 uint8_t isr;
75 uint16_t queue_sel;
76 uint32_t features;
77 size_t config_len;
78 void *config;
79 uint32_t (*get_features)(VirtIODevice *vdev);
80 void (*set_features)(VirtIODevice *vdev, uint32_t val);
81 void (*get_config)(VirtIODevice *vdev, uint8_t *config);
82 void (*set_config)(VirtIODevice *vdev, const uint8_t *config);
83 void (*reset)(VirtIODevice *vdev);
84 VirtQueue *vq;
85};
86
87VirtIODevice *virtio_init_pci(PCIBus *bus, const char *name,
88 uint16_t vendor, uint16_t device,
89 uint16_t subvendor, uint16_t subdevice,
90 uint8_t class_code, uint8_t subclass_code,
91 uint8_t pif, size_t config_size,
92 size_t struct_size);
93
94VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,
95 void (*handle_output)(VirtIODevice *,
96 VirtQueue *));
97
98void virtqueue_push(VirtQueue *vq, const VirtQueueElement *elem,
99 unsigned int len);
100void virtqueue_flush(VirtQueue *vq, unsigned int count);
101void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
102 unsigned int len, unsigned int idx);
103
104int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem);
105int virtqueue_avail_bytes(VirtQueue *vq, int in_bytes, int out_bytes);
106
107void virtio_notify(VirtIODevice *vdev, VirtQueue *vq);
108
109void virtio_save(VirtIODevice *vdev, QEMUFile *f);
110
111void virtio_load(VirtIODevice *vdev, QEMUFile *f);
112
113void virtio_notify_config(VirtIODevice *vdev);
114
115void virtio_queue_set_notification(VirtQueue *vq, int enable);
116
117int virtio_queue_ready(VirtQueue *vq);
118
119int virtio_queue_empty(VirtQueue *vq);
120
121#endif