From patchwork Mon May 25 10:06:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenfan X-Patchwork-Id: 476125 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 00A821402B4 for ; Mon, 25 May 2015 20:10:46 +1000 (AEST) Received: from localhost ([::1]:42766 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YwpLI-0006cn-18 for incoming@patchwork.ozlabs.org; Mon, 25 May 2015 06:10:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53715) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YwpIr-0001nq-3Y for qemu-devel@nongnu.org; Mon, 25 May 2015 06:08:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YwpIm-0003KG-6z for qemu-devel@nongnu.org; Mon, 25 May 2015 06:08:12 -0400 Received: from [59.151.112.132] (port=47539 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YwpIl-0003IO-5D for qemu-devel@nongnu.org; Mon, 25 May 2015 06:08:08 -0400 X-IronPort-AV: E=Sophos;i="5.01,1,1399996800"; d="scan'208";a="95799061" Received: from localhost (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 25 May 2015 18:12:35 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t4PA6dxM014456; Mon, 25 May 2015 18:06:39 +0800 Received: from G08FNSTD131468.g08.fujitsu.local (10.167.226.78) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Mon, 25 May 2015 18:08:07 +0800 From: Chen Fan To: Date: Mon, 25 May 2015 18:06:08 +0800 Message-ID: <514162f0ccb789bf5c4f7f7d07b3090f29f955b5.1432548038.git.chen.fan.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.167.226.78] X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: izumi.taku@jp.fujitsu.com, alex.williamson@redhat.com, "Michael S. Tsirkin" Subject: [Qemu-devel] [RFC v8 08/13] pci: add bus reset_notifiers callbacks for host bus 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Particularly, For vfio devices, Once need to recovery devices by bus reset such as AER, we always need to reset the host bus to recovery the devices under the bus, so we need to add pci bus callbacks to specify to do host bus reset. Cc: Michael S. Tsirkin Signed-off-by: Chen Fan --- hw/pci/pci.c | 16 ++++++++++++++++ hw/pci/pci_bridge.c | 5 +++++ include/hw/pci/pci.h | 4 ++++ include/hw/pci/pci_bus.h | 2 ++ 4 files changed, 27 insertions(+) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 48f19a3..0878834 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -74,11 +74,27 @@ static const VMStateDescription vmstate_pcibus = { } }; +void pci_bus_add_reset_notifier(PCIBus *bus, Notifier *notify) +{ + notifier_list_add(&bus->reset_notifiers, notify); +} + +void pci_bus_remove_reset_notifier(Notifier *notify) +{ + notifier_remove(notify); +} + +void pci_bus_run_reset_notifier(PCIBus *bus, void *opaque) +{ + notifier_list_notify(&bus->reset_notifiers, opaque); +} + static void pci_bus_realize(BusState *qbus, Error **errp) { PCIBus *bus = PCI_BUS(qbus); vmstate_register(NULL, -1, &vmstate_pcibus, bus); + notifier_list_init(&bus->reset_notifiers); } static void pci_bus_unrealize(BusState *qbus, Error **errp) diff --git a/hw/pci/pci_bridge.c b/hw/pci/pci_bridge.c index 40c97b1..75d2b4b 100644 --- a/hw/pci/pci_bridge.c +++ b/hw/pci/pci_bridge.c @@ -267,6 +267,11 @@ void pci_bridge_write_config(PCIDevice *d, newctl = pci_get_word(d->config + PCI_BRIDGE_CONTROL); if (~oldctl & newctl & PCI_BRIDGE_CTL_BUS_RESET) { + /* + * Notify all vfio-pci devices under the bus + * to do physical bus reset. + */ + pci_for_each_bus(&s->sec_bus, pci_bus_run_reset_notifier, NULL); /* Trigger hot reset on 0->1 transition. */ qbus_reset_all(&s->sec_bus.qbus); } diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 5d050c8..5a9357c 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -7,6 +7,7 @@ #include "exec/memory.h" #include "sysemu/dma.h" #include "qapi/error.h" +#include "qemu/notify.h" /* PCI includes legacy ISA access. */ #include "hw/isa/isa.h" @@ -371,6 +372,9 @@ void pci_bus_fire_intx_routing_notifier(PCIBus *bus); void pci_device_set_intx_routing_notifier(PCIDevice *dev, PCIINTxRoutingNotifier notifier); void pci_device_reset(PCIDevice *dev); +void pci_bus_add_reset_notifier(PCIBus *bus, Notifier *notify); +void pci_bus_remove_reset_notifier(Notifier *notify); +void pci_bus_run_reset_notifier(PCIBus *bus, void *opaque); PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus, const char *default_model, diff --git a/include/hw/pci/pci_bus.h b/include/hw/pci/pci_bus.h index fabaeee..3b551d7 100644 --- a/include/hw/pci/pci_bus.h +++ b/include/hw/pci/pci_bus.h @@ -29,6 +29,8 @@ struct PCIBus { Keep a count of the number of devices with raised IRQs. */ int nirq; int *irq_count; + + NotifierList reset_notifiers; }; typedef struct PCIBridgeWindows PCIBridgeWindows;