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