qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v3 5/6] target/loongarch: Support LoongArch32 DMW


From: Richard Henderson
Subject: Re: [PATCH v3 5/6] target/loongarch: Support LoongArch32 DMW
Date: Mon, 7 Aug 2023 08:50:19 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0

On 8/7/23 02:45, Jiajie Chen wrote:
LA32 uses a different encoding for CSR.DMW and a new direct mapping
mechanism.

Signed-off-by: Jiajie Chen <c@jia.je>
---
  target/loongarch/cpu-csr.h    |  7 +++----
  target/loongarch/tlb_helper.c | 31 ++++++++++++++++++++++++++++---
  2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/target/loongarch/cpu-csr.h b/target/loongarch/cpu-csr.h
index 48ed2e0632..b93f99a9ef 100644
--- a/target/loongarch/cpu-csr.h
+++ b/target/loongarch/cpu-csr.h
@@ -188,10 +188,9 @@ FIELD(CSR_DMW, PLV1, 1, 1)
  FIELD(CSR_DMW, PLV2, 2, 1)
  FIELD(CSR_DMW, PLV3, 3, 1)
  FIELD(CSR_DMW, MAT, 4, 2)
-FIELD(CSR_DMW, VSEG, 60, 4)
-
-#define dmw_va2pa(va) \
-    (va & MAKE_64BIT_MASK(0, TARGET_VIRT_ADDR_SPACE_BITS))
+FIELD(CSR_DMW_32, PSEG, 25, 3)
+FIELD(CSR_DMW_32, VSEG, 29, 3)
+FIELD(CSR_DMW_64, VSEG, 60, 4)
/* Debug CSRs */
  #define LOONGARCH_CSR_DBG            0x500 /* debug config */
diff --git a/target/loongarch/tlb_helper.c b/target/loongarch/tlb_helper.c
index 690c6ef25f..cf6f5863f9 100644
--- a/target/loongarch/tlb_helper.c
+++ b/target/loongarch/tlb_helper.c
@@ -173,6 +173,18 @@ static int loongarch_map_address(CPULoongArchState *env, 
hwaddr *physical,
      return TLBRET_NOMATCH;
  }
+static hwaddr dmw_va2pa(CPULoongArchState *env, target_ulong va,
+                        target_ulong dmw)
+{
+    if (env->mode == LA64) {
+        return va & TARGET_PHYS_MASK;
+    } else {
+        uint32_t pseg = FIELD_EX32(dmw, CSR_DMW_32, PSEG);
+        return (va & MAKE_64BIT_MASK(0, R_CSR_DMW_32_VSEG_SHIFT)) | \
+            (pseg << R_CSR_DMW_32_VSEG_SHIFT);
+    }
+}
+
  static int get_physical_address(CPULoongArchState *env, hwaddr *physical,
                                  int *prot, target_ulong address,
                                  MMUAccessType access_type, int mmu_idx)
@@ -184,6 +196,11 @@ static int get_physical_address(CPULoongArchState *env, 
hwaddr *physical,
      uint8_t da = FIELD_EX64(env->CSR_CRMD, CSR_CRMD, DA);
      uint8_t pg = FIELD_EX64(env->CSR_CRMD, CSR_CRMD, PG);
+ /* Truncate high 32 bits for LA32 */
+    if (env->mode == LA32) {
+        address = (uint32_t)address;
+    }

You need to do this in the translator, because this also depends on VA32L* and the current priv level.

Otherwise the window manipulation looks correct.


r~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]