smp.c 1.3 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * drivers/power/smp.c - Functions for stopping other CPUs.
 *
 * Copyright 2004 Pavel Machek <pavel@suse.cz>
 * Copyright (C) 2002-2003 Nigel Cunningham <ncunningham@clear.net.nz>
 *
 * This file is released under the GPLv2.
 */

#undef DEBUG

#include <linux/smp_lock.h>
#include <linux/interrupt.h>
#include <linux/suspend.h>
#include <linux/module.h>
L
Li Shaohua 已提交
16
#include <linux/cpu.h>
L
Linus Torvalds 已提交
17 18 19
#include <asm/atomic.h>
#include <asm/tlbflush.h>

L
Li Shaohua 已提交
20 21
/* This is protected by pm_sem semaphore */
static cpumask_t frozen_cpus;
L
Linus Torvalds 已提交
22 23 24

void disable_nonboot_cpus(void)
{
L
Li Shaohua 已提交
25
	int cpu, error;
L
Linus Torvalds 已提交
26

L
Li Shaohua 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39
	error = 0;
	cpus_clear(frozen_cpus);
	printk("Freezing cpus ...\n");
	for_each_online_cpu(cpu) {
		if (cpu == 0)
			continue;
		error = cpu_down(cpu);
		if (!error) {
			cpu_set(cpu, frozen_cpus);
			printk("CPU%d is down\n", cpu);
			continue;
		}
		printk("Error taking cpu %d down: %d\n", cpu, error);
L
Linus Torvalds 已提交
40
	}
L
Li Shaohua 已提交
41 42 43
	BUG_ON(smp_processor_id() != 0);
	if (error)
		panic("cpus not sleeping");
L
Linus Torvalds 已提交
44 45 46 47
}

void enable_nonboot_cpus(void)
{
L
Li Shaohua 已提交
48
	int cpu, error;
L
Linus Torvalds 已提交
49

L
Li Shaohua 已提交
50 51 52 53 54 55 56 57 58 59 60 61 62
	printk("Thawing cpus ...\n");
	for_each_cpu_mask(cpu, frozen_cpus) {
		error = smp_prepare_cpu(cpu);
		if (!error)
			error = cpu_up(cpu);
		if (!error) {
			printk("CPU%d is up\n", cpu);
			continue;
		}
		printk("Error taking cpu %d up: %d\n", cpu, error);
		panic("Not enough cpus");
	}
	cpus_clear(frozen_cpus);
L
Linus Torvalds 已提交
63 64
}