From 7fa009c315849fde322fd7012c956bc591cf7649 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Thu, 9 Oct 2025 18:30:58 -0400 Subject: kern/amd64: isa: Add locks to keybuf operations Signed-off-by: Ian Moffett --- src/sys/arch/amd64/isa/i8042.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/sys/arch/amd64/isa/i8042.c') diff --git a/src/sys/arch/amd64/isa/i8042.c b/src/sys/arch/amd64/isa/i8042.c index 296989f..3036184 100644 --- a/src/sys/arch/amd64/isa/i8042.c +++ b/src/sys/arch/amd64/isa/i8042.c @@ -99,7 +99,9 @@ keybuf_enter(struct keybuf *kbp, uint8_t scancode) return; } + spinlock_acquire(&lock); kbp->ring[kbp->head++] = scancode; + spinlock_release(&lock); } /* @@ -135,13 +137,15 @@ keybuf_pop(struct keybuf *kbp) static ssize_t i8042_read_tap(struct iotap_desc *desc, void *p, size_t len) { - size_t maxlen, i; + size_t maxlen, i = 0; char *pbuf = p; int8_t scancode; /* Truncate if needed */ + spinlock_acquire(&lock); maxlen = keybuf_len(&buf); if (len == 0) { + goto done; return -EAGAIN; } @@ -152,6 +156,7 @@ i8042_read_tap(struct iotap_desc *desc, void *p, size_t len) */ for (i = 0; i < MIN(len, maxlen); ++i) { scancode = keybuf_pop(&buf); + spinlock_release(&lock); /* Failed and haven't read anything? */ if (scancode < 0) { @@ -163,6 +168,8 @@ i8042_read_tap(struct iotap_desc *desc, void *p, size_t len) } } +done: + spinlock_release(&lock); return (i == 0) ? -EAGAIN : i; } @@ -270,7 +277,6 @@ i8042_init(struct module *modp) /* Enable the keyboard and flush it */ i8042_write(true, I8042_ENABLE_PORT0); - i8042_read(); return 0; } -- cgit v1.2.3