lebuffer.c revision 1.2
1/*	$NetBSD: lebuffer.c,v 1.2 1998/07/27 19:13:45 pk Exp $ */
2
3/*
4 * Copyright (c) 1996 Paul Kranenburg.  All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 *    must display the following acknowledgement:
16 *	This product includes software developed by Peter Galbavy.
17 * 4. The name of the author may not be used to endorse or promote products
18 *    derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#include <sys/types.h>
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/kernel.h>
36#include <sys/errno.h>
37#include <sys/ioctl.h>
38#include <sys/device.h>
39#include <sys/malloc.h>
40#include <sys/buf.h>
41#include <sys/proc.h>
42#include <sys/user.h>
43
44#include <machine/bus.h>
45#include <machine/autoconf.h>
46#include <machine/cpu.h>
47
48#include <dev/sbus/sbusvar.h>
49#include <dev/sbus/lebuffervar.h>
50
51int	lebufprint	__P((void *, const char *));
52int	lebufmatch	__P((struct device *, struct cfdata *, void *));
53void	lebufattach	__P((struct device *, struct device *, void *));
54
55struct cfattach lebuffer_ca = {
56	sizeof(struct lebuf_softc), lebufmatch, lebufattach
57};
58
59int
60lebufprint(aux, busname)
61	void *aux;
62	const char *busname;
63{
64	struct sbus_attach_args *sa = aux;
65	bus_space_tag_t t = sa->sa_bustag;
66	struct lebuf_softc *sc = t->cookie;
67
68	sa->sa_bustag = sc->sc_bustag;	/* XXX */
69	sbus_print(aux, busname);	/* XXX */
70	sa->sa_bustag = t;		/* XXX */
71	return (UNCONF);
72}
73
74int
75lebufmatch(parent, cf, aux)
76	struct device *parent;
77	struct cfdata *cf;
78	void *aux;
79{
80	struct sbus_attach_args *sa = aux;
81
82	return (strcmp(cf->cf_driver->cd_name, sa->sa_name) == 0);
83}
84
85/*
86 * Attach all the sub-devices we can find
87 */
88void
89lebufattach(parent, self, aux)
90	struct device *parent, *self;
91	void *aux;
92{
93	struct sbus_attach_args *sa = aux;
94	struct lebuf_softc *sc = (void *)self;
95	int node;
96	int sbusburst;
97	bus_space_tag_t sbt;
98	bus_space_handle_t bh;
99	struct bootpath *bp;
100
101	sc->sc_bustag = sa->sa_bustag;
102	sc->sc_dmatag = sa->sa_dmatag;
103
104	if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
105			 sa->sa_offset,
106			 sa->sa_size,
107			 0, 0, &bh) != 0) {
108		printf("%s: attach: cannot map registers\n", self->dv_xname);
109		return;
110	}
111
112	/*
113	 * This device's "register space" is just a buffer where the
114	 * Lance ring-buffers can be stored. Note the buffer's location
115	 * and size, so the `le' driver can pick them up.
116	 */
117	sc->sc_buffer = (caddr_t)bh;
118	sc->sc_bufsiz = sa->sa_size;
119
120	node = sc->sc_node = sa->sa_node;
121
122	/*
123	 * Get transfer burst size from PROM
124	 */
125	sbusburst = ((struct sbus_softc *)parent)->sc_burst;
126	if (sbusburst == 0)
127		sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
128
129	sc->sc_burst = getpropint(node, "burst-sizes", -1);
130	if (sc->sc_burst == -1)
131		/* take SBus burst sizes */
132		sc->sc_burst = sbusburst;
133
134	/* Clamp at parent's burst sizes */
135	sc->sc_burst &= sbusburst;
136
137	sbus_establish(&sc->sc_sd, &sc->sc_dev);
138
139	/* Propagate bootpath */
140	if (sa->sa_bp != NULL)
141		bp = sa->sa_bp + 1;
142	else
143		bp = NULL;
144
145	/* Allocate a bus tag */
146	sbt = (bus_space_tag_t)
147		malloc(sizeof(struct sparc_bus_space_tag), M_DEVBUF, M_NOWAIT);
148	if (sbt == NULL) {
149		printf("%s: attach: out of memory\n", self->dv_xname);
150		return;
151	}
152
153	printf(": %dK memory\n", sc->sc_bufsiz / 1024);
154
155	bzero(sbt, sizeof *sbt);
156	sbt->cookie = sc;
157	sbt->parent = sc->sc_bustag;
158
159	/* search through children */
160	for (node = firstchild(node); node; node = nextsibling(node)) {
161		struct sbus_attach_args sa;
162		sbus_setup_attach_args((struct sbus_softc *)parent,
163				       sbt, sc->sc_dmatag, node, bp, &sa);
164		(void)config_found(&sc->sc_dev, (void *)&sa, lebufprint);
165	}
166}
167