smp.c 25 KB

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