On 23.05.14 04:26, Alexey Kardashevskiy wrote:
This adds basic support for the "compat" CPU option. By specifying
the compat property, the user can manually switch guest CPU mode from
"raw" to "architected".

This defines feature disable bits which are not used yet as, for example,
PowerISA 2.07 says if 2.06 mode is selected, the TM bit does not matter -
transactional memory (TM) will be disabled because 2.06 does not define
it at all. The same is true for VSX and 2.05 mode. So just setting a mode
must be ok.

This does not change the existing behavior as the actual compatibility
mode support is coming in next patches.

Signed-off-by: Alexey Kardashevskiy <a...@ozlabs.ru>
---
  hw/ppc/spapr.c              | 14 ++++++++++++++
  target-ppc/cpu-qom.h        |  2 ++
  target-ppc/cpu.h            | 11 +++++++++++
  target-ppc/translate_init.c | 34 ++++++++++++++++++++++++++++++++++
  4 files changed, 61 insertions(+)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index aa17cae..5ea9640 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -210,6 +210,14 @@ static int spapr_fixup_cpu_smt_dt(void *fdt, int offset, 
PowerPCCPU *cpu,
      uint32_t gservers_prop[smt_threads * 2];
      int index = ppc_get_vcpu_dt_id(cpu);
+ if (cpu->cpu_version) {
+        ret = fdt_setprop(fdt, offset, "cpu-version",
+                          &cpu->cpu_version, sizeof(cpu->cpu_version));
+        if (ret < 0) {
+            return ret;
+        }
+    }
+
      /* Build interrupt servers and gservers properties */
      for (i = 0; i < smt_threads; i++) {
          servers_prop[i] = cpu_to_be32(index + i);
@@ -1289,6 +1297,12 @@ static void ppc_spapr_init(QEMUMachineInitArgs *args)
              kvmppc_set_papr(cpu);
          }
+ if (cpu->max_compat) {
+            if (ppc_set_compat(cpu, cpu->max_compat) < 0) {
+                exit(1);
+            }
+        }
+
          xics_cpu_setup(spapr->icp, cpu);
qemu_register_reset(spapr_cpu_reset, cpu);
diff --git a/target-ppc/cpu-qom.h b/target-ppc/cpu-qom.h
index 533de8f..e88e1da 100644
--- a/target-ppc/cpu-qom.h
+++ b/target-ppc/cpu-qom.h
@@ -84,6 +84,7 @@ typedef struct PowerPCCPUClass {
   * @env: #CPUPPCState
   * @cpu_dt_id: CPU index used in the device tree. KVM uses this index too
   * @max_compat: Maximal supported logical PVR from the command line
+ * @cpu_version: Current logical PVR, zero if in "raw" mode
   *
   * A PowerPC CPU.
   */
@@ -95,6 +96,7 @@ struct PowerPCCPU {
      CPUPPCState env;
      int cpu_dt_id;
      uint32_t max_compat;
+    uint32_t cpu_version;
  };
static inline PowerPCCPU *ppc_env_get_cpu(CPUPPCState *env)
diff --git a/target-ppc/cpu.h b/target-ppc/cpu.h
index b035e91..d3b8236 100644
--- a/target-ppc/cpu.h
+++ b/target-ppc/cpu.h
@@ -1122,6 +1122,7 @@ void ppc_store_sdr1 (CPUPPCState *env, target_ulong 
value);
  void ppc_store_msr (CPUPPCState *env, target_ulong value);
void ppc_cpu_list (FILE *f, fprintf_function cpu_fprintf);
+int ppc_set_compat(PowerPCCPU *cpu, uint32_t cpu_version);
/* Time-base and decrementer management */
  #ifndef NO_CPU_IO_DEFS
@@ -1338,6 +1339,7 @@ static inline int cpu_mmu_index (CPUPPCState *env)
  #define SPR_LPCR              (0x13E)
  #define SPR_BOOKE_DVC2        (0x13F)
  #define SPR_BOOKE_TSR         (0x150)
+#define SPR_PCR               (0x152)
  #define SPR_BOOKE_TCR         (0x154)
  #define SPR_BOOKE_TLB0PS      (0x158)
  #define SPR_BOOKE_TLB1PS      (0x159)
@@ -2061,6 +2063,15 @@ enum {
      PPC_INTERRUPT_PERFM,          /* Performance monitor interrupt        */
  };
+/* Processor Compatibility mask (PCR) */
+enum {
+    PCR_COMPAT_2_05     = 1ul << (63-62),
+    PCR_COMPAT_2_06     = 1ul << (63-61),
+    PCR_VEC_DIS         = 1ul << (63-0), /* Vec. disable (bit NA since POWER8) 
*/
+    PCR_VSX_DIS         = 1ul << (63-1), /* VSX disable (bit NA since POWER8) 
*/
+    PCR_TM_DIS          = 1ul << (63-2), /* Trans. memory disable (POWER8) */

This breaks compilation on 32bit hosts with

05/27 01:53:16 ERROR|     utils:0144| [stderr] In file included from 
/usr/local/autotest/tmp/virt/src/qemu/include/qemu-common.h:116:0,
05/27 01:53:16 ERROR|     utils:0144| [stderr]                  from 
/usr/local/autotest/tmp/virt/src/qemu/exec.c:25:
05/27 01:53:16 ERROR|     utils:0144| [stderr] 
/usr/local/autotest/tmp/virt/src/qemu/target-ppc/cpu.h:2071:5: error: left shift 
count >= width of type [-Werror]
05/27 01:53:16 ERROR|     utils:0144| [stderr] 
/usr/local/autotest/tmp/virt/src/qemu/target-ppc/cpu.h:2072:5: error: left shift 
count >= width of type [-Werror]
05/27 01:53:16 ERROR|     utils:0144| [stderr] 
/usr/local/autotest/tmp/virt/src/qemu/target-ppc/cpu.h:2073:5: error: left shift 
count >= width of type [-Werror]
05/27 01:53:16 ERROR|     utils:0144| [stderr] cc1: all warnings being treated 
as errors


I've changed the 1 to be ULL instead of UL (which is usually bogus in TCG code)


Alex


Reply via email to