From 87a7ef7659e27cdd5ef9a639cd68cf628be3d2d3 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Sat, 14 Mar 2020 09:57:45 +0530 Subject: 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 Reviewed-by: Bin Meng Reviewed-by: Atish Patra --- include/sbi/sbi_scratch.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/sbi/sbi_scratch.h b/include/sbi/sbi_scratch.h index 8960c021..ec47caf7 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 -- cgit v1.3.1