smp.c 25 KB

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