diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2020-09-19 10:30:14 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-09-22 06:22:34 +0000 |
commit | ecb7d230c778a2d4b80bd82740ded33b44707b36 (patch) | |
tree | 1a755daf0e3470af9d304cb4bf9687dfe401da59 /util/ectool.c | |
parent | d945d6dfec09880be4aa2a8f67f3577fc9f344d4 (diff) | |
download | chrome-ec-ecb7d230c778a2d4b80bd82740ded33b44707b36.tar.gz |
ectool: Add host command for unified host event interface
This patch adds 'hostevent' command to ectool to support unified host
event command interface (EC_CMD_HOST_EVENT).
$ ectool hostevent get 6
0x4102
$ ectool hostevent set 6 0x1000200030004000
0x1000200030004000
BUG=b:168939843
BRANCH=None
TEST=Verified on Atlas. See above.
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Change-Id: I36ab890b19c994504af88ebee90ea8cffbe02f81
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2420145
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
Diffstat (limited to 'util/ectool.c')
-rw-r--r-- | util/ectool.c | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/util/ectool.c b/util/ectool.c index 2cb5eee3d3..85be6055bf 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -172,6 +172,8 @@ const char help_str[] = " Set the delay before going into hibernation\n" " hostsleepstate\n" " Report host sleep state to the EC\n" + " hostevent\n" + " Get & set host event masks.\n" " i2cprotect <port> [status]\n" " Protect EC's I2C bus\n" " i2cread\n" @@ -555,6 +557,82 @@ int cmd_hibdelay(int argc, char *argv[]) return 0; } +static void cmd_hostevent_help(char *cmd) +{ + fprintf(stderr, + " Usage: %s get <type>\n" + " Usage: %s set <type> <value>\n" + " <type> is one of:\n" + " 1: EC_HOST_EVENT_B\n" + " 2: EC_HOST_EVENT_SCI_MASK\n" + " 3: EC_HOST_EVENT_SMI_MASK\n" + " 4: EC_HOST_EVENT_ALWAYS_REPORT_MASK\n" + " 5: EC_HOST_EVENT_ACTIVE_WAKE_MASK\n" + " 6: EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX\n" + " 7: EC_HOST_EVENT_LAZY_WAKE_MASK_S3\n" + " 8: EC_HOST_EVENT_LAZY_WAKE_MASK_S5\n" + , cmd, cmd); +} + +static int cmd_hostevent(int argc, char *argv[]) +{ + struct ec_params_host_event p; + struct ec_response_host_event r; + char *e; + int rv; + + if (argc < 2) { + fprintf(stderr, "Invalid number of params\n"); + cmd_hostevent_help(argv[0]); + return -1; + } + + if (!strcasecmp(argv[1], "get")) { + if (argc != 3) { + fprintf(stderr, "Invalid number of params\n"); + cmd_hostevent_help(argv[0]); + return -1; + } + p.action = EC_HOST_EVENT_GET; + } else if (!strcasecmp(argv[1], "set")) { + if (argc != 4) { + fprintf(stderr, "Invalid number of params\n"); + cmd_hostevent_help(argv[0]); + return -1; + } + p.action = EC_HOST_EVENT_SET; + p.value = strtoul(argv[3], &e, 0); + if (e && *e) { + fprintf(stderr, "Bad value\n"); + return -1; + } + } else { + fprintf(stderr, "Bad subcommand: %s\n", argv[1]); + return -1; + } + + p.mask_type = strtol(argv[2], &e, 0); + if (e && *e) { + fprintf(stderr, "Bad type\n"); + return -1; + } + + rv = ec_command(EC_CMD_HOST_EVENT, 0, &p, sizeof(p), &r, sizeof(r)); + if (rv == -EC_RES_ACCESS_DENIED - EECRESULT) { + fprintf(stderr, "%s isn't permitted for mask %d.\n", + p.action == EC_HOST_EVENT_SET ? "Set" : "Get", + p.mask_type); + return rv; + } else if (rv < 0) { + return rv; + } + + if (p.action == EC_HOST_EVENT_GET) + printf("0x%" PRIx64 "\n", r.value); + + return 0; +} + static int get_latest_cmd_version(uint8_t cmd, int *version) { struct ec_params_get_cmd_versions p; @@ -9870,6 +9948,7 @@ const struct command commands[] = { {"hangdetect", cmd_hang_detect}, {"hello", cmd_hello}, {"hibdelay", cmd_hibdelay}, + {"hostevent", cmd_hostevent}, {"hostsleepstate", cmd_hostsleepstate}, {"locatechip", cmd_locate_chip}, {"i2cprotect", cmd_i2c_protect}, |