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 146392 2005-05-19 14:51:10Z marius $");
| 66__FBSDID("$FreeBSD: head/sys/sparc64/sbus/dma_sbus.c 152684 2005-11-22 16:39: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> 73#include <sys/resource.h> 74#include <sys/rman.h> 75 76#include <dev/ofw/ofw_bus.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>
|
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 {
| 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 {
|
90 char *ddi_compat; /* PROM compatible */ 91 char *ddi_model; /* PROM model */ 92 char *ddi_name; /* PROM name */ 93 phandle_t ddi_node; /* PROM node */ 94 char *ddi_type; /* PROM device_type */ 95
| 91 struct ofw_bus_devinfo ddi_obdinfo;
|
96 struct resource_list ddi_rl; 97}; 98 99struct dma_softc { 100 struct lsi64854_softc sc_lsi64854; /* base device */ 101 int sc_ign; 102 int sc_slot; 103}; 104 105static devclass_t dma_devclass; 106 107static device_probe_t dma_probe; 108static device_attach_t dma_attach; 109static bus_print_child_t dma_print_child; 110static bus_probe_nomatch_t dma_probe_nomatch; 111static bus_get_resource_list_t dma_get_resource_list; 112#if 0 113static bus_setup_intr_t dma_setup_intr; 114#endif
| 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; 108#if 0 109static bus_setup_intr_t dma_setup_intr; 110#endif
|
115static ofw_bus_get_compat_t dma_get_compat; 116static ofw_bus_get_model_t dma_get_model; 117static ofw_bus_get_name_t dma_get_name; 118static ofw_bus_get_node_t dma_get_node; 119static ofw_bus_get_type_t dma_get_type;
| 111static ofw_bus_get_devinfo_t dma_get_devinfo;
|
120
| 112
|
121static struct dma_devinfo *dma_setup_dinfo(device_t, phandle_t, char *);
| 113static struct dma_devinfo *dma_setup_dinfo(device_t, struct dma_softc *, 114 phandle_t);
|
122static void dma_destroy_dinfo(struct dma_devinfo *);
| 115static void dma_destroy_dinfo(struct dma_devinfo *);
|
| 116static int dma_print_res(struct dma_devinfo *);
|
123 124static device_method_t dma_methods[] = { 125 /* Device interface */ 126 DEVMETHOD(device_probe, dma_probe), 127 DEVMETHOD(device_attach, dma_attach), 128 129 /* Bus interface */ 130 DEVMETHOD(bus_print_child, dma_print_child), 131 DEVMETHOD(bus_probe_nomatch, dma_probe_nomatch), 132#if 0 133 DEVMETHOD(bus_setup_intr, dma_setup_intr), 134#else 135 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), 136#endif 137 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), 138 DEVMETHOD(bus_alloc_resource, bus_generic_rl_alloc_resource), 139 DEVMETHOD(bus_release_resource, bus_generic_rl_release_resource), 140 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), 141 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), 142 DEVMETHOD(bus_get_resource_list, dma_get_resource_list), 143 DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource), 144 145 /* ofw_bus interface */
| 117 118static device_method_t dma_methods[] = { 119 /* Device interface */ 120 DEVMETHOD(device_probe, dma_probe), 121 DEVMETHOD(device_attach, dma_attach), 122 123 /* Bus interface */ 124 DEVMETHOD(bus_print_child, dma_print_child), 125 DEVMETHOD(bus_probe_nomatch, dma_probe_nomatch), 126#if 0 127 DEVMETHOD(bus_setup_intr, dma_setup_intr), 128#else 129 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), 130#endif 131 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), 132 DEVMETHOD(bus_alloc_resource, bus_generic_rl_alloc_resource), 133 DEVMETHOD(bus_release_resource, bus_generic_rl_release_resource), 134 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), 135 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), 136 DEVMETHOD(bus_get_resource_list, dma_get_resource_list), 137 DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource), 138 139 /* ofw_bus interface */
|
146 DEVMETHOD(ofw_bus_get_compat, dma_get_compat), 147 DEVMETHOD(ofw_bus_get_model, dma_get_model), 148 DEVMETHOD(ofw_bus_get_name, dma_get_name), 149 DEVMETHOD(ofw_bus_get_node, dma_get_node), 150 DEVMETHOD(ofw_bus_get_type, dma_get_type),
| 140 DEVMETHOD(ofw_bus_get_devinfo, dma_get_devinfo), 141 DEVMETHOD(ofw_bus_get_compat, ofw_bus_gen_get_compat), 142 DEVMETHOD(ofw_bus_get_model, ofw_bus_gen_get_model), 143 DEVMETHOD(ofw_bus_get_name, ofw_bus_gen_get_name), 144 DEVMETHOD(ofw_bus_get_node, ofw_bus_gen_get_node), 145 DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type),
|
151 152 { 0, 0 } 153}; 154 155static driver_t dma_driver = { 156 "dma", 157 dma_methods, 158 sizeof(struct dma_softc), 159}; 160 161DRIVER_MODULE(dma, sbus, dma_driver, dma_devclass, 0, 0); 162 163static int 164dma_probe(device_t dev) 165{ 166 const char *name; 167 168 name = ofw_bus_get_name(dev); 169 if (strcmp(name, "espdma") == 0 || strcmp(name, "dma") == 0 || 170 strcmp(name, "ledma") == 0) { 171 device_set_desc_copy(dev, name); 172 return (0); 173 } 174 return (ENXIO); 175} 176 177static int 178dma_attach(device_t dev) 179{ 180 struct dma_softc *dsc; 181 struct lsi64854_softc *lsc; 182 struct dma_devinfo *ddi; 183 device_t cdev; 184 const char *name;
| 146 147 { 0, 0 } 148}; 149 150static driver_t dma_driver = { 151 "dma", 152 dma_methods, 153 sizeof(struct dma_softc), 154}; 155 156DRIVER_MODULE(dma, sbus, dma_driver, dma_devclass, 0, 0); 157 158static int 159dma_probe(device_t dev) 160{ 161 const char *name; 162 163 name = ofw_bus_get_name(dev); 164 if (strcmp(name, "espdma") == 0 || strcmp(name, "dma") == 0 || 165 strcmp(name, "ledma") == 0) { 166 device_set_desc_copy(dev, name); 167 return (0); 168 } 169 return (ENXIO); 170} 171 172static int 173dma_attach(device_t dev) 174{ 175 struct dma_softc *dsc; 176 struct lsi64854_softc *lsc; 177 struct dma_devinfo *ddi; 178 device_t cdev; 179 const char *name;
|
185 char *cabletype, *cname;
| 180 char *cabletype;
|
186 uint32_t csr; 187 phandle_t child, node; 188 int error, burst, children; 189 190 dsc = device_get_softc(dev);
| 181 uint32_t csr; 182 phandle_t child, node; 183 int error, burst, children; 184 185 dsc = device_get_softc(dev);
|
191 bzero(dsc, sizeof(struct dma_softc));
| |
192 lsc = &dsc->sc_lsi64854; 193 194 name = ofw_bus_get_name(dev); 195 node = ofw_bus_get_node(dev); 196 dsc->sc_ign = sbus_get_ign(dev); 197 dsc->sc_slot = sbus_get_slot(dev); 198 199 lsc->sc_rid = 0; 200 lsc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &lsc->sc_rid, 201 RF_ACTIVE); 202 if (lsc->sc_res == NULL) { 203 device_printf(dev, "cannot allocate resources\n"); 204 return (ENXIO); 205 } 206 lsc->sc_regt = rman_get_bustag(lsc->sc_res); 207 lsc->sc_regh = rman_get_bushandle(lsc->sc_res); 208 209 if (strcmp(name, "espdma") == 0 || strcmp(name, "dma") == 0) 210 lsc->sc_channel = L64854_CHANNEL_SCSI; 211 else if (strcmp(name, "ledma") == 0) { 212 /* 213 * Check to see which cable type is currently active and 214 * set the appropriate bit in the ledma csr so that it 215 * gets used. If we didn't netboot, the PROM won't have 216 * the "cable-selection" property; default to TP and then 217 * the user can change it via a "media" option to ifconfig. 218 */ 219 csr = L64854_GCSR(lsc); 220 if ((OF_getprop_alloc(node, "cable-selection", 1, 221 (void **)&cabletype)) == -1) { 222 /* assume TP if nothing there */ 223 csr |= E_TP_AUI; 224 } else { 225 if (strcmp(cabletype, "aui") == 0) 226 csr &= ~E_TP_AUI; 227 else 228 csr |= E_TP_AUI; 229 free(cabletype, M_OFWPROP); 230 } 231 L64854_SCSR(lsc, csr); 232 DELAY(20000); /* manual says we need a 20ms delay */ 233 lsc->sc_channel = L64854_CHANNEL_ENET; 234 } else { 235 device_printf(dev, "unsupported DMA channel\n"); 236 error = ENXIO; 237 goto fail_lres; 238 } 239 240 error = bus_dma_tag_create( 241 NULL, /* parent */ 242 PAGE_SIZE, 0, /* alignment, boundary */ 243 BUS_SPACE_MAXADDR, /* lowaddr */ 244 BUS_SPACE_MAXADDR, /* highaddr */ 245 NULL, NULL, /* filter, filterarg */ 246 BUS_SPACE_MAXSIZE_32BIT, /* maxsize */ 247 0, /* nsegments */ 248 BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ 249 0, /* flags */ 250 NULL, NULL, /* no locking */ 251 &lsc->sc_parent_dmat); 252 if (error != 0) { 253 device_printf(dev, "cannot allocate parent DMA tag\n"); 254 goto fail_lres; 255 } 256 257 burst = sbus_get_burstsz(dev); 258 lsc->sc_burst = (burst & SBUS_BURST_32) ? 32 : 259 (burst & SBUS_BURST_16) ? 16 : 0; 260 lsc->sc_dev = dev; 261 262 error = lsi64854_attach(lsc); 263 if (error != 0) { 264 device_printf(dev, "lsi64854_attach failed\n"); 265 goto fail_lpdma; 266 } 267 268 /* Attach children. */ 269 children = 0; 270 for (child = OF_child(node); child != 0; child = OF_peer(child)) {
| 186 lsc = &dsc->sc_lsi64854; 187 188 name = ofw_bus_get_name(dev); 189 node = ofw_bus_get_node(dev); 190 dsc->sc_ign = sbus_get_ign(dev); 191 dsc->sc_slot = sbus_get_slot(dev); 192 193 lsc->sc_rid = 0; 194 lsc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &lsc->sc_rid, 195 RF_ACTIVE); 196 if (lsc->sc_res == NULL) { 197 device_printf(dev, "cannot allocate resources\n"); 198 return (ENXIO); 199 } 200 lsc->sc_regt = rman_get_bustag(lsc->sc_res); 201 lsc->sc_regh = rman_get_bushandle(lsc->sc_res); 202 203 if (strcmp(name, "espdma") == 0 || strcmp(name, "dma") == 0) 204 lsc->sc_channel = L64854_CHANNEL_SCSI; 205 else if (strcmp(name, "ledma") == 0) { 206 /* 207 * Check to see which cable type is currently active and 208 * set the appropriate bit in the ledma csr so that it 209 * gets used. If we didn't netboot, the PROM won't have 210 * the "cable-selection" property; default to TP and then 211 * the user can change it via a "media" option to ifconfig. 212 */ 213 csr = L64854_GCSR(lsc); 214 if ((OF_getprop_alloc(node, "cable-selection", 1, 215 (void **)&cabletype)) == -1) { 216 /* assume TP if nothing there */ 217 csr |= E_TP_AUI; 218 } else { 219 if (strcmp(cabletype, "aui") == 0) 220 csr &= ~E_TP_AUI; 221 else 222 csr |= E_TP_AUI; 223 free(cabletype, M_OFWPROP); 224 } 225 L64854_SCSR(lsc, csr); 226 DELAY(20000); /* manual says we need a 20ms delay */ 227 lsc->sc_channel = L64854_CHANNEL_ENET; 228 } else { 229 device_printf(dev, "unsupported DMA channel\n"); 230 error = ENXIO; 231 goto fail_lres; 232 } 233 234 error = bus_dma_tag_create( 235 NULL, /* parent */ 236 PAGE_SIZE, 0, /* alignment, boundary */ 237 BUS_SPACE_MAXADDR, /* lowaddr */ 238 BUS_SPACE_MAXADDR, /* highaddr */ 239 NULL, NULL, /* filter, filterarg */ 240 BUS_SPACE_MAXSIZE_32BIT, /* maxsize */ 241 0, /* nsegments */ 242 BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ 243 0, /* flags */ 244 NULL, NULL, /* no locking */ 245 &lsc->sc_parent_dmat); 246 if (error != 0) { 247 device_printf(dev, "cannot allocate parent DMA tag\n"); 248 goto fail_lres; 249 } 250 251 burst = sbus_get_burstsz(dev); 252 lsc->sc_burst = (burst & SBUS_BURST_32) ? 32 : 253 (burst & SBUS_BURST_16) ? 16 : 0; 254 lsc->sc_dev = dev; 255 256 error = lsi64854_attach(lsc); 257 if (error != 0) { 258 device_printf(dev, "lsi64854_attach failed\n"); 259 goto fail_lpdma; 260 } 261 262 /* Attach children. */ 263 children = 0; 264 for (child = OF_child(node); child != 0; child = OF_peer(child)) {
|
271 if ((OF_getprop_alloc(child, "name", 1, (void **)&cname)) == -1)
| 265 if ((ddi = dma_setup_dinfo(dev, dsc, child)) == NULL)
|
272 continue;
| 266 continue;
|
273 if ((ddi = dma_setup_dinfo(dev, child, cname)) == NULL) { 274 device_printf(dev, "<%s>: incomplete\n", cname); 275 free(cname, M_OFWPROP); 276 continue; 277 }
| |
278 if (children != 0) {
| 267 if (children != 0) {
|
279 device_printf(dev, "<%s>: only one child per DMA " 280 "channel supported\n", cname);
| 268 device_printf(dev, 269 "<%s>: only one child per DMA channel supported\n", 270 ddi->ddi_obdinfo.obd_name);
|
281 dma_destroy_dinfo(ddi);
| 271 dma_destroy_dinfo(ddi);
|
282 free(cname, M_OFWPROP);
| |
283 continue; 284 } 285 if ((cdev = device_add_child(dev, NULL, -1)) == NULL) { 286 device_printf(dev, "<%s>: device_add_child failed\n",
| 272 continue; 273 } 274 if ((cdev = device_add_child(dev, NULL, -1)) == NULL) { 275 device_printf(dev, "<%s>: device_add_child failed\n",
|
287 cname);
| 276 ddi->ddi_obdinfo.obd_name);
|
288 dma_destroy_dinfo(ddi);
| 277 dma_destroy_dinfo(ddi);
|
289 free(cname, M_OFWPROP);
| |
290 continue; 291 } 292 device_set_ivars(cdev, ddi); 293 children++; 294 }
| 278 continue; 279 } 280 device_set_ivars(cdev, ddi); 281 children++; 282 }
|
295 error = bus_generic_attach(dev); 296 if (error != 0) { 297 device_printf(dev, "bus_generic_attach failed\n"); 298 goto fail_lsi; 299 }
| 283 return (bus_generic_attach(dev));
|
300
| 284
|
301 return (0); 302 303 fail_lsi: 304 lsi64854_detach(lsc);
| |
305 fail_lpdma: 306 bus_dma_tag_destroy(lsc->sc_parent_dmat); 307 fail_lres: 308 bus_release_resource(dev, SYS_RES_MEMORY, lsc->sc_rid, lsc->sc_res); 309 return (error); 310} 311 312static struct dma_devinfo *
| 285 fail_lpdma: 286 bus_dma_tag_destroy(lsc->sc_parent_dmat); 287 fail_lres: 288 bus_release_resource(dev, SYS_RES_MEMORY, lsc->sc_rid, lsc->sc_res); 289 return (error); 290} 291 292static struct dma_devinfo *
|
313dma_setup_dinfo(device_t dev, phandle_t node, char *name)
| 293dma_setup_dinfo(device_t dev, struct dma_softc *dsc, phandle_t node)
|
314{
| 294{
|
315 struct dma_softc *dsc;
| |
316 struct dma_devinfo *ddi; 317 struct sbus_regs *reg; 318 uint32_t base, iv, *intr; 319 int i, nreg, nintr, slot, rslot; 320
| 295 struct dma_devinfo *ddi; 296 struct sbus_regs *reg; 297 uint32_t base, iv, *intr; 298 int i, nreg, nintr, slot, rslot; 299
|
321 dsc = device_get_softc(dev); 322
| |
323 ddi = malloc(sizeof(*ddi), M_DEVBUF, M_WAITOK | M_ZERO);
| 300 ddi = malloc(sizeof(*ddi), M_DEVBUF, M_WAITOK | M_ZERO);
|
324 if (ddi == NULL)
| 301 if (ofw_bus_gen_setup_devinfo(&ddi->ddi_obdinfo, node) != 0) { 302 free(ddi, M_DEVBUF);
|
325 return (NULL);
| 303 return (NULL);
|
| 304 }
|
326 resource_list_init(&ddi->ddi_rl);
| 305 resource_list_init(&ddi->ddi_rl);
|
327 ddi->ddi_name = name; 328 ddi->ddi_node = node; 329 OF_getprop_alloc(node, "compatible", 1, (void **)&ddi->ddi_compat); 330 OF_getprop_alloc(node, "device_type", 1, (void **)&ddi->ddi_type); 331 OF_getprop_alloc(node, "model", 1, (void **)&ddi->ddi_model);
| |
332 slot = -1; 333 nreg = OF_getprop_alloc(node, "reg", sizeof(*reg), (void **)®); 334 if (nreg == -1) {
| 306 slot = -1; 307 nreg = OF_getprop_alloc(node, "reg", sizeof(*reg), (void **)®); 308 if (nreg == -1) {
|
335 dma_destroy_dinfo(ddi); 336 return (NULL);
| 309 device_printf(dev, "<%s>: incomplete\n", 310 ddi->ddi_obdinfo.obd_name); 311 goto fail;
|
337 } 338 for (i = 0; i < nreg; i++) { 339 base = reg[i].sbr_offset; 340 if (SBUS_ABS(base)) { 341 rslot = SBUS_ABS_TO_SLOT(base); 342 base = SBUS_ABS_TO_OFFSET(base); 343 } else 344 rslot = reg[i].sbr_slot; 345 if (slot != -1 && slot != rslot) {
| 312 } 313 for (i = 0; i < nreg; i++) { 314 base = reg[i].sbr_offset; 315 if (SBUS_ABS(base)) { 316 rslot = SBUS_ABS_TO_SLOT(base); 317 base = SBUS_ABS_TO_OFFSET(base); 318 } else 319 rslot = reg[i].sbr_slot; 320 if (slot != -1 && slot != rslot) {
|
346 device_printf(dev, "<%s>: multiple slots\n", name);
| 321 device_printf(dev, "<%s>: multiple slots\n", 322 ddi->ddi_obdinfo.obd_name);
|
347 free(reg, M_OFWPROP);
| 323 free(reg, M_OFWPROP);
|
348 dma_destroy_dinfo(ddi); 349 return (NULL);
| 324 goto fail;
|
350 } 351 slot = rslot; 352 353 resource_list_add(&ddi->ddi_rl, SYS_RES_MEMORY, i, base, 354 base + reg[i].sbr_size, reg[i].sbr_size); 355 } 356 free(reg, M_OFWPROP); 357 if (slot != dsc->sc_slot) { 358 device_printf(dev, "<%s>: parent and child slot do not match\n",
| 325 } 326 slot = rslot; 327 328 resource_list_add(&ddi->ddi_rl, SYS_RES_MEMORY, i, base, 329 base + reg[i].sbr_size, reg[i].sbr_size); 330 } 331 free(reg, M_OFWPROP); 332 if (slot != dsc->sc_slot) { 333 device_printf(dev, "<%s>: parent and child slot do not match\n",
|
359 name); 360 dma_destroy_dinfo(ddi); 361 return (NULL);
| 334 ddi->ddi_obdinfo.obd_name); 335 goto fail;
|
362 } 363 364 /* 365 * The `interrupts' property contains the SBus interrupt level. 366 */ 367 nintr = OF_getprop_alloc(node, "interrupts", sizeof(*intr), 368 (void **)&intr); 369 if (nintr != -1) { 370 for (i = 0; i < nintr; i++) { 371 iv = intr[i]; 372 /* 373 * SBus card devices need the slot number encoded into 374 * the vector as this is generally not done. 375 */ 376 if ((iv & INTMAP_OBIO_MASK) == 0) 377 iv |= slot << 3; 378 /* Set the IGN as appropriate. */ 379 iv |= dsc->sc_ign << INTMAP_IGN_SHIFT; 380 resource_list_add(&ddi->ddi_rl, SYS_RES_IRQ, i, 381 iv, iv, 1); 382 } 383 free(intr, M_OFWPROP); 384 } 385 return (ddi);
| 336 } 337 338 /* 339 * The `interrupts' property contains the SBus interrupt level. 340 */ 341 nintr = OF_getprop_alloc(node, "interrupts", sizeof(*intr), 342 (void **)&intr); 343 if (nintr != -1) { 344 for (i = 0; i < nintr; i++) { 345 iv = intr[i]; 346 /* 347 * SBus card devices need the slot number encoded into 348 * the vector as this is generally not done. 349 */ 350 if ((iv & INTMAP_OBIO_MASK) == 0) 351 iv |= slot << 3; 352 /* Set the IGN as appropriate. */ 353 iv |= dsc->sc_ign << INTMAP_IGN_SHIFT; 354 resource_list_add(&ddi->ddi_rl, SYS_RES_IRQ, i, 355 iv, iv, 1); 356 } 357 free(intr, M_OFWPROP); 358 } 359 return (ddi);
|
| 360 361 fail: 362 dma_destroy_dinfo(ddi); 363 return (NULL);
|
386} 387 388static void 389dma_destroy_dinfo(struct dma_devinfo *dinfo) 390{ 391 392 resource_list_free(&dinfo->ddi_rl);
| 364} 365 366static void 367dma_destroy_dinfo(struct dma_devinfo *dinfo) 368{ 369 370 resource_list_free(&dinfo->ddi_rl);
|
393 if (dinfo->ddi_compat != NULL) 394 free(dinfo->ddi_compat, M_OFWPROP); 395 if (dinfo->ddi_model != NULL) 396 free(dinfo->ddi_model, M_OFWPROP); 397 if (dinfo->ddi_type != NULL) 398 free(dinfo->ddi_type, M_OFWPROP);
| 371 ofw_bus_gen_destroy_devinfo(&dinfo->ddi_obdinfo);
|
399 free(dinfo, M_DEVBUF); 400} 401 402static int 403dma_print_child(device_t dev, device_t child) 404{
| 372 free(dinfo, M_DEVBUF); 373} 374 375static int 376dma_print_child(device_t dev, device_t child) 377{
|
405 struct dma_devinfo *ddi; 406 struct resource_list *rl;
| |
407 int rv; 408
| 378 int rv; 379
|
409 ddi = device_get_ivars(child); 410 rl = &ddi->ddi_rl;
| |
411 rv = bus_print_child_header(dev, child);
| 380 rv = bus_print_child_header(dev, child);
|
412 rv += resource_list_print_type(rl, "mem", SYS_RES_MEMORY, "%#lx"); 413 rv += resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%ld");
| 381 rv += dma_print_res(device_get_ivars(child));
|
414 rv += bus_print_child_footer(dev, child); 415 return (rv); 416} 417 418static void 419dma_probe_nomatch(device_t dev, device_t child) 420{
| 382 rv += bus_print_child_footer(dev, child); 383 return (rv); 384} 385 386static void 387dma_probe_nomatch(device_t dev, device_t child) 388{
|
421 struct dma_devinfo *ddi; 422 struct resource_list *rl;
| 389 const char *type;
|
423
| 390
|
424 ddi = device_get_ivars(child); 425 rl = &ddi->ddi_rl; 426 device_printf(dev, "<%s>", ddi->ddi_name); 427 resource_list_print_type(rl, "mem", SYS_RES_MEMORY, "%#lx"); 428 resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%ld"); 429 printf(" type %s (no driver attached)\n", 430 ddi->ddi_type != NULL ? ddi->ddi_type : "unknown");
| 391 device_printf(dev, "<%s>", ofw_bus_get_name(child)); 392 dma_print_res(device_get_ivars(child)); 393 type = ofw_bus_get_type(child); 394 printf(" type %s (no driver attached)\n", 395 type != NULL ? type : "unknown");
|
431} 432 433static struct resource_list * 434dma_get_resource_list(device_t dev, device_t child) 435{ 436 struct dma_devinfo *ddi; 437 438 ddi = device_get_ivars(child); 439 return (&ddi->ddi_rl); 440} 441 442#if 0 443static int 444dma_setup_intr(device_t dev, device_t child, struct resource *ires, int flags, 445 driver_intr_t *intr, void *arg, void **cookiep) 446{ 447 struct lsi64854_softc *sc; 448 449 sc = (struct lsi64854_softc *)device_get_softc(dev); 450 /* XXX - for now only le; do ESP later */ 451 if (sc->sc_channel == L64854_CHANNEL_ENET) { 452 sc->sc_intrchain = intr; 453 sc->sc_intrchainarg = arg; 454 intr = (driver_intr_t *)lsi64854_enet_intr; 455 arg = sc; 456 } 457 458 return (BUS_SETUP_INTR(device_get_parent(dev), child, ires, flags, 459 intr, arg, cookiep)); 460} 461#endif 462
| 396} 397 398static struct resource_list * 399dma_get_resource_list(device_t dev, device_t child) 400{ 401 struct dma_devinfo *ddi; 402 403 ddi = device_get_ivars(child); 404 return (&ddi->ddi_rl); 405} 406 407#if 0 408static int 409dma_setup_intr(device_t dev, device_t child, struct resource *ires, int flags, 410 driver_intr_t *intr, void *arg, void **cookiep) 411{ 412 struct lsi64854_softc *sc; 413 414 sc = (struct lsi64854_softc *)device_get_softc(dev); 415 /* XXX - for now only le; do ESP later */ 416 if (sc->sc_channel == L64854_CHANNEL_ENET) { 417 sc->sc_intrchain = intr; 418 sc->sc_intrchainarg = arg; 419 intr = (driver_intr_t *)lsi64854_enet_intr; 420 arg = sc; 421 } 422 423 return (BUS_SETUP_INTR(device_get_parent(dev), child, ires, flags, 424 intr, arg, cookiep)); 425} 426#endif 427
|
463static const char * 464dma_get_compat(device_t bus, device_t dev)
| 428static const struct ofw_bus_devinfo * 429dma_get_devinfo(device_t bus, device_t child)
|
465{
| 430{
|
466 struct dma_devinfo *dinfo;
| 431 struct dma_devinfo *ddi;
|
467
| 432
|
468 dinfo = device_get_ivars(dev); 469 return (dinfo->ddi_compat);
| 433 ddi = device_get_ivars(child); 434 return (&ddi->ddi_obdinfo);
|
470} 471
| 435} 436
|
472static const char * 473dma_get_model(device_t bus, device_t dev)
| 437static int 438dma_print_res(struct dma_devinfo *ddi)
|
474{
| 439{
|
475 struct dma_devinfo *dinfo;
| 440 int rv;
|
476
| 441
|
477 dinfo = device_get_ivars(dev); 478 return (dinfo->ddi_model);
| 442 rv = 0; 443 rv += resource_list_print_type(&ddi->ddi_rl, "mem", SYS_RES_MEMORY, 444 "%#lx"); 445 rv += resource_list_print_type(&ddi->ddi_rl, "irq", SYS_RES_IRQ, "%ld"); 446 return (rv);
|
479}
| 447}
|
480 481static const char * 482dma_get_name(device_t bus, device_t dev) 483{ 484 struct dma_devinfo *dinfo; 485 486 dinfo = device_get_ivars(dev); 487 return (dinfo->ddi_name); 488} 489 490static phandle_t 491dma_get_node(device_t bus, device_t dev) 492{ 493 struct dma_devinfo *dinfo; 494 495 dinfo = device_get_ivars(dev); 496 return (dinfo->ddi_node); 497} 498 499static const char * 500dma_get_type(device_t bus, device_t dev) 501{ 502 struct dma_devinfo *dinfo; 503 504 dinfo = device_get_ivars(dev); 505 return (dinfo->ddi_type); 506}
| |
| |