smpboot.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  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. *
  7. * 01/05/16 Rohit Seth <rohit.seth@intel.com> Moved SMP booting functions from smp.c to here.
  8. * 01/04/27 David Mosberger <davidm@hpl.hp.com> Added ITC synching code.
  9. * 02/07/31 David Mosberger <davidm@hpl.hp.com> Switch over to hotplug-CPU boot-sequence.
  10. * smp_boot_cpus()/smp_commence() is replaced by
  11. * smp_prepare_cpus()/__cpu_up()/smp_cpus_done().
  12. * 04/06/21 Ashok Raj <ashok.raj@intel.com> Added CPU Hotplug Support
  13. */
  14. #include <linux/config.h>
  15. #include <linux/module.h>
  16. #include <linux/acpi.h>
  17. #include <linux/bootmem.h>
  18. #include <linux/cpu.h>
  19. #include <linux/delay.h>
  20. #include <linux/init.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/irq.h>
  23. #include <linux/kernel.h>
  24. #include <linux/kernel_stat.h>
  25. #include <linux/mm.h>
  26. #include <linux/notifier.h>
  27. #include <linux/smp.h>
  28. #include <linux/smp_lock.h>
  29. #include <linux/spinlock.h>
  30. #include <linux/efi.h>
  31. #include <linux/percpu.h>
  32. #include <linux/bitops.h>
  33. #include <asm/atomic.h>
  34. #include <asm/cache.h>
  35. #include <asm/current.h>
  36. #include <asm/delay.h>
  37. #include <asm/ia32.h>
  38. #include <asm/io.h>
  39. #include <asm/irq.h>
  40. #include <asm/machvec.h>
  41. #include <asm/mca.h>
  42. #include <asm/page.h>
  43. #include <asm/pgalloc.h>
  44. #include <asm/pgtable.h>
  45. #include <asm/processor.h>
  46. #include <asm/ptrace.h>
  47. #include <asm/sal.h>
  48. #include <asm/system.h>
  49. #include <asm/tlbflush.h>
  50. #include <asm/unistd.h>
  51. #define SMP_DEBUG 0
  52. #if SMP_DEBUG
  53. #define Dprintk(x...) printk(x)
  54. #else
  55. #define Dprintk(x...)
  56. #endif
  57. #ifdef CONFIG_HOTPLUG_CPU
  58. /*
  59. * Store all idle threads, this can be reused instead of creating
  60. * a new thread. Also avoids complicated thread destroy functionality
  61. * for idle threads.
  62. */
  63. struct task_struct *idle_thread_array[NR_CPUS];
  64. /*
  65. * Global array allocated for NR_CPUS at boot time
  66. */
  67. struct sal_to_os_boot sal_boot_rendez_state[NR_CPUS];
  68. /*
  69. * start_ap in head.S uses this to store current booting cpu
  70. * info.
  71. */
  72. struct sal_to_os_boot *sal_state_for_booting_cpu = &sal_boot_rendez_state[0];
  73. #define set_brendez_area(x) (sal_state_for_booting_cpu = &sal_boot_rendez_state[(x)]);
  74. #define get_idle_for_cpu(x) (idle_thread_array[(x)])
  75. #define set_idle_for_cpu(x,p) (idle_thread_array[(x)] = (p))
  76. #else
  77. #define get_idle_for_cpu(x) (NULL)
  78. #define set_idle_for_cpu(x,p)
  79. #define set_brendez_area(x)
  80. #endif
  81. /*
  82. * ITC synchronization related stuff:
  83. */
  84. #define MASTER 0
  85. #define SLAVE (SMP_CACHE_BYTES/8)
  86. #define NUM_ROUNDS 64 /* magic value */
  87. #define NUM_ITERS 5 /* likewise */
  88. static DEFINE_SPINLOCK(itc_sync_lock);
  89. static volatile unsigned long go[SLAVE + 1];
  90. #define DEBUG_ITC_SYNC 0
  91. extern void __devinit calibrate_delay (void);
  92. extern void start_ap (void);
  93. extern unsigned long ia64_iobase;
  94. task_t *task_for_booting_cpu;
  95. /*
  96. * State for each CPU
  97. */
  98. DEFINE_PER_CPU(int, cpu_state);
  99. /* Bitmasks of currently online, and possible CPUs */
  100. cpumask_t cpu_online_map;
  101. EXPORT_SYMBOL(cpu_online_map);
  102. cpumask_t cpu_possible_map;
  103. EXPORT_SYMBOL(cpu_possible_map);
  104. /* which logical CPU number maps to which CPU (physical APIC ID) */
  105. volatile int ia64_cpu_to_sapicid[NR_CPUS];
  106. EXPORT_SYMBOL(ia64_cpu_to_sapicid);
  107. static volatile cpumask_t cpu_callin_map;
  108. struct smp_boot_data smp_boot_data __initdata;
  109. unsigned long ap_wakeup_vector = -1; /* External Int use to wakeup APs */
  110. char __initdata no_int_routing;
  111. unsigned char smp_int_redirect; /* are INT and IPI redirectable by the chipset? */
  112. static int __init
  113. nointroute (char *str)
  114. {
  115. no_int_routing = 1;
  116. printk ("no_int_routing on\n");
  117. return 1;
  118. }
  119. __setup("nointroute", nointroute);
  120. void
  121. sync_master (void *arg)
  122. {
  123. unsigned long flags, i;
  124. go[MASTER] = 0;
  125. local_irq_save(flags);
  126. {
  127. for (i = 0; i < NUM_ROUNDS*NUM_ITERS; ++i) {
  128. while (!go[MASTER])
  129. cpu_relax();
  130. go[MASTER] = 0;
  131. go[SLAVE] = ia64_get_itc();
  132. }
  133. }
  134. local_irq_restore(flags);
  135. }
  136. /*
  137. * Return the number of cycles by which our itc differs from the itc on the master
  138. * (time-keeper) CPU. A positive number indicates our itc is ahead of the master,
  139. * negative that it is behind.
  140. */
  141. static inline long
  142. get_delta (long *rt, long *master)
  143. {
  144. unsigned long best_t0 = 0, best_t1 = ~0UL, best_tm = 0;
  145. unsigned long tcenter, t0, t1, tm;
  146. long i;
  147. for (i = 0; i < NUM_ITERS; ++i) {
  148. t0 = ia64_get_itc();
  149. go[MASTER] = 1;
  150. while (!(tm = go[SLAVE]))
  151. cpu_relax();
  152. go[SLAVE] = 0;
  153. t1 = ia64_get_itc();
  154. if (t1 - t0 < best_t1 - best_t0)
  155. best_t0 = t0, best_t1 = t1, best_tm = tm;
  156. }
  157. *rt = best_t1 - best_t0;
  158. *master = best_tm - best_t0;
  159. /* average best_t0 and best_t1 without overflow: */
  160. tcenter = (best_t0/2 + best_t1/2);
  161. if (best_t0 % 2 + best_t1 % 2 == 2)
  162. ++tcenter;
  163. return tcenter - best_tm;
  164. }
  165. /*
  166. * Synchronize ar.itc of the current (slave) CPU with the ar.itc of the MASTER CPU
  167. * (normally the time-keeper CPU). We use a closed loop to eliminate the possibility of
  168. * unaccounted-for errors (such as getting a machine check in the middle of a calibration
  169. * step). The basic idea is for the slave to ask the master what itc value it has and to
  170. * read its own itc before and after the master responds. Each iteration gives us three
  171. * timestamps:
  172. *
  173. * slave master
  174. *
  175. * t0 ---\
  176. * ---\
  177. * --->
  178. * tm
  179. * /---
  180. * /---
  181. * t1 <---
  182. *
  183. *
  184. * The goal is to adjust the slave's ar.itc such that tm falls exactly half-way between t0
  185. * and t1. If we achieve this, the clocks are synchronized provided the interconnect
  186. * between the slave and the master is symmetric. Even if the interconnect were
  187. * asymmetric, we would still know that the synchronization error is smaller than the
  188. * roundtrip latency (t0 - t1).
  189. *
  190. * When the interconnect is quiet and symmetric, this lets us synchronize the itc to
  191. * within one or two cycles. However, we can only *guarantee* that the synchronization is
  192. * accurate to within a round-trip time, which is typically in the range of several
  193. * hundred cycles (e.g., ~500 cycles). In practice, this means that the itc's are usually
  194. * almost perfectly synchronized, but we shouldn't assume that the accuracy is much better
  195. * than half a micro second or so.
  196. */
  197. void
  198. ia64_sync_itc (unsigned int master)
  199. {
  200. long i, delta, adj, adjust_latency = 0, done = 0;
  201. unsigned long flags, rt, master_time_stamp, bound;
  202. #if DEBUG_ITC_SYNC
  203. struct {
  204. long rt; /* roundtrip time */
  205. long master; /* master's timestamp */
  206. long diff; /* difference between midpoint and master's timestamp */
  207. long lat; /* estimate of itc adjustment latency */
  208. } t[NUM_ROUNDS];
  209. #endif
  210. /*
  211. * Make sure local timer ticks are disabled while we sync. If
  212. * they were enabled, we'd have to worry about nasty issues
  213. * like setting the ITC ahead of (or a long time before) the
  214. * next scheduled tick.
  215. */
  216. BUG_ON((ia64_get_itv() & (1 << 16)) == 0);
  217. go[MASTER] = 1;
  218. if (smp_call_function_single(master, sync_master, NULL, 1, 0) < 0) {
  219. printk(KERN_ERR "sync_itc: failed to get attention of CPU %u!\n", master);
  220. return;
  221. }
  222. while (go[MASTER])
  223. cpu_relax(); /* wait for master to be ready */
  224. spin_lock_irqsave(&itc_sync_lock, flags);
  225. {
  226. for (i = 0; i < NUM_ROUNDS; ++i) {
  227. delta = get_delta(&rt, &master_time_stamp);
  228. if (delta == 0) {
  229. done = 1; /* let's lock on to this... */
  230. bound = rt;
  231. }
  232. if (!done) {
  233. if (i > 0) {
  234. adjust_latency += -delta;
  235. adj = -delta + adjust_latency/4;
  236. } else
  237. adj = -delta;
  238. ia64_set_itc(ia64_get_itc() + adj);
  239. }
  240. #if DEBUG_ITC_SYNC
  241. t[i].rt = rt;
  242. t[i].master = master_time_stamp;
  243. t[i].diff = delta;
  244. t[i].lat = adjust_latency/4;
  245. #endif
  246. }
  247. }
  248. spin_unlock_irqrestore(&itc_sync_lock, flags);
  249. #if DEBUG_ITC_SYNC
  250. for (i = 0; i < NUM_ROUNDS; ++i)
  251. printk("rt=%5ld master=%5ld diff=%5ld adjlat=%5ld\n",
  252. t[i].rt, t[i].master, t[i].diff, t[i].lat);
  253. #endif
  254. printk(KERN_INFO "CPU %d: synchronized ITC with CPU %u (last diff %ld cycles, "
  255. "maxerr %lu cycles)\n", smp_processor_id(), master, delta, rt);
  256. }
  257. /*
  258. * Ideally sets up per-cpu profiling hooks. Doesn't do much now...
  259. */
  260. static inline void __devinit
  261. smp_setup_percpu_timer (void)
  262. {
  263. }
  264. static void __devinit
  265. smp_callin (void)
  266. {
  267. int cpuid, phys_id;
  268. extern void ia64_init_itm(void);
  269. #ifdef CONFIG_PERFMON
  270. extern void pfm_init_percpu(void);
  271. #endif
  272. cpuid = smp_processor_id();
  273. phys_id = hard_smp_processor_id();
  274. if (cpu_online(cpuid)) {
  275. printk(KERN_ERR "huh, phys CPU#0x%x, CPU#0x%x already present??\n",
  276. phys_id, cpuid);
  277. BUG();
  278. }
  279. lock_ipi_calllock();
  280. cpu_set(cpuid, cpu_online_map);
  281. unlock_ipi_calllock();
  282. smp_setup_percpu_timer();
  283. ia64_mca_cmc_vector_setup(); /* Setup vector on AP */
  284. #ifdef CONFIG_PERFMON
  285. pfm_init_percpu();
  286. #endif
  287. local_irq_enable();
  288. if (!(sal_platform_features & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)) {
  289. /*
  290. * Synchronize the ITC with the BP. Need to do this after irqs are
  291. * enabled because ia64_sync_itc() calls smp_call_function_single(), which
  292. * calls spin_unlock_bh(), which calls spin_unlock_bh(), which calls
  293. * local_bh_enable(), which bugs out if irqs are not enabled...
  294. */
  295. Dprintk("Going to syncup ITC with BP.\n");
  296. ia64_sync_itc(0);
  297. }
  298. /*
  299. * Get our bogomips.
  300. */
  301. ia64_init_itm();
  302. calibrate_delay();
  303. local_cpu_data->loops_per_jiffy = loops_per_jiffy;
  304. #ifdef CONFIG_IA32_SUPPORT
  305. ia32_gdt_init();
  306. #endif
  307. /*
  308. * Allow the master to continue.
  309. */
  310. cpu_set(cpuid, cpu_callin_map);
  311. Dprintk("Stack on CPU %d at about %p\n",cpuid, &cpuid);
  312. }
  313. /*
  314. * Activate a secondary processor. head.S calls this.
  315. */
  316. int __devinit
  317. start_secondary (void *unused)
  318. {
  319. /* Early console may use I/O ports */
  320. ia64_set_kr(IA64_KR_IO_BASE, __pa(ia64_iobase));
  321. Dprintk("start_secondary: starting CPU 0x%x\n", hard_smp_processor_id());
  322. efi_map_pal_code();
  323. cpu_init();
  324. smp_callin();
  325. cpu_idle();
  326. return 0;
  327. }
  328. struct pt_regs * __devinit idle_regs(struct pt_regs *regs)
  329. {
  330. return NULL;
  331. }
  332. struct create_idle {
  333. struct task_struct *idle;
  334. struct completion done;
  335. int cpu;
  336. };
  337. void
  338. do_fork_idle(void *_c_idle)
  339. {
  340. struct create_idle *c_idle = _c_idle;
  341. c_idle->idle = fork_idle(c_idle->cpu);
  342. complete(&c_idle->done);
  343. }
  344. static int __devinit
  345. do_boot_cpu (int sapicid, int cpu)
  346. {
  347. int timeout;
  348. struct create_idle c_idle = {
  349. .cpu = cpu,
  350. .done = COMPLETION_INITIALIZER(c_idle.done),
  351. };
  352. DECLARE_WORK(work, do_fork_idle, &c_idle);
  353. c_idle.idle = get_idle_for_cpu(cpu);
  354. if (c_idle.idle) {
  355. init_idle(c_idle.idle, cpu);
  356. goto do_rest;
  357. }
  358. /*
  359. * We can't use kernel_thread since we must avoid to reschedule the child.
  360. */
  361. if (!keventd_up() || current_is_keventd())
  362. work.func(work.data);
  363. else {
  364. schedule_work(&work);
  365. wait_for_completion(&c_idle.done);
  366. }
  367. if (IS_ERR(c_idle.idle))
  368. panic("failed fork for CPU %d", cpu);
  369. set_idle_for_cpu(cpu, c_idle.idle);
  370. do_rest:
  371. task_for_booting_cpu = c_idle.idle;
  372. Dprintk("Sending wakeup vector %lu to AP 0x%x/0x%x.\n", ap_wakeup_vector, cpu, sapicid);
  373. set_brendez_area(cpu);
  374. platform_send_ipi(cpu, ap_wakeup_vector, IA64_IPI_DM_INT, 0);
  375. /*
  376. * Wait 10s total for the AP to start
  377. */
  378. Dprintk("Waiting on callin_map ...");
  379. for (timeout = 0; timeout < 100000; timeout++) {
  380. if (cpu_isset(cpu, cpu_callin_map))
  381. break; /* It has booted */
  382. udelay(100);
  383. }
  384. Dprintk("\n");
  385. if (!cpu_isset(cpu, cpu_callin_map)) {
  386. printk(KERN_ERR "Processor 0x%x/0x%x is stuck.\n", cpu, sapicid);
  387. ia64_cpu_to_sapicid[cpu] = -1;
  388. cpu_clear(cpu, cpu_online_map); /* was set in smp_callin() */
  389. return -EINVAL;
  390. }
  391. return 0;
  392. }
  393. static int __init
  394. decay (char *str)
  395. {
  396. int ticks;
  397. get_option (&str, &ticks);
  398. return 1;
  399. }
  400. __setup("decay=", decay);
  401. /*
  402. * Initialize the logical CPU number to SAPICID mapping
  403. */
  404. void __init
  405. smp_build_cpu_map (void)
  406. {
  407. int sapicid, cpu, i;
  408. int boot_cpu_id = hard_smp_processor_id();
  409. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  410. ia64_cpu_to_sapicid[cpu] = -1;
  411. #ifdef CONFIG_HOTPLUG_CPU
  412. cpu_set(cpu, cpu_possible_map);
  413. #endif
  414. }
  415. ia64_cpu_to_sapicid[0] = boot_cpu_id;
  416. cpus_clear(cpu_present_map);
  417. cpu_set(0, cpu_present_map);
  418. cpu_set(0, cpu_possible_map);
  419. for (cpu = 1, i = 0; i < smp_boot_data.cpu_count; i++) {
  420. sapicid = smp_boot_data.cpu_phys_id[i];
  421. if (sapicid == boot_cpu_id)
  422. continue;
  423. cpu_set(cpu, cpu_present_map);
  424. cpu_set(cpu, cpu_possible_map);
  425. ia64_cpu_to_sapicid[cpu] = sapicid;
  426. cpu++;
  427. }
  428. }
  429. #ifdef CONFIG_NUMA
  430. /* on which node is each logical CPU (one cacheline even for 64 CPUs) */
  431. u8 cpu_to_node_map[NR_CPUS] __cacheline_aligned;
  432. EXPORT_SYMBOL(cpu_to_node_map);
  433. /* which logical CPUs are on which nodes */
  434. cpumask_t node_to_cpu_mask[MAX_NUMNODES] __cacheline_aligned;
  435. /*
  436. * Build cpu to node mapping and initialize the per node cpu masks.
  437. */
  438. void __init
  439. build_cpu_to_node_map (void)
  440. {
  441. int cpu, i, node;
  442. for(node=0; node<MAX_NUMNODES; node++)
  443. cpus_clear(node_to_cpu_mask[node]);
  444. for(cpu = 0; cpu < NR_CPUS; ++cpu) {
  445. /*
  446. * All Itanium NUMA platforms I know use ACPI, so maybe we
  447. * can drop this ifdef completely. [EF]
  448. */
  449. #ifdef CONFIG_ACPI_NUMA
  450. node = -1;
  451. for (i = 0; i < NR_CPUS; ++i)
  452. if (cpu_physical_id(cpu) == node_cpuid[i].phys_id) {
  453. node = node_cpuid[i].nid;
  454. break;
  455. }
  456. #else
  457. # error Fixme: Dunno how to build CPU-to-node map.
  458. #endif
  459. cpu_to_node_map[cpu] = (node >= 0) ? node : 0;
  460. if (node >= 0)
  461. cpu_set(cpu, node_to_cpu_mask[node]);
  462. }
  463. }
  464. #endif /* CONFIG_NUMA */
  465. /*
  466. * Cycle through the APs sending Wakeup IPIs to boot each.
  467. */
  468. void __init
  469. smp_prepare_cpus (unsigned int max_cpus)
  470. {
  471. int boot_cpu_id = hard_smp_processor_id();
  472. /*
  473. * Initialize the per-CPU profiling counter/multiplier
  474. */
  475. smp_setup_percpu_timer();
  476. /*
  477. * We have the boot CPU online for sure.
  478. */
  479. cpu_set(0, cpu_online_map);
  480. cpu_set(0, cpu_callin_map);
  481. local_cpu_data->loops_per_jiffy = loops_per_jiffy;
  482. ia64_cpu_to_sapicid[0] = boot_cpu_id;
  483. printk(KERN_INFO "Boot processor id 0x%x/0x%x\n", 0, boot_cpu_id);
  484. current_thread_info()->cpu = 0;
  485. /*
  486. * If SMP should be disabled, then really disable it!
  487. */
  488. if (!max_cpus) {
  489. printk(KERN_INFO "SMP mode deactivated.\n");
  490. cpus_clear(cpu_online_map);
  491. cpus_clear(cpu_present_map);
  492. cpus_clear(cpu_possible_map);
  493. cpu_set(0, cpu_online_map);
  494. cpu_set(0, cpu_present_map);
  495. cpu_set(0, cpu_possible_map);
  496. return;
  497. }
  498. }
  499. void __devinit smp_prepare_boot_cpu(void)
  500. {
  501. cpu_set(smp_processor_id(), cpu_online_map);
  502. cpu_set(smp_processor_id(), cpu_callin_map);
  503. }
  504. #ifdef CONFIG_HOTPLUG_CPU
  505. extern void fixup_irqs(void);
  506. /* must be called with cpucontrol mutex held */
  507. int __cpu_disable(void)
  508. {
  509. int cpu = smp_processor_id();
  510. /*
  511. * dont permit boot processor for now
  512. */
  513. if (cpu == 0)
  514. return -EBUSY;
  515. fixup_irqs();
  516. local_flush_tlb_all();
  517. cpu_clear(cpu, cpu_callin_map);
  518. return 0;
  519. }
  520. void __cpu_die(unsigned int cpu)
  521. {
  522. unsigned int i;
  523. for (i = 0; i < 100; i++) {
  524. /* They ack this in play_dead by setting CPU_DEAD */
  525. if (per_cpu(cpu_state, cpu) == CPU_DEAD)
  526. {
  527. printk ("CPU %d is now offline\n", cpu);
  528. return;
  529. }
  530. msleep(100);
  531. }
  532. printk(KERN_ERR "CPU %u didn't die...\n", cpu);
  533. }
  534. #else /* !CONFIG_HOTPLUG_CPU */
  535. int __cpu_disable(void)
  536. {
  537. return -ENOSYS;
  538. }
  539. void __cpu_die(unsigned int cpu)
  540. {
  541. /* We said "no" in __cpu_disable */
  542. BUG();
  543. }
  544. #endif /* CONFIG_HOTPLUG_CPU */
  545. void
  546. smp_cpus_done (unsigned int dummy)
  547. {
  548. int cpu;
  549. unsigned long bogosum = 0;
  550. /*
  551. * Allow the user to impress friends.
  552. */
  553. for (cpu = 0; cpu < NR_CPUS; cpu++)
  554. if (cpu_online(cpu))
  555. bogosum += cpu_data(cpu)->loops_per_jiffy;
  556. printk(KERN_INFO "Total of %d processors activated (%lu.%02lu BogoMIPS).\n",
  557. (int)num_online_cpus(), bogosum/(500000/HZ), (bogosum/(5000/HZ))%100);
  558. }
  559. int __devinit
  560. __cpu_up (unsigned int cpu)
  561. {
  562. int ret;
  563. int sapicid;
  564. sapicid = ia64_cpu_to_sapicid[cpu];
  565. if (sapicid == -1)
  566. return -EINVAL;
  567. /*
  568. * Already booted cpu? not valid anymore since we dont
  569. * do idle loop tightspin anymore.
  570. */
  571. if (cpu_isset(cpu, cpu_callin_map))
  572. return -EINVAL;
  573. /* Processor goes to start_secondary(), sets online flag */
  574. ret = do_boot_cpu(sapicid, cpu);
  575. if (ret < 0)
  576. return ret;
  577. return 0;
  578. }
  579. /*
  580. * Assume that CPU's have been discovered by some platform-dependent interface. For
  581. * SoftSDV/Lion, that would be ACPI.
  582. *
  583. * Setup of the IPI irq handler is done in irq.c:init_IRQ_SMP().
  584. */
  585. void __init
  586. init_smp_config(void)
  587. {
  588. struct fptr {
  589. unsigned long fp;
  590. unsigned long gp;
  591. } *ap_startup;
  592. long sal_ret;
  593. /* Tell SAL where to drop the AP's. */
  594. ap_startup = (struct fptr *) start_ap;
  595. sal_ret = ia64_sal_set_vectors(SAL_VECTOR_OS_BOOT_RENDEZ,
  596. ia64_tpa(ap_startup->fp), ia64_tpa(ap_startup->gp), 0, 0, 0, 0);
  597. if (sal_ret < 0)
  598. printk(KERN_ERR "SMP: Can't set SAL AP Boot Rendezvous: %s\n",
  599. ia64_sal_strerror(sal_ret));
  600. }