Hi,
Instead of letting uhidev drivers get the report sizes, do it once in
uhidev and pass the same sizes as part of the attach arguments. Makes
the uhidev drivers a bit less repetitive. Note that each call to
uhidev_get_report_size() requires one malloc() and a full traversal of
the HID report. Not that this change will cause any noticeable
difference in terms of time but we can at least avoid doing the same
operation over and over.
It might look tempting to let uhidev assign the sizes after a driver has
attached, removing the need to repeat this logic in each driver. This
does however not work since the input size (sc_isize) must be known
while calling uhidev_open() in order to open the interrupt pipe; and
uhidev_open() is called from several attach routines.
Note that this change only works and applies to when attaching to a
single report ID.
While here, get rid of the unused repsize array.
Comments? OK?
Index: dev/usb/ucc.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/ucc.c,v
retrieving revision 1.24
diff -u -p -r1.24 ucc.c
--- dev/usb/ucc.c 2 Sep 2021 15:15:12 -0000 1.24
+++ dev/usb/ucc.c 9 Sep 2021 05:26:35 -0000
@@ -633,9 +633,9 @@ ucc_match(struct device *parent, void *m
void *desc;
int size;
- uhidev_get_report_desc(uha->parent, &desc, &size);
- if (hid_report_size(desc, size, hid_input, uha->reportid) == 0)
+ if (uha->isize == 0)
return UMATCH_NONE;
+ uhidev_get_report_desc(uha->parent, &desc, &size);
if (!ucc_hid_match(desc, size, uha->reportid))
return UMATCH_NONE;
@@ -648,7 +648,7 @@ ucc_attach(struct device *parent, struct
struct ucc_softc *sc = (struct ucc_softc *)self;
struct uhidev_attach_arg *uha = (struct uhidev_attach_arg *)aux;
void *desc;
- int error, repid, size;
+ int error, size;
sc->sc_mode = WSKBD_TRANSLATED;
sc->sc_last_translate = -1;
@@ -659,10 +659,9 @@ ucc_attach(struct device *parent, struct
sc->sc_hdev.sc_report_id = uha->reportid;
uhidev_get_report_desc(uha->parent, &desc, &size);
- repid = uha->reportid;
- sc->sc_hdev.sc_isize = hid_report_size(desc, size, hid_input, repid);
- sc->sc_hdev.sc_osize = hid_report_size(desc, size, hid_output, repid);
- sc->sc_hdev.sc_fsize = hid_report_size(desc, size, hid_feature, repid);
+ sc->sc_hdev.sc_isize = uha->isize;
+ sc->sc_hdev.sc_osize = uha->osize;
+ sc->sc_hdev.sc_fsize = uha->fsize;
error = ucc_hid_parse(sc, desc, size);
if (error) {
Index: dev/usb/ugold.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/ugold.c,v
retrieving revision 1.17
diff -u -p -r1.17 ugold.c
--- dev/usb/ugold.c 5 Apr 2021 16:26:06 -0000 1.17
+++ dev/usb/ugold.c 9 Sep 2021 05:26:35 -0000
@@ -139,7 +139,7 @@ ugold_attach(struct device *parent, stru
{
struct ugold_softc *sc = (struct ugold_softc *)self;
struct uhidev_attach_arg *uha = aux;
- int size, repid;
+ int size;
void *desc;
sc->sc_udev = uha->parent->sc_udev;
@@ -159,10 +159,9 @@ ugold_attach(struct device *parent, stru
}
uhidev_get_report_desc(uha->parent, &desc, &size);
- repid = uha->reportid;
- sc->sc_hdev.sc_isize = hid_report_size(desc, size, hid_input, repid);
- sc->sc_hdev.sc_osize = hid_report_size(desc, size, hid_output, repid);
- sc->sc_hdev.sc_fsize = hid_report_size(desc, size, hid_feature, repid);
+ sc->sc_hdev.sc_isize = uha->isize;
+ sc->sc_hdev.sc_osize = uha->osize;
+ sc->sc_hdev.sc_fsize = uha->fsize;
if (uhidev_open(&sc->sc_hdev)) {
printf(", unable to open interrupt pipe\n");
Index: dev/usb/uhid.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/uhid.c,v
retrieving revision 1.84
diff -u -p -r1.84 uhid.c
--- dev/usb/uhid.c 8 Mar 2021 14:35:57 -0000 1.84
+++ dev/usb/uhid.c 9 Sep 2021 05:26:35 -0000
@@ -126,7 +126,7 @@ uhid_attach(struct device *parent, struc
{
struct uhid_softc *sc = (struct uhid_softc *)self;
struct uhidev_attach_arg *uha = (struct uhidev_attach_arg *)aux;
- int size, repid;
+ int size;
void *desc;
sc->sc_hdev.sc_intr = uhid_intr;
@@ -135,10 +135,9 @@ uhid_attach(struct device *parent, struc
sc->sc_hdev.sc_report_id = uha->reportid;
uhidev_get_report_desc(uha->parent, &desc, &size);
- repid = uha->reportid;
- sc->sc_hdev.sc_isize = hid_report_size(desc, size, hid_input, repid);
- sc->sc_hdev.sc_osize = hid_report_size(desc, size, hid_output, repid);
- sc->sc_hdev.sc_fsize = hid_report_size(desc, size, hid_feature, repid);
+ sc->sc_hdev.sc_isize = uha->isize;
+ sc->sc_hdev.sc_osize = uha->osize;
+ sc->sc_hdev.sc_fsize = uha->fsize;
printf(": input=%d, output=%d, feature=%d\n",
sc->sc_hdev.sc_isize, sc->sc_hdev.sc_osize, sc->sc_hdev.sc_fsize);
Index: dev/usb/uhidev.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/uhidev.c,v
retrieving revision 1.92
diff -u -p -r1.92 uhidev.c
--- dev/usb/uhidev.c 18 Mar 2021 09:21:53 -0000 1.92
+++ dev/usb/uhidev.c 9 Sep 2021 05:26:35 -0000
@@ -142,7 +142,7 @@ uhidev_attach(struct device *parent, str
usb_endpoint_descriptor_t *ed;
struct uhidev_attach_arg uha;
int size, nrepid, repid, repsz;
- int i, repsizes[256];
+ int i;
void *desc = NULL;
struct device *dev;
@@ -241,7 +241,6 @@ uhidev_attach(struct device *parent, str
for (repid = 0; repid < nrepid; repid++) {
repsz = hid_report_size(desc, size, hid_input, repid);
DPRINTF(("uhidev_match: repid=%d, repsz=%d\n", repid, repsz));
- repsizes[repid] = repsz;
if (repsz > sc->sc_isize)
sc->sc_isize = repsz;
}
@@ -253,6 +252,7 @@ uhidev_attach(struct device *parent, str
uha.reportid = UHIDEV_CLAIM_MULTIPLE_REPORTID;
uha.nreports = nrepid;
uha.claimed = malloc(nrepid, M_TEMP, M_WAITOK|M_ZERO);
+ uha.isize = uha.osize = uha.fsize =0;
/* Look for a driver claiming multiple report IDs first. */
dev = config_found_sm(self, &uha, NULL, uhidevsubmatch);
@@ -273,10 +273,12 @@ uhidev_attach(struct device *parent, str
uha.claimed = NULL;
for (repid = 0; repid < nrepid; repid++) {
+ int isize, osize, fsize;
+
DPRINTF(("%s: try repid=%d\n", __func__, repid));
- if (hid_report_size(desc, size, hid_input, repid) == 0 &&
- hid_report_size(desc, size, hid_output, repid) == 0 &&
- hid_report_size(desc, size, hid_feature, repid) == 0)
+ if ((isize = hid_report_size(desc, size, hid_input, repid)) ==
0 &&
+ (osize = hid_report_size(desc, size, hid_output, repid)) ==
0 &&
+ (fsize = hid_report_size(desc, size, hid_feature, repid))
== 0)
continue;
/* Could already be assigned by uhidev_set_report_dev(). */
@@ -284,6 +286,9 @@ uhidev_attach(struct device *parent, str
continue;
uha.reportid = repid;
+ uha.isize = isize;
+ uha.osize = osize;
+ uha.fsize = fsize;
dev = config_found_sm(self, &uha, uhidevprint, uhidevsubmatch);
sc->sc_subdevs[repid] = (struct uhidev *)dev;
}
Index: dev/usb/uhidev.h
===================================================================
RCS file: /cvs/src/sys/dev/usb/uhidev.h,v
retrieving revision 1.29
diff -u -p -r1.29 uhidev.h
--- dev/usb/uhidev.h 18 Mar 2021 09:21:53 -0000 1.29
+++ dev/usb/uhidev.h 9 Sep 2021 05:26:35 -0000
@@ -84,6 +84,9 @@ struct uhidev_attach_arg {
#define UHIDEV_CLAIM_MULTIPLE_REPORTID 255
uint8_t nreports;
uint8_t *claimed;
+ int isize;
+ int osize;
+ int fsize;
};
int uhidev_report_type_conv(int);
Index: dev/usb/ukbd.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/ukbd.c,v
retrieving revision 1.82
diff -u -p -r1.82 ukbd.c
--- dev/usb/ukbd.c 29 Jan 2021 16:59:41 -0000 1.82
+++ dev/usb/ukbd.c 9 Sep 2021 05:26:35 -0000
@@ -231,9 +231,9 @@ ukbd_attach(struct device *parent, struc
uhidev_get_report_desc(uha->parent, &desc, &dlen);
repid = uha->reportid;
- sc->sc_hdev.sc_isize = hid_report_size(desc, dlen, hid_input, repid);
- sc->sc_hdev.sc_osize = hid_report_size(desc, dlen, hid_output, repid);
- sc->sc_hdev.sc_fsize = hid_report_size(desc, dlen, hid_feature, repid);
+ sc->sc_hdev.sc_isize = uha->isize;
+ sc->sc_hdev.sc_osize = uha->osize;
+ sc->sc_hdev.sc_fsize = uha->fsize;
/*
* Since the HID-Proxy is always detected before any
Index: dev/usb/ums.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/ums.c,v
retrieving revision 1.48
diff -u -p -r1.48 ums.c
--- dev/usb/ums.c 24 Mar 2021 02:49:57 -0000 1.48
+++ dev/usb/ums.c 9 Sep 2021 05:26:35 -0000
@@ -121,7 +121,7 @@ ums_attach(struct device *parent, struct
struct hidms *ms = &sc->sc_ms;
struct uhidev_attach_arg *uha = (struct uhidev_attach_arg *)aux;
struct usb_attach_arg *uaa = uha->uaa;
- int size, repid;
+ int size;
void *desc;
u_int32_t qflags = 0;
@@ -138,10 +138,9 @@ ums_attach(struct device *parent, struct
if (uaa->vendor == USB_VENDOR_ELECOM)
ums_fix_elecom_descriptor(sc, desc, size, uaa->product);
- repid = uha->reportid;
- sc->sc_hdev.sc_isize = hid_report_size(desc, size, hid_input, repid);
- sc->sc_hdev.sc_osize = hid_report_size(desc, size, hid_output, repid);
- sc->sc_hdev.sc_fsize = hid_report_size(desc, size, hid_feature, repid);
+ sc->sc_hdev.sc_isize = uha->isize;
+ sc->sc_hdev.sc_osize = uha->osize;
+ sc->sc_hdev.sc_fsize = uha->fsize;
if (sc->sc_quirks & UQ_MS_REVZ)
qflags |= HIDMS_REVZ;
Index: dev/usb/umstc.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/umstc.c,v
retrieving revision 1.4
diff -u -p -r1.4 umstc.c
--- dev/usb/umstc.c 8 Mar 2021 14:39:34 -0000 1.4
+++ dev/usb/umstc.c 9 Sep 2021 05:26:35 -0000
@@ -98,7 +98,7 @@ umstc_attach(struct device *parent, stru
struct umstc_softc *sc = (struct umstc_softc *)self;
struct uhidev_attach_arg *uha = (struct uhidev_attach_arg *)aux;
struct usb_attach_arg *uaa = uha->uaa;
- int size, repid;
+ int size;
void *desc;
sc->sc_hdev.sc_intr = umstc_intr;
@@ -109,10 +109,9 @@ umstc_attach(struct device *parent, stru
usbd_set_idle(uha->parent->sc_udev, uha->parent->sc_ifaceno, 0, 0);
uhidev_get_report_desc(uha->parent, &desc, &size);
- repid = uha->reportid;
- sc->sc_hdev.sc_isize = hid_report_size(desc, size, hid_input, repid);
- sc->sc_hdev.sc_osize = hid_report_size(desc, size, hid_output, repid);
- sc->sc_hdev.sc_fsize = hid_report_size(desc, size, hid_feature, repid);
+ sc->sc_hdev.sc_isize = uha->isize;
+ sc->sc_hdev.sc_osize = uha->osize;
+ sc->sc_hdev.sc_fsize = uha->fsize;
uhidev_open(&sc->sc_hdev);
Index: dev/usb/uwacom.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/uwacom.c,v
retrieving revision 1.2
diff -u -p -r1.2 uwacom.c
--- dev/usb/uwacom.c 23 Aug 2020 11:08:02 -0000 1.2
+++ dev/usb/uwacom.c 9 Sep 2021 05:26:35 -0000
@@ -95,7 +95,7 @@ uwacom_attach(struct device *parent, str
struct hidms *ms = &sc->sc_ms;
struct uhidev_attach_arg *uha = (struct uhidev_attach_arg *)aux;
struct usb_attach_arg *uaa = uha->uaa;
- int size, repid;
+ int size;
void *desc;
sc->sc_hdev.sc_intr = uwacom_intr;
@@ -106,10 +106,9 @@ uwacom_attach(struct device *parent, str
usbd_set_idle(uha->parent->sc_udev, uha->parent->sc_ifaceno, 0, 0);
uhidev_get_report_desc(uha->parent, &desc, &size);
- repid = uha->reportid;
- sc->sc_hdev.sc_isize = hid_report_size(desc, size, hid_input, repid);
- sc->sc_hdev.sc_osize = hid_report_size(desc, size, hid_output, repid);
- sc->sc_hdev.sc_fsize = hid_report_size(desc, size, hid_feature, repid);
+ sc->sc_hdev.sc_isize = uha->isize;
+ sc->sc_hdev.sc_osize = uha->osize;
+ sc->sc_hdev.sc_fsize = uha->fsize;
ms->sc_device = self;
ms->sc_rawmode = 1;