smp.c 34 KB

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