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