[PATCH v3 07/12] target/loongarch: Add common API loongarch_tlb_search_cb()

Bibo Mao posted 12 patches 3 days, 5 hours ago
Maintainers: Song Gao <gaosong@loongson.cn>
There is a newer version of this series
[PATCH v3 07/12] target/loongarch: Add common API loongarch_tlb_search_cb()
Posted by Bibo Mao 3 days, 5 hours ago
Common API loongarch_tlb_search_cb() is added here to search TLB entry
with specified address.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
 target/loongarch/tcg/tlb_helper.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/target/loongarch/tcg/tlb_helper.c b/target/loongarch/tcg/tlb_helper.c
index 006fe1b207..fc853f6e80 100644
--- a/target/loongarch/tcg/tlb_helper.c
+++ b/target/loongarch/tcg/tlb_helper.c
@@ -207,18 +207,16 @@ static uint32_t get_random_tlb(uint32_t low, uint32_t high)
  * field in tlb entry contains bit[47:13], so need adjust.
  * virt_vpn = vaddr[47:13]
  */
-static bool loongarch_tlb_search(CPULoongArchState *env, vaddr vaddr,
-                                 int *index)
+static bool loongarch_tlb_search_cb(CPULoongArchState *env, vaddr vaddr,
+                                    int *index, int asid, tlb_match func)
 {
     LoongArchTLB *tlb;
     uint16_t csr_asid, tlb_asid, stlb_idx;
     uint8_t tlb_e, tlb_ps, tlb_g, stlb_ps;
     int i, compare_shift;
     uint64_t vpn, tlb_vppn;
-    tlb_match func;
 
-    func = tlb_match_any;
-    csr_asid = FIELD_EX64(env->CSR_ASID, CSR_ASID, ASID);
+    csr_asid = asid;
     stlb_ps = FIELD_EX64(env->CSR_STLBPS, CSR_STLBPS, PS);
     vpn = (vaddr & TARGET_VIRT_MASK) >> (stlb_ps + 1);
     stlb_idx = vpn & 0xff; /* VA[25:15] <==> TLBIDX.index for 16KiB Page */
@@ -262,6 +260,17 @@ static bool loongarch_tlb_search(CPULoongArchState *env, vaddr vaddr,
     return false;
 }
 
+static bool loongarch_tlb_search(CPULoongArchState *env, vaddr vaddr,
+                                 int *index)
+{
+    int asid;
+    tlb_match func;
+
+    func = tlb_match_any;
+    asid = FIELD_EX64(env->CSR_ASID, CSR_ASID, ASID);
+    return loongarch_tlb_search_cb(env, vaddr, index, asid, func);
+}
+
 void helper_tlbsrch(CPULoongArchState *env)
 {
     int index, match;
-- 
2.39.3
Re: [PATCH v3 07/12] target/loongarch: Add common API loongarch_tlb_search_cb()
Posted by Richard Henderson 3 days, 1 hour ago
On 9/3/25 10:48, Bibo Mao wrote:
> Common API loongarch_tlb_search_cb() is added here to search TLB entry
> with specified address.
> 
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
>   target/loongarch/tcg/tlb_helper.c | 19 ++++++++++++++-----
>   1 file changed, 14 insertions(+), 5 deletions(-)
> 
> diff --git a/target/loongarch/tcg/tlb_helper.c b/target/loongarch/tcg/tlb_helper.c
> index 006fe1b207..fc853f6e80 100644
> --- a/target/loongarch/tcg/tlb_helper.c
> +++ b/target/loongarch/tcg/tlb_helper.c
> @@ -207,18 +207,16 @@ static uint32_t get_random_tlb(uint32_t low, uint32_t high)
>    * field in tlb entry contains bit[47:13], so need adjust.
>    * virt_vpn = vaddr[47:13]
>    */
> -static bool loongarch_tlb_search(CPULoongArchState *env, vaddr vaddr,
> -                                 int *index)
> +static bool loongarch_tlb_search_cb(CPULoongArchState *env, vaddr vaddr,
> +                                    int *index, int asid, tlb_match func)

Name the parameter csr_asid, then

>   {
>       LoongArchTLB *tlb;
>       uint16_t csr_asid, tlb_asid, stlb_idx;
>       uint8_t tlb_e, tlb_ps, tlb_g, stlb_ps;
>       int i, compare_shift;
>       uint64_t vpn, tlb_vppn;
> -    tlb_match func;
>   
> -    func = tlb_match_any;
> -    csr_asid = FIELD_EX64(env->CSR_ASID, CSR_ASID, ASID);
> +    csr_asid = asid;

this is unnecessary.

Anyway,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~