2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2011, Bryan Venteicher <bryanv@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice unmodified, this list of conditions, and the following
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 /* Driver for the legacy VirtIO PCI interface. */
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
35 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/module.h>
40 #include <sys/endian.h>
42 #include <machine/bus.h>
43 #include <machine/resource.h>
47 #include <dev/pci/pcivar.h>
48 #include <dev/pci/pcireg.h>
50 #include <dev/virtio/virtio.h>
51 #include <dev/virtio/virtqueue.h>
52 #include <dev/virtio/pci/virtio_pci.h>
53 #include <dev/virtio/pci/virtio_pci_legacy_var.h>
55 #include "virtio_bus_if.h"
56 #include "virtio_pci_if.h"
57 #include "virtio_if.h"
59 struct vtpci_legacy_softc {
61 struct vtpci_common vtpci_common;
63 struct resource *vtpci_res;
64 struct resource *vtpci_msix_table_res;
65 struct resource *vtpci_msix_pba_res;
68 static int vtpci_legacy_probe(device_t);
69 static int vtpci_legacy_attach(device_t);
70 static int vtpci_legacy_detach(device_t);
71 static int vtpci_legacy_suspend(device_t);
72 static int vtpci_legacy_resume(device_t);
73 static int vtpci_legacy_shutdown(device_t);
75 static void vtpci_legacy_driver_added(device_t, driver_t *);
76 static void vtpci_legacy_child_detached(device_t, device_t);
77 static int vtpci_legacy_read_ivar(device_t, device_t, int, uintptr_t *);
78 static int vtpci_legacy_write_ivar(device_t, device_t, int, uintptr_t);
80 static uint8_t vtpci_legacy_read_isr(device_t);
81 static uint16_t vtpci_legacy_get_vq_size(device_t, int);
82 static bus_size_t vtpci_legacy_get_vq_notify_off(device_t, int);
83 static void vtpci_legacy_set_vq(device_t, struct virtqueue *);
84 static void vtpci_legacy_disable_vq(device_t, int);
85 static int vtpci_legacy_register_cfg_msix(device_t,
86 struct vtpci_interrupt *);
87 static int vtpci_legacy_register_vq_msix(device_t, int idx,
88 struct vtpci_interrupt *);
90 static uint64_t vtpci_legacy_negotiate_features(device_t, uint64_t);
91 static int vtpci_legacy_with_feature(device_t, uint64_t);
92 static int vtpci_legacy_alloc_virtqueues(device_t, int, int,
93 struct vq_alloc_info *);
94 static int vtpci_legacy_setup_interrupts(device_t, enum intr_type);
95 static void vtpci_legacy_stop(device_t);
96 static int vtpci_legacy_reinit(device_t, uint64_t);
97 static void vtpci_legacy_reinit_complete(device_t);
98 static void vtpci_legacy_notify_vq(device_t, uint16_t, bus_size_t);
99 static void vtpci_legacy_read_dev_config(device_t, bus_size_t, void *, int);
100 static void vtpci_legacy_write_dev_config(device_t, bus_size_t, void *, int);
102 static bool vtpci_legacy_setup_msix(struct vtpci_legacy_softc *sc);
103 static void vtpci_legacy_teardown_msix(struct vtpci_legacy_softc *sc);
104 static int vtpci_legacy_alloc_resources(struct vtpci_legacy_softc *);
105 static void vtpci_legacy_free_resources(struct vtpci_legacy_softc *);
107 static void vtpci_legacy_probe_and_attach_child(struct vtpci_legacy_softc *);
109 static uint8_t vtpci_legacy_get_status(struct vtpci_legacy_softc *);
110 static void vtpci_legacy_set_status(struct vtpci_legacy_softc *, uint8_t);
111 static void vtpci_legacy_select_virtqueue(struct vtpci_legacy_softc *, int);
112 static void vtpci_legacy_reset(struct vtpci_legacy_softc *);
114 #define VIRTIO_PCI_LEGACY_CONFIG(_sc) \
115 VIRTIO_PCI_CONFIG_OFF(vtpci_is_msix_enabled(&(_sc)->vtpci_common))
117 #define vtpci_legacy_read_config_1(sc, o) \
118 bus_read_1((sc)->vtpci_res, (o))
119 #define vtpci_legacy_write_config_1(sc, o, v) \
120 bus_write_1((sc)->vtpci_res, (o), (v))
122 * VirtIO specifies that PCI Configuration area is guest endian. However,
123 * since PCI devices are inherently little-endian, on big-endian systems
124 * the bus layer transparently converts it to BE. For virtio-legacy, this
125 * conversion is undesired, so an extra byte swap is required to fix it.
127 #define vtpci_legacy_read_config_2(sc, o) \
128 le16toh(bus_read_2((sc)->vtpci_res, (o)))
129 #define vtpci_legacy_read_config_4(sc, o) \
130 le32toh(bus_read_4((sc)->vtpci_res, (o)))
131 #define vtpci_legacy_write_config_2(sc, o, v) \
132 bus_write_2((sc)->vtpci_res, (o), (htole16(v)))
133 #define vtpci_legacy_write_config_4(sc, o, v) \
134 bus_write_4((sc)->vtpci_res, (o), (htole32(v)))
135 /* PCI Header LE. On BE systems the bus layer takes care of byte swapping. */
136 #define vtpci_legacy_read_header_2(sc, o) \
137 bus_read_2((sc)->vtpci_res, (o))
138 #define vtpci_legacy_read_header_4(sc, o) \
139 bus_read_4((sc)->vtpci_res, (o))
140 #define vtpci_legacy_write_header_2(sc, o, v) \
141 bus_write_2((sc)->vtpci_res, (o), (v))
142 #define vtpci_legacy_write_header_4(sc, o, v) \
143 bus_write_4((sc)->vtpci_res, (o), (v))
145 static device_method_t vtpci_legacy_methods[] = {
146 /* Device interface. */
147 DEVMETHOD(device_probe, vtpci_legacy_probe),
148 DEVMETHOD(device_attach, vtpci_legacy_attach),
149 DEVMETHOD(device_detach, vtpci_legacy_detach),
150 DEVMETHOD(device_suspend, vtpci_legacy_suspend),
151 DEVMETHOD(device_resume, vtpci_legacy_resume),
152 DEVMETHOD(device_shutdown, vtpci_legacy_shutdown),
155 DEVMETHOD(bus_driver_added, vtpci_legacy_driver_added),
156 DEVMETHOD(bus_child_detached, vtpci_legacy_child_detached),
157 DEVMETHOD(bus_child_pnpinfo_str, virtio_child_pnpinfo_str),
158 DEVMETHOD(bus_read_ivar, vtpci_legacy_read_ivar),
159 DEVMETHOD(bus_write_ivar, vtpci_legacy_write_ivar),
161 /* VirtIO PCI interface. */
162 DEVMETHOD(virtio_pci_read_isr, vtpci_legacy_read_isr),
163 DEVMETHOD(virtio_pci_get_vq_size, vtpci_legacy_get_vq_size),
164 DEVMETHOD(virtio_pci_get_vq_notify_off, vtpci_legacy_get_vq_notify_off),
165 DEVMETHOD(virtio_pci_set_vq, vtpci_legacy_set_vq),
166 DEVMETHOD(virtio_pci_disable_vq, vtpci_legacy_disable_vq),
167 DEVMETHOD(virtio_pci_register_cfg_msix, vtpci_legacy_register_cfg_msix),
168 DEVMETHOD(virtio_pci_register_vq_msix, vtpci_legacy_register_vq_msix),
170 /* VirtIO bus interface. */
171 DEVMETHOD(virtio_bus_negotiate_features, vtpci_legacy_negotiate_features),
172 DEVMETHOD(virtio_bus_with_feature, vtpci_legacy_with_feature),
173 DEVMETHOD(virtio_bus_alloc_virtqueues, vtpci_legacy_alloc_virtqueues),
174 DEVMETHOD(virtio_bus_setup_intr, vtpci_legacy_setup_interrupts),
175 DEVMETHOD(virtio_bus_stop, vtpci_legacy_stop),
176 DEVMETHOD(virtio_bus_reinit, vtpci_legacy_reinit),
177 DEVMETHOD(virtio_bus_reinit_complete, vtpci_legacy_reinit_complete),
178 DEVMETHOD(virtio_bus_notify_vq, vtpci_legacy_notify_vq),
179 DEVMETHOD(virtio_bus_read_device_config, vtpci_legacy_read_dev_config),
180 DEVMETHOD(virtio_bus_write_device_config, vtpci_legacy_write_dev_config),
185 static driver_t vtpci_legacy_driver = {
186 .name = "virtio_pci",
187 .methods = vtpci_legacy_methods,
188 .size = sizeof(struct vtpci_legacy_softc)
191 devclass_t vtpci_legacy_devclass;
193 DRIVER_MODULE(virtio_pci_legacy, pci, vtpci_legacy_driver,
194 vtpci_legacy_devclass, 0, 0);
197 vtpci_legacy_probe(device_t dev)
202 if (pci_get_vendor(dev) != VIRTIO_PCI_VENDORID)
205 if (pci_get_device(dev) < VIRTIO_PCI_DEVICEID_MIN ||
206 pci_get_device(dev) > VIRTIO_PCI_DEVICEID_LEGACY_MAX)
209 if (pci_get_revid(dev) != VIRTIO_PCI_ABI_VERSION)
212 name = virtio_device_name(pci_get_subdevice(dev));
216 snprintf(desc, sizeof(desc), "VirtIO PCI (legacy) %s adapter", name);
217 device_set_desc_copy(dev, desc);
219 /* Prefer transitional modern VirtIO PCI. */
220 return (BUS_PROBE_LOW_PRIORITY);
224 vtpci_legacy_attach(device_t dev)
226 struct vtpci_legacy_softc *sc;
229 sc = device_get_softc(dev);
231 vtpci_init(&sc->vtpci_common, dev, false);
233 error = vtpci_legacy_alloc_resources(sc);
235 device_printf(dev, "cannot map I/O space nor memory space\n");
239 if (vtpci_is_msix_available(&sc->vtpci_common) &&
240 !vtpci_legacy_setup_msix(sc)) {
241 device_printf(dev, "cannot setup MSI-x resources\n");
246 vtpci_legacy_reset(sc);
248 /* Tell the host we've noticed this device. */
249 vtpci_legacy_set_status(sc, VIRTIO_CONFIG_STATUS_ACK);
251 error = vtpci_add_child(&sc->vtpci_common);
255 vtpci_legacy_probe_and_attach_child(sc);
260 vtpci_legacy_set_status(sc, VIRTIO_CONFIG_STATUS_FAILED);
261 vtpci_legacy_detach(dev);
267 vtpci_legacy_detach(device_t dev)
269 struct vtpci_legacy_softc *sc;
272 sc = device_get_softc(dev);
274 error = vtpci_delete_child(&sc->vtpci_common);
278 vtpci_legacy_reset(sc);
279 vtpci_legacy_teardown_msix(sc);
280 vtpci_legacy_free_resources(sc);
286 vtpci_legacy_suspend(device_t dev)
288 return (bus_generic_suspend(dev));
292 vtpci_legacy_resume(device_t dev)
294 return (bus_generic_resume(dev));
298 vtpci_legacy_shutdown(device_t dev)
300 (void) bus_generic_shutdown(dev);
301 /* Forcibly stop the host device. */
302 vtpci_legacy_stop(dev);
308 vtpci_legacy_driver_added(device_t dev, driver_t *driver)
310 vtpci_legacy_probe_and_attach_child(device_get_softc(dev));
314 vtpci_legacy_child_detached(device_t dev, device_t child)
316 struct vtpci_legacy_softc *sc;
318 sc = device_get_softc(dev);
320 vtpci_legacy_reset(sc);
321 vtpci_child_detached(&sc->vtpci_common);
323 /* After the reset, retell the host we've noticed this device. */
324 vtpci_legacy_set_status(sc, VIRTIO_CONFIG_STATUS_ACK);
328 vtpci_legacy_read_ivar(device_t dev, device_t child, int index,
331 struct vtpci_legacy_softc *sc;
332 struct vtpci_common *cn;
334 sc = device_get_softc(dev);
335 cn = &sc->vtpci_common;
337 if (vtpci_child_device(cn) != child)
341 case VIRTIO_IVAR_DEVTYPE:
342 *result = pci_get_subdevice(dev);
345 return (vtpci_read_ivar(cn, index, result));
352 vtpci_legacy_write_ivar(device_t dev, device_t child, int index, uintptr_t value)
354 struct vtpci_legacy_softc *sc;
355 struct vtpci_common *cn;
357 sc = device_get_softc(dev);
358 cn = &sc->vtpci_common;
360 if (vtpci_child_device(cn) != child)
365 return (vtpci_write_ivar(cn, index, value));
372 vtpci_legacy_negotiate_features(device_t dev, uint64_t child_features)
374 struct vtpci_legacy_softc *sc;
375 uint64_t host_features, features;
377 sc = device_get_softc(dev);
378 host_features = vtpci_legacy_read_header_4(sc, VIRTIO_PCI_HOST_FEATURES);
380 features = vtpci_negotiate_features(&sc->vtpci_common,
381 child_features, host_features);
382 vtpci_legacy_write_header_4(sc, VIRTIO_PCI_GUEST_FEATURES, features);
388 vtpci_legacy_with_feature(device_t dev, uint64_t feature)
390 struct vtpci_legacy_softc *sc;
392 sc = device_get_softc(dev);
394 return (vtpci_with_feature(&sc->vtpci_common, feature));
398 vtpci_legacy_alloc_virtqueues(device_t dev, int flags, int nvqs,
399 struct vq_alloc_info *vq_info)
401 struct vtpci_legacy_softc *sc;
402 struct vtpci_common *cn;
404 sc = device_get_softc(dev);
405 cn = &sc->vtpci_common;
407 return (vtpci_alloc_virtqueues(cn, flags, nvqs, vq_info));
411 vtpci_legacy_setup_interrupts(device_t dev, enum intr_type type)
413 struct vtpci_legacy_softc *sc;
415 sc = device_get_softc(dev);
417 return (vtpci_setup_interrupts(&sc->vtpci_common, type));
421 vtpci_legacy_stop(device_t dev)
423 vtpci_legacy_reset(device_get_softc(dev));
427 vtpci_legacy_reinit(device_t dev, uint64_t features)
429 struct vtpci_legacy_softc *sc;
430 struct vtpci_common *cn;
433 sc = device_get_softc(dev);
434 cn = &sc->vtpci_common;
437 * Redrive the device initialization. This is a bit of an abuse of
438 * the specification, but VirtualBox, QEMU/KVM, and BHyVe seem to
441 * We do not allow the host device to change from what was originally
442 * negotiated beyond what the guest driver changed. MSIX state should
443 * not change, number of virtqueues and their size remain the same, etc.
444 * This will need to be rethought when we want to support migration.
447 if (vtpci_legacy_get_status(sc) != VIRTIO_CONFIG_STATUS_RESET)
448 vtpci_legacy_stop(dev);
451 * Quickly drive the status through ACK and DRIVER. The device does
452 * not become usable again until DRIVER_OK in reinit complete.
454 vtpci_legacy_set_status(sc, VIRTIO_CONFIG_STATUS_ACK);
455 vtpci_legacy_set_status(sc, VIRTIO_CONFIG_STATUS_DRIVER);
457 vtpci_legacy_negotiate_features(dev, features);
459 error = vtpci_reinit(cn);
467 vtpci_legacy_reinit_complete(device_t dev)
469 struct vtpci_legacy_softc *sc;
471 sc = device_get_softc(dev);
473 vtpci_legacy_set_status(sc, VIRTIO_CONFIG_STATUS_DRIVER_OK);
477 vtpci_legacy_notify_vq(device_t dev, uint16_t queue, bus_size_t offset)
479 struct vtpci_legacy_softc *sc;
481 sc = device_get_softc(dev);
482 MPASS(offset == VIRTIO_PCI_QUEUE_NOTIFY);
484 vtpci_legacy_write_header_2(sc, offset, queue);
488 vtpci_legacy_get_status(struct vtpci_legacy_softc *sc)
490 return (vtpci_legacy_read_config_1(sc, VIRTIO_PCI_STATUS));
494 vtpci_legacy_set_status(struct vtpci_legacy_softc *sc, uint8_t status)
496 if (status != VIRTIO_CONFIG_STATUS_RESET)
497 status |= vtpci_legacy_get_status(sc);
499 vtpci_legacy_write_config_1(sc, VIRTIO_PCI_STATUS, status);
503 vtpci_legacy_read_dev_config(device_t dev, bus_size_t offset,
504 void *dst, int length)
506 struct vtpci_legacy_softc *sc;
511 sc = device_get_softc(dev);
512 off = VIRTIO_PCI_LEGACY_CONFIG(sc) + offset;
514 for (d = dst; length > 0; d += size, off += size, length -= size) {
517 *(uint32_t *)d = vtpci_legacy_read_config_4(sc, off);
518 } else if (length >= 2) {
520 *(uint16_t *)d = vtpci_legacy_read_config_2(sc, off);
523 *d = vtpci_legacy_read_config_1(sc, off);
529 vtpci_legacy_write_dev_config(device_t dev, bus_size_t offset,
530 void *src, int length)
532 struct vtpci_legacy_softc *sc;
537 sc = device_get_softc(dev);
538 off = VIRTIO_PCI_LEGACY_CONFIG(sc) + offset;
540 for (s = src; length > 0; s += size, off += size, length -= size) {
543 vtpci_legacy_write_config_4(sc, off, *(uint32_t *)s);
544 } else if (length >= 2) {
546 vtpci_legacy_write_config_2(sc, off, *(uint16_t *)s);
549 vtpci_legacy_write_config_1(sc, off, *s);
555 vtpci_legacy_setup_msix(struct vtpci_legacy_softc *sc)
562 rid = table_rid = pci_msix_table_bar(dev);
563 if (rid != PCIR_BAR(0)) {
564 sc->vtpci_msix_table_res = bus_alloc_resource_any(
565 dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
566 if (sc->vtpci_msix_table_res == NULL)
570 rid = pci_msix_pba_bar(dev);
571 if (rid != table_rid && rid != PCIR_BAR(0)) {
572 sc->vtpci_msix_pba_res = bus_alloc_resource_any(
573 dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
574 if (sc->vtpci_msix_pba_res == NULL)
582 vtpci_legacy_teardown_msix(struct vtpci_legacy_softc *sc)
588 if (sc->vtpci_msix_pba_res != NULL) {
589 bus_release_resource(dev, SYS_RES_MEMORY,
590 rman_get_rid(sc->vtpci_msix_pba_res),
591 sc->vtpci_msix_pba_res);
592 sc->vtpci_msix_pba_res = NULL;
594 if (sc->vtpci_msix_table_res != NULL) {
595 bus_release_resource(dev, SYS_RES_MEMORY,
596 rman_get_rid(sc->vtpci_msix_table_res),
597 sc->vtpci_msix_table_res);
598 sc->vtpci_msix_table_res = NULL;
603 vtpci_legacy_alloc_resources(struct vtpci_legacy_softc *sc)
605 const int res_types[] = { SYS_RES_IOPORT, SYS_RES_MEMORY };
612 * Most hypervisors export the common configuration structure in IO
613 * space, but some use memory space; try both.
615 for (i = 0; nitems(res_types); i++) {
617 sc->vtpci_res_type = res_types[i];
618 sc->vtpci_res = bus_alloc_resource_any(dev, res_types[i], &rid,
620 if (sc->vtpci_res != NULL)
623 if (sc->vtpci_res == NULL)
630 vtpci_legacy_free_resources(struct vtpci_legacy_softc *sc)
636 if (sc->vtpci_res != NULL) {
637 bus_release_resource(dev, sc->vtpci_res_type, PCIR_BAR(0),
639 sc->vtpci_res = NULL;
644 vtpci_legacy_probe_and_attach_child(struct vtpci_legacy_softc *sc)
649 child = vtpci_child_device(&sc->vtpci_common);
651 if (child == NULL || device_get_state(child) != DS_NOTPRESENT)
654 if (device_probe(child) != 0)
657 vtpci_legacy_set_status(sc, VIRTIO_CONFIG_STATUS_DRIVER);
659 if (device_attach(child) != 0) {
660 vtpci_legacy_set_status(sc, VIRTIO_CONFIG_STATUS_FAILED);
661 /* Reset status for future attempt. */
662 vtpci_legacy_child_detached(dev, child);
664 vtpci_legacy_set_status(sc, VIRTIO_CONFIG_STATUS_DRIVER_OK);
665 VIRTIO_ATTACH_COMPLETED(child);
670 vtpci_legacy_register_msix(struct vtpci_legacy_softc *sc, int offset,
671 struct vtpci_interrupt *intr)
679 /* Map from guest rid to host vector. */
680 vector = intr->vti_rid - 1;
682 vector = VIRTIO_MSI_NO_VECTOR;
684 vtpci_legacy_write_header_2(sc, offset, vector);
685 return (vtpci_legacy_read_header_2(sc, offset) == vector ? 0 : ENODEV);
689 vtpci_legacy_register_cfg_msix(device_t dev, struct vtpci_interrupt *intr)
691 struct vtpci_legacy_softc *sc;
694 sc = device_get_softc(dev);
696 error = vtpci_legacy_register_msix(sc, VIRTIO_MSI_CONFIG_VECTOR, intr);
699 "unable to register config MSIX interrupt\n");
707 vtpci_legacy_register_vq_msix(device_t dev, int idx,
708 struct vtpci_interrupt *intr)
710 struct vtpci_legacy_softc *sc;
713 sc = device_get_softc(dev);
715 vtpci_legacy_select_virtqueue(sc, idx);
716 error = vtpci_legacy_register_msix(sc, VIRTIO_MSI_QUEUE_VECTOR, intr);
719 "unable to register virtqueue MSIX interrupt\n");
727 vtpci_legacy_reset(struct vtpci_legacy_softc *sc)
730 * Setting the status to RESET sets the host device to the
731 * original, uninitialized state.
733 vtpci_legacy_set_status(sc, VIRTIO_CONFIG_STATUS_RESET);
734 (void) vtpci_legacy_get_status(sc);
738 vtpci_legacy_select_virtqueue(struct vtpci_legacy_softc *sc, int idx)
740 vtpci_legacy_write_header_2(sc, VIRTIO_PCI_QUEUE_SEL, idx);
744 vtpci_legacy_read_isr(device_t dev)
746 struct vtpci_legacy_softc *sc;
748 sc = device_get_softc(dev);
750 return (vtpci_legacy_read_config_1(sc, VIRTIO_PCI_ISR));
754 vtpci_legacy_get_vq_size(device_t dev, int idx)
756 struct vtpci_legacy_softc *sc;
758 sc = device_get_softc(dev);
760 vtpci_legacy_select_virtqueue(sc, idx);
761 return (vtpci_legacy_read_header_2(sc, VIRTIO_PCI_QUEUE_NUM));
765 vtpci_legacy_get_vq_notify_off(device_t dev, int idx)
767 return (VIRTIO_PCI_QUEUE_NOTIFY);
771 vtpci_legacy_set_vq(device_t dev, struct virtqueue *vq)
773 struct vtpci_legacy_softc *sc;
775 sc = device_get_softc(dev);
777 vtpci_legacy_select_virtqueue(sc, virtqueue_index(vq));
778 vtpci_legacy_write_header_4(sc, VIRTIO_PCI_QUEUE_PFN,
779 virtqueue_paddr(vq) >> VIRTIO_PCI_QUEUE_ADDR_SHIFT);
783 vtpci_legacy_disable_vq(device_t dev, int idx)
785 struct vtpci_legacy_softc *sc;
787 sc = device_get_softc(dev);
789 vtpci_legacy_select_virtqueue(sc, idx);
790 vtpci_legacy_write_header_4(sc, VIRTIO_PCI_QUEUE_PFN, 0);