smp.c 3.98 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * SMP support for BPA machines.
 *
 * Dave Engebretsen, Peter Bergner, and
 * Mike Corrigan {engebret|bergner|mikec}@us.ibm.com
 *
 * Plus various changes from other IBM teams...
 *
 *      This program is free software; you can redistribute it and/or
 *      modify it under the terms of the GNU General Public License
 *      as published by the Free Software Foundation; either version
 *      2 of the License, or (at your option) any later version.
 */

#undef DEBUG

#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/smp.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/spinlock.h>
#include <linux/cache.h>
#include <linux/err.h>
26
#include <linux/device.h>
27 28 29
#include <linux/cpu.h>

#include <asm/ptrace.h>
Arun Sharma's avatar
Arun Sharma committed
30
#include <linux/atomic.h>
31 32 33 34 35 36 37 38 39 40 41
#include <asm/irq.h>
#include <asm/page.h>
#include <asm/pgtable.h>
#include <asm/io.h>
#include <asm/prom.h>
#include <asm/smp.h>
#include <asm/paca.h>
#include <asm/machdep.h>
#include <asm/cputable.h>
#include <asm/firmware.h>
#include <asm/rtas.h>
42
#include <asm/cputhreads.h>
43
#include <asm/code-patching.h>
44 45

#include "interrupt.h"
46
#include <asm/udbg.h>
47 48 49 50 51 52 53 54

#ifdef DEBUG
#define DBG(fmt...) udbg_printf(fmt)
#else
#define DBG(fmt...)
#endif

/*
55 56
 * The Primary thread of each non-boot processor was started from the OF client
 * interface by prom_hold_cpus and is spinning on secondary_hold_spinloop.
57 58 59 60 61 62 63 64 65 66 67 68 69 70
 */
static cpumask_t of_spin_map;

/**
 * smp_startup_cpu() - start the given cpu
 *
 * At boot time, there is nothing to do for primary threads which were
 * started from Open Firmware.  For anything else, call RTAS with the
 * appropriate start location.
 *
 * Returns:
 *	0	- failure
 *	1	- success
 */
71
static inline int smp_startup_cpu(unsigned int lcpu)
72 73
{
	int status;
74 75
	unsigned long start_here =
			__pa(ppc_function_entry(generic_secondary_smp_init));
76 77 78
	unsigned int pcpu;
	int start_cpu;

79
	if (cpumask_test_cpu(lcpu, &of_spin_map))
80 81 82 83 84 85
		/* Already started by OF and sitting in spin loop */
		return 1;

	pcpu = get_hard_smp_processor_id(lcpu);

	/* Fixup atomic count: it exited inside IRQ handler. */
86
	task_thread_info(paca[lcpu].__current)->preempt_count	= 0;
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108

	/*
	 * If the RTAS start-cpu token does not exist then presume the
	 * cpu is already spinning.
	 */
	start_cpu = rtas_token("start-cpu");
	if (start_cpu == RTAS_UNKNOWN_SERVICE)
		return 1;

	status = rtas_call(start_cpu, 3, 1, NULL, pcpu, start_here, lcpu);
	if (status != 0) {
		printk(KERN_ERR "start-cpu failed: %i\n", status);
		return 0;
	}

	return 1;
}

static int __init smp_iic_probe(void)
{
	iic_request_IPIs();

109
	return num_possible_cpus();
110 111
}

112
static void smp_cell_setup_cpu(int cpu)
113 114 115
{
	if (cpu != boot_cpuid)
		iic_setup_cpu();
116 117 118 119 120

	/*
	 * change default DABRX to allow user watchpoints
	 */
	mtspr(SPRN_DABRX, DABRX_KERNEL | DABRX_USER);
121 122
}

123
static int smp_cell_kick_cpu(int nr)
124 125 126 127
{
	BUG_ON(nr < 0 || nr >= NR_CPUS);

	if (!smp_startup_cpu(nr))
128
		return -ENOENT;
129 130 131 132 133 134 135

	/*
	 * The processor is currently spinning, waiting for the
	 * cpu_start field to become non-zero After we set cpu_start,
	 * the processor will continue on to secondary_start
	 */
	paca[nr].cpu_start = 1;
136 137

	return 0;
138 139 140
}

static struct smp_ops_t bpa_iic_smp_ops = {
141
	.message_pass	= iic_message_pass,
142 143
	.probe		= smp_iic_probe,
	.kick_cpu	= smp_cell_kick_cpu,
144
	.setup_cpu	= smp_cell_setup_cpu,
145
	.cpu_bootable	= smp_generic_cpu_bootable,
146 147 148 149 150 151 152 153 154 155 156 157 158 159
};

/* This is called very early */
void __init smp_init_cell(void)
{
	int i;

	DBG(" -> smp_init_cell()\n");

	smp_ops = &bpa_iic_smp_ops;

	/* Mark threads which are still spinning in hold loops. */
	if (cpu_has_feature(CPU_FTR_SMT)) {
		for_each_present_cpu(i) {
160
			if (cpu_thread_in_core(i) == 0)
161
				cpumask_set_cpu(i, &of_spin_map);
162
		}
163 164
	} else
		cpumask_copy(&of_spin_map, cpu_present_mask);
165

166
	cpumask_clear_cpu(boot_cpuid, &of_spin_map);
167 168 169

	/* Non-lpar has additional take/give timebase */
	if (rtas_token("freeze-time-base") != RTAS_UNKNOWN_SERVICE) {
170 171
		smp_ops->give_timebase = rtas_give_timebase;
		smp_ops->take_timebase = rtas_take_timebase;
172 173 174 175
	}

	DBG(" <- smp_init_cell()\n");
}