Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * linux/arch/arm/kernel/time.c |
| 4 | * |
| 5 | * Copyright (C) 1991, 1992, 1995 Linus Torvalds |
| 6 | * Modifications for ARM (C) 1994-2001 Russell King |
| 7 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * This file contains the ARM-specific time handling details: |
| 9 | * reading the RTC at bootup, etc... |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
Sebastian Hesselbarth | 4178bac | 2013-09-04 12:24:03 +0200 | [diff] [blame] | 11 | #include <linux/clk-provider.h> |
Arnd Bergmann | f414f13 | 2013-03-25 11:14:57 -0500 | [diff] [blame] | 12 | #include <linux/clocksource.h> |
Sebastian Hesselbarth | 4178bac | 2013-09-04 12:24:03 +0200 | [diff] [blame] | 13 | #include <linux/errno.h> |
| 14 | #include <linux/export.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/interrupt.h> |
Frederik Deweerdt | e317c8c | 2006-10-06 18:58:24 +0000 | [diff] [blame] | 17 | #include <linux/irq.h> |
Sebastian Hesselbarth | 4178bac | 2013-09-04 12:24:03 +0200 | [diff] [blame] | 18 | #include <linux/kernel.h> |
| 19 | #include <linux/profile.h> |
| 20 | #include <linux/sched.h> |
Stephen Boyd | 38ff87f | 2013-06-01 23:39:40 -0700 | [diff] [blame] | 21 | #include <linux/sched_clock.h> |
Sebastian Hesselbarth | 4178bac | 2013-09-04 12:24:03 +0200 | [diff] [blame] | 22 | #include <linux/smp.h> |
| 23 | #include <linux/time.h> |
| 24 | #include <linux/timex.h> |
| 25 | #include <linux/timer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Russell King | 8ff1443 | 2010-12-20 10:18:36 +0000 | [diff] [blame] | 27 | #include <asm/mach/arch.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <asm/mach/time.h> |
Sebastian Hesselbarth | 4178bac | 2013-09-04 12:24:03 +0200 | [diff] [blame] | 29 | #include <asm/stacktrace.h> |
| 30 | #include <asm/thread_info.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Arnd Bergmann | 63216d3 | 2011-06-10 13:58:30 +0000 | [diff] [blame] | 32 | #if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE) || \ |
| 33 | defined(CONFIG_NVRAM) || defined(CONFIG_NVRAM_MODULE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | /* this needs a better home */ |
| 35 | DEFINE_SPINLOCK(rtc_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | EXPORT_SYMBOL(rtc_lock); |
David Brownell | 9dd3494 | 2007-01-17 22:11:27 +0100 | [diff] [blame] | 37 | #endif /* pc-style 'CMOS' RTC support */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | /* change this if you have some constant time drift */ |
| 40 | #define USECS_PER_JIFFY (1000000/HZ) |
| 41 | |
| 42 | #ifdef CONFIG_SMP |
| 43 | unsigned long profile_pc(struct pt_regs *regs) |
| 44 | { |
Catalin Marinas | 2d7c11b | 2009-02-11 13:07:53 +0100 | [diff] [blame] | 45 | struct stackframe frame; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Catalin Marinas | 2d7c11b | 2009-02-11 13:07:53 +0100 | [diff] [blame] | 47 | if (!in_lock_functions(regs->ARM_pc)) |
| 48 | return regs->ARM_pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Nikolay Borisov | a3250c9 | 2014-06-03 19:48:58 +0100 | [diff] [blame] | 50 | arm_get_current_stackframe(regs, &frame); |
Catalin Marinas | 2d7c11b | 2009-02-11 13:07:53 +0100 | [diff] [blame] | 51 | do { |
| 52 | int ret = unwind_frame(&frame); |
| 53 | if (ret < 0) |
| 54 | return 0; |
| 55 | } while (in_lock_functions(frame.pc)); |
| 56 | |
| 57 | return frame.pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | } |
| 59 | EXPORT_SYMBOL(profile_pc); |
| 60 | #endif |
| 61 | |
Kevin Hilman | 9e4559d | 2007-03-14 17:33:24 +0100 | [diff] [blame] | 62 | #ifndef CONFIG_GENERIC_CLOCKEVENTS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | /* |
| 64 | * Kernel system timer support. |
| 65 | */ |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 66 | void timer_tick(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { |
Frederik Deweerdt | e317c8c | 2006-10-06 18:58:24 +0000 | [diff] [blame] | 68 | profile_tick(CPU_PROFILING); |
Torben Hohn | 6906e33 | 2011-01-27 15:59:21 +0100 | [diff] [blame] | 69 | xtime_update(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | #ifndef CONFIG_SMP |
Russell King | c97d486 | 2006-10-25 13:59:16 +0100 | [diff] [blame] | 71 | update_process_times(user_mode(get_irq_regs())); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #endif |
| 73 | } |
Kevin Hilman | 9e4559d | 2007-03-14 17:33:24 +0100 | [diff] [blame] | 74 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Xunlei Pang | cb85071 | 2015-04-01 20:34:26 -0700 | [diff] [blame] | 76 | static void dummy_clock_access(struct timespec64 *ts) |
Marc Zyngier | bd0493e | 2012-05-05 19:28:44 +0100 | [diff] [blame] | 77 | { |
| 78 | ts->tv_sec = 0; |
| 79 | ts->tv_nsec = 0; |
| 80 | } |
| 81 | |
| 82 | static clock_access_fn __read_persistent_clock = dummy_clock_access; |
Marc Zyngier | bd0493e | 2012-05-05 19:28:44 +0100 | [diff] [blame] | 83 | |
Xunlei Pang | cb85071 | 2015-04-01 20:34:26 -0700 | [diff] [blame] | 84 | void read_persistent_clock64(struct timespec64 *ts) |
Marc Zyngier | bd0493e | 2012-05-05 19:28:44 +0100 | [diff] [blame] | 85 | { |
| 86 | __read_persistent_clock(ts); |
| 87 | } |
| 88 | |
Pavel Tatashin | 227e395 | 2018-07-19 16:55:37 -0400 | [diff] [blame] | 89 | int __init register_persistent_clock(clock_access_fn read_persistent) |
Marc Zyngier | bd0493e | 2012-05-05 19:28:44 +0100 | [diff] [blame] | 90 | { |
| 91 | /* Only allow the clockaccess functions to be registered once */ |
Pavel Tatashin | 227e395 | 2018-07-19 16:55:37 -0400 | [diff] [blame] | 92 | if (__read_persistent_clock == dummy_clock_access) { |
Marc Zyngier | bd0493e | 2012-05-05 19:28:44 +0100 | [diff] [blame] | 93 | if (read_persistent) |
| 94 | __read_persistent_clock = read_persistent; |
Marc Zyngier | bd0493e | 2012-05-05 19:28:44 +0100 | [diff] [blame] | 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | return -EINVAL; |
| 99 | } |
| 100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | void __init time_init(void) |
| 102 | { |
Sebastian Hesselbarth | 4178bac | 2013-09-04 12:24:03 +0200 | [diff] [blame] | 103 | if (machine_desc->init_time) { |
Arnd Bergmann | f414f13 | 2013-03-25 11:14:57 -0500 | [diff] [blame] | 104 | machine_desc->init_time(); |
Sebastian Hesselbarth | 4178bac | 2013-09-04 12:24:03 +0200 | [diff] [blame] | 105 | } else { |
| 106 | #ifdef CONFIG_COMMON_CLK |
| 107 | of_clk_init(NULL); |
| 108 | #endif |
Daniel Lezcano | ba5d08c | 2017-05-26 17:40:46 +0200 | [diff] [blame] | 109 | timer_probe(); |
Sebastian Hesselbarth | 4178bac | 2013-09-04 12:24:03 +0200 | [diff] [blame] | 110 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |