aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2007-03-21 15:36:38 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2007-03-21 15:36:38 +0000
commitd66ff2777373b12e48d641bb9aa13fa23a70a094 (patch)
tree4989128fac6d15df8be136f9b5a8497fa5929014
parent63f0abbf1b90c890fd3d17e603e52c90812a5621 (diff)
downloadsrc-d66ff2777373b12e48d641bb9aa13fa23a70a094.tar.gz
src-d66ff2777373b12e48d641bb9aa13fa23a70a094.zip
Change the amd64, i386, and ia64 nexus drivers to setup bus space tags and
handles when activating a resource via bus_activate_resource() rather than doing some of the work in bus_alloc_resource() and some of it in bus_activate_resource(). One note is that when using isa_alloc_resourcev() on PC-98, drivers now need to just use bus_release_resource() without explicitly calling bus_deactivate_resource() first. nyan@ has already fixed all of the PC-98 drivers.
Notes
Notes: svn path=/head/; revision=167767
-rw-r--r--sys/amd64/amd64/nexus.c14
-rw-r--r--sys/i386/i386/nexus.c75
-rw-r--r--sys/ia64/ia64/nexus.c26
3 files changed, 53 insertions, 62 deletions
diff --git a/sys/amd64/amd64/nexus.c b/sys/amd64/amd64/nexus.c
index d6fcef9a4681..b15d301d2f0b 100644
--- a/sys/amd64/amd64/nexus.c
+++ b/sys/amd64/amd64/nexus.c
@@ -351,12 +351,6 @@ nexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
if (rv == 0)
return 0;
rman_set_rid(rv, *rid);
- if (type == SYS_RES_MEMORY) {
- rman_set_bustag(rv, AMD64_BUS_SPACE_MEM);
- } else if (type == SYS_RES_IOPORT) {
- rman_set_bustag(rv, AMD64_BUS_SPACE_IO);
- rman_set_bushandle(rv, rman_get_start(rv));
- }
if (needactivate) {
if (bus_activate_resource(child, type, *rid, rv)) {
@@ -376,12 +370,16 @@ nexus_activate_resource(device_t bus, device_t child, int type, int rid,
/*
* If this is a memory resource, map it into the kernel.
*/
- if (rman_get_bustag(r) == AMD64_BUS_SPACE_MEM) {
+ if (type == SYS_RES_MEMORY) {
void *vaddr;
vaddr = pmap_mapdev(rman_get_start(r), rman_get_size(r));
rman_set_virtual(r, vaddr);
+ rman_set_bustag(r, AMD64_BUS_SPACE_MEM);
rman_set_bushandle(r, (bus_space_handle_t) vaddr);
+ } else if (type == SYS_RES_IOPORT) {
+ rman_set_bustag(r, AMD64_BUS_SPACE_IO);
+ rman_set_bushandle(r, rman_get_start(r));
}
return (rman_activate_resource(r));
}
@@ -393,7 +391,7 @@ nexus_deactivate_resource(device_t bus, device_t child, int type, int rid,
/*
* If this is a memory resource, unmap it.
*/
- if (rman_get_bustag(r) == AMD64_BUS_SPACE_MEM) {
+ if (type == SYS_RES_MEMORY) {
pmap_unmapdev((vm_offset_t)rman_get_virtual(r),
rman_get_size(r));
}
diff --git a/sys/i386/i386/nexus.c b/sys/i386/i386/nexus.c
index 44b3c69363e0..9615e9d3d4b0 100644
--- a/sys/i386/i386/nexus.c
+++ b/sys/i386/i386/nexus.c
@@ -320,9 +320,6 @@ nexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
struct resource_list_entry *rle;
struct rman *rm;
int needactivate = flags & RF_ACTIVE;
-#ifdef PC98
- bus_space_handle_t bh;
-#endif
/*
* If this is an allocation of the "default" range for a given RID, and
@@ -367,34 +364,9 @@ nexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
if (rv == 0)
return 0;
rman_set_rid(rv, *rid);
- if (type == SYS_RES_MEMORY) {
- rman_set_bustag(rv, I386_BUS_SPACE_MEM);
- } else if (type == SYS_RES_IOPORT) {
- rman_set_bustag(rv, I386_BUS_SPACE_IO);
-#ifndef PC98
- rman_set_bushandle(rv, rman_get_start(rv));
-#endif
- }
-
-#ifdef PC98
- if ((type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) &&
- i386_bus_space_handle_alloc(rman_get_bustag(rv),
- rman_get_start(rv), count, &bh) != 0) {
- rman_release_resource(rv);
- return 0;
- }
- rman_set_bushandle(rv, bh);
-#endif
if (needactivate) {
if (bus_activate_resource(child, type, *rid, rv)) {
-#ifdef PC98
- if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) {
- bh = rman_get_bushandle(rv);
- i386_bus_space_handle_free(rman_get_bustag(rv),
- bh, bh->bsh_sz);
- }
-#endif
rman_release_resource(rv);
return 0;
}
@@ -409,19 +381,40 @@ nexus_activate_resource(device_t bus, device_t child, int type, int rid,
{
#ifdef PC98
bus_space_handle_t bh;
+ int error;
#endif
+ void *vaddr;
+
/*
* If this is a memory resource, map it into the kernel.
*/
- if (rman_get_bustag(r) == I386_BUS_SPACE_MEM) {
- void *vaddr;
-
+ switch (type) {
+ case SYS_RES_IOPORT:
+#ifdef PC98
+ error = i386_bus_space_handle_alloc(I386_BUS_SPACE_IO,
+ rman_get_start(r), rman_get_size(r), &bh);
+ if (error)
+ return (error);
+ rman_set_bushandle(r, bh);
+#else
+ rman_set_bushandle(r, rman_get_start(r));
+#endif
+ rman_set_bustag(r, I386_BUS_SPACE_IO);
+ break;
+ case SYS_RES_MEMORY:
+#ifdef PC98
+ error = i386_bus_space_handle_alloc(I386_BUS_SPACE_MEM,
+ rman_get_start(r), rman_get_size(r), &bh);
+ if (error)
+ return (error);
+#endif
vaddr = pmap_mapdev(rman_get_start(r), rman_get_size(r));
rman_set_virtual(r, vaddr);
+ rman_set_bustag(r, I386_BUS_SPACE_MEM);
#ifdef PC98
/* PC-98: the type of bus_space_handle_t is the structure. */
- bh = rman_get_bushandle(r);
bh->bsh_base = (bus_addr_t) vaddr;
+ rman_set_bushandle(r, bh);
#else
/* IBM-PC: the type of bus_space_handle_t is u_int */
rman_set_bushandle(r, (bus_space_handle_t) vaddr);
@@ -434,14 +427,22 @@ static int
nexus_deactivate_resource(device_t bus, device_t child, int type, int rid,
struct resource *r)
{
+
/*
* If this is a memory resource, unmap it.
*/
- if (rman_get_bustag(r) == I386_BUS_SPACE_MEM) {
+ if (type == SYS_RES_MEMORY) {
pmap_unmapdev((vm_offset_t)rman_get_virtual(r),
rman_get_size(r));
}
+#ifdef PC98
+ if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) {
+ bus_space_handle_t bh;
+ bh = rman_get_bushandle(r);
+ i386_bus_space_handle_free(rman_get_bustag(r), bh, bh->bsh_sz);
+ }
+#endif
return (rman_deactivate_resource(r));
}
@@ -454,14 +455,6 @@ nexus_release_resource(device_t bus, device_t child, int type, int rid,
if (error)
return error;
}
-#ifdef PC98
- if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) {
- bus_space_handle_t bh;
-
- bh = rman_get_bushandle(r);
- i386_bus_space_handle_free(rman_get_bustag(r), bh, bh->bsh_sz);
- }
-#endif
return (rman_release_resource(r));
}
diff --git a/sys/ia64/ia64/nexus.c b/sys/ia64/ia64/nexus.c
index 166a3ba9887b..38c56bf2f978 100644
--- a/sys/ia64/ia64/nexus.c
+++ b/sys/ia64/ia64/nexus.c
@@ -356,15 +356,7 @@ nexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
rv = rman_reserve_resource(rm, start, end, count, flags, child);
if (rv == 0)
return 0;
-
rman_set_rid(rv, *rid);
- if (type == SYS_RES_MEMORY) {
- rman_set_bustag(rv, IA64_BUS_SPACE_MEM);
- } else if (type == SYS_RES_IOPORT) {
- rman_set_bustag(rv, IA64_BUS_SPACE_IO);
- /* IBM-PC: the type of bus_space_handle_t is u_int */
- rman_set_bushandle(rv, rman_get_start(rv));
- }
if (needactivate) {
if (bus_activate_resource(child, type, *rid, rv)) {
@@ -380,17 +372,25 @@ static int
nexus_activate_resource(device_t bus, device_t child, int type, int rid,
struct resource *r)
{
+ vm_paddr_t paddr, psize;
+ void *vaddr;
+
/*
* If this is a memory resource, map it into the kernel.
*/
- if (rman_get_bustag(r) == IA64_BUS_SPACE_MEM) {
- vm_offset_t paddr = rman_get_start(r);
- vm_offset_t psize = rman_get_size(r);
- caddr_t vaddr = 0;
-
+ switch (type) {
+ case SYS_RES_IOPORT:
+ rman_set_bustag(r, IA64_BUS_SPACE_IO);
+ rman_set_bushandle(r, rman_get_start(r));
+ break;
+ case SYS_RES_MEMORY:
+ paddr = rman_get_start(r);
+ psize = rman_get_size(r);
vaddr = pmap_mapdev(paddr, psize);
rman_set_virtual(r, vaddr);
+ rman_set_bustag(r, IA64_BUS_SPACE_MEM);
rman_set_bushandle(r, (bus_space_handle_t) paddr);
+ break;
}
return (rman_activate_resource(r));
}