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>
|
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 */ 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), 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; 180 char *cabletype; 181 uint32_t csr; 182 phandle_t child, node; 183 int error, burst, children; 184 185 dsc = device_get_softc(dev); 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)) { 265 if ((ddi = dma_setup_dinfo(dev, dsc, child)) == NULL) 266 continue; 267 if (children != 0) { 268 device_printf(dev, 269 "<%s>: only one child per DMA channel supported\n", 270 ddi->ddi_obdinfo.obd_name); 271 dma_destroy_dinfo(ddi); 272 continue; 273 } 274 if ((cdev = device_add_child(dev, NULL, -1)) == NULL) { 275 device_printf(dev, "<%s>: device_add_child failed\n", 276 ddi->ddi_obdinfo.obd_name); 277 dma_destroy_dinfo(ddi); 278 continue; 279 } 280 device_set_ivars(cdev, ddi); 281 children++; 282 } 283 return (bus_generic_attach(dev)); 284 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 * 293dma_setup_dinfo(device_t dev, struct dma_softc *dsc, phandle_t node) 294{ 295 struct dma_devinfo *ddi; 296 struct sbus_regs *reg; 297 uint32_t base, iv, *intr; 298 int i, nreg, nintr, slot, rslot; 299 300 ddi = malloc(sizeof(*ddi), M_DEVBUF, M_WAITOK | M_ZERO); 301 if (ofw_bus_gen_setup_devinfo(&ddi->ddi_obdinfo, node) != 0) { 302 free(ddi, M_DEVBUF); 303 return (NULL); 304 } 305 resource_list_init(&ddi->ddi_rl); 306 slot = -1; 307 nreg = OF_getprop_alloc(node, "reg", sizeof(*reg), (void **)®); 308 if (nreg == -1) { 309 device_printf(dev, "<%s>: incomplete\n", 310 ddi->ddi_obdinfo.obd_name); 311 goto fail; 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) { 321 device_printf(dev, "<%s>: multiple slots\n", 322 ddi->ddi_obdinfo.obd_name); 323 free(reg, M_OFWPROP); 324 goto fail; 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", 334 ddi->ddi_obdinfo.obd_name); 335 goto fail; 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); 364} 365 366static void 367dma_destroy_dinfo(struct dma_devinfo *dinfo) 368{ 369 370 resource_list_free(&dinfo->ddi_rl); 371 ofw_bus_gen_destroy_devinfo(&dinfo->ddi_obdinfo); 372 free(dinfo, M_DEVBUF); 373} 374 375static int 376dma_print_child(device_t dev, device_t child) 377{ 378 int rv; 379 380 rv = bus_print_child_header(dev, child); 381 rv += dma_print_res(device_get_ivars(child)); 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{ 389 const char *type; 390 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"); 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
| 128 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), 129 DEVMETHOD(bus_alloc_resource, bus_generic_rl_alloc_resource), 130 DEVMETHOD(bus_release_resource, bus_generic_rl_release_resource), 131 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), 132 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), 133 DEVMETHOD(bus_get_resource_list, dma_get_resource_list), 134 DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource), 135 136 /* ofw_bus interface */ 137 DEVMETHOD(ofw_bus_get_devinfo, dma_get_devinfo), 138 DEVMETHOD(ofw_bus_get_compat, ofw_bus_gen_get_compat), 139 DEVMETHOD(ofw_bus_get_model, ofw_bus_gen_get_model), 140 DEVMETHOD(ofw_bus_get_name, ofw_bus_gen_get_name), 141 DEVMETHOD(ofw_bus_get_node, ofw_bus_gen_get_node), 142 DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type), 143 144 { 0, 0 } 145}; 146 147static driver_t dma_driver = { 148 "dma", 149 dma_methods, 150 sizeof(struct dma_softc), 151}; 152 153DRIVER_MODULE(dma, sbus, dma_driver, dma_devclass, 0, 0); 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; 180 int error, burst, children; 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 190 lsc->sc_rid = 0; 191 lsc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &lsc->sc_rid, 192 RF_ACTIVE); 193 if (lsc->sc_res == NULL) { 194 device_printf(dev, "cannot allocate resources\n"); 195 return (ENXIO); 196 } 197 lsc->sc_regt = rman_get_bustag(lsc->sc_res); 198 lsc->sc_regh = rman_get_bushandle(lsc->sc_res); 199 200 if (strcmp(name, "espdma") == 0 || strcmp(name, "dma") == 0) 201 lsc->sc_channel = L64854_CHANNEL_SCSI; 202 else if (strcmp(name, "ledma") == 0) { 203 /* 204 * Check to see which cable type is currently active and 205 * set the appropriate bit in the ledma csr so that it 206 * gets used. If we didn't netboot, the PROM won't have 207 * the "cable-selection" property; default to TP and then 208 * the user can change it via a "media" option to ifconfig. 209 */ 210 csr = L64854_GCSR(lsc); 211 if ((OF_getprop_alloc(node, "cable-selection", 1, 212 (void **)&cabletype)) == -1) { 213 /* assume TP if nothing there */ 214 csr |= E_TP_AUI; 215 } else { 216 if (strcmp(cabletype, "aui") == 0) 217 csr &= ~E_TP_AUI; 218 else 219 csr |= E_TP_AUI; 220 free(cabletype, M_OFWPROP); 221 } 222 L64854_SCSR(lsc, csr); 223 DELAY(20000); /* manual says we need a 20ms delay */ 224 lsc->sc_channel = L64854_CHANNEL_ENET; 225 } else { 226 device_printf(dev, "unsupported DMA channel\n"); 227 error = ENXIO; 228 goto fail_lres; 229 } 230 231 error = bus_dma_tag_create( 232 NULL, /* parent */ 233 PAGE_SIZE, 0, /* alignment, boundary */ 234 BUS_SPACE_MAXADDR, /* lowaddr */ 235 BUS_SPACE_MAXADDR, /* highaddr */ 236 NULL, NULL, /* filter, filterarg */ 237 BUS_SPACE_MAXSIZE_32BIT, /* maxsize */ 238 0, /* nsegments */ 239 BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ 240 0, /* flags */ 241 NULL, NULL, /* no locking */ 242 &lsc->sc_parent_dmat); 243 if (error != 0) { 244 device_printf(dev, "cannot allocate parent DMA tag\n"); 245 goto fail_lres; 246 } 247 248 burst = sbus_get_burstsz(dev); 249 lsc->sc_burst = (burst & SBUS_BURST_32) ? 32 : 250 (burst & SBUS_BURST_16) ? 16 : 0; 251 lsc->sc_dev = dev; 252 253 error = lsi64854_attach(lsc); 254 if (error != 0) { 255 device_printf(dev, "lsi64854_attach failed\n"); 256 goto fail_lpdma; 257 } 258 259 /* Attach children. */ 260 children = 0; 261 for (child = OF_child(node); child != 0; child = OF_peer(child)) { 262 if ((ddi = dma_setup_dinfo(dev, dsc, child)) == NULL) 263 continue; 264 if (children != 0) { 265 device_printf(dev, 266 "<%s>: only one child per DMA channel supported\n", 267 ddi->ddi_obdinfo.obd_name); 268 dma_destroy_dinfo(ddi); 269 continue; 270 } 271 if ((cdev = device_add_child(dev, NULL, -1)) == NULL) { 272 device_printf(dev, "<%s>: device_add_child failed\n", 273 ddi->ddi_obdinfo.obd_name); 274 dma_destroy_dinfo(ddi); 275 continue; 276 } 277 device_set_ivars(cdev, ddi); 278 children++; 279 } 280 return (bus_generic_attach(dev)); 281 282 fail_lpdma: 283 bus_dma_tag_destroy(lsc->sc_parent_dmat); 284 fail_lres: 285 bus_release_resource(dev, SYS_RES_MEMORY, lsc->sc_rid, lsc->sc_res); 286 return (error); 287} 288 289static struct dma_devinfo * 290dma_setup_dinfo(device_t dev, struct dma_softc *dsc, phandle_t node) 291{ 292 struct dma_devinfo *ddi; 293 struct sbus_regs *reg; 294 uint32_t base, iv, *intr; 295 int i, nreg, nintr, slot, rslot; 296 297 ddi = malloc(sizeof(*ddi), M_DEVBUF, M_WAITOK | M_ZERO); 298 if (ofw_bus_gen_setup_devinfo(&ddi->ddi_obdinfo, node) != 0) { 299 free(ddi, M_DEVBUF); 300 return (NULL); 301 } 302 resource_list_init(&ddi->ddi_rl); 303 slot = -1; 304 nreg = OF_getprop_alloc(node, "reg", sizeof(*reg), (void **)®); 305 if (nreg == -1) { 306 device_printf(dev, "<%s>: incomplete\n", 307 ddi->ddi_obdinfo.obd_name); 308 goto fail; 309 } 310 for (i = 0; i < nreg; i++) { 311 base = reg[i].sbr_offset; 312 if (SBUS_ABS(base)) { 313 rslot = SBUS_ABS_TO_SLOT(base); 314 base = SBUS_ABS_TO_OFFSET(base); 315 } else 316 rslot = reg[i].sbr_slot; 317 if (slot != -1 && slot != rslot) { 318 device_printf(dev, "<%s>: multiple slots\n", 319 ddi->ddi_obdinfo.obd_name); 320 free(reg, M_OFWPROP); 321 goto fail; 322 } 323 slot = rslot; 324 325 resource_list_add(&ddi->ddi_rl, SYS_RES_MEMORY, i, base, 326 base + reg[i].sbr_size, reg[i].sbr_size); 327 } 328 free(reg, M_OFWPROP); 329 if (slot != dsc->sc_slot) { 330 device_printf(dev, "<%s>: parent and child slot do not match\n", 331 ddi->ddi_obdinfo.obd_name); 332 goto fail; 333 } 334 335 /* 336 * The `interrupts' property contains the SBus interrupt level. 337 */ 338 nintr = OF_getprop_alloc(node, "interrupts", sizeof(*intr), 339 (void **)&intr); 340 if (nintr != -1) { 341 for (i = 0; i < nintr; i++) { 342 iv = intr[i]; 343 /* 344 * SBus card devices need the slot number encoded into 345 * the vector as this is generally not done. 346 */ 347 if ((iv & INTMAP_OBIO_MASK) == 0) 348 iv |= slot << 3; 349 /* Set the IGN as appropriate. */ 350 iv |= dsc->sc_ign << INTMAP_IGN_SHIFT; 351 resource_list_add(&ddi->ddi_rl, SYS_RES_IRQ, i, 352 iv, iv, 1); 353 } 354 free(intr, M_OFWPROP); 355 } 356 return (ddi); 357 358 fail: 359 dma_destroy_dinfo(ddi); 360 return (NULL); 361} 362 363static void 364dma_destroy_dinfo(struct dma_devinfo *dinfo) 365{ 366 367 resource_list_free(&dinfo->ddi_rl); 368 ofw_bus_gen_destroy_devinfo(&dinfo->ddi_obdinfo); 369 free(dinfo, M_DEVBUF); 370} 371 372static int 373dma_print_child(device_t dev, device_t child) 374{ 375 int rv; 376 377 rv = bus_print_child_header(dev, child); 378 rv += dma_print_res(device_get_ivars(child)); 379 rv += bus_print_child_footer(dev, child); 380 return (rv); 381} 382 383static void 384dma_probe_nomatch(device_t dev, device_t child) 385{ 386 const char *type; 387 388 device_printf(dev, "<%s>", ofw_bus_get_name(child)); 389 dma_print_res(device_get_ivars(child)); 390 type = ofw_bus_get_type(child); 391 printf(" type %s (no driver attached)\n", 392 type != NULL ? type : "unknown"); 393} 394 395static struct resource_list * 396dma_get_resource_list(device_t dev, device_t child) 397{ 398 struct dma_devinfo *ddi; 399 400 ddi = device_get_ivars(child); 401 return (&ddi->ddi_rl); 402} 403
|