Home | History | Annotate | Line # | Download | only in include
intr.h revision 1.9
      1  1.9   tsutsui /*	$NetBSD: intr.h,v 1.9 2006/10/05 14:24:10 tsutsui Exp $	*/
      2  1.1  fredette 
      3  1.1  fredette /*
      4  1.1  fredette  * Copyright (c) 2001 Matt Fredette.
      5  1.1  fredette  * Copyright (c) 1998 Matt Thomas.
      6  1.1  fredette  * All rights reserved.
      7  1.1  fredette  *
      8  1.1  fredette  * Redistribution and use in source and binary forms, with or without
      9  1.1  fredette  * modification, are permitted provided that the following conditions
     10  1.1  fredette  * are met:
     11  1.1  fredette  * 1. Redistributions of source code must retain the above copyright
     12  1.1  fredette  *    notice, this list of conditions and the following disclaimer.
     13  1.1  fredette  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1  fredette  *    notice, this list of conditions and the following disclaimer in the
     15  1.1  fredette  *    documentation and/or other materials provided with the distribution.
     16  1.1  fredette  * 3. The name of the company nor the names of the authors may be used to
     17  1.1  fredette  *    endorse or promote products derived from this software without specific
     18  1.1  fredette  *    prior written permission.
     19  1.1  fredette  *
     20  1.1  fredette  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
     21  1.1  fredette  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     22  1.1  fredette  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  1.1  fredette  * IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     24  1.1  fredette  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     25  1.1  fredette  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     26  1.1  fredette  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     27  1.1  fredette  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     28  1.1  fredette  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     29  1.1  fredette  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     30  1.1  fredette  * SUCH DAMAGE.
     31  1.1  fredette  */
     32  1.1  fredette 
     33  1.1  fredette #ifndef _SUN68K_INTR_H_
     34  1.1  fredette #define _SUN68K_INTR_H_
     35  1.1  fredette 
     36  1.1  fredette #include <sys/queue.h>
     37  1.3       chs #include <m68k/psl.h>
     38  1.1  fredette 
     39  1.1  fredette /*
     40  1.1  fredette  * Interrupt levels.  Right now these correspond to real
     41  1.1  fredette  * hardware levels, but I don't think anything counts on
     42  1.1  fredette  * that (yet?).
     43  1.1  fredette  */
     44  1.1  fredette #define _IPL_SOFT_LEVEL1	1
     45  1.1  fredette #define _IPL_SOFT_LEVEL2	2
     46  1.1  fredette #define _IPL_SOFT_LEVEL3	3
     47  1.1  fredette #define _IPL_SOFT_LEVEL_MIN	1
     48  1.1  fredette #define _IPL_SOFT_LEVEL_MAX	3
     49  1.7      yamt 
     50  1.7      yamt #define	IPL_NONE	0
     51  1.8   tsutsui #define	IPL_SOFT_LEVEL1	(PSL_S|PSL_IPL1)
     52  1.8   tsutsui #define	IPL_SOFT_LEVEL2	(PSL_S|PSL_IPL2)
     53  1.8   tsutsui #define	IPL_SOFT_LEVEL3	(PSL_S|PSL_IPL3)
     54  1.8   tsutsui #define	IPL_SOFTCLOCK	IPL_SOFT_LEVEL1
     55  1.8   tsutsui #define	IPL_SOFTNET	IPL_SOFT_LEVEL1
     56  1.7      yamt #define	IPL_BIO		(PSL_S|PSL_IPL2)
     57  1.7      yamt #define	IPL_NET		(PSL_S|PSL_IPL3)
     58  1.8   tsutsui #define	IPL_SOFTSERIAL	IPL_SOFT_LEVEL3
     59  1.7      yamt #define	IPL_TTY		(PSL_S|PSL_IPL4)
     60  1.7      yamt #define	IPL_VM		(PSL_S|PSL_IPL4)
     61  1.7      yamt /* Intersil or Am9513 clock hardware interrupts (hard-wired at 5) */
     62  1.7      yamt #define	IPL_CLOCK	(PSL_S|PSL_IPL5)
     63  1.7      yamt #define	IPL_STATCLOCK	IPL_CLOCK
     64  1.7      yamt #define	IPL_SCHED	(PSL_S|PSL_IPL7)
     65  1.7      yamt #define	IPL_HIGH	(PSL_S|PSL_IPL7)
     66  1.7      yamt #define	IPL_LOCK	(PSL_S|PSL_IPL7)
     67  1.7      yamt #define	IPL_SERIAL	(PSL_S|PSL_IPL6)
     68  1.1  fredette 
     69  1.1  fredette #ifdef _KERNEL
     70  1.1  fredette LIST_HEAD(sh_head, softintr_handler);
     71  1.1  fredette 
     72  1.1  fredette struct softintr_head {
     73  1.1  fredette 	int shd_ipl;
     74  1.1  fredette 	struct sh_head shd_intrs;
     75  1.1  fredette };
     76  1.1  fredette 
     77  1.1  fredette struct softintr_handler {
     78  1.1  fredette 	struct softintr_head *sh_head;
     79  1.1  fredette 	LIST_ENTRY(softintr_handler) sh_link;
     80  1.1  fredette 	void (*sh_func)(void *);
     81  1.1  fredette 	void *sh_arg;
     82  1.1  fredette 	int sh_pending;
     83  1.1  fredette };
     84  1.1  fredette 
     85  1.9   tsutsui void softintr_init(void);
     86  1.9   tsutsui void *softintr_establish(int, void (*)(void *), void *);
     87  1.9   tsutsui void softintr_disestablish(void *);
     88  1.9   tsutsui 
     89  1.9   tsutsui /* These control the software interrupt register. */
     90  1.9   tsutsui void isr_soft_request(int);
     91  1.9   tsutsui void isr_soft_clear(int);
     92  1.1  fredette 
     93  1.6     perry static __inline void
     94  1.1  fredette softintr_schedule(void *arg)
     95  1.1  fredette {
     96  1.1  fredette 	struct softintr_handler * const sh = arg;
     97  1.1  fredette 	if (sh->sh_pending == 0) {
     98  1.1  fredette 		sh->sh_pending = 1;
     99  1.1  fredette 		isr_soft_request(sh->sh_head->shd_ipl);
    100  1.1  fredette 	}
    101  1.1  fredette }
    102  1.1  fredette 
    103  1.9   tsutsui extern void *softnet_cookie;
    104  1.9   tsutsui #define setsoftnet()	softintr_schedule(softnet_cookie)
    105  1.9   tsutsui 
    106  1.1  fredette /* These connect interrupt handlers. */
    107  1.2       chs typedef int (*isr_func_t)(void *);
    108  1.9   tsutsui void isr_add_autovect(isr_func_t, void *, int);
    109  1.9   tsutsui void isr_add_vectored(isr_func_t, void *, int, int);
    110  1.9   tsutsui void isr_add_custom(int, void *);
    111  1.1  fredette 
    112  1.3       chs /*
    113  1.3       chs  * Define inline functions for PSL manipulation.
    114  1.3       chs  * These are as close to macros as one can get.
    115  1.3       chs  * When not optimizing gcc will call the locore.s
    116  1.3       chs  * functions by the same names, so breakpoints on
    117  1.3       chs  * these functions will work normally, etc.
    118  1.3       chs  * (See the GCC extensions info document.)
    119  1.3       chs  */
    120  1.3       chs 
    121  1.6     perry static __inline int _getsr(void);
    122  1.3       chs 
    123  1.3       chs /* Get current sr value. */
    124  1.6     perry static __inline int
    125  1.3       chs _getsr(void)
    126  1.3       chs {
    127  1.3       chs 	int rv;
    128  1.3       chs 
    129  1.5     perry 	__asm volatile ("clrl %0; movew %%sr,%0" : "=&d" (rv));
    130  1.3       chs 	return (rv);
    131  1.3       chs }
    132  1.3       chs 
    133  1.3       chs /*
    134  1.3       chs  * The rest of this is sun68k specific, because other ports may
    135  1.3       chs  * need to do special things in spl0() (i.e. simulate SIR).
    136  1.3       chs  * Suns have a REAL interrupt register, so spl0() and splx(s)
    137  1.3       chs  * have no need to check for any simulated interrupts, etc.
    138  1.3       chs  */
    139  1.3       chs 
    140  1.3       chs #define spl0()  _spl0()		/* we have real software interrupts */
    141  1.3       chs #define splx(x)	_spl(x)
    142  1.3       chs 
    143  1.3       chs /* IPL used by soft interrupts: netintr(), softclock() */
    144  1.3       chs #define	spllowersoftclock() spl1()
    145  1.3       chs 
    146  1.3       chs /* Zilog Serial hardware interrupts (hard-wired at 6) */
    147  1.3       chs #define splzs()		spl6()
    148  1.3       chs 
    149  1.3       chs /* This returns true iff the spl given is spl0. */
    150  1.3       chs #define	is_spl0(s)	(((s) & PSL_IPL7) == 0)
    151  1.3       chs 
    152  1.7      yamt #define	splraiseipl(x)	_splraise(x)
    153  1.7      yamt 
    154  1.7      yamt #include <sys/spl.h>
    155  1.7      yamt 
    156  1.3       chs #endif	/* _KERNEL */
    157  1.3       chs 
    158  1.1  fredette #endif	/* _SUN68K_INTR_H */
    159