2003-09-26 21:17:47 +04:00
|
|
|
/* $NetBSD: tc.c,v 1.36 2003/09/26 17:17:47 tsutsui Exp $ */
|
1995-12-20 03:48:32 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1994, 1995 Carnegie-Mellon University.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Author: Chris G. Demetriou
|
1996-04-18 05:12:41 +04:00
|
|
|
*
|
1995-12-20 03:48:32 +03:00
|
|
|
* Permission to use, copy, modify and distribute this software and
|
|
|
|
* its documentation is hereby granted, provided that both the copyright
|
|
|
|
* notice and this permission notice appear in all copies of the
|
|
|
|
* software, derivative works or modified versions, and any portions
|
|
|
|
* thereof, and that both notices appear in supporting documentation.
|
1996-04-18 05:12:41 +04:00
|
|
|
*
|
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
|
1995-12-20 03:48:32 +03:00
|
|
|
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
1996-04-18 05:12:41 +04:00
|
|
|
*
|
1995-12-20 03:48:32 +03:00
|
|
|
* Carnegie Mellon requests users of this software to return to
|
|
|
|
*
|
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
|
|
|
*
|
|
|
|
* any improvements or extensions that they make and grant Carnegie the
|
|
|
|
* rights to redistribute these changes.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 09:26:09 +03:00
|
|
|
#include <sys/cdefs.h>
|
2003-09-26 21:17:47 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: tc.c,v 1.36 2003/09/26 17:17:47 tsutsui Exp $");
|
2001-11-13 09:26:09 +03:00
|
|
|
|
1997-09-13 12:52:23 +04:00
|
|
|
#include "opt_tcverbose.h"
|
|
|
|
|
1995-12-20 03:48:32 +03:00
|
|
|
#include <sys/param.h>
|
1996-04-10 00:50:06 +04:00
|
|
|
#include <sys/systm.h>
|
1995-12-20 03:48:32 +03:00
|
|
|
#include <sys/device.h>
|
|
|
|
|
|
|
|
#include <dev/tc/tcreg.h>
|
|
|
|
#include <dev/tc/tcvar.h>
|
1996-03-02 04:16:47 +03:00
|
|
|
#include <dev/tc/tcdevs.h>
|
1995-12-20 03:48:32 +03:00
|
|
|
|
|
|
|
|
|
|
|
/* Definition of the driver for autoconfig. */
|
1996-12-05 04:25:23 +03:00
|
|
|
int tcmatch __P((struct device *, struct cfdata *, void *));
|
1995-12-20 03:48:32 +03:00
|
|
|
void tcattach __P((struct device *, struct device *, void *));
|
1996-03-17 03:57:14 +03:00
|
|
|
|
2002-10-01 05:05:50 +04:00
|
|
|
CFATTACH_DECL(tc, sizeof(struct tc_softc),
|
2002-10-02 20:51:16 +04:00
|
|
|
tcmatch, tcattach, NULL, NULL);
|
2002-10-01 05:05:50 +04:00
|
|
|
|
1999-11-15 06:41:49 +03:00
|
|
|
extern struct cfdriver tc_cd;
|
1996-03-17 03:57:14 +03:00
|
|
|
|
1996-08-28 01:53:46 +04:00
|
|
|
int tcprint __P((void *, const char *));
|
1996-12-05 04:25:23 +03:00
|
|
|
int tcsubmatch __P((struct device *, struct cfdata *, void *));
|
1995-12-20 03:48:32 +03:00
|
|
|
int tc_checkslot __P((tc_addr_t, char *));
|
1996-03-02 04:16:47 +03:00
|
|
|
void tc_devinfo __P((const char *, char *));
|
1995-12-20 03:48:32 +03:00
|
|
|
|
|
|
|
int
|
1996-12-05 04:25:23 +03:00
|
|
|
tcmatch(parent, cf, aux)
|
1995-12-20 03:48:32 +03:00
|
|
|
struct device *parent;
|
1996-12-05 04:25:23 +03:00
|
|
|
struct cfdata *cf;
|
1995-12-20 03:48:32 +03:00
|
|
|
void *aux;
|
|
|
|
{
|
1996-02-27 02:38:38 +03:00
|
|
|
struct tcbus_attach_args *tba = aux;
|
|
|
|
|
2002-09-27 06:24:06 +04:00
|
|
|
if (strcmp(tba->tba_busname, cf->cf_name))
|
1996-02-27 02:38:38 +03:00
|
|
|
return (0);
|
|
|
|
|
1995-12-20 03:48:32 +03:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tcattach(parent, self, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct device *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct tc_softc *sc = (struct tc_softc *)self;
|
1996-02-27 02:38:38 +03:00
|
|
|
struct tcbus_attach_args *tba = aux;
|
|
|
|
struct tc_attach_args ta;
|
1995-12-20 03:48:32 +03:00
|
|
|
const struct tc_builtin *builtin;
|
|
|
|
struct tc_slotdesc *slot;
|
|
|
|
tc_addr_t tcaddr;
|
|
|
|
int i;
|
|
|
|
|
1996-10-13 05:37:04 +04:00
|
|
|
printf(": %s MHz clock\n",
|
1996-02-27 04:37:32 +03:00
|
|
|
tba->tba_speed == TC_SPEED_25_MHZ ? "25" : "12.5");
|
1995-12-20 03:48:32 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Save important CPU/chipset information.
|
|
|
|
*/
|
1996-02-27 02:38:38 +03:00
|
|
|
sc->sc_speed = tba->tba_speed;
|
|
|
|
sc->sc_nslots = tba->tba_nslots;
|
|
|
|
sc->sc_slots = tba->tba_slots;
|
2000-06-04 23:14:14 +04:00
|
|
|
sc->sc_intr_evcnt = tba->tba_intr_evcnt;
|
1996-02-27 02:38:38 +03:00
|
|
|
sc->sc_intr_establish = tba->tba_intr_establish;
|
|
|
|
sc->sc_intr_disestablish = tba->tba_intr_disestablish;
|
1998-01-19 05:50:58 +03:00
|
|
|
sc->sc_get_dma_tag = tba->tba_get_dma_tag;
|
1995-12-20 03:48:32 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to configure each built-in device
|
|
|
|
*/
|
1996-02-27 02:38:38 +03:00
|
|
|
for (i = 0; i < tba->tba_nbuiltins; i++) {
|
|
|
|
builtin = &tba->tba_builtins[i];
|
1995-12-20 03:48:32 +03:00
|
|
|
|
|
|
|
/* sanity check! */
|
|
|
|
if (builtin->tcb_slot > sc->sc_nslots)
|
|
|
|
panic("tcattach: builtin %d slot > nslots", i);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure device is really there, because some
|
|
|
|
* built-in devices are really optional.
|
|
|
|
*/
|
|
|
|
tcaddr = sc->sc_slots[builtin->tcb_slot].tcs_addr +
|
|
|
|
builtin->tcb_offset;
|
|
|
|
if (tc_badaddr(tcaddr))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the device attachment information.
|
|
|
|
*/
|
1996-02-27 02:38:38 +03:00
|
|
|
strncpy(ta.ta_modname, builtin->tcb_modname, TC_ROM_LLEN);
|
1996-10-23 01:34:19 +04:00
|
|
|
ta.ta_memt = tba->tba_memt;
|
1998-01-19 05:50:58 +03:00
|
|
|
ta.ta_dmat = (*sc->sc_get_dma_tag)(builtin->tcb_slot);
|
1996-02-27 02:38:38 +03:00
|
|
|
ta.ta_modname[TC_ROM_LLEN] = '\0';
|
|
|
|
ta.ta_slot = builtin->tcb_slot;
|
|
|
|
ta.ta_offset = builtin->tcb_offset;
|
|
|
|
ta.ta_addr = tcaddr;
|
|
|
|
ta.ta_cookie = builtin->tcb_cookie;
|
|
|
|
ta.ta_busspeed = sc->sc_speed;
|
1996-04-18 05:12:41 +04:00
|
|
|
|
1995-12-20 03:48:32 +03:00
|
|
|
/*
|
|
|
|
* Mark the slot as used, so we don't check it later.
|
|
|
|
*/
|
|
|
|
sc->sc_slots[builtin->tcb_slot].tcs_used = 1;
|
|
|
|
|
|
|
|
/*
|
1996-02-28 00:48:52 +03:00
|
|
|
* Attach the device.
|
1995-12-20 03:48:32 +03:00
|
|
|
*/
|
1996-02-28 00:48:52 +03:00
|
|
|
config_found_sm(self, &ta, tcprint, tcsubmatch);
|
1995-12-20 03:48:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to configure each unused slot, last to first.
|
|
|
|
*/
|
|
|
|
for (i = sc->sc_nslots - 1; i >= 0; i--) {
|
|
|
|
slot = &sc->sc_slots[i];
|
|
|
|
|
|
|
|
/* If already checked above, don't look again now. */
|
|
|
|
if (slot->tcs_used)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure something is there, and find out what it is.
|
|
|
|
*/
|
|
|
|
tcaddr = slot->tcs_addr;
|
|
|
|
if (tc_badaddr(tcaddr))
|
|
|
|
continue;
|
1996-02-27 02:38:38 +03:00
|
|
|
if (tc_checkslot(tcaddr, ta.ta_modname) == 0)
|
1995-12-20 03:48:32 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the rest of the attachment information.
|
|
|
|
*/
|
1998-01-19 05:50:58 +03:00
|
|
|
ta.ta_memt = tba->tba_memt;
|
|
|
|
ta.ta_dmat = (*sc->sc_get_dma_tag)(i);
|
1996-02-27 02:38:38 +03:00
|
|
|
ta.ta_slot = i;
|
|
|
|
ta.ta_offset = 0;
|
|
|
|
ta.ta_addr = tcaddr;
|
|
|
|
ta.ta_cookie = slot->tcs_cookie;
|
1995-12-20 03:48:32 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark the slot as used.
|
|
|
|
*/
|
|
|
|
slot->tcs_used = 1;
|
|
|
|
|
|
|
|
/*
|
1996-02-28 00:48:52 +03:00
|
|
|
* Attach the device.
|
1995-12-20 03:48:32 +03:00
|
|
|
*/
|
1996-02-28 00:48:52 +03:00
|
|
|
config_found_sm(self, &ta, tcprint, tcsubmatch);
|
1995-12-20 03:48:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tcprint(aux, pnp)
|
|
|
|
void *aux;
|
1996-08-28 01:53:46 +04:00
|
|
|
const char *pnp;
|
1995-12-20 03:48:32 +03:00
|
|
|
{
|
1996-02-27 02:38:38 +03:00
|
|
|
struct tc_attach_args *ta = aux;
|
1996-03-02 04:16:47 +03:00
|
|
|
char devinfo[256];
|
1995-12-20 03:48:32 +03:00
|
|
|
|
1996-03-02 04:16:47 +03:00
|
|
|
if (pnp) {
|
|
|
|
tc_devinfo(ta->ta_modname, devinfo);
|
2003-01-01 03:10:15 +03:00
|
|
|
aprint_normal("%s at %s", devinfo, pnp);
|
1996-03-02 04:16:47 +03:00
|
|
|
}
|
2003-09-26 21:17:47 +04:00
|
|
|
aprint_normal(" slot %d offset 0x%x", ta->ta_slot, ta->ta_offset);
|
1996-03-02 04:16:47 +03:00
|
|
|
return (UNCONF);
|
1995-12-20 03:48:32 +03:00
|
|
|
}
|
|
|
|
|
1996-04-18 05:12:41 +04:00
|
|
|
int
|
1996-12-05 04:25:23 +03:00
|
|
|
tcsubmatch(parent, cf, aux)
|
1996-04-18 05:12:41 +04:00
|
|
|
struct device *parent;
|
1996-12-05 04:25:23 +03:00
|
|
|
struct cfdata *cf;
|
|
|
|
void *aux;
|
1995-12-20 03:48:32 +03:00
|
|
|
{
|
1996-02-27 02:38:38 +03:00
|
|
|
struct tc_attach_args *d = aux;
|
|
|
|
|
|
|
|
if ((cf->tccf_slot != TCCF_SLOT_UNKNOWN) &&
|
|
|
|
(cf->tccf_slot != d->ta_slot))
|
|
|
|
return 0;
|
|
|
|
if ((cf->tccf_offset != TCCF_SLOT_UNKNOWN) &&
|
|
|
|
(cf->tccf_offset != d->ta_offset))
|
|
|
|
return 0;
|
1995-12-20 03:48:32 +03:00
|
|
|
|
2002-09-27 07:17:40 +04:00
|
|
|
return (config_match(parent, cf, aux));
|
1995-12-20 03:48:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define NTC_ROMOFFS 2
|
|
|
|
static tc_offset_t tc_slot_romoffs[NTC_ROMOFFS] = {
|
|
|
|
TC_SLOT_ROM,
|
|
|
|
TC_SLOT_PROTOROM,
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
tc_checkslot(slotbase, namep)
|
|
|
|
tc_addr_t slotbase;
|
|
|
|
char *namep;
|
|
|
|
{
|
|
|
|
struct tc_rommap *romp;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < NTC_ROMOFFS; i++) {
|
|
|
|
romp = (struct tc_rommap *)
|
|
|
|
(slotbase + tc_slot_romoffs[i]);
|
|
|
|
|
|
|
|
switch (romp->tcr_width.v) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 4:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (romp->tcr_stride.v != 4)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (j = 0; j < 4; j++)
|
|
|
|
if (romp->tcr_test[j+0*romp->tcr_stride.v] != 0x55 ||
|
|
|
|
romp->tcr_test[j+1*romp->tcr_stride.v] != 0x00 ||
|
|
|
|
romp->tcr_test[j+2*romp->tcr_stride.v] != 0xaa ||
|
|
|
|
romp->tcr_test[j+3*romp->tcr_stride.v] != 0xff)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (j = 0; j < TC_ROM_LLEN; j++)
|
|
|
|
namep[j] = romp->tcr_modname[j].v;
|
|
|
|
namep[j] = '\0';
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-06-04 23:14:14 +04:00
|
|
|
const struct evcnt *
|
|
|
|
tc_intr_evcnt(struct device *dev, void *cookie)
|
|
|
|
{
|
|
|
|
struct tc_softc *sc = tc_cd.cd_devs[0];
|
|
|
|
|
|
|
|
return ((*sc->sc_intr_evcnt)(dev, cookie));
|
|
|
|
}
|
|
|
|
|
1995-12-20 03:48:32 +03:00
|
|
|
void
|
|
|
|
tc_intr_establish(dev, cookie, level, handler, arg)
|
|
|
|
struct device *dev;
|
|
|
|
void *cookie, *arg;
|
1999-11-15 06:41:49 +03:00
|
|
|
int level;
|
1995-12-20 03:48:32 +03:00
|
|
|
int (*handler) __P((void *));
|
|
|
|
{
|
1999-11-15 06:41:49 +03:00
|
|
|
struct tc_softc *sc = tc_cd.cd_devs[0];
|
1995-12-20 03:48:32 +03:00
|
|
|
|
1999-11-15 06:41:49 +03:00
|
|
|
(*sc->sc_intr_establish)(dev, cookie, level, handler, arg);
|
1995-12-20 03:48:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tc_intr_disestablish(dev, cookie)
|
|
|
|
struct device *dev;
|
|
|
|
void *cookie;
|
|
|
|
{
|
1999-11-15 06:41:49 +03:00
|
|
|
struct tc_softc *sc = tc_cd.cd_devs[0];
|
1995-12-20 03:48:32 +03:00
|
|
|
|
1999-11-15 06:41:49 +03:00
|
|
|
(*sc->sc_intr_disestablish)(dev, cookie);
|
1995-12-20 03:48:32 +03:00
|
|
|
}
|
1996-03-02 04:16:47 +03:00
|
|
|
|
|
|
|
#ifdef TCVERBOSE
|
1996-04-18 05:12:41 +04:00
|
|
|
/*
|
1996-03-02 04:16:47 +03:00
|
|
|
* Descriptions of of known devices.
|
1996-04-18 05:12:41 +04:00
|
|
|
*/
|
1996-03-02 04:16:47 +03:00
|
|
|
struct tc_knowndev {
|
1996-03-06 02:15:05 +03:00
|
|
|
const char *id, *driver, *description;
|
1996-04-18 05:12:41 +04:00
|
|
|
};
|
1996-03-02 04:16:47 +03:00
|
|
|
|
|
|
|
#include <dev/tc/tcdevs_data.h>
|
|
|
|
#endif /* TCVERBOSE */
|
|
|
|
|
|
|
|
void
|
|
|
|
tc_devinfo(id, cp)
|
|
|
|
const char *id;
|
|
|
|
char *cp;
|
|
|
|
{
|
1996-03-06 02:15:05 +03:00
|
|
|
const char *driver, *description;
|
1996-03-02 04:16:47 +03:00
|
|
|
#ifdef TCVERBOSE
|
|
|
|
struct tc_knowndev *tdp;
|
|
|
|
int match;
|
1996-03-02 05:44:25 +03:00
|
|
|
const char *unmatched = "unknown ";
|
1996-03-02 04:16:47 +03:00
|
|
|
#else
|
|
|
|
const char *unmatched = "";
|
|
|
|
#endif
|
|
|
|
|
1996-03-06 02:15:05 +03:00
|
|
|
driver = NULL;
|
|
|
|
description = id;
|
1996-03-02 04:16:47 +03:00
|
|
|
|
|
|
|
#ifdef TCVERBOSE
|
|
|
|
/* find the device in the table, if possible. */
|
|
|
|
tdp = tc_knowndevs;
|
|
|
|
while (tdp->id != NULL) {
|
|
|
|
/* check this entry for a match */
|
|
|
|
match = !strcmp(tdp->id, id);
|
|
|
|
if (match) {
|
1996-03-06 02:15:05 +03:00
|
|
|
driver = tdp->driver;
|
|
|
|
description = tdp->description;
|
1996-03-02 04:16:47 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
tdp++;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1996-03-06 02:15:05 +03:00
|
|
|
if (driver == NULL)
|
1996-10-13 05:37:04 +04:00
|
|
|
cp += sprintf(cp, "%sdevice %s", unmatched, id);
|
1996-03-02 04:16:47 +03:00
|
|
|
else
|
1996-10-13 05:37:04 +04:00
|
|
|
cp += sprintf(cp, "%s (%s)", driver, description);
|
1996-03-02 04:16:47 +03:00
|
|
|
}
|