timer_64.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* timer.h: System timer definitions for sun5.
  3. *
  4. * Copyright (C) 1997, 2008 David S. Miller ([email protected])
  5. */
  6. #ifndef _SPARC64_TIMER_H
  7. #define _SPARC64_TIMER_H
  8. #include <uapi/asm/asi.h>
  9. #include <linux/types.h>
  10. #include <linux/init.h>
  11. /* The most frequently accessed fields should be first,
  12. * to fit into the same cacheline.
  13. */
  14. struct sparc64_tick_ops {
  15. unsigned long ticks_per_nsec_quotient;
  16. unsigned long offset;
  17. unsigned long long (*get_tick)(void);
  18. int (*add_compare)(unsigned long);
  19. unsigned long softint_mask;
  20. void (*disable_irq)(void);
  21. void (*init_tick)(void);
  22. unsigned long (*add_tick)(unsigned long);
  23. unsigned long (*get_frequency)(void);
  24. unsigned long frequency;
  25. char *name;
  26. };
  27. extern struct sparc64_tick_ops *tick_ops;
  28. unsigned long sparc64_get_clock_tick(unsigned int cpu);
  29. void setup_sparc64_timer(void);
  30. void __init time_init(void);
  31. #define TICK_PRIV_BIT BIT(63)
  32. #define TICKCMP_IRQ_BIT BIT(63)
  33. #define HBIRD_STICKCMP_ADDR 0x1fe0000f060UL
  34. #define HBIRD_STICK_ADDR 0x1fe0000f070UL
  35. #define GET_TICK_NINSTR 13
  36. struct get_tick_patch {
  37. unsigned int addr;
  38. unsigned int tick[GET_TICK_NINSTR];
  39. unsigned int stick[GET_TICK_NINSTR];
  40. };
  41. extern struct get_tick_patch __get_tick_patch;
  42. extern struct get_tick_patch __get_tick_patch_end;
  43. static inline unsigned long get_tick(void)
  44. {
  45. unsigned long tick, tmp1, tmp2;
  46. __asm__ __volatile__(
  47. /* read hbtick 13 instructions */
  48. "661:\n"
  49. " mov 0x1fe, %1\n"
  50. " sllx %1, 0x20, %1\n"
  51. " sethi %%hi(0xf000), %2\n"
  52. " or %2, 0x70, %2\n"
  53. " or %1, %2, %1\n" /* %1 = HBIRD_STICK_ADDR */
  54. " add %1, 8, %2\n"
  55. " ldxa [%2]%3, %0\n"
  56. " ldxa [%1]%3, %1\n"
  57. " ldxa [%2]%3, %2\n"
  58. " sub %2, %0, %0\n" /* don't modify %xcc */
  59. " brnz,pn %0, 661b\n" /* restart to save one register */
  60. " sllx %2, 32, %2\n"
  61. " or %2, %1, %0\n"
  62. /* Common/not patched code */
  63. " sllx %0, 1, %0\n"
  64. " srlx %0, 1, %0\n" /* Clear TICK_PRIV_BIT */
  65. /* Beginning of patch section */
  66. " .section .get_tick_patch, \"ax\"\n"
  67. " .word 661b\n"
  68. /* read tick 2 instructions and 11 skipped */
  69. " ba 1f\n"
  70. " rd %%tick, %0\n"
  71. " .skip 4 * (%4 - 2)\n"
  72. "1:\n"
  73. /* read stick 2 instructions and 11 skipped */
  74. " ba 1f\n"
  75. " rd %%asr24, %0\n"
  76. " .skip 4 * (%4 - 2)\n"
  77. "1:\n"
  78. /* End of patch section */
  79. " .previous\n"
  80. : "=&r" (tick), "=&r" (tmp1), "=&r" (tmp2)
  81. : "i" (ASI_PHYS_BYPASS_EC_E), "i" (GET_TICK_NINSTR));
  82. return tick;
  83. }
  84. #endif /* _SPARC64_TIMER_H */