Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/sparc Add a generic function to translate a device ...



details:   https://anonhg.NetBSD.org/src/rev/e60cc9bf8554
branches:  trunk
changeset: 535657:e60cc9bf8554
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sun Aug 25 16:05:41 2002 +0000

description:
Add a generic function to translate a device address using a
parent's "ranges" property, and use it.

diffstat:

 sys/arch/sparc/dev/bootbus.c      |  32 ++++--------------------
 sys/arch/sparc/dev/sbus.c         |  50 ++++++++++++--------------------------
 sys/arch/sparc/include/autoconf.h |   5 +++-
 sys/arch/sparc/sparc/autoconf.c   |  28 +++++++++++++++++++++-
 sys/arch/sparc/sparc/cpuunit.c    |  32 ++++--------------------
 5 files changed, 59 insertions(+), 88 deletions(-)

diffs (282 lines):

diff -r 0c05e9f49017 -r e60cc9bf8554 sys/arch/sparc/dev/bootbus.c
--- a/sys/arch/sparc/dev/bootbus.c      Sun Aug 25 16:02:53 2002 +0000
+++ b/sys/arch/sparc/dev/bootbus.c      Sun Aug 25 16:05:41 2002 +0000
@@ -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"
 
@@ -235,28 +235,6 @@
 }
 
 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 @@
        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 @@
        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));
diff -r 0c05e9f49017 -r e60cc9bf8554 sys/arch/sparc/dev/sbus.c
--- a/sys/arch/sparc/dev/sbus.c Sun Aug 25 16:02:53 2002 +0000
+++ b/sys/arch/sparc/dev/sbus.c Sun Aug 25 16:05:41 2002 +0000
@@ -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 @@
        bus_space_handle_t *hp;
 {
        struct sbus_softc *sc = t->cookie;
-       int slot = BUS_ADDR_IOSPACE(ba);
-       int i;
-
-       for (i = 0; i < sc->sc_nrange; i++) {
-               struct openprom_range *rp = &sc->sc_range[i];
-
-               if (rp->or_child_space != slot)
-                       continue;
+       bus_addr_t addr;
+       int error;
 
-               /* 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 @@
        int flags;
 {
        struct sbus_softc *sc = t->cookie;
-       int slot = BUS_ADDR_IOSPACE(ba);
-       int i;
-
-       for (i = 0; i < sc->sc_nrange; i++) {
-               struct openprom_range *rp = &sc->sc_range[i];
+       bus_addr_t addr;
+       int error;
 
-               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
diff -r 0c05e9f49017 -r e60cc9bf8554 sys/arch/sparc/include/autoconf.h
--- a/sys/arch/sparc/include/autoconf.h Sun Aug 25 16:02:53 2002 +0000
+++ b/sys/arch/sparc/include/autoconf.h Sun Aug 25 16:05:41 2002 +0000
@@ -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   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 *);
diff -r 0c05e9f49017 -r e60cc9bf8554 sys/arch/sparc/sparc/autoconf.c
--- a/sys/arch/sparc/sparc/autoconf.c   Sun Aug 25 16:02:53 2002 +0000
+++ b/sys/arch/sparc/sparc/autoconf.c   Sun Aug 25 16:05:41 2002 +0000
@@ -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 @@
        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 */
diff -r 0c05e9f49017 -r e60cc9bf8554 sys/arch/sparc/sparc/cpuunit.c
--- a/sys/arch/sparc/sparc/cpuunit.c    Sun Aug 25 16:02:53 2002 +0000
+++ b/sys/arch/sparc/sparc/cpuunit.c    Sun Aug 25 16:05:41 2002 +0000
@@ -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;
@@ -194,28 +194,6 @@
 }
 
 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 @@
        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 @@
        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));



Home | Main Index | Thread Index | Old Index