smp.c 21 KB

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