Home | History | Annotate | Line # | Download | only in tc
ioasic.c revision 1.19
      1  1.19   thorpej /* $NetBSD: ioasic.c,v 1.19 1998/05/27 00:18:13 thorpej Exp $ */
      2  1.17   thorpej 
      3  1.17   thorpej /*-
      4  1.17   thorpej  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
      5  1.17   thorpej  * All rights reserved.
      6  1.17   thorpej  *
      7  1.17   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.17   thorpej  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  1.17   thorpej  * NASA Ames Research Center.
     10  1.17   thorpej  *
     11  1.17   thorpej  * Redistribution and use in source and binary forms, with or without
     12  1.17   thorpej  * modification, are permitted provided that the following conditions
     13  1.17   thorpej  * are met:
     14  1.17   thorpej  * 1. Redistributions of source code must retain the above copyright
     15  1.17   thorpej  *    notice, this list of conditions and the following disclaimer.
     16  1.17   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.17   thorpej  *    notice, this list of conditions and the following disclaimer in the
     18  1.17   thorpej  *    documentation and/or other materials provided with the distribution.
     19  1.17   thorpej  * 3. All advertising materials mentioning features or use of this software
     20  1.17   thorpej  *    must display the following acknowledgement:
     21  1.17   thorpej  *	This product includes software developed by the NetBSD
     22  1.17   thorpej  *	Foundation, Inc. and its contributors.
     23  1.17   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.17   thorpej  *    contributors may be used to endorse or promote products derived
     25  1.17   thorpej  *    from this software without specific prior written permission.
     26  1.17   thorpej  *
     27  1.17   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.17   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.17   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.17   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.17   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.17   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.17   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.17   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.17   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.17   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.17   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     38  1.17   thorpej  */
     39   1.1       cgd 
     40   1.1       cgd /*
     41   1.4       cgd  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
     42   1.1       cgd  * All rights reserved.
     43   1.1       cgd  *
     44   1.1       cgd  * Author: Keith Bostic, Chris G. Demetriou
     45   1.1       cgd  *
     46   1.1       cgd  * Permission to use, copy, modify and distribute this software and
     47   1.1       cgd  * its documentation is hereby granted, provided that both the copyright
     48   1.1       cgd  * notice and this permission notice appear in all copies of the
     49   1.1       cgd  * software, derivative works or modified versions, and any portions
     50   1.1       cgd  * thereof, and that both notices appear in supporting documentation.
     51   1.1       cgd  *
     52   1.1       cgd  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     53   1.1       cgd  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     54   1.1       cgd  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     55   1.1       cgd  *
     56   1.1       cgd  * Carnegie Mellon requests users of this software to return to
     57   1.1       cgd  *
     58   1.1       cgd  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     59   1.1       cgd  *  School of Computer Science
     60   1.1       cgd  *  Carnegie Mellon University
     61   1.1       cgd  *  Pittsburgh PA 15213-3890
     62   1.1       cgd  *
     63   1.1       cgd  * any improvements or extensions that they make and grant Carnegie the
     64   1.1       cgd  * rights to redistribute these changes.
     65   1.1       cgd  */
     66  1.12       cgd 
     67  1.15   thorpej #include "opt_dec_3000_300.h"
     68  1.15   thorpej 
     69  1.13       cgd #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     70  1.13       cgd 
     71  1.19   thorpej __KERNEL_RCSID(0, "$NetBSD: ioasic.c,v 1.19 1998/05/27 00:18:13 thorpej Exp $");
     72   1.1       cgd 
     73   1.1       cgd #include <sys/param.h>
     74   1.1       cgd #include <sys/kernel.h>
     75   1.1       cgd #include <sys/systm.h>
     76   1.1       cgd #include <sys/device.h>
     77   1.1       cgd 
     78   1.1       cgd #include <machine/autoconf.h>
     79  1.17   thorpej #include <machine/bus.h>
     80   1.1       cgd #include <machine/pte.h>
     81   1.1       cgd #include <machine/rpb.h>
     82   1.5       cgd #ifndef EVCNT_COUNTERS
     83   1.5       cgd #include <machine/intrcnt.h>
     84   1.5       cgd #endif
     85   1.1       cgd 
     86   1.1       cgd #include <dev/tc/tcvar.h>
     87   1.1       cgd #include <alpha/tc/ioasicreg.h>
     88   1.1       cgd #include <dev/tc/ioasicvar.h>
     89   1.1       cgd 
     90   1.1       cgd struct ioasic_softc {
     91   1.1       cgd 	struct	device sc_dv;
     92   1.1       cgd 
     93   1.1       cgd 	tc_addr_t sc_base;
     94   1.1       cgd 	void	*sc_cookie;
     95  1.17   thorpej 
     96  1.17   thorpej 	bus_dma_tag_t sc_dmat;
     97  1.17   thorpej 	bus_dmamap_t sc_lance_dmam;
     98   1.1       cgd };
     99   1.1       cgd 
    100   1.1       cgd /* Definition of the driver for autoconfig. */
    101  1.10       cgd int	ioasicmatch __P((struct device *, struct cfdata *, void *));
    102   1.1       cgd void	ioasicattach __P((struct device *, struct device *, void *));
    103   1.7       cgd int     ioasicprint(void *, const char *);
    104   1.2   thorpej 
    105   1.2   thorpej struct cfattach ioasic_ca = {
    106   1.3       cgd 	sizeof(struct ioasic_softc), ioasicmatch, ioasicattach,
    107   1.2   thorpej };
    108   1.1       cgd 
    109   1.1       cgd int	ioasic_intr __P((void *));
    110   1.1       cgd int	ioasic_intrnull __P((void *));
    111   1.1       cgd 
    112   1.1       cgd #define	C(x)	((void *)(x))
    113   1.1       cgd 
    114   1.1       cgd #define	IOASIC_DEV_LANCE	0
    115   1.1       cgd #define	IOASIC_DEV_SCC0		1
    116   1.1       cgd #define	IOASIC_DEV_SCC1		2
    117   1.1       cgd #define	IOASIC_DEV_ISDN		3
    118   1.1       cgd 
    119   1.1       cgd #define	IOASIC_DEV_BOGUS	-1
    120   1.1       cgd 
    121   1.1       cgd #define	IOASIC_NCOOKIES		4
    122   1.1       cgd 
    123   1.1       cgd struct ioasic_dev {
    124   1.1       cgd 	char		*iad_modname;
    125   1.1       cgd 	tc_offset_t	iad_offset;
    126   1.1       cgd 	void		*iad_cookie;
    127   1.1       cgd 	u_int32_t	iad_intrbits;
    128   1.1       cgd } ioasic_devs[] = {
    129   1.3       cgd 	/* XXX lance name */
    130  1.19   thorpej 	{ "lance",    IOASIC_SLOT_3_START, C(IOASIC_DEV_LANCE),
    131  1.19   thorpej 	  IOASIC_INTR_LANCE, },
    132  1.19   thorpej 	{ "z8530   ", IOASIC_SLOT_4_START, C(IOASIC_DEV_SCC0),
    133  1.19   thorpej 	  IOASIC_INTR_SCC_0, },
    134  1.19   thorpej 	{ "z8530   ", IOASIC_SLOT_6_START, C(IOASIC_DEV_SCC1),
    135  1.19   thorpej 	  IOASIC_INTR_SCC_1, },
    136  1.19   thorpej 	{ "TOY_RTC ", IOASIC_SLOT_8_START, C(IOASIC_DEV_BOGUS),
    137  1.19   thorpej 	  0, },
    138  1.19   thorpej 	{ "AMD79c30", IOASIC_SLOT_9_START, C(IOASIC_DEV_ISDN),
    139  1.19   thorpej 	  IOASIC_INTR_ISDN,  },
    140   1.1       cgd };
    141   1.1       cgd int ioasic_ndevs = sizeof(ioasic_devs) / sizeof(ioasic_devs[0]);
    142   1.1       cgd 
    143   1.1       cgd struct ioasicintr {
    144   1.1       cgd 	int	(*iai_func) __P((void *));
    145   1.1       cgd 	void	*iai_arg;
    146   1.1       cgd } ioasicintrs[IOASIC_NCOOKIES];
    147   1.1       cgd 
    148   1.1       cgd tc_addr_t ioasic_base;		/* XXX XXX XXX */
    149   1.1       cgd 
    150   1.1       cgd /* There can be only one. */
    151   1.1       cgd int ioasicfound;
    152   1.1       cgd 
    153   1.1       cgd extern int cputype;
    154   1.1       cgd 
    155  1.17   thorpej /*
    156  1.17   thorpej  * DMA area for IOASIC LANCE.
    157  1.17   thorpej  * XXX Should be done differently, but this is better than it used to be.
    158  1.17   thorpej  */
    159  1.17   thorpej #define	LE_IOASIC_MEMSIZE	(128*1024)
    160  1.17   thorpej #define	LE_IOASIC_MEMALIGN	(128*1024)
    161  1.17   thorpej caddr_t	le_iomem;
    162  1.17   thorpej 
    163  1.17   thorpej void	ioasic_lance_dma_setup __P((struct ioasic_softc *));
    164  1.17   thorpej 
    165   1.1       cgd int
    166   1.1       cgd ioasicmatch(parent, cfdata, aux)
    167   1.1       cgd 	struct device *parent;
    168  1.10       cgd 	struct cfdata *cfdata;
    169   1.1       cgd 	void *aux;
    170   1.1       cgd {
    171   1.3       cgd 	struct tc_attach_args *ta = aux;
    172   1.1       cgd 
    173   1.1       cgd 	/* Make sure that we're looking for this type of device. */
    174   1.3       cgd 	if (strncmp("FLAMG-IO", ta->ta_modname, TC_ROM_LLEN))
    175   1.1       cgd 		return (0);
    176   1.1       cgd 
    177   1.1       cgd 	/* Check that it can actually exist. */
    178   1.1       cgd 	if ((cputype != ST_DEC_3000_500) && (cputype != ST_DEC_3000_300))
    179   1.1       cgd 		panic("ioasicmatch: how did we get here?");
    180   1.1       cgd 
    181   1.1       cgd 	if (ioasicfound)
    182   1.1       cgd 		return (0);
    183   1.1       cgd 
    184   1.1       cgd 	return (1);
    185   1.1       cgd }
    186   1.1       cgd 
    187   1.1       cgd void
    188   1.1       cgd ioasicattach(parent, self, aux)
    189   1.1       cgd 	struct device *parent, *self;
    190   1.1       cgd 	void *aux;
    191   1.1       cgd {
    192   1.1       cgd 	struct ioasic_softc *sc = (struct ioasic_softc *)self;
    193   1.3       cgd 	struct tc_attach_args *ta = aux;
    194   1.1       cgd 	struct ioasicdev_attach_args ioasicdev;
    195   1.1       cgd 	u_long i;
    196   1.1       cgd 
    197   1.1       cgd 	ioasicfound = 1;
    198   1.1       cgd 
    199   1.3       cgd 	sc->sc_base = ta->ta_addr;
    200   1.1       cgd 	ioasic_base = sc->sc_base;			/* XXX XXX XXX */
    201   1.3       cgd 	sc->sc_cookie = ta->ta_cookie;
    202  1.17   thorpej 	sc->sc_dmat = ta->ta_dmat;
    203   1.1       cgd 
    204   1.1       cgd #ifdef DEC_3000_300
    205   1.1       cgd 	if (cputype == ST_DEC_3000_300) {
    206   1.1       cgd 		*(volatile u_int *)IOASIC_REG_CSR(sc->sc_base) |=
    207   1.1       cgd 		    IOASIC_CSR_FASTMODE;
    208   1.1       cgd 		tc_mb();
    209   1.9  christos 		printf(": slow mode\n");
    210   1.1       cgd 	} else
    211   1.1       cgd #endif
    212   1.9  christos 		printf(": fast mode\n");
    213   1.1       cgd 
    214   1.1       cgd 	/*
    215   1.1       cgd 	 * Turn off all device interrupt bits.
    216   1.1       cgd 	 * (This does _not_ include 3000/300 TC option slot bits.
    217   1.1       cgd 	 */
    218   1.1       cgd 	for (i = 0; i < ioasic_ndevs; i++)
    219   1.1       cgd 		*(volatile u_int32_t *)IOASIC_REG_IMSK(ioasic_base) &=
    220   1.1       cgd 			~ioasic_devs[i].iad_intrbits;
    221   1.1       cgd 	tc_mb();
    222   1.1       cgd 
    223   1.1       cgd 	/*
    224   1.1       cgd 	 * Set up interrupt handlers.
    225   1.1       cgd 	 */
    226   1.1       cgd 	for (i = 0; i < IOASIC_NCOOKIES; i++) {
    227   1.1       cgd 		ioasicintrs[i].iai_func = ioasic_intrnull;
    228   1.1       cgd 		ioasicintrs[i].iai_arg = (void *)i;
    229   1.1       cgd 	}
    230   1.1       cgd 	tc_intr_establish(parent, sc->sc_cookie, TC_IPL_NONE, ioasic_intr, sc);
    231   1.1       cgd 
    232  1.17   thorpej 	/*
    233  1.17   thorpej 	 * Set up the LANCE DMA area.
    234  1.17   thorpej 	 */
    235  1.17   thorpej 	ioasic_lance_dma_setup(sc);
    236  1.17   thorpej 
    237   1.1       cgd         /*
    238   1.1       cgd 	 * Try to configure each device.
    239   1.1       cgd 	 */
    240   1.1       cgd         for (i = 0; i < ioasic_ndevs; i++) {
    241   1.1       cgd 		strncpy(ioasicdev.iada_modname, ioasic_devs[i].iad_modname,
    242   1.1       cgd 			TC_ROM_LLEN);
    243   1.1       cgd 		ioasicdev.iada_modname[TC_ROM_LLEN] = '\0';
    244   1.1       cgd 		ioasicdev.iada_offset = ioasic_devs[i].iad_offset;
    245   1.1       cgd 		ioasicdev.iada_addr = sc->sc_base + ioasic_devs[i].iad_offset;
    246   1.1       cgd 		ioasicdev.iada_cookie = ioasic_devs[i].iad_cookie;
    247   1.1       cgd 
    248   1.1       cgd                 /* Tell the autoconfig machinery we've found the hardware. */
    249   1.1       cgd                 config_found(self, &ioasicdev, ioasicprint);
    250   1.1       cgd         }
    251   1.1       cgd }
    252   1.1       cgd 
    253   1.1       cgd int
    254   1.1       cgd ioasicprint(aux, pnp)
    255   1.1       cgd 	void *aux;
    256   1.7       cgd 	const char *pnp;
    257   1.1       cgd {
    258   1.1       cgd 	struct ioasicdev_attach_args *d = aux;
    259   1.1       cgd 
    260   1.1       cgd         if (pnp)
    261   1.9  christos                 printf("%s at %s", d->iada_modname, pnp);
    262   1.9  christos         printf(" offset 0x%lx", (long)d->iada_offset);
    263   1.1       cgd         return (UNCONF);
    264   1.1       cgd }
    265   1.1       cgd 
    266   1.1       cgd int
    267   1.1       cgd ioasic_submatch(match, d)
    268   1.1       cgd 	struct cfdata *match;
    269   1.1       cgd 	struct ioasicdev_attach_args *d;
    270   1.1       cgd {
    271   1.1       cgd 
    272   1.1       cgd 	return ((match->ioasiccf_offset == d->iada_offset) ||
    273   1.1       cgd 		(match->ioasiccf_offset == IOASIC_OFFSET_UNKNOWN));
    274   1.1       cgd }
    275   1.1       cgd 
    276   1.1       cgd void
    277   1.1       cgd ioasic_intr_establish(ioa, cookie, level, func, arg)
    278   1.1       cgd 	struct device *ioa;
    279   1.1       cgd 	void *cookie, *arg;
    280   1.1       cgd 	tc_intrlevel_t level;
    281   1.1       cgd 	int (*func) __P((void *));
    282   1.1       cgd {
    283   1.1       cgd 	u_long dev, i;
    284   1.1       cgd 
    285   1.1       cgd 	dev = (u_long)cookie;
    286   1.1       cgd #ifdef DIAGNOSTIC
    287   1.1       cgd 	/* XXX check cookie. */
    288   1.1       cgd #endif
    289   1.1       cgd 
    290   1.1       cgd 	if (ioasicintrs[dev].iai_func != ioasic_intrnull)
    291   1.1       cgd 		panic("ioasic_intr_establish: cookie %d twice", dev);
    292   1.1       cgd 
    293   1.1       cgd 	ioasicintrs[dev].iai_func = func;
    294   1.1       cgd 	ioasicintrs[dev].iai_arg = arg;
    295   1.1       cgd 
    296   1.1       cgd 	/* Enable interrupts for the device. */
    297   1.1       cgd 	for (i = 0; i < ioasic_ndevs; i++)
    298   1.1       cgd 		if (ioasic_devs[i].iad_cookie == cookie)
    299   1.1       cgd 			break;
    300   1.1       cgd 	if (i == ioasic_ndevs)
    301   1.1       cgd 		panic("ioasic_intr_establish: invalid cookie.");
    302   1.1       cgd 	*(volatile u_int32_t *)IOASIC_REG_IMSK(ioasic_base) |=
    303   1.1       cgd 		ioasic_devs[i].iad_intrbits;
    304   1.1       cgd 	tc_mb();
    305   1.1       cgd }
    306   1.1       cgd 
    307   1.1       cgd void
    308   1.1       cgd ioasic_intr_disestablish(ioa, cookie)
    309   1.1       cgd 	struct device *ioa;
    310   1.1       cgd 	void *cookie;
    311   1.1       cgd {
    312   1.1       cgd 	u_long dev, i;
    313   1.1       cgd 
    314   1.1       cgd 	dev = (u_long)cookie;
    315   1.1       cgd #ifdef DIAGNOSTIC
    316   1.1       cgd 	/* XXX check cookie. */
    317   1.1       cgd #endif
    318   1.1       cgd 
    319   1.1       cgd 	if (ioasicintrs[dev].iai_func == ioasic_intrnull)
    320   1.1       cgd 		panic("ioasic_intr_disestablish: cookie %d missing intr", dev);
    321   1.1       cgd 
    322   1.1       cgd 	/* Enable interrupts for the device. */
    323   1.1       cgd 	for (i = 0; i < ioasic_ndevs; i++)
    324   1.1       cgd 		if (ioasic_devs[i].iad_cookie == cookie)
    325   1.1       cgd 			break;
    326   1.1       cgd 	if (i == ioasic_ndevs)
    327   1.1       cgd 		panic("ioasic_intr_disestablish: invalid cookie.");
    328   1.1       cgd 	*(volatile u_int32_t *)IOASIC_REG_IMSK(ioasic_base) &=
    329   1.1       cgd 		~ioasic_devs[i].iad_intrbits;
    330   1.1       cgd 	tc_mb();
    331   1.1       cgd 
    332   1.1       cgd 	ioasicintrs[dev].iai_func = ioasic_intrnull;
    333   1.1       cgd 	ioasicintrs[dev].iai_arg = (void *)dev;
    334   1.1       cgd }
    335   1.1       cgd 
    336   1.1       cgd int
    337   1.1       cgd ioasic_intrnull(val)
    338   1.1       cgd 	void *val;
    339   1.1       cgd {
    340   1.1       cgd 
    341   1.1       cgd 	panic("ioasic_intrnull: uncaught IOASIC intr for cookie %ld\n",
    342   1.1       cgd 	    (u_long)val);
    343   1.1       cgd }
    344   1.1       cgd 
    345   1.1       cgd /*
    346   1.1       cgd  * asic_intr --
    347   1.1       cgd  *	ASIC interrupt handler.
    348   1.1       cgd  */
    349   1.1       cgd int
    350   1.1       cgd ioasic_intr(val)
    351   1.1       cgd 	void *val;
    352   1.1       cgd {
    353   1.1       cgd 	register struct ioasic_softc *sc = val;
    354   1.6       cgd 	register int ifound;
    355   1.1       cgd 	int gifound;
    356   1.6       cgd 	u_int32_t sir;
    357   1.6       cgd 	volatile u_int32_t *sirp;
    358   1.1       cgd 
    359   1.1       cgd 	sirp = (volatile u_int32_t *)IOASIC_REG_INTR(sc->sc_base);
    360   1.1       cgd 
    361   1.1       cgd 	gifound = 0;
    362   1.1       cgd 	do {
    363   1.1       cgd 		ifound = 0;
    364   1.1       cgd 		tc_syncbus();
    365   1.1       cgd 
    366   1.1       cgd 		sir = *sirp;
    367   1.1       cgd 
    368   1.5       cgd #ifdef EVCNT_COUNTERS
    369   1.5       cgd 	/* No interrupt counting via evcnt counters */
    370   1.5       cgd 	XXX BREAK HERE XXX
    371   1.5       cgd #else /* !EVCNT_COUNTERS */
    372   1.5       cgd #define	INCRINTRCNT(slot)	intrcnt[INTRCNT_IOASIC + slot]++
    373   1.5       cgd #endif /* EVCNT_COUNTERS */
    374   1.5       cgd 
    375   1.1       cgd 		/* XXX DUPLICATION OF INTERRUPT BIT INFORMATION... */
    376   1.1       cgd #define	CHECKINTR(slot, bits)						\
    377   1.1       cgd 		if (sir & bits) {					\
    378   1.1       cgd 			ifound = 1;					\
    379   1.5       cgd 			INCRINTRCNT(slot);				\
    380   1.1       cgd 			(*ioasicintrs[slot].iai_func)			\
    381   1.1       cgd 			    (ioasicintrs[slot].iai_arg);		\
    382   1.1       cgd 		}
    383   1.1       cgd 		CHECKINTR(IOASIC_DEV_SCC0, IOASIC_INTR_SCC_0);
    384   1.1       cgd 		CHECKINTR(IOASIC_DEV_SCC1, IOASIC_INTR_SCC_1);
    385   1.1       cgd 		CHECKINTR(IOASIC_DEV_LANCE, IOASIC_INTR_LANCE);
    386   1.1       cgd 		CHECKINTR(IOASIC_DEV_ISDN, IOASIC_INTR_ISDN);
    387   1.1       cgd 
    388   1.1       cgd 		gifound |= ifound;
    389   1.1       cgd 	} while (ifound);
    390   1.1       cgd 
    391   1.1       cgd 	return (gifound);
    392   1.1       cgd }
    393   1.1       cgd 
    394   1.1       cgd /* XXX */
    395   1.1       cgd char *
    396   1.1       cgd ioasic_lance_ether_address()
    397   1.1       cgd {
    398   1.1       cgd 
    399   1.1       cgd 	return (u_char *)IOASIC_SYS_ETHER_ADDRESS(ioasic_base);
    400   1.1       cgd }
    401   1.1       cgd 
    402   1.1       cgd void
    403  1.17   thorpej ioasic_lance_dma_setup(sc)
    404  1.17   thorpej 	struct ioasic_softc *sc;
    405   1.1       cgd {
    406  1.17   thorpej 	bus_dma_tag_t dmat = sc->sc_dmat;
    407  1.17   thorpej 	bus_dma_segment_t seg;
    408   1.1       cgd 	volatile u_int32_t *ldp;
    409   1.1       cgd 	tc_addr_t tca;
    410  1.17   thorpej 	int rseg;
    411   1.1       cgd 
    412  1.17   thorpej 	/*
    413  1.17   thorpej 	 * Allocate a DMA area for the chip.
    414  1.17   thorpej 	 */
    415  1.17   thorpej 	if (bus_dmamem_alloc(dmat, LE_IOASIC_MEMSIZE, LE_IOASIC_MEMALIGN,
    416  1.17   thorpej 	    0, &seg, 1, &rseg, BUS_DMA_NOWAIT)) {
    417  1.17   thorpej 		printf("%s: can't allocate DMA area for LANCE\n",
    418  1.17   thorpej 		    sc->sc_dv.dv_xname);
    419  1.17   thorpej 		return;
    420  1.17   thorpej 	}
    421  1.17   thorpej 	if (bus_dmamem_map(dmat, &seg, rseg, LE_IOASIC_MEMSIZE,
    422  1.18   thorpej 	    &le_iomem, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
    423  1.17   thorpej 		printf("%s: can't map DMA area for LANCE\n",
    424  1.17   thorpej 		    sc->sc_dv.dv_xname);
    425  1.17   thorpej 		bus_dmamem_free(dmat, &seg, rseg);
    426  1.17   thorpej 		return;
    427  1.17   thorpej 	}
    428  1.17   thorpej 
    429  1.17   thorpej 	/*
    430  1.17   thorpej 	 * Create and load the DMA map for the DMA area.
    431  1.17   thorpej 	 */
    432  1.17   thorpej 	if (bus_dmamap_create(dmat, LE_IOASIC_MEMSIZE, 1,
    433  1.17   thorpej 	    LE_IOASIC_MEMSIZE, 0, BUS_DMA_NOWAIT, &sc->sc_lance_dmam)) {
    434  1.17   thorpej 		printf("%s: can't create DMA map\n", sc->sc_dv.dv_xname);
    435  1.17   thorpej 		goto bad;
    436  1.17   thorpej 	}
    437  1.17   thorpej 	if (bus_dmamap_load(dmat, sc->sc_lance_dmam,
    438  1.17   thorpej 	    le_iomem, LE_IOASIC_MEMSIZE, NULL, BUS_DMA_NOWAIT)) {
    439  1.17   thorpej 		printf("%s: can't load DMA map\n", sc->sc_dv.dv_xname);
    440  1.17   thorpej 		goto bad;
    441  1.17   thorpej 	}
    442  1.17   thorpej 
    443  1.17   thorpej 	tca = (tc_addr_t)sc->sc_lance_dmam->dm_segs[0].ds_addr;
    444  1.17   thorpej 	if (tca != sc->sc_lance_dmam->dm_segs[0].ds_addr) {
    445  1.17   thorpej 		printf("%s: bad LANCE DMA address\n", sc->sc_dv.dv_xname);
    446  1.17   thorpej 		bus_dmamap_unload(dmat, sc->sc_lance_dmam);
    447  1.17   thorpej 		goto bad;
    448  1.17   thorpej 	}
    449   1.1       cgd 
    450   1.1       cgd 	ldp = (volatile u_int *)IOASIC_REG_LANCE_DMAPTR(ioasic_base);
    451   1.1       cgd 	*ldp = ((tca << 3) & ~(tc_addr_t)0x1f) | ((tca >> 29) & 0x1f);
    452   1.1       cgd 	tc_wmb();
    453   1.1       cgd 
    454   1.1       cgd 	*(volatile u_int32_t *)IOASIC_REG_CSR(ioasic_base) |=
    455   1.1       cgd 	    IOASIC_CSR_DMAEN_LANCE;
    456   1.1       cgd 	tc_mb();
    457  1.17   thorpej 	return;
    458  1.17   thorpej 
    459  1.17   thorpej  bad:
    460  1.17   thorpej 	bus_dmamem_unmap(dmat, le_iomem, LE_IOASIC_MEMSIZE);
    461  1.17   thorpej 	bus_dmamem_free(dmat, &seg, rseg);
    462  1.17   thorpej 	le_iomem = 0;
    463   1.1       cgd }
    464