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.
This commit is contained in:
pk 2004-06-27 18:24:46 +00:00
parent f142712a67
commit 66a4653f8a
6 changed files with 148 additions and 191 deletions

View File

@ -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. * Copyright (c) 1997,1998 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__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 <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
@ -99,28 +99,8 @@ static int _obio_bus_map __P((bus_space_tag_t, bus_addr_t,
bus_size_t, int, bus_size_t, int,
vaddr_t, bus_space_handle_t *)); vaddr_t, bus_space_handle_t *));
static struct sparc_bus_space_tag obio_space_tag = { /* There's at most one obio bus, so we can allocate the bus tag statically */
NULL, /* cookie */ static struct sparc_bus_space_tag obio_space_tag;
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
};
#endif #endif
/* /*
@ -174,8 +154,11 @@ obioattach(parent, self, aux)
sc->sc_bustag = ma->ma_bustag; sc->sc_bustag = ma->ma_bustag;
sc->sc_dmatag = ma->ma_dmatag; 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.cookie = sc;
obio_space_tag.parent = sc->sc_bustag; 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; oa.ma = ma;
@ -245,13 +228,12 @@ _obio_bus_map(t, ba, size, flags, va, hp)
vaddr_t va; vaddr_t va;
bus_space_handle_t *hp; bus_space_handle_t *hp;
{ {
struct obio4_softc *sc = t->cookie;
if ((flags & OBIO_BUS_MAP_USE_ROM) != 0 && if ((flags & OBIO_BUS_MAP_USE_ROM) != 0 &&
obio_find_rom_map(ba, size, hp) == 0) obio_find_rom_map(ba, size, hp) == 0)
return (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 paddr_t
@ -262,9 +244,8 @@ obio_bus_mmap(t, ba, off, prot, flags)
int prot; int prot;
int flags; 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 int

View File

@ -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. * Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -81,7 +81,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__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 <sys/param.h> #include <sys/param.h>
#include <sys/malloc.h> #include <sys/malloc.h>
@ -703,12 +703,12 @@ sbus_alloc_bustag(sc)
if (sbt == NULL) if (sbt == NULL)
return (NULL); return (NULL);
bzero(sbt, sizeof *sbt); memcpy(sbt, sc->sc_bustag, sizeof(*sbt));
sbt->cookie = sc; sbt->cookie = sc;
sbt->parent = sc->sc_bustag; 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->sparc_intr_establish = sbus_intr_establish;
sbt->ranges = NULL;
sbt->nranges = 0;
return (sbt); return (sbt);
} }

View File

@ -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. * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@ -186,4 +186,4 @@ struct device *getdevunit __P((char *, int));
int romgetcursoraddr __P((int **, int **)); int romgetcursoraddr __P((int **, int **));
int bus_translate_address_generic(struct openprom_range *, int, int bus_translate_address_generic(struct openprom_range *, int,
bus_addr_t, bus_addr_t *); bus_addr_t *);

View File

@ -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. * 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) \ #define BUS_ADDR(io, pa) \
((((u_int64_t)(u_int32_t)(io))<<32) | (u_int32_t)(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 #define __BUS_SPACE_HAS_STREAM_METHODS 1
/* /*
@ -160,7 +146,6 @@ struct sparc_bus_space_tag {
void *, /*handler arg*/ void *, /*handler arg*/
void (*)(void))); /*optional fast vector*/ void (*)(void))); /*optional fast vector*/
#if __FULL_SPARC_BUS_SPACE
u_int8_t (*sparc_read_1) __P(( u_int8_t (*sparc_read_1) __P((
bus_space_tag_t space, bus_space_tag_t space,
bus_space_handle_t handle, bus_space_handle_t handle,
@ -204,26 +189,8 @@ struct sparc_bus_space_tag {
bus_space_handle_t handle, bus_space_handle_t handle,
bus_size_t offset, bus_size_t offset,
u_int64_t value)); 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. * Bus space function prototypes.
* In bus_space_map2(), supply a special virtual address only if you * 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*/ 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 static __inline__ int
bus_space_map(t, a, s, f, hp) bus_space_map(t, a, s, f, hp)
bus_space_tag_t t; bus_space_tag_t t;
@ -295,7 +256,7 @@ bus_space_map(t, a, s, f, hp)
int f; int f;
bus_space_handle_t *hp; 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 static __inline__ int
@ -307,7 +268,7 @@ bus_space_map2(t, a, s, f, v, hp)
vaddr_t v; vaddr_t v;
bus_space_handle_t *hp; 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 static __inline__ int
@ -316,7 +277,7 @@ bus_space_unmap(t, h, s)
bus_space_handle_t h; bus_space_handle_t h;
bus_size_t s; bus_size_t s;
{ {
_BS_CALL(t, sparc_bus_unmap)(t, h, s); return (*t->sparc_bus_unmap)(t, h, s);
} }
static __inline__ int static __inline__ int
@ -327,7 +288,7 @@ bus_space_subregion(t, h, o, s, hp)
bus_size_t s; bus_size_t s;
bus_space_handle_t *hp; 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 static __inline__ paddr_t
@ -338,7 +299,7 @@ bus_space_mmap(t, a, o, p, f)
int p; int p;
int f; 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 * static __inline__ void *
@ -349,7 +310,7 @@ bus_intr_establish(t, p, l, h, a)
int (*h)__P((void *)); int (*h)__P((void *));
void *a; 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 * static __inline__ void *
@ -361,7 +322,7 @@ bus_intr_establish2(t, p, l, h, a, v)
void *a; void *a;
void (*v)__P((void)); 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 static __inline__ void
@ -372,7 +333,7 @@ bus_space_barrier(t, h, o, s, f)
bus_size_t s; bus_size_t s;
int f; 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_space_handle_t,
bus_size_t)); bus_size_t));
#if __FULL_SPARC_BUS_SPACE
static __inline__ u_int8_t static __inline__ u_int8_t
bus_space_read_1(t, h, o) bus_space_read_1(t, h, o)
bus_space_tag_t t; bus_space_tag_t t;
bus_space_handle_t h; bus_space_handle_t h;
bus_size_t o; bus_size_t o;
{ {
__insn_barrier(); return (*t->sparc_read_1)(t, h, o);
return t->sparc_read_1 ?
(*t->sparc_read_1)(t, h, o) :
bus_space_read_1_real(t, h, o);
} }
static __inline__ u_int16_t static __inline__ u_int16_t
@ -472,10 +428,7 @@ bus_space_read_2(t, h, o)
bus_space_handle_t h; bus_space_handle_t h;
bus_size_t o; bus_size_t o;
{ {
__insn_barrier(); return (*t->sparc_read_2)(t, h, o);
return t->sparc_read_2 ?
(*t->sparc_read_2)(t, h, o) :
bus_space_read_2_real(t, h, o);
} }
static __inline__ u_int32_t static __inline__ u_int32_t
@ -484,10 +437,7 @@ bus_space_read_4(t, h, o)
bus_space_handle_t h; bus_space_handle_t h;
bus_size_t o; bus_size_t o;
{ {
__insn_barrier(); return (*t->sparc_read_4)(t, h, o);
return t->sparc_read_4 ?
(*t->sparc_read_4)(t, h, o) :
bus_space_read_4_real(t, h, o);
} }
static __inline__ u_int64_t static __inline__ u_int64_t
@ -496,14 +446,10 @@ bus_space_read_8(t, h, o)
bus_space_handle_t h; bus_space_handle_t h;
bus_size_t o; bus_size_t o;
{ {
__insn_barrier(); return (*t->sparc_read_8)(t, h, o);
return t->sparc_read_8 ?
(*t->sparc_read_8)(t, h, o) :
bus_space_read_8_real(t, h, o);
} }
#else /* __FULL_SPARC_BUS_SPACE */ #if __SLIM_SPARC_BUS_SPACE
static __inline__ u_int8_t static __inline__ u_int8_t
bus_space_read_1(t, h, o) bus_space_read_1(t, h, o)
bus_space_tag_t t; 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); 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_1 bus_space_read_1_real
#define bus_space_read_stream_2 bus_space_read_2_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, bus_size_t,
const u_int64_t)); const u_int64_t));
#if __FULL_SPARC_BUS_SPACE
static __inline__ void static __inline__ void
bus_space_write_1(t, h, o, v) bus_space_write_1(t, h, o, v)
bus_space_tag_t t; bus_space_tag_t t;
@ -605,11 +549,7 @@ bus_space_write_1(t, h, o, v)
bus_size_t o; bus_size_t o;
u_int8_t v; u_int8_t v;
{ {
__insn_barrier(); (*t->sparc_write_1)(t, h, o, v);
if (t->sparc_write_1)
(*t->sparc_write_1)(t, h, o, v);
else
bus_space_write_1_real(t, h, o, v);
} }
static __inline__ void static __inline__ void
@ -619,11 +559,7 @@ bus_space_write_2(t, h, o, v)
bus_size_t o; bus_size_t o;
u_int16_t v; u_int16_t v;
{ {
__insn_barrier(); (*t->sparc_write_2)(t, h, o, v);
if (t->sparc_write_2)
(*t->sparc_write_2)(t, h, o, v);
else
bus_space_write_2_real(t, h, o, v);
} }
static __inline__ void static __inline__ void
@ -633,11 +569,7 @@ bus_space_write_4(t, h, o, v)
bus_size_t o; bus_size_t o;
u_int32_t v; u_int32_t v;
{ {
__insn_barrier(); (*t->sparc_write_4)(t, h, o, v);
if (t->sparc_write_4)
(*t->sparc_write_4)(t, h, o, v);
else
bus_space_write_4_real(t, h, o, v);
} }
static __inline__ void static __inline__ void
@ -647,14 +579,10 @@ bus_space_write_8(t, h, o, v)
bus_size_t o; bus_size_t o;
u_int64_t v; u_int64_t v;
{ {
__insn_barrier(); (*t->sparc_write_8)(t, h, o, v);
if (t->sparc_write_8)
(*t->sparc_write_8)(t, h, o, v);
else
bus_space_write_8_real(t, h, o, v);
} }
#else /* __FULL_SPARC_BUS_SPACE */ #if __SLIM_SPARC_BUS_SPACE
static __inline__ void static __inline__ void
bus_space_write_1(t, h, o, v) 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); 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_1 bus_space_write_1_real
#define bus_space_write_stream_2 bus_space_write_2_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); *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 #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, 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); *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, * void bus_space_write_multi_N __P((bus_space_tag_t tag,
* bus_space_handle_t bsh, bus_size_t offset, * 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++); 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 #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, 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++); 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, * void bus_space_set_multi_N __P((bus_space_tag_t tag,

View File

@ -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. * Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -41,7 +41,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__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 <sys/param.h> #include <sys/param.h>
#include <sys/malloc.h> #include <sys/malloc.h>
@ -93,6 +93,7 @@ cpuunit_attach(struct device *parent, struct device *self, void *aux)
struct cpuunit_softc *sc = (void *) self; struct cpuunit_softc *sc = (void *) self;
struct mainbus_attach_args *ma = aux; struct mainbus_attach_args *ma = aux;
int node, error; int node, error;
bus_space_tag_t sbt;
sc->sc_node = ma->ma_node; sc->sc_node = ma->ma_node;
sc->sc_st = ma->ma_bustag; 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. * Initialize the bus space tag we pass on to our children.
*/ */
sc->sc_bustag = malloc(sizeof(*sc->sc_bustag), M_DEVBUF, sbt = sc->sc_bustag = malloc(sizeof(*sbt), M_DEVBUF, M_WAITOK);
M_WAITOK|M_ZERO); memcpy(sbt, sc->sc_st, sizeof(*sbt));
sc->sc_bustag->cookie = sc; sbt->cookie = sc;
sc->sc_bustag->parent = sc->sc_st; sbt->parent = sc->sc_st;
sc->sc_bustag->sparc_bus_map = sc->sc_st->sparc_bus_map; sbt->nranges = 0;
sc->sc_bustag->sparc_bus_mmap = sc->sc_st->sparc_bus_mmap; sbt->ranges = NULL;
/* /*
* Collect address translations from the OBP. * Collect address translations from the OBP.
*/ */
error = prom_getprop(sc->sc_node, "ranges", error = prom_getprop(sc->sc_node, "ranges",
sizeof(struct openprom_range), &sc->sc_bustag->nranges, sizeof(struct openprom_range), &sbt->nranges, &sbt->ranges);
&sc->sc_bustag->ranges);
if (error) { if (error) {
printf("%s: error %d getting \"ranges\" property\n", printf("%s: error %d getting \"ranges\" property\n",
sc->sc_dev.dv_xname, error); sc->sc_dev.dv_xname, error);
@ -129,7 +129,7 @@ cpuunit_attach(struct device *parent, struct device *self, void *aux)
node = nextsibling(node)) { node = nextsibling(node)) {
struct cpuunit_attach_args cpua; 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"); panic("cpuunit_attach: failed to set up attach args");
(void) config_found(&sc->sc_dev, &cpua, cpuunit_print); (void) config_found(&sc->sc_dev, &cpua, cpuunit_print);

View File

@ -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. * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@ -78,7 +78,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__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_netbsd.h"
#include "opt_compat_sunos.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 int
bus_translate_address_generic(struct openprom_range *ranges, int nranges, 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++) { for (i = 0; i < nranges; i++) {
struct openprom_range *rp = &ranges[i]; struct openprom_range *rp = &ranges[i];
@ -2153,8 +2153,8 @@ bus_translate_address_generic(struct openprom_range *ranges, int nranges,
continue; continue;
/* We've found the connection to the parent bus. */ /* We've found the connection to the parent bus. */
*addrp = BUS_ADDR(rp->or_parent_space, *bap = BUS_ADDR(rp->or_parent_space,
rp->or_parent_base + BUS_ADDR_PADDR(addr)); rp->or_parent_base + BUS_ADDR_PADDR(*bap));
return (0); return (0);
} }
@ -2172,17 +2172,28 @@ sparc_bus_map(t, ba, size, flags, va, hp)
vaddr_t v; vaddr_t v;
paddr_t pa; paddr_t pa;
unsigned int pmtype; unsigned int pmtype;
bus_space_tag_t pt;
static vaddr_t iobase; static vaddr_t iobase;
if (t->ranges != NULL) { /*
bus_addr_t addr; * This base class bus map function knows about address range
int error; * 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, if ((error = bus_translate_address_generic(
ba, &addr); t->ranges, t->nranges, &ba)) != 0)
if (error) return (error);
return (error); }
return (bus_space_map2(t->parent, addr, size, flags, va, hp)); if (pt->sparc_bus_map != sparc_bus_map)
return (bus_space_map2(pt, ba, size, flags, va, hp));
t = pt;
} }
if (iobase == 0) if (iobase == 0)
@ -2256,16 +2267,22 @@ sparc_bus_mmap(t, ba, off, prot, flags)
{ {
u_int pmtype; u_int pmtype;
paddr_t pa; paddr_t pa;
bus_space_tag_t pt;
if (t->ranges != NULL) { /*
bus_addr_t addr; * Base class bus mmap function; see also sparc_bus_map
int error; */
while ((pt = t->parent) != NULL) {
if (t->ranges != NULL) {
int error;
error = bus_translate_address_generic(t->ranges, t->nranges, if ((error = bus_translate_address_generic(
ba, &addr); t->ranges, t->nranges, &ba)) != 0)
if (error) return (-1);
return (-1); }
return (bus_space_mmap(t->parent, addr, off, prot, flags)); 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)); pmtype = PMAP_IOENC(BUS_ADDR_IOSPACE(ba));
@ -2336,6 +2353,58 @@ void sparc_bus_barrier (t, h, offset, size, flags)
return; 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 = { struct sparc_bus_space_tag mainbus_space_tag = {
NULL, /* cookie */ NULL, /* cookie */
NULL, /* parent bus tag */ NULL, /* parent bus tag */
@ -2347,14 +2416,13 @@ struct sparc_bus_space_tag mainbus_space_tag = {
sparc_bus_barrier, /* bus_space_barrier */ sparc_bus_barrier, /* bus_space_barrier */
sparc_bus_mmap, /* bus_space_mmap */ sparc_bus_mmap, /* bus_space_mmap */
sparc_mainbus_intr_establish, /* bus_intr_establish */ sparc_mainbus_intr_establish, /* bus_intr_establish */
#if __FULL_SPARC_BUS_SPACE
NULL, /* read_1 */ sparc_bus_space_read_1, /* bus_space_read_1 */
NULL, /* read_2 */ sparc_bus_space_read_2, /* bus_space_read_2 */
NULL, /* read_4 */ sparc_bus_space_read_4, /* bus_space_read_4 */
NULL, /* read_8 */ sparc_bus_space_read_8, /* bus_space_read_8 */
NULL, /* write_1 */ sparc_bus_space_write_1, /* bus_space_write_1 */
NULL, /* write_2 */ sparc_bus_space_write_2, /* bus_space_write_2 */
NULL, /* write_4 */ sparc_bus_space_write_4, /* bus_space_write_4 */
NULL /* write_8 */ sparc_bus_space_write_8 /* bus_space_write_8 */
#endif
}; };