numachip.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. *
  3. * Copyright (C) 2015 Numascale AS. All rights reserved.
  4. *
  5. * This software is licensed under the terms of the GNU General Public
  6. * License version 2, as published by the Free Software Foundation, and
  7. * may be copied, distributed, and modified under those terms.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. */
  15. #include <linux/clockchips.h>
  16. #include <asm/irq.h>
  17. #include <asm/numachip/numachip.h>
  18. #include <asm/numachip/numachip_csr.h>
  19. static DEFINE_PER_CPU(struct clock_event_device, numachip2_ced);
  20. static cycles_t numachip2_timer_read(struct clocksource *cs)
  21. {
  22. return numachip2_read64_lcsr(NUMACHIP2_TIMER_NOW);
  23. }
  24. static struct clocksource numachip2_clocksource = {
  25. .name = "numachip2",
  26. .rating = 295,
  27. .read = numachip2_timer_read,
  28. .mask = CLOCKSOURCE_MASK(64),
  29. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  30. .mult = 1,
  31. .shift = 0,
  32. };
  33. static int numachip2_set_next_event(unsigned long delta, struct clock_event_device *ced)
  34. {
  35. numachip2_write64_lcsr(NUMACHIP2_TIMER_DEADLINE + numachip2_timer(),
  36. delta);
  37. return 0;
  38. }
  39. static const struct clock_event_device numachip2_clockevent __initconst = {
  40. .name = "numachip2",
  41. .rating = 400,
  42. .set_next_event = numachip2_set_next_event,
  43. .features = CLOCK_EVT_FEAT_ONESHOT,
  44. .mult = 1,
  45. .shift = 0,
  46. .min_delta_ns = 1250,
  47. .min_delta_ticks = 1250,
  48. .max_delta_ns = LONG_MAX,
  49. .max_delta_ticks = LONG_MAX,
  50. };
  51. static void numachip_timer_interrupt(void)
  52. {
  53. struct clock_event_device *ced = this_cpu_ptr(&numachip2_ced);
  54. ced->event_handler(ced);
  55. }
  56. static __init void numachip_timer_each(struct work_struct *work)
  57. {
  58. unsigned local_apicid = __this_cpu_read(x86_cpu_to_apicid) & 0xff;
  59. struct clock_event_device *ced = this_cpu_ptr(&numachip2_ced);
  60. /* Setup IPI vector to local core and relative timing mode */
  61. numachip2_write64_lcsr(NUMACHIP2_TIMER_INT + numachip2_timer(),
  62. (3 << 22) | (X86_PLATFORM_IPI_VECTOR << 14) |
  63. (local_apicid << 6));
  64. *ced = numachip2_clockevent;
  65. ced->cpumask = cpumask_of(smp_processor_id());
  66. clockevents_register_device(ced);
  67. }
  68. static int __init numachip_timer_init(void)
  69. {
  70. if (numachip_system != 2)
  71. return -ENODEV;
  72. /* Reset timer */
  73. numachip2_write64_lcsr(NUMACHIP2_TIMER_RESET, 0);
  74. clocksource_register_hz(&numachip2_clocksource, NSEC_PER_SEC);
  75. /* Setup per-cpu clockevents */
  76. x86_platform_ipi_callback = numachip_timer_interrupt;
  77. schedule_on_each_cpu(&numachip_timer_each);
  78. return 0;
  79. }
  80. arch_initcall(numachip_timer_init);