diff options
author | Patrick Wildt <patrick@cvs.openbsd.org> | 2016-12-18 22:19:37 +0000 |
---|---|---|
committer | Patrick Wildt <patrick@cvs.openbsd.org> | 2016-12-18 22:19:37 +0000 |
commit | 42969a12669ce2a3e13cf89a37e81680da668b99 (patch) | |
tree | 55b13e4aa7311f15691feb536c8871fdfba477b5 | |
parent | 49f85a0a9fc5dbc1197823b753b1714fe21c203f (diff) |
Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.
-rw-r--r-- | sys/arch/arm64/arm64/arm64_a4x_iobus.c | 135 | ||||
-rw-r--r-- | sys/arch/arm64/arm64/arm64_iobus.c | 198 | ||||
-rw-r--r-- | sys/arch/arm64/conf/files.arm64 | 3 | ||||
-rw-r--r-- | sys/arch/arm64/dev/arm64_bus_space.c | 80 |
4 files changed, 77 insertions, 339 deletions
diff --git a/sys/arch/arm64/arm64/arm64_a4x_iobus.c b/sys/arch/arm64/arm64/arm64_a4x_iobus.c deleted file mode 100644 index 8038b17bad2..00000000000 --- a/sys/arch/arm64/arm64/arm64_a4x_iobus.c +++ /dev/null @@ -1,135 +0,0 @@ -/* $OpenBSD: arm64_a4x_iobus.c,v 1.1 2016/12/17 23:38:33 patrick Exp $ */ -/* - * Copyright (c) 2000-2004 Opsycon AB (www.opsycon.se) - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ - -/* - * This is a iobus driver. - * It handles configuration of all devices on the processor bus except UART. - */ - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/kernel.h> -#include <sys/conf.h> -#include <sys/malloc.h> -#include <sys/device.h> -#include <sys/proc.h> -#include <sys/atomic.h> - -#include <machine/intr.h> -#include <machine/bus.h> -#include <uvm/uvm_extern.h> -#include <machine/pmap.h> - -#if 0 -u_int8_t iobus_read_1(bus_space_tag_t, bus_space_handle_t, bus_size_t); -u_int16_t iobus_read_2(bus_space_tag_t, bus_space_handle_t, bus_size_t); -u_int32_t iobus_read_4(bus_space_tag_t, bus_space_handle_t, bus_size_t); -u_int64_t iobus_read_8(bus_space_tag_t, bus_space_handle_t, bus_size_t); - -void iobus_write_1(bus_space_tag_t, bus_space_handle_t, bus_size_t, - u_int8_t); -void iobus_write_2(bus_space_tag_t, bus_space_handle_t, bus_size_t, - u_int16_t); -void iobus_write_4(bus_space_tag_t, bus_space_handle_t, bus_size_t, - u_int32_t); -void iobus_write_8(bus_space_tag_t, bus_space_handle_t, bus_size_t, - u_int64_t); - -void iobus_read_raw_2(bus_space_tag_t, bus_space_handle_t, bus_addr_t, - u_int8_t *, bus_size_t); -void iobus_write_raw_2(bus_space_tag_t, bus_space_handle_t, bus_addr_t, - const u_int8_t *, bus_size_t); -void iobus_read_raw_4(bus_space_tag_t, bus_space_handle_t, bus_addr_t, - u_int8_t *, bus_size_t); -void iobus_write_raw_4(bus_space_tag_t, bus_space_handle_t, bus_addr_t, - const u_int8_t *, bus_size_t); -void iobus_read_raw_8(bus_space_tag_t, bus_space_handle_t, bus_addr_t, - u_int8_t *, bus_size_t); -void iobus_write_raw_8(bus_space_tag_t, bus_space_handle_t, bus_addr_t, - const u_int8_t *, bus_size_t); - -struct cfattach iobus_ca = { - sizeof(struct device), iobusmatch, iobusattach -}; - -struct cfdriver iobus_cd = { - NULL, "iobus", DV_DULL -}; -#endif - -int iobus_space_map(bus_space_tag_t t, bus_addr_t offs, bus_size_t size, - int flags, bus_space_handle_t *bshp); -void iobus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh, - bus_size_t size); - -bus_space_t arm64_bs_tag = { - .bus_base = 0ULL, // XXX - .bus_private = NULL, - ._space_read_1 = generic_space_read_1, - ._space_write_1 = generic_space_write_1, - ._space_read_2 = generic_space_read_2, - ._space_write_2 = generic_space_write_2, - ._space_read_4 = generic_space_read_4, - ._space_write_4 = generic_space_write_4, - ._space_read_8 = generic_space_read_8, - ._space_write_8 = generic_space_write_8, - ._space_read_raw_2 = generic_space_read_raw_2, - ._space_write_raw_2 = generic_space_write_raw_2, - ._space_read_raw_4 = generic_space_read_raw_4, - ._space_write_raw_4 = generic_space_write_raw_4, - ._space_read_raw_8 = generic_space_read_raw_8, - ._space_write_raw_8 = generic_space_write_raw_8, - ._space_map = iobus_space_map, - ._space_unmap = iobus_space_unmap, - ._space_subregion = generic_space_region, - ._space_vaddr = generic_space_vaddr -}; - -bus_space_handle_t iobus_h; - -#if 0 -struct machine_bus_dma_tag iobus_bus_dma_tag = { - NULL, /* _cookie */ - _dmamap_create, - _dmamap_destroy, - _dmamap_load, - _dmamap_load_mbuf, - _dmamap_load_uio, - _dmamap_load_raw, - _dmamap_load_buffer, - _dmamap_unload, - _dmamap_sync, - _dmamem_alloc, - _dmamem_free, - _dmamem_map, - _dmamem_unmap, - _dmamem_mmap, - iobus_pa_to_device, - iobus_device_to_pa, - 0 -}; -#endif diff --git a/sys/arch/arm64/arm64/arm64_iobus.c b/sys/arch/arm64/arm64/arm64_iobus.c deleted file mode 100644 index 5f9ad2a808c..00000000000 --- a/sys/arch/arm64/arm64/arm64_iobus.c +++ /dev/null @@ -1,198 +0,0 @@ -/* $OpenBSD: arm64_iobus.c,v 1.1 2016/12/17 23:38:33 patrick Exp $ */ -/* - * Copyright (c) 2000-2004 Opsycon AB (www.opsycon.se) - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ - -/* - * This is a iobus driver. - * It handles configuration of all devices on the processor bus except UART. - */ - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/kernel.h> -#include <sys/conf.h> -#include <sys/malloc.h> -#include <sys/device.h> -#include <sys/proc.h> -#include <sys/atomic.h> - -#include <machine/intr.h> -#include <machine/bus.h> -#include <uvm/uvm_extern.h> -#include <machine/pmap.h> - -#if 0 -u_int8_t iobus_read_1(bus_space_tag_t, bus_space_handle_t, bus_size_t); -u_int16_t iobus_read_2(bus_space_tag_t, bus_space_handle_t, bus_size_t); -u_int32_t iobus_read_4(bus_space_tag_t, bus_space_handle_t, bus_size_t); -u_int64_t iobus_read_8(bus_space_tag_t, bus_space_handle_t, bus_size_t); - -void iobus_write_1(bus_space_tag_t, bus_space_handle_t, bus_size_t, - u_int8_t); -void iobus_write_2(bus_space_tag_t, bus_space_handle_t, bus_size_t, - u_int16_t); -void iobus_write_4(bus_space_tag_t, bus_space_handle_t, bus_size_t, - u_int32_t); -void iobus_write_8(bus_space_tag_t, bus_space_handle_t, bus_size_t, - u_int64_t); - -void iobus_read_raw_2(bus_space_tag_t, bus_space_handle_t, bus_addr_t, - u_int8_t *, bus_size_t); -void iobus_write_raw_2(bus_space_tag_t, bus_space_handle_t, bus_addr_t, - const u_int8_t *, bus_size_t); -void iobus_read_raw_4(bus_space_tag_t, bus_space_handle_t, bus_addr_t, - u_int8_t *, bus_size_t); -void iobus_write_raw_4(bus_space_tag_t, bus_space_handle_t, bus_addr_t, - const u_int8_t *, bus_size_t); -void iobus_read_raw_8(bus_space_tag_t, bus_space_handle_t, bus_addr_t, - u_int8_t *, bus_size_t); -void iobus_write_raw_8(bus_space_tag_t, bus_space_handle_t, bus_addr_t, - const u_int8_t *, bus_size_t); - -struct cfattach iobus_ca = { - sizeof(struct device), iobusmatch, iobusattach -}; - -struct cfdriver iobus_cd = { - NULL, "iobus", DV_DULL -}; -#endif - -int iobus_space_map(bus_space_tag_t t, bus_addr_t offs, bus_size_t size, - int flags, bus_space_handle_t *bshp); -void iobus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh, - bus_size_t size); - -bus_space_t arm64_bs_tag = { - .bus_base = 0ULL, // XXX - .bus_private = NULL, - ._space_read_1 = generic_space_read_1, - ._space_write_1 = generic_space_write_1, - ._space_read_2 = generic_space_read_2, - ._space_write_2 = generic_space_write_2, - ._space_read_4 = generic_space_read_4, - ._space_write_4 = generic_space_write_4, - ._space_read_8 = generic_space_read_8, - ._space_write_8 = generic_space_write_8, - ._space_read_raw_2 = generic_space_read_raw_2, - ._space_write_raw_2 = generic_space_write_raw_2, - ._space_read_raw_4 = generic_space_read_raw_4, - ._space_write_raw_4 = generic_space_write_raw_4, - ._space_read_raw_8 = generic_space_read_raw_8, - ._space_write_raw_8 = generic_space_write_raw_8, - ._space_map = iobus_space_map, - ._space_unmap = iobus_space_unmap, - ._space_subregion = generic_space_region, - ._space_vaddr = generic_space_vaddr -}; - -bus_space_handle_t iobus_h; - -#if 0 -struct machine_bus_dma_tag iobus_bus_dma_tag = { - NULL, /* _cookie */ - _dmamap_create, - _dmamap_destroy, - _dmamap_load, - _dmamap_load_mbuf, - _dmamap_load_uio, - _dmamap_load_raw, - _dmamap_load_buffer, - _dmamap_unload, - _dmamap_sync, - _dmamem_alloc, - _dmamem_free, - _dmamem_map, - _dmamem_unmap, - _dmamem_mmap, - iobus_pa_to_device, - iobus_device_to_pa, - 0 -}; -#endif - -int -iobus_space_map(bus_space_tag_t t, bus_addr_t bpa, bus_size_t size, - int flags, bus_space_handle_t *bshp) -{ - u_long startpa, endpa, pa; - vaddr_t va; - int cache = flags & BUS_SPACE_MAP_CACHEABLE ? - PMAP_CACHE_WB : PMAP_CACHE_CI; - - startpa = trunc_page(bpa); - endpa = round_page(bpa + size); - - va = (vaddr_t)km_alloc(endpa - startpa, &kv_any, &kp_none, &kd_nowait); - if (! va) - return(ENOMEM); - - *bshp = (bus_space_handle_t)(va + (bpa - startpa)); - - for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) { - pmap_kenter_cache(va, pa, PROT_READ | PROT_WRITE, cache); - } - pmap_update(pmap_kernel()); - - return(0); -} - -void -iobus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh, bus_size_t size) -{ - vaddr_t va, endva; - - va = trunc_page((vaddr_t)bsh); - endva = round_page((vaddr_t)bsh + size); - - pmap_kremove(va, endva - va); - pmap_update(pmap_kernel()); - km_free((void *)va, endva - va, &kv_any, &kp_none); -} - -bus_space_t arm64_a4x_bs_tag = { - .bus_base = 0ULL, // XXX - .bus_private = NULL, - ._space_read_1 = a4x_space_read_1, - ._space_write_1 = a4x_space_write_1, - ._space_read_2 = a4x_space_read_2, - ._space_write_2 = a4x_space_write_2, - ._space_read_4 = a4x_space_read_4, - ._space_write_4 = a4x_space_write_4, - ._space_read_8 = a4x_space_read_8, - ._space_write_8 = a4x_space_write_8, - ._space_read_raw_2 = a4x_space_read_raw_2, - ._space_write_raw_2 = a4x_space_write_raw_2, - ._space_read_raw_4 = a4x_space_read_raw_4, - ._space_write_raw_4 = a4x_space_write_raw_4, - ._space_read_raw_8 = a4x_space_read_raw_8, - ._space_write_raw_8 = a4x_space_write_raw_8, - ._space_map = iobus_space_map, - ._space_unmap = iobus_space_unmap, - ._space_subregion = generic_space_region, - ._space_vaddr = generic_space_vaddr -}; - diff --git a/sys/arch/arm64/conf/files.arm64 b/sys/arch/arm64/conf/files.arm64 index d03b7640744..aaac6b92f1a 100644 --- a/sys/arch/arm64/conf/files.arm64 +++ b/sys/arch/arm64/conf/files.arm64 @@ -1,4 +1,4 @@ -# $OpenBSD: files.arm64,v 1.1 2016/12/17 23:38:33 patrick Exp $ +# $OpenBSD: files.arm64,v 1.2 2016/12/18 22:19:36 patrick Exp $ maxpartitions 16 maxusers 2 8 64 @@ -33,7 +33,6 @@ file arch/arm64/arm64/arm64_mutex.c file arch/arm64/arm64/support.S file arch/arm64/arm64/bus_dma.c -file arch/arm64/arm64/arm64_iobus.c file arch/arm64/dev/arm64_bus_space.c diff --git a/sys/arch/arm64/dev/arm64_bus_space.c b/sys/arch/arm64/dev/arm64_bus_space.c index 05d5c886ce3..56848adbdc3 100644 --- a/sys/arch/arm64/dev/arm64_bus_space.c +++ b/sys/arch/arm64/dev/arm64_bus_space.c @@ -1,4 +1,4 @@ -/* $OpenBSD: arm64_bus_space.c,v 1.1 2016/12/17 23:38:33 patrick Exp $ */ +/* $OpenBSD: arm64_bus_space.c,v 1.2 2016/12/18 22:19:36 patrick Exp $ */ /* * Copyright (c) 2001-2003 Opsycon AB (www.opsycon.se / www.opsycon.com) @@ -34,6 +34,53 @@ #include <sys/systm.h> #include <machine/bus.h> +#include <uvm/uvm_extern.h> + +bus_space_t arm64_bs_tag = { + .bus_base = 0ULL, // XXX + .bus_private = NULL, + ._space_read_1 = generic_space_read_1, + ._space_write_1 = generic_space_write_1, + ._space_read_2 = generic_space_read_2, + ._space_write_2 = generic_space_write_2, + ._space_read_4 = generic_space_read_4, + ._space_write_4 = generic_space_write_4, + ._space_read_8 = generic_space_read_8, + ._space_write_8 = generic_space_write_8, + ._space_read_raw_2 = generic_space_read_raw_2, + ._space_write_raw_2 = generic_space_write_raw_2, + ._space_read_raw_4 = generic_space_read_raw_4, + ._space_write_raw_4 = generic_space_write_raw_4, + ._space_read_raw_8 = generic_space_read_raw_8, + ._space_write_raw_8 = generic_space_write_raw_8, + ._space_map = generic_space_map, + ._space_unmap = generic_space_unmap, + ._space_subregion = generic_space_region, + ._space_vaddr = generic_space_vaddr +}; + +bus_space_t arm64_a4x_bs_tag = { + .bus_base = 0ULL, // XXX + .bus_private = NULL, + ._space_read_1 = a4x_space_read_1, + ._space_write_1 = a4x_space_write_1, + ._space_read_2 = a4x_space_read_2, + ._space_write_2 = a4x_space_write_2, + ._space_read_4 = a4x_space_read_4, + ._space_write_4 = a4x_space_write_4, + ._space_read_8 = a4x_space_read_8, + ._space_write_8 = a4x_space_write_8, + ._space_read_raw_2 = a4x_space_read_raw_2, + ._space_write_raw_2 = a4x_space_write_raw_2, + ._space_read_raw_4 = a4x_space_read_raw_4, + ._space_write_raw_4 = a4x_space_write_raw_4, + ._space_read_raw_8 = a4x_space_read_raw_8, + ._space_write_raw_8 = a4x_space_write_raw_8, + ._space_map = generic_space_map, + ._space_unmap = generic_space_unmap, + ._space_subregion = generic_space_region, + ._space_vaddr = generic_space_vaddr +}; uint8_t generic_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) @@ -163,13 +210,39 @@ int generic_space_map(bus_space_tag_t t, bus_addr_t offs, bus_size_t size, int flags, bus_space_handle_t *bshp) { - *bshp = t->bus_base + offs; - return 0; + u_long startpa, endpa, pa; + vaddr_t va; + int cache = flags & BUS_SPACE_MAP_CACHEABLE ? + PMAP_CACHE_WB : PMAP_CACHE_CI; + + startpa = trunc_page(offs); + endpa = round_page(offs + size); + + va = (vaddr_t)km_alloc(endpa - startpa, &kv_any, &kp_none, &kd_nowait); + if (! va) + return(ENOMEM); + + *bshp = (bus_space_handle_t)(va + (offs - startpa)); + + for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) { + pmap_kenter_cache(va, pa, PROT_READ | PROT_WRITE, cache); + } + pmap_update(pmap_kernel()); + + return(0); } void generic_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh, bus_size_t size) { + vaddr_t va, endva; + + va = trunc_page((vaddr_t)bsh); + endva = round_page((vaddr_t)bsh + size); + + pmap_kremove(va, endva - va); + pmap_update(pmap_kernel()); + km_free((void *)va, endva - va, &kv_any, &kp_none); } int @@ -309,4 +382,3 @@ a4x_space_write_raw_8(bus_space_tag_t t, bus_space_handle_t h, bus_addr_t o, buf += 8; } } - |