smp.c 18 KB

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