From 828f6b428e541363b386d579afc1740059d01739 Mon Sep 17 00:00:00 2001 From: Nico Huber Date: Sun, 1 Nov 2020 19:49:55 +0100 Subject: libpayload/keyboard: Avoid races around input draining Draining the keyboard's buffer is only possible when the keyboard port is enabled. We should also disable input scanning before, as the buffer could be filled again with new keystrokes otherwise. Change-Id: Ibac9c0d04880ff4a3efda5ac53da2f9731f6602c Signed-off-by: Nico Huber Reviewed-on: https://review.coreboot.org/c/coreboot/+/47085 Tested-by: build bot (Jenkins) Reviewed-by: Angel Pons --- payloads/libpayload/drivers/i8042/keyboard.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'payloads') diff --git a/payloads/libpayload/drivers/i8042/keyboard.c b/payloads/libpayload/drivers/i8042/keyboard.c index 46afdc03f0..9da3902168 100644 --- a/payloads/libpayload/drivers/i8042/keyboard.c +++ b/payloads/libpayload/drivers/i8042/keyboard.c @@ -374,11 +374,13 @@ void keyboard_init(void) if (!i8042_probe() || !i8042_has_ps2()) return; - keyboard_drain_input(); - /* Enable first PS/2 port */ i8042_cmd(I8042_CMD_EN_KB); + /* Disable scanning */ + keyboard_cmd(I8042_KBCMD_DEFAULT_DIS); + keyboard_drain_input(); + i8042_set_kbd_translation(false); if (set_scancode_set(2)) @@ -404,10 +406,9 @@ void keyboard_disconnect(void) if (!i8042_has_ps2()) return; - keyboard_drain_input(); - /* Disable scanning */ keyboard_cmd(I8042_KBCMD_DEFAULT_DIS); + keyboard_drain_input(); /* Send keyboard disconnect command */ i8042_cmd(I8042_CMD_DIS_KB); -- cgit v1.2.3