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