The existing PS2 port code waits 100ms to see if the device attached to the keyboard port responds to a reset command with two bytes (instead of the normal one byte). If an extra byte is received, it is discarded.
Receiving two bytes would be unusual and waiting to check for that event is unnecessary because the next command in the keyboard init sequence already seamlessly discards any extra bytes in the command queue.
This patch eliminates the 100ms wait, which notably reduces the SeaBIOS boot time on QEMU. This patch also forces PS2 mice to always respond with two bytes during a reset sequence (instead of just one byte), which is a good sanity check.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/hw/ps2port.c | 15 ++++++++------- src/hw/ps2port.h | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/src/hw/ps2port.c b/src/hw/ps2port.c index 4558a6e..c368afc 100644 --- a/src/hw/ps2port.c +++ b/src/hw/ps2port.c @@ -242,8 +242,8 @@ __ps2_command(int aux, int command, u8 *param) if (ret) goto fail;
- if (command == ATKBD_CMD_RESET_BAT) { - // Reset is special wrt timeouts and bytes received. + if ((u8)command == (u8)ATKBD_CMD_RESET_BAT) { + // Reset is special wrt timeouts.
// Send command. ret = ps2_sendbyte(aux, command, 1000); @@ -255,11 +255,12 @@ __ps2_command(int aux, int command, u8 *param) if (ret < 0) goto fail; param[0] = ret; - ret = ps2_recvbyte(aux, 0, 100); - if (ret < 0) - // Some devices only respond with one byte on reset. - ret = 0; - param[1] = ret; + if (receive > 1) { + ret = ps2_recvbyte(aux, 0, 500); + if (ret < 0) + goto fail; + param[1] = ret; + } } else if (command == ATKBD_CMD_GETID) { // Getid is special wrt bytes received.
diff --git a/src/hw/ps2port.h b/src/hw/ps2port.h index dc0e430..1338406 100644 --- a/src/hw/ps2port.h +++ b/src/hw/ps2port.h @@ -26,7 +26,7 @@ #define ATKBD_CMD_GETID 0x02f2 #define ATKBD_CMD_ENABLE 0x00f4 #define ATKBD_CMD_RESET_DIS 0x00f5 -#define ATKBD_CMD_RESET_BAT 0x02ff +#define ATKBD_CMD_RESET_BAT 0x01ff
// Mouse commands #define PSMOUSE_CMD_SETSCALE11 0x00e6