target/ppc: add hash MMU support for the POWER9 PowerNV machine
cover target/ppc: add hash MMU support for the POWER9 PowerNV machine
Hello,
This adds support for the Hash Page Table MMU mode on POWER9 PowerNV machines. The Radix Tree mode support for the host is still to be done but we are getting close.
The full tree can be found here :
https://github.com/legoater/qemu powernv-2.12
Thanks,
C.
Cédric Le Goater (3):
target/ppc: add basic support for PTCR on POWER9 target/ppc: add hash MMU support on POWER9 for PowerNV only target/ppc: generalize check on radix when in HV mode
hw/ppc/spapr_hcall.c | 5 +++-- target/ppc/cpu.h | 2 ++ target/ppc/helper.h | 1 + target/ppc/misc_helper.c | 12 ++++++++++++ target/ppc/mmu-book3s-v3.c | 17 +++++++++++++++- target/ppc/mmu-book3s-v3.h | 8 +------- target/ppc/mmu-hash64.c | 48 ++++++++++++++++++++++++++++++++++++--------- target/ppc/mmu-hash64.h | 41 ++++++++++++++++++++++++++++++++++++-- target/ppc/mmu_helper.c | 32 ++++++++++++++++++++++++++++-- target/ppc/translate.c | 3 +++ target/ppc/translate_init.c | 20 ++++++++++++++++++- 11 files changed, 165 insertions(+), 24 deletions(-)
Signature · 1 line
2.13.6
PATCH 1/3 target/ppc: add basic support for PTCR on POWER9
The Partition Table Control Register (PTCR) is a hypervisor privileged SPR. It contains the host real address of the Partition Table and its size.
--- target/ppc/cpu.h | 2 ++ target/ppc/helper.h | 1 + target/ppc/misc_helper.c | 12 ++++++++++++ target/ppc/mmu-hash64.h | 6 ++++++ target/ppc/mmu_helper.c | 28 ++++++++++++++++++++++++++++ target/ppc/translate.c | 3 +++ target/ppc/translate_init.c | 18 ++++++++++++++++++ 7 files changed, 70 insertions(+)
target/ppc/cpu.h +2 -0
@@ -1314,6 +1314,7 @@ int ppc_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int size, int rw,#if !defined(CONFIG_USER_ONLY )void ppc_store_sdr1 (CPUPPCState *env,target_ulong value); +void ppc_store_ptcr (CPUPPCState *env,target_ulong value);#endif /* !defined(CONFIG_USER_ONLY) */ void ppc_store_msr (CPUPPCState *env,target_ulong value);
@@ -1605,6 +1606,7 @@ void ppc_compat_add_property(Object *obj, const char *name,#define SPR_BOOKE_GIVOR13 (0x1BC)#define SPR_BOOKE_GIVOR14 (0x1BD)#define SPR_TIR (0x1BE) +#define SPR_PTCR (0x1D0)#define SPR_BOOKE_SPEFSCR (0x200)#define SPR_Exxx_BBEAR (0x201)#define SPR_Exxx_BBTAR (0x202)
target/ppc/helper.h +1 -0
@@ -709,6 +709,7 @@ DEF_HELPER_FLAGS_1(load_601_rtcu, TCG_CALL_NO_RWG, tl, env)#if !defined(CONFIG_USER_ONLY )#if defined(TARGET_PPC64 ) DEF_HELPER_FLAGS_1(load_purr, TCG_CALL_NO_RWG, tl, env) +DEF_HELPER_2(store_ptcr, void, env, tl)#endif DEF_HELPER_2(store_sdr1, void, env, tl)DEF_HELPER_2 (store_pidr, void, env, tl)
target/ppc/misc_helper.c +12 -0
@@ -88,6 +88,18 @@ void helper_store_sdr1(CPUPPCState *env, target_ulong val) } } +#if defined(TARGET_PPC64 ) +void helper_store_ptcr (CPUPPCState *env,target_ulong val) +{ +PowerPCCPU *cpu =ppc_env_get_cpu (env); + +if (env->spr[SPR_PTCR ] != val) { +ppc_store_ptcr (env, val); +tlb_flush (CPU (cpu)); + } +} +#endif /* defined(TARGET_PPC64) */ +void helper_store_pidr (CPUPPCState *env,target_ulong val) {PowerPCCPU *cpu =ppc_env_get_cpu (env);
target/ppc/mmu-hash64.h +6 -0
@@ -98,6 +98,12 @@ void ppc_hash64_update_rmls(CPUPPCState *env);#define HPTE64_V_1TB_SEG 0x4000000000000000ULL#define HPTE64_V_VRMA_MASK 0x4001ffffff000000ULL +/* +* Partition table definitions +*/ +#define PTCR_PTAB 0x0FFFFFFFFFFFF000ULL/* Partition Table Base */ +#define PTCR_PTAS 0x000000000000001FULL/* Partition Table Size */ +static inline hwaddr ppc_hash64_hpt_base (PowerPCCPU *cpu) {return cpu->env.spr[SPR_SDR1 ] &SDR_64_HTABORG ;
target/ppc/mmu_helper.c +28 -0
@@ -2029,6 +2029,34 @@ void ppc_store_sdr1(CPUPPCState *env, target_ulong value) env->spr[SPR_SDR1 ] = value; } +#if defined(TARGET_PPC64 ) +void ppc_store_ptcr (CPUPPCState *env,target_ulong value) +{ +PowerPCCPU *cpu =ppc_env_get_cpu (env); +qemu_log_mask (CPU_LOG_MMU ,"%s: " TARGET_FMT_lx"\n" , __func__, value); + +assert (!cpu->vhyp); + +if (env->mmu_model &POWERPC_MMU_V3 ) { +target_ulong ptcr_mask =PTCR_PTAB |PTCR_PTAS ; +target_ulong ptas = value &PTCR_PTAS ; + +if (value & ~ptcr_mask) { +error_report ("Invalid bits 0x" TARGET_FMT_lx" set in PTCR" , + value & ~ptcr_mask); + value &= ptcr_mask; + } +if (ptas >28 ) { +error_report ("Invalid PTAS 0x" TARGET_FMT_lx" stored in PTCR" , + ptas); +return ; + } + } + env->spr[SPR_PTCR ] = value; +} + +#endif /* defined(TARGET_PPC64) */ +/* Segment registers load and store */ target_ulong helper_load_sr (CPUPPCState *env,target_ulong sr_num) {
target/ppc/translate.c +3 -0
@@ -7130,6 +7130,9 @@ void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,if (env->spr_cb[SPR_SDR1 ].name) {/* SDR1 Exists */ cpu_fprintf (f," SDR1 " TARGET_FMT_lx" " , env->spr[SPR_SDR1 ]); } +if (env->spr_cb[SPR_PTCR ].name) {/* PTCR Exists */ +cpu_fprintf (f," PTCR " TARGET_FMT_lx" " , env->spr[SPR_PTCR ]); + }cpu_fprintf (f," DAR " TARGET_FMT_lx" DSISR " TARGET_FMT_lx"\n" , env->spr[SPR_DAR ], env->spr[SPR_DSISR ]);break ;
target/ppc/translate_init.c +18 -0
@@ -417,6 +417,11 @@ static void spr_write_hior(DisasContext *ctx, int sprn, int gprn)tcg_gen_st_tl (t0, cpu_env, offsetof(CPUPPCState , excp_prefix));tcg_temp_free (t0); } +static void spr_write_ptcr (DisasContext *ctx,int sprn,int gprn) +{ +gen_helper_store_ptcr (cpu_env, cpu_gpr[gprn]); +} +#endif #endif
@@ -8164,6 +8169,18 @@ static void gen_spr_power8_rpr(CPUPPCState *env)#endif } +/* Page Table */ +static void gen_spr_power9_ptcr (CPUPPCState *env) +{ +#if !defined(CONFIG_USER_ONLY ) +spr_register_hv (env,SPR_PTCR ,"PTCR" , +SPR_NOACCESS ,SPR_NOACCESS , +SPR_NOACCESS ,SPR_NOACCESS , + &spr_read_generic, &spr_write_ptcr, +0x00000000 ); +#endif +} +static void init_proc_book3s_common (CPUPPCState *env) {gen_spr_ne_601 (env);
@@ -8756,6 +8773,7 @@ static void init_proc_POWER9(CPUPPCState *env)gen_spr_power8_ic (env);gen_spr_power8_book4 (env);gen_spr_power8_rpr (env); +gen_spr_power9_ptcr (env);/* POWER9 Specific registers */ spr_register_kvm(env, SPR_TIDR, "TIDR", NULL, NULL,
Signature · 1 line
2.13.6
PATCH 2/3 target/ppc: add hash MMU support on POWER9 for PowerNV only
In reply to Cédric Le GoaterThe HPTE bits definitions are slightly modified in ISA v3.0. Let's add some helpers to hide the differences in the hash MMU code.
On a POWER9 processor, the Partition Table is composed of a pair of doublewords per partition. The first doubleword indicates whether the partition uses HPT or Radix Trees translation and contains the address of the host's translation table structure and size.
The first doubleword of the PTCR holds the Hash Page Table base address for the host when the hash MMU is in use. Also add an helper to retrieve the HPT base address depending on the MMU revision.
--- hw/ppc/spapr_hcall.c | 5 +++-- target/ppc/mmu-hash64.c | 48 +++++++++++++++++++++++++++++++++++++++--------- target/ppc/mmu-hash64.h | 34 ++++++++++++++++++++++++++++++++-- 3 files changed, 74 insertions(+), 13 deletions(-)
hw/ppc/spapr_hcall.c +3 -2
@@ -94,7 +94,7 @@ static target_ulong h_enter(PowerPCCPU *cpu, sPAPRMachineState *spapr,return H_PARAMETER ; } - raddr = (ptel &HPTE64_R_RPN ) & ~((1ULL << apshift) -1 ); + raddr = (ptel &ppc_hash64_hpte_r_rpn (cpu)) & ~((1ULL << apshift) -1 );if (is_ram_address (spapr, raddr)) {/* Regular RAM - should have WIMG=0010 */
@@ -586,7 +586,8 @@ static int rehash_hpte(PowerPCCPU *cpu, base_pg_shift =ppc_hash64_hpte_page_shift_noslb (cpu, pte0, pte1);assert (base_pg_shift);/* H_ENTER shouldn't allow a bad encoding */ - avpn =HPTE64_V_AVPN_VAL (pte0) & ~(((1ULL << base_pg_shift) -1 ) >>23 ); + avpn =ppc_hash64_hpte_v_avpn_val (cpu, pte0) & + ~(((1ULL << base_pg_shift) -1 ) >>23 );if (pte0 &HPTE64_V_SECONDARY ) { pteg = ~pteg;
target/ppc/mmu-hash64.c +39 -9
102 lines not on this page · raw message
target/ppc/mmu-hash64.h +32 -2
@@ -69,8 +69,12 @@ void ppc_hash64_update_rmls(CPUPPCState *env);#define HPTE64_V_SSIZE_SHIFT 62#define HPTE64_V_AVPN_SHIFT 7#define HPTE64_V_AVPN 0x3fffffffffffff80ULL +#define HPTE64_V_AVPN_3_0 0x000fffffffffff80ULL#define HPTE64_V_AVPN_VAL (x) (((x) & HPTE64_V_AVPN) >> HPTE64_V_AVPN_SHIFT) +#define HPTE64_V_AVPN_VAL_3_0 (x) \ + (((x) & HPTE64_V_AVPN_3_0) >> HPTE64_V_AVPN_SHIFT)#define HPTE64_V_COMPARE (x, y) (!(((x) ^ (y)) & 0xffffffffffffff83ULL)) +#define HPTE64_V_COMPARE_3_0 (x, y) (!(((x) ^ (y)) & 0x3fffffffffffff83ULL))#define HPTE64_V_BOLTED 0x0000000000000010ULL#define HPTE64_V_LARGE 0x0000000000000004ULL#define HPTE64_V_SECONDARY 0x0000000000000002ULL
@@ -81,6 +85,7 @@ void ppc_hash64_update_rmls(CPUPPCState *env);#define HPTE64_R_KEY_HI 0x3000000000000000ULL#define HPTE64_R_RPN_SHIFT 12#define HPTE64_R_RPN 0x0ffffffffffff000ULL +#define HPTE64_R_RPN_3_0 0x01fffffffffff000ULL#define HPTE64_R_FLAGS 0x00000000000003ffULL#define HPTE64_R_PP 0x0000000000000003ULL#define HPTE64_R_N 0x0000000000000004ULL
@@ -104,9 +109,34 @@ void ppc_hash64_update_rmls(CPUPPCState *env);#define PTCR_PTAB 0x0FFFFFFFFFFFF000ULL/* Partition Table Base */ #define PTCR_PTAS 0x000000000000001FULL/* Partition Table Size */ +static inline target_ulong ppc_hash64_hpte_r_rpn (PowerPCCPU *cpu) +{ +CPUPPCState *env = &cpu->env; + +return env->mmu_model &POWERPC_MMU_V3 ?HPTE64_R_RPN_3_0 :HPTE64_R_RPN ; +} + +static inline target_ulong ppc_hash64_hpte_v_avpn (PowerPCCPU *cpu) +{ +CPUPPCState *env = &cpu->env; + +return env->mmu_model &POWERPC_MMU_V3 ?HPTE64_V_AVPN_3_0 :HPTE64_V_AVPN ; +} + +static inline target_ulong ppc_hash64_hpte_v_avpn_val (PowerPCCPU *cpu, +target_ulong pte0) +{ +CPUPPCState *env = &cpu->env; + +return env->mmu_model &POWERPC_MMU_V3 ? +HPTE64_V_AVPN_VAL_3_0 (pte0) :HPTE64_V_AVPN_VAL (pte0); +} + +hwaddr ppc_hash64_hpt_reg (PowerPCCPU *cpu); +static inline hwaddr ppc_hash64_hpt_base (PowerPCCPU *cpu) { -return cpu->env.spr[SPR_SDR1 ] &SDR_64_HTABORG ; +return ppc_hash64_hpt_reg (cpu) &SDR_64_HTABORG ; }static inline hwaddr ppc_hash64_hpt_mask (PowerPCCPU *cpu)
@@ -116,7 +146,7 @@ static inline hwaddr ppc_hash64_hpt_mask(PowerPCCPU *cpu)PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp);return vhc->hpt_mask (cpu->vhyp); } -return (1ULL << ((cpu->env.spr[SPR_SDR1 ] &SDR_64_HTABSIZE ) +18 -7 )) -1 ; +return (1ULL << ((ppc_hash64_hpt_reg (cpu) &SDR_64_HTABSIZE ) +18 -7 )) -1 ; }struct ppc_hash_pte64 {
Signature · 1 line
2.13.6
PATCH 3/3 target/ppc: generalize check on radix when in HV mode
In reply to Cédric Le GoaterOn a POWER9 processor, the first doubleword of the PTCR indicates whether the partition uses HPT or Radix Trees translation. Use that bit to check for radix mode on powernv QEMU machines.
--- target/ppc/mmu-book3s-v3.c | 17 ++++++++++++++++- target/ppc/mmu-book3s-v3.h | 8 +------- target/ppc/mmu-hash64.h | 1 + target/ppc/mmu_helper.c | 4 ++-- target/ppc/translate_init.c | 2 +- 5 files changed, 21 insertions(+), 11 deletions(-)
target/ppc/mmu-book3s-v3.c +16 -1
@@ -24,10 +24,25 @@#include "mmu-book3s-v3.h" #include "mmu-radix64.h" +bool ppc64_radix (PowerPCCPU *cpu) +{ +CPUPPCState *env = &cpu->env; + +if (msr_hv) { +return ldq_phys (CPU (cpu)->as, cpu->env.spr[SPR_PTCR ] & +PTCR_PTAB ) &PTCR_PTAB_HR ; + }else { +PPCVirtualHypervisorClass *vhc = +PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp); + +return !!(vhc->get_patbe (cpu->vhyp) &PATBE1_GR ); + } +} +int ppc64_v3_handle_mmu_fault (PowerPCCPU *cpu,vaddr eaddr,int rwx,int mmu_idx) { -if (ppc64_radix_guest (cpu)) {/* Guest uses radix */ +if (ppc64_radix (cpu)) {/* radix mode */ return ppc_radix64_handle_mmu_fault (cpu, eaddr, rwx, mmu_idx); }else {/* Guest uses hash */ return ppc_hash64_handle_mmu_fault (cpu, eaddr, rwx, mmu_idx);
target/ppc/mmu-book3s-v3.h +1 -7
@@ -37,13 +37,7 @@ static inline bool ppc64_use_proc_tbl(PowerPCCPU *cpu)return !!(cpu->env.spr[SPR_LPCR ] &LPCR_UPRT ); } -static inline bool ppc64_radix_guest (PowerPCCPU *cpu) -{ -PPCVirtualHypervisorClass *vhc = -PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp); - -return !!(vhc->get_patbe (cpu->vhyp) &PATBE1_GR ); -} +bool ppc64_radix (PowerPCCPU *cpu);int ppc64_v3_handle_mmu_fault (PowerPCCPU *cpu,vaddr eaddr,int rwx,int mmu_idx);
target/ppc/mmu-hash64.h +1 -0
@@ -106,6 +106,7 @@ void ppc_hash64_update_rmls(CPUPPCState *env);/* * Partition table definitions */ +#define PTCR_PTAB_HR PPC_BIT(0)/* 1:Host Radix 0:HPT */ #define PTCR_PTAB 0x0FFFFFFFFFFFF000ULL/* Partition Table Base */ #define PTCR_PTAS 0x000000000000001FULL/* Partition Table Size */
target/ppc/mmu_helper.c +2 -2
@@ -1286,7 +1286,7 @@ void dump_mmu(FILE *f, fprintf_function cpu_fprintf, CPUPPCState *env)dump_slb (f, cpu_fprintf,ppc_env_get_cpu (env));break ;case POWERPC_MMU_VER_3_00 : -if (ppc64_radix_guest (ppc_env_get_cpu (env))) { +if (ppc64_radix (ppc_env_get_cpu (env))) {/* TODO - Unsupported */ }else {dump_slb (f, cpu_fprintf,ppc_env_get_cpu (env));
@@ -1432,7 +1432,7 @@ hwaddr ppc_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)case POWERPC_MMU_VER_2_07 :return ppc_hash64_get_phys_page_debug (cpu, addr);case POWERPC_MMU_VER_3_00 : -if (ppc64_radix_guest (ppc_env_get_cpu (env))) { +if (ppc64_radix (ppc_env_get_cpu (env))) {return ppc_radix64_get_phys_page_debug (cpu, addr); }else {return ppc_hash64_get_phys_page_debug (cpu, addr);
target/ppc/translate_init.c +1 -1
@@ -8965,7 +8965,7 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp)* KVM but not under TCG. Update the default LPCR to keep new * CPUs in sync when radix is enabled. */ -if (ppc64_radix_guest (cpu)) { +if (ppc64_radix (cpu)) { lpcr->default_value |=LPCR_UPRT |LPCR_GTSE ; }else { lpcr->default_value &= ~(LPCR_UPRT |LPCR_GTSE );
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH 1/3] target/ppc: add basic support for PTCR on POWER9
In reply to Cédric Le GoaterQuoted 87 lines · Cédric Le Goater
The Partition Table Control Register (PTCR) is a hypervisor privileged
SPR. It contains the host real address of the Partition Table and its size.Signed-off-by Cédric Le Goater <[email protected]>--- target/ppc/cpu.h | 2 ++ target/ppc/helper.h | 1 + target/ppc/misc_helper.c | 12 ++++++++++++ target/ppc/mmu-hash64.h | 6 ++++++ target/ppc/mmu_helper.c | 28 ++++++++++++++++++++++++++++ target/ppc/translate.c | 3 +++ target/ppc/translate_init.c | 18 ++++++++++++++++++ 7 files changed, 70 insertions(+)target/ppc/cpu.h +2
-0@@ -1314,6 +1314,7 @@ int ppc_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int size, int rw, #if !defined(CONFIG_USER_ONLY) void ppc_store_sdr1 (CPUPPCState *env, target_ulong value); +void ppc_store_ptcr (CPUPPCState *env,target_ulong value);#endif /* !defined(CONFIG_USER_ONLY) */ void ppc_store_msr (CPUPPCState *env,target_ulong value);@@ -1605,6 +1606,7 @@ void ppc_compat_add_property(Object *obj, const char *name,#define SPR_BOOKE_GIVOR13 (0x1BC)#define SPR_BOOKE_GIVOR14 (0x1BD)#define SPR_TIR (0x1BE) +#define SPR_PTCR (0x1D0)#define SPR_BOOKE_SPEFSCR (0x200)#define SPR_Exxx_BBEAR (0x201)#define
SPR_Exxx_BBTAR(0x202)target/ppc/helper.h +1
-0@@ -709,6 +709,7 @@ DEF_HELPER_FLAGS_1(load_601_rtcu, TCG_CALL_NO_RWG, tl, env)#if !defined(CONFIG_USER_ONLY )#if defined(TARGET_PPC64 ) DEF_HELPER_FLAGS_1(load_purr, TCG_CALL_NO_RWG, tl, env) +DEF_HELPER_2(store_ptcr, void, env, tl)#endif DEF_HELPER_2 (store_sdr1, void, env, tl)
DEF_HELPER_2(store_pidr, void, env, tl)target/ppc/misc_helper.c +12
-0@@ -88,6 +88,18 @@ void helper_store_sdr1(CPUPPCState *env, target_ulong val) } } +#if defined(TARGET_PPC64 ) +void helper_store_ptcr (CPUPPCState *env,target_ulong val) +{ +PowerPCCPU *cpu =ppc_env_get_cpu (env); + +if (env->spr[SPR_PTCR ] != val) { +ppc_store_ptcr (env, val); +tlb_flush (CPU (cpu)); + } +} +#endif /* defined(TARGET_PPC64) */ +void helper_store_pidr (CPUPPCState *env,target_ulong val) {PowerPCCPU *cpu = ppc_env_get_cpu(env);target/ppc/mmu-hash64.h +4
-0@@ -98,6 +98,12 @@ void ppc_hash64_update_rmls(CPUPPCState *env);#define HPTE64_V_1TB_SEG 0x4000000000000000ULL#define HPTE64_V_VRMA_MASK 0x4001ffffff000000ULL +/* +* Partition table definitions +*/ +#define PTCR_PTAB 0x0FFFFFFFFFFFF000ULL/* Partition
Quoted 4 lines
Table Base */
+#definePTCR_PTAS0x000000000000001FULL/* Partition
Table Size */
+
s/PTCR_PTAB/PTCR_PATB
s/PTCR_PTAS/PTCR_PATS
To match the ISA?
Quoted 34 lines
static inline hwaddr
ppc_hash64_hpt_base(PowerPCCPU *cpu){ return cpu->env.spr[SPR_SDR1] & SDR_64_HTABORG;target/ppc/mmu_helper.c +19
-0@@ -2029,6 +2029,34 @@ void ppc_store_sdr1(CPUPPCState *env, target_ulong value) env->spr[SPR_SDR1] = value; } +#if defined(TARGET_PPC64) +void ppc_store_ptcr(CPUPPCState *env, target_ulong value) +{ + PowerPCCPU *cpu = ppc_env_get_cpu(env); + qemu_log_mask(CPU_LOG_MMU, "%s: " TARGET_FMT_lx "\n", __func__, value); + + assert(!cpu->vhyp); + + if (env->mmu_model & POWERPC_MMU_V3) { + target_ulong ptcr_mask = PTCR_PTAB | PTCR_PTAS; + target_ulong ptas = value & PTCR_PTAS; + + if (value & ~ptcr_mask) { + error_report("Invalid bits 0x"TARGET_FMT_lx" set in PTCR", + value & ~ptcr_mask); + value &= ptcr_mask; + } + if (ptas > 28) { + error_report("Invalid PTAS 0x" TARGET_FMT_lx" stored inPTCR",
target/ppc/mmu_helper.c void ppc_store_sdr1(CPUPPCState *env, target_ulong value) · line 2054
Quoted 4 lines
target/ppc/mmu_helper.c +4
-0+ ptas); +return ; + } + }
Should we throw some error if the ptcr is being accessed on a non- power9 machine?
Quoted 72 lines
target/ppc/mmu_helper.c +5
-0+ env->spr[SPR_PTCR] = value; +} + +#endif /* defined(TARGET_PPC64) */ +/* Segment registers load and store */ target_ulong helper_load_sr (CPUPPCState *env,target_ulong sr_num) {target/ppc/translate.c +3
-0@@ -7130,6 +7130,9 @@ void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf, if (env->spr_cb[SPR_SDR1].name) { /* SDR1 Exists */ cpu_fprintf(f, " SDR1 " TARGET_FMT_lx " ", env- >spr[SPR_SDR1]); } +if (env->spr_cb[SPR_PTCR ].name) {/* PTCR Exists */ +cpu_fprintf (f," PTCR " TARGET_FMT_lx" " , env- >spr[SPR_PTCR]); + }cpu_fprintf(f, " DAR "
TARGET_FMT_lx" DSISR "TARGET_FMT_lx"\n",env->spr[SPR_DAR], env->spr[SPR_DSISR]); break;target/ppc/translate_init.c +17
-0@@ -417,6 +417,11 @@ static void spr_write_hior(DisasContext *ctx, int sprn, int gprn)tcg_gen_st_tl (t0 ,cpu_env ,offsetof (CPUPPCState ,excp_prefix ));tcg_temp_free (t0); } +static void spr_write_ptcr (DisasContext *ctx,int sprn,int gprn) +{ +gen_helper_store_ptcr (cpu_env, cpu_gpr[gprn]); +} +#endif #endif @@ -8164,6 +8169,18 @@ static void gen_spr_power8_rpr(CPUPPCState *env)#endif } +/* Page Table */ +static void gen_spr_power9_ptcr (CPUPPCState *env) +{ +#if !defined(CONFIG_USER_ONLY ) +spr_register_hv (env,SPR_PTCR ,"PTCR" , +SPR_NOACCESS ,SPR_NOACCESS , +SPR_NOACCESS ,SPR_NOACCESS , + &spr_read_generic, &spr_write_ptcr, +0x00000000 ); +#endif +} +static void init_proc_book3s_common (CPUPPCState *env) {gen_spr_ne_601(env);target/ppc/translate_init.c +1
-0@@ -8756,6 +8773,7 @@ static void init_proc_POWER9(CPUPPCState *env)gen_spr_power8_ic (env);gen_spr_power8_book4 (env);gen_spr_power8_rpr (env); +gen_spr_power9_ptcr (env);/* POWER9 Specific registers */ spr_register_kvm(env, SPR_TIDR, "TIDR", NULL, NULL,
Re: [Qemu-devel] [PATCH 1/3] target/ppc: add basic support for PTCR on POWER9
Quoted 86 lines · Suraj Jitindar Singh
Quoted 85 lines · Cédric Le Goater
The Partition Table Control Register (PTCR) is a hypervisor privileged
SPR. It contains the host real address of the Partition Table and its
size.Signed-off-by Cédric Le Goater <[email protected]>--- target/ppc/cpu.h | 2 ++ target/ppc/helper.h | 1 + target/ppc/misc_helper.c | 12 ++++++++++++ target/ppc/mmu-hash64.h | 6 ++++++ target/ppc/mmu_helper.c | 28 ++++++++++++++++++++++++++++ target/ppc/translate.c | 3 +++ target/ppc/translate_init.c | 18 ++++++++++++++++++ 7 files changed, 70 insertions(+)target/ppc/cpu.h +1
-0@@ -1314,6 +1314,7 @@ int ppc_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int size, int rw, #if !defined(CONFIG_USER_ONLY) void ppc_store_sdr1 (CPUPPCState *env, target_ulong value); +void ppc_store_ptcr (CPUPPCState *env,target_ulong value);#endif /* !defined(CONFIG_USER_ONLY) */ void ppc_store_msr (CPUPPCState *env,target_ulong value);@@ -1605,6 +1606,7 @@ void ppc_compat_add_property(Object *obj,const
char *name,#define SPR_BOOKE_GIVOR13 (0x1BC) #define SPR_BOOKE_GIVOR14 (0x1BD) #define SPR_TIR (0x1BE)target/ppc/cpu.h +1
-0+#define SPR_PTCR (0x1D0)#define SPR_BOOKE_SPEFSCR (0x200)#define SPR_Exxx_BBEAR (0x201)#define SPR_Exxx_BBTAR (0x202)target/ppc/helper.h +1
-0@@ -709,6 +709,7 @@ DEF_HELPER_FLAGS_1(load_601_rtcu, TCG_CALL_NO_RWG, tl, env)#if !defined(CONFIG_USER_ONLY )#if defined(TARGET_PPC64 ) DEF_HELPER_FLAGS_1(load_purr, TCG_CALL_NO_RWG, tl, env) +DEF_HELPER_2(store_ptcr, void, env, tl)#endif DEF_HELPER_2 (store_sdr1, void, env, tl)
DEF_HELPER_2(store_pidr, void, env, tl)target/ppc/misc_helper.c +12
-0@@ -88,6 +88,18 @@ void helper_store_sdr1(CPUPPCState *env, target_ulong val) } } +#if defined(TARGET_PPC64 ) +void helper_store_ptcr (CPUPPCState *env,target_ulong val) +{ +PowerPCCPU *cpu =ppc_env_get_cpu (env); + +if (env->spr[SPR_PTCR ] != val) { +ppc_store_ptcr (env, val); +tlb_flush (CPU (cpu)); + } +} +#endif /* defined(TARGET_PPC64) */ +void helper_store_pidr (CPUPPCState *env,target_ulong val) {PowerPCCPU *cpu = ppc_env_get_cpu(env);target/ppc/mmu-hash64.h +0
-0@@ -98,6 +98,12 @@ void ppc_hash64_update_rmls(CPUPPCState *env);#define HPTE64_V_1TB_SEG 0x4000000000000000ULL#define HPTE64_V_VRMA_MASK 0x4001ffffff000000ULL
Quoted 12 lines
Quoted 8 lines
target/ppc/mmu-hash64.h +4
-0+/* +* Partition table definitions +*/ +#define PTCR_PTAB 0x0FFFFFFFFFFFF000ULL/* Partition Table Base */
+#definePTCR_PTAS0x000000000000001FULL/* Partition
Table Size */
+s/PTCR_PTAB/PTCR_PATB
s/PTCR_PTAS/PTCR_PATS
To match the ISA?
Also these should be in target/ppc/mmu-book3s-v3.h, they're not hash specific
Quoted 122 lines
Quoted 37 lines
static inline hwaddr
ppc_hash64_hpt_base(PowerPCCPU *cpu){ return cpu->env.spr[SPR_SDR1] & SDR_64_HTABORG;target/ppc/mmu_helper.c +14
-0@@ -2029,6 +2029,34 @@ void ppc_store_sdr1(CPUPPCState *env, target_ulong value) env->spr[SPR_SDR1] = value; } +#if defined(TARGET_PPC64) +void ppc_store_ptcr(CPUPPCState *env, target_ulong value) +{ + PowerPCCPU *cpu = ppc_env_get_cpu(env); + qemu_log_mask(CPU_LOG_MMU, "%s: " TARGET_FMT_lx "\n", __func__, value); + + assert(!cpu->vhyp); + + if (env->mmu_model & POWERPC_MMU_V3) { + target_ulong ptcr_mask = PTCR_PTAB | PTCR_PTAS; + target_ulong ptas = value & PTCR_PTAS; + + if (value & ~ptcr_mask) { + error_report("Invalid bits 0x"TARGET_FMT_lx" set inPTCR",
target/ppc/mmu_helper.c +5
-0+ value & ~ptcr_mask); + value &= ptcr_mask; + } + if (ptas > 28) { + error_report("Invalid PTAS 0x" TARGET_FMT_lx" storedin
PTCR",target/ppc/mmu_helper.c void ppc_store_sdr1(CPUPPCState *env, target_ulong value) · line 2054
Quoted 4 lines
target/ppc/mmu_helper.c +4
-0+ ptas); +return ; + } + }Should we throw some error if the ptcr is being accessed on a non- power9 machine?
Quoted 77 lines
target/ppc/mmu_helper.c +5
-0+ env->spr[SPR_PTCR] = value; +} + +#endif /* defined(TARGET_PPC64) */ +/* Segment registers load and store */ target_ulong helper_load_sr (CPUPPCState *env,target_ulong sr_num) {target/ppc/translate.c +2
-0@@ -7130,6 +7130,9 @@ void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf, if (env->spr_cb[SPR_SDR1].name) { /* SDR1 Exists */cpu_fprintf (f," SDR1 " TARGET_FMT_lx" " , env- > spr[SPR_SDR1]); } +if (env->spr_cb[SPR_PTCR ].name) {/* PTCR Exists */ + cpu_fprintf(f, " PTCR " TARGET_FMT_lx " ", env-Quoted 1 line
spr[SPR_PTCR]);
+ }
cpu_fprintf(f, " DAR "TARGET_FMT_lx" DSISR "TARGET_FMT_lx"\n",env->spr[SPR_DAR], env->spr[SPR_DSISR]); break;target/ppc/translate_init.c +5
-0@@ -417,6 +417,11 @@ static void spr_write_hior(DisasContext *ctx, int sprn, int gprn)tcg_gen_st_tl (t0 ,cpu_env ,offsetof (CPUPPCState ,excp_prefix )); tcg_temp_free(t0); } +static void spr_write_ptcr (DisasContext *ctx,int sprn,int gprn) +{ +gen_helper_store_ptcr (cpu_env, cpu_gpr[gprn]); +} +#endif #endif
target/ppc/translate_init.c +12
-0@@ -8164,6 +8169,18 @@ static void gen_spr_power8_rpr(CPUPPCState *env)#endif } +/* Page Table */ +static void gen_spr_power9_ptcr (CPUPPCState *env) +{ +#if !defined(CONFIG_USER_ONLY ) +spr_register_hv (env,SPR_PTCR ,"PTCR" , +SPR_NOACCESS ,SPR_NOACCESS , +SPR_NOACCESS ,SPR_NOACCESS , + &spr_read_generic, &spr_write_ptcr, +0x00000000 ); +#endif +} +static void init_proc_book3s_common (CPUPPCState *env) {gen_spr_ne_601(env);target/ppc/translate_init.c +1
-0@@ -8756,6 +8773,7 @@ static void init_proc_POWER9(CPUPPCState *env)gen_spr_power8_ic (env);gen_spr_power8_book4 (env);gen_spr_power8_rpr (env); +gen_spr_power9_ptcr (env);/* POWER9 Specific registers */ spr_register_kvm(env,
SPR_TIDR, "TIDR", NULL, NULL,
Re: [Qemu-devel] [PATCH 3/3] target/ppc: generalize check on radix when in HV mode
In reply to Cédric Le GoaterQuoted 3 lines · Cédric Le Goater
On a POWER9 processor, the first doubleword of the PTCR indicates whether the partition uses HPT or Radix Trees translation. Use that bit to check for radix mode on powernv QEMU machines.
The above isn't quite right.
On a POWER9 processor, the first doubleword of the partition table entry (as pointed to by the PTCR) indicates whether the host uses HPT or Radix Tree translation for that partition.
Quoted 15 lines
Signed-off-by Cédric Le Goater <[email protected]>--- target/ppc/mmu-book3s-v3.c | 17 ++++++++++++++++- target/ppc/mmu-book3s-v3.h | 8 +------- target/ppc/mmu-hash64.h | 1 + target/ppc/mmu_helper.c | 4 ++-- target/ppc/translate_init.c | 2 +- 5 files changed, 21 insertions(+), 11 deletions(-)target/ppc/mmu-book3s-v3.c +0
-0
target/ppc/mmu-book3s-v3.c line 31
Quoted 8 lines
target/ppc/mmu-book3s-v3.c +5
-0@@ -24,10 +24,25 @@#include "mmu-book3s-v3.h" #include "mmu-radix64.h" +bool ppc64_radix (PowerPCCPU *cpu) +{ +CPUPPCState *env = &cpu->env; + +if (msr_hv) {
I would prefer something like:
uint64_t prtbe0 = ldq_phys(...);
return prtbe0 & HR;
Quoted 45 lines
target/ppc/mmu-book3s-v3.c +11
-1+return ldq_phys (CPU (cpu)->as, cpu->env.spr[SPR_PTCR ] & +PTCR_PTAB ) &PTCR_PTAB_HR ; + }else { +PPCVirtualHypervisorClass *vhc = +PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp); + +return !!(vhc->get_patbe (cpu->vhyp) &PATBE1_GR ); + } +} +int ppc64_v3_handle_mmu_fault (PowerPCCPU *cpu,vaddr eaddr,int rwx,int mmu_idx) { -if (ppc64_radix_guest (cpu)) {/* Guest uses radix */ +if (ppc64_radix (cpu)) {/* radix mode */ return ppc_radix64_handle_mmu_fault (cpu, eaddr, rwx, mmu_idx); }else {/* Guest uses hash */ return ppc_hash64_handle_mmu_fault(cpu, eaddr, rwx,
mmu_idx);target/ppc/mmu-book3s-v3.h +1
-7@@ -37,13 +37,7 @@ static inline bool ppc64_use_proc_tbl(PowerPCCPU *cpu)return !!(cpu->env.spr[SPR_LPCR ] &LPCR_UPRT ); } -static inline bool ppc64_radix_guest (PowerPCCPU *cpu) -{ -PPCVirtualHypervisorClass *vhc = -PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp); - -return !!(vhc->get_patbe (cpu->vhyp) &PATBE1_GR ); -} +bool ppc64_radix (PowerPCCPU *cpu); int ppc64_v3_handle_mmu_fault(PowerPCCPU *cpu, vaddr eaddr, int rwx,int mmu_idx);target/ppc/mmu-hash64.h +0
-0
target/ppc/mmu-hash64.h void ppc_hash64_update_rmls(CPUPPCState *env); · line 109
Quoted 4 lines
target/ppc/mmu-hash64.h +1
-0@@ -106,6 +106,7 @@ void ppc_hash64_update_rmls(CPUPPCState *env);/* * Partition table definitions */ +#define PTCR_PTAB_HR PPC_BIT(0)/* 1:Host
This isn't a bit in the partition table register, it is a bit in the partition table entry. It should be defined in target/ppc/mmu-book3s- v3.h as part of "/* Partition Table Entry Fields */"
Also to follow the naming, please call it:
#define PATBE0_HR PPC_BIT(0)
:)
Quoted 46 lines
Radix 0:HPT */
#definePTCR_PTAB0x0FFFFFFFFFFFF000ULL/* Partition
Table Base */
#definePTCR_PTAS0x000000000000001FULL/* Partition
Table Size */target/ppc/mmu_helper.c +1
-1@@ -1286,7 +1286,7 @@ void dump_mmu(FILE *f, fprintf_function cpu_fprintf, CPUPPCState *env)dump_slb (f, cpu_fprintf,ppc_env_get_cpu (env));break ;case POWERPC_MMU_VER_3_00 : -if (ppc64_radix_guest (ppc_env_get_cpu (env))) { +if (ppc64_radix (ppc_env_get_cpu (env))) {/* TODO - Unsupported */ }else {dump_slb(f, cpu_fprintf, ppc_env_get_cpu(env));target/ppc/mmu_helper.c +1
-1@@ -1432,7 +1432,7 @@ hwaddr ppc_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)case POWERPC_MMU_VER_2_07 :return ppc_hash64_get_phys_page_debug (cpu, addr);case POWERPC_MMU_VER_3_00 : -if (ppc64_radix_guest (ppc_env_get_cpu (env))) { +if (ppc64_radix (ppc_env_get_cpu (env))) {return ppc_radix64_get_phys_page_debug (cpu, addr); }else {return ppc_hash64_get_phys_page_debug(cpu, addr);target/ppc/translate_init.c +0
-0@@ -8965,7 +8965,7 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) * KVM but not under TCG. Update the default LPCR to keepnew
* CPUs in sync when radix is enabled.
*/target/ppc/translate_init.c +1
-1-if (ppc64_radix_guest (cpu)) { +if (ppc64_radix (cpu)) { lpcr->default_value |=LPCR_UPRT |LPCR_GTSE ; }else { lpcr->default_value &= ~(LPCR_UPRT |LPCR_GTSE );
Re: [Qemu-devel] [PATCH 1/3] target/ppc: add basic support for PTCR on POWER9
In reply to Suraj Jitindar SinghQuoted 84 lines · Suraj Jitindar Singh
Quoted 83 lines · Cédric Le Goater
The Partition Table Control Register (PTCR) is a hypervisor privileged
SPR. It contains the host real address of the Partition Table and its size.Signed-off-by Cédric Le Goater <[email protected]>--- target/ppc/cpu.h | 2 ++ target/ppc/helper.h | 1 + target/ppc/misc_helper.c | 12 ++++++++++++ target/ppc/mmu-hash64.h | 6 ++++++ target/ppc/mmu_helper.c | 28 ++++++++++++++++++++++++++++ target/ppc/translate.c | 3 +++ target/ppc/translate_init.c | 18 ++++++++++++++++++ 7 files changed, 70 insertions(+)target/ppc/cpu.h +2
-0@@ -1314,6 +1314,7 @@ int ppc_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int size, int rw, #if !defined(CONFIG_USER_ONLY) void ppc_store_sdr1 (CPUPPCState *env, target_ulong value); +void ppc_store_ptcr (CPUPPCState *env,target_ulong value);#endif /* !defined(CONFIG_USER_ONLY) */ void ppc_store_msr (CPUPPCState *env,target_ulong value);@@ -1605,6 +1606,7 @@ void ppc_compat_add_property(Object *obj, const char *name,#define SPR_BOOKE_GIVOR13 (0x1BC)#define SPR_BOOKE_GIVOR14 (0x1BD)#define SPR_TIR (0x1BE) +#define SPR_PTCR (0x1D0)#define SPR_BOOKE_SPEFSCR (0x200)#define SPR_Exxx_BBEAR (0x201)#define
SPR_Exxx_BBTAR(0x202)target/ppc/helper.h +1
-0@@ -709,6 +709,7 @@ DEF_HELPER_FLAGS_1(load_601_rtcu, TCG_CALL_NO_RWG, tl, env)#if !defined(CONFIG_USER_ONLY )#if defined(TARGET_PPC64 ) DEF_HELPER_FLAGS_1(load_purr, TCG_CALL_NO_RWG, tl, env) +DEF_HELPER_2(store_ptcr, void, env, tl)#endif DEF_HELPER_2 (store_sdr1, void, env, tl)
DEF_HELPER_2(store_pidr, void, env, tl)target/ppc/misc_helper.c +12
-0@@ -88,6 +88,18 @@ void helper_store_sdr1(CPUPPCState *env, target_ulong val) } } +#if defined(TARGET_PPC64 ) +void helper_store_ptcr (CPUPPCState *env,target_ulong val) +{ +PowerPCCPU *cpu =ppc_env_get_cpu (env); + +if (env->spr[SPR_PTCR ] != val) { +ppc_store_ptcr (env, val); +tlb_flush (CPU (cpu)); + } +} +#endif /* defined(TARGET_PPC64) */ +void helper_store_pidr (CPUPPCState *env,target_ulong val) {PowerPCCPU *cpu = ppc_env_get_cpu(env);target/ppc/mmu-hash64.h +0
-0@@ -98,6 +98,12 @@ void ppc_hash64_update_rmls(CPUPPCState *env);#define HPTE64_V_1TB_SEG 0x4000000000000000ULL#define HPTE64_V_VRMA_MASK 0x4001ffffff000000ULL
Quoted 12 lines
Quoted 8 lines
target/ppc/mmu-hash64.h +4
-0+/* +* Partition table definitions +*/ +#define PTCR_PTAB 0x0FFFFFFFFFFFF000ULL/* Partition Table Base */
+#definePTCR_PTAS0x000000000000001FULL/* Partition
Table Size */
+s/PTCR_PTAB/PTCR_PATB
s/PTCR_PTAS/PTCR_PATS
To match the ISA?
yes. My bad.
Quoted 33 lines
Quoted 33 lines
static inline hwaddr
ppc_hash64_hpt_base(PowerPCCPU *cpu){ return cpu->env.spr[SPR_SDR1] & SDR_64_HTABORG;target/ppc/mmu_helper.c +19
-0@@ -2029,6 +2029,34 @@ void ppc_store_sdr1(CPUPPCState *env, target_ulong value) env->spr[SPR_SDR1] = value; } +#if defined(TARGET_PPC64) +void ppc_store_ptcr(CPUPPCState *env, target_ulong value) +{ + PowerPCCPU *cpu = ppc_env_get_cpu(env); + qemu_log_mask(CPU_LOG_MMU, "%s: " TARGET_FMT_lx "\n", __func__, value); + + assert(!cpu->vhyp); + + if (env->mmu_model & POWERPC_MMU_V3) { + target_ulong ptcr_mask = PTCR_PTAB | PTCR_PTAS; + target_ulong ptas = value & PTCR_PTAS; + + if (value & ~ptcr_mask) { + error_report("Invalid bits 0x"TARGET_FMT_lx" set in PTCR", + value & ~ptcr_mask); + value &= ptcr_mask; + } + if (ptas > 28) { + error_report("Invalid PTAS 0x" TARGET_FMT_lx" stored in
Quoted 8 lines
target/ppc/mmu_helper.c void ppc_store_sdr1(CPUPPCState *env, target_ulong value) · line 2054
Quoted 5 lines
PTCR",
target/ppc/mmu_helper.c +4
-0+ ptas); +return ; + } + }Should we throw some error if the ptcr is being accessed on a non- power9 machine?
The SPR is only added for POWER9 processor. We should be fine.
Thanks,
C.
Quoted 73 lines
Quoted 73 lines
target/ppc/mmu_helper.c +5
-0+ env->spr[SPR_PTCR] = value; +} + +#endif /* defined(TARGET_PPC64) */ +/* Segment registers load and store */ target_ulong helper_load_sr (CPUPPCState *env,target_ulong sr_num) {target/ppc/translate.c +3
-0@@ -7130,6 +7130,9 @@ void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf, if (env->spr_cb[SPR_SDR1].name) { /* SDR1 Exists */ cpu_fprintf(f, " SDR1 " TARGET_FMT_lx " ", env- > spr[SPR_SDR1]); } +if (env->spr_cb[SPR_PTCR ].name) {/* PTCR Exists */ +cpu_fprintf (f," PTCR " TARGET_FMT_lx" " , env- > spr[SPR_PTCR]); + }cpu_fprintf(f, " DAR "
TARGET_FMT_lx" DSISR "TARGET_FMT_lx"\n",env->spr[SPR_DAR], env->spr[SPR_DSISR]); break;target/ppc/translate_init.c +17
-0@@ -417,6 +417,11 @@ static void spr_write_hior(DisasContext *ctx, int sprn, int gprn)tcg_gen_st_tl (t0 ,cpu_env ,offsetof (CPUPPCState ,excp_prefix ));tcg_temp_free (t0); } +static void spr_write_ptcr (DisasContext *ctx,int sprn,int gprn) +{ +gen_helper_store_ptcr (cpu_env, cpu_gpr[gprn]); +} +#endif #endif @@ -8164,6 +8169,18 @@ static void gen_spr_power8_rpr(CPUPPCState *env)#endif } +/* Page Table */ +static void gen_spr_power9_ptcr (CPUPPCState *env) +{ +#if !defined(CONFIG_USER_ONLY ) +spr_register_hv (env,SPR_PTCR ,"PTCR" , +SPR_NOACCESS ,SPR_NOACCESS , +SPR_NOACCESS ,SPR_NOACCESS , + &spr_read_generic, &spr_write_ptcr, +0x00000000 ); +#endif +} +static void init_proc_book3s_common (CPUPPCState *env) {gen_spr_ne_601(env);target/ppc/translate_init.c +1
-0@@ -8756,6 +8773,7 @@ static void init_proc_POWER9(CPUPPCState *env)gen_spr_power8_ic (env);gen_spr_power8_book4 (env);gen_spr_power8_rpr (env); +gen_spr_power9_ptcr (env);/* POWER9 Specific registers */ spr_register_kvm(env, SPR_TIDR, "TIDR", NULL, NULL,
Re: [Qemu-devel] [PATCH 1/3] target/ppc: add basic support for PTCR on POWER9
In reply to Suraj Jitindar SinghQuoted 12 lines · Suraj Jitindar Singh
Quoted 11 lines
Quoted 8 lines
target/ppc/mmu-hash64.h +4
-0+/* +* Partition table definitions +*/ +#define PTCR_PTAB 0x0FFFFFFFFFFFF000ULL/* Partition Table Base */
+#definePTCR_PTAS0x000000000000001FULL/* Partition
Table Size */
+s/PTCR_PTAB/PTCR_PATB
s/PTCR_PTAS/PTCR_PATS
To match the ISA?
Quoted 3 lines
Also these should be in
target/ppc/mmu-book3s-v3.h, they're not hash specific
OK. I Will fix that.
Thanks,
C.
Re: [Qemu-devel] [PATCH 3/3] target/ppc: generalize check on radix when in HV mode
In reply to Suraj Jitindar SinghQuoted 10 lines · Suraj Jitindar Singh
Quoted 3 lines · Cédric Le Goater
On a POWER9 processor, the first doubleword of the PTCR indicates whether the partition uses HPT or Radix Trees translation. Use that bit to check for radix mode on powernv QEMU machines.
The above isn't quite right.
On a POWER9 processor, the first doubleword of the partition table entry (as pointed to by the PTCR) indicates whether the host uses HPT or Radix Tree translation for that partition.
yes. This is better.
Quoted 26 lines
Quoted 15 lines
Signed-off-by Cédric Le Goater <[email protected]>--- target/ppc/mmu-book3s-v3.c | 17 ++++++++++++++++- target/ppc/mmu-book3s-v3.h | 8 +------- target/ppc/mmu-hash64.h | 1 + target/ppc/mmu_helper.c | 4 ++-- target/ppc/translate_init.c | 2 +- 5 files changed, 21 insertions(+), 11 deletions(-)target/ppc/mmu-book3s-v3.c +0
-0target/ppc/mmu-book3s-v3.c line 31
Quoted 8 lines
target/ppc/mmu-book3s-v3.c +5
-0@@ -24,10 +24,25 @@#include "mmu-book3s-v3.h" #include "mmu-radix64.h" +bool ppc64_radix (PowerPCCPU *cpu) +{ +CPUPPCState *env = &cpu->env; + +if (msr_hv) {I would prefer something like:
Quoted 2 lines
uint64_tprtbe0 =ldq_phys(...);
return prtbe0 & HR;
I will add a helper to retrieve the first partition table entry, as we need it in other places in patch 2.
Quoted 54 lines
Quoted 45 lines
target/ppc/mmu-book3s-v3.c +11
-1+return ldq_phys (CPU (cpu)->as, cpu->env.spr[SPR_PTCR ] & +PTCR_PTAB ) &PTCR_PTAB_HR ; + }else { +PPCVirtualHypervisorClass *vhc = +PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp); + +return !!(vhc->get_patbe (cpu->vhyp) &PATBE1_GR ); + } +} +int ppc64_v3_handle_mmu_fault (PowerPCCPU *cpu,vaddr eaddr,int rwx,int mmu_idx) { -if (ppc64_radix_guest (cpu)) {/* Guest uses radix */ +if (ppc64_radix (cpu)) {/* radix mode */ return ppc_radix64_handle_mmu_fault (cpu, eaddr, rwx, mmu_idx); }else {/* Guest uses hash */ return ppc_hash64_handle_mmu_fault(cpu, eaddr, rwx,
mmu_idx);target/ppc/mmu-book3s-v3.h +1
-7@@ -37,13 +37,7 @@ static inline bool ppc64_use_proc_tbl(PowerPCCPU *cpu)return !!(cpu->env.spr[SPR_LPCR ] &LPCR_UPRT ); } -static inline bool ppc64_radix_guest (PowerPCCPU *cpu) -{ -PPCVirtualHypervisorClass *vhc = -PPC_VIRTUAL_HYPERVISOR_GET_CLASS (cpu->vhyp); - -return !!(vhc->get_patbe (cpu->vhyp) &PATBE1_GR ); -} +bool ppc64_radix (PowerPCCPU *cpu); int ppc64_v3_handle_mmu_fault(PowerPCCPU *cpu, vaddr eaddr, int rwx,int mmu_idx);target/ppc/mmu-hash64.h +0
-0target/ppc/mmu-hash64.h void ppc_hash64_update_rmls(CPUPPCState *env); · line 109
Quoted 4 lines
target/ppc/mmu-hash64.h +1
-0@@ -106,6 +106,7 @@ void ppc_hash64_update_rmls(CPUPPCState *env);/* * Partition table definitions */ +#define PTCR_PTAB_HR PPC_BIT(0)/* 1:Host This isn't a bit in the partition table register, it is a bit in the partition table entry. It should be defined in target/ppc/mmu-book3s-
v3.has part of "/* Partition Table Entry Fields */"
Quoted 4 lines
Also to follow the naming, please call it:
#definePATBE0_HRPPC_BIT(0):)
yeah sure.
Thanks,
C.
Quoted 46 lines
Quoted 46 lines
Radix 0:HPT */
#definePTCR_PTAB0x0FFFFFFFFFFFF000ULL/* Partition
Table Base */
#definePTCR_PTAS0x000000000000001FULL/* Partition
Table Size */target/ppc/mmu_helper.c +1
-1@@ -1286,7 +1286,7 @@ void dump_mmu(FILE *f, fprintf_function cpu_fprintf, CPUPPCState *env)dump_slb (f, cpu_fprintf,ppc_env_get_cpu (env));break ;case POWERPC_MMU_VER_3_00 : -if (ppc64_radix_guest (ppc_env_get_cpu (env))) { +if (ppc64_radix (ppc_env_get_cpu (env))) {/* TODO - Unsupported */ }else {dump_slb(f, cpu_fprintf, ppc_env_get_cpu(env));target/ppc/mmu_helper.c +1
-1@@ -1432,7 +1432,7 @@ hwaddr ppc_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)case POWERPC_MMU_VER_2_07 :return ppc_hash64_get_phys_page_debug (cpu, addr);case POWERPC_MMU_VER_3_00 : -if (ppc64_radix_guest (ppc_env_get_cpu (env))) { +if (ppc64_radix (ppc_env_get_cpu (env))) {return ppc_radix64_get_phys_page_debug (cpu, addr); }else {return ppc_hash64_get_phys_page_debug(cpu, addr);target/ppc/translate_init.c +0
-0@@ -8965,7 +8965,7 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) * KVM but not under TCG. Update the default LPCR to keepnew
* CPUs in sync when radix is enabled.
*/target/ppc/translate_init.c +1
-1-if (ppc64_radix_guest (cpu)) { +if (ppc64_radix (cpu)) { lpcr->default_value |=LPCR_UPRT |LPCR_GTSE ; }else { lpcr->default_value &= ~(LPCR_UPRT |LPCR_GTSE );