aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/firmware/fw_payload.md2
-rw-r--r--lib/sbi/Kconfig4
-rw-r--r--lib/sbi/objects.mk3
-rw-r--r--lib/sbi/sbi_dbtr.c20
-rw-r--r--lib/sbi/sbi_ecall_fwft.c49
-rw-r--r--lib/sbi/sbi_fwft.c14
6 files changed, 80 insertions, 12 deletions
diff --git a/docs/firmware/fw_payload.md b/docs/firmware/fw_payload.md
index d25be60..9b00e32 100644
--- a/docs/firmware/fw_payload.md
+++ b/docs/firmware/fw_payload.md
@@ -23,7 +23,7 @@ The *FW_PAYLOAD* firmware can be enabled by any of the following methods:
2. Specifying `FW_PAYLOAD=y` in the target platform *objects.mk* configuration
file.
-The compiled *FW_PAYLOAD* firmware ELF file is named *fw_jump.elf*. Its
+The compiled *FW_PAYLOAD* firmware ELF file is named *fw_payload.elf*. Its
expanded image file is *fw_payload.bin*. Both files are created in the
platform-specific build directory under the
*build/platform/<platform_subdir>/firmware* directory.
diff --git a/lib/sbi/Kconfig b/lib/sbi/Kconfig
index cc8e031..6cf54ce 100644
--- a/lib/sbi/Kconfig
+++ b/lib/sbi/Kconfig
@@ -38,6 +38,10 @@ config SBI_ECALL_CPPC
bool "CPPC extension"
default y
+config SBI_ECALL_FWFT
+ bool "Firmware Feature extension"
+ default y
+
config SBI_ECALL_LEGACY
bool "SBI v0.1 legacy extensions"
default y
diff --git a/lib/sbi/objects.mk b/lib/sbi/objects.mk
index 221e72c..211abad 100644
--- a/lib/sbi/objects.mk
+++ b/lib/sbi/objects.mk
@@ -46,6 +46,9 @@ libsbi-objs-$(CONFIG_SBI_ECALL_DBCN) += sbi_ecall_dbcn.o
carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_CPPC) += ecall_cppc
libsbi-objs-$(CONFIG_SBI_ECALL_CPPC) += sbi_ecall_cppc.o
+carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_FWFT) += ecall_fwft
+libsbi-objs-$(CONFIG_SBI_ECALL_FWFT) += sbi_ecall_fwft.o
+
carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_LEGACY) += ecall_legacy
libsbi-objs-$(CONFIG_SBI_ECALL_LEGACY) += sbi_ecall_legacy.o
diff --git a/lib/sbi/sbi_dbtr.c b/lib/sbi/sbi_dbtr.c
index 9c92af6..6e2083e 100644
--- a/lib/sbi/sbi_dbtr.c
+++ b/lib/sbi/sbi_dbtr.c
@@ -47,13 +47,7 @@ static unsigned long hart_state_ptr_offset;
_idx < _max; \
_idx++, _entry = ((_etype *)_base + _idx))
-#if __riscv_xlen == 64
#define DBTR_SHMEM_MAKE_PHYS(_p_hi, _p_lo) (_p_lo)
-#elif __riscv_xlen == 32
-#define DBTR_SHMEM_MAKE_PHYS(_p_hi, _p_lo) (((u64)(_p_hi) << 32) | (_p_lo))
-#else
-#error "Undefined XLEN"
-#endif
/* must call with hs != NULL */
static inline bool sbi_dbtr_shmem_disabled(
@@ -277,6 +271,20 @@ int sbi_dbtr_setup_shmem(const struct sbi_domain *dom, unsigned long smode,
if (shmem_phys_lo & SBI_DBTR_SHMEM_ALIGN_MASK)
return SBI_ERR_INVALID_PARAM;
+ /*
+ * On RV32, the M-mode can only access the first 4GB of
+ * the physical address space because M-mode does not have
+ * MMU to access full 34-bit physical address space.
+ * So fail if the upper 32 bits of the physical address
+ * is non-zero on RV32.
+ *
+ * On RV64, kernel sets upper 64bit address part to zero.
+ * So fail if the upper 64bit of the physical address
+ * is non-zero on RV64.
+ */
+ if (shmem_phys_hi)
+ return SBI_EINVALID_ADDR;
+
if (dom && !sbi_domain_check_addr(dom,
DBTR_SHMEM_MAKE_PHYS(shmem_phys_hi, shmem_phys_lo), smode,
SBI_DOMAIN_READ | SBI_DOMAIN_WRITE))
diff --git a/lib/sbi/sbi_ecall_fwft.c b/lib/sbi/sbi_ecall_fwft.c
new file mode 100644
index 0000000..267cbab
--- /dev/null
+++ b/lib/sbi/sbi_ecall_fwft.c
@@ -0,0 +1,49 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Rivos Inc.
+ *
+ * Authors:
+ * Clément Léger <cleger@rivosinc.com>
+ */
+
+#include <sbi/sbi_ecall.h>
+#include <sbi/sbi_ecall_interface.h>
+#include <sbi/sbi_error.h>
+#include <sbi/sbi_fwft.h>
+#include <sbi/sbi_trap.h>
+
+static int sbi_ecall_fwft_handler(unsigned long extid, unsigned long funcid,
+ struct sbi_trap_regs *regs,
+ struct sbi_ecall_return *out)
+{
+ int ret = 0;
+
+ switch (funcid) {
+ case SBI_EXT_FWFT_SET:
+ ret = sbi_fwft_set(regs->a0, regs->a1, regs->a2);
+ break;
+ case SBI_EXT_FWFT_GET:
+ ret = sbi_fwft_get(regs->a0, &out->value);
+ break;
+ default:
+ ret = SBI_ENOTSUPP;
+ break;
+ }
+
+ return ret;
+}
+
+struct sbi_ecall_extension ecall_fwft;
+
+static int sbi_ecall_fwft_register_extensions(void)
+{
+ return sbi_ecall_register_extension(&ecall_fwft);
+}
+
+struct sbi_ecall_extension ecall_fwft = {
+ .extid_start = SBI_EXT_FWFT,
+ .extid_end = SBI_EXT_FWFT,
+ .register_extensions = sbi_ecall_fwft_register_extensions,
+ .handle = sbi_ecall_fwft_handler,
+};
diff --git a/lib/sbi/sbi_fwft.c b/lib/sbi/sbi_fwft.c
index aff087f..f1ae915 100644
--- a/lib/sbi/sbi_fwft.c
+++ b/lib/sbi/sbi_fwft.c
@@ -84,10 +84,12 @@ static int fwft_misaligned_delegation_supported(struct fwft_config *conf)
static int fwft_set_misaligned_delegation(struct fwft_config *conf,
unsigned long value)
{
- if (value)
+ if (value == 1)
csr_set(CSR_MEDELEG, MIS_DELEG);
- else
+ else if (value == 0)
csr_clear(CSR_MEDELEG, MIS_DELEG);
+ else
+ return SBI_EINVAL;
return SBI_OK;
}
@@ -111,18 +113,20 @@ static int fwft_adue_supported(struct fwft_config *conf)
static int fwft_set_adue(struct fwft_config *conf, unsigned long value)
{
- if (value)
+ if (value == 1)
#if __riscv_xlen == 32
csr_set(CSR_MENVCFGH, ENVCFG_ADUE >> 32);
#else
csr_set(CSR_MENVCFG, ENVCFG_ADUE);
#endif
- else
+ else if (value == 0)
#if __riscv_xlen == 32
csr_clear(CSR_MENVCFGH, ENVCFG_ADUE >> 32);
#else
csr_clear(CSR_MENVCFG, ENVCFG_ADUE);
#endif
+ else
+ return SBI_EINVAL;
return SBI_OK;
}
@@ -192,7 +196,7 @@ int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value,
return ret;
if ((flags & ~SBI_FWFT_SET_FLAG_LOCK) != 0)
- return SBI_ERR_INVALID_PARAM;
+ return SBI_EINVAL;
if (conf->flags & SBI_FWFT_SET_FLAG_LOCK)
return SBI_EDENIED;