Lines Matching +full:- +full:- +full:-
12 * the COPYING file in the top-level directory.
14 * Contributions after 2012-01-13 are licensed under the terms of the
21 #include "standard-headers/linux/virtio_pci.h"
22 #include "standard-headers/linux/virtio_ids.h"
25 #include "migration/qemu-file-types.h"
28 #include "hw/qdev-properties.h"
30 #include "qemu/error-report.h"
37 #include "hw/virtio/virtio-pci.h"
39 #include "hw/virtio/virtio-bus.h"
48 /* The remaining space is defined by each driver as the per-driver
57 /* DeviceState to VirtIOPCIProxy. For use off data-path. TODO: use QOM. */
75 if (msix_enabled(&proxy->pci_dev)) { in virtio_pci_notify()
77 msix_notify(&proxy->pci_dev, vector); in virtio_pci_notify()
80 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_notify()
81 pci_set_irq(&proxy->pci_dev, qatomic_read(&vdev->isr) & 1); in virtio_pci_notify()
88 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_save_config()
90 pci_device_save(&proxy->pci_dev, f); in virtio_pci_save_config()
91 msix_save(&proxy->pci_dev, f); in virtio_pci_save_config()
92 if (msix_present(&proxy->pci_dev)) in virtio_pci_save_config()
93 qemu_put_be16(f, vdev->config_vector); in virtio_pci_save_config()
169 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_save_queue()
171 if (msix_present(&proxy->pci_dev)) in virtio_pci_save_queue()
178 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_load_config()
182 ret = pci_device_load(&proxy->pci_dev, f); in virtio_pci_load_config()
186 msix_unuse_all_vectors(&proxy->pci_dev); in virtio_pci_load_config()
187 msix_load(&proxy->pci_dev, f); in virtio_pci_load_config()
188 if (msix_present(&proxy->pci_dev)) { in virtio_pci_load_config()
191 if (vector != VIRTIO_NO_VECTOR && vector >= proxy->nvectors) { in virtio_pci_load_config()
192 return -EINVAL; in virtio_pci_load_config()
197 vdev->config_vector = vector; in virtio_pci_load_config()
199 msix_vector_use(&proxy->pci_dev, vector); in virtio_pci_load_config()
207 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_load_queue()
210 if (msix_present(&proxy->pci_dev)) { in virtio_pci_load_queue()
212 if (vector != VIRTIO_NO_VECTOR && vector >= proxy->nvectors) { in virtio_pci_load_queue()
213 return -EINVAL; in virtio_pci_load_queue()
220 msix_vector_use(&proxy->pci_dev, vector); in virtio_pci_load_queue()
295 * zero if the device is non-transitional.
299 return virtio_pci_get_id_info(device_id)->trans_devid; in virtio_pci_get_trans_devid()
307 return virtio_pci_get_id_info(device_id)->class_id; in virtio_pci_get_class_id()
314 return (proxy->flags & VIRTIO_PCI_FLAG_USE_IOEVENTFD) != 0; in virtio_pci_ioeventfd_enabled()
321 return (proxy->flags & VIRTIO_PCI_FLAG_PAGE_PER_VQ) ? in virtio_pci_queue_mem_mult()
329 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_ioeventfd_assign()
333 bool modern_pio = proxy->flags & VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY; in virtio_pci_ioeventfd_assign()
334 MemoryRegion *modern_mr = &proxy->notify.mr; in virtio_pci_ioeventfd_assign()
335 MemoryRegion *modern_notify_mr = &proxy->notify_pio.mr; in virtio_pci_ioeventfd_assign()
336 MemoryRegion *legacy_mr = &proxy->bar; in virtio_pci_ioeventfd_assign()
373 virtio_bus_start_ioeventfd(&proxy->bus); in virtio_pci_start_ioeventfd()
378 virtio_bus_stop_ioeventfd(&proxy->bus); in virtio_pci_stop_ioeventfd()
384 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_ioport_write()
392 val = virtio_bus_get_vdev_bad_features(&proxy->bus); in virtio_ioport_write()
402 virtio_queue_set_addr(vdev, vdev->queue_sel, pa); in virtio_ioport_write()
406 vdev->queue_sel = val; in virtio_ioport_write()
430 if (vdev->status == 0) { in virtio_ioport_write()
439 pci_default_write_config(&proxy->pci_dev, PCI_COMMAND, in virtio_ioport_write()
440 proxy->pci_dev.config[PCI_COMMAND] | in virtio_ioport_write()
445 if (vdev->config_vector != VIRTIO_NO_VECTOR) { in virtio_ioport_write()
446 msix_vector_unuse(&proxy->pci_dev, vdev->config_vector); in virtio_ioport_write()
449 if (val < proxy->nvectors) { in virtio_ioport_write()
450 msix_vector_use(&proxy->pci_dev, val); in virtio_ioport_write()
454 vdev->config_vector = val; in virtio_ioport_write()
457 vector = virtio_queue_vector(vdev, vdev->queue_sel); in virtio_ioport_write()
459 msix_vector_unuse(&proxy->pci_dev, vector); in virtio_ioport_write()
462 if (val < proxy->nvectors) { in virtio_ioport_write()
463 msix_vector_use(&proxy->pci_dev, val); in virtio_ioport_write()
467 virtio_queue_set_vector(vdev, vdev->queue_sel, val); in virtio_ioport_write()
479 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_ioport_read()
484 ret = vdev->host_features; in virtio_ioport_read()
487 ret = vdev->guest_features; in virtio_ioport_read()
490 ret = virtio_queue_get_addr(vdev, vdev->queue_sel) in virtio_ioport_read()
494 ret = virtio_queue_get_num(vdev, vdev->queue_sel); in virtio_ioport_read()
497 ret = vdev->queue_sel; in virtio_ioport_read()
500 ret = vdev->status; in virtio_ioport_read()
504 ret = qatomic_xchg(&vdev->isr, 0); in virtio_ioport_read()
505 pci_irq_deassert(&proxy->pci_dev); in virtio_ioport_read()
508 ret = vdev->config_vector; in virtio_ioport_read()
511 ret = virtio_queue_vector(vdev, vdev->queue_sel); in virtio_ioport_read()
524 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_config_read()
525 uint32_t config = VIRTIO_PCI_CONFIG_SIZE(&proxy->pci_dev); in virtio_pci_config_read()
535 addr -= config; in virtio_pci_config_read()
561 uint32_t config = VIRTIO_PCI_CONFIG_SIZE(&proxy->pci_dev); in virtio_pci_config_write()
562 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_config_write()
572 addr -= config; in virtio_pci_config_write()
574 * Virtio-PCI is odd. Ioports are LE but config space is target native in virtio_pci_config_write()
612 for (i = 0; i < ARRAY_SIZE(proxy->regs); ++i) { in virtio_address_space_lookup()
613 reg = &proxy->regs[i]; in virtio_address_space_lookup()
614 if (*off >= reg->offset && in virtio_address_space_lookup()
615 *off + len <= reg->offset + reg->size) { in virtio_address_space_lookup()
616 MemoryRegionSection mrs = memory_region_find(®->mr, in virtio_address_space_lookup()
617 *off - reg->offset, len); in virtio_address_space_lookup()
633 * known-endianness integer value.
650 addr &= ~(len - 1); in virtio_address_space_write()
658 assert(!(((uintptr_t)buf) & (len - 1))); in virtio_address_space_write()
688 addr &= ~(len - 1); in virtio_address_space_read()
696 assert(!(((uintptr_t)buf) & (len - 1))); in virtio_address_space_read()
719 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_ats_ctrl_trigger()
722 vdev->device_iotlb_enabled = enable; in virtio_pci_ats_ctrl_trigger()
724 if (k->toggle_device_iotlb) { in virtio_pci_ats_ctrl_trigger()
725 k->toggle_device_iotlb(vdev); in virtio_pci_ats_ctrl_trigger()
733 uint16_t ats_cap = dev->exp.ats_cap; in pcie_ats_config_write()
738 off = address - ats_cap; in pcie_ats_config_write()
752 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_write_config()
757 if (proxy->flags & VIRTIO_PCI_FLAG_INIT_FLR) { in virtio_write_config()
761 if (proxy->flags & VIRTIO_PCI_FLAG_ATS) { in virtio_write_config()
766 if (!(pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) { in virtio_write_config()
769 virtio_set_status(vdev, vdev->status & ~VIRTIO_CONFIG_S_DRIVER_OK); in virtio_write_config()
775 if (proxy->config_cap && in virtio_write_config()
776 ranges_overlap(address, len, proxy->config_cap + offsetof(struct virtio_pci_cfg_cap, in virtio_write_config()
778 sizeof cfg->pci_cfg_data)) { in virtio_write_config()
782 cfg = (void *)(proxy->pci_dev.config + proxy->config_cap); in virtio_write_config()
783 off = le32_to_cpu(cfg->cap.offset); in virtio_write_config()
784 caplen = le32_to_cpu(cfg->cap.length); in virtio_write_config()
787 assert(caplen <= sizeof cfg->pci_cfg_data); in virtio_write_config()
788 virtio_address_space_write(proxy, off, cfg->pci_cfg_data, caplen); in virtio_write_config()
799 if (proxy->config_cap && in virtio_read_config()
800 ranges_overlap(address, len, proxy->config_cap + offsetof(struct virtio_pci_cfg_cap, in virtio_read_config()
802 sizeof cfg->pci_cfg_data)) { in virtio_read_config()
806 cfg = (void *)(proxy->pci_dev.config + proxy->config_cap); in virtio_read_config()
807 off = le32_to_cpu(cfg->cap.offset); in virtio_read_config()
808 caplen = le32_to_cpu(cfg->cap.length); in virtio_read_config()
811 assert(caplen <= sizeof cfg->pci_cfg_data); in virtio_read_config()
812 virtio_address_space_read(proxy, off, cfg->pci_cfg_data, caplen); in virtio_read_config()
822 VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector]; in kvm_virtio_pci_vq_vector_use()
825 if (irqfd->users == 0) { in kvm_virtio_pci_vq_vector_use()
827 ret = kvm_irqchip_add_msi_route(&c, vector, &proxy->pci_dev); in kvm_virtio_pci_vq_vector_use()
832 irqfd->virq = ret; in kvm_virtio_pci_vq_vector_use()
834 irqfd->users++; in kvm_virtio_pci_vq_vector_use()
841 VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector]; in kvm_virtio_pci_vq_vector_release()
842 if (--irqfd->users == 0) { in kvm_virtio_pci_vq_vector_release()
843 kvm_irqchip_release_virq(kvm_state, irqfd->virq); in kvm_virtio_pci_vq_vector_release()
851 VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector]; in kvm_virtio_pci_irqfd_use()
852 return kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, n, NULL, irqfd->virq); in kvm_virtio_pci_irqfd_use()
859 VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector]; in kvm_virtio_pci_irqfd_release()
862 ret = kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, n, irqfd->virq); in kvm_virtio_pci_irqfd_release()
868 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_get_notifier()
871 if (!proxy->vector_irqfd && vdev->status & VIRTIO_CONFIG_S_DRIVER_OK) in virtio_pci_get_notifier()
872 return -1; in virtio_pci_get_notifier()
876 *vector = vdev->config_vector; in virtio_pci_get_notifier()
879 return -1; in virtio_pci_get_notifier()
893 PCIDevice *dev = &proxy->pci_dev; in kvm_virtio_pci_vector_use_one()
894 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in kvm_virtio_pci_vector_use_one()
912 if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) { in kvm_virtio_pci_vector_use_one()
926 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in kvm_virtio_pci_vector_vq_use()
930 return -1; in kvm_virtio_pci_vector_vq_use()
945 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in kvm_virtio_pci_vector_release_one()
950 PCIDevice *dev = &proxy->pci_dev; in kvm_virtio_pci_vector_release_one()
959 if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) { in kvm_virtio_pci_vector_release_one()
968 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in kvm_virtio_pci_vector_vq_release()
989 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_one_vector_unmask()
994 if (proxy->vector_irqfd) { in virtio_pci_one_vector_unmask()
995 irqfd = &proxy->vector_irqfd[vector]; in virtio_pci_one_vector_unmask()
996 if (irqfd->msg.data != msg.data || irqfd->msg.address != msg.address) { in virtio_pci_one_vector_unmask()
997 ret = kvm_irqchip_update_msi_route(kvm_state, irqfd->virq, msg, in virtio_pci_one_vector_unmask()
998 &proxy->pci_dev); in virtio_pci_one_vector_unmask()
1009 if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) { in virtio_pci_one_vector_unmask()
1010 k->guest_notifier_mask(vdev, queue_no, false); in virtio_pci_one_vector_unmask()
1012 if (k->guest_notifier_pending && in virtio_pci_one_vector_unmask()
1013 k->guest_notifier_pending(vdev, queue_no)) { in virtio_pci_one_vector_unmask()
1027 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_one_vector_mask()
1033 if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) { in virtio_pci_one_vector_mask()
1034 k->guest_notifier_mask(vdev, queue_no, true); in virtio_pci_one_vector_mask()
1044 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_vector_unmask()
1054 if (index < proxy->nvqs_with_notifiers) { in virtio_pci_vector_unmask()
1065 if (vector == vdev->config_vector) { in virtio_pci_vector_unmask()
1081 if (index < proxy->nvqs_with_notifiers) { in virtio_pci_vector_unmask()
1084 --unmasked; in virtio_pci_vector_unmask()
1094 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_vector_mask()
1105 if (index < proxy->nvqs_with_notifiers) { in virtio_pci_vector_mask()
1111 if (vector == vdev->config_vector) { in virtio_pci_vector_mask()
1122 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_vector_poll()
1129 for (queue_no = 0; queue_no < proxy->nvqs_with_notifiers; queue_no++) { in virtio_pci_vector_poll()
1138 if (k->guest_notifier_pending) { in virtio_pci_vector_poll()
1139 if (k->guest_notifier_pending(vdev, queue_no)) { in virtio_pci_vector_poll()
1156 if (k->guest_notifier_pending) { in virtio_pci_vector_poll()
1157 if (k->guest_notifier_pending(vdev, VIRTIO_CONFIG_IRQ_IDX)) { in virtio_pci_vector_poll()
1180 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_set_guest_notifier()
1204 if (!msix_enabled(&proxy->pci_dev) && in virtio_pci_set_guest_notifier()
1205 vdev->use_guest_notifier_mask && in virtio_pci_set_guest_notifier()
1206 vdc->guest_notifier_mask) { in virtio_pci_set_guest_notifier()
1207 vdc->guest_notifier_mask(vdev, n, !assign); in virtio_pci_set_guest_notifier()
1217 if (msix_enabled(&proxy->pci_dev)) { in virtio_pci_query_guest_notifiers()
1220 return pci_irq_disabled(&proxy->pci_dev); in virtio_pci_query_guest_notifiers()
1227 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_set_guest_notifiers()
1230 bool with_irqfd = msix_enabled(&proxy->pci_dev) && in virtio_pci_set_guest_notifiers()
1240 if (!assign && !proxy->nvqs_with_notifiers) { in virtio_pci_set_guest_notifiers()
1243 assert(assign || nvqs == proxy->nvqs_with_notifiers); in virtio_pci_set_guest_notifiers()
1245 proxy->nvqs_with_notifiers = nvqs; in virtio_pci_set_guest_notifiers()
1248 if ((proxy->vector_irqfd || in virtio_pci_set_guest_notifiers()
1249 (vdev->use_guest_notifier_mask && k->guest_notifier_mask)) && in virtio_pci_set_guest_notifiers()
1251 msix_unset_vector_notifiers(&proxy->pci_dev); in virtio_pci_set_guest_notifiers()
1252 if (proxy->vector_irqfd) { in virtio_pci_set_guest_notifiers()
1255 g_free(proxy->vector_irqfd); in virtio_pci_set_guest_notifiers()
1256 proxy->vector_irqfd = NULL; in virtio_pci_set_guest_notifiers()
1277 (vdev->use_guest_notifier_mask && k->guest_notifier_mask)) && in virtio_pci_set_guest_notifiers()
1280 proxy->vector_irqfd = in virtio_pci_set_guest_notifiers()
1281 g_malloc0(sizeof(*proxy->vector_irqfd) * in virtio_pci_set_guest_notifiers()
1282 msix_nr_vectors_allocated(&proxy->pci_dev)); in virtio_pci_set_guest_notifiers()
1293 r = msix_set_vector_notifiers(&proxy->pci_dev, virtio_pci_vector_unmask, in virtio_pci_set_guest_notifiers()
1318 while (--n >= 0) { in virtio_pci_set_guest_notifiers()
1321 g_free(proxy->vector_irqfd); in virtio_pci_set_guest_notifiers()
1322 proxy->vector_irqfd = NULL; in virtio_pci_set_guest_notifiers()
1334 return -1; in virtio_pci_set_host_notifier_mr()
1339 memory_region_add_subregion_overlap(&proxy->notify.mr, offset, mr, 1); in virtio_pci_set_host_notifier_mr()
1341 memory_region_del_subregion(&proxy->notify.mr, mr); in virtio_pci_set_host_notifier_mr()
1350 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_vmstate_change()
1356 if ((proxy->flags & VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION) && in virtio_pci_vmstate_change()
1357 (vdev->status & VIRTIO_CONFIG_S_DRIVER) && in virtio_pci_vmstate_change()
1358 !(proxy->pci_dev.config[PCI_COMMAND] & PCI_COMMAND_MASTER)) { in virtio_pci_vmstate_change()
1359 pci_default_write_config(&proxy->pci_dev, PCI_COMMAND, in virtio_pci_vmstate_change()
1360 proxy->pci_dev.config[PCI_COMMAND] | in virtio_pci_vmstate_change()
1370 * virtio-pci: This is the PCIDevice which has a virtio-pci-bus.
1377 return proxy->nvectors; in virtio_pci_query_nvectors()
1383 PCIDevice *dev = &proxy->pci_dev; in virtio_pci_get_dma_as()
1391 PCIDevice *dev = &proxy->pci_dev; in virtio_pci_iommu_enabled()
1404 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_queue_enabled()
1407 return proxy->vqs[n].enabled; in virtio_pci_queue_enabled()
1416 PCIDevice *dev = &proxy->pci_dev; in virtio_pci_add_mem_cap()
1420 cap->cap_len, &error_abort); in virtio_pci_add_mem_cap()
1422 assert(cap->cap_len >= sizeof *cap); in virtio_pci_add_mem_cap()
1423 memcpy(dev->config + offset + PCI_CAP_FLAGS, &cap->cap_len, in virtio_pci_add_mem_cap()
1424 cap->cap_len - PCI_CAP_FLAGS); in virtio_pci_add_mem_cap()
1434 bool kvm_irqfd = (vdev->status & VIRTIO_CONFIG_S_DRIVER_OK) && in virtio_pci_set_vector()
1435 msix_enabled(&proxy->pci_dev) && kvm_msi_via_irqfd_enabled(); in virtio_pci_set_vector()
1451 vdev->config_vector = new_vector; in virtio_pci_set_vector()
1483 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_common_read()
1493 val = proxy->dfselect; in virtio_pci_common_read()
1496 if (proxy->dfselect <= 1) { in virtio_pci_common_read()
1499 val = (vdev->host_features & ~vdc->legacy_features) >> in virtio_pci_common_read()
1500 (32 * proxy->dfselect); in virtio_pci_common_read()
1504 val = proxy->gfselect; in virtio_pci_common_read()
1507 if (proxy->gfselect < ARRAY_SIZE(proxy->guest_features)) { in virtio_pci_common_read()
1508 val = proxy->guest_features[proxy->gfselect]; in virtio_pci_common_read()
1512 val = vdev->config_vector; in virtio_pci_common_read()
1522 val = vdev->status; in virtio_pci_common_read()
1525 val = vdev->generation; in virtio_pci_common_read()
1528 val = vdev->queue_sel; in virtio_pci_common_read()
1531 val = virtio_queue_get_num(vdev, vdev->queue_sel); in virtio_pci_common_read()
1534 val = virtio_queue_vector(vdev, vdev->queue_sel); in virtio_pci_common_read()
1537 val = proxy->vqs[vdev->queue_sel].enabled; in virtio_pci_common_read()
1541 val = vdev->queue_sel; in virtio_pci_common_read()
1544 val = proxy->vqs[vdev->queue_sel].desc[0]; in virtio_pci_common_read()
1547 val = proxy->vqs[vdev->queue_sel].desc[1]; in virtio_pci_common_read()
1550 val = proxy->vqs[vdev->queue_sel].avail[0]; in virtio_pci_common_read()
1553 val = proxy->vqs[vdev->queue_sel].avail[1]; in virtio_pci_common_read()
1556 val = proxy->vqs[vdev->queue_sel].used[0]; in virtio_pci_common_read()
1559 val = proxy->vqs[vdev->queue_sel].used[1]; in virtio_pci_common_read()
1562 val = proxy->vqs[vdev->queue_sel].reset; in virtio_pci_common_read()
1575 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_common_write()
1584 proxy->dfselect = val; in virtio_pci_common_write()
1587 proxy->gfselect = val; in virtio_pci_common_write()
1590 if (proxy->gfselect < ARRAY_SIZE(proxy->guest_features)) { in virtio_pci_common_write()
1591 proxy->guest_features[proxy->gfselect] = val; in virtio_pci_common_write()
1593 (((uint64_t)proxy->guest_features[1]) << 32) | in virtio_pci_common_write()
1594 proxy->guest_features[0]); in virtio_pci_common_write()
1598 if (vdev->config_vector != VIRTIO_NO_VECTOR) { in virtio_pci_common_write()
1599 msix_vector_unuse(&proxy->pci_dev, vdev->config_vector); in virtio_pci_common_write()
1602 if (val < proxy->nvectors) { in virtio_pci_common_write()
1603 msix_vector_use(&proxy->pci_dev, val); in virtio_pci_common_write()
1608 vdev->config_vector, val); in virtio_pci_common_write()
1621 if (vdev->status == 0) { in virtio_pci_common_write()
1628 vdev->queue_sel = val; in virtio_pci_common_write()
1632 proxy->vqs[vdev->queue_sel].num = val; in virtio_pci_common_write()
1633 virtio_queue_set_num(vdev, vdev->queue_sel, in virtio_pci_common_write()
1634 proxy->vqs[vdev->queue_sel].num); in virtio_pci_common_write()
1635 virtio_init_region_cache(vdev, vdev->queue_sel); in virtio_pci_common_write()
1638 vector = virtio_queue_vector(vdev, vdev->queue_sel); in virtio_pci_common_write()
1640 msix_vector_unuse(&proxy->pci_dev, vector); in virtio_pci_common_write()
1643 if (val < proxy->nvectors) { in virtio_pci_common_write()
1644 msix_vector_use(&proxy->pci_dev, val); in virtio_pci_common_write()
1648 virtio_pci_set_vector(vdev, proxy, vdev->queue_sel, vector, val); in virtio_pci_common_write()
1652 virtio_queue_set_num(vdev, vdev->queue_sel, in virtio_pci_common_write()
1653 proxy->vqs[vdev->queue_sel].num); in virtio_pci_common_write()
1654 virtio_queue_set_rings(vdev, vdev->queue_sel, in virtio_pci_common_write()
1655 ((uint64_t)proxy->vqs[vdev->queue_sel].desc[1]) << 32 | in virtio_pci_common_write()
1656 proxy->vqs[vdev->queue_sel].desc[0], in virtio_pci_common_write()
1657 ((uint64_t)proxy->vqs[vdev->queue_sel].avail[1]) << 32 | in virtio_pci_common_write()
1658 proxy->vqs[vdev->queue_sel].avail[0], in virtio_pci_common_write()
1659 ((uint64_t)proxy->vqs[vdev->queue_sel].used[1]) << 32 | in virtio_pci_common_write()
1660 proxy->vqs[vdev->queue_sel].used[0]); in virtio_pci_common_write()
1661 proxy->vqs[vdev->queue_sel].enabled = 1; in virtio_pci_common_write()
1662 proxy->vqs[vdev->queue_sel].reset = 0; in virtio_pci_common_write()
1663 virtio_queue_enable(vdev, vdev->queue_sel); in virtio_pci_common_write()
1669 proxy->vqs[vdev->queue_sel].desc[0] = val; in virtio_pci_common_write()
1672 proxy->vqs[vdev->queue_sel].desc[1] = val; in virtio_pci_common_write()
1675 proxy->vqs[vdev->queue_sel].avail[0] = val; in virtio_pci_common_write()
1678 proxy->vqs[vdev->queue_sel].avail[1] = val; in virtio_pci_common_write()
1681 proxy->vqs[vdev->queue_sel].used[0] = val; in virtio_pci_common_write()
1684 proxy->vqs[vdev->queue_sel].used[1] = val; in virtio_pci_common_write()
1688 proxy->vqs[vdev->queue_sel].reset = 1; in virtio_pci_common_write()
1690 virtio_queue_reset(vdev, vdev->queue_sel); in virtio_pci_common_write()
1692 proxy->vqs[vdev->queue_sel].reset = 0; in virtio_pci_common_write()
1693 proxy->vqs[vdev->queue_sel].enabled = 0; in virtio_pci_common_write()
1706 if (virtio_bus_get_device(&proxy->bus) == NULL) { in virtio_pci_notify_read()
1717 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_notify_write()
1731 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_notify_write_pio()
1745 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_isr_read()
1752 val = qatomic_xchg(&vdev->isr, 0); in virtio_pci_isr_read()
1753 pci_irq_deassert(&proxy->pci_dev); in virtio_pci_isr_read()
1766 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_device_read()
1794 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_device_write()
1863 g_string_printf(name, "virtio-pci-common-%s", vdev_name); in virtio_pci_modern_regions_init()
1864 memory_region_init_io(&proxy->common.mr, OBJECT(proxy), in virtio_pci_modern_regions_init()
1867 name->str, in virtio_pci_modern_regions_init()
1868 proxy->common.size); in virtio_pci_modern_regions_init()
1870 g_string_printf(name, "virtio-pci-isr-%s", vdev_name); in virtio_pci_modern_regions_init()
1871 memory_region_init_io(&proxy->isr.mr, OBJECT(proxy), in virtio_pci_modern_regions_init()
1874 name->str, in virtio_pci_modern_regions_init()
1875 proxy->isr.size); in virtio_pci_modern_regions_init()
1877 g_string_printf(name, "virtio-pci-device-%s", vdev_name); in virtio_pci_modern_regions_init()
1878 memory_region_init_io(&proxy->device.mr, OBJECT(proxy), in virtio_pci_modern_regions_init()
1881 name->str, in virtio_pci_modern_regions_init()
1882 proxy->device.size); in virtio_pci_modern_regions_init()
1884 g_string_printf(name, "virtio-pci-notify-%s", vdev_name); in virtio_pci_modern_regions_init()
1885 memory_region_init_io(&proxy->notify.mr, OBJECT(proxy), in virtio_pci_modern_regions_init()
1888 name->str, in virtio_pci_modern_regions_init()
1889 proxy->notify.size); in virtio_pci_modern_regions_init()
1891 g_string_printf(name, "virtio-pci-notify-pio-%s", vdev_name); in virtio_pci_modern_regions_init()
1892 memory_region_init_io(&proxy->notify_pio.mr, OBJECT(proxy), in virtio_pci_modern_regions_init()
1895 name->str, in virtio_pci_modern_regions_init()
1896 proxy->notify_pio.size); in virtio_pci_modern_regions_init()
1905 memory_region_add_subregion(mr, region->offset, ®ion->mr); in virtio_pci_modern_region_map()
1907 cap->cfg_type = region->type; in virtio_pci_modern_region_map()
1908 cap->bar = bar; in virtio_pci_modern_region_map()
1909 cap->offset = cpu_to_le32(region->offset); in virtio_pci_modern_region_map()
1910 cap->length = cpu_to_le32(region->size); in virtio_pci_modern_region_map()
1920 &proxy->modern_bar, proxy->modern_mem_bar_idx); in virtio_pci_modern_mem_region_map()
1928 &proxy->io_bar, proxy->modern_io_bar_idx); in virtio_pci_modern_io_region_map()
1934 memory_region_del_subregion(&proxy->modern_bar, in virtio_pci_modern_mem_region_unmap()
1935 ®ion->mr); in virtio_pci_modern_mem_region_unmap()
1941 memory_region_del_subregion(&proxy->io_bar, in virtio_pci_modern_io_region_unmap()
1942 ®ion->mr); in virtio_pci_modern_io_region_unmap()
1948 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_pre_plugged()
1951 virtio_add_feature(&vdev->host_features, VIRTIO_F_VERSION_1); in virtio_pci_pre_plugged()
1954 virtio_add_feature(&vdev->host_features, VIRTIO_F_BAD_FEATURE); in virtio_pci_pre_plugged()
1957 /* This is called by virtio-bus just after the device is plugged. */
1961 VirtioBusState *bus = &proxy->bus; in virtio_pci_device_plugged()
1964 bool modern_pio = proxy->flags & VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY; in virtio_pci_device_plugged()
1974 if (!proxy->ignore_backend_features && in virtio_pci_device_plugged()
1975 !virtio_has_feature(vdev->host_features, VIRTIO_F_VERSION_1)) { in virtio_pci_device_plugged()
1981 error_append_hint(errp, "Set disable-legacy to off\n"); in virtio_pci_device_plugged()
1989 config = proxy->pci_dev.config; in virtio_pci_device_plugged()
1990 if (proxy->class_code) { in virtio_pci_device_plugged()
1991 pci_config_set_class(config, proxy->class_code); in virtio_pci_device_plugged()
2001 warn_report("device is modern-only, but for backward " in virtio_pci_device_plugged()
2005 "device is modern-only, use disable-legacy=on"); in virtio_pci_device_plugged()
2020 if (proxy->trans_devid) { in virtio_pci_device_plugged()
2021 pci_config_set_device_id(config, proxy->trans_devid); in virtio_pci_device_plugged()
2024 /* pure virtio-1.0 */ in virtio_pci_device_plugged()
2054 virtio_pci_modern_regions_init(proxy, vdev->name); in virtio_pci_device_plugged()
2056 virtio_pci_modern_mem_region_map(proxy, &proxy->common, &cap); in virtio_pci_device_plugged()
2057 virtio_pci_modern_mem_region_map(proxy, &proxy->isr, &cap); in virtio_pci_device_plugged()
2058 virtio_pci_modern_mem_region_map(proxy, &proxy->device, &cap); in virtio_pci_device_plugged()
2059 virtio_pci_modern_mem_region_map(proxy, &proxy->notify, ¬ify.cap); in virtio_pci_device_plugged()
2062 memory_region_init(&proxy->io_bar, OBJECT(proxy), in virtio_pci_device_plugged()
2063 "virtio-pci-io", 0x4); in virtio_pci_device_plugged()
2064 address_space_init(&proxy->modern_cfg_io_as, &proxy->io_bar, in virtio_pci_device_plugged()
2065 "virtio-pci-cfg-io-as"); in virtio_pci_device_plugged()
2067 pci_register_bar(&proxy->pci_dev, proxy->modern_io_bar_idx, in virtio_pci_device_plugged()
2068 PCI_BASE_ADDRESS_SPACE_IO, &proxy->io_bar); in virtio_pci_device_plugged()
2070 virtio_pci_modern_io_region_map(proxy, &proxy->notify_pio, in virtio_pci_device_plugged()
2074 pci_register_bar(&proxy->pci_dev, proxy->modern_mem_bar_idx, in virtio_pci_device_plugged()
2078 &proxy->modern_bar); in virtio_pci_device_plugged()
2080 proxy->config_cap = virtio_pci_add_mem_cap(proxy, &cfg.cap); in virtio_pci_device_plugged()
2081 cfg_mask = (void *)(proxy->pci_dev.wmask + proxy->config_cap); in virtio_pci_device_plugged()
2082 pci_set_byte(&cfg_mask->cap.bar, ~0x0); in virtio_pci_device_plugged()
2083 pci_set_long((uint8_t *)&cfg_mask->cap.offset, ~0x0); in virtio_pci_device_plugged()
2084 pci_set_long((uint8_t *)&cfg_mask->cap.length, ~0x0); in virtio_pci_device_plugged()
2085 pci_set_long(cfg_mask->pci_cfg_data, ~0x0); in virtio_pci_device_plugged()
2088 if (proxy->nvectors) { in virtio_pci_device_plugged()
2089 int err = msix_init_exclusive_bar(&proxy->pci_dev, proxy->nvectors, in virtio_pci_device_plugged()
2090 proxy->msix_bar_idx, NULL); in virtio_pci_device_plugged()
2093 if (err != -ENOTSUP) { in virtio_pci_device_plugged()
2095 proxy->nvectors); in virtio_pci_device_plugged()
2097 proxy->nvectors = 0; in virtio_pci_device_plugged()
2101 proxy->pci_dev.config_write = virtio_write_config; in virtio_pci_device_plugged()
2102 proxy->pci_dev.config_read = virtio_read_config; in virtio_pci_device_plugged()
2105 size = VIRTIO_PCI_REGION_SIZE(&proxy->pci_dev) in virtio_pci_device_plugged()
2109 memory_region_init_io(&proxy->bar, OBJECT(proxy), in virtio_pci_device_plugged()
2111 proxy, "virtio-pci", size); in virtio_pci_device_plugged()
2113 pci_register_bar(&proxy->pci_dev, proxy->legacy_io_bar_idx, in virtio_pci_device_plugged()
2114 PCI_BASE_ADDRESS_SPACE_IO, &proxy->bar); in virtio_pci_device_plugged()
2117 if (pci_is_vf(&proxy->pci_dev)) { in virtio_pci_device_plugged()
2118 pcie_ari_init(&proxy->pci_dev, proxy->last_pcie_cap_offset); in virtio_pci_device_plugged()
2119 proxy->last_pcie_cap_offset += PCI_ARI_SIZEOF; in virtio_pci_device_plugged()
2122 &proxy->pci_dev, proxy->last_pcie_cap_offset, errp); in virtio_pci_device_plugged()
2124 proxy->last_pcie_cap_offset += res; in virtio_pci_device_plugged()
2125 virtio_add_feature(&vdev->host_features, VIRTIO_F_SR_IOV); in virtio_pci_device_plugged()
2134 bool modern_pio = proxy->flags & VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY; in virtio_pci_device_unplugged()
2139 virtio_pci_modern_mem_region_unmap(proxy, &proxy->common); in virtio_pci_device_unplugged()
2140 virtio_pci_modern_mem_region_unmap(proxy, &proxy->isr); in virtio_pci_device_unplugged()
2141 virtio_pci_modern_mem_region_unmap(proxy, &proxy->device); in virtio_pci_device_unplugged()
2142 virtio_pci_modern_mem_region_unmap(proxy, &proxy->notify); in virtio_pci_device_unplugged()
2144 virtio_pci_modern_io_region_unmap(proxy, &proxy->notify_pio); in virtio_pci_device_unplugged()
2156 /* fd-based ioevents can't be synchronized in record/replay */ in virtio_pci_realize()
2158 proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD; in virtio_pci_realize()
2163 * subclasses can re-arrange things if needed. in virtio_pci_realize()
2165 * region 0 -- virtio legacy io bar in virtio_pci_realize()
2166 * region 1 -- msi-x bar in virtio_pci_realize()
2167 * region 2 -- virtio modern io bar (off by default) in virtio_pci_realize()
2168 * region 4+5 -- virtio modern memory (64bit) bar in virtio_pci_realize()
2171 proxy->legacy_io_bar_idx = 0; in virtio_pci_realize()
2172 proxy->msix_bar_idx = 1; in virtio_pci_realize()
2173 proxy->modern_io_bar_idx = 2; in virtio_pci_realize()
2174 proxy->modern_mem_bar_idx = 4; in virtio_pci_realize()
2176 proxy->common.offset = 0x0; in virtio_pci_realize()
2177 proxy->common.size = 0x1000; in virtio_pci_realize()
2178 proxy->common.type = VIRTIO_PCI_CAP_COMMON_CFG; in virtio_pci_realize()
2180 proxy->isr.offset = 0x1000; in virtio_pci_realize()
2181 proxy->isr.size = 0x1000; in virtio_pci_realize()
2182 proxy->isr.type = VIRTIO_PCI_CAP_ISR_CFG; in virtio_pci_realize()
2184 proxy->device.offset = 0x2000; in virtio_pci_realize()
2185 proxy->device.size = 0x1000; in virtio_pci_realize()
2186 proxy->device.type = VIRTIO_PCI_CAP_DEVICE_CFG; in virtio_pci_realize()
2188 proxy->notify.offset = 0x3000; in virtio_pci_realize()
2189 proxy->notify.size = virtio_pci_queue_mem_mult(proxy) * VIRTIO_QUEUE_MAX; in virtio_pci_realize()
2190 proxy->notify.type = VIRTIO_PCI_CAP_NOTIFY_CFG; in virtio_pci_realize()
2192 proxy->notify_pio.offset = 0x0; in virtio_pci_realize()
2193 proxy->notify_pio.size = 0x4; in virtio_pci_realize()
2194 proxy->notify_pio.type = VIRTIO_PCI_CAP_NOTIFY_CFG; in virtio_pci_realize()
2197 memory_region_init(&proxy->modern_bar, OBJECT(proxy), "virtio-pci", in virtio_pci_realize()
2199 pow2ceil(proxy->notify.offset + proxy->notify.size)); in virtio_pci_realize()
2201 address_space_init(&proxy->modern_cfg_mem_as, &proxy->modern_bar, in virtio_pci_realize()
2202 "virtio-pci-cfg-mem-as"); in virtio_pci_realize()
2204 if (proxy->disable_legacy == ON_OFF_AUTO_AUTO) { in virtio_pci_realize()
2205 proxy->disable_legacy = pcie_port ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF; in virtio_pci_realize()
2211 error_append_hint(errp, "Set either disable-modern or disable-legacy" in virtio_pci_realize()
2218 proxy->last_pcie_cap_offset = PCI_CONFIG_SPACE_SIZE; in virtio_pci_realize()
2232 pci_set_word(pci_dev->config + pos + PCI_PM_PMC, 0x3); in virtio_pci_realize()
2234 if (proxy->flags & VIRTIO_PCI_FLAG_AER) { in virtio_pci_realize()
2235 pcie_aer_init(pci_dev, PCI_ERR_VER, proxy->last_pcie_cap_offset, in virtio_pci_realize()
2237 proxy->last_pcie_cap_offset += PCI_ERR_SIZEOF; in virtio_pci_realize()
2240 if (proxy->flags & VIRTIO_PCI_FLAG_INIT_DEVERR) { in virtio_pci_realize()
2245 if (proxy->flags & VIRTIO_PCI_FLAG_INIT_LNKCTL) { in virtio_pci_realize()
2250 if (proxy->flags & VIRTIO_PCI_FLAG_PM_NO_SOFT_RESET) { in virtio_pci_realize()
2251 pci_set_word(pci_dev->config + pos + PCI_PM_CTRL, in virtio_pci_realize()
2255 if (proxy->flags & VIRTIO_PCI_FLAG_INIT_PM) { in virtio_pci_realize()
2257 pci_set_word(pci_dev->wmask + pos + PCI_PM_CTRL, in virtio_pci_realize()
2261 if (proxy->flags & VIRTIO_PCI_FLAG_ATS) { in virtio_pci_realize()
2262 pcie_ats_init(pci_dev, proxy->last_pcie_cap_offset, in virtio_pci_realize()
2263 proxy->flags & VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED); in virtio_pci_realize()
2264 proxy->last_pcie_cap_offset += PCI_EXT_CAP_ATS_SIZEOF; in virtio_pci_realize()
2267 if (proxy->flags & VIRTIO_PCI_FLAG_INIT_FLR) { in virtio_pci_realize()
2276 pci_dev->cap_present &= ~QEMU_PCI_CAP_EXPRESS; in virtio_pci_realize()
2279 virtio_pci_bus_new(&proxy->bus, sizeof(proxy->bus), proxy); in virtio_pci_realize()
2280 if (k->realize) { in virtio_pci_realize()
2281 k->realize(proxy, errp); in virtio_pci_realize()
2290 bool modern_pio = proxy->flags & VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY; in virtio_pci_exit()
2292 pcie_sriov_pf_exit(&proxy->pci_dev); in virtio_pci_exit()
2294 if (proxy->flags & VIRTIO_PCI_FLAG_AER && pcie_port && in virtio_pci_exit()
2298 address_space_destroy(&proxy->modern_cfg_mem_as); in virtio_pci_exit()
2300 address_space_destroy(&proxy->modern_cfg_io_as); in virtio_pci_exit()
2307 VirtioBusState *bus = VIRTIO_BUS(&proxy->bus); in virtio_pci_reset()
2311 msix_unuse_all_vectors(&proxy->pci_dev); in virtio_pci_reset()
2314 proxy->vqs[i].enabled = 0; in virtio_pci_reset()
2315 proxy->vqs[i].reset = 0; in virtio_pci_reset()
2316 proxy->vqs[i].num = 0; in virtio_pci_reset()
2317 proxy->vqs[i].desc[0] = proxy->vqs[i].desc[1] = 0; in virtio_pci_reset()
2318 proxy->vqs[i].avail[0] = proxy->vqs[i].avail[1] = 0; in virtio_pci_reset()
2319 proxy->vqs[i].used[0] = proxy->vqs[i].used[1] = 0; in virtio_pci_reset()
2327 if (!pci_is_express(dev) || !(dev->cap_present & QEMU_PCI_CAP_PM)) { in virtio_pci_no_soft_reset()
2331 pmcsr = pci_get_word(dev->config + dev->pm_cap + PCI_PM_CTRL); in virtio_pci_no_soft_reset()
2358 if (proxy->flags & VIRTIO_PCI_FLAG_INIT_PM) { in virtio_pci_bus_reset_hold()
2360 dev->config + dev->pm_cap + PCI_PM_CTRL, in virtio_pci_bus_reset_hold()
2367 DEFINE_PROP_BIT("virtio-pci-bus-master-bug-migration", VirtIOPCIProxy, flags,
2369 DEFINE_PROP_BIT("modern-pio-notify", VirtIOPCIProxy, flags,
2371 DEFINE_PROP_BIT("page-per-vq", VirtIOPCIProxy, flags,
2373 DEFINE_PROP_BOOL("x-ignore-backend-features", VirtIOPCIProxy,
2377 DEFINE_PROP_BIT("x-ats-page-aligned", VirtIOPCIProxy, flags,
2379 DEFINE_PROP_BIT("x-pcie-deverr-init", VirtIOPCIProxy, flags,
2381 DEFINE_PROP_BIT("x-pcie-lnkctl-init", VirtIOPCIProxy, flags,
2383 DEFINE_PROP_BIT("x-pcie-pm-init", VirtIOPCIProxy, flags,
2385 DEFINE_PROP_BIT("x-pcie-pm-no-soft-reset", VirtIOPCIProxy, flags,
2387 DEFINE_PROP_BIT("x-pcie-flr-init", VirtIOPCIProxy, flags,
2397 PCIDevice *pci_dev = &proxy->pci_dev; in virtio_pci_dc_realize()
2400 pci_dev->cap_present |= QEMU_PCI_CAP_EXPRESS; in virtio_pci_dc_realize()
2403 vpciklass->parent_dc_realize(qdev, errp); in virtio_pci_dc_realize()
2409 VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); in virtio_pci_sync_config()
2422 k->realize = virtio_pci_realize; in virtio_pci_class_init()
2423 k->exit = virtio_pci_exit; in virtio_pci_class_init()
2424 k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; in virtio_pci_class_init()
2425 k->revision = VIRTIO_PCI_ABI_VERSION; in virtio_pci_class_init()
2426 k->class_id = PCI_CLASS_OTHERS; in virtio_pci_class_init()
2428 &vpciklass->parent_dc_realize); in virtio_pci_class_init()
2429 rc->phases.hold = virtio_pci_bus_reset_hold; in virtio_pci_class_init()
2430 dc->sync_config = virtio_pci_sync_config; in virtio_pci_class_init()
2443 DEFINE_PROP_ON_OFF_AUTO("disable-legacy", VirtIOPCIProxy, disable_legacy,
2445 DEFINE_PROP_BOOL("disable-modern", VirtIOPCIProxy, disable_modern, false),
2451 if (t->class_init) { in virtio_pci_base_class_init()
2452 t->class_init(klass, NULL); in virtio_pci_base_class_init()
2467 proxy->disable_legacy = ON_OFF_AUTO_OFF; in virtio_pci_transitional_instance_init()
2468 proxy->disable_modern = false; in virtio_pci_transitional_instance_init()
2475 proxy->disable_legacy = ON_OFF_AUTO_ON; in virtio_pci_non_transitional_instance_init()
2476 proxy->disable_modern = false; in virtio_pci_non_transitional_instance_init()
2483 .name = t->base_name, in virtio_pci_types_register()
2484 .parent = t->parent ? t->parent : TYPE_VIRTIO_PCI, in virtio_pci_types_register()
2485 .instance_size = t->instance_size, in virtio_pci_types_register()
2486 .instance_init = t->instance_init, in virtio_pci_types_register()
2487 .instance_finalize = t->instance_finalize, in virtio_pci_types_register()
2488 .class_size = t->class_size, in virtio_pci_types_register()
2490 .interfaces = t->interfaces, in virtio_pci_types_register()
2493 .name = t->generic_name, in virtio_pci_types_register()
2504 /* No base type -> register a single generic device type */ in virtio_pci_types_register()
2505 /* use intermediate %s-base-type to add generic device props */ in virtio_pci_types_register()
2506 base_name = g_strdup_printf("%s-base-type", t->generic_name); in virtio_pci_types_register()
2514 assert(!t->non_transitional_name); in virtio_pci_types_register()
2515 assert(!t->transitional_name); in virtio_pci_types_register()
2526 if (t->non_transitional_name) { in virtio_pci_types_register()
2528 .name = t->non_transitional_name, in virtio_pci_types_register()
2540 if (t->transitional_name) { in virtio_pci_types_register()
2542 .name = t->transitional_name, in virtio_pci_types_register()
2567 * Virtqueues consume guest RAM and MSI-X vectors. This is wasteful in in virtio_pci_optimal_num_queues()
2575 unsigned num_queues = current_machine->smp.cpus; in virtio_pci_optimal_num_queues()
2578 * The maximum number of MSI-X vectors is PCI_MSIX_FLAGS_QSIZE + 1, but the in virtio_pci_optimal_num_queues()
2582 num_queues = MIN(num_queues, PCI_MSIX_FLAGS_QSIZE - fixed_queues); in virtio_pci_optimal_num_queues()
2587 return MIN(num_queues, VIRTIO_QUEUE_MAX - fixed_queues); in virtio_pci_optimal_num_queues()
2590 /* virtio-pci-bus */
2596 char virtio_bus_name[] = "virtio-bus"; in virtio_pci_bus_new()
2605 bus_class->max_dev = 1; in virtio_pci_bus_class_init()
2606 k->notify = virtio_pci_notify; in virtio_pci_bus_class_init()
2607 k->save_config = virtio_pci_save_config; in virtio_pci_bus_class_init()
2608 k->load_config = virtio_pci_load_config; in virtio_pci_bus_class_init()
2609 k->save_queue = virtio_pci_save_queue; in virtio_pci_bus_class_init()
2610 k->load_queue = virtio_pci_load_queue; in virtio_pci_bus_class_init()
2611 k->save_extra_state = virtio_pci_save_extra_state; in virtio_pci_bus_class_init()
2612 k->load_extra_state = virtio_pci_load_extra_state; in virtio_pci_bus_class_init()
2613 k->has_extra_state = virtio_pci_has_extra_state; in virtio_pci_bus_class_init()
2614 k->query_guest_notifiers = virtio_pci_query_guest_notifiers; in virtio_pci_bus_class_init()
2615 k->set_guest_notifiers = virtio_pci_set_guest_notifiers; in virtio_pci_bus_class_init()
2616 k->set_host_notifier_mr = virtio_pci_set_host_notifier_mr; in virtio_pci_bus_class_init()
2617 k->vmstate_change = virtio_pci_vmstate_change; in virtio_pci_bus_class_init()
2618 k->pre_plugged = virtio_pci_pre_plugged; in virtio_pci_bus_class_init()
2619 k->device_plugged = virtio_pci_device_plugged; in virtio_pci_bus_class_init()
2620 k->device_unplugged = virtio_pci_device_unplugged; in virtio_pci_bus_class_init()
2621 k->query_nvectors = virtio_pci_query_nvectors; in virtio_pci_bus_class_init()
2622 k->ioeventfd_enabled = virtio_pci_ioeventfd_enabled; in virtio_pci_bus_class_init()
2623 k->ioeventfd_assign = virtio_pci_ioeventfd_assign; in virtio_pci_bus_class_init()
2624 k->get_dma_as = virtio_pci_get_dma_as; in virtio_pci_bus_class_init()
2625 k->iommu_enabled = virtio_pci_iommu_enabled; in virtio_pci_bus_class_init()
2626 k->queue_enabled = virtio_pci_queue_enabled; in virtio_pci_bus_class_init()