|
22 | 22 | #include <linux/dma_remapping.h> |
23 | 23 | #include <linux/init_task.h> |
24 | 24 | #include <linux/spinlock.h> |
| 25 | +#include <linux/delay.h> |
25 | 26 | #include <linux/sched.h> |
26 | 27 | #include <linux/init.h> |
27 | 28 | #include <linux/dmar.h> |
| 29 | +#include <linux/cpu.h> |
28 | 30 | #include <linux/pfn.h> |
29 | 31 | #include <linux/mm.h> |
| 32 | +#include <linux/tboot.h> |
30 | 33 |
|
31 | 34 | #include <asm/trampoline.h> |
32 | 35 | #include <asm/processor.h> |
|
36 | 39 | #include <asm/fixmap.h> |
37 | 40 | #include <asm/proto.h> |
38 | 41 | #include <asm/setup.h> |
39 | | -#include <asm/tboot.h> |
40 | 42 | #include <asm/e820.h> |
41 | 43 | #include <asm/io.h> |
42 | 44 |
|
@@ -154,13 +156,10 @@ static int map_tboot_pages(unsigned long vaddr, unsigned long start_pfn, |
154 | 156 | return 0; |
155 | 157 | } |
156 | 158 |
|
157 | | -void tboot_create_trampoline(void) |
| 159 | +static void tboot_create_trampoline(void) |
158 | 160 | { |
159 | 161 | u32 map_base, map_size; |
160 | 162 |
|
161 | | - if (!tboot_enabled()) |
162 | | - return; |
163 | | - |
164 | 163 | /* Create identity map for tboot shutdown code. */ |
165 | 164 | map_base = PFN_DOWN(tboot->tboot_base); |
166 | 165 | map_size = PFN_UP(tboot->tboot_size); |
@@ -295,21 +294,58 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control) |
295 | 294 | tboot_shutdown(acpi_shutdown_map[sleep_state]); |
296 | 295 | } |
297 | 296 |
|
298 | | -int tboot_wait_for_aps(int num_aps) |
| 297 | +static atomic_t ap_wfs_count; |
| 298 | + |
| 299 | +static int tboot_wait_for_aps(int num_aps) |
299 | 300 | { |
300 | 301 | unsigned long timeout; |
301 | 302 |
|
| 303 | + timeout = AP_WAIT_TIMEOUT*HZ; |
| 304 | + while (atomic_read((atomic_t *)&tboot->num_in_wfs) != num_aps && |
| 305 | + timeout) { |
| 306 | + mdelay(1); |
| 307 | + timeout--; |
| 308 | + } |
| 309 | + |
| 310 | + if (timeout) |
| 311 | + pr_warning("tboot wait for APs timeout\n"); |
| 312 | + |
| 313 | + return !(atomic_read((atomic_t *)&tboot->num_in_wfs) == num_aps); |
| 314 | +} |
| 315 | + |
| 316 | +static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb, |
| 317 | + unsigned long action, void *hcpu) |
| 318 | +{ |
| 319 | + switch (action) { |
| 320 | + case CPU_DYING: |
| 321 | + atomic_inc(&ap_wfs_count); |
| 322 | + if (num_online_cpus() == 1) |
| 323 | + if (tboot_wait_for_aps(atomic_read(&ap_wfs_count))) |
| 324 | + return NOTIFY_BAD; |
| 325 | + break; |
| 326 | + } |
| 327 | + return NOTIFY_OK; |
| 328 | +} |
| 329 | + |
| 330 | +static struct notifier_block tboot_cpu_notifier __cpuinitdata = |
| 331 | +{ |
| 332 | + .notifier_call = tboot_cpu_callback, |
| 333 | +}; |
| 334 | + |
| 335 | +static __init int tboot_late_init(void) |
| 336 | +{ |
302 | 337 | if (!tboot_enabled()) |
303 | 338 | return 0; |
304 | 339 |
|
305 | | - timeout = jiffies + AP_WAIT_TIMEOUT*HZ; |
306 | | - while (atomic_read((atomic_t *)&tboot->num_in_wfs) != num_aps && |
307 | | - time_before(jiffies, timeout)) |
308 | | - cpu_relax(); |
| 340 | + tboot_create_trampoline(); |
309 | 341 |
|
310 | | - return time_before(jiffies, timeout) ? 0 : 1; |
| 342 | + atomic_set(&ap_wfs_count, 0); |
| 343 | + register_hotcpu_notifier(&tboot_cpu_notifier); |
| 344 | + return 0; |
311 | 345 | } |
312 | 346 |
|
| 347 | +late_initcall(tboot_late_init); |
| 348 | + |
313 | 349 | /* |
314 | 350 | * TXT configuration registers (offsets from TXT_{PUB, PRIV}_CONFIG_REGS_BASE) |
315 | 351 | */ |
|
0 commit comments