From: Sasha Levin Date: Thu, 26 May 2011 10:30:11 +0000 (+0300) Subject: kvm tools: Use dynamic IO port allocation in virtio-net X-Git-Tag: next-20110824~3^2~254 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=f943158e37bfa667f60a719dbe266c8a9afe033f;p=karo-tx-linux.git kvm tools: Use dynamic IO port allocation in virtio-net Signed-off-by: Sasha Levin Signed-off-by: Pekka Enberg --- diff --git a/tools/kvm/include/kvm/ioport.h b/tools/kvm/include/kvm/ioport.h index 4fccbd6e6a71..59f118f428f6 100644 --- a/tools/kvm/include/kvm/ioport.h +++ b/tools/kvm/include/kvm/ioport.h @@ -12,9 +12,6 @@ #define IOPORT_START 0x6200 #define IOPORT_SIZE 0x400 -#define IOPORT_VIRTIO_NET 0xe200 /* Virtio network device */ -#define IOPORT_VIRTIO_NET_SIZE 256 - #define IOPORT_EMPTY USHRT_MAX struct kvm; diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c index 014205b09557..3064da612554 100644 --- a/tools/kvm/virtio/net.c +++ b/tools/kvm/virtio/net.c @@ -37,7 +37,6 @@ static struct pci_device_header pci_header = { .class = 0x020000, .subsys_vendor_id = PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET, .subsys_id = VIRTIO_ID_NET, - .bar[0] = IOPORT_VIRTIO_NET | PCI_BASE_ADDRESS_SPACE_IO, }; struct net_device { @@ -51,6 +50,7 @@ struct net_device { u8 status; u8 isr; u16 queue_selector; + u16 base_addr; pthread_t io_rx_thread; pthread_mutex_t io_rx_lock; @@ -166,7 +166,7 @@ static bool virtio_net_pci_io_device_specific_in(void *data, unsigned long offse static bool virtio_net_pci_io_in(struct ioport *ioport, struct kvm *kvm, u16 port, void *data, int size, u32 count) { - unsigned long offset = port - IOPORT_VIRTIO_NET; + unsigned long offset = port - ndev.base_addr; bool ret = true; mutex_lock(&ndev.mutex); @@ -230,7 +230,7 @@ static void virtio_net_handle_callback(struct kvm *kvm, u16 queue_index) static bool virtio_net_pci_io_out(struct ioport *ioport, struct kvm *kvm, u16 port, void *data, int size, u32 count) { - unsigned long offset = port - IOPORT_VIRTIO_NET; + unsigned long offset = port - ndev.base_addr; bool ret = true; mutex_lock(&ndev.mutex); @@ -387,14 +387,18 @@ void virtio_net__init(const struct virtio_net_parameters *params) { if (virtio_net__tap_init(params)) { u8 dev, line, pin; + u16 net_base_addr; if (irq__register_device(VIRTIO_ID_NET, &dev, &pin, &line) < 0) return; pci_header.irq_pin = pin; pci_header.irq_line = line; + net_base_addr = ioport__register(IOPORT_EMPTY, &virtio_net_io_ops, IOPORT_SIZE, NULL); + pci_header.bar[0] = net_base_addr | PCI_BASE_ADDRESS_SPACE_IO; + ndev.base_addr = net_base_addr; + pci__register(&pci_header, dev); - ioport__register(IOPORT_VIRTIO_NET, &virtio_net_io_ops, IOPORT_VIRTIO_NET_SIZE, NULL); virtio_net__io_thread_init(params->kvm); }