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