Lines Matching +full:kind +full:- +full:of +full:- +full:intr
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2019-2020 Vladimir Kondratyev <wulf@FreeBSD.org>
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * notice, this list of conditions and the following disclaimer in the
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 struct mtx *mtx; /* child intr mtx */
83 int nauto; /* Number of autochildren */
94 hri->data = __DECONST(void *, data); in hidbus_fill_rdesc_info()
95 hri->len = len; in hidbus_fill_rdesc_info()
101 hri->isize = len == 0 ? HID_RSIZE_MAX : in hidbus_fill_rdesc_info()
102 hid_report_size_max(data, len, hid_input, &hri->iid); in hidbus_fill_rdesc_info()
103 hri->osize = len == 0 ? HID_RSIZE_MAX : in hidbus_fill_rdesc_info()
104 hid_report_size_max(data, len, hid_output, &hri->oid); in hidbus_fill_rdesc_info()
105 hri->fsize = len == 0 ? HID_RSIZE_MAX : in hidbus_fill_rdesc_info()
106 hid_report_size_max(data, len, hid_feature, &hri->fid); in hidbus_fill_rdesc_info()
108 if (hri->isize > HID_RSIZE_MAX) { in hidbus_fill_rdesc_info()
110 hri->isize); in hidbus_fill_rdesc_info()
111 hri->isize = HID_RSIZE_MAX; in hidbus_fill_rdesc_info()
114 if (hri->osize > HID_RSIZE_MAX) { in hidbus_fill_rdesc_info()
116 hri->osize); in hidbus_fill_rdesc_info()
117 hri->osize = HID_RSIZE_MAX; in hidbus_fill_rdesc_info()
120 if (hri->fsize > HID_RSIZE_MAX) { in hidbus_fill_rdesc_info()
122 hri->fsize); in hidbus_fill_rdesc_info()
123 hri->fsize = HID_RSIZE_MAX; in hidbus_fill_rdesc_info()
142 if (h.kind == k && h.usages[i] == u) { in hidbus_locate()
143 if (index--) in hidbus_locate()
163 loc->size = 0; in hidbus_locate()
182 if (h.kind == hid_collection && h.usage == usage) { in hidbus_is_collection()
203 tlc->mtx = &sc->mtx; in hidbus_add_child()
205 sx_xlock(&sc->sx); in hidbus_add_child()
206 CK_STAILQ_INSERT_TAIL(&sc->tlcs, tlc, link); in hidbus_add_child()
207 sx_unlock(&sc->sx); in hidbus_add_child()
227 if (hi.kind != hid_collection || hi.collevel != 1) in hidbus_enumerate_children()
246 sc->nauto = index; in hidbus_enumerate_children()
258 &sc->rdesc); in hidbus_attach_children()
260 error = hidbus_enumerate_children(dev, sc->rdesc.data, sc->rdesc.len); in hidbus_attach_children()
265 * hidbus_attach_children() can recurse through device_identify-> in hidbus_attach_children()
269 sc->nest++; in hidbus_attach_children()
271 sc->nest--; in hidbus_attach_children()
272 if (sc->nest != 0) in hidbus_attach_children()
275 if (hid_is_keyboard(sc->rdesc.data, sc->rdesc.len) != 0) in hidbus_attach_children()
309 while (i-- > 0) { in hidbus_detach_children()
349 sc->dev = dev; in hidbus_attach()
350 CK_STAILQ_INIT(&sc->tlcs); in hidbus_attach()
351 mtx_init(&sc->mtx, "hidbus ivar lock", NULL, MTX_DEF); in hidbus_attach()
352 sx_init(&sc->sx, "hidbus ivar list lock"); in hidbus_attach()
355 * Ignore error. It is possible for non-HID device e.g. XBox360 gamepad in hidbus_attach()
356 * to emulate HID through overloading of report descriptor. in hidbus_attach()
358 d_len = devinfo->rdescsize; in hidbus_attach()
369 hidbus_fill_rdesc_info(&sc->rdesc, d_ptr, d_len); in hidbus_attach()
371 sc->nowrite = hid_test_quirk(devinfo, HQ_NOWRITE); in hidbus_attach()
388 sx_destroy(&sc->sx); in hidbus_detach()
389 mtx_destroy(&sc->mtx); in hidbus_detach()
390 free(sc->rdesc.data, M_DEVBUF); in hidbus_detach()
401 KASSERT(!tlc->active, ("Child device is running")); in hidbus_child_detached()
402 tlc->mtx = &sc->mtx; in hidbus_child_detached()
403 tlc->intr_handler = NULL; in hidbus_child_detached()
404 tlc->flags &= ~HIDBUS_FLAG_CAN_POLL; in hidbus_child_detached()
425 sx_xlock(&sc->sx); in hidbus_child_deleted()
426 KASSERT(!tlc->active, ("Child device is running")); in hidbus_child_deleted()
427 CK_STAILQ_REMOVE(&sc->tlcs, tlc, hidbus_ivars, link); in hidbus_child_deleted()
428 sx_unlock(&sc->sx); in hidbus_child_deleted()
429 epoch_call(INPUT_EPOCH, hidbus_ivar_dtor, &tlc->epoch_ctx); in hidbus_child_deleted()
440 *result = tlc->index; in hidbus_read_ivar()
443 *result = tlc->usage; in hidbus_read_ivar()
446 *result = tlc->flags; in hidbus_read_ivar()
449 *result = tlc->driver_info; in hidbus_read_ivar()
452 *result = (uintptr_t)(tlc->mtx == &sc->mtx ? NULL : tlc->mtx); in hidbus_read_ivar()
468 tlc->index = value; in hidbus_write_ivar()
471 tlc->usage = value; in hidbus_write_ivar()
474 tlc->flags = value; in hidbus_write_ivar()
480 tlc->driver_info = value; in hidbus_write_ivar()
483 tlc->mtx = (struct mtx *)value == NULL ? in hidbus_write_ivar()
484 &sc->mtx : (struct mtx *)value; in hidbus_write_ivar()
498 sbuf_printf(sb, "index=%hhu", tlc->index); in hidbus_child_location()
511 HID_GET_USAGE_PAGE(tlc->usage), HID_GET_USAGE(tlc->usage), in hidbus_child_pnpinfo()
512 devinfo->idBus, devinfo->idVendor, devinfo->idProduct, in hidbus_child_pnpinfo()
513 devinfo->idVersion, devinfo->idPnP[0] == '\0' ? "" : " _HID=", in hidbus_child_pnpinfo()
514 devinfo->idPnP[0] == '\0' ? "" : devinfo->idPnP); in hidbus_child_pnpinfo()
527 if (suffix != NULL && strcasestr(devinfo->name, suffix) == NULL && in hidbus_set_desc()
528 (sc->nauto > 1 || (tlc->flags & HIDBUS_FLAG_AUTOCHILD) == 0)) in hidbus_set_desc()
529 device_set_descf(child, "%s %s", devinfo->name, suffix); in hidbus_set_desc()
531 device_set_desc(child, devinfo->name); in hidbus_set_desc()
542 /* Get a list of all hidbus children */ in hidbus_find_child()
574 CK_STAILQ_FOREACH(tlc, &sc->tlcs, link) { in hidbus_intr()
575 if (!tlc->active || tlc->intr_handler == NULL) in hidbus_intr()
578 if ((tlc->flags & HIDBUS_FLAG_CAN_POLL) != 0) in hidbus_intr()
579 tlc->intr_handler(tlc->intr_ctx, buf, len); in hidbus_intr()
581 mtx_lock(tlc->mtx); in hidbus_intr()
582 tlc->intr_handler(tlc->intr_ctx, buf, len); in hidbus_intr()
583 mtx_unlock(tlc->mtx); in hidbus_intr()
595 tlc->intr_handler = handler; in hidbus_set_intr()
596 tlc->intr_ctx = context; in hidbus_set_intr()
607 if (sx_xlock_sig(&sc->sx) != 0) in hidbus_intr_start()
609 mtx_lock(ivar->mtx); in hidbus_intr_start()
610 ivar->active = true; in hidbus_intr_start()
611 mtx_unlock(ivar->mtx); in hidbus_intr_start()
613 sx_unlock(&sc->sx); in hidbus_intr_start()
628 if (sx_xlock_sig(&sc->sx) != 0) in hidbus_intr_stop()
630 mtx_lock(ivar->mtx); in hidbus_intr_stop()
631 ivar->active = false; in hidbus_intr_stop()
632 mtx_unlock(ivar->mtx); in hidbus_intr_stop()
633 CK_STAILQ_FOREACH(tlc, &sc->tlcs, link) in hidbus_intr_stop()
634 active |= tlc->active; in hidbus_intr_stop()
636 sx_unlock(&sc->sx); in hidbus_intr_stop()
653 return (&sc->rdesc); in hidbus_get_rdesc_info()
675 * Use cached report descriptor instead of it. in hid_get_report_descr()
677 if (sc->rdesc.data == NULL || sc->rdesc.len == 0) in hid_get_report_descr()
681 *data = sc->rdesc.data; in hid_get_report_descr()
683 *len = sc->rdesc.len; in hid_get_report_descr()
717 if (is_bus && sc->overloaded) in hid_set_report_descr()
731 /* Make private copy to handle a case of dynamicaly allocated data. */ in hid_set_report_descr()
734 sc->overloaded = true; in hid_set_report_descr()
735 free(sc->rdesc.data, M_DEVBUF); in hid_set_report_descr()
736 bcopy(&rdesc, &sc->rdesc, sizeof(struct hid_rdesc_info)); in hid_set_report_descr()
769 if (sc->nowrite) { in hidbus_write()
771 id = (sc->rdesc.oid & (len > 0)) ? *(const uint8_t*)data : 0; in hidbus_write()
812 /*------------------------------------------------------------------------*
815 * This functions takes an array of "struct hid_device_id" and tries
821 *------------------------------------------------------------------------*/
842 * until we reach the end of the matching array: in hidbus_lookup_id()
846 if (is_child && (id->match_flag_page) && in hidbus_lookup_id()
847 (id->page != HID_GET_USAGE_PAGE(usage))) { in hidbus_lookup_id()
850 if (is_child && (id->match_flag_usage) && in hidbus_lookup_id()
851 (id->usage != HID_GET_USAGE(usage))) { in hidbus_lookup_id()
854 if ((id->match_flag_bus) && in hidbus_lookup_id()
855 (id->idBus != info->idBus)) { in hidbus_lookup_id()
858 if ((id->match_flag_vendor) && in hidbus_lookup_id()
859 (id->idVendor != info->idVendor)) { in hidbus_lookup_id()
862 if ((id->match_flag_product) && in hidbus_lookup_id()
863 (id->idProduct != info->idProduct)) { in hidbus_lookup_id()
866 if ((id->match_flag_ver_lo) && in hidbus_lookup_id()
867 (id->idVersion_lo > info->idVersion)) { in hidbus_lookup_id()
870 if ((id->match_flag_ver_hi) && in hidbus_lookup_id()
871 (id->idVersion_hi < info->idVersion)) { in hidbus_lookup_id()
874 if (id->match_flag_pnp && in hidbus_lookup_id()
875 strncmp(id->idPnP, info->idPnP, HID_PNP_ID_SIZE) != 0) { in hidbus_lookup_id()
886 /*------------------------------------------------------------------------*
887 * hidbus_lookup_driver_info - factored out code
892 *------------------------------------------------------------------------*/
901 hidbus_set_driver_info(child, id->driver_info); in hidbus_lookup_driver_info()