Home | History | Annotate | Line # | Download | only in isa
isa_milan.c revision 1.4.2.1
      1  1.4.2.1  nathanw /*	$NetBSD: isa_milan.c,v 1.4.2.1 2001/06/21 19:20:35 nathanw 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 <machine/iomap.h>
     48      1.1      leo 
     49      1.1      leo void	isa_bus_init(void);
     50      1.1      leo #if 0
     51      1.1      leo static void init_icu(void);
     52      1.1      leo #endif
     53      1.1      leo static void set_icus(void);
     54      1.1      leo static void calc_imask(void);
     55      1.3      leo static void isa_callback(int);
     56      1.1      leo 
     57      1.1      leo /*
     58      1.1      leo  * Bitmask of currently enabled isa interrupts. Used by set_icus().
     59      1.1      leo  */
     60      1.1      leo static u_int16_t imask_enable = 0xffff;
     61      1.1      leo 
     62      1.1      leo #define	IRQ_SLAVE	2
     63      1.1      leo 
     64      1.1      leo /*
     65      1.1      leo  * Interrupt routing table
     66      1.1      leo  */
     67      1.1      leo #define MILAN_MAX_ISA_INTS	16
     68      1.1      leo 
     69      1.1      leo static isa_intr_info_t milan_isa_iinfo[MILAN_MAX_ISA_INTS];
     70      1.1      leo 
     71      1.1      leo void
     72      1.1      leo isa_bus_init()
     73      1.1      leo {
     74      1.1      leo #if 0
     75      1.1      leo 	init_icu();
     76      1.1      leo #endif
     77      1.1      leo 	set_icus();
     78      1.1      leo }
     79      1.1      leo 
     80      1.1      leo #if 0
     81      1.2      leo /*
     82      1.2      leo  * XXX: For some reason, this does not work at all... (Leo).
     83      1.2      leo  */
     84      1.1      leo static void
     85      1.1      leo init_icu()
     86      1.1      leo {
     87      1.1      leo #define	ICU_OFFSET	0
     88      1.1      leo 
     89      1.1      leo 	u_int8_t	*icu;
     90      1.1      leo 
     91      1.1      leo 	icu = (u_int8_t*)(AD_8259_MASTER);
     92      1.1      leo 
     93      1.1      leo 	icu[0] = 0x11;			/* reset; program device, four bytes */
     94      1.1      leo 	icu[1] = ICU_OFFSET;		/* starting at this vector index */
     95      1.1      leo 	icu[1] = (1 << IRQ_SLAVE);	/* slave on line 2 */
     96      1.1      leo 	icu[1] = 1;			/* 8086 mode */
     97      1.1      leo 	icu[1] = 0xff;			/* leave interrupts masked */
     98      1.1      leo 
     99      1.1      leo 	icu = (u_int8_t*)(AD_8259_SLAVE);
    100      1.1      leo 
    101      1.1      leo 	icu[0] = 0x11;			/* reset; program device, four bytes */
    102      1.1      leo 	icu[1] = ICU_OFFSET + 8;	/* starting at this vector index */
    103      1.1      leo 	icu[1] = IRQ_SLAVE;		/* slave on line 2 */
    104      1.1      leo 	icu[1] = 1;			/* 8086 mode */
    105      1.1      leo 	icu[1] = 0xff;			/* leave interrupts masked */
    106      1.1      leo }
    107      1.1      leo #endif
    108      1.1      leo 
    109      1.1      leo static void
    110      1.1      leo set_icus()
    111      1.1      leo {
    112      1.1      leo 	u_int8_t	*icu;
    113      1.1      leo 
    114      1.1      leo 	icu = (u_int8_t*)AD_8259_MASTER;
    115      1.1      leo 	icu[1] = imask_enable & 0xff;
    116      1.1      leo 	icu = (u_int8_t*)AD_8259_SLAVE;
    117      1.1      leo 	icu[1] = (imask_enable >> 8) & 0xff;
    118      1.1      leo }
    119      1.1      leo 
    120      1.1      leo static void
    121      1.1      leo calc_imask()
    122      1.1      leo {
    123      1.1      leo 	int		irq;
    124      1.1      leo 	u_int16_t	nmask = 0;
    125      1.1      leo 
    126      1.1      leo 	for (irq = 0; irq < MILAN_MAX_ISA_INTS; irq++) {
    127      1.1      leo 		if (milan_isa_iinfo[irq].ifunc != NULL)
    128      1.1      leo 			nmask |= 1 << irq;
    129      1.1      leo 		if (nmask >= 0x100)
    130      1.1      leo 			nmask |= 1 << IRQ_SLAVE;
    131      1.1      leo 	}
    132      1.1      leo 	imask_enable = ~nmask;
    133      1.1      leo 	set_icus();
    134      1.1      leo }
    135      1.1      leo 
    136      1.3      leo static void
    137      1.3      leo isa_callback(vector)
    138      1.3      leo 	int	vector;
    139      1.3      leo {
    140      1.3      leo 	isa_intr_info_t	*iinfo_p;
    141      1.3      leo 	int		s;
    142      1.3      leo 
    143      1.3      leo 	iinfo_p = &milan_isa_iinfo[vector];
    144      1.3      leo 
    145      1.3      leo 	s = splx(iinfo_p->ipl);
    146      1.3      leo 	(void) (iinfo_p->ifunc)(iinfo_p->iarg);
    147      1.3      leo 	splx(s);
    148      1.3      leo }
    149      1.1      leo 
    150      1.3      leo void milan_isa_intr(int, int);
    151      1.1      leo void
    152      1.3      leo milan_isa_intr(vector, sr)
    153      1.3      leo 	int	vector, sr;
    154      1.1      leo {
    155      1.1      leo 	isa_intr_info_t *iinfo_p;
    156      1.4      leo 	int		s;
    157      1.1      leo 
    158      1.1      leo 	if (vector >= MILAN_MAX_ISA_INTS) {
    159      1.1      leo 		printf("milan_isa_intr: Bogus vector %d\n", vector);
    160      1.1      leo 		return;
    161      1.1      leo 	}
    162      1.1      leo 
    163      1.1      leo 	/* Acknowledge interrupt XXX 0x20 == EOI	*/
    164      1.1      leo 	if (vector > 7)
    165      1.1      leo 		*((u_char *)AD_8259_SLAVE) = 0x20;
    166      1.1      leo 	*((u_char *)AD_8259_MASTER) = 0x20;
    167      1.1      leo 
    168      1.1      leo 	iinfo_p = &milan_isa_iinfo[vector];
    169      1.3      leo 	if (iinfo_p->ifunc == NULL) {
    170      1.1      leo 		printf("milan_isa_intr: Stray interrupt: %d (mask:%04x)\n",
    171      1.1      leo 				vector, imask_enable);
    172      1.3      leo 		return;
    173      1.3      leo 	}
    174      1.3      leo 	if ((sr & PSL_IPL) >= (iinfo_p->ipl & PSL_IPL)) {
    175      1.3      leo 		/*
    176      1.3      leo 		 * We're running at a too high priority now.
    177      1.3      leo 		 */
    178      1.3      leo 		add_sicallback((si_farg)isa_callback, (void*)vector, 0);
    179      1.3      leo 	}
    180      1.3      leo 	else {
    181      1.3      leo 		s = splx(iinfo_p->ipl);
    182      1.3      leo 		(void) (iinfo_p->ifunc)(iinfo_p->iarg);
    183      1.3      leo 		splx(s);
    184      1.3      leo 	}
    185      1.1      leo }
    186      1.1      leo 
    187      1.1      leo 
    188      1.1      leo /*
    189      1.1      leo  * Try to allocate a free interrupt... On the Milan, we have available:
    190      1.1      leo  * 5, 9, 10, 11, 13. Or in a bitmask: 0x1720.
    191      1.1      leo  */
    192      1.1      leo #define	MILAN_AVAIL_ISA_INTS	0x1720
    193      1.1      leo 
    194      1.1      leo int
    195      1.1      leo isa_intr_alloc(ic, mask, type, irq)
    196      1.1      leo 	isa_chipset_tag_t ic;
    197      1.1      leo 	int mask;
    198      1.1      leo 	int type;
    199      1.1      leo 	int *irq;
    200      1.1      leo {
    201      1.1      leo 	int	i;
    202      1.1      leo 
    203      1.1      leo 	/*
    204      1.1      leo 	 * The Hades only supports edge triggered interrupts!
    205      1.1      leo 	 * XXX: Find out about the Milan....
    206      1.1      leo 	 */
    207      1.1      leo 	if (type != IST_EDGE)
    208      1.1      leo 		return 1;
    209      1.1      leo 
    210      1.1      leo 	/*
    211      1.1      leo 	 * Say no to impossible questions...
    212      1.1      leo 	 */
    213      1.1      leo 	if (!(mask &= MILAN_AVAIL_ISA_INTS))
    214      1.1      leo 		return 1;
    215      1.1      leo 
    216      1.1      leo 	for (i = 0; i < MILAN_MAX_ISA_INTS; i++) {
    217      1.1      leo 		if (mask & (1<<i)) {
    218      1.1      leo 		    if (milan_isa_iinfo[i].ifunc == NULL) {
    219      1.1      leo 			*irq = i;
    220      1.1      leo 			return 0;
    221      1.1      leo 		    }
    222      1.1      leo 		}
    223      1.1      leo 	}
    224      1.1      leo 	return (1);
    225      1.1      leo }
    226      1.1      leo 
    227      1.1      leo void *
    228      1.1      leo isa_intr_establish(ic, irq, type, level, ih_fun, ih_arg)
    229      1.1      leo 	isa_chipset_tag_t ic;
    230      1.1      leo 	int		  irq, type, level;
    231      1.1      leo 	int		  (*ih_fun) __P((void *));
    232      1.1      leo 	void		  *ih_arg;
    233      1.1      leo {
    234      1.1      leo 	isa_intr_info_t *iinfo_p;
    235      1.1      leo 
    236      1.1      leo 	/*
    237      1.1      leo 	 * The Hades only supports edge triggered interrupts!
    238      1.1      leo 	 * XXX: Find out oubout the Milan...
    239      1.1      leo 	 */
    240      1.1      leo 	if (type != IST_EDGE)
    241      1.1      leo 		return NULL;
    242      1.1      leo 
    243      1.1      leo 	iinfo_p = &milan_isa_iinfo[irq];
    244      1.1      leo 
    245      1.1      leo 	if (iinfo_p->ifunc != NULL) {
    246      1.1      leo 		printf("isa_intr_establish: interrupt %d was already "
    247      1.1      leo 			"established\n", irq);
    248      1.1      leo 		return NULL;
    249      1.1      leo 	}
    250      1.1      leo 
    251      1.1      leo 	iinfo_p->slot  = 0;	/* Unused on Milan */
    252      1.1      leo 	iinfo_p->ihand = NULL;	/* Unused on Milan */
    253      1.1      leo 	iinfo_p->ipl   = level;
    254      1.1      leo 	iinfo_p->ifunc = ih_fun;
    255      1.1      leo 	iinfo_p->iarg  = ih_arg;
    256      1.1      leo 
    257      1.1      leo 	calc_imask();
    258      1.1      leo 	return(iinfo_p);
    259      1.1      leo }
    260      1.1      leo 
    261      1.1      leo void
    262      1.1      leo isa_intr_disestablish(ic, handler)
    263      1.1      leo 	isa_chipset_tag_t	ic;
    264      1.1      leo 	void			*handler;
    265      1.1      leo {
    266      1.1      leo 	isa_intr_info_t *iinfo_p = (isa_intr_info_t *)handler;
    267      1.1      leo 
    268      1.1      leo 	if (iinfo_p->ifunc == NULL)
    269      1.1      leo 	    panic("isa_intr_disestablish: interrupt was not established\n");
    270      1.1      leo 
    271      1.1      leo 	iinfo_p->ifunc = NULL;
    272      1.1      leo 	calc_imask();
    273      1.1      leo }
    274