From nobody Wed Nov 5 17:41:35 2025 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 --- 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