From nobody Mon Feb 9 20:12:27 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.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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519971880777508.12399767145155; Thu, 1 Mar 2018 22:24:40 -0800 (PST) Received: from localhost ([::1]:32874 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ere7O-0000fW-OE for importer@patchew.org; Fri, 02 Mar 2018 01:24:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38732) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erdnf-0000mL-Ot for qemu-devel@nongnu.org; Fri, 02 Mar 2018 01:04:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erdnc-00049V-Dk for qemu-devel@nongnu.org; Fri, 02 Mar 2018 01:04:11 -0500 Received: from ozlabs.org ([103.22.144.67]:33219) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erdnb-00044j-RJ; Fri, 02 Mar 2018 01:04:08 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 3zszJZ4s8Xz9sX4; Fri, 2 Mar 2018 17:03:57 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1519970638; bh=6uGurp3xIHOMSQD5ss7uXQINyAvzVjZ1TcRElB7gZzY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pVrIGBxCX5UVahLw2jjLI/XOj+5twMSPqJrIBDEb9R16kphqFSA7yQN0brMDVPGbM sabVVyNl5XC/SJkP99JOMlcWfp/9uGfQpbO+pGno/W2UQoBS1Wc7KigzRWmorMzFxx BMw3tdvZGBF07o9jEj3ghvVj/CflPTaWaD/tJ+AA= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 2 Mar 2018 17:03:45 +1100 Message-Id: <20180302060350.24330-20-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180302060350.24330-1-david@gibson.dropbear.id.au> References: <20180302060350.24330-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 19/24] 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, mark.cave-ayland@ilande.co.uk, qemu-devel@nongnu.org, groug@kaod.org, 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