Commit Graph

79 Commits

Author SHA1 Message Date
riastradh e56a369d75 usb: Overhaul uhid(4) and uhidev(4) locking.
- uhidev API rules:

  1. Call uhidev_open when you want exclusive use of a report id.
     After it succeeds, you will get interrupts.

  2. Call uhidev_close when done with exclusive use of a report id.
     After it returns, you will no longer get interrupts.

     => uhidev_open/close do not nest.

  3. uhidev_write no longer requires the caller to have exclusive
     access -- if there is a write in progress, it will block
     interruptibly until done.  This way drivers for individual
     report ids need not work separately to coordinate their writes.

  4. You must uhidev_stop to abort any pending writes on the same
     report id.  (uhidev_stop no longer does anything else -- to
     ensure no more interrupts, just use uhidev_close.)

- Fix uhidev_open/close locking -- uhidev now has an interruptible
  config lock held only on first open and last close by any report id
  in the device, to serialize the transition between zero and nonzero
  numbers of references which requires opening/closing pipes and
  allocating/freeing buffers.

- Make /dev/uhidN selnotify(POLLHUP) when the device is yanked.

- Factor uhid device lookup and reference counting and dying
  detection and so on into uhid_enter/exit.

- Nix struct uhid_softc::sc_access_lock.  This served no purpose but
  to confuse me when trying to understand the logic of this beast
  (and to ensure uhidev_write exclusion, but it was uninterruptible,
  which is wrong for something that implements userland operations,
  and didn't actually work because uhidev_write did nothing to
  coordinate between different report ids).

- Fix locking in select/poll.

- Use atomics to manage UHID_IMMED to keep it simple.  (sc_lock would
  be fine too but it makes the code more verbose.)

- Omit needless UHID_ASLP -- cv_broadcast already has this
  micro-optimization.


With these changes, my Pinebook survives

for i in `jot 100`; do
        echo '###' $i
        for j in `jot 16`; do
                usbhidctl -rf /dev/uhid$j >/dev/null &
        done
        wait
done

while plugging and unplugging uhid(4) devices (U2F keys), and the U2F
keys still work as U2F keys.


ok nick, mrg

XXX pullup-9
XXX pullup-8?


Note on ABI and pullups: This changes the layout of struct
uhidev_softc, but with the sole exception of ucycom(4) -- which at
the moment is completely broken and unusable -- the only members that
USB HID drivers use are sc_udev and sc_iface, which haven't changed.
The layout of struct uhidev, which is allocated by each USB HID
driver in its own softc structure, is unchanged.
2020-11-29 22:54:51 +00:00
christos aa3d6ec155 revert the 0x% -> %# change for fixed width formats pointed out by uwe. 2020-03-14 02:35:33 +00:00
christos d3dde16c1a PR/55068: sc.dying: Fix printf formats:
- no %s/%p for kernel log
- 0x% -> %#
- always %j for kernel log
2020-03-13 18:17:40 +00:00
maxv 8d129e6ebf localify 2019-12-06 07:12:38 +00:00
mrg 3b24a1344e remove explicit 'extern struct cfdriver <my>_cd;' and use ioconf.h 2019-05-05 03:17:54 +00:00
jakllsch 269297e942 Correctly handle signed/unsigned quantities in kernel HID parser.
Should fix PR kern/53605.
2018-11-15 23:01:45 +00:00
bouyer 404d04cdb7 Factor out bus-independant HID code so that it can be shared by USB, bluetooth
and i2c.
dev/usb/ukbdmap.c is renamed to dev/hid/hidkbdmap.c
dev/usb/hid.[ch] moved to dev/hid/
usage pages moved from dev/usb/usbhid.h moved to dev/hid/hid.h,
and updated with OpenBSD entries.
bus-independant code moved from dev/usb/ums.c to dev/hid/hidms.c
(the same should be done for keyboard and touchpad drivers)

Needed for the upcoming HID over I2C support, proposed on tech-kern@
on Dec, 1.
2017-12-10 17:03:07 +00:00
ryoon 58bb514de8 Support some Wacom pen tablets:
* Graphire (pen)
* Graphire2 (pen)
* Intuos2 A4 (pen)
* Intuos Art (pen, no finger touch)

Remove report descriptor override workaround for
Graphire and Graphire2.
2017-09-02 04:35:51 +00:00
jakllsch fc12da1821 Always try to set USB HID devices into Report Protocol. (Unless the
device is known to be quirky.)

Some of the most-widely-compatible methods of implementing USB Keyboard
NKRO depend on this Request to function as designed.

Issuing this Request is recommended by the HID 1.11 spec (7.2.6):

... "the host should not make any assumptions about the device's state
and should set the desired protocol whenever initializing a device."
2017-08-13 22:29:42 +00:00
chs fd34ea77eb remove checks for failure after memory allocation calls that cannot fail:
kmem_alloc() with KM_SLEEP
  kmem_zalloc() with KM_SLEEP
  percpu_alloc()
  pserialize_create()
  psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.
2017-06-01 02:45:05 +00:00
skrll c5a90c121f Whitespace 2016-12-04 10:08:26 +00:00
msaitoh 8bc54e5be6 KNF. Remove extra spaces. No functional change. 2016-07-07 06:55:38 +00:00
jakllsch 7dff8092e7 Make #if 0 code that sets the protocol mode compilable. 2016-04-30 18:40:26 +00:00
jakllsch f734221ad6 Pull in opt_usb.h in _KERNEL_OPT case for various *_DEBUG options.
Makes various driver-specific debugging options work again.

XXX more to fix in dev/usb
2016-04-27 19:35:17 +00:00
skrll 4e8e66439e Merge nick-nhusb
- API / infrastructure changes to support memory management changes.
- Memory management improvements and bug fixes.
- HCDs should now be MP safe
- conversion to KERNHIST based debug
- FS/LS isoc support on ehci(4).
- conversion to kmem(9)
- Some USB 3 support - mostly from Takahiro HAYASHI (t-hash).
- interrupt transfers now get proper DMA operations
- general bug fixes
    - kern/48308
    - uhub status notification improvements
    - umass(4) probe fix (applied to HEAD already)
    - ohci(4) short transfer fix
2016-04-23 10:15:27 +00:00
riastradh 233f556c2e Convert sys/dev to use <sys/rndsource.h>. 2015-04-13 16:33:23 +00:00
mrg d9406a725c properly protect uhid's sc_q member with sc_lock. should fix PR#49728.
while here, remove D_MPSAFE from uhid* and all uhid users, as it really
needs all the callers to be safe and they're not.

XXX: pullup-7
2015-03-07 20:20:55 +00:00
jmcneill 47c1f0bc3f Add Xbox One controller support. Report descriptor from https://github.com/lloeki/xbox_one_controller 2015-02-08 19:22:45 +00:00
tls ea6af427bd Merge tls-earlyentropy branch into HEAD. 2014-08-10 16:44:32 +00:00
skrll 20f8d0eef9 PR/48908: Cannot open /dev/uhid? when another report id at the same uhidev
was already opened.

Restore the sc reference counting lost in usbmp merge.
2014-06-17 09:35:46 +00:00
christos 069760d69e from "Just a Normal Person", make sure that we set things to NULL after
we free them.
2013-12-26 15:32:48 +00:00
skrll 33e736ad8f Trailing whitespace. 2013-10-05 07:05:01 +00:00
skrll 9b7b8d7c22 Remove usbd_do_request_async. It's callback was calling usbd_free_xfer
from softint context.

Adjust callers appropriately

	- usbd_clear_endpoint_stall_async is already triggered via a
	  usb_task, so simply call usbd_do_request.

	- uhidev_set_report_async had one caller in ukbd_set_leds.
	  Convert this usage to use usb_task as well.

Discussed with mrg@
2013-09-26 07:25:31 +00:00
mrg dc74fbbf85 merge the jmcneill-usbmp branch. many thanks to jared for the
initial work, and every one else who has tested things for me.
this is largely my fault at this point :-)

the main changes are something like:

        - usbd_bus_methods{} gains a get_lock() to enable the
          host controller to provide a lock for the USB code.
          if the lock isn't provided, old-style protection is
          (partially) applied.

        - ehci/ohci/uhci have been converted to the new
          interfaces, including mutex/cv/etc conversion.

        - usbdivar.h contains a discussion about locking and
          what locks are held for which method calls.  more
          to come for usbdi(9) here.

        - audio drivers (uaudio, umidi, auvitek) have been
          properly SMPified now that USB is ready.

        - scsi drivers have been modified to take the kernel
          lock explicitly before calling into scsi code.

        - usb pipes are associated with a lock, that is the
          same as the controller lock.  (this could be split
          up further in the future.)

        - several usbfoo_locked() or usbfoo_unlocked()
          functions have been added to the usbdi(9) to
          enable functionality with or without the USB
          lock (per controller) already being held.

the TODO.usbmp file has specific details on what is left to
do, including what device-specific changes should be done now
that the whole framework is ready.
2012-06-10 06:15:52 +00:00
tls 7b0b7dedd9 Entropy-pool implementation move and cleanup.
1) Move core entropy-pool code and source/sink/sample management code
   to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
   source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
   avoid expensive operations on disabled entropy sources; make the
   rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
   have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
   system events, and skew between clocks, with a sample implementation
   for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files).  Tested with release
builds on amd64 and evbarm and live testing on amd64.
2012-02-02 19:42:57 +00:00
jakllsch 71fd84843e Revert previous due to active usbmp branch(es). 2011-12-23 00:51:43 +00:00
jakllsch 7f2b9b9ad4 Adjust-away inconsistent and trailing whitespace. 2011-12-22 20:06:59 +00:00
aymeric 9b7bd08973 enable Sony's Six Axis and DualShock 3 USB controllers 2011-10-25 16:12:02 +00:00
jmcneill 0ccce83148 add support for game controllers in "XInput" mode, they are basically
HID devices without a report descriptor
2011-07-30 12:15:44 +00:00
ryoon 34f09a59dc Fix PR kern/42570
* Graphire uses the descriptor as same as Graphire 3.
  This is confirmed by USB analysis on Windows.
  That is done with Wacom's official device driver and USB Snoopy.

* Old rev. 1.1 descriptor supports stylus only, probably 4D mouse
  is not supported. Graphire 3's one probably supports 4D mouse.

* Graphire also needs 0x0202 sending.
2011-07-20 19:27:53 +00:00
tsutsui 9b611cb949 kern/44483: Support for WACOM Graphire2 ET-0405A-U graphics tablet. 2011-01-29 14:20:18 +00:00
dyoung 49337c8880 Stop using the compatibility macros USB_ATTACH(), USB_DETACH(),
USB_MATCH(), et cetera.  These files produce the same assembly
(according to objdump -d) before and after the change
2010-11-03 22:34:23 +00:00
jakllsch d1d4fac35a Adjust report descriptor for Logitech USB Receiver M/N C-BT44 to
more closely match what is in the report.  (This corrects the
off-by-one usages of most of the gray multimedia keys on a EX110
wireless keyboard so they can sensibly be used with libusbhid(3),
usbhidctl(1) and usbhidaction(1).)

This device also uses officially reserved usages (in the approximate
range of 0x1000 to 0x1100) in the Consumer usage page, but these
are out of the logical range the device reports as being valid.
2010-01-12 16:50:58 +00:00
jakllsch ded5c676f3 The Dell DRAC5 gives us a zero-length report immediately following
a normal report.  Thus, ignore zero-length reports.  Move some related
report size insanity checking into the UHIDEV_DEBUG case.

Should fix PR/39911.
2009-12-30 23:42:22 +00:00
dyoung f611b6f9fc Simplify activation hooks. (sc_dying must die!) 2009-11-12 19:58:27 +00:00
rafal 4e042dc0d8 Fix kern/41737 -- add quirks to make MS Wireless Laser Mouse 6000 work. 2009-11-06 04:42:27 +00:00
plunky 5fab894c54 fix up USB drivers printing of autoconf information
1. expand the USB_ATTACH_SETUP macro (requested by jmcneill)

2. reorder the attach function so that the first thing it does is print
   newlines.

3. after this, we can call usbd_devinfo_alloc(), which polls the device
   allowing a context switch, and aprint_normal() the device information.

this avoids problems where autoconf messages are getting mixed up.
2009-09-23 19:07:19 +00:00
drochner a87b5494b4 Fix a dereference if a softc pointer which can legally be zero, leading
to a crash reported by Christoph Egger in a followup to PR kern/38528.
For consistency, keep track of the device_t pointer to child devices
rather than the softc. We really shouldn't mess with child's softc data.
2008-05-26 19:01:51 +00:00
cube 3624455eba Split device_t and softc for all USB device drivers, and related cosmetic
changes.

Matthias Drochner kindly reviewed this patch, and tested ums, ubt, uaudio
and ral.  I tested umass myself.
2008-05-24 16:40:58 +00:00
martin ce099b4099 Remove clause 3 and 4 from TNF licenses 2008-04-28 20:22:51 +00:00
dyoung 0b1dce29ae Use device_t and its accessor functions.
Register _childdetached methods with drivers that attach children.
Wait to set child references to NULL there, instead of doing that
in the detach method.

Replace many uses of USB_DECLARE_DRIVER() with CFATTACH_DECL2().
2008-02-18 05:24:24 +00:00
jmcneill 8eeb638b73 Register with pmf 2007-12-11 03:45:57 +00:00
jmcneill 490542edae aprintify, on behalf of xtraeme 2007-12-01 23:40:28 +00:00
veego d7415fbd43 Add support to ignore hid attachments for some devices, right now MGE and
APC UPS devices.
No objections on tech-kern at the end of June 2007
Patch is from PR kern/31884
2007-10-03 15:01:28 +00:00
drochner dc9d1127cc kill the private submatch function, use the generic one 2007-03-15 15:11:54 +00:00
drochner 8258b792b7 Introduce different autoconf interface attributes for USB drivers
matching (and handling) a whole device and those which match an
interface only. This will allow to enforce some rules, eg that
the former don't use interface information for matching or that the
latter don't modify global device state.
The previous way left too much freedom do the drivers which led to
inconsistencies and abuse.
For now, I've not changed locators and submatch rules, this will
happen later.
There should not be any change in behaviour, except in the case of
some drivers which did behave inconsistently:
if_atu, if_axe, uep: matched the configured device in the interface
 stage, but did configuration again. I've converted them to match
 in the device stage.
ustir, utoppy: matched in the interface stage, but only against
 vendor/device information, and used any configuration/interface
 without checking. Changed to match in device stage, and added
 some simple code to configure and use the first interface.
If you have one of those devices, please test!
2007-03-13 13:51:53 +00:00
ghen f391a807d6 Add ID's for the Graphire3 6x8 (from PR 35111) and Graphire4 4x5 (tested by
myself).
2007-01-22 19:39:37 +00:00
christos 86c0f863d1 Don't allocate >1K on the stack. 2006-06-12 21:01:58 +00:00
augustss cf1de1bda0 Normally a ugen device only attaches if no other driver wants the device.
Add the ability to force ugen to attach with very high priority if "flags 1"
is specified.  This can be used with the vendor and product locators to
force ugen to be used for certain devices.
Similarly, uhid only attaches if no other HID driver (ums or ukbd) wants it.
Again, "flags 1" will force uhid to attach anyway.
2005-11-23 08:54:47 +00:00
itohy a2f0c58dbb If an unknown endpoint is found, ignore it, rather than abort attach.
This change allows to use HID-like devices with additional functions.
2005-10-20 13:09:18 +00:00