summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaul E Rangel <rrangel@chromium.org>2020-08-06 10:06:03 -0600
committerCommit Bot <commit-bot@chromium.org>2020-08-06 21:36:06 +0000
commitda7d2c02f003d4ec739987624a13a3e7ac639613 (patch)
tree50866fd49273d9f9b6825262eec31ee211a97580
parent69bab88511023f0742aa2794698b3cab7f816eb6 (diff)
downloadchrome-ec-da7d2c02f003d4ec739987624a13a3e7ac639613.tar.gz
chip/npcx/lpc: Read HIKMST before HIKMDI
Reading HIKMDI causes the IBF flag to deassert and allows the host to write a new byte into the input buffer. So if we don't capture the status before reading HIKMDI we will race with the host and get an invalid value for HIKMST.A20. BUG=b:162539945, b:157617092, b:159282882 BRANCH=none TEST=Boot ezkinil and make sure keyboard still functions. Signed-off-by: Raul E Rangel <rrangel@chromium.org> Change-Id: Ia8dcd18e3de31b4fa8c1742c7604d5c39e80dc51 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2341090 Commit-Queue: Edward Hill <ecgh@chromium.org> Reviewed-by: Edward Hill <ecgh@chromium.org>
-rw-r--r--chip/npcx/lpc.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/chip/npcx/lpc.c b/chip/npcx/lpc.c
index 8572ce497d..b287ad8c36 100644
--- a/chip/npcx/lpc.c
+++ b/chip/npcx/lpc.c
@@ -518,11 +518,19 @@ static void handle_host_write(int is_cmd)
/* KB controller input buffer full ISR */
void lpc_kbc_ibf_interrupt(void)
{
+ uint8_t status;
uint8_t ibf;
/* If "command" input 0, else 1*/
if (lpc_keyboard_input_pending()) {
+ /*
+ * Reading HIKMDI causes the IBF flag to deassert and allows
+ * the host to write a new byte into the input buffer. So if we
+ * don't capture the status before reading HIKMDI we will race
+ * with the host and get an invalid value for HIKMST.A20.
+ */
+ status = NPCX_HIKMST;
ibf = NPCX_HIKMDI;
- keyboard_host_write(ibf, (NPCX_HIKMST & 0x08) ? 1 : 0);
+ keyboard_host_write(ibf, (status & 0x08) ? 1 : 0);
CPRINTS("ibf isr %02x", ibf);
task_wake(TASK_ID_KEYPROTO);
} else {