From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 15/16] hid: move idle+protocol from usb-hid to hid too.
Date: Thu, 4 Aug 2011 17:10:25 +0200 [thread overview]
Message-ID: <1312470626-25872-16-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1312470626-25872-1-git-send-email-kraxel@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/hid.c | 8 ++++++++
hw/hid.h | 4 ++++
hw/usb-hid.c | 36 +++++++++++++-----------------------
3 files changed, 25 insertions(+), 23 deletions(-)
diff --git a/hw/hid.c b/hw/hid.c
index 1893ae5..7b5ef5f 100644
--- a/hw/hid.c
+++ b/hw/hid.c
@@ -24,6 +24,7 @@
*/
#include "hw.h"
#include "console.h"
+#include "qemu-timer.h"
#include "hid.h"
#define HID_USAGE_ERROR_ROLLOVER 0x01
@@ -73,6 +74,11 @@ bool hid_has_events(HIDState *hs)
return hs->n > 0;
}
+void hid_set_next_idle(HIDState *hs, int64_t curtime)
+{
+ hs->next_idle_clock = curtime + (get_ticks_per_sec() * hs->idle * 4) / 1000;
+}
+
static void hid_pointer_event_clear(HIDPointerEvent *e, int buttons)
{
e->xdx = e->ydy = e->dz = 0;
@@ -365,6 +371,8 @@ void hid_reset(HIDState *hs)
}
hs->head = 0;
hs->n = 0;
+ hs->protocol = 1;
+ hs->idle = 0;
}
void hid_free(HIDState *hs)
diff --git a/hw/hid.h b/hw/hid.h
index 99910c3..4a8fa5b 100644
--- a/hw/hid.h
+++ b/hw/hid.h
@@ -39,6 +39,9 @@ struct HIDState {
uint32_t head; /* index into circular queue */
uint32_t n;
int kind;
+ int32_t protocol;
+ uint8_t idle;
+ int64_t next_idle_clock;
HIDEventFunc event;
};
@@ -47,6 +50,7 @@ void hid_reset(HIDState *hs);
void hid_free(HIDState *hs);
bool hid_has_events(HIDState *hs);
+void hid_set_next_idle(HIDState *hs, int64_t curtime);
int hid_pointer_poll(HIDState *hs, uint8_t *buf, int len);
int hid_keyboard_poll(HIDState *hs, uint8_t *buf, int len);
int hid_keyboard_write(HIDState *hs, uint8_t *buf, int len);
diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index 48ce743..e5d57de 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -45,9 +45,6 @@
typedef struct USBHIDState {
USBDevice dev;
HIDState hid;
- int32_t protocol;
- uint8_t idle;
- int64_t next_idle_clock;
void *datain_opaque;
void (*datain)(void *);
} USBHIDState;
@@ -377,13 +374,6 @@ static void usb_hid_handle_reset(USBDevice *dev)
USBHIDState *us = DO_UPCAST(USBHIDState, dev, dev);
hid_reset(&us->hid);
- us->protocol = 1;
- us->idle = 0;
-}
-
-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, USBPacket *p,
@@ -448,22 +438,22 @@ static int usb_hid_handle_control(USBDevice *dev, USBPacket *p,
goto fail;
}
ret = 1;
- data[0] = us->protocol;
+ data[0] = hs->protocol;
break;
case SET_PROTOCOL:
if (hs->kind != HID_KEYBOARD && hs->kind != HID_MOUSE) {
goto fail;
}
ret = 0;
- us->protocol = value;
+ hs->protocol = value;
break;
case GET_IDLE:
ret = 1;
- data[0] = us->idle;
+ data[0] = hs->idle;
break;
case SET_IDLE:
- us->idle = (uint8_t) (value >> 8);
- usb_hid_set_next_idle(us, qemu_get_clock_ns(vm_clock));
+ hs->idle = (uint8_t) (value >> 8);
+ hid_set_next_idle(hs, qemu_get_clock_ns(vm_clock));
ret = 0;
break;
default:
@@ -486,10 +476,10 @@ static int usb_hid_handle_data(USBDevice *dev, USBPacket *p)
if (p->devep == 1) {
int64_t curtime = qemu_get_clock_ns(vm_clock);
if (!hid_has_events(hs) &&
- (!us->idle || us->next_idle_clock - curtime > 0)) {
+ (!hs->idle || hs->next_idle_clock - curtime > 0)) {
return USB_RET_NAK;
}
- usb_hid_set_next_idle(us, curtime);
+ hid_set_next_idle(hs, curtime);
if (hs->kind == HID_MOUSE || hs->kind == HID_TABLET) {
ret = hid_pointer_poll(hs, buf, p->iov.size);
} else if (hs->kind == HID_KEYBOARD) {
@@ -552,8 +542,8 @@ static int usb_hid_post_load(void *opaque, int version_id)
{
USBHIDState *s = opaque;
- if (s->idle) {
- usb_hid_set_next_idle(s, qemu_get_clock_ns(vm_clock));
+ if (s->hid.idle) {
+ hid_set_next_idle(&s->hid, qemu_get_clock_ns(vm_clock));
}
return 0;
}
@@ -581,8 +571,8 @@ static const VMStateDescription vmstate_usb_ptr = {
vmstate_usb_ptr_queue, HIDPointerEvent),
VMSTATE_UINT32(hid.head, USBHIDState),
VMSTATE_UINT32(hid.n, USBHIDState),
- VMSTATE_INT32(protocol, USBHIDState),
- VMSTATE_UINT8(idle, USBHIDState),
+ VMSTATE_INT32(hid.protocol, USBHIDState),
+ VMSTATE_UINT8(hid.idle, USBHIDState),
VMSTATE_END_OF_LIST()
}
};
@@ -601,8 +591,8 @@ static const VMStateDescription vmstate_usb_kbd = {
VMSTATE_UINT8(hid.kbd.leds, USBHIDState),
VMSTATE_UINT8_ARRAY(hid.kbd.key, USBHIDState, 16),
VMSTATE_INT32(hid.kbd.keys, USBHIDState),
- VMSTATE_INT32(protocol, USBHIDState),
- VMSTATE_UINT8(idle, USBHIDState),
+ VMSTATE_INT32(hid.protocol, USBHIDState),
+ VMSTATE_UINT8(hid.idle, USBHIDState),
VMSTATE_END_OF_LIST()
}
};
--
1.7.1
next prev parent reply other threads:[~2011-08-04 15:11 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-04 15:10 [Qemu-devel] [PULL] usb patch queue: iovecs, hid split, misc fixes Gerd Hoffmann
2011-08-04 15:10 ` [Qemu-devel] [PATCH 01/16] re-activate usb-host for bsd Gerd Hoffmann
2011-08-04 18:50 ` Blue Swirl
2011-08-04 18:53 ` Gerd Hoffmann
2011-08-04 15:10 ` [Qemu-devel] [PATCH 02/16] Add iov_hexdump() Gerd Hoffmann
2011-08-04 15:10 ` [Qemu-devel] [PATCH 03/16] Add iov_clear() Gerd Hoffmann
2011-08-05 11:30 ` Kevin Wolf
2011-08-05 14:19 ` Gerd Hoffmann
2011-08-04 15:10 ` [Qemu-devel] [PATCH 04/16] move QEMUSGList typedef Gerd Hoffmann
2011-08-04 15:10 ` [Qemu-devel] [PATCH 05/16] usb: use iovecs in USBPacket Gerd Hoffmann
2011-08-04 15:10 ` [Qemu-devel] [PATCH 06/16] usb-serial: iovec support Gerd Hoffmann
2011-08-04 15:10 ` [Qemu-devel] [PATCH 07/16] usb-host: " Gerd Hoffmann
2011-08-04 15:10 ` [Qemu-devel] [PATCH 08/16] usb-storage: " Gerd Hoffmann
2011-08-04 15:10 ` [Qemu-devel] [PATCH 09/16] uhci: remove buffer Gerd Hoffmann
2011-08-04 15:10 ` [Qemu-devel] [PATCH 10/16] ehci: iovec support, " Gerd Hoffmann
2011-08-04 15:10 ` [Qemu-devel] [PATCH 11/16] usb-hid: create & use HIDState Gerd Hoffmann
2011-08-04 15:10 ` [Qemu-devel] [PATCH 12/16] usb-hid: add event callback Gerd Hoffmann
2011-08-04 15:10 ` [Qemu-devel] [PATCH 13/16] usb-hid: add hid_has_events() Gerd Hoffmann
2011-08-08 8:32 ` TeLeMan
2011-08-10 15:17 ` Gerd Hoffmann
2011-08-11 5:45 ` TeLeMan
2011-08-04 15:10 ` [Qemu-devel] [PATCH 14/16] usb-hid: split hid code to hw/hid.[ch] Gerd Hoffmann
2011-08-04 15:10 ` Gerd Hoffmann [this message]
2011-08-04 15:10 ` [Qemu-devel] [PATCH 16/16] bluetooth: kill dummy usb device, use hid code directly Gerd Hoffmann
2011-08-04 22:42 ` [Qemu-devel] [PULL] usb patch queue: iovecs, hid split, misc fixes Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1312470626-25872-16-git-send-email-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).