diff options
author | Anup Patel <anup.patel@wdc.com> | 2020-03-14 07:27:45 +0300 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2020-03-19 06:32:23 +0300 |
commit | 87a7ef7659e27cdd5ef9a639cd68cf628be3d2d3 (patch) | |
tree | ac6ddd1dad09a1521dc8c439a7b1a6eca966c9da | |
parent | 3f8d754c2c7f2937b10013ea2866d7e7ebfee60b (diff) | |
download | opensbi-87a7ef7659e27cdd5ef9a639cd68cf628be3d2d3.tar.xz |
lib: sbi_scratch: Introduce HART id to scratch table
Instead of calling hartid_to_scratch() callback every time when
we want sbi_scratch pointer from HART id, we create a table of
sbi_scratch pointers and use that to get sbi_scratch pointer.
As a result of HART id to scratch table, the conversion of
HART id to sbi_scratch pointer is just 2-3 instructions which
was 9 instructions previously.
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
-rw-r--r-- | include/sbi/sbi_scratch.h | 8 | ||||
-rw-r--r-- | lib/sbi/sbi_init.c | 5 | ||||
-rw-r--r-- | lib/sbi/sbi_scratch.c | 17 |
3 files changed, 28 insertions, 2 deletions
diff --git a/include/sbi/sbi_scratch.h b/include/sbi/sbi_scratch.h index 8960c02..ec47caf 100644 --- a/include/sbi/sbi_scratch.h +++ b/include/sbi/sbi_scratch.h @@ -85,6 +85,9 @@ enum sbi_scratch_options { #define sbi_scratch_thishart_arg1_ptr() \ ((void *)(sbi_scratch_thishart_ptr()->next_arg1)) +/** Initialize scatch table and allocator */ +int sbi_scratch_init(struct sbi_scratch *scratch); + /** * Allocate from extra space in sbi_scratch * @@ -103,11 +106,12 @@ void sbi_scratch_free_offset(unsigned long offset); #define sbi_scratch_thishart_offset_ptr(offset) \ ((void *)sbi_scratch_thishart_ptr() + (offset)) -typedef struct sbi_scratch *(*hartid2scratch)(ulong hartid); +/** HART id to scratch table */ +extern struct sbi_scratch *hartid_to_scratch_table[]; /** Get sbi_scratch from HART id */ #define sbi_hart_id_to_scratch(__scratch, __hartid) \ - ((hartid2scratch)(__scratch)->hartid_to_scratch)(__hartid) + hartid_to_scratch_table[__hartid] #endif diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index 11882d6..113987c 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -146,6 +146,11 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid) unsigned long *init_count; const struct sbi_platform *plat = sbi_platform_ptr(scratch); + /* Note: This has to be first thing in coldboot init sequence */ + rc = sbi_scratch_init(scratch); + if (rc) + sbi_hart_hang(); + init_count_offset = sbi_scratch_alloc_offset(__SIZEOF_POINTER__, "INIT_COUNT"); if (!init_count_offset) diff --git a/lib/sbi/sbi_scratch.c b/lib/sbi/sbi_scratch.c index 26716c5..68c5853 100644 --- a/lib/sbi/sbi_scratch.c +++ b/lib/sbi/sbi_scratch.c @@ -9,13 +9,30 @@ #include <sbi/riscv_locks.h> #include <sbi/sbi_hart.h> +#include <sbi/sbi_hartmask.h> #include <sbi/sbi_platform.h> #include <sbi/sbi_scratch.h> #include <sbi/sbi_string.h> +struct sbi_scratch *hartid_to_scratch_table[SBI_HARTMASK_MAX_BITS] = { 0 }; + static spinlock_t extra_lock = SPIN_LOCK_INITIALIZER; static unsigned long extra_offset = SBI_SCRATCH_EXTRA_SPACE_OFFSET; +typedef struct sbi_scratch *(*hartid2scratch)(ulong hartid); + +int sbi_scratch_init(struct sbi_scratch *scratch) +{ + u32 i; + const struct sbi_platform *plat = sbi_platform_ptr(scratch); + + for (i = 0; i < sbi_platform_hart_count(plat); i++) + hartid_to_scratch_table[i] = + ((hartid2scratch)scratch->hartid_to_scratch)(i); + + return 0; +} + unsigned long sbi_scratch_alloc_offset(unsigned long size, const char *owner) { u32 i; |