Statistics
| Branch: | Revision:

root / hw / virtio-pci.c @ 66c80e75

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