]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
2d21ac55 | 2 | * Copyright (c) 2000-2007 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> |
55e303ae A |
38 | #include <i386/machine_cpu.h> |
39 | #include <i386/machine_routines.h> | |
91447636 A |
40 | #include <i386/pmap.h> |
41 | #include <i386/misc_protos.h> | |
42 | #include <i386/cpu_threads.h> | |
0c530ab8 | 43 | #include <i386/rtclock.h> |
91447636 | 44 | #include <vm/vm_kern.h> |
0c530ab8 | 45 | #include "cpuid.h" |
1c79356b | 46 | |
91447636 | 47 | struct processor processor_master; |
9bccf70c | 48 | |
1c79356b A |
49 | /*ARGSUSED*/ |
50 | kern_return_t | |
51 | cpu_control( | |
52 | int slot_num, | |
53 | processor_info_t info, | |
54 | unsigned int count) | |
55 | { | |
2d21ac55 | 56 | printf("cpu_control(%d,%p,%d) not implemented\n", |
91447636 | 57 | slot_num, info, count); |
1c79356b A |
58 | return (KERN_FAILURE); |
59 | } | |
60 | ||
61 | /*ARGSUSED*/ | |
62 | kern_return_t | |
63 | cpu_info_count( | |
91447636 A |
64 | __unused processor_flavor_t flavor, |
65 | unsigned int *count) | |
1c79356b A |
66 | { |
67 | *count = 0; | |
68 | return (KERN_FAILURE); | |
69 | } | |
70 | ||
71 | /*ARGSUSED*/ | |
72 | kern_return_t | |
73 | cpu_info( | |
74 | processor_flavor_t flavor, | |
75 | int slot_num, | |
76 | processor_info_t info, | |
77 | unsigned int *count) | |
78 | { | |
2d21ac55 | 79 | printf("cpu_info(%d,%d,%p,%p) not implemented\n", |
91447636 | 80 | flavor, slot_num, info, count); |
1c79356b A |
81 | return (KERN_FAILURE); |
82 | } | |
83 | ||
84 | void | |
91447636 | 85 | cpu_sleep(void) |
1c79356b | 86 | { |
2d21ac55 | 87 | cpu_data_t *cdp = current_cpu_datap(); |
55e303ae | 88 | |
2d21ac55 | 89 | i386_deactivate_cpu(); |
0c530ab8 | 90 | |
2d21ac55 | 91 | PE_cpu_machine_quiesce(cdp->cpu_id); |
55e303ae | 92 | |
91447636 | 93 | cpu_thread_halt(); |
55e303ae A |
94 | } |
95 | ||
91447636 A |
96 | void |
97 | cpu_init(void) | |
55e303ae | 98 | { |
91447636 | 99 | cpu_data_t *cdp = current_cpu_datap(); |
55e303ae | 100 | |
0c530ab8 A |
101 | cdp->cpu_type = cpuid_cputype(); |
102 | cdp->cpu_subtype = cpuid_cpusubtype(); | |
103 | ||
2d21ac55 | 104 | i386_activate_cpu(); |
55e303ae A |
105 | } |
106 | ||
107 | kern_return_t | |
108 | cpu_start( | |
109 | int cpu) | |
110 | { | |
111 | kern_return_t ret; | |
112 | ||
113 | if (cpu == cpu_number()) { | |
91447636 | 114 | cpu_machine_init(); |
55e303ae A |
115 | return KERN_SUCCESS; |
116 | } else { | |
117 | /* | |
118 | * Should call out through PE. | |
119 | * But take the shortcut here. | |
120 | */ | |
121 | ret = intel_startCPU(cpu); | |
122 | return(ret); | |
123 | } | |
124 | } | |
125 | ||
91447636 A |
126 | void |
127 | cpu_exit_wait( | |
2d21ac55 | 128 | int cpu) |
91447636 | 129 | { |
2d21ac55 A |
130 | cpu_data_t *cdp = cpu_datap(cpu); |
131 | ||
132 | simple_lock(&x86_topo_lock); | |
133 | while (!cdp->lcpu.halted) { | |
134 | simple_unlock(&x86_topo_lock); | |
135 | cpu_pause(); | |
136 | simple_lock(&x86_topo_lock); | |
137 | } | |
138 | simple_unlock(&x86_topo_lock); | |
91447636 A |
139 | } |
140 | ||
55e303ae A |
141 | void |
142 | cpu_machine_init( | |
143 | void) | |
144 | { | |
0c530ab8 | 145 | cpu_data_t *cdp = current_cpu_datap(); |
55e303ae | 146 | |
0c530ab8 A |
147 | PE_cpu_machine_init(cdp->cpu_id, !cdp->cpu_boot_complete); |
148 | cdp->cpu_boot_complete = TRUE; | |
149 | cdp->cpu_running = TRUE; | |
3a60a9f5 A |
150 | #if 0 |
151 | if (cpu_datap(cpu)->hibernate) | |
152 | { | |
153 | cpu_datap(cpu)->hibernate = 0; | |
154 | hibernate_machine_init(); | |
155 | } | |
156 | #endif | |
55e303ae | 157 | ml_init_interrupt(); |
2d21ac55 A |
158 | |
159 | /* for every CPU, get the VT specs */ | |
160 | vmx_get_specs(); | |
55e303ae A |
161 | } |
162 | ||
91447636 A |
163 | processor_t |
164 | cpu_processor_alloc(boolean_t is_boot_cpu) | |
165 | { | |
166 | int ret; | |
167 | processor_t proc; | |
168 | ||
169 | if (is_boot_cpu) | |
170 | return &processor_master; | |
171 | ||
172 | ret = kmem_alloc(kernel_map, (vm_offset_t *) &proc, sizeof(*proc)); | |
173 | if (ret != KERN_SUCCESS) | |
174 | return NULL; | |
175 | ||
176 | bzero((void *) proc, sizeof(*proc)); | |
177 | return proc; | |
178 | } | |
179 | ||
180 | void | |
181 | cpu_processor_free(processor_t proc) | |
182 | { | |
183 | if (proc != NULL && proc != &processor_master) | |
184 | kfree((void *) proc, sizeof(*proc)); | |
185 | } | |
186 | ||
187 | processor_t | |
188 | current_processor(void) | |
189 | { | |
190 | return current_cpu_datap()->cpu_processor; | |
191 | } | |
192 | ||
193 | processor_t | |
194 | cpu_to_processor( | |
195 | int cpu) | |
196 | { | |
197 | return cpu_datap(cpu)->cpu_processor; | |
198 | } | |
199 | ||
200 | ast_t * | |
201 | ast_pending(void) | |
202 | { | |
203 | return (¤t_cpu_datap()->cpu_pending_ast); | |
204 | } | |
205 | ||
206 | cpu_type_t | |
207 | slot_type( | |
208 | int slot_num) | |
209 | { | |
210 | return (cpu_datap(slot_num)->cpu_type); | |
211 | } | |
212 | ||
213 | cpu_subtype_t | |
214 | slot_subtype( | |
215 | int slot_num) | |
216 | { | |
217 | return (cpu_datap(slot_num)->cpu_subtype); | |
218 | } | |
219 | ||
220 | cpu_threadtype_t | |
221 | slot_threadtype( | |
222 | int slot_num) | |
223 | { | |
224 | return (cpu_datap(slot_num)->cpu_threadtype); | |
225 | } | |
226 | ||
227 | cpu_type_t | |
228 | cpu_type(void) | |
229 | { | |
230 | return (current_cpu_datap()->cpu_type); | |
231 | } | |
232 | ||
233 | cpu_subtype_t | |
234 | cpu_subtype(void) | |
235 | { | |
236 | return (current_cpu_datap()->cpu_subtype); | |
237 | } | |
238 | ||
239 | cpu_threadtype_t | |
240 | cpu_threadtype(void) | |
241 | { | |
242 | return (current_cpu_datap()->cpu_threadtype); | |
243 | } |