Home | History | Annotate | Line # | Download | only in include
intr.h revision 1.3.96.2
      1 /* $NetBSD: intr.h,v 1.3.96.2 2010/02/15 07:36:03 matt Exp $ */
      2 /*-
      3  * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
      4  * All rights reserved.
      5  *
      6  * This code is derived from software contributed to The NetBSD Foundation
      7  * by Matt Thomas <matt (at) 3am-software.com>.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     20  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28  * POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #ifndef _MIPS_INTR_H_
     32 #define	_MIPS_INTR_H_
     33 
     34 /*
     35  * This is a common <machine/intr.h> for all MIPS platforms.
     36  */
     37 
     38 #define	IPL_NONE	0
     39 #ifdef __HAVE_PREEMPTION
     40 #define	IPL_PREEMPT	(IPL_NONE+1)
     41 #else
     42 #define	IPL_PREEMPT	IPL_NONE
     43 #endif
     44 #define	IPL_SOFTCLOCK	(IPL_PREEMPT+1)
     45 #define	IPL_SOFTBIO	(IPL_SOFTCLOCK)		/* shares SWINT with softclock */
     46 #define	IPL_SOFTNET	(IPL_SOFTBIO+1)
     47 #define	IPL_SOFTSERIAL	(IPL_SOFTNET)		/* shares SWINT with softnet */
     48 #define	IPL_VM		(IPL_SOFTSERIAL+1)
     49 #define	IPL_SCHED	(IPL_VM+1)
     50 #define	IPL_HIGH	(IPL_SCHED)
     51 
     52 #define	_IPL_N		(IPL_HIGH+1)
     53 
     54 #define	IST_UNUSABLE	-1	/* interrupt cannot be used */
     55 #define	IST_NONE	0	/* none (dummy) */
     56 #define	IST_PULSE	1	/* pulsed */
     57 #define	IST_EDGE	2	/* edge-triggered */
     58 #define	IST_LEVEL	3	/* level-triggered */
     59 #define	IST_LEVEL_HIGH	4	/* level triggered, active high */
     60 #define	IST_LEVEL_LOW	5       /* level triggered, active low */
     61 
     62 struct splsw {
     63 	int	(*splsw_splhigh)(void);
     64 	int	(*splsw_splsched)(void);
     65 	int	(*splsw_splvm)(void);
     66 	int	(*splsw_splsoftserial)(void);
     67 	int	(*splsw_splsoftnet)(void);
     68 	int	(*splsw_splsoftbio)(void);
     69 	int	(*splsw_splsoftclock)(void);
     70 	int	(*splsw_splraise)(int);
     71 	void	(*splsw_spl0)(void);
     72 	void	(*splsw_splx)(int);
     73 	int	(*splsw_splhigh_noprof)(void);
     74 	void	(*splsw_splx_noprof)(int);
     75 	void	(*splsw_setsoftintr)(uint32_t);
     76 	void	(*splsw_clrsoftintr)(uint32_t);
     77 	int	(*splsw_splintr)(uint32_t *);
     78 	void	(*splsw_splcheck)(void);
     79 };
     80 
     81 typedef int ipl_t;
     82 typedef struct {
     83         ipl_t _spl;
     84 } ipl_cookie_t;
     85 
     86 #ifdef _KERNEL
     87 extern	struct splsw	mips_splsw;
     88 extern	const uint32_t	ipl_sr_bits[_IPL_N];
     89 
     90 static inline int
     91 splhigh(void)
     92 {
     93 	return (*mips_splsw.splsw_splhigh)();
     94 }
     95 
     96 static inline int
     97 splhigh_noprof(void)
     98 {
     99 	return (*mips_splsw.splsw_splhigh_noprof)();
    100 }
    101 
    102 static inline int
    103 splsched(void)
    104 {
    105 	return (*mips_splsw.splsw_splsched)();
    106 }
    107 
    108 static inline int
    109 splvm(void)
    110 {
    111 	return (*mips_splsw.splsw_splvm)();
    112 }
    113 
    114 static inline int
    115 splsoftserial(void)
    116 {
    117 	return (*mips_splsw.splsw_splsoftserial)();
    118 }
    119 
    120 static inline int
    121 splsoftnet(void)
    122 {
    123 	return (*mips_splsw.splsw_splsoftnet)();
    124 }
    125 
    126 static inline int
    127 splsoftbio(void)
    128 {
    129 	return (*mips_splsw.splsw_splsoftbio)();
    130 }
    131 
    132 static inline int
    133 splsoftclock(void)
    134 {
    135 	return (*mips_splsw.splsw_splsoftclock)();
    136 }
    137 
    138 static inline void
    139 spl0(void)
    140 {
    141 	(*mips_splsw.splsw_spl0)();
    142 }
    143 
    144 static inline void
    145 splx(int s)
    146 {
    147 	(*mips_splsw.splsw_splx)(s);
    148 }
    149 
    150 static inline void
    151 splx_noprof(int s)
    152 {
    153 	(*mips_splsw.splsw_splx_noprof)(s);
    154 }
    155 
    156 static inline void
    157 _setsoftintr(uint32_t m)
    158 {
    159 	(*mips_splsw.splsw_setsoftintr)(m);
    160 }
    161 
    162 static inline void
    163 _clrsoftintr(uint32_t m)
    164 {
    165 	(*mips_splsw.splsw_clrsoftintr)(m);
    166 }
    167 
    168 static inline ipl_cookie_t
    169 makeiplcookie(ipl_t s)
    170 {
    171 	return (ipl_cookie_t){._spl = s};
    172 }
    173 
    174 static inline int
    175 splraise(int s)
    176 {
    177         return (*mips_splsw.splsw_splraise)(s);
    178 }
    179 
    180 static inline int
    181 splraiseipl(ipl_cookie_t icookie)
    182 {
    183 	return splraise(icookie._spl);
    184 }
    185 
    186 static inline int
    187 splintr(uint32_t *p)
    188 {
    189 	return (*mips_splsw.splsw_splintr)(p);
    190 }
    191 
    192 #endif /* _KERNEL */
    193 #endif /* _MIPS_INTR_H_ */
    194