Home | History | Annotate | Line # | Download | only in isa
isa_machdep.c revision 1.16.2.1
      1 /*	$NetBSD: isa_machdep.c,v 1.16.2.1 2000/06/22 16:59:39 minoura Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997 Leo Weppelman.  All rights reserved.
      5  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
      6  * Copyright (c) 1994 Charles M. Hannum.  All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *	This product includes software developed by Charles M. Hannum.
     19  * 4. The name of the author may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 
     34 #include <sys/types.h>
     35 #include <sys/param.h>
     36 #include <sys/time.h>
     37 #include <sys/systm.h>
     38 #include <sys/errno.h>
     39 #include <sys/device.h>
     40 
     41 #include <vm/vm.h>
     42 #include <vm/vm_kern.h>
     43 
     44 #include <dev/isa/isavar.h>
     45 #include <dev/isa/isareg.h>
     46 
     47 #include <m68k/asm_single.h>
     48 
     49 #include <machine/bus.h>
     50 #include <machine/cpu.h>
     51 #include <machine/iomap.h>
     52 #include <machine/mfp.h>
     53 #include <atari/atari/device.h>
     54 
     55 static int	isabusprint __P((void *auxp, const char *));
     56 static int	isabusmatch __P((struct device *, struct cfdata *, void *));
     57 static void	isabusattach __P((struct device *, struct device *, void *));
     58 
     59 struct isabus_softc {
     60 	struct device sc_dev;
     61 	struct atari_isa_chipset sc_chipset;
     62 };
     63 
     64 struct cfattach isabus_ca = {
     65 	sizeof(struct isabus_softc), isabusmatch, isabusattach
     66 };
     67 
     68 int
     69 isabusmatch(pdp, cfp, auxp)
     70 struct device	*pdp;
     71 struct cfdata	*cfp;
     72 void		*auxp;
     73 {
     74 	if(atari_realconfig == 0)
     75 		return (0);
     76 	if (strcmp((char *)auxp, "isabus") || cfp->cf_unit != 0)
     77 		return(0);
     78 	return(machineid & ATARI_HADES ? 1 : 0);
     79 }
     80 
     81 void
     82 isabusattach(pdp, dp, auxp)
     83 struct device	*pdp, *dp;
     84 void		*auxp;
     85 {
     86 	struct isabus_softc *sc = (struct isabus_softc *)dp;
     87 	struct isabus_attach_args	iba;
     88 
     89 	iba.iba_busname = "isa";
     90 	iba.iba_dmat	= BUS_ISA_DMA_TAG;
     91 	iba.iba_iot     = leb_alloc_bus_space_tag(NULL);
     92 	iba.iba_memt    = leb_alloc_bus_space_tag(NULL);
     93 	iba.iba_ic	= &sc->sc_chipset;
     94 	if ((iba.iba_iot == NULL) || (iba.iba_memt == NULL)) {
     95 		printf("leb_alloc_bus_space_tag failed!\n");
     96 		return;
     97 	}
     98 	iba.iba_iot->base  = ISA_IOSTART;
     99 	iba.iba_memt->base = ISA_MEMSTART;
    100 
    101 	MFP->mf_aer |= (IO_ISA1|IO_ISA2); /* ISA interrupts: LOW->HIGH */
    102 
    103 	printf("\n");
    104 	config_found(dp, &iba, isabusprint);
    105 }
    106 
    107 int
    108 isabusprint(auxp, name)
    109 void		*auxp;
    110 const char	*name;
    111 {
    112 	if(name == NULL)
    113 		return(UNCONF);
    114 	return(QUIET);
    115 }
    116 
    117 void
    118 isa_attach_hook(parent, self, iba)
    119 	struct device		  *parent, *self;
    120 	struct isabus_attach_args *iba;
    121 {
    122 }
    123 
    124 /*
    125  * The interrupt stuff is rather ugly. On the Hades, all interrupt lines
    126  * for a slot are wired together and connected to either IO3 (slot1) or
    127  * IO7 (slot2). Since no info can be obtained about the slot position
    128  * at isa_intr_establish() time, the following assumption is made:
    129  *   - irq <= 6 -> slot 1
    130  *   - irq >  6 -> slot 2
    131  */
    132 
    133 #define	SLOTNR(irq)	((irq <= 6) ? 0 : 1)
    134 
    135 static isa_intr_info_t iinfo[2] = { { -1 }, { -1 } };
    136 
    137 static int	iifun __P((int, int));
    138 
    139 static int
    140 iifun(slot, sr)
    141 int	slot;
    142 int	sr;
    143 {
    144 	isa_intr_info_t *iinfo_p;
    145 	int		s;
    146 
    147 	iinfo_p = &iinfo[slot];
    148 
    149 	/*
    150 	 * Disable the interrupts
    151 	 */
    152 	if (slot == 0) {
    153 		single_inst_bclr_b(MFP->mf_imrb, IB_ISA1);
    154 	}
    155 	else {
    156 		single_inst_bclr_b(MFP->mf_imra, IA_ISA2);
    157 	}
    158 
    159 	if ((sr & PSL_IPL) >= (iinfo_p->ipl & PSL_IPL)) {
    160 		/*
    161 		 * We're running at a too high priority now.
    162 		 */
    163 		add_sicallback((si_farg)iifun, (void*)slot, 0);
    164 	}
    165 	else {
    166 		s = splx(iinfo_p->ipl);
    167 		if (slot == 0) {
    168 			do {
    169 				MFP->mf_iprb = (u_int8_t)~IB_ISA1;
    170 				(void) (iinfo_p->ifunc)(iinfo_p->iarg);
    171 			} while (MFP->mf_iprb & IB_ISA1);
    172 			single_inst_bset_b(MFP->mf_imrb, IB_ISA1);
    173 		}
    174 		else {
    175 			do {
    176 				MFP->mf_ipra = (u_int8_t)~IA_ISA2;
    177 				(void) (iinfo_p->ifunc)(iinfo_p->iarg);
    178 			} while (MFP->mf_ipra & IA_ISA2);
    179 			single_inst_bset_b(MFP->mf_imra, IA_ISA2);
    180 		}
    181 		splx(s);
    182 	}
    183 	return 1;
    184 }
    185 
    186 
    187 /*
    188  * XXXX
    189  * XXXX Note that this function is not really working yet! The big problem is
    190  * XXXX to only generate interrupts for the slot the card is in...
    191  */
    192 int
    193 isa_intr_alloc(ic, mask, type, irq)
    194 	isa_chipset_tag_t ic;
    195 	int mask;
    196 	int type;
    197 	int *irq;
    198 {
    199 	isa_intr_info_t *iinfo_p;
    200 	int		slot, i;
    201 
    202 
    203 	/*
    204 	 * The Hades only supports edge triggered interrupts!
    205 	 */
    206 	if (type != IST_EDGE)
    207 		return 1;
    208 
    209 #define	MAXIRQ		10	/* XXX: Pure fiction	*/
    210 	for (i = 0; i < MAXIRQ; i++) {
    211 		if (mask & (1<<i)) {
    212 		    slot    = SLOTNR(i);
    213 		    iinfo_p = &iinfo[slot];
    214 
    215 		    if (iinfo_p->slot < 0) {
    216 			*irq = i;
    217 			printf("WARNING: isa_intr_alloc is not yet ready!\n"
    218 			       "         make sure the card is in slot %d!\n",
    219 				slot);
    220 			return 0;
    221 		    }
    222 		}
    223 	}
    224 	return (1);
    225 }
    226 
    227 const struct evcnt *
    228 isa_intr_evcnt(isa_chipset_tag_t ic, int irq)
    229 {
    230 
    231 	/* XXX for now, no evcnt parent reported */
    232 	return NULL;
    233 }
    234 
    235 void *
    236 isa_intr_establish(ic, irq, type, level, ih_fun, ih_arg)
    237 	isa_chipset_tag_t ic;
    238 	int		  irq, type, level;
    239 	int		  (*ih_fun) __P((void *));
    240 	void		  *ih_arg;
    241 {
    242 	isa_intr_info_t *iinfo_p;
    243 	struct intrhand	*ihand;
    244 	int		slot;
    245 
    246 	/*
    247 	 * The Hades only supports edge triggered interrupts!
    248 	 */
    249 	if (type != IST_EDGE)
    250 		return NULL;
    251 
    252 	slot    = SLOTNR(irq);
    253 	iinfo_p = &iinfo[slot];
    254 
    255 	if (iinfo_p->slot >= 0)
    256 	    panic("isa_intr_establish: interrupt was already established\n");
    257 
    258 	ihand = intr_establish((slot == 0) ? 3 : 15, USER_VEC, 0,
    259 				(hw_ifun_t)iifun, (void *)slot);
    260 	if (ihand != NULL) {
    261 		iinfo_p->slot  = slot;
    262 		iinfo_p->ipl   = level;
    263 		iinfo_p->ifunc = ih_fun;
    264 		iinfo_p->iarg  = ih_arg;
    265 		iinfo_p->ihand = ihand;
    266 
    267 		/*
    268 		 * Enable (unmask) the interrupt
    269 		 */
    270 		if (slot == 0) {
    271 			single_inst_bset_b(MFP->mf_imrb, IB_ISA1);
    272 			single_inst_bset_b(MFP->mf_ierb, IB_ISA1);
    273 		}
    274 		else {
    275 			single_inst_bset_b(MFP->mf_imra, IA_ISA2);
    276 			single_inst_bset_b(MFP->mf_iera, IA_ISA2);
    277 		}
    278 		return(iinfo_p);
    279 	}
    280 	return NULL;
    281 }
    282 
    283 void
    284 isa_intr_disestablish(ic, handler)
    285 	isa_chipset_tag_t	ic;
    286 	void			*handler;
    287 {
    288 	isa_intr_info_t *iinfo_p = (isa_intr_info_t *)handler;
    289 
    290 	if (iinfo_p->slot < 0)
    291 	    panic("isa_intr_disestablish: interrupt was not established\n");
    292 
    293 	(void) intr_disestablish(iinfo_p->ihand);
    294 	iinfo_p->slot = -1;
    295 }
    296