Home | History | Annotate | Line # | Download | only in include
intr.h revision 1.23
      1 /*	$NetBSD: intr.h,v 1.23 2006/02/16 20:17:14 perry 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 #ifndef _PREP_INTR_H_
     40 #define _PREP_INTR_H_
     41 
     42 /* Interrupt priority `levels'. */
     43 #define	IPL_NONE	9	/* nothing */
     44 #define	IPL_SOFTCLOCK	8	/* software clock interrupt */
     45 #define	IPL_SOFTNET	7	/* software network interrupt */
     46 #define	IPL_BIO		6	/* block I/O */
     47 #define	IPL_NET		5	/* network */
     48 #define	IPL_SOFTSERIAL	4	/* software serial interrupt */
     49 #define	IPL_TTY		3	/* terminal */
     50 #define	IPL_VM		3	/* memory allocation */
     51 #define	IPL_AUDIO	2	/* audio */
     52 #define	IPL_CLOCK	1	/* clock */
     53 #define	IPL_HIGH	1	/* everything */
     54 #define	IPL_SERIAL	0	/* serial */
     55 #define	NIPL		10
     56 
     57 /* Interrupt sharing types. */
     58 #define	IST_NONE	0	/* none */
     59 #define	IST_PULSE	1	/* pulsed */
     60 #define	IST_EDGE	2	/* edge-triggered */
     61 #define	IST_LEVEL	3	/* level-triggered */
     62 
     63 #ifndef _LOCORE
     64 
     65 /*
     66  * Interrupt handler chains.  intr_establish() inserts a handler into
     67  * the list.  The handler is called with its (single) argument.
     68  */
     69 struct intrhand {
     70 	int	(*ih_fun)(void *);
     71 	void	*ih_arg;
     72 	u_long	ih_count;
     73 	struct	intrhand *ih_next;
     74 	int	ih_level;
     75 	int	ih_irq;
     76 };
     77 
     78 void do_pending_int(void);
     79 
     80 void init_intr(void);
     81 void init_intr_ivr(void);
     82 void init_intr_openpic(void);
     83 
     84 void enable_intr(void);
     85 void disable_intr(void);
     86 
     87 void *intr_establish(int, int, int, int (*)(void *), void *);
     88 void intr_disestablish(void *);
     89 
     90 void softnet(int);
     91 void softserial(void);
     92 int isa_intr(void);
     93 void isa_intr_mask(int);
     94 void isa_intr_clr(int);
     95 void isa_setirqstat(int, int, int);
     96 
     97 static __inline int splraise(int);
     98 static __inline void spllower(int);
     99 static __inline void set_sint(int);
    100 
    101 extern volatile int cpl, ipending, astpending, tickspending;
    102 extern int imen;
    103 extern int imask[];
    104 extern long intrcnt[];
    105 extern unsigned intrcnt2[];
    106 extern struct intrhand *intrhand[];
    107 extern int intrtype[];
    108 extern vaddr_t prep_intr_reg;
    109 
    110 /*
    111  *  Reorder protection in the following inline functions is
    112  * achieved with the "eieio" instruction which the assembler
    113  * seems to detect and then doesn't move instructions past....
    114  */
    115 static __inline int
    116 splraise(int newcpl)
    117 {
    118 	int oldcpl;
    119 
    120 	__asm volatile("sync; eieio\n");	/* don't reorder.... */
    121 	oldcpl = cpl;
    122 	cpl = oldcpl | newcpl;
    123 	__asm volatile("sync; eieio\n");	/* reorder protect */
    124 	return(oldcpl);
    125 }
    126 
    127 static __inline void
    128 spllower(int newcpl)
    129 {
    130 
    131 	__asm volatile("sync; eieio\n");	/* reorder protect */
    132 	cpl = newcpl;
    133 	if(ipending & ~newcpl)
    134 		do_pending_int();
    135 	__asm volatile("sync; eieio\n");	/* reorder protect */
    136 }
    137 
    138 /* Following code should be implemented with lwarx/stwcx to avoid
    139  * the disable/enable. i need to read the manual once more.... */
    140 static __inline void
    141 set_sint(int pending)
    142 {
    143 	int	msrsave;
    144 
    145 	__asm ("mfmsr %0" : "=r"(msrsave));
    146 	__asm volatile ("mtmsr %0" :: "r"(msrsave & ~PSL_EE));
    147 	ipending |= pending;
    148 	__asm volatile ("mtmsr %0" :: "r"(msrsave));
    149 }
    150 
    151 #define	ICU_LEN			32
    152 #define	IRQ_SLAVE		2
    153 #define	LEGAL_IRQ(x)		((x) >= 0 && (x) < ICU_LEN && (x) != IRQ_SLAVE)
    154 #define	I8259_INTR_NUM		16
    155 #define	OPENPIC_INTR_NUM	((ICU_LEN)-(I8259_INTR_NUM))
    156 #define	CLKF_BASEPRI(frame)	((frame)->pri == 0)
    157 
    158 #define	PREP_INTR_REG	0xbffff000
    159 #define	INTR_VECTOR_REG	0xff0
    160 
    161 #define	SINT_CLOCK	0x20000000
    162 #define	SINT_NET	0x40000000
    163 #define	SINT_SERIAL	0x80000000
    164 #define	SPL_CLOCK	0x00000001
    165 #define	SINT_MASK	(SINT_CLOCK|SINT_NET|SINT_SERIAL)
    166 
    167 #define	CNT_SINT_NET	29
    168 #define	CNT_SINT_CLOCK	30
    169 #define	CNT_SINT_SERIAL	31
    170 #define	CNT_CLOCK	0
    171 
    172 #define splbio()	splraise(imask[IPL_BIO])
    173 #define splnet()	splraise(imask[IPL_NET])
    174 #define spltty()	splraise(imask[IPL_TTY])
    175 #define splclock()	splraise(imask[IPL_CLOCK])
    176 #define splvm()		splraise(imask[IPL_VM])
    177 #define splaudio()	splraise(imask[IPL_AUDIO])
    178 #define	splserial()	splraise(imask[IPL_SERIAL])
    179 #define splstatclock()	splclock()
    180 #define	spllowersoftclock() spllower(imask[IPL_SOFTCLOCK])
    181 #define	splsoftclock()	splraise(imask[IPL_SOFTCLOCK])
    182 #define	splsoftnet()	splraise(imask[IPL_SOFTNET])
    183 #define	splsoftserial()	splraise(imask[IPL_SOFTSERIAL])
    184 
    185 #define spllpt()	spltty()
    186 
    187 #define	setsoftclock()	set_sint(SINT_CLOCK);
    188 #define	setsoftnet()	set_sint(SINT_NET);
    189 #define	setsoftserial()	set_sint(SINT_SERIAL);
    190 
    191 #define	splhigh()	splraise(imask[IPL_HIGH])
    192 #define	splsched()	splhigh()
    193 #define	spllock()	splhigh()
    194 #define	splx(x)		spllower(x)
    195 #define	spl0()		spllower(0)
    196 
    197 #endif /* !_LOCORE */
    198 
    199 #endif /* !_PREP_INTR_H_ */
    200