All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v3 00/11] sunxi: PSCI implementation rewrite in C
@ 2016-06-07  2:54 Chen-Yu Tsai
  2016-06-07  2:54 ` [U-Boot] [PATCH v3 01/11] ARM: PSCI: use only r0 and r3 in psci_get_cpu_stack_top() Chen-Yu Tsai
                   ` (11 more replies)
  0 siblings, 12 replies; 20+ messages in thread
From: Chen-Yu Tsai @ 2016-06-07  2:54 UTC (permalink / raw)
  To: u-boot

Hi everyone,

This series rewrites the Allwinner/sunxi PSCI implementation in C, to make
it easier to maintain and extend for the currently unsupported multi-cluster
SoCs. The SMP code in the BSP kernels are in C. Having the PSCI code in C
as well will make it easier to work on.

To be able to convert the platform bits to C, some common PSCI functions
have to be fixed up according to the ARM calling conventions. Function
declarations are also needed.

This series is based on sunxi/next. Parts of it will likely conflict with
the effort to support PSCI 1.0 on the Freescale LS102xA.

Changes since v2:

  - Add missing __secure attributes to helpers.

  - Fix __mdelay calculation, and avoid calling __udivsi3.

  - Add ISB at end of __mdelay, after disabling timer.

  - Move ISB inside cp15_write_scr helper.

  - Fix "End of interrupt" comment.

  - __ARMV7_ALLOCATE_SECURE_STACK -> __ARMV7_PSCI_STACK_IN_RAM

  - Split out power sequencing into more helpers  as Marc suggested.

  - Drop linux/compiler.h include from psci.h


Changes since v1:

  - Add and use helpers for accessing co-processors.

  - Split out power gating/clamping into helpers based on sun7i and the rest.

  - Drop secure section attribute on PSCI common function declarations.

  - Add packed attribute to PRCM and CPUCFG register struct definitions.

  - Only allocate PSCI stack space when PSCI is put in main memory.

  - Make it clear that PSCI stack overwriting normal memory only happens
    when PSCI is put in main memory.

  - Drop "cc" from clobber list.

  - Add comments explaining the need to preserve registers across
    psci_arch_init, and preserve r0 instead of setting it to 0.

Patch 1 fixes up psci_get_cpu_stack_top.

Patch 2 fixes up the PSCI version of v7_flush_dcache_all.

Patch 3 adds function declarations for some of the common PSCI functions.

Patch 4 fixes issues with reserving memory for the secure section.

Patch 5 unifies the CPUCFG_BASE macro names for various sunxi platforms.

Patch 6 adds packed attribute to struct sunxi_prcm_reg.

Patch 7 adds a missing header to cpucfg.h

Patch 8 groups cpu core related controls together into one struct per core.
This makes it straightforward to access the controls by the cpu index.

Patch 9 adds some missing fields to cpucfg, which were used in the assembly
code.

Patch 10 adds the base address for the GIC.

Patch 11 is the new PSCI implementation in C. Almost all of the code is
converted, with the exception of initial setup of the stack.


Regards
ChenYu


Chen-Yu Tsai (11):
  ARM: PSCI: use only r0 and r3 in psci_get_cpu_stack_top()
  ARM: PSCI: save and restore clobbered registers in v7_flush_dcache_all
  ARM: PSCI: export common PSCI function declarations for C code
  ARM: allocate extra space for PSCI stack in secure section during link
    phase
  sunxi: Make CPUCFG_BASE macro names the same across families
  sunxi: Add packed attribute to struct sunxi_prcm_reg
  sunxi: Add missing linux/types.h header for cpucfg_sun6i.h
  sunxi: Group cpu core related controls together
  sunxi: Add CPUCFG debug lock and sun7i cpu power controls
  sunxi: Add base address for GIC
  sunxi: Add PSCI implementation in C

 arch/arm/cpu/armv7/psci.S                          |  20 +-
 arch/arm/cpu/armv7/sunxi/Makefile                  |   7 +-
 arch/arm/cpu/armv7/sunxi/psci.c                    | 273 +++++++++++++++++++++
 arch/arm/cpu/armv7/sunxi/psci_head.S               |  66 +++++
 arch/arm/cpu/armv7/sunxi/psci_sun6i.S              | 262 --------------------
 arch/arm/cpu/armv7/sunxi/psci_sun7i.S              | 237 ------------------
 arch/arm/cpu/u-boot.lds                            |   7 +
 arch/arm/include/asm/arch-sunxi/cpu_sun4i.h        |  17 +-
 .../asm/arch-sunxi/{cpucfg_sun6i.h => cpucfg.h}    |  41 ++--
 arch/arm/include/asm/arch-sunxi/prcm.h             |  10 +-
 arch/arm/include/asm/psci.h                        |   7 +
 11 files changed, 407 insertions(+), 540 deletions(-)
 create mode 100644 arch/arm/cpu/armv7/sunxi/psci.c
 create mode 100644 arch/arm/cpu/armv7/sunxi/psci_head.S
 delete mode 100644 arch/arm/cpu/armv7/sunxi/psci_sun6i.S
 delete mode 100644 arch/arm/cpu/armv7/sunxi/psci_sun7i.S
 rename arch/arm/include/asm/arch-sunxi/{cpucfg_sun6i.h => cpucfg.h} (67%)

-- 
2.8.1

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [U-Boot] [PATCH v3 01/11] ARM: PSCI: use only r0 and r3 in psci_get_cpu_stack_top()
  2016-06-07  2:54 [U-Boot] [PATCH v3 00/11] sunxi: PSCI implementation rewrite in C Chen-Yu Tsai
@ 2016-06-07  2:54 ` Chen-Yu Tsai
  2016-06-07  2:54 ` [U-Boot] [PATCH v3 02/11] ARM: PSCI: save and restore clobbered registers in v7_flush_dcache_all Chen-Yu Tsai
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Chen-Yu Tsai @ 2016-06-07  2:54 UTC (permalink / raw)
  To: u-boot

For psci_get_cpu_stack_top() to be usable in C code, it must adhere to
the ARM calling conventions. Since it could be called when the stack
is still unavailable, and the entry code to linux also expects r1 and
r2 to remain unchanged, stick to r0 and r3.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 arch/arm/cpu/armv7/psci.S | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/arch/arm/cpu/armv7/psci.S b/arch/arm/cpu/armv7/psci.S
index 87c0c0b6f5eb..cdd001fe3fb0 100644
--- a/arch/arm/cpu/armv7/psci.S
+++ b/arch/arm/cpu/armv7/psci.S
@@ -196,15 +196,15 @@ ENDPROC(psci_cpu_off_common)
 
 @ expects CPU ID in r0 and returns stack top in r0
 ENTRY(psci_get_cpu_stack_top)
-	mov	r5, #0x400			@ 1kB of stack per CPU
-	mul	r0, r0, r5
-
-	ldr	r5, =psci_text_end		@ end of monitor text
-	add	r5, r5, #0x2000			@ Skip two pages
-	lsr	r5, r5, #12			@ Align to start of page
-	lsl	r5, r5, #12
-	sub	r5, r5, #4			@ reserve 1 word for target PC
-	sub	r0, r5, r0			@ here's our stack!
+	mov	r3, #0x400			@ 1kB of stack per CPU
+	mul	r0, r0, r3
+
+	ldr	r3, =psci_text_end		@ end of monitor text
+	add	r3, r3, #0x2000			@ Skip two pages
+	lsr	r3, r3, #12			@ Align to start of page
+	lsl	r3, r3, #12
+	sub	r3, r3, #4			@ reserve 1 word for target PC
+	sub	r0, r3, r0			@ here's our stack!
 
 	bx	lr
 ENDPROC(psci_get_cpu_stack_top)
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [U-Boot] [PATCH v3 02/11] ARM: PSCI: save and restore clobbered registers in v7_flush_dcache_all
  2016-06-07  2:54 [U-Boot] [PATCH v3 00/11] sunxi: PSCI implementation rewrite in C Chen-Yu Tsai
  2016-06-07  2:54 ` [U-Boot] [PATCH v3 01/11] ARM: PSCI: use only r0 and r3 in psci_get_cpu_stack_top() Chen-Yu Tsai
@ 2016-06-07  2:54 ` Chen-Yu Tsai
  2016-06-07  2:54 ` [U-Boot] [PATCH v3 03/11] ARM: PSCI: export common PSCI function declarations for C code Chen-Yu Tsai
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Chen-Yu Tsai @ 2016-06-07  2:54 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 arch/arm/cpu/armv7/psci.S | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/cpu/armv7/psci.S b/arch/arm/cpu/armv7/psci.S
index cdd001fe3fb0..ab408378fcae 100644
--- a/arch/arm/cpu/armv7/psci.S
+++ b/arch/arm/cpu/armv7/psci.S
@@ -110,6 +110,7 @@ ENDPROC(psci_get_cpu_id)
 
 /* Imported from Linux kernel */
 LENTRY(v7_flush_dcache_all)
+	stmfd	sp!, {r4-r5, r7, r9-r11, lr}
 	dmb					@ ensure ordering with previous memory accesses
 	mrc	p15, 1, r0, c0, c0, 1		@ read clidr
 	ands	r3, r0, #0x7000000		@ extract loc from clidr
@@ -153,6 +154,7 @@ finished:
 	mcr	p15, 2, r10, c0, c0, 0		@ select current cache level in cssr
 	dsb	st
 	isb
+	ldmfd	sp!, {r4-r5, r7, r9-r11, lr}
 	bx	lr
 ENDPROC(v7_flush_dcache_all)
 
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [U-Boot] [PATCH v3 03/11] ARM: PSCI: export common PSCI function declarations for C code
  2016-06-07  2:54 [U-Boot] [PATCH v3 00/11] sunxi: PSCI implementation rewrite in C Chen-Yu Tsai
  2016-06-07  2:54 ` [U-Boot] [PATCH v3 01/11] ARM: PSCI: use only r0 and r3 in psci_get_cpu_stack_top() Chen-Yu Tsai
  2016-06-07  2:54 ` [U-Boot] [PATCH v3 02/11] ARM: PSCI: save and restore clobbered registers in v7_flush_dcache_all Chen-Yu Tsai
@ 2016-06-07  2:54 ` Chen-Yu Tsai
  2016-06-07  2:54 ` [U-Boot] [PATCH v3 04/11] ARM: allocate extra space for PSCI stack in secure section during link phase Chen-Yu Tsai
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Chen-Yu Tsai @ 2016-06-07  2:54 UTC (permalink / raw)
  To: u-boot

Some common PSCI functions are written in assembly, but it should be
possible to use them from C code.

Add function declarations for C code to consume.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 arch/arm/include/asm/psci.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
index 128a606444fe..f6a9ff8bd876 100644
--- a/arch/arm/include/asm/psci.h
+++ b/arch/arm/include/asm/psci.h
@@ -33,6 +33,13 @@
 #define ARM_PSCI_RET_DENIED		(-3)
 
 #ifndef __ASSEMBLY__
+#include <asm/types.h>
+
+void psci_cpu_entry(void);
+u32 psci_get_cpu_id(void);
+u32 psci_get_cpu_stack_top(int cpu);
+void psci_cpu_off_common(void);
+
 int psci_update_dt(void *fdt);
 void psci_board_init(void);
 #endif /* ! __ASSEMBLY__ */
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [U-Boot] [PATCH v3 04/11] ARM: allocate extra space for PSCI stack in secure section during link phase
  2016-06-07  2:54 [U-Boot] [PATCH v3 00/11] sunxi: PSCI implementation rewrite in C Chen-Yu Tsai
                   ` (2 preceding siblings ...)
  2016-06-07  2:54 ` [U-Boot] [PATCH v3 03/11] ARM: PSCI: export common PSCI function declarations for C code Chen-Yu Tsai
@ 2016-06-07  2:54 ` Chen-Yu Tsai
  2016-06-07  2:54 ` [U-Boot] [PATCH v3 05/11] sunxi: Make CPUCFG_BASE macro names the same across families Chen-Yu Tsai
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Chen-Yu Tsai @ 2016-06-07  2:54 UTC (permalink / raw)
  To: u-boot

The PSCI implementation expects at most 2 pages worth of space reserved
at the end of the secure section for its stacks. If PSCI is relocated to
secure SRAM, then everything is fine. If no secure SRAM is available,
and PSCI remains in main memory, the reserved memory space doesn't cover
the space used by the stack.

If one accesses PSCI after Linux has fully booted, the memory that should
have been reserved for the PSCI stacks may have been used by the kernel
or userspace, and would be corrupted. Observed after effects include the
system hanging or telinit core dumping when trying to reboot. It seems
the init process gets hit the most on my test bed.

This fix allocates the space used by the PSCI stacks in the secure
section by skipping pages in the linker script, but only when there is
no secure SRAM, to avoid bloating the binary.

This fix is only a stop gap. It would be better to rework the stack
allocation mechanism, maybe with proper usage of CONFIG_ macros and an
explicit symbol.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>

squash! ARM: allocate extra space for PSCI stack in secure section during link phase
---
 arch/arm/cpu/u-boot.lds | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/cpu/u-boot.lds b/arch/arm/cpu/u-boot.lds
index cfab8b041234..1769b6ea881b 100644
--- a/arch/arm/cpu/u-boot.lds
+++ b/arch/arm/cpu/u-boot.lds
@@ -50,6 +50,7 @@ SECTIONS
 
 #ifndef CONFIG_ARMV7_SECURE_BASE
 #define CONFIG_ARMV7_SECURE_BASE
+#define __ARMV7_PSCI_STACK_IN_RAM
 #endif
 
 	.__secure_start : {
@@ -67,6 +68,12 @@ SECTIONS
 		SIZEOF(.__secure_start) +
 		SIZEOF(.secure_text);
 
+#ifdef __ARMV7_PSCI_STACK_IN_RAM
+	/* Align to page boundary and skip 2 pages */
+	. = (. & ~ 0xfff) + 0x2000;
+#undef __ARMV7_PSCI_STACK_IN_RAM
+#endif
+
 	__secure_end_lma = .;
 	.__secure_end : AT(__secure_end_lma) {
 		*(.__secure_end)
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [U-Boot] [PATCH v3 05/11] sunxi: Make CPUCFG_BASE macro names the same across families
  2016-06-07  2:54 [U-Boot] [PATCH v3 00/11] sunxi: PSCI implementation rewrite in C Chen-Yu Tsai
                   ` (3 preceding siblings ...)
  2016-06-07  2:54 ` [U-Boot] [PATCH v3 04/11] ARM: allocate extra space for PSCI stack in secure section during link phase Chen-Yu Tsai
@ 2016-06-07  2:54 ` Chen-Yu Tsai
  2016-06-07  2:54 ` [U-Boot] [PATCH v3 06/11] sunxi: Add packed attribute to struct sunxi_prcm_reg Chen-Yu Tsai
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Chen-Yu Tsai @ 2016-06-07  2:54 UTC (permalink / raw)
  To: u-boot

Use SUNXI_CPUCFG_BASE across all families. This makes writing common
PSCI code easier.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 arch/arm/cpu/armv7/sunxi/psci_sun6i.S       | 16 ++++++++--------
 arch/arm/cpu/armv7/sunxi/psci_sun7i.S       |  8 ++++----
 arch/arm/include/asm/arch-sunxi/cpu_sun4i.h | 15 +++++++++++++--
 3 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/arch/arm/cpu/armv7/sunxi/psci_sun6i.S b/arch/arm/cpu/armv7/sunxi/psci_sun6i.S
index 90b5bfd35947..9752550dea35 100644
--- a/arch/arm/cpu/armv7/sunxi/psci_sun6i.S
+++ b/arch/arm/cpu/armv7/sunxi/psci_sun6i.S
@@ -73,8 +73,8 @@ psci_fiq_enter:
 	lsr	r9, r9, #10
 	and	r9, r9, #0xf
 
-	movw	r8, #(SUN6I_CPUCFG_BASE & 0xffff)
-	movt	r8, #(SUN6I_CPUCFG_BASE >> 16)
+	movw	r8, #(SUNXI_CPUCFG_BASE & 0xffff)
+	movt	r8, #(SUNXI_CPUCFG_BASE >> 16)
 
 	@ Wait for the core to enter WFI
 	lsl	r11, r9, #6		@ x64
@@ -114,8 +114,8 @@ psci_fiq_enter:
 	str	r10, [r12, #0x140]
 #endif
 
-	movw	r8, #(SUN6I_CPUCFG_BASE & 0xffff)
-	movt	r8, #(SUN6I_CPUCFG_BASE >> 16)
+	movw	r8, #(SUNXI_CPUCFG_BASE & 0xffff)
+	movt	r8, #(SUNXI_CPUCFG_BASE >> 16)
 
 	@ Unlock CPU
 	ldr	r10, [r8, #0x1e4]
@@ -139,8 +139,8 @@ psci_cpu_on:
 	str	r2, [r0]		@ store target PC at stack top
 	dsb
 
-	movw	r0, #(SUN6I_CPUCFG_BASE & 0xffff)
-	movt	r0, #(SUN6I_CPUCFG_BASE >> 16)
+	movw	r0, #(SUNXI_CPUCFG_BASE & 0xffff)
+	movt	r0, #(SUNXI_CPUCFG_BASE >> 16)
 
 	@ CPU mask
 	and	r1, r1, #3	@ only care about first cluster
@@ -189,8 +189,8 @@ psci_cpu_on:
 	str	r6, [r0, #0x100]
 
 	@ re-calculate CPU control register address
-	movw	r0, #(SUN6I_CPUCFG_BASE & 0xffff)
-	movt	r0, #(SUN6I_CPUCFG_BASE >> 16)
+	movw	r0, #(SUNXI_CPUCFG_BASE & 0xffff)
+	movt	r0, #(SUNXI_CPUCFG_BASE >> 16)
 
 	@ Deassert reset on target CPU
 	mov	r6, #3
diff --git a/arch/arm/cpu/armv7/sunxi/psci_sun7i.S b/arch/arm/cpu/armv7/sunxi/psci_sun7i.S
index e15d587f2901..ac8ebf888a4a 100644
--- a/arch/arm/cpu/armv7/sunxi/psci_sun7i.S
+++ b/arch/arm/cpu/armv7/sunxi/psci_sun7i.S
@@ -73,8 +73,8 @@ psci_fiq_enter:
 	lsr	r9, r9, #10
 	and	r9, r9, #0xf
 
-	movw	r8, #(SUN7I_CPUCFG_BASE & 0xffff)
-	movt	r8, #(SUN7I_CPUCFG_BASE >> 16)
+	movw	r8, #(SUNXI_CPUCFG_BASE & 0xffff)
+	movt	r8, #(SUNXI_CPUCFG_BASE >> 16)
 
 	@ Wait for the core to enter WFI
 	lsl	r11, r9, #6		@ x64
@@ -128,8 +128,8 @@ psci_cpu_on:
 	str	r2, [r0]		@ store target PC at stack top
 	dsb
 
-	movw	r0, #(SUN7I_CPUCFG_BASE & 0xffff)
-	movt	r0, #(SUN7I_CPUCFG_BASE >> 16)
+	movw	r0, #(SUNXI_CPUCFG_BASE & 0xffff)
+	movt	r0, #(SUNXI_CPUCFG_BASE >> 16)
 
 	@ CPU mask
 	and	r1, r1, #3	@ only care about first cluster
diff --git a/arch/arm/include/asm/arch-sunxi/cpu_sun4i.h b/arch/arm/include/asm/arch-sunxi/cpu_sun4i.h
index 65c0441fe8a2..47e327e71f84 100644
--- a/arch/arm/include/asm/arch-sunxi/cpu_sun4i.h
+++ b/arch/arm/include/asm/arch-sunxi/cpu_sun4i.h
@@ -18,6 +18,10 @@
 #define SUNXI_SRAM_D_BASE		0x00010000	/* 4 kiB */
 #define SUNXI_SRAM_B_BASE		0x00020000	/* 64 kiB (secure) */
 
+#ifdef CONFIG_MACH_SUN8I_A83T
+#define SUNXI_CPUCFG_BASE		0x01700000
+#endif
+
 #define SUNXI_SRAMC_BASE		0x01c00000
 #define SUNXI_DRAMC_BASE		0x01c01000
 #define SUNXI_DMA_BASE			0x01c02000
@@ -94,7 +98,10 @@
 
 #define SUNXI_TP_BASE			0x01c25000
 #define SUNXI_PMU_BASE			0x01c25400
-#define SUN7I_CPUCFG_BASE              0x01c25c00
+
+#ifdef CONFIG_MACH_SUN7I
+#define SUNXI_CPUCFG_BASE		0x01c25c00
+#endif
 
 #define SUNXI_UART0_BASE		0x01c28000
 #define SUNXI_UART1_BASE		0x01c28400
@@ -148,7 +155,11 @@
 
 #define SUNXI_RTC_BASE			0x01f00000
 #define SUNXI_PRCM_BASE			0x01f01400
-#define SUN6I_CPUCFG_BASE		0x01f01c00
+
+#if defined CONFIG_SUNXI_GEN_SUN6I && !defined CONFIG_MACH_SUN8I_A83T
+#define SUNXI_CPUCFG_BASE		0x01f01c00
+#endif
+
 #define SUNXI_R_TWI_BASE		0x01f02400
 #define SUNXI_R_UART_BASE		0x01f02800
 #define SUNXI_R_PIO_BASE		0x01f02c00
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [U-Boot] [PATCH v3 06/11] sunxi: Add packed attribute to struct sunxi_prcm_reg
  2016-06-07  2:54 [U-Boot] [PATCH v3 00/11] sunxi: PSCI implementation rewrite in C Chen-Yu Tsai
                   ` (4 preceding siblings ...)
  2016-06-07  2:54 ` [U-Boot] [PATCH v3 05/11] sunxi: Make CPUCFG_BASE macro names the same across families Chen-Yu Tsai
@ 2016-06-07  2:54 ` Chen-Yu Tsai
  2016-06-07  2:54 ` [U-Boot] [PATCH v3 07/11] sunxi: Add missing linux/types.h header for cpucfg_sun6i.h Chen-Yu Tsai
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Chen-Yu Tsai @ 2016-06-07  2:54 UTC (permalink / raw)
  To: u-boot

struct sunxi_prcm_reg is a representation of the PRCM registers. Add
the packed attribute to prevent the compiler from doing funny things.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 arch/arm/include/asm/arch-sunxi/prcm.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/arm/include/asm/arch-sunxi/prcm.h b/arch/arm/include/asm/arch-sunxi/prcm.h
index 556c1af60058..34e01e825df2 100644
--- a/arch/arm/include/asm/arch-sunxi/prcm.h
+++ b/arch/arm/include/asm/arch-sunxi/prcm.h
@@ -197,7 +197,9 @@
 #define PRCM_CPU3_PWR_CLAMP_MASK PRCM_CPU3_PWR_CLAMP(0xff)
 
 #ifndef __ASSEMBLY__
-struct sunxi_prcm_reg {
+#include <linux/compiler.h>
+
+struct __packed sunxi_prcm_reg {
 	u32 cpus_cfg;		/* 0x000 */
 	u8 res0[0x8];		/* 0x004 */
 	u32 apb0_ratio;		/* 0x00c */
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [U-Boot] [PATCH v3 07/11] sunxi: Add missing linux/types.h header for cpucfg_sun6i.h
  2016-06-07  2:54 [U-Boot] [PATCH v3 00/11] sunxi: PSCI implementation rewrite in C Chen-Yu Tsai
                   ` (5 preceding siblings ...)
  2016-06-07  2:54 ` [U-Boot] [PATCH v3 06/11] sunxi: Add packed attribute to struct sunxi_prcm_reg Chen-Yu Tsai
@ 2016-06-07  2:54 ` Chen-Yu Tsai
  2016-06-07  2:54 ` [U-Boot] [PATCH v3 08/11] sunxi: Group cpu core related controls together Chen-Yu Tsai
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Chen-Yu Tsai @ 2016-06-07  2:54 UTC (permalink / raw)
  To: u-boot

cpucfg_sun6i.h includes a register definition for the CPUCFG register
block. The types used are u32 and u8, which are defined in linux/types.h.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 arch/arm/include/asm/arch-sunxi/cpucfg_sun6i.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/include/asm/arch-sunxi/cpucfg_sun6i.h b/arch/arm/include/asm/arch-sunxi/cpucfg_sun6i.h
index e2a29cb1818e..6885a972ce0b 100644
--- a/arch/arm/include/asm/arch-sunxi/cpucfg_sun6i.h
+++ b/arch/arm/include/asm/arch-sunxi/cpucfg_sun6i.h
@@ -9,6 +9,8 @@
 #ifndef _SUNXI_CPUCFG_H
 #define _SUNXI_CPUCFG_H
 
+#include <linux/types.h>
+
 #ifndef __ASSEMBLY__
 
 struct sunxi_cpucfg_reg {
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [U-Boot] [PATCH v3 08/11] sunxi: Group cpu core related controls together
  2016-06-07  2:54 [U-Boot] [PATCH v3 00/11] sunxi: PSCI implementation rewrite in C Chen-Yu Tsai
                   ` (6 preceding siblings ...)
  2016-06-07  2:54 ` [U-Boot] [PATCH v3 07/11] sunxi: Add missing linux/types.h header for cpucfg_sun6i.h Chen-Yu Tsai
@ 2016-06-07  2:54 ` Chen-Yu Tsai
  2016-06-07  2:54 ` [U-Boot] [PATCH v3 09/11] sunxi: Add CPUCFG debug lock and sun7i cpu power controls Chen-Yu Tsai
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Chen-Yu Tsai @ 2016-06-07  2:54 UTC (permalink / raw)
  To: u-boot

Instead of listing individual registers for controls to each processor
core, list them as an array of registers. This makes accessing controls
by core index easier.

Also rename "cpucfg_sun6i.h" (which was unused anyway) to the more generic
"cpucfg.h", and add packed attribute to struct sunxi_cpucfg.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 .../asm/arch-sunxi/{cpucfg_sun6i.h => cpucfg.h}    | 34 +++++++++-------------
 arch/arm/include/asm/arch-sunxi/prcm.h             |  6 ++--
 2 files changed, 16 insertions(+), 24 deletions(-)
 rename arch/arm/include/asm/arch-sunxi/{cpucfg_sun6i.h => cpucfg.h} (68%)

diff --git a/arch/arm/include/asm/arch-sunxi/cpucfg_sun6i.h b/arch/arm/include/asm/arch-sunxi/cpucfg.h
similarity index 68%
rename from arch/arm/include/asm/arch-sunxi/cpucfg_sun6i.h
rename to arch/arm/include/asm/arch-sunxi/cpucfg.h
index 6885a972ce0b..f6d2f21d9d24 100644
--- a/arch/arm/include/asm/arch-sunxi/cpucfg_sun6i.h
+++ b/arch/arm/include/asm/arch-sunxi/cpucfg.h
@@ -9,37 +9,31 @@
 #ifndef _SUNXI_CPUCFG_H
 #define _SUNXI_CPUCFG_H
 
+#include <linux/compiler.h>
 #include <linux/types.h>
 
 #ifndef __ASSEMBLY__
 
-struct sunxi_cpucfg_reg {
+struct __packed sunxi_cpucfg_cpu {
+	u32 rst;		/* base + 0x0 */
+	u32 ctrl;		/* base + 0x4 */
+	u32 status;		/* base + 0x8 */
+	u8 res[0x34];		/* base + 0xc */
+};
+
+struct __packed sunxi_cpucfg_reg {
 	u8 res0[0x40];		/* 0x000 */
-	u32 cpu0_rst;		/* 0x040 */
-	u32 cpu0_ctrl;		/* 0x044 */
-	u32 cpu0_status;	/* 0x048 */
-	u8 res1[0x34];		/* 0x04c */
-	u32 cpu1_rst;		/* 0x080 */
-	u32 cpu1_ctrl;		/* 0x084 */
-	u32 cpu1_status;	/* 0x088 */
-	u8 res2[0x34];		/* 0x08c */
-	u32 cpu2_rst;		/* 0x0c0 */
-	u32 cpu2_ctrl;		/* 0x0c4 */
-	u32 cpu2_status;	/* 0x0c8 */
-	u8 res3[0x34];		/* 0x0cc */
-	u32 cpu3_rst;		/* 0x100 */
-	u32 cpu3_ctrl;		/* 0x104 */
-	u32 cpu3_status;	/* 0x108 */
-	u8 res4[0x78];		/* 0x10c */
+	struct sunxi_cpucfg_cpu cpu[4];		/* 0x040 */
+	u8 res1[0x44];		/* 0x140 */
 	u32 gen_ctrl;		/* 0x184 */
 	u32 l2_status;		/* 0x188 */
-	u8 res5[0x4];		/* 0x18c */
+	u8 res2[0x4];		/* 0x18c */
 	u32 event_in;		/* 0x190 */
-	u8 res6[0xc];		/* 0x194 */
+	u8 res3[0xc];		/* 0x194 */
 	u32 super_standy_flag;	/* 0x1a0 */
 	u32 priv0;		/* 0x1a4 */
 	u32 priv1;		/* 0x1a8 */
-	u8 res7[0x54];		/* 0x1ac */
+	u8 res4[0x54];		/* 0x1ac */
 	u32 idle_cnt0_low;	/* 0x200 */
 	u32 idle_cnt0_high;	/* 0x204 */
 	u32 idle_cnt0_ctrl;	/* 0x208 */
diff --git a/arch/arm/include/asm/arch-sunxi/prcm.h b/arch/arm/include/asm/arch-sunxi/prcm.h
index 34e01e825df2..ae3880b13bdf 100644
--- a/arch/arm/include/asm/arch-sunxi/prcm.h
+++ b/arch/arm/include/asm/arch-sunxi/prcm.h
@@ -227,10 +227,8 @@ struct __packed sunxi_prcm_reg {
 	u32 gpu_pwroff;		/* 0x118 */
 	u8 res9[0x4];		/* 0x11c */
 	u32 vdd_pwr_reset;	/* 0x120 */
-	u8 res10[0x20];		/* 0x124 */
-	u32 cpu1_pwr_clamp;	/* 0x144 */
-	u32 cpu2_pwr_clamp;	/* 0x148 */
-	u32 cpu3_pwr_clamp;	/* 0x14c */
+	u8 res10[0x1c];		/* 0x124 */
+	u32 cpu_pwr_clamp[4];	/* 0x140 but first one is actually unused */
 	u8 res11[0x30];		/* 0x150 */
 	u32 dram_pwr;		/* 0x180 */
 	u8 res12[0xc];		/* 0x184 */
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [U-Boot] [PATCH v3 09/11] sunxi: Add CPUCFG debug lock and sun7i cpu power controls
  2016-06-07  2:54 [U-Boot] [PATCH v3 00/11] sunxi: PSCI implementation rewrite in C Chen-Yu Tsai
                   ` (7 preceding siblings ...)
  2016-06-07  2:54 ` [U-Boot] [PATCH v3 08/11] sunxi: Group cpu core related controls together Chen-Yu Tsai
@ 2016-06-07  2:54 ` Chen-Yu Tsai
  2016-06-07  2:54 ` [U-Boot] [PATCH v3 10/11] sunxi: Add base address for GIC Chen-Yu Tsai
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 20+ messages in thread
From: Chen-Yu Tsai @ 2016-06-07  2:54 UTC (permalink / raw)
  To: u-boot

CPUCFG has an unlisted debug control register, which is used to disable
external debug access.

Also, sun7i secondary core power controls are in CPUCFG, as there's no
separate PRCM block.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 arch/arm/include/asm/arch-sunxi/cpucfg.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/arm/include/asm/arch-sunxi/cpucfg.h b/arch/arm/include/asm/arch-sunxi/cpucfg.h
index f6d2f21d9d24..297cdd28c060 100644
--- a/arch/arm/include/asm/arch-sunxi/cpucfg.h
+++ b/arch/arm/include/asm/arch-sunxi/cpucfg.h
@@ -33,7 +33,12 @@ struct __packed sunxi_cpucfg_reg {
 	u32 super_standy_flag;	/* 0x1a0 */
 	u32 priv0;		/* 0x1a4 */
 	u32 priv1;		/* 0x1a8 */
-	u8 res4[0x54];		/* 0x1ac */
+	u8 res4[0x4];		/* 0x1ac */
+	u32 cpu1_pwr_clamp;	/* 0x1b0 sun7i only */
+	u32 cpu1_pwroff;	/* 0x1b4 sun7i only */
+	u8 res5[0x2c];		/* 0x1b8 */
+	u32 dbg_ctrl1;		/* 0x1e4 */
+	u8 res6[0x18];		/* 0x1e8 */
 	u32 idle_cnt0_low;	/* 0x200 */
 	u32 idle_cnt0_high;	/* 0x204 */
 	u32 idle_cnt0_ctrl;	/* 0x208 */
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [U-Boot] [PATCH v3 10/11] sunxi: Add base address for GIC
  2016-06-07  2:54 [U-Boot] [PATCH v3 00/11] sunxi: PSCI implementation rewrite in C Chen-Yu Tsai
                   ` (8 preceding siblings ...)
  2016-06-07  2:54 ` [U-Boot] [PATCH v3 09/11] sunxi: Add CPUCFG debug lock and sun7i cpu power controls Chen-Yu Tsai
@ 2016-06-07  2:54 ` Chen-Yu Tsai
  2016-06-07  2:54 ` [U-Boot] [PATCH v3 11/11] sunxi: Add PSCI implementation in C Chen-Yu Tsai
  2016-06-07  9:49 ` [U-Boot] [PATCH v3 00/11] sunxi: PSCI implementation rewrite " Marc Zyngier
  11 siblings, 0 replies; 20+ messages in thread
From: Chen-Yu Tsai @ 2016-06-07  2:54 UTC (permalink / raw)
  To: u-boot

Instead of hardcoding the GIC addresses in the PSCI implementation,
provide a base address in the cpu header.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 arch/arm/cpu/armv7/sunxi/psci_sun6i.S       | 4 ++--
 arch/arm/cpu/armv7/sunxi/psci_sun7i.S       | 4 ++--
 arch/arm/include/asm/arch-sunxi/cpu_sun4i.h | 2 ++
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/arch/arm/cpu/armv7/sunxi/psci_sun6i.S b/arch/arm/cpu/armv7/sunxi/psci_sun6i.S
index 9752550dea35..95fdb0e58874 100644
--- a/arch/arm/cpu/armv7/sunxi/psci_sun6i.S
+++ b/arch/arm/cpu/armv7/sunxi/psci_sun6i.S
@@ -42,8 +42,8 @@
 
 #define	ONE_MS			(CONFIG_TIMER_CLK_FREQ / 1000)
 #define	TEN_MS			(10 * ONE_MS)
-#define	GICD_BASE		0x1c81000
-#define	GICC_BASE		0x1c82000
+#define	GICD_BASE		(SUNXI_GIC400_BASE +  0x1000)
+#define	GICC_BASE		(SUNXI_GIC400_BASE +  0x2000)
 
 .globl	psci_fiq_enter
 psci_fiq_enter:
diff --git a/arch/arm/cpu/armv7/sunxi/psci_sun7i.S b/arch/arm/cpu/armv7/sunxi/psci_sun7i.S
index ac8ebf888a4a..87bbd725f0b3 100644
--- a/arch/arm/cpu/armv7/sunxi/psci_sun7i.S
+++ b/arch/arm/cpu/armv7/sunxi/psci_sun7i.S
@@ -42,8 +42,8 @@
 
 #define	ONE_MS			(CONFIG_TIMER_CLK_FREQ / 1000)
 #define	TEN_MS			(10 * ONE_MS)
-#define	GICD_BASE		0x1c81000
-#define	GICC_BASE		0x1c82000
+#define	GICD_BASE		(SUNXI_GIC400_BASE +  0x1000)
+#define	GICC_BASE		(SUNXI_GIC400_BASE +  0x2000)
 
 .globl	psci_fiq_enter
 psci_fiq_enter:
diff --git a/arch/arm/include/asm/arch-sunxi/cpu_sun4i.h b/arch/arm/include/asm/arch-sunxi/cpu_sun4i.h
index 47e327e71f84..c5e9d88bab5c 100644
--- a/arch/arm/include/asm/arch-sunxi/cpu_sun4i.h
+++ b/arch/arm/include/asm/arch-sunxi/cpu_sun4i.h
@@ -143,6 +143,8 @@
 #define SUNXI_DRAM_PHY0_BASE		0x01c65000
 #define SUNXI_DRAM_PHY1_BASE		0x01c66000
 
+#define SUNXI_GIC400_BASE		0x01c80000
+
 /* module sram */
 #define SUNXI_SRAM_C_BASE		0x01d00000
 
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [U-Boot] [PATCH v3 11/11] sunxi: Add PSCI implementation in C
  2016-06-07  2:54 [U-Boot] [PATCH v3 00/11] sunxi: PSCI implementation rewrite in C Chen-Yu Tsai
                   ` (9 preceding siblings ...)
  2016-06-07  2:54 ` [U-Boot] [PATCH v3 10/11] sunxi: Add base address for GIC Chen-Yu Tsai
@ 2016-06-07  2:54 ` Chen-Yu Tsai
  2016-06-10 13:40   ` Hans de Goede
  2016-06-07  9:49 ` [U-Boot] [PATCH v3 00/11] sunxi: PSCI implementation rewrite " Marc Zyngier
  11 siblings, 1 reply; 20+ messages in thread
From: Chen-Yu Tsai @ 2016-06-07  2:54 UTC (permalink / raw)
  To: u-boot

To make the PSCI backend more maintainable and easier to port to newer
SoCs, rewrite the current PSCI implementation in C.

Some inline assembly bits are required to access coprocessor registers.
PSCI stack setup is the only part left completely in assembly. In theory
this part could be split out of psci_arch_init into a separate common
function, and psci_arch_init could be completely in C.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 arch/arm/cpu/armv7/sunxi/Makefile     |   7 +-
 arch/arm/cpu/armv7/sunxi/psci.c       | 273 ++++++++++++++++++++++++++++++++++
 arch/arm/cpu/armv7/sunxi/psci_head.S  |  66 ++++++++
 arch/arm/cpu/armv7/sunxi/psci_sun6i.S | 262 --------------------------------
 arch/arm/cpu/armv7/sunxi/psci_sun7i.S | 237 -----------------------------
 5 files changed, 341 insertions(+), 504 deletions(-)
 create mode 100644 arch/arm/cpu/armv7/sunxi/psci.c
 create mode 100644 arch/arm/cpu/armv7/sunxi/psci_head.S
 delete mode 100644 arch/arm/cpu/armv7/sunxi/psci_sun6i.S
 delete mode 100644 arch/arm/cpu/armv7/sunxi/psci_sun7i.S

diff --git a/arch/arm/cpu/armv7/sunxi/Makefile b/arch/arm/cpu/armv7/sunxi/Makefile
index 4d2274a38ed1..c2085101685b 100644
--- a/arch/arm/cpu/armv7/sunxi/Makefile
+++ b/arch/arm/cpu/armv7/sunxi/Makefile
@@ -13,11 +13,8 @@ obj-$(CONFIG_MACH_SUN6I)	+= tzpc.o
 obj-$(CONFIG_MACH_SUN8I_H3)	+= tzpc.o
 
 ifndef CONFIG_SPL_BUILD
-ifdef CONFIG_ARMV7_PSCI
-obj-$(CONFIG_MACH_SUN6I)	+= psci_sun6i.o
-obj-$(CONFIG_MACH_SUN7I)	+= psci_sun7i.o
-obj-$(CONFIG_MACH_SUN8I)	+= psci_sun6i.o
-endif
+obj-$(CONFIG_ARMV7_PSCI)	+= psci.o
+obj-$(CONFIG_ARMV7_PSCI)	+= psci_head.o
 endif
 
 ifdef CONFIG_SPL_BUILD
diff --git a/arch/arm/cpu/armv7/sunxi/psci.c b/arch/arm/cpu/armv7/sunxi/psci.c
new file mode 100644
index 000000000000..0059f4cbc9d6
--- /dev/null
+++ b/arch/arm/cpu/armv7/sunxi/psci.c
@@ -0,0 +1,273 @@
+/*
+ * Copyright (C) 2016
+ * Author: Chen-Yu Tsai <wens@csie.org>
+ *
+ * Based on assembly code by Marc Zyngier <marc.zyngier@arm.com>,
+ * which was based on code by Carl van Schaik <carl@ok-labs.com>.
+ *
+ * SPDX-License-Identifier:	GPL-2.0
+ */
+#include <config.h>
+#include <common.h>
+
+#include <asm/arch/cpu.h>
+#include <asm/arch/cpucfg.h>
+#include <asm/arch/prcm.h>
+#include <asm/armv7.h>
+#include <asm/gic.h>
+#include <asm/io.h>
+#include <asm/psci.h>
+#include <asm/system.h>
+
+#include <linux/bitops.h>
+
+#define __secure	__attribute__ ((section ("._secure.text")))
+#define __irq		__attribute__ ((interrupt ("IRQ")))
+
+#define	GICD_BASE	(SUNXI_GIC400_BASE + GIC_DIST_OFFSET)
+#define	GICC_BASE	(SUNXI_GIC400_BASE + GIC_CPU_OFFSET_A15)
+
+static void __secure cp15_write_cntp_tval(u32 tval)
+{
+	asm volatile ("mcr p15, 0, %0, c14, c2, 0" : : "r" (tval));
+}
+
+static void __secure cp15_write_cntp_ctl(u32 val)
+{
+	asm volatile ("mcr p15, 0, %0, c14, c2, 1" : : "r" (val));
+}
+
+static u32 __secure cp15_read_cntp_ctl(void)
+{
+	u32 val;
+
+	asm volatile ("mrc p15, 0, %0, c14, c2, 1" : "=r" (val));
+
+	return val;
+}
+
+#define ONE_MS (CONFIG_TIMER_CLK_FREQ / 1000)
+
+static void __secure __mdelay(u32 ms)
+{
+	u32 reg = ONE_MS * ms;
+
+	cp15_write_cntp_tval(reg);
+	ISB;
+	cp15_write_cntp_ctl(3);
+
+	do {
+		ISB;
+		reg = cp15_read_cntp_ctl();
+	} while (!(reg & BIT(2)));
+
+	cp15_write_cntp_ctl(0);
+	ISB;
+}
+
+static void __secure clamp_release(u32 __maybe_unused *clamp)
+{
+#if defined(CONFIG_MACH_SUN6I) || defined(CONFIG_MACH_SUN7I) || \
+	defined(CONFIG_MACH_SUN8I_H3)
+	u32 tmp = 0x1ff;
+	do {
+		tmp >>= 1;
+		writel(tmp, clamp);
+	} while (tmp);
+
+	__mdelay(10);
+#endif
+}
+
+static void __secure clamp_set(u32 __maybe_unused *clamp)
+{
+#if defined(CONFIG_MACH_SUN6I) || defined(CONFIG_MACH_SUN7I) || \
+	defined(CONFIG_MACH_SUN8I_H3)
+	writel(0xff, clamp);
+#endif
+}
+
+static void __secure sunxi_power_switch(u32 *clamp, u32 *pwroff, bool on,
+					int cpu)
+{
+	if (on) {
+		/* Release power clamp */
+		clamp_release(clamp);
+
+		/* Clear power gating */
+		clrbits_le32(pwroff, BIT(cpu));
+	} else {
+		/* Set power gating */
+		setbits_le32(pwroff, BIT(cpu));
+
+		/* Activate power clamp */
+		clamp_set(clamp);
+	}
+}
+
+#ifdef CONFIG_MACH_SUN7I
+/* sun7i (A20) is different from other single cluster SoCs */
+static void __secure sunxi_cpu_set_power(int __always_unused cpu, bool on)
+{
+	struct sunxi_cpucfg_reg *cpucfg =
+		(struct sunxi_cpucfg_reg *)SUNXI_CPUCFG_BASE;
+
+	sunxi_power_switch(&cpucfg->cpu1_pwr_clamp, &cpucfg->cpu1_pwroff,
+			   on, 0);
+}
+#else /* ! CONFIG_MACH_SUN7I */
+static void __secure sunxi_cpu_set_power(int cpu, bool on)
+{
+	struct sunxi_prcm_reg *prcm =
+		(struct sunxi_prcm_reg *)SUNXI_PRCM_BASE;
+
+	sunxi_power_switch(&prcm->cpu_pwr_clamp[cpu], &prcm->cpu_pwroff,
+			   on, cpu);
+}
+#endif /* CONFIG_MACH_SUN7I */
+
+void __secure sunxi_cpu_power_off(u32 cpuid)
+{
+	struct sunxi_cpucfg_reg *cpucfg =
+		(struct sunxi_cpucfg_reg *)SUNXI_CPUCFG_BASE;
+	u32 cpu = cpuid & 0x3;
+
+	/* Wait for the core to enter WFI */
+	while (1) {
+		if (readl(&cpucfg->cpu[cpu].status) & BIT(2))
+			break;
+		__mdelay(1);
+	}
+
+	/* Assert reset on target CPU */
+	writel(0, &cpucfg->cpu[cpu].rst);
+
+	/* Lock CPU (Disable external debug access) */
+	clrbits_le32(&cpucfg->dbg_ctrl1, BIT(cpu));
+
+	/* Power down CPU */
+	sunxi_cpu_set_power(cpuid, false);
+
+	/* Unlock CPU (Disable external debug access) */
+	setbits_le32(&cpucfg->dbg_ctrl1, BIT(cpu));
+}
+
+static u32 cp15_read_scr(void)
+{
+	u32 scr;
+
+	asm volatile ("mrc p15, 0, %0, c1, c1, 0" : "=r" (scr));
+
+	return scr;
+}
+
+static void cp15_write_scr(u32 scr)
+{
+	asm volatile ("mcr p15, 0, %0, c1, c1, 0" : : "r" (scr));
+	ISB;
+}
+
+/*
+ * Although this is an FIQ handler, the FIQ is processed in monitor mode,
+ * which means there's no FIQ banked registers. This is the same as IRQ
+ * mode, so use the IRQ attribute to ask the compiler to handler entry
+ * and return.
+ */
+void __secure __irq psci_fiq_enter(void)
+{
+	u32 scr, reg, cpu;
+
+	/* Switch to secure mode */
+	scr = cp15_read_scr();
+	cp15_write_scr(scr & ~BIT(0));
+
+	/* Validate reason based on IAR and acknowledge */
+	reg = readl(GICC_BASE + GICC_IAR);
+
+	/* Skip spurious interrupts 1022 and 1023 */
+	if (reg == 1023 || reg == 1022)
+		goto out;
+
+	/* End of interrupt */
+	writel(reg, GICC_BASE + GICC_EOIR);
+	DSB;
+
+	/* Get CPU number */
+	cpu = (reg >> 10) & 0x7;
+
+	/* Power off the CPU */
+	sunxi_cpu_power_off(cpu);
+
+out:
+	/* Restore security level */
+	cp15_write_scr(scr);
+}
+
+int __secure psci_cpu_on(u32 __always_unused unused, u32 mpidr, u32 pc)
+{
+	struct sunxi_cpucfg_reg *cpucfg =
+		(struct sunxi_cpucfg_reg *)SUNXI_CPUCFG_BASE;
+	u32 cpu = (mpidr & 0x3);
+
+	/* store target PC at target CPU stack top */
+	writel(pc, psci_get_cpu_stack_top(cpu));
+	DSB;
+
+	/* Set secondary core power on PC */
+	writel((u32)&psci_cpu_entry, &cpucfg->priv0);
+
+	/* Assert reset on target CPU */
+	writel(0, &cpucfg->cpu[cpu].rst);
+
+	/* Invalidate L1 cache */
+	clrbits_le32(&cpucfg->gen_ctrl, BIT(cpu));
+
+	/* Lock CPU (Disable external debug access) */
+	clrbits_le32(&cpucfg->dbg_ctrl1, BIT(cpu));
+
+	/* Power up target CPU */
+	sunxi_cpu_set_power(cpu, true);
+
+	/* De-assert reset on target CPU */
+	writel(BIT(1) | BIT(0), &cpucfg->cpu[cpu].rst);
+
+	/* Unlock CPU (Disable external debug access) */
+	setbits_le32(&cpucfg->dbg_ctrl1, BIT(cpu));
+
+	return ARM_PSCI_RET_SUCCESS;
+}
+
+void __secure psci_cpu_off(void)
+{
+	psci_cpu_off_common();
+
+	/* Ask CPU0 via SGI15 to pull the rug... */
+	writel(BIT(16) | 15, GICD_BASE + GICD_SGIR);
+	DSB;
+
+	/* Wait to be turned off */
+	while (1)
+		wfi();
+}
+
+void __secure sunxi_gic_init(void)
+{
+	u32 reg;
+
+	/* SGI15 as Group-0 */
+	clrbits_le32(GICD_BASE + GICD_IGROUPRn, BIT(15));
+
+	/* Set SGI15 priority to 0 */
+	writeb(0, GICD_BASE + GICD_IPRIORITYRn + 15);
+
+	/* Be cool with non-secure */
+	writel(0xff, GICC_BASE + GICC_PMR);
+
+	/* Switch FIQEn on */
+	setbits_le32(GICC_BASE + GICC_CTLR, BIT(3));
+
+	reg = cp15_read_scr();
+	reg |= BIT(2);  /* Enable FIQ in monitor mode */
+	reg &= ~BIT(0); /* Secure mode */
+	cp15_write_scr(reg);
+}
diff --git a/arch/arm/cpu/armv7/sunxi/psci_head.S b/arch/arm/cpu/armv7/sunxi/psci_head.S
new file mode 100644
index 000000000000..8fa823d1df3a
--- /dev/null
+++ b/arch/arm/cpu/armv7/sunxi/psci_head.S
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2013 - ARM Ltd
+ * Author: Marc Zyngier <marc.zyngier@arm.com>
+ *
+ * Based on code by Carl van Schaik <carl@ok-labs.com>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <linux/linkage.h>
+
+#include <asm/arch-armv7/generictimer.h>
+#include <asm/gic.h>
+#include <asm/macro.h>
+#include <asm/psci.h>
+#include <asm/arch/cpu.h>
+
+/*
+ * Memory layout:
+ *
+ * SECURE_RAM to text_end :
+ *	._secure_text section
+ * text_end to ALIGN_PAGE(text_end):
+ *	nothing
+ * ALIGN_PAGE(text_end) to ALIGN_PAGE(text_end) + 0x1000)
+ *	1kB of stack per CPU (4 CPUs max).
+ */
+
+	.pushsection ._secure.text, "ax"
+
+	.arch_extension sec
+
+#define	GICD_BASE		(SUNXI_GIC400_BASE +  0x1000)
+#define	GICC_BASE		(SUNXI_GIC400_BASE +  0x2000)
+
+@ {r0, r1, r2, ip} from _do_nonsec_entry(kernel_entry, 0, machid, r2) in
+@ arch/arm/lib/bootm.c:boot_jump_linux() must remain unchanged across
+@ this function.
+ENTRY(psci_arch_init)
+	mov	r6, lr
+	mov	r7, r0
+	bl	psci_get_cpu_id		@ CPU ID => r0
+	bl	psci_get_cpu_stack_top	@ stack top => r0
+	sub	r0, r0, #4		@ Save space for target PC
+	mov	sp, r0
+	mov	r0, r7
+	mov	lr, r6
+
+	push	{r0, r1, r2, ip, lr}
+	bl	sunxi_gic_init
+	pop	{r0, r1, r2, ip, pc}
+ENDPROC(psci_arch_init)
+
+ENTRY(psci_text_end)
+	.popsection
diff --git a/arch/arm/cpu/armv7/sunxi/psci_sun6i.S b/arch/arm/cpu/armv7/sunxi/psci_sun6i.S
deleted file mode 100644
index 95fdb0e58874..000000000000
--- a/arch/arm/cpu/armv7/sunxi/psci_sun6i.S
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * Copyright (C) 2015 - Chen-Yu Tsai
- * Author: Chen-Yu Tsai <wens@csie.org>
- *
- * Based on psci_sun7i.S by Marc Zyngier <marc.zyngier@arm.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <config.h>
-
-#include <asm/arch-armv7/generictimer.h>
-#include <asm/gic.h>
-#include <asm/macro.h>
-#include <asm/psci.h>
-#include <asm/arch/cpu.h>
-
-/*
- * Memory layout:
- *
- * SECURE_RAM to text_end :
- *	._secure_text section
- * text_end to ALIGN_PAGE(text_end):
- *	nothing
- * ALIGN_PAGE(text_end) to ALIGN_PAGE(text_end) + 0x1000)
- *	1kB of stack per CPU (4 CPUs max).
- */
-
-	.pushsection ._secure.text, "ax"
-
-	.arch_extension sec
-
-#define	ONE_MS			(CONFIG_TIMER_CLK_FREQ / 1000)
-#define	TEN_MS			(10 * ONE_MS)
-#define	GICD_BASE		(SUNXI_GIC400_BASE +  0x1000)
-#define	GICC_BASE		(SUNXI_GIC400_BASE +  0x2000)
-
-.globl	psci_fiq_enter
-psci_fiq_enter:
-	push	{r0-r12}
-
-	@ Switch to secure
-	mrc	p15, 0, r7, c1, c1, 0
-	bic	r8, r7, #1
-	mcr	p15, 0, r8, c1, c1, 0
-	isb
-
-	@ Validate reason based on IAR and acknowledge
-	movw	r8, #(GICC_BASE & 0xffff)
-	movt	r8, #(GICC_BASE >> 16)
-	ldr	r9, [r8, #GICC_IAR]
-	movw	r10, #0x3ff
-	movt	r10, #0
-	cmp	r9, r10			@ skip spurious interrupt 1023
-	beq	out
-	movw	r10, #0x3fe		@ ...and 1022
-	cmp	r9, r10
-	beq	out
-	str	r9, [r8, #GICC_EOIR]	@ acknowledge the interrupt
-	dsb
-
-	@ Compute CPU number
-	lsr	r9, r9, #10
-	and	r9, r9, #0xf
-
-	movw	r8, #(SUNXI_CPUCFG_BASE & 0xffff)
-	movt	r8, #(SUNXI_CPUCFG_BASE >> 16)
-
-	@ Wait for the core to enter WFI
-	lsl	r11, r9, #6		@ x64
-	add	r11, r11, r8
-
-1:	ldr	r10, [r11, #0x48]
-	tst	r10, #(1 << 2)
-	bne	2f
-	timer_wait r10, ONE_MS
-	b	1b
-
-	@ Reset CPU
-2:	mov	r10, #0
-	str	r10, [r11, #0x40]
-
-	@ Lock CPU
-	mov	r10, #1
-	lsl	r11, r10, r9		@ r11 is now CPU mask
-	ldr	r10, [r8, #0x1e4]
-	bic	r10, r10, r11
-	str	r10, [r8, #0x1e4]
-
-	movw	r8, #(SUNXI_PRCM_BASE & 0xffff)
-	movt	r8, #(SUNXI_PRCM_BASE >> 16)
-
-	@ Set power gating
-	ldr	r10, [r8, #0x100]
-	orr	r10, r10, r11
-	str	r10, [r8, #0x100]
-	timer_wait r10, ONE_MS
-
-#if defined(CONFIG_MACH_SUN6I) || defined(CONFIG_MACH_SUN8I_H3)
-	@ Activate power clamp
-	lsl	r12, r9, #2		@ x4
-	add	r12, r12, r8
-	mov	r10, #0xff
-	str	r10, [r12, #0x140]
-#endif
-
-	movw	r8, #(SUNXI_CPUCFG_BASE & 0xffff)
-	movt	r8, #(SUNXI_CPUCFG_BASE >> 16)
-
-	@ Unlock CPU
-	ldr	r10, [r8, #0x1e4]
-	orr	r10, r10, r11
-	str	r10, [r8, #0x1e4]
-
-	@ Restore security level
-out:	mcr	p15, 0, r7, c1, c1, 0
-
-	pop	{r0-r12}
-	subs    pc, lr, #4
-
-	@ r1 = target CPU
-	@ r2 = target PC
-.globl	psci_cpu_on
-psci_cpu_on:
-	push	{lr}
-
-	mov	r0, r1
-	bl	psci_get_cpu_stack_top	@ get stack top of target CPU
-	str	r2, [r0]		@ store target PC at stack top
-	dsb
-
-	movw	r0, #(SUNXI_CPUCFG_BASE & 0xffff)
-	movt	r0, #(SUNXI_CPUCFG_BASE >> 16)
-
-	@ CPU mask
-	and	r1, r1, #3	@ only care about first cluster
-	mov	r4, #1
-	lsl	r4, r4, r1
-
-	ldr	r6, =psci_cpu_entry
-	str	r6, [r0, #0x1a4] @ PRIVATE_REG (boot vector)
-
-	@ Assert reset on target CPU
-	mov	r6, #0
-	lsl	r5, r1, #6	@ 64 bytes per CPU
-	add	r5, r5, #0x40	@ Offset from base
-	add	r5, r5, r0	@ CPU control block
-	str	r6, [r5]	@ Reset CPU
-
-	@ l1 invalidate
-	ldr	r6, [r0, #0x184] @ CPUCFG_GEN_CTRL_REG
-	bic	r6, r6, r4
-	str	r6, [r0, #0x184]
-
-	@ Lock CPU (Disable external debug access)
-	ldr	r6, [r0, #0x1e4] @ CPUCFG_DBG_CTL1_REG
-	bic	r6, r6, r4
-	str	r6, [r0, #0x1e4]
-
-	movw	r0, #(SUNXI_PRCM_BASE & 0xffff)
-	movt	r0, #(SUNXI_PRCM_BASE >> 16)
-
-#if defined(CONFIG_MACH_SUN6I) || defined(CONFIG_MACH_SUN8I_H3)
-	@ Release power clamp
-	lsl	r5, r1, #2	@ 1 register per CPU
-	add	r5, r5, r0	@ PRCM
-	movw	r6, #0x1ff
-	movt	r6, #0
-1:	lsrs	r6, r6, #1
-	str	r6, [r5, #0x140] @ CPUx_PWR_CLAMP
-	bne	1b
-#endif
-
-	timer_wait r6, TEN_MS
-
-	@ Clear power gating
-	ldr	r6, [r0, #0x100] @ CPU_PWROFF_GATING
-	bic	r6, r6, r4
-	str	r6, [r0, #0x100]
-
-	@ re-calculate CPU control register address
-	movw	r0, #(SUNXI_CPUCFG_BASE & 0xffff)
-	movt	r0, #(SUNXI_CPUCFG_BASE >> 16)
-
-	@ Deassert reset on target CPU
-	mov	r6, #3
-	lsl	r5, r1, #6	@ 64 bytes per CPU
-	add	r5, r5, #0x40	@ Offset from base
-	add	r5, r5, r0	@ CPU control block
-	str	r6, [r5]
-
-	@ Unlock CPU (Enable external debug access)
-	ldr	r6, [r0, #0x1e4] @ CPUCFG_DBG_CTL1_REG
-	orr	r6, r6, r4
-	str	r6, [r0, #0x1e4]
-
-	mov	r0, #ARM_PSCI_RET_SUCCESS	@ Return PSCI_RET_SUCCESS
-	pop	{pc}
-
-.globl	psci_cpu_off
-psci_cpu_off:
-	bl	psci_cpu_off_common
-
-	@ Ask CPU0 to pull the rug...
-	movw	r0, #(GICD_BASE & 0xffff)
-	movt	r0, #(GICD_BASE >> 16)
-	movw	r1, #15				@ SGI15
-	movt	r1, #1				@ Target is CPU0
-	str	r1, [r0, #GICD_SGIR]
-	dsb
-
-1:	wfi
-	b	1b
-
-.globl	psci_arch_init
-psci_arch_init:
-	mov	r6, lr
-
-	movw	r4, #(GICD_BASE & 0xffff)
-	movt	r4, #(GICD_BASE >> 16)
-
-	ldr	r5, [r4, #GICD_IGROUPRn]
-	bic	r5, r5, #(1 << 15) 	@ SGI15 as Group-0
-	str	r5, [r4, #GICD_IGROUPRn]
-
-	mov	r5, #0			@ Set SGI15 priority to 0
-	strb	r5, [r4, #(GICD_IPRIORITYRn + 15)]
-
-	add	r4, r4, #0x1000		@ GICC address
-
-	mov	r5, #0xff
-	str	r5, [r4, #GICC_PMR]	@ Be cool with non-secure
-
-	ldr	r5, [r4, #GICC_CTLR]
-	orr	r5, r5, #(1 << 3)	@ Switch FIQEn on
-	str	r5, [r4, #GICC_CTLR]
-
-	mrc	p15, 0, r5, c1, c1, 0	@ Read SCR
-	orr	r5, r5, #4		@ Enable FIQ in monitor mode
-	bic	r5, r5, #1		@ Secure mode
-	mcr	p15, 0, r5, c1, c1, 0	@ Write SCR
-	isb
-
-	bl	psci_get_cpu_id		@ CPU ID => r0
-	bl	psci_get_cpu_stack_top	@ stack top => r0
-	mov	sp, r0
-
-	bx	r6
-
-	.globl psci_text_end
-psci_text_end:
-	.popsection
diff --git a/arch/arm/cpu/armv7/sunxi/psci_sun7i.S b/arch/arm/cpu/armv7/sunxi/psci_sun7i.S
deleted file mode 100644
index 87bbd725f0b3..000000000000
--- a/arch/arm/cpu/armv7/sunxi/psci_sun7i.S
+++ /dev/null
@@ -1,237 +0,0 @@
-/*
- * Copyright (C) 2013 - ARM Ltd
- * Author: Marc Zyngier <marc.zyngier@arm.com>
- *
- * Based on code by Carl van Schaik <carl@ok-labs.com>.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <config.h>
-
-#include <asm/arch-armv7/generictimer.h>
-#include <asm/gic.h>
-#include <asm/macro.h>
-#include <asm/psci.h>
-#include <asm/arch/cpu.h>
-
-/*
- * Memory layout:
- *
- * SECURE_RAM to text_end :
- *	._secure_text section
- * text_end to ALIGN_PAGE(text_end):
- *	nothing
- * ALIGN_PAGE(text_end) to ALIGN_PAGE(text_end) + 0x1000)
- *	1kB of stack per CPU (4 CPUs max).
- */
-
-	.pushsection ._secure.text, "ax"
-
-	.arch_extension sec
-
-#define	ONE_MS			(CONFIG_TIMER_CLK_FREQ / 1000)
-#define	TEN_MS			(10 * ONE_MS)
-#define	GICD_BASE		(SUNXI_GIC400_BASE +  0x1000)
-#define	GICC_BASE		(SUNXI_GIC400_BASE +  0x2000)
-
-.globl	psci_fiq_enter
-psci_fiq_enter:
-	push	{r0-r12}
-
-	@ Switch to secure
-	mrc	p15, 0, r7, c1, c1, 0
-	bic	r8, r7, #1
-	mcr	p15, 0, r8, c1, c1, 0
-	isb
-
-	@ Validate reason based on IAR and acknowledge
-	movw	r8, #(GICC_BASE & 0xffff)
-	movt	r8, #(GICC_BASE >> 16)
-	ldr	r9, [r8, #GICC_IAR]
-	movw	r10, #0x3ff
-	movt	r10, #0
-	cmp	r9, r10			@ skip spurious interrupt 1023
-	beq	out
-	movw	r10, #0x3fe		@ ...and 1022
-	cmp	r9, r10
-	beq	out
-	str	r9, [r8, #GICC_EOIR]	@ acknowledge the interrupt
-	dsb
-
-	@ Compute CPU number
-	lsr	r9, r9, #10
-	and	r9, r9, #0xf
-
-	movw	r8, #(SUNXI_CPUCFG_BASE & 0xffff)
-	movt	r8, #(SUNXI_CPUCFG_BASE >> 16)
-
-	@ Wait for the core to enter WFI
-	lsl	r11, r9, #6		@ x64
-	add	r11, r11, r8
-
-1:	ldr	r10, [r11, #0x48]
-	tst	r10, #(1 << 2)
-	bne	2f
-	timer_wait r10, ONE_MS
-	b	1b
-
-	@ Reset CPU
-2:	mov	r10, #0
-	str	r10, [r11, #0x40]
-
-	@ Lock CPU
-	mov	r10, #1
-	lsl	r9, r10, r9		@ r9 is now CPU mask
-	ldr	r10, [r8, #0x1e4]
-	bic	r10, r10, r9
-	str	r10, [r8, #0x1e4]
-
-	@ Set power gating
-	ldr	r10, [r8, #0x1b4]
-	orr	r10, r10, #1
-	str	r10, [r8, #0x1b4]
-	timer_wait r10, ONE_MS
-
-	@ Activate power clamp
-	mov	r10, #1
-1:	str	r10, [r8, #0x1b0]
-	lsl	r10, r10, #1
-	orr	r10, r10, #1
-	tst	r10, #0x100
-	beq	1b
-
-	@ Restore security level
-out:	mcr	p15, 0, r7, c1, c1, 0
-
-	pop	{r0-r12}
-	subs    pc, lr, #4
-
-	@ r1 = target CPU
-	@ r2 = target PC
-.globl	psci_cpu_on
-psci_cpu_on:
-	push	{lr}
-
-	mov	r0, r1
-	bl	psci_get_cpu_stack_top	@ get stack top of target CPU
-	str	r2, [r0]		@ store target PC@stack top
-	dsb
-
-	movw	r0, #(SUNXI_CPUCFG_BASE & 0xffff)
-	movt	r0, #(SUNXI_CPUCFG_BASE >> 16)
-
-	@ CPU mask
-	and	r1, r1, #3	@ only care about first cluster
-	mov	r4, #1
-	lsl	r4, r4, r1
-
-	ldr	r6, =psci_cpu_entry
-	str	r6, [r0, #0x1a4] @ PRIVATE_REG (boot vector)
-
-	@ Assert reset on target CPU
-	mov	r6, #0
-	lsl	r5, r1, #6	@ 64 bytes per CPU
-	add	r5, r5, #0x40	@ Offset from base
-	add	r5, r5, r0	@ CPU control block
-	str	r6, [r5]	@ Reset CPU
-
-	@ l1 invalidate
-	ldr	r6, [r0, #0x184] @ CPUCFG_GEN_CTRL_REG
-	bic	r6, r6, r4
-	str	r6, [r0, #0x184]
-
-	@ Lock CPU (Disable external debug access)
-	ldr	r6, [r0, #0x1e4] @ CPUCFG_DBG_CTL1_REG
-	bic	r6, r6, r4
-	str	r6, [r0, #0x1e4]
-
-	@ Release power clamp
-	movw	r6, #0x1ff
-	movt	r6, #0
-1:	lsrs	r6, r6, #1
-	str	r6, [r0, #0x1b0] @ CPU1_PWR_CLAMP
-	bne	1b
-
-	timer_wait r1, TEN_MS
-
-	@ Clear power gating
-	ldr	r6, [r0, #0x1b4] @ CPU1_PWROFF_REG
-	bic	r6, r6, #1
-	str	r6, [r0, #0x1b4]
-
-	@ Deassert reset on target CPU
-	mov	r6, #3
-	str	r6, [r5]
-
-	@ Unlock CPU (Enable external debug access)
-	ldr	r6, [r0, #0x1e4] @ CPUCFG_DBG_CTL1_REG
-	orr	r6, r6, r4
-	str	r6, [r0, #0x1e4]
-
-	mov	r0, #ARM_PSCI_RET_SUCCESS	@ Return PSCI_RET_SUCCESS
-	pop	{pc}
-
-.globl	psci_cpu_off
-psci_cpu_off:
-	bl	psci_cpu_off_common
-
-	@ Ask CPU0 to pull the rug...
-	movw	r0, #(GICD_BASE & 0xffff)
-	movt	r0, #(GICD_BASE >> 16)
-	movw	r1, #15				@ SGI15
-	movt	r1, #1				@ Target is CPU0
-	str	r1, [r0, #GICD_SGIR]
-	dsb
-
-1:	wfi
-	b	1b
-
-.globl	psci_arch_init
-psci_arch_init:
-	mov	r6, lr
-
-	movw	r4, #(GICD_BASE & 0xffff)
-	movt	r4, #(GICD_BASE >> 16)
-
-	ldr	r5, [r4, #GICD_IGROUPRn]
-	bic	r5, r5, #(1 << 15) 	@ SGI15 as Group-0
-	str	r5, [r4, #GICD_IGROUPRn]
-
-	mov	r5, #0			@ Set SGI15 priority to 0
-	strb	r5, [r4, #(GICD_IPRIORITYRn + 15)]
-
-	add	r4, r4, #0x1000		@ GICC address
-
-	mov	r5, #0xff
-	str	r5, [r4, #GICC_PMR]	@ Be cool with non-secure
-
-	ldr	r5, [r4, #GICC_CTLR]
-	orr	r5, r5, #(1 << 3)	@ Switch FIQEn on
-	str	r5, [r4, #GICC_CTLR]
-
-	mrc	p15, 0, r5, c1, c1, 0	@ Read SCR
-	orr	r5, r5, #4		@ Enable FIQ in monitor mode
-	bic	r5, r5, #1		@ Secure mode
-	mcr	p15, 0, r5, c1, c1, 0	@ Write SCR
-	isb
-
-	bl	psci_get_cpu_id		@ CPU ID => r0
-	bl	psci_get_cpu_stack_top	@ stack top => r0
-	mov	sp, r0
-
-	bx	r6
-
-	.globl psci_text_end
-psci_text_end:
-	.popsection
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [U-Boot] [PATCH v3 00/11] sunxi: PSCI implementation rewrite in C
  2016-06-07  2:54 [U-Boot] [PATCH v3 00/11] sunxi: PSCI implementation rewrite in C Chen-Yu Tsai
                   ` (10 preceding siblings ...)
  2016-06-07  2:54 ` [U-Boot] [PATCH v3 11/11] sunxi: Add PSCI implementation in C Chen-Yu Tsai
@ 2016-06-07  9:49 ` Marc Zyngier
  2016-06-07 10:04   ` Hans de Goede
  11 siblings, 1 reply; 20+ messages in thread
From: Marc Zyngier @ 2016-06-07  9:49 UTC (permalink / raw)
  To: u-boot

On Tue, 7 Jun 2016 10:54:23 +0800
Chen-Yu Tsai <wens@csie.org> wrote:

Hi Chen-Yu,

> Hi everyone,
> 
> This series rewrites the Allwinner/sunxi PSCI implementation in C, to make
> it easier to maintain and extend for the currently unsupported multi-cluster
> SoCs. The SMP code in the BSP kernels are in C. Having the PSCI code in C
> as well will make it easier to work on.
> 
> To be able to convert the platform bits to C, some common PSCI functions
> have to be fixed up according to the ARM calling conventions. Function
> declarations are also needed.
> 
> This series is based on sunxi/next. Parts of it will likely conflict with
> the effort to support PSCI 1.0 on the Freescale LS102xA.

[...]

Thanks a lot for doing this and for following up on the review
comments; I'm quite pleased with how it ended-up, so please put my 

Acked-by: Marc Zyngier <marc.zyngier@arm.com>

on all of these patches.

	M.
-- 
Jazz is not dead. It just smells funny.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [U-Boot] [PATCH v3 00/11] sunxi: PSCI implementation rewrite in C
  2016-06-07  9:49 ` [U-Boot] [PATCH v3 00/11] sunxi: PSCI implementation rewrite " Marc Zyngier
@ 2016-06-07 10:04   ` Hans de Goede
  2016-06-12 17:33     ` Tom Rini
  0 siblings, 1 reply; 20+ messages in thread
From: Hans de Goede @ 2016-06-07 10:04 UTC (permalink / raw)
  To: u-boot

Hi,

On 07-06-16 11:49, Marc Zyngier wrote:
> On Tue, 7 Jun 2016 10:54:23 +0800
> Chen-Yu Tsai <wens@csie.org> wrote:
>
> Hi Chen-Yu,
>
>> Hi everyone,
>>
>> This series rewrites the Allwinner/sunxi PSCI implementation in C, to make
>> it easier to maintain and extend for the currently unsupported multi-cluster
>> SoCs. The SMP code in the BSP kernels are in C. Having the PSCI code in C
>> as well will make it easier to work on.
>>
>> To be able to convert the platform bits to C, some common PSCI functions
>> have to be fixed up according to the ARM calling conventions. Function
>> declarations are also needed.
>>
>> This series is based on sunxi/next. Parts of it will likely conflict with
>> the effort to support PSCI 1.0 on the Freescale LS102xA.
>
> [...]
>
> Thanks a lot for doing this and for following up on the review
> comments; I'm quite pleased with how it ended-up, so please put my
>
> Acked-by: Marc Zyngier <marc.zyngier@arm.com>
>
> on all of these patches.

Cool. Chen-Yu, Marc thank you both for your hard work on this.

So what to do wrt merging this set, 2 questions:

1) Timing, v1 was posted in time for v2016.07, but given how far along
the cycle we are now I tend towards postponing this to v2016.09, note
I've no objections with this going into v2016.07 if people prefer that,
just putting the question out there.

2) Merging through which tree ?  I'm more then willing to merge this
through the sunxi tree, but it does touch some generic ARM files, so
if people prefer another merging strategy let me know.

Regards,

Hans

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [U-Boot] [PATCH v3 11/11] sunxi: Add PSCI implementation in C
  2016-06-07  2:54 ` [U-Boot] [PATCH v3 11/11] sunxi: Add PSCI implementation in C Chen-Yu Tsai
@ 2016-06-10 13:40   ` Hans de Goede
  2016-06-13  2:50     ` Chen-Yu Tsai
  0 siblings, 1 reply; 20+ messages in thread
From: Hans de Goede @ 2016-06-10 13:40 UTC (permalink / raw)
  To: u-boot

Hi,

On 07-06-16 04:54, Chen-Yu Tsai wrote:
> To make the PSCI backend more maintainable and easier to port to newer
> SoCs, rewrite the current PSCI implementation in C.
>
> Some inline assembly bits are required to access coprocessor registers.
> PSCI stack setup is the only part left completely in assembly. In theory
> this part could be split out of psci_arch_init into a separate common
> function, and psci_arch_init could be completely in C.
>
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>

I tried merging this in my tree to add it to u-boot-sunxi/next, but
unfortunately it triggers a bug in gcc-6.1, I've filed a bug with
gcc to get this fixed:

https://bugzilla.redhat.com/show_bug.cgi?id=1344717

Also cp15_read_scr / cp15_write_scr are missing __secure notations.

Regards,

Hans



> ---
>  arch/arm/cpu/armv7/sunxi/Makefile     |   7 +-
>  arch/arm/cpu/armv7/sunxi/psci.c       | 273 ++++++++++++++++++++++++++++++++++
>  arch/arm/cpu/armv7/sunxi/psci_head.S  |  66 ++++++++
>  arch/arm/cpu/armv7/sunxi/psci_sun6i.S | 262 --------------------------------
>  arch/arm/cpu/armv7/sunxi/psci_sun7i.S | 237 -----------------------------
>  5 files changed, 341 insertions(+), 504 deletions(-)
>  create mode 100644 arch/arm/cpu/armv7/sunxi/psci.c
>  create mode 100644 arch/arm/cpu/armv7/sunxi/psci_head.S
>  delete mode 100644 arch/arm/cpu/armv7/sunxi/psci_sun6i.S
>  delete mode 100644 arch/arm/cpu/armv7/sunxi/psci_sun7i.S
>
> diff --git a/arch/arm/cpu/armv7/sunxi/Makefile b/arch/arm/cpu/armv7/sunxi/Makefile
> index 4d2274a38ed1..c2085101685b 100644
> --- a/arch/arm/cpu/armv7/sunxi/Makefile
> +++ b/arch/arm/cpu/armv7/sunxi/Makefile
> @@ -13,11 +13,8 @@ obj-$(CONFIG_MACH_SUN6I)	+= tzpc.o
>  obj-$(CONFIG_MACH_SUN8I_H3)	+= tzpc.o
>
>  ifndef CONFIG_SPL_BUILD
> -ifdef CONFIG_ARMV7_PSCI
> -obj-$(CONFIG_MACH_SUN6I)	+= psci_sun6i.o
> -obj-$(CONFIG_MACH_SUN7I)	+= psci_sun7i.o
> -obj-$(CONFIG_MACH_SUN8I)	+= psci_sun6i.o
> -endif
> +obj-$(CONFIG_ARMV7_PSCI)	+= psci.o
> +obj-$(CONFIG_ARMV7_PSCI)	+= psci_head.o
>  endif
>
>  ifdef CONFIG_SPL_BUILD
> diff --git a/arch/arm/cpu/armv7/sunxi/psci.c b/arch/arm/cpu/armv7/sunxi/psci.c
> new file mode 100644
> index 000000000000..0059f4cbc9d6
> --- /dev/null
> +++ b/arch/arm/cpu/armv7/sunxi/psci.c
> @@ -0,0 +1,273 @@
> +/*
> + * Copyright (C) 2016
> + * Author: Chen-Yu Tsai <wens@csie.org>
> + *
> + * Based on assembly code by Marc Zyngier <marc.zyngier@arm.com>,
> + * which was based on code by Carl van Schaik <carl@ok-labs.com>.
> + *
> + * SPDX-License-Identifier:	GPL-2.0
> + */
> +#include <config.h>
> +#include <common.h>
> +
> +#include <asm/arch/cpu.h>
> +#include <asm/arch/cpucfg.h>
> +#include <asm/arch/prcm.h>
> +#include <asm/armv7.h>
> +#include <asm/gic.h>
> +#include <asm/io.h>
> +#include <asm/psci.h>
> +#include <asm/system.h>
> +
> +#include <linux/bitops.h>
> +
> +#define __secure	__attribute__ ((section ("._secure.text")))
> +#define __irq		__attribute__ ((interrupt ("IRQ")))
> +
> +#define	GICD_BASE	(SUNXI_GIC400_BASE + GIC_DIST_OFFSET)
> +#define	GICC_BASE	(SUNXI_GIC400_BASE + GIC_CPU_OFFSET_A15)
> +
> +static void __secure cp15_write_cntp_tval(u32 tval)
> +{
> +	asm volatile ("mcr p15, 0, %0, c14, c2, 0" : : "r" (tval));
> +}
> +
> +static void __secure cp15_write_cntp_ctl(u32 val)
> +{
> +	asm volatile ("mcr p15, 0, %0, c14, c2, 1" : : "r" (val));
> +}
> +
> +static u32 __secure cp15_read_cntp_ctl(void)
> +{
> +	u32 val;
> +
> +	asm volatile ("mrc p15, 0, %0, c14, c2, 1" : "=r" (val));
> +
> +	return val;
> +}
> +
> +#define ONE_MS (CONFIG_TIMER_CLK_FREQ / 1000)
> +
> +static void __secure __mdelay(u32 ms)
> +{
> +	u32 reg = ONE_MS * ms;
> +
> +	cp15_write_cntp_tval(reg);
> +	ISB;
> +	cp15_write_cntp_ctl(3);
> +
> +	do {
> +		ISB;
> +		reg = cp15_read_cntp_ctl();
> +	} while (!(reg & BIT(2)));
> +
> +	cp15_write_cntp_ctl(0);
> +	ISB;
> +}
> +
> +static void __secure clamp_release(u32 __maybe_unused *clamp)
> +{
> +#if defined(CONFIG_MACH_SUN6I) || defined(CONFIG_MACH_SUN7I) || \
> +	defined(CONFIG_MACH_SUN8I_H3)
> +	u32 tmp = 0x1ff;
> +	do {
> +		tmp >>= 1;
> +		writel(tmp, clamp);
> +	} while (tmp);
> +
> +	__mdelay(10);
> +#endif
> +}
> +
> +static void __secure clamp_set(u32 __maybe_unused *clamp)
> +{
> +#if defined(CONFIG_MACH_SUN6I) || defined(CONFIG_MACH_SUN7I) || \
> +	defined(CONFIG_MACH_SUN8I_H3)
> +	writel(0xff, clamp);
> +#endif
> +}
> +
> +static void __secure sunxi_power_switch(u32 *clamp, u32 *pwroff, bool on,
> +					int cpu)
> +{
> +	if (on) {
> +		/* Release power clamp */
> +		clamp_release(clamp);
> +
> +		/* Clear power gating */
> +		clrbits_le32(pwroff, BIT(cpu));
> +	} else {
> +		/* Set power gating */
> +		setbits_le32(pwroff, BIT(cpu));
> +
> +		/* Activate power clamp */
> +		clamp_set(clamp);
> +	}
> +}
> +
> +#ifdef CONFIG_MACH_SUN7I
> +/* sun7i (A20) is different from other single cluster SoCs */
> +static void __secure sunxi_cpu_set_power(int __always_unused cpu, bool on)
> +{
> +	struct sunxi_cpucfg_reg *cpucfg =
> +		(struct sunxi_cpucfg_reg *)SUNXI_CPUCFG_BASE;
> +
> +	sunxi_power_switch(&cpucfg->cpu1_pwr_clamp, &cpucfg->cpu1_pwroff,
> +			   on, 0);
> +}
> +#else /* ! CONFIG_MACH_SUN7I */
> +static void __secure sunxi_cpu_set_power(int cpu, bool on)
> +{
> +	struct sunxi_prcm_reg *prcm =
> +		(struct sunxi_prcm_reg *)SUNXI_PRCM_BASE;
> +
> +	sunxi_power_switch(&prcm->cpu_pwr_clamp[cpu], &prcm->cpu_pwroff,
> +			   on, cpu);
> +}
> +#endif /* CONFIG_MACH_SUN7I */
> +
> +void __secure sunxi_cpu_power_off(u32 cpuid)
> +{
> +	struct sunxi_cpucfg_reg *cpucfg =
> +		(struct sunxi_cpucfg_reg *)SUNXI_CPUCFG_BASE;
> +	u32 cpu = cpuid & 0x3;
> +
> +	/* Wait for the core to enter WFI */
> +	while (1) {
> +		if (readl(&cpucfg->cpu[cpu].status) & BIT(2))
> +			break;
> +		__mdelay(1);
> +	}
> +
> +	/* Assert reset on target CPU */
> +	writel(0, &cpucfg->cpu[cpu].rst);
> +
> +	/* Lock CPU (Disable external debug access) */
> +	clrbits_le32(&cpucfg->dbg_ctrl1, BIT(cpu));
> +
> +	/* Power down CPU */
> +	sunxi_cpu_set_power(cpuid, false);
> +
> +	/* Unlock CPU (Disable external debug access) */
> +	setbits_le32(&cpucfg->dbg_ctrl1, BIT(cpu));
> +}
> +
> +static u32 cp15_read_scr(void)
> +{
> +	u32 scr;
> +
> +	asm volatile ("mrc p15, 0, %0, c1, c1, 0" : "=r" (scr));
> +
> +	return scr;
> +}
> +
> +static void cp15_write_scr(u32 scr)
> +{
> +	asm volatile ("mcr p15, 0, %0, c1, c1, 0" : : "r" (scr));
> +	ISB;
> +}
> +
> +/*
> + * Although this is an FIQ handler, the FIQ is processed in monitor mode,
> + * which means there's no FIQ banked registers. This is the same as IRQ
> + * mode, so use the IRQ attribute to ask the compiler to handler entry
> + * and return.
> + */
> +void __secure __irq psci_fiq_enter(void)
> +{
> +	u32 scr, reg, cpu;
> +
> +	/* Switch to secure mode */
> +	scr = cp15_read_scr();
> +	cp15_write_scr(scr & ~BIT(0));
> +
> +	/* Validate reason based on IAR and acknowledge */
> +	reg = readl(GICC_BASE + GICC_IAR);
> +
> +	/* Skip spurious interrupts 1022 and 1023 */
> +	if (reg == 1023 || reg == 1022)
> +		goto out;
> +
> +	/* End of interrupt */
> +	writel(reg, GICC_BASE + GICC_EOIR);
> +	DSB;
> +
> +	/* Get CPU number */
> +	cpu = (reg >> 10) & 0x7;
> +
> +	/* Power off the CPU */
> +	sunxi_cpu_power_off(cpu);
> +
> +out:
> +	/* Restore security level */
> +	cp15_write_scr(scr);
> +}
> +
> +int __secure psci_cpu_on(u32 __always_unused unused, u32 mpidr, u32 pc)
> +{
> +	struct sunxi_cpucfg_reg *cpucfg =
> +		(struct sunxi_cpucfg_reg *)SUNXI_CPUCFG_BASE;
> +	u32 cpu = (mpidr & 0x3);
> +
> +	/* store target PC at target CPU stack top */
> +	writel(pc, psci_get_cpu_stack_top(cpu));
> +	DSB;
> +
> +	/* Set secondary core power on PC */
> +	writel((u32)&psci_cpu_entry, &cpucfg->priv0);
> +
> +	/* Assert reset on target CPU */
> +	writel(0, &cpucfg->cpu[cpu].rst);
> +
> +	/* Invalidate L1 cache */
> +	clrbits_le32(&cpucfg->gen_ctrl, BIT(cpu));
> +
> +	/* Lock CPU (Disable external debug access) */
> +	clrbits_le32(&cpucfg->dbg_ctrl1, BIT(cpu));
> +
> +	/* Power up target CPU */
> +	sunxi_cpu_set_power(cpu, true);
> +
> +	/* De-assert reset on target CPU */
> +	writel(BIT(1) | BIT(0), &cpucfg->cpu[cpu].rst);
> +
> +	/* Unlock CPU (Disable external debug access) */
> +	setbits_le32(&cpucfg->dbg_ctrl1, BIT(cpu));
> +
> +	return ARM_PSCI_RET_SUCCESS;
> +}
> +
> +void __secure psci_cpu_off(void)
> +{
> +	psci_cpu_off_common();
> +
> +	/* Ask CPU0 via SGI15 to pull the rug... */
> +	writel(BIT(16) | 15, GICD_BASE + GICD_SGIR);
> +	DSB;
> +
> +	/* Wait to be turned off */
> +	while (1)
> +		wfi();
> +}
> +
> +void __secure sunxi_gic_init(void)
> +{
> +	u32 reg;
> +
> +	/* SGI15 as Group-0 */
> +	clrbits_le32(GICD_BASE + GICD_IGROUPRn, BIT(15));
> +
> +	/* Set SGI15 priority to 0 */
> +	writeb(0, GICD_BASE + GICD_IPRIORITYRn + 15);
> +
> +	/* Be cool with non-secure */
> +	writel(0xff, GICC_BASE + GICC_PMR);
> +
> +	/* Switch FIQEn on */
> +	setbits_le32(GICC_BASE + GICC_CTLR, BIT(3));
> +
> +	reg = cp15_read_scr();
> +	reg |= BIT(2);  /* Enable FIQ in monitor mode */
> +	reg &= ~BIT(0); /* Secure mode */
> +	cp15_write_scr(reg);
> +}
> diff --git a/arch/arm/cpu/armv7/sunxi/psci_head.S b/arch/arm/cpu/armv7/sunxi/psci_head.S
> new file mode 100644
> index 000000000000..8fa823d1df3a
> --- /dev/null
> +++ b/arch/arm/cpu/armv7/sunxi/psci_head.S
> @@ -0,0 +1,66 @@
> +/*
> + * Copyright (C) 2013 - ARM Ltd
> + * Author: Marc Zyngier <marc.zyngier@arm.com>
> + *
> + * Based on code by Carl van Schaik <carl@ok-labs.com>.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <config.h>
> +#include <linux/linkage.h>
> +
> +#include <asm/arch-armv7/generictimer.h>
> +#include <asm/gic.h>
> +#include <asm/macro.h>
> +#include <asm/psci.h>
> +#include <asm/arch/cpu.h>
> +
> +/*
> + * Memory layout:
> + *
> + * SECURE_RAM to text_end :
> + *	._secure_text section
> + * text_end to ALIGN_PAGE(text_end):
> + *	nothing
> + * ALIGN_PAGE(text_end) to ALIGN_PAGE(text_end) + 0x1000)
> + *	1kB of stack per CPU (4 CPUs max).
> + */
> +
> +	.pushsection ._secure.text, "ax"
> +
> +	.arch_extension sec
> +
> +#define	GICD_BASE		(SUNXI_GIC400_BASE +  0x1000)
> +#define	GICC_BASE		(SUNXI_GIC400_BASE +  0x2000)
> +
> +@ {r0, r1, r2, ip} from _do_nonsec_entry(kernel_entry, 0, machid, r2) in
> +@ arch/arm/lib/bootm.c:boot_jump_linux() must remain unchanged across
> +@ this function.
> +ENTRY(psci_arch_init)
> +	mov	r6, lr
> +	mov	r7, r0
> +	bl	psci_get_cpu_id		@ CPU ID => r0
> +	bl	psci_get_cpu_stack_top	@ stack top => r0
> +	sub	r0, r0, #4		@ Save space for target PC
> +	mov	sp, r0
> +	mov	r0, r7
> +	mov	lr, r6
> +
> +	push	{r0, r1, r2, ip, lr}
> +	bl	sunxi_gic_init
> +	pop	{r0, r1, r2, ip, pc}
> +ENDPROC(psci_arch_init)
> +
> +ENTRY(psci_text_end)
> +	.popsection
> diff --git a/arch/arm/cpu/armv7/sunxi/psci_sun6i.S b/arch/arm/cpu/armv7/sunxi/psci_sun6i.S
> deleted file mode 100644
> index 95fdb0e58874..000000000000
> --- a/arch/arm/cpu/armv7/sunxi/psci_sun6i.S
> +++ /dev/null
> @@ -1,262 +0,0 @@
> -/*
> - * Copyright (C) 2015 - Chen-Yu Tsai
> - * Author: Chen-Yu Tsai <wens@csie.org>
> - *
> - * Based on psci_sun7i.S by Marc Zyngier <marc.zyngier@arm.com>
> - *
> - * This program is free software; you can redistribute it and/or modify
> - * it under the terms of the GNU General Public License version 2 as
> - * published by the Free Software Foundation.
> - *
> - * This program is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> - * GNU General Public License for more details.
> - *
> - * You should have received a copy of the GNU General Public License
> - * along with this program.  If not, see <http://www.gnu.org/licenses/>.
> - */
> -
> -#include <config.h>
> -
> -#include <asm/arch-armv7/generictimer.h>
> -#include <asm/gic.h>
> -#include <asm/macro.h>
> -#include <asm/psci.h>
> -#include <asm/arch/cpu.h>
> -
> -/*
> - * Memory layout:
> - *
> - * SECURE_RAM to text_end :
> - *	._secure_text section
> - * text_end to ALIGN_PAGE(text_end):
> - *	nothing
> - * ALIGN_PAGE(text_end) to ALIGN_PAGE(text_end) + 0x1000)
> - *	1kB of stack per CPU (4 CPUs max).
> - */
> -
> -	.pushsection ._secure.text, "ax"
> -
> -	.arch_extension sec
> -
> -#define	ONE_MS			(CONFIG_TIMER_CLK_FREQ / 1000)
> -#define	TEN_MS			(10 * ONE_MS)
> -#define	GICD_BASE		(SUNXI_GIC400_BASE +  0x1000)
> -#define	GICC_BASE		(SUNXI_GIC400_BASE +  0x2000)
> -
> -.globl	psci_fiq_enter
> -psci_fiq_enter:
> -	push	{r0-r12}
> -
> -	@ Switch to secure
> -	mrc	p15, 0, r7, c1, c1, 0
> -	bic	r8, r7, #1
> -	mcr	p15, 0, r8, c1, c1, 0
> -	isb
> -
> -	@ Validate reason based on IAR and acknowledge
> -	movw	r8, #(GICC_BASE & 0xffff)
> -	movt	r8, #(GICC_BASE >> 16)
> -	ldr	r9, [r8, #GICC_IAR]
> -	movw	r10, #0x3ff
> -	movt	r10, #0
> -	cmp	r9, r10			@ skip spurious interrupt 1023
> -	beq	out
> -	movw	r10, #0x3fe		@ ...and 1022
> -	cmp	r9, r10
> -	beq	out
> -	str	r9, [r8, #GICC_EOIR]	@ acknowledge the interrupt
> -	dsb
> -
> -	@ Compute CPU number
> -	lsr	r9, r9, #10
> -	and	r9, r9, #0xf
> -
> -	movw	r8, #(SUNXI_CPUCFG_BASE & 0xffff)
> -	movt	r8, #(SUNXI_CPUCFG_BASE >> 16)
> -
> -	@ Wait for the core to enter WFI
> -	lsl	r11, r9, #6		@ x64
> -	add	r11, r11, r8
> -
> -1:	ldr	r10, [r11, #0x48]
> -	tst	r10, #(1 << 2)
> -	bne	2f
> -	timer_wait r10, ONE_MS
> -	b	1b
> -
> -	@ Reset CPU
> -2:	mov	r10, #0
> -	str	r10, [r11, #0x40]
> -
> -	@ Lock CPU
> -	mov	r10, #1
> -	lsl	r11, r10, r9		@ r11 is now CPU mask
> -	ldr	r10, [r8, #0x1e4]
> -	bic	r10, r10, r11
> -	str	r10, [r8, #0x1e4]
> -
> -	movw	r8, #(SUNXI_PRCM_BASE & 0xffff)
> -	movt	r8, #(SUNXI_PRCM_BASE >> 16)
> -
> -	@ Set power gating
> -	ldr	r10, [r8, #0x100]
> -	orr	r10, r10, r11
> -	str	r10, [r8, #0x100]
> -	timer_wait r10, ONE_MS
> -
> -#if defined(CONFIG_MACH_SUN6I) || defined(CONFIG_MACH_SUN8I_H3)
> -	@ Activate power clamp
> -	lsl	r12, r9, #2		@ x4
> -	add	r12, r12, r8
> -	mov	r10, #0xff
> -	str	r10, [r12, #0x140]
> -#endif
> -
> -	movw	r8, #(SUNXI_CPUCFG_BASE & 0xffff)
> -	movt	r8, #(SUNXI_CPUCFG_BASE >> 16)
> -
> -	@ Unlock CPU
> -	ldr	r10, [r8, #0x1e4]
> -	orr	r10, r10, r11
> -	str	r10, [r8, #0x1e4]
> -
> -	@ Restore security level
> -out:	mcr	p15, 0, r7, c1, c1, 0
> -
> -	pop	{r0-r12}
> -	subs    pc, lr, #4
> -
> -	@ r1 = target CPU
> -	@ r2 = target PC
> -.globl	psci_cpu_on
> -psci_cpu_on:
> -	push	{lr}
> -
> -	mov	r0, r1
> -	bl	psci_get_cpu_stack_top	@ get stack top of target CPU
> -	str	r2, [r0]		@ store target PC at stack top
> -	dsb
> -
> -	movw	r0, #(SUNXI_CPUCFG_BASE & 0xffff)
> -	movt	r0, #(SUNXI_CPUCFG_BASE >> 16)
> -
> -	@ CPU mask
> -	and	r1, r1, #3	@ only care about first cluster
> -	mov	r4, #1
> -	lsl	r4, r4, r1
> -
> -	ldr	r6, =psci_cpu_entry
> -	str	r6, [r0, #0x1a4] @ PRIVATE_REG (boot vector)
> -
> -	@ Assert reset on target CPU
> -	mov	r6, #0
> -	lsl	r5, r1, #6	@ 64 bytes per CPU
> -	add	r5, r5, #0x40	@ Offset from base
> -	add	r5, r5, r0	@ CPU control block
> -	str	r6, [r5]	@ Reset CPU
> -
> -	@ l1 invalidate
> -	ldr	r6, [r0, #0x184] @ CPUCFG_GEN_CTRL_REG
> -	bic	r6, r6, r4
> -	str	r6, [r0, #0x184]
> -
> -	@ Lock CPU (Disable external debug access)
> -	ldr	r6, [r0, #0x1e4] @ CPUCFG_DBG_CTL1_REG
> -	bic	r6, r6, r4
> -	str	r6, [r0, #0x1e4]
> -
> -	movw	r0, #(SUNXI_PRCM_BASE & 0xffff)
> -	movt	r0, #(SUNXI_PRCM_BASE >> 16)
> -
> -#if defined(CONFIG_MACH_SUN6I) || defined(CONFIG_MACH_SUN8I_H3)
> -	@ Release power clamp
> -	lsl	r5, r1, #2	@ 1 register per CPU
> -	add	r5, r5, r0	@ PRCM
> -	movw	r6, #0x1ff
> -	movt	r6, #0
> -1:	lsrs	r6, r6, #1
> -	str	r6, [r5, #0x140] @ CPUx_PWR_CLAMP
> -	bne	1b
> -#endif
> -
> -	timer_wait r6, TEN_MS
> -
> -	@ Clear power gating
> -	ldr	r6, [r0, #0x100] @ CPU_PWROFF_GATING
> -	bic	r6, r6, r4
> -	str	r6, [r0, #0x100]
> -
> -	@ re-calculate CPU control register address
> -	movw	r0, #(SUNXI_CPUCFG_BASE & 0xffff)
> -	movt	r0, #(SUNXI_CPUCFG_BASE >> 16)
> -
> -	@ Deassert reset on target CPU
> -	mov	r6, #3
> -	lsl	r5, r1, #6	@ 64 bytes per CPU
> -	add	r5, r5, #0x40	@ Offset from base
> -	add	r5, r5, r0	@ CPU control block
> -	str	r6, [r5]
> -
> -	@ Unlock CPU (Enable external debug access)
> -	ldr	r6, [r0, #0x1e4] @ CPUCFG_DBG_CTL1_REG
> -	orr	r6, r6, r4
> -	str	r6, [r0, #0x1e4]
> -
> -	mov	r0, #ARM_PSCI_RET_SUCCESS	@ Return PSCI_RET_SUCCESS
> -	pop	{pc}
> -
> -.globl	psci_cpu_off
> -psci_cpu_off:
> -	bl	psci_cpu_off_common
> -
> -	@ Ask CPU0 to pull the rug...
> -	movw	r0, #(GICD_BASE & 0xffff)
> -	movt	r0, #(GICD_BASE >> 16)
> -	movw	r1, #15				@ SGI15
> -	movt	r1, #1				@ Target is CPU0
> -	str	r1, [r0, #GICD_SGIR]
> -	dsb
> -
> -1:	wfi
> -	b	1b
> -
> -.globl	psci_arch_init
> -psci_arch_init:
> -	mov	r6, lr
> -
> -	movw	r4, #(GICD_BASE & 0xffff)
> -	movt	r4, #(GICD_BASE >> 16)
> -
> -	ldr	r5, [r4, #GICD_IGROUPRn]
> -	bic	r5, r5, #(1 << 15) 	@ SGI15 as Group-0
> -	str	r5, [r4, #GICD_IGROUPRn]
> -
> -	mov	r5, #0			@ Set SGI15 priority to 0
> -	strb	r5, [r4, #(GICD_IPRIORITYRn + 15)]
> -
> -	add	r4, r4, #0x1000		@ GICC address
> -
> -	mov	r5, #0xff
> -	str	r5, [r4, #GICC_PMR]	@ Be cool with non-secure
> -
> -	ldr	r5, [r4, #GICC_CTLR]
> -	orr	r5, r5, #(1 << 3)	@ Switch FIQEn on
> -	str	r5, [r4, #GICC_CTLR]
> -
> -	mrc	p15, 0, r5, c1, c1, 0	@ Read SCR
> -	orr	r5, r5, #4		@ Enable FIQ in monitor mode
> -	bic	r5, r5, #1		@ Secure mode
> -	mcr	p15, 0, r5, c1, c1, 0	@ Write SCR
> -	isb
> -
> -	bl	psci_get_cpu_id		@ CPU ID => r0
> -	bl	psci_get_cpu_stack_top	@ stack top => r0
> -	mov	sp, r0
> -
> -	bx	r6
> -
> -	.globl psci_text_end
> -psci_text_end:
> -	.popsection
> diff --git a/arch/arm/cpu/armv7/sunxi/psci_sun7i.S b/arch/arm/cpu/armv7/sunxi/psci_sun7i.S
> deleted file mode 100644
> index 87bbd725f0b3..000000000000
> --- a/arch/arm/cpu/armv7/sunxi/psci_sun7i.S
> +++ /dev/null
> @@ -1,237 +0,0 @@
> -/*
> - * Copyright (C) 2013 - ARM Ltd
> - * Author: Marc Zyngier <marc.zyngier@arm.com>
> - *
> - * Based on code by Carl van Schaik <carl@ok-labs.com>.
> - *
> - * This program is free software; you can redistribute it and/or modify
> - * it under the terms of the GNU General Public License version 2 as
> - * published by the Free Software Foundation.
> - *
> - * This program is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> - * GNU General Public License for more details.
> - *
> - * You should have received a copy of the GNU General Public License
> - * along with this program.  If not, see <http://www.gnu.org/licenses/>.
> - */
> -
> -#include <config.h>
> -
> -#include <asm/arch-armv7/generictimer.h>
> -#include <asm/gic.h>
> -#include <asm/macro.h>
> -#include <asm/psci.h>
> -#include <asm/arch/cpu.h>
> -
> -/*
> - * Memory layout:
> - *
> - * SECURE_RAM to text_end :
> - *	._secure_text section
> - * text_end to ALIGN_PAGE(text_end):
> - *	nothing
> - * ALIGN_PAGE(text_end) to ALIGN_PAGE(text_end) + 0x1000)
> - *	1kB of stack per CPU (4 CPUs max).
> - */
> -
> -	.pushsection ._secure.text, "ax"
> -
> -	.arch_extension sec
> -
> -#define	ONE_MS			(CONFIG_TIMER_CLK_FREQ / 1000)
> -#define	TEN_MS			(10 * ONE_MS)
> -#define	GICD_BASE		(SUNXI_GIC400_BASE +  0x1000)
> -#define	GICC_BASE		(SUNXI_GIC400_BASE +  0x2000)
> -
> -.globl	psci_fiq_enter
> -psci_fiq_enter:
> -	push	{r0-r12}
> -
> -	@ Switch to secure
> -	mrc	p15, 0, r7, c1, c1, 0
> -	bic	r8, r7, #1
> -	mcr	p15, 0, r8, c1, c1, 0
> -	isb
> -
> -	@ Validate reason based on IAR and acknowledge
> -	movw	r8, #(GICC_BASE & 0xffff)
> -	movt	r8, #(GICC_BASE >> 16)
> -	ldr	r9, [r8, #GICC_IAR]
> -	movw	r10, #0x3ff
> -	movt	r10, #0
> -	cmp	r9, r10			@ skip spurious interrupt 1023
> -	beq	out
> -	movw	r10, #0x3fe		@ ...and 1022
> -	cmp	r9, r10
> -	beq	out
> -	str	r9, [r8, #GICC_EOIR]	@ acknowledge the interrupt
> -	dsb
> -
> -	@ Compute CPU number
> -	lsr	r9, r9, #10
> -	and	r9, r9, #0xf
> -
> -	movw	r8, #(SUNXI_CPUCFG_BASE & 0xffff)
> -	movt	r8, #(SUNXI_CPUCFG_BASE >> 16)
> -
> -	@ Wait for the core to enter WFI
> -	lsl	r11, r9, #6		@ x64
> -	add	r11, r11, r8
> -
> -1:	ldr	r10, [r11, #0x48]
> -	tst	r10, #(1 << 2)
> -	bne	2f
> -	timer_wait r10, ONE_MS
> -	b	1b
> -
> -	@ Reset CPU
> -2:	mov	r10, #0
> -	str	r10, [r11, #0x40]
> -
> -	@ Lock CPU
> -	mov	r10, #1
> -	lsl	r9, r10, r9		@ r9 is now CPU mask
> -	ldr	r10, [r8, #0x1e4]
> -	bic	r10, r10, r9
> -	str	r10, [r8, #0x1e4]
> -
> -	@ Set power gating
> -	ldr	r10, [r8, #0x1b4]
> -	orr	r10, r10, #1
> -	str	r10, [r8, #0x1b4]
> -	timer_wait r10, ONE_MS
> -
> -	@ Activate power clamp
> -	mov	r10, #1
> -1:	str	r10, [r8, #0x1b0]
> -	lsl	r10, r10, #1
> -	orr	r10, r10, #1
> -	tst	r10, #0x100
> -	beq	1b
> -
> -	@ Restore security level
> -out:	mcr	p15, 0, r7, c1, c1, 0
> -
> -	pop	{r0-r12}
> -	subs    pc, lr, #4
> -
> -	@ r1 = target CPU
> -	@ r2 = target PC
> -.globl	psci_cpu_on
> -psci_cpu_on:
> -	push	{lr}
> -
> -	mov	r0, r1
> -	bl	psci_get_cpu_stack_top	@ get stack top of target CPU
> -	str	r2, [r0]		@ store target PC at stack top
> -	dsb
> -
> -	movw	r0, #(SUNXI_CPUCFG_BASE & 0xffff)
> -	movt	r0, #(SUNXI_CPUCFG_BASE >> 16)
> -
> -	@ CPU mask
> -	and	r1, r1, #3	@ only care about first cluster
> -	mov	r4, #1
> -	lsl	r4, r4, r1
> -
> -	ldr	r6, =psci_cpu_entry
> -	str	r6, [r0, #0x1a4] @ PRIVATE_REG (boot vector)
> -
> -	@ Assert reset on target CPU
> -	mov	r6, #0
> -	lsl	r5, r1, #6	@ 64 bytes per CPU
> -	add	r5, r5, #0x40	@ Offset from base
> -	add	r5, r5, r0	@ CPU control block
> -	str	r6, [r5]	@ Reset CPU
> -
> -	@ l1 invalidate
> -	ldr	r6, [r0, #0x184] @ CPUCFG_GEN_CTRL_REG
> -	bic	r6, r6, r4
> -	str	r6, [r0, #0x184]
> -
> -	@ Lock CPU (Disable external debug access)
> -	ldr	r6, [r0, #0x1e4] @ CPUCFG_DBG_CTL1_REG
> -	bic	r6, r6, r4
> -	str	r6, [r0, #0x1e4]
> -
> -	@ Release power clamp
> -	movw	r6, #0x1ff
> -	movt	r6, #0
> -1:	lsrs	r6, r6, #1
> -	str	r6, [r0, #0x1b0] @ CPU1_PWR_CLAMP
> -	bne	1b
> -
> -	timer_wait r1, TEN_MS
> -
> -	@ Clear power gating
> -	ldr	r6, [r0, #0x1b4] @ CPU1_PWROFF_REG
> -	bic	r6, r6, #1
> -	str	r6, [r0, #0x1b4]
> -
> -	@ Deassert reset on target CPU
> -	mov	r6, #3
> -	str	r6, [r5]
> -
> -	@ Unlock CPU (Enable external debug access)
> -	ldr	r6, [r0, #0x1e4] @ CPUCFG_DBG_CTL1_REG
> -	orr	r6, r6, r4
> -	str	r6, [r0, #0x1e4]
> -
> -	mov	r0, #ARM_PSCI_RET_SUCCESS	@ Return PSCI_RET_SUCCESS
> -	pop	{pc}
> -
> -.globl	psci_cpu_off
> -psci_cpu_off:
> -	bl	psci_cpu_off_common
> -
> -	@ Ask CPU0 to pull the rug...
> -	movw	r0, #(GICD_BASE & 0xffff)
> -	movt	r0, #(GICD_BASE >> 16)
> -	movw	r1, #15				@ SGI15
> -	movt	r1, #1				@ Target is CPU0
> -	str	r1, [r0, #GICD_SGIR]
> -	dsb
> -
> -1:	wfi
> -	b	1b
> -
> -.globl	psci_arch_init
> -psci_arch_init:
> -	mov	r6, lr
> -
> -	movw	r4, #(GICD_BASE & 0xffff)
> -	movt	r4, #(GICD_BASE >> 16)
> -
> -	ldr	r5, [r4, #GICD_IGROUPRn]
> -	bic	r5, r5, #(1 << 15) 	@ SGI15 as Group-0
> -	str	r5, [r4, #GICD_IGROUPRn]
> -
> -	mov	r5, #0			@ Set SGI15 priority to 0
> -	strb	r5, [r4, #(GICD_IPRIORITYRn + 15)]
> -
> -	add	r4, r4, #0x1000		@ GICC address
> -
> -	mov	r5, #0xff
> -	str	r5, [r4, #GICC_PMR]	@ Be cool with non-secure
> -
> -	ldr	r5, [r4, #GICC_CTLR]
> -	orr	r5, r5, #(1 << 3)	@ Switch FIQEn on
> -	str	r5, [r4, #GICC_CTLR]
> -
> -	mrc	p15, 0, r5, c1, c1, 0	@ Read SCR
> -	orr	r5, r5, #4		@ Enable FIQ in monitor mode
> -	bic	r5, r5, #1		@ Secure mode
> -	mcr	p15, 0, r5, c1, c1, 0	@ Write SCR
> -	isb
> -
> -	bl	psci_get_cpu_id		@ CPU ID => r0
> -	bl	psci_get_cpu_stack_top	@ stack top => r0
> -	mov	sp, r0
> -
> -	bx	r6
> -
> -	.globl psci_text_end
> -psci_text_end:
> -	.popsection
>

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [U-Boot] [PATCH v3 00/11] sunxi: PSCI implementation rewrite in C
  2016-06-07 10:04   ` Hans de Goede
@ 2016-06-12 17:33     ` Tom Rini
  0 siblings, 0 replies; 20+ messages in thread
From: Tom Rini @ 2016-06-12 17:33 UTC (permalink / raw)
  To: u-boot

On Tue, Jun 07, 2016 at 12:04:20PM +0200, Hans de Goede wrote:
> Hi,
> 
> On 07-06-16 11:49, Marc Zyngier wrote:
> >On Tue, 7 Jun 2016 10:54:23 +0800
> >Chen-Yu Tsai <wens@csie.org> wrote:
> >
> >Hi Chen-Yu,
> >
> >>Hi everyone,
> >>
> >>This series rewrites the Allwinner/sunxi PSCI implementation in C, to make
> >>it easier to maintain and extend for the currently unsupported multi-cluster
> >>SoCs. The SMP code in the BSP kernels are in C. Having the PSCI code in C
> >>as well will make it easier to work on.
> >>
> >>To be able to convert the platform bits to C, some common PSCI functions
> >>have to be fixed up according to the ARM calling conventions. Function
> >>declarations are also needed.
> >>
> >>This series is based on sunxi/next. Parts of it will likely conflict with
> >>the effort to support PSCI 1.0 on the Freescale LS102xA.
> >
> >[...]
> >
> >Thanks a lot for doing this and for following up on the review
> >comments; I'm quite pleased with how it ended-up, so please put my
> >
> >Acked-by: Marc Zyngier <marc.zyngier@arm.com>
> >
> >on all of these patches.
> 
> Cool. Chen-Yu, Marc thank you both for your hard work on this.
> 
> So what to do wrt merging this set, 2 questions:
> 
> 1) Timing, v1 was posted in time for v2016.07, but given how far along
> the cycle we are now I tend towards postponing this to v2016.09, note
> I've no objections with this going into v2016.07 if people prefer that,
> just putting the question out there.
> 
> 2) Merging through which tree ?  I'm more then willing to merge this
> through the sunxi tree, but it does touch some generic ARM files, so
> if people prefer another merging strategy let me know.

I'm OK with now'ish and the sunxi tree, this seems both important enough
and well thought out enough to be safe enough to grab here.

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160612/3d4c2664/attachment.sig>

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [U-Boot] [PATCH v3 11/11] sunxi: Add PSCI implementation in C
  2016-06-10 13:40   ` Hans de Goede
@ 2016-06-13  2:50     ` Chen-Yu Tsai
  2016-06-13  9:49       ` Hans de Goede
  0 siblings, 1 reply; 20+ messages in thread
From: Chen-Yu Tsai @ 2016-06-13  2:50 UTC (permalink / raw)
  To: u-boot

On Fri, Jun 10, 2016 at 9:40 PM, Hans de Goede <hdegoede@redhat.com> wrote:
> Hi,
>
> On 07-06-16 04:54, Chen-Yu Tsai wrote:
>>
>> To make the PSCI backend more maintainable and easier to port to newer
>> SoCs, rewrite the current PSCI implementation in C.
>>
>> Some inline assembly bits are required to access coprocessor registers.
>> PSCI stack setup is the only part left completely in assembly. In theory
>> this part could be split out of psci_arch_init into a separate common
>> function, and psci_arch_init could be completely in C.
>>
>> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
>
>
> I tried merging this in my tree to add it to u-boot-sunxi/next, but
> unfortunately it triggers a bug in gcc-6.1, I've filed a bug with
> gcc to get this fixed:
>
> https://bugzilla.redhat.com/show_bug.cgi?id=1344717

Interesting. Seems like the compiler should be emitting LDMFD instead
of POP, or a POP followed by a SUBS/MOVS.

>
> Also cp15_read_scr / cp15_write_scr are missing __secure notations.

Do you want me to send a new version for this?

ChenYu

> Regards,
>
> Hans

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [U-Boot] [PATCH v3 11/11] sunxi: Add PSCI implementation in C
  2016-06-13  2:50     ` Chen-Yu Tsai
@ 2016-06-13  9:49       ` Hans de Goede
  2016-06-13 10:58         ` Chen-Yu Tsai
  0 siblings, 1 reply; 20+ messages in thread
From: Hans de Goede @ 2016-06-13  9:49 UTC (permalink / raw)
  To: u-boot

Hi,

On 13-06-16 04:50, Chen-Yu Tsai wrote:
> On Fri, Jun 10, 2016 at 9:40 PM, Hans de Goede <hdegoede@redhat.com> wrote:
>> Hi,
>>
>> On 07-06-16 04:54, Chen-Yu Tsai wrote:
>>>
>>> To make the PSCI backend more maintainable and easier to port to newer
>>> SoCs, rewrite the current PSCI implementation in C.
>>>
>>> Some inline assembly bits are required to access coprocessor registers.
>>> PSCI stack setup is the only part left completely in assembly. In theory
>>> this part could be split out of psci_arch_init into a separate common
>>> function, and psci_arch_init could be completely in C.
>>>
>>> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
>>
>>
>> I tried merging this in my tree to add it to u-boot-sunxi/next, but
>> unfortunately it triggers a bug in gcc-6.1, I've filed a bug with
>> gcc to get this fixed:
>>
>> https://bugzilla.redhat.com/show_bug.cgi?id=1344717
>
> Interesting. Seems like the compiler should be emitting LDMFD instead
> of POP, or a POP followed by a SUBS/MOVS.
>
>>
>> Also cp15_read_scr / cp15_write_scr are missing __secure notations.
>
> Do you want me to send a new version for this?

No, I already have a local branch with this fixed.

As for getting this merged and Tom's "go for it"
comment earlier, I consider this a blocker for merging, sorry.

I hope that the gcc folks can resolve this soon and that I can
get the Fedora devs to deploy a fix soon-ish. I'm not sure what
other distros are doing wrt jumping to gcc-6.1, but having code
in u-boot master which does not build with the latest gcc seems
like a bad idea.

Regards,

Hans

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [U-Boot] [PATCH v3 11/11] sunxi: Add PSCI implementation in C
  2016-06-13  9:49       ` Hans de Goede
@ 2016-06-13 10:58         ` Chen-Yu Tsai
  2016-06-13 15:40           ` Hans de Goede
  0 siblings, 1 reply; 20+ messages in thread
From: Chen-Yu Tsai @ 2016-06-13 10:58 UTC (permalink / raw)
  To: u-boot

On Mon, Jun 13, 2016 at 5:49 PM, Hans de Goede <hdegoede@redhat.com> wrote:
> Hi,
>
> On 13-06-16 04:50, Chen-Yu Tsai wrote:
>>
>> On Fri, Jun 10, 2016 at 9:40 PM, Hans de Goede <hdegoede@redhat.com>
>> wrote:
>>>
>>> Hi,
>>>
>>> On 07-06-16 04:54, Chen-Yu Tsai wrote:
>>>>
>>>>
>>>> To make the PSCI backend more maintainable and easier to port to newer
>>>> SoCs, rewrite the current PSCI implementation in C.
>>>>
>>>> Some inline assembly bits are required to access coprocessor registers.
>>>> PSCI stack setup is the only part left completely in assembly. In theory
>>>> this part could be split out of psci_arch_init into a separate common
>>>> function, and psci_arch_init could be completely in C.
>>>>
>>>> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
>>>
>>>
>>>
>>> I tried merging this in my tree to add it to u-boot-sunxi/next, but
>>> unfortunately it triggers a bug in gcc-6.1, I've filed a bug with
>>> gcc to get this fixed:
>>>
>>> https://bugzilla.redhat.com/show_bug.cgi?id=1344717
>>
>>
>> Interesting. Seems like the compiler should be emitting LDMFD instead
>> of POP, or a POP followed by a SUBS/MOVS.
>>
>>>
>>> Also cp15_read_scr / cp15_write_scr are missing __secure notations.
>>
>>
>> Do you want me to send a new version for this?
>
>
> No, I already have a local branch with this fixed.
>
> As for getting this merged and Tom's "go for it"
> comment earlier, I consider this a blocker for merging, sorry.
>
> I hope that the gcc folks can resolve this soon and that I can
> get the Fedora devs to deploy a fix soon-ish. I'm not sure what
> other distros are doing wrt jumping to gcc-6.1, but having code
> in u-boot master which does not build with the latest gcc seems
> like a bad idea.

This is marked as resolved upstream:

    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70830

And Debian/Ubuntu seems to have pulled the fix into their latest
unstable package:

    http://metadata.ftp-master.debian.org/changelogs//main/g/gcc-6/gcc-6_6.1.1-6_changelog

I'm not familiar with Fedora, though you could reference the GCC
PR I listed above and have them pull in the fix.

Interesting that Fedora only provides one version of GCC though.

Regards
ChenYu

>
> Regards,
>
> Hans

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [U-Boot] [PATCH v3 11/11] sunxi: Add PSCI implementation in C
  2016-06-13 10:58         ` Chen-Yu Tsai
@ 2016-06-13 15:40           ` Hans de Goede
  0 siblings, 0 replies; 20+ messages in thread
From: Hans de Goede @ 2016-06-13 15:40 UTC (permalink / raw)
  To: u-boot

Hi,

On 13-06-16 12:58, Chen-Yu Tsai wrote:
> On Mon, Jun 13, 2016 at 5:49 PM, Hans de Goede <hdegoede@redhat.com> wrote:
>> Hi,
>>
>> On 13-06-16 04:50, Chen-Yu Tsai wrote:
>>>
>>> On Fri, Jun 10, 2016 at 9:40 PM, Hans de Goede <hdegoede@redhat.com>
>>> wrote:
>>>>
>>>> Hi,
>>>>
>>>> On 07-06-16 04:54, Chen-Yu Tsai wrote:
>>>>>
>>>>>
>>>>> To make the PSCI backend more maintainable and easier to port to newer
>>>>> SoCs, rewrite the current PSCI implementation in C.
>>>>>
>>>>> Some inline assembly bits are required to access coprocessor registers.
>>>>> PSCI stack setup is the only part left completely in assembly. In theory
>>>>> this part could be split out of psci_arch_init into a separate common
>>>>> function, and psci_arch_init could be completely in C.
>>>>>
>>>>> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
>>>>
>>>>
>>>>
>>>> I tried merging this in my tree to add it to u-boot-sunxi/next, but
>>>> unfortunately it triggers a bug in gcc-6.1, I've filed a bug with
>>>> gcc to get this fixed:
>>>>
>>>> https://bugzilla.redhat.com/show_bug.cgi?id=1344717
>>>
>>>
>>> Interesting. Seems like the compiler should be emitting LDMFD instead
>>> of POP, or a POP followed by a SUBS/MOVS.
>>>
>>>>
>>>> Also cp15_read_scr / cp15_write_scr are missing __secure notations.
>>>
>>>
>>> Do you want me to send a new version for this?
>>
>>
>> No, I already have a local branch with this fixed.
>>
>> As for getting this merged and Tom's "go for it"
>> comment earlier, I consider this a blocker for merging, sorry.
>>
>> I hope that the gcc folks can resolve this soon and that I can
>> get the Fedora devs to deploy a fix soon-ish. I'm not sure what
>> other distros are doing wrt jumping to gcc-6.1, but having code
>> in u-boot master which does not build with the latest gcc seems
>> like a bad idea.
>
> This is marked as resolved upstream:
>
>     https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70830
>
> And Debian/Ubuntu seems to have pulled the fix into their latest
> unstable package:
>
>     http://metadata.ftp-master.debian.org/changelogs//main/g/gcc-6/gcc-6_6.1.1-6_changelog
>
> I'm not familiar with Fedora, though you could reference the GCC
> PR I listed above and have them pull in the fix.

Yes it indeed is that bug, thanks for finding that. I've done a local
Fedora cross-gcc build with the patches from that bug applied and that
fixes things.

I've added these patches to my sunxi-wip branch now and I'll send
them out in my next pull-req, after the dust surrounding the
BOOTDELAY changes settles.

> Interesting that Fedora only provides one version of GCC though.

Fedora always contains the latest gcc, glibc, etc. Given that it is
Red Hat's community distro and that we employ a lot of gcc / glibc
developers we try to follow upstream as close as possible.


Regards,

Hans

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2016-06-13 15:40 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-07  2:54 [U-Boot] [PATCH v3 00/11] sunxi: PSCI implementation rewrite in C Chen-Yu Tsai
2016-06-07  2:54 ` [U-Boot] [PATCH v3 01/11] ARM: PSCI: use only r0 and r3 in psci_get_cpu_stack_top() Chen-Yu Tsai
2016-06-07  2:54 ` [U-Boot] [PATCH v3 02/11] ARM: PSCI: save and restore clobbered registers in v7_flush_dcache_all Chen-Yu Tsai
2016-06-07  2:54 ` [U-Boot] [PATCH v3 03/11] ARM: PSCI: export common PSCI function declarations for C code Chen-Yu Tsai
2016-06-07  2:54 ` [U-Boot] [PATCH v3 04/11] ARM: allocate extra space for PSCI stack in secure section during link phase Chen-Yu Tsai
2016-06-07  2:54 ` [U-Boot] [PATCH v3 05/11] sunxi: Make CPUCFG_BASE macro names the same across families Chen-Yu Tsai
2016-06-07  2:54 ` [U-Boot] [PATCH v3 06/11] sunxi: Add packed attribute to struct sunxi_prcm_reg Chen-Yu Tsai
2016-06-07  2:54 ` [U-Boot] [PATCH v3 07/11] sunxi: Add missing linux/types.h header for cpucfg_sun6i.h Chen-Yu Tsai
2016-06-07  2:54 ` [U-Boot] [PATCH v3 08/11] sunxi: Group cpu core related controls together Chen-Yu Tsai
2016-06-07  2:54 ` [U-Boot] [PATCH v3 09/11] sunxi: Add CPUCFG debug lock and sun7i cpu power controls Chen-Yu Tsai
2016-06-07  2:54 ` [U-Boot] [PATCH v3 10/11] sunxi: Add base address for GIC Chen-Yu Tsai
2016-06-07  2:54 ` [U-Boot] [PATCH v3 11/11] sunxi: Add PSCI implementation in C Chen-Yu Tsai
2016-06-10 13:40   ` Hans de Goede
2016-06-13  2:50     ` Chen-Yu Tsai
2016-06-13  9:49       ` Hans de Goede
2016-06-13 10:58         ` Chen-Yu Tsai
2016-06-13 15:40           ` Hans de Goede
2016-06-07  9:49 ` [U-Boot] [PATCH v3 00/11] sunxi: PSCI implementation rewrite " Marc Zyngier
2016-06-07 10:04   ` Hans de Goede
2016-06-12 17:33     ` Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.