Skip to contentSkip to conversation

platform: sifive: Add initial support for SiFive development platform

RFC PATCH Applied Yu-Chien Peter Lin 2 participants 6 messages Feb 24 – Apr 6 SiFive drivers

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/3 platform: sifive: Add initial support for SiFive development platform

Add initial platform support for SiFive development platforms with the "sifive-dev" compatible string.

---
 platform/generic/Kconfig                      |  4 ++++
 platform/generic/configs/defconfig            |  1 +
 platform/generic/sifive/objects.mk            |  3 +++
 platform/generic/sifive/sifive_dev_platform.c | 23 +++++++++++++++++++
 4 files changed, 31 insertions(+)
 create mode 100644 platform/generic/sifive/sifive_dev_platform.c
platform/generic/Kconfig +4 -0
index 0c11fbd2c..eaa972b73 100644
@@ -66,6 +66,10 @@ config PLATFORM_RENESAS_RZFIVE
 	select ANDES_PMU
 	default n
 
+config PLATFORM_SIFIVE_DEV
+	bool "SiFive development platform support"
+	default n
+
 config PLATFORM_SIFIVE_FU540
 	bool "SiFive FU540 support"
 	default n
platform/generic/configs/defconfig +1 -0
index 19a73a247..347ca56d9 100644
@@ -5,6 +5,7 @@ CONFIG_PLATFORM_ESWIN_EIC770X=y
 CONFIG_PLATFORM_OPENHWGROUP_ARIANE=y
 CONFIG_PLATFORM_OPENHWGROUP_OPENPITON=y
 CONFIG_PLATFORM_RENESAS_RZFIVE=y
+CONFIG_PLATFORM_SIFIVE_DEV=y
 CONFIG_PLATFORM_SIFIVE_FU540=y
 CONFIG_PLATFORM_SIFIVE_FU740=y
 CONFIG_PLATFORM_SOPHGO_SG2042=y
platform/generic/sifive/objects.mk +3 -0
index d75e444ab..d32e1273d 100644
@@ -2,6 +2,9 @@
 # SPDX-License-Identifier: BSD-2-Clause
 #
 
+carray-platform_override_modules-$(CONFIG_PLATFORM_SIFIVE_DEV) += sifive_dev_platform
+platform-objs-$(CONFIG_PLATFORM_SIFIVE_DEV) += sifive/sifive_dev_platform.o
+
 carray-platform_override_modules-$(CONFIG_PLATFORM_SIFIVE_FU540) += sifive_fu540
 platform-objs-$(CONFIG_PLATFORM_SIFIVE_FU540) += sifive/fu540.o
 
platform/generic/sifive/sifive_dev_platform.c new file +23 -0
new file mode 100644
index 000000000..facc044f1
@@ -0,0 +1,23 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2026 SiFive Inc.
+ */
+
+#include <platform_override.h>
+
+static int sifive_platform_init(const void *fdt, int nodeoff,
+				const struct fdt_match *match)
+{
+	return 0;
+}
+
+static const struct fdt_match sifive_dev_platform_match[] = {
+	{ .compatible = "sifive-dev" },
+	{ },
+};
+
+const struct fdt_driver sifive_dev_platform = {
+	.match_table = sifive_dev_platform_match,
+	.init = sifive_platform_init,
+};
Signature · 7 lines
2.43.7


-- 
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#1 lore raw

RFC PATCH 2/3 lib: sbi_init: Call hart init before platform early init

To allow the platform early_init hook to use the sbi_hart_has_extension() helper, reorder the initialization sequence to call sbi_hart_init() prior to sbi_platform_early_init() during both cold and warm boot paths.

---
 lib/sbi/sbi_init.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
lib/sbi/sbi_init.c +4 -4
index 5259064b1..aed2b96f8 100644
@@ -265,11 +265,11 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
 	 */
 	wake_coldboot_harts(scratch);
 
-	rc = sbi_platform_early_init(plat, true);
+	rc = sbi_hart_init(scratch, true);
 	if (rc)
 		sbi_hart_hang();
 
-	rc = sbi_hart_init(scratch, true);
+	rc = sbi_platform_early_init(plat, true);
 	if (rc)
 		sbi_hart_hang();
 
@@ -424,11 +424,11 @@ static void __noreturn init_warm_startup(struct sbi_scratch *scratch,
 	if (rc)
 		sbi_hart_hang();
 
-	rc = sbi_platform_early_init(plat, false);
+	rc = sbi_hart_init(scratch, false);
 	if (rc)
 		sbi_hart_hang();
 
-	rc = sbi_hart_init(scratch, false);
+	rc = sbi_platform_early_init(plat, false);
 	if (rc)
 		sbi_hart_hang();
 
Signature · 7 lines
2.43.7


-- 
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
Applied
#2 lore raw

Re: [RFC PATCH 2/3] lib: sbi_init: Call hart init before platform early init

Quoted 10 lines · Yu-Chien Peter Lin

To allow the platform early_init hook to use the sbi_hart_has_extension() helper, reorder the initialization sequence to call sbi_hart_init() prior to sbi_platform_early_init() during both cold and warm boot paths.

Not just sbi_hart_has_extension(), the platform early drivers may use sbi_timer_mdelay/udelay() functions as well. For e.g. the RPMI shmem driver uses delay functions and it also probed as early driver.

I have updated this patch re-order both sbi_hart_init() and sbi_timer_init() before sbi_platform_early_init().

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 44 lines
---
 lib/sbi/sbi_init.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
lib/sbi/sbi_init.c +4 -5
index 5259064b1..aed2b96f8 100644
@@ -265,11 +265,11 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
         */
        wake_coldboot_harts(scratch);
 
-       rc = sbi_platform_early_init(plat, true);
+       rc = sbi_hart_init(scratch, true);
        if (rc)
                sbi_hart_hang();
 
-       rc = sbi_hart_init(scratch, true);
+       rc = sbi_platform_early_init(plat, true);
        if (rc)
                sbi_hart_hang();
 
@@ -424,11 +424,11 @@ static void __noreturn init_warm_startup(struct sbi_scratch *scratch,
        if (rc)
                sbi_hart_hang();
 
-       rc = sbi_platform_early_init(plat, false);
+       rc = sbi_hart_init(scratch, false);
        if (rc)
                sbi_hart_hang();
 
-       rc = sbi_hart_init(scratch, false);
+       rc = sbi_platform_early_init(plat, false);
        if (rc)
                sbi_hart_hang();
 
--

2.43.7

--
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#3 lore raw

RFC PATCH 3/3 sifive_dev_platform: Set default MMIO region when SmePMP is enabled

In reply to Yu-Chien Peter Lin

Set a default MMIO region with a single SmePMP entry, which allows us to save entries for M-mode only devices. The default entry has M-/S-mode shared permission, so system-level resource protection, such as RISC-V World extension and WorldGuard checker, will be introduced to protect M-mode only region access from lower privilege modes.

---
 platform/generic/sifive/sifive_dev_platform.c | 48 +++++++++++++++++++
 1 file changed, 48 insertions(+)
platform/generic/sifive/sifive_dev_platform.c +48 -0
index facc044f1..9799e5b88 100644
@@ -5,10 +5,58 @@
  */
 
 #include <platform_override.h>
+#include <sbi/sbi_hart.h>
+#include <sbi/sbi_scratch.h>
+
+/*
+ * Instead of allocating individual PMP entries for each M-mode
+ * MMIO driver, configure SMEPMP regions to grant R/W permission
+ * to peripheral and system ports for all privilege modes.
+ * Finer-grained access control is enforced by wgChecker rules.
+ */
+static int sifive_smepmp_setup(void)
+{
+	struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
+	int rc;
+
+	if (!sbi_hart_has_extension(scratch, SBI_HART_EXT_SMEPMP))
+		return 0;
+
+	/* Peripheral port region: 0 to 2GiB */
+	rc = sbi_domain_root_add_memrange(0x0, 0x80000000, 0x80000000,
+					  SBI_DOMAIN_MEMREGION_MMIO |
+					  SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW);
+	if (rc)
+		return rc;
+
+	/* System port region: 512GiB to 1TiB */
+	rc = sbi_domain_root_add_memrange(0x8000000000, 0x8000000000, 0x8000000000,
+					  SBI_DOMAIN_MEMREGION_MMIO |
+					  SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW);
+	if (rc)
+		return rc;
+
+	return 0;
+}
+
+static int sifive_early_init(bool cold_boot)
+{
+	int rc;
+
+	if (cold_boot) {
+		rc = sifive_smepmp_setup();
+		if (rc)
+			return rc;
+	}
+
+	return generic_early_init(cold_boot);
+}
 
 static int sifive_platform_init(const void *fdt, int nodeoff,
 				const struct fdt_match *match)
 {
+	generic_platform_ops.early_init = sifive_early_init;
+
 	return 0;
 }
 
Signature · 7 lines
2.43.7


-- 
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
Applied
#4 lore raw

Re: [RFC PATCH 3/3] sifive_dev_platform: Set default MMIO region when SmePMP is enabled

Quoted 42 lines · Yu-Chien Peter Lin

Set a default MMIO region with a single SmePMP entry, which allows us to save entries for M-mode only devices. The default entry has M-/S-mode shared permission, so system-level resource protection, such as RISC-V World extension and WorldGuard checker, will be introduced to protect M-mode only region access from lower privilege modes.

---
 platform/generic/sifive/sifive_dev_platform.c | 48 +++++++++++++++++++
 1 file changed, 48 insertions(+)
platform/generic/sifive/sifive_dev_platform.c +20 -0
index facc044f1..9799e5b88 100644
@@ -5,10 +5,58 @@
  */
 
 #include <platform_override.h>
+#include <sbi/sbi_hart.h>
+#include <sbi/sbi_scratch.h>
+
+/*
+ * Instead of allocating individual PMP entries for each M-mode
+ * MMIO driver, configure SMEPMP regions to grant R/W permission
+ * to peripheral and system ports for all privilege modes.
+ * Finer-grained access control is enforced by wgChecker rules.
+ */
+static int sifive_smepmp_setup(void)
+{
+       struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
+       int rc;
+
+       if (!sbi_hart_has_extension(scratch, SBI_HART_EXT_SMEPMP))
+               return 0;
+
+       /* Peripheral port region: 0 to 2GiB */
+       rc = sbi_domain_root_add_memrange(0x0, 0x80000000, 0x80000000,
+                                         SBI_DOMAIN_MEMREGION_MMIO |

platform/generic/sifive/sifive_dev_platform.c line 37

Quoted 10 lines
platform/generic/sifive/sifive_dev_platform.c +10 -0
+                                         SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW);
+       if (rc)
+               return rc;
+
+       /* System port region: 512GiB to 1TiB */
+       rc = sbi_domain_root_add_memrange(0x8000000000, 0x8000000000, 0x8000000000,
+                                         SBI_DOMAIN_MEMREGION_MMIO |
+                                         SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW);
+       if (rc)
+               return rc;

This breaks compilation of generic platform on RV32 because addresses are beyond 32-bit space. I have put #if at the time of merging.

Quoted 29 lines
platform/generic/sifive/sifive_dev_platform.c +18 -1
+
+       return 0;
+}
+
+static int sifive_early_init(bool cold_boot)
+{
+       int rc;
+
+       if (cold_boot) {
+               rc = sifive_smepmp_setup();
+               if (rc)
+                       return rc;
+       }
+
+       return generic_early_init(cold_boot);
+}
 
 static int sifive_platform_init(const void *fdt, int nodeoff,
                                const struct fdt_match *match)
 {
+       generic_platform_ops.early_init = sifive_early_init;
+
        return 0;
 }
 
--

2.43.7

Quoted 4 lines

--
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
Applied
#5 lore raw
In reply to Yu-Chien Peter Lin
Quoted 7 lines · Yu-Chien Peter Lin

Add initial platform support for SiFive development platforms with the "sifive-dev" compatible string.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 86 lines
---
 platform/generic/Kconfig                      |  4 ++++
 platform/generic/configs/defconfig            |  1 +
 platform/generic/sifive/objects.mk            |  3 +++
 platform/generic/sifive/sifive_dev_platform.c | 23 +++++++++++++++++++
 4 files changed, 31 insertions(+)
 create mode 100644 platform/generic/sifive/sifive_dev_platform.c
platform/generic/Kconfig +4 -0
index 0c11fbd2c..eaa972b73 100644
@@ -66,6 +66,10 @@ config PLATFORM_RENESAS_RZFIVE
        select ANDES_PMU
        default n
 
+config PLATFORM_SIFIVE_DEV
+       bool "SiFive development platform support"
+       default n
+
 config PLATFORM_SIFIVE_FU540
        bool "SiFive FU540 support"
        default n
platform/generic/configs/defconfig +1 -0
index 19a73a247..347ca56d9 100644
@@ -5,6 +5,7 @@ CONFIG_PLATFORM_ESWIN_EIC770X=y
 CONFIG_PLATFORM_OPENHWGROUP_ARIANE=y
 CONFIG_PLATFORM_OPENHWGROUP_OPENPITON=y
 CONFIG_PLATFORM_RENESAS_RZFIVE=y
+CONFIG_PLATFORM_SIFIVE_DEV=y
 CONFIG_PLATFORM_SIFIVE_FU540=y
 CONFIG_PLATFORM_SIFIVE_FU740=y
 CONFIG_PLATFORM_SOPHGO_SG2042=y
platform/generic/sifive/objects.mk +3 -0
index d75e444ab..d32e1273d 100644
@@ -2,6 +2,9 @@
 # SPDX-License-Identifier: BSD-2-Clause
 #
 
+carray-platform_override_modules-$(CONFIG_PLATFORM_SIFIVE_DEV) += sifive_dev_platform
+platform-objs-$(CONFIG_PLATFORM_SIFIVE_DEV) += sifive/sifive_dev_platform.o
+
 carray-platform_override_modules-$(CONFIG_PLATFORM_SIFIVE_FU540) += sifive_fu540
 platform-objs-$(CONFIG_PLATFORM_SIFIVE_FU540) += sifive/fu540.o
 
platform/generic/sifive/sifive_dev_platform.c new file +23 -1
new file mode 100644
index 000000000..facc044f1
@@ -0,0 +1,23 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2026 SiFive Inc.
+ */
+
+#include <platform_override.h>
+
+static int sifive_platform_init(const void *fdt, int nodeoff,
+                               const struct fdt_match *match)
+{
+       return 0;
+}
+
+static const struct fdt_match sifive_dev_platform_match[] = {
+       { .compatible = "sifive-dev" },
+       { },
+};
+
+const struct fdt_driver sifive_dev_platform = {
+       .match_table = sifive_dev_platform_match,
+       .init = sifive_platform_init,
+};
--

2.43.7

--
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi