From patchwork Wed Apr 26 21:31:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 9702051 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F350B603F4 for ; Wed, 26 Apr 2017 21:33:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3B0A2858E for ; Wed, 26 Apr 2017 21:33:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5852285EA; Wed, 26 Apr 2017 21:33:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id E11042858E for ; Wed, 26 Apr 2017 21:33:11 +0000 (UTC) Received: from localhost ([::1]:57230 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3UYh-0002vN-2r for patchwork-qemu-devel@patchwork.kernel.org; Wed, 26 Apr 2017 17:33:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48880) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3UXN-0002so-9c for qemu-devel@nongnu.org; Wed, 26 Apr 2017 17:31:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3UXI-0003X6-Ck for qemu-devel@nongnu.org; Wed, 26 Apr 2017 17:31:49 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:42905 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3UXI-0003Wa-6f for qemu-devel@nongnu.org; Wed, 26 Apr 2017 17:31:44 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v3QLSmij017958 for ; Wed, 26 Apr 2017 17:31:42 -0400 Received: from e24smtp04.br.ibm.com (e24smtp04.br.ibm.com [32.104.18.25]) by mx0a-001b2d01.pphosted.com with ESMTP id 2a2ebvh1fn-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 26 Apr 2017 17:31:41 -0400 Received: from localhost by e24smtp04.br.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 26 Apr 2017 18:31:39 -0300 Received: from d24relay03.br.ibm.com (9.18.232.225) by e24smtp04.br.ibm.com (10.172.0.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 26 Apr 2017 18:31:38 -0300 Received: from d24av01.br.ibm.com (d24av01.br.ibm.com [9.8.31.91]) by d24relay03.br.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v3QLVb0x18219152; Wed, 26 Apr 2017 18:31:37 -0300 Received: from d24av01.br.ibm.com (localhost [127.0.0.1]) by d24av01.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v3QLVbPw017208; Wed, 26 Apr 2017 18:31:37 -0300 Received: from localhost.localdomain ([9.85.186.39]) by d24av01.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v3QLVWkT017183; Wed, 26 Apr 2017 18:31:35 -0300 From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Wed, 26 Apr 2017 18:31:21 -0300 X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170426213124.29064-1-danielhb@linux.vnet.ibm.com> References: <20170426213124.29064-1-danielhb@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17042621-0028-0000-0000-000001AEA48C X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17042621-0029-0000-0000-000014AEE75F Message-Id: <20170426213124.29064-2-danielhb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-26_14:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1704260353 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH 1/4] hw/ppc: setting spapr_drc_detach_cb in spapr_dr_connector_new X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The idea of moving the detach callback functions to the constructor of the dr_connector is to set them statically at init time, avoiding any post-load hooks to restore it (after a migration, for example). Summary of changes: - hw/ppc/spapr_drc.c and include/hw/ppc/spapr_drc.h: * spapr_dr_connector_new() now has an additional parameter, spapr_drc_detach_cb *detach_cb * 'spapr_drc_detach_cb *detach_cb' parameter was removed of the detach function pointer in sPAPRDRConnectorClass - hw/ppc/spapr_pci.c: * the callback 'spapr_phb_remove_pci_device_cb' is now passed as a parameter in 'spapr_dr_connector_new' instead of 'drck->detach()' - hw/ppc/spapr.c: * 'spapr_create_lmb_dr_connectors' now passes the callback 'spapr_lmb_release' to 'spapr_dr_connector_new' instead of 'drck-detach()' * 'spapr_init_cpus' now passes the callback 'spapr_core_release' to 'spapr_dr_connector_new' instead of 'drck-detach()' * moved the callback functions up in the code so they can be referenced by 'spapr_create_lmb_dr_connectors' and 'spapr_init_cpus' Signed-off-by: Daniel Henrique Barboza --- hw/ppc/spapr.c | 71 +++++++++++++++++++++++----------------------- hw/ppc/spapr_drc.c | 17 ++++++----- hw/ppc/spapr_pci.c | 5 ++-- include/hw/ppc/spapr_drc.h | 4 +-- 4 files changed, 49 insertions(+), 48 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 80d12d0..bc11757 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1887,6 +1887,29 @@ static void spapr_drc_reset(void *opaque) } } +typedef struct sPAPRDIMMState { + uint32_t nr_lmbs; +} sPAPRDIMMState; + +static void spapr_lmb_release(DeviceState *dev, void *opaque) +{ + sPAPRDIMMState *ds = (sPAPRDIMMState *)opaque; + HotplugHandler *hotplug_ctrl; + + if (--ds->nr_lmbs) { + return; + } + + g_free(ds); + + /* + * Now that all the LMBs have been removed by the guest, call the + * pc-dimm unplug handler to cleanup up the pc-dimm device. + */ + hotplug_ctrl = qdev_get_hotplug_handler(dev); + hotplug_handler_unplug(hotplug_ctrl, dev, &error_abort); +} + static void spapr_create_lmb_dr_connectors(sPAPRMachineState *spapr) { MachineState *machine = MACHINE(spapr); @@ -1900,7 +1923,7 @@ static void spapr_create_lmb_dr_connectors(sPAPRMachineState *spapr) addr = i * lmb_size + spapr->hotplug_memory.base; drc = spapr_dr_connector_new(OBJECT(spapr), SPAPR_DR_CONNECTOR_TYPE_LMB, - addr/lmb_size); + (addr / lmb_size), spapr_lmb_release); qemu_register_reset(spapr_drc_reset, drc); } } @@ -1956,6 +1979,14 @@ static CPUArchId *spapr_find_cpu_slot(MachineState *ms, uint32_t id, int *idx) return &ms->possible_cpus->cpus[index]; } +static void spapr_core_release(DeviceState *dev, void *opaque) +{ + HotplugHandler *hotplug_ctrl; + + hotplug_ctrl = qdev_get_hotplug_handler(dev); + hotplug_handler_unplug(hotplug_ctrl, dev, &error_abort); +} + static void spapr_init_cpus(sPAPRMachineState *spapr) { MachineState *machine = MACHINE(spapr); @@ -1998,7 +2029,8 @@ static void spapr_init_cpus(sPAPRMachineState *spapr) sPAPRDRConnector *drc = spapr_dr_connector_new(OBJECT(spapr), SPAPR_DR_CONNECTOR_TYPE_CPU, - (core_id / smp_threads) * smt); + (core_id / smp_threads) * smt, + spapr_core_release); qemu_register_reset(spapr_drc_reset, drc); } @@ -2596,29 +2628,6 @@ out: error_propagate(errp, local_err); } -typedef struct sPAPRDIMMState { - uint32_t nr_lmbs; -} sPAPRDIMMState; - -static void spapr_lmb_release(DeviceState *dev, void *opaque) -{ - sPAPRDIMMState *ds = (sPAPRDIMMState *)opaque; - HotplugHandler *hotplug_ctrl; - - if (--ds->nr_lmbs) { - return; - } - - g_free(ds); - - /* - * Now that all the LMBs have been removed by the guest, call the - * pc-dimm unplug handler to cleanup up the pc-dimm device. - */ - hotplug_ctrl = qdev_get_hotplug_handler(dev); - hotplug_handler_unplug(hotplug_ctrl, dev, &error_abort); -} - static void spapr_del_lmbs(DeviceState *dev, uint64_t addr_start, uint64_t size, Error **errp) { @@ -2636,7 +2645,7 @@ static void spapr_del_lmbs(DeviceState *dev, uint64_t addr_start, uint64_t size, g_assert(drc); drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); - drck->detach(drc, dev, spapr_lmb_release, ds, errp); + drck->detach(drc, dev, ds, errp); addr += SPAPR_MEMORY_BLOCK_SIZE; } @@ -2712,14 +2721,6 @@ static void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev, object_unparent(OBJECT(dev)); } -static void spapr_core_release(DeviceState *dev, void *opaque) -{ - HotplugHandler *hotplug_ctrl; - - hotplug_ctrl = qdev_get_hotplug_handler(dev); - hotplug_handler_unplug(hotplug_ctrl, dev, &error_abort); -} - static void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) @@ -2745,7 +2746,7 @@ void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev, g_assert(drc); drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); - drck->detach(drc, dev, spapr_core_release, NULL, &local_err); + drck->detach(drc, dev, NULL, &local_err); if (local_err) { error_propagate(errp, local_err); return; diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index a1cdc87..afe5d82 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -99,8 +99,8 @@ static uint32_t set_isolation_state(sPAPRDRConnector *drc, if (drc->awaiting_release) { if (drc->configured) { trace_spapr_drc_set_isolation_state_finalizing(get_index(drc)); - drck->detach(drc, DEVICE(drc->dev), drc->detach_cb, - drc->detach_cb_opaque, NULL); + drck->detach(drc, DEVICE(drc->dev), drc->detach_cb_opaque, + NULL); } else { trace_spapr_drc_set_isolation_state_deferring(get_index(drc)); } @@ -153,8 +153,8 @@ static uint32_t set_allocation_state(sPAPRDRConnector *drc, if (drc->awaiting_release && drc->allocation_state == SPAPR_DR_ALLOCATION_STATE_UNUSABLE) { trace_spapr_drc_set_allocation_state_finalizing(get_index(drc)); - drck->detach(drc, DEVICE(drc->dev), drc->detach_cb, - drc->detach_cb_opaque, NULL); + drck->detach(drc, DEVICE(drc->dev), drc->detach_cb_opaque, + NULL); } else if (drc->allocation_state == SPAPR_DR_ALLOCATION_STATE_USABLE) { drc->awaiting_allocation = false; } @@ -405,12 +405,10 @@ static void attach(sPAPRDRConnector *drc, DeviceState *d, void *fdt, } static void detach(sPAPRDRConnector *drc, DeviceState *d, - spapr_drc_detach_cb *detach_cb, void *detach_cb_opaque, Error **errp) { trace_spapr_drc_detach(get_index(drc)); - drc->detach_cb = detach_cb; drc->detach_cb_opaque = detach_cb_opaque; /* if we've signalled device presence to the guest, or if the guest @@ -498,8 +496,7 @@ static void reset(DeviceState *d) * force removal if we are */ if (drc->awaiting_release) { - drck->detach(drc, DEVICE(drc->dev), drc->detach_cb, - drc->detach_cb_opaque, NULL); + drck->detach(drc, DEVICE(drc->dev), drc->detach_cb_opaque, NULL); } /* non-PCI devices may be awaiting a transition to UNUSABLE */ @@ -566,7 +563,8 @@ static void unrealize(DeviceState *d, Error **errp) sPAPRDRConnector *spapr_dr_connector_new(Object *owner, sPAPRDRConnectorType type, - uint32_t id) + uint32_t id, + spapr_drc_detach_cb *detach_cb) { sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(object_new(TYPE_SPAPR_DR_CONNECTOR)); @@ -577,6 +575,7 @@ sPAPRDRConnector *spapr_dr_connector_new(Object *owner, drc->type = type; drc->id = id; drc->owner = owner; + drc->detach_cb = detach_cb; prop_name = g_strdup_printf("dr-connector[%"PRIu32"]", get_index(drc)); object_property_add_child(owner, prop_name, OBJECT(drc), NULL); object_property_set_bool(OBJECT(drc), true, "realized", NULL); diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index e7567e2..935e65e 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1392,7 +1392,7 @@ static void spapr_phb_remove_pci_device(sPAPRDRConnector *drc, { sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); - drck->detach(drc, DEVICE(pdev), spapr_phb_remove_pci_device_cb, phb, errp); + drck->detach(drc, DEVICE(pdev), phb, errp); } static sPAPRDRConnector *spapr_phb_get_pci_func_drc(sPAPRPHBState *phb, @@ -1764,7 +1764,8 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp) for (i = 0; i < PCI_SLOT_MAX * 8; i++) { spapr_dr_connector_new(OBJECT(phb), SPAPR_DR_CONNECTOR_TYPE_PCI, - (sphb->index << 16) | i); + (sphb->index << 16) | i, + spapr_phb_remove_pci_device_cb); } } diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index 5524247..0a2c173 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -189,7 +189,6 @@ typedef struct sPAPRDRConnectorClass { void (*attach)(sPAPRDRConnector *drc, DeviceState *d, void *fdt, int fdt_start_offset, bool coldplug, Error **errp); void (*detach)(sPAPRDRConnector *drc, DeviceState *d, - spapr_drc_detach_cb *detach_cb, void *detach_cb_opaque, Error **errp); bool (*release_pending)(sPAPRDRConnector *drc); void (*set_signalled)(sPAPRDRConnector *drc); @@ -197,7 +196,8 @@ typedef struct sPAPRDRConnectorClass { sPAPRDRConnector *spapr_dr_connector_new(Object *owner, sPAPRDRConnectorType type, - uint32_t id); + uint32_t id, + spapr_drc_detach_cb *detach_cb); sPAPRDRConnector *spapr_dr_connector_by_index(uint32_t index); sPAPRDRConnector *spapr_dr_connector_by_id(sPAPRDRConnectorType type, uint32_t id);