]>
Commit | Line | Data |
---|---|---|
0c530ab8 A |
1 | /* |
2 | * Copyright (c) 2003-2004 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
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. | |
11 | * | |
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 | |
18 | * under the License. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | #include <mach/mach_types.h> | |
23 | #include <mach/mach_host.h> | |
24 | ||
25 | #include <kern/host.h> | |
26 | #include <kern/processor.h> | |
27 | ||
28 | #include <i386/cpu_data.h> | |
29 | #include <i386/machine_routines.h> | |
30 | #include <i386/perfmon.h> | |
31 | #include <i386/mp.h> | |
32 | ||
33 | #include <chud/chud_xnu.h> | |
34 | ||
35 | #pragma mark **** cpu enable/disable **** | |
36 | ||
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 | |
39 | ||
40 | __private_extern__ | |
41 | kern_return_t chudxnu_enable_cpu(int cpu, boolean_t enable) | |
42 | { | |
43 | chudxnu_unbind_thread(current_thread()); | |
44 | ||
45 | if(cpu < 0 || (unsigned int)cpu >= real_ncpus) // sanity check | |
46 | return KERN_FAILURE; | |
47 | ||
48 | if((cpu_data_ptr[cpu] != NULL) && cpu != master_cpu) { | |
49 | processor_t processor = cpu_to_processor(cpu); | |
50 | ||
51 | if(processor == master_processor) // don't mess with the boot processor | |
52 | return KERN_FAILURE; | |
53 | ||
54 | if(enable) { | |
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); | |
59 | } | |
60 | return KERN_SUCCESS; // it's already running | |
61 | } else { | |
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); | |
66 | } | |
67 | return KERN_SUCCESS; | |
68 | } | |
69 | } | |
70 | return KERN_FAILURE; | |
71 | } | |
72 | ||
73 | #pragma mark **** cache flush **** | |
74 | ||
75 | __private_extern__ | |
76 | void | |
77 | chudxnu_flush_caches(void) | |
78 | { | |
79 | /* XXX */ | |
80 | } | |
81 | ||
82 | __private_extern__ | |
83 | void | |
84 | chudxnu_enable_caches(boolean_t enable) | |
85 | { | |
86 | #pragma unused (enable) | |
87 | /* XXX */ | |
88 | } | |
89 | ||
90 | #pragma mark **** perfmon facility **** | |
91 | ||
92 | __private_extern__ kern_return_t | |
93 | chudxnu_perfmon_acquire_facility(task_t task) | |
94 | { | |
95 | return pmc_acquire(task); | |
96 | } | |
97 | ||
98 | __private_extern__ kern_return_t | |
99 | chudxnu_perfmon_release_facility(task_t task) | |
100 | { | |
101 | return pmc_release(task); | |
102 | } | |
103 | ||
104 | #pragma mark **** rupt counters **** | |
105 | ||
106 | __private_extern__ kern_return_t | |
107 | chudxnu_get_cpu_rupt_counters(int cpu, rupt_counters_t *rupts) | |
108 | { | |
109 | if(cpu < 0 || (unsigned int)cpu >= real_ncpus) { // sanity check | |
110 | return KERN_FAILURE; | |
111 | } | |
112 | ||
113 | if(rupts) { | |
114 | boolean_t oldlevel = ml_set_interrupts_enabled(FALSE); | |
115 | cpu_data_t *per_proc; | |
116 | ||
117 | per_proc = cpu_data_ptr[cpu]; | |
118 | rupts->hwResets = 0; | |
119 | rupts->hwMachineChecks = 0; | |
120 | rupts->hwDSIs = 0; | |
121 | rupts->hwISIs = 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; | |
129 | rupts->hwTraces = 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; | |
140 | ||
141 | ml_set_interrupts_enabled(oldlevel); | |
142 | return KERN_SUCCESS; | |
143 | } else { | |
144 | return KERN_FAILURE; | |
145 | } | |
146 | } | |
147 | ||
148 | __private_extern__ kern_return_t | |
149 | chudxnu_clear_cpu_rupt_counters(int cpu) | |
150 | { | |
151 | if(cpu < 0 || (unsigned int)cpu >= real_ncpus) { // sanity check | |
152 | return KERN_FAILURE; | |
153 | } | |
154 | ||
155 | /* | |
156 | * XXX | |
157 | * bzero((char *)&(cpu_data_ptr[cpu]->hwCtrs), sizeof(struct hwCtrs)); | |
158 | */ | |
159 | return KERN_SUCCESS; | |
160 | } |