mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-19 10:53:58 +00:00
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
This commit is contained in:
parent
67dbd33ca8
commit
f61b6fe561
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=260283
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user