Add a generic function to translate a device address using a
parent's "ranges" property, and use it.
This commit is contained in:
parent
51b546d0bb
commit
0570742a0b
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: bootbus.c,v 1.1 2002/08/24 05:26:57 thorpej Exp $ */
|
||||
/* $NetBSD: bootbus.c,v 1.2 2002/08/25 16:05:41 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||
|
@ -45,11 +45,11 @@
|
|||
#include <sys/systm.h>
|
||||
#include <sys/device.h>
|
||||
|
||||
#include <machine/autoconf.h>
|
||||
#include <machine/bus.h>
|
||||
|
||||
#include <sparc/sparc/cpuunitvar.h>
|
||||
#include <sparc/dev/bootbusvar.h>
|
||||
#include <machine/autoconf.h>
|
||||
|
||||
#include "locators.h"
|
||||
|
||||
|
@ -234,28 +234,6 @@ bootbus_destroy_attach_args(struct bootbus_attach_args *baa)
|
|||
free(baa->ba_promvaddrs, M_DEVBUF);
|
||||
}
|
||||
|
||||
static int
|
||||
bootbus_translate_address(struct bootbus_softc *sc, bus_addr_t addr,
|
||||
bus_addr_t *addrp)
|
||||
{
|
||||
int space = BUS_ADDR_IOSPACE(addr);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sc->sc_nrange; i++) {
|
||||
struct openprom_range *rp = &sc->sc_range[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);
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -264,7 +242,8 @@ bootbus_bus_map(bus_space_tag_t t, bus_addr_t ba, bus_size_t size,
|
|||
bus_addr_t addr;
|
||||
int error;
|
||||
|
||||
error = bootbus_translate_address(sc, ba, &addr);
|
||||
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));
|
||||
|
@ -278,7 +257,8 @@ bootbus_bus_mmap(bus_space_tag_t t, bus_addr_t ba, off_t off, int prot,
|
|||
bus_addr_t addr;
|
||||
int error;
|
||||
|
||||
error = bootbus_translate_address(sc, ba, &addr);
|
||||
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));
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: sbus.c,v 1.46 2002/08/23 02:53:11 thorpej Exp $ */
|
||||
/* $NetBSD: sbus.c,v 1.47 2002/08/25 16:05:41 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
||||
|
@ -92,14 +92,13 @@
|
|||
|
||||
#include <uvm/uvm_extern.h>
|
||||
|
||||
#include <machine/autoconf.h>
|
||||
#include <machine/bus.h>
|
||||
#include <sparc/dev/sbusreg.h>
|
||||
#include <dev/sbus/sbusvar.h>
|
||||
#include <dev/sbus/xboxvar.h>
|
||||
|
||||
#include <sparc/sparc/iommuvar.h>
|
||||
#include <machine/autoconf.h>
|
||||
|
||||
|
||||
void sbusreset __P((int));
|
||||
|
||||
|
@ -554,23 +553,14 @@ _sbus_bus_map(t, ba, size, flags, va, hp)
|
|||
bus_space_handle_t *hp;
|
||||
{
|
||||
struct sbus_softc *sc = t->cookie;
|
||||
int slot = BUS_ADDR_IOSPACE(ba);
|
||||
int i;
|
||||
bus_addr_t addr;
|
||||
int error;
|
||||
|
||||
for (i = 0; i < sc->sc_nrange; i++) {
|
||||
struct openprom_range *rp = &sc->sc_range[i];
|
||||
|
||||
if (rp->or_child_space != slot)
|
||||
continue;
|
||||
|
||||
/* We've found the connection to the parent bus */
|
||||
return (bus_space_map2(sc->sc_bustag,
|
||||
BUS_ADDR(rp->or_parent_space,
|
||||
rp->or_parent_base + BUS_ADDR_PADDR(ba)),
|
||||
size, flags, va, hp));
|
||||
}
|
||||
|
||||
return (EINVAL);
|
||||
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
|
||||
|
@ -582,22 +572,14 @@ sbus_bus_mmap(t, ba, off, prot, flags)
|
|||
int flags;
|
||||
{
|
||||
struct sbus_softc *sc = t->cookie;
|
||||
int slot = BUS_ADDR_IOSPACE(ba);
|
||||
int i;
|
||||
bus_addr_t addr;
|
||||
int error;
|
||||
|
||||
for (i = 0; i < sc->sc_nrange; i++) {
|
||||
struct openprom_range *rp = &sc->sc_range[i];
|
||||
|
||||
if (rp->or_child_space != slot)
|
||||
continue;
|
||||
|
||||
return (bus_space_mmap(sc->sc_bustag,
|
||||
BUS_ADDR(rp->or_parent_space,
|
||||
rp->or_parent_base + BUS_ADDR_PADDR(ba)),
|
||||
off, prot, flags));
|
||||
}
|
||||
|
||||
return (-1);
|
||||
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
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: autoconf.h,v 1.34 2002/03/11 16:06:42 pk Exp $ */
|
||||
/* $NetBSD: autoconf.h,v 1.35 2002/08/25 16:05:42 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
|
||||
|
@ -206,3 +206,6 @@ void mountroot_hook_establish __P((void (*) __P((struct device *)),
|
|||
void bootstrap __P((void));
|
||||
struct device *getdevunit __P((char *, int));
|
||||
int romgetcursoraddr __P((int **, int **));
|
||||
|
||||
int bus_translate_address_generic(struct openprom_range *, int,
|
||||
bus_addr_t, bus_addr_t *);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: autoconf.c,v 1.172 2002/08/23 02:53:11 thorpej Exp $ */
|
||||
/* $NetBSD: autoconf.c,v 1.173 2002/08/25 16:05:43 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996
|
||||
|
@ -2089,3 +2089,29 @@ 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 */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: cpuunit.c,v 1.1 2002/08/23 18:00:47 thorpej Exp $ */
|
||||
/* $NetBSD: cpuunit.c,v 1.2 2002/08/25 16:05:44 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||
|
@ -45,10 +45,10 @@
|
|||
#include <sys/systm.h>
|
||||
#include <sys/device.h>
|
||||
|
||||
#include <machine/autoconf.h>
|
||||
#include <machine/bus.h>
|
||||
|
||||
#include <sparc/sparc/cpuunitvar.h>
|
||||
#include <machine/autoconf.h>
|
||||
|
||||
struct cpuunit_softc {
|
||||
struct device sc_dev;
|
||||
|
@ -193,28 +193,6 @@ cpuunit_destroy_attach_args(struct cpuunit_attach_args *cpua)
|
|||
free(cpua->cpua_type, M_DEVBUF);
|
||||
}
|
||||
|
||||
static int
|
||||
cpuunit_translate_address(struct cpuunit_softc *sc, bus_addr_t addr,
|
||||
bus_addr_t *addrp)
|
||||
{
|
||||
int space = BUS_ADDR_IOSPACE(addr);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sc->sc_nrange; i++) {
|
||||
struct openprom_range *rp = &sc->sc_range[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);
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -223,7 +201,8 @@ cpuunit_bus_map(bus_space_tag_t t, bus_addr_t ba, bus_size_t size,
|
|||
bus_addr_t addr;
|
||||
int error;
|
||||
|
||||
error = cpuunit_translate_address(sc, ba, &addr);
|
||||
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));
|
||||
|
@ -237,7 +216,8 @@ cpuunit_bus_mmap(bus_space_tag_t t, bus_addr_t ba, off_t off, int prot,
|
|||
bus_addr_t addr;
|
||||
int error;
|
||||
|
||||
error = cpuunit_translate_address(sc, ba, &addr);
|
||||
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));
|
||||
|
|
Loading…
Reference in New Issue