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:
@@ -703,6 +703,9 @@ atkbd_read_char(keyboard_t *kbd, int wait)
|
|||||||
evdev_sync(state->ks_evdev);
|
evdev_sync(state->ks_evdev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (state->ks_evdev != NULL && evdev_is_grabbed(state->ks_evdev))
|
||||||
|
return (NOKEY);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* return the byte as is for the K_RAW mode */
|
/* return the byte as is for the K_RAW mode */
|
||||||
|
|||||||
@@ -1097,6 +1097,8 @@ evdev_release_client(struct evdev_dev *evdev, struct evdev_client *client)
|
|||||||
bool
|
bool
|
||||||
evdev_is_grabbed(struct evdev_dev *evdev)
|
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
|
* The function is intended to be called from evdev-unrelated parts of
|
||||||
* code like syscons-compatible parts of mouse and keyboard drivers.
|
* code like syscons-compatible parts of mouse and keyboard drivers.
|
||||||
|
|||||||
@@ -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_push_key(sc->sc_evdev, key->evcode, pressed);
|
||||||
evdev_sync(sc->sc_evdev);
|
evdev_sync(sc->sc_evdev);
|
||||||
}
|
}
|
||||||
|
if (evdev_is_grabbed(sc->sc_evdev)) {
|
||||||
|
GPIOKEYS_UNLOCK(sc);
|
||||||
|
return;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if (key->keycode != GPIOKEY_NONE) {
|
if (key->keycode != GPIOKEY_NONE) {
|
||||||
code = key->keycode & SCAN_KEYCODE_MASK;
|
code = key->keycode & SCAN_KEYCODE_MASK;
|
||||||
|
|||||||
@@ -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)
|
if (evdev_rcpt_mask & EVDEV_RCPT_HW_KBD && sc->sc_evdev != NULL)
|
||||||
evdev_push_event(sc->sc_evdev, EV_KEY,
|
evdev_push_event(sc->sc_evdev, EV_KEY,
|
||||||
evdev_hid2key(KEY_INDEX(key)), !(key & KEY_RELEASE));
|
evdev_hid2key(KEY_INDEX(key)), !(key & KEY_RELEASE));
|
||||||
|
if (sc->sc_evdev != NULL && evdev_is_grabbed(sc->sc_evdev))
|
||||||
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
tail = (sc->sc_inputtail + 1) % HKBD_IN_BUF_SIZE;
|
tail = (sc->sc_inputtail + 1) % HKBD_IN_BUF_SIZE;
|
||||||
@@ -541,6 +543,8 @@ hkbd_interrupt(struct hkbd_softc *sc)
|
|||||||
#ifdef EVDEV_SUPPORT
|
#ifdef EVDEV_SUPPORT
|
||||||
if (evdev_rcpt_mask & EVDEV_RCPT_HW_KBD && sc->sc_evdev != NULL)
|
if (evdev_rcpt_mask & EVDEV_RCPT_HW_KBD && sc->sc_evdev != NULL)
|
||||||
evdev_sync(sc->sc_evdev);
|
evdev_sync(sc->sc_evdev);
|
||||||
|
if (sc->sc_evdev != NULL && evdev_is_grabbed(sc->sc_evdev))
|
||||||
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* wakeup keyboard system */
|
/* wakeup keyboard system */
|
||||||
|
|||||||
@@ -340,6 +340,8 @@ hvkbd_read_char_locked(keyboard_t *kbd, int wait)
|
|||||||
evdev_sync(sc->ks_evdev);
|
evdev_sync(sc->ks_evdev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (sc->ks_evdev != NULL && evdev_is_grabbed(sc->ks_evdev))
|
||||||
|
return (NOKEY);
|
||||||
#endif
|
#endif
|
||||||
++kbd->kb_count;
|
++kbd->kb_count;
|
||||||
DEBUG_HVKBD(kbd, "read scan: 0x%x\n", scancode);
|
DEBUG_HVKBD(kbd, "read scan: 0x%x\n", scancode);
|
||||||
|
|||||||
@@ -715,6 +715,9 @@ kbdmux_read_char(keyboard_t *kbd, int wait)
|
|||||||
evdev_sync(state->ks_evdev);
|
evdev_sync(state->ks_evdev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (state->ks_evdev != NULL && evdev_is_grabbed(state->ks_evdev))
|
||||||
|
return (NOKEY);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* return the byte as is for the K_RAW mode */
|
/* return the byte as is for the K_RAW mode */
|
||||||
|
|||||||
@@ -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)
|
if (evdev_rcpt_mask & EVDEV_RCPT_HW_KBD && sc->sc_evdev != NULL)
|
||||||
evdev_push_event(sc->sc_evdev, EV_KEY,
|
evdev_push_event(sc->sc_evdev, EV_KEY,
|
||||||
evdev_hid2key(KEY_INDEX(key)), !(key & KEY_RELEASE));
|
evdev_hid2key(KEY_INDEX(key)), !(key & KEY_RELEASE));
|
||||||
|
if (sc->sc_evdev != NULL && evdev_is_grabbed(sc->sc_evdev))
|
||||||
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (sc->sc_inputs < UKBD_IN_BUF_SIZE) {
|
if (sc->sc_inputs < UKBD_IN_BUF_SIZE) {
|
||||||
@@ -562,6 +564,8 @@ ukbd_interrupt(struct ukbd_softc *sc)
|
|||||||
#ifdef EVDEV_SUPPORT
|
#ifdef EVDEV_SUPPORT
|
||||||
if (evdev_rcpt_mask & EVDEV_RCPT_HW_KBD && sc->sc_evdev != NULL)
|
if (evdev_rcpt_mask & EVDEV_RCPT_HW_KBD && sc->sc_evdev != NULL)
|
||||||
evdev_sync(sc->sc_evdev);
|
evdev_sync(sc->sc_evdev);
|
||||||
|
if (sc->sc_evdev != NULL && evdev_is_grabbed(sc->sc_evdev))
|
||||||
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* wakeup keyboard system */
|
/* wakeup keyboard system */
|
||||||
|
|||||||
Reference in New Issue
Block a user