xref: /netbsd-src/sys/arch/or1k/include/intr.h (revision 87fd18f8e547eaf74cc8b13c2004dc30f5ff1662)
1 /* $NetBSD: intr.h,v 1.2 2018/04/19 21:50:07 christos Exp $ */
2 
3 /*-
4  * Copyright (c) 2014 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Matt Thomas of 3am Software Foundry.
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  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _OR1K_INTR_H_
33 #define _OR1K_INTR_H_
34 
35 #ifdef _LOCORE
36 #error use "assym.h"
37 #endif
38 
39 #ifdef _KERNEL
40 
41 #ifdef _KERNEL_OPT
42 #include "opt_multiprocessor.h"
43 #endif
44 
45 #ifdef MULTIPROCESSOR
46 #define __HAVE_PREEMPTION	1
47 #endif
48 
49 /* Interrupt priority "levels". */
50 #define	IPL_NONE	0		/* nothing */
51 #define	IPL_SOFTCLOCK	1		/* clock */
52 #define	IPL_SOFTBIO	2		/* block I/O */
53 #define	IPL_SOFTNET	3		/* software network interrupt */
54 #define	IPL_SOFTSERIAL	4		/* software serial interrupt */
55 #define	IPL_VM		5		/* memory allocation */
56 #define	IPL_SCHED	6		/* clock interrupt */
57 #define	IPL_HIGH	7		/* everything */
58 
59 #define	NIPL		8
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 #define IST_LEVEL_LOW	IST_LEVEL
68 #define IST_LEVEL_HIGH	4
69 #define IST_EDGE_FALLING IST_EDGE
70 #define IST_EDGE_RISING	5
71 #define IST_EDGE_BOTH	6
72 #define IST_SOFT	7
73 
74 #include <or1k/pic/picvar.h>
75 
76 static __inline void
spl0(void)77 spl0(void)
78 {
79 	(void)_spllower(IPL_NONE);
80 }
81 
82 static __inline int
splsoftclock(void)83 splsoftclock(void)
84 {
85 	return _splraise(IPL_SOFTCLOCK);
86 }
87 
88 static __inline int
splsoftbio(void)89 splsoftbio(void)
90 {
91 	return _splraise(IPL_SOFTBIO);
92 }
93 
94 static __inline int
splsoftnet(void)95 splsoftnet(void)
96 {
97 	return _splraise(IPL_SOFTNET);
98 }
99 
100 static __inline int
splsoftserial(void)101 splsoftserial(void)
102 {
103 	return _splraise(IPL_SOFTSERIAL);
104 }
105 
106 static __inline int
splvm(void)107 splvm(void)
108 {
109 	return _splraise(IPL_VM);
110 }
111 
112 static __inline int
splsched(void)113 splsched(void)
114 {
115 	return _splraise(IPL_SCHED);
116 }
117 
118 static __inline int
splhigh(void)119 splhigh(void)
120 {
121 	return _splraise(IPL_HIGH);
122 }
123 
124 typedef uint8_t ipl_t;
125 typedef struct {
126 	ipl_t _ipl;
127 } ipl_cookie_t;
128 
129 static __inline ipl_cookie_t
makeiplcookie(ipl_t ipl)130 makeiplcookie(ipl_t ipl)
131 {
132 
133 	return (ipl_cookie_t){._ipl = ipl};
134 }
135 
136 static __inline int
splraiseipl(ipl_cookie_t icookie)137 splraiseipl(ipl_cookie_t icookie)
138 {
139 
140 	return _splraise(icookie._ipl);
141 }
142 
143 #endif /* _KERNEL */
144 
145 #endif /* _OR1K_INTR_H_ */
146