Home | History | Annotate | Line # | Download | only in isa
isa_machdep.c revision 1.3
      1 /*	$NetBSD: isa_machdep.c,v 1.3 1998/01/12 18:04:19 thorpej 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 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 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 <machine/bus.h>
     48 #include <machine/cpu.h>
     49 #include <machine/iomap.h>
     50 #include <machine/mfp.h>
     51 #include <atari/atari/device.h>
     52 
     53 static int	isabusprint __P((void *auxp, const char *));
     54 static int	isabusmatch __P((struct device *, struct cfdata *, void *));
     55 static void	isabusattach __P((struct device *, struct device *, void *));
     56 
     57 struct cfattach isabus_ca = {
     58 	sizeof(struct device), isabusmatch, isabusattach
     59 };
     60 
     61 int
     62 isabusmatch(pdp, cfp, auxp)
     63 struct device	*pdp;
     64 struct cfdata	*cfp;
     65 void		*auxp;
     66 {
     67 	if(atari_realconfig == 0)
     68 		return (0);
     69 	if (strcmp((char *)auxp, "isabus") || cfp->cf_unit != 0)
     70 		return(0);
     71 	return(machineid & ATARI_HADES ? 1 : 0);
     72 }
     73 
     74 void
     75 isabusattach(pdp, dp, auxp)
     76 struct device	*pdp, *dp;
     77 void		*auxp;
     78 {
     79 	struct isabus_attach_args	iba;
     80 
     81 	iba.iba_busname = "isa";
     82 	iba.iba_iot     = ISA_IOSTART;
     83 	iba.iba_memt    = ISA_MEMSTART;
     84 
     85 	MFP->mf_aer    |= (IO_ISA1|IO_ISA2); /* ISA interrupts: LOW->HIGH */
     86 
     87 	printf("\n");
     88 	config_found(dp, &iba, isabusprint);
     89 }
     90 
     91 int
     92 isabusprint(auxp, name)
     93 void		*auxp;
     94 const char	*name;
     95 {
     96 	if(name == NULL)
     97 		return(UNCONF);
     98 	return(QUIET);
     99 }
    100 
    101 void
    102 isa_attach_hook(parent, self, iba)
    103 	struct device		  *parent, *self;
    104 	struct isabus_attach_args *iba;
    105 {
    106 }
    107 
    108 /*
    109  * The interrupt stuff is rather ugly. On the Hades, all interrupt lines
    110  * for a slot are wired together and connected to either IO3 (slot1) or
    111  * IO7 (slot2). Since no info can be obtained about the slot position
    112  * at isa_intr_establish() time, the following assumption is made:
    113  *   - irq <= 6 -> slot 1
    114  *   - irq >  6 -> slot 2
    115  */
    116 static isa_intr_info_t iinfo[2] = { { -1 }, { -1 } };
    117 
    118 static int	iifun __P((int, int));
    119 
    120 static int
    121 iifun(slot, sr)
    122 int	slot;
    123 int	sr;
    124 {
    125 	isa_intr_info_t *iinfo_p;
    126 	int		s;
    127 
    128 	iinfo_p = &iinfo[slot];
    129 
    130 	/*
    131 	 * Disable the interrupts
    132 	 */
    133 	if (slot == 0)
    134 		MFP->mf_imrb  &= ~(IB_ISA1);
    135 	else MFP->mf_imra &= ~(IA_ISA2);
    136 
    137 
    138 	if ((sr & PSL_IPL) >= iinfo_p->ipl) {
    139 		/*
    140 		 * We're running at a too high priority now.
    141 		 */
    142 		add_sicallback((si_farg)iifun, (void*)slot, 0);
    143 	}
    144 	else {
    145 		s = splx(iinfo_p->ipl);
    146 		(void) (iinfo_p->ifunc)(iinfo_p->iarg, 0);
    147 		splx(s);
    148 
    149 		/*
    150 		 * Re-enable interrupts after handling
    151 		 */
    152 		if (slot == 0)
    153 			MFP->mf_imrb  |= IB_ISA1;
    154 		else MFP->mf_imra |= IA_ISA2;
    155 	}
    156 	return 1;
    157 }
    158 
    159 void *
    160 isa_intr_establish(ic, irq, type, level, ih_fun, ih_arg)
    161 	isa_chipset_tag_t ic;
    162 	int		  irq, type, level;
    163 	hw_ifun_t	  ih_fun;
    164 	void		  *ih_arg;
    165 {
    166 	isa_intr_info_t *iinfo_p;
    167 	struct intrhand	*ihand;
    168 	int		slot;
    169 
    170 	slot    = (irq <= 6) ? 0 : 1;
    171 	iinfo_p = &iinfo[slot];
    172 
    173 	if (iinfo_p->slot > 0)
    174 	    panic("isa_intr_establish: interrupt was already established\n");
    175 
    176 	ihand = intr_establish((slot == 0) ? 3 : 15, USER_VEC, 0,
    177 				(hw_ifun_t)iifun, (void *)slot);
    178 	if (ihand != NULL) {
    179 		iinfo_p->slot  = slot;
    180 		iinfo_p->ipl   = level;
    181 		iinfo_p->ifunc = ih_fun;
    182 		iinfo_p->iarg  = ih_arg;
    183 		iinfo_p->ihand = ihand;
    184 
    185 		/*
    186 		 * Enable (unmask) the interrupt
    187 		 */
    188 		if (slot == 0) {
    189 			MFP->mf_imrb |= IB_ISA1;
    190 			MFP->mf_ierb |= IB_ISA1;
    191 		}
    192 		else {
    193 			MFP->mf_imra |= IA_ISA2;
    194 			MFP->mf_iera |= IA_ISA2;
    195 		}
    196 		return(iinfo_p);
    197 	}
    198 	return NULL;
    199 }
    200 
    201 void
    202 isa_intr_disestablish(ic, handler)
    203 	isa_chipset_tag_t	ic;
    204 	void			*handler;
    205 {
    206 	isa_intr_info_t *iinfo_p = (isa_intr_info_t *)handler;
    207 
    208 	if (iinfo_p->slot < 0)
    209 	    panic("isa_intr_disestablish: interrupt was not established\n");
    210 
    211 	(void) intr_disestablish(iinfo_p->ihand);
    212 	iinfo_p->slot = -1;
    213 }
    214