From patchwork Thu May 2 09:38:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 240925 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 67E1D2C00A3 for ; Thu, 2 May 2013 19:40:56 +1000 (EST) Received: from localhost ([::1]:58621 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UXq0U-0000Hu-MP for incoming@patchwork.ozlabs.org; Thu, 02 May 2013 05:40:54 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45039) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UXpyZ-0006UI-0u for qemu-devel@nongnu.org; Thu, 02 May 2013 05:38:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UXpyX-0001kj-GG for qemu-devel@nongnu.org; Thu, 02 May 2013 05:38:54 -0400 Received: from mail-wg0-x22c.google.com ([2a00:1450:400c:c00::22c]:64881) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UXpyX-0001kD-5b for qemu-devel@nongnu.org; Thu, 02 May 2013 05:38:53 -0400 Received: by mail-wg0-f44.google.com with SMTP id z12so355822wgg.11 for ; Thu, 02 May 2013 02:38:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=zuP8jQp5soE2FT1NPZWAKBYC1Z1M4MrEYVO/w+gSb20=; b=C1R0YoLKhxAXUUgMju3mtqEgYURUnfQvr62l1z7jQZuWh0WKVSJN6HWnHBQq6/YBf+ FhFytFe8IWaFe8NHCtVlL+YzAn9ABV958fO7//B1l+o1zYE2EIFyKQLGiVOC+HhR+pG+ V4jtToiUc6S0iZ23p3wFt6+MGuK/TfuHdmQ+0x7B41m0Tmf3tyfvZhw5E0UOnC9knaR2 /Q2vh7guk1Eqj21gk07AG+MvObzdqdLvB/1B7aXAorI/Yajn/nHjDy0HrGDnQC+M1tRy 7HvlZKaRmyLiSr5QlroLWtp0BBfe8wMAN2SI7F/pNCzbzpFNqzOyndcmdUiw4PyIZLmz JivQ== X-Received: by 10.194.63.239 with SMTP id j15mr6711767wjs.30.1367487532424; Thu, 02 May 2013 02:38:52 -0700 (PDT) Received: from yakj.usersys.redhat.com (nat-pool-mxp-t.redhat.com. [209.132.186.18]) by mx.google.com with ESMTPSA id g8sm9258483wiy.4.2013.05.02.02.38.50 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 02 May 2013 02:38:51 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 2 May 2013 11:38:39 +0200 Message-Id: <1367487519-17332-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.2 In-Reply-To: <1367487519-17332-1-git-send-email-pbonzini@redhat.com> References: <1367487519-17332-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c00::22c Cc: mst@redhat.com Subject: [Qemu-devel] [PATCH 1.5 3/3] qdev: switch reset to post-order 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 Post-order is the only sensible direction for the reset signals. For example, suppose pre-order is used and the parent has some data structures that cache children state (for example a list of active requests). When the reset method is invoked on the parent, these caches could be in any state. If post-order is used, on the other hand, these will be in a known state when the reset method is invoked on the parent. This change means that it is no longer possible to block the visit of the devices, so the callback is changed to return void. This is not a problem, because PCI was returning 1 exactly in order to achieve the same ordering that this patch implements. PCI can then rely on the qdev core having sent a "reset signal" (whatever that means) to the device, and only do the PCI-specific initialization with the new function pci_do_device_reset, extracted from pci_device_reset. There is no change in the operation of FLR, which used and still uses pci_device_reset. Tested-by: Claudio Bley Signed-off-by: Paolo Bonzini --- hw/core/qdev.c | 6 +++--- hw/pci/pci.c | 31 ++++++++++++++++--------------- include/hw/qdev-core.h | 2 +- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 280b641..67db212 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -232,19 +232,19 @@ static int qbus_reset_one(BusState *bus, void *opaque) { BusClass *bc = BUS_GET_CLASS(bus); if (bc->reset) { - return bc->reset(bus); + bc->reset(bus); } return 0; } void qdev_reset_all(DeviceState *dev) { - qdev_walk_children(dev, qdev_reset_one, qbus_reset_one, NULL, NULL, NULL); + qdev_walk_children(dev, NULL, NULL, qdev_reset_one, qbus_reset_one, NULL); } void qbus_reset_all(BusState *bus) { - qbus_walk_children(bus, qdev_reset_one, qbus_reset_one, NULL, NULL, NULL); + qbus_walk_children(bus, NULL, NULL, qdev_reset_one, qbus_reset_one, NULL); } void qbus_reset_all_fn(void *opaque) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 8e9b983..746862a 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -45,7 +45,7 @@ static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent); static char *pcibus_get_dev_path(DeviceState *dev); static char *pcibus_get_fw_dev_path(DeviceState *dev); -static int pcibus_reset(BusState *qbus); +static void pcibus_reset(BusState *qbus); static Property pci_props[] = { DEFINE_PROP_PCI_DEVFN("addr", PCIDevice, devfn, -1), @@ -169,16 +169,10 @@ void pci_device_deassert_intx(PCIDevice *dev) } } -/* - * This function is called on #RST and FLR. - * FLR if PCI_EXP_DEVCTL_BCR_FLR is set - */ -void pci_device_reset(PCIDevice *dev) +static void pci_do_device_reset(PCIDevice *dev) { int r; - qdev_reset_all(&dev->qdev); - dev->irq_state = 0; pci_update_irq_status(dev); pci_device_deassert_intx(dev); @@ -211,10 +205,21 @@ void pci_device_reset(PCIDevice *dev) } /* + * This function is called on #RST and FLR. + * FLR if PCI_EXP_DEVCTL_BCR_FLR is set + */ +void pci_device_reset(PCIDevice *dev) +{ + qdev_reset_all(&dev->qdev); + pci_do_device_reset(dev); +} + +/* * Trigger pci bus reset under a given bus. - * To be called on RST# assert. + * Called via qbus_reset_all on RST# assert, after the devices + * have been reset qdev_reset_all-ed already. */ -static int pcibus_reset(BusState *qbus) +static void pcibus_reset(BusState *qbus) { PCIBus *bus = DO_UPCAST(PCIBus, qbus, qbus); int i; @@ -224,13 +229,9 @@ static int pcibus_reset(BusState *qbus) } for (i = 0; i < ARRAY_SIZE(bus->devices); ++i) { if (bus->devices[i]) { - pci_device_reset(bus->devices[i]); + pci_do_device_reset(bus->devices[i]); } } - - /* topology traverse is done by pci_bus_reset(). - Tell qbus/qdev walker not to traverse the tree */ - return 1; } static void pci_host_bus_register(int domain, PCIBus *bus) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 6f13254..04ca54e 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -144,7 +144,7 @@ struct BusClass { * bindings can be found at http://playground.sun.com/1275/bindings/. */ char *(*get_fw_dev_path)(DeviceState *dev); - int (*reset)(BusState *bus); + void (*reset)(BusState *bus); /* maximum devices allowed on the bus, 0: no limit. */ int max_dev; };