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