Blame SOURCES/kvm-hw-ppc-spapr_caps-Rework-spapr_caps-to-use-uint8-int.patch

9bac43
From dde06ffd66bbc8aa9232dd2c0b849c074d9fcd06 Mon Sep 17 00:00:00 2001
9bac43
From: David Gibson <dgibson@redhat.com>
9bac43
Date: Fri, 19 Jan 2018 02:34:41 +0100
9bac43
Subject: [PATCH 13/21] hw/ppc/spapr_caps: Rework spapr_caps to use uint8
9bac43
 internal representation
9bac43
9bac43
RH-Author: David Gibson <dgibson@redhat.com>
9bac43
Message-id: <20180119023442.28577-7-dgibson@redhat.com>
9bac43
Patchwork-id: 78674
9bac43
O-Subject: [RHEL-7.5 qemu-kvm-rhev PATCH 6/7] hw/ppc/spapr_caps: Rework spapr_caps to use uint8 internal representation
9bac43
Bugzilla: 1523414
9bac43
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
9bac43
RH-Acked-by: Thomas Huth <thuth@redhat.com>
9bac43
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9bac43
9bac43
From: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
9bac43
9bac43
Currently spapr_caps are tied to boolean values (on or off). This patch
9bac43
reworks the caps so that they can have any uint8 value. This allows more
9bac43
capabilities with various values to be represented in the same way
9bac43
internally. Capabilities are numbered in ascending order. The internal
9bac43
representation of capability values is an array of uint8s in the
9bac43
sPAPRMachineState, indexed by capability number.
9bac43
9bac43
Capabilities can have their own name, description, options, getter and
9bac43
setter functions, type and allow functions. They also each have their own
9bac43
section in the migration stream. Capabilities are only migrated if they
9bac43
were explictly set on the command line, with the assumption that
9bac43
otherwise the default will match.
9bac43
9bac43
On migration we ensure that the capability value on the destination
9bac43
is greater than or equal to the capability value from the source. So
9bac43
long at this remains the case then the migration is considered
9bac43
compatible and allowed to continue.
9bac43
9bac43
This patch implements generic getter and setter functions for boolean
9bac43
capabilities. It also converts the existings cap-htm, cap-vsx and
9bac43
cap-dfp capabilities to this new format.
9bac43
9bac43
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
9bac43
(cherry picked from commit 4e5fe3688e23d61b45cc549ff1322aff8f50ef45)
9bac43
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9bac43
9bac43
Conflicts:
9bac43
	hw/ppc/spapr.c
9bac43
	include/hw/ppc/spapr.h
9bac43
9bac43
Some trivial contextual conflicts.  Also conflicts due to difference
9bac43
between upstream and downstream machine type versions.  Converted to
9bac43
apply to relevant downstream versions.
9bac43
9bac43
Again needed adjustment to the pre_save function because its return
9bac43
type has been changed upstream, but not downstream.
9bac43
9bac43
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1523414
9bac43
9bac43
Signed-off-by: David Gibson <dgibson@redhat.com>
9bac43
---
9bac43
 hw/ppc/spapr.c         |  38 ++++--
9bac43
 hw/ppc/spapr_caps.c    | 321 +++++++++++++++++++++++++------------------------
9bac43
 include/hw/ppc/spapr.h |  45 +++----
9bac43
 3 files changed, 218 insertions(+), 186 deletions(-)
9bac43
9bac43
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
9bac43
index 41cb2fa..66227c3 100644
9bac43
--- a/hw/ppc/spapr.c
9bac43
+++ b/hw/ppc/spapr.c
9bac43
@@ -320,7 +320,7 @@ static void spapr_populate_pa_features(sPAPRMachineState *spapr,
9bac43
          */
9bac43
         pa_features[3] |= 0x20;
9bac43
     }
9bac43
-    if (spapr_has_cap(spapr, SPAPR_CAP_HTM) && pa_size > 24) {
9bac43
+    if ((spapr_get_cap(spapr, SPAPR_CAP_HTM) != 0) && pa_size > 24) {
9bac43
         pa_features[24] |= 0x80;    /* Transactional memory support */
9bac43
     }
9bac43
     if (legacy_guest && pa_size > 40) {
9bac43
@@ -566,7 +566,7 @@ static void spapr_populate_cpu_dt(CPUState *cs, void *fdt, int offset,
9bac43
      *
9bac43
      * Only CPUs for which we create core types in spapr_cpu_core.c
9bac43
      * are possible, and all of those have VMX */
9bac43
-    if (spapr_has_cap(spapr, SPAPR_CAP_VSX)) {
9bac43
+    if (spapr_get_cap(spapr, SPAPR_CAP_VSX) != 0) {
9bac43
         _FDT((fdt_setprop_cell(fdt, offset, "ibm,vmx", 2)));
9bac43
     } else {
9bac43
         _FDT((fdt_setprop_cell(fdt, offset, "ibm,vmx", 1)));
9bac43
@@ -575,7 +575,7 @@ static void spapr_populate_cpu_dt(CPUState *cs, void *fdt, int offset,
9bac43
     /* Advertise DFP (Decimal Floating Point) if available
9bac43
      *   0 / no property == no DFP
9bac43
      *   1               == DFP available */
9bac43
-    if (spapr_has_cap(spapr, SPAPR_CAP_DFP)) {
9bac43
+    if (spapr_get_cap(spapr, SPAPR_CAP_DFP) != 0) {
9bac43
         _FDT((fdt_setprop_cell(fdt, offset, "ibm,dfp", 1)));
9bac43
     }
9bac43
 
9bac43
@@ -1544,6 +1544,18 @@ static bool spapr_vga_init(PCIBus *pci_bus, Error **errp)
9bac43
     }
9bac43
 }
9bac43
 
9bac43
+static int spapr_pre_load(void *opaque)
9bac43
+{
9bac43
+    int rc;
9bac43
+
9bac43
+    rc = spapr_caps_pre_load(opaque);
9bac43
+    if (rc) {
9bac43
+        return rc;
9bac43
+    }
9bac43
+
9bac43
+    return 0;
9bac43
+}
9bac43
+
9bac43
 static int spapr_post_load(void *opaque, int version_id)
9bac43
 {
9bac43
     sPAPRMachineState *spapr = (sPAPRMachineState *)opaque;
9bac43
@@ -1585,6 +1597,11 @@ static int spapr_post_load(void *opaque, int version_id)
9bac43
     return err;
9bac43
 }
9bac43
 
9bac43
+static void spapr_pre_save(void *opaque)
9bac43
+{
9bac43
+    spapr_caps_pre_save(opaque);
9bac43
+}
9bac43
+
9bac43
 static bool version_before_3(void *opaque, int version_id)
9bac43
 {
9bac43
     return version_id < 3;
9bac43
@@ -1705,7 +1722,9 @@ static const VMStateDescription vmstate_spapr = {
9bac43
     .name = "spapr",
9bac43
     .version_id = 3,
9bac43
     .minimum_version_id = 1,
9bac43
+    .pre_load = spapr_pre_load,
9bac43
     .post_load = spapr_post_load,
9bac43
+    .pre_save = spapr_pre_save,
9bac43
     .fields = (VMStateField[]) {
9bac43
         /* used to be @next_irq */
9bac43
         VMSTATE_UNUSED_BUFFER(version_before_3, 0, 4),
9bac43
@@ -1720,7 +1739,9 @@ static const VMStateDescription vmstate_spapr = {
9bac43
         &vmstate_spapr_ov5_cas,
9bac43
         &vmstate_spapr_patb_entry,
9bac43
         &vmstate_spapr_pending_events,
9bac43
-        &vmstate_spapr_caps,
9bac43
+        &vmstate_spapr_cap_htm,
9bac43
+        &vmstate_spapr_cap_vsx,
9bac43
+        &vmstate_spapr_cap_dfp,
9bac43
         NULL
9bac43
     }
9bac43
 };
9bac43
@@ -2279,8 +2300,6 @@ static void ppc_spapr_init(MachineState *machine)
9bac43
     char *filename;
9bac43
     Error *resize_hpt_err = NULL;
9bac43
 
9bac43
-    spapr_caps_validate(spapr, &error_fatal);
9bac43
-
9bac43
     msi_nonbroken = true;
9bac43
 
9bac43
     QLIST_INIT(&spapr->phbs);
9bac43
@@ -3650,7 +3669,9 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data)
9bac43
     mc->numa_mem_align_shift = 28;
9bac43
     smc->has_power9_support = true;
9bac43
 
9bac43
-    smc->default_caps = spapr_caps(SPAPR_CAP_VSX | SPAPR_CAP_DFP);
9bac43
+    smc->default_caps.caps[SPAPR_CAP_HTM] = SPAPR_CAP_OFF;
9bac43
+    smc->default_caps.caps[SPAPR_CAP_VSX] = SPAPR_CAP_ON;
9bac43
+    smc->default_caps.caps[SPAPR_CAP_DFP] = SPAPR_CAP_ON;
9bac43
     spapr_caps_add_properties(smc, &error_abort);
9bac43
 }
9bac43
 
9bac43
@@ -4056,8 +4077,7 @@ static void spapr_machine_rhel740_class_options(MachineClass *mc)
9bac43
     smc->has_power9_support = false;
9bac43
     smc->pre_2_10_has_unused_icps = true;
9bac43
     smc->resize_hpt_default = SPAPR_RESIZE_HPT_DISABLED;
9bac43
-    smc->default_caps = spapr_caps(SPAPR_CAP_HTM | SPAPR_CAP_VSX
9bac43
-                                   | SPAPR_CAP_DFP);
9bac43
+    smc->default_caps.caps[SPAPR_CAP_HTM] = SPAPR_CAP_ON;
9bac43
 }
9bac43
 
9bac43
 DEFINE_SPAPR_MACHINE(rhel740, "rhel7.4.0", false);
9bac43
diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c
9bac43
index 2b67ac2..f95a785 100644
9bac43
--- a/hw/ppc/spapr_caps.c
9bac43
+++ b/hw/ppc/spapr_caps.c
9bac43
@@ -35,18 +35,51 @@
9bac43
 typedef struct sPAPRCapabilityInfo {
9bac43
     const char *name;
9bac43
     const char *description;
9bac43
-    uint64_t flag;
9bac43
+    const char *options;                        /* valid capability values */
9bac43
+    int index;
9bac43
 
9bac43
+    /* Getter and Setter Function Pointers */
9bac43
+    ObjectPropertyAccessor *get;
9bac43
+    ObjectPropertyAccessor *set;
9bac43
+    const char *type;
9bac43
     /* Make sure the virtual hardware can support this capability */
9bac43
-    void (*allow)(sPAPRMachineState *spapr, Error **errp);
9bac43
-
9bac43
-    /* If possible, tell the virtual hardware not to allow the cap to
9bac43
-     * be used at all */
9bac43
-    void (*disallow)(sPAPRMachineState *spapr, Error **errp);
9bac43
+    void (*apply)(sPAPRMachineState *spapr, uint8_t val, Error **errp);
9bac43
 } sPAPRCapabilityInfo;
9bac43
 
9bac43
-static void cap_htm_allow(sPAPRMachineState *spapr, Error **errp)
9bac43
+static void spapr_cap_get_bool(Object *obj, Visitor *v, const char *name,
9bac43
+                               void *opaque, Error **errp)
9bac43
+{
9bac43
+    sPAPRCapabilityInfo *cap = opaque;
9bac43
+    sPAPRMachineState *spapr = SPAPR_MACHINE(obj);
9bac43
+    bool value = spapr_get_cap(spapr, cap->index) == SPAPR_CAP_ON;
9bac43
+
9bac43
+    visit_type_bool(v, name, &value, errp);
9bac43
+}
9bac43
+
9bac43
+static void spapr_cap_set_bool(Object *obj, Visitor *v, const char *name,
9bac43
+                               void *opaque, Error **errp)
9bac43
+{
9bac43
+    sPAPRCapabilityInfo *cap = opaque;
9bac43
+    sPAPRMachineState *spapr = SPAPR_MACHINE(obj);
9bac43
+    bool value;
9bac43
+    Error *local_err = NULL;
9bac43
+
9bac43
+    visit_type_bool(v, name, &value, &local_err);
9bac43
+    if (local_err) {
9bac43
+        error_propagate(errp, local_err);
9bac43
+        return;
9bac43
+    }
9bac43
+
9bac43
+    spapr->cmd_line_caps[cap->index] = true;
9bac43
+    spapr->eff.caps[cap->index] = value ? SPAPR_CAP_ON : SPAPR_CAP_OFF;
9bac43
+}
9bac43
+
9bac43
+static void cap_htm_apply(sPAPRMachineState *spapr, uint8_t val, Error **errp)
9bac43
 {
9bac43
+    if (!val) {
9bac43
+        /* TODO: We don't support disabling htm yet */
9bac43
+        return;
9bac43
+    }
9bac43
     if (tcg_enabled()) {
9bac43
         error_setg(errp,
9bac43
                    "No Transactional Memory support in TCG, try cap-htm=off");
9bac43
@@ -57,11 +90,15 @@ static void cap_htm_allow(sPAPRMachineState *spapr, Error **errp)
9bac43
     }
9bac43
 }
9bac43
 
9bac43
-static void cap_vsx_allow(sPAPRMachineState *spapr, Error **errp)
9bac43
+static void cap_vsx_apply(sPAPRMachineState *spapr, uint8_t val, Error **errp)
9bac43
 {
9bac43
     PowerPCCPU *cpu = POWERPC_CPU(first_cpu);
9bac43
     CPUPPCState *env = &cpu->env;
9bac43
 
9bac43
+    if (!val) {
9bac43
+        /* TODO: We don't support disabling vsx yet */
9bac43
+        return;
9bac43
+    }
9bac43
     /* Allowable CPUs in spapr_cpu_core.c should already have gotten
9bac43
      * rid of anything that doesn't do VMX */
9bac43
     g_assert(env->insns_flags & PPC_ALTIVEC);
9bac43
@@ -70,37 +107,51 @@ static void cap_vsx_allow(sPAPRMachineState *spapr, Error **errp)
9bac43
     }
9bac43
 }
9bac43
 
9bac43
-static void cap_dfp_allow(sPAPRMachineState *spapr, Error **errp)
9bac43
+static void cap_dfp_apply(sPAPRMachineState *spapr, uint8_t val, Error **errp)
9bac43
 {
9bac43
     PowerPCCPU *cpu = POWERPC_CPU(first_cpu);
9bac43
     CPUPPCState *env = &cpu->env;
9bac43
 
9bac43
+    if (!val) {
9bac43
+        /* TODO: We don't support disabling dfp yet */
9bac43
+        return;
9bac43
+    }
9bac43
     if (!(env->insns_flags2 & PPC2_DFP)) {
9bac43
         error_setg(errp, "DFP support not available, try cap-dfp=off");
9bac43
     }
9bac43
 }
9bac43
 
9bac43
-static sPAPRCapabilityInfo capability_table[] = {
9bac43
-    {
9bac43
+
9bac43
+sPAPRCapabilityInfo capability_table[SPAPR_CAP_NUM] = {
9bac43
+    [SPAPR_CAP_HTM] = {
9bac43
         .name = "htm",
9bac43
         .description = "Allow Hardware Transactional Memory (HTM)",
9bac43
-        .flag = SPAPR_CAP_HTM,
9bac43
-        .allow = cap_htm_allow,
9bac43
-        /* TODO: add cap_htm_disallow */
9bac43
+        .options = "",
9bac43
+        .index = SPAPR_CAP_HTM,
9bac43
+        .get = spapr_cap_get_bool,
9bac43
+        .set = spapr_cap_set_bool,
9bac43
+        .type = "bool",
9bac43
+        .apply = cap_htm_apply,
9bac43
     },
9bac43
-    {
9bac43
+    [SPAPR_CAP_VSX] = {
9bac43
         .name = "vsx",
9bac43
         .description = "Allow Vector Scalar Extensions (VSX)",
9bac43
-        .flag = SPAPR_CAP_VSX,
9bac43
-        .allow = cap_vsx_allow,
9bac43
-        /* TODO: add cap_vsx_disallow */
9bac43
+        .options = "",
9bac43
+        .index = SPAPR_CAP_VSX,
9bac43
+        .get = spapr_cap_get_bool,
9bac43
+        .set = spapr_cap_set_bool,
9bac43
+        .type = "bool",
9bac43
+        .apply = cap_vsx_apply,
9bac43
     },
9bac43
-    {
9bac43
+    [SPAPR_CAP_DFP] = {
9bac43
         .name = "dfp",
9bac43
         .description = "Allow Decimal Floating Point (DFP)",
9bac43
-        .flag = SPAPR_CAP_DFP,
9bac43
-        .allow = cap_dfp_allow,
9bac43
-        /* TODO: add cap_dfp_disallow */
9bac43
+        .options = "",
9bac43
+        .index = SPAPR_CAP_DFP,
9bac43
+        .get = spapr_cap_get_bool,
9bac43
+        .set = spapr_cap_set_bool,
9bac43
+        .type = "bool",
9bac43
+        .apply = cap_dfp_apply,
9bac43
     },
9bac43
 };
9bac43
 
9bac43
@@ -115,23 +166,33 @@ static sPAPRCapabilities default_caps_with_cpu(sPAPRMachineState *spapr,
9bac43
 
9bac43
     if (!ppc_check_compat(cpu, CPU_POWERPC_LOGICAL_2_07,
9bac43
                           0, spapr->max_compat_pvr)) {
9bac43
-        caps.mask &= ~SPAPR_CAP_HTM;
9bac43
+        caps.caps[SPAPR_CAP_HTM] = SPAPR_CAP_OFF;
9bac43
     }
9bac43
 
9bac43
     if (!ppc_check_compat(cpu, CPU_POWERPC_LOGICAL_2_06,
9bac43
                           0, spapr->max_compat_pvr)) {
9bac43
-        caps.mask &= ~SPAPR_CAP_VSX;
9bac43
-        caps.mask &= ~SPAPR_CAP_DFP;
9bac43
+        caps.caps[SPAPR_CAP_VSX] = SPAPR_CAP_OFF;
9bac43
+        caps.caps[SPAPR_CAP_DFP] = SPAPR_CAP_OFF;
9bac43
     }
9bac43
 
9bac43
     return caps;
9bac43
 }
9bac43
 
9bac43
-static bool spapr_caps_needed(void *opaque)
9bac43
+int spapr_caps_pre_load(void *opaque)
9bac43
 {
9bac43
     sPAPRMachineState *spapr = opaque;
9bac43
 
9bac43
-    return (spapr->forced_caps.mask != 0) || (spapr->forbidden_caps.mask != 0);
9bac43
+    /* Set to default so we can tell if this came in with the migration */
9bac43
+    spapr->mig = spapr->def;
9bac43
+    return 0;
9bac43
+}
9bac43
+
9bac43
+int spapr_caps_pre_save(void *opaque)
9bac43
+{
9bac43
+    sPAPRMachineState *spapr = opaque;
9bac43
+
9bac43
+    spapr->mig = spapr->eff;
9bac43
+    return 0;
9bac43
 }
9bac43
 
9bac43
 /* This has to be called from the top-level spapr post_load, not the
9bac43
@@ -140,175 +201,121 @@ static bool spapr_caps_needed(void *opaque)
9bac43
  * caps on the destination */
9bac43
 int spapr_caps_post_migration(sPAPRMachineState *spapr)
9bac43
 {
9bac43
-    uint64_t allcaps = 0;
9bac43
     int i;
9bac43
     bool ok = true;
9bac43
-    sPAPRCapabilities dstcaps = spapr->effective_caps;
9bac43
+    sPAPRCapabilities dstcaps = spapr->eff;
9bac43
     sPAPRCapabilities srccaps;
9bac43
 
9bac43
     srccaps = default_caps_with_cpu(spapr, first_cpu);
9bac43
-    srccaps.mask |= spapr->mig_forced_caps.mask;
9bac43
-    srccaps.mask &= ~spapr->mig_forbidden_caps.mask;
9bac43
+    for (i = 0; i < SPAPR_CAP_NUM; i++) {
9bac43
+        /* If not default value then assume came in with the migration */
9bac43
+        if (spapr->mig.caps[i] != spapr->def.caps[i]) {
9bac43
+            srccaps.caps[i] = spapr->mig.caps[i];
9bac43
+        }
9bac43
+    }
9bac43
 
9bac43
-    for (i = 0; i < ARRAY_SIZE(capability_table); i++) {
9bac43
+    for (i = 0; i < SPAPR_CAP_NUM; i++) {
9bac43
         sPAPRCapabilityInfo *info = &capability_table[i];
9bac43
 
9bac43
-        allcaps |= info->flag;
9bac43
-
9bac43
-        if ((srccaps.mask & info->flag) && !(dstcaps.mask & info->flag)) {
9bac43
-            error_report("cap-%s=on in incoming stream, but off in destination",
9bac43
-                         info->name);
9bac43
+        if (srccaps.caps[i] > dstcaps.caps[i]) {
9bac43
+            error_report("cap-%s higher level (%d) in incoming stream than on destination (%d)",
9bac43
+                         info->name, srccaps.caps[i], dstcaps.caps[i]);
9bac43
             ok = false;
9bac43
         }
9bac43
 
9bac43
-        if (!(srccaps.mask & info->flag) && (dstcaps.mask & info->flag)) {
9bac43
-            warn_report("cap-%s=off in incoming stream, but on in destination",
9bac43
-                         info->name);
9bac43
+        if (srccaps.caps[i] < dstcaps.caps[i]) {
9bac43
+            warn_report("cap-%s lower level (%d) in incoming stream than on destination (%d)",
9bac43
+                         info->name, srccaps.caps[i], dstcaps.caps[i]);
9bac43
         }
9bac43
     }
9bac43
 
9bac43
-    if (spapr->mig_forced_caps.mask & ~allcaps) {
9bac43
-        error_report(
9bac43
-            "Unknown capabilities 0x%"PRIx64" enabled in incoming stream",
9bac43
-            spapr->mig_forced_caps.mask & ~allcaps);
9bac43
-        ok = false;
9bac43
-    }
9bac43
-    if (spapr->mig_forbidden_caps.mask & ~allcaps) {
9bac43
-        warn_report(
9bac43
-            "Unknown capabilities 0x%"PRIx64" disabled in incoming stream",
9bac43
-            spapr->mig_forbidden_caps.mask & ~allcaps);
9bac43
-    }
9bac43
-
9bac43
     return ok ? 0 : -EINVAL;
9bac43
 }
9bac43
 
9bac43
-static void spapr_caps_pre_save(void *opaque)
9bac43
+static bool spapr_cap_htm_needed(void *opaque)
9bac43
 {
9bac43
     sPAPRMachineState *spapr = opaque;
9bac43
 
9bac43
-    spapr->mig_forced_caps = spapr->forced_caps;
9bac43
-    spapr->mig_forbidden_caps = spapr->forbidden_caps;
9bac43
+    return spapr->cmd_line_caps[SPAPR_CAP_HTM] &&
9bac43
+           (spapr->eff.caps[SPAPR_CAP_HTM] != spapr->def.caps[SPAPR_CAP_HTM]);
9bac43
 }
9bac43
 
9bac43
-static int spapr_caps_pre_load(void *opaque)
9bac43
+const VMStateDescription vmstate_spapr_cap_htm = {
9bac43
+    .name = "spapr/cap/htm",
9bac43
+    .version_id = 1,
9bac43
+    .minimum_version_id = 1,
9bac43
+    .needed = spapr_cap_htm_needed,
9bac43
+    .fields = (VMStateField[]) {
9bac43
+        VMSTATE_UINT8(mig.caps[SPAPR_CAP_HTM], sPAPRMachineState),
9bac43
+        VMSTATE_END_OF_LIST()
9bac43
+    },
9bac43
+};
9bac43
+
9bac43
+static bool spapr_cap_vsx_needed(void *opaque)
9bac43
 {
9bac43
     sPAPRMachineState *spapr = opaque;
9bac43
 
9bac43
-    spapr->mig_forced_caps = spapr_caps(0);
9bac43
-    spapr->mig_forbidden_caps = spapr_caps(0);
9bac43
-    return 0;
9bac43
+    return spapr->cmd_line_caps[SPAPR_CAP_VSX] &&
9bac43
+           (spapr->eff.caps[SPAPR_CAP_VSX] != spapr->def.caps[SPAPR_CAP_VSX]);
9bac43
 }
9bac43
 
9bac43
-const VMStateDescription vmstate_spapr_caps = {
9bac43
-    .name = "spapr/caps",
9bac43
+const VMStateDescription vmstate_spapr_cap_vsx = {
9bac43
+    .name = "spapr/cap/vsx",
9bac43
     .version_id = 1,
9bac43
     .minimum_version_id = 1,
9bac43
-    .needed = spapr_caps_needed,
9bac43
-    .pre_save = spapr_caps_pre_save,
9bac43
-    .pre_load = spapr_caps_pre_load,
9bac43
+    .needed = spapr_cap_vsx_needed,
9bac43
     .fields = (VMStateField[]) {
9bac43
-        VMSTATE_UINT64(mig_forced_caps.mask, sPAPRMachineState),
9bac43
-        VMSTATE_UINT64(mig_forbidden_caps.mask, sPAPRMachineState),
9bac43
+        VMSTATE_UINT8(mig.caps[SPAPR_CAP_VSX], sPAPRMachineState),
9bac43
         VMSTATE_END_OF_LIST()
9bac43
     },
9bac43
 };
9bac43
 
9bac43
-void spapr_caps_reset(sPAPRMachineState *spapr)
9bac43
-{
9bac43
-    Error *local_err = NULL;
9bac43
-    sPAPRCapabilities caps;
9bac43
-    int i;
9bac43
-
9bac43
-    /* First compute the actual set of caps we're running with.. */
9bac43
-    caps = default_caps_with_cpu(spapr, first_cpu);
9bac43
-
9bac43
-    /* Remove unnecessary forced/forbidden bits (this will help us
9bac43
-     * with migration) */
9bac43
-    spapr->forced_caps.mask &= ~caps.mask;
9bac43
-    spapr->forbidden_caps.mask &= caps.mask;
9bac43
-
9bac43
-    caps.mask |= spapr->forced_caps.mask;
9bac43
-    caps.mask &= ~spapr->forbidden_caps.mask;
9bac43
-
9bac43
-    spapr->effective_caps = caps;
9bac43
-
9bac43
-    /* .. then apply those caps to the virtual hardware */
9bac43
-
9bac43
-    for (i = 0; i < ARRAY_SIZE(capability_table); i++) {
9bac43
-        sPAPRCapabilityInfo *info = &capability_table[i];
9bac43
-
9bac43
-        if (spapr->effective_caps.mask & info->flag) {
9bac43
-            /* Failure to allow a cap is fatal - if the guest doesn't
9bac43
-             * have it, we'll be supplying an incorrect environment */
9bac43
-            if (info->allow) {
9bac43
-                info->allow(spapr, &error_fatal);
9bac43
-            }
9bac43
-        } else {
9bac43
-            /* Failure to enforce a cap is only a warning.  The guest
9bac43
-             * shouldn't be using it, since it's not advertised, so it
9bac43
-             * doesn't get to complain about weird behaviour if it
9bac43
-             * goes ahead anyway */
9bac43
-            if (info->disallow) {
9bac43
-                info->disallow(spapr, &local_err);
9bac43
-            }
9bac43
-            if (local_err) {
9bac43
-                warn_report_err(local_err);
9bac43
-                local_err = NULL;
9bac43
-            }
9bac43
-        }
9bac43
-    }
9bac43
-}
9bac43
-
9bac43
-static void spapr_cap_get(Object *obj, Visitor *v, const char *name,
9bac43
-                          void *opaque, Error **errp)
9bac43
+static bool spapr_cap_dfp_needed(void *opaque)
9bac43
 {
9bac43
-    sPAPRCapabilityInfo *cap = opaque;
9bac43
-    sPAPRMachineState *spapr = SPAPR_MACHINE(obj);
9bac43
-    bool value = spapr_has_cap(spapr, cap->flag);
9bac43
-
9bac43
-    /* TODO: Could this get called before effective_caps is finalized
9bac43
-     * in spapr_caps_reset()? */
9bac43
+    sPAPRMachineState *spapr = opaque;
9bac43
 
9bac43
-    visit_type_bool(v, name, &value, errp);
9bac43
+    return spapr->cmd_line_caps[SPAPR_CAP_DFP] &&
9bac43
+           (spapr->eff.caps[SPAPR_CAP_DFP] != spapr->def.caps[SPAPR_CAP_DFP]);
9bac43
 }
9bac43
 
9bac43
-static void spapr_cap_set(Object *obj, Visitor *v, const char *name,
9bac43
-                          void *opaque, Error **errp)
9bac43
-{
9bac43
-    sPAPRCapabilityInfo *cap = opaque;
9bac43
-    sPAPRMachineState *spapr = SPAPR_MACHINE(obj);
9bac43
-    bool value;
9bac43
-    Error *local_err = NULL;
9bac43
-
9bac43
-    visit_type_bool(v, name, &value, &local_err);
9bac43
-    if (local_err) {
9bac43
-        error_propagate(errp, local_err);
9bac43
-        return;
9bac43
-    }
9bac43
-
9bac43
-    if (value) {
9bac43
-        spapr->forced_caps.mask |= cap->flag;
9bac43
-    } else {
9bac43
-        spapr->forbidden_caps.mask |= cap->flag;
9bac43
-    }
9bac43
-}
9bac43
+const VMStateDescription vmstate_spapr_cap_dfp = {
9bac43
+    .name = "spapr/cap/dfp",
9bac43
+    .version_id = 1,
9bac43
+    .minimum_version_id = 1,
9bac43
+    .needed = spapr_cap_dfp_needed,
9bac43
+    .fields = (VMStateField[]) {
9bac43
+        VMSTATE_UINT8(mig.caps[SPAPR_CAP_DFP], sPAPRMachineState),
9bac43
+        VMSTATE_END_OF_LIST()
9bac43
+    },
9bac43
+};
9bac43
 
9bac43
-void spapr_caps_validate(sPAPRMachineState *spapr, Error **errp)
9bac43
+void spapr_caps_reset(sPAPRMachineState *spapr)
9bac43
 {
9bac43
-    uint64_t allcaps = 0;
9bac43
+    sPAPRCapabilities default_caps;
9bac43
     int i;
9bac43
 
9bac43
-    for (i = 0; i < ARRAY_SIZE(capability_table); i++) {
9bac43
-        g_assert((allcaps & capability_table[i].flag) == 0);
9bac43
-        allcaps |= capability_table[i].flag;
9bac43
+    /* First compute the actual set of caps we're running with.. */
9bac43
+    default_caps = default_caps_with_cpu(spapr, first_cpu);
9bac43
+
9bac43
+    for (i = 0; i < SPAPR_CAP_NUM; i++) {
9bac43
+        /* Store the defaults */
9bac43
+        spapr->def.caps[i] = default_caps.caps[i];
9bac43
+        /* If not set on the command line then apply the default value */
9bac43
+        if (!spapr->cmd_line_caps[i]) {
9bac43
+            spapr->eff.caps[i] = default_caps.caps[i];
9bac43
+        }
9bac43
     }
9bac43
 
9bac43
-    g_assert((spapr->forced_caps.mask & ~allcaps) == 0);
9bac43
-    g_assert((spapr->forbidden_caps.mask & ~allcaps) == 0);
9bac43
+    /* .. then apply those caps to the virtual hardware */
9bac43
+
9bac43
+    for (i = 0; i < SPAPR_CAP_NUM; i++) {
9bac43
+        sPAPRCapabilityInfo *info = &capability_table[i];
9bac43
 
9bac43
-    if (spapr->forced_caps.mask & spapr->forbidden_caps.mask) {
9bac43
-        error_setg(errp, "Some sPAPR capabilities set both on and off");
9bac43
-        return;
9bac43
+        /*
9bac43
+         * If the apply function can't set the desired level and thinks it's
9bac43
+         * fatal, it should cause that.
9bac43
+         */
9bac43
+        info->apply(spapr, spapr->eff.caps[i], &error_fatal);
9bac43
     }
9bac43
 }
9bac43
 
9bac43
@@ -321,17 +328,19 @@ void spapr_caps_add_properties(sPAPRMachineClass *smc, Error **errp)
9bac43
     for (i = 0; i < ARRAY_SIZE(capability_table); i++) {
9bac43
         sPAPRCapabilityInfo *cap = &capability_table[i];
9bac43
         const char *name = g_strdup_printf("cap-%s", cap->name);
9bac43
+        char *desc;
9bac43
 
9bac43
-        object_class_property_add(klass, name, "bool",
9bac43
-                                  spapr_cap_get, spapr_cap_set, NULL,
9bac43
-                                  cap, &local_err);
9bac43
+        object_class_property_add(klass, name, cap->type,
9bac43
+                                  cap->get, cap->set,
9bac43
+                                  NULL, cap, &local_err);
9bac43
         if (local_err) {
9bac43
             error_propagate(errp, local_err);
9bac43
             return;
9bac43
         }
9bac43
 
9bac43
-        object_class_property_set_description(klass, name, cap->description,
9bac43
-                                              &local_err);
9bac43
+        desc = g_strdup_printf("%s%s", cap->description, cap->options);
9bac43
+        object_class_property_set_description(klass, name, desc, &local_err);
9bac43
+        g_free(desc);
9bac43
         if (local_err) {
9bac43
             error_propagate(errp, local_err);
9bac43
             return;
9bac43
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
9bac43
index df767c3..7156a70 100644
9bac43
--- a/include/hw/ppc/spapr.h
9bac43
+++ b/include/hw/ppc/spapr.h
9bac43
@@ -54,20 +54,25 @@ typedef enum {
9bac43
  * Capabilities
9bac43
  */
9bac43
 
9bac43
-/* These bits go in the migration stream, so they can't be reassigned */
9bac43
-
9bac43
 /* Hardware Transactional Memory */
9bac43
-#define SPAPR_CAP_HTM               0x0000000000000001ULL
9bac43
-
9bac43
+#define SPAPR_CAP_HTM                   0x00
9bac43
 /* Vector Scalar Extensions */
9bac43
-#define SPAPR_CAP_VSX               0x0000000000000002ULL
9bac43
-
9bac43
+#define SPAPR_CAP_VSX                   0x01
9bac43
 /* Decimal Floating Point */
9bac43
-#define SPAPR_CAP_DFP               0x0000000000000004ULL
9bac43
+#define SPAPR_CAP_DFP                   0x02
9bac43
+/* Num Caps */
9bac43
+#define SPAPR_CAP_NUM                   (SPAPR_CAP_DFP + 1)
9bac43
+
9bac43
+/*
9bac43
+ * Capability Values
9bac43
+ */
9bac43
+/* Bool Caps */
9bac43
+#define SPAPR_CAP_OFF                   0x00
9bac43
+#define SPAPR_CAP_ON                    0x01
9bac43
 
9bac43
 typedef struct sPAPRCapabilities sPAPRCapabilities;
9bac43
 struct sPAPRCapabilities {
9bac43
-    uint64_t mask;
9bac43
+    uint8_t caps[SPAPR_CAP_NUM];
9bac43
 };
9bac43
 
9bac43
 /**
9bac43
@@ -151,9 +156,8 @@ struct sPAPRMachineState {
9bac43
 
9bac43
     const char *icp_type;
9bac43
 
9bac43
-    sPAPRCapabilities forced_caps, forbidden_caps;
9bac43
-    sPAPRCapabilities mig_forced_caps, mig_forbidden_caps;
9bac43
-    sPAPRCapabilities effective_caps;
9bac43
+    bool cmd_line_caps[SPAPR_CAP_NUM];
9bac43
+    sPAPRCapabilities def, eff, mig;
9bac43
 };
9bac43
 
9bac43
 #define H_SUCCESS         0
9bac43
@@ -732,24 +736,23 @@ void spapr_do_system_reset_on_cpu(CPUState *cs, run_on_cpu_data arg);
9bac43
 
9bac43
 #define HTAB_SIZE(spapr)        (1ULL << ((spapr)->htab_shift))
9bac43
 
9bac43
+
9bac43
+int spapr_caps_pre_load(void *opaque);
9bac43
+int spapr_caps_pre_save(void *opaque);
9bac43
+
9bac43
 /*
9bac43
  * Handling of optional capabilities
9bac43
  */
9bac43
-extern const VMStateDescription vmstate_spapr_caps;
9bac43
-
9bac43
-static inline sPAPRCapabilities spapr_caps(uint64_t mask)
9bac43
-{
9bac43
-    sPAPRCapabilities caps = { mask };
9bac43
-    return caps;
9bac43
-}
9bac43
+extern const VMStateDescription vmstate_spapr_cap_htm;
9bac43
+extern const VMStateDescription vmstate_spapr_cap_vsx;
9bac43
+extern const VMStateDescription vmstate_spapr_cap_dfp;
9bac43
 
9bac43
-static inline bool spapr_has_cap(sPAPRMachineState *spapr, uint64_t cap)
9bac43
+static inline uint8_t spapr_get_cap(sPAPRMachineState *spapr, int cap)
9bac43
 {
9bac43
-    return !!(spapr->effective_caps.mask & cap);
9bac43
+    return spapr->eff.caps[cap];
9bac43
 }
9bac43
 
9bac43
 void spapr_caps_reset(sPAPRMachineState *spapr);
9bac43
-void spapr_caps_validate(sPAPRMachineState *spapr, Error **errp);
9bac43
 void spapr_caps_add_properties(sPAPRMachineClass *smc, Error **errp);
9bac43
 int spapr_caps_post_migration(sPAPRMachineState *spapr);
9bac43
 
9bac43
-- 
9bac43
1.8.3.1
9bac43