kvm tools, i8042: Sort status register bits
PATCH 1/3 kvm tools, i8042: Sort status register bits
This patch sorts the status register bits in preparation for switching over to kernel constant names.
--- tools/kvm/hw/i8042.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)
tools/kvm/hw/i8042.c +6 -3
@@ -39,11 +39,14 @@#define AUX_DEFAULT_RESOLUTION 0x2#define AUX_DEFAULT_SAMPLE 100 -#define KBD_STATUS_SYS 0x4 -#define KBD_STATUS_A2 0x8 +/* +* Status register bits +*/ +#define KBD_STATUS_AUX_OBF 0x20#define KBD_STATUS_INH 0x10 +#define KBD_STATUS_A2 0x08 +#define KBD_STATUS_SYS 0x04#define KBD_STATUS_OBF 0x01 -#define KBD_STATUS_AUX_OBF 0x20#define KBD_MODE_KBD_INT 0x01#define KBD_MODE_SYS 0x02
Signature · 1 line
1.7.0.4
PATCH 2/3 kmv tools, i8042: Use kernel status register bit names
This patch renames the status register bit constant names to be identical with drivers/input/serio/i8042.h. This makes code review easier.
--- tools/kvm/hw/i8042.c | 18 +++++++++--------- 1 files changed, 9 insertions(+), 9 deletions(-)
tools/kvm/hw/i8042.c +9 -9
@@ -42,11 +42,11 @@/* * Status register bits */ -#define KBD_STATUS_AUX_OBF 0x20 -#define KBD_STATUS_INH 0x10 -#define KBD_STATUS_A2 0x08 -#define KBD_STATUS_SYS 0x04 -#define KBD_STATUS_OBF 0x01 +#define I8042_STR_AUXDATA 0x20 +#define I8042_STR_KEYLOCK 0x10 +#define I8042_STR_CMDDAT 0x08 +#define I8042_STR_MUXERR 0x04 +#define I8042_STR_OBF 0x01#define KBD_MODE_KBD_INT 0x01#define KBD_MODE_SYS 0x02
@@ -92,16 +92,16 @@ static void kbd_update_irq(void)u8 mlevel =0 ;/* First, clear the kbd and aux output buffer full bits */ - state.status &= ~(KBD_STATUS_OBF |KBD_STATUS_AUX_OBF ); + state.status &= ~(I8042_STR_OBF |I8042_STR_AUXDATA );if (state.kcount >0 ) { - state.status |=KBD_STATUS_OBF ; + state.status |=I8042_STR_OBF ; klevel =1 ; }/* Keyboard has higher priority than mouse */ if (klevel ==0 && state.mcount !=0 ) { - state.status |=KBD_STATUS_OBF |KBD_STATUS_AUX_OBF ; + state.status |=I8042_STR_OBF |I8042_STR_AUXDATA ; mlevel =1 ; }
@@ -281,7 +281,7 @@ static void kbd_write_data(u32 val)static void kbd_reset (void ) { state = (struct kbd_state ) { - .status =KBD_STATUS_SYS |KBD_STATUS_A2 |KBD_STATUS_INH ,/* 0x1c */ + .status =I8042_STR_MUXERR |I8042_STR_CMDDAT |I8042_STR_KEYLOCK ,/* 0x1c */ .mode =KBD_MODE_KBD_INT |KBD_MODE_SYS ,/* 0x3 */ .mres =AUX_DEFAULT_RESOLUTION , .msample =AUX_DEFAULT_SAMPLE ,
Signature · 1 line
1.7.0.4
PATCH 3/3 kvm tools, i8042: Use kernel command names
In reply to Pekka EnbergThis patch renames the command constants in hw/i8042.c to use similar names as in <linux/i8042.h>. Note: we cannot use <linux/i8042.h> constants directly because they include the command and data.
--- tools/kvm/hw/i8042.c | 37 ++++++++++++++++++++----------------- 1 files changed, 20 insertions(+), 17 deletions(-)
tools/kvm/hw/i8042.c +20 -17
@@ -22,13 +22,16 @@#define I8042_DATA_REG 0x60#define I8042_COMMAND_REG 0x64 -#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 +/* +* Commands +*/ +#define I8042_CMD_CTL_RCTR 0x20 +#define I8042_CMD_CTL_WCTR 0x60 +#define I8042_CMD_AUX_LOOP 0xD3 +#define I8042_CMD_AUX_SEND 0xD4 +#define I8042_CMD_AUX_TEST 0xA9 +#define I8042_CMD_AUX_DISABLE 0xA7 +#define I8042_CMD_AUX_ENABLE 0xA8#define RESPONSE_ACK 0xFA
@@ -143,22 +146,22 @@ static void kbd_queue(u8 c)static void kbd_write_command (u32 val) {switch (val) { -case CMD_READ_MODE : +case I8042_CMD_CTL_RCTR :kbd_queue (state.mode);break ; -case CMD_WRITE_MODE : -case CMD_WRITE_AUX : -case CMD_WRITE_AUX_BUF : +case I8042_CMD_CTL_WCTR : +case I8042_CMD_AUX_SEND : +case I8042_CMD_AUX_LOOP : state.write_cmd = val;break ; -case CMD_TEST_AUX : +case I8042_CMD_AUX_TEST :/* 0 means we're a normal PS/2 mouse */ mouse_queue (0 );break ; -case CMD_DISABLE_AUX : +case I8042_CMD_AUX_DISABLE : state.mode |=MODE_DISABLE_AUX ;break ; -case CMD_ENABLE_AUX : +case I8042_CMD_AUX_ENABLE : state.mode &= ~MODE_DISABLE_AUX ;break ;default :
@@ -211,15 +214,15 @@ static u32 kbd_read_status(void)static void kbd_write_data (u32 val) {switch (state.write_cmd) { -case CMD_WRITE_MODE : +case I8042_CMD_CTL_WCTR : state.mode = val;kbd_update_irq ();break ; -case CMD_WRITE_AUX_BUF : +case I8042_CMD_AUX_LOOP :mouse_queue (val);mouse_queue (RESPONSE_ACK );break ; -case CMD_WRITE_AUX : +case I8042_CMD_AUX_SEND :/* The OS wants to send a command to the mouse */ mouse_queue (RESPONSE_ACK );switch (val) {
Signature · 1 line
1.7.0.4
Re: [PATCH 3/3] kvm tools, i8042: Use kernel command names
Re: [PATCH 3/3] kvm tools, i8042: Use kernel command names
In reply to Pekka Enbergok, with the shared commands it place here's some feature-completeness comparison of the kernel driver and the emulator:
guest driver i8042.h | hw/i8042.c emu /* * Status register bits */ #define I8042_STR_PARITY 0x80 | missing #define I8042_STR_TIMEOUT 0x40 | missing #define I8042_STR_AUXDATA 0x20 | ok #define I8042_STR_KEYLOCK 0x10 | ok #define I8042_STR_CMDDAT 0x08 | ok #define I8042_STR_MUXERR 0x04 | ok #define I8042_STR_IBF 0x02 | missing #define I8042_STR_OBF 0x01 | ok
The missing bits might be uninteresting, but wanted to map them out.
There's more divergence for commands:
guest driver i8042.h | hw/i8042.c emu
/*
* Standard commands.
*/
#define I8042_CMD_CTL_RCTR 0x0120 != 0x20 #define I8042_CMD_CTL_WCTR 0x1060 != 0x60 #define I8042_CMD_CTL_TEST 0x01aa | missing
#define I8042_CMD_KBD_DISABLE 0x00ad | missing #define I8042_CMD_KBD_ENABLE 0x00ae | missing #define I8042_CMD_KBD_TEST 0x01ab | missing #define I8042_CMD_KBD_LOOP 0x11d2 | missing
#define I8042_CMD_AUX_DISABLE 0x00a7 | ok #define I8042_CMD_AUX_ENABLE 0x00a8 | ok #define I8042_CMD_AUX_TEST 0x01a9 | != 0xa9 #define I8042_CMD_AUX_SEND 0x10d4 | != 0xd4 #define I8042_CMD_AUX_LOOP 0x11d3 | != 0xd3
#define I8042_CMD_MUX_PFX 0x0090 | missing #define I8042_CMD_MUX_SEND 0x1090 | missing
Now the missing high word might just be some command symbol encoding difference, but it might be something more substantial as well.
Thanks,
Ingo
Re: [PATCH 3/3] kvm tools, i8042: Use kernel command names
Quoted 43 lines · Ingo Molnar
ok, with the shared commands it place here's some feature-completeness comparison of the kernel driver and the emulator:
guest driver
i8042.h|hw/i8042.cemu /*
* Status register bits
*/
#defineI8042_STR_PARITY0x80 | missing#define I8042_STR_TIMEOUT 0x40 | missing #define I8042_STR_AUXDATA 0x20 | ok #define I8042_STR_KEYLOCK 0x10 | ok#define
I8042_STR_CMDDAT0x08 | ok #defineI8042_STR_MUXERR0x04 | ok #defineI8042_STR_IBF0x02| missing #defineI8042_STR_OBF0x01| okThe missing bits might be uninteresting, but wanted to map them out.
There's more divergence for commands:
guest driver
i8042.h|hw/i8042.cemu/*
* Standard commands.
*/#define
I8042_CMD_CTL_RCTR0x0120 !=0x20#defineI8042_CMD_CTL_WCTR0x1060 !=0x60#defineI8042_CMD_CTL_TEST0x01aa | missing#define
I8042_CMD_KBD_DISABLE0x00ad| missing #defineI8042_CMD_KBD_ENABLE0x00ae | missing #defineI8042_CMD_KBD_TEST0x01ab | missing #defineI8042_CMD_KBD_LOOP0x11d2 | missing#define
I8042_CMD_AUX_DISABLE0x00a7| ok #defineI8042_CMD_AUX_ENABLE0x00a8 | ok#define I8042_CMD_AUX_TEST 0x01a9 | != 0xa9 #define I8042_CMD_AUX_SEND 0x10d4 | != 0xd4 #define I8042_CMD_AUX_LOOP 0x11d3 | != 0xd3
Quoted 5 lines
#define
I8042_CMD_MUX_PFX0x0090| missing #defineI8042_CMD_MUX_SEND0x1090 | missingNow the missing high word might just be some command symbol encoding difference, but it might be something more substantial as well.
The high byte is the data byte that's written immediately after the command byte.
Pekka
Re: [PATCH 3/3] kvm tools, i8042: Use kernel command names
In reply to Ingo Molnaroh, the keyboard driver did not work for me due to:
if (vnc) {
kbd__init(kvm);
vesa__init(kvm);
}I don't have VNC installed - i just wanted to see whether the keyboard gets detected.
With kbd__init() called unconditionally it works fine here:
[ 1.658000] serio: i8042 KBD port at 0x60,0x64 irq 1 [ 1.659000] mousedev: PS/2 mouse device common for all mice
Thanks,
Ingo