summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2004-01-28 23:50:20 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2004-01-28 23:50:20 +0000
commit72f4f57ba7a1995800771745b3ea06271cd0b8f5 (patch)
tree696a8a6096628fba20fa6a1673abe0cff44b81ac
parent8c40da6ce09705ba6c14afaae59329b7701bc8f4 (diff)
More clock handling cleanup:
- move clock callbacks outside the firmware structure - map the clock virtual. A bit tricky because it needs to be mapped before autoconf... - compensate for the removal of 1:1 segment 8 mapping
-rw-r--r--sys/arch/mvmeppc/dev/clock.c28
-rw-r--r--sys/arch/mvmeppc/dev/nvramreg.h11
-rw-r--r--sys/arch/mvmeppc/include/cpu.h3
-rw-r--r--sys/arch/mvmeppc/include/powerpc.h65
-rw-r--r--sys/arch/mvmeppc/mvmeppc/machdep.c50
-rw-r--r--sys/arch/mvmeppc/mvmeppc/ppc1_machdep.c75
-rw-r--r--sys/arch/mvmeppc/pci/mpcpcibr.c60
7 files changed, 123 insertions, 169 deletions
diff --git a/sys/arch/mvmeppc/dev/clock.c b/sys/arch/mvmeppc/dev/clock.c
index 1e569a49696..8cc39d5bffa 100644
--- a/sys/arch/mvmeppc/dev/clock.c
+++ b/sys/arch/mvmeppc/dev/clock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clock.c,v 1.7 2004/01/26 22:55:52 miod Exp $ */
+/* $OpenBSD: clock.c,v 1.8 2004/01/28 23:50:16 miod Exp $ */
/* $NetBSD: clock.c,v 1.1 1996/09/30 16:34:40 ws Exp $ */
/*
@@ -63,6 +63,12 @@ static volatile u_long lasttb;
#define LEAPYEAR(y) (((y) & 3) == 0)
#define YEAR0 1900
+tps_t *tps;
+clock_read_t *clock_read;
+clock_write_t *clock_write;
+time_read_t *time_read;
+time_write_t *time_write;
+
static u_int32_t chiptotime(int, int, int, int, int, int);
/* event tracking variables, when the next event of each time should occur */
@@ -113,12 +119,12 @@ inittodr(time_t base)
badbase = 1;
}
- if (fw->clock_read != NULL ) {
- (fw->clock_read)( &sec, &min, &hour, &day, &mon, &year);
+ if (clock_read != NULL ) {
+ (*clock_read)( &sec, &min, &hour, &day, &mon, &year);
time.tv_sec = chiptotime(sec, min, hour, day, mon, year);
- } else if (fw->time_read != NULL) {
- u_long cursec;
- (fw->time_read)(&cursec);
+ } else if (time_read != NULL) {
+ u_int32_t cursec;
+ (*time_read)(&cursec);
time.tv_sec = cursec;
} else {
/* force failure */
@@ -246,16 +252,16 @@ void
resettodr()
{
struct timeval curtime = time;
- if (fw->clock_write != NULL) {
+ if (clock_write != NULL) {
struct chiptime c;
timetochip(&c);
- (fw->clock_write)(c.sec, c.min, c.hour, c.day, c.mon, c.year);
- } else if (fw->time_write != NULL) {
+ (*clock_write)(c.sec, c.min, c.hour, c.day, c.mon, c.year);
+ } else if (time_write != NULL) {
curtime.tv_sec -= tz.tz_minuteswest * 60;
if (tz.tz_dsttime) {
curtime.tv_sec += 3600;
}
- (fw->time_write)(curtime.tv_sec);
+ (*time_write)(curtime.tv_sec);
}
}
@@ -398,7 +404,7 @@ calc_delayconst(void)
{
int s;
- ticks_per_sec = ppc_tps();
+ ticks_per_sec = (*tps)();
s = ppc_intr_disable();
ns_per_tick = 1000000000 / ticks_per_sec;
ticks_per_intr = ticks_per_sec / hz;
diff --git a/sys/arch/mvmeppc/dev/nvramreg.h b/sys/arch/mvmeppc/dev/nvramreg.h
index 0ea3e1873e1..86769c4f801 100644
--- a/sys/arch/mvmeppc/dev/nvramreg.h
+++ b/sys/arch/mvmeppc/dev/nvramreg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: nvramreg.h,v 1.2 2003/06/02 23:27:53 millert Exp $ */
+/* $OpenBSD: nvramreg.h,v 1.3 2004/01/28 23:50:17 miod Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -59,9 +59,12 @@
* 1ff8-1fff TOD clock
*/
-#define NVRAM_S0 0x80000074
-#define NVRAM_S1 0x80000075
-#define NVRAM_DATA 0x80000077
+#define NVRAM_PA 0x80000000
+#define NVRAM_SIZE 0x2000
+
+#define NVRAM_S0 0x00000074
+#define NVRAM_S1 0x00000075
+#define NVRAM_DATA 0x00000077
#define RTC_SECONDS 0x1FF9
#define RTC_MINUTES 0x1FFA
diff --git a/sys/arch/mvmeppc/include/cpu.h b/sys/arch/mvmeppc/include/cpu.h
index 81320fba161..c2c4cfe5bbd 100644
--- a/sys/arch/mvmeppc/include/cpu.h
+++ b/sys/arch/mvmeppc/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.6 2004/01/25 21:41:28 miod Exp $ */
+/* $OpenBSD: cpu.h,v 1.7 2004/01/28 23:50:18 miod Exp $ */
/* $NetBSD: cpu.h,v 1.1 1996/09/30 16:34:21 ws Exp $ */
/*
@@ -37,5 +37,6 @@
#include <powerpc/cpu.h>
void install_extint(void (*)(void));
+void nvram_map(void);
#endif /* _MACHINE_CPU_H_ */
diff --git a/sys/arch/mvmeppc/include/powerpc.h b/sys/arch/mvmeppc/include/powerpc.h
index 1b5bd13abbd..4b13a038867 100644
--- a/sys/arch/mvmeppc/include/powerpc.h
+++ b/sys/arch/mvmeppc/include/powerpc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: powerpc.h,v 1.3 2004/01/22 20:45:18 miod Exp $ */
+/* $OpenBSD: powerpc.h,v 1.4 2004/01/28 23:50:18 miod Exp $ */
/* $NetBSD: powerpc.h,v 1.1 1996/09/30 16:34:30 ws Exp $ */
/*
@@ -49,21 +49,10 @@ void mem_regions(struct mem_region **, struct mem_region **);
typedef void (exit_f)(void) /*__attribute__((__noreturn__))*/ ;
typedef void (boot_f)(char *bootspec) /* __attribute__((__noreturn__))*/ ;
typedef void (vmon_f)(void);
-typedef unsigned char (nvram_rd_f)(unsigned long offset);
-typedef void (nvram_wr_f)(unsigned long offset, unsigned char val);
-typedef unsigned long (tps_f)(void);
-
typedef void (mem_regions_f)(struct mem_region **memp,
struct mem_region **availp);
-typedef int (clock_read_f)(int *sec, int *min, int *hour, int *day,
- int *mon, int *yr);
-typedef int (clock_write_f)(int sec, int min, int hour, int day,
- int mon, int yr);
-typedef int (time_read_f)(u_long *sec);
-typedef int (time_write_f)(u_long sec);
-
/* firmware interface.
* regardless of type of firmware used several items
* are need from firmware to boot up.
@@ -81,51 +70,27 @@ struct firmware {
exit_f *exit;
boot_f *boot;
vmon_f *vmon;
- nvram_rd_f *nvram_rd;
- nvram_wr_f *nvram_wr;
- tps_f *tps;
- clock_read_f *clock_read;
- clock_write_f *clock_write;
- time_read_f *time_read;
- time_write_f *time_write;
+
#ifdef FW_HAS_PUTC
boot_f *putc;
#endif
};
extern struct firmware *fw;
-#define ppc_exit() if (fw->exit != NULL) (fw->exit)()
-#define ppc_boot(x) if (fw->boot != NULL) (fw->boot)(x)
-#define ppc_nvram_rd(a) ({unsigned char val; \
- if (fw->nvram_rd !=NULL) \
- val = (fw->nvram_rd)(a); \
- else \
- val = 0; \
- val;})
-
-#define ppc_nvram_wr(a, v) if (fw->nvram_wr !=NULL) (fw->nvram_wr)(a, v)
-
-#define ppc_tps() ({unsigned long val; \
- if (fw->tps != NULL) \
- val = (fw->tps)(); \
- else \
- val = 0; \
- val;})
+/* Clock callbacks */
-#define SPR_XER "1"
-#define SPR_LR "8"
-#define SPR_CTR "9"
-#define SPR_DSISR "18"
-#define SPR_DAR "19"
-#define SPR_DEC "22"
-#define SPR_SDR1 "25"
-#define SPR_SRR0 "26"
-#define SPR_SRR1 "27"
+typedef unsigned long (tps_t)(void);
+typedef int (clock_read_t)(int *sec, int *min, int *hour, int *day,
+ int *mon, int *yr);
+typedef int (clock_write_t)(int sec, int min, int hour, int day,
+ int mon, int yr);
+typedef int (time_read_t)(u_int32_t *sec);
+typedef int (time_write_t)(u_int32_t sec);
-#define ppc_get_spr(reg) ({u_int32_t val; \
- __asm__ volatile("mfspr %0," reg : "=r"(val)); \
- val;})
-#define ppc_set_spr(reg, val) ({ \
- __asm__ volatile("mtspr " reg ",%0" :: "r"(val));})
+extern tps_t *tps;
+extern clock_read_t *clock_read;
+extern clock_write_t *clock_write;
+extern time_read_t *time_read;
+extern time_write_t *time_write;
#endif /* _MACHINE_POWERPC_H_ */
diff --git a/sys/arch/mvmeppc/mvmeppc/machdep.c b/sys/arch/mvmeppc/mvmeppc/machdep.c
index c9a96af4525..840cb13c010 100644
--- a/sys/arch/mvmeppc/mvmeppc/machdep.c
+++ b/sys/arch/mvmeppc/mvmeppc/machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: machdep.c,v 1.42 2004/01/26 22:58:15 miod Exp $ */
+/* $OpenBSD: machdep.c,v 1.43 2004/01/28 23:50:19 miod Exp $ */
/* $NetBSD: machdep.c,v 1.4 1996/10/16 19:33:11 ws Exp $ */
/*
@@ -136,7 +136,7 @@ struct bat battable[16];
struct vm_map *exec_map = NULL;
struct vm_map *phys_map = NULL;
-int ppc_malloc_ok = 0;
+int ppc_malloc_ok;
#ifndef SYS_TYPE
/* XXX Hardwire it for now */
@@ -162,10 +162,6 @@ static long devio_ex_storage[EXTENT_FIXED_STORAGE_SIZE(8) / sizeof (long)];
struct extent *devio_ex;
static int devio_malloc_safe = 0;
-/* HACK - XXX */
-int segment8_mapped = 1;
-int segmentC_mapped = 0;
-
void
initppc(startkernel, endkernel, args)
u_int startkernel, endkernel;
@@ -217,8 +213,6 @@ initppc(startkernel, endkernel, args)
*/
battable[0].batl = BATL(0x00000000, BAT_M);
battable[0].batu = BATU(0x00000000);
- battable[8].batl = BATL(0x80000000, BAT_I);
- battable[8].batu = BATU(0x80000000);
/*
* Now setup fixed bat registers
@@ -234,10 +228,6 @@ initppc(startkernel, endkernel, args)
ppc_mtdbat0l(battable[0].batl);
ppc_mtdbat0u(battable[0].batu);
- /* DBAT2 used for ISA space */
- ppc_mtdbat2l(battable[8].batl);
- ppc_mtdbat2u(battable[8].batu);
-
/*
* Set up trap vectors
*/
@@ -513,6 +503,7 @@ cpu_startup()
phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
VM_PHYS_SIZE, 0, FALSE, NULL);
ppc_malloc_ok = 1;
+ devio_malloc_safe = 1;
printf("avail mem = %ld (%ldK)\n", ptoa(uvmexp.free),
ptoa(uvmexp.free) / 1024);
@@ -524,8 +515,11 @@ cpu_startup()
*/
bufinit();
+ /*
+ * Set up early mappings
+ */
+ nvram_map();
prep_bus_space_init();
- devio_malloc_safe = 1;
}
@@ -801,21 +795,20 @@ boot(howto)
if (howto & RB_HALT) {
doshutdownhooks();
printf("halted\n\n");
- ppc_exit();
+ (fw->exit)();
}
if (!cold && (howto & RB_DUMP))
dumpsys();
doshutdownhooks();
printf("rebooting\n\n");
- ppc_boot(str);
- while(1) /* forever */;
+ (fw->boot)(str);
+ for (;;) ; /* spinning */
}
/*
* Get Ethernet address for the onboard ethernet chip.
*/
-void mvmeprom_brdid(struct mvmeprom_brdid *);
void
myetheraddr(cp)
u_char *cp;
@@ -1047,21 +1040,26 @@ mapiodev(pa, len)
spa = trunc_page(pa);
off = pa - spa;
size = round_page(off+len);
- if ((pa >= 0x80000000) && ((pa+len) < 0x90000000)) {
- if (segment8_mapped) {
- return (void *)pa;
+
+ if (ppc_malloc_ok == 0) {
+ /* need to steal vm space before kernel vm is initialized */
+ va = VM_MIN_KERNEL_ADDRESS + ppc_kvm_stolen;
+ ppc_kvm_stolen += size;
+ if (ppc_kvm_stolen > SEGMENT_LENGTH) {
+ panic("ppc_kvm_stolen: out of space");
}
+ } else {
+ va = uvm_km_valloc_wait(phys_map, size);
}
- va = vaddr = uvm_km_valloc_wait(phys_map, size);
if (va == 0)
return NULL;
- for (; size > 0; size -= NBPG) {
+ for (vaddr = va; size > 0; size -= PAGE_SIZE) {
pmap_kenter_cache(vaddr, spa,
VM_PROT_READ | VM_PROT_WRITE, PMAP_CACHE_DEFAULT);
- spa += NBPG;
- vaddr += NBPG;
+ spa += PAGE_SIZE;
+ vaddr += PAGE_SIZE;
}
return (void *) (va+off);
}
@@ -1080,8 +1078,8 @@ unmapiodev(kva, p_size)
uvm_km_free_wakeup(phys_map, vaddr, size);
for (; size > 0; size -= NBPG) {
- pmap_remove(pmap_kernel(), vaddr, vaddr+NBPG-1);
- vaddr += NBPG;
+ pmap_remove(pmap_kernel(), vaddr, vaddr+PAGE_SIZE-1);
+ vaddr += PAGE_SIZE;
}
pmap_update(pmap_kernel());
}
diff --git a/sys/arch/mvmeppc/mvmeppc/ppc1_machdep.c b/sys/arch/mvmeppc/mvmeppc/ppc1_machdep.c
index 6e269638681..c7f99ab36b6 100644
--- a/sys/arch/mvmeppc/mvmeppc/ppc1_machdep.c
+++ b/sys/arch/mvmeppc/mvmeppc/ppc1_machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ppc1_machdep.c,v 1.12 2004/01/26 20:38:53 miod Exp $ */
+/* $OpenBSD: ppc1_machdep.c,v 1.13 2004/01/28 23:50:19 miod Exp $ */
/* $NetBSD: ofw_machdep.c,v 1.1 1996/09/30 16:34:50 ws Exp $ */
/*
@@ -32,15 +32,8 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/param.h>
-#include <sys/buf.h>
#include <sys/conf.h>
-#include <sys/device.h>
-#include <sys/disk.h>
-#include <sys/disklabel.h>
-#include <sys/fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/malloc.h>
-#include <sys/stat.h>
+#include <sys/extent.h>
#include <sys/systm.h>
#include <uvm/uvm_extern.h>
@@ -60,10 +53,8 @@ unsigned char PPC1_nvram_rd(unsigned long offset);
void PPC1_nvram_wr(unsigned long offset, unsigned char val);
unsigned long PPC1_tps(void);
-int PPC1_clock_read(int *sec, int *min, int *hour, int *day,
- int *mon, int *yr);
-int PPC1_clock_write(int sec, int min, int hour, int day,
- int mon, int yr);
+int PPC1_clock_read(int *sec, int *min, int *hour, int *day, int *mon, int *yr);
+int PPC1_clock_write(int sec, int min, int hour, int day, int mon, int yr);
vm_offset_t size_memory(void);
@@ -72,15 +63,8 @@ struct firmware ppc1_firmware = {
PPC1_exit,
PPC1_boot,
PPC1_vmon,
- PPC1_nvram_rd,
- PPC1_nvram_wr,
- PPC1_tps,
- PPC1_clock_read,
- PPC1_clock_write,
- NULL,
- NULL,
#ifdef FW_HAS_PUTC
- mvmeprom_outchar;
+ mvmeprom_outchar,
#endif
};
@@ -193,15 +177,22 @@ PPC1_mem_regions(memp, availp)
void
PPC1_vmon()
{
+ /*
+ * Now is a good time to setup the clock callbacks, though this
+ * could have been done earlier...
+ */
+ clock_read = PPC1_clock_read;
+ clock_write = PPC1_clock_write;
+ tps = PPC1_tps;
}
void
PPC1_exit()
{
mvmeprom_return();
- panic("PPC1_exit returned!"); /* just in case */
for (;;) ;
}
+
void
PPC1_boot(bootspec)
char *bootspec;
@@ -225,13 +216,37 @@ PPC1_boot(bootspec)
for (;;) ;
}
+/*
+ * Clock and NVRAM functions
+ *
+ * This needs to become a real device, but it needs to be mapped early
+ * because we need to setup the clocks before autoconf.
+ */
+
+vaddr_t nvram_va;
+
+void
+nvram_map()
+{
+ int error;
+ extern struct extent *devio_ex;
+ extern int ppc_malloc_ok;
+
+ if ((error = extent_alloc_region(devio_ex, NVRAM_PA, NVRAM_SIZE,
+ EX_NOWAIT | (ppc_malloc_ok ? EX_MALLOCOK : 0))) != 0)
+ panic("nvram_map: can't map NVRAM, extent error %d", error);
+
+ if ((nvram_va = (vaddr_t)mapiodev(NVRAM_PA, NVRAM_SIZE)) == NULL)
+ panic("nvram_map: map failed");
+}
+
unsigned char
PPC1_nvram_rd(addr)
unsigned long addr;
{
- outb(NVRAM_S0, addr);
- outb(NVRAM_S1, addr>>8);
- return inb(NVRAM_DATA);
+ outb(nvram_va + NVRAM_S0, addr);
+ outb(nvram_va + NVRAM_S1, addr>>8);
+ return inb(nvram_va + NVRAM_DATA);
}
void
@@ -239,9 +254,9 @@ PPC1_nvram_wr(addr, val)
unsigned long addr;
unsigned char val;
{
- outb(NVRAM_S0, addr);
- outb(NVRAM_S1, addr>>8);
- outb(NVRAM_DATA, val);
+ outb(nvram_va + NVRAM_S0, addr);
+ outb(nvram_va + NVRAM_S1, addr>>8);
+ outb(nvram_va + NVRAM_DATA, val);
}
/* Function to get ticks per second. */
@@ -264,7 +279,7 @@ PPC1_tps()
break;
}
- start_val = ppc_get_spr(SPR_DEC);
+ start_val = ppc_mfdec();
/* wait until it changes. */
sec = PPC1_nvram_rd(RTC_SECONDS);
@@ -272,7 +287,7 @@ PPC1_tps()
if (PPC1_nvram_rd(RTC_SECONDS) != sec)
break;
}
- ticks = start_val - ppc_get_spr(SPR_DEC);
+ ticks = start_val - ppc_mfdec();
return (ticks);
}
diff --git a/sys/arch/mvmeppc/pci/mpcpcibr.c b/sys/arch/mvmeppc/pci/mpcpcibr.c
index 60af47188c8..8e8af4e8589 100644
--- a/sys/arch/mvmeppc/pci/mpcpcibr.c
+++ b/sys/arch/mvmeppc/pci/mpcpcibr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mpcpcibr.c,v 1.12 2003/12/20 22:40:27 miod Exp $ */
+/* $OpenBSD: mpcpcibr.c,v 1.13 2004/01/28 23:50:19 miod Exp $ */
/*
* Copyright (c) 2001 Steve Murphree, Jr.
@@ -59,7 +59,7 @@ int mpcpcibrmatch(struct device *, void *, void *);
void mpcpcibrattach(struct device *, struct device *, void *);
void mpc_attach_hook(struct device *, struct device *,
- struct pcibus_attach_args *);
+ struct pcibus_attach_args *);
int mpc_bus_maxdevs(void *, int);
pcitag_t mpc_make_tag(void *, int, int, int);
void mpc_decompose_tag(void *, pcitag_t, int *, int *, int *);
@@ -139,7 +139,6 @@ mpcpcibrmatch(parent, match, aux)
return 1;
}
-int pci_map_a = 0;
void
mpcpcibrattach(parent, self, aux)
struct device *parent, *self;
@@ -251,48 +250,20 @@ mpcpcibrprint(aux, pnp)
* Get PCI physical address from given virtual address.
* XXX Note that cross page boundaries are *not* guaranteed to work!
*/
-#if 0
-vm_offset_t
-vtophys(p)
-vaddr_t p;
+paddr_t
+vtophys(paddr_t pa)
{
- vm_offset_t pa;
- vm_offset_t va;
+ vaddr_t va = (vaddr_t) pa;
- va = (vm_offset_t)p;
- if ((vm_offset_t)va < VM_MIN_KERNEL_ADDRESS) {
- pa = va;
- } else {
- pmap_extract(vm_map_pmap(phys_map), va, (paddr_t *)&pa);
+ if (va < VM_MIN_KERNEL_ADDRESS)
+ return pa;
+ else {
+ if (pmap_extract(pmap_kernel(), va, &pa))
+ return pa;
}
- return (pa | ((pci_map_a == 1) ? RAVEN_PCI_CPUMEM : 0 ));
-}
-#else
-vm_offset_t
-vtophys(p)
-vaddr_t p;
-{
- vm_offset_t pa;
- vm_offset_t va;
- extern int segment8_mapped;
- extern int segmentC_mapped;
-
- va = (vm_offset_t)p;
- /* This crap gets maped by bats 1:1 */
- if (segment8_mapped && (va >= 0x80000000 && va < 0x90000000)) {
- pa = va;
- } else if (segmentC_mapped && (va >= 0xC0000000 && va < 0xD0000000)) {
- pa = va;
- } else if (va >= 0xF0000000) {
- pa = va;
- } else if ((vm_offset_t)va < VM_MIN_KERNEL_ADDRESS) {
- pa = va;
- } else if (pmap_extract(pmap_kernel(), va, &pa))
- return pa;
- return va;
+ return NULL;
}
-#endif
void
mpc_attach_hook(parent, self, pba)
@@ -353,11 +324,6 @@ mpc_gen_config_reg(cpv, tag, offset)
struct pcibr_config *cp = cpv;
unsigned int bus, dev, fcn;
u_int32_t reg;
- /*
- static int spin = 0;
- while (spin > 85);
- spin++;
- */
mpc_decompose_tag(cpv, tag, &bus, &dev, &fcn);
@@ -532,8 +498,8 @@ mpc_intr_line(lcv, ih)
return (ih);
}
-typedef void *(intr_establish_t)(void *, pci_intr_handle_t,
- int, int, int (*func)(void *), void *, char *);
+typedef void *(intr_establish_t)(void *, pci_intr_handle_t, int, int,
+ int (*func)(void *), void *, char *);
typedef void (intr_disestablish_t)(void *, void *);
extern intr_establish_t *intr_establish_func;
extern intr_disestablish_t *intr_disestablish_func;