From: Michael Buesch <mb@bu3sch.de>
To: Andi Kleen <andi@firstfloor.org>
Cc: Jeff Garzik <jeff@garzik.org>,
ggrundstrom@neteffect.com, rdreier@cisco.com,
ewg@lists.openfabrics.org, netdev@vger.kernel.org
Subject: Re: [PATCH 2/14] nes: device structures and defines
Date: Wed, 8 Aug 2007 15:48:25 +0200 [thread overview]
Message-ID: <200708081548.25399.mb@bu3sch.de> (raw)
In-Reply-To: <20070808133850.GE14419@one.firstfloor.org>
On Wednesday 08 August 2007 15:38:50 Andi Kleen wrote:
> On Wed, Aug 08, 2007 at 03:28:33PM +0200, Michael Buesch wrote:
> > On Wednesday 08 August 2007 15:08:28 Andi Kleen wrote:
> > > On Wed, Aug 08, 2007 at 03:02:35PM +0200, Michael Buesch wrote:
> > > > On Wednesday 08 August 2007 14:55:11 Andi Kleen wrote:
> > > > > On Wed, Aug 08, 2007 at 01:50:35PM +0200, Michael Buesch wrote:
> > > > > > On Wednesday 08 August 2007 14:38:10 Andi Kleen wrote:
> > > > > > > Jeff Garzik <jeff@garzik.org> writes:
> > > > > > > > > + val, reg_index, addr, addr+4); */
> > > > > > > > > + writel(cpu_to_le32(reg_index), addr);
> > > > > > > > > + writel(cpu_to_le32(val),(u8 *)addr + 4);
> > > > > > > >
> > > > > > > > wrong -- endian conversion macros not needed with writel()
> >
> > > > Fact is that we do _not_ need cpu_to_le32 with writel.
> > >
> > > We do on a big endian platform if the register is LE. I assume that's the case
> > > on this hardware.
> >
> > That is not true.
> > writeX does automatically convert to bus-endian.
> > Which, in case of the PCI bus, is little endian.
> > So if your register is LE (which it is most likely), you don't
> > need any conversion. If your register is BE (which I very much doubt),
> > then you need swab32().
> > In _no_ case you need cpu_to_xx().
>
> Hmm, I checked a couple of BE architectures and none seem to convert explicitely.
That depends on the arch.
Look at this from ppc, for example:
184 static inline void writel(__u32 b, volatile void __iomem *addr)
185 {
186 out_le32(addr, b);
187 }
out_le32 writes a little endian value. So it converts it.
Also note that b is __u32. Sparse would complain, if someone used cpu_to_xx
on it.
> But ok it's possible that their PCI bridges convert. I'll take your
> word for it although it sounds somewhat dubious.
>
> However if that's true then there are quite some drivers wrong:
>
> % grep -r write[bwl]\(cpu_to * | wc -l
> 57
Yeah, seems so.
Here comes an example (with 16bit values)
Little endian register
LittleEndian arch BigEngian arch
value 0xBBAA 0xAABB
writew 0xBBAA 0xAABB
on bus 0xBBAA 0xBBAA
on dev 0xBBAA 0xBBAA
Big endian register
LittleEndian arch BigEngian arch
value 0xBBAA 0xAABB
swab16 0xAABB 0xBBAA
writew 0xAABB 0xBBAA
on bus 0xAABB 0xAABB
on dev 0xAABB 0xAABB
I hope I got it right. :)
Same result on every arch.
Most hardware has little endian registers. Some can switch
endianess based on some bit, too. So in case of a BE register that
bit has to be flipped, or if not possible swabX() has to be used.
--
Greetings Michael.
next prev parent reply other threads:[~2007-08-08 13:49 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-08 0:45 [PATCH 2/14] nes: device structures and defines ggrundstrom
2007-08-08 1:13 ` Jeff Garzik
2007-08-08 12:38 ` Andi Kleen
2007-08-08 11:50 ` Michael Buesch
2007-08-08 12:55 ` Andi Kleen
2007-08-08 13:02 ` Michael Buesch
2007-08-08 13:08 ` Andi Kleen
2007-08-08 13:28 ` Michael Buesch
2007-08-08 13:38 ` Andi Kleen
2007-08-08 13:48 ` Michael Buesch [this message]
2007-08-08 13:55 ` Michael Buesch
2007-08-08 16:18 ` Roland Dreier
2007-08-08 16:25 ` Jeff Garzik
2007-08-08 16:30 ` Michael Buesch
2007-08-08 16:33 ` Jeff Garzik
2007-08-08 16:43 ` Michael Buesch
2007-08-08 16:46 ` Roland Dreier
2007-08-08 16:57 ` akepner
2007-08-08 16:59 ` Jeff Garzik
2007-08-08 17:34 ` Michael Buesch
2007-08-08 19:40 ` Jeff Garzik
2007-08-08 16:39 ` Roland Dreier
2007-08-08 16:19 ` Jeff Garzik
2007-08-08 22:04 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200708081548.25399.mb@bu3sch.de \
--to=mb@bu3sch.de \
--cc=andi@firstfloor.org \
--cc=ewg@lists.openfabrics.org \
--cc=ggrundstrom@neteffect.com \
--cc=jeff@garzik.org \
--cc=netdev@vger.kernel.org \
--cc=rdreier@cisco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.