Home | History | Annotate | Line # | Download | only in include
intr.h revision 1.10.16.2
      1 /*	$NetBSD: intr.h,v 1.10.16.2 2006/11/04 14:13:38 yamt Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Charles M. Hannum.
      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  * Sandpoint-specific code developed
     40  * by Allen Briggs for Wasabi Systems, Inc.
     41  *
     42  * OpenPIC code derived from code with the following notice.
     43  */
     44 /*-
     45  * Copyright (c) 2000 Tsubai Masanari.  All rights reserved.
     46  *
     47  * Redistribution and use in source and binary forms, with or without
     48  * modification, are permitted provided that the following conditions
     49  * are met:
     50  * 1. Redistributions of source code must retain the above copyright
     51  *    notice, this list of conditions and the following disclaimer.
     52  * 2. Redistributions in binary form must reproduce the above copyright
     53  *    notice, this list of conditions and the following disclaimer in the
     54  *    documentation and/or other materials provided with the distribution.
     55  * 3. The name of the author may not be used to endorse or promote products
     56  *    derived from this software without specific prior written permission.
     57  *
     58  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     59  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     60  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     61  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     62  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     63  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     64  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     65  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     66  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     67  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     68  */
     69 
     70 #ifndef _SANDPOINT_INTR_H_
     71 #define _SANDPOINT_INTR_H_
     72 
     73 /* Interrupt priority `levels'. */
     74 #define	IPL_NONE	9	/* nothing */
     75 #define	IPL_SOFTCLOCK	8	/* software clock interrupt */
     76 #define	IPL_SOFTNET	7	/* software network interrupt */
     77 #define	IPL_BIO		6	/* block I/O */
     78 #define	IPL_NET		5	/* network */
     79 #define	IPL_SOFTSERIAL	4	/* software serial interrupt */
     80 #define	IPL_TTY		3	/* terminal */
     81 #define	IPL_VM		3	/* memory allocation */
     82 #define	IPL_AUDIO	2	/* audio */
     83 #define	IPL_CLOCK	1	/* clock */
     84 #define	IPL_STATCLOCK	IPL_CLOCK
     85 #define	IPL_HIGH	1	/* everything */
     86 #define	IPL_SCHED	IPL_HIGH
     87 #define	IPL_LOCK	IPL_HIGH
     88 #define	IPL_SERIAL	0	/* serial */
     89 #define	NIPL		10
     90 
     91 /* Interrupt sharing types. */
     92 #define	IST_NONE	0	/* none */
     93 #define	IST_PULSE	1	/* pulsed */
     94 #define	IST_EDGE	2	/* edge-triggered */
     95 #define	IST_LEVEL	3	/* level-triggered */
     96 
     97 #ifndef _LOCORE
     98 #define	CLKF_BASEPRI(frame)	((frame)->pri == 0)
     99 
    100 /*
    101  * Interrupt handler chains.  intr_establish() inserts a handler into
    102  * the list.  The handler is called with its (single) argument.
    103  */
    104 struct intrhand {
    105 	int	(*ih_fun)(void *);
    106 	void	*ih_arg;
    107 	u_long	ih_count;
    108 	struct	intrhand *ih_next;
    109 	int	ih_level;
    110 	int	ih_irq;
    111 };
    112 
    113 void	do_pending_int(void);
    114 void	*intr_establish(int, int, int, int (*)(void *), void *);
    115 void	intr_disestablish(void *);
    116 
    117 static __inline int splraise(int);
    118 static __inline int spllower(int);
    119 static __inline void splx(int);
    120 static __inline void set_sint(int);
    121 
    122 extern volatile int cpl, ipending, astpending, tickspending;
    123 extern int imask[];
    124 extern long intrcnt[];
    125 
    126 /*
    127  * Reorder protection in the following inline functions is
    128  * protected with the "eieio" instruction.
    129  */
    130 static __inline int
    131 splraise(newcpl)
    132 	int newcpl;
    133 {
    134 	int oldcpl;
    135 
    136 	__asm volatile("sync; eieio\n");	/* don't reorder.... */
    137 	oldcpl = cpl;
    138 	cpl = oldcpl | newcpl;
    139 	__asm volatile("sync; eieio\n");	/* reorder protect */
    140 	return(oldcpl);
    141 }
    142 
    143 static __inline void
    144 splx(newcpl)
    145 	int newcpl;
    146 {
    147 	__asm volatile("sync; eieio\n");	/* reorder protect */
    148 	cpl = newcpl;
    149 	if(ipending & ~newcpl)
    150 		do_pending_int();
    151 	__asm volatile("sync; eieio\n");	/* reorder protect */
    152 }
    153 
    154 static __inline int
    155 spllower(newcpl)
    156 	int newcpl;
    157 {
    158 	int oldcpl;
    159 
    160 	__asm volatile("sync; eieio\n");	/* reorder protect */
    161 	oldcpl = cpl;
    162 	cpl = newcpl;
    163 	if(ipending & ~newcpl)
    164 		do_pending_int();
    165 	__asm volatile("sync; eieio\n");	/* reorder protect */
    166 	return(oldcpl);
    167 }
    168 
    169 /* Following code should be implemented with lwarx/stwcx to avoid
    170  * the disable/enable. i need to read the manual once more.... */
    171 static __inline void
    172 set_sint(pending)
    173 	int	pending;
    174 {
    175 	int	msrsave;
    176 
    177 	__asm ("mfmsr %0" : "=r"(msrsave));
    178 	__asm volatile ("mtmsr %0" :: "r"(msrsave & ~PSL_EE));
    179 	ipending |= pending;
    180 	__asm volatile ("mtmsr %0" :: "r"(msrsave));
    181 }
    182 
    183 /*
    184  * Motorola SandPoint PPC eval board interrupt list
    185  */
    186 #define	ICU_LEN		25
    187 #define	ICU_MASK	0x01ffffff
    188 
    189 #define	LEGAL_IRQ(x)	((x) >= 0 && (x) < ICU_LEN)
    190 
    191 #define	SINT_ISA	0x10000000
    192 #define	SINT_NET	0x20000000
    193 #define	SINT_CLOCK	0x40000000
    194 #define	SINT_SERIAL	0x80000000
    195 #define	SPL_CLOCK	0x00000001
    196 #define	SINT_MASK	(SINT_ISA|SINT_CLOCK|SINT_NET|SINT_SERIAL)
    197 
    198 #define	CNT_SINT_ISA	28
    199 #define	CNT_SINT_NET	29
    200 #define	CNT_SINT_CLOCK	30
    201 #define	CNT_SINT_SERIAL	31
    202 #define	CNT_CLOCK	0
    203 
    204 #define splbio()	splraise(imask[IPL_BIO])
    205 #define splnet()	splraise(imask[IPL_NET])
    206 #define spltty()	splraise(imask[IPL_TTY])
    207 #define splclock()	splraise(imask[IPL_CLOCK])
    208 #define splvm()		splraise(imask[IPL_VM])
    209 #define	splserial()	splraise(imask[IPL_SERIAL])
    210 #define splstatclock()	splclock()
    211 #define	spllowersoftclock() spllower(imask[IPL_SOFTCLOCK])
    212 #define	splsoftclock()	splraise(imask[IPL_SOFTCLOCK])
    213 #define	splsoftnet()	splraise(imask[IPL_SOFTNET])
    214 #define	splsoftserial()	splraise(imask[IPL_SOFTSERIAL])
    215 
    216 #define spllpt()	spltty()
    217 
    218 #define	setsoftisa()	set_sint(SINT_ISA);
    219 #define	setsoftclock()	set_sint(SINT_CLOCK);
    220 #define	setsoftnet()	set_sint(SINT_NET);
    221 #define	setsoftserial()	set_sint(SINT_SERIAL);
    222 
    223 #define	splhigh()	splraise(imask[IPL_HIGH])
    224 #define	spl0()		spllower(0)
    225 
    226 #define splsched()	splhigh()
    227 #define spllock()	splhigh()
    228 
    229 typedef int ipl_t;
    230 typedef struct {
    231 	ipl_t _ipl;
    232 } ipl_cookie_t;
    233 
    234 static inline ipl_cookie_t
    235 makeiplcookie(ipl_t ipl)
    236 {
    237 
    238 	return (ipl_cookie_t){._ipl = ipl};
    239 }
    240 
    241 static inline int
    242 splraiseipl(ipl_cookie_t icookie)
    243 {
    244 
    245 	return splraise(imask[icookie._ipl]);
    246 }
    247 
    248 #endif /* !_LOCORE */
    249 
    250 #endif /* !_SANDPOINT_INTR_H_ */
    251