lib: sbi: Use current_hartindex() where possible

This avoids calls to the expensive sbi_hartid_to_hartindex() function
and also makes the firmware smaller.

Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Samuel Holland
2024-08-30 08:49:07 -07:00
committed by Anup Patel
parent 9d7a983060
commit 15c4e285db
5 changed files with 9 additions and 10 deletions

View File

@@ -204,7 +204,7 @@ void sbi_update_hartindex_to_domain(u32 hartindex, struct sbi_domain *dom);
/** Get pointer to sbi_domain for current HART */
#define sbi_domain_thishart_ptr() \
sbi_hartindex_to_domain(sbi_hartid_to_hartindex(current_hartid()))
sbi_hartindex_to_domain(current_hartindex())
/** Head of linked list of domains */
extern struct sbi_dlist domain_list;

View File

@@ -52,10 +52,9 @@ struct sbi_context {
(__d)->hartindex_to_context_table[__hartindex]
/** Macro to obtain the current hart's context pointer */
#define sbi_domain_context_thishart_ptr() \
sbi_hartindex_to_domain_context( \
sbi_hartid_to_hartindex(current_hartid()), \
sbi_domain_thishart_ptr())
#define sbi_domain_context_thishart_ptr() \
sbi_hartindex_to_domain_context(current_hartindex(), \
sbi_domain_thishart_ptr())
/**
* Enter a specific domain context synchronously

View File

@@ -26,7 +26,7 @@
static void switch_to_next_domain_context(struct sbi_context *ctx,
struct sbi_context *dom_ctx)
{
u32 hartindex = sbi_hartid_to_hartindex(current_hartid());
u32 hartindex = current_hartindex();
struct sbi_trap_context *trap_ctx;
struct sbi_domain *current_dom = ctx->dom;
struct sbi_domain *target_dom = dom_ctx->dom;
@@ -91,7 +91,7 @@ int sbi_domain_context_enter(struct sbi_domain *dom)
{
struct sbi_context *ctx = sbi_domain_context_thishart_ptr();
struct sbi_context *dom_ctx = sbi_hartindex_to_domain_context(
sbi_hartid_to_hartindex(current_hartid()), dom);
current_hartindex(), dom);
/* Validate the domain context existence */
if (!dom_ctx)
@@ -107,7 +107,7 @@ int sbi_domain_context_enter(struct sbi_domain *dom)
int sbi_domain_context_exit(void)
{
u32 hartindex = sbi_hartid_to_hartindex(current_hartid());
u32 hartindex = current_hartindex();
struct sbi_domain *dom;
struct sbi_context *ctx = sbi_domain_context_thishart_ptr();
struct sbi_context *dom_ctx, *tmp;

View File

@@ -261,7 +261,7 @@ int sbi_hsm_init(struct sbi_scratch *scratch, u32 hartid, bool cold_boot)
hdata = sbi_scratch_offset_ptr(rscratch,
hart_data_offset);
ATOMIC_INIT(&hdata->state,
(sbi_hartindex_to_hartid(i) == hartid) ?
(i == current_hartindex()) ?
SBI_HSM_STATE_START_PENDING :
SBI_HSM_STATE_STOPPED);
ATOMIC_INIT(&hdata->start_ticket, 0);

View File

@@ -233,7 +233,7 @@ void sbi_ipi_process(void)
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
struct sbi_ipi_data *ipi_data =
sbi_scratch_offset_ptr(scratch, ipi_data_off);
u32 hartindex = sbi_hartid_to_hartindex(current_hartid());
u32 hartindex = current_hartindex();
sbi_pmu_ctr_incr_fw(SBI_PMU_FW_IPI_RECVD);
sbi_ipi_raw_clear(hartindex);