smp.c 32 KB

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