Home | History | Annotate | Line # | Download | only in include
intr.h revision 1.1
      1  1.1  nonaka /*	$NetBSD: intr.h,v 1.1 2000/02/29 15:21:29 nonaka Exp $	*/
      2  1.1  nonaka 
      3  1.1  nonaka /*-
      4  1.1  nonaka  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  1.1  nonaka  * All rights reserved.
      6  1.1  nonaka  *
      7  1.1  nonaka  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  nonaka  * by Charles M. Hannum.
      9  1.1  nonaka  *
     10  1.1  nonaka  * Redistribution and use in source and binary forms, with or without
     11  1.1  nonaka  * modification, are permitted provided that the following conditions
     12  1.1  nonaka  * are met:
     13  1.1  nonaka  * 1. Redistributions of source code must retain the above copyright
     14  1.1  nonaka  *    notice, this list of conditions and the following disclaimer.
     15  1.1  nonaka  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  nonaka  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  nonaka  *    documentation and/or other materials provided with the distribution.
     18  1.1  nonaka  * 3. All advertising materials mentioning features or use of this software
     19  1.1  nonaka  *    must display the following acknowledgement:
     20  1.1  nonaka  *        This product includes software developed by the NetBSD
     21  1.1  nonaka  *        Foundation, Inc. and its contributors.
     22  1.1  nonaka  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  nonaka  *    contributors may be used to endorse or promote products derived
     24  1.1  nonaka  *    from this software without specific prior written permission.
     25  1.1  nonaka  *
     26  1.1  nonaka  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  nonaka  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  nonaka  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  nonaka  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  nonaka  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  nonaka  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  nonaka  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  nonaka  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  nonaka  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  nonaka  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  nonaka  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  nonaka  */
     38  1.1  nonaka 
     39  1.1  nonaka #ifndef _PREP_INTR_H_
     40  1.1  nonaka #define _PREP_INTR_H_
     41  1.1  nonaka 
     42  1.1  nonaka /* Interrupt priority `levels'. */
     43  1.1  nonaka #define	IPL_NONE	9	/* nothing */
     44  1.1  nonaka #define	IPL_SOFTCLOCK	8	/* software clock interrupt */
     45  1.1  nonaka #define	IPL_SOFTNET	7	/* software network interrupt */
     46  1.1  nonaka #define	IPL_BIO		6	/* block I/O */
     47  1.1  nonaka #define	IPL_NET		5	/* network */
     48  1.1  nonaka #define	IPL_SOFTSERIAL	4	/* software serial interrupt */
     49  1.1  nonaka #define	IPL_TTY		3	/* terminal */
     50  1.1  nonaka #define	IPL_IMP		3	/* memory allocation */
     51  1.1  nonaka #define	IPL_AUDIO	2	/* audio */
     52  1.1  nonaka #define	IPL_CLOCK	1	/* clock */
     53  1.1  nonaka #define	IPL_HIGH	1	/* everything */
     54  1.1  nonaka #define	IPL_SERIAL	0	/* serial */
     55  1.1  nonaka #define	NIPL		10
     56  1.1  nonaka 
     57  1.1  nonaka /* Interrupt sharing types. */
     58  1.1  nonaka #define	IST_NONE	0	/* none */
     59  1.1  nonaka #define	IST_PULSE	1	/* pulsed */
     60  1.1  nonaka #define	IST_EDGE	2	/* edge-triggered */
     61  1.1  nonaka #define	IST_LEVEL	3	/* level-triggered */
     62  1.1  nonaka 
     63  1.1  nonaka #ifndef _LOCORE
     64  1.1  nonaka 
     65  1.1  nonaka /*
     66  1.1  nonaka  * Interrupt handler chains.  intr_establish() inserts a handler into
     67  1.1  nonaka  * the list.  The handler is called with its (single) argument.
     68  1.1  nonaka  */
     69  1.1  nonaka struct intrhand {
     70  1.1  nonaka 	int	(*ih_fun) __P((void *));
     71  1.1  nonaka 	void	*ih_arg;
     72  1.1  nonaka 	u_long	ih_count;
     73  1.1  nonaka 	struct	intrhand *ih_next;
     74  1.1  nonaka 	int	ih_level;
     75  1.1  nonaka 	int	ih_irq;
     76  1.1  nonaka };
     77  1.1  nonaka 
     78  1.1  nonaka void setsoftclock __P((void));
     79  1.1  nonaka void clearsoftclock __P((void));
     80  1.1  nonaka int  splsoftclock __P((void));
     81  1.1  nonaka void setsoftnet   __P((void));
     82  1.1  nonaka void clearsoftnet __P((void));
     83  1.1  nonaka int  splsoftnet   __P((void));
     84  1.1  nonaka 
     85  1.1  nonaka void do_pending_int __P((void));
     86  1.1  nonaka 
     87  1.1  nonaka void ext_intr __P((void));
     88  1.1  nonaka 
     89  1.1  nonaka void enable_intr __P((void));
     90  1.1  nonaka void disable_intr __P((void));
     91  1.1  nonaka 
     92  1.1  nonaka void *intr_establish __P((int, int, int, int (*) __P((void *)), void *));
     93  1.1  nonaka void intr_disestablish __P((void *));
     94  1.1  nonaka 
     95  1.1  nonaka void softnet __P((void));
     96  1.1  nonaka void softserial __P((void));
     97  1.1  nonaka 
     98  1.1  nonaka static __inline int splraise __P((int));
     99  1.1  nonaka static __inline int spllower __P((int));
    100  1.1  nonaka static __inline void splx __P((int));
    101  1.1  nonaka static __inline void set_sint __P((int));
    102  1.1  nonaka 
    103  1.1  nonaka extern volatile int cpl, ipending, astpending, tickspending;
    104  1.1  nonaka extern int imask[];
    105  1.1  nonaka extern long intrcnt[];
    106  1.1  nonaka 
    107  1.1  nonaka /*
    108  1.1  nonaka  *  Reorder protection in the following inline functions is
    109  1.1  nonaka  * achived with the "eieio" instruction which the assembler
    110  1.1  nonaka  * seems to detect and then doen't move instructions past....
    111  1.1  nonaka  */
    112  1.1  nonaka static __inline int
    113  1.1  nonaka splraise(newcpl)
    114  1.1  nonaka 	int newcpl;
    115  1.1  nonaka {
    116  1.1  nonaka 	int oldcpl;
    117  1.1  nonaka 
    118  1.1  nonaka 	__asm__ volatile("sync; eieio\n");	/* don't reorder.... */
    119  1.1  nonaka 	oldcpl = cpl;
    120  1.1  nonaka 	cpl = oldcpl | newcpl;
    121  1.1  nonaka 	__asm__ volatile("sync; eieio\n");	/* reorder protect */
    122  1.1  nonaka 	return(oldcpl);
    123  1.1  nonaka }
    124  1.1  nonaka 
    125  1.1  nonaka static __inline void
    126  1.1  nonaka splx(newcpl)
    127  1.1  nonaka 	int newcpl;
    128  1.1  nonaka {
    129  1.1  nonaka 	__asm__ volatile("sync; eieio\n");	/* reorder protect */
    130  1.1  nonaka 	cpl = newcpl;
    131  1.1  nonaka 	if(ipending & ~newcpl)
    132  1.1  nonaka 		do_pending_int();
    133  1.1  nonaka 	__asm__ volatile("sync; eieio\n");	/* reorder protect */
    134  1.1  nonaka }
    135  1.1  nonaka 
    136  1.1  nonaka static __inline int
    137  1.1  nonaka spllower(newcpl)
    138  1.1  nonaka 	int newcpl;
    139  1.1  nonaka {
    140  1.1  nonaka 	int oldcpl;
    141  1.1  nonaka 
    142  1.1  nonaka 	__asm__ volatile("sync; eieio\n");	/* reorder protect */
    143  1.1  nonaka 	oldcpl = cpl;
    144  1.1  nonaka 	cpl = newcpl;
    145  1.1  nonaka 	if(ipending & ~newcpl)
    146  1.1  nonaka 		do_pending_int();
    147  1.1  nonaka 	__asm__ volatile("sync; eieio\n");	/* reorder protect */
    148  1.1  nonaka 	return(oldcpl);
    149  1.1  nonaka }
    150  1.1  nonaka 
    151  1.1  nonaka /* Following code should be implemented with lwarx/stwcx to avoid
    152  1.1  nonaka  * the disable/enable. i need to read the manual once more.... */
    153  1.1  nonaka static __inline void
    154  1.1  nonaka set_sint(pending)
    155  1.1  nonaka 	int	pending;
    156  1.1  nonaka {
    157  1.1  nonaka 	int	msrsave;
    158  1.1  nonaka 
    159  1.1  nonaka 	__asm__ ("mfmsr %0" : "=r"(msrsave));
    160  1.1  nonaka 	__asm__ volatile ("mtmsr %0" :: "r"(msrsave & ~PSL_EE));
    161  1.1  nonaka 	ipending |= pending;
    162  1.1  nonaka 	__asm__ volatile ("mtmsr %0" :: "r"(msrsave));
    163  1.1  nonaka }
    164  1.1  nonaka 
    165  1.1  nonaka #define	ICU_LEN		32
    166  1.1  nonaka #define	IRQ_SLAVE	2
    167  1.1  nonaka #define	LEGAL_IRQ(x)	((x) >= 0 && (x) < ICU_LEN && (x) != IRQ_SLAVE)
    168  1.1  nonaka 
    169  1.1  nonaka #define	PREP_INTR_REG	0xbffff000
    170  1.1  nonaka #define	INTR_VECTOR_REG	0xff0
    171  1.1  nonaka 
    172  1.1  nonaka #define	SINT_CLOCK	0x20000000
    173  1.1  nonaka #define	SINT_NET	0x40000000
    174  1.1  nonaka #define	SINT_SERIAL	0x80000000
    175  1.1  nonaka #define	SPL_CLOCK	0x00000001
    176  1.1  nonaka #define	SINT_MASK	(SINT_CLOCK|SINT_NET|SINT_SERIAL)
    177  1.1  nonaka 
    178  1.1  nonaka #define	CNT_SINT_NET	29
    179  1.1  nonaka #define	CNT_SINT_CLOCK	30
    180  1.1  nonaka #define	CNT_SINT_SERIAL	31
    181  1.1  nonaka #define	CNT_CLOCK	0
    182  1.1  nonaka 
    183  1.1  nonaka #define splbio()	splraise(imask[IPL_BIO])
    184  1.1  nonaka #define splnet()	splraise(imask[IPL_NET])
    185  1.1  nonaka #define spltty()	splraise(imask[IPL_TTY])
    186  1.1  nonaka #define splclock()	splraise(imask[IPL_CLOCK])
    187  1.1  nonaka #define splimp()	splraise(imask[IPL_IMP])
    188  1.1  nonaka #define splaudio()	splraise(imask[IPL_AUDIO])
    189  1.1  nonaka #define	splserial()	splraise(imask[IPL_SERIAL])
    190  1.1  nonaka #define splstatclock()	splclock()
    191  1.1  nonaka #define	spllowersoftclock() spllower(imask[IPL_SOFTCLOCK])
    192  1.1  nonaka #define	splsoftclock()	splraise(imask[IPL_SOFTCLOCK])
    193  1.1  nonaka #define	splsoftnet()	splraise(imask[IPL_SOFTNET])
    194  1.1  nonaka #define	splsoftserial()	splraise(imask[IPL_SOFTSERIAL])
    195  1.1  nonaka 
    196  1.1  nonaka #define spllpt()	spltty()
    197  1.1  nonaka 
    198  1.1  nonaka #define	setsoftclock()	set_sint(SINT_CLOCK);
    199  1.1  nonaka #define	setsoftnet()	set_sint(SINT_NET);
    200  1.1  nonaka #define	setsoftserial()	set_sint(SINT_SERIAL);
    201  1.1  nonaka 
    202  1.1  nonaka #define	splhigh()	splraise(imask[IPL_HIGH])
    203  1.1  nonaka #define	spl0()		spllower(0)
    204  1.1  nonaka 
    205  1.1  nonaka #endif /* !_LOCORE */
    206  1.1  nonaka 
    207  1.1  nonaka #endif /* !_PREP_INTR_H_ */
    208