kern_softint.c revision 1.1.6.2 1 1.1.6.2 joerg /* $NetBSD: kern_softint.c,v 1.1.6.2 2007/11/06 19:25:31 joerg Exp $ */
2 1.1.6.1 joerg
3 1.1.6.1 joerg /*-
4 1.1.6.1 joerg * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 1.1.6.1 joerg * All rights reserved.
6 1.1.6.1 joerg *
7 1.1.6.1 joerg * This code is derived from software contributed to The NetBSD Foundation
8 1.1.6.1 joerg * by Andrew Doran.
9 1.1.6.1 joerg *
10 1.1.6.1 joerg * Redistribution and use in source and binary forms, with or without
11 1.1.6.1 joerg * modification, are permitted provided that the following conditions
12 1.1.6.1 joerg * are met:
13 1.1.6.1 joerg * 1. Redistributions of source code must retain the above copyright
14 1.1.6.1 joerg * notice, this list of conditions and the following disclaimer.
15 1.1.6.1 joerg * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.6.1 joerg * notice, this list of conditions and the following disclaimer in the
17 1.1.6.1 joerg * documentation and/or other materials provided with the distribution.
18 1.1.6.1 joerg * 3. All advertising materials mentioning features or use of this software
19 1.1.6.1 joerg * must display the following acknowledgement:
20 1.1.6.1 joerg * This product includes software developed by the NetBSD
21 1.1.6.1 joerg * Foundation, Inc. and its contributors.
22 1.1.6.1 joerg * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.6.1 joerg * contributors may be used to endorse or promote products derived
24 1.1.6.1 joerg * from this software without specific prior written permission.
25 1.1.6.1 joerg *
26 1.1.6.1 joerg * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.6.1 joerg * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.6.1 joerg * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.6.1 joerg * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.6.1 joerg * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.6.1 joerg * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.6.1 joerg * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.6.1 joerg * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.6.1 joerg * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.6.1 joerg * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.6.1 joerg * POSSIBILITY OF SUCH DAMAGE.
37 1.1.6.1 joerg */
38 1.1.6.1 joerg
39 1.1.6.1 joerg /*
40 1.1.6.1 joerg * Stub for code to be merged from the vmlocking CVS branch.
41 1.1.6.1 joerg */
42 1.1.6.1 joerg
43 1.1.6.1 joerg #include <sys/cdefs.h>
44 1.1.6.2 joerg __KERNEL_RCSID(0, "$NetBSD: kern_softint.c,v 1.1.6.2 2007/11/06 19:25:31 joerg Exp $");
45 1.1.6.1 joerg
46 1.1.6.1 joerg #include <sys/param.h>
47 1.1.6.1 joerg #include <sys/intr.h>
48 1.1.6.1 joerg
49 1.1.6.1 joerg u_int softint_timing;
50 1.1.6.1 joerg
51 1.1.6.1 joerg /*
52 1.1.6.1 joerg * softint_init:
53 1.1.6.1 joerg *
54 1.1.6.1 joerg * Initialize per-CPU data structures. Called from mi_cpu_attach().
55 1.1.6.1 joerg */
56 1.1.6.1 joerg void
57 1.1.6.1 joerg softint_init(struct cpu_info *ci)
58 1.1.6.1 joerg {
59 1.1.6.1 joerg
60 1.1.6.1 joerg /* nothing yet */
61 1.1.6.1 joerg }
62 1.1.6.1 joerg
63 1.1.6.1 joerg /*
64 1.1.6.1 joerg * softint_establish:
65 1.1.6.1 joerg *
66 1.1.6.1 joerg * Register a software interrupt handler.
67 1.1.6.1 joerg */
68 1.1.6.1 joerg void *
69 1.1.6.1 joerg softint_establish(u_int flags, void (*func)(void *), void *arg)
70 1.1.6.1 joerg {
71 1.1.6.1 joerg u_int level;
72 1.1.6.1 joerg
73 1.1.6.1 joerg level = (flags & SOFTINT_LVLMASK);
74 1.1.6.1 joerg KASSERT(level < SOFTINT_COUNT);
75 1.1.6.1 joerg
76 1.1.6.1 joerg switch (level) {
77 1.1.6.1 joerg case SOFTINT_CLOCK:
78 1.1.6.1 joerg level = IPL_SOFTCLOCK;
79 1.1.6.1 joerg break;
80 1.1.6.1 joerg case SOFTINT_NET:
81 1.1.6.1 joerg case SOFTINT_BIO:
82 1.1.6.1 joerg level = IPL_SOFTNET;
83 1.1.6.1 joerg break;
84 1.1.6.1 joerg case SOFTINT_SERIAL:
85 1.1.6.1 joerg #ifdef IPL_SOFTSERIAL
86 1.1.6.1 joerg level = IPL_SOFTSERIAL;
87 1.1.6.1 joerg #else
88 1.1.6.1 joerg level = IPL_SOFTNET;
89 1.1.6.1 joerg #endif
90 1.1.6.1 joerg break;
91 1.1.6.1 joerg default:
92 1.1.6.1 joerg panic("softint_establish");
93 1.1.6.1 joerg }
94 1.1.6.1 joerg
95 1.1.6.1 joerg return softintr_establish(level, func, arg);
96 1.1.6.1 joerg }
97 1.1.6.1 joerg
98 1.1.6.1 joerg /*
99 1.1.6.1 joerg * softint_disestablish:
100 1.1.6.1 joerg *
101 1.1.6.1 joerg * Unregister a software interrupt handler.
102 1.1.6.1 joerg */
103 1.1.6.1 joerg void
104 1.1.6.1 joerg softint_disestablish(void *arg)
105 1.1.6.1 joerg {
106 1.1.6.1 joerg
107 1.1.6.1 joerg softintr_disestablish(arg);
108 1.1.6.1 joerg }
109 1.1.6.1 joerg
110 1.1.6.1 joerg /*
111 1.1.6.1 joerg * softint_schedule:
112 1.1.6.1 joerg *
113 1.1.6.1 joerg * Trigger a software interrupt. Must be called from a hardware
114 1.1.6.1 joerg * interrupt handler, or with preemption disabled (since we are
115 1.1.6.1 joerg * using the value of curcpu()).
116 1.1.6.1 joerg */
117 1.1.6.1 joerg void
118 1.1.6.1 joerg softint_schedule(void *arg)
119 1.1.6.1 joerg {
120 1.1.6.1 joerg
121 1.1.6.1 joerg softintr_schedule(arg);
122 1.1.6.1 joerg }
123 1.1.6.1 joerg
124 1.1.6.1 joerg /*
125 1.1.6.1 joerg * softint_block:
126 1.1.6.1 joerg *
127 1.1.6.1 joerg * Update statistics when the soft interrupt blocks.
128 1.1.6.1 joerg */
129 1.1.6.1 joerg void
130 1.1.6.1 joerg softint_block(lwp_t *l)
131 1.1.6.1 joerg {
132 1.1.6.1 joerg
133 1.1.6.1 joerg /* nothing yet */
134 1.1.6.1 joerg }
135 1.1.6.2 joerg
136 1.1.6.2 joerg /*
137 1.1.6.2 joerg * softint_picklwp:
138 1.1.6.2 joerg *
139 1.1.6.2 joerg * Slow path: called from mi_switch() to pick the highest priority
140 1.1.6.2 joerg * soft interrupt LWP that needs to run.
141 1.1.6.2 joerg */
142 1.1.6.2 joerg lwp_t *
143 1.1.6.2 joerg softint_picklwp(void)
144 1.1.6.2 joerg {
145 1.1.6.2 joerg
146 1.1.6.2 joerg panic("softint_picklwp");
147 1.1.6.2 joerg }
148 1.1.6.2 joerg
149 1.1.6.2 joerg /*
150 1.1.6.2 joerg * softint_overlay:
151 1.1.6.2 joerg *
152 1.1.6.2 joerg * Slow path: called from lwp_userret() to run a soft interrupt
153 1.1.6.2 joerg * within the context of a user thread. If the LWP blocks,
154 1.1.6.2 joerg * priority will be elevated in sched_kpri().
155 1.1.6.2 joerg */
156 1.1.6.2 joerg void
157 1.1.6.2 joerg softint_overlay(void)
158 1.1.6.2 joerg {
159 1.1.6.2 joerg
160 1.1.6.2 joerg panic("softint_overlay");
161 1.1.6.2 joerg }
162 1.1.6.2 joerg
163 1.1.6.2 joerg /*
164 1.1.6.2 joerg * softint_kpri:
165 1.1.6.2 joerg *
166 1.1.6.2 joerg * Adjust priority for a blocking user LWP that is handling a
167 1.1.6.2 joerg * soft interrupt.
168 1.1.6.2 joerg */
169 1.1.6.2 joerg pri_t
170 1.1.6.2 joerg softint_kpri(lwp_t *l)
171 1.1.6.2 joerg {
172 1.1.6.2 joerg
173 1.1.6.2 joerg /* No point doing anything more fair / complicated. */
174 1.1.6.2 joerg return PRI_SOFTSERIAL;
175 1.1.6.2 joerg }
176