lebuffer.c revision 1.2
11.2Spk/*	$NetBSD: lebuffer.c,v 1.2 1998/07/27 19:13:45 pk Exp $ */
21.1Smrg
31.1Smrg/*
41.1Smrg * Copyright (c) 1996 Paul Kranenburg.  All rights reserved.
51.1Smrg *
61.1Smrg * Redistribution and use in source and binary forms, with or without
71.1Smrg * modification, are permitted provided that the following conditions
81.1Smrg * are met:
91.1Smrg * 1. Redistributions of source code must retain the above copyright
101.1Smrg *    notice, this list of conditions and the following disclaimer.
111.1Smrg * 2. Redistributions in binary form must reproduce the above copyright
121.1Smrg *    notice, this list of conditions and the following disclaimer in the
131.1Smrg *    documentation and/or other materials provided with the distribution.
141.1Smrg * 3. All advertising materials mentioning features or use of this software
151.1Smrg *    must display the following acknowledgement:
161.1Smrg *	This product includes software developed by Peter Galbavy.
171.1Smrg * 4. The name of the author may not be used to endorse or promote products
181.1Smrg *    derived from this software without specific prior written permission.
191.1Smrg *
201.1Smrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
211.1Smrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
221.1Smrg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
231.1Smrg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
241.1Smrg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
251.1Smrg * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
261.1Smrg * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
271.1Smrg * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
281.1Smrg * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
291.1Smrg * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
301.1Smrg */
311.1Smrg
321.1Smrg#include <sys/types.h>
331.1Smrg#include <sys/param.h>
341.1Smrg#include <sys/systm.h>
351.1Smrg#include <sys/kernel.h>
361.1Smrg#include <sys/errno.h>
371.1Smrg#include <sys/ioctl.h>
381.1Smrg#include <sys/device.h>
391.1Smrg#include <sys/malloc.h>
401.1Smrg#include <sys/buf.h>
411.1Smrg#include <sys/proc.h>
421.1Smrg#include <sys/user.h>
431.1Smrg
441.1Smrg#include <machine/bus.h>
451.1Smrg#include <machine/autoconf.h>
461.1Smrg#include <machine/cpu.h>
471.1Smrg
481.2Spk#include <dev/sbus/sbusvar.h>
491.1Smrg#include <dev/sbus/lebuffervar.h>
501.1Smrg
511.1Smrgint	lebufprint	__P((void *, const char *));
521.1Smrgint	lebufmatch	__P((struct device *, struct cfdata *, void *));
531.1Smrgvoid	lebufattach	__P((struct device *, struct device *, void *));
541.1Smrg
551.1Smrgstruct cfattach lebuffer_ca = {
561.1Smrg	sizeof(struct lebuf_softc), lebufmatch, lebufattach
571.1Smrg};
581.1Smrg
591.1Smrgint
601.1Smrglebufprint(aux, busname)
611.1Smrg	void *aux;
621.1Smrg	const char *busname;
631.1Smrg{
641.1Smrg	struct sbus_attach_args *sa = aux;
651.1Smrg	bus_space_tag_t t = sa->sa_bustag;
661.1Smrg	struct lebuf_softc *sc = t->cookie;
671.1Smrg
681.1Smrg	sa->sa_bustag = sc->sc_bustag;	/* XXX */
691.1Smrg	sbus_print(aux, busname);	/* XXX */
701.1Smrg	sa->sa_bustag = t;		/* XXX */
711.1Smrg	return (UNCONF);
721.1Smrg}
731.1Smrg
741.1Smrgint
751.1Smrglebufmatch(parent, cf, aux)
761.1Smrg	struct device *parent;
771.1Smrg	struct cfdata *cf;
781.1Smrg	void *aux;
791.1Smrg{
801.1Smrg	struct sbus_attach_args *sa = aux;
811.1Smrg
821.1Smrg	return (strcmp(cf->cf_driver->cd_name, sa->sa_name) == 0);
831.1Smrg}
841.1Smrg
851.1Smrg/*
861.1Smrg * Attach all the sub-devices we can find
871.1Smrg */
881.1Smrgvoid
891.1Smrglebufattach(parent, self, aux)
901.1Smrg	struct device *parent, *self;
911.1Smrg	void *aux;
921.1Smrg{
931.1Smrg	struct sbus_attach_args *sa = aux;
941.1Smrg	struct lebuf_softc *sc = (void *)self;
951.1Smrg	int node;
961.1Smrg	int sbusburst;
971.1Smrg	bus_space_tag_t sbt;
981.1Smrg	bus_space_handle_t bh;
991.1Smrg	struct bootpath *bp;
1001.1Smrg
1011.1Smrg	sc->sc_bustag = sa->sa_bustag;
1021.1Smrg	sc->sc_dmatag = sa->sa_dmatag;
1031.1Smrg
1041.1Smrg	if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
1051.1Smrg			 sa->sa_offset,
1061.1Smrg			 sa->sa_size,
1071.1Smrg			 0, 0, &bh) != 0) {
1081.1Smrg		printf("%s: attach: cannot map registers\n", self->dv_xname);
1091.1Smrg		return;
1101.1Smrg	}
1111.1Smrg
1121.1Smrg	/*
1131.1Smrg	 * This device's "register space" is just a buffer where the
1141.1Smrg	 * Lance ring-buffers can be stored. Note the buffer's location
1151.1Smrg	 * and size, so the `le' driver can pick them up.
1161.1Smrg	 */
1171.1Smrg	sc->sc_buffer = (caddr_t)bh;
1181.1Smrg	sc->sc_bufsiz = sa->sa_size;
1191.1Smrg
1201.1Smrg	node = sc->sc_node = sa->sa_node;
1211.1Smrg
1221.1Smrg	/*
1231.1Smrg	 * Get transfer burst size from PROM
1241.1Smrg	 */
1251.1Smrg	sbusburst = ((struct sbus_softc *)parent)->sc_burst;
1261.1Smrg	if (sbusburst == 0)
1271.1Smrg		sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
1281.1Smrg
1291.1Smrg	sc->sc_burst = getpropint(node, "burst-sizes", -1);
1301.1Smrg	if (sc->sc_burst == -1)
1311.1Smrg		/* take SBus burst sizes */
1321.1Smrg		sc->sc_burst = sbusburst;
1331.1Smrg
1341.1Smrg	/* Clamp at parent's burst sizes */
1351.1Smrg	sc->sc_burst &= sbusburst;
1361.1Smrg
1371.1Smrg	sbus_establish(&sc->sc_sd, &sc->sc_dev);
1381.1Smrg
1391.1Smrg	/* Propagate bootpath */
1401.1Smrg	if (sa->sa_bp != NULL)
1411.1Smrg		bp = sa->sa_bp + 1;
1421.1Smrg	else
1431.1Smrg		bp = NULL;
1441.1Smrg
1451.1Smrg	/* Allocate a bus tag */
1461.1Smrg	sbt = (bus_space_tag_t)
1471.1Smrg		malloc(sizeof(struct sparc_bus_space_tag), M_DEVBUF, M_NOWAIT);
1481.1Smrg	if (sbt == NULL) {
1491.1Smrg		printf("%s: attach: out of memory\n", self->dv_xname);
1501.1Smrg		return;
1511.1Smrg	}
1521.1Smrg
1531.1Smrg	printf(": %dK memory\n", sc->sc_bufsiz / 1024);
1541.1Smrg
1551.1Smrg	bzero(sbt, sizeof *sbt);
1561.1Smrg	sbt->cookie = sc;
1571.1Smrg	sbt->parent = sc->sc_bustag;
1581.1Smrg
1591.1Smrg	/* search through children */
1601.1Smrg	for (node = firstchild(node); node; node = nextsibling(node)) {
1611.1Smrg		struct sbus_attach_args sa;
1621.1Smrg		sbus_setup_attach_args((struct sbus_softc *)parent,
1631.1Smrg				       sbt, sc->sc_dmatag, node, bp, &sa);
1641.1Smrg		(void)config_found(&sc->sc_dev, (void *)&sa, lebufprint);
1651.1Smrg	}
1661.1Smrg}
167