Put together the common parts of all virtio device initialization.
Signed-off-by: Paolo Bonzini pbonzini@redhat.com --- src/virtio-blk.c | 9 +-------- src/virtio-pci.c | 11 +++++++++++ src/virtio-pci.h | 1 + 3 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/src/virtio-blk.c b/src/virtio-blk.c index a81a873..9ed82e0 100644 --- a/src/virtio-blk.c +++ b/src/virtio-blk.c @@ -114,15 +114,8 @@ init_virtio_blk(struct pci_device *pci) vdrive_g->drive.cntl_id = bdf; vdrive_g->vq = vq;
- u16 ioaddr = pci_config_readl(bdf, PCI_BASE_ADDRESS_0) & - PCI_BASE_ADDRESS_IO_MASK; - + u16 ioaddr = vp_init_simple(bdf); vdrive_g->ioaddr = ioaddr; - - vp_reset(ioaddr); - vp_set_status(ioaddr, VIRTIO_CONFIG_S_ACKNOWLEDGE | - VIRTIO_CONFIG_S_DRIVER ); - if (vp_find_vq(ioaddr, 0, vdrive_g->vq) < 0 ) { dprintf(1, "fail to find vq for virtio-blk %x:%x\n", pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf)); diff --git a/src/virtio-pci.c b/src/virtio-pci.c index db19e97..6a23d5d 100644 --- a/src/virtio-pci.c +++ b/src/virtio-pci.c @@ -67,3 +67,14 @@ int vp_find_vq(unsigned int ioaddr, int queue_index,
return num; } + +u16 vp_init_simple(u16 bdf) +{ + u16 ioaddr = pci_config_readl(bdf, PCI_BASE_ADDRESS_0) & + PCI_BASE_ADDRESS_IO_MASK; + + vp_reset(ioaddr); + vp_set_status(ioaddr, VIRTIO_CONFIG_S_ACKNOWLEDGE | + VIRTIO_CONFIG_S_DRIVER ); + return ioaddr; +} diff --git a/src/virtio-pci.h b/src/virtio-pci.h index d21d5a5..60e7b35 100644 --- a/src/virtio-pci.h +++ b/src/virtio-pci.h @@ -99,6 +99,7 @@ static inline void vp_del_vq(unsigned int ioaddr, int queue_index) }
struct vring_virtqueue; +u16 vp_init_simple(u16 bdf); int vp_find_vq(unsigned int ioaddr, int queue_index, struct vring_virtqueue *vq); #endif /* _VIRTIO_PCI_H_ */