[PATCH 0/3] Some ARM cleanups

11 views
Skip to first unread message

Jan Kiszka

unread,
Jun 17, 2015, 3:28:11 AM6/17/15
to jailho...@googlegroups.com
Mostly targeting demo inmates, see patches for details.

Jan

Jan Kiszka (3):
arm: Remove unused defines
inmates: arm: Add generic timer services
inmates: arm: Switch gic-demo to new timer services

hypervisor/arch/arm/include/asm/platform.h | 5 --
hypervisor/arch/arm/include/asm/sysregs.h | 2 +
inmates/demos/arm/gic-demo.c | 49 ++++---------------
inmates/lib/arm/Makefile | 2 +-
inmates/lib/arm/include/inmates/inmate.h | 16 +++++++
inmates/lib/arm/include/mach-sun7i/mach/timer.h | 1 -
inmates/lib/arm/include/mach-tegra124/mach/timer.h | 1 -
inmates/lib/arm/include/mach-vexpress/mach/timer.h | 1 -
inmates/lib/arm/timer.c | 55 ++++++++++++++++++++++
9 files changed, 84 insertions(+), 48 deletions(-)
create mode 100644 inmates/lib/arm/timer.c

--
2.1.4

Jan Kiszka

unread,
Jun 17, 2015, 3:28:11 AM6/17/15
to jailho...@googlegroups.com
Historic left-overs, nowhere referenced anymore.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
hypervisor/arch/arm/include/asm/platform.h | 5 -----
1 file changed, 5 deletions(-)

diff --git a/hypervisor/arch/arm/include/asm/platform.h b/hypervisor/arch/arm/include/asm/platform.h
index fa7bfdc..1911ee0 100644
--- a/hypervisor/arch/arm/include/asm/platform.h
+++ b/hypervisor/arch/arm/include/asm/platform.h
@@ -86,10 +86,5 @@

#endif /* CONFIG_MACH_TEGRA124 */

-#define HOTPLUG_SPIN 1
-/*
-#define HOTPLUG_PSCI 1
-*/
-
#endif /* !__ASSEMBLY__ */
#endif /* !_JAILHOUSE_ASM_PLATFORM_H */
--
2.1.4

Jan Kiszka

unread,
Jun 17, 2015, 3:28:12 AM6/17/15
to jailho...@googlegroups.com
Make use of the factored-out services and drop the now unused TIMER_FREQ
configuration constant.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
inmates/demos/arm/gic-demo.c | 49 +++++-----------------
inmates/lib/arm/include/mach-sun7i/mach/timer.h | 1 -
inmates/lib/arm/include/mach-tegra124/mach/timer.h | 1 -
inmates/lib/arm/include/mach-vexpress/mach/timer.h | 1 -
4 files changed, 10 insertions(+), 42 deletions(-)

diff --git a/inmates/demos/arm/gic-demo.c b/inmates/demos/arm/gic-demo.c
index e5c3669..330da66 100644
--- a/inmates/demos/arm/gic-demo.c
+++ b/inmates/demos/arm/gic-demo.c
@@ -11,45 +11,14 @@
*/

#include <asm/gic_common.h>
-#include <asm/sysregs.h>
#include <inmates/inmate.h>
#include <mach/timer.h>

#define BEATS_PER_SEC 10
-#define TICKS_PER_BEAT (TIMER_FREQ / BEATS_PER_SEC)

+static u64 ticks_per_beat;
static volatile u64 expected_ticks;

-static void timer_arm(u64 timeout)
-{
- arm_write_sysreg(CNTV_TVAL_EL0, timeout);
- arm_write_sysreg(CNTV_CTL_EL0, 1);
-}
-
-static u64 get_actual_ticks(void)
-{
- u64 pct64;
-
- arm_read_sysreg(CNTPCT, pct64);
- return pct64;
-}
-
-static unsigned long emul_division(u64 val, u64 div)
-{
- unsigned long cnt = 0;
-
- while (val > div) {
- val -= div;
- cnt++;
- }
- return cnt;
-}
-
-static inline unsigned long ticks_to_ns(u64 ticks)
-{
- return emul_division(ticks * 1000, TIMER_FREQ / 1000 / 1000);
-}
-
static void handle_IRQ(unsigned int irqn)
{
static u64 min_delta = ~0ULL, max_delta = 0;
@@ -58,15 +27,16 @@ static void handle_IRQ(unsigned int irqn)
if (irqn != TIMER_IRQ)
return;

- delta = get_actual_ticks() - expected_ticks;
+ delta = timer_get_ticks() - expected_ticks;
if (delta < min_delta)
min_delta = delta;
if (delta > max_delta)
max_delta = delta;

printk("Timer fired, jitter: %6ld ns, min: %6ld ns, max: %6ld ns\n",
- ticks_to_ns(delta), ticks_to_ns(min_delta),
- ticks_to_ns(max_delta));
+ (long)timer_ticks_to_ns(delta),
+ (long)timer_ticks_to_ns(min_delta),
+ (long)timer_ticks_to_ns(max_delta));

#ifdef CONFIG_MACH_SUN7I
/* let green LED on Banana Pi blink */
@@ -74,8 +44,8 @@ static void handle_IRQ(unsigned int irqn)
mmio_write32(LED_REG, mmio_read32(LED_REG) ^ (1<<24));
#endif

- expected_ticks = get_actual_ticks() + TICKS_PER_BEAT;
- timer_arm(TICKS_PER_BEAT);
+ expected_ticks = timer_get_ticks() + ticks_per_beat;
+ timer_start(ticks_per_beat);
}

void inmate_main(void)
@@ -85,8 +55,9 @@ void inmate_main(void)
gic_enable_irq(TIMER_IRQ);

printk("Initializing the timer...\n");
- expected_ticks = get_actual_ticks() + TICKS_PER_BEAT;
- timer_arm(TICKS_PER_BEAT);
+ ticks_per_beat = timer_get_frequency() / BEATS_PER_SEC;
+ expected_ticks = timer_get_ticks() + ticks_per_beat;
+ timer_start(ticks_per_beat);

while (1)
asm volatile("wfi" : : : "memory");
diff --git a/inmates/lib/arm/include/mach-sun7i/mach/timer.h b/inmates/lib/arm/include/mach-sun7i/mach/timer.h
index 78088ae..b0b544c 100644
--- a/inmates/lib/arm/include/mach-sun7i/mach/timer.h
+++ b/inmates/lib/arm/include/mach-sun7i/mach/timer.h
@@ -11,4 +11,3 @@
*/

#define TIMER_IRQ 27
-#define TIMER_FREQ 24000000
diff --git a/inmates/lib/arm/include/mach-tegra124/mach/timer.h b/inmates/lib/arm/include/mach-tegra124/mach/timer.h
index 478f6cb..428162d 100644
--- a/inmates/lib/arm/include/mach-tegra124/mach/timer.h
+++ b/inmates/lib/arm/include/mach-tegra124/mach/timer.h
@@ -11,4 +11,3 @@
*/

#define TIMER_IRQ 27
-#define TIMER_FREQ 12000000
diff --git a/inmates/lib/arm/include/mach-vexpress/mach/timer.h b/inmates/lib/arm/include/mach-vexpress/mach/timer.h
index beecf84..be6e411 100644
--- a/inmates/lib/arm/include/mach-vexpress/mach/timer.h
+++ b/inmates/lib/arm/include/mach-vexpress/mach/timer.h
@@ -11,4 +11,3 @@
*/

#define TIMER_IRQ 27
-#define TIMER_FREQ 0x10000000
--
2.1.4

Jan Kiszka

unread,
Jun 17, 2015, 3:28:12 AM6/17/15
to jailho...@googlegroups.com
Factor out some logic from the gic-demo that reads and programs the
generic virtual timer, including read-out of the timer frequency from
CNTFRQ.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
hypervisor/arch/arm/include/asm/sysregs.h | 2 ++
inmates/lib/arm/Makefile | 2 +-
inmates/lib/arm/include/inmates/inmate.h | 16 +++++++++
inmates/lib/arm/timer.c | 55 +++++++++++++++++++++++++++++++
4 files changed, 74 insertions(+), 1 deletion(-)
create mode 100644 inmates/lib/arm/timer.c

diff --git a/hypervisor/arch/arm/include/asm/sysregs.h b/hypervisor/arch/arm/include/asm/sysregs.h
index d1f63b3..3011364 100644
--- a/hypervisor/arch/arm/include/asm/sysregs.h
+++ b/hypervisor/arch/arm/include/asm/sysregs.h
@@ -97,6 +97,8 @@
#define TPIDRURO SYSREG_32(0, c13, c0, 3)
#define TPIDRPRW SYSREG_32(0, c13, c0, 4)

+#define CNTFRQ SYSREG_32(0, c14, c0, 0)
+
#define ATS1HR SYSREG_32(4, c7, c8, 0)

#define ICIALLUIS SYSREG_32(0, c7, c1, 0)
diff --git a/inmates/lib/arm/Makefile b/inmates/lib/arm/Makefile
index 8478a49..c116181 100644
--- a/inmates/lib/arm/Makefile
+++ b/inmates/lib/arm/Makefile
@@ -14,7 +14,7 @@ include $(INMATES_LIB)/Makefile.lib

always := lib.a

-lib-y := header.o gic.o printk.o
+lib-y := header.o gic.o printk.o timer.o
lib-$(CONFIG_ARM_GIC) += gic-v2.o
lib-$(CONFIG_ARM_GIC_V3) += gic-v3.o
lib-$(CONFIG_SERIAL_AMBA_PL011) += uart-pl011.o
diff --git a/inmates/lib/arm/include/inmates/inmate.h b/inmates/lib/arm/include/inmates/inmate.h
index 062ada3..63a3e35 100644
--- a/inmates/lib/arm/include/inmates/inmate.h
+++ b/inmates/lib/arm/include/inmates/inmate.h
@@ -13,6 +13,17 @@
#define _JAILHOUSE_INMATES_INMATE_H

#ifndef __ASSEMBLY__
+typedef signed char s8;
+typedef unsigned char u8;
+
+typedef signed short s16;
+typedef unsigned short u16;
+
+typedef signed int s32;
+typedef unsigned int u32;
+
+typedef signed long long s64;
+typedef unsigned long long u64;

static inline void *memset(void *addr, int val, unsigned int size)
{
@@ -34,5 +45,10 @@ typedef void (*irq_handler_t)(unsigned int);
void gic_setup(irq_handler_t handler);
void gic_enable_irq(unsigned int irq);

+unsigned long timer_get_frequency(void);
+u64 timer_get_ticks(void);
+u64 timer_ticks_to_ns(u64 ticks);
+void timer_start(u64 timeout);
+
#endif /* !__ASSEMBLY__ */
#endif
diff --git a/inmates/lib/arm/timer.c b/inmates/lib/arm/timer.c
new file mode 100644
index 0000000..5f5e865
--- /dev/null
+++ b/inmates/lib/arm/timer.c
@@ -0,0 +1,55 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) ARM Limited, 2014
+ * Copyright (c) Siemens AG, 2015
+ *
+ * Authors:
+ * Jean-Philippe Brucker <jean-phili...@arm.com>
+ * Jan Kiszka <jan.k...@siemens.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+
+#include <asm/sysregs.h>
+#include <inmates/inmate.h>
+
+unsigned long timer_get_frequency(void)
+{
+ u32 freq;
+
+ arm_read_sysreg(CNTFRQ, freq);
+ return freq;
+}
+
+u64 timer_get_ticks(void)
+{
+ u64 pct64;
+
+ arm_read_sysreg(CNTPCT, pct64);
+ return pct64;
+}
+
+static unsigned long emul_division(u64 val, u64 div)
+{
+ unsigned long cnt = 0;
+
+ while (val > div) {
+ val -= div;
+ cnt++;
+ }
+ return cnt;
+}
+
+u64 timer_ticks_to_ns(u64 ticks)
+{
+ return emul_division(ticks * 1000,
+ timer_get_frequency() / 1000 / 1000);
+}
+
+void timer_start(u64 timeout)
+{
+ arm_write_sysreg(CNTV_TVAL_EL0, timeout);
+ arm_write_sysreg(CNTV_CTL_EL0, 1);
+}
--
2.1.4

Reply all
Reply to author
Forward
0 new messages