]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm: Fail virtio blk ioports by default
authorPekka Enberg <penberg@kernel.org>
Sun, 15 Aug 2010 14:17:43 +0000 (17:17 +0300)
committerPekka Enberg <penberg@kernel.org>
Sun, 15 Aug 2010 14:17:43 +0000 (17:17 +0300)
This patch changes virtio block device ioports to fail by default and adds few
specific stubs to keep kernel booting still.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/blk-virtio.c
tools/kvm/include/kvm/ioport.h

index 7670f0c572ac21826a81dc9dd3ed23b816cec6f8..e7eb44e45a570337523ad9e9e28d10573656f505 100644 (file)
@@ -6,22 +6,13 @@
 
 #define VIRTIO_PCI_IOPORT_SIZE         24
 
-#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 blk_virtio_device = {
-       .vendor_id              = PCI_VENDOR_ID_REDHAT_QUMRANET,
-       .device_id              = PCI_DEVICE_ID_VIRTIO_BLK,
-       .header_type            = PCI_HEADER_TYPE_NORMAL,
-       .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,
+struct device {
+       uint32_t                guest_features;
+       uint8_t                 status;
 };
 
+static struct device device;
+
 static bool blk_virtio_in(struct kvm *self, uint16_t port, void *data, int size, uint32_t count)
 {
        unsigned long offset;
@@ -30,20 +21,28 @@ static bool blk_virtio_in(struct kvm *self, uint16_t port, void *data, int size,
 
        switch (offset) {
        case VIRTIO_PCI_HOST_FEATURES:
+               ioport__write32(data, 0x00);
+               break;
        case VIRTIO_PCI_GUEST_FEATURES:
        case VIRTIO_PCI_QUEUE_PFN:
        case VIRTIO_PCI_QUEUE_NUM:
        case VIRTIO_PCI_QUEUE_SEL:
        case VIRTIO_PCI_QUEUE_NOTIFY:
+               return false;
        case VIRTIO_PCI_STATUS:
+               ioport__write8(data, device.status);
+               break;
        case VIRTIO_PCI_ISR:
        case VIRTIO_MSI_CONFIG_VECTOR:
-               return true;
+       default:
+               return false;
        };
 
-       return false;
+       return true;
 }
 
+#include <stdio.h>
+
 static bool blk_virtio_out(struct kvm *self, uint16_t port, void *data, int size, uint32_t count)
 {
        unsigned long offset;
@@ -52,16 +51,22 @@ static bool blk_virtio_out(struct kvm *self, uint16_t port, void *data, int size
 
        switch (offset) {
        case VIRTIO_PCI_GUEST_FEATURES:
+               device.guest_features   = ioport__read32(data);
+               break;
        case VIRTIO_PCI_QUEUE_PFN:
        case VIRTIO_PCI_QUEUE_SEL:
        case VIRTIO_PCI_QUEUE_NOTIFY:
+               return false;
        case VIRTIO_PCI_STATUS:
+               device.status           = ioport__read8(data);
+               break;
        case VIRTIO_MSI_CONFIG_VECTOR:
        case VIRTIO_MSI_QUEUE_VECTOR:
-               return true;
+       default:
+               return false;
        };
 
-       return false;
+       return true;
 }
 
 static struct ioport_operations blk_virtio_io_ops = {
@@ -69,9 +74,25 @@ static struct ioport_operations blk_virtio_io_ops = {
        .io_out         = blk_virtio_out,
 };
 
+#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 blk_virtio_pci_device = {
+       .vendor_id              = PCI_VENDOR_ID_REDHAT_QUMRANET,
+       .device_id              = PCI_DEVICE_ID_VIRTIO_BLK,
+       .header_type            = PCI_HEADER_TYPE_NORMAL,
+       .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,
+};
+
 void blk_virtio__init(void)
 {
-       pci__register(&blk_virtio_device, 1);
+       pci__register(&blk_virtio_pci_device, 1);
 
        ioport__register(IOPORT_VIRTIO, &blk_virtio_io_ops, VIRTIO_PCI_IOPORT_SIZE);
 }
index eaedc1e7be820feffcfa211fe972f11eec537a7f..b4ae9abea61e0c77c33fe991c5be31358c7c94a6 100644 (file)
@@ -17,4 +17,24 @@ struct ioport_operations {
 
 void ioport__register(uint16_t port, struct ioport_operations *ops, int count);
 
+static inline uint8_t ioport__read8(uint8_t *data)
+{
+       return *data;
+}
+
+static inline uint32_t ioport__read32(uint32_t *data)
+{
+       return *data;
+}
+
+static inline void ioport__write8(uint8_t *data, uint8_t value)
+{
+       *data            = value;
+}
+
+static inline void ioport__write32(uint32_t *data, uint32_t value)
+{
+       *data            = value;
+}
+
 #endif /* KVM__IOPORT_H */