summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMary Ruthven <mruthven@chromium.org>2021-11-09 16:48:46 -0600
committerCommit Bot <commit-bot@chromium.org>2021-11-18 04:50:07 +0000
commit8efbe561ab79d290eab455744af39c5f875cac92 (patch)
treea7d2e51123f8e6acc4526343a4adc82a54364bb3 /common
parent18262b77ea30bd5ea4f1c2e5c262904a6fe51677 (diff)
downloadchrome-ec-8efbe561ab79d290eab455744af39c5f875cac92.tar.gz
Revert "uart_buffering: expose interface to support non-host command"
This reverts commit 3f19d870f81f062410e30d166848d47a2a20e5d9. BUG=b:200823466 TEST=make buildall -j Change-Id: I0c6f63c96d23959a2bd63d6a27d6e4f0efa1cc5c Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3273414 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/uart_buffering.c111
1 files changed, 47 insertions, 64 deletions
diff --git a/common/uart_buffering.c b/common/uart_buffering.c
index 7e2776e7a3..5c614d0f9f 100644
--- a/common/uart_buffering.c
+++ b/common/uart_buffering.c
@@ -342,51 +342,6 @@ DECLARE_HOOK(HOOK_INIT, uart_rx_dma_init, HOOK_PRIO_DEFAULT);
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);
-#ifdef CONFIG_CONSOLE_ENABLE_READ_V1
- } else if (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);
-#endif
- }
- return EC_RES_INVALID_PARAM;
-}
-DECLARE_HOST_COMMAND(EC_CMD_CONSOLE_READ,
- host_command_console_read,
- EC_VER_MASK(0)
-#ifdef CONFIG_CONSOLE_ENABLE_READ_V1
- | EC_VER_MASK(1)
-#endif
- );
-
-enum ec_status uart_console_read_buffer_init(void)
-{
/* Assume the whole circular buffer is full */
tx_snapshot_head = tx_buf_head;
tx_snapshot_tail = TX_BUF_NEXT(tx_snapshot_head);
@@ -412,31 +367,26 @@ enum ec_status uart_console_read_buffer_init(void)
return EC_RES_SUCCESS;
}
+DECLARE_HOST_COMMAND(EC_CMD_CONSOLE_SNAPSHOT,
+ host_command_console_snapshot,
+ EC_VER_MASK(0));
-int uart_console_read_buffer(uint8_t type,
- char *dest,
- uint16_t dest_size,
- uint16_t *write_count)
+/*
+ * Common code for host_command_console_read and
+ * host_command_console_read_recent.
+ */
+static enum ec_status console_read_helper(struct host_cmd_handler_args *args,
+ int *tail)
{
- int *tail;
-
- switch (type) {
- case CONSOLE_READ_NEXT:
- tail = &tx_snapshot_tail;
- break;
- case CONSOLE_READ_RECENT:
- tail = &tx_last_snapshot_head;
- break;
- default:
- return EC_RES_INVALID_PARAM;
- }
+ char *dest = (char *)args->response;
/* If no snapshot data, return empty response */
if (tx_snapshot_head == *tail)
return EC_RES_SUCCESS;
/* Copy data to response */
- while (*tail != tx_snapshot_head && *write_count < dest_size - 1) {
+ while (*tail != tx_snapshot_head &&
+ args->response_size < args->response_max - 1) {
/*
* Copy only non-zero bytes, so that we don't copy unused
@@ -444,7 +394,7 @@ int uart_console_read_buffer(uint8_t type,
*/
if (tx_buf[*tail]) {
*(dest++) = tx_buf[*tail];
- (*write_count)++;
+ args->response_size++;
}
*tail = TX_BUF_NEXT(*tail);
@@ -452,7 +402,40 @@ int uart_console_read_buffer(uint8_t type,
/* Null-terminate */
*(dest++) = '\0';
- (*write_count)++;
+ args->response_size++;
return EC_RES_SUCCESS;
}
+
+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 console_read_helper(args, &tx_snapshot_tail);
+#ifdef CONFIG_CONSOLE_ENABLE_READ_V1
+ } else if (args->version == 1) {
+ const struct ec_params_console_read_v1 *p;
+
+ /* Check the params to figure out where to start reading. */
+ p = args->params;
+ if (p->subcmd == CONSOLE_READ_NEXT)
+ return console_read_helper(args, &tx_snapshot_tail);
+ else if (p->subcmd == CONSOLE_READ_RECENT)
+ return console_read_helper(args,
+ &tx_last_snapshot_head);
+#endif
+ }
+ return EC_RES_INVALID_PARAM;
+}
+DECLARE_HOST_COMMAND(EC_CMD_CONSOLE_READ,
+ host_command_console_read,
+ EC_VER_MASK(0)
+#ifdef CONFIG_CONSOLE_ENABLE_READ_V1
+ | EC_VER_MASK(1)
+#endif
+ );