Re: [PATCH] kvm tools: Add support for PS/2 keyboard system

2011-06-02 Thread Ingo Molnar

btw., i tried to match up the kernel's i8042.c with kvm's and it was 
pretty hard due to arbitrary differences. The kernel knows about:

--->
/*
 * Status register bits.
 */

#define I8042_STR_PARITY0x80
#define I8042_STR_TIMEOUT   0x40
#define I8042_STR_AUXDATA   0x20
#define I8042_STR_KEYLOCK   0x10
#define I8042_STR_CMDDAT0x08
#define I8042_STR_MUXERR0x04
#define I8042_STR_IBF   0x02
#define I8042_STR_OBF   0x01

/*
 * Control register bits.
 */

#define I8042_CTR_KBDINT0x01
#define I8042_CTR_AUXINT0x02
#define I8042_CTR_IGNKEYLOCK0x08
#define I8042_CTR_KBDDIS0x10
#define I8042_CTR_AUXDIS0x20
#define I8042_CTR_XLATE 0x40

/*
 * Return codes.
 */

#define I8042_RET_CTL_TEST  0x55
<---


While hw/i8042.c knows about similar things, just under different 
names:

--->
#define CMD_READ_MODE   0x20
#define CMD_WRITE_MODE  0x60
#define CMD_WRITE_AUX_BUF   0xD3
#define CMD_WRITE_AUX   0xD4
#define CMD_TEST_AUX0xA9
#define CMD_DISABLE_AUX 0xA7
#define CMD_ENABLE_AUX  0xA8

#define RESPONSE_ACK0xFA

#define MODE_DISABLE_AUX0x20

#define AUX_ENABLE_REPORTING0x20
#define AUX_SCALING_FLAG0x10
#define AUX_DEFAULT_RESOLUTION  0x2
#define AUX_DEFAULT_SAMPLE  100

#define KBD_STATUS_SYS  0x4
#define KBD_STATUS_A2   0x8
#define KBD_STATUS_INH  0x10
#define KBD_STATUS_OBF  0x01
#define KBD_STATUS_AUX_OBF  0x20

#define KBD_MODE_KBD_INT0x01
#define KBD_MODE_SYS0x02
<---

Would it be possible for hw/i8042.c to use the kernel names, to make 
it easier to review and debug this code?

(also, 0x2 should be 0x02 to make it easier to review as well.)

Thanks,

Ingo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] kvm tools: Add support for PS/2 keyboard system

2011-06-02 Thread Ingo Molnar

* Pekka Enberg  wrote:

> On Thu, 2011-06-02 at 11:18 +0200, Ingo Molnar wrote:
> > * Pekka Enberg  wrote:
> > 
> > > On Thu, 2 Jun 2011, Sasha Levin wrote:
> > > >Strange, those are the same errors you're supposed to get when theres no
> > > >i8042 device at all.
> > > >
> > > >Could you verify that hw/pckbd.c is being built? Did the makefile get
> > > >updated?
> > > >
> > > >What I'm seeing here is:
> > > >
> > > >[   49.326316] i8042: PNP: No PS/2 controller found. Probing ports
> > > >directly.
> > > >[   50.410492] serio: i8042 KBD port at 0x60,0x64 irq 1
> > > >[   51.518829] serio: i8042 AUX port at 0x60,0x64 irq 12
> > > >[   51.519104] mousedev: PS/2 mouse device common for all mice
> > > 
> > > kbd_init() is called if that's what you wanted to know.
> > 
> > btw., i suspect port IO printf()s in i8042.c would be rather 
> > informative now: they would nicely and synchronously interlace with 
> > guest serial console output, showing exactly what is going on in the 
> > probing sequence.
> 
> Do you mean a generic ioport tracing thing?
> 
>   ./kvm run --trace=ioport
> 
> or something?

heh, yeah :-)

btw., i'm getting the same message here:

[1.458000] usbcore: registered new interface driver libusual
[1.46] i8042: PNP: No PS/2 controller found. Probing ports directly.
[1.463000] i8042: Can't read CTR while initializing i8042
[1.464000] i8042: probe of i8042 failed with error -5
[1.465000] mousedev: PS/2 mouse device common for all mice
[1.467000] rtc_cmos rtc_cmos: rtc core: registered rtc_cmos as rtc0

Thanks,

Ingo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] kvm tools: Add support for PS/2 keyboard system

2011-06-02 Thread Sasha Levin
On Thu, 2011-06-02 at 12:15 +0300, Pekka Enberg wrote:
> On Thu, 2 Jun 2011, Sasha Levin wrote:
> > Strange, those are the same errors you're supposed to get when theres no
> > i8042 device at all.
> >
> > Could you verify that hw/pckbd.c is being built? Did the makefile get
> > updated?
> >
> > What I'm seeing here is:
> >
> > [   49.326316] i8042: PNP: No PS/2 controller found. Probing ports
> > directly.
> > [   50.410492] serio: i8042 KBD port at 0x60,0x64 irq 1
> > [   51.518829] serio: i8042 AUX port at 0x60,0x64 irq 12
> > [   51.519104] mousedev: PS/2 mouse device common for all mice
> 
> kbd_init() is called if that's what you wanted to know.

I've pulled master, and tried running keyboard on it. What I see now is:

[   33.114810] i8042: PNP: No PS/2 controller found. Probing ports
directly.
[   33.365370] serio: i8042 KBD port at 0x60,0x64 irq 1
[   33.365599] mousedev: PS/2 mouse device common for all mice

Which means that the mouse is gone. Might be related to what you're
seeing.


-- 

Sasha.

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] kvm tools: Add support for PS/2 keyboard system

2011-06-02 Thread Pekka Enberg
On Thu, 2011-06-02 at 11:18 +0200, Ingo Molnar wrote:
> * Pekka Enberg  wrote:
> 
> > On Thu, 2 Jun 2011, Sasha Levin wrote:
> > >Strange, those are the same errors you're supposed to get when theres no
> > >i8042 device at all.
> > >
> > >Could you verify that hw/pckbd.c is being built? Did the makefile get
> > >updated?
> > >
> > >What I'm seeing here is:
> > >
> > >[   49.326316] i8042: PNP: No PS/2 controller found. Probing ports
> > >directly.
> > >[   50.410492] serio: i8042 KBD port at 0x60,0x64 irq 1
> > >[   51.518829] serio: i8042 AUX port at 0x60,0x64 irq 12
> > >[   51.519104] mousedev: PS/2 mouse device common for all mice
> > 
> > kbd_init() is called if that's what you wanted to know.
> 
> btw., i suspect port IO printf()s in i8042.c would be rather 
> informative now: they would nicely and synchronously interlace with 
> guest serial console output, showing exactly what is going on in the 
> probing sequence.

Do you mean a generic ioport tracing thing?

  ./kvm run --trace=ioport

or something?

Pekka


--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] kvm tools: Add support for PS/2 keyboard system

2011-06-02 Thread Ingo Molnar

* Pekka Enberg  wrote:

> On Thu, 2 Jun 2011, Sasha Levin wrote:
> >Strange, those are the same errors you're supposed to get when theres no
> >i8042 device at all.
> >
> >Could you verify that hw/pckbd.c is being built? Did the makefile get
> >updated?
> >
> >What I'm seeing here is:
> >
> >[   49.326316] i8042: PNP: No PS/2 controller found. Probing ports
> >directly.
> >[   50.410492] serio: i8042 KBD port at 0x60,0x64 irq 1
> >[   51.518829] serio: i8042 AUX port at 0x60,0x64 irq 12
> >[   51.519104] mousedev: PS/2 mouse device common for all mice
> 
> kbd_init() is called if that's what you wanted to know.

btw., i suspect port IO printf()s in i8042.c would be rather 
informative now: they would nicely and synchronously interlace with 
guest serial console output, showing exactly what is going on in the 
probing sequence.

Thanks,

Ingo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] kvm tools: Add support for PS/2 keyboard system

2011-06-02 Thread Pekka Enberg

On Thu, 2 Jun 2011, Sasha Levin wrote:

Strange, those are the same errors you're supposed to get when theres no
i8042 device at all.

Could you verify that hw/pckbd.c is being built? Did the makefile get
updated?

What I'm seeing here is:

[   49.326316] i8042: PNP: No PS/2 controller found. Probing ports
directly.
[   50.410492] serio: i8042 KBD port at 0x60,0x64 irq 1
[   51.518829] serio: i8042 AUX port at 0x60,0x64 irq 12
[   51.519104] mousedev: PS/2 mouse device common for all mice


kbd_init() is called if that's what you wanted to know.

Pekka
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] kvm tools: Add support for PS/2 keyboard system

2011-06-02 Thread Sasha Levin
On Thu, 2011-06-02 at 11:52 +0300, Pekka Enberg wrote:
> On Wed, 1 Jun 2011, Sasha Levin wrote:
> > From: John Floren 
> >
> > Add support for PS/2 keyboard system with AUX device (aka mouse).
> > The device works with vnc, the guest must be started with the
> > '--vnc' parameter for the device to be initialized.
> >
> > Signed-off-by: John Floren 
> > [ turn into patch and clean up code ]
> > Signed-off-by: Sasha Levin 
> 
> I am seeing this in my guest dmesg:
> 
> [   24.972609] i8042: PNP: No PS/2 controller found. Probing ports 
> directly.
> [   25.568982] i8042: Can't read CTR while initializing i8042
> [   25.568996] i8042: probe of i8042 failed with error -5
> [   25.569102] mousedev: PS/2 mouse device common for all mice
> 
> and nothing happens when I try to press some keys in vncviewer. There's a 
> small blinking thingy following the mouse which I assume is our guest 
> mouse cursor?

Strange, those are the same errors you're supposed to get when theres no
i8042 device at all.

Could you verify that hw/pckbd.c is being built? Did the makefile get
updated?

What I'm seeing here is:

[   49.326316] i8042: PNP: No PS/2 controller found. Probing ports
directly.
[   50.410492] serio: i8042 KBD port at 0x60,0x64 irq 1
[   51.518829] serio: i8042 AUX port at 0x60,0x64 irq 12
[   51.519104] mousedev: PS/2 mouse device common for all mice

-- 

Sasha.

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] kvm tools: Add support for PS/2 keyboard system

2011-06-02 Thread Pekka Enberg

On Thu, 2 Jun 2011, Ingo Molnar wrote:

Since this is a PS2 keyboard and mouse driver please name it
i8042.[ch] like the kernel-side does.

that will also make it easier to find the guest-side <-> host-side
pair of guest-driver/host-driver files :-)


Fixed, thanks!
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] kvm tools: Add support for PS/2 keyboard system

2011-06-02 Thread Pekka Enberg

On Wed, 1 Jun 2011, Sasha Levin wrote:

From: John Floren 

Add support for PS/2 keyboard system with AUX device (aka mouse).
The device works with vnc, the guest must be started with the
'--vnc' parameter for the device to be initialized.

Signed-off-by: John Floren 
[ turn into patch and clean up code ]
Signed-off-by: Sasha Levin 


I am seeing this in my guest dmesg:

[   24.972609] i8042: PNP: No PS/2 controller found. Probing ports 
directly.

[   25.568982] i8042: Can't read CTR while initializing i8042
[   25.568996] i8042: probe of i8042 failed with error -5
[   25.569102] mousedev: PS/2 mouse device common for all mice

and nothing happens when I try to press some keys in vncviewer. There's a 
small blinking thingy following the mouse which I assume is our guest 
mouse cursor?


Pekka
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] kvm tools: Add support for PS/2 keyboard system

2011-06-02 Thread Ingo Molnar

* Sasha Levin  wrote:

> From: John Floren 
> 
> Add support for PS/2 keyboard system with AUX device (aka mouse).
> The device works with vnc, the guest must be started with the
> '--vnc' parameter for the device to be initialized.
> 
> Signed-off-by: John Floren 
> [ turn into patch and clean up code ]
> Signed-off-by: Sasha Levin 
> ---
>  tools/kvm/Makefile|1 +
>  tools/kvm/hw/pckbd.c  |  475 
> +

Since this is a PS2 keyboard and mouse driver please name it 
i8042.[ch] like the kernel-side does.

that will also make it easier to find the guest-side <-> host-side 
pair of guest-driver/host-driver files :-)

>  tools/kvm/hw/vesa.c   |3 +
>  tools/kvm/include/kvm/pckbd.h |   19 ++
>  tools/kvm/ioport.c|4 -
>  tools/kvm/kvm-run.c   |5 +-
>  6 files changed, 502 insertions(+), 5 deletions(-)
>  create mode 100644 tools/kvm/hw/pckbd.c
>  create mode 100644 tools/kvm/include/kvm/pckbd.h

In general the code looks very clean to me!

Found two minor nits:

> + ret = state.kq[state.kread++ % QUEUE_SIZE];
> + ret = state.mq[state.mread++ % QUEUE_SIZE];

Please increment the index explicitly, on a separate line - the 
permanent side-effect to the keyboard state is not obvious at first 
sight.

Thanks,

Ingo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] kvm tools: Add support for PS/2 keyboard system

2011-06-01 Thread Sasha Levin
From: John Floren 

Add support for PS/2 keyboard system with AUX device (aka mouse).
The device works with vnc, the guest must be started with the
'--vnc' parameter for the device to be initialized.

Signed-off-by: John Floren 
[ turn into patch and clean up code ]
Signed-off-by: Sasha Levin 
---
 tools/kvm/Makefile|1 +
 tools/kvm/hw/pckbd.c  |  475 +
 tools/kvm/hw/vesa.c   |3 +
 tools/kvm/include/kvm/pckbd.h |   19 ++
 tools/kvm/ioport.c|4 -
 tools/kvm/kvm-run.c   |5 +-
 6 files changed, 502 insertions(+), 5 deletions(-)
 create mode 100644 tools/kvm/hw/pckbd.c
 create mode 100644 tools/kvm/include/kvm/pckbd.h

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index e7ceb5c..c0feae0 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -64,6 +64,7 @@ has_vncserver := $(call 
try-cc,$(SOURCE_VNCSERVER),$(FLAGS_VNCSERVER))
 ifeq ($(has_vncserver),y)
CFLAGS  += -DCONFIG_HAS_VNCSERVER
OBJS+= hw/vesa.o
+   OBJS+= hw/pckbd.o
LIBS+= -lvncserver
 endif
 
diff --git a/tools/kvm/hw/pckbd.c b/tools/kvm/hw/pckbd.c
new file mode 100644
index 000..14d074d
--- /dev/null
+++ b/tools/kvm/hw/pckbd.c
@@ -0,0 +1,475 @@
+#include "kvm/read-write.h"
+#include "kvm/ioport.h"
+#include "kvm/mutex.h"
+#include "kvm/util.h"
+#include "kvm/term.h"
+#include "kvm/kvm.h"
+#include "kvm/pckbd.h"
+
+#include 
+#include 
+#include 
+
+#define KBD_IRQ1
+#define AUX_IRQ12
+
+#define CMD_READ_MODE  0x20
+#define CMD_WRITE_MODE 0x60
+#define CMD_WRITE_AUX_BUF  0xD3
+#define CMD_WRITE_AUX  0xD4
+#define CMD_TEST_AUX   0xA9
+#define CMD_DISABLE_AUX0xA7
+#define CMD_ENABLE_AUX 0xA8
+
+#define RESPONSE_ACK   0xFA
+
+#define MODE_DISABLE_AUX   0x20
+
+#define AUX_ENABLE_REPORTING   0x20
+#define AUX_SCALING_FLAG   0x10
+#define AUX_DEFAULT_RESOLUTION 0x2
+#define AUX_DEFAULT_SAMPLE 100
+
+#define KBD_STATUS_SYS 0x4
+#define KBD_STATUS_A2  0x8
+#define KBD_STATUS_INH 0x10
+#define KBD_STATUS_OBF 0x01
+#define KBD_STATUS_AUX_OBF 0x20
+
+#define KBD_MODE_KBD_INT   0x01
+#define KBD_MODE_SYS   0x02
+
+#define QUEUE_SIZE 128
+
+/*
+ * This represents the current state of the PS/2 keyboard system,
+ * including the AUX device (the mouse)
+ */
+struct kbd_state {
+   struct kvm  *kvm;
+
+   charkq[QUEUE_SIZE]; /* Keyboard queue */
+   int kread, kwrite;  /* Indexes into the queue */
+   int kcount; /* number of elements in queue 
*/
+
+   charmq[QUEUE_SIZE];
+   int mread, mwrite;
+   int mcount;
+
+   u8  mstatus;/* Mouse status byte */
+   u8  mres;   /* Current mouse resolution */
+   u8  msample;/* Current mouse samples/second 
*/
+
+   u8  mode;   /* i8042 mode register */
+   u8  status; /* i8042 status register */
+   /*
+* Some commands (on port 0x64) have arguments;
+* we store the command here while we wait for the argument
+*/
+   u32 write_cmd;
+};
+
+static struct kbd_statestate;
+
+/*
+ * If there are packets to be read, set the appropriate IRQs high
+ */
+static void kbd_update_irq(void)
+{
+   u8 klevel = 0;
+   u8 mlevel = 0;
+
+   /* First, clear the kbd and aux output buffer full bits */
+   state.status &= ~(KBD_STATUS_OBF | KBD_STATUS_AUX_OBF);
+
+   if (state.kcount > 0) {
+   state.status |= KBD_STATUS_OBF;
+   klevel = 1;
+   }
+
+   /* Keyboard has higher priority than mouse */
+   if (klevel == 0 && state.mcount != 0) {
+   state.status |= KBD_STATUS_OBF | KBD_STATUS_AUX_OBF;
+   mlevel = 1;
+   }
+
+   kvm__irq_line(state.kvm, KBD_IRQ, klevel);
+   kvm__irq_line(state.kvm, AUX_IRQ, mlevel);
+}
+
+/*
+ * Add a byte to the mouse queue, then set IRQs
+ */
+static void mouse_queue(u8 c)
+{
+   if (state.mcount >= QUEUE_SIZE)
+   return;
+
+   state.mq[state.mwrite++ % QUEUE_SIZE] = c;
+
+   state.mcount++;
+   kbd_update_irq();
+}
+
+/*
+ * Add a byte to the keyboard queue, then set IRQs
+ */
+static void kbd_queue(u8 c)
+{
+   if (state.kcount >= QUEUE_SIZE)
+   return;
+
+   state.kq[state.kwrite++ % QUEUE_SIZE] = c;
+
+   state.kcount++;
+   kbd_update_irq();
+}
+
+/*
+ * This function is called when the OS issues a write to port 0x64
+ */
+static void kbd_write_command(u32 val)
+{
+   switch (val) {
+   case CMD_READ_MODE:
+   kbd_qu