root / hw / virtio.h @ 4870852c
History | View | Annotate | Download (3.9 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 | 967f97fa | aliguori | #include "pci.h" |
19 | 967f97fa | aliguori | |
20 | 967f97fa | aliguori | /* from Linux's linux/virtio_config.h */
|
21 | 967f97fa | aliguori | |
22 | 967f97fa | aliguori | /* Status byte for guest to report progress, and synchronize features. */
|
23 | 967f97fa | aliguori | /* We have seen device and processed generic fields (VIRTIO_CONFIG_F_VIRTIO) */
|
24 | 967f97fa | aliguori | #define VIRTIO_CONFIG_S_ACKNOWLEDGE 1 |
25 | 967f97fa | aliguori | /* We have found a driver for the device. */
|
26 | 967f97fa | aliguori | #define VIRTIO_CONFIG_S_DRIVER 2 |
27 | 967f97fa | aliguori | /* Driver has used its parts of the config, and is happy */
|
28 | 967f97fa | aliguori | #define VIRTIO_CONFIG_S_DRIVER_OK 4 |
29 | 967f97fa | aliguori | /* We've given up on this device. */
|
30 | 967f97fa | aliguori | #define VIRTIO_CONFIG_S_FAILED 0x80 |
31 | 967f97fa | aliguori | |
32 | 967f97fa | aliguori | /* We notify when the ring is completely used, even if the guest is supressing
|
33 | 967f97fa | aliguori | * callbacks */
|
34 | 967f97fa | aliguori | #define VIRTIO_F_NOTIFY_ON_EMPTY 24 |
35 | 8eca6b1b | aliguori | /* A guest should never accept this. It implies negotiation is broken. */
|
36 | 8eca6b1b | aliguori | #define VIRTIO_F_BAD_FEATURE 30 |
37 | 967f97fa | aliguori | |
38 | 967f97fa | aliguori | /* from Linux's linux/virtio_ring.h */
|
39 | 967f97fa | aliguori | |
40 | 967f97fa | aliguori | /* This marks a buffer as continuing via the next field. */
|
41 | 967f97fa | aliguori | #define VRING_DESC_F_NEXT 1 |
42 | 967f97fa | aliguori | /* This marks a buffer as write-only (otherwise read-only). */
|
43 | 967f97fa | aliguori | #define VRING_DESC_F_WRITE 2 |
44 | 967f97fa | aliguori | |
45 | 967f97fa | aliguori | /* This means don't notify other side when buffer added. */
|
46 | 967f97fa | aliguori | #define VRING_USED_F_NO_NOTIFY 1 |
47 | 967f97fa | aliguori | /* This means don't interrupt guest when buffer consumed. */
|
48 | 967f97fa | aliguori | #define VRING_AVAIL_F_NO_INTERRUPT 1 |
49 | 967f97fa | aliguori | |
50 | 967f97fa | aliguori | struct VirtQueue;
|
51 | 967f97fa | aliguori | |
52 | f46f15bc | aliguori | static inline target_phys_addr_t vring_align(target_phys_addr_t addr, |
53 | f46f15bc | aliguori | unsigned long align) |
54 | f46f15bc | aliguori | { |
55 | f46f15bc | aliguori | return (addr + align - 1) & ~(align - 1); |
56 | f46f15bc | aliguori | } |
57 | f46f15bc | aliguori | |
58 | 967f97fa | aliguori | typedef struct VirtQueue VirtQueue; |
59 | 967f97fa | aliguori | typedef struct VirtIODevice VirtIODevice; |
60 | 967f97fa | aliguori | |
61 | 967f97fa | aliguori | #define VIRTQUEUE_MAX_SIZE 1024 |
62 | 967f97fa | aliguori | |
63 | 967f97fa | aliguori | typedef struct VirtQueueElement |
64 | 967f97fa | aliguori | { |
65 | 967f97fa | aliguori | unsigned int index; |
66 | 967f97fa | aliguori | unsigned int out_num; |
67 | 967f97fa | aliguori | unsigned int in_num; |
68 | 967f97fa | aliguori | target_phys_addr_t in_addr[VIRTQUEUE_MAX_SIZE]; |
69 | 967f97fa | aliguori | struct iovec in_sg[VIRTQUEUE_MAX_SIZE];
|
70 | 967f97fa | aliguori | struct iovec out_sg[VIRTQUEUE_MAX_SIZE];
|
71 | 967f97fa | aliguori | } VirtQueueElement; |
72 | 967f97fa | aliguori | |
73 | 967f97fa | aliguori | #define VIRTIO_PCI_QUEUE_MAX 16 |
74 | 967f97fa | aliguori | |
75 | 967f97fa | aliguori | struct VirtIODevice
|
76 | 967f97fa | aliguori | { |
77 | 967f97fa | aliguori | PCIDevice pci_dev; |
78 | 967f97fa | aliguori | const char *name; |
79 | 967f97fa | aliguori | uint32_t addr; |
80 | 967f97fa | aliguori | uint8_t status; |
81 | 967f97fa | aliguori | uint8_t isr; |
82 | 967f97fa | aliguori | uint16_t queue_sel; |
83 | 967f97fa | aliguori | uint32_t features; |
84 | 967f97fa | aliguori | size_t config_len; |
85 | 967f97fa | aliguori | void *config;
|
86 | 967f97fa | aliguori | uint32_t (*get_features)(VirtIODevice *vdev); |
87 | 8eca6b1b | aliguori | uint32_t (*bad_features)(VirtIODevice *vdev); |
88 | 967f97fa | aliguori | void (*set_features)(VirtIODevice *vdev, uint32_t val);
|
89 | 967f97fa | aliguori | void (*get_config)(VirtIODevice *vdev, uint8_t *config);
|
90 | 967f97fa | aliguori | void (*set_config)(VirtIODevice *vdev, const uint8_t *config); |
91 | 967f97fa | aliguori | void (*reset)(VirtIODevice *vdev);
|
92 | 967f97fa | aliguori | VirtQueue *vq; |
93 | 967f97fa | aliguori | }; |
94 | 967f97fa | aliguori | |
95 | 967f97fa | aliguori | VirtIODevice *virtio_init_pci(PCIBus *bus, const char *name, |
96 | 967f97fa | aliguori | uint16_t vendor, uint16_t device, |
97 | 967f97fa | aliguori | uint16_t subvendor, uint16_t subdevice, |
98 | 173a543b | blueswir1 | uint16_t class_code, uint8_t pif, |
99 | 173a543b | blueswir1 | size_t config_size, size_t struct_size); |
100 | 967f97fa | aliguori | |
101 | 967f97fa | aliguori | VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,
|
102 | 967f97fa | aliguori | void (*handle_output)(VirtIODevice *,
|
103 | 967f97fa | aliguori | VirtQueue *)); |
104 | 967f97fa | aliguori | |
105 | 967f97fa | aliguori | void virtqueue_push(VirtQueue *vq, const VirtQueueElement *elem, |
106 | 967f97fa | aliguori | unsigned int len); |
107 | 967f97fa | aliguori | void virtqueue_flush(VirtQueue *vq, unsigned int count); |
108 | 967f97fa | aliguori | void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem, |
109 | 967f97fa | aliguori | unsigned int len, unsigned int idx); |
110 | 967f97fa | aliguori | |
111 | 967f97fa | aliguori | int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem);
|
112 | 967f97fa | aliguori | int virtqueue_avail_bytes(VirtQueue *vq, int in_bytes, int out_bytes); |
113 | 967f97fa | aliguori | |
114 | 967f97fa | aliguori | void virtio_notify(VirtIODevice *vdev, VirtQueue *vq);
|
115 | 967f97fa | aliguori | |
116 | 967f97fa | aliguori | void virtio_save(VirtIODevice *vdev, QEMUFile *f);
|
117 | 967f97fa | aliguori | |
118 | 967f97fa | aliguori | void virtio_load(VirtIODevice *vdev, QEMUFile *f);
|
119 | 967f97fa | aliguori | |
120 | b946a153 | aliguori | void virtio_cleanup(VirtIODevice *vdev);
|
121 | b946a153 | aliguori | |
122 | 967f97fa | aliguori | void virtio_notify_config(VirtIODevice *vdev);
|
123 | 967f97fa | aliguori | |
124 | 967f97fa | aliguori | void virtio_queue_set_notification(VirtQueue *vq, int enable); |
125 | 967f97fa | aliguori | |
126 | 967f97fa | aliguori | int virtio_queue_ready(VirtQueue *vq);
|
127 | 967f97fa | aliguori | |
128 | 967f97fa | aliguori | int virtio_queue_empty(VirtQueue *vq);
|
129 | 967f97fa | aliguori | |
130 | 967f97fa | aliguori | #endif |