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