vring: create a common function to parse descriptors

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
vring: factor common code for error exits

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
dataplane: change vring API to use VirtQueueElement

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
dataplane: replace hostmem with memory_region_find

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qdev: document assumption that unrealize is followed by finalize

This becomes important when undoing realize's initializations is split
in two places (unrealize and exit).

The way to fix this could be to split realize further in "alloc" (done
only one) and "realize" (can be undone).

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
pci: split exit and finalize

When converting devices to use out-of-BQL memory access, destruction
needs to be done in two phases.  First, the device is unrealized;
at this point, pending memory accesses can still be completed, but
no new accesses will be started.  The second part is freeing the
device, which happens only after the reference count drops to zero;
this means that all memory accesses are complete.

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
ac97: move memory_region_destroy to instance_finalize

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
es1370: move memory_region_destroy to instance_finalize

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
hda: move memory_region_destroy to instance_finalize

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
nvme: move memory_region_destroy of BARs to instance_finalize

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
serial: move memory_region_destroy to instance_finalize

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tpci200: move memory_region_destroy to instance_finalize

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
pci-assign: move memory_region_destroy of BARs to instance_finalize

free_assigned_device is also doing memory_region_del_subregion for the
"real_iomem" regions.  This is not a problem, because these regions are
always nested in a container region; these container regions are passed
to pci_register_bar and are unreachable after pci_unregister_io_regions
returns, hence the same thing is true of "real_iomem" regions.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
ahci: move memory_region_destroy of BARs to instance_finalize

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
ide/cmd646: move memory_region_destroy of BARs to instance_finalize

Subregions of the bmdma_bar are removed from their parent in
pci_cmd646_ide_instance_finalize.  This is not a problem: the BAR itself
is not reachable from the guest after pci_unregister_io_regions returns,
and the same thing is true of its subregions.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
ide/piix: move memory_region_destroy of BARs to instance_finalize

Subregions of the bmdma_bar are removed from their parent in
pci_piix_ide_instance_finalize.  This is not a problem: the BAR itself
is not reachable from the guest after pci_unregister_io_regions returns,
and the same thing is true of its subregions.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
ide/via: move memory_region_destroy of BARs to instance_finalize

Subregions of the bmdma_bar are removed from their parent in
vt82c686b_ide_instance_finalize.  This is not a problem: the BAR itself
is not reachable from the guest after pci_unregister_io_regions returns,
and the same thing is true of its subregions.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
ivshmem: move memory_region_destroy of BARs to instance_finalize

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
pci-testdev: move memory_region_destroy of BARs to instance_finalize

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
vfio: move memory_region_destroy of BARs to instance_finalize

And also what came after it in vfio_exitfn, because instance_finalize will
also handle the error paths in vfio_initfn.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>