smp.c 19 KB

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