2 * Copyright (c) 2003-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 #include <mach/mach_types.h>
29 #include <mach/mach_host.h>
31 #include <kern/host.h>
32 #include <kern/processor.h>
34 #include <i386/cpu_data.h>
35 #include <i386/machine_routines.h>
36 #include <i386/perfmon.h>
39 #include <chud/chud_xnu.h>
41 #pragma mark **** cpu enable/disable ****
43 extern kern_return_t
processor_start(processor_t processor
); // osfmk/kern/processor.c
44 extern kern_return_t
processor_exit(processor_t processor
); // osfmk/kern/processor.c
47 kern_return_t
chudxnu_enable_cpu(int cpu
, boolean_t enable
)
49 chudxnu_unbind_thread(current_thread());
51 if(cpu
< 0 || (unsigned int)cpu
>= real_ncpus
) // sanity check
54 if((cpu_data_ptr
[cpu
] != NULL
) && cpu
!= master_cpu
) {
55 processor_t processor
= cpu_to_processor(cpu
);
57 if(processor
== master_processor
) // don't mess with the boot processor
61 // make sure it isn't already running
62 if(processor
->state
== PROCESSOR_OFF_LINE
||
63 processor
->state
== PROCESSOR_SHUTDOWN
) {
64 return processor_start(processor
);
66 return KERN_SUCCESS
; // it's already running
68 // make sure it hasn't already exited
69 if(processor
->state
!= PROCESSOR_OFF_LINE
&&
70 processor
->state
!= PROCESSOR_SHUTDOWN
) {
71 return processor_exit(processor
);
79 #pragma mark **** cache flush ****
83 chudxnu_flush_caches(void)
90 chudxnu_enable_caches(boolean_t enable
)
92 #pragma unused (enable)
96 #pragma mark **** perfmon facility ****
98 __private_extern__ kern_return_t
99 chudxnu_perfmon_acquire_facility(task_t task
)
101 return pmc_acquire(task
);
104 __private_extern__ kern_return_t
105 chudxnu_perfmon_release_facility(task_t task
)
107 return pmc_release(task
);
110 #pragma mark **** rupt counters ****
112 __private_extern__ kern_return_t
113 chudxnu_get_cpu_rupt_counters(int cpu
, rupt_counters_t
*rupts
)
115 if(cpu
< 0 || (unsigned int)cpu
>= real_ncpus
) { // sanity check
120 boolean_t oldlevel
= ml_set_interrupts_enabled(FALSE
);
121 cpu_data_t
*per_proc
;
123 per_proc
= cpu_data_ptr
[cpu
];
125 rupts
->hwMachineChecks
= 0;
128 rupts
->hwExternals
= 0;
129 rupts
->hwAlignments
= 0;
130 rupts
->hwPrograms
= 0;
131 rupts
->hwFloatPointUnavailable
= 0;
132 rupts
->hwDecrementers
= 0;
133 rupts
->hwIOErrors
= 0;
134 rupts
->hwSystemCalls
= 0;
136 rupts
->hwFloatingPointAssists
= 0;
137 rupts
->hwPerformanceMonitors
= 0;
138 rupts
->hwAltivecs
= 0;
139 rupts
->hwInstBreakpoints
= 0;
140 rupts
->hwSystemManagements
= 0;
141 rupts
->hwAltivecAssists
= 0;
142 rupts
->hwThermal
= 0;
143 rupts
->hwSoftPatches
= 0;
144 rupts
->hwMaintenances
= 0;
145 rupts
->hwInstrumentations
= 0;
147 ml_set_interrupts_enabled(oldlevel
);
154 __private_extern__ kern_return_t
155 chudxnu_clear_cpu_rupt_counters(int cpu
)
157 if(cpu
< 0 || (unsigned int)cpu
>= real_ncpus
) { // sanity check
163 * bzero((char *)&(cpu_data_ptr[cpu]->hwCtrs), sizeof(struct hwCtrs));