[PATCHv2 2/2] bsps/riscv: HTIF - Use 32-bit HTIF syscalls on RV32
Sebastian Huber
sebastian.huber at embedded-brains.de
Tue Apr 9 05:43:21 UTC 2019
On 08/04/2019 14:44, Hesham Almatary wrote:
> HTIF devices are not supported on RV32, so proxy a write system call
>
> This syncs HTIF Console with riscv-pk (proxy kernel) to use 32-bit
> HTIF syscalls on RV32 instead of 64-bit commands that are not atomic.
> ---
> bsps/riscv/riscv/console/htif.c | 59 +++++++++++++++++++++++++++++----
> 1 file changed, 52 insertions(+), 7 deletions(-)
>
> diff --git a/bsps/riscv/riscv/console/htif.c b/bsps/riscv/riscv/console/htif.c
> index bcfe6a5db5..b605764fc1 100644
> --- a/bsps/riscv/riscv/console/htif.c
> +++ b/bsps/riscv/riscv/console/htif.c
> @@ -31,8 +31,8 @@
>
> #if RISCV_ENABLE_HTIF_SUPPORT != 0
>
> +#include <bsp/irq-generic.h>
> #include <dev/serial/htif.h>
> -
> #include <assert.h>
>
> /* Most of the code below is copied from riscv-pk project */
> @@ -43,12 +43,16 @@
> #define FROMHOST_CMD(fromhost_value) ((uint64_t)(fromhost_value) << 8 >> 56)
> #define FROMHOST_DATA(fromhost_value) ((uint64_t)(fromhost_value) << 16 >> 16)
>
> +#define SYS_write 64
> +
> volatile uint64_t tohost __attribute__((section(".htif")));
> volatile uint64_t fromhost __attribute__((section(".htif")));
> volatile uint64_t riscv_fill_up_htif_section[510] __attribute__((section(".htif")));
> volatile int htif_console_buf;
>
> -static void __check_fromhost(void)
> +RTEMS_INTERRUPT_LOCK_DEFINE( static, htif_lock, "htif_lock");
> +
> +static void __check_fromhost()
I guess this will introduce a warning due to the (void) -> () change.
> {
> uint64_t fh = fromhost;
> if (!fh) {
> @@ -77,23 +81,64 @@ static void __set_tohost(uintptr_t dev, uintptr_t cmd, uintptr_t data)
> tohost = TOHOST_CMD(dev, cmd, data);
> }
>
> +static void do_tohost_fromhost(uintptr_t dev, uintptr_t cmd, uintptr_t data)
> +{
> + rtems_interrupt_lock_context htif_lock_context;
> +
> + rtems_interrupt_lock_acquire( &htif_lock, &htif_lock_context );
Other functions don't use the space after ( and before ) in this file.
> + __set_tohost(dev, cmd, data);
No indent after lock acquire.
> +
> + while (1) {
> + uint64_t fh = fromhost;
> + if (fh) {
> + if (FROMHOST_DEV(fh) == dev && FROMHOST_CMD(fh) == cmd) {
> + fromhost = 0;
> + break;
> + }
> + __check_fromhost();
> + }
> + }
> + rtems_interrupt_lock_release( &htif_lock, &htif_lock_context );
> +}
> +
> +void htif_syscall(uintptr_t arg)
> +{
> + do_tohost_fromhost(0, 0, arg);
> +}
> +
> +void htif_console_putchar(rtems_termios_device_context *base, char ch)
> +{
> +#if __riscv_xlen == 32
> + // HTIF devices are not supported on RV32, so proxy a write system call
> + volatile uint64_t magic_mem[8];
> + magic_mem[0] = SYS_write;
> + magic_mem[1] = 1;
> + magic_mem[2] = (uintptr_t)&ch;
> + magic_mem[3] = 1;
> + do_tohost_fromhost(0, 0, (uintptr_t)magic_mem);
> +#else
> + rtems_interrupt_lock_context htif_lock_context;
> + rtems_interrupt_lock_acquire(&htif_lock, &htif_lock_context );
> + __set_tohost(1, 1, ch);
> + rtems_interrupt_lock_release(&htif_lock, &htif_lock_context );
> +#endif
> +}
> +
> int htif_console_getchar(rtems_termios_device_context *base)
> {
> + rtems_interrupt_lock_context htif_lock_context;
Please one blank line after declarations.
> + rtems_interrupt_lock_acquire(&htif_lock, &htif_lock_context );
> __check_fromhost();
> int ch = htif_console_buf;
> if (ch >= 0) {
> htif_console_buf = -1;
> __set_tohost(1, 0, 0);
> }
> + rtems_interrupt_lock_release(&htif_lock, &htif_lock_context );
>
> return ch - 1;
> }
>
> -void htif_console_putchar(rtems_termios_device_context *base, char c)
> -{
> - __set_tohost(1, 1, c);
> -}
> -
> static void htif_console_write_polled(
> rtems_termios_device_context *base,
> const char *buf,
--
Sebastian Huber, embedded brains GmbH
Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : sebastian.huber at embedded-brains.de
PGP : Public key available on request.
Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
More information about the devel
mailing list