From patchwork Fri Oct 9 06:28:43 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 35557 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 84BACB7B92 for ; Fri, 9 Oct 2009 17:38:32 +1100 (EST) Received: from localhost ([127.0.0.1]:34001 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mw97U-0007qm-CL for incoming@patchwork.ozlabs.org; Fri, 09 Oct 2009 02:38:28 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mw90B-00040J-8c for qemu-devel@nongnu.org; Fri, 09 Oct 2009 02:30:56 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mw904-0003po-9M for qemu-devel@nongnu.org; Fri, 09 Oct 2009 02:30:53 -0400 Received: from [199.232.76.173] (port=55745 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mw904-0003p1-0e for qemu-devel@nongnu.org; Fri, 09 Oct 2009 02:30:48 -0400 Received: from mail.valinux.co.jp ([210.128.90.3]:36123) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mw901-0001OY-Og for qemu-devel@nongnu.org; Fri, 09 Oct 2009 02:30:46 -0400 Received: from nm.local.valinux.co.jp (vagw.valinux.co.jp [210.128.90.14]) by mail.valinux.co.jp (Postfix) with ESMTP id CCE7E49E1D; Fri, 9 Oct 2009 15:30:39 +0900 (JST) Received: from yamahata by nm.local.valinux.co.jp with local (Exim 4.69) (envelope-from ) id 1Mw8yM-00046U-MY; Fri, 09 Oct 2009 15:29:02 +0900 From: Isaku Yamahata To: qemu-devel@nongnu.org, mst@redhat.com Date: Fri, 9 Oct 2009 15:28:43 +0900 Message-Id: <1255069742-15724-11-git-send-email-yamahata@valinux.co.jp> X-Mailer: git-send-email 1.6.0.2 In-Reply-To: <1255069742-15724-1-git-send-email-yamahata@valinux.co.jp> References: <1255069742-15724-1-git-send-email-yamahata@valinux.co.jp> X-Virus-Scanned: clamav-milter 0.95.2 at va-mail.local.valinux.co.jp X-Virus-Status: Clean X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: yamahata@valinux.co.jp Subject: [Qemu-devel] [PATCH V5 10/29] pci: make pci_bar() aware of header type 1. 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 make pci_bar() aware of header type 1. When PCI_ROM_SLOT it should return PCI_ROM_ADDRESS1 (!= PCI_ROM_ADDRESS) Signed-off-by: Isaku Yamahata Acked-by: Michael S. Tsirkin --- hw/pci.c | 18 ++++++++++++------ hw/pci.h | 3 +++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index 755ebad..82c1c3c 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -84,9 +84,15 @@ static const VMStateDescription vmstate_pcibus = { } }; -static inline int pci_bar(int reg) +static int pci_bar(PCIDevice *d, int reg) { - return reg == PCI_ROM_SLOT ? PCI_ROM_ADDRESS : PCI_BASE_ADDRESS_0 + reg * 4; + if (reg == PCI_ROM_SLOT) { + return (d->config[PCI_HEADER_TYPE] & ~PCI_HEADER_TYPE_MULTI_FUNCTION) + == PCI_HEADER_TYPE_BRIDGE ? + PCI_ROM_ADDRESS1 : PCI_ROM_ADDRESS; + } + + return PCI_BASE_ADDRESS_0 + reg * 4; } static void pci_device_reset(PCIDevice *dev) @@ -102,7 +108,7 @@ static void pci_device_reset(PCIDevice *dev) if (!dev->io_regions[r].size) { continue; } - pci_set_long(dev->config + pci_bar(r), dev->io_regions[r].type); + pci_set_long(dev->config + pci_bar(dev, r), dev->io_regions[r].type); } pci_update_mappings(dev); } @@ -472,7 +478,7 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num, r->map_func = map_func; wmask = ~(size - 1); - addr = pci_bar(region_num); + addr = pci_bar(pci_dev, region_num); if (region_num == PCI_ROM_SLOT) { /* ROM enable bit is writeable */ wmask |= PCI_ROM_ADDRESS_ENABLE; @@ -494,7 +500,7 @@ static void pci_update_mappings(PCIDevice *d) if (r->size != 0) { if (r->type & PCI_BASE_ADDRESS_SPACE_IO) { if (cmd & PCI_COMMAND_IO) { - new_addr = pci_get_long(d->config + pci_bar(i)); + new_addr = pci_get_long(d->config + pci_bar(d, i)); new_addr = new_addr & ~(r->size - 1); last_addr = new_addr + r->size - 1; /* NOTE: we have only 64K ioports on PC */ @@ -507,7 +513,7 @@ static void pci_update_mappings(PCIDevice *d) } } else { if (cmd & PCI_COMMAND_MEMORY) { - new_addr = pci_get_long(d->config + pci_bar(i)); + new_addr = pci_get_long(d->config + pci_bar(d, i)); /* the ROM slot has a specific enable bit */ if (i == PCI_ROM_SLOT && !(new_addr & PCI_ROM_ADDRESS_ENABLE)) goto no_mem_map; diff --git a/hw/pci.h b/hw/pci.h index bbce56b..bd63534 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -153,6 +153,9 @@ typedef struct PCIIORegion { #define PCI_COMMAND_RESERVED_MASK_HI (PCI_COMMAND_RESERVED >> 8) +/* Header type 1 (PCI-to-PCI bridges) */ +#define PCI_ROM_ADDRESS1 0x38 /* Same as PCI_ROM_ADDRESS, but for htype 1 */ + /* Size of the standard PCI config header */ #define PCI_CONFIG_HEADER_SIZE 0x40 /* Size of the standard PCI config space */