[PATCH v2 00/11] gpiolib: add an ioctl() for monitoring line status changes

From: Bartosz Golaszewski
Date: Wed Dec 04 2019 - 10:59:20 EST


From: Bartosz Golaszewski <bgolaszewski@xxxxxxxxxxxx>

When discussing the recent user-space changes with Kent and while working
on dbus API for libgpiod I noticed that we really don't have any way of
keeping the line info synchronized between the kernel and user-space
processes. We can of course periodically re-read the line information or
even do it every time we want to read a property but this isn't optimal.

This series adds a new ioctl() that allows user-space to set up a watch on
the GPIO chardev file-descriptor which can then be polled for events
emitted by the kernel when the line is requested, released or its status
changed. This of course doesn't require the line to be requested. Multiple
user-space processes can watch the same lines.

The first couple patches just fix some issues I noticed when implementing
the new interface. Patch 10/11 provides the actual ioctl() implementation
while patch 11/11 adds a simple user-space program to tools that can be
used to watch the line info changes.

v1: https://lkml.org/lkml/2019/11/27/327

v1 -> v2:
- rework the main patch of the series: re-use the existing file-descriptor
associated with an open character device
- add a patch adding a debug message when the line event kfifo is full and
we're discarding another event
- rework the locking mechanism for lineevent kfifo: reuse the spinlock
from the waitqueue structure
- other minor changes

Bartosz Golaszewski (11):
gpiolib: use 'unsigned int' instead of 'unsigned' in gpio_set_config()
gpiolib: have a single place of calling set_config()
gpiolib: convert the type of hwnum to unsigned int in
gpiochip_get_desc()
gpiolib: use gpiochip_get_desc() in linehandle_create()
gpiolib: use gpiochip_get_desc() in lineevent_create()
gpiolib: use gpiochip_get_desc() in gpio_ioctl()
gpiolib: rework the locking mechanism for lineevent kfifo
gpiolib: emit a debug message when adding events to a full kfifo
gpiolib: provide a dedicated function for setting lineinfo
gpiolib: add new ioctl() for monitoring changes in line info
tools: gpio: implement gpio-watch

drivers/gpio/gpiolib.c | 378 ++++++++++++++++++++++++++----------
drivers/gpio/gpiolib.h | 5 +-
include/linux/gpio/driver.h | 3 +-
include/uapi/linux/gpio.h | 24 +++
tools/gpio/.gitignore | 1 +
tools/gpio/Build | 1 +
tools/gpio/Makefile | 11 +-
tools/gpio/gpio-watch.c | 112 +++++++++++
8 files changed, 434 insertions(+), 101 deletions(-)
create mode 100644 tools/gpio/gpio-watch.c

--
2.23.0