]> git.saurik.com Git - apple/xnu.git/blob - osfmk/chud/i386/chud_cpu_i386.c
c175ed94535125026b5ff44d1b187046b396a0e2
[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_LICENSE_OSREFERENCE_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
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
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
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.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 #include <mach/mach_types.h>
31 #include <mach/mach_host.h>
32
33 #include <kern/host.h>
34 #include <kern/processor.h>
35
36 #include <i386/cpu_data.h>
37 #include <i386/machine_routines.h>
38 #include <i386/perfmon.h>
39 #include <i386/mp.h>
40
41 #include <chud/chud_xnu.h>
42
43 #pragma mark **** cpu enable/disable ****
44
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
47
48 __private_extern__
49 kern_return_t chudxnu_enable_cpu(int cpu, boolean_t enable)
50 {
51 chudxnu_unbind_thread(current_thread());
52
53 if(cpu < 0 || (unsigned int)cpu >= real_ncpus) // sanity check
54 return KERN_FAILURE;
55
56 if((cpu_data_ptr[cpu] != NULL) && cpu != master_cpu) {
57 processor_t processor = cpu_to_processor(cpu);
58
59 if(processor == master_processor) // don't mess with the boot processor
60 return KERN_FAILURE;
61
62 if(enable) {
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);
67 }
68 return KERN_SUCCESS; // it's already running
69 } else {
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);
74 }
75 return KERN_SUCCESS;
76 }
77 }
78 return KERN_FAILURE;
79 }
80
81 #pragma mark **** cache flush ****
82
83 __private_extern__
84 void
85 chudxnu_flush_caches(void)
86 {
87 /* XXX */
88 }
89
90 __private_extern__
91 void
92 chudxnu_enable_caches(boolean_t enable)
93 {
94 #pragma unused (enable)
95 /* XXX */
96 }
97
98 #pragma mark **** perfmon facility ****
99
100 __private_extern__ kern_return_t
101 chudxnu_perfmon_acquire_facility(task_t task)
102 {
103 return pmc_acquire(task);
104 }
105
106 __private_extern__ kern_return_t
107 chudxnu_perfmon_release_facility(task_t task)
108 {
109 return pmc_release(task);
110 }
111
112 #pragma mark **** rupt counters ****
113
114 __private_extern__ kern_return_t
115 chudxnu_get_cpu_rupt_counters(int cpu, rupt_counters_t *rupts)
116 {
117 if(cpu < 0 || (unsigned int)cpu >= real_ncpus) { // sanity check
118 return KERN_FAILURE;
119 }
120
121 if(rupts) {
122 boolean_t oldlevel = ml_set_interrupts_enabled(FALSE);
123 cpu_data_t *per_proc;
124
125 per_proc = cpu_data_ptr[cpu];
126 rupts->hwResets = 0;
127 rupts->hwMachineChecks = 0;
128 rupts->hwDSIs = 0;
129 rupts->hwISIs = 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;
137 rupts->hwTraces = 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;
148
149 ml_set_interrupts_enabled(oldlevel);
150 return KERN_SUCCESS;
151 } else {
152 return KERN_FAILURE;
153 }
154 }
155
156 __private_extern__ kern_return_t
157 chudxnu_clear_cpu_rupt_counters(int cpu)
158 {
159 if(cpu < 0 || (unsigned int)cpu >= real_ncpus) { // sanity check
160 return KERN_FAILURE;
161 }
162
163 /*
164 * XXX
165 * bzero((char *)&(cpu_data_ptr[cpu]->hwCtrs), sizeof(struct hwCtrs));
166 */
167 return KERN_SUCCESS;
168 }