]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Add helper to retrieve the field used in virtio config space
authorSasha Levin <levinsasha928@gmail.com>
Sun, 21 Aug 2011 10:16:34 +0000 (13:16 +0300)
committerPekka Enberg <penberg@kernel.org>
Sun, 21 Aug 2011 17:34:29 +0000 (20:34 +0300)
This patch adds a helper used to retrieve the type of field used when guest
is writing or reading from virtio config space.

Since the config space is dynamic, it may change during runtime - so we must
calculate it before every read/write.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/include/kvm/virtio.h
tools/kvm/virtio/core.c

index b96270574261660d6b353fa5b5af8a60310a6420..34423389b74295e2e1a91315908a8d9f598824e1 100644 (file)
 #define VIRTIO_IRQ_LOW         0
 #define VIRTIO_IRQ_HIGH                1
 
+#define VIRTIO_PCI_O_CONFIG    0
+#define VIRTIO_PCI_O_MSIX      1
+#define VIRTIO_PCI_O_FEATURES  2
+
 struct virt_queue {
        struct vring    vring;
        u32             pfn;
@@ -56,4 +60,6 @@ u16 virt_queue__get_inout_iov(struct kvm *kvm, struct virt_queue *queue,
 
 void virt_queue__trigger_irq(struct virt_queue *vq, int irq, u8 *isr, struct kvm *kvm);
 
+int virtio__get_dev_specific_field(int offset, bool msix, bool features_hi, u32 *config_off);
+
 #endif /* KVM__VIRTIO_H */
index d28cfc6cb511cde2889b615888c21311f00c3767..d7c132b1ade6560af773ff2d34959a32450b62eb 100644 (file)
@@ -100,3 +100,24 @@ void virt_queue__trigger_irq(struct virt_queue *vq, int irq, u8 *isr, struct kvm
                kvm__irq_line(kvm, irq, VIRTIO_IRQ_HIGH);
        }
 }
+
+int virtio__get_dev_specific_field(int offset, bool msix, bool features_hi, u32 *config_off)
+{
+       if (msix) {
+               if (offset < 4)
+                       return VIRTIO_PCI_O_MSIX;
+               else
+                       offset -= 4;
+       }
+
+       if (features_hi) {
+               if (offset < 4)
+                       return VIRTIO_PCI_O_FEATURES;
+               else
+                       offset -= 4;
+       }
+
+       *config_off = offset;
+
+       return VIRTIO_PCI_O_CONFIG;
+}