mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* Subject: [PATCH 1/1] ARM:lib32: add architected timer
@ 2023-03-03 17:05 Renaud Barbier
  2023-03-03 17:31 ` Ahmad Fatoum
  0 siblings, 1 reply; 6+ messages in thread
From: Renaud Barbier @ 2023-03-03 17:05 UTC (permalink / raw)
  To: Barebox List

In preparation for the introduction of the LS1021A support,
add a specific timer support based on the LS1046A support so
that delays can be used in the PBL.

Signed-off-by: Renaud Barbier <renaud.barbier@ametek.com>
---
 arch/arm/lib32/Makefile                |  2 ++
 arch/arm/lib32/arm_architected_timer.c | 17 +++++++++++++++++
 include/clock.h                        |  2 ++
 3 files changed, 21 insertions(+)
 create mode 100644 arch/arm/lib32/arm_architected_timer.c

diff --git a/arch/arm/lib32/Makefile b/arch/arm/lib32/Makefile
index 82507fffc0..d54fb7644c 100644
--- a/arch/arm/lib32/Makefile
+++ b/arch/arm/lib32/Makefile
@@ -31,6 +31,8 @@ extra-y += barebox.lds
 pbl-y	+= lib1funcs.o
 pbl-y	+= ashldi3.o
 pbl-y	+= div0.o
+pbl-$(CONFIG_CPU_32v7)	+= arm_architected_timer.o
+CFLAGS_arm_architected_timer.o := -march=armv7-a
 
 obj-pbl-y	+= setjmp.o
 
diff --git a/arch/arm/lib32/arm_architected_timer.c b/arch/arm/lib32/arm_architected_timer.c
new file mode 100644
index 0000000000..83b49656cb
--- /dev/null
+++ b/arch/arm/lib32/arm_architected_timer.c
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <asm/system.h>
+#include <clock.h>
+#include <common.h>
+
+/* Unlike the ARMv8, the timer is not generic to ARM32 */
+void arm_architected_timer_udelay(unsigned long us)
+{
+	unsigned long long ticks, cntfrq = get_cntfrq();
+	unsigned long long start = get_cntpct();
+
+	ticks = us * cntfrq + 999999;
+	do_div(ticks, 1000000);
+
+	while ((long)(start + ticks - get_cntpct()) > 0);
+}
diff --git a/include/clock.h b/include/clock.h
index e6197e7eb0..8e07c35d37 100644
--- a/include/clock.h
+++ b/include/clock.h
@@ -35,6 +35,8 @@ uint32_t clocksource_hz2mult(uint32_t hz, uint32_t shift_constant);
 int is_timeout(uint64_t start_ns, uint64_t time_offset_ns);
 int is_timeout_non_interruptible(uint64_t start_ns, uint64_t time_offset_ns);
 
+void arm_architected_timer_udelay(unsigned long us);
+
 void ndelay(unsigned long nsecs);
 void udelay(unsigned long usecs);
 void mdelay(unsigned long msecs);
-- 
2.27.0



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

* Re: Subject: [PATCH 1/1] ARM:lib32: add architected timer
  2023-03-03 17:05 Subject: [PATCH 1/1] ARM:lib32: add architected timer Renaud Barbier
@ 2023-03-03 17:31 ` Ahmad Fatoum
  2023-03-04 14:14   ` Sascha Hauer
  2023-03-06 13:13   ` Renaud Barbier
  0 siblings, 2 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2023-03-03 17:31 UTC (permalink / raw)
  To: Renaud Barbier, Barebox List

Hi,

On 03.03.23 18:05, Renaud Barbier wrote:
> In preparation for the introduction of the LS1021A support,
> add a specific timer support based on the LS1046A support so
> that delays can be used in the PBL.
> 
> Signed-off-by: Renaud Barbier <renaud.barbier@ametek.com>
> ---
>  arch/arm/lib32/Makefile                |  2 ++
>  arch/arm/lib32/arm_architected_timer.c | 17 +++++++++++++++++
>  include/clock.h                        |  2 ++
>  3 files changed, 21 insertions(+)
>  create mode 100644 arch/arm/lib32/arm_architected_timer.c
> 
> diff --git a/arch/arm/lib32/Makefile b/arch/arm/lib32/Makefile
> index 82507fffc0..d54fb7644c 100644
> --- a/arch/arm/lib32/Makefile
> +++ b/arch/arm/lib32/Makefile
> @@ -31,6 +31,8 @@ extra-y += barebox.lds
>  pbl-y	+= lib1funcs.o
>  pbl-y	+= ashldi3.o
>  pbl-y	+= div0.o
> +pbl-$(CONFIG_CPU_32v7)	+= arm_architected_timer.o
> +CFLAGS_arm_architected_timer.o := -march=armv7-a

Sorry, I should have been clearer before. Once you only build the
file for ARMv7, you don't need to mess with -march=armv7-a anymore,
see arch/arm/Makefile:
  
  arch-$(CONFIG_CPU_32v7) :=-D__LINUX_ARM_ARCH__=7 $(call cc-option,-march=armv7-a,-march=armv5t -Wa$(comma)-march=armv7-a)

>  obj-pbl-y	+= setjmp.o
>  
> diff --git a/arch/arm/lib32/arm_architected_timer.c b/arch/arm/lib32/arm_architected_timer.c
> new file mode 100644
> index 0000000000..83b49656cb
> --- /dev/null
> +++ b/arch/arm/lib32/arm_architected_timer.c
> @@ -0,0 +1,17 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +
> +#include <asm/system.h>
> +#include <clock.h>
> +#include <common.h>
> +
> +/* Unlike the ARMv8, the timer is not generic to ARM32 */
> +void arm_architected_timer_udelay(unsigned long us)
> +{
> +	unsigned long long ticks, cntfrq = get_cntfrq();
> +	unsigned long long start = get_cntpct();
> +
> +	ticks = us * cntfrq + 999999;
> +	do_div(ticks, 1000000);

There's DIV_ROUND_UP_ULL you could use instead of opencoding that.
I see that we round down in the udelay for ARM64.
Do you think we should rather be rounding up there too?

In any case, it's worth mentioning why you choose to round up here
in the commit message.

> +
> +	while ((long)(start + ticks - get_cntpct()) > 0);
> +}
> diff --git a/include/clock.h b/include/clock.h
> index e6197e7eb0..8e07c35d37 100644
> --- a/include/clock.h
> +++ b/include/clock.h
> @@ -35,6 +35,8 @@ uint32_t clocksource_hz2mult(uint32_t hz, uint32_t shift_constant);
>  int is_timeout(uint64_t start_ns, uint64_t time_offset_ns);
>  int is_timeout_non_interruptible(uint64_t start_ns, uint64_t time_offset_ns);
>  
> +void arm_architected_timer_udelay(unsigned long us);
> +
>  void ndelay(unsigned long nsecs);
>  void udelay(unsigned long usecs);
>  void mdelay(unsigned long msecs);

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |




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

* Re: Subject: [PATCH 1/1] ARM:lib32: add architected timer
  2023-03-03 17:31 ` Ahmad Fatoum
@ 2023-03-04 14:14   ` Sascha Hauer
  2023-03-06 13:13   ` Renaud Barbier
  1 sibling, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2023-03-04 14:14 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: Renaud Barbier, Barebox List

On Fri, Mar 03, 2023 at 06:31:27PM +0100, Ahmad Fatoum wrote:
> Hi,
> 
> On 03.03.23 18:05, Renaud Barbier wrote:
> > In preparation for the introduction of the LS1021A support,
> > add a specific timer support based on the LS1046A support so
> > that delays can be used in the PBL.
> > 
> > Signed-off-by: Renaud Barbier <renaud.barbier@ametek.com>
> > ---
> >  arch/arm/lib32/Makefile                |  2 ++
> >  arch/arm/lib32/arm_architected_timer.c | 17 +++++++++++++++++
> >  include/clock.h                        |  2 ++
> >  3 files changed, 21 insertions(+)
> >  create mode 100644 arch/arm/lib32/arm_architected_timer.c
> > 
> > diff --git a/arch/arm/lib32/Makefile b/arch/arm/lib32/Makefile
> > index 82507fffc0..d54fb7644c 100644
> > --- a/arch/arm/lib32/Makefile
> > +++ b/arch/arm/lib32/Makefile
> > @@ -31,6 +31,8 @@ extra-y += barebox.lds
> >  pbl-y	+= lib1funcs.o
> >  pbl-y	+= ashldi3.o
> >  pbl-y	+= div0.o
> > +pbl-$(CONFIG_CPU_32v7)	+= arm_architected_timer.o
> > +CFLAGS_arm_architected_timer.o := -march=armv7-a
> 
> Sorry, I should have been clearer before. Once you only build the
> file for ARMv7, you don't need to mess with -march=armv7-a anymore,
> see arch/arm/Makefile:
>   
>   arch-$(CONFIG_CPU_32v7) :=-D__LINUX_ARM_ARCH__=7 $(call cc-option,-march=armv7-a,-march=armv5t -Wa$(comma)-march=armv7-a)

You still need to add -march=armv7-a. CONFIG_CPU_32v7 means support for
that CPU is enabled, but that isn't necessarily the only CPU supported.
arch/arm/Makefile continues with:

arch-$(CONFIG_CPU_32v6)         :=-D__LINUX_ARM_ARCH__=6 $(call cc-option,-march=armv6,-march=armv5t -Wa$(comma)-march=armv6)
arch-$(CONFIG_CPU_32v5)         :=-D__LINUX_ARM_ARCH__=5 $(call cc-option,-march=armv5te,-march=armv4t)
arch-$(CONFIG_CPU_32v4T)        :=-D__LINUX_ARM_ARCH__=4 -march=armv4t

That means when you build barebox with CONFIG_CPU_32v7 and
CONFIG_CPU_32v4T enabled you'll end up with -march=armv4t. In that case
you still have to explicitly pass -march=armv7-a for compilation of
arm_architected_timer.c.

It's perfectly fine how Renaud did it here.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



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

* RE: Subject: [PATCH 1/1] ARM:lib32: add architected timer
  2023-03-03 17:31 ` Ahmad Fatoum
  2023-03-04 14:14   ` Sascha Hauer
@ 2023-03-06 13:13   ` Renaud Barbier
  1 sibling, 0 replies; 6+ messages in thread
From: Renaud Barbier @ 2023-03-06 13:13 UTC (permalink / raw)
  To: Ahmad Fatoum, Barebox List

> > ---
> >  arch/arm/lib32/Makefile                |  2 ++
> >  arch/arm/lib32/arm_architected_timer.c | 17 +++++++++++++++++
> >  include/clock.h                        |  2 ++
> >  3 files changed, 21 insertions(+)
> > --- /dev/null
> > +++ b/arch/arm/lib32/arm_architected_timer.c
> > @@ -0,0 +1,17 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +
> > +#include <asm/system.h>
> > +#include <clock.h>
> > +#include <common.h>
> > +
> > +/* Unlike the ARMv8, the timer is not generic to ARM32 */ void
> > +arm_architected_timer_udelay(unsigned long us) {
> > +     unsigned long long ticks, cntfrq = get_cntfrq();
> > +     unsigned long long start = get_cntpct();
> > +
> > +     ticks = us * cntfrq + 999999;
> > +     do_div(ticks, 1000000);
> 
> There's DIV_ROUND_UP_ULL you could use instead of opencoding that.
> I see that we round down in the udelay for ARM64.
> Do you think we should rather be rounding up there too?
> 
> In any case, it's worth mentioning why you choose to round up here in the
> commit message.
> 
 I must have picked up these two lines of code somewhere because I had to use do_div as I was getting an error: " undefined reference to `__udivdi3'"
To round down I will use DIV_ROUND_DOWN_ULL instead. 
Thanks you for pointing this out. 

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

* Re: Subject: [PATCH 1/1] ARM:lib32: add architected timer
  2023-03-07 16:17 Renaud Barbier
@ 2023-03-09 10:48 ` Sascha Hauer
  0 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2023-03-09 10:48 UTC (permalink / raw)
  To: Renaud Barbier; +Cc: Barebox List

On Tue, Mar 07, 2023 at 04:17:08PM +0000, Renaud Barbier wrote:
> In preparation for the introduction of the LS1021A support,
> add a specific timer support based on the LS1046A support so
> that delays can be used in the PBL.
> 
> Signed-off-by: Renaud Barbier <renaud.barbier@ametek.com>
> ---
>  arch/arm/lib32/Makefile                |  2 ++
>  arch/arm/lib32/arm_architected_timer.c | 17 +++++++++++++++++
>  include/clock.h                        |  2 ++
>  3 files changed, 21 insertions(+)
>  create mode 100644 arch/arm/lib32/arm_architected_timer.c

Applied, thanks

Sascha

> 
> diff --git a/arch/arm/lib32/Makefile b/arch/arm/lib32/Makefile
> index 82507fffc0..d54fb7644c 100644
> --- a/arch/arm/lib32/Makefile
> +++ b/arch/arm/lib32/Makefile
> @@ -31,6 +31,8 @@ extra-y += barebox.lds
>  pbl-y	+= lib1funcs.o
>  pbl-y	+= ashldi3.o
>  pbl-y	+= div0.o
> +pbl-$(CONFIG_CPU_32v7)	+= arm_architected_timer.o
> +CFLAGS_arm_architected_timer.o := -march=armv7-a
>  
>  obj-pbl-y	+= setjmp.o
>  
> diff --git a/arch/arm/lib32/arm_architected_timer.c b/arch/arm/lib32/arm_architected_timer.c
> new file mode 100644
> index 0000000000..54eca13f8b
> --- /dev/null
> +++ b/arch/arm/lib32/arm_architected_timer.c
> @@ -0,0 +1,17 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +
> +#include <asm/system.h>
> +#include <clock.h>
> +#include <common.h>
> +
> +/* Unlike the ARMv8, the timer is not generic to ARM32 */
> +void arm_architected_timer_udelay(unsigned long us)
> +{
> +	unsigned long long ticks, cntfrq = get_cntfrq();
> +	unsigned long long start = get_cntpct();
> +
> +	ticks = DIV_ROUND_DOWN_ULL((us * cntfrq), 1000000);
> +
> +	while ((long)(start + ticks - get_cntpct()) > 0)
> +		;
> +}
> diff --git a/include/clock.h b/include/clock.h
> index e6197e7eb0..8e07c35d37 100644
> --- a/include/clock.h
> +++ b/include/clock.h
> @@ -35,6 +35,8 @@ uint32_t clocksource_hz2mult(uint32_t hz, uint32_t shift_constant);
>  int is_timeout(uint64_t start_ns, uint64_t time_offset_ns);
>  int is_timeout_non_interruptible(uint64_t start_ns, uint64_t time_offset_ns);
>  
> +void arm_architected_timer_udelay(unsigned long us);
> +
>  void ndelay(unsigned long nsecs);
>  void udelay(unsigned long usecs);
>  void mdelay(unsigned long msecs);
> -- 
> 2.27.0
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



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

* Subject: [PATCH 1/1] ARM:lib32: add architected timer
@ 2023-03-07 16:17 Renaud Barbier
  2023-03-09 10:48 ` Sascha Hauer
  0 siblings, 1 reply; 6+ messages in thread
From: Renaud Barbier @ 2023-03-07 16:17 UTC (permalink / raw)
  To: Barebox List

In preparation for the introduction of the LS1021A support,
add a specific timer support based on the LS1046A support so
that delays can be used in the PBL.

Signed-off-by: Renaud Barbier <renaud.barbier@ametek.com>
---
 arch/arm/lib32/Makefile                |  2 ++
 arch/arm/lib32/arm_architected_timer.c | 17 +++++++++++++++++
 include/clock.h                        |  2 ++
 3 files changed, 21 insertions(+)
 create mode 100644 arch/arm/lib32/arm_architected_timer.c

diff --git a/arch/arm/lib32/Makefile b/arch/arm/lib32/Makefile
index 82507fffc0..d54fb7644c 100644
--- a/arch/arm/lib32/Makefile
+++ b/arch/arm/lib32/Makefile
@@ -31,6 +31,8 @@ extra-y += barebox.lds
 pbl-y	+= lib1funcs.o
 pbl-y	+= ashldi3.o
 pbl-y	+= div0.o
+pbl-$(CONFIG_CPU_32v7)	+= arm_architected_timer.o
+CFLAGS_arm_architected_timer.o := -march=armv7-a
 
 obj-pbl-y	+= setjmp.o
 
diff --git a/arch/arm/lib32/arm_architected_timer.c b/arch/arm/lib32/arm_architected_timer.c
new file mode 100644
index 0000000000..54eca13f8b
--- /dev/null
+++ b/arch/arm/lib32/arm_architected_timer.c
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <asm/system.h>
+#include <clock.h>
+#include <common.h>
+
+/* Unlike the ARMv8, the timer is not generic to ARM32 */
+void arm_architected_timer_udelay(unsigned long us)
+{
+	unsigned long long ticks, cntfrq = get_cntfrq();
+	unsigned long long start = get_cntpct();
+
+	ticks = DIV_ROUND_DOWN_ULL((us * cntfrq), 1000000);
+
+	while ((long)(start + ticks - get_cntpct()) > 0)
+		;
+}
diff --git a/include/clock.h b/include/clock.h
index e6197e7eb0..8e07c35d37 100644
--- a/include/clock.h
+++ b/include/clock.h
@@ -35,6 +35,8 @@ uint32_t clocksource_hz2mult(uint32_t hz, uint32_t shift_constant);
 int is_timeout(uint64_t start_ns, uint64_t time_offset_ns);
 int is_timeout_non_interruptible(uint64_t start_ns, uint64_t time_offset_ns);
 
+void arm_architected_timer_udelay(unsigned long us);
+
 void ndelay(unsigned long nsecs);
 void udelay(unsigned long usecs);
 void mdelay(unsigned long msecs);
-- 
2.27.0



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

end of thread, other threads:[~2023-03-09 10:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-03 17:05 Subject: [PATCH 1/1] ARM:lib32: add architected timer Renaud Barbier
2023-03-03 17:31 ` Ahmad Fatoum
2023-03-04 14:14   ` Sascha Hauer
2023-03-06 13:13   ` Renaud Barbier
2023-03-07 16:17 Renaud Barbier
2023-03-09 10:48 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox