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