Home | History | Annotate | Line # | Download | only in include
      1  1.85   thorpej /* $NetBSD: intr.h,v 1.85 2021/07/16 19:02:22 thorpej 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  *
     19  1.26   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.26   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.26   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.26   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.26   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.26   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.26   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.26   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.26   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.26   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.26   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     30  1.26   thorpej  */
     31   1.1       cgd 
     32   1.1       cgd /*
     33   1.6       cgd  * Copyright (c) 1997 Christopher G. Demetriou.  All rights reserved.
     34   1.1       cgd  * Copyright (c) 1996 Carnegie-Mellon University.
     35   1.1       cgd  * All rights reserved.
     36   1.1       cgd  *
     37   1.1       cgd  * Author: Chris G. Demetriou
     38   1.1       cgd  *
     39   1.1       cgd  * Permission to use, copy, modify and distribute this software and
     40   1.1       cgd  * its documentation is hereby granted, provided that both the copyright
     41   1.1       cgd  * notice and this permission notice appear in all copies of the
     42   1.1       cgd  * software, derivative works or modified versions, and any portions
     43   1.1       cgd  * thereof, and that both notices appear in supporting documentation.
     44   1.1       cgd  *
     45   1.1       cgd  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     46   1.1       cgd  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     47   1.1       cgd  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     48   1.1       cgd  *
     49   1.1       cgd  * Carnegie Mellon requests users of this software to return to
     50   1.1       cgd  *
     51   1.1       cgd  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     52   1.1       cgd  *  School of Computer Science
     53   1.1       cgd  *  Carnegie Mellon University
     54   1.1       cgd  *  Pittsburgh PA 15213-3890
     55   1.1       cgd  *
     56   1.1       cgd  * any improvements or extensions that they make and grant Carnegie the
     57   1.1       cgd  * rights to redistribute these changes.
     58   1.1       cgd  */
     59   1.1       cgd 
     60   1.2       cgd #ifndef _ALPHA_INTR_H_
     61   1.2       cgd #define _ALPHA_INTR_H_
     62   1.2       cgd 
     63  1.63        ad #include <sys/evcnt.h>
     64  1.76   thorpej #include <machine/alpha_cpu.h>
     65  1.58        ad 
     66  1.26   thorpej /*
     67  1.49   thorpej  * The Alpha System Control Block.  This is 8k long, and you get
     68  1.49   thorpej  * 16 bytes per vector (i.e. the vector numbers are spaced 16
     69  1.49   thorpej  * apart).
     70  1.49   thorpej  *
     71  1.49   thorpej  * This is sort of a "shadow" SCB -- rather than the CPU jumping
     72  1.49   thorpej  * to (SCBaddr + (16 * vector)), like it does on the VAX, we get
     73  1.49   thorpej  * a vector number in a1.  We use the SCB to look up a routine/arg
     74  1.49   thorpej  * and jump to it.
     75  1.49   thorpej  *
     76  1.49   thorpej  * Since we use the SCB only for I/O interrupts, we make it shorter
     77  1.49   thorpej  * than normal, starting it at vector 0x800 (the start of the I/O
     78  1.49   thorpej  * interrupt vectors).
     79  1.49   thorpej  */
     80  1.49   thorpej #define	SCB_IOVECBASE	0x0800
     81  1.49   thorpej #define	SCB_VECSIZE	0x0010
     82  1.49   thorpej #define	SCB_SIZE	0x2000
     83  1.49   thorpej 
     84  1.49   thorpej #define	SCB_VECTOIDX(x)	((x) >> 4)
     85  1.49   thorpej #define	SCB_IDXTOVEC(x)	((x) << 4)
     86  1.49   thorpej 
     87  1.49   thorpej #define	SCB_NIOVECS	SCB_VECTOIDX(SCB_SIZE - SCB_IOVECBASE)
     88  1.49   thorpej 
     89  1.70      matt struct scbvec {
     90  1.49   thorpej 	void	(*scb_func)(void *, u_long);
     91  1.49   thorpej 	void	*scb_arg;
     92  1.49   thorpej };
     93  1.49   thorpej 
     94  1.49   thorpej /*
     95  1.74   thorpej  * Alpha interrupts come in at one of 3 levels:
     96  1.26   thorpej  *
     97  1.26   thorpej  *	i/o level 1
     98  1.26   thorpej  *	i/o level 2
     99  1.26   thorpej  *	clock level
    100  1.26   thorpej  *
    101  1.26   thorpej  * However, since we do not have any way to know which hardware
    102  1.26   thorpej  * level a particular i/o interrupt comes in on, we have to
    103  1.74   thorpej  * whittle it down to 2.  In addition, there are 2 software interrupt
    104  1.74   thorpej  * levels available to system software.
    105  1.26   thorpej  */
    106  1.26   thorpej 
    107  1.74   thorpej #define	IPL_NONE	ALPHA_PSL_IPL_0
    108  1.74   thorpej #define	IPL_SOFTCLOCK	ALPHA_PSL_IPL_SOFT_LO
    109  1.74   thorpej #define	IPL_SOFTBIO	ALPHA_PSL_IPL_SOFT_LO
    110  1.76   thorpej #ifdef __HAVE_FAST_SOFTINTS
    111  1.76   thorpej #define	IPL_SOFTNET	ALPHA_PSL_IPL_SOFT_HI
    112  1.76   thorpej #define	IPL_SOFTSERIAL	ALPHA_PSL_IPL_SOFT_HI
    113  1.76   thorpej #else
    114  1.76   thorpej #define	IPL_SOFTNET	ALPHA_PSL_IPL_SOFT_LO
    115  1.76   thorpej #define	IPL_SOFTSERIAL	ALPHA_PSL_IPL_SOFT_LO
    116  1.76   thorpej #endif /* __HAVE_FAST_SOFTINTS */
    117  1.74   thorpej #define	IPL_VM		ALPHA_PSL_IPL_IO_HI
    118  1.74   thorpej #define	IPL_SCHED	ALPHA_PSL_IPL_CLOCK
    119  1.74   thorpej #define	IPL_HIGH	ALPHA_PSL_IPL_HIGH
    120  1.56      yamt 
    121  1.78   thorpej #define	SOFTINT_CLOCK_MASK	__BIT(SOFTINT_CLOCK)
    122  1.78   thorpej #define	SOFTINT_BIO_MASK	__BIT(SOFTINT_BIO)
    123  1.78   thorpej #define	SOFTINT_NET_MASK	__BIT(SOFTINT_NET)
    124  1.78   thorpej #define	SOFTINT_SERIAL_MASK	__BIT(SOFTINT_SERIAL)
    125  1.78   thorpej 
    126  1.78   thorpej #define	ALPHA_IPL1_SOFTINTS	(SOFTINT_CLOCK_MASK | SOFTINT_BIO_MASK)
    127  1.78   thorpej #define	ALPHA_IPL2_SOFTINTS	(SOFTINT_NET_MASK | SOFTINT_SERIAL_MASK)
    128  1.78   thorpej 
    129  1.78   thorpej #define	ALPHA_ALL_SOFTINTS	(ALPHA_IPL1_SOFTINTS | ALPHA_IPL2_SOFTINTS)
    130  1.78   thorpej 
    131  1.56      yamt typedef int ipl_t;
    132  1.56      yamt typedef struct {
    133  1.57        ad 	uint8_t _psl;
    134  1.56      yamt } ipl_cookie_t;
    135  1.56      yamt 
    136  1.74   thorpej static inline ipl_cookie_t
    137  1.74   thorpej makeiplcookie(ipl_t ipl)
    138  1.74   thorpej {
    139  1.74   thorpej 	return (ipl_cookie_t){._psl = (uint8_t)ipl};
    140  1.74   thorpej }
    141  1.52      yamt 
    142   1.3       cgd #define	IST_UNUSABLE	-1	/* interrupt cannot be used */
    143   1.1       cgd #define	IST_NONE	0	/* none (dummy) */
    144   1.1       cgd #define	IST_PULSE	1	/* pulsed */
    145   1.1       cgd #define	IST_EDGE	2	/* edge-triggered */
    146   1.1       cgd #define	IST_LEVEL	3	/* level-triggered */
    147  1.17   thorpej 
    148  1.11    mjacob #ifdef	_KERNEL
    149   1.2       cgd 
    150  1.75   thorpej /* IPL-lowering/restoring macros */
    151  1.75   thorpej void	spllower(int);
    152  1.44   thorpej 
    153  1.75   thorpej #define	splx(s)		spllower(s)
    154  1.75   thorpej #define	spl0()		spllower(ALPHA_PSL_IPL_0)
    155  1.44   thorpej 
    156   1.8       cgd /* IPL-raising functions/macros */
    157  1.55     perry static __inline int
    158  1.27   thorpej _splraise(int s)
    159   1.8       cgd {
    160  1.85   thorpej 	int cur = (int)alpha_pal_rdps();
    161  1.72  christos 	return (s > cur ? (int)alpha_pal_swpipl(s) : cur);
    162   1.8       cgd }
    163  1.51      yamt 
    164  1.56      yamt #define	splraiseipl(icookie)	_splraise((icookie)._psl)
    165  1.51      yamt 
    166  1.52      yamt #include <sys/spl.h>
    167   1.2       cgd 
    168  1.76   thorpej /* Fast soft interrupt dispatch. */
    169  1.76   thorpej void	alpha_softint_dispatch(int);
    170  1.76   thorpej void	alpha_softint_switchto(struct lwp *, int, struct lwp *);
    171  1.76   thorpej 
    172   1.2       cgd /*
    173  1.19   thorpej  * Interprocessor interrupts.  In order how we want them processed.
    174  1.18   thorpej  */
    175  1.47   thorpej #define	ALPHA_IPI_HALT			(1UL << 0)
    176  1.83   thorpej #define	ALPHA_IPI_PRIMARY_CC		(1UL << 1)
    177  1.48   thorpej #define	ALPHA_IPI_SHOOTDOWN		(1UL << 2)
    178  1.73   thorpej #define	ALPHA_IPI_AST			(1UL << 3)
    179  1.73   thorpej #define	ALPHA_IPI_PAUSE			(1UL << 4)
    180  1.73   thorpej #define	ALPHA_IPI_XCALL			(1UL << 5)
    181  1.73   thorpej #define	ALPHA_IPI_GENERIC		(1UL << 6)
    182  1.19   thorpej 
    183  1.73   thorpej #define	ALPHA_NIPIS			7	/* must not exceed 64 */
    184  1.18   thorpej 
    185  1.35   thorpej struct cpu_info;
    186  1.37   thorpej struct trapframe;
    187  1.35   thorpej 
    188  1.35   thorpej void	alpha_ipi_init(struct cpu_info *);
    189  1.37   thorpej void	alpha_ipi_process(struct cpu_info *, struct trapframe *);
    190  1.27   thorpej void	alpha_send_ipi(unsigned long, unsigned long);
    191  1.27   thorpej void	alpha_broadcast_ipi(unsigned long);
    192  1.31   thorpej void	alpha_multicast_ipi(unsigned long, unsigned long);
    193   1.3       cgd 
    194   1.3       cgd /*
    195   1.3       cgd  * Alpha shared-interrupt-line common code.
    196   1.3       cgd  */
    197   1.3       cgd 
    198  1.79   thorpej #define	ALPHA_INTR_MPSAFE		0x01
    199  1.79   thorpej 
    200   1.3       cgd struct alpha_shared_intrhand {
    201   1.3       cgd 	TAILQ_ENTRY(alpha_shared_intrhand)
    202   1.3       cgd 		ih_q;
    203  1.24   thorpej 	struct alpha_shared_intr *ih_intrhead;
    204  1.27   thorpej 	int	(*ih_fn)(void *);
    205   1.3       cgd 	void	*ih_arg;
    206  1.80   thorpej 	int	(*ih_real_fn)(void *);
    207  1.80   thorpej 	void	*ih_real_arg;
    208   1.3       cgd 	int	ih_level;
    209  1.81   thorpej 	int	ih_type;
    210  1.15   thorpej 	unsigned int ih_num;
    211   1.3       cgd };
    212   1.3       cgd 
    213   1.3       cgd struct alpha_shared_intr {
    214   1.3       cgd 	TAILQ_HEAD(,alpha_shared_intrhand)
    215   1.3       cgd 		intr_q;
    216  1.28   thorpej 	struct evcnt intr_evcnt;
    217  1.28   thorpej 	char	*intr_string;
    218  1.22   thorpej 	void	*intr_private;
    219  1.81   thorpej 	struct cpu_info *intr_cpu;
    220   1.3       cgd 	int	intr_sharetype;
    221   1.3       cgd 	int	intr_dfltsharetype;
    222   1.3       cgd 	int	intr_nstrays;
    223   1.3       cgd 	int	intr_maxstrays;
    224   1.3       cgd };
    225  1.12   thorpej 
    226  1.13   thorpej #define	ALPHA_SHARED_INTR_DISABLE(asi, num)				\
    227  1.13   thorpej 	((asi)[num].intr_maxstrays != 0 &&				\
    228  1.13   thorpej 	 (asi)[num].intr_nstrays == (asi)[num].intr_maxstrays)
    229  1.26   thorpej 
    230  1.84   thorpej struct alpha_shared_intr *alpha_shared_intr_alloc(unsigned int);
    231  1.27   thorpej int	alpha_shared_intr_dispatch(struct alpha_shared_intr *,
    232  1.27   thorpej 	    unsigned int);
    233  1.81   thorpej struct alpha_shared_intrhand *
    234  1.81   thorpej 	alpha_shared_intr_alloc_intrhand(struct alpha_shared_intr *,
    235  1.81   thorpej 	    unsigned int, int, int, int, int (*)(void *), void *,
    236  1.81   thorpej 	    const char *);
    237  1.81   thorpej void	alpha_shared_intr_free_intrhand(struct alpha_shared_intrhand *);
    238  1.81   thorpej bool	alpha_shared_intr_link(struct alpha_shared_intr *,
    239  1.81   thorpej 	    struct alpha_shared_intrhand *, const char *);
    240  1.81   thorpej void	alpha_shared_intr_unlink(struct alpha_shared_intr *,
    241  1.81   thorpej 	    struct alpha_shared_intrhand *, const char *);
    242  1.27   thorpej int	alpha_shared_intr_get_sharetype(struct alpha_shared_intr *,
    243  1.27   thorpej 	    unsigned int);
    244  1.27   thorpej int	alpha_shared_intr_isactive(struct alpha_shared_intr *,
    245  1.27   thorpej 	    unsigned int);
    246  1.49   thorpej int	alpha_shared_intr_firstactive(struct alpha_shared_intr *,
    247  1.49   thorpej 	    unsigned int);
    248  1.27   thorpej void	alpha_shared_intr_set_dfltsharetype(struct alpha_shared_intr *,
    249  1.27   thorpej 	    unsigned int, int);
    250  1.27   thorpej void	alpha_shared_intr_set_maxstrays(struct alpha_shared_intr *,
    251  1.27   thorpej 	    unsigned int, int);
    252  1.50   thorpej void	alpha_shared_intr_reset_strays(struct alpha_shared_intr *,
    253  1.50   thorpej 	    unsigned int);
    254  1.27   thorpej void	alpha_shared_intr_stray(struct alpha_shared_intr *, unsigned int,
    255  1.27   thorpej 	    const char *);
    256  1.27   thorpej void	alpha_shared_intr_set_private(struct alpha_shared_intr *,
    257  1.27   thorpej 	    unsigned int, void *);
    258  1.27   thorpej void	*alpha_shared_intr_get_private(struct alpha_shared_intr *,
    259  1.27   thorpej 	    unsigned int);
    260  1.81   thorpej void	alpha_shared_intr_set_cpu(struct alpha_shared_intr *,
    261  1.81   thorpej 	    unsigned int, struct cpu_info *ci);
    262  1.81   thorpej struct cpu_info	*
    263  1.81   thorpej 	alpha_shared_intr_get_cpu(struct alpha_shared_intr *,
    264  1.81   thorpej 	    unsigned int);
    265  1.84   thorpej void	alpha_shared_intr_set_string(struct alpha_shared_intr *,
    266  1.84   thorpej 	    unsigned int, char *);
    267  1.84   thorpej const char *alpha_shared_intr_string(struct alpha_shared_intr *,
    268  1.28   thorpej 	    unsigned int);
    269  1.28   thorpej struct evcnt *alpha_shared_intr_evcnt(struct alpha_shared_intr *,
    270  1.28   thorpej 	    unsigned int);
    271  1.28   thorpej 
    272  1.49   thorpej extern struct scbvec scb_iovectab[];
    273  1.82   thorpej extern void (*alpha_intr_redistribute)(void);
    274  1.49   thorpej 
    275  1.49   thorpej void	scb_init(void);
    276  1.79   thorpej void	scb_set(u_long, void (*)(void *, u_long), void *);
    277  1.49   thorpej u_long	scb_alloc(void (*)(void *, u_long), void *);
    278  1.49   thorpej void	scb_free(u_long);
    279  1.49   thorpej 
    280  1.49   thorpej #define	SCB_ALLOC_FAILED	((u_long) -1)
    281   1.2       cgd 
    282  1.17   thorpej #endif /* _KERNEL */
    283  1.17   thorpej #endif /* ! _ALPHA_INTR_H_ */
    284