time.c 2.6 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 *  linux/arch/arm/kernel/time.c
 *
 *  Copyright (C) 1991, 1992, 1995  Linus Torvalds
 *  Modifications for ARM (C) 1994-2001 Russell King
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 *  This file contains the ARM-specific time handling details:
 *  reading the RTC at bootup, etc...
 */
14 15 16
#include <linux/clk-provider.h>
#include <linux/clocksource.h>
#include <linux/errno.h>
17
#include <linux/export.h>
L
Linus Torvalds 已提交
18
#include <linux/init.h>
19 20 21 22
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/kernel.h>
#include <linux/profile.h>
23
#include <linux/sched.h>
24
#include <linux/sched_clock.h>
L
Linus Torvalds 已提交
25
#include <linux/smp.h>
26
#include <linux/time.h>
L
Linus Torvalds 已提交
27 28 29
#include <linux/timex.h>
#include <linux/timer.h>

30
#include <asm/mach/arch.h>
L
Linus Torvalds 已提交
31
#include <asm/mach/time.h>
32 33
#include <asm/stacktrace.h>
#include <asm/thread_info.h>
L
Linus Torvalds 已提交
34

35 36
#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE) || \
    defined(CONFIG_NVRAM) || defined(CONFIG_NVRAM_MODULE)
L
Linus Torvalds 已提交
37 38 39
/* this needs a better home */
DEFINE_SPINLOCK(rtc_lock);
EXPORT_SYMBOL(rtc_lock);
40
#endif	/* pc-style 'CMOS' RTC support */
L
Linus Torvalds 已提交
41 42 43 44 45 46 47

/* change this if you have some constant time drift */
#define USECS_PER_JIFFY	(1000000/HZ)

#ifdef CONFIG_SMP
unsigned long profile_pc(struct pt_regs *regs)
{
48
	struct stackframe frame;
L
Linus Torvalds 已提交
49

50 51
	if (!in_lock_functions(regs->ARM_pc))
		return regs->ARM_pc;
L
Linus Torvalds 已提交
52

53
	arm_get_current_stackframe(regs, &frame);
54 55 56 57 58 59 60
	do {
		int ret = unwind_frame(&frame);
		if (ret < 0)
			return 0;
	} while (in_lock_functions(frame.pc));

	return frame.pc;
L
Linus Torvalds 已提交
61 62 63 64
}
EXPORT_SYMBOL(profile_pc);
#endif

65
#ifndef CONFIG_GENERIC_CLOCKEVENTS
L
Linus Torvalds 已提交
66 67 68
/*
 * Kernel system timer support.
 */
69
void timer_tick(void)
L
Linus Torvalds 已提交
70
{
71
	profile_tick(CPU_PROFILING);
72
	xtime_update(1);
L
Linus Torvalds 已提交
73
#ifndef CONFIG_SMP
R
Russell King 已提交
74
	update_process_times(user_mode(get_irq_regs()));
L
Linus Torvalds 已提交
75 76
#endif
}
77
#endif
L
Linus Torvalds 已提交
78

79
static void dummy_clock_access(struct timespec64 *ts)
80 81 82 83 84 85 86
{
	ts->tv_sec = 0;
	ts->tv_nsec = 0;
}

static clock_access_fn __read_persistent_clock = dummy_clock_access;

87
void read_persistent_clock64(struct timespec64 *ts)
88 89 90 91
{
	__read_persistent_clock(ts);
}

92
int __init register_persistent_clock(clock_access_fn read_persistent)
93 94
{
	/* Only allow the clockaccess functions to be registered once */
95
	if (__read_persistent_clock == dummy_clock_access) {
96 97 98 99 100 101 102 103
		if (read_persistent)
			__read_persistent_clock = read_persistent;
		return 0;
	}

	return -EINVAL;
}

L
Linus Torvalds 已提交
104 105
void __init time_init(void)
{
106
	if (machine_desc->init_time) {
107
		machine_desc->init_time();
108 109 110 111
	} else {
#ifdef CONFIG_COMMON_CLK
		of_clk_init(NULL);
#endif
112
		timer_probe();
113
	}
L
Linus Torvalds 已提交
114
}