/*-
* Copyright (c) 1997,1998 The NetBSD Foundation, Inc.
* 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.
*
* 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.
*/
struct obio4_softc {
device_t 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 obio4_softc sc_obio; /* sun4 obio */
#if NSBUS > 0
struct sbus_softc sc_sbus; /* sun4m obio is another sbus slot */
#endif
};
/*
* 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;
};
#if defined(SUN4)
static int obioprint(void *, const char *);
static int obiosearch(device_t, struct cfdata *, const int *, void *);
static paddr_t obio_bus_mmap(bus_space_tag_t, bus_addr_t, off_t, int, int);
static int _obio_bus_map(bus_space_tag_t, bus_addr_t, bus_size_t, int,
vaddr_t, bus_space_handle_t *);
/* 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
#if NSBUS > 0
/*
* 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
};
#endif
/* Find all other obio devices */
oa.name = NULL;
config_search(self, &oa,
CFARGS(.search = obiosearch));
#endif
return;
} else if (CPU_ISSUN4M) {
#if NSBUS > 0
/*
* Attach the on-board I/O bus at on a sun4m.
* In this case we treat the obio bus as another sbus slot.
*/
union obio_softc *usc = device_private(self);
struct sbus_softc *sc = &usc->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
};
static int
obiosearch(device_t parent, struct cfdata *cf, const int *ldesc,
void *aux)
{
struct obio4_busattachargs *oap = aux;
union obio_attach_args uoba;
struct obio4_attach_args *oba = &uoba.uoba_oba4;
int addr;
/* Check whether we're looking for a specifically named device */
if (oap->name != NULL && strcmp(oap->name, cf->cf_name) != 0)
return (0);
/*
* Avoid sun4m entries which don't have valid PAs.
* no point in even probing them.
*/
addr = cf->cf_loc[OBIOCF_ADDR];
if (addr == -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)
*/
if (cpuinfo.cpu_type == CPUTYP_4_100 && (addr & 0xf0000000))
return (0);
if (cpuinfo.cpu_type != CPUTYP_4_100 && !(addr & 0xf0000000))
return (0);
/*
* If we can find a mapping that was established by the rom, use it.
* Else, create a new mapping.
*/
int
obio_find_rom_map(bus_addr_t ba, int len, bus_space_handle_t *hp)
{
#define getpte(va) lda(va, ASI_PTE)
u_long pa, pf;
int pgtype;
u_long va, pte;
if (len > PAGE_SIZE)
return (EINVAL);
pa = BUS_ADDR_PADDR(ba);
pf = pa >> PGSHIFT;
pgtype = PMAP_T2PTE_4(PMAP_OBIO);
for (va = OLDMON_STARTVADDR; va < OLDMON_ENDVADDR; va += PAGE_SIZE) {
pte = getpte(va);
if ((pte & PG_V) == 0 || (pte & PG_TYPE) != pgtype ||
(pte & PG_PFNUM) != pf)
continue;