From f61b6fe561583c44adb1a7fa2343b02a4837f480 Mon Sep 17 00:00:00 2001 From: Ian Lepore Date: Sat, 4 Jan 2014 21:18:22 +0000 Subject: [PATCH] Use bus_space_map() rather than pmap_mapdev() in nexus_activate_resource(), when running on FDT systems. Unmap memory in nexus_deactivate_resource(). Also, call rman_activate_resource() before mapping device memory, and only do the mapping if it returns success. Reviewed by: nwhitehorn --- sys/arm/arm/nexus.c | 55 +++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/sys/arm/arm/nexus.c b/sys/arm/arm/nexus.c index 5c02e2aa3c71..5200303b0764 100644 --- a/sys/arm/arm/nexus.c +++ b/sys/arm/arm/nexus.c @@ -278,36 +278,63 @@ static int nexus_activate_resource(device_t bus, device_t child, int type, int rid, struct resource *r) { + int err; + bus_addr_t paddr; + bus_size_t psize; + bus_space_handle_t vaddr; + + if ((err = rman_activate_resource(r)) != 0) + return (err); + /* * If this is a memory resource, map it into the kernel. */ if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) { - caddr_t vaddr = 0; - u_int32_t paddr; - u_int32_t psize; - u_int32_t poffs; - - paddr = rman_get_start(r); - psize = rman_get_size(r); - poffs = paddr - trunc_page(paddr); - vaddr = (caddr_t) pmap_mapdev(paddr-poffs, psize+poffs) + poffs; - rman_set_virtual(r, vaddr); + paddr = (bus_addr_t)rman_get_start(r); + psize = (bus_size_t)rman_get_size(r); #ifdef FDT + err = bus_space_map(fdtbus_bs_tag, paddr, psize, 0, &vaddr); + if (err != 0) { + rman_deactivate_resource(r); + return (err); + } rman_set_bustag(r, fdtbus_bs_tag); #else + vaddr = (bus_space_handle_t)pmap_mapdev((vm_offset_t)paddr, + (vm_size_t)psize); + if (vaddr == 0) { + rman_deactivate_resource(r); + return (ENOMEM); + } rman_set_bustag(r, (void *)1); #endif - rman_set_bushandle(r, (bus_space_handle_t) vaddr); + rman_set_virtual(r, (void *)vaddr); + rman_set_bushandle(r, vaddr); } - return (rman_activate_resource(r)); + return (0); } static int nexus_deactivate_resource(device_t bus, device_t child, int type, int rid, - struct resource *res) + struct resource *r) { + bus_size_t psize; + bus_space_handle_t vaddr; - return (rman_deactivate_resource(res)); + psize = (bus_size_t)rman_get_size(r); + vaddr = rman_get_bushandle(r); + + if (vaddr != 0) { +#ifdef FDT + bus_space_unmap(fdtbus_bs_tag, vaddr, psize); +#else + pmap_unmapdev((vm_offset_t)vaddr, (vm_size_t)psize); +#endif + rman_set_virtual(r, NULL); + rman_set_bushandle(r, 0); + } + + return (rman_deactivate_resource(r)); } #ifdef FDT