]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
e2fac8b1 | 2 | * Copyright (c) 2000-2009 Apple Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
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. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * File: i386/cpu.c | |
30 | * | |
31 | * cpu specific routines | |
32 | */ | |
33 | ||
91447636 | 34 | #include <kern/kalloc.h> |
1c79356b | 35 | #include <kern/misc_protos.h> |
91447636 | 36 | #include <kern/machine.h> |
1c79356b | 37 | #include <mach/processor_info.h> |
b0d623f7 | 38 | #include <i386/pmap.h> |
55e303ae A |
39 | #include <i386/machine_cpu.h> |
40 | #include <i386/machine_routines.h> | |
91447636 A |
41 | #include <i386/misc_protos.h> |
42 | #include <i386/cpu_threads.h> | |
0c530ab8 | 43 | #include <i386/rtclock.h> |
b0d623f7 A |
44 | #include <i386/cpuid.h> |
45 | #if CONFIG_VMX | |
46 | #include <i386/vmx/vmx_cpu.h> | |
47 | #endif | |
91447636 | 48 | #include <vm/vm_kern.h> |
1c79356b | 49 | |
91447636 | 50 | struct processor processor_master; |
9bccf70c | 51 | |
1c79356b A |
52 | /*ARGSUSED*/ |
53 | kern_return_t | |
54 | cpu_control( | |
55 | int slot_num, | |
56 | processor_info_t info, | |
57 | unsigned int count) | |
58 | { | |
2d21ac55 | 59 | printf("cpu_control(%d,%p,%d) not implemented\n", |
91447636 | 60 | slot_num, info, count); |
1c79356b A |
61 | return (KERN_FAILURE); |
62 | } | |
63 | ||
64 | /*ARGSUSED*/ | |
65 | kern_return_t | |
66 | cpu_info_count( | |
91447636 A |
67 | __unused processor_flavor_t flavor, |
68 | unsigned int *count) | |
1c79356b A |
69 | { |
70 | *count = 0; | |
71 | return (KERN_FAILURE); | |
72 | } | |
73 | ||
74 | /*ARGSUSED*/ | |
75 | kern_return_t | |
76 | cpu_info( | |
77 | processor_flavor_t flavor, | |
78 | int slot_num, | |
79 | processor_info_t info, | |
80 | unsigned int *count) | |
81 | { | |
2d21ac55 | 82 | printf("cpu_info(%d,%d,%p,%p) not implemented\n", |
91447636 | 83 | flavor, slot_num, info, count); |
1c79356b A |
84 | return (KERN_FAILURE); |
85 | } | |
86 | ||
87 | void | |
91447636 | 88 | cpu_sleep(void) |
1c79356b | 89 | { |
2d21ac55 | 90 | cpu_data_t *cdp = current_cpu_datap(); |
55e303ae | 91 | |
2d21ac55 | 92 | i386_deactivate_cpu(); |
0c530ab8 | 93 | |
2d21ac55 | 94 | PE_cpu_machine_quiesce(cdp->cpu_id); |
55e303ae | 95 | |
91447636 | 96 | cpu_thread_halt(); |
55e303ae A |
97 | } |
98 | ||
91447636 A |
99 | void |
100 | cpu_init(void) | |
55e303ae | 101 | { |
91447636 | 102 | cpu_data_t *cdp = current_cpu_datap(); |
55e303ae | 103 | |
0c530ab8 A |
104 | cdp->cpu_type = cpuid_cputype(); |
105 | cdp->cpu_subtype = cpuid_cpusubtype(); | |
106 | ||
2d21ac55 | 107 | i386_activate_cpu(); |
55e303ae A |
108 | } |
109 | ||
110 | kern_return_t | |
111 | cpu_start( | |
112 | int cpu) | |
113 | { | |
114 | kern_return_t ret; | |
115 | ||
116 | if (cpu == cpu_number()) { | |
91447636 | 117 | cpu_machine_init(); |
55e303ae | 118 | return KERN_SUCCESS; |
593a1d5f A |
119 | } |
120 | ||
121 | /* | |
122 | * Try to bring the CPU back online without a reset. | |
123 | * If the fast restart doesn't succeed, fall back to | |
124 | * the slow way. | |
125 | */ | |
126 | ret = intel_startCPU_fast(cpu); | |
127 | if (ret != KERN_SUCCESS) { | |
55e303ae A |
128 | /* |
129 | * Should call out through PE. | |
130 | * But take the shortcut here. | |
131 | */ | |
132 | ret = intel_startCPU(cpu); | |
55e303ae | 133 | } |
593a1d5f A |
134 | |
135 | if (ret != KERN_SUCCESS) | |
136 | kprintf("cpu: cpu_start(%d) returning failure!\n", cpu); | |
137 | ||
138 | return(ret); | |
55e303ae A |
139 | } |
140 | ||
91447636 A |
141 | void |
142 | cpu_exit_wait( | |
2d21ac55 | 143 | int cpu) |
91447636 | 144 | { |
2d21ac55 A |
145 | cpu_data_t *cdp = cpu_datap(cpu); |
146 | ||
e2fac8b1 A |
147 | /* |
148 | * Wait until the CPU indicates that it has stopped. | |
149 | */ | |
2d21ac55 | 150 | simple_lock(&x86_topo_lock); |
593a1d5f | 151 | while ((cdp->lcpu.state != LCPU_HALT) |
e2fac8b1 A |
152 | && (cdp->lcpu.state != LCPU_OFF) |
153 | && !cdp->lcpu.stopped) { | |
2d21ac55 A |
154 | simple_unlock(&x86_topo_lock); |
155 | cpu_pause(); | |
156 | simple_lock(&x86_topo_lock); | |
157 | } | |
158 | simple_unlock(&x86_topo_lock); | |
91447636 A |
159 | } |
160 | ||
55e303ae A |
161 | void |
162 | cpu_machine_init( | |
163 | void) | |
164 | { | |
0c530ab8 | 165 | cpu_data_t *cdp = current_cpu_datap(); |
55e303ae | 166 | |
0c530ab8 A |
167 | PE_cpu_machine_init(cdp->cpu_id, !cdp->cpu_boot_complete); |
168 | cdp->cpu_boot_complete = TRUE; | |
169 | cdp->cpu_running = TRUE; | |
3a60a9f5 A |
170 | #if 0 |
171 | if (cpu_datap(cpu)->hibernate) | |
172 | { | |
173 | cpu_datap(cpu)->hibernate = 0; | |
174 | hibernate_machine_init(); | |
175 | } | |
176 | #endif | |
55e303ae | 177 | ml_init_interrupt(); |
2d21ac55 | 178 | |
b0d623f7 | 179 | #if CONFIG_VMX |
2d21ac55 A |
180 | /* for every CPU, get the VT specs */ |
181 | vmx_get_specs(); | |
b0d623f7 | 182 | #endif |
55e303ae A |
183 | } |
184 | ||
91447636 A |
185 | processor_t |
186 | cpu_processor_alloc(boolean_t is_boot_cpu) | |
187 | { | |
188 | int ret; | |
189 | processor_t proc; | |
190 | ||
191 | if (is_boot_cpu) | |
192 | return &processor_master; | |
193 | ||
194 | ret = kmem_alloc(kernel_map, (vm_offset_t *) &proc, sizeof(*proc)); | |
195 | if (ret != KERN_SUCCESS) | |
196 | return NULL; | |
197 | ||
198 | bzero((void *) proc, sizeof(*proc)); | |
199 | return proc; | |
200 | } | |
201 | ||
202 | void | |
203 | cpu_processor_free(processor_t proc) | |
204 | { | |
205 | if (proc != NULL && proc != &processor_master) | |
206 | kfree((void *) proc, sizeof(*proc)); | |
207 | } | |
208 | ||
209 | processor_t | |
210 | current_processor(void) | |
211 | { | |
212 | return current_cpu_datap()->cpu_processor; | |
213 | } | |
214 | ||
215 | processor_t | |
216 | cpu_to_processor( | |
217 | int cpu) | |
218 | { | |
219 | return cpu_datap(cpu)->cpu_processor; | |
220 | } | |
221 | ||
222 | ast_t * | |
223 | ast_pending(void) | |
224 | { | |
225 | return (¤t_cpu_datap()->cpu_pending_ast); | |
226 | } | |
227 | ||
228 | cpu_type_t | |
229 | slot_type( | |
230 | int slot_num) | |
231 | { | |
232 | return (cpu_datap(slot_num)->cpu_type); | |
233 | } | |
234 | ||
235 | cpu_subtype_t | |
236 | slot_subtype( | |
237 | int slot_num) | |
238 | { | |
239 | return (cpu_datap(slot_num)->cpu_subtype); | |
240 | } | |
241 | ||
242 | cpu_threadtype_t | |
243 | slot_threadtype( | |
244 | int slot_num) | |
245 | { | |
246 | return (cpu_datap(slot_num)->cpu_threadtype); | |
247 | } | |
248 | ||
b0d623f7 A |
249 | |
250 | ||
91447636 A |
251 | cpu_type_t |
252 | cpu_type(void) | |
253 | { | |
254 | return (current_cpu_datap()->cpu_type); | |
255 | } | |
256 | ||
257 | cpu_subtype_t | |
258 | cpu_subtype(void) | |
259 | { | |
260 | return (current_cpu_datap()->cpu_subtype); | |
261 | } | |
262 | ||
263 | cpu_threadtype_t | |
264 | cpu_threadtype(void) | |
265 | { | |
266 | return (current_cpu_datap()->cpu_threadtype); | |
267 | } |