summaryrefslogtreecommitdiff
path: root/common/uart_hostcmd.c
diff options
context:
space:
mode:
authorJack Rosenthal <jrosenth@chromium.org>2021-02-10 12:49:39 -0700
committerCommit Bot <commit-bot@chromium.org>2021-02-11 06:43:54 +0000
commit74886bcc173fa0d11e1508d412a4be390b96edad (patch)
treec5cbfb5424b4a299456b3a67c3473abca53c6a83 /common/uart_hostcmd.c
parentce27af42105d9ceb1bd8a921e2baeacced4867bc (diff)
downloadchrome-ec-74886bcc173fa0d11e1508d412a4be390b96edad.tar.gz
common: uart: split off host commands to separate module
Split off UART host commands to a separate module for better modularity and to enable sharing the host command code with Zephyr. Note: originally I had intended to share the entire uart_buffering module with Zephyr, but our initial goal was to get working with printk as the backend instead of Zephyr's UART drivers (they are rather complex). We may end up sharing the rest of uart_buffering in the future, but this lets us scale up/down the amount of UART code sharing we do as needed. BUG=b:178033156 BRANCH=none TEST=make buildall Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: Ib63e46700fb79b46c7ec2ea52dfcbe99d9fd8bbb Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2685410 Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common/uart_hostcmd.c')
-rw-r--r--common/uart_hostcmd.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/common/uart_hostcmd.c b/common/uart_hostcmd.c
new file mode 100644
index 0000000000..5cef2a8e24
--- /dev/null
+++ b/common/uart_hostcmd.c
@@ -0,0 +1,54 @@
+/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "config.h"
+#include "common.h"
+#include "ec_commands.h"
+#include "host_command.h"
+#include "uart.h"
+
+static enum ec_status
+host_command_console_snapshot(struct host_cmd_handler_args *args)
+{
+ return uart_console_read_buffer_init();
+}
+DECLARE_HOST_COMMAND(EC_CMD_CONSOLE_SNAPSHOT, host_command_console_snapshot,
+ EC_VER_MASK(0));
+
+static enum ec_status
+host_command_console_read(struct host_cmd_handler_args *args)
+{
+ if (args->version == 0) {
+ /*
+ * Prior versions of this command only support reading from
+ * an entire snapshot, not just the output since the last
+ * snapshot.
+ */
+ return uart_console_read_buffer(CONSOLE_READ_NEXT,
+ (char *)args->response,
+ args->response_max,
+ &args->response_size);
+ } else if (IS_ENABLED(CONFIG_CONSOLE_ENABLE_READ_V1) &&
+ args->version == 1) {
+ const struct ec_params_console_read_v1 *p;
+
+ /* Check the params to figure out where to start reading. */
+ p = args->params;
+ return uart_console_read_buffer(p->subcmd,
+ (char *)args->response,
+ args->response_max,
+ &args->response_size);
+ }
+ return EC_RES_INVALID_PARAM;
+}
+
+#ifdef CONFIG_CONSOLE_ENABLE_READ_V1
+#define READ_V1_MASK EC_VER_MASK(1)
+#else
+#define READ_V1_MASK 0
+#endif
+
+DECLARE_HOST_COMMAND(EC_CMD_CONSOLE_READ, host_command_console_read,
+ EC_VER_MASK(0) | READ_V1_MASK);