smp.c 20 KB

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