kvm tools: Add support for PS/2 keyboard system
PATCH 1/1 kvm tools: Add support for PS/2 keyboard system
From: John Floren <[email protected]>
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.
--- 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
tools/kvm/Makefile +1 -0
@@ -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
tools/kvm/hw/pckbd.c new file +475 -0
475 lines not on this page · raw message
tools/kvm/hw/vesa.c +3 -0
@@ -7,6 +7,7 @@#include "kvm/irq.h" #include "kvm/kvm.h" #include "kvm/pci.h" +#include "kvm/pckbd.h" #include <sys/types.h> #include <sys/ioctl.h>
@@ -99,6 +100,8 @@ void *vesa__dovnc(void *v) server =rfbGetScreen (&argc, (char **) argv,VESA_WIDTH ,VESA_HEIGHT ,8 ,3 ,4 ); server->frameBuffer = videomem; server->alwaysShared = TRUE; + server->kbdAddEvent = kbd_handle_key; + server->ptrAddEvent = kbd_handle_ptr;rfbInitServer (server);while (rfbIsActive (server)) {
tools/kvm/include/kvm/pckbd.h new file +19 -0
@@ -0,0 +1,19 @@ +#ifndef KVM__PCKBD_H +#define KVM__PCKBD_H + +void kbd__init (struct kvm *kvm); + +#ifdef CONFIG_HAS_VNCSERVER +#include <rfb/keysym.h> +#include <rfb/rfb.h> + +void kbd_handle_key (rfbBool ,rfbKeySym ,rfbClientPtr ); +void kbd_handle_ptr (int ,int ,int ,rfbClientPtr ); + +#else + +void kbd__init (struct kvm *kvm) { } + +#endif + +#endif
tools/kvm/ioport.c +0 -4
@@ -160,10 +160,6 @@ void ioport__setup_legacy(void)/* PORT 0040-005F - PIT - PROGRAMMABLE INTERVAL TIMER (8253, 8254) */ ioport__register (0x0040 , &dummy_read_write_ioport_ops,4 ,NULL ); -/* PORT 0060-006F - KEYBOARD CONTROLLER 804x (8041, 8042) (or PPI (8255) on PC,XT) */ -ioport__register (0x0060 , &dummy_read_write_ioport_ops,2 ,NULL ); -ioport__register (0x0064 , &dummy_read_write_ioport_ops,1 ,NULL ); -/* 0x00A0 - 0x00AF - 8259A PIC 2 */ ioport__register (0x00A0 , &dummy_read_write_ioport_ops,2 ,NULL );
tools/kvm/kvm-run.c +4 -1
@@ -30,6 +30,7 @@#include <kvm/virtio-9p.h> #include <kvm/vesa.h> #include <kvm/ioeventfd.h> +#include <kvm/pckbd.h> /* header files for gitish interface */ #include <kvm/kvm-run.h>
@@ -611,8 +612,10 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)kvm__init_ram (kvm); -if (vnc) +if (vnc) { +kbd__init (kvm);vesa__init (kvm); + }thread_pool__init (nr_online_cpus);ioeventfd__start ();
Signature · 1 line
1.7.5.3
Quoted 6 lines · Sasha Levin
From: John Floren <[email protected]>
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.
Quoted 6 lines
Signed-off-by John Floren <[email protected]>[ turn into patch and clean up code ]Signed-off-by Sasha Levin <[email protected]>--- 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 :-)
Quoted 7 lines
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:
tools/kvm/hw/pckbd.c line 173
Quoted 2 lines
tools/kvm/hw/pckbd.c new file +2
-0+ 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
Quoted 5 lines · Ingo Molnar
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!
Quoted 9 lines · Sasha Levin
From: John Floren <[email protected]>
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 <[email protected]>[ turn into patch and clean up code ]Signed-off-by Sasha Levin <[email protected]>
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
Quoted 19 lines · Pekka Enberg
Quoted 9 lines · Sasha Levin
From: John Floren <[email protected]>
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 <[email protected]>[ turn into patch and clean up code ]Signed-off-by Sasha Levin <[email protected]>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
Quoted 3 lines
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
Signature · 1 line
Sasha.
Quoted 6 lines · Sasha Levin
Strange, those are the same errors you're supposed to get when theres no i8042 device at all.
Could you verify that
hw/pckbd.cis being built? Did the makefile get updated?
Quoted 7 lines
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
Quoted 9 lines · Pekka Enberg
Quoted 8 lines · Sasha Levin
Strange, those are the same errors you're supposed to get when theres no i8042 device at all.
Could you verify that
hw/pckbd.cis being built? Did the makefile get updated?What I'm seeing here is:
Quoted 7 lines
Quoted 5 lines
[ 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
Quoted 17 lines · Ingo Molnar
Quoted 15 lines · Pekka Enberg
Quoted 13 lines · Sasha Levin
Strange, those are the same errors you're supposed to get when theres no i8042 device at all.
Could you verify that
hw/pckbd.cis 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
Quoted 6 lines
Quoted 1 line
kbd_init()is called if that's what you wanted to know.btw., i suspect port IO printf()s in
i8042.cwould 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
Quoted 25 lines · Pekka Enberg
Quoted 17 lines · Ingo Molnar
Quoted 15 lines · Pekka Enberg
Quoted 13 lines · Sasha Levin
Strange, those are the same errors you're supposed to get when theres no i8042 device at all.
Could you verify that
hw/pckbd.cis 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 miceQuoted 6 lines
Quoted 1 line
kbd_init()is called if that's what you wanted to know.btw., i suspect port IO printf()s in
i8042.cwould 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.
Quoted 5 lines
Do you mean a generic ioport tracing thing?
./kvm run --trace=ioportor something?
heh, yeah :-)
btw., i'm getting the same message here:
[ 1.458000] usbcore: registered new interface driver libusual [ 1.460000] 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
Quoted 9 lines · Pekka Enberg
Quoted 8 lines · Sasha Levin
Strange, those are the same errors you're supposed to get when theres no i8042 device at all.
Could you verify that
hw/pckbd.cis being built? Did the makefile get updated?What I'm seeing here is:
Quoted 7 lines
Quoted 5 lines
[ 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.
Signature · 1 line
Sasha.
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_PARITY 0x80 #define I8042_STR_TIMEOUT 0x40 #define I8042_STR_AUXDATA 0x20 #define I8042_STR_KEYLOCK 0x10 #define I8042_STR_CMDDAT 0x08 #define I8042_STR_MUXERR 0x04 #define I8042_STR_IBF 0x02 #define I8042_STR_OBF 0x01
/*
* Control register bits.
*/
#define I8042_CTR_KBDINT 0x01 #define I8042_CTR_AUXINT 0x02 #define I8042_CTR_IGNKEYLOCK 0x08 #define I8042_CTR_KBDDIS 0x10 #define I8042_CTR_AUXDIS 0x20 #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_AUX 0xA9 #define CMD_DISABLE_AUX 0xA7 #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
<-------------------
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