From patchwork Thu May 26 10:30:11 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 820362 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p4QAUprd003758 for ; Thu, 26 May 2011 10:30:51 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757449Ab1EZKas (ORCPT ); Thu, 26 May 2011 06:30:48 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]:60477 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757209Ab1EZKar (ORCPT ); Thu, 26 May 2011 06:30:47 -0400 Received: by mail-ww0-f44.google.com with SMTP id 36so599461wwa.1 for ; Thu, 26 May 2011 03:30:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=p/PVyd235QtA48PkuRip59ExDhd6bd0efDlx0pWjNg0=; b=Gb4uIxzDl1m80qsdsibPnbR9GqhXrU5PXm0AJg0eJG7xRYow5Tx5kbkS0AqjsJ2Shp wvW35mSCREEi2ZwJ6OP0WpMQDzGAFXw44FDDyf8V7Ai2avelZ9BmIke2adyi30feTCDI v7sXPwidtEyvB8vxDx7QTwD1Kkt3RNPlvWiDg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=SS0FkIKa15ayhzkEt1Fy57gyitDoE4cfx7NR6QPND9pR+4ahm0vypYVwHWZRZFR7E7 GWNp+EAJSRmM2OO7I6pdV+VByhI5eoVLa8J9zu9Zcji226g7+M0lOf0yolLheh5F1OEi kVZjj/bMI3dQTjrCzmswESZSJd05jWcxGqHqY= Received: by 10.227.165.69 with SMTP id h5mr634895wby.78.1306405847076; Thu, 26 May 2011 03:30:47 -0700 (PDT) Received: from localhost.localdomain ([109.66.201.145]) by mx.google.com with ESMTPS id et5sm365858wbb.33.2011.05.26.03.30.45 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 26 May 2011 03:30:46 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: john@jfloren.net, kvm@vger.kernel.org, mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com, Sasha Levin Subject: [PATCH v3 8/8] kvm tools: Use dynamic IO port allocation in virtio-net Date: Thu, 26 May 2011 13:30:11 +0300 Message-Id: <1306405811-4482-8-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.5.rc3 In-Reply-To: <1306405811-4482-1-git-send-email-levinsasha928@gmail.com> References: <1306405811-4482-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Thu, 26 May 2011 10:30:51 +0000 (UTC) Signed-off-by: Sasha Levin --- tools/kvm/include/kvm/ioport.h | 3 --- tools/kvm/virtio/net.c | 12 ++++++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tools/kvm/include/kvm/ioport.h b/tools/kvm/include/kvm/ioport.h index 4fccbd6..59f118f 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 014205b..3064da6 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); }