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