Home | History | Annotate | Line # | Download | only in include
intr.h revision 1.1.20.1
      1  1.1.20.1  minoura /* 	$NetBSD: intr.h,v 1.1.20.1 2000/06/22 17:05:06 minoura Exp $	*/
      2       1.1     matt 
      3       1.1     matt /*
      4       1.1     matt  * Copyright (c) 1998 Matt Thomas.
      5       1.1     matt  * All rights reserved.
      6       1.1     matt  *
      7       1.1     matt  * Redistribution and use in source and binary forms, with or without
      8       1.1     matt  * modification, are permitted provided that the following conditions
      9       1.1     matt  * are met:
     10       1.1     matt  * 1. Redistributions of source code must retain the above copyright
     11       1.1     matt  *    notice, this list of conditions and the following disclaimer.
     12       1.1     matt  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1     matt  *    notice, this list of conditions and the following disclaimer in the
     14       1.1     matt  *    documentation and/or other materials provided with the distribution.
     15       1.1     matt  * 3. The name of the company nor the name of the author may be used to
     16       1.1     matt  *    endorse or promote products derived from this software without specific
     17       1.1     matt  *    prior written permission.
     18       1.1     matt  *
     19       1.1     matt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     20       1.1     matt  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     21       1.1     matt  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22       1.1     matt  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     23       1.1     matt  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     24       1.1     matt  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     25       1.1     matt  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26       1.1     matt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27       1.1     matt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28       1.1     matt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29       1.1     matt  * SUCH DAMAGE.
     30       1.1     matt  */
     31       1.1     matt 
     32       1.1     matt #ifndef _VAX_INTR_H_
     33       1.1     matt #define _VAX_INTR_H_
     34       1.1     matt 
     35  1.1.20.1  minoura #include <sys/queue.h>
     36  1.1.20.1  minoura 
     37       1.1     matt /* Define the various Interrupt Priority Levels */
     38       1.1     matt 
     39       1.1     matt /* Interrupt Priority Levels are not mutually exclusive. */
     40       1.1     matt 
     41  1.1.20.1  minoura /* Hardware interrupt levels are 16 (0x10) thru 31 (0x1f)
     42  1.1.20.1  minoura  */
     43  1.1.20.1  minoura #define IPL_HIGH	0x1f	/* high -- blocks all interrupts */
     44  1.1.20.1  minoura #define IPL_CLOCK	0x18	/* clock */
     45  1.1.20.1  minoura #define IPL_UBA		0x17	/* unibus adapters */
     46  1.1.20.1  minoura #define IPL_IMP		0x17	/* memory allocation */
     47  1.1.20.1  minoura #define IPL_BIO		0x15	/* block I/O */
     48  1.1.20.1  minoura #define IPL_NET		0x15	/* network */
     49  1.1.20.1  minoura #define IPL_TTY		0x15	/* terminal */
     50  1.1.20.1  minoura #define IPL_AUDIO	0x15	/* audio */
     51  1.1.20.1  minoura #define IPL_CONSMEDIA	0x14	/* console media */
     52       1.1     matt 
     53  1.1.20.1  minoura /* Software interrupt level s are 0 (0x00) thru 15 (0x0f)
     54  1.1.20.1  minoura  */
     55  1.1.20.1  minoura #define IPL_SOFTDDB	0x0f	/* used by DDB on VAX */
     56  1.1.20.1  minoura #define IPL_SOFTSERIAL	0x0d	/* soft serial */
     57  1.1.20.1  minoura #define IPL_SOFTNET	0x0c	/* soft network */
     58  1.1.20.1  minoura #define IPL_SOFTCLOCK	0x08
     59  1.1.20.1  minoura #define IPL_NONE	0x00
     60  1.1.20.1  minoura 
     61  1.1.20.1  minoura #define IPL_LEVELS	32
     62  1.1.20.1  minoura 
     63  1.1.20.1  minoura #define IST_UNUSABLE	-1	/* interrupt cannot be used */
     64  1.1.20.1  minoura #define IST_NONE	0	/* none (dummy) */
     65  1.1.20.1  minoura #define IST_PULSE	1	/* pulsed */
     66  1.1.20.1  minoura #define IST_EDGE	2	/* edge-triggered */
     67  1.1.20.1  minoura #define IST_LEVEL	3	/* level-triggered */
     68  1.1.20.1  minoura 
     69  1.1.20.1  minoura 
     70  1.1.20.1  minoura #ifdef _KERNEL
     71  1.1.20.1  minoura #ifndef lint
     72  1.1.20.1  minoura #define splx(reg)						\
     73  1.1.20.1  minoura ({								\
     74  1.1.20.1  minoura 	register int val;					\
     75  1.1.20.1  minoura 	__asm __volatile ("mfpr $0x12,%0;mtpr %1,$0x12"		\
     76  1.1.20.1  minoura 				: "&=g" (val)			\
     77  1.1.20.1  minoura 				: "g" (reg));			\
     78  1.1.20.1  minoura 	val;							\
     79  1.1.20.1  minoura })
     80  1.1.20.1  minoura 
     81  1.1.20.1  minoura #define _splset(reg)						\
     82  1.1.20.1  minoura ((void)({							\
     83  1.1.20.1  minoura 	__asm __volatile ("mtpr %0,$0x12"			\
     84  1.1.20.1  minoura 				: 				\
     85  1.1.20.1  minoura 				: "g" (reg));			\
     86  1.1.20.1  minoura }))
     87  1.1.20.1  minoura 
     88  1.1.20.1  minoura #define _splraise(reg)						\
     89  1.1.20.1  minoura ({								\
     90  1.1.20.1  minoura 	register int val;					\
     91  1.1.20.1  minoura 	__asm __volatile ("mfpr $0x12,%0"			\
     92  1.1.20.1  minoura 				: "&=g" (val)			\
     93  1.1.20.1  minoura 				: );				\
     94  1.1.20.1  minoura 	if ((reg) > val) {					\
     95  1.1.20.1  minoura 		_splset(reg);					\
     96  1.1.20.1  minoura 	}							\
     97  1.1.20.1  minoura 	val;							\
     98  1.1.20.1  minoura })
     99  1.1.20.1  minoura 
    100  1.1.20.1  minoura #define _setsirr(reg)						\
    101  1.1.20.1  minoura do {								\
    102  1.1.20.1  minoura 	__asm __volatile ("mtpr %0,$0x14"			\
    103  1.1.20.1  minoura 				:				\
    104  1.1.20.1  minoura 				: "g" (reg));			\
    105  1.1.20.1  minoura } while (0)
    106  1.1.20.1  minoura #endif
    107  1.1.20.1  minoura 
    108  1.1.20.1  minoura #define spl0()		_splset(IPL_NONE)		/* IPL00 */
    109  1.1.20.1  minoura #define spllowersoftclock() _splset(IPL_SOFTCLOCK)	/* IPL08 */
    110  1.1.20.1  minoura #define splsoftclock()	_splraise(IPL_SOFTCLOCK)	/* IPL08 */
    111  1.1.20.1  minoura #define splsoftnet()	_splraise(IPL_SOFTNET)		/* IPL0C */
    112  1.1.20.1  minoura #define splsoftserial()	_splraise(IPL_SOFTSERIAL)	/* IPL0D */
    113  1.1.20.1  minoura #define splddb()	_splraise(IPL_SOFTDDB)		/* IPL0F */
    114  1.1.20.1  minoura #define splconsmedia()	_splraise(IPL_CONSMEDIA)	/* IPL14 */
    115  1.1.20.1  minoura #define splbio()	_splraise(IPL_BIO)		/* IPL15 */
    116  1.1.20.1  minoura #define splnet()	_splraise(IPL_NET)		/* IPL15 */
    117  1.1.20.1  minoura #define spltty()	_splraise(IPL_TTY)		/* IPL15 */
    118  1.1.20.1  minoura #define splimp()	_splraise(IPL_IMP)		/* IPL17 */
    119  1.1.20.1  minoura #define splclock()	_splraise(IPL_CLOCK)		/* IPL18 */
    120  1.1.20.1  minoura #define splhigh()	_splraise(IPL_HIGH)		/* IPL1F */
    121  1.1.20.1  minoura #define splstatclock()	splclock()
    122  1.1.20.1  minoura 
    123  1.1.20.1  minoura /* These are better to use when playing with VAX buses */
    124  1.1.20.1  minoura #define spl4()		splx(0x14)
    125  1.1.20.1  minoura #define spl5()		splx(0x15)
    126  1.1.20.1  minoura #define spl6()		splx(0x16)
    127  1.1.20.1  minoura #define spl7()		splx(0x17)
    128       1.1     matt 
    129  1.1.20.1  minoura /* schedule software interrupts
    130  1.1.20.1  minoura  */
    131  1.1.20.1  minoura #define setsoftddb()	_setsirr(IPL_SOFTDDB)
    132  1.1.20.1  minoura #define setsoftserial()	_setsirr(IPL_SOFTSERIAL)
    133  1.1.20.1  minoura #define setsoftnet()	_setsirr(IPL_SOFTNET)
    134  1.1.20.1  minoura #define setsoftclock()	_setsirr(IPL_SOFTCLOCK)
    135  1.1.20.1  minoura 
    136  1.1.20.1  minoura #define __GENERIC_SOFT_INTERRUPTS
    137  1.1.20.1  minoura 
    138  1.1.20.1  minoura #if !defined(_LOCORE)
    139  1.1.20.1  minoura LIST_HEAD(sh_head, softintr_handler);
    140  1.1.20.1  minoura 
    141  1.1.20.1  minoura struct softintr_head {
    142  1.1.20.1  minoura 	int shd_ipl;
    143  1.1.20.1  minoura 	struct sh_head shd_intrs;
    144  1.1.20.1  minoura };
    145  1.1.20.1  minoura 
    146  1.1.20.1  minoura struct softintr_handler {
    147  1.1.20.1  minoura 	struct softintr_head *sh_head;
    148  1.1.20.1  minoura 	LIST_ENTRY(softintr_handler) sh_link;
    149  1.1.20.1  minoura 	void (*sh_func)(void *);
    150  1.1.20.1  minoura 	void *sh_arg;
    151  1.1.20.1  minoura 	int sh_pending;
    152  1.1.20.1  minoura };
    153  1.1.20.1  minoura 
    154  1.1.20.1  minoura extern void *softintr_establish(int, void (*)(void *), void *);
    155  1.1.20.1  minoura extern void softintr_disestablish(void *);
    156  1.1.20.1  minoura 
    157  1.1.20.1  minoura static __inline void
    158  1.1.20.1  minoura softintr_schedule(void *arg)
    159  1.1.20.1  minoura {
    160  1.1.20.1  minoura 	struct softintr_handler * const sh = arg;
    161  1.1.20.1  minoura 	sh->sh_pending = 1;
    162  1.1.20.1  minoura 	_setsirr(sh->sh_head->shd_ipl);
    163  1.1.20.1  minoura }
    164  1.1.20.1  minoura #endif /* _LOCORE */
    165  1.1.20.1  minoura #endif /* _KERNEL */
    166       1.1     matt #endif	/* _VAX_INTR_H */
    167