smp.c 34 KB

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