2 * Copyright (c) 2003-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 #include <mach/mach_types.h>
23 #include <mach/mach_host.h>
25 #include <kern/host.h>
26 #include <kern/processor.h>
28 #include <i386/cpu_data.h>
29 #include <i386/machine_routines.h>
30 #include <i386/perfmon.h>
33 #include <chud/chud_xnu.h>
35 #pragma mark **** cpu enable/disable ****
37 extern kern_return_t
processor_start(processor_t processor
); // osfmk/kern/processor.c
38 extern kern_return_t
processor_exit(processor_t processor
); // osfmk/kern/processor.c
41 kern_return_t
chudxnu_enable_cpu(int cpu
, boolean_t enable
)
43 chudxnu_unbind_thread(current_thread());
45 if(cpu
< 0 || (unsigned int)cpu
>= real_ncpus
) // sanity check
48 if((cpu_data_ptr
[cpu
] != NULL
) && cpu
!= master_cpu
) {
49 processor_t processor
= cpu_to_processor(cpu
);
51 if(processor
== master_processor
) // don't mess with the boot processor
55 // make sure it isn't already running
56 if(processor
->state
== PROCESSOR_OFF_LINE
||
57 processor
->state
== PROCESSOR_SHUTDOWN
) {
58 return processor_start(processor
);
60 return KERN_SUCCESS
; // it's already running
62 // make sure it hasn't already exited
63 if(processor
->state
!= PROCESSOR_OFF_LINE
&&
64 processor
->state
!= PROCESSOR_SHUTDOWN
) {
65 return processor_exit(processor
);
73 #pragma mark **** cache flush ****
77 chudxnu_flush_caches(void)
84 chudxnu_enable_caches(boolean_t enable
)
86 #pragma unused (enable)
90 #pragma mark **** perfmon facility ****
92 __private_extern__ kern_return_t
93 chudxnu_perfmon_acquire_facility(task_t task
)
95 return pmc_acquire(task
);
98 __private_extern__ kern_return_t
99 chudxnu_perfmon_release_facility(task_t task
)
101 return pmc_release(task
);
104 #pragma mark **** rupt counters ****
106 __private_extern__ kern_return_t
107 chudxnu_get_cpu_rupt_counters(int cpu
, rupt_counters_t
*rupts
)
109 if(cpu
< 0 || (unsigned int)cpu
>= real_ncpus
) { // sanity check
114 boolean_t oldlevel
= ml_set_interrupts_enabled(FALSE
);
115 cpu_data_t
*per_proc
;
117 per_proc
= cpu_data_ptr
[cpu
];
119 rupts
->hwMachineChecks
= 0;
122 rupts
->hwExternals
= 0;
123 rupts
->hwAlignments
= 0;
124 rupts
->hwPrograms
= 0;
125 rupts
->hwFloatPointUnavailable
= 0;
126 rupts
->hwDecrementers
= 0;
127 rupts
->hwIOErrors
= 0;
128 rupts
->hwSystemCalls
= 0;
130 rupts
->hwFloatingPointAssists
= 0;
131 rupts
->hwPerformanceMonitors
= 0;
132 rupts
->hwAltivecs
= 0;
133 rupts
->hwInstBreakpoints
= 0;
134 rupts
->hwSystemManagements
= 0;
135 rupts
->hwAltivecAssists
= 0;
136 rupts
->hwThermal
= 0;
137 rupts
->hwSoftPatches
= 0;
138 rupts
->hwMaintenances
= 0;
139 rupts
->hwInstrumentations
= 0;
141 ml_set_interrupts_enabled(oldlevel
);
148 __private_extern__ kern_return_t
149 chudxnu_clear_cpu_rupt_counters(int cpu
)
151 if(cpu
< 0 || (unsigned int)cpu
>= real_ncpus
) { // sanity check
157 * bzero((char *)&(cpu_data_ptr[cpu]->hwCtrs), sizeof(struct hwCtrs));