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 --- 49 unchanged lines hidden (view full) --- 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 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> |
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> --- 91 unchanged lines hidden (view full) --- 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, i; |
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 i = 0; 191 lsc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &i, |
192 RF_ACTIVE); 193 if (lsc->sc_res == NULL) { 194 device_printf(dev, "cannot allocate resources\n"); 195 return (ENXIO); 196 } |
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 --- 33 unchanged lines hidden (view full) --- 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 |
246 i = sbus_get_burstsz(dev); 247 lsc->sc_burst = (i & SBUS_BURST_32) ? 32 : 248 (i & SBUS_BURST_16) ? 16 : 0; |
249 lsc->sc_dev = dev; 250 |
251 /* Attach children. */ |
252 i = 0; |
253 for (child = OF_child(node); child != 0; child = OF_peer(child)) { 254 if ((ddi = dma_setup_dinfo(dev, dsc, child)) == NULL) 255 continue; |
256 if (i != 0) { |
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); |
270 i++; |
271 } 272 return (bus_generic_attach(dev)); 273 |
274 fail_lres: |
275 bus_release_resource(dev, SYS_RES_MEMORY, rman_get_rid(lsc->sc_res), 276 lsc->sc_res); |
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; --- 130 unchanged lines hidden --- |