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