From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Niahw-0005Pf-4e for qemu-devel@nongnu.org; Fri, 19 Feb 2010 16:48:20 -0500 Received: from [199.232.76.173] (port=43100 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Niahv-0005Ow-BX for qemu-devel@nongnu.org; Fri, 19 Feb 2010 16:48:19 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Niaht-0007N0-Pc for qemu-devel@nongnu.org; Fri, 19 Feb 2010 16:48:19 -0500 Received: from mail-gx0-f213.google.com ([209.85.217.213]:41706) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Niaht-0007Mm-HN for qemu-devel@nongnu.org; Fri, 19 Feb 2010 16:48:17 -0500 Received: by gxk5 with SMTP id 5so327932gxk.16 for ; Fri, 19 Feb 2010 13:48:16 -0800 (PST) Message-ID: <4B7F071E.5090400@codemonkey.ws> Date: Fri, 19 Feb 2010 15:48:14 -0600 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] USB HID does not support Set_Idle References: <20100213233217.GC18169@morn.localdomain> In-Reply-To: <20100213233217.GC18169@morn.localdomain> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin O'Connor Cc: seabios@seabios.org, qemu-devel@nongnu.org On 02/13/2010 05:32 PM, Kevin O'Connor wrote: > I found that the QEMU USB keyboard support does not work properly with > the Set_Idle command. Once a non-zero value is given to Set_Idle, > then the keyboard reports an event on every poll - not based on the > time issued in the Set_Idle command. > > I changed the code (see patch below) and it works for me. I'm not > that familiar with the qemu internals, so I'm not sure if this is the > best way to implement this feature. > > -Kevin > Applied. Thanks. Regards, Anthony Liguori > > diff --git a/hw/usb-hid.c b/hw/usb-hid.c > index 4f320d7..bf456bb 100644 > --- a/hw/usb-hid.c > +++ b/hw/usb-hid.c > @@ -66,6 +66,7 @@ typedef struct USBHIDState { > int kind; > int protocol; > uint8_t idle; > + int64_t next_idle_clock; > int changed; > void *datain_opaque; > void (*datain)(void *); > @@ -630,6 +631,11 @@ static void usb_keyboard_handle_reset(USBDevice *dev) > s->protocol = 1; > } > > +static void usb_hid_set_next_idle(USBHIDState *s, int64_t curtime) > +{ > + s->next_idle_clock = curtime + (get_ticks_per_sec() * s->idle * 4) / 1000; > +} > + > static int usb_hid_handle_control(USBDevice *dev, int request, int value, > int index, int length, uint8_t *data) > { > @@ -795,6 +801,7 @@ static int usb_hid_handle_control(USBDevice *dev, int request, int value, > break; > case SET_IDLE: > s->idle = (uint8_t) (value>> 8); > + usb_hid_set_next_idle(s, qemu_get_clock(vm_clock)); > ret = 0; > break; > default: > @@ -813,9 +820,10 @@ static int usb_hid_handle_data(USBDevice *dev, USBPacket *p) > switch(p->pid) { > case USB_TOKEN_IN: > if (p->devep == 1) { > - /* TODO: Implement finite idle delays. */ > - if (!(s->changed || s->idle)) > + int64_t curtime = qemu_get_clock(vm_clock); > + if (!s->changed&& (!s->idle || s->next_idle_clock - curtime> 0)) > return USB_RET_NAK; > + usb_hid_set_next_idle(s, curtime); > s->changed = 0; > if (s->kind == USB_MOUSE) > ret = usb_mouse_poll(s, p->data, p->len); > > > >