]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/cpu.c
xnu-1699.32.7.tar.gz
[apple/xnu.git] / osfmk / i386 / cpu.c
CommitLineData
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>
6d2010ae 43#include <i386/rtclock_protos.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>
6d2010ae
A
49#include <kern/etimer.h>
50#include <kern/timer_call.h>
1c79356b 51
91447636 52struct processor processor_master;
9bccf70c 53
1c79356b
A
54/*ARGSUSED*/
55kern_return_t
56cpu_control(
57 int slot_num,
58 processor_info_t info,
59 unsigned int count)
60{
2d21ac55 61 printf("cpu_control(%d,%p,%d) not implemented\n",
91447636 62 slot_num, info, count);
1c79356b
A
63 return (KERN_FAILURE);
64}
65
66/*ARGSUSED*/
67kern_return_t
68cpu_info_count(
91447636
A
69 __unused processor_flavor_t flavor,
70 unsigned int *count)
1c79356b
A
71{
72 *count = 0;
73 return (KERN_FAILURE);
74}
75
76/*ARGSUSED*/
77kern_return_t
78cpu_info(
79 processor_flavor_t flavor,
80 int slot_num,
81 processor_info_t info,
82 unsigned int *count)
83{
2d21ac55 84 printf("cpu_info(%d,%d,%p,%p) not implemented\n",
91447636 85 flavor, slot_num, info, count);
1c79356b
A
86 return (KERN_FAILURE);
87}
88
89void
91447636 90cpu_sleep(void)
1c79356b 91{
2d21ac55 92 cpu_data_t *cdp = current_cpu_datap();
55e303ae 93
2d21ac55 94 i386_deactivate_cpu();
0c530ab8 95
2d21ac55 96 PE_cpu_machine_quiesce(cdp->cpu_id);
55e303ae 97
91447636 98 cpu_thread_halt();
55e303ae
A
99}
100
91447636
A
101void
102cpu_init(void)
55e303ae 103{
91447636 104 cpu_data_t *cdp = current_cpu_datap();
55e303ae 105
6d2010ae
A
106 timer_call_initialize_queue(&cdp->rtclock_timer.queue);
107 cdp->rtclock_timer.deadline = EndOfAllTime;
108
0c530ab8
A
109 cdp->cpu_type = cpuid_cputype();
110 cdp->cpu_subtype = cpuid_cpusubtype();
111
2d21ac55 112 i386_activate_cpu();
55e303ae
A
113}
114
115kern_return_t
116cpu_start(
117 int cpu)
118{
119 kern_return_t ret;
120
121 if (cpu == cpu_number()) {
91447636 122 cpu_machine_init();
55e303ae 123 return KERN_SUCCESS;
593a1d5f
A
124 }
125
126 /*
127 * Try to bring the CPU back online without a reset.
128 * If the fast restart doesn't succeed, fall back to
129 * the slow way.
130 */
131 ret = intel_startCPU_fast(cpu);
132 if (ret != KERN_SUCCESS) {
55e303ae
A
133 /*
134 * Should call out through PE.
135 * But take the shortcut here.
136 */
137 ret = intel_startCPU(cpu);
55e303ae 138 }
593a1d5f
A
139
140 if (ret != KERN_SUCCESS)
141 kprintf("cpu: cpu_start(%d) returning failure!\n", cpu);
142
143 return(ret);
55e303ae
A
144}
145
91447636
A
146void
147cpu_exit_wait(
2d21ac55 148 int cpu)
91447636 149{
2d21ac55
A
150 cpu_data_t *cdp = cpu_datap(cpu);
151
e2fac8b1
A
152 /*
153 * Wait until the CPU indicates that it has stopped.
154 */
2d21ac55 155 simple_lock(&x86_topo_lock);
593a1d5f 156 while ((cdp->lcpu.state != LCPU_HALT)
e2fac8b1
A
157 && (cdp->lcpu.state != LCPU_OFF)
158 && !cdp->lcpu.stopped) {
2d21ac55
A
159 simple_unlock(&x86_topo_lock);
160 cpu_pause();
161 simple_lock(&x86_topo_lock);
162 }
163 simple_unlock(&x86_topo_lock);
91447636
A
164}
165
55e303ae
A
166void
167cpu_machine_init(
168 void)
169{
0c530ab8 170 cpu_data_t *cdp = current_cpu_datap();
55e303ae 171
0c530ab8
A
172 PE_cpu_machine_init(cdp->cpu_id, !cdp->cpu_boot_complete);
173 cdp->cpu_boot_complete = TRUE;
174 cdp->cpu_running = TRUE;
55e303ae 175 ml_init_interrupt();
2d21ac55 176
b0d623f7 177#if CONFIG_VMX
2d21ac55
A
178 /* for every CPU, get the VT specs */
179 vmx_get_specs();
b0d623f7 180#endif
55e303ae
A
181}
182
91447636
A
183processor_t
184cpu_processor_alloc(boolean_t is_boot_cpu)
185{
186 int ret;
187 processor_t proc;
188
189 if (is_boot_cpu)
190 return &processor_master;
191
192 ret = kmem_alloc(kernel_map, (vm_offset_t *) &proc, sizeof(*proc));
193 if (ret != KERN_SUCCESS)
194 return NULL;
195
196 bzero((void *) proc, sizeof(*proc));
197 return proc;
198}
199
200void
201cpu_processor_free(processor_t proc)
202{
203 if (proc != NULL && proc != &processor_master)
204 kfree((void *) proc, sizeof(*proc));
205}
206
207processor_t
208current_processor(void)
209{
210 return current_cpu_datap()->cpu_processor;
211}
212
213processor_t
214cpu_to_processor(
215 int cpu)
216{
217 return cpu_datap(cpu)->cpu_processor;
218}
219
220ast_t *
221ast_pending(void)
222{
223 return (&current_cpu_datap()->cpu_pending_ast);
224}
225
226cpu_type_t
227slot_type(
228 int slot_num)
229{
230 return (cpu_datap(slot_num)->cpu_type);
231}
232
233cpu_subtype_t
234slot_subtype(
235 int slot_num)
236{
237 return (cpu_datap(slot_num)->cpu_subtype);
238}
239
240cpu_threadtype_t
241slot_threadtype(
242 int slot_num)
243{
244 return (cpu_datap(slot_num)->cpu_threadtype);
245}
246
247cpu_type_t
248cpu_type(void)
249{
250 return (current_cpu_datap()->cpu_type);
251}
252
253cpu_subtype_t
254cpu_subtype(void)
255{
256 return (current_cpu_datap()->cpu_subtype);
257}
258
259cpu_threadtype_t
260cpu_threadtype(void)
261{
262 return (current_cpu_datap()->cpu_threadtype);
263}