smp.c 18 KB

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