Home | History | Annotate | Line # | Download | only in isa
isa_machdep.c revision 1.1
      1  1.1  leo /*	$NetBSD: isa_machdep.c,v 1.1 1997/07/15 08:17:39 leo Exp $	*/
      2  1.1  leo 
      3  1.1  leo /*
      4  1.1  leo  * Copyright (c) 1997 Leo Weppelman.  All rights reserved.
      5  1.1  leo  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
      6  1.1  leo  * Copyright (c) 1994 Charles Hannum.  All rights reserved.
      7  1.1  leo  *
      8  1.1  leo  * Redistribution and use in source and binary forms, with or without
      9  1.1  leo  * modification, are permitted provided that the following conditions
     10  1.1  leo  * are met:
     11  1.1  leo  * 1. Redistributions of source code must retain the above copyright
     12  1.1  leo  *    notice, this list of conditions and the following disclaimer.
     13  1.1  leo  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1  leo  *    notice, this list of conditions and the following disclaimer in the
     15  1.1  leo  *    documentation and/or other materials provided with the distribution.
     16  1.1  leo  * 3. All advertising materials mentioning features or use of this software
     17  1.1  leo  *    must display the following acknowledgement:
     18  1.1  leo  *	This product includes software developed by Charles Hannum.
     19  1.1  leo  * 4. The name of the author may not be used to endorse or promote products
     20  1.1  leo  *    derived from this software without specific prior written permission.
     21  1.1  leo  *
     22  1.1  leo  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.1  leo  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.1  leo  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.1  leo  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.1  leo  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  1.1  leo  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  1.1  leo  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  1.1  leo  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  1.1  leo  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  1.1  leo  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.1  leo  */
     33  1.1  leo 
     34  1.1  leo #include <sys/types.h>
     35  1.1  leo #include <sys/param.h>
     36  1.1  leo #include <sys/time.h>
     37  1.1  leo #include <sys/systm.h>
     38  1.1  leo #include <sys/errno.h>
     39  1.1  leo #include <sys/device.h>
     40  1.1  leo 
     41  1.1  leo #include <vm/vm.h>
     42  1.1  leo #include <vm/vm_kern.h>
     43  1.1  leo 
     44  1.1  leo #include <dev/isa/isavar.h>
     45  1.1  leo #include <dev/isa/isareg.h>
     46  1.1  leo 
     47  1.1  leo #include <machine/bus.h>
     48  1.1  leo #include <machine/cpu.h>
     49  1.1  leo #include <machine/iomap.h>
     50  1.1  leo #include <machine/mfp.h>
     51  1.1  leo #include <atari/atari/device.h>
     52  1.1  leo 
     53  1.1  leo static int	isabusprint __P((void *auxp, const char *));
     54  1.1  leo static int	isabusmatch __P((struct device *, struct cfdata *, void *));
     55  1.1  leo static void	isabusattach __P((struct device *, struct device *, void *));
     56  1.1  leo 
     57  1.1  leo struct cfattach isabus_ca = {
     58  1.1  leo 	sizeof(struct device), isabusmatch, isabusattach
     59  1.1  leo };
     60  1.1  leo 
     61  1.1  leo struct cfdriver isabus_cd = {
     62  1.1  leo 	NULL, "isabus", DV_DULL
     63  1.1  leo };
     64  1.1  leo 
     65  1.1  leo int
     66  1.1  leo isabusmatch(pdp, cfp, auxp)
     67  1.1  leo struct device	*pdp;
     68  1.1  leo struct cfdata	*cfp;
     69  1.1  leo void		*auxp;
     70  1.1  leo {
     71  1.1  leo 	if(atari_realconfig == 0)
     72  1.1  leo 		return (0);
     73  1.1  leo 	if (strcmp((char *)auxp, "isabus") || cfp->cf_unit != 0)
     74  1.1  leo 		return(0);
     75  1.1  leo 	return(machineid & ATARI_HADES ? 1 : 0);
     76  1.1  leo }
     77  1.1  leo 
     78  1.1  leo void
     79  1.1  leo isabusattach(pdp, dp, auxp)
     80  1.1  leo struct device	*pdp, *dp;
     81  1.1  leo void		*auxp;
     82  1.1  leo {
     83  1.1  leo 	struct isabus_attach_args	iba;
     84  1.1  leo 
     85  1.1  leo 	iba.iba_busname = "isa";
     86  1.1  leo 	iba.iba_iot     = ISA_IOSTART;
     87  1.1  leo 	iba.iba_memt    = ISA_MEMSTART;
     88  1.1  leo 
     89  1.1  leo 	MFP->mf_aer    |= (IO_ISA1|IO_ISA2); /* ISA interrupts: LOW->HIGH */
     90  1.1  leo 
     91  1.1  leo 	printf("\n");
     92  1.1  leo 	config_found(dp, &iba, isabusprint);
     93  1.1  leo }
     94  1.1  leo 
     95  1.1  leo int
     96  1.1  leo isabusprint(auxp, name)
     97  1.1  leo void		*auxp;
     98  1.1  leo const char	*name;
     99  1.1  leo {
    100  1.1  leo 	if(name == NULL)
    101  1.1  leo 		return(UNCONF);
    102  1.1  leo 	return(QUIET);
    103  1.1  leo }
    104  1.1  leo 
    105  1.1  leo void
    106  1.1  leo isa_attach_hook(parent, self, iba)
    107  1.1  leo 	struct device		  *parent, *self;
    108  1.1  leo 	struct isabus_attach_args *iba;
    109  1.1  leo {
    110  1.1  leo }
    111  1.1  leo 
    112  1.1  leo /*
    113  1.1  leo  * The interrupt stuff is rather ugly. On the Hades, all interrupt lines
    114  1.1  leo  * for a slot are wired together and connected to either IO3 (slot1) or
    115  1.1  leo  * IO7 (slot2). Since no info can be obtained about the slot position
    116  1.1  leo  * at isa_intr_establish() time, the following assumption is made:
    117  1.1  leo  *   - irq <= 6 -> slot 1
    118  1.1  leo  *   - irq >  6 -> slot 2
    119  1.1  leo  */
    120  1.1  leo static isa_intr_info_t iinfo[2] = { { -1 }, { -1 } };
    121  1.1  leo 
    122  1.1  leo static int	iifun __P((int, int));
    123  1.1  leo 
    124  1.1  leo static int
    125  1.1  leo iifun(slot, sr)
    126  1.1  leo int	slot;
    127  1.1  leo int	sr;
    128  1.1  leo {
    129  1.1  leo 	isa_intr_info_t *iinfo_p;
    130  1.1  leo 	int		s;
    131  1.1  leo 
    132  1.1  leo 	iinfo_p = &iinfo[slot];
    133  1.1  leo 
    134  1.1  leo 	/*
    135  1.1  leo 	 * Disable the interrupts
    136  1.1  leo 	 */
    137  1.1  leo 	if (slot == 1)
    138  1.1  leo 		MFP->mf_imrb  &= ~(IB_ISA1);
    139  1.1  leo 	else MFP->mf_imra &= ~(IA_ISA2);
    140  1.1  leo 
    141  1.1  leo 
    142  1.1  leo 	if ((sr & PSL_IPL) >= iinfo_p->ipl) {
    143  1.1  leo 		/*
    144  1.1  leo 		 * We're running at a too high priority now.
    145  1.1  leo 		 */
    146  1.1  leo 		add_sicallback((si_farg)iifun, (void*)slot, 0);
    147  1.1  leo 	}
    148  1.1  leo 	else {
    149  1.1  leo 		s = splx(iinfo_p->ipl);
    150  1.1  leo 		(void) (iinfo_p->ifunc)(iinfo_p->iarg, 0);
    151  1.1  leo 		splx(s);
    152  1.1  leo 
    153  1.1  leo 		/*
    154  1.1  leo 		 * Re-enable interrupts after handling
    155  1.1  leo 		 */
    156  1.1  leo 		if (slot == 1)
    157  1.1  leo 			MFP->mf_imrb  |= IB_ISA1;
    158  1.1  leo 		else MFP->mf_imra |= IA_ISA2;
    159  1.1  leo 	}
    160  1.1  leo 	return 1;
    161  1.1  leo }
    162  1.1  leo 
    163  1.1  leo void *
    164  1.1  leo isa_intr_establish(ic, irq, type, level, ih_fun, ih_arg)
    165  1.1  leo 	isa_chipset_tag_t ic;
    166  1.1  leo 	int		  irq, type, level;
    167  1.1  leo 	hw_ifun_t	  ih_fun;
    168  1.1  leo 	void		  *ih_arg;
    169  1.1  leo {
    170  1.1  leo 	isa_intr_info_t *iinfo_p;
    171  1.1  leo 	struct intrhand	*ihand;
    172  1.1  leo 	int		slot;
    173  1.1  leo 
    174  1.1  leo printf("isa_intr_est: irq:%d, type:%d, level:%d\n",irq,type,level);
    175  1.1  leo 	slot    = (irq <= 6) ? 1 : 2;
    176  1.1  leo 	iinfo_p = &iinfo[slot];
    177  1.1  leo 
    178  1.1  leo 	if (iinfo_p->slot > 0)
    179  1.1  leo 	    panic("isa_intr_establish: interrupt was already established\n");
    180  1.1  leo 
    181  1.1  leo 	ihand = intr_establish((slot == 1) ? 3 : 15, USER_VEC, 0,
    182  1.1  leo 				(hw_ifun_t)iifun, (void *)slot);
    183  1.1  leo 	if (ihand != NULL) {
    184  1.1  leo 		iinfo_p->slot  = slot;
    185  1.1  leo 		iinfo_p->ipl   = level;
    186  1.1  leo 		iinfo_p->ifunc = ih_fun;
    187  1.1  leo 		iinfo_p->iarg  = ih_arg;
    188  1.1  leo 		iinfo_p->ihand = ihand;
    189  1.1  leo 
    190  1.1  leo 		/*
    191  1.1  leo 		 * Enable (unmask) the interrupt
    192  1.1  leo 		 */
    193  1.1  leo 		if (slot == 1) {
    194  1.1  leo 			MFP->mf_imrb |= IB_ISA1;
    195  1.1  leo 			MFP->mf_ierb |= IB_ISA1;
    196  1.1  leo 		}
    197  1.1  leo 		else {
    198  1.1  leo 			MFP->mf_imra |= IA_ISA2;
    199  1.1  leo 			MFP->mf_iera |= IA_ISA2;
    200  1.1  leo 		}
    201  1.1  leo 		return(iinfo_p);
    202  1.1  leo 	}
    203  1.1  leo 	return NULL;
    204  1.1  leo }
    205  1.1  leo 
    206  1.1  leo void
    207  1.1  leo isa_intr_disestablish(ic, handler)
    208  1.1  leo 	isa_chipset_tag_t	ic;
    209  1.1  leo 	void			*handler;
    210  1.1  leo {
    211  1.1  leo 	isa_intr_info_t *iinfo_p = (isa_intr_info_t *)handler;
    212  1.1  leo 
    213  1.1  leo 	if (iinfo_p->slot < 0)
    214  1.1  leo 	    panic("isa_intr_disestablish: interrupt was not established\n");
    215  1.1  leo 
    216  1.1  leo 	(void) intr_disestablish(iinfo_p->ihand);
    217  1.1  leo 	iinfo_p->slot = -1;
    218  1.1  leo }
    219