]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - arch/powerpc/platforms/cell/smp.c
powerpc/64s: Do not allocate lppaca if we are not virtualized
[mirror_ubuntu-jammy-kernel.git] / arch / powerpc / platforms / cell / smp.c
CommitLineData
19fe0475
AB
1/*
2 * SMP support for BPA machines.
3 *
4 * Dave Engebretsen, Peter Bergner, and
5 * Mike Corrigan {engebret|bergner|mikec}@us.ibm.com
6 *
7 * Plus various changes from other IBM teams...
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
13 */
14
15#undef DEBUG
16
19fe0475 17#include <linux/kernel.h>
19fe0475
AB
18#include <linux/sched.h>
19#include <linux/smp.h>
20#include <linux/interrupt.h>
21#include <linux/delay.h>
22#include <linux/init.h>
23#include <linux/spinlock.h>
24#include <linux/cache.h>
25#include <linux/err.h>
edbaa603 26#include <linux/device.h>
19fe0475
AB
27#include <linux/cpu.h>
28
29#include <asm/ptrace.h>
60063497 30#include <linux/atomic.h>
19fe0475
AB
31#include <asm/irq.h>
32#include <asm/page.h>
33#include <asm/pgtable.h>
34#include <asm/io.h>
35#include <asm/prom.h>
36#include <asm/smp.h>
37#include <asm/paca.h>
19fe0475
AB
38#include <asm/machdep.h>
39#include <asm/cputable.h>
40#include <asm/firmware.h>
19fe0475 41#include <asm/rtas.h>
8d089085 42#include <asm/cputhreads.h>
2751b628 43#include <asm/code-patching.h>
19fe0475
AB
44
45#include "interrupt.h"
aa39be09 46#include <asm/udbg.h>
19fe0475
AB
47
48#ifdef DEBUG
49#define DBG(fmt...) udbg_printf(fmt)
50#else
51#define DBG(fmt...)
52#endif
53
54/*
6a75a6b8
MM
55 * The Primary thread of each non-boot processor was started from the OF client
56 * interface by prom_hold_cpus and is spinning on secondary_hold_spinloop.
19fe0475
AB
57 */
58static cpumask_t of_spin_map;
59
19fe0475
AB
60/**
61 * smp_startup_cpu() - start the given cpu
62 *
63 * At boot time, there is nothing to do for primary threads which were
64 * started from Open Firmware. For anything else, call RTAS with the
65 * appropriate start location.
66 *
67 * Returns:
68 * 0 - failure
69 * 1 - success
70 */
cad5cef6 71static inline int smp_startup_cpu(unsigned int lcpu)
19fe0475
AB
72{
73 int status;
2751b628
AB
74 unsigned long start_here =
75 __pa(ppc_function_entry(generic_secondary_smp_init));
19fe0475
AB
76 unsigned int pcpu;
77 int start_cpu;
78
104699c0 79 if (cpumask_test_cpu(lcpu, &of_spin_map))
19fe0475
AB
80 /* Already started by OF and sitting in spin loop */
81 return 1;
82
83 pcpu = get_hard_smp_processor_id(lcpu);
84
85 /* Fixup atomic count: it exited inside IRQ handler. */
b5e2fc1c 86 task_thread_info(paca[lcpu].__current)->preempt_count = 0;
19fe0475
AB
87
88 /*
89 * If the RTAS start-cpu token does not exist then presume the
90 * cpu is already spinning.
91 */
92 start_cpu = rtas_token("start-cpu");
93 if (start_cpu == RTAS_UNKNOWN_SERVICE)
94 return 1;
95
96 status = rtas_call(start_cpu, 3, 1, NULL, pcpu, start_here, lcpu);
97 if (status != 0) {
98 printk(KERN_ERR "start-cpu failed: %i\n", status);
99 return 0;
100 }
101
102 return 1;
103}
104
cad5cef6 105static void smp_cell_setup_cpu(int cpu)
19fe0475
AB
106{
107 if (cpu != boot_cpuid)
108 iic_setup_cpu();
960cedb4
AB
109
110 /*
111 * change default DABRX to allow user watchpoints
112 */
113 mtspr(SPRN_DABRX, DABRX_KERNEL | DABRX_USER);
19fe0475
AB
114}
115
cad5cef6 116static int smp_cell_kick_cpu(int nr)
19fe0475 117{
c642af9c 118 if (nr < 0 || nr >= nr_cpu_ids)
f8d0d5dc 119 return -EINVAL;
19fe0475
AB
120
121 if (!smp_startup_cpu(nr))
de300974 122 return -ENOENT;
19fe0475
AB
123
124 /*
125 * The processor is currently spinning, waiting for the
126 * cpu_start field to become non-zero After we set cpu_start,
127 * the processor will continue on to secondary_start
128 */
129 paca[nr].cpu_start = 1;
de300974
ME
130
131 return 0;
19fe0475
AB
132}
133
19fe0475 134static struct smp_ops_t bpa_iic_smp_ops = {
d5a1c193 135 .message_pass = iic_message_pass,
a7f4ee1f 136 .probe = iic_request_IPIs,
19fe0475 137 .kick_cpu = smp_cell_kick_cpu,
960cedb4 138 .setup_cpu = smp_cell_setup_cpu,
39fd4027 139 .cpu_bootable = smp_generic_cpu_bootable,
19fe0475
AB
140};
141
142/* This is called very early */
143void __init smp_init_cell(void)
144{
145 int i;
146
147 DBG(" -> smp_init_cell()\n");
148
149 smp_ops = &bpa_iic_smp_ops;
150
151 /* Mark threads which are still spinning in hold loops. */
152 if (cpu_has_feature(CPU_FTR_SMT)) {
153 for_each_present_cpu(i) {
6a75a6b8 154 if (cpu_thread_in_core(i) == 0)
104699c0 155 cpumask_set_cpu(i, &of_spin_map);
19fe0475 156 }
104699c0
KM
157 } else
158 cpumask_copy(&of_spin_map, cpu_present_mask);
19fe0475 159
104699c0 160 cpumask_clear_cpu(boot_cpuid, &of_spin_map);
19fe0475
AB
161
162 /* Non-lpar has additional take/give timebase */
163 if (rtas_token("freeze-time-base") != RTAS_UNKNOWN_SERVICE) {
c4007a2f
BH
164 smp_ops->give_timebase = rtas_give_timebase;
165 smp_ops->take_timebase = rtas_take_timebase;
19fe0475
AB
166 }
167
168 DBG(" <- smp_init_cell()\n");
169}