From patchwork Tue Feb 9 22:01:34 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 44974 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2DE2FB7DE5 for ; Wed, 10 Feb 2010 09:25:21 +1100 (EST) Received: from localhost ([127.0.0.1]:44660 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NeyUN-0003QG-Cn for incoming@patchwork.ozlabs.org; Tue, 09 Feb 2010 17:23:23 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ney9q-0002Mq-Br for qemu-devel@nongnu.org; Tue, 09 Feb 2010 17:02:10 -0500 Received: from [199.232.76.173] (port=52492 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ney9n-0002KF-JJ for qemu-devel@nongnu.org; Tue, 09 Feb 2010 17:02:07 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Ney9l-0005ok-Rl for qemu-devel@nongnu.org; Tue, 09 Feb 2010 17:02:06 -0500 Received: from e4.ny.us.ibm.com ([32.97.182.144]:45748) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Ney9l-0005oY-Ib for qemu-devel@nongnu.org; Tue, 09 Feb 2010 17:02:05 -0500 Received: from d01relay03.pok.ibm.com (d01relay03.pok.ibm.com [9.56.227.235]) by e4.ny.us.ibm.com (8.14.3/8.13.1) with ESMTP id o19Lpj5Y020340 for ; Tue, 9 Feb 2010 16:51:45 -0500 Received: from d01av01.pok.ibm.com (d01av01.pok.ibm.com [9.56.224.215]) by d01relay03.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o19M24bU151486 for ; Tue, 9 Feb 2010 17:02:04 -0500 Received: from d01av01.pok.ibm.com (loopback [127.0.0.1]) by d01av01.pok.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o19M24rN015537 for ; Tue, 9 Feb 2010 17:02:04 -0500 Received: from localhost.localdomain (sig-9-65-47-242.mts.ibm.com [9.65.47.242]) by d01av01.pok.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id o19M1eiK013399; Tue, 9 Feb 2010 17:01:54 -0500 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Tue, 9 Feb 2010 16:01:34 -0600 Message-Id: <1265752899-26980-11-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.6.5.2 In-Reply-To: <1265752899-26980-1-git-send-email-aliguori@us.ibm.com> References: <1265752899-26980-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Michael Tsirkin , Anthony Liguori , Alex Graf Subject: [Qemu-devel] [PATCH 10/15] virtio-pci: convert to new pci interface X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org - in each config_readN function, we already do get_config so drop it in map - virtio still has knowledge of target_phys_addr_t, syborg makes it hard to remove Signed-off-by: Anthony Liguori --- hw/virtio-pci.c | 110 ++++++++++++++----------------------------------------- 1 files changed, 28 insertions(+), 82 deletions(-) diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index 709d13e..a2ba294 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -169,9 +169,9 @@ static void virtio_pci_reset(DeviceState *d) msix_reset(&proxy->pci_dev); } -static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val) +static void virtio_ioport_write(VirtIOPCIProxy *proxy, uint32_t addr, + uint32_t val) { - VirtIOPCIProxy *proxy = opaque; VirtIODevice *vdev = proxy->vdev; target_phys_addr_t pa; @@ -189,6 +189,8 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val) vdev->guest_features = val; break; case VIRTIO_PCI_QUEUE_PFN: + /* FIXME need to rethink how we handle this. We should use PCI memory + * access functions for everything here. Syborg complicates that. */ pa = (target_phys_addr_t)val << VIRTIO_PCI_QUEUE_ADDR_SHIFT; if (pa == 0) { virtio_reset(proxy->vdev); @@ -277,96 +279,40 @@ static uint32_t virtio_ioport_read(VirtIOPCIProxy *proxy, uint32_t addr) return ret; } -static uint32_t virtio_pci_config_readb(void *opaque, uint32_t addr) +static uint32_t virtio_pci_config_read(PCIDevice *dev, pcibus_t addr, int size) { - VirtIOPCIProxy *proxy = opaque; + VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, dev); uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); - addr -= proxy->addr; - if (addr < config) - return virtio_ioport_read(proxy, addr); - addr -= config; - return virtio_config_readb(proxy->vdev, addr); -} + uint32_t value; -static uint32_t virtio_pci_config_readw(void *opaque, uint32_t addr) -{ - VirtIOPCIProxy *proxy = opaque; - uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); - addr -= proxy->addr; - if (addr < config) - return virtio_ioport_read(proxy, addr); - addr -= config; - return virtio_config_readw(proxy->vdev, addr); -} - -static uint32_t virtio_pci_config_readl(void *opaque, uint32_t addr) -{ - VirtIOPCIProxy *proxy = opaque; - uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); - addr -= proxy->addr; - if (addr < config) - return virtio_ioport_read(proxy, addr); - addr -= config; - return virtio_config_readl(proxy->vdev, addr); -} - -static void virtio_pci_config_writeb(void *opaque, uint32_t addr, uint32_t val) -{ - VirtIOPCIProxy *proxy = opaque; - uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); - addr -= proxy->addr; if (addr < config) { - virtio_ioport_write(proxy, addr, val); - return; + value = virtio_ioport_read(proxy, addr); + } else if (size == 1) { + value = virtio_config_readb(proxy->vdev, addr - config); + } else if (size == 2) { + value = virtio_config_readw(proxy->vdev, addr - config); + } else { + value = virtio_config_readl(proxy->vdev, addr - config); } - addr -= config; - virtio_config_writeb(proxy->vdev, addr, val); -} -static void virtio_pci_config_writew(void *opaque, uint32_t addr, uint32_t val) -{ - VirtIOPCIProxy *proxy = opaque; - uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); - addr -= proxy->addr; - if (addr < config) { - virtio_ioport_write(proxy, addr, val); - return; - } - addr -= config; - virtio_config_writew(proxy->vdev, addr, val); + return value; } -static void virtio_pci_config_writel(void *opaque, uint32_t addr, uint32_t val) +static void virtio_pci_config_write(PCIDevice *dev, pcibus_t addr, int size, + uint32_t value) { - VirtIOPCIProxy *proxy = opaque; + VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, dev); uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); - addr -= proxy->addr; + if (addr < config) { - virtio_ioport_write(proxy, addr, val); - return; + virtio_ioport_write(proxy, addr, value); + } else if (size == 1) { + virtio_config_writeb(proxy->vdev, addr - config, value); + } else if (size == 2) { + virtio_config_writew(proxy->vdev, addr - config, value); + } else { + virtio_config_writel(proxy->vdev, addr - config, value); } - addr -= config; - virtio_config_writel(proxy->vdev, addr, val); -} - -static void virtio_map(PCIDevice *pci_dev, int region_num, - pcibus_t addr, pcibus_t size, int type) -{ - VirtIOPCIProxy *proxy = container_of(pci_dev, VirtIOPCIProxy, pci_dev); - VirtIODevice *vdev = proxy->vdev; - unsigned config_len = VIRTIO_PCI_REGION_SIZE(pci_dev) + vdev->config_len; - - proxy->addr = addr; - - register_ioport_write(addr, config_len, 1, virtio_pci_config_writeb, proxy); - register_ioport_write(addr, config_len, 2, virtio_pci_config_writew, proxy); - register_ioport_write(addr, config_len, 4, virtio_pci_config_writel, proxy); - register_ioport_read(addr, config_len, 1, virtio_pci_config_readb, proxy); - register_ioport_read(addr, config_len, 2, virtio_pci_config_readw, proxy); - register_ioport_read(addr, config_len, 4, virtio_pci_config_readl, proxy); - - if (vdev->config_len) - vdev->get_config(vdev, vdev->config); } static void virtio_write_config(PCIDevice *pci_dev, uint32_t address, @@ -439,8 +385,8 @@ static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev, if (size & (size-1)) size = 1 << qemu_fls(size); - pci_register_bar(&proxy->pci_dev, 0, size, PCI_BASE_ADDRESS_SPACE_IO, - virtio_map); + pci_register_io_region(&proxy->pci_dev, 0, size, PCI_BASE_ADDRESS_SPACE_IO, + virtio_pci_config_read, virtio_pci_config_write); virtio_bind_device(vdev, &virtio_pci_bindings, proxy); proxy->host_features |= 0x1 << VIRTIO_F_NOTIFY_ON_EMPTY;