summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordrahn <drahn@openbsd.org>2011-11-06 01:34:53 +0000
committerdrahn <drahn@openbsd.org>2011-11-06 01:34:53 +0000
commitadcd8f604d1f5820c07b42ef6a563d193a78f0f9 (patch)
tree07bac7b68963bd9875076333c10901edf1678fbd
parentI had moved earlier the adding of processes to the pgrp and children lists (diff)
downloadwireguard-openbsd-adcd8f604d1f5820c07b42ef6a563d193a78f0f9.tar.xz
wireguard-openbsd-adcd8f604d1f5820c07b42ef6a563d193a78f0f9.zip
Further on the road to working.
-rw-r--r--sys/arch/beagle/beagle/intr.c17
-rw-r--r--sys/arch/beagle/conf/GENERIC6
-rw-r--r--sys/arch/beagle/conf/RAMDISK7
-rw-r--r--sys/arch/beagle/dev/ampintc.c65
-rw-r--r--sys/arch/beagle/dev/amptimer.c101
-rw-r--r--sys/arch/beagle/dev/gptimer.c8
-rw-r--r--sys/arch/beagle/include/intr.h4
7 files changed, 158 insertions, 50 deletions
diff --git a/sys/arch/beagle/beagle/intr.c b/sys/arch/beagle/beagle/intr.c
index 4abce860714..f8f02d5dfdb 100644
--- a/sys/arch/beagle/beagle/intr.c
+++ b/sys/arch/beagle/beagle/intr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: intr.c,v 1.3 2011/11/05 19:02:25 drahn Exp $ */
+/* $OpenBSD: intr.c,v 1.4 2011/11/06 01:34:53 drahn Exp $ */
/*
* Copyright (c) 2011 Dale Rahn <drahn@openbsd.org>
*
@@ -294,16 +294,20 @@ void arm_dflt_delay(u_int usecs);
struct {
void (*delay)(u_int);
void (*initclocks)(void);
+ void (*setstatclockrate)(int);
} arm_clock_func = {
arm_dflt_delay,
+ NULL,
NULL
};
void
-arm_clock_register(void (*initclock)(void), void (*delay)(u_int))
+arm_clock_register(void (*initclock)(void), void (*delay)(u_int),
+ void (*statclock)(int))
{
arm_clock_func.initclocks = initclock;
arm_clock_func.delay = delay;
+ arm_clock_func.setstatclockrate = statclock;
}
@@ -418,3 +422,12 @@ resettodr(void)
todr_settime(todr_handle, &rtctime) != 0)
printf("resettodr: failed to set time\n");
}
+
+void
+setstatclockrate(int new)
+{
+ if (arm_clock_func.setstatclockrate == NULL) {
+ panic("arm_clock_func.setstatclockrate not intialized");
+ }
+ arm_clock_func.setstatclockrate(new);
+}
diff --git a/sys/arch/beagle/conf/GENERIC b/sys/arch/beagle/conf/GENERIC
index d4acfd2dbdf..58d52fc97ef 100644
--- a/sys/arch/beagle/conf/GENERIC
+++ b/sys/arch/beagle/conf/GENERIC
@@ -1,4 +1,4 @@
-# $OpenBSD: GENERIC,v 1.10 2011/11/05 12:30:58 drahn Exp $
+# $OpenBSD: GENERIC,v 1.11 2011/11/06 01:34:53 drahn Exp $
#
# GENERIC machine description file
#
@@ -24,8 +24,6 @@ options TIMEZONE=0 # time zone to adjust RTC time by
options DST=0 # daylight saving time used by RTC
#options NFSCLIENT # NFS
-options ARM11_AVIC_INTR
-
makeoptions KERNEL_BASE_PHYS="0x80300000"
makeoptions KERNEL_BASE_VIRT="0xc0300000"
options BUILD_STARTUP_PAGETABLE
@@ -62,7 +60,7 @@ ampintc0 at ahb?
gptimer0 at ahb? addr 0x49032000 intr 38 # timer GPTIMER2
gptimer1 at ahb? addr 0x48318000 intr 37 # timer GPTIMER1
-amptimer0 at ahb? addr 0x48240600
+amptimer0 at ahb? addr 0x48240000
omgpio0 at ahb? addr 0x48310000 intr 29
omgpio1 at ahb? addr 0x49050000 intr 30
diff --git a/sys/arch/beagle/conf/RAMDISK b/sys/arch/beagle/conf/RAMDISK
index 9dced825eb0..14944bc52df 100644
--- a/sys/arch/beagle/conf/RAMDISK
+++ b/sys/arch/beagle/conf/RAMDISK
@@ -1,4 +1,4 @@
-# $OpenBSD: RAMDISK,v 1.13 2011/11/05 12:30:58 drahn Exp $
+# $OpenBSD: RAMDISK,v 1.14 2011/11/06 01:34:53 drahn Exp $
#
# GENERIC machine description file
#
@@ -31,8 +31,6 @@ options DDB # kernel debugger
options FIFO # FIFOs; RECOMMENDED
#options NFSCLIENT # NFS
-options ARM11_AVIC_INTR
-
makeoptions KERNEL_BASE_PHYS="0x80300000"
makeoptions KERNEL_BASE_VIRT="0xc0300000"
options BUILD_STARTUP_PAGETABLE
@@ -67,7 +65,7 @@ ampintc0 at ahb?
gptimer0 at ahb? addr 0x49032000 intr 38 # timer GPTIMER2
gptimer1 at ahb? addr 0x48318000 intr 37 # timer GPTIMER1
-amptimer0 at ahb? addr 0x48240600
+amptimer0 at ahb? addr 0x48240000
omgpio0 at ahb? addr 0x48310000 intr 29
omgpio1 at ahb? addr 0x49050000 intr 30
@@ -164,6 +162,7 @@ uk* at scsibus?
# onboard uarts
+com0 at ahb? addr 0x48020000 size 0x400 intr 74 # UART3
com0 at ahb? addr 0x49020000 size 0x400 intr 74 # UART3
#com1 at ahb? addr 0xXXXXXX00 size 0x400 intr 73
diff --git a/sys/arch/beagle/dev/ampintc.c b/sys/arch/beagle/dev/ampintc.c
index 7f4432d664b..45cc6d5d33d 100644
--- a/sys/arch/beagle/dev/ampintc.c
+++ b/sys/arch/beagle/dev/ampintc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ampintc.c,v 1.2 2011/11/05 15:13:51 drahn Exp $ */
+/* $OpenBSD: ampintc.c,v 1.3 2011/11/06 01:34:53 drahn Exp $ */
/*
* Copyright (c) 2007,2009,2011 Dale Rahn <drahn@openbsd.org>
*
@@ -65,7 +65,7 @@
#define ICD_ICPRn(i) (0x280 + (IRQ_TO_REG32(i) * 4))
#define ICD_ABRn(i) (0x300 + (IRQ_TO_REG32(i) * 4))
#define ICD_IPRn(i) (0x400 + (i))
-#define ICD_IPTRn(i) (0x800 + (IRQ_TO_REG4(i) * 4))
+#define ICD_IPTRn(i) (0x800 + (i))
#define ICD_ICRn(i) (0xC00 + (IRQ_TO_REG16(i) * 4))
/*
* what about (ppi|spi)_status
@@ -122,6 +122,9 @@
#define AMPAMPINTC_SIZE 0x1000
+#define IRQ_ENABLE 1
+#define IRQ_DISABLE 0
+
struct ampintc_softc {
struct device sc_dev;
struct intrq *sc_ampintc_handler;
@@ -167,6 +170,7 @@ void ampintc_eoi(uint32_t);
void ampintc_set_priority(int, int);
void ampintc_intr_enable(int);
void ampintc_intr_disable(int);
+void ampintc_route(int, int , int);
struct cfattach ampintc_ca = {
sizeof (struct ampintc_softc), ampintc_match, ampintc_attach
@@ -243,17 +247,16 @@ ampintc_attach(struct device *parent, struct device *self, void *args)
for (i = 0; i < nintr/32; i++) {
bus_space_write_4(iot, d_ioh, ICD_ICERn(i*32), ~0);
bus_space_write_4(iot, d_ioh, ICD_ICPRn(i*32), ~0);
+ bus_space_write_1(iot, d_ioh, ICD_IPTRn(i), 0);
}
for (i = 0; i < nintr/4; i++) {
-
/* lowest priority ?? */
bus_space_write_4(iot, d_ioh, ICD_IPRn(i*32), 0xffffffff);
/* target no cpus */
- bus_space_write_4(iot, d_ioh, ICD_IPTRn(i*32), 0);
}
- for (i = 2; i < nintr/15; i++) {
+ for (i = 2; i < nintr/16; i++) {
/* irq 32 - N */
- bus_space_write_4(iot, d_ioh, ICD_ICRn(i*32), 0);
+ bus_space_write_4(iot, d_ioh, ICD_ICRn(i*4), 0);
}
/* software reset of the part? */
@@ -321,6 +324,9 @@ ampintc_intr_enable(int irq)
{
struct ampintc_softc *sc = ampintc;
+ printf("enable irq %d register %x bitmask %08x\n",
+ irq, ICD_ISERn(irq), 1 << IRQ_TO_REG32BIT(irq));
+
bus_space_write_4(sc->sc_iot, sc->sc_d_ioh, ICD_ISERn(irq),
1 << IRQ_TO_REG32BIT(irq));
}
@@ -375,11 +381,14 @@ ampintc_calc_mask(void)
if (min != IPL_NONE) {
ampintc_set_priority(irq, min);
ampintc_intr_enable(irq);
+ ampintc_route(irq, IRQ_ENABLE, 0);
} else {
ampintc_intr_disable(irq);
+ ampintc_route(irq, IRQ_DISABLE, 0);
+
}
}
- printf("cpl %d", ci->ci_cpl);
+ printf("cpl %d\n", ci->ci_cpl);
ampintc_setipl(ci->ci_cpl);
}
@@ -438,11 +447,24 @@ ampintc_iack(void)
void
ampintc_eoi(uint32_t eoi)
{
-#if 0
- uint32_t intid;
struct ampintc_softc *sc = ampintc;
- intid = bus_space_write_4(sc->sc_cpu, ICPEOIR, eoi);
-#endif
+ bus_space_write_4(sc->sc_iot, sc->sc_p_ioh, ICPEOIR, eoi);
+}
+
+void
+ampintc_route(int irq, int enable, int cpu)
+{
+ uint8_t val;
+ struct ampintc_softc *sc = ampintc;
+ if (enable == IRQ_ENABLE) {
+ val = bus_space_read_1(sc->sc_iot, sc->sc_d_ioh, ICD_IPTRn(irq));
+ val |= (1 << cpu);
+ bus_space_write_1(sc->sc_iot, sc->sc_d_ioh, ICD_IPTRn(irq), val);
+ } else {
+ val = bus_space_read_1(sc->sc_iot, sc->sc_d_ioh, ICD_IPTRn(irq));
+ val &= ~(1 << cpu);
+ bus_space_write_1(sc->sc_iot, sc->sc_d_ioh, ICD_IPTRn(irq), val);
+ }
}
void
@@ -454,10 +476,25 @@ ampintc_irq_handler(void *frame)
uint32_t iack_val;
int irq, pri, s;
+ iack_val = ampintc_iack();
+//#define DEBUG_INTC
#ifdef DEBUG_INTC
- printf("irq %d fired\n", irq);
+ if (iack_val != 27)
+ printf("irq %d fired\n", iack_val);
+ else {
+ static int cnt = 0;
+ if ((cnt++ % 100) == 0) {
+ printf("irq %d fired * _100\n", iack_val);
+ Debugger();
+ }
+
+ }
#endif
- iack_val = ampintc_iack();
+
+ if (iack_val == 1023) {
+ printf("spur\n");
+ return;
+ }
irq = iack_val & ((1 << sc->sc_nintr) - 1);
pri = sc->sc_ampintc_handler[irq].iq_irq;
@@ -485,7 +522,7 @@ ampintc_intr_establish(int irqno, int level, int (*func)(void *),
struct intrhand *ih;
int psw;
- printf("ampintc intr_establish %s %d %d", name, irqno, level);
+ printf("ampintc intr_establish %s %d %d\n", name, irqno, level);
if (irqno < 0 || irqno >= sc->sc_nintr)
panic("ampintc_intr_establish: bogus irqnumber %d: %s",
irqno, name);
diff --git a/sys/arch/beagle/dev/amptimer.c b/sys/arch/beagle/dev/amptimer.c
index ff1b1e7ba9b..18152a5f774 100644
--- a/sys/arch/beagle/dev/amptimer.c
+++ b/sys/arch/beagle/dev/amptimer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: amptimer.c,v 1.1 2011/11/05 11:48:26 drahn Exp $ */
+/* $OpenBSD: amptimer.c,v 1.2 2011/11/06 01:34:53 drahn Exp $ */
/*
* Copyright (c) 2011 Dale Rahn <drahn@openbsd.org>
*
@@ -29,23 +29,23 @@
#include <machine/intr.h>
#include <arch/beagle/beagle/ahb.h>
-#define GTIMER_CNT_LOW 0x00
-#define GTIMER_CNT_HIGH 0x04
-#define GTIMER_CTRL 0x08
+#define GTIMER_CNT_LOW 0x200
+#define GTIMER_CNT_HIGH 0x204
+#define GTIMER_CTRL 0x208
#define GTIMER_CTRL_AA (1 << 3)
#define GTIMER_CTRL_IRQ (1 << 2)
#define GTIMER_CTRL_COMP (1 << 1)
#define GTIMER_CTRL_TIMER (1 << 0)
-#define GTIMER_STATUS 0x0c
+#define GTIMER_STATUS 0x10c
#define GTIMER_STATUS_EVENT (1 << 0)
-#define GTIMER_CMP_LOW 0x10
-#define GTIMER_CMP_HIGH 0x14
-#define GTIMER_AUTOINC 0x18
+#define GTIMER_CMP_LOW 0x210
+#define GTIMER_CMP_HIGH 0x214
+#define GTIMER_AUTOINC 0x218
-#define GTIMER_SIZE 0x20
+#define GTIMER_SIZE 0x300
/* XXX - PERIPHCLK */
-#define TIMER_FREQUENCY 32768
+#define TIMER_FREQUENCY 512 * 1024 * 1024 /* XXX - PERIPHCLK? */
u_int amptimer_get_timecount(struct timecounter *);
@@ -76,6 +76,8 @@ void amptimer_attach(struct device *, struct device *, void *);
uint64_t amptimer_readcnt64(struct amptimer_softc *sc);
int amptimer_intr(void *);
void amptimer_cpu_initclocks(void);
+void amptimer_delay(u_int);
+void amptimer_setstatclockrate(int stathz);
struct cfattach amptimer_ca = {
sizeof (struct amptimer_softc), amptimer_match, amptimer_attach
@@ -89,10 +91,8 @@ int
amptimer_match(struct device *parent, void *v, void *aux)
{
switch (board_id) {
- case BOARD_ID_OMAP3_BEAGLE:
- break; /* continue trying */
case BOARD_ID_OMAP4_PANDA:
- return 0; /* not ported yet ??? - different */
+ break; /* continue trying */
default:
return 0; /* unknown */
}
@@ -124,10 +124,12 @@ amptimer_attach(struct device *parent, struct device *self, void *args)
bus_space_handle_t ioh;
sc->sc_iot = aa->aa_iot;
-
if (bus_space_map(sc->sc_iot, aa->aa_addr, GTIMER_SIZE, 0, &ioh))
panic("amptimer_attach: bus_space_map failed!");
+ sc->sc_ticks_per_second = TIMER_FREQUENCY;
+ printf("tick rate %d KHz\n", sc->sc_ticks_per_second /1024);
+
sc->sc_ioh = ioh;
/* disable global timer */
@@ -147,11 +149,9 @@ amptimer_attach(struct device *parent, struct device *self, void *args)
* comparitor registers and interrupts not enabled until
* timer configures
*/
- /*
- * XXX - configure delay -> amptimer_delay()
- * XXX - configure cpu_initclocks -> amptimer_initclocks()
- */
- sc->sc_ticks_per_second = TIMER_FREQUENCY;
+
+ arm_clock_register(amptimer_cpu_initclocks, amptimer_delay,
+ amptimer_setstatclockrate);
amptimer_timecounter.tc_frequency = sc->sc_ticks_per_second;
amptimer_timecounter.tc_priv = sc;
@@ -184,7 +184,7 @@ amptimer_intr(void *frame)
* do the right thing
*/
- now = bus_space_read_4(sc->sc_iot, sc->sc_ioh, GTIMER_CNT_LOW);
+ now = amptimer_readcnt64(sc);
while (sc->sc_nexttickevent <= now) {
sc->sc_nexttickevent += sc->sc_ticks_per_intr;
@@ -255,7 +255,7 @@ amptimer_cpu_initclocks()
sc->sc_ticks_per_second = TIMER_FREQUENCY;
- setstatclockrate(stathz);
+ amptimer_setstatclockrate(stathz);
sc->sc_ticks_per_intr = sc->sc_ticks_per_second / hz;
sc->sc_ticks_err_cnt = sc->sc_ticks_per_second % hz;
@@ -281,3 +281,62 @@ amptimer_cpu_initclocks()
bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTIMER_CTRL, reg);
}
+void
+amptimer_delay(u_int usecs)
+{
+ struct amptimer_softc *sc = amptimer_cd.cd_devs[0];
+ u_int32_t clock, oclock, delta, delaycnt;
+ volatile int j;
+ int csec, usec;
+
+ if (usecs > (0x80000000 / (sc->sc_ticks_per_second))) {
+ csec = usecs / 10000;
+ usec = usecs % 10000;
+
+ delaycnt = (sc->sc_ticks_per_second / 100) * csec +
+ (sc->sc_ticks_per_second / 100) * usec / 10000;
+ } else {
+ delaycnt = sc->sc_ticks_per_second * usecs / 1000000;
+ }
+ if (delaycnt <= 1)
+ for (j = 100; j > 0; j--)
+ ;
+
+ oclock = bus_space_read_4(sc->sc_iot, sc->sc_ioh, GTIMER_CNT_LOW);
+ while (1) {
+ for (j = 100; j > 0; j--)
+ ;
+ clock = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
+ GTIMER_CNT_LOW);
+ delta = clock - oclock;
+ if (delta > delaycnt)
+ break;
+ }
+
+}
+
+void
+amptimer_setstatclockrate(int newhz)
+{
+ struct amptimer_softc *sc = amptimer_cd.cd_devs[0];
+ int minint, statint;
+ int s;
+
+ s = splclock();
+
+ statint = sc->sc_ticks_per_second / newhz;
+ /* calculate largest 2^n which is smaller that just over half statint */
+ sc->sc_statvar = 0x40000000; /* really big power of two */
+ minint = statint / 2 + 100;
+ while (sc->sc_statvar > minint)
+ sc->sc_statvar >>= 1;
+
+ sc->sc_statmin = statint - (sc->sc_statvar >> 1);
+
+ splx(s);
+
+ /*
+ * XXX this allows the next stat timer to occur then it switches
+ * to the new frequency. Rather than switching instantly.
+ */
+}
diff --git a/sys/arch/beagle/dev/gptimer.c b/sys/arch/beagle/dev/gptimer.c
index 78b41ea3aa2..01e498d6053 100644
--- a/sys/arch/beagle/dev/gptimer.c
+++ b/sys/arch/beagle/dev/gptimer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gptimer.c,v 1.9 2011/11/05 18:28:32 drahn Exp $ */
+/* $OpenBSD: gptimer.c,v 1.10 2011/11/06 01:34:53 drahn Exp $ */
/*
* Copyright (c) 2007,2009 Dale Rahn <drahn@openbsd.org>
*
@@ -112,6 +112,7 @@ int gptimer_intr(void *frame);
void gptimer_wait(int reg);
void gptimer_cpu_initclocks(void);
void gptimer_delay(u_int);
+void gptimer_setstatclockrate(int newhz);
bus_space_tag_t gptimer_iot;
bus_space_handle_t gptimer_ioh0, gptimer_ioh1;
@@ -189,7 +190,8 @@ gptimer_attach(struct device *parent, struct device *self, void *args)
panic("attaching too many gptimers at %x", aa->aa_addr);
- arm_clock_register(gptimer_cpu_initclocks, gptimer_delay);
+ arm_clock_register(gptimer_cpu_initclocks, gptimer_delay,
+ gptimer_setstatclockrate);
}
/*
@@ -423,7 +425,7 @@ gptimer_delay(u_int usecs)
}
void
-setstatclockrate(int newhz)
+gptimer_setstatclockrate(int newhz)
{
int minint, statint;
int s;
diff --git a/sys/arch/beagle/include/intr.h b/sys/arch/beagle/include/intr.h
index d99a1cc6894..7f6b852312c 100644
--- a/sys/arch/beagle/include/intr.h
+++ b/sys/arch/beagle/include/intr.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: intr.h,v 1.5 2011/11/05 18:28:32 drahn Exp $ */
+/* $OpenBSD: intr.h,v 1.6 2011/11/06 01:34:53 drahn Exp $ */
/* $NetBSD: intr.h,v 1.12 2003/06/16 20:00:59 thorpej Exp $ */
/*
@@ -138,7 +138,7 @@ void arm_intr_disestablish(void *cookie);
const char *arm_intr_string(void *cookie);
/* XXX - this is probably the wrong location for this */
-void arm_clock_register(void (*)(void), void (*)(u_int));
+void arm_clock_register(void (*)(void), void (*)(u_int), void (*)(int));
#ifdef DIAGNOSTIC
/*