2002-10-02 20:51:16 +04:00
|
|
|
/* $NetBSD: lebuffer.c,v 1.18 2002/10/02 16:52:40 thorpej Exp $ */
|
1998-07-27 09:43:58 +04:00
|
|
|
|
1998-07-27 23:25:34 +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.
|
1998-07-27 09:43:58 +04:00
|
|
|
*
|
|
|
|
* 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:
|
1998-07-27 23:25:34 +04:00
|
|
|
* 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.
|
1998-07-27 09:43:58 +04:00
|
|
|
*
|
1998-07-27 23:25:34 +04:00
|
|
|
* 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-07-27 09:43:58 +04:00
|
|
|
*/
|
|
|
|
|
2001-11-13 09:54:32 +03:00
|
|
|
#include <sys/cdefs.h>
|
2002-10-02 20:51:16 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: lebuffer.c,v 1.18 2002/10/02 16:52:40 thorpej Exp $");
|
2001-11-13 09:54:32 +03:00
|
|
|
|
1998-07-27 09:43:58 +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>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/autoconf.h>
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
|
1998-07-27 23:13:45 +04:00
|
|
|
#include <dev/sbus/sbusvar.h>
|
1998-07-27 09:43:58 +04:00
|
|
|
#include <dev/sbus/lebuffervar.h>
|
|
|
|
|
|
|
|
int lebufprint __P((void *, const char *));
|
|
|
|
int lebufmatch __P((struct device *, struct cfdata *, void *));
|
|
|
|
void lebufattach __P((struct device *, struct device *, void *));
|
|
|
|
|
2002-10-01 03:07:07 +04:00
|
|
|
CFATTACH_DECL(lebuffer, sizeof(struct lebuf_softc),
|
2002-10-02 20:51:16 +04:00
|
|
|
lebufmatch, lebufattach, NULL, NULL);
|
1998-07-27 09:43:58 +04:00
|
|
|
|
|
|
|
int
|
|
|
|
lebufprint(aux, busname)
|
|
|
|
void *aux;
|
|
|
|
const char *busname;
|
|
|
|
{
|
|
|
|
struct sbus_attach_args *sa = aux;
|
|
|
|
bus_space_tag_t t = sa->sa_bustag;
|
|
|
|
struct lebuf_softc *sc = t->cookie;
|
|
|
|
|
|
|
|
sa->sa_bustag = sc->sc_bustag; /* XXX */
|
|
|
|
sbus_print(aux, busname); /* XXX */
|
|
|
|
sa->sa_bustag = t; /* XXX */
|
|
|
|
return (UNCONF);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
lebufmatch(parent, cf, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *cf;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct sbus_attach_args *sa = aux;
|
|
|
|
|
2002-09-27 06:24:06 +04:00
|
|
|
return (strcmp(cf->cf_name, sa->sa_name) == 0);
|
1998-07-27 09:43:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach all the sub-devices we can find
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lebufattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct sbus_attach_args *sa = aux;
|
|
|
|
struct lebuf_softc *sc = (void *)self;
|
|
|
|
int node;
|
|
|
|
int sbusburst;
|
|
|
|
bus_space_tag_t sbt;
|
|
|
|
bus_space_handle_t bh;
|
|
|
|
|
|
|
|
sc->sc_bustag = sa->sa_bustag;
|
|
|
|
sc->sc_dmatag = sa->sa_dmatag;
|
|
|
|
|
2002-03-11 19:00:55 +03:00
|
|
|
if (sbus_bus_map(sa->sa_bustag,
|
|
|
|
sa->sa_slot, sa->sa_offset, sa->sa_size,
|
|
|
|
BUS_SPACE_MAP_LINEAR, &bh) != 0) {
|
1998-07-27 09:43:58 +04:00
|
|
|
printf("%s: attach: cannot map registers\n", self->dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This device's "register space" is just a buffer where the
|
|
|
|
* Lance ring-buffers can be stored. Note the buffer's location
|
|
|
|
* and size, so the `le' driver can pick them up.
|
|
|
|
*/
|
2002-03-20 20:52:41 +03:00
|
|
|
sc->sc_buffer = bus_space_vaddr(sa->sa_bustag, bh);
|
1998-07-27 09:43:58 +04:00
|
|
|
sc->sc_bufsiz = sa->sa_size;
|
|
|
|
|
|
|
|
node = sc->sc_node = sa->sa_node;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get transfer burst size from PROM
|
|
|
|
*/
|
|
|
|
sbusburst = ((struct sbus_softc *)parent)->sc_burst;
|
|
|
|
if (sbusburst == 0)
|
|
|
|
sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
|
|
|
|
|
2001-09-27 00:53:05 +04:00
|
|
|
sc->sc_burst = PROM_getpropint(node, "burst-sizes", -1);
|
1998-07-27 09:43:58 +04:00
|
|
|
if (sc->sc_burst == -1)
|
|
|
|
/* take SBus burst sizes */
|
|
|
|
sc->sc_burst = sbusburst;
|
|
|
|
|
|
|
|
/* Clamp at parent's burst sizes */
|
|
|
|
sc->sc_burst &= sbusburst;
|
|
|
|
|
|
|
|
sbus_establish(&sc->sc_sd, &sc->sc_dev);
|
|
|
|
|
|
|
|
/* Allocate a bus tag */
|
2002-01-14 16:32:44 +03:00
|
|
|
sbt = (bus_space_tag_t) malloc(sizeof(struct sparc_bus_space_tag),
|
|
|
|
M_DEVBUF, M_NOWAIT|M_ZERO);
|
1998-07-27 09:43:58 +04:00
|
|
|
if (sbt == NULL) {
|
|
|
|
printf("%s: attach: out of memory\n", self->dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf(": %dK memory\n", sc->sc_bufsiz / 1024);
|
|
|
|
|
|
|
|
sbt->cookie = sc;
|
|
|
|
sbt->parent = sc->sc_bustag;
|
|
|
|
|
|
|
|
/* search through children */
|
|
|
|
for (node = firstchild(node); node; node = nextsibling(node)) {
|
|
|
|
struct sbus_attach_args sa;
|
|
|
|
sbus_setup_attach_args((struct sbus_softc *)parent,
|
2000-01-11 15:59:43 +03:00
|
|
|
sbt, sc->sc_dmatag, node, &sa);
|
1998-07-27 09:43:58 +04:00
|
|
|
(void)config_found(&sc->sc_dev, (void *)&sa, lebufprint);
|
1998-07-29 22:33:27 +04:00
|
|
|
sbus_destroy_attach_args(&sa);
|
1998-07-27 09:43:58 +04:00
|
|
|
}
|
|
|
|
}
|