1 /* $NetBSD: lebuffer.c,v 1.35 2009/09/17 17:51:52 tsutsui Exp $ */
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: lebuffer.c,v 1.35 2009/09/17 17:51:52 tsutsui Exp $");
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>
43 #include <machine/autoconf.h>
46 #include <dev/sbus/sbusvar.h>
47 #include <dev/sbus/lebuffervar.h>
49 int lebufprint(void *, const char *);
50 int lebufmatch(device_t
, cfdata_t
, void *);
51 void lebufattach(device_t
, device_t
, void *);
53 CFATTACH_DECL_NEW(lebuffer
, sizeof(struct lebuf_softc
),
54 lebufmatch
, lebufattach
, NULL
, NULL
);
57 lebufprint(void *aux
, const char *busname
)
60 sbus_print(aux
, busname
);
65 lebufmatch(device_t parent
, cfdata_t cf
, void *aux
)
67 struct sbus_attach_args
*sa
= aux
;
69 return (strcmp(cf
->cf_name
, sa
->sa_name
) == 0);
73 * Attach all the sub-devices we can find
76 lebufattach(device_t parent
, device_t self
, void *aux
)
78 struct sbus_attach_args
*sa
= aux
;
79 struct lebuf_softc
*sc
= device_private(self
);
80 struct sbus_softc
*sbsc
= device_private(parent
);
83 bus_space_tag_t bt
= sa
->sa_bustag
;
84 bus_dma_tag_t dt
= sa
->sa_dmatag
;
85 bus_space_handle_t bh
;
89 if (sbus_bus_map(bt
, sa
->sa_slot
, sa
->sa_offset
, sa
->sa_size
,
90 BUS_SPACE_MAP_LINEAR
, &bh
) != 0) {
91 aprint_error(": cannot map registers\n");
96 * This device's "register space" is just a buffer where the
97 * Lance ring-buffers can be stored. Note the buffer's location
98 * and size, so the `le' driver can pick them up.
100 sc
->sc_buffer
= bus_space_vaddr(bt
, bh
);
101 sc
->sc_bufsiz
= sa
->sa_size
;
103 node
= sc
->sc_node
= sa
->sa_node
;
106 * Get transfer burst size from PROM
108 sbusburst
= sbsc
->sc_burst
;
110 sbusburst
= SBUS_BURST_32
- 1; /* 1->16 */
112 sc
->sc_burst
= prom_getpropint(node
, "burst-sizes", -1);
113 if (sc
->sc_burst
== -1)
114 /* take SBus burst sizes */
115 sc
->sc_burst
= sbusburst
;
117 /* Clamp at parent's burst sizes */
118 sc
->sc_burst
&= sbusburst
;
120 printf(": %dK memory\n", sc
->sc_bufsiz
/ 1024);
122 /* search through children */
123 for (node
= firstchild(node
); node
; node
= nextsibling(node
)) {
124 struct sbus_attach_args sax
;
125 sbus_setup_attach_args(sbsc
,
127 (void)config_found(self
, (void *)&sax
, lebufprint
);
128 sbus_destroy_attach_args(&sax
);