diff options
author | Visa Hankala <visa@cvs.openbsd.org> | 2020-07-18 08:37:45 +0000 |
---|---|---|
committer | Visa Hankala <visa@cvs.openbsd.org> | 2020-07-18 08:37:45 +0000 |
commit | b8e39666a5fab838c785939e76bff8c071a6eca8 (patch) | |
tree | 92b266dd5fbe763a1b7da28eebce02c3476fba3e | |
parent | 0e1dac87e7cfe9d38f19194836f95666c950ef8f (diff) |
Userland timecounter implementation for octeon
OK naddy@; no objections from kettenis@
-rw-r--r-- | distrib/sets/lists/comp/md.loongson | 1 | ||||
-rw-r--r-- | distrib/sets/lists/comp/md.octeon | 1 | ||||
-rw-r--r-- | distrib/sets/lists/comp/md.sgi | 1 | ||||
-rw-r--r-- | lib/libc/arch/mips64/gen/usertc.c | 33 | ||||
-rw-r--r-- | sys/arch/loongson/include/timetc.h | 4 | ||||
-rw-r--r-- | sys/arch/mips64/include/mips_cpu.h | 3 | ||||
-rw-r--r-- | sys/arch/mips64/include/timetc.h | 23 | ||||
-rw-r--r-- | sys/arch/octeon/include/timetc.h | 4 | ||||
-rw-r--r-- | sys/arch/octeon/octeon/machdep.c | 6 | ||||
-rw-r--r-- | sys/arch/sgi/include/timetc.h | 4 |
10 files changed, 69 insertions, 11 deletions
diff --git a/distrib/sets/lists/comp/md.loongson b/distrib/sets/lists/comp/md.loongson index 903173a69d0..21751f6c405 100644 --- a/distrib/sets/lists/comp/md.loongson +++ b/distrib/sets/lists/comp/md.loongson @@ -105,6 +105,7 @@ ./usr/include/mips64/spinlock.h ./usr/include/mips64/sysarch.h ./usr/include/mips64/tcb.h +./usr/include/mips64/timetc.h ./usr/include/mips64/trap.h ./usr/include/mips64/vmparam.h ./usr/include/unwind.h diff --git a/distrib/sets/lists/comp/md.octeon b/distrib/sets/lists/comp/md.octeon index 071bd6fca66..bda9c3565a0 100644 --- a/distrib/sets/lists/comp/md.octeon +++ b/distrib/sets/lists/comp/md.octeon @@ -49,6 +49,7 @@ ./usr/include/mips64/spinlock.h ./usr/include/mips64/sysarch.h ./usr/include/mips64/tcb.h +./usr/include/mips64/timetc.h ./usr/include/mips64/trap.h ./usr/include/mips64/vmparam.h ./usr/include/octeon diff --git a/distrib/sets/lists/comp/md.sgi b/distrib/sets/lists/comp/md.sgi index 103b29f5833..f80b6a25de0 100644 --- a/distrib/sets/lists/comp/md.sgi +++ b/distrib/sets/lists/comp/md.sgi @@ -49,6 +49,7 @@ ./usr/include/mips64/spinlock.h ./usr/include/mips64/sysarch.h ./usr/include/mips64/tcb.h +./usr/include/mips64/timetc.h ./usr/include/mips64/trap.h ./usr/include/mips64/vmparam.h ./usr/include/sgi diff --git a/lib/libc/arch/mips64/gen/usertc.c b/lib/libc/arch/mips64/gen/usertc.c index f73831f742e..be7263e1c46 100644 --- a/lib/libc/arch/mips64/gen/usertc.c +++ b/lib/libc/arch/mips64/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/18 08:37:43 visa Exp $ */ /* - * Copyright (c) 2020 Paul Irofti <paul@irofti.net> + * Copyright (c) 2020 Visa Hankala * * 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,31 @@ #include <sys/types.h> #include <sys/timetc.h> -int (*const _tc_get_timecount)(struct timekeep *, u_int *) = NULL; +static inline u_int +get_cp0_count(void) +{ + uint32_t count; + + __asm__ volatile ( + " .set push\n" + " .set mips64r2\n" + " rdhwr %0, $2\n" + " .set pop\n" + : "=r" (count)); + + return count; +} + +static int +tc_get_timecount(struct timekeep *tk, u_int *tc) +{ + switch (tk->tk_user) { + case TC_CP0_COUNT: + *tc = get_cp0_count(); + return 0; + } + + return -1; +} + +int (*const _tc_get_timecount)(struct timekeep *, u_int *) = tc_get_timecount; diff --git a/sys/arch/loongson/include/timetc.h b/sys/arch/loongson/include/timetc.h index be5be950d4d..e5905d45fdb 100644 --- a/sys/arch/loongson/include/timetc.h +++ b/sys/arch/loongson/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/18 08:37:43 visa 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 +#include <mips64/timetc.h> #endif /* _MACHINE_TIMETC_H_ */ diff --git a/sys/arch/mips64/include/mips_cpu.h b/sys/arch/mips64/include/mips_cpu.h index 65f555043cd..f0e49d6e9f9 100644 --- a/sys/arch/mips64/include/mips_cpu.h +++ b/sys/arch/mips64/include/mips_cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mips_cpu.h,v 1.8 2018/04/09 13:46:15 visa Exp $ */ +/* $OpenBSD: mips_cpu.h,v 1.9 2020/07/18 08:37:43 visa Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -373,6 +373,7 @@ * HWREna register */ #define HWRENA_ULR 0x20000000u +#define HWRENA_CC 0x00000004u #endif /* _KERNEL || _STANDALONE */ diff --git a/sys/arch/mips64/include/timetc.h b/sys/arch/mips64/include/timetc.h new file mode 100644 index 00000000000..fb00493b871 --- /dev/null +++ b/sys/arch/mips64/include/timetc.h @@ -0,0 +1,23 @@ +/* $OpenBSD: timetc.h,v 1.3 2020/07/18 08:37:43 visa Exp $ */ +/* + * Copyright (c) 2020 Paul Irofti <paul@irofti.net> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MIPS64_TIMETC_H_ +#define _MIPS64_TIMETC_H_ + +#define TC_CP0_COUNT 1 + +#endif /* _MIPS64_TIMETC_H_ */ diff --git a/sys/arch/octeon/include/timetc.h b/sys/arch/octeon/include/timetc.h index ec63af16d18..e5905d45fdb 100644 --- a/sys/arch/octeon/include/timetc.h +++ b/sys/arch/octeon/include/timetc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:08 pirofti Exp $ */ +/* $OpenBSD: timetc.h,v 1.2 2020/07/18 08:37:43 visa 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 +#include <mips64/timetc.h> #endif /* _MACHINE_TIMETC_H_ */ diff --git a/sys/arch/octeon/octeon/machdep.c b/sys/arch/octeon/octeon/machdep.c index 8dbabe647fc..060f5acd8f7 100644 --- a/sys/arch/octeon/octeon/machdep.c +++ b/sys/arch/octeon/octeon/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.126 2020/07/11 15:18:08 visa Exp $ */ +/* $OpenBSD: machdep.c,v 1.127 2020/07/18 08:37:44 visa Exp $ */ /* * Copyright (c) 2009, 2010 Miodrag Vallat. @@ -602,6 +602,7 @@ mips_init(register_t a0, register_t a1, register_t a2, register_t a3) cpu_has_synced_cp0_count = 1; cp0_timecounter.tc_quality = 1000; + cp0_timecounter.tc_user = TC_CP0_COUNT; /* * Return the new kernel stack pointer. @@ -772,6 +773,9 @@ octeon_tlb_init(void) frac = ((1ULL << 63) / imul) * 2; octeon_sync_tc(PHYS_TO_XKPHYS(clk_reg, CCA_NC), cmul, frac); + /* Let userspace access the cycle counter. */ + hwrena |= HWRENA_CC; + /* * If the UserLocal register is available, let userspace * access it using the RDHWR instruction. diff --git a/sys/arch/sgi/include/timetc.h b/sys/arch/sgi/include/timetc.h index ec63af16d18..f538f141819 100644 --- a/sys/arch/sgi/include/timetc.h +++ b/sys/arch/sgi/include/timetc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:08 pirofti Exp $ */ +/* $OpenBSD: timetc.h,v 1.2 2020/07/18 08:37:44 visa 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 +#include <mips64/timetc.h> #endif /* _MACHINE_TIMETC_H_ */ |