]> git.saurik.com Git - apple/xnu.git/blame_incremental - osfmk/i386/cpu.c
xnu-1504.15.3.tar.gz
[apple/xnu.git] / osfmk / i386 / cpu.c
... / ...
CommitLineData
1/*
2 * Copyright (c) 2000-2009 Apple 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/*
29 * File: i386/cpu.c
30 *
31 * cpu specific routines
32 */
33
34#include <kern/kalloc.h>
35#include <kern/misc_protos.h>
36#include <kern/machine.h>
37#include <mach/processor_info.h>
38#include <i386/pmap.h>
39#include <i386/machine_cpu.h>
40#include <i386/machine_routines.h>
41#include <i386/misc_protos.h>
42#include <i386/cpu_threads.h>
43#include <i386/rtclock.h>
44#include <i386/cpuid.h>
45#if CONFIG_VMX
46#include <i386/vmx/vmx_cpu.h>
47#endif
48#include <vm/vm_kern.h>
49
50struct processor processor_master;
51
52/*ARGSUSED*/
53kern_return_t
54cpu_control(
55 int slot_num,
56 processor_info_t info,
57 unsigned int count)
58{
59 printf("cpu_control(%d,%p,%d) not implemented\n",
60 slot_num, info, count);
61 return (KERN_FAILURE);
62}
63
64/*ARGSUSED*/
65kern_return_t
66cpu_info_count(
67 __unused processor_flavor_t flavor,
68 unsigned int *count)
69{
70 *count = 0;
71 return (KERN_FAILURE);
72}
73
74/*ARGSUSED*/
75kern_return_t
76cpu_info(
77 processor_flavor_t flavor,
78 int slot_num,
79 processor_info_t info,
80 unsigned int *count)
81{
82 printf("cpu_info(%d,%d,%p,%p) not implemented\n",
83 flavor, slot_num, info, count);
84 return (KERN_FAILURE);
85}
86
87void
88cpu_sleep(void)
89{
90 cpu_data_t *cdp = current_cpu_datap();
91
92 i386_deactivate_cpu();
93
94 PE_cpu_machine_quiesce(cdp->cpu_id);
95
96 cpu_thread_halt();
97}
98
99void
100cpu_init(void)
101{
102 cpu_data_t *cdp = current_cpu_datap();
103
104 cdp->cpu_type = cpuid_cputype();
105 cdp->cpu_subtype = cpuid_cpusubtype();
106
107 i386_activate_cpu();
108}
109
110kern_return_t
111cpu_start(
112 int cpu)
113{
114 kern_return_t ret;
115
116 if (cpu == cpu_number()) {
117 cpu_machine_init();
118 return KERN_SUCCESS;
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) {
128 /*
129 * Should call out through PE.
130 * But take the shortcut here.
131 */
132 ret = intel_startCPU(cpu);
133 }
134
135 if (ret != KERN_SUCCESS)
136 kprintf("cpu: cpu_start(%d) returning failure!\n", cpu);
137
138 return(ret);
139}
140
141void
142cpu_exit_wait(
143 int cpu)
144{
145 cpu_data_t *cdp = cpu_datap(cpu);
146
147 /*
148 * Wait until the CPU indicates that it has stopped.
149 */
150 simple_lock(&x86_topo_lock);
151 while ((cdp->lcpu.state != LCPU_HALT)
152 && (cdp->lcpu.state != LCPU_OFF)
153 && !cdp->lcpu.stopped) {
154 simple_unlock(&x86_topo_lock);
155 cpu_pause();
156 simple_lock(&x86_topo_lock);
157 }
158 simple_unlock(&x86_topo_lock);
159}
160
161void
162cpu_machine_init(
163 void)
164{
165 cpu_data_t *cdp = current_cpu_datap();
166
167 PE_cpu_machine_init(cdp->cpu_id, !cdp->cpu_boot_complete);
168 cdp->cpu_boot_complete = TRUE;
169 cdp->cpu_running = TRUE;
170#if 0
171 if (cpu_datap(cpu)->hibernate)
172 {
173 cpu_datap(cpu)->hibernate = 0;
174 hibernate_machine_init();
175 }
176#endif
177 ml_init_interrupt();
178
179#if CONFIG_VMX
180 /* for every CPU, get the VT specs */
181 vmx_get_specs();
182#endif
183}
184
185processor_t
186cpu_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
202void
203cpu_processor_free(processor_t proc)
204{
205 if (proc != NULL && proc != &processor_master)
206 kfree((void *) proc, sizeof(*proc));
207}
208
209processor_t
210current_processor(void)
211{
212 return current_cpu_datap()->cpu_processor;
213}
214
215processor_t
216cpu_to_processor(
217 int cpu)
218{
219 return cpu_datap(cpu)->cpu_processor;
220}
221
222ast_t *
223ast_pending(void)
224{
225 return (&current_cpu_datap()->cpu_pending_ast);
226}
227
228cpu_type_t
229slot_type(
230 int slot_num)
231{
232 return (cpu_datap(slot_num)->cpu_type);
233}
234
235cpu_subtype_t
236slot_subtype(
237 int slot_num)
238{
239 return (cpu_datap(slot_num)->cpu_subtype);
240}
241
242cpu_threadtype_t
243slot_threadtype(
244 int slot_num)
245{
246 return (cpu_datap(slot_num)->cpu_threadtype);
247}
248
249
250
251cpu_type_t
252cpu_type(void)
253{
254 return (current_cpu_datap()->cpu_type);
255}
256
257cpu_subtype_t
258cpu_subtype(void)
259{
260 return (current_cpu_datap()->cpu_subtype);
261}
262
263cpu_threadtype_t
264cpu_threadtype(void)
265{
266 return (current_cpu_datap()->cpu_threadtype);
267}