smp.c 24 KB

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