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