2007-02-16 17:28:00 +08:00
|
|
|
/* linux/include/linux/clockchips.h
|
|
|
|
*
|
|
|
|
* This file contains the structure definitions for clockchips.
|
|
|
|
*
|
|
|
|
* If you are not a clockchip, or the time of day code, you should
|
|
|
|
* not be including this file!
|
|
|
|
*/
|
|
|
|
#ifndef _LINUX_CLOCKCHIPS_H
|
|
|
|
#define _LINUX_CLOCKCHIPS_H
|
|
|
|
|
2013-03-27 18:22:09 +08:00
|
|
|
/* Clock event notification values */
|
|
|
|
enum clock_event_nofitiers {
|
|
|
|
CLOCK_EVT_NOTIFY_ADD,
|
|
|
|
CLOCK_EVT_NOTIFY_BROADCAST_ON,
|
|
|
|
CLOCK_EVT_NOTIFY_BROADCAST_OFF,
|
|
|
|
CLOCK_EVT_NOTIFY_BROADCAST_FORCE,
|
|
|
|
CLOCK_EVT_NOTIFY_BROADCAST_ENTER,
|
|
|
|
CLOCK_EVT_NOTIFY_BROADCAST_EXIT,
|
|
|
|
CLOCK_EVT_NOTIFY_SUSPEND,
|
|
|
|
CLOCK_EVT_NOTIFY_RESUME,
|
|
|
|
CLOCK_EVT_NOTIFY_CPU_DYING,
|
|
|
|
CLOCK_EVT_NOTIFY_CPU_DEAD,
|
|
|
|
};
|
|
|
|
|
2007-10-13 05:04:05 +08:00
|
|
|
#ifdef CONFIG_GENERIC_CLOCKEVENTS_BUILD
|
2007-02-16 17:28:00 +08:00
|
|
|
|
|
|
|
#include <linux/clocksource.h>
|
|
|
|
#include <linux/cpumask.h>
|
|
|
|
#include <linux/ktime.h>
|
|
|
|
#include <linux/notifier.h>
|
|
|
|
|
|
|
|
struct clock_event_device;
|
2013-04-26 04:31:49 +08:00
|
|
|
struct module;
|
2007-02-16 17:28:00 +08:00
|
|
|
|
|
|
|
/* Clock event mode commands */
|
|
|
|
enum clock_event_mode {
|
|
|
|
CLOCK_EVT_MODE_UNUSED = 0,
|
|
|
|
CLOCK_EVT_MODE_SHUTDOWN,
|
|
|
|
CLOCK_EVT_MODE_PERIODIC,
|
|
|
|
CLOCK_EVT_MODE_ONESHOT,
|
2007-07-21 19:37:34 +08:00
|
|
|
CLOCK_EVT_MODE_RESUME,
|
2015-02-13 08:54:56 +08:00
|
|
|
|
|
|
|
/* Legacy ->set_mode() callback doesn't support below modes */
|
2007-02-16 17:28:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clock event features
|
|
|
|
*/
|
|
|
|
#define CLOCK_EVT_FEAT_PERIODIC 0x000001
|
|
|
|
#define CLOCK_EVT_FEAT_ONESHOT 0x000002
|
2011-08-23 21:29:43 +08:00
|
|
|
#define CLOCK_EVT_FEAT_KTIME 0x000004
|
2007-02-16 17:28:00 +08:00
|
|
|
/*
|
|
|
|
* x86(64) specific misfeatures:
|
|
|
|
*
|
|
|
|
* - Clockevent source stops in C3 State and needs broadcast support.
|
|
|
|
* - Local APIC timer is used as a dummy device.
|
|
|
|
*/
|
2011-08-23 21:29:43 +08:00
|
|
|
#define CLOCK_EVT_FEAT_C3STOP 0x000008
|
|
|
|
#define CLOCK_EVT_FEAT_DUMMY 0x000010
|
2007-02-16 17:28:00 +08:00
|
|
|
|
2013-03-02 18:10:11 +08:00
|
|
|
/*
|
|
|
|
* Core shall set the interrupt affinity dynamically in broadcast mode
|
|
|
|
*/
|
|
|
|
#define CLOCK_EVT_FEAT_DYNIRQ 0x000020
|
2013-09-19 02:48:35 +08:00
|
|
|
#define CLOCK_EVT_FEAT_PERCPU 0x000040
|
2013-03-02 18:10:11 +08:00
|
|
|
|
2014-02-07 16:06:32 +08:00
|
|
|
/*
|
|
|
|
* Clockevent device is based on a hrtimer for broadcast
|
|
|
|
*/
|
|
|
|
#define CLOCK_EVT_FEAT_HRTIMER 0x000080
|
|
|
|
|
2007-02-16 17:28:00 +08:00
|
|
|
/**
|
|
|
|
* struct clock_event_device - clock event device descriptor
|
2011-05-19 05:33:41 +08:00
|
|
|
* @event_handler: Assigned by the framework to be called by the low
|
|
|
|
* level handler of the event source
|
2011-08-23 21:29:43 +08:00
|
|
|
* @set_next_event: set next event function using a clocksource delta
|
|
|
|
* @set_next_ktime: set next event function using a direct ktime value
|
2011-05-19 05:33:41 +08:00
|
|
|
* @next_event: local storage for the next event in oneshot mode
|
2007-02-16 17:28:00 +08:00
|
|
|
* @max_delta_ns: maximum delta value in ns
|
|
|
|
* @min_delta_ns: minimum delta value in ns
|
|
|
|
* @mult: nanosecond to cycles multiplier
|
|
|
|
* @shift: nanoseconds to cycles divisor (power of two)
|
2011-05-19 05:33:41 +08:00
|
|
|
* @mode: operating mode assigned by the management code
|
|
|
|
* @features: features
|
|
|
|
* @retries: number of forced programming retries
|
2015-02-13 08:54:56 +08:00
|
|
|
* @set_mode: legacy set mode function, only for modes <= CLOCK_EVT_MODE_RESUME.
|
|
|
|
* @set_mode_periodic: switch mode to periodic, if !set_mode
|
|
|
|
* @set_mode_oneshot: switch mode to oneshot, if !set_mode
|
|
|
|
* @set_mode_shutdown: switch mode to shutdown, if !set_mode
|
2015-02-27 19:51:32 +08:00
|
|
|
* @tick_resume: resume clkevt device, if !set_mode
|
2011-05-19 05:33:41 +08:00
|
|
|
* @broadcast: function to broadcast events
|
2011-05-19 05:33:41 +08:00
|
|
|
* @min_delta_ticks: minimum delta value in ticks stored for reconfiguration
|
|
|
|
* @max_delta_ticks: maximum delta value in ticks stored for reconfiguration
|
2011-05-19 05:33:41 +08:00
|
|
|
* @name: ptr to clock event name
|
2007-02-16 17:28:00 +08:00
|
|
|
* @rating: variable to rate clock event devices
|
2007-05-08 15:31:55 +08:00
|
|
|
* @irq: IRQ number (only for non CPU local devices)
|
2014-02-07 16:06:32 +08:00
|
|
|
* @bound_on: Bound on CPU
|
2007-05-08 15:31:55 +08:00
|
|
|
* @cpumask: cpumask to indicate for which CPUs this device works
|
2007-02-16 17:28:00 +08:00
|
|
|
* @list: list head for the management code
|
2013-04-26 04:31:49 +08:00
|
|
|
* @owner: module reference
|
2007-02-16 17:28:00 +08:00
|
|
|
*/
|
|
|
|
struct clock_event_device {
|
2011-05-19 05:33:41 +08:00
|
|
|
void (*event_handler)(struct clock_event_device *);
|
|
|
|
int (*set_next_event)(unsigned long evt,
|
|
|
|
struct clock_event_device *);
|
2011-08-23 21:29:43 +08:00
|
|
|
int (*set_next_ktime)(ktime_t expires,
|
|
|
|
struct clock_event_device *);
|
2011-05-19 05:33:41 +08:00
|
|
|
ktime_t next_event;
|
2009-08-19 01:45:11 +08:00
|
|
|
u64 max_delta_ns;
|
|
|
|
u64 min_delta_ns;
|
2009-11-11 22:05:25 +08:00
|
|
|
u32 mult;
|
|
|
|
u32 shift;
|
2011-05-19 05:33:41 +08:00
|
|
|
enum clock_event_mode mode;
|
|
|
|
unsigned int features;
|
|
|
|
unsigned long retries;
|
|
|
|
|
2015-02-13 08:54:56 +08:00
|
|
|
/*
|
|
|
|
* Mode transition callback(s): Only one of the two groups should be
|
|
|
|
* defined:
|
|
|
|
* - set_mode(), only for modes <= CLOCK_EVT_MODE_RESUME.
|
|
|
|
* - set_mode_{shutdown|periodic|oneshot|resume}().
|
|
|
|
*/
|
2011-05-19 05:33:41 +08:00
|
|
|
void (*set_mode)(enum clock_event_mode mode,
|
|
|
|
struct clock_event_device *);
|
2015-02-13 08:54:56 +08:00
|
|
|
int (*set_mode_periodic)(struct clock_event_device *);
|
|
|
|
int (*set_mode_oneshot)(struct clock_event_device *);
|
|
|
|
int (*set_mode_shutdown)(struct clock_event_device *);
|
2015-02-27 19:51:32 +08:00
|
|
|
int (*tick_resume)(struct clock_event_device *);
|
2015-02-13 08:54:56 +08:00
|
|
|
|
|
|
|
void (*broadcast)(const struct cpumask *mask);
|
2012-08-06 07:40:41 +08:00
|
|
|
void (*suspend)(struct clock_event_device *);
|
|
|
|
void (*resume)(struct clock_event_device *);
|
2011-05-19 05:33:41 +08:00
|
|
|
unsigned long min_delta_ticks;
|
|
|
|
unsigned long max_delta_ticks;
|
|
|
|
|
2011-05-19 05:33:41 +08:00
|
|
|
const char *name;
|
2007-02-16 17:28:00 +08:00
|
|
|
int rating;
|
|
|
|
int irq;
|
2014-02-07 16:06:32 +08:00
|
|
|
int bound_on;
|
2008-12-13 18:50:26 +08:00
|
|
|
const struct cpumask *cpumask;
|
2007-02-16 17:28:00 +08:00
|
|
|
struct list_head list;
|
2013-04-26 04:31:49 +08:00
|
|
|
struct module *owner;
|
2011-05-19 05:33:41 +08:00
|
|
|
} ____cacheline_aligned;
|
2007-02-16 17:28:00 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate a multiplication factor for scaled math, which is used to convert
|
|
|
|
* nanoseconds based values to clock ticks:
|
|
|
|
*
|
|
|
|
* clock_ticks = (nanoseconds * factor) >> shift.
|
|
|
|
*
|
|
|
|
* div_sc is the rearranged equation to calculate a factor from a given clock
|
|
|
|
* ticks / nanoseconds ratio:
|
|
|
|
*
|
|
|
|
* factor = (clock_ticks << shift) / nanoseconds
|
|
|
|
*/
|
|
|
|
static inline unsigned long div_sc(unsigned long ticks, unsigned long nsec,
|
|
|
|
int shift)
|
|
|
|
{
|
|
|
|
uint64_t tmp = ((uint64_t)ticks) << shift;
|
|
|
|
|
|
|
|
do_div(tmp, nsec);
|
|
|
|
return (unsigned long) tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clock event layer functions */
|
2009-08-19 01:45:11 +08:00
|
|
|
extern u64 clockevent_delta2ns(unsigned long latch,
|
|
|
|
struct clock_event_device *evt);
|
2007-02-16 17:28:00 +08:00
|
|
|
extern void clockevents_register_device(struct clock_event_device *dev);
|
2013-04-26 04:31:50 +08:00
|
|
|
extern int clockevents_unbind_device(struct clock_event_device *ced, int cpu);
|
2007-02-16 17:28:00 +08:00
|
|
|
|
2012-05-09 22:39:34 +08:00
|
|
|
extern void clockevents_config(struct clock_event_device *dev, u32 freq);
|
2011-05-19 05:33:41 +08:00
|
|
|
extern void clockevents_config_and_register(struct clock_event_device *dev,
|
|
|
|
u32 freq, unsigned long min_delta,
|
|
|
|
unsigned long max_delta);
|
|
|
|
|
2011-05-19 05:33:42 +08:00
|
|
|
extern int clockevents_update_freq(struct clock_event_device *ce, u32 freq);
|
|
|
|
|
2007-02-16 17:28:00 +08:00
|
|
|
extern void clockevents_exchange_device(struct clock_event_device *old,
|
|
|
|
struct clock_event_device *new);
|
|
|
|
extern void clockevents_set_mode(struct clock_event_device *dev,
|
|
|
|
enum clock_event_mode mode);
|
|
|
|
extern int clockevents_program_event(struct clock_event_device *dev,
|
2011-08-23 21:29:42 +08:00
|
|
|
ktime_t expires, bool force);
|
2007-02-16 17:28:00 +08:00
|
|
|
|
2008-09-04 05:36:50 +08:00
|
|
|
extern void clockevents_handle_noop(struct clock_event_device *dev);
|
|
|
|
|
2009-11-11 22:05:29 +08:00
|
|
|
static inline void
|
|
|
|
clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 minsec)
|
|
|
|
{
|
|
|
|
return clocks_calc_mult_shift(&ce->mult, &ce->shift, NSEC_PER_SEC,
|
|
|
|
freq, minsec);
|
|
|
|
}
|
|
|
|
|
2012-08-06 07:40:41 +08:00
|
|
|
extern void clockevents_suspend(void);
|
|
|
|
extern void clockevents_resume(void);
|
|
|
|
|
2013-01-15 01:05:21 +08:00
|
|
|
#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
|
2013-01-15 01:05:22 +08:00
|
|
|
#ifdef CONFIG_ARCH_HAS_TICK_BROADCAST
|
|
|
|
extern void tick_broadcast(const struct cpumask *mask);
|
|
|
|
#else
|
|
|
|
#define tick_broadcast NULL
|
|
|
|
#endif
|
2013-01-15 01:05:21 +08:00
|
|
|
extern int tick_receive_broadcast(void);
|
|
|
|
#endif
|
|
|
|
|
2013-03-06 19:18:36 +08:00
|
|
|
#if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
|
2014-02-07 16:06:32 +08:00
|
|
|
extern void tick_setup_hrtimer_broadcast(void);
|
2013-03-06 19:18:36 +08:00
|
|
|
extern int tick_check_broadcast_expired(void);
|
|
|
|
#else
|
|
|
|
static inline int tick_check_broadcast_expired(void) { return 0; }
|
2014-02-07 23:00:46 +08:00
|
|
|
static inline void tick_setup_hrtimer_broadcast(void) {};
|
2013-03-06 19:18:36 +08:00
|
|
|
#endif
|
|
|
|
|
2007-10-13 05:04:05 +08:00
|
|
|
#ifdef CONFIG_GENERIC_CLOCKEVENTS
|
2014-02-07 16:06:06 +08:00
|
|
|
extern int clockevents_notify(unsigned long reason, void *arg);
|
2007-02-16 17:28:00 +08:00
|
|
|
#else
|
2014-02-07 16:06:06 +08:00
|
|
|
static inline int clockevents_notify(unsigned long reason, void *arg) { return 0; }
|
2007-10-13 05:04:05 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#else /* CONFIG_GENERIC_CLOCKEVENTS_BUILD */
|
2007-02-16 17:28:00 +08:00
|
|
|
|
2012-08-06 07:40:41 +08:00
|
|
|
static inline void clockevents_suspend(void) {}
|
|
|
|
static inline void clockevents_resume(void) {}
|
|
|
|
|
2014-02-07 16:06:06 +08:00
|
|
|
static inline int clockevents_notify(unsigned long reason, void *arg) { return 0; }
|
2013-03-22 17:48:33 +08:00
|
|
|
static inline int tick_check_broadcast_expired(void) { return 0; }
|
2014-02-09 14:02:22 +08:00
|
|
|
static inline void tick_setup_hrtimer_broadcast(void) {};
|
2007-02-16 17:28:00 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|