Home | History | Annotate | Line # | Download | only in include
intr.h revision 1.11.2.3
      1  1.11.2.3  jdolecek /*	$NetBSD: intr.h,v 1.11.2.3 2002/06/23 17:40:40 jdolecek Exp $	*/
      2       1.1    itojun 
      3  1.11.2.3  jdolecek /*-
      4  1.11.2.3  jdolecek  * Copyright (c) 2002 The NetBSD Foundation, Inc.
      5  1.11.2.3  jdolecek  * All rights reserved.
      6       1.1    itojun  *
      7       1.1    itojun  * Redistribution and use in source and binary forms, with or without
      8       1.1    itojun  * modification, are permitted provided that the following conditions
      9       1.1    itojun  * are met:
     10       1.1    itojun  * 1. Redistributions of source code must retain the above copyright
     11       1.1    itojun  *    notice, this list of conditions and the following disclaimer.
     12       1.1    itojun  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1    itojun  *    notice, this list of conditions and the following disclaimer in the
     14       1.1    itojun  *    documentation and/or other materials provided with the distribution.
     15       1.1    itojun  * 3. All advertising materials mentioning features or use of this software
     16       1.1    itojun  *    must display the following acknowledgement:
     17  1.11.2.3  jdolecek  *        This product includes software developed by the NetBSD
     18  1.11.2.3  jdolecek  *        Foundation, Inc. and its contributors.
     19  1.11.2.3  jdolecek  * 4. Neither the name of The NetBSD Foundation nor the names of its
     20  1.11.2.3  jdolecek  *    contributors may be used to endorse or promote products derived
     21  1.11.2.3  jdolecek  *    from this software without specific prior written permission.
     22       1.1    itojun  *
     23  1.11.2.3  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     24  1.11.2.3  jdolecek  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     25  1.11.2.3  jdolecek  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     26  1.11.2.3  jdolecek  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     27  1.11.2.3  jdolecek  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     28  1.11.2.3  jdolecek  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     29  1.11.2.3  jdolecek  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     30  1.11.2.3  jdolecek  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     31  1.11.2.3  jdolecek  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     32  1.11.2.3  jdolecek  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     33  1.11.2.3  jdolecek  * POSSIBILITY OF SUCH DAMAGE.
     34       1.1    itojun  */
     35       1.1    itojun 
     36       1.1    itojun #ifndef _SH3_INTR_H_
     37  1.11.2.3  jdolecek #define	_SH3_INTR_H_
     38       1.1    itojun 
     39  1.11.2.3  jdolecek #include <sys/device.h>
     40  1.11.2.3  jdolecek #include <sys/lock.h>
     41  1.11.2.3  jdolecek #include <sys/queue.h>
     42  1.11.2.2  jdolecek #include <sh3/psl.h>
     43  1.11.2.2  jdolecek 
     44       1.1    itojun /* Interrupt sharing types. */
     45  1.11.2.3  jdolecek #define	IST_NONE		0	/* none */
     46  1.11.2.3  jdolecek #define	IST_PULSE		1	/* pulsed */
     47  1.11.2.3  jdolecek #define	IST_EDGE		2	/* edge-triggered */
     48  1.11.2.3  jdolecek #define	IST_LEVEL		3	/* level-triggered */
     49  1.11.2.3  jdolecek 
     50  1.11.2.3  jdolecek /* Interrupt priority levels */
     51  1.11.2.3  jdolecek #define	_IPL_N		15
     52  1.11.2.3  jdolecek #define	_IPL_NSOFT	4
     53  1.11.2.3  jdolecek 
     54  1.11.2.3  jdolecek #define	IPL_NONE	0	/* nothing */
     55  1.11.2.3  jdolecek #define	IPL_SOFT	1
     56  1.11.2.3  jdolecek #define	IPL_SOFTCLOCK	2	/* timeouts */
     57  1.11.2.3  jdolecek #define	IPL_SOFTNET	3	/* protocol stacks */
     58  1.11.2.3  jdolecek #define	IPL_SOFTSERIAL	4	/* serial */
     59  1.11.2.3  jdolecek 
     60  1.11.2.3  jdolecek #define	IPL_SOFTNAMES {							\
     61  1.11.2.3  jdolecek 	"misc",								\
     62  1.11.2.3  jdolecek 	"clock",							\
     63  1.11.2.3  jdolecek 	"net",								\
     64  1.11.2.3  jdolecek 	"serial",							\
     65       1.1    itojun }
     66       1.1    itojun 
     67  1.11.2.3  jdolecek struct intc_intrhand {
     68  1.11.2.3  jdolecek 	int	(*ih_func)(void *);
     69  1.11.2.3  jdolecek 	void	*ih_arg;
     70  1.11.2.3  jdolecek 	int	ih_level;	/* SR.I[0:3] value */
     71  1.11.2.3  jdolecek 	int	ih_evtcode;	/* INTEVT or INTEVT2(SH7709/SH7709A) */
     72  1.11.2.3  jdolecek 	int	ih_idx;		/* evtcode -> intrhand mapping */
     73  1.11.2.3  jdolecek };
     74  1.11.2.3  jdolecek 
     75  1.11.2.3  jdolecek #define	EVTCODE_TO_MAP_INDEX(x)		(((x) - 0x200) >> 5)
     76  1.11.2.3  jdolecek #define	EVTCODE_TO_IH_INDEX(x)						\
     77  1.11.2.3  jdolecek 	__intc_evtcode_to_ih[EVTCODE_TO_MAP_INDEX(x)]
     78  1.11.2.3  jdolecek #define	EVTCODE_IH(x)	(&__intc_intrhand[EVTCODE_TO_IH_INDEX(x)])
     79  1.11.2.3  jdolecek extern int8_t __intc_evtcode_to_ih[];
     80  1.11.2.3  jdolecek extern struct intc_intrhand __intc_intrhand[];
     81  1.11.2.3  jdolecek 
     82  1.11.2.3  jdolecek void intc_init(void);
     83  1.11.2.3  jdolecek void *intc_intr_establish(int, int, int, int (*)(void *), void *);
     84  1.11.2.3  jdolecek void intc_intr_disestablish(void *);
     85  1.11.2.3  jdolecek void intc_intr(int, int, int);
     86  1.11.2.3  jdolecek 
     87  1.11.2.3  jdolecek /*
     88  1.11.2.3  jdolecek  * software simulated interrupt
     89  1.11.2.3  jdolecek  */
     90  1.11.2.3  jdolecek struct sh_soft_intrhand {
     91  1.11.2.3  jdolecek 	TAILQ_ENTRY(sh_soft_intrhand) sih_q;
     92  1.11.2.3  jdolecek 	struct sh_soft_intr *sih_intrhead;
     93  1.11.2.3  jdolecek 	void	(*sih_fn)(void *);
     94  1.11.2.3  jdolecek 	void	*sih_arg;
     95  1.11.2.3  jdolecek 	int	sih_pending;
     96  1.11.2.3  jdolecek };
     97  1.11.2.3  jdolecek 
     98  1.11.2.3  jdolecek struct sh_soft_intr {
     99  1.11.2.3  jdolecek 	TAILQ_HEAD(, sh_soft_intrhand) softintr_q;
    100  1.11.2.3  jdolecek 	struct evcnt softintr_evcnt;
    101  1.11.2.3  jdolecek 	struct simplelock softintr_slock;
    102  1.11.2.3  jdolecek 	unsigned long softintr_ipl;
    103  1.11.2.3  jdolecek };
    104  1.11.2.3  jdolecek 
    105  1.11.2.3  jdolecek #define	softintr_schedule(arg)						\
    106  1.11.2.3  jdolecek do {									\
    107  1.11.2.3  jdolecek 	struct sh_soft_intrhand *__sih = (arg);				\
    108  1.11.2.3  jdolecek 	struct sh_soft_intr *__si = __sih->sih_intrhead;		\
    109  1.11.2.3  jdolecek 	int __s;							\
    110  1.11.2.3  jdolecek 									\
    111  1.11.2.3  jdolecek 	__s = _cpu_intr_suspend();					\
    112  1.11.2.3  jdolecek 	simple_lock(&__si->softintr_slock);				\
    113  1.11.2.3  jdolecek 	if (__sih->sih_pending == 0) {					\
    114  1.11.2.3  jdolecek 		TAILQ_INSERT_TAIL(&__si->softintr_q, __sih, sih_q);	\
    115  1.11.2.3  jdolecek 		__sih->sih_pending = 1;					\
    116  1.11.2.3  jdolecek 		setsoft(__si->softintr_ipl);				\
    117  1.11.2.3  jdolecek 	}								\
    118  1.11.2.3  jdolecek 	simple_unlock(&__si->softintr_slock);				\
    119  1.11.2.3  jdolecek 	_cpu_intr_resume(__s);						\
    120  1.11.2.3  jdolecek } while (/*CONSTCOND*/0)
    121  1.11.2.3  jdolecek 
    122  1.11.2.3  jdolecek void softintr_init(void);
    123  1.11.2.3  jdolecek void *softintr_establish(int, void (*)(void *), void *);
    124  1.11.2.3  jdolecek void softintr_disestablish(void *);
    125  1.11.2.3  jdolecek void softintr_dispatch(int);
    126  1.11.2.3  jdolecek void setsoft(int);
    127       1.1    itojun 
    128  1.11.2.3  jdolecek /* XXX For legacy software interrupts. */
    129  1.11.2.3  jdolecek extern struct sh_soft_intrhand *softnet_intrhand;
    130       1.1    itojun 
    131  1.11.2.3  jdolecek #define	setsoftnet()	softintr_schedule(softnet_intrhand)
    132       1.1    itojun 
    133       1.1    itojun #endif /* !_SH3_INTR_H_ */
    134