smp.c 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  1. /*
  2. * arch/s390/kernel/smp.c
  3. *
  4. * Copyright IBM Corp. 1999, 2009
  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. #define KMSG_COMPONENT "cpu"
  23. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  24. #include <linux/module.h>
  25. #include <linux/init.h>
  26. #include <linux/mm.h>
  27. #include <linux/err.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/kernel_stat.h>
  30. #include <linux/delay.h>
  31. #include <linux/cache.h>
  32. #include <linux/interrupt.h>
  33. #include <linux/irqflags.h>
  34. #include <linux/cpu.h>
  35. #include <linux/timex.h>
  36. #include <linux/bootmem.h>
  37. #include <linux/slab.h>
  38. #include <asm/asm-offsets.h>
  39. #include <asm/ipl.h>
  40. #include <asm/setup.h>
  41. #include <asm/sigp.h>
  42. #include <asm/pgalloc.h>
  43. #include <asm/irq.h>
  44. #include <asm/s390_ext.h>
  45. #include <asm/cpcmd.h>
  46. #include <asm/tlbflush.h>
  47. #include <asm/timer.h>
  48. #include <asm/lowcore.h>
  49. #include <asm/sclp.h>
  50. #include <asm/cputime.h>
  51. #include <asm/vdso.h>
  52. #include <asm/cpu.h>
  53. #include "entry.h"
  54. /* logical cpu to cpu address */
  55. unsigned short __cpu_logical_map[NR_CPUS];
  56. static struct task_struct *current_set[NR_CPUS];
  57. static u8 smp_cpu_type;
  58. static int smp_use_sigp_detection;
  59. enum s390_cpu_state {
  60. CPU_STATE_STANDBY,
  61. CPU_STATE_CONFIGURED,
  62. };
  63. DEFINE_MUTEX(smp_cpu_state_mutex);
  64. int smp_cpu_polarization[NR_CPUS];
  65. static int smp_cpu_state[NR_CPUS];
  66. static int cpu_management;
  67. static DEFINE_PER_CPU(struct cpu, cpu_devices);
  68. static void smp_ext_bitcall(int, int);
  69. static int raw_cpu_stopped(int cpu)
  70. {
  71. u32 status;
  72. switch (raw_sigp_ps(&status, 0, cpu, sigp_sense)) {
  73. case sigp_status_stored:
  74. /* Check for stopped and check stop state */
  75. if (status & 0x50)
  76. return 1;
  77. break;
  78. default:
  79. break;
  80. }
  81. return 0;
  82. }
  83. static inline int cpu_stopped(int cpu)
  84. {
  85. return raw_cpu_stopped(cpu_logical_map(cpu));
  86. }
  87. void smp_switch_to_ipl_cpu(void (*func)(void *), void *data)
  88. {
  89. struct _lowcore *lc, *current_lc;
  90. struct stack_frame *sf;
  91. struct pt_regs *regs;
  92. unsigned long sp;
  93. if (smp_processor_id() == 0)
  94. func(data);
  95. __load_psw_mask(PSW_BASE_BITS | PSW_DEFAULT_KEY);
  96. /* Disable lowcore protection */
  97. __ctl_clear_bit(0, 28);
  98. current_lc = lowcore_ptr[smp_processor_id()];
  99. lc = lowcore_ptr[0];
  100. if (!lc)
  101. lc = current_lc;
  102. lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
  103. lc->restart_psw.addr = PSW_ADDR_AMODE | (unsigned long) smp_restart_cpu;
  104. if (!cpu_online(0))
  105. smp_switch_to_cpu(func, data, 0, stap(), __cpu_logical_map[0]);
  106. while (sigp(0, sigp_stop_and_store_status) == sigp_busy)
  107. cpu_relax();
  108. sp = lc->panic_stack;
  109. sp -= sizeof(struct pt_regs);
  110. regs = (struct pt_regs *) sp;
  111. memcpy(&regs->gprs, &current_lc->gpregs_save_area, sizeof(regs->gprs));
  112. regs->psw = lc->psw_save_area;
  113. sp -= STACK_FRAME_OVERHEAD;
  114. sf = (struct stack_frame *) sp;
  115. sf->back_chain = regs->gprs[15];
  116. smp_switch_to_cpu(func, data, sp, stap(), __cpu_logical_map[0]);
  117. }
  118. void smp_send_stop(void)
  119. {
  120. int cpu, rc;
  121. /* Disable all interrupts/machine checks */
  122. __load_psw_mask(psw_kernel_bits & ~PSW_MASK_MCHECK);
  123. trace_hardirqs_off();
  124. /* stop all processors */
  125. for_each_online_cpu(cpu) {
  126. if (cpu == smp_processor_id())
  127. continue;
  128. do {
  129. rc = sigp(cpu, sigp_stop);
  130. } while (rc == sigp_busy);
  131. while (!cpu_stopped(cpu))
  132. cpu_relax();
  133. }
  134. }
  135. /*
  136. * This is the main routine where commands issued by other
  137. * cpus are handled.
  138. */
  139. static void do_ext_call_interrupt(__u16 code)
  140. {
  141. unsigned long bits;
  142. /*
  143. * handle bit signal external calls
  144. *
  145. * For the ec_schedule signal we have to do nothing. All the work
  146. * is done automatically when we return from the interrupt.
  147. */
  148. bits = xchg(&S390_lowcore.ext_call_fast, 0);
  149. if (test_bit(ec_call_function, &bits))
  150. generic_smp_call_function_interrupt();
  151. if (test_bit(ec_call_function_single, &bits))
  152. generic_smp_call_function_single_interrupt();
  153. }
  154. /*
  155. * Send an external call sigp to another cpu and return without waiting
  156. * for its completion.
  157. */
  158. static void smp_ext_bitcall(int cpu, int sig)
  159. {
  160. /*
  161. * Set signaling bit in lowcore of target cpu and kick it
  162. */
  163. set_bit(sig, (unsigned long *) &lowcore_ptr[cpu]->ext_call_fast);
  164. while (sigp(cpu, sigp_emergency_signal) == sigp_busy)
  165. udelay(10);
  166. }
  167. void arch_send_call_function_ipi_mask(const struct cpumask *mask)
  168. {
  169. int cpu;
  170. for_each_cpu(cpu, mask)
  171. smp_ext_bitcall(cpu, ec_call_function);
  172. }
  173. void arch_send_call_function_single_ipi(int cpu)
  174. {
  175. smp_ext_bitcall(cpu, ec_call_function_single);
  176. }
  177. #ifndef CONFIG_64BIT
  178. /*
  179. * this function sends a 'purge tlb' signal to another CPU.
  180. */
  181. static void smp_ptlb_callback(void *info)
  182. {
  183. __tlb_flush_local();
  184. }
  185. void smp_ptlb_all(void)
  186. {
  187. on_each_cpu(smp_ptlb_callback, NULL, 1);
  188. }
  189. EXPORT_SYMBOL(smp_ptlb_all);
  190. #endif /* ! CONFIG_64BIT */
  191. /*
  192. * this function sends a 'reschedule' IPI to another CPU.
  193. * it goes straight through and wastes no time serializing
  194. * anything. Worst case is that we lose a reschedule ...
  195. */
  196. void smp_send_reschedule(int cpu)
  197. {
  198. smp_ext_bitcall(cpu, ec_schedule);
  199. }
  200. /*
  201. * parameter area for the set/clear control bit callbacks
  202. */
  203. struct ec_creg_mask_parms {
  204. unsigned long orvals[16];
  205. unsigned long andvals[16];
  206. };
  207. /*
  208. * callback for setting/clearing control bits
  209. */
  210. static void smp_ctl_bit_callback(void *info)
  211. {
  212. struct ec_creg_mask_parms *pp = info;
  213. unsigned long cregs[16];
  214. int i;
  215. __ctl_store(cregs, 0, 15);
  216. for (i = 0; i <= 15; i++)
  217. cregs[i] = (cregs[i] & pp->andvals[i]) | pp->orvals[i];
  218. __ctl_load(cregs, 0, 15);
  219. }
  220. /*
  221. * Set a bit in a control register of all cpus
  222. */
  223. void smp_ctl_set_bit(int cr, int bit)
  224. {
  225. struct ec_creg_mask_parms parms;
  226. memset(&parms.orvals, 0, sizeof(parms.orvals));
  227. memset(&parms.andvals, 0xff, sizeof(parms.andvals));
  228. parms.orvals[cr] = 1 << bit;
  229. on_each_cpu(smp_ctl_bit_callback, &parms, 1);
  230. }
  231. EXPORT_SYMBOL(smp_ctl_set_bit);
  232. /*
  233. * Clear a bit in a control register of all cpus
  234. */
  235. void smp_ctl_clear_bit(int cr, int bit)
  236. {
  237. struct ec_creg_mask_parms parms;
  238. memset(&parms.orvals, 0, sizeof(parms.orvals));
  239. memset(&parms.andvals, 0xff, sizeof(parms.andvals));
  240. parms.andvals[cr] = ~(1L << bit);
  241. on_each_cpu(smp_ctl_bit_callback, &parms, 1);
  242. }
  243. EXPORT_SYMBOL(smp_ctl_clear_bit);
  244. #ifdef CONFIG_ZFCPDUMP
  245. static void __init smp_get_save_area(unsigned int cpu, unsigned int phy_cpu)
  246. {
  247. if (ipl_info.type != IPL_TYPE_FCP_DUMP)
  248. return;
  249. if (cpu >= NR_CPUS) {
  250. pr_warning("CPU %i exceeds the maximum %i and is excluded from "
  251. "the dump\n", cpu, NR_CPUS - 1);
  252. return;
  253. }
  254. zfcpdump_save_areas[cpu] = kmalloc(sizeof(struct save_area), GFP_KERNEL);
  255. while (raw_sigp(phy_cpu, sigp_stop_and_store_status) == sigp_busy)
  256. cpu_relax();
  257. memcpy_real(zfcpdump_save_areas[cpu],
  258. (void *)(unsigned long) store_prefix() + SAVE_AREA_BASE,
  259. sizeof(struct save_area));
  260. }
  261. struct save_area *zfcpdump_save_areas[NR_CPUS + 1];
  262. EXPORT_SYMBOL_GPL(zfcpdump_save_areas);
  263. #else
  264. static inline void smp_get_save_area(unsigned int cpu, unsigned int phy_cpu) { }
  265. #endif /* CONFIG_ZFCPDUMP */
  266. static int cpu_known(int cpu_id)
  267. {
  268. int cpu;
  269. for_each_present_cpu(cpu) {
  270. if (__cpu_logical_map[cpu] == cpu_id)
  271. return 1;
  272. }
  273. return 0;
  274. }
  275. static int smp_rescan_cpus_sigp(cpumask_t avail)
  276. {
  277. int cpu_id, logical_cpu;
  278. logical_cpu = cpumask_first(&avail);
  279. if (logical_cpu >= nr_cpu_ids)
  280. return 0;
  281. for (cpu_id = 0; cpu_id <= MAX_CPU_ADDRESS; cpu_id++) {
  282. if (cpu_known(cpu_id))
  283. continue;
  284. __cpu_logical_map[logical_cpu] = cpu_id;
  285. smp_cpu_polarization[logical_cpu] = POLARIZATION_UNKNWN;
  286. if (!cpu_stopped(logical_cpu))
  287. continue;
  288. cpu_set(logical_cpu, cpu_present_map);
  289. smp_cpu_state[logical_cpu] = CPU_STATE_CONFIGURED;
  290. logical_cpu = cpumask_next(logical_cpu, &avail);
  291. if (logical_cpu >= nr_cpu_ids)
  292. break;
  293. }
  294. return 0;
  295. }
  296. static int smp_rescan_cpus_sclp(cpumask_t avail)
  297. {
  298. struct sclp_cpu_info *info;
  299. int cpu_id, logical_cpu, cpu;
  300. int rc;
  301. logical_cpu = cpumask_first(&avail);
  302. if (logical_cpu >= nr_cpu_ids)
  303. return 0;
  304. info = kmalloc(sizeof(*info), GFP_KERNEL);
  305. if (!info)
  306. return -ENOMEM;
  307. rc = sclp_get_cpu_info(info);
  308. if (rc)
  309. goto out;
  310. for (cpu = 0; cpu < info->combined; cpu++) {
  311. if (info->has_cpu_type && info->cpu[cpu].type != smp_cpu_type)
  312. continue;
  313. cpu_id = info->cpu[cpu].address;
  314. if (cpu_known(cpu_id))
  315. continue;
  316. __cpu_logical_map[logical_cpu] = cpu_id;
  317. smp_cpu_polarization[logical_cpu] = POLARIZATION_UNKNWN;
  318. cpu_set(logical_cpu, cpu_present_map);
  319. if (cpu >= info->configured)
  320. smp_cpu_state[logical_cpu] = CPU_STATE_STANDBY;
  321. else
  322. smp_cpu_state[logical_cpu] = CPU_STATE_CONFIGURED;
  323. logical_cpu = cpumask_next(logical_cpu, &avail);
  324. if (logical_cpu >= nr_cpu_ids)
  325. break;
  326. }
  327. out:
  328. kfree(info);
  329. return rc;
  330. }
  331. static int __smp_rescan_cpus(void)
  332. {
  333. cpumask_t avail;
  334. cpus_xor(avail, cpu_possible_map, cpu_present_map);
  335. if (smp_use_sigp_detection)
  336. return smp_rescan_cpus_sigp(avail);
  337. else
  338. return smp_rescan_cpus_sclp(avail);
  339. }
  340. static void __init smp_detect_cpus(void)
  341. {
  342. unsigned int cpu, c_cpus, s_cpus;
  343. struct sclp_cpu_info *info;
  344. u16 boot_cpu_addr, cpu_addr;
  345. c_cpus = 1;
  346. s_cpus = 0;
  347. boot_cpu_addr = __cpu_logical_map[0];
  348. info = kmalloc(sizeof(*info), GFP_KERNEL);
  349. if (!info)
  350. panic("smp_detect_cpus failed to allocate memory\n");
  351. /* Use sigp detection algorithm if sclp doesn't work. */
  352. if (sclp_get_cpu_info(info)) {
  353. smp_use_sigp_detection = 1;
  354. for (cpu = 0; cpu <= MAX_CPU_ADDRESS; cpu++) {
  355. if (cpu == boot_cpu_addr)
  356. continue;
  357. if (!raw_cpu_stopped(cpu))
  358. continue;
  359. smp_get_save_area(c_cpus, cpu);
  360. c_cpus++;
  361. }
  362. goto out;
  363. }
  364. if (info->has_cpu_type) {
  365. for (cpu = 0; cpu < info->combined; cpu++) {
  366. if (info->cpu[cpu].address == boot_cpu_addr) {
  367. smp_cpu_type = info->cpu[cpu].type;
  368. break;
  369. }
  370. }
  371. }
  372. for (cpu = 0; cpu < info->combined; cpu++) {
  373. if (info->has_cpu_type && info->cpu[cpu].type != smp_cpu_type)
  374. continue;
  375. cpu_addr = info->cpu[cpu].address;
  376. if (cpu_addr == boot_cpu_addr)
  377. continue;
  378. if (!raw_cpu_stopped(cpu_addr)) {
  379. s_cpus++;
  380. continue;
  381. }
  382. smp_get_save_area(c_cpus, cpu_addr);
  383. c_cpus++;
  384. }
  385. out:
  386. kfree(info);
  387. pr_info("%d configured CPUs, %d standby CPUs\n", c_cpus, s_cpus);
  388. get_online_cpus();
  389. __smp_rescan_cpus();
  390. put_online_cpus();
  391. }
  392. /*
  393. * Activate a secondary processor.
  394. */
  395. int __cpuinit start_secondary(void *cpuvoid)
  396. {
  397. /* Setup the cpu */
  398. cpu_init();
  399. preempt_disable();
  400. /* Enable TOD clock interrupts on the secondary cpu. */
  401. init_cpu_timer();
  402. /* Enable cpu timer interrupts on the secondary cpu. */
  403. init_cpu_vtimer();
  404. /* Enable pfault pseudo page faults on this cpu. */
  405. pfault_init();
  406. /* call cpu notifiers */
  407. notify_cpu_starting(smp_processor_id());
  408. /* Mark this cpu as online */
  409. ipi_call_lock();
  410. cpu_set(smp_processor_id(), cpu_online_map);
  411. ipi_call_unlock();
  412. /* Switch on interrupts */
  413. local_irq_enable();
  414. /* Print info about this processor */
  415. print_cpu_info();
  416. /* cpu_idle will call schedule for us */
  417. cpu_idle();
  418. return 0;
  419. }
  420. static void __init smp_create_idle(unsigned int cpu)
  421. {
  422. struct task_struct *p;
  423. /*
  424. * don't care about the psw and regs settings since we'll never
  425. * reschedule the forked task.
  426. */
  427. p = fork_idle(cpu);
  428. if (IS_ERR(p))
  429. panic("failed fork for CPU %u: %li", cpu, PTR_ERR(p));
  430. current_set[cpu] = p;
  431. }
  432. static int __cpuinit smp_alloc_lowcore(int cpu)
  433. {
  434. unsigned long async_stack, panic_stack;
  435. struct _lowcore *lowcore;
  436. lowcore = (void *) __get_free_pages(GFP_KERNEL | GFP_DMA, LC_ORDER);
  437. if (!lowcore)
  438. return -ENOMEM;
  439. async_stack = __get_free_pages(GFP_KERNEL, ASYNC_ORDER);
  440. panic_stack = __get_free_page(GFP_KERNEL);
  441. if (!panic_stack || !async_stack)
  442. goto out;
  443. memcpy(lowcore, &S390_lowcore, 512);
  444. memset((char *)lowcore + 512, 0, sizeof(*lowcore) - 512);
  445. lowcore->async_stack = async_stack + ASYNC_SIZE;
  446. lowcore->panic_stack = panic_stack + PAGE_SIZE;
  447. #ifndef CONFIG_64BIT
  448. if (MACHINE_HAS_IEEE) {
  449. unsigned long save_area;
  450. save_area = get_zeroed_page(GFP_KERNEL);
  451. if (!save_area)
  452. goto out;
  453. lowcore->extended_save_area_addr = (u32) save_area;
  454. }
  455. #else
  456. if (vdso_alloc_per_cpu(cpu, lowcore))
  457. goto out;
  458. #endif
  459. lowcore_ptr[cpu] = lowcore;
  460. return 0;
  461. out:
  462. free_page(panic_stack);
  463. free_pages(async_stack, ASYNC_ORDER);
  464. free_pages((unsigned long) lowcore, LC_ORDER);
  465. return -ENOMEM;
  466. }
  467. static void smp_free_lowcore(int cpu)
  468. {
  469. struct _lowcore *lowcore;
  470. lowcore = lowcore_ptr[cpu];
  471. #ifndef CONFIG_64BIT
  472. if (MACHINE_HAS_IEEE)
  473. free_page((unsigned long) lowcore->extended_save_area_addr);
  474. #else
  475. vdso_free_per_cpu(cpu, lowcore);
  476. #endif
  477. free_page(lowcore->panic_stack - PAGE_SIZE);
  478. free_pages(lowcore->async_stack - ASYNC_SIZE, ASYNC_ORDER);
  479. free_pages((unsigned long) lowcore, LC_ORDER);
  480. lowcore_ptr[cpu] = NULL;
  481. }
  482. /* Upping and downing of CPUs */
  483. int __cpuinit __cpu_up(unsigned int cpu)
  484. {
  485. struct _lowcore *cpu_lowcore;
  486. struct task_struct *idle;
  487. struct stack_frame *sf;
  488. u32 lowcore;
  489. int ccode;
  490. if (smp_cpu_state[cpu] != CPU_STATE_CONFIGURED)
  491. return -EIO;
  492. if (smp_alloc_lowcore(cpu))
  493. return -ENOMEM;
  494. do {
  495. ccode = sigp(cpu, sigp_initial_cpu_reset);
  496. if (ccode == sigp_busy)
  497. udelay(10);
  498. if (ccode == sigp_not_operational)
  499. goto err_out;
  500. } while (ccode == sigp_busy);
  501. lowcore = (u32)(unsigned long)lowcore_ptr[cpu];
  502. while (sigp_p(lowcore, cpu, sigp_set_prefix) == sigp_busy)
  503. udelay(10);
  504. idle = current_set[cpu];
  505. cpu_lowcore = lowcore_ptr[cpu];
  506. cpu_lowcore->kernel_stack = (unsigned long)
  507. task_stack_page(idle) + THREAD_SIZE;
  508. cpu_lowcore->thread_info = (unsigned long) task_thread_info(idle);
  509. sf = (struct stack_frame *) (cpu_lowcore->kernel_stack
  510. - sizeof(struct pt_regs)
  511. - sizeof(struct stack_frame));
  512. memset(sf, 0, sizeof(struct stack_frame));
  513. sf->gprs[9] = (unsigned long) sf;
  514. cpu_lowcore->save_area[15] = (unsigned long) sf;
  515. __ctl_store(cpu_lowcore->cregs_save_area, 0, 15);
  516. asm volatile(
  517. " stam 0,15,0(%0)"
  518. : : "a" (&cpu_lowcore->access_regs_save_area) : "memory");
  519. cpu_lowcore->percpu_offset = __per_cpu_offset[cpu];
  520. cpu_lowcore->current_task = (unsigned long) idle;
  521. cpu_lowcore->cpu_nr = cpu;
  522. cpu_lowcore->kernel_asce = S390_lowcore.kernel_asce;
  523. cpu_lowcore->machine_flags = S390_lowcore.machine_flags;
  524. cpu_lowcore->ftrace_func = S390_lowcore.ftrace_func;
  525. eieio();
  526. while (sigp(cpu, sigp_restart) == sigp_busy)
  527. udelay(10);
  528. while (!cpu_online(cpu))
  529. cpu_relax();
  530. return 0;
  531. err_out:
  532. smp_free_lowcore(cpu);
  533. return -EIO;
  534. }
  535. static int __init setup_possible_cpus(char *s)
  536. {
  537. int pcpus, cpu;
  538. pcpus = simple_strtoul(s, NULL, 0);
  539. init_cpu_possible(cpumask_of(0));
  540. for (cpu = 1; cpu < pcpus && cpu < nr_cpu_ids; cpu++)
  541. set_cpu_possible(cpu, true);
  542. return 0;
  543. }
  544. early_param("possible_cpus", setup_possible_cpus);
  545. #ifdef CONFIG_HOTPLUG_CPU
  546. int __cpu_disable(void)
  547. {
  548. struct ec_creg_mask_parms cr_parms;
  549. int cpu = smp_processor_id();
  550. cpu_clear(cpu, cpu_online_map);
  551. /* Disable pfault pseudo page faults on this cpu. */
  552. pfault_fini();
  553. memset(&cr_parms.orvals, 0, sizeof(cr_parms.orvals));
  554. memset(&cr_parms.andvals, 0xff, sizeof(cr_parms.andvals));
  555. /* disable all external interrupts */
  556. cr_parms.orvals[0] = 0;
  557. cr_parms.andvals[0] = ~(1 << 15 | 1 << 14 | 1 << 13 | 1 << 12 |
  558. 1 << 11 | 1 << 10 | 1 << 6 | 1 << 4);
  559. /* disable all I/O interrupts */
  560. cr_parms.orvals[6] = 0;
  561. cr_parms.andvals[6] = ~(1 << 31 | 1 << 30 | 1 << 29 | 1 << 28 |
  562. 1 << 27 | 1 << 26 | 1 << 25 | 1 << 24);
  563. /* disable most machine checks */
  564. cr_parms.orvals[14] = 0;
  565. cr_parms.andvals[14] = ~(1 << 28 | 1 << 27 | 1 << 26 |
  566. 1 << 25 | 1 << 24);
  567. smp_ctl_bit_callback(&cr_parms);
  568. return 0;
  569. }
  570. void __cpu_die(unsigned int cpu)
  571. {
  572. /* Wait until target cpu is down */
  573. while (!cpu_stopped(cpu))
  574. cpu_relax();
  575. while (sigp_p(0, cpu, sigp_set_prefix) == sigp_busy)
  576. udelay(10);
  577. smp_free_lowcore(cpu);
  578. pr_info("Processor %d stopped\n", cpu);
  579. }
  580. void cpu_die(void)
  581. {
  582. idle_task_exit();
  583. while (sigp(smp_processor_id(), sigp_stop) == sigp_busy)
  584. cpu_relax();
  585. for (;;);
  586. }
  587. #endif /* CONFIG_HOTPLUG_CPU */
  588. void __init smp_prepare_cpus(unsigned int max_cpus)
  589. {
  590. #ifndef CONFIG_64BIT
  591. unsigned long save_area = 0;
  592. #endif
  593. unsigned long async_stack, panic_stack;
  594. struct _lowcore *lowcore;
  595. unsigned int cpu;
  596. smp_detect_cpus();
  597. /* request the 0x1201 emergency signal external interrupt */
  598. if (register_external_interrupt(0x1201, do_ext_call_interrupt) != 0)
  599. panic("Couldn't request external interrupt 0x1201");
  600. print_cpu_info();
  601. /* Reallocate current lowcore, but keep its contents. */
  602. lowcore = (void *) __get_free_pages(GFP_KERNEL | GFP_DMA, LC_ORDER);
  603. panic_stack = __get_free_page(GFP_KERNEL);
  604. async_stack = __get_free_pages(GFP_KERNEL, ASYNC_ORDER);
  605. BUG_ON(!lowcore || !panic_stack || !async_stack);
  606. #ifndef CONFIG_64BIT
  607. if (MACHINE_HAS_IEEE)
  608. save_area = get_zeroed_page(GFP_KERNEL);
  609. #endif
  610. local_irq_disable();
  611. local_mcck_disable();
  612. lowcore_ptr[smp_processor_id()] = lowcore;
  613. *lowcore = S390_lowcore;
  614. lowcore->panic_stack = panic_stack + PAGE_SIZE;
  615. lowcore->async_stack = async_stack + ASYNC_SIZE;
  616. #ifndef CONFIG_64BIT
  617. if (MACHINE_HAS_IEEE)
  618. lowcore->extended_save_area_addr = (u32) save_area;
  619. #endif
  620. set_prefix((u32)(unsigned long) lowcore);
  621. local_mcck_enable();
  622. local_irq_enable();
  623. #ifdef CONFIG_64BIT
  624. if (vdso_alloc_per_cpu(smp_processor_id(), &S390_lowcore))
  625. BUG();
  626. #endif
  627. for_each_possible_cpu(cpu)
  628. if (cpu != smp_processor_id())
  629. smp_create_idle(cpu);
  630. }
  631. void __init smp_prepare_boot_cpu(void)
  632. {
  633. BUG_ON(smp_processor_id() != 0);
  634. current_thread_info()->cpu = 0;
  635. cpu_set(0, cpu_present_map);
  636. cpu_set(0, cpu_online_map);
  637. S390_lowcore.percpu_offset = __per_cpu_offset[0];
  638. current_set[0] = current;
  639. smp_cpu_state[0] = CPU_STATE_CONFIGURED;
  640. smp_cpu_polarization[0] = POLARIZATION_UNKNWN;
  641. }
  642. void __init smp_cpus_done(unsigned int max_cpus)
  643. {
  644. }
  645. void __init smp_setup_processor_id(void)
  646. {
  647. S390_lowcore.cpu_nr = 0;
  648. __cpu_logical_map[0] = stap();
  649. }
  650. /*
  651. * the frequency of the profiling timer can be changed
  652. * by writing a multiplier value into /proc/profile.
  653. *
  654. * usually you want to run this on all CPUs ;)
  655. */
  656. int setup_profiling_timer(unsigned int multiplier)
  657. {
  658. return 0;
  659. }
  660. #ifdef CONFIG_HOTPLUG_CPU
  661. static ssize_t cpu_configure_show(struct sys_device *dev,
  662. struct sysdev_attribute *attr, char *buf)
  663. {
  664. ssize_t count;
  665. mutex_lock(&smp_cpu_state_mutex);
  666. count = sprintf(buf, "%d\n", smp_cpu_state[dev->id]);
  667. mutex_unlock(&smp_cpu_state_mutex);
  668. return count;
  669. }
  670. static ssize_t cpu_configure_store(struct sys_device *dev,
  671. struct sysdev_attribute *attr,
  672. const char *buf, size_t count)
  673. {
  674. int cpu = dev->id;
  675. int val, rc;
  676. char delim;
  677. if (sscanf(buf, "%d %c", &val, &delim) != 1)
  678. return -EINVAL;
  679. if (val != 0 && val != 1)
  680. return -EINVAL;
  681. get_online_cpus();
  682. mutex_lock(&smp_cpu_state_mutex);
  683. rc = -EBUSY;
  684. /* disallow configuration changes of online cpus and cpu 0 */
  685. if (cpu_online(cpu) || cpu == 0)
  686. goto out;
  687. rc = 0;
  688. switch (val) {
  689. case 0:
  690. if (smp_cpu_state[cpu] == CPU_STATE_CONFIGURED) {
  691. rc = sclp_cpu_deconfigure(__cpu_logical_map[cpu]);
  692. if (!rc) {
  693. smp_cpu_state[cpu] = CPU_STATE_STANDBY;
  694. smp_cpu_polarization[cpu] = POLARIZATION_UNKNWN;
  695. }
  696. }
  697. break;
  698. case 1:
  699. if (smp_cpu_state[cpu] == CPU_STATE_STANDBY) {
  700. rc = sclp_cpu_configure(__cpu_logical_map[cpu]);
  701. if (!rc) {
  702. smp_cpu_state[cpu] = CPU_STATE_CONFIGURED;
  703. smp_cpu_polarization[cpu] = POLARIZATION_UNKNWN;
  704. }
  705. }
  706. break;
  707. default:
  708. break;
  709. }
  710. out:
  711. mutex_unlock(&smp_cpu_state_mutex);
  712. put_online_cpus();
  713. return rc ? rc : count;
  714. }
  715. static SYSDEV_ATTR(configure, 0644, cpu_configure_show, cpu_configure_store);
  716. #endif /* CONFIG_HOTPLUG_CPU */
  717. static ssize_t cpu_polarization_show(struct sys_device *dev,
  718. struct sysdev_attribute *attr, char *buf)
  719. {
  720. int cpu = dev->id;
  721. ssize_t count;
  722. mutex_lock(&smp_cpu_state_mutex);
  723. switch (smp_cpu_polarization[cpu]) {
  724. case POLARIZATION_HRZ:
  725. count = sprintf(buf, "horizontal\n");
  726. break;
  727. case POLARIZATION_VL:
  728. count = sprintf(buf, "vertical:low\n");
  729. break;
  730. case POLARIZATION_VM:
  731. count = sprintf(buf, "vertical:medium\n");
  732. break;
  733. case POLARIZATION_VH:
  734. count = sprintf(buf, "vertical:high\n");
  735. break;
  736. default:
  737. count = sprintf(buf, "unknown\n");
  738. break;
  739. }
  740. mutex_unlock(&smp_cpu_state_mutex);
  741. return count;
  742. }
  743. static SYSDEV_ATTR(polarization, 0444, cpu_polarization_show, NULL);
  744. static ssize_t show_cpu_address(struct sys_device *dev,
  745. struct sysdev_attribute *attr, char *buf)
  746. {
  747. return sprintf(buf, "%d\n", __cpu_logical_map[dev->id]);
  748. }
  749. static SYSDEV_ATTR(address, 0444, show_cpu_address, NULL);
  750. static struct attribute *cpu_common_attrs[] = {
  751. #ifdef CONFIG_HOTPLUG_CPU
  752. &attr_configure.attr,
  753. #endif
  754. &attr_address.attr,
  755. &attr_polarization.attr,
  756. NULL,
  757. };
  758. static struct attribute_group cpu_common_attr_group = {
  759. .attrs = cpu_common_attrs,
  760. };
  761. static ssize_t show_capability(struct sys_device *dev,
  762. struct sysdev_attribute *attr, char *buf)
  763. {
  764. unsigned int capability;
  765. int rc;
  766. rc = get_cpu_capability(&capability);
  767. if (rc)
  768. return rc;
  769. return sprintf(buf, "%u\n", capability);
  770. }
  771. static SYSDEV_ATTR(capability, 0444, show_capability, NULL);
  772. static ssize_t show_idle_count(struct sys_device *dev,
  773. struct sysdev_attribute *attr, char *buf)
  774. {
  775. struct s390_idle_data *idle;
  776. unsigned long long idle_count;
  777. unsigned int sequence;
  778. idle = &per_cpu(s390_idle, dev->id);
  779. repeat:
  780. sequence = idle->sequence;
  781. smp_rmb();
  782. if (sequence & 1)
  783. goto repeat;
  784. idle_count = idle->idle_count;
  785. if (idle->idle_enter)
  786. idle_count++;
  787. smp_rmb();
  788. if (idle->sequence != sequence)
  789. goto repeat;
  790. return sprintf(buf, "%llu\n", idle_count);
  791. }
  792. static SYSDEV_ATTR(idle_count, 0444, show_idle_count, NULL);
  793. static ssize_t show_idle_time(struct sys_device *dev,
  794. struct sysdev_attribute *attr, char *buf)
  795. {
  796. struct s390_idle_data *idle;
  797. unsigned long long now, idle_time, idle_enter;
  798. unsigned int sequence;
  799. idle = &per_cpu(s390_idle, dev->id);
  800. now = get_clock();
  801. repeat:
  802. sequence = idle->sequence;
  803. smp_rmb();
  804. if (sequence & 1)
  805. goto repeat;
  806. idle_time = idle->idle_time;
  807. idle_enter = idle->idle_enter;
  808. if (idle_enter != 0ULL && idle_enter < now)
  809. idle_time += now - idle_enter;
  810. smp_rmb();
  811. if (idle->sequence != sequence)
  812. goto repeat;
  813. return sprintf(buf, "%llu\n", idle_time >> 12);
  814. }
  815. static SYSDEV_ATTR(idle_time_us, 0444, show_idle_time, NULL);
  816. static struct attribute *cpu_online_attrs[] = {
  817. &attr_capability.attr,
  818. &attr_idle_count.attr,
  819. &attr_idle_time_us.attr,
  820. NULL,
  821. };
  822. static struct attribute_group cpu_online_attr_group = {
  823. .attrs = cpu_online_attrs,
  824. };
  825. static int __cpuinit smp_cpu_notify(struct notifier_block *self,
  826. unsigned long action, void *hcpu)
  827. {
  828. unsigned int cpu = (unsigned int)(long)hcpu;
  829. struct cpu *c = &per_cpu(cpu_devices, cpu);
  830. struct sys_device *s = &c->sysdev;
  831. struct s390_idle_data *idle;
  832. switch (action) {
  833. case CPU_ONLINE:
  834. case CPU_ONLINE_FROZEN:
  835. idle = &per_cpu(s390_idle, cpu);
  836. memset(idle, 0, sizeof(struct s390_idle_data));
  837. if (sysfs_create_group(&s->kobj, &cpu_online_attr_group))
  838. return NOTIFY_BAD;
  839. break;
  840. case CPU_DEAD:
  841. case CPU_DEAD_FROZEN:
  842. sysfs_remove_group(&s->kobj, &cpu_online_attr_group);
  843. break;
  844. }
  845. return NOTIFY_OK;
  846. }
  847. static struct notifier_block __cpuinitdata smp_cpu_nb = {
  848. .notifier_call = smp_cpu_notify,
  849. };
  850. static int __devinit smp_add_present_cpu(int cpu)
  851. {
  852. struct cpu *c = &per_cpu(cpu_devices, cpu);
  853. struct sys_device *s = &c->sysdev;
  854. int rc;
  855. c->hotpluggable = 1;
  856. rc = register_cpu(c, cpu);
  857. if (rc)
  858. goto out;
  859. rc = sysfs_create_group(&s->kobj, &cpu_common_attr_group);
  860. if (rc)
  861. goto out_cpu;
  862. if (!cpu_online(cpu))
  863. goto out;
  864. rc = sysfs_create_group(&s->kobj, &cpu_online_attr_group);
  865. if (!rc)
  866. return 0;
  867. sysfs_remove_group(&s->kobj, &cpu_common_attr_group);
  868. out_cpu:
  869. #ifdef CONFIG_HOTPLUG_CPU
  870. unregister_cpu(c);
  871. #endif
  872. out:
  873. return rc;
  874. }
  875. #ifdef CONFIG_HOTPLUG_CPU
  876. int __ref smp_rescan_cpus(void)
  877. {
  878. cpumask_t newcpus;
  879. int cpu;
  880. int rc;
  881. get_online_cpus();
  882. mutex_lock(&smp_cpu_state_mutex);
  883. newcpus = cpu_present_map;
  884. rc = __smp_rescan_cpus();
  885. if (rc)
  886. goto out;
  887. cpus_andnot(newcpus, cpu_present_map, newcpus);
  888. for_each_cpu_mask(cpu, newcpus) {
  889. rc = smp_add_present_cpu(cpu);
  890. if (rc)
  891. cpu_clear(cpu, cpu_present_map);
  892. }
  893. rc = 0;
  894. out:
  895. mutex_unlock(&smp_cpu_state_mutex);
  896. put_online_cpus();
  897. if (!cpus_empty(newcpus))
  898. topology_schedule_update();
  899. return rc;
  900. }
  901. static ssize_t __ref rescan_store(struct sysdev_class *class,
  902. struct sysdev_class_attribute *attr,
  903. const char *buf,
  904. size_t count)
  905. {
  906. int rc;
  907. rc = smp_rescan_cpus();
  908. return rc ? rc : count;
  909. }
  910. static SYSDEV_CLASS_ATTR(rescan, 0200, NULL, rescan_store);
  911. #endif /* CONFIG_HOTPLUG_CPU */
  912. static ssize_t dispatching_show(struct sysdev_class *class,
  913. struct sysdev_class_attribute *attr,
  914. char *buf)
  915. {
  916. ssize_t count;
  917. mutex_lock(&smp_cpu_state_mutex);
  918. count = sprintf(buf, "%d\n", cpu_management);
  919. mutex_unlock(&smp_cpu_state_mutex);
  920. return count;
  921. }
  922. static ssize_t dispatching_store(struct sysdev_class *dev,
  923. struct sysdev_class_attribute *attr,
  924. const char *buf,
  925. size_t count)
  926. {
  927. int val, rc;
  928. char delim;
  929. if (sscanf(buf, "%d %c", &val, &delim) != 1)
  930. return -EINVAL;
  931. if (val != 0 && val != 1)
  932. return -EINVAL;
  933. rc = 0;
  934. get_online_cpus();
  935. mutex_lock(&smp_cpu_state_mutex);
  936. if (cpu_management == val)
  937. goto out;
  938. rc = topology_set_cpu_management(val);
  939. if (!rc)
  940. cpu_management = val;
  941. out:
  942. mutex_unlock(&smp_cpu_state_mutex);
  943. put_online_cpus();
  944. return rc ? rc : count;
  945. }
  946. static SYSDEV_CLASS_ATTR(dispatching, 0644, dispatching_show,
  947. dispatching_store);
  948. static int __init topology_init(void)
  949. {
  950. int cpu;
  951. int rc;
  952. register_cpu_notifier(&smp_cpu_nb);
  953. #ifdef CONFIG_HOTPLUG_CPU
  954. rc = sysdev_class_create_file(&cpu_sysdev_class, &attr_rescan);
  955. if (rc)
  956. return rc;
  957. #endif
  958. rc = sysdev_class_create_file(&cpu_sysdev_class, &attr_dispatching);
  959. if (rc)
  960. return rc;
  961. for_each_present_cpu(cpu) {
  962. rc = smp_add_present_cpu(cpu);
  963. if (rc)
  964. return rc;
  965. }
  966. return 0;
  967. }
  968. subsys_initcall(topology_init);