1999-06-29 02:40:15 +04:00
|
|
|
/* $NetBSD: obio.c,v 1.46 1999/06/28 22:40:15 pk Exp $ */
|
1998-01-25 22:44:43 +03:00
|
|
|
|
|
|
|
/*-
|
1998-04-08 00:20:03 +04:00
|
|
|
* Copyright (c) 1997,1998 The NetBSD Foundation, Inc.
|
1998-01-25 22:44:43 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Paul Kranenburg.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
1994-08-24 13:16:46 +04:00
|
|
|
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
1996-03-14 22:44:30 +03:00
|
|
|
#include <sys/systm.h>
|
1994-08-24 13:16:46 +04:00
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
|
1998-03-21 22:55:31 +03:00
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <sparc/dev/sbusvar.h>
|
1994-08-24 13:16:46 +04:00
|
|
|
#include <machine/autoconf.h>
|
|
|
|
#include <machine/pmap.h>
|
1994-09-18 03:49:58 +04:00
|
|
|
#include <machine/oldmon.h>
|
1994-10-26 10:09:41 +03:00
|
|
|
#include <machine/cpu.h>
|
1994-09-18 03:49:58 +04:00
|
|
|
#include <machine/ctlreg.h>
|
|
|
|
#include <sparc/sparc/asm.h>
|
|
|
|
#include <sparc/sparc/vaddrs.h>
|
1997-03-11 02:01:40 +03:00
|
|
|
#include <sparc/sparc/cpuvar.h>
|
1994-08-24 13:16:46 +04:00
|
|
|
|
1998-03-21 22:55:31 +03:00
|
|
|
struct obio4_softc {
|
|
|
|
struct device sc_dev; /* base device */
|
|
|
|
bus_space_tag_t sc_bustag; /* parent bus tag */
|
|
|
|
bus_dma_tag_t sc_dmatag; /* parent bus dma tag */
|
|
|
|
};
|
|
|
|
|
|
|
|
union obio_softc {
|
|
|
|
struct device sc_dev; /* base device */
|
|
|
|
struct obio4_softc sc_obio; /* sun4 obio */
|
|
|
|
struct sbus_softc sc_sbus; /* sun4m obio is another sbus slot */
|
1994-08-24 13:16:46 +04:00
|
|
|
};
|
|
|
|
|
1997-05-18 23:37:37 +04:00
|
|
|
|
1994-08-24 13:16:46 +04:00
|
|
|
/* autoconfiguration driver */
|
1998-03-21 22:55:31 +03:00
|
|
|
static int obiomatch __P((struct device *, struct cfdata *, void *));
|
|
|
|
static void obioattach __P((struct device *, struct device *, void *));
|
1996-03-17 05:00:30 +03:00
|
|
|
|
1998-01-25 22:44:43 +03:00
|
|
|
struct cfattach obio_ca = {
|
1998-03-21 22:55:31 +03:00
|
|
|
sizeof(union obio_softc), obiomatch, obioattach
|
|
|
|
};
|
|
|
|
|
1999-06-29 02:40:15 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This `obio4_busattachargs' data structure only exists to pass down
|
|
|
|
* to obiosearch() the name of a device that must be configured early.
|
|
|
|
*/
|
|
|
|
struct obio4_busattachargs {
|
|
|
|
struct mainbus_attach_args *ma;
|
|
|
|
const char *name;
|
|
|
|
};
|
|
|
|
|
1998-03-21 22:55:31 +03:00
|
|
|
#if defined(SUN4)
|
1998-03-30 02:05:05 +04:00
|
|
|
static int obioprint __P((void *, const char *));
|
|
|
|
static int obiosearch __P((struct device *, struct cfdata *, void *));
|
1998-04-08 00:20:03 +04:00
|
|
|
static int obio_bus_mmap __P((bus_space_tag_t, bus_type_t, bus_addr_t,
|
|
|
|
int, bus_space_handle_t *));
|
|
|
|
static int _obio_bus_map __P((bus_space_tag_t, bus_type_t, bus_addr_t,
|
|
|
|
bus_size_t, int,
|
1998-08-21 18:07:37 +04:00
|
|
|
vaddr_t, bus_space_handle_t *));
|
1998-03-30 02:05:05 +04:00
|
|
|
|
1998-03-21 22:55:31 +03:00
|
|
|
static struct sparc_bus_space_tag obio_space_tag = {
|
|
|
|
NULL, /* cookie */
|
1998-04-08 00:20:03 +04:00
|
|
|
NULL, /* parent bus tag */
|
1998-03-30 02:05:05 +04:00
|
|
|
_obio_bus_map, /* bus_space_map */
|
1998-03-21 22:55:31 +03:00
|
|
|
NULL, /* bus_space_unmap */
|
|
|
|
NULL, /* bus_space_subregion */
|
|
|
|
NULL, /* bus_space_barrier */
|
|
|
|
obio_bus_mmap, /* bus_space_mmap */
|
|
|
|
NULL /* bus_intr_establish */
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Translate obio `interrupts' property value to processor IPL (see sbus.c)
|
|
|
|
* Apparently, the `interrupts' property on obio devices is just
|
|
|
|
* the processor IPL.
|
|
|
|
*/
|
|
|
|
static int intr_obio2ipl[] = {
|
|
|
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
|
1997-05-18 23:37:37 +04:00
|
|
|
};
|
|
|
|
|
1994-08-24 13:16:46 +04:00
|
|
|
int
|
1998-01-25 22:44:43 +03:00
|
|
|
obiomatch(parent, cf, aux)
|
1994-08-24 13:16:46 +04:00
|
|
|
struct device *parent;
|
1996-12-11 01:54:46 +03:00
|
|
|
struct cfdata *cf;
|
|
|
|
void *aux;
|
1994-08-24 13:16:46 +04:00
|
|
|
{
|
1998-03-21 22:55:31 +03:00
|
|
|
struct mainbus_attach_args *ma = aux;
|
1994-10-03 00:59:56 +03:00
|
|
|
|
1998-03-21 22:55:31 +03:00
|
|
|
return (strcmp(cf->cf_driver->cd_name, ma->ma_name) == 0);
|
1994-08-24 13:16:46 +04:00
|
|
|
}
|
|
|
|
|
1998-01-25 22:44:43 +03:00
|
|
|
void
|
1998-03-21 22:55:31 +03:00
|
|
|
obioattach(parent, self, aux)
|
1998-01-25 22:44:43 +03:00
|
|
|
struct device *parent, *self;
|
1998-03-21 22:55:31 +03:00
|
|
|
void *aux;
|
1998-01-25 22:44:43 +03:00
|
|
|
{
|
1998-03-21 22:55:31 +03:00
|
|
|
struct mainbus_attach_args *ma = aux;
|
1996-04-01 02:28:38 +04:00
|
|
|
|
|
|
|
/*
|
1998-03-21 22:55:31 +03:00
|
|
|
* There is only one obio bus
|
1996-04-01 02:28:38 +04:00
|
|
|
*/
|
1997-05-18 23:37:37 +04:00
|
|
|
if (self->dv_unit > 0) {
|
1996-10-13 06:59:55 +04:00
|
|
|
printf(" unsupported\n");
|
1996-04-01 02:28:38 +04:00
|
|
|
return;
|
|
|
|
}
|
1996-10-13 06:59:55 +04:00
|
|
|
printf("\n");
|
1996-04-01 02:28:38 +04:00
|
|
|
|
1998-03-21 22:55:31 +03:00
|
|
|
if (CPU_ISSUN4) {
|
|
|
|
#if defined(SUN4)
|
1998-03-30 02:05:05 +04:00
|
|
|
struct obio4_softc *sc = &((union obio_softc *)self)->sc_obio;
|
1999-06-29 02:40:15 +04:00
|
|
|
struct obio4_busattachargs oa;
|
|
|
|
const char *const *cpp;
|
|
|
|
static const char *const special4[] = {
|
|
|
|
/* find these first */
|
|
|
|
"timer",
|
|
|
|
NULL
|
|
|
|
};
|
1998-03-30 02:05:05 +04:00
|
|
|
|
|
|
|
sc->sc_bustag = ma->ma_bustag;
|
|
|
|
sc->sc_dmatag = ma->ma_dmatag;
|
|
|
|
|
|
|
|
obio_space_tag.cookie = sc;
|
1998-04-08 00:20:03 +04:00
|
|
|
obio_space_tag.parent = sc->sc_bustag;
|
1996-04-01 02:28:38 +04:00
|
|
|
|
1999-06-29 02:40:15 +04:00
|
|
|
oa.ma = ma;
|
|
|
|
|
|
|
|
/* Find all `early' obio devices */
|
|
|
|
for (cpp = special4; *cpp != NULL; cpp++) {
|
|
|
|
oa.name = *cpp;
|
|
|
|
(void)config_search(obiosearch, self, &oa);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find all other obio devices */
|
|
|
|
oa.name = NULL;
|
|
|
|
(void)config_search(obiosearch, self, &oa);
|
1998-03-21 22:55:31 +03:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
} else if (CPU_ISSUN4M) {
|
|
|
|
/*
|
|
|
|
* Attach the on-board I/O bus at on a sun4m.
|
|
|
|
* In this case we treat the obio bus as another sbus slot.
|
|
|
|
*/
|
|
|
|
struct sbus_softc *sc = &((union obio_softc *)self)->sc_sbus;
|
|
|
|
|
|
|
|
static const char *const special4m[] = {
|
|
|
|
/* find these first */
|
|
|
|
"eeprom",
|
|
|
|
"counter",
|
|
|
|
#if 0 /* Not all sun4m's have an `auxio' */
|
|
|
|
"auxio",
|
|
|
|
#endif
|
|
|
|
"",
|
|
|
|
/* place device to ignore here */
|
|
|
|
"interrupt",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
sc->sc_bustag = ma->ma_bustag;
|
|
|
|
sc->sc_dmatag = ma->ma_dmatag;
|
|
|
|
sc->sc_intr2ipl = intr_obio2ipl;
|
|
|
|
|
1998-09-06 02:15:51 +04:00
|
|
|
sbus_attach_common(sc, "obio", ma->ma_node, ma->ma_bp, special4m);
|
1998-03-21 22:55:31 +03:00
|
|
|
} else {
|
|
|
|
printf("obio on this machine?\n");
|
1996-04-01 02:28:38 +04:00
|
|
|
}
|
1998-03-21 22:55:31 +03:00
|
|
|
}
|
1996-04-01 02:28:38 +04:00
|
|
|
|
1998-03-30 02:05:05 +04:00
|
|
|
#if defined(SUN4)
|
1998-03-21 22:55:31 +03:00
|
|
|
int
|
1998-03-30 02:05:05 +04:00
|
|
|
obioprint(args, busname)
|
|
|
|
void *args;
|
|
|
|
const char *busname;
|
1998-03-21 22:55:31 +03:00
|
|
|
{
|
1998-03-30 02:05:05 +04:00
|
|
|
union obio_attach_args *uoba = args;
|
|
|
|
struct obio4_attach_args *oba = &uoba->uoba_oba4;
|
1996-04-01 02:28:38 +04:00
|
|
|
|
1998-03-30 02:05:05 +04:00
|
|
|
printf(" addr 0x%lx", (long)oba->oba_paddr);
|
|
|
|
if (oba->oba_pri != -1)
|
|
|
|
printf(" level %d", oba->oba_pri);
|
1996-04-01 02:28:38 +04:00
|
|
|
|
1998-03-30 02:05:05 +04:00
|
|
|
return (UNCONF);
|
1997-05-18 23:37:37 +04:00
|
|
|
}
|
1997-06-07 23:16:23 +04:00
|
|
|
|
1998-03-21 22:55:31 +03:00
|
|
|
int
|
1998-04-08 00:20:03 +04:00
|
|
|
_obio_bus_map(t, btype, paddr, size, flags, vaddr, hp)
|
|
|
|
bus_space_tag_t t;
|
1998-03-30 02:05:05 +04:00
|
|
|
bus_type_t btype;
|
|
|
|
bus_addr_t paddr;
|
|
|
|
bus_size_t size;
|
1998-03-21 22:55:31 +03:00
|
|
|
int flags;
|
1998-08-21 18:07:37 +04:00
|
|
|
vaddr_t vaddr;
|
1998-03-21 22:55:31 +03:00
|
|
|
bus_space_handle_t *hp;
|
|
|
|
{
|
1998-04-08 00:20:03 +04:00
|
|
|
struct obio4_softc *sc = t->cookie;
|
1998-03-21 22:55:31 +03:00
|
|
|
|
|
|
|
if ((flags & OBIO_BUS_MAP_USE_ROM) != 0 &&
|
|
|
|
obio_find_rom_map(paddr, PMAP_OBIO, size, hp) == 0)
|
|
|
|
return (0);
|
|
|
|
|
1998-03-30 02:05:05 +04:00
|
|
|
return (bus_space_map2(sc->sc_bustag, PMAP_OBIO, paddr,
|
|
|
|
size, flags, vaddr, hp));
|
1998-03-21 22:55:31 +03:00
|
|
|
}
|
1997-05-25 00:08:41 +04:00
|
|
|
|
1995-04-25 23:59:49 +04:00
|
|
|
int
|
1998-04-08 00:20:03 +04:00
|
|
|
obio_bus_mmap(t, btype, paddr, flags, hp)
|
|
|
|
bus_space_tag_t t;
|
1998-03-21 22:55:31 +03:00
|
|
|
bus_type_t btype;
|
|
|
|
bus_addr_t paddr;
|
|
|
|
int flags;
|
1998-04-08 00:20:03 +04:00
|
|
|
bus_space_handle_t *hp;
|
1998-03-21 22:55:31 +03:00
|
|
|
{
|
1998-04-08 00:20:03 +04:00
|
|
|
struct obio4_softc *sc = t->cookie;
|
1998-03-21 22:55:31 +03:00
|
|
|
|
1998-04-08 00:20:03 +04:00
|
|
|
return (bus_space_mmap(sc->sc_bustag, PMAP_OBIO, paddr, flags, hp));
|
1998-03-21 22:55:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
obiosearch(parent, cf, aux)
|
1995-04-25 23:59:49 +04:00
|
|
|
struct device *parent;
|
1996-12-11 01:54:46 +03:00
|
|
|
struct cfdata *cf;
|
1998-03-21 22:55:31 +03:00
|
|
|
void *aux;
|
1994-08-24 13:16:46 +04:00
|
|
|
{
|
1999-06-29 02:40:15 +04:00
|
|
|
struct obio4_busattachargs *oap = aux;
|
1998-03-21 22:55:31 +03:00
|
|
|
union obio_attach_args uoba;
|
|
|
|
struct obio4_attach_args *oba = &uoba.uoba_oba4;
|
|
|
|
struct bootpath *bp;
|
1994-08-24 13:16:46 +04:00
|
|
|
|
1999-06-29 02:40:15 +04:00
|
|
|
/* Check whether we're looking for a specifically named device */
|
|
|
|
if (oap->name != NULL && strcmp(oap->name, cf->cf_driver->cd_name) != 0)
|
|
|
|
return (0);
|
1998-01-25 22:44:43 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Avoid sun4m entries which don't have valid PAs.
|
|
|
|
* no point in even probing them.
|
|
|
|
*/
|
|
|
|
if (cf->cf_loc[0] == -1)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* On the 4/100 obio addresses must be mapped at
|
|
|
|
* 0x0YYYYYYY, but alias higher up (we avoid the
|
|
|
|
* alias condition because it causes pmap difficulties)
|
|
|
|
* XXX: We also assume that 4/[23]00 obio addresses
|
|
|
|
* must be 0xZYYYYYYY, where (Z != 0)
|
|
|
|
*/
|
1998-03-21 22:55:31 +03:00
|
|
|
if (cpuinfo.cpu_type == CPUTYP_4_100 && (cf->cf_loc[0] & 0xf0000000))
|
1998-01-25 22:44:43 +03:00
|
|
|
return (0);
|
1998-03-21 22:55:31 +03:00
|
|
|
if (cpuinfo.cpu_type != CPUTYP_4_100 && !(cf->cf_loc[0] & 0xf0000000))
|
1998-01-25 22:44:43 +03:00
|
|
|
return (0);
|
1994-08-24 13:16:46 +04:00
|
|
|
|
1998-03-21 22:55:31 +03:00
|
|
|
uoba.uoba_isobio4 = 1;
|
|
|
|
oba->oba_bustag = &obio_space_tag;
|
1999-06-29 02:40:15 +04:00
|
|
|
oba->oba_dmatag = oap->ma->ma_dmatag;
|
1998-03-30 02:05:05 +04:00
|
|
|
oba->oba_paddr = cf->cf_loc[0];
|
1998-03-21 22:55:31 +03:00
|
|
|
oba->oba_pri = cf->cf_loc[1];
|
1997-06-07 23:16:23 +04:00
|
|
|
|
1999-06-29 02:40:15 +04:00
|
|
|
bp = oap->ma->ma_bp;
|
1998-03-21 22:55:31 +03:00
|
|
|
if (bp != NULL && strcmp(bp->name, "obio") == 0)
|
|
|
|
oba->oba_bp = bp + 1;
|
1996-05-18 16:22:49 +04:00
|
|
|
else
|
1998-03-21 22:55:31 +03:00
|
|
|
oba->oba_bp = NULL;
|
1995-04-25 23:59:49 +04:00
|
|
|
|
1998-03-21 22:55:31 +03:00
|
|
|
if ((*cf->cf_attach->ca_match)(parent, cf, &uoba) == 0)
|
1998-01-25 22:44:43 +03:00
|
|
|
return (0);
|
1995-04-25 23:59:49 +04:00
|
|
|
|
1998-03-21 22:55:31 +03:00
|
|
|
config_attach(parent, cf, &uoba, obioprint);
|
1998-01-25 22:44:43 +03:00
|
|
|
return (1);
|
1994-10-26 10:09:41 +03:00
|
|
|
}
|
1994-10-15 08:48:47 +03:00
|
|
|
|
1994-09-18 03:49:58 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we can find a mapping that was established by the rom, use it.
|
|
|
|
* Else, create a new mapping.
|
|
|
|
*/
|
1998-03-21 22:55:31 +03:00
|
|
|
int
|
|
|
|
obio_find_rom_map(pa, iospace, len, hp)
|
|
|
|
bus_addr_t pa;
|
|
|
|
bus_type_t iospace;
|
|
|
|
int len;
|
|
|
|
bus_space_handle_t *hp;
|
1994-09-18 03:49:58 +04:00
|
|
|
{
|
1998-03-21 22:55:31 +03:00
|
|
|
#define getpte(va) lda(va, ASI_PTE)
|
|
|
|
|
|
|
|
u_long pf;
|
|
|
|
int pgtype;
|
|
|
|
u_long va, pte;
|
|
|
|
|
1998-03-30 02:05:05 +04:00
|
|
|
if (len > NBPG)
|
1998-03-21 22:55:31 +03:00
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
pf = pa >> PGSHIFT;
|
|
|
|
pgtype = PMAP_T2PTE_4(iospace);
|
|
|
|
|
|
|
|
for (va = OLDMON_STARTVADDR; va < OLDMON_ENDVADDR; va += NBPG) {
|
|
|
|
pte = getpte(va);
|
|
|
|
if ((pte & PG_V) == 0 || (pte & PG_TYPE) != pgtype ||
|
|
|
|
(pte & PG_PFNUM) != pf)
|
|
|
|
continue;
|
1994-09-18 03:49:58 +04:00
|
|
|
|
1998-03-21 22:55:31 +03:00
|
|
|
/*
|
|
|
|
* Found entry in PROM's pagetable
|
|
|
|
* note: preserve page offset
|
|
|
|
*/
|
|
|
|
*hp = (bus_space_handle_t)(va | ((u_long)pa & PGOFSET));
|
|
|
|
return (0);
|
1994-09-18 03:49:58 +04:00
|
|
|
}
|
1997-05-18 23:37:37 +04:00
|
|
|
|
1998-03-21 22:55:31 +03:00
|
|
|
return (ENOENT);
|
1994-09-18 03:49:58 +04:00
|
|
|
}
|
1998-01-25 22:44:43 +03:00
|
|
|
#endif /* SUN4 */
|