[PATCH] risc-v: Resurrect RISCV_ENABLE_HTIF_SUPPORT
Hesham Almatary
heshamelmatary at gmail.com
Wed Jan 11 14:39:56 UTC 2023
LGTM. We also need to update the docs accordingly.
On Wed, 11 Jan 2023 at 07:45, Sebastian Huber
<sebastian.huber at embedded-brains.de> wrote:
>
> Low-end configurations may want to have the HTIF support removed.
> Enable the option by default. Fix formatting. Fix node validity
> checks.
>
> Updates #4779.
> ---
> bsps/riscv/noel/include/bsp/riscv.h | 2 --
> bsps/riscv/riscv/console/console-config.c | 9 ++++++++-
> bsps/riscv/riscv/console/htif.c | 4 ++++
> bsps/riscv/riscv/include/bsp/riscv.h | 2 ++
> bsps/riscv/riscv/irq/irq.c | 18 +++++++++++-------
> bsps/riscv/riscv/start/bsp_fatal_halt.c | 7 +++++--
> spec/build/bsps/riscv/riscv/opthtif.yml | 4 ++--
> 7 files changed, 32 insertions(+), 14 deletions(-)
>
> diff --git a/bsps/riscv/noel/include/bsp/riscv.h b/bsps/riscv/noel/include/bsp/riscv.h
> index 3ab75573f0..0fdf64747b 100644
> --- a/bsps/riscv/noel/include/bsp/riscv.h
> +++ b/bsps/riscv/noel/include/bsp/riscv.h
> @@ -50,8 +50,6 @@ extern uint32_t riscv_hart_count;
>
> uint32_t riscv_get_hart_index_by_phandle(uint32_t phandle);
>
> -void htif_poweroff(void);
> -
> #ifdef __cplusplus
> }
> #endif
> diff --git a/bsps/riscv/riscv/console/console-config.c b/bsps/riscv/riscv/console/console-config.c
> index fe339c2353..4916191e0b 100644
> --- a/bsps/riscv/riscv/console/console-config.c
> +++ b/bsps/riscv/riscv/console/console-config.c
> @@ -60,7 +60,9 @@
> static fe310_uart_context fe310_uart_instance;
> #endif
>
> +#ifdef RISCV_ENABLE_HTIF_SUPPORT
> static htif_console_context htif_console_instance;
> +#endif
>
> #if RISCV_CONSOLE_MAX_NS16550_DEVICES > 0
> static ns16550_context ns16550_instances[RISCV_CONSOLE_MAX_NS16550_DEVICES];
> @@ -163,6 +165,7 @@ static void riscv_console_probe(void)
> compat_len = 0;
> }
>
> +#ifdef RISCV_ENABLE_HTIF_SUPPORT
> /* Search for HTIF (eg. on Spike) and use it if found */
> if (fdt_stringlist_contains(compat, compat_len, "ucb,htif0")) {
> htif_console_context_init(&htif_console_instance.base, node);
> @@ -171,6 +174,7 @@ static void riscv_console_probe(void)
> riscv_console.putchar = htif_console_putchar;
> riscv_console.getchar = htif_console_getchar;
> };
> +#endif
>
> #if RISCV_CONSOLE_MAX_NS16550_DEVICES > 0
> if (
> @@ -277,9 +281,10 @@ rtems_status_code console_initialize(
> void *arg
> )
> {
> +#ifdef RISCV_ENABLE_HTIF_SUPPORT
> rtems_termios_device_context *base;
> char htif_path[] = "/dev/ttyShtif";
> -
> +#endif
> #if RISCV_CONSOLE_MAX_NS16550_DEVICES > 0
> char path[] = "/dev/ttyS?";
> size_t i;
> @@ -292,12 +297,14 @@ rtems_status_code console_initialize(
>
> rtems_termios_initialize();
>
> +#ifdef RISCV_ENABLE_HTIF_SUPPORT
> base = &htif_console_instance.base;
> rtems_termios_device_install(htif_path, &htif_console_handler, NULL, base);
>
> if (base == riscv_console.context) {
> link(htif_path, CONSOLE_DEVICE_NAME);
> }
> +#endif
>
> #if RISCV_CONSOLE_MAX_NS16550_DEVICES > 0
> for (i = 0; i < RISCV_CONSOLE_MAX_NS16550_DEVICES; ++i) {
> diff --git a/bsps/riscv/riscv/console/htif.c b/bsps/riscv/riscv/console/htif.c
> index 750abe6e3e..159d9d72fb 100644
> --- a/bsps/riscv/riscv/console/htif.c
> +++ b/bsps/riscv/riscv/console/htif.c
> @@ -29,6 +29,8 @@
>
> #include <bsp/riscv.h>
>
> +#ifdef RISCV_ENABLE_HTIF_SUPPORT
> +
> #include <dev/serial/htif.h>
>
> #include <assert.h>
> @@ -137,3 +139,5 @@ const rtems_termios_device_handler htif_console_handler = {
> .poll_read = htif_console_getchar,
> .mode = TERMIOS_POLLED
> };
> +
> +#endif /* RISCV_ENABLE_HTIF_SUPPORT */
> diff --git a/bsps/riscv/riscv/include/bsp/riscv.h b/bsps/riscv/riscv/include/bsp/riscv.h
> index a11ae4291e..bbaaa246c1 100644
> --- a/bsps/riscv/riscv/include/bsp/riscv.h
> +++ b/bsps/riscv/riscv/include/bsp/riscv.h
> @@ -52,7 +52,9 @@ extern uint32_t riscv_hart_count;
>
> uint32_t riscv_get_hart_index_by_phandle(uint32_t phandle);
>
> +#ifdef RISCV_ENABLE_HTIF_SUPPORT
> void htif_poweroff(void);
> +#endif
>
> #ifdef __cplusplus
> }
> diff --git a/bsps/riscv/riscv/irq/irq.c b/bsps/riscv/riscv/irq/irq.c
> index f0ccc6f5f0..e8d297052b 100644
> --- a/bsps/riscv/riscv/irq/irq.c
> +++ b/bsps/riscv/riscv/irq/irq.c
> @@ -249,14 +249,18 @@ static void riscv_plic_init(const void *fdt)
> plic = riscv_fdt_get_address(fdt, node);
>
> if (plic == NULL) {
> - node = fdt_node_offset_by_compatible(fdt, -1, "ucb,htif0");
> +#ifdef RISCV_ENABLE_HTIF_SUPPORT
> + node = fdt_node_offset_by_compatible(fdt, -1, "ucb,htif0");
>
> - /* Spike platform has HTIF and does not have a PLIC */
> - if (node != -1) {
> - return;
> - } else {
> - bsp_fatal(RISCV_FATAL_NO_PLIC_REG_IN_DEVICE_TREE);
> - }
> + /* Spike platform has HTIF and does not have a PLIC */
> + if (node >= 0) {
> + return;
> + } else {
> + bsp_fatal(RISCV_FATAL_NO_PLIC_REG_IN_DEVICE_TREE);
> + }
> +#else
> + bsp_fatal(RISCV_FATAL_NO_PLIC_REG_IN_DEVICE_TREE);
> +#endif
> }
>
> riscv_plic = plic;
> diff --git a/bsps/riscv/riscv/start/bsp_fatal_halt.c b/bsps/riscv/riscv/start/bsp_fatal_halt.c
> index cd7c5f20c5..e4db1f03ca 100644
> --- a/bsps/riscv/riscv/start/bsp_fatal_halt.c
> +++ b/bsps/riscv/riscv/start/bsp_fatal_halt.c
> @@ -40,10 +40,13 @@ void _CPU_Fatal_halt( uint32_t source, CPU_Uint32ptr error )
>
> fdt = bsp_fdt_get();
>
> +#ifdef RISCV_ENABLE_HTIF_SUPPORT
> node = fdt_node_offset_by_compatible(fdt, -1, "ucb,htif0");
>
> - if (node != -1)
> - htif_poweroff();
> + if (node >= 0) {
> + htif_poweroff();
> + }
> +#endif
>
> #if RISCV_ENABLE_MPFS_SUPPORT != 0
> for(;;);
> diff --git a/spec/build/bsps/riscv/riscv/opthtif.yml b/spec/build/bsps/riscv/riscv/opthtif.yml
> index 9161716869..af174f82ea 100644
> --- a/spec/build/bsps/riscv/riscv/opthtif.yml
> +++ b/spec/build/bsps/riscv/riscv/opthtif.yml
> @@ -5,10 +5,10 @@ actions:
> build-type: option
> copyrights:
> - Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
> -default: false
> +default: true
> default-by-variant: []
> description: |
> - enables the HTIF support if defined to a non-zero value, otherwise it is disabled (disabled by default)
> + Enable the Host/Target Interface (HTIF) support.
> enabled-by: true
> links: []
> name: RISCV_ENABLE_HTIF_SUPPORT
> --
> 2.35.3
>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
--
Regards,
Hesham
More information about the devel
mailing list