Received: from eggs.gnu.org ([208.118.235.92]:51758) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ucs8n-0003Od-Bo for qemu-devel@nongnu.org; Thu, 16 May 2013 02:58:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ucs8m-0001Lz-22 for qemu-devel@nongnu.org; Thu, 16 May 2013 02:58:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:18111) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ucs8l-0001Lr-Re for qemu-devel@nongnu.org; Thu, 16 May 2013 02:58:16 -0400 Date: Thu, 16 May 2013 14:58:10 +0800 From: Amos Kong Message-ID: <20130516065810.GB3785@t430s.nay.redhat.com> References: <1368678651-3561-1-git-send-email-akong@redhat.com> <1368682228.5142.68.camel@liguang.fnst.cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1368682228.5142.68.camel@liguang.fnst.cn.fujitsu.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] ps2: add support of auto-repeat List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: li guang Cc: aliguori@us.ibm.com, lcapitulino@redhat.com, lersek@redhat.com, qemu-devel@nongnu.org, kraxel@redhat.com On Thu, May 16, 2013 at 01:30:28PM +0800, li guang wrote: > =E5=9C=A8 2013-05-16=E5=9B=9B=E7=9A=84 12:30 +0800=EF=BC=8CAmos Kong=E5= =86=99=E9=81=93=EF=BC=9A > > Guest driver sets repeat rate and delay time by KBD_CMD_SET_RATE, > > but ps2 backend doesn't process it and no auto-repeat implementation. > > This patch adds support of auto-repeat feature. > >=20 > > Guest ps2 driver sets autorepeat to fastest possible in reset, > > period: 250ms, delay: 33ms > >=20 > > Tested by 'sendkey' monitor command. > >=20 > > referenced: http://www.computer-engineering.org/ps2keyboard/ > >=20 > > Signed-off-by: Amos Kong > > --- > > hw/input/ps2.c | 42 ++++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 42 insertions(+) > >=20 > > diff --git a/hw/input/ps2.c b/hw/input/ps2.c > > index 3412079..1cfe055 100644 > > --- a/hw/input/ps2.c > > +++ b/hw/input/ps2.c > > @@ -94,6 +94,9 @@ typedef struct { > > int translate; > > int scancode_set; /* 1=3DXT, 2=3DAT, 3=3DPS/2 */ > > int ledstate; > > + int repeat_period; /* typematic period, ms */ > > + int repeat_delay; /* typematic delay, ms */ > > + int repeat_key; /* keycode to repeat */ > > } PS2KbdState; > > =20 > > typedef struct { > > @@ -146,6 +149,22 @@ void ps2_queue(void *opaque, int b) > > s->update_irq(s->update_arg, 1); > > } > > =20 > > +static QEMUTimer *repeat_timer; > > +static bool auto_repeat; > > + > > +static void repeat_ps2_queue(void *opaque) > > +{ > > + PS2KbdState *s =3D opaque; > > + Hi, Li guang =20 > theoretically, we have to check if the typematic key is in break > now, if so, we will not do repeat anymore. You mean key is released? I checked by '~keycode & 0x80', stop repeat when key is release. > don't you think we have a chance that new key can come in during > waiting? When the new key (press) comes, repeat_timer will be modified by qemu_mod_timer(), original repate will be end. =20 > > + if (auto_repeat) { > > + qemu_mod_timer(repeat_timer, qemu_get_clock_ns(vm_clock) + > > + muldiv64(get_ticks_per_sec(), s->repeat_perio= d, > > + 1000)); > > + ps2_queue(&s->common, s->repeat_key); > > + } > > +} > > + > > + > > /* > > keycode is expressed as follow: > > bit 7 - 0 key pressed, 1 =3D key released > > @@ -167,7 +186,17 @@ static void ps2_put_keycode(void *opaque, int ke= ycode) > > keycode =3D ps2_raw_keycode_set3[keycode & 0x7f]; > > } > > } > > + > > + /* only auto-repeat press event */ > > + auto_repeat =3D ~keycode & 0x80; ^^^ > > ps2_queue(&s->common, keycode); > > + > > + if (auto_repeat) { > > + s->repeat_key =3D keycode; > > + /* delay a while before first repeat */ > > + qemu_mod_timer(repeat_timer, qemu_get_clock_ns(vm_clock) + > > + muldiv64(get_ticks_per_sec(), s->repeat_delay= , 1000)); > > + } > > } > > =20 > > uint32_t ps2_read_data(void *opaque) > > @@ -213,6 +242,11 @@ static void ps2_reset_keyboard(PS2KbdState *s) > > =20 > > void ps2_write_keyboard(void *opaque, int val) > > { > > + /* repeat period/delay table from kernel (drivers/input/keyboard= /atkbd.c) */ > > + const short period[32] =3D { 33, 37, 42, 46, 50, 54, 58, = 63, 67, 75, > > + 83, 92, 100, 109, 116, 125, 133, 149, 167, 182, 200= , 217, 232, > > + 250, 270, 303, 333, 370, 400, 435, 470, 500 }; > > + const short delay[4] =3D { 250, 500, 750, 1000 }; > > PS2KbdState *s =3D (PS2KbdState *)opaque; > > =20 > > switch(s->common.write_cmd) { > > @@ -288,6 +322,11 @@ void ps2_write_keyboard(void *opaque, int val) > > s->common.write_cmd =3D -1; > > break; > > case KBD_CMD_SET_RATE: > > + /* Bit0-4 specifies the repeat rate */ > > + s->repeat_period =3D period[val & 0x1f]; > > + /* Bit5-6 bit specifies the delay time */ > > + s->repeat_delay =3D delay[(val & 0x60) >> 5]; >=20 > s/(val & 0x60) >> 5/(val & 0x60) >> 5 & 0x4/ ^^ 0x3 ? val >> 5 & 0x3 --=20 Amos.