[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAPk366QgcOYPZJXM46o3Gn8ksFYYoNwJvnunUe7y0aLNgJuSRg@mail.gmail.com>
Date: Tue, 26 Nov 2019 10:02:18 +0100
From: Mateusz Holenko <mholenko@...micro.com>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Rob Herring <robh+dt@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Jiri Slaby <jslaby@...e.com>, devicetree@...r.kernel.org,
"open list:SERIAL DRIVERS" <linux-serial@...r.kernel.org>,
Stafford Horne <shorne@...il.com>,
Karol Gugala <kgugala@...micro.com>,
Mauro Carvalho Chehab <mchehab+samsung@...nel.org>,
"David S. Miller" <davem@...emloft.net>,
"Paul E. McKenney" <paulmck@...ux.ibm.com>,
Filip Kokosinski <fkokosinski@...ernships.antmicro.com>,
Joel Stanley <joel@....id.au>,
Jonathan Cameron <Jonathan.Cameron@...wei.com>,
Maxime Ripard <mripard@...nel.org>,
Shawn Guo <shawnguo@...nel.org>,
Heiko Stuebner <heiko@...ech.de>,
Sam Ravnborg <sam@...nborg.org>,
Icenowy Zheng <icenowy@...c.io>,
Laurent Pinchart <laurent.pinchart@...asonboard.com>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 2/4] litex: add common LiteX header
śr., 20 lis 2019 o 20:26 Greg Kroah-Hartman
<gregkh@...uxfoundation.org> napisał(a):
>
> On Wed, Oct 23, 2019 at 11:47:04AM +0200, Mateusz Holenko wrote:
> > +#ifdef __LITTLE_ENDIAN
> > +# define LITEX_READ_REG(addr) ioread32(addr)
> > +# define LITEX_READ_REG_OFF(addr, off) ioread32(addr + off)
> > +# define LITEX_WRITE_REG(val, addr) iowrite32(val, addr)
> > +# define LITEX_WRITE_REG_OFF(val, addr, off) iowrite32(val, addr + off)
> > +#else
> > +# define LITEX_READ_REG(addr) ioread32be(addr)
> > +# define LITEX_READ_REG_OFF(addr, off) ioread32be(addr + off)
> > +# define LITEX_WRITE_REG(val, addr) iowrite32be(val, addr)
> > +# define LITEX_WRITE_REG_OFF(val, addr, off) iowrite32be(val, addr + off)
> > +#endif
>
> I just noticed this.
>
> Ick, this is not good. You will run into problems in the future with
> this, I can guarantee it. What about systems where the CPU is one
> endian and the hardware in the other? It will happen trust us.
As mentioned in the previous comment, LiteX CSRs are guaranteed to be
always little-endian - this includes configurations with both
big-endian and little-endian CPUs.
The aim of including the ifdef section was exactly to target situation
where endianness is different for CPU and devices. As such this
approach *should* work.
> Make these real functions (inline is nice) and pass in the pointer to
> the device so you can test for it and call the correct function based on
> the cpu/hardware type.
>
> And what about bitfields? What endian are they for your
> system/hardware?
>
> Almost no kernel code should EVER be testing __LITTLE_ENDIAN, don't add
> to it as it is not a good idea.
If I understand correctly, you suggest to replace compile-time
ifdefing with probing the endianness in the runtime (by reading some
register that should return a known value, say 1, and testing how bits
are arranged). This is a good idea, as it protects against breaking an
always-little-endian property of LiteX CSRs in the future.
I'll include this in the next version of the patchset.
> thanks,
>
> greg k-h
Thanks for your comments!
--
Mateusz Holenko
Antmicro Ltd | www.antmicro.com
Roosevelta 22, 60-829 Poznan, Poland
Powered by blists - more mailing lists