]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Use dynamic IO port allocation in virtio-console
authorSasha Levin <levinsasha928@gmail.com>
Thu, 26 May 2011 10:30:10 +0000 (13:30 +0300)
committerPekka Enberg <penberg@kernel.org>
Thu, 26 May 2011 15:55:56 +0000 (18:55 +0300)
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/include/kvm/ioport.h
tools/kvm/virtio/console.c

index 310f75d31f78ba205bb2ffa3cd74b234dfd8c3e2..4fccbd6e6a7138ddecc02af0a813dc83e711fd34 100644 (file)
@@ -12,8 +12,6 @@
 #define IOPORT_START                   0x6200
 #define IOPORT_SIZE                    0x400
 
-#define IOPORT_VIRTIO_CONSOLE          0xd200  /* Virtio console device */
-#define IOPORT_VIRTIO_CONSOLE_SIZE     256
 #define IOPORT_VIRTIO_NET              0xe200  /* Virtio network device */
 #define IOPORT_VIRTIO_NET_SIZE         256
 
index 614f0d2b641687b165a50a6bb706563ab8c4e862..038e53fde7b1e8131ca4dff6265a84dcc5147823 100644 (file)
@@ -36,7 +36,6 @@ static struct pci_device_header virtio_console_pci_device = {
        .class                  = 0x078000,
        .subsys_vendor_id       = PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET,
        .subsys_id              = VIRTIO_ID_CONSOLE,
-       .bar[0]                 = IOPORT_VIRTIO_CONSOLE | PCI_BASE_ADDRESS_SPACE_IO,
 };
 
 struct con_dev {
@@ -50,6 +49,7 @@ struct con_dev {
        u8                              status;
        u8                              isr;
        u16                             queue_selector;
+       u16                             base_addr;
 
        void                            *jobs[VIRTIO_CONSOLE_NUM_QUEUES];
 };
@@ -113,7 +113,7 @@ static bool virtio_console_pci_io_device_specific_in(void *data, unsigned long o
 
 static bool virtio_console_pci_io_in(struct ioport *ioport, struct kvm *kvm, u16 port, void *data, int size, u32 count)
 {
-       unsigned long offset = port - IOPORT_VIRTIO_CONSOLE;
+       unsigned long offset = port - cdev.base_addr;
        bool ret = true;
 
        mutex_lock(&cdev.mutex);
@@ -181,7 +181,7 @@ static void virtio_console_handle_callback(struct kvm *kvm, void *param)
 
 static bool virtio_console_pci_io_out(struct ioport *ioport, struct kvm *kvm, u16 port, void *data, int size, u32 count)
 {
-       unsigned long offset = port - IOPORT_VIRTIO_CONSOLE;
+       unsigned long offset = port - cdev.base_addr;
        bool ret = true;
 
        mutex_lock(&cdev.mutex);
@@ -243,12 +243,15 @@ static struct ioport_operations virtio_console_io_ops = {
 void virtio_console__init(struct kvm *kvm)
 {
        u8 dev, line, pin;
+       u16 console_base_addr;
 
        if (irq__register_device(VIRTIO_ID_CONSOLE, &dev, &pin, &line) < 0)
                return;
 
        virtio_console_pci_device.irq_pin       = pin;
        virtio_console_pci_device.irq_line      = line;
+       console_base_addr                       = ioport__register(IOPORT_EMPTY, &virtio_console_io_ops, IOPORT_SIZE, NULL);
+       virtio_console_pci_device.bar[0]        = console_base_addr | PCI_BASE_ADDRESS_SPACE_IO;
+       cdev.base_addr                          = console_base_addr;
        pci__register(&virtio_console_pci_device, dev);
-       ioport__register(IOPORT_VIRTIO_CONSOLE, &virtio_console_io_ops, IOPORT_VIRTIO_CONSOLE_SIZE, NULL);
 }