xref: /linux/arch/arm64/kernel/time.c (revision 945409a6ef442cfe5f2f14e5626d4306d53100f0)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Based on arch/arm/kernel/time.c
4  *
5  * Copyright (C) 1991, 1992, 1995  Linus Torvalds
6  * Modifications for ARM (C) 1994-2001 Russell King
7  * Copyright (C) 2012 ARM Ltd.
8  */
9 
10 #include <linux/clockchips.h>
11 #include <linux/export.h>
12 #include <linux/kernel.h>
13 #include <linux/interrupt.h>
14 #include <linux/time.h>
15 #include <linux/init.h>
16 #include <linux/sched.h>
17 #include <linux/smp.h>
18 #include <linux/timex.h>
19 #include <linux/errno.h>
20 #include <linux/profile.h>
21 #include <linux/stacktrace.h>
22 #include <linux/syscore_ops.h>
23 #include <linux/timer.h>
24 #include <linux/irq.h>
25 #include <linux/delay.h>
26 #include <linux/clocksource.h>
27 #include <linux/of_clk.h>
28 #include <linux/acpi.h>
29 
30 #include <clocksource/arm_arch_timer.h>
31 
32 #include <asm/thread_info.h>
33 #include <asm/paravirt.h>
34 
35 static bool profile_pc_cb(void *arg, unsigned long pc)
36 {
37 	unsigned long *prof_pc = arg;
38 
39 	if (in_lock_functions(pc))
40 		return true;
41 	*prof_pc = pc;
42 	return false;
43 }
44 
45 unsigned long profile_pc(struct pt_regs *regs)
46 {
47 	unsigned long prof_pc = 0;
48 
49 	arch_stack_walk(profile_pc_cb, &prof_pc, current, regs);
50 
51 	return prof_pc;
52 }
53 EXPORT_SYMBOL(profile_pc);
54 
55 void __init time_init(void)
56 {
57 	u32 arch_timer_rate;
58 
59 	of_clk_init(NULL);
60 	timer_probe();
61 
62 	tick_setup_hrtimer_broadcast();
63 
64 	arch_timer_rate = arch_timer_get_rate();
65 	if (!arch_timer_rate)
66 		panic("Unable to initialise architected timer.\n");
67 
68 	/* Calibrate the delay loop directly */
69 	lpj_fine = arch_timer_rate / HZ;
70 
71 	pv_time_init();
72 }
73