Blame SOURCES/kvm-ppc-spapr-caps-Add-support-for-custom-spapr_capabili.patch

c7c90d
From d5704100a478118313ce89e8725c714f20deb094 Mon Sep 17 00:00:00 2001
c7c90d
From: Suraj Jitindar Singh <sursingh@redhat.com>
c7c90d
Date: Tue, 13 Mar 2018 05:21:32 +0100
c7c90d
Subject: [PATCH 10/17] ppc/spapr-caps: Add support for custom
c7c90d
 spapr_capabilities
c7c90d
c7c90d
RH-Author: Suraj Jitindar Singh <sursingh@redhat.com>
c7c90d
Message-id: <1520918499-27663-5-git-send-email-sursingh@redhat.com>
c7c90d
Patchwork-id: 79246
c7c90d
O-Subject: [RHEL7.5 qemu-kvm-rhev PATCH 04/11] ppc/spapr-caps: Add support for custom spapr_capabilities
c7c90d
Bugzilla: 1554957
c7c90d
RH-Acked-by: David Gibson <dgibson@redhat.com>
c7c90d
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
c7c90d
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
c7c90d
c7c90d
From: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
c7c90d
c7c90d
There are currently 2 implemented types of spapr-caps, boolean and
c7c90d
tristate. However there may be a need for caps which don't fit either of
c7c90d
these options. Add a custom capability type for which a list of custom
c7c90d
valid strings can be specified and implement the get/set functions for
c7c90d
these. Also add a field for help text to describe the available options.
c7c90d
c7c90d
Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
c7c90d
[dwg: Change "help" option to "?" matching qemu conventions]
c7c90d
[dwg: Add ATTRIBUTE_UNUSED to avoid breaking bisect]
c7c90d
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
c7c90d
c7c90d
(cherry picked from commit 87175d1bc5272fff5cffb05c410b39f839dfc948)
c7c90d
c7c90d
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1548919
c7c90d
c7c90d
Signed-off-by: Suraj Jitindar Singh <sursingh@redhat.com>
c7c90d
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
c7c90d
---
c7c90d
 hw/ppc/spapr_caps.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++
c7c90d
 1 file changed, 70 insertions(+)
c7c90d
c7c90d
diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c
c7c90d
index 99a4b71..3d8b796 100644
c7c90d
--- a/hw/ppc/spapr_caps.c
c7c90d
+++ b/hw/ppc/spapr_caps.c
c7c90d
@@ -32,6 +32,20 @@
c7c90d
 
c7c90d
 #include "hw/ppc/spapr.h"
c7c90d
 
c7c90d
+typedef struct sPAPRCapPossible {
c7c90d
+    int num;            /* size of vals array below */
c7c90d
+    const char *help;   /* help text for vals */
c7c90d
+    /*
c7c90d
+     * Note:
c7c90d
+     * - because of the way compatibility is determined vals MUST be ordered
c7c90d
+     *   such that later options are a superset of all preceding options.
c7c90d
+     * - the order of vals must be preserved, that is their index is important,
c7c90d
+     *   however vals may be added to the end of the list so long as the above
c7c90d
+     *   point is observed
c7c90d
+     */
c7c90d
+    const char *vals[];
c7c90d
+} sPAPRCapPossible;
c7c90d
+
c7c90d
 typedef struct sPAPRCapabilityInfo {
c7c90d
     const char *name;
c7c90d
     const char *description;
c7c90d
@@ -41,6 +55,8 @@ typedef struct sPAPRCapabilityInfo {
c7c90d
     ObjectPropertyAccessor *get;
c7c90d
     ObjectPropertyAccessor *set;
c7c90d
     const char *type;
c7c90d
+    /* Possible values if this is a custom string type */
c7c90d
+    sPAPRCapPossible *possible;
c7c90d
     /* Make sure the virtual hardware can support this capability */
c7c90d
     void (*apply)(sPAPRMachineState *spapr, uint8_t val, Error **errp);
c7c90d
 } sPAPRCapabilityInfo;
c7c90d
@@ -133,6 +149,60 @@ out:
c7c90d
     g_free(val);
c7c90d
 }
c7c90d
 
c7c90d
+static void ATTRIBUTE_UNUSED spapr_cap_get_string(Object *obj, Visitor *v,
c7c90d
+                                                  const char *name,
c7c90d
+                                                  void *opaque, Error **errp)
c7c90d
+{
c7c90d
+    sPAPRCapabilityInfo *cap = opaque;
c7c90d
+    sPAPRMachineState *spapr = SPAPR_MACHINE(obj);
c7c90d
+    char *val = NULL;
c7c90d
+    uint8_t value = spapr_get_cap(spapr, cap->index);
c7c90d
+
c7c90d
+    if (value >= cap->possible->num) {
c7c90d
+        error_setg(errp, "Invalid value (%d) for cap-%s", value, cap->name);
c7c90d
+        return;
c7c90d
+    }
c7c90d
+
c7c90d
+    val = g_strdup(cap->possible->vals[value]);
c7c90d
+
c7c90d
+    visit_type_str(v, name, &val, errp);
c7c90d
+    g_free(val);
c7c90d
+}
c7c90d
+
c7c90d
+static void ATTRIBUTE_UNUSED spapr_cap_set_string(Object *obj, Visitor *v,
c7c90d
+                                                  const char *name,
c7c90d
+                                                  void *opaque, Error **errp)
c7c90d
+{
c7c90d
+    sPAPRCapabilityInfo *cap = opaque;
c7c90d
+    sPAPRMachineState *spapr = SPAPR_MACHINE(obj);
c7c90d
+    Error *local_err = NULL;
c7c90d
+    uint8_t i;
c7c90d
+    char *val;
c7c90d
+
c7c90d
+    visit_type_str(v, name, &val, &local_err);
c7c90d
+    if (local_err) {
c7c90d
+        error_propagate(errp, local_err);
c7c90d
+        return;
c7c90d
+    }
c7c90d
+
c7c90d
+    if (!strcmp(val, "?")) {
c7c90d
+        error_setg(errp, "%s", cap->possible->help);
c7c90d
+        goto out;
c7c90d
+    }
c7c90d
+    for (i = 0; i < cap->possible->num; i++) {
c7c90d
+        if (!strcasecmp(val, cap->possible->vals[i])) {
c7c90d
+            spapr->cmd_line_caps[cap->index] = true;
c7c90d
+            spapr->eff.caps[cap->index] = i;
c7c90d
+            goto out;
c7c90d
+        }
c7c90d
+    }
c7c90d
+
c7c90d
+    error_setg(errp, "Invalid capability mode \"%s\" for cap-%s", val,
c7c90d
+               cap->name);
c7c90d
+out:
c7c90d
+    g_free(val);
c7c90d
+}
c7c90d
+
c7c90d
 static void cap_htm_apply(sPAPRMachineState *spapr, uint8_t val, Error **errp)
c7c90d
 {
c7c90d
     if (!val) {
c7c90d
-- 
c7c90d
1.8.3.1
c7c90d