Home | History | Annotate | Line # | Download | only in include
intr.h revision 1.4
      1 /*	$NetBSD: intr.h,v 1.4 1998/05/18 17:37:38 kleink Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #ifndef _HP300_INTR_H_
     40 #define	_HP300_INTR_H_
     41 
     42 #include <machine/psl.h>
     43 
     44 #ifdef _HP300_INTR_H_PRIVATE
     45 #include <sys/queue.h>
     46 
     47 /*
     48  * The location and size of the autovectored interrupt portion
     49  * of the vector table.
     50  */
     51 #define ISRLOC		0x18
     52 #define NISR		8
     53 
     54 struct isr {
     55 	LIST_ENTRY(isr) isr_link;
     56 	int		(*isr_func) __P((void *));
     57 	void		*isr_arg;
     58 	int		isr_ipl;
     59 	int		isr_priority;
     60 };
     61 #endif /* _HP300_INTR_H_PRIVATE */
     62 
     63 /*
     64  * Interrupt "levels".  These are a more abstract representation
     65  * of interrupt levels, and do not have the same meaning as m68k
     66  * CPU interrupt levels.  They serve two purposes:
     67  *
     68  *	- properly order ISRs in the list for that CPU ipl
     69  *	- compute CPU PSL values for the spl*() calls.
     70  */
     71 #define	IPL_NONE	0	/* disable only this interrupt */
     72 #define	IPL_BIO		1	/* disable block I/O interrupts */
     73 #define	IPL_NET		2	/* disable network interrupts */
     74 #define	IPL_TTY		3	/* disable terminal interrupts */
     75 #define	IPL_TTYNOBUF	4	/* IPL_TTY + higher ISR priority */
     76 #define	IPL_CLOCK	5	/* disable clock interrupts */
     77 #define	IPL_HIGH	6	/* disable all interrupts */
     78 
     79 /*
     80  * Convert PSL values to CPU IPLs and vice-versa.
     81  */
     82 #define	PSLTOIPL(x)	(((x) >> 8) & 0xf)
     83 #define	IPLTOPSL(x)	((((x) & 0xf) << 8) | PSL_S)
     84 
     85 #ifdef _KERNEL
     86 /*
     87  * spl functions; all but spl0 are done in-line
     88  */
     89 
     90 #define	_spl(s)								\
     91 ({									\
     92 	register int _spl_r;						\
     93 									\
     94 	__asm __volatile ("clrl %0; movew sr,%0; movew %1,sr" :		\
     95 	    "&=d" (_spl_r) : "di" (s));					\
     96 	_spl_r;								\
     97 })
     98 
     99 #define	_splraise(s)							\
    100 ({									\
    101 	int _spl_r;							\
    102 									\
    103 	__asm __volatile ("						\
    104 		clrl	d0					;	\
    105 		movw	sr,d0					;	\
    106 		movl	d0,%0					;	\
    107 		andw	#0x700,d0				;	\
    108 		movw	%1,d1					;	\
    109 		andw	#0x700,d1				;	\
    110 		cmpw	d0,d1					;	\
    111 		jle	1f					;	\
    112 		movw	%1,sr					;	\
    113 	    1:"							:	\
    114 		    "&=d" (_spl_r)				:	\
    115 		    "di" (s)					:	\
    116 		    "d0", "d1");					\
    117 	_spl_r;								\
    118 })
    119 
    120 /* spl0 requires checking for software interrupts */
    121 #define	spl1()	_spl(PSL_S|PSL_IPL1)
    122 #define	spl2()	_spl(PSL_S|PSL_IPL2)
    123 #define	spl3()	_spl(PSL_S|PSL_IPL3)
    124 #define	spl4()	_spl(PSL_S|PSL_IPL4)
    125 #define	spl5()	_spl(PSL_S|PSL_IPL5)
    126 #define	spl6()	_spl(PSL_S|PSL_IPL6)
    127 #define	spl7()	_spl(PSL_S|PSL_IPL7)
    128 
    129 /*
    130  * These four globals contain the appropriate PSL_S|PSL_IPL? values
    131  * to raise interrupt priority to the requested level.
    132  */
    133 extern	unsigned short hp300_bioipl;
    134 extern	unsigned short hp300_netipl;
    135 extern	unsigned short hp300_ttyipl;
    136 extern	unsigned short hp300_impipl;
    137 
    138 /* These spl calls are _not_ to be used by machine-independent code. */
    139 #define	splhil()	_splraise(PSL_S|PSL_IPL1)
    140 #define	splkbd()	splhil()
    141 #define	splsoft()	spl1()
    142 
    143 /* These spl calls are used by machine-independent code. */
    144 #define	splsoftclock()	splsoft()
    145 #define	splsoftnet()	splsoft()
    146 #define	splbio()	_splraise(hp300_bioipl)
    147 #define	splnet()	_splraise(hp300_netipl)
    148 #define	spltty()	_splraise(hp300_ttyipl)
    149 #define	splimp()	_splraise(hp300_impipl)
    150 #define	splclock()	spl6()
    151 #define	splstatclock()	spl6()
    152 #define	splvm()		spl6()
    153 #define	splhigh()	spl7()
    154 #define	splsched()	spl7()
    155 
    156 /* watch out for side effects */
    157 #define	splx(s)		((s) & PSL_IPL ? _spl((s)) : spl0())
    158 
    159 /*
    160  * Simulated software interrupt register.
    161  */
    162 extern volatile u_int8_t ssir;
    163 
    164 #define	SIR_NET		0x01
    165 #define	SIR_CLOCK	0x02
    166 
    167 #define	siron(mask)	\
    168 	__asm __volatile ( "orb %0,_ssir" : : "i" ((mask)))
    169 #define	siroff(mask)	\
    170 	__asm __volatile ( "andb %0,_ssir" : : "ir" (~(mask)));
    171 
    172 #define	setsoftnet()	siron(SIR_NET)
    173 #define	setsoftclock()	siron(SIR_CLOCK)
    174 
    175 /* locore.s */
    176 int	spl0 __P((void));
    177 
    178 /* intr.c */
    179 void	intr_init __P((void));
    180 void	*intr_establish __P((int (*)(void *), void *, int, int));
    181 void	intr_disestablish __P((void *));
    182 void	intr_dispatch __P((int));
    183 void	intr_printlevels __P((void));
    184 #endif /* _KERNEL */
    185 
    186 #endif /* _HP300_INTR_H_ */
    187