]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
b0d623f7 | 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 | * @OSF_COPYRIGHT@ | |
30 | */ | |
31 | /* | |
32 | * Mach Operating System | |
33 | * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University | |
34 | * All Rights Reserved. | |
35 | * | |
36 | * Permission to use, copy, modify and distribute this software and its | |
37 | * documentation is hereby granted, provided that both the copyright | |
38 | * notice and this permission notice appear in all copies of the | |
39 | * software, derivative works or modified versions, and any portions | |
40 | * thereof, and that both notices appear in supporting documentation. | |
41 | * | |
42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | |
43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
45 | * | |
46 | * Carnegie Mellon requests users of this software to return to | |
47 | * | |
48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
49 | * School of Computer Science | |
50 | * Carnegie Mellon University | |
51 | * Pittsburgh PA 15213-3890 | |
52 | * | |
53 | * any improvements or extensions that they make and grant Carnegie Mellon | |
54 | * the rights to redistribute these changes. | |
55 | */ | |
56 | /* | |
57 | */ | |
58 | /* | |
59 | * File: kern/machine.c | |
60 | * Author: Avadis Tevanian, Jr. | |
61 | * Date: 1987 | |
62 | * | |
63 | * Support for machine independent machine abstraction. | |
64 | */ | |
65 | ||
1c79356b | 66 | #include <string.h> |
91447636 A |
67 | |
68 | #include <mach/mach_types.h> | |
1c79356b A |
69 | #include <mach/boolean.h> |
70 | #include <mach/kern_return.h> | |
1c79356b A |
71 | #include <mach/machine.h> |
72 | #include <mach/host_info.h> | |
73 | #include <mach/host_reboot.h> | |
91447636 A |
74 | #include <mach/host_priv_server.h> |
75 | #include <mach/processor_server.h> | |
76 | ||
77 | #include <kern/kern_types.h> | |
1c79356b A |
78 | #include <kern/counters.h> |
79 | #include <kern/cpu_data.h> | |
80 | #include <kern/ipc_host.h> | |
81 | #include <kern/host.h> | |
82 | #include <kern/lock.h> | |
83 | #include <kern/machine.h> | |
91447636 | 84 | #include <kern/misc_protos.h> |
1c79356b A |
85 | #include <kern/processor.h> |
86 | #include <kern/queue.h> | |
87 | #include <kern/sched.h> | |
88 | #include <kern/task.h> | |
89 | #include <kern/thread.h> | |
1c79356b | 90 | |
6d2010ae A |
91 | #include <machine/commpage.h> |
92 | ||
2d21ac55 | 93 | #if HIBERNATION |
3a60a9f5 | 94 | #include <IOKit/IOHibernatePrivate.h> |
2d21ac55 | 95 | #endif |
0c530ab8 | 96 | #include <IOKit/IOPlatformExpert.h> |
1c79356b A |
97 | |
98 | /* | |
99 | * Exported variables: | |
100 | */ | |
101 | ||
102 | struct machine_info machine_info; | |
1c79356b A |
103 | |
104 | /* Forwards */ | |
1c79356b A |
105 | void processor_doshutdown( |
106 | processor_t processor); | |
107 | ||
108 | /* | |
91447636 | 109 | * processor_up: |
1c79356b | 110 | * |
91447636 A |
111 | * Flag processor as up and running, and available |
112 | * for scheduling. | |
1c79356b A |
113 | */ |
114 | void | |
91447636 | 115 | processor_up( |
2d21ac55 | 116 | processor_t processor) |
1c79356b | 117 | { |
2d21ac55 | 118 | processor_set_t pset; |
91447636 | 119 | spl_t s; |
1c79356b A |
120 | |
121 | s = splsched(); | |
1c79356b | 122 | init_ast_check(processor); |
2d21ac55 A |
123 | pset = processor->processor_set; |
124 | pset_lock(pset); | |
6d2010ae A |
125 | if (++pset->online_processor_count == 1) { |
126 | pset_pri_init_hint(pset, processor); | |
127 | pset_count_init_hint(pset, processor); | |
128 | } | |
cf7d32b8 | 129 | enqueue_tail(&pset->active_queue, (queue_entry_t)processor); |
1c79356b | 130 | processor->state = PROCESSOR_RUNNING; |
2d21ac55 | 131 | (void)hw_atomic_add(&processor_avail_count, 1); |
6d2010ae | 132 | commpage_update_active_cpus(); |
2d21ac55 | 133 | pset_unlock(pset); |
91447636 | 134 | ml_cpu_up(); |
1c79356b A |
135 | splx(s); |
136 | } | |
137 | ||
138 | kern_return_t | |
139 | host_reboot( | |
55e303ae | 140 | host_priv_t host_priv, |
1c79356b A |
141 | int options) |
142 | { | |
143 | if (host_priv == HOST_PRIV_NULL) | |
144 | return (KERN_INVALID_HOST); | |
145 | ||
146 | assert(host_priv == &realhost); | |
147 | ||
148 | if (options & HOST_REBOOT_DEBUGGER) { | |
149 | Debugger("Debugger"); | |
55e303ae | 150 | return (KERN_SUCCESS); |
1c79356b A |
151 | } |
152 | ||
0c530ab8 A |
153 | if (options & HOST_REBOOT_UPSDELAY) { |
154 | // UPS power cutoff path | |
155 | PEHaltRestart( kPEUPSDelayHaltCPU ); | |
156 | } else { | |
157 | halt_all_cpus(!(options & HOST_REBOOT_HALT)); | |
158 | } | |
9bccf70c | 159 | |
55e303ae | 160 | return (KERN_SUCCESS); |
1c79356b A |
161 | } |
162 | ||
163 | kern_return_t | |
164 | processor_assign( | |
91447636 A |
165 | __unused processor_t processor, |
166 | __unused processor_set_t new_pset, | |
167 | __unused boolean_t wait) | |
1c79356b | 168 | { |
1c79356b A |
169 | return (KERN_FAILURE); |
170 | } | |
171 | ||
1c79356b A |
172 | kern_return_t |
173 | processor_shutdown( | |
55e303ae | 174 | processor_t processor) |
1c79356b | 175 | { |
55e303ae A |
176 | processor_set_t pset; |
177 | spl_t s; | |
1c79356b A |
178 | |
179 | s = splsched(); | |
2d21ac55 A |
180 | pset = processor->processor_set; |
181 | pset_lock(pset); | |
91447636 | 182 | if (processor->state == PROCESSOR_OFF_LINE) { |
1c79356b | 183 | /* |
91447636 | 184 | * Success if already shutdown. |
1c79356b | 185 | */ |
2d21ac55 | 186 | pset_unlock(pset); |
1c79356b A |
187 | splx(s); |
188 | ||
189 | return (KERN_SUCCESS); | |
190 | } | |
191 | ||
55e303ae A |
192 | if (processor->state == PROCESSOR_START) { |
193 | /* | |
194 | * Failure if currently being started. | |
195 | */ | |
2d21ac55 | 196 | pset_unlock(pset); |
55e303ae | 197 | splx(s); |
1c79356b | 198 | |
55e303ae A |
199 | return (KERN_FAILURE); |
200 | } | |
1c79356b | 201 | |
55e303ae | 202 | /* |
2d21ac55 | 203 | * If the processor is dispatching, let it finish. |
55e303ae | 204 | */ |
2d21ac55 A |
205 | while (processor->state == PROCESSOR_DISPATCHING) { |
206 | pset_unlock(pset); | |
207 | delay(1); | |
208 | pset_lock(pset); | |
91447636 | 209 | } |
2d21ac55 A |
210 | |
211 | /* | |
212 | * Success if already being shutdown. | |
213 | */ | |
214 | if (processor->state == PROCESSOR_SHUTDOWN) { | |
215 | pset_unlock(pset); | |
91447636 A |
216 | splx(s); |
217 | ||
218 | return (KERN_SUCCESS); | |
55e303ae | 219 | } |
1c79356b | 220 | |
c910b4d9 | 221 | if (processor->state == PROCESSOR_IDLE) |
6d2010ae | 222 | remqueue((queue_entry_t)processor); |
55e303ae A |
223 | else |
224 | if (processor->state == PROCESSOR_RUNNING) | |
6d2010ae | 225 | remqueue((queue_entry_t)processor); |
1c79356b | 226 | |
55e303ae | 227 | processor->state = PROCESSOR_SHUTDOWN; |
1c79356b | 228 | |
2d21ac55 | 229 | pset_unlock(pset); |
1c79356b | 230 | |
55e303ae | 231 | processor_doshutdown(processor); |
1c79356b | 232 | splx(s); |
1c79356b | 233 | |
b0d623f7 | 234 | cpu_exit_wait(processor->cpu_id); |
5353443c | 235 | |
55e303ae | 236 | return (KERN_SUCCESS); |
1c79356b A |
237 | } |
238 | ||
239 | /* | |
55e303ae | 240 | * Called at splsched. |
1c79356b A |
241 | */ |
242 | void | |
55e303ae A |
243 | processor_doshutdown( |
244 | processor_t processor) | |
1c79356b | 245 | { |
55e303ae | 246 | thread_t old_thread, self = current_thread(); |
55e303ae | 247 | processor_t prev; |
1c79356b A |
248 | |
249 | /* | |
250 | * Get onto the processor to shutdown | |
251 | */ | |
2d21ac55 | 252 | prev = thread_bind(processor); |
9bccf70c | 253 | thread_block(THREAD_CONTINUE_NULL); |
1c79356b | 254 | |
2d21ac55 A |
255 | #if HIBERNATION |
256 | if (processor_avail_count < 2) | |
3a60a9f5 | 257 | hibernate_vm_lock(); |
2d21ac55 | 258 | #endif |
1c79356b | 259 | |
55e303ae | 260 | assert(processor->state == PROCESSOR_SHUTDOWN); |
1c79356b | 261 | |
2d21ac55 A |
262 | #if HIBERNATION |
263 | if (processor_avail_count < 2) | |
3a60a9f5 | 264 | hibernate_vm_unlock(); |
2d21ac55 | 265 | #endif |
91447636 | 266 | |
1c79356b | 267 | /* |
91447636 | 268 | * Continue processor shutdown in shutdown context. |
1c79356b | 269 | */ |
2d21ac55 | 270 | thread_bind(prev); |
91447636 | 271 | old_thread = machine_processor_shutdown(self, processor_offline, processor); |
a3d08fcd | 272 | |
2d21ac55 | 273 | thread_dispatch(old_thread, self); |
1c79356b A |
274 | } |
275 | ||
276 | /* | |
91447636 A |
277 | * Complete the shutdown and place the processor offline. |
278 | * | |
279 | * Called at splsched in the shutdown context. | |
1c79356b | 280 | */ |
1c79356b | 281 | void |
55e303ae | 282 | processor_offline( |
2d21ac55 | 283 | processor_t processor) |
1c79356b | 284 | { |
2d21ac55 A |
285 | thread_t new_thread, old_thread = processor->active_thread; |
286 | processor_set_t pset; | |
91447636 | 287 | |
2d21ac55 A |
288 | new_thread = processor->idle_thread; |
289 | processor->active_thread = new_thread; | |
91447636 | 290 | processor->current_pri = IDLEPRI; |
6d2010ae | 291 | processor->current_thmode = TH_MODE_NONE; |
2d21ac55 A |
292 | processor->deadline = UINT64_MAX; |
293 | new_thread->last_processor = processor; | |
91447636 A |
294 | |
295 | processor->last_dispatch = mach_absolute_time(); | |
2d21ac55 | 296 | timer_stop(PROCESSOR_DATA(processor, thread_timer), processor->last_dispatch); |
91447636 | 297 | |
2d21ac55 | 298 | machine_set_current_thread(new_thread); |
91447636 | 299 | |
2d21ac55 | 300 | thread_dispatch(old_thread, new_thread); |
1c79356b | 301 | |
b0d623f7 | 302 | PMAP_DEACTIVATE_KERNEL(processor->cpu_id); |
91447636 | 303 | |
2d21ac55 A |
304 | pset = processor->processor_set; |
305 | pset_lock(pset); | |
91447636 | 306 | processor->state = PROCESSOR_OFF_LINE; |
6d2010ae A |
307 | if (--pset->online_processor_count == 0) { |
308 | pset_pri_init_hint(pset, PROCESSOR_NULL); | |
309 | pset_count_init_hint(pset, PROCESSOR_NULL); | |
310 | } | |
2d21ac55 | 311 | (void)hw_atomic_sub(&processor_avail_count, 1); |
6d2010ae A |
312 | commpage_update_active_cpus(); |
313 | SCHED(processor_queue_shutdown)(processor); | |
c910b4d9 A |
314 | /* pset lock dropped */ |
315 | ||
91447636 | 316 | ml_cpu_down(); |
91447636 | 317 | |
1c79356b A |
318 | cpu_sleep(); |
319 | panic("zombie processor"); | |
320 | /*NOTREACHED*/ | |
321 | } | |
322 | ||
323 | kern_return_t | |
324 | host_get_boot_info( | |
325 | host_priv_t host_priv, | |
326 | kernel_boot_info_t boot_info) | |
327 | { | |
91447636 | 328 | const char *src = ""; |
1c79356b A |
329 | if (host_priv == HOST_PRIV_NULL) |
330 | return (KERN_INVALID_HOST); | |
331 | ||
332 | assert(host_priv == &realhost); | |
333 | ||
334 | /* | |
335 | * Copy first operator string terminated by '\0' followed by | |
336 | * standardized strings generated from boot string. | |
337 | */ | |
338 | src = machine_boot_info(boot_info, KERNEL_BOOT_INFO_MAX); | |
339 | if (src != boot_info) | |
340 | (void) strncpy(boot_info, src, KERNEL_BOOT_INFO_MAX); | |
341 | ||
342 | return (KERN_SUCCESS); | |
343 | } |