All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] USB HID does not support Set_Idle
@ 2010-02-13 23:32 Kevin O'Connor
  2010-02-19 21:48 ` Anthony Liguori
  0 siblings, 1 reply; 2+ messages in thread
From: Kevin O'Connor @ 2010-02-13 23:32 UTC (permalink / raw)
  To: seabios, qemu-devel

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


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);

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] USB HID does not support Set_Idle
  2010-02-13 23:32 [Qemu-devel] [PATCH] USB HID does not support Set_Idle Kevin O'Connor
@ 2010-02-19 21:48 ` Anthony Liguori
  0 siblings, 0 replies; 2+ messages in thread
From: Anthony Liguori @ 2010-02-19 21:48 UTC (permalink / raw)
  To: Kevin O'Connor; +Cc: seabios, qemu-devel

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);
>
>
>
>    

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-02-19 21:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-13 23:32 [Qemu-devel] [PATCH] USB HID does not support Set_Idle Kevin O'Connor
2010-02-19 21:48 ` Anthony Liguori

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.