Home | History | Annotate | Line # | Download | only in isa
isa_hades.c revision 1.2
      1  1.2  provos /*	$NetBSD: isa_hades.c,v 1.2 2002/09/27 15:35:53 provos Exp $	*/
      2  1.1     leo 
      3  1.1     leo /*-
      4  1.1     leo  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  1.1     leo  * All rights reserved.
      6  1.1     leo  *
      7  1.1     leo  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1     leo  * by Leo Weppelman.
      9  1.1     leo  *
     10  1.1     leo  * Redistribution and use in source and binary forms, with or without
     11  1.1     leo  * modification, are permitted provided that the following conditions
     12  1.1     leo  * are met:
     13  1.1     leo  * 1. Redistributions of source code must retain the above copyright
     14  1.1     leo  *    notice, this list of conditions and the following disclaimer.
     15  1.1     leo  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1     leo  *    notice, this list of conditions and the following disclaimer in the
     17  1.1     leo  *    documentation and/or other materials provided with the distribution.
     18  1.1     leo  * 3. All advertising materials mentioning features or use of this software
     19  1.1     leo  *    must display the following acknowledgement:
     20  1.1     leo  *	This product includes software developed by the NetBSD
     21  1.1     leo  *	Foundation, Inc. and its contributors.
     22  1.1     leo  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1     leo  *    contributors may be used to endorse or promote products derived
     24  1.1     leo  *    from this software without specific prior written permission.
     25  1.1     leo  *
     26  1.1     leo  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1     leo  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1     leo  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1     leo  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1     leo  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1     leo  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1     leo  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1     leo  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1     leo  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1     leo  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1     leo  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1     leo  */
     38  1.1     leo 
     39  1.1     leo #include <sys/types.h>
     40  1.1     leo #include <sys/param.h>
     41  1.1     leo #include <sys/systm.h>
     42  1.1     leo #include <sys/device.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 <m68k/asm_single.h>
     48  1.1     leo 
     49  1.1     leo #include <machine/iomap.h>
     50  1.1     leo #include <machine/mfp.h>
     51  1.1     leo 
     52  1.1     leo void	isa_bus_init(void);
     53  1.1     leo 
     54  1.1     leo void
     55  1.1     leo isa_bus_init()
     56  1.1     leo {
     57  1.1     leo }
     58  1.1     leo 
     59  1.1     leo /*
     60  1.1     leo  * The interrupt stuff is rather ugly. On the Hades, all interrupt lines
     61  1.1     leo  * for a slot are wired together and connected to either IO3 (slot1) or
     62  1.1     leo  * IO7 (slot2). Since no info can be obtained about the slot position
     63  1.1     leo  * at isa_intr_establish() time, the following assumption is made:
     64  1.1     leo  *   - irq <= 6 -> slot 1
     65  1.1     leo  *   - irq >  6 -> slot 2
     66  1.1     leo  */
     67  1.1     leo 
     68  1.1     leo #define	SLOTNR(irq)	((irq <= 6) ? 0 : 1)
     69  1.1     leo 
     70  1.1     leo static isa_intr_info_t iinfo[2] = { { -1 }, { -1 } };
     71  1.1     leo 
     72  1.1     leo static int	iifun __P((int, int));
     73  1.1     leo 
     74  1.1     leo static int
     75  1.1     leo iifun(slot, sr)
     76  1.1     leo int	slot;
     77  1.1     leo int	sr;
     78  1.1     leo {
     79  1.1     leo 	isa_intr_info_t *iinfo_p;
     80  1.1     leo 	int		s;
     81  1.1     leo 
     82  1.1     leo 	iinfo_p = &iinfo[slot];
     83  1.1     leo 
     84  1.1     leo 	/*
     85  1.1     leo 	 * Disable the interrupts
     86  1.1     leo 	 */
     87  1.1     leo 	if (slot == 0) {
     88  1.1     leo 		single_inst_bclr_b(MFP->mf_imrb, IB_ISA1);
     89  1.1     leo 	}
     90  1.1     leo 	else {
     91  1.1     leo 		single_inst_bclr_b(MFP->mf_imra, IA_ISA2);
     92  1.1     leo 	}
     93  1.1     leo 
     94  1.1     leo 	if ((sr & PSL_IPL) >= (iinfo_p->ipl & PSL_IPL)) {
     95  1.1     leo 		/*
     96  1.1     leo 		 * We're running at a too high priority now.
     97  1.1     leo 		 */
     98  1.1     leo 		add_sicallback((si_farg)iifun, (void*)slot, 0);
     99  1.1     leo 	}
    100  1.1     leo 	else {
    101  1.1     leo 		s = splx(iinfo_p->ipl);
    102  1.1     leo 		if (slot == 0) {
    103  1.1     leo 			do {
    104  1.1     leo 				MFP->mf_iprb = (u_int8_t)~IB_ISA1;
    105  1.1     leo 				(void) (iinfo_p->ifunc)(iinfo_p->iarg);
    106  1.1     leo 			} while (MFP->mf_iprb & IB_ISA1);
    107  1.1     leo 			single_inst_bset_b(MFP->mf_imrb, IB_ISA1);
    108  1.1     leo 		}
    109  1.1     leo 		else {
    110  1.1     leo 			do {
    111  1.1     leo 				MFP->mf_ipra = (u_int8_t)~IA_ISA2;
    112  1.1     leo 				(void) (iinfo_p->ifunc)(iinfo_p->iarg);
    113  1.1     leo 			} while (MFP->mf_ipra & IA_ISA2);
    114  1.1     leo 			single_inst_bset_b(MFP->mf_imra, IA_ISA2);
    115  1.1     leo 		}
    116  1.1     leo 		splx(s);
    117  1.1     leo 	}
    118  1.1     leo 	return 1;
    119  1.1     leo }
    120  1.1     leo 
    121  1.1     leo 
    122  1.1     leo /*
    123  1.1     leo  * XXXX
    124  1.1     leo  * XXXX Note that this function is not really working yet! The big problem is
    125  1.1     leo  * XXXX to only generate interrupts for the slot the card is in...
    126  1.1     leo  */
    127  1.1     leo int
    128  1.1     leo isa_intr_alloc(ic, mask, type, irq)
    129  1.1     leo 	isa_chipset_tag_t ic;
    130  1.1     leo 	int mask;
    131  1.1     leo 	int type;
    132  1.1     leo 	int *irq;
    133  1.1     leo {
    134  1.1     leo 	isa_intr_info_t *iinfo_p;
    135  1.1     leo 	int		slot, i;
    136  1.1     leo 
    137  1.1     leo 
    138  1.1     leo 	/*
    139  1.1     leo 	 * The Hades only supports edge triggered interrupts!
    140  1.1     leo 	 */
    141  1.1     leo 	if (type != IST_EDGE)
    142  1.1     leo 		return 1;
    143  1.1     leo 
    144  1.1     leo #define	MAXIRQ		10	/* XXX: Pure fiction	*/
    145  1.1     leo 	for (i = 0; i < MAXIRQ; i++) {
    146  1.1     leo 		if (mask & (1<<i)) {
    147  1.1     leo 		    slot    = SLOTNR(i);
    148  1.1     leo 		    iinfo_p = &iinfo[slot];
    149  1.1     leo 
    150  1.1     leo 		    if (iinfo_p->slot < 0) {
    151  1.1     leo 			*irq = i;
    152  1.1     leo 			printf("WARNING: isa_intr_alloc is not yet ready!\n"
    153  1.1     leo 			       "         make sure the card is in slot %d!\n",
    154  1.1     leo 				slot);
    155  1.1     leo 			return 0;
    156  1.1     leo 		    }
    157  1.1     leo 		}
    158  1.1     leo 	}
    159  1.1     leo 	return (1);
    160  1.1     leo }
    161  1.1     leo void *
    162  1.1     leo isa_intr_establish(ic, irq, type, level, ih_fun, ih_arg)
    163  1.1     leo 	isa_chipset_tag_t ic;
    164  1.1     leo 	int		  irq, type, level;
    165  1.1     leo 	int		  (*ih_fun) __P((void *));
    166  1.1     leo 	void		  *ih_arg;
    167  1.1     leo {
    168  1.1     leo 	isa_intr_info_t *iinfo_p;
    169  1.1     leo 	struct intrhand	*ihand;
    170  1.1     leo 	int		slot;
    171  1.1     leo 
    172  1.1     leo 	/*
    173  1.1     leo 	 * The Hades only supports edge triggered interrupts!
    174  1.1     leo 	 */
    175  1.1     leo 	if (type != IST_EDGE)
    176  1.1     leo 		return NULL;
    177  1.1     leo 
    178  1.1     leo 	slot    = SLOTNR(irq);
    179  1.1     leo 	iinfo_p = &iinfo[slot];
    180  1.1     leo 
    181  1.1     leo 	if (iinfo_p->slot >= 0)
    182  1.2  provos 	    panic("isa_intr_establish: interrupt was already established");
    183  1.1     leo 
    184  1.1     leo 	ihand = intr_establish((slot == 0) ? 3 : 15, USER_VEC, 0,
    185  1.1     leo 				(hw_ifun_t)iifun, (void *)slot);
    186  1.1     leo 	if (ihand != NULL) {
    187  1.1     leo 		iinfo_p->slot  = slot;
    188  1.1     leo 		iinfo_p->ipl   = level;
    189  1.1     leo 		iinfo_p->ifunc = ih_fun;
    190  1.1     leo 		iinfo_p->iarg  = ih_arg;
    191  1.1     leo 		iinfo_p->ihand = ihand;
    192  1.1     leo 
    193  1.1     leo 		/*
    194  1.1     leo 		 * Enable (unmask) the interrupt
    195  1.1     leo 		 */
    196  1.1     leo 		if (slot == 0) {
    197  1.1     leo 			single_inst_bset_b(MFP->mf_imrb, IB_ISA1);
    198  1.1     leo 			single_inst_bset_b(MFP->mf_ierb, IB_ISA1);
    199  1.1     leo 		}
    200  1.1     leo 		else {
    201  1.1     leo 			single_inst_bset_b(MFP->mf_imra, IA_ISA2);
    202  1.1     leo 			single_inst_bset_b(MFP->mf_iera, IA_ISA2);
    203  1.1     leo 		}
    204  1.1     leo 		return(iinfo_p);
    205  1.1     leo 	}
    206  1.1     leo 	return NULL;
    207  1.1     leo }
    208  1.1     leo 
    209  1.1     leo void
    210  1.1     leo isa_intr_disestablish(ic, handler)
    211  1.1     leo 	isa_chipset_tag_t	ic;
    212  1.1     leo 	void			*handler;
    213  1.1     leo {
    214  1.1     leo 	isa_intr_info_t *iinfo_p = (isa_intr_info_t *)handler;
    215  1.1     leo 
    216  1.1     leo 	if (iinfo_p->slot < 0)
    217  1.2  provos 	    panic("isa_intr_disestablish: interrupt was not established");
    218  1.1     leo 
    219  1.1     leo 	(void) intr_disestablish(iinfo_p->ihand);
    220  1.1     leo 	iinfo_p->slot = -1;
    221  1.1     leo }
    222