gettimeofday.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #define VDSO_HAS_CLOCK_GETRES 1
  10. static __always_inline
  11. int gettimeofday_fallback(struct __kernel_old_timeval *_tv,
  12. struct timezone *_tz)
  13. {
  14. register struct __kernel_old_timeval *tv asm("a0") = _tv;
  15. register struct timezone *tz asm("a1") = _tz;
  16. register long ret asm("a0");
  17. register long nr asm("a7") = __NR_gettimeofday;
  18. asm volatile ("ecall\n"
  19. : "=r" (ret)
  20. : "r"(tv), "r"(tz), "r"(nr)
  21. : "memory");
  22. return ret;
  23. }
  24. static __always_inline
  25. long clock_gettime_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
  26. {
  27. register clockid_t clkid asm("a0") = _clkid;
  28. register struct __kernel_timespec *ts asm("a1") = _ts;
  29. register long ret asm("a0");
  30. register long nr asm("a7") = __NR_clock_gettime;
  31. asm volatile ("ecall\n"
  32. : "=r" (ret)
  33. : "r"(clkid), "r"(ts), "r"(nr)
  34. : "memory");
  35. return ret;
  36. }
  37. static __always_inline
  38. int clock_getres_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
  39. {
  40. register clockid_t clkid asm("a0") = _clkid;
  41. register struct __kernel_timespec *ts asm("a1") = _ts;
  42. register long ret asm("a0");
  43. register long nr asm("a7") = __NR_clock_getres;
  44. asm volatile ("ecall\n"
  45. : "=r" (ret)
  46. : "r"(clkid), "r"(ts), "r"(nr)
  47. : "memory");
  48. return ret;
  49. }
  50. static __always_inline u64 __arch_get_hw_counter(s32 clock_mode,
  51. const struct vdso_data *vd)
  52. {
  53. /*
  54. * The purpose of csr_read(CSR_TIME) is to trap the system into
  55. * M-mode to obtain the value of CSR_TIME. Hence, unlike other
  56. * architecture, no fence instructions surround the csr_read()
  57. */
  58. return csr_read(CSR_TIME);
  59. }
  60. static __always_inline const struct vdso_data *__arch_get_vdso_data(void)
  61. {
  62. return _vdso_data;
  63. }
  64. #endif /* !__ASSEMBLY__ */
  65. #endif /* __ASM_VDSO_GETTIMEOFDAY_H */