]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2000-2008 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_OSREFERENCE_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. 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 | |
24 | * limitations under the License. | |
25 | * | |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
27 | */ | |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | * | |
31 | */ | |
32 | ||
33 | #ifndef I386_CPU_DATA | |
34 | #define I386_CPU_DATA | |
35 | ||
36 | #include <mach_assert.h> | |
37 | ||
38 | #if defined(__GNUC__) | |
39 | ||
40 | #include <kern/assert.h> | |
41 | #include <kern/kern_types.h> | |
42 | #include <kern/processor.h> | |
43 | #include <kern/pms.h> | |
44 | #include <pexpert/pexpert.h> | |
45 | #include <mach/i386/thread_status.h> | |
46 | #include <i386/rtclock.h> | |
47 | #include <i386/pmCPU.h> | |
48 | #include <i386/cpu_topology.h> | |
49 | ||
50 | #include <i386/vmx/vmx_cpu.h> | |
51 | ||
52 | /* | |
53 | * Data structures referenced (anonymously) from per-cpu data: | |
54 | */ | |
55 | struct cpu_cons_buffer; | |
56 | struct cpu_desc_table; | |
57 | struct mca_state; | |
58 | ||
59 | ||
60 | /* | |
61 | * Data structures embedded in per-cpu data: | |
62 | */ | |
63 | typedef struct rtclock_timer { | |
64 | queue_head_t queue; | |
65 | uint64_t deadline; | |
66 | boolean_t is_set; | |
67 | boolean_t has_expired; | |
68 | } rtclock_timer_t; | |
69 | ||
70 | ||
71 | typedef struct { | |
72 | struct i386_tss *cdi_ktss; | |
73 | #if MACH_KDB | |
74 | struct i386_tss *cdi_dbtss; | |
75 | #endif /* MACH_KDB */ | |
76 | struct fake_descriptor *cdi_gdt; | |
77 | struct fake_descriptor *cdi_idt; | |
78 | struct fake_descriptor *cdi_ldt; | |
79 | vm_offset_t cdi_sstk; | |
80 | } cpu_desc_index_t; | |
81 | ||
82 | typedef enum { | |
83 | TASK_MAP_32BIT, /* 32-bit, compatibility mode */ | |
84 | TASK_MAP_64BIT, /* 64-bit, separate address space */ | |
85 | TASK_MAP_64BIT_SHARED /* 64-bit, kernel-shared addr space */ | |
86 | } task_map_t; | |
87 | ||
88 | /* | |
89 | * This structure is used on entry into the (uber-)kernel on syscall from | |
90 | * a 64-bit user. It contains the address of the machine state save area | |
91 | * for the current thread and a temporary place to save the user's rsp | |
92 | * before loading this address into rsp. | |
93 | */ | |
94 | typedef struct { | |
95 | addr64_t cu_isf; /* thread->pcb->iss.isf */ | |
96 | uint64_t cu_tmp; /* temporary scratch */ | |
97 | addr64_t cu_user_gs_base; | |
98 | } cpu_uber_t; | |
99 | ||
100 | /* | |
101 | * Per-cpu data. | |
102 | * | |
103 | * Each processor has a per-cpu data area which is dereferenced through the | |
104 | * current_cpu_datap() macro. For speed, the %gs segment is based here, and | |
105 | * using this, inlines provides single-instruction access to frequently used | |
106 | * members - such as get_cpu_number()/cpu_number(), and get_active_thread()/ | |
107 | * current_thread(). | |
108 | * | |
109 | * Cpu data owned by another processor can be accessed using the | |
110 | * cpu_datap(cpu_number) macro which uses the cpu_data_ptr[] array of per-cpu | |
111 | * pointers. | |
112 | */ | |
113 | typedef struct cpu_data | |
114 | { | |
115 | struct cpu_data *cpu_this; /* pointer to myself */ | |
116 | thread_t cpu_active_thread; | |
117 | void *cpu_int_state; /* interrupt state */ | |
118 | vm_offset_t cpu_active_stack; /* kernel stack base */ | |
119 | vm_offset_t cpu_kernel_stack; /* kernel stack top */ | |
120 | vm_offset_t cpu_int_stack_top; | |
121 | int cpu_preemption_level; | |
122 | int cpu_simple_lock_count; | |
123 | int cpu_interrupt_level; | |
124 | int cpu_number; /* Logical CPU */ | |
125 | int cpu_phys_number; /* Physical CPU */ | |
126 | cpu_id_t cpu_id; /* Platform Expert */ | |
127 | int cpu_signals; /* IPI events */ | |
128 | int cpu_mcount_off; /* mcount recursion */ | |
129 | ast_t cpu_pending_ast; | |
130 | int cpu_type; | |
131 | int cpu_subtype; | |
132 | int cpu_threadtype; | |
133 | int cpu_running; | |
134 | rtclock_timer_t rtclock_timer; | |
135 | boolean_t cpu_is64bit; | |
136 | task_map_t cpu_task_map; | |
137 | addr64_t cpu_task_cr3; | |
138 | addr64_t cpu_active_cr3; | |
139 | addr64_t cpu_kernel_cr3; | |
140 | cpu_uber_t cpu_uber; | |
141 | void *cpu_chud; | |
142 | void *cpu_console_buf; | |
143 | struct x86_lcpu lcpu; | |
144 | struct processor *cpu_processor; | |
145 | struct cpu_pmap *cpu_pmap; | |
146 | struct cpu_desc_table *cpu_desc_tablep; | |
147 | struct fake_descriptor *cpu_ldtp; | |
148 | cpu_desc_index_t cpu_desc_index; | |
149 | int cpu_ldt; | |
150 | #ifdef MACH_KDB | |
151 | /* XXX Untested: */ | |
152 | int cpu_db_pass_thru; | |
153 | vm_offset_t cpu_db_stacks; | |
154 | void *cpu_kdb_saved_state; | |
155 | spl_t cpu_kdb_saved_ipl; | |
156 | int cpu_kdb_is_slave; | |
157 | int cpu_kdb_active; | |
158 | #endif /* MACH_KDB */ | |
159 | boolean_t cpu_iflag; | |
160 | boolean_t cpu_boot_complete; | |
161 | int cpu_hibernate; | |
162 | ||
163 | vm_offset_t cpu_copywindow_base; | |
164 | uint64_t *cpu_copywindow_pdp; | |
165 | ||
166 | vm_offset_t cpu_physwindow_base; | |
167 | uint64_t *cpu_physwindow_ptep; | |
168 | void *cpu_hi_iss; | |
169 | boolean_t cpu_tlb_invalid; | |
170 | uint32_t cpu_hwIntCnt[256]; /* Interrupt counts */ | |
171 | uint64_t cpu_dr7; /* debug control register */ | |
172 | uint64_t cpu_int_event_time; /* intr entry/exit time */ | |
173 | vmx_cpu_t cpu_vmx; /* wonderful world of virtualization */ | |
174 | struct mca_state *cpu_mca_state; /* State at MC fault */ | |
175 | uint64_t cpu_uber_arg_store; /* Double mapped address | |
176 | * of current thread's | |
177 | * uu_arg array. | |
178 | */ | |
179 | uint64_t cpu_uber_arg_store_valid; /* Double mapped | |
180 | * address of pcb | |
181 | * arg store | |
182 | * validity flag. | |
183 | */ | |
184 | rtc_nanotime_t *cpu_nanotime; /* Nanotime info */ | |
185 | ||
186 | } cpu_data_t; | |
187 | ||
188 | extern cpu_data_t *cpu_data_ptr[]; | |
189 | extern cpu_data_t cpu_data_master; | |
190 | ||
191 | /* Macro to generate inline bodies to retrieve per-cpu data fields. */ | |
192 | #ifndef offsetof | |
193 | #define offsetof(TYPE,MEMBER) ((size_t) &((TYPE *)0)->MEMBER) | |
194 | #endif /* offsetof */ | |
195 | #define CPU_DATA_GET(member,type) \ | |
196 | type ret; \ | |
197 | __asm__ volatile ("movl %%gs:%P1,%0" \ | |
198 | : "=r" (ret) \ | |
199 | : "i" (offsetof(cpu_data_t,member))); \ | |
200 | return ret; | |
201 | ||
202 | /* | |
203 | * Everyone within the osfmk part of the kernel can use the fast | |
204 | * inline versions of these routines. Everyone outside, must call | |
205 | * the real thing, | |
206 | */ | |
207 | static inline thread_t | |
208 | get_active_thread(void) | |
209 | { | |
210 | CPU_DATA_GET(cpu_active_thread,thread_t) | |
211 | } | |
212 | #define current_thread_fast() get_active_thread() | |
213 | #define current_thread() current_thread_fast() | |
214 | ||
215 | static inline boolean_t | |
216 | get_is64bit(void) | |
217 | { | |
218 | CPU_DATA_GET(cpu_is64bit, boolean_t) | |
219 | } | |
220 | #define cpu_mode_is64bit() get_is64bit() | |
221 | ||
222 | static inline int | |
223 | get_preemption_level(void) | |
224 | { | |
225 | CPU_DATA_GET(cpu_preemption_level,int) | |
226 | } | |
227 | static inline int | |
228 | get_simple_lock_count(void) | |
229 | { | |
230 | CPU_DATA_GET(cpu_simple_lock_count,int) | |
231 | } | |
232 | static inline int | |
233 | get_interrupt_level(void) | |
234 | { | |
235 | CPU_DATA_GET(cpu_interrupt_level,int) | |
236 | } | |
237 | static inline int | |
238 | get_cpu_number(void) | |
239 | { | |
240 | CPU_DATA_GET(cpu_number,int) | |
241 | } | |
242 | static inline int | |
243 | get_cpu_phys_number(void) | |
244 | { | |
245 | CPU_DATA_GET(cpu_phys_number,int) | |
246 | } | |
247 | ||
248 | static inline void | |
249 | disable_preemption(void) | |
250 | { | |
251 | __asm__ volatile ("incl %%gs:%P0" | |
252 | : | |
253 | : "i" (offsetof(cpu_data_t, cpu_preemption_level))); | |
254 | } | |
255 | ||
256 | static inline void | |
257 | enable_preemption(void) | |
258 | { | |
259 | assert(get_preemption_level() > 0); | |
260 | ||
261 | __asm__ volatile ("decl %%gs:%P0 \n\t" | |
262 | "jne 1f \n\t" | |
263 | "call _kernel_preempt_check \n\t" | |
264 | "1:" | |
265 | : /* no outputs */ | |
266 | : "i" (offsetof(cpu_data_t, cpu_preemption_level)) | |
267 | : "eax", "ecx", "edx", "cc", "memory"); | |
268 | } | |
269 | ||
270 | static inline void | |
271 | enable_preemption_no_check(void) | |
272 | { | |
273 | assert(get_preemption_level() > 0); | |
274 | ||
275 | __asm__ volatile ("decl %%gs:%P0" | |
276 | : /* no outputs */ | |
277 | : "i" (offsetof(cpu_data_t, cpu_preemption_level)) | |
278 | : "cc", "memory"); | |
279 | } | |
280 | ||
281 | static inline void | |
282 | mp_disable_preemption(void) | |
283 | { | |
284 | disable_preemption(); | |
285 | } | |
286 | ||
287 | static inline void | |
288 | mp_enable_preemption(void) | |
289 | { | |
290 | enable_preemption(); | |
291 | } | |
292 | ||
293 | static inline void | |
294 | mp_enable_preemption_no_check(void) | |
295 | { | |
296 | enable_preemption_no_check(); | |
297 | } | |
298 | ||
299 | static inline cpu_data_t * | |
300 | current_cpu_datap(void) | |
301 | { | |
302 | CPU_DATA_GET(cpu_this, cpu_data_t *); | |
303 | } | |
304 | ||
305 | static inline cpu_data_t * | |
306 | cpu_datap(int cpu) | |
307 | { | |
308 | assert(cpu_data_ptr[cpu]); | |
309 | return cpu_data_ptr[cpu]; | |
310 | } | |
311 | ||
312 | extern cpu_data_t *cpu_data_alloc(boolean_t is_boot_cpu); | |
313 | ||
314 | #else /* !defined(__GNUC__) */ | |
315 | ||
316 | #endif /* defined(__GNUC__) */ | |
317 | ||
318 | #endif /* I386_CPU_DATA */ |