]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/cpu.c
7d19205d83ac7c3c64a95334c9cd7014118e6db3
[apple/xnu.git] / osfmk / i386 / cpu.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * File: i386/cpu.c
24 *
25 * cpu specific routines
26 */
27
28 #include <kern/kalloc.h>
29 #include <kern/misc_protos.h>
30 #include <kern/machine.h>
31 #include <mach/processor_info.h>
32 #include <i386/mp.h>
33 #include <i386/machine_cpu.h>
34 #include <i386/machine_routines.h>
35 #include <i386/pmap.h>
36 #include <i386/misc_protos.h>
37 #include <i386/cpu_threads.h>
38 #include <i386/rtclock.h>
39 #include <vm/vm_kern.h>
40 #include "cpuid.h"
41
42 struct processor processor_master;
43
44 /*ARGSUSED*/
45 kern_return_t
46 cpu_control(
47 int slot_num,
48 processor_info_t info,
49 unsigned int count)
50 {
51 printf("cpu_control(%d,0x%x,%d) not implemented\n",
52 slot_num, info, count);
53 return (KERN_FAILURE);
54 }
55
56 /*ARGSUSED*/
57 kern_return_t
58 cpu_info_count(
59 __unused processor_flavor_t flavor,
60 unsigned int *count)
61 {
62 *count = 0;
63 return (KERN_FAILURE);
64 }
65
66 /*ARGSUSED*/
67 kern_return_t
68 cpu_info(
69 processor_flavor_t flavor,
70 int slot_num,
71 processor_info_t info,
72 unsigned int *count)
73 {
74 printf("cpu_info(%d,%d,0x%x,0x%x) not implemented\n",
75 flavor, slot_num, info, count);
76 return (KERN_FAILURE);
77 }
78
79 void
80 cpu_sleep(void)
81 {
82 cpu_data_t *proc_info = current_cpu_datap();
83
84 proc_info->cpu_running = FALSE;
85
86 PE_cpu_machine_quiesce(proc_info->cpu_id);
87
88 cpu_thread_halt();
89 }
90
91 void
92 cpu_init(void)
93 {
94 cpu_data_t *cdp = current_cpu_datap();
95
96 /* be sure cpuid is initialized */
97 cpuid_set_info();
98
99 /* and allow it to be authoritative */
100 cdp->cpu_type = cpuid_cputype();
101 cdp->cpu_subtype = cpuid_cpusubtype();
102
103 cdp->cpu_running = TRUE;
104 }
105
106 kern_return_t
107 cpu_start(
108 int cpu)
109 {
110 kern_return_t ret;
111
112 if (cpu == cpu_number()) {
113 cpu_machine_init();
114 return KERN_SUCCESS;
115 } else {
116 /*
117 * Should call out through PE.
118 * But take the shortcut here.
119 */
120 ret = intel_startCPU(cpu);
121 return(ret);
122 }
123 }
124
125 void
126 cpu_exit_wait(
127 __unused int cpu)
128 {
129 }
130
131 void
132 cpu_machine_init(
133 void)
134 {
135 cpu_data_t *cdp = current_cpu_datap();
136
137 PE_cpu_machine_init(cdp->cpu_id, !cdp->cpu_boot_complete);
138 cdp->cpu_boot_complete = TRUE;
139 cdp->cpu_running = TRUE;
140 #if 0
141 if (cpu_datap(cpu)->hibernate)
142 {
143 cpu_datap(cpu)->hibernate = 0;
144 hibernate_machine_init();
145 }
146 #endif
147 ml_init_interrupt();
148 }
149
150 processor_t
151 cpu_processor_alloc(boolean_t is_boot_cpu)
152 {
153 int ret;
154 processor_t proc;
155
156 if (is_boot_cpu)
157 return &processor_master;
158
159 ret = kmem_alloc(kernel_map, (vm_offset_t *) &proc, sizeof(*proc));
160 if (ret != KERN_SUCCESS)
161 return NULL;
162
163 bzero((void *) proc, sizeof(*proc));
164 return proc;
165 }
166
167 void
168 cpu_processor_free(processor_t proc)
169 {
170 if (proc != NULL && proc != &processor_master)
171 kfree((void *) proc, sizeof(*proc));
172 }
173
174 processor_t
175 current_processor(void)
176 {
177 return current_cpu_datap()->cpu_processor;
178 }
179
180 processor_t
181 cpu_to_processor(
182 int cpu)
183 {
184 return cpu_datap(cpu)->cpu_processor;
185 }
186
187 ast_t *
188 ast_pending(void)
189 {
190 return (&current_cpu_datap()->cpu_pending_ast);
191 }
192
193 cpu_type_t
194 slot_type(
195 int slot_num)
196 {
197 return (cpu_datap(slot_num)->cpu_type);
198 }
199
200 cpu_subtype_t
201 slot_subtype(
202 int slot_num)
203 {
204 return (cpu_datap(slot_num)->cpu_subtype);
205 }
206
207 cpu_threadtype_t
208 slot_threadtype(
209 int slot_num)
210 {
211 return (cpu_datap(slot_num)->cpu_threadtype);
212 }
213
214 cpu_type_t
215 cpu_type(void)
216 {
217 return (current_cpu_datap()->cpu_type);
218 }
219
220 cpu_subtype_t
221 cpu_subtype(void)
222 {
223 return (current_cpu_datap()->cpu_subtype);
224 }
225
226 cpu_threadtype_t
227 cpu_threadtype(void)
228 {
229 return (current_cpu_datap()->cpu_threadtype);
230 }