2 * Copyright (c) 2003-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
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
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 #include <mach/mach_types.h>
31 #include <mach/mach_host.h>
33 #include <kern/host.h>
34 #include <kern/processor.h>
36 #include <i386/cpu_data.h>
37 #include <i386/machine_routines.h>
38 #include <i386/perfmon.h>
41 #include <chud/chud_xnu.h>
43 #pragma mark **** cpu enable/disable ****
45 extern kern_return_t
processor_start(processor_t processor
); // osfmk/kern/processor.c
46 extern kern_return_t
processor_exit(processor_t processor
); // osfmk/kern/processor.c
49 kern_return_t
chudxnu_enable_cpu(int cpu
, boolean_t enable
)
51 chudxnu_unbind_thread(current_thread());
53 if(cpu
< 0 || (unsigned int)cpu
>= real_ncpus
) // sanity check
56 if((cpu_data_ptr
[cpu
] != NULL
) && cpu
!= master_cpu
) {
57 processor_t processor
= cpu_to_processor(cpu
);
59 if(processor
== master_processor
) // don't mess with the boot processor
63 // make sure it isn't already running
64 if(processor
->state
== PROCESSOR_OFF_LINE
||
65 processor
->state
== PROCESSOR_SHUTDOWN
) {
66 return processor_start(processor
);
68 return KERN_SUCCESS
; // it's already running
70 // make sure it hasn't already exited
71 if(processor
->state
!= PROCESSOR_OFF_LINE
&&
72 processor
->state
!= PROCESSOR_SHUTDOWN
) {
73 return processor_exit(processor
);
81 #pragma mark **** cache flush ****
85 chudxnu_flush_caches(void)
92 chudxnu_enable_caches(boolean_t enable
)
94 #pragma unused (enable)
98 #pragma mark **** perfmon facility ****
100 __private_extern__ kern_return_t
101 chudxnu_perfmon_acquire_facility(task_t task
)
103 return pmc_acquire(task
);
106 __private_extern__ kern_return_t
107 chudxnu_perfmon_release_facility(task_t task
)
109 return pmc_release(task
);
112 #pragma mark **** rupt counters ****
114 __private_extern__ kern_return_t
115 chudxnu_get_cpu_rupt_counters(int cpu
, rupt_counters_t
*rupts
)
117 if(cpu
< 0 || (unsigned int)cpu
>= real_ncpus
) { // sanity check
122 boolean_t oldlevel
= ml_set_interrupts_enabled(FALSE
);
123 cpu_data_t
*per_proc
;
125 per_proc
= cpu_data_ptr
[cpu
];
127 rupts
->hwMachineChecks
= 0;
130 rupts
->hwExternals
= 0;
131 rupts
->hwAlignments
= 0;
132 rupts
->hwPrograms
= 0;
133 rupts
->hwFloatPointUnavailable
= 0;
134 rupts
->hwDecrementers
= 0;
135 rupts
->hwIOErrors
= 0;
136 rupts
->hwSystemCalls
= 0;
138 rupts
->hwFloatingPointAssists
= 0;
139 rupts
->hwPerformanceMonitors
= 0;
140 rupts
->hwAltivecs
= 0;
141 rupts
->hwInstBreakpoints
= 0;
142 rupts
->hwSystemManagements
= 0;
143 rupts
->hwAltivecAssists
= 0;
144 rupts
->hwThermal
= 0;
145 rupts
->hwSoftPatches
= 0;
146 rupts
->hwMaintenances
= 0;
147 rupts
->hwInstrumentations
= 0;
149 ml_set_interrupts_enabled(oldlevel
);
156 __private_extern__ kern_return_t
157 chudxnu_clear_cpu_rupt_counters(int cpu
)
159 if(cpu
< 0 || (unsigned int)cpu
>= real_ncpus
) { // sanity check
165 * bzero((char *)&(cpu_data_ptr[cpu]->hwCtrs), sizeof(struct hwCtrs));