From nobody Sat Oct 25 09:08:51 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.zohomail.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 1520309821524292.865130014681; Mon, 5 Mar 2018 20:17:01 -0800 (PST) Received: from localhost ([::1]:52846 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1et428-0006Nv-O4 for importer@patchew.org; Mon, 05 Mar 2018 23:17:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49568) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1et3o0-0001aG-Dd for qemu-devel@nongnu.org; Mon, 05 Mar 2018 23:02:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1et3nx-0004Vp-FH for qemu-devel@nongnu.org; Mon, 05 Mar 2018 23:02:24 -0500 Received: from ozlabs.org ([103.22.144.67]:33437) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1et3nx-0004UE-2g; Mon, 05 Mar 2018 23:02:21 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 3zwNQ80khDz9shY; Tue, 6 Mar 2018 15:02:04 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1520308928; bh=6uGurp3xIHOMSQD5ss7uXQINyAvzVjZ1TcRElB7gZzY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HNnFw0WBxZpZXsysJwLXaiRewwTQzD1A1gojGylPwHkJ5YmQUt6M+KpmisuhOMd0n 2IsGS2lEflOSb2qLq7WuxDCja0TYcAVTICin8urSCVFnxdSAcemJxLH5ppKehX+fc2 FijYrnh9UwynFAgk4Pb/Ux57v08mQLbKLm3QVx4A= From: David Gibson To: peter.maydell@linaro.org, groug@kaod.org Date: Tue, 6 Mar 2018 15:01:46 +1100 Message-Id: <20180306040154.3669-23-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180306040154.3669-1-david@gibson.dropbear.id.au> References: <20180306040154.3669-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 22/30] ppc/spapr-caps: Add support for custom spapr_capabilities 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: surajjs@au1.ibm.com, qemu-devel@nongnu.org, agraf@suse.de, qemu-ppc@nongnu.org, Suraj Jitindar Singh , 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" From: Suraj Jitindar Singh There are currently 2 implemented types of spapr-caps, boolean and tristate. However there may be a need for caps which don't fit either of these options. Add a custom capability type for which a list of custom valid strings can be specified and implement the get/set functions for these. Also add a field for help text to describe the available options. Signed-off-by: Suraj Jitindar Singh [dwg: Change "help" option to "?" matching qemu conventions] [dwg: Add ATTRIBUTE_UNUSED to avoid breaking bisect] Signed-off-by: David Gibson --- hw/ppc/spapr_caps.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 70 insertions(+) diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c index 99a4b71d19..3d8b796df9 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -32,6 +32,20 @@ =20 #include "hw/ppc/spapr.h" =20 +typedef struct sPAPRCapPossible { + int num; /* size of vals array below */ + const char *help; /* help text for vals */ + /* + * Note: + * - because of the way compatibility is determined vals MUST be order= ed + * such that later options are a superset of all preceding options. + * - the order of vals must be preserved, that is their index is impor= tant, + * however vals may be added to the end of the list so long as the a= bove + * point is observed + */ + const char *vals[]; +} sPAPRCapPossible; + typedef struct sPAPRCapabilityInfo { const char *name; const char *description; @@ -41,6 +55,8 @@ typedef struct sPAPRCapabilityInfo { ObjectPropertyAccessor *get; ObjectPropertyAccessor *set; const char *type; + /* Possible values if this is a custom string type */ + sPAPRCapPossible *possible; /* Make sure the virtual hardware can support this capability */ void (*apply)(sPAPRMachineState *spapr, uint8_t val, Error **errp); } sPAPRCapabilityInfo; @@ -133,6 +149,60 @@ out: g_free(val); } =20 +static void ATTRIBUTE_UNUSED spapr_cap_get_string(Object *obj, Visitor *v, + const char *name, + void *opaque, Error **er= rp) +{ + sPAPRCapabilityInfo *cap =3D opaque; + sPAPRMachineState *spapr =3D SPAPR_MACHINE(obj); + char *val =3D NULL; + uint8_t value =3D spapr_get_cap(spapr, cap->index); + + if (value >=3D cap->possible->num) { + error_setg(errp, "Invalid value (%d) for cap-%s", value, cap->name= ); + return; + } + + val =3D g_strdup(cap->possible->vals[value]); + + visit_type_str(v, name, &val, errp); + g_free(val); +} + +static void ATTRIBUTE_UNUSED spapr_cap_set_string(Object *obj, Visitor *v, + const char *name, + void *opaque, Error **er= rp) +{ + sPAPRCapabilityInfo *cap =3D opaque; + sPAPRMachineState *spapr =3D SPAPR_MACHINE(obj); + Error *local_err =3D NULL; + uint8_t i; + char *val; + + visit_type_str(v, name, &val, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + if (!strcmp(val, "?")) { + error_setg(errp, "%s", cap->possible->help); + goto out; + } + for (i =3D 0; i < cap->possible->num; i++) { + if (!strcasecmp(val, cap->possible->vals[i])) { + spapr->cmd_line_caps[cap->index] =3D true; + spapr->eff.caps[cap->index] =3D i; + goto out; + } + } + + error_setg(errp, "Invalid capability mode \"%s\" for cap-%s", val, + cap->name); +out: + g_free(val); +} + static void cap_htm_apply(sPAPRMachineState *spapr, uint8_t val, Error **e= rrp) { if (!val) { --=20 2.14.3