Put a bus's ranges in the bus space tag, and make sparc_bus_map()

perform the translation and recursion if t->ranges != NULL.  Make
sbus, cpuunit, and bootbus inherit the parent's map/mmap routines,
and delete the now-unused mapping functions.  Update all places where
bus space tags are statically allocated.
This commit is contained in:
thorpej 2002-08-25 17:54:57 +00:00
parent 9ca1f94f72
commit a9f285b0ac
9 changed files with 87 additions and 201 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: bootbus.c,v 1.2 2002/08/25 16:05:41 thorpej Exp $ */
/* $NetBSD: bootbus.c,v 1.3 2002/08/25 17:54:57 thorpej Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -59,9 +59,6 @@ struct bootbus_softc {
bus_space_tag_t sc_st; /* ours */
bus_space_tag_t sc_bustag; /* passed on to children */
struct openprom_range *sc_range; /* our address ranges */
int sc_nrange;
};
static int bootbus_match(struct device *, struct cfdata *, void *);
@ -74,13 +71,6 @@ struct cfattach bootbus_ca = {
static int bootbus_submatch(struct device *, struct cfdata *, void *);
static int bootbus_print(void *, const char *);
static int bootbus_bus_map(bus_space_tag_t, bus_addr_t, size_t, int,
vaddr_t, bus_space_handle_t *);
static paddr_t bootbus_bus_mmap(bus_space_tag_t, bus_addr_t, off_t,
int, int);
static void *bootbus_intr_establish(bus_space_tag_t, int, int, int,
int (*)(void *), void *);
static int bootbus_setup_attach_args(struct bootbus_softc *, bus_space_tag_t,
int, struct bootbus_attach_args *);
static void bootbus_destroy_attach_args(struct bootbus_attach_args *);
@ -115,16 +105,15 @@ bootbus_attach(struct device *parent, struct device *self, void *aux)
M_WAITOK|M_ZERO);
sc->sc_bustag->cookie = sc;
sc->sc_bustag->parent = sc->sc_st;
sc->sc_bustag->sparc_bus_map = bootbus_bus_map;
sc->sc_bustag->sparc_bus_mmap = bootbus_bus_mmap;
sc->sc_bustag->sparc_intr_establish = bootbus_intr_establish;
sc->sc_bustag->sparc_bus_map = sc->sc_st->sparc_bus_map;
sc->sc_bustag->sparc_bus_mmap = sc->sc_st->sparc_bus_mmap;
/*
* Collect address translations from the OBP.
*/
error = PROM_getprop(sc->sc_node, "ranges",
sizeof(struct openprom_range), &sc->sc_nrange,
(void **) &sc->sc_range);
sizeof(struct openprom_range), &sc->sc_bustag->nranges,
(void **) &sc->sc_bustag->ranges);
if (error) {
printf("%s: error %d getting \"ranges\" property\n",
sc->sc_dev.dv_xname, error);
@ -233,52 +222,3 @@ bootbus_destroy_attach_args(struct bootbus_attach_args *baa)
if (baa->ba_promvaddrs != NULL)
free(baa->ba_promvaddrs, M_DEVBUF);
}
static int
bootbus_bus_map(bus_space_tag_t t, bus_addr_t ba, bus_size_t size,
int flags, vaddr_t va, bus_space_handle_t *hp)
{
struct bootbus_softc *sc = t->cookie;
bus_addr_t addr;
int error;
error = bus_translate_address_generic(sc->sc_range, sc->sc_nrange,
ba, &addr);
if (error)
return (error);
return (bus_space_map2(sc->sc_st, addr, size, flags, va, hp));
}
static paddr_t
bootbus_bus_mmap(bus_space_tag_t t, bus_addr_t ba, off_t off, int prot,
int flags)
{
struct bootbus_softc *sc = t->cookie;
bus_addr_t addr;
int error;
error = bus_translate_address_generic(sc->sc_range, sc->sc_nrange,
ba, &addr);
if (error)
return (-1);
return (bus_space_mmap(sc->sc_st, addr, off, prot, flags));
}
static void *
bootbus_intr_establish(bus_space_tag_t t, int pil, int level, int flags,
int (*handler)(void *), void *arg)
{
struct intrhand *ih;
ih = malloc(sizeof(*ih), M_DEVBUF, M_NOWAIT);
if (ih == NULL)
return (NULL);
ih->ih_fun = handler;
ih->ih_arg = arg;
if ((flags & BUS_INTR_ESTABLISH_FASTTRAP) != 0)
intr_fasttrap(pil, (void (*)__P((void)))handler);
else
intr_establish(pil, ih);
return (ih);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: obio.c,v 1.52 2002/04/11 11:11:23 pk Exp $ */
/* $NetBSD: obio.c,v 1.53 2002/08/25 17:54:58 thorpej Exp $ */
/*-
* Copyright (c) 1997,1998 The NetBSD Foundation, Inc.
@ -102,6 +102,8 @@ static int _obio_bus_map __P((bus_space_tag_t, bus_addr_t,
static struct sparc_bus_space_tag obio_space_tag = {
NULL, /* cookie */
NULL, /* parent bus tag */
NULL, /* ranges */
0, /* nranges */
_obio_bus_map, /* bus_space_map */
NULL, /* bus_space_unmap */
NULL, /* bus_space_subregion */

View File

@ -1,4 +1,4 @@
/* $NetBSD: sbus.c,v 1.47 2002/08/25 16:05:41 thorpej Exp $ */
/* $NetBSD: sbus.c,v 1.48 2002/08/25 17:54:58 thorpej Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -105,15 +105,6 @@ void sbusreset __P((int));
static bus_space_tag_t sbus_alloc_bustag __P((struct sbus_softc *));
static int sbus_get_intr __P((struct sbus_softc *, int,
struct openprom_intr **, int *));
static paddr_t sbus_bus_mmap __P((bus_space_tag_t, bus_addr_t, off_t,
int, int));
static int _sbus_bus_map __P((
bus_space_tag_t,
bus_addr_t, /*coded slot+offset*/
bus_size_t, /*size*/
int, /*flags*/
vaddr_t, /*preferred virtual address */
bus_space_handle_t *));
static void *sbus_intr_establish __P((
bus_space_tag_t,
int, /*Sbus interrupt level*/
@ -415,14 +406,14 @@ sbus_attach_common(sc, busname, busnode, specials)
* Collect address translations from the OBP.
*/
error = PROM_getprop(busnode, "ranges", sizeof(struct rom_range),
&sc->sc_nrange, (void **)&sc->sc_range);
&sbt->nranges, (void **) &sbt->ranges);
switch (error) {
case 0:
break;
case ENOENT:
/* Fall back to our own `range' construction */
sc->sc_range = sbus_translations;
sc->sc_nrange =
sbt->ranges = sbus_translations;
sbt->nranges =
sizeof(sbus_translations)/sizeof(sbus_translations[0]);
break;
default:
@ -542,46 +533,6 @@ sbus_destroy_attach_args(sa)
bzero(sa, sizeof(struct sbus_attach_args));/*DEBUG*/
}
int
_sbus_bus_map(t, ba, size, flags, va, hp)
bus_space_tag_t t;
bus_addr_t ba;
bus_size_t size;
int flags;
vaddr_t va;
bus_space_handle_t *hp;
{
struct sbus_softc *sc = t->cookie;
bus_addr_t addr;
int error;
error = bus_translate_address_generic(sc->sc_range, sc->sc_nrange,
ba, &addr);
if (error)
return (error);
return (bus_space_map2(sc->sc_bustag, addr, size, flags, va, hp));
}
static paddr_t
sbus_bus_mmap(t, ba, off, prot, flags)
bus_space_tag_t t;
bus_addr_t ba;
off_t off;
int prot;
int flags;
{
struct sbus_softc *sc = t->cookie;
bus_addr_t addr;
int error;
error = bus_translate_address_generic(sc->sc_range, sc->sc_nrange,
ba, &addr);
if (error)
return (-1);
return (bus_space_mmap(sc->sc_bustag, addr, off, prot, flags));
}
bus_addr_t
sbus_bus_addr(t, btype, offset)
bus_space_tag_t t;
@ -762,8 +713,8 @@ sbus_alloc_bustag(sc)
bzero(sbt, sizeof *sbt);
sbt->cookie = sc;
sbt->parent = sc->sc_bustag;
sbt->sparc_bus_map = _sbus_bus_map;
sbt->sparc_bus_mmap = sbus_bus_mmap;
sbt->sparc_bus_map = sc->sc_bustag->sparc_bus_map;
sbt->sparc_bus_mmap = sc->sc_bustag->sparc_bus_mmap;
sbt->sparc_intr_establish = sbus_intr_establish;
return (sbt);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: sbusvar.h,v 1.12 2002/08/23 02:53:11 thorpej Exp $ */
/* $NetBSD: sbusvar.h,v 1.13 2002/08/25 17:54:59 thorpej Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -92,13 +92,10 @@ struct sbus_softc {
bus_space_handle_t sc_bh; /* SBus control registers */
int sc_clockfreq; /* clock frequency (in Hz) */
struct sbusdev *sc_sbdev; /* list of all children */
struct openprom_range *sc_range;/* Address space translations */
int sc_nrange;
int sc_burst; /* burst transfer sizes supported */
/* MD fields follow here */
int *sc_intr2ipl; /* Interrupt level translation */
int *sc_intr_compat; /* `intr' property to sbus compat */
};
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: bus.h,v 1.32 2002/05/07 06:45:22 uwe Exp $ */
/* $NetBSD: bus.h,v 1.33 2002/08/25 17:55:00 thorpej Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
@ -95,6 +95,14 @@ struct sparc_bus_space_tag {
void *cookie;
bus_space_tag_t parent;
/*
* Windows onto the parent bus that this tag maps. If ranges
* is non-NULL, the address will be translated, and recursively
* mapped via the parent tag.
*/
struct openprom_range *ranges;
int nranges;
int (*sparc_bus_map) __P((
bus_space_tag_t,
bus_addr_t,

View File

@ -1,4 +1,4 @@
/* $NetBSD: autoconf.c,v 1.173 2002/08/25 16:05:43 thorpej Exp $ */
/* $NetBSD: autoconf.c,v 1.174 2002/08/25 17:55:01 thorpej Exp $ */
/*
* Copyright (c) 1996
@ -2089,29 +2089,3 @@ bootinfo_relocate(newloc)
kernel_top = (char *)newloc + ALIGN(bi_size);
}
#endif
#if defined(SUN4C) || defined(SUN4M) || defined(SUN4D)
/*
* Generic routine to translate an address using OpenPROM `ranges'.
*/
int
bus_translate_address_generic(struct openprom_range *ranges, int nranges,
bus_addr_t addr, bus_addr_t *addrp)
{
int i, space = BUS_ADDR_IOSPACE(addr);
for (i = 0; i < nranges; i++) {
struct openprom_range *rp = &ranges[i];
if (rp->or_child_space != space)
continue;
/* We've found the connection to the parent bus. */
*addrp = BUS_ADDR(rp->or_parent_space,
rp->or_parent_base + BUS_ADDR_PADDR(addr));
return (0);
}
return (EINVAL);
}
#endif /* SUN4C || SUN4M || SUN4D */

View File

@ -1,4 +1,4 @@
/* $NetBSD: cpuunit.c,v 1.2 2002/08/25 16:05:44 thorpej Exp $ */
/* $NetBSD: cpuunit.c,v 1.3 2002/08/25 17:55:02 thorpej Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -57,9 +57,6 @@ struct cpuunit_softc {
bus_space_tag_t sc_st; /* ours */
bus_space_tag_t sc_bustag; /* passed on to children */
struct openprom_range *sc_range; /* our address ranges */
int sc_nrange;
int sc_device_id; /* device-id */
int sc_board; /* board number */
};
@ -73,11 +70,6 @@ struct cfattach cpuunit_ca = {
static int cpuunit_print(void *, const char *);
static int cpuunit_bus_map(bus_space_tag_t, bus_addr_t, size_t, int,
vaddr_t, bus_space_handle_t *);
static paddr_t cpuunit_bus_mmap(bus_space_tag_t, bus_addr_t, off_t,
int, int);
static int cpuunit_setup_attach_args(struct cpuunit_softc *, bus_space_tag_t,
int, struct cpuunit_attach_args *);
static void cpuunit_destroy_attach_args(struct cpuunit_attach_args *);
@ -115,15 +107,15 @@ cpuunit_attach(struct device *parent, struct device *self, void *aux)
M_WAITOK|M_ZERO);
sc->sc_bustag->cookie = sc;
sc->sc_bustag->parent = sc->sc_st;
sc->sc_bustag->sparc_bus_map = cpuunit_bus_map;
sc->sc_bustag->sparc_bus_mmap = cpuunit_bus_mmap;
sc->sc_bustag->sparc_bus_map = sc->sc_st->sparc_bus_map;
sc->sc_bustag->sparc_bus_mmap = sc->sc_st->sparc_bus_mmap;
/*
* Collect address translations from the OBP.
*/
error = PROM_getprop(sc->sc_node, "ranges",
sizeof(struct openprom_range), &sc->sc_nrange,
(void **) &sc->sc_range);
sizeof(struct openprom_range), &sc->sc_bustag->nranges,
(void **) &sc->sc_bustag->ranges);
if (error) {
printf("%s: error %d getting \"ranges\" property\n",
sc->sc_dev.dv_xname, error);
@ -192,33 +184,3 @@ cpuunit_destroy_attach_args(struct cpuunit_attach_args *cpua)
if (cpua->cpua_type != NULL)
free(cpua->cpua_type, M_DEVBUF);
}
static int
cpuunit_bus_map(bus_space_tag_t t, bus_addr_t ba, bus_size_t size,
int flags, vaddr_t va, bus_space_handle_t *hp)
{
struct cpuunit_softc *sc = t->cookie;
bus_addr_t addr;
int error;
error = bus_translate_address_generic(sc->sc_range,
sc->sc_nrange, ba, &addr);
if (error)
return (error);
return (bus_space_map2(sc->sc_st, addr, size, flags, va, hp));
}
static paddr_t
cpuunit_bus_mmap(bus_space_tag_t t, bus_addr_t ba, off_t off, int prot,
int flags)
{
struct cpuunit_softc *sc = t->cookie;
bus_addr_t addr;
int error;
error = bus_translate_address_generic(sc->sc_range, sc->sc_nrange,
ba, &addr);
if (error)
return (-1);
return (bus_space_mmap(sc->sc_st, addr, off, prot, flags));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.197 2002/07/17 15:57:12 thorpej Exp $ */
/* $NetBSD: machdep.c,v 1.198 2002/08/25 17:55:02 thorpej Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@ -1779,6 +1779,29 @@ static void *sparc_mainbus_intr_establish __P((bus_space_tag_t, int, int,
static void sparc_bus_barrier __P(( bus_space_tag_t, bus_space_handle_t,
bus_size_t, bus_size_t, int));
/*
* Generic routine to translate an address using OpenPROM `ranges'.
*/
int
bus_translate_address_generic(struct openprom_range *ranges, int nranges,
bus_addr_t addr, bus_addr_t *addrp)
{
int i, space = BUS_ADDR_IOSPACE(addr);
for (i = 0; i < nranges; i++) {
struct openprom_range *rp = &ranges[i];
if (rp->or_child_space != space)
continue;
/* We've found the connection to the parent bus. */
*addrp = BUS_ADDR(rp->or_parent_space,
rp->or_parent_base + BUS_ADDR_PADDR(addr));
return (0);
}
return (EINVAL);
}
int
sparc_bus_map(t, ba, size, flags, va, hp)
@ -1793,6 +1816,14 @@ sparc_bus_map(t, ba, size, flags, va, hp)
unsigned int pmtype;
static vaddr_t iobase;
if (t->ranges != NULL) {
bus_addr_t addr;
int error;
error = bus_translate_address_generic(t->ranges, t->nranges,
ba, &addr);
return (bus_space_map2(t->parent, addr, size, flags, va, hp));
}
if (iobase == NULL)
iobase = IODEV_BASE;
@ -1863,8 +1894,23 @@ sparc_bus_mmap(t, ba, off, prot, flags)
int prot;
int flags;
{
u_int pmtype = PMAP_IOENC(BUS_ADDR_IOSPACE(ba));
paddr_t pa = trunc_page(BUS_ADDR_PADDR(ba) + off);
u_int pmtype;
paddr_t pa;
if (t->ranges != NULL) {
bus_addr_t addr;
int error;
error = bus_translate_address_generic(t->ranges, t->nranges,
ba, &addr);
if (error)
return (-1);
return (bus_space_mmap(t->parent, addr, off, prot, flags));
}
pmtype = PMAP_IOENC(BUS_ADDR_IOSPACE(ba));
pa = trunc_page(BUS_ADDR_PADDR(ba) + off);
return (paddr_t)(pa | pmtype | PMAP_NC);
}
@ -1936,6 +1982,8 @@ void sparc_bus_barrier (t, h, offset, size, flags)
struct sparc_bus_space_tag mainbus_space_tag = {
NULL, /* cookie */
NULL, /* parent bus tag */
NULL, /* ranges */
0, /* nranges */
sparc_bus_map, /* bus_space_map */
sparc_bus_unmap, /* bus_space_unmap */
sparc_bus_subregion, /* bus_space_subregion */

View File

@ -1,4 +1,4 @@
/* $NetBSD: msiiep.c,v 1.10 2002/06/05 00:23:01 uwe Exp $ */
/* $NetBSD: msiiep.c,v 1.11 2002/08/25 17:55:04 thorpej Exp $ */
/*
* Copyright (c) 2001 Valeriy E. Ushakov
@ -27,7 +27,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: msiiep.c,v 1.10 2002/06/05 00:23:01 uwe Exp $");
__KERNEL_RCSID(0, "$NetBSD: msiiep.c,v 1.11 2002/08/25 17:55:04 thorpej Exp $");
#include <sys/param.h>
#include <sys/malloc.h>
@ -153,6 +153,8 @@ static void *mspcic_intr_establish(bus_space_tag_t, int, int, int,
static struct sparc_bus_space_tag mspcic_io_tag = {
&mspcic_io_cookie, /* cookie */
NULL, /* parent bus tag */
NULL, /* ranges */
0, /* nranges */
mspcic_bus_map, /* bus_space_map */
NULL, /* bus_space_unmap */
NULL, /* bus_space_subregion */
@ -164,6 +166,8 @@ static struct sparc_bus_space_tag mspcic_io_tag = {
static struct sparc_bus_space_tag mspcic_mem_tag = {
&mspcic_mem_cookie, /* cookie */
NULL, /* parent bus tag */
NULL, /* ranges */
0, /* nranges */
mspcic_bus_map, /* bus_space_map */
NULL, /* bus_space_unmap */
NULL, /* bus_space_subregion */