smp.c 25 KB

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