Home | History | Annotate | Line # | Download | only in include
intr.h revision 1.19.16.2
      1 /*	$NetBSD: intr.h,v 1.19.16.2 2006/12/30 20:46:49 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 #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_LPT		IPL_TTY
     51 #define	IPL_VM		3	/* memory allocation */
     52 #define	IPL_AUDIO	2	/* audio */
     53 #define	IPL_CLOCK	1	/* clock */
     54 #define	IPL_STATCLOCK	IPL_CLOCK
     55 #define	IPL_HIGH	1	/* everything */
     56 #define	IPL_SCHED	IPL_HIGH
     57 #define	IPL_LOCK	IPL_HIGH
     58 #define	IPL_SERIAL	0	/* serial */
     59 #define	NIPL		10
     60 
     61 /* Interrupt sharing types. */
     62 #define	IST_NONE	0	/* none */
     63 #define	IST_PULSE	1	/* pulsed */
     64 #define	IST_EDGE	2	/* edge-triggered */
     65 #define	IST_LEVEL	3	/* level-triggered */
     66 
     67 #ifndef _LOCORE
     68 #include <powerpc/softintr.h>
     69 #include <machine/cpu.h>
     70 
     71 /*
     72  * Interrupt handler chains.  intr_establish() inserts a handler into
     73  * the list.  The handler is called with its (single) argument.
     74  */
     75 struct intrhand {
     76 	int	(*ih_fun)(void *);
     77 	void	*ih_arg;
     78 	u_long	ih_count;
     79 	struct	intrhand *ih_next;
     80 	int	ih_level;
     81 	int	ih_irq;
     82 };
     83 
     84 #include <sys/device.h>
     85 struct intrsource {
     86 	int is_type;
     87 	int is_level;
     88 	int is_hwirq;
     89 	int is_mask;
     90 	struct intrhand *is_hand;
     91 	struct evcnt is_ev;
     92 	char is_source[16];
     93 };
     94 
     95 int splraise(int);
     96 int spllower(int);
     97 void softintr(int);
     98 
     99 void do_pending_int(void);
    100 
    101 void init_intr(void);
    102 void init_intr_ivr(void);
    103 void init_intr_openpic(void);
    104 void openpic_init(unsigned char *);
    105 
    106 void enable_intr(void);
    107 void disable_intr(void);
    108 
    109 void *intr_establish(int, int, int, int (*)(void *), void *);
    110 void intr_disestablish(void *);
    111 
    112 void softnet(int);
    113 void softserial(void);
    114 int isa_intr(void);
    115 void isa_intr_mask(int);
    116 void isa_intr_clr(int);
    117 void isa_setirqstat(int, int, int);
    118 
    119 extern int imen;
    120 extern int imask[];
    121 extern struct intrhand *intrhand[];
    122 extern vaddr_t prep_intr_reg;
    123 extern uint32_t prep_intr_reg_off;
    124 
    125 #define	ICU_LEN			32
    126 extern struct intrsource intrsources[ICU_LEN];
    127 
    128 #define	IRQ_SLAVE		2
    129 #define	LEGAL_IRQ(x)		((x) >= 0 && (x) < ICU_LEN && (x) != IRQ_SLAVE)
    130 #define	I8259_INTR_NUM		16
    131 #define	OPENPIC_INTR_NUM	((ICU_LEN)-(I8259_INTR_NUM))
    132 #define	CLKF_BASEPRI(frame)	((frame)->pri == 0)
    133 
    134 #define	PREP_INTR_REG	0xbffff000
    135 #define	INTR_VECTOR_REG	0xff0
    136 
    137 #define	SINT_CLOCK	0x20000000
    138 #define	SINT_NET	0x40000000
    139 #define	SINT_SERIAL	0x80000000
    140 #define	SPL_CLOCK	0x00000001
    141 #define	SINT_MASK	(SINT_CLOCK|SINT_NET|SINT_SERIAL)
    142 
    143 #define	CNT_SINT_NET	29
    144 #define	CNT_SINT_CLOCK	30
    145 #define	CNT_SINT_SERIAL	31
    146 #define	CNT_CLOCK	0
    147 
    148 #define	spllowersoftclock() spllower(imask[IPL_SOFTCLOCK])
    149 
    150 #define setsoftclock()  softintr(SINT_CLOCK);
    151 #define setsoftnet()    softintr(SINT_NET);
    152 #define setsoftserial() softintr(SINT_SERIAL);
    153 
    154 #define	splx(x)		spllower(x)
    155 #define	spl0()		spllower(0)
    156 
    157 typedef int ipl_t;
    158 typedef struct {
    159 	ipl_t _ipl;
    160 } ipl_cookie_t;
    161 
    162 static inline ipl_cookie_t
    163 makeiplcookie(ipl_t ipl)
    164 {
    165 
    166 	return (ipl_cookie_t){._ipl = ipl};
    167 }
    168 
    169 static inline int
    170 splraiseipl(ipl_cookie_t icookie)
    171 {
    172 
    173 	return splraise(imask[icookie._ipl]);
    174 }
    175 
    176 #include <sys/spl.h>
    177 
    178 #endif /* !_LOCORE */
    179 
    180 #endif /* !_PREP_INTR_H_ */
    181