From: Bibo Mao Date: Thu, 9 Oct 2025 06:54:33 +0000 (+0800) Subject: target/loongarch: Add common interface update_tlb_index() X-Git-Tag: v10.2.0-rc1~49^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d0472b89ba1664562081357692e6c51a09583a84;p=thirdparty%2Fqemu.git target/loongarch: Add common interface update_tlb_index() Common API update_tlb_index() is added here, it is to update TLB entry with specified index. It is called by helper_tlbwr() now, also it can be used by HW PTW when adding new TLB entry. Signed-off-by: Bibo Mao Reviewed-by: Song Gao --- diff --git a/target/loongarch/tcg/tlb_helper.c b/target/loongarch/tcg/tlb_helper.c index 8d962ce3e3..92f89841b0 100644 --- a/target/loongarch/tcg/tlb_helper.c +++ b/target/loongarch/tcg/tlb_helper.c @@ -350,21 +350,14 @@ void helper_tlbrd(CPULoongArchState *env) } } -void helper_tlbwr(CPULoongArchState *env) +static void update_tlb_index(CPULoongArchState *env, MMUContext *context, + int index) { - int index = FIELD_EX64(env->CSR_TLBIDX, CSR_TLBIDX, INDEX); LoongArchTLB *old, new = {}; bool skip_inv = false, tlb_v0, tlb_v1; - MMUContext context; old = env->tlb + index; - if (FIELD_EX64(env->CSR_TLBIDX, CSR_TLBIDX, NE)) { - invalidate_tlb(env, index); - return; - } - - sptw_prepare_context(env, &context); - fill_tlb_entry(env, &new, &context); + fill_tlb_entry(env, &new, context); /* Check whether ASID/VPPN is the same */ if (old->tlb_misc == new.tlb_misc) { /* Check whether both even/odd pages is the same or invalid */ @@ -384,6 +377,20 @@ void helper_tlbwr(CPULoongArchState *env) *old = new; } +void helper_tlbwr(CPULoongArchState *env) +{ + int index = FIELD_EX64(env->CSR_TLBIDX, CSR_TLBIDX, INDEX); + MMUContext context; + + if (FIELD_EX64(env->CSR_TLBIDX, CSR_TLBIDX, NE)) { + invalidate_tlb(env, index); + return; + } + + sptw_prepare_context(env, &context); + update_tlb_index(env, &context, index); +} + static int get_tlb_random_index(CPULoongArchState *env, vaddr addr, int pagesize) {