~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/kvm/include/riscv/arch_timer.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 /*
  3  * RISC-V Arch Timer(sstc) specific interface
  4  *
  5  * Copyright (c) 2024 Intel Corporation
  6  */
  7 
  8 #ifndef SELFTEST_KVM_ARCH_TIMER_H
  9 #define SELFTEST_KVM_ARCH_TIMER_H
 10 
 11 #include <asm/csr.h>
 12 #include <asm/vdso/processor.h>
 13 
 14 static unsigned long timer_freq;
 15 
 16 #define msec_to_cycles(msec)    \
 17         ((timer_freq) * (uint64_t)(msec) / 1000)
 18 
 19 #define usec_to_cycles(usec)    \
 20         ((timer_freq) * (uint64_t)(usec) / 1000000)
 21 
 22 #define cycles_to_usec(cycles) \
 23         ((uint64_t)(cycles) * 1000000 / (timer_freq))
 24 
 25 static inline uint64_t timer_get_cycles(void)
 26 {
 27         return csr_read(CSR_TIME);
 28 }
 29 
 30 static inline void timer_set_cmp(uint64_t cval)
 31 {
 32         csr_write(CSR_STIMECMP, cval);
 33 }
 34 
 35 static inline uint64_t timer_get_cmp(void)
 36 {
 37         return csr_read(CSR_STIMECMP);
 38 }
 39 
 40 static inline void timer_irq_enable(void)
 41 {
 42         csr_set(CSR_SIE, IE_TIE);
 43 }
 44 
 45 static inline void timer_irq_disable(void)
 46 {
 47         csr_clear(CSR_SIE, IE_TIE);
 48 }
 49 
 50 static inline void timer_set_next_cmp_ms(uint32_t msec)
 51 {
 52         uint64_t now_ct = timer_get_cycles();
 53         uint64_t next_ct = now_ct + msec_to_cycles(msec);
 54 
 55         timer_set_cmp(next_ct);
 56 }
 57 
 58 static inline void __delay(uint64_t cycles)
 59 {
 60         uint64_t start = timer_get_cycles();
 61 
 62         while ((timer_get_cycles() - start) < cycles)
 63                 cpu_relax();
 64 }
 65 
 66 static inline void udelay(unsigned long usec)
 67 {
 68         __delay(usec_to_cycles(usec));
 69 }
 70 
 71 #endif /* SELFTEST_KVM_ARCH_TIMER_H */
 72 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php