summaryrefslogtreecommitdiff
path: root/common/uart_hostcmd.c
blob: 506a49221dd14a0f859ec1a775ebe8affb9b56d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* Copyright 2021 The ChromiumOS Authors
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "common.h"
#include "config.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);