Commit 10f7e7c1 authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Paul Mackerras

[PATCH] ppc64: consolidate calibrate_decr implementations

pSeries and maple have almost the same code for calibrate_decr,
and BPA would need yet another copy. Instead, I'm moving the
code to arch/ppc64/kernel/time.c.

Some of the related declarations were missing from header
files, so I'm moving those as well.

It makes sense to merge this with the pmac function of the
same name, so we end up having just one implemetation for
iSeries and one for Open Firmware based machines.
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarPaul Mackerras <paulus@samba.org>
parent a4936044
...@@ -671,9 +671,6 @@ static void __init iSeries_bolt_kernel(unsigned long saddr, unsigned long eaddr) ...@@ -671,9 +671,6 @@ static void __init iSeries_bolt_kernel(unsigned long saddr, unsigned long eaddr)
} }
} }
extern unsigned long ppc_proc_freq;
extern unsigned long ppc_tb_freq;
/* /*
* Document me. * Document me.
*/ */
...@@ -772,8 +769,6 @@ static void iSeries_halt(void) ...@@ -772,8 +769,6 @@ static void iSeries_halt(void)
mf_power_off(); mf_power_off();
} }
extern void setup_default_decr(void);
/* /*
* void __init iSeries_calibrate_decr() * void __init iSeries_calibrate_decr()
* *
......
...@@ -235,6 +235,6 @@ struct machdep_calls __initdata maple_md = { ...@@ -235,6 +235,6 @@ struct machdep_calls __initdata maple_md = {
.get_boot_time = maple_get_boot_time, .get_boot_time = maple_get_boot_time,
.set_rtc_time = maple_set_rtc_time, .set_rtc_time = maple_set_rtc_time,
.get_rtc_time = maple_get_rtc_time, .get_rtc_time = maple_get_rtc_time,
.calibrate_decr = maple_calibrate_decr, .calibrate_decr = generic_calibrate_decr,
.progress = maple_progress, .progress = maple_progress,
}; };
...@@ -42,11 +42,8 @@ ...@@ -42,11 +42,8 @@
#define DBG(x...) #define DBG(x...)
#endif #endif
extern void setup_default_decr(void);
extern void GregorianDay(struct rtc_time * tm); extern void GregorianDay(struct rtc_time * tm);
extern unsigned long ppc_tb_freq;
extern unsigned long ppc_proc_freq;
static int maple_rtc_addr; static int maple_rtc_addr;
static int maple_clock_read(int addr) static int maple_clock_read(int addr)
...@@ -176,51 +173,3 @@ void __init maple_get_boot_time(struct rtc_time *tm) ...@@ -176,51 +173,3 @@ void __init maple_get_boot_time(struct rtc_time *tm)
maple_get_rtc_time(tm); maple_get_rtc_time(tm);
} }
/* XXX FIXME: Some sane defaults: 125 MHz timebase, 1GHz processor */
#define DEFAULT_TB_FREQ 125000000UL
#define DEFAULT_PROC_FREQ (DEFAULT_TB_FREQ * 8)
void __init maple_calibrate_decr(void)
{
struct device_node *cpu;
struct div_result divres;
unsigned int *fp = NULL;
/*
* The cpu node should have a timebase-frequency property
* to tell us the rate at which the decrementer counts.
*/
cpu = of_find_node_by_type(NULL, "cpu");
ppc_tb_freq = DEFAULT_TB_FREQ;
if (cpu != 0)
fp = (unsigned int *)get_property(cpu, "timebase-frequency", NULL);
if (fp != NULL)
ppc_tb_freq = *fp;
else
printk(KERN_ERR "WARNING: Estimating decrementer frequency (not found)\n");
fp = NULL;
ppc_proc_freq = DEFAULT_PROC_FREQ;
if (cpu != 0)
fp = (unsigned int *)get_property(cpu, "clock-frequency", NULL);
if (fp != NULL)
ppc_proc_freq = *fp;
else
printk(KERN_ERR "WARNING: Estimating processor frequency (not found)\n");
of_node_put(cpu);
printk(KERN_INFO "time_init: decrementer frequency = %lu.%.6lu MHz\n",
ppc_tb_freq/1000000, ppc_tb_freq%1000000);
printk(KERN_INFO "time_init: processor frequency = %lu.%.6lu MHz\n",
ppc_proc_freq/1000000, ppc_proc_freq%1000000);
tb_ticks_per_jiffy = ppc_tb_freq / HZ;
tb_ticks_per_sec = tb_ticks_per_jiffy * HZ;
tb_ticks_per_usec = ppc_tb_freq / 1000000;
tb_to_us = mulhwu_scale_factor(ppc_tb_freq, 1000000);
div128_by_32(1024*1024, 0, tb_ticks_per_sec, &divres);
tb_to_xs = divres.result_low;
setup_default_decr();
}
...@@ -84,9 +84,6 @@ extern void generic_find_legacy_serial_ports(u64 *physport, ...@@ -84,9 +84,6 @@ extern void generic_find_legacy_serial_ports(u64 *physport,
int fwnmi_active; /* TRUE if an FWNMI handler is present */ int fwnmi_active; /* TRUE if an FWNMI handler is present */
extern unsigned long ppc_proc_freq;
extern unsigned long ppc_tb_freq;
extern void pSeries_system_reset_exception(struct pt_regs *regs); extern void pSeries_system_reset_exception(struct pt_regs *regs);
extern int pSeries_machine_check_exception(struct pt_regs *regs); extern int pSeries_machine_check_exception(struct pt_regs *regs);
...@@ -482,70 +479,6 @@ static void pSeries_progress(char *s, unsigned short hex) ...@@ -482,70 +479,6 @@ static void pSeries_progress(char *s, unsigned short hex)
spin_unlock(&progress_lock); spin_unlock(&progress_lock);
} }
extern void setup_default_decr(void);
/* Some sane defaults: 125 MHz timebase, 1GHz processor */
#define DEFAULT_TB_FREQ 125000000UL
#define DEFAULT_PROC_FREQ (DEFAULT_TB_FREQ * 8)
static void __init pSeries_calibrate_decr(void)
{
struct device_node *cpu;
struct div_result divres;
unsigned int *fp;
int node_found;
/*
* The cpu node should have a timebase-frequency property
* to tell us the rate at which the decrementer counts.
*/
cpu = of_find_node_by_type(NULL, "cpu");
ppc_tb_freq = DEFAULT_TB_FREQ; /* hardcoded default */
node_found = 0;
if (cpu != 0) {
fp = (unsigned int *)get_property(cpu, "timebase-frequency",
NULL);
if (fp != 0) {
node_found = 1;
ppc_tb_freq = *fp;
}
}
if (!node_found)
printk(KERN_ERR "WARNING: Estimating decrementer frequency "
"(not found)\n");
ppc_proc_freq = DEFAULT_PROC_FREQ;
node_found = 0;
if (cpu != 0) {
fp = (unsigned int *)get_property(cpu, "clock-frequency",
NULL);
if (fp != 0) {
node_found = 1;
ppc_proc_freq = *fp;
}
}
if (!node_found)
printk(KERN_ERR "WARNING: Estimating processor frequency "
"(not found)\n");
of_node_put(cpu);
printk(KERN_INFO "time_init: decrementer frequency = %lu.%.6lu MHz\n",
ppc_tb_freq/1000000, ppc_tb_freq%1000000);
printk(KERN_INFO "time_init: processor frequency = %lu.%.6lu MHz\n",
ppc_proc_freq/1000000, ppc_proc_freq%1000000);
tb_ticks_per_jiffy = ppc_tb_freq / HZ;
tb_ticks_per_sec = tb_ticks_per_jiffy * HZ;
tb_ticks_per_usec = ppc_tb_freq / 1000000;
tb_to_us = mulhwu_scale_factor(ppc_tb_freq, 1000000);
div128_by_32(1024*1024, 0, tb_ticks_per_sec, &divres);
tb_to_xs = divres.result_low;
setup_default_decr();
}
static int pSeries_check_legacy_ioport(unsigned int baseport) static int pSeries_check_legacy_ioport(unsigned int baseport)
{ {
struct device_node *np; struct device_node *np;
...@@ -604,7 +537,7 @@ struct machdep_calls __initdata pSeries_md = { ...@@ -604,7 +537,7 @@ struct machdep_calls __initdata pSeries_md = {
.get_boot_time = pSeries_get_boot_time, .get_boot_time = pSeries_get_boot_time,
.get_rtc_time = pSeries_get_rtc_time, .get_rtc_time = pSeries_get_rtc_time,
.set_rtc_time = pSeries_set_rtc_time, .set_rtc_time = pSeries_set_rtc_time,
.calibrate_decr = pSeries_calibrate_decr, .calibrate_decr = generic_calibrate_decr,
.progress = pSeries_progress, .progress = pSeries_progress,
.check_legacy_ioport = pSeries_check_legacy_ioport, .check_legacy_ioport = pSeries_check_legacy_ioport,
.system_reset_exception = pSeries_system_reset_exception, .system_reset_exception = pSeries_system_reset_exception,
......
...@@ -40,11 +40,6 @@ ...@@ -40,11 +40,6 @@
#define DBG(x...) #define DBG(x...)
#endif #endif
extern void setup_default_decr(void);
extern unsigned long ppc_tb_freq;
extern unsigned long ppc_proc_freq;
/* Apparently the RTC stores seconds since 1 Jan 1904 */ /* Apparently the RTC stores seconds since 1 Jan 1904 */
#define RTC_OFFSET 2082844800 #define RTC_OFFSET 2082844800
...@@ -161,8 +156,7 @@ void __init pmac_get_boot_time(struct rtc_time *tm) ...@@ -161,8 +156,7 @@ void __init pmac_get_boot_time(struct rtc_time *tm)
/* /*
* Query the OF and get the decr frequency. * Query the OF and get the decr frequency.
* This was taken from the pmac time_init() when merging the prep/pmac * FIXME: merge this with generic_calibrate_decr
* time functions.
*/ */
void __init pmac_calibrate_decr(void) void __init pmac_calibrate_decr(void)
{ {
......
...@@ -701,9 +701,6 @@ void machine_halt(void) ...@@ -701,9 +701,6 @@ void machine_halt(void)
EXPORT_SYMBOL(machine_halt); EXPORT_SYMBOL(machine_halt);
unsigned long ppc_proc_freq;
unsigned long ppc_tb_freq;
static int ppc64_panic_event(struct notifier_block *this, static int ppc64_panic_event(struct notifier_block *this,
unsigned long event, void *ptr) unsigned long event, void *ptr)
{ {
...@@ -1117,7 +1114,7 @@ void ppc64_dump_msg(unsigned int src, const char *msg) ...@@ -1117,7 +1114,7 @@ void ppc64_dump_msg(unsigned int src, const char *msg)
} }
/* This should only be called on processor 0 during calibrate decr */ /* This should only be called on processor 0 during calibrate decr */
void setup_default_decr(void) void __init setup_default_decr(void)
{ {
struct paca_struct *lpaca = get_paca(); struct paca_struct *lpaca = get_paca();
......
...@@ -107,6 +107,9 @@ void ppc_adjtimex(void); ...@@ -107,6 +107,9 @@ void ppc_adjtimex(void);
static unsigned adjusting_time = 0; static unsigned adjusting_time = 0;
unsigned long ppc_proc_freq;
unsigned long ppc_tb_freq;
static __inline__ void timer_check_rtc(void) static __inline__ void timer_check_rtc(void)
{ {
/* /*
...@@ -472,6 +475,66 @@ int do_settimeofday(struct timespec *tv) ...@@ -472,6 +475,66 @@ int do_settimeofday(struct timespec *tv)
EXPORT_SYMBOL(do_settimeofday); EXPORT_SYMBOL(do_settimeofday);
#if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_MAPLE) || defined(CONFIG_PPC_BPA)
void __init generic_calibrate_decr(void)
{
struct device_node *cpu;
struct div_result divres;
unsigned int *fp;
int node_found;
/*
* The cpu node should have a timebase-frequency property
* to tell us the rate at which the decrementer counts.
*/
cpu = of_find_node_by_type(NULL, "cpu");
ppc_tb_freq = DEFAULT_TB_FREQ; /* hardcoded default */
node_found = 0;
if (cpu != 0) {
fp = (unsigned int *)get_property(cpu, "timebase-frequency",
NULL);
if (fp != 0) {
node_found = 1;
ppc_tb_freq = *fp;
}
}
if (!node_found)
printk(KERN_ERR "WARNING: Estimating decrementer frequency "
"(not found)\n");
ppc_proc_freq = DEFAULT_PROC_FREQ;
node_found = 0;
if (cpu != 0) {
fp = (unsigned int *)get_property(cpu, "clock-frequency",
NULL);
if (fp != 0) {
node_found = 1;
ppc_proc_freq = *fp;
}
}
if (!node_found)
printk(KERN_ERR "WARNING: Estimating processor frequency "
"(not found)\n");
of_node_put(cpu);
printk(KERN_INFO "time_init: decrementer frequency = %lu.%.6lu MHz\n",
ppc_tb_freq/1000000, ppc_tb_freq%1000000);
printk(KERN_INFO "time_init: processor frequency = %lu.%.6lu MHz\n",
ppc_proc_freq/1000000, ppc_proc_freq%1000000);
tb_ticks_per_jiffy = ppc_tb_freq / HZ;
tb_ticks_per_sec = tb_ticks_per_jiffy * HZ;
tb_ticks_per_usec = ppc_tb_freq / 1000000;
tb_to_us = mulhwu_scale_factor(ppc_tb_freq, 1000000);
div128_by_32(1024*1024, 0, tb_ticks_per_sec, &divres);
tb_to_xs = divres.result_low;
setup_default_decr();
}
#endif
void __init time_init(void) void __init time_init(void)
{ {
/* This function is only called on the boot processor */ /* This function is only called on the boot processor */
......
...@@ -34,6 +34,15 @@ struct rtc_time; ...@@ -34,6 +34,15 @@ struct rtc_time;
extern void to_tm(int tim, struct rtc_time * tm); extern void to_tm(int tim, struct rtc_time * tm);
extern time_t last_rtc_update; extern time_t last_rtc_update;
void generic_calibrate_decr(void);
void setup_default_decr(void);
/* Some sane defaults: 125 MHz timebase, 1GHz processor */
extern unsigned long ppc_proc_freq;
#define DEFAULT_PROC_FREQ (DEFAULT_TB_FREQ * 8)
extern unsigned long ppc_tb_freq;
#define DEFAULT_TB_FREQ 125000000UL
/* /*
* By putting all of this stuff into a single struct we * By putting all of this stuff into a single struct we
* reduce the number of cache lines touched by do_gettimeofday. * reduce the number of cache lines touched by do_gettimeofday.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment