1 /* $OpenBSD: usertc.c,v 1.2 2020/07/15 22:58:33 kettenis Exp $ */ 2 /* 3 * Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #include <sys/types.h> 19 #include <sys/timetc.h> 20 21 static inline u_int 22 agtimer_get_timecount(struct timecounter *tc) 23 { 24 uint64_t val; 25 26 /* 27 * No need to work around Cortex-A73 errata 858921 since we 28 * only look at the low 32 bits here. 29 */ 30 __asm volatile("isb" ::: "memory"); 31 __asm volatile("mrs %x0, CNTVCT_EL0" : "=r" (val)); 32 return (val & 0xffffffff); 33 } 34 35 static int 36 tc_get_timecount(struct timekeep *tk, u_int *tc) 37 { 38 switch (tk->tk_user) { 39 case TC_AGTIMER: 40 *tc = agtimer_get_timecount(NULL); 41 return 0; 42 } 43 44 return -1; 45 } 46 47 int (*const _tc_get_timecount)(struct timekeep *, u_int *) = tc_get_timecount; 48