smp.c 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052
  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. /* Enable cpu timer interrupts on the secondary cpu. */
  388. init_cpu_vtimer();
  389. /* Enable pfault pseudo page faults on this cpu. */
  390. pfault_init();
  391. /* call cpu notifiers */
  392. notify_cpu_starting(smp_processor_id());
  393. /* Mark this cpu as online */
  394. ipi_call_lock();
  395. cpu_set(smp_processor_id(), cpu_online_map);
  396. ipi_call_unlock();
  397. /* Switch on interrupts */
  398. local_irq_enable();
  399. /* Print info about this processor */
  400. print_cpu_info(&S390_lowcore.cpu_data);
  401. /* cpu_idle will call schedule for us */
  402. cpu_idle();
  403. return 0;
  404. }
  405. static void __init smp_create_idle(unsigned int cpu)
  406. {
  407. struct task_struct *p;
  408. /*
  409. * don't care about the psw and regs settings since we'll never
  410. * reschedule the forked task.
  411. */
  412. p = fork_idle(cpu);
  413. if (IS_ERR(p))
  414. panic("failed fork for CPU %u: %li", cpu, PTR_ERR(p));
  415. current_set[cpu] = p;
  416. }
  417. static int __cpuinit smp_alloc_lowcore(int cpu)
  418. {
  419. unsigned long async_stack, panic_stack;
  420. struct _lowcore *lowcore;
  421. int lc_order;
  422. lc_order = sizeof(long) == 8 ? 1 : 0;
  423. lowcore = (void *) __get_free_pages(GFP_KERNEL | GFP_DMA, lc_order);
  424. if (!lowcore)
  425. return -ENOMEM;
  426. async_stack = __get_free_pages(GFP_KERNEL, ASYNC_ORDER);
  427. panic_stack = __get_free_page(GFP_KERNEL);
  428. if (!panic_stack || !async_stack)
  429. goto out;
  430. memcpy(lowcore, &S390_lowcore, 512);
  431. memset((char *)lowcore + 512, 0, sizeof(*lowcore) - 512);
  432. lowcore->async_stack = async_stack + ASYNC_SIZE;
  433. lowcore->panic_stack = panic_stack + PAGE_SIZE;
  434. #ifndef CONFIG_64BIT
  435. if (MACHINE_HAS_IEEE) {
  436. unsigned long save_area;
  437. save_area = get_zeroed_page(GFP_KERNEL);
  438. if (!save_area)
  439. goto out_save_area;
  440. lowcore->extended_save_area_addr = (u32) save_area;
  441. }
  442. #endif
  443. lowcore_ptr[cpu] = lowcore;
  444. return 0;
  445. #ifndef CONFIG_64BIT
  446. out_save_area:
  447. free_page(panic_stack);
  448. #endif
  449. out:
  450. free_pages(async_stack, ASYNC_ORDER);
  451. free_pages((unsigned long) lowcore, lc_order);
  452. return -ENOMEM;
  453. }
  454. #ifdef CONFIG_HOTPLUG_CPU
  455. static void smp_free_lowcore(int cpu)
  456. {
  457. struct _lowcore *lowcore;
  458. int lc_order;
  459. lc_order = sizeof(long) == 8 ? 1 : 0;
  460. lowcore = lowcore_ptr[cpu];
  461. #ifndef CONFIG_64BIT
  462. if (MACHINE_HAS_IEEE)
  463. free_page((unsigned long) lowcore->extended_save_area_addr);
  464. #endif
  465. free_page(lowcore->panic_stack - PAGE_SIZE);
  466. free_pages(lowcore->async_stack - ASYNC_SIZE, ASYNC_ORDER);
  467. free_pages((unsigned long) lowcore, lc_order);
  468. lowcore_ptr[cpu] = NULL;
  469. }
  470. #endif /* CONFIG_HOTPLUG_CPU */
  471. /* Upping and downing of CPUs */
  472. int __cpuinit __cpu_up(unsigned int cpu)
  473. {
  474. struct task_struct *idle;
  475. struct _lowcore *cpu_lowcore;
  476. struct stack_frame *sf;
  477. sigp_ccode ccode;
  478. if (smp_cpu_state[cpu] != CPU_STATE_CONFIGURED)
  479. return -EIO;
  480. if (smp_alloc_lowcore(cpu))
  481. return -ENOMEM;
  482. ccode = signal_processor_p((__u32)(unsigned long)(lowcore_ptr[cpu]),
  483. cpu, sigp_set_prefix);
  484. if (ccode) {
  485. printk("sigp_set_prefix failed for cpu %d "
  486. "with condition code %d\n",
  487. (int) cpu, (int) ccode);
  488. return -EIO;
  489. }
  490. idle = current_set[cpu];
  491. cpu_lowcore = lowcore_ptr[cpu];
  492. cpu_lowcore->kernel_stack = (unsigned long)
  493. task_stack_page(idle) + THREAD_SIZE;
  494. cpu_lowcore->thread_info = (unsigned long) task_thread_info(idle);
  495. sf = (struct stack_frame *) (cpu_lowcore->kernel_stack
  496. - sizeof(struct pt_regs)
  497. - sizeof(struct stack_frame));
  498. memset(sf, 0, sizeof(struct stack_frame));
  499. sf->gprs[9] = (unsigned long) sf;
  500. cpu_lowcore->save_area[15] = (unsigned long) sf;
  501. __ctl_store(cpu_lowcore->cregs_save_area, 0, 15);
  502. asm volatile(
  503. " stam 0,15,0(%0)"
  504. : : "a" (&cpu_lowcore->access_regs_save_area) : "memory");
  505. cpu_lowcore->percpu_offset = __per_cpu_offset[cpu];
  506. cpu_lowcore->current_task = (unsigned long) idle;
  507. cpu_lowcore->cpu_data.cpu_nr = cpu;
  508. cpu_lowcore->kernel_asce = S390_lowcore.kernel_asce;
  509. cpu_lowcore->ipl_device = S390_lowcore.ipl_device;
  510. eieio();
  511. while (signal_processor(cpu, sigp_restart) == sigp_busy)
  512. udelay(10);
  513. while (!cpu_online(cpu))
  514. cpu_relax();
  515. return 0;
  516. }
  517. static int __init setup_possible_cpus(char *s)
  518. {
  519. int pcpus, cpu;
  520. pcpus = simple_strtoul(s, NULL, 0);
  521. cpu_possible_map = cpumask_of_cpu(0);
  522. for (cpu = 1; cpu < pcpus && cpu < NR_CPUS; cpu++)
  523. cpu_set(cpu, cpu_possible_map);
  524. return 0;
  525. }
  526. early_param("possible_cpus", setup_possible_cpus);
  527. #ifdef CONFIG_HOTPLUG_CPU
  528. int __cpu_disable(void)
  529. {
  530. struct ec_creg_mask_parms cr_parms;
  531. int cpu = smp_processor_id();
  532. cpu_clear(cpu, cpu_online_map);
  533. /* Disable pfault pseudo page faults on this cpu. */
  534. pfault_fini();
  535. memset(&cr_parms.orvals, 0, sizeof(cr_parms.orvals));
  536. memset(&cr_parms.andvals, 0xff, sizeof(cr_parms.andvals));
  537. /* disable all external interrupts */
  538. cr_parms.orvals[0] = 0;
  539. cr_parms.andvals[0] = ~(1 << 15 | 1 << 14 | 1 << 13 | 1 << 12 |
  540. 1 << 11 | 1 << 10 | 1 << 6 | 1 << 4);
  541. /* disable all I/O interrupts */
  542. cr_parms.orvals[6] = 0;
  543. cr_parms.andvals[6] = ~(1 << 31 | 1 << 30 | 1 << 29 | 1 << 28 |
  544. 1 << 27 | 1 << 26 | 1 << 25 | 1 << 24);
  545. /* disable most machine checks */
  546. cr_parms.orvals[14] = 0;
  547. cr_parms.andvals[14] = ~(1 << 28 | 1 << 27 | 1 << 26 |
  548. 1 << 25 | 1 << 24);
  549. smp_ctl_bit_callback(&cr_parms);
  550. return 0;
  551. }
  552. void __cpu_die(unsigned int cpu)
  553. {
  554. /* Wait until target cpu is down */
  555. while (!smp_cpu_not_running(cpu))
  556. cpu_relax();
  557. smp_free_lowcore(cpu);
  558. printk(KERN_INFO "Processor %d spun down\n", cpu);
  559. }
  560. void cpu_die(void)
  561. {
  562. idle_task_exit();
  563. signal_processor(smp_processor_id(), sigp_stop);
  564. BUG();
  565. for (;;);
  566. }
  567. #endif /* CONFIG_HOTPLUG_CPU */
  568. void __init smp_prepare_cpus(unsigned int max_cpus)
  569. {
  570. #ifndef CONFIG_64BIT
  571. unsigned long save_area = 0;
  572. #endif
  573. unsigned long async_stack, panic_stack;
  574. struct _lowcore *lowcore;
  575. unsigned int cpu;
  576. int lc_order;
  577. smp_detect_cpus();
  578. /* request the 0x1201 emergency signal external interrupt */
  579. if (register_external_interrupt(0x1201, do_ext_call_interrupt) != 0)
  580. panic("Couldn't request external interrupt 0x1201");
  581. print_cpu_info(&S390_lowcore.cpu_data);
  582. /* Reallocate current lowcore, but keep its contents. */
  583. lc_order = sizeof(long) == 8 ? 1 : 0;
  584. lowcore = (void *) __get_free_pages(GFP_KERNEL | GFP_DMA, lc_order);
  585. panic_stack = __get_free_page(GFP_KERNEL);
  586. async_stack = __get_free_pages(GFP_KERNEL, ASYNC_ORDER);
  587. #ifndef CONFIG_64BIT
  588. if (MACHINE_HAS_IEEE)
  589. save_area = get_zeroed_page(GFP_KERNEL);
  590. #endif
  591. local_irq_disable();
  592. local_mcck_disable();
  593. lowcore_ptr[smp_processor_id()] = lowcore;
  594. *lowcore = S390_lowcore;
  595. lowcore->panic_stack = panic_stack + PAGE_SIZE;
  596. lowcore->async_stack = async_stack + ASYNC_SIZE;
  597. #ifndef CONFIG_64BIT
  598. if (MACHINE_HAS_IEEE)
  599. lowcore->extended_save_area_addr = (u32) save_area;
  600. #endif
  601. set_prefix((u32)(unsigned long) lowcore);
  602. local_mcck_enable();
  603. local_irq_enable();
  604. for_each_possible_cpu(cpu)
  605. if (cpu != smp_processor_id())
  606. smp_create_idle(cpu);
  607. }
  608. void __init smp_prepare_boot_cpu(void)
  609. {
  610. BUG_ON(smp_processor_id() != 0);
  611. current_thread_info()->cpu = 0;
  612. cpu_set(0, cpu_present_map);
  613. cpu_set(0, cpu_online_map);
  614. S390_lowcore.percpu_offset = __per_cpu_offset[0];
  615. current_set[0] = current;
  616. smp_cpu_state[0] = CPU_STATE_CONFIGURED;
  617. smp_cpu_polarization[0] = POLARIZATION_UNKNWN;
  618. }
  619. void __init smp_cpus_done(unsigned int max_cpus)
  620. {
  621. }
  622. /*
  623. * the frequency of the profiling timer can be changed
  624. * by writing a multiplier value into /proc/profile.
  625. *
  626. * usually you want to run this on all CPUs ;)
  627. */
  628. int setup_profiling_timer(unsigned int multiplier)
  629. {
  630. return 0;
  631. }
  632. #ifdef CONFIG_HOTPLUG_CPU
  633. static ssize_t cpu_configure_show(struct sys_device *dev,
  634. struct sysdev_attribute *attr, char *buf)
  635. {
  636. ssize_t count;
  637. mutex_lock(&smp_cpu_state_mutex);
  638. count = sprintf(buf, "%d\n", smp_cpu_state[dev->id]);
  639. mutex_unlock(&smp_cpu_state_mutex);
  640. return count;
  641. }
  642. static ssize_t cpu_configure_store(struct sys_device *dev,
  643. struct sysdev_attribute *attr,
  644. const char *buf, size_t count)
  645. {
  646. int cpu = dev->id;
  647. int val, rc;
  648. char delim;
  649. if (sscanf(buf, "%d %c", &val, &delim) != 1)
  650. return -EINVAL;
  651. if (val != 0 && val != 1)
  652. return -EINVAL;
  653. get_online_cpus();
  654. mutex_lock(&smp_cpu_state_mutex);
  655. rc = -EBUSY;
  656. if (cpu_online(cpu))
  657. goto out;
  658. rc = 0;
  659. switch (val) {
  660. case 0:
  661. if (smp_cpu_state[cpu] == CPU_STATE_CONFIGURED) {
  662. rc = sclp_cpu_deconfigure(__cpu_logical_map[cpu]);
  663. if (!rc) {
  664. smp_cpu_state[cpu] = CPU_STATE_STANDBY;
  665. smp_cpu_polarization[cpu] = POLARIZATION_UNKNWN;
  666. }
  667. }
  668. break;
  669. case 1:
  670. if (smp_cpu_state[cpu] == CPU_STATE_STANDBY) {
  671. rc = sclp_cpu_configure(__cpu_logical_map[cpu]);
  672. if (!rc) {
  673. smp_cpu_state[cpu] = CPU_STATE_CONFIGURED;
  674. smp_cpu_polarization[cpu] = POLARIZATION_UNKNWN;
  675. }
  676. }
  677. break;
  678. default:
  679. break;
  680. }
  681. out:
  682. mutex_unlock(&smp_cpu_state_mutex);
  683. put_online_cpus();
  684. return rc ? rc : count;
  685. }
  686. static SYSDEV_ATTR(configure, 0644, cpu_configure_show, cpu_configure_store);
  687. #endif /* CONFIG_HOTPLUG_CPU */
  688. static ssize_t cpu_polarization_show(struct sys_device *dev,
  689. struct sysdev_attribute *attr, char *buf)
  690. {
  691. int cpu = dev->id;
  692. ssize_t count;
  693. mutex_lock(&smp_cpu_state_mutex);
  694. switch (smp_cpu_polarization[cpu]) {
  695. case POLARIZATION_HRZ:
  696. count = sprintf(buf, "horizontal\n");
  697. break;
  698. case POLARIZATION_VL:
  699. count = sprintf(buf, "vertical:low\n");
  700. break;
  701. case POLARIZATION_VM:
  702. count = sprintf(buf, "vertical:medium\n");
  703. break;
  704. case POLARIZATION_VH:
  705. count = sprintf(buf, "vertical:high\n");
  706. break;
  707. default:
  708. count = sprintf(buf, "unknown\n");
  709. break;
  710. }
  711. mutex_unlock(&smp_cpu_state_mutex);
  712. return count;
  713. }
  714. static SYSDEV_ATTR(polarization, 0444, cpu_polarization_show, NULL);
  715. static ssize_t show_cpu_address(struct sys_device *dev,
  716. struct sysdev_attribute *attr, char *buf)
  717. {
  718. return sprintf(buf, "%d\n", __cpu_logical_map[dev->id]);
  719. }
  720. static SYSDEV_ATTR(address, 0444, show_cpu_address, NULL);
  721. static struct attribute *cpu_common_attrs[] = {
  722. #ifdef CONFIG_HOTPLUG_CPU
  723. &attr_configure.attr,
  724. #endif
  725. &attr_address.attr,
  726. &attr_polarization.attr,
  727. NULL,
  728. };
  729. static struct attribute_group cpu_common_attr_group = {
  730. .attrs = cpu_common_attrs,
  731. };
  732. static ssize_t show_capability(struct sys_device *dev,
  733. struct sysdev_attribute *attr, char *buf)
  734. {
  735. unsigned int capability;
  736. int rc;
  737. rc = get_cpu_capability(&capability);
  738. if (rc)
  739. return rc;
  740. return sprintf(buf, "%u\n", capability);
  741. }
  742. static SYSDEV_ATTR(capability, 0444, show_capability, NULL);
  743. static ssize_t show_idle_count(struct sys_device *dev,
  744. struct sysdev_attribute *attr, char *buf)
  745. {
  746. struct s390_idle_data *idle;
  747. unsigned long long idle_count;
  748. idle = &per_cpu(s390_idle, dev->id);
  749. spin_lock_irq(&idle->lock);
  750. idle_count = idle->idle_count;
  751. spin_unlock_irq(&idle->lock);
  752. return sprintf(buf, "%llu\n", idle_count);
  753. }
  754. static SYSDEV_ATTR(idle_count, 0444, show_idle_count, NULL);
  755. static ssize_t show_idle_time(struct sys_device *dev,
  756. struct sysdev_attribute *attr, char *buf)
  757. {
  758. struct s390_idle_data *idle;
  759. unsigned long long new_time;
  760. idle = &per_cpu(s390_idle, dev->id);
  761. spin_lock_irq(&idle->lock);
  762. if (idle->in_idle) {
  763. new_time = get_clock();
  764. idle->idle_time += new_time - idle->idle_enter;
  765. idle->idle_enter = new_time;
  766. }
  767. new_time = idle->idle_time;
  768. spin_unlock_irq(&idle->lock);
  769. return sprintf(buf, "%llu\n", new_time >> 12);
  770. }
  771. static SYSDEV_ATTR(idle_time_us, 0444, show_idle_time, NULL);
  772. static struct attribute *cpu_online_attrs[] = {
  773. &attr_capability.attr,
  774. &attr_idle_count.attr,
  775. &attr_idle_time_us.attr,
  776. NULL,
  777. };
  778. static struct attribute_group cpu_online_attr_group = {
  779. .attrs = cpu_online_attrs,
  780. };
  781. static int __cpuinit smp_cpu_notify(struct notifier_block *self,
  782. unsigned long action, void *hcpu)
  783. {
  784. unsigned int cpu = (unsigned int)(long)hcpu;
  785. struct cpu *c = &per_cpu(cpu_devices, cpu);
  786. struct sys_device *s = &c->sysdev;
  787. struct s390_idle_data *idle;
  788. switch (action) {
  789. case CPU_ONLINE:
  790. case CPU_ONLINE_FROZEN:
  791. idle = &per_cpu(s390_idle, cpu);
  792. spin_lock_irq(&idle->lock);
  793. idle->idle_enter = 0;
  794. idle->idle_time = 0;
  795. idle->idle_count = 0;
  796. spin_unlock_irq(&idle->lock);
  797. if (sysfs_create_group(&s->kobj, &cpu_online_attr_group))
  798. return NOTIFY_BAD;
  799. break;
  800. case CPU_DEAD:
  801. case CPU_DEAD_FROZEN:
  802. sysfs_remove_group(&s->kobj, &cpu_online_attr_group);
  803. break;
  804. }
  805. return NOTIFY_OK;
  806. }
  807. static struct notifier_block __cpuinitdata smp_cpu_nb = {
  808. .notifier_call = smp_cpu_notify,
  809. };
  810. static int __devinit smp_add_present_cpu(int cpu)
  811. {
  812. struct cpu *c = &per_cpu(cpu_devices, cpu);
  813. struct sys_device *s = &c->sysdev;
  814. int rc;
  815. c->hotpluggable = 1;
  816. rc = register_cpu(c, cpu);
  817. if (rc)
  818. goto out;
  819. rc = sysfs_create_group(&s->kobj, &cpu_common_attr_group);
  820. if (rc)
  821. goto out_cpu;
  822. if (!cpu_online(cpu))
  823. goto out;
  824. rc = sysfs_create_group(&s->kobj, &cpu_online_attr_group);
  825. if (!rc)
  826. return 0;
  827. sysfs_remove_group(&s->kobj, &cpu_common_attr_group);
  828. out_cpu:
  829. #ifdef CONFIG_HOTPLUG_CPU
  830. unregister_cpu(c);
  831. #endif
  832. out:
  833. return rc;
  834. }
  835. #ifdef CONFIG_HOTPLUG_CPU
  836. int __ref smp_rescan_cpus(void)
  837. {
  838. cpumask_t newcpus;
  839. int cpu;
  840. int rc;
  841. get_online_cpus();
  842. mutex_lock(&smp_cpu_state_mutex);
  843. newcpus = cpu_present_map;
  844. rc = __smp_rescan_cpus();
  845. if (rc)
  846. goto out;
  847. cpus_andnot(newcpus, cpu_present_map, newcpus);
  848. for_each_cpu_mask(cpu, newcpus) {
  849. rc = smp_add_present_cpu(cpu);
  850. if (rc)
  851. cpu_clear(cpu, cpu_present_map);
  852. }
  853. rc = 0;
  854. out:
  855. mutex_unlock(&smp_cpu_state_mutex);
  856. put_online_cpus();
  857. if (!cpus_empty(newcpus))
  858. topology_schedule_update();
  859. return rc;
  860. }
  861. static ssize_t __ref rescan_store(struct sysdev_class *class, const char *buf,
  862. size_t count)
  863. {
  864. int rc;
  865. rc = smp_rescan_cpus();
  866. return rc ? rc : count;
  867. }
  868. static SYSDEV_CLASS_ATTR(rescan, 0200, NULL, rescan_store);
  869. #endif /* CONFIG_HOTPLUG_CPU */
  870. static ssize_t dispatching_show(struct sysdev_class *class, char *buf)
  871. {
  872. ssize_t count;
  873. mutex_lock(&smp_cpu_state_mutex);
  874. count = sprintf(buf, "%d\n", cpu_management);
  875. mutex_unlock(&smp_cpu_state_mutex);
  876. return count;
  877. }
  878. static ssize_t dispatching_store(struct sysdev_class *dev, const char *buf,
  879. size_t count)
  880. {
  881. int val, rc;
  882. char delim;
  883. if (sscanf(buf, "%d %c", &val, &delim) != 1)
  884. return -EINVAL;
  885. if (val != 0 && val != 1)
  886. return -EINVAL;
  887. rc = 0;
  888. get_online_cpus();
  889. mutex_lock(&smp_cpu_state_mutex);
  890. if (cpu_management == val)
  891. goto out;
  892. rc = topology_set_cpu_management(val);
  893. if (!rc)
  894. cpu_management = val;
  895. out:
  896. mutex_unlock(&smp_cpu_state_mutex);
  897. put_online_cpus();
  898. return rc ? rc : count;
  899. }
  900. static SYSDEV_CLASS_ATTR(dispatching, 0644, dispatching_show,
  901. dispatching_store);
  902. static int __init topology_init(void)
  903. {
  904. int cpu;
  905. int rc;
  906. register_cpu_notifier(&smp_cpu_nb);
  907. #ifdef CONFIG_HOTPLUG_CPU
  908. rc = sysdev_class_create_file(&cpu_sysdev_class, &attr_rescan);
  909. if (rc)
  910. return rc;
  911. #endif
  912. rc = sysdev_class_create_file(&cpu_sysdev_class, &attr_dispatching);
  913. if (rc)
  914. return rc;
  915. for_each_present_cpu(cpu) {
  916. rc = smp_add_present_cpu(cpu);
  917. if (rc)
  918. return rc;
  919. }
  920. return 0;
  921. }
  922. subsys_initcall(topology_init);