smp.c 33 KB

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