devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Kevin Cernekee <cernekee@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Jason Cooper <jason@lakedaemon.net>,
	Ralf Baechle <ralf@linux-mips.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	Maxime Bizon <mbizon@freebox.fr>, Jonas Gorski <jogo@openwrt.org>,
	Linux MIPS Mailing List <linux-mips@linux-mips.org>
Subject: Re: [PATCH 01/11] irqchip: Allow irq_reg_{readl,writel} to use __raw_{readl_writel}
Date: Wed, 29 Oct 2014 22:13:10 +0100	[thread overview]
Message-ID: <22478002.kqKBdeLAKz@wuerfel> (raw)
In-Reply-To: <CAJiQ=7C7SzT2ngQzP=dQqdQz=+ShJ_Jf0z4kwFgvUKg1G3vrAw@mail.gmail.com>

On Wednesday 29 October 2014 13:09:47 Kevin Cernekee wrote:
> On Wed, Oct 29, 2014 at 12:14 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> >> The host CPU is connected to the peripheral/register interface using a
> >> 32-bit wide data bus.  A simple 32-bit store originating from the host
> >> CPU, targeted to an onchip SoC peripheral, will never need endian
> >> swapping.  i.e. this code works equally well on all supported systems
> >> regardless of endianness:
> >>
> >>     volatile u32 *foo = (void *)MY_REG_VA;
> >>     *foo = 0x12345678;
> >>
> >> 8-bit and 16-bit accesses may be another story, but only appear in a
> >> few very special peripherals.
> >
> > Sorry, but this makes no sense. If you run a little-endian kernel
> > on one of the MIPS systems that you marked as "always BE", or a
> > big-endian kernel on the systems that are marked "always LE",
> > then you have to byte swap.
> 
> If I ran an LE MIPS kernel on a BE system, it would hang on boot.  I
> know this through experience. 

What is a "BE system" then? Is the CPU core not capable of running
code either way?

> Setting aside the problem that the instruction words, pointers, and
> bitfields in the image are all in the wrong byte order, there are many
> other endian-specific assumptions baked into the executable.

Most of those are handled by the compiler. Bitfields are of course
a problem when they are accessed through DMA, but I would assume
that this is still a problem with the hardware byteswap hack that
the Broadcom SoCs have.

Of course, anything that uses __raw_readl on an MMIO register is
broken if you try to do this, which was my point the whole time.

> Does this actually work on other architectures like ARM?  I still see
> compile-time checks for CONFIG_CPU_ENDIAN* in a couple of places under
> arch/arm.

Yes, it should work on any architecture that supports both modes. It
definitely works on all ARM cores I know, and on most PowerPC cores.
I always assumed that MIPS was bi-endian as well, but according to
what you say I guess it is not.

ARM and PowerPC can actually switch endianess in the kernel, and this
is what they do in the first instruction when you run a different
endianess from what the boot loader runs as it calls into the kernel.
The ARM boot protocol requires entering the kernel in little-endian
mode, while I think on PowerPC the boot loader is supposed to detect
the format of the kernel binary and pick the right mode before calling
it.

> >> Or, we could add IRQ_GC_NATIVE_IO and/or IRQ_GC_BE_IO to enum irq_gc_flags.
> >>
> >> Would either of these choices satisfy everyone's goals?
> >
> > This is what I meant with doing extra work in the case where we want to
> > support both in the same kernel. We would only enable the runtime
> > logic if both GENERIC_IRQ_CHIP and GENERIC_IRQ_CHIP_BE are set, and
> > leave it up to the platform to select the right one. For MIPS BCM7xxx,
> > you could use
> >
> > config BCM7xxx
> >         select GENERIC_IRQ_CHIP if CPU_LITTLE_ENDIAN
> >         select GENERIC_IRQ_CHIP_BE if CPU_BIG_ENDIAN
> >
> > so you would default to the hardwired big-endian accessor unless
> > some other drivers selects GENERIC_IRQ_CHIP.
> 
> generic-chip.c already has a fair amount of indirection, with pointers
> to saved masks, user-specified register offsets, and such.  Is there a
> concern that introducing, say, a pair of readl/writel function
> pointers, would cause an unacceptable performance drop?

I don't know. Thomas' reply suggests that it isn't. Doing byteswap
in software at a register access is usually free in terms of CPU
cycles, but an indirect function call can be noticeable if we do
that a lot.
 
> Backing up a little bit, do we have a consensus that defining
> irq_reg_{readl,writel} at compile time from include/linux/irq.h is a
> bad idea for multiplatform images, and it should be removed one way or
> another?

If we can prove at compile-time that all users of irq_reg_{readl,writel}
are the same, then I think it's ok to hardcode it, but of course if
any driver we build needs the opposite of the others, or needs CPU-endian
access, then it definitely can't work.

	Arnd

  reply	other threads:[~2014-10-29 21:13 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-29  3:58 [PATCH 01/11] irqchip: Allow irq_reg_{readl,writel} to use __raw_{readl_writel} Kevin Cernekee
2014-10-29  3:58 ` [PATCH 02/11] irqchip: brcmstb-l2: Eliminate dependency on ARM code Kevin Cernekee
     [not found]   ` <1414555138-6500-2-git-send-email-cernekee-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-10-29  7:29     ` Arnd Bergmann
2014-10-29 16:53   ` Florian Fainelli
2014-10-29  3:58 ` [PATCH 03/11] irqchip: bcm7120-l2: Eliminate bad IRQ check Kevin Cernekee
2014-10-29 16:53   ` Florian Fainelli
2014-10-29  3:58 ` [PATCH 04/11] irqchip: Remove ARM dependency for bcm7120-l2 and brcmstb-l2 Kevin Cernekee
2014-10-29  7:44   ` Arnd Bergmann
2014-10-29 16:53   ` Florian Fainelli
2014-10-29  3:58 ` [PATCH 05/11] irqchip: bcm7120-l2: Make sure all register accesses use base+offset Kevin Cernekee
2014-10-29  7:46   ` Arnd Bergmann
2014-10-29  7:56     ` Arnd Bergmann
2014-10-29 16:53   ` Florian Fainelli
2014-10-29  3:58 ` [PATCH 06/11] irqchip: bcm7120-l2: Use irq_reg_* accessors Kevin Cernekee
2014-10-29  7:46   ` Arnd Bergmann
2014-10-29 16:54   ` Florian Fainelli
2014-10-29  3:58 ` [PATCH 07/11] irqchip: brcmstb-l2: " Kevin Cernekee
     [not found]   ` <1414555138-6500-7-git-send-email-cernekee-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-10-29  7:46     ` Arnd Bergmann
2014-10-29 16:54   ` Florian Fainelli
2014-10-29  3:58 ` [PATCH 08/11] irqchip: bcm7120-l2: Fix missing nibble in gc->unused mask Kevin Cernekee
2014-10-29  7:47   ` Arnd Bergmann
2014-10-29 16:55   ` Florian Fainelli
2014-10-29  3:58 ` [PATCH 09/11] irqchip: bcm7120-l2: Use gc->mask_cache to simplify suspend/resume functions Kevin Cernekee
     [not found]   ` <1414555138-6500-9-git-send-email-cernekee-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-10-29 16:55     ` Florian Fainelli
2014-10-29  3:58 ` [PATCH 10/11] irqchip: bcm7120-l2: Extend driver to support 64+ bit controllers Kevin Cernekee
2014-10-29  7:53   ` Arnd Bergmann
2014-10-29 23:22     ` Kevin Cernekee
2014-10-30  9:10       ` Arnd Bergmann
2014-10-29  3:58 ` [PATCH 11/11] irqchip: Decouple bcm7120-l2 from brcmstb-l2 Kevin Cernekee
2014-10-29  7:55   ` Arnd Bergmann
2014-10-29 16:56   ` Florian Fainelli
2014-10-29  7:43 ` [PATCH 01/11] irqchip: Allow irq_reg_{readl,writel} to use __raw_{readl_writel} Arnd Bergmann
2014-10-29 17:36   ` Florian Fainelli
     [not found]     ` <54512599.4080500-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-10-29 19:14       ` Arnd Bergmann
2014-10-29 18:48   ` Kevin Cernekee
2014-10-29 19:10     ` Thomas Gleixner
2014-10-29 19:14     ` Arnd Bergmann
2014-10-29 20:09       ` Kevin Cernekee
2014-10-29 21:13         ` Arnd Bergmann [this message]
2014-10-29 21:31           ` Thomas Gleixner
2014-10-29 21:41             ` Arnd Bergmann
2014-10-29 21:50               ` Thomas Gleixner
2014-10-29 23:05           ` Kevin Cernekee
2014-10-30  9:58             ` Arnd Bergmann
2014-10-30 19:03               ` Kevin Cernekee
2014-10-30 19:52                 ` Arnd Bergmann
2014-10-30 20:54                   ` Kevin Cernekee
     [not found]                     ` <CAJiQ=7C+r80Jt51NXLCk-0D2nRezBfMN9pGBVT9V8ncefGhBnQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-10-30 21:18                       ` Arnd Bergmann
2014-10-29 10:12 ` Thomas Gleixner

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=22478002.kqKBdeLAKz@wuerfel \
    --to=arnd@arndb.de \
    --cc=cernekee@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=f.fainelli@gmail.com \
    --cc=jason@lakedaemon.net \
    --cc=jogo@openwrt.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=mbizon@freebox.fr \
    --cc=ralf@linux-mips.org \
    --cc=tglx@linutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).