summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormpi <mpi@openbsd.org>2013-09-13 07:29:01 +0000
committermpi <mpi@openbsd.org>2013-09-13 07:29:01 +0000
commit425bdff6ee7fe4973aeb11110ce201a0a41e1115 (patch)
tree1043cc1a93e2031ba8d0777f1f0117c2787e2867
parentavoid unaligned access in code that reused a buffer to send a (diff)
downloadwireguard-openbsd-425bdff6ee7fe4973aeb11110ce201a0a41e1115.tar.xz
wireguard-openbsd-425bdff6ee7fe4973aeb11110ce201a0a41e1115.zip
Initialize the variable guarding the clock interrupt routine after
calling initclocks(). This prevents hardclock() from trying to schedule a softclock interrupt before its cookie has been allocated, leading to a panic. While here grab the ticks/second value from the OpenFirmware at the same time we read the clock frequency, no need to look twice for the same node. Looks ok to kettenis@
-rw-r--r--sys/arch/macppc/include/cpu.h4
-rw-r--r--sys/arch/macppc/macppc/autoconf.c5
-rw-r--r--sys/arch/macppc/macppc/clock.c44
-rw-r--r--sys/arch/macppc/macppc/cpu.c23
4 files changed, 23 insertions, 53 deletions
diff --git a/sys/arch/macppc/include/cpu.h b/sys/arch/macppc/include/cpu.h
index 0cd4ce37c54..586d91678f6 100644
--- a/sys/arch/macppc/include/cpu.h
+++ b/sys/arch/macppc/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.12 2013/03/17 15:10:33 kettenis Exp $ */
+/* $OpenBSD: cpu.h,v 1.13 2013/09/13 07:29:02 mpi Exp $ */
/* $NetBSD: cpu.h,v 1.1 1996/09/30 16:34:21 ws Exp $ */
/*
@@ -62,5 +62,7 @@ extern int ppc_altivec;
extern void (*ppc64_slew_voltage)(u_int);
+extern u_int32_t ticks_per_sec;
+
#endif /* _KERNEL */
#endif /* _MACHINE_CPU_H_ */
diff --git a/sys/arch/macppc/macppc/autoconf.c b/sys/arch/macppc/macppc/autoconf.c
index a25deef4bcb..879ce4f8d8a 100644
--- a/sys/arch/macppc/macppc/autoconf.c
+++ b/sys/arch/macppc/macppc/autoconf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: autoconf.c,v 1.40 2013/06/03 19:16:43 mpi Exp $ */
+/* $OpenBSD: autoconf.c,v 1.41 2013/09/13 07:29:01 mpi Exp $ */
/*
* Copyright (c) 1996, 1997 Per Fogelstrom
* Copyright (c) 1995 Theo de Raadt
@@ -37,7 +37,7 @@
* from: Utah Hdr: autoconf.c 1.31 91/01/21
*
* from: @(#)autoconf.c 8.1 (Berkeley) 6/10/93
- * $Id: autoconf.c,v 1.40 2013/06/03 19:16:43 mpi Exp $
+ * $Id: autoconf.c,v 1.41 2013/09/13 07:29:01 mpi Exp $
*/
/*
@@ -93,7 +93,6 @@ void
cpu_configure()
{
(void)splhigh(); /* To be really sure.. */
- calc_delayconst();
softintr_init();
diff --git a/sys/arch/macppc/macppc/clock.c b/sys/arch/macppc/macppc/clock.c
index fd44514216a..37d2a0df05a 100644
--- a/sys/arch/macppc/macppc/clock.c
+++ b/sys/arch/macppc/macppc/clock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clock.c,v 1.33 2013/04/23 07:38:05 mpi Exp $ */
+/* $OpenBSD: clock.c,v 1.34 2013/09/13 07:29:01 mpi Exp $ */
/* $NetBSD: clock.c,v 1.1 1996/09/30 16:34:40 ws Exp $ */
/*
@@ -51,7 +51,7 @@ u_int tb_get_timecount(struct timecounter *);
/*
* Initially we assume a processor with a bus frequency of 12.5 MHz.
*/
-static u_int32_t ticks_per_sec = 3125000;
+u_int32_t ticks_per_sec = 3125000;
static u_int32_t ns_per_tick = 320;
static int32_t ticks_per_intr;
@@ -304,6 +304,9 @@ cpu_initclocks()
intrstate = ppc_intr_disable();
+ ns_per_tick = 1000000000 / ticks_per_sec;
+ ticks_per_intr = ticks_per_sec / hz;
+
stathz = 100;
profhz = 1000; /* must be a multiple of stathz */
@@ -346,43 +349,6 @@ cpu_startclock()
ppc_mtdec(nextevent - ci->ci_lasttb);
}
-void
-calc_delayconst(void)
-{
- int qhandle, phandle = 0;
- char name[32];
- int s;
-
- /*
- * Get this info during autoconf? XXX
- */
- for (qhandle = OF_peer(0); qhandle; qhandle = phandle) {
- if (OF_getprop(qhandle, "device_type", name, sizeof name) >= 0
- && !strcmp(name, "cpu")
- && OF_getprop(qhandle, "timebase-frequency",
- &ticks_per_sec, sizeof ticks_per_sec) >= 0) {
- /*
- * Should check for correct CPU here? XXX
- */
- s = ppc_intr_disable();
- ns_per_tick = 1000000000 / ticks_per_sec;
- ticks_per_intr = ticks_per_sec / hz;
- ppc_intr_enable(s);
- break;
- }
- if ((phandle = OF_child(qhandle)))
- continue;
- while (qhandle) {
- if ((phandle = OF_peer(qhandle)))
- break;
- qhandle = OF_parent(qhandle);
- }
- }
-
- if (!phandle)
- panic("no cpu node");
-}
-
/*
* Wait for about n microseconds (us) (at least!).
*/
diff --git a/sys/arch/macppc/macppc/cpu.c b/sys/arch/macppc/macppc/cpu.c
index 22595524103..f24eac50fe2 100644
--- a/sys/arch/macppc/macppc/cpu.c
+++ b/sys/arch/macppc/macppc/cpu.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.c,v 1.71 2013/06/03 16:55:22 guenther Exp $ */
+/* $OpenBSD: cpu.c,v 1.72 2013/09/13 07:29:02 mpi Exp $ */
/*
* Copyright (c) 1997 Per Fogelstrom
@@ -45,6 +45,7 @@
#include <machine/autoconf.h>
#include <machine/bat.h>
+#include <machine/cpu.h>
#include <machine/trap.h>
/* only valid on 603(e,ev) and G3, G4 */
@@ -241,8 +242,8 @@ cpuattach(struct device *parent, struct device *dev, void *aux)
int *reg = ca->ca_reg;
u_int32_t cpu, pvr, hid0;
char name[32];
- int qhandle, phandle;
- u_int32_t clock_freq = 0;
+ int qhandle, phandle, len;
+ u_int32_t clock_freq = 0, timebase = 0;
struct cpu_info *ci;
ci = &cpu_info[reg[0]];
@@ -330,14 +331,13 @@ cpuattach(struct device *parent, struct device *dev, void *aux)
" (Revision 0x%x)", pvr & 0xffff);
printf(": %s", cpu_model);
- /* This should only be executed on openfirmware systems... */
-
for (qhandle = OF_peer(0); qhandle; qhandle = phandle) {
- if (OF_getprop(qhandle, "device_type", name, sizeof name) >= 0
- && !strcmp(name, "cpu")
- && OF_getprop(qhandle, "clock-frequency",
- &clock_freq, sizeof clock_freq) >= 0)
- {
+ len = OF_getprop(qhandle, "device_type", name, sizeof(name));
+ if (len >= 0 && strcmp(name, "cpu") == 0) {
+ OF_getprop(qhandle, "clock-frequency", &clock_freq,
+ sizeof(clock_freq));
+ OF_getprop(qhandle, "timebase-frequency", &timebase,
+ sizeof(timebase));
break;
}
if ((phandle = OF_child(qhandle)))
@@ -349,6 +349,9 @@ cpuattach(struct device *parent, struct device *dev, void *aux)
}
}
+ if (timebase != 0)
+ ticks_per_sec = timebase;
+
if (clock_freq != 0) {
/* Openfirmware stores clock in Hz, not MHz */
clock_freq /= 1000000;