All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicolas Pitre <nicolas.pitre@linaro.org>
To: Shawn Guo <shawn.guo@linaro.org>
Cc: Russell King - ARM Linux <linux@arm.linux.org.uk>,
	Arnd Bergmann <arnd@arndb.de>,
	linux-arm-kernel@lists.infradead.org,
	Stephen Warren <swarren@nvidia.com>, Pavel Machek <pavel@denx.de>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	linux-kernel@vger.kernel.org, arm@kernel.org,
	Simon Horman <horms+renesas@verge.net.au>,
	Dinh Nguyen <dinguyen@altera.com>
Subject: Re: [PATCH 8/9] [HACK] ARM: imx: work around v7_cpu_resume link error
Date: Mon, 18 Feb 2013 12:06:32 -0500 (EST)	[thread overview]
Message-ID: <alpine.LFD.2.03.1302181204050.6419@syhkavp.arg> (raw)
In-Reply-To: <20130218055541.GK6782@S2101-09.ap.freescale.net>

On Mon, 18 Feb 2013, Shawn Guo wrote:

> On Sat, Feb 16, 2013 at 12:14:49AM -0500, Nicolas Pitre wrote:
> > Something like this should work:
> > 
> > diff --git a/arch/arm/mach-imx/headsmp.S b/arch/arm/mach-imx/headsmp.S
> > index 7e49deb128..9de26f3edb 100644
> > --- a/arch/arm/mach-imx/headsmp.S
> > +++ b/arch/arm/mach-imx/headsmp.S
> > @@ -99,8 +99,11 @@ phys_l2x0_saved_regs:
> >  #endif
> >  
> >  ENTRY(v7_cpu_resume)
> > -	bl	v7_invalidate_l1
> > +	ldr	ip, 2f
> > +	mov	lr, pc
> > +1:	add	pc, pc, ip
> >  	pl310_resume
> >  	b	cpu_resume
> > +2:	.word v7_invalidate_l1 - 1b - 8
> >  ENDPROC(v7_cpu_resume)
> >  #endif
> > 
> Yes, it works.
> 
> > 
> > However it is probably best to move all the code to the .text section 
> > where it belongs and fixup the data access instead.  I must plead guilty 
> > for introducing this idea of putting code in the .data section with the 
> > SA1100resume code over 10 years ago that everyone copied since.
> > 
> > So here's how I think it should look instead, and how I should have done 
> > the SA1100 code back then:
> > 
> > diff --git a/arch/arm/mach-imx/headsmp.S b/arch/arm/mach-imx/headsmp.S
> > index 7e49deb128..38a544a037 100644
> > --- a/arch/arm/mach-imx/headsmp.S
> > +++ b/arch/arm/mach-imx/headsmp.S
> > @@ -73,16 +73,16 @@ ENDPROC(v7_secondary_startup)
> >  
> >  #ifdef CONFIG_PM
> >  /*
> > - * The following code is located into the .data section.  This is to
> > - * allow phys_l2x0_saved_regs to be accessed with a relative load
> > - * as we are running on physical address here.
> > + * The following code must assume it is running from physical address
> > + * where absolute virtual addresses to the data section have to be
> > + * turned into relative ones.
> >   */
> > -	.data
> > -	.align
> >  
> >  #ifdef CONFIG_CACHE_L2X0
> >  	.macro	pl310_resume
> > -	ldr	r2, phys_l2x0_saved_regs
> > +	adr	r0, phys_l2x0_saved_ptr_offset
> > +	ldr	r2, [r0]
> > +	add	r2, r2, r0
> >  	ldr	r0, [r2, #L2X0_R_PHY_BASE]	@ get physical base of l2x0
> >  	ldr	r1, [r2, #L2X0_R_AUX_CTRL]	@ get aux_ctrl value
> >  	str	r1, [r0, #L2X0_AUX_CTRL]	@ restore aux_ctrl
> > @@ -90,9 +90,13 @@ ENDPROC(v7_secondary_startup)
> >  	str	r1, [r0, #L2X0_CTRL]		@ re-enable L2
> >  	.endm
> >  
> > +	.bss
> >  	.globl	phys_l2x0_saved_regs
> >  phys_l2x0_saved_regs:
> > -        .long   0
> > +        .space   4
> > +	.previous
> > +phys_l2x0_saved_ptr_offset:
> > +	.word	phys_l2x0_saved_regs - .
> >  #else
> >  	.macro	pl310_resume
> >  	.endm
> > 
> But this does not work.  It seems the execution jumps to the start of
> kernel on system resuming.

Try the following instead.  It makes the code simpler and easier to 
debug.

diff --git a/arch/arm/mach-imx/headsmp.S b/arch/arm/mach-imx/headsmp.S
index 7e49deb128..27bc06e910 100644
--- a/arch/arm/mach-imx/headsmp.S
+++ b/arch/arm/mach-imx/headsmp.S
@@ -73,16 +73,16 @@ ENDPROC(v7_secondary_startup)
 
 #ifdef CONFIG_PM
 /*
- * The following code is located into the .data section.  This is to
- * allow phys_l2x0_saved_regs to be accessed with a relative load
- * as we are running on physical address here.
+ * The following code must assume it is running from physical address
+ * where absolute virtual addresses to the data section have to be
+ * turned into relative ones.
  */
-	.data
-	.align
 
 #ifdef CONFIG_CACHE_L2X0
 	.macro	pl310_resume
-	ldr	r2, phys_l2x0_saved_regs
+	adr	r0, l2x0_saved_regs_offset
+	ldr	r2, [r0]
+	add	r2, r2, r0
 	ldr	r0, [r2, #L2X0_R_PHY_BASE]	@ get physical base of l2x0
 	ldr	r1, [r2, #L2X0_R_AUX_CTRL]	@ get aux_ctrl value
 	str	r1, [r0, #L2X0_AUX_CTRL]	@ restore aux_ctrl
@@ -90,9 +90,9 @@ ENDPROC(v7_secondary_startup)
 	str	r1, [r0, #L2X0_CTRL]		@ re-enable L2
 	.endm
 
-	.globl	phys_l2x0_saved_regs
-phys_l2x0_saved_regs:
-        .long   0
+l2x0_saved_regs_offset:
+	.word	l2x0_saved_regs - .
+
 #else
 	.macro	pl310_resume
 	.endm
diff --git a/arch/arm/mach-imx/pm-imx6q.c b/arch/arm/mach-imx/pm-imx6q.c
index f7b0c2b1b9..f3791f980d 100644
--- a/arch/arm/mach-imx/pm-imx6q.c
+++ b/arch/arm/mach-imx/pm-imx6q.c
@@ -21,8 +21,6 @@
 #include <mach/common.h>
 #include <mach/hardware.h>
 
-extern unsigned long phys_l2x0_saved_regs;
-
 static int imx6q_suspend_finish(unsigned long val)
 {
 	cpu_do_idle();
@@ -55,18 +53,5 @@ static const struct platform_suspend_ops imx6q_pm_ops = {
 
 void __init imx6q_pm_init(void)
 {
-	/*
-	 * The l2x0 core code provides an infrastucture to save and restore
-	 * l2x0 registers across suspend/resume cycle.  But because imx6q
-	 * retains L2 content during suspend and needs to resume L2 before
-	 * MMU is enabled, it can only utilize register saving support and
-	 * have to take care of restoring on its own.  So we save physical
-	 * address of the data structure used by l2x0 core to save registers,
-	 * and later restore the necessary ones in imx6q resume entry.
-	 */
-#ifdef CONFIG_CACHE_L2X0
-	phys_l2x0_saved_regs = __pa(&l2x0_saved_regs);
-#endif
-
 	suspend_set_ops(&imx6q_pm_ops);
 }

Nicolas

WARNING: multiple messages have this Message-ID (diff)
From: nicolas.pitre@linaro.org (Nicolas Pitre)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 8/9] [HACK] ARM: imx: work around v7_cpu_resume link error
Date: Mon, 18 Feb 2013 12:06:32 -0500 (EST)	[thread overview]
Message-ID: <alpine.LFD.2.03.1302181204050.6419@syhkavp.arg> (raw)
In-Reply-To: <20130218055541.GK6782@S2101-09.ap.freescale.net>

On Mon, 18 Feb 2013, Shawn Guo wrote:

> On Sat, Feb 16, 2013 at 12:14:49AM -0500, Nicolas Pitre wrote:
> > Something like this should work:
> > 
> > diff --git a/arch/arm/mach-imx/headsmp.S b/arch/arm/mach-imx/headsmp.S
> > index 7e49deb128..9de26f3edb 100644
> > --- a/arch/arm/mach-imx/headsmp.S
> > +++ b/arch/arm/mach-imx/headsmp.S
> > @@ -99,8 +99,11 @@ phys_l2x0_saved_regs:
> >  #endif
> >  
> >  ENTRY(v7_cpu_resume)
> > -	bl	v7_invalidate_l1
> > +	ldr	ip, 2f
> > +	mov	lr, pc
> > +1:	add	pc, pc, ip
> >  	pl310_resume
> >  	b	cpu_resume
> > +2:	.word v7_invalidate_l1 - 1b - 8
> >  ENDPROC(v7_cpu_resume)
> >  #endif
> > 
> Yes, it works.
> 
> > 
> > However it is probably best to move all the code to the .text section 
> > where it belongs and fixup the data access instead.  I must plead guilty 
> > for introducing this idea of putting code in the .data section with the 
> > SA1100resume code over 10 years ago that everyone copied since.
> > 
> > So here's how I think it should look instead, and how I should have done 
> > the SA1100 code back then:
> > 
> > diff --git a/arch/arm/mach-imx/headsmp.S b/arch/arm/mach-imx/headsmp.S
> > index 7e49deb128..38a544a037 100644
> > --- a/arch/arm/mach-imx/headsmp.S
> > +++ b/arch/arm/mach-imx/headsmp.S
> > @@ -73,16 +73,16 @@ ENDPROC(v7_secondary_startup)
> >  
> >  #ifdef CONFIG_PM
> >  /*
> > - * The following code is located into the .data section.  This is to
> > - * allow phys_l2x0_saved_regs to be accessed with a relative load
> > - * as we are running on physical address here.
> > + * The following code must assume it is running from physical address
> > + * where absolute virtual addresses to the data section have to be
> > + * turned into relative ones.
> >   */
> > -	.data
> > -	.align
> >  
> >  #ifdef CONFIG_CACHE_L2X0
> >  	.macro	pl310_resume
> > -	ldr	r2, phys_l2x0_saved_regs
> > +	adr	r0, phys_l2x0_saved_ptr_offset
> > +	ldr	r2, [r0]
> > +	add	r2, r2, r0
> >  	ldr	r0, [r2, #L2X0_R_PHY_BASE]	@ get physical base of l2x0
> >  	ldr	r1, [r2, #L2X0_R_AUX_CTRL]	@ get aux_ctrl value
> >  	str	r1, [r0, #L2X0_AUX_CTRL]	@ restore aux_ctrl
> > @@ -90,9 +90,13 @@ ENDPROC(v7_secondary_startup)
> >  	str	r1, [r0, #L2X0_CTRL]		@ re-enable L2
> >  	.endm
> >  
> > +	.bss
> >  	.globl	phys_l2x0_saved_regs
> >  phys_l2x0_saved_regs:
> > -        .long   0
> > +        .space   4
> > +	.previous
> > +phys_l2x0_saved_ptr_offset:
> > +	.word	phys_l2x0_saved_regs - .
> >  #else
> >  	.macro	pl310_resume
> >  	.endm
> > 
> But this does not work.  It seems the execution jumps to the start of
> kernel on system resuming.

Try the following instead.  It makes the code simpler and easier to 
debug.

diff --git a/arch/arm/mach-imx/headsmp.S b/arch/arm/mach-imx/headsmp.S
index 7e49deb128..27bc06e910 100644
--- a/arch/arm/mach-imx/headsmp.S
+++ b/arch/arm/mach-imx/headsmp.S
@@ -73,16 +73,16 @@ ENDPROC(v7_secondary_startup)
 
 #ifdef CONFIG_PM
 /*
- * The following code is located into the .data section.  This is to
- * allow phys_l2x0_saved_regs to be accessed with a relative load
- * as we are running on physical address here.
+ * The following code must assume it is running from physical address
+ * where absolute virtual addresses to the data section have to be
+ * turned into relative ones.
  */
-	.data
-	.align
 
 #ifdef CONFIG_CACHE_L2X0
 	.macro	pl310_resume
-	ldr	r2, phys_l2x0_saved_regs
+	adr	r0, l2x0_saved_regs_offset
+	ldr	r2, [r0]
+	add	r2, r2, r0
 	ldr	r0, [r2, #L2X0_R_PHY_BASE]	@ get physical base of l2x0
 	ldr	r1, [r2, #L2X0_R_AUX_CTRL]	@ get aux_ctrl value
 	str	r1, [r0, #L2X0_AUX_CTRL]	@ restore aux_ctrl
@@ -90,9 +90,9 @@ ENDPROC(v7_secondary_startup)
 	str	r1, [r0, #L2X0_CTRL]		@ re-enable L2
 	.endm
 
-	.globl	phys_l2x0_saved_regs
-phys_l2x0_saved_regs:
-        .long   0
+l2x0_saved_regs_offset:
+	.word	l2x0_saved_regs - .
+
 #else
 	.macro	pl310_resume
 	.endm
diff --git a/arch/arm/mach-imx/pm-imx6q.c b/arch/arm/mach-imx/pm-imx6q.c
index f7b0c2b1b9..f3791f980d 100644
--- a/arch/arm/mach-imx/pm-imx6q.c
+++ b/arch/arm/mach-imx/pm-imx6q.c
@@ -21,8 +21,6 @@
 #include <mach/common.h>
 #include <mach/hardware.h>
 
-extern unsigned long phys_l2x0_saved_regs;
-
 static int imx6q_suspend_finish(unsigned long val)
 {
 	cpu_do_idle();
@@ -55,18 +53,5 @@ static const struct platform_suspend_ops imx6q_pm_ops = {
 
 void __init imx6q_pm_init(void)
 {
-	/*
-	 * The l2x0 core code provides an infrastucture to save and restore
-	 * l2x0 registers across suspend/resume cycle.  But because imx6q
-	 * retains L2 content during suspend and needs to resume L2 before
-	 * MMU is enabled, it can only utilize register saving support and
-	 * have to take care of restoring on its own.  So we save physical
-	 * address of the data structure used by l2x0 core to save registers,
-	 * and later restore the necessary ones in imx6q resume entry.
-	 */
-#ifdef CONFIG_CACHE_L2X0
-	phys_l2x0_saved_regs = __pa(&l2x0_saved_regs);
-#endif
-
 	suspend_set_ops(&imx6q_pm_ops);
 }

Nicolas

  reply	other threads:[~2013-02-18 17:06 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-14 22:47 [PATCH 0/9] arm-soc/for-next allyesconfig build regressions Arnd Bergmann
2013-02-14 22:47 ` Arnd Bergmann
2013-02-14 22:47 ` [PATCH 1/9] ARM: arch_timer: include linux/errno.h Arnd Bergmann
2013-02-14 22:47   ` Arnd Bergmann
2013-02-15 10:26   ` Mark Rutland
2013-02-15 10:26     ` Mark Rutland
2013-02-15 18:33     ` Arnd Bergmann
2013-02-15 18:33       ` Arnd Bergmann
2013-02-14 22:47 ` [PATCH 2/9] ARM: imx: MACH_MX31ADS_WM1133_EV1 needs REGULATOR_WM8350 Arnd Bergmann
2013-02-14 22:47   ` Arnd Bergmann
2013-02-15 17:21   ` Sascha Hauer
2013-02-15 17:21     ` Sascha Hauer
2013-02-14 22:47 ` [PATCH 3/9] ARM: omap2: include linux/errno.h in hwmod_reset Arnd Bergmann
2013-02-14 22:47   ` Arnd Bergmann
2013-02-14 22:51   ` Tony Lindgren
2013-02-14 22:51     ` Tony Lindgren
2013-02-15 12:38     ` Arnd Bergmann
2013-02-15 12:38       ` Arnd Bergmann
2013-02-14 22:58   ` Paul Walmsley
2013-02-14 22:58     ` Paul Walmsley
2013-02-14 22:47 ` [PATCH 4/9] ARM: omap: add include guard for soc.h Arnd Bergmann
2013-02-14 22:47   ` Arnd Bergmann
2013-02-14 22:55   ` Tony Lindgren
2013-02-14 22:55     ` Tony Lindgren
2013-02-14 23:11     ` Arnd Bergmann
2013-02-14 23:11       ` Arnd Bergmann
2013-02-15 12:40     ` Arnd Bergmann
2013-02-15 12:40       ` Arnd Bergmann
2013-02-14 22:47 ` [PATCH 5/9] drm: export drm_vm_open_locked Arnd Bergmann
2013-02-14 22:47   ` Arnd Bergmann
2013-02-14 22:47 ` [PATCH 6/9] net: cwdavinci_cpdma: export symbols for cpsw Arnd Bergmann
2013-02-14 22:47   ` Arnd Bergmann
2013-02-14 22:52   ` David Miller
2013-02-14 22:52     ` David Miller
2013-02-14 22:47 ` [PATCH 7/9] remoteproc: omap: depend on OMAP_MBOX_FWK Arnd Bergmann
2013-02-14 22:47   ` Arnd Bergmann
2013-02-14 22:55   ` Tony Lindgren
2013-02-14 22:55     ` Tony Lindgren
2013-02-15  6:56     ` Ohad Ben-Cohen
2013-02-15  6:56       ` Ohad Ben-Cohen
2013-02-14 22:47 ` [PATCH 8/9] [HACK] ARM: imx: work around v7_cpu_resume link error Arnd Bergmann
2013-02-14 22:47   ` Arnd Bergmann
2013-02-14 23:45   ` Stephen Warren
2013-02-14 23:45     ` Stephen Warren
2013-02-15 11:05     ` Arnd Bergmann
2013-02-15 11:05       ` Arnd Bergmann
2013-02-15 11:13       ` Russell King - ARM Linux
2013-02-15 11:13         ` Russell King - ARM Linux
2013-02-15 15:49         ` Arnd Bergmann
2013-02-15 15:49           ` Arnd Bergmann
2013-02-15 11:07   ` Russell King - ARM Linux
2013-02-15 11:07     ` Russell King - ARM Linux
2013-02-16  5:14     ` Nicolas Pitre
2013-02-16  5:14       ` Nicolas Pitre
2013-02-18  5:55       ` Shawn Guo
2013-02-18  5:55         ` Shawn Guo
2013-02-18 17:06         ` Nicolas Pitre [this message]
2013-02-18 17:06           ` Nicolas Pitre
2013-02-19  1:42           ` Shawn Guo
2013-02-19  1:42             ` Shawn Guo
2013-02-19  4:11             ` Nicolas Pitre
2013-02-19  4:11               ` Nicolas Pitre
2013-02-19  5:10               ` Shawn Guo
2013-02-19  5:10                 ` Shawn Guo
2013-02-14 22:47 ` [PATCH 9/9] [media] davinci: do not include mach/hardware.h Arnd Bergmann
2013-02-14 22:47   ` Arnd Bergmann
2013-02-14 22:57   ` Tony Lindgren
2013-02-14 22:57     ` Tony Lindgren
2013-02-15  5:06   ` Prabhakar Lad
2013-02-15  5:06     ` Prabhakar Lad

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.2.03.1302181204050.6419@syhkavp.arg \
    --to=nicolas.pitre@linaro.org \
    --cc=arm@kernel.org \
    --cc=arnd@arndb.de \
    --cc=dinguyen@altera.com \
    --cc=horms+renesas@verge.net.au \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=pavel@denx.de \
    --cc=s.hauer@pengutronix.de \
    --cc=shawn.guo@linaro.org \
    --cc=swarren@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.