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