[PATCH] platform: support starriver 9530
Bo Gan
ganboing at gmail.com
Tue Feb 24 15:12:50 PST 2026
Hi,
Please state your real name and have proper signed-off-by.
What's starriver? A SoC vendor? Can't find anything online. Also, from
your code I think the platform init logic is not necessary. Why not get
rid of those hard-coded values and use device-tree instead?
Bo
On 2/24/26 06:03, 362800175 wrote:
> From f93376ac9420836b1c23e885c2dafa30da96aeb3 Mon Sep 17 00:00:00 2001
> From: nwumengfei <362800175 at qq.com>
> Date: Tue, 24 Feb 2026 21:34:09 +0800
> Subject: [PATCH] platform: support starriver 9530
>
> ---
> lib/utils/serial/Kconfig | 3 +
> lib/utils/serial/objects.mk | 1 +
> lib/utils/serial/starriver_uart.c | 55 ++++++++
> platform/generic/Kconfig | 4 +
> platform/generic/configs/defconfig | 1 +
> platform/generic/starriver/9530/9530.c | 141 +++++++++++++++++++++
> platform/generic/starriver/9530/objects.mk | 3 +
> 7 files changed, 208 insertions(+)
> create mode 100755 lib/utils/serial/starriver_uart.c
> create mode 100755 platform/generic/starriver/9530/9530.c
> create mode 100755 platform/generic/starriver/9530/objects.mk
>
> diff --git a/lib/utils/serial/Kconfig b/lib/utils/serial/Kconfig
> index 21619d0d..75334425 100644
> --- a/lib/utils/serial/Kconfig
> +++ b/lib/utils/serial/Kconfig
> @@ -101,4 +101,7 @@ config SERIAL_SEMIHOSTING
> bool "Semihosting support"
> default n
>
> +config SERIAL_STARRIVER
> + bool "Starriver support"
> + default y
> endmenu
> diff --git a/lib/utils/serial/objects.mk b/lib/utils/serial/objects.mk
> index 94cf3a4b..24b57133 100644
> --- a/lib/utils/serial/objects.mk
> +++ b/lib/utils/serial/objects.mk
> @@ -50,3 +50,4 @@ libsbiutils-objs-$(CONFIG_SERIAL_LITEX) += serial/litex-uart.o
> libsbiutils-objs-$(CONFIG_SERIAL_UART8250) += serial/uart8250.o
> libsbiutils-objs-$(CONFIG_SERIAL_XILINX_UARTLITE) += serial/xlnx-uartlite.o
> libsbiutils-objs-$(CONFIG_SERIAL_SEMIHOSTING) += serial/semihosting.o
> +libsbiutils-objs-$(CONFIG_SERIAL_STARRIVER) += serial/starriver_uart.o
> diff --git a/lib/utils/serial/starriver_uart.c b/lib/utils/serial/starriver_uart.c
> new file mode 100755
> index 00000000..47247a93
> --- /dev/null
> +++ b/lib/utils/serial/starriver_uart.c
> @@ -0,0 +1,55 @@
> +/*
> + * SPDX-License-Identifier: BSD-2-Clause
> + *
> + * Authors:
> + * 362800175 <362800175 at qq.com>
> + *
> + */
> +
> +#include <sbi/riscv_io.h>
> +#include <sbi/sbi_types.h>
> +#include <sbi/sbi_console.h>
> +
> +#define UART0_BASE 0x9000000UL
> +#define PADDR_UARTCR (UART0_BASE + 0x030)
> +#define PADDR_UARTDR (UART0_BASE + 0x000)
> +#define PADDR_UARTSR (UART0_BASE + 0x4)
> +#define PADDR_UARTFR (UART0_BASE + 0x18)
> +#define UART0 PADDR_UARTDR
> +#define STAR_UART_TXFIFO_FULL (1<<3)
> +
> +void starriver_uart_putc(char c)
> +{
> + volatile uint64_t *dr_addr = (volatile uint64_t *)PADDR_UARTDR;
> + volatile uint64_t *fr_addr = (volatile uint64_t *)PADDR_UARTFR;
> +
> + while(*(fr_addr) & STAR_UART_TXFIFO_FULL);
> +
> + *dr_addr = c & 0xff;
> +}
> +
> +unsigned long starriver_uart_puts(const char *str, unsigned long len)
> +{
> + unsigned long i;
> + for (i = 0; i < len; i++) {
> + if (str[i] == '\n')
> + starriver_uart_putc('\r');
> + starriver_uart_putc(str[i]);
> + }
> +
> + return len;
> +}
> +
> +
> +struct sbi_console_device starriver_console = {
> + .name = "starriver_uart",
> + .console_putc = starriver_uart_putc,
> + .console_puts = starriver_uart_puts,
> +};
> +
> +int starriver_uart_init(void)
> +{
> + sbi_console_set_device(&starriver_console);
> +
> + return 0;
> +}
> diff --git a/platform/generic/Kconfig b/platform/generic/Kconfig
> index 0c11fbd2..4a783bff 100644
> --- a/platform/generic/Kconfig
> +++ b/platform/generic/Kconfig
> @@ -99,6 +99,10 @@ config PLATFORM_SPACEMIT_K1
> bool "Spacemit K1 support"
> select FDT_HSM_SPACEMIT
> default n
> +
> +config PLATFORM_STARRIVER_9530
> + bool "StarRiver 9530 support"
> + default n
>
> source "$(OPENSBI_SRC_DIR)/platform/generic/andes/Kconfig"
> source "$(OPENSBI_SRC_DIR)/platform/generic/eswin/Kconfig"
> diff --git a/platform/generic/configs/defconfig b/platform/generic/configs/defconfig
> index 727c5f4a..b531b73e 100644
> --- a/platform/generic/configs/defconfig
> +++ b/platform/generic/configs/defconfig
> @@ -12,6 +12,7 @@ CONFIG_PLATFORM_STARFIVE_JH7110=y
> CONFIG_PLATFORM_THEAD=y
> CONFIG_PLATFORM_MIPS_P8700=y
> CONFIG_PLATFORM_SPACEMIT_K1=y
> +CONFIG_PLATFORM_STARRIVER_9530=y
> CONFIG_FDT_CACHE=y
> CONFIG_FDT_CACHE_ANDES_LLCACHE=y
> CONFIG_FDT_CACHE_SIFIVE_CCACHE=y
> diff --git a/platform/generic/starriver/9530/9530.c b/platform/generic/starriver/9530/9530.c
> new file mode 100755
> index 00000000..37705692
> --- /dev/null
> +++ b/platform/generic/starriver/9530/9530.c
> @@ -0,0 +1,141 @@
> +/*
> + * SPDX-License-Identifier: BSD-2-Clause
> + *
> + * Authors:
> + * 362800175 <362800175 at qq.com>
> + *
> + */
> +#include <platform_override.h>
> +#include <sbi/riscv_io.h>
> +#include <sbi/sbi_console.h>
> +
> +#include <sbi_utils/irqchip/plic.h>
> +#include <sbi_utils/timer/aclint_mtimer.h>
> +
> +#define STARRIVER_HART_COUNT 2
> +#define STARRIVER_TIMER_FREQ 375000
> +#define STARRIVER_TIMER_ADDR 0x2000000
> +
> +#define STARRIVER_ACLINT_MSWI_ADDR (STARRIVER_TIMER_ADDR + CLINT_MSWI_OFFSET)
> +#define STARRIVER_ACLINT_MTIMER_ADDR (STARRIVER_TIMER_ADDR + 0xbff8)
> +#define STARRIVER_ACLINT_MTIMECMP_ADDR (STARRIVER_TIMER_ADDR + 0x4000)
> +
> +#define STARRIVER_PLIC_ADDR 0xc000000
> +#define STARRIVER_PLIC_SIZE 0x10000000
> +
> +#define STARRIVER_PLIC_NUM_SOURCES 0x35
> +#define STARRIVER_PLIC_NUM_PRIORITIES 7
> +
> +#define STARRIVER_MTIMECMP_SIZE 0xbff8
> +#define STARRIVER_MTIME_SIZE 0x8
> +
> +#define UART0_BASE (0x09000000UL) /*!< (UART0) Base Address */
> +#define PADDR_UARTCR (UART0_BASE + 0x030)
> +#define PADDR_UARTDR (UART0_BASE + 0x000)
> +#define SOC_DEBUG_UART PADDR_UARTDR
> +#define PADDR_UARTIBRD (UART0_BASE + 0x024)
> +#define PADDR_UARTFBRD (UART0_BASE + 0x028)
> +#define PADDR_UUARTLCR_H (UART0_BASE + 0x02c)
> +
> +#define STARRIVER_TIMER_VALUE() readl((void *)STARRIVER_ACLINT_MTIMER_ADDR)
> +
> +static struct plic_data plic = {
> + .addr = STARRIVER_PLIC_ADDR,
> + .size = STARRIVER_PLIC_SIZE,
> + .num_src = STARRIVER_PLIC_NUM_SOURCES,
> +};
> +
> +static struct aclint_mtimer_data mtimer = {
> + .mtime_freq = STARRIVER_TIMER_FREQ,
> + .mtime_addr = STARRIVER_ACLINT_MTIMER_ADDR,
> + .mtime_size = STARRIVER_MTIME_SIZE,
> + .mtimecmp_addr = STARRIVER_ACLINT_MTIMECMP_ADDR,
> + .mtimecmp_size = STARRIVER_MTIMECMP_SIZE,
> + .first_hartid = 0,
> + .hart_count = STARRIVER_HART_COUNT,
> + .has_64bit_mmio = true,
> +};
> +
> +static u32 measure_cpu_freq(u32 n)
> +{
> + u32 start_mtime, delta_mtime;
> + u32 mtime_freq = STARRIVER_TIMER_FREQ;
> + u32 tmp = (u32)STARRIVER_TIMER_VALUE();
> + u32 start_mcycle, delta_mcycle, freq;
> + /* Don't start measuring until we see an mtime tick */
> + do {
> + start_mtime = (u32)STARRIVER_TIMER_VALUE();
> + } while (start_mtime == tmp);
> + start_mcycle = csr_read(mcycle);
> + do {
> + delta_mtime = (u32)STARRIVER_TIMER_VALUE() - start_mtime;
> + } while (delta_mtime < n);
> +
> + delta_mcycle = csr_read(mcycle) - start_mcycle;
> +
> + freq = (delta_mcycle / delta_mtime) * mtime_freq
> + + ((delta_mcycle % delta_mtime) * mtime_freq) / delta_mtime;
> +
> + sbi_printf("%s: delta_mcycle = %u delta_mtime = %u mtime_freq = %u freq = %u\n",
> + __func__, delta_mcycle, delta_mtime, mtime_freq, freq);
> +
> + return freq;
> +}
> +
> +extern int starriver_uart_init(void);
> +
> +static int starriver_console_init(void)
> +{
> + return starriver_uart_init();
> +}
> +
> +static int starriver_irqchip_init(bool cold_boot)
> +{
> + int rc = 0;
> +
> + if (cold_boot) {
> + rc = plic_cold_irqchip_init(&plic);
> + }
> +
> + return rc;
> +}
> +
> +static int starriver_timer_init(bool cold_boot)
> +{
> + int rc = 0;
> +
> + if (cold_boot) {
> + measure_cpu_freq(100);
> + rc = aclint_mtimer_cold_init(&mtimer, NULL);
> + }
> +
> + return rc;
> +}
> +
> +static int starriver_early_init(bool cold_boot)
> +{
> + starriver_console_init();
> +
> + starriver_irqchip_init(cold_boot);
> +
> + starriver_timer_init(cold_boot);
> +
> + return 0;
> +}
> +
> +static int starriver_9530_platform_init(const void *fdt, int nodeoff, const struct fdt_match *match)
> +{
> + generic_platform_ops.final_init = starriver_early_init;
> +
> + return 0;
> +}
> +
> +static const struct fdt_match starriver_9530_match[] = {
> + { .compatible = "starriver,9530" },
> + { },
> +};
> +
> +const struct fdt_driver starriver_9530 = {
> + .match_table = starriver_9530_match,
> + .init = starriver_9530_platform_init,
> +};
> \ No newline at end of file
> diff --git a/platform/generic/starriver/9530/objects.mk b/platform/generic/starriver/9530/objects.mk
> new file mode 100755
> index 00000000..b88af7cd
> --- /dev/null
> +++ b/platform/generic/starriver/9530/objects.mk
> @@ -0,0 +1,3 @@
> +carray-platform_override_modules-$(CONFIG_PLATFORM_STARRIVER_9530) += starriver_9530
> +
> +platform-objs-$(CONFIG_PLATFORM_STARRIVER_9530) += starriver/9530/9530.o
More information about the opensbi
mailing list