From patchwork Wed Apr 29 19:20:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 466261 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 A474414007D for ; Thu, 30 Apr 2015 05:29:17 +1000 (AEST) Received: from localhost ([::1]:40776 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnXfW-0007ba-EA for incoming@patchwork.ozlabs.org; Wed, 29 Apr 2015 15:29:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39146) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnXXt-0001fW-48 for qemu-devel@nongnu.org; Wed, 29 Apr 2015 15:21:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YnXXn-0006FP-6k for qemu-devel@nongnu.org; Wed, 29 Apr 2015 15:21:21 -0400 Received: from e36.co.us.ibm.com ([32.97.110.154]:53535) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnXXn-0006F2-0c for qemu-devel@nongnu.org; Wed, 29 Apr 2015 15:21:15 -0400 Received: from /spool/local by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 29 Apr 2015 13:21:14 -0600 Received: from d03dlp03.boulder.ibm.com (9.17.202.179) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 29 Apr 2015 13:21:12 -0600 Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id 0D49B19D803F; Wed, 29 Apr 2015 13:12:16 -0600 (MDT) Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t3TJLBYf33095810; Wed, 29 Apr 2015 12:21:11 -0700 Received: from d03av03.boulder.ibm.com (localhost [127.0.0.1]) by d03av03.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t3TJLBo1022260; Wed, 29 Apr 2015 13:21:11 -0600 Received: from localhost ([9.80.84.126]) by d03av03.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t3TJL91m022183; Wed, 29 Apr 2015 13:21:10 -0600 From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 29 Apr 2015 14:20:14 -0500 Message-Id: <1430335224-6716-6-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1430335224-6716-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1430335224-6716-1-git-send-email-mdroth@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15042919-0021-0000-0000-00000A29DC5B X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 32.97.110.154 Cc: aik@ozlabs.ru, nfont@linux.vnet.ibm.com, bharata@linux.vnet.ibm.com, qemu-ppc@nongnu.org, david@gibson.dropbear.id.au Subject: [Qemu-devel] [RFC PATCH 05/15] spapr_pci: add PHB unrealize 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 To support PHB hotplug we need to clean up lingering references, memory, child properties, etc. prior to the PHB object being finalized. Generally this will be called as a result of calling object_unref() on the PHB object, which in turn would normally be called as the result of an unplug() operation. When the PHB is finalized, child objects will be unparented in turn, and finalized if the PHB was the only reference holder. so we don't bother to explicitly unparent child objects of the PHB (spapr_iommu, spapr_drc, etc). We do need to handle memory regions explicitly however, since they also take a reference on the PHB, and won't allow it to be finalized otherwise. Signed-off-by: Michael Roth --- hw/ppc/spapr_pci.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 2e7590c..25a738c 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1108,6 +1108,37 @@ static void spapr_phb_hot_unplug_child(HotplugHandler *plug_handler, } } +static void spapr_phb_unrealize(DeviceState *dev, Error **errp) +{ + SysBusDevice *s = SYS_BUS_DEVICE(dev); + PCIHostState *phb = PCI_HOST_BRIDGE(s); + sPAPRPHBState *sphb = SPAPR_PCI_HOST_BRIDGE(phb); + sPAPRTCETable *tcet; + + pci_unregister_bus(phb->bus); + + g_free(sphb->dtbusname); + sphb->dtbusname = NULL; + + /* remove IO/MMIO subregions and aliases, rest should get cleaned + * via PHB's unrealize->object_finalize + */ + memory_region_del_subregion(get_system_memory(), &sphb->iowindow); + object_unparent(OBJECT(&sphb->iowindow)); + object_unparent(OBJECT(&sphb->iospace)); + + memory_region_del_subregion(get_system_memory(), &sphb->memwindow); + object_unparent(OBJECT(&sphb->memwindow)); + object_unparent(OBJECT(&sphb->memspace)); + + tcet = spapr_tce_find_by_liobn(sphb->dma_liobn); + memory_region_del_subregion(&sphb->iommu_root, &sphb->msiwindow); + memory_region_del_subregion(&sphb->iommu_root, spapr_tce_get_iommu(tcet)); + address_space_destroy(&sphb->iommu_as); + + QLIST_REMOVE(sphb, list); +} + static void spapr_phb_realize(DeviceState *dev, Error **errp) { SysBusDevice *s = SYS_BUS_DEVICE(dev); @@ -1442,6 +1473,7 @@ static void spapr_phb_class_init(ObjectClass *klass, void *data) hc->root_bus_path = spapr_phb_root_bus_path; dc->realize = spapr_phb_realize; + dc->unrealize = spapr_phb_unrealize; dc->props = spapr_phb_properties; dc->reset = spapr_phb_reset; dc->vmsd = &vmstate_spapr_pci;