smp.c 20 KB

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