git: eead9017d283 - main - hid: Chase for HID function name changes in existing USB HID drivers
Vladimir Kondratyev
wulf at FreeBSD.org
Thu Jan 7 23:20:57 UTC 2021
The branch main has been updated by wulf:
URL: https://cgit.FreeBSD.org/src/commit/?id=eead9017d28366016dece0dbc027c5baefcf2cfe
commit eead9017d28366016dece0dbc027c5baefcf2cfe
Author: Vladimir Kondratyev <wulf at FreeBSD.org>
AuthorDate: 2021-01-01 18:23:01 +0000
Commit: Vladimir Kondratyev <wulf at FreeBSD.org>
CommitDate: 2021-01-07 23:18:42 +0000
hid: Chase for HID function name changes in existing USB HID drivers
Also hide shim code added in a previous commit under COMPAT_USBHID12.
Note: it is enough to add -DCOMPAT_USBHID12 to CFLAGS to compile old
code with new HID subsystem, but it is not enough to link it at runtime.
HID dependency has to be added explicitly with MODULE_DEPEND macro.
Reviewed by: manu, hselasky (as part of D27887)
---
sys/dev/sound/usb/uaudio.c | 4 ++-
sys/dev/usb/input/atp.c | 4 ++-
sys/dev/usb/input/uhid.c | 8 +++---
sys/dev/usb/input/ukbd.c | 14 +++++-----
sys/dev/usb/input/ums.c | 4 ++-
sys/dev/usb/input/wmt.c | 65 +++++++++------------------------------------
sys/dev/usb/input/wsp.c | 5 +++-
sys/dev/usb/misc/ugold.c | 4 ++-
sys/dev/usb/serial/ucycom.c | 8 +++---
sys/dev/usb/usbhid.h | 2 ++
10 files changed, 49 insertions(+), 69 deletions(-)
diff --git a/sys/dev/sound/usb/uaudio.c b/sys/dev/sound/usb/uaudio.c
index 126f0494bac2..c2a7e328b49e 100644
--- a/sys/dev/sound/usb/uaudio.c
+++ b/sys/dev/sound/usb/uaudio.c
@@ -69,6 +69,8 @@ __FBSDID("$FreeBSD$");
#include <sys/malloc.h>
#include <sys/priv.h>
+#include <dev/hid/hid.h>
+
#include "usbdevs.h"
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
@@ -6145,7 +6147,7 @@ uaudio_hid_probe(struct uaudio_softc *sc,
}
/* check if there is an ID byte */
- hid_report_size(d_ptr, d_len, hid_input, &id);
+ hid_report_size_max(d_ptr, d_len, hid_input, &id);
if (id != 0)
sc->sc_hid.flags |= UAUDIO_HID_HAS_ID;
diff --git a/sys/dev/usb/input/atp.c b/sys/dev/usb/input/atp.c
index 7b9b1eb04c9c..3515c08a1a6d 100644
--- a/sys/dev/usb/input/atp.c
+++ b/sys/dev/usb/input/atp.c
@@ -79,6 +79,8 @@ __FBSDID("$FreeBSD$");
#include <sys/selinfo.h>
#include <sys/poll.h>
+#include <dev/hid/hid.h>
+
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
@@ -2204,7 +2206,7 @@ atp_attach(device_t dev)
return (ENXIO);
/* Get HID report descriptor length */
- sc->sc_expected_sensor_data_len = hid_report_size(descriptor_ptr,
+ sc->sc_expected_sensor_data_len = hid_report_size_max(descriptor_ptr,
descriptor_len, hid_input, NULL);
free(descriptor_ptr, M_TEMP);
diff --git a/sys/dev/usb/input/uhid.c b/sys/dev/usb/input/uhid.c
index 97c27608049c..0f87264b7033 100644
--- a/sys/dev/usb/input/uhid.c
+++ b/sys/dev/usb/input/uhid.c
@@ -64,6 +64,8 @@ __FBSDID("$FreeBSD$");
#include <sys/conf.h>
#include <sys/fcntl.h>
+#include <dev/hid/hid.h>
+
#include "usbdevs.h"
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
@@ -828,13 +830,13 @@ uhid_attach(device_t dev)
DPRINTF("set idle failed, error=%s (ignored)\n",
usbd_errstr(error));
}
- sc->sc_isize = hid_report_size
+ sc->sc_isize = hid_report_size_max
(sc->sc_repdesc_ptr, sc->sc_repdesc_size, hid_input, &sc->sc_iid);
- sc->sc_osize = hid_report_size
+ sc->sc_osize = hid_report_size_max
(sc->sc_repdesc_ptr, sc->sc_repdesc_size, hid_output, &sc->sc_oid);
- sc->sc_fsize = hid_report_size
+ sc->sc_fsize = hid_report_size_max
(sc->sc_repdesc_ptr, sc->sc_repdesc_size, hid_feature, &sc->sc_fid);
if (sc->sc_isize > UHID_BSIZE) {
diff --git a/sys/dev/usb/input/ukbd.c b/sys/dev/usb/input/ukbd.c
index 261a4b5aef95..3314a3b3e70f 100644
--- a/sys/dev/usb/input/ukbd.c
+++ b/sys/dev/usb/input/ukbd.c
@@ -62,6 +62,8 @@ __FBSDID("$FreeBSD$");
#include <sys/priv.h>
#include <sys/proc.h>
+#include <dev/hid/hid.h>
+
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
@@ -717,7 +719,7 @@ ukbd_intr_callback(struct usb_xfer *xfer, usb_error_t error)
tmp_loc.count = UKBD_NKEYCODE;
while (tmp_loc.count--) {
uint32_t key =
- hid_get_data_unsigned(sc->sc_buffer, len, &tmp_loc);
+ hid_get_udata(sc->sc_buffer, len, &tmp_loc);
/* advance to next location */
tmp_loc.pos += tmp_loc.size;
if (modifiers & MOD_FN)
@@ -816,7 +818,7 @@ ukbd_set_leds_callback(struct usb_xfer *xfer, usb_error_t error)
if (sc->sc_flags & UKBD_FLAG_NUMLOCK) {
if (sc->sc_leds & NLKED) {
- hid_put_data_unsigned(sc->sc_buffer + 1, UKBD_BUFFER_SIZE - 1,
+ hid_put_udata(sc->sc_buffer + 1, UKBD_BUFFER_SIZE - 1,
&sc->sc_loc_numlock, 1);
}
id = sc->sc_id_numlock;
@@ -825,7 +827,7 @@ ukbd_set_leds_callback(struct usb_xfer *xfer, usb_error_t error)
if (sc->sc_flags & UKBD_FLAG_SCROLLLOCK) {
if (sc->sc_leds & SLKED) {
- hid_put_data_unsigned(sc->sc_buffer + 1, UKBD_BUFFER_SIZE - 1,
+ hid_put_udata(sc->sc_buffer + 1, UKBD_BUFFER_SIZE - 1,
&sc->sc_loc_scrolllock, 1);
}
id = sc->sc_id_scrolllock;
@@ -834,7 +836,7 @@ ukbd_set_leds_callback(struct usb_xfer *xfer, usb_error_t error)
if (sc->sc_flags & UKBD_FLAG_CAPSLOCK) {
if (sc->sc_leds & CLKED) {
- hid_put_data_unsigned(sc->sc_buffer + 1, UKBD_BUFFER_SIZE - 1,
+ hid_put_udata(sc->sc_buffer + 1, UKBD_BUFFER_SIZE - 1,
&sc->sc_loc_capslock, 1);
}
id = sc->sc_id_capslock;
@@ -983,7 +985,7 @@ ukbd_parse_hid(struct ukbd_softc *sc, const uint8_t *ptr, uint32_t len)
memset(sc->sc_loc_key_valid, 0, sizeof(sc->sc_loc_key_valid));
/* check if there is an ID byte */
- sc->sc_kbd_size = hid_report_size(ptr, len,
+ sc->sc_kbd_size = hid_report_size_max(ptr, len,
hid_input, &sc->sc_kbd_id);
/* investigate if this is an Apple Keyboard */
@@ -1033,7 +1035,7 @@ ukbd_parse_hid(struct ukbd_softc *sc, const uint8_t *ptr, uint32_t len)
}
/* figure out leds on keyboard */
- sc->sc_led_size = hid_report_size(ptr, len,
+ sc->sc_led_size = hid_report_size_max(ptr, len,
hid_output, NULL);
if (hid_locate(ptr, len,
diff --git a/sys/dev/usb/input/ums.c b/sys/dev/usb/input/ums.c
index 038ed8121df1..6b7c3d526ad0 100644
--- a/sys/dev/usb/input/ums.c
+++ b/sys/dev/usb/input/ums.c
@@ -61,6 +61,8 @@ __FBSDID("$FreeBSD$");
#include <sys/fcntl.h>
#include <sys/sbuf.h>
+#include <dev/hid/hid.h>
+
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
@@ -614,7 +616,7 @@ ums_attach(device_t dev)
goto detach;
}
- isize = hid_report_size(d_ptr, d_len, hid_input, &sc->sc_iid);
+ isize = hid_report_size_max(d_ptr, d_len, hid_input, &sc->sc_iid);
/*
* The Microsoft Wireless Notebook Optical Mouse seems to be in worse
diff --git a/sys/dev/usb/input/wmt.c b/sys/dev/usb/input/wmt.c
index 056c2c3cb0cc..8191c6ff9369 100644
--- a/sys/dev/usb/input/wmt.c
+++ b/sys/dev/usb/input/wmt.c
@@ -45,6 +45,8 @@ __FBSDID("$FreeBSD$");
#include <sys/sysctl.h>
#include <sys/systm.h>
+#include <dev/hid/hid.h>
+
#include "usbdevs.h"
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
@@ -352,7 +354,7 @@ wmt_attach(device_t dev)
sc->cont_max_rlen, uaa->info.bIfaceIndex,
UHID_FEATURE_REPORT, sc->cont_max_rid);
if (err == USB_ERR_NORMAL_COMPLETION) {
- cont_count_max = hid_get_data_unsigned(sc->buf + 1,
+ cont_count_max = hid_get_udata(sc->buf + 1,
sc->cont_max_rlen - 1, &sc->cont_max_loc);
/*
* Feature report is a primary source of
@@ -377,7 +379,7 @@ wmt_attach(device_t dev)
}
if (sc->btn_type_rlen > 1) {
if (err == 0)
- sc->is_clickpad = hid_get_data_unsigned(sc->buf + 1,
+ sc->is_clickpad = hid_get_udata(sc->buf + 1,
sc->btn_type_rlen - 1, &sc->btn_type_loc) == 0;
else
DPRINTF("usbd_req_get_report error=%d\n", err);
@@ -522,7 +524,7 @@ wmt_process_report(struct wmt_softc *sc, uint8_t *buf, int len)
* report with contactid=0 but contactids are zero-based, find
* contactcount first.
*/
- cont_count = hid_get_data_unsigned(buf, len, &sc->cont_count_loc);
+ cont_count = hid_get_udata(buf, len, &sc->cont_count_loc);
/*
* "In Hybrid mode, the number of contacts that can be reported in one
* report is less than the maximum number of contacts that the device
@@ -559,7 +561,7 @@ wmt_process_report(struct wmt_softc *sc, uint8_t *buf, int len)
bzero(slot_data, sizeof(sc->slot_data));
WMT_FOREACH_USAGE(sc->caps, usage) {
if (sc->locs[cont][usage].size > 0)
- slot_data[usage] = hid_get_data_unsigned(
+ slot_data[usage] = hid_get_udata(
buf, len, &sc->locs[cont][usage]);
}
@@ -611,8 +613,7 @@ wmt_process_report(struct wmt_softc *sc, uint8_t *buf, int len)
sc->nconts_todo -= cont_count;
if (sc->do_timestamps && sc->nconts_todo == 0) {
/* HUD_SCAN_TIME is measured in 100us, convert to us. */
- scan_time =
- hid_get_data_unsigned(buf, len, &sc->scan_time_loc);
+ scan_time = hid_get_udata(buf, len, &sc->scan_time_loc);
if (sc->prev_touch) {
delta = scan_time - sc->scan_time;
if (delta < 0)
@@ -747,46 +748,6 @@ wmt_ev_open(struct evdev_dev *evdev)
}
#endif
-/* port of userland hid_report_size() from usbhid(3) to kernel */
-static int
-wmt_hid_report_size(const void *buf, uint16_t len, enum hid_kind k, uint8_t id)
-{
- struct hid_data *d;
- struct hid_item h;
- uint32_t temp;
- uint32_t hpos;
- uint32_t lpos;
- int report_id = 0;
-
- hpos = 0;
- lpos = 0xFFFFFFFF;
-
- for (d = hid_start_parse(buf, len, 1 << k); hid_get_item(d, &h);) {
- if (h.kind == k && h.report_ID == id) {
- /* compute minimum */
- if (lpos > h.loc.pos)
- lpos = h.loc.pos;
- /* compute end position */
- temp = h.loc.pos + (h.loc.size * h.loc.count);
- /* compute maximum */
- if (hpos < temp)
- hpos = temp;
- if (h.report_ID != 0)
- report_id = 1;
- }
- }
- hid_end_parse(d);
-
- /* safety check - can happen in case of currupt descriptors */
- if (lpos > hpos)
- temp = 0;
- else
- temp = hpos - lpos;
-
- /* return length in bytes rounded up */
- return ((temp + 7) / 8 + report_id);
-}
-
static enum wmt_type
wmt_hid_parse(struct wmt_softc *sc, const void *d_ptr, uint16_t d_len)
{
@@ -1000,16 +961,16 @@ wmt_hid_parse(struct wmt_softc *sc, const void *d_ptr, uint16_t d_len)
sc->ai[WMT_ORIENTATION].max = 1;
}
- sc->isize = hid_report_size(d_ptr, d_len, hid_input, NULL);
- sc->report_len = wmt_hid_report_size(d_ptr, d_len, hid_input,
+ sc->isize = hid_report_size_max(d_ptr, d_len, hid_input, NULL);
+ sc->report_len = hid_report_size(d_ptr, d_len, hid_input,
report_id);
- sc->cont_max_rlen = wmt_hid_report_size(d_ptr, d_len, hid_feature,
+ sc->cont_max_rlen = hid_report_size(d_ptr, d_len, hid_feature,
sc->cont_max_rid);
if (sc->btn_type_rid > 0)
- sc->btn_type_rlen = wmt_hid_report_size(d_ptr, d_len,
+ sc->btn_type_rlen = hid_report_size(d_ptr, d_len,
hid_feature, sc->btn_type_rid);
if (sc->thqa_cert_rid > 0)
- sc->thqa_cert_rlen = wmt_hid_report_size(d_ptr, d_len,
+ sc->thqa_cert_rlen = hid_report_size(d_ptr, d_len,
hid_feature, sc->thqa_cert_rid);
sc->report_id = report_id;
@@ -1039,7 +1000,7 @@ wmt_set_input_mode(struct wmt_softc *sc, enum wmt_input_mode mode)
bzero(sc->buf + 1, sc->input_mode_rlen - 1);
sc->buf[0] = sc->input_mode_rid;
- hid_put_data_unsigned(sc->buf + 1, sc->input_mode_rlen - 1,
+ hid_put_udata(sc->buf + 1, sc->input_mode_rlen - 1,
&sc->input_mode_loc, mode);
err = usbd_req_set_report(uaa->device, NULL, sc->buf,
sc->input_mode_rlen, uaa->info.bIfaceIndex,
diff --git a/sys/dev/usb/input/wsp.c b/sys/dev/usb/input/wsp.c
index 29eaa34cdfdc..a25539e7b939 100644
--- a/sys/dev/usb/input/wsp.c
+++ b/sys/dev/usb/input/wsp.c
@@ -44,6 +44,8 @@ __FBSDID("$FreeBSD$");
#include <sys/poll.h>
#include <sys/sysctl.h>
+#include <dev/hid/hid.h>
+
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
@@ -733,7 +735,8 @@ wsp_attach(device_t dev)
if (err == USB_ERR_NORMAL_COMPLETION) {
/* Get HID report descriptor length */
- sc->tp_datalen = hid_report_size(d_ptr, d_len, hid_input, NULL);
+ sc->tp_datalen = hid_report_size_max(d_ptr, d_len, hid_input,
+ NULL);
free(d_ptr, M_TEMP);
if (sc->tp_datalen <= 0 || sc->tp_datalen > WSP_BUFFER_MAX) {
diff --git a/sys/dev/usb/misc/ugold.c b/sys/dev/usb/misc/ugold.c
index f09bd629af28..b5fb9591857f 100644
--- a/sys/dev/usb/misc/ugold.c
+++ b/sys/dev/usb/misc/ugold.c
@@ -42,6 +42,8 @@ __FBSDID("$FreeBSD$");
#include <sys/priv.h>
#include <sys/conf.h>
+#include <dev/hid/hid.h>
+
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbhid.h>
@@ -227,7 +229,7 @@ ugold_attach(device_t dev)
if (error)
goto detach;
- (void)hid_report_size(d_ptr, d_len, hid_input, &sc->sc_report_id);
+ (void)hid_report_size_max(d_ptr, d_len, hid_input, &sc->sc_report_id);
free(d_ptr, M_TEMP);
diff --git a/sys/dev/usb/serial/ucycom.c b/sys/dev/usb/serial/ucycom.c
index 7870d9c88227..06ef6480f27c 100644
--- a/sys/dev/usb/serial/ucycom.c
+++ b/sys/dev/usb/serial/ucycom.c
@@ -55,6 +55,8 @@ __FBSDID("$FreeBSD$");
#include <sys/malloc.h>
#include <sys/priv.h>
+#include <dev/hid/hid.h>
+
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
@@ -249,9 +251,9 @@ ucycom_attach(device_t dev)
}
/* get report sizes */
- sc->sc_flen = hid_report_size(urd_ptr, urd_len, hid_feature, &sc->sc_fid);
- sc->sc_ilen = hid_report_size(urd_ptr, urd_len, hid_input, &sc->sc_iid);
- sc->sc_olen = hid_report_size(urd_ptr, urd_len, hid_output, &sc->sc_oid);
+ sc->sc_flen = hid_report_size_max(urd_ptr, urd_len, hid_feature, &sc->sc_fid);
+ sc->sc_ilen = hid_report_size_max(urd_ptr, urd_len, hid_input, &sc->sc_iid);
+ sc->sc_olen = hid_report_size_max(urd_ptr, urd_len, hid_output, &sc->sc_oid);
if ((sc->sc_ilen > UCYCOM_MAX_IOLEN) || (sc->sc_ilen < 1) ||
(sc->sc_olen > UCYCOM_MAX_IOLEN) || (sc->sc_olen < 2) ||
diff --git a/sys/dev/usb/usbhid.h b/sys/dev/usb/usbhid.h
index 9e87e8226abf..9ceb3d147af2 100644
--- a/sys/dev/usb/usbhid.h
+++ b/sys/dev/usb/usbhid.h
@@ -70,6 +70,7 @@ struct usb_hid_descriptor {
#if defined(_KERNEL) || defined(_STANDALONE)
struct usb_config_descriptor;
+#ifdef COMPAT_USBHID12
/* FreeBSD <= 12 compat shims */
#define hid_report_size(buf, len, kind, id) \
hid_report_size_max(buf, len, kind, id)
@@ -85,6 +86,7 @@ hid_put_data_unsigned(uint8_t *buf, hid_size_t len, struct hid_location *loc,
{
return (hid_put_udata(buf, len, loc, value));
}
+#endif
struct usb_hid_descriptor *hid_get_descriptor_from_usb(
struct usb_config_descriptor *cd,
More information about the dev-commits-src-main
mailing list