smp.c 21 KB

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