]> git.saurik.com Git - apple/xnu.git/blob - osfmk/chud/chud_xnu.h
xnu-1228.15.4.tar.gz
[apple/xnu.git] / osfmk / chud / chud_xnu.h
1 /*
2 * Copyright (c) 2003-2007 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 #ifndef _CHUD_XNU_H_
30 #define _CHUD_XNU_H_
31
32 #include <stdint.h>
33 #include <mach/boolean.h>
34 #include <mach/mach_types.h>
35
36 #pragma mark **** version ****
37 extern uint32_t chudxnu_version(void);
38
39 #pragma mark **** task ****
40 // ********************************************************************************
41 // task
42 // ********************************************************************************
43 extern int chudxnu_pid_for_task(task_t task);
44 extern task_t chudxnu_task_for_pid(int pid);
45 extern int chudxnu_current_pid(void);
46
47 extern kern_return_t chudxnu_task_read(task_t task, void *kernaddr, uint64_t usraddr, vm_size_t size);
48 extern kern_return_t chudxnu_task_write(task_t task, uint64_t useraddr, void *kernaddr, vm_size_t size);
49 extern kern_return_t chudxnu_kern_read(void *destaddr, vm_offset_t srcaddr, vm_size_t size);
50 extern kern_return_t chudxnu_kern_write(vm_offset_t destaddr, void *srcaddr, vm_size_t size);
51
52 extern boolean_t chudxnu_is_64bit_task(task_t task);
53
54 #pragma mark **** thread ****
55 // ********************************************************************************
56 // thread
57 // ********************************************************************************
58 extern kern_return_t chudxnu_bind_thread(thread_t thread, int cpu, int options);
59 extern kern_return_t chudxnu_unbind_thread(thread_t thread, int options);
60
61 extern kern_return_t chudxnu_thread_get_state(thread_t thread, thread_flavor_t flavor, thread_state_t tstate, mach_msg_type_number_t *count, boolean_t user_only);
62 extern kern_return_t chudxnu_thread_set_state(thread_t thread, thread_flavor_t flavor, thread_state_t tstate, mach_msg_type_number_t count, boolean_t user_only);
63 extern kern_return_t chudxnu_thread_user_state_available(thread_t thread);
64
65 extern kern_return_t chudxnu_thread_get_callstack64(thread_t thread, uint64_t *callStack, mach_msg_type_number_t *count, boolean_t user_only);
66
67 extern task_t chudxnu_current_task(void);
68 extern thread_t chudxnu_current_thread(void);
69
70 extern task_t chudxnu_task_for_thread(thread_t thread);
71
72 extern kern_return_t chudxnu_all_tasks(task_array_t *task_list, mach_msg_type_number_t *count);
73 extern kern_return_t chudxnu_free_task_list(task_array_t *task_list, mach_msg_type_number_t *count);
74
75 extern kern_return_t chudxnu_all_threads(thread_array_t *thread_list, mach_msg_type_number_t *count);
76 extern kern_return_t chudxnu_task_threads(task_t task, thread_array_t *thread_list, mach_msg_type_number_t *count);
77 extern kern_return_t chudxnu_free_thread_list(thread_array_t *thread_list, mach_msg_type_number_t *count);
78
79 extern kern_return_t chudxnu_thread_info( thread_t thread, thread_flavor_t flavor, thread_info_t thread_info_out, mach_msg_type_number_t *thread_info_count);
80
81 extern kern_return_t chudxnu_thread_last_context_switch(thread_t thread, uint64_t *timestamp);
82
83 extern boolean_t chudxnu_thread_set_marked(thread_t thread, boolean_t marked);
84 extern boolean_t chudxnu_thread_get_marked(thread_t thread);
85 extern boolean_t chudxnu_thread_get_idle(thread_t thread);
86
87 #pragma mark **** memory ****
88 // ********************************************************************************
89 // memory
90 // ********************************************************************************
91
92 extern uint64_t chudxnu_avail_memory_size(void);
93 extern uint64_t chudxnu_phys_memory_size(void);
94 extern uint64_t chudxnu_free_memory_size(void);
95 extern uint64_t chudxnu_inactive_memory_size(void);
96
97 #pragma mark **** cpu ****
98 // ********************************************************************************
99 // cpu
100 // ********************************************************************************
101 extern int chudxnu_logical_cpu_count(void);
102 extern int chudxnu_phys_cpu_count(void);
103 extern int chudxnu_cpu_number(void);
104
105 extern kern_return_t chudxnu_enable_cpu(int cpu, boolean_t enable);
106
107 extern boolean_t chudxnu_get_interrupts_enabled(void);
108 extern boolean_t chudxnu_set_interrupts_enabled(boolean_t enable);
109 extern boolean_t chudxnu_at_interrupt_context(void);
110 extern void chudxnu_cause_interrupt(void);
111
112 extern void chudxnu_enable_preemption(void);
113 extern void chudxnu_disable_preemption(void);
114 extern int chudxnu_get_preemption_level(void);
115
116 extern kern_return_t chudxnu_set_shadowed_spr(int cpu, int spr, uint32_t val);
117 extern kern_return_t chudxnu_set_shadowed_spr64(int cpu, int spr, uint64_t val);
118
119 extern kern_return_t chudxnu_perfmon_acquire_facility(task_t);
120 extern kern_return_t chudxnu_perfmon_release_facility(task_t);
121
122 typedef struct {
123 uint32_t hwResets;
124 uint32_t hwMachineChecks;
125 uint32_t hwDSIs;
126 uint32_t hwISIs;
127 uint32_t hwExternals;
128 uint32_t hwAlignments;
129 uint32_t hwPrograms;
130 uint32_t hwFloatPointUnavailable;
131 uint32_t hwDecrementers;
132 uint32_t hwIOErrors;
133 uint32_t hwSystemCalls;
134 uint32_t hwTraces;
135 uint32_t hwFloatingPointAssists;
136 uint32_t hwPerformanceMonitors;
137 uint32_t hwAltivecs;
138 uint32_t hwInstBreakpoints;
139 uint32_t hwSystemManagements;
140 uint32_t hwAltivecAssists;
141 uint32_t hwThermal;
142 uint32_t hwSoftPatches;
143 uint32_t hwMaintenances;
144 uint32_t hwInstrumentations;
145 } rupt_counters_t;
146
147 extern kern_return_t chudxnu_get_cpu_interrupt_counters(int cpu, rupt_counters_t *rupts);
148 extern kern_return_t chudxnu_clear_cpu_interrupt_counters(int cpu);
149
150 #pragma mark **** callbacks ****
151 // ********************************************************************************
152 // callbacks
153 // ********************************************************************************
154
155 extern void chudxnu_cancel_all_callbacks(void);
156
157 // cpu timer - each cpu has its own callback
158 typedef kern_return_t (*chudxnu_cpu_timer_callback_func_t)(thread_flavor_t flavor, thread_state_t tstate, mach_msg_type_number_t count);
159 extern kern_return_t chudxnu_cpu_timer_callback_enter(chudxnu_cpu_timer_callback_func_t func, uint32_t time, uint32_t units); // callback is entered on current cpu
160 extern kern_return_t chudxnu_cpu_timer_callback_cancel(void); // callback is cleared on current cpu
161 extern kern_return_t chudxnu_cpu_timer_callback_cancel_all(void); // callback is cleared on all cpus
162
163 enum {
164 PPC_TRAP_PROGRAM = 0x700,
165 PPC_TRAP_TRACE = 0xD00,
166 PPC_TRAP_PERFMON = 0xF00,
167 };
168
169 enum {
170 X86_TRAP_DEBUG = 0x1,
171 };
172
173 // trap callback - one callback for system
174 typedef kern_return_t (*chudxnu_trap_callback_func_t)(uint32_t trapentry, thread_flavor_t flavor, thread_state_t tstate, mach_msg_type_number_t count);
175 extern kern_return_t chudxnu_trap_callback_enter(chudxnu_trap_callback_func_t func);
176 extern kern_return_t chudxnu_trap_callback_cancel(void);
177
178 enum {
179 PPC_INTERRUPT_DECREMENTER = 0x900,
180 PPC_INTERRUPT_INTERRUPT = 0x500,
181 PPC_INTERRUPT_CPU_SIGNAL = 0x2200,
182 };
183
184 enum {
185 X86_INTERRUPT_PERFMON = 0xB,
186 };
187
188 // interrupt callback - one callback for system
189 typedef kern_return_t (*chudxnu_interrupt_callback_func_t)(uint32_t trapentry, thread_flavor_t flavor, thread_state_t tstate, mach_msg_type_number_t count);
190 extern kern_return_t chudxnu_interrupt_callback_enter(chudxnu_interrupt_callback_func_t func);
191 extern kern_return_t chudxnu_interrupt_callback_cancel(void);
192
193 // ast callback - one callback for system
194 typedef kern_return_t (*chudxnu_perfmon_ast_callback_func_t)(thread_flavor_t flavor, thread_state_t tstate, mach_msg_type_number_t count);
195 extern kern_return_t chudxnu_perfmon_ast_callback_enter(chudxnu_perfmon_ast_callback_func_t func);
196 extern kern_return_t chudxnu_perfmon_ast_callback_cancel(void);
197 extern kern_return_t chudxnu_perfmon_ast_send_urgent(boolean_t urgent);
198
199 // cpusig callback - one callback for system
200 typedef kern_return_t (*chudxnu_cpusig_callback_func_t)(int request, thread_flavor_t flavor, thread_state_t tstate, mach_msg_type_number_t count);
201 extern kern_return_t chudxnu_cpusig_callback_enter(chudxnu_cpusig_callback_func_t func);
202 extern kern_return_t chudxnu_cpusig_callback_cancel(void);
203 extern kern_return_t chudxnu_cpusig_send(int otherCPU, uint32_t request);
204
205 // kdebug callback - one callback for system
206 typedef kern_return_t (*chudxnu_kdebug_callback_func_t)(uint32_t debugid, uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4);
207 extern kern_return_t chudxnu_kdebug_callback_enter(chudxnu_kdebug_callback_func_t func);
208 extern kern_return_t chudxnu_kdebug_callback_cancel(void);
209
210 // timer callback - multiple callbacks
211 typedef kern_return_t (*chudxnu_timer_callback_func_t)(uint32_t param0, uint32_t param1);
212 typedef void * chud_timer_t;
213 extern chud_timer_t chudxnu_timer_alloc(chudxnu_timer_callback_func_t func, uint32_t param0);
214 extern kern_return_t chudxnu_timer_callback_enter(chud_timer_t timer, uint32_t param1, uint32_t time, uint32_t units);
215 extern kern_return_t chudxnu_timer_callback_cancel(chud_timer_t timer);
216 extern kern_return_t chudxnu_timer_free(chud_timer_t timer);
217
218 // CHUD systemcall callback - one callback for system
219 typedef kern_return_t (*chudxnu_syscall_callback_func_t)(uint32_t code, uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4);
220 extern kern_return_t chudxnu_syscall_callback_enter(chudxnu_syscall_callback_func_t func);
221 extern kern_return_t chudxnu_syscall_callback_cancel(void);
222
223 // DTrace Triggering
224 typedef kern_return_t (*chudxnu_dtrace_callback_t)(uint64_t selector, uint64_t *args, uint32_t count);
225 extern kern_return_t chudxnu_dtrace_callback(uint64_t selector, uint64_t *args, uint32_t count);
226 extern void chudxnu_dtrace_callback_enter(chudxnu_dtrace_callback_t fn);
227 extern void chudxnu_dtrace_callback_cancel(void);
228
229 // ********************************************************************************
230 // DEPRECATED
231 // ********************************************************************************
232 extern kern_return_t chudxnu_perfmon_ast_send(void);
233 extern kern_return_t chudxnu_thread_get_callstack(thread_t thread, uint32_t *callStack, mach_msg_type_number_t *count, boolean_t user_only);
234
235 extern vm_offset_t chudxnu_io_map(uint64_t phys_addr, vm_size_t size);
236 extern uint32_t chudxnu_phys_addr_wimg(uint64_t phys_addr);
237
238 extern int chudxnu_avail_cpu_count(void);
239
240 extern kern_return_t chudxnu_enable_cpu_nap(int cpu, boolean_t enable);
241 extern boolean_t chudxnu_cpu_nap_enabled(int cpu);
242
243 extern uint32_t chudxnu_get_orig_cpu_l2cr(int cpu);
244 extern uint32_t chudxnu_get_orig_cpu_l3cr(int cpu);
245
246 extern kern_return_t chudxnu_read_spr(int cpu, int spr, uint32_t *val_p);
247 extern kern_return_t chudxnu_read_spr64(int cpu, int spr, uint64_t *val_p);
248 extern kern_return_t chudxnu_write_spr(int cpu, int spr, uint32_t val);
249 extern kern_return_t chudxnu_write_spr64(int cpu, int spr, uint64_t val);
250
251 extern kern_return_t chudxnu_get_cpu_rupt_counters(int cpu, rupt_counters_t *rupts);
252 extern kern_return_t chudxnu_clear_cpu_rupt_counters(int cpu);
253
254 extern kern_return_t chudxnu_passup_alignment_exceptions(boolean_t enable);
255
256 extern kern_return_t chudxnu_scom_read(uint32_t reg, uint64_t *data);
257 extern kern_return_t chudxnu_scom_write(uint32_t reg, uint64_t data);
258
259 extern void chudxnu_flush_caches(void);
260 extern void chudxnu_enable_caches(boolean_t enable);
261
262 #endif /* _CHUD_XNU_H_ */