Re: [PATCH v9 04/20] gpio: uapi: define uAPI v2

From: Kent Gibson
Date: Tue Sep 22 2020 - 06:07:17 EST


On Tue, Sep 22, 2020 at 11:50:51AM +0200, Bartosz Golaszewski wrote:
> On Tue, Sep 22, 2020 at 9:41 AM Arnd Bergmann <arnd@xxxxxxxx> wrote:
> >
> > On Tue, Sep 22, 2020 at 4:34 AM Kent Gibson <warthog618@xxxxxxxxx> wrote:
> > > +/**
> > > + * struct gpio_v2_line_attribute - a configurable attribute of a line
> > > + * @id: attribute identifier with value from &enum gpio_v2_line_attr_id
> > > + * @padding: reserved for future use and must be zero filled
> > > + * @flags: if id is GPIO_V2_LINE_ATTR_ID_FLAGS, the flags for the GPIO
> > > + * line, with values from enum gpio_v2_line_flag, such as
> > > + * GPIO_V2_LINE_FLAG_ACTIVE_LOW, GPIO_V2_LINE_FLAG_OUTPUT etc, OR:ed
> > > + * together. This overrides the default flags contained in the &struct
> > > + * gpio_v2_line_config for the associated line.
> > > + * @values: if id is GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES, a bitmap
> > > + * containing the values to which the lines will be set, with each bit
> > > + * number corresponding to the index into &struct
> > > + * gpio_v2_line_request.offsets.
> > > + * @debounce_period_us: if id is GPIO_V2_LINE_ATTR_ID_DEBOUNCE, the desired
> > > + * debounce period, in microseconds
> > > + */
> > > +struct gpio_v2_line_attribute {
> > > + __u32 id;
> > > + __u32 padding;
> > > + union {
> > > + __aligned_u64 flags;
> > > + __aligned_u64 values;
> > > + __u32 debounce_period_us;
> > > + };
> > > +};
> >
> > Having different-sized members in the union makes it hard for
> > something like strace to print the contents. How about just making
> > them all __aligned_u64 even when 32 bits are sufficient?
> >
>
> Ah yes, adding support for GPIO ioctl()'s to strace has been on my
> TODO list for 3 years now. :(
>

Great - you beat me to it - I was going to ask if we could fix strace
;-). If it can be taught the id/union semantics I'd rather do that,
so we could then also format the 64-bit values appropriately.
e.g. flags and values are both bitmaps but the bits are interpreted
very differently.

Cheers,
Kent.