From 74886bcc173fa0d11e1508d412a4be390b96edad Mon Sep 17 00:00:00 2001 From: Jack Rosenthal Date: Wed, 10 Feb 2021 12:49:39 -0700 Subject: 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 Change-Id: Ib63e46700fb79b46c7ec2ea52dfcbe99d9fd8bbb Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2685410 Reviewed-by: Simon Glass --- common/uart_hostcmd.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 common/uart_hostcmd.c (limited to 'common/uart_hostcmd.c') 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); -- cgit v1.2.1