From nobody Mon Apr 29 18:09:26 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1517387400167242.43824189539225; Wed, 31 Jan 2018 00:30:00 -0800 (PST) Received: from localhost ([::1]:44710 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1egnm8-0005mJ-78 for importer@patchew.org; Wed, 31 Jan 2018 03:29:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38412) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1egnka-0004is-Nz for qemu-devel@nongnu.org; Wed, 31 Jan 2018 03:28:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1egnkW-0001GP-IP for qemu-devel@nongnu.org; Wed, 31 Jan 2018 03:28:12 -0500 Received: from 7.mo69.mail-out.ovh.net ([46.105.50.32]:37136) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1egnkW-0001Fy-86 for qemu-devel@nongnu.org; Wed, 31 Jan 2018 03:28:08 -0500 Received: from player699.ha.ovh.net (gw6.ovh.net [213.251.189.206]) by mo69.mail-out.ovh.net (Postfix) with ESMTP id F1D1A52674 for ; Wed, 31 Jan 2018 09:28:06 +0100 (CET) Received: from zorba.kaod.org.com (LFbn-1-2226-150.w90-76.abo.wanadoo.fr [90.76.48.150]) (Authenticated sender: clg@kaod.org) by player699.ha.ovh.net (Postfix) with ESMTPSA id 9D6182400B1; Wed, 31 Jan 2018 09:28:01 +0100 (CET) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-ppc@nongnu.org, qemu-devel@nongnu.org, David Gibson Date: Wed, 31 Jan 2018 09:27:47 +0100 Message-Id: <20180131082749.1803-2-clg@kaod.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180131082749.1803-1-clg@kaod.org> References: <20180131082749.1803-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 9085449300410141523 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtfedrtddugdduvddvucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.50.32 Subject: [Qemu-devel] [PATCH 1/3] target/ppc: add basic support for PTCR on POWER9 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Suraj Jitindar Singh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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=C3=A9dric Le Goater --- 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(+) diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 9f8cbbe7aa4d..53061229a0a8 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1314,6 +1314,7 @@ int ppc_cpu_handle_mmu_fault(CPUState *cpu, vaddr add= ress, int size, int rw, =20 #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); =20 @@ -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) diff --git a/target/ppc/helper.h b/target/ppc/helper.h index 5b739179b8b5..19453c68138a 100644 --- a/target/ppc/helper.h +++ b/target/ppc/helper.h @@ -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) diff --git a/target/ppc/misc_helper.c b/target/ppc/misc_helper.c index 0e4217821b8e..8c8cba5cc6f1 100644 --- a/target/ppc/misc_helper.c +++ b/target/ppc/misc_helper.c @@ -88,6 +88,18 @@ void helper_store_sdr1(CPUPPCState *env, target_ulong va= l) } } =20 +#if defined(TARGET_PPC64) +void helper_store_ptcr(CPUPPCState *env, target_ulong val) +{ + PowerPCCPU *cpu =3D ppc_env_get_cpu(env); + + if (env->spr[SPR_PTCR] !=3D 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 =3D ppc_env_get_cpu(env); diff --git a/target/ppc/mmu-hash64.h b/target/ppc/mmu-hash64.h index d297b97d3773..4fb00ac17abb 100644 --- a/target/ppc/mmu-hash64.h +++ b/target/ppc/mmu-hash64.h @@ -98,6 +98,12 @@ void ppc_hash64_update_rmls(CPUPPCState *env); #define HPTE64_V_1TB_SEG 0x4000000000000000ULL #define HPTE64_V_VRMA_MASK 0x4001ffffff000000ULL =20 +/* + * Partition table definitions + */ +#define PTCR_PTAB 0x0FFFFFFFFFFFF000ULL /* Partition Table B= ase */ +#define PTCR_PTAS 0x000000000000001FULL /* Partition Table S= ize */ + static inline hwaddr ppc_hash64_hpt_base(PowerPCCPU *cpu) { return cpu->env.spr[SPR_SDR1] & SDR_64_HTABORG; diff --git a/target/ppc/mmu_helper.c b/target/ppc/mmu_helper.c index 16ef5acaa28f..b1e660a4d16a 100644 --- a/target/ppc/mmu_helper.c +++ b/target/ppc/mmu_helper.c @@ -2029,6 +2029,34 @@ void ppc_store_sdr1(CPUPPCState *env, target_ulong v= alue) env->spr[SPR_SDR1] =3D value; } =20 +#if defined(TARGET_PPC64) +void ppc_store_ptcr(CPUPPCState *env, target_ulong value) +{ + PowerPCCPU *cpu =3D 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 =3D PTCR_PTAB | PTCR_PTAS; + target_ulong ptas =3D value & PTCR_PTAS; + + if (value & ~ptcr_mask) { + error_report("Invalid bits 0x"TARGET_FMT_lx" set in PTCR", + value & ~ptcr_mask); + value &=3D ptcr_mask; + } + if (ptas > 28) { + error_report("Invalid PTAS 0x" TARGET_FMT_lx" stored in PTCR", + ptas); + return; + } + } + env->spr[SPR_PTCR] =3D value; +} + +#endif /* defined(TARGET_PPC64) */ + /* Segment registers load and store */ target_ulong helper_load_sr(CPUPPCState *env, target_ulong sr_num) { diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 4132f67bb1f7..c2e6e3072799 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -7130,6 +7130,9 @@ void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprint= f_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; diff --git a/target/ppc/translate_init.c b/target/ppc/translate_init.c index 55c99c97e377..a6eaa74244ca 100644 --- a/target/ppc/translate_init.c +++ b/target/ppc/translate_init.c @@ -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 =20 @@ -8164,6 +8169,18 @@ static void gen_spr_power8_rpr(CPUPPCState *env) #endif } =20 +/* 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); =20 /* POWER9 Specific registers */ spr_register_kvm(env, SPR_TIDR, "TIDR", NULL, NULL, --=20 2.13.6 From nobody Mon Apr 29 18:09:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1517387490167872.3714155277793; Wed, 31 Jan 2018 00:31:30 -0800 (PST) Received: from localhost ([::1]:44821 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1egnnk-0007L1-0a for importer@patchew.org; Wed, 31 Jan 2018 03:31:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38443) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1egnkg-0004ni-Dz for qemu-devel@nongnu.org; Wed, 31 Jan 2018 03:28:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1egnkc-0001Im-0j for qemu-devel@nongnu.org; Wed, 31 Jan 2018 03:28:18 -0500 Received: from 3.mo69.mail-out.ovh.net ([188.165.52.203]:48880) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1egnkb-0001IB-Mh for qemu-devel@nongnu.org; Wed, 31 Jan 2018 03:28:13 -0500 Received: from player699.ha.ovh.net (gw6.ovh.net [213.251.189.206]) by mo69.mail-out.ovh.net (Postfix) with ESMTP id 249C83626C for ; Wed, 31 Jan 2018 09:28:12 +0100 (CET) Received: from zorba.kaod.org.com (LFbn-1-2226-150.w90-76.abo.wanadoo.fr [90.76.48.150]) (Authenticated sender: clg@kaod.org) by player699.ha.ovh.net (Postfix) with ESMTPSA id C66022400AD; Wed, 31 Jan 2018 09:28:06 +0100 (CET) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-ppc@nongnu.org, qemu-devel@nongnu.org, David Gibson Date: Wed, 31 Jan 2018 09:27:48 +0100 Message-Id: <20180131082749.1803-3-clg@kaod.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180131082749.1803-1-clg@kaod.org> References: <20180131082749.1803-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 9086856675715418963 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtfedrtddugdduvddvucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 188.165.52.203 Subject: [Qemu-devel] [PATCH 2/3] target/ppc: add hash MMU support on POWER9 for PowerNV only X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Suraj Jitindar Singh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The 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. Signed-off-by: C=C3=A9dric Le Goater --- 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(-) diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 3fda7fd39da1..30cfc1f450cc 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -94,7 +94,7 @@ static target_ulong h_enter(PowerPCCPU *cpu, sPAPRMachine= State *spapr, return H_PARAMETER; } =20 - raddr =3D (ptel & HPTE64_R_RPN) & ~((1ULL << apshift) - 1); + raddr =3D (ptel & ppc_hash64_hpte_r_rpn(cpu)) & ~((1ULL << apshift) - = 1); =20 if (is_ram_address(spapr, raddr)) { /* Regular RAM - should have WIMG=3D0010 */ @@ -586,7 +586,8 @@ static int rehash_hpte(PowerPCCPU *cpu, =20 base_pg_shift =3D ppc_hash64_hpte_page_shift_noslb(cpu, pte0, pte1); assert(base_pg_shift); /* H_ENTER shouldn't allow a bad encoding */ - avpn =3D HPTE64_V_AVPN_VAL(pte0) & ~(((1ULL << base_pg_shift) - 1) >> = 23); + avpn =3D ppc_hash64_hpte_v_avpn_val(cpu, pte0) & + ~(((1ULL << base_pg_shift) - 1) >> 23); =20 if (pte0 & HPTE64_V_SECONDARY) { pteg =3D ~pteg; diff --git a/target/ppc/mmu-hash64.c b/target/ppc/mmu-hash64.c index 14d34e512f42..54f052ad717c 100644 --- a/target/ppc/mmu-hash64.c +++ b/target/ppc/mmu-hash64.c @@ -290,6 +290,22 @@ target_ulong helper_load_slb_vsid(CPUPPCState *env, ta= rget_ulong rb) return rt; } =20 +hwaddr ppc_hash64_hpt_reg(PowerPCCPU *cpu) +{ + CPUPPCState *env =3D &cpu->env; + + if (env->mmu_model & POWERPC_MMU_V3) { + if (msr_hv) { + return ldq_phys(CPU(cpu)->as, cpu->env.spr[SPR_PTCR] & PTCR_PT= AB); + } else { + error_report("HPT Support Unimplemented"); + exit(1); + } + } else { + return cpu->env.spr[SPR_SDR1]; + } +} + /* Check No-Execute or Guarded Storage */ static inline int ppc_hash64_pte_noexec_guard(PowerPCCPU *cpu, ppc_hash_pte64_t pte) @@ -452,8 +468,9 @@ void ppc_hash64_unmap_hptes(PowerPCCPU *cpu, const ppc_= hash_pte64_t *hptes, false, n * HASH_PTE_SIZE_64); } =20 -static unsigned hpte_page_shift(const struct ppc_one_seg_page_size *sps, - uint64_t pte0, uint64_t pte1) +static unsigned hpte_page_shift(PowerPCCPU *cpu, + const struct ppc_one_seg_page_size *sps, + uint64_t pte0, uint64_t pte1) { int i; =20 @@ -479,7 +496,7 @@ static unsigned hpte_page_shift(const struct ppc_one_se= g_page_size *sps, continue; } =20 - mask =3D ((1ULL << ps->page_shift) - 1) & HPTE64_R_RPN; + mask =3D ((1ULL << ps->page_shift) - 1) & ppc_hash64_hpte_r_rpn(cp= u); =20 if ((pte1 & mask) =3D=3D ((uint64_t)ps->pte_enc << HPTE64_R_RPN_SH= IFT)) { return ps->page_shift; @@ -489,6 +506,18 @@ static unsigned hpte_page_shift(const struct ppc_one_s= eg_page_size *sps, return 0; /* Bad page size encoding */ } =20 +static bool ppc_hash64_hpte_v_compare(PowerPCCPU *cpu, target_ulong pte0, + target_ulong ptem) +{ + CPUPPCState *env =3D &cpu->env; + + if (env->mmu_model & POWERPC_MMU_V3) { + return HPTE64_V_COMPARE_3_0(pte0, ptem); + } else { + return HPTE64_V_COMPARE(pte0, ptem); + } +} + static hwaddr ppc_hash64_pteg_search(PowerPCCPU *cpu, hwaddr hash, const struct ppc_one_seg_page_size *s= ps, target_ulong ptem, @@ -509,8 +538,8 @@ static hwaddr ppc_hash64_pteg_search(PowerPCCPU *cpu, h= waddr hash, pte1 =3D ppc_hash64_hpte1(cpu, pteg, i); =20 /* This compares V, B, H (secondary) and the AVPN */ - if (HPTE64_V_COMPARE(pte0, ptem)) { - *pshift =3D hpte_page_shift(sps, pte0, pte1); + if (ppc_hash64_hpte_v_compare(cpu, pte0, ptem)) { + *pshift =3D hpte_page_shift(cpu, sps, pte0, pte1); /* * If there is no match, ignore the PTE, it could simply * be for a different segment size encoding and the @@ -570,7 +599,8 @@ static hwaddr ppc_hash64_htab_lookup(PowerPCCPU *cpu, epn =3D (eaddr & ~SEGMENT_MASK_256M) & epnmask; hash =3D vsid ^ (epn >> sps->page_shift); } - ptem =3D (slb->vsid & SLB_VSID_PTEM) | ((epn >> 16) & HPTE64_V_AVPN); + ptem =3D (slb->vsid & SLB_VSID_PTEM) | ((epn >> 16) & + ppc_hash64_hpte_v_avpn(cpu)); ptem |=3D HPTE64_V_VALID; =20 /* Page address translation */ @@ -625,7 +655,7 @@ unsigned ppc_hash64_hpte_page_shift_noslb(PowerPCCPU *c= pu, break; } =20 - shift =3D hpte_page_shift(sps, pte0, pte1); + shift =3D hpte_page_shift(cpu, sps, pte0, pte1); if (shift) { return shift; } @@ -861,7 +891,7 @@ skip_slb_search: =20 /* 7. Determine the real address from the PTE */ =20 - raddr =3D deposit64(pte.pte1 & HPTE64_R_RPN, 0, apshift, eaddr); + raddr =3D deposit64(pte.pte1 & ppc_hash64_hpte_r_rpn(cpu), 0, apshift,= eaddr); =20 tlb_set_page(cs, eaddr & TARGET_PAGE_MASK, raddr & TARGET_PAGE_MASK, prot, mmu_idx, 1ULL << apshift); @@ -911,7 +941,7 @@ hwaddr ppc_hash64_get_phys_page_debug(PowerPCCPU *cpu, = target_ulong addr) return -1; } =20 - return deposit64(pte.pte1 & HPTE64_R_RPN, 0, apshift, addr) + return deposit64(pte.pte1 & ppc_hash64_hpte_r_rpn(cpu), 0, apshift, ad= dr) & TARGET_PAGE_MASK; } =20 diff --git a/target/ppc/mmu-hash64.h b/target/ppc/mmu-hash64.h index 4fb00ac17abb..4dc6b3968ec0 100644 --- a/target/ppc/mmu-hash64.h +++ b/target/ppc/mmu-hash64.h @@ -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_SH= IFT) +#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 B= ase */ #define PTCR_PTAS 0x000000000000001FULL /* Partition Table S= ize */ =20 +static inline target_ulong ppc_hash64_hpte_r_rpn(PowerPCCPU *cpu) +{ + CPUPPCState *env =3D &cpu->env; + + return env->mmu_model & POWERPC_MMU_V3 ? HPTE64_R_RPN_3_0 : HPTE64_R_R= PN; +} + +static inline target_ulong ppc_hash64_hpte_v_avpn(PowerPCCPU *cpu) +{ + CPUPPCState *env =3D &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 =3D &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; } =20 static inline hwaddr ppc_hash64_hpt_mask(PowerPCCPU *cpu) @@ -116,7 +146,7 @@ static inline hwaddr ppc_hash64_hpt_mask(PowerPCCPU *cp= u) 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; } =20 struct ppc_hash_pte64 { --=20 2.13.6 From nobody Mon Apr 29 18:09:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1517387602910584.174291003983; Wed, 31 Jan 2018 00:33:22 -0800 (PST) Received: from localhost ([::1]:44891 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1egnpZ-00008n-9A for importer@patchew.org; Wed, 31 Jan 2018 03:33:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38466) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1egnkk-0004rY-Af for qemu-devel@nongnu.org; Wed, 31 Jan 2018 03:28:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1egnkh-0001K5-6E for qemu-devel@nongnu.org; Wed, 31 Jan 2018 03:28:22 -0500 Received: from 1.mo69.mail-out.ovh.net ([178.33.251.173]:41748) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1egnkg-0001Jc-V1 for qemu-devel@nongnu.org; Wed, 31 Jan 2018 03:28:19 -0500 Received: from player699.ha.ovh.net (gw6.ovh.net [213.251.189.206]) by mo69.mail-out.ovh.net (Postfix) with ESMTP id 48F0948744 for ; Wed, 31 Jan 2018 09:28:17 +0100 (CET) Received: from zorba.kaod.org.com (LFbn-1-2226-150.w90-76.abo.wanadoo.fr [90.76.48.150]) (Authenticated sender: clg@kaod.org) by player699.ha.ovh.net (Postfix) with ESMTPSA id F138F240096; Wed, 31 Jan 2018 09:28:11 +0100 (CET) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-ppc@nongnu.org, qemu-devel@nongnu.org, David Gibson Date: Wed, 31 Jan 2018 09:27:49 +0100 Message-Id: <20180131082749.1803-4-clg@kaod.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180131082749.1803-1-clg@kaod.org> References: <20180131082749.1803-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 9088545524651821907 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtfedrtddugdduvddvucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 178.33.251.173 Subject: [Qemu-devel] [PATCH 3/3] target/ppc: generalize check on radix when in HV mode X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Suraj Jitindar Singh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: C=C3=A9dric Le Goater --- 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(-) diff --git a/target/ppc/mmu-book3s-v3.c b/target/ppc/mmu-book3s-v3.c index e7798b3582b0..50b60fca3445 100644 --- a/target/ppc/mmu-book3s-v3.c +++ b/target/ppc/mmu-book3s-v3.c @@ -24,10 +24,25 @@ #include "mmu-book3s-v3.h" #include "mmu-radix64.h" =20 +bool ppc64_radix(PowerPCCPU *cpu) +{ + CPUPPCState *env =3D &cpu->env; + + if (msr_hv) { + return ldq_phys(CPU(cpu)->as, cpu->env.spr[SPR_PTCR] & + PTCR_PTAB) & PTCR_PTAB_HR; + } else { + PPCVirtualHypervisorClass *vhc =3D + 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); diff --git a/target/ppc/mmu-book3s-v3.h b/target/ppc/mmu-book3s-v3.h index 56095dab522c..3876cb51b35c 100644 --- a/target/ppc/mmu-book3s-v3.h +++ b/target/ppc/mmu-book3s-v3.h @@ -37,13 +37,7 @@ static inline bool ppc64_use_proc_tbl(PowerPCCPU *cpu) return !!(cpu->env.spr[SPR_LPCR] & LPCR_UPRT); } =20 -static inline bool ppc64_radix_guest(PowerPCCPU *cpu) -{ - PPCVirtualHypervisorClass *vhc =3D - PPC_VIRTUAL_HYPERVISOR_GET_CLASS(cpu->vhyp); - - return !!(vhc->get_patbe(cpu->vhyp) & PATBE1_GR); -} +bool ppc64_radix(PowerPCCPU *cpu); =20 int ppc64_v3_handle_mmu_fault(PowerPCCPU *cpu, vaddr eaddr, int rwx, int mmu_idx); diff --git a/target/ppc/mmu-hash64.h b/target/ppc/mmu-hash64.h index 4dc6b3968ec0..7e2ac64b6eeb 100644 --- a/target/ppc/mmu-hash64.h +++ b/target/ppc/mmu-hash64.h @@ -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:HP= T */ #define PTCR_PTAB 0x0FFFFFFFFFFFF000ULL /* Partition Table B= ase */ #define PTCR_PTAS 0x000000000000001FULL /* Partition Table S= ize */ =20 diff --git a/target/ppc/mmu_helper.c b/target/ppc/mmu_helper.c index b1e660a4d16a..059863b99b2e 100644 --- a/target/ppc/mmu_helper.c +++ b/target/ppc/mmu_helper.c @@ -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, vadd= r 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); diff --git a/target/ppc/translate_init.c b/target/ppc/translate_init.c index a6eaa74244ca..07012ee75e81 100644 --- a/target/ppc/translate_init.c +++ b/target/ppc/translate_init.c @@ -8965,7 +8965,7 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHype= rvisor *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 |=3D LPCR_UPRT | LPCR_GTSE; } else { lpcr->default_value &=3D ~(LPCR_UPRT | LPCR_GTSE); --=20 2.13.6