diff options
-rw-r--r-- | lib/sbi/sbi_scratch.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/sbi/sbi_scratch.c b/lib/sbi/sbi_scratch.c index 0a615a2..95ee2f2 100644 --- a/lib/sbi/sbi_scratch.c +++ b/lib/sbi/sbi_scratch.c @@ -8,14 +8,21 @@ */ #include <sbi/riscv_locks.h> +#include <sbi/sbi_hart.h> +#include <sbi/sbi_platform.h> #include <sbi/sbi_scratch.h> +#include <sbi/sbi_string.h> static spinlock_t extra_lock = SPIN_LOCK_INITIALIZER; static unsigned long extra_offset = SBI_SCRATCH_EXTRA_SPACE_OFFSET; unsigned long sbi_scratch_alloc_offset(unsigned long size, const char *owner) { + u32 i; + void *ptr; unsigned long ret = 0; + struct sbi_scratch *scratch, *rscratch; + const struct sbi_platform *plat; /* * We have a simple brain-dead allocator which never expects @@ -43,6 +50,16 @@ unsigned long sbi_scratch_alloc_offset(unsigned long size, const char *owner) done: spin_unlock(&extra_lock); + if (ret) { + scratch = sbi_scratch_thishart_ptr(); + plat = sbi_platform_ptr(scratch); + for (i = 0; i < sbi_platform_hart_count(plat); i++) { + rscratch = sbi_hart_id_to_scratch(scratch, i); + ptr = sbi_scratch_offset_ptr(rscratch, ret); + sbi_memset(ptr, 0, size); + } + } + return ret; } |