smp.c 20 KB

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