smp.c 19 KB

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