smp.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437
  1. /* smp.c: Sparc64 SMP support.
  2. *
  3. * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
  4. */
  5. #include <linux/module.h>
  6. #include <linux/kernel.h>
  7. #include <linux/sched.h>
  8. #include <linux/mm.h>
  9. #include <linux/pagemap.h>
  10. #include <linux/threads.h>
  11. #include <linux/smp.h>
  12. #include <linux/smp_lock.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/kernel_stat.h>
  15. #include <linux/delay.h>
  16. #include <linux/init.h>
  17. #include <linux/spinlock.h>
  18. #include <linux/fs.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/cache.h>
  21. #include <linux/jiffies.h>
  22. #include <linux/profile.h>
  23. #include <linux/bootmem.h>
  24. #include <asm/head.h>
  25. #include <asm/ptrace.h>
  26. #include <asm/atomic.h>
  27. #include <asm/tlbflush.h>
  28. #include <asm/mmu_context.h>
  29. #include <asm/cpudata.h>
  30. #include <asm/irq.h>
  31. #include <asm/page.h>
  32. #include <asm/pgtable.h>
  33. #include <asm/oplib.h>
  34. #include <asm/uaccess.h>
  35. #include <asm/timer.h>
  36. #include <asm/starfire.h>
  37. #include <asm/tlb.h>
  38. #include <asm/sections.h>
  39. extern void calibrate_delay(void);
  40. /* Please don't make this stuff initdata!!! --DaveM */
  41. static unsigned char boot_cpu_id;
  42. cpumask_t cpu_online_map __read_mostly = CPU_MASK_NONE;
  43. cpumask_t phys_cpu_present_map __read_mostly = CPU_MASK_NONE;
  44. cpumask_t cpu_sibling_map[NR_CPUS] __read_mostly =
  45. { [0 ... NR_CPUS-1] = CPU_MASK_NONE };
  46. static cpumask_t smp_commenced_mask;
  47. static cpumask_t cpu_callout_map;
  48. void smp_info(struct seq_file *m)
  49. {
  50. int i;
  51. seq_printf(m, "State:\n");
  52. for (i = 0; i < NR_CPUS; i++) {
  53. if (cpu_online(i))
  54. seq_printf(m,
  55. "CPU%d:\t\tonline\n", i);
  56. }
  57. }
  58. void smp_bogo(struct seq_file *m)
  59. {
  60. int i;
  61. for (i = 0; i < NR_CPUS; i++)
  62. if (cpu_online(i))
  63. seq_printf(m,
  64. "Cpu%dBogo\t: %lu.%02lu\n"
  65. "Cpu%dClkTck\t: %016lx\n",
  66. i, cpu_data(i).udelay_val / (500000/HZ),
  67. (cpu_data(i).udelay_val / (5000/HZ)) % 100,
  68. i, cpu_data(i).clock_tick);
  69. }
  70. void __init smp_store_cpu_info(int id)
  71. {
  72. int cpu_node, def;
  73. /* multiplier and counter set by
  74. smp_setup_percpu_timer() */
  75. cpu_data(id).udelay_val = loops_per_jiffy;
  76. cpu_find_by_mid(id, &cpu_node);
  77. cpu_data(id).clock_tick = prom_getintdefault(cpu_node,
  78. "clock-frequency", 0);
  79. def = ((tlb_type == hypervisor) ? (8 * 1024) : (16 * 1024));
  80. cpu_data(id).dcache_size = prom_getintdefault(cpu_node, "dcache-size",
  81. def);
  82. def = 32;
  83. cpu_data(id).dcache_line_size =
  84. prom_getintdefault(cpu_node, "dcache-line-size", def);
  85. def = 16 * 1024;
  86. cpu_data(id).icache_size = prom_getintdefault(cpu_node, "icache-size",
  87. def);
  88. def = 32;
  89. cpu_data(id).icache_line_size =
  90. prom_getintdefault(cpu_node, "icache-line-size", def);
  91. def = ((tlb_type == hypervisor) ?
  92. (3 * 1024 * 1024) :
  93. (4 * 1024 * 1024));
  94. cpu_data(id).ecache_size = prom_getintdefault(cpu_node, "ecache-size",
  95. def);
  96. def = 64;
  97. cpu_data(id).ecache_line_size =
  98. prom_getintdefault(cpu_node, "ecache-line-size", def);
  99. printk("CPU[%d]: Caches "
  100. "D[sz(%d):line_sz(%d)] "
  101. "I[sz(%d):line_sz(%d)] "
  102. "E[sz(%d):line_sz(%d)]\n",
  103. id,
  104. cpu_data(id).dcache_size, cpu_data(id).dcache_line_size,
  105. cpu_data(id).icache_size, cpu_data(id).icache_line_size,
  106. cpu_data(id).ecache_size, cpu_data(id).ecache_line_size);
  107. }
  108. static void smp_setup_percpu_timer(void);
  109. static volatile unsigned long callin_flag = 0;
  110. void __init smp_callin(void)
  111. {
  112. int cpuid = hard_smp_processor_id();
  113. __local_per_cpu_offset = __per_cpu_offset(cpuid);
  114. if (tlb_type == hypervisor)
  115. sun4v_ktsb_register();
  116. __flush_tlb_all();
  117. smp_setup_percpu_timer();
  118. if (cheetah_pcache_forced_on)
  119. cheetah_enable_pcache();
  120. local_irq_enable();
  121. calibrate_delay();
  122. smp_store_cpu_info(cpuid);
  123. callin_flag = 1;
  124. __asm__ __volatile__("membar #Sync\n\t"
  125. "flush %%g6" : : : "memory");
  126. /* Clear this or we will die instantly when we
  127. * schedule back to this idler...
  128. */
  129. current_thread_info()->new_child = 0;
  130. /* Attach to the address space of init_task. */
  131. atomic_inc(&init_mm.mm_count);
  132. current->active_mm = &init_mm;
  133. while (!cpu_isset(cpuid, smp_commenced_mask))
  134. rmb();
  135. cpu_set(cpuid, cpu_online_map);
  136. /* idle thread is expected to have preempt disabled */
  137. preempt_disable();
  138. }
  139. void cpu_panic(void)
  140. {
  141. printk("CPU[%d]: Returns from cpu_idle!\n", smp_processor_id());
  142. panic("SMP bolixed\n");
  143. }
  144. static unsigned long current_tick_offset __read_mostly;
  145. /* This tick register synchronization scheme is taken entirely from
  146. * the ia64 port, see arch/ia64/kernel/smpboot.c for details and credit.
  147. *
  148. * The only change I've made is to rework it so that the master
  149. * initiates the synchonization instead of the slave. -DaveM
  150. */
  151. #define MASTER 0
  152. #define SLAVE (SMP_CACHE_BYTES/sizeof(unsigned long))
  153. #define NUM_ROUNDS 64 /* magic value */
  154. #define NUM_ITERS 5 /* likewise */
  155. static DEFINE_SPINLOCK(itc_sync_lock);
  156. static unsigned long go[SLAVE + 1];
  157. #define DEBUG_TICK_SYNC 0
  158. static inline long get_delta (long *rt, long *master)
  159. {
  160. unsigned long best_t0 = 0, best_t1 = ~0UL, best_tm = 0;
  161. unsigned long tcenter, t0, t1, tm;
  162. unsigned long i;
  163. for (i = 0; i < NUM_ITERS; i++) {
  164. t0 = tick_ops->get_tick();
  165. go[MASTER] = 1;
  166. membar_storeload();
  167. while (!(tm = go[SLAVE]))
  168. rmb();
  169. go[SLAVE] = 0;
  170. wmb();
  171. t1 = tick_ops->get_tick();
  172. if (t1 - t0 < best_t1 - best_t0)
  173. best_t0 = t0, best_t1 = t1, best_tm = tm;
  174. }
  175. *rt = best_t1 - best_t0;
  176. *master = best_tm - best_t0;
  177. /* average best_t0 and best_t1 without overflow: */
  178. tcenter = (best_t0/2 + best_t1/2);
  179. if (best_t0 % 2 + best_t1 % 2 == 2)
  180. tcenter++;
  181. return tcenter - best_tm;
  182. }
  183. void smp_synchronize_tick_client(void)
  184. {
  185. long i, delta, adj, adjust_latency = 0, done = 0;
  186. unsigned long flags, rt, master_time_stamp, bound;
  187. #if DEBUG_TICK_SYNC
  188. struct {
  189. long rt; /* roundtrip time */
  190. long master; /* master's timestamp */
  191. long diff; /* difference between midpoint and master's timestamp */
  192. long lat; /* estimate of itc adjustment latency */
  193. } t[NUM_ROUNDS];
  194. #endif
  195. go[MASTER] = 1;
  196. while (go[MASTER])
  197. rmb();
  198. local_irq_save(flags);
  199. {
  200. for (i = 0; i < NUM_ROUNDS; i++) {
  201. delta = get_delta(&rt, &master_time_stamp);
  202. if (delta == 0) {
  203. done = 1; /* let's lock on to this... */
  204. bound = rt;
  205. }
  206. if (!done) {
  207. if (i > 0) {
  208. adjust_latency += -delta;
  209. adj = -delta + adjust_latency/4;
  210. } else
  211. adj = -delta;
  212. tick_ops->add_tick(adj, current_tick_offset);
  213. }
  214. #if DEBUG_TICK_SYNC
  215. t[i].rt = rt;
  216. t[i].master = master_time_stamp;
  217. t[i].diff = delta;
  218. t[i].lat = adjust_latency/4;
  219. #endif
  220. }
  221. }
  222. local_irq_restore(flags);
  223. #if DEBUG_TICK_SYNC
  224. for (i = 0; i < NUM_ROUNDS; i++)
  225. printk("rt=%5ld master=%5ld diff=%5ld adjlat=%5ld\n",
  226. t[i].rt, t[i].master, t[i].diff, t[i].lat);
  227. #endif
  228. printk(KERN_INFO "CPU %d: synchronized TICK with master CPU (last diff %ld cycles,"
  229. "maxerr %lu cycles)\n", smp_processor_id(), delta, rt);
  230. }
  231. static void smp_start_sync_tick_client(int cpu);
  232. static void smp_synchronize_one_tick(int cpu)
  233. {
  234. unsigned long flags, i;
  235. go[MASTER] = 0;
  236. smp_start_sync_tick_client(cpu);
  237. /* wait for client to be ready */
  238. while (!go[MASTER])
  239. rmb();
  240. /* now let the client proceed into his loop */
  241. go[MASTER] = 0;
  242. membar_storeload();
  243. spin_lock_irqsave(&itc_sync_lock, flags);
  244. {
  245. for (i = 0; i < NUM_ROUNDS*NUM_ITERS; i++) {
  246. while (!go[MASTER])
  247. rmb();
  248. go[MASTER] = 0;
  249. wmb();
  250. go[SLAVE] = tick_ops->get_tick();
  251. membar_storeload();
  252. }
  253. }
  254. spin_unlock_irqrestore(&itc_sync_lock, flags);
  255. }
  256. extern void sun4v_init_mondo_queues(int use_bootmem, int cpu, int alloc, int load);
  257. extern unsigned long sparc64_cpu_startup;
  258. /* The OBP cpu startup callback truncates the 3rd arg cookie to
  259. * 32-bits (I think) so to be safe we have it read the pointer
  260. * contained here so we work on >4GB machines. -DaveM
  261. */
  262. static struct thread_info *cpu_new_thread = NULL;
  263. static int __devinit smp_boot_one_cpu(unsigned int cpu)
  264. {
  265. unsigned long entry =
  266. (unsigned long)(&sparc64_cpu_startup);
  267. unsigned long cookie =
  268. (unsigned long)(&cpu_new_thread);
  269. struct task_struct *p;
  270. int timeout, ret;
  271. p = fork_idle(cpu);
  272. callin_flag = 0;
  273. cpu_new_thread = task_thread_info(p);
  274. cpu_set(cpu, cpu_callout_map);
  275. if (tlb_type == hypervisor) {
  276. /* Alloc the mondo queues, cpu will load them. */
  277. sun4v_init_mondo_queues(0, cpu, 1, 0);
  278. prom_startcpu_cpuid(cpu, entry, cookie);
  279. } else {
  280. int cpu_node;
  281. cpu_find_by_mid(cpu, &cpu_node);
  282. prom_startcpu(cpu_node, entry, cookie);
  283. }
  284. for (timeout = 0; timeout < 5000000; timeout++) {
  285. if (callin_flag)
  286. break;
  287. udelay(100);
  288. }
  289. if (callin_flag) {
  290. ret = 0;
  291. } else {
  292. printk("Processor %d is stuck.\n", cpu);
  293. cpu_clear(cpu, cpu_callout_map);
  294. ret = -ENODEV;
  295. }
  296. cpu_new_thread = NULL;
  297. return ret;
  298. }
  299. static void spitfire_xcall_helper(u64 data0, u64 data1, u64 data2, u64 pstate, unsigned long cpu)
  300. {
  301. u64 result, target;
  302. int stuck, tmp;
  303. if (this_is_starfire) {
  304. /* map to real upaid */
  305. cpu = (((cpu & 0x3c) << 1) |
  306. ((cpu & 0x40) >> 4) |
  307. (cpu & 0x3));
  308. }
  309. target = (cpu << 14) | 0x70;
  310. again:
  311. /* Ok, this is the real Spitfire Errata #54.
  312. * One must read back from a UDB internal register
  313. * after writes to the UDB interrupt dispatch, but
  314. * before the membar Sync for that write.
  315. * So we use the high UDB control register (ASI 0x7f,
  316. * ADDR 0x20) for the dummy read. -DaveM
  317. */
  318. tmp = 0x40;
  319. __asm__ __volatile__(
  320. "wrpr %1, %2, %%pstate\n\t"
  321. "stxa %4, [%0] %3\n\t"
  322. "stxa %5, [%0+%8] %3\n\t"
  323. "add %0, %8, %0\n\t"
  324. "stxa %6, [%0+%8] %3\n\t"
  325. "membar #Sync\n\t"
  326. "stxa %%g0, [%7] %3\n\t"
  327. "membar #Sync\n\t"
  328. "mov 0x20, %%g1\n\t"
  329. "ldxa [%%g1] 0x7f, %%g0\n\t"
  330. "membar #Sync"
  331. : "=r" (tmp)
  332. : "r" (pstate), "i" (PSTATE_IE), "i" (ASI_INTR_W),
  333. "r" (data0), "r" (data1), "r" (data2), "r" (target),
  334. "r" (0x10), "0" (tmp)
  335. : "g1");
  336. /* NOTE: PSTATE_IE is still clear. */
  337. stuck = 100000;
  338. do {
  339. __asm__ __volatile__("ldxa [%%g0] %1, %0"
  340. : "=r" (result)
  341. : "i" (ASI_INTR_DISPATCH_STAT));
  342. if (result == 0) {
  343. __asm__ __volatile__("wrpr %0, 0x0, %%pstate"
  344. : : "r" (pstate));
  345. return;
  346. }
  347. stuck -= 1;
  348. if (stuck == 0)
  349. break;
  350. } while (result & 0x1);
  351. __asm__ __volatile__("wrpr %0, 0x0, %%pstate"
  352. : : "r" (pstate));
  353. if (stuck == 0) {
  354. printk("CPU[%d]: mondo stuckage result[%016lx]\n",
  355. smp_processor_id(), result);
  356. } else {
  357. udelay(2);
  358. goto again;
  359. }
  360. }
  361. static __inline__ void spitfire_xcall_deliver(u64 data0, u64 data1, u64 data2, cpumask_t mask)
  362. {
  363. u64 pstate;
  364. int i;
  365. __asm__ __volatile__("rdpr %%pstate, %0" : "=r" (pstate));
  366. for_each_cpu_mask(i, mask)
  367. spitfire_xcall_helper(data0, data1, data2, pstate, i);
  368. }
  369. /* Cheetah now allows to send the whole 64-bytes of data in the interrupt
  370. * packet, but we have no use for that. However we do take advantage of
  371. * the new pipelining feature (ie. dispatch to multiple cpus simultaneously).
  372. */
  373. static void cheetah_xcall_deliver(u64 data0, u64 data1, u64 data2, cpumask_t mask)
  374. {
  375. u64 pstate, ver;
  376. int nack_busy_id, is_jbus;
  377. if (cpus_empty(mask))
  378. return;
  379. /* Unfortunately, someone at Sun had the brilliant idea to make the
  380. * busy/nack fields hard-coded by ITID number for this Ultra-III
  381. * derivative processor.
  382. */
  383. __asm__ ("rdpr %%ver, %0" : "=r" (ver));
  384. is_jbus = ((ver >> 32) == __JALAPENO_ID ||
  385. (ver >> 32) == __SERRANO_ID);
  386. __asm__ __volatile__("rdpr %%pstate, %0" : "=r" (pstate));
  387. retry:
  388. __asm__ __volatile__("wrpr %0, %1, %%pstate\n\t"
  389. : : "r" (pstate), "i" (PSTATE_IE));
  390. /* Setup the dispatch data registers. */
  391. __asm__ __volatile__("stxa %0, [%3] %6\n\t"
  392. "stxa %1, [%4] %6\n\t"
  393. "stxa %2, [%5] %6\n\t"
  394. "membar #Sync\n\t"
  395. : /* no outputs */
  396. : "r" (data0), "r" (data1), "r" (data2),
  397. "r" (0x40), "r" (0x50), "r" (0x60),
  398. "i" (ASI_INTR_W));
  399. nack_busy_id = 0;
  400. {
  401. int i;
  402. for_each_cpu_mask(i, mask) {
  403. u64 target = (i << 14) | 0x70;
  404. if (!is_jbus)
  405. target |= (nack_busy_id << 24);
  406. __asm__ __volatile__(
  407. "stxa %%g0, [%0] %1\n\t"
  408. "membar #Sync\n\t"
  409. : /* no outputs */
  410. : "r" (target), "i" (ASI_INTR_W));
  411. nack_busy_id++;
  412. }
  413. }
  414. /* Now, poll for completion. */
  415. {
  416. u64 dispatch_stat;
  417. long stuck;
  418. stuck = 100000 * nack_busy_id;
  419. do {
  420. __asm__ __volatile__("ldxa [%%g0] %1, %0"
  421. : "=r" (dispatch_stat)
  422. : "i" (ASI_INTR_DISPATCH_STAT));
  423. if (dispatch_stat == 0UL) {
  424. __asm__ __volatile__("wrpr %0, 0x0, %%pstate"
  425. : : "r" (pstate));
  426. return;
  427. }
  428. if (!--stuck)
  429. break;
  430. } while (dispatch_stat & 0x5555555555555555UL);
  431. __asm__ __volatile__("wrpr %0, 0x0, %%pstate"
  432. : : "r" (pstate));
  433. if ((dispatch_stat & ~(0x5555555555555555UL)) == 0) {
  434. /* Busy bits will not clear, continue instead
  435. * of freezing up on this cpu.
  436. */
  437. printk("CPU[%d]: mondo stuckage result[%016lx]\n",
  438. smp_processor_id(), dispatch_stat);
  439. } else {
  440. int i, this_busy_nack = 0;
  441. /* Delay some random time with interrupts enabled
  442. * to prevent deadlock.
  443. */
  444. udelay(2 * nack_busy_id);
  445. /* Clear out the mask bits for cpus which did not
  446. * NACK us.
  447. */
  448. for_each_cpu_mask(i, mask) {
  449. u64 check_mask;
  450. if (is_jbus)
  451. check_mask = (0x2UL << (2*i));
  452. else
  453. check_mask = (0x2UL <<
  454. this_busy_nack);
  455. if ((dispatch_stat & check_mask) == 0)
  456. cpu_clear(i, mask);
  457. this_busy_nack += 2;
  458. }
  459. goto retry;
  460. }
  461. }
  462. }
  463. /* Multi-cpu list version. */
  464. static void hypervisor_xcall_deliver(u64 data0, u64 data1, u64 data2, cpumask_t mask)
  465. {
  466. struct trap_per_cpu *tb;
  467. u16 *cpu_list;
  468. u64 *mondo;
  469. cpumask_t error_mask;
  470. unsigned long flags, status;
  471. int cnt, retries, this_cpu, prev_sent, i;
  472. /* We have to do this whole thing with interrupts fully disabled.
  473. * Otherwise if we send an xcall from interrupt context it will
  474. * corrupt both our mondo block and cpu list state.
  475. *
  476. * One consequence of this is that we cannot use timeout mechanisms
  477. * that depend upon interrupts being delivered locally. So, for
  478. * example, we cannot sample jiffies and expect it to advance.
  479. *
  480. * Fortunately, udelay() uses %stick/%tick so we can use that.
  481. */
  482. local_irq_save(flags);
  483. this_cpu = smp_processor_id();
  484. tb = &trap_block[this_cpu];
  485. mondo = __va(tb->cpu_mondo_block_pa);
  486. mondo[0] = data0;
  487. mondo[1] = data1;
  488. mondo[2] = data2;
  489. wmb();
  490. cpu_list = __va(tb->cpu_list_pa);
  491. /* Setup the initial cpu list. */
  492. cnt = 0;
  493. for_each_cpu_mask(i, mask)
  494. cpu_list[cnt++] = i;
  495. cpus_clear(error_mask);
  496. retries = 0;
  497. prev_sent = 0;
  498. do {
  499. int forward_progress, n_sent;
  500. status = sun4v_cpu_mondo_send(cnt,
  501. tb->cpu_list_pa,
  502. tb->cpu_mondo_block_pa);
  503. /* HV_EOK means all cpus received the xcall, we're done. */
  504. if (likely(status == HV_EOK))
  505. break;
  506. /* First, see if we made any forward progress.
  507. *
  508. * The hypervisor indicates successful sends by setting
  509. * cpu list entries to the value 0xffff.
  510. */
  511. n_sent = 0;
  512. for (i = 0; i < cnt; i++) {
  513. if (likely(cpu_list[i] == 0xffff))
  514. n_sent++;
  515. }
  516. forward_progress = 0;
  517. if (n_sent > prev_sent)
  518. forward_progress = 1;
  519. prev_sent = n_sent;
  520. /* If we get a HV_ECPUERROR, then one or more of the cpus
  521. * in the list are in error state. Use the cpu_state()
  522. * hypervisor call to find out which cpus are in error state.
  523. */
  524. if (unlikely(status == HV_ECPUERROR)) {
  525. for (i = 0; i < cnt; i++) {
  526. long err;
  527. u16 cpu;
  528. cpu = cpu_list[i];
  529. if (cpu == 0xffff)
  530. continue;
  531. err = sun4v_cpu_state(cpu);
  532. if (err >= 0 &&
  533. err == HV_CPU_STATE_ERROR) {
  534. cpu_list[i] = 0xffff;
  535. cpu_set(cpu, error_mask);
  536. }
  537. }
  538. } else if (unlikely(status != HV_EWOULDBLOCK))
  539. goto fatal_mondo_error;
  540. /* Don't bother rewriting the CPU list, just leave the
  541. * 0xffff and non-0xffff entries in there and the
  542. * hypervisor will do the right thing.
  543. *
  544. * Only advance timeout state if we didn't make any
  545. * forward progress.
  546. */
  547. if (unlikely(!forward_progress)) {
  548. if (unlikely(++retries > 10000))
  549. goto fatal_mondo_timeout;
  550. /* Delay a little bit to let other cpus catch up
  551. * on their cpu mondo queue work.
  552. */
  553. udelay(2 * cnt);
  554. }
  555. } while (1);
  556. local_irq_restore(flags);
  557. if (unlikely(!cpus_empty(error_mask)))
  558. goto fatal_mondo_cpu_error;
  559. return;
  560. fatal_mondo_cpu_error:
  561. printk(KERN_CRIT "CPU[%d]: SUN4V mondo cpu error, some target cpus "
  562. "were in error state\n",
  563. this_cpu);
  564. printk(KERN_CRIT "CPU[%d]: Error mask [ ", this_cpu);
  565. for_each_cpu_mask(i, error_mask)
  566. printk("%d ", i);
  567. printk("]\n");
  568. return;
  569. fatal_mondo_timeout:
  570. local_irq_restore(flags);
  571. printk(KERN_CRIT "CPU[%d]: SUN4V mondo timeout, no forward "
  572. " progress after %d retries.\n",
  573. this_cpu, retries);
  574. goto dump_cpu_list_and_out;
  575. fatal_mondo_error:
  576. local_irq_restore(flags);
  577. printk(KERN_CRIT "CPU[%d]: Unexpected SUN4V mondo error %lu\n",
  578. this_cpu, status);
  579. printk(KERN_CRIT "CPU[%d]: Args were cnt(%d) cpulist_pa(%lx) "
  580. "mondo_block_pa(%lx)\n",
  581. this_cpu, cnt, tb->cpu_list_pa, tb->cpu_mondo_block_pa);
  582. dump_cpu_list_and_out:
  583. printk(KERN_CRIT "CPU[%d]: CPU list [ ", this_cpu);
  584. for (i = 0; i < cnt; i++)
  585. printk("%u ", cpu_list[i]);
  586. printk("]\n");
  587. }
  588. /* Send cross call to all processors mentioned in MASK
  589. * except self.
  590. */
  591. static void smp_cross_call_masked(unsigned long *func, u32 ctx, u64 data1, u64 data2, cpumask_t mask)
  592. {
  593. u64 data0 = (((u64)ctx)<<32 | (((u64)func) & 0xffffffff));
  594. int this_cpu = get_cpu();
  595. cpus_and(mask, mask, cpu_online_map);
  596. cpu_clear(this_cpu, mask);
  597. if (tlb_type == spitfire)
  598. spitfire_xcall_deliver(data0, data1, data2, mask);
  599. else if (tlb_type == cheetah || tlb_type == cheetah_plus)
  600. cheetah_xcall_deliver(data0, data1, data2, mask);
  601. else
  602. hypervisor_xcall_deliver(data0, data1, data2, mask);
  603. /* NOTE: Caller runs local copy on master. */
  604. put_cpu();
  605. }
  606. extern unsigned long xcall_sync_tick;
  607. static void smp_start_sync_tick_client(int cpu)
  608. {
  609. cpumask_t mask = cpumask_of_cpu(cpu);
  610. smp_cross_call_masked(&xcall_sync_tick,
  611. 0, 0, 0, mask);
  612. }
  613. /* Send cross call to all processors except self. */
  614. #define smp_cross_call(func, ctx, data1, data2) \
  615. smp_cross_call_masked(func, ctx, data1, data2, cpu_online_map)
  616. struct call_data_struct {
  617. void (*func) (void *info);
  618. void *info;
  619. atomic_t finished;
  620. int wait;
  621. };
  622. static DEFINE_SPINLOCK(call_lock);
  623. static struct call_data_struct *call_data;
  624. extern unsigned long xcall_call_function;
  625. /*
  626. * You must not call this function with disabled interrupts or from a
  627. * hardware interrupt handler or from a bottom half handler.
  628. */
  629. static int smp_call_function_mask(void (*func)(void *info), void *info,
  630. int nonatomic, int wait, cpumask_t mask)
  631. {
  632. struct call_data_struct data;
  633. int cpus;
  634. long timeout;
  635. /* Can deadlock when called with interrupts disabled */
  636. WARN_ON(irqs_disabled());
  637. data.func = func;
  638. data.info = info;
  639. atomic_set(&data.finished, 0);
  640. data.wait = wait;
  641. spin_lock(&call_lock);
  642. cpu_clear(smp_processor_id(), mask);
  643. cpus = cpus_weight(mask);
  644. if (!cpus)
  645. goto out_unlock;
  646. call_data = &data;
  647. smp_cross_call_masked(&xcall_call_function, 0, 0, 0, mask);
  648. /*
  649. * Wait for other cpus to complete function or at
  650. * least snap the call data.
  651. */
  652. timeout = 1000000;
  653. while (atomic_read(&data.finished) != cpus) {
  654. if (--timeout <= 0)
  655. goto out_timeout;
  656. barrier();
  657. udelay(1);
  658. }
  659. out_unlock:
  660. spin_unlock(&call_lock);
  661. return 0;
  662. out_timeout:
  663. spin_unlock(&call_lock);
  664. printk("XCALL: Remote cpus not responding, ncpus=%d finished=%d\n",
  665. cpus, atomic_read(&data.finished));
  666. return 0;
  667. }
  668. int smp_call_function(void (*func)(void *info), void *info,
  669. int nonatomic, int wait)
  670. {
  671. return smp_call_function_mask(func, info, nonatomic, wait,
  672. cpu_online_map);
  673. }
  674. void smp_call_function_client(int irq, struct pt_regs *regs)
  675. {
  676. void (*func) (void *info) = call_data->func;
  677. void *info = call_data->info;
  678. clear_softint(1 << irq);
  679. if (call_data->wait) {
  680. /* let initiator proceed only after completion */
  681. func(info);
  682. atomic_inc(&call_data->finished);
  683. } else {
  684. /* let initiator proceed after getting data */
  685. atomic_inc(&call_data->finished);
  686. func(info);
  687. }
  688. }
  689. static void tsb_sync(void *info)
  690. {
  691. struct mm_struct *mm = info;
  692. if (current->active_mm == mm)
  693. tsb_context_switch(mm);
  694. }
  695. void smp_tsb_sync(struct mm_struct *mm)
  696. {
  697. smp_call_function_mask(tsb_sync, mm, 0, 1, mm->cpu_vm_mask);
  698. }
  699. extern unsigned long xcall_flush_tlb_mm;
  700. extern unsigned long xcall_flush_tlb_pending;
  701. extern unsigned long xcall_flush_tlb_kernel_range;
  702. extern unsigned long xcall_report_regs;
  703. extern unsigned long xcall_receive_signal;
  704. extern unsigned long xcall_new_mmu_context_version;
  705. #ifdef DCACHE_ALIASING_POSSIBLE
  706. extern unsigned long xcall_flush_dcache_page_cheetah;
  707. #endif
  708. extern unsigned long xcall_flush_dcache_page_spitfire;
  709. #ifdef CONFIG_DEBUG_DCFLUSH
  710. extern atomic_t dcpage_flushes;
  711. extern atomic_t dcpage_flushes_xcall;
  712. #endif
  713. static __inline__ void __local_flush_dcache_page(struct page *page)
  714. {
  715. #ifdef DCACHE_ALIASING_POSSIBLE
  716. __flush_dcache_page(page_address(page),
  717. ((tlb_type == spitfire) &&
  718. page_mapping(page) != NULL));
  719. #else
  720. if (page_mapping(page) != NULL &&
  721. tlb_type == spitfire)
  722. __flush_icache_page(__pa(page_address(page)));
  723. #endif
  724. }
  725. void smp_flush_dcache_page_impl(struct page *page, int cpu)
  726. {
  727. cpumask_t mask = cpumask_of_cpu(cpu);
  728. int this_cpu;
  729. if (tlb_type == hypervisor)
  730. return;
  731. #ifdef CONFIG_DEBUG_DCFLUSH
  732. atomic_inc(&dcpage_flushes);
  733. #endif
  734. this_cpu = get_cpu();
  735. if (cpu == this_cpu) {
  736. __local_flush_dcache_page(page);
  737. } else if (cpu_online(cpu)) {
  738. void *pg_addr = page_address(page);
  739. u64 data0;
  740. if (tlb_type == spitfire) {
  741. data0 =
  742. ((u64)&xcall_flush_dcache_page_spitfire);
  743. if (page_mapping(page) != NULL)
  744. data0 |= ((u64)1 << 32);
  745. spitfire_xcall_deliver(data0,
  746. __pa(pg_addr),
  747. (u64) pg_addr,
  748. mask);
  749. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  750. #ifdef DCACHE_ALIASING_POSSIBLE
  751. data0 =
  752. ((u64)&xcall_flush_dcache_page_cheetah);
  753. cheetah_xcall_deliver(data0,
  754. __pa(pg_addr),
  755. 0, mask);
  756. #endif
  757. }
  758. #ifdef CONFIG_DEBUG_DCFLUSH
  759. atomic_inc(&dcpage_flushes_xcall);
  760. #endif
  761. }
  762. put_cpu();
  763. }
  764. void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
  765. {
  766. void *pg_addr = page_address(page);
  767. cpumask_t mask = cpu_online_map;
  768. u64 data0;
  769. int this_cpu;
  770. if (tlb_type == hypervisor)
  771. return;
  772. this_cpu = get_cpu();
  773. cpu_clear(this_cpu, mask);
  774. #ifdef CONFIG_DEBUG_DCFLUSH
  775. atomic_inc(&dcpage_flushes);
  776. #endif
  777. if (cpus_empty(mask))
  778. goto flush_self;
  779. if (tlb_type == spitfire) {
  780. data0 = ((u64)&xcall_flush_dcache_page_spitfire);
  781. if (page_mapping(page) != NULL)
  782. data0 |= ((u64)1 << 32);
  783. spitfire_xcall_deliver(data0,
  784. __pa(pg_addr),
  785. (u64) pg_addr,
  786. mask);
  787. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  788. #ifdef DCACHE_ALIASING_POSSIBLE
  789. data0 = ((u64)&xcall_flush_dcache_page_cheetah);
  790. cheetah_xcall_deliver(data0,
  791. __pa(pg_addr),
  792. 0, mask);
  793. #endif
  794. }
  795. #ifdef CONFIG_DEBUG_DCFLUSH
  796. atomic_inc(&dcpage_flushes_xcall);
  797. #endif
  798. flush_self:
  799. __local_flush_dcache_page(page);
  800. put_cpu();
  801. }
  802. static void __smp_receive_signal_mask(cpumask_t mask)
  803. {
  804. smp_cross_call_masked(&xcall_receive_signal, 0, 0, 0, mask);
  805. }
  806. void smp_receive_signal(int cpu)
  807. {
  808. cpumask_t mask = cpumask_of_cpu(cpu);
  809. if (cpu_online(cpu))
  810. __smp_receive_signal_mask(mask);
  811. }
  812. void smp_receive_signal_client(int irq, struct pt_regs *regs)
  813. {
  814. clear_softint(1 << irq);
  815. }
  816. void smp_new_mmu_context_version_client(int irq, struct pt_regs *regs)
  817. {
  818. struct mm_struct *mm;
  819. unsigned long flags;
  820. clear_softint(1 << irq);
  821. /* See if we need to allocate a new TLB context because
  822. * the version of the one we are using is now out of date.
  823. */
  824. mm = current->active_mm;
  825. if (unlikely(!mm || (mm == &init_mm)))
  826. return;
  827. spin_lock_irqsave(&mm->context.lock, flags);
  828. if (unlikely(!CTX_VALID(mm->context)))
  829. get_new_mmu_context(mm);
  830. spin_unlock_irqrestore(&mm->context.lock, flags);
  831. load_secondary_context(mm);
  832. __flush_tlb_mm(CTX_HWBITS(mm->context),
  833. SECONDARY_CONTEXT);
  834. }
  835. void smp_new_mmu_context_version(void)
  836. {
  837. smp_cross_call(&xcall_new_mmu_context_version, 0, 0, 0);
  838. }
  839. void smp_report_regs(void)
  840. {
  841. smp_cross_call(&xcall_report_regs, 0, 0, 0);
  842. }
  843. /* We know that the window frames of the user have been flushed
  844. * to the stack before we get here because all callers of us
  845. * are flush_tlb_*() routines, and these run after flush_cache_*()
  846. * which performs the flushw.
  847. *
  848. * The SMP TLB coherency scheme we use works as follows:
  849. *
  850. * 1) mm->cpu_vm_mask is a bit mask of which cpus an address
  851. * space has (potentially) executed on, this is the heuristic
  852. * we use to avoid doing cross calls.
  853. *
  854. * Also, for flushing from kswapd and also for clones, we
  855. * use cpu_vm_mask as the list of cpus to make run the TLB.
  856. *
  857. * 2) TLB context numbers are shared globally across all processors
  858. * in the system, this allows us to play several games to avoid
  859. * cross calls.
  860. *
  861. * One invariant is that when a cpu switches to a process, and
  862. * that processes tsk->active_mm->cpu_vm_mask does not have the
  863. * current cpu's bit set, that tlb context is flushed locally.
  864. *
  865. * If the address space is non-shared (ie. mm->count == 1) we avoid
  866. * cross calls when we want to flush the currently running process's
  867. * tlb state. This is done by clearing all cpu bits except the current
  868. * processor's in current->active_mm->cpu_vm_mask and performing the
  869. * flush locally only. This will force any subsequent cpus which run
  870. * this task to flush the context from the local tlb if the process
  871. * migrates to another cpu (again).
  872. *
  873. * 3) For shared address spaces (threads) and swapping we bite the
  874. * bullet for most cases and perform the cross call (but only to
  875. * the cpus listed in cpu_vm_mask).
  876. *
  877. * The performance gain from "optimizing" away the cross call for threads is
  878. * questionable (in theory the big win for threads is the massive sharing of
  879. * address space state across processors).
  880. */
  881. /* This currently is only used by the hugetlb arch pre-fault
  882. * hook on UltraSPARC-III+ and later when changing the pagesize
  883. * bits of the context register for an address space.
  884. */
  885. void smp_flush_tlb_mm(struct mm_struct *mm)
  886. {
  887. u32 ctx = CTX_HWBITS(mm->context);
  888. int cpu = get_cpu();
  889. if (atomic_read(&mm->mm_users) == 1) {
  890. mm->cpu_vm_mask = cpumask_of_cpu(cpu);
  891. goto local_flush_and_out;
  892. }
  893. smp_cross_call_masked(&xcall_flush_tlb_mm,
  894. ctx, 0, 0,
  895. mm->cpu_vm_mask);
  896. local_flush_and_out:
  897. __flush_tlb_mm(ctx, SECONDARY_CONTEXT);
  898. put_cpu();
  899. }
  900. void smp_flush_tlb_pending(struct mm_struct *mm, unsigned long nr, unsigned long *vaddrs)
  901. {
  902. u32 ctx = CTX_HWBITS(mm->context);
  903. int cpu = get_cpu();
  904. if (mm == current->active_mm && atomic_read(&mm->mm_users) == 1)
  905. mm->cpu_vm_mask = cpumask_of_cpu(cpu);
  906. else
  907. smp_cross_call_masked(&xcall_flush_tlb_pending,
  908. ctx, nr, (unsigned long) vaddrs,
  909. mm->cpu_vm_mask);
  910. __flush_tlb_pending(ctx, nr, vaddrs);
  911. put_cpu();
  912. }
  913. void smp_flush_tlb_kernel_range(unsigned long start, unsigned long end)
  914. {
  915. start &= PAGE_MASK;
  916. end = PAGE_ALIGN(end);
  917. if (start != end) {
  918. smp_cross_call(&xcall_flush_tlb_kernel_range,
  919. 0, start, end);
  920. __flush_tlb_kernel_range(start, end);
  921. }
  922. }
  923. /* CPU capture. */
  924. /* #define CAPTURE_DEBUG */
  925. extern unsigned long xcall_capture;
  926. static atomic_t smp_capture_depth = ATOMIC_INIT(0);
  927. static atomic_t smp_capture_registry = ATOMIC_INIT(0);
  928. static unsigned long penguins_are_doing_time;
  929. void smp_capture(void)
  930. {
  931. int result = atomic_add_ret(1, &smp_capture_depth);
  932. if (result == 1) {
  933. int ncpus = num_online_cpus();
  934. #ifdef CAPTURE_DEBUG
  935. printk("CPU[%d]: Sending penguins to jail...",
  936. smp_processor_id());
  937. #endif
  938. penguins_are_doing_time = 1;
  939. membar_storestore_loadstore();
  940. atomic_inc(&smp_capture_registry);
  941. smp_cross_call(&xcall_capture, 0, 0, 0);
  942. while (atomic_read(&smp_capture_registry) != ncpus)
  943. rmb();
  944. #ifdef CAPTURE_DEBUG
  945. printk("done\n");
  946. #endif
  947. }
  948. }
  949. void smp_release(void)
  950. {
  951. if (atomic_dec_and_test(&smp_capture_depth)) {
  952. #ifdef CAPTURE_DEBUG
  953. printk("CPU[%d]: Giving pardon to "
  954. "imprisoned penguins\n",
  955. smp_processor_id());
  956. #endif
  957. penguins_are_doing_time = 0;
  958. membar_storeload_storestore();
  959. atomic_dec(&smp_capture_registry);
  960. }
  961. }
  962. /* Imprisoned penguins run with %pil == 15, but PSTATE_IE set, so they
  963. * can service tlb flush xcalls...
  964. */
  965. extern void prom_world(int);
  966. void smp_penguin_jailcell(int irq, struct pt_regs *regs)
  967. {
  968. clear_softint(1 << irq);
  969. preempt_disable();
  970. __asm__ __volatile__("flushw");
  971. prom_world(1);
  972. atomic_inc(&smp_capture_registry);
  973. membar_storeload_storestore();
  974. while (penguins_are_doing_time)
  975. rmb();
  976. atomic_dec(&smp_capture_registry);
  977. prom_world(0);
  978. preempt_enable();
  979. }
  980. #define prof_multiplier(__cpu) cpu_data(__cpu).multiplier
  981. #define prof_counter(__cpu) cpu_data(__cpu).counter
  982. void smp_percpu_timer_interrupt(struct pt_regs *regs)
  983. {
  984. unsigned long compare, tick, pstate;
  985. int cpu = smp_processor_id();
  986. int user = user_mode(regs);
  987. /*
  988. * Check for level 14 softint.
  989. */
  990. {
  991. unsigned long tick_mask = tick_ops->softint_mask;
  992. if (!(get_softint() & tick_mask)) {
  993. extern void handler_irq(int, struct pt_regs *);
  994. handler_irq(14, regs);
  995. return;
  996. }
  997. clear_softint(tick_mask);
  998. }
  999. do {
  1000. profile_tick(CPU_PROFILING, regs);
  1001. if (!--prof_counter(cpu)) {
  1002. irq_enter();
  1003. if (cpu == boot_cpu_id) {
  1004. kstat_this_cpu.irqs[0]++;
  1005. timer_tick_interrupt(regs);
  1006. }
  1007. update_process_times(user);
  1008. irq_exit();
  1009. prof_counter(cpu) = prof_multiplier(cpu);
  1010. }
  1011. /* Guarantee that the following sequences execute
  1012. * uninterrupted.
  1013. */
  1014. __asm__ __volatile__("rdpr %%pstate, %0\n\t"
  1015. "wrpr %0, %1, %%pstate"
  1016. : "=r" (pstate)
  1017. : "i" (PSTATE_IE));
  1018. compare = tick_ops->add_compare(current_tick_offset);
  1019. tick = tick_ops->get_tick();
  1020. /* Restore PSTATE_IE. */
  1021. __asm__ __volatile__("wrpr %0, 0x0, %%pstate"
  1022. : /* no outputs */
  1023. : "r" (pstate));
  1024. } while (time_after_eq(tick, compare));
  1025. }
  1026. static void __init smp_setup_percpu_timer(void)
  1027. {
  1028. int cpu = smp_processor_id();
  1029. unsigned long pstate;
  1030. prof_counter(cpu) = prof_multiplier(cpu) = 1;
  1031. /* Guarantee that the following sequences execute
  1032. * uninterrupted.
  1033. */
  1034. __asm__ __volatile__("rdpr %%pstate, %0\n\t"
  1035. "wrpr %0, %1, %%pstate"
  1036. : "=r" (pstate)
  1037. : "i" (PSTATE_IE));
  1038. tick_ops->init_tick(current_tick_offset);
  1039. /* Restore PSTATE_IE. */
  1040. __asm__ __volatile__("wrpr %0, 0x0, %%pstate"
  1041. : /* no outputs */
  1042. : "r" (pstate));
  1043. }
  1044. void __init smp_tick_init(void)
  1045. {
  1046. boot_cpu_id = hard_smp_processor_id();
  1047. current_tick_offset = timer_tick_offset;
  1048. cpu_set(boot_cpu_id, cpu_online_map);
  1049. prof_counter(boot_cpu_id) = prof_multiplier(boot_cpu_id) = 1;
  1050. }
  1051. /* /proc/profile writes can call this, don't __init it please. */
  1052. static DEFINE_SPINLOCK(prof_setup_lock);
  1053. int setup_profiling_timer(unsigned int multiplier)
  1054. {
  1055. unsigned long flags;
  1056. int i;
  1057. if ((!multiplier) || (timer_tick_offset / multiplier) < 1000)
  1058. return -EINVAL;
  1059. spin_lock_irqsave(&prof_setup_lock, flags);
  1060. for (i = 0; i < NR_CPUS; i++)
  1061. prof_multiplier(i) = multiplier;
  1062. current_tick_offset = (timer_tick_offset / multiplier);
  1063. spin_unlock_irqrestore(&prof_setup_lock, flags);
  1064. return 0;
  1065. }
  1066. /* Constrain the number of cpus to max_cpus. */
  1067. void __init smp_prepare_cpus(unsigned int max_cpus)
  1068. {
  1069. int i;
  1070. if (num_possible_cpus() > max_cpus) {
  1071. int instance, mid;
  1072. instance = 0;
  1073. while (!cpu_find_by_instance(instance, NULL, &mid)) {
  1074. if (mid != boot_cpu_id) {
  1075. cpu_clear(mid, phys_cpu_present_map);
  1076. if (num_possible_cpus() <= max_cpus)
  1077. break;
  1078. }
  1079. instance++;
  1080. }
  1081. }
  1082. for_each_cpu(i) {
  1083. if (tlb_type == hypervisor) {
  1084. int j;
  1085. /* XXX get this mapping from machine description */
  1086. for_each_cpu(j) {
  1087. if ((j >> 2) == (i >> 2))
  1088. cpu_set(j, cpu_sibling_map[i]);
  1089. }
  1090. } else {
  1091. cpu_set(i, cpu_sibling_map[i]);
  1092. }
  1093. }
  1094. smp_store_cpu_info(boot_cpu_id);
  1095. }
  1096. /* Set this up early so that things like the scheduler can init
  1097. * properly. We use the same cpu mask for both the present and
  1098. * possible cpu map.
  1099. */
  1100. void __init smp_setup_cpu_possible_map(void)
  1101. {
  1102. int instance, mid;
  1103. instance = 0;
  1104. while (!cpu_find_by_instance(instance, NULL, &mid)) {
  1105. if (mid < NR_CPUS)
  1106. cpu_set(mid, phys_cpu_present_map);
  1107. instance++;
  1108. }
  1109. }
  1110. void __devinit smp_prepare_boot_cpu(void)
  1111. {
  1112. int cpu = hard_smp_processor_id();
  1113. if (cpu >= NR_CPUS) {
  1114. prom_printf("Serious problem, boot cpu id >= NR_CPUS\n");
  1115. prom_halt();
  1116. }
  1117. current_thread_info()->cpu = cpu;
  1118. __local_per_cpu_offset = __per_cpu_offset(cpu);
  1119. cpu_set(smp_processor_id(), cpu_online_map);
  1120. cpu_set(smp_processor_id(), phys_cpu_present_map);
  1121. }
  1122. int __devinit __cpu_up(unsigned int cpu)
  1123. {
  1124. int ret = smp_boot_one_cpu(cpu);
  1125. if (!ret) {
  1126. cpu_set(cpu, smp_commenced_mask);
  1127. while (!cpu_isset(cpu, cpu_online_map))
  1128. mb();
  1129. if (!cpu_isset(cpu, cpu_online_map)) {
  1130. ret = -ENODEV;
  1131. } else {
  1132. /* On SUN4V, writes to %tick and %stick are
  1133. * not allowed.
  1134. */
  1135. if (tlb_type != hypervisor)
  1136. smp_synchronize_one_tick(cpu);
  1137. }
  1138. }
  1139. return ret;
  1140. }
  1141. void __init smp_cpus_done(unsigned int max_cpus)
  1142. {
  1143. unsigned long bogosum = 0;
  1144. int i;
  1145. for (i = 0; i < NR_CPUS; i++) {
  1146. if (cpu_online(i))
  1147. bogosum += cpu_data(i).udelay_val;
  1148. }
  1149. printk("Total of %ld processors activated "
  1150. "(%lu.%02lu BogoMIPS).\n",
  1151. (long) num_online_cpus(),
  1152. bogosum/(500000/HZ),
  1153. (bogosum/(5000/HZ))%100);
  1154. }
  1155. void smp_send_reschedule(int cpu)
  1156. {
  1157. smp_receive_signal(cpu);
  1158. }
  1159. /* This is a nop because we capture all other cpus
  1160. * anyways when making the PROM active.
  1161. */
  1162. void smp_send_stop(void)
  1163. {
  1164. }
  1165. unsigned long __per_cpu_base __read_mostly;
  1166. unsigned long __per_cpu_shift __read_mostly;
  1167. EXPORT_SYMBOL(__per_cpu_base);
  1168. EXPORT_SYMBOL(__per_cpu_shift);
  1169. void __init setup_per_cpu_areas(void)
  1170. {
  1171. unsigned long goal, size, i;
  1172. char *ptr;
  1173. /* Copy section for each CPU (we discard the original) */
  1174. goal = ALIGN(__per_cpu_end - __per_cpu_start, SMP_CACHE_BYTES);
  1175. #ifdef CONFIG_MODULES
  1176. if (goal < PERCPU_ENOUGH_ROOM)
  1177. goal = PERCPU_ENOUGH_ROOM;
  1178. #endif
  1179. __per_cpu_shift = 0;
  1180. for (size = 1UL; size < goal; size <<= 1UL)
  1181. __per_cpu_shift++;
  1182. ptr = alloc_bootmem(size * NR_CPUS);
  1183. __per_cpu_base = ptr - __per_cpu_start;
  1184. for (i = 0; i < NR_CPUS; i++, ptr += size)
  1185. memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
  1186. }