Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/numachip: Introduce Numachip2 timer mechanisms

Add 1GHz 64-bit Numachip2 clocksource timer support for accurate
system-wide timekeeping, as core TSCs are unsynchronised.

Additionally, add a per-core clockevent mechanism that interrupts via the
platform IPI vector after a programmed period.

[ tglx: Taking it through x86 due to dependencies ]

Signed-off-by: Daniel J Blueman <daniel@numascale.com>
Acked-by: Steffen Persvold <sp@numascale.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: http://lkml.kernel.org/r/1442829745-29311-1-git-send-email-daniel@numascale.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

authored by

Daniel J Blueman and committed by
Thomas Gleixner
ce2e572c ad03a9c2

+105
+9
arch/x86/include/asm/numachip/numachip_csr.h
··· 59 59 #define NUMACHIP2_LCSR_BASE 0xf0000000UL 60 60 #define NUMACHIP2_LCSR_SIZE 0x1000000UL 61 61 #define NUMACHIP2_APIC_ICR 0x100000 62 + #define NUMACHIP2_TIMER_DEADLINE 0x200000 63 + #define NUMACHIP2_TIMER_INT 0x200008 64 + #define NUMACHIP2_TIMER_NOW 0x200018 65 + #define NUMACHIP2_TIMER_RESET 0x200020 62 66 63 67 static inline void __iomem *numachip2_lcsr_address(unsigned long offset) 64 68 { ··· 88 84 static inline void numachip2_write64_lcsr(unsigned long offset, u64 val) 89 85 { 90 86 writeq(val, numachip2_lcsr_address(offset)); 87 + } 88 + 89 + static inline unsigned int numachip2_timer(void) 90 + { 91 + return (smp_processor_id() % 48) << 6; 91 92 } 92 93 93 94 #endif /* _ASM_X86_NUMACHIP_NUMACHIP_CSR_H */
+1
drivers/clocksource/Makefile
··· 62 62 obj-$(CONFIG_H8300_TMR16) += h8300_timer16.o 63 63 obj-$(CONFIG_H8300_TPU) += h8300_tpu.o 64 64 obj-$(CONFIG_CLKSRC_ST_LPC) += clksrc_st_lpc.o 65 + obj-$(CONFIG_X86_NUMACHIP) += numachip.o
+95
drivers/clocksource/numachip.c
··· 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 + 16 + #include <linux/clockchips.h> 17 + 18 + #include <asm/irq.h> 19 + #include <asm/numachip/numachip.h> 20 + #include <asm/numachip/numachip_csr.h> 21 + 22 + static DEFINE_PER_CPU(struct clock_event_device, cpu_ced); 23 + 24 + static cycles_t numachip2_timer_read(struct clocksource *cs) 25 + { 26 + return numachip2_read64_lcsr(NUMACHIP2_TIMER_NOW); 27 + } 28 + 29 + static struct clocksource numachip2_clocksource = { 30 + .name = "numachip2", 31 + .rating = 295, 32 + .read = numachip2_timer_read, 33 + .mask = CLOCKSOURCE_MASK(64), 34 + .flags = CLOCK_SOURCE_IS_CONTINUOUS, 35 + .mult = 1, 36 + .shift = 0, 37 + }; 38 + 39 + static int numachip2_set_next_event(unsigned long delta, struct clock_event_device *ced) 40 + { 41 + numachip2_write64_lcsr(NUMACHIP2_TIMER_DEADLINE + numachip2_timer(), 42 + delta); 43 + return 0; 44 + } 45 + 46 + static struct clock_event_device numachip2_clockevent = { 47 + .name = "numachip2", 48 + .rating = 400, 49 + .set_next_event = numachip2_set_next_event, 50 + .features = CLOCK_EVT_FEAT_ONESHOT, 51 + .mult = 1, 52 + .shift = 0, 53 + .min_delta_ns = 1250, 54 + .max_delta_ns = LONG_MAX, 55 + }; 56 + 57 + static void numachip_timer_interrupt(void) 58 + { 59 + struct clock_event_device *ced = this_cpu_ptr(&cpu_ced); 60 + 61 + ced->event_handler(ced); 62 + } 63 + 64 + static __init void numachip_timer_each(struct work_struct *work) 65 + { 66 + unsigned local_apicid = __this_cpu_read(x86_cpu_to_apicid) & 0xff; 67 + struct clock_event_device *ced = this_cpu_ptr(&cpu_ced); 68 + 69 + /* Setup IPI vector to local core and relative timing mode */ 70 + numachip2_write64_lcsr(NUMACHIP2_TIMER_INT + numachip2_timer(), 71 + (3 << 22) | (X86_PLATFORM_IPI_VECTOR << 14) | 72 + (local_apicid << 6)); 73 + 74 + *ced = numachip2_clockevent; 75 + ced->cpumask = cpumask_of(smp_processor_id()); 76 + clockevents_register_device(ced); 77 + } 78 + 79 + static int __init numachip_timer_init(void) 80 + { 81 + if (numachip_system != 2) 82 + return -ENODEV; 83 + 84 + /* Reset timer */ 85 + numachip2_write64_lcsr(NUMACHIP2_TIMER_RESET, 0); 86 + clocksource_register_hz(&numachip2_clocksource, NSEC_PER_SEC); 87 + 88 + /* Setup per-cpu clockevents */ 89 + x86_platform_ipi_callback = numachip_timer_interrupt; 90 + schedule_on_each_cpu(&numachip_timer_each); 91 + 92 + return 0; 93 + } 94 + 95 + arch_initcall(numachip_timer_init);