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:	4a0db5e292
Tested by:	corvink
Differential revision:	https://reviews.freebsd.org/D30542
This commit is contained in:
Vladimir Kondratyev 2022-11-19 02:54:46 +03:00
parent d487cba33d
commit 183088934a
7 changed files with 22 additions and 0 deletions

View File

@ -703,6 +703,9 @@ atkbd_read_char(keyboard_t *kbd, int wait)
evdev_sync(state->ks_evdev);
}
}
if (state->ks_evdev != NULL && evdev_is_grabbed(state->ks_evdev))
return (NOKEY);
#endif
/* return the byte as is for the K_RAW mode */

View File

@ -1097,6 +1097,8 @@ evdev_release_client(struct evdev_dev *evdev, struct evdev_client *client)
bool
evdev_is_grabbed(struct evdev_dev *evdev)
{
if (kdb_active || SCHEDULER_STOPPED())
return (false);
/*
* The function is intended to be called from evdev-unrelated parts of
* code like syscons-compatible parts of mouse and keyboard drivers.

View File

@ -194,6 +194,10 @@ gpiokeys_key_event(struct gpiokeys_softc *sc, struct gpiokey *key, int pressed)
evdev_push_key(sc->sc_evdev, key->evcode, pressed);
evdev_sync(sc->sc_evdev);
}
if (evdev_is_grabbed(sc->sc_evdev)) {
GPIOKEYS_UNLOCK(sc);
return;
}
#endif
if (key->keycode != GPIOKEY_NONE) {
code = key->keycode & SCAN_KEYCODE_MASK;

View File

@ -391,6 +391,8 @@ hkbd_put_key(struct hkbd_softc *sc, uint32_t key)
if (evdev_rcpt_mask & EVDEV_RCPT_HW_KBD && sc->sc_evdev != NULL)
evdev_push_event(sc->sc_evdev, EV_KEY,
evdev_hid2key(KEY_INDEX(key)), !(key & KEY_RELEASE));
if (sc->sc_evdev != NULL && evdev_is_grabbed(sc->sc_evdev))
return;
#endif
tail = (sc->sc_inputtail + 1) % HKBD_IN_BUF_SIZE;
@ -541,6 +543,8 @@ hkbd_interrupt(struct hkbd_softc *sc)
#ifdef EVDEV_SUPPORT
if (evdev_rcpt_mask & EVDEV_RCPT_HW_KBD && sc->sc_evdev != NULL)
evdev_sync(sc->sc_evdev);
if (sc->sc_evdev != NULL && evdev_is_grabbed(sc->sc_evdev))
return;
#endif
/* wakeup keyboard system */

View File

@ -340,6 +340,8 @@ hvkbd_read_char_locked(keyboard_t *kbd, int wait)
evdev_sync(sc->ks_evdev);
}
}
if (sc->ks_evdev != NULL && evdev_is_grabbed(sc->ks_evdev))
return (NOKEY);
#endif
++kbd->kb_count;
DEBUG_HVKBD(kbd, "read scan: 0x%x\n", scancode);

View File

@ -715,6 +715,9 @@ kbdmux_read_char(keyboard_t *kbd, int wait)
evdev_sync(state->ks_evdev);
}
}
if (state->ks_evdev != NULL && evdev_is_grabbed(state->ks_evdev))
return (NOKEY);
#endif
/* return the byte as is for the K_RAW mode */

View File

@ -394,6 +394,8 @@ ukbd_put_key(struct ukbd_softc *sc, uint32_t key)
if (evdev_rcpt_mask & EVDEV_RCPT_HW_KBD && sc->sc_evdev != NULL)
evdev_push_event(sc->sc_evdev, EV_KEY,
evdev_hid2key(KEY_INDEX(key)), !(key & KEY_RELEASE));
if (sc->sc_evdev != NULL && evdev_is_grabbed(sc->sc_evdev))
return;
#endif
if (sc->sc_inputs < UKBD_IN_BUF_SIZE) {
@ -562,6 +564,8 @@ ukbd_interrupt(struct ukbd_softc *sc)
#ifdef EVDEV_SUPPORT
if (evdev_rcpt_mask & EVDEV_RCPT_HW_KBD && sc->sc_evdev != NULL)
evdev_sync(sc->sc_evdev);
if (sc->sc_evdev != NULL && evdev_is_grabbed(sc->sc_evdev))
return;
#endif
/* wakeup keyboard system */