diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2020-07-15 22:58:34 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2020-07-15 22:58:34 +0000 |
commit | e78a2776a9bc871165e090fd4ed7d06545f3f00d (patch) | |
tree | 836f9b2075ceb9a05defc353faec45b47b0e5cd5 | |
parent | 1cd56b31e3bb5eaffab676cf14d382a209377bb9 (diff) |
Userland timecounter implementation for arm64.
ok naddy@
-rw-r--r-- | lib/libc/arch/aarch64/gen/usertc.c | 32 | ||||
-rw-r--r-- | sys/arch/arm64/dev/agtimer.c | 15 | ||||
-rw-r--r-- | sys/arch/arm64/include/timetc.h | 4 |
3 files changed, 43 insertions, 8 deletions
diff --git a/lib/libc/arch/aarch64/gen/usertc.c b/lib/libc/arch/aarch64/gen/usertc.c index f73831f742e..d1dd51c9a78 100644 --- a/lib/libc/arch/aarch64/gen/usertc.c +++ b/lib/libc/arch/aarch64/gen/usertc.c @@ -1,6 +1,6 @@ -/* $OpenBSD: usertc.c,v 1.1 2020/07/06 13:33:05 pirofti Exp $ */ +/* $OpenBSD: usertc.c,v 1.2 2020/07/15 22:58:33 kettenis Exp $ */ /* - * Copyright (c) 2020 Paul Irofti <paul@irofti.net> + * Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -18,4 +18,30 @@ #include <sys/types.h> #include <sys/timetc.h> -int (*const _tc_get_timecount)(struct timekeep *, u_int *) = NULL; +static inline u_int +agtimer_get_timecount(struct timecounter *tc) +{ + uint64_t val; + + /* + * No need to work around Cortex-A73 errata 858921 since we + * only look at the low 32 bits here. + */ + __asm volatile("isb" ::: "memory"); + __asm volatile("mrs %x0, CNTVCT_EL0" : "=r" (val)); + return (val & 0xffffffff); +} + +static int +tc_get_timecount(struct timekeep *tk, u_int *tc) +{ + switch (tk->tk_user) { + case TC_AGTIMER: + *tc = agtimer_get_timecount(NULL); + return 0; + } + + return -1; +} + +int (*const _tc_get_timecount)(struct timekeep *, u_int *) = tc_get_timecount; diff --git a/sys/arch/arm64/dev/agtimer.c b/sys/arch/arm64/dev/agtimer.c index d64ce663563..199c10a5f93 100644 --- a/sys/arch/arm64/dev/agtimer.c +++ b/sys/arch/arm64/dev/agtimer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: agtimer.c,v 1.14 2020/07/11 15:22:44 kettenis Exp $ */ +/* $OpenBSD: agtimer.c,v 1.15 2020/07/15 22:58:33 kettenis Exp $ */ /* * Copyright (c) 2011 Dale Rahn <drahn@openbsd.org> * Copyright (c) 2013 Patrick Wildt <patrick@blueri.se> @@ -43,7 +43,8 @@ int32_t agtimer_frequency = TIMER_FREQUENCY; u_int agtimer_get_timecount(struct timecounter *); static struct timecounter agtimer_timecounter = { - agtimer_get_timecount, NULL, 0x7fffffff, 0, "agtimer", 0, NULL, 0 + agtimer_get_timecount, NULL, 0xffffffff, 0, "agtimer", 0, NULL, + TC_AGTIMER }; struct agtimer_pcpu_softc { @@ -191,7 +192,15 @@ agtimer_attach(struct device *parent, struct device *self, void *aux) u_int agtimer_get_timecount(struct timecounter *tc) { - return agtimer_readcnt64(); + uint64_t val; + + /* + * No need to work around Cortex-A73 errata 858921 since we + * only look at the low 32 bits here. + */ + __asm volatile("isb" ::: "memory"); + __asm volatile("mrs %x0, CNTVCT_EL0" : "=r" (val)); + return (val & 0xffffffff); } int diff --git a/sys/arch/arm64/include/timetc.h b/sys/arch/arm64/include/timetc.h index be5be950d4d..653a7d33189 100644 --- a/sys/arch/arm64/include/timetc.h +++ b/sys/arch/arm64/include/timetc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:07 pirofti Exp $ */ +/* $OpenBSD: timetc.h,v 1.2 2020/07/15 22:58:33 kettenis Exp $ */ /* * Copyright (c) 2020 Paul Irofti <paul@irofti.net> * @@ -18,6 +18,6 @@ #ifndef _MACHINE_TIMETC_H_ #define _MACHINE_TIMETC_H_ -#define TC_LAST 0 +#define TC_AGTIMER 1 #endif /* _MACHINE_TIMETC_H_ */ |