]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/ast.h
xnu-344.21.73.tar.gz
[apple/xnu.git] / osfmk / kern / ast.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * @OSF_COPYRIGHT@
27 */
28 /*
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
31 * All Rights Reserved.
32 *
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
38 *
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
42 *
43 * Carnegie Mellon requests users of this software to return to
44 *
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
49 *
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
52 */
53 /*
54 */
55
56 /*
57 * kern/ast.h: Definitions for Asynchronous System Traps.
58 */
59
60 #ifndef _KERN_AST_H_
61 #define _KERN_AST_H_
62
63 #include <cpus.h>
64 #include <platforms.h>
65
66 #include <kern/assert.h>
67 #include <kern/cpu_number.h>
68 #include <kern/macro_help.h>
69 #include <kern/lock.h>
70 #include <kern/spl.h>
71 #include <machine/ast.h>
72
73 /*
74 * A processor takes an AST when it is about to return from an
75 * interrupt context, and calls ast_taken.
76 *
77 * Machine-dependent code is responsible for maintaining
78 * a set of reasons for an AST, and passing this set to ast_taken.
79 */
80 typedef uint32_t ast_t;
81
82 /*
83 * Bits for reasons
84 */
85 #define AST_BLOCK 0x01
86 #define AST_QUANTUM 0x02
87 #define AST_HANDOFF 0x04
88 #define AST_YIELD 0x08
89 #define AST_URGENT 0x10
90 #define AST_APC 0x20 /* migration APC hook */
91 /*
92 * JMM - This is here temporarily. AST_BSD is used to simulate a
93 * general purpose mechanism for setting asynchronous procedure calls
94 * from the outside.
95 */
96 #define AST_BSD 0x80
97
98 #define AST_NONE 0x00
99 #define AST_ALL (~AST_NONE)
100
101 #define AST_SCHEDULING (AST_PREEMPT | AST_YIELD | AST_HANDOFF)
102 #define AST_PREEMPT (AST_BLOCK | AST_QUANTUM | AST_URGENT)
103
104 extern volatile ast_t need_ast[NCPUS];
105
106 #ifdef MACHINE_AST
107 /*
108 * machine/ast.h is responsible for defining aston and astoff.
109 */
110 #else /* MACHINE_AST */
111
112 #define aston(mycpu)
113 #define astoff(mycpu)
114
115 #endif /* MACHINE_AST */
116
117 /* Initialize module */
118 extern void ast_init(void);
119
120 /* Handle ASTs */
121 extern void ast_taken(
122 ast_t mask,
123 boolean_t enable);
124
125 /* Check for pending ASTs */
126 extern void ast_check(
127 processor_t processor);
128
129 /*
130 * Per-thread ASTs are reset at context-switch time.
131 */
132 #ifndef MACHINE_AST_PER_THREAD
133 #define MACHINE_AST_PER_THREAD 0
134 #endif
135
136 #define AST_PER_THREAD (AST_APC | AST_BSD | MACHINE_AST_PER_THREAD)
137 /*
138 * ast_needed(), ast_on(), ast_off(), ast_context(), and ast_propagate()
139 * assume splsched.
140 */
141 #define ast_needed(mycpu) (need_ast[mycpu] != AST_NONE)
142
143 #define ast_on_fast(reasons) \
144 MACRO_BEGIN \
145 int mycpu = cpu_number(); \
146 if ((need_ast[mycpu] |= (reasons)) != AST_NONE) \
147 { aston(mycpu); } \
148 MACRO_END
149
150 #define ast_off_fast(reasons) \
151 MACRO_BEGIN \
152 int mycpu = cpu_number(); \
153 if ((need_ast[mycpu] &= ~(reasons)) == AST_NONE) \
154 { astoff(mycpu); } \
155 MACRO_END
156
157 #define ast_propagate(reasons) ast_on(reasons)
158
159 #define ast_context(act, mycpu) \
160 MACRO_BEGIN \
161 assert((mycpu) == cpu_number()); \
162 if ((need_ast[mycpu] = \
163 ((need_ast[mycpu] &~ AST_PER_THREAD) | (act)->ast)) != AST_NONE) \
164 { aston(mycpu); } \
165 else \
166 { astoff(mycpu); } \
167 MACRO_END
168
169 #define ast_on(reason) ast_on_fast(reason)
170 #define ast_off(reason) ast_off_fast(reason)
171
172 #define thread_ast_set(act, reason) \
173 (hw_atomic_or(&(act)->ast, (reason)))
174 #define thread_ast_clear(act, reason) \
175 (hw_atomic_and(&(act)->ast, ~(reason)))
176 #define thread_ast_clear_all(act) \
177 (hw_atomic_and(&(act)->ast, AST_NONE))
178
179 /*
180 * NOTE: if thread is the current thread, thread_ast_set() should
181 * be followed by ast_propagate().
182 */
183
184 #ifdef MACH_KERNEL_PRIVATE
185
186 #define ast_urgency() (need_ast[cpu_number()] & AST_URGENT)
187
188 #endif /* MACH_KERNEL_PRIVATE */
189
190 #endif /* _KERN_AST_H_ */