mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
ps2: don't wait forever on machines with no controller
This commit is contained in:
@@ -132,7 +132,13 @@ bool ps2_init_device(int port, bool *mouse) {
|
||||
|
||||
void arch_ps2_init() {
|
||||
// XXX actually check if the controller is there
|
||||
ps2_write_command(PS2_CTLR_CMD_DISABLEP1);
|
||||
bool t;
|
||||
ps2_write_command_timeout(PS2_CTLR_CMD_DISABLEP1, 10, &t);
|
||||
if (t) {
|
||||
printf("ps2: no controller on this machine\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ps2_write_command(PS2_CTLR_CMD_DISABLEP2);
|
||||
|
||||
// just to make sure
|
||||
|
||||
@@ -63,6 +63,21 @@ static inline void ps2_write_command(uint8_t cmd) {
|
||||
outb(PS2_PORT_COMMAND, cmd);
|
||||
}
|
||||
|
||||
static inline void ps2_write_command_timeout(uint8_t cmd, int ms, bool *timeout) {
|
||||
timespec_t initial = timekeeper_timefromboot();
|
||||
|
||||
while (ps2_inbuffer_full()) {
|
||||
timespec_t current = timekeeper_timefromboot();
|
||||
if (timespec_diffms(initial, current) >= ms) {
|
||||
*timeout = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
*timeout = false;
|
||||
outb(PS2_PORT_COMMAND, cmd);
|
||||
}
|
||||
|
||||
static inline void ps2_write_data(uint8_t cmd) {
|
||||
while (ps2_inbuffer_full());
|
||||
outb(PS2_PORT_DATA, cmd);
|
||||
|
||||
Reference in New Issue
Block a user