blob: 5d9076e862005006649c82a9f577c668e5508553 [file] [log] [blame]
Marc Zyngier985c0672012-03-05 11:49:30 +00001/*
2 * Based on arch/arm/kernel/time.c
3 *
4 * Copyright (C) 1991, 1992, 1995 Linus Torvalds
5 * Modifications for ARM (C) 1994-2001 Russell King
6 * Copyright (C) 2012 ARM Ltd.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
Lorenzo Pieralisi9358d752014-05-29 18:16:54 +010021#include <linux/clockchips.h>
Marc Zyngier985c0672012-03-05 11:49:30 +000022#include <linux/export.h>
23#include <linux/kernel.h>
24#include <linux/interrupt.h>
25#include <linux/time.h>
26#include <linux/init.h>
27#include <linux/sched.h>
28#include <linux/smp.h>
29#include <linux/timex.h>
30#include <linux/errno.h>
31#include <linux/profile.h>
32#include <linux/syscore_ops.h>
33#include <linux/timer.h>
34#include <linux/irq.h>
Mark Rutland1aee5d72012-11-20 10:06:00 +000035#include <linux/delay.h>
Rob Herring0583fe42013-04-10 18:27:51 -050036#include <linux/clocksource.h>
Chanho Minbc3ee182014-04-14 08:38:53 +010037#include <linux/clk-provider.h>
Hanjun Guob09ca1e2015-03-24 14:02:50 +000038#include <linux/acpi.h>
Marc Zyngier985c0672012-03-05 11:49:30 +000039
Mark Rutland1aee5d72012-11-20 10:06:00 +000040#include <clocksource/arm_arch_timer.h>
Marc Zyngier985c0672012-03-05 11:49:30 +000041
42#include <asm/thread_info.h>
43#include <asm/stacktrace.h>
44
Marc Zyngier985c0672012-03-05 11:49:30 +000045unsigned long profile_pc(struct pt_regs *regs)
46{
47 struct stackframe frame;
48
49 if (!in_lock_functions(regs->pc))
50 return regs->pc;
51
52 frame.fp = regs->regs[29];
53 frame.sp = regs->sp;
54 frame.pc = regs->pc;
AKASHI Takahiro20380bb2015-12-15 17:33:41 +090055#ifdef CONFIG_FUNCTION_GRAPH_TRACER
Pratyush Anandc3655e72018-02-05 14:28:01 +010056 frame.graph = current->curr_ret_stack;
AKASHI Takahiro20380bb2015-12-15 17:33:41 +090057#endif
Marc Zyngier985c0672012-03-05 11:49:30 +000058 do {
AKASHI Takahirofe13f952015-12-15 17:33:40 +090059 int ret = unwind_frame(NULL, &frame);
Marc Zyngier985c0672012-03-05 11:49:30 +000060 if (ret < 0)
61 return 0;
62 } while (in_lock_functions(frame.pc));
63
64 return frame.pc;
65}
66EXPORT_SYMBOL(profile_pc);
Marc Zyngier985c0672012-03-05 11:49:30 +000067
68void __init time_init(void)
69{
Mark Rutland1aee5d72012-11-20 10:06:00 +000070 u32 arch_timer_rate;
71
Chanho Minbc3ee182014-04-14 08:38:53 +010072 of_clk_init(NULL);
Marc Zyngier3722ed22015-09-28 15:49:18 +010073 clocksource_probe();
Mark Rutland1aee5d72012-11-20 10:06:00 +000074
Lorenzo Pieralisi9358d752014-05-29 18:16:54 +010075 tick_setup_hrtimer_broadcast();
76
Mark Rutland1aee5d72012-11-20 10:06:00 +000077 arch_timer_rate = arch_timer_get_rate();
Rob Herring0583fe42013-04-10 18:27:51 -050078 if (!arch_timer_rate)
79 panic("Unable to initialise architected timer.\n");
Mark Rutland1aee5d72012-11-20 10:06:00 +000080
Mark Rutland1aee5d72012-11-20 10:06:00 +000081 /* Calibrate the delay loop directly */
82 lpj_fine = arch_timer_rate / HZ;
Marc Zyngier985c0672012-03-05 11:49:30 +000083}