smp.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  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/setup.h>
  34. #include <asm/sigp.h>
  35. #include <asm/pgalloc.h>
  36. #include <asm/irq.h>
  37. #include <asm/s390_ext.h>
  38. #include <asm/cpcmd.h>
  39. #include <asm/tlbflush.h>
  40. #include <asm/timer.h>
  41. extern volatile int __cpu_logical_map[];
  42. /*
  43. * An array with a pointer the lowcore of every CPU.
  44. */
  45. struct _lowcore *lowcore_ptr[NR_CPUS];
  46. cpumask_t cpu_online_map = CPU_MASK_NONE;
  47. cpumask_t cpu_possible_map = CPU_MASK_NONE;
  48. static struct task_struct *current_set[NR_CPUS];
  49. static void smp_ext_bitcall(int, ec_bit_sig);
  50. static void smp_ext_bitcall_others(ec_bit_sig);
  51. /*
  52. * Structure and data for smp_call_function(). This is designed to minimise
  53. * 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. atomic_t started;
  60. atomic_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. atomic_inc(&call_data->started);
  73. (*func)(info);
  74. if (wait)
  75. atomic_inc(&call_data->finished);
  76. }
  77. /*
  78. * this function sends a 'generic call function' IPI to all other CPUs
  79. * in the system.
  80. */
  81. int smp_call_function (void (*func) (void *info), void *info, int nonatomic,
  82. int wait)
  83. /*
  84. * [SUMMARY] Run a function on all other CPUs.
  85. * <func> The function to run. This must be fast and non-blocking.
  86. * <info> An arbitrary pointer to pass to the function.
  87. * <nonatomic> currently unused.
  88. * <wait> If true, wait (atomically) until function has completed on other CPUs.
  89. * [RETURNS] 0 on success, else a negative status code. Does not return until
  90. * remote CPUs are nearly ready to execute <<func>> or are or have executed.
  91. *
  92. * You must not call this function with disabled interrupts or from a
  93. * hardware interrupt handler.
  94. */
  95. {
  96. struct call_data_struct data;
  97. int cpus = num_online_cpus()-1;
  98. if (cpus <= 0)
  99. return 0;
  100. /* Can deadlock when interrupts are disabled or if in wrong context */
  101. WARN_ON(irqs_disabled() || in_irq());
  102. data.func = func;
  103. data.info = info;
  104. atomic_set(&data.started, 0);
  105. data.wait = wait;
  106. if (wait)
  107. atomic_set(&data.finished, 0);
  108. spin_lock_bh(&call_lock);
  109. call_data = &data;
  110. /* Send a message to all other CPUs and wait for them to respond */
  111. smp_ext_bitcall_others(ec_call_function);
  112. /* Wait for response */
  113. while (atomic_read(&data.started) != cpus)
  114. cpu_relax();
  115. if (wait)
  116. while (atomic_read(&data.finished) != cpus)
  117. cpu_relax();
  118. spin_unlock_bh(&call_lock);
  119. return 0;
  120. }
  121. /*
  122. * Call a function on one CPU
  123. * cpu : the CPU the function should be executed on
  124. *
  125. * You must not call this function with disabled interrupts or from a
  126. * hardware interrupt handler. You may call it from a bottom half.
  127. *
  128. * It is guaranteed that the called function runs on the specified CPU,
  129. * preemption is disabled.
  130. */
  131. int smp_call_function_on(void (*func) (void *info), void *info,
  132. int nonatomic, int wait, int cpu)
  133. {
  134. struct call_data_struct data;
  135. int curr_cpu;
  136. if (!cpu_online(cpu))
  137. return -EINVAL;
  138. /* Can deadlock when interrupts are disabled or if in wrong context */
  139. WARN_ON(irqs_disabled() || in_irq());
  140. /* disable preemption for local function call */
  141. curr_cpu = get_cpu();
  142. if (curr_cpu == cpu) {
  143. /* direct call to function */
  144. func(info);
  145. put_cpu();
  146. return 0;
  147. }
  148. data.func = func;
  149. data.info = info;
  150. atomic_set(&data.started, 0);
  151. data.wait = wait;
  152. if (wait)
  153. atomic_set(&data.finished, 0);
  154. spin_lock_bh(&call_lock);
  155. call_data = &data;
  156. smp_ext_bitcall(cpu, ec_call_function);
  157. /* Wait for response */
  158. while (atomic_read(&data.started) != 1)
  159. cpu_relax();
  160. if (wait)
  161. while (atomic_read(&data.finished) != 1)
  162. cpu_relax();
  163. spin_unlock_bh(&call_lock);
  164. put_cpu();
  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. /*
  277. * Send an external call sigp to every other cpu in the system and
  278. * return without waiting for its completion.
  279. */
  280. static void smp_ext_bitcall_others(ec_bit_sig sig)
  281. {
  282. int cpu;
  283. for_each_online_cpu(cpu) {
  284. if (cpu == smp_processor_id())
  285. continue;
  286. /*
  287. * Set signaling bit in lowcore of target cpu and kick it
  288. */
  289. set_bit(sig, (unsigned long *) &lowcore_ptr[cpu]->ext_call_fast);
  290. while (signal_processor(cpu, sigp_emergency_signal) == sigp_busy)
  291. udelay(10);
  292. }
  293. }
  294. #ifndef CONFIG_64BIT
  295. /*
  296. * this function sends a 'purge tlb' signal to another CPU.
  297. */
  298. void smp_ptlb_callback(void *info)
  299. {
  300. local_flush_tlb();
  301. }
  302. void smp_ptlb_all(void)
  303. {
  304. on_each_cpu(smp_ptlb_callback, NULL, 0, 1);
  305. }
  306. EXPORT_SYMBOL(smp_ptlb_all);
  307. #endif /* ! CONFIG_64BIT */
  308. /*
  309. * this function sends a 'reschedule' IPI to another CPU.
  310. * it goes straight through and wastes no time serializing
  311. * anything. Worst case is that we lose a reschedule ...
  312. */
  313. void smp_send_reschedule(int cpu)
  314. {
  315. smp_ext_bitcall(cpu, ec_schedule);
  316. }
  317. /*
  318. * parameter area for the set/clear control bit callbacks
  319. */
  320. struct ec_creg_mask_parms {
  321. unsigned long orvals[16];
  322. unsigned long andvals[16];
  323. };
  324. /*
  325. * callback for setting/clearing control bits
  326. */
  327. static void smp_ctl_bit_callback(void *info) {
  328. struct ec_creg_mask_parms *pp = info;
  329. unsigned long cregs[16];
  330. int i;
  331. __ctl_store(cregs, 0, 15);
  332. for (i = 0; i <= 15; i++)
  333. cregs[i] = (cregs[i] & pp->andvals[i]) | pp->orvals[i];
  334. __ctl_load(cregs, 0, 15);
  335. }
  336. /*
  337. * Set a bit in a control register of all cpus
  338. */
  339. void smp_ctl_set_bit(int cr, int bit)
  340. {
  341. struct ec_creg_mask_parms parms;
  342. memset(&parms.orvals, 0, sizeof(parms.orvals));
  343. memset(&parms.andvals, 0xff, sizeof(parms.andvals));
  344. parms.orvals[cr] = 1 << bit;
  345. on_each_cpu(smp_ctl_bit_callback, &parms, 0, 1);
  346. }
  347. /*
  348. * Clear a bit in a control register of all cpus
  349. */
  350. void smp_ctl_clear_bit(int cr, int bit)
  351. {
  352. struct ec_creg_mask_parms parms;
  353. memset(&parms.orvals, 0, sizeof(parms.orvals));
  354. memset(&parms.andvals, 0xff, sizeof(parms.andvals));
  355. parms.andvals[cr] = ~(1L << bit);
  356. on_each_cpu(smp_ctl_bit_callback, &parms, 0, 1);
  357. }
  358. /*
  359. * Lets check how many CPUs we have.
  360. */
  361. static unsigned int
  362. __init smp_count_cpus(void)
  363. {
  364. unsigned int cpu, num_cpus;
  365. __u16 boot_cpu_addr;
  366. /*
  367. * cpu 0 is the boot cpu. See smp_prepare_boot_cpu.
  368. */
  369. boot_cpu_addr = S390_lowcore.cpu_data.cpu_addr;
  370. current_thread_info()->cpu = 0;
  371. num_cpus = 1;
  372. for (cpu = 0; cpu <= 65535; cpu++) {
  373. if ((__u16) cpu == boot_cpu_addr)
  374. continue;
  375. __cpu_logical_map[1] = (__u16) cpu;
  376. if (signal_processor(1, sigp_sense) ==
  377. sigp_not_operational)
  378. continue;
  379. num_cpus++;
  380. }
  381. printk("Detected %d CPU's\n",(int) num_cpus);
  382. printk("Boot cpu address %2X\n", boot_cpu_addr);
  383. return num_cpus;
  384. }
  385. /*
  386. * Activate a secondary processor.
  387. */
  388. int __devinit start_secondary(void *cpuvoid)
  389. {
  390. /* Setup the cpu */
  391. cpu_init();
  392. preempt_disable();
  393. /* Enable TOD clock interrupts on the secondary cpu. */
  394. init_cpu_timer();
  395. #ifdef CONFIG_VIRT_TIMER
  396. /* Enable cpu timer interrupts on the secondary cpu. */
  397. init_cpu_vtimer();
  398. #endif
  399. /* Enable pfault pseudo page faults on this cpu. */
  400. pfault_init();
  401. /* Mark this cpu as online */
  402. cpu_set(smp_processor_id(), cpu_online_map);
  403. /* Switch on interrupts */
  404. local_irq_enable();
  405. /* Print info about this processor */
  406. print_cpu_info(&S390_lowcore.cpu_data);
  407. /* cpu_idle will call schedule for us */
  408. cpu_idle();
  409. return 0;
  410. }
  411. static void __init smp_create_idle(unsigned int cpu)
  412. {
  413. struct task_struct *p;
  414. /*
  415. * don't care about the psw and regs settings since we'll never
  416. * reschedule the forked task.
  417. */
  418. p = fork_idle(cpu);
  419. if (IS_ERR(p))
  420. panic("failed fork for CPU %u: %li", cpu, PTR_ERR(p));
  421. current_set[cpu] = p;
  422. }
  423. /* Reserving and releasing of CPUs */
  424. static DEFINE_SPINLOCK(smp_reserve_lock);
  425. static int smp_cpu_reserved[NR_CPUS];
  426. int
  427. smp_get_cpu(cpumask_t cpu_mask)
  428. {
  429. unsigned long flags;
  430. int cpu;
  431. spin_lock_irqsave(&smp_reserve_lock, flags);
  432. /* Try to find an already reserved cpu. */
  433. for_each_cpu_mask(cpu, cpu_mask) {
  434. if (smp_cpu_reserved[cpu] != 0) {
  435. smp_cpu_reserved[cpu]++;
  436. /* Found one. */
  437. goto out;
  438. }
  439. }
  440. /* Reserve a new cpu from cpu_mask. */
  441. for_each_cpu_mask(cpu, cpu_mask) {
  442. if (cpu_online(cpu)) {
  443. smp_cpu_reserved[cpu]++;
  444. goto out;
  445. }
  446. }
  447. cpu = -ENODEV;
  448. out:
  449. spin_unlock_irqrestore(&smp_reserve_lock, flags);
  450. return cpu;
  451. }
  452. void
  453. smp_put_cpu(int cpu)
  454. {
  455. unsigned long flags;
  456. spin_lock_irqsave(&smp_reserve_lock, flags);
  457. smp_cpu_reserved[cpu]--;
  458. spin_unlock_irqrestore(&smp_reserve_lock, flags);
  459. }
  460. static int
  461. cpu_stopped(int cpu)
  462. {
  463. __u32 status;
  464. /* Check for stopped state */
  465. if (signal_processor_ps(&status, 0, cpu, sigp_sense) == sigp_status_stored) {
  466. if (status & 0x40)
  467. return 1;
  468. }
  469. return 0;
  470. }
  471. /* Upping and downing of CPUs */
  472. int
  473. __cpu_up(unsigned int cpu)
  474. {
  475. struct task_struct *idle;
  476. struct _lowcore *cpu_lowcore;
  477. struct stack_frame *sf;
  478. sigp_ccode ccode;
  479. int curr_cpu;
  480. for (curr_cpu = 0; curr_cpu <= 65535; curr_cpu++) {
  481. __cpu_logical_map[cpu] = (__u16) curr_cpu;
  482. if (cpu_stopped(cpu))
  483. break;
  484. }
  485. if (!cpu_stopped(cpu))
  486. return -ENODEV;
  487. ccode = signal_processor_p((__u32)(unsigned long)(lowcore_ptr[cpu]),
  488. cpu, sigp_set_prefix);
  489. if (ccode){
  490. printk("sigp_set_prefix failed for cpu %d "
  491. "with condition code %d\n",
  492. (int) cpu, (int) ccode);
  493. return -EIO;
  494. }
  495. idle = current_set[cpu];
  496. cpu_lowcore = lowcore_ptr[cpu];
  497. cpu_lowcore->kernel_stack = (unsigned long)
  498. task_stack_page(idle) + (THREAD_SIZE);
  499. sf = (struct stack_frame *) (cpu_lowcore->kernel_stack
  500. - sizeof(struct pt_regs)
  501. - sizeof(struct stack_frame));
  502. memset(sf, 0, sizeof(struct stack_frame));
  503. sf->gprs[9] = (unsigned long) sf;
  504. cpu_lowcore->save_area[15] = (unsigned long) sf;
  505. __ctl_store(cpu_lowcore->cregs_save_area[0], 0, 15);
  506. asm volatile(
  507. " stam 0,15,0(%0)"
  508. : : "a" (&cpu_lowcore->access_regs_save_area) : "memory");
  509. cpu_lowcore->percpu_offset = __per_cpu_offset[cpu];
  510. cpu_lowcore->current_task = (unsigned long) idle;
  511. cpu_lowcore->cpu_data.cpu_nr = cpu;
  512. eieio();
  513. while (signal_processor(cpu,sigp_restart) == sigp_busy)
  514. udelay(10);
  515. while (!cpu_online(cpu))
  516. cpu_relax();
  517. return 0;
  518. }
  519. static unsigned int __initdata additional_cpus;
  520. static unsigned int __initdata possible_cpus;
  521. void __init smp_setup_cpu_possible_map(void)
  522. {
  523. unsigned int phy_cpus, pos_cpus, cpu;
  524. phy_cpus = smp_count_cpus();
  525. pos_cpus = min(phy_cpus + additional_cpus, (unsigned int) NR_CPUS);
  526. if (possible_cpus)
  527. pos_cpus = min(possible_cpus, (unsigned int) NR_CPUS);
  528. for (cpu = 0; cpu < pos_cpus; cpu++)
  529. cpu_set(cpu, cpu_possible_map);
  530. phy_cpus = min(phy_cpus, pos_cpus);
  531. for (cpu = 0; cpu < phy_cpus; cpu++)
  532. cpu_set(cpu, cpu_present_map);
  533. }
  534. #ifdef CONFIG_HOTPLUG_CPU
  535. static int __init setup_additional_cpus(char *s)
  536. {
  537. additional_cpus = simple_strtoul(s, NULL, 0);
  538. return 0;
  539. }
  540. early_param("additional_cpus", setup_additional_cpus);
  541. static int __init setup_possible_cpus(char *s)
  542. {
  543. possible_cpus = simple_strtoul(s, NULL, 0);
  544. return 0;
  545. }
  546. early_param("possible_cpus", setup_possible_cpus);
  547. int
  548. __cpu_disable(void)
  549. {
  550. unsigned long flags;
  551. struct ec_creg_mask_parms cr_parms;
  552. int cpu = smp_processor_id();
  553. spin_lock_irqsave(&smp_reserve_lock, flags);
  554. if (smp_cpu_reserved[cpu] != 0) {
  555. spin_unlock_irqrestore(&smp_reserve_lock, flags);
  556. return -EBUSY;
  557. }
  558. cpu_clear(cpu, cpu_online_map);
  559. /* Disable pfault pseudo page faults on this cpu. */
  560. pfault_fini();
  561. memset(&cr_parms.orvals, 0, sizeof(cr_parms.orvals));
  562. memset(&cr_parms.andvals, 0xff, sizeof(cr_parms.andvals));
  563. /* disable all external interrupts */
  564. cr_parms.orvals[0] = 0;
  565. cr_parms.andvals[0] = ~(1<<15 | 1<<14 | 1<<13 | 1<<12 |
  566. 1<<11 | 1<<10 | 1<< 6 | 1<< 4);
  567. /* disable all I/O interrupts */
  568. cr_parms.orvals[6] = 0;
  569. cr_parms.andvals[6] = ~(1<<31 | 1<<30 | 1<<29 | 1<<28 |
  570. 1<<27 | 1<<26 | 1<<25 | 1<<24);
  571. /* disable most machine checks */
  572. cr_parms.orvals[14] = 0;
  573. cr_parms.andvals[14] = ~(1<<28 | 1<<27 | 1<<26 | 1<<25 | 1<<24);
  574. smp_ctl_bit_callback(&cr_parms);
  575. spin_unlock_irqrestore(&smp_reserve_lock, flags);
  576. return 0;
  577. }
  578. void
  579. __cpu_die(unsigned int cpu)
  580. {
  581. /* Wait until target cpu is down */
  582. while (!smp_cpu_not_running(cpu))
  583. cpu_relax();
  584. printk("Processor %d spun down\n", cpu);
  585. }
  586. void
  587. cpu_die(void)
  588. {
  589. idle_task_exit();
  590. signal_processor(smp_processor_id(), sigp_stop);
  591. BUG();
  592. for(;;);
  593. }
  594. #endif /* CONFIG_HOTPLUG_CPU */
  595. /*
  596. * Cycle through the processors and setup structures.
  597. */
  598. void __init smp_prepare_cpus(unsigned int max_cpus)
  599. {
  600. unsigned long stack;
  601. unsigned int cpu;
  602. int i;
  603. /* request the 0x1201 emergency signal external interrupt */
  604. if (register_external_interrupt(0x1201, do_ext_call_interrupt) != 0)
  605. panic("Couldn't request external interrupt 0x1201");
  606. memset(lowcore_ptr,0,sizeof(lowcore_ptr));
  607. /*
  608. * Initialize prefix pages and stacks for all possible cpus
  609. */
  610. print_cpu_info(&S390_lowcore.cpu_data);
  611. for_each_possible_cpu(i) {
  612. lowcore_ptr[i] = (struct _lowcore *)
  613. __get_free_pages(GFP_KERNEL|GFP_DMA,
  614. sizeof(void*) == 8 ? 1 : 0);
  615. stack = __get_free_pages(GFP_KERNEL,ASYNC_ORDER);
  616. if (lowcore_ptr[i] == NULL || stack == 0ULL)
  617. panic("smp_boot_cpus failed to allocate memory\n");
  618. *(lowcore_ptr[i]) = S390_lowcore;
  619. lowcore_ptr[i]->async_stack = stack + (ASYNC_SIZE);
  620. stack = __get_free_pages(GFP_KERNEL,0);
  621. if (stack == 0ULL)
  622. panic("smp_boot_cpus failed to allocate memory\n");
  623. lowcore_ptr[i]->panic_stack = stack + (PAGE_SIZE);
  624. #ifndef CONFIG_64BIT
  625. if (MACHINE_HAS_IEEE) {
  626. lowcore_ptr[i]->extended_save_area_addr =
  627. (__u32) __get_free_pages(GFP_KERNEL,0);
  628. if (lowcore_ptr[i]->extended_save_area_addr == 0)
  629. panic("smp_boot_cpus failed to "
  630. "allocate memory\n");
  631. }
  632. #endif
  633. }
  634. #ifndef CONFIG_64BIT
  635. if (MACHINE_HAS_IEEE)
  636. ctl_set_bit(14, 29); /* enable extended save area */
  637. #endif
  638. set_prefix((u32)(unsigned long) lowcore_ptr[smp_processor_id()]);
  639. for_each_possible_cpu(cpu)
  640. if (cpu != smp_processor_id())
  641. smp_create_idle(cpu);
  642. }
  643. void __devinit smp_prepare_boot_cpu(void)
  644. {
  645. BUG_ON(smp_processor_id() != 0);
  646. cpu_set(0, cpu_online_map);
  647. S390_lowcore.percpu_offset = __per_cpu_offset[0];
  648. current_set[0] = current;
  649. }
  650. void smp_cpus_done(unsigned int max_cpus)
  651. {
  652. cpu_present_map = cpu_possible_map;
  653. }
  654. /*
  655. * the frequency of the profiling timer can be changed
  656. * by writing a multiplier value into /proc/profile.
  657. *
  658. * usually you want to run this on all CPUs ;)
  659. */
  660. int setup_profiling_timer(unsigned int multiplier)
  661. {
  662. return 0;
  663. }
  664. static DEFINE_PER_CPU(struct cpu, cpu_devices);
  665. static int __init topology_init(void)
  666. {
  667. int cpu;
  668. int ret;
  669. for_each_possible_cpu(cpu) {
  670. struct cpu *c = &per_cpu(cpu_devices, cpu);
  671. c->hotpluggable = 1;
  672. ret = register_cpu(c, cpu);
  673. if (ret)
  674. printk(KERN_WARNING "topology_init: register_cpu %d "
  675. "failed (%d)\n", cpu, ret);
  676. }
  677. return 0;
  678. }
  679. subsys_initcall(topology_init);
  680. EXPORT_SYMBOL(cpu_online_map);
  681. EXPORT_SYMBOL(cpu_possible_map);
  682. EXPORT_SYMBOL(lowcore_ptr);
  683. EXPORT_SYMBOL(smp_ctl_set_bit);
  684. EXPORT_SYMBOL(smp_ctl_clear_bit);
  685. EXPORT_SYMBOL(smp_call_function);
  686. EXPORT_SYMBOL(smp_get_cpu);
  687. EXPORT_SYMBOL(smp_put_cpu);