From f92147c2b2fd01bd32debe4d6cb0375705dceeac Mon Sep 17 00:00:00 2001
From: Anup Patel <anup.patel@wdc.com>
Date: Wed, 11 Mar 2020 19:08:08 +0530
Subject: include: Make sbi_hart_id_to_scratch() as macro

The sbi_hart_id_to_scratch() just forwards call to firmware specific
hartid_to_scratch() callback so we make sbi_hart_id_to_scratch() as
macro in sbi_scratch.h instead of regular function in sbi_hart.c.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---
 include/sbi/sbi_hart.h    | 3 ---
 include/sbi/sbi_scratch.h | 6 ++++++
 lib/sbi/sbi_hart.c        | 8 --------
 3 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h
index c999b58..d91e58f 100644
--- a/include/sbi/sbi_hart.h
+++ b/include/sbi/sbi_hart.h
@@ -32,9 +32,6 @@ sbi_hart_switch_mode(unsigned long arg0, unsigned long arg1,
 		     unsigned long next_addr, unsigned long next_mode,
 		     bool next_virt);
 
-struct sbi_scratch *sbi_hart_id_to_scratch(struct sbi_scratch *scratch,
-					   u32 hartid);
-
 u32 sbi_current_hartid(void);
 
 #endif
diff --git a/include/sbi/sbi_scratch.h b/include/sbi/sbi_scratch.h
index 1c85562..8960c02 100644
--- a/include/sbi/sbi_scratch.h
+++ b/include/sbi/sbi_scratch.h
@@ -103,6 +103,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);
+
+/** Get sbi_scratch from HART id */
+#define sbi_hart_id_to_scratch(__scratch, __hartid) \
+	((hartid2scratch)(__scratch)->hartid_to_scratch)(__hartid)
+
 #endif
 
 #endif
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index 732ff5f..f61a82f 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -340,11 +340,3 @@ sbi_hart_switch_mode(unsigned long arg0, unsigned long arg1,
 	__asm__ __volatile__("mret" : : "r"(a0), "r"(a1));
 	__builtin_unreachable();
 }
-
-typedef struct sbi_scratch *(*h2s)(ulong hartid);
-
-struct sbi_scratch *sbi_hart_id_to_scratch(struct sbi_scratch *scratch,
-					   u32 hartid)
-{
-	return ((h2s)scratch->hartid_to_scratch)(hartid);
-}
-- 
cgit v1.2.3