gettimeofday.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2018 ARM Limited
  4. */
  5. #ifndef __ASM_VDSO_GETTIMEOFDAY_H
  6. #define __ASM_VDSO_GETTIMEOFDAY_H
  7. #ifndef __ASSEMBLY__
  8. #include <asm/alternative.h>
  9. #include <asm/barrier.h>
  10. #include <asm/unistd.h>
  11. #include <asm/sysreg.h>
  12. #define VDSO_HAS_CLOCK_GETRES 1
  13. static __always_inline
  14. int gettimeofday_fallback(struct __kernel_old_timeval *_tv,
  15. struct timezone *_tz)
  16. {
  17. register struct timezone *tz asm("x1") = _tz;
  18. register struct __kernel_old_timeval *tv asm("x0") = _tv;
  19. register long ret asm ("x0");
  20. register long nr asm("x8") = __NR_gettimeofday;
  21. asm volatile(
  22. " svc #0\n"
  23. : "=r" (ret)
  24. : "r" (tv), "r" (tz), "r" (nr)
  25. : "memory");
  26. return ret;
  27. }
  28. static __always_inline
  29. long clock_gettime_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
  30. {
  31. register struct __kernel_timespec *ts asm("x1") = _ts;
  32. register clockid_t clkid asm("x0") = _clkid;
  33. register long ret asm ("x0");
  34. register long nr asm("x8") = __NR_clock_gettime;
  35. asm volatile(
  36. " svc #0\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 struct __kernel_timespec *ts asm("x1") = _ts;
  46. register clockid_t clkid asm("x0") = _clkid;
  47. register long ret asm ("x0");
  48. register long nr asm("x8") = __NR_clock_getres;
  49. asm volatile(
  50. " svc #0\n"
  51. : "=r" (ret)
  52. : "r" (clkid), "r" (ts), "r" (nr)
  53. : "memory");
  54. return ret;
  55. }
  56. static __always_inline u64 __arch_get_hw_counter(s32 clock_mode,
  57. const struct vdso_data *vd)
  58. {
  59. u64 res;
  60. /*
  61. * Core checks for mode already, so this raced against a concurrent
  62. * update. Return something. Core will do another round and then
  63. * see the mode change and fallback to the syscall.
  64. */
  65. if (clock_mode == VDSO_CLOCKMODE_NONE)
  66. return 0;
  67. /*
  68. * If FEAT_ECV is available, use the self-synchronizing counter.
  69. * Otherwise the isb is required to prevent that the counter value
  70. * is speculated.
  71. */
  72. asm volatile(
  73. ALTERNATIVE("isb\n"
  74. "mrs %0, cntvct_el0",
  75. "nop\n"
  76. __mrs_s("%0", SYS_CNTVCTSS_EL0),
  77. ARM64_HAS_ECV)
  78. : "=r" (res)
  79. :
  80. : "memory");
  81. arch_counter_enforce_ordering(res);
  82. return res;
  83. }
  84. static __always_inline
  85. const struct vdso_data *__arch_get_vdso_data(void)
  86. {
  87. return _vdso_data;
  88. }
  89. #ifdef CONFIG_TIME_NS
  90. static __always_inline
  91. const struct vdso_data *__arch_get_timens_vdso_data(const struct vdso_data *vd)
  92. {
  93. return _timens_data;
  94. }
  95. #endif
  96. #endif /* !__ASSEMBLY__ */
  97. #endif /* __ASM_VDSO_GETTIMEOFDAY_H */