http://downloads.netgear.com/files/GPL/DM111PSP_v3.61d_GPL.tar.gz
[bcm963xx.git] / kernel / linux / arch / s390 / kernel / smp.c
1 /*
2  *  arch/s390/kernel/smp.c
3  *
4  *  S390 version
5  *    Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
6  *    Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
7  *               Martin Schwidefsky (schwidefsky@de.ibm.com)
8  *               Heiko Carstens (heiko.carstens@de.ibm.com)
9  *
10  *  based on other smp stuff by 
11  *    (c) 1995 Alan Cox, CymruNET Ltd  <alan@cymru.net>
12  *    (c) 1998 Ingo Molnar
13  *
14  * We work with logical cpu numbering everywhere we can. The only
15  * functions using the real cpu address (got from STAP) are the sigp
16  * functions. For all other functions we use the identity mapping.
17  * That means that cpu_number_map[i] == i for every cpu. cpu_number_map is
18  * used e.g. to find the idle task belonging to a logical cpu. Every array
19  * in the kernel is sorted by the logical cpu number and not by the physical
20  * one which is causing all the confusion with __cpu_logical_map and
21  * cpu_number_map in other architectures.
22  */
23
24 #include <linux/module.h>
25 #include <linux/init.h>
26
27 #include <linux/mm.h>
28 #include <linux/spinlock.h>
29 #include <linux/kernel_stat.h>
30 #include <linux/smp_lock.h>
31
32 #include <linux/delay.h>
33 #include <linux/cache.h>
34 #include <linux/interrupt.h>
35 #include <linux/cpu.h>
36
37 #include <asm/sigp.h>
38 #include <asm/pgalloc.h>
39 #include <asm/irq.h>
40 #include <asm/s390_ext.h>
41 #include <asm/cpcmd.h>
42 #include <asm/tlbflush.h>
43
44 /* prototypes */
45 extern int cpu_idle(void * unused);
46
47 extern volatile int __cpu_logical_map[];
48
49 /*
50  * An array with a pointer the lowcore of every CPU.
51  */
52
53 struct _lowcore *lowcore_ptr[NR_CPUS];
54 cycles_t         cacheflush_time=0;
55 int              smp_threads_ready=0;      /* Set when the idlers are all forked. */
56
57 cpumask_t cpu_online_map;
58 cpumask_t cpu_possible_map;
59 unsigned long    cache_decay_ticks = 0;
60
61 static struct task_struct *current_set[NR_CPUS];
62
63 EXPORT_SYMBOL(cpu_online_map);
64
65 /*
66  * Reboot, halt and power_off routines for SMP.
67  */
68 extern char vmhalt_cmd[];
69 extern char vmpoff_cmd[];
70
71 extern void reipl(unsigned long devno);
72
73 static void smp_ext_bitcall(int, ec_bit_sig);
74 static void smp_ext_bitcall_others(ec_bit_sig);
75
76 /*
77  * Structure and data for smp_call_function(). This is designed to minimise
78  * static memory requirements. It also looks cleaner.
79  */
80 static spinlock_t call_lock = SPIN_LOCK_UNLOCKED;
81
82 struct call_data_struct {
83         void (*func) (void *info);
84         void *info;
85         atomic_t started;
86         atomic_t finished;
87         int wait;
88 };
89
90 static struct call_data_struct * call_data;
91
92 /*
93  * 'Call function' interrupt callback
94  */
95 static void do_call_function(void)
96 {
97         void (*func) (void *info) = call_data->func;
98         void *info = call_data->info;
99         int wait = call_data->wait;
100
101         atomic_inc(&call_data->started);
102         (*func)(info);
103         if (wait)
104                 atomic_inc(&call_data->finished);
105 }
106
107 /*
108  * this function sends a 'generic call function' IPI to all other CPUs
109  * in the system.
110  */
111
112 int smp_call_function (void (*func) (void *info), void *info, int nonatomic,
113                         int wait)
114 /*
115  * [SUMMARY] Run a function on all other CPUs.
116  * <func> The function to run. This must be fast and non-blocking.
117  * <info> An arbitrary pointer to pass to the function.
118  * <nonatomic> currently unused.
119  * <wait> If true, wait (atomically) until function has completed on other CPUs.
120  * [RETURNS] 0 on success, else a negative status code. Does not return until
121  * remote CPUs are nearly ready to execute <<func>> or are or have executed.
122  *
123  * You must not call this function with disabled interrupts or from a
124  * hardware interrupt handler or from a bottom half handler.
125  */
126 {
127         struct call_data_struct data;
128         int cpus = num_online_cpus()-1;
129
130         if (cpus <= 0)
131                 return 0;
132
133         /* Can deadlock when called with interrupts disabled */
134         WARN_ON(irqs_disabled());
135
136         data.func = func;
137         data.info = info;
138         atomic_set(&data.started, 0);
139         data.wait = wait;
140         if (wait)
141                 atomic_set(&data.finished, 0);
142
143         spin_lock(&call_lock);
144         call_data = &data;
145         /* Send a message to all other CPUs and wait for them to respond */
146         smp_ext_bitcall_others(ec_call_function);
147
148         /* Wait for response */
149         while (atomic_read(&data.started) != cpus)
150                 cpu_relax();
151
152         if (wait)
153                 while (atomic_read(&data.finished) != cpus)
154                         cpu_relax();
155         spin_unlock(&call_lock);
156
157         return 0;
158 }
159
160 /*
161  * Call a function on one CPU
162  * cpu : the CPU the function should be executed on
163  *
164  * You must not call this function with disabled interrupts or from a
165  * hardware interrupt handler. You may call it from a bottom half.
166  *
167  * It is guaranteed that the called function runs on the specified CPU,
168  * preemption is disabled.
169  */
170 int smp_call_function_on(void (*func) (void *info), void *info,
171                          int nonatomic, int wait, int cpu)
172 {
173         struct call_data_struct data;
174         int curr_cpu;
175
176         if (!cpu_online(cpu))
177                 return -EINVAL;
178
179         /* disable preemption for local function call */
180         curr_cpu = get_cpu();
181
182         if (curr_cpu == cpu) {
183                 /* direct call to function */
184                 func(info);
185                 put_cpu();
186                 return 0;
187         }
188
189         data.func = func;
190         data.info = info;
191         atomic_set(&data.started, 0);
192         data.wait = wait;
193         if (wait)
194                 atomic_set(&data.finished, 0);
195
196         spin_lock_bh(&call_lock);
197         call_data = &data;
198         smp_ext_bitcall(cpu, ec_call_function);
199
200         /* Wait for response */
201         while (atomic_read(&data.started) != 1)
202                 cpu_relax();
203
204         if (wait)
205                 while (atomic_read(&data.finished) != 1)
206                         cpu_relax();
207
208         spin_unlock_bh(&call_lock);
209         put_cpu();
210         return 0;
211 }
212 EXPORT_SYMBOL(smp_call_function_on);
213
214 static inline void do_send_stop(void)
215 {
216         int i, rc;
217
218         /* stop all processors */
219         for (i =  0; i < NR_CPUS; i++) {
220                 if (!cpu_online(i) || smp_processor_id() == i)
221                         continue;
222                 do {
223                         rc = signal_processor(i, sigp_stop);
224                 } while (rc == sigp_busy);
225         }
226 }
227
228 static inline void do_store_status(void)
229 {
230         int i, rc;
231
232         /* store status of all processors in their lowcores (real 0) */
233         for (i =  0; i < NR_CPUS; i++) {
234                 if (!cpu_online(i) || smp_processor_id() == i) 
235                         continue;
236                 do {
237                         rc = signal_processor_p(
238                                 (__u32)(unsigned long) lowcore_ptr[i], i,
239                                 sigp_store_status_at_address);
240                 } while(rc == sigp_busy);
241         }
242 }
243
244 /*
245  * this function sends a 'stop' sigp to all other CPUs in the system.
246  * it goes straight through.
247  */
248 void smp_send_stop(void)
249 {
250         /* write magic number to zero page (absolute 0) */
251         lowcore_ptr[smp_processor_id()]->panic_magic = __PANIC_MAGIC;
252
253         /* stop other processors. */
254         do_send_stop();
255
256         /* store status of other processors. */
257         do_store_status();
258 }
259
260 /*
261  * Reboot, halt and power_off routines for SMP.
262  */
263 static cpumask_t cpu_restart_map;
264
265 static void do_machine_restart(void * __unused)
266 {
267         static atomic_t cpuid = ATOMIC_INIT(-1);
268
269         cpu_clear(smp_processor_id(), cpu_restart_map);
270         if (atomic_compare_and_swap(-1, smp_processor_id(), &cpuid) == 0) {
271                 /* Wait for all other cpus to enter do_machine_restart. */
272                 while (!cpus_empty(cpu_restart_map))
273                         cpu_relax();
274                 /* Store status of other cpus. */
275                 do_store_status();
276                 /*
277                  * Finally call reipl. Because we waited for all other
278                  * cpus to enter this function we know that they do
279                  * not hold any s390irq-locks (the cpus have been
280                  * interrupted by an external interrupt and s390irq
281                  * locks are always held disabled).
282                  */
283                 if (MACHINE_IS_VM)
284                         cpcmd ("IPL", NULL, 0);
285                 else
286                         reipl (0x10000 | S390_lowcore.ipl_device);
287         }
288         signal_processor(smp_processor_id(), sigp_stop);
289 }
290
291 void machine_restart_smp(char * __unused) 
292 {
293         cpu_restart_map = cpu_online_map;
294         on_each_cpu(do_machine_restart, NULL, 0, 0);
295 }
296
297 static void do_wait_for_stop(void)
298 {
299         unsigned long cr[16];
300
301         __ctl_store(cr, 0, 15);
302         cr[0] &= ~0xffff;
303         cr[6] = 0;
304         __ctl_load(cr, 0, 15);
305         for (;;)
306                 enabled_wait();
307 }
308
309 static void do_machine_halt(void * __unused)
310 {
311         static atomic_t cpuid = ATOMIC_INIT(-1);
312
313         if (atomic_compare_and_swap(-1, smp_processor_id(), &cpuid) == 0) {
314                 smp_send_stop();
315                 if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0)
316                         cpcmd(vmhalt_cmd, NULL, 0);
317                 signal_processor(smp_processor_id(),
318                                  sigp_stop_and_store_status);
319         }
320         do_wait_for_stop();
321 }
322
323 void machine_halt_smp(void)
324 {
325         on_each_cpu(do_machine_halt, NULL, 0, 0);
326 }
327
328 static void do_machine_power_off(void * __unused)
329 {
330         static atomic_t cpuid = ATOMIC_INIT(-1);
331
332         if (atomic_compare_and_swap(-1, smp_processor_id(), &cpuid) == 0) {
333                 smp_send_stop();
334                 if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0)
335                         cpcmd(vmpoff_cmd, NULL, 0);
336                 signal_processor(smp_processor_id(),
337                                  sigp_stop_and_store_status);
338         }
339         do_wait_for_stop();
340 }
341
342 void machine_power_off_smp(void)
343 {
344         on_each_cpu(do_machine_power_off, NULL, 0, 0);
345 }
346
347 /*
348  * This is the main routine where commands issued by other
349  * cpus are handled.
350  */
351
352 void do_ext_call_interrupt(struct pt_regs *regs, __u16 code)
353 {
354         unsigned long bits;
355
356         /*
357          * handle bit signal external calls
358          *
359          * For the ec_schedule signal we have to do nothing. All the work
360          * is done automatically when we return from the interrupt.
361          */
362         bits = xchg(&S390_lowcore.ext_call_fast, 0);
363
364         if (test_bit(ec_call_function, &bits)) 
365                 do_call_function();
366 }
367
368 /*
369  * Send an external call sigp to another cpu and return without waiting
370  * for its completion.
371  */
372 static void smp_ext_bitcall(int cpu, ec_bit_sig sig)
373 {
374         /*
375          * Set signaling bit in lowcore of target cpu and kick it
376          */
377         set_bit(sig, (unsigned long *) &lowcore_ptr[cpu]->ext_call_fast);
378         while(signal_processor(cpu, sigp_external_call) == sigp_busy)
379                 udelay(10);
380 }
381
382 /*
383  * Send an external call sigp to every other cpu in the system and
384  * return without waiting for its completion.
385  */
386 static void smp_ext_bitcall_others(ec_bit_sig sig)
387 {
388         int i;
389
390         for (i = 0; i < NR_CPUS; i++) {
391                 if (!cpu_online(i) || smp_processor_id() == i)
392                         continue;
393                 /*
394                  * Set signaling bit in lowcore of target cpu and kick it
395                  */
396                 set_bit(sig, (unsigned long *) &lowcore_ptr[i]->ext_call_fast);
397                 while (signal_processor(i, sigp_external_call) == sigp_busy)
398                         udelay(10);
399         }
400 }
401
402 #ifndef CONFIG_ARCH_S390X
403 /*
404  * this function sends a 'purge tlb' signal to another CPU.
405  */
406 void smp_ptlb_callback(void *info)
407 {
408         local_flush_tlb();
409 }
410
411 void smp_ptlb_all(void)
412 {
413         on_each_cpu(smp_ptlb_callback, NULL, 0, 1);
414 }
415 EXPORT_SYMBOL(smp_ptlb_all);
416 #endif /* ! CONFIG_ARCH_S390X */
417
418 /*
419  * this function sends a 'reschedule' IPI to another CPU.
420  * it goes straight through and wastes no time serializing
421  * anything. Worst case is that we lose a reschedule ...
422  */
423 void smp_send_reschedule(int cpu)
424 {
425         smp_ext_bitcall(cpu, ec_schedule);
426 }
427
428 /*
429  * parameter area for the set/clear control bit callbacks
430  */
431 typedef struct
432 {
433         __u16 start_ctl;
434         __u16 end_ctl;
435         unsigned long orvals[16];
436         unsigned long andvals[16];
437 } ec_creg_mask_parms;
438
439 /*
440  * callback for setting/clearing control bits
441  */
442 void smp_ctl_bit_callback(void *info) {
443         ec_creg_mask_parms *pp;
444         unsigned long cregs[16];
445         int i;
446         
447         pp = (ec_creg_mask_parms *) info;
448         __ctl_store(cregs[pp->start_ctl], pp->start_ctl, pp->end_ctl);
449         for (i = pp->start_ctl; i <= pp->end_ctl; i++)
450                 cregs[i] = (cregs[i] & pp->andvals[i]) | pp->orvals[i];
451         __ctl_load(cregs[pp->start_ctl], pp->start_ctl, pp->end_ctl);
452 }
453
454 /*
455  * Set a bit in a control register of all cpus
456  */
457 void smp_ctl_set_bit(int cr, int bit) {
458         ec_creg_mask_parms parms;
459
460         parms.start_ctl = cr;
461         parms.end_ctl = cr;
462         parms.orvals[cr] = 1 << bit;
463         parms.andvals[cr] = -1L;
464         preempt_disable();
465         smp_call_function(smp_ctl_bit_callback, &parms, 0, 1);
466         __ctl_set_bit(cr, bit);
467         preempt_enable();
468 }
469
470 /*
471  * Clear a bit in a control register of all cpus
472  */
473 void smp_ctl_clear_bit(int cr, int bit) {
474         ec_creg_mask_parms parms;
475
476         parms.start_ctl = cr;
477         parms.end_ctl = cr;
478         parms.orvals[cr] = 0;
479         parms.andvals[cr] = ~(1L << bit);
480         preempt_disable();
481         smp_call_function(smp_ctl_bit_callback, &parms, 0, 1);
482         __ctl_clear_bit(cr, bit);
483         preempt_enable();
484 }
485
486 /*
487  * Lets check how many CPUs we have.
488  */
489
490 #ifdef CONFIG_HOTPLUG_CPU
491
492 void
493 __init smp_check_cpus(unsigned int max_cpus)
494 {
495         int cpu;
496
497         /*
498          * cpu 0 is the boot cpu. See smp_prepare_boot_cpu.
499          */
500         for (cpu = 1; cpu < max_cpus; cpu++)
501                 cpu_set(cpu, cpu_possible_map);
502 }
503
504 #else /* CONFIG_HOTPLUG_CPU */
505
506 void
507 __init smp_check_cpus(unsigned int max_cpus)
508 {
509         int curr_cpu, num_cpus;
510         __u16 boot_cpu_addr;
511
512         boot_cpu_addr = S390_lowcore.cpu_data.cpu_addr;
513         current_thread_info()->cpu = 0;
514         num_cpus = 1;
515         for (curr_cpu = 0;
516              curr_cpu <= 65535 && num_cpus < max_cpus; curr_cpu++) {
517                 if ((__u16) curr_cpu == boot_cpu_addr)
518                         continue;
519                 __cpu_logical_map[num_cpus] = (__u16) curr_cpu;
520                 if (signal_processor(num_cpus, sigp_sense) ==
521                     sigp_not_operational)
522                         continue;
523                 cpu_set(num_cpus, cpu_possible_map);
524                 num_cpus++;
525         }
526         printk("Detected %d CPU's\n",(int) num_cpus);
527         printk("Boot cpu address %2X\n", boot_cpu_addr);
528 }
529
530 #endif /* CONFIG_HOTPLUG_CPU */
531
532 /*
533  *      Activate a secondary processor.
534  */
535 extern void init_cpu_timer(void);
536 extern void init_cpu_vtimer(void);
537 extern int pfault_init(void);
538 extern int pfault_token(void);
539
540 int __devinit start_secondary(void *cpuvoid)
541 {
542         /* Setup the cpu */
543         cpu_init();
544         /* init per CPU timer */
545         init_cpu_timer();
546 #ifdef CONFIG_VIRT_TIMER
547         init_cpu_vtimer();
548 #endif
549 #ifdef CONFIG_PFAULT
550         /* Enable pfault pseudo page faults on this cpu. */
551         pfault_init();
552 #endif
553         /* Mark this cpu as online */
554         cpu_set(smp_processor_id(), cpu_online_map);
555         /* Switch on interrupts */
556         local_irq_enable();
557         /* Print info about this processor */
558         print_cpu_info(&S390_lowcore.cpu_data);
559         /* cpu_idle will call schedule for us */
560         return cpu_idle(NULL);
561 }
562
563 static void __init smp_create_idle(unsigned int cpu)
564 {
565         struct pt_regs regs;
566         struct task_struct *p;
567
568         /*
569          *  don't care about the psw and regs settings since we'll never
570          *  reschedule the forked task.
571          */
572         memset(&regs, 0, sizeof(struct pt_regs));
573         p = copy_process(CLONE_VM | CLONE_IDLETASK, 0, &regs, 0, NULL, NULL);
574         if (IS_ERR(p))
575                 panic("failed fork for CPU %u: %li", cpu, PTR_ERR(p));
576
577         wake_up_forked_process(p);
578         init_idle(p, cpu);
579         unhash_process(p);
580         current_set[cpu] = p;
581 }
582
583 /* Reserving and releasing of CPUs */
584
585 static spinlock_t smp_reserve_lock = SPIN_LOCK_UNLOCKED;
586 static int smp_cpu_reserved[NR_CPUS];
587
588 int
589 smp_get_cpu(cpumask_t cpu_mask)
590 {
591         unsigned long flags;
592         int cpu;
593
594         spin_lock_irqsave(&smp_reserve_lock, flags);
595         /* Try to find an already reserved cpu. */
596         for_each_cpu_mask(cpu, cpu_mask) {
597                 if (smp_cpu_reserved[cpu] != 0) {
598                         smp_cpu_reserved[cpu]++;
599                         /* Found one. */
600                         goto out;
601                 }
602         }
603         /* Reserve a new cpu from cpu_mask. */
604         for_each_cpu_mask(cpu, cpu_mask) {
605                 if (cpu_online(cpu)) {
606                         smp_cpu_reserved[cpu]++;
607                         goto out;
608                 }
609         }
610         cpu = -ENODEV;
611 out:
612         spin_unlock_irqrestore(&smp_reserve_lock, flags);
613         return cpu;
614 }
615
616 void
617 smp_put_cpu(int cpu)
618 {
619         unsigned long flags;
620
621         spin_lock_irqsave(&smp_reserve_lock, flags);
622         smp_cpu_reserved[cpu]--;
623         spin_unlock_irqrestore(&smp_reserve_lock, flags);
624 }
625
626 static inline int
627 cpu_stopped(int cpu)
628 {
629         __u32 status;
630
631         /* Check for stopped state */
632         if (signal_processor_ps(&status, 0, cpu, sigp_sense) == sigp_status_stored) {
633                 if (status & 0x40)
634                         return 1;
635         }
636         return 0;
637 }
638
639 /* Upping and downing of CPUs */
640
641 int
642 __cpu_up(unsigned int cpu)
643 {
644         struct task_struct *idle;
645         struct _lowcore    *cpu_lowcore;
646         sigp_ccode          ccode;
647         int                 curr_cpu;
648
649         for (curr_cpu = 0; curr_cpu <= 65535; curr_cpu++) {
650                 __cpu_logical_map[cpu] = (__u16) curr_cpu;
651                 if (cpu_stopped(cpu))
652                         break;
653         }
654
655         if (!cpu_stopped(cpu))
656                 return -ENODEV;
657
658         ccode = signal_processor_p((__u32)(unsigned long)(lowcore_ptr[cpu]),
659                                    cpu, sigp_set_prefix);
660         if (ccode){
661                 printk("sigp_set_prefix failed for cpu %d "
662                        "with condition code %d\n",
663                        (int) cpu, (int) ccode);
664                 return -EIO;
665         }
666
667         idle = current_set[cpu];
668         cpu_lowcore = lowcore_ptr[cpu];
669         cpu_lowcore->save_area[15] = idle->thread.ksp;
670         cpu_lowcore->kernel_stack = (unsigned long)
671                 idle->thread_info + (THREAD_SIZE);
672         __ctl_store(cpu_lowcore->cregs_save_area[0], 0, 15);
673         __asm__ __volatile__("stam  0,15,0(%0)"
674                              : : "a" (&cpu_lowcore->access_regs_save_area)
675                              : "memory");
676         cpu_lowcore->percpu_offset = __per_cpu_offset[cpu];
677         cpu_lowcore->current_task = (unsigned long) idle;
678         cpu_lowcore->cpu_data.cpu_nr = cpu;
679         eieio();
680         signal_processor(cpu,sigp_restart);
681
682         while (!cpu_online(cpu));
683         return 0;
684 }
685
686 int
687 __cpu_disable(void)
688 {
689         unsigned long flags;
690         ec_creg_mask_parms cr_parms;
691
692         spin_lock_irqsave(&smp_reserve_lock, flags);
693         if (smp_cpu_reserved[smp_processor_id()] != 0) {
694                 spin_unlock_irqrestore(&smp_reserve_lock, flags);
695                 return -EBUSY;
696         }
697
698         /* disable all external interrupts */
699
700         cr_parms.start_ctl = 0;
701         cr_parms.end_ctl = 0;
702         cr_parms.orvals[0] = 0;
703         cr_parms.andvals[0] = ~(1<<15 | 1<<14 | 1<<13 | 1<<12 |
704                                 1<<11 | 1<<10 | 1<< 6 | 1<< 4);
705         smp_ctl_bit_callback(&cr_parms);
706
707         /* disable all I/O interrupts */
708
709         cr_parms.start_ctl = 6;
710         cr_parms.end_ctl = 6;
711         cr_parms.orvals[6] = 0;
712         cr_parms.andvals[6] = ~(1<<31 | 1<<30 | 1<<29 | 1<<28 |
713                                 1<<27 | 1<<26 | 1<<25 | 1<<24);
714         smp_ctl_bit_callback(&cr_parms);
715
716         /* disable most machine checks */
717
718         cr_parms.start_ctl = 14;
719         cr_parms.end_ctl = 14;
720         cr_parms.orvals[14] = 0;
721         cr_parms.andvals[14] = ~(1<<28 | 1<<27 | 1<<26 | 1<<25 | 1<<24);
722         smp_ctl_bit_callback(&cr_parms);
723
724         spin_unlock_irqrestore(&smp_reserve_lock, flags);
725         return 0;
726 }
727
728 void
729 __cpu_die(unsigned int cpu)
730 {
731         /* Wait until target cpu is down */
732         while (!cpu_stopped(cpu));
733         printk("Processor %d spun down\n", cpu);
734 }
735
736 void
737 cpu_die(void)
738 {
739         signal_processor(smp_processor_id(), sigp_stop);
740         BUG();
741         for(;;);
742 }
743
744 /*
745  *      Cycle through the processors and setup structures.
746  */
747
748 void __init smp_prepare_cpus(unsigned int max_cpus)
749 {
750         unsigned long async_stack;
751         unsigned int cpu;
752         int i;
753
754         /* request the 0x1202 external interrupt */
755         if (register_external_interrupt(0x1202, do_ext_call_interrupt) != 0)
756                 panic("Couldn't request external interrupt 0x1202");
757         smp_check_cpus(max_cpus);
758         memset(lowcore_ptr,0,sizeof(lowcore_ptr));  
759         /*
760          *  Initialize prefix pages and stacks for all possible cpus
761          */
762         print_cpu_info(&S390_lowcore.cpu_data);
763
764         for(i = 0; i < NR_CPUS; i++) {
765                 if (!cpu_possible(i))
766                         continue;
767                 lowcore_ptr[i] = (struct _lowcore *)
768                         __get_free_pages(GFP_KERNEL|GFP_DMA, 
769                                         sizeof(void*) == 8 ? 1 : 0);
770                 async_stack = __get_free_pages(GFP_KERNEL,ASYNC_ORDER);
771                 if (lowcore_ptr[i] == NULL || async_stack == 0ULL)
772                         panic("smp_boot_cpus failed to allocate memory\n");
773
774                 *(lowcore_ptr[i]) = S390_lowcore;
775                 lowcore_ptr[i]->async_stack = async_stack + (ASYNC_SIZE);
776         }
777         set_prefix((u32)(unsigned long) lowcore_ptr[smp_processor_id()]);
778
779         for_each_cpu(cpu)
780                 if (cpu != smp_processor_id())
781                         smp_create_idle(cpu);
782 }
783
784 void __devinit smp_prepare_boot_cpu(void)
785 {
786         BUG_ON(smp_processor_id() != 0);
787
788         cpu_set(0, cpu_online_map);
789         cpu_set(0, cpu_possible_map);
790         S390_lowcore.percpu_offset = __per_cpu_offset[0];
791         current_set[0] = current;
792 }
793
794 void smp_cpus_done(unsigned int max_cpus)
795 {
796 }
797
798 /*
799  * the frequency of the profiling timer can be changed
800  * by writing a multiplier value into /proc/profile.
801  *
802  * usually you want to run this on all CPUs ;)
803  */
804 int setup_profiling_timer(unsigned int multiplier)
805 {
806         return 0;
807 }
808
809 static DEFINE_PER_CPU(struct cpu, cpu_devices);
810
811 static int __init topology_init(void)
812 {
813         int cpu;
814         int ret;
815
816         for_each_cpu(cpu) {
817                 ret = register_cpu(&per_cpu(cpu_devices, cpu), cpu, NULL);
818                 if (ret)
819                         printk(KERN_WARNING "topology_init: register_cpu %d "
820                                "failed (%d)\n", cpu, ret);
821         }
822         return 0;
823 }
824
825 subsys_initcall(topology_init);
826
827 EXPORT_SYMBOL(cpu_possible_map);
828 EXPORT_SYMBOL(lowcore_ptr);
829 EXPORT_SYMBOL(smp_ctl_set_bit);
830 EXPORT_SYMBOL(smp_ctl_clear_bit);
831 EXPORT_SYMBOL(smp_call_function);
832 EXPORT_SYMBOL(smp_get_cpu);
833 EXPORT_SYMBOL(smp_put_cpu);
834