lib: sbi_tlb: Check tlb_range_flush_limit only once per request
authorSamuel Holland <samuel.holland@sifive.com>
Fri, 8 Dec 2023 20:29:55 +0000 (12:29 -0800)
committerAnup Patel <anup@brainfault.org>
Mon, 11 Dec 2023 05:11:48 +0000 (10:41 +0530)
The tlb_update() callback is called for each destination hart.
Move the size check earlier, so it is executed only once.

Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
lib/sbi/sbi_tlb.c

index dad95088b17110f3a9b4b6b66a31d755a6a45981..d3ed56dfe084e3950f6a7dd1afda834741a1ecfd 100644 (file)
@@ -327,16 +327,6 @@ static int tlb_update(struct sbi_scratch *scratch,
        struct sbi_tlb_info *tinfo = data;
        u32 curr_hartid = current_hartid();
 
-       /*
-        * If address range to flush is too big then simply
-        * upgrade it to flush all because we can only flush
-        * 4KB at a time.
-        */
-       if (tinfo->size > tlb_range_flush_limit) {
-               tinfo->start = 0;
-               tinfo->size = SBI_TLB_FLUSH_ALL;
-       }
-
        /*
         * If the request is to queue a tlb flush entry for itself
         * then just do a local flush and return;
@@ -385,6 +375,16 @@ int sbi_tlb_request(ulong hmask, ulong hbase, struct sbi_tlb_info *tinfo)
        if (!tinfo->local_fn)
                return SBI_EINVAL;
 
+       /*
+        * If address range to flush is too big then simply
+        * upgrade it to flush all because we can only flush
+        * 4KB at a time.
+        */
+       if (tinfo->size > tlb_range_flush_limit) {
+               tinfo->start = 0;
+               tinfo->size = SBI_TLB_FLUSH_ALL;
+       }
+
        tlb_pmu_incr_fw_ctr(tinfo);
 
        return sbi_ipi_send_many(hmask, hbase, tlb_event, tinfo);