]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
8ad349bb | 2 | * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. |
1c79356b | 3 | * |
8ad349bb | 4 | * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ |
1c79356b | 5 | * |
8ad349bb 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 | |
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@ | |
1c79356b A |
29 | */ |
30 | /* | |
31 | * @OSF_COPYRIGHT@ | |
32 | * | |
33 | */ | |
34 | ||
35 | #ifndef I386_CPU_DATA | |
36 | #define I386_CPU_DATA | |
37 | ||
1c79356b A |
38 | #include <mach_assert.h> |
39 | ||
40 | #if defined(__GNUC__) | |
41 | ||
42 | #include <kern/assert.h> | |
43 | #include <kern/kern_types.h> | |
91447636 | 44 | #include <kern/processor.h> |
55e303ae | 45 | #include <pexpert/pexpert.h> |
8ad349bb | 46 | |
91447636 A |
47 | |
48 | /* | |
49 | * Data structures referenced (anonymously) from per-cpu data: | |
50 | */ | |
51 | struct cpu_core; | |
52 | struct cpu_cons_buffer; | |
8ad349bb | 53 | struct mp_desc_table; |
91447636 A |
54 | |
55 | ||
56 | /* | |
57 | * Data structures embedded in per-cpu data: | |
58 | */ | |
59 | typedef struct rtclock_timer { | |
60 | uint64_t deadline; | |
61 | boolean_t is_set; | |
62 | boolean_t has_expired; | |
63 | } rtclock_timer_t; | |
64 | ||
65 | typedef struct { | |
8ad349bb A |
66 | uint64_t rnt_tsc; /* timestamp */ |
67 | uint64_t rnt_nanos; /* nanoseconds */ | |
68 | uint32_t rnt_scale; /* tsc -> nanosec multiplier */ | |
69 | uint32_t rnt_shift; /* tsc -> nanosec shift/div */ | |
70 | uint64_t rnt_step_tsc; /* tsc when scale applied */ | |
71 | uint64_t rnt_step_nanos; /* ns when scale applied */ | |
91447636 A |
72 | } rtc_nanotime_t; |
73 | ||
74 | typedef struct { | |
75 | struct i386_tss *cdi_ktss; | |
76 | #if MACH_KDB | |
77 | struct i386_tss *cdi_dbtss; | |
78 | #endif /* MACH_KDB */ | |
79 | struct fake_descriptor *cdi_gdt; | |
80 | struct fake_descriptor *cdi_idt; | |
81 | struct fake_descriptor *cdi_ldt; | |
82 | } cpu_desc_index_t; | |
83 | ||
84 | ||
85 | /* | |
86 | * Per-cpu data. | |
87 | * | |
88 | * Each processor has a per-cpu data area which is dereferenced through the | |
89 | * current_cpu_datap() macro. For speed, the %gs segment is based here, and | |
90 | * using this, inlines provides single-instruction access to frequently used | |
91 | * members - such as get_cpu_number()/cpu_number(), and get_active_thread()/ | |
92 | * current_thread(). | |
93 | * | |
94 | * Cpu data owned by another processor can be accessed using the | |
95 | * cpu_datap(cpu_number) macro which uses the cpu_data_ptr[] array of per-cpu | |
96 | * pointers. | |
97 | */ | |
98 | typedef struct cpu_data | |
99 | { | |
100 | struct cpu_data *cpu_this; /* pointer to myself */ | |
101 | thread_t cpu_active_thread; | |
8ad349bb A |
102 | thread_t cpu_active_kloaded; |
103 | vm_offset_t cpu_active_stack; | |
104 | vm_offset_t cpu_kernel_stack; | |
91447636 A |
105 | vm_offset_t cpu_int_stack_top; |
106 | int cpu_preemption_level; | |
107 | int cpu_simple_lock_count; | |
108 | int cpu_interrupt_level; | |
109 | int cpu_number; /* Logical CPU */ | |
110 | int cpu_phys_number; /* Physical CPU */ | |
111 | cpu_id_t cpu_id; /* Platform Expert */ | |
112 | int cpu_signals; /* IPI events */ | |
113 | int cpu_mcount_off; /* mcount recursion */ | |
114 | ast_t cpu_pending_ast; | |
115 | int cpu_type; | |
116 | int cpu_subtype; | |
117 | int cpu_threadtype; | |
118 | int cpu_running; | |
c0fea474 | 119 | struct cpu_core *cpu_core; /* cpu's parent core */ |
8ad349bb A |
120 | uint64_t cpu_rtc_tick_deadline; |
121 | uint64_t cpu_rtc_intr_deadline; | |
122 | rtclock_timer_t cpu_rtc_timer; | |
123 | rtc_nanotime_t cpu_rtc_nanotime; | |
124 | void *cpu_console_buf; | |
91447636 A |
125 | struct processor *cpu_processor; |
126 | struct cpu_pmap *cpu_pmap; | |
8ad349bb | 127 | struct mp_desc_table *cpu_desc_tablep; |
91447636 | 128 | cpu_desc_index_t cpu_desc_index; |
8ad349bb | 129 | boolean_t cpu_iflag; |
91447636 A |
130 | #ifdef MACH_KDB |
131 | /* XXX Untested: */ | |
132 | int cpu_db_pass_thru; | |
8ad349bb A |
133 | vm_offset_t cpu_db_stacks; |
134 | struct i386_saved_state *cpu_kdb_saved_state; | |
135 | spl_t cpu_kdb_saved_ipl; | |
91447636 A |
136 | int cpu_kdb_is_slave; |
137 | int cpu_kdb_active; | |
138 | #endif /* MACH_KDB */ | |
8ad349bb | 139 | int cpu_hibernate; |
55e303ae | 140 | } cpu_data_t; |
1c79356b | 141 | |
91447636 A |
142 | extern cpu_data_t *cpu_data_ptr[]; |
143 | extern cpu_data_t cpu_data_master; | |
9bccf70c | 144 | |
55e303ae A |
145 | /* Macro to generate inline bodies to retrieve per-cpu data fields. */ |
146 | #define offsetof(TYPE,MEMBER) ((size_t) &((TYPE *)0)->MEMBER) | |
91447636 | 147 | #define CPU_DATA_GET(member,type) \ |
55e303ae A |
148 | type ret; \ |
149 | __asm__ volatile ("movl %%gs:%P1,%0" \ | |
150 | : "=r" (ret) \ | |
91447636 | 151 | : "i" (offsetof(cpu_data_t,member))); \ |
55e303ae | 152 | return ret; |
9bccf70c | 153 | |
1c79356b A |
154 | /* |
155 | * Everyone within the osfmk part of the kernel can use the fast | |
156 | * inline versions of these routines. Everyone outside, must call | |
157 | * the real thing, | |
158 | */ | |
91447636 A |
159 | static inline thread_t |
160 | get_active_thread(void) | |
1c79356b | 161 | { |
91447636 | 162 | CPU_DATA_GET(cpu_active_thread,thread_t) |
1c79356b | 163 | } |
91447636 A |
164 | #define current_thread_fast() get_active_thread() |
165 | #define current_thread() current_thread_fast() | |
1c79356b | 166 | |
91447636 A |
167 | static inline int |
168 | get_preemption_level(void) | |
1c79356b | 169 | { |
91447636 | 170 | CPU_DATA_GET(cpu_preemption_level,int) |
55e303ae | 171 | } |
91447636 A |
172 | static inline int |
173 | get_simple_lock_count(void) | |
55e303ae | 174 | { |
91447636 | 175 | CPU_DATA_GET(cpu_simple_lock_count,int) |
55e303ae | 176 | } |
91447636 A |
177 | static inline int |
178 | get_interrupt_level(void) | |
55e303ae | 179 | { |
91447636 | 180 | CPU_DATA_GET(cpu_interrupt_level,int) |
55e303ae | 181 | } |
91447636 A |
182 | static inline int |
183 | get_cpu_number(void) | |
55e303ae A |
184 | { |
185 | CPU_DATA_GET(cpu_number,int) | |
186 | } | |
91447636 A |
187 | static inline int |
188 | get_cpu_phys_number(void) | |
55e303ae A |
189 | { |
190 | CPU_DATA_GET(cpu_phys_number,int) | |
1c79356b | 191 | } |
91447636 A |
192 | static inline struct |
193 | cpu_core * get_cpu_core(void) | |
1c79356b | 194 | { |
91447636 | 195 | CPU_DATA_GET(cpu_core,struct cpu_core *) |
1c79356b A |
196 | } |
197 | ||
91447636 A |
198 | static inline void |
199 | disable_preemption(void) | |
1c79356b | 200 | { |
91447636 A |
201 | __asm__ volatile ("incl %%gs:%P0" |
202 | : | |
203 | : "i" (offsetof(cpu_data_t, cpu_preemption_level))); | |
204 | } | |
1c79356b | 205 | |
91447636 A |
206 | static inline void |
207 | enable_preemption(void) | |
208 | { | |
55e303ae A |
209 | assert(get_preemption_level() > 0); |
210 | ||
91447636 A |
211 | __asm__ volatile ("decl %%gs:%P0 \n\t" |
212 | "jne 1f \n\t" | |
213 | "call _kernel_preempt_check \n\t" | |
214 | "1:" | |
1c79356b | 215 | : /* no outputs */ |
91447636 A |
216 | : "i" (offsetof(cpu_data_t, cpu_preemption_level)) |
217 | : "eax", "ecx", "edx", "cc", "memory"); | |
1c79356b A |
218 | } |
219 | ||
91447636 A |
220 | static inline void |
221 | enable_preemption_no_check(void) | |
1c79356b | 222 | { |
1c79356b | 223 | assert(get_preemption_level() > 0); |
1c79356b | 224 | |
91447636 | 225 | __asm__ volatile ("decl %%gs:%P0" |
1c79356b | 226 | : /* no outputs */ |
91447636 | 227 | : "i" (offsetof(cpu_data_t, cpu_preemption_level)) |
1c79356b | 228 | : "cc", "memory"); |
1c79356b A |
229 | } |
230 | ||
91447636 A |
231 | static inline void |
232 | mp_disable_preemption(void) | |
1c79356b | 233 | { |
1c79356b | 234 | disable_preemption(); |
1c79356b A |
235 | } |
236 | ||
91447636 A |
237 | static inline void |
238 | mp_enable_preemption(void) | |
1c79356b | 239 | { |
1c79356b | 240 | enable_preemption(); |
1c79356b A |
241 | } |
242 | ||
91447636 A |
243 | static inline void |
244 | mp_enable_preemption_no_check(void) | |
1c79356b | 245 | { |
1c79356b | 246 | enable_preemption_no_check(); |
1c79356b A |
247 | } |
248 | ||
91447636 A |
249 | static inline cpu_data_t * |
250 | current_cpu_datap(void) | |
251 | { | |
252 | CPU_DATA_GET(cpu_this, cpu_data_t *); | |
253 | } | |
254 | ||
255 | static inline cpu_data_t * | |
256 | cpu_datap(int cpu) | |
257 | { | |
258 | assert(cpu_data_ptr[cpu]); | |
259 | return cpu_data_ptr[cpu]; | |
260 | } | |
261 | ||
262 | extern cpu_data_t *cpu_data_alloc(boolean_t is_boot_cpu); | |
1c79356b A |
263 | |
264 | #else /* !defined(__GNUC__) */ | |
265 | ||
266 | #endif /* defined(__GNUC__) */ | |
267 | ||
268 | #endif /* I386_CPU_DATA */ |