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