Re: [PATCH 05/16] bus: mhi: core: Add support for ringing channel/event ring doorbells

From: Greg KH
Date: Mon Jan 27 2020 - 02:21:32 EST


On Mon, Jan 27, 2020 at 12:40:52PM +0530, Manivannan Sadhasivam wrote:
> On Sat, Jan 25, 2020 at 02:46:31PM +0100, Greg KH wrote:
> > On Fri, Jan 24, 2020 at 03:51:12PM -0700, Jeffrey Hugo wrote:
> > > > +struct mhi_event_ctxt {
> > > > + u32 reserved : 8;
> > > > + u32 intmodc : 8;
> > > > + u32 intmodt : 16;
> > > > + u32 ertype;
> > > > + u32 msivec;
> > > > +
> > > > + u64 rbase __packed __aligned(4);
> > > > + u64 rlen __packed __aligned(4);
> > > > + u64 rp __packed __aligned(4);
> > > > + u64 wp __packed __aligned(4);
> > > > +};
> > >
> > > This is the struct that is shared with the device, correct? Surely it needs
> > > to be packed then? Seems like you'd expect some padding between msivec and
> > > rbase on a 64-bit system otherwise, which is probably not intended.
> > >
> > > Also I strongly dislike bitfields in structures which are shared with
> > > another system since the C specification doesn't define how they are
> > > implemented, therefore you can run into issues where different compilers
> > > decide to implement the actual backing memory differently. I know its less
> > > convinent, but I would prefer the use of bitmasks for these fields.
> >
> > You have to use bitmasks in order for all endian cpus to work properly
> > here, so that needs to be fixed.
> >
>
> Okay.
>
> > Oh, and if these values are in hardware, then the correct types also
> > need to be used (i.e. __u32 and __u64).
> >
>
> I thought the __* prefix types are only for sharing with userspace...
> Could you please clarify why it is needed here?

It crosses the kernel boundry, so it needs to use those types. This is
not a new requirement, has been there for decades.

greg k-h