History log of /freebsd-current/sys/dev/usb/input/ukbd.c
Revision Date Author Comments
# 685dc743 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 971bac5a 06-Jul-2023 Michael <git@paepcke.de>

kbd: consolidate kb interfaces (phase one)

Refactor to eliminate duplicated rate and delay tables, with minor style
tweaks for changed lines. Remove an obsolete comment about needing to
convert from microseconds to ticks (that's done elsewhere). Remove
traiing whitespace in kbdcontrol.c.

Except for the new warning, no change in behavior

Sponsored by: DSS GmbH
Reviewed by: imp [minor style tweaks as well]
Pull Request: https://github.com/freebsd/pull/683
Differential Revision: https://reviews.freebsd.org/D38818


# b61a5730 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-NetBSD identifier is obsolete, drop -NetBSD

The SPDX folks have obsoleted the BSD-2-Clause-NetBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# f2005895 14-Feb-2023 Stefan Eßer <se@FreeBSD.org>

sys/kbio.h: make pre-unicode keymap support optional

FreeBSD-9 had introduced support for the full set of Unicode
characters to the parsing and processing of keymap character tables.

This support has been extended to cover the table for accented
characters that are reached via dead key combinations in FreeBSD-13.2.

New ioctls have been introduced to support both the pre-Unicode and
the Unicode formats and keyboard drivers have been extended to support
those ioctls.

This commit makes the ABI compatibility functions in the kernel
optional and dependent on COMPAT_FREEBSD13 in -CURRENT.

The kbdcontrol command in -CURRENT and 13-STABLE (before 13.2) has
been made ABI compatible with old kernels to allow a new world to be
run on an old kernel (that does not have full Unicode support for
keymaps).

This commit is not to merged back to 12-STABLE or 13-STABLE. It is
part of review D38465, which has been split into 3 separate commits
due to different MFC and life-time requirements of either commit.

Approved by: imp
Differential Revision: https://reviews.freebsd.org/D38465


# 4972fb92 06-Feb-2023 Stefan Eßer <se@FreeBSD.org>

Support Unicode characters in keymap dead key tables

Support for Unicode characters had been added to the keyboard code,
but there are keymaps that have accented characters accessed via dead
key combinations, and those were still restricted to 8 bit codes.

This update to kbd.c adds support for Unicode characters and
compatibility code that allows a kbdcontrol command built from kbio.h
without these patches to work on a new kernel.

Compatibility code that allows a new kbdcontrol binary running on an
old kernel to load and display the dead key map will be committed in a
separate commit.

Reviewed by: imp, brooks
Approved by: brooks
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D38381


# 18308893 18-Nov-2022 Vladimir Kondratyev <wulf@FreeBSD.org>

evdev: Extend EVIOCGRAB ioctl scope to cover kbd interface

of various keyboard drivers.
EVIOCGRAB ioctl execution on /dev/input/event# device node gains
exclusive access to this device to caller. It is used mostly for
development purposes and remote control software. See e.g.
https://reviews.freebsd.org/D30020 which is the reason of creation
of this change.
Keyboard grabbing is disabled in KDB and during panics.

MFC with: 4a0db5e2920c
Tested by: corvink
Differential revision: https://reviews.freebsd.org/D30542


# bc9372d7 06-May-2022 John Baldwin <jhb@FreeBSD.org>

usb: Remove unused devclass arguments to DRIVER_MODULE.


# 032d3153 13-Feb-2021 Vladimir Kondratyev <wulf@FreeBSD.org>

ukbd: Fix handling of keyboard ErrorRollOver reports

Ignore fantom keyboard state reports entirelly rather than ignore
RollOver states for each key separatelly. Latter results in spurious
release/push pairs of events on each fantom keyboard state report.

Reported by: Jan Martin Mikkelsen <janm_AT_transactionware_DOT_com>
Submitted by: Jan Martin Mikkelsen (initial version)
PR: 253249
MFC after: 1 week


# b62f6dfa 12-Jan-2021 Vladimir Kondratyev <wulf@FreeBSD.org>

hid: Replace USBHID_ENABLED kernel config option with loader tunable

usbhid(4) is disabled by default to avoid conflicts with existing USB HID
drivers. To enable it place following lines to /boot/loader.conf:

hw.usb.usbhid.enable=1
usbhid_load="YES"

Suggested by: jhb
Reviewed by: hselasky
Differential revision: https://reviews.freebsd.org/D28124


# 01f2e864 08-Oct-2020 Vladimir Kondratyev <wulf@FreeBSD.org>

hid: Import usbhid - USB transport backend for HID subsystem.

This change implements hid_if.m methods for HID-over-USB protocol [1].

Also, this change adds USBHID_ENABLED kernel option which changes
device_probe() priority and adds/removes PnP records to prefer usbhid
over ums, ukbd, wmt and other USB HID device drivers and vice-versa.

The module is based on uhid(4) driver. It is disabled by default for
now due to conflicts with existing USB HID drivers.

[1] https://www.usb.org/sites/default/files/hid1_11.pdf

Reviewed by: hselasky
Differential revision: https://reviews.freebsd.org/D27893


# eead9017 01-Jan-2021 Vladimir Kondratyev <wulf@FreeBSD.org>

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)


# 67de2db2 04-Oct-2020 Vladimir Kondratyev <wulf@FreeBSD.org>

Factor-out hardware-independent part of USB HID support to new module

It will be used by the upcoming HID-over-i2C implementation. Should be
no-op, except hid.ko module dependency is to be added to affected drivers.

Reviewed by: hselasky, manu
Differential revision: https://reviews.freebsd.org/D27867


# 30f34a51 24-Dec-2020 Vladimir Kondratyev <wulf@FreeBSD.org>

ukbd(4): Push LED events in ioctl handler rather than in xfer callback

If LED state is set through evdev interface, than asynchronous nature
of USB transfer callback can lead to change of order of events echoed
back to userland as it causes LED events to be echoed with some lag.

Fix that with echoing of LED events synchronously in ioctl handler.

Reviewed by: hselasky
Obtained from: sysutils/iichid
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D27750


# 769935a4 24-Dec-2020 Vladimir Kondratyev <wulf@FreeBSD.org>

ukbd(4): Do not serialize evdev key events

Unlike AT keyboards, HID devices are able to send all pc105 key
states within a single report. Let evdev to transmit all key state
changes within a single report too.

Reviewed by: hselasky
Obtained from: sysutils/iichid
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D27749


# 9dd3156e 01-Sep-2020 Mateusz Guzik <mjg@FreeBSD.org>

usb: clean up empty lines in .c and .h files


# 8e2e5ae7 30-Mar-2020 Hans Petter Selasky <hselasky@FreeBSD.org>

Evaluate modifier keys before the regular keys, so that if a modifier
key is pressed at the same time as a regular key, that means key with
modifier is output. Some automated USB keyboards like Yubikeys need this.

This fixes a regression issue after r357861.

Reported by: Adam McDougall <mcdouga9@egr.msu.edu>
PR: 224592
PR: 233884
MFC after: 3 days
Sponsored by: Mellanox Technologies


# 0e5670a9 04-Mar-2020 Hans Petter Selasky <hselasky@FreeBSD.org>

Restart the USB keyboard repeat timer at every valid key-press.

This fixes a regression issue after r357861.

Reported by: James Wright <james.wright@jigsawdezign.com>
PR: 224592
PR: 233884
MFC after: 3 days
Sponsored by: Mellanox Technologies


# 0ba49072 24-Feb-2020 Hans Petter Selasky <hselasky@FreeBSD.org>

Use hid_get_data_unsigned() instead of hid_get_data() when reading the
key-codes from the USB keyboard. Negative key-codes are currently skipped.

While at it use the bit size value provided by the HID location structure
instead of assuming a value of 8.

This fixes a regression issue after r357861.

Reported by: Minoru TANABE <kotanabe3@gmail.com>
PR: 224592
PR: 233884
MFC after: 3 days
Sponsored by: Mellanox Technologies


# f8d2b1f3 15-Feb-2020 Pawel Biernacki <kaktus@FreeBSD.org>

Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (2 of many)

r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are
still not MPSAFE (or already are but aren’t properly marked). Use it in
preparation for a general review of all nodes.
This is non-functional change that adds annotations to SYSCTL_NODE and
SYSCTL_PROC nodes using one of the soon-to-be-required flags.

Reviewed by: hselasky, kib
Approved by: kib (mentor)
Differential Revision: https://reviews.freebsd.org/D23632


# 144d6690 13-Feb-2020 Hans Petter Selasky <hselasky@FreeBSD.org>

Exclude modifier keys from keyboard repeat logic.
This restores USB keyboard driver behaviour prior to r357861.

Requested by: jkim@
MFC after: 1 week
Sponsored by: Mellanox Technologies


# d4028678 13-Feb-2020 Hans Petter Selasky <hselasky@FreeBSD.org>

Improve USB gaming keyboard support.

Add support for decoding pressed keys as a bitmap. The keys in the
bitmap are described in the interface specific HID descriptor. Some
keyboards even have multiple input interfaces, only using the bitmap
method when the event array is full. That typically means when more
than seven keys are pressed simultaneously.

The internals of the USB keyboard driver have been slightly reworked
to keep track of all keys in a single bitmap having 256 bits. This
bitmap is then divided into blocks of 64-bits as an optimisation.

Simplify automatic key repeat logic, because only the last key pressed
can be repeated.

PR: 224592
PR: 233884
Tested by: Alex V. Petrov <alexvpetrov@gmail.com>
MFC after: 1 week
Sponsored by: Mellanox Technologies


# 2899979d 26-Dec-2019 Kyle Evans <kevans@FreeBSD.org>

Revert r355806: kbd drivers: don't double register keyboard drivers

r356087 made it rather innocuous to double-register built-in keyboard
drivers; we now set a flag to indicate that it's been registered and only
act once on a registration anyways. There is no misleading here, as the
follow-up kbd_delete_driver will actually remove the driver as needed now
that the linker set isn't also consulted after kbdinit.


# 5a7a578b 16-Dec-2019 Kyle Evans <kevans@FreeBSD.org>

kbd drivers: don't double register keyboard drivers

Keyboard drivers are generally registered via linker set. In these cases,
they're also available as kmods which use KPI for registering/unregistering
keyboard drivers outside of the linker set.

For built-in modules, we still fire off MOD_LOAD and maybe even MOD_UNLOAD
if an error occurs, leading to registration via linker set and at MOD_LOAD
time.

This is a minor optimization at best, but it keeps the internal kbd driver
tidy as a future change will merge the linker set driver list into its
internal keyboard_drivers list via SYSINIT and simplify driver lookup by
removing the need to consult the linker set.


# eefc662f 15-Dec-2019 Kyle Evans <kevans@FreeBSD.org>

kbd: provide default implementations of get_fkeystr/diag

Most keyboard drivers are using the genkbd implementations as it is;
formally use them for any that aren't set and make
genkbd_get_fkeystr/genkbd_diag private.


# 4434de96 15-Dec-2019 Kyle Evans <kevans@FreeBSD.org>

kbd drivers: use kbdd_* indirection for diag invocation

These invocations were directly calling enkbd_diag(), rather than
indirection back through kbdd_diag/kbdsw. While they're functionally
equivent, invoking kbdd_diag where feasible (i.e. not in a diag
implementation) makes it easier to visually identify locking needs in these
other drivers.


# ac3f30a4 30-Nov-2019 Kyle Evans <kevans@FreeBSD.org>

usb: remove some extraneous tty.h includes


# f86e7267 27-Oct-2018 Vladimir Kondratyev <wulf@FreeBSD.org>

evdev: Use console lock as evdev lock for all supported keyboard drivers.

Now evdev part of keyboard drivers does not take any locks if corresponding
input/eventN device node is not opened by userland consumers.

Do not assert console lock inside evdev to handle the cases when keyboard
driver is called from some special single-threaded context like shutdown
thread.


# 48f2b006 13-Aug-2018 Vladimir Kondratyev <wulf@FreeBSD.org>

evdev: Remove evdev.ko linkage dependency on kbd driver

Move evdev_ev_kbd_event() helper from evdev to kbd.c as otherwise evdev
unconditionally requires all keyboard and console stuff to be compiled
into the kernel. This dependency happens as evdev_ev_kbd_event() helper
references kbdsw global variable defined in kbd.c through use of
kbdd_ioctl() macro.

While here make all keyboard drivers respect evdev_rcpt_mask while setting
typematic rate and LEDs with evdev interface.

Requested by: Milan Obuch <bsd@dino.sk>
Reviewed by: hselasky, gonzo
Differential Revision: https://reviews.freebsd.org/D16614


# 6469bdcd 06-Apr-2018 Brooks Davis <brooks@FreeBSD.org>

Move most of the contents of opt_compat.h to opt_global.h.

opt_compat.h is mentioned in nearly 180 files. In-progress network
driver compabibility improvements may add over 100 more so this is
closer to "just about everywhere" than "only some files" per the
guidance in sys/conf/options.

Keep COMPAT_LINUX32 in opt_compat.h as it is confined to a subset of
sys/compat/linux/*.c. A fake _COMPAT_LINUX option ensure opt_compat.h
is created on all architectures.

Move COMPAT_LINUXKPI to opt_dontuse.h as it is only used to control the
set of compiled files.

Reviewed by: kib, cem, jhb, jtl
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D14941


# 6e786862 28-Mar-2018 Hans Petter Selasky <hselasky@FreeBSD.org>

Fix for regression issue in USB keyboard driver after r304735.

A series of zero delay callouts can happen causing high CPU usage of the
timer subsystem when trying to repeat keys, because the time of the
absolute timeout is not moving forward. The condition clears when all
keys are released.

Reported by: Johannes Lundberg <johalun0@gmail.com>
Discussed with: bde@
PR: 226968
MFC after: 1 week
Sponsored by: Mellanox Technologies


# 718cf2cc 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

sys/dev: further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.


# 5163e77f 03-Oct-2016 Oleksandr Tymoshenko <gonzo@FreeBSD.org>

const-ify struct evdev_methods

Submitted by: Vladimir Kondratiev <wulf@cicgroup.ru>
Suggested by: hselasky


# a6b15a34 01-Oct-2016 Oleksandr Tymoshenko <gonzo@FreeBSD.org>

Modularize evdev

- Convert "options EVDEV" to "device evdev" and "device uinput", add
modules for both new devices. They are isolated subsystems and do not
require any compile-time changes to general kernel subsytems
- For hybrid drivers that have evdev as an optional way to deliver input
events add option EVDEV_SUPPORT. Update all existing hybrid drivers
to use it instead of EVDEV
- Remove no-op DECLARE_MODULE in evdev, it's not required, MODULE_VERSION
is enough
- Add evdev module dependency to uinput

Submitted by: Vladimir Kondratiev <wulf@cicgroup.ru>


# fa26e8ed 30-Sep-2016 Oleksandr Tymoshenko <gonzo@FreeBSD.org>

Declare a module for evdev and add dependency to ukbd(4) and ums(4)

Prepare for making evdev a module. "Pure" evdev device drivers (like
touchscreen) and evdev itself can be built as a modules regardless of
"options EVDEV" in kernel config. So if people does not require evdev
functionality in hybrid drivers like ums and ukbd they can, for instance,
kldload evdev and utouchscreen to run FreeBSD in kiosk mode.


# 7dd7ec2c 23-Sep-2016 Oleksandr Tymoshenko <gonzo@FreeBSD.org>

Do not perform extra check for NULL, evdev_free can handle NULL value

Submitted by: Vladimir Kondratiev <wulf@cicgroup.ru>


# 10063b79 21-Sep-2016 Oleksandr Tymoshenko <gonzo@FreeBSD.org>

Add evdev support to ukbd driver

event generation is disabled by default in favour of kbdmux. This
behavoiur is controlled by kern.evdev.rcpt_mask sysctl, bit 3 should
be set to give priority to hw over mux

Submitted by: Vladimir Kondratiev <wulf@cicgroup.ru>
Reviewed by: hans
Differential Revision: https://reviews.freebsd.org/D7957


# 0eb8d462 13-Sep-2016 Hans Petter Selasky <hselasky@FreeBSD.org>

Improve USB polling mode by not locking any mutexes, asserting any
mutexes or using any callouts when active.

Trying to lock a mutex when KDB is active or the scheduler is stopped
can result in infinite wait loops. The same goes for calling callout
related functions which in turn lock mutexes.

If the USB controller at which a USB keyboard is connected is idle
when KDB is entered, polling the USB keyboard via USB will always
succeed. Else polling may fail depending on which state the USB
subsystem and USB interrupt handler is in. This is unavoidable unless
KDB can wait for USB interrupt threads to complete before stalling the
CPU(s).

Tested by: Bruce Evans <bde@freebsd.org>
MFC after: 4 weeks


# 1a58327b 23-Aug-2016 Bruce Evans <bde@FreeBSD.org>

Fix key delay and repeat, part 2.

Use sbintime_t timeouts with precision control to get very accurate
timing. It costs little to always ask for about 1% accuracy, and the
not so new event timer implementation usual delivers that, and when
it can't it gets much closer than our previous coarse timeouts and
buggy simple countdown.

The 2 fastest atkbd repeat rates have periods 34 and 38 msec, and ukbd
pretended to support rates in between these. This requires
sub-microsecond precision and accuracy even to handle the 4 msec
difference very well, but ukbd asked the timeout subsystem for timeouts
of 25 msec and the buggy simple countdown of this gave a a wide range
of precisions and accuracies depending on HZ and other timer
configuration (sometimes better than 25 msec but usually more like 50
msec). We now ask for and usually get precision and accuracy of about
1% for each repeat and much better on average.

The 1% accuracy is overkill. Rounding of 30 cps to 34 msec instead of
33 already gives an error of +2% instead of -1%, and ut AT keyboards on
PS/2 interfaces have similar errors.

A timeout is now scheduled for every keypress and release. This allows
some simplifications that are not done. It allows removing the timeout
scheduling for exiting polled mode where it was unsafe in ddb mode. This
is done. Exiting polled mode had some problems with extra repeats. Now
exiting polled mode lets an extra timeout fire and the state is fudged
so that the timeout handler does very little.

The sc->time_ms variable is unsigned to avoid overflow. Differences of
it need to be signed. Signed comparisons were emulated by testing an
emulated sign bits. This only works easily for '<' comparisonss, but
we now need a '<=' comparison. Change the difference variable to
signed and use a signed comparison. Using unsigned types here didn't
prevent overflow bugs but just reduced them. Overflow occurs with
n repeats at the silly repeat period of [U]INT_MAX / n. The old countdown
had an off by 1 error, and the simplifications would simply count down
1 to 0 and not need to accumulate possibly-large repeat repeats.


# e99472e0 23-Aug-2016 Bruce Evans <bde@FreeBSD.org>

Fix key delay and repeat, part 1.

kbdcontrol -r fast is documented to give a non-emulated atkbd's fastest
rate of 250.34, but is misimplemented to request this as 0.0. ukbd
supports many nonstandard rates, although it is currently too inaccurate
by a factor of several hundred for non-huge nonstandard rates to be
useful. It mapped 0.0 to 200.0. A repeat delay of 0 means a rate of
infinity which is quite fast, but physical constraints limit this to
a few MHz and the inaccuracies made it almost usable.

Convert 0.0 to the documented 250.34.

Also convert negative args and small args to the 250.34 minimal ones,
like atkbd does. This is for KDSETREPEAT -- the 2 versions of the
deprecated KDSETRAD have bounds checking. Keep not doing any bounds
checking or conversions for upper limits since nonstandard large
delays are useful for testing.

The inaccuracies are dependent on HZ and the timeout implementation.
With the old timeout implementation and HZ = 1000, 200.0 probably
worked better to emulate 250.34 than 250.34 itself. HZ = 100 gives
roundoff errors that accidentally reduce the inaaccuracies, and
event timers reduce the inaccuracies even more, so 200.0 was giving
more like itself (perhaps 215.15 on average but sometimes close to
10 msec repeat which is noticebly too fast). This commit makes 0.0
noticeably too slow, like 250.34 always was.


# ded67349 22-Aug-2016 Bruce Evans <bde@FreeBSD.org>

Further fixes for translation of PrintScreen/SysRq.

The previous fix was tested mainly on 3 AT keyboards with USB adaptors where
it works. 1 USB keyboard doesn't translate Alt-PrintScreen, so the software
has to do it.

Reorganize a little to share some code and to not translate the unusual usb
scan code0x8a unless an Alt modified is set. Remove redundant check of Alt
modifiers. Translation now more clearly filters out Alt-PrintScreen before
the check.

The table of errors fixed in the previous commit had many bugs. Correct
table:

K_RAW Ctl-PrintScreen: E0-2A-E0-37 -> E0-37
K_RAW Alt-PrintScreen (with 4 comb. of Ctl/Shift): 79 -> 54
K_RAW Pause/Break (with 4 comb. of Alt/Shift): E0-46 -> E1-1D-45
K_CODE PrintScreen (with 4 comb. of Ctl/Shift): 54 -> 5c
K_CODE Alt-PrintScreen (with 4 comb. of Ctl/Shift): 7e -> 54
K_CODE Pause/Break (with 8 comb. of Ctl/Alt/Shift): 6c -> 68

That is 25 of 32 shift combinations for 2 keys fixed. All 16 combinations
were broken for K_CODE and thus also for K_XLATE.


# a6ae9251 21-Aug-2016 Hans Petter Selasky <hselasky@FreeBSD.org>

Make the UKBD USB transfers double buffered and set them up one by one,
so they are memory independent which allows for handling panics
triggered by the keyboard driver itself, typically via CTRL+ALT+ESC
sequences. Or if the USB keyboard driver was processing a key at the
moment of panic. Allow UKBD to be attached while keyboard polling is active.

Tested by: Bruce Evans <bde@freebsd.org>
MFC after: 1 week


# 3f7880e2 21-Aug-2016 Bruce Evans <bde@FreeBSD.org>

Fix translation of the PrintScreen/SysRq and Pause/Break keys. Almost
everything was broken. The cases that I noticed were Ctrl-PrintScreen
not being mapped to the virtual scancode 0x5c (debug) and Pause not being
mapped to the physical/virtual scancode 0x46 (slock).

These keys are the most complicated ones due to kludges to give some
compatibility back to before AT keyboards.

Alt-PrintScreen must pretend to be a separate key from PrintScreen
even at the "raw" level. The (unique) usb code for it is 0x8a and we
just have to map this to our unique virtual scancode 0x54, but we
mapped it first to the internal code 0x7e and then to 0x79 which is a
key on the Japanese 106/109 keyboard. This fix is under the
UKBD_EMULATE_ATASCANCODE option which shouldn't be used for non-AT
keyboards. If it is, then the syscons Japanese keymaps have nothing
of importance for code 0x79 and can easily be changed. 0x54 is also
unimportant in Japanese and US keymaps.

NonAlt-PrintScreen and NonCtl-Pause/Break had many much larger bugs with
smaller compatibility problems from fixing them. The details are too
ugly to give here. Summary of the changed (hex) codes:

K_RAW PrintScreen (Ctl, Shift, Ctl-Shift): E0-2A-E0-37 -> E0-37
K_RAW Alt-PrintScreen (all shift states): 79 -> 54
K_RAW Pause/Break (unshifted, Shift, Alt, Alt-Shift)): E0-46 -> E1-1D-45
K_CODE ALT-PrintScreen (all shift states): 79 -> 54

That is 15 of 32 shift combinations for 2 keys fixed, with 8 easy cases
from the 79 -> 54 remapping.

The difference is only large and with no workaround using a keymap for
for K_RAW, but this affects other modes when ukbd is layered under kbmux
because kbmux keeps all subdevices in K_RAW mode and translates. Oops.
I used kbdmux to generate the above table of changes.


# f87a304c 05-Aug-2016 Hans Petter Selasky <hselasky@FreeBSD.org>

Keep a reference count on USB keyboard polling to allow recursive
cngrab() during a panic for example, similar to what the AT-keyboard
driver is doing.

Found by: Bruce Evans <brde@optusnet.com.au>
MFC after: 1 week


# 432157dc 19-Apr-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

dev/usb: use our nitems() macro when param.h is available.

Reviewed by: hselasky


# f809f280 10-Dec-2015 Warner Losh <imp@FreeBSD.org>

Create a USB_PNP_INFO and use it to export the existing PNP
tables. Some drivers needed some slight re-arrangement of declarations
to accommodate this. Change the USB pnp tables slightly to allow
better compatibility with the system by moving linux driver info from
start of each entry to the end. All other PNP tables in the system
have the per-device flags and such at the end of the elements rather
that at the beginning.

Differential Review: https://reviews.freebsd.org/D3458


# db002659 21-Nov-2015 Hans Petter Selasky <hselasky@FreeBSD.org>

Add support for Kana and Eisu keys to the USB keyboard driver.

PR: 204709
Submitted by: naito.yuichiro@gmail.com
MFC after: 3 days


# af3b2549 27-Jun-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

Pull in r267961 and r267973 again. Fix for issues reported will follow.


# 37a107a4 27-Jun-2014 Glen Barber <gjb@FreeBSD.org>

Revert r267961, r267973:

These changes prevent sysctl(8) from returning proper output,
such as:

1) no output from sysctl(8)
2) erroneously returning ENOMEM with tools like truss(1)
or uname(1)
truss: can not get etype: Cannot allocate memory


# 3da1cf1e 27-Jun-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

Extend the meaning of the CTLFLAG_TUN flag to automatically check if
there is an environment variable which shall initialize the SYSCTL
during early boot. This works for all SYSCTL types both statically and
dynamically created ones, except for the SYSCTL NODE type and SYSCTLs
which belong to VNETs. A new flag, CTLFLAG_NOFETCH, has been added to
be used in the case a tunable sysctl has a custom initialisation
function allowing the sysctl to still be marked as a tunable. The
kernel SYSCTL API is mostly the same, with a few exceptions for some
special operations like iterating childrens of a static/extern SYSCTL
node. This operation should probably be made into a factored out
common macro, hence some device drivers use this. The reason for
changing the SYSCTL API was the need for a SYSCTL parent OID pointer
and not only the SYSCTL parent OID list pointer in order to quickly
generate the sysctl path. The motivation behind this patch is to avoid
parameter loading cludges inside the OFED driver subsystem. Instead of
adding special code to the OFED driver subsystem to post-load tunables
into dynamically created sysctls, we generalize this in the kernel.

Other changes:
- Corrected a possibly incorrect sysctl name from "hw.cbb.intr_mask"
to "hw.pcic.intr_mask".
- Removed redundant TUNABLE statements throughout the kernel.
- Some minor code rewrites in connection to removing not needed
TUNABLE statements.
- Added a missing SYSCTL_DECL().
- Wrapped two very long lines.
- Avoid malloc()/free() inside sysctl string handling, in case it is
called to initialize a sysctl from a tunable, hence malloc()/free() is
not ready when sysctls from the sysctl dataset are registered.
- Bumped FreeBSD version to indicate SYSCTL API change.

MFC after: 2 weeks
Sponsored by: Mellanox Technologies


# ed25d0e8 17-Mar-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

Fix spelling.

Reported by: Kevin P. Neal <kpneal@pobox.com>


# cdea3bef 10-Mar-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

Ignore USB keyboard driver calls from critical sections.

Reported by: Oliver Pinter <oliver.pntr@gmail.com>
MFC after: 1 week


# 1c006b57 28-Jan-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

When detaching a [USB] keyboard, keys might still be pressed. Ensure
that all pressed keys are released before completing the USB keyboard
detach. This will prevent so-called "ghost-keys" from appearing after
that the USB device generating the key event(s) has been detached.

MFC after: 1 week


# ef3187d5 28-Jan-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

Revert r260622:
To be implemented a bit differently.


# 8af981a4 14-Jan-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

Don't output any modifier keys before we see a valid
non-modifier key press. This prevents so-called "ghost
keyboards" keeping modifier keys pressed while not
actually seen as a real keyboard.

MFC after: 2 weeks


# 3a8f0c44 20-Aug-2013 Hans Petter Selasky <hselasky@FreeBSD.org>

Force keyboards which don't have the required
HID fields to use the USB BOOT protocol for now.

PR: usb/181425
Submitted by: Andrey Zholos <aaz@q-fu.com>
MFC after: 4 weeks


# 0ccd2fb0 13-Jul-2013 Hans Petter Selasky <hselasky@FreeBSD.org>

Allow regular off-the-shelf keyboards to be overclocked like so-called
"Gamers Keyboards" by adding a tunable, "hw.usb.ukbd.pollrate", which
can fix the polling rate of the attached USB keyboards in the range
1..1000Hz. A similar feature already exists in the USB mouse
driver. Use with care! Might leave you without keyboard input. This
feature is only available when the USB_DEBUG option is set in the
kernel configuration file.

Correct "unit" type to "int" while at it.


# 61bfd867 30-Jan-2013 Sofian Brabez <sbz@FreeBSD.org>

Use DEVMETHOD_END macro defined in sys/bus.h instead of {0, 0} sentinel on device_method_t arrays

Reviewed by: cognet
Approved by: cognet


# 60867f57 10-Jan-2013 Hans Petter Selasky <hselasky@FreeBSD.org>

Fix detection of Razer Copperhead as a USB mouse.
Factor out USB mouse and keyboard detection logic.
Reject USB keyboards which have mouse alike HID items
in their HID descriptors.

Submitted by: Matthew W
MFC after: 1 week


# 83cadd7d 26-Oct-2012 Hans Petter Selasky <hselasky@FreeBSD.org>

Add missing CTLFLAG_TUN flag to tunable sysctls in USB stack.
Rearrange the tunables and belonging sysctl declarations, so
that they are next to eachother.

Submitted by: n_hibma @
MFC after: 1 week


# 6d917491 02-Apr-2012 Hans Petter Selasky <hselasky@FreeBSD.org>

Fix compiler warnings, mostly signed issues,
when USB modules are compiled with WARNS=9.

MFC after: 1 weeks


# bc40a969 21-Dec-2011 Andriy Gapon <avg@FreeBSD.org>

ukbd: adjust for SCHEDULER_STOPPED() and overhaul locking code

This change is designed to let USB keyboard work in the panic context
with stop_scheduler_on_panic=1. Most of change consists of removing
mtx_owned() checks where they can be easily avoided. Some additional
lock cleanup is performed along the way.

A list of the smaller changes:
- newbus methods should be executed with Giant already held, just assert
this
- kbd methods called in the non-polling context should be executed with
Giant already held, just assert this
- Giant is recursive, so we should just take it where we must have it,
without redundant checks if we already have it
- thanks to recent syscons changes we don't need to go through the hoops
to detect if kernel is going to poll us; polling mode is now clearly
separated from non-polling mode
- at present the polling mode can be entered by only one thread
- document special cases in greater detail

Please note that the ukbd code and underlying USB code still lve
dangerously in the kdb context by trying to obtain various locks
including the Giant. If any of those locks are already held by the
stopped threads, then the things would blow up.
Another limitation of the ukbd driver is that it is detached before a
system enters the halt state.

With this commit we can enable kern.stop_scheduler_on_panic by default,
that should not introduce any regressions.

Reviewed by: hselasky
MFC after: 3 months
X-MFC after: r228424, r228760


# 6472ac3d 07-Nov-2011 Ed Schouten <ed@FreeBSD.org>

Mark all SYSCTL_NODEs static that have no corresponding SYSCTL_DECLs.

The SYSCTL_NODE macro defines a list that stores all child-elements of
that node. If there's no SYSCTL_DECL macro anywhere else, there's no
reason why it shouldn't be static.


# 78d4d8ee 17-Jul-2011 Ed Schouten <ed@FreeBSD.org>

Restore binary compatibility for GIO_KEYMAP and PIO_KEYMAP.

Back in 2009 I changed the ABI of the GIO_KEYMAP and PIO_KEYMAP ioctls
to support wide characters. I created a patch to add ABI compatibility
for the old calls, but I didn't get any feedback to that.

It seems now people are upgrading from 8 to 9 they experience this
issue, so add it anyway.


# 2b6ce80c 13-Jul-2011 Hans Petter Selasky <hselasky@FreeBSD.org>

Fix for dump after shutdown with USB keyboard plugged in. It appears that the
system timer is stopped during shutdown and that the pause() statement in ukbd
causes infinite hang in this regard. The fix is to use mi_switch() instead of
pause() to do the required task switch to ensure that the required USB processes
get executed.

Reported by: Mike_Karels@mcafee.com
MFC after: 1 week


# e92091ad 04-Jul-2011 Hans Petter Selasky <hselasky@FreeBSD.org>

Make the USB keyboard driver more HID compliant.
Try to auto-detect keyboards which should use the BOOT protocol.

MFC after: 2 weeks


# 9c916c62 24-Jun-2011 Hans Petter Selasky <hselasky@FreeBSD.org>

- Export more USB device ID's.
- Update bus_auto.conf accordingly.

MFC after: 3 days


# cd10bffa 18-May-2011 Andriy Gapon <avg@FreeBSD.org>

usb: change to one-pass probing of device drivers

This brings USB bus more in line with how newbus is supposed to be used.
Also, because of the two-pass probing the following message was produced
by devd in default configuration when almost any USB device was
connected:
Unknown USB device: vendor <> product <> bus <>
This should be fixed now.

Note that many USB device drivers pass some information from probe
method to attach method via ivars. For this to continue working we rely
on the fact that the subr_bus code calls probe method of a winning driver
again before calling its attach method in the case where multiple
drivers claim to support a device. This is done because device
description is set in successful probe methods and we want to get a correct
device description from a winning driver. So now this logic is re-used
for setting ivars too.

Reviewed by: hselasky
MFC after: 1 month


# 58ccf5b4 11-Jan-2011 John Baldwin <jhb@FreeBSD.org>

Remove unneeded includes of <sys/linker_set.h>. Other headers that use
it internally contain nested includes.

Reviewed by: bde


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# a6eb8319 01-Sep-2010 Andrew Thompson <thompsa@FreeBSD.org>

Silence debug error by default.

PR: usb/141212
Submitted by: Hans Petter Selasky


# 910cb8fe 01-Sep-2010 Andrew Thompson <thompsa@FreeBSD.org>

Add missing MODULE_VERSION() definitions, this resolves problems around
duplicate module loads.

PR: usb/125736
Submitted by: danger, mm
Reviewed by: hselasky


# 199841d3 17-May-2010 Andrew Thompson <thompsa@FreeBSD.org>

MFC r206638

Use the UIPROTO_BOOT_KEYBOARD #define from usb.h rather than a local
(almost identically named) local #define.


# ad658060 29-Apr-2010 Andrew Thompson <thompsa@FreeBSD.org>

MFC r207077

Change USB_DEBUG to #ifdef and allow it to be turned off. Previously this had
the illusion of a tunable setting but was always turned on regardless.


# b850ecc1 22-Apr-2010 Andrew Thompson <thompsa@FreeBSD.org>

Change USB_DEBUG to #ifdef and allow it to be turned off. Previously this had
the illusion of a tunable setting but was always turned on regardless.

MFC after: 1 week


# 2d8d6ee4 14-Apr-2010 Gavin Atkinson <gavin@FreeBSD.org>

Use the UIPROTO_BOOT_KEYBOARD #define from usb.h rather than a local
(almost identically named) local #define.

Reviewed by: hselasky


# 6b6aaa9f 06-Apr-2010 Andrew Thompson <thompsa@FreeBSD.org>

MFC r205804

Do not swap Apple keys when detecting Apple-FN keyboards.

Reported by: Steven Noonan
Submitted by: Hans Petter Selasky


# 963d675e 06-Apr-2010 Andrew Thompson <thompsa@FreeBSD.org>

MFC r205040

extend search for Apple Function Key.

PR: usb/144414
Submitted by: Hans Petter Selasky


# 2c50fc45 06-Apr-2010 Andrew Thompson <thompsa@FreeBSD.org>

MFC r203896

Detect when we are polling from kernel via cngetc() in the boot process and
reserve the keypresses so they do not get passed to syscons.

Submitted by: Hans Petter Selasky


# 9e5d4aec 28-Mar-2010 Andrew Thompson <thompsa@FreeBSD.org>

Do not swap Apple keys when detecting Apple-FN keyboards.

Reported by: Steven Noonan
Submitted by: Hans Petter Selasky


# abaa9bfe 11-Mar-2010 Andrew Thompson <thompsa@FreeBSD.org>

extend search for Apple Function Key.

PR: usb/144414
Submitted by: Hans Petter Selasky


# 7e4b1c06 03-Mar-2010 Joel Dahl <joel@FreeBSD.org>

The NetBSD Foundation has granted permission to remove clause 3 and 4 from
their software.

Obtained from: NetBSD


# 1bdb81f1 14-Feb-2010 Andrew Thompson <thompsa@FreeBSD.org>

Detect when we are polling from kernel via cngetc() in the boot process and
reserve the keypresses so they do not get passed to syscons.

Submitted by: Hans Petter Selasky


# c1b5138f 09-Dec-2009 Andrew Thompson <thompsa@FreeBSD.org>

MFC r199816

Remove overuse of exclamation marks in kernel printfs, there mere fact a
message has been printed is enough to get someones attention. Also remove the
line number for DPRINTF/DPRINTFN, it already prints the funtion name and a
unique message.


# c7838bf9 09-Dec-2009 Andrew Thompson <thompsa@FreeBSD.org>

MFC r199675

Provide tunables for some of the usb sysctls that affect boot behaviour.

Submitted by: Andriy Gapon


# a4ca3864 09-Dec-2009 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

MFC r199169:

Reduce probe priority of USB input devices to BUS_PROBE_GENERIC from
BUS_PROBE_SPECIFIC. This allows device-specific drivers like atp to
attach reliably.


# 767cb2e2 25-Nov-2009 Andrew Thompson <thompsa@FreeBSD.org>

Remove overuse of exclamation marks in kernel printfs, there mere fact a
message has been printed is enough to get someones attention. Also remove the
line number for DPRINTF/DPRINTFN, it already prints the funtion name and a
unique message.


# c13fd8d4 22-Nov-2009 Andrew Thompson <thompsa@FreeBSD.org>

Provide tunables for some of the usb sysctls that affect boot behaviour.

Submitted by: Andriy Gapon


# b201cde6 10-Nov-2009 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Reduce probe priority of USB input devices to BUS_PROBE_GENERIC from
BUS_PROBE_SPECIFIC. This allows device-specific drivers like atp to
attach reliably.

Reviewed by: hps


# 6a8d0ac9 29-Oct-2009 Andrew Thompson <thompsa@FreeBSD.org>

MFC r198152

Only poll ukbd if KDB is active.


# b0deb909 29-Oct-2009 Andrew Thompson <thompsa@FreeBSD.org>

MFC r197999 (hrs)

Fix the 106/109 USB Japanese keyboard "underscore" issue.
Sun Type 6 USB keyboard support added in rev 1.46 conflicted with
some scan codes used in Japanese keyboards because the scan code
conversion routine was ambiguous for the overlapped codes.

PR: ports/134005


# c3139ea6 15-Oct-2009 Andrew Thompson <thompsa@FreeBSD.org>

Only poll ukbd if KDB is active.

Submitted by: HPS


# aea0c7f3 12-Oct-2009 Hiroki Sato <hrs@FreeBSD.org>

Fix the 106/109 USB Japanese keyboard "underscore" issue.
Sun Type 6 USB keyboard support added in rev 1.46 conflicted with
some scan codes used in Japanese keyboards because the scan code
conversion routine was ambiguous for the overlapped codes.

PR: ports/134005
Submitted by: YAMASHIRO Jun


# 42a66b53 01-Sep-2009 Alfred Perlstein <alfred@FreeBSD.org>

MFC: r196489,196498
Critical USB bugfixes for 8.0

Approved by: re


# 247549d1 23-Aug-2009 Alfred Perlstein <alfred@FreeBSD.org>

- patch for cordump slowdown. Avoid using DELAY(1000) when no
keys are pressed.
- Reported by: Various people

- add sysctl to disable keyboard led control request
- Reported by: Yoshihiro Ota

- Save system CPU usage: Patch to stop keyboard timer when no
keys are pressed.

Submitted by: hps
MFC after: 3 days


# 247db074 20-Aug-2009 John Baldwin <jhb@FreeBSD.org>

MFC 196403: Temporarily revert the new-bus locking for 8.0 release.

Approved by: re (kib)


# a56fe095 20-Aug-2009 John Baldwin <jhb@FreeBSD.org>

Temporarily revert the new-bus locking for 8.0 release. It will be
reintroduced after HEAD is reopened for commits by re@.

Approved by: re (kib), attilio


# 444b9186 02-Aug-2009 Attilio Rao <attilio@FreeBSD.org>

Make the newbus subsystem Giant free by adding the new newbus sxlock.
The newbus lock is responsible for protecting newbus internIal structures,
device states and devclass flags. It is necessary to hold it when all
such datas are accessed. For the other operations, softc locking should
ensure enough protection to avoid races.

Newbus lock is automatically held when virtual operations on the device
and bus are invoked when loading the driver or when the suspend/resume
take place. For other 'spourious' operations trying to access/modify
the newbus topology, newbus lock needs to be automatically acquired and
dropped.

For the moment Giant is also acquired in some key point (modules subsystem)
in order to avoid problems before the 8.0 release as module handlers could
make assumptions about it. This Giant locking should go just after
the release happens.

Please keep in mind that the public interface can be expanded in order
to provide more support, if there are really necessities at some point
and also some bugs could arise as long as the patch needs a bit of
further testing.

Bump __FreeBSD_version in order to reflect the newbus lock introduction.

Reviewed by: ed, hps, jhb, imp, mav, scottl
No answer by: ariff, thompsa, yongari
Tested by: pho,
G. Trematerra <giovanni dot trematerra at gmail dot com>,
Brandon Gooch <jamesbrandongooch at gmail dot com>
Sponsored by: Yahoo! Incorporated
Approved by: re (ksmith)


# dddb25f9 29-Jul-2009 Alfred Perlstein <alfred@FreeBSD.org>

USB CORE:
- Add minimum polling support to drive UMASS
and UKBD in case of panic.
- Add extra check to ukbd probe to fix problem about
mouse devices attaching like keyboards.
- P4 ID: 166148

Submitted by: hps
Approved by: re


# ed6d949a 22-Jun-2009 Andrew Thompson <thompsa@FreeBSD.org>

- Make struct usb_xfer opaque so that drivers can not access the internals
- Reduce the number of headers needed for a usb driver, the common case is just usb.h and usbdi.h


# a593f6b8 14-Jun-2009 Andrew Thompson <thompsa@FreeBSD.org>

s/usb2_/usb_|usbd_/ on all function names for the USB stack.


# a8675cae 12-Jun-2009 Andrew Thompson <thompsa@FreeBSD.org>

Make variables static where appropriate.

Found by: cscout


# 191e179a 12-Jun-2009 Andrew Thompson <thompsa@FreeBSD.org>

Check for a keyboard HID report in addition to the interface class so devices
such as the Yubikey attach.

Submitted by: Hans Petter Selasky
Reported by: Jeremy Faulkner


# b7d3e242 04-Jun-2009 Andrew Thompson <thompsa@FreeBSD.org>

Remove duplicate variable setting.

Spotted by: Sylvestre Gallon


# 7b8b6d35 02-Jun-2009 Andrew Thompson <thompsa@FreeBSD.org>

Staticize ukbd_detach and fix indentation.

Submitted by: Sylvestre Gallon


# e0a69b51 29-May-2009 Andrew Thompson <thompsa@FreeBSD.org>

s/usb2_/usb_/ on all typedefs for the USB stack.


# 760bc48e 28-May-2009 Andrew Thompson <thompsa@FreeBSD.org>

s/usb2_/usb_/ on all C structs for the USB stack.


# fa64b944 27-May-2009 Andrew Thompson <thompsa@FreeBSD.org>

Add support for the Apple MacBook Pro keyboard
- add key mappings for fn keys
- byte swapping for certain models
- Fix leds for keyboards which require an ID byte for the HID output structures

Submitted by: Hans Petter Selasky


# 9360ae40 20-May-2009 Andrew Thompson <thompsa@FreeBSD.org>

Rename the usb sysctl tree from hw.usb2.* back to hw.usb.*.

Submitted by: Hans Petter Selasky


# f29a0724 20-May-2009 Andrew Thompson <thompsa@FreeBSD.org>

- rename usb2_mode to usb_mode [1]
- change variable types to use the enum

Submitted by: Hans Petter Selasky [1]


# 4eae601e 05-Apr-2009 Andrew Thompson <thompsa@FreeBSD.org>

MFp4 //depot/projects/usb@159909

- make usb2_power_mask_t 16-bit
- remove "usb2_config_sub" structure from "usb2_config". To compensate for this
"usb2_config" has a new field called "usb_mode" which select for which mode
the current xfer entry is active. Options are: a) Device mode only b) Host
mode only (default-by-zero) c) Both modes. This change was scripted using
the following sed script: "s/\.mh\././g".
- the standard packet size table in "usb_transfer.c" is now a function, hence
the code for the function uses less memory than the table itself.

Submitted by: Hans Petter Selasky


# 9aef556d 01-Mar-2009 Andrew Thompson <thompsa@FreeBSD.org>

Rename the ushub device class back to uhub as it was in the old usb stack,
moused(8) looks for "uhub/ums" to decide if needs to load the module.

Reported by: Garrett Cooper


# 02ac6454 23-Feb-2009 Andrew Thompson <thompsa@FreeBSD.org>

Move the new USB stack into its new home.