lib: Simplify trap parameters in sbi_ecall functions

The out_tcause and out_tval parameters are not sufficient for most
sbi_ecall functions because this will grow in-future when we support
RISC-V hypervisor v0.5 draft. We replace these parameters with out_trap
which is a pointer to struct sbi_trap_info.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
This commit is contained in:
Anup Patel
2019-11-17 15:25:41 +05:30
committed by Anup Patel
parent 0e1322bacb
commit 75f903dd78
2 changed files with 35 additions and 43 deletions

View File

@@ -41,10 +41,11 @@
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
#include <sbi/sbi_version.h>
#include <sbi/sbi_scratch.h>
#include <sbi/sbi_ecall.h> #include <sbi/sbi_ecall.h>
#include <sbi/sbi_error.h> #include <sbi/sbi_error.h>
#include <sbi/sbi_scratch.h>
#include <sbi/sbi_trap.h>
#include <sbi/sbi_version.h>
/** Possible feature flags of a platform */ /** Possible feature flags of a platform */
enum sbi_platform_features { enum sbi_platform_features {
@@ -119,9 +120,9 @@ struct sbi_platform_operations {
int (*vendor_ext_check)(long extid); int (*vendor_ext_check)(long extid);
/** platform specific SBI extension implementation provider */ /** platform specific SBI extension implementation provider */
int (*vendor_ext_provider)(long extid, long funcid, int (*vendor_ext_provider)(long extid, long funcid,
unsigned long *args, unsigned long *out_value, unsigned long *args,
unsigned long *out_trap_cause, unsigned long *out_value,
unsigned long *out_trap_val); struct sbi_trap_info *out_trap);
} __packed; } __packed;
/** Representation of a platform */ /** Representation of a platform */
@@ -540,25 +541,23 @@ static inline int sbi_platform_vendor_ext_check(const struct sbi_platform *plat,
* @param extid vendor SBI extension id * @param extid vendor SBI extension id
* @param funcid SBI function id within the extension id * @param funcid SBI function id within the extension id
* @param args pointer to arguments passed by the caller * @param args pointer to arguments passed by the caller
* @param out_value output value that can be filled the callee * @param out_value output value that can be filled by the callee
* @param out_tcause trap cause that can be filled the callee * @param out_trap trap info that can be filled by the callee
* @param out_tvalue possible trap value that can be filled the callee
* *
* @return 0 on success and negative error code on failure * @return 0 on success and negative error code on failure
*/ */
static inline int sbi_platform_vendor_ext_provider(const struct sbi_platform *plat, static inline int sbi_platform_vendor_ext_provider(
long extid, long funcid, const struct sbi_platform *plat,
unsigned long *args, long extid, long funcid,
unsigned long *out_value, unsigned long *args,
unsigned long *out_tcause, unsigned long *out_value,
unsigned long *out_tval) struct sbi_trap_info *out_trap)
{ {
if (plat && sbi_platform_ops(plat)->vendor_ext_provider) { if (plat && sbi_platform_ops(plat)->vendor_ext_provider) {
return sbi_platform_ops(plat)->vendor_ext_provider(extid, return sbi_platform_ops(plat)->vendor_ext_provider(extid,
funcid, args, funcid, args,
out_value, out_value,
out_tcause, out_trap);
out_tval);
} }
return SBI_ENOTSUPP; return SBI_ENOTSUPP;

View File

@@ -64,18 +64,17 @@ int sbi_check_extension(struct sbi_scratch *scratch, unsigned long extid,
int sbi_ecall_vendor_ext_handler(struct sbi_scratch *scratch, int sbi_ecall_vendor_ext_handler(struct sbi_scratch *scratch,
unsigned long extid, unsigned long funcid, unsigned long extid, unsigned long funcid,
unsigned long *args, unsigned long *out_val, unsigned long *args, unsigned long *out_val,
unsigned long *out_tcause, struct sbi_trap_info *out_trap)
unsigned long *out_tval)
{ {
return sbi_platform_vendor_ext_provider(sbi_platform_ptr(scratch), return sbi_platform_vendor_ext_provider(sbi_platform_ptr(scratch),
extid, funcid, args, out_val, extid, funcid, args,
out_tcause, out_tval); out_val, out_trap);
} }
int sbi_ecall_base_handler(struct sbi_scratch *scratch, unsigned long extid, int sbi_ecall_base_handler(struct sbi_scratch *scratch,
unsigned long funcid, unsigned long *args, unsigned long extid, unsigned long funcid,
unsigned long *out_val, unsigned long *out_tcause, unsigned long *args, unsigned long *out_val,
unsigned long *out_tval) struct sbi_trap_info *out_trap)
{ {
int ret = 0; int ret = 0;
@@ -111,14 +110,13 @@ int sbi_ecall_base_handler(struct sbi_scratch *scratch, unsigned long extid,
return ret; return ret;
} }
int sbi_ecall_0_1_handler(struct sbi_scratch *scratch, unsigned long extid, int sbi_ecall_0_1_handler(struct sbi_scratch *scratch,
unsigned long *args, unsigned long *tval, unsigned long extid, unsigned long *args,
unsigned long *tcause) struct sbi_trap_info *out_trap)
{ {
int ret = 0; int ret = 0;
struct sbi_tlb_info tlb_info; struct sbi_tlb_info tlb_info;
u32 source_hart = sbi_current_hartid(); u32 source_hart = sbi_current_hartid();
struct sbi_trap_info uptrap = {0};
switch (extid) { switch (extid) {
case SBI_EXT_0_1_SET_TIMER: case SBI_EXT_0_1_SET_TIMER:
@@ -139,7 +137,7 @@ int sbi_ecall_0_1_handler(struct sbi_scratch *scratch, unsigned long extid,
sbi_ipi_clear_smode(scratch); sbi_ipi_clear_smode(scratch);
break; break;
case SBI_EXT_0_1_SEND_IPI: case SBI_EXT_0_1_SEND_IPI:
ret = sbi_ipi_send_many(scratch, &uptrap, (ulong *)args[0], ret = sbi_ipi_send_many(scratch, out_trap, (ulong *)args[0],
SBI_IPI_EVENT_SOFT, NULL); SBI_IPI_EVENT_SOFT, NULL);
break; break;
case SBI_EXT_0_1_REMOTE_FENCE_I: case SBI_EXT_0_1_REMOTE_FENCE_I:
@@ -147,7 +145,7 @@ int sbi_ecall_0_1_handler(struct sbi_scratch *scratch, unsigned long extid,
tlb_info.size = 0; tlb_info.size = 0;
tlb_info.type = SBI_ITLB_FLUSH; tlb_info.type = SBI_ITLB_FLUSH;
tlb_info.shart_mask = 1UL << source_hart; tlb_info.shart_mask = 1UL << source_hart;
ret = sbi_ipi_send_many(scratch, &uptrap, (ulong *)args[0], ret = sbi_ipi_send_many(scratch, out_trap, (ulong *)args[0],
SBI_IPI_EVENT_FENCE_I, &tlb_info); SBI_IPI_EVENT_FENCE_I, &tlb_info);
break; break;
case SBI_EXT_0_1_REMOTE_SFENCE_VMA: case SBI_EXT_0_1_REMOTE_SFENCE_VMA:
@@ -156,7 +154,7 @@ int sbi_ecall_0_1_handler(struct sbi_scratch *scratch, unsigned long extid,
tlb_info.type = SBI_TLB_FLUSH_VMA; tlb_info.type = SBI_TLB_FLUSH_VMA;
tlb_info.shart_mask = 1UL << source_hart; tlb_info.shart_mask = 1UL << source_hart;
ret = sbi_ipi_send_many(scratch, &uptrap, (ulong *)args[0], ret = sbi_ipi_send_many(scratch, out_trap, (ulong *)args[0],
SBI_IPI_EVENT_SFENCE_VMA, &tlb_info); SBI_IPI_EVENT_SFENCE_VMA, &tlb_info);
break; break;
case SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID: case SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID:
@@ -166,7 +164,7 @@ int sbi_ecall_0_1_handler(struct sbi_scratch *scratch, unsigned long extid,
tlb_info.type = SBI_TLB_FLUSH_VMA_ASID; tlb_info.type = SBI_TLB_FLUSH_VMA_ASID;
tlb_info.shart_mask = 1UL << source_hart; tlb_info.shart_mask = 1UL << source_hart;
ret = sbi_ipi_send_many(scratch, &uptrap, (ulong *)args[0], ret = sbi_ipi_send_many(scratch, out_trap, (ulong *)args[0],
SBI_IPI_EVENT_SFENCE_VMA_ASID, SBI_IPI_EVENT_SFENCE_VMA_ASID,
&tlb_info); &tlb_info);
break; break;
@@ -177,10 +175,6 @@ int sbi_ecall_0_1_handler(struct sbi_scratch *scratch, unsigned long extid,
ret = SBI_ENOTSUPP; ret = SBI_ENOTSUPP;
}; };
if (ret == SBI_ETRAP) {
*tcause = uptrap.cause;
*tval = uptrap.tval;
}
return ret; return ret;
} }
@@ -204,18 +198,17 @@ int sbi_ecall_handler(u32 hartid, ulong mcause, struct sbi_trap_regs *regs,
if (extension_id >= SBI_EXT_0_1_SET_TIMER && if (extension_id >= SBI_EXT_0_1_SET_TIMER &&
extension_id <= SBI_EXT_0_1_SHUTDOWN) { extension_id <= SBI_EXT_0_1_SHUTDOWN) {
ret = sbi_ecall_0_1_handler(scratch, extension_id, args, ret = sbi_ecall_0_1_handler(scratch, extension_id,
&trap.tval, &trap.cause); args, &trap);
is_0_1_spec = 1; is_0_1_spec = 1;
} else if (extension_id == SBI_EXT_BASE) } else if (extension_id == SBI_EXT_BASE)
ret = sbi_ecall_base_handler(scratch, extension_id, func_id, ret = sbi_ecall_base_handler(scratch, extension_id, func_id,
args, &out_val, args, &out_val, &trap);
&trap.tval, &trap.cause);
else if (extension_id >= SBI_EXT_VENDOR_START && else if (extension_id >= SBI_EXT_VENDOR_START &&
extension_id <= SBI_EXT_VENDOR_END) { extension_id <= SBI_EXT_VENDOR_END) {
ret = sbi_ecall_vendor_ext_handler(scratch, extension_id, ret = sbi_ecall_vendor_ext_handler(scratch, extension_id,
func_id, args, &out_val, func_id, args, &out_val,
&trap.tval, &trap.cause); &trap);
} else { } else {
ret = SBI_ENOTSUPP; ret = SBI_ENOTSUPP;
} }