From 66a4653f8ad44d41de3f41a0f54aa85b92da75ee Mon Sep 17 00:00:00 2001 From: pk Date: Sun, 27 Jun 2004 18:24:46 +0000 Subject: [PATCH] Always use `full bus space'. In order to implement this more efficiently, require that all bus tags have pointers to bus_space_read/write functions, i.e. no run-time hunting for the first "upstream" implementation. Since this changes the way bus tags should be constructed it makes sense to do the same thing for the rest of the bus space methods. So, now bus space tags are generally constructed by copying the parent's bus tag and then overriding the methods that the bus driver needs to handle, instead of starting with an empty bus tag and fiiling in only the fields needed. --- sys/arch/sparc/dev/obio.c | 37 ++------- sys/arch/sparc/dev/sbus.c | 10 +-- sys/arch/sparc/include/autoconf.h | 4 +- sys/arch/sparc/include/bus.h | 134 +++++------------------------- sys/arch/sparc/sparc/cpuunit.c | 22 ++--- sys/arch/sparc/sparc/machdep.c | 132 ++++++++++++++++++++++------- 6 files changed, 148 insertions(+), 191 deletions(-) diff --git a/sys/arch/sparc/dev/obio.c b/sys/arch/sparc/dev/obio.c index f47f576692d5..a40a3917356a 100644 --- a/sys/arch/sparc/dev/obio.c +++ b/sys/arch/sparc/dev/obio.c @@ -1,4 +1,4 @@ -/* $NetBSD: obio.c,v 1.64 2003/07/15 00:04:55 lukem Exp $ */ +/* $NetBSD: obio.c,v 1.65 2004/06/27 18:24:47 pk Exp $ */ /*- * Copyright (c) 1997,1998 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.64 2003/07/15 00:04:55 lukem Exp $"); +__KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.65 2004/06/27 18:24:47 pk Exp $"); #include #include @@ -99,28 +99,8 @@ static int _obio_bus_map __P((bus_space_tag_t, bus_addr_t, bus_size_t, int, vaddr_t, bus_space_handle_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 */ - NULL, /* bus_space_barrier */ - obio_bus_mmap, /* bus_space_mmap */ - NULL, /* bus_intr_establish */ -#if __FULL_SPARC_BUS_SPACE - NULL, /* read_1 */ - NULL, /* read_2 */ - NULL, /* read_4 */ - NULL, /* read_8 */ - NULL, /* write_1 */ - NULL, /* write_2 */ - NULL, /* write_4 */ - NULL, /* write_8 */ -#endif -}; +/* There's at most one obio bus, so we can allocate the bus tag statically */ +static struct sparc_bus_space_tag obio_space_tag; #endif /* @@ -174,8 +154,11 @@ obioattach(parent, self, aux) sc->sc_bustag = ma->ma_bustag; sc->sc_dmatag = ma->ma_dmatag; + memcpy(&obio_space_tag, sc->sc_bustag, sizeof(obio_space_tag)); obio_space_tag.cookie = sc; obio_space_tag.parent = sc->sc_bustag; + obio_space_tag.sparc_bus_map = _obio_bus_map; + obio_space_tag.sparc_bus_mmap = obio_bus_mmap; oa.ma = ma; @@ -245,13 +228,12 @@ _obio_bus_map(t, ba, size, flags, va, hp) vaddr_t va; bus_space_handle_t *hp; { - struct obio4_softc *sc = t->cookie; if ((flags & OBIO_BUS_MAP_USE_ROM) != 0 && obio_find_rom_map(ba, size, hp) == 0) return (0); - return (bus_space_map2(sc->sc_bustag, ba, size, flags, va, hp)); + return (bus_space_map2(t->parent, ba, size, flags, va, hp)); } paddr_t @@ -262,9 +244,8 @@ obio_bus_mmap(t, ba, off, prot, flags) int prot; int flags; { - struct obio4_softc *sc = t->cookie; - return (bus_space_mmap(sc->sc_bustag, ba, off, prot, flags)); + return (bus_space_mmap(t->parent, ba, off, prot, flags)); } int diff --git a/sys/arch/sparc/dev/sbus.c b/sys/arch/sparc/dev/sbus.c index ad92433baa60..31c85020a04b 100644 --- a/sys/arch/sparc/dev/sbus.c +++ b/sys/arch/sparc/dev/sbus.c @@ -1,4 +1,4 @@ -/* $NetBSD: sbus.c,v 1.60 2004/03/17 17:04:59 pk Exp $ */ +/* $NetBSD: sbus.c,v 1.61 2004/06/27 18:24:47 pk Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -81,7 +81,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sbus.c,v 1.60 2004/03/17 17:04:59 pk Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sbus.c,v 1.61 2004/06/27 18:24:47 pk Exp $"); #include #include @@ -703,12 +703,12 @@ sbus_alloc_bustag(sc) if (sbt == NULL) return (NULL); - bzero(sbt, sizeof *sbt); + memcpy(sbt, sc->sc_bustag, sizeof(*sbt)); sbt->cookie = sc; sbt->parent = sc->sc_bustag; - 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; + sbt->ranges = NULL; + sbt->nranges = 0; return (sbt); } diff --git a/sys/arch/sparc/include/autoconf.h b/sys/arch/sparc/include/autoconf.h index 65b94f89dc22..3614578ae216 100644 --- a/sys/arch/sparc/include/autoconf.h +++ b/sys/arch/sparc/include/autoconf.h @@ -1,4 +1,4 @@ -/* $NetBSD: autoconf.h,v 1.37 2003/08/07 16:29:38 agc Exp $ */ +/* $NetBSD: autoconf.h,v 1.38 2004/06/27 18:24:46 pk Exp $ */ /*- * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. @@ -186,4 +186,4 @@ 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 *); + bus_addr_t *); diff --git a/sys/arch/sparc/include/bus.h b/sys/arch/sparc/include/bus.h index 48fd93fe1dfb..7753036eaf07 100644 --- a/sys/arch/sparc/include/bus.h +++ b/sys/arch/sparc/include/bus.h @@ -1,4 +1,4 @@ -/* $NetBSD: bus.h,v 1.40 2003/11/16 11:09:07 pk Exp $ */ +/* $NetBSD: bus.h,v 1.41 2004/06/27 18:24:46 pk Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc. @@ -86,20 +86,6 @@ typedef u_long bus_size_t; #define BUS_ADDR(io, pa) \ ((((u_int64_t)(u_int32_t)(io))<<32) | (u_int32_t)(pa)) -/* - * If __FULL_SPARC_BUS_SPACE is not defined, define it to 0. We normally - * don't need to deal with bus_space_{read,write}*() needing to be - * functions rather than simple memory accesses. We expose the option - * to the user via FULL_SPARC_BUS_SPACE. - */ -#ifdef FULL_SPARC_BUS_SPACE -#define __FULL_SPARC_BUS_SPACE 1 -#endif - -#ifndef __FULL_SPARC_BUS_SPACE -#define __FULL_SPARC_BUS_SPACE 0 -#endif - #define __BUS_SPACE_HAS_STREAM_METHODS 1 /* @@ -160,7 +146,6 @@ struct sparc_bus_space_tag { void *, /*handler arg*/ void (*)(void))); /*optional fast vector*/ -#if __FULL_SPARC_BUS_SPACE u_int8_t (*sparc_read_1) __P(( bus_space_tag_t space, bus_space_handle_t handle, @@ -204,26 +189,8 @@ struct sparc_bus_space_tag { bus_space_handle_t handle, bus_size_t offset, u_int64_t value)); -#endif }; -#if 0 -/* - * The following macro could be used to generate the bus_space*() functions - * but it uses a gcc extension and is ANSI-only. -#define PROTO_bus_space_xxx __P((bus_space_tag_t t, ...)) -#define RETURNTYPE_bus_space_xxx void * -#define BUSFUN(name, returntype, t, args...) \ - __inline__ RETURNTYPE_##name \ - bus_##name PROTO_##name \ - { \ - while (t->sparc_##name == NULL) \ - t = t->parent; \ - return (*(t)->sparc_##name)(t, args); \ - } - */ -#endif - /* * Bus space function prototypes. * In bus_space_map2(), supply a special virtual address only if you @@ -281,12 +248,6 @@ static void *bus_intr_establish2 __P(( void (*)(void))); /*optional fast vector*/ -/* This macro finds the first "upstream" implementation of method `f' */ -#define _BS_CALL(t,f) \ - while (t->f == NULL) \ - t = t->parent; \ - return (*(t)->f) - static __inline__ int bus_space_map(t, a, s, f, hp) bus_space_tag_t t; @@ -295,7 +256,7 @@ bus_space_map(t, a, s, f, hp) int f; bus_space_handle_t *hp; { - _BS_CALL(t, sparc_bus_map)(t, a, s, f, (vaddr_t)0, hp); + return (*t->sparc_bus_map)(t, a, s, f, (vaddr_t)0, hp); } static __inline__ int @@ -307,7 +268,7 @@ bus_space_map2(t, a, s, f, v, hp) vaddr_t v; bus_space_handle_t *hp; { - _BS_CALL(t, sparc_bus_map)(t, a, s, f, v, hp); + return (*t->sparc_bus_map)(t, a, s, f, v, hp); } static __inline__ int @@ -316,7 +277,7 @@ bus_space_unmap(t, h, s) bus_space_handle_t h; bus_size_t s; { - _BS_CALL(t, sparc_bus_unmap)(t, h, s); + return (*t->sparc_bus_unmap)(t, h, s); } static __inline__ int @@ -327,7 +288,7 @@ bus_space_subregion(t, h, o, s, hp) bus_size_t s; bus_space_handle_t *hp; { - _BS_CALL(t, sparc_bus_subregion)(t, h, o, s, hp); + return (*t->sparc_bus_subregion)(t, h, o, s, hp); } static __inline__ paddr_t @@ -338,7 +299,7 @@ bus_space_mmap(t, a, o, p, f) int p; int f; { - _BS_CALL(t, sparc_bus_mmap)(t, a, o, p, f); + return (*t->sparc_bus_mmap)(t, a, o, p, f); } static __inline__ void * @@ -349,7 +310,7 @@ bus_intr_establish(t, p, l, h, a) int (*h)__P((void *)); void *a; { - _BS_CALL(t, sparc_intr_establish)(t, p, l, h, a, NULL); + return (*t->sparc_intr_establish)(t, p, l, h, a, NULL); } static __inline__ void * @@ -361,7 +322,7 @@ bus_intr_establish2(t, p, l, h, a, v) void *a; void (*v)__P((void)); { - _BS_CALL(t, sparc_intr_establish)(t, p, l, h, a, v); + return (*t->sparc_intr_establish)(t, p, l, h, a, v); } static __inline__ void @@ -372,7 +333,7 @@ bus_space_barrier(t, h, o, s, f) bus_size_t s; int f; { - _BS_CALL(t, sparc_bus_barrier)(t, h, o, s, f); + (*t->sparc_bus_barrier)(t, h, o, s, f); } @@ -452,18 +413,13 @@ static u_int64_t bus_space_read_8 __P((bus_space_tag_t, bus_space_handle_t, bus_size_t)); -#if __FULL_SPARC_BUS_SPACE - static __inline__ u_int8_t bus_space_read_1(t, h, o) bus_space_tag_t t; bus_space_handle_t h; bus_size_t o; { - __insn_barrier(); - return t->sparc_read_1 ? - (*t->sparc_read_1)(t, h, o) : - bus_space_read_1_real(t, h, o); + return (*t->sparc_read_1)(t, h, o); } static __inline__ u_int16_t @@ -472,10 +428,7 @@ bus_space_read_2(t, h, o) bus_space_handle_t h; bus_size_t o; { - __insn_barrier(); - return t->sparc_read_2 ? - (*t->sparc_read_2)(t, h, o) : - bus_space_read_2_real(t, h, o); + return (*t->sparc_read_2)(t, h, o); } static __inline__ u_int32_t @@ -484,10 +437,7 @@ bus_space_read_4(t, h, o) bus_space_handle_t h; bus_size_t o; { - __insn_barrier(); - return t->sparc_read_4 ? - (*t->sparc_read_4)(t, h, o) : - bus_space_read_4_real(t, h, o); + return (*t->sparc_read_4)(t, h, o); } static __inline__ u_int64_t @@ -496,14 +446,10 @@ bus_space_read_8(t, h, o) bus_space_handle_t h; bus_size_t o; { - __insn_barrier(); - return t->sparc_read_8 ? - (*t->sparc_read_8)(t, h, o) : - bus_space_read_8_real(t, h, o); + return (*t->sparc_read_8)(t, h, o); } -#else /* __FULL_SPARC_BUS_SPACE */ - +#if __SLIM_SPARC_BUS_SPACE static __inline__ u_int8_t bus_space_read_1(t, h, o) bus_space_tag_t t; @@ -544,7 +490,7 @@ bus_space_read_8(t, h, o) return bus_space_read_8_real(t, h, o); } -#endif /* __FULL_SPARC_BUS_SPACE */ +#endif /* __SLIM_SPARC_BUS_SPACE */ #define bus_space_read_stream_1 bus_space_read_1_real #define bus_space_read_stream_2 bus_space_read_2_real @@ -596,8 +542,6 @@ static void bus_space_write_8 __P((bus_space_tag_t, bus_size_t, const u_int64_t)); -#if __FULL_SPARC_BUS_SPACE - static __inline__ void bus_space_write_1(t, h, o, v) bus_space_tag_t t; @@ -605,11 +549,7 @@ bus_space_write_1(t, h, o, v) bus_size_t o; u_int8_t v; { - __insn_barrier(); - if (t->sparc_write_1) - (*t->sparc_write_1)(t, h, o, v); - else - bus_space_write_1_real(t, h, o, v); + (*t->sparc_write_1)(t, h, o, v); } static __inline__ void @@ -619,11 +559,7 @@ bus_space_write_2(t, h, o, v) bus_size_t o; u_int16_t v; { - __insn_barrier(); - if (t->sparc_write_2) - (*t->sparc_write_2)(t, h, o, v); - else - bus_space_write_2_real(t, h, o, v); + (*t->sparc_write_2)(t, h, o, v); } static __inline__ void @@ -633,11 +569,7 @@ bus_space_write_4(t, h, o, v) bus_size_t o; u_int32_t v; { - __insn_barrier(); - if (t->sparc_write_4) - (*t->sparc_write_4)(t, h, o, v); - else - bus_space_write_4_real(t, h, o, v); + (*t->sparc_write_4)(t, h, o, v); } static __inline__ void @@ -647,14 +579,10 @@ bus_space_write_8(t, h, o, v) bus_size_t o; u_int64_t v; { - __insn_barrier(); - if (t->sparc_write_8) - (*t->sparc_write_8)(t, h, o, v); - else - bus_space_write_8_real(t, h, o, v); + (*t->sparc_write_8)(t, h, o, v); } -#else /* __FULL_SPARC_BUS_SPACE */ +#if __SLIM_SPARC_BUS_SPACE static __inline__ void bus_space_write_1(t, h, o, v) @@ -700,7 +628,7 @@ bus_space_write_8(t, h, o, v) bus_space_write_8_real(t, h, o, v); } -#endif /* __FULL_SPARC_BUS_SPACE */ +#endif /* __SLIM_SPARC_BUS_SPACE */ #define bus_space_write_stream_1 bus_space_write_1_real #define bus_space_write_stream_2 bus_space_write_2_real @@ -785,14 +713,6 @@ bus_space_read_multi_8(t, h, o, a, c) *a++ = bus_space_read_8(t, h, o); } -#ifndef __FULL_SPARC_BUS_SPACE -#define bus_space_read_multi_stream_1 bus_space_read_multi_1 -#define bus_space_read_multi_stream_2 bus_space_read_multi_2 -#define bus_space_read_multi_stream_4 bus_space_read_multi_4 -#define bus_space_read_multi_stream_8 bus_space_read_multi_8 - -#else - #define bus_space_read_multi_stream_1 bus_space_read_multi_1 static void bus_space_read_multi_stream_2 __P((bus_space_tag_t, @@ -846,8 +766,6 @@ bus_space_read_multi_stream_8(t, h, o, a, c) *a++ = bus_space_read_8_real(t, h, o); } -#endif /* __FULL_SPARC_BUS_SPACE */ - /* * void bus_space_write_multi_N __P((bus_space_tag_t tag, * bus_space_handle_t bsh, bus_size_t offset, @@ -920,15 +838,6 @@ bus_space_write_multi_8(t, h, o, a, c) bus_space_write_8(t, h, o, *a++); } -#ifndef __FULL_SPARC_BUS_SPACE - -#define bus_space_write_multi_stream_1 bus_space_write_multi_1 -#define bus_space_write_multi_stream_2 bus_space_write_multi_2 -#define bus_space_write_multi_stream_4 bus_space_write_multi_4 -#define bus_space_write_multi_stream_8 bus_space_write_multi_8 - -#else - #define bus_space_write_multi_stream_1 bus_space_write_multi_1 static void bus_space_write_multi_stream_2 __P((bus_space_tag_t, @@ -980,7 +889,6 @@ bus_space_write_multi_stream_8(t, h, o, a, c) bus_space_write_8_real(t, h, o, *a++); } -#endif /* __FULL_SPARC_BUS_SPACE */ /* * void bus_space_set_multi_N __P((bus_space_tag_t tag, diff --git a/sys/arch/sparc/sparc/cpuunit.c b/sys/arch/sparc/sparc/cpuunit.c index 5341a5a4ff6b..480e2ac64ead 100644 --- a/sys/arch/sparc/sparc/cpuunit.c +++ b/sys/arch/sparc/sparc/cpuunit.c @@ -1,4 +1,4 @@ -/* $NetBSD: cpuunit.c,v 1.10 2004/03/17 17:04:59 pk Exp $ */ +/* $NetBSD: cpuunit.c,v 1.11 2004/06/27 18:24:46 pk Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cpuunit.c,v 1.10 2004/03/17 17:04:59 pk Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cpuunit.c,v 1.11 2004/06/27 18:24:46 pk Exp $"); #include #include @@ -93,6 +93,7 @@ cpuunit_attach(struct device *parent, struct device *self, void *aux) struct cpuunit_softc *sc = (void *) self; struct mainbus_attach_args *ma = aux; int node, error; + bus_space_tag_t sbt; sc->sc_node = ma->ma_node; sc->sc_st = ma->ma_bustag; @@ -105,19 +106,18 @@ cpuunit_attach(struct device *parent, struct device *self, void *aux) /* * Initialize the bus space tag we pass on to our children. */ - sc->sc_bustag = malloc(sizeof(*sc->sc_bustag), M_DEVBUF, - M_WAITOK|M_ZERO); - sc->sc_bustag->cookie = sc; - sc->sc_bustag->parent = sc->sc_st; - sc->sc_bustag->sparc_bus_map = sc->sc_st->sparc_bus_map; - sc->sc_bustag->sparc_bus_mmap = sc->sc_st->sparc_bus_mmap; + sbt = sc->sc_bustag = malloc(sizeof(*sbt), M_DEVBUF, M_WAITOK); + memcpy(sbt, sc->sc_st, sizeof(*sbt)); + sbt->cookie = sc; + sbt->parent = sc->sc_st; + sbt->nranges = 0; + sbt->ranges = NULL; /* * Collect address translations from the OBP. */ error = prom_getprop(sc->sc_node, "ranges", - sizeof(struct openprom_range), &sc->sc_bustag->nranges, - &sc->sc_bustag->ranges); + sizeof(struct openprom_range), &sbt->nranges, &sbt->ranges); if (error) { printf("%s: error %d getting \"ranges\" property\n", sc->sc_dev.dv_xname, error); @@ -129,7 +129,7 @@ cpuunit_attach(struct device *parent, struct device *self, void *aux) node = nextsibling(node)) { struct cpuunit_attach_args cpua; - if (cpuunit_setup_attach_args(sc, sc->sc_bustag, node, &cpua)) + if (cpuunit_setup_attach_args(sc, sbt, node, &cpua)) panic("cpuunit_attach: failed to set up attach args"); (void) config_found(&sc->sc_dev, &cpua, cpuunit_print); diff --git a/sys/arch/sparc/sparc/machdep.c b/sys/arch/sparc/sparc/machdep.c index 6eba0751bb79..0c82d7268e71 100644 --- a/sys/arch/sparc/sparc/machdep.c +++ b/sys/arch/sparc/sparc/machdep.c @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.248 2004/04/27 11:25:24 pk Exp $ */ +/* $NetBSD: machdep.c,v 1.249 2004/06/27 18:24:46 pk Exp $ */ /*- * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc. @@ -78,7 +78,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.248 2004/04/27 11:25:24 pk Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.249 2004/06/27 18:24:46 pk Exp $"); #include "opt_compat_netbsd.h" #include "opt_compat_sunos.h" @@ -2142,9 +2142,9 @@ static void sparc_bus_barrier __P(( bus_space_tag_t, bus_space_handle_t, */ int bus_translate_address_generic(struct openprom_range *ranges, int nranges, - bus_addr_t addr, bus_addr_t *addrp) + bus_addr_t *bap) { - int i, space = BUS_ADDR_IOSPACE(addr); + int i, space = BUS_ADDR_IOSPACE(*bap); for (i = 0; i < nranges; i++) { struct openprom_range *rp = &ranges[i]; @@ -2153,8 +2153,8 @@ bus_translate_address_generic(struct openprom_range *ranges, int nranges, 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)); + *bap = BUS_ADDR(rp->or_parent_space, + rp->or_parent_base + BUS_ADDR_PADDR(*bap)); return (0); } @@ -2172,17 +2172,28 @@ sparc_bus_map(t, ba, size, flags, va, hp) vaddr_t v; paddr_t pa; unsigned int pmtype; + bus_space_tag_t pt; static vaddr_t iobase; - if (t->ranges != NULL) { - bus_addr_t addr; - int error; + /* + * This base class bus map function knows about address range + * translation so bus drivers that need no other special + * handling can just keep this method in their tags. + * + * We expect to resolve range translations iteratively, but allow + * for recursion just in case. + */ + while ((pt = t->parent) != NULL) { + if (t->ranges != NULL) { + int error; - error = bus_translate_address_generic(t->ranges, t->nranges, - ba, &addr); - if (error) - return (error); - return (bus_space_map2(t->parent, addr, size, flags, va, hp)); + if ((error = bus_translate_address_generic( + t->ranges, t->nranges, &ba)) != 0) + return (error); + } + if (pt->sparc_bus_map != sparc_bus_map) + return (bus_space_map2(pt, ba, size, flags, va, hp)); + t = pt; } if (iobase == 0) @@ -2256,16 +2267,22 @@ sparc_bus_mmap(t, ba, off, prot, flags) { u_int pmtype; paddr_t pa; + bus_space_tag_t pt; - if (t->ranges != NULL) { - bus_addr_t addr; - int error; + /* + * Base class bus mmap function; see also sparc_bus_map + */ + while ((pt = t->parent) != NULL) { + if (t->ranges != NULL) { + 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)); + if ((error = bus_translate_address_generic( + t->ranges, t->nranges, &ba)) != 0) + return (-1); + } + if (pt->sparc_bus_mmap != sparc_bus_mmap) + return (bus_space_mmap(pt, ba, off, prot, flags)); + t = pt; } pmtype = PMAP_IOENC(BUS_ADDR_IOSPACE(ba)); @@ -2336,6 +2353,58 @@ void sparc_bus_barrier (t, h, offset, size, flags) return; } +static u_int8_t +sparc_bus_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) +{ + return bus_space_read_1_real(t, h, o); +} + +static u_int16_t +sparc_bus_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) +{ + return bus_space_read_2_real(t, h, o); +} + +static u_int32_t +sparc_bus_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) +{ + return bus_space_read_4_real(t, h, o); +} + +static u_int64_t +sparc_bus_space_read_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) +{ + return bus_space_read_8_real(t, h, o); +} + +static void +sparc_bus_space_write_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, + u_int8_t v) +{ + bus_space_write_1_real(t, h, o, v); +} + +static void +sparc_bus_space_write_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, + u_int16_t v) +{ + bus_space_write_2_real(t, h, o, v); +} + +static void +sparc_bus_space_write_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, + u_int32_t v) +{ + bus_space_write_4_real(t, h, o, v); +} + +static void +sparc_bus_space_write_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, + u_int64_t v) +{ + bus_space_write_8_real(t, h, o, v); +} + struct sparc_bus_space_tag mainbus_space_tag = { NULL, /* cookie */ NULL, /* parent bus tag */ @@ -2347,14 +2416,13 @@ struct sparc_bus_space_tag mainbus_space_tag = { sparc_bus_barrier, /* bus_space_barrier */ sparc_bus_mmap, /* bus_space_mmap */ sparc_mainbus_intr_establish, /* bus_intr_establish */ -#if __FULL_SPARC_BUS_SPACE - NULL, /* read_1 */ - NULL, /* read_2 */ - NULL, /* read_4 */ - NULL, /* read_8 */ - NULL, /* write_1 */ - NULL, /* write_2 */ - NULL, /* write_4 */ - NULL /* write_8 */ -#endif + + sparc_bus_space_read_1, /* bus_space_read_1 */ + sparc_bus_space_read_2, /* bus_space_read_2 */ + sparc_bus_space_read_4, /* bus_space_read_4 */ + sparc_bus_space_read_8, /* bus_space_read_8 */ + sparc_bus_space_write_1, /* bus_space_write_1 */ + sparc_bus_space_write_2, /* bus_space_write_2 */ + sparc_bus_space_write_4, /* bus_space_write_4 */ + sparc_bus_space_write_8 /* bus_space_write_8 */ };