diff mbox

[v4,05/13] pm: at91: move the copying the sram function to the sram initializationi phase

Message ID 1422409396-24394-1-git-send-email-wenyou.yang@atmel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Wenyou Yang Jan. 28, 2015, 1:43 a.m. UTC
To decrease the suspend time, move the copying the sram function
to the sram initialization phase, instead of every time go to suspend.

In the meanwhile, if there is no sram allocated for PM, the PM is not supported.

Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
 arch/arm/mach-at91/pm.c |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

Russell King - ARM Linux Jan. 29, 2015, 11:28 a.m. UTC | #1
On Wed, Jan 28, 2015 at 09:43:16AM +0800, Wenyou Yang wrote:
> -#ifdef CONFIG_AT91_SLOW_CLOCK
> -				/* copy slow_clock handler to SRAM, and call it */
> -				memcpy(slow_clock, at91_slow_clock, at91_slow_clock_sz);
> -#endif
>  				slow_clock(at91_pmc_base, at91_ramc_base[0],
>  					   at91_ramc_base[1],
>  					   at91_pm_data.memctrl);
> @@ -272,6 +268,9 @@ static void __init at91_pm_sram_init(void)
>  	sram_pbase = gen_pool_virt_to_phys(sram_pool, sram_base);
>  	slow_clock = __arm_ioremap_exec(sram_pbase, at91_slow_clock_sz, false);
>  
> +	/* Copy the slow_clock handler to SRAM */
> +	memcpy(slow_clock, at91_slow_clock, at91_slow_clock_sz);
> +

Why is this code not using the fncpy() support for copying functions.
Why is it not checking the return code from __arm_ioremap_exec() or
gen_pool_virt_to_phys() for failure?

This looks like quite a massive review failure when this code was
originally merged.  It needs fixing.
Alexandre Belloni Jan. 29, 2015, 3:09 p.m. UTC | #2
Hi,

On 29/01/2015 at 11:28:00 +0000, Russell King - ARM Linux wrote :
> On Wed, Jan 28, 2015 at 09:43:16AM +0800, Wenyou Yang wrote:
> > -#ifdef CONFIG_AT91_SLOW_CLOCK
> > -				/* copy slow_clock handler to SRAM, and call it */
> > -				memcpy(slow_clock, at91_slow_clock, at91_slow_clock_sz);
> > -#endif
> >  				slow_clock(at91_pmc_base, at91_ramc_base[0],
> >  					   at91_ramc_base[1],
> >  					   at91_pm_data.memctrl);
> > @@ -272,6 +268,9 @@ static void __init at91_pm_sram_init(void)
> >  	sram_pbase = gen_pool_virt_to_phys(sram_pool, sram_base);
> >  	slow_clock = __arm_ioremap_exec(sram_pbase, at91_slow_clock_sz, false);
> >  
> > +	/* Copy the slow_clock handler to SRAM */
> > +	memcpy(slow_clock, at91_slow_clock, at91_slow_clock_sz);
> > +
> 
> Why is this code not using the fncpy() support for copying functions.

Indeed, this was done in the original version of the patch that I acked.

> Why is it not checking the return code from __arm_ioremap_exec() or
> gen_pool_virt_to_phys() for failure?

gen_pool_virt_to_phys() will not fail as the chunk is allocated just
before so it will necessarily be found in the list.

We need to reintroduce a check for slow_clock != NULL before fncpy()
since it is moved out of its original if block.
Wenyou Yang Jan. 30, 2015, 6:59 a.m. UTC | #3
Hi Russell,

Thank you for your review.

> -----Original Message-----
> From: Russell King - ARM Linux [mailto:linux@arm.linux.org.uk]
> Sent: Thursday, January 29, 2015 7:28 PM
> To: Yang, Wenyou
> Cc: Ferre, Nicolas; linux-arm-kernel@lists.infradead.org; linux-
> kernel@vger.kernel.org; alexandre.belloni@free-electrons.com;
> sylvain.rochet@finsecur.com; peda@axentia.se;
> sergei.shtylyov@cogentembedded.com; linux@maxim.org.za
> Subject: Re: [PATCH v4 05/13] pm: at91: move the copying the sram function to
> the sram initializationi phase
> 
> On Wed, Jan 28, 2015 at 09:43:16AM +0800, Wenyou Yang wrote:
> > -#ifdef CONFIG_AT91_SLOW_CLOCK
> > -				/* copy slow_clock handler to SRAM, and call it */
> > -				memcpy(slow_clock, at91_slow_clock,
> at91_slow_clock_sz);
> > -#endif
> >  				slow_clock(at91_pmc_base, at91_ramc_base[0],
> >  					   at91_ramc_base[1],
> >  					   at91_pm_data.memctrl);
> > @@ -272,6 +268,9 @@ static void __init at91_pm_sram_init(void)
> >  	sram_pbase = gen_pool_virt_to_phys(sram_pool, sram_base);
> >  	slow_clock = __arm_ioremap_exec(sram_pbase, at91_slow_clock_sz,
> > false);
> >
> > +	/* Copy the slow_clock handler to SRAM */
> > +	memcpy(slow_clock, at91_slow_clock, at91_slow_clock_sz);
> > +
> 
> Why is this code not using the fncpy() support for copying functions.
At first, used the fncpy(), but it work not well on the some chip. I will check it again.

> Why is it not checking the return code from __arm_ioremap_exec() or
> gen_pool_virt_to_phys() for failure?
> 
> This looks like quite a massive review failure when this code was originally merged.
> It needs fixing.
I will fix it.

> 
> --
> FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
> according to speedtest.net.

Best Regards,
Wenyou Yang
Wenyou Yang Jan. 30, 2015, 7:03 a.m. UTC | #4
Hi  Alexandre,

> -----Original Message-----
> From: Alexandre Belloni [mailto:alexandre.belloni@free-electrons.com]
> Sent: Thursday, January 29, 2015 11:09 PM
> To: Russell King - ARM Linux
> Cc: Yang, Wenyou; Ferre, Nicolas; linux-arm-kernel@lists.infradead.org; linux-
> kernel@vger.kernel.org; sylvain.rochet@finsecur.com; peda@axentia.se;
> sergei.shtylyov@cogentembedded.com; linux@maxim.org.za
> Subject: Re: [PATCH v4 05/13] pm: at91: move the copying the sram function to
> the sram initializationi phase
> 
> Hi,
> 
> On 29/01/2015 at 11:28:00 +0000, Russell King - ARM Linux wrote :
> > On Wed, Jan 28, 2015 at 09:43:16AM +0800, Wenyou Yang wrote:
> > > -#ifdef CONFIG_AT91_SLOW_CLOCK
> > > -				/* copy slow_clock handler to SRAM, and call it */
> > > -				memcpy(slow_clock, at91_slow_clock,
> at91_slow_clock_sz);
> > > -#endif
> > >  				slow_clock(at91_pmc_base, at91_ramc_base[0],
> > >  					   at91_ramc_base[1],
> > >  					   at91_pm_data.memctrl);
> > > @@ -272,6 +268,9 @@ static void __init at91_pm_sram_init(void)
> > >  	sram_pbase = gen_pool_virt_to_phys(sram_pool, sram_base);
> > >  	slow_clock = __arm_ioremap_exec(sram_pbase, at91_slow_clock_sz,
> > > false);
> > >
> > > +	/* Copy the slow_clock handler to SRAM */
> > > +	memcpy(slow_clock, at91_slow_clock, at91_slow_clock_sz);
> > > +
> >
> > Why is this code not using the fncpy() support for copying functions.
> 
> Indeed, this was done in the original version of the patch that I acked.
Yes, in the original version used the fncpy(), but it works not well for some SoCs.
Sorry for that, I forget to record it on the change log.

> 
> > Why is it not checking the return code from __arm_ioremap_exec() or
> > gen_pool_virt_to_phys() for failure?
> 
> gen_pool_virt_to_phys() will not fail as the chunk is allocated just before so it will
> necessarily be found in the list.
> 
> We need to reintroduce a check for slow_clock != NULL before fncpy() since it is
> moved out of its original if block.
> 
> --
> Alexandre Belloni, Free Electrons
> Embedded Linux, Kernel and Android engineering http://free-electrons.com

Best Regards,
Wenyou yang
Russell King - ARM Linux Jan. 30, 2015, 10:16 a.m. UTC | #5
On Fri, Jan 30, 2015 at 06:59:58AM +0000, Yang, Wenyou wrote:
> Hi Russell,
> 
> Thank you for your review.
> 
> > -----Original Message-----
> > From: Russell King - ARM Linux [mailto:linux@arm.linux.org.uk]
> > 
> > On Wed, Jan 28, 2015 at 09:43:16AM +0800, Wenyou Yang wrote:
> > > @@ -272,6 +268,9 @@ static void __init at91_pm_sram_init(void)
> > >  	sram_pbase = gen_pool_virt_to_phys(sram_pool, sram_base);
> > >  	slow_clock = __arm_ioremap_exec(sram_pbase, at91_slow_clock_sz,
> > > false);
> > >
> > > +	/* Copy the slow_clock handler to SRAM */
> > > +	memcpy(slow_clock, at91_slow_clock, at91_slow_clock_sz);
> > > +
> > 
> > Why is this code not using the fncpy() support for copying functions.
> At first, used the fncpy(), but it work not well on the some chip. I
> will check it again.

Please report on this; why does it "work not well" ?
diff mbox

Patch

diff --git a/arch/arm/mach-at91/pm.c b/arch/arm/mach-at91/pm.c
index 5dd4e41..6b08098 100644
--- a/arch/arm/mach-at91/pm.c
+++ b/arch/arm/mach-at91/pm.c
@@ -161,10 +161,6 @@  static int at91_pm_enter(suspend_state_t state)
 			 * turning off the main oscillator; reverse on wakeup.
 			 */
 			if (slow_clock) {
-#ifdef CONFIG_AT91_SLOW_CLOCK
-				/* copy slow_clock handler to SRAM, and call it */
-				memcpy(slow_clock, at91_slow_clock, at91_slow_clock_sz);
-#endif
 				slow_clock(at91_pmc_base, at91_ramc_base[0],
 					   at91_ramc_base[1],
 					   at91_pm_data.memctrl);
@@ -272,6 +268,9 @@  static void __init at91_pm_sram_init(void)
 	sram_pbase = gen_pool_virt_to_phys(sram_pool, sram_base);
 	slow_clock = __arm_ioremap_exec(sram_pbase, at91_slow_clock_sz, false);
 
+	/* Copy the slow_clock handler to SRAM */
+	memcpy(slow_clock, at91_slow_clock, at91_slow_clock_sz);
+
 put_node:
 	of_node_put(node);
 }
@@ -289,7 +288,10 @@  static void __init at91_pm_init(void)
 	if (at91_cpuidle_device.dev.platform_data)
 		platform_device_register(&at91_cpuidle_device);
 
-	suspend_set_ops(&at91_pm_ops);
+	if (slow_clock)
+		suspend_set_ops(&at91_pm_ops);
+	else
+		pr_info("AT91: PM : Not supported, due to no sram allocated\n");
 }
 
 void __init at91_rm9200_pm_init(void)