From patchwork Sat Feb 13 23:32:17 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin O'Connor X-Patchwork-Id: 45280 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 71AEAB7C59 for ; Sun, 14 Feb 2010 10:35:26 +1100 (EST) Received: from localhost ([127.0.0.1]:54867 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NgRUX-0005gB-Eb for incoming@patchwork.ozlabs.org; Sat, 13 Feb 2010 18:33:37 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NgRTM-0005fY-HN for qemu-devel@nongnu.org; Sat, 13 Feb 2010 18:32:24 -0500 Received: from [199.232.76.173] (port=54086 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NgRTM-0005fL-2t for qemu-devel@nongnu.org; Sat, 13 Feb 2010 18:32:24 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NgRTK-0000TH-Tv for qemu-devel@nongnu.org; Sat, 13 Feb 2010 18:32:24 -0500 Received: from mail-vw0-f45.google.com ([209.85.212.45]:42164) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NgRTK-0000TB-Iy for qemu-devel@nongnu.org; Sat, 13 Feb 2010 18:32:22 -0500 Received: by vws11 with SMTP id 11so943492vws.4 for ; Sat, 13 Feb 2010 15:32:21 -0800 (PST) Received: by 10.220.107.101 with SMTP id a37mr2269057vcp.0.1266103940523; Sat, 13 Feb 2010 15:32:20 -0800 (PST) Received: from localhost (207-172-165-101.s101.tnt1.nywnj.ny.dialup.rcn.com [207.172.165.101]) by mx.google.com with ESMTPS id 41sm48362737vws.10.2010.02.13.15.32.18 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 13 Feb 2010 15:32:19 -0800 (PST) Date: Sat, 13 Feb 2010 18:32:17 -0500 From: Kevin O'Connor To: seabios@seabios.org, qemu-devel@nongnu.org Message-ID: <20100213233217.GC18169@morn.localdomain> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-08-17) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: Subject: [Qemu-devel] [PATCH] USB HID does not support Set_Idle X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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);