gettimeofday.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ASM_VDSO_GETTIMEOFDAY_H
  3. #define __ASM_VDSO_GETTIMEOFDAY_H
  4. #ifndef __ASSEMBLY__
  5. #include <asm/barrier.h>
  6. #include <asm/unistd.h>
  7. #include <asm/csr.h>
  8. #include <uapi/linux/time.h>
  9. /*
  10. * 32-bit land is lacking generic time vsyscalls as well as the legacy 32-bit
  11. * time syscalls like gettimeofday. Skip these definitions since on 32-bit.
  12. */
  13. #ifdef CONFIG_GENERIC_TIME_VSYSCALL
  14. #define VDSO_HAS_CLOCK_GETRES 1
  15. static __always_inline
  16. int gettimeofday_fallback(struct __kernel_old_timeval *_tv,
  17. struct timezone *_tz)
  18. {
  19. register struct __kernel_old_timeval *tv asm("a0") = _tv;
  20. register struct timezone *tz asm("a1") = _tz;
  21. register long ret asm("a0");
  22. register long nr asm("a7") = __NR_gettimeofday;
  23. asm volatile ("ecall\n"
  24. : "=r" (ret)
  25. : "r"(tv), "r"(tz), "r"(nr)
  26. : "memory");
  27. return ret;
  28. }
  29. static __always_inline
  30. long clock_gettime_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
  31. {
  32. register clockid_t clkid asm("a0") = _clkid;
  33. register struct __kernel_timespec *ts asm("a1") = _ts;
  34. register long ret asm("a0");
  35. register long nr asm("a7") = __NR_clock_gettime;
  36. asm volatile ("ecall\n"
  37. : "=r" (ret)
  38. : "r"(clkid), "r"(ts), "r"(nr)
  39. : "memory");
  40. return ret;
  41. }
  42. static __always_inline
  43. int clock_getres_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
  44. {
  45. register clockid_t clkid asm("a0") = _clkid;
  46. register struct __kernel_timespec *ts asm("a1") = _ts;
  47. register long ret asm("a0");
  48. register long nr asm("a7") = __NR_clock_getres;
  49. asm volatile ("ecall\n"
  50. : "=r" (ret)
  51. : "r"(clkid), "r"(ts), "r"(nr)
  52. : "memory");
  53. return ret;
  54. }
  55. #endif /* CONFIG_GENERIC_TIME_VSYSCALL */
  56. static __always_inline u64 __arch_get_hw_counter(s32 clock_mode,
  57. const struct vdso_data *vd)
  58. {
  59. /*
  60. * The purpose of csr_read(CSR_TIME) is to trap the system into
  61. * M-mode to obtain the value of CSR_TIME. Hence, unlike other
  62. * architecture, no fence instructions surround the csr_read()
  63. */
  64. return csr_read(CSR_TIME);
  65. }
  66. static __always_inline const struct vdso_data *__arch_get_vdso_data(void)
  67. {
  68. return _vdso_data;
  69. }
  70. #ifdef CONFIG_TIME_NS
  71. static __always_inline
  72. const struct vdso_data *__arch_get_timens_vdso_data(const struct vdso_data *vd)
  73. {
  74. return _timens_data;
  75. }
  76. #endif
  77. #endif /* !__ASSEMBLY__ */
  78. #endif /* __ASM_VDSO_GETTIMEOFDAY_H */