diff options
author | Namyoon Woo <namyoon@chromium.org> | 2018-12-04 13:16:42 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-12-13 06:43:35 -0800 |
commit | 8f13e78bae71940b6ad7c427611b52eddfb19287 (patch) | |
tree | e785680795894c4d4088e0d3c7d477a9a5bc4fee /chip/g/post_reset.c | |
parent | 80e6645b2d9876be58102c454cb0cf188f1d1eff (diff) | |
download | chrome-ec-8f13e78bae71940b6ad7c427611b52eddfb19287.tar.gz |
cr50: VENDOR_CC_IMMEDIATE_RESET may have a delay argument.
VENDOR_CC_IMMEDIATE_RESET has either uint16_t argument or none.
The argument is a time delay in millisecond unit.
If it has no argument, then Cr50 resets H1 immediately without
any delay.
BUG=b:120485010
BRANCH=cr50
TEST=none
Change-Id: I33aaacbb0a0532aa84f39a8cd51d0d54fa2d281a
Signed-off-by: Namyoon Woo <namyoon@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1361998
Commit-Ready: Joel Kitching <kitching@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Diffstat (limited to 'chip/g/post_reset.c')
-rw-r--r-- | chip/g/post_reset.c | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/chip/g/post_reset.c b/chip/g/post_reset.c index 24a98a9470..323cde05f3 100644 --- a/chip/g/post_reset.c +++ b/chip/g/post_reset.c @@ -7,12 +7,15 @@ #include "config.h" #include "board.h" #include "console.h" +#include "endian.h" #include "extension.h" +#include "hooks.h" #include "system.h" +#include "util.h" #define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args) -void post_reset_command_handler(void *body, +static void post_reset_command_handler(void *body, size_t cmd_size, size_t *response_size) { @@ -20,20 +23,50 @@ void post_reset_command_handler(void *body, ((uint8_t *)body)[0] = 0; post_reboot_request(); } - DECLARE_EXTENSION_COMMAND(EXTENSION_POST_RESET, post_reset_command_handler); +static void deferred_reset(void) +{ + system_reset(SYSTEM_RESET_MANUALLY_TRIGGERED | SYSTEM_RESET_HARD); +} +DECLARE_DEFERRED(deferred_reset); + +#define MAX_REBOOT_TIMEOUT_MS 1000 + static enum vendor_cmd_rc immediate_reset(enum vendor_cmd_cc code, void *buf, size_t input_size, size_t *response_size) { - CPRINTS("%s: rebooting on host's request", __func__); + uint16_t timeout = 0; + + *response_size = 0; + if (input_size) { + if (input_size != sizeof(uint16_t)) { + CPRINTS("%s: incorrect request size %d", + __func__, input_size); + return VENDOR_RC_BOGUS_ARGS; + } + + /* Retrieve the requested timeout. */ + memcpy(&timeout, buf, sizeof(timeout)); + timeout = be16toh(timeout); + + if (timeout > MAX_REBOOT_TIMEOUT_MS) { + CPRINTS("%s: incorrect timeout value %d", + __func__, timeout); + return VENDOR_RC_BOGUS_ARGS; + } + } + + CPRINTS("%s: rebooting on host's request in %d ms", __func__, timeout); cflush(); /* Let the console drain. */ - /* This will never return. */ - system_reset(SYSTEM_RESET_MANUALLY_TRIGGERED | SYSTEM_RESET_HARD); - /* Never reached. */ + if (timeout) + hook_call_deferred(&deferred_reset_data, timeout * MSEC); + else + deferred_reset(); + return VENDOR_RC_SUCCESS; } DECLARE_VENDOR_COMMAND(VENDOR_CC_IMMEDIATE_RESET, immediate_reset); |