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