* Subject: [PATCH 1/3] ARM:lib32: add architected timer
@ 2023-03-01 16:59 Renaud Barbier
2023-03-01 17:41 ` Ahmad Fatoum
0 siblings, 1 reply; 6+ messages in thread
From: Renaud Barbier @ 2023-03-01 16:59 UTC (permalink / raw)
To: Barebox List
Subject: [PATCH 1/3] ARM:lib32: add architected timer
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 | 1 +
arch/arm/lib32/pbl.c | 17 +++++++++++++++++
include/clock.h | 2 ++
3 files changed, 20 insertions(+)
create mode 100644 arch/arm/lib32/pbl.c
diff --git a/arch/arm/lib32/Makefile b/arch/arm/lib32/Makefile
index 82507fffc0..1be8d70c45 100644
--- a/arch/arm/lib32/Makefile
+++ b/arch/arm/lib32/Makefile
@@ -31,6 +31,7 @@ extra-y += barebox.lds
pbl-y += lib1funcs.o
pbl-y += ashldi3.o
pbl-y += div0.o
+pbl-y += pbl.o
obj-pbl-y += setjmp.o
diff --git a/arch/arm/lib32/pbl.c b/arch/arm/lib32/pbl.c
new file mode 100644
index 0000000000..83b49656cb
--- /dev/null
+++ b/arch/arm/lib32/pbl.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/3] ARM:lib32: add architected timer
2023-03-01 16:59 Subject: [PATCH 1/3] ARM:lib32: add architected timer Renaud Barbier
@ 2023-03-01 17:41 ` Ahmad Fatoum
2023-03-02 10:57 ` Renaud Barbier
2023-03-03 9:23 ` Renaud Barbier
0 siblings, 2 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2023-03-01 17:41 UTC (permalink / raw)
To: Renaud Barbier, Barebox List
Hello Renaud,
On 01.03.23 17:59, Renaud Barbier wrote:
> Subject: [PATCH 1/3] ARM:lib32: add architected timer
>
> 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 | 1 +
> arch/arm/lib32/pbl.c | 17 +++++++++++++++++
> include/clock.h | 2 ++
> 3 files changed, 20 insertions(+)
> create mode 100644 arch/arm/lib32/pbl.c
>
> diff --git a/arch/arm/lib32/Makefile b/arch/arm/lib32/Makefile
> index 82507fffc0..1be8d70c45 100644
> --- a/arch/arm/lib32/Makefile
> +++ b/arch/arm/lib32/Makefile
> @@ -31,6 +31,7 @@ extra-y += barebox.lds
> pbl-y += lib1funcs.o
> pbl-y += ashldi3.o
> pbl-y += div0.o
> +pbl-y += pbl.o
I think we need a CFLAGS_pbl.o := -march=armv7-a here, otherwise
this would break builds of non-ARMv7 platforms.
See arm_architected_timer.o in drivers/clocksource. Also, perhaps
you should rename the file to arm_architected_timer.c as well?
> obj-pbl-y += setjmp.o
>
> diff --git a/arch/arm/lib32/pbl.c b/arch/arm/lib32/pbl.c
> new file mode 100644
> index 0000000000..83b49656cb
> --- /dev/null
> +++ b/arch/arm/lib32/pbl.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);
--
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/3] ARM:lib32: add architected timer
2023-03-01 17:41 ` Ahmad Fatoum
@ 2023-03-02 10:57 ` Renaud Barbier
2023-03-03 9:23 ` Renaud Barbier
1 sibling, 0 replies; 6+ messages in thread
From: Renaud Barbier @ 2023-03-02 10:57 UTC (permalink / raw)
To: Ahmad Fatoum, Barebox List
> > diff --git a/arch/arm/lib32/Makefile b/arch/arm/lib32/Makefile index
> > 82507fffc0..1be8d70c45 100644
> > --- a/arch/arm/lib32/Makefile
> > +++ b/arch/arm/lib32/Makefile
> > @@ -31,6 +31,7 @@ extra-y += barebox.lds
> > pbl-y += lib1funcs.o
> > pbl-y += ashldi3.o
> > pbl-y += div0.o
> > +pbl-y += pbl.o
>
> I think we need a CFLAGS_pbl.o := -march=armv7-a here, otherwise this would
> break builds of non-ARMv7 platforms.
>
> See arm_architected_timer.o in drivers/clocksource. Also, perhaps you should
> rename the file to arm_architected_timer.c as well?
>
>
Is there a list of boards I can build barebox against to cover this case?
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: Subject: [PATCH 1/3] ARM:lib32: add architected timer
2023-03-01 17:41 ` Ahmad Fatoum
2023-03-02 10:57 ` Renaud Barbier
@ 2023-03-03 9:23 ` Renaud Barbier
2023-03-03 11:57 ` Sascha Hauer
2023-03-03 14:44 ` Ahmad Fatoum
1 sibling, 2 replies; 6+ messages in thread
From: Renaud Barbier @ 2023-03-03 9:23 UTC (permalink / raw)
To: Ahmad Fatoum, Barebox List
> On 01.03.23 17:59, Renaud Barbier wrote:
> > Subject: [PATCH 1/3] ARM:lib32: add architected timer
> >
> > 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 | 1 +
> > arch/arm/lib32/pbl.c | 17 +++++++++++++++++
> > include/clock.h | 2 ++
> > 3 files changed, 20 insertions(+)
> > create mode 100644 arch/arm/lib32/pbl.c
> >
> > diff --git a/arch/arm/lib32/Makefile b/arch/arm/lib32/Makefile index
> > 82507fffc0..1be8d70c45 100644
> > --- a/arch/arm/lib32/Makefile
> > +++ b/arch/arm/lib32/Makefile
> > @@ -31,6 +31,7 @@ extra-y += barebox.lds
> > pbl-y += lib1funcs.o
> > pbl-y += ashldi3.o
> > pbl-y += div0.o
> > +pbl-y += pbl.o
>
> I think we need a CFLAGS_pbl.o := -march=armv7-a here, otherwise this would
> break builds of non-ARMv7 platforms.
>
> See arm_architected_timer.o in drivers/clocksource. Also, perhaps you should
> rename the file to arm_architected_timer.c as well?
>
>
Would something like below makes sense in arch/arm/lib32/Makefile:
pbl-$(CONFIG_CLOCKSOURCE_ARM_ARCHITECTED_TIMER) += arm_architected_timer.o
ifeq ($(CONFIG_CPU_32v7),y)
CFLAGS_arm_architected_timer.o := -march=armv7-a
endif
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Subject: [PATCH 1/3] ARM:lib32: add architected timer
2023-03-03 9:23 ` Renaud Barbier
@ 2023-03-03 11:57 ` Sascha Hauer
2023-03-03 14:44 ` Ahmad Fatoum
1 sibling, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2023-03-03 11:57 UTC (permalink / raw)
To: Renaud Barbier; +Cc: Ahmad Fatoum, Barebox List
On Fri, Mar 03, 2023 at 09:23:13AM +0000, Renaud Barbier wrote:
> > On 01.03.23 17:59, Renaud Barbier wrote:
> > > Subject: [PATCH 1/3] ARM:lib32: add architected timer
> > >
> > > 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 | 1 +
> > > arch/arm/lib32/pbl.c | 17 +++++++++++++++++
> > > include/clock.h | 2 ++
> > > 3 files changed, 20 insertions(+)
> > > create mode 100644 arch/arm/lib32/pbl.c
> > >
> > > diff --git a/arch/arm/lib32/Makefile b/arch/arm/lib32/Makefile index
> > > 82507fffc0..1be8d70c45 100644
> > > --- a/arch/arm/lib32/Makefile
> > > +++ b/arch/arm/lib32/Makefile
> > > @@ -31,6 +31,7 @@ extra-y += barebox.lds
> > > pbl-y += lib1funcs.o
> > > pbl-y += ashldi3.o
> > > pbl-y += div0.o
> > > +pbl-y += pbl.o
> >
> > I think we need a CFLAGS_pbl.o := -march=armv7-a here, otherwise this would
> > break builds of non-ARMv7 platforms.
> >
> > See arm_architected_timer.o in drivers/clocksource. Also, perhaps you should
> > rename the file to arm_architected_timer.c as well?
> >
> >
>
> Would something like below makes sense in arch/arm/lib32/Makefile:
>
> pbl-$(CONFIG_CLOCKSOURCE_ARM_ARCHITECTED_TIMER) += arm_architected_timer.o
> ifeq ($(CONFIG_CPU_32v7),y)
> CFLAGS_arm_architected_timer.o := -march=armv7-a
> endif
I don't see what the ifeq is needed for. I think you can drop it.
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/3] ARM:lib32: add architected timer
2023-03-03 9:23 ` Renaud Barbier
2023-03-03 11:57 ` Sascha Hauer
@ 2023-03-03 14:44 ` Ahmad Fatoum
1 sibling, 0 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2023-03-03 14:44 UTC (permalink / raw)
To: Renaud Barbier, Barebox List
On 03.03.23 10:23, Renaud Barbier wrote:
>> On 01.03.23 17:59, Renaud Barbier wrote:
>>> Subject: [PATCH 1/3] ARM:lib32: add architected timer
>>>
>>> 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 | 1 +
>>> arch/arm/lib32/pbl.c | 17 +++++++++++++++++
>>> include/clock.h | 2 ++
>>> 3 files changed, 20 insertions(+)
>>> create mode 100644 arch/arm/lib32/pbl.c
>>>
>>> diff --git a/arch/arm/lib32/Makefile b/arch/arm/lib32/Makefile index
>>> 82507fffc0..1be8d70c45 100644
>>> --- a/arch/arm/lib32/Makefile
>>> +++ b/arch/arm/lib32/Makefile
>>> @@ -31,6 +31,7 @@ extra-y += barebox.lds
>>> pbl-y += lib1funcs.o
>>> pbl-y += ashldi3.o
>>> pbl-y += div0.o
>>> +pbl-y += pbl.o
>>
>> I think we need a CFLAGS_pbl.o := -march=armv7-a here, otherwise this would
>> break builds of non-ARMv7 platforms.
>>
>> See arm_architected_timer.o in drivers/clocksource. Also, perhaps you should
>> rename the file to arm_architected_timer.c as well?
>>
>>
>
> Would something like below makes sense in arch/arm/lib32/Makefile:
>
> pbl-$(CONFIG_CLOCKSOURCE_ARM_ARCHITECTED_TIMER) += arm_architected_timer.o
> ifeq ($(CONFIG_CPU_32v7),y)
> CFLAGS_arm_architected_timer.o := -march=armv7-a
> endif
If you try to compile this for CPU_32v6, you will get an assembler error.
That's why you need to explicitly set -march=armv7-a for everything that
would not work otherwise. Of course if you are on v6 and try to execute
a function containing the unallowed instructions, you get an exception,
but that shouldn't happen as you wouldn't register a clocksource on such
a platform.
In your case, you could just change it to pbl-$(CONFIG_CPU_32v7) += arm_architected_timer.o
--
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
end of thread, other threads:[~2023-03-03 14:45 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-01 16:59 Subject: [PATCH 1/3] ARM:lib32: add architected timer Renaud Barbier
2023-03-01 17:41 ` Ahmad Fatoum
2023-03-02 10:57 ` Renaud Barbier
2023-03-03 9:23 ` Renaud Barbier
2023-03-03 11:57 ` Sascha Hauer
2023-03-03 14:44 ` Ahmad Fatoum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox