From nobody Mon Feb 9 02:48:38 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496805742920259.2673350808516; Tue, 6 Jun 2017 20:22:22 -0700 (PDT) Received: from localhost ([::1]:41026 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIRY4-0004n5-8l for importer@patchew.org; Tue, 06 Jun 2017 23:22:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37953) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIRWH-0003Zk-49 for qemu-devel@nongnu.org; Tue, 06 Jun 2017 23:20:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIRWF-0002Sh-NM for qemu-devel@nongnu.org; Tue, 06 Jun 2017 23:20:29 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:38899) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIRWF-0002PC-0B; Tue, 06 Jun 2017 23:20:27 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wjDMV38NRz9sDC; Wed, 7 Jun 2017 13:20:22 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1496805622; bh=qy3PEVNUAvqDqw/VNyIBBJ0boEKHNgyixCRMGAQvQg0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oft09nagL9Bn5guFEgYRy8Z/pCQQ2lmf1vJqz28OOCFTtNHexAO/4rjciod4lcuD2 D3sIEzI5TX/0aPiFAgHJcBSpH4cw2SB24kMc4h2M/dALdPPxpns4TEB/AaF20rOTiu 3XJJ2jCQz+tpdSxiaW0te4qvxZz5ZqOmV0EWnMTk= From: David Gibson To: mdroth@linux.vnet.ibm.com Date: Wed, 7 Jun 2017 13:20:12 +1000 Message-Id: <20170607032018.19588-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170607032018.19588-1-david@gibson.dropbear.id.au> References: <20170607032018.19588-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PATCHv2 1/7] spapr: Clean up DR entity sense handling 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: sursingh@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, bharata@linux.vnet.ibm.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" DRC classes have an entity_sense method to determine (in a specific PAPR sense) the presence or absence of a device plugged into a DRC. However, we only have one implementation of the method, which explicitly tests for different DRC types. This changes it to instead have different method implementations for the two cases: "logical" and "physical" DRCs. While we're at it, the entity sense method always returns RTAS_OUT_SUCCESS, and the interesting value is returned via pass-by-reference. Simplify this to directly return the value we care about Signed-off-by: David Gibson Acked-by: Michael Roth Reviewed-by: Michael Roth --- hw/ppc/spapr_drc.c | 72 ++++++++++++++++++++++--------------------= ---- hw/ppc/spapr_pci.c | 6 ++-- hw/ppc/trace-events | 1 - include/hw/ppc/spapr_drc.h | 4 +-- 4 files changed, 40 insertions(+), 43 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 39e7f30..cabeacf 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -185,39 +185,25 @@ static void set_signalled(sPAPRDRConnector *drc) * based on the current allocation/indicator/power states * for the DR connector. */ -static uint32_t entity_sense(sPAPRDRConnector *drc, sPAPRDREntitySense *st= ate) +static sPAPRDREntitySense physical_entity_sense(sPAPRDRConnector *drc) { - if (drc->dev) { - if (spapr_drc_type(drc) !=3D SPAPR_DR_CONNECTOR_TYPE_PCI && - drc->allocation_state =3D=3D SPAPR_DR_ALLOCATION_STATE_UNUSABL= E) { - /* for logical DR, we return a state of UNUSABLE - * iff the allocation state UNUSABLE. - * Otherwise, report the state as USABLE/PRESENT, - * as we would for PCI. - */ - *state =3D SPAPR_DR_ENTITY_SENSE_UNUSABLE; - } else { - /* this assumes all PCI devices are assigned to - * a 'live insertion' power domain, where QEMU - * manages power state automatically as opposed - * to the guest. present, non-PCI resources are - * unaffected by power state. - */ - *state =3D SPAPR_DR_ENTITY_SENSE_PRESENT; - } + /* this assumes all PCI devices are assigned to a 'live insertion' + * power domain, where QEMU manages power state automatically as + * opposed to the guest. present, non-PCI resources are unaffected + * by power state. + */ + return drc->dev ? SPAPR_DR_ENTITY_SENSE_PRESENT + : SPAPR_DR_ENTITY_SENSE_EMPTY; +} + +static sPAPRDREntitySense logical_entity_sense(sPAPRDRConnector *drc) +{ + if (drc->dev + && (drc->allocation_state !=3D SPAPR_DR_ALLOCATION_STATE_UNUSABLE)= ) { + return SPAPR_DR_ENTITY_SENSE_PRESENT; } else { - if (spapr_drc_type(drc) =3D=3D SPAPR_DR_CONNECTOR_TYPE_PCI) { - /* PCI devices, and only PCI devices, use EMPTY - * in cases where we'd otherwise use UNUSABLE - */ - *state =3D SPAPR_DR_ENTITY_SENSE_EMPTY; - } else { - *state =3D SPAPR_DR_ENTITY_SENSE_UNUSABLE; - } + return SPAPR_DR_ENTITY_SENSE_UNUSABLE; } - - trace_spapr_drc_entity_sense(spapr_drc_index(drc), *state); - return RTAS_OUT_SUCCESS; } =20 static void prop_get_index(Object *obj, Visitor *v, const char *name, @@ -445,7 +431,6 @@ static void reset(DeviceState *d) { sPAPRDRConnector *drc =3D SPAPR_DR_CONNECTOR(d); sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - sPAPRDREntitySense state; =20 trace_spapr_drc_reset(spapr_drc_index(drc)); =20 @@ -477,8 +462,7 @@ static void reset(DeviceState *d) } } =20 - drck->entity_sense(drc, &state); - if (state =3D=3D SPAPR_DR_ENTITY_SENSE_PRESENT) { + if (drck->dr_entity_sense(drc) =3D=3D SPAPR_DR_ENTITY_SENSE_PRESENT) { drck->set_signalled(drc); } } @@ -488,8 +472,7 @@ static bool spapr_drc_needed(void *opaque) sPAPRDRConnector *drc =3D (sPAPRDRConnector *)opaque; sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); bool rc =3D false; - sPAPRDREntitySense value; - drck->entity_sense(drc, &value); + sPAPRDREntitySense value =3D drck->dr_entity_sense(drc); =20 /* If no dev is plugged in there is no need to migrate the DRC state */ if (value !=3D SPAPR_DR_ENTITY_SENSE_PRESENT) { @@ -667,7 +650,6 @@ static void spapr_dr_connector_class_init(ObjectClass *= k, void *data) drck->set_indicator_state =3D set_indicator_state; drck->set_allocation_state =3D set_allocation_state; drck->get_name =3D get_name; - drck->entity_sense =3D entity_sense; drck->attach =3D attach; drck->detach =3D detach; drck->release_pending =3D release_pending; @@ -678,6 +660,20 @@ static void spapr_dr_connector_class_init(ObjectClass = *k, void *data) dk->user_creatable =3D false; } =20 +static void spapr_drc_physical_class_init(ObjectClass *k, void *data) +{ + sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_CLASS(k); + + drck->dr_entity_sense =3D physical_entity_sense; +} + +static void spapr_drc_logical_class_init(ObjectClass *k, void *data) +{ + sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_CLASS(k); + + drck->dr_entity_sense =3D logical_entity_sense; +} + static void spapr_drc_cpu_class_init(ObjectClass *k, void *data) { sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_CLASS(k); @@ -716,6 +712,7 @@ static const TypeInfo spapr_drc_physical_info =3D { .name =3D TYPE_SPAPR_DRC_PHYSICAL, .parent =3D TYPE_SPAPR_DR_CONNECTOR, .instance_size =3D sizeof(sPAPRDRConnector), + .class_init =3D spapr_drc_physical_class_init, .abstract =3D true, }; =20 @@ -723,6 +720,7 @@ static const TypeInfo spapr_drc_logical_info =3D { .name =3D TYPE_SPAPR_DRC_LOGICAL, .parent =3D TYPE_SPAPR_DR_CONNECTOR, .instance_size =3D sizeof(sPAPRDRConnector), + .class_init =3D spapr_drc_logical_class_init, .abstract =3D true, }; =20 @@ -1010,7 +1008,7 @@ static void rtas_get_sensor_state(PowerPCCPU *cpu, sP= APRMachineState *spapr, goto out; } drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - ret =3D drck->entity_sense(drc, &sensor_state); + sensor_state =3D drck->dr_entity_sense(drc); =20 out: rtas_st(rets, 0, ret); diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 0c181bb..5cba8f9 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1481,7 +1481,7 @@ static void spapr_phb_hot_plug_child(HotplugHandler *= plug_handler, func_drc =3D spapr_phb_get_pci_func_drc(phb, pci_bus_num(bus), PCI_DEVFN(slotnr, i)); func_drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(func_drc); - func_drck->entity_sense(func_drc, &state); + state =3D func_drck->dr_entity_sense(func_drc); =20 if (state =3D=3D SPAPR_DR_ENTITY_SENSE_PRESENT) { spapr_hotplug_req_add_by_index(func_drc); @@ -1522,7 +1522,7 @@ static void spapr_phb_hot_unplug_child(HotplugHandler= *plug_handler, func_drc =3D spapr_phb_get_pci_func_drc(phb, pci_bus_num(b= us), PCI_DEVFN(slotnr, i)= ); func_drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(func_drc); - func_drck->entity_sense(func_drc, &state); + state =3D func_drck->dr_entity_sense(func_drc); if (state =3D=3D SPAPR_DR_ENTITY_SENSE_PRESENT && !func_drck->release_pending(func_drc)) { error_setg(errp, @@ -1548,7 +1548,7 @@ static void spapr_phb_hot_unplug_child(HotplugHandler= *plug_handler, func_drc =3D spapr_phb_get_pci_func_drc(phb, pci_bus_num(b= us), PCI_DEVFN(slotnr, i)= ); func_drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(func_drc); - func_drck->entity_sense(func_drc, &state); + state =3D func_drck->dr_entity_sense(func_drc); if (state =3D=3D SPAPR_DR_ENTITY_SENSE_PRESENT) { spapr_hotplug_req_remove_by_index(func_drc); } diff --git a/hw/ppc/trace-events b/hw/ppc/trace-events index 43d265f..4979397 100644 --- a/hw/ppc/trace-events +++ b/hw/ppc/trace-events @@ -44,7 +44,6 @@ spapr_drc_set_allocation_state(uint32_t index, int state)= "drc: 0x%"PRIx32", sta spapr_drc_set_allocation_state_finalizing(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_set_configured(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_set_configured_skipping(uint32_t index) "drc: 0x%"PRIx32", isola= ted device" -spapr_drc_entity_sense(uint32_t index, int state) "drc: 0x%"PRIx32", state= : 0x%x" spapr_drc_attach(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_detach(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_awaiting_isolated(uint32_t index) "drc: 0x%"PRIx32 diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index c88e1be..f892b94 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -214,6 +214,8 @@ typedef struct sPAPRDRConnectorClass { sPAPRDRConnectorTypeShift typeshift; const char *typename; /* used in device tree, PAPR 13.5.2.6 & C.6.1 */ =20 + sPAPRDREntitySense (*dr_entity_sense)(sPAPRDRConnector *drc); + /* accessors for guest-visible (generally via RTAS) DR state */ uint32_t (*set_isolation_state)(sPAPRDRConnector *drc, sPAPRDRIsolationState state); @@ -223,8 +225,6 @@ typedef struct sPAPRDRConnectorClass { sPAPRDRAllocationState state); const char *(*get_name)(sPAPRDRConnector *drc); =20 - uint32_t (*entity_sense)(sPAPRDRConnector *drc, sPAPRDREntitySense *st= ate); - /* QEMU interfaces for managing hotplug operations */ void (*attach)(sPAPRDRConnector *drc, DeviceState *d, void *fdt, int fdt_start_offset, bool coldplug, Error **errp); --=20 2.9.4 From nobody Mon Feb 9 02:48:38 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496805891129494.91903150151154; Tue, 6 Jun 2017 20:24:51 -0700 (PDT) Received: from localhost ([::1]:41039 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIRaT-0007UM-Gn for importer@patchew.org; Tue, 06 Jun 2017 23:24:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38043) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIRWK-0003aZ-Az for qemu-devel@nongnu.org; Tue, 06 Jun 2017 23:20:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIRWI-0002Ur-Uf for qemu-devel@nongnu.org; Tue, 06 Jun 2017 23:20:32 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:39103) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIRWI-0002St-Ht; Tue, 06 Jun 2017 23:20:30 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wjDMW1gNdz9sNM; Wed, 7 Jun 2017 13:20:22 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1496805623; bh=wa4dHPPiqCHxejMHEulAtyGTfriYOXU/53tiX6pLilI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TzdA12Pcx2j3cIxX9M5uJK1wwhQBmm43R7xTcmFAaUtbmxaO4yswq2WDp2zJH6EPI LZlRBtZJDyy3ILhgUqU4KeCZKATEtVqbQ/PaRXO2qEFRP0dYrVf3ESjyz0hzjriOrs uQrw5ZEKYkBufbP4WQXp5lRyBDSfn2Mi+kNT1Wfc= From: David Gibson To: mdroth@linux.vnet.ibm.com Date: Wed, 7 Jun 2017 13:20:13 +1000 Message-Id: <20170607032018.19588-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170607032018.19588-1-david@gibson.dropbear.id.au> References: <20170607032018.19588-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PATCHv2 2/7] spapr: Don't misuse DR-indicator in spapr_recover_pending_dimm_state() 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: sursingh@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, bharata@linux.vnet.ibm.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" With some combinations of migration and hotplug we can lost temporary state indicating how many DRCs (guest side hotplug handles) are still connected to a DIMM object in the process of removal. When we hit that situation spapr_recover_pending_dimm_state() is used to scan more extensively and work out the right number. It does this using drc->indicator state to determine what state of disconnection the DRC is in. However, this is not safe, because the indicator state is guest settable - in fact it's more-or-less a purely guest->host notification mechanism which should have no bearing on the internals of hotplug state management. So, replace the test for this with a test on drc->dev, which is a purely qemu side managed variable, and updated the same BQL critical section as the indicator state. This does introduce an off-by-one change, because the indicator state was updated before the call to spapr_lmb_release() on the current DRC, whereas drc->dev is updated afterwards. That's corrected by always decrementing the nr_lmbs value instead of only doing so in the case where we didn't have to recover information. Signed-off-by: David Gibson Acked-by: Michael Roth Reviewed-by: Michael Roth --- hw/ppc/spapr.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 9b7ae28..b2311dc 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2676,7 +2676,7 @@ static sPAPRDIMMState *spapr_recover_pending_dimm_sta= te(sPAPRMachineState *ms, drc =3D spapr_drc_by_id(TYPE_SPAPR_DRC_LMB, addr / SPAPR_MEMORY_BLOCK_SIZE); g_assert(drc); - if (drc->indicator_state !=3D SPAPR_DR_INDICATOR_STATE_INACTIVE) { + if (drc->dev) { avail_lmbs++; } addr +=3D SPAPR_MEMORY_BLOCK_SIZE; @@ -2700,10 +2700,11 @@ void spapr_lmb_release(DeviceState *dev) * during the unplug process. In this case recover it. */ if (ds =3D=3D NULL) { ds =3D spapr_recover_pending_dimm_state(spapr, PC_DIMM(dev)); - if (ds->nr_lmbs) { - return; - } - } else if (--ds->nr_lmbs) { + /* The DRC being examined by the caller at least must be counted */ + g_assert(ds->nr_lmbs); + } + + if (--ds->nr_lmbs) { return; } =20 --=20 2.9.4 From nobody Mon Feb 9 02:48:38 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496805743210887.267821401113; Tue, 6 Jun 2017 20:22:23 -0700 (PDT) Received: from localhost ([::1]:41027 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIRY5-0004oN-Eh for importer@patchew.org; Tue, 06 Jun 2017 23:22:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38004) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIRWJ-0003a2-Bz for qemu-devel@nongnu.org; Tue, 06 Jun 2017 23:20:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIRWH-0002Tk-Vc for qemu-devel@nongnu.org; Tue, 06 Jun 2017 23:20:31 -0400 Received: from ozlabs.org ([103.22.144.67]:46821) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIRWH-0002Sp-KL; Tue, 06 Jun 2017 23:20:29 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wjDMW165Zz9sNS; Wed, 7 Jun 2017 13:20:22 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1496805623; bh=mtC0lCtBYTFVD9UCqfgpe4IJxVi3fSL+8tJAY/WJeYE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XdOeaLqdZtWGkFRamP+pQ10orGYUmSw/OXV6rsWEvxaJkRwRCf184yioZ50+XCKxQ tNcVPiyVF565ayBc0/ixEmfUCnA7PzFHs42436gHhIFN0wMZ6EJkcICCfvSXIaTmSq 17aGGQsFKTcQQ7pBOGfzQFoPTECTk/rdVlo3/NvQ= From: David Gibson To: mdroth@linux.vnet.ibm.com Date: Wed, 7 Jun 2017 13:20:14 +1000 Message-Id: <20170607032018.19588-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170607032018.19588-1-david@gibson.dropbear.id.au> References: <20170607032018.19588-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PATCHv2 3/7] spapr: Clean up RTAS set-indicator 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: sursingh@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, bharata@linux.vnet.ibm.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In theory the RTAS set-indicator call can be used for a number of "indicators" defined by PAPR. In practice the only ones we're ever likely to implement are those used for Dynamic Reconfiguration (i.e. hotplug). Because of this, the current implementation determines the associated DRC object, before dispatching based on the type of indicator. However, this means we also need a check that we're dealing with a DR related indicator at all, which duplicates some of the logic from the switch further down. Even though it means a bit of code duplication, things work out cleaner if we delegate the DRC lookup to the individual indicator type functions - and it also allows some further cleanups. While we're there, remove references to "sensor", a copy/paste artefact from the related, but distinct "get-sensor" call. Signed-off-by: David Gibson Acked-by: Michael Roth Reviewed-by: Michael Roth --- hw/ppc/spapr_drc.c | 84 ++++++++++++++++++++++++++++---------------------= ---- hw/ppc/trace-events | 2 -- 2 files changed, 44 insertions(+), 42 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index cabeacf..f0cff0b 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -903,74 +903,78 @@ out: * RTAS calls */ =20 -static bool sensor_type_is_dr(uint32_t sensor_type) +static uint32_t rtas_set_isolation_state(uint32_t idx, uint32_t state) { - switch (sensor_type) { - case RTAS_SENSOR_TYPE_ISOLATION_STATE: - case RTAS_SENSOR_TYPE_DR: - case RTAS_SENSOR_TYPE_ALLOCATION_STATE: - return true; + sPAPRDRConnector *drc =3D spapr_drc_by_index(idx); + sPAPRDRConnectorClass *drck; + + if (!drc) { + return RTAS_OUT_PARAM_ERROR; } =20 - return false; + drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); + return drck->set_isolation_state(drc, state); } =20 -static void rtas_set_indicator(PowerPCCPU *cpu, sPAPRMachineState *spapr, - uint32_t token, uint32_t nargs, - target_ulong args, uint32_t nret, - target_ulong rets) +static uint32_t rtas_set_allocation_state(uint32_t idx, uint32_t state) { - uint32_t sensor_type; - uint32_t sensor_index; - uint32_t sensor_state; - uint32_t ret =3D RTAS_OUT_SUCCESS; - sPAPRDRConnector *drc; + sPAPRDRConnector *drc =3D spapr_drc_by_index(idx); sPAPRDRConnectorClass *drck; =20 - if (nargs !=3D 3 || nret !=3D 1) { - ret =3D RTAS_OUT_PARAM_ERROR; - goto out; + if (!drc) { + return RTAS_OUT_PARAM_ERROR; } =20 - sensor_type =3D rtas_ld(args, 0); - sensor_index =3D rtas_ld(args, 1); - sensor_state =3D rtas_ld(args, 2); + drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); + return drck->set_allocation_state(drc, state); +} =20 - if (!sensor_type_is_dr(sensor_type)) { - goto out_unimplemented; - } +static uint32_t rtas_set_indicator_state(uint32_t idx, uint32_t state) +{ + sPAPRDRConnector *drc =3D spapr_drc_by_index(idx); + sPAPRDRConnectorClass *drck; =20 - /* if this is a DR sensor we can assume sensor_index =3D=3D drc_index = */ - drc =3D spapr_drc_by_index(sensor_index); if (!drc) { - trace_spapr_rtas_set_indicator_invalid(sensor_index); + return RTAS_OUT_PARAM_ERROR; + } + + drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); + return drck->set_indicator_state(drc, state); +} + +static void rtas_set_indicator(PowerPCCPU *cpu, sPAPRMachineState *spapr, + uint32_t token, + uint32_t nargs, target_ulong args, + uint32_t nret, target_ulong rets) +{ + uint32_t type, idx, state; + uint32_t ret =3D RTAS_OUT_SUCCESS; + + if (nargs !=3D 3 || nret !=3D 1) { ret =3D RTAS_OUT_PARAM_ERROR; goto out; } - drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); =20 - switch (sensor_type) { + type =3D rtas_ld(args, 0); + idx =3D rtas_ld(args, 1); + state =3D rtas_ld(args, 2); + + switch (type) { case RTAS_SENSOR_TYPE_ISOLATION_STATE: - ret =3D drck->set_isolation_state(drc, sensor_state); + ret =3D rtas_set_isolation_state(idx, state); break; case RTAS_SENSOR_TYPE_DR: - ret =3D drck->set_indicator_state(drc, sensor_state); + ret =3D rtas_set_indicator_state(idx, state); break; case RTAS_SENSOR_TYPE_ALLOCATION_STATE: - ret =3D drck->set_allocation_state(drc, sensor_state); + ret =3D rtas_set_allocation_state(idx, state); break; default: - goto out_unimplemented; + ret =3D RTAS_OUT_NOT_SUPPORTED; } =20 out: rtas_st(rets, 0, ret); - return; - -out_unimplemented: - /* currently only DR-related sensors are implemented */ - trace_spapr_rtas_set_indicator_not_supported(sensor_index, sensor_type= ); - rtas_st(rets, 0, RTAS_OUT_NOT_SUPPORTED); } =20 static void rtas_get_sensor_state(PowerPCCPU *cpu, sPAPRMachineState *spap= r, diff --git a/hw/ppc/trace-events b/hw/ppc/trace-events index 4979397..581fa85 100644 --- a/hw/ppc/trace-events +++ b/hw/ppc/trace-events @@ -60,8 +60,6 @@ spapr_ovec_parse_vector(int vector, int byte, uint16_t ve= c_len, uint8_t entry) " spapr_ovec_populate_dt(int byte, uint16_t vec_len, uint8_t entry) "encodin= g guest vector byte %3d / %3d: 0x%.2x" =20 # hw/ppc/spapr_rtas.c -spapr_rtas_set_indicator_invalid(uint32_t index) "sensor index: 0x%"PRIx32 -spapr_rtas_set_indicator_not_supported(uint32_t index, uint32_t type) "sen= sor index: 0x%"PRIx32", type: %"PRIu32 spapr_rtas_get_sensor_state_not_supported(uint32_t index, uint32_t type) "= sensor index: 0x%"PRIx32", type: %"PRIu32 spapr_rtas_get_sensor_state_invalid(uint32_t index) "sensor index: 0x%"PRI= x32 spapr_rtas_ibm_configure_connector_invalid(uint32_t index) "DRC index: 0x%= "PRIx32 --=20 2.9.4 From nobody Mon Feb 9 02:48:38 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496806097247756.6014251707736; Tue, 6 Jun 2017 20:28:17 -0700 (PDT) Received: from localhost ([::1]:41061 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIRdn-0002UT-Ox for importer@patchew.org; Tue, 06 Jun 2017 23:28:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38005) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIRWJ-0003a3-Cx for qemu-devel@nongnu.org; Tue, 06 Jun 2017 23:20:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIRWH-0002TZ-OW for qemu-devel@nongnu.org; Tue, 06 Jun 2017 23:20:31 -0400 Received: from ozlabs.org ([103.22.144.67]:53967) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIRWH-0002SQ-5A; Tue, 06 Jun 2017 23:20:29 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wjDMV6Fbdz9sDb; Wed, 7 Jun 2017 13:20:22 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1496805622; bh=LBwHAisiWm8VxK6BtN559/AuVsQAxW2TsmCKyek5QWg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CHtKEk9/H15UxsQmfFBGUY5y+46JpOPWJEzT8Tw99wiUeJV8L7/l412M1DOxKgh0Z Val83jf7D+z8LB7tHBCFO7bUFEtkkNoY6Ad18vMPWtzKDadJnrAoNX0g+WcOZ019e7 lcBJcZfXKQ/lAPhbLQEXuZlXc70x5Z/6PH3bDDZ8= From: David Gibson To: mdroth@linux.vnet.ibm.com Date: Wed, 7 Jun 2017 13:20:15 +1000 Message-Id: <20170607032018.19588-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170607032018.19588-1-david@gibson.dropbear.id.au> References: <20170607032018.19588-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PATCHv2 4/7] spapr: Clean up handling of DR-indicator 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: sursingh@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, bharata@linux.vnet.ibm.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" There are 3 types of "indicator" associated with hotplug in the PAPR spec the "allocation state", "isolation state" and "DR-indicator". The first two are intimately tied to the various state transitions associated with hotplug. The DR-indicator, however, is different and simpler. It's basically just a guest controlled variable which can be used by the guest to flag state or problems associated with a device. The idea is that the hypervisor can use it to present information back on management consoles (on some machines with PowerVM it may even control physical LEDs on the machine case associated with the relevant device). For that reason, there's only ever likely to be a single update implementation so the set_indicator_state method isn't useful. Replace it with a direct function call. While we're there, make some small associated cleanups: * PAPR doesn't use the term "indicator state", just "DR-indicator" and the allocation state and isolation state are also considered "indicators". Rename things to be less confusing * Fold set_indicator_state() and rtas_set_indicator_state() into a single rtas_set_dr_indicator() function. Signed-off-by: David Gibson Acked-by: Michael Roth Reviewed-by: Michael Roth --- hw/ppc/spapr_drc.c | 25 ++++++++----------------- hw/ppc/trace-events | 2 +- include/hw/ppc/spapr_drc.h | 16 ++++++++-------- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index f0cff0b..19e2c0d 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -116,14 +116,6 @@ static uint32_t set_isolation_state(sPAPRDRConnector *= drc, return RTAS_OUT_SUCCESS; } =20 -static uint32_t set_indicator_state(sPAPRDRConnector *drc, - sPAPRDRIndicatorState state) -{ - trace_spapr_drc_set_indicator_state(spapr_drc_index(drc), state); - drc->indicator_state =3D state; - return RTAS_OUT_SUCCESS; -} - static uint32_t set_allocation_state(sPAPRDRConnector *drc, sPAPRDRAllocationState state) { @@ -321,7 +313,7 @@ static void attach(sPAPRDRConnector *drc, DeviceState *= d, void *fdt, if (spapr_drc_type(drc) =3D=3D SPAPR_DR_CONNECTOR_TYPE_PCI) { drc->isolation_state =3D SPAPR_DR_ISOLATION_STATE_UNISOLATED; } - drc->indicator_state =3D SPAPR_DR_INDICATOR_STATE_ACTIVE; + drc->dr_indicator =3D SPAPR_DR_INDICATOR_ACTIVE; =20 drc->dev =3D d; drc->fdt =3D fdt; @@ -394,7 +386,7 @@ static void detach(sPAPRDRConnector *drc, DeviceState *= d, Error **errp) } } =20 - drc->indicator_state =3D SPAPR_DR_INDICATOR_STATE_INACTIVE; + drc->dr_indicator =3D SPAPR_DR_INDICATOR_INACTIVE; =20 /* Calling release callbacks based on spapr_drc_type(drc). */ switch (spapr_drc_type(drc)) { @@ -507,7 +499,7 @@ static const VMStateDescription vmstate_spapr_drc =3D { .fields =3D (VMStateField []) { VMSTATE_UINT32(isolation_state, sPAPRDRConnector), VMSTATE_UINT32(allocation_state, sPAPRDRConnector), - VMSTATE_UINT32(indicator_state, sPAPRDRConnector), + VMSTATE_UINT32(dr_indicator, sPAPRDRConnector), VMSTATE_BOOL(configured, sPAPRDRConnector), VMSTATE_BOOL(awaiting_release, sPAPRDRConnector), VMSTATE_BOOL(awaiting_allocation, sPAPRDRConnector), @@ -647,7 +639,6 @@ static void spapr_dr_connector_class_init(ObjectClass *= k, void *data) dk->realize =3D realize; dk->unrealize =3D unrealize; drck->set_isolation_state =3D set_isolation_state; - drck->set_indicator_state =3D set_indicator_state; drck->set_allocation_state =3D set_allocation_state; drck->get_name =3D get_name; drck->attach =3D attach; @@ -929,17 +920,17 @@ static uint32_t rtas_set_allocation_state(uint32_t id= x, uint32_t state) return drck->set_allocation_state(drc, state); } =20 -static uint32_t rtas_set_indicator_state(uint32_t idx, uint32_t state) +static uint32_t rtas_set_dr_indicator(uint32_t idx, uint32_t state) { sPAPRDRConnector *drc =3D spapr_drc_by_index(idx); - sPAPRDRConnectorClass *drck; =20 if (!drc) { return RTAS_OUT_PARAM_ERROR; } =20 - drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - return drck->set_indicator_state(drc, state); + trace_spapr_drc_set_dr_indicator(idx, state); + drc->dr_indicator =3D state; + return RTAS_OUT_SUCCESS; } =20 static void rtas_set_indicator(PowerPCCPU *cpu, sPAPRMachineState *spapr, @@ -964,7 +955,7 @@ static void rtas_set_indicator(PowerPCCPU *cpu, sPAPRMa= chineState *spapr, ret =3D rtas_set_isolation_state(idx, state); break; case RTAS_SENSOR_TYPE_DR: - ret =3D rtas_set_indicator_state(idx, state); + ret =3D rtas_set_dr_indicator(idx, state); break; case RTAS_SENSOR_TYPE_ALLOCATION_STATE: ret =3D rtas_set_allocation_state(idx, state); diff --git a/hw/ppc/trace-events b/hw/ppc/trace-events index 581fa85..3e8e3cf 100644 --- a/hw/ppc/trace-events +++ b/hw/ppc/trace-events @@ -39,7 +39,7 @@ spapr_iommu_ddw_reset(uint64_t buid, uint32_t cfgaddr) "b= uid=3D%"PRIx64" addr=3D%"PR spapr_drc_set_isolation_state(uint32_t index, int state) "drc: 0x%"PRIx32"= , state: %"PRIx32 spapr_drc_set_isolation_state_finalizing(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_set_isolation_state_deferring(uint32_t index) "drc: 0x%"PRIx32 -spapr_drc_set_indicator_state(uint32_t index, int state) "drc: 0x%"PRIx32"= , state: 0x%x" +spapr_drc_set_dr_indicator(uint32_t index, int state) "drc: 0x%"PRIx32", s= tate: 0x%x" spapr_drc_set_allocation_state(uint32_t index, int state) "drc: 0x%"PRIx32= ", state: 0x%x" spapr_drc_set_allocation_state_finalizing(uint32_t index) "drc: 0x%"PRIx32 spapr_drc_set_configured(uint32_t index) "drc: 0x%"PRIx32 diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index f892b94..70db573 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -125,7 +125,7 @@ typedef enum { } sPAPRDRAllocationState; =20 /* - * LED/visual indicator state + * DR-indicator (LED/visual indicator) * * set via set-indicator RTAS calls * as documented by PAPR+ 2.7 13.5.3.4, Table 177, @@ -137,10 +137,10 @@ typedef enum { * action: (currently unused) */ typedef enum { - SPAPR_DR_INDICATOR_STATE_INACTIVE =3D 0, - SPAPR_DR_INDICATOR_STATE_ACTIVE =3D 1, - SPAPR_DR_INDICATOR_STATE_IDENTIFY =3D 2, - SPAPR_DR_INDICATOR_STATE_ACTION =3D 3, + SPAPR_DR_INDICATOR_INACTIVE =3D 0, + SPAPR_DR_INDICATOR_ACTIVE =3D 1, + SPAPR_DR_INDICATOR_IDENTIFY =3D 2, + SPAPR_DR_INDICATOR_ACTION =3D 3, } sPAPRDRIndicatorState; =20 /* @@ -186,10 +186,12 @@ typedef struct sPAPRDRConnector { Object *owner; const char *name; =20 + /* DR-indicator */ + uint32_t dr_indicator; + /* sensor/indicator states */ uint32_t isolation_state; uint32_t allocation_state; - uint32_t indicator_state; =20 /* configure-connector state */ void *fdt; @@ -219,8 +221,6 @@ typedef struct sPAPRDRConnectorClass { /* accessors for guest-visible (generally via RTAS) DR state */ uint32_t (*set_isolation_state)(sPAPRDRConnector *drc, sPAPRDRIsolationState state); - uint32_t (*set_indicator_state)(sPAPRDRConnector *drc, - sPAPRDRIndicatorState state); uint32_t (*set_allocation_state)(sPAPRDRConnector *drc, sPAPRDRAllocationState state); const char *(*get_name)(sPAPRDRConnector *drc); --=20 2.9.4 From nobody Mon Feb 9 02:48:38 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496806159752142.9269543856459; Tue, 6 Jun 2017 20:29:19 -0700 (PDT) Received: from localhost ([::1]:41064 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIReo-00032P-Dl for importer@patchew.org; Tue, 06 Jun 2017 23:29:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38058) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIRWK-0003b4-Ob for qemu-devel@nongnu.org; Tue, 06 Jun 2017 23:20:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIRWI-0002U3-Cg for qemu-devel@nongnu.org; Tue, 06 Jun 2017 23:20:32 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:36201) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIRWH-0002SW-N3; Tue, 06 Jun 2017 23:20:30 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wjDMV71n7z9sNP; Wed, 7 Jun 2017 13:20:22 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1496805622; bh=3k6603FmX2Hqy3Vo8dHd0ZZyygSf6UxPBgOqrRpHKVA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D1vbufK2ngcrKWSYOhXvPk/aoWvXAo1mhg/T9iRrifJACqUoS+lbvm6MVeVTfmyU5 NaEpUACRXYkkYqIvNQk6UCDxdKP4oCS6RYEYZVaMj2krw3fX+v9gbORTkUx+mvkGJX yJ5Fg6bNerH2clWP+6GU3br9nhgxBCd2JvIKsjPA= From: David Gibson To: mdroth@linux.vnet.ibm.com Date: Wed, 7 Jun 2017 13:20:16 +1000 Message-Id: <20170607032018.19588-6-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170607032018.19588-1-david@gibson.dropbear.id.au> References: <20170607032018.19588-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PATCHv2 5/7] spapr: Change DRC attach & detach methods to functions 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: sursingh@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, bharata@linux.vnet.ibm.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" DRC objects have attach & detach methods, but there's only one implementation. Although there are some differences in its behaviour for different DRC types, the overall structure is the same, so while we might want different method implementations for some parts, we're unlikely to want them for the top-level functions. So, replace them with direct function calls. Signed-off-by: David Gibson Acked-by: Michael Roth Reviewed-by: Michael Roth --- hw/ppc/spapr.c | 19 ++++++------------- hw/ppc/spapr_drc.c | 18 ++++++------------ hw/ppc/spapr_pci.c | 9 +++------ include/hw/ppc/spapr_drc.h | 7 ++++--- 4 files changed, 19 insertions(+), 34 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index b2311dc..e340ff3 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2523,7 +2523,6 @@ static void spapr_add_lmbs(DeviceState *dev, uint64_t= addr_start, uint64_t size, Error **errp) { sPAPRDRConnector *drc; - sPAPRDRConnectorClass *drck; uint32_t nr_lmbs =3D size/SPAPR_MEMORY_BLOCK_SIZE; int i, fdt_offset, fdt_size; void *fdt; @@ -2538,10 +2537,10 @@ static void spapr_add_lmbs(DeviceState *dev, uint64= _t addr_start, uint64_t size, fdt_offset =3D spapr_populate_memory_node(fdt, node, addr, SPAPR_MEMORY_BLOCK_SIZE); =20 - drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - drck->attach(drc, dev, fdt, fdt_offset, !dev->hotplugged, errp); + spapr_drc_attach(drc, dev, fdt, fdt_offset, !dev->hotplugged, errp= ); addr +=3D SPAPR_MEMORY_BLOCK_SIZE; if (!dev->hotplugged) { + sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(d= rc); /* guests expect coldplugged LMBs to be pre-allocated */ drck->set_allocation_state(drc, SPAPR_DR_ALLOCATION_STATE_USAB= LE); drck->set_isolation_state(drc, SPAPR_DR_ISOLATION_STATE_UNISOL= ATED); @@ -2554,7 +2553,6 @@ static void spapr_add_lmbs(DeviceState *dev, uint64_t= addr_start, uint64_t size, if (dedicated_hp_event_source) { drc =3D spapr_drc_by_id(TYPE_SPAPR_DRC_LMB, addr_start / SPAPR_MEMORY_BLOCK_SIZE); - drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); spapr_hotplug_req_add_by_count_indexed(SPAPR_DR_CONNECTOR_TYPE= _LMB, nr_lmbs, spapr_drc_index(drc)); @@ -2742,7 +2740,6 @@ static void spapr_memory_unplug_request(HotplugHandle= r *hotplug_dev, uint64_t addr_start, addr; int i; sPAPRDRConnector *drc; - sPAPRDRConnectorClass *drck; sPAPRDIMMState *ds; =20 addr_start =3D object_property_get_int(OBJECT(dimm), PC_DIMM_ADDR_PROP, @@ -2762,14 +2759,12 @@ static void spapr_memory_unplug_request(HotplugHand= ler *hotplug_dev, addr / SPAPR_MEMORY_BLOCK_SIZE); g_assert(drc); =20 - drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - drck->detach(drc, dev, errp); + spapr_drc_detach(drc, dev, errp); addr +=3D SPAPR_MEMORY_BLOCK_SIZE; } =20 drc =3D spapr_drc_by_id(TYPE_SPAPR_DRC_LMB, addr_start / SPAPR_MEMORY_BLOCK_SIZE); - drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); spapr_hotplug_req_remove_by_count_indexed(SPAPR_DR_CONNECTOR_TYPE_LMB, nr_lmbs, spapr_drc_index(drc= )); out: @@ -2824,7 +2819,6 @@ void spapr_core_unplug_request(HotplugHandler *hotplu= g_dev, DeviceState *dev, { int index; sPAPRDRConnector *drc; - sPAPRDRConnectorClass *drck; Error *local_err =3D NULL; CPUCore *cc =3D CPU_CORE(dev); int smt =3D kvmppc_smt_threads(); @@ -2842,8 +2836,7 @@ void spapr_core_unplug_request(HotplugHandler *hotplu= g_dev, DeviceState *dev, drc =3D spapr_drc_by_id(TYPE_SPAPR_DRC_CPU, index * smt); g_assert(drc); =20 - drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - drck->detach(drc, dev, &local_err); + spapr_drc_detach(drc, dev, &local_err); if (local_err) { error_propagate(errp, local_err); return; @@ -2887,8 +2880,8 @@ static void spapr_core_plug(HotplugHandler *hotplug_d= ev, DeviceState *dev, } =20 if (drc) { - sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - drck->attach(drc, dev, fdt, fdt_offset, !dev->hotplugged, &local_e= rr); + spapr_drc_attach(drc, dev, fdt, fdt_offset, !dev->hotplugged, + &local_err); if (local_err) { g_free(fdt); error_propagate(errp, local_err); diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 19e2c0d..82c0b94 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -49,8 +49,6 @@ uint32_t spapr_drc_index(sPAPRDRConnector *drc) static uint32_t set_isolation_state(sPAPRDRConnector *drc, sPAPRDRIsolationState state) { - sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - trace_spapr_drc_set_isolation_state(spapr_drc_index(drc), state); =20 /* if the guest is configuring a device attached to this DRC, we @@ -105,7 +103,7 @@ static uint32_t set_isolation_state(sPAPRDRConnector *d= rc, uint32_t drc_index =3D spapr_drc_index(drc); if (drc->configured) { trace_spapr_drc_set_isolation_state_finalizing(drc_index); - drck->detach(drc, DEVICE(drc->dev), NULL); + spapr_drc_detach(drc, DEVICE(drc->dev), NULL); } else { trace_spapr_drc_set_isolation_state_deferring(drc_index); } @@ -119,8 +117,6 @@ static uint32_t set_isolation_state(sPAPRDRConnector *d= rc, static uint32_t set_allocation_state(sPAPRDRConnector *drc, sPAPRDRAllocationState state) { - sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - trace_spapr_drc_set_allocation_state(spapr_drc_index(drc), state); =20 if (state =3D=3D SPAPR_DR_ALLOCATION_STATE_USABLE) { @@ -151,7 +147,7 @@ static uint32_t set_allocation_state(sPAPRDRConnector *= drc, drc->allocation_state =3D=3D SPAPR_DR_ALLOCATION_STATE_UNUSABL= E) { uint32_t drc_index =3D spapr_drc_index(drc); trace_spapr_drc_set_allocation_state_finalizing(drc_index); - drck->detach(drc, DEVICE(drc->dev), NULL); + spapr_drc_detach(drc, DEVICE(drc->dev), NULL); } else if (drc->allocation_state =3D=3D SPAPR_DR_ALLOCATION_STATE_= USABLE) { drc->awaiting_allocation =3D false; } @@ -289,8 +285,8 @@ static void prop_get_fdt(Object *obj, Visitor *v, const= char *name, } while (fdt_depth !=3D 0); } =20 -static void attach(sPAPRDRConnector *drc, DeviceState *d, void *fdt, - int fdt_start_offset, bool coldplug, Error **errp) +void spapr_drc_attach(sPAPRDRConnector *drc, DeviceState *d, void *fdt, + int fdt_start_offset, bool coldplug, Error **errp) { trace_spapr_drc_attach(spapr_drc_index(drc)); =20 @@ -341,7 +337,7 @@ static void attach(sPAPRDRConnector *drc, DeviceState *= d, void *fdt, NULL, 0, NULL); } =20 -static void detach(sPAPRDRConnector *drc, DeviceState *d, Error **errp) +void spapr_drc_detach(sPAPRDRConnector *drc, DeviceState *d, Error **errp) { trace_spapr_drc_detach(spapr_drc_index(drc)); =20 @@ -444,7 +440,7 @@ static void reset(DeviceState *d) * force removal if we are */ if (drc->awaiting_release) { - drck->detach(drc, DEVICE(drc->dev), NULL); + spapr_drc_detach(drc, DEVICE(drc->dev), NULL); } =20 /* non-PCI devices may be awaiting a transition to UNUSABLE */ @@ -641,8 +637,6 @@ static void spapr_dr_connector_class_init(ObjectClass *= k, void *data) drck->set_isolation_state =3D set_isolation_state; drck->set_allocation_state =3D set_allocation_state; drck->get_name =3D get_name; - drck->attach =3D attach; - drck->detach =3D detach; drck->release_pending =3D release_pending; drck->set_signalled =3D set_signalled; /* diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 5cba8f9..56cb4b8 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1349,7 +1349,6 @@ static void spapr_phb_add_pci_device(sPAPRDRConnector= *drc, PCIDevice *pdev, Error **errp) { - sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); DeviceState *dev =3D DEVICE(pdev); void *fdt =3D NULL; int fdt_start_offset =3D 0, fdt_size; @@ -1361,8 +1360,8 @@ static void spapr_phb_add_pci_device(sPAPRDRConnector= *drc, goto out; } =20 - drck->attach(drc, DEVICE(pdev), - fdt, fdt_start_offset, !dev->hotplugged, errp); + spapr_drc_attach(drc, DEVICE(pdev), + fdt, fdt_start_offset, !dev->hotplugged, errp); out: if (*errp) { g_free(fdt); @@ -1391,9 +1390,7 @@ static void spapr_phb_remove_pci_device(sPAPRDRConnec= tor *drc, PCIDevice *pdev, Error **errp) { - sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - - drck->detach(drc, DEVICE(pdev), errp); + spapr_drc_detach(drc, DEVICE(pdev), errp); } =20 static sPAPRDRConnector *spapr_phb_get_pci_func_drc(sPAPRPHBState *phb, diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index 70db573..4f82001 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -226,9 +226,6 @@ typedef struct sPAPRDRConnectorClass { const char *(*get_name)(sPAPRDRConnector *drc); =20 /* QEMU interfaces for managing hotplug operations */ - void (*attach)(sPAPRDRConnector *drc, DeviceState *d, void *fdt, - int fdt_start_offset, bool coldplug, Error **errp); - void (*detach)(sPAPRDRConnector *drc, DeviceState *d, Error **errp); bool (*release_pending)(sPAPRDRConnector *drc); void (*set_signalled)(sPAPRDRConnector *drc); } sPAPRDRConnectorClass; @@ -243,4 +240,8 @@ sPAPRDRConnector *spapr_drc_by_id(const char *type, uin= t32_t id); int spapr_drc_populate_dt(void *fdt, int fdt_offset, Object *owner, uint32_t drc_type_mask); =20 +void spapr_drc_attach(sPAPRDRConnector *drc, DeviceState *d, void *fdt, + int fdt_start_offset, bool coldplug, Error **errp); +void spapr_drc_detach(sPAPRDRConnector *drc, DeviceState *d, Error **errp); + #endif /* HW_SPAPR_DRC_H */ --=20 2.9.4 From nobody Mon Feb 9 02:48:38 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496806008611168.91002399586785; Tue, 6 Jun 2017 20:26:48 -0700 (PDT) Received: from localhost ([::1]:41054 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIRcN-0000n9-8m for importer@patchew.org; Tue, 06 Jun 2017 23:26:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37994) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIRWI-0003Zw-PJ for qemu-devel@nongnu.org; Tue, 06 Jun 2017 23:20:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIRWH-0002TR-Jt for qemu-devel@nongnu.org; Tue, 06 Jun 2017 23:20:30 -0400 Received: from ozlabs.org ([103.22.144.67]:36313) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIRWH-0002SS-8m; Tue, 06 Jun 2017 23:20:29 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wjDMW0W5Mz9sNR; Wed, 7 Jun 2017 13:20:22 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1496805623; bh=J8CawP/3DngtB3DbyVe8rkLu8QRkzIxHZWaI4iBKY60=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XxDP9EGv+eNSpBcRZkdfzzS5GfJzGDXa1EVM/q9c8m2YxO2yUge+ENb8wSIAePi2k Oavip+C3h9wYwHIGoO38CRUklvLbWls8qwuteHYpFa5nbKy9wcOvbdwKdESW2wo10C MKG+XgHWMHBbcX9LfRz1T9R2Ksd1oTvF5UTNmB4Y= From: David Gibson To: mdroth@linux.vnet.ibm.com Date: Wed, 7 Jun 2017 13:20:17 +1000 Message-Id: <20170607032018.19588-7-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170607032018.19588-1-david@gibson.dropbear.id.au> References: <20170607032018.19588-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PATCHv2 6/7] spapr: Fold spapr_phb_{add, remove}_pci_device() into their only callers 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: sursingh@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, bharata@linux.vnet.ibm.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Both functions are fairly short, and so are their callers. There's no particular logical distinction between them, so fold them together. Signed-off-by: David Gibson Acked-by: Michael Roth Reviewed-by: Michael Roth --- hw/ppc/spapr_pci.c | 63 ++++++++++++++++++++------------------------------= ---- 1 file changed, 23 insertions(+), 40 deletions(-) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 56cb4b8..0b447f2 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1344,30 +1344,6 @@ static int spapr_create_pci_child_dt(sPAPRPHBState *= phb, PCIDevice *dev, return offset; } =20 -static void spapr_phb_add_pci_device(sPAPRDRConnector *drc, - sPAPRPHBState *phb, - PCIDevice *pdev, - Error **errp) -{ - DeviceState *dev =3D DEVICE(pdev); - void *fdt =3D NULL; - int fdt_start_offset =3D 0, fdt_size; - - fdt =3D create_device_tree(&fdt_size); - fdt_start_offset =3D spapr_create_pci_child_dt(phb, pdev, fdt, 0); - if (!fdt_start_offset) { - error_setg(errp, "Failed to create pci child device tree node"); - goto out; - } - - spapr_drc_attach(drc, DEVICE(pdev), - fdt, fdt_start_offset, !dev->hotplugged, errp); -out: - if (*errp) { - g_free(fdt); - } -} - /* Callback to be called during DRC release. */ void spapr_phb_remove_pci_device_cb(DeviceState *dev) { @@ -1385,14 +1361,6 @@ void spapr_phb_remove_pci_device_cb(DeviceState *dev) object_unparent(OBJECT(dev)); } =20 -static void spapr_phb_remove_pci_device(sPAPRDRConnector *drc, - sPAPRPHBState *phb, - PCIDevice *pdev, - Error **errp) -{ - spapr_drc_detach(drc, DEVICE(pdev), errp); -} - static sPAPRDRConnector *spapr_phb_get_pci_func_drc(sPAPRPHBState *phb, uint32_t busnr, int32_t devfn) @@ -1429,6 +1397,8 @@ static void spapr_phb_hot_plug_child(HotplugHandler *= plug_handler, Error *local_err =3D NULL; PCIBus *bus =3D PCI_BUS(qdev_get_parent_bus(DEVICE(pdev))); uint32_t slotnr =3D PCI_SLOT(pdev->devfn); + void *fdt =3D NULL; + int fdt_start_offset, fdt_size; =20 /* if DR is disabled we don't need to do anything in the case of * hotplug or coldplug callbacks @@ -1438,10 +1408,10 @@ static void spapr_phb_hot_plug_child(HotplugHandler= *plug_handler, * we need to let them know it's not enabled */ if (plugged_dev->hotplugged) { - error_setg(errp, QERR_BUS_NO_HOTPLUG, + error_setg(&local_err, QERR_BUS_NO_HOTPLUG, object_get_typename(OBJECT(phb))); } - return; + goto out; } =20 g_assert(drc); @@ -1452,16 +1422,23 @@ static void spapr_phb_hot_plug_child(HotplugHandler= *plug_handler, */ if (plugged_dev->hotplugged && bus->devices[PCI_DEVFN(slotnr, 0)] && PCI_FUNC(pdev->devfn) !=3D 0) { - error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s," + error_setg(&local_err, "PCI: slot %d function 0 already ocuppied b= y %s," " additional functions can no longer be exposed to gues= t.", slotnr, bus->devices[PCI_DEVFN(slotnr, 0)]->name); - return; + goto out; + } + + fdt =3D create_device_tree(&fdt_size); + fdt_start_offset =3D spapr_create_pci_child_dt(phb, pdev, fdt, 0); + if (!fdt_start_offset) { + error_setg(&local_err, "Failed to create pci child device tree nod= e"); + goto out; } =20 - spapr_phb_add_pci_device(drc, phb, pdev, &local_err); + spapr_drc_attach(drc, DEVICE(pdev), fdt, fdt_start_offset, + !plugged_dev->hotplugged, &local_err); if (local_err) { - error_propagate(errp, local_err); - return; + goto out; } =20 /* If this is function 0, signal hotplug for all the device functions. @@ -1485,6 +1462,12 @@ static void spapr_phb_hot_plug_child(HotplugHandler = *plug_handler, } } } + +out: + if (local_err) { + error_propagate(errp, local_err); + g_free(fdt); + } } =20 static void spapr_phb_hot_unplug_child(HotplugHandler *plug_handler, @@ -1531,7 +1514,7 @@ static void spapr_phb_hot_unplug_child(HotplugHandler= *plug_handler, } } =20 - spapr_phb_remove_pci_device(drc, phb, pdev, &local_err); + spapr_drc_detach(drc, DEVICE(pdev), &local_err); if (local_err) { error_propagate(errp, local_err); return; --=20 2.9.4 From nobody Mon Feb 9 02:48:38 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 14968062222261015.66060439222; Tue, 6 Jun 2017 20:30:22 -0700 (PDT) Received: from localhost ([::1]:41073 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIRfo-0003eo-Fi for importer@patchew.org; Tue, 06 Jun 2017 23:30:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38051) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIRWK-0003at-K4 for qemu-devel@nongnu.org; Tue, 06 Jun 2017 23:20:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIRWI-0002UB-Gd for qemu-devel@nongnu.org; Tue, 06 Jun 2017 23:20:32 -0400 Received: from ozlabs.org ([103.22.144.67]:48811) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIRWH-0002Sv-Ti; Tue, 06 Jun 2017 23:20:30 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wjDMW29k7z9sNH; Wed, 7 Jun 2017 13:20:22 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1496805623; bh=NWDC4O3IIRMw85jaIr7GNF7ABQaN2wiyxTDlpprqaI0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qRgKqRTpjLj/llBXH3EE4rDfEkpEe0eUe+itH0ll1MFeEVLmTMfwB6i0gxwpRUGZG C7jJEfmet7t7n7KLANWP8jJ21OUyZ6yIvtOFs0PzthShOWVyD9lWR/M5UJ8+FWQEWe nVbjeYHwbJpWG1KA93inuOfuyWKZ2Nsk0KNuaYig= From: David Gibson To: mdroth@linux.vnet.ibm.com Date: Wed, 7 Jun 2017 13:20:18 +1000 Message-Id: <20170607032018.19588-8-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170607032018.19588-1-david@gibson.dropbear.id.au> References: <20170607032018.19588-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PATCHv2 7/7] spapr: Rework DRC name handling 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: sursingh@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, bharata@linux.vnet.ibm.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" DRC objects have a get_name method which returns the DRC name generated when the DRC is created. Replace that with a fixed spapr_drc_name() function which generates the name on the fly from other information. This means: * We get rid of a method with only one implementation, and only local callers * We don't have to carry the name string around for the lifetime of the DRC * We use information added to the class structure to generate the name in standard format, so we don't need an explicit switch on drc type any more We also eliminate the 'name' property; it's basically useless since the only information in it can easily be deduced from other things. Signed-off-by: David Gibson Acked-by: Michael Roth Reviewed-by: Michael Roth --- hw/ppc/spapr_drc.c | 80 +++++++++++++++++-------------------------= ---- include/hw/ppc/spapr_drc.h | 3 +- 2 files changed, 30 insertions(+), 53 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 82c0b94..15ef67d 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -155,9 +155,32 @@ static uint32_t set_allocation_state(sPAPRDRConnector = *drc, return RTAS_OUT_SUCCESS; } =20 -static const char *get_name(sPAPRDRConnector *drc) +static const char *spapr_drc_name(sPAPRDRConnector *drc) { - return drc->name; + sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); + + /* human-readable name for a DRC to encode into the DT + * description. this is mainly only used within a guest in place + * of the unique DRC index. + * + * in the case of VIO/PCI devices, it corresponds to a "location + * code" that maps a logical device/function (DRC index) to a + * physical (or virtual in the case of VIO) location in the system + * by chaining together the "location label" for each + * encapsulating component. + * + * since this is more to do with diagnosing physical hardware + * issues than guest compatibility, we choose location codes/DRC + * names that adhere to the documented format, but avoid encoding + * the entire topology information into the label/code, instead + * just using the location codes based on the labels for the + * endpoints (VIO/PCI adaptor connectors), which is basically just + * "C" followed by an integer ID. + * + * DRC names as documented by PAPR+ v2.7, 13.5.2.4 + * location codes as documented by PAPR+ v2.7, 12.3.1.5 + */ + return g_strdup_printf("%s%d", drck->drc_name_prefix, drc->id); } =20 /* has the guest been notified of device attachment? */ @@ -202,13 +225,6 @@ static void prop_get_index(Object *obj, Visitor *v, co= nst char *name, visit_type_uint32(v, name, &value, errp); } =20 -static char *prop_get_name(Object *obj, Error **errp) -{ - sPAPRDRConnector *drc =3D SPAPR_DR_CONNECTOR(obj); - sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - return g_strdup(drck->get_name(drc)); -} - static void prop_get_fdt(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { @@ -567,45 +583,6 @@ sPAPRDRConnector *spapr_dr_connector_new(Object *owner= , const char *type, object_property_set_bool(OBJECT(drc), true, "realized", NULL); g_free(prop_name); =20 - /* human-readable name for a DRC to encode into the DT - * description. this is mainly only used within a guest in place - * of the unique DRC index. - * - * in the case of VIO/PCI devices, it corresponds to a - * "location code" that maps a logical device/function (DRC index) - * to a physical (or virtual in the case of VIO) location in the - * system by chaining together the "location label" for each - * encapsulating component. - * - * since this is more to do with diagnosing physical hardware - * issues than guest compatibility, we choose location codes/DRC - * names that adhere to the documented format, but avoid encoding - * the entire topology information into the label/code, instead - * just using the location codes based on the labels for the - * endpoints (VIO/PCI adaptor connectors), which is basically - * just "C" followed by an integer ID. - * - * DRC names as documented by PAPR+ v2.7, 13.5.2.4 - * location codes as documented by PAPR+ v2.7, 12.3.1.5 - */ - switch (spapr_drc_type(drc)) { - case SPAPR_DR_CONNECTOR_TYPE_CPU: - drc->name =3D g_strdup_printf("CPU %d", id); - break; - case SPAPR_DR_CONNECTOR_TYPE_PHB: - drc->name =3D g_strdup_printf("PHB %d", id); - break; - case SPAPR_DR_CONNECTOR_TYPE_VIO: - case SPAPR_DR_CONNECTOR_TYPE_PCI: - drc->name =3D g_strdup_printf("C%d", id); - break; - case SPAPR_DR_CONNECTOR_TYPE_LMB: - drc->name =3D g_strdup_printf("LMB %d", id); - break; - default: - g_assert(false); - } - /* PCI slot always start in a USABLE state, and stay there */ if (spapr_drc_type(drc) =3D=3D SPAPR_DR_CONNECTOR_TYPE_PCI) { drc->allocation_state =3D SPAPR_DR_ALLOCATION_STATE_USABLE; @@ -621,7 +598,6 @@ static void spapr_dr_connector_instance_init(Object *ob= j) object_property_add_uint32_ptr(obj, "id", &drc->id, NULL); object_property_add(obj, "index", "uint32", prop_get_index, NULL, NULL, NULL, NULL); - object_property_add_str(obj, "name", prop_get_name, NULL, NULL); object_property_add(obj, "fdt", "struct", prop_get_fdt, NULL, NULL, NULL, NULL); } @@ -636,7 +612,6 @@ static void spapr_dr_connector_class_init(ObjectClass *= k, void *data) dk->unrealize =3D unrealize; drck->set_isolation_state =3D set_isolation_state; drck->set_allocation_state =3D set_allocation_state; - drck->get_name =3D get_name; drck->release_pending =3D release_pending; drck->set_signalled =3D set_signalled; /* @@ -665,6 +640,7 @@ static void spapr_drc_cpu_class_init(ObjectClass *k, vo= id *data) =20 drck->typeshift =3D SPAPR_DR_CONNECTOR_TYPE_SHIFT_CPU; drck->typename =3D "CPU"; + drck->drc_name_prefix =3D "CPU "; } =20 static void spapr_drc_pci_class_init(ObjectClass *k, void *data) @@ -673,6 +649,7 @@ static void spapr_drc_pci_class_init(ObjectClass *k, vo= id *data) =20 drck->typeshift =3D SPAPR_DR_CONNECTOR_TYPE_SHIFT_PCI; drck->typename =3D "28"; + drck->drc_name_prefix =3D "C"; } =20 static void spapr_drc_lmb_class_init(ObjectClass *k, void *data) @@ -681,6 +658,7 @@ static void spapr_drc_lmb_class_init(ObjectClass *k, vo= id *data) =20 drck->typeshift =3D SPAPR_DR_CONNECTOR_TYPE_SHIFT_LMB; drck->typename =3D "MEM"; + drck->drc_name_prefix =3D "LMB "; } =20 static const TypeInfo spapr_dr_connector_info =3D { @@ -829,7 +807,7 @@ int spapr_drc_populate_dt(void *fdt, int fdt_offset, Ob= ject *owner, g_array_append_val(drc_power_domains, drc_power_domain); =20 /* ibm,drc-names */ - drc_names =3D g_string_append(drc_names, drck->get_name(drc)); + drc_names =3D g_string_append(drc_names, spapr_drc_name(drc)); drc_names =3D g_string_insert_len(drc_names, -1, "\0", 1); =20 /* ibm,drc-types */ diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index 4f82001..c487123 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -184,7 +184,6 @@ typedef struct sPAPRDRConnector { =20 uint32_t id; Object *owner; - const char *name; =20 /* DR-indicator */ uint32_t dr_indicator; @@ -215,6 +214,7 @@ typedef struct sPAPRDRConnectorClass { /*< public >*/ sPAPRDRConnectorTypeShift typeshift; const char *typename; /* used in device tree, PAPR 13.5.2.6 & C.6.1 */ + const char *drc_name_prefix; /* used other places in device tree */ =20 sPAPRDREntitySense (*dr_entity_sense)(sPAPRDRConnector *drc); =20 @@ -223,7 +223,6 @@ typedef struct sPAPRDRConnectorClass { sPAPRDRIsolationState state); uint32_t (*set_allocation_state)(sPAPRDRConnector *drc, sPAPRDRAllocationState state); - const char *(*get_name)(sPAPRDRConnector *drc); =20 /* QEMU interfaces for managing hotplug operations */ bool (*release_pending)(sPAPRDRConnector *drc); --=20 2.9.4