From 40fb6ef556df1efb72f3f53809cf8f921faadbc3 Mon Sep 17 00:00:00 2001 From: Asias He Date: Sat, 7 Aug 2010 14:47:25 +0800 Subject: [PATCH] kvm, pci: fill up virtio device configuration header IO base address register must be aligned at 4 bytes. Memory base address register must be aligned at 16 bytes. We should not shift io port or memory address in base address register. See PCI_System_Architecture_FourthEdition Page 427. We need more io space for virtio device, qemu-kvm uses 64 byes, so io space reserved for bios is not enough. See drivers/virtio/virtio_pci.c static struct virtio_config_ops virtio_pci_config_ops = { .get = vp_get, .set = vp_set, .get_status = vp_get_status, .set_status = vp_set_status, .reset = vp_reset, .find_vqs = vp_find_vqs, .del_vqs = vp_del_vqs, .get_features = vp_get_features, .finalize_features = vp_finalize_features, }; --------------------------------------------------------------------- guest_using_virtio_blk $ lspci -xxx 00:04.0 SCSI storage controller: Qumranet, Inc. Virtio block device 00: f4 1a 01 10 03 00 10 00 00 00 00 01 00 00 00 00 10: 01 c2 00 00 00 00 03 f2 00 00 00 00 00 00 00 00 20: 00 00 00 00 00 00 00 00 00 00 00 00 f4 1a 02 00 30: 00 00 00 00 40 00 00 00 00 00 00 00 0b 01 00 00 40: 11 00 01 80 01 00 00 00 01 08 00 00 00 00 00 00 50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------- guest_using_virtio_blk $ cat /proc/iomem f2030000-f2030fff : 0000:00:04.0 f2030000-f2030fff : virtio-pci --------------------------------------------------------------------- guest_using_virtio_blk $ cat /proc/ioports c200-c23f : 0000:00:04.0 c200-c23f : virtio-pci --------------------------------------------------------------------- $ ./kvm bzImage #virtio enabled guest kernel Logs: [ 0.548000] virtio-pci 0000:00:01.0: enabling device (0000 -> 0001) [ 0.549000] asias:drivers/virtio/virtio.c:virtio_dev_probe [ 0.549000] asias:drivers/virtio/virtio_pci.c:vp_get_features Info: virtio_io [ 0.549000] asias:drivers/block/virtio_blk.c:virtblk_probe [ 0.549000] virtio_blk: probe of virtio0 failed with error -16 Signed-off-by: Asias He Signed-off-by: Pekka Enberg --- tools/kvm/include/kvm/ioport.h | 2 +- tools/kvm/pci.c | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tools/kvm/include/kvm/ioport.h b/tools/kvm/include/kvm/ioport.h index 42438500a1ee..75678c0974a5 100644 --- a/tools/kvm/include/kvm/ioport.h +++ b/tools/kvm/include/kvm/ioport.h @@ -6,7 +6,7 @@ /* some ports we reserve for own use */ #define IOPORT_DBG 0xe0 -#define IOPORT_VIRTIO 0xea +#define IOPORT_VIRTIO 0xc200 struct kvm; diff --git a/tools/kvm/pci.c b/tools/kvm/pci.c index 13414940f280..39db138a7c31 100644 --- a/tools/kvm/pci.c +++ b/tools/kvm/pci.c @@ -34,15 +34,20 @@ static bool pci_config_data_out(struct kvm *self, uint16_t port, void *data, int return true; } -#define PCI_VENDOR_ID_REDHAT_QUMRANET 0x1af4 -#define PCI_DEVICE_ID_VIRTIO_BLK 0x1001 +#define PCI_VENDOR_ID_REDHAT_QUMRANET 0x1af4 +#define PCI_DEVICE_ID_VIRTIO_BLK 0x1001 +#define PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET 0x1af4 +#define PCI_SUBSYSTEM_ID_VIRTIO_BLK 0x0002 static struct pci_device_header virtio_device = { .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET, .device_id = PCI_DEVICE_ID_VIRTIO_BLK, .header_type = PCI_HEADER_TYPE_NORMAL, - /* .class = (0x01 << 16) | (0x01 << 8) | ((1<<7) | * (1<<1)), */ - .bar[0] = (IOPORT_VIRTIO << 4) | PCI_BASE_ADDRESS_SPACE_IO, + .revision_id = 0, + .class = 0x010000, + .subsys_vendor_id = PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET, + .subsys_id = PCI_SUBSYSTEM_ID_VIRTIO_BLK, + .bar[0] = IOPORT_VIRTIO | PCI_BASE_ADDRESS_SPACE_IO, }; static bool pci_device_matches(uint8_t bus_number, uint8_t device_number, uint8_t function_number) -- 2.39.5