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 182062 2008-08-23 15:20:33Z 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>
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>
--- 91 unchanged lines hidden (view full) ---
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;
181 int error, burst, children;
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
191 lsc->sc_rid = 0;
192 lsc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &lsc->sc_rid,
193 RF_ACTIVE);
194 if (lsc->sc_res == NULL) {
195 device_printf(dev, "cannot allocate resources\n");
196 return (ENXIO);
197 }
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
--- 33 unchanged lines hidden (view full) ---
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
249 burst = sbus_get_burstsz(dev);
250 lsc->sc_burst = (burst & SBUS_BURST_32) ? 32 :
251 (burst & SBUS_BURST_16) ? 16 : 0;
252 lsc->sc_dev = dev;
253
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. */
261 children = 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;
265 if (children != 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);
279 children++;
280 }
281 return (bus_generic_attach(dev));
282
283 fail_lpdma:
284 bus_dma_tag_destroy(lsc->sc_parent_dmat);
285 fail_lres:
286 bus_release_resource(dev, SYS_RES_MEMORY, lsc->sc_rid, 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;
--- 130 unchanged lines hidden ---
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 182062 2008-08-23 15:20:33Z 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>
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>
--- 91 unchanged lines hidden (view full) ---
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;
181 int error, burst, children;
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
191 lsc->sc_rid = 0;
192 lsc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &lsc->sc_rid,
193 RF_ACTIVE);
194 if (lsc->sc_res == NULL) {
195 device_printf(dev, "cannot allocate resources\n");
196 return (ENXIO);
197 }
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
--- 33 unchanged lines hidden (view full) ---
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
249 burst = sbus_get_burstsz(dev);
250 lsc->sc_burst = (burst & SBUS_BURST_32) ? 32 :
251 (burst & SBUS_BURST_16) ? 16 : 0;
252 lsc->sc_dev = dev;
253
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. */
261 children = 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;
265 if (children != 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);
279 children++;
280 }
281 return (bus_generic_attach(dev));
282
283 fail_lpdma:
284 bus_dma_tag_destroy(lsc->sc_parent_dmat);
285 fail_lres:
286 bus_release_resource(dev, SYS_RES_MEMORY, lsc->sc_rid, 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;
--- 130 unchanged lines hidden ---