Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: ulli.kroll@googlemail.com (Hans Ulli Kroll)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] ARM: Gemini: Add support for PCI BUS
Date: Wed, 1 Dec 2010 12:52:28 +0100 (CET)	[thread overview]
Message-ID: <alpine.LNX.2.00.1012011244120.8521@localhost.localdomain> (raw)
In-Reply-To: <AANLkTinABzeM9Q+5PvvLX7HKYtDrig=nRHY7KMapJD5k@mail.gmail.com>



On Tue, 30 Nov 2010, Paulius Zaleckas wrote:

> On Tue, Nov 30, 2010 at 10:15 AM, Hans Ulli Kroll
> <ulli.kroll@googlemail.com> wrote:
> >
> >
> > On Mon, 29 Nov 2010, Paulius Zaleckas wrote:
> >
> >> On 11/29/2010 10:02 PM, Arnd Bergmann wrote:
> >> > On Monday 29 November 2010 19:52:55 Paulius Zaleckas wrote:
> >> > > On 11/29/2010 06:45 PM, Arnd Bergmann wrote:
> >> > > > There are many differences between readl and __raw_readl, including
> >> > > >
> >> > > > * __raw_readl does not have barriers and does not serialize with
> >> > > > ? ? spinlocks, so it breaks on out-of-order CPUs.
> >> > > > * __raw_readl does not have a specific endianess, while readl is
> >> > > > ? ? fixed little-endian, just as the hardware is in this case.
> >> > > > ? ? The endian-conversion is a NOP on little-endian ARM, but required
> >> > > > ? ? if you actually run on a big-endian ARM (you don't).
> >> > > > * __raw_readl may not be atomic, gcc is free to split the access
> >> > > > ? ? into byte wise reads (it normally does not, unless you mark
> >> > > > ? ? the pointer __attribute__((packed))).
> >> > > >
> >> > > > In essence, it is almost never a good idea to use __raw_readl, and
> >> > > > the double underscores should tell you so.
> >> > >
> >> > > You are wrong:
> >> > >
> >> > > Since CONFIG_ARM_DMA_MEM_BUFFERABLE is NOT defined for FA526 core,
> >> > > no barriers are in use when using readl. It just translates into
> >> > > le32_to_cpu(__raw_readl(x)). Now this CPU has physical pin for endianess
> >> > > configuration and if you will chose big-endian you will fail to read
> >> > > internal registers, because they ALSO change endianess and le32_to_cpu()
> >> > > will screw it. However it is different when accessing registers through
> >> > > PCI bus, then you need to use readl().
> >> >
> >> > Ok, I only checked that the platform does not support big-endian Linux
> >> > kernel, not if the HW designers screwed up their registers, sorry about
> >> > that.
> >> >
> >> > The other points are of course still valid: If the code ever gets
> >> > used on an out of order CPU, it is broken. More importantly, if someone
> >> > looks at the code as an example for writing another PCI support code,
> >> > it may end up getting copied to some place where it ends up causing
> >> > trouble.
> >> >
> >> > The typical way to deal with mixed-endian hardware reliably is to have
> >> > a header file containing code like
> >> >
> >> > #ifdef CONFIG_GEMINI_BIG_ENDIAN_IO
> >> > #define gemini_readl(x) __swab32(readl(x))
> >> > #define ...
> >> > #else
> >> > #define gemini_readl(x) readl(x))
> >> > #endif
> >> >
> >> > This also takes care of the (not as unlikely as you'd hope) case that
> >> > the next person reusing the PCI hardware wires its endianess different
> >> > from the CPU endianess.
> >>
> >> Actually I am not very sure how CPU works in big endian mode :)
> >> I have never tried it and I think only some guys who made it did that.
> >> So readl will work for 99.99% of cases. In datasheet they say that:
> >> "All registers in Gemini use Little Endian and must be accessed by aligned
> >> 32-bit word operations. The bus connection interface logic provides an Endian
> >> Conversion function."
> >> For me it looks like it can mean whatever you want :)
> >>
> >
> > I think the endianes pin switched only the cpu, not the hardware
> > registers.
> 
> Yes, but original driver used readl/writel and it does le32_to_cpu,
> so that structure definition is just reversing it.
> If you will use __raw_readl/__raw_writel than there will be no need
> for this redefinition.
> 
> > Here is some sample code from the ethernet devive on Gemini
> > typedef union
> > {
> > ? ? ? ?unsigned int bits32;
> > ? ? ? ?struct bit
> > ? ? ? ?{
> > #if (BIG_ENDIAN==1)
> > ? ? ? ? ? ? ? ?unsigned int reserved ? ? ? ? ? : 15; ? // bit 31:17
> > ? ? ? ? ? ? ? ?unsigned int v_bit_mode ? ? ? ? : 1; ? ?// bit 16
> > ? ? ? ? ? ? ? ?unsigned int device_id ? ? ? ? ?: 12; ? // bit 15:4
> > ? ? ? ? ? ? ? ?unsigned int revision_id ? ? ? ?: 4; ? ?// bit ?3:0
> > #else
> > ? ? ? ? ? ? ? ?unsigned int revision_id ? ? ? ?: 4; ? ?// bit ?3:0
> > ? ? ? ? ? ? ? ?unsigned int device_id ? ? ? ? ?: 12; ? // bit 15:4
> > ? ? ? ? ? ? ? ?unsigned int v_bit_mode ? ? ? ? : 1; ? ?// bit 16
> > ? ? ? ? ? ? ? ?unsigned int reserved ? ? ? ? ? : 15; ? // bit 31:17
> > #endif
> 
> The other thing is that this endianess redefinition is very starnge since
> it should swap bytes and not bits inside this struct. So I assume that
> big endian was never tested on this driver and it will not work.
> But ofcouse I can be wrong here :)
> 

At this momment my brain restarts in very slow motion mode ;-)
This can't work. The definition Storlinksemi uses for swapping bits and 
bytes are totaly wrong. 
They never _even_ testet this, or understand little endian or big endian.
Take this simple sample

typedef union {
	unsigned int bits32;
	struct bit {
#if (BIG_ENDIAN==0) 
		unsigned int a	: 1;		
		unsigned int b  : 31;
#else
		unsigned int b  : 31;
		unsigned int a  : 1;
#endif
	};
} TEST;

They swaped the bits inside one byte

> > ? ? ? ?} bits;
> > } TOE_VERSION_T;
> >
> >
> >
> 

  reply	other threads:[~2010-12-01 11:52 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-27 12:24 [PATCH] ARM: Gemini: Add support for PCI BUS Hans Ulli Kroll
2010-11-28 19:56 ` Arnd Bergmann
2010-11-29 12:17   ` Hans Ulli Kroll
2010-11-29 15:02     ` Arnd Bergmann
2010-11-29 16:05   ` Paulius Zaleckas
2010-11-29 16:45     ` Arnd Bergmann
2010-11-29 18:52       ` Paulius Zaleckas
2010-11-29 20:02         ` Arnd Bergmann
2010-11-29 20:19           ` Paulius Zaleckas
2010-11-30  8:15             ` Hans Ulli Kroll
2010-11-30  9:34               ` Paulius Zaleckas
2010-12-01 11:52                 ` Hans Ulli Kroll [this message]
2010-12-01 13:08                   ` Paulius Zaleckas
2010-12-01 15:02                     ` Hans Ulli Kroll
2010-12-06 10:51       ` Sergei Shtylyov
2010-12-06 12:18         ` Arnd Bergmann
2010-11-29 19:32     ` Russell King - ARM Linux
2010-11-29 19:57       ` Paulius Zaleckas
  -- strict thread matches above, loose matches on Subject: below --
2010-11-20 14:27 [PATCH] ARM: Gemini: Add support for PCI Bus Hans Ulli Kroll
2010-11-20 19:30 ` Paulius Zaleckas
2010-11-26 11:18   ` Russell King - ARM Linux
2010-11-26 11:57 ` Michał Mirosław
2010-11-27 12:16   ` Hans Ulli Kroll
2010-11-27 13:01     ` Michał Mirosław
2010-11-27 15:39       ` Arnd Bergmann
2010-11-29  8:12         ` Hans Ulli Kroll
2010-11-29 14:22         ` Russell King - ARM Linux
2010-11-29 14:50           ` Hans Ulli Kroll
2010-11-29 15:57             ` Arnd Bergmann
2010-11-30 15:38               ` Hans Ulli Kroll
2010-11-30 16:05               ` Russell King - ARM Linux
2010-11-30 16:19                 ` Arnd Bergmann
2010-12-01 15:05                   ` Hans Ulli Kroll
2010-11-29 15:50           ` Arnd Bergmann

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=alpine.LNX.2.00.1012011244120.8521@localhost.localdomain \
    --to=ulli.kroll@googlemail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox