smp.c 34 KB

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