blob: 911fc62b822546d0e1b05dddb0c2d8bdc771c056 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/power/smp.c - Functions for stopping other CPUs.
3 *
4 * Copyright 2004 Pavel Machek <pavel@suse.cz>
5 * Copyright (C) 2002-2003 Nigel Cunningham <ncunningham@clear.net.nz>
6 *
7 * This file is released under the GPLv2.
8 */
9
10#undef DEBUG
11
12#include <linux/smp_lock.h>
13#include <linux/interrupt.h>
14#include <linux/suspend.h>
15#include <linux/module.h>
Li Shaohua5a72e042005-06-25 14:55:06 -070016#include <linux/cpu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/atomic.h>
18#include <asm/tlbflush.h>
19
Li Shaohua5a72e042005-06-25 14:55:06 -070020/* This is protected by pm_sem semaphore */
21static cpumask_t frozen_cpus;
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23void disable_nonboot_cpus(void)
24{
Li Shaohua5a72e042005-06-25 14:55:06 -070025 int cpu, error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Li Shaohua5a72e042005-06-25 14:55:06 -070027 error = 0;
28 cpus_clear(frozen_cpus);
29 printk("Freezing cpus ...\n");
30 for_each_online_cpu(cpu) {
31 if (cpu == 0)
32 continue;
33 error = cpu_down(cpu);
34 if (!error) {
35 cpu_set(cpu, frozen_cpus);
36 printk("CPU%d is down\n", cpu);
37 continue;
38 }
39 printk("Error taking cpu %d down: %d\n", cpu, error);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 }
Nigel Cunninghambba0e462005-07-27 11:43:41 -070041 BUG_ON(raw_smp_processor_id() != 0);
Li Shaohua5a72e042005-06-25 14:55:06 -070042 if (error)
43 panic("cpus not sleeping");
Linus Torvalds1da177e2005-04-16 15:20:36 -070044}
45
46void enable_nonboot_cpus(void)
47{
Li Shaohua5a72e042005-06-25 14:55:06 -070048 int cpu, error;
49
50 printk("Thawing cpus ...\n");
51 for_each_cpu_mask(cpu, frozen_cpus) {
52 error = smp_prepare_cpu(cpu);
53 if (!error)
54 error = cpu_up(cpu);
55 if (!error) {
56 printk("CPU%d is up\n", cpu);
57 continue;
58 }
59 printk("Error taking cpu %d up: %d\n", cpu, error);
60 panic("Not enough cpus");
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 }
Li Shaohua5a72e042005-06-25 14:55:06 -070062 cpus_clear(frozen_cpus);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}
64