Deleted Added
full compact
dma_sbus.c (182062) dma_sbus.c (182876)
1/* $OpenBSD: dma_sbus.c,v 1.12 2005/03/03 01:41:45 miod Exp $ */
2/* $NetBSD: dma_sbus.c,v 1.5 2000/07/09 20:57:42 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/*-
41 * Copyright (c) 1994 Peter Galbavy. All rights reserved.
42 * Copyright (c) 2005 Marius Strobl <marius@FreeBSD.org>. All rights reserved.
43 *
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
46 * are met:
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution.
52 *
53 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
54 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
55 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
56 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
57 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
58 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
62 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 */
64
65#include <sys/cdefs.h>
1/* $OpenBSD: dma_sbus.c,v 1.12 2005/03/03 01:41:45 miod Exp $ */
2/* $NetBSD: dma_sbus.c,v 1.5 2000/07/09 20:57:42 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/*-
41 * Copyright (c) 1994 Peter Galbavy. All rights reserved.
42 * Copyright (c) 2005 Marius Strobl <marius@FreeBSD.org>. All rights reserved.
43 *
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
46 * are met:
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution.
52 *
53 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
54 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
55 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
56 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
57 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
58 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
62 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 */
64
65#include <sys/cdefs.h>
66__FBSDID("$FreeBSD: head/sys/sparc64/sbus/dma_sbus.c 182062 2008-08-23 15:20:33Z marius $");
66__FBSDID("$FreeBSD: head/sys/sparc64/sbus/dma_sbus.c 182876 2008-09-08 20:20:44Z marius $");
67
68#include <sys/param.h>
69#include <sys/systm.h>
70#include <sys/bus.h>
71#include <sys/kernel.h>
72#include <sys/module.h>
67
68#include <sys/param.h>
69#include <sys/systm.h>
70#include <sys/bus.h>
71#include <sys/kernel.h>
72#include <sys/module.h>
73#include <sys/resource.h>
74#include <sys/rman.h>
75
76#include <dev/ofw/ofw_bus.h>
77#include <dev/ofw/ofw_bus_subr.h>
78#include <dev/ofw/openfirm.h>
79
80#include <machine/bus.h>
81#include <machine/bus_common.h>
82#include <machine/resource.h>
83
84#include <sparc64/sbus/lsi64854reg.h>
85#include <sparc64/sbus/lsi64854var.h>
86#include <sparc64/sbus/ofw_sbus.h>
87#include <sparc64/sbus/sbusreg.h>
88#include <sparc64/sbus/sbusvar.h>
89
90struct dma_devinfo {
91 struct ofw_bus_devinfo ddi_obdinfo;
92 struct resource_list ddi_rl;
93};
94
95struct dma_softc {
96 struct lsi64854_softc sc_lsi64854; /* base device */
97 int sc_ign;
98 int sc_slot;
99};
100
101static devclass_t dma_devclass;
102
103static device_probe_t dma_probe;
104static device_attach_t dma_attach;
105static bus_print_child_t dma_print_child;
106static bus_probe_nomatch_t dma_probe_nomatch;
107static bus_get_resource_list_t dma_get_resource_list;
108static ofw_bus_get_devinfo_t dma_get_devinfo;
109
110static struct dma_devinfo *dma_setup_dinfo(device_t, struct dma_softc *,
111 phandle_t);
112static void dma_destroy_dinfo(struct dma_devinfo *);
113static int dma_print_res(struct dma_devinfo *);
114
115static device_method_t dma_methods[] = {
116 /* Device interface */
117 DEVMETHOD(device_probe, dma_probe),
118 DEVMETHOD(device_attach, dma_attach),
119 DEVMETHOD(device_shutdown, bus_generic_shutdown),
120 DEVMETHOD(device_suspend, bus_generic_suspend),
121 DEVMETHOD(device_resume, bus_generic_resume),
122
123 /* Bus interface */
124 DEVMETHOD(bus_print_child, dma_print_child),
125 DEVMETHOD(bus_probe_nomatch, dma_probe_nomatch),
126 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
127 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
128 DEVMETHOD(bus_alloc_resource, bus_generic_rl_alloc_resource),
129 DEVMETHOD(bus_release_resource, bus_generic_rl_release_resource),
130 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
131 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
132 DEVMETHOD(bus_get_resource_list, dma_get_resource_list),
133 DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource),
134
135 /* ofw_bus interface */
136 DEVMETHOD(ofw_bus_get_devinfo, dma_get_devinfo),
137 DEVMETHOD(ofw_bus_get_compat, ofw_bus_gen_get_compat),
138 DEVMETHOD(ofw_bus_get_model, ofw_bus_gen_get_model),
139 DEVMETHOD(ofw_bus_get_name, ofw_bus_gen_get_name),
140 DEVMETHOD(ofw_bus_get_node, ofw_bus_gen_get_node),
141 DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type),
142
143 { 0, 0 }
144};
145
146static driver_t dma_driver = {
147 "dma",
148 dma_methods,
149 sizeof(struct dma_softc),
150};
151
152DRIVER_MODULE(dma, sbus, dma_driver, dma_devclass, 0, 0);
153MODULE_DEPEND(dma, sbus, 1, 1, 1);
154MODULE_VERSION(dma, 1);
155
156static int
157dma_probe(device_t dev)
158{
159 const char *name;
160
161 name = ofw_bus_get_name(dev);
162 if (strcmp(name, "espdma") == 0 || strcmp(name, "dma") == 0 ||
163 strcmp(name, "ledma") == 0) {
164 device_set_desc_copy(dev, name);
165 return (0);
166 }
167 return (ENXIO);
168}
169
170static int
171dma_attach(device_t dev)
172{
173 struct dma_softc *dsc;
174 struct lsi64854_softc *lsc;
175 struct dma_devinfo *ddi;
176 device_t cdev;
177 const char *name;
178 char *cabletype;
179 uint32_t csr;
180 phandle_t child, node;
73#include <sys/rman.h>
74
75#include <dev/ofw/ofw_bus.h>
76#include <dev/ofw/ofw_bus_subr.h>
77#include <dev/ofw/openfirm.h>
78
79#include <machine/bus.h>
80#include <machine/bus_common.h>
81#include <machine/resource.h>
82
83#include <sparc64/sbus/lsi64854reg.h>
84#include <sparc64/sbus/lsi64854var.h>
85#include <sparc64/sbus/ofw_sbus.h>
86#include <sparc64/sbus/sbusreg.h>
87#include <sparc64/sbus/sbusvar.h>
88
89struct dma_devinfo {
90 struct ofw_bus_devinfo ddi_obdinfo;
91 struct resource_list ddi_rl;
92};
93
94struct dma_softc {
95 struct lsi64854_softc sc_lsi64854; /* base device */
96 int sc_ign;
97 int sc_slot;
98};
99
100static devclass_t dma_devclass;
101
102static device_probe_t dma_probe;
103static device_attach_t dma_attach;
104static bus_print_child_t dma_print_child;
105static bus_probe_nomatch_t dma_probe_nomatch;
106static bus_get_resource_list_t dma_get_resource_list;
107static ofw_bus_get_devinfo_t dma_get_devinfo;
108
109static struct dma_devinfo *dma_setup_dinfo(device_t, struct dma_softc *,
110 phandle_t);
111static void dma_destroy_dinfo(struct dma_devinfo *);
112static int dma_print_res(struct dma_devinfo *);
113
114static device_method_t dma_methods[] = {
115 /* Device interface */
116 DEVMETHOD(device_probe, dma_probe),
117 DEVMETHOD(device_attach, dma_attach),
118 DEVMETHOD(device_shutdown, bus_generic_shutdown),
119 DEVMETHOD(device_suspend, bus_generic_suspend),
120 DEVMETHOD(device_resume, bus_generic_resume),
121
122 /* Bus interface */
123 DEVMETHOD(bus_print_child, dma_print_child),
124 DEVMETHOD(bus_probe_nomatch, dma_probe_nomatch),
125 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
126 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
127 DEVMETHOD(bus_alloc_resource, bus_generic_rl_alloc_resource),
128 DEVMETHOD(bus_release_resource, bus_generic_rl_release_resource),
129 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
130 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
131 DEVMETHOD(bus_get_resource_list, dma_get_resource_list),
132 DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource),
133
134 /* ofw_bus interface */
135 DEVMETHOD(ofw_bus_get_devinfo, dma_get_devinfo),
136 DEVMETHOD(ofw_bus_get_compat, ofw_bus_gen_get_compat),
137 DEVMETHOD(ofw_bus_get_model, ofw_bus_gen_get_model),
138 DEVMETHOD(ofw_bus_get_name, ofw_bus_gen_get_name),
139 DEVMETHOD(ofw_bus_get_node, ofw_bus_gen_get_node),
140 DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type),
141
142 { 0, 0 }
143};
144
145static driver_t dma_driver = {
146 "dma",
147 dma_methods,
148 sizeof(struct dma_softc),
149};
150
151DRIVER_MODULE(dma, sbus, dma_driver, dma_devclass, 0, 0);
152MODULE_DEPEND(dma, sbus, 1, 1, 1);
153MODULE_VERSION(dma, 1);
154
155static int
156dma_probe(device_t dev)
157{
158 const char *name;
159
160 name = ofw_bus_get_name(dev);
161 if (strcmp(name, "espdma") == 0 || strcmp(name, "dma") == 0 ||
162 strcmp(name, "ledma") == 0) {
163 device_set_desc_copy(dev, name);
164 return (0);
165 }
166 return (ENXIO);
167}
168
169static int
170dma_attach(device_t dev)
171{
172 struct dma_softc *dsc;
173 struct lsi64854_softc *lsc;
174 struct dma_devinfo *ddi;
175 device_t cdev;
176 const char *name;
177 char *cabletype;
178 uint32_t csr;
179 phandle_t child, node;
181 int error, burst, children;
180 int error, i;
182
183 dsc = device_get_softc(dev);
184 lsc = &dsc->sc_lsi64854;
185
186 name = ofw_bus_get_name(dev);
187 node = ofw_bus_get_node(dev);
188 dsc->sc_ign = sbus_get_ign(dev);
189 dsc->sc_slot = sbus_get_slot(dev);
190
181
182 dsc = device_get_softc(dev);
183 lsc = &dsc->sc_lsi64854;
184
185 name = ofw_bus_get_name(dev);
186 node = ofw_bus_get_node(dev);
187 dsc->sc_ign = sbus_get_ign(dev);
188 dsc->sc_slot = sbus_get_slot(dev);
189
191 lsc->sc_rid = 0;
192 lsc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &lsc->sc_rid,
190 i = 0;
191 lsc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &i,
193 RF_ACTIVE);
194 if (lsc->sc_res == NULL) {
195 device_printf(dev, "cannot allocate resources\n");
196 return (ENXIO);
197 }
192 RF_ACTIVE);
193 if (lsc->sc_res == NULL) {
194 device_printf(dev, "cannot allocate resources\n");
195 return (ENXIO);
196 }
198 lsc->sc_regt = rman_get_bustag(lsc->sc_res);
199 lsc->sc_regh = rman_get_bushandle(lsc->sc_res);
200
201 if (strcmp(name, "espdma") == 0 || strcmp(name, "dma") == 0)
202 lsc->sc_channel = L64854_CHANNEL_SCSI;
203 else if (strcmp(name, "ledma") == 0) {
204 /*
205 * Check to see which cable type is currently active and
206 * set the appropriate bit in the ledma csr so that it
207 * gets used. If we didn't netboot, the PROM won't have
208 * the "cable-selection" property; default to TP and then
209 * the user can change it via a "media" option to ifconfig.
210 */
211 csr = L64854_GCSR(lsc);
212 if ((OF_getprop_alloc(node, "cable-selection", 1,
213 (void **)&cabletype)) == -1) {
214 /* assume TP if nothing there */
215 csr |= E_TP_AUI;
216 } else {
217 if (strcmp(cabletype, "aui") == 0)
218 csr &= ~E_TP_AUI;
219 else
220 csr |= E_TP_AUI;
221 free(cabletype, M_OFWPROP);
222 }
223 L64854_SCSR(lsc, csr);
224 DELAY(20000); /* manual says we need a 20ms delay */
225 lsc->sc_channel = L64854_CHANNEL_ENET;
226 } else {
227 device_printf(dev, "unsupported DMA channel\n");
228 error = ENXIO;
229 goto fail_lres;
230 }
231
232 error = bus_dma_tag_create(
233 bus_get_dma_tag(dev), /* parent */
234 1, 0, /* alignment, boundary */
235 BUS_SPACE_MAXADDR, /* lowaddr */
236 BUS_SPACE_MAXADDR, /* highaddr */
237 NULL, NULL, /* filter, filterarg */
238 BUS_SPACE_MAXSIZE_32BIT, /* maxsize */
239 0, /* nsegments */
240 BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
241 0, /* flags */
242 NULL, NULL, /* no locking */
243 &lsc->sc_parent_dmat);
244 if (error != 0) {
245 device_printf(dev, "cannot allocate parent DMA tag\n");
246 goto fail_lres;
247 }
248
197
198 if (strcmp(name, "espdma") == 0 || strcmp(name, "dma") == 0)
199 lsc->sc_channel = L64854_CHANNEL_SCSI;
200 else if (strcmp(name, "ledma") == 0) {
201 /*
202 * Check to see which cable type is currently active and
203 * set the appropriate bit in the ledma csr so that it
204 * gets used. If we didn't netboot, the PROM won't have
205 * the "cable-selection" property; default to TP and then
206 * the user can change it via a "media" option to ifconfig.
207 */
208 csr = L64854_GCSR(lsc);
209 if ((OF_getprop_alloc(node, "cable-selection", 1,
210 (void **)&cabletype)) == -1) {
211 /* assume TP if nothing there */
212 csr |= E_TP_AUI;
213 } else {
214 if (strcmp(cabletype, "aui") == 0)
215 csr &= ~E_TP_AUI;
216 else
217 csr |= E_TP_AUI;
218 free(cabletype, M_OFWPROP);
219 }
220 L64854_SCSR(lsc, csr);
221 DELAY(20000); /* manual says we need a 20ms delay */
222 lsc->sc_channel = L64854_CHANNEL_ENET;
223 } else {
224 device_printf(dev, "unsupported DMA channel\n");
225 error = ENXIO;
226 goto fail_lres;
227 }
228
229 error = bus_dma_tag_create(
230 bus_get_dma_tag(dev), /* parent */
231 1, 0, /* alignment, boundary */
232 BUS_SPACE_MAXADDR, /* lowaddr */
233 BUS_SPACE_MAXADDR, /* highaddr */
234 NULL, NULL, /* filter, filterarg */
235 BUS_SPACE_MAXSIZE_32BIT, /* maxsize */
236 0, /* nsegments */
237 BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
238 0, /* flags */
239 NULL, NULL, /* no locking */
240 &lsc->sc_parent_dmat);
241 if (error != 0) {
242 device_printf(dev, "cannot allocate parent DMA tag\n");
243 goto fail_lres;
244 }
245
249 burst = sbus_get_burstsz(dev);
250 lsc->sc_burst = (burst & SBUS_BURST_32) ? 32 :
251 (burst & SBUS_BURST_16) ? 16 : 0;
246 i = sbus_get_burstsz(dev);
247 lsc->sc_burst = (i & SBUS_BURST_32) ? 32 :
248 (i & SBUS_BURST_16) ? 16 : 0;
252 lsc->sc_dev = dev;
253
249 lsc->sc_dev = dev;
250
254 error = lsi64854_attach(lsc);
255 if (error != 0) {
256 device_printf(dev, "lsi64854_attach failed\n");
257 goto fail_lpdma;
258 }
259
260 /* Attach children. */
251 /* Attach children. */
261 children = 0;
252 i = 0;
262 for (child = OF_child(node); child != 0; child = OF_peer(child)) {
263 if ((ddi = dma_setup_dinfo(dev, dsc, child)) == NULL)
264 continue;
253 for (child = OF_child(node); child != 0; child = OF_peer(child)) {
254 if ((ddi = dma_setup_dinfo(dev, dsc, child)) == NULL)
255 continue;
265 if (children != 0) {
256 if (i != 0) {
266 device_printf(dev,
267 "<%s>: only one child per DMA channel supported\n",
268 ddi->ddi_obdinfo.obd_name);
269 dma_destroy_dinfo(ddi);
270 continue;
271 }
272 if ((cdev = device_add_child(dev, NULL, -1)) == NULL) {
273 device_printf(dev, "<%s>: device_add_child failed\n",
274 ddi->ddi_obdinfo.obd_name);
275 dma_destroy_dinfo(ddi);
276 continue;
277 }
278 device_set_ivars(cdev, ddi);
257 device_printf(dev,
258 "<%s>: only one child per DMA channel supported\n",
259 ddi->ddi_obdinfo.obd_name);
260 dma_destroy_dinfo(ddi);
261 continue;
262 }
263 if ((cdev = device_add_child(dev, NULL, -1)) == NULL) {
264 device_printf(dev, "<%s>: device_add_child failed\n",
265 ddi->ddi_obdinfo.obd_name);
266 dma_destroy_dinfo(ddi);
267 continue;
268 }
269 device_set_ivars(cdev, ddi);
279 children++;
270 i++;
280 }
281 return (bus_generic_attach(dev));
282
271 }
272 return (bus_generic_attach(dev));
273
283 fail_lpdma:
284 bus_dma_tag_destroy(lsc->sc_parent_dmat);
285 fail_lres:
274 fail_lres:
286 bus_release_resource(dev, SYS_RES_MEMORY, lsc->sc_rid, lsc->sc_res);
275 bus_release_resource(dev, SYS_RES_MEMORY, rman_get_rid(lsc->sc_res),
276 lsc->sc_res);
287 return (error);
288}
289
290static struct dma_devinfo *
291dma_setup_dinfo(device_t dev, struct dma_softc *dsc, phandle_t node)
292{
293 struct dma_devinfo *ddi;
294 struct sbus_regs *reg;
295 uint32_t base, iv, *intr;
296 int i, nreg, nintr, slot, rslot;
297
298 ddi = malloc(sizeof(*ddi), M_DEVBUF, M_WAITOK | M_ZERO);
299 if (ofw_bus_gen_setup_devinfo(&ddi->ddi_obdinfo, node) != 0) {
300 free(ddi, M_DEVBUF);
301 return (NULL);
302 }
303 resource_list_init(&ddi->ddi_rl);
304 slot = -1;
305 nreg = OF_getprop_alloc(node, "reg", sizeof(*reg), (void **)&reg);
306 if (nreg == -1) {
307 device_printf(dev, "<%s>: incomplete\n",
308 ddi->ddi_obdinfo.obd_name);
309 goto fail;
310 }
311 for (i = 0; i < nreg; i++) {
312 base = reg[i].sbr_offset;
313 if (SBUS_ABS(base)) {
314 rslot = SBUS_ABS_TO_SLOT(base);
315 base = SBUS_ABS_TO_OFFSET(base);
316 } else
317 rslot = reg[i].sbr_slot;
318 if (slot != -1 && slot != rslot) {
319 device_printf(dev, "<%s>: multiple slots\n",
320 ddi->ddi_obdinfo.obd_name);
321 free(reg, M_OFWPROP);
322 goto fail;
323 }
324 slot = rslot;
325
326 resource_list_add(&ddi->ddi_rl, SYS_RES_MEMORY, i, base,
327 base + reg[i].sbr_size, reg[i].sbr_size);
328 }
329 free(reg, M_OFWPROP);
330 if (slot != dsc->sc_slot) {
331 device_printf(dev, "<%s>: parent and child slot do not match\n",
332 ddi->ddi_obdinfo.obd_name);
333 goto fail;
334 }
335
336 /*
337 * The `interrupts' property contains the SBus interrupt level.
338 */
339 nintr = OF_getprop_alloc(node, "interrupts", sizeof(*intr),
340 (void **)&intr);
341 if (nintr != -1) {
342 for (i = 0; i < nintr; i++) {
343 iv = intr[i];
344 /*
345 * SBus card devices need the slot number encoded into
346 * the vector as this is generally not done.
347 */
348 if ((iv & INTMAP_OBIO_MASK) == 0)
349 iv |= slot << 3;
350 /* Set the IGN as appropriate. */
351 iv |= dsc->sc_ign << INTMAP_IGN_SHIFT;
352 resource_list_add(&ddi->ddi_rl, SYS_RES_IRQ, i,
353 iv, iv, 1);
354 }
355 free(intr, M_OFWPROP);
356 }
357 return (ddi);
358
359 fail:
360 dma_destroy_dinfo(ddi);
361 return (NULL);
362}
363
364static void
365dma_destroy_dinfo(struct dma_devinfo *dinfo)
366{
367
368 resource_list_free(&dinfo->ddi_rl);
369 ofw_bus_gen_destroy_devinfo(&dinfo->ddi_obdinfo);
370 free(dinfo, M_DEVBUF);
371}
372
373static int
374dma_print_child(device_t dev, device_t child)
375{
376 int rv;
377
378 rv = bus_print_child_header(dev, child);
379 rv += dma_print_res(device_get_ivars(child));
380 rv += bus_print_child_footer(dev, child);
381 return (rv);
382}
383
384static void
385dma_probe_nomatch(device_t dev, device_t child)
386{
387 const char *type;
388
389 device_printf(dev, "<%s>", ofw_bus_get_name(child));
390 dma_print_res(device_get_ivars(child));
391 type = ofw_bus_get_type(child);
392 printf(" type %s (no driver attached)\n",
393 type != NULL ? type : "unknown");
394}
395
396static struct resource_list *
397dma_get_resource_list(device_t dev, device_t child)
398{
399 struct dma_devinfo *ddi;
400
401 ddi = device_get_ivars(child);
402 return (&ddi->ddi_rl);
403}
404
405static const struct ofw_bus_devinfo *
406dma_get_devinfo(device_t bus, device_t child)
407{
408 struct dma_devinfo *ddi;
409
410 ddi = device_get_ivars(child);
411 return (&ddi->ddi_obdinfo);
412}
413
414static int
415dma_print_res(struct dma_devinfo *ddi)
416{
417 int rv;
418
419 rv = 0;
420 rv += resource_list_print_type(&ddi->ddi_rl, "mem", SYS_RES_MEMORY,
421 "%#lx");
422 rv += resource_list_print_type(&ddi->ddi_rl, "irq", SYS_RES_IRQ, "%ld");
423 return (rv);
424}
277 return (error);
278}
279
280static struct dma_devinfo *
281dma_setup_dinfo(device_t dev, struct dma_softc *dsc, phandle_t node)
282{
283 struct dma_devinfo *ddi;
284 struct sbus_regs *reg;
285 uint32_t base, iv, *intr;
286 int i, nreg, nintr, slot, rslot;
287
288 ddi = malloc(sizeof(*ddi), M_DEVBUF, M_WAITOK | M_ZERO);
289 if (ofw_bus_gen_setup_devinfo(&ddi->ddi_obdinfo, node) != 0) {
290 free(ddi, M_DEVBUF);
291 return (NULL);
292 }
293 resource_list_init(&ddi->ddi_rl);
294 slot = -1;
295 nreg = OF_getprop_alloc(node, "reg", sizeof(*reg), (void **)&reg);
296 if (nreg == -1) {
297 device_printf(dev, "<%s>: incomplete\n",
298 ddi->ddi_obdinfo.obd_name);
299 goto fail;
300 }
301 for (i = 0; i < nreg; i++) {
302 base = reg[i].sbr_offset;
303 if (SBUS_ABS(base)) {
304 rslot = SBUS_ABS_TO_SLOT(base);
305 base = SBUS_ABS_TO_OFFSET(base);
306 } else
307 rslot = reg[i].sbr_slot;
308 if (slot != -1 && slot != rslot) {
309 device_printf(dev, "<%s>: multiple slots\n",
310 ddi->ddi_obdinfo.obd_name);
311 free(reg, M_OFWPROP);
312 goto fail;
313 }
314 slot = rslot;
315
316 resource_list_add(&ddi->ddi_rl, SYS_RES_MEMORY, i, base,
317 base + reg[i].sbr_size, reg[i].sbr_size);
318 }
319 free(reg, M_OFWPROP);
320 if (slot != dsc->sc_slot) {
321 device_printf(dev, "<%s>: parent and child slot do not match\n",
322 ddi->ddi_obdinfo.obd_name);
323 goto fail;
324 }
325
326 /*
327 * The `interrupts' property contains the SBus interrupt level.
328 */
329 nintr = OF_getprop_alloc(node, "interrupts", sizeof(*intr),
330 (void **)&intr);
331 if (nintr != -1) {
332 for (i = 0; i < nintr; i++) {
333 iv = intr[i];
334 /*
335 * SBus card devices need the slot number encoded into
336 * the vector as this is generally not done.
337 */
338 if ((iv & INTMAP_OBIO_MASK) == 0)
339 iv |= slot << 3;
340 /* Set the IGN as appropriate. */
341 iv |= dsc->sc_ign << INTMAP_IGN_SHIFT;
342 resource_list_add(&ddi->ddi_rl, SYS_RES_IRQ, i,
343 iv, iv, 1);
344 }
345 free(intr, M_OFWPROP);
346 }
347 return (ddi);
348
349 fail:
350 dma_destroy_dinfo(ddi);
351 return (NULL);
352}
353
354static void
355dma_destroy_dinfo(struct dma_devinfo *dinfo)
356{
357
358 resource_list_free(&dinfo->ddi_rl);
359 ofw_bus_gen_destroy_devinfo(&dinfo->ddi_obdinfo);
360 free(dinfo, M_DEVBUF);
361}
362
363static int
364dma_print_child(device_t dev, device_t child)
365{
366 int rv;
367
368 rv = bus_print_child_header(dev, child);
369 rv += dma_print_res(device_get_ivars(child));
370 rv += bus_print_child_footer(dev, child);
371 return (rv);
372}
373
374static void
375dma_probe_nomatch(device_t dev, device_t child)
376{
377 const char *type;
378
379 device_printf(dev, "<%s>", ofw_bus_get_name(child));
380 dma_print_res(device_get_ivars(child));
381 type = ofw_bus_get_type(child);
382 printf(" type %s (no driver attached)\n",
383 type != NULL ? type : "unknown");
384}
385
386static struct resource_list *
387dma_get_resource_list(device_t dev, device_t child)
388{
389 struct dma_devinfo *ddi;
390
391 ddi = device_get_ivars(child);
392 return (&ddi->ddi_rl);
393}
394
395static const struct ofw_bus_devinfo *
396dma_get_devinfo(device_t bus, device_t child)
397{
398 struct dma_devinfo *ddi;
399
400 ddi = device_get_ivars(child);
401 return (&ddi->ddi_obdinfo);
402}
403
404static int
405dma_print_res(struct dma_devinfo *ddi)
406{
407 int rv;
408
409 rv = 0;
410 rv += resource_list_print_type(&ddi->ddi_rl, "mem", SYS_RES_MEMORY,
411 "%#lx");
412 rv += resource_list_print_type(&ddi->ddi_rl, "irq", SYS_RES_IRQ, "%ld");
413 return (rv);
414}