summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2018-06-25 08:44:16 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2018-06-28 15:02:13 +0200
commit1232cd46905cc5a59dae2195c39eb5dd5742a754 (patch)
treea09d3122cd82300d25dc63261ae95bf163eee16c
parentbsp/riscv: Fix vector table for lp64 (diff)
downloadrtems-1232cd46905cc5a59dae2195c39eb5dd5742a754.tar.bz2
bsp/riscv: Add device tree support for console
Update #3433.
-rw-r--r--bsps/riscv/riscv/console/console-config.c127
-rw-r--r--bsps/riscv/riscv/console/htif.c (renamed from bsps/riscv/riscv/console/console-io.c)90
-rw-r--r--bsps/riscv/riscv/include/dev/serial/htif.h58
-rw-r--r--c/src/lib/libbsp/riscv/riscv/Makefile.am9
-rw-r--r--c/src/lib/libbsp/riscv/riscv/configure.ac3
5 files changed, 222 insertions, 65 deletions
diff --git a/bsps/riscv/riscv/console/console-config.c b/bsps/riscv/riscv/console/console-config.c
new file mode 100644
index 0000000000..06b5d69662
--- /dev/null
+++ b/bsps/riscv/riscv/console/console-config.c
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2018 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <info@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#include <rtems/bspIo.h>
+#include <rtems/console.h>
+#include <rtems/sysinit.h>
+#include <rtems/termiostypes.h>
+
+#include <bsp.h>
+#include <bsp/fdt.h>
+#include <bsp/irq.h>
+
+#include <dev/serial/htif.h>
+
+#include <libfdt.h>
+
+#if RISCV_ENABLE_HTIF_SUPPORT > 0
+static htif_console_context htif_console_instance;
+#endif
+
+static struct {
+ rtems_termios_device_context *context;
+ void (*write_polled)(
+ rtems_termios_device_context *base,
+ const char *buf,
+ size_t len
+ );
+ int (*poll_char)(rtems_termios_device_context *base);
+} riscv_console;
+
+static void riscv_output_char(char c)
+{
+ (*riscv_console.write_polled)(riscv_console.context, &c, 1);
+}
+
+static int riscv_get_console_node(const void *fdt)
+{
+ const char *stdout_path;
+ int node;
+
+ node = fdt_path_offset(fdt, "/chosen");
+
+ stdout_path = fdt_getprop(fdt, node, "stdout-path", NULL);
+ if (stdout_path == NULL) {
+ stdout_path = "";
+ }
+
+ return fdt_path_offset(fdt, stdout_path);
+}
+
+static void riscv_console_probe(void)
+{
+ const void *fdt;
+ int node;
+ int console_node;
+
+ fdt = bsp_fdt_get();
+ console_node = riscv_get_console_node(fdt);
+
+ node = fdt_next_node(fdt, -1, NULL);
+
+ while (node >= 0) {
+#if RISCV_ENABLE_HTIF_SUPPORT
+ if (fdt_node_check_compatible(fdt, node, "ucb,htif0") == 0) {
+ htif_console_context_init(&htif_console_instance.base, node);
+
+ riscv_console.context = &htif_console_instance.base;
+ riscv_console.write_polled = htif_console_write_polled;
+ riscv_console.poll_char = htif_console_poll_char;
+ };
+#endif
+
+ node = fdt_next_node(fdt, node, NULL);
+ }
+
+ BSP_output_char = riscv_output_char;
+}
+
+static void riscv_output_char_init(char c)
+{
+ riscv_console_probe();
+ riscv_output_char(c);
+}
+
+BSP_output_char_function_type BSP_output_char = riscv_output_char_init;
+
+BSP_polling_getchar_function_type BSP_poll_char = NULL;
+
+rtems_status_code console_initialize(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+)
+{
+ rtems_termios_device_context *base;
+ char htif_path[] = "/dev/ttyShtif";
+
+ rtems_termios_initialize();
+
+#if 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
+
+ return RTEMS_SUCCESSFUL;
+}
+
+RTEMS_SYSINIT_ITEM(
+ riscv_console_probe,
+ RTEMS_SYSINIT_BSP_START,
+ RTEMS_SYSINIT_ORDER_LAST
+);
diff --git a/bsps/riscv/riscv/console/console-io.c b/bsps/riscv/riscv/console/htif.c
index 6fb5705467..6b9cdedc21 100644
--- a/bsps/riscv/riscv/console/console-io.c
+++ b/bsps/riscv/riscv/console/htif.c
@@ -27,12 +27,9 @@
* SUCH DAMAGE.
*/
-#include <bsp.h>
-#include <bsp/console-polled.h>
-#include <rtems/libio.h>
-#include <stdlib.h>
+#include <dev/serial/htif.h>
+
#include <assert.h>
-#include <stdio.h>
/* Most of the code below is copied from riscv-pk project */
# define TOHOST_CMD(dev, cmd, payload) \
@@ -76,7 +73,7 @@ static void __set_tohost(uintptr_t dev, uintptr_t cmd, uintptr_t data)
tohost = TOHOST_CMD(dev, cmd, data);
}
-static int htif_console_getchar(void)
+int htif_console_poll_char(rtems_termios_device_context *base)
{
__check_fromhost();
int ch = htif_console_buf;
@@ -88,9 +85,17 @@ static int htif_console_getchar(void)
return ch - 1;
}
-static void htif_console_putchar(uint8_t ch)
+void htif_console_write_polled(
+ rtems_termios_device_context *base,
+ const char *buf,
+ size_t len
+)
{
- __set_tohost(1, 1, ch);
+ size_t i;
+
+ for (i = 0; i < len; ++i) {
+ __set_tohost(1, 1, buf[i]);
+ }
}
void htif_poweroff(void)
@@ -101,62 +106,27 @@ void htif_poweroff(void)
}
}
-void console_initialize_hardware(void)
-{
- /* Do nothing */
-}
-
-static void outbyte_console(char ch)
-{
- htif_console_putchar(ch);
-}
-
-static char inbyte_console(void)
-{
- return htif_console_getchar();
-}
-
-/*
- * console_outbyte_polled
- *
- * This routine transmits a character using polling.
- */
-void console_outbyte_polled(
- int port,
- char ch
+void htif_console_context_init(
+ rtems_termios_device_context *base,
+ int device_tree_node
)
{
- outbyte_console( ch );
+ rtems_termios_device_context_initialize(base, "HTIF");
}
-/*
- * console_inbyte_nonblocking
- *
- * This routine polls for a character.
- */
-
-int console_inbyte_nonblocking(int port)
-{
- char c;
-
- c = inbyte_console();
- if (!c) {
- return -1;
- }
- return (int) c;
-}
-
-/*
- * To support printk
- */
-
-#include <rtems/bspIo.h>
-
-static void RISCV_output_char(char c)
+static bool htif_console_first_open(
+ struct rtems_termios_tty *tty,
+ rtems_termios_device_context *base,
+ struct termios *term,
+ rtems_libio_open_close_args_t *args
+)
{
- console_outbyte_polled( 0, c );
+ return true;
}
-BSP_output_char_function_type BSP_output_char = RISCV_output_char;
-BSP_polling_getchar_function_type BSP_poll_char =
- (void *)console_inbyte_nonblocking;
+const rtems_termios_device_handler htif_console_handler = {
+ .first_open = htif_console_first_open,
+ .write = htif_console_write_polled,
+ .poll_read = htif_console_poll_char,
+ .mode = TERMIOS_POLLED
+};
diff --git a/bsps/riscv/riscv/include/dev/serial/htif.h b/bsps/riscv/riscv/include/dev/serial/htif.h
new file mode 100644
index 0000000000..c200a6f388
--- /dev/null
+++ b/bsps/riscv/riscv/include/dev/serial/htif.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2018 embedded brains GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <rtems/termiostypes.h>
+
+#ifndef DEV_SERIAL_HTIF_H
+#define DEV_SERIAL_HTIF_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+typedef struct {
+ rtems_termios_device_context base;
+} htif_console_context;
+
+void htif_console_context_init(
+ rtems_termios_device_context *base,
+ int device_tree_node
+);
+
+void htif_console_write_polled(
+ rtems_termios_device_context *base,
+ const char *buf,
+ size_t len
+);
+
+int htif_console_poll_char(rtems_termios_device_context *base);
+
+const rtems_termios_device_handler htif_console_handler;
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* DEV_SERIAL_HTIF_H */
diff --git a/c/src/lib/libbsp/riscv/riscv/Makefile.am b/c/src/lib/libbsp/riscv/riscv/Makefile.am
index bc5355f585..c8299f3e72 100644
--- a/c/src/lib/libbsp/riscv/riscv/Makefile.am
+++ b/c/src/lib/libbsp/riscv/riscv/Makefile.am
@@ -49,9 +49,6 @@ librtemsbsp_a_SOURCES +=../../../../../../bsps/riscv/riscv/clock/clockdrv.c
# Timer
librtemsbsp_a_SOURCES += ../../../../../../bsps/riscv/riscv/btimer/btimer.c
-# console
-librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/serial/console-polled.c
-
# IRQ
librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-default-handler.c
librtemsbsp_a_SOURCES += ../../../../../../bsps/riscv/riscv/irq/irq.c
@@ -59,8 +56,10 @@ librtemsbsp_a_SOURCES += ../../../../../../bsps/riscv/riscv/irq/irq.c
# Cache
librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/cache/nocache.c
-# debugio
-librtemsbsp_a_SOURCES += ../../../../../../bsps/riscv/riscv/console/console-io.c
+# Console
+librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/serial/console-termios.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/riscv/riscv/console/console-config.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/riscv/riscv/console/htif.c
if HAS_SMP
librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/start/bspsmp-dummy.c
diff --git a/c/src/lib/libbsp/riscv/riscv/configure.ac b/c/src/lib/libbsp/riscv/riscv/configure.ac
index 9d13210cd7..68a7b50871 100644
--- a/c/src/lib/libbsp/riscv/riscv/configure.ac
+++ b/c/src/lib/libbsp/riscv/riscv/configure.ac
@@ -27,6 +27,9 @@ RTEMS_BSPOPTS_HELP([BSP_FDT_BLOB_READ_ONLY],[place the FDT blob into the read-on
RTEMS_BSPOPTS_SET([BSP_FDT_BLOB_COPY_TO_READ_ONLY_LOAD_AREA],[*],[1])
RTEMS_BSPOPTS_HELP([BSP_FDT_BLOB_COPY_TO_READ_ONLY_LOAD_AREA],[copy the FDT blob into the read-only load area via bsp_fdt_copy()])
+RTEMS_BSPOPTS_SET([RISCV_ENABLE_HTIF_SUPPORT],[*],[1])
+RTEMS_BSPOPTS_HELP([RISCV_ENABLE_HTIF_SUPPORT],[enables the HTIF support if defined to a non-zero value, otherwise it is disabled (enabled by default)])
+
RTEMS_BSP_CLEANUP_OPTIONS
case "${RTEMS_BSP}" in