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