Remove all inclusions of <linux/config.h>
[wandboard.git] / arch / um / kernel / smp.c
blob759b07053160736a1b0ce8e4220ec3c054197689
1 /*
2 * Copyright (C) 2000 - 2003 Jeff Dike (jdike@addtoit.com)
3 * Licensed under the GPL
4 */
6 #include "linux/percpu.h"
7 #include "asm/pgalloc.h"
8 #include "asm/tlb.h"
10 /* For some reason, mmu_gathers are referenced when CONFIG_SMP is off. */
11 DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
13 #ifdef CONFIG_SMP
15 #include "linux/sched.h"
16 #include "linux/module.h"
17 #include "linux/threads.h"
18 #include "linux/interrupt.h"
19 #include "linux/err.h"
20 #include "linux/hardirq.h"
21 #include "asm/smp.h"
22 #include "asm/processor.h"
23 #include "asm/spinlock.h"
24 #include "user_util.h"
25 #include "kern_util.h"
26 #include "kern.h"
27 #include "irq_user.h"
28 #include "os.h"
30 /* CPU online map, set by smp_boot_cpus */
31 cpumask_t cpu_online_map = CPU_MASK_NONE;
32 cpumask_t cpu_possible_map = CPU_MASK_NONE;
34 EXPORT_SYMBOL(cpu_online_map);
35 EXPORT_SYMBOL(cpu_possible_map);
37 /* Per CPU bogomips and other parameters
38 * The only piece used here is the ipi pipe, which is set before SMP is
39 * started and never changed.
41 struct cpuinfo_um cpu_data[NR_CPUS];
43 /* A statistic, can be a little off */
44 int num_reschedules_sent = 0;
46 /* Not changed after boot */
47 struct task_struct *idle_threads[NR_CPUS];
49 void smp_send_reschedule(int cpu)
51 os_write_file(cpu_data[cpu].ipi_pipe[1], "R", 1);
52 num_reschedules_sent++;
55 void smp_send_stop(void)
57 int i;
59 printk(KERN_INFO "Stopping all CPUs...");
60 for(i = 0; i < num_online_cpus(); i++){
61 if(i == current_thread->cpu)
62 continue;
63 os_write_file(cpu_data[i].ipi_pipe[1], "S", 1);
65 printk("done\n");
68 static cpumask_t smp_commenced_mask = CPU_MASK_NONE;
69 static cpumask_t cpu_callin_map = CPU_MASK_NONE;
71 static int idle_proc(void *cpup)
73 int cpu = (int) cpup, err;
75 err = os_pipe(cpu_data[cpu].ipi_pipe, 1, 1);
76 if(err < 0)
77 panic("CPU#%d failed to create IPI pipe, err = %d", cpu, -err);
79 os_set_fd_async(cpu_data[cpu].ipi_pipe[0],
80 current->thread.mode.tt.extern_pid);
82 wmb();
83 if (cpu_test_and_set(cpu, cpu_callin_map)) {
84 printk("huh, CPU#%d already present??\n", cpu);
85 BUG();
88 while (!cpu_isset(cpu, smp_commenced_mask))
89 cpu_relax();
91 cpu_set(cpu, cpu_online_map);
92 default_idle();
93 return(0);
96 static struct task_struct *idle_thread(int cpu)
98 struct task_struct *new_task;
99 unsigned char c;
101 current->thread.request.u.thread.proc = idle_proc;
102 current->thread.request.u.thread.arg = (void *) cpu;
103 new_task = fork_idle(cpu);
104 if(IS_ERR(new_task))
105 panic("copy_process failed in idle_thread, error = %ld",
106 PTR_ERR(new_task));
108 cpu_tasks[cpu] = ((struct cpu_task)
109 { .pid = new_task->thread.mode.tt.extern_pid,
110 .task = new_task } );
111 idle_threads[cpu] = new_task;
112 CHOOSE_MODE(os_write_file(new_task->thread.mode.tt.switch_pipe[1], &c,
113 sizeof(c)),
114 ({ panic("skas mode doesn't support SMP"); }));
115 return(new_task);
118 void smp_prepare_cpus(unsigned int maxcpus)
120 struct task_struct *idle;
121 unsigned long waittime;
122 int err, cpu, me = smp_processor_id();
123 int i;
125 for (i = 0; i < ncpus; ++i)
126 cpu_set(i, cpu_possible_map);
128 cpu_clear(me, cpu_online_map);
129 cpu_set(me, cpu_online_map);
130 cpu_set(me, cpu_callin_map);
132 err = os_pipe(cpu_data[me].ipi_pipe, 1, 1);
133 if(err < 0)
134 panic("CPU#0 failed to create IPI pipe, errno = %d", -err);
136 os_set_fd_async(cpu_data[me].ipi_pipe[0],
137 current->thread.mode.tt.extern_pid);
139 for(cpu = 1; cpu < ncpus; cpu++){
140 printk("Booting processor %d...\n", cpu);
142 idle = idle_thread(cpu);
144 init_idle(idle, cpu);
146 waittime = 200000000;
147 while (waittime-- && !cpu_isset(cpu, cpu_callin_map))
148 cpu_relax();
150 if (cpu_isset(cpu, cpu_callin_map))
151 printk("done\n");
152 else printk("failed\n");
156 void smp_prepare_boot_cpu(void)
158 cpu_set(smp_processor_id(), cpu_online_map);
161 int __cpu_up(unsigned int cpu)
163 cpu_set(cpu, smp_commenced_mask);
164 while (!cpu_isset(cpu, cpu_online_map))
165 mb();
166 return(0);
169 int setup_profiling_timer(unsigned int multiplier)
171 printk(KERN_INFO "setup_profiling_timer\n");
172 return(0);
175 void smp_call_function_slave(int cpu);
177 void IPI_handler(int cpu)
179 unsigned char c;
180 int fd;
182 fd = cpu_data[cpu].ipi_pipe[0];
183 while (os_read_file(fd, &c, 1) == 1) {
184 switch (c) {
185 case 'C':
186 smp_call_function_slave(cpu);
187 break;
189 case 'R':
190 set_tsk_need_resched(current);
191 break;
193 case 'S':
194 printk("CPU#%d stopping\n", cpu);
195 while(1)
196 pause();
197 break;
199 default:
200 printk("CPU#%d received unknown IPI [%c]!\n", cpu, c);
201 break;
206 int hard_smp_processor_id(void)
208 return(pid_to_processor_id(os_getpid()));
211 static DEFINE_SPINLOCK(call_lock);
212 static atomic_t scf_started;
213 static atomic_t scf_finished;
214 static void (*func)(void *info);
215 static void *info;
217 void smp_call_function_slave(int cpu)
219 atomic_inc(&scf_started);
220 (*func)(info);
221 atomic_inc(&scf_finished);
224 int smp_call_function(void (*_func)(void *info), void *_info, int nonatomic,
225 int wait)
227 int cpus = num_online_cpus() - 1;
228 int i;
230 if (!cpus)
231 return 0;
233 /* Can deadlock when called with interrupts disabled */
234 WARN_ON(irqs_disabled());
236 spin_lock_bh(&call_lock);
237 atomic_set(&scf_started, 0);
238 atomic_set(&scf_finished, 0);
239 func = _func;
240 info = _info;
242 for_each_online_cpu(i)
243 os_write_file(cpu_data[i].ipi_pipe[1], "C", 1);
245 while (atomic_read(&scf_started) != cpus)
246 barrier();
248 if (wait)
249 while (atomic_read(&scf_finished) != cpus)
250 barrier();
252 spin_unlock_bh(&call_lock);
253 return 0;
256 #endif
259 * Overrides for Emacs so that we follow Linus's tabbing style.
260 * Emacs will notice this stuff at the end of the file and automatically
261 * adjust the settings for this buffer only. This must remain at the end
262 * of the file.
263 * ---------------------------------------------------------------------------
264 * Local variables:
265 * c-file-style: "linux"
266 * End: