From 9d7a983060dc379ae788ed1879371211a1005c6f Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Fri, 30 Aug 2024 08:49:06 -0700 Subject: [PATCH] include: sbi: Store the hart index in struct sbi_scratch This is a more efficient way to get the index of the current hart than calling a function to loop through the hartindex -> hartid lookup table. Signed-off-by: Samuel Holland Reviewed-by: Anup Patel --- firmware/fw_base.S | 2 ++ include/sbi/sbi_scratch.h | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/firmware/fw_base.S b/firmware/fw_base.S index 0b58cc42..41ae46f2 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -218,6 +218,8 @@ _scratch_init: #endif REG_S a0, SBI_SCRATCH_OPTIONS_OFFSET(tp) MOV_3R a0, s0, a1, s1, a2, s2 + /* Store hart index in scratch space */ + REG_S t1, SBI_SCRATCH_HARTINDEX_OFFSET(tp) /* Move to next scratch space */ add t1, t1, t2 blt t1, s7, _scratch_init diff --git a/include/sbi/sbi_scratch.h b/include/sbi/sbi_scratch.h index 12e6a983..9ae4f891 100644 --- a/include/sbi/sbi_scratch.h +++ b/include/sbi/sbi_scratch.h @@ -42,8 +42,10 @@ #define SBI_SCRATCH_TMP0_OFFSET (12 * __SIZEOF_POINTER__) /** Offset of options member in sbi_scratch */ #define SBI_SCRATCH_OPTIONS_OFFSET (13 * __SIZEOF_POINTER__) +/** Offset of hartindex member in sbi_scratch */ +#define SBI_SCRATCH_HARTINDEX_OFFSET (14 * __SIZEOF_POINTER__) /** Offset of extra space in sbi_scratch */ -#define SBI_SCRATCH_EXTRA_SPACE_OFFSET (14 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_EXTRA_SPACE_OFFSET (15 * __SIZEOF_POINTER__) /** Maximum size of sbi_scratch (4KB) */ #define SBI_SCRATCH_SIZE (0x1000) @@ -83,6 +85,8 @@ struct sbi_scratch { unsigned long tmp0; /** Options for OpenSBI library */ unsigned long options; + /** Index of the hart */ + unsigned long hartindex; }; /** @@ -202,6 +206,10 @@ do { \ = (__type)(__ptr); \ } while (0) +/** Get the hart index of the current hart */ +#define current_hartindex() \ + (sbi_scratch_thishart_ptr()->hartindex) + /** Last HART index having a sbi_scratch pointer */ extern u32 last_hartindex_having_scratch;