2000-11-03 00:18:03 +03:00
|
|
|
/* $NetBSD: obio.c,v 1.12 2000/11/02 21:18:03 tsutsui Exp $ */
|
1997-01-14 23:57:01 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1996 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Adam Glass and Gordon W. Ross.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
|
|
|
|
#include <machine/autoconf.h>
|
|
|
|
#include <machine/mon.h>
|
1997-01-28 01:15:06 +03:00
|
|
|
#include <machine/pte.h>
|
1997-01-26 00:47:44 +03:00
|
|
|
|
1998-02-05 07:56:24 +03:00
|
|
|
#include <sun3/sun3/machdep.h>
|
|
|
|
#include <sun3/sun3x/obio.h>
|
1997-01-14 23:57:01 +03:00
|
|
|
|
|
|
|
static int obio_match __P((struct device *, struct cfdata *, void *));
|
|
|
|
static void obio_attach __P((struct device *, struct device *, void *));
|
|
|
|
static int obio_print __P((void *, const char *parentname));
|
|
|
|
static int obio_submatch __P((struct device *, struct cfdata *, void *));
|
|
|
|
|
|
|
|
struct cfattach obio_ca = {
|
|
|
|
sizeof(struct device), obio_match, obio_attach
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
obio_match(parent, cf, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *cf;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct confargs *ca = aux;
|
|
|
|
|
|
|
|
if (ca->ca_bustype != BUS_OBIO)
|
|
|
|
return (0);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1998-02-08 08:07:06 +03:00
|
|
|
* We need control over the order of attachment on OBIO,
|
|
|
|
* so do "direct" style autoconfiguration with addresses
|
|
|
|
* from the list below. OBIO addresses are fixed forever.
|
1997-04-25 19:35:27 +04:00
|
|
|
*
|
|
|
|
* Warning: This whole list is very carefully ordered!
|
|
|
|
* In general, anything not already shown here should
|
|
|
|
* be added at or near the end.
|
1997-01-14 23:57:01 +03:00
|
|
|
*/
|
|
|
|
static int obio_alist[] = {
|
|
|
|
|
1998-02-08 08:07:06 +03:00
|
|
|
/* This is used by the Ethernet and SCSI drivers. */
|
|
|
|
OBIO_IOMMU,
|
|
|
|
|
1997-04-25 19:35:27 +04:00
|
|
|
/* Misc. registers - needed by many things */
|
1997-01-14 23:57:01 +03:00
|
|
|
OBIO_ENABLEREG,
|
|
|
|
OBIO_BUSERRREG,
|
1997-04-25 19:35:27 +04:00
|
|
|
OBIO_DIAGREG, /* leds.c */
|
|
|
|
OBIO_IDPROM1, /* idprom.c (3/470) */
|
|
|
|
OBIO_MEMREG, /* memerr.c */
|
|
|
|
OBIO_INTERREG, /* intreg.c */
|
1997-01-14 23:57:01 +03:00
|
|
|
|
1997-04-25 19:35:27 +04:00
|
|
|
/* Zilog UARTs */
|
|
|
|
OBIO_ZS_KBD_MS,
|
|
|
|
OBIO_ZS_TTY_AB,
|
|
|
|
|
|
|
|
/* eeprom.c */
|
|
|
|
OBIO_EEPROM,
|
|
|
|
|
|
|
|
/* Note: This must come after OBIO_IDPROM1. */
|
|
|
|
OBIO_IDPROM2, /* idprom.c (3/80) */
|
1997-02-21 23:33:09 +03:00
|
|
|
|
1997-04-25 19:35:27 +04:00
|
|
|
/* Note: Must probe for the Intersil first! */
|
|
|
|
OBIO_CLOCK1, /* clock.c (3/470) */
|
|
|
|
OBIO_CLOCK2, /* clock.c (3/80) */
|
1997-02-21 23:33:09 +03:00
|
|
|
|
1997-01-14 23:57:01 +03:00
|
|
|
OBIO_INTEL_ETHER,
|
|
|
|
OBIO_LANCE_ETHER,
|
|
|
|
|
1999-04-06 06:07:51 +04:00
|
|
|
/* Need esp DMA before SCSI. */
|
|
|
|
OBIO_EMULEX_DMA, /* 3/80 only */
|
1997-02-21 23:33:09 +03:00
|
|
|
OBIO_EMULEX_SCSI, /* 3/80 only */
|
|
|
|
|
1998-02-08 08:07:06 +03:00
|
|
|
/* Memory subsystem */
|
|
|
|
OBIO_PCACHE_TAGS,
|
|
|
|
OBIO_ECCPARREG,
|
|
|
|
OBIO_IOC_TAGS,
|
|
|
|
OBIO_IOC_FLUSH,
|
|
|
|
|
|
|
|
OBIO_FDC, /* floppy disk (3/80) */
|
2000-11-03 00:18:03 +03:00
|
|
|
OBIO_PRINTER_PORT, /* printer port (3/80) */
|
1997-01-14 23:57:01 +03:00
|
|
|
};
|
1997-02-21 23:33:09 +03:00
|
|
|
#define OBIO_ALIST_LEN (sizeof(obio_alist) / \
|
|
|
|
sizeof(obio_alist[0]))
|
1997-01-14 23:57:01 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
obio_attach(parent, self, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct device *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct confargs *ca = aux;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
1997-04-25 19:35:27 +04:00
|
|
|
/* Configure these in the order listed above. */
|
1997-01-14 23:57:01 +03:00
|
|
|
for (i = 0; i < OBIO_ALIST_LEN; i++) {
|
1997-04-25 19:35:27 +04:00
|
|
|
/* Our parent set ca->ca_bustype already. */
|
1997-01-14 23:57:01 +03:00
|
|
|
ca->ca_paddr = obio_alist[i];
|
1997-04-25 19:35:27 +04:00
|
|
|
/* These are filled-in by obio_submatch. */
|
1997-01-14 23:57:01 +03:00
|
|
|
ca->ca_intpri = -1;
|
|
|
|
ca->ca_intvec = -1;
|
|
|
|
(void) config_found_sm(self, ca, obio_print, obio_submatch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print out the confargs. The (parent) name is non-NULL
|
|
|
|
* when there was no match found by config_found().
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
obio_print(args, name)
|
|
|
|
void *args;
|
|
|
|
const char *name;
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Be quiet about empty OBIO locations. */
|
|
|
|
if (name)
|
|
|
|
return(QUIET);
|
|
|
|
|
1997-04-25 19:35:27 +04:00
|
|
|
/* Otherwise do the usual. */
|
|
|
|
return(bus_print(args, name));
|
1997-01-14 23:57:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
obio_submatch(parent, cf, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *cf;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct confargs *ca = aux;
|
|
|
|
cfmatch_t submatch;
|
|
|
|
|
|
|
|
/*
|
1997-04-25 19:35:27 +04:00
|
|
|
* Note that a defaulted address locator can never match
|
|
|
|
* the value of ca->ca_paddr set by the obio_attach loop.
|
|
|
|
* Without this diagnostic, any device with a defaulted
|
|
|
|
* address locator would always be silently unmatched.
|
|
|
|
* Therefore, just disallow default addresses on OBIO.
|
1997-01-14 23:57:01 +03:00
|
|
|
*/
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (cf->cf_paddr == -1)
|
|
|
|
panic("obio_submatch: invalid address for: %s%d\n",
|
|
|
|
cf->cf_driver->cd_name, cf->cf_unit);
|
|
|
|
#endif
|
|
|
|
|
1997-04-25 19:35:27 +04:00
|
|
|
/*
|
|
|
|
* Note that obio_attach calls config_found_sm() with
|
|
|
|
* this function as the "submatch" and ca->ca_paddr
|
|
|
|
* set to each of the possible OBIO locations, so we
|
|
|
|
* want to reject any unmatched address here.
|
|
|
|
*/
|
1997-01-14 23:57:01 +03:00
|
|
|
if (cf->cf_paddr != ca->ca_paddr)
|
|
|
|
return 0;
|
|
|
|
|
1997-04-25 19:35:27 +04:00
|
|
|
/*
|
|
|
|
* Copy the locators into our confargs for the child.
|
|
|
|
* Note: ca->ca_bustype was set by our parent driver
|
|
|
|
* (mainbus) and ca->ca_paddr was set by obio_attach.
|
|
|
|
*/
|
|
|
|
ca->ca_intpri = cf->cf_intpri;
|
|
|
|
ca->ca_intvec = cf->cf_intvec;
|
|
|
|
|
1997-01-14 23:57:01 +03:00
|
|
|
/* Now call the match function of the potential child. */
|
|
|
|
submatch = cf->cf_attach->ca_match;
|
|
|
|
if (submatch == NULL)
|
|
|
|
panic("obio_submatch: no match function for: %s\n",
|
|
|
|
cf->cf_driver->cd_name);
|
|
|
|
|
|
|
|
return ((*submatch)(parent, cf, aux));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is our record of "interesting" OBIO mappings that
|
|
|
|
* the PROM has left in the virtual space reserved for it.
|
1998-02-08 08:07:06 +03:00
|
|
|
* Each row of the array holds a virtual address and the
|
|
|
|
* physical address it maps to (if found).
|
1997-01-14 23:57:01 +03:00
|
|
|
*/
|
|
|
|
static struct prom_map {
|
|
|
|
vm_offset_t pa, va;
|
|
|
|
} prom_mappings[] = {
|
1997-04-25 19:35:27 +04:00
|
|
|
{ OBIO_ENABLEREG, 0 }, /* regs: Sys ENA, Bus ERR, etc. */
|
1997-01-14 23:57:01 +03:00
|
|
|
{ OBIO_ZS_KBD_MS, 0 }, /* Keyboard and Mouse */
|
|
|
|
{ OBIO_ZS_TTY_AB, 0 }, /* Serial Ports */
|
|
|
|
{ OBIO_EEPROM, 0 }, /* EEPROM/IDPROM/clock */
|
|
|
|
};
|
|
|
|
#define PROM_MAP_CNT (sizeof(prom_mappings) / \
|
|
|
|
sizeof(prom_mappings[0]))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find a virtual address for a device at physical address 'pa'.
|
|
|
|
* If one is found among the mappings already made by the PROM
|
|
|
|
* at power-up time, use it. Otherwise return 0 as a sign that
|
|
|
|
* a mapping will have to be created.
|
|
|
|
*/
|
|
|
|
caddr_t
|
1998-02-08 08:07:06 +03:00
|
|
|
obio_find_mapping(int pa, int sz)
|
1997-01-14 23:57:01 +03:00
|
|
|
{
|
|
|
|
int i, off;
|
|
|
|
|
|
|
|
off = pa & PGOFSET;
|
|
|
|
pa -= off;
|
1998-02-08 08:07:06 +03:00
|
|
|
sz += off;
|
|
|
|
|
|
|
|
/* The saved mappings are all one page long. */
|
|
|
|
if (sz > NBPG)
|
|
|
|
return (caddr_t)0;
|
1997-01-14 23:57:01 +03:00
|
|
|
|
1998-02-08 08:07:06 +03:00
|
|
|
/* Linear search for it. The list is short. */
|
1997-01-14 23:57:01 +03:00
|
|
|
for (i = 0; i < PROM_MAP_CNT; i++) {
|
|
|
|
if (pa == prom_mappings[i].pa) {
|
|
|
|
return ((caddr_t)(prom_mappings[i].va + off));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (caddr_t)0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Search the PROM page tables for OBIO mappings that
|
|
|
|
* we would like to borrow.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
save_prom_mappings __P((void))
|
|
|
|
{
|
|
|
|
int *mon_pte;
|
|
|
|
vm_offset_t va, pa;
|
|
|
|
int i;
|
|
|
|
|
1998-02-05 07:56:24 +03:00
|
|
|
/* Note: mon_ctbl[0] maps SUN3X_MON_KDB_BASE */
|
1997-01-14 23:57:01 +03:00
|
|
|
mon_pte = *romVectorPtr->monptaddr;
|
|
|
|
|
1998-02-05 07:56:24 +03:00
|
|
|
for (va = SUN3X_MON_KDB_BASE; va < SUN3X_MONEND;
|
1997-01-14 23:57:01 +03:00
|
|
|
va += NBPG, mon_pte++)
|
|
|
|
{
|
|
|
|
/* Is this a valid mapping to OBIO? */
|
|
|
|
/* XXX - Some macros would be nice... */
|
|
|
|
if ((*mon_pte & 0xF0000003) != 0x60000001)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Yes it is. Is this a mapping we want? */
|
|
|
|
pa = *mon_pte & MMU_SHORT_PTE_BASEADDR;
|
|
|
|
for (i = 0; i < PROM_MAP_CNT; i++) {
|
|
|
|
if (pa != prom_mappings[i].pa)
|
|
|
|
continue;
|
|
|
|
/* Yes, we want it. Save the va? */
|
|
|
|
if (prom_mappings[i].va == 0) {
|
|
|
|
prom_mappings[i].va = va;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These are all the OBIO address that are required early in
|
|
|
|
* the life of the kernel. All are less than one page long.
|
|
|
|
* This function should make any required mappings that we
|
|
|
|
* were not able to find among the PROM monitor's mappings.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
make_required_mappings __P((void))
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < PROM_MAP_CNT; i++) {
|
|
|
|
if (prom_mappings[i].va == 0) {
|
|
|
|
/*
|
|
|
|
* Actually, the PROM always has all the
|
|
|
|
* "required" mappings we need, (smile)
|
|
|
|
* but this makes sure that is true.
|
|
|
|
*/
|
1997-01-26 00:47:44 +03:00
|
|
|
mon_printf("obio: no mapping for pa=0x%x\n",
|
1997-01-14 23:57:01 +03:00
|
|
|
prom_mappings[i].pa);
|
1997-01-26 00:47:44 +03:00
|
|
|
sunmon_abort(); /* Ancient PROM? */
|
1997-01-14 23:57:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find mappings for devices that are needed before autoconfiguration.
|
|
|
|
* We first look for and record any useful PROM mappings, then call
|
|
|
|
* the "init" functions for drivers that we need to use before the
|
|
|
|
* normal autoconfiguration calls configure(). Warning: this is
|
|
|
|
* called before pmap_bootstrap, so no allocation allowed!
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
obio_init()
|
|
|
|
{
|
|
|
|
save_prom_mappings();
|
|
|
|
make_required_mappings();
|
|
|
|
|
1998-02-05 07:56:24 +03:00
|
|
|
enable_init();
|
1997-04-25 19:35:27 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the interrupt reg mapping and turn off the
|
|
|
|
* interrupts, otherwise the PROM clock interrupt
|
|
|
|
* would poll the zs and toggle some LEDs...
|
|
|
|
*/
|
1997-01-14 23:57:01 +03:00
|
|
|
intreg_init();
|
|
|
|
}
|