Home | History | Annotate | Line # | Download | only in include
intr.h revision 1.7
      1  1.7     yamt /*	$NetBSD: intr.h,v 1.7 2006/12/21 15:55:24 yamt Exp $	*/
      2  1.2  thorpej 
      3  1.2  thorpej /*
      4  1.2  thorpej  * Copyright 2001 Wasabi Systems, Inc.
      5  1.2  thorpej  * All rights reserved.
      6  1.2  thorpej  *
      7  1.2  thorpej  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
      8  1.2  thorpej  *
      9  1.2  thorpej  * Redistribution and use in source and binary forms, with or without
     10  1.2  thorpej  * modification, are permitted provided that the following conditions
     11  1.2  thorpej  * are met:
     12  1.2  thorpej  * 1. Redistributions of source code must retain the above copyright
     13  1.2  thorpej  *    notice, this list of conditions and the following disclaimer.
     14  1.2  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.2  thorpej  *    notice, this list of conditions and the following disclaimer in the
     16  1.2  thorpej  *    documentation and/or other materials provided with the distribution.
     17  1.2  thorpej  * 3. All advertising materials mentioning features or use of this software
     18  1.2  thorpej  *    must display the following acknowledgement:
     19  1.2  thorpej  *	This product includes software developed for the NetBSD Project by
     20  1.2  thorpej  *	Wasabi Systems, Inc.
     21  1.2  thorpej  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.2  thorpej  *    or promote products derived from this software without specific prior
     23  1.2  thorpej  *    written permission.
     24  1.2  thorpej  *
     25  1.2  thorpej  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.2  thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.2  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.2  thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.2  thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.2  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.2  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.2  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.2  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.2  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.2  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     36  1.2  thorpej  */
     37  1.1     matt 
     38  1.1     matt /*
     39  1.1     matt  * Copyright (C) 1995-1997 Wolfgang Solfrank.
     40  1.1     matt  * Copyright (C) 1995-1997 TooLs GmbH.
     41  1.1     matt  * All rights reserved.
     42  1.1     matt  *
     43  1.1     matt  * Redistribution and use in source and binary forms, with or without
     44  1.1     matt  * modification, are permitted provided that the following conditions
     45  1.1     matt  * are met:
     46  1.1     matt  * 1. Redistributions of source code must retain the above copyright
     47  1.1     matt  *    notice, this list of conditions and the following disclaimer.
     48  1.1     matt  * 2. Redistributions in binary form must reproduce the above copyright
     49  1.1     matt  *    notice, this list of conditions and the following disclaimer in the
     50  1.1     matt  *    documentation and/or other materials provided with the distribution.
     51  1.1     matt  * 3. All advertising materials mentioning features or use of this software
     52  1.1     matt  *    must display the following acknowledgement:
     53  1.1     matt  *	This product includes software developed by TooLs GmbH.
     54  1.1     matt  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     55  1.1     matt  *    derived from this software without specific prior written permission.
     56  1.1     matt  *
     57  1.1     matt  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     58  1.1     matt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     59  1.1     matt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     60  1.1     matt  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     61  1.1     matt  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     62  1.1     matt  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     63  1.1     matt  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     64  1.1     matt  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     65  1.1     matt  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     66  1.1     matt  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     67  1.1     matt  */
     68  1.2  thorpej 
     69  1.1     matt #ifndef	_MACHINE_INTR_H_
     70  1.1     matt #define	_MACHINE_INTR_H_
     71  1.1     matt 
     72  1.2  thorpej /* Interrupt priority "levels". */
     73  1.2  thorpej #define	IPL_NONE	0	/* nothing */
     74  1.2  thorpej #define	IPL_SOFT	1	/* generic software interrupts */
     75  1.2  thorpej #define	IPL_SOFTCLOCK	2	/* software clock interrupt */
     76  1.2  thorpej #define	IPL_SOFTNET	3	/* software network interrupt */
     77  1.2  thorpej #define	IPL_BIO		4	/* block I/O */
     78  1.2  thorpej #define	IPL_NET		5	/* network */
     79  1.2  thorpej #define	IPL_SOFTSERIAL	6	/* software serial interrupt */
     80  1.2  thorpej #define	IPL_TTY		7	/* terminals */
     81  1.4  thorpej #define	IPL_VM		8	/* memory allocation */
     82  1.2  thorpej #define	IPL_AUDIO	9	/* audio device */
     83  1.2  thorpej #define	IPL_CLOCK	10	/* clock interrupt */
     84  1.7     yamt #define	IPL_STATCLOCK	IPL_CLOCK
     85  1.2  thorpej #define	IPL_HIGH	11	/* everything */
     86  1.7     yamt #define	IPL_SCHED	IPL_HIGH
     87  1.7     yamt #define	IPL_LOCK	IPL_HIGH
     88  1.2  thorpej #define	IPL_SERIAL	12	/* serial device */
     89  1.2  thorpej 
     90  1.2  thorpej #define	NIPL		13
     91  1.2  thorpej 
     92  1.2  thorpej /* Interrupt sharing types. */
     93  1.2  thorpej #define	IST_NONE	0	/* none */
     94  1.2  thorpej #define	IST_PULSE	1	/* pulsed */
     95  1.2  thorpej #define	IST_EDGE	2	/* edge-triggered */
     96  1.2  thorpej #define	IST_LEVEL	3	/* level-triggered */
     97  1.2  thorpej 
     98  1.2  thorpej #ifdef _KERNEL
     99  1.2  thorpej #ifndef _LOCORE
    100  1.5     matt #define	CLKF_BASEPRI(frame)	((frame)->pri == IPL_NONE)
    101  1.2  thorpej 
    102  1.2  thorpej struct clockframe;
    103  1.2  thorpej 
    104  1.3      chs extern int imask[];
    105  1.6   nonaka extern long ticks_per_intr;
    106  1.6   nonaka extern volatile u_long lasttb;
    107  1.3      chs 
    108  1.1     matt struct machvec {
    109  1.2  thorpej 	int (*mvec_splraise)(int);
    110  1.2  thorpej 	int (*mvec_spllower)(int);
    111  1.2  thorpej 	void (*mvec_splx)(int);
    112  1.2  thorpej 	void (*mvec_setsoft)(int);
    113  1.6   nonaka 	void (*mvec_clock_return)(struct clockframe *, int, long);
    114  1.2  thorpej 	void *(*mvec_intr_establish)(int, int, int, int (*)(void *), void *);
    115  1.2  thorpej 	void (*mvec_intr_disestablish)(void *);
    116  1.1     matt };
    117  1.1     matt 
    118  1.1     matt extern struct machvec machine_interface;
    119  1.1     matt 
    120  1.2  thorpej #define	_splraise(x)	((*machine_interface.mvec_splraise)(x))
    121  1.2  thorpej #define	_spllower(x)	((*machine_interface.mvec_spllower)(x))
    122  1.2  thorpej #define	splx(x)		((*machine_interface.mvec_splx)(x))
    123  1.2  thorpej #define	setsoftintr(x)	((*machine_interface.mvec_setsoft)(x))
    124  1.6   nonaka #define	clock_return(x, y, z) ((*machine_interface.mvec_clock_return)(x, y, z))
    125  1.2  thorpej #define	intr_establish(irq, lvl, ist, func, arg)			\
    126  1.2  thorpej 	((*machine_interface.mvec_intr_establish)((irq), (lvl), (ist),	\
    127  1.2  thorpej 	    (func), (arg)))
    128  1.2  thorpej #define	intr_disestablish(cookie)					\
    129  1.2  thorpej 	((*machine_interface.mvec_intr_disestablish)((cookie)))
    130  1.2  thorpej 
    131  1.3      chs #define	splsoft()	_splraise(imask[IPL_SOFT])
    132  1.2  thorpej 
    133  1.3      chs #define	spl0()		_spllower(imask[IPL_NONE])
    134  1.3      chs #define	spllowersoftclock() _spllower(imask[IPL_SOFTCLOCK])
    135  1.1     matt 
    136  1.2  thorpej #define	setsoftnet()	setsoftintr(IPL_SOFTNET)
    137  1.2  thorpej #define	setsoftclock()	setsoftintr(IPL_SOFTCLOCK)
    138  1.2  thorpej 
    139  1.2  thorpej /*
    140  1.2  thorpej  * Software interrupt support.
    141  1.2  thorpej  */
    142  1.2  thorpej 
    143  1.2  thorpej #define	SI_SOFT			0	/* for IPL_SOFT */
    144  1.2  thorpej #define	SI_SOFTCLOCK		1	/* for IPL_SOFTCLOCK */
    145  1.2  thorpej #define	SI_SOFTNET		2	/* for IPL_SOFTNET */
    146  1.2  thorpej #define	SI_SOFTSERIAL		3	/* for IPL_SOFTSERIAL */
    147  1.2  thorpej 
    148  1.2  thorpej #define	SI_NQUEUES		4
    149  1.2  thorpej 
    150  1.2  thorpej #define	SI_QUEUENAMES {							\
    151  1.2  thorpej 	"generic",							\
    152  1.2  thorpej 	"clock",							\
    153  1.2  thorpej 	"net",								\
    154  1.2  thorpej 	"serial",							\
    155  1.2  thorpej }
    156  1.2  thorpej 
    157  1.7     yamt typedef int ipl_t;
    158  1.7     yamt typedef struct {
    159  1.7     yamt 	ipl_t _ipl;
    160  1.7     yamt } ipl_cookie_t;
    161  1.7     yamt 
    162  1.7     yamt static inline ipl_cookie_t
    163  1.7     yamt makeiplcookie(ipl_t ipl)
    164  1.7     yamt {
    165  1.7     yamt 
    166  1.7     yamt 	return (ipl_cookie_t){._ipl = ipl};
    167  1.7     yamt }
    168  1.7     yamt 
    169  1.7     yamt static inline int
    170  1.7     yamt splraiseipl(ipl_cookie_t icookie)
    171  1.7     yamt {
    172  1.7     yamt 
    173  1.7     yamt 	return _splraise(imask[icookie._ipl]);
    174  1.7     yamt }
    175  1.7     yamt 
    176  1.7     yamt #include <sys/spl.h>
    177  1.7     yamt 
    178  1.2  thorpej #endif /* _LOCORE */
    179  1.7     yamt 
    180  1.2  thorpej #endif /* _KERNEL */
    181  1.1     matt 
    182  1.1     matt #endif	/* _MACHINE_INTR_H_ */
    183