Home | History | Annotate | Line # | Download | only in isa
isa_machdep.c revision 1.21
      1  1.21      leo /*	$NetBSD: isa_machdep.c,v 1.21 2001/03/09 20:55:47 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.10  mycroft  * Copyright (c) 1994 Charles M. 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.10  mycroft  *	This product includes software developed by Charles M. 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.19      mrg #include <uvm/uvm_extern.h>
     42   1.1      leo 
     43  1.21      leo #define _ATARI_BUS_DMA_PRIVATE
     44  1.21      leo #include <machine/bus.h>
     45   1.1      leo #include <dev/isa/isavar.h>
     46   1.1      leo #include <dev/isa/isareg.h>
     47   1.1      leo 
     48  1.11      leo #include <m68k/asm_single.h>
     49  1.11      leo 
     50   1.1      leo #include <machine/cpu.h>
     51   1.1      leo #include <machine/iomap.h>
     52   1.1      leo #include <machine/mfp.h>
     53   1.1      leo #include <atari/atari/device.h>
     54   1.1      leo 
     55  1.21      leo #include "isadma.h"
     56  1.21      leo 
     57  1.21      leo #if NISADMA == 0
     58  1.21      leo 
     59  1.21      leo /*
     60  1.21      leo  * Entry points for ISA DMA while no DMA capable devices are attached.
     61  1.21      leo  * This must be a serious error. Cause a panic...
     62  1.21      leo  */
     63  1.21      leo struct atari_bus_dma_tag isa_bus_dma_tag = {
     64  1.21      leo 	0
     65  1.21      leo };
     66  1.21      leo #endif /* NISADMA == 0 */
     67  1.21      leo 
     68   1.1      leo static int	isabusprint __P((void *auxp, const char *));
     69   1.1      leo static int	isabusmatch __P((struct device *, struct cfdata *, void *));
     70   1.1      leo static void	isabusattach __P((struct device *, struct device *, void *));
     71   1.1      leo 
     72   1.8  thorpej struct isabus_softc {
     73   1.8  thorpej 	struct device sc_dev;
     74   1.8  thorpej 	struct atari_isa_chipset sc_chipset;
     75   1.8  thorpej };
     76   1.8  thorpej 
     77   1.1      leo struct cfattach isabus_ca = {
     78   1.8  thorpej 	sizeof(struct isabus_softc), isabusmatch, isabusattach
     79   1.1      leo };
     80   1.1      leo 
     81   1.1      leo int
     82   1.1      leo isabusmatch(pdp, cfp, auxp)
     83   1.1      leo struct device	*pdp;
     84   1.1      leo struct cfdata	*cfp;
     85   1.1      leo void		*auxp;
     86   1.1      leo {
     87  1.20      leo 	static int	nmatched = 0;
     88  1.20      leo 
     89  1.20      leo 	if (strcmp((char *)auxp, "isabus"))
     90  1.20      leo 		return (0); /* Wrong number... */
     91  1.20      leo 
     92   1.1      leo 	if(atari_realconfig == 0)
     93   1.1      leo 		return (0);
     94  1.20      leo 
     95  1.20      leo 	if (machineid & (ATARI_HADES|ATARI_MILAN)) {
     96  1.20      leo 		/*
     97  1.20      leo 		 * The Hades and Milan have only one pci bus
     98  1.20      leo 		 */
     99  1.20      leo 		if (nmatched)
    100  1.20      leo 			return (0);
    101  1.20      leo 		nmatched++;
    102  1.20      leo 		return (1);
    103  1.20      leo 	}
    104  1.20      leo 	return(0);
    105   1.1      leo }
    106   1.1      leo 
    107   1.1      leo void
    108   1.1      leo isabusattach(pdp, dp, auxp)
    109   1.1      leo struct device	*pdp, *dp;
    110   1.1      leo void		*auxp;
    111   1.1      leo {
    112   1.9      leo 	struct isabus_softc *sc = (struct isabus_softc *)dp;
    113   1.1      leo 	struct isabus_attach_args	iba;
    114  1.21      leo 	extern struct atari_bus_dma_tag isa_bus_dma_tag;
    115   1.1      leo 
    116   1.1      leo 	iba.iba_busname = "isa";
    117  1.21      leo 	iba.iba_dmat	= &isa_bus_dma_tag;
    118  1.16      leo 	iba.iba_iot     = leb_alloc_bus_space_tag(NULL);
    119  1.16      leo 	iba.iba_memt    = leb_alloc_bus_space_tag(NULL);
    120   1.8  thorpej 	iba.iba_ic	= &sc->sc_chipset;
    121   1.5      leo 	if ((iba.iba_iot == NULL) || (iba.iba_memt == NULL)) {
    122   1.5      leo 		printf("leb_alloc_bus_space_tag failed!\n");
    123   1.5      leo 		return;
    124   1.5      leo 	}
    125   1.5      leo 	iba.iba_iot->base  = ISA_IOSTART;
    126   1.5      leo 	iba.iba_memt->base = ISA_MEMSTART;
    127   1.1      leo 
    128  1.13      leo 	MFP->mf_aer |= (IO_ISA1|IO_ISA2); /* ISA interrupts: LOW->HIGH */
    129   1.1      leo 
    130   1.1      leo 	printf("\n");
    131   1.1      leo 	config_found(dp, &iba, isabusprint);
    132   1.1      leo }
    133   1.1      leo 
    134   1.1      leo int
    135   1.1      leo isabusprint(auxp, name)
    136   1.1      leo void		*auxp;
    137   1.1      leo const char	*name;
    138   1.1      leo {
    139   1.1      leo 	if(name == NULL)
    140   1.1      leo 		return(UNCONF);
    141   1.1      leo 	return(QUIET);
    142   1.1      leo }
    143   1.1      leo 
    144   1.1      leo void
    145   1.1      leo isa_attach_hook(parent, self, iba)
    146   1.1      leo 	struct device		  *parent, *self;
    147   1.1      leo 	struct isabus_attach_args *iba;
    148   1.1      leo {
    149   1.1      leo }
    150   1.1      leo 
    151   1.1      leo /*
    152   1.1      leo  * The interrupt stuff is rather ugly. On the Hades, all interrupt lines
    153   1.1      leo  * for a slot are wired together and connected to either IO3 (slot1) or
    154   1.1      leo  * IO7 (slot2). Since no info can be obtained about the slot position
    155   1.1      leo  * at isa_intr_establish() time, the following assumption is made:
    156   1.1      leo  *   - irq <= 6 -> slot 1
    157   1.1      leo  *   - irq >  6 -> slot 2
    158   1.1      leo  */
    159  1.14      leo 
    160  1.14      leo #define	SLOTNR(irq)	((irq <= 6) ? 0 : 1)
    161  1.14      leo 
    162   1.1      leo static isa_intr_info_t iinfo[2] = { { -1 }, { -1 } };
    163   1.1      leo 
    164   1.1      leo static int	iifun __P((int, int));
    165   1.1      leo 
    166   1.1      leo static int
    167   1.1      leo iifun(slot, sr)
    168   1.1      leo int	slot;
    169   1.1      leo int	sr;
    170   1.1      leo {
    171   1.1      leo 	isa_intr_info_t *iinfo_p;
    172   1.1      leo 	int		s;
    173   1.1      leo 
    174   1.1      leo 	iinfo_p = &iinfo[slot];
    175   1.1      leo 
    176   1.1      leo 	/*
    177   1.1      leo 	 * Disable the interrupts
    178   1.1      leo 	 */
    179  1.11      leo 	if (slot == 0) {
    180  1.13      leo 		single_inst_bclr_b(MFP->mf_imrb, IB_ISA1);
    181  1.11      leo 	}
    182  1.11      leo 	else {
    183  1.13      leo 		single_inst_bclr_b(MFP->mf_imra, IA_ISA2);
    184  1.11      leo 	}
    185   1.1      leo 
    186   1.7      leo 	if ((sr & PSL_IPL) >= (iinfo_p->ipl & PSL_IPL)) {
    187   1.1      leo 		/*
    188   1.1      leo 		 * We're running at a too high priority now.
    189   1.1      leo 		 */
    190   1.1      leo 		add_sicallback((si_farg)iifun, (void*)slot, 0);
    191   1.1      leo 	}
    192   1.1      leo 	else {
    193   1.1      leo 		s = splx(iinfo_p->ipl);
    194  1.11      leo 		if (slot == 0) {
    195  1.11      leo 			do {
    196  1.13      leo 				MFP->mf_iprb = (u_int8_t)~IB_ISA1;
    197  1.11      leo 				(void) (iinfo_p->ifunc)(iinfo_p->iarg);
    198  1.11      leo 			} while (MFP->mf_iprb & IB_ISA1);
    199  1.13      leo 			single_inst_bset_b(MFP->mf_imrb, IB_ISA1);
    200  1.11      leo 		}
    201  1.11      leo 		else {
    202  1.11      leo 			do {
    203  1.13      leo 				MFP->mf_ipra = (u_int8_t)~IA_ISA2;
    204  1.11      leo 				(void) (iinfo_p->ifunc)(iinfo_p->iarg);
    205  1.11      leo 			} while (MFP->mf_ipra & IA_ISA2);
    206  1.13      leo 			single_inst_bset_b(MFP->mf_imra, IA_ISA2);
    207  1.11      leo 		}
    208   1.1      leo 		splx(s);
    209   1.1      leo 	}
    210   1.1      leo 	return 1;
    211   1.1      leo }
    212   1.1      leo 
    213  1.14      leo 
    214  1.14      leo /*
    215  1.14      leo  * XXXX
    216  1.14      leo  * XXXX Note that this function is not really working yet! The big problem is
    217  1.14      leo  * XXXX to only generate interrupts for the slot the card is in...
    218  1.14      leo  */
    219  1.14      leo int
    220  1.14      leo isa_intr_alloc(ic, mask, type, irq)
    221  1.14      leo 	isa_chipset_tag_t ic;
    222  1.14      leo 	int mask;
    223  1.14      leo 	int type;
    224  1.14      leo 	int *irq;
    225  1.14      leo {
    226  1.14      leo 	isa_intr_info_t *iinfo_p;
    227  1.14      leo 	int		slot, i;
    228  1.14      leo 
    229  1.14      leo 
    230  1.14      leo 	/*
    231  1.14      leo 	 * The Hades only supports edge triggered interrupts!
    232  1.14      leo 	 */
    233  1.14      leo 	if (type != IST_EDGE)
    234  1.14      leo 		return 1;
    235  1.14      leo 
    236  1.14      leo #define	MAXIRQ		10	/* XXX: Pure fiction	*/
    237  1.14      leo 	for (i = 0; i < MAXIRQ; i++) {
    238  1.14      leo 		if (mask & (1<<i)) {
    239  1.14      leo 		    slot    = SLOTNR(i);
    240  1.14      leo 		    iinfo_p = &iinfo[slot];
    241  1.14      leo 
    242  1.15      leo 		    if (iinfo_p->slot < 0) {
    243  1.14      leo 			*irq = i;
    244  1.15      leo 			printf("WARNING: isa_intr_alloc is not yet ready!\n"
    245  1.15      leo 			       "         make sure the card is in slot %d!\n",
    246  1.15      leo 				slot);
    247  1.14      leo 			return 0;
    248  1.14      leo 		    }
    249  1.14      leo 		}
    250  1.14      leo 	}
    251  1.14      leo 	return (1);
    252  1.17      cgd }
    253  1.17      cgd 
    254  1.17      cgd const struct evcnt *
    255  1.17      cgd isa_intr_evcnt(isa_chipset_tag_t ic, int irq)
    256  1.17      cgd {
    257  1.17      cgd 
    258  1.17      cgd 	/* XXX for now, no evcnt parent reported */
    259  1.17      cgd 	return NULL;
    260  1.14      leo }
    261  1.14      leo 
    262   1.1      leo void *
    263   1.1      leo isa_intr_establish(ic, irq, type, level, ih_fun, ih_arg)
    264   1.1      leo 	isa_chipset_tag_t ic;
    265   1.1      leo 	int		  irq, type, level;
    266   1.6      leo 	int		  (*ih_fun) __P((void *));
    267   1.1      leo 	void		  *ih_arg;
    268   1.1      leo {
    269   1.1      leo 	isa_intr_info_t *iinfo_p;
    270   1.1      leo 	struct intrhand	*ihand;
    271   1.1      leo 	int		slot;
    272  1.12      leo 
    273  1.12      leo 	/*
    274  1.12      leo 	 * The Hades only supports edge triggered interrupts!
    275  1.12      leo 	 */
    276  1.12      leo 	if (type != IST_EDGE)
    277  1.12      leo 		return NULL;
    278   1.1      leo 
    279  1.14      leo 	slot    = SLOTNR(irq);
    280   1.1      leo 	iinfo_p = &iinfo[slot];
    281   1.1      leo 
    282  1.14      leo 	if (iinfo_p->slot >= 0)
    283   1.1      leo 	    panic("isa_intr_establish: interrupt was already established\n");
    284   1.1      leo 
    285   1.2      leo 	ihand = intr_establish((slot == 0) ? 3 : 15, USER_VEC, 0,
    286   1.1      leo 				(hw_ifun_t)iifun, (void *)slot);
    287   1.1      leo 	if (ihand != NULL) {
    288   1.1      leo 		iinfo_p->slot  = slot;
    289   1.1      leo 		iinfo_p->ipl   = level;
    290   1.1      leo 		iinfo_p->ifunc = ih_fun;
    291   1.1      leo 		iinfo_p->iarg  = ih_arg;
    292   1.1      leo 		iinfo_p->ihand = ihand;
    293   1.1      leo 
    294   1.1      leo 		/*
    295   1.1      leo 		 * Enable (unmask) the interrupt
    296   1.1      leo 		 */
    297   1.2      leo 		if (slot == 0) {
    298  1.13      leo 			single_inst_bset_b(MFP->mf_imrb, IB_ISA1);
    299  1.13      leo 			single_inst_bset_b(MFP->mf_ierb, IB_ISA1);
    300   1.1      leo 		}
    301   1.1      leo 		else {
    302  1.13      leo 			single_inst_bset_b(MFP->mf_imra, IA_ISA2);
    303  1.13      leo 			single_inst_bset_b(MFP->mf_iera, IA_ISA2);
    304   1.1      leo 		}
    305   1.1      leo 		return(iinfo_p);
    306   1.1      leo 	}
    307   1.1      leo 	return NULL;
    308   1.1      leo }
    309   1.1      leo 
    310   1.1      leo void
    311   1.1      leo isa_intr_disestablish(ic, handler)
    312   1.1      leo 	isa_chipset_tag_t	ic;
    313   1.1      leo 	void			*handler;
    314   1.1      leo {
    315   1.1      leo 	isa_intr_info_t *iinfo_p = (isa_intr_info_t *)handler;
    316   1.1      leo 
    317   1.1      leo 	if (iinfo_p->slot < 0)
    318   1.1      leo 	    panic("isa_intr_disestablish: interrupt was not established\n");
    319   1.1      leo 
    320   1.1      leo 	(void) intr_disestablish(iinfo_p->ihand);
    321   1.1      leo 	iinfo_p->slot = -1;
    322   1.1      leo }
    323