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