All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [PULL 27/28] target/arm: Use ARMGranuleSize in ARMVAParameters
Date: Mon, 10 Oct 2022 15:27:29 +0100	[thread overview]
Message-ID: <20221010142730.502083-28-peter.maydell@linaro.org> (raw)
In-Reply-To: <20221010142730.502083-1-peter.maydell@linaro.org>

Now we have an enum for the granule size, use it in the
ARMVAParameters struct instead of the using16k/using64k bools.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20221003162315.2833797-3-peter.maydell@linaro.org
---
 target/arm/internals.h | 23 +++++++++++++++++++++--
 target/arm/helper.c    | 39 ++++++++++++++++++++++++++++-----------
 target/arm/ptw.c       |  8 +-------
 3 files changed, 50 insertions(+), 20 deletions(-)

diff --git a/target/arm/internals.h b/target/arm/internals.h
index 6166ac0a98f..9566364dcae 100644
--- a/target/arm/internals.h
+++ b/target/arm/internals.h
@@ -1007,6 +1007,26 @@ typedef enum ARMGranuleSize {
     GranInvalid,
 } ARMGranuleSize;
 
+/**
+ * arm_granule_bits: Return address size of the granule in bits
+ *
+ * Return the address size of the granule in bits. This corresponds
+ * to the pseudocode TGxGranuleBits().
+ */
+static inline int arm_granule_bits(ARMGranuleSize gran)
+{
+    switch (gran) {
+    case Gran64K:
+        return 16;
+    case Gran16K:
+        return 14;
+    case Gran4K:
+        return 12;
+    default:
+        g_assert_not_reached();
+    }
+}
+
 /*
  * Parameters of a given virtual address, as extracted from the
  * translation control register (TCR) for a given regime.
@@ -1019,10 +1039,9 @@ typedef struct ARMVAParameters {
     bool tbi        : 1;
     bool epd        : 1;
     bool hpd        : 1;
-    bool using16k   : 1;
-    bool using64k   : 1;
     bool tsz_oob    : 1;  /* tsz has been clamped to legal range */
     bool ds         : 1;
+    ARMGranuleSize gran : 2;
 } ARMVAParameters;
 
 ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va,
diff --git a/target/arm/helper.c b/target/arm/helper.c
index d7f578f2baa..dde64a487ae 100644
--- a/target/arm/helper.c
+++ b/target/arm/helper.c
@@ -4473,6 +4473,24 @@ typedef struct {
     uint64_t length;
 } TLBIRange;
 
+static ARMGranuleSize tlbi_range_tg_to_gran_size(int tg)
+{
+    /*
+     * Note that the TLBI range TG field encoding differs from both
+     * TG0 and TG1 encodings.
+     */
+    switch (tg) {
+    case 1:
+        return Gran4K;
+    case 2:
+        return Gran16K;
+    case 3:
+        return Gran64K;
+    default:
+        return GranInvalid;
+    }
+}
+
 static TLBIRange tlbi_aa64_get_range(CPUARMState *env, ARMMMUIdx mmuidx,
                                      uint64_t value)
 {
@@ -4481,17 +4499,19 @@ static TLBIRange tlbi_aa64_get_range(CPUARMState *env, ARMMMUIdx mmuidx,
     uint64_t select = sextract64(value, 36, 1);
     ARMVAParameters param = aa64_va_parameters(env, select, mmuidx, true);
     TLBIRange ret = { };
+    ARMGranuleSize gran;
 
     page_size_granule = extract64(value, 46, 2);
+    gran = tlbi_range_tg_to_gran_size(page_size_granule);
 
     /* The granule encoded in value must match the granule in use. */
-    if (page_size_granule != (param.using64k ? 3 : param.using16k ? 2 : 1)) {
+    if (gran != param.gran) {
         qemu_log_mask(LOG_GUEST_ERROR, "Invalid tlbi page size granule %d\n",
                       page_size_granule);
         return ret;
     }
 
-    page_shift = (page_size_granule - 1) * 2 + 12;
+    page_shift = arm_granule_bits(gran);
     num = extract64(value, 39, 5);
     scale = extract64(value, 44, 2);
     exponent = (5 * scale) + 1;
@@ -10375,7 +10395,7 @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va,
                                    ARMMMUIdx mmu_idx, bool data)
 {
     uint64_t tcr = regime_tcr(env, mmu_idx);
-    bool epd, hpd, using16k, using64k, tsz_oob, ds;
+    bool epd, hpd, tsz_oob, ds;
     int select, tsz, tbi, max_tsz, min_tsz, ps, sh;
     ARMGranuleSize gran;
     ARMCPU *cpu = env_archcpu(env);
@@ -10419,11 +10439,9 @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va,
     }
 
     gran = sanitize_gran_size(cpu, gran, stage2);
-    using64k = gran == Gran64K;
-    using16k = gran == Gran16K;
 
     if (cpu_isar_feature(aa64_st, cpu)) {
-        max_tsz = 48 - using64k;
+        max_tsz = 48 - (gran == Gran64K);
     } else {
         max_tsz = 39;
     }
@@ -10433,7 +10451,7 @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va,
      * adjust the effective value of DS, as documented.
      */
     min_tsz = 16;
-    if (using64k) {
+    if (gran == Gran64K) {
         if (cpu_isar_feature(aa64_lva, cpu)) {
             min_tsz = 12;
         }
@@ -10442,14 +10460,14 @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va,
         switch (mmu_idx) {
         case ARMMMUIdx_Stage2:
         case ARMMMUIdx_Stage2_S:
-            if (using16k) {
+            if (gran == Gran16K) {
                 ds = cpu_isar_feature(aa64_tgran16_2_lpa2, cpu);
             } else {
                 ds = cpu_isar_feature(aa64_tgran4_2_lpa2, cpu);
             }
             break;
         default:
-            if (using16k) {
+            if (gran == Gran16K) {
                 ds = cpu_isar_feature(aa64_tgran16_lpa2, cpu);
             } else {
                 ds = cpu_isar_feature(aa64_tgran4_lpa2, cpu);
@@ -10486,10 +10504,9 @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va,
         .tbi = tbi,
         .epd = epd,
         .hpd = hpd,
-        .using16k = using16k,
-        .using64k = using64k,
         .tsz_oob = tsz_oob,
         .ds = ds,
+        .gran = gran,
     };
 }
 
diff --git a/target/arm/ptw.c b/target/arm/ptw.c
index ddacffa7ee6..23f16f4ff7f 100644
--- a/target/arm/ptw.c
+++ b/target/arm/ptw.c
@@ -1062,13 +1062,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address,
         }
     }
 
-    if (param.using64k) {
-        stride = 13;
-    } else if (param.using16k) {
-        stride = 11;
-    } else {
-        stride = 9;
-    }
+    stride = arm_granule_bits(param.gran) - 3;
 
     /*
      * Note that QEMU ignores shareability and cacheability attributes,
-- 
2.25.1



  parent reply	other threads:[~2022-10-10 14:59 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-10 14:27 [PULL 00/28] target-arm queue Peter Maydell
2022-10-10 14:27 ` [PULL 01/28] target/arm/kvm: Retry KVM_CREATE_VM call if it fails EINTR Peter Maydell
2022-10-10 14:27 ` [PULL 02/28] target/arm: allow setting SCR_EL3.EnTP2 when FEAT_SME is implemented Peter Maydell
2022-10-10 14:27 ` [PULL 03/28] docs/nuvoton: Update URL for images Peter Maydell
2022-10-10 14:27 ` [PULL 04/28] target/arm: Split s2walk_secure from ipa_secure in get_phys_addr Peter Maydell
2022-10-10 14:27 ` [PULL 05/28] target/arm: Make the final stage1+2 write to secure be unconditional Peter Maydell
2022-10-10 14:27 ` [PULL 06/28] target/arm: Add is_secure parameter to get_phys_addr_lpae Peter Maydell
2022-10-10 14:27 ` [PULL 07/28] target/arm: Fix S2 disabled check in S1_ptw_translate Peter Maydell
2022-10-10 14:27 ` [PULL 08/28] target/arm: Add is_secure parameter to regime_translation_disabled Peter Maydell
2022-10-10 14:27 ` [PULL 09/28] target/arm: Split out get_phys_addr_with_secure Peter Maydell
2022-10-10 14:27 ` [PULL 10/28] target/arm: Add is_secure parameter to v7m_read_half_insn Peter Maydell
2022-10-10 14:27 ` [PULL 11/28] target/arm: Add TBFLAG_M32.SECURE Peter Maydell
2022-10-10 14:27 ` [PULL 12/28] target/arm: Merge regime_is_secure into get_phys_addr Peter Maydell
2022-10-10 14:27 ` [PULL 13/28] target/arm: Add is_secure parameter to do_ats_write Peter Maydell
2022-10-10 14:27 ` [PULL 14/28] target/arm: Fold secure and non-secure a-profile mmu indexes Peter Maydell
2022-10-10 14:27 ` [PULL 15/28] target/arm: Reorg regime_translation_disabled Peter Maydell
2022-10-10 14:27 ` [PULL 16/28] target/arm: Drop secure check for HCR.TGE vs SCTLR_EL1.M Peter Maydell
2022-10-10 14:27 ` [PULL 17/28] target/arm: Introduce arm_hcr_el2_eff_secstate Peter Maydell
2022-10-10 14:27 ` [PULL 18/28] target/arm: Hoist read of *is_secure in S1_ptw_translate Peter Maydell
2022-10-10 14:27 ` [PULL 19/28] target/arm: Remove env argument from combined_attrs_fwb Peter Maydell
2022-10-10 14:27 ` [PULL 20/28] target/arm: Pass HCR to attribute subroutines Peter Maydell
2022-10-10 14:27 ` [PULL 21/28] target/arm: Fix ATS12NSO* from S PL1 Peter Maydell
2022-10-10 14:27 ` [PULL 22/28] target/arm: Split out get_phys_addr_disabled Peter Maydell
2022-10-10 14:27 ` [PULL 23/28] target/arm: Fix cacheattr in get_phys_addr_disabled Peter Maydell
2022-10-10 14:27 ` [PULL 24/28] target/arm: Use tlb_set_page_full Peter Maydell
2022-10-10 14:27 ` [PULL 25/28] hw/arm/boot: set CPTR_EL3.ESM and SCR_EL3.EnTP2 when booting Linux with EL3 Peter Maydell
2022-10-10 14:27 ` [PULL 26/28] target/arm: Don't allow guest to use unimplemented granule sizes Peter Maydell
2022-10-10 14:27 ` Peter Maydell [this message]
2022-10-10 14:27 ` [PULL 28/28] docs/system/arm/emulation.rst: Report FEAT_GTG support Peter Maydell
2022-10-12 21:25 ` [PULL 00/28] target-arm queue Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221010142730.502083-28-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.