smp.c 25 KB

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