Home | History | Annotate | Line # | Download | only in include
intr.h revision 1.55
      1  1.55    perry /* $NetBSD: intr.h,v 1.55 2006/02/16 20:17:13 perry Exp $ */
      2  1.26  thorpej 
      3  1.26  thorpej /*-
      4  1.51     yamt  * Copyright (c) 2000, 2001, 2002 The NetBSD Foundation, Inc.
      5  1.26  thorpej  * All rights reserved.
      6  1.26  thorpej  *
      7  1.26  thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.26  thorpej  * by Jason R. Thorpe.
      9  1.26  thorpej  *
     10  1.26  thorpej  * Redistribution and use in source and binary forms, with or without
     11  1.26  thorpej  * modification, are permitted provided that the following conditions
     12  1.26  thorpej  * are met:
     13  1.26  thorpej  * 1. Redistributions of source code must retain the above copyright
     14  1.26  thorpej  *    notice, this list of conditions and the following disclaimer.
     15  1.26  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.26  thorpej  *    notice, this list of conditions and the following disclaimer in the
     17  1.26  thorpej  *    documentation and/or other materials provided with the distribution.
     18  1.26  thorpej  * 3. All advertising materials mentioning features or use of this software
     19  1.26  thorpej  *    must display the following acknowledgement:
     20  1.26  thorpej  *	This product includes software developed by the NetBSD
     21  1.26  thorpej  *	Foundation, Inc. and its contributors.
     22  1.26  thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.26  thorpej  *    contributors may be used to endorse or promote products derived
     24  1.26  thorpej  *    from this software without specific prior written permission.
     25  1.26  thorpej  *
     26  1.26  thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.26  thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.26  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.26  thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.26  thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.26  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.26  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.26  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.26  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.26  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.26  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37  1.26  thorpej  */
     38   1.1      cgd 
     39   1.1      cgd /*
     40   1.6      cgd  * Copyright (c) 1997 Christopher G. Demetriou.  All rights reserved.
     41   1.1      cgd  * Copyright (c) 1996 Carnegie-Mellon University.
     42   1.1      cgd  * All rights reserved.
     43   1.1      cgd  *
     44   1.1      cgd  * Author: Chris G. Demetriou
     45   1.1      cgd  *
     46   1.1      cgd  * Permission to use, copy, modify and distribute this software and
     47   1.1      cgd  * its documentation is hereby granted, provided that both the copyright
     48   1.1      cgd  * notice and this permission notice appear in all copies of the
     49   1.1      cgd  * software, derivative works or modified versions, and any portions
     50   1.1      cgd  * thereof, and that both notices appear in supporting documentation.
     51   1.1      cgd  *
     52   1.1      cgd  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     53   1.1      cgd  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     54   1.1      cgd  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     55   1.1      cgd  *
     56   1.1      cgd  * Carnegie Mellon requests users of this software to return to
     57   1.1      cgd  *
     58   1.1      cgd  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     59   1.1      cgd  *  School of Computer Science
     60   1.1      cgd  *  Carnegie Mellon University
     61   1.1      cgd  *  Pittsburgh PA 15213-3890
     62   1.1      cgd  *
     63   1.1      cgd  * any improvements or extensions that they make and grant Carnegie the
     64   1.1      cgd  * rights to redistribute these changes.
     65   1.1      cgd  */
     66   1.1      cgd 
     67   1.2      cgd #ifndef _ALPHA_INTR_H_
     68   1.2      cgd #define _ALPHA_INTR_H_
     69   1.2      cgd 
     70  1.28  thorpej #include <sys/device.h>
     71  1.26  thorpej #include <sys/lock.h>
     72   1.3      cgd #include <sys/queue.h>
     73  1.23  thorpej #include <machine/atomic.h>
     74   1.3      cgd 
     75  1.26  thorpej /*
     76  1.49  thorpej  * The Alpha System Control Block.  This is 8k long, and you get
     77  1.49  thorpej  * 16 bytes per vector (i.e. the vector numbers are spaced 16
     78  1.49  thorpej  * apart).
     79  1.49  thorpej  *
     80  1.49  thorpej  * This is sort of a "shadow" SCB -- rather than the CPU jumping
     81  1.49  thorpej  * to (SCBaddr + (16 * vector)), like it does on the VAX, we get
     82  1.49  thorpej  * a vector number in a1.  We use the SCB to look up a routine/arg
     83  1.49  thorpej  * and jump to it.
     84  1.49  thorpej  *
     85  1.49  thorpej  * Since we use the SCB only for I/O interrupts, we make it shorter
     86  1.49  thorpej  * than normal, starting it at vector 0x800 (the start of the I/O
     87  1.49  thorpej  * interrupt vectors).
     88  1.49  thorpej  */
     89  1.49  thorpej #define	SCB_IOVECBASE	0x0800
     90  1.49  thorpej #define	SCB_VECSIZE	0x0010
     91  1.49  thorpej #define	SCB_SIZE	0x2000
     92  1.49  thorpej 
     93  1.49  thorpej #define	SCB_VECTOIDX(x)	((x) >> 4)
     94  1.49  thorpej #define	SCB_IDXTOVEC(x)	((x) << 4)
     95  1.49  thorpej 
     96  1.49  thorpej #define	SCB_NIOVECS	SCB_VECTOIDX(SCB_SIZE - SCB_IOVECBASE)
     97  1.49  thorpej 
     98  1.49  thorpej struct scbvec {
     99  1.49  thorpej 	void	(*scb_func)(void *, u_long);
    100  1.49  thorpej 	void	*scb_arg;
    101  1.49  thorpej };
    102  1.49  thorpej 
    103  1.49  thorpej /*
    104  1.26  thorpej  * Alpha interrupts come in at one of 4 levels:
    105  1.26  thorpej  *
    106  1.26  thorpej  *	software interrupt level
    107  1.26  thorpej  *	i/o level 1
    108  1.26  thorpej  *	i/o level 2
    109  1.26  thorpej  *	clock level
    110  1.26  thorpej  *
    111  1.26  thorpej  * However, since we do not have any way to know which hardware
    112  1.26  thorpej  * level a particular i/o interrupt comes in on, we have to
    113  1.26  thorpej  * whittle it down to 3.
    114  1.26  thorpej  */
    115  1.26  thorpej 
    116  1.51     yamt #define	IPL_NONE	ALPHA_PSL_IPL_0	   /* no interrupt level */
    117  1.51     yamt #define	IPL_SOFT	ALPHA_PSL_IPL_SOFT /* generic software interrupts */
    118  1.51     yamt #define	IPL_SOFTCLOCK	IPL_SOFT	   /* clock software interrupts */
    119  1.51     yamt #define	IPL_SOFTNET	IPL_SOFT	   /* network software interrupts */
    120  1.51     yamt #define	IPL_SOFTSERIAL	IPL_SOFT	   /* serial software interrupts */
    121  1.51     yamt #define	IPL_BIO		ALPHA_PSL_IPL_IO   /* block I/O interrupts */
    122  1.51     yamt #define	IPL_NET		ALPHA_PSL_IPL_IO   /* network interrupts */
    123  1.51     yamt #define	IPL_TTY		ALPHA_PSL_IPL_IO   /* terminal interrupts */
    124  1.52     yamt #define	IPL_LPT		IPL_TTY
    125  1.51     yamt #define	IPL_VM		ALPHA_PSL_IPL_IO   /* interrupts that can alloc mem */
    126  1.51     yamt #define	IPL_CLOCK	ALPHA_PSL_IPL_CLOCK/* clock interrupts */
    127  1.52     yamt #define	IPL_STATCLOCK	IPL_CLOCK
    128  1.51     yamt #define	IPL_HIGH	ALPHA_PSL_IPL_HIGH /* all interrupts */
    129  1.51     yamt #define	IPL_SERIAL	ALPHA_PSL_IPL_IO   /* serial interrupts */
    130  1.51     yamt 
    131  1.52     yamt #define	IPL_SCHED	IPL_HIGH
    132  1.52     yamt #define	IPL_LOCK	IPL_HIGH
    133  1.52     yamt #define	IPL_IPI		IPL_CLOCK	/* AARM, 5-2, II-B */
    134  1.52     yamt 
    135  1.51     yamt #define	SI_SOFTSERIAL	0
    136  1.51     yamt #define	SI_SOFTNET	1
    137  1.51     yamt #define	SI_SOFTCLOCK	2
    138  1.51     yamt #define	SI_SOFT		3
    139   1.1      cgd 
    140  1.51     yamt #define	SI_NQUEUES	4
    141  1.51     yamt 
    142  1.51     yamt #define	SI_QUEUENAMES {							\
    143  1.28  thorpej 	"serial",							\
    144  1.28  thorpej 	"net",								\
    145  1.28  thorpej 	"clock",							\
    146  1.28  thorpej 	"misc",								\
    147  1.28  thorpej }
    148  1.28  thorpej 
    149   1.3      cgd #define	IST_UNUSABLE	-1	/* interrupt cannot be used */
    150   1.1      cgd #define	IST_NONE	0	/* none (dummy) */
    151   1.1      cgd #define	IST_PULSE	1	/* pulsed */
    152   1.1      cgd #define	IST_EDGE	2	/* edge-triggered */
    153   1.1      cgd #define	IST_LEVEL	3	/* level-triggered */
    154  1.17  thorpej 
    155  1.11   mjacob #ifdef	_KERNEL
    156   1.2      cgd 
    157  1.44  thorpej /* Simulated software interrupt register. */
    158  1.54    perry extern volatile unsigned long ssir;
    159  1.44  thorpej 
    160   1.6      cgd /* IPL-lowering/restoring macros */
    161  1.29      cgd void	spl0(void);
    162  1.44  thorpej 
    163  1.55    perry static __inline void
    164  1.29      cgd splx(int s)
    165  1.29      cgd {
    166  1.44  thorpej 	if (s == ALPHA_PSL_IPL_0 && ssir != 0)
    167  1.29      cgd 		spl0();
    168  1.29      cgd 	else
    169  1.29      cgd 		alpha_pal_swpipl(s);
    170  1.29      cgd }
    171  1.29      cgd #define	spllowersoftclock()	((void)alpha_pal_swpipl(ALPHA_PSL_IPL_SOFT))
    172   1.6      cgd 
    173   1.8      cgd /* IPL-raising functions/macros */
    174  1.55    perry static __inline int
    175  1.27  thorpej _splraise(int s)
    176   1.8      cgd {
    177   1.8      cgd 	int cur = alpha_pal_rdps() & ALPHA_PSL_IPL_MASK;
    178   1.9      cgd 	return (s > cur ? alpha_pal_swpipl(s) : cur);
    179   1.8      cgd }
    180  1.51     yamt 
    181  1.51     yamt #define	splraiseipl(ipl)	_splraise((ipl))
    182  1.51     yamt 
    183  1.52     yamt #include <sys/spl.h>
    184   1.2      cgd 
    185   1.2      cgd /*
    186  1.19  thorpej  * Interprocessor interrupts.  In order how we want them processed.
    187  1.18  thorpej  */
    188  1.47  thorpej #define	ALPHA_IPI_HALT			(1UL << 0)
    189  1.47  thorpej #define	ALPHA_IPI_MICROSET		(1UL << 1)
    190  1.48  thorpej #define	ALPHA_IPI_SHOOTDOWN		(1UL << 2)
    191  1.48  thorpej #define	ALPHA_IPI_IMB			(1UL << 3)
    192  1.48  thorpej #define	ALPHA_IPI_AST			(1UL << 4)
    193  1.48  thorpej #define	ALPHA_IPI_SYNCH_FPU		(1UL << 5)
    194  1.48  thorpej #define	ALPHA_IPI_DISCARD_FPU		(1UL << 6)
    195  1.48  thorpej #define	ALPHA_IPI_PAUSE			(1UL << 7)
    196  1.48  thorpej #define	ALPHA_IPI_PMAP_REACTIVATE	(1UL << 8)
    197  1.19  thorpej 
    198  1.48  thorpej #define	ALPHA_NIPIS		9	/* must not exceed 64 */
    199  1.18  thorpej 
    200  1.35  thorpej struct cpu_info;
    201  1.37  thorpej struct trapframe;
    202  1.35  thorpej 
    203  1.35  thorpej void	alpha_ipi_init(struct cpu_info *);
    204  1.37  thorpej void	alpha_ipi_process(struct cpu_info *, struct trapframe *);
    205  1.27  thorpej void	alpha_send_ipi(unsigned long, unsigned long);
    206  1.27  thorpej void	alpha_broadcast_ipi(unsigned long);
    207  1.31  thorpej void	alpha_multicast_ipi(unsigned long, unsigned long);
    208   1.3      cgd 
    209   1.3      cgd /*
    210   1.3      cgd  * Alpha shared-interrupt-line common code.
    211   1.3      cgd  */
    212   1.3      cgd 
    213   1.3      cgd struct alpha_shared_intrhand {
    214   1.3      cgd 	TAILQ_ENTRY(alpha_shared_intrhand)
    215   1.3      cgd 		ih_q;
    216  1.24  thorpej 	struct alpha_shared_intr *ih_intrhead;
    217  1.27  thorpej 	int	(*ih_fn)(void *);
    218   1.3      cgd 	void	*ih_arg;
    219   1.3      cgd 	int	ih_level;
    220  1.15  thorpej 	unsigned int ih_num;
    221   1.3      cgd };
    222   1.3      cgd 
    223   1.3      cgd struct alpha_shared_intr {
    224   1.3      cgd 	TAILQ_HEAD(,alpha_shared_intrhand)
    225   1.3      cgd 		intr_q;
    226  1.28  thorpej 	struct evcnt intr_evcnt;
    227  1.28  thorpej 	char	*intr_string;
    228  1.22  thorpej 	void	*intr_private;
    229   1.3      cgd 	int	intr_sharetype;
    230   1.3      cgd 	int	intr_dfltsharetype;
    231   1.3      cgd 	int	intr_nstrays;
    232   1.3      cgd 	int	intr_maxstrays;
    233   1.3      cgd };
    234  1.12  thorpej 
    235  1.13  thorpej #define	ALPHA_SHARED_INTR_DISABLE(asi, num)				\
    236  1.13  thorpej 	((asi)[num].intr_maxstrays != 0 &&				\
    237  1.13  thorpej 	 (asi)[num].intr_nstrays == (asi)[num].intr_maxstrays)
    238  1.26  thorpej 
    239  1.26  thorpej #define	setsoft(x)	atomic_setbits_ulong(&ssir, 1 << (x))
    240  1.26  thorpej 
    241  1.26  thorpej struct alpha_soft_intrhand {
    242  1.42  thorpej 	TAILQ_ENTRY(alpha_soft_intrhand)
    243  1.26  thorpej 		sih_q;
    244  1.26  thorpej 	struct alpha_soft_intr *sih_intrhead;
    245  1.27  thorpej 	void	(*sih_fn)(void *);
    246  1.26  thorpej 	void	*sih_arg;
    247  1.26  thorpej 	int	sih_pending;
    248  1.26  thorpej };
    249  1.26  thorpej 
    250  1.26  thorpej struct alpha_soft_intr {
    251  1.42  thorpej 	TAILQ_HEAD(, alpha_soft_intrhand)
    252  1.26  thorpej 		softintr_q;
    253  1.28  thorpej 	struct evcnt softintr_evcnt;
    254  1.26  thorpej 	struct simplelock softintr_slock;
    255  1.51     yamt 	unsigned long softintr_siq;
    256  1.26  thorpej };
    257  1.26  thorpej 
    258  1.27  thorpej void	*softintr_establish(int, void (*)(void *), void *);
    259  1.27  thorpej void	softintr_disestablish(void *);
    260  1.27  thorpej void	softintr_init(void);
    261  1.27  thorpej void	softintr_dispatch(void);
    262  1.26  thorpej 
    263  1.26  thorpej #define	softintr_schedule(arg)						\
    264  1.26  thorpej do {									\
    265  1.26  thorpej 	struct alpha_soft_intrhand *__sih = (arg);			\
    266  1.42  thorpej 	struct alpha_soft_intr *__si = __sih->sih_intrhead;		\
    267  1.42  thorpej 	int __s;							\
    268  1.42  thorpej 									\
    269  1.43  thorpej 	__s = splhigh();						\
    270  1.43  thorpej 	simple_lock(&__si->softintr_slock);				\
    271  1.42  thorpej 	if (__sih->sih_pending == 0) {					\
    272  1.42  thorpej 		TAILQ_INSERT_TAIL(&__si->softintr_q, __sih, sih_q);	\
    273  1.42  thorpej 		__sih->sih_pending = 1;					\
    274  1.51     yamt 		setsoft(__si->softintr_siq);				\
    275  1.42  thorpej 	}								\
    276  1.43  thorpej 	simple_unlock(&__si->softintr_slock);				\
    277  1.43  thorpej 	splx(__s);							\
    278  1.26  thorpej } while (0)
    279  1.26  thorpej 
    280  1.26  thorpej /* XXX For legacy software interrupts. */
    281  1.26  thorpej extern struct alpha_soft_intrhand *softnet_intrhand;
    282  1.26  thorpej 
    283  1.26  thorpej #define	setsoftnet()	softintr_schedule(softnet_intrhand)
    284   1.3      cgd 
    285  1.28  thorpej struct alpha_shared_intr *alpha_shared_intr_alloc(unsigned int, unsigned int);
    286  1.27  thorpej int	alpha_shared_intr_dispatch(struct alpha_shared_intr *,
    287  1.27  thorpej 	    unsigned int);
    288  1.27  thorpej void	*alpha_shared_intr_establish(struct alpha_shared_intr *,
    289  1.27  thorpej 	    unsigned int, int, int, int (*)(void *), void *, const char *);
    290  1.27  thorpej void	alpha_shared_intr_disestablish(struct alpha_shared_intr *,
    291  1.27  thorpej 	    void *, const char *);
    292  1.27  thorpej int	alpha_shared_intr_get_sharetype(struct alpha_shared_intr *,
    293  1.27  thorpej 	    unsigned int);
    294  1.27  thorpej int	alpha_shared_intr_isactive(struct alpha_shared_intr *,
    295  1.27  thorpej 	    unsigned int);
    296  1.49  thorpej int	alpha_shared_intr_firstactive(struct alpha_shared_intr *,
    297  1.49  thorpej 	    unsigned int);
    298  1.27  thorpej void	alpha_shared_intr_set_dfltsharetype(struct alpha_shared_intr *,
    299  1.27  thorpej 	    unsigned int, int);
    300  1.27  thorpej void	alpha_shared_intr_set_maxstrays(struct alpha_shared_intr *,
    301  1.27  thorpej 	    unsigned int, int);
    302  1.50  thorpej void	alpha_shared_intr_reset_strays(struct alpha_shared_intr *,
    303  1.50  thorpej 	    unsigned int);
    304  1.27  thorpej void	alpha_shared_intr_stray(struct alpha_shared_intr *, unsigned int,
    305  1.27  thorpej 	    const char *);
    306  1.27  thorpej void	alpha_shared_intr_set_private(struct alpha_shared_intr *,
    307  1.27  thorpej 	    unsigned int, void *);
    308  1.27  thorpej void	*alpha_shared_intr_get_private(struct alpha_shared_intr *,
    309  1.27  thorpej 	    unsigned int);
    310  1.28  thorpej char	*alpha_shared_intr_string(struct alpha_shared_intr *,
    311  1.28  thorpej 	    unsigned int);
    312  1.28  thorpej struct evcnt *alpha_shared_intr_evcnt(struct alpha_shared_intr *,
    313  1.28  thorpej 	    unsigned int);
    314  1.28  thorpej 
    315  1.49  thorpej extern struct scbvec scb_iovectab[];
    316  1.49  thorpej 
    317  1.49  thorpej void	scb_init(void);
    318  1.49  thorpej void	scb_set(u_long, void (*)(void *, u_long), void *);
    319  1.49  thorpej u_long	scb_alloc(void (*)(void *, u_long), void *);
    320  1.49  thorpej void	scb_free(u_long);
    321  1.49  thorpej 
    322  1.49  thorpej #define	SCB_ALLOC_FAILED	((u_long) -1)
    323   1.2      cgd 
    324  1.17  thorpej #endif /* _KERNEL */
    325  1.17  thorpej #endif /* ! _ALPHA_INTR_H_ */
    326