* [PATCH v3 1/4] lib: sbi: add support for firmware features extension
2024-06-19 9:42 [PATCH v3 0/4] Add SBI FWFT extension support Clément Léger
@ 2024-06-19 9:42 ` Clément Léger
2024-06-19 12:47 ` Anup Patel
2024-06-19 9:42 ` [PATCH v3 2/4] lib: sbi: fwft: add support for SBI_FWFT_MISALIGNED_EXC_DELEG Clément Léger
` (2 subsequent siblings)
3 siblings, 1 reply; 11+ messages in thread
From: Clément Léger @ 2024-06-19 9:42 UTC (permalink / raw)
To: opensbi
This extension allows the software running in supervisor mode to control
the behavior of various features of the SBI [1]. Implement the support
for such extension.
Link: https://lists.riscv.org/g/tech-prs/message/924 [1]
Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
---
include/sbi/sbi_ecall_interface.h | 27 +++++
include/sbi/sbi_fwft.h | 23 ++++
lib/sbi/objects.mk | 1 +
lib/sbi/sbi_fwft.c | 178 ++++++++++++++++++++++++++++++
lib/sbi/sbi_init.c | 11 ++
5 files changed, 240 insertions(+)
create mode 100644 include/sbi/sbi_fwft.h
create mode 100644 lib/sbi/sbi_fwft.c
diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h
index 2600b66..e9a8167 100644
--- a/include/sbi/sbi_ecall_interface.h
+++ b/include/sbi/sbi_ecall_interface.h
@@ -34,6 +34,7 @@
#define SBI_EXT_CPPC 0x43505043
#define SBI_EXT_DBTR 0x44425452
#define SBI_EXT_SSE 0x535345
+#define SBI_EXT_FWFT 0x46574654
/* SBI function IDs for BASE extension*/
#define SBI_EXT_BASE_GET_SPEC_VERSION 0x0
@@ -117,6 +118,32 @@
#define SBI_EXT_DBTR_TRIGGER_ENABLE 0x6
#define SBI_EXT_DBTR_TRIGGER_DISABLE 0x7
+/* SBI function IDs for FW feature extension */
+#define SBI_EXT_FWFT_SET 0x0
+#define SBI_EXT_FWFT_GET 0x1
+
+enum sbi_fwft_feature_t {
+ SBI_FWFT_MISALIGNED_EXC_DELEG = 0x0,
+ SBI_FWFT_LANDING_PAD = 0x1,
+ SBI_FWFT_SHADOW_STACK = 0x2,
+ SBI_FWFT_DOUBLE_TRAP = 0x3,
+ SBI_FWFT_PTE_AD_HW_UPDATING = 0x4,
+ SBI_FWFT_LOCAL_RESERVED_START = 0x5,
+ SBI_FWFT_LOCAL_RESERVED_END = 0x3fffffff,
+ SBI_FWFT_LOCAL_PLATFORM_START = 0x40000000,
+ SBI_FWFT_LOCAL_PLATFORM_END = 0x7fffffff,
+
+ SBI_FWFT_GLOBAL_RESERVED_START = 0x80000000,
+ SBI_FWFT_GLOBAL_RESERVED_END = 0xbfffffff,
+ SBI_FWFT_GLOBAL_PLATFORM_START = 0xc0000000,
+ SBI_FWFT_GLOBAL_PLATFORM_END = 0xffffffff,
+};
+
+#define SBI_FWFT_GLOBAL_FEATURE_BIT (1 << 31)
+#define SBI_FWFT_PLATFORM_FEATURE_BIT (1 << 30)
+
+#define SBI_FWFT_SET_FLAG_LOCK (1 << 0)
+
/** General pmu event codes specified in SBI PMU extension */
enum sbi_pmu_hw_generic_events_t {
SBI_PMU_HW_NO_EVENT = 0,
diff --git a/include/sbi/sbi_fwft.h b/include/sbi/sbi_fwft.h
new file mode 100644
index 0000000..2148820
--- /dev/null
+++ b/include/sbi/sbi_fwft.h
@@ -0,0 +1,23 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Rivos Inc.
+ *
+ * Authors:
+ * Cl?ment L?ger <cleger@rivosinc.com>
+ */
+
+#ifndef __SBI_FW_FEATURE_H__
+#define __SBI_FW_FEATURE_H__
+
+#include <sbi/sbi_ecall_interface.h>
+
+struct sbi_scratch;
+
+int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value,
+ unsigned long flags);
+int sbi_fwft_get(enum sbi_fwft_feature_t feature, unsigned long *out_val);
+
+int sbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot);
+
+#endif
diff --git a/lib/sbi/objects.mk b/lib/sbi/objects.mk
index b1c4a50..221e72c 100644
--- a/lib/sbi/objects.mk
+++ b/lib/sbi/objects.mk
@@ -65,6 +65,7 @@ libsbi-objs-y += sbi_domain_context.o
libsbi-objs-y += sbi_domain.o
libsbi-objs-y += sbi_emulate_csr.o
libsbi-objs-y += sbi_fifo.o
+libsbi-objs-y += sbi_fwft.o
libsbi-objs-y += sbi_hart.o
libsbi-objs-y += sbi_heap.o
libsbi-objs-y += sbi_math.o
diff --git a/lib/sbi/sbi_fwft.c b/lib/sbi/sbi_fwft.c
new file mode 100644
index 0000000..b302b5d
--- /dev/null
+++ b/lib/sbi/sbi_fwft.c
@@ -0,0 +1,178 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Rivos Inc.
+ *
+ * Authors:
+ * Cl?ment L?ger <cleger@rivosinc.com>
+ */
+
+#include <sbi/sbi_console.h>
+#include <sbi/sbi_bitmap.h>
+#include <sbi/sbi_ecall_interface.h>
+#include <sbi/sbi_error.h>
+#include <sbi/sbi_hart.h>
+#include <sbi/sbi_heap.h>
+#include <sbi/sbi_scratch.h>
+#include <sbi/sbi_string.h>
+#include <sbi/sbi_types.h>
+
+#include <sbi/riscv_asm.h>
+#include <sbi/riscv_encoding.h>
+
+/** Offset of pointer to FWFT HART state in scratch space */
+static unsigned long fwft_ptr_offset;
+
+#define fwft_get_hart_state_ptr(__scratch) \
+ sbi_scratch_read_type((__scratch), void *, fwft_ptr_offset)
+
+#define fwft_thishart_state_ptr() \
+ fwft_get_hart_state_ptr(sbi_scratch_thishart_ptr())
+
+#define fwft_set_hart_state_ptr(__scratch, __phs) \
+ sbi_scratch_write_type((__scratch), void *, fwft_ptr_offset, (__phs))
+
+struct fwft_config;
+
+struct fwft_feature {
+ enum sbi_fwft_feature_t id;
+ int (*supported)(struct fwft_config *conf);
+ int (*set)(struct fwft_config *conf, unsigned long value);
+ int (*get)(struct fwft_config *conf, unsigned long *value);
+};
+
+struct fwft_config {
+ const struct fwft_feature *feature;
+ unsigned long flags;
+};
+
+struct fwft_hart_state {
+ unsigned int config_count;
+ struct fwft_config configs[];
+};
+
+static const unsigned long fwft_defined_features[] = {
+ SBI_FWFT_MISALIGNED_EXC_DELEG,
+ SBI_FWFT_LANDING_PAD,
+ SBI_FWFT_SHADOW_STACK,
+ SBI_FWFT_DOUBLE_TRAP,
+ SBI_FWFT_PTE_AD_HW_UPDATING,
+};
+
+static bool fwft_is_defined_feature(enum sbi_fwft_feature_t feature)
+{
+ int i;
+
+ for (i = 0; i < array_size(fwft_defined_features); i++) {
+ if (fwft_defined_features[i] == feature)
+ return true;
+ }
+
+ return false;
+}
+
+static struct fwft_config* get_feature_config(enum sbi_fwft_feature_t feature)
+{
+ int i;
+ struct fwft_hart_state *fhs = fwft_thishart_state_ptr();
+
+ if (feature & SBI_FWFT_GLOBAL_FEATURE_BIT)
+ return NULL;
+
+ for (i = 0; i < fhs->config_count; i++){
+ if (feature == fhs->configs[i].feature->id)
+ return &fhs->configs[i];
+ }
+
+ return NULL;
+}
+
+static int fwft_get_feature(enum sbi_fwft_feature_t feature,
+ struct fwft_config **conf)
+{
+ int ret;
+ struct fwft_config *tconf;
+
+ tconf = get_feature_config(feature);
+ if (!tconf) {
+ if (fwft_is_defined_feature(feature))
+ return SBI_ENOTSUPP;
+
+ return SBI_EDENIED;
+ }
+
+ if (tconf->feature->supported) {
+ ret = tconf->feature->supported(tconf);
+ if (ret)
+ return ret;
+ }
+ *conf = tconf;
+
+ return SBI_SUCCESS;
+}
+
+int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value,
+ unsigned long flags)
+{
+ int ret;
+ struct fwft_config *conf;
+
+ ret = fwft_get_feature(feature, &conf);
+ if (ret)
+ return ret;
+
+ if ((flags & ~SBI_FWFT_SET_FLAG_LOCK) != 0)
+ return SBI_ERR_INVALID_PARAM;
+
+ if (conf->flags & SBI_FWFT_SET_FLAG_LOCK)
+ return SBI_EDENIED;
+
+ ret = conf->feature->set(conf, value);
+ if (ret)
+ return ret;
+
+ conf->flags = flags;
+
+ return SBI_OK;
+}
+
+int sbi_fwft_get(enum sbi_fwft_feature_t feature, unsigned long *out_val)
+{
+ int ret;
+ struct fwft_config *conf;
+
+ ret = fwft_get_feature(feature, &conf);
+ if (ret)
+ return ret;
+
+ return conf->feature->get(conf, out_val);
+}
+
+static const struct fwft_feature features[] = {};
+
+int sbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot)
+{
+ int i;
+ struct fwft_hart_state *fhs;
+
+ if (cold_boot) {
+ fwft_ptr_offset = sbi_scratch_alloc_type_offset(void *);
+ if (!fwft_ptr_offset)
+ return SBI_ENOMEM;
+ }
+
+ fhs = fwft_get_hart_state_ptr(scratch);
+ if (!fhs) {
+ fhs = sbi_zalloc(sizeof(fhs) + array_size(features) * sizeof(struct fwft_config));
+ if (!fhs)
+ return SBI_ENOMEM;
+
+ fhs->config_count = array_size(features);
+ for (i = 0; i < array_size(features); i++)
+ fhs->configs[i].feature = &features[i];
+
+ fwft_set_hart_state_ptr(scratch, fhs);
+ }
+
+ return 0;
+}
diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c
index 389172a..0f9e14c 100644
--- a/lib/sbi/sbi_init.c
+++ b/lib/sbi/sbi_init.c
@@ -14,6 +14,7 @@
#include <sbi/sbi_cppc.h>
#include <sbi/sbi_domain.h>
#include <sbi/sbi_ecall.h>
+#include <sbi/sbi_fwft.h>
#include <sbi/sbi_hart.h>
#include <sbi/sbi_hartmask.h>
#include <sbi/sbi_heap.h>
@@ -308,6 +309,12 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
sbi_hart_hang();
}
+ rc = sbi_fwft_init(scratch, true);
+ if (rc) {
+ sbi_printf("%s: fwft init failed (error %d)\n", __func__, rc);
+ sbi_hart_hang();
+ }
+
/*
* Note: Finalize domains after HSM initialization so that we
* can startup non-root domains.
@@ -423,6 +430,10 @@ static void __noreturn init_warm_startup(struct sbi_scratch *scratch,
if (rc)
sbi_hart_hang();
+ rc = sbi_fwft_init(scratch, false);
+ if (rc)
+ sbi_hart_hang();
+
rc = sbi_platform_final_init(plat, false);
if (rc)
sbi_hart_hang();
--
2.45.2
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH v3 1/4] lib: sbi: add support for firmware features extension
2024-06-19 9:42 ` [PATCH v3 1/4] lib: sbi: add support for firmware features extension Clément Léger
@ 2024-06-19 12:47 ` Anup Patel
0 siblings, 0 replies; 11+ messages in thread
From: Anup Patel @ 2024-06-19 12:47 UTC (permalink / raw)
To: opensbi
On Wed, Jun 19, 2024 at 3:13?PM Cl?ment L?ger <cleger@rivosinc.com> wrote:
>
> This extension allows the software running in supervisor mode to control
> the behavior of various features of the SBI [1]. Implement the support
> for such extension.
>
> Link: https://lists.riscv.org/g/tech-prs/message/924 [1]
> Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
I had already reviewed the previous revision of this patch.
Reviewed-by: Anup Patel <anup@brainfault.org>
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
> ---
> include/sbi/sbi_ecall_interface.h | 27 +++++
> include/sbi/sbi_fwft.h | 23 ++++
> lib/sbi/objects.mk | 1 +
> lib/sbi/sbi_fwft.c | 178 ++++++++++++++++++++++++++++++
> lib/sbi/sbi_init.c | 11 ++
> 5 files changed, 240 insertions(+)
> create mode 100644 include/sbi/sbi_fwft.h
> create mode 100644 lib/sbi/sbi_fwft.c
>
> diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h
> index 2600b66..e9a8167 100644
> --- a/include/sbi/sbi_ecall_interface.h
> +++ b/include/sbi/sbi_ecall_interface.h
> @@ -34,6 +34,7 @@
> #define SBI_EXT_CPPC 0x43505043
> #define SBI_EXT_DBTR 0x44425452
> #define SBI_EXT_SSE 0x535345
> +#define SBI_EXT_FWFT 0x46574654
>
> /* SBI function IDs for BASE extension*/
> #define SBI_EXT_BASE_GET_SPEC_VERSION 0x0
> @@ -117,6 +118,32 @@
> #define SBI_EXT_DBTR_TRIGGER_ENABLE 0x6
> #define SBI_EXT_DBTR_TRIGGER_DISABLE 0x7
>
> +/* SBI function IDs for FW feature extension */
> +#define SBI_EXT_FWFT_SET 0x0
> +#define SBI_EXT_FWFT_GET 0x1
> +
> +enum sbi_fwft_feature_t {
> + SBI_FWFT_MISALIGNED_EXC_DELEG = 0x0,
> + SBI_FWFT_LANDING_PAD = 0x1,
> + SBI_FWFT_SHADOW_STACK = 0x2,
> + SBI_FWFT_DOUBLE_TRAP = 0x3,
> + SBI_FWFT_PTE_AD_HW_UPDATING = 0x4,
> + SBI_FWFT_LOCAL_RESERVED_START = 0x5,
> + SBI_FWFT_LOCAL_RESERVED_END = 0x3fffffff,
> + SBI_FWFT_LOCAL_PLATFORM_START = 0x40000000,
> + SBI_FWFT_LOCAL_PLATFORM_END = 0x7fffffff,
> +
> + SBI_FWFT_GLOBAL_RESERVED_START = 0x80000000,
> + SBI_FWFT_GLOBAL_RESERVED_END = 0xbfffffff,
> + SBI_FWFT_GLOBAL_PLATFORM_START = 0xc0000000,
> + SBI_FWFT_GLOBAL_PLATFORM_END = 0xffffffff,
> +};
> +
> +#define SBI_FWFT_GLOBAL_FEATURE_BIT (1 << 31)
> +#define SBI_FWFT_PLATFORM_FEATURE_BIT (1 << 30)
> +
> +#define SBI_FWFT_SET_FLAG_LOCK (1 << 0)
> +
> /** General pmu event codes specified in SBI PMU extension */
> enum sbi_pmu_hw_generic_events_t {
> SBI_PMU_HW_NO_EVENT = 0,
> diff --git a/include/sbi/sbi_fwft.h b/include/sbi/sbi_fwft.h
> new file mode 100644
> index 0000000..2148820
> --- /dev/null
> +++ b/include/sbi/sbi_fwft.h
> @@ -0,0 +1,23 @@
> +/*
> + * SPDX-License-Identifier: BSD-2-Clause
> + *
> + * Copyright (c) 2024 Rivos Inc.
> + *
> + * Authors:
> + * Cl?ment L?ger <cleger@rivosinc.com>
> + */
> +
> +#ifndef __SBI_FW_FEATURE_H__
> +#define __SBI_FW_FEATURE_H__
> +
> +#include <sbi/sbi_ecall_interface.h>
> +
> +struct sbi_scratch;
> +
> +int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value,
> + unsigned long flags);
> +int sbi_fwft_get(enum sbi_fwft_feature_t feature, unsigned long *out_val);
> +
> +int sbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot);
> +
> +#endif
> diff --git a/lib/sbi/objects.mk b/lib/sbi/objects.mk
> index b1c4a50..221e72c 100644
> --- a/lib/sbi/objects.mk
> +++ b/lib/sbi/objects.mk
> @@ -65,6 +65,7 @@ libsbi-objs-y += sbi_domain_context.o
> libsbi-objs-y += sbi_domain.o
> libsbi-objs-y += sbi_emulate_csr.o
> libsbi-objs-y += sbi_fifo.o
> +libsbi-objs-y += sbi_fwft.o
> libsbi-objs-y += sbi_hart.o
> libsbi-objs-y += sbi_heap.o
> libsbi-objs-y += sbi_math.o
> diff --git a/lib/sbi/sbi_fwft.c b/lib/sbi/sbi_fwft.c
> new file mode 100644
> index 0000000..b302b5d
> --- /dev/null
> +++ b/lib/sbi/sbi_fwft.c
> @@ -0,0 +1,178 @@
> +/*
> + * SPDX-License-Identifier: BSD-2-Clause
> + *
> + * Copyright (c) 2024 Rivos Inc.
> + *
> + * Authors:
> + * Cl?ment L?ger <cleger@rivosinc.com>
> + */
> +
> +#include <sbi/sbi_console.h>
> +#include <sbi/sbi_bitmap.h>
> +#include <sbi/sbi_ecall_interface.h>
> +#include <sbi/sbi_error.h>
> +#include <sbi/sbi_hart.h>
> +#include <sbi/sbi_heap.h>
> +#include <sbi/sbi_scratch.h>
> +#include <sbi/sbi_string.h>
> +#include <sbi/sbi_types.h>
> +
> +#include <sbi/riscv_asm.h>
> +#include <sbi/riscv_encoding.h>
> +
> +/** Offset of pointer to FWFT HART state in scratch space */
> +static unsigned long fwft_ptr_offset;
> +
> +#define fwft_get_hart_state_ptr(__scratch) \
> + sbi_scratch_read_type((__scratch), void *, fwft_ptr_offset)
> +
> +#define fwft_thishart_state_ptr() \
> + fwft_get_hart_state_ptr(sbi_scratch_thishart_ptr())
> +
> +#define fwft_set_hart_state_ptr(__scratch, __phs) \
> + sbi_scratch_write_type((__scratch), void *, fwft_ptr_offset, (__phs))
> +
> +struct fwft_config;
> +
> +struct fwft_feature {
> + enum sbi_fwft_feature_t id;
> + int (*supported)(struct fwft_config *conf);
> + int (*set)(struct fwft_config *conf, unsigned long value);
> + int (*get)(struct fwft_config *conf, unsigned long *value);
> +};
> +
> +struct fwft_config {
> + const struct fwft_feature *feature;
> + unsigned long flags;
> +};
> +
> +struct fwft_hart_state {
> + unsigned int config_count;
> + struct fwft_config configs[];
> +};
> +
> +static const unsigned long fwft_defined_features[] = {
> + SBI_FWFT_MISALIGNED_EXC_DELEG,
> + SBI_FWFT_LANDING_PAD,
> + SBI_FWFT_SHADOW_STACK,
> + SBI_FWFT_DOUBLE_TRAP,
> + SBI_FWFT_PTE_AD_HW_UPDATING,
> +};
> +
> +static bool fwft_is_defined_feature(enum sbi_fwft_feature_t feature)
> +{
> + int i;
> +
> + for (i = 0; i < array_size(fwft_defined_features); i++) {
> + if (fwft_defined_features[i] == feature)
> + return true;
> + }
> +
> + return false;
> +}
> +
> +static struct fwft_config* get_feature_config(enum sbi_fwft_feature_t feature)
> +{
> + int i;
> + struct fwft_hart_state *fhs = fwft_thishart_state_ptr();
> +
> + if (feature & SBI_FWFT_GLOBAL_FEATURE_BIT)
> + return NULL;
> +
> + for (i = 0; i < fhs->config_count; i++){
> + if (feature == fhs->configs[i].feature->id)
> + return &fhs->configs[i];
> + }
> +
> + return NULL;
> +}
> +
> +static int fwft_get_feature(enum sbi_fwft_feature_t feature,
> + struct fwft_config **conf)
> +{
> + int ret;
> + struct fwft_config *tconf;
> +
> + tconf = get_feature_config(feature);
> + if (!tconf) {
> + if (fwft_is_defined_feature(feature))
> + return SBI_ENOTSUPP;
> +
> + return SBI_EDENIED;
> + }
> +
> + if (tconf->feature->supported) {
> + ret = tconf->feature->supported(tconf);
> + if (ret)
> + return ret;
> + }
> + *conf = tconf;
> +
> + return SBI_SUCCESS;
> +}
> +
> +int sbi_fwft_set(enum sbi_fwft_feature_t feature, unsigned long value,
> + unsigned long flags)
> +{
> + int ret;
> + struct fwft_config *conf;
> +
> + ret = fwft_get_feature(feature, &conf);
> + if (ret)
> + return ret;
> +
> + if ((flags & ~SBI_FWFT_SET_FLAG_LOCK) != 0)
> + return SBI_ERR_INVALID_PARAM;
> +
> + if (conf->flags & SBI_FWFT_SET_FLAG_LOCK)
> + return SBI_EDENIED;
> +
> + ret = conf->feature->set(conf, value);
> + if (ret)
> + return ret;
> +
> + conf->flags = flags;
> +
> + return SBI_OK;
> +}
> +
> +int sbi_fwft_get(enum sbi_fwft_feature_t feature, unsigned long *out_val)
> +{
> + int ret;
> + struct fwft_config *conf;
> +
> + ret = fwft_get_feature(feature, &conf);
> + if (ret)
> + return ret;
> +
> + return conf->feature->get(conf, out_val);
> +}
> +
> +static const struct fwft_feature features[] = {};
> +
> +int sbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot)
> +{
> + int i;
> + struct fwft_hart_state *fhs;
> +
> + if (cold_boot) {
> + fwft_ptr_offset = sbi_scratch_alloc_type_offset(void *);
> + if (!fwft_ptr_offset)
> + return SBI_ENOMEM;
> + }
> +
> + fhs = fwft_get_hart_state_ptr(scratch);
> + if (!fhs) {
> + fhs = sbi_zalloc(sizeof(fhs) + array_size(features) * sizeof(struct fwft_config));
> + if (!fhs)
> + return SBI_ENOMEM;
> +
> + fhs->config_count = array_size(features);
> + for (i = 0; i < array_size(features); i++)
> + fhs->configs[i].feature = &features[i];
> +
> + fwft_set_hart_state_ptr(scratch, fhs);
> + }
> +
> + return 0;
> +}
> diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c
> index 389172a..0f9e14c 100644
> --- a/lib/sbi/sbi_init.c
> +++ b/lib/sbi/sbi_init.c
> @@ -14,6 +14,7 @@
> #include <sbi/sbi_cppc.h>
> #include <sbi/sbi_domain.h>
> #include <sbi/sbi_ecall.h>
> +#include <sbi/sbi_fwft.h>
> #include <sbi/sbi_hart.h>
> #include <sbi/sbi_hartmask.h>
> #include <sbi/sbi_heap.h>
> @@ -308,6 +309,12 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
> sbi_hart_hang();
> }
>
> + rc = sbi_fwft_init(scratch, true);
> + if (rc) {
> + sbi_printf("%s: fwft init failed (error %d)\n", __func__, rc);
> + sbi_hart_hang();
> + }
> +
> /*
> * Note: Finalize domains after HSM initialization so that we
> * can startup non-root domains.
> @@ -423,6 +430,10 @@ static void __noreturn init_warm_startup(struct sbi_scratch *scratch,
> if (rc)
> sbi_hart_hang();
>
> + rc = sbi_fwft_init(scratch, false);
> + if (rc)
> + sbi_hart_hang();
> +
> rc = sbi_platform_final_init(plat, false);
> if (rc)
> sbi_hart_hang();
> --
> 2.45.2
>
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v3 2/4] lib: sbi: fwft: add support for SBI_FWFT_MISALIGNED_EXC_DELEG
2024-06-19 9:42 [PATCH v3 0/4] Add SBI FWFT extension support Clément Léger
2024-06-19 9:42 ` [PATCH v3 1/4] lib: sbi: add support for firmware features extension Clément Léger
@ 2024-06-19 9:42 ` Clément Léger
2024-06-19 12:48 ` Anup Patel
2024-06-21 13:50 ` Andrew Jones
2024-06-19 9:42 ` [PATCH v3 3/4] lib: sbi: fwft: add support for SBI_FWFT_PTE_AD_HW_UPDATING Clément Léger
2024-06-19 9:42 ` [PATCH v3 4/4] lib: sbi: implement SBI FWFT extension Clément Léger
3 siblings, 2 replies; 11+ messages in thread
From: Clément Léger @ 2024-06-19 9:42 UTC (permalink / raw)
To: opensbi
Add support for SBI_FWFT_MISALIGNED_EXC_DELEG withing FWFT support. This
support allows to delegate misaligned accesses traps.
Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
---
lib/sbi/sbi_fwft.c | 39 ++++++++++++++++++++++++++++++++++++++-
lib/sbi/sbi_hsm.c | 3 +++
2 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/lib/sbi/sbi_fwft.c b/lib/sbi/sbi_fwft.c
index b302b5d..289a344 100644
--- a/lib/sbi/sbi_fwft.c
+++ b/lib/sbi/sbi_fwft.c
@@ -32,6 +32,8 @@ static unsigned long fwft_ptr_offset;
#define fwft_set_hart_state_ptr(__scratch, __phs) \
sbi_scratch_write_type((__scratch), void *, fwft_ptr_offset, (__phs))
+#define MIS_DELEG (1UL << CAUSE_MISALIGNED_LOAD | 1UL << CAUSE_MISALIGNED_STORE)
+
struct fwft_config;
struct fwft_feature {
@@ -71,6 +73,33 @@ static bool fwft_is_defined_feature(enum sbi_fwft_feature_t feature)
return false;
}
+static int fwft_misaligned_delegation_supported(struct fwft_config *conf)
+{
+ if (!misa_extension('S'))
+ return SBI_ENOTSUPP;
+
+ return SBI_OK;
+}
+
+static int fwft_set_misaligned_delegation(struct fwft_config *conf,
+ unsigned long value)
+{
+ if (value)
+ csr_set(CSR_MEDELEG, MIS_DELEG);
+ else
+ csr_clear(CSR_MEDELEG, MIS_DELEG);
+
+ return SBI_OK;
+}
+
+static int fwft_get_misaligned_delegation(struct fwft_config *conf,
+ unsigned long *value)
+{
+ *value = (csr_read(CSR_MEDELEG) & MIS_DELEG) != 0;
+
+ return SBI_OK;
+}
+
static struct fwft_config* get_feature_config(enum sbi_fwft_feature_t feature)
{
int i;
@@ -148,7 +177,15 @@ int sbi_fwft_get(enum sbi_fwft_feature_t feature, unsigned long *out_val)
return conf->feature->get(conf, out_val);
}
-static const struct fwft_feature features[] = {};
+static const struct fwft_feature features[] =
+{
+ {
+ .id = SBI_FWFT_MISALIGNED_EXC_DELEG,
+ .supported = fwft_misaligned_delegation_supported,
+ .set = fwft_set_misaligned_delegation,
+ .get = fwft_get_misaligned_delegation,
+ },
+};
int sbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot)
{
diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c
index be48d64..2b23e13 100644
--- a/lib/sbi/sbi_hsm.c
+++ b/lib/sbi/sbi_hsm.c
@@ -44,6 +44,7 @@ struct sbi_hsm_data {
unsigned long suspend_type;
unsigned long saved_mie;
unsigned long saved_mip;
+ unsigned long saved_medeleg;
atomic_t start_ticket;
};
@@ -417,6 +418,7 @@ void __sbi_hsm_suspend_non_ret_save(struct sbi_scratch *scratch)
hdata->saved_mie = csr_read(CSR_MIE);
hdata->saved_mip = csr_read(CSR_MIP) & (MIP_SSIP | MIP_STIP);
+ hdata->saved_medeleg = csr_read(CSR_MEDELEG);
}
static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch)
@@ -424,6 +426,7 @@ static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch)
struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch,
hart_data_offset);
+ csr_write(CSR_MEDELEG, hdata->saved_medeleg);
csr_write(CSR_MIE, hdata->saved_mie);
csr_set(CSR_MIP, (hdata->saved_mip & (MIP_SSIP | MIP_STIP)));
}
--
2.45.2
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH v3 2/4] lib: sbi: fwft: add support for SBI_FWFT_MISALIGNED_EXC_DELEG
2024-06-19 9:42 ` [PATCH v3 2/4] lib: sbi: fwft: add support for SBI_FWFT_MISALIGNED_EXC_DELEG Clément Léger
@ 2024-06-19 12:48 ` Anup Patel
2024-06-21 13:50 ` Andrew Jones
1 sibling, 0 replies; 11+ messages in thread
From: Anup Patel @ 2024-06-19 12:48 UTC (permalink / raw)
To: opensbi
On Wed, Jun 19, 2024 at 3:13?PM Cl?ment L?ger <cleger@rivosinc.com> wrote:
>
> Add support for SBI_FWFT_MISALIGNED_EXC_DELEG withing FWFT support. This
> support allows to delegate misaligned accesses traps.
>
> Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
LGTM.
Reviewed-by: Anup Patel <anup@brainfault.org>
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
> ---
> lib/sbi/sbi_fwft.c | 39 ++++++++++++++++++++++++++++++++++++++-
> lib/sbi/sbi_hsm.c | 3 +++
> 2 files changed, 41 insertions(+), 1 deletion(-)
>
> diff --git a/lib/sbi/sbi_fwft.c b/lib/sbi/sbi_fwft.c
> index b302b5d..289a344 100644
> --- a/lib/sbi/sbi_fwft.c
> +++ b/lib/sbi/sbi_fwft.c
> @@ -32,6 +32,8 @@ static unsigned long fwft_ptr_offset;
> #define fwft_set_hart_state_ptr(__scratch, __phs) \
> sbi_scratch_write_type((__scratch), void *, fwft_ptr_offset, (__phs))
>
> +#define MIS_DELEG (1UL << CAUSE_MISALIGNED_LOAD | 1UL << CAUSE_MISALIGNED_STORE)
> +
> struct fwft_config;
>
> struct fwft_feature {
> @@ -71,6 +73,33 @@ static bool fwft_is_defined_feature(enum sbi_fwft_feature_t feature)
> return false;
> }
>
> +static int fwft_misaligned_delegation_supported(struct fwft_config *conf)
> +{
> + if (!misa_extension('S'))
> + return SBI_ENOTSUPP;
> +
> + return SBI_OK;
> +}
> +
> +static int fwft_set_misaligned_delegation(struct fwft_config *conf,
> + unsigned long value)
> +{
> + if (value)
> + csr_set(CSR_MEDELEG, MIS_DELEG);
> + else
> + csr_clear(CSR_MEDELEG, MIS_DELEG);
> +
> + return SBI_OK;
> +}
> +
> +static int fwft_get_misaligned_delegation(struct fwft_config *conf,
> + unsigned long *value)
> +{
> + *value = (csr_read(CSR_MEDELEG) & MIS_DELEG) != 0;
> +
> + return SBI_OK;
> +}
> +
> static struct fwft_config* get_feature_config(enum sbi_fwft_feature_t feature)
> {
> int i;
> @@ -148,7 +177,15 @@ int sbi_fwft_get(enum sbi_fwft_feature_t feature, unsigned long *out_val)
> return conf->feature->get(conf, out_val);
> }
>
> -static const struct fwft_feature features[] = {};
> +static const struct fwft_feature features[] =
> +{
> + {
> + .id = SBI_FWFT_MISALIGNED_EXC_DELEG,
> + .supported = fwft_misaligned_delegation_supported,
> + .set = fwft_set_misaligned_delegation,
> + .get = fwft_get_misaligned_delegation,
> + },
> +};
>
> int sbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot)
> {
> diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c
> index be48d64..2b23e13 100644
> --- a/lib/sbi/sbi_hsm.c
> +++ b/lib/sbi/sbi_hsm.c
> @@ -44,6 +44,7 @@ struct sbi_hsm_data {
> unsigned long suspend_type;
> unsigned long saved_mie;
> unsigned long saved_mip;
> + unsigned long saved_medeleg;
> atomic_t start_ticket;
> };
>
> @@ -417,6 +418,7 @@ void __sbi_hsm_suspend_non_ret_save(struct sbi_scratch *scratch)
>
> hdata->saved_mie = csr_read(CSR_MIE);
> hdata->saved_mip = csr_read(CSR_MIP) & (MIP_SSIP | MIP_STIP);
> + hdata->saved_medeleg = csr_read(CSR_MEDELEG);
> }
>
> static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch)
> @@ -424,6 +426,7 @@ static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch)
> struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch,
> hart_data_offset);
>
> + csr_write(CSR_MEDELEG, hdata->saved_medeleg);
> csr_write(CSR_MIE, hdata->saved_mie);
> csr_set(CSR_MIP, (hdata->saved_mip & (MIP_SSIP | MIP_STIP)));
> }
> --
> 2.45.2
>
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH v3 2/4] lib: sbi: fwft: add support for SBI_FWFT_MISALIGNED_EXC_DELEG
2024-06-19 9:42 ` [PATCH v3 2/4] lib: sbi: fwft: add support for SBI_FWFT_MISALIGNED_EXC_DELEG Clément Léger
2024-06-19 12:48 ` Anup Patel
@ 2024-06-21 13:50 ` Andrew Jones
2024-06-24 8:28 ` Clément Léger
1 sibling, 1 reply; 11+ messages in thread
From: Andrew Jones @ 2024-06-21 13:50 UTC (permalink / raw)
To: opensbi
On Wed, Jun 19, 2024 at 11:42:40AM GMT, Cl?ment L?ger wrote:
> Add support for SBI_FWFT_MISALIGNED_EXC_DELEG withing FWFT support. This
> support allows to delegate misaligned accesses traps.
>
> Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
> ---
> lib/sbi/sbi_fwft.c | 39 ++++++++++++++++++++++++++++++++++++++-
> lib/sbi/sbi_hsm.c | 3 +++
> 2 files changed, 41 insertions(+), 1 deletion(-)
>
> diff --git a/lib/sbi/sbi_fwft.c b/lib/sbi/sbi_fwft.c
> index b302b5d..289a344 100644
> --- a/lib/sbi/sbi_fwft.c
> +++ b/lib/sbi/sbi_fwft.c
> @@ -32,6 +32,8 @@ static unsigned long fwft_ptr_offset;
> #define fwft_set_hart_state_ptr(__scratch, __phs) \
> sbi_scratch_write_type((__scratch), void *, fwft_ptr_offset, (__phs))
>
> +#define MIS_DELEG (1UL << CAUSE_MISALIGNED_LOAD | 1UL << CAUSE_MISALIGNED_STORE)
> +
> struct fwft_config;
>
> struct fwft_feature {
> @@ -71,6 +73,33 @@ static bool fwft_is_defined_feature(enum sbi_fwft_feature_t feature)
> return false;
> }
>
> +static int fwft_misaligned_delegation_supported(struct fwft_config *conf)
> +{
> + if (!misa_extension('S'))
> + return SBI_ENOTSUPP;
> +
> + return SBI_OK;
> +}
> +
> +static int fwft_set_misaligned_delegation(struct fwft_config *conf,
> + unsigned long value)
> +{
> + if (value)
> + csr_set(CSR_MEDELEG, MIS_DELEG);
> + else
> + csr_clear(CSR_MEDELEG, MIS_DELEG);
Sorry for my late review. This should be
if (value == 1)
csr_set(CSR_MEDELEG, MIS_DELEG);
else if (value == 0)
csr_clear(CSR_MEDELEG, MIS_DELEG);
else
return SBI_EINVAL;
It's unlikely we'll ever extend the inputs/behaviors, but if we don't
check for the inputs explicitly now, then we never can.
And same comment for SBI_FWFT_PTE_AD_HW_UPDATING.
Thanks,
drew
> +
> + return SBI_OK;
> +}
> +
> +static int fwft_get_misaligned_delegation(struct fwft_config *conf,
> + unsigned long *value)
> +{
> + *value = (csr_read(CSR_MEDELEG) & MIS_DELEG) != 0;
> +
> + return SBI_OK;
> +}
> +
> static struct fwft_config* get_feature_config(enum sbi_fwft_feature_t feature)
> {
> int i;
> @@ -148,7 +177,15 @@ int sbi_fwft_get(enum sbi_fwft_feature_t feature, unsigned long *out_val)
> return conf->feature->get(conf, out_val);
> }
>
> -static const struct fwft_feature features[] = {};
> +static const struct fwft_feature features[] =
> +{
> + {
> + .id = SBI_FWFT_MISALIGNED_EXC_DELEG,
> + .supported = fwft_misaligned_delegation_supported,
> + .set = fwft_set_misaligned_delegation,
> + .get = fwft_get_misaligned_delegation,
> + },
> +};
>
> int sbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot)
> {
> diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c
> index be48d64..2b23e13 100644
> --- a/lib/sbi/sbi_hsm.c
> +++ b/lib/sbi/sbi_hsm.c
> @@ -44,6 +44,7 @@ struct sbi_hsm_data {
> unsigned long suspend_type;
> unsigned long saved_mie;
> unsigned long saved_mip;
> + unsigned long saved_medeleg;
> atomic_t start_ticket;
> };
>
> @@ -417,6 +418,7 @@ void __sbi_hsm_suspend_non_ret_save(struct sbi_scratch *scratch)
>
> hdata->saved_mie = csr_read(CSR_MIE);
> hdata->saved_mip = csr_read(CSR_MIP) & (MIP_SSIP | MIP_STIP);
> + hdata->saved_medeleg = csr_read(CSR_MEDELEG);
> }
>
> static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch)
> @@ -424,6 +426,7 @@ static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch)
> struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch,
> hart_data_offset);
>
> + csr_write(CSR_MEDELEG, hdata->saved_medeleg);
> csr_write(CSR_MIE, hdata->saved_mie);
> csr_set(CSR_MIP, (hdata->saved_mip & (MIP_SSIP | MIP_STIP)));
> }
> --
> 2.45.2
>
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH v3 2/4] lib: sbi: fwft: add support for SBI_FWFT_MISALIGNED_EXC_DELEG
2024-06-21 13:50 ` Andrew Jones
@ 2024-06-24 8:28 ` Clément Léger
0 siblings, 0 replies; 11+ messages in thread
From: Clément Léger @ 2024-06-24 8:28 UTC (permalink / raw)
To: opensbi
On 21/06/2024 15:50, Andrew Jones wrote:
> On Wed, Jun 19, 2024 at 11:42:40AM GMT, Cl?ment L?ger wrote:
>> Add support for SBI_FWFT_MISALIGNED_EXC_DELEG withing FWFT support. This
>> support allows to delegate misaligned accesses traps.
>>
>> Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
>> ---
>> lib/sbi/sbi_fwft.c | 39 ++++++++++++++++++++++++++++++++++++++-
>> lib/sbi/sbi_hsm.c | 3 +++
>> 2 files changed, 41 insertions(+), 1 deletion(-)
>>
>> diff --git a/lib/sbi/sbi_fwft.c b/lib/sbi/sbi_fwft.c
>> index b302b5d..289a344 100644
>> --- a/lib/sbi/sbi_fwft.c
>> +++ b/lib/sbi/sbi_fwft.c
>> @@ -32,6 +32,8 @@ static unsigned long fwft_ptr_offset;
>> #define fwft_set_hart_state_ptr(__scratch, __phs) \
>> sbi_scratch_write_type((__scratch), void *, fwft_ptr_offset, (__phs))
>>
>> +#define MIS_DELEG (1UL << CAUSE_MISALIGNED_LOAD | 1UL << CAUSE_MISALIGNED_STORE)
>> +
>> struct fwft_config;
>>
>> struct fwft_feature {
>> @@ -71,6 +73,33 @@ static bool fwft_is_defined_feature(enum sbi_fwft_feature_t feature)
>> return false;
>> }
>>
>> +static int fwft_misaligned_delegation_supported(struct fwft_config *conf)
>> +{
>> + if (!misa_extension('S'))
>> + return SBI_ENOTSUPP;
>> +
>> + return SBI_OK;
>> +}
>> +
>> +static int fwft_set_misaligned_delegation(struct fwft_config *conf,
>> + unsigned long value)
>> +{
>> + if (value)
>> + csr_set(CSR_MEDELEG, MIS_DELEG);
>> + else
>> + csr_clear(CSR_MEDELEG, MIS_DELEG);
>
> Sorry for my late review. This should be
>
> if (value == 1)
> csr_set(CSR_MEDELEG, MIS_DELEG);
> else if (value == 0)
> csr_clear(CSR_MEDELEG, MIS_DELEG);
> else
> return SBI_EINVAL;
>
> It's unlikely we'll ever extend the inputs/behaviors, but if we don't
> check for the inputs explicitly now, then we never can.
>
> And same comment for SBI_FWFT_PTE_AD_HW_UPDATING.
Arg, I thought I had this right but I might have dropped it at some
point. But agreed this needs to be checked thoroughly. I'll send a fix.
Thanks,
Cl?ment
>
> Thanks,
> drew
>
>> +
>> + return SBI_OK;
>> +}
>> +
>> +static int fwft_get_misaligned_delegation(struct fwft_config *conf,
>> + unsigned long *value)
>> +{
>> + *value = (csr_read(CSR_MEDELEG) & MIS_DELEG) != 0;
>> +
>> + return SBI_OK;
>> +}
>> +
>> static struct fwft_config* get_feature_config(enum sbi_fwft_feature_t feature)
>> {
>> int i;
>> @@ -148,7 +177,15 @@ int sbi_fwft_get(enum sbi_fwft_feature_t feature, unsigned long *out_val)
>> return conf->feature->get(conf, out_val);
>> }
>>
>> -static const struct fwft_feature features[] = {};
>> +static const struct fwft_feature features[] =
>> +{
>> + {
>> + .id = SBI_FWFT_MISALIGNED_EXC_DELEG,
>> + .supported = fwft_misaligned_delegation_supported,
>> + .set = fwft_set_misaligned_delegation,
>> + .get = fwft_get_misaligned_delegation,
>> + },
>> +};
>>
>> int sbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot)
>> {
>> diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c
>> index be48d64..2b23e13 100644
>> --- a/lib/sbi/sbi_hsm.c
>> +++ b/lib/sbi/sbi_hsm.c
>> @@ -44,6 +44,7 @@ struct sbi_hsm_data {
>> unsigned long suspend_type;
>> unsigned long saved_mie;
>> unsigned long saved_mip;
>> + unsigned long saved_medeleg;
>> atomic_t start_ticket;
>> };
>>
>> @@ -417,6 +418,7 @@ void __sbi_hsm_suspend_non_ret_save(struct sbi_scratch *scratch)
>>
>> hdata->saved_mie = csr_read(CSR_MIE);
>> hdata->saved_mip = csr_read(CSR_MIP) & (MIP_SSIP | MIP_STIP);
>> + hdata->saved_medeleg = csr_read(CSR_MEDELEG);
>> }
>>
>> static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch)
>> @@ -424,6 +426,7 @@ static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch)
>> struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch,
>> hart_data_offset);
>>
>> + csr_write(CSR_MEDELEG, hdata->saved_medeleg);
>> csr_write(CSR_MIE, hdata->saved_mie);
>> csr_set(CSR_MIP, (hdata->saved_mip & (MIP_SSIP | MIP_STIP)));
>> }
>> --
>> 2.45.2
>>
>>
>> --
>> opensbi mailing list
>> opensbi at lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/opensbi
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v3 3/4] lib: sbi: fwft: add support for SBI_FWFT_PTE_AD_HW_UPDATING
2024-06-19 9:42 [PATCH v3 0/4] Add SBI FWFT extension support Clément Léger
2024-06-19 9:42 ` [PATCH v3 1/4] lib: sbi: add support for firmware features extension Clément Léger
2024-06-19 9:42 ` [PATCH v3 2/4] lib: sbi: fwft: add support for SBI_FWFT_MISALIGNED_EXC_DELEG Clément Léger
@ 2024-06-19 9:42 ` Clément Léger
2024-06-19 12:48 ` Anup Patel
2024-06-19 9:42 ` [PATCH v3 4/4] lib: sbi: implement SBI FWFT extension Clément Léger
3 siblings, 1 reply; 11+ messages in thread
From: Clément Léger @ 2024-06-19 9:42 UTC (permalink / raw)
To: opensbi
Add support for SBI_FWFT_PTE_AD_HW_UPDATING based on SVADU presence.
Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
---
lib/sbi/sbi_fwft.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++
lib/sbi/sbi_hsm.c | 12 ++++++++++++
2 files changed, 59 insertions(+)
diff --git a/lib/sbi/sbi_fwft.c b/lib/sbi/sbi_fwft.c
index 289a344..aff087f 100644
--- a/lib/sbi/sbi_fwft.c
+++ b/lib/sbi/sbi_fwft.c
@@ -100,6 +100,47 @@ static int fwft_get_misaligned_delegation(struct fwft_config *conf,
return SBI_OK;
}
+static int fwft_adue_supported(struct fwft_config *conf)
+{
+ if (!sbi_hart_has_extension(sbi_scratch_thishart_ptr(),
+ SBI_HART_EXT_SVADU))
+ return SBI_ENOTSUPP;
+
+ return SBI_OK;
+}
+
+static int fwft_set_adue(struct fwft_config *conf, unsigned long value)
+{
+ if (value)
+#if __riscv_xlen == 32
+ csr_set(CSR_MENVCFGH, ENVCFG_ADUE >> 32);
+#else
+ csr_set(CSR_MENVCFG, ENVCFG_ADUE);
+#endif
+ else
+#if __riscv_xlen == 32
+ csr_clear(CSR_MENVCFGH, ENVCFG_ADUE >> 32);
+#else
+ csr_clear(CSR_MENVCFG, ENVCFG_ADUE);
+#endif
+
+ return SBI_OK;
+}
+
+static int fwft_get_adue(struct fwft_config *conf, unsigned long *value)
+{
+ unsigned long cfg;
+
+#if __riscv_xlen == 32
+ cfg = csr_read(CSR_MENVCFGH) & (ENVCFG_ADUE >> 32);
+#else
+ cfg = csr_read(CSR_MENVCFG) & ENVCFG_ADUE;
+#endif
+ *value = cfg != 0;
+
+ return SBI_OK;
+}
+
static struct fwft_config* get_feature_config(enum sbi_fwft_feature_t feature)
{
int i;
@@ -185,6 +226,12 @@ static const struct fwft_feature features[] =
.set = fwft_set_misaligned_delegation,
.get = fwft_get_misaligned_delegation,
},
+ {
+ .id = SBI_FWFT_PTE_AD_HW_UPDATING,
+ .supported = fwft_adue_supported,
+ .set = fwft_set_adue,
+ .get = fwft_get_adue,
+ },
};
int sbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot)
diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c
index 2b23e13..7e32af3 100644
--- a/lib/sbi/sbi_hsm.c
+++ b/lib/sbi/sbi_hsm.c
@@ -45,6 +45,10 @@ struct sbi_hsm_data {
unsigned long saved_mie;
unsigned long saved_mip;
unsigned long saved_medeleg;
+ unsigned long saved_menvcfg;
+#if __riscv_xlen == 32
+ unsigned long saved_menvcfgh;
+#endif
atomic_t start_ticket;
};
@@ -419,6 +423,10 @@ void __sbi_hsm_suspend_non_ret_save(struct sbi_scratch *scratch)
hdata->saved_mie = csr_read(CSR_MIE);
hdata->saved_mip = csr_read(CSR_MIP) & (MIP_SSIP | MIP_STIP);
hdata->saved_medeleg = csr_read(CSR_MEDELEG);
+#if __riscv_xlen == 32
+ hdata->saved_menvcfgh = csr_read(CSR_MENVCFGH);
+#endif
+ hdata->saved_menvcfg = csr_read(CSR_MENVCFG);
}
static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch)
@@ -426,6 +434,10 @@ static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch)
struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch,
hart_data_offset);
+ csr_write(CSR_MENVCFG, hdata->saved_menvcfg);
+#if __riscv_xlen == 32
+ csr_write(CSR_MENVCFGH, hdata->saved_menvcfgh);
+#endif
csr_write(CSR_MEDELEG, hdata->saved_medeleg);
csr_write(CSR_MIE, hdata->saved_mie);
csr_set(CSR_MIP, (hdata->saved_mip & (MIP_SSIP | MIP_STIP)));
--
2.45.2
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH v3 3/4] lib: sbi: fwft: add support for SBI_FWFT_PTE_AD_HW_UPDATING
2024-06-19 9:42 ` [PATCH v3 3/4] lib: sbi: fwft: add support for SBI_FWFT_PTE_AD_HW_UPDATING Clément Léger
@ 2024-06-19 12:48 ` Anup Patel
0 siblings, 0 replies; 11+ messages in thread
From: Anup Patel @ 2024-06-19 12:48 UTC (permalink / raw)
To: opensbi
On Wed, Jun 19, 2024 at 3:13?PM Cl?ment L?ger <cleger@rivosinc.com> wrote:
>
> Add support for SBI_FWFT_PTE_AD_HW_UPDATING based on SVADU presence.
>
> Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
I had already reviewed the previous revision of this patch.
Reviewed-by: Anup Patel <anup@brainfault.org>
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
> ---
> lib/sbi/sbi_fwft.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++
> lib/sbi/sbi_hsm.c | 12 ++++++++++++
> 2 files changed, 59 insertions(+)
>
> diff --git a/lib/sbi/sbi_fwft.c b/lib/sbi/sbi_fwft.c
> index 289a344..aff087f 100644
> --- a/lib/sbi/sbi_fwft.c
> +++ b/lib/sbi/sbi_fwft.c
> @@ -100,6 +100,47 @@ static int fwft_get_misaligned_delegation(struct fwft_config *conf,
> return SBI_OK;
> }
>
> +static int fwft_adue_supported(struct fwft_config *conf)
> +{
> + if (!sbi_hart_has_extension(sbi_scratch_thishart_ptr(),
> + SBI_HART_EXT_SVADU))
> + return SBI_ENOTSUPP;
> +
> + return SBI_OK;
> +}
> +
> +static int fwft_set_adue(struct fwft_config *conf, unsigned long value)
> +{
> + if (value)
> +#if __riscv_xlen == 32
> + csr_set(CSR_MENVCFGH, ENVCFG_ADUE >> 32);
> +#else
> + csr_set(CSR_MENVCFG, ENVCFG_ADUE);
> +#endif
> + else
> +#if __riscv_xlen == 32
> + csr_clear(CSR_MENVCFGH, ENVCFG_ADUE >> 32);
> +#else
> + csr_clear(CSR_MENVCFG, ENVCFG_ADUE);
> +#endif
> +
> + return SBI_OK;
> +}
> +
> +static int fwft_get_adue(struct fwft_config *conf, unsigned long *value)
> +{
> + unsigned long cfg;
> +
> +#if __riscv_xlen == 32
> + cfg = csr_read(CSR_MENVCFGH) & (ENVCFG_ADUE >> 32);
> +#else
> + cfg = csr_read(CSR_MENVCFG) & ENVCFG_ADUE;
> +#endif
> + *value = cfg != 0;
> +
> + return SBI_OK;
> +}
> +
> static struct fwft_config* get_feature_config(enum sbi_fwft_feature_t feature)
> {
> int i;
> @@ -185,6 +226,12 @@ static const struct fwft_feature features[] =
> .set = fwft_set_misaligned_delegation,
> .get = fwft_get_misaligned_delegation,
> },
> + {
> + .id = SBI_FWFT_PTE_AD_HW_UPDATING,
> + .supported = fwft_adue_supported,
> + .set = fwft_set_adue,
> + .get = fwft_get_adue,
> + },
> };
>
> int sbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot)
> diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c
> index 2b23e13..7e32af3 100644
> --- a/lib/sbi/sbi_hsm.c
> +++ b/lib/sbi/sbi_hsm.c
> @@ -45,6 +45,10 @@ struct sbi_hsm_data {
> unsigned long saved_mie;
> unsigned long saved_mip;
> unsigned long saved_medeleg;
> + unsigned long saved_menvcfg;
> +#if __riscv_xlen == 32
> + unsigned long saved_menvcfgh;
> +#endif
> atomic_t start_ticket;
> };
>
> @@ -419,6 +423,10 @@ void __sbi_hsm_suspend_non_ret_save(struct sbi_scratch *scratch)
> hdata->saved_mie = csr_read(CSR_MIE);
> hdata->saved_mip = csr_read(CSR_MIP) & (MIP_SSIP | MIP_STIP);
> hdata->saved_medeleg = csr_read(CSR_MEDELEG);
> +#if __riscv_xlen == 32
> + hdata->saved_menvcfgh = csr_read(CSR_MENVCFGH);
> +#endif
> + hdata->saved_menvcfg = csr_read(CSR_MENVCFG);
> }
>
> static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch)
> @@ -426,6 +434,10 @@ static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch)
> struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch,
> hart_data_offset);
>
> + csr_write(CSR_MENVCFG, hdata->saved_menvcfg);
> +#if __riscv_xlen == 32
> + csr_write(CSR_MENVCFGH, hdata->saved_menvcfgh);
> +#endif
> csr_write(CSR_MEDELEG, hdata->saved_medeleg);
> csr_write(CSR_MIE, hdata->saved_mie);
> csr_set(CSR_MIP, (hdata->saved_mip & (MIP_SSIP | MIP_STIP)));
> --
> 2.45.2
>
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v3 4/4] lib: sbi: implement SBI FWFT extension
2024-06-19 9:42 [PATCH v3 0/4] Add SBI FWFT extension support Clément Léger
` (2 preceding siblings ...)
2024-06-19 9:42 ` [PATCH v3 3/4] lib: sbi: fwft: add support for SBI_FWFT_PTE_AD_HW_UPDATING Clément Léger
@ 2024-06-19 9:42 ` Clément Léger
2024-06-19 12:49 ` Anup Patel
3 siblings, 1 reply; 11+ messages in thread
From: Clément Léger @ 2024-06-19 9:42 UTC (permalink / raw)
To: opensbi
The SBI FWFT extension defines a set of function that can be called to
control the configuration of some platform features (misaligned
trap delegation, etc). This patch implements sbi_fwft_set() and
sbi_fwft_get() as defined in the specification [1].
Link: https://lists.riscv.org/g/tech-prs/message/924 [1]
Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
---
lib/sbi/Kconfig | 4 ++++
lib/sbi/objects.mk | 3 +++
lib/sbi/sbi_ecall_fwft.c | 49 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 56 insertions(+)
create mode 100644 lib/sbi/sbi_ecall_fwft.c
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_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,
+};
--
2.45.2
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH v3 4/4] lib: sbi: implement SBI FWFT extension
2024-06-19 9:42 ` [PATCH v3 4/4] lib: sbi: implement SBI FWFT extension Clément Léger
@ 2024-06-19 12:49 ` Anup Patel
0 siblings, 0 replies; 11+ messages in thread
From: Anup Patel @ 2024-06-19 12:49 UTC (permalink / raw)
To: opensbi
On Wed, Jun 19, 2024 at 3:13?PM Cl?ment L?ger <cleger@rivosinc.com> wrote:
>
> The SBI FWFT extension defines a set of function that can be called to
> control the configuration of some platform features (misaligned
> trap delegation, etc). This patch implements sbi_fwft_set() and
> sbi_fwft_get() as defined in the specification [1].
>
> Link: https://lists.riscv.org/g/tech-prs/message/924 [1]
> Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
I had already reviewed the previous revision of this patch.
Reviewed-by: Anup Patel <anup@brainfault.org>
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
> ---
> lib/sbi/Kconfig | 4 ++++
> lib/sbi/objects.mk | 3 +++
> lib/sbi/sbi_ecall_fwft.c | 49 ++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 56 insertions(+)
> create mode 100644 lib/sbi/sbi_ecall_fwft.c
>
> 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_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,
> +};
> --
> 2.45.2
>
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi
^ permalink raw reply [flat|nested] 11+ messages in thread