From nobody Tue Feb 10 14:32:19 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 1498819726743880.5395162860736; Fri, 30 Jun 2017 03:48:46 -0700 (PDT) Received: from localhost ([::1]:43646 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtTe-0001Mt-Ei for importer@patchew.org; Fri, 30 Jun 2017 06:48:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34395) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQtRk-0008T1-Pz for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQtRj-0007uN-05 for qemu-devel@nongnu.org; Fri, 30 Jun 2017 06:46:44 -0400 Received: from ozlabs.org ([103.22.144.67]:34287) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQtRi-0007sa-KA; Fri, 30 Jun 2017 06:46:42 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3wzY9n4wtBz9sRg; Fri, 30 Jun 2017 20:46:37 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1498819597; bh=p9BP9m7oiQx7AZbzn3H15TWvCVXnvk019uise7zLVKk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jLdUpW3E6kMPqOYAlRxOrQaQ4UPMvFTWtvvJEunmt9b1DzE5Am6w5YXV1DFtMHNJq M04YuYjLC5rPWcLg8wJwLMOs720JmCSo64WyPwZhrd+90egEuPKoFRWxOfhwNxmJY/ nsFX6M0rtaQbJWV6aE5ZPtJ68RIsnQkFXHDvpO0s= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 30 Jun 2017 20:46:31 +1000 Message-Id: <20170630104632.27942-21-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170630104632.27942-1-david@gibson.dropbear.id.au> References: <20170630104632.27942-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] [PULL 20/21] spapr: Clean up DRC set_allocation_state path 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: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, sursingh@redhat.com, mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-ppc@nongnu.org, sbobroff@redhat.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" The allocation-state indicator should only actually be implemented for "logical" DRCs, not physical ones. Factor a check for this, and also for valid indicator state values into rtas_set_allocation_state(). Because they don't exist for physical DRCs, there's no reason that we'd ever want more than one method implementation, so it can just be a plain function. In addition, the setting to USABLE and setting to UNUSABLE paths in set_allocation_state() don't actually have much in common. So, split the method separate functions for each parameter value (drc_set_usable() and drc_set_unusable()). Signed-off-by: David Gibson Reviewed-by: Greg Kurz Reviewed-by: Michael Roth --- hw/ppc/spapr_drc.c | 73 ++++++++++++++++++++++++++++--------------= ---- include/hw/ppc/spapr_drc.h | 2 -- 2 files changed, 45 insertions(+), 30 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 9a2511f..dbcd670 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -114,33 +114,42 @@ static uint32_t set_isolation_state(sPAPRDRConnector = *drc, return RTAS_OUT_SUCCESS; } =20 -static uint32_t set_allocation_state(sPAPRDRConnector *drc, - sPAPRDRAllocationState state) +static uint32_t drc_set_usable(sPAPRDRConnector *drc) { - trace_spapr_drc_set_allocation_state(spapr_drc_index(drc), state); - - if (state =3D=3D SPAPR_DR_ALLOCATION_STATE_USABLE) { - /* if there's no resource/device associated with the DRC, there's - * no way for us to put it in an allocation state consistent with - * being 'USABLE'. PAPR 2.7, 13.5.3.4 documents that this should - * result in an RTAS return code of -3 / "no such indicator" + /* if there's no resource/device associated with the DRC, there's + * no way for us to put it in an allocation state consistent with + * being 'USABLE'. PAPR 2.7, 13.5.3.4 documents that this should + * result in an RTAS return code of -3 / "no such indicator" + */ + if (!drc->dev) { + return RTAS_OUT_NO_SUCH_INDICATOR; + } + if (drc->awaiting_release && drc->awaiting_allocation) { + /* kernel is acknowledging a previous hotplug event + * while we are already removing it. + * it's safe to ignore awaiting_allocation here since we know the + * situation is predicated on the guest either already having done + * so (boot-time hotplug), or never being able to acquire in the + * first place (hotplug followed by immediate unplug). */ - if (!drc->dev) { - return RTAS_OUT_NO_SUCH_INDICATOR; - } + return RTAS_OUT_NO_SUCH_INDICATOR; } =20 - if (spapr_drc_type(drc) !=3D SPAPR_DR_CONNECTOR_TYPE_PCI) { - drc->allocation_state =3D state; - if (drc->awaiting_release && - 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); - 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; - } + drc->allocation_state =3D SPAPR_DR_ALLOCATION_STATE_USABLE; + drc->awaiting_allocation =3D false; + + return RTAS_OUT_SUCCESS; +} + +static uint32_t drc_set_unusable(sPAPRDRConnector *drc) +{ + drc->allocation_state =3D SPAPR_DR_ALLOCATION_STATE_UNUSABLE; + if (drc->awaiting_release) { + uint32_t drc_index =3D spapr_drc_index(drc); + trace_spapr_drc_set_allocation_state_finalizing(drc_index); + spapr_drc_detach(drc, DEVICE(drc->dev), NULL); } + return RTAS_OUT_SUCCESS; } =20 @@ -547,7 +556,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_allocation_state =3D set_allocation_state; drck->release_pending =3D release_pending; /* * Reason: it crashes FIXME find and document the real reason @@ -817,14 +825,23 @@ static uint32_t rtas_set_isolation_state(uint32_t idx= , uint32_t state) static uint32_t rtas_set_allocation_state(uint32_t idx, uint32_t state) { sPAPRDRConnector *drc =3D spapr_drc_by_index(idx); - sPAPRDRConnectorClass *drck; =20 - if (!drc) { - return RTAS_OUT_PARAM_ERROR; + if (!drc || !object_dynamic_cast(OBJECT(drc), TYPE_SPAPR_DRC_LOGICAL))= { + return RTAS_OUT_NO_SUCH_INDICATOR; } =20 - drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); - return drck->set_allocation_state(drc, state); + trace_spapr_drc_set_allocation_state(spapr_drc_index(drc), state); + + switch (state) { + case SPAPR_DR_ALLOCATION_STATE_USABLE: + return drc_set_usable(drc); + + case SPAPR_DR_ALLOCATION_STATE_UNUSABLE: + return drc_set_unusable(drc); + + default: + return RTAS_OUT_PARAM_ERROR; + } } =20 static uint32_t rtas_set_dr_indicator(uint32_t idx, uint32_t state) diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index 388e2a6..1674b66 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -219,8 +219,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_allocation_state)(sPAPRDRConnector *drc, - sPAPRDRAllocationState state); =20 /* QEMU interfaces for managing hotplug operations */ bool (*release_pending)(sPAPRDRConnector *drc); --=20 2.9.4