smp.c 31 KB

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