From patchwork Thu Jun 17 06:15:45 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 55968 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 B98C2B7D85 for ; Thu, 17 Jun 2010 16:29:42 +1000 (EST) Received: from localhost ([127.0.0.1]:60898 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OP8ba-0003RZ-8N for incoming@patchwork.ozlabs.org; Thu, 17 Jun 2010 02:29:38 -0400 Received: from [140.186.70.92] (port=38427 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OP8S0-0008AI-9u for qemu-devel@nongnu.org; Thu, 17 Jun 2010 02:19:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OP8Rx-0002kV-Lc for qemu-devel@nongnu.org; Thu, 17 Jun 2010 02:19:44 -0400 Received: from mail.valinux.co.jp ([210.128.90.3]:36645) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OP8Rx-0002jc-5A for qemu-devel@nongnu.org; Thu, 17 Jun 2010 02:19:41 -0400 Received: from ps.local.valinux.co.jp (vagw.valinux.co.jp [210.128.90.14]) by mail.valinux.co.jp (Postfix) with SMTP id A7C461072C0; Thu, 17 Jun 2010 15:19:38 +0900 (JST) Received: (nullmailer pid 29411 invoked by uid 1000); Thu, 17 Jun 2010 06:15:52 -0000 From: Isaku Yamahata To: qemu-devel@nongnu.org Date: Thu, 17 Jun 2010 15:15:45 +0900 Message-Id: <551d7f5ea27a3bf8fcf69dea059d237493a92a2b.1276755023.git.yamahata@valinux.co.jp> X-Mailer: git-send-email 1.6.6.1 In-Reply-To: References: In-Reply-To: References: X-Virus-Scanned: clamav-milter 0.95.2 at va-mail.local.valinux.co.jp X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: jan.kiszka@siemens.com, mst@redhat.com, allen.m.kay@intel.com, blauwirbel@gmail.com, yamahata@valinux.co.jp, kraxel@redhat.com, stefano.stabellini@eu.citrix.com, jean.guyader@gmail.com Subject: [Qemu-devel] [PATCH 03/10] pci: fix pci_bus_reset() with 64bit BAR and several clean ups. 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 fix pci_device_reset() with 64bit BAR. export pci_bus_reset(), pci_device_reset() and two helper functions for later use. And several clean ups. Signed-off-by: Isaku Yamahata --- hw/pci.c | 44 ++++++++++++++++++++++++++++++++++++-------- hw/pci.h | 5 +++++ 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index 9ba62eb..87f5e6c 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -144,28 +144,50 @@ static void pci_update_irq_status(PCIDevice *dev) } } -static void pci_device_reset(PCIDevice *dev) +void pci_device_reset_default(PCIDevice *dev) { int r; dev->irq_state = 0; pci_update_irq_status(dev); - dev->config[PCI_COMMAND] &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY | - PCI_COMMAND_MASTER); + pci_set_word(dev->config + PCI_COMMAND, + pci_get_word(dev->config + PCI_COMMAND) & + ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER)); dev->config[PCI_CACHE_LINE_SIZE] = 0x0; dev->config[PCI_INTERRUPT_LINE] = 0x0; for (r = 0; r < PCI_NUM_REGIONS; ++r) { - if (!dev->io_regions[r].size) { + PCIIORegion *region = &dev->io_regions[r]; + if (!region->size) { continue; } - pci_set_long(dev->config + pci_bar(dev, r), dev->io_regions[r].type); + + if (!(region->type & PCI_BASE_ADDRESS_SPACE_IO) && + region->type & PCI_BASE_ADDRESS_MEM_TYPE_64) { + pci_set_quad(dev->config + pci_bar(dev, r), region->type); + } else { + pci_set_long(dev->config + pci_bar(dev, r), region->type); + } } pci_update_mappings(dev); } -static void pci_bus_reset(void *opaque) +void pci_device_reset(PCIDevice *dev) +{ + if (!dev->qdev.info) { + /* for not qdevified device */ + pci_device_reset_default(dev); + return; + } + + qdev_reset(&dev->qdev); + + /* TODO: make DeviceInfo::reset call + pci_device_reset_default() itself. */ + pci_device_reset_default(dev); +} + +void pci_bus_reset(PCIBus *bus) { - PCIBus *bus = opaque; int i; for (i = 0; i < bus->nirq; i++) { @@ -178,6 +200,12 @@ static void pci_bus_reset(void *opaque) } } +static void pci_bus_resetfn(void *opaque) +{ + PCIBus *bus = opaque; + pci_bus_reset(bus); +} + static void pci_host_bus_register(int domain, PCIBus *bus) { struct PCIHostBus *host; @@ -231,7 +259,7 @@ void pci_bus_new_inplace(PCIBus *bus, DeviceState *parent, pci_host_bus_register(0, bus); /* for now only pci domain 0 is supported */ vmstate_register(-1, &vmstate_pcibus, bus); - qemu_register_reset(pci_bus_reset, bus); + qemu_register_reset(pci_bus_resetfn, bus); } PCIBus *pci_bus_new(DeviceState *parent, const char *name, int devfn_min) diff --git a/hw/pci.h b/hw/pci.h index f6e2551..2a2c8ef 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -199,6 +199,11 @@ int pci_device_load(PCIDevice *s, QEMUFile *f); typedef void (*pci_set_irq_fn)(void *opaque, int irq_num, int level); typedef int (*pci_map_irq_fn)(PCIDevice *pci_dev, int irq_num); typedef int (*pci_hotplug_fn)(DeviceState *qdev, PCIDevice *pci_dev, int state); + +void pci_device_reset_default(PCIDevice *dev); +void pci_device_reset(PCIDevice *dev); +void pci_bus_reset(PCIBus *bus); + void pci_bus_new_inplace(PCIBus *bus, DeviceState *parent, const char *name, int devfn_min); PCIBus *pci_bus_new(DeviceState *parent, const char *name, int devfn_min);