]> git.saurik.com Git - apple/xnu.git/blob - osfmk/chud/i386/chud_cpu_i386.c
25ac19b740c9dd4c6a812e99ac2a237a4c2c66f5
[apple/xnu.git] / osfmk / chud / i386 / chud_cpu_i386.c
1 /*
2 * Copyright (c) 2003-2004 Apple Computer, 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 #include <mach/mach_types.h>
29 #include <mach/mach_host.h>
30
31 #include <kern/host.h>
32 #include <kern/processor.h>
33
34 #include <i386/cpu_data.h>
35 #include <i386/machine_routines.h>
36 #include <i386/perfmon.h>
37 #include <i386/mp.h>
38
39 #include <chud/chud_xnu.h>
40
41 #pragma mark **** cpu enable/disable ****
42
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
45
46 __private_extern__
47 kern_return_t chudxnu_enable_cpu(int cpu, boolean_t enable)
48 {
49 chudxnu_unbind_thread(current_thread());
50
51 if(cpu < 0 || (unsigned int)cpu >= real_ncpus) // sanity check
52 return KERN_FAILURE;
53
54 if((cpu_data_ptr[cpu] != NULL) && cpu != master_cpu) {
55 processor_t processor = cpu_to_processor(cpu);
56
57 if(processor == master_processor) // don't mess with the boot processor
58 return KERN_FAILURE;
59
60 if(enable) {
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);
65 }
66 return KERN_SUCCESS; // it's already running
67 } else {
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);
72 }
73 return KERN_SUCCESS;
74 }
75 }
76 return KERN_FAILURE;
77 }
78
79 #pragma mark **** cache flush ****
80
81 __private_extern__
82 void
83 chudxnu_flush_caches(void)
84 {
85 /* XXX */
86 }
87
88 __private_extern__
89 void
90 chudxnu_enable_caches(boolean_t enable)
91 {
92 #pragma unused (enable)
93 /* XXX */
94 }
95
96 #pragma mark **** perfmon facility ****
97
98 __private_extern__ kern_return_t
99 chudxnu_perfmon_acquire_facility(task_t task)
100 {
101 return pmc_acquire(task);
102 }
103
104 __private_extern__ kern_return_t
105 chudxnu_perfmon_release_facility(task_t task)
106 {
107 return pmc_release(task);
108 }
109
110 #pragma mark **** rupt counters ****
111
112 __private_extern__ kern_return_t
113 chudxnu_get_cpu_rupt_counters(int cpu, rupt_counters_t *rupts)
114 {
115 if(cpu < 0 || (unsigned int)cpu >= real_ncpus) { // sanity check
116 return KERN_FAILURE;
117 }
118
119 if(rupts) {
120 boolean_t oldlevel = ml_set_interrupts_enabled(FALSE);
121 cpu_data_t *per_proc;
122
123 per_proc = cpu_data_ptr[cpu];
124 rupts->hwResets = 0;
125 rupts->hwMachineChecks = 0;
126 rupts->hwDSIs = 0;
127 rupts->hwISIs = 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;
135 rupts->hwTraces = 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;
146
147 ml_set_interrupts_enabled(oldlevel);
148 return KERN_SUCCESS;
149 } else {
150 return KERN_FAILURE;
151 }
152 }
153
154 __private_extern__ kern_return_t
155 chudxnu_clear_cpu_rupt_counters(int cpu)
156 {
157 if(cpu < 0 || (unsigned int)cpu >= real_ncpus) { // sanity check
158 return KERN_FAILURE;
159 }
160
161 /*
162 * XXX
163 * bzero((char *)&(cpu_data_ptr[cpu]->hwCtrs), sizeof(struct hwCtrs));
164 */
165 return KERN_SUCCESS;
166 }