diff --git a/include/sbi/sbi_ecall.h b/include/sbi/sbi_ecall.h index 80c99be..2a3500f 100644 --- a/include/sbi/sbi_ecall.h +++ b/include/sbi/sbi_ecall.h @@ -13,6 +13,10 @@ #include #include +#define SBI_ECALL_VERSION_MAJOR 0 +#define SBI_ECALL_VERSION_MINOR 2 +#define SBI_OPENSBI_IMPID 1 + struct sbi_trap_regs; struct sbi_trap_info; struct sbi_scratch; @@ -29,6 +33,7 @@ struct sbi_ecall_extension { struct sbi_trap_info *out_trap); }; +extern struct sbi_ecall_extension ecall_base; extern struct sbi_ecall_extension ecall_legacy; extern struct sbi_ecall_extension ecall_time; extern struct sbi_ecall_extension ecall_rfence; diff --git a/lib/sbi/objects.mk b/lib/sbi/objects.mk index 48e7530..fac980f 100644 --- a/lib/sbi/objects.mk +++ b/lib/sbi/objects.mk @@ -14,6 +14,7 @@ libsbi-objs-y += riscv_locks.o libsbi-objs-y += sbi_console.o libsbi-objs-y += sbi_ecall.o +libsbi-objs-y += sbi_ecall_base.o libsbi-objs-y += sbi_ecall_legacy.o libsbi-objs-y += sbi_ecall_replace.o libsbi-objs-y += sbi_ecall_vendor.o diff --git a/lib/sbi/sbi_ecall.c b/lib/sbi/sbi_ecall.c index d34bc49..e52a654 100644 --- a/lib/sbi/sbi_ecall.c +++ b/lib/sbi/sbi_ecall.c @@ -11,12 +11,6 @@ #include #include #include -#include -#include - -#define SBI_ECALL_VERSION_MAJOR 0 -#define SBI_ECALL_VERSION_MINOR 2 -#define SBI_OPENSBI_IMPID 1 u16 sbi_ecall_version_major(void) { @@ -28,71 +22,6 @@ u16 sbi_ecall_version_minor(void) return SBI_ECALL_VERSION_MINOR; } -static int sbi_ecall_base_probe(struct sbi_scratch *scratch, - unsigned long extid, - unsigned long *out_val) -{ - struct sbi_ecall_extension *ext; - - ext = sbi_ecall_find_extension(extid); - if (!ext) { - *out_val = 0; - return 0; - } - - if (ext->probe) - return ext->probe(scratch, extid, out_val); - - *out_val = 1; - return 0; -} - -static int sbi_ecall_base_handler(struct sbi_scratch *scratch, - unsigned long extid, unsigned long funcid, - unsigned long *args, unsigned long *out_val, - struct sbi_trap_info *out_trap) -{ - int ret = 0; - - switch (funcid) { - case SBI_EXT_BASE_GET_SPEC_VERSION: - *out_val = (SBI_ECALL_VERSION_MAJOR << - SBI_SPEC_VERSION_MAJOR_OFFSET) & - (SBI_SPEC_VERSION_MAJOR_MASK << - SBI_SPEC_VERSION_MAJOR_OFFSET); - *out_val = *out_val | SBI_ECALL_VERSION_MINOR; - break; - case SBI_EXT_BASE_GET_IMP_ID: - *out_val = SBI_OPENSBI_IMPID; - break; - case SBI_EXT_BASE_GET_IMP_VERSION: - *out_val = OPENSBI_VERSION; - break; - case SBI_EXT_BASE_GET_MVENDORID: - *out_val = csr_read(CSR_MVENDORID); - break; - case SBI_EXT_BASE_GET_MARCHID: - *out_val = csr_read(CSR_MARCHID); - break; - case SBI_EXT_BASE_GET_MIMPID: - *out_val = csr_read(CSR_MIMPID); - break; - case SBI_EXT_BASE_PROBE_EXT: - ret = sbi_ecall_base_probe(scratch, args[0], out_val); - break; - default: - ret = SBI_ENOTSUPP; - } - - return ret; -} - -static struct sbi_ecall_extension ecall_base = { - .extid_start = SBI_EXT_BASE, - .extid_end = SBI_EXT_BASE, - .handle = sbi_ecall_base_handler, -}; - 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 new file mode 100644 index 0000000..6475745 --- /dev/null +++ b/lib/sbi/sbi_ecall_base.c @@ -0,0 +1,80 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2020 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel + * Atish Patra + */ + +#include +#include +#include +#include +#include + +static int sbi_ecall_base_probe(struct sbi_scratch *scratch, + unsigned long extid, + unsigned long *out_val) +{ + struct sbi_ecall_extension *ext; + + ext = sbi_ecall_find_extension(extid); + if (!ext) { + *out_val = 0; + return 0; + } + + if (ext->probe) + return ext->probe(scratch, extid, out_val); + + *out_val = 1; + return 0; +} + +static int sbi_ecall_base_handler(struct sbi_scratch *scratch, + unsigned long extid, unsigned long funcid, + unsigned long *args, unsigned long *out_val, + struct sbi_trap_info *out_trap) +{ + int ret = 0; + + switch (funcid) { + case SBI_EXT_BASE_GET_SPEC_VERSION: + *out_val = (SBI_ECALL_VERSION_MAJOR << + SBI_SPEC_VERSION_MAJOR_OFFSET) & + (SBI_SPEC_VERSION_MAJOR_MASK << + SBI_SPEC_VERSION_MAJOR_OFFSET); + *out_val = *out_val | SBI_ECALL_VERSION_MINOR; + break; + case SBI_EXT_BASE_GET_IMP_ID: + *out_val = SBI_OPENSBI_IMPID; + break; + case SBI_EXT_BASE_GET_IMP_VERSION: + *out_val = OPENSBI_VERSION; + break; + case SBI_EXT_BASE_GET_MVENDORID: + *out_val = csr_read(CSR_MVENDORID); + break; + case SBI_EXT_BASE_GET_MARCHID: + *out_val = csr_read(CSR_MARCHID); + break; + case SBI_EXT_BASE_GET_MIMPID: + *out_val = csr_read(CSR_MIMPID); + break; + case SBI_EXT_BASE_PROBE_EXT: + ret = sbi_ecall_base_probe(scratch, args[0], out_val); + break; + default: + ret = SBI_ENOTSUPP; + } + + return ret; +} + +struct sbi_ecall_extension ecall_base = { + .extid_start = SBI_EXT_BASE, + .extid_end = SBI_EXT_BASE, + .handle = sbi_ecall_base_handler, +};