diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2019-07-02 09:17:17 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-07-04 05:43:33 +0000 |
commit | f4de8a08a0b6d222f44aa3c81bf8e7fa8f7bea2f (patch) | |
tree | 2721025844038898984f9036c5bd914db51d9b2a | |
parent | 4c9d9bc5174a9fc29223cb81f21c824b0e935003 (diff) | |
download | chrome-ec-f4de8a08a0b6d222f44aa3c81bf8e7fa8f7bea2f.tar.gz |
mec1322: Check HTIMER_PRELOAD in system_hibernate
This patch makes system_hibernate check if input time (seconds &
microseconds) exceed the max value of HTIMER_PRELOAD.
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
BUG=b/133859209,b/128455667
BRANCH=strago
TEST=Error message is printed when 'hibernate 8200' is run.
Change-Id: I3799ed141f375403ec04933821ea16c682a0d567
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1686593
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Auto-Submit: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r-- | chip/mec1322/system.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/chip/mec1322/system.c b/chip/mec1322/system.c index 310498a168..4a10e3220b 100644 --- a/chip/mec1322/system.c +++ b/chip/mec1322/system.c @@ -193,8 +193,22 @@ uint32_t system_get_scratchpad(void) void system_hibernate(uint32_t seconds, uint32_t microseconds) { int i; + int htimer; CPRINTS("%s(%d, %d)", __func__, seconds, microseconds); + if (seconds || microseconds) { + if (seconds > 2) { + MEC1322_HTIMER_CONTROL = 1; + htimer = seconds * 8 + microseconds / 125000; + } else { + MEC1322_HTIMER_CONTROL = 0; + htimer = (seconds * 1000000 + microseconds) * 2 / 71; + } + if (htimer > UINT16_MAX) { + CPRINTS("Invalid HTIMER_PRELOAD"); + return; + } + } cflush(); if (board_hibernate) @@ -285,20 +299,11 @@ void system_hibernate(uint32_t seconds, uint32_t microseconds) task_enable_irq(MEC1322_IRQ_GIRQ20); } - if (seconds || microseconds) { + if (htimer) { MEC1322_INT_BLK_EN |= 1 << 17; MEC1322_INT_ENABLE(17) |= MEC1322_INT_SOURCE_HTIMER; task_enable_irq(MEC1322_IRQ_HTIMER); - if (seconds > 2) { - ASSERT(seconds <= 0xffff / 8); - MEC1322_HTIMER_CONTROL = 1; - MEC1322_HTIMER_PRELOAD = - (seconds * 8 + microseconds / 125000); - } else { - MEC1322_HTIMER_CONTROL = 0; - MEC1322_HTIMER_PRELOAD = - (seconds * 1000000 + microseconds) * 2 / 71; - } + MEC1322_HTIMER_PRELOAD = htimer; /* Clear source register so that we will know for sure we * woke up by *NEW* timer expiration. */ MEC1322_INT_SOURCE(17) |= MEC1322_INT_SOURCE_HTIMER; |