ref: f7514acc95ee1b7515936a9a7bfd48f72d21025b
parent: 145624eec22577ec6a61cb3c469da48061d6f447
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Wed Aug 5 05:22:07 EDT 2015
devkbd: disable mosue/keyboard on shutdown, disable ps2 mouse on init, remove kbdenable()/kbdinit() on vmware, loading a new kernel sometimes reboots when wiggling the mouse. disabling keyboard and mouse on shutdown fixes the issue. make sure ps2 mouse is disabled on init, will get re-enabled in i8042auxenable(). keyboard isnt special anymore, we can just use the devreset entry point in the device to do the keyboard initialization, so kbdinit()/kbdenable() are not needed anymore.
--- a/sys/src/9/pc/devkbd.c
+++ b/sys/src/9/pc/devkbd.c
@@ -152,7 +152,8 @@
iunlock(&i8042lock);
if(c != 0xFA){
- print("i8042: %2.2ux returned to the %2.2ux command (pc=%#p)\n", c, cmd, getcallerpc(&cmd));
+ print("i8042: %2.2ux returned to the %2.2ux command (pc=%#p)\n",
+ c, cmd, getcallerpc(&cmd));
return -1;
}
return 0;
@@ -253,11 +254,12 @@
{
char *err = "i8042: aux init failed\n";
+ ilock(&i8042lock);
+
/* enable kbd/aux xfers and interrupts */
ccc &= ~Cauxdis;
ccc |= Cauxint;
- ilock(&i8042lock);
if(outready() < 0)
print(err);
outb(Cmd, 0x60); /* write control register */
@@ -274,6 +276,7 @@
}
auxputc = putc;
intrenable(IrqAUX, i8042intr, 0, BUSUNKNOWN, "kbdaux");
+
iunlock(&i8042lock);
}
@@ -285,6 +288,20 @@
i8042intr(0, 0);
}
+static void
+kbdshutdown(void)
+{
+ if(nokbd)
+ return;
+ ccc &= ~(Ckbdint|Cauxint);
+ ccc |= (Cauxdis|Ckbddis);
+ outready();
+ outb(Cmd, 0x60);
+ outready();
+ outb(Data, ccc);
+ outready();
+}
+
static Chan *
kbdattach(char *spec)
{
@@ -371,60 +388,17 @@
return n;
}
-Dev kbddevtab = {
- L'b',
- "kbd",
-
- devreset,
- devinit,
- devshutdown,
- kbdattach,
- kbdwalk,
- kbdstat,
- kbdopen,
- devcreate,
- kbdclose,
- kbdread,
- kbdbread,
- kbdwrite,
- devbwrite,
- devremove,
- devwstat,
-};
-
-
-static char *initfailed = "i8042: kbdinit failed\n";
-
-static int
-outbyte(int port, int c)
+static void
+kbdreset(void)
{
- outb(port, c);
- if(outready() < 0) {
- print(initfailed);
- return -1;
- }
- return 0;
-}
+ static char *initfailed = "i8042: init failed\n";
+ int c, try;
-void
-kbdenable(void)
-{
kbd.q = qopen(1024, Qcoalesce, 0, 0);
if(kbd.q == nil)
- panic("kbdenable");
+ panic("kbdreset");
qnoblock(kbd.q, 1);
- ioalloc(Data, 1, 0, "kbd");
- ioalloc(Cmd, 1, 0, "kbd");
-
- intrenable(IrqKBD, i8042intr, 0, BUSUNKNOWN, "kbd");
-}
-
-void
-kbdinit(void)
-{
- int c, try;
-
/* wait for a quiescent controller */
try = 1000;
while(try-- > 0 && (c = inb(Status)) & (Outbusy | Inready)) {
@@ -440,7 +414,7 @@
/* get current controller command byte */
outb(Cmd, 0x20);
if(inready() < 0){
- print("i8042: kbdinit can't read ccc\n");
+ print("i8042: can't read ccc\n");
ccc = 0;
} else
ccc = inb(Data);
@@ -448,14 +422,44 @@
/* enable kbd xfers and interrupts */
ccc &= ~Ckbddis;
ccc |= Csf | Ckbdint | Cscs1;
+
+ /* disable ps2 mouse */
+ ccc &= ~Cauxint;
+ ccc |= Cauxdis;
+
if(outready() < 0) {
print(initfailed);
return;
}
+ outb(Cmd, 0x60);
+ outready();
+ outb(Data, ccc);
+ outready();
nokbd = 0;
-
- /* disable mouse */
- if (outbyte(Cmd, 0x60) < 0 || outbyte(Data, ccc) < 0)
- print("i8042: kbdinit mouse disable failed\n");
+ ioalloc(Data, 1, 0, "kbd");
+ ioalloc(Cmd, 1, 0, "kbd");
+ intrenable(IrqKBD, i8042intr, 0, BUSUNKNOWN, "kbd");
}
+
+Dev kbddevtab = {
+ L'b',
+ "kbd",
+
+ kbdreset,
+ devinit,
+ kbdshutdown,
+ kbdattach,
+ kbdwalk,
+ kbdstat,
+ kbdopen,
+ devcreate,
+ kbdclose,
+ kbdread,
+ kbdbread,
+ kbdwrite,
+ devbwrite,
+ devremove,
+ devwstat,
+};
+
--- a/sys/src/9/pc/fns.h
+++ b/sys/src/9/pc/fns.h
@@ -96,8 +96,6 @@
int iprint(char*, ...);
int isaconfig(char*, int, ISAConf*);
void* kaddr(ulong);
-void kbdenable(void);
-void kbdinit(void);
#define kmapinval()
void ldmxcsr(ulong);
void lgdt(ushort[3]);
--- a/sys/src/9/pc/main.c
+++ b/sys/src/9/pc/main.c
@@ -137,7 +137,6 @@
print("\nPlan 9\n");
trapinit0();
- kbdinit();
i8253init();
cpuidentify();
meminit();
@@ -155,7 +154,6 @@
arch->intrinit();
timersinit();
mathinit();
- kbdenable();
if(arch->clockenable)
arch->clockenable();
procinit0();
--- a/sys/src/9/pc64/fns.h
+++ b/sys/src/9/pc64/fns.h
@@ -87,8 +87,6 @@
int iprint(char*, ...);
int isaconfig(char*, int, ISAConf*);
void* kaddr(uintptr);
-void kbdenable(void);
-void kbdinit(void);
KMap* kmap(Page*);
void kunmap(KMap*);
#define kmapinval()
--- a/sys/src/9/pc64/main.c
+++ b/sys/src/9/pc64/main.c
@@ -486,7 +486,6 @@
screeninit();
print("\nPlan 9\n");
trapinit0();
- kbdinit();
i8253init();
cpuidentify();
meminit();
@@ -504,7 +503,6 @@
arch->intrinit();
timersinit();
mathinit();
- kbdenable();
if(arch->clockenable)
arch->clockenable();
procinit0();