aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorXiang W <wxjstz@126.com>2023-09-06 21:10:04 +0800
committerAnup Patel <anup@brainfault.org>2023-09-10 11:46:44 +0530
commit5bd969477f2c710ee5945f1a66cf534c478c48de (patch)
treeddfbe09c0c61781cbb9d7dc026edbc079c99675c /lib
parentcacfba32cc9541b7b9f838df43c1f2bd43222d3a (diff)
downloadopensbi-5bd969477f2c710ee5945f1a66cf534c478c48de.zip
opensbi-5bd969477f2c710ee5945f1a66cf534c478c48de.tar.gz
opensbi-5bd969477f2c710ee5945f1a66cf534c478c48de.tar.bz2
lib: sbi: alloc tlb fifo by sbi_malloc
If the system is defined from tlb_fifo_num_entries, the scratch may be too small to hold the fifo, so it is alloc through the heap. Signed-off-by: Xiang W <wxjstz@126.com> Signed-off-by: Xing Xiaoguang <xiaoguang.xing@sophgo.com> Reviewed-by: Anup Patel <anup@brainfault.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/sbi/sbi_tlb.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/sbi/sbi_tlb.c b/lib/sbi/sbi_tlb.c
index 92648da..ee6a4fe 100644
--- a/lib/sbi/sbi_tlb.c
+++ b/lib/sbi/sbi_tlb.c
@@ -14,6 +14,7 @@
#include <sbi/sbi_error.h>
#include <sbi/sbi_fifo.h>
#include <sbi/sbi_hart.h>
+#include <sbi/sbi_heap.h>
#include <sbi/sbi_ipi.h>
#include <sbi/sbi_scratch.h>
#include <sbi/sbi_tlb.h>
@@ -421,8 +422,7 @@ int sbi_tlb_init(struct sbi_scratch *scratch, bool cold_boot)
sbi_scratch_free_offset(tlb_sync_off);
return SBI_ENOMEM;
}
- tlb_fifo_mem_off = sbi_scratch_alloc_offset(
- sbi_platform_tlb_fifo_num_entries(plat) * SBI_TLB_INFO_SIZE);
+ tlb_fifo_mem_off = sbi_scratch_alloc_offset(sizeof(tlb_mem));
if (!tlb_fifo_mem_off) {
sbi_scratch_free_offset(tlb_fifo_off);
sbi_scratch_free_offset(tlb_sync_off);
@@ -448,7 +448,14 @@ int sbi_tlb_init(struct sbi_scratch *scratch, bool cold_boot)
tlb_sync = sbi_scratch_offset_ptr(scratch, tlb_sync_off);
tlb_q = sbi_scratch_offset_ptr(scratch, tlb_fifo_off);
- tlb_mem = sbi_scratch_offset_ptr(scratch, tlb_fifo_mem_off);
+ tlb_mem = sbi_scratch_read_type(scratch, void *, tlb_fifo_mem_off);
+ if (!tlb_mem) {
+ tlb_mem = sbi_malloc(
+ sbi_platform_tlb_fifo_num_entries(plat) * SBI_TLB_INFO_SIZE);
+ if (!tlb_mem)
+ return SBI_ENOMEM;
+ sbi_scratch_write_type(scratch, void *, tlb_fifo_mem_off, tlb_mem);
+ }
ATOMIC_INIT(tlb_sync, 0);