root / hw / virtio-pci.c @ 50132156
History | View | Annotate | Download (17.9 kB)
1 | 53c25cea | Paul Brook | /*
|
---|---|---|---|
2 | 53c25cea | Paul Brook | * Virtio PCI Bindings
|
3 | 53c25cea | Paul Brook | *
|
4 | 53c25cea | Paul Brook | * Copyright IBM, Corp. 2007
|
5 | 53c25cea | Paul Brook | * Copyright (c) 2009 CodeSourcery
|
6 | 53c25cea | Paul Brook | *
|
7 | 53c25cea | Paul Brook | * Authors:
|
8 | 53c25cea | Paul Brook | * Anthony Liguori <aliguori@us.ibm.com>
|
9 | 53c25cea | Paul Brook | * Paul Brook <paul@codesourcery.com>
|
10 | 53c25cea | Paul Brook | *
|
11 | 53c25cea | Paul Brook | * This work is licensed under the terms of the GNU GPL, version 2. See
|
12 | 53c25cea | Paul Brook | * the COPYING file in the top-level directory.
|
13 | 53c25cea | Paul Brook | *
|
14 | 53c25cea | Paul Brook | */
|
15 | 53c25cea | Paul Brook | |
16 | 53c25cea | Paul Brook | #include <inttypes.h> |
17 | 53c25cea | Paul Brook | |
18 | 53c25cea | Paul Brook | #include "virtio.h" |
19 | 53c25cea | Paul Brook | #include "pci.h" |
20 | d176c495 | Gerd Hoffmann | #include "sysemu.h" |
21 | aba800a3 | Michael S. Tsirkin | #include "msix.h" |
22 | a1e0fea5 | Gerd Hoffmann | #include "net.h" |
23 | 97b15621 | Gerd Hoffmann | #include "loader.h" |
24 | 53c25cea | Paul Brook | |
25 | 53c25cea | Paul Brook | /* from Linux's linux/virtio_pci.h */
|
26 | 53c25cea | Paul Brook | |
27 | 53c25cea | Paul Brook | /* A 32-bit r/o bitmask of the features supported by the host */
|
28 | 53c25cea | Paul Brook | #define VIRTIO_PCI_HOST_FEATURES 0 |
29 | 53c25cea | Paul Brook | |
30 | 53c25cea | Paul Brook | /* A 32-bit r/w bitmask of features activated by the guest */
|
31 | 53c25cea | Paul Brook | #define VIRTIO_PCI_GUEST_FEATURES 4 |
32 | 53c25cea | Paul Brook | |
33 | 53c25cea | Paul Brook | /* A 32-bit r/w PFN for the currently selected queue */
|
34 | 53c25cea | Paul Brook | #define VIRTIO_PCI_QUEUE_PFN 8 |
35 | 53c25cea | Paul Brook | |
36 | 53c25cea | Paul Brook | /* A 16-bit r/o queue size for the currently selected queue */
|
37 | 53c25cea | Paul Brook | #define VIRTIO_PCI_QUEUE_NUM 12 |
38 | 53c25cea | Paul Brook | |
39 | 53c25cea | Paul Brook | /* A 16-bit r/w queue selector */
|
40 | 53c25cea | Paul Brook | #define VIRTIO_PCI_QUEUE_SEL 14 |
41 | 53c25cea | Paul Brook | |
42 | 53c25cea | Paul Brook | /* A 16-bit r/w queue notifier */
|
43 | 53c25cea | Paul Brook | #define VIRTIO_PCI_QUEUE_NOTIFY 16 |
44 | 53c25cea | Paul Brook | |
45 | 53c25cea | Paul Brook | /* An 8-bit device status register. */
|
46 | 53c25cea | Paul Brook | #define VIRTIO_PCI_STATUS 18 |
47 | 53c25cea | Paul Brook | |
48 | 53c25cea | Paul Brook | /* An 8-bit r/o interrupt status register. Reading the value will return the
|
49 | 53c25cea | Paul Brook | * current contents of the ISR and will also clear it. This is effectively
|
50 | 53c25cea | Paul Brook | * a read-and-acknowledge. */
|
51 | 53c25cea | Paul Brook | #define VIRTIO_PCI_ISR 19 |
52 | 53c25cea | Paul Brook | |
53 | aba800a3 | Michael S. Tsirkin | /* MSI-X registers: only enabled if MSI-X is enabled. */
|
54 | aba800a3 | Michael S. Tsirkin | /* A 16-bit vector for configuration changes. */
|
55 | aba800a3 | Michael S. Tsirkin | #define VIRTIO_MSI_CONFIG_VECTOR 20 |
56 | aba800a3 | Michael S. Tsirkin | /* A 16-bit vector for selected queue notifications. */
|
57 | aba800a3 | Michael S. Tsirkin | #define VIRTIO_MSI_QUEUE_VECTOR 22 |
58 | aba800a3 | Michael S. Tsirkin | |
59 | aba800a3 | Michael S. Tsirkin | /* Config space size */
|
60 | aba800a3 | Michael S. Tsirkin | #define VIRTIO_PCI_CONFIG_NOMSI 20 |
61 | aba800a3 | Michael S. Tsirkin | #define VIRTIO_PCI_CONFIG_MSI 24 |
62 | aba800a3 | Michael S. Tsirkin | #define VIRTIO_PCI_REGION_SIZE(dev) (msix_present(dev) ? \
|
63 | aba800a3 | Michael S. Tsirkin | VIRTIO_PCI_CONFIG_MSI : \ |
64 | aba800a3 | Michael S. Tsirkin | VIRTIO_PCI_CONFIG_NOMSI) |
65 | aba800a3 | Michael S. Tsirkin | |
66 | aba800a3 | Michael S. Tsirkin | /* The remaining space is defined by each driver as the per-driver
|
67 | aba800a3 | Michael S. Tsirkin | * configuration space */
|
68 | aba800a3 | Michael S. Tsirkin | #define VIRTIO_PCI_CONFIG(dev) (msix_enabled(dev) ? \
|
69 | aba800a3 | Michael S. Tsirkin | VIRTIO_PCI_CONFIG_MSI : \ |
70 | aba800a3 | Michael S. Tsirkin | VIRTIO_PCI_CONFIG_NOMSI) |
71 | 53c25cea | Paul Brook | |
72 | 53c25cea | Paul Brook | /* Virtio ABI version, if we increment this, we break the guest driver. */
|
73 | 53c25cea | Paul Brook | #define VIRTIO_PCI_ABI_VERSION 0 |
74 | 53c25cea | Paul Brook | |
75 | 53c25cea | Paul Brook | /* How many bits to shift physical queue address written to QUEUE_PFN.
|
76 | 53c25cea | Paul Brook | * 12 is historical, and due to x86 page size. */
|
77 | 53c25cea | Paul Brook | #define VIRTIO_PCI_QUEUE_ADDR_SHIFT 12 |
78 | 53c25cea | Paul Brook | |
79 | 53c25cea | Paul Brook | /* QEMU doesn't strictly need write barriers since everything runs in
|
80 | 53c25cea | Paul Brook | * lock-step. We'll leave the calls to wmb() in though to make it obvious for
|
81 | 53c25cea | Paul Brook | * KVM or if kqemu gets SMP support.
|
82 | 53c25cea | Paul Brook | */
|
83 | 53c25cea | Paul Brook | #define wmb() do { } while (0) |
84 | 53c25cea | Paul Brook | |
85 | 53c25cea | Paul Brook | /* PCI bindings. */
|
86 | 53c25cea | Paul Brook | |
87 | 53c25cea | Paul Brook | typedef struct { |
88 | 53c25cea | Paul Brook | PCIDevice pci_dev; |
89 | 53c25cea | Paul Brook | VirtIODevice *vdev; |
90 | 53c25cea | Paul Brook | uint32_t addr; |
91 | ab73ff29 | Gerd Hoffmann | uint32_t class_code; |
92 | a1e0fea5 | Gerd Hoffmann | uint32_t nvectors; |
93 | d176c495 | Gerd Hoffmann | DriveInfo *dinfo; |
94 | 97b15621 | Gerd Hoffmann | NICConf nic; |
95 | 53c25cea | Paul Brook | } VirtIOPCIProxy; |
96 | 53c25cea | Paul Brook | |
97 | 53c25cea | Paul Brook | /* virtio device */
|
98 | 53c25cea | Paul Brook | |
99 | 7055e687 | Michael S. Tsirkin | static void virtio_pci_notify(void *opaque, uint16_t vector) |
100 | 53c25cea | Paul Brook | { |
101 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = opaque; |
102 | aba800a3 | Michael S. Tsirkin | if (msix_enabled(&proxy->pci_dev))
|
103 | aba800a3 | Michael S. Tsirkin | msix_notify(&proxy->pci_dev, vector); |
104 | aba800a3 | Michael S. Tsirkin | else
|
105 | aba800a3 | Michael S. Tsirkin | qemu_set_irq(proxy->pci_dev.irq[0], proxy->vdev->isr & 1); |
106 | 53c25cea | Paul Brook | } |
107 | 53c25cea | Paul Brook | |
108 | ff24bd58 | Michael S. Tsirkin | static void virtio_pci_save_config(void * opaque, QEMUFile *f) |
109 | ff24bd58 | Michael S. Tsirkin | { |
110 | ff24bd58 | Michael S. Tsirkin | VirtIOPCIProxy *proxy = opaque; |
111 | ff24bd58 | Michael S. Tsirkin | pci_device_save(&proxy->pci_dev, f); |
112 | ff24bd58 | Michael S. Tsirkin | msix_save(&proxy->pci_dev, f); |
113 | ff24bd58 | Michael S. Tsirkin | if (msix_present(&proxy->pci_dev))
|
114 | ff24bd58 | Michael S. Tsirkin | qemu_put_be16(f, proxy->vdev->config_vector); |
115 | ff24bd58 | Michael S. Tsirkin | } |
116 | ff24bd58 | Michael S. Tsirkin | |
117 | ff24bd58 | Michael S. Tsirkin | static void virtio_pci_save_queue(void * opaque, int n, QEMUFile *f) |
118 | ff24bd58 | Michael S. Tsirkin | { |
119 | ff24bd58 | Michael S. Tsirkin | VirtIOPCIProxy *proxy = opaque; |
120 | ff24bd58 | Michael S. Tsirkin | if (msix_present(&proxy->pci_dev))
|
121 | ff24bd58 | Michael S. Tsirkin | qemu_put_be16(f, virtio_queue_vector(proxy->vdev, n)); |
122 | ff24bd58 | Michael S. Tsirkin | } |
123 | ff24bd58 | Michael S. Tsirkin | |
124 | ff24bd58 | Michael S. Tsirkin | static int virtio_pci_load_config(void * opaque, QEMUFile *f) |
125 | ff24bd58 | Michael S. Tsirkin | { |
126 | ff24bd58 | Michael S. Tsirkin | VirtIOPCIProxy *proxy = opaque; |
127 | ff24bd58 | Michael S. Tsirkin | int ret;
|
128 | ff24bd58 | Michael S. Tsirkin | ret = pci_device_load(&proxy->pci_dev, f); |
129 | e6da7680 | Michael S. Tsirkin | if (ret) {
|
130 | ff24bd58 | Michael S. Tsirkin | return ret;
|
131 | e6da7680 | Michael S. Tsirkin | } |
132 | ff24bd58 | Michael S. Tsirkin | msix_load(&proxy->pci_dev, f); |
133 | e6da7680 | Michael S. Tsirkin | if (msix_present(&proxy->pci_dev)) {
|
134 | ff24bd58 | Michael S. Tsirkin | qemu_get_be16s(f, &proxy->vdev->config_vector); |
135 | e6da7680 | Michael S. Tsirkin | } else {
|
136 | e6da7680 | Michael S. Tsirkin | proxy->vdev->config_vector = VIRTIO_NO_VECTOR; |
137 | e6da7680 | Michael S. Tsirkin | } |
138 | e6da7680 | Michael S. Tsirkin | if (proxy->vdev->config_vector != VIRTIO_NO_VECTOR) {
|
139 | e6da7680 | Michael S. Tsirkin | return msix_vector_use(&proxy->pci_dev, proxy->vdev->config_vector);
|
140 | e6da7680 | Michael S. Tsirkin | } |
141 | ff24bd58 | Michael S. Tsirkin | return 0; |
142 | ff24bd58 | Michael S. Tsirkin | } |
143 | ff24bd58 | Michael S. Tsirkin | |
144 | ff24bd58 | Michael S. Tsirkin | static int virtio_pci_load_queue(void * opaque, int n, QEMUFile *f) |
145 | ff24bd58 | Michael S. Tsirkin | { |
146 | ff24bd58 | Michael S. Tsirkin | VirtIOPCIProxy *proxy = opaque; |
147 | ff24bd58 | Michael S. Tsirkin | uint16_t vector; |
148 | e6da7680 | Michael S. Tsirkin | if (msix_present(&proxy->pci_dev)) {
|
149 | e6da7680 | Michael S. Tsirkin | qemu_get_be16s(f, &vector); |
150 | e6da7680 | Michael S. Tsirkin | } else {
|
151 | e6da7680 | Michael S. Tsirkin | vector = VIRTIO_NO_VECTOR; |
152 | e6da7680 | Michael S. Tsirkin | } |
153 | ff24bd58 | Michael S. Tsirkin | virtio_queue_set_vector(proxy->vdev, n, vector); |
154 | e6da7680 | Michael S. Tsirkin | if (vector != VIRTIO_NO_VECTOR) {
|
155 | e6da7680 | Michael S. Tsirkin | return msix_vector_use(&proxy->pci_dev, vector);
|
156 | e6da7680 | Michael S. Tsirkin | } |
157 | ff24bd58 | Michael S. Tsirkin | return 0; |
158 | ff24bd58 | Michael S. Tsirkin | } |
159 | ff24bd58 | Michael S. Tsirkin | |
160 | e489030d | Michael S. Tsirkin | static void virtio_pci_reset(DeviceState *d) |
161 | 7055e687 | Michael S. Tsirkin | { |
162 | e489030d | Michael S. Tsirkin | VirtIOPCIProxy *proxy = container_of(d, VirtIOPCIProxy, pci_dev.qdev); |
163 | 7055e687 | Michael S. Tsirkin | virtio_reset(proxy->vdev); |
164 | aba800a3 | Michael S. Tsirkin | msix_reset(&proxy->pci_dev); |
165 | 7055e687 | Michael S. Tsirkin | } |
166 | 7055e687 | Michael S. Tsirkin | |
167 | 53c25cea | Paul Brook | static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val) |
168 | 53c25cea | Paul Brook | { |
169 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = opaque; |
170 | 53c25cea | Paul Brook | VirtIODevice *vdev = proxy->vdev; |
171 | c227f099 | Anthony Liguori | target_phys_addr_t pa; |
172 | 53c25cea | Paul Brook | |
173 | 53c25cea | Paul Brook | switch (addr) {
|
174 | 53c25cea | Paul Brook | case VIRTIO_PCI_GUEST_FEATURES:
|
175 | 53c25cea | Paul Brook | /* Guest does not negotiate properly? We have to assume nothing. */
|
176 | 53c25cea | Paul Brook | if (val & (1 << VIRTIO_F_BAD_FEATURE)) { |
177 | 53c25cea | Paul Brook | if (vdev->bad_features)
|
178 | 53c25cea | Paul Brook | val = vdev->bad_features(vdev); |
179 | 53c25cea | Paul Brook | else
|
180 | 53c25cea | Paul Brook | val = 0;
|
181 | 53c25cea | Paul Brook | } |
182 | 53c25cea | Paul Brook | if (vdev->set_features)
|
183 | 53c25cea | Paul Brook | vdev->set_features(vdev, val); |
184 | 53c25cea | Paul Brook | vdev->features = val; |
185 | 53c25cea | Paul Brook | break;
|
186 | 53c25cea | Paul Brook | case VIRTIO_PCI_QUEUE_PFN:
|
187 | c227f099 | Anthony Liguori | pa = (target_phys_addr_t)val << VIRTIO_PCI_QUEUE_ADDR_SHIFT; |
188 | 7055e687 | Michael S. Tsirkin | if (pa == 0) |
189 | e489030d | Michael S. Tsirkin | virtio_pci_reset(&proxy->pci_dev.qdev); |
190 | 7055e687 | Michael S. Tsirkin | else
|
191 | 7055e687 | Michael S. Tsirkin | virtio_queue_set_addr(vdev, vdev->queue_sel, pa); |
192 | 53c25cea | Paul Brook | break;
|
193 | 53c25cea | Paul Brook | case VIRTIO_PCI_QUEUE_SEL:
|
194 | 53c25cea | Paul Brook | if (val < VIRTIO_PCI_QUEUE_MAX)
|
195 | 53c25cea | Paul Brook | vdev->queue_sel = val; |
196 | 53c25cea | Paul Brook | break;
|
197 | 53c25cea | Paul Brook | case VIRTIO_PCI_QUEUE_NOTIFY:
|
198 | 53c25cea | Paul Brook | virtio_queue_notify(vdev, val); |
199 | 53c25cea | Paul Brook | break;
|
200 | 53c25cea | Paul Brook | case VIRTIO_PCI_STATUS:
|
201 | 53c25cea | Paul Brook | vdev->status = val & 0xFF;
|
202 | 53c25cea | Paul Brook | if (vdev->status == 0) |
203 | e489030d | Michael S. Tsirkin | virtio_pci_reset(&proxy->pci_dev.qdev); |
204 | 53c25cea | Paul Brook | break;
|
205 | aba800a3 | Michael S. Tsirkin | case VIRTIO_MSI_CONFIG_VECTOR:
|
206 | aba800a3 | Michael S. Tsirkin | msix_vector_unuse(&proxy->pci_dev, vdev->config_vector); |
207 | aba800a3 | Michael S. Tsirkin | /* Make it possible for guest to discover an error took place. */
|
208 | aba800a3 | Michael S. Tsirkin | if (msix_vector_use(&proxy->pci_dev, val) < 0) |
209 | aba800a3 | Michael S. Tsirkin | val = VIRTIO_NO_VECTOR; |
210 | aba800a3 | Michael S. Tsirkin | vdev->config_vector = val; |
211 | aba800a3 | Michael S. Tsirkin | break;
|
212 | aba800a3 | Michael S. Tsirkin | case VIRTIO_MSI_QUEUE_VECTOR:
|
213 | aba800a3 | Michael S. Tsirkin | msix_vector_unuse(&proxy->pci_dev, |
214 | aba800a3 | Michael S. Tsirkin | virtio_queue_vector(vdev, vdev->queue_sel)); |
215 | aba800a3 | Michael S. Tsirkin | /* Make it possible for guest to discover an error took place. */
|
216 | aba800a3 | Michael S. Tsirkin | if (msix_vector_use(&proxy->pci_dev, val) < 0) |
217 | aba800a3 | Michael S. Tsirkin | val = VIRTIO_NO_VECTOR; |
218 | aba800a3 | Michael S. Tsirkin | virtio_queue_set_vector(vdev, vdev->queue_sel, val); |
219 | aba800a3 | Michael S. Tsirkin | break;
|
220 | aba800a3 | Michael S. Tsirkin | default:
|
221 | aba800a3 | Michael S. Tsirkin | fprintf(stderr, "%s: unexpected address 0x%x value 0x%x\n",
|
222 | aba800a3 | Michael S. Tsirkin | __func__, addr, val); |
223 | aba800a3 | Michael S. Tsirkin | break;
|
224 | 53c25cea | Paul Brook | } |
225 | 53c25cea | Paul Brook | } |
226 | 53c25cea | Paul Brook | |
227 | aba800a3 | Michael S. Tsirkin | static uint32_t virtio_ioport_read(VirtIOPCIProxy *proxy, uint32_t addr)
|
228 | 53c25cea | Paul Brook | { |
229 | 53c25cea | Paul Brook | VirtIODevice *vdev = proxy->vdev; |
230 | 53c25cea | Paul Brook | uint32_t ret = 0xFFFFFFFF;
|
231 | 53c25cea | Paul Brook | |
232 | 53c25cea | Paul Brook | switch (addr) {
|
233 | 53c25cea | Paul Brook | case VIRTIO_PCI_HOST_FEATURES:
|
234 | 53c25cea | Paul Brook | ret = vdev->get_features(vdev); |
235 | efeea6d0 | Mark McLoughlin | ret |= (1 << VIRTIO_F_NOTIFY_ON_EMPTY);
|
236 | efeea6d0 | Mark McLoughlin | ret |= (1 << VIRTIO_RING_F_INDIRECT_DESC);
|
237 | efeea6d0 | Mark McLoughlin | ret |= (1 << VIRTIO_F_BAD_FEATURE);
|
238 | 53c25cea | Paul Brook | break;
|
239 | 53c25cea | Paul Brook | case VIRTIO_PCI_GUEST_FEATURES:
|
240 | 53c25cea | Paul Brook | ret = vdev->features; |
241 | 53c25cea | Paul Brook | break;
|
242 | 53c25cea | Paul Brook | case VIRTIO_PCI_QUEUE_PFN:
|
243 | 53c25cea | Paul Brook | ret = virtio_queue_get_addr(vdev, vdev->queue_sel) |
244 | 53c25cea | Paul Brook | >> VIRTIO_PCI_QUEUE_ADDR_SHIFT; |
245 | 53c25cea | Paul Brook | break;
|
246 | 53c25cea | Paul Brook | case VIRTIO_PCI_QUEUE_NUM:
|
247 | 53c25cea | Paul Brook | ret = virtio_queue_get_num(vdev, vdev->queue_sel); |
248 | 53c25cea | Paul Brook | break;
|
249 | 53c25cea | Paul Brook | case VIRTIO_PCI_QUEUE_SEL:
|
250 | 53c25cea | Paul Brook | ret = vdev->queue_sel; |
251 | 53c25cea | Paul Brook | break;
|
252 | 53c25cea | Paul Brook | case VIRTIO_PCI_STATUS:
|
253 | 53c25cea | Paul Brook | ret = vdev->status; |
254 | 53c25cea | Paul Brook | break;
|
255 | 53c25cea | Paul Brook | case VIRTIO_PCI_ISR:
|
256 | 53c25cea | Paul Brook | /* reading from the ISR also clears it. */
|
257 | 53c25cea | Paul Brook | ret = vdev->isr; |
258 | 53c25cea | Paul Brook | vdev->isr = 0;
|
259 | 7055e687 | Michael S. Tsirkin | qemu_set_irq(proxy->pci_dev.irq[0], 0); |
260 | 53c25cea | Paul Brook | break;
|
261 | aba800a3 | Michael S. Tsirkin | case VIRTIO_MSI_CONFIG_VECTOR:
|
262 | aba800a3 | Michael S. Tsirkin | ret = vdev->config_vector; |
263 | aba800a3 | Michael S. Tsirkin | break;
|
264 | aba800a3 | Michael S. Tsirkin | case VIRTIO_MSI_QUEUE_VECTOR:
|
265 | aba800a3 | Michael S. Tsirkin | ret = virtio_queue_vector(vdev, vdev->queue_sel); |
266 | aba800a3 | Michael S. Tsirkin | break;
|
267 | 53c25cea | Paul Brook | default:
|
268 | 53c25cea | Paul Brook | break;
|
269 | 53c25cea | Paul Brook | } |
270 | 53c25cea | Paul Brook | |
271 | 53c25cea | Paul Brook | return ret;
|
272 | 53c25cea | Paul Brook | } |
273 | 53c25cea | Paul Brook | |
274 | 53c25cea | Paul Brook | static uint32_t virtio_pci_config_readb(void *opaque, uint32_t addr) |
275 | 53c25cea | Paul Brook | { |
276 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = opaque; |
277 | aba800a3 | Michael S. Tsirkin | uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); |
278 | aba800a3 | Michael S. Tsirkin | addr -= proxy->addr; |
279 | aba800a3 | Michael S. Tsirkin | if (addr < config)
|
280 | aba800a3 | Michael S. Tsirkin | return virtio_ioport_read(proxy, addr);
|
281 | aba800a3 | Michael S. Tsirkin | addr -= config; |
282 | 53c25cea | Paul Brook | return virtio_config_readb(proxy->vdev, addr);
|
283 | 53c25cea | Paul Brook | } |
284 | 53c25cea | Paul Brook | |
285 | 53c25cea | Paul Brook | static uint32_t virtio_pci_config_readw(void *opaque, uint32_t addr) |
286 | 53c25cea | Paul Brook | { |
287 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = opaque; |
288 | aba800a3 | Michael S. Tsirkin | uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); |
289 | aba800a3 | Michael S. Tsirkin | addr -= proxy->addr; |
290 | aba800a3 | Michael S. Tsirkin | if (addr < config)
|
291 | aba800a3 | Michael S. Tsirkin | return virtio_ioport_read(proxy, addr);
|
292 | aba800a3 | Michael S. Tsirkin | addr -= config; |
293 | 53c25cea | Paul Brook | return virtio_config_readw(proxy->vdev, addr);
|
294 | 53c25cea | Paul Brook | } |
295 | 53c25cea | Paul Brook | |
296 | 53c25cea | Paul Brook | static uint32_t virtio_pci_config_readl(void *opaque, uint32_t addr) |
297 | 53c25cea | Paul Brook | { |
298 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = opaque; |
299 | aba800a3 | Michael S. Tsirkin | uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); |
300 | aba800a3 | Michael S. Tsirkin | addr -= proxy->addr; |
301 | aba800a3 | Michael S. Tsirkin | if (addr < config)
|
302 | aba800a3 | Michael S. Tsirkin | return virtio_ioport_read(proxy, addr);
|
303 | aba800a3 | Michael S. Tsirkin | addr -= config; |
304 | 53c25cea | Paul Brook | return virtio_config_readl(proxy->vdev, addr);
|
305 | 53c25cea | Paul Brook | } |
306 | 53c25cea | Paul Brook | |
307 | 53c25cea | Paul Brook | static void virtio_pci_config_writeb(void *opaque, uint32_t addr, uint32_t val) |
308 | 53c25cea | Paul Brook | { |
309 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = opaque; |
310 | aba800a3 | Michael S. Tsirkin | uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); |
311 | aba800a3 | Michael S. Tsirkin | addr -= proxy->addr; |
312 | aba800a3 | Michael S. Tsirkin | if (addr < config) {
|
313 | aba800a3 | Michael S. Tsirkin | virtio_ioport_write(proxy, addr, val); |
314 | aba800a3 | Michael S. Tsirkin | return;
|
315 | aba800a3 | Michael S. Tsirkin | } |
316 | aba800a3 | Michael S. Tsirkin | addr -= config; |
317 | 53c25cea | Paul Brook | virtio_config_writeb(proxy->vdev, addr, val); |
318 | 53c25cea | Paul Brook | } |
319 | 53c25cea | Paul Brook | |
320 | 53c25cea | Paul Brook | static void virtio_pci_config_writew(void *opaque, uint32_t addr, uint32_t val) |
321 | 53c25cea | Paul Brook | { |
322 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = opaque; |
323 | aba800a3 | Michael S. Tsirkin | uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); |
324 | aba800a3 | Michael S. Tsirkin | addr -= proxy->addr; |
325 | aba800a3 | Michael S. Tsirkin | if (addr < config) {
|
326 | aba800a3 | Michael S. Tsirkin | virtio_ioport_write(proxy, addr, val); |
327 | aba800a3 | Michael S. Tsirkin | return;
|
328 | aba800a3 | Michael S. Tsirkin | } |
329 | aba800a3 | Michael S. Tsirkin | addr -= config; |
330 | 53c25cea | Paul Brook | virtio_config_writew(proxy->vdev, addr, val); |
331 | 53c25cea | Paul Brook | } |
332 | 53c25cea | Paul Brook | |
333 | 53c25cea | Paul Brook | static void virtio_pci_config_writel(void *opaque, uint32_t addr, uint32_t val) |
334 | 53c25cea | Paul Brook | { |
335 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = opaque; |
336 | aba800a3 | Michael S. Tsirkin | uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); |
337 | aba800a3 | Michael S. Tsirkin | addr -= proxy->addr; |
338 | aba800a3 | Michael S. Tsirkin | if (addr < config) {
|
339 | aba800a3 | Michael S. Tsirkin | virtio_ioport_write(proxy, addr, val); |
340 | aba800a3 | Michael S. Tsirkin | return;
|
341 | aba800a3 | Michael S. Tsirkin | } |
342 | aba800a3 | Michael S. Tsirkin | addr -= config; |
343 | 53c25cea | Paul Brook | virtio_config_writel(proxy->vdev, addr, val); |
344 | 53c25cea | Paul Brook | } |
345 | 53c25cea | Paul Brook | |
346 | 53c25cea | Paul Brook | static void virtio_map(PCIDevice *pci_dev, int region_num, |
347 | 53c25cea | Paul Brook | uint32_t addr, uint32_t size, int type)
|
348 | 53c25cea | Paul Brook | { |
349 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = container_of(pci_dev, VirtIOPCIProxy, pci_dev); |
350 | 53c25cea | Paul Brook | VirtIODevice *vdev = proxy->vdev; |
351 | aba800a3 | Michael S. Tsirkin | unsigned config_len = VIRTIO_PCI_REGION_SIZE(pci_dev) + vdev->config_len;
|
352 | 53c25cea | Paul Brook | |
353 | 53c25cea | Paul Brook | proxy->addr = addr; |
354 | 53c25cea | Paul Brook | |
355 | aba800a3 | Michael S. Tsirkin | register_ioport_write(addr, config_len, 1, virtio_pci_config_writeb, proxy);
|
356 | aba800a3 | Michael S. Tsirkin | register_ioport_write(addr, config_len, 2, virtio_pci_config_writew, proxy);
|
357 | aba800a3 | Michael S. Tsirkin | register_ioport_write(addr, config_len, 4, virtio_pci_config_writel, proxy);
|
358 | aba800a3 | Michael S. Tsirkin | register_ioport_read(addr, config_len, 1, virtio_pci_config_readb, proxy);
|
359 | aba800a3 | Michael S. Tsirkin | register_ioport_read(addr, config_len, 2, virtio_pci_config_readw, proxy);
|
360 | aba800a3 | Michael S. Tsirkin | register_ioport_read(addr, config_len, 4, virtio_pci_config_readl, proxy);
|
361 | 53c25cea | Paul Brook | |
362 | aba800a3 | Michael S. Tsirkin | if (vdev->config_len)
|
363 | 53c25cea | Paul Brook | vdev->get_config(vdev, vdev->config); |
364 | aba800a3 | Michael S. Tsirkin | } |
365 | aba800a3 | Michael S. Tsirkin | |
366 | aba800a3 | Michael S. Tsirkin | static void virtio_write_config(PCIDevice *pci_dev, uint32_t address, |
367 | aba800a3 | Michael S. Tsirkin | uint32_t val, int len)
|
368 | aba800a3 | Michael S. Tsirkin | { |
369 | ed757e14 | Yan Vugenfirer | VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); |
370 | ed757e14 | Yan Vugenfirer | |
371 | ed757e14 | Yan Vugenfirer | if (PCI_COMMAND == address) {
|
372 | ed757e14 | Yan Vugenfirer | if (!(val & PCI_COMMAND_MASTER)) {
|
373 | ed757e14 | Yan Vugenfirer | proxy->vdev->status &= !VIRTIO_CONFIG_S_DRIVER_OK; |
374 | ed757e14 | Yan Vugenfirer | } |
375 | ed757e14 | Yan Vugenfirer | } |
376 | ed757e14 | Yan Vugenfirer | |
377 | aba800a3 | Michael S. Tsirkin | pci_default_write_config(pci_dev, address, val, len); |
378 | 85352471 | Michael S. Tsirkin | msix_write_config(pci_dev, address, val, len); |
379 | 53c25cea | Paul Brook | } |
380 | 53c25cea | Paul Brook | |
381 | 53c25cea | Paul Brook | static const VirtIOBindings virtio_pci_bindings = { |
382 | ff24bd58 | Michael S. Tsirkin | .notify = virtio_pci_notify, |
383 | ff24bd58 | Michael S. Tsirkin | .save_config = virtio_pci_save_config, |
384 | ff24bd58 | Michael S. Tsirkin | .load_config = virtio_pci_load_config, |
385 | ff24bd58 | Michael S. Tsirkin | .save_queue = virtio_pci_save_queue, |
386 | ff24bd58 | Michael S. Tsirkin | .load_queue = virtio_pci_load_queue, |
387 | 53c25cea | Paul Brook | }; |
388 | 53c25cea | Paul Brook | |
389 | 53c25cea | Paul Brook | static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev, |
390 | 53c25cea | Paul Brook | uint16_t vendor, uint16_t device, |
391 | 53c25cea | Paul Brook | uint16_t class_code, uint8_t pif) |
392 | 53c25cea | Paul Brook | { |
393 | 53c25cea | Paul Brook | uint8_t *config; |
394 | 53c25cea | Paul Brook | uint32_t size; |
395 | 53c25cea | Paul Brook | |
396 | 53c25cea | Paul Brook | proxy->vdev = vdev; |
397 | 53c25cea | Paul Brook | |
398 | 53c25cea | Paul Brook | config = proxy->pci_dev.config; |
399 | 53c25cea | Paul Brook | pci_config_set_vendor_id(config, vendor); |
400 | 53c25cea | Paul Brook | pci_config_set_device_id(config, device); |
401 | 53c25cea | Paul Brook | |
402 | 53c25cea | Paul Brook | config[0x08] = VIRTIO_PCI_ABI_VERSION;
|
403 | 53c25cea | Paul Brook | |
404 | 53c25cea | Paul Brook | config[0x09] = pif;
|
405 | 53c25cea | Paul Brook | pci_config_set_class(config, class_code); |
406 | 53c25cea | Paul Brook | config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; |
407 | 53c25cea | Paul Brook | |
408 | 53c25cea | Paul Brook | config[0x2c] = vendor & 0xFF; |
409 | 53c25cea | Paul Brook | config[0x2d] = (vendor >> 8) & 0xFF; |
410 | 53c25cea | Paul Brook | config[0x2e] = vdev->device_id & 0xFF; |
411 | 53c25cea | Paul Brook | config[0x2f] = (vdev->device_id >> 8) & 0xFF; |
412 | 53c25cea | Paul Brook | |
413 | 53c25cea | Paul Brook | config[0x3d] = 1; |
414 | 53c25cea | Paul Brook | |
415 | 5a1fc5e8 | Michael S. Tsirkin | if (vdev->nvectors && !msix_init(&proxy->pci_dev, vdev->nvectors, 1, 0)) { |
416 | aba800a3 | Michael S. Tsirkin | pci_register_bar(&proxy->pci_dev, 1,
|
417 | aba800a3 | Michael S. Tsirkin | msix_bar_size(&proxy->pci_dev), |
418 | aba800a3 | Michael S. Tsirkin | PCI_ADDRESS_SPACE_MEM, |
419 | aba800a3 | Michael S. Tsirkin | msix_mmio_map); |
420 | aba800a3 | Michael S. Tsirkin | } else
|
421 | aba800a3 | Michael S. Tsirkin | vdev->nvectors = 0;
|
422 | aba800a3 | Michael S. Tsirkin | |
423 | ed757e14 | Yan Vugenfirer | proxy->pci_dev.config_write = virtio_write_config; |
424 | ed757e14 | Yan Vugenfirer | |
425 | aba800a3 | Michael S. Tsirkin | size = VIRTIO_PCI_REGION_SIZE(&proxy->pci_dev) + vdev->config_len; |
426 | 53c25cea | Paul Brook | if (size & (size-1)) |
427 | 53c25cea | Paul Brook | size = 1 << qemu_fls(size);
|
428 | 53c25cea | Paul Brook | |
429 | 28c2c264 | Avi Kivity | pci_register_bar(&proxy->pci_dev, 0, size, PCI_ADDRESS_SPACE_IO,
|
430 | 53c25cea | Paul Brook | virtio_map); |
431 | 53c25cea | Paul Brook | |
432 | 53c25cea | Paul Brook | virtio_bind_device(vdev, &virtio_pci_bindings, proxy); |
433 | 53c25cea | Paul Brook | } |
434 | 53c25cea | Paul Brook | |
435 | 81a322d4 | Gerd Hoffmann | static int virtio_blk_init_pci(PCIDevice *pci_dev) |
436 | 53c25cea | Paul Brook | { |
437 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); |
438 | 53c25cea | Paul Brook | VirtIODevice *vdev; |
439 | 53c25cea | Paul Brook | |
440 | ab73ff29 | Gerd Hoffmann | if (proxy->class_code != PCI_CLASS_STORAGE_SCSI &&
|
441 | ab73ff29 | Gerd Hoffmann | proxy->class_code != PCI_CLASS_STORAGE_OTHER) |
442 | ab73ff29 | Gerd Hoffmann | proxy->class_code = PCI_CLASS_STORAGE_SCSI; |
443 | 53c25cea | Paul Brook | |
444 | d176c495 | Gerd Hoffmann | if (!proxy->dinfo) {
|
445 | 84fc5589 | Gerd Hoffmann | qemu_error("virtio-blk-pci: drive property not set\n");
|
446 | 81a322d4 | Gerd Hoffmann | return -1; |
447 | d176c495 | Gerd Hoffmann | } |
448 | d176c495 | Gerd Hoffmann | vdev = virtio_blk_init(&pci_dev->qdev, proxy->dinfo); |
449 | 177539e0 | Gerd Hoffmann | vdev->nvectors = proxy->nvectors; |
450 | 53c25cea | Paul Brook | virtio_init_pci(proxy, vdev, |
451 | 53c25cea | Paul Brook | PCI_VENDOR_ID_REDHAT_QUMRANET, |
452 | 85c2c735 | Mark McLoughlin | PCI_DEVICE_ID_VIRTIO_BLOCK, |
453 | 85c2c735 | Mark McLoughlin | proxy->class_code, 0x00);
|
454 | 177539e0 | Gerd Hoffmann | /* make the actual value visible */
|
455 | 177539e0 | Gerd Hoffmann | proxy->nvectors = vdev->nvectors; |
456 | 81a322d4 | Gerd Hoffmann | return 0; |
457 | 21d58b57 | Mark McLoughlin | } |
458 | 21d58b57 | Mark McLoughlin | |
459 | 0f457d91 | Michael S. Tsirkin | static int virtio_exit_pci(PCIDevice *pci_dev) |
460 | 0f457d91 | Michael S. Tsirkin | { |
461 | 0f457d91 | Michael S. Tsirkin | return msix_uninit(pci_dev);
|
462 | 0f457d91 | Michael S. Tsirkin | } |
463 | 0f457d91 | Michael S. Tsirkin | |
464 | 56a14938 | Gerd Hoffmann | static int virtio_blk_exit_pci(PCIDevice *pci_dev) |
465 | 56a14938 | Gerd Hoffmann | { |
466 | 56a14938 | Gerd Hoffmann | VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); |
467 | 56a14938 | Gerd Hoffmann | |
468 | 56a14938 | Gerd Hoffmann | drive_uninit(proxy->dinfo); |
469 | 0f457d91 | Michael S. Tsirkin | return virtio_exit_pci(pci_dev);
|
470 | 56a14938 | Gerd Hoffmann | } |
471 | 56a14938 | Gerd Hoffmann | |
472 | 81a322d4 | Gerd Hoffmann | static int virtio_console_init_pci(PCIDevice *pci_dev) |
473 | 21d58b57 | Mark McLoughlin | { |
474 | d6beee99 | Gerd Hoffmann | VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); |
475 | 85c2c735 | Mark McLoughlin | VirtIODevice *vdev; |
476 | 85c2c735 | Mark McLoughlin | |
477 | d6beee99 | Gerd Hoffmann | if (proxy->class_code != PCI_CLASS_COMMUNICATION_OTHER &&
|
478 | d6beee99 | Gerd Hoffmann | proxy->class_code != PCI_CLASS_DISPLAY_OTHER && /* qemu 0.10 */
|
479 | d6beee99 | Gerd Hoffmann | proxy->class_code != PCI_CLASS_OTHERS) /* qemu-kvm */
|
480 | d6beee99 | Gerd Hoffmann | proxy->class_code = PCI_CLASS_COMMUNICATION_OTHER; |
481 | d6beee99 | Gerd Hoffmann | |
482 | 85c2c735 | Mark McLoughlin | vdev = virtio_console_init(&pci_dev->qdev); |
483 | 25fe3654 | Amit Shah | if (!vdev) {
|
484 | 25fe3654 | Amit Shah | return -1; |
485 | 25fe3654 | Amit Shah | } |
486 | 85c2c735 | Mark McLoughlin | virtio_init_pci(proxy, vdev, |
487 | 85c2c735 | Mark McLoughlin | PCI_VENDOR_ID_REDHAT_QUMRANET, |
488 | 85c2c735 | Mark McLoughlin | PCI_DEVICE_ID_VIRTIO_CONSOLE, |
489 | 85c2c735 | Mark McLoughlin | proxy->class_code, 0x00);
|
490 | 81a322d4 | Gerd Hoffmann | return 0; |
491 | 53c25cea | Paul Brook | } |
492 | 53c25cea | Paul Brook | |
493 | 81a322d4 | Gerd Hoffmann | static int virtio_net_init_pci(PCIDevice *pci_dev) |
494 | 53c25cea | Paul Brook | { |
495 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); |
496 | 53c25cea | Paul Brook | VirtIODevice *vdev; |
497 | 53c25cea | Paul Brook | |
498 | 97b15621 | Gerd Hoffmann | vdev = virtio_net_init(&pci_dev->qdev, &proxy->nic); |
499 | a1e0fea5 | Gerd Hoffmann | |
500 | 97b15621 | Gerd Hoffmann | vdev->nvectors = proxy->nvectors; |
501 | 53c25cea | Paul Brook | virtio_init_pci(proxy, vdev, |
502 | 53c25cea | Paul Brook | PCI_VENDOR_ID_REDHAT_QUMRANET, |
503 | 53c25cea | Paul Brook | PCI_DEVICE_ID_VIRTIO_NET, |
504 | 53c25cea | Paul Brook | PCI_CLASS_NETWORK_ETHERNET, |
505 | 53c25cea | Paul Brook | 0x00);
|
506 | a1e0fea5 | Gerd Hoffmann | |
507 | a1e0fea5 | Gerd Hoffmann | /* make the actual value visible */
|
508 | a1e0fea5 | Gerd Hoffmann | proxy->nvectors = vdev->nvectors; |
509 | 97b15621 | Gerd Hoffmann | |
510 | 97b15621 | Gerd Hoffmann | if (!pci_dev->qdev.hotplugged) {
|
511 | 97b15621 | Gerd Hoffmann | static int loaded = 0; |
512 | 97b15621 | Gerd Hoffmann | if (!loaded) {
|
513 | 97b15621 | Gerd Hoffmann | rom_add_option("pxe-virtio.bin");
|
514 | 97b15621 | Gerd Hoffmann | loaded = 1;
|
515 | 97b15621 | Gerd Hoffmann | } |
516 | 97b15621 | Gerd Hoffmann | } |
517 | 81a322d4 | Gerd Hoffmann | return 0; |
518 | 53c25cea | Paul Brook | } |
519 | 53c25cea | Paul Brook | |
520 | 97b15621 | Gerd Hoffmann | static int virtio_net_exit_pci(PCIDevice *pci_dev) |
521 | 97b15621 | Gerd Hoffmann | { |
522 | 97b15621 | Gerd Hoffmann | VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); |
523 | 97b15621 | Gerd Hoffmann | |
524 | 97b15621 | Gerd Hoffmann | virtio_net_exit(proxy->vdev); |
525 | 97b15621 | Gerd Hoffmann | return virtio_exit_pci(pci_dev);
|
526 | 97b15621 | Gerd Hoffmann | } |
527 | 97b15621 | Gerd Hoffmann | |
528 | 81a322d4 | Gerd Hoffmann | static int virtio_balloon_init_pci(PCIDevice *pci_dev) |
529 | 53c25cea | Paul Brook | { |
530 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); |
531 | 53c25cea | Paul Brook | VirtIODevice *vdev; |
532 | 53c25cea | Paul Brook | |
533 | 53c25cea | Paul Brook | vdev = virtio_balloon_init(&pci_dev->qdev); |
534 | 53c25cea | Paul Brook | virtio_init_pci(proxy, vdev, |
535 | 53c25cea | Paul Brook | PCI_VENDOR_ID_REDHAT_QUMRANET, |
536 | 53c25cea | Paul Brook | PCI_DEVICE_ID_VIRTIO_BALLOON, |
537 | 53c25cea | Paul Brook | PCI_CLASS_MEMORY_RAM, |
538 | 53c25cea | Paul Brook | 0x00);
|
539 | 81a322d4 | Gerd Hoffmann | return 0; |
540 | 53c25cea | Paul Brook | } |
541 | 53c25cea | Paul Brook | |
542 | 0aab0d3a | Gerd Hoffmann | static PCIDeviceInfo virtio_info[] = {
|
543 | 0aab0d3a | Gerd Hoffmann | { |
544 | 0aab0d3a | Gerd Hoffmann | .qdev.name = "virtio-blk-pci",
|
545 | 0aab0d3a | Gerd Hoffmann | .qdev.size = sizeof(VirtIOPCIProxy),
|
546 | 0aab0d3a | Gerd Hoffmann | .init = virtio_blk_init_pci, |
547 | 56a14938 | Gerd Hoffmann | .exit = virtio_blk_exit_pci, |
548 | ab73ff29 | Gerd Hoffmann | .qdev.props = (Property[]) { |
549 | 72c61d0b | Gerd Hoffmann | DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0), |
550 | 72c61d0b | Gerd Hoffmann | DEFINE_PROP_DRIVE("drive", VirtIOPCIProxy, dinfo),
|
551 | 177539e0 | Gerd Hoffmann | DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2), |
552 | 72c61d0b | Gerd Hoffmann | DEFINE_PROP_END_OF_LIST(), |
553 | ab73ff29 | Gerd Hoffmann | }, |
554 | e489030d | Michael S. Tsirkin | .qdev.reset = virtio_pci_reset, |
555 | 0aab0d3a | Gerd Hoffmann | },{ |
556 | a1e0fea5 | Gerd Hoffmann | .qdev.name = "virtio-net-pci",
|
557 | a1e0fea5 | Gerd Hoffmann | .qdev.size = sizeof(VirtIOPCIProxy),
|
558 | a1e0fea5 | Gerd Hoffmann | .init = virtio_net_init_pci, |
559 | 97b15621 | Gerd Hoffmann | .exit = virtio_net_exit_pci, |
560 | a1e0fea5 | Gerd Hoffmann | .qdev.props = (Property[]) { |
561 | 97b15621 | Gerd Hoffmann | DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3), |
562 | 97b15621 | Gerd Hoffmann | DEFINE_NIC_PROPERTIES(VirtIOPCIProxy, nic), |
563 | 72c61d0b | Gerd Hoffmann | DEFINE_PROP_END_OF_LIST(), |
564 | a1e0fea5 | Gerd Hoffmann | }, |
565 | e489030d | Michael S. Tsirkin | .qdev.reset = virtio_pci_reset, |
566 | 0aab0d3a | Gerd Hoffmann | },{ |
567 | 0aab0d3a | Gerd Hoffmann | .qdev.name = "virtio-console-pci",
|
568 | 0aab0d3a | Gerd Hoffmann | .qdev.size = sizeof(VirtIOPCIProxy),
|
569 | 0aab0d3a | Gerd Hoffmann | .init = virtio_console_init_pci, |
570 | 0f457d91 | Michael S. Tsirkin | .exit = virtio_exit_pci, |
571 | d6beee99 | Gerd Hoffmann | .qdev.props = (Property[]) { |
572 | 72c61d0b | Gerd Hoffmann | DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0), |
573 | 72c61d0b | Gerd Hoffmann | DEFINE_PROP_END_OF_LIST(), |
574 | d6beee99 | Gerd Hoffmann | }, |
575 | e489030d | Michael S. Tsirkin | .qdev.reset = virtio_pci_reset, |
576 | 0aab0d3a | Gerd Hoffmann | },{ |
577 | 0aab0d3a | Gerd Hoffmann | .qdev.name = "virtio-balloon-pci",
|
578 | 0aab0d3a | Gerd Hoffmann | .qdev.size = sizeof(VirtIOPCIProxy),
|
579 | 0aab0d3a | Gerd Hoffmann | .init = virtio_balloon_init_pci, |
580 | 0f457d91 | Michael S. Tsirkin | .exit = virtio_exit_pci, |
581 | e489030d | Michael S. Tsirkin | .qdev.reset = virtio_pci_reset, |
582 | 0aab0d3a | Gerd Hoffmann | },{ |
583 | 0aab0d3a | Gerd Hoffmann | /* end of list */
|
584 | 0aab0d3a | Gerd Hoffmann | } |
585 | 0aab0d3a | Gerd Hoffmann | }; |
586 | 0aab0d3a | Gerd Hoffmann | |
587 | 53c25cea | Paul Brook | static void virtio_pci_register_devices(void) |
588 | 53c25cea | Paul Brook | { |
589 | 0aab0d3a | Gerd Hoffmann | pci_qdev_register_many(virtio_info); |
590 | 53c25cea | Paul Brook | } |
591 | 53c25cea | Paul Brook | |
592 | 53c25cea | Paul Brook | device_init(virtio_pci_register_devices) |