lebuffer.c revision 1.30
1/*	$NetBSD: lebuffer.c,v 1.30 2009/03/14 21:04:22 dsl 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 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: lebuffer.c,v 1.30 2009/03/14 21:04:22 dsl Exp $");
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/kernel.h>
38#include <sys/errno.h>
39#include <sys/device.h>
40#include <sys/malloc.h>
41
42#include <sys/bus.h>
43#include <machine/autoconf.h>
44#include <sys/cpu.h>
45
46#include <dev/sbus/sbusvar.h>
47#include <dev/sbus/lebuffervar.h>
48
49int	lebufprint(void *, const char *);
50int	lebufmatch(struct device *, struct cfdata *, void *);
51void	lebufattach(struct device *, struct device *, void *);
52
53CFATTACH_DECL(lebuffer, sizeof(struct lebuf_softc),
54    lebufmatch, lebufattach, NULL, NULL);
55
56int
57lebufprint(void *aux, const char *busname)
58{
59
60	sbus_print(aux, busname);
61	return (UNCONF);
62}
63
64int
65lebufmatch(struct device *parent, struct cfdata *cf, void *aux)
66{
67	struct sbus_attach_args *sa = aux;
68
69	return (strcmp(cf->cf_name, sa->sa_name) == 0);
70}
71
72/*
73 * Attach all the sub-devices we can find
74 */
75void
76lebufattach(struct device *parent, struct device *self, void *aux)
77{
78	struct sbus_attach_args *sa = aux;
79	struct lebuf_softc *sc = (void *)self;
80	int node;
81	int sbusburst;
82	bus_space_tag_t bt = sa->sa_bustag;
83	bus_dma_tag_t	dt = sa->sa_dmatag;
84	bus_space_handle_t bh;
85
86	if (sbus_bus_map(bt, sa->sa_slot, sa->sa_offset, sa->sa_size,
87			 BUS_SPACE_MAP_LINEAR, &bh) != 0) {
88		aprint_error_dev(self, "attach: cannot map registers\n");
89		return;
90	}
91
92	/*
93	 * This device's "register space" is just a buffer where the
94	 * Lance ring-buffers can be stored. Note the buffer's location
95	 * and size, so the `le' driver can pick them up.
96	 */
97	sc->sc_buffer = bus_space_vaddr(bt, bh);
98	sc->sc_bufsiz = sa->sa_size;
99
100	node = sc->sc_node = sa->sa_node;
101
102	/*
103	 * Get transfer burst size from PROM
104	 */
105	sbusburst = ((struct sbus_softc *)parent)->sc_burst;
106	if (sbusburst == 0)
107		sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
108
109	sc->sc_burst = prom_getpropint(node, "burst-sizes", -1);
110	if (sc->sc_burst == -1)
111		/* take SBus burst sizes */
112		sc->sc_burst = sbusburst;
113
114	/* Clamp at parent's burst sizes */
115	sc->sc_burst &= sbusburst;
116
117	sbus_establish(&sc->sc_sd, &sc->sc_dev);
118
119	printf(": %dK memory\n", sc->sc_bufsiz / 1024);
120
121	/* search through children */
122	for (node = firstchild(node); node; node = nextsibling(node)) {
123		struct sbus_attach_args sax;
124		sbus_setup_attach_args((struct sbus_softc *)parent,
125				       bt, dt, node, &sax);
126		(void)config_found(&sc->sc_dev, (void *)&sax, lebufprint);
127		sbus_destroy_attach_args(&sax);
128	}
129}
130