lebuffer.c revision 1.9
11.9Slukem/*	$NetBSD: lebuffer.c,v 1.9 2001/11/13 06:58:17 lukem 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.9Slukem
391.9Slukem#include <sys/cdefs.h>
401.9Slukem__KERNEL_RCSID(0, "$NetBSD: lebuffer.c,v 1.9 2001/11/13 06:58:17 lukem Exp $");
411.1Smrg
421.1Smrg#include <sys/types.h>
431.1Smrg#include <sys/param.h>
441.1Smrg#include <sys/systm.h>
451.1Smrg#include <sys/kernel.h>
461.1Smrg#include <sys/errno.h>
471.1Smrg#include <sys/device.h>
481.1Smrg#include <sys/malloc.h>
491.1Smrg
501.1Smrg#include <machine/bus.h>
511.1Smrg#include <machine/autoconf.h>
521.1Smrg#include <machine/cpu.h>
531.1Smrg
541.2Spk#include <dev/sbus/sbusvar.h>
551.1Smrg#include <dev/sbus/lebuffervar.h>
561.1Smrg
571.1Smrgint	lebufprint	__P((void *, const char *));
581.1Smrgint	lebufmatch	__P((struct device *, struct cfdata *, void *));
591.1Smrgvoid	lebufattach	__P((struct device *, struct device *, void *));
601.1Smrg
611.1Smrgstruct cfattach lebuffer_ca = {
621.1Smrg	sizeof(struct lebuf_softc), lebufmatch, lebufattach
631.1Smrg};
641.1Smrg
651.1Smrgint
661.1Smrglebufprint(aux, busname)
671.1Smrg	void *aux;
681.1Smrg	const char *busname;
691.1Smrg{
701.1Smrg	struct sbus_attach_args *sa = aux;
711.1Smrg	bus_space_tag_t t = sa->sa_bustag;
721.1Smrg	struct lebuf_softc *sc = t->cookie;
731.1Smrg
741.1Smrg	sa->sa_bustag = sc->sc_bustag;	/* XXX */
751.1Smrg	sbus_print(aux, busname);	/* XXX */
761.1Smrg	sa->sa_bustag = t;		/* XXX */
771.1Smrg	return (UNCONF);
781.1Smrg}
791.1Smrg
801.1Smrgint
811.1Smrglebufmatch(parent, cf, aux)
821.1Smrg	struct device *parent;
831.1Smrg	struct cfdata *cf;
841.1Smrg	void *aux;
851.1Smrg{
861.1Smrg	struct sbus_attach_args *sa = aux;
871.1Smrg
881.1Smrg	return (strcmp(cf->cf_driver->cd_name, sa->sa_name) == 0);
891.1Smrg}
901.1Smrg
911.1Smrg/*
921.1Smrg * Attach all the sub-devices we can find
931.1Smrg */
941.1Smrgvoid
951.1Smrglebufattach(parent, self, aux)
961.1Smrg	struct device *parent, *self;
971.1Smrg	void *aux;
981.1Smrg{
991.1Smrg	struct sbus_attach_args *sa = aux;
1001.1Smrg	struct lebuf_softc *sc = (void *)self;
1011.1Smrg	int node;
1021.1Smrg	int sbusburst;
1031.1Smrg	bus_space_tag_t sbt;
1041.1Smrg	bus_space_handle_t bh;
1051.1Smrg
1061.1Smrg	sc->sc_bustag = sa->sa_bustag;
1071.1Smrg	sc->sc_dmatag = sa->sa_dmatag;
1081.1Smrg
1091.1Smrg	if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
1101.1Smrg			 sa->sa_offset,
1111.1Smrg			 sa->sa_size,
1121.1Smrg			 0, 0, &bh) != 0) {
1131.1Smrg		printf("%s: attach: cannot map registers\n", self->dv_xname);
1141.1Smrg		return;
1151.1Smrg	}
1161.1Smrg
1171.1Smrg	/*
1181.1Smrg	 * This device's "register space" is just a buffer where the
1191.1Smrg	 * Lance ring-buffers can be stored. Note the buffer's location
1201.1Smrg	 * and size, so the `le' driver can pick them up.
1211.1Smrg	 */
1221.7Smrg	sc->sc_buffer = (caddr_t)(u_long)bh;
1231.1Smrg	sc->sc_bufsiz = sa->sa_size;
1241.1Smrg
1251.1Smrg	node = sc->sc_node = sa->sa_node;
1261.1Smrg
1271.1Smrg	/*
1281.1Smrg	 * Get transfer burst size from PROM
1291.1Smrg	 */
1301.1Smrg	sbusburst = ((struct sbus_softc *)parent)->sc_burst;
1311.1Smrg	if (sbusburst == 0)
1321.1Smrg		sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
1331.1Smrg
1341.8Seeh	sc->sc_burst = PROM_getpropint(node, "burst-sizes", -1);
1351.1Smrg	if (sc->sc_burst == -1)
1361.1Smrg		/* take SBus burst sizes */
1371.1Smrg		sc->sc_burst = sbusburst;
1381.1Smrg
1391.1Smrg	/* Clamp at parent's burst sizes */
1401.1Smrg	sc->sc_burst &= sbusburst;
1411.1Smrg
1421.1Smrg	sbus_establish(&sc->sc_sd, &sc->sc_dev);
1431.1Smrg
1441.1Smrg	/* Allocate a bus tag */
1451.1Smrg	sbt = (bus_space_tag_t)
1461.1Smrg		malloc(sizeof(struct sparc_bus_space_tag), M_DEVBUF, M_NOWAIT);
1471.1Smrg	if (sbt == NULL) {
1481.1Smrg		printf("%s: attach: out of memory\n", self->dv_xname);
1491.1Smrg		return;
1501.1Smrg	}
1511.1Smrg
1521.1Smrg	printf(": %dK memory\n", sc->sc_bufsiz / 1024);
1531.1Smrg
1541.1Smrg	bzero(sbt, sizeof *sbt);
1551.1Smrg	sbt->cookie = sc;
1561.1Smrg	sbt->parent = sc->sc_bustag;
1571.1Smrg
1581.1Smrg	/* search through children */
1591.1Smrg	for (node = firstchild(node); node; node = nextsibling(node)) {
1601.1Smrg		struct sbus_attach_args sa;
1611.1Smrg		sbus_setup_attach_args((struct sbus_softc *)parent,
1621.6Spk				       sbt, sc->sc_dmatag, node, &sa);
1631.1Smrg		(void)config_found(&sc->sc_dev, (void *)&sa, lebufprint);
1641.4Spk		sbus_destroy_attach_args(&sa);
1651.1Smrg	}
1661.1Smrg}
167