1*0a6a1f1dSLionel Sambuc /* $NetBSD: intr.h,v 1.26 2014/03/13 23:48:38 matt Exp $ */
284d9c625SLionel Sambuc
384d9c625SLionel Sambuc /*
484d9c625SLionel Sambuc * Copyright (c) 2001, 2003 Wasabi Systems, Inc.
584d9c625SLionel Sambuc * All rights reserved.
684d9c625SLionel Sambuc *
784d9c625SLionel Sambuc * Written by Jason R. Thorpe for Wasabi Systems, Inc.
884d9c625SLionel Sambuc *
984d9c625SLionel Sambuc * Redistribution and use in source and binary forms, with or without
1084d9c625SLionel Sambuc * modification, are permitted provided that the following conditions
1184d9c625SLionel Sambuc * are met:
1284d9c625SLionel Sambuc * 1. Redistributions of source code must retain the above copyright
1384d9c625SLionel Sambuc * notice, this list of conditions and the following disclaimer.
1484d9c625SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
1584d9c625SLionel Sambuc * notice, this list of conditions and the following disclaimer in the
1684d9c625SLionel Sambuc * documentation and/or other materials provided with the distribution.
1784d9c625SLionel Sambuc * 3. All advertising materials mentioning features or use of this software
1884d9c625SLionel Sambuc * must display the following acknowledgement:
1984d9c625SLionel Sambuc * This product includes software developed for the NetBSD Project by
2084d9c625SLionel Sambuc * Wasabi Systems, Inc.
2184d9c625SLionel Sambuc * 4. The name of Wasabi Systems, Inc. may not be used to endorse
2284d9c625SLionel Sambuc * or promote products derived from this software without specific prior
2384d9c625SLionel Sambuc * written permission.
2484d9c625SLionel Sambuc *
2584d9c625SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
2684d9c625SLionel Sambuc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2784d9c625SLionel Sambuc * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2884d9c625SLionel Sambuc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
2984d9c625SLionel Sambuc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3084d9c625SLionel Sambuc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3184d9c625SLionel Sambuc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3284d9c625SLionel Sambuc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3384d9c625SLionel Sambuc * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3484d9c625SLionel Sambuc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3584d9c625SLionel Sambuc * POSSIBILITY OF SUCH DAMAGE.
3684d9c625SLionel Sambuc */
3784d9c625SLionel Sambuc
3884d9c625SLionel Sambuc #ifndef _EVBARM_INTR_H_
3984d9c625SLionel Sambuc #define _EVBARM_INTR_H_
4084d9c625SLionel Sambuc
4184d9c625SLionel Sambuc #ifdef _KERNEL
4284d9c625SLionel Sambuc
4384d9c625SLionel Sambuc /* Interrupt priority "levels". */
4484d9c625SLionel Sambuc #define IPL_NONE 0 /* nothing */
4584d9c625SLionel Sambuc #define IPL_SOFTCLOCK 1 /* clock */
4684d9c625SLionel Sambuc #define IPL_SOFTBIO 2 /* block I/O */
4784d9c625SLionel Sambuc #define IPL_SOFTNET 3 /* software network interrupt */
4884d9c625SLionel Sambuc #define IPL_SOFTSERIAL 4 /* software serial interrupt */
4984d9c625SLionel Sambuc #define IPL_VM 5 /* memory allocation */
5084d9c625SLionel Sambuc #define IPL_SCHED 6 /* clock interrupt */
5184d9c625SLionel Sambuc #define IPL_HIGH 7 /* everything */
5284d9c625SLionel Sambuc
5384d9c625SLionel Sambuc #define NIPL 8
5484d9c625SLionel Sambuc
5584d9c625SLionel Sambuc /* Interrupt sharing types. */
5684d9c625SLionel Sambuc #define IST_NONE 0 /* none */
5784d9c625SLionel Sambuc #define IST_PULSE 1 /* pulsed */
5884d9c625SLionel Sambuc #define IST_EDGE 2 /* edge-triggered */
5984d9c625SLionel Sambuc #define IST_LEVEL 3 /* level-triggered */
6084d9c625SLionel Sambuc
6184d9c625SLionel Sambuc #define IST_LEVEL_LOW IST_LEVEL
6284d9c625SLionel Sambuc #define IST_LEVEL_HIGH 4
6384d9c625SLionel Sambuc #define IST_EDGE_FALLING IST_EDGE
6484d9c625SLionel Sambuc #define IST_EDGE_RISING 5
6584d9c625SLionel Sambuc #define IST_EDGE_BOTH 6
6684d9c625SLionel Sambuc #define IST_SOFT 7
6784d9c625SLionel Sambuc
68*0a6a1f1dSLionel Sambuc #define IST_MPSAFE 0x100 /* interrupt is MPSAFE */
69*0a6a1f1dSLionel Sambuc
7084d9c625SLionel Sambuc #ifndef _LOCORE
7184d9c625SLionel Sambuc
7284d9c625SLionel Sambuc #include <sys/queue.h>
7384d9c625SLionel Sambuc
7484d9c625SLionel Sambuc #if defined(_LKM)
7584d9c625SLionel Sambuc
7684d9c625SLionel Sambuc int _splraise(int);
7784d9c625SLionel Sambuc int _spllower(int);
7884d9c625SLionel Sambuc void splx(int);
7984d9c625SLionel Sambuc
8084d9c625SLionel Sambuc #else /* _LKM */
8184d9c625SLionel Sambuc
8284d9c625SLionel Sambuc #include "opt_arm_intr_impl.h"
8384d9c625SLionel Sambuc
8484d9c625SLionel Sambuc #if defined(ARM_INTR_IMPL)
8584d9c625SLionel Sambuc
8684d9c625SLionel Sambuc /*
8784d9c625SLionel Sambuc * Each board needs to define the following functions:
8884d9c625SLionel Sambuc *
8984d9c625SLionel Sambuc * int _splraise(int);
9084d9c625SLionel Sambuc * int _spllower(int);
9184d9c625SLionel Sambuc * void splx(int);
9284d9c625SLionel Sambuc *
9384d9c625SLionel Sambuc * These may be defined as functions, static inline functions, or macros,
9484d9c625SLionel Sambuc * but there must be a _spllower() and splx() defined as functions callable
9584d9c625SLionel Sambuc * from assembly language (for cpu_switch()). However, since it's quite
9684d9c625SLionel Sambuc * useful to be able to inline splx(), you could do something like the
9784d9c625SLionel Sambuc * following:
9884d9c625SLionel Sambuc *
9984d9c625SLionel Sambuc * in <boardtype>_intr.h:
10084d9c625SLionel Sambuc * static inline int
10184d9c625SLionel Sambuc * boardtype_splx(int spl)
10284d9c625SLionel Sambuc * {...}
10384d9c625SLionel Sambuc *
10484d9c625SLionel Sambuc * #define splx(nspl) boardtype_splx(nspl)
10584d9c625SLionel Sambuc * ...
10684d9c625SLionel Sambuc * and in boardtype's machdep code:
10784d9c625SLionel Sambuc *
10884d9c625SLionel Sambuc * ...
10984d9c625SLionel Sambuc * #undef splx
11084d9c625SLionel Sambuc * int
11184d9c625SLionel Sambuc * splx(int spl)
11284d9c625SLionel Sambuc * {
11384d9c625SLionel Sambuc * return boardtype_splx(spl);
11484d9c625SLionel Sambuc * }
11584d9c625SLionel Sambuc */
11684d9c625SLionel Sambuc
11784d9c625SLionel Sambuc #include ARM_INTR_IMPL
11884d9c625SLionel Sambuc
11984d9c625SLionel Sambuc #else /* ARM_INTR_IMPL */
12084d9c625SLionel Sambuc
12184d9c625SLionel Sambuc #error ARM_INTR_IMPL not defined.
12284d9c625SLionel Sambuc
12384d9c625SLionel Sambuc #endif /* ARM_INTR_IMPL */
12484d9c625SLionel Sambuc
12584d9c625SLionel Sambuc #endif /* _LKM */
12684d9c625SLionel Sambuc
12784d9c625SLionel Sambuc typedef uint8_t ipl_t;
12884d9c625SLionel Sambuc typedef struct {
12984d9c625SLionel Sambuc ipl_t _ipl;
13084d9c625SLionel Sambuc } ipl_cookie_t;
13184d9c625SLionel Sambuc
13284d9c625SLionel Sambuc static inline ipl_cookie_t
makeiplcookie(ipl_t ipl)13384d9c625SLionel Sambuc makeiplcookie(ipl_t ipl)
13484d9c625SLionel Sambuc {
13584d9c625SLionel Sambuc
13684d9c625SLionel Sambuc return (ipl_cookie_t){._ipl = ipl};
13784d9c625SLionel Sambuc }
13884d9c625SLionel Sambuc
13984d9c625SLionel Sambuc static inline int
splraiseipl(ipl_cookie_t icookie)14084d9c625SLionel Sambuc splraiseipl(ipl_cookie_t icookie)
14184d9c625SLionel Sambuc {
14284d9c625SLionel Sambuc
14384d9c625SLionel Sambuc return _splraise(icookie._ipl);
14484d9c625SLionel Sambuc }
14584d9c625SLionel Sambuc
14684d9c625SLionel Sambuc #define spl0() _spllower(IPL_NONE)
14784d9c625SLionel Sambuc
14884d9c625SLionel Sambuc #include <sys/spl.h>
14984d9c625SLionel Sambuc
15084d9c625SLionel Sambuc #endif /* ! _LOCORE */
15184d9c625SLionel Sambuc
15284d9c625SLionel Sambuc #endif /* _KERNEL */
15384d9c625SLionel Sambuc
15484d9c625SLionel Sambuc #endif /* _EVBARM_INTR_H_ */
155