Module Name: src Committed By: thorpej Date: Fri Mar 5 02:58:13 UTC 2021
Modified Files: src/sys/arch/powerpc/oea: ofwoea_machdep.c Log Message: Split set_timebase() into get_timebase_frequency() and init_decrementer(). Call get_timebase_frequency() much earlier. To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.58 src/sys/arch/powerpc/oea/ofwoea_machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/powerpc/oea/ofwoea_machdep.c diff -u src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.57 src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.58 --- src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.57 Fri Mar 5 01:33:33 2021 +++ src/sys/arch/powerpc/oea/ofwoea_machdep.c Fri Mar 5 02:58:13 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: ofwoea_machdep.c,v 1.57 2021/03/05 01:33:33 thorpej Exp $ */ +/* $NetBSD: ofwoea_machdep.c,v 1.58 2021/03/05 02:58:13 thorpej Exp $ */ /*- * Copyright (c) 2007 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ofwoea_machdep.c,v 1.57 2021/03/05 01:33:33 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ofwoea_machdep.c,v 1.58 2021/03/05 02:58:13 thorpej Exp $"); #include "ksyms.h" #include "wsdisplay.h" @@ -136,8 +136,10 @@ extern uint32_t ticks_per_sec; extern uint32_t ns_per_tick; extern uint32_t ticks_per_intr; +static void get_timebase_frequency(void); +static void init_decrementer(void); + static void restore_ofmap(void); -static void set_timebase(void); void ofwoea_initppc(u_int startkernel, u_int endkernel, char *args) @@ -172,6 +174,9 @@ ofwoea_initppc(u_int startkernel, u_int bootpath[len] = 0; } + /* Get the timebase frequency from the firmware. */ + get_timebase_frequency(); + /* Initialize bus_space */ ofwoea_bus_space_init(); @@ -267,8 +272,8 @@ ofwoea_initppc(u_int startkernel, u_int ksyms_addsyms_elf((int)((uintptr_t)endsym - (uintptr_t)startsym), startsym, endsym); #endif - /* CPU clock stuff */ - set_timebase(); + /* Kick off the clock. */ + init_decrementer(); #ifdef DDB if (boothowto & RB_KDB) @@ -276,22 +281,22 @@ ofwoea_initppc(u_int startkernel, u_int #endif } -void -set_timebase(void) +static void +get_timebase_frequency(void) { - int qhandle, phandle, msr, scratch, node; + int qhandle, phandle, node; char type[32]; if (timebase_freq != 0) { ticks_per_sec = timebase_freq; - goto found; + return; } node = OF_finddevice("/cpus/@0"); if (node != -1 && OF_getprop(node, "timebase-frequency", &ticks_per_sec, sizeof ticks_per_sec) > 0) { - goto found; + return; } node = OF_finddevice("/"); @@ -300,7 +305,7 @@ set_timebase(void) && strcmp(type, "cpu") == 0 && OF_getprop(qhandle, "timebase-frequency", &ticks_per_sec, sizeof ticks_per_sec) > 0) { - goto found; + return; } if ((phandle = OF_child(qhandle))) continue; @@ -311,8 +316,15 @@ set_timebase(void) } } panic("no cpu node"); +} + +static void +init_decrementer(void) +{ + int scratch, msr; + + KASSERT(ticks_per_sec != 0); -found: __asm volatile ("mfmsr %0; andi. %1,%0,%2; mtmsr %1" : "=r"(msr), "=r"(scratch) : "K"((u_short)~PSL_EE)); ns_per_tick = 1000000000 / ticks_per_sec; @@ -321,10 +333,10 @@ found: #ifdef PPC_OEA601 if ((mfpvr() >> 16) == MPC601) - curcpu()->ci_lasttb = rtc_nanosecs(); + curcpu()->ci_lasttb = rtc_nanosecs(); else #endif - curcpu()->ci_lasttb = mftbl(); + curcpu()->ci_lasttb = mftbl(); mtspr(SPR_DEC, ticks_per_intr); mtmsr(msr);