linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ARM: rcar-gen2: Do not setup timer in non-secure mode
@ 2013-12-10 15:53 Ben Dooks
  2013-12-10 17:01 ` Sergei Shtylyov
  2013-12-11  0:41 ` Simon Horman
  0 siblings, 2 replies; 6+ messages in thread
From: Ben Dooks @ 2013-12-10 15:53 UTC (permalink / raw)
  To: linux-arm-kernel

If the system has been started in non-secure mode, then the ARM generic
timer is not configurable during the kernel initialisation. Currently
the only thing we can check for is if the timer has been correctly
configured during the boot process.

Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
Reviewed-by: Ian Molton <ian.molton@codethink.co.uk>
---
 arch/arm/mach-shmobile/setup-rcar-gen2.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/arch/arm/mach-shmobile/setup-rcar-gen2.c b/arch/arm/mach-shmobile/setup-rcar-gen2.c
index 5734c24..6b7b7f1 100644
--- a/arch/arm/mach-shmobile/setup-rcar-gen2.c
+++ b/arch/arm/mach-shmobile/setup-rcar-gen2.c
@@ -78,12 +78,20 @@ void __init rcar_gen2_timer_init(void)
 	/* Remap "armgcnt address map" space */
 	base = ioremap(0xe6080000, PAGE_SIZE);
 
-	/* Update registers with correct frequency */
-	iowrite32(freq, base + CNTFID0);
-	asm volatile("mcr p15, 0, %0, c14, c0, 0" : : "r" (freq));
+	/* Update the timer if it is either not running, or is not at the
+	 * right frequency. The timer is only configurable in secure mode
+	 * so this avoids an abort if the loader started the timer and
+	 * started the kernel in non-secure mode. */
+	if ((ioread32(base + CNTCR) & 1) == 0 ||
+	    ioread32(base + CNTFID0) != freq) {
+		/* Update registers with correct frequency */
+		iowrite32(freq, base + CNTFID0);
+		asm volatile("mcr p15, 0, %0, c14, c0, 0" : : "r" (freq));
+
+		/* make sure arch timer is started by setting bit 0 of CNTCR */
+		iowrite32(1, base + CNTCR);
+	}
 
-	/* make sure arch timer is started by setting bit 0 of CNTCR */
-	iowrite32(1, base + CNTCR);
 	iounmap(base);
 #endif /* CONFIG_ARM_ARCH_TIMER */
 
-- 
1.8.5.1

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

* [PATCH] ARM: rcar-gen2: Do not setup timer in non-secure mode
  2013-12-10 15:53 [PATCH] ARM: rcar-gen2: Do not setup timer in non-secure mode Ben Dooks
@ 2013-12-10 17:01 ` Sergei Shtylyov
  2013-12-10 17:15   ` Ben Dooks
  2013-12-11  0:41 ` Simon Horman
  1 sibling, 1 reply; 6+ messages in thread
From: Sergei Shtylyov @ 2013-12-10 17:01 UTC (permalink / raw)
  To: linux-arm-kernel

Hello.

On 10-12-2013 19:53, Ben Dooks wrote:

> If the system has been started in non-secure mode, then the ARM generic
> timer is not configurable during the kernel initialisation. Currently
> the only thing we can check for is if the timer has been correctly
> configured during the boot process.

> Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
> Reviewed-by: Ian Molton <ian.molton@codethink.co.uk>
> ---
>   arch/arm/mach-shmobile/setup-rcar-gen2.c | 18 +++++++++++++-----
>   1 file changed, 13 insertions(+), 5 deletions(-)

> diff --git a/arch/arm/mach-shmobile/setup-rcar-gen2.c b/arch/arm/mach-shmobile/setup-rcar-gen2.c
> index 5734c24..6b7b7f1 100644
> --- a/arch/arm/mach-shmobile/setup-rcar-gen2.c
> +++ b/arch/arm/mach-shmobile/setup-rcar-gen2.c
> @@ -78,12 +78,20 @@ void __init rcar_gen2_timer_init(void)
>   	/* Remap "armgcnt address map" space */
>   	base = ioremap(0xe6080000, PAGE_SIZE);
>
> -	/* Update registers with correct frequency */
> -	iowrite32(freq, base + CNTFID0);
> -	asm volatile("mcr p15, 0, %0, c14, c0, 0" : : "r" (freq));
> +	/* Update the timer if it is either not running, or is not at the
> +	 * right frequency. The timer is only configurable in secure mode
> +	 * so this avoids an abort if the loader started the timer and
> +	 * started the kernel in non-secure mode. */

    The preferred style of the multi-line comments is this:

/*
  * bla
  * bla
  */

WBR, Sergei

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

* [PATCH] ARM: rcar-gen2: Do not setup timer in non-secure mode
  2013-12-10 17:01 ` Sergei Shtylyov
@ 2013-12-10 17:15   ` Ben Dooks
  0 siblings, 0 replies; 6+ messages in thread
From: Ben Dooks @ 2013-12-10 17:15 UTC (permalink / raw)
  To: linux-arm-kernel

On 10/12/13 17:01, Sergei Shtylyov wrote:
> Hello.
>
> On 10-12-2013 19:53, Ben Dooks wrote:
>
>> If the system has been started in non-secure mode, then the ARM generic
>> timer is not configurable during the kernel initialisation. Currently
>> the only thing we can check for is if the timer has been correctly
>> configured during the boot process.
>
>> Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
>> Reviewed-by: Ian Molton <ian.molton@codethink.co.uk>


>   * bla
>   * bla
>   */
>
> WBR, Sergei

Thanks, fixed.

-- 
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius

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

* [PATCH] ARM: rcar-gen2: Do not setup timer in non-secure mode
  2013-12-10 15:53 [PATCH] ARM: rcar-gen2: Do not setup timer in non-secure mode Ben Dooks
  2013-12-10 17:01 ` Sergei Shtylyov
@ 2013-12-11  0:41 ` Simon Horman
  1 sibling, 0 replies; 6+ messages in thread
From: Simon Horman @ 2013-12-11  0:41 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Dec 10, 2013 at 03:53:33PM +0000, Ben Dooks wrote:
> If the system has been started in non-secure mode, then the ARM generic
> timer is not configurable during the kernel initialisation. Currently
> the only thing we can check for is if the timer has been correctly
> configured during the boot process.
> 
> Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
> Reviewed-by: Ian Molton <ian.molton@codethink.co.uk>

Magnus, could you please review this?

> ---
>  arch/arm/mach-shmobile/setup-rcar-gen2.c | 18 +++++++++++++-----
>  1 file changed, 13 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/arm/mach-shmobile/setup-rcar-gen2.c b/arch/arm/mach-shmobile/setup-rcar-gen2.c
> index 5734c24..6b7b7f1 100644
> --- a/arch/arm/mach-shmobile/setup-rcar-gen2.c
> +++ b/arch/arm/mach-shmobile/setup-rcar-gen2.c
> @@ -78,12 +78,20 @@ void __init rcar_gen2_timer_init(void)
>  	/* Remap "armgcnt address map" space */
>  	base = ioremap(0xe6080000, PAGE_SIZE);
>  
> -	/* Update registers with correct frequency */
> -	iowrite32(freq, base + CNTFID0);
> -	asm volatile("mcr p15, 0, %0, c14, c0, 0" : : "r" (freq));
> +	/* Update the timer if it is either not running, or is not at the
> +	 * right frequency. The timer is only configurable in secure mode
> +	 * so this avoids an abort if the loader started the timer and
> +	 * started the kernel in non-secure mode. */
> +	if ((ioread32(base + CNTCR) & 1) == 0 ||
> +	    ioread32(base + CNTFID0) != freq) {
> +		/* Update registers with correct frequency */
> +		iowrite32(freq, base + CNTFID0);
> +		asm volatile("mcr p15, 0, %0, c14, c0, 0" : : "r" (freq));
> +
> +		/* make sure arch timer is started by setting bit 0 of CNTCR */
> +		iowrite32(1, base + CNTCR);
> +	}
>  
> -	/* make sure arch timer is started by setting bit 0 of CNTCR */
> -	iowrite32(1, base + CNTCR);
>  	iounmap(base);
>  #endif /* CONFIG_ARM_ARCH_TIMER */
>  
> -- 
> 1.8.5.1
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> 

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

* [PATCH] ARM: rcar-gen2: Do not setup timer in non-secure mode
  2013-12-11 10:07 [V2] correct patch for renesas arm timer Ben Dooks
@ 2013-12-11 10:07 ` Ben Dooks
  2013-12-12 13:00   ` Simon Horman
  0 siblings, 1 reply; 6+ messages in thread
From: Ben Dooks @ 2013-12-11 10:07 UTC (permalink / raw)
  To: linux-arm-kernel

If the system has been started in non-secure mode, then the ARM generic
timer is not configurable during the kernel initialisation. Currently
the only thing we can check for is if the timer has been correctly
configured during the boot process.

Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
Reviewed-by: Ian Molton <ian.molton@codethink.co.uk>
---
 arch/arm/mach-shmobile/setup-rcar-gen2.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/arch/arm/mach-shmobile/setup-rcar-gen2.c b/arch/arm/mach-shmobile/setup-rcar-gen2.c
index 5734c24..b6275ab 100644
--- a/arch/arm/mach-shmobile/setup-rcar-gen2.c
+++ b/arch/arm/mach-shmobile/setup-rcar-gen2.c
@@ -78,12 +78,23 @@ void __init rcar_gen2_timer_init(void)
 	/* Remap "armgcnt address map" space */
 	base = ioremap(0xe6080000, PAGE_SIZE);
 
-	/* Update registers with correct frequency */
-	iowrite32(freq, base + CNTFID0);
-	asm volatile("mcr p15, 0, %0, c14, c0, 0" : : "r" (freq));
+	/*
+	 * Update the timer if it is either not running, or is not at the
+	 * right frequency. The timer is only configurable in secure mode
+	 * so this avoids an abort if the loader started the timer and
+	 * entered the kernel in non-secure mode.
+	 */
+
+	if ((ioread32(base + CNTCR) & 1) == 0 ||
+	    ioread32(base + CNTFID0) != freq) {
+		/* Update registers with correct frequency */
+		iowrite32(freq, base + CNTFID0);
+		asm volatile("mcr p15, 0, %0, c14, c0, 0" : : "r" (freq));
+
+		/* make sure arch timer is started by setting bit 0 of CNTCR */
+		iowrite32(1, base + CNTCR);
+	}
 
-	/* make sure arch timer is started by setting bit 0 of CNTCR */
-	iowrite32(1, base + CNTCR);
 	iounmap(base);
 #endif /* CONFIG_ARM_ARCH_TIMER */
 
-- 
1.8.5.1

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

* [PATCH] ARM: rcar-gen2: Do not setup timer in non-secure mode
  2013-12-11 10:07 ` [PATCH] ARM: rcar-gen2: Do not setup timer in non-secure mode Ben Dooks
@ 2013-12-12 13:00   ` Simon Horman
  0 siblings, 0 replies; 6+ messages in thread
From: Simon Horman @ 2013-12-12 13:00 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Dec 11, 2013 at 10:07:42AM +0000, Ben Dooks wrote:
> If the system has been started in non-secure mode, then the ARM generic
> timer is not configurable during the kernel initialisation. Currently
> the only thing we can check for is if the timer has been correctly
> configured during the boot process.
> 
> Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
> Reviewed-by: Ian Molton <ian.molton@codethink.co.uk>

Thanks, I will queue this up.

> ---
>  arch/arm/mach-shmobile/setup-rcar-gen2.c | 21 ++++++++++++++++-----
>  1 file changed, 16 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/arm/mach-shmobile/setup-rcar-gen2.c b/arch/arm/mach-shmobile/setup-rcar-gen2.c
> index 5734c24..b6275ab 100644
> --- a/arch/arm/mach-shmobile/setup-rcar-gen2.c
> +++ b/arch/arm/mach-shmobile/setup-rcar-gen2.c
> @@ -78,12 +78,23 @@ void __init rcar_gen2_timer_init(void)
>  	/* Remap "armgcnt address map" space */
>  	base = ioremap(0xe6080000, PAGE_SIZE);
>  
> -	/* Update registers with correct frequency */
> -	iowrite32(freq, base + CNTFID0);
> -	asm volatile("mcr p15, 0, %0, c14, c0, 0" : : "r" (freq));
> +	/*
> +	 * Update the timer if it is either not running, or is not at the
> +	 * right frequency. The timer is only configurable in secure mode
> +	 * so this avoids an abort if the loader started the timer and
> +	 * entered the kernel in non-secure mode.
> +	 */
> +
> +	if ((ioread32(base + CNTCR) & 1) == 0 ||
> +	    ioread32(base + CNTFID0) != freq) {
> +		/* Update registers with correct frequency */
> +		iowrite32(freq, base + CNTFID0);
> +		asm volatile("mcr p15, 0, %0, c14, c0, 0" : : "r" (freq));
> +
> +		/* make sure arch timer is started by setting bit 0 of CNTCR */
> +		iowrite32(1, base + CNTCR);
> +	}
>  
> -	/* make sure arch timer is started by setting bit 0 of CNTCR */
> -	iowrite32(1, base + CNTCR);
>  	iounmap(base);
>  #endif /* CONFIG_ARM_ARCH_TIMER */
>  
> -- 
> 1.8.5.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-sh" in
> the body of a message to majordomo at vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

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

end of thread, other threads:[~2013-12-12 13:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-10 15:53 [PATCH] ARM: rcar-gen2: Do not setup timer in non-secure mode Ben Dooks
2013-12-10 17:01 ` Sergei Shtylyov
2013-12-10 17:15   ` Ben Dooks
2013-12-11  0:41 ` Simon Horman
  -- strict thread matches above, loose matches on Subject: below --
2013-12-11 10:07 [V2] correct patch for renesas arm timer Ben Dooks
2013-12-11 10:07 ` [PATCH] ARM: rcar-gen2: Do not setup timer in non-secure mode Ben Dooks
2013-12-12 13:00   ` Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).