From 66d018499cf928e0c8c8a15e0a896e7f80ad5f99 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Fri, 17 Apr 2020 15:10:10 +0530 Subject: [PATCH] lib: Allow overriding SBI implementation ID Ideally, the SBI implementation ID for OpenSBI should always be 0x1 (as mentioned in SBI v0.2 spec) but external firmware (such as EDK2) which use OpenSBI as library might want to override the SBI implementation ID with their custom implementation ID. Signed-off-by: Anup Patel Reviewed-by: Bin Meng Reviewed-by: Atish Patra --- include/sbi/sbi_ecall.h | 4 ++++ lib/sbi/sbi_ecall.c | 12 ++++++++++++ lib/sbi/sbi_ecall_base.c | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/sbi/sbi_ecall.h b/include/sbi/sbi_ecall.h index 0b92e67..3273ba6 100644 --- a/include/sbi/sbi_ecall.h +++ b/include/sbi/sbi_ecall.h @@ -42,6 +42,10 @@ u16 sbi_ecall_version_major(void); u16 sbi_ecall_version_minor(void); +unsigned long sbi_ecall_get_impid(void); + +void sbi_ecall_set_impid(unsigned long impid); + struct sbi_ecall_extension *sbi_ecall_find_extension(unsigned long extid); int sbi_ecall_register_extension(struct sbi_ecall_extension *ext); diff --git a/lib/sbi/sbi_ecall.c b/lib/sbi/sbi_ecall.c index 6c42553..1a54c6e 100644 --- a/lib/sbi/sbi_ecall.c +++ b/lib/sbi/sbi_ecall.c @@ -22,6 +22,18 @@ u16 sbi_ecall_version_minor(void) return SBI_ECALL_VERSION_MINOR; } +static unsigned long ecall_impid = SBI_OPENSBI_IMPID; + +unsigned long sbi_ecall_get_impid(void) +{ + return ecall_impid; +} + +void sbi_ecall_set_impid(unsigned long impid) +{ + ecall_impid = impid; +} + static SBI_LIST_HEAD(ecall_exts_list); struct sbi_ecall_extension *sbi_ecall_find_extension(unsigned long extid) diff --git a/lib/sbi/sbi_ecall_base.c b/lib/sbi/sbi_ecall_base.c index 1049c80..53c93c8 100644 --- a/lib/sbi/sbi_ecall_base.c +++ b/lib/sbi/sbi_ecall_base.c @@ -46,7 +46,7 @@ static int sbi_ecall_base_handler(unsigned long extid, unsigned long funcid, *out_val = *out_val | SBI_ECALL_VERSION_MINOR; break; case SBI_EXT_BASE_GET_IMP_ID: - *out_val = SBI_OPENSBI_IMPID; + *out_val = sbi_ecall_get_impid(); break; case SBI_EXT_BASE_GET_IMP_VERSION: *out_val = OPENSBI_VERSION; -- 2.7.4