Skip to content

Commit

Permalink
Provide userland notification of gpio pin changes ("userland gpio int…
Browse files Browse the repository at this point in the history
…errupts").

This is an import of the Google Summer of Code 2018 project completed by
Christian Kramer (and, sadly, ignored by us for two years now).  The goals
stated for that project were:

    FreeBSD already has support for interrupts implemented in the GPIO
    controller drivers of several SoCs, but there are no interfaces to take
    advantage of them out of user space yet. The goal of this work is to
    implement such an interface by providing descriptors which integrate
    with the common I/O system calls and multiplexing mechanisms.

The initial imported code supports the following functionality:

 -  A kernel driver that provides an interface to the user space; the
    existing gpioc(4) driver was enhanced with this functionality.
 -  Implement support for the most common I/O system calls / multiplexing
    mechanisms:
     -  read() Places the pin number on which the interrupt occurred in the
        buffer. Blocking and non-blocking behaviour supported.
     -	poll()/select()
     -	kqueue()
     -	signal driven I/O. Posting SIGIO when the O_ASYNC was set.
 -  Many-to-many relationship between pins and file descriptors.
     -  A file descriptor can monitor several GPIO pins.
     -  A GPIO pin can be monitored by multiple file descriptors.
 -  Integration with gpioctl and libgpio.

I added some fixes (mostly to locking) and feature enhancements on top of
the original gsoc code.  The feature ehancements allow the user to choose
between detailed and summary event reporting.  Detailed reporting provides
a record describing each pin change event.  Summary reporting provides the
time of the first and last change of each pin, and a count of how many times
it changed state since the last read(2) call.  Another enhancement allows
the recording of multiple state change events on multiple pins between each
call to read(2) (the original code would track only a single event at a time).

The phabricator review for these changes timed out without approval, but I
cite it below anyway, because the review contains a series of diffs that
show how I evolved the code from its original state in Christian's github
repo for the gsoc project to what is being commited here.  (In effect,
the phab review extends the VC history back to the original code.)

Submitted by:	Christian Kramer
Obtained from:	https://github.com/ckraemer/freebsd/tree/gsoc2018
Differential Revision:	https://reviews.freebsd.org/D27398
  • Loading branch information
Ian Lepore authored and Ian Lepore committed Dec 12, 2020
1 parent 0d2dcf2 commit ff3468a
Show file tree
Hide file tree
Showing 7 changed files with 1,634 additions and 78 deletions.
9 changes: 9 additions & 0 deletions sys/dev/gpio/gpiobus.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ gpio_check_flags(uint32_t caps, uint32_t flags)
/* Cannot mix pull-up/pull-down together. */
if (flags & GPIO_PIN_PULLUP && flags & GPIO_PIN_PULLDOWN)
return (EINVAL);
/* Cannot mix output and interrupt flags together */
if (flags & GPIO_PIN_OUTPUT && flags & GPIO_INTR_MASK)
return (EINVAL);
/* Only one interrupt flag can be defined at once */
if ((flags & GPIO_INTR_MASK) & ((flags & GPIO_INTR_MASK) - 1))
return (EINVAL);
/* The interrupt attached flag cannot be set */
if (flags & GPIO_INTR_ATTACHED)
return (EINVAL);

return (0);
}
Expand Down
Loading

0 comments on commit ff3468a

Please sign in to comment.