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