Module Name: src Committed By: skrll Date: Fri Apr 23 15:04:09 UTC 2010
Modified Files: src/sys/arch/hp700/hp700: mainbus.c src/sys/arch/hp700/include: iomod.h Log Message: Don't round the bus space map/unmap requests to page size, but keep track of the exact regions requested. Only ever map the whole FLEX area in when mapped and don't unmap. G/C the BTLB stuff - it doesn't work. Maybe one day it will come back. To generate a diff of this commit: cvs rdiff -u -r1.66 -r1.67 src/sys/arch/hp700/hp700/mainbus.c cvs rdiff -u -r1.7 -r1.8 src/sys/arch/hp700/include/iomod.h 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/hp700/hp700/mainbus.c diff -u src/sys/arch/hp700/hp700/mainbus.c:1.66 src/sys/arch/hp700/hp700/mainbus.c:1.67 --- src/sys/arch/hp700/hp700/mainbus.c:1.66 Thu Apr 15 14:34:25 2010 +++ src/sys/arch/hp700/hp700/mainbus.c Fri Apr 23 15:04:09 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: mainbus.c,v 1.66 2010/04/15 14:34:25 skrll Exp $ */ +/* $NetBSD: mainbus.c,v 1.67 2010/04/23 15:04:09 skrll Exp $ */ /*- * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -/* $OpenBSD: mainbus.c,v 1.13 2001/09/19 20:50:56 mickey Exp $ */ +/* $OpenBSD: mainbus.c,v 1.74 2009/04/20 00:42:06 oga Exp $ */ /* * Copyright (c) 1998-2004 Michael Shalayeff @@ -58,7 +58,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.66 2010/04/15 14:34:25 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.67 2010/04/23 15:04:09 skrll Exp $"); #include "locators.h" #include "power.h" @@ -152,7 +152,6 @@ void mbus_cp_8(void *, bus_space_handle_t, bus_size_t, bus_space_handle_t, bus_size_t, bus_size_t); int mbus_add_mapping(bus_addr_t, bus_size_t, int, bus_space_handle_t *); -int mbus_remove_mapping(bus_space_handle_t, bus_size_t, bus_addr_t *); int mbus_map(void *, bus_addr_t, bus_size_t, int, bus_space_handle_t *); void mbus_unmap(void *, bus_space_handle_t, bus_size_t); int mbus_alloc(void *, bus_addr_t, bus_addr_t, bus_size_t, bus_size_t, bus_size_t, int, bus_addr_t *, bus_space_handle_t *); @@ -179,134 +178,56 @@ bus_size_t buflen, struct vmspace *vm, int flags, paddr_t *lastaddrp, int *segp, int first); +extern struct pdc_btlb pdc_btlb; +static uint32_t bmm[HPPA_FLEX_COUNT/32]; + int mbus_add_mapping(bus_addr_t bpa, bus_size_t size, int flags, bus_space_handle_t *bshp) { - u_int frames; -#ifdef USE_BTLB - vsize_t btlb_size; - int error; -#endif /* USE_BTLB */ + vaddr_t pa, spa, epa; + int flex; DPRINTF(("\n%s(%lx,%lx,%scachable,%p)\n", __func__, bpa, size, flags? "" : "non", bshp)); - /* - * We must be called with a page-aligned address in - * I/O space, and with a multiple of the page size. - */ - KASSERT((bpa & PGOFSET) == 0); KASSERT(bpa >= HPPA_IOSPACE); - KASSERT((size & PGOFSET) == 0); + KASSERT(!(flags & BUS_SPACE_MAP_CACHEABLE)); /* - * Assume that this will succeed. + * Mappings are established in HPPA_FLEX_SIZE units, + * either with BTLB, or regular mappings of the whole area. */ - *bshp = bpa; + for (pa = bpa ; size != 0; pa = epa) { + flex = HPPA_FLEX(pa); + spa = pa & HPPA_FLEX_MASK; + epa = spa + HPPA_FLEX_SIZE; /* may wrap to 0... */ - /* - * Loop while there is space left to map. - */ - frames = size >> PGSHIFT; - while (frames > 0) { + size -= min(size, HPPA_FLEX_SIZE - (pa - spa)); - /* - * If this mapping is more than eight pages long, - * try to add a BTLB entry. - */ -#ifdef USE_BTLB - if (frames > 8 && - frames >= hppa_btlb_size_min) { - btlb_size = frames; - if (btlb_size > hppa_btlb_size_max) - btlb_size = hppa_btlb_size_max; - btlb_size <<= PGSHIFT; - error = hppa_btlb_insert(pmap_kernel()->pmap_space, - bpa, bpa, &btlb_size, - pmap_kernel()->pmap_pid | - pmap_prot(pmap_kernel(), VM_PROT_READ | VM_PROT_WRITE)); - if (error == 0) { - bpa += btlb_size; - frames -= (btlb_size >> PGSHIFT); - continue; - } - else if (error != ENOMEM) - return error; + /* do need a new mapping? */ + if (bmm[flex / 32] & (1 << (flex % 32))) { + DPRINTF(("%s: already mapped flex=%x, mask=%x\n", + __func__, flex, bmm[flex / 32])); + continue; } -#endif /* USE_BTLB */ - - /* - * Enter another single-page mapping. - */ - pmap_kenter_pa(bpa, bpa, VM_PROT_READ | VM_PROT_WRITE, 0); - bpa += PAGE_SIZE; - frames--; - } - - /* Success. */ - return 0; -} - -/* - * This removes a mapping added by mbus_add_mapping. - */ -int -mbus_remove_mapping(bus_space_handle_t bsh, bus_size_t size, bus_addr_t *bpap) -{ - bus_addr_t bpa; - u_int frames; -#ifdef USE_BTLB - vsize_t btlb_size; - int error; -#endif /* USE_BTLB */ - /* - * We must be called with a page-aligned address in - * I/O space, and with a multiple of the page size. - */ - bpa = *bpap = bsh; - KASSERT((bpa & PGOFSET) == 0); - KASSERT(bpa >= HPPA_IOSPACE); - KASSERT((size & PGOFSET) == 0); + DPRINTF(("%s: adding flex=%x %lx-%lx, ", __func__, flex, spa, + epa - 1)); - /* - * Loop while there is space left to unmap. - */ - frames = size >> PGSHIFT; - while (frames > 0) { + bmm[flex / 32] |= (1 << (flex % 32)); - /* - * If this mapping is more than eight pages long, - * try to remove a BTLB entry. - */ -#ifdef USE_BTLB - if (frames > 8 && - frames >= hppa_btlb_size_min) { - btlb_size = frames; - if (btlb_size > hppa_btlb_size_max) - btlb_size = hppa_btlb_size_max; - btlb_size <<= PGSHIFT; - error = hppa_btlb_purge(pmap_kernel()->pmap_space, - bpa, &btlb_size); - if (error == 0) { - bpa += btlb_size; - frames -= (btlb_size >> PGSHIFT); - continue; - } - else if (error != ENOENT) - return error; + while (spa != epa) { + DPRINTF(("%s: kenter 0x%lx-0x%lx", __func__, spa, + epa)); + for (; spa != epa; spa += PAGE_SIZE) + pmap_kenter_pa(spa, spa, + VM_PROT_READ | VM_PROT_WRITE, 0); } -#endif /* USE_BTLB */ - - /* - * Remove another single-page mapping. - */ - pmap_kremove(bpa, PAGE_SIZE); - bpa += PAGE_SIZE; - frames--; } + *bshp = bpa; + /* Success. */ return 0; } @@ -316,7 +237,6 @@ bus_space_handle_t *bshp) { int error; - bus_size_t offset; /* * We must only be called with addresses in I/O space. @@ -324,14 +244,6 @@ KASSERT(bpa >= HPPA_IOSPACE); /* - * Page-align the I/O address and size. - */ - offset = (bpa & PGOFSET); - bpa -= offset; - size += offset; - size = round_page(size); - - /* * Allocate the region of I/O space. */ error = extent_alloc_region(hp700_io_extent, bpa, size, EX_NOWAIT); @@ -342,7 +254,6 @@ * Map the region of I/O space. */ error = mbus_add_mapping(bpa, size, flags, bshp); - *bshp |= offset; if (error) { DPRINTF(("bus_space_map: pa 0x%lx, size 0x%lx failed\n", bpa, size)); @@ -357,26 +268,10 @@ void mbus_unmap(void *v, bus_space_handle_t bsh, bus_size_t size) { - bus_size_t offset; - bus_addr_t bpa; + bus_addr_t bpa = bsh; int error; /* - * Page-align the bus_space handle and size. - */ - offset = bsh & PGOFSET; - bsh -= offset; - size += offset; - size = round_page(size); - - /* - * Unmap the region of I/O space. - */ - error = mbus_remove_mapping(bsh, size, &bpa); - if (error) - panic("mbus_unmap: can't unmap region (%d)", error); - - /* * Free the region of I/O space. */ error = extent_free(hp700_io_extent, bpa, size, EX_NOWAIT); @@ -400,13 +295,6 @@ panic("bus_space_alloc: bad region start/end"); /* - * Force the allocated region to be page-aligned. - */ - if (align < PAGE_SIZE) - align = PAGE_SIZE; - size = round_page(size); - - /* * Allocate the region of I/O space. */ error = extent_alloc_subregion1(hp700_io_extent, rstart, rend, size, Index: src/sys/arch/hp700/include/iomod.h diff -u src/sys/arch/hp700/include/iomod.h:1.7 src/sys/arch/hp700/include/iomod.h:1.8 --- src/sys/arch/hp700/include/iomod.h:1.7 Wed Aug 12 20:10:41 2009 +++ src/sys/arch/hp700/include/iomod.h Fri Apr 23 15:04:09 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: iomod.h,v 1.7 2009/08/12 20:10:41 skrll Exp $ */ +/* $NetBSD: iomod.h,v 1.8 2010/04/23 15:04:09 skrll Exp $ */ /* $OpenBSD: iomod.h,v 1.18 2007/10/20 16:41:45 miod Exp $ */ @@ -123,6 +123,7 @@ #define FPA_IOMOD ((FPA_HIGH-FPA_LOW)/sizeof(struct iomod)) #define MAXMODBUS ((int)(FPA_IOMOD)) /* maximum modules/bus */ +#define HPPA_FLEX_COUNT 0x4000 /* number of "flex" blocks */ #define HPPA_FLEX_MASK 0xFFFC0000 /* (see below) */ #define HPPA_FLEX_SIZE (~HPPA_FLEX_MASK + 1) #define HPPA_FLEX(a) (((a) & HPPA_FLEX_MASK) >> 18)