Home | History | Annotate | Line # | Download | only in isa
      1  1.10  tsutsui /*	$NetBSD: isa_hades.c,v 1.10 2023/01/06 10:28:28 tsutsui 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.10  tsutsui __KERNEL_RCSID(0, "$NetBSD: isa_hades.c,v 1.10 2023/01/06 10:28:28 tsutsui 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.9   cegger isa_bus_init(void)
     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.6      dsl static int	iifun(int, int);
     69   1.1      leo 
     70   1.1      leo static int
     71   1.7      dsl iifun(int slot, int sr)
     72   1.1      leo {
     73   1.1      leo 	isa_intr_info_t *iinfo_p;
     74   1.1      leo 	int		s;
     75   1.1      leo 
     76   1.1      leo 	iinfo_p = &iinfo[slot];
     77   1.1      leo 
     78   1.1      leo 	/*
     79   1.1      leo 	 * Disable the interrupts
     80   1.1      leo 	 */
     81   1.1      leo 	if (slot == 0) {
     82   1.1      leo 		single_inst_bclr_b(MFP->mf_imrb, IB_ISA1);
     83   1.1      leo 	}
     84   1.1      leo 	else {
     85   1.1      leo 		single_inst_bclr_b(MFP->mf_imra, IA_ISA2);
     86   1.1      leo 	}
     87   1.1      leo 
     88   1.1      leo 	if ((sr & PSL_IPL) >= (iinfo_p->ipl & PSL_IPL)) {
     89   1.1      leo 		/*
     90   1.1      leo 		 * We're running at a too high priority now.
     91   1.1      leo 		 */
     92   1.1      leo 		add_sicallback((si_farg)iifun, (void*)slot, 0);
     93   1.1      leo 	}
     94   1.1      leo 	else {
     95   1.1      leo 		s = splx(iinfo_p->ipl);
     96   1.1      leo 		if (slot == 0) {
     97   1.1      leo 			do {
     98   1.1      leo 				MFP->mf_iprb = (u_int8_t)~IB_ISA1;
     99   1.1      leo 				(void) (iinfo_p->ifunc)(iinfo_p->iarg);
    100   1.1      leo 			} while (MFP->mf_iprb & IB_ISA1);
    101   1.1      leo 			single_inst_bset_b(MFP->mf_imrb, IB_ISA1);
    102   1.1      leo 		}
    103   1.1      leo 		else {
    104   1.1      leo 			do {
    105   1.1      leo 				MFP->mf_ipra = (u_int8_t)~IA_ISA2;
    106   1.1      leo 				(void) (iinfo_p->ifunc)(iinfo_p->iarg);
    107   1.1      leo 			} while (MFP->mf_ipra & IA_ISA2);
    108   1.1      leo 			single_inst_bset_b(MFP->mf_imra, IA_ISA2);
    109   1.1      leo 		}
    110   1.1      leo 		splx(s);
    111   1.1      leo 	}
    112   1.1      leo 	return 1;
    113   1.1      leo }
    114   1.1      leo 
    115   1.1      leo 
    116   1.1      leo /*
    117   1.1      leo  * XXXX
    118   1.1      leo  * XXXX Note that this function is not really working yet! The big problem is
    119   1.1      leo  * XXXX to only generate interrupts for the slot the card is in...
    120   1.1      leo  */
    121   1.1      leo int
    122   1.7      dsl isa_intr_alloc(isa_chipset_tag_t ic, int mask, int type, int *irq)
    123   1.1      leo {
    124   1.1      leo 	isa_intr_info_t *iinfo_p;
    125   1.1      leo 	int		slot, i;
    126   1.1      leo 
    127   1.1      leo 
    128   1.1      leo 	/*
    129   1.1      leo 	 * The Hades only supports edge triggered interrupts!
    130   1.1      leo 	 */
    131   1.1      leo 	if (type != IST_EDGE)
    132   1.1      leo 		return 1;
    133   1.1      leo 
    134   1.1      leo #define	MAXIRQ		10	/* XXX: Pure fiction	*/
    135   1.1      leo 	for (i = 0; i < MAXIRQ; i++) {
    136   1.1      leo 		if (mask & (1<<i)) {
    137   1.1      leo 		    slot    = SLOTNR(i);
    138   1.1      leo 		    iinfo_p = &iinfo[slot];
    139   1.1      leo 
    140   1.1      leo 		    if (iinfo_p->slot < 0) {
    141   1.1      leo 			*irq = i;
    142   1.1      leo 			printf("WARNING: isa_intr_alloc is not yet ready!\n"
    143   1.1      leo 			       "         make sure the card is in slot %d!\n",
    144   1.1      leo 				slot);
    145   1.1      leo 			return 0;
    146   1.1      leo 		    }
    147   1.1      leo 		}
    148   1.1      leo 	}
    149   1.1      leo 	return (1);
    150   1.1      leo }
    151   1.1      leo void *
    152   1.8      dsl isa_intr_establish(isa_chipset_tag_t ic, int irq, int type, int level, int (*ih_fun)(void *), void *ih_arg)
    153   1.1      leo {
    154   1.1      leo 	isa_intr_info_t *iinfo_p;
    155   1.1      leo 	struct intrhand	*ihand;
    156   1.1      leo 	int		slot;
    157   1.1      leo 
    158   1.1      leo 	/*
    159   1.1      leo 	 * The Hades only supports edge triggered interrupts!
    160   1.1      leo 	 */
    161   1.1      leo 	if (type != IST_EDGE)
    162   1.1      leo 		return NULL;
    163   1.1      leo 
    164   1.1      leo 	slot    = SLOTNR(irq);
    165   1.1      leo 	iinfo_p = &iinfo[slot];
    166   1.1      leo 
    167   1.1      leo 	if (iinfo_p->slot >= 0)
    168  1.10  tsutsui 		panic("isa_intr_establish: interrupt was already established");
    169   1.1      leo 
    170   1.1      leo 	ihand = intr_establish((slot == 0) ? 3 : 15, USER_VEC, 0,
    171   1.1      leo 				(hw_ifun_t)iifun, (void *)slot);
    172   1.1      leo 	if (ihand != NULL) {
    173   1.1      leo 		iinfo_p->slot  = slot;
    174   1.1      leo 		iinfo_p->ipl   = level;
    175   1.1      leo 		iinfo_p->ifunc = ih_fun;
    176   1.1      leo 		iinfo_p->iarg  = ih_arg;
    177   1.1      leo 		iinfo_p->ihand = ihand;
    178   1.1      leo 
    179   1.1      leo 		/*
    180   1.1      leo 		 * Enable (unmask) the interrupt
    181   1.1      leo 		 */
    182   1.1      leo 		if (slot == 0) {
    183   1.1      leo 			single_inst_bset_b(MFP->mf_imrb, IB_ISA1);
    184   1.1      leo 			single_inst_bset_b(MFP->mf_ierb, IB_ISA1);
    185   1.1      leo 		}
    186   1.1      leo 		else {
    187   1.1      leo 			single_inst_bset_b(MFP->mf_imra, IA_ISA2);
    188   1.1      leo 			single_inst_bset_b(MFP->mf_iera, IA_ISA2);
    189   1.1      leo 		}
    190   1.1      leo 		return(iinfo_p);
    191   1.1      leo 	}
    192   1.1      leo 	return NULL;
    193   1.1      leo }
    194   1.1      leo 
    195   1.1      leo void
    196   1.7      dsl isa_intr_disestablish(isa_chipset_tag_t ic, void *handler)
    197   1.1      leo {
    198   1.1      leo 	isa_intr_info_t *iinfo_p = (isa_intr_info_t *)handler;
    199   1.1      leo 
    200   1.1      leo 	if (iinfo_p->slot < 0)
    201  1.10  tsutsui 		panic("isa_intr_disestablish: interrupt was not established");
    202   1.1      leo 
    203   1.1      leo 	(void) intr_disestablish(iinfo_p->ihand);
    204   1.1      leo 	iinfo_p->slot = -1;
    205   1.1      leo }
    206