Skip to content

Commit

Permalink
Add timeout to i8042 driver.
Browse files Browse the repository at this point in the history
Not all amd64-based PCs have functional i8042 HW (e.g. Apple products).
Because the i8042 driver busy-polls the "ready" status, this results in
performance reduction on these systems, as the device is never ready and
100% of CPU cycles are wasted checking this over and over. This commit adds
a 100 millisecond timeout the first time the device is polled, if the
timeout is reached the driver aborts.
  • Loading branch information
cvparker committed Feb 7, 2023
1 parent ea156b8 commit 2ef2f0e
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions uspace/drv/char/i8042/i8042.c
Expand Up @@ -46,6 +46,7 @@
#include <str_error.h>
#include <inttypes.h>
#include <io/chardev_srv.h>
#include <time.h>

#include "i8042.h"

Expand Down Expand Up @@ -113,9 +114,25 @@ static const irq_cmd_t i8042_cmds[] = {
/** Wait until it is safe to write to the device. */
static void wait_ready(i8042_t *dev)
{
static bool first_time = true;
assert(dev);
while (pio_read_8(&dev->regs->status) & i8042_INPUT_FULL)
;

struct timespec cur_time, start_time;
if(first_time) getuptime(&start_time);
while (pio_read_8(&dev->regs->status) & i8042_INPUT_FULL) {
if (first_time) {
nsec_t time_diff;

getuptime(&cur_time);
time_diff = ts_sub_diff(&cur_time, &start_time);
if (time_diff > 100*1000*((nsec_t)1000)) {
log_msg(LOG_DEFAULT, LVL_ERROR,
"Timed out waiting for device ready.");
abort();
}
}
}
first_time = false;
}

/** Interrupt handler routine.
Expand Down

0 comments on commit 2ef2f0e

Please sign in to comment.