From 43fd4d987ed052b13dc10e242705c0d862e4b6dd Mon Sep 17 00:00:00 2001 From: Miod Vallat Date: Tue, 9 Nov 2004 15:02:24 +0000 Subject: Luna88k does not have an iomap, so kill all iomap related defines, and move the mapiodev()/unmapiodev() code back to mvme88k. --- sys/arch/mvme88k/dev/mainbus.c | 91 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 86 insertions(+), 5 deletions(-) (limited to 'sys/arch/mvme88k/dev') diff --git a/sys/arch/mvme88k/dev/mainbus.c b/sys/arch/mvme88k/dev/mainbus.c index a394254f76d..bc82805a4ce 100644 --- a/sys/arch/mvme88k/dev/mainbus.c +++ b/sys/arch/mvme88k/dev/mainbus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mainbus.c,v 1.13 2004/08/02 08:35:00 miod Exp $ */ +/* $OpenBSD: mainbus.c,v 1.14 2004/11/09 15:02:23 miod Exp $ */ /* * Copyright (c) 1998 Steve Murphree, Jr. * Copyright (c) 2004, Miodrag Vallat. @@ -31,11 +31,15 @@ #include #include #include +#include + +#include #include #include #include #include +#include #ifdef MVME188 #include @@ -66,6 +70,12 @@ const struct mvme88k_bus_space_tag mainbus_bustag = { mainbus_vaddr }; +extern struct extent *iomap_extent; +extern struct vm_map *iomap_map; + +void *mapiodev(void *, int); +void unmapiodev(void *, int); + /* * Obio (internal IO) space is mapped 1:1 (see pmap_bootstrap() for details). * @@ -103,11 +113,7 @@ mainbus_map(bus_addr_t addr, bus_size_t size, int flags, if (addr >= threshold) map = (vaddr_t)addr; else { -#if 0 - map = iomap_mapin(addr, size, 0); -#else map = (vaddr_t)mapiodev((void *)addr, size); -#endif } if (map == NULL) @@ -137,6 +143,81 @@ mainbus_vaddr(bus_space_handle_t handle) return (void *)handle; } +/* + * Map a range [pa, pa+size] in the given map to a kernel address + * in iomap space. + * + * Note: To be flexible, I did not put a restriction on the alignment + * of pa. However, it is advisable to have pa page aligned since otherwise, + * we might have several mappings for a given chunk of the IO page. + */ +void * +mapiodev(pa, size) + void *pa; + int size; +{ + vaddr_t iova, tva, off; + paddr_t ppa; + int s, error; + + if (size <= 0) + return NULL; + + ppa = trunc_page((paddr_t)pa); + off = (paddr_t)pa & PGOFSET; + size = round_page(off + size); + + s = splhigh(); + error = extent_alloc(iomap_extent, size, PAGE_SIZE, 0, EX_NOBOUNDARY, + EX_WAITSPACE, &iova); + splx(s); + + if (error != 0) + return NULL; + + cmmu_flush_tlb(cpu_number(), 1, iova, size); /* necessary? */ + + tva = iova; + while (size != 0) { + pmap_enter(vm_map_pmap(iomap_map), tva, ppa, + VM_PROT_WRITE | VM_PROT_READ, + VM_PROT_WRITE | VM_PROT_READ | PMAP_WIRED); + size -= PAGE_SIZE; + tva += PAGE_SIZE; + ppa += PAGE_SIZE; + } + pmap_update(vm_map_pmap(iomap_map)); + + return (void *)(iova + off); +} + +/* + * Free up the mapping in iomap. + */ +void +unmapiodev(va, size) + void *va; + int size; +{ + vaddr_t kva, off; + int s, error; + + off = (vaddr_t)va & PGOFSET; + kva = trunc_page((vaddr_t)va); + size = round_page(off + size); + + pmap_remove(vm_map_pmap(iomap_map), kva, kva + size); + pmap_update(vm_map_pmap(iomap_map)); + + s = splhigh(); + error = extent_free(iomap_extent, kva, size, EX_NOWAIT); +#ifdef DIAGNOSTIC + if (error != 0) + printf("unmapiodev: extent_free failed\n"); +#endif + splx(s); +} + /* * Configuration glue */ -- cgit v1.2.3