From patchwork Mon Oct 7 09:35:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 281048 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6810A2C007E for ; Mon, 7 Oct 2013 20:55:27 +1100 (EST) Received: from localhost ([::1]:58293 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VT7Dm-0005SG-5a for incoming@patchwork.ozlabs.org; Mon, 07 Oct 2013 05:35:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43511) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VT7BI-0001z7-To for qemu-devel@nongnu.org; Mon, 07 Oct 2013 05:32:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VT7BC-0000gX-Vh for qemu-devel@nongnu.org; Mon, 07 Oct 2013 05:32:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:23037) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VT7BC-0000gI-MV for qemu-devel@nongnu.org; Mon, 07 Oct 2013 05:32:42 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r979Wfgp029286 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 7 Oct 2013 05:32:41 -0400 Received: from redhat.com (vpn1-7-45.ams2.redhat.com [10.36.7.45]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id r979WbPd003741; Mon, 7 Oct 2013 05:32:38 -0400 Date: Mon, 7 Oct 2013 12:35:05 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org, Anthony Liguori Message-ID: <1381138458-6848-5-git-send-email-mst@redhat.com> References: <1381138458-6848-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1381138458-6848-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: pbonzini@redhat.com, imammedo@redhat.com, afaerber@suse.de, kraxel@redhat.com Subject: [Qemu-devel] [PATCH v9 04/27] pci: fix up w64 size calculation helper X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org BAR base was calculated incorrectly. Use existing pci_bar_address to get it right. Tested-by: Igor Mammedov Signed-off-by: Michael S. Tsirkin --- hw/pci/pci.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 00554a0..c3fdff4 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2264,7 +2264,7 @@ static void pci_dev_get_w64(PCIBus *b, PCIDevice *dev, void *opaque) Range *range = opaque; PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev); uint16_t cmd = pci_get_word(dev->config + PCI_COMMAND); - int r; + int i; if (!(cmd & PCI_COMMAND_MEMORY)) { return; @@ -2283,17 +2283,21 @@ static void pci_dev_get_w64(PCIBus *b, PCIDevice *dev, void *opaque) range_extend(range, &pref_range); } } - for (r = 0; r < PCI_NUM_REGIONS; ++r) { - PCIIORegion *region = &dev->io_regions[r]; + for (i = 0; i < PCI_NUM_REGIONS; ++i) { + PCIIORegion *r = &dev->io_regions[i]; Range region_range; - if (!region->size || - (region->type & PCI_BASE_ADDRESS_SPACE_IO) || - !(region->type & PCI_BASE_ADDRESS_MEM_TYPE_64)) { + if (!r->size || + (r->type & PCI_BASE_ADDRESS_SPACE_IO) || + !(r->type & PCI_BASE_ADDRESS_MEM_TYPE_64)) { + continue; + } + region_range.begin = pci_bar_address(dev, i, r->type, r->size); + region_range.end = region_range.begin + r->size; + + if (region_range.begin == PCI_BAR_UNMAPPED) { continue; } - region_range.begin = pci_get_quad(dev->config + pci_bar(dev, r)); - region_range.end = region_range.begin + region->size; region_range.begin = MAX(region_range.begin, 0x1ULL << 32);