2008-05-17 22:09:03 +04:00
|
|
|
/* $NetBSD: dma_sbus.c,v 1.33 2008/05/17 18:09:03 macallan Exp $ */
|
1998-09-05 21:28:57 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 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.
|
|
|
|
*/
|
1998-08-30 00:32:09 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1994 Peter Galbavy. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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 Peter Galbavy.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 09:54:32 +03:00
|
|
|
#include <sys/cdefs.h>
|
2008-05-17 22:09:03 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: dma_sbus.c,v 1.33 2008/05/17 18:09:03 macallan Exp $");
|
2001-11-13 09:54:32 +03:00
|
|
|
|
1998-08-30 00:32:09 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/intr.h>
|
1998-08-30 00:32:09 +04:00
|
|
|
#include <machine/autoconf.h>
|
|
|
|
|
|
|
|
#include <dev/sbus/sbusvar.h>
|
|
|
|
|
|
|
|
#include <dev/ic/lsi64854reg.h>
|
|
|
|
#include <dev/ic/lsi64854var.h>
|
|
|
|
|
|
|
|
struct dma_softc {
|
|
|
|
struct lsi64854_softc sc_lsi64854; /* base device */
|
|
|
|
struct sbusdev sc_sd; /* sbus device */
|
|
|
|
};
|
|
|
|
|
2008-04-13 08:55:52 +04:00
|
|
|
int dmamatch_sbus(device_t, cfdata_t, void *);
|
|
|
|
void dmaattach_sbus(device_t, device_t, void *);
|
1998-08-30 00:32:09 +04:00
|
|
|
|
2005-02-04 05:10:35 +03:00
|
|
|
int dmaprint_sbus(void *, const char *);
|
1998-08-30 00:32:09 +04:00
|
|
|
|
2005-02-04 05:10:35 +03:00
|
|
|
void *dmabus_intr_establish(
|
1998-08-30 00:32:09 +04:00
|
|
|
bus_space_tag_t,
|
2000-07-10 00:57:41 +04:00
|
|
|
int, /*bus interrupt priority*/
|
|
|
|
int, /*`device class' level*/
|
2005-02-04 05:10:35 +03:00
|
|
|
int (*)(void *), /*handler*/
|
2002-12-10 15:21:02 +03:00
|
|
|
void *, /*handler arg*/
|
2005-02-04 05:10:35 +03:00
|
|
|
void (*) (void)); /*optional fast trap handler*/
|
1998-08-30 00:32:09 +04:00
|
|
|
|
2008-04-13 08:55:52 +04:00
|
|
|
CFATTACH_DECL_NEW(dma_sbus, sizeof(struct dma_softc),
|
2002-10-02 20:51:16 +04:00
|
|
|
dmamatch_sbus, dmaattach_sbus, NULL, NULL);
|
1998-08-30 00:32:09 +04:00
|
|
|
|
2008-04-13 08:55:52 +04:00
|
|
|
CFATTACH_DECL_NEW(ledma, sizeof(struct dma_softc),
|
2002-10-02 20:51:16 +04:00
|
|
|
dmamatch_sbus, dmaattach_sbus, NULL, NULL);
|
1998-08-30 00:32:09 +04:00
|
|
|
|
|
|
|
int
|
2008-04-13 08:55:52 +04:00
|
|
|
dmaprint_sbus(void *aux, const char *busname)
|
1998-08-30 00:32:09 +04:00
|
|
|
{
|
|
|
|
struct sbus_attach_args *sa = aux;
|
|
|
|
bus_space_tag_t t = sa->sa_bustag;
|
|
|
|
struct dma_softc *sc = t->cookie;
|
|
|
|
|
|
|
|
sa->sa_bustag = sc->sc_lsi64854.sc_bustag; /* XXX */
|
|
|
|
sbus_print(aux, busname); /* XXX */
|
|
|
|
sa->sa_bustag = t; /* XXX */
|
2008-04-13 08:55:52 +04:00
|
|
|
return UNCONF;
|
1998-08-30 00:32:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-05-17 22:09:03 +04:00
|
|
|
dmamatch_sbus(device_t parent, struct cfdata *cf, void *aux)
|
1998-08-30 00:32:09 +04:00
|
|
|
{
|
|
|
|
struct sbus_attach_args *sa = aux;
|
|
|
|
|
2008-04-13 08:55:52 +04:00
|
|
|
return strcmp(cf->cf_name, sa->sa_name) == 0 ||
|
|
|
|
strcmp("espdma", sa->sa_name) == 0;
|
1998-08-30 00:32:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-04-13 08:55:52 +04:00
|
|
|
dmaattach_sbus(device_t parent, device_t self, void *aux)
|
1998-08-30 00:32:09 +04:00
|
|
|
{
|
2008-04-13 08:55:52 +04:00
|
|
|
struct dma_softc *dsc = device_private(self);
|
1998-08-30 00:32:09 +04:00
|
|
|
struct lsi64854_softc *sc = &dsc->sc_lsi64854;
|
2008-04-13 08:55:52 +04:00
|
|
|
struct sbus_attach_args *sa = aux;
|
|
|
|
struct sbus_softc *sbsc = device_private(parent);
|
1998-08-30 00:32:09 +04:00
|
|
|
bus_space_tag_t sbt;
|
|
|
|
int sbusburst, burst;
|
|
|
|
int node;
|
|
|
|
|
|
|
|
node = sa->sa_node;
|
|
|
|
|
2008-04-13 08:55:52 +04:00
|
|
|
sc->sc_dev = self;
|
1998-08-30 00:32:09 +04:00
|
|
|
sc->sc_bustag = sa->sa_bustag;
|
|
|
|
sc->sc_dmatag = sa->sa_dmatag;
|
|
|
|
|
|
|
|
/* Map registers */
|
2002-03-21 03:16:15 +03:00
|
|
|
if (sa->sa_npromvaddrs) {
|
|
|
|
sbus_promaddr_to_handle(sa->sa_bustag,
|
2008-04-13 08:55:52 +04:00
|
|
|
sa->sa_promvaddrs[0], &sc->sc_regs);
|
2002-03-21 03:16:15 +03:00
|
|
|
} else {
|
2002-03-11 19:00:55 +03:00
|
|
|
if (sbus_bus_map(sa->sa_bustag,
|
2008-04-13 08:55:52 +04:00
|
|
|
sa->sa_slot, sa->sa_offset, sa->sa_size,
|
|
|
|
0, &sc->sc_regs) != 0) {
|
|
|
|
aprint_error(": cannot map registers\n");
|
1998-08-30 00:32:09 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get transfer burst size from PROM and plug it into the
|
|
|
|
* controller registers. This is needed on the Sun4m; do
|
|
|
|
* others need it too?
|
|
|
|
*/
|
2008-04-13 08:55:52 +04:00
|
|
|
sbusburst = sbsc->sc_burst;
|
1998-08-30 00:32:09 +04:00
|
|
|
if (sbusburst == 0)
|
|
|
|
sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
|
|
|
|
|
2004-03-17 20:04:58 +03:00
|
|
|
burst = prom_getpropint(node,"burst-sizes", -1);
|
1998-08-30 00:32:09 +04:00
|
|
|
if (burst == -1)
|
|
|
|
/* take SBus burst sizes */
|
|
|
|
burst = sbusburst;
|
|
|
|
|
|
|
|
/* Clamp at parent's burst sizes */
|
|
|
|
burst &= sbusburst;
|
|
|
|
sc->sc_burst = (burst & SBUS_BURST_32) ? 32 :
|
|
|
|
(burst & SBUS_BURST_16) ? 16 : 0;
|
|
|
|
|
2008-04-13 08:55:52 +04:00
|
|
|
if (device_is_a(self, "ledma")) {
|
1998-08-30 00:32:09 +04:00
|
|
|
char *cabletype;
|
2008-04-13 08:55:52 +04:00
|
|
|
uint32_t csr;
|
1998-08-30 00:32:09 +04:00
|
|
|
/*
|
1998-08-30 01:43:00 +04:00
|
|
|
* Check to see which cable type is currently active and
|
|
|
|
* set the appropriate bit in the ledma csr so that it
|
|
|
|
* gets used. If we didn't netboot, the PROM won't have
|
|
|
|
* the "cable-selection" property; default to TP and then
|
|
|
|
* the user can change it via a "media" option to ifconfig.
|
1998-08-30 00:32:09 +04:00
|
|
|
*/
|
2004-03-17 20:04:58 +03:00
|
|
|
cabletype = prom_getpropstring(node, "cable-selection");
|
1998-08-30 00:32:09 +04:00
|
|
|
csr = L64854_GCSR(sc);
|
|
|
|
if (strcmp(cabletype, "tpe") == 0) {
|
|
|
|
csr |= E_TP_AUI;
|
|
|
|
} else if (strcmp(cabletype, "aui") == 0) {
|
|
|
|
csr &= ~E_TP_AUI;
|
|
|
|
} else {
|
|
|
|
/* assume TP if nothing there */
|
|
|
|
csr |= E_TP_AUI;
|
|
|
|
}
|
|
|
|
L64854_SCSR(sc, csr);
|
1998-08-30 01:43:00 +04:00
|
|
|
delay(20000); /* manual says we need a 20ms delay */
|
|
|
|
sc->sc_channel = L64854_CHANNEL_ENET;
|
1998-08-30 00:32:09 +04:00
|
|
|
} else {
|
1998-08-30 01:43:00 +04:00
|
|
|
sc->sc_channel = L64854_CHANNEL_SCSI;
|
1998-08-30 00:32:09 +04:00
|
|
|
}
|
|
|
|
|
2008-04-13 08:55:52 +04:00
|
|
|
sbus_establish(&dsc->sc_sd, self);
|
2004-07-01 01:16:38 +04:00
|
|
|
if ((sbt = bus_space_tag_alloc(sc->sc_bustag, dsc)) == NULL) {
|
2008-04-13 08:55:52 +04:00
|
|
|
aprint_error(": out of memory\n");
|
2004-07-01 01:16:38 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
sbt->sparc_intr_establish = dmabus_intr_establish;
|
1998-08-30 00:32:09 +04:00
|
|
|
lsi64854_attach(sc);
|
|
|
|
|
|
|
|
/* Attach children */
|
|
|
|
for (node = firstchild(sa->sa_node); node; node = nextsibling(node)) {
|
2005-05-31 02:17:47 +04:00
|
|
|
struct sbus_attach_args sax;
|
2008-04-13 08:55:52 +04:00
|
|
|
sbus_setup_attach_args(sbsc, sbt, sc->sc_dmatag, node, &sax);
|
|
|
|
(void)config_found(self, (void *)&sax, dmaprint_sbus);
|
2005-05-31 02:17:47 +04:00
|
|
|
sbus_destroy_attach_args(&sax);
|
1998-08-30 00:32:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2008-04-13 08:55:52 +04:00
|
|
|
dmabus_intr_establish(bus_space_tag_t t, int pri, int level,
|
|
|
|
int (*handler)(void *), void *arg, void (*fastvec)(void))
|
1998-08-30 00:32:09 +04:00
|
|
|
{
|
|
|
|
struct lsi64854_softc *sc = t->cookie;
|
|
|
|
|
1998-08-30 01:43:00 +04:00
|
|
|
/* XXX - for now only le; do esp later */
|
|
|
|
if (sc->sc_channel == L64854_CHANNEL_ENET) {
|
1998-08-30 00:32:09 +04:00
|
|
|
sc->sc_intrchain = handler;
|
|
|
|
sc->sc_intrchainarg = arg;
|
|
|
|
handler = lsi64854_enet_intr;
|
|
|
|
arg = sc;
|
|
|
|
}
|
2008-04-13 08:55:52 +04:00
|
|
|
return bus_intr_establish(sc->sc_bustag, pri, level, handler, arg);
|
1998-08-30 00:32:09 +04:00
|
|
|
}
|