smp.c 19 KB

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