smp.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. /*
  2. * arch/s390/kernel/smp.c
  3. *
  4. * Copyright IBM Corp. 1999,2007
  5. * Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
  6. * Martin Schwidefsky (schwidefsky@de.ibm.com)
  7. * Heiko Carstens (heiko.carstens@de.ibm.com)
  8. *
  9. * based on other smp stuff by
  10. * (c) 1995 Alan Cox, CymruNET Ltd <alan@cymru.net>
  11. * (c) 1998 Ingo Molnar
  12. *
  13. * We work with logical cpu numbering everywhere we can. The only
  14. * functions using the real cpu address (got from STAP) are the sigp
  15. * functions. For all other functions we use the identity mapping.
  16. * That means that cpu_number_map[i] == i for every cpu. cpu_number_map is
  17. * used e.g. to find the idle task belonging to a logical cpu. Every array
  18. * in the kernel is sorted by the logical cpu number and not by the physical
  19. * one which is causing all the confusion with __cpu_logical_map and
  20. * cpu_number_map in other architectures.
  21. */
  22. #include <linux/module.h>
  23. #include <linux/init.h>
  24. #include <linux/mm.h>
  25. #include <linux/spinlock.h>
  26. #include <linux/kernel_stat.h>
  27. #include <linux/delay.h>
  28. #include <linux/cache.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/cpu.h>
  31. #include <linux/timex.h>
  32. #include <linux/bootmem.h>
  33. #include <asm/ipl.h>
  34. #include <asm/setup.h>
  35. #include <asm/sigp.h>
  36. #include <asm/pgalloc.h>
  37. #include <asm/irq.h>
  38. #include <asm/s390_ext.h>
  39. #include <asm/cpcmd.h>
  40. #include <asm/tlbflush.h>
  41. #include <asm/timer.h>
  42. #include <asm/lowcore.h>
  43. /*
  44. * An array with a pointer the lowcore of every CPU.
  45. */
  46. struct _lowcore *lowcore_ptr[NR_CPUS];
  47. EXPORT_SYMBOL(lowcore_ptr);
  48. cpumask_t cpu_online_map = CPU_MASK_NONE;
  49. EXPORT_SYMBOL(cpu_online_map);
  50. cpumask_t cpu_possible_map = CPU_MASK_NONE;
  51. EXPORT_SYMBOL(cpu_possible_map);
  52. static struct task_struct *current_set[NR_CPUS];
  53. static void smp_ext_bitcall(int, ec_bit_sig);
  54. /*
  55. * Structure and data for __smp_call_function_map(). This is designed to
  56. * minimise static memory requirements. It also looks cleaner.
  57. */
  58. static DEFINE_SPINLOCK(call_lock);
  59. struct call_data_struct {
  60. void (*func) (void *info);
  61. void *info;
  62. cpumask_t started;
  63. cpumask_t finished;
  64. int wait;
  65. };
  66. static struct call_data_struct *call_data;
  67. /*
  68. * 'Call function' interrupt callback
  69. */
  70. static void do_call_function(void)
  71. {
  72. void (*func) (void *info) = call_data->func;
  73. void *info = call_data->info;
  74. int wait = call_data->wait;
  75. cpu_set(smp_processor_id(), call_data->started);
  76. (*func)(info);
  77. if (wait)
  78. cpu_set(smp_processor_id(), call_data->finished);;
  79. }
  80. static void __smp_call_function_map(void (*func) (void *info), void *info,
  81. int nonatomic, int wait, cpumask_t map)
  82. {
  83. struct call_data_struct data;
  84. int cpu, local = 0;
  85. /*
  86. * Can deadlock when interrupts are disabled or if in wrong context.
  87. */
  88. WARN_ON(irqs_disabled() || in_irq());
  89. /*
  90. * Check for local function call. We have to have the same call order
  91. * as in on_each_cpu() because of machine_restart_smp().
  92. */
  93. if (cpu_isset(smp_processor_id(), map)) {
  94. local = 1;
  95. cpu_clear(smp_processor_id(), map);
  96. }
  97. cpus_and(map, map, cpu_online_map);
  98. if (cpus_empty(map))
  99. goto out;
  100. data.func = func;
  101. data.info = info;
  102. data.started = CPU_MASK_NONE;
  103. data.wait = wait;
  104. if (wait)
  105. data.finished = CPU_MASK_NONE;
  106. spin_lock_bh(&call_lock);
  107. call_data = &data;
  108. for_each_cpu_mask(cpu, map)
  109. smp_ext_bitcall(cpu, ec_call_function);
  110. /* Wait for response */
  111. while (!cpus_equal(map, data.started))
  112. cpu_relax();
  113. if (wait)
  114. while (!cpus_equal(map, data.finished))
  115. cpu_relax();
  116. spin_unlock_bh(&call_lock);
  117. out:
  118. local_irq_disable();
  119. if (local)
  120. func(info);
  121. local_irq_enable();
  122. }
  123. /*
  124. * smp_call_function:
  125. * @func: the function to run; this must be fast and non-blocking
  126. * @info: an arbitrary pointer to pass to the function
  127. * @nonatomic: unused
  128. * @wait: if true, wait (atomically) until function has completed on other CPUs
  129. *
  130. * Run a function on all other CPUs.
  131. *
  132. * You must not call this function with disabled interrupts, from a
  133. * hardware interrupt handler or from a bottom half.
  134. */
  135. int smp_call_function(void (*func) (void *info), void *info, int nonatomic,
  136. int wait)
  137. {
  138. cpumask_t map;
  139. preempt_disable();
  140. map = cpu_online_map;
  141. cpu_clear(smp_processor_id(), map);
  142. __smp_call_function_map(func, info, nonatomic, wait, map);
  143. preempt_enable();
  144. return 0;
  145. }
  146. EXPORT_SYMBOL(smp_call_function);
  147. /*
  148. * smp_call_function_single:
  149. * @cpu: the CPU where func should run
  150. * @func: the function to run; this must be fast and non-blocking
  151. * @info: an arbitrary pointer to pass to the function
  152. * @nonatomic: unused
  153. * @wait: if true, wait (atomically) until function has completed on other CPUs
  154. *
  155. * Run a function on one processor.
  156. *
  157. * You must not call this function with disabled interrupts, from a
  158. * hardware interrupt handler or from a bottom half.
  159. */
  160. int smp_call_function_single(int cpu, void (*func) (void *info), void *info,
  161. int nonatomic, int wait)
  162. {
  163. preempt_disable();
  164. __smp_call_function_map(func, info, nonatomic, wait,
  165. cpumask_of_cpu(cpu));
  166. preempt_enable();
  167. return 0;
  168. }
  169. EXPORT_SYMBOL(smp_call_function_single);
  170. static void do_send_stop(void)
  171. {
  172. int cpu, rc;
  173. /* stop all processors */
  174. for_each_online_cpu(cpu) {
  175. if (cpu == smp_processor_id())
  176. continue;
  177. do {
  178. rc = signal_processor(cpu, sigp_stop);
  179. } while (rc == sigp_busy);
  180. }
  181. }
  182. static void do_store_status(void)
  183. {
  184. int cpu, rc;
  185. /* store status of all processors in their lowcores (real 0) */
  186. for_each_online_cpu(cpu) {
  187. if (cpu == smp_processor_id())
  188. continue;
  189. do {
  190. rc = signal_processor_p(
  191. (__u32)(unsigned long) lowcore_ptr[cpu], cpu,
  192. sigp_store_status_at_address);
  193. } while (rc == sigp_busy);
  194. }
  195. }
  196. static void do_wait_for_stop(void)
  197. {
  198. int cpu;
  199. /* Wait for all other cpus to enter stopped state */
  200. for_each_online_cpu(cpu) {
  201. if (cpu == smp_processor_id())
  202. continue;
  203. while (!smp_cpu_not_running(cpu))
  204. cpu_relax();
  205. }
  206. }
  207. /*
  208. * this function sends a 'stop' sigp to all other CPUs in the system.
  209. * it goes straight through.
  210. */
  211. void smp_send_stop(void)
  212. {
  213. /* Disable all interrupts/machine checks */
  214. __load_psw_mask(psw_kernel_bits & ~PSW_MASK_MCHECK);
  215. /* write magic number to zero page (absolute 0) */
  216. lowcore_ptr[smp_processor_id()]->panic_magic = __PANIC_MAGIC;
  217. /* stop other processors. */
  218. do_send_stop();
  219. /* wait until other processors are stopped */
  220. do_wait_for_stop();
  221. /* store status of other processors. */
  222. do_store_status();
  223. }
  224. /*
  225. * Reboot, halt and power_off routines for SMP.
  226. */
  227. void machine_restart_smp(char *__unused)
  228. {
  229. smp_send_stop();
  230. do_reipl();
  231. }
  232. void machine_halt_smp(void)
  233. {
  234. smp_send_stop();
  235. if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0)
  236. __cpcmd(vmhalt_cmd, NULL, 0, NULL);
  237. signal_processor(smp_processor_id(), sigp_stop_and_store_status);
  238. for (;;);
  239. }
  240. void machine_power_off_smp(void)
  241. {
  242. smp_send_stop();
  243. if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0)
  244. __cpcmd(vmpoff_cmd, NULL, 0, NULL);
  245. signal_processor(smp_processor_id(), sigp_stop_and_store_status);
  246. for (;;);
  247. }
  248. /*
  249. * This is the main routine where commands issued by other
  250. * cpus are handled.
  251. */
  252. static void do_ext_call_interrupt(__u16 code)
  253. {
  254. unsigned long bits;
  255. /*
  256. * handle bit signal external calls
  257. *
  258. * For the ec_schedule signal we have to do nothing. All the work
  259. * is done automatically when we return from the interrupt.
  260. */
  261. bits = xchg(&S390_lowcore.ext_call_fast, 0);
  262. if (test_bit(ec_call_function, &bits))
  263. do_call_function();
  264. }
  265. /*
  266. * Send an external call sigp to another cpu and return without waiting
  267. * for its completion.
  268. */
  269. static void smp_ext_bitcall(int cpu, ec_bit_sig sig)
  270. {
  271. /*
  272. * Set signaling bit in lowcore of target cpu and kick it
  273. */
  274. set_bit(sig, (unsigned long *) &lowcore_ptr[cpu]->ext_call_fast);
  275. while (signal_processor(cpu, sigp_emergency_signal) == sigp_busy)
  276. udelay(10);
  277. }
  278. #ifndef CONFIG_64BIT
  279. /*
  280. * this function sends a 'purge tlb' signal to another CPU.
  281. */
  282. void smp_ptlb_callback(void *info)
  283. {
  284. local_flush_tlb();
  285. }
  286. void smp_ptlb_all(void)
  287. {
  288. on_each_cpu(smp_ptlb_callback, NULL, 0, 1);
  289. }
  290. EXPORT_SYMBOL(smp_ptlb_all);
  291. #endif /* ! CONFIG_64BIT */
  292. /*
  293. * this function sends a 'reschedule' IPI to another CPU.
  294. * it goes straight through and wastes no time serializing
  295. * anything. Worst case is that we lose a reschedule ...
  296. */
  297. void smp_send_reschedule(int cpu)
  298. {
  299. smp_ext_bitcall(cpu, ec_schedule);
  300. }
  301. /*
  302. * parameter area for the set/clear control bit callbacks
  303. */
  304. struct ec_creg_mask_parms {
  305. unsigned long orvals[16];
  306. unsigned long andvals[16];
  307. };
  308. /*
  309. * callback for setting/clearing control bits
  310. */
  311. static void smp_ctl_bit_callback(void *info)
  312. {
  313. struct ec_creg_mask_parms *pp = info;
  314. unsigned long cregs[16];
  315. int i;
  316. __ctl_store(cregs, 0, 15);
  317. for (i = 0; i <= 15; i++)
  318. cregs[i] = (cregs[i] & pp->andvals[i]) | pp->orvals[i];
  319. __ctl_load(cregs, 0, 15);
  320. }
  321. /*
  322. * Set a bit in a control register of all cpus
  323. */
  324. void smp_ctl_set_bit(int cr, int bit)
  325. {
  326. struct ec_creg_mask_parms parms;
  327. memset(&parms.orvals, 0, sizeof(parms.orvals));
  328. memset(&parms.andvals, 0xff, sizeof(parms.andvals));
  329. parms.orvals[cr] = 1 << bit;
  330. on_each_cpu(smp_ctl_bit_callback, &parms, 0, 1);
  331. }
  332. EXPORT_SYMBOL(smp_ctl_set_bit);
  333. /*
  334. * Clear a bit in a control register of all cpus
  335. */
  336. void smp_ctl_clear_bit(int cr, int bit)
  337. {
  338. struct ec_creg_mask_parms parms;
  339. memset(&parms.orvals, 0, sizeof(parms.orvals));
  340. memset(&parms.andvals, 0xff, sizeof(parms.andvals));
  341. parms.andvals[cr] = ~(1L << bit);
  342. on_each_cpu(smp_ctl_bit_callback, &parms, 0, 1);
  343. }
  344. EXPORT_SYMBOL(smp_ctl_clear_bit);
  345. #if defined(CONFIG_ZFCPDUMP) || defined(CONFIG_ZFCPDUMP_MODULE)
  346. /*
  347. * zfcpdump_prefix_array holds prefix registers for the following scenario:
  348. * 64 bit zfcpdump kernel and 31 bit kernel which is to be dumped. We have to
  349. * save its prefix registers, since they get lost, when switching from 31 bit
  350. * to 64 bit.
  351. */
  352. unsigned int zfcpdump_prefix_array[NR_CPUS + 1] \
  353. __attribute__((__section__(".data")));
  354. static void __init smp_get_save_area(unsigned int cpu, unsigned int phy_cpu)
  355. {
  356. if (ipl_info.type != IPL_TYPE_FCP_DUMP)
  357. return;
  358. if (cpu >= NR_CPUS) {
  359. printk(KERN_WARNING "Registers for cpu %i not saved since dump "
  360. "kernel was compiled with NR_CPUS=%i\n", cpu, NR_CPUS);
  361. return;
  362. }
  363. zfcpdump_save_areas[cpu] = alloc_bootmem(sizeof(union save_area));
  364. __cpu_logical_map[1] = (__u16) phy_cpu;
  365. while (signal_processor(1, sigp_stop_and_store_status) == sigp_busy)
  366. cpu_relax();
  367. memcpy(zfcpdump_save_areas[cpu],
  368. (void *)(unsigned long) store_prefix() + SAVE_AREA_BASE,
  369. SAVE_AREA_SIZE);
  370. #ifdef CONFIG_64BIT
  371. /* copy original prefix register */
  372. zfcpdump_save_areas[cpu]->s390x.pref_reg = zfcpdump_prefix_array[cpu];
  373. #endif
  374. }
  375. union save_area *zfcpdump_save_areas[NR_CPUS + 1];
  376. EXPORT_SYMBOL_GPL(zfcpdump_save_areas);
  377. #else
  378. static inline void smp_get_save_area(unsigned int cpu, unsigned int phy_cpu) { }
  379. #endif /* CONFIG_ZFCPDUMP || CONFIG_ZFCPDUMP_MODULE */
  380. /*
  381. * Lets check how many CPUs we have.
  382. */
  383. static unsigned int __init smp_count_cpus(void)
  384. {
  385. unsigned int cpu, num_cpus;
  386. __u16 boot_cpu_addr;
  387. /*
  388. * cpu 0 is the boot cpu. See smp_prepare_boot_cpu.
  389. */
  390. boot_cpu_addr = S390_lowcore.cpu_data.cpu_addr;
  391. current_thread_info()->cpu = 0;
  392. num_cpus = 1;
  393. for (cpu = 0; cpu <= 65535; cpu++) {
  394. if ((__u16) cpu == boot_cpu_addr)
  395. continue;
  396. __cpu_logical_map[1] = (__u16) cpu;
  397. if (signal_processor(1, sigp_sense) == sigp_not_operational)
  398. continue;
  399. smp_get_save_area(num_cpus, cpu);
  400. num_cpus++;
  401. }
  402. printk("Detected %d CPU's\n", (int) num_cpus);
  403. printk("Boot cpu address %2X\n", boot_cpu_addr);
  404. return num_cpus;
  405. }
  406. /*
  407. * Activate a secondary processor.
  408. */
  409. int __cpuinit start_secondary(void *cpuvoid)
  410. {
  411. /* Setup the cpu */
  412. cpu_init();
  413. preempt_disable();
  414. /* Enable TOD clock interrupts on the secondary cpu. */
  415. init_cpu_timer();
  416. #ifdef CONFIG_VIRT_TIMER
  417. /* Enable cpu timer interrupts on the secondary cpu. */
  418. init_cpu_vtimer();
  419. #endif
  420. /* Enable pfault pseudo page faults on this cpu. */
  421. pfault_init();
  422. /* Mark this cpu as online */
  423. cpu_set(smp_processor_id(), cpu_online_map);
  424. /* Switch on interrupts */
  425. local_irq_enable();
  426. /* Print info about this processor */
  427. print_cpu_info(&S390_lowcore.cpu_data);
  428. /* cpu_idle will call schedule for us */
  429. cpu_idle();
  430. return 0;
  431. }
  432. static void __init smp_create_idle(unsigned int cpu)
  433. {
  434. struct task_struct *p;
  435. /*
  436. * don't care about the psw and regs settings since we'll never
  437. * reschedule the forked task.
  438. */
  439. p = fork_idle(cpu);
  440. if (IS_ERR(p))
  441. panic("failed fork for CPU %u: %li", cpu, PTR_ERR(p));
  442. current_set[cpu] = p;
  443. }
  444. static int cpu_stopped(int cpu)
  445. {
  446. __u32 status;
  447. /* Check for stopped state */
  448. if (signal_processor_ps(&status, 0, cpu, sigp_sense) ==
  449. sigp_status_stored) {
  450. if (status & 0x40)
  451. return 1;
  452. }
  453. return 0;
  454. }
  455. /* Upping and downing of CPUs */
  456. int __cpu_up(unsigned int cpu)
  457. {
  458. struct task_struct *idle;
  459. struct _lowcore *cpu_lowcore;
  460. struct stack_frame *sf;
  461. sigp_ccode ccode;
  462. int curr_cpu;
  463. for (curr_cpu = 0; curr_cpu <= 65535; curr_cpu++) {
  464. __cpu_logical_map[cpu] = (__u16) curr_cpu;
  465. if (cpu_stopped(cpu))
  466. break;
  467. }
  468. if (!cpu_stopped(cpu))
  469. return -ENODEV;
  470. ccode = signal_processor_p((__u32)(unsigned long)(lowcore_ptr[cpu]),
  471. cpu, sigp_set_prefix);
  472. if (ccode) {
  473. printk("sigp_set_prefix failed for cpu %d "
  474. "with condition code %d\n",
  475. (int) cpu, (int) ccode);
  476. return -EIO;
  477. }
  478. idle = current_set[cpu];
  479. cpu_lowcore = lowcore_ptr[cpu];
  480. cpu_lowcore->kernel_stack = (unsigned long)
  481. task_stack_page(idle) + THREAD_SIZE;
  482. sf = (struct stack_frame *) (cpu_lowcore->kernel_stack
  483. - sizeof(struct pt_regs)
  484. - sizeof(struct stack_frame));
  485. memset(sf, 0, sizeof(struct stack_frame));
  486. sf->gprs[9] = (unsigned long) sf;
  487. cpu_lowcore->save_area[15] = (unsigned long) sf;
  488. __ctl_store(cpu_lowcore->cregs_save_area[0], 0, 15);
  489. asm volatile(
  490. " stam 0,15,0(%0)"
  491. : : "a" (&cpu_lowcore->access_regs_save_area) : "memory");
  492. cpu_lowcore->percpu_offset = __per_cpu_offset[cpu];
  493. cpu_lowcore->current_task = (unsigned long) idle;
  494. cpu_lowcore->cpu_data.cpu_nr = cpu;
  495. eieio();
  496. while (signal_processor(cpu, sigp_restart) == sigp_busy)
  497. udelay(10);
  498. while (!cpu_online(cpu))
  499. cpu_relax();
  500. return 0;
  501. }
  502. static unsigned int __initdata additional_cpus;
  503. static unsigned int __initdata possible_cpus;
  504. void __init smp_setup_cpu_possible_map(void)
  505. {
  506. unsigned int phy_cpus, pos_cpus, cpu;
  507. phy_cpus = smp_count_cpus();
  508. pos_cpus = min(phy_cpus + additional_cpus, (unsigned int) NR_CPUS);
  509. if (possible_cpus)
  510. pos_cpus = min(possible_cpus, (unsigned int) NR_CPUS);
  511. for (cpu = 0; cpu < pos_cpus; cpu++)
  512. cpu_set(cpu, cpu_possible_map);
  513. phy_cpus = min(phy_cpus, pos_cpus);
  514. for (cpu = 0; cpu < phy_cpus; cpu++)
  515. cpu_set(cpu, cpu_present_map);
  516. }
  517. #ifdef CONFIG_HOTPLUG_CPU
  518. static int __init setup_additional_cpus(char *s)
  519. {
  520. additional_cpus = simple_strtoul(s, NULL, 0);
  521. return 0;
  522. }
  523. early_param("additional_cpus", setup_additional_cpus);
  524. static int __init setup_possible_cpus(char *s)
  525. {
  526. possible_cpus = simple_strtoul(s, NULL, 0);
  527. return 0;
  528. }
  529. early_param("possible_cpus", setup_possible_cpus);
  530. int __cpu_disable(void)
  531. {
  532. struct ec_creg_mask_parms cr_parms;
  533. int cpu = smp_processor_id();
  534. cpu_clear(cpu, cpu_online_map);
  535. /* Disable pfault pseudo page faults on this cpu. */
  536. pfault_fini();
  537. memset(&cr_parms.orvals, 0, sizeof(cr_parms.orvals));
  538. memset(&cr_parms.andvals, 0xff, sizeof(cr_parms.andvals));
  539. /* disable all external interrupts */
  540. cr_parms.orvals[0] = 0;
  541. cr_parms.andvals[0] = ~(1 << 15 | 1 << 14 | 1 << 13 | 1 << 12 |
  542. 1 << 11 | 1 << 10 | 1 << 6 | 1 << 4);
  543. /* disable all I/O interrupts */
  544. cr_parms.orvals[6] = 0;
  545. cr_parms.andvals[6] = ~(1 << 31 | 1 << 30 | 1 << 29 | 1 << 28 |
  546. 1 << 27 | 1 << 26 | 1 << 25 | 1 << 24);
  547. /* disable most machine checks */
  548. cr_parms.orvals[14] = 0;
  549. cr_parms.andvals[14] = ~(1 << 28 | 1 << 27 | 1 << 26 |
  550. 1 << 25 | 1 << 24);
  551. smp_ctl_bit_callback(&cr_parms);
  552. return 0;
  553. }
  554. void __cpu_die(unsigned int cpu)
  555. {
  556. /* Wait until target cpu is down */
  557. while (!smp_cpu_not_running(cpu))
  558. cpu_relax();
  559. printk("Processor %d spun down\n", cpu);
  560. }
  561. void cpu_die(void)
  562. {
  563. idle_task_exit();
  564. signal_processor(smp_processor_id(), sigp_stop);
  565. BUG();
  566. for (;;);
  567. }
  568. #endif /* CONFIG_HOTPLUG_CPU */
  569. /*
  570. * Cycle through the processors and setup structures.
  571. */
  572. void __init smp_prepare_cpus(unsigned int max_cpus)
  573. {
  574. unsigned long stack;
  575. unsigned int cpu;
  576. int i;
  577. /* request the 0x1201 emergency signal external interrupt */
  578. if (register_external_interrupt(0x1201, do_ext_call_interrupt) != 0)
  579. panic("Couldn't request external interrupt 0x1201");
  580. memset(lowcore_ptr, 0, sizeof(lowcore_ptr));
  581. /*
  582. * Initialize prefix pages and stacks for all possible cpus
  583. */
  584. print_cpu_info(&S390_lowcore.cpu_data);
  585. for_each_possible_cpu(i) {
  586. lowcore_ptr[i] = (struct _lowcore *)
  587. __get_free_pages(GFP_KERNEL | GFP_DMA,
  588. sizeof(void*) == 8 ? 1 : 0);
  589. stack = __get_free_pages(GFP_KERNEL, ASYNC_ORDER);
  590. if (!lowcore_ptr[i] || !stack)
  591. panic("smp_boot_cpus failed to allocate memory\n");
  592. *(lowcore_ptr[i]) = S390_lowcore;
  593. lowcore_ptr[i]->async_stack = stack + ASYNC_SIZE;
  594. stack = __get_free_pages(GFP_KERNEL, 0);
  595. if (!stack)
  596. panic("smp_boot_cpus failed to allocate memory\n");
  597. lowcore_ptr[i]->panic_stack = stack + PAGE_SIZE;
  598. #ifndef CONFIG_64BIT
  599. if (MACHINE_HAS_IEEE) {
  600. lowcore_ptr[i]->extended_save_area_addr =
  601. (__u32) __get_free_pages(GFP_KERNEL, 0);
  602. if (!lowcore_ptr[i]->extended_save_area_addr)
  603. panic("smp_boot_cpus failed to "
  604. "allocate memory\n");
  605. }
  606. #endif
  607. }
  608. #ifndef CONFIG_64BIT
  609. if (MACHINE_HAS_IEEE)
  610. ctl_set_bit(14, 29); /* enable extended save area */
  611. #endif
  612. set_prefix((u32)(unsigned long) lowcore_ptr[smp_processor_id()]);
  613. for_each_possible_cpu(cpu)
  614. if (cpu != smp_processor_id())
  615. smp_create_idle(cpu);
  616. }
  617. void __init smp_prepare_boot_cpu(void)
  618. {
  619. BUG_ON(smp_processor_id() != 0);
  620. cpu_set(0, cpu_online_map);
  621. S390_lowcore.percpu_offset = __per_cpu_offset[0];
  622. current_set[0] = current;
  623. }
  624. void __init smp_cpus_done(unsigned int max_cpus)
  625. {
  626. cpu_present_map = cpu_possible_map;
  627. }
  628. /*
  629. * the frequency of the profiling timer can be changed
  630. * by writing a multiplier value into /proc/profile.
  631. *
  632. * usually you want to run this on all CPUs ;)
  633. */
  634. int setup_profiling_timer(unsigned int multiplier)
  635. {
  636. return 0;
  637. }
  638. static DEFINE_PER_CPU(struct cpu, cpu_devices);
  639. static ssize_t show_capability(struct sys_device *dev, char *buf)
  640. {
  641. unsigned int capability;
  642. int rc;
  643. rc = get_cpu_capability(&capability);
  644. if (rc)
  645. return rc;
  646. return sprintf(buf, "%u\n", capability);
  647. }
  648. static SYSDEV_ATTR(capability, 0444, show_capability, NULL);
  649. static int __cpuinit smp_cpu_notify(struct notifier_block *self,
  650. unsigned long action, void *hcpu)
  651. {
  652. unsigned int cpu = (unsigned int)(long)hcpu;
  653. struct cpu *c = &per_cpu(cpu_devices, cpu);
  654. struct sys_device *s = &c->sysdev;
  655. switch (action) {
  656. case CPU_ONLINE:
  657. case CPU_ONLINE_FROZEN:
  658. if (sysdev_create_file(s, &attr_capability))
  659. return NOTIFY_BAD;
  660. break;
  661. case CPU_DEAD:
  662. case CPU_DEAD_FROZEN:
  663. sysdev_remove_file(s, &attr_capability);
  664. break;
  665. }
  666. return NOTIFY_OK;
  667. }
  668. static struct notifier_block __cpuinitdata smp_cpu_nb = {
  669. .notifier_call = smp_cpu_notify,
  670. };
  671. static int __init topology_init(void)
  672. {
  673. int cpu;
  674. register_cpu_notifier(&smp_cpu_nb);
  675. for_each_possible_cpu(cpu) {
  676. struct cpu *c = &per_cpu(cpu_devices, cpu);
  677. struct sys_device *s = &c->sysdev;
  678. c->hotpluggable = 1;
  679. register_cpu(c, cpu);
  680. if (!cpu_online(cpu))
  681. continue;
  682. s = &c->sysdev;
  683. sysdev_create_file(s, &attr_capability);
  684. }
  685. return 0;
  686. }
  687. subsys_initcall(topology_init);