Date: Thu, 11 Feb 2016 06:24:34 +0000 (UTC) From: Adrian Chadd <adrian@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r295504 - head/sys/mips/mips Message-ID: <201602110624.u1B6OY8W054559@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: adrian Date: Thu Feb 11 06:24:34 2016 New Revision: 295504 URL: https://svnweb.freebsd.org/changeset/base/295504 Log: Make bus_space_generic properly map/unmap memory (using pmap_mapdev and pmap_unmapdev respectively) so that resources are properly managed. This is work originally done by kan@. Stanislav picked it up as part of his Mediatek SoC work. Tested: * Carambola2, AR933x SoC Submitted by: Stanislav Galabov <sgalabov@gmail.com> Reviewed by: kan Differential Revision: https://reviews.freebsd.org/D5184 Modified: head/sys/mips/mips/bus_space_generic.c head/sys/mips/mips/nexus.c Modified: head/sys/mips/mips/bus_space_generic.c ============================================================================== --- head/sys/mips/mips/bus_space_generic.c Thu Feb 11 06:23:02 2016 (r295503) +++ head/sys/mips/mips/bus_space_generic.c Thu Feb 11 06:24:34 2016 (r295504) @@ -228,20 +228,21 @@ bus_space_tag_t mips_bus_space_generic = int generic_bs_map(void *t __unused, bus_addr_t addr, - bus_size_t size __unused, int flags __unused, + bus_size_t size, int flags __unused, bus_space_handle_t *bshp) { - *bshp = addr; + *bshp = (bus_space_handle_t)pmap_mapdev((vm_paddr_t)addr, + (vm_size_t)size); return (0); } void -generic_bs_unmap(void *t __unused, bus_space_handle_t bh __unused, - bus_size_t size __unused) +generic_bs_unmap(void *t __unused, bus_space_handle_t bh, + bus_size_t size) { - /* Do nothing */ + pmap_unmapdev((vm_offset_t)bh, (vm_size_t)size); } int Modified: head/sys/mips/mips/nexus.c ============================================================================== --- head/sys/mips/mips/nexus.c Thu Feb 11 06:23:02 2016 (r295503) +++ head/sys/mips/mips/nexus.c Thu Feb 11 06:24:34 2016 (r295504) @@ -415,6 +415,7 @@ nexus_activate_resource(device_t bus, de void *vaddr; vm_paddr_t paddr; vm_size_t psize; + int err; /* * If this is a memory resource, use pmap_mapdev to map it. @@ -422,10 +423,14 @@ nexus_activate_resource(device_t bus, de if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) { paddr = rman_get_start(r); psize = rman_get_size(r); - vaddr = pmap_mapdev(paddr, psize); - - rman_set_virtual(r, vaddr); rman_set_bustag(r, mips_bus_space_generic); + err = bus_space_map(rman_get_bustag(r), paddr, psize, 0, + (bus_space_handle_t *)&vaddr); + if (err != 0) { + rman_deactivate_resource(r); + return (err); + } + rman_set_virtual(r, vaddr); rman_set_bushandle(r, (bus_space_handle_t)(uintptr_t)vaddr); } @@ -436,11 +441,16 @@ static int nexus_deactivate_resource(device_t bus, device_t child, int type, int rid, struct resource *r) { - vm_offset_t va; - - if (type == SYS_RES_MEMORY) { - va = (vm_offset_t)rman_get_virtual(r); - pmap_unmapdev(va, rman_get_size(r)); + bus_space_handle_t vaddr; + bus_size_t psize; + + vaddr = rman_get_bushandle(r); + + if (type == SYS_RES_MEMORY && vaddr != 0) { + psize = (bus_size_t)rman_get_size(r); + bus_space_unmap(rman_get_bustag(r), vaddr, psize); + rman_set_virtual(r, NULL); + rman_set_bushandle(r, 0); } return (rman_deactivate_resource(r));
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201602110624.u1B6OY8W054559>