smpboot.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  1. /*
  2. * SMP boot-related support
  3. *
  4. * Copyright (C) 1998-2003, 2005 Hewlett-Packard Co
  5. * David Mosberger-Tang <davidm@hpl.hp.com>
  6. * Copyright (C) 2001, 2004-2005 Intel Corp
  7. * Rohit Seth <rohit.seth@intel.com>
  8. * Suresh Siddha <suresh.b.siddha@intel.com>
  9. * Gordon Jin <gordon.jin@intel.com>
  10. * Ashok Raj <ashok.raj@intel.com>
  11. *
  12. * 01/05/16 Rohit Seth <rohit.seth@intel.com> Moved SMP booting functions from smp.c to here.
  13. * 01/04/27 David Mosberger <davidm@hpl.hp.com> Added ITC synching code.
  14. * 02/07/31 David Mosberger <davidm@hpl.hp.com> Switch over to hotplug-CPU boot-sequence.
  15. * smp_boot_cpus()/smp_commence() is replaced by
  16. * smp_prepare_cpus()/__cpu_up()/smp_cpus_done().
  17. * 04/06/21 Ashok Raj <ashok.raj@intel.com> Added CPU Hotplug Support
  18. * 04/12/26 Jin Gordon <gordon.jin@intel.com>
  19. * 04/12/26 Rohit Seth <rohit.seth@intel.com>
  20. * Add multi-threading and multi-core detection
  21. * 05/01/30 Suresh Siddha <suresh.b.siddha@intel.com>
  22. * Setup cpu_sibling_map and cpu_core_map
  23. */
  24. #include <linux/module.h>
  25. #include <linux/acpi.h>
  26. #include <linux/bootmem.h>
  27. #include <linux/cpu.h>
  28. #include <linux/delay.h>
  29. #include <linux/init.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/irq.h>
  32. #include <linux/kernel.h>
  33. #include <linux/kernel_stat.h>
  34. #include <linux/mm.h>
  35. #include <linux/notifier.h>
  36. #include <linux/smp.h>
  37. #include <linux/spinlock.h>
  38. #include <linux/efi.h>
  39. #include <linux/percpu.h>
  40. #include <linux/bitops.h>
  41. #include <linux/atomic.h>
  42. #include <asm/cache.h>
  43. #include <asm/current.h>
  44. #include <asm/delay.h>
  45. #include <asm/io.h>
  46. #include <asm/irq.h>
  47. #include <asm/machvec.h>
  48. #include <asm/mca.h>
  49. #include <asm/page.h>
  50. #include <asm/paravirt.h>
  51. #include <asm/pgalloc.h>
  52. #include <asm/pgtable.h>
  53. #include <asm/processor.h>
  54. #include <asm/ptrace.h>
  55. #include <asm/sal.h>
  56. #include <asm/tlbflush.h>
  57. #include <asm/unistd.h>
  58. #include <asm/sn/arch.h>
  59. #define SMP_DEBUG 0
  60. #if SMP_DEBUG
  61. #define Dprintk(x...) printk(x)
  62. #else
  63. #define Dprintk(x...)
  64. #endif
  65. #ifdef CONFIG_HOTPLUG_CPU
  66. #ifdef CONFIG_PERMIT_BSP_REMOVE
  67. #define bsp_remove_ok 1
  68. #else
  69. #define bsp_remove_ok 0
  70. #endif
  71. /*
  72. * Global array allocated for NR_CPUS at boot time
  73. */
  74. struct sal_to_os_boot sal_boot_rendez_state[NR_CPUS];
  75. /*
  76. * start_ap in head.S uses this to store current booting cpu
  77. * info.
  78. */
  79. struct sal_to_os_boot *sal_state_for_booting_cpu = &sal_boot_rendez_state[0];
  80. #define set_brendez_area(x) (sal_state_for_booting_cpu = &sal_boot_rendez_state[(x)]);
  81. #else
  82. #define set_brendez_area(x)
  83. #endif
  84. /*
  85. * ITC synchronization related stuff:
  86. */
  87. #define MASTER (0)
  88. #define SLAVE (SMP_CACHE_BYTES/8)
  89. #define NUM_ROUNDS 64 /* magic value */
  90. #define NUM_ITERS 5 /* likewise */
  91. static DEFINE_SPINLOCK(itc_sync_lock);
  92. static volatile unsigned long go[SLAVE + 1];
  93. #define DEBUG_ITC_SYNC 0
  94. extern void start_ap (void);
  95. extern unsigned long ia64_iobase;
  96. struct task_struct *task_for_booting_cpu;
  97. /*
  98. * State for each CPU
  99. */
  100. DEFINE_PER_CPU(int, cpu_state);
  101. cpumask_t cpu_core_map[NR_CPUS] __cacheline_aligned;
  102. EXPORT_SYMBOL(cpu_core_map);
  103. DEFINE_PER_CPU_SHARED_ALIGNED(cpumask_t, cpu_sibling_map);
  104. EXPORT_PER_CPU_SYMBOL(cpu_sibling_map);
  105. int smp_num_siblings = 1;
  106. /* which logical CPU number maps to which CPU (physical APIC ID) */
  107. volatile int ia64_cpu_to_sapicid[NR_CPUS];
  108. EXPORT_SYMBOL(ia64_cpu_to_sapicid);
  109. static volatile cpumask_t cpu_callin_map;
  110. struct smp_boot_data smp_boot_data __initdata;
  111. unsigned long ap_wakeup_vector = -1; /* External Int use to wakeup APs */
  112. char __initdata no_int_routing;
  113. unsigned char smp_int_redirect; /* are INT and IPI redirectable by the chipset? */
  114. #ifdef CONFIG_FORCE_CPEI_RETARGET
  115. #define CPEI_OVERRIDE_DEFAULT (1)
  116. #else
  117. #define CPEI_OVERRIDE_DEFAULT (0)
  118. #endif
  119. unsigned int force_cpei_retarget = CPEI_OVERRIDE_DEFAULT;
  120. static int __init
  121. cmdl_force_cpei(char *str)
  122. {
  123. int value=0;
  124. get_option (&str, &value);
  125. force_cpei_retarget = value;
  126. return 1;
  127. }
  128. __setup("force_cpei=", cmdl_force_cpei);
  129. static int __init
  130. nointroute (char *str)
  131. {
  132. no_int_routing = 1;
  133. printk ("no_int_routing on\n");
  134. return 1;
  135. }
  136. __setup("nointroute", nointroute);
  137. static void fix_b0_for_bsp(void)
  138. {
  139. #ifdef CONFIG_HOTPLUG_CPU
  140. int cpuid;
  141. static int fix_bsp_b0 = 1;
  142. cpuid = smp_processor_id();
  143. /*
  144. * Cache the b0 value on the first AP that comes up
  145. */
  146. if (!(fix_bsp_b0 && cpuid))
  147. return;
  148. sal_boot_rendez_state[0].br[0] = sal_boot_rendez_state[cpuid].br[0];
  149. printk ("Fixed BSP b0 value from CPU %d\n", cpuid);
  150. fix_bsp_b0 = 0;
  151. #endif
  152. }
  153. void
  154. sync_master (void *arg)
  155. {
  156. unsigned long flags, i;
  157. go[MASTER] = 0;
  158. local_irq_save(flags);
  159. {
  160. for (i = 0; i < NUM_ROUNDS*NUM_ITERS; ++i) {
  161. while (!go[MASTER])
  162. cpu_relax();
  163. go[MASTER] = 0;
  164. go[SLAVE] = ia64_get_itc();
  165. }
  166. }
  167. local_irq_restore(flags);
  168. }
  169. /*
  170. * Return the number of cycles by which our itc differs from the itc on the master
  171. * (time-keeper) CPU. A positive number indicates our itc is ahead of the master,
  172. * negative that it is behind.
  173. */
  174. static inline long
  175. get_delta (long *rt, long *master)
  176. {
  177. unsigned long best_t0 = 0, best_t1 = ~0UL, best_tm = 0;
  178. unsigned long tcenter, t0, t1, tm;
  179. long i;
  180. for (i = 0; i < NUM_ITERS; ++i) {
  181. t0 = ia64_get_itc();
  182. go[MASTER] = 1;
  183. while (!(tm = go[SLAVE]))
  184. cpu_relax();
  185. go[SLAVE] = 0;
  186. t1 = ia64_get_itc();
  187. if (t1 - t0 < best_t1 - best_t0)
  188. best_t0 = t0, best_t1 = t1, best_tm = tm;
  189. }
  190. *rt = best_t1 - best_t0;
  191. *master = best_tm - best_t0;
  192. /* average best_t0 and best_t1 without overflow: */
  193. tcenter = (best_t0/2 + best_t1/2);
  194. if (best_t0 % 2 + best_t1 % 2 == 2)
  195. ++tcenter;
  196. return tcenter - best_tm;
  197. }
  198. /*
  199. * Synchronize ar.itc of the current (slave) CPU with the ar.itc of the MASTER CPU
  200. * (normally the time-keeper CPU). We use a closed loop to eliminate the possibility of
  201. * unaccounted-for errors (such as getting a machine check in the middle of a calibration
  202. * step). The basic idea is for the slave to ask the master what itc value it has and to
  203. * read its own itc before and after the master responds. Each iteration gives us three
  204. * timestamps:
  205. *
  206. * slave master
  207. *
  208. * t0 ---\
  209. * ---\
  210. * --->
  211. * tm
  212. * /---
  213. * /---
  214. * t1 <---
  215. *
  216. *
  217. * The goal is to adjust the slave's ar.itc such that tm falls exactly half-way between t0
  218. * and t1. If we achieve this, the clocks are synchronized provided the interconnect
  219. * between the slave and the master is symmetric. Even if the interconnect were
  220. * asymmetric, we would still know that the synchronization error is smaller than the
  221. * roundtrip latency (t0 - t1).
  222. *
  223. * When the interconnect is quiet and symmetric, this lets us synchronize the itc to
  224. * within one or two cycles. However, we can only *guarantee* that the synchronization is
  225. * accurate to within a round-trip time, which is typically in the range of several
  226. * hundred cycles (e.g., ~500 cycles). In practice, this means that the itc's are usually
  227. * almost perfectly synchronized, but we shouldn't assume that the accuracy is much better
  228. * than half a micro second or so.
  229. */
  230. void
  231. ia64_sync_itc (unsigned int master)
  232. {
  233. long i, delta, adj, adjust_latency = 0, done = 0;
  234. unsigned long flags, rt, master_time_stamp, bound;
  235. #if DEBUG_ITC_SYNC
  236. struct {
  237. long rt; /* roundtrip time */
  238. long master; /* master's timestamp */
  239. long diff; /* difference between midpoint and master's timestamp */
  240. long lat; /* estimate of itc adjustment latency */
  241. } t[NUM_ROUNDS];
  242. #endif
  243. /*
  244. * Make sure local timer ticks are disabled while we sync. If
  245. * they were enabled, we'd have to worry about nasty issues
  246. * like setting the ITC ahead of (or a long time before) the
  247. * next scheduled tick.
  248. */
  249. BUG_ON((ia64_get_itv() & (1 << 16)) == 0);
  250. go[MASTER] = 1;
  251. if (smp_call_function_single(master, sync_master, NULL, 0) < 0) {
  252. printk(KERN_ERR "sync_itc: failed to get attention of CPU %u!\n", master);
  253. return;
  254. }
  255. while (go[MASTER])
  256. cpu_relax(); /* wait for master to be ready */
  257. spin_lock_irqsave(&itc_sync_lock, flags);
  258. {
  259. for (i = 0; i < NUM_ROUNDS; ++i) {
  260. delta = get_delta(&rt, &master_time_stamp);
  261. if (delta == 0) {
  262. done = 1; /* let's lock on to this... */
  263. bound = rt;
  264. }
  265. if (!done) {
  266. if (i > 0) {
  267. adjust_latency += -delta;
  268. adj = -delta + adjust_latency/4;
  269. } else
  270. adj = -delta;
  271. ia64_set_itc(ia64_get_itc() + adj);
  272. }
  273. #if DEBUG_ITC_SYNC
  274. t[i].rt = rt;
  275. t[i].master = master_time_stamp;
  276. t[i].diff = delta;
  277. t[i].lat = adjust_latency/4;
  278. #endif
  279. }
  280. }
  281. spin_unlock_irqrestore(&itc_sync_lock, flags);
  282. #if DEBUG_ITC_SYNC
  283. for (i = 0; i < NUM_ROUNDS; ++i)
  284. printk("rt=%5ld master=%5ld diff=%5ld adjlat=%5ld\n",
  285. t[i].rt, t[i].master, t[i].diff, t[i].lat);
  286. #endif
  287. printk(KERN_INFO "CPU %d: synchronized ITC with CPU %u (last diff %ld cycles, "
  288. "maxerr %lu cycles)\n", smp_processor_id(), master, delta, rt);
  289. }
  290. /*
  291. * Ideally sets up per-cpu profiling hooks. Doesn't do much now...
  292. */
  293. static inline void __devinit
  294. smp_setup_percpu_timer (void)
  295. {
  296. }
  297. static void __cpuinit
  298. smp_callin (void)
  299. {
  300. int cpuid, phys_id, itc_master;
  301. struct cpuinfo_ia64 *last_cpuinfo, *this_cpuinfo;
  302. extern void ia64_init_itm(void);
  303. extern volatile int time_keeper_id;
  304. #ifdef CONFIG_PERFMON
  305. extern void pfm_init_percpu(void);
  306. #endif
  307. cpuid = smp_processor_id();
  308. phys_id = hard_smp_processor_id();
  309. itc_master = time_keeper_id;
  310. if (cpu_online(cpuid)) {
  311. printk(KERN_ERR "huh, phys CPU#0x%x, CPU#0x%x already present??\n",
  312. phys_id, cpuid);
  313. BUG();
  314. }
  315. fix_b0_for_bsp();
  316. /*
  317. * numa_node_id() works after this.
  318. */
  319. set_numa_node(cpu_to_node_map[cpuid]);
  320. set_numa_mem(local_memory_node(cpu_to_node_map[cpuid]));
  321. spin_lock(&vector_lock);
  322. /* Setup the per cpu irq handling data structures */
  323. __setup_vector_irq(cpuid);
  324. notify_cpu_starting(cpuid);
  325. set_cpu_online(cpuid, true);
  326. per_cpu(cpu_state, cpuid) = CPU_ONLINE;
  327. spin_unlock(&vector_lock);
  328. smp_setup_percpu_timer();
  329. ia64_mca_cmc_vector_setup(); /* Setup vector on AP */
  330. #ifdef CONFIG_PERFMON
  331. pfm_init_percpu();
  332. #endif
  333. local_irq_enable();
  334. if (!(sal_platform_features & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)) {
  335. /*
  336. * Synchronize the ITC with the BP. Need to do this after irqs are
  337. * enabled because ia64_sync_itc() calls smp_call_function_single(), which
  338. * calls spin_unlock_bh(), which calls spin_unlock_bh(), which calls
  339. * local_bh_enable(), which bugs out if irqs are not enabled...
  340. */
  341. Dprintk("Going to syncup ITC with ITC Master.\n");
  342. ia64_sync_itc(itc_master);
  343. }
  344. /*
  345. * Get our bogomips.
  346. */
  347. ia64_init_itm();
  348. /*
  349. * Delay calibration can be skipped if new processor is identical to the
  350. * previous processor.
  351. */
  352. last_cpuinfo = cpu_data(cpuid - 1);
  353. this_cpuinfo = local_cpu_data;
  354. if (last_cpuinfo->itc_freq != this_cpuinfo->itc_freq ||
  355. last_cpuinfo->proc_freq != this_cpuinfo->proc_freq ||
  356. last_cpuinfo->features != this_cpuinfo->features ||
  357. last_cpuinfo->revision != this_cpuinfo->revision ||
  358. last_cpuinfo->family != this_cpuinfo->family ||
  359. last_cpuinfo->archrev != this_cpuinfo->archrev ||
  360. last_cpuinfo->model != this_cpuinfo->model)
  361. calibrate_delay();
  362. local_cpu_data->loops_per_jiffy = loops_per_jiffy;
  363. /*
  364. * Allow the master to continue.
  365. */
  366. cpu_set(cpuid, cpu_callin_map);
  367. Dprintk("Stack on CPU %d at about %p\n",cpuid, &cpuid);
  368. }
  369. /*
  370. * Activate a secondary processor. head.S calls this.
  371. */
  372. int __cpuinit
  373. start_secondary (void *unused)
  374. {
  375. /* Early console may use I/O ports */
  376. ia64_set_kr(IA64_KR_IO_BASE, __pa(ia64_iobase));
  377. #ifndef CONFIG_PRINTK_TIME
  378. Dprintk("start_secondary: starting CPU 0x%x\n", hard_smp_processor_id());
  379. #endif
  380. efi_map_pal_code();
  381. cpu_init();
  382. preempt_disable();
  383. smp_callin();
  384. cpu_idle();
  385. return 0;
  386. }
  387. struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
  388. {
  389. return NULL;
  390. }
  391. static int __cpuinit
  392. do_boot_cpu (int sapicid, int cpu, struct task_struct *idle)
  393. {
  394. int timeout;
  395. task_for_booting_cpu = idle;
  396. Dprintk("Sending wakeup vector %lu to AP 0x%x/0x%x.\n", ap_wakeup_vector, cpu, sapicid);
  397. set_brendez_area(cpu);
  398. platform_send_ipi(cpu, ap_wakeup_vector, IA64_IPI_DM_INT, 0);
  399. /*
  400. * Wait 10s total for the AP to start
  401. */
  402. Dprintk("Waiting on callin_map ...");
  403. for (timeout = 0; timeout < 100000; timeout++) {
  404. if (cpu_isset(cpu, cpu_callin_map))
  405. break; /* It has booted */
  406. udelay(100);
  407. }
  408. Dprintk("\n");
  409. if (!cpu_isset(cpu, cpu_callin_map)) {
  410. printk(KERN_ERR "Processor 0x%x/0x%x is stuck.\n", cpu, sapicid);
  411. ia64_cpu_to_sapicid[cpu] = -1;
  412. set_cpu_online(cpu, false); /* was set in smp_callin() */
  413. return -EINVAL;
  414. }
  415. return 0;
  416. }
  417. static int __init
  418. decay (char *str)
  419. {
  420. int ticks;
  421. get_option (&str, &ticks);
  422. return 1;
  423. }
  424. __setup("decay=", decay);
  425. /*
  426. * Initialize the logical CPU number to SAPICID mapping
  427. */
  428. void __init
  429. smp_build_cpu_map (void)
  430. {
  431. int sapicid, cpu, i;
  432. int boot_cpu_id = hard_smp_processor_id();
  433. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  434. ia64_cpu_to_sapicid[cpu] = -1;
  435. }
  436. ia64_cpu_to_sapicid[0] = boot_cpu_id;
  437. init_cpu_present(cpumask_of(0));
  438. set_cpu_possible(0, true);
  439. for (cpu = 1, i = 0; i < smp_boot_data.cpu_count; i++) {
  440. sapicid = smp_boot_data.cpu_phys_id[i];
  441. if (sapicid == boot_cpu_id)
  442. continue;
  443. set_cpu_present(cpu, true);
  444. set_cpu_possible(cpu, true);
  445. ia64_cpu_to_sapicid[cpu] = sapicid;
  446. cpu++;
  447. }
  448. }
  449. /*
  450. * Cycle through the APs sending Wakeup IPIs to boot each.
  451. */
  452. void __init
  453. smp_prepare_cpus (unsigned int max_cpus)
  454. {
  455. int boot_cpu_id = hard_smp_processor_id();
  456. /*
  457. * Initialize the per-CPU profiling counter/multiplier
  458. */
  459. smp_setup_percpu_timer();
  460. cpu_set(0, cpu_callin_map);
  461. local_cpu_data->loops_per_jiffy = loops_per_jiffy;
  462. ia64_cpu_to_sapicid[0] = boot_cpu_id;
  463. printk(KERN_INFO "Boot processor id 0x%x/0x%x\n", 0, boot_cpu_id);
  464. current_thread_info()->cpu = 0;
  465. /*
  466. * If SMP should be disabled, then really disable it!
  467. */
  468. if (!max_cpus) {
  469. printk(KERN_INFO "SMP mode deactivated.\n");
  470. init_cpu_online(cpumask_of(0));
  471. init_cpu_present(cpumask_of(0));
  472. init_cpu_possible(cpumask_of(0));
  473. return;
  474. }
  475. }
  476. void __devinit smp_prepare_boot_cpu(void)
  477. {
  478. set_cpu_online(smp_processor_id(), true);
  479. cpu_set(smp_processor_id(), cpu_callin_map);
  480. set_numa_node(cpu_to_node_map[smp_processor_id()]);
  481. per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE;
  482. paravirt_post_smp_prepare_boot_cpu();
  483. }
  484. #ifdef CONFIG_HOTPLUG_CPU
  485. static inline void
  486. clear_cpu_sibling_map(int cpu)
  487. {
  488. int i;
  489. for_each_cpu_mask(i, per_cpu(cpu_sibling_map, cpu))
  490. cpu_clear(cpu, per_cpu(cpu_sibling_map, i));
  491. for_each_cpu_mask(i, cpu_core_map[cpu])
  492. cpu_clear(cpu, cpu_core_map[i]);
  493. per_cpu(cpu_sibling_map, cpu) = cpu_core_map[cpu] = CPU_MASK_NONE;
  494. }
  495. static void
  496. remove_siblinginfo(int cpu)
  497. {
  498. int last = 0;
  499. if (cpu_data(cpu)->threads_per_core == 1 &&
  500. cpu_data(cpu)->cores_per_socket == 1) {
  501. cpu_clear(cpu, cpu_core_map[cpu]);
  502. cpu_clear(cpu, per_cpu(cpu_sibling_map, cpu));
  503. return;
  504. }
  505. last = (cpus_weight(cpu_core_map[cpu]) == 1 ? 1 : 0);
  506. /* remove it from all sibling map's */
  507. clear_cpu_sibling_map(cpu);
  508. }
  509. extern void fixup_irqs(void);
  510. int migrate_platform_irqs(unsigned int cpu)
  511. {
  512. int new_cpei_cpu;
  513. struct irq_data *data = NULL;
  514. const struct cpumask *mask;
  515. int retval = 0;
  516. /*
  517. * dont permit CPEI target to removed.
  518. */
  519. if (cpe_vector > 0 && is_cpu_cpei_target(cpu)) {
  520. printk ("CPU (%d) is CPEI Target\n", cpu);
  521. if (can_cpei_retarget()) {
  522. /*
  523. * Now re-target the CPEI to a different processor
  524. */
  525. new_cpei_cpu = cpumask_any(cpu_online_mask);
  526. mask = cpumask_of(new_cpei_cpu);
  527. set_cpei_target_cpu(new_cpei_cpu);
  528. data = irq_get_irq_data(ia64_cpe_irq);
  529. /*
  530. * Switch for now, immediately, we need to do fake intr
  531. * as other interrupts, but need to study CPEI behaviour with
  532. * polling before making changes.
  533. */
  534. if (data && data->chip) {
  535. data->chip->irq_disable(data);
  536. data->chip->irq_set_affinity(data, mask, false);
  537. data->chip->irq_enable(data);
  538. printk ("Re-targeting CPEI to cpu %d\n", new_cpei_cpu);
  539. }
  540. }
  541. if (!data) {
  542. printk ("Unable to retarget CPEI, offline cpu [%d] failed\n", cpu);
  543. retval = -EBUSY;
  544. }
  545. }
  546. return retval;
  547. }
  548. /* must be called with cpucontrol mutex held */
  549. int __cpu_disable(void)
  550. {
  551. int cpu = smp_processor_id();
  552. /*
  553. * dont permit boot processor for now
  554. */
  555. if (cpu == 0 && !bsp_remove_ok) {
  556. printk ("Your platform does not support removal of BSP\n");
  557. return (-EBUSY);
  558. }
  559. if (ia64_platform_is("sn2")) {
  560. if (!sn_cpu_disable_allowed(cpu))
  561. return -EBUSY;
  562. }
  563. set_cpu_online(cpu, false);
  564. if (migrate_platform_irqs(cpu)) {
  565. set_cpu_online(cpu, true);
  566. return -EBUSY;
  567. }
  568. remove_siblinginfo(cpu);
  569. fixup_irqs();
  570. local_flush_tlb_all();
  571. cpu_clear(cpu, cpu_callin_map);
  572. return 0;
  573. }
  574. void __cpu_die(unsigned int cpu)
  575. {
  576. unsigned int i;
  577. for (i = 0; i < 100; i++) {
  578. /* They ack this in play_dead by setting CPU_DEAD */
  579. if (per_cpu(cpu_state, cpu) == CPU_DEAD)
  580. {
  581. printk ("CPU %d is now offline\n", cpu);
  582. return;
  583. }
  584. msleep(100);
  585. }
  586. printk(KERN_ERR "CPU %u didn't die...\n", cpu);
  587. }
  588. #endif /* CONFIG_HOTPLUG_CPU */
  589. void
  590. smp_cpus_done (unsigned int dummy)
  591. {
  592. int cpu;
  593. unsigned long bogosum = 0;
  594. /*
  595. * Allow the user to impress friends.
  596. */
  597. for_each_online_cpu(cpu) {
  598. bogosum += cpu_data(cpu)->loops_per_jiffy;
  599. }
  600. printk(KERN_INFO "Total of %d processors activated (%lu.%02lu BogoMIPS).\n",
  601. (int)num_online_cpus(), bogosum/(500000/HZ), (bogosum/(5000/HZ))%100);
  602. }
  603. static inline void __devinit
  604. set_cpu_sibling_map(int cpu)
  605. {
  606. int i;
  607. for_each_online_cpu(i) {
  608. if ((cpu_data(cpu)->socket_id == cpu_data(i)->socket_id)) {
  609. cpu_set(i, cpu_core_map[cpu]);
  610. cpu_set(cpu, cpu_core_map[i]);
  611. if (cpu_data(cpu)->core_id == cpu_data(i)->core_id) {
  612. cpu_set(i, per_cpu(cpu_sibling_map, cpu));
  613. cpu_set(cpu, per_cpu(cpu_sibling_map, i));
  614. }
  615. }
  616. }
  617. }
  618. int __cpuinit
  619. __cpu_up(unsigned int cpu, struct task_struct *tidle)
  620. {
  621. int ret;
  622. int sapicid;
  623. sapicid = ia64_cpu_to_sapicid[cpu];
  624. if (sapicid == -1)
  625. return -EINVAL;
  626. /*
  627. * Already booted cpu? not valid anymore since we dont
  628. * do idle loop tightspin anymore.
  629. */
  630. if (cpu_isset(cpu, cpu_callin_map))
  631. return -EINVAL;
  632. per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
  633. /* Processor goes to start_secondary(), sets online flag */
  634. ret = do_boot_cpu(sapicid, cpu, tidle);
  635. if (ret < 0)
  636. return ret;
  637. if (cpu_data(cpu)->threads_per_core == 1 &&
  638. cpu_data(cpu)->cores_per_socket == 1) {
  639. cpu_set(cpu, per_cpu(cpu_sibling_map, cpu));
  640. cpu_set(cpu, cpu_core_map[cpu]);
  641. return 0;
  642. }
  643. set_cpu_sibling_map(cpu);
  644. return 0;
  645. }
  646. /*
  647. * Assume that CPUs have been discovered by some platform-dependent interface. For
  648. * SoftSDV/Lion, that would be ACPI.
  649. *
  650. * Setup of the IPI irq handler is done in irq.c:init_IRQ_SMP().
  651. */
  652. void __init
  653. init_smp_config(void)
  654. {
  655. struct fptr {
  656. unsigned long fp;
  657. unsigned long gp;
  658. } *ap_startup;
  659. long sal_ret;
  660. /* Tell SAL where to drop the APs. */
  661. ap_startup = (struct fptr *) start_ap;
  662. sal_ret = ia64_sal_set_vectors(SAL_VECTOR_OS_BOOT_RENDEZ,
  663. ia64_tpa(ap_startup->fp), ia64_tpa(ap_startup->gp), 0, 0, 0, 0);
  664. if (sal_ret < 0)
  665. printk(KERN_ERR "SMP: Can't set SAL AP Boot Rendezvous: %s\n",
  666. ia64_sal_strerror(sal_ret));
  667. }
  668. /*
  669. * identify_siblings(cpu) gets called from identify_cpu. This populates the
  670. * information related to logical execution units in per_cpu_data structure.
  671. */
  672. void __devinit
  673. identify_siblings(struct cpuinfo_ia64 *c)
  674. {
  675. long status;
  676. u16 pltid;
  677. pal_logical_to_physical_t info;
  678. status = ia64_pal_logical_to_phys(-1, &info);
  679. if (status != PAL_STATUS_SUCCESS) {
  680. if (status != PAL_STATUS_UNIMPLEMENTED) {
  681. printk(KERN_ERR
  682. "ia64_pal_logical_to_phys failed with %ld\n",
  683. status);
  684. return;
  685. }
  686. info.overview_ppid = 0;
  687. info.overview_cpp = 1;
  688. info.overview_tpc = 1;
  689. }
  690. status = ia64_sal_physical_id_info(&pltid);
  691. if (status != PAL_STATUS_SUCCESS) {
  692. if (status != PAL_STATUS_UNIMPLEMENTED)
  693. printk(KERN_ERR
  694. "ia64_sal_pltid failed with %ld\n",
  695. status);
  696. return;
  697. }
  698. c->socket_id = (pltid << 8) | info.overview_ppid;
  699. if (info.overview_cpp == 1 && info.overview_tpc == 1)
  700. return;
  701. c->cores_per_socket = info.overview_cpp;
  702. c->threads_per_core = info.overview_tpc;
  703. c->num_log = info.overview_num_log;
  704. c->core_id = info.log1_cid;
  705. c->thread_id = info.log1_tid;
  706. }
  707. /*
  708. * returns non zero, if multi-threading is enabled
  709. * on at least one physical package. Due to hotplug cpu
  710. * and (maxcpus=), all threads may not necessarily be enabled
  711. * even though the processor supports multi-threading.
  712. */
  713. int is_multithreading_enabled(void)
  714. {
  715. int i, j;
  716. for_each_present_cpu(i) {
  717. for_each_present_cpu(j) {
  718. if (j == i)
  719. continue;
  720. if ((cpu_data(j)->socket_id == cpu_data(i)->socket_id)) {
  721. if (cpu_data(j)->core_id == cpu_data(i)->core_id)
  722. return 1;
  723. }
  724. }
  725. }
  726. return 0;
  727. }
  728. EXPORT_SYMBOL_GPL(is_multithreading_enabled);