From patchwork Wed Apr 29 19:20:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 466258 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 C28271402BC for ; Thu, 30 Apr 2015 05:27:30 +1000 (AEST) Received: from localhost ([::1]:40751 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnXdo-0003zK-V5 for incoming@patchwork.ozlabs.org; Wed, 29 Apr 2015 15:27:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38974) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnXXk-0001O0-BW for qemu-devel@nongnu.org; Wed, 29 Apr 2015 15:21:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YnXXg-0006Bx-Js for qemu-devel@nongnu.org; Wed, 29 Apr 2015 15:21:12 -0400 Received: from e17.ny.us.ibm.com ([129.33.205.207]:51076) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnXXg-0006Bg-Fj for qemu-devel@nongnu.org; Wed, 29 Apr 2015 15:21:08 -0400 Received: from /spool/local by e17.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 29 Apr 2015 15:21:08 -0400 Received: from d01dlp01.pok.ibm.com (9.56.250.166) by e17.ny.us.ibm.com (146.89.104.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 29 Apr 2015 15:21:05 -0400 Received: from b01cxnp22033.gho.pok.ibm.com (b01cxnp22033.gho.pok.ibm.com [9.57.198.23]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id 15F3B38C804A; Wed, 29 Apr 2015 15:21:03 -0400 (EDT) Received: from d01av01.pok.ibm.com (d01av01.pok.ibm.com [9.56.224.215]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t3TJL2sW58720436; Wed, 29 Apr 2015 19:21:03 GMT Received: from d01av01.pok.ibm.com (localhost [127.0.0.1]) by d01av01.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t3TJL2kI012351; Wed, 29 Apr 2015 15:21:02 -0400 Received: from localhost ([9.80.84.126]) by d01av01.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t3TJL1RX012307; Wed, 29 Apr 2015 15:21:02 -0400 From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 29 Apr 2015 14:20:24 -0500 Message-Id: <1430335224-6716-16-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-0041-0000-0000-00000031030F X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 129.33.205.207 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 15/15] spapr: add hotplug hooks for PHB hotplug 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 Hotplugging PHBs is a machine-level operation, but PHBs reside on the main system bus, so we register spapr machine as the handler for the main system bus. The entry point for plug/unplug is shared by all such machine-level hotplug operations (memory, CPU, PHB, etc), and from there we branch off to specific hotplug callbacks based on the object type. Signed-off-by: Michael Roth Reviewed-by: David Gibson --- hw/ppc/spapr.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index ecf40e4..25c46bb 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -62,6 +62,7 @@ #include "hw/compat.h" #include +#include "sysemu/device_tree.h" /* SLOF memory layout: * @@ -1711,6 +1712,11 @@ static void ppc_spapr_init(MachineState *machine) /* used by RTAS */ QTAILQ_INIT(&spapr->ccs_list); qemu_register_reset(spapr_ccs_reset_hook, spapr); + + if (spapr->dr_phb_enabled) { + qbus_set_hotplug_handler_generic(sysbus_get_default(), OBJECT(machine), + NULL); + } } static int spapr_kvm_type(const char *vm_type) @@ -1829,14 +1835,104 @@ static void spapr_nmi(NMIState *n, int cpu_index, Error **errp) } } +static void spapr_machine_phb_plug(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + sPAPRPHBState *sphb; + void *fdt = NULL; + int fdt_start_offset = 0; + int fdt_size = 0; + Error *local_err = NULL; + sPAPRDRConnector *drc; + sPAPRDRConnectorClass *drck; + + sphb = SPAPR_PCI_HOST_BRIDGE(dev); + drc = spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_PHB, sphb->index); + /* hotplug hooks should check it's enabled before getting this far */ + g_assert(drc); + drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); + + /* boot-time devices get their device tree node created by SLOF, but for + * hotplugged devices we need QEMU to generate it so the guest can fetch + * it via RTAS + */ + if (dev->hotplugged) { + int ret; + fdt = create_device_tree(&fdt_size); + ret = spapr_populate_pci_dt(sphb, PHANDLE_XICP, fdt, &fdt_start_offset); + if (ret < 0) { + error_setg(&local_err, "unable to create FDT for hotplugged PHB"); + goto out; + } + + /* generally SLOF creates these, for hotplug it's up to QEMU */ + _FDT(fdt_setprop_string(fdt, fdt_start_offset, "name", "pci")); + } + + /* boot-time devices still get associated with a DRC to allow for unplug, + * but since we use SLOF-generated DT here we don't need to re-generate it + */ + drck->attach(drc, DEVICE(dev), + fdt, fdt_start_offset, !dev->hotplugged, &local_err); +out: + if (local_err) { + error_propagate(errp, local_err); + g_free(fdt); + return; + } + + if (dev->hotplugged) { + spapr_hotplug_req_add_event(drc); + } +} + +static void spapr_machine_phb_remove_cb(DeviceState *dev, void *opaque) +{ + object_unparent(OBJECT(dev)); +} + +static void spapr_machine_phb_unplug(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + sPAPRPHBState *sphb; + sPAPRDRConnector *drc; + sPAPRDRConnectorClass *drck; + Error *local_err = NULL; + + sphb = SPAPR_PCI_HOST_BRIDGE(dev); + drc = spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_PHB, sphb->index); + g_assert(drc); + drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); + + if (!drck->release_pending(drc)) { + drck->detach(drc, DEVICE(dev), spapr_machine_phb_remove_cb, NULL, + &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + spapr_hotplug_req_remove_event(drc); + } +} + static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { + if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_PCI_HOST_BRIDGE)) { + if (spapr->dr_phb_enabled) { + spapr_machine_phb_plug(hotplug_dev, dev, errp); + } + } } static void spapr_machine_device_unplug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { + if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_PCI_HOST_BRIDGE)) { + if (spapr->dr_phb_enabled) { + spapr_machine_phb_unplug(hotplug_dev, dev, errp); + } + } } static HotplugHandler *spapr_get_hotplug_handler(MachineState *machine,