smp.c 20 KB

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