smp.c 20 KB

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