smp.c 32 KB

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