David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 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. |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 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/syscore_ops.h> |
| 22 | #include <linux/timer.h> |
| 23 | #include <linux/irq.h> |
| 24 | #include <linux/delay.h> |
| 25 | #include <linux/clocksource.h> |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 26 | #include <linux/of_clk.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 27 | #include <linux/acpi.h> |
| 28 | |
| 29 | #include <clocksource/arm_arch_timer.h> |
| 30 | |
| 31 | #include <asm/thread_info.h> |
| 32 | #include <asm/stacktrace.h> |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 33 | #include <asm/paravirt.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 34 | |
| 35 | unsigned long profile_pc(struct pt_regs *regs) |
| 36 | { |
| 37 | struct stackframe frame; |
| 38 | |
| 39 | if (!in_lock_functions(regs->pc)) |
| 40 | return regs->pc; |
| 41 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 42 | start_backtrace(&frame, regs->regs[29], regs->pc); |
| 43 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 44 | do { |
| 45 | int ret = unwind_frame(NULL, &frame); |
| 46 | if (ret < 0) |
| 47 | return 0; |
| 48 | } while (in_lock_functions(frame.pc)); |
| 49 | |
| 50 | return frame.pc; |
| 51 | } |
| 52 | EXPORT_SYMBOL(profile_pc); |
| 53 | |
| 54 | void __init time_init(void) |
| 55 | { |
| 56 | u32 arch_timer_rate; |
| 57 | |
| 58 | of_clk_init(NULL); |
| 59 | timer_probe(); |
| 60 | |
| 61 | tick_setup_hrtimer_broadcast(); |
| 62 | |
| 63 | arch_timer_rate = arch_timer_get_rate(); |
| 64 | if (!arch_timer_rate) |
| 65 | panic("Unable to initialise architected timer.\n"); |
| 66 | |
| 67 | /* Calibrate the delay loop directly */ |
| 68 | lpj_fine = arch_timer_rate / HZ; |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 69 | |
| 70 | pv_time_init(); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 71 | } |