From owner-svn-src-all@FreeBSD.ORG Thu May 20 00:05:33 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C3C8D1065674; Thu, 20 May 2010 00:05:33 +0000 (UTC) (envelope-from thompsa@FreeBSD.org) Received: from svn.freebsd.org (unknown [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A81448FC08; Thu, 20 May 2010 00:05:33 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o4K05XTc028541; Thu, 20 May 2010 00:05:33 GMT (envelope-from thompsa@svn.freebsd.org) Received: (from thompsa@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o4K05XqB028538; Thu, 20 May 2010 00:05:33 GMT (envelope-from thompsa@svn.freebsd.org) Message-Id: <201005200005.o4K05XqB028538@svn.freebsd.org> From: Andrew Thompson Date: Thu, 20 May 2010 00:05:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r208321 - stable/8/sys/dev/usb X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 May 2010 00:05:34 -0000 Author: thompsa Date: Thu May 20 00:05:33 2010 New Revision: 208321 URL: http://svn.freebsd.org/changeset/base/208321 Log: MFC r208012 Support getting signed and unsigned HID data. Submitted by: Alex Deiter Modified: stable/8/sys/dev/usb/usb_hid.c stable/8/sys/dev/usb/usbhid.h Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) stable/8/sys/geom/sched/ (props changed) Modified: stable/8/sys/dev/usb/usb_hid.c ============================================================================== --- stable/8/sys/dev/usb/usb_hid.c Wed May 19 23:56:26 2010 (r208320) +++ stable/8/sys/dev/usb/usb_hid.c Thu May 20 00:05:33 2010 (r208321) @@ -653,8 +653,9 @@ hid_locate(const void *desc, usb_size_t /*------------------------------------------------------------------------* * hid_get_data *------------------------------------------------------------------------*/ -uint32_t -hid_get_data(const uint8_t *buf, usb_size_t len, struct hid_location *loc) +static uint32_t +hid_get_data_sub(const uint8_t *buf, usb_size_t len, struct hid_location *loc, + int is_signed) { uint32_t hpos = loc->pos; uint32_t hsize = loc->size; @@ -683,16 +684,31 @@ hid_get_data(const uint8_t *buf, usb_siz /* Correctly shift down data */ data = (data >> (hpos % 8)); + n = 32 - hsize; /* Mask and sign extend in one */ - n = 32 - hsize; - data = ((int32_t)data << n) >> n; + if (is_signed != 0) + data = (int32_t)((int32_t)data << n) >> n; + else + data = (uint32_t)((uint32_t)data << n) >> n; DPRINTFN(11, "hid_get_data: loc %d/%d = %lu\n", loc->pos, loc->size, (long)data); return (data); } +int32_t +hid_get_data(const uint8_t *buf, usb_size_t len, struct hid_location *loc) +{ + return (hid_get_data_sub(buf, len, loc, 1)); +} + +uint32_t +hid_get_data_unsigned(const uint8_t *buf, usb_size_t len, struct hid_location *loc) +{ + return (hid_get_data_sub(buf, len, loc, 0)); +} + /*------------------------------------------------------------------------* * hid_is_collection *------------------------------------------------------------------------*/ Modified: stable/8/sys/dev/usb/usbhid.h ============================================================================== --- stable/8/sys/dev/usb/usbhid.h Wed May 19 23:56:26 2010 (r208320) +++ stable/8/sys/dev/usb/usbhid.h Thu May 20 00:05:33 2010 (r208321) @@ -229,7 +229,9 @@ int hid_report_size(const void *buf, usb int hid_locate(const void *desc, usb_size_t size, uint32_t usage, enum hid_kind kind, uint8_t index, struct hid_location *loc, uint32_t *flags, uint8_t *id); -uint32_t hid_get_data(const uint8_t *buf, usb_size_t len, +int32_t hid_get_data(const uint8_t *buf, usb_size_t len, + struct hid_location *loc); +uint32_t hid_get_data_unsigned(const uint8_t *buf, usb_size_t len, struct hid_location *loc); int hid_is_collection(const void *desc, usb_size_t size, uint32_t usage); struct usb_hid_descriptor *hid_get_descriptor_from_usb(