From patchwork Mon Mar 7 03:23:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cao jin X-Patchwork-Id: 8515041 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 875F1C0553 for ; Mon, 7 Mar 2016 03:26:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D2FE82013A for ; Mon, 7 Mar 2016 03:26:06 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1693020138 for ; Mon, 7 Mar 2016 03:26:06 +0000 (UTC) Received: from localhost ([::1]:53285 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aclo5-0006RV-Em for patchwork-qemu-devel@patchwork.kernel.org; Sun, 06 Mar 2016 22:26:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51176) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aclkX-0000Lf-2U for qemu-devel@nongnu.org; Sun, 06 Mar 2016 22:22:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aclkT-0001PT-PM for qemu-devel@nongnu.org; Sun, 06 Mar 2016 22:22:24 -0500 Received: from [59.151.112.132] (port=51939 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aclkS-0001L8-TU for qemu-devel@nongnu.org; Sun, 06 Mar 2016 22:22:21 -0500 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="4286098" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 07 Mar 2016 11:22:09 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id 5656441890FE; Mon, 7 Mar 2016 11:22:09 +0800 (CST) Received: from G08FNSTD140223.g08.fujitsu.local (10.167.226.69) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Mon, 7 Mar 2016 11:22:08 +0800 From: Cao jin To: Date: Mon, 7 Mar 2016 11:23:01 +0800 Message-ID: <1457320984-6540-9-git-send-email-caoj.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1457320984-6540-1-git-send-email-caoj.fnst@cn.fujitsu.com> References: <1457320984-6540-1-git-send-email-caoj.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.69] X-yoursite-MailScanner-ID: 5656441890FE.A9ED3 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: caoj.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: chen.fan.fnst@cn.fujitsu.com, izumi.taku@jp.fujitsu.com, alex.williamson@redhat.com, mst@redhat.com Subject: [Qemu-devel] [PATCH v2 08/11] pci: introduce pci bus pre reset 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Chen Fan in order to distinguish a hot reset with a normal reset. we add this pre reset call back to notice that we should do a hot reset for all devices. Signed-off-by: Chen Fan --- hw/core/qdev.c | 4 ++-- hw/pci/pci.c | 11 +++++++++++ hw/pci/pci_bridge.c | 5 ++++- include/hw/pci/pci_bus.h | 5 +++++ include/hw/qdev-core.h | 3 +++ 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 779de2b..e36fa07 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -304,14 +304,14 @@ void qdev_unplug(DeviceState *dev, Error **errp) } } -static int qdev_reset_one(DeviceState *dev, void *opaque) +int qdev_reset_one(DeviceState *dev, void *opaque) { device_reset(dev); return 0; } -static int qbus_reset_one(BusState *bus, void *opaque) +int qbus_reset_one(BusState *bus, void *opaque) { BusClass *bc = BUS_GET_CLASS(bus); if (bc->reset) { diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 72650c5..7c79767 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -257,6 +257,15 @@ void pci_device_reset(PCIDevice *dev) pci_do_device_reset(dev); } +int pcibus_pre_reset(BusState *qbus, void *opaque) +{ + PCIBus *pci_bus = DO_UPCAST(PCIBus, qbus, qbus); + + pci_bus->in_hot_reset = true; + + return 0; +} + /* * Trigger pci bus reset under a given bus. * Called via qbus_reset_all on RST# assert, after the devices @@ -276,6 +285,8 @@ static void pcibus_reset(BusState *qbus) for (i = 0; i < bus->nirq; i++) { assert(bus->irq_count[i] == 0); } + + bus->in_hot_reset = false; } static void pci_host_bus_register(PCIBus *bus, DeviceState *parent) diff --git a/hw/pci/pci_bridge.c b/hw/pci/pci_bridge.c index 7eab9d5..6c35171 100644 --- a/hw/pci/pci_bridge.c +++ b/hw/pci/pci_bridge.c @@ -269,7 +269,10 @@ void pci_bridge_write_config(PCIDevice *d, newctl = pci_get_word(d->config + PCI_BRIDGE_CONTROL); if (~oldctl & newctl & PCI_BRIDGE_CTL_BUS_RESET) { /* Trigger hot reset on 0->1 transition. */ - qbus_reset_all(&s->sec_bus.qbus); + qbus_walk_children(&s->sec_bus.qbus, NULL, + pcibus_pre_reset, + qdev_reset_one, + qbus_reset_one, &s->sec_bus.qbus); } } diff --git a/include/hw/pci/pci_bus.h b/include/hw/pci/pci_bus.h index 403fec6..1a87179 100644 --- a/include/hw/pci/pci_bus.h +++ b/include/hw/pci/pci_bus.h @@ -39,8 +39,13 @@ struct PCIBus { Keep a count of the number of devices with raised IRQs. */ int nirq; int *irq_count; + + /* The bus need to do a hot reset */ + bool in_hot_reset; }; +int pcibus_pre_reset(BusState *qbus, void *opaque); + typedef struct PCIBridgeWindows PCIBridgeWindows; /* diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index abcdee8..3d71c17 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -401,4 +401,7 @@ static inline bool qbus_is_hotpluggable(BusState *bus) void device_listener_register(DeviceListener *listener); void device_listener_unregister(DeviceListener *listener); +int qdev_reset_one(DeviceState *dev, void *opaque); +int qbus_reset_one(BusState *bus, void *opaque); + #endif