smp.c 19 KB

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