root / hw / virtio-pci.c @ a15fdf86
History | View | Annotate | Download (18 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 | 1b8e9b27 | Michael S. Tsirkin | if (pa == 0) { |
189 | 1b8e9b27 | Michael S. Tsirkin | virtio_reset(proxy->vdev); |
190 | 1b8e9b27 | Michael S. Tsirkin | msix_unuse_all_vectors(&proxy->pci_dev); |
191 | 1b8e9b27 | Michael S. Tsirkin | } |
192 | 7055e687 | Michael S. Tsirkin | else
|
193 | 7055e687 | Michael S. Tsirkin | virtio_queue_set_addr(vdev, vdev->queue_sel, pa); |
194 | 53c25cea | Paul Brook | break;
|
195 | 53c25cea | Paul Brook | case VIRTIO_PCI_QUEUE_SEL:
|
196 | 53c25cea | Paul Brook | if (val < VIRTIO_PCI_QUEUE_MAX)
|
197 | 53c25cea | Paul Brook | vdev->queue_sel = val; |
198 | 53c25cea | Paul Brook | break;
|
199 | 53c25cea | Paul Brook | case VIRTIO_PCI_QUEUE_NOTIFY:
|
200 | 53c25cea | Paul Brook | virtio_queue_notify(vdev, val); |
201 | 53c25cea | Paul Brook | break;
|
202 | 53c25cea | Paul Brook | case VIRTIO_PCI_STATUS:
|
203 | 53c25cea | Paul Brook | vdev->status = val & 0xFF;
|
204 | 1b8e9b27 | Michael S. Tsirkin | if (vdev->status == 0) { |
205 | 1b8e9b27 | Michael S. Tsirkin | virtio_reset(proxy->vdev); |
206 | 1b8e9b27 | Michael S. Tsirkin | msix_unuse_all_vectors(&proxy->pci_dev); |
207 | 1b8e9b27 | Michael S. Tsirkin | } |
208 | 53c25cea | Paul Brook | break;
|
209 | aba800a3 | Michael S. Tsirkin | case VIRTIO_MSI_CONFIG_VECTOR:
|
210 | aba800a3 | Michael S. Tsirkin | msix_vector_unuse(&proxy->pci_dev, vdev->config_vector); |
211 | aba800a3 | Michael S. Tsirkin | /* Make it possible for guest to discover an error took place. */
|
212 | aba800a3 | Michael S. Tsirkin | if (msix_vector_use(&proxy->pci_dev, val) < 0) |
213 | aba800a3 | Michael S. Tsirkin | val = VIRTIO_NO_VECTOR; |
214 | aba800a3 | Michael S. Tsirkin | vdev->config_vector = val; |
215 | aba800a3 | Michael S. Tsirkin | break;
|
216 | aba800a3 | Michael S. Tsirkin | case VIRTIO_MSI_QUEUE_VECTOR:
|
217 | aba800a3 | Michael S. Tsirkin | msix_vector_unuse(&proxy->pci_dev, |
218 | aba800a3 | Michael S. Tsirkin | virtio_queue_vector(vdev, vdev->queue_sel)); |
219 | aba800a3 | Michael S. Tsirkin | /* Make it possible for guest to discover an error took place. */
|
220 | aba800a3 | Michael S. Tsirkin | if (msix_vector_use(&proxy->pci_dev, val) < 0) |
221 | aba800a3 | Michael S. Tsirkin | val = VIRTIO_NO_VECTOR; |
222 | aba800a3 | Michael S. Tsirkin | virtio_queue_set_vector(vdev, vdev->queue_sel, val); |
223 | aba800a3 | Michael S. Tsirkin | break;
|
224 | aba800a3 | Michael S. Tsirkin | default:
|
225 | aba800a3 | Michael S. Tsirkin | fprintf(stderr, "%s: unexpected address 0x%x value 0x%x\n",
|
226 | aba800a3 | Michael S. Tsirkin | __func__, addr, val); |
227 | aba800a3 | Michael S. Tsirkin | break;
|
228 | 53c25cea | Paul Brook | } |
229 | 53c25cea | Paul Brook | } |
230 | 53c25cea | Paul Brook | |
231 | aba800a3 | Michael S. Tsirkin | static uint32_t virtio_ioport_read(VirtIOPCIProxy *proxy, uint32_t addr)
|
232 | 53c25cea | Paul Brook | { |
233 | 53c25cea | Paul Brook | VirtIODevice *vdev = proxy->vdev; |
234 | 53c25cea | Paul Brook | uint32_t ret = 0xFFFFFFFF;
|
235 | 53c25cea | Paul Brook | |
236 | 53c25cea | Paul Brook | switch (addr) {
|
237 | 53c25cea | Paul Brook | case VIRTIO_PCI_HOST_FEATURES:
|
238 | 53c25cea | Paul Brook | ret = vdev->get_features(vdev); |
239 | efeea6d0 | Mark McLoughlin | ret |= (1 << VIRTIO_F_NOTIFY_ON_EMPTY);
|
240 | efeea6d0 | Mark McLoughlin | ret |= (1 << VIRTIO_RING_F_INDIRECT_DESC);
|
241 | efeea6d0 | Mark McLoughlin | ret |= (1 << VIRTIO_F_BAD_FEATURE);
|
242 | 53c25cea | Paul Brook | break;
|
243 | 53c25cea | Paul Brook | case VIRTIO_PCI_GUEST_FEATURES:
|
244 | 53c25cea | Paul Brook | ret = vdev->features; |
245 | 53c25cea | Paul Brook | break;
|
246 | 53c25cea | Paul Brook | case VIRTIO_PCI_QUEUE_PFN:
|
247 | 53c25cea | Paul Brook | ret = virtio_queue_get_addr(vdev, vdev->queue_sel) |
248 | 53c25cea | Paul Brook | >> VIRTIO_PCI_QUEUE_ADDR_SHIFT; |
249 | 53c25cea | Paul Brook | break;
|
250 | 53c25cea | Paul Brook | case VIRTIO_PCI_QUEUE_NUM:
|
251 | 53c25cea | Paul Brook | ret = virtio_queue_get_num(vdev, vdev->queue_sel); |
252 | 53c25cea | Paul Brook | break;
|
253 | 53c25cea | Paul Brook | case VIRTIO_PCI_QUEUE_SEL:
|
254 | 53c25cea | Paul Brook | ret = vdev->queue_sel; |
255 | 53c25cea | Paul Brook | break;
|
256 | 53c25cea | Paul Brook | case VIRTIO_PCI_STATUS:
|
257 | 53c25cea | Paul Brook | ret = vdev->status; |
258 | 53c25cea | Paul Brook | break;
|
259 | 53c25cea | Paul Brook | case VIRTIO_PCI_ISR:
|
260 | 53c25cea | Paul Brook | /* reading from the ISR also clears it. */
|
261 | 53c25cea | Paul Brook | ret = vdev->isr; |
262 | 53c25cea | Paul Brook | vdev->isr = 0;
|
263 | 7055e687 | Michael S. Tsirkin | qemu_set_irq(proxy->pci_dev.irq[0], 0); |
264 | 53c25cea | Paul Brook | break;
|
265 | aba800a3 | Michael S. Tsirkin | case VIRTIO_MSI_CONFIG_VECTOR:
|
266 | aba800a3 | Michael S. Tsirkin | ret = vdev->config_vector; |
267 | aba800a3 | Michael S. Tsirkin | break;
|
268 | aba800a3 | Michael S. Tsirkin | case VIRTIO_MSI_QUEUE_VECTOR:
|
269 | aba800a3 | Michael S. Tsirkin | ret = virtio_queue_vector(vdev, vdev->queue_sel); |
270 | aba800a3 | Michael S. Tsirkin | break;
|
271 | 53c25cea | Paul Brook | default:
|
272 | 53c25cea | Paul Brook | break;
|
273 | 53c25cea | Paul Brook | } |
274 | 53c25cea | Paul Brook | |
275 | 53c25cea | Paul Brook | return ret;
|
276 | 53c25cea | Paul Brook | } |
277 | 53c25cea | Paul Brook | |
278 | 53c25cea | Paul Brook | static uint32_t virtio_pci_config_readb(void *opaque, uint32_t addr) |
279 | 53c25cea | Paul Brook | { |
280 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = opaque; |
281 | aba800a3 | Michael S. Tsirkin | uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); |
282 | aba800a3 | Michael S. Tsirkin | addr -= proxy->addr; |
283 | aba800a3 | Michael S. Tsirkin | if (addr < config)
|
284 | aba800a3 | Michael S. Tsirkin | return virtio_ioport_read(proxy, addr);
|
285 | aba800a3 | Michael S. Tsirkin | addr -= config; |
286 | 53c25cea | Paul Brook | return virtio_config_readb(proxy->vdev, addr);
|
287 | 53c25cea | Paul Brook | } |
288 | 53c25cea | Paul Brook | |
289 | 53c25cea | Paul Brook | static uint32_t virtio_pci_config_readw(void *opaque, uint32_t addr) |
290 | 53c25cea | Paul Brook | { |
291 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = opaque; |
292 | aba800a3 | Michael S. Tsirkin | uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); |
293 | aba800a3 | Michael S. Tsirkin | addr -= proxy->addr; |
294 | aba800a3 | Michael S. Tsirkin | if (addr < config)
|
295 | aba800a3 | Michael S. Tsirkin | return virtio_ioport_read(proxy, addr);
|
296 | aba800a3 | Michael S. Tsirkin | addr -= config; |
297 | 53c25cea | Paul Brook | return virtio_config_readw(proxy->vdev, addr);
|
298 | 53c25cea | Paul Brook | } |
299 | 53c25cea | Paul Brook | |
300 | 53c25cea | Paul Brook | static uint32_t virtio_pci_config_readl(void *opaque, uint32_t addr) |
301 | 53c25cea | Paul Brook | { |
302 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = opaque; |
303 | aba800a3 | Michael S. Tsirkin | uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); |
304 | aba800a3 | Michael S. Tsirkin | addr -= proxy->addr; |
305 | aba800a3 | Michael S. Tsirkin | if (addr < config)
|
306 | aba800a3 | Michael S. Tsirkin | return virtio_ioport_read(proxy, addr);
|
307 | aba800a3 | Michael S. Tsirkin | addr -= config; |
308 | 53c25cea | Paul Brook | return virtio_config_readl(proxy->vdev, addr);
|
309 | 53c25cea | Paul Brook | } |
310 | 53c25cea | Paul Brook | |
311 | 53c25cea | Paul Brook | static void virtio_pci_config_writeb(void *opaque, uint32_t addr, uint32_t val) |
312 | 53c25cea | Paul Brook | { |
313 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = opaque; |
314 | aba800a3 | Michael S. Tsirkin | uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); |
315 | aba800a3 | Michael S. Tsirkin | addr -= proxy->addr; |
316 | aba800a3 | Michael S. Tsirkin | if (addr < config) {
|
317 | aba800a3 | Michael S. Tsirkin | virtio_ioport_write(proxy, addr, val); |
318 | aba800a3 | Michael S. Tsirkin | return;
|
319 | aba800a3 | Michael S. Tsirkin | } |
320 | aba800a3 | Michael S. Tsirkin | addr -= config; |
321 | 53c25cea | Paul Brook | virtio_config_writeb(proxy->vdev, addr, val); |
322 | 53c25cea | Paul Brook | } |
323 | 53c25cea | Paul Brook | |
324 | 53c25cea | Paul Brook | static void virtio_pci_config_writew(void *opaque, uint32_t addr, uint32_t val) |
325 | 53c25cea | Paul Brook | { |
326 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = opaque; |
327 | aba800a3 | Michael S. Tsirkin | uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); |
328 | aba800a3 | Michael S. Tsirkin | addr -= proxy->addr; |
329 | aba800a3 | Michael S. Tsirkin | if (addr < config) {
|
330 | aba800a3 | Michael S. Tsirkin | virtio_ioport_write(proxy, addr, val); |
331 | aba800a3 | Michael S. Tsirkin | return;
|
332 | aba800a3 | Michael S. Tsirkin | } |
333 | aba800a3 | Michael S. Tsirkin | addr -= config; |
334 | 53c25cea | Paul Brook | virtio_config_writew(proxy->vdev, addr, val); |
335 | 53c25cea | Paul Brook | } |
336 | 53c25cea | Paul Brook | |
337 | 53c25cea | Paul Brook | static void virtio_pci_config_writel(void *opaque, uint32_t addr, uint32_t val) |
338 | 53c25cea | Paul Brook | { |
339 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = opaque; |
340 | aba800a3 | Michael S. Tsirkin | uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); |
341 | aba800a3 | Michael S. Tsirkin | addr -= proxy->addr; |
342 | aba800a3 | Michael S. Tsirkin | if (addr < config) {
|
343 | aba800a3 | Michael S. Tsirkin | virtio_ioport_write(proxy, addr, val); |
344 | aba800a3 | Michael S. Tsirkin | return;
|
345 | aba800a3 | Michael S. Tsirkin | } |
346 | aba800a3 | Michael S. Tsirkin | addr -= config; |
347 | 53c25cea | Paul Brook | virtio_config_writel(proxy->vdev, addr, val); |
348 | 53c25cea | Paul Brook | } |
349 | 53c25cea | Paul Brook | |
350 | 53c25cea | Paul Brook | static void virtio_map(PCIDevice *pci_dev, int region_num, |
351 | 6e355d90 | Isaku Yamahata | pcibus_t addr, pcibus_t size, int type)
|
352 | 53c25cea | Paul Brook | { |
353 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = container_of(pci_dev, VirtIOPCIProxy, pci_dev); |
354 | 53c25cea | Paul Brook | VirtIODevice *vdev = proxy->vdev; |
355 | aba800a3 | Michael S. Tsirkin | unsigned config_len = VIRTIO_PCI_REGION_SIZE(pci_dev) + vdev->config_len;
|
356 | 53c25cea | Paul Brook | |
357 | 53c25cea | Paul Brook | proxy->addr = addr; |
358 | 53c25cea | Paul Brook | |
359 | aba800a3 | Michael S. Tsirkin | register_ioport_write(addr, config_len, 1, virtio_pci_config_writeb, proxy);
|
360 | aba800a3 | Michael S. Tsirkin | register_ioport_write(addr, config_len, 2, virtio_pci_config_writew, proxy);
|
361 | aba800a3 | Michael S. Tsirkin | register_ioport_write(addr, config_len, 4, virtio_pci_config_writel, proxy);
|
362 | aba800a3 | Michael S. Tsirkin | register_ioport_read(addr, config_len, 1, virtio_pci_config_readb, proxy);
|
363 | aba800a3 | Michael S. Tsirkin | register_ioport_read(addr, config_len, 2, virtio_pci_config_readw, proxy);
|
364 | aba800a3 | Michael S. Tsirkin | register_ioport_read(addr, config_len, 4, virtio_pci_config_readl, proxy);
|
365 | 53c25cea | Paul Brook | |
366 | aba800a3 | Michael S. Tsirkin | if (vdev->config_len)
|
367 | 53c25cea | Paul Brook | vdev->get_config(vdev, vdev->config); |
368 | aba800a3 | Michael S. Tsirkin | } |
369 | aba800a3 | Michael S. Tsirkin | |
370 | aba800a3 | Michael S. Tsirkin | static void virtio_write_config(PCIDevice *pci_dev, uint32_t address, |
371 | aba800a3 | Michael S. Tsirkin | uint32_t val, int len)
|
372 | aba800a3 | Michael S. Tsirkin | { |
373 | ed757e14 | Yan Vugenfirer | VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); |
374 | ed757e14 | Yan Vugenfirer | |
375 | ed757e14 | Yan Vugenfirer | if (PCI_COMMAND == address) {
|
376 | ed757e14 | Yan Vugenfirer | if (!(val & PCI_COMMAND_MASTER)) {
|
377 | ed757e14 | Yan Vugenfirer | proxy->vdev->status &= !VIRTIO_CONFIG_S_DRIVER_OK; |
378 | ed757e14 | Yan Vugenfirer | } |
379 | ed757e14 | Yan Vugenfirer | } |
380 | ed757e14 | Yan Vugenfirer | |
381 | aba800a3 | Michael S. Tsirkin | pci_default_write_config(pci_dev, address, val, len); |
382 | 85352471 | Michael S. Tsirkin | msix_write_config(pci_dev, address, val, len); |
383 | 53c25cea | Paul Brook | } |
384 | 53c25cea | Paul Brook | |
385 | 53c25cea | Paul Brook | static const VirtIOBindings virtio_pci_bindings = { |
386 | ff24bd58 | Michael S. Tsirkin | .notify = virtio_pci_notify, |
387 | ff24bd58 | Michael S. Tsirkin | .save_config = virtio_pci_save_config, |
388 | ff24bd58 | Michael S. Tsirkin | .load_config = virtio_pci_load_config, |
389 | ff24bd58 | Michael S. Tsirkin | .save_queue = virtio_pci_save_queue, |
390 | ff24bd58 | Michael S. Tsirkin | .load_queue = virtio_pci_load_queue, |
391 | 53c25cea | Paul Brook | }; |
392 | 53c25cea | Paul Brook | |
393 | 53c25cea | Paul Brook | static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev, |
394 | 53c25cea | Paul Brook | uint16_t vendor, uint16_t device, |
395 | 53c25cea | Paul Brook | uint16_t class_code, uint8_t pif) |
396 | 53c25cea | Paul Brook | { |
397 | 53c25cea | Paul Brook | uint8_t *config; |
398 | 53c25cea | Paul Brook | uint32_t size; |
399 | 53c25cea | Paul Brook | |
400 | 53c25cea | Paul Brook | proxy->vdev = vdev; |
401 | 53c25cea | Paul Brook | |
402 | 53c25cea | Paul Brook | config = proxy->pci_dev.config; |
403 | 53c25cea | Paul Brook | pci_config_set_vendor_id(config, vendor); |
404 | 53c25cea | Paul Brook | pci_config_set_device_id(config, device); |
405 | 53c25cea | Paul Brook | |
406 | 53c25cea | Paul Brook | config[0x08] = VIRTIO_PCI_ABI_VERSION;
|
407 | 53c25cea | Paul Brook | |
408 | 53c25cea | Paul Brook | config[0x09] = pif;
|
409 | 53c25cea | Paul Brook | pci_config_set_class(config, class_code); |
410 | 53c25cea | Paul Brook | config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; |
411 | 53c25cea | Paul Brook | |
412 | 53c25cea | Paul Brook | config[0x2c] = vendor & 0xFF; |
413 | 53c25cea | Paul Brook | config[0x2d] = (vendor >> 8) & 0xFF; |
414 | 53c25cea | Paul Brook | config[0x2e] = vdev->device_id & 0xFF; |
415 | 53c25cea | Paul Brook | config[0x2f] = (vdev->device_id >> 8) & 0xFF; |
416 | 53c25cea | Paul Brook | |
417 | 53c25cea | Paul Brook | config[0x3d] = 1; |
418 | 53c25cea | Paul Brook | |
419 | 5a1fc5e8 | Michael S. Tsirkin | if (vdev->nvectors && !msix_init(&proxy->pci_dev, vdev->nvectors, 1, 0)) { |
420 | aba800a3 | Michael S. Tsirkin | pci_register_bar(&proxy->pci_dev, 1,
|
421 | aba800a3 | Michael S. Tsirkin | msix_bar_size(&proxy->pci_dev), |
422 | 0392a017 | Isaku Yamahata | PCI_BASE_ADDRESS_SPACE_MEMORY, |
423 | aba800a3 | Michael S. Tsirkin | msix_mmio_map); |
424 | aba800a3 | Michael S. Tsirkin | } else
|
425 | aba800a3 | Michael S. Tsirkin | vdev->nvectors = 0;
|
426 | aba800a3 | Michael S. Tsirkin | |
427 | ed757e14 | Yan Vugenfirer | proxy->pci_dev.config_write = virtio_write_config; |
428 | ed757e14 | Yan Vugenfirer | |
429 | aba800a3 | Michael S. Tsirkin | size = VIRTIO_PCI_REGION_SIZE(&proxy->pci_dev) + vdev->config_len; |
430 | 53c25cea | Paul Brook | if (size & (size-1)) |
431 | 53c25cea | Paul Brook | size = 1 << qemu_fls(size);
|
432 | 53c25cea | Paul Brook | |
433 | 0392a017 | Isaku Yamahata | pci_register_bar(&proxy->pci_dev, 0, size, PCI_BASE_ADDRESS_SPACE_IO,
|
434 | 53c25cea | Paul Brook | virtio_map); |
435 | 53c25cea | Paul Brook | |
436 | 53c25cea | Paul Brook | virtio_bind_device(vdev, &virtio_pci_bindings, proxy); |
437 | 53c25cea | Paul Brook | } |
438 | 53c25cea | Paul Brook | |
439 | 81a322d4 | Gerd Hoffmann | static int virtio_blk_init_pci(PCIDevice *pci_dev) |
440 | 53c25cea | Paul Brook | { |
441 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); |
442 | 53c25cea | Paul Brook | VirtIODevice *vdev; |
443 | 53c25cea | Paul Brook | |
444 | ab73ff29 | Gerd Hoffmann | if (proxy->class_code != PCI_CLASS_STORAGE_SCSI &&
|
445 | ab73ff29 | Gerd Hoffmann | proxy->class_code != PCI_CLASS_STORAGE_OTHER) |
446 | ab73ff29 | Gerd Hoffmann | proxy->class_code = PCI_CLASS_STORAGE_SCSI; |
447 | 53c25cea | Paul Brook | |
448 | d176c495 | Gerd Hoffmann | if (!proxy->dinfo) {
|
449 | 84fc5589 | Gerd Hoffmann | qemu_error("virtio-blk-pci: drive property not set\n");
|
450 | 81a322d4 | Gerd Hoffmann | return -1; |
451 | d176c495 | Gerd Hoffmann | } |
452 | d176c495 | Gerd Hoffmann | vdev = virtio_blk_init(&pci_dev->qdev, proxy->dinfo); |
453 | 177539e0 | Gerd Hoffmann | vdev->nvectors = proxy->nvectors; |
454 | 53c25cea | Paul Brook | virtio_init_pci(proxy, vdev, |
455 | 53c25cea | Paul Brook | PCI_VENDOR_ID_REDHAT_QUMRANET, |
456 | 85c2c735 | Mark McLoughlin | PCI_DEVICE_ID_VIRTIO_BLOCK, |
457 | 85c2c735 | Mark McLoughlin | proxy->class_code, 0x00);
|
458 | 177539e0 | Gerd Hoffmann | /* make the actual value visible */
|
459 | 177539e0 | Gerd Hoffmann | proxy->nvectors = vdev->nvectors; |
460 | 81a322d4 | Gerd Hoffmann | return 0; |
461 | 21d58b57 | Mark McLoughlin | } |
462 | 21d58b57 | Mark McLoughlin | |
463 | 0f457d91 | Michael S. Tsirkin | static int virtio_exit_pci(PCIDevice *pci_dev) |
464 | 0f457d91 | Michael S. Tsirkin | { |
465 | 0f457d91 | Michael S. Tsirkin | return msix_uninit(pci_dev);
|
466 | 0f457d91 | Michael S. Tsirkin | } |
467 | 0f457d91 | Michael S. Tsirkin | |
468 | 56a14938 | Gerd Hoffmann | static int virtio_blk_exit_pci(PCIDevice *pci_dev) |
469 | 56a14938 | Gerd Hoffmann | { |
470 | 56a14938 | Gerd Hoffmann | VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); |
471 | 56a14938 | Gerd Hoffmann | |
472 | 56a14938 | Gerd Hoffmann | drive_uninit(proxy->dinfo); |
473 | 0f457d91 | Michael S. Tsirkin | return virtio_exit_pci(pci_dev);
|
474 | 56a14938 | Gerd Hoffmann | } |
475 | 56a14938 | Gerd Hoffmann | |
476 | 81a322d4 | Gerd Hoffmann | static int virtio_console_init_pci(PCIDevice *pci_dev) |
477 | 21d58b57 | Mark McLoughlin | { |
478 | d6beee99 | Gerd Hoffmann | VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); |
479 | 85c2c735 | Mark McLoughlin | VirtIODevice *vdev; |
480 | 85c2c735 | Mark McLoughlin | |
481 | d6beee99 | Gerd Hoffmann | if (proxy->class_code != PCI_CLASS_COMMUNICATION_OTHER &&
|
482 | d6beee99 | Gerd Hoffmann | proxy->class_code != PCI_CLASS_DISPLAY_OTHER && /* qemu 0.10 */
|
483 | d6beee99 | Gerd Hoffmann | proxy->class_code != PCI_CLASS_OTHERS) /* qemu-kvm */
|
484 | d6beee99 | Gerd Hoffmann | proxy->class_code = PCI_CLASS_COMMUNICATION_OTHER; |
485 | d6beee99 | Gerd Hoffmann | |
486 | 85c2c735 | Mark McLoughlin | vdev = virtio_console_init(&pci_dev->qdev); |
487 | 25fe3654 | Amit Shah | if (!vdev) {
|
488 | 25fe3654 | Amit Shah | return -1; |
489 | 25fe3654 | Amit Shah | } |
490 | 85c2c735 | Mark McLoughlin | virtio_init_pci(proxy, vdev, |
491 | 85c2c735 | Mark McLoughlin | PCI_VENDOR_ID_REDHAT_QUMRANET, |
492 | 85c2c735 | Mark McLoughlin | PCI_DEVICE_ID_VIRTIO_CONSOLE, |
493 | 85c2c735 | Mark McLoughlin | proxy->class_code, 0x00);
|
494 | 81a322d4 | Gerd Hoffmann | return 0; |
495 | 53c25cea | Paul Brook | } |
496 | 53c25cea | Paul Brook | |
497 | 81a322d4 | Gerd Hoffmann | static int virtio_net_init_pci(PCIDevice *pci_dev) |
498 | 53c25cea | Paul Brook | { |
499 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); |
500 | 53c25cea | Paul Brook | VirtIODevice *vdev; |
501 | 53c25cea | Paul Brook | |
502 | 97b15621 | Gerd Hoffmann | vdev = virtio_net_init(&pci_dev->qdev, &proxy->nic); |
503 | a1e0fea5 | Gerd Hoffmann | |
504 | 97b15621 | Gerd Hoffmann | vdev->nvectors = proxy->nvectors; |
505 | 53c25cea | Paul Brook | virtio_init_pci(proxy, vdev, |
506 | 53c25cea | Paul Brook | PCI_VENDOR_ID_REDHAT_QUMRANET, |
507 | 53c25cea | Paul Brook | PCI_DEVICE_ID_VIRTIO_NET, |
508 | 53c25cea | Paul Brook | PCI_CLASS_NETWORK_ETHERNET, |
509 | 53c25cea | Paul Brook | 0x00);
|
510 | a1e0fea5 | Gerd Hoffmann | |
511 | a1e0fea5 | Gerd Hoffmann | /* make the actual value visible */
|
512 | a1e0fea5 | Gerd Hoffmann | proxy->nvectors = vdev->nvectors; |
513 | 97b15621 | Gerd Hoffmann | |
514 | 97b15621 | Gerd Hoffmann | if (!pci_dev->qdev.hotplugged) {
|
515 | 97b15621 | Gerd Hoffmann | static int loaded = 0; |
516 | 97b15621 | Gerd Hoffmann | if (!loaded) {
|
517 | 97b15621 | Gerd Hoffmann | rom_add_option("pxe-virtio.bin");
|
518 | 97b15621 | Gerd Hoffmann | loaded = 1;
|
519 | 97b15621 | Gerd Hoffmann | } |
520 | 97b15621 | Gerd Hoffmann | } |
521 | 81a322d4 | Gerd Hoffmann | return 0; |
522 | 53c25cea | Paul Brook | } |
523 | 53c25cea | Paul Brook | |
524 | 97b15621 | Gerd Hoffmann | static int virtio_net_exit_pci(PCIDevice *pci_dev) |
525 | 97b15621 | Gerd Hoffmann | { |
526 | 97b15621 | Gerd Hoffmann | VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); |
527 | 97b15621 | Gerd Hoffmann | |
528 | 97b15621 | Gerd Hoffmann | virtio_net_exit(proxy->vdev); |
529 | 97b15621 | Gerd Hoffmann | return virtio_exit_pci(pci_dev);
|
530 | 97b15621 | Gerd Hoffmann | } |
531 | 97b15621 | Gerd Hoffmann | |
532 | 81a322d4 | Gerd Hoffmann | static int virtio_balloon_init_pci(PCIDevice *pci_dev) |
533 | 53c25cea | Paul Brook | { |
534 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); |
535 | 53c25cea | Paul Brook | VirtIODevice *vdev; |
536 | 53c25cea | Paul Brook | |
537 | 53c25cea | Paul Brook | vdev = virtio_balloon_init(&pci_dev->qdev); |
538 | 53c25cea | Paul Brook | virtio_init_pci(proxy, vdev, |
539 | 53c25cea | Paul Brook | PCI_VENDOR_ID_REDHAT_QUMRANET, |
540 | 53c25cea | Paul Brook | PCI_DEVICE_ID_VIRTIO_BALLOON, |
541 | 53c25cea | Paul Brook | PCI_CLASS_MEMORY_RAM, |
542 | 53c25cea | Paul Brook | 0x00);
|
543 | 81a322d4 | Gerd Hoffmann | return 0; |
544 | 53c25cea | Paul Brook | } |
545 | 53c25cea | Paul Brook | |
546 | 0aab0d3a | Gerd Hoffmann | static PCIDeviceInfo virtio_info[] = {
|
547 | 0aab0d3a | Gerd Hoffmann | { |
548 | 0aab0d3a | Gerd Hoffmann | .qdev.name = "virtio-blk-pci",
|
549 | 0aab0d3a | Gerd Hoffmann | .qdev.size = sizeof(VirtIOPCIProxy),
|
550 | 0aab0d3a | Gerd Hoffmann | .init = virtio_blk_init_pci, |
551 | 56a14938 | Gerd Hoffmann | .exit = virtio_blk_exit_pci, |
552 | ab73ff29 | Gerd Hoffmann | .qdev.props = (Property[]) { |
553 | 72c61d0b | Gerd Hoffmann | DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0), |
554 | 72c61d0b | Gerd Hoffmann | DEFINE_PROP_DRIVE("drive", VirtIOPCIProxy, dinfo),
|
555 | 177539e0 | Gerd Hoffmann | DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2), |
556 | 72c61d0b | Gerd Hoffmann | DEFINE_PROP_END_OF_LIST(), |
557 | ab73ff29 | Gerd Hoffmann | }, |
558 | e489030d | Michael S. Tsirkin | .qdev.reset = virtio_pci_reset, |
559 | 0aab0d3a | Gerd Hoffmann | },{ |
560 | a1e0fea5 | Gerd Hoffmann | .qdev.name = "virtio-net-pci",
|
561 | a1e0fea5 | Gerd Hoffmann | .qdev.size = sizeof(VirtIOPCIProxy),
|
562 | a1e0fea5 | Gerd Hoffmann | .init = virtio_net_init_pci, |
563 | 97b15621 | Gerd Hoffmann | .exit = virtio_net_exit_pci, |
564 | a1e0fea5 | Gerd Hoffmann | .qdev.props = (Property[]) { |
565 | 97b15621 | Gerd Hoffmann | DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3), |
566 | 97b15621 | Gerd Hoffmann | DEFINE_NIC_PROPERTIES(VirtIOPCIProxy, nic), |
567 | 72c61d0b | Gerd Hoffmann | DEFINE_PROP_END_OF_LIST(), |
568 | a1e0fea5 | Gerd Hoffmann | }, |
569 | e489030d | Michael S. Tsirkin | .qdev.reset = virtio_pci_reset, |
570 | 0aab0d3a | Gerd Hoffmann | },{ |
571 | 0aab0d3a | Gerd Hoffmann | .qdev.name = "virtio-console-pci",
|
572 | 0aab0d3a | Gerd Hoffmann | .qdev.size = sizeof(VirtIOPCIProxy),
|
573 | 0aab0d3a | Gerd Hoffmann | .init = virtio_console_init_pci, |
574 | 0f457d91 | Michael S. Tsirkin | .exit = virtio_exit_pci, |
575 | d6beee99 | Gerd Hoffmann | .qdev.props = (Property[]) { |
576 | 72c61d0b | Gerd Hoffmann | DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0), |
577 | 72c61d0b | Gerd Hoffmann | DEFINE_PROP_END_OF_LIST(), |
578 | d6beee99 | Gerd Hoffmann | }, |
579 | e489030d | Michael S. Tsirkin | .qdev.reset = virtio_pci_reset, |
580 | 0aab0d3a | Gerd Hoffmann | },{ |
581 | 0aab0d3a | Gerd Hoffmann | .qdev.name = "virtio-balloon-pci",
|
582 | 0aab0d3a | Gerd Hoffmann | .qdev.size = sizeof(VirtIOPCIProxy),
|
583 | 0aab0d3a | Gerd Hoffmann | .init = virtio_balloon_init_pci, |
584 | 0f457d91 | Michael S. Tsirkin | .exit = virtio_exit_pci, |
585 | e489030d | Michael S. Tsirkin | .qdev.reset = virtio_pci_reset, |
586 | 0aab0d3a | Gerd Hoffmann | },{ |
587 | 0aab0d3a | Gerd Hoffmann | /* end of list */
|
588 | 0aab0d3a | Gerd Hoffmann | } |
589 | 0aab0d3a | Gerd Hoffmann | }; |
590 | 0aab0d3a | Gerd Hoffmann | |
591 | 53c25cea | Paul Brook | static void virtio_pci_register_devices(void) |
592 | 53c25cea | Paul Brook | { |
593 | 0aab0d3a | Gerd Hoffmann | pci_qdev_register_many(virtio_info); |
594 | 53c25cea | Paul Brook | } |
595 | 53c25cea | Paul Brook | |
596 | 53c25cea | Paul Brook | device_init(virtio_pci_register_devices) |