Home | History | Annotate | Line # | Download | only in mvme
vme_two_isr.c revision 1.2.6.2
      1  1.2.6.2  jdolecek /*	$NetBSD: vme_two_isr.c,v 1.2.6.2 2002/10/10 18:40:17 jdolecek Exp $	*/
      2  1.2.6.2  jdolecek 
      3  1.2.6.2  jdolecek /*-
      4  1.2.6.2  jdolecek  * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
      5  1.2.6.2  jdolecek  * All rights reserved.
      6  1.2.6.2  jdolecek  *
      7  1.2.6.2  jdolecek  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2.6.2  jdolecek  * by Steve C. Woodford.
      9  1.2.6.2  jdolecek  *
     10  1.2.6.2  jdolecek  * Redistribution and use in source and binary forms, with or without
     11  1.2.6.2  jdolecek  * modification, are permitted provided that the following conditions
     12  1.2.6.2  jdolecek  * are met:
     13  1.2.6.2  jdolecek  * 1. Redistributions of source code must retain the above copyright
     14  1.2.6.2  jdolecek  *    notice, this list of conditions and the following disclaimer.
     15  1.2.6.2  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.2.6.2  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     17  1.2.6.2  jdolecek  *    documentation and/or other materials provided with the distribution.
     18  1.2.6.2  jdolecek  * 3. All advertising materials mentioning features or use of this software
     19  1.2.6.2  jdolecek  *    must display the following acknowledgement:
     20  1.2.6.2  jdolecek  *        This product includes software developed by the NetBSD
     21  1.2.6.2  jdolecek  *        Foundation, Inc. and its contributors.
     22  1.2.6.2  jdolecek  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.2.6.2  jdolecek  *    contributors may be used to endorse or promote products derived
     24  1.2.6.2  jdolecek  *    from this software without specific prior written permission.
     25  1.2.6.2  jdolecek  *
     26  1.2.6.2  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.2.6.2  jdolecek  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.2.6.2  jdolecek  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.2.6.2  jdolecek  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.2.6.2  jdolecek  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.2.6.2  jdolecek  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.2.6.2  jdolecek  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.2.6.2  jdolecek  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.2.6.2  jdolecek  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.2.6.2  jdolecek  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.2.6.2  jdolecek  * POSSIBILITY OF SUCH DAMAGE.
     37  1.2.6.2  jdolecek  */
     38  1.2.6.2  jdolecek 
     39  1.2.6.2  jdolecek /*
     40  1.2.6.2  jdolecek  * Split off from vme_two.c specifically to deal with hardware assisted
     41  1.2.6.2  jdolecek  * soft interrupts when the user hasn't specified `vmetwo0' in the
     42  1.2.6.2  jdolecek  * kernel config file (mvme1[67]2 only).
     43  1.2.6.2  jdolecek  */
     44  1.2.6.2  jdolecek 
     45  1.2.6.2  jdolecek #include "vmetwo.h"
     46  1.2.6.2  jdolecek 
     47  1.2.6.2  jdolecek #include <sys/param.h>
     48  1.2.6.2  jdolecek #include <sys/kernel.h>
     49  1.2.6.2  jdolecek #include <sys/systm.h>
     50  1.2.6.2  jdolecek #include <sys/device.h>
     51  1.2.6.2  jdolecek #include <sys/malloc.h>
     52  1.2.6.2  jdolecek 
     53  1.2.6.2  jdolecek #include <machine/cpu.h>
     54  1.2.6.2  jdolecek #include <machine/bus.h>
     55  1.2.6.2  jdolecek 
     56  1.2.6.2  jdolecek #include <dev/vme/vmereg.h>
     57  1.2.6.2  jdolecek #include <dev/vme/vmevar.h>
     58  1.2.6.2  jdolecek 
     59  1.2.6.2  jdolecek #include <dev/mvme/mvmebus.h>
     60  1.2.6.2  jdolecek #include <dev/mvme/vme_tworeg.h>
     61  1.2.6.2  jdolecek #include <dev/mvme/vme_twovar.h>
     62  1.2.6.2  jdolecek 
     63  1.2.6.2  jdolecek /*
     64  1.2.6.2  jdolecek  * Non-zero if there is no VMEChip2 on this board.
     65  1.2.6.2  jdolecek  */
     66  1.2.6.2  jdolecek int vmetwo_not_present;
     67  1.2.6.2  jdolecek 
     68  1.2.6.2  jdolecek /*
     69  1.2.6.2  jdolecek  * Array of interrupt handlers registered with us for the non-VMEbus
     70  1.2.6.2  jdolecek  * vectored interrupts. Eg. ABORT Switch, SYSFAIL etc.
     71  1.2.6.2  jdolecek  *
     72  1.2.6.2  jdolecek  * We can't just install a caller's handler directly, since these
     73  1.2.6.2  jdolecek  * interrupts have to be manually cleared, so we have a trampoline
     74  1.2.6.2  jdolecek  * which does the clearing automatically.
     75  1.2.6.2  jdolecek  */
     76  1.2.6.2  jdolecek static struct vme_two_handler {
     77  1.2.6.2  jdolecek 	int (*isr_hand) __P((void *));
     78  1.2.6.2  jdolecek 	void *isr_arg;
     79  1.2.6.2  jdolecek } vme_two_handlers[(VME2_VECTOR_LOCAL_MAX - VME2_VECTOR_LOCAL_MIN) + 1];
     80  1.2.6.2  jdolecek 
     81  1.2.6.2  jdolecek #define VMETWO_HANDLERS_SZ	(sizeof(vme_two_handlers) /	\
     82  1.2.6.2  jdolecek 				 sizeof(struct vme_two_handler))
     83  1.2.6.2  jdolecek 
     84  1.2.6.2  jdolecek static	int  vmetwo_local_isr_trampoline(void *);
     85  1.2.6.2  jdolecek static	void vmetwo_softintr_assert(void);
     86  1.2.6.2  jdolecek 
     87  1.2.6.2  jdolecek static	struct vmetwo_softc *vmetwo_sc;
     88  1.2.6.2  jdolecek 
     89  1.2.6.2  jdolecek int
     90  1.2.6.2  jdolecek vmetwo_probe(bus_space_tag_t bt, bus_addr_t offset)
     91  1.2.6.2  jdolecek {
     92  1.2.6.2  jdolecek 	bus_space_handle_t bh;
     93  1.2.6.2  jdolecek 
     94  1.2.6.2  jdolecek 	bus_space_map(bt, offset + VME2REG_LCSR_OFFSET, VME2LCSR_SIZE, 0, &bh);
     95  1.2.6.2  jdolecek 
     96  1.2.6.2  jdolecek 	if (bus_space_peek_4(bt, bh, VME2LCSR_MISC_STATUS, NULL) != 0) {
     97  1.2.6.2  jdolecek #if defined(MVME162) || defined(MVME172)
     98  1.2.6.2  jdolecek #if defined(MVME167) || defined(MVME177)
     99  1.2.6.2  jdolecek 		if (machineid == MVME_162 || machineid == MVME_172)
    100  1.2.6.2  jdolecek #endif
    101  1.2.6.2  jdolecek 		{
    102  1.2.6.2  jdolecek 			/*
    103  1.2.6.2  jdolecek 			 * No VMEChip2 on mvme162/172 is not too big a
    104  1.2.6.2  jdolecek 			 * deal; we can fall back on timer4 in the
    105  1.2.6.2  jdolecek 			 * mcchip for h/w assisted soft interrupts...
    106  1.2.6.2  jdolecek 			 */
    107  1.2.6.2  jdolecek 			extern void pcctwosoftintrinit(void);
    108  1.2.6.2  jdolecek 			bus_space_unmap(bt, bh, VME2LCSR_SIZE);
    109  1.2.6.2  jdolecek 			vmetwo_not_present = 1;
    110  1.2.6.2  jdolecek 			pcctwosoftintrinit();
    111  1.2.6.2  jdolecek 			return (0);
    112  1.2.6.2  jdolecek 		}
    113  1.2.6.2  jdolecek #endif
    114  1.2.6.2  jdolecek #if defined(MVME167) || defined(MVME177) || defined(MVME88K)
    115  1.2.6.2  jdolecek 		/*
    116  1.2.6.2  jdolecek 		 * No VMEChip2 on mvme167/177, however, is a Big Deal.
    117  1.2.6.2  jdolecek 		 * In fact, it means the hardware's shot since the
    118  1.2.6.2  jdolecek 		 * VMEChip2 is not a `build-option' on those boards.
    119  1.2.6.2  jdolecek 		 */
    120  1.2.6.2  jdolecek 		panic("VMEChip2 not responding! Faulty board?");
    121  1.2.6.2  jdolecek 		/* NOTREACHED */
    122  1.2.6.2  jdolecek #endif
    123  1.2.6.2  jdolecek #if defined(MVMEPPC)
    124  1.2.6.2  jdolecek 		/*
    125  1.2.6.2  jdolecek 		 * No VMEChip2 on mvmeppc is no big deal.
    126  1.2.6.2  jdolecek 		 */
    127  1.2.6.2  jdolecek 		bus_space_unmap(bt, bh, VME2LCSR_SIZE);
    128  1.2.6.2  jdolecek 		vmetwo_not_present = 1;
    129  1.2.6.2  jdolecek 		return (0);
    130  1.2.6.2  jdolecek #endif
    131  1.2.6.2  jdolecek 	}
    132  1.2.6.2  jdolecek #if NVMETWO == 0
    133  1.2.6.2  jdolecek 	else {
    134  1.2.6.2  jdolecek 		/*
    135  1.2.6.2  jdolecek 		 * The kernel config file has no `vmetwo0' device, but
    136  1.2.6.2  jdolecek 		 * there is a VMEChip2 on the board. Fix up things
    137  1.2.6.2  jdolecek 		 * just enough to hook VMEChip2 local interrupts.
    138  1.2.6.2  jdolecek 		 */
    139  1.2.6.2  jdolecek 		struct vmetwo_softc *sc;
    140  1.2.6.2  jdolecek 
    141  1.2.6.2  jdolecek 		/* XXX Should check sc != NULL here... */
    142  1.2.6.2  jdolecek 		MALLOC(sc, struct vmetwo_softc *, sizeof(*sc), M_DEVBUF,
    143  1.2.6.2  jdolecek 		    M_NOWAIT);
    144  1.2.6.2  jdolecek 
    145  1.2.6.2  jdolecek 		sc->sc_mvmebus.sc_bust = bt;
    146  1.2.6.2  jdolecek 		sc->sc_lcrh = bh;
    147  1.2.6.2  jdolecek 		vmetwo_intr_init(sc);
    148  1.2.6.2  jdolecek 		return 0;
    149  1.2.6.2  jdolecek 	}
    150  1.2.6.2  jdolecek #else
    151  1.2.6.2  jdolecek 	bus_space_unmap(bt, bh, VME2LCSR_SIZE);
    152  1.2.6.2  jdolecek 	return (1);
    153  1.2.6.2  jdolecek #endif
    154  1.2.6.2  jdolecek }
    155  1.2.6.2  jdolecek 
    156  1.2.6.2  jdolecek void
    157  1.2.6.2  jdolecek vmetwo_intr_init(struct vmetwo_softc *sc)
    158  1.2.6.2  jdolecek {
    159  1.2.6.2  jdolecek 	u_int32_t reg;
    160  1.2.6.2  jdolecek 	int i;
    161  1.2.6.2  jdolecek 
    162  1.2.6.2  jdolecek 	vmetwo_sc = sc;
    163  1.2.6.2  jdolecek 
    164  1.2.6.2  jdolecek 	/* Clear out the ISR handler array */
    165  1.2.6.2  jdolecek 	for (i = 0; i < VMETWO_HANDLERS_SZ; i++)
    166  1.2.6.2  jdolecek 		vme_two_handlers[i].isr_hand = NULL;
    167  1.2.6.2  jdolecek 
    168  1.2.6.2  jdolecek 	/*
    169  1.2.6.2  jdolecek 	 * Initialize the chip.
    170  1.2.6.2  jdolecek 	 * Firstly, disable all VMEChip2 Interrupts
    171  1.2.6.2  jdolecek 	 */
    172  1.2.6.2  jdolecek 	reg = vme2_lcsr_read(sc, VME2LCSR_MISC_STATUS) & ~VME2_MISC_STATUS_MIEN;
    173  1.2.6.2  jdolecek 	vme2_lcsr_write(sc, VME2LCSR_MISC_STATUS, reg);
    174  1.2.6.2  jdolecek 	vme2_lcsr_write(sc, VME2LCSR_LOCAL_INTERRUPT_ENABLE, 0);
    175  1.2.6.2  jdolecek 	vme2_lcsr_write(sc, VME2LCSR_LOCAL_INTERRUPT_CLEAR,
    176  1.2.6.2  jdolecek 	    VME2_LOCAL_INTERRUPT_CLEAR_ALL);
    177  1.2.6.2  jdolecek 
    178  1.2.6.2  jdolecek 	/* Zap all the IRQ level registers */
    179  1.2.6.2  jdolecek 	for (i = 0; i < VME2_NUM_IL_REGS; i++)
    180  1.2.6.2  jdolecek 		vme2_lcsr_write(sc, VME2LCSR_INTERRUPT_LEVEL_BASE + (i * 4), 0);
    181  1.2.6.2  jdolecek 
    182  1.2.6.2  jdolecek 	/* Disable the tick timers */
    183  1.2.6.2  jdolecek 	reg = vme2_lcsr_read(sc, VME2LCSR_TIMER_CONTROL);
    184  1.2.6.2  jdolecek 	reg &= ~VME2_TIMER_CONTROL_EN(0);
    185  1.2.6.2  jdolecek 	reg &= ~VME2_TIMER_CONTROL_EN(1);
    186  1.2.6.2  jdolecek 	vme2_lcsr_write(sc, VME2LCSR_TIMER_CONTROL, reg);
    187  1.2.6.2  jdolecek 
    188  1.2.6.2  jdolecek 	/* Set the VMEChip2's vector base register to the required value */
    189  1.2.6.2  jdolecek 	reg = vme2_lcsr_read(sc, VME2LCSR_VECTOR_BASE);
    190  1.2.6.2  jdolecek 	reg &= ~VME2_VECTOR_BASE_MASK;
    191  1.2.6.2  jdolecek 	reg |= VME2_VECTOR_BASE_REG_VALUE;
    192  1.2.6.2  jdolecek 	vme2_lcsr_write(sc, VME2LCSR_VECTOR_BASE, reg);
    193  1.2.6.2  jdolecek 
    194  1.2.6.2  jdolecek 	/* Set the Master Interrupt Enable bit now */
    195  1.2.6.2  jdolecek 	reg = vme2_lcsr_read(sc, VME2LCSR_MISC_STATUS) | VME2_MISC_STATUS_MIEN;
    196  1.2.6.2  jdolecek 	vme2_lcsr_write(sc, VME2LCSR_MISC_STATUS, reg);
    197  1.2.6.2  jdolecek 
    198  1.2.6.2  jdolecek 	/* Allow the MD code the chance to do some initialising */
    199  1.2.6.2  jdolecek 	vmetwo_md_intr_init(sc);
    200  1.2.6.2  jdolecek 
    201  1.2.6.2  jdolecek #if defined(MVME167) || defined(MVME177)
    202  1.2.6.2  jdolecek #if defined(MVME162) || defined(MVME172)
    203  1.2.6.2  jdolecek 	if (machineid != MVME_162 && machineid != MVME_172)
    204  1.2.6.2  jdolecek #endif
    205  1.2.6.2  jdolecek 	{
    206  1.2.6.2  jdolecek 		/*
    207  1.2.6.2  jdolecek 		 * Let the NMI handler deal with level 7 ABORT switch
    208  1.2.6.2  jdolecek 		 * interrupts
    209  1.2.6.2  jdolecek 		 */
    210  1.2.6.2  jdolecek 		vmetwo_intr_establish(sc, 7, 7, VME2_VEC_ABORT, 1,
    211  1.2.6.2  jdolecek 		    nmihand, NULL, NULL);
    212  1.2.6.2  jdolecek 	}
    213  1.2.6.2  jdolecek #endif
    214  1.2.6.2  jdolecek 
    215  1.2.6.2  jdolecek 	/* Setup hardware assisted soft interrupts */
    216  1.2.6.2  jdolecek 	vmetwo_intr_establish(sc, 1, 1, VME2_VEC_SOFT0, 1,
    217  1.2.6.2  jdolecek 	    (int (*)(void *))softintr_dispatch, NULL, NULL);
    218  1.2.6.2  jdolecek 	_softintr_chipset_assert = vmetwo_softintr_assert;
    219  1.2.6.2  jdolecek }
    220  1.2.6.2  jdolecek 
    221  1.2.6.2  jdolecek static int
    222  1.2.6.2  jdolecek vmetwo_local_isr_trampoline(arg)
    223  1.2.6.2  jdolecek 	void *arg;
    224  1.2.6.2  jdolecek {
    225  1.2.6.2  jdolecek 	struct vme_two_handler *isr;
    226  1.2.6.2  jdolecek 	int vec;
    227  1.2.6.2  jdolecek 
    228  1.2.6.2  jdolecek 	vec = (int) arg;	/* 0x08 <= vec <= 0x1f */
    229  1.2.6.2  jdolecek 
    230  1.2.6.2  jdolecek 	/* Clear the interrupt source */
    231  1.2.6.2  jdolecek 	vme2_lcsr_write(vmetwo_sc, VME2LCSR_LOCAL_INTERRUPT_CLEAR,
    232  1.2.6.2  jdolecek 	    VME2_LOCAL_INTERRUPT(vec));
    233  1.2.6.2  jdolecek 
    234  1.2.6.2  jdolecek 	isr = &vme_two_handlers[vec - VME2_VECTOR_LOCAL_OFFSET];
    235  1.2.6.2  jdolecek 	if (isr->isr_hand)
    236  1.2.6.2  jdolecek 		(void) (*isr->isr_hand) (isr->isr_arg);
    237  1.2.6.2  jdolecek 	else
    238  1.2.6.2  jdolecek 		printf("vmetwo: Spurious local interrupt, vector 0x%x\n", vec);
    239  1.2.6.2  jdolecek 
    240  1.2.6.2  jdolecek 	return (1);
    241  1.2.6.2  jdolecek }
    242  1.2.6.2  jdolecek 
    243  1.2.6.2  jdolecek void
    244  1.2.6.2  jdolecek vmetwo_local_intr_establish(pri, vec, hand, arg, evcnt)
    245  1.2.6.2  jdolecek 	int pri, vec;
    246  1.2.6.2  jdolecek 	int (*hand)(void *);
    247  1.2.6.2  jdolecek 	void *arg;
    248  1.2.6.2  jdolecek 	struct evcnt *evcnt;
    249  1.2.6.2  jdolecek {
    250  1.2.6.2  jdolecek 
    251  1.2.6.2  jdolecek 	vmetwo_intr_establish(vmetwo_sc, pri, pri, vec, 1, hand, arg, evcnt);
    252  1.2.6.2  jdolecek }
    253  1.2.6.2  jdolecek 
    254  1.2.6.2  jdolecek /* ARGSUSED */
    255  1.2.6.2  jdolecek void
    256  1.2.6.2  jdolecek vmetwo_intr_establish(csc, prior, lvl, vec, first, hand, arg, evcnt)
    257  1.2.6.2  jdolecek 	void *csc;
    258  1.2.6.2  jdolecek 	int prior, lvl, vec, first;
    259  1.2.6.2  jdolecek 	int (*hand)(void *);
    260  1.2.6.2  jdolecek 	void *arg;
    261  1.2.6.2  jdolecek 	struct evcnt *evcnt;
    262  1.2.6.2  jdolecek {
    263  1.2.6.2  jdolecek 	struct vmetwo_softc *sc = csc;
    264  1.2.6.2  jdolecek 	u_int32_t reg;
    265  1.2.6.2  jdolecek 	int bitoff;
    266  1.2.6.2  jdolecek 	int iloffset, ilshift;
    267  1.2.6.2  jdolecek 	int s;
    268  1.2.6.2  jdolecek 
    269  1.2.6.2  jdolecek 	s = splhigh();
    270  1.2.6.2  jdolecek 
    271  1.2.6.2  jdolecek #if NVMETWO > 0
    272  1.2.6.2  jdolecek 	/*
    273  1.2.6.2  jdolecek 	 * Sort out interrupts generated locally by the VMEChip2 from
    274  1.2.6.2  jdolecek 	 * those generated by VMEbus devices...
    275  1.2.6.2  jdolecek 	 */
    276  1.2.6.2  jdolecek 	if (vec >= VME2_VECTOR_LOCAL_MIN && vec <= VME2_VECTOR_LOCAL_MAX) {
    277  1.2.6.2  jdolecek #endif
    278  1.2.6.2  jdolecek 		/*
    279  1.2.6.2  jdolecek 		 * Local interrupts need to be bounced through some
    280  1.2.6.2  jdolecek 		 * trampoline code which acknowledges/clears them.
    281  1.2.6.2  jdolecek 		 */
    282  1.2.6.2  jdolecek 		vme_two_handlers[vec - VME2_VECTOR_LOCAL_MIN].isr_hand = hand;
    283  1.2.6.2  jdolecek 		vme_two_handlers[vec - VME2_VECTOR_LOCAL_MIN].isr_arg = arg;
    284  1.2.6.2  jdolecek 		hand = vmetwo_local_isr_trampoline;
    285  1.2.6.2  jdolecek 		arg = (void *) (vec - VME2_VECTOR_BASE);
    286  1.2.6.2  jdolecek 
    287  1.2.6.2  jdolecek 		/*
    288  1.2.6.2  jdolecek 		 * Interrupt enable/clear bit offset is 0x08 - 0x1f
    289  1.2.6.2  jdolecek 		 */
    290  1.2.6.2  jdolecek 		bitoff = vec - VME2_VECTOR_BASE;
    291  1.2.6.2  jdolecek #if NVMETWO > 0
    292  1.2.6.2  jdolecek 		first = 1;	/* Force the interrupt to be enabled */
    293  1.2.6.2  jdolecek 	} else {
    294  1.2.6.2  jdolecek 		/*
    295  1.2.6.2  jdolecek 		 * Interrupts originating from the VMEbus are
    296  1.2.6.2  jdolecek 		 * controlled by an offset of 0x00 - 0x07
    297  1.2.6.2  jdolecek 		 */
    298  1.2.6.2  jdolecek 		bitoff = lvl - 1;
    299  1.2.6.2  jdolecek 	}
    300  1.2.6.2  jdolecek #endif
    301  1.2.6.2  jdolecek 
    302  1.2.6.2  jdolecek 	/* Hook the interrupt */
    303  1.2.6.2  jdolecek 	(*sc->sc_isrlink)(sc->sc_isrcookie, hand, arg, prior, vec, evcnt);
    304  1.2.6.2  jdolecek 
    305  1.2.6.2  jdolecek 	/*
    306  1.2.6.2  jdolecek 	 * Do we need to tell the VMEChip2 to let the interrupt through?
    307  1.2.6.2  jdolecek 	 * (This is always true for locally-generated interrupts, but only
    308  1.2.6.2  jdolecek 	 * needs doing once for each VMEbus interrupt level which is hooked)
    309  1.2.6.2  jdolecek 	 */
    310  1.2.6.2  jdolecek #if NVMETWO > 0
    311  1.2.6.2  jdolecek 	if (first) {
    312  1.2.6.2  jdolecek 		if (evcnt)
    313  1.2.6.2  jdolecek 			evcnt_attach_dynamic(evcnt, EVCNT_TYPE_INTR,
    314  1.2.6.2  jdolecek 			    (*sc->sc_isrevcnt)(sc->sc_isrcookie, prior),
    315  1.2.6.2  jdolecek 			    sc->sc_mvmebus.sc_dev.dv_xname,
    316  1.2.6.2  jdolecek 			    mvmebus_irq_name[lvl]);
    317  1.2.6.2  jdolecek #endif
    318  1.2.6.2  jdolecek 		iloffset = VME2_ILOFFSET_FROM_VECTOR(bitoff) +
    319  1.2.6.2  jdolecek 		    VME2LCSR_INTERRUPT_LEVEL_BASE;
    320  1.2.6.2  jdolecek 		ilshift = VME2_ILSHIFT_FROM_VECTOR(bitoff);
    321  1.2.6.2  jdolecek 
    322  1.2.6.2  jdolecek 		/* Program the specified interrupt to signal at 'prior' */
    323  1.2.6.2  jdolecek 		reg = vme2_lcsr_read(sc, iloffset);
    324  1.2.6.2  jdolecek 		reg &= ~(VME2_INTERRUPT_LEVEL_MASK << ilshift);
    325  1.2.6.2  jdolecek 		reg |= (prior << ilshift);
    326  1.2.6.2  jdolecek 		vme2_lcsr_write(sc, iloffset, reg);
    327  1.2.6.2  jdolecek 
    328  1.2.6.2  jdolecek 		/* Clear it */
    329  1.2.6.2  jdolecek 		vme2_lcsr_write(sc, VME2LCSR_LOCAL_INTERRUPT_CLEAR,
    330  1.2.6.2  jdolecek 		    VME2_LOCAL_INTERRUPT(bitoff));
    331  1.2.6.2  jdolecek 
    332  1.2.6.2  jdolecek 		/* Enable it. */
    333  1.2.6.2  jdolecek 		reg = vme2_lcsr_read(sc, VME2LCSR_LOCAL_INTERRUPT_ENABLE);
    334  1.2.6.2  jdolecek 		reg |= VME2_LOCAL_INTERRUPT(bitoff);
    335  1.2.6.2  jdolecek 		vme2_lcsr_write(sc, VME2LCSR_LOCAL_INTERRUPT_ENABLE, reg);
    336  1.2.6.2  jdolecek #if NVMETWO > 0
    337  1.2.6.2  jdolecek 	}
    338  1.2.6.2  jdolecek #ifdef DIAGNOSTIC
    339  1.2.6.2  jdolecek 	else {
    340  1.2.6.2  jdolecek 		/* Verify the interrupt priority is the same */
    341  1.2.6.2  jdolecek 		iloffset = VME2_ILOFFSET_FROM_VECTOR(bitoff) +
    342  1.2.6.2  jdolecek 		    VME2LCSR_INTERRUPT_LEVEL_BASE;
    343  1.2.6.2  jdolecek 		ilshift = VME2_ILSHIFT_FROM_VECTOR(bitoff);
    344  1.2.6.2  jdolecek 
    345  1.2.6.2  jdolecek 		reg = vme2_lcsr_read(sc, iloffset);
    346  1.2.6.2  jdolecek 		reg &= (VME2_INTERRUPT_LEVEL_MASK << ilshift);
    347  1.2.6.2  jdolecek 
    348  1.2.6.2  jdolecek 		if ((prior << ilshift) != reg)
    349  1.2.6.2  jdolecek 			panic("vmetwo_intr_establish: priority mismatch!");
    350  1.2.6.2  jdolecek 	}
    351  1.2.6.2  jdolecek #endif
    352  1.2.6.2  jdolecek #endif
    353  1.2.6.2  jdolecek 	splx(s);
    354  1.2.6.2  jdolecek }
    355  1.2.6.2  jdolecek 
    356  1.2.6.2  jdolecek void
    357  1.2.6.2  jdolecek vmetwo_intr_disestablish(csc, lvl, vec, last, evcnt)
    358  1.2.6.2  jdolecek 	void *csc;
    359  1.2.6.2  jdolecek 	int lvl, vec, last;
    360  1.2.6.2  jdolecek 	struct evcnt *evcnt;
    361  1.2.6.2  jdolecek {
    362  1.2.6.2  jdolecek 	struct vmetwo_softc *sc = csc;
    363  1.2.6.2  jdolecek 	u_int32_t reg;
    364  1.2.6.2  jdolecek 	int iloffset, ilshift;
    365  1.2.6.2  jdolecek 	int bitoff;
    366  1.2.6.2  jdolecek 	int s;
    367  1.2.6.2  jdolecek 
    368  1.2.6.2  jdolecek 	s = splhigh();
    369  1.2.6.2  jdolecek 
    370  1.2.6.2  jdolecek #if NVMETWO > 0
    371  1.2.6.2  jdolecek 	/*
    372  1.2.6.2  jdolecek 	 * Sort out interrupts generated locally by the VMEChip2 from
    373  1.2.6.2  jdolecek 	 * those generated by VMEbus devices...
    374  1.2.6.2  jdolecek 	 */
    375  1.2.6.2  jdolecek 	if (vec >= VME2_VECTOR_LOCAL_MIN && vec <= VME2_VECTOR_LOCAL_MAX) {
    376  1.2.6.2  jdolecek #endif
    377  1.2.6.2  jdolecek 		/*
    378  1.2.6.2  jdolecek 		 * Interrupt enable/clear bit offset is 0x08 - 0x1f
    379  1.2.6.2  jdolecek 		 */
    380  1.2.6.2  jdolecek 		bitoff = vec - VME2_VECTOR_BASE;
    381  1.2.6.2  jdolecek 		vme_two_handlers[vec - VME2_VECTOR_LOCAL_MIN].isr_hand = NULL;
    382  1.2.6.2  jdolecek 		last = 1; /* Force the interrupt to be cleared */
    383  1.2.6.2  jdolecek #if NVMETWO > 0
    384  1.2.6.2  jdolecek 	} else {
    385  1.2.6.2  jdolecek 		/*
    386  1.2.6.2  jdolecek 		 * Interrupts originating from the VMEbus are
    387  1.2.6.2  jdolecek 		 * controlled by an offset of 0x00 - 0x07
    388  1.2.6.2  jdolecek 		 */
    389  1.2.6.2  jdolecek 		bitoff = lvl - 1;
    390  1.2.6.2  jdolecek 	}
    391  1.2.6.2  jdolecek #endif
    392  1.2.6.2  jdolecek 
    393  1.2.6.2  jdolecek 	/*
    394  1.2.6.2  jdolecek 	 * Do we need to tell the VMEChip2 to block the interrupt?
    395  1.2.6.2  jdolecek 	 * (This is always true for locally-generated interrupts, but only
    396  1.2.6.2  jdolecek 	 * needs doing once when the last VMEbus handler for any given level
    397  1.2.6.2  jdolecek 	 * has been unhooked.)
    398  1.2.6.2  jdolecek 	 */
    399  1.2.6.2  jdolecek 	if (last) {
    400  1.2.6.2  jdolecek 		iloffset = VME2_ILOFFSET_FROM_VECTOR(bitoff) +
    401  1.2.6.2  jdolecek 		    VME2LCSR_INTERRUPT_LEVEL_BASE;
    402  1.2.6.2  jdolecek 		ilshift = VME2_ILSHIFT_FROM_VECTOR(bitoff);
    403  1.2.6.2  jdolecek 
    404  1.2.6.2  jdolecek 		/* Disable it. */
    405  1.2.6.2  jdolecek 		reg = vme2_lcsr_read(sc, VME2LCSR_LOCAL_INTERRUPT_ENABLE);
    406  1.2.6.2  jdolecek 		reg &= ~VME2_LOCAL_INTERRUPT(bitoff);
    407  1.2.6.2  jdolecek 		vme2_lcsr_write(sc, VME2LCSR_LOCAL_INTERRUPT_ENABLE, reg);
    408  1.2.6.2  jdolecek 
    409  1.2.6.2  jdolecek 		/* Set the interrupt's level to zero */
    410  1.2.6.2  jdolecek 		reg = vme2_lcsr_read(sc, iloffset);
    411  1.2.6.2  jdolecek 		reg &= ~(VME2_INTERRUPT_LEVEL_MASK << ilshift);
    412  1.2.6.2  jdolecek 		vme2_lcsr_write(sc, iloffset, reg);
    413  1.2.6.2  jdolecek 
    414  1.2.6.2  jdolecek 		/* Clear it */
    415  1.2.6.2  jdolecek 		vme2_lcsr_write(sc, VME2LCSR_LOCAL_INTERRUPT_CLEAR,
    416  1.2.6.2  jdolecek 		    VME2_LOCAL_INTERRUPT(vec));
    417  1.2.6.2  jdolecek 
    418  1.2.6.2  jdolecek 		if (evcnt)
    419  1.2.6.2  jdolecek 			evcnt_detach(evcnt);
    420  1.2.6.2  jdolecek 	}
    421  1.2.6.2  jdolecek 	/* Un-hook it */
    422  1.2.6.2  jdolecek 	(*sc->sc_isrunlink)(sc->sc_isrcookie, vec);
    423  1.2.6.2  jdolecek 
    424  1.2.6.2  jdolecek 	splx(s);
    425  1.2.6.2  jdolecek }
    426  1.2.6.2  jdolecek 
    427  1.2.6.2  jdolecek static void
    428  1.2.6.2  jdolecek vmetwo_softintr_assert(void)
    429  1.2.6.2  jdolecek {
    430  1.2.6.2  jdolecek 
    431  1.2.6.2  jdolecek 	vme2_lcsr_write(vmetwo_sc, VME2LCSR_SOFTINT_SET, VME2_SOFTINT_SET(0));
    432  1.2.6.2  jdolecek }
    433