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