vgabios: Add support for vbe get/set line length function.
[seabios.git] / src / ps2port.c
index d1e6d48ab51a10a183a4dce6b610c2cc588ceb03..58335af913852b7893ec6f4fad1c743531aabdf4 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "ioport.h" // inb
 #include "util.h" // dprintf
+#include "paravirt.h" // romfile_loadint
 #include "biosvar.h" // GET_EBDA
 #include "ps2port.h" // ps2_kbd_command
 #include "pic.h" // eoi_pic1
@@ -327,6 +328,17 @@ ps2_kbd_command(int command, u8 *param)
 int
 ps2_mouse_command(int command, u8 *param)
 {
+    // Update ps2ctr for mouse enable/disable.
+    if (command == PSMOUSE_CMD_ENABLE || command == PSMOUSE_CMD_DISABLE) {
+        u16 ebda_seg = get_ebda_seg();
+        u8 ps2ctr = GET_EBDA2(ebda_seg, ps2ctr);
+        if (command == PSMOUSE_CMD_ENABLE)
+            ps2ctr = (ps2ctr | I8042_CTR_AUXINT) & ~I8042_CTR_AUXDIS;
+        else
+            ps2ctr = (ps2ctr | I8042_CTR_AUXDIS) & ~I8042_CTR_AUXINT;
+        SET_EBDA2(ebda_seg, ps2ctr, ps2ctr);
+    }
+
     return ps2_command(1, command, param);
 }
 
@@ -427,9 +439,19 @@ keyboard_init(void *data)
 
     /* ------------------- keyboard side ------------------------*/
     /* reset keyboard and self test  (keyboard side) */
-    ret = ps2_kbd_command(ATKBD_CMD_RESET_BAT, param);
-    if (ret)
-        return;
+    int spinupdelay = romfile_loadint("etc/ps2-keyboard-spinup", 0);
+    u64 end = calc_future_tsc(spinupdelay);
+    for (;;) {
+        ret = ps2_kbd_command(ATKBD_CMD_RESET_BAT, param);
+        if (!ret)
+            break;
+        if (check_tsc(end)) {
+            if (spinupdelay)
+                warn_timeout();
+            return;
+        }
+        yield();
+    }
     if (param[0] != 0xaa) {
         dprintf(1, "keyboard self test failed (got %x not 0xaa)\n", param[0]);
         return;