smp.c 25 KB

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