smp.c 32 KB

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