LSI SCSI and e1000 unregister callbacks
[qemu-kvm/fedora.git] / hw / virtio.h
blobdee97ba705f0c2012215c6b19bde8e583c259598
1 /*
2 * Virtio Support
4 * Copyright IBM, Corp. 2007
6 * Authors:
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
17 #include <sys/uio.h>
18 #include "hw.h"
19 #include "pci.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 /* from Linux's linux/virtio_ring.h */
35 /* This marks a buffer as continuing via the next field. */
36 #define VRING_DESC_F_NEXT 1
37 /* This marks a buffer as write-only (otherwise read-only). */
38 #define VRING_DESC_F_WRITE 2
40 /* This means don't notify other side when buffer added. */
41 #define VRING_USED_F_NO_NOTIFY 1
42 /* This means don't interrupt guest when buffer consumed. */
43 #define VRING_AVAIL_F_NO_INTERRUPT 1
45 typedef struct VirtQueue VirtQueue;
46 typedef struct VirtIODevice VirtIODevice;
48 typedef struct VRingDesc
50 uint64_t addr;
51 uint32_t len;
52 uint16_t flags;
53 uint16_t next;
54 } VRingDesc;
56 typedef struct VRingAvail
58 uint16_t flags;
59 uint16_t idx;
60 uint16_t ring[0];
61 } VRingAvail;
63 typedef struct VRingUsedElem
65 uint32_t id;
66 uint32_t len;
67 } VRingUsedElem;
69 typedef struct VRingUsed
71 uint16_t flags;
72 uint16_t idx;
73 VRingUsedElem ring[0];
74 } VRingUsed;
76 typedef struct VRing
78 unsigned int num;
79 VRingDesc *desc;
80 VRingAvail *avail;
81 VRingUsed *used;
82 } VRing;
84 struct VirtQueue
86 VRing vring;
87 uint32_t pfn;
88 uint16_t last_avail_idx;
89 void (*handle_output)(VirtIODevice *vdev, VirtQueue *vq);
90 int index;
93 #define VIRTQUEUE_MAX_SIZE 1024
95 typedef struct VirtQueueElement
97 unsigned int index;
98 unsigned int out_num;
99 unsigned int in_num;
100 struct iovec in_sg[VIRTQUEUE_MAX_SIZE];
101 struct iovec out_sg[VIRTQUEUE_MAX_SIZE];
102 } VirtQueueElement;
104 #define VIRTIO_PCI_QUEUE_MAX 16
106 struct VirtIODevice
108 PCIDevice pci_dev;
109 const char *name;
110 uint32_t addr;
111 uint16_t vendor;
112 uint16_t device;
113 uint8_t status;
114 uint8_t isr;
115 uint16_t queue_sel;
116 uint32_t features;
117 size_t config_len;
118 void *config;
119 uint32_t (*get_features)(VirtIODevice *vdev);
120 void (*set_features)(VirtIODevice *vdev, uint32_t val);
121 void (*update_config)(VirtIODevice *vdev, uint8_t *config);
122 VirtQueue vq[VIRTIO_PCI_QUEUE_MAX];
125 VirtIODevice *virtio_init_pci(PCIBus *bus, const char *name,
126 uint16_t vendor, uint16_t device,
127 uint16_t subvendor, uint16_t subdevice,
128 uint8_t class_code, uint8_t subclass_code,
129 uint8_t pif, size_t config_size,
130 size_t struct_size);
132 VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,
133 void (*handle_output)(VirtIODevice *,
134 VirtQueue *));
136 void virtqueue_push(VirtQueue *vq, const VirtQueueElement *elem,
137 unsigned int len);
139 int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem);
141 void virtio_notify(VirtIODevice *vdev, VirtQueue *vq);
143 #endif