RE: [PATCH 5/6 v2] kvm: powerpc: booke: Add linux pte lookup like booke3s

2013-08-06 Thread Bhushan Bharat-R65777


 -Original Message-
 From: Bhushan Bharat-R65777
 Sent: Tuesday, August 06, 2013 6:42 AM
 To: Wood Scott-B07421
 Cc: Benjamin Herrenschmidt; ag...@suse.de; kvm-...@vger.kernel.org;
 k...@vger.kernel.org; linuxppc-dev@lists.ozlabs.org
 Subject: RE: [PATCH 5/6 v2] kvm: powerpc: booke: Add linux pte lookup like
 booke3s
 
 
 
  -Original Message-
  From: Wood Scott-B07421
  Sent: Tuesday, August 06, 2013 12:49 AM
  To: Bhushan Bharat-R65777
  Cc: Benjamin Herrenschmidt; Wood Scott-B07421; ag...@suse.de; kvm-
  p...@vger.kernel.org; k...@vger.kernel.org;
  linuxppc-dev@lists.ozlabs.org
  Subject: Re: [PATCH 5/6 v2] kvm: powerpc: booke: Add linux pte lookup
  like booke3s
 
  On Mon, 2013-08-05 at 09:27 -0500, Bhushan Bharat-R65777 wrote:
  
-Original Message-
From: Benjamin Herrenschmidt [mailto:b...@kernel.crashing.org]
Sent: Saturday, August 03, 2013 9:54 AM
To: Bhushan Bharat-R65777
Cc: Wood Scott-B07421; ag...@suse.de; kvm-...@vger.kernel.org;
k...@vger.kernel.org; linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH 5/6 v2] kvm: powerpc: booke: Add linux pte
lookup like booke3s
   
On Sat, 2013-08-03 at 02:58 +, Bhushan Bharat-R65777 wrote:
 One of the problem I saw was that if I put this code in
 asm/pgtable-32.h and asm/pgtable-64.h then pte_persent() and
 other friend function (on which this code depends) are defined in
 pgtable.h.
 And pgtable.h includes asm/pgtable-32.h and asm/pgtable-64.h
 before it defines pte_present() and friends functions.

 Ok I move wove this in asm/pgtable*.h, initially I fought with
 myself to take this code in pgtable* but finally end up doing
 here (got biased by book3s :)).
   
Is there a reason why these routines can not be completely generic
in pgtable.h ?
  
   How about the generic function:
  
   diff --git a/arch/powerpc/include/asm/pgtable-ppc64.h
   b/arch/powerpc/include/asm/pgtable-ppc64.h
   index d257d98..21daf28 100644
   --- a/arch/powerpc/include/asm/pgtable-ppc64.h
   +++ b/arch/powerpc/include/asm/pgtable-ppc64.h
   @@ -221,6 +221,27 @@ static inline unsigned long pte_update(struct
   mm_struct
  *mm,
   return old;
}
  
   +static inline unsigned long pte_read(pte_t *p) { #ifdef
   +PTE_ATOMIC_UPDATES
   +   pte_t pte;
   +   pte_t tmp;
   +   __asm__ __volatile__ (
   +   1: ldarx   %0,0,%3\n
   +  andi.   %1,%0,%4\n
   +  bne-1b\n
   +  ori %1,%0,%4\n
   +  stdcx.  %1,0,%3\n
   +  bne-1b
   +   : =r (pte), =r (tmp), =m (*p)
   +   : r (p), i (_PAGE_BUSY)
   +   : cc);
   +
   +   return pte;
   +#else
   +   return pte_val(*p);
   +#endif
   +#endif
   +}
static inline int __ptep_test_and_clear_young(struct mm_struct *mm,
 unsigned long addr,
   pte_t *ptep)
 
  Please leave a blank line between functions.
 
{
   diff --git a/arch/powerpc/include/asm/pgtable.h
   b/arch/powerpc/include/asm/pgtable.h
   index 690c8c2..dad712c 100644
   --- a/arch/powerpc/include/asm/pgtable.h
   +++ b/arch/powerpc/include/asm/pgtable.h
   @@ -254,6 +254,45 @@ static inline pte_t
   *find_linux_pte_or_hugepte(pgd_t *pgdir, unsigned long ea,  }
   #endif
   /* !CONFIG_HUGETLB_PAGE */
  
   +static inline pte_t lookup_linux_pte(pgd_t *pgdir, unsigned long hva,
   +int writing, unsigned long
   +*pte_sizep)
 
  The name implies that it just reads the PTE.  Setting accessed/dirty
  shouldn't be an undocumented side-effect.
 
 Ok, will rename and document.
 
  Why can't the caller do that (or a different function that the caller
  calls afterward if desired)?
 
 The current implementation in book3s is;
  1) find a pte/hugepte
  2) return null if pte not present
  3) take _PAGE_BUSY lock
  4) set accessed/dirty
  5) clear _PAGE_BUSY.
 
 What I tried was
 1) find a pte/hugepte
 2) return null if pte not present
 3) return pte (not take lock by not setting _PAGE_BUSY)
 
 4) then user calls  __ptep_set_access_flags() to atomic update the
 dirty/accessed flags in pte.
 
 - but the benchmark results were not good
 - Also can there be race as we do not take lock in step 3 and update in step 
 4 ?
 
 
  Though even then you have the undocumented side effect of locking the
  PTE on certain targets.
 
   +{
   +   pte_t *ptep;
   +   pte_t pte;
   +   unsigned long ps = *pte_sizep;
   +   unsigned int shift;
   +
   +   ptep = find_linux_pte_or_hugepte(pgdir, hva, shift);
   +   if (!ptep)
   +   return __pte(0);
   +   if (shift)
   +   *pte_sizep = 1ul  shift;
   +   else
   +   *pte_sizep = PAGE_SIZE;
   +
   +   if (ps  *pte_sizep)
   +   return __pte(0);
   +
   +   if (!pte_present(*ptep))
   +   return __pte(0);
   +
   +#ifdef CONFIG_PPC64
   +   /* Lock 

Re: PCIE device errors after linux kernel upgrade

2013-08-06 Thread Johannes Thumshirn
On Mon, Aug 05, 2013 at 09:38:45AM -0600, Bjorn Helgaas wrote:
 [+cc linuxppc-dev]

 On Mon, Aug 5, 2013 at 5:17 AM, Leon Ravich lrav...@gmail.com wrote:
  Hi all ,
  I am trying to upgrade ours embedded device (freescale powerPC P2020 cpu)
  linux kernel  , till now we used 2.6.32 I am trying to upgrade to 3.8.13 .
  I took the source from freescale git:
  git://git.freescale.com/ppc/sdk/linux.git
 
  on our embedded device we have an FPGA connected through PCIE .
 
  on each boot we loading the rbf design to the FPGA and the rescan pci bus 
  to let
  kernel detect it .
 
  during the rescan I getting error messages:
   genirq: Setting trigger mode 0 for irq 27 failed
  (mpc8xxx_irq_set_type+0x0/0xec)
  [   22.060898] genirq: Setting trigger mode 0 for irq 28 failed
  (mpc8xxx_irq_set_type+0x0/0xec)
  [   22.069461] genirq: Setting trigger mode 0 for irq 31 failed
  (mpc8xxx_irq_set_type+0x0/0xec)
  [   22.078010] genirq: Setting trigger mode 0 for irq 32 failed
  (mpc8xxx_irq_set_type+0x0/0xec)
  [   22.086576] genirq: Setting trigger mode 0 for irq 33 failed
  (mpc8xxx_irq_set_type+0x0/0xec)
  [   22.095143] genirq: Setting trigger mode 0 for irq 37 failed
  (mpc8xxx_irq_set_type+0x0/0xec)
  [   22.103715] genirq: Setting trigger mode 0 for irq 38 failed
  (mpc8xxx_irq_set_type+0x0/0xec)
  [   22.112282] genirq: Setting trigger mode 0 for irq 39 failed
  (mpc8xxx_irq_set_type+0x0/0xec)

 Hmm, I don't know much about IRQ issues.

  [   37.945785] pci :00:00.0: ignoring class 0x0b2000 (doesn't
  match header type 01)

 There's a recent patch related to this:
 http://lkml.kernel.org/r/1374823418-1550-1-git-send-email-chunhe@freescale.com

  [   37.953640] PCIE error(s) detected
  [   37.953858] pci :00:00.0: PCI bridge to [bus 01-ff]
  [   37.953988] pci :00:00.0: BAR 8: assigned [mem 0xc000-0xdfff]
  [   37.953994] pci :00:00.0: BAR 7: can't assign io (size 0x1)
  [   37.954000] pci :01:00.0: BAR 0: assigned [mem 0xc000-0xc00f]
  [   37.954013] pci :01:00.0: BAR 1: assigned [mem 0xc010-0xc017]
  [   37.954025] pci :01:00.0: BAR 2: assigned [mem 0xc018-0xc01f]
  [   37.954036] pci :00:00.0: PCI bridge to [bus 01]
  [   37.954041] pci :00:00.0:   bridge window [mem 0xc000-0xdfff]
  [   38.007354] PCIE ERR_DR register: 0x8002
  [   38.011613] PCIE ERR_CAP_STAT register: 0x0041
  [   38.016392] PCIE ERR_CAP_R0 register: 0x0800
  [   38.020997] PCIE ERR_CAP_R1 register: 0x
  [   38.025602] PCIE ERR_CAP_R2 register: 0x
  [   38.030207] PCIE ERR_CAP_R3 register: 0x
 
 
  and after a few minutes I linux reboot it self,
 
 
  where can I start debugging it??

 I'd start by applying the header quirk patch above, then comparing the
 complete console log (boot with ignore_loglevel) from 2.6.32 and
 3.8.13.

 Bjorn
 ___
 Linuxppc-dev mailing list
 Linuxppc-dev@lists.ozlabs.org
 https://lists.ozlabs.org/listinfo/linuxppc-dev

Hi,

I have a similar problem here on a P4080 based board with the same 3.8 Kernel
from freescale git. Does your system panic (maybe due to a machine check
exception)?  If yes could it be the first read from the PCI device?

Johannes
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: mm/slab: ppc: ubi: kmalloc_slab WARNING / PPC + UBI driver

2013-08-06 Thread Wladislav Wiebe
Hi,

On 31/07/13 19:04, Christoph Lameter wrote:
 On Wed, 31 Jul 2013, Wladislav Wiebe wrote:
 
 Thanks for the point, do you plan to make kmalloc_large available for extern 
 access in a separate mainline patch?
 Since kmalloc_large is statically defined in slub_def.h and when including 
 it to seq_file.c
 we have a lot of conflicting types:
 
 You cannot separatly include slub_def.h. slab.h includes slub_def.h for
 you. What problem did you try to fix by doing so?
 
 There is a patch pending that moves kmalloc_large to slab.h. So maybe we
 have to wait a merge period in order to be able to use it with other
 allocators than slub.
 
 

ok, just saw in slab/for-linus branch that those stuff is reverted again..

commit 4932163637fbb9aaa654ca0703c5a624b7809da2
Author: Pekka Enberg penb...@kernel.org
Date:   Wed Jul 10 10:16:01 2013 +0300

Revert mm/sl[aou]b: Move kmalloc_node functions to common code

..

commit 35be03cafb8f5ddcc1236e90144b6ec76296b789
Author: Pekka Enberg penb...@kernel.org
Date:   Wed Jul 10 09:56:49 2013 +0300

Revert mm/sl[aou]b: Move kmalloc definitions to slab.h


--
WBR, WLadislav Wiebe
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v3 1/3] selftests: Add infrastructure for powerpc selftests

2013-08-06 Thread Michael Ellerman
This commit adds a powerpc subdirectory to tools/testing/selftests,
for tests that are powerpc specific.

On other architectures nothing is built. The makefile supports cross
compilation if the user sets ARCH and CROSS_COMPILE.

Signed-off-by: Michael Ellerman mich...@ellerman.id.au
---
v3: Add tags
v2: No change

 tools/testing/selftests/Makefile |  1 +
 tools/testing/selftests/powerpc/Makefile | 39 
 2 files changed, 40 insertions(+)
 create mode 100644 tools/testing/selftests/powerpc/Makefile

diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 4cb14ca..9f3eae2 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -8,6 +8,7 @@ TARGETS += net
 TARGETS += ptrace
 TARGETS += timers
 TARGETS += vm
+TARGETS += powerpc
 
 all:
for TARGET in $(TARGETS); do \
diff --git a/tools/testing/selftests/powerpc/Makefile 
b/tools/testing/selftests/powerpc/Makefile
new file mode 100644
index 000..b315740
--- /dev/null
+++ b/tools/testing/selftests/powerpc/Makefile
@@ -0,0 +1,39 @@
+# Makefile for powerpc selftests
+
+# ARCH can be overridden by the user for cross compiling
+ARCH ?= $(shell uname -m)
+ARCH := $(shell echo $(ARCH) | sed -e s/ppc.*/powerpc/)
+
+ifeq ($(ARCH),powerpc)
+
+GIT_VERSION = $(shell git describe --always --long --dirty || echo unknown)
+
+CC := $(CROSS_COMPILE)$(CC)
+CFLAGS := -Wall -O2 -flto -Wall -Werror -DGIT_VERSION='$(GIT_VERSION)' 
-I$(CURDIR) $(CFLAGS)
+
+export CC CFLAGS
+
+TARGETS =
+
+endif
+
+all:
+   @for TARGET in $(TARGETS); do \
+   $(MAKE) -C $$TARGET all; \
+   done;
+
+run_tests: all
+   @for TARGET in $(TARGETS); do \
+   $(MAKE) -C $$TARGET run_tests; \
+   done;
+
+clean:
+   @for TARGET in $(TARGETS); do \
+   $(MAKE) -C $$TARGET clean; \
+   done;
+   rm -f tags
+
+tags:
+   find . -name '*.c' -o -name '*.h' | xargs ctags
+
+.PHONY: all run_tests clean tags
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v3 2/3] selftests: Add support files for powerpc tests

2013-08-06 Thread Michael Ellerman
This commit adds support code used by upcoming powerpc tests.

Signed-off-by: Michael Ellerman mich...@ellerman.id.au
---
v3: Print when the child dies due to a signal
v2: Put back the SIGALARM handler to make the hang logic work.

 tools/testing/selftests/powerpc/harness.c | 105 ++
 tools/testing/selftests/powerpc/subunit.h |  47 +
 tools/testing/selftests/powerpc/utils.h   |  34 ++
 3 files changed, 186 insertions(+)
 create mode 100644 tools/testing/selftests/powerpc/harness.c
 create mode 100644 tools/testing/selftests/powerpc/subunit.h
 create mode 100644 tools/testing/selftests/powerpc/utils.h

diff --git a/tools/testing/selftests/powerpc/harness.c 
b/tools/testing/selftests/powerpc/harness.c
new file mode 100644
index 000..e80c42a
--- /dev/null
+++ b/tools/testing/selftests/powerpc/harness.c
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2013, Michael Ellerman, IBM Corp.
+ * Licensed under GPLv2.
+ */
+
+#include errno.h
+#include signal.h
+#include stdbool.h
+#include stdio.h
+#include stdlib.h
+#include sys/types.h
+#include sys/wait.h
+#include unistd.h
+
+#include subunit.h
+#include utils.h
+
+#define TIMEOUT120
+#define KILL_TIMEOUT   5
+
+
+int run_test(int (test_function)(void), char *name)
+{
+   bool terminated;
+   int rc, status;
+   pid_t pid;
+
+   /* Make sure output is flushed before forking */
+   fflush(stdout);
+
+   pid = fork();
+   if (pid == 0) {
+   exit(test_function());
+   } else if (pid == -1) {
+   perror(fork);
+   return 1;
+   }
+
+   /* Wake us up in timeout seconds */
+   alarm(TIMEOUT);
+   terminated = false;
+
+wait:
+   rc = waitpid(pid, status, 0);
+   if (rc == -1) {
+   if (errno != EINTR) {
+   printf(unknown error from waitpid\n);
+   return 1;
+   }
+
+   if (terminated) {
+   printf(!! force killing %s\n, name);
+   kill(pid, SIGKILL);
+   return 1;
+   } else {
+   printf(!! killing %s\n, name);
+   kill(pid, SIGTERM);
+   terminated = true;
+   alarm(KILL_TIMEOUT);
+   goto wait;
+   }
+   }
+
+   if (WIFEXITED(status))
+   status = WEXITSTATUS(status);
+   else {
+   if (WIFSIGNALED(status))
+   printf(!! child died by signal %d\n, 
WTERMSIG(status));
+   else
+   printf(!! child died by unknown cause\n);
+
+   status = 1; /* Signal or other */
+   }
+
+   return status;
+}
+
+static void alarm_handler(int signum)
+{
+   /* Jut wake us up from waitpid */
+}
+
+static struct sigaction alarm_action = {
+   .sa_handler = alarm_handler,
+};
+
+int test_harness(int (test_function)(void), char *name)
+{
+   int rc;
+
+   test_start(name);
+   test_set_git_version(GIT_VERSION);
+
+   if (sigaction(SIGALRM, alarm_action, NULL)) {
+   perror(sigaction);
+   test_error(name);
+   return 1;
+   }
+
+   rc = run_test(test_function, name);
+
+   test_finish(name, rc);
+
+   return rc;
+}
diff --git a/tools/testing/selftests/powerpc/subunit.h 
b/tools/testing/selftests/powerpc/subunit.h
new file mode 100644
index 000..98a2292
--- /dev/null
+++ b/tools/testing/selftests/powerpc/subunit.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2013, Michael Ellerman, IBM Corp.
+ * Licensed under GPLv2.
+ */
+
+#ifndef _SELFTESTS_POWERPC_SUBUNIT_H
+#define _SELFTESTS_POWERPC_SUBUNIT_H
+
+static inline void test_start(char *name)
+{
+   printf(test: %s\n, name);
+}
+
+static inline void test_failure_detail(char *name, char *detail)
+{
+   printf(failure: %s [%s]\n, name, detail);
+}
+
+static inline void test_failure(char *name)
+{
+   printf(failure: %s\n, name);
+}
+
+static inline void test_error(char *name)
+{
+   printf(error: %s\n, name);
+}
+
+static inline void test_success(char *name)
+{
+   printf(success: %s\n, name);
+}
+
+static inline void test_finish(char *name, int status)
+{
+   if (status)
+   test_failure(name);
+   else
+   test_success(name);
+}
+
+static inline void test_set_git_version(char *value)
+{
+   printf(tags: git_version:%s\n, value);
+}
+
+#endif /* _SELFTESTS_POWERPC_SUBUNIT_H */
diff --git a/tools/testing/selftests/powerpc/utils.h 
b/tools/testing/selftests/powerpc/utils.h
new file mode 100644
index 000..5851c4b
--- /dev/null
+++ b/tools/testing/selftests/powerpc/utils.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2013, Michael Ellerman, IBM Corp.
+ * Licensed under GPLv2.
+ */
+
+#ifndef _SELFTESTS_POWERPC_UTILS_H
+#define _SELFTESTS_POWERPC_UTILS_H
+
+#include stdint.h
+#include stdbool.h
+
+/* Avoid headaches with 

Re: PCIE device errors after linux kernel upgrade

2013-08-06 Thread Johannes Thumshirn
On Tue, Aug 06, 2013 at 10:26:18AM +0300, Leon Ravich wrote:
 Hi Johannes
 no panic just reboot.
 it is not the first read, it takes few minutes of work with pcie to reboot.


Ah, OK. Unfortunately I can't really help you then.

Have you looked up the error values from the EDAC driver?

If it's just a reboot without panic, could there be a watchdog resetting the
board?




 On 6 August 2013 10:07, Johannes Thumshirn johannes.thumsh...@men.de wrote:
  On Mon, Aug 05, 2013 at 09:38:45AM -0600, Bjorn Helgaas wrote:
  [+cc linuxppc-dev]
 
  On Mon, Aug 5, 2013 at 5:17 AM, Leon Ravich lrav...@gmail.com wrote:
   Hi all ,
   I am trying to upgrade ours embedded device (freescale powerPC P2020 cpu)
   linux kernel  , till now we used 2.6.32 I am trying to upgrade to 3.8.13 
   .
   I took the source from freescale git:
   git://git.freescale.com/ppc/sdk/linux.git
  
   on our embedded device we have an FPGA connected through PCIE .
  
   on each boot we loading the rbf design to the FPGA and the rescan pci 
   bus to let
   kernel detect it .
  
   during the rescan I getting error messages:
genirq: Setting trigger mode 0 for irq 27 failed
   (mpc8xxx_irq_set_type+0x0/0xec)
   [   22.060898] genirq: Setting trigger mode 0 for irq 28 failed
   (mpc8xxx_irq_set_type+0x0/0xec)
   [   22.069461] genirq: Setting trigger mode 0 for irq 31 failed
   (mpc8xxx_irq_set_type+0x0/0xec)
   [   22.078010] genirq: Setting trigger mode 0 for irq 32 failed
   (mpc8xxx_irq_set_type+0x0/0xec)
   [   22.086576] genirq: Setting trigger mode 0 for irq 33 failed
   (mpc8xxx_irq_set_type+0x0/0xec)
   [   22.095143] genirq: Setting trigger mode 0 for irq 37 failed
   (mpc8xxx_irq_set_type+0x0/0xec)
   [   22.103715] genirq: Setting trigger mode 0 for irq 38 failed
   (mpc8xxx_irq_set_type+0x0/0xec)
   [   22.112282] genirq: Setting trigger mode 0 for irq 39 failed
   (mpc8xxx_irq_set_type+0x0/0xec)
 
  Hmm, I don't know much about IRQ issues.
 
   [   37.945785] pci :00:00.0: ignoring class 0x0b2000 (doesn't
   match header type 01)
 
  There's a recent patch related to this:
  http://lkml.kernel.org/r/1374823418-1550-1-git-send-email-chunhe@freescale.com
 
   [   37.953640] PCIE error(s) detected
   [   37.953858] pci :00:00.0: PCI bridge to [bus 01-ff]
   [   37.953988] pci :00:00.0: BAR 8: assigned [mem 
   0xc000-0xdfff]
   [   37.953994] pci :00:00.0: BAR 7: can't assign io (size 0x1)
   [   37.954000] pci :01:00.0: BAR 0: assigned [mem 
   0xc000-0xc00f]
   [   37.954013] pci :01:00.0: BAR 1: assigned [mem 
   0xc010-0xc017]
   [   37.954025] pci :01:00.0: BAR 2: assigned [mem 
   0xc018-0xc01f]
   [   37.954036] pci :00:00.0: PCI bridge to [bus 01]
   [   37.954041] pci :00:00.0:   bridge window [mem 
   0xc000-0xdfff]
   [   38.007354] PCIE ERR_DR register: 0x8002
   [   38.011613] PCIE ERR_CAP_STAT register: 0x0041
   [   38.016392] PCIE ERR_CAP_R0 register: 0x0800
   [   38.020997] PCIE ERR_CAP_R1 register: 0x
   [   38.025602] PCIE ERR_CAP_R2 register: 0x
   [   38.030207] PCIE ERR_CAP_R3 register: 0x
  
  
   and after a few minutes I linux reboot it self,
  
  
   where can I start debugging it??
 
  I'd start by applying the header quirk patch above, then comparing the
  complete console log (boot with ignore_loglevel) from 2.6.32 and
  3.8.13.
 
  Bjorn
  ___
  Linuxppc-dev mailing list
  Linuxppc-dev@lists.ozlabs.org
  https://lists.ozlabs.org/listinfo/linuxppc-dev
 
  Hi,
 
  I have a similar problem here on a P4080 based board with the same 3.8 
  Kernel
  from freescale git. Does your system panic (maybe due to a machine check
  exception)?  If yes could it be the first read from the PCI device?
 
  Johannes



 --
 Leonid Ravich
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v3 3/3] selftests: Add test of PMU instruction counting on powerpc

2013-08-06 Thread Michael Ellerman
This commit adds a test of instruction counting using the PMU on powerpc.

Although the bulk of the code is architecture agnostic, the code needs to
run a precisely sized loop which is implemented in assembler.

Signed-off-by: Michael Ellerman mich...@ellerman.id.au
---
v2,3: No change

 tools/testing/selftests/powerpc/Makefile   |   2 +-
 tools/testing/selftests/powerpc/pmu/Makefile   |  23 
 .../selftests/powerpc/pmu/count_instructions.c | 135 +
 tools/testing/selftests/powerpc/pmu/event.c| 105 
 tools/testing/selftests/powerpc/pmu/event.h|  39 ++
 tools/testing/selftests/powerpc/pmu/loop.S |  46 +++
 6 files changed, 349 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/pmu/Makefile
 create mode 100644 tools/testing/selftests/powerpc/pmu/count_instructions.c
 create mode 100644 tools/testing/selftests/powerpc/pmu/event.c
 create mode 100644 tools/testing/selftests/powerpc/pmu/event.h
 create mode 100644 tools/testing/selftests/powerpc/pmu/loop.S

diff --git a/tools/testing/selftests/powerpc/Makefile 
b/tools/testing/selftests/powerpc/Makefile
index b315740..bd24ae5 100644
--- a/tools/testing/selftests/powerpc/Makefile
+++ b/tools/testing/selftests/powerpc/Makefile
@@ -13,7 +13,7 @@ CFLAGS := -Wall -O2 -flto -Wall -Werror 
-DGIT_VERSION='$(GIT_VERSION)' -I$(CUR
 
 export CC CFLAGS
 
-TARGETS =
+TARGETS = pmu
 
 endif
 
diff --git a/tools/testing/selftests/powerpc/pmu/Makefile 
b/tools/testing/selftests/powerpc/pmu/Makefile
new file mode 100644
index 000..7216f00
--- /dev/null
+++ b/tools/testing/selftests/powerpc/pmu/Makefile
@@ -0,0 +1,23 @@
+noarg:
+   $(MAKE) -C ../
+
+PROGS := count_instructions
+EXTRA_SOURCES := ../harness.c event.c
+
+all: $(PROGS)
+
+$(PROGS): $(EXTRA_SOURCES)
+
+# loop.S can only be built 64-bit
+count_instructions: loop.S count_instructions.c $(EXTRA_SOURCES)
+   $(CC) $(CFLAGS) -m64 -o $@ $^
+
+run_tests: all
+   @-for PROG in $(PROGS); do \
+   ./$$PROG; \
+   done;
+
+clean:
+   rm -f $(PROGS) loop.o
+
+.PHONY: all run_tests clean
diff --git a/tools/testing/selftests/powerpc/pmu/count_instructions.c 
b/tools/testing/selftests/powerpc/pmu/count_instructions.c
new file mode 100644
index 000..312b4f0
--- /dev/null
+++ b/tools/testing/selftests/powerpc/pmu/count_instructions.c
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2013, Michael Ellerman, IBM Corp.
+ * Licensed under GPLv2.
+ */
+
+#define _GNU_SOURCE
+
+#include stdio.h
+#include stdbool.h
+#include string.h
+#include sys/prctl.h
+
+#include event.h
+#include utils.h
+
+extern void thirty_two_instruction_loop(u64 loops);
+
+static void setup_event(struct event *e, u64 config, char *name)
+{
+   event_init_opts(e, config, PERF_TYPE_HARDWARE, name);
+
+   e-attr.disabled = 1;
+   e-attr.exclude_kernel = 1;
+   e-attr.exclude_hv = 1;
+   e-attr.exclude_idle = 1;
+}
+
+static int do_count_loop(struct event *events, u64 instructions,
+u64 overhead, bool report)
+{
+   s64 difference, expected;
+   double percentage;
+
+   prctl(PR_TASK_PERF_EVENTS_ENABLE);
+
+   /* Run for 1M instructions */
+   thirty_two_instruction_loop(instructions  5);
+
+   prctl(PR_TASK_PERF_EVENTS_DISABLE);
+
+   event_read(events[0]);
+   event_read(events[1]);
+
+   expected = instructions + overhead;
+   difference = events[0].result.value - expected;
+   percentage = (double)difference / events[0].result.value * 100;
+
+   if (report) {
+   event_report(events[0]);
+   event_report(events[1]);
+
+   printf(Looped for %llu instructions, overhead %llu\n, 
instructions, overhead);
+   printf(Expected %llu\n, expected);
+   printf(Actual   %llu\n, events[0].result.value);
+   printf(Delta%lld, %f%%\n, difference, percentage);
+   }
+
+   event_reset(events[0]);
+   event_reset(events[1]);
+
+   if (difference  0)
+   difference = -difference;
+
+   /* Tolerate a difference below 0.0001 % */
+   difference *= 1 * 100;
+   if (difference / events[0].result.value)
+   return -1;
+
+   return 0;
+}
+
+/* Count how many instructions it takes to do a null loop */
+static u64 determine_overhead(struct event *events)
+{
+   u64 current, overhead;
+   int i;
+
+   do_count_loop(events, 0, 0, false);
+   overhead = events[0].result.value;
+
+   for (i = 0; i  100; i++) {
+   do_count_loop(events, 0, 0, false);
+   current = events[0].result.value;
+   if (current  overhead) {
+   printf(Replacing overhead %llu with %llu\n, overhead, 
current);
+   overhead = current;
+   }
+   }
+
+   return overhead;
+}
+
+static int count_instructions(void)
+{
+   struct event events[2];

Re: PCIE device errors after linux kernel upgrade

2013-08-06 Thread Leon Ravich
Thanks Bjorn.

1) If I understand it right this patch only removes the pci
:00:00.0: ignoring class 0x0b2000 (doesn't
match header type 01) message , don't  care about it , had it before .

2) regarding the comparing of printouts:

kernel 3.8.13:

[   37.908846] pci_bus :00: scanning bus
[   37.912870] pci :00:00.0: [1957:0070] type 01 class 0x0b2000
[   37.918881] pci :00:00.0: ignoring class 0x0b2000 (doesn't
match header type 01)
[   37.926640] pci :00:00.0: calling fixup_hide_host_resource_fsl+0x0/0x5c
[   37.933596] pci :00:00.0: calling pcibios_fixup_resources+0x0/0xf0
[   37.940132] pci :00:00.0: calling quirk_fsl_pcie_header+0x0/0x78
[   37.946505] pci :00:00.0: supports D1 D2
[   37.950779] pci :00:00.0: PME# supported from D0 D1 D2 D3hot D3cold
[   37.957397] pci :00:00.0: PME# disabled
[   37.961580] PCIE error(s) detected
[   37.964971] PCIE ERR_DR register: 0x0002
[   37.969229] PCIE ERR_CAP_STAT register: 0x0041
[   37.974008] PCIE ERR_CAP_R0 register: 0x0800
[   37.978614] PCIE ERR_CAP_R1 register: 0x
[   37.983218] PCIE ERR_CAP_R2 register: 0x
[   37.987823] PCIE ERR_CAP_R3 register: 0x
[   37.992448] PCIE error(s) detected
[   37.995841] PCIE ERR_DR register: 0x0002
[   38.98] PCIE ERR_CAP_STAT register: 0x0041
[   38.004877] PCIE ERR_CAP_R0 register: 0x0800
[   38.009482] PCIE ERR_CAP_R1 register: 0x
[   38.014087] PCIE ERR_CAP_R2 register: 0x
[   38.018692] PCIE ERR_CAP_R3 register: 0x
[   38.023312] PCIE error(s) detected
[   38.026704] PCIE ERR_DR register: 0x0002
[   38.030961] PCIE ERR_CAP_STAT register: 0x0041
[   38.035740] PCIE ERR_CAP_R0 register: 0x0800
[   38.040345] PCIE ERR_CAP_R1 register: 0x
[   38.044950] PCIE ERR_CAP_R2 register: 0x
[   38.049554] PCIE ERR_CAP_R3 register: 0x
[   38.054180] PCIE error(s) detected
[   38.057573] PCIE ERR_DR register: 0x0002
[   38.061831] PCIE ERR_CAP_STAT register: 0x0041
[   38.066609] PCIE ERR_CAP_R0 register: 0x0800
[   38.071214] PCIE ERR_CAP_R1 register: 0x
[   38.075819] PCIE ERR_CAP_R2 register: 0x
[   38.080424] PCIE ERR_CAP_R3 register: 0x
[   38.085046] PCIE error(s) detected
[   38.088438] PCIE ERR_DR register: 0x0002
[   38.092696] PCIE ERR_CAP_STAT register: 0x0041
[   38.097474] PCIE ERR_CAP_R0 register: 0x0800
[   38.102079] PCIE ERR_CAP_R1 register: 0x
[   38.106684] PCIE ERR_CAP_R2 register: 0x
[   38.111289] PCIE ERR_CAP_R3 register: 0x
[   38.115909] PCIE error(s) detected
[   38.119301] PCIE ERR_DR register: 0x0002
[   38.123559] PCIE ERR_CAP_STAT register: 0x0041
[   38.128337] PCIE ERR_CAP_R0 register: 0x0800
[   38.132942] PCIE ERR_CAP_R1 register: 0x
[   38.137547] PCIE ERR_CAP_R2 register: 0x
[   38.142152] PCIE ERR_CAP_R3 register: 0x
[   38.146773] PCIE error(s) detected
[   38.150164] PCIE ERR_DR register: 0x0002
[   38.154423] PCIE ERR_CAP_STAT register: 0x0041
[   38.159201] PCIE ERR_CAP_R0 register: 0x0800
[   38.163806] PCIE ERR_CAP_R1 register: 0x
[   38.168410] PCIE ERR_CAP_R2 register: 0x
[   38.173015] PCIE ERR_CAP_R3 register: 0x
[   38.177635] PCIE error(s) detected
[   38.181028] PCIE ERR_DR register: 0x0002
[   38.185286] PCIE ERR_CAP_STAT register: 0x0041
[   38.190066] PCIE ERR_CAP_R0 register: 0x0800
[   38.194670] PCIE ERR_CAP_R1 register: 0x
[   38.199275] PCIE ERR_CAP_R2 register: 0x
[   38.203880] PCIE ERR_CAP_R3 register: 0x
[   38.208504] PCIE error(s) detected
[   38.211897] PCIE ERR_DR register: 0x0002
[   38.216156] PCIE ERR_CAP_STAT register: 0x0041
[   38.220935] PCIE ERR_CAP_R0 register: 0x0800
[   38.225540] PCIE ERR_CAP_R1 register: 0x
[   38.230144] PCIE ERR_CAP_R2 register: 0x
[   38.234749] PCIE ERR_CAP_R3 register: 0x
[   38.239395] PCIE error(s) detected
[   38.242788] PCIE ERR_DR register: 0x0002
[   38.247046] PCIE ERR_CAP_STAT register: 0x0041
[   38.251825] PCIE ERR_CAP_R0 register: 0x0800
[   38.256430] PCIE ERR_CAP_R1 register: 0x
[   38.261034] PCIE ERR_CAP_R2 register: 0x
[   38.265639] PCIE ERR_CAP_R3 register: 0x
[   38.270268] PCIE error(s) detected
[   38.273660] PCIE ERR_DR register: 0x0002
[   38.277918] PCIE ERR_CAP_STAT register: 0x0041
[   38.282697] PCIE ERR_CAP_R0 register: 0x0800
[   38.287302] PCIE ERR_CAP_R1 register: 0x
[   38.291906] PCIE ERR_CAP_R2 register: 0x
[   38.296511] PCIE ERR_CAP_R3 register: 0x
[   38.301134] PCIE error(s) detected
[   38.304526] PCIE ERR_DR register: 0x0002
[   38.308784] PCIE ERR_CAP_STAT register: 0x0041
[   38.313563] PCIE ERR_CAP_R0 register: 0x0800
[   38.318168] PCIE ERR_CAP_R1 register: 0x
[   38.322772] PCIE ERR_CAP_R2 register: 0x
[   38.327377] PCIE 

Re: PCIE device errors after linux kernel upgrade

2013-08-06 Thread Leon Ravich
Hi Johannes
no panic just reboot.
it is not the first read, it takes few minutes of work with pcie to reboot.



On 6 August 2013 10:07, Johannes Thumshirn johannes.thumsh...@men.de wrote:
 On Mon, Aug 05, 2013 at 09:38:45AM -0600, Bjorn Helgaas wrote:
 [+cc linuxppc-dev]

 On Mon, Aug 5, 2013 at 5:17 AM, Leon Ravich lrav...@gmail.com wrote:
  Hi all ,
  I am trying to upgrade ours embedded device (freescale powerPC P2020 cpu)
  linux kernel  , till now we used 2.6.32 I am trying to upgrade to 3.8.13 .
  I took the source from freescale git:
  git://git.freescale.com/ppc/sdk/linux.git
 
  on our embedded device we have an FPGA connected through PCIE .
 
  on each boot we loading the rbf design to the FPGA and the rescan pci bus 
  to let
  kernel detect it .
 
  during the rescan I getting error messages:
   genirq: Setting trigger mode 0 for irq 27 failed
  (mpc8xxx_irq_set_type+0x0/0xec)
  [   22.060898] genirq: Setting trigger mode 0 for irq 28 failed
  (mpc8xxx_irq_set_type+0x0/0xec)
  [   22.069461] genirq: Setting trigger mode 0 for irq 31 failed
  (mpc8xxx_irq_set_type+0x0/0xec)
  [   22.078010] genirq: Setting trigger mode 0 for irq 32 failed
  (mpc8xxx_irq_set_type+0x0/0xec)
  [   22.086576] genirq: Setting trigger mode 0 for irq 33 failed
  (mpc8xxx_irq_set_type+0x0/0xec)
  [   22.095143] genirq: Setting trigger mode 0 for irq 37 failed
  (mpc8xxx_irq_set_type+0x0/0xec)
  [   22.103715] genirq: Setting trigger mode 0 for irq 38 failed
  (mpc8xxx_irq_set_type+0x0/0xec)
  [   22.112282] genirq: Setting trigger mode 0 for irq 39 failed
  (mpc8xxx_irq_set_type+0x0/0xec)

 Hmm, I don't know much about IRQ issues.

  [   37.945785] pci :00:00.0: ignoring class 0x0b2000 (doesn't
  match header type 01)

 There's a recent patch related to this:
 http://lkml.kernel.org/r/1374823418-1550-1-git-send-email-chunhe@freescale.com

  [   37.953640] PCIE error(s) detected
  [   37.953858] pci :00:00.0: PCI bridge to [bus 01-ff]
  [   37.953988] pci :00:00.0: BAR 8: assigned [mem 
  0xc000-0xdfff]
  [   37.953994] pci :00:00.0: BAR 7: can't assign io (size 0x1)
  [   37.954000] pci :01:00.0: BAR 0: assigned [mem 
  0xc000-0xc00f]
  [   37.954013] pci :01:00.0: BAR 1: assigned [mem 
  0xc010-0xc017]
  [   37.954025] pci :01:00.0: BAR 2: assigned [mem 
  0xc018-0xc01f]
  [   37.954036] pci :00:00.0: PCI bridge to [bus 01]
  [   37.954041] pci :00:00.0:   bridge window [mem 
  0xc000-0xdfff]
  [   38.007354] PCIE ERR_DR register: 0x8002
  [   38.011613] PCIE ERR_CAP_STAT register: 0x0041
  [   38.016392] PCIE ERR_CAP_R0 register: 0x0800
  [   38.020997] PCIE ERR_CAP_R1 register: 0x
  [   38.025602] PCIE ERR_CAP_R2 register: 0x
  [   38.030207] PCIE ERR_CAP_R3 register: 0x
 
 
  and after a few minutes I linux reboot it self,
 
 
  where can I start debugging it??

 I'd start by applying the header quirk patch above, then comparing the
 complete console log (boot with ignore_loglevel) from 2.6.32 and
 3.8.13.

 Bjorn
 ___
 Linuxppc-dev mailing list
 Linuxppc-dev@lists.ozlabs.org
 https://lists.ozlabs.org/listinfo/linuxppc-dev

 Hi,

 I have a similar problem here on a P4080 based board with the same 3.8 Kernel
 from freescale git. Does your system panic (maybe due to a machine check
 exception)?  If yes could it be the first read from the PCI device?

 Johannes



-- 
Leonid Ravich
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: PCIE device errors after linux kernel upgrade

2013-08-06 Thread Leon Ravich
 Have you looked up the error values from the EDAC driver?
[   37.961580] PCIE error(s) detected
[   37.964971] PCIE ERR_DR register: 0x0002
= Invalid CONFIG_ADDR/PEX_CONFIG_DATA access detected
[   37.969229] PCIE ERR_CAP_STAT register: 0x0041   =
Transaction originated from PEX_CONFIG_ADDR/PEX_CONFIG_DATA.
[   37.974008] PCIE ERR_CAP_R0 register: 0x0800
= PCI Express packet format 0,  PCI express packet type  4
[   37.978614] PCIE ERR_CAP_R1 register: 0x
[   37.983218] PCIE ERR_CAP_R2 register: 0x
[   37.987823] PCIE ERR_CAP_R3 register: 0x

 If it's just a reboot without panic, could there be a watchdog resetting the
 board?

does not look like a  watch dog , no watch dog printout. no freeze .



On 6 August 2013 10:36, Johannes Thumshirn johannes.thumsh...@men.de wrote:
 On Tue, Aug 06, 2013 at 10:26:18AM +0300, Leon Ravich wrote:
 Hi Johannes
 no panic just reboot.
 it is not the first read, it takes few minutes of work with pcie to reboot.


 Ah, OK. Unfortunately I can't really help you then.

 Have you looked up the error values from the EDAC driver?

 If it's just a reboot without panic, could there be a watchdog resetting the
 board?




 On 6 August 2013 10:07, Johannes Thumshirn johannes.thumsh...@men.de wrote:
  On Mon, Aug 05, 2013 at 09:38:45AM -0600, Bjorn Helgaas wrote:
  [+cc linuxppc-dev]
 
  On Mon, Aug 5, 2013 at 5:17 AM, Leon Ravich lrav...@gmail.com wrote:
   Hi all ,
   I am trying to upgrade ours embedded device (freescale powerPC P2020 
   cpu)
   linux kernel  , till now we used 2.6.32 I am trying to upgrade to 
   3.8.13 .
   I took the source from freescale git:
   git://git.freescale.com/ppc/sdk/linux.git
  
   on our embedded device we have an FPGA connected through PCIE .
  
   on each boot we loading the rbf design to the FPGA and the rescan pci 
   bus to let
   kernel detect it .
  
   during the rescan I getting error messages:
genirq: Setting trigger mode 0 for irq 27 failed
   (mpc8xxx_irq_set_type+0x0/0xec)
   [   22.060898] genirq: Setting trigger mode 0 for irq 28 failed
   (mpc8xxx_irq_set_type+0x0/0xec)
   [   22.069461] genirq: Setting trigger mode 0 for irq 31 failed
   (mpc8xxx_irq_set_type+0x0/0xec)
   [   22.078010] genirq: Setting trigger mode 0 for irq 32 failed
   (mpc8xxx_irq_set_type+0x0/0xec)
   [   22.086576] genirq: Setting trigger mode 0 for irq 33 failed
   (mpc8xxx_irq_set_type+0x0/0xec)
   [   22.095143] genirq: Setting trigger mode 0 for irq 37 failed
   (mpc8xxx_irq_set_type+0x0/0xec)
   [   22.103715] genirq: Setting trigger mode 0 for irq 38 failed
   (mpc8xxx_irq_set_type+0x0/0xec)
   [   22.112282] genirq: Setting trigger mode 0 for irq 39 failed
   (mpc8xxx_irq_set_type+0x0/0xec)
 
  Hmm, I don't know much about IRQ issues.
 
   [   37.945785] pci :00:00.0: ignoring class 0x0b2000 (doesn't
   match header type 01)
 
  There's a recent patch related to this:
  http://lkml.kernel.org/r/1374823418-1550-1-git-send-email-chunhe@freescale.com
 
   [   37.953640] PCIE error(s) detected
   [   37.953858] pci :00:00.0: PCI bridge to [bus 01-ff]
   [   37.953988] pci :00:00.0: BAR 8: assigned [mem 
   0xc000-0xdfff]
   [   37.953994] pci :00:00.0: BAR 7: can't assign io (size 0x1)
   [   37.954000] pci :01:00.0: BAR 0: assigned [mem 
   0xc000-0xc00f]
   [   37.954013] pci :01:00.0: BAR 1: assigned [mem 
   0xc010-0xc017]
   [   37.954025] pci :01:00.0: BAR 2: assigned [mem 
   0xc018-0xc01f]
   [   37.954036] pci :00:00.0: PCI bridge to [bus 01]
   [   37.954041] pci :00:00.0:   bridge window [mem 
   0xc000-0xdfff]
   [   38.007354] PCIE ERR_DR register: 0x8002
   [   38.011613] PCIE ERR_CAP_STAT register: 0x0041
   [   38.016392] PCIE ERR_CAP_R0 register: 0x0800
   [   38.020997] PCIE ERR_CAP_R1 register: 0x
   [   38.025602] PCIE ERR_CAP_R2 register: 0x
   [   38.030207] PCIE ERR_CAP_R3 register: 0x
  
  
   and after a few minutes I linux reboot it self,
  
  
   where can I start debugging it??
 
  I'd start by applying the header quirk patch above, then comparing the
  complete console log (boot with ignore_loglevel) from 2.6.32 and
  3.8.13.
 
  Bjorn
  ___
  Linuxppc-dev mailing list
  Linuxppc-dev@lists.ozlabs.org
  https://lists.ozlabs.org/listinfo/linuxppc-dev
 
  Hi,
 
  I have a similar problem here on a P4080 based board with the same 3.8 
  Kernel
  from freescale git. Does your system panic (maybe due to a machine check
  exception)?  If yes could it be the first read from the PCI device?
 
  Johannes



 --
 Leonid Ravich



-- 
Leonid Ravich
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 0/3] powerpc: several patches for icache flush

2013-08-06 Thread Kevin Hao
These patches passed the build test with the following configurations.
ppc40x_defconfig
ppc64e_defconfig
ppc64_defconfig
mpc85xx_defconfig
mpc85xx_smp_defconfig
corenet32_smp_defconfig
corenet64_smp_defconfig
ppc44x_defconfig
mpc885_ads_defconfig
pseries_defconfig

Boot test on a p5020ds board.

---
Kevin Hao (3):
  powerpc: move the testing of CPU_FTR_COHERENT_ICACHE into
__flush_icache_range
  powerpc: remove the symbol __flush_icache_range
  powerpc: check CPU_FTR_COHERENT_ICACHE in __flush_dcache_icache for   
 64bit kernel

 arch/powerpc/include/asm/cacheflush.h | 8 +---
 arch/powerpc/kernel/misc_32.S | 2 +-
 arch/powerpc/kernel/misc_64.S | 9 +++--
 arch/powerpc/kernel/ppc_ksyms.c   | 1 -
 4 files changed, 9 insertions(+), 11 deletions(-)

-- 
1.8.3.1

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 1/3] powerpc: move the testing of CPU_FTR_COHERENT_ICACHE into __flush_icache_range

2013-08-06 Thread Kevin Hao
In function flush_icache_range(), we use cpu_has_feature() to test
the feature bit of CPU_FTR_COHERENT_ICACHE. But this seems not optimal
for two reasons:
 a) For ppc32, the function __flush_icache_range() already do this
check with the macro END_FTR_SECTION_IFSET.
 b) Compare with the cpu_has_feature(), the method of using macro
END_FTR_SECTION_IFSET will not introduce any runtime overhead.

Signed-off-by: Kevin Hao haoke...@gmail.com
---
 arch/powerpc/include/asm/cacheflush.h | 3 +--
 arch/powerpc/kernel/misc_64.S | 4 +++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/include/asm/cacheflush.h 
b/arch/powerpc/include/asm/cacheflush.h
index b843e35..60b620d 100644
--- a/arch/powerpc/include/asm/cacheflush.h
+++ b/arch/powerpc/include/asm/cacheflush.h
@@ -35,8 +35,7 @@ extern void __flush_disable_L1(void);
 extern void __flush_icache_range(unsigned long, unsigned long);
 static inline void flush_icache_range(unsigned long start, unsigned long stop)
 {
-   if (!cpu_has_feature(CPU_FTR_COHERENT_ICACHE))
-   __flush_icache_range(start, stop);
+   __flush_icache_range(start, stop);
 }
 
 extern void flush_icache_user_range(struct vm_area_struct *vma,
diff --git a/arch/powerpc/kernel/misc_64.S b/arch/powerpc/kernel/misc_64.S
index 6820e45..74d87f1 100644
--- a/arch/powerpc/kernel/misc_64.S
+++ b/arch/powerpc/kernel/misc_64.S
@@ -68,7 +68,9 @@ PPC64_CACHES:
  */
 
 _KPROBE(__flush_icache_range)
-
+BEGIN_FTR_SECTION
+   blr
+END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
 /*
  * Flush the data cache to memory 
  * 
-- 
1.8.3.1

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 2/3] powerpc: remove the symbol __flush_icache_range

2013-08-06 Thread Kevin Hao
And now the function flush_icache_range() is just a wrapper which
only invoke the function __flush_icache_range() directly. So we
don't have reason to keep it anymore.

Signed-off-by: Kevin Hao haoke...@gmail.com
---
 arch/powerpc/include/asm/cacheflush.h | 7 +--
 arch/powerpc/kernel/misc_32.S | 2 +-
 arch/powerpc/kernel/misc_64.S | 2 +-
 arch/powerpc/kernel/ppc_ksyms.c   | 1 -
 4 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/include/asm/cacheflush.h 
b/arch/powerpc/include/asm/cacheflush.h
index 60b620d..5b93122 100644
--- a/arch/powerpc/include/asm/cacheflush.h
+++ b/arch/powerpc/include/asm/cacheflush.h
@@ -32,12 +32,7 @@ extern void flush_dcache_page(struct page *page);
 
 extern void __flush_disable_L1(void);
 
-extern void __flush_icache_range(unsigned long, unsigned long);
-static inline void flush_icache_range(unsigned long start, unsigned long stop)
-{
-   __flush_icache_range(start, stop);
-}
-
+extern void flush_icache_range(unsigned long, unsigned long);
 extern void flush_icache_user_range(struct vm_area_struct *vma,
struct page *page, unsigned long addr,
int len);
diff --git a/arch/powerpc/kernel/misc_32.S b/arch/powerpc/kernel/misc_32.S
index e469f30..3f70dbf 100644
--- a/arch/powerpc/kernel/misc_32.S
+++ b/arch/powerpc/kernel/misc_32.S
@@ -327,7 +327,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_UNIFIED_ID_CACHE)
  *
  * flush_icache_range(unsigned long start, unsigned long stop)
  */
-_KPROBE(__flush_icache_range)
+_KPROBE(flush_icache_range)
 BEGIN_FTR_SECTION
blr /* for 601, do nothing */
 END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
diff --git a/arch/powerpc/kernel/misc_64.S b/arch/powerpc/kernel/misc_64.S
index 74d87f1..a781566 100644
--- a/arch/powerpc/kernel/misc_64.S
+++ b/arch/powerpc/kernel/misc_64.S
@@ -67,7 +67,7 @@ PPC64_CACHES:
  *   flush all bytes from start through stop-1 inclusive
  */
 
-_KPROBE(__flush_icache_range)
+_KPROBE(flush_icache_range)
 BEGIN_FTR_SECTION
blr
 END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
diff --git a/arch/powerpc/kernel/ppc_ksyms.c b/arch/powerpc/kernel/ppc_ksyms.c
index c296665..380a6f9 100644
--- a/arch/powerpc/kernel/ppc_ksyms.c
+++ b/arch/powerpc/kernel/ppc_ksyms.c
@@ -111,7 +111,6 @@ EXPORT_SYMBOL(giveup_spe);
 #ifndef CONFIG_PPC64
 EXPORT_SYMBOL(flush_instruction_cache);
 #endif
-EXPORT_SYMBOL(__flush_icache_range);
 EXPORT_SYMBOL(flush_dcache_range);
 
 #ifdef CONFIG_SMP
-- 
1.8.3.1

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [PATCH 1/3] powerpc: move the testing of CPU_FTR_COHERENT_ICACHE into __flush_icache_range

2013-08-06 Thread Benjamin Herrenschmidt
On Tue, 2013-08-06 at 18:23 +0800, Kevin Hao wrote:
 In function flush_icache_range(), we use cpu_has_feature() to test
 the feature bit of CPU_FTR_COHERENT_ICACHE. But this seems not optimal
 for two reasons:
  a) For ppc32, the function __flush_icache_range() already do this
 check with the macro END_FTR_SECTION_IFSET.
  b) Compare with the cpu_has_feature(), the method of using macro
 END_FTR_SECTION_IFSET will not introduce any runtime overhead.

Nak.

It adds the overhead of calling into a function :-)

What about modifying cpu_has_feature to use jump labels ? It might solve
the problem of no runtime overhead ... however it might also be hard to
keep the ability to remove the whole statement at compile time if the
bit doesn't fit in the POSSIBLE mask... unless you find the right macro
magic.

In any case, I suspect the function call introduces more overhead than
the bit test + conditional branch which will generally predict very
well, so the patch as-is is probably a regression.

Did you measure ?

Ben.


 Signed-off-by: Kevin Hao haoke...@gmail.com
 ---
  arch/powerpc/include/asm/cacheflush.h | 3 +--
  arch/powerpc/kernel/misc_64.S | 4 +++-
  2 files changed, 4 insertions(+), 3 deletions(-)
 
 diff --git a/arch/powerpc/include/asm/cacheflush.h 
 b/arch/powerpc/include/asm/cacheflush.h
 index b843e35..60b620d 100644
 --- a/arch/powerpc/include/asm/cacheflush.h
 +++ b/arch/powerpc/include/asm/cacheflush.h
 @@ -35,8 +35,7 @@ extern void __flush_disable_L1(void);
  extern void __flush_icache_range(unsigned long, unsigned long);
  static inline void flush_icache_range(unsigned long start, unsigned long 
 stop)
  {
 - if (!cpu_has_feature(CPU_FTR_COHERENT_ICACHE))
 - __flush_icache_range(start, stop);
 + __flush_icache_range(start, stop);
  }
  
  extern void flush_icache_user_range(struct vm_area_struct *vma,
 diff --git a/arch/powerpc/kernel/misc_64.S b/arch/powerpc/kernel/misc_64.S
 index 6820e45..74d87f1 100644
 --- a/arch/powerpc/kernel/misc_64.S
 +++ b/arch/powerpc/kernel/misc_64.S
 @@ -68,7 +68,9 @@ PPC64_CACHES:
   */
  
  _KPROBE(__flush_icache_range)
 -
 +BEGIN_FTR_SECTION
 + blr
 +END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  /*
   * Flush the data cache to memory 
   * 


___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [PATCH 3/3] powerpc: check CPU_FTR_COHERENT_ICACHE in __flush_dcache_icache for 64bit kernel

2013-08-06 Thread Benjamin Herrenschmidt
On Tue, 2013-08-06 at 18:23 +0800, Kevin Hao wrote:
 We don't need to flush the dcache and invalidate the icache on the
 CPU which has CPU_FTR_COHERENT_ICACHE set.

Actually we probably need an isync...

Ben.

 Signed-off-by: Kevin Hao haoke...@gmail.com
 ---
  arch/powerpc/kernel/misc_64.S | 3 +++
  1 file changed, 3 insertions(+)
 
 diff --git a/arch/powerpc/kernel/misc_64.S b/arch/powerpc/kernel/misc_64.S
 index a781566..32e78e2 100644
 --- a/arch/powerpc/kernel/misc_64.S
 +++ b/arch/powerpc/kernel/misc_64.S
 @@ -207,6 +207,9 @@ _GLOBAL(flush_inval_dcache_range)
   *   void __flush_dcache_icache(void *page)
   */
  _GLOBAL(__flush_dcache_icache)
 +BEGIN_FTR_SECTION
 + blr
 +END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  /*
   * Flush the data cache to memory 
   * 


___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH] powerpc: Convert out of line __arch_hweight to inline

2013-08-06 Thread Madhavan Srinivasan
Patch attempts to improve the performace of __arch_hweight functions by
making them inline instead of current out of line implementation.

Testcase is to disable/enable SMT on a large (192 thread) POWER7 lpar.
Program used for SMT disable/enable is ppc64_cpu with --smt=[off/on]
option. Here are the perf output. In this case, __arch_hweight64 is
called by __bitmap_weight.

Without patch (ppc64_cpu --smt=off):

 17.60%  ppc64_cpu  [kernel.kallsyms]   [k] .deactivate_slab

  4.85%  ppc64_cpu  [kernel.kallsyms]   [k] .__bitmap_weight

  1.36%  ppc64_cpu  [kernel.kallsyms]   [k] .__disable_runtime
  1.29%  ppc64_cpu  [kernel.kallsyms]   [k] .__arch_hweight64


With patch (ppc64_cpu --smt=off):

 17.29%  ppc64_cpu  [kernel.kallsyms]   [k] .deactivate_slab

  3.71%  ppc64_cpu  [kernel.kallsyms]   [k] .__bitmap_weight
  3.26%  ppc64_cpu  [kernel.kallsyms]   [k]
.build_overlap_sched_groups


Without patch (ppc64_cpu --smt=on):

  8.35%  ppc64_cpu  [kernel.kallsyms]   [k] .strlen
  7.00%  ppc64_cpu  [kernel.kallsyms]   [k] .memset
  6.78%  ppc64_cpu  [kernel.kallsyms]   [k] .__bitmap_weight
  4.23%  ppc64_cpu  [kernel.kallsyms]   [k] .deactivate_slab

  1.58%  ppc64_cpu  [kernel.kallsyms]   [k]
.refresh_zone_stat_thresholds
  1.57%  ppc64_cpu  [kernel.kallsyms]   [k] .__arch_hweight64
  1.54%  ppc64_cpu  [kernel.kallsyms]   [k] .__enable_runtime


With patch (ppc64_cpu --smt=on):

  9.44%  ppc64_cpu  [kernel.kallsyms]   [k] .strlen
  6.43%  ppc64_cpu  [kernel.kallsyms]   [k] .memset
  5.48%  ppc64_cpu  [kernel.kallsyms]   [k] .__bitmap_weight
  4.59%  ppc64_cpu  [kernel.kallsyms]   [k] .insert_entry
  4.29%  ppc64_cpu  [kernel.kallsyms]   [k] .deactivate_slab


Signed-off-by: Madhavan Srinivasan ma...@linux.vnet.ibm.com
---
 arch/powerpc/include/asm/bitops.h |  130 -
 arch/powerpc/include/asm/ppc-opcode.h |6 ++
 arch/powerpc/lib/Makefile |2 +-
 3 files changed, 133 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/include/asm/bitops.h 
b/arch/powerpc/include/asm/bitops.h
index 910194e..136fe6a 100644
--- a/arch/powerpc/include/asm/bitops.h
+++ b/arch/powerpc/include/asm/bitops.h
@@ -43,8 +43,10 @@
 #endif
 
 #include linux/compiler.h
+#include linux/types.h
 #include asm/asm-compat.h
 #include asm/synch.h
+#include asm/cputable.h
 
 /*
  * clear_bit doesn't imply a memory barrier
@@ -263,10 +265,130 @@ static __inline__ int fls64(__u64 x)
 #endif /* __powerpc64__ */
 
 #ifdef CONFIG_PPC64
-unsigned int __arch_hweight8(unsigned int w);
-unsigned int __arch_hweight16(unsigned int w);
-unsigned int __arch_hweight32(unsigned int w);
-unsigned long __arch_hweight64(__u64 w);
+
+static inline unsigned int __arch_hweight8(unsigned int w)
+{
+   unsigned int register iop asm(r3) = w;
+   unsigned int register tmp asm(r4);
+   __asm__ __volatile__ (
+   stringify_in_c(BEGIN_FTR_SECTION)
+   bl .__sw_hweight8;
+   nop;
+   stringify_in_c(FTR_SECTION_ELSE)
+   PPC_POPCNTB_M(%1,%2) ;
+   clrldi %0,%1,64-8;
+   stringify_in_c(ALT_FTR_SECTION_END_IFCLR((%3)))
+   : =r (iop), =r (tmp)
+   : r (iop), i (CPU_FTR_POPCNTB)
+   : r0, r1, r5, r6, r7, r8, r9,
+   r10, r11, r12, r13, r31, lr, cr0, xer);
+
+   return iop;
+}
+
+static inline unsigned int __arch_hweight16(unsigned int w)
+{
+   unsigned int register iop asm(r3) = w;
+   unsigned int register tmp asm(r4);
+   __asm__ __volatile__ (
+   stringify_in_c(BEGIN_FTR_SECTION)
+   bl .__sw_hweight16;
+   nop;
+   nop;
+   nop;
+   nop;
+   stringify_in_c(FTR_SECTION_ELSE)
+   stringify_in_c(BEGIN_FTR_SECTION_NESTED(50))
+   PPC_POPCNTB_M(%0,%2) ;
+   srdi %1,%0,8;
+   add %0,%1,%0;
+   clrldi %0,%0,64-8;
+   stringify_in_c(FTR_SECTION_ELSE_NESTED(50))
+   clrlwi %0,%2,16;
+   PPC_POPCNTW_M(%1,%0) ;
+   clrldi %0,%1,64-8;
+   stringify_in_c(ALT_FTR_SECTION_END_NESTED_IFCLR(%4,50))
+   stringify_in_c(ALT_FTR_SECTION_END_IFCLR((%3)))
+   : =r (iop), =r (tmp)
+   : r (iop), i (CPU_FTR_POPCNTB), i (CPU_FTR_POPCNTD)
+   : r0, r1, r5, r6, r7, r8, r9,
+   r10, r11, r12, r13, r31, lr, cr0, xer);
+
+   return iop;
+}
+
+static inline unsigned int __arch_hweight32(unsigned int w)
+{
+   unsigned int register iop asm(r3) = w;
+   unsigned int register tmp asm(r4);
+   __asm__ __volatile__ (
+   stringify_in_c(BEGIN_FTR_SECTION)
+   bl .__sw_hweight32;
+   nop;
+   nop;
+   nop;
+   nop;
+   nop;
+   nop;
+   stringify_in_c(FTR_SECTION_ELSE)
+   

[PATCH 2/6 v3] kvm: powerpc: allow guest control E attribute in mas2

2013-08-06 Thread Bharat Bhushan
E bit in MAS2 bit indicates whether the page is accessed
in Little-Endian or Big-Endian byte order.
There is no reason to stop guest setting  E, so allow him.

Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
---
v2-v3
 - no change
v1-v2
 - no change
 arch/powerpc/kvm/e500.h |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kvm/e500.h b/arch/powerpc/kvm/e500.h
index c2e5e98..277cb18 100644
--- a/arch/powerpc/kvm/e500.h
+++ b/arch/powerpc/kvm/e500.h
@@ -117,7 +117,7 @@ static inline struct kvmppc_vcpu_e500 *to_e500(struct 
kvm_vcpu *vcpu)
 #define E500_TLB_USER_PERM_MASK (MAS3_UX|MAS3_UR|MAS3_UW)
 #define E500_TLB_SUPER_PERM_MASK (MAS3_SX|MAS3_SR|MAS3_SW)
 #define MAS2_ATTRIB_MASK \
- (MAS2_X0 | MAS2_X1)
+ (MAS2_X0 | MAS2_X1 | MAS2_E)
 #define MAS3_ATTRIB_MASK \
  (MAS3_U0 | MAS3_U1 | MAS3_U2 | MAS3_U3 \
   | E500_TLB_USER_PERM_MASK | E500_TLB_SUPER_PERM_MASK)
-- 
1.7.0.4


___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 1/6 v3] powerpc: book3e: _PAGE_LENDIAN must be _PAGE_ENDIAN

2013-08-06 Thread Bharat Bhushan
For booke3e _PAGE_ENDIAN is not defined. Infact what is defined
is _PAGE_LENDIAN which is wrong and should be _PAGE_ENDIAN.
There are no compilation errors as
arch/powerpc/include/asm/pte-common.h defines _PAGE_ENDIAN to 0
as it is not defined anywhere.

Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
---
v2-v3
 - no change
v1-v2
 - no change

 arch/powerpc/include/asm/pte-book3e.h |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/include/asm/pte-book3e.h 
b/arch/powerpc/include/asm/pte-book3e.h
index 0156702..576ad88 100644
--- a/arch/powerpc/include/asm/pte-book3e.h
+++ b/arch/powerpc/include/asm/pte-book3e.h
@@ -40,7 +40,7 @@
 #define _PAGE_U1   0x01
 #define _PAGE_U0   0x02
 #define _PAGE_ACCESSED 0x04
-#define _PAGE_LENDIAN  0x08
+#define _PAGE_ENDIAN   0x08
 #define _PAGE_GUARDED  0x10
 #define _PAGE_COHERENT 0x20 /* M: enforce memory coherence */
 #define _PAGE_NO_CACHE 0x40 /* I: cache inhibit */
-- 
1.7.0.4


___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 0/6 v3] kvm: powerpc: use cache attributes from linux pte

2013-08-06 Thread Bharat Bhushan
From: Bharat Bhushan bharat.bhus...@freescale.com

First patch is a typo fix where book3e define _PAGE_LENDIAN while it should be
defined as _PAGE_ENDIAN. This seems to show that this is never exercised :-)

Second and third patch is to allow guest controlling G-Guarded and
E-Endian TLB attributes respectively.

Fourth and fifth patch is moving functions/logic in common code
so they can be used on booke also.

Sixth patch is actually setting caching attributes (TLB.WIMGE) using
corresponding Linux pte.

v2-v3
 - now lookup_linux_pte() only have pte search logic and it does not
   set any access flags in pte. There is already a function for setting
   access flag which will be called explicitly where needed.
   On booke we only need to search for pte to get WIMG.

v1-v2
 - Earlier caching attributes (WIMGE) were set based of page is RAM or not
   But now we get these attributes from corresponding Linux PTE.

Bharat Bhushan (6):
  powerpc: book3e: _PAGE_LENDIAN must be _PAGE_ENDIAN
  kvm: powerpc: allow guest control E attribute in mas2
  kvm: powerpc: allow guest control G attribute in mas2
  powerpc: move linux pte/hugepte search to more generic file
  kvm: powerpc: keep only pte search logic in lookup_linux_pte
  kvm: powerpc: use caching attributes as per linux pte

 arch/powerpc/include/asm/kvm_host.h  |2 +-
 arch/powerpc/include/asm/pgtable-ppc64.h |   36 --
 arch/powerpc/include/asm/pgtable.h   |   60 ++
 arch/powerpc/include/asm/pte-book3e.h|2 +-
 arch/powerpc/kvm/book3s_hv_rm_mmu.c  |   38 ++-
 arch/powerpc/kvm/booke.c |2 +-
 arch/powerpc/kvm/e500.h  |   10 +++--
 arch/powerpc/kvm/e500_mmu_host.c |   36 ++---
 8 files changed, 102 insertions(+), 84 deletions(-)


___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 3/6 v3] kvm: powerpc: allow guest control G attribute in mas2

2013-08-06 Thread Bharat Bhushan
G bit in MAS2 indicates whether the page is Guarded.
There is no reason to stop guest setting  G, so allow him.

Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
---
v2-v3
 - no change
v1-v2
 - no change
 arch/powerpc/kvm/e500.h |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kvm/e500.h b/arch/powerpc/kvm/e500.h
index 277cb18..4fd9650 100644
--- a/arch/powerpc/kvm/e500.h
+++ b/arch/powerpc/kvm/e500.h
@@ -117,7 +117,7 @@ static inline struct kvmppc_vcpu_e500 *to_e500(struct 
kvm_vcpu *vcpu)
 #define E500_TLB_USER_PERM_MASK (MAS3_UX|MAS3_UR|MAS3_UW)
 #define E500_TLB_SUPER_PERM_MASK (MAS3_SX|MAS3_SR|MAS3_SW)
 #define MAS2_ATTRIB_MASK \
- (MAS2_X0 | MAS2_X1 | MAS2_E)
+ (MAS2_X0 | MAS2_X1 | MAS2_E | MAS2_G)
 #define MAS3_ATTRIB_MASK \
  (MAS3_U0 | MAS3_U1 | MAS3_U2 | MAS3_U3 \
   | E500_TLB_USER_PERM_MASK | E500_TLB_SUPER_PERM_MASK)
-- 
1.7.0.4


___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 4/6 v3] powerpc: move linux pte/hugepte search to more generic file

2013-08-06 Thread Bharat Bhushan
Linux pte search functions find_linux_pte_or_hugepte() and
find_linux_pte() have nothing specific to 64bit anymore.
So they are move from pgtable-ppc64.h to asm/pgtable.h

Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
---
v2-v3
 - no change
v1-v2
 - This is a new change in this version
 
 arch/powerpc/include/asm/pgtable-ppc64.h |   36 -
 arch/powerpc/include/asm/pgtable.h   |   37 ++
 2 files changed, 37 insertions(+), 36 deletions(-)

diff --git a/arch/powerpc/include/asm/pgtable-ppc64.h 
b/arch/powerpc/include/asm/pgtable-ppc64.h
index e3d55f6..d257d98 100644
--- a/arch/powerpc/include/asm/pgtable-ppc64.h
+++ b/arch/powerpc/include/asm/pgtable-ppc64.h
@@ -340,42 +340,6 @@ static inline void __ptep_set_access_flags(pte_t *ptep, 
pte_t entry)
 void pgtable_cache_add(unsigned shift, void (*ctor)(void *));
 void pgtable_cache_init(void);
 
-/*
- * find_linux_pte returns the address of a linux pte for a given
- * effective address and directory.  If not found, it returns zero.
- */
-static inline pte_t *find_linux_pte(pgd_t *pgdir, unsigned long ea)
-{
-   pgd_t *pg;
-   pud_t *pu;
-   pmd_t *pm;
-   pte_t *pt = NULL;
-
-   pg = pgdir + pgd_index(ea);
-   if (!pgd_none(*pg)) {
-   pu = pud_offset(pg, ea);
-   if (!pud_none(*pu)) {
-   pm = pmd_offset(pu, ea);
-   if (pmd_present(*pm))
-   pt = pte_offset_kernel(pm, ea);
-   }
-   }
-   return pt;
-}
-
-#ifdef CONFIG_HUGETLB_PAGE
-pte_t *find_linux_pte_or_hugepte(pgd_t *pgdir, unsigned long ea,
-unsigned *shift);
-#else
-static inline pte_t *find_linux_pte_or_hugepte(pgd_t *pgdir, unsigned long ea,
-  unsigned *shift)
-{
-   if (shift)
-   *shift = 0;
-   return find_linux_pte(pgdir, ea);
-}
-#endif /* !CONFIG_HUGETLB_PAGE */
-
 #endif /* __ASSEMBLY__ */
 
 #endif /* _ASM_POWERPC_PGTABLE_PPC64_H_ */
diff --git a/arch/powerpc/include/asm/pgtable.h 
b/arch/powerpc/include/asm/pgtable.h
index b6293d2..690c8c2 100644
--- a/arch/powerpc/include/asm/pgtable.h
+++ b/arch/powerpc/include/asm/pgtable.h
@@ -217,6 +217,43 @@ extern int gup_hugepd(hugepd_t *hugepd, unsigned pdshift, 
unsigned long addr,
 
 extern int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr,
   unsigned long end, int write, struct page **pages, int 
*nr);
+
+/*
+ * find_linux_pte returns the address of a linux pte for a given
+ * effective address and directory.  If not found, it returns zero.
+ */
+static inline pte_t *find_linux_pte(pgd_t *pgdir, unsigned long ea)
+{
+   pgd_t *pg;
+   pud_t *pu;
+   pmd_t *pm;
+   pte_t *pt = NULL;
+
+   pg = pgdir + pgd_index(ea);
+   if (!pgd_none(*pg)) {
+   pu = pud_offset(pg, ea);
+   if (!pud_none(*pu)) {
+   pm = pmd_offset(pu, ea);
+   if (pmd_present(*pm))
+   pt = pte_offset_kernel(pm, ea);
+   }
+   }
+   return pt;
+}
+
+#ifdef CONFIG_HUGETLB_PAGE
+pte_t *find_linux_pte_or_hugepte(pgd_t *pgdir, unsigned long ea,
+unsigned *shift);
+#else
+static inline pte_t *find_linux_pte_or_hugepte(pgd_t *pgdir, unsigned long ea,
+  unsigned *shift)
+{
+   if (shift)
+   *shift = 0;
+   return find_linux_pte(pgdir, ea);
+}
+#endif /* !CONFIG_HUGETLB_PAGE */
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* __KERNEL__ */
-- 
1.7.0.4


___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 6/6 v3] kvm: powerpc: use caching attributes as per linux pte

2013-08-06 Thread Bharat Bhushan
KVM uses same WIM tlb attributes as the corresponding qemu pte.
For this we now search the linux pte for the requested page and
get these cache caching/coherency attributes from pte.

Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
---
v2-v3
 - setting pgdir before kvmppc_fix_ee_before_entry() on vcpu_run
 - Aligned as per changes in patch 5/6
 - setting WIMG for pfnmap pages also
 
v1-v2
 - Use Linux pte for wimge rather than RAM/no-RAM mechanism

 arch/powerpc/include/asm/kvm_host.h |2 +-
 arch/powerpc/kvm/booke.c|2 +-
 arch/powerpc/kvm/e500.h |8 --
 arch/powerpc/kvm/e500_mmu_host.c|   36 --
 4 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index 3328353..583d405 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -535,6 +535,7 @@ struct kvm_vcpu_arch {
 #endif
gpa_t paddr_accessed;
gva_t vaddr_accessed;
+   pgd_t *pgdir;
 
u8 io_gpr; /* GPR used as IO source/target */
u8 mmio_is_bigendian;
@@ -592,7 +593,6 @@ struct kvm_vcpu_arch {
struct list_head run_list;
struct task_struct *run_task;
struct kvm_run *kvm_run;
-   pgd_t *pgdir;
 
spinlock_t vpa_update_lock;
struct kvmppc_vpa vpa;
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 17722d8..0d96d50 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -696,8 +696,8 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
kvmppc_load_guest_fp(vcpu);
 #endif
 
+   vcpu-arch.pgdir = current-mm-pgd;
kvmppc_fix_ee_before_entry();
-
ret = __kvmppc_vcpu_run(kvm_run, vcpu);
 
/* No need for kvm_guest_exit. It's done in handle_exit.
diff --git a/arch/powerpc/kvm/e500.h b/arch/powerpc/kvm/e500.h
index 4fd9650..fc4b2f6 100644
--- a/arch/powerpc/kvm/e500.h
+++ b/arch/powerpc/kvm/e500.h
@@ -31,11 +31,13 @@ enum vcpu_ftr {
 #define E500_TLB_NUM   2
 
 /* entry is mapped somewhere in host TLB */
-#define E500_TLB_VALID (1  0)
+#define E500_TLB_VALID (1  31)
 /* TLB1 entry is mapped by host TLB1, tracked by bitmaps */
-#define E500_TLB_BITMAP(1  1)
+#define E500_TLB_BITMAP(1  30)
 /* TLB1 entry is mapped by host TLB0 */
-#define E500_TLB_TLB0  (1  2)
+#define E500_TLB_TLB0  (1  29)
+/* Lower 5 bits have WIMGE value */
+#define E500_TLB_WIMGE_MASK(0x1f)
 
 struct tlbe_ref {
pfn_t pfn;  /* valid only for TLB0, except briefly */
diff --git a/arch/powerpc/kvm/e500_mmu_host.c b/arch/powerpc/kvm/e500_mmu_host.c
index 1c6a9d7..001a2b0 100644
--- a/arch/powerpc/kvm/e500_mmu_host.c
+++ b/arch/powerpc/kvm/e500_mmu_host.c
@@ -64,15 +64,6 @@ static inline u32 e500_shadow_mas3_attrib(u32 mas3, int 
usermode)
return mas3;
 }
 
-static inline u32 e500_shadow_mas2_attrib(u32 mas2, int usermode)
-{
-#ifdef CONFIG_SMP
-   return (mas2  MAS2_ATTRIB_MASK) | MAS2_M;
-#else
-   return mas2  MAS2_ATTRIB_MASK;
-#endif
-}
-
 /*
  * writing shadow tlb entry to host TLB
  */
@@ -248,10 +239,12 @@ static inline int tlbe_is_writable(struct 
kvm_book3e_206_tlb_entry *tlbe)
 
 static inline void kvmppc_e500_ref_setup(struct tlbe_ref *ref,
 struct kvm_book3e_206_tlb_entry *gtlbe,
-pfn_t pfn)
+pfn_t pfn, int wimg)
 {
ref-pfn = pfn;
ref-flags |= E500_TLB_VALID;
+   /* Use guest supplied MAS2_G and MAS2_E */
+   ref-flags |= (gtlbe-mas2  MAS2_ATTRIB_MASK) | wimg;
 
if (tlbe_is_writable(gtlbe))
kvm_set_pfn_dirty(pfn);
@@ -312,8 +305,7 @@ static void kvmppc_e500_setup_stlbe(
 
/* Force IPROT=0 for all guest mappings. */
stlbe-mas1 = MAS1_TSIZE(tsize) | get_tlb_sts(gtlbe) | MAS1_VALID;
-   stlbe-mas2 = (gvaddr  MAS2_EPN) |
- e500_shadow_mas2_attrib(gtlbe-mas2, pr);
+   stlbe-mas2 = (gvaddr  MAS2_EPN) | (ref-flags  E500_TLB_WIMGE_MASK);
stlbe-mas7_3 = ((u64)pfn  PAGE_SHIFT) |
e500_shadow_mas3_attrib(gtlbe-mas7_3, pr);
 
@@ -332,6 +324,10 @@ static inline int kvmppc_e500_shadow_map(struct 
kvmppc_vcpu_e500 *vcpu_e500,
unsigned long hva;
int pfnmap = 0;
int tsize = BOOK3E_PAGESZ_4K;
+   unsigned long tsize_pages = 0;
+   pte_t *ptep;
+   int wimg = 0;
+   pgd_t *pgdir;
 
/*
 * Translate guest physical to true physical, acquiring
@@ -394,7 +390,7 @@ static inline int kvmppc_e500_shadow_map(struct 
kvmppc_vcpu_e500 *vcpu_e500,
 */
 
for (; tsize  BOOK3E_PAGESZ_4K; tsize -= 2) {
-   unsigned long gfn_start, gfn_end, tsize_pages;
+  

[PATCH 5/6 v3] kvm: powerpc: keep only pte search logic in lookup_linux_pte

2013-08-06 Thread Bharat Bhushan
lookup_linux_pte() was searching for a pte and also sets access
flags is writable. This function now searches only pte while
access flag setting is done explicitly.

This pte lookup is not kvm specific, so moved to common code (asm/pgtable.h)
My Followup patch will use this on booke.

Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
---
v2-v3
 - New change

 arch/powerpc/include/asm/pgtable.h  |   23 +
 arch/powerpc/kvm/book3s_hv_rm_mmu.c |   38 +++---
 2 files changed, 35 insertions(+), 26 deletions(-)

diff --git a/arch/powerpc/include/asm/pgtable.h 
b/arch/powerpc/include/asm/pgtable.h
index 690c8c2..d4d16ab 100644
--- a/arch/powerpc/include/asm/pgtable.h
+++ b/arch/powerpc/include/asm/pgtable.h
@@ -254,6 +254,29 @@ static inline pte_t *find_linux_pte_or_hugepte(pgd_t 
*pgdir, unsigned long ea,
 }
 #endif /* !CONFIG_HUGETLB_PAGE */
 
+static inline pte_t *lookup_linux_pte(pgd_t *pgdir, unsigned long hva,
+unsigned long *pte_sizep)
+{
+   pte_t *ptep;
+   unsigned long ps = *pte_sizep;
+   unsigned int shift;
+
+   ptep = find_linux_pte_or_hugepte(pgdir, hva, shift);
+   if (!ptep)
+   return __pte(0);
+   if (shift)
+   *pte_sizep = 1ul  shift;
+   else
+   *pte_sizep = PAGE_SIZE;
+
+   if (ps  *pte_sizep)
+   return __pte(0);
+
+   if (!pte_present(*ptep))
+   return __pte(0);
+
+   return ptep;
+}
 #endif /* __ASSEMBLY__ */
 
 #endif /* __KERNEL__ */
diff --git a/arch/powerpc/kvm/book3s_hv_rm_mmu.c 
b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
index 105b00f..7e6200c 100644
--- a/arch/powerpc/kvm/book3s_hv_rm_mmu.c
+++ b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
@@ -134,27 +134,6 @@ static void remove_revmap_chain(struct kvm *kvm, long 
pte_index,
unlock_rmap(rmap);
 }
 
-static pte_t lookup_linux_pte(pgd_t *pgdir, unsigned long hva,
- int writing, unsigned long *pte_sizep)
-{
-   pte_t *ptep;
-   unsigned long ps = *pte_sizep;
-   unsigned int shift;
-
-   ptep = find_linux_pte_or_hugepte(pgdir, hva, shift);
-   if (!ptep)
-   return __pte(0);
-   if (shift)
-   *pte_sizep = 1ul  shift;
-   else
-   *pte_sizep = PAGE_SIZE;
-   if (ps  *pte_sizep)
-   return __pte(0);
-   if (!pte_present(*ptep))
-   return __pte(0);
-   return kvmppc_read_update_linux_pte(ptep, writing);
-}
-
 static inline void unlock_hpte(unsigned long *hpte, unsigned long hpte_v)
 {
asm volatile(PPC_RELEASE_BARRIER  : : : memory);
@@ -174,6 +153,7 @@ long kvmppc_do_h_enter(struct kvm *kvm, unsigned long flags,
unsigned long *physp, pte_size;
unsigned long is_io;
unsigned long *rmap;
+   pte_t *ptep;
pte_t pte;
unsigned int writing;
unsigned long mmu_seq;
@@ -233,8 +213,9 @@ long kvmppc_do_h_enter(struct kvm *kvm, unsigned long flags,
 
/* Look up the Linux PTE for the backing page */
pte_size = psize;
-   pte = lookup_linux_pte(pgdir, hva, writing, pte_size);
-   if (pte_present(pte)) {
+   ptep = lookup_linux_pte(pgdir, hva, pte_size);
+   if (pte_present(pte_val(*ptep))) {
+   pte = kvmppc_read_update_linux_pte(ptep, writing);
if (writing  !pte_write(pte))
/* make the actual HPTE be read-only */
ptel = hpte_make_readonly(ptel);
@@ -662,6 +643,7 @@ long kvmppc_h_protect(struct kvm_vcpu *vcpu, unsigned long 
flags,
unsigned long psize, gfn, hva;
struct kvm_memory_slot *memslot;
pgd_t *pgdir = vcpu-arch.pgdir;
+   pte_t *ptep;
pte_t pte;
 
psize = hpte_page_size(v, r);
@@ -669,9 +651,13 @@ long kvmppc_h_protect(struct kvm_vcpu *vcpu, unsigned long 
flags,
memslot = __gfn_to_memslot(kvm_memslots(kvm), gfn);
if (memslot) {
hva = __gfn_to_hva_memslot(memslot, gfn);
-   pte = lookup_linux_pte(pgdir, hva, 1, psize);
-   if (pte_present(pte)  !pte_write(pte))
-   r = hpte_make_readonly(r);
+   ptep = lookup_linux_pte(pgdir, hva, psize);
+   if (pte_present(pte_val(*ptep))) {
+   pte = kvmppc_read_update_linux_pte(ptep,
+  1);
+   if (pte_present(pte)  !pte_write(pte))
+   r = hpte_make_readonly(r);
+   }
   

RE: [PATCH 5/6 v2] kvm: powerpc: booke: Add linux pte lookup like booke3s

2013-08-06 Thread Bhushan Bharat-R65777


 -Original Message-
 From: Wood Scott-B07421
 Sent: Tuesday, August 06, 2013 12:49 AM
 To: Bhushan Bharat-R65777
 Cc: Benjamin Herrenschmidt; Wood Scott-B07421; ag...@suse.de; kvm-
 p...@vger.kernel.org; k...@vger.kernel.org; linuxppc-dev@lists.ozlabs.org
 Subject: Re: [PATCH 5/6 v2] kvm: powerpc: booke: Add linux pte lookup like
 booke3s
 
 On Mon, 2013-08-05 at 09:27 -0500, Bhushan Bharat-R65777 wrote:
 
   -Original Message-
   From: Benjamin Herrenschmidt [mailto:b...@kernel.crashing.org]
   Sent: Saturday, August 03, 2013 9:54 AM
   To: Bhushan Bharat-R65777
   Cc: Wood Scott-B07421; ag...@suse.de; kvm-...@vger.kernel.org;
   k...@vger.kernel.org; linuxppc-dev@lists.ozlabs.org
   Subject: Re: [PATCH 5/6 v2] kvm: powerpc: booke: Add linux pte
   lookup like booke3s
  
   On Sat, 2013-08-03 at 02:58 +, Bhushan Bharat-R65777 wrote:
One of the problem I saw was that if I put this code in
asm/pgtable-32.h and asm/pgtable-64.h then pte_persent() and other
friend function (on which this code depends) are defined in pgtable.h.
And pgtable.h includes asm/pgtable-32.h and asm/pgtable-64.h
before it defines pte_present() and friends functions.
   
Ok I move wove this in asm/pgtable*.h, initially I fought with
myself to take this code in pgtable* but finally end up doing here
(got biased by book3s :)).
  
   Is there a reason why these routines can not be completely generic
   in pgtable.h ?
 
  How about the generic function:
 
  diff --git a/arch/powerpc/include/asm/pgtable-ppc64.h
  b/arch/powerpc/include/asm/pgtable-ppc64.h
  index d257d98..21daf28 100644
  --- a/arch/powerpc/include/asm/pgtable-ppc64.h
  +++ b/arch/powerpc/include/asm/pgtable-ppc64.h
  @@ -221,6 +221,27 @@ static inline unsigned long pte_update(struct mm_struct
 *mm,
  return old;
   }
 
  +static inline unsigned long pte_read(pte_t *p) { #ifdef
  +PTE_ATOMIC_UPDATES
  +   pte_t pte;
  +   pte_t tmp;
  +   __asm__ __volatile__ (
  +   1: ldarx   %0,0,%3\n
  +  andi.   %1,%0,%4\n
  +  bne-1b\n
  +  ori %1,%0,%4\n
  +  stdcx.  %1,0,%3\n
  +  bne-1b
  +   : =r (pte), =r (tmp), =m (*p)
  +   : r (p), i (_PAGE_BUSY)
  +   : cc);
  +
  +   return pte;
  +#else
  +   return pte_val(*p);
  +#endif
  +#endif
  +}
   static inline int __ptep_test_and_clear_young(struct mm_struct *mm,
unsigned long addr,
  pte_t *ptep)
 
 Please leave a blank line between functions.
 
   {
  diff --git a/arch/powerpc/include/asm/pgtable.h
  b/arch/powerpc/include/asm/pgtable.h
  index 690c8c2..dad712c 100644
  --- a/arch/powerpc/include/asm/pgtable.h
  +++ b/arch/powerpc/include/asm/pgtable.h
  @@ -254,6 +254,45 @@ static inline pte_t
  *find_linux_pte_or_hugepte(pgd_t *pgdir, unsigned long ea,  }  #endif
  /* !CONFIG_HUGETLB_PAGE */
 
  +static inline pte_t lookup_linux_pte(pgd_t *pgdir, unsigned long hva,
  +int writing, unsigned long
  +*pte_sizep)
 
 The name implies that it just reads the PTE.  Setting accessed/dirty shouldn't
 be an undocumented side-effect.  Why can't the caller do that (or a different
 function that the caller calls afterward if desired)?

Scott, I sent the next version of patch based on above idea. Now I think we do 
not need to update the pte flags on booke 
So we do not need to solve the kvmppc_read_update_linux_pte() stuff of book3s.

-Bharat

 
 Though even then you have the undocumented side effect of locking the PTE on
 certain targets.
 
  +{
  +   pte_t *ptep;
  +   pte_t pte;
  +   unsigned long ps = *pte_sizep;
  +   unsigned int shift;
  +
  +   ptep = find_linux_pte_or_hugepte(pgdir, hva, shift);
  +   if (!ptep)
  +   return __pte(0);
  +   if (shift)
  +   *pte_sizep = 1ul  shift;
  +   else
  +   *pte_sizep = PAGE_SIZE;
  +
  +   if (ps  *pte_sizep)
  +   return __pte(0);
  +
  +   if (!pte_present(*ptep))
  +   return __pte(0);
  +
  +#ifdef CONFIG_PPC64
  +   /* Lock PTE (set _PAGE_BUSY) and read */
  +   pte = pte_read(ptep);
  +#else
  +   pte = pte_val(*ptep);
  +#endif
 
 What about 32-bit platforms that need atomic PTEs?
 
 -Scott
 

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: mm/slab: ppc: ubi: kmalloc_slab WARNING / PPC + UBI driver

2013-08-06 Thread Christoph Lameter
On Tue, 6 Aug 2013, Wladislav Wiebe wrote:

 ok, just saw in slab/for-linus branch that those stuff is reverted again..

No that was only for the 3.11 merge by Linus. The 3.12 patches have not
been put into pekkas tree.
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 00/63] 64bit PowerPC little endian support

2013-08-06 Thread Anton Blanchard
This patchset adds support for building a 64bit PowerPC little
endian kernel.

binutils and gcc support (powerpcle/powerpc64le) is already
upstream. For gcc you can use gcc tip, or for the less adventurous
the gcc 4.8 branch works too.

QEMU patches to boot a little endian kernel will be posted over the
next day.

Anton
--

Alistair Popple (4):
  powerpc: More little endian fixes for prom.c
  powerpc: More little endian fixes for setup-common.c
  powerpc: Little endian fixes for legacy_serial.c
  powerpc: Make NUMA device node code endian safe

Anton Blanchard (53):
  powerpc: Align p_toc
  powerpc: handle unaligned ldbrx/stdbrx
  powerpc: Wrap MSR macros with parentheses
  powerpc: Remove SAVE_VSRU and REST_VSRU macros
  powerpc: Simplify logic in include/uapi/asm/elf.h
  powerpc/pseries: Simplify H_GET_TERM_CHAR
  powerpc: Fix a number of sparse warnings
  powerpc/pci: Don't use bitfield for force_32bit_msi
  powerpc: Stop using non-architected shared_proc field in lppaca
  powerpc: Make RTAS device tree accesses endian safe
  powerpc: Make cache info device tree accesses endian safe
  powerpc: Make RTAS calls endian safe
  powerpc: Make logical to real cpu mapping code endian safe
  powerpc: Add some endian annotations to time and xics code
  powerpc: Fix some endian issues in xics code
  powerpc: of_parse_dma_window should take a __be32 *dma_window
  powerpc: Make device tree accesses in cache info code endian safe
  powerpc: Make device tree accesses in HVC VIO console endian safe
  powerpc: Make device tree accesses in VIO subsystem endian safe
  powerpc: Make OF PCI device tree accesses endian safe
  powerpc: Make PCI device node device tree accesses endian safe
  powerpc: Add endian annotations to lppaca, slb_shadow and dtl_entry
  powerpc: Fix little endian lppaca, slb_shadow and dtl_entry
  powerpc: Emulate instructions in little endian mode
  powerpc: Little endian SMP IPI demux
  powerpc/pseries: Fix endian issues in H_GET_TERM_CHAR/H_PUT_TERM_CHAR
  powerpc: Fix little endian coredumps
  powerpc: Make rwlocks endian safe
  powerpc: Fix endian issues in VMX copy loops
  powerpc: Book 3S MMU little endian support
  powerpc: Fix offset of FPRs in VSX registers in little endian builds
  powerpc: PTRACE_PEEKUSR/PTRACE_POKEUSER of FPR registers in little
endian builds
  powerpc: Little endian builds double word swap VSX state during
context save/restore
  powerpc: Add little endian support for word-at-a-time functions
  powerpc: Set MSR_LE bit on little endian builds
  powerpc: Reset MSR_LE on signal entry
  powerpc: Add endian safe trampoline to pseries secondary thread entry
  pseries: Add H_SET_MODE to change exception endianness
  powerpc/kvm/book3s_hv: Add little endian guest support
  powerpc: Remove open coded byte swap macro in alignment handler
  powerpc: Remove hard coded FP offsets in alignment handler
  powerpc: Alignment handler shouldn't access VSX registers with TS_FPR
  powerpc: Add little endian support to alignment handler
  powerpc: Handle VSX alignment faults in little endian mode
  ibmveth: Fix little endian issues
  ibmvscsi: Fix little endian issues
  [SCSI] lpfc: Don't force CONFIG_GENERIC_CSUM on
  powerpc: Use generic checksum code in little endian
  powerpc: Use generic memcpy code in little endian
  powerpc: uname should return ppc64le/ppcle on little endian builds
  powerpc: Don't set HAVE_EFFICIENT_UNALIGNED_ACCESS on little endian
builds
  powerpc: Work around little endian gcc bug
  powerpc: Add pseries_le_defconfig

Benjamin Herrenschmidt (2):
  powerpc: Make prom_init.c endian safe
  powerpc: endian safe trampoline

Ian Munsie (4):
  powerpc: Make prom.c device tree accesses endian safe
  powerpc: Support endian agnostic MMIO
  powerpc: Include the appropriate endianness header
  powerpc: Add ability to build little endian kernels

 arch/powerpc/Kconfig|   5 +-
 arch/powerpc/Makefile   |  37 ++-
 arch/powerpc/boot/Makefile  |   3 +-
 arch/powerpc/configs/pseries_le_defconfig   | 347 
 arch/powerpc/include/asm/asm-compat.h   |   9 +
 arch/powerpc/include/asm/checksum.h |   5 +
 arch/powerpc/include/asm/hvcall.h   |   2 +
 arch/powerpc/include/asm/io.h   |  67 +++--
 arch/powerpc/include/asm/kvm_host.h |   1 +
 arch/powerpc/include/asm/lppaca.h   |  68 +++--
 arch/powerpc/include/asm/mmu-hash64.h   |   4 +-
 arch/powerpc/include/asm/paca.h |   5 +
 arch/powerpc/include/asm/pci-bridge.h   |   2 +-
 arch/powerpc/include/asm/ppc-opcode.h   |   3 +
 arch/powerpc/include/asm/ppc_asm.h  |  68 +++--
 arch/powerpc/include/asm/processor.h|  12 +-
 arch/powerpc/include/asm/prom.h |   5 +-
 arch/powerpc/include/asm/reg.h  |  13 +-
 arch/powerpc/include/asm/reg_booke.h|   8 +-
 

[PATCH 01/63] powerpc: Align p_toc

2013-08-06 Thread Anton Blanchard
p_toc is an 8 byte relative offset to the TOC that we place in the
text section. This means it is only 4 byte aligned where it should
be 8 byte aligned. Add an explicit alignment.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/kernel/head_64.S | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/kernel/head_64.S b/arch/powerpc/kernel/head_64.S
index b61363d..3d11d80 100644
--- a/arch/powerpc/kernel/head_64.S
+++ b/arch/powerpc/kernel/head_64.S
@@ -703,6 +703,7 @@ _GLOBAL(relative_toc)
mtlrr0
blr
 
+.balign 8
 p_toc: .llong  __toc_start + 0x8000 - 0b
 
 /*
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 03/63] powerpc: Wrap MSR macros with parentheses

2013-08-06 Thread Anton Blanchard
Not having parentheses around a macro is asking for trouble.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/include/asm/reg.h   | 8 
 arch/powerpc/include/asm/reg_booke.h | 8 
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
index a6840e4..a312e0c 100644
--- a/arch/powerpc/include/asm/reg.h
+++ b/arch/powerpc/include/asm/reg.h
@@ -115,10 +115,10 @@
 #define MSR_64BIT  MSR_SF
 
 /* Server variant */
-#define MSR_   MSR_ME | MSR_RI | MSR_IR | MSR_DR | MSR_ISF |MSR_HV
-#define MSR_KERNEL MSR_ | MSR_64BIT
-#define MSR_USER32 MSR_ | MSR_PR | MSR_EE
-#define MSR_USER64 MSR_USER32 | MSR_64BIT
+#define MSR_   (MSR_ME | MSR_RI | MSR_IR | MSR_DR | MSR_ISF |MSR_HV)
+#define MSR_KERNEL (MSR_ | MSR_64BIT)
+#define MSR_USER32 (MSR_ | MSR_PR | MSR_EE)
+#define MSR_USER64 (MSR_USER32 | MSR_64BIT)
 #elif defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_8xx)
 /* Default MSR for kernel mode. */
 #define MSR_KERNEL (MSR_ME|MSR_RI|MSR_IR|MSR_DR)
diff --git a/arch/powerpc/include/asm/reg_booke.h 
b/arch/powerpc/include/asm/reg_booke.h
index b417de3..ed8f836 100644
--- a/arch/powerpc/include/asm/reg_booke.h
+++ b/arch/powerpc/include/asm/reg_booke.h
@@ -29,10 +29,10 @@
 #if defined(CONFIG_PPC_BOOK3E_64)
 #define MSR_64BIT  MSR_CM
 
-#define MSR_   MSR_ME | MSR_CE
-#define MSR_KERNEL MSR_ | MSR_64BIT
-#define MSR_USER32 MSR_ | MSR_PR | MSR_EE
-#define MSR_USER64 MSR_USER32 | MSR_64BIT
+#define MSR_   (MSR_ME | MSR_CE)
+#define MSR_KERNEL (MSR_ | MSR_64BIT)
+#define MSR_USER32 (MSR_ | MSR_PR | MSR_EE)
+#define MSR_USER64 (MSR_USER32 | MSR_64BIT)
 #elif defined (CONFIG_40x)
 #define MSR_KERNEL (MSR_ME|MSR_RI|MSR_IR|MSR_DR|MSR_CE)
 #define MSR_USER   (MSR_KERNEL|MSR_PR|MSR_EE)
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 04/63] powerpc: Remove SAVE_VSRU and REST_VSRU macros

2013-08-06 Thread Anton Blanchard
We always use VMX loads and stores to manage the high 32
VSRs. Remove these unused macros.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/include/asm/ppc_asm.h | 13 -
 1 file changed, 13 deletions(-)

diff --git a/arch/powerpc/include/asm/ppc_asm.h 
b/arch/powerpc/include/asm/ppc_asm.h
index 2f1b6c5..b5c85f1 100644
--- a/arch/powerpc/include/asm/ppc_asm.h
+++ b/arch/powerpc/include/asm/ppc_asm.h
@@ -219,19 +219,6 @@ END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR)
 #define REST_8VSRS(n,b,base)   REST_4VSRS(n,b,base); REST_4VSRS(n+4,b,base)
 #define REST_16VSRS(n,b,base)  REST_8VSRS(n,b,base); REST_8VSRS(n+8,b,base)
 #define REST_32VSRS(n,b,base)  REST_16VSRS(n,b,base); REST_16VSRS(n+16,b,base)
-/* Save the upper 32 VSRs (32-63) in the thread VSX region (0-31) */
-#define SAVE_VSRU(n,b,base)li b,THREAD_VR0+(16*(n));  
STXVD2X(n+32,R##base,R##b)
-#define SAVE_2VSRSU(n,b,base)  SAVE_VSRU(n,b,base); SAVE_VSRU(n+1,b,base)
-#define SAVE_4VSRSU(n,b,base)  SAVE_2VSRSU(n,b,base); SAVE_2VSRSU(n+2,b,base)
-#define SAVE_8VSRSU(n,b,base)  SAVE_4VSRSU(n,b,base); SAVE_4VSRSU(n+4,b,base)
-#define SAVE_16VSRSU(n,b,base) SAVE_8VSRSU(n,b,base); SAVE_8VSRSU(n+8,b,base)
-#define SAVE_32VSRSU(n,b,base) SAVE_16VSRSU(n,b,base); 
SAVE_16VSRSU(n+16,b,base)
-#define REST_VSRU(n,b,base)li b,THREAD_VR0+(16*(n)); 
LXVD2X(n+32,R##base,R##b)
-#define REST_2VSRSU(n,b,base)  REST_VSRU(n,b,base); REST_VSRU(n+1,b,base)
-#define REST_4VSRSU(n,b,base)  REST_2VSRSU(n,b,base); REST_2VSRSU(n+2,b,base)
-#define REST_8VSRSU(n,b,base)  REST_4VSRSU(n,b,base); REST_4VSRSU(n+4,b,base)
-#define REST_16VSRSU(n,b,base) REST_8VSRSU(n,b,base); REST_8VSRSU(n+8,b,base)
-#define REST_32VSRSU(n,b,base) REST_16VSRSU(n,b,base); 
REST_16VSRSU(n+16,b,base)
 
 /*
  * b = base register for addressing, o = base offset from register of 1st EVR
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 07/63] powerpc: Fix a number of sparse warnings

2013-08-06 Thread Anton Blanchard
Address some of the trivial sparse warnings in arch/powerpc.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/kernel/legacy_serial.c | 2 +-
 arch/powerpc/kernel/pci-common.c| 4 ++--
 arch/powerpc/kernel/pci_64.c| 2 +-
 arch/powerpc/kernel/setup_64.c  | 4 ++--
 arch/powerpc/kernel/signal_64.c | 8 
 arch/powerpc/kernel/smp.c   | 2 +-
 arch/powerpc/mm/hash_utils_64.c | 2 +-
 arch/powerpc/mm/subpage-prot.c  | 4 ++--
 arch/powerpc/perf/core-book3s.c | 2 +-
 arch/powerpc/platforms/powernv/opal.c   | 2 +-
 arch/powerpc/platforms/pseries/lpar.c   | 2 +-
 arch/powerpc/platforms/pseries/pseries_energy.c | 4 ++--
 arch/powerpc/platforms/pseries/setup.c  | 2 +-
 13 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/arch/powerpc/kernel/legacy_serial.c 
b/arch/powerpc/kernel/legacy_serial.c
index 0733b05..af1c63f 100644
--- a/arch/powerpc/kernel/legacy_serial.c
+++ b/arch/powerpc/kernel/legacy_serial.c
@@ -99,7 +99,7 @@ static int __init add_legacy_port(struct device_node *np, int 
want_index,
legacy_serial_count = index + 1;
 
/* Check if there is a port who already claimed our slot */
-   if (legacy_serial_infos[index].np != 0) {
+   if (legacy_serial_infos[index].np != NULL) {
/* if we still have some room, move it, else override */
if (legacy_serial_count  MAX_LEGACY_SERIAL_PORTS) {
printk(KERN_DEBUG Moved legacy port %d - %d\n,
diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
index 7d22a67..22fe401 100644
--- a/arch/powerpc/kernel/pci-common.c
+++ b/arch/powerpc/kernel/pci-common.c
@@ -306,7 +306,7 @@ static struct resource *__pci_mmap_make_offset(struct 
pci_dev *dev,
unsigned long io_offset = 0;
int i, res_bit;
 
-   if (hose == 0)
+   if (hose == NULL)
return NULL;/* should never happen */
 
/* If memory, add on the PCI bridge address offset */
@@ -1578,7 +1578,7 @@ fake_pci_bus(struct pci_controller *hose, int busnr)
 {
static struct pci_bus bus;
 
-   if (hose == 0) {
+   if (hose == NULL) {
printk(KERN_ERR Can't find hose for PCI bus %d!\n, busnr);
}
bus.number = busnr;
diff --git a/arch/powerpc/kernel/pci_64.c b/arch/powerpc/kernel/pci_64.c
index 2e86296..cdf5aa1 100644
--- a/arch/powerpc/kernel/pci_64.c
+++ b/arch/powerpc/kernel/pci_64.c
@@ -109,7 +109,7 @@ int pcibios_unmap_io_space(struct pci_bus *bus)
hose = pci_bus_to_host(bus);
 
/* Check if we have IOs allocated */
-   if (hose-io_base_alloc == 0)
+   if (hose-io_base_alloc == NULL)
return 0;
 
pr_debug(IO unmapping for PHB %s\n, hose-dn-full_name);
diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index 389fb807..b3b5fd3 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -322,7 +322,7 @@ static void __init initialize_cache_info(void)
 NULL);
if (lsizep != NULL)
lsize = *lsizep;
-   if (sizep == 0 || lsizep == 0)
+   if (sizep == NULL || lsizep == NULL)
DBG(Argh, can't find dcache properties ! 
sizep: %p, lsizep: %p\n, sizep, lsizep);
 
@@ -344,7 +344,7 @@ static void __init initialize_cache_info(void)
 NULL);
if (lsizep != NULL)
lsize = *lsizep;
-   if (sizep == 0 || lsizep == 0)
+   if (sizep == NULL || lsizep == NULL)
DBG(Argh, can't find icache properties ! 
sizep: %p, lsizep: %p\n, sizep, lsizep);
 
diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
index 887e99d..cbd2692 100644
--- a/arch/powerpc/kernel/signal_64.c
+++ b/arch/powerpc/kernel/signal_64.c
@@ -346,13 +346,13 @@ static long restore_sigcontext(struct pt_regs *regs, 
sigset_t *set, int sig,
if (v_regs  !access_ok(VERIFY_READ, v_regs, 34 * sizeof(vector128)))
return -EFAULT;
/* Copy 33 vec registers (vr0..31 and vscr) from the stack */
-   if (v_regs != 0  (msr  MSR_VEC) != 0)
+   if (v_regs != NULL  (msr  MSR_VEC) != 0)
err |= __copy_from_user(current-thread.vr, v_regs,
33 * sizeof(vector128));
else if (current-thread.used_vr)
memset(current-thread.vr, 0, 33 * sizeof(vector128));
/* Always get VRSAVE back */
-   if (v_regs != 0)
+   if (v_regs != NULL)
  

[PATCH 05/63] powerpc: Simplify logic in include/uapi/asm/elf.h

2013-08-06 Thread Anton Blanchard
Simplify things by putting all the 32bit and 64bit defines
together instead of in two spots.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/include/uapi/asm/elf.h | 19 +++
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/arch/powerpc/include/uapi/asm/elf.h 
b/arch/powerpc/include/uapi/asm/elf.h
index 05b8d56..89fa042 100644
--- a/arch/powerpc/include/uapi/asm/elf.h
+++ b/arch/powerpc/include/uapi/asm/elf.h
@@ -107,6 +107,11 @@ typedef elf_gregset_t32 compat_elf_gregset_t;
 # define ELF_NVRREG34  /* includes vscr  vrsave in split vectors */
 # define ELF_NVSRHALFREG 32/* Half the vsx registers */
 # define ELF_GREG_TYPE elf_greg_t64
+# define ELF_ARCH  EM_PPC64
+# define ELF_CLASS ELFCLASS64
+# define ELF_DATA  ELFDATA2MSB
+typedef elf_greg_t64 elf_greg_t;
+typedef elf_gregset_t64 elf_gregset_t;
 #else
 # define ELF_NEVRREG   34  /* includes acc (as 2) */
 # define ELF_NVRREG33  /* includes vscr */
@@ -114,20 +119,10 @@ typedef elf_gregset_t32 compat_elf_gregset_t;
 # define ELF_ARCH  EM_PPC
 # define ELF_CLASS ELFCLASS32
 # define ELF_DATA  ELFDATA2MSB
+typedef elf_greg_t32 elf_greg_t;
+typedef elf_gregset_t32 elf_gregset_t;
 #endif /* __powerpc64__ */
 
-#ifndef ELF_ARCH
-# define ELF_ARCH  EM_PPC64
-# define ELF_CLASS ELFCLASS64
-# define ELF_DATA  ELFDATA2MSB
-  typedef elf_greg_t64 elf_greg_t;
-  typedef elf_gregset_t64 elf_gregset_t;
-#else
-  /* Assumption: ELF_ARCH == EM_PPC and ELF_CLASS == ELFCLASS32 */
-  typedef elf_greg_t32 elf_greg_t;
-  typedef elf_gregset_t32 elf_gregset_t;
-#endif /* ELF_ARCH */
-
 /* Floating point registers */
 typedef double elf_fpreg_t;
 typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 06/63] powerpc/pseries: Simplify H_GET_TERM_CHAR

2013-08-06 Thread Anton Blanchard
plpar_get_term_char is only used once and just adds a layer
of complexity to H_GET_TERM_CHAR. plpar_put_term_char isn't
used at all so we can remove it.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/platforms/pseries/hvconsole.c  | 12 +---
 arch/powerpc/platforms/pseries/plpar_wrappers.h | 24 
 2 files changed, 9 insertions(+), 27 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/hvconsole.c 
b/arch/powerpc/platforms/pseries/hvconsole.c
index b344f94..aa0aa37 100644
--- a/arch/powerpc/platforms/pseries/hvconsole.c
+++ b/arch/powerpc/platforms/pseries/hvconsole.c
@@ -40,10 +40,16 @@
  */
 int hvc_get_chars(uint32_t vtermno, char *buf, int count)
 {
-   unsigned long got;
+   long ret;
+   unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
+   unsigned long *lbuf = (unsigned long *)buf;
+
+   ret = plpar_hcall(H_GET_TERM_CHAR, retbuf, vtermno);
+   lbuf[0] = retbuf[1];
+   lbuf[1] = retbuf[2];
 
-   if (plpar_get_term_char(vtermno, got, buf) == H_SUCCESS)
-   return got;
+   if (ret == H_SUCCESS)
+   return retbuf[0];
 
return 0;
 }
diff --git a/arch/powerpc/platforms/pseries/plpar_wrappers.h 
b/arch/powerpc/platforms/pseries/plpar_wrappers.h
index f35787b..417d0bf 100644
--- a/arch/powerpc/platforms/pseries/plpar_wrappers.h
+++ b/arch/powerpc/platforms/pseries/plpar_wrappers.h
@@ -256,30 +256,6 @@ static inline long plpar_tce_stuff(unsigned long liobn, 
unsigned long ioba,
return plpar_hcall_norets(H_STUFF_TCE, liobn, ioba, tceval, count);
 }
 
-static inline long plpar_get_term_char(unsigned long termno,
-   unsigned long *len_ret, char *buf_ret)
-{
-   long rc;
-   unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
-   unsigned long *lbuf = (unsigned long *)buf_ret; /* TODO: alignment? */
-
-   rc = plpar_hcall(H_GET_TERM_CHAR, retbuf, termno);
-
-   *len_ret = retbuf[0];
-   lbuf[0] = retbuf[1];
-   lbuf[1] = retbuf[2];
-
-   return rc;
-}
-
-static inline long plpar_put_term_char(unsigned long termno, unsigned long len,
-   const char *buffer)
-{
-   unsigned long *lbuf = (unsigned long *)buffer;  /* TODO: alignment? */
-   return plpar_hcall_norets(H_PUT_TERM_CHAR, termno, len, lbuf[0],
-   lbuf[1]);
-}
-
 /* Set various resource mode parameters */
 static inline long plpar_set_mode(unsigned long mflags, unsigned long resource,
unsigned long value1, unsigned long value2)
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 08/63] powerpc/pci: Don't use bitfield for force_32bit_msi

2013-08-06 Thread Anton Blanchard
Fix a sparse warning about force_32bit_msi being a one bit bitfield.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/include/asm/pci-bridge.h | 2 +-
 arch/powerpc/kernel/pci_64.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/include/asm/pci-bridge.h 
b/arch/powerpc/include/asm/pci-bridge.h
index 32d0d20..4ca90a3 100644
--- a/arch/powerpc/include/asm/pci-bridge.h
+++ b/arch/powerpc/include/asm/pci-bridge.h
@@ -159,7 +159,7 @@ struct pci_dn {
 
int pci_ext_config_space;   /* for pci devices */
 
-   int force_32bit_msi:1;
+   boolforce_32bit_msi;
 
struct  pci_dev *pcidev;/* back-pointer to the pci device */
 #ifdef CONFIG_EEH
diff --git a/arch/powerpc/kernel/pci_64.c b/arch/powerpc/kernel/pci_64.c
index cdf5aa1..a9e311f 100644
--- a/arch/powerpc/kernel/pci_64.c
+++ b/arch/powerpc/kernel/pci_64.c
@@ -272,7 +272,7 @@ static void quirk_radeon_32bit_msi(struct pci_dev *dev)
struct pci_dn *pdn = pci_get_pdn(dev);
 
if (pdn)
-   pdn-force_32bit_msi = 1;
+   pdn-force_32bit_msi = true;
 }
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x68f2, quirk_radeon_32bit_msi);
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0xaa68, quirk_radeon_32bit_msi);
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 10/63] powerpc: Make prom.c device tree accesses endian safe

2013-08-06 Thread Anton Blanchard
From: Ian Munsie imun...@au1.ibm.com

On PowerPC the device tree is always big endian, but the CPU could be
either, so add be32_to_cpu where appropriate and change the types of
device tree data to __be32 etc to allow sparse to locate endian issues.

Signed-off-by: Ian Munsie imun...@au1.ibm.com
Acked-by: Grant Likely grant.lik...@secretlab.ca
---
 arch/powerpc/kernel/prom.c | 60 --
 1 file changed, 31 insertions(+), 29 deletions(-)

diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index eb23ac9..d072f67 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -215,16 +215,16 @@ static void __init check_cpu_pa_features(unsigned long 
node)
 #ifdef CONFIG_PPC_STD_MMU_64
 static void __init check_cpu_slb_size(unsigned long node)
 {
-   u32 *slb_size_ptr;
+   __be32 *slb_size_ptr;
 
slb_size_ptr = of_get_flat_dt_prop(node, slb-size, NULL);
if (slb_size_ptr != NULL) {
-   mmu_slb_size = *slb_size_ptr;
+   mmu_slb_size = be32_to_cpup(slb_size_ptr);
return;
}
slb_size_ptr = of_get_flat_dt_prop(node, ibm,slb-size, NULL);
if (slb_size_ptr != NULL) {
-   mmu_slb_size = *slb_size_ptr;
+   mmu_slb_size = be32_to_cpup(slb_size_ptr);
}
 }
 #else
@@ -279,11 +279,11 @@ static void __init check_cpu_feature_properties(unsigned 
long node)
 {
unsigned long i;
struct feature_property *fp = feature_properties;
-   const u32 *prop;
+   const __be32 *prop;
 
for (i = 0; i  ARRAY_SIZE(feature_properties); ++i, ++fp) {
prop = of_get_flat_dt_prop(node, fp-name, NULL);
-   if (prop  *prop = fp-min_value) {
+   if (prop  be32_to_cpup(prop) = fp-min_value) {
cur_cpu_spec-cpu_features |= fp-cpu_feature;
cur_cpu_spec-cpu_user_features |= fp-cpu_user_ftr;
}
@@ -295,8 +295,8 @@ static int __init early_init_dt_scan_cpus(unsigned long 
node,
  void *data)
 {
char *type = of_get_flat_dt_prop(node, device_type, NULL);
-   const u32 *prop;
-   const u32 *intserv;
+   const __be32 *prop;
+   const __be32 *intserv;
int i, nthreads;
unsigned long len;
int found = -1;
@@ -324,8 +324,9 @@ static int __init early_init_dt_scan_cpus(unsigned long 
node,
 * version 2 of the kexec param format adds the phys cpuid of
 * booted proc.
 */
-   if (initial_boot_params-version = 2) {
-   if (intserv[i] == initial_boot_params-boot_cpuid_phys) 
{
+   if (be32_to_cpu(initial_boot_params-version) = 2) {
+   if (be32_to_cpu(intserv[i]) ==
+   be32_to_cpu(initial_boot_params-boot_cpuid_phys)) {
found = boot_cpu_count;
found_thread = i;
}
@@ -347,9 +348,10 @@ static int __init early_init_dt_scan_cpus(unsigned long 
node,
 
if (found = 0) {
DBG(boot cpu: logical %d physical %d\n, found,
-   intserv[found_thread]);
+   be32_to_cpu(intserv[found_thread]));
boot_cpuid = found;
-   set_hard_smp_processor_id(found, intserv[found_thread]);
+   set_hard_smp_processor_id(found,
+   be32_to_cpu(intserv[found_thread]));
 
/*
 * PAPR defines logical PVR values for cpus that
@@ -366,8 +368,8 @@ static int __init early_init_dt_scan_cpus(unsigned long 
node,
 * it uses 0x0f01.
 */
prop = of_get_flat_dt_prop(node, cpu-version, NULL);
-   if (prop  (*prop  0xff00) == 0x0f00)
-   identify_cpu(0, *prop);
+   if (prop  (be32_to_cpup(prop)  0xff00) == 0x0f00)
+   identify_cpu(0, be32_to_cpup(prop));
 
identical_pvr_fixup(node);
}
@@ -389,7 +391,7 @@ static int __init early_init_dt_scan_cpus(unsigned long 
node,
 int __init early_init_dt_scan_chosen_ppc(unsigned long node, const char *uname,
 int depth, void *data)
 {
-   unsigned long *lprop;
+   unsigned long *lprop; /* All these set by kernel, so no need to convert 
endian */
 
/* Use common scan routine to determine if this is the chosen node */
if (early_init_dt_scan_chosen(node, uname, depth, data) == 0)
@@ -591,16 +593,16 @@ static void __init early_reserve_mem_dt(void)
 static void __init early_reserve_mem(void)
 {
u64 base, size;
-   u64 *reserve_map;
+   __be64 *reserve_map;
unsigned long self_base;
unsigned long self_size;
 
-   reserve_map = (u64 *)(((unsigned 

[PATCH 09/63] powerpc: Stop using non-architected shared_proc field in lppaca

2013-08-06 Thread Anton Blanchard
Although the shared_proc field in the lppaca works today, it is
not architected. A shared processor partition will always have a non
zero yield_count so use that instead. Create a wrapper so users
don't have to know about the details.

In order for older kernels to continue to work on KVM we need
to set the shared_proc bit. While here, remove the ugly bitfield.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/include/asm/lppaca.h   | 18 ++
 arch/powerpc/include/asm/spinlock.h |  2 +-
 arch/powerpc/kernel/lparcfg.c   |  5 +++--
 arch/powerpc/kvm/book3s_hv.c|  2 +-
 arch/powerpc/mm/numa.c  |  2 +-
 arch/powerpc/platforms/pseries/hotplug-cpu.c|  4 ++--
 arch/powerpc/platforms/pseries/processor_idle.c |  2 +-
 7 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/arch/powerpc/include/asm/lppaca.h 
b/arch/powerpc/include/asm/lppaca.h
index 9b12f88..bc8def0 100644
--- a/arch/powerpc/include/asm/lppaca.h
+++ b/arch/powerpc/include/asm/lppaca.h
@@ -50,10 +50,8 @@ struct lppaca {
 
u32 desc;   /* Eye catcher 0xD397D781 */
u16 size;   /* Size of this struct */
-   u16 reserved1;
-   u16 reserved2:14;
-   u8  shared_proc:1;  /* Shared processor indicator */
-   u8  secondary_thread:1; /* Secondary thread indicator */
+   u8  reserved1[3];
+   u8  __old_status;   /* Old status, including shared proc */
u8  reserved3[14];
volatile u32 dyn_hw_node_id;/* Dynamic hardware node id */
volatile u32 dyn_hw_proc_id;/* Dynamic hardware proc id */
@@ -108,6 +106,18 @@ extern struct lppaca lppaca[];
 #define lppaca_of(cpu) (*paca[cpu].lppaca_ptr)
 
 /*
+ * Old kernels used a reserved bit in the VPA to determine if it was running
+ * in shared processor mode. New kernels look for a non zero yield count
+ * but KVM still needs to set the bit to keep the old stuff happy.
+ */
+#define LPPACA_OLD_SHARED_PROC 2
+
+static inline bool lppaca_shared_proc(struct lppaca *l)
+{
+   return l-yield_count != 0;
+}
+
+/*
  * SLB shadow buffer structure as defined in the PAPR.  The save_area
  * contains adjacent ESID and VSID pairs for each shadowed SLB.  The
  * ESID is stored in the lower 64bits, then the VSID.
diff --git a/arch/powerpc/include/asm/spinlock.h 
b/arch/powerpc/include/asm/spinlock.h
index 5b23f91..7c345b6 100644
--- a/arch/powerpc/include/asm/spinlock.h
+++ b/arch/powerpc/include/asm/spinlock.h
@@ -96,7 +96,7 @@ static inline int arch_spin_trylock(arch_spinlock_t *lock)
 
 #if defined(CONFIG_PPC_SPLPAR)
 /* We only yield to the hypervisor if we are in shared processor mode */
-#define SHARED_PROCESSOR (local_paca-lppaca_ptr-shared_proc)
+#define SHARED_PROCESSOR (lppaca_shared_proc(local_paca-lppaca_ptr))
 extern void __spin_yield(arch_spinlock_t *lock);
 extern void __rw_yield(arch_rwlock_t *lock);
 #else /* SPLPAR */
diff --git a/arch/powerpc/kernel/lparcfg.c b/arch/powerpc/kernel/lparcfg.c
index d92f387..e6024c2 100644
--- a/arch/powerpc/kernel/lparcfg.c
+++ b/arch/powerpc/kernel/lparcfg.c
@@ -165,7 +165,7 @@ static void parse_ppp_data(struct seq_file *m)
   ppp_data.active_system_procs);
 
/* pool related entries are appropriate for shared configs */
-   if (lppaca_of(0).shared_proc) {
+   if (lppaca_shared_proc(get_lppaca())) {
unsigned long pool_idle_time, pool_procs;
 
seq_printf(m, pool=%d\n, ppp_data.pool_num);
@@ -473,7 +473,8 @@ static int pseries_lparcfg_data(struct seq_file *m, void *v)
seq_printf(m, partition_potential_processors=%d\n,
   partition_potential_processors);
 
-   seq_printf(m, shared_processor_mode=%d\n, lppaca_of(0).shared_proc);
+   seq_printf(m, shared_processor_mode=%d\n,
+  lppaca_shared_proc(get_lppaca()));
 
seq_printf(m, slb_size=%d\n, mmu_slb_size);
 
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 2efa9dd..cf39bf4 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -217,7 +217,7 @@ struct kvm_vcpu *kvmppc_find_vcpu(struct kvm *kvm, int id)
 
 static void init_vpa(struct kvm_vcpu *vcpu, struct lppaca *vpa)
 {
-   vpa-shared_proc = 1;
+   vpa-__old_status |= LPPACA_OLD_SHARED_PROC;
vpa-yield_count = 1;
 }
 
diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index 5850798..501e32c 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -1609,7 +1609,7 @@ int start_topology_update(void)
 #endif
}
} else if (firmware_has_feature(FW_FEATURE_VPHN) 
-  get_lppaca()-shared_proc) {
+  lppaca_shared_proc(get_lppaca())) {
if (!vphn_enabled) {
prrn_enabled = 0;
vphn_enabled 

[PATCH 11/63] powerpc: More little endian fixes for prom.c

2013-08-06 Thread Anton Blanchard
From: Alistair Popple alist...@popple.id.au

Signed-off-by: Alistair Popple alist...@popple.id.au
---
 arch/powerpc/kernel/prom.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index d072f67..987a4fb 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -456,7 +456,7 @@ static int __init early_init_dt_scan_drconf_memory(unsigned 
long node)
if (dm == NULL || l  sizeof(__be32))
return 0;
 
-   n = *dm++;  /* number of entries */
+   n = of_read_number(dm++, 1);/* number of entries */
if (l  (n * (dt_root_addr_cells + 4) + 1) * sizeof(__be32))
return 0;
 
@@ -468,7 +468,7 @@ static int __init early_init_dt_scan_drconf_memory(unsigned 
long node)
 
for (; n != 0; --n) {
base = dt_mem_next_cell(dt_root_addr_cells, dm);
-   flags = dm[3];
+   flags = of_read_number(dm[3], 1);
/* skip DRC index, pad, assoc. list index, flags */
dm += 4;
/* skip this block if the reserved bit is set in flags (0x80)
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 13/63] powerpc: Make cache info device tree accesses endian safe

2013-08-06 Thread Anton Blanchard
Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/kernel/setup_64.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index b3b5fd3..00dfcc5 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -305,14 +305,14 @@ static void __init initialize_cache_info(void)
 * d-cache and i-cache sizes... -Peter
 */
if (num_cpus == 1) {
-   const u32 *sizep, *lsizep;
+   const __be32 *sizep, *lsizep;
u32 size, lsize;
 
size = 0;
lsize = cur_cpu_spec-dcache_bsize;
sizep = of_get_property(np, d-cache-size, NULL);
if (sizep != NULL)
-   size = *sizep;
+   size = be32_to_cpu(*sizep);
lsizep = of_get_property(np, d-cache-block-size,
 NULL);
/* fallback if block size missing */
@@ -321,7 +321,7 @@ static void __init initialize_cache_info(void)
 d-cache-line-size,
 NULL);
if (lsizep != NULL)
-   lsize = *lsizep;
+   lsize = be32_to_cpu(*lsizep);
if (sizep == NULL || lsizep == NULL)
DBG(Argh, can't find dcache properties ! 
sizep: %p, lsizep: %p\n, sizep, lsizep);
@@ -335,7 +335,7 @@ static void __init initialize_cache_info(void)
lsize = cur_cpu_spec-icache_bsize;
sizep = of_get_property(np, i-cache-size, NULL);
if (sizep != NULL)
-   size = *sizep;
+   size = be32_to_cpu(*sizep);
lsizep = of_get_property(np, i-cache-block-size,
 NULL);
if (lsizep == NULL)
@@ -343,7 +343,7 @@ static void __init initialize_cache_info(void)
 i-cache-line-size,
 NULL);
if (lsizep != NULL)
-   lsize = *lsizep;
+   lsize = be32_to_cpu(*lsizep);
if (sizep == NULL || lsizep == NULL)
DBG(Argh, can't find icache properties ! 
sizep: %p, lsizep: %p\n, sizep, lsizep);
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 12/63] powerpc: Make RTAS device tree accesses endian safe

2013-08-06 Thread Anton Blanchard
Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/kernel/rtas.c | 28 ++--
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/arch/powerpc/kernel/rtas.c b/arch/powerpc/kernel/rtas.c
index 80b5ef4..98b26af 100644
--- a/arch/powerpc/kernel/rtas.c
+++ b/arch/powerpc/kernel/rtas.c
@@ -204,7 +204,7 @@ void rtas_progress(char *s, unsigned short hex)
 {
struct device_node *root;
int width;
-   const int *p;
+   const __be32 *p;
char *os;
static int display_character, set_indicator;
static int display_width, display_lines, form_feed;
@@ -221,13 +221,13 @@ void rtas_progress(char *s, unsigned short hex)
if ((root = of_find_node_by_path(/rtas))) {
if ((p = of_get_property(root,
ibm,display-line-length, NULL)))
-   display_width = *p;
+   display_width = be32_to_cpu(*p);
if ((p = of_get_property(root,
ibm,form-feed, NULL)))
-   form_feed = *p;
+   form_feed = be32_to_cpu(*p);
if ((p = of_get_property(root,
ibm,display-number-of-lines, NULL)))
-   display_lines = *p;
+   display_lines = be32_to_cpu(*p);
row_width = of_get_property(root,
ibm,display-truncation-length, NULL);
of_node_put(root);
@@ -322,11 +322,11 @@ EXPORT_SYMBOL(rtas_progress); /* needed by 
rtas_flash module */
 
 int rtas_token(const char *service)
 {
-   const int *tokp;
+   const __be32 *tokp;
if (rtas.dev == NULL)
return RTAS_UNKNOWN_SERVICE;
tokp = of_get_property(rtas.dev, service, NULL);
-   return tokp ? *tokp : RTAS_UNKNOWN_SERVICE;
+   return tokp ? be32_to_cpu(*tokp) : RTAS_UNKNOWN_SERVICE;
 }
 EXPORT_SYMBOL(rtas_token);
 
@@ -588,8 +588,8 @@ bool rtas_indicator_present(int token, int *maxindex)
 {
int proplen, count, i;
const struct indicator_elem {
-   u32 token;
-   u32 maxindex;
+   __be32 token;
+   __be32 maxindex;
} *indicators;
 
indicators = of_get_property(rtas.dev, rtas-indicators, proplen);
@@ -599,10 +599,10 @@ bool rtas_indicator_present(int token, int *maxindex)
count = proplen / sizeof(struct indicator_elem);
 
for (i = 0; i  count; i++) {
-   if (indicators[i].token != token)
+   if (__be32_to_cpu(indicators[i].token) != token)
continue;
if (maxindex)
-   *maxindex = indicators[i].maxindex;
+   *maxindex = __be32_to_cpu(indicators[i].maxindex);
return true;
}
 
@@ -1097,19 +1097,19 @@ void __init rtas_initialize(void)
 */
rtas.dev = of_find_node_by_name(NULL, rtas);
if (rtas.dev) {
-   const u32 *basep, *entryp, *sizep;
+   const __be32 *basep, *entryp, *sizep;
 
basep = of_get_property(rtas.dev, linux,rtas-base, NULL);
sizep = of_get_property(rtas.dev, rtas-size, NULL);
if (basep != NULL  sizep != NULL) {
-   rtas.base = *basep;
-   rtas.size = *sizep;
+   rtas.base = __be32_to_cpu(*basep);
+   rtas.size = __be32_to_cpu(*sizep);
entryp = of_get_property(rtas.dev,
linux,rtas-entry, NULL);
if (entryp == NULL) /* Ugh */
rtas.entry = rtas.base;
else
-   rtas.entry = *entryp;
+   rtas.entry = __be32_to_cpu(*entryp);
} else
rtas.dev = NULL;
}
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 15/63] powerpc: Make logical to real cpu mapping code endian safe

2013-08-06 Thread Anton Blanchard
Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/kernel/setup-common.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kernel/setup-common.c 
b/arch/powerpc/kernel/setup-common.c
index 63d051f..ee0e055 100644
--- a/arch/powerpc/kernel/setup-common.c
+++ b/arch/powerpc/kernel/setup-common.c
@@ -436,7 +436,7 @@ void __init smp_setup_cpu_maps(void)
DBG(smp_setup_cpu_maps()\n);
 
while ((dn = of_find_node_by_type(dn, cpu))  cpu  nr_cpu_ids) {
-   const int *intserv;
+   const __be32 *intserv;
int j, len;
 
DBG(  * %s...\n, dn-full_name);
@@ -456,9 +456,9 @@ void __init smp_setup_cpu_maps(void)
 
for (j = 0; j  nthreads  cpu  nr_cpu_ids; j++) {
DBG(thread %d - cpu %d (hard id %d)\n,
-   j, cpu, intserv[j]);
+   j, cpu, be32_to_cpu(intserv[j]));
set_cpu_present(cpu, true);
-   set_hard_smp_processor_id(cpu, intserv[j]);
+   set_hard_smp_processor_id(cpu, be32_to_cpu(intserv[j]));
set_cpu_possible(cpu, true);
cpu++;
}
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 14/63] powerpc: Make RTAS calls endian safe

2013-08-06 Thread Anton Blanchard
RTAS expects arguments in the call buffer to be big endian so we
need to byteswap on little endian builds

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/include/asm/rtas.h |  8 
 arch/powerpc/kernel/rtas.c  | 38 +++---
 2 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/arch/powerpc/include/asm/rtas.h b/arch/powerpc/include/asm/rtas.h
index c7a8bfc..9bd52c6 100644
--- a/arch/powerpc/include/asm/rtas.h
+++ b/arch/powerpc/include/asm/rtas.h
@@ -44,12 +44,12 @@
  *
  */
 
-typedef u32 rtas_arg_t;
+typedef __be32 rtas_arg_t;
 
 struct rtas_args {
-   u32 token;
-   u32 nargs;
-   u32 nret; 
+   __be32 token;
+   __be32 nargs;
+   __be32 nret; 
rtas_arg_t args[16];
rtas_arg_t *rets; /* Pointer to return values in args[]. */
 };  
diff --git a/arch/powerpc/kernel/rtas.c b/arch/powerpc/kernel/rtas.c
index 98b26af..4cf674d 100644
--- a/arch/powerpc/kernel/rtas.c
+++ b/arch/powerpc/kernel/rtas.c
@@ -91,7 +91,7 @@ static void unlock_rtas(unsigned long flags)
  * are designed only for very early low-level debugging, which
  * is why the token is hard-coded to 10.
  */
-static void call_rtas_display_status(char c)
+static void call_rtas_display_status(unsigned char c)
 {
struct rtas_args *args = rtas.args;
unsigned long s;
@@ -100,11 +100,11 @@ static void call_rtas_display_status(char c)
return;
s = lock_rtas();
 
-   args-token = 10;
-   args-nargs = 1;
-   args-nret  = 1;
-   args-rets  = (rtas_arg_t *)(args-args[1]);
-   args-args[0] = (unsigned char)c;
+   args-token = cpu_to_be32(10);
+   args-nargs = cpu_to_be32(1);
+   args-nret  = cpu_to_be32(1);
+   args-rets  = (args-args[1]);
+   args-args[0] = cpu_to_be32(c);
 
enter_rtas(__pa(args));
 
@@ -380,11 +380,11 @@ static char *__fetch_rtas_last_error(char *altbuf)
 
bufsz = rtas_get_error_log_max();
 
-   err_args.token = rtas_last_error_token;
-   err_args.nargs = 2;
-   err_args.nret = 1;
-   err_args.args[0] = (rtas_arg_t)__pa(rtas_err_buf);
-   err_args.args[1] = bufsz;
+   err_args.token = cpu_to_be32(rtas_last_error_token);
+   err_args.nargs = cpu_to_be32(2);
+   err_args.nret = cpu_to_be32(1);
+   err_args.args[0] = cpu_to_be32(__pa(rtas_err_buf));
+   err_args.args[1] = cpu_to_be32(bufsz);
err_args.args[2] = 0;
 
save_args = rtas.args;
@@ -433,13 +433,13 @@ int rtas_call(int token, int nargs, int nret, int 
*outputs, ...)
s = lock_rtas();
rtas_args = rtas.args;
 
-   rtas_args-token = token;
-   rtas_args-nargs = nargs;
-   rtas_args-nret  = nret;
-   rtas_args-rets  = (rtas_arg_t *)(rtas_args-args[nargs]);
+   rtas_args-token = cpu_to_be32(token);
+   rtas_args-nargs = cpu_to_be32(nargs);
+   rtas_args-nret  = cpu_to_be32(nret);
+   rtas_args-rets  = (rtas_args-args[nargs]);
va_start(list, outputs);
for (i = 0; i  nargs; ++i)
-   rtas_args-args[i] = va_arg(list, rtas_arg_t);
+   rtas_args-args[i] = cpu_to_be32(va_arg(list, __u32));
va_end(list);
 
for (i = 0; i  nret; ++i)
@@ -449,13 +449,13 @@ int rtas_call(int token, int nargs, int nret, int 
*outputs, ...)
 
/* A -1 return code indicates that the last command couldn't
   be completed due to a hardware error. */
-   if (rtas_args-rets[0] == -1)
+   if (be32_to_cpu(rtas_args-rets[0]) == -1)
buff_copy = __fetch_rtas_last_error(NULL);
 
if (nret  1  outputs != NULL)
for (i = 0; i  nret-1; ++i)
-   outputs[i] = rtas_args-rets[i+1];
-   ret = (nret  0)? rtas_args-rets[0]: 0;
+   outputs[i] = be32_to_cpu(rtas_args-rets[i+1]);
+   ret = (nret  0)? be32_to_cpu(rtas_args-rets[0]): 0;
 
unlock_rtas(s);
 
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 02/63] powerpc: handle unaligned ldbrx/stdbrx

2013-08-06 Thread Anton Blanchard
Normally when we haven't implemented an alignment handler for
a load or store instruction the process will be terminated.

The alignment handler uses the DSISR (or a pseudo one) to locate
the right handler. Unfortunately ldbrx and stdbrx overlap lfs and
stfs so we incorrectly think ldbrx is an lfs and stdbrx is an
stfs.

This bug is particularly nasty - instead of terminating the
process we apply an incorrect fixup and continue on.

With more and more overlapping instructions we should stop
creating a pseudo DSISR and index using the instruction directly,
but for now add a special case to catch ldbrx/stdbrx.

Signed-off-by: Anton Blanchard an...@samba.org
Cc: sta...@vger.kernel.org
---
 arch/powerpc/kernel/align.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/powerpc/kernel/align.c b/arch/powerpc/kernel/align.c
index ee5b690..52e5758 100644
--- a/arch/powerpc/kernel/align.c
+++ b/arch/powerpc/kernel/align.c
@@ -764,6 +764,16 @@ int fix_alignment(struct pt_regs *regs)
nb = aligninfo[instr].len;
flags = aligninfo[instr].flags;
 
+   /* ldbrx/stdbrx overlap lfs/stfs in the DSISR unfortunately */
+   if (IS_XFORM(instruction)  ((instruction  1)  0x3ff) == 532) {
+   nb = 8;
+   flags = LD+SW;
+   } else if (IS_XFORM(instruction) 
+  ((instruction  1)  0x3ff) == 660) {
+   nb = 8;
+   flags = ST+SW;
+   }
+
/* Byteswap little endian loads and stores */
swiz = 0;
if (regs-msr  MSR_LE) {
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 16/63] powerpc: More little endian fixes for setup-common.c

2013-08-06 Thread Anton Blanchard
From: Alistair Popple alist...@popple.id.au

Signed-off-by: Alistair Popple alist...@popple.id.au
---
 arch/powerpc/kernel/setup-common.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/setup-common.c 
b/arch/powerpc/kernel/setup-common.c
index ee0e055..3d261c0 100644
--- a/arch/powerpc/kernel/setup-common.c
+++ b/arch/powerpc/kernel/setup-common.c
@@ -437,6 +437,7 @@ void __init smp_setup_cpu_maps(void)
 
while ((dn = of_find_node_by_type(dn, cpu))  cpu  nr_cpu_ids) {
const __be32 *intserv;
+   __be32 cpu_be;
int j, len;
 
DBG(  * %s...\n, dn-full_name);
@@ -450,8 +451,10 @@ void __init smp_setup_cpu_maps(void)
} else {
DBG(no ibm,ppc-interrupt-server#s - 1 thread\n);
intserv = of_get_property(dn, reg, NULL);
-   if (!intserv)
-   intserv = cpu; /* assume logical == phys */
+   if (!intserv) {
+   cpu_be = cpu_to_be32(cpu);
+   intserv = cpu_be;  /* assume logical == 
phys */
+   }
}
 
for (j = 0; j  nthreads  cpu  nr_cpu_ids; j++) {
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 18/63] powerpc: Fix some endian issues in xics code

2013-08-06 Thread Anton Blanchard
Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/sysdev/xics/xics-common.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/sysdev/xics/xics-common.c 
b/arch/powerpc/sysdev/xics/xics-common.c
index 9049d9f..fe0cca4 100644
--- a/arch/powerpc/sysdev/xics/xics-common.c
+++ b/arch/powerpc/sysdev/xics/xics-common.c
@@ -49,7 +49,7 @@ void xics_update_irq_servers(void)
int i, j;
struct device_node *np;
u32 ilen;
-   const u32 *ireg;
+   const __be32 *ireg;
u32 hcpuid;
 
/* Find the server numbers for the boot cpu. */
@@ -75,8 +75,8 @@ void xics_update_irq_servers(void)
 * default distribution server
 */
for (j = 0; j  i; j += 2) {
-   if (ireg[j] == hcpuid) {
-   xics_default_distrib_server = ireg[j+1];
+   if (be32_to_cpu(ireg[j]) == hcpuid) {
+   xics_default_distrib_server = be32_to_cpu(ireg[j+1]);
break;
}
}
@@ -383,7 +383,7 @@ void __init xics_register_ics(struct ics *ics)
 static void __init xics_get_server_size(void)
 {
struct device_node *np;
-   const u32 *isize;
+   const __be32 *isize;
 
/* We fetch the interrupt server size from the first ICS node
 * we find if any
@@ -394,7 +394,7 @@ static void __init xics_get_server_size(void)
isize = of_get_property(np, ibm,interrupt-server#-size, NULL);
if (!isize)
return;
-   xics_interrupt_server_size = *isize;
+   xics_interrupt_server_size = be32_to_cpu(*isize);
of_node_put(np);
 }
 
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 17/63] powerpc: Add some endian annotations to time and xics code

2013-08-06 Thread Anton Blanchard
Fix a couple of sparse warnings.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/kernel/time.c| 2 +-
 arch/powerpc/sysdev/xics/icp-native.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 65ab9e9..c863aa1 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -612,7 +612,7 @@ unsigned long long sched_clock(void)
 static int __init get_freq(char *name, int cells, unsigned long *val)
 {
struct device_node *cpu;
-   const unsigned int *fp;
+   const __be32 *fp;
int found = 0;
 
/* The cpu node should have timebase and clock frequency properties */
diff --git a/arch/powerpc/sysdev/xics/icp-native.c 
b/arch/powerpc/sysdev/xics/icp-native.c
index 7cd728b..9dee470 100644
--- a/arch/powerpc/sysdev/xics/icp-native.c
+++ b/arch/powerpc/sysdev/xics/icp-native.c
@@ -216,7 +216,7 @@ static int __init icp_native_init_one_node(struct 
device_node *np,
   unsigned int *indx)
 {
unsigned int ilen;
-   const u32 *ireg;
+   const __be32 *ireg;
int i;
int reg_tuple_size;
int num_servers = 0;
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 20/63] powerpc: Make device tree accesses in cache info code endian safe

2013-08-06 Thread Anton Blanchard
Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/kernel/cacheinfo.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/kernel/cacheinfo.c b/arch/powerpc/kernel/cacheinfo.c
index 9262cf2..6549327 100644
--- a/arch/powerpc/kernel/cacheinfo.c
+++ b/arch/powerpc/kernel/cacheinfo.c
@@ -196,7 +196,7 @@ static void cache_cpu_set(struct cache *cache, int cpu)
 static int cache_size(const struct cache *cache, unsigned int *ret)
 {
const char *propname;
-   const u32 *cache_size;
+   const __be32 *cache_size;
 
propname = cache_type_info[cache-type].size_prop;
 
@@ -204,7 +204,7 @@ static int cache_size(const struct cache *cache, unsigned 
int *ret)
if (!cache_size)
return -ENODEV;
 
-   *ret = *cache_size;
+   *ret = of_read_number(cache_size, 1);
return 0;
 }
 
@@ -222,7 +222,7 @@ static int cache_size_kb(const struct cache *cache, 
unsigned int *ret)
 /* not cache_line_size() because that's a macro in include/linux/cache.h */
 static int cache_get_line_size(const struct cache *cache, unsigned int *ret)
 {
-   const u32 *line_size;
+   const __be32 *line_size;
int i, lim;
 
lim = ARRAY_SIZE(cache_type_info[cache-type].line_size_props);
@@ -239,14 +239,14 @@ static int cache_get_line_size(const struct cache *cache, 
unsigned int *ret)
if (!line_size)
return -ENODEV;
 
-   *ret = *line_size;
+   *ret = of_read_number(line_size, 1);
return 0;
 }
 
 static int cache_nr_sets(const struct cache *cache, unsigned int *ret)
 {
const char *propname;
-   const u32 *nr_sets;
+   const __be32 *nr_sets;
 
propname = cache_type_info[cache-type].nr_sets_prop;
 
@@ -254,7 +254,7 @@ static int cache_nr_sets(const struct cache *cache, 
unsigned int *ret)
if (!nr_sets)
return -ENODEV;
 
-   *ret = *nr_sets;
+   *ret = of_read_number(nr_sets, 1);
return 0;
 }
 
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 19/63] powerpc: of_parse_dma_window should take a __be32 *dma_window

2013-08-06 Thread Anton Blanchard
We pass dma_window to of_parse_dma_window as a void * and then
run through hoops to cast it back to a u32 array. In the process
we lose endian annotation.

Simplify it by just passing a __be32 * down.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/include/asm/prom.h|  5 +++--
 arch/powerpc/kernel/prom_parse.c   | 17 -
 arch/powerpc/kernel/vio.c  |  2 +-
 arch/powerpc/platforms/cell/iommu.c|  2 +-
 arch/powerpc/platforms/pseries/iommu.c |  8 
 5 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/arch/powerpc/include/asm/prom.h b/arch/powerpc/include/asm/prom.h
index bc2da15..fa2f30c 100644
--- a/arch/powerpc/include/asm/prom.h
+++ b/arch/powerpc/include/asm/prom.h
@@ -38,8 +38,9 @@ extern unsigned long pci_address_to_pio(phys_addr_t address);
 /* Parse the ibm,dma-window property of an OF node into the busno, phys and
  * size parameters.
  */
-void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,
-   unsigned long *busno, unsigned long *phys, unsigned long *size);
+void of_parse_dma_window(struct device_node *dn, const __be32 *dma_window,
+unsigned long *busno, unsigned long *phys,
+unsigned long *size);
 
 extern void kdump_move_device_tree(void);
 
diff --git a/arch/powerpc/kernel/prom_parse.c b/arch/powerpc/kernel/prom_parse.c
index 4e1331b..6295e64 100644
--- a/arch/powerpc/kernel/prom_parse.c
+++ b/arch/powerpc/kernel/prom_parse.c
@@ -7,28 +7,27 @@
 #include linux/of_address.h
 #include asm/prom.h
 
-void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,
-   unsigned long *busno, unsigned long *phys, unsigned long *size)
+void of_parse_dma_window(struct device_node *dn, const __be32 *dma_window,
+unsigned long *busno, unsigned long *phys,
+unsigned long *size)
 {
-   const u32 *dma_window;
u32 cells;
-   const unsigned char *prop;
-
-   dma_window = dma_window_prop;
+   const __be32 *prop;
 
/* busno is always one cell */
-   *busno = *(dma_window++);
+   *busno = of_read_number(dma_window, 1);
+   dma_window++;
 
prop = of_get_property(dn, ibm,#dma-address-cells, NULL);
if (!prop)
prop = of_get_property(dn, #address-cells, NULL);
 
-   cells = prop ? *(u32 *)prop : of_n_addr_cells(dn);
+   cells = prop ? of_read_number(prop, 1) : of_n_addr_cells(dn);
*phys = of_read_number(dma_window, cells);
 
dma_window += cells;
 
prop = of_get_property(dn, ibm,#dma-size-cells, NULL);
-   cells = prop ? *(u32 *)prop : of_n_size_cells(dn);
+   cells = prop ? of_read_number(prop, 1) : of_n_size_cells(dn);
*size = of_read_number(dma_window, cells);
 }
diff --git a/arch/powerpc/kernel/vio.c b/arch/powerpc/kernel/vio.c
index 536016d..31875a6 100644
--- a/arch/powerpc/kernel/vio.c
+++ b/arch/powerpc/kernel/vio.c
@@ -1153,7 +1153,7 @@ EXPORT_SYMBOL(vio_h_cop_sync);
 
 static struct iommu_table *vio_build_iommu_table(struct vio_dev *dev)
 {
-   const unsigned char *dma_window;
+   const __be32 *dma_window;
struct iommu_table *tbl;
unsigned long offset, size;
 
diff --git a/arch/powerpc/platforms/cell/iommu.c 
b/arch/powerpc/platforms/cell/iommu.c
index 946306b..b535606 100644
--- a/arch/powerpc/platforms/cell/iommu.c
+++ b/arch/powerpc/platforms/cell/iommu.c
@@ -697,7 +697,7 @@ static int __init cell_iommu_get_window(struct device_node 
*np,
 unsigned long *base,
 unsigned long *size)
 {
-   const void *dma_window;
+   const __be32 *dma_window;
unsigned long index;
 
/* Use ibm,dma-window if available, else, hard code ! */
diff --git a/arch/powerpc/platforms/pseries/iommu.c 
b/arch/powerpc/platforms/pseries/iommu.c
index 23fc1dc..9087f97 100644
--- a/arch/powerpc/platforms/pseries/iommu.c
+++ b/arch/powerpc/platforms/pseries/iommu.c
@@ -530,7 +530,7 @@ static void iommu_table_setparms(struct pci_controller *phb,
 static void iommu_table_setparms_lpar(struct pci_controller *phb,
  struct device_node *dn,
  struct iommu_table *tbl,
- const void *dma_window)
+ const __be32 *dma_window)
 {
unsigned long offset, size;
 
@@ -630,7 +630,7 @@ static void pci_dma_bus_setup_pSeriesLP(struct pci_bus *bus)
struct iommu_table *tbl;
struct device_node *dn, *pdn;
struct pci_dn *ppci;
-   const void *dma_window = NULL;
+   const __be32 *dma_window = NULL;
 
dn = pci_bus_to_OF_node(bus);
 
@@ -1152,7 +1152,7 @@ static void pci_dma_dev_setup_pSeriesLP(struct pci_dev 
*dev)
 {
struct device_node *pdn, *dn;
struct iommu_table *tbl;
-   

[PATCH 21/63] powerpc: Make prom_init.c endian safe

2013-08-06 Thread Anton Blanchard
From: Benjamin Herrenschmidt b...@kernel.crashing.org

Signed-off-by: Benjamin Herrenschmidt b...@kernel.crashing.org
Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/kernel/prom_init.c | 253 +++-
 1 file changed, 147 insertions(+), 106 deletions(-)

diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index 6079024..5996a2983 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -107,10 +107,10 @@ int of_workarounds;
 typedef u32 prom_arg_t;
 
 struct prom_args {
-u32 service;
-u32 nargs;
-u32 nret;
-prom_arg_t args[10];
+__be32 service;
+__be32 nargs;
+__be32 nret;
+__be32 args[10];
 };
 
 struct prom_t {
@@ -123,11 +123,11 @@ struct prom_t {
 };
 
 struct mem_map_entry {
-   u64 base;
-   u64 size;
+   __be64  base;
+   __be64  size;
 };
 
-typedef u32 cell_t;
+typedef __be32 cell_t;
 
 extern void __start(unsigned long r3, unsigned long r4, unsigned long r5,
unsigned long r6, unsigned long r7, unsigned long r8,
@@ -219,13 +219,13 @@ static int __init call_prom(const char *service, int 
nargs, int nret, ...)
struct prom_args args;
va_list list;
 
-   args.service = ADDR(service);
-   args.nargs = nargs;
-   args.nret = nret;
+   args.service = cpu_to_be32(ADDR(service));
+   args.nargs = cpu_to_be32(nargs);
+   args.nret = cpu_to_be32(nret);
 
va_start(list, nret);
for (i = 0; i  nargs; i++)
-   args.args[i] = va_arg(list, prom_arg_t);
+   args.args[i] = cpu_to_be32(va_arg(list, prom_arg_t));
va_end(list);
 
for (i = 0; i  nret; i++)
@@ -234,7 +234,7 @@ static int __init call_prom(const char *service, int nargs, 
int nret, ...)
if (enter_prom(args, prom_entry)  0)
return PROM_ERROR;
 
-   return (nret  0) ? args.args[nargs] : 0;
+   return (nret  0) ? be32_to_cpu(args.args[nargs]) : 0;
 }
 
 static int __init call_prom_ret(const char *service, int nargs, int nret,
@@ -244,13 +244,13 @@ static int __init call_prom_ret(const char *service, int 
nargs, int nret,
struct prom_args args;
va_list list;
 
-   args.service = ADDR(service);
-   args.nargs = nargs;
-   args.nret = nret;
+   args.service = cpu_to_be32(ADDR(service));
+   args.nargs = cpu_to_be32(nargs);
+   args.nret = cpu_to_be32(nret);
 
va_start(list, rets);
for (i = 0; i  nargs; i++)
-   args.args[i] = va_arg(list, prom_arg_t);
+   args.args[i] = cpu_to_be32(va_arg(list, prom_arg_t));
va_end(list);
 
for (i = 0; i  nret; i++)
@@ -261,9 +261,9 @@ static int __init call_prom_ret(const char *service, int 
nargs, int nret,
 
if (rets != NULL)
for (i = 1; i  nret; ++i)
-   rets[i-1] = args.args[nargs+i];
+   rets[i-1] = be32_to_cpu(args.args[nargs+i]);
 
-   return (nret  0) ? args.args[nargs] : 0;
+   return (nret  0) ? be32_to_cpu(args.args[nargs]) : 0;
 }
 
 
@@ -527,7 +527,7 @@ static int __init prom_setprop(phandle node, const char 
*nodename,
 #define islower(c) ('a' = (c)  (c) = 'z')
 #define toupper(c) (islower(c) ? ((c) - 'a' + 'A') : (c))
 
-unsigned long prom_strtoul(const char *cp, const char **endp)
+static unsigned long prom_strtoul(const char *cp, const char **endp)
 {
unsigned long result = 0, base = 10, value;
 
@@ -552,7 +552,7 @@ unsigned long prom_strtoul(const char *cp, const char 
**endp)
return result;
 }
 
-unsigned long prom_memparse(const char *ptr, const char **retptr)
+static unsigned long prom_memparse(const char *ptr, const char **retptr)
 {
unsigned long ret = prom_strtoul(ptr, retptr);
int shift = 0;
@@ -724,7 +724,8 @@ unsigned char ibm_architecture_vec[] = {
 
 };
 
-/* Old method - ELF header with PT_NOTE sections */
+/* Old method - ELF header with PT_NOTE sections only works on BE */
+#ifdef __BIG_ENDIAN__
 static struct fake_elf {
Elf32_Ehdr  elfhdr;
Elf32_Phdr  phdr[2];
@@ -810,6 +811,7 @@ static struct fake_elf {
}
}
 };
+#endif /* __BIG_ENDIAN__ */
 
 static int __init prom_count_smt_threads(void)
 {
@@ -852,9 +854,9 @@ static int __init prom_count_smt_threads(void)
 
 static void __init prom_send_capabilities(void)
 {
-   ihandle elfloader, root;
+   ihandle root;
prom_arg_t ret;
-   u32 *cores;
+   __be32 *cores;
 
root = call_prom(open, 1, 1, ADDR(/));
if (root != 0) {
@@ -864,15 +866,15 @@ static void __init prom_send_capabilities(void)
 * (we assume this is the same for all cores) and use it to
 * divide NR_CPUS.
 */
-   cores = (u32 
*)ibm_architecture_vec[IBM_ARCH_VEC_NRCORES_OFFSET];
-   if (*cores 

[PATCH 22/63] powerpc: Make device tree accesses in HVC VIO console endian safe

2013-08-06 Thread Anton Blanchard
Signed-off-by: Anton Blanchard an...@samba.org
---
 drivers/tty/hvc/hvc_vio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/hvc/hvc_vio.c b/drivers/tty/hvc/hvc_vio.c
index 0c62980..c791b18 100644
--- a/drivers/tty/hvc/hvc_vio.c
+++ b/drivers/tty/hvc/hvc_vio.c
@@ -404,7 +404,7 @@ module_exit(hvc_vio_exit);
 void __init hvc_vio_init_early(void)
 {
struct device_node *stdout_node;
-   const u32 *termno;
+   const __be32 *termno;
const char *name;
const struct hv_ops *ops;
 
@@ -429,7 +429,7 @@ void __init hvc_vio_init_early(void)
termno = of_get_property(stdout_node, reg, NULL);
if (termno == NULL)
goto out;
-   hvterm_priv0.termno = *termno;
+   hvterm_priv0.termno = of_read_number(termno, 1);
spin_lock_init(hvterm_priv0.buf_lock);
hvterm_privs[0] = hvterm_priv0;
 
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 24/63] powerpc: Make OF PCI device tree accesses endian safe

2013-08-06 Thread Anton Blanchard
Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/kernel/pci-common.c  |  6 +++---
 arch/powerpc/kernel/pci_of_scan.c | 23 +--
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
index 22fe401..7d72f8f 100644
--- a/arch/powerpc/kernel/pci-common.c
+++ b/arch/powerpc/kernel/pci-common.c
@@ -667,7 +667,7 @@ void pci_resource_to_user(const struct pci_dev *dev, int 
bar,
 void pci_process_bridge_OF_ranges(struct pci_controller *hose,
  struct device_node *dev, int primary)
 {
-   const u32 *ranges;
+   const __be32 *ranges;
int rlen;
int pna = of_n_addr_cells(dev);
int np = pna + 5;
@@ -687,7 +687,7 @@ void pci_process_bridge_OF_ranges(struct pci_controller 
*hose,
/* Parse it */
while ((rlen -= np * 4) = 0) {
/* Read next ranges element */
-   pci_space = ranges[0];
+   pci_space = of_read_number(ranges, 1);
pci_addr = of_read_number(ranges + 1, 2);
cpu_addr = of_translate_address(dev, ranges + 3);
size = of_read_number(ranges + pna + 3, 2);
@@ -704,7 +704,7 @@ void pci_process_bridge_OF_ranges(struct pci_controller 
*hose,
/* Now consume following elements while they are contiguous */
for (; rlen = np * sizeof(u32);
 ranges += np, rlen -= np * 4) {
-   if (ranges[0] != pci_space)
+   if (of_read_number(ranges, 1) != pci_space)
break;
pci_next = of_read_number(ranges + 1, 2);
cpu_next = of_translate_address(dev, ranges + 3);
diff --git a/arch/powerpc/kernel/pci_of_scan.c 
b/arch/powerpc/kernel/pci_of_scan.c
index 15d9105..4368ec6 100644
--- a/arch/powerpc/kernel/pci_of_scan.c
+++ b/arch/powerpc/kernel/pci_of_scan.c
@@ -24,12 +24,12 @@
  */
 static u32 get_int_prop(struct device_node *np, const char *name, u32 def)
 {
-   const u32 *prop;
+   const __be32 *prop;
int len;
 
prop = of_get_property(np, name, len);
if (prop  len = 4)
-   return *prop;
+   return of_read_number(prop, 1);
return def;
 }
 
@@ -77,7 +77,7 @@ static void of_pci_parse_addrs(struct device_node *node, 
struct pci_dev *dev)
unsigned int flags;
struct pci_bus_region region;
struct resource *res;
-   const u32 *addrs;
+   const __be32 *addrs;
u32 i;
int proplen;
 
@@ -86,14 +86,14 @@ static void of_pci_parse_addrs(struct device_node *node, 
struct pci_dev *dev)
return;
pr_debug(parse addresses (%d bytes) @ %p\n, proplen, addrs);
for (; proplen = 20; proplen -= 20, addrs += 5) {
-   flags = pci_parse_of_flags(addrs[0], 0);
+   flags = pci_parse_of_flags(of_read_number(addrs, 1), 0);
if (!flags)
continue;
base = of_read_number(addrs[1], 2);
size = of_read_number(addrs[3], 2);
if (!size)
continue;
-   i = addrs[0]  0xff;
+   i = of_read_number(addrs, 1)  0xff;
pr_debug(  base: %llx, size: %llx, i: %x\n,
 (unsigned long long)base,
 (unsigned long long)size, i);
@@ -207,7 +207,7 @@ void of_scan_pci_bridge(struct pci_dev *dev)
 {
struct device_node *node = dev-dev.of_node;
struct pci_bus *bus;
-   const u32 *busrange, *ranges;
+   const __be32 *busrange, *ranges;
int len, i, mode;
struct pci_bus_region region;
struct resource *res;
@@ -230,9 +230,11 @@ void of_scan_pci_bridge(struct pci_dev *dev)
return;
}
 
-   bus = pci_find_bus(pci_domain_nr(dev-bus), busrange[0]);
+   bus = pci_find_bus(pci_domain_nr(dev-bus),
+  of_read_number(busrange, 1));
if (!bus) {
-   bus = pci_add_new_bus(dev-bus, dev, busrange[0]);
+   bus = pci_add_new_bus(dev-bus, dev,
+ of_read_number(busrange, 1));
if (!bus) {
printk(KERN_ERR Failed to create pci bus for %s\n,
   node-full_name);
@@ -241,7 +243,8 @@ void of_scan_pci_bridge(struct pci_dev *dev)
}
 
bus-primary = dev-bus-number;
-   pci_bus_insert_busn_res(bus, busrange[0], busrange[1]);
+   pci_bus_insert_busn_res(bus, of_read_number(busrange, 1),
+   of_read_number(busrange+1, 1));
bus-bridge_ctl = 0;
 
/* parse ranges property */
@@ -254,7 +257,7 @@ void of_scan_pci_bridge(struct pci_dev *dev)
}
i = 1;
for (; len = 32; len -= 32, ranges += 8) {
-   flags = 

[PATCH 23/63] powerpc: Make device tree accesses in VIO subsystem endian safe

2013-08-06 Thread Anton Blanchard
Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/kernel/vio.c | 31 +--
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/arch/powerpc/kernel/vio.c b/arch/powerpc/kernel/vio.c
index 31875a6..78a3506 100644
--- a/arch/powerpc/kernel/vio.c
+++ b/arch/powerpc/kernel/vio.c
@@ -1312,8 +1312,7 @@ struct vio_dev *vio_register_device_node(struct 
device_node *of_node)
 {
struct vio_dev *viodev;
struct device_node *parent_node;
-   const unsigned int *unit_address;
-   const unsigned int *pfo_resid = NULL;
+   const __be32 *prop;
enum vio_dev_family family;
const char *of_node_name = of_node-name ? of_node-name : unknown;
 
@@ -1360,6 +1359,8 @@ struct vio_dev *vio_register_device_node(struct 
device_node *of_node)
/* we need the 'device_type' property, in order to match with drivers */
viodev-family = family;
if (viodev-family == VDEVICE) {
+   unsigned int unit_address;
+
if (of_node-type != NULL)
viodev-type = of_node-type;
else {
@@ -1368,24 +1369,24 @@ struct vio_dev *vio_register_device_node(struct 
device_node *of_node)
goto out;
}
 
-   unit_address = of_get_property(of_node, reg, NULL);
-   if (unit_address == NULL) {
+   prop = of_get_property(of_node, reg, NULL);
+   if (prop == NULL) {
pr_warn(%s: node %s missing 'reg'\n,
__func__, of_node_name);
goto out;
}
-   dev_set_name(viodev-dev, %x, *unit_address);
+   unit_address = of_read_number(prop, 1);
+   dev_set_name(viodev-dev, %x, unit_address);
viodev-irq = irq_of_parse_and_map(of_node, 0);
-   viodev-unit_address = *unit_address;
+   viodev-unit_address = unit_address;
} else {
/* PFO devices need their resource_id for submitting COP_OPs
 * This is an optional field for devices, but is required when
 * performing synchronous ops */
-   pfo_resid = of_get_property(of_node, ibm,resource-id, NULL);
-   if (pfo_resid != NULL)
-   viodev-resource_id = *pfo_resid;
+   prop = of_get_property(of_node, ibm,resource-id, NULL);
+   if (prop != NULL)
+   viodev-resource_id = of_read_number(prop, 1);
 
-   unit_address = NULL;
dev_set_name(viodev-dev, %s, of_node_name);
viodev-type = of_node_name;
viodev-irq = 0;
@@ -1622,7 +1623,6 @@ static struct vio_dev *vio_find_name(const char *name)
  */
 struct vio_dev *vio_find_node(struct device_node *vnode)
 {
-   const uint32_t *unit_address;
char kobj_name[20];
struct device_node *vnode_parent;
const char *dev_type;
@@ -1638,10 +1638,13 @@ struct vio_dev *vio_find_node(struct device_node *vnode)
 
/* construct the kobject name from the device node */
if (!strcmp(dev_type, vdevice)) {
-   unit_address = of_get_property(vnode, reg, NULL);
-   if (!unit_address)
+   const __be32 *prop;
+   
+   prop = of_get_property(vnode, reg, NULL);
+   if (!prop)
return NULL;
-   snprintf(kobj_name, sizeof(kobj_name), %x, *unit_address);
+   snprintf(kobj_name, sizeof(kobj_name), %x,
+(uint32_t)of_read_number(prop, 1));
} else if (!strcmp(dev_type, ibm,platform-facilities))
snprintf(kobj_name, sizeof(kobj_name), %s, vnode-name);
else
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 25/63] powerpc: Make PCI device node device tree accesses endian safe

2013-08-06 Thread Anton Blanchard
Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/kernel/pci_dn.c | 20 +++-
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/kernel/pci_dn.c b/arch/powerpc/kernel/pci_dn.c
index df03844..1f61fab 100644
--- a/arch/powerpc/kernel/pci_dn.c
+++ b/arch/powerpc/kernel/pci_dn.c
@@ -47,9 +47,8 @@ struct pci_dn *pci_get_pdn(struct pci_dev *pdev)
 void *update_dn_pci_info(struct device_node *dn, void *data)
 {
struct pci_controller *phb = data;
-   const int *type =
-   of_get_property(dn, ibm,pci-config-space-type, NULL);
-   const u32 *regs;
+   const __be32 *type = of_get_property(dn, ibm,pci-config-space-type, 
NULL);
+   const __be32 *regs;
struct pci_dn *pdn;
 
pdn = zalloc_maybe_bootmem(sizeof(*pdn), GFP_KERNEL);
@@ -63,12 +62,14 @@ void *update_dn_pci_info(struct device_node *dn, void *data)
 #endif
regs = of_get_property(dn, reg, NULL);
if (regs) {
+   u32 addr = of_read_number(regs, 1);
+
/* First register entry is addr (00BBSS00)  */
-   pdn-busno = (regs[0]  16)  0xff;
-   pdn-devfn = (regs[0]  8)  0xff;
+   pdn-busno = (addr  16)  0xff;
+   pdn-devfn = (addr  8)  0xff;
}
 
-   pdn-pci_ext_config_space = (type  *type == 1);
+   pdn-pci_ext_config_space = (type  of_read_number(type, 1) == 1);
return NULL;
 }
 
@@ -98,12 +99,13 @@ void *traverse_pci_devices(struct device_node *start, 
traverse_func pre,
 
/* We started with a phb, iterate all childs */
for (dn = start-child; dn; dn = nextdn) {
-   const u32 *classp;
-   u32 class;
+   const __be32 *classp;
+   u32 class = 0;
 
nextdn = NULL;
classp = of_get_property(dn, class-code, NULL);
-   class = classp ? *classp : 0;
+   if (classp)
+   class = of_read_number(classp, 1);
 
if (pre  ((ret = pre(dn, data)) != NULL))
return ret;
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 26/63] powerpc: Little endian fixes for legacy_serial.c

2013-08-06 Thread Anton Blanchard
From: Alistair Popple alist...@popple.id.au

Signed-off-by: Alistair Popple alist...@popple.id.au
---
 arch/powerpc/kernel/legacy_serial.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kernel/legacy_serial.c 
b/arch/powerpc/kernel/legacy_serial.c
index af1c63f..179beea 100644
--- a/arch/powerpc/kernel/legacy_serial.c
+++ b/arch/powerpc/kernel/legacy_serial.c
@@ -152,7 +152,7 @@ static int __init add_legacy_soc_port(struct device_node 
*np,
  struct device_node *soc_dev)
 {
u64 addr;
-   const u32 *addrp;
+   const __be32 *addrp;
upf_t flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_SHARE_IRQ
| UPF_FIXED_PORT;
struct device_node *tsi = of_get_parent(np);
@@ -237,7 +237,7 @@ static int __init add_legacy_pci_port(struct device_node 
*np,
  struct device_node *pci_dev)
 {
u64 addr, base;
-   const u32 *addrp;
+   const __be32 *addrp;
unsigned int flags;
int iotype, index = -1, lindex = 0;
 
@@ -270,7 +270,7 @@ static int __init add_legacy_pci_port(struct device_node 
*np,
if (iotype == UPIO_MEM)
base = addr;
else
-   base = addrp[2];
+   base = of_read_number(addrp[2], 1);
 
/* Try to guess an index... If we have subdevices of the pci dev,
 * we get to their reg property
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 27/63] powerpc: Make NUMA device node code endian safe

2013-08-06 Thread Anton Blanchard
From: Alistair Popple alist...@popple.id.au

The device tree is big endian so make sure we byteswap on little
endian. We assume any pHyp calls also return big endian results in
memory.

Signed-off-by: Alistair Popple alist...@popple.id.au
---
 arch/powerpc/mm/numa.c | 100 +
 1 file changed, 52 insertions(+), 48 deletions(-)

diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index 501e32c..c916127 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -58,7 +58,7 @@ static int form1_affinity;
 
 #define MAX_DISTANCE_REF_POINTS 4
 static int distance_ref_points_depth;
-static const unsigned int *distance_ref_points;
+static const __be32 *distance_ref_points;
 static int distance_lookup_table[MAX_NUMNODES][MAX_DISTANCE_REF_POINTS];
 
 /*
@@ -179,7 +179,7 @@ static void unmap_cpu_from_node(unsigned long cpu)
 #endif /* CONFIG_HOTPLUG_CPU || CONFIG_PPC_SPLPAR */
 
 /* must hold reference to node during call */
-static const int *of_get_associativity(struct device_node *dev)
+static const __be32 *of_get_associativity(struct device_node *dev)
 {
return of_get_property(dev, ibm,associativity, NULL);
 }
@@ -189,9 +189,9 @@ static const int *of_get_associativity(struct device_node 
*dev)
  * it exists (the property exists only in kexec/kdump kernels,
  * added by kexec-tools)
  */
-static const u32 *of_get_usable_memory(struct device_node *memory)
+static const __be32 *of_get_usable_memory(struct device_node *memory)
 {
-   const u32 *prop;
+   const __be32 *prop;
u32 len;
prop = of_get_property(memory, linux,drconf-usable-memory, len);
if (!prop || len  sizeof(unsigned int))
@@ -219,7 +219,7 @@ int __node_distance(int a, int b)
 }
 
 static void initialize_distance_lookup_table(int nid,
-   const unsigned int *associativity)
+   const __be32 *associativity)
 {
int i;
 
@@ -227,29 +227,32 @@ static void initialize_distance_lookup_table(int nid,
return;
 
for (i = 0; i  distance_ref_points_depth; i++) {
-   distance_lookup_table[nid][i] =
-   associativity[distance_ref_points[i]];
+   const __be32 *entry;
+
+   entry = associativity[be32_to_cpu(distance_ref_points[i])];
+   distance_lookup_table[nid][i] = of_read_number(entry, 1);
}
 }
 
 /* Returns nid in the range [0..MAX_NUMNODES-1], or -1 if no useful numa
  * info is found.
  */
-static int associativity_to_nid(const unsigned int *associativity)
+static int associativity_to_nid(const __be32 *associativity)
 {
int nid = -1;
 
if (min_common_depth == -1)
goto out;
 
-   if (associativity[0] = min_common_depth)
-   nid = associativity[min_common_depth];
+   if (of_read_number(associativity, 1) = min_common_depth)
+   nid = of_read_number(associativity[min_common_depth], 1);
 
/* POWER4 LPAR uses 0x as invalid node */
if (nid == 0x || nid = MAX_NUMNODES)
nid = -1;
 
-   if (nid  0  associativity[0] = distance_ref_points_depth)
+   if (nid  0 
+   of_read_number(associativity, 1) = distance_ref_points_depth)
initialize_distance_lookup_table(nid, associativity);
 
 out:
@@ -262,7 +265,7 @@ out:
 static int of_node_to_nid_single(struct device_node *device)
 {
int nid = -1;
-   const unsigned int *tmp;
+   const __be32 *tmp;
 
tmp = of_get_associativity(device);
if (tmp)
@@ -334,7 +337,7 @@ static int __init find_min_common_depth(void)
}
 
if (form1_affinity) {
-   depth = distance_ref_points[0];
+   depth = of_read_number(distance_ref_points, 1);
} else {
if (distance_ref_points_depth  2) {
printk(KERN_WARNING NUMA: 
@@ -342,7 +345,7 @@ static int __init find_min_common_depth(void)
goto err;
}
 
-   depth = distance_ref_points[1];
+   depth = of_read_number(distance_ref_points[1], 1);
}
 
/*
@@ -376,12 +379,12 @@ static void __init get_n_mem_cells(int *n_addr_cells, int 
*n_size_cells)
of_node_put(memory);
 }
 
-static unsigned long read_n_cells(int n, const unsigned int **buf)
+static unsigned long read_n_cells(int n, const __be32 **buf)
 {
unsigned long result = 0;
 
while (n--) {
-   result = (result  32) | **buf;
+   result = (result  32) | of_read_number(*buf, 1);
(*buf)++;
}
return result;
@@ -391,17 +394,17 @@ static unsigned long read_n_cells(int n, const unsigned 
int **buf)
  * Read the next memblock list entry from the ibm,dynamic-memory property
  * and return the information in the provided of_drconf_cell structure.
  */
-static void read_drconf_cell(struct of_drconf_cell *drmem, const u32 **cellp)
+static 

[PATCH 30/63] powerpc: Emulate instructions in little endian mode

2013-08-06 Thread Anton Blanchard
Alistair noticed we got a SIGILL on userspace mfpvr instructions.

Remove the little endian check in the emulation code, it is
probably there to protect against the old pseudo little endian
implementations but doesn't make sense for real little endian.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/kernel/traps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
index bf33c22..e601220 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -964,7 +964,7 @@ static int emulate_instruction(struct pt_regs *regs)
u32 instword;
u32 rd;
 
-   if (!user_mode(regs) || (regs-msr  MSR_LE))
+   if (!user_mode(regs))
return -EINVAL;
CHECK_FULL_REGS(regs);
 
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 29/63] powerpc: Fix little endian lppaca, slb_shadow and dtl_entry

2013-08-06 Thread Anton Blanchard
The lppaca, slb_shadow and dtl_entry hypervisor structures are
big endian, so we have to byte swap them in little endian builds.

LE KVM hosts will also need to be fixed but for now add an #error
to remind us.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/include/asm/asm-compat.h   |  9 +
 arch/powerpc/include/asm/ppc_asm.h  |  3 ++-
 arch/powerpc/kernel/entry_64.S  | 11 +++
 arch/powerpc/kernel/lparcfg.c   |  9 +
 arch/powerpc/kernel/paca.c  | 10 +-
 arch/powerpc/kernel/time.c  | 16 
 arch/powerpc/kvm/book3s_64_slb.S|  4 
 arch/powerpc/kvm/book3s_hv_rmhandlers.S |  4 
 arch/powerpc/lib/locks.c|  4 ++--
 arch/powerpc/mm/fault.c |  6 +-
 arch/powerpc/mm/slb.c   |  9 ++---
 arch/powerpc/platforms/pseries/dtl.c|  2 +-
 arch/powerpc/platforms/pseries/lpar.c   |  2 +-
 arch/powerpc/platforms/pseries/processor_idle.c |  6 +-
 arch/powerpc/platforms/pseries/setup.c  |  2 +-
 15 files changed, 65 insertions(+), 32 deletions(-)

diff --git a/arch/powerpc/include/asm/asm-compat.h 
b/arch/powerpc/include/asm/asm-compat.h
index 6e82f5f..4b237aa 100644
--- a/arch/powerpc/include/asm/asm-compat.h
+++ b/arch/powerpc/include/asm/asm-compat.h
@@ -32,6 +32,15 @@
 #define PPC_MTOCRF(FXM, RS) MTOCRF((FXM), RS)
 #define PPC_LR_STKOFF  16
 #define PPC_MIN_STKFRM 112
+
+#ifdef __BIG_ENDIAN__
+#define LDX_BE stringify_in_c(ldx)
+#define STDX_BEstringify_in_c(stdx)
+#else
+#define LDX_BE stringify_in_c(ldbrx)
+#define STDX_BEstringify_in_c(stdbrx)
+#endif
+
 #else /* 32-bit */
 
 /* operations for longs and pointers */
diff --git a/arch/powerpc/include/asm/ppc_asm.h 
b/arch/powerpc/include/asm/ppc_asm.h
index b5c85f1..4ebb4f8 100644
--- a/arch/powerpc/include/asm/ppc_asm.h
+++ b/arch/powerpc/include/asm/ppc_asm.h
@@ -54,7 +54,8 @@ BEGIN_FW_FTR_SECTION; 
\
/* from user - see if there are any DTL entries to process */   \
ld  r10,PACALPPACAPTR(r13); /* get ptr to VPA */\
ld  r11,PACA_DTL_RIDX(r13); /* get log read index */\
-   ld  r10,LPPACA_DTLIDX(r10); /* get log write index */   \
+   addir10,r10,LPPACA_DTLIDX;  \
+   LDX_BE  r10,0,r10;  /* get log write index */   \
cmpdcr1,r11,r10;\
beq+cr1,33f;\
bl  .accumulate_stolen_time;\
diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
index ab15b8d..209e8ce 100644
--- a/arch/powerpc/kernel/entry_64.S
+++ b/arch/powerpc/kernel/entry_64.S
@@ -102,7 +102,8 @@ BEGIN_FW_FTR_SECTION
/* if from user, see if there are any DTL entries to process */
ld  r10,PACALPPACAPTR(r13)  /* get ptr to VPA */
ld  r11,PACA_DTL_RIDX(r13)  /* get log read index */
-   ld  r10,LPPACA_DTLIDX(r10)  /* get log write index */
+   addir10,r10,LPPACA_DTLIDX
+   LDX_BE  r10,0,r10   /* get log write index */
cmpdcr1,r11,r10
beq+cr1,33f
bl  .accumulate_stolen_time
@@ -531,9 +532,11 @@ END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
 */
ld  r9,PACA_SLBSHADOWPTR(r13)
li  r12,0
-   std r12,SLBSHADOW_STACKESID(r9) /* Clear ESID */
-   std r7,SLBSHADOW_STACKVSID(r9)  /* Save VSID */
-   std r0,SLBSHADOW_STACKESID(r9)  /* Save ESID */
+   std r12,SLBSHADOW_STACKESID(r9) /* Clear ESID */
+   li  r12,SLBSHADOW_STACKVSID
+   STDX_BE r7,r12,r9   /* Save VSID */
+   li  r12,SLBSHADOW_STACKESID
+   STDX_BE r0,r12,r9   /* Save ESID */
 
/* No need to check for MMU_FTR_NO_SLBIE_B here, since when
 * we have 1TB segments, the only CPUs known to have the errata
diff --git a/arch/powerpc/kernel/lparcfg.c b/arch/powerpc/kernel/lparcfg.c
index e6024c2..0204089 100644
--- a/arch/powerpc/kernel/lparcfg.c
+++ b/arch/powerpc/kernel/lparcfg.c
@@ -387,8 +387,8 @@ static void pseries_cmo_data(struct seq_file *m)
return;
 
for_each_possible_cpu(cpu) {
-   cmo_faults += lppaca_of(cpu).cmo_faults;
-   cmo_fault_time += lppaca_of(cpu).cmo_fault_time;
+   cmo_faults += be64_to_cpu(lppaca_of(cpu).cmo_faults);
+   cmo_fault_time += be64_to_cpu(lppaca_of(cpu).cmo_fault_time);
}
 
seq_printf(m, cmo_faults=%lu\n, cmo_faults);
@@ -406,8 +406,9 @@ static void splpar_dispatch_data(struct seq_file *m)
unsigned long dispatch_dispersions = 0;
 

[PATCH 31/63] powerpc: Little endian SMP IPI demux

2013-08-06 Thread Anton Blanchard
Add little endian support for demuxing SMP IPIs

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/kernel/smp.c | 19 ++-
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index 98822400..bcdb706 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -210,6 +210,12 @@ void smp_muxed_ipi_message_pass(int cpu, int msg)
smp_ops-cause_ipi(cpu, info-data);
 }
 
+#ifdef __BIG_ENDIAN__
+#define IPI_MESSAGE(A) (1  (24 - 8 * (A)))
+#else
+#define IPI_MESSAGE(A) (1  (8 * (A)))
+#endif
+
 irqreturn_t smp_ipi_demux(void)
 {
struct cpu_messages *info = __get_cpu_var(ipi_message);
@@ -219,19 +225,14 @@ irqreturn_t smp_ipi_demux(void)
 
do {
all = xchg(info-messages, 0);
-
-#ifdef __BIG_ENDIAN
-   if (all  (1  (24 - 8 * PPC_MSG_CALL_FUNCTION)))
+   if (all  IPI_MESSAGE(PPC_MSG_CALL_FUNCTION))
generic_smp_call_function_interrupt();
-   if (all  (1  (24 - 8 * PPC_MSG_RESCHEDULE)))
+   if (all  IPI_MESSAGE(PPC_MSG_RESCHEDULE))
scheduler_ipi();
-   if (all  (1  (24 - 8 * PPC_MSG_CALL_FUNC_SINGLE)))
+   if (all  IPI_MESSAGE(PPC_MSG_CALL_FUNC_SINGLE))
generic_smp_call_function_single_interrupt();
-   if (all  (1  (24 - 8 * PPC_MSG_DEBUGGER_BREAK)))
+   if (all  IPI_MESSAGE(PPC_MSG_DEBUGGER_BREAK))
debug_ipi_action(0, NULL);
-#else
-#error Unsupported ENDIAN
-#endif
} while (info-messages);
 
return IRQ_HANDLED;
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 32/63] powerpc/pseries: Fix endian issues in H_GET_TERM_CHAR/H_PUT_TERM_CHAR

2013-08-06 Thread Anton Blanchard
Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/platforms/pseries/hvconsole.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/hvconsole.c 
b/arch/powerpc/platforms/pseries/hvconsole.c
index aa0aa37..ef6d59a 100644
--- a/arch/powerpc/platforms/pseries/hvconsole.c
+++ b/arch/powerpc/platforms/pseries/hvconsole.c
@@ -45,8 +45,8 @@ int hvc_get_chars(uint32_t vtermno, char *buf, int count)
unsigned long *lbuf = (unsigned long *)buf;
 
ret = plpar_hcall(H_GET_TERM_CHAR, retbuf, vtermno);
-   lbuf[0] = retbuf[1];
-   lbuf[1] = retbuf[2];
+   lbuf[0] = be64_to_cpu(retbuf[1]);
+   lbuf[1] = be64_to_cpu(retbuf[2]);
 
if (ret == H_SUCCESS)
return retbuf[0];
@@ -75,8 +75,9 @@ int hvc_put_chars(uint32_t vtermno, const char *buf, int 
count)
if (count  MAX_VIO_PUT_CHARS)
count = MAX_VIO_PUT_CHARS;
 
-   ret = plpar_hcall_norets(H_PUT_TERM_CHAR, vtermno, count, lbuf[0],
-lbuf[1]);
+   ret = plpar_hcall_norets(H_PUT_TERM_CHAR, vtermno, count,
+cpu_to_be64(lbuf[0]),
+cpu_to_be64(lbuf[1]));
if (ret == H_SUCCESS)
return count;
if (ret == H_BUSY)
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 33/63] powerpc: Fix little endian coredumps

2013-08-06 Thread Anton Blanchard
We need to set ELF_DATA correctly on LE coredumps.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/include/uapi/asm/elf.h | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/include/uapi/asm/elf.h 
b/arch/powerpc/include/uapi/asm/elf.h
index 89fa042..7e39c91 100644
--- a/arch/powerpc/include/uapi/asm/elf.h
+++ b/arch/powerpc/include/uapi/asm/elf.h
@@ -109,7 +109,6 @@ typedef elf_gregset_t32 compat_elf_gregset_t;
 # define ELF_GREG_TYPE elf_greg_t64
 # define ELF_ARCH  EM_PPC64
 # define ELF_CLASS ELFCLASS64
-# define ELF_DATA  ELFDATA2MSB
 typedef elf_greg_t64 elf_greg_t;
 typedef elf_gregset_t64 elf_gregset_t;
 #else
@@ -118,11 +117,16 @@ typedef elf_gregset_t64 elf_gregset_t;
 # define ELF_GREG_TYPE elf_greg_t32
 # define ELF_ARCH  EM_PPC
 # define ELF_CLASS ELFCLASS32
-# define ELF_DATA  ELFDATA2MSB
 typedef elf_greg_t32 elf_greg_t;
 typedef elf_gregset_t32 elf_gregset_t;
 #endif /* __powerpc64__ */
 
+#ifdef __BIG_ENDIAN__
+#define ELF_DATA   ELFDATA2MSB
+#else
+#define ELF_DATA   ELFDATA2LSB
+#endif
+
 /* Floating point registers */
 typedef double elf_fpreg_t;
 typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 34/63] powerpc: Make rwlocks endian safe

2013-08-06 Thread Anton Blanchard
Our ppc64 spinlocks and rwlocks use a trick where a lock token and
the paca index are placed in the lock with a single store. Since we
are using two u16s they need adjusting for little endian.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/include/asm/paca.h | 5 +
 arch/powerpc/include/asm/spinlock.h | 4 
 arch/powerpc/kvm/book3s_hv_rm_mmu.c | 4 
 arch/powerpc/kvm/book3s_hv_rmhandlers.S | 8 
 4 files changed, 21 insertions(+)

diff --git a/arch/powerpc/include/asm/paca.h b/arch/powerpc/include/asm/paca.h
index 77c91e7..2bf78b3 100644
--- a/arch/powerpc/include/asm/paca.h
+++ b/arch/powerpc/include/asm/paca.h
@@ -68,8 +68,13 @@ struct paca_struct {
 * instruction.  They must travel together and be properly
 * aligned.
 */
+#ifdef __BIG_ENDIAN__
u16 lock_token; /* Constant 0x8000, used in locks */
u16 paca_index; /* Logical processor number */
+#else
+   u16 paca_index; /* Logical processor number */
+   u16 lock_token; /* Constant 0x8000, used in locks */
+#endif
 
u64 kernel_toc; /* Kernel TOC address */
u64 kernelbase; /* Base address of kernel */
diff --git a/arch/powerpc/include/asm/spinlock.h 
b/arch/powerpc/include/asm/spinlock.h
index 7c345b6..5f54a74 100644
--- a/arch/powerpc/include/asm/spinlock.h
+++ b/arch/powerpc/include/asm/spinlock.h
@@ -32,8 +32,12 @@
 
 #ifdef CONFIG_PPC64
 /* use 0x80yy when locked, where yy == CPU number */
+#ifdef __BIG_ENDIAN__
 #define LOCK_TOKEN (*(u32 *)(get_paca()-lock_token))
 #else
+#define LOCK_TOKEN (*(u32 *)(get_paca()-paca_index))
+#endif
+#else
 #define LOCK_TOKEN 1
 #endif
 
diff --git a/arch/powerpc/kvm/book3s_hv_rm_mmu.c 
b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
index fc25689..c3785d4 100644
--- a/arch/powerpc/kvm/book3s_hv_rm_mmu.c
+++ b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
@@ -363,7 +363,11 @@ long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long 
flags,
 vcpu-arch.pgdir, true, vcpu-arch.gpr[4]);
 }
 
+#ifdef __BIG_ENDIAN__
 #define LOCK_TOKEN (*(u32 *)(get_paca()-lock_token))
+#else
+#define LOCK_TOKEN (*(u32 *)(get_paca()-paca_index))
+#endif
 
 static inline int try_lock_tlbie(unsigned int *lock)
 {
diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S 
b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index 20e7fcd..b93e3cd 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -393,7 +393,11 @@ toc_tlbie_lock:
.tc native_tlbie_lock[TC],native_tlbie_lock
.previous
ld  r3,toc_tlbie_lock@toc(2)
+#ifdef __BIG_ENDIAN__
lwz r8,PACA_LOCK_TOKEN(r13)
+#else
+   lwz r8,PACAPACAINDEX(r13)
+#endif
 24:lwarx   r0,0,r3
cmpwi   r0,0
bne 24b
@@ -968,7 +972,11 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
 32:ld  r4,VCPU_KVM(r9) /* pointer to struct kvm */
 
/* Take the guest's tlbie_lock */
+#ifdef __BIG_ENDIAN__
lwz r8,PACA_LOCK_TOKEN(r13)
+#else
+   lwz r8,PACAPACAINDEX(r13)
+#endif
addir3,r4,KVM_TLBIE_LOCK
 24:lwarx   r0,0,r3
cmpwi   r0,0
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 35/63] powerpc: Fix endian issues in VMX copy loops

2013-08-06 Thread Anton Blanchard
Fix the permute loops for little endian.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/lib/copyuser_power7.S | 54 +
 arch/powerpc/lib/memcpy_power7.S   | 55 ++
 2 files changed, 63 insertions(+), 46 deletions(-)

diff --git a/arch/powerpc/lib/copyuser_power7.S 
b/arch/powerpc/lib/copyuser_power7.S
index d1f1179..e8e9c36 100644
--- a/arch/powerpc/lib/copyuser_power7.S
+++ b/arch/powerpc/lib/copyuser_power7.S
@@ -19,6 +19,14 @@
  */
 #include asm/ppc_asm.h
 
+#ifdef __BIG_ENDIAN__
+#define LVS(VRT,RA,RB) lvslVRT,RA,RB
+#define VPERM(VRT,VRA,VRB,VRC) vperm   VRT,VRA,VRB,VRC
+#else
+#define LVS(VRT,RA,RB) lvsrVRT,RA,RB
+#define VPERM(VRT,VRA,VRB,VRC) vperm   VRT,VRB,VRA,VRC
+#endif
+
.macro err1
 100:
.section __ex_table,a
@@ -552,13 +560,13 @@ err3; stw r7,4(r3)
li  r10,32
li  r11,48
 
-   lvslvr16,0,r4   /* Setup permute control vector */
+   LVS(vr16,0,r4)  /* Setup permute control vector */
 err3;  lvx vr0,0,r4
addir4,r4,16
 
bf  cr7*4+3,5f
 err3;  lvx vr1,r0,r4
-   vperm   vr8,vr0,vr1,vr16
+   VPERM(vr8,vr0,vr1,vr16)
addir4,r4,16
 err3;  stvxvr8,r0,r3
addir3,r3,16
@@ -566,9 +574,9 @@ err3;   stvxvr8,r0,r3
 
 5: bf  cr7*4+2,6f
 err3;  lvx vr1,r0,r4
-   vperm   vr8,vr0,vr1,vr16
+   VPERM(vr8,vr0,vr1,vr16)
 err3;  lvx vr0,r4,r9
-   vperm   vr9,vr1,vr0,vr16
+   VPERM(vr9,vr1,vr0,vr16)
addir4,r4,32
 err3;  stvxvr8,r0,r3
 err3;  stvxvr9,r3,r9
@@ -576,13 +584,13 @@ err3; stvxvr9,r3,r9
 
 6: bf  cr7*4+1,7f
 err3;  lvx vr3,r0,r4
-   vperm   vr8,vr0,vr3,vr16
+   VPERM(vr8,vr0,vr3,vr16)
 err3;  lvx vr2,r4,r9
-   vperm   vr9,vr3,vr2,vr16
+   VPERM(vr9,vr3,vr2,vr16)
 err3;  lvx vr1,r4,r10
-   vperm   vr10,vr2,vr1,vr16
+   VPERM(vr10,vr2,vr1,vr16)
 err3;  lvx vr0,r4,r11
-   vperm   vr11,vr1,vr0,vr16
+   VPERM(vr11,vr1,vr0,vr16)
addir4,r4,64
 err3;  stvxvr8,r0,r3
 err3;  stvxvr9,r3,r9
@@ -611,21 +619,21 @@ err3; stvxvr11,r3,r11
.align  5
 8:
 err4;  lvx vr7,r0,r4
-   vperm   vr8,vr0,vr7,vr16
+   VPERM(vr8,vr0,vr7,vr16)
 err4;  lvx vr6,r4,r9
-   vperm   vr9,vr7,vr6,vr16
+   VPERM(vr9,vr7,vr6,vr16)
 err4;  lvx vr5,r4,r10
-   vperm   vr10,vr6,vr5,vr16
+   VPERM(vr10,vr6,vr5,vr16)
 err4;  lvx vr4,r4,r11
-   vperm   vr11,vr5,vr4,vr16
+   VPERM(vr11,vr5,vr4,vr16)
 err4;  lvx vr3,r4,r12
-   vperm   vr12,vr4,vr3,vr16
+   VPERM(vr12,vr4,vr3,vr16)
 err4;  lvx vr2,r4,r14
-   vperm   vr13,vr3,vr2,vr16
+   VPERM(vr13,vr3,vr2,vr16)
 err4;  lvx vr1,r4,r15
-   vperm   vr14,vr2,vr1,vr16
+   VPERM(vr14,vr2,vr1,vr16)
 err4;  lvx vr0,r4,r16
-   vperm   vr15,vr1,vr0,vr16
+   VPERM(vr15,vr1,vr0,vr16)
addir4,r4,128
 err4;  stvxvr8,r0,r3
 err4;  stvxvr9,r3,r9
@@ -649,13 +657,13 @@ err4; stvxvr15,r3,r16
 
bf  cr7*4+1,9f
 err3;  lvx vr3,r0,r4
-   vperm   vr8,vr0,vr3,vr16
+   VPERM(vr8,vr0,vr3,vr16)
 err3;  lvx vr2,r4,r9
-   vperm   vr9,vr3,vr2,vr16
+   VPERM(vr9,vr3,vr2,vr16)
 err3;  lvx vr1,r4,r10
-   vperm   vr10,vr2,vr1,vr16
+   VPERM(vr10,vr2,vr1,vr16)
 err3;  lvx vr0,r4,r11
-   vperm   vr11,vr1,vr0,vr16
+   VPERM(vr11,vr1,vr0,vr16)
addir4,r4,64
 err3;  stvxvr8,r0,r3
 err3;  stvxvr9,r3,r9
@@ -665,9 +673,9 @@ err3;   stvxvr11,r3,r11
 
 9: bf  cr7*4+2,10f
 err3;  lvx vr1,r0,r4
-   vperm   vr8,vr0,vr1,vr16
+   VPERM(vr8,vr0,vr1,vr16)
 err3;  lvx vr0,r4,r9
-   vperm   vr9,vr1,vr0,vr16
+   VPERM(vr9,vr1,vr0,vr16)
addir4,r4,32
 err3;  stvxvr8,r0,r3
 err3;  stvxvr9,r3,r9
@@ -675,7 +683,7 @@ err3;   stvxvr9,r3,r9
 
 10:bf  cr7*4+3,11f
 err3;  lvx vr1,r0,r4
-   vperm   vr8,vr0,vr1,vr16
+   VPERM(vr8,vr0,vr1,vr16)
addir4,r4,16
 err3;  stvxvr8,r0,r3
addir3,r3,16
diff --git a/arch/powerpc/lib/memcpy_power7.S b/arch/powerpc/lib/memcpy_power7.S
index 0663630..e4177db 100644
--- a/arch/powerpc/lib/memcpy_power7.S
+++ b/arch/powerpc/lib/memcpy_power7.S
@@ -20,6 +20,15 @@
 #include asm/ppc_asm.h
 
 _GLOBAL(memcpy_power7)
+
+#ifdef __BIG_ENDIAN__
+#define LVS(VRT,RA,RB) lvslVRT,RA,RB
+#define VPERM(VRT,VRA,VRB,VRC) vperm   VRT,VRA,VRB,VRC
+#else
+#define LVS(VRT,RA,RB) lvsrVRT,RA,RB
+#define VPERM(VRT,VRA,VRB,VRC) vperm   VRT,VRB,VRA,VRC
+#endif
+
 #ifdef CONFIG_ALTIVEC
cmpldi  r5,16
cmpldi  cr1,r5,4096
@@ -485,13 +494,13 @@ _GLOBAL(memcpy_power7)
li  r10,32
li  r11,48
 
-   lvslvr16,0,r4   /* Setup permute control vector */
+   LVS(vr16,0,r4)  /* 

[PATCH 38/63] powerpc: PTRACE_PEEKUSR/PTRACE_POKEUSER of FPR registers in little endian builds

2013-08-06 Thread Anton Blanchard
FPRs overlap the high 64bits of the first 32 VSX registers. The
ptrace FP read/write code assumes big endian ordering and grabs
the lowest 64 bits.

Fix this by using the TS_FPR macro which does the right thing.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/kernel/ptrace.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
index 9a0d24c..8d5d4e9 100644
--- a/arch/powerpc/kernel/ptrace.c
+++ b/arch/powerpc/kernel/ptrace.c
@@ -1554,8 +1554,8 @@ long arch_ptrace(struct task_struct *child, long request,
 
flush_fp_to_thread(child);
if (fpidx  (PT_FPSCR - PT_FPR0))
-   tmp = ((unsigned long *)child-thread.fpr)
-   [fpidx * TS_FPRWIDTH];
+   memcpy(tmp, child-thread.TS_FPR(fpidx),
+  sizeof(long));
else
tmp = child-thread.fpscr.val;
}
@@ -1587,8 +1587,8 @@ long arch_ptrace(struct task_struct *child, long request,
 
flush_fp_to_thread(child);
if (fpidx  (PT_FPSCR - PT_FPR0))
-   ((unsigned long *)child-thread.fpr)
-   [fpidx * TS_FPRWIDTH] = data;
+   memcpy(child-thread.TS_FPR(fpidx), data,
+  sizeof(long));
else
child-thread.fpscr.val = data;
ret = 0;
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 37/63] powerpc: Fix offset of FPRs in VSX registers in little endian builds

2013-08-06 Thread Anton Blanchard
The FPRs overlap the high doublewords of the first 32 VSX registers.
Fix TS_FPROFFSET and TS_VSRLOWOFFSET so we access the correct fields
in little endian mode.

If VSX is disabled the FPRs are only one doubleword in length so
TS_FPROFFSET needs adjusting in little endian.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/include/asm/processor.h | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/include/asm/processor.h 
b/arch/powerpc/include/asm/processor.h
index 47a35b0..d705431 100644
--- a/arch/powerpc/include/asm/processor.h
+++ b/arch/powerpc/include/asm/processor.h
@@ -14,8 +14,18 @@
 
 #ifdef CONFIG_VSX
 #define TS_FPRWIDTH 2
+
+#ifdef __BIG_ENDIAN__
+#define TS_FPROFFSET 0
+#define TS_VSRLOWOFFSET 1
+#else
+#define TS_FPROFFSET 1
+#define TS_VSRLOWOFFSET 0
+#endif
+
 #else
 #define TS_FPRWIDTH 1
+#define TS_FPROFFSET 0
 #endif
 
 #ifdef CONFIG_PPC64
@@ -142,8 +152,6 @@ typedef struct {
unsigned long seg;
 } mm_segment_t;
 
-#define TS_FPROFFSET 0
-#define TS_VSRLOWOFFSET 1
 #define TS_FPR(i) fpr[i][TS_FPROFFSET]
 #define TS_TRANS_FPR(i) transact_fpr[i][TS_FPROFFSET]
 
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 36/63] powerpc: Book 3S MMU little endian support

2013-08-06 Thread Anton Blanchard
Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/include/asm/mmu-hash64.h |  4 +--
 arch/powerpc/mm/hash_native_64.c  | 46 ---
 arch/powerpc/mm/hash_utils_64.c   | 38 ++---
 3 files changed, 46 insertions(+), 42 deletions(-)

diff --git a/arch/powerpc/include/asm/mmu-hash64.h 
b/arch/powerpc/include/asm/mmu-hash64.h
index c4cf011..807014d 100644
--- a/arch/powerpc/include/asm/mmu-hash64.h
+++ b/arch/powerpc/include/asm/mmu-hash64.h
@@ -135,8 +135,8 @@ extern char initial_stab[];
 #ifndef __ASSEMBLY__
 
 struct hash_pte {
-   unsigned long v;
-   unsigned long r;
+   __be64 v;
+   __be64 r;
 };
 
 extern struct hash_pte *htab_address;
diff --git a/arch/powerpc/mm/hash_native_64.c b/arch/powerpc/mm/hash_native_64.c
index c33d939..9bcd991 100644
--- a/arch/powerpc/mm/hash_native_64.c
+++ b/arch/powerpc/mm/hash_native_64.c
@@ -35,7 +35,11 @@
 #define DBG_LOW(fmt...)
 #endif
 
+#ifdef __BIG_ENDIAN__
 #define HPTE_LOCK_BIT 3
+#else
+#define HPTE_LOCK_BIT (63-3)
+#endif
 
 DEFINE_RAW_SPINLOCK(native_tlbie_lock);
 
@@ -172,7 +176,7 @@ static inline void tlbie(unsigned long vpn, int psize, int 
apsize,
 
 static inline void native_lock_hpte(struct hash_pte *hptep)
 {
-   unsigned long *word = hptep-v;
+   unsigned long *word = (unsigned long *)hptep-v;
 
while (1) {
if (!test_and_set_bit_lock(HPTE_LOCK_BIT, word))
@@ -184,7 +188,7 @@ static inline void native_lock_hpte(struct hash_pte *hptep)
 
 static inline void native_unlock_hpte(struct hash_pte *hptep)
 {
-   unsigned long *word = hptep-v;
+   unsigned long *word = (unsigned long *)hptep-v;
 
clear_bit_unlock(HPTE_LOCK_BIT, word);
 }
@@ -204,10 +208,10 @@ static long native_hpte_insert(unsigned long hpte_group, 
unsigned long vpn,
}
 
for (i = 0; i  HPTES_PER_GROUP; i++) {
-   if (! (hptep-v  HPTE_V_VALID)) {
+   if (! (be64_to_cpu(hptep-v)  HPTE_V_VALID)) {
/* retry with lock held */
native_lock_hpte(hptep);
-   if (! (hptep-v  HPTE_V_VALID))
+   if (! (be64_to_cpu(hptep-v)  HPTE_V_VALID))
break;
native_unlock_hpte(hptep);
}
@@ -226,14 +230,14 @@ static long native_hpte_insert(unsigned long hpte_group, 
unsigned long vpn,
i, hpte_v, hpte_r);
}
 
-   hptep-r = hpte_r;
+   hptep-r = cpu_to_be64(hpte_r);
/* Guarantee the second dword is visible before the valid bit */
eieio();
/*
 * Now set the first dword including the valid bit
 * NOTE: this also unlocks the hpte
 */
-   hptep-v = hpte_v;
+   hptep-v = cpu_to_be64(hpte_v);
 
__asm__ __volatile__ (ptesync : : : memory);
 
@@ -254,12 +258,12 @@ static long native_hpte_remove(unsigned long hpte_group)
 
for (i = 0; i  HPTES_PER_GROUP; i++) {
hptep = htab_address + hpte_group + slot_offset;
-   hpte_v = hptep-v;
+   hpte_v = be64_to_cpu(hptep-v);
 
if ((hpte_v  HPTE_V_VALID)  !(hpte_v  HPTE_V_BOLTED)) {
/* retry with lock held */
native_lock_hpte(hptep);
-   hpte_v = hptep-v;
+   hpte_v = be64_to_cpu(hptep-v);
if ((hpte_v  HPTE_V_VALID)
 !(hpte_v  HPTE_V_BOLTED))
break;
@@ -294,7 +298,7 @@ static long native_hpte_updatepp(unsigned long slot, 
unsigned long newpp,
 
native_lock_hpte(hptep);
 
-   hpte_v = hptep-v;
+   hpte_v = be64_to_cpu(hptep-v);
/*
 * We need to invalidate the TLB always because hpte_remove doesn't do
 * a tlb invalidate. If a hash bucket gets full, we evict a more/less
@@ -308,8 +312,8 @@ static long native_hpte_updatepp(unsigned long slot, 
unsigned long newpp,
} else {
DBG_LOW( - hit\n);
/* Update the HPTE */
-   hptep-r = (hptep-r  ~(HPTE_R_PP | HPTE_R_N)) |
-   (newpp  (HPTE_R_PP | HPTE_R_N | HPTE_R_C));
+   hptep-r = cpu_to_be64((be64_to_cpu(hptep-r)  ~(HPTE_R_PP | 
HPTE_R_N)) |
+   (newpp  (HPTE_R_PP | HPTE_R_N | HPTE_R_C)));
}
native_unlock_hpte(hptep);
 
@@ -334,7 +338,7 @@ static long native_hpte_find(unsigned long vpn, int psize, 
int ssize)
slot = (hash  htab_hash_mask) * HPTES_PER_GROUP;
for (i = 0; i  HPTES_PER_GROUP; i++) {
hptep = htab_address + slot;
-   hpte_v = hptep-v;
+   hpte_v = be64_to_cpu(hptep-v);
 
if (HPTE_V_COMPARE(hpte_v, want_v)  (hpte_v  HPTE_V_VALID))
/* HPTE matches */
@@ -369,8 +373,9 @@ static void native_hpte_updateboltedpp(unsigned long 

[PATCH 39/63] powerpc: Little endian builds double word swap VSX state during context save/restore

2013-08-06 Thread Anton Blanchard
The elements within VSX loads and stores are big endian ordered
regardless of endianness. Our VSX context save/restore code uses
lxvd2x and stxvd2x which is a 2x doubleword operation. This means
the two doublewords will be swapped and we have to perform another
swap to undo it.

We need to do this on save and restore.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/include/asm/ppc-opcode.h |  3 +++
 arch/powerpc/include/asm/ppc_asm.h| 21 +
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/include/asm/ppc-opcode.h 
b/arch/powerpc/include/asm/ppc-opcode.h
index eccfc16..247fa1d 100644
--- a/arch/powerpc/include/asm/ppc-opcode.h
+++ b/arch/powerpc/include/asm/ppc-opcode.h
@@ -134,6 +134,7 @@
 #define PPC_INST_TLBIVAX   0x7c000624
 #define PPC_INST_TLBSRX_DOT0x7c0006a5
 #define PPC_INST_XXLOR 0xf510
+#define PPC_INST_XXSWAPD   0xf250
 #define PPC_INST_XVCPSGNDP 0xf780
 #define PPC_INST_TRECHKPT  0x7c0007dd
 #define PPC_INST_TRECLAIM  0x7c00075d
@@ -297,6 +298,8 @@
   VSX_XX1((s), a, b))
 #define XXLOR(t, a, b) stringify_in_c(.long PPC_INST_XXLOR | \
   VSX_XX3((t), a, b))
+#define XXSWAPD(t, a)  stringify_in_c(.long PPC_INST_XXSWAPD | \
+  VSX_XX3((t), a, a))
 #define XVCPSGNDP(t, a, b) stringify_in_c(.long (PPC_INST_XVCPSGNDP | \
   VSX_XX3((t), (a), (b
 
diff --git a/arch/powerpc/include/asm/ppc_asm.h 
b/arch/powerpc/include/asm/ppc_asm.h
index 4ebb4f8..bc606e4 100644
--- a/arch/powerpc/include/asm/ppc_asm.h
+++ b/arch/powerpc/include/asm/ppc_asm.h
@@ -180,9 +180,20 @@ END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR)
 #define REST_32VRS_TRANSACT(n,b,base)  REST_16VRS_TRANSACT(n,b,base);  \
REST_16VRS_TRANSACT(n+16,b,base)
 
+#ifdef __BIG_ENDIAN__
+#define STXVD2X_ROT(n,b,base)  STXVD2X(n,b,base)
+#define LXVD2X_ROT(n,b,base)   LXVD2X(n,b,base)
+#else
+#define STXVD2X_ROT(n,b,base)  XXSWAPD(n,n);   \
+   STXVD2X(n,b,base);  \
+   XXSWAPD(n,n)
+
+#define LXVD2X_ROT(n,b,base)   LXVD2X(n,b,base);   \
+   XXSWAPD(n,n)
+#endif
 
 #define SAVE_VSR_TRANSACT(n,b,base)li b,THREAD_TRANSACT_VSR0+(16*(n)); \
-   STXVD2X(n,R##base,R##b)
+   STXVD2X_ROT(n,R##base,R##b)
 #define SAVE_2VSRS_TRANSACT(n,b,base)  SAVE_VSR_TRANSACT(n,b,base);\
SAVE_VSR_TRANSACT(n+1,b,base)
 #define SAVE_4VSRS_TRANSACT(n,b,base)  SAVE_2VSRS_TRANSACT(n,b,base);  \
@@ -195,7 +206,7 @@ END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR)
SAVE_16VSRS_TRANSACT(n+16,b,base)
 
 #define REST_VSR_TRANSACT(n,b,base)li b,THREAD_TRANSACT_VSR0+(16*(n)); \
-   LXVD2X(n,R##base,R##b)
+   LXVD2X_ROT(n,R##base,R##b)
 #define REST_2VSRS_TRANSACT(n,b,base)  REST_VSR_TRANSACT(n,b,base);\
REST_VSR_TRANSACT(n+1,b,base)
 #define REST_4VSRS_TRANSACT(n,b,base)  REST_2VSRS_TRANSACT(n,b,base);  \
@@ -208,13 +219,15 @@ END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR)
REST_16VSRS_TRANSACT(n+16,b,base)
 
 /* Save the lower 32 VSRs in the thread VSR region */
-#define SAVE_VSR(n,b,base) li b,THREAD_VSR0+(16*(n));  
STXVD2X(n,R##base,R##b)
+#define SAVE_VSR(n,b,base) li b,THREAD_VSR0+(16*(n)); \
+   STXVD2X_ROT(n,R##base,R##b)
 #define SAVE_2VSRS(n,b,base)   SAVE_VSR(n,b,base); SAVE_VSR(n+1,b,base)
 #define SAVE_4VSRS(n,b,base)   SAVE_2VSRS(n,b,base); SAVE_2VSRS(n+2,b,base)
 #define SAVE_8VSRS(n,b,base)   SAVE_4VSRS(n,b,base); SAVE_4VSRS(n+4,b,base)
 #define SAVE_16VSRS(n,b,base)  SAVE_8VSRS(n,b,base); SAVE_8VSRS(n+8,b,base)
 #define SAVE_32VSRS(n,b,base)  SAVE_16VSRS(n,b,base); SAVE_16VSRS(n+16,b,base)
-#define REST_VSR(n,b,base) li b,THREAD_VSR0+(16*(n)); 
LXVD2X(n,R##base,R##b)
+#define REST_VSR(n,b,base) li b,THREAD_VSR0+(16*(n)); \
+   LXVD2X_ROT(n,R##base,R##b)
 #define REST_2VSRS(n,b,base)   REST_VSR(n,b,base); REST_VSR(n+1,b,base)
 #define REST_4VSRS(n,b,base)   REST_2VSRS(n,b,base); REST_2VSRS(n+2,b,base)
 #define REST_8VSRS(n,b,base)   REST_4VSRS(n,b,base); REST_4VSRS(n+4,b,base)
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 40/63] powerpc: Support endian agnostic MMIO

2013-08-06 Thread Anton Blanchard
From: Ian Munsie imun...@au1.ibm.com

This patch maps the MMIO functions for 32bit PowerPC to their
appropriate instructions depending on CPU endianness.

The macros used to create the corresponding inline functions are also
renamed by this patch. Previously they had BE or LE in their names which
was misleading - they had nothing to do with endianness, but actually
created different instruction forms so their new names reflect the
instruction form they are creating (D-Form and X-Form).

Little endian 64bit PowerPC is not supported, so the lack of mappings
(and corresponding breakage) for that case is intentional to bring the
attention of anyone doing a 64bit little endian port. 64bit big endian
is unaffected.

[ Added 64 bit versions - Anton ]

Signed-off-by: Ian Munsie imun...@au1.ibm.com
Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/include/asm/io.h | 67 +++
 1 file changed, 49 insertions(+), 18 deletions(-)

diff --git a/arch/powerpc/include/asm/io.h b/arch/powerpc/include/asm/io.h
index dd15e5e..3aca565 100644
--- a/arch/powerpc/include/asm/io.h
+++ b/arch/powerpc/include/asm/io.h
@@ -103,7 +103,7 @@ extern resource_size_t isa_mem_base;
 
 /* gcc 4.0 and older doesn't have 'Z' constraint */
 #if __GNUC__  4 || (__GNUC__ == 4  __GNUC_MINOR__ == 0)
-#define DEF_MMIO_IN_LE(name, size, insn)   \
+#define DEF_MMIO_IN_X(name, size, insn)\
 static inline u##size name(const volatile u##size __iomem *addr)   \
 {  \
u##size ret;\
@@ -112,7 +112,7 @@ static inline u##size name(const volatile u##size __iomem 
*addr)\
return ret; \
 }
 
-#define DEF_MMIO_OUT_LE(name, size, insn)  \
+#define DEF_MMIO_OUT_X(name, size, insn)   \
 static inline void name(volatile u##size __iomem *addr, u##size val)   \
 {  \
__asm__ __volatile__(sync;#insn %1,0,%2 \
@@ -120,7 +120,7 @@ static inline void name(volatile u##size __iomem *addr, 
u##size val)\
IO_SET_SYNC_FLAG(); \
 }
 #else /* newer gcc */
-#define DEF_MMIO_IN_LE(name, size, insn)   \
+#define DEF_MMIO_IN_X(name, size, insn)\
 static inline u##size name(const volatile u##size __iomem *addr)   \
 {  \
u##size ret;\
@@ -129,7 +129,7 @@ static inline u##size name(const volatile u##size __iomem 
*addr)\
return ret; \
 }
 
-#define DEF_MMIO_OUT_LE(name, size, insn)  \
+#define DEF_MMIO_OUT_X(name, size, insn)   \
 static inline void name(volatile u##size __iomem *addr, u##size val)   \
 {  \
__asm__ __volatile__(sync;#insn %1,%y0  \
@@ -138,7 +138,7 @@ static inline void name(volatile u##size __iomem *addr, 
u##size val)\
 }
 #endif
 
-#define DEF_MMIO_IN_BE(name, size, insn)   \
+#define DEF_MMIO_IN_D(name, size, insn)\
 static inline u##size name(const volatile u##size __iomem *addr)   \
 {  \
u##size ret;\
@@ -147,7 +147,7 @@ static inline u##size name(const volatile u##size __iomem 
*addr)\
return ret; \
 }
 
-#define DEF_MMIO_OUT_BE(name, size, insn)  \
+#define DEF_MMIO_OUT_D(name, size, insn)   \
 static inline void name(volatile u##size __iomem *addr, u##size val)   \
 {  \
__asm__ __volatile__(sync;#insn%U0%X0 %1,%0 \
@@ -155,22 +155,37 @@ static inline void name(volatile u##size __iomem *addr, 
u##size val)  \
IO_SET_SYNC_FLAG(); \
 }
 
+DEF_MMIO_IN_D(in_8, 8, lbz);
+DEF_MMIO_OUT_D(out_8,   8, stb);
 
-DEF_MMIO_IN_BE(in_8, 8, lbz);
-DEF_MMIO_IN_BE(in_be16, 16, lhz);
-DEF_MMIO_IN_BE(in_be32, 32, lwz);
-DEF_MMIO_IN_LE(in_le16, 16, lhbrx);
-DEF_MMIO_IN_LE(in_le32, 32, lwbrx);
+#ifdef __BIG_ENDIAN__
+DEF_MMIO_IN_D(in_be16, 16, lhz);
+DEF_MMIO_IN_D(in_be32, 32, lwz);
+DEF_MMIO_IN_X(in_le16, 16, lhbrx);
+DEF_MMIO_IN_X(in_le32, 32, lwbrx);
 
-DEF_MMIO_OUT_BE(out_8, 8, stb);

[PATCH 28/63] powerpc: Add endian annotations to lppaca, slb_shadow and dtl_entry

2013-08-06 Thread Anton Blanchard
Add endian annotation to various hypervisor structures which
are defined as big endian.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/include/asm/lppaca.h | 50 +++
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/arch/powerpc/include/asm/lppaca.h 
b/arch/powerpc/include/asm/lppaca.h
index bc8def0..4470d1e 100644
--- a/arch/powerpc/include/asm/lppaca.h
+++ b/arch/powerpc/include/asm/lppaca.h
@@ -48,13 +48,13 @@
 struct lppaca {
/* cacheline 1 contains read-only data */
 
-   u32 desc;   /* Eye catcher 0xD397D781 */
-   u16 size;   /* Size of this struct */
+   __be32  desc;   /* Eye catcher 0xD397D781 */
+   __be16  size;   /* Size of this struct */
u8  reserved1[3];
u8  __old_status;   /* Old status, including shared proc */
u8  reserved3[14];
-   volatile u32 dyn_hw_node_id;/* Dynamic hardware node id */
-   volatile u32 dyn_hw_proc_id;/* Dynamic hardware proc id */
+   volatile __be32 dyn_hw_node_id; /* Dynamic hardware node id */
+   volatile __be32 dyn_hw_proc_id; /* Dynamic hardware proc id */
u8  reserved4[56];
volatile u8 vphn_assoc_counts[8]; /* Virtual processor home node */
  /* associativity change counters */
@@ -71,9 +71,9 @@ struct lppaca {
u8  fpregs_in_use;
u8  pmcregs_in_use;
u8  reserved8[28];
-   u64 wait_state_cycles;  /* Wait cycles for this proc */
+   __be64  wait_state_cycles;  /* Wait cycles for this proc */
u8  reserved9[28];
-   u16 slb_count;  /* # of SLBs to maintain */
+   __be16  slb_count;  /* # of SLBs to maintain */
u8  idle;   /* Indicate OS is idle */
u8  vmxregs_in_use;
 
@@ -87,17 +87,17 @@ struct lppaca {
 * NOTE: This value will ALWAYS be zero for dedicated processors and
 * will NEVER be zero for shared processors (ie, initialized to a 1).
 */
-   volatile u32 yield_count;
-   volatile u32 dispersion_count;  /* dispatch changed physical cpu */
-   volatile u64 cmo_faults;/* CMO page fault count */
-   volatile u64 cmo_fault_time;/* CMO page fault time */
+   volatile __be32 yield_count;
+   volatile __be32 dispersion_count; /* dispatch changed physical cpu */
+   volatile __be64 cmo_faults; /* CMO page fault count */
+   volatile __be64 cmo_fault_time; /* CMO page fault time */
u8  reserved10[104];
 
/* cacheline 4-5 */
 
-   u32 page_ins;   /* CMO Hint - # page ins by OS */
+   __be32  page_ins;   /* CMO Hint - # page ins by OS */
u8  reserved11[148];
-   volatile u64 dtl_idx;   /* Dispatch Trace Log head index */
+   volatile __be64 dtl_idx;/* Dispatch Trace Log head 
index */
u8  reserved12[96];
 } __attribute__((__aligned__(0x400)));
 
@@ -123,12 +123,12 @@ static inline bool lppaca_shared_proc(struct lppaca *l)
  * ESID is stored in the lower 64bits, then the VSID.
  */
 struct slb_shadow {
-   u32 persistent; /* Number of persistent SLBs */
-   u32 buffer_length;  /* Total shadow buffer length */
-   u64 reserved;
+   __be32  persistent; /* Number of persistent SLBs */
+   __be32  buffer_length;  /* Total shadow buffer length */
+   __be64  reserved;
struct  {
-   u64 esid;
-   u64 vsid;
+   __be64 esid;
+   __be64  vsid;
} save_area[SLB_NUM_BOLTED];
 } cacheline_aligned;
 
@@ -140,14 +140,14 @@ extern struct slb_shadow slb_shadow[];
 struct dtl_entry {
u8  dispatch_reason;
u8  preempt_reason;
-   u16 processor_id;
-   u32 enqueue_to_dispatch_time;
-   u32 ready_to_enqueue_time;
-   u32 waiting_to_ready_time;
-   u64 timebase;
-   u64 fault_addr;
-   u64 srr0;
-   u64 srr1;
+   __be16  processor_id;
+   __be32  enqueue_to_dispatch_time;
+   __be32  ready_to_enqueue_time;
+   __be32  waiting_to_ready_time;
+   __be64  timebase;
+   __be64  fault_addr;
+   __be64  srr0;
+   __be64  srr1;
 };
 
 #define DISPATCH_LOG_BYTES 4096/* bytes per cpu */
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 41/63] powerpc: Add little endian support for word-at-a-time functions

2013-08-06 Thread Anton Blanchard
The powerpc word-at-a-time functions are big endian specific.
Bring in the x86 version in order to support little endian builds.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/include/asm/word-at-a-time.h | 71 +++
 1 file changed, 71 insertions(+)

diff --git a/arch/powerpc/include/asm/word-at-a-time.h 
b/arch/powerpc/include/asm/word-at-a-time.h
index d0b6d4a..213a5f2 100644
--- a/arch/powerpc/include/asm/word-at-a-time.h
+++ b/arch/powerpc/include/asm/word-at-a-time.h
@@ -8,6 +8,8 @@
 #include linux/kernel.h
 #include asm/asm-compat.h
 
+#ifdef __BIG_ENDIAN__
+
 struct word_at_a_time {
const unsigned long high_bits, low_bits;
 };
@@ -38,4 +40,73 @@ static inline bool has_zero(unsigned long val, unsigned long 
*data, const struct
return (val + c-high_bits)  ~rhs;
 }
 
+#else
+
+/*
+ * This is largely generic for little-endian machines, but the
+ * optimal byte mask counting is probably going to be something
+ * that is architecture-specific. If you have a reliably fast
+ * bit count instruction, that might be better than the multiply
+ * and shift, for example.
+ */
+struct word_at_a_time {
+   const unsigned long one_bits, high_bits;
+};
+
+#define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
+
+#ifdef CONFIG_64BIT
+
+/*
+ * Jan Achrenius on G+: microoptimized version of
+ * the simpler (mask  ONEBYTES) * ONEBYTES  56
+ * that works for the bytemasks without having to
+ * mask them first.
+ */
+static inline long count_masked_bytes(unsigned long mask)
+{
+   return mask*0x0001020304050608ul  56;
+}
+
+#else  /* 32-bit case */
+
+/* Carl Chatfield / Jan Achrenius G+ version for 32-bit */
+static inline long count_masked_bytes(long mask)
+{
+   /* (00 ff 00 ff) - ( 1 1 2 3 ) */
+   long a = (0x0ff0001+mask)  23;
+   /* Fix the 1 for 00 case */
+   return a  mask;
+}
+
+#endif
+
+/* Return nonzero if it has a zero */
+static inline unsigned long has_zero(unsigned long a, unsigned long *bits, 
const struct word_at_a_time *c)
+{
+   unsigned long mask = ((a - c-one_bits)  ~a)  c-high_bits;
+   *bits = mask;
+   return mask;
+}
+
+static inline unsigned long prep_zero_mask(unsigned long a, unsigned long 
bits, const struct word_at_a_time *c)
+{
+   return bits;
+}
+
+static inline unsigned long create_zero_mask(unsigned long bits)
+{
+   bits = (bits - 1)  ~bits;
+   return bits  7;
+}
+
+/* The mask we created is directly usable as a bytemask */
+#define zero_bytemask(mask) (mask)
+
+static inline unsigned long find_zero(unsigned long mask)
+{
+   return count_masked_bytes(mask);
+}
+#endif
+
 #endif /* _ASM_WORD_AT_A_TIME_H */
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 42/63] powerpc: Set MSR_LE bit on little endian builds

2013-08-06 Thread Anton Blanchard
We need to set MSR_LE in kernel and userspace for little endian builds

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/include/asm/reg.h | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
index a312e0c..4e57083 100644
--- a/arch/powerpc/include/asm/reg.h
+++ b/arch/powerpc/include/asm/reg.h
@@ -115,7 +115,12 @@
 #define MSR_64BIT  MSR_SF
 
 /* Server variant */
-#define MSR_   (MSR_ME | MSR_RI | MSR_IR | MSR_DR | MSR_ISF |MSR_HV)
+#define __MSR  (MSR_ME | MSR_RI | MSR_IR | MSR_DR | MSR_ISF |MSR_HV)
+#ifdef __BIG_ENDIAN__
+#define MSR_   __MSR
+#else
+#define MSR_   (__MSR | MSR_LE)
+#endif
 #define MSR_KERNEL (MSR_ | MSR_64BIT)
 #define MSR_USER32 (MSR_ | MSR_PR | MSR_EE)
 #define MSR_USER64 (MSR_USER32 | MSR_64BIT)
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 43/63] powerpc: Reset MSR_LE on signal entry

2013-08-06 Thread Anton Blanchard
We always take signals in big endian which is wrong. Signals
should be taken in native endian.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/kernel/signal_32.c | 3 ++-
 arch/powerpc/kernel/signal_64.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
index 0f83122..3b9a673 100644
--- a/arch/powerpc/kernel/signal_32.c
+++ b/arch/powerpc/kernel/signal_32.c
@@ -1036,8 +1036,9 @@ int handle_rt_signal32(unsigned long sig, struct 
k_sigaction *ka,
regs-gpr[5] = (unsigned long) rt_sf-uc;
regs-gpr[6] = (unsigned long) rt_sf;
regs-nip = (unsigned long) ka-sa.sa_handler;
-   /* enter the signal handler in big-endian mode */
+   /* enter the signal handler in native-endian mode */
regs-msr = ~MSR_LE;
+   regs-msr |= (MSR_KERNEL  MSR_LE);
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
/* Remove TM bits from thread's MSR.  The MSR in the sigcontext
 * just indicates to userland that we were doing a transaction, but we
diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
index cbd2692..f7e61e0 100644
--- a/arch/powerpc/kernel/signal_64.c
+++ b/arch/powerpc/kernel/signal_64.c
@@ -767,8 +767,9 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, 
siginfo_t *info,
 
/* Set up regs so we return to the signal handler. */
err |= get_user(regs-nip, funct_desc_ptr-entry);
-   /* enter the signal handler in big-endian mode */
+   /* enter the signal handler in native-endian mode */
regs-msr = ~MSR_LE;
+   regs-msr |= (MSR_KERNEL  MSR_LE);
regs-gpr[1] = newsp;
err |= get_user(regs-gpr[2], funct_desc_ptr-toc);
regs-gpr[3] = signr;
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 44/63] powerpc: Include the appropriate endianness header

2013-08-06 Thread Anton Blanchard
From: Ian Munsie imun...@au1.ibm.com

This patch will have powerpc include the appropriate generic endianness
header depending on what the compiler reports.

Signed-off-by: Ian Munsie imun...@au1.ibm.com
Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/include/uapi/asm/byteorder.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/powerpc/include/uapi/asm/byteorder.h 
b/arch/powerpc/include/uapi/asm/byteorder.h
index aa6cc4f..ca931d0 100644
--- a/arch/powerpc/include/uapi/asm/byteorder.h
+++ b/arch/powerpc/include/uapi/asm/byteorder.h
@@ -7,6 +7,10 @@
  * as published by the Free Software Foundation; either version
  * 2 of the License, or (at your option) any later version.
  */
+#ifdef __LITTLE_ENDIAN__
+#include linux/byteorder/little_endian.h
+#else
 #include linux/byteorder/big_endian.h
+#endif
 
 #endif /* _ASM_POWERPC_BYTEORDER_H */
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 45/63] powerpc: endian safe trampoline

2013-08-06 Thread Anton Blanchard
From: Benjamin Herrenschmidt b...@kernel.crashing.org

Create a trampoline that works in either endian and flips to
the expected endian. Use it for primary and secondary thread
entry as well as RTAS and OF call return.

Signed-off-by: Benjamin Herrenschmidt b...@kernel.crashing.org
Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/include/asm/ppc_asm.h | 31 ++-
 arch/powerpc/kernel/entry_64.S | 36 
 arch/powerpc/kernel/head_64.S  |  2 ++
 3 files changed, 52 insertions(+), 17 deletions(-)

diff --git a/arch/powerpc/include/asm/ppc_asm.h 
b/arch/powerpc/include/asm/ppc_asm.h
index bc606e4..f9d8418 100644
--- a/arch/powerpc/include/asm/ppc_asm.h
+++ b/arch/powerpc/include/asm/ppc_asm.h
@@ -845,6 +845,35 @@ END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,946)
 #define N_SLINE68
 #define N_SO   100
 
-#endif /*  __ASSEMBLY__ */
+/*
+ * Create an endian fixup trampoline
+ *
+ * This starts with a tdi 0,0,0x48 instruction which is
+ * essentially a trap never, and thus akin to a nop.
+ *
+ * The opcode for this instruction read with the wrong endian
+ * however results in a b . + 8
+ *
+ * So essentially we use that trick to execute the following
+ * trampoline in reverse endian if we are running with the
+ * MSR_LE bit set the wrong way for whatever endianness the
+ * kernel is built for.
+ */
 
+#ifdef CONFIG_PPC_BOOK3E
+#define FIXUP_ENDIAN
+#else
+#define FIXUP_ENDIAN  \
+   tdi   0,0,0x48;   /* Reverse endian of b . + 8  */ \
+   b $+36;   /* Skip trampoline if endian is good  */ \
+   .long 0x05009f42; /* bcl 20,31,$+4  */ \
+   .long 0xa602487d; /* mflr r10   */ \
+   .long 0x1c004a39; /* addi r10,r10,28*/ \
+   .long 0xa600607d; /* mfmsr r11  */ \
+   .long 0x01006b69; /* xori r11,r11,1 */ \
+   .long 0xa6035a7d; /* mtsrr0 r10 */ \
+   .long 0xa6037b7d; /* mtsrr1 r11 */ \
+   .long 0x244c  /* rfid   */
+#endif /* !CONFIG_PPC_BOOK3E */
+#endif /*  __ASSEMBLY__ */
 #endif /* _ASM_POWERPC_PPC_ASM_H */
diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
index 209e8ce..5694e1f 100644
--- a/arch/powerpc/kernel/entry_64.S
+++ b/arch/powerpc/kernel/entry_64.S
@@ -1020,7 +1020,7 @@ _GLOBAL(enter_rtas)

 li  r9,1
 rldicr  r9,r9,MSR_SF_LG,(63-MSR_SF_LG)
-   ori r9,r9,MSR_IR|MSR_DR|MSR_FE0|MSR_FE1|MSR_FP|MSR_RI
+   ori r9,r9,MSR_IR|MSR_DR|MSR_FE0|MSR_FE1|MSR_FP|MSR_RI|MSR_LE
andcr6,r0,r9
sync/* disable interrupts so SRR0/1 */
mtmsrd  r0  /* don't get trashed */
@@ -1035,6 +1035,8 @@ _GLOBAL(enter_rtas)
b   .   /* prevent speculative execution */
 
 _STATIC(rtas_return_loc)
+   FIXUP_ENDIAN
+
/* relocation is off at this point */
GET_PACA(r4)
clrldi  r4,r4,2 /* convert to realmode address */
@@ -1106,28 +1108,30 @@ _GLOBAL(enter_prom)
std r10,_CCR(r1)
std r11,_MSR(r1)
 
-   /* Get the PROM entrypoint */
-   mtlrr4
+   /* Put PROM address in SRR0 */
+   mtsrr0  r4
+
+   /* Setup our trampoline return addr in LR */
+   bcl 20,31,$+4
+0: mflrr4
+   addir4,r4,(1f - 0b)
+   mtlrr4
 
-   /* Switch MSR to 32 bits mode
+   /* Prepare a 32-bit mode big endian MSR
 */
 #ifdef CONFIG_PPC_BOOK3E
rlwinm  r11,r11,0,1,31
-   mtmsr   r11
+   mtsrr1  r11
+   rfi
 #else /* CONFIG_PPC_BOOK3E */
-mfmsr   r11
-li  r12,1
-rldicr  r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
-andcr11,r11,r12
-li  r12,1
-rldicr  r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
-andcr11,r11,r12
-mtmsrd  r11
+   LOAD_REG_IMMEDIATE(r12, MSR_SF | MSR_ISF | MSR_LE)
+   andcr11,r11,r12
+   mtsrr1  r11
+   rfid
 #endif /* CONFIG_PPC_BOOK3E */
-isync
 
-   /* Enter PROM here... */
-   blrl
+1: /* Return from OF */
+   FIXUP_ENDIAN
 
/* Just make sure that r1 top 32 bits didn't get
 * corrupt by OF
diff --git a/arch/powerpc/kernel/head_64.S b/arch/powerpc/kernel/head_64.S
index 3d11d80..065d10f 100644
--- a/arch/powerpc/kernel/head_64.S
+++ b/arch/powerpc/kernel/head_64.S
@@ -68,6 +68,7 @@ _stext:
 _GLOBAL(__start)
/* NOP this out unconditionally */
 BEGIN_FTR_SECTION
+   FIXUP_ENDIAN
b   .__start_initialization_multiplatform
 END_FTR_SECTION(0, 1)
 
@@ -115,6 +116,7 @@ __run_at_load:
  */
.globl  __secondary_hold
 __secondary_hold:
+   FIXUP_ENDIAN
 #ifndef CONFIG_PPC_BOOK3E
mfmsr   r24
ori 

[PATCH 46/63] powerpc: Add endian safe trampoline to pseries secondary thread entry

2013-08-06 Thread Anton Blanchard
We might need to flip endian when starting secondary threads via
RTAS.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/kernel/head_64.S | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/kernel/head_64.S b/arch/powerpc/kernel/head_64.S
index 065d10f..2ae41ab 100644
--- a/arch/powerpc/kernel/head_64.S
+++ b/arch/powerpc/kernel/head_64.S
@@ -207,6 +207,7 @@ _GLOBAL(generic_secondary_thread_init)
  * as SCOM before entry).
  */
 _GLOBAL(generic_secondary_smp_init)
+   FIXUP_ENDIAN
mr  r24,r3
mr  r25,r4
 
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 47/63] pseries: Add H_SET_MODE to change exception endianness

2013-08-06 Thread Anton Blanchard
On little endian builds call H_SET_MODE so exceptions have the
correct endianness. We need a better hook to handle flipping back
into big endian mode on a kexec, but insert it into the mmu
teardown callback for now.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/include/asm/hvcall.h   |  2 ++
 arch/powerpc/platforms/pseries/lpar.c   | 17 ++
 arch/powerpc/platforms/pseries/plpar_wrappers.h | 26 +++
 arch/powerpc/platforms/pseries/setup.c  | 42 +
 4 files changed, 87 insertions(+)

diff --git a/arch/powerpc/include/asm/hvcall.h 
b/arch/powerpc/include/asm/hvcall.h
index 0c7f2bf..d8b600b 100644
--- a/arch/powerpc/include/asm/hvcall.h
+++ b/arch/powerpc/include/asm/hvcall.h
@@ -403,6 +403,8 @@ static inline unsigned long cmo_get_page_size(void)
 extern long pSeries_enable_reloc_on_exc(void);
 extern long pSeries_disable_reloc_on_exc(void);
 
+extern long pseries_big_endian_exceptions(void);
+
 #else
 
 #define pSeries_enable_reloc_on_exc()  do {} while (0)
diff --git a/arch/powerpc/platforms/pseries/lpar.c 
b/arch/powerpc/platforms/pseries/lpar.c
index 0b7c86e..f28bf35 100644
--- a/arch/powerpc/platforms/pseries/lpar.c
+++ b/arch/powerpc/platforms/pseries/lpar.c
@@ -239,6 +239,23 @@ static void pSeries_lpar_hptab_clear(void)
(ptes[j].pteh), (ptes[j].ptel));
}
}
+
+#ifdef __LITTLE_ENDIAN__
+   /* Reset exceptions to big endian */
+   if (firmware_has_feature(FW_FEATURE_SET_MODE)) {
+   long rc;
+
+   rc = pseries_big_endian_exceptions();
+   /*
+* At this point it is unlikely panic() will get anything
+* out to the user, but at least this will stop us from
+* continuing on further and creating an even more
+* difficult to debug situation.
+*/
+   if (rc)
+   panic(Could not enable big endian exceptions);
+   }
+#endif
 }
 
 /*
diff --git a/arch/powerpc/platforms/pseries/plpar_wrappers.h 
b/arch/powerpc/platforms/pseries/plpar_wrappers.h
index 417d0bf..6c1c218 100644
--- a/arch/powerpc/platforms/pseries/plpar_wrappers.h
+++ b/arch/powerpc/platforms/pseries/plpar_wrappers.h
@@ -287,6 +287,32 @@ static inline long disable_reloc_on_exceptions(void) {
return plpar_set_mode(0, 3, 0, 0);
 }
 
+/*
+ * Take exceptions in big endian mode on this partition
+ *
+ * Note: this call has a partition wide scope and can take a while to complete.
+ * If it returns H_LONG_BUSY_* it should be retried periodically until it
+ * returns H_SUCCESS.
+ */
+static inline long enable_big_endian_exceptions(void)
+{
+   /* mflags = 0: big endian exceptions */
+   return plpar_set_mode(0, 4, 0, 0);
+}
+
+/*
+ * Take exceptions in little endian mode on this partition
+ *
+ * Note: this call has a partition wide scope and can take a while to complete.
+ * If it returns H_LONG_BUSY_* it should be retried periodically until it
+ * returns H_SUCCESS.
+ */
+static inline long enable_little_endian_exceptions(void)
+{
+   /* mflags = 1: little endian exceptions */
+   return plpar_set_mode(1, 4, 0, 0);
+}
+
 static inline long plapr_set_ciabr(unsigned long ciabr)
 {
return plpar_set_mode(0, 1, ciabr, 0);
diff --git a/arch/powerpc/platforms/pseries/setup.c 
b/arch/powerpc/platforms/pseries/setup.c
index 33d6196..51c195d 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -430,6 +430,32 @@ static void pSeries_machine_kexec(struct kimage *image)
 }
 #endif
 
+#ifdef __LITTLE_ENDIAN__
+long pseries_big_endian_exceptions(void)
+{
+   long rc;
+
+   while (1) {
+   rc = enable_big_endian_exceptions();
+   if (!H_IS_LONG_BUSY(rc))
+   return rc;
+   mdelay(get_longbusy_msecs(rc));
+   }
+}
+
+static long pseries_little_endian_exceptions(void)
+{
+   long rc;
+
+   while (1) {
+   rc = enable_little_endian_exceptions();
+   if (!H_IS_LONG_BUSY(rc))
+   return rc;
+   mdelay(get_longbusy_msecs(rc));
+   }
+}
+#endif
+
 static void __init pSeries_setup_arch(void)
 {
panic_timeout = 10;
@@ -687,6 +713,22 @@ static int __init pSeries_probe(void)
/* Now try to figure out if we are running on LPAR */
of_scan_flat_dt(pseries_probe_fw_features, NULL);
 
+#ifdef __LITTLE_ENDIAN__
+   if (firmware_has_feature(FW_FEATURE_SET_MODE)) {
+   long rc;
+   /*
+* Tell the hypervisor that we want our exceptions to
+* be taken in little endian mode. If this fails we don't
+* want to use BUG() because it will trigger an exception.
+*/
+   rc = pseries_little_endian_exceptions();
+   if (rc) {
+   

[PATCH 48/63] powerpc/kvm/book3s_hv: Add little endian guest support

2013-08-06 Thread Anton Blanchard
Add support for the H_SET_MODE hcall so we can select the
endianness of our exceptions.

We create a guest MSR from scratch when delivering exceptions in
a few places and instead of extracting the LPCR[ILE] and inserting
it into MSR_LE each time simply create a new variable intr_msr which
contains the entire MSR to use.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/include/asm/kvm_host.h |  1 +
 arch/powerpc/kernel/asm-offsets.c   |  1 +
 arch/powerpc/kvm/book3s_64_mmu_hv.c |  2 +-
 arch/powerpc/kvm/book3s_hv.c| 44 +
 arch/powerpc/kvm/book3s_hv_rmhandlers.S | 15 ---
 5 files changed, 52 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index af326cd..88f0c8e 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -609,6 +609,7 @@ struct kvm_vcpu_arch {
spinlock_t tbacct_lock;
u64 busy_stolen;
u64 busy_preempt;
+   unsigned long intr_msr;
 #endif
 };
 
diff --git a/arch/powerpc/kernel/asm-offsets.c 
b/arch/powerpc/kernel/asm-offsets.c
index c7e8afc..0f93cb0 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -486,6 +486,7 @@ int main(void)
DEFINE(VCPU_DAR, offsetof(struct kvm_vcpu, arch.shregs.dar));
DEFINE(VCPU_VPA, offsetof(struct kvm_vcpu, arch.vpa.pinned_addr));
DEFINE(VCPU_VPA_DIRTY, offsetof(struct kvm_vcpu, arch.vpa.dirty));
+   DEFINE(VCPU_INTR_MSR, offsetof(struct kvm_vcpu, arch.intr_msr));
 #endif
 #ifdef CONFIG_PPC_BOOK3S
DEFINE(VCPU_VCPUID, offsetof(struct kvm_vcpu, vcpu_id));
diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c 
b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index 710d313..fae9751 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -266,7 +266,7 @@ void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu)
 
 static void kvmppc_mmu_book3s_64_hv_reset_msr(struct kvm_vcpu *vcpu)
 {
-   kvmppc_set_msr(vcpu, MSR_SF | MSR_ME);
+   kvmppc_set_msr(vcpu, vcpu-arch.intr_msr);
 }
 
 /*
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index cf39bf4..d4f087b 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -503,6 +503,43 @@ static void kvmppc_create_dtl_entry(struct kvm_vcpu *vcpu,
vcpu-arch.dtl.dirty = true;
 }
 
+static int kvmppc_h_set_mode(struct kvm_vcpu *vcpu, unsigned long mflags,
+unsigned long resource, unsigned long value1,
+unsigned long value2)
+{
+   struct kvm *kvm = vcpu-kvm;
+   struct kvm_vcpu *v;
+   int n;
+
+   if (resource == 4) {
+   if (value1)
+   return H_P3;
+   if (value2)
+   return H_P4;
+
+   switch (mflags) {
+   case 0:
+   kvm-arch.lpcr = ~LPCR_ILE;
+   kvm_for_each_vcpu(n, v, kvm)
+   v-arch.intr_msr = ~MSR_LE;
+   kick_all_cpus_sync();
+   return H_SUCCESS;
+
+   case 1:
+   kvm-arch.lpcr |= LPCR_ILE;
+   kvm_for_each_vcpu(n, v, kvm)
+   v-arch.intr_msr |= MSR_LE;
+   kick_all_cpus_sync();
+   return H_SUCCESS;
+
+   default:
+   return H_UNSUPPORTED_FLAG_START;
+   }
+   }
+
+   return H_P2;
+}
+
 int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)
 {
unsigned long req = kvmppc_get_gpr(vcpu, 3);
@@ -557,6 +594,12 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)
 
/* Send the error out to userspace via KVM_RUN */
return rc;
+   case H_SET_MODE:
+   ret = kvmppc_h_set_mode(vcpu, kvmppc_get_gpr(vcpu, 4),
+   kvmppc_get_gpr(vcpu, 5),
+   kvmppc_get_gpr(vcpu, 6),
+   kvmppc_get_gpr(vcpu, 7));
+   break;
 
case H_XIRR:
case H_CPPR:
@@ -925,6 +968,7 @@ struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, 
unsigned int id)
spin_lock_init(vcpu-arch.vpa_update_lock);
spin_lock_init(vcpu-arch.tbacct_lock);
vcpu-arch.busy_preempt = TB_NIL;
+   vcpu-arch.intr_msr = MSR_SF | MSR_ME;
 
kvmppc_mmu_book3s_hv_init(vcpu);
 
diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S 
b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index b93e3cd..c48061c 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -521,8 +521,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
 12:mr  r6,r10
mr  r10,r0
mr  r7,r11
-   li  r11,(MSR_ME  1) | 1   /* synthesize MSR_SF | MSR_ME */

[PATCH 49/63] powerpc: Remove open coded byte swap macro in alignment handler

2013-08-06 Thread Anton Blanchard
Use swab64/32/16 instead of open coding it.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/kernel/align.c | 36 
 1 file changed, 12 insertions(+), 24 deletions(-)

diff --git a/arch/powerpc/kernel/align.c b/arch/powerpc/kernel/align.c
index 52e5758..573728b 100644
--- a/arch/powerpc/kernel/align.c
+++ b/arch/powerpc/kernel/align.c
@@ -54,8 +54,6 @@ struct aligninfo {
 /* DSISR bits reported for a DCBZ instruction: */
 #define DCBZ   0x5f/* 8xx/82xx dcbz faults when cache not enabled */
 
-#define SWAP(a, b) (t = (a), (a) = (b), (b) = t)
-
 /*
  * The PowerPC stores certain bits of the instruction that caused the
  * alignment exception in the DSISR register.  This array maps those
@@ -458,7 +456,7 @@ static struct aligninfo spe_aligninfo[32] = {
 static int emulate_spe(struct pt_regs *regs, unsigned int reg,
   unsigned int instr)
 {
-   int t, ret;
+   int ret;
union {
u64 ll;
u32 w[2];
@@ -581,24 +579,18 @@ static int emulate_spe(struct pt_regs *regs, unsigned int 
reg,
if (flags  SW) {
switch (flags  0xf0) {
case E8:
-   SWAP(data.v[0], data.v[7]);
-   SWAP(data.v[1], data.v[6]);
-   SWAP(data.v[2], data.v[5]);
-   SWAP(data.v[3], data.v[4]);
+   data.ll = swab64(data.ll);
break;
case E4:
-
-   SWAP(data.v[0], data.v[3]);
-   SWAP(data.v[1], data.v[2]);
-   SWAP(data.v[4], data.v[7]);
-   SWAP(data.v[5], data.v[6]);
+   data.w[0] = swab32(data.w[0]);
+   data.w[1] = swab32(data.w[1]);
break;
/* Its half word endian */
default:
-   SWAP(data.v[0], data.v[1]);
-   SWAP(data.v[2], data.v[3]);
-   SWAP(data.v[4], data.v[5]);
-   SWAP(data.v[6], data.v[7]);
+   data.h[0] = swab16(data.h[0]);
+   data.h[1] = swab16(data.h[1]);
+   data.h[2] = swab16(data.h[2]);
+   data.h[3] = swab16(data.h[3]);
break;
}
}
@@ -706,7 +698,7 @@ int fix_alignment(struct pt_regs *regs)
unsigned int dsisr;
unsigned char __user *addr;
unsigned long p, swiz;
-   int ret, t;
+   int ret;
union {
u64 ll;
double dd;
@@ -911,17 +903,13 @@ int fix_alignment(struct pt_regs *regs)
if (flags  SW) {
switch (nb) {
case 8:
-   SWAP(data.v[0], data.v[7]);
-   SWAP(data.v[1], data.v[6]);
-   SWAP(data.v[2], data.v[5]);
-   SWAP(data.v[3], data.v[4]);
+   data.ll = swab64(data.ll);
break;
case 4:
-   SWAP(data.v[4], data.v[7]);
-   SWAP(data.v[5], data.v[6]);
+   data.x32.low32 = swab32(data.x32.low32);
break;
case 2:
-   SWAP(data.v[6], data.v[7]);
+   data.x16.low16 = swab16(data.x16.low16);
break;
}
}
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 50/63] powerpc: Remove hard coded FP offsets in alignment handler

2013-08-06 Thread Anton Blanchard
The alignment handler assumes big endian ordering when selecting
the low word of a 64bit floating point value. Use the existing
union which works in both little and big endian.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/kernel/align.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/align.c b/arch/powerpc/kernel/align.c
index 573728b..ceced33 100644
--- a/arch/powerpc/kernel/align.c
+++ b/arch/powerpc/kernel/align.c
@@ -891,7 +891,7 @@ int fix_alignment(struct pt_regs *regs)
 #ifdef CONFIG_PPC_FPU
preempt_disable();
enable_kernel_fp();
-   cvt_df(data.dd, (float *)data.v[4]);
+   cvt_df(data.dd, (float *)data.x32.low32);
preempt_enable();
 #else
return 0;
@@ -931,7 +931,7 @@ int fix_alignment(struct pt_regs *regs)
 #ifdef CONFIG_PPC_FPU
preempt_disable();
enable_kernel_fp();
-   cvt_fd((float *)data.v[4], data.dd);
+   cvt_fd((float *)data.x32.low32, data.dd);
preempt_enable();
 #else
return 0;
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 51/63] powerpc: Alignment handler shouldn't access VSX registers with TS_FPR

2013-08-06 Thread Anton Blanchard
The TS_FPR macro selects the FPR component of a VSX register (the
high doubleword). emulate_vsx is using this macro to get the
address of the associated VSX register. This happens to work on big
endian, but fails on little endian.

Replace it with an explicit array access.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/kernel/align.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/align.c b/arch/powerpc/kernel/align.c
index ceced33..edc179f 100644
--- a/arch/powerpc/kernel/align.c
+++ b/arch/powerpc/kernel/align.c
@@ -646,7 +646,7 @@ static int emulate_vsx(unsigned char __user *addr, unsigned 
int reg,
flush_vsx_to_thread(current);
 
if (reg  32)
-   ptr = (char *) current-thread.TS_FPR(reg);
+   ptr = (char *) current-thread.fpr[reg][0];
else
ptr = (char *) current-thread.vr[reg - 32];
 
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 52/63] powerpc: Add little endian support to alignment handler

2013-08-06 Thread Anton Blanchard
Handle most unaligned load and store faults in little
endian mode. Strings, multiples and VSX are not supported.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/kernel/align.c | 93 ++---
 1 file changed, 63 insertions(+), 30 deletions(-)

diff --git a/arch/powerpc/kernel/align.c b/arch/powerpc/kernel/align.c
index edc179f..0a1a8f2 100644
--- a/arch/powerpc/kernel/align.c
+++ b/arch/powerpc/kernel/align.c
@@ -262,6 +262,7 @@ static int emulate_dcbz(struct pt_regs *regs, unsigned char 
__user *addr)
 
 #define SWIZ_PTR(p)((unsigned char __user *)((p) ^ swiz))
 
+#ifdef __BIG_ENDIAN__
 static int emulate_multiple(struct pt_regs *regs, unsigned char __user *addr,
unsigned int reg, unsigned int nb,
unsigned int flags, unsigned int instr,
@@ -390,6 +391,7 @@ static int emulate_fp_pair(unsigned char __user *addr, 
unsigned int reg,
return -EFAULT;
return 1;   /* exception handled and fixed up */
 }
+#endif
 
 #ifdef CONFIG_SPE
 
@@ -628,7 +630,7 @@ static int emulate_spe(struct pt_regs *regs, unsigned int 
reg,
 }
 #endif /* CONFIG_SPE */
 
-#ifdef CONFIG_VSX
+#if defined(CONFIG_VSX)  defined(__BIG_ENDIAN__)
 /*
  * Emulate VSX instructions...
  */
@@ -698,18 +700,28 @@ int fix_alignment(struct pt_regs *regs)
unsigned int dsisr;
unsigned char __user *addr;
unsigned long p, swiz;
-   int ret;
-   union {
+   int ret, i;
+   union data {
u64 ll;
double dd;
unsigned char v[8];
struct {
+#ifdef __LITTLE_ENDIAN__
+   int  low32;
+   unsigned hi32;
+#else
unsigned hi32;
int  low32;
+#endif
} x32;
struct {
+#ifdef __LITTLE_ENDIAN__
+   short low16;
+   unsigned char hi48[6];
+#else
unsigned char hi48[6];
short low16;
+#endif
} x16;
} data;
 
@@ -768,8 +780,9 @@ int fix_alignment(struct pt_regs *regs)
 
/* Byteswap little endian loads and stores */
swiz = 0;
-   if (regs-msr  MSR_LE) {
+   if ((regs-msr  MSR_LE) != (MSR_KERNEL  MSR_LE)) {
flags ^= SW;
+#ifdef __BIG_ENDIAN__
/*
 * So-called PowerPC little endian mode works by
 * swizzling addresses rather than by actually doing
@@ -782,11 +795,13 @@ int fix_alignment(struct pt_regs *regs)
 */
if (cpu_has_feature(CPU_FTR_PPC_LE))
swiz = 7;
+#endif
}
 
/* DAR has the operand effective address */
addr = (unsigned char __user *)regs-dar;
 
+#ifdef __BIG_ENDIAN__
 #ifdef CONFIG_VSX
if ((instruction  0xfc3e) == 0x7c18) {
unsigned int elsize;
@@ -806,7 +821,7 @@ int fix_alignment(struct pt_regs *regs)
elsize = 8;
 
flags = 0;
-   if (regs-msr  MSR_LE)
+   if ((regs-msr  MSR_LE) != (MSR_KERNEL  MSR_LE))
flags |= SW;
if (instruction  0x100)
flags |= ST;
@@ -821,6 +836,9 @@ int fix_alignment(struct pt_regs *regs)
return emulate_vsx(addr, reg, areg, regs, flags, nb, elsize);
}
 #endif
+#else
+   return -EFAULT;
+#endif
/* A size of 0 indicates an instruction we don't support, with
 * the exception of DCBZ which is handled as a special case here
 */
@@ -835,9 +853,13 @@ int fix_alignment(struct pt_regs *regs)
 * function
 */
if (flags  M) {
+#ifdef __BIG_ENDIAN__
PPC_WARN_ALIGNMENT(multiple, regs);
return emulate_multiple(regs, addr, reg, nb,
flags, instr, swiz);
+#else
+   return -EFAULT;
+#endif
}
 
/* Verify the address of the operand */
@@ -856,8 +878,12 @@ int fix_alignment(struct pt_regs *regs)
 
/* Special case for 16-byte FP loads and stores */
if (nb == 16) {
+#ifdef __BIG_ENDIAN__
PPC_WARN_ALIGNMENT(fp_pair, regs);
return emulate_fp_pair(addr, reg, flags);
+#else
+   return -EFAULT;
+#endif
}
 
PPC_WARN_ALIGNMENT(unaligned, regs);
@@ -866,24 +892,28 @@ int fix_alignment(struct pt_regs *regs)
 * get it from register values
 */
if (!(flags  ST)) {
-   data.ll = 0;
-   ret = 0;
-   p = (unsigned long) addr;
+   unsigned int start = 0;
+
switch (nb) {
-   case 8:
-   ret |= __get_user_inatomic(data.v[0], SWIZ_PTR(p++));
-   ret |= __get_user_inatomic(data.v[1], 

[PATCH 53/63] powerpc: Handle VSX alignment faults in little endian mode

2013-08-06 Thread Anton Blanchard
Things are complicated by the fact that VSX elements are big
endian ordered even in little endian mode. 8 byte loads and
stores also write to the top 8 bytes of the register.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/kernel/align.c | 41 +
 1 file changed, 33 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/kernel/align.c b/arch/powerpc/kernel/align.c
index 0a1a8f2..033d04a 100644
--- a/arch/powerpc/kernel/align.c
+++ b/arch/powerpc/kernel/align.c
@@ -630,7 +630,7 @@ static int emulate_spe(struct pt_regs *regs, unsigned int 
reg,
 }
 #endif /* CONFIG_SPE */
 
-#if defined(CONFIG_VSX)  defined(__BIG_ENDIAN__)
+#ifdef CONFIG_VSX
 /*
  * Emulate VSX instructions...
  */
@@ -654,8 +654,25 @@ static int emulate_vsx(unsigned char __user *addr, 
unsigned int reg,
 
lptr = (unsigned long *) ptr;
 
+#ifdef __LITTLE_ENDIAN__
+   if (flags  SW) {
+   elsize = length;
+   sw = length-1;
+   } else {
+   /*
+* The elements are BE ordered, even in LE mode, so process
+* them in reverse order.
+*/
+   addr += length - elsize;
+
+   /* 8 byte memory accesses go in the top 8 bytes of the VR */
+   if (length == 8)
+   ptr += 8;
+   }
+#else
if (flags  SW)
sw = elsize-1;
+#endif
 
for (j = 0; j  length; j += elsize) {
for (i = 0; i  elsize; ++i) {
@@ -665,19 +682,31 @@ static int emulate_vsx(unsigned char __user *addr, 
unsigned int reg,
ret |= __get_user(ptr[i^sw], addr + i);
}
ptr  += elsize;
+#ifdef __LITTLE_ENDIAN__
+   addr -= elsize;
+#else
addr += elsize;
+#endif
}
 
+#ifdef __BIG_ENDIAN__
+#define VSX_HI 0
+#define VSX_LO 1
+#else
+#define VSX_HI 1
+#define VSX_LO 0
+#endif
+
if (!ret) {
if (flags  U)
regs-gpr[areg] = regs-dar;
 
/* Splat load copies the same data to top and bottom 8 bytes */
if (flags  SPLT)
-   lptr[1] = lptr[0];
-   /* For 8 byte loads, zero the top 8 bytes */
+   lptr[VSX_LO] = lptr[VSX_HI];
+   /* For 8 byte loads, zero the low 8 bytes */
else if (!(flags  ST)  (8 == length))
-   lptr[1] = 0;
+   lptr[VSX_LO] = 0;
} else
return -EFAULT;
 
@@ -801,7 +830,6 @@ int fix_alignment(struct pt_regs *regs)
/* DAR has the operand effective address */
addr = (unsigned char __user *)regs-dar;
 
-#ifdef __BIG_ENDIAN__
 #ifdef CONFIG_VSX
if ((instruction  0xfc3e) == 0x7c18) {
unsigned int elsize;
@@ -836,9 +864,6 @@ int fix_alignment(struct pt_regs *regs)
return emulate_vsx(addr, reg, areg, regs, flags, nb, elsize);
}
 #endif
-#else
-   return -EFAULT;
-#endif
/* A size of 0 indicates an instruction we don't support, with
 * the exception of DCBZ which is handled as a special case here
 */
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 55/63] ibmvscsi: Fix little endian issues

2013-08-06 Thread Anton Blanchard
The hypervisor is big endian, so little endian kernel builds need
to byteswap.

Signed-off-by: Anton Blanchard an...@samba.org
---
 drivers/scsi/ibmvscsi/ibmvscsi.c | 153 ++-
 drivers/scsi/ibmvscsi/viosrp.h   |  46 ++--
 2 files changed, 108 insertions(+), 91 deletions(-)

diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.c b/drivers/scsi/ibmvscsi/ibmvscsi.c
index d0fa4b6..62bdbc9 100644
--- a/drivers/scsi/ibmvscsi/ibmvscsi.c
+++ b/drivers/scsi/ibmvscsi/ibmvscsi.c
@@ -241,7 +241,7 @@ static void gather_partition_info(void)
struct device_node *rootdn;
 
const char *ppartition_name;
-   const unsigned int *p_number_ptr;
+   const __be32 *p_number_ptr;
 
/* Retrieve information about this partition */
rootdn = of_find_node_by_path(/);
@@ -255,7 +255,7 @@ static void gather_partition_info(void)
sizeof(partition_name));
p_number_ptr = of_get_property(rootdn, ibm,partition-no, NULL);
if (p_number_ptr)
-   partition_number = *p_number_ptr;
+   partition_number = of_read_number(p_number_ptr, 1);
of_node_put(rootdn);
 }
 
@@ -270,10 +270,11 @@ static void set_adapter_info(struct ibmvscsi_host_data 
*hostdata)
strncpy(hostdata-madapter_info.partition_name, partition_name,
sizeof(hostdata-madapter_info.partition_name));
 
-   hostdata-madapter_info.partition_number = partition_number;
+   hostdata-madapter_info.partition_number =
+   cpu_to_be32(partition_number);
 
-   hostdata-madapter_info.mad_version = 1;
-   hostdata-madapter_info.os_type = 2;
+   hostdata-madapter_info.mad_version = cpu_to_be32(1);
+   hostdata-madapter_info.os_type = cpu_to_be32(2);
 }
 
 /**
@@ -464,9 +465,9 @@ static int initialize_event_pool(struct event_pool *pool,
memset(evt-crq, 0x00, sizeof(evt-crq));
atomic_set(evt-free, 1);
evt-crq.valid = 0x80;
-   evt-crq.IU_length = sizeof(*evt-xfer_iu);
-   evt-crq.IU_data_ptr = pool-iu_token + 
-   sizeof(*evt-xfer_iu) * i;
+   evt-crq.IU_length = cpu_to_be16(sizeof(*evt-xfer_iu));
+   evt-crq.IU_data_ptr = cpu_to_be64(pool-iu_token + 
+   sizeof(*evt-xfer_iu) * i);
evt-xfer_iu = pool-iu_storage + i;
evt-hostdata = hostdata;
evt-ext_list = NULL;
@@ -588,7 +589,7 @@ static void init_event_struct(struct srp_event_struct 
*evt_struct,
evt_struct-cmnd_done = NULL;
evt_struct-sync_srp = NULL;
evt_struct-crq.format = format;
-   evt_struct-crq.timeout = timeout;
+   evt_struct-crq.timeout = cpu_to_be16(timeout);
evt_struct-done = done;
 }
 
@@ -659,8 +660,8 @@ static int map_sg_list(struct scsi_cmnd *cmd, int nseg,
 
scsi_for_each_sg(cmd, sg, nseg, i) {
struct srp_direct_buf *descr = md + i;
-   descr-va = sg_dma_address(sg);
-   descr-len = sg_dma_len(sg);
+   descr-va = cpu_to_be64(sg_dma_address(sg));
+   descr-len = cpu_to_be32(sg_dma_len(sg));
descr-key = 0;
total_length += sg_dma_len(sg);
}
@@ -703,13 +704,14 @@ static int map_sg_data(struct scsi_cmnd *cmd,
}
 
indirect-table_desc.va = 0;
-   indirect-table_desc.len = sg_mapped * sizeof(struct srp_direct_buf);
+   indirect-table_desc.len = cpu_to_be32(sg_mapped *
+  sizeof(struct srp_direct_buf));
indirect-table_desc.key = 0;
 
if (sg_mapped = MAX_INDIRECT_BUFS) {
total_length = map_sg_list(cmd, sg_mapped,
   indirect-desc_list[0]);
-   indirect-len = total_length;
+   indirect-len = cpu_to_be32(total_length);
return 1;
}
 
@@ -731,9 +733,10 @@ static int map_sg_data(struct scsi_cmnd *cmd,
 
total_length = map_sg_list(cmd, sg_mapped, evt_struct-ext_list);
 
-   indirect-len = total_length;
-   indirect-table_desc.va = evt_struct-ext_list_token;
-   indirect-table_desc.len = sg_mapped * sizeof(indirect-desc_list[0]);
+   indirect-len = cpu_to_be32(total_length);
+   indirect-table_desc.va = cpu_to_be64(evt_struct-ext_list_token);
+   indirect-table_desc.len = cpu_to_be32(sg_mapped *
+  sizeof(indirect-desc_list[0]));
memcpy(indirect-desc_list, evt_struct-ext_list,
   MAX_INDIRECT_BUFS * sizeof(struct srp_direct_buf));
return 1;
@@ -849,7 +852,7 @@ static int ibmvscsi_send_srp_event(struct srp_event_struct 
*evt_struct,
   struct ibmvscsi_host_data *hostdata,
   unsigned long timeout)
 {
-   u64 *crq_as_u64 = (u64 *) 

[PATCH 54/63] ibmveth: Fix little endian issues

2013-08-06 Thread Anton Blanchard
The hypervisor is big endian, so little endian kernel builds need
to byteswap.

Signed-off-by: Anton Blanchard an...@samba.org
---
 drivers/net/ethernet/ibm/ibmveth.c |  4 ++--
 drivers/net/ethernet/ibm/ibmveth.h | 19 ---
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/ibm/ibmveth.c 
b/drivers/net/ethernet/ibm/ibmveth.c
index 70fd559..5d41aee 100644
--- a/drivers/net/ethernet/ibm/ibmveth.c
+++ b/drivers/net/ethernet/ibm/ibmveth.c
@@ -106,7 +106,7 @@ struct ibmveth_stat ibmveth_stats[] = {
 /* simple methods of getting data from the current rxq entry */
 static inline u32 ibmveth_rxq_flags(struct ibmveth_adapter *adapter)
 {
-   return adapter-rx_queue.queue_addr[adapter-rx_queue.index].flags_off;
+   return 
be32_to_cpu(adapter-rx_queue.queue_addr[adapter-rx_queue.index].flags_off);
 }
 
 static inline int ibmveth_rxq_toggle(struct ibmveth_adapter *adapter)
@@ -132,7 +132,7 @@ static inline int ibmveth_rxq_frame_offset(struct 
ibmveth_adapter *adapter)
 
 static inline int ibmveth_rxq_frame_length(struct ibmveth_adapter *adapter)
 {
-   return adapter-rx_queue.queue_addr[adapter-rx_queue.index].length;
+   return 
be32_to_cpu(adapter-rx_queue.queue_addr[adapter-rx_queue.index].length);
 }
 
 static inline int ibmveth_rxq_csum_good(struct ibmveth_adapter *adapter)
diff --git a/drivers/net/ethernet/ibm/ibmveth.h 
b/drivers/net/ethernet/ibm/ibmveth.h
index 43a794f..84066ba 100644
--- a/drivers/net/ethernet/ibm/ibmveth.h
+++ b/drivers/net/ethernet/ibm/ibmveth.h
@@ -164,14 +164,26 @@ struct ibmveth_adapter {
 u64 tx_send_failed;
 };
 
+/*
+ * We pass struct ibmveth_buf_desc_fields to the hypervisor in registers,
+ * so we don't need to byteswap the two elements. However since we use
+ * a union (ibmveth_buf_desc) to convert from the struct to a u64 we
+ * do end up with endian specific ordering of the elements and that
+ * needs correcting.
+ */
 struct ibmveth_buf_desc_fields {
+#ifdef __BIG_ENDIAN
+   u32 flags_len;
+   u32 address;
+#else
+   u32 address;
u32 flags_len;
+#endif
 #define IBMVETH_BUF_VALID  0x8000
 #define IBMVETH_BUF_TOGGLE 0x4000
 #define IBMVETH_BUF_NO_CSUM0x0200
 #define IBMVETH_BUF_CSUM_GOOD  0x0100
 #define IBMVETH_BUF_LEN_MASK   0x00FF
-   u32 address;
 };
 
 union ibmveth_buf_desc {
@@ -180,7 +192,7 @@ union ibmveth_buf_desc {
 };
 
 struct ibmveth_rx_q_entry {
-   u32 flags_off;
+   __be32 flags_off;
 #define IBMVETH_RXQ_TOGGLE 0x8000
 #define IBMVETH_RXQ_TOGGLE_SHIFT   31
 #define IBMVETH_RXQ_VALID  0x4000
@@ -188,7 +200,8 @@ struct ibmveth_rx_q_entry {
 #define IBMVETH_RXQ_CSUM_GOOD  0x0100
 #define IBMVETH_RXQ_OFF_MASK   0x
 
-   u32 length;
+   __be32 length;
+   /* correlator is only used by the OS, no need to byte swap */
u64 correlator;
 };
 
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 56/63] [SCSI] lpfc: Don't force CONFIG_GENERIC_CSUM on

2013-08-06 Thread Anton Blanchard
We want ppc64 to be able to select between optimised assembly
checksum routines in big endian, and the generic lib/checksum.c
routines in little endian.

The lpfc driver is forcing CONFIG_GENERIC_CSUM on which means
we are unable to make the choice of when to enable and disable
it in the arch Kconfig. If the option exists it is always
forced on.

Other users of the checksum routines (eg networking code) do
not have a select CONFIG_GENERIC_CSUM, so I don't see why
the lpfc driver should.

Signed-off-by: Anton Blanchard an...@samba.org
---
 drivers/scsi/Kconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 48b2918..92ff027 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -1353,7 +1353,6 @@ config SCSI_LPFC
tristate Emulex LightPulse Fibre Channel Support
depends on PCI  SCSI
select SCSI_FC_ATTRS
-   select GENERIC_CSUM
select CRC_T10DIF
help
   This lpfc driver supports the Emulex LightPulse
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 57/63] powerpc: Use generic checksum code in little endian

2013-08-06 Thread Anton Blanchard
We need to fix some endian issues in our checksum code. For now
just enable the generic checksum routines for little endian builds.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/Kconfig| 3 +++
 arch/powerpc/include/asm/checksum.h | 5 +
 arch/powerpc/kernel/ppc_ksyms.c | 2 ++
 arch/powerpc/lib/Makefile   | 9 +++--
 4 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 3bf72cd..818974d 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -140,6 +140,9 @@ config PPC
select OLD_SIGACTION if PPC32
select HAVE_DEBUG_STACKOVERFLOW
 
+config GENERIC_CSUM
+   def_bool CPU_LITTLE_ENDIAN
+
 config EARLY_PRINTK
bool
default y
diff --git a/arch/powerpc/include/asm/checksum.h 
b/arch/powerpc/include/asm/checksum.h
index ce0c284..a8de989 100644
--- a/arch/powerpc/include/asm/checksum.h
+++ b/arch/powerpc/include/asm/checksum.h
@@ -14,6 +14,7 @@
  * which always checksum on 4 octet boundaries.  ihl is the number
  * of 32-bit words and is always = 5.
  */
+#ifndef CONFIG_GENERIC_CSUM
 extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
 
 /*
@@ -123,5 +124,9 @@ static inline __wsum csum_tcpudp_nofold(__be32 saddr, 
__be32 daddr,
return sum;
 #endif
 }
+
+#else
+#include asm-generic/checksum.h
+#endif
 #endif /* __KERNEL__ */
 #endif
diff --git a/arch/powerpc/kernel/ppc_ksyms.c b/arch/powerpc/kernel/ppc_ksyms.c
index c296665..0c2dd60 100644
--- a/arch/powerpc/kernel/ppc_ksyms.c
+++ b/arch/powerpc/kernel/ppc_ksyms.c
@@ -79,10 +79,12 @@ EXPORT_SYMBOL(strlen);
 EXPORT_SYMBOL(strcmp);
 EXPORT_SYMBOL(strncmp);
 
+#ifndef CONFIG_GENERIC_CSUM
 EXPORT_SYMBOL(csum_partial);
 EXPORT_SYMBOL(csum_partial_copy_generic);
 EXPORT_SYMBOL(ip_fast_csum);
 EXPORT_SYMBOL(csum_tcpudp_magic);
+#endif
 
 EXPORT_SYMBOL(__copy_tofrom_user);
 EXPORT_SYMBOL(__clear_user);
diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
index 4504332..33ab261 100644
--- a/arch/powerpc/lib/Makefile
+++ b/arch/powerpc/lib/Makefile
@@ -10,15 +10,20 @@ CFLAGS_REMOVE_code-patching.o = -pg
 CFLAGS_REMOVE_feature-fixups.o = -pg
 
 obj-y  := string.o alloc.o \
-  checksum_$(CONFIG_WORD_SIZE).o crtsavres.o
+  crtsavres.o
 obj-$(CONFIG_PPC32)+= div64.o copy_32.o
 obj-$(CONFIG_HAS_IOMEM)+= devres.o
 
 obj-$(CONFIG_PPC64)+= copypage_64.o copyuser_64.o \
   memcpy_64.o usercopy_64.o mem_64.o string.o \
-  checksum_wrappers_64.o hweight_64.o \
+  hweight_64.o \
   copyuser_power7.o string_64.o copypage_power7.o \
   memcpy_power7.o
+ifeq ($(CONFIG_GENERIC_CSUM),)
+obj-y  += checksum_$(CONFIG_WORD_SIZE).o
+obj-$(CONFIG_PPC64)+= checksum_wrappers_64.o
+endif
+
 obj-$(CONFIG_PPC_EMULATE_SSTEP)+= sstep.o ldstfp.o
 
 ifeq ($(CONFIG_PPC64),y)
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 58/63] powerpc: Use generic memcpy code in little endian

2013-08-06 Thread Anton Blanchard
We need to fix some endian issues in our memcpy code. For now
just enable the generic memcpy routine for little endian builds.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/include/asm/string.h | 4 
 arch/powerpc/kernel/ppc_ksyms.c   | 2 ++
 arch/powerpc/lib/Makefile | 9 ++---
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/include/asm/string.h 
b/arch/powerpc/include/asm/string.h
index e40010a..0dffad6 100644
--- a/arch/powerpc/include/asm/string.h
+++ b/arch/powerpc/include/asm/string.h
@@ -10,7 +10,9 @@
 #define __HAVE_ARCH_STRNCMP
 #define __HAVE_ARCH_STRCAT
 #define __HAVE_ARCH_MEMSET
+#ifdef __BIG_ENDIAN__
 #define __HAVE_ARCH_MEMCPY
+#endif
 #define __HAVE_ARCH_MEMMOVE
 #define __HAVE_ARCH_MEMCMP
 #define __HAVE_ARCH_MEMCHR
@@ -22,7 +24,9 @@ extern int strcmp(const char *,const char *);
 extern int strncmp(const char *, const char *, __kernel_size_t);
 extern char * strcat(char *, const char *);
 extern void * memset(void *,int,__kernel_size_t);
+#ifdef __BIG_ENDIAN__
 extern void * memcpy(void *,const void *,__kernel_size_t);
+#endif
 extern void * memmove(void *,const void *,__kernel_size_t);
 extern int memcmp(const void *,const void *,__kernel_size_t);
 extern void * memchr(const void *,int,__kernel_size_t);
diff --git a/arch/powerpc/kernel/ppc_ksyms.c b/arch/powerpc/kernel/ppc_ksyms.c
index 0c2dd60..526ad5c 100644
--- a/arch/powerpc/kernel/ppc_ksyms.c
+++ b/arch/powerpc/kernel/ppc_ksyms.c
@@ -147,7 +147,9 @@ EXPORT_SYMBOL(__ucmpdi2);
 #endif
 long long __bswapdi2(long long);
 EXPORT_SYMBOL(__bswapdi2);
+#ifdef __BIG_ENDIAN__
 EXPORT_SYMBOL(memcpy);
+#endif
 EXPORT_SYMBOL(memset);
 EXPORT_SYMBOL(memmove);
 EXPORT_SYMBOL(memcmp);
diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
index 33ab261..5310132 100644
--- a/arch/powerpc/lib/Makefile
+++ b/arch/powerpc/lib/Makefile
@@ -15,15 +15,18 @@ obj-$(CONFIG_PPC32) += div64.o copy_32.o
 obj-$(CONFIG_HAS_IOMEM)+= devres.o
 
 obj-$(CONFIG_PPC64)+= copypage_64.o copyuser_64.o \
-  memcpy_64.o usercopy_64.o mem_64.o string.o \
+  usercopy_64.o mem_64.o string.o \
   hweight_64.o \
-  copyuser_power7.o string_64.o copypage_power7.o \
-  memcpy_power7.o
+  copyuser_power7.o string_64.o copypage_power7.o
 ifeq ($(CONFIG_GENERIC_CSUM),)
 obj-y  += checksum_$(CONFIG_WORD_SIZE).o
 obj-$(CONFIG_PPC64)+= checksum_wrappers_64.o
 endif
 
+ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),)
+obj-$(CONFIG_PPC64)+= memcpy_power7.o memcpy_64.o 
+endif
+
 obj-$(CONFIG_PPC_EMULATE_SSTEP)+= sstep.o ldstfp.o
 
 ifeq ($(CONFIG_PPC64),y)
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 60/63] powerpc: Add ability to build little endian kernels

2013-08-06 Thread Anton Blanchard
From: Ian Munsie imun...@au1.ibm.com

This patch allows the kbuild system to successfully compile a kernel for
the little endian PowerPC64 architecture.

To build such a kernel a supported platform must be used and
CONFIG_CPU_LITTLE_ENDIAN must be set. If cross compiling, CROSS_COMPILE
must point to a suitable toolchain (compiled for the powerpc64le-linux
and powerpcle-linux targets).

Signed-off-by: Ian Munsie imun...@au1.ibm.com
Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/Makefile   | 24 +---
 arch/powerpc/boot/Makefile  |  3 ++-
 arch/powerpc/kernel/vdso32/vdso32.lds.S |  4 
 arch/powerpc/kernel/vdso64/vdso64.lds.S |  4 
 arch/powerpc/platforms/Kconfig.cputype  | 11 +++
 5 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index c574a69..0ebad9c 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -65,11 +65,29 @@ endif
 
 UTS_MACHINE := $(OLDARCH)
 
+ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),y)
+override CC+= -mlittle-endian
+override AS+= -mlittle-endian
+override LD+= -EL
+override CROSS32CC += -mlittle-endian
+override CROSS32AS += -mlittle-endian
+LDEMULATION:= lppc
+GNUTARGET  := powerpcle
+MULTIPLEWORD   := -mno-multiple
+else
+override CC+= -mbig-endian
+override AS+= -mbig-endian
+override LD+= -EB
+LDEMULATION:= ppc
+GNUTARGET  := powerpc
+MULTIPLEWORD   := -mmultiple
+endif
+
 ifeq ($(HAS_BIARCH),y)
 override AS+= -a$(CONFIG_WORD_SIZE)
-override LD+= -m elf$(CONFIG_WORD_SIZE)ppc
+override LD+= -m elf$(CONFIG_WORD_SIZE)$(LDEMULATION)
 override CC+= -m$(CONFIG_WORD_SIZE)
-override AR:= GNUTARGET=elf$(CONFIG_WORD_SIZE)-powerpc $(AR)
+override AR:= GNUTARGET=elf$(CONFIG_WORD_SIZE)-$(GNUTARGET) $(AR)
 endif
 
 LDFLAGS_vmlinux-y := -Bstatic
@@ -95,7 +113,7 @@ endif
 CFLAGS-$(CONFIG_PPC64) := -mtraceback=no -mcall-aixdesc
 CFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mcmodel=medium,-mminimal-toc)
 CFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mno-pointers-to-nested-functions)
-CFLAGS-$(CONFIG_PPC32) := -ffixed-r2 -mmultiple
+CFLAGS-$(CONFIG_PPC32) := -ffixed-r2 $(MULTIPLEWORD)
 
 CFLAGS-$(CONFIG_GENERIC_CPU) += $(call cc-option,-mtune=power7,-mtune=power4)
 CFLAGS-$(CONFIG_CELL_CPU) += $(call cc-option,-mcpu=cell)
diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile
index 6a15c96..1e6baf0 100644
--- a/arch/powerpc/boot/Makefile
+++ b/arch/powerpc/boot/Makefile
@@ -22,7 +22,8 @@ all: $(obj)/zImage
 BOOTCFLAGS:= -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
 -fno-strict-aliasing -Os -msoft-float -pipe \
 -fomit-frame-pointer -fno-builtin -fPIC -nostdinc \
--isystem $(shell $(CROSS32CC) -print-file-name=include)
+-isystem $(shell $(CROSS32CC) -print-file-name=include) \
+-mbig-endian
 BOOTAFLAGS := -D__ASSEMBLY__ $(BOOTCFLAGS) -traditional -nostdinc
 
 ifdef CONFIG_DEBUG_INFO
diff --git a/arch/powerpc/kernel/vdso32/vdso32.lds.S 
b/arch/powerpc/kernel/vdso32/vdso32.lds.S
index f223409..e58ee10 100644
--- a/arch/powerpc/kernel/vdso32/vdso32.lds.S
+++ b/arch/powerpc/kernel/vdso32/vdso32.lds.S
@@ -4,7 +4,11 @@
  */
 #include asm/vdso.h
 
+#ifdef __LITTLE_ENDIAN__
+OUTPUT_FORMAT(elf32-powerpcle, elf32-powerpcle, elf32-powerpcle)
+#else
 OUTPUT_FORMAT(elf32-powerpc, elf32-powerpc, elf32-powerpc)
+#endif
 OUTPUT_ARCH(powerpc:common)
 ENTRY(_start)
 
diff --git a/arch/powerpc/kernel/vdso64/vdso64.lds.S 
b/arch/powerpc/kernel/vdso64/vdso64.lds.S
index e486381..64fb183 100644
--- a/arch/powerpc/kernel/vdso64/vdso64.lds.S
+++ b/arch/powerpc/kernel/vdso64/vdso64.lds.S
@@ -4,7 +4,11 @@
  */
 #include asm/vdso.h
 
+#ifdef __LITTLE_ENDIAN__
+OUTPUT_FORMAT(elf64-powerpcle, elf64-powerpcle, elf64-powerpcle)
+#else
 OUTPUT_FORMAT(elf64-powerpc, elf64-powerpc, elf64-powerpc)
+#endif
 OUTPUT_ARCH(powerpc:common64)
 ENTRY(_start)
 
diff --git a/arch/powerpc/platforms/Kconfig.cputype 
b/arch/powerpc/platforms/Kconfig.cputype
index 47d9a03..89f91ed 100644
--- a/arch/powerpc/platforms/Kconfig.cputype
+++ b/arch/powerpc/platforms/Kconfig.cputype
@@ -389,3 +389,14 @@ config PPC_DOORBELL
default n
 
 endmenu
+
+config CPU_LITTLE_ENDIAN
+   bool Build little endian kernel
+   default n
+   help
+ This option selects whether a big endian or little endian kernel will
+ be built.
+
+ Note that if cross compiling a little endian kernel,
+ CROSS_COMPILE must point to a toolchain capable of targeting
+ little endian powerpc.
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 61/63] powerpc: Don't set HAVE_EFFICIENT_UNALIGNED_ACCESS on little endian builds

2013-08-06 Thread Anton Blanchard
POWER7 takes alignment exceptions on some unaligned addresses, so
disable HAVE_EFFICIENT_UNALIGNED_ACCESS. This fixes an early boot
issue in the printk code.

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 818974d..9dcc85f 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -97,7 +97,7 @@ config PPC
select VIRT_TO_BUS if !PPC64
select HAVE_IDE
select HAVE_IOREMAP_PROT
-   select HAVE_EFFICIENT_UNALIGNED_ACCESS
+   select HAVE_EFFICIENT_UNALIGNED_ACCESS if !CPU_LITTLE_ENDIAN
select HAVE_KPROBES
select HAVE_ARCH_KGDB
select HAVE_KRETPROBES
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 62/63] powerpc: Work around little endian gcc bug

2013-08-06 Thread Anton Blanchard
Temporarily work around an ICE we are seeing while building
in little endian mode:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57134

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 0ebad9c..ab23441 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -66,7 +66,7 @@ endif
 UTS_MACHINE := $(OLDARCH)
 
 ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),y)
-override CC+= -mlittle-endian
+override CC+= -mlittle-endian -mno-strict-align
 override AS+= -mlittle-endian
 override LD+= -EL
 override CROSS32CC += -mlittle-endian
-- 
1.8.1.2

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 63/63] powerpc: Add pseries_le_defconfig

2013-08-06 Thread Anton Blanchard
This is the pseries_defconfig with CONFIG_CPU_LITTLE_ENDIAN enabled
and CONFIG_VIRTUALIZATION disabled (required until we fix some
endian issues in KVM).

Signed-off-by: Anton Blanchard an...@samba.org
---
 arch/powerpc/configs/pseries_le_defconfig | 347 ++
 1 file changed, 347 insertions(+)
 create mode 100644 arch/powerpc/configs/pseries_le_defconfig

diff --git a/arch/powerpc/configs/pseries_le_defconfig 
b/arch/powerpc/configs/pseries_le_defconfig
new file mode 100644
index 000..a30db45
--- /dev/null
+++ b/arch/powerpc/configs/pseries_le_defconfig
@@ -0,0 +1,347 @@
+CONFIG_PPC64=y
+CONFIG_ALTIVEC=y
+CONFIG_VSX=y
+CONFIG_SMP=y
+CONFIG_NR_CPUS=2048
+CONFIG_EXPERIMENTAL=y
+CONFIG_SYSVIPC=y
+CONFIG_POSIX_MQUEUE=y
+CONFIG_AUDIT=y
+CONFIG_AUDITSYSCALL=y
+CONFIG_IRQ_DOMAIN_DEBUG=y
+CONFIG_NO_HZ=y
+CONFIG_HIGH_RES_TIMERS=y
+CONFIG_TASKSTATS=y
+CONFIG_TASK_DELAY_ACCT=y
+CONFIG_TASK_XACCT=y
+CONFIG_TASK_IO_ACCOUNTING=y
+CONFIG_IKCONFIG=y
+CONFIG_IKCONFIG_PROC=y
+CONFIG_CGROUPS=y
+CONFIG_CGROUP_FREEZER=y
+CONFIG_CGROUP_DEVICE=y
+CONFIG_CPUSETS=y
+CONFIG_CGROUP_CPUACCT=y
+CONFIG_BLK_DEV_INITRD=y
+# CONFIG_COMPAT_BRK is not set
+CONFIG_PROFILING=y
+CONFIG_OPROFILE=y
+CONFIG_KPROBES=y
+CONFIG_JUMP_LABEL=y
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+CONFIG_MODVERSIONS=y
+CONFIG_MODULE_SRCVERSION_ALL=y
+CONFIG_PARTITION_ADVANCED=y
+CONFIG_EFI_PARTITION=y
+CONFIG_PPC_SPLPAR=y
+CONFIG_SCANLOG=m
+CONFIG_PPC_SMLPAR=y
+CONFIG_DTL=y
+# CONFIG_PPC_PMAC is not set
+CONFIG_RTAS_FLASH=m
+CONFIG_IBMEBUS=y
+CONFIG_HZ_100=y
+CONFIG_BINFMT_MISC=m
+CONFIG_PPC_TRANSACTIONAL_MEM=y
+CONFIG_HOTPLUG_CPU=y
+CONFIG_KEXEC=y
+CONFIG_IRQ_ALL_CPUS=y
+CONFIG_MEMORY_HOTPLUG=y
+CONFIG_MEMORY_HOTREMOVE=y
+CONFIG_PPC_64K_PAGES=y
+CONFIG_PPC_SUBPAGE_PROT=y
+CONFIG_SCHED_SMT=y
+CONFIG_PPC_DENORMALISATION=y
+CONFIG_HOTPLUG_PCI=m
+CONFIG_HOTPLUG_PCI_RPA=m
+CONFIG_HOTPLUG_PCI_RPA_DLPAR=m
+CONFIG_PACKET=y
+CONFIG_UNIX=y
+CONFIG_XFRM_USER=m
+CONFIG_NET_KEY=m
+CONFIG_INET=y
+CONFIG_IP_MULTICAST=y
+CONFIG_NET_IPIP=y
+CONFIG_SYN_COOKIES=y
+CONFIG_INET_AH=m
+CONFIG_INET_ESP=m
+CONFIG_INET_IPCOMP=m
+# CONFIG_IPV6 is not set
+CONFIG_NETFILTER=y
+CONFIG_NF_CONNTRACK=m
+CONFIG_NF_CONNTRACK_EVENTS=y
+CONFIG_NF_CT_PROTO_UDPLITE=m
+CONFIG_NF_CONNTRACK_FTP=m
+CONFIG_NF_CONNTRACK_IRC=m
+CONFIG_NF_CONNTRACK_TFTP=m
+CONFIG_NF_CT_NETLINK=m
+CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
+CONFIG_NETFILTER_XT_TARGET_CONNMARK=m
+CONFIG_NETFILTER_XT_TARGET_MARK=m
+CONFIG_NETFILTER_XT_TARGET_NFLOG=m
+CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
+CONFIG_NETFILTER_XT_TARGET_TCPMSS=m
+CONFIG_NETFILTER_XT_MATCH_COMMENT=m
+CONFIG_NETFILTER_XT_MATCH_CONNBYTES=m
+CONFIG_NETFILTER_XT_MATCH_CONNLIMIT=m
+CONFIG_NETFILTER_XT_MATCH_CONNMARK=m
+CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
+CONFIG_NETFILTER_XT_MATCH_DCCP=m
+CONFIG_NETFILTER_XT_MATCH_DSCP=m
+CONFIG_NETFILTER_XT_MATCH_ESP=m
+CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
+CONFIG_NETFILTER_XT_MATCH_HELPER=m
+CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
+CONFIG_NETFILTER_XT_MATCH_LENGTH=m
+CONFIG_NETFILTER_XT_MATCH_LIMIT=m
+CONFIG_NETFILTER_XT_MATCH_MAC=m
+CONFIG_NETFILTER_XT_MATCH_MARK=m
+CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m
+CONFIG_NETFILTER_XT_MATCH_OWNER=m
+CONFIG_NETFILTER_XT_MATCH_POLICY=m
+CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
+CONFIG_NETFILTER_XT_MATCH_QUOTA=m
+CONFIG_NETFILTER_XT_MATCH_RATEEST=m
+CONFIG_NETFILTER_XT_MATCH_REALM=m
+CONFIG_NETFILTER_XT_MATCH_RECENT=m
+CONFIG_NETFILTER_XT_MATCH_SCTP=m
+CONFIG_NETFILTER_XT_MATCH_STATE=m
+CONFIG_NETFILTER_XT_MATCH_STATISTIC=m
+CONFIG_NETFILTER_XT_MATCH_STRING=m
+CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
+CONFIG_NETFILTER_XT_MATCH_TIME=m
+CONFIG_NETFILTER_XT_MATCH_U32=m
+CONFIG_NF_CONNTRACK_IPV4=m
+CONFIG_IP_NF_QUEUE=m
+CONFIG_IP_NF_IPTABLES=m
+CONFIG_IP_NF_MATCH_AH=m
+CONFIG_IP_NF_MATCH_ECN=m
+CONFIG_IP_NF_MATCH_TTL=m
+CONFIG_IP_NF_FILTER=m
+CONFIG_IP_NF_TARGET_REJECT=m
+CONFIG_IP_NF_TARGET_ULOG=m
+CONFIG_UEVENT_HELPER_PATH=/sbin/hotplug
+CONFIG_DEVTMPFS=y
+CONFIG_DEVTMPFS_MOUNT=y
+CONFIG_PROC_DEVICETREE=y
+CONFIG_PARPORT=m
+CONFIG_PARPORT_PC=m
+CONFIG_BLK_DEV_FD=m
+CONFIG_BLK_DEV_LOOP=y
+CONFIG_BLK_DEV_NBD=m
+CONFIG_BLK_DEV_RAM=y
+CONFIG_BLK_DEV_RAM_SIZE=65536
+CONFIG_IDE=y
+CONFIG_BLK_DEV_IDECD=y
+CONFIG_BLK_DEV_GENERIC=y
+CONFIG_BLK_DEV_AMD74XX=y
+CONFIG_BLK_DEV_SD=y
+CONFIG_CHR_DEV_ST=y
+CONFIG_BLK_DEV_SR=y
+CONFIG_BLK_DEV_SR_VENDOR=y
+CONFIG_CHR_DEV_SG=y
+CONFIG_SCSI_MULTI_LUN=y
+CONFIG_SCSI_CONSTANTS=y
+CONFIG_SCSI_FC_ATTRS=y
+CONFIG_SCSI_CXGB3_ISCSI=m
+CONFIG_SCSI_CXGB4_ISCSI=m
+CONFIG_SCSI_BNX2_ISCSI=m
+CONFIG_BE2ISCSI=m
+CONFIG_SCSI_MPT2SAS=m
+CONFIG_SCSI_IBMVSCSI=y
+CONFIG_SCSI_IBMVFC=m
+CONFIG_SCSI_SYM53C8XX_2=y
+CONFIG_SCSI_SYM53C8XX_DMA_ADDRESSING_MODE=0
+CONFIG_SCSI_IPR=y
+CONFIG_SCSI_QLA_FC=m
+CONFIG_SCSI_QLA_ISCSI=m
+CONFIG_SCSI_LPFC=m
+CONFIG_ATA=y
+# CONFIG_ATA_SFF is not set
+CONFIG_MD=y
+CONFIG_BLK_DEV_MD=y
+CONFIG_MD_LINEAR=y
+CONFIG_MD_RAID0=y
+CONFIG_MD_RAID1=y
+CONFIG_MD_RAID10=m
+CONFIG_MD_RAID456=m
+CONFIG_MD_MULTIPATH=m
+CONFIG_MD_FAULTY=m
+CONFIG_BLK_DEV_DM=y

[PATCH] powerpc: Ignore zImage.epapr

2013-08-06 Thread Mark Brown
From: Mark Brown broo...@linaro.org

This is another file we can generate so add it to the list.

Signed-off-by: Mark Brown broo...@linaro.org
---
 arch/powerpc/boot/.gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/boot/.gitignore b/arch/powerpc/boot/.gitignore
index c32ae5c..554734f 100644
--- a/arch/powerpc/boot/.gitignore
+++ b/arch/powerpc/boot/.gitignore
@@ -22,6 +22,7 @@ zImage.initrd
 zImage.bin.*
 zImage.chrp
 zImage.coff
+zImage.epapr
 zImage.holly
 zImage.*lds
 zImage.miboot
-- 
1.8.4.rc1

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: Failure to detect PCI card

2013-08-06 Thread Anatolij Gustschin
On Mon, 5 Aug 2013 16:14:29 -0700
Peter LaDow pet...@gocougs.wsu.edu wrote:
...
 Perhaps it is a BIOS option ROM like you suggested earlier.  The
 3c90xC reference manual I found
 (http://people.freebsd.org/~wpaul/3Com/3c90xc.pdf) mentions an option
 ROM (and there is an Atmel part stuffed).  I can't find any technical
 information on the FA331 (yet), so I don't know about it.
 
 But regardless, wouldn't enumeration have to occur before any option
 ROM could even be used?

Yes. If the device didn't respond with its Device- and Vendor-ID
when reading its configuration space, then it cannot be configured
and reading the expansion ROM won't work.

Thanks,

Anatolij

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v4 00/31] add COMMON_CLK support for PowerPC MPC512x

2013-08-06 Thread Gerhard Sittig
this series
- fixes several drivers that are used in the MPC512x platform (UART,
  SPI, ethernet, PCI, USB, CAN, NAND flash, video capture) in how they
  handle clocks (appropriately acquire and setup them, hold references
  during use, release clocks after use)
- introduces support for the common clock framework (CCF, COMMON_CLK
  Kconfig option) in the PowerPC based MPC512x platform, which brings
  device tree based clock lookup as well

although the series does touch several subsystems -- tty (serial), spi,
net (can, fs_enet), mtd (nfc), usb, i2c, media (viu), and dts -- all of
the patches are strictly clock related or trivial

it appears most appropriate to take this series through either the clk
or the powerpc trees after it has passed review and other subsystem
maintainers ACKed the clock setup related driver modifications

the series passes 'checkpatch.pl --strict' except for one warning which
cannot get resolved, since that either breaks compilation (the data type
is preset by the clk-provider.h API) or requires a cast which shadows
real mismatches:

  WARNING: static const char * array should probably be static const char * 
const
  #431: FILE: arch/powerpc/platforms/512x/clock-commonclk.c:334:
  +static const char *parent_names_mux0[] = {

  total: 0 errors, 1 warnings, 0 checks, 807 lines checked

each step in the series was build and run tested (with a display that is
attached to the DIU as well as SPI, with an SPI attached NOR flash, with
multiple UART ports such that one is not the boot console, with EEPROMs
attached to I2C, with an SD card, booting from network)


changes in v4:
- remove explicit devm_clk_put() calls as these will occur implicitly
  upon device release (01/31, 02/31, 03/31, 04/31, 05/31, 06/31, 08/31,
  09/31, 27/31)
- split the PSC (SPI, UART) and MSCAN (CAN) related MCLK subtrees into
  separate 'ipg'/'bdlc' gated clock items for register access as well as
  the 'mclk' clock subtrees that apply to bitrates -- this eliminates
  the need for shared gates and further reduces clock pre-enable
  workarounds (11/31, 15/31, 17/31, 18/31, 20/31, 21/31, 22/31, 27/31)
- further adjust the CAN clock driver, fix an incomplete error code path
  in the network device open callback (11/31), only enable the bitrate
  clock when the network device is open (27/31)
- remove debug output in the clock tree setup when introducing the
  platform's clock driver, there already is CONFIG_COMMON_CLK_DEBUG to
  retrieve more complete information (17/31)
- remove an enums don't work here comment in the dt-bindings header
  file (15/31)
- reword and update commit messages (body and/or subject) where
  appropriate (03/31, 04/31, 05/31, 06/31, 08/31, 09/31, 11/31, 12/31,
  17/31, 20/31, 21/31, 22/31, 27/31, 28/31, 30/31, 31/31)
- add 'Reviewed-By' attributes which were received for v3

changes in v3:
- rebase the series against v3.11-rc2
- re-ordered the series to first address all general clock handling
  concerns in existing drivers, before introducing common clock support
  in the platform's clock driver
- slightly rework the SPI (01/31), UART (02/31), and PSC FIFO (23/31)
  clock handling in comparison to v2 which introduced those fixes
  (devm_{get,put}_clk() calls, fewer goto labels in error paths)
- fix and improve clock handling (balance allocation and release of
  clocks, check for errors during setup) in all of the other drivers
  which this series has touched before in naive ways: USB (03/31), NAND
  flash (04/31), video capture (05/31), I2C (06/31), ethernet (08/31),
  PCI (09/31), CAN (11/31)
- silence a build warning in the ethernet driver (07/31)
- eliminate all PPC_CLOCK references, use 'per' clock names for NAND
  flash (25/31) and VIU (26/31) as well
- unbreak CAN operation for the period between introducing common clock
  support in the platform's clock driver and introducing common clock
  support in the CAN peripheral driver as well as providing clock specs
  in the device tree (provide clkdev aliases for SYS and REF)
- improve common clock support for CAN (devm_{get,put}_clk() calls,
  check enable() errors, keep a reference to used clocks, disable and
  put clocks after use)
- reworded several commit messages to better reflect the kind of change
  and because fixes were applied before adding common infrastructure
  support
- point to individual numbered patches of the series in the list of
  changes for v2 as well

changes in v2:
- cleanup of the UART (02/24) and SPI (01/24) clock handling before the
  introduction of common clock support for the platform, as incomplete
  clock handling becomes fatal or more dangerous later (which in turn
  changes the context of the device tree lookup only followup patch
  later)
- reordered the sequence of patches to keep the serial communication
  related parts together (UART, SPI, and PSC FIFO changes after common
  clock support was introduced, which have become 11-14/24 now)
- updated commit messages for the clock API use cleanup in the 

[PATCH v4 01/31] spi: mpc512x: cleanup clock API use

2013-08-06 Thread Gerhard Sittig
cleanup the MPC512x SoC's SPI master's use of the clock API
- get, prepare, and enable the MCLK during probe; disable, unprepare and
  put the MCLK upon remove; hold a reference to the clock over the
  period of use
- fetch MCLK rate (reference) once during probe and slightly reword BCLK
  (bitrate) determination to reduce redundancy as well as to not exceed
  the maximum text line length
- stick with the PPC_CLOCK 'psc%d_mclk' name for clock lookup, only
  switch to a fixed string later after device tree based clock lookup
  will have become available

Signed-off-by: Gerhard Sittig g...@denx.de
---
 drivers/spi/spi-mpc512x-psc.c |   48 +
 1 file changed, 30 insertions(+), 18 deletions(-)

diff --git a/drivers/spi/spi-mpc512x-psc.c b/drivers/spi/spi-mpc512x-psc.c
index 29fce6a..85581f3 100644
--- a/drivers/spi/spi-mpc512x-psc.c
+++ b/drivers/spi/spi-mpc512x-psc.c
@@ -38,7 +38,8 @@ struct mpc512x_psc_spi {
struct mpc512x_psc_fifo __iomem *fifo;
unsigned int irq;
u8 bits_per_word;
-   u32 mclk;
+   struct clk *clk_mclk;
+   u32 mclk_rate;
 
struct completion txisrdone;
 };
@@ -72,6 +73,7 @@ static void mpc512x_psc_spi_activate_cs(struct spi_device 
*spi)
struct mpc52xx_psc __iomem *psc = mps-psc;
u32 sicr;
u32 ccr;
+   int speed;
u16 bclkdiv;
 
sicr = in_be32(psc-sicr);
@@ -95,10 +97,10 @@ static void mpc512x_psc_spi_activate_cs(struct spi_device 
*spi)
 
ccr = in_be32(psc-ccr);
ccr = 0xFF00;
-   if (cs-speed_hz)
-   bclkdiv = (mps-mclk / cs-speed_hz) - 1;
-   else
-   bclkdiv = (mps-mclk / 100) - 1;/* default 1MHz */
+   speed = cs-speed_hz;
+   if (!speed)
+   speed = 100;/* default 1MHz */
+   bclkdiv = (mps-mclk_rate / speed) - 1;
 
ccr |= (((bclkdiv  0xff)  16) | (((bclkdiv  8)  0xff)  8));
out_be32(psc-ccr, ccr);
@@ -386,19 +388,11 @@ static int mpc512x_psc_spi_port_config(struct spi_master 
*master,
 {
struct mpc52xx_psc __iomem *psc = mps-psc;
struct mpc512x_psc_fifo __iomem *fifo = mps-fifo;
-   struct clk *spiclk;
-   int ret = 0;
-   char name[32];
u32 sicr;
u32 ccr;
+   int speed;
u16 bclkdiv;
 
-   sprintf(name, psc%d_mclk, master-bus_num);
-   spiclk = clk_get(master-dev, name);
-   clk_enable(spiclk);
-   mps-mclk = clk_get_rate(spiclk);
-   clk_put(spiclk);
-
/* Reset the PSC into a known state */
out_8(psc-command, MPC52xx_PSC_RST_RX);
out_8(psc-command, MPC52xx_PSC_RST_TX);
@@ -425,7 +419,8 @@ static int mpc512x_psc_spi_port_config(struct spi_master 
*master,
 
ccr = in_be32(psc-ccr);
ccr = 0xFF00;
-   bclkdiv = (mps-mclk / 100) - 1;/* default 1MHz */
+   speed = 100;/* default 1MHz */
+   bclkdiv = (mps-mclk_rate / speed) - 1;
ccr |= (((bclkdiv  0xff)  16) | (((bclkdiv  8)  0xff)  8));
out_be32(psc-ccr, ccr);
 
@@ -445,7 +440,7 @@ static int mpc512x_psc_spi_port_config(struct spi_master 
*master,
 
mps-bits_per_word = 8;
 
-   return ret;
+   return 0;
 }
 
 static irqreturn_t mpc512x_psc_spi_isr(int irq, void *dev_id)
@@ -479,6 +474,9 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 
regaddr,
struct spi_master *master;
int ret;
void *tempp;
+   int psc_num;
+   char clk_name[16];
+   struct clk *clk;
 
master = spi_alloc_master(dev, sizeof *mps);
if (master == NULL)
@@ -521,16 +519,29 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, 
u32 regaddr,
goto free_master;
init_completion(mps-txisrdone);
 
+   psc_num = master-bus_num;
+   snprintf(clk_name, sizeof(clk_name), psc%d_mclk, psc_num);
+   clk = devm_clk_get(dev, clk_name);
+   if (IS_ERR(clk))
+   goto free_irq;
+   ret = clk_prepare_enable(clk);
+   if (ret)
+   goto free_irq;
+   mps-clk_mclk = clk;
+   mps-mclk_rate = clk_get_rate(clk);
+
ret = mpc512x_psc_spi_port_config(master, mps);
if (ret  0)
-   goto free_irq;
+   goto free_clock;
 
ret = spi_register_master(master);
if (ret  0)
-   goto free_irq;
+   goto free_clock;
 
return ret;
 
+free_clock:
+   clk_disable_unprepare(mps-clk_mclk);
 free_irq:
free_irq(mps-irq, mps);
 free_master:
@@ -547,6 +558,7 @@ static int mpc512x_psc_spi_do_remove(struct device *dev)
struct mpc512x_psc_spi *mps = spi_master_get_devdata(master);
 
spi_unregister_master(master);
+   clk_disable_unprepare(mps-clk_mclk);
free_irq(mps-irq, mps);
if (mps-psc)
iounmap(mps-psc);
-- 
1.7.10.4

___
Linuxppc-dev mailing list

[PATCH v4 02/31] serial: mpc512x: cleanup clock API use

2013-08-06 Thread Gerhard Sittig
cleanup the clock API use of the UART driver which is shared among the
MPC512x and the MPC5200 platforms
- get, prepare, and enable the MCLK during port allocation; disable,
  unprepare and put the MCLK upon port release; hold a reference to the
  clock over the period of use; check for and propagate enable errors
- fix a buffer overflow for clock names with two digit PSC index numbers
- stick with the PPC_CLOCK 'psc%d_mclk' name for clock lookup, only
  switch to a fixed string later after device tree based clock lookup
  will have become available

to achieve support for MPC512x which is neutral to MPC5200, the
modification was done as follows
- introduce clock alloc and clock release routines in addition to
  the previous clock enable/disable routine in the psc_ops struct
- make the clock allocation a part of the port request (resource
  allocation), and make clock release a part of the port release, such
  that essential resources get allocated early
- just enable/disable the clock from within the .clock() callback
  without any allocation or preparation as the former implementation
  did, since this routine is called from within the startup and shutdown
  callbacks
- all of the above remains a NOP for the MPC5200 platform (no callbacks
  are provided on that platform)
- implementation note: the clock gets enabled upon allocation already
  just in case the clock is not only required for bitrate generation but
  for register access as well

Signed-off-by: Gerhard Sittig g...@denx.de
---
 drivers/tty/serial/mpc52xx_uart.c |   98 ++---
 1 file changed, 81 insertions(+), 17 deletions(-)

diff --git a/drivers/tty/serial/mpc52xx_uart.c 
b/drivers/tty/serial/mpc52xx_uart.c
index e1280a2..5be1df3 100644
--- a/drivers/tty/serial/mpc52xx_uart.c
+++ b/drivers/tty/serial/mpc52xx_uart.c
@@ -107,6 +107,8 @@ struct psc_ops {
unsigned int(*set_baudrate)(struct uart_port *port,
struct ktermios *new,
struct ktermios *old);
+   int (*clock_alloc)(struct uart_port *port);
+   void(*clock_relse)(struct uart_port *port);
int (*clock)(struct uart_port *port, int enable);
int (*fifoc_init)(void);
void(*fifoc_uninit)(void);
@@ -616,31 +618,73 @@ static irqreturn_t mpc512x_psc_handle_irq(struct 
uart_port *port)
return IRQ_NONE;
 }
 
-static int mpc512x_psc_clock(struct uart_port *port, int enable)
+static struct clk *psc_mclk_clk[MPC52xx_PSC_MAXNUM];
+
+/* called from within the .request_port() callback (allocation) */
+static int mpc512x_psc_alloc_clock(struct uart_port *port)
 {
-   struct clk *psc_clk;
int psc_num;
-   char clk_name[10];
+   char clk_name[16];
+   struct clk *clk;
+   int err;
+
+   psc_num = (port-mapbase  0xf00)  8;
+   snprintf(clk_name, sizeof(clk_name), psc%d_mclk, psc_num);
+   clk = devm_clk_get(port-dev, clk_name);
+   if (IS_ERR(clk)) {
+   dev_err(port-dev, Failed to get MCLK!\n);
+   return PTR_ERR(clk);
+   }
+   err = clk_prepare_enable(clk);
+   if (err) {
+   dev_err(port-dev, Failed to enable MCLK!\n);
+   return err;
+   }
+   psc_mclk_clk[psc_num] = clk;
+   return 0;
+}
+
+/* called from within the .release_port() callback (release) */
+static void mpc512x_psc_relse_clock(struct uart_port *port)
+{
+   int psc_num;
+   struct clk *clk;
+
+   psc_num = (port-mapbase  0xf00)  8;
+   clk = psc_mclk_clk[psc_num];
+   if (clk) {
+   clk_disable_unprepare(clk);
+   psc_mclk_clk[psc_num] = NULL;
+   }
+}
+
+/* implementation of the .clock() callback (enable/disable) */
+static int mpc512x_psc_endis_clock(struct uart_port *port, int enable)
+{
+   int psc_num;
+   struct clk *psc_clk;
+   int ret;
 
if (uart_console(port))
return 0;
 
psc_num = (port-mapbase  0xf00)  8;
-   snprintf(clk_name, sizeof(clk_name), psc%d_mclk, psc_num);
-   psc_clk = clk_get(port-dev, clk_name);
-   if (IS_ERR(psc_clk)) {
+   psc_clk = psc_mclk_clk[psc_num];
+   if (!psc_clk) {
dev_err(port-dev, Failed to get PSC clock entry!\n);
return -ENODEV;
}
 
-   dev_dbg(port-dev, %s %sable\n, clk_name, enable ? en : dis);
-
-   if (enable)
-   clk_enable(psc_clk);
-   else
+   dev_dbg(port-dev, mclk %sable\n, enable ? en : dis);
+   if (enable) {
+   ret = clk_enable(psc_clk);
+   if (ret)
+   dev_err(port-dev, Failed to enable MCLK!\n);
+   return ret;
+   } else {
clk_disable(psc_clk);
-
-   return 0;
+   return 0;
+   }
 }
 
 static void mpc512x_psc_get_irq(struct uart_port *port, struct device_node *np)
@@ -873,7 

[PATCH v4 04/31] mtd: mpc5121_nfc: cleanup clock API use

2013-08-06 Thread Gerhard Sittig
use devm_clk_get() for automatic put after device close, check for and
propagate errors when enabling clocks, need to prepare clocks before
they can get enabled, adjust error code paths to correctly balance
get/put and prepare/unprepare and enable/disable calls

Signed-off-by: Gerhard Sittig g...@denx.de
---
 drivers/mtd/nand/mpc5121_nfc.c |   21 -
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/nand/mpc5121_nfc.c b/drivers/mtd/nand/mpc5121_nfc.c
index 3c9cdcb..3c60a00 100644
--- a/drivers/mtd/nand/mpc5121_nfc.c
+++ b/drivers/mtd/nand/mpc5121_nfc.c
@@ -617,10 +617,8 @@ static void mpc5121_nfc_free(struct device *dev, struct 
mtd_info *mtd)
struct nand_chip *chip = mtd-priv;
struct mpc5121_nfc_prv *prv = chip-priv;
 
-   if (prv-clk) {
-   clk_disable(prv-clk);
-   clk_put(prv-clk);
-   }
+   if (prv-clk)
+   clk_disable_unprepare(prv-clk);
 
if (prv-csreg)
iounmap(prv-csreg);
@@ -629,6 +627,7 @@ static void mpc5121_nfc_free(struct device *dev, struct 
mtd_info *mtd)
 static int mpc5121_nfc_probe(struct platform_device *op)
 {
struct device_node *rootnode, *dn = op-dev.of_node;
+   struct clk *clk;
struct device *dev = op-dev;
struct mpc5121_nfc_prv *prv;
struct resource res;
@@ -730,14 +729,18 @@ static int mpc5121_nfc_probe(struct platform_device *op)
of_node_put(rootnode);
 
/* Enable NFC clock */
-   prv-clk = clk_get(dev, nfc_clk);
-   if (IS_ERR(prv-clk)) {
+   clk = devm_clk_get(dev, nfc_clk);
+   if (IS_ERR(clk)) {
dev_err(dev, Unable to acquire NFC clock!\n);
-   retval = PTR_ERR(prv-clk);
+   retval = PTR_ERR(clk);
goto error;
}
-
-   clk_enable(prv-clk);
+   retval = clk_prepare_enable(clk);
+   if (retval) {
+   dev_err(dev, Unable to enable NFC clock!\n);
+   goto error;
+   }
+   prv-clk = clk;
 
/* Reset NAND Flash controller */
nfc_set(mtd, NFC_CONFIG1, NFC_RESET);
-- 
1.7.10.4

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v4 03/31] USB: fsl-mph-dr-of: cleanup clock API use

2013-08-06 Thread Gerhard Sittig
use devm_get_clk() for automatic put upon device close, check for and
propagate errors when enabling clocks, must prepare clocks before they
can get enabled, unprepare after disable

Signed-off-by: Gerhard Sittig g...@denx.de
---
 drivers/usb/host/fsl-mph-dr-of.c |   16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/host/fsl-mph-dr-of.c b/drivers/usb/host/fsl-mph-dr-of.c
index 11e0b79..b8a1866 100644
--- a/drivers/usb/host/fsl-mph-dr-of.c
+++ b/drivers/usb/host/fsl-mph-dr-of.c
@@ -260,6 +260,7 @@ int fsl_usb2_mpc5121_init(struct platform_device *pdev)
 {
struct fsl_usb2_platform_data *pdata = pdev-dev.platform_data;
struct clk *clk;
+   int err;
char clk_name[10];
int base, clk_num;
 
@@ -272,13 +273,16 @@ int fsl_usb2_mpc5121_init(struct platform_device *pdev)
return -ENODEV;
 
snprintf(clk_name, sizeof(clk_name), usb%d_clk, clk_num);
-   clk = clk_get(pdev-dev, clk_name);
+   clk = devm_clk_get(pdev-dev, clk_name);
if (IS_ERR(clk)) {
dev_err(pdev-dev, failed to get clk\n);
return PTR_ERR(clk);
}
-
-   clk_enable(clk);
+   err = clk_prepare_enable(clk);
+   if (err) {
+   dev_err(pdev-dev, failed to enable clk\n);
+   return err;
+   }
pdata-clk = clk;
 
if (pdata-phy_mode == FSL_USB2_PHY_UTMI_WIDE) {
@@ -302,10 +306,8 @@ static void fsl_usb2_mpc5121_exit(struct platform_device 
*pdev)
 
pdata-regs = NULL;
 
-   if (pdata-clk) {
-   clk_disable(pdata-clk);
-   clk_put(pdata-clk);
-   }
+   if (pdata-clk)
+   clk_disable_unprepare(pdata-clk);
 }
 
 static struct fsl_usb2_platform_data fsl_usb2_mpc5121_pd = {
-- 
1.7.10.4

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v4 05/31] [media] fsl-viu: cleanup clock API use

2013-08-06 Thread Gerhard Sittig
use devm_clk_get() for automatic put after device close, check for and
propagate errors when enabling clocks, need to prepare clocks before
they can get enabled, adjust code paths to correctly balance get/put and
prepare/unprepare and enable/disable calls

Signed-off-by: Gerhard Sittig g...@denx.de
---
 drivers/media/platform/fsl-viu.c |   23 +--
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/drivers/media/platform/fsl-viu.c b/drivers/media/platform/fsl-viu.c
index 221ec42..fe9898c 100644
--- a/drivers/media/platform/fsl-viu.c
+++ b/drivers/media/platform/fsl-viu.c
@@ -1485,6 +1485,7 @@ static int viu_of_probe(struct platform_device *op)
struct viu_reg __iomem *viu_regs;
struct i2c_adapter *ad;
int ret, viu_irq;
+   struct clk *clk;
 
ret = of_address_to_resource(op-dev.of_node, 0, r);
if (ret) {
@@ -1577,14 +1578,18 @@ static int viu_of_probe(struct platform_device *op)
}
 
/* enable VIU clock */
-   viu_dev-clk = clk_get(op-dev, viu_clk);
-   if (IS_ERR(viu_dev-clk)) {
-   dev_err(op-dev, failed to find the clock module!\n);
-   ret = -ENODEV;
+   clk = devm_clk_get(op-dev, viu_clk);
+   if (IS_ERR(clk)) {
+   dev_err(op-dev, failed to lookup the clock!\n);
+   ret = PTR_ERR(clk);
+   goto err_clk;
+   }
+   ret = clk_prepare_enable(clk);
+   if (ret) {
+   dev_err(op-dev, failed to enable the clock!\n);
goto err_clk;
-   } else {
-   clk_enable(viu_dev-clk);
}
+   viu_dev-clk = clk;
 
/* reset VIU module */
viu_reset(viu_dev-vr);
@@ -1602,8 +1607,7 @@ static int viu_of_probe(struct platform_device *op)
return ret;
 
 err_irq:
-   clk_disable(viu_dev-clk);
-   clk_put(viu_dev-clk);
+   clk_disable_unprepare(viu_dev-clk);
 err_clk:
video_unregister_device(viu_dev-vdev);
 err_vdev:
@@ -1626,8 +1630,7 @@ static int viu_of_remove(struct platform_device *op)
free_irq(dev-irq, (void *)dev);
irq_dispose_mapping(dev-irq);
 
-   clk_disable(dev-clk);
-   clk_put(dev-clk);
+   clk_disable_unprepare(dev-clk);
 
video_unregister_device(dev-vdev);
i2c_put_adapter(client-adapter);
-- 
1.7.10.4

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [PATCH 3/8] Add all memory via sysfs probe interface at once

2013-08-06 Thread Nathan Fontenot
On 08/04/2013 10:13 PM, Michael Ellerman wrote:
 On Fri, Aug 02, 2013 at 02:13:06PM -0500, Nathan Fontenot wrote:
 On 08/01/2013 09:32 PM, Michael Ellerman wrote:
 On Wed, Jul 24, 2013 at 01:37:47PM -0500, Nathan Fontenot wrote:
 When doing memory hot add via the 'probe' interface in sysfs we do not
 need to loop through and add memory one section at a time. I think this
 was originally done for powerpc, but is not needed. This patch removes
 the loop and just calls add_memory for all of the memory to be added.

 Looks like memory hot add is supported on ia64, x86, sh, powerpc and
 s390. Have you tested on any?

 I have tested on powerpc. I would love to say I tested on the other
 platforms... but I haven't.  I should be able to get a x86 box to test
 on but the other architectures may not be possible.
 
 Is the rest of your series dependent on this patch? Or is it sort of
 incidental?
 
 If possible it might be worth pulling this one out and sticking it in
 linux-next for a cycle to give people a chance to test it. Unless
 someone who knows the code well is comfortable with it.
 

I am planning on pulling the first two patches and sending them out
separate from the patch set since they are really independent of the
rest of the patch series.

The remaining code I will send out for review and inclusion in
linux-next so it can have the proper test time as you mentioned.

-Nathan

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v4 06/31] i2c: mpc: cleanup clock API use

2013-08-06 Thread Gerhard Sittig
make the MPC I2C driver get, prepare and enable the peripheral clock
during probe ('per' for access to the peripheral's registers); disable
and unprepare the clock upon remove(), put is done by the devm approach;
hold a reference to the clock over the period of use

clock lookup is non-fatal in this implementation as not all platforms
may provide clock specs in their device tree, but enable errors for
specified clocks are considered fatal

Signed-off-by: Gerhard Sittig g...@denx.de
---
 drivers/i2c/busses/i2c-mpc.c |   24 
 1 file changed, 24 insertions(+)

diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 7607dc0..4b00dd0 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -21,6 +21,7 @@
 #include linux/of_i2c.h
 #include linux/slab.h
 
+#include linux/clk.h
 #include linux/io.h
 #include linux/fsl_devices.h
 #include linux/i2c.h
@@ -67,6 +68,7 @@ struct mpc_i2c {
 #ifdef CONFIG_PM
u8 fdr, dfsrr;
 #endif
+   struct clk *clk_per;
 };
 
 struct mpc_i2c_divider {
@@ -623,6 +625,8 @@ static int fsl_i2c_probe(struct platform_device *op)
u32 clock = MPC_I2C_CLOCK_LEGACY;
int result = 0;
int plen;
+   struct clk *clk;
+   int err;
 
match = of_match_device(mpc_i2c_of_match, op-dev);
if (!match)
@@ -653,6 +657,21 @@ static int fsl_i2c_probe(struct platform_device *op)
}
}
 
+   /*
+* enable clock for the I2C peripheral (non fatal),
+* keep a reference upon successful allocation
+*/
+   clk = devm_clk_get(op-dev, per);
+   if (!IS_ERR(clk)) {
+   err = clk_prepare_enable(clk);
+   if (err) {
+   dev_err(op-dev, failed to enable clock\n);
+   goto fail_request;
+   } else {
+   i2c-clk_per = clk;
+   }
+   }
+
if (of_get_property(op-dev.of_node, fsl,preserve-clocking, NULL)) {
clock = MPC_I2C_CLOCK_PRESERVE;
} else {
@@ -696,6 +715,8 @@ static int fsl_i2c_probe(struct platform_device *op)
return result;
 
  fail_add:
+   if (i2c-clk_per)
+   clk_disable_unprepare(i2c-clk_per);
free_irq(i2c-irq, i2c);
  fail_request:
irq_dispose_mapping(i2c-irq);
@@ -711,6 +732,9 @@ static int fsl_i2c_remove(struct platform_device *op)
 
i2c_del_adapter(i2c-adap);
 
+   if (i2c-clk_per)
+   clk_disable_unprepare(i2c-clk_per);
+
if (i2c-irq)
free_irq(i2c-irq, i2c);
 
-- 
1.7.10.4

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v4 07/31] fs_enet: silence a build warning (unused variable)

2013-08-06 Thread Gerhard Sittig

Signed-off-by: Gerhard Sittig g...@denx.de
---
 drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c |1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c 
b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
index 8de53a1..c04eb3a 100644
--- a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
+++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
@@ -583,7 +583,6 @@ static struct sk_buff *tx_skb_align_workaround(struct 
net_device *dev,
   struct sk_buff *skb)
 {
struct sk_buff *new_skb;
-   struct fs_enet_private *fep = netdev_priv(dev);
 
/* Alloc new skb */
new_skb = netdev_alloc_skb(dev, skb-len + 4);
-- 
1.7.10.4

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v4 08/31] fs_enet: cleanup clock API use

2013-08-06 Thread Gerhard Sittig
make the Freescale ethernet driver get, prepare and enable the FEC clock
during probe(); disable and unprepare the clock upon remove(), put is
done by the devm approach; hold a reference to the clock over the period
of use

clock lookup is non-fatal as not all platforms provide clock specs in
their device tree; failure to enable specified clocks is fatal

Signed-off-by: Gerhard Sittig g...@denx.de
---
 .../net/ethernet/freescale/fs_enet/fs_enet-main.c  |   20 
 include/linux/fs_enet_pd.h |3 +++
 2 files changed, 23 insertions(+)

diff --git a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c 
b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
index c04eb3a..6b60582 100644
--- a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
+++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
@@ -999,6 +999,8 @@ static int fs_enet_probe(struct platform_device *ofdev)
struct fs_enet_private *fep;
struct fs_platform_info *fpi;
const u32 *data;
+   struct clk *clk;
+   int err;
const u8 *mac_addr;
const char *phy_connection_type;
int privsize, len, ret = -ENODEV;
@@ -1036,6 +1038,20 @@ static int fs_enet_probe(struct platform_device *ofdev)
fpi-use_rmii = 1;
}
 
+   /* make clock lookup non-fatal (the driver is shared among platforms),
+* but require enable to succeed when a clock was specified/found,
+* keep a reference to the clock upon successful acquisition
+*/
+   clk = devm_clk_get(ofdev-dev, per);
+   if (!IS_ERR(clk)) {
+   err = clk_prepare_enable(clk);
+   if (err) {
+   ret = err;
+   goto out_free_fpi;
+   }
+   fpi-clk_per = clk;
+   }
+
privsize = sizeof(*fep) +
   sizeof(struct sk_buff **) *
   (fpi-rx_ring + fpi-tx_ring);
@@ -1107,6 +1123,8 @@ out_free_dev:
free_netdev(ndev);
 out_put:
of_node_put(fpi-phy_node);
+   if (fpi-clk_per)
+   clk_disable_unprepare(fpi-clk_per);
 out_free_fpi:
kfree(fpi);
return ret;
@@ -1123,6 +1141,8 @@ static int fs_enet_remove(struct platform_device *ofdev)
fep-ops-cleanup_data(ndev);
dev_set_drvdata(fep-dev, NULL);
of_node_put(fep-fpi-phy_node);
+   if (fep-fpi-clk_per)
+   clk_disable_unprepare(fep-fpi-clk_per);
free_netdev(ndev);
return 0;
 }
diff --git a/include/linux/fs_enet_pd.h b/include/linux/fs_enet_pd.h
index 51b7934..a978d0d 100644
--- a/include/linux/fs_enet_pd.h
+++ b/include/linux/fs_enet_pd.h
@@ -16,6 +16,7 @@
 #ifndef FS_ENET_PD_H
 #define FS_ENET_PD_H
 
+#include linux/clk.h
 #include linux/string.h
 #include linux/of_mdio.h
 #include asm/types.h
@@ -142,6 +143,8 @@ struct fs_platform_info {
 
int use_rmii;   /* use RMII mode   */
int has_phy;/* if the network is phy container as well...*/
+
+   struct clk *clk_per;/* 'per' clock for register access */
 };
 struct fs_mii_fec_platform_info {
u32 irq[32];
-- 
1.7.10.4

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


  1   2   >