[PATCH 0/8] gpiolib: add an ioctl() for monitoring line status changes

From: Bartosz Golaszewski
Date: Wed Nov 27 2019 - 08:35:25 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 retrieve a
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 7/8 provides the actual ioctl() implementation
while patch 8/8 adds a simple user-space program to tools that can be used
to watch the line info changes.

Bartosz Golaszewski (8):
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: actually protect the line event kfifo with mutex
gpiolib: add new ioctl() for monitoring changes in line info
tools: gpio: implement gpio-watch

drivers/gpio/gpiolib.c | 267 +++++++++++++++++++++++++++++++++---
drivers/gpio/gpiolib.h | 4 +-
include/linux/gpio/driver.h | 3 +-
include/uapi/linux/gpio.h | 36 +++++
tools/gpio/.gitignore | 1 +
tools/gpio/Build | 1 +
tools/gpio/Makefile | 11 +-
tools/gpio/gpio-watch.c | 114 +++++++++++++++
8 files changed, 415 insertions(+), 22 deletions(-)
create mode 100644 tools/gpio/gpio-watch.c

--
2.23.0