yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-target-ppc-add-basic-support-for-PTCR-on-POWER9.patch

ae23c9
From 3b97963ddb435e25f758032691cb2315570a2093 Mon Sep 17 00:00:00 2001
ae23c9
From: David Gibson <dgibson@redhat.com>
ae23c9
Date: Mon, 12 Nov 2018 01:28:32 +0000
ae23c9
Subject: [PATCH 01/16] target/ppc: add basic support for PTCR on POWER9
ae23c9
MIME-Version: 1.0
ae23c9
Content-Type: text/plain; charset=UTF-8
ae23c9
Content-Transfer-Encoding: 8bit
ae23c9
ae23c9
RH-Author: David Gibson <dgibson@redhat.com>
ae23c9
Message-id: <20181112012835.21863-2-dgibson@redhat.com>
ae23c9
Patchwork-id: 82978
ae23c9
O-Subject: [RHEL-8 qemu-kvm PATCH 1/4] target/ppc: add basic support for PTCR on POWER9
ae23c9
Bugzilla: 1639069
ae23c9
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
ae23c9
RH-Acked-by: Serhii Popovych <spopovyc@redhat.com>
ae23c9
RH-Acked-by: Thomas Huth <thuth@redhat.com>
ae23c9
ae23c9
From: Cédric Le Goater <clg@kaod.org>
ae23c9
ae23c9
The Partition Table Control Register (PTCR) is a hypervisor privileged
ae23c9
SPR. It contains the host real address of the Partition Table and its
ae23c9
size.
ae23c9
ae23c9
Signed-off-by: Cédric Le Goater <clg@kaod.org>
ae23c9
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
ae23c9
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
ae23c9
(cherry picked from commit 4a7518e0fdaa20525730ae0709a4afa0960a6c67)
ae23c9
ae23c9
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1639069
ae23c9
ae23c9
Signed-off-by: David Gibson <dgibson@redhat.com>
ae23c9
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ae23c9
---
ae23c9
 target/ppc/cpu.h            |  2 ++
ae23c9
 target/ppc/helper.h         |  1 +
ae23c9
 target/ppc/misc_helper.c    | 12 ++++++++++++
ae23c9
 target/ppc/mmu-book3s-v3.h  |  6 ++++++
ae23c9
 target/ppc/mmu_helper.c     | 29 +++++++++++++++++++++++++++++
ae23c9
 target/ppc/translate.c      |  3 +++
ae23c9
 target/ppc/translate_init.c | 18 ++++++++++++++++++
ae23c9
 7 files changed, 71 insertions(+)
ae23c9
ae23c9
diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
ae23c9
index 1932c2e..8f3cf44 100644
ae23c9
--- a/target/ppc/cpu.h
ae23c9
+++ b/target/ppc/cpu.h
ae23c9
@@ -1313,6 +1313,7 @@ int ppc_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int size, int rw,
ae23c9
 
ae23c9
 #if !defined(CONFIG_USER_ONLY)
ae23c9
 void ppc_store_sdr1 (CPUPPCState *env, target_ulong value);
ae23c9
+void ppc_store_ptcr(CPUPPCState *env, target_ulong value);
ae23c9
 #endif /* !defined(CONFIG_USER_ONLY) */
ae23c9
 void ppc_store_msr (CPUPPCState *env, target_ulong value);
ae23c9
 
ae23c9
@@ -1604,6 +1605,7 @@ void ppc_compat_add_property(Object *obj, const char *name,
ae23c9
 #define SPR_BOOKE_GIVOR13     (0x1BC)
ae23c9
 #define SPR_BOOKE_GIVOR14     (0x1BD)
ae23c9
 #define SPR_TIR               (0x1BE)
ae23c9
+#define SPR_PTCR              (0x1D0)
ae23c9
 #define SPR_BOOKE_SPEFSCR     (0x200)
ae23c9
 #define SPR_Exxx_BBEAR        (0x201)
ae23c9
 #define SPR_Exxx_BBTAR        (0x202)
ae23c9
diff --git a/target/ppc/helper.h b/target/ppc/helper.h
ae23c9
index 5b73917..19453c6 100644
ae23c9
--- a/target/ppc/helper.h
ae23c9
+++ b/target/ppc/helper.h
ae23c9
@@ -709,6 +709,7 @@ DEF_HELPER_FLAGS_1(load_601_rtcu, TCG_CALL_NO_RWG, tl, env)
ae23c9
 #if !defined(CONFIG_USER_ONLY)
ae23c9
 #if defined(TARGET_PPC64)
ae23c9
 DEF_HELPER_FLAGS_1(load_purr, TCG_CALL_NO_RWG, tl, env)
ae23c9
+DEF_HELPER_2(store_ptcr, void, env, tl)
ae23c9
 #endif
ae23c9
 DEF_HELPER_2(store_sdr1, void, env, tl)
ae23c9
 DEF_HELPER_2(store_pidr, void, env, tl)
ae23c9
diff --git a/target/ppc/misc_helper.c b/target/ppc/misc_helper.c
ae23c9
index 0e42178..8c8cba5 100644
ae23c9
--- a/target/ppc/misc_helper.c
ae23c9
+++ b/target/ppc/misc_helper.c
ae23c9
@@ -88,6 +88,18 @@ void helper_store_sdr1(CPUPPCState *env, target_ulong val)
ae23c9
     }
ae23c9
 }
ae23c9
 
ae23c9
+#if defined(TARGET_PPC64)
ae23c9
+void helper_store_ptcr(CPUPPCState *env, target_ulong val)
ae23c9
+{
ae23c9
+    PowerPCCPU *cpu = ppc_env_get_cpu(env);
ae23c9
+
ae23c9
+    if (env->spr[SPR_PTCR] != val) {
ae23c9
+        ppc_store_ptcr(env, val);
ae23c9
+        tlb_flush(CPU(cpu));
ae23c9
+    }
ae23c9
+}
ae23c9
+#endif /* defined(TARGET_PPC64) */
ae23c9
+
ae23c9
 void helper_store_pidr(CPUPPCState *env, target_ulong val)
ae23c9
 {
ae23c9
     PowerPCCPU *cpu = ppc_env_get_cpu(env);
ae23c9
diff --git a/target/ppc/mmu-book3s-v3.h b/target/ppc/mmu-book3s-v3.h
ae23c9
index 56095da..fdf8098 100644
ae23c9
--- a/target/ppc/mmu-book3s-v3.h
ae23c9
+++ b/target/ppc/mmu-book3s-v3.h
ae23c9
@@ -22,6 +22,12 @@
ae23c9
 
ae23c9
 #ifndef CONFIG_USER_ONLY
ae23c9
 
ae23c9
+/*
ae23c9
+ * Partition table definitions
ae23c9
+ */
ae23c9
+#define PTCR_PATB               0x0FFFFFFFFFFFF000ULL /* Partition Table Base */
ae23c9
+#define PTCR_PATS               0x000000000000001FULL /* Partition Table Size */
ae23c9
+
ae23c9
 /* Partition Table Entry Fields */
ae23c9
 #define PATBE1_GR 0x8000000000000000
ae23c9
 
ae23c9
diff --git a/target/ppc/mmu_helper.c b/target/ppc/mmu_helper.c
ae23c9
index 5568d16..e2197a5 100644
ae23c9
--- a/target/ppc/mmu_helper.c
ae23c9
+++ b/target/ppc/mmu_helper.c
ae23c9
@@ -2028,6 +2028,35 @@ void ppc_store_sdr1(CPUPPCState *env, target_ulong value)
ae23c9
     env->spr[SPR_SDR1] = value;
ae23c9
 }
ae23c9
 
ae23c9
+#if defined(TARGET_PPC64)
ae23c9
+void ppc_store_ptcr(CPUPPCState *env, target_ulong value)
ae23c9
+{
ae23c9
+    PowerPCCPU *cpu = ppc_env_get_cpu(env);
ae23c9
+    target_ulong ptcr_mask = PTCR_PATB | PTCR_PATS;
ae23c9
+    target_ulong patbsize = value & PTCR_PATS;
ae23c9
+
ae23c9
+    qemu_log_mask(CPU_LOG_MMU, "%s: " TARGET_FMT_lx "\n", __func__, value);
ae23c9
+
ae23c9
+    assert(!cpu->vhyp);
ae23c9
+    assert(env->mmu_model & POWERPC_MMU_3_00);
ae23c9
+
ae23c9
+    if (value & ~ptcr_mask) {
ae23c9
+        error_report("Invalid bits 0x"TARGET_FMT_lx" set in PTCR",
ae23c9
+                     value & ~ptcr_mask);
ae23c9
+        value &= ptcr_mask;
ae23c9
+    }
ae23c9
+
ae23c9
+    if (patbsize > 24) {
ae23c9
+        error_report("Invalid Partition Table size 0x" TARGET_FMT_lx
ae23c9
+                     " stored in PTCR", patbsize);
ae23c9
+        return;
ae23c9
+    }
ae23c9
+
ae23c9
+    env->spr[SPR_PTCR] = value;
ae23c9
+}
ae23c9
+
ae23c9
+#endif /* defined(TARGET_PPC64) */
ae23c9
+
ae23c9
 /* Segment registers load and store */
ae23c9
 target_ulong helper_load_sr(CPUPPCState *env, target_ulong sr_num)
ae23c9
 {
ae23c9
diff --git a/target/ppc/translate.c b/target/ppc/translate.c
ae23c9
index 3457d29..7da9b67 100644
ae23c9
--- a/target/ppc/translate.c
ae23c9
+++ b/target/ppc/translate.c
ae23c9
@@ -7136,6 +7136,9 @@ void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,
ae23c9
         if (env->spr_cb[SPR_SDR1].name) { /* SDR1 Exists */
ae23c9
             cpu_fprintf(f, " SDR1 " TARGET_FMT_lx " ", env->spr[SPR_SDR1]);
ae23c9
         }
ae23c9
+        if (env->spr_cb[SPR_PTCR].name) { /* PTCR Exists */
ae23c9
+            cpu_fprintf(f, " PTCR " TARGET_FMT_lx " ", env->spr[SPR_PTCR]);
ae23c9
+        }
ae23c9
         cpu_fprintf(f, "  DAR " TARGET_FMT_lx "  DSISR " TARGET_FMT_lx "\n",
ae23c9
                     env->spr[SPR_DAR], env->spr[SPR_DSISR]);
ae23c9
         break;
ae23c9
diff --git a/target/ppc/translate_init.c b/target/ppc/translate_init.c
ae23c9
index 17b06c7..926efbc 100644
ae23c9
--- a/target/ppc/translate_init.c
ae23c9
+++ b/target/ppc/translate_init.c
ae23c9
@@ -420,6 +420,11 @@ static void spr_write_hior(DisasContext *ctx, int sprn, int gprn)
ae23c9
     tcg_gen_st_tl(t0, cpu_env, offsetof(CPUPPCState, excp_prefix));
ae23c9
     tcg_temp_free(t0);
ae23c9
 }
ae23c9
+static void spr_write_ptcr(DisasContext *ctx, int sprn, int gprn)
ae23c9
+{
ae23c9
+    gen_helper_store_ptcr(cpu_env, cpu_gpr[gprn]);
ae23c9
+}
ae23c9
+
ae23c9
 #endif
ae23c9
 #endif
ae23c9
 
ae23c9
@@ -8167,6 +8172,18 @@ static void gen_spr_power8_rpr(CPUPPCState *env)
ae23c9
 #endif
ae23c9
 }
ae23c9
 
ae23c9
+static void gen_spr_power9_mmu(CPUPPCState *env)
ae23c9
+{
ae23c9
+#if !defined(CONFIG_USER_ONLY)
ae23c9
+    /* Partition Table Control */
ae23c9
+    spr_register_hv(env, SPR_PTCR, "PTCR",
ae23c9
+                    SPR_NOACCESS, SPR_NOACCESS,
ae23c9
+                    SPR_NOACCESS, SPR_NOACCESS,
ae23c9
+                    &spr_read_generic, &spr_write_ptcr,
ae23c9
+                    0x00000000);
ae23c9
+#endif
ae23c9
+}
ae23c9
+
ae23c9
 static void init_proc_book3s_common(CPUPPCState *env)
ae23c9
 {
ae23c9
     gen_spr_ne_601(env);
ae23c9
@@ -8761,6 +8778,7 @@ static void init_proc_POWER9(CPUPPCState *env)
ae23c9
     gen_spr_power8_ic(env);
ae23c9
     gen_spr_power8_book4(env);
ae23c9
     gen_spr_power8_rpr(env);
ae23c9
+    gen_spr_power9_mmu(env);
ae23c9
 
ae23c9
     /* POWER9 Specific registers */
ae23c9
     spr_register_kvm(env, SPR_TIDR, "TIDR", NULL, NULL,
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9