smp.c 21 KB

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