smp.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. /*
  2. * linux/arch/alpha/kernel/smp.c
  3. *
  4. * 2001-07-09 Phil Ezolt (Phillip.Ezolt@compaq.com)
  5. * Renamed modified smp_call_function to smp_call_function_on_cpu()
  6. * Created an function that conforms to the old calling convention
  7. * of smp_call_function().
  8. *
  9. * This is helpful for DCPI.
  10. *
  11. */
  12. #include <linux/errno.h>
  13. #include <linux/kernel.h>
  14. #include <linux/kernel_stat.h>
  15. #include <linux/module.h>
  16. #include <linux/sched.h>
  17. #include <linux/mm.h>
  18. #include <linux/err.h>
  19. #include <linux/threads.h>
  20. #include <linux/smp.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/init.h>
  23. #include <linux/delay.h>
  24. #include <linux/spinlock.h>
  25. #include <linux/irq.h>
  26. #include <linux/cache.h>
  27. #include <linux/profile.h>
  28. #include <linux/bitops.h>
  29. #include <linux/cpu.h>
  30. #include <asm/hwrpb.h>
  31. #include <asm/ptrace.h>
  32. #include <linux/atomic.h>
  33. #include <asm/io.h>
  34. #include <asm/irq.h>
  35. #include <asm/pgtable.h>
  36. #include <asm/pgalloc.h>
  37. #include <asm/mmu_context.h>
  38. #include <asm/tlbflush.h>
  39. #include "proto.h"
  40. #include "irq_impl.h"
  41. #define DEBUG_SMP 0
  42. #if DEBUG_SMP
  43. #define DBGS(args) printk args
  44. #else
  45. #define DBGS(args)
  46. #endif
  47. /* A collection of per-processor data. */
  48. struct cpuinfo_alpha cpu_data[NR_CPUS];
  49. EXPORT_SYMBOL(cpu_data);
  50. /* A collection of single bit ipi messages. */
  51. static struct {
  52. unsigned long bits ____cacheline_aligned;
  53. } ipi_data[NR_CPUS] __cacheline_aligned;
  54. enum ipi_message_type {
  55. IPI_RESCHEDULE,
  56. IPI_CALL_FUNC,
  57. IPI_CPU_STOP,
  58. };
  59. /* Set to a secondary's cpuid when it comes online. */
  60. static int smp_secondary_alive = 0;
  61. int smp_num_probed; /* Internal processor count */
  62. int smp_num_cpus = 1; /* Number that came online. */
  63. EXPORT_SYMBOL(smp_num_cpus);
  64. /*
  65. * Called by both boot and secondaries to move global data into
  66. * per-processor storage.
  67. */
  68. static inline void __init
  69. smp_store_cpu_info(int cpuid)
  70. {
  71. cpu_data[cpuid].loops_per_jiffy = loops_per_jiffy;
  72. cpu_data[cpuid].last_asn = ASN_FIRST_VERSION;
  73. cpu_data[cpuid].need_new_asn = 0;
  74. cpu_data[cpuid].asn_lock = 0;
  75. }
  76. /*
  77. * Ideally sets up per-cpu profiling hooks. Doesn't do much now...
  78. */
  79. static inline void __init
  80. smp_setup_percpu_timer(int cpuid)
  81. {
  82. cpu_data[cpuid].prof_counter = 1;
  83. cpu_data[cpuid].prof_multiplier = 1;
  84. }
  85. static void __init
  86. wait_boot_cpu_to_stop(int cpuid)
  87. {
  88. unsigned long stop = jiffies + 10*HZ;
  89. while (time_before(jiffies, stop)) {
  90. if (!smp_secondary_alive)
  91. return;
  92. barrier();
  93. }
  94. printk("wait_boot_cpu_to_stop: FAILED on CPU %d, hanging now\n", cpuid);
  95. for (;;)
  96. barrier();
  97. }
  98. /*
  99. * Where secondaries begin a life of C.
  100. */
  101. void
  102. smp_callin(void)
  103. {
  104. int cpuid = hard_smp_processor_id();
  105. if (cpu_online(cpuid)) {
  106. printk("??, cpu 0x%x already present??\n", cpuid);
  107. BUG();
  108. }
  109. set_cpu_online(cpuid, true);
  110. /* Turn on machine checks. */
  111. wrmces(7);
  112. /* Set trap vectors. */
  113. trap_init();
  114. /* Set interrupt vector. */
  115. wrent(entInt, 0);
  116. /* Get our local ticker going. */
  117. smp_setup_percpu_timer(cpuid);
  118. init_clockevent();
  119. /* Call platform-specific callin, if specified */
  120. if (alpha_mv.smp_callin)
  121. alpha_mv.smp_callin();
  122. /* All kernel threads share the same mm context. */
  123. atomic_inc(&init_mm.mm_count);
  124. current->active_mm = &init_mm;
  125. /* inform the notifiers about the new cpu */
  126. notify_cpu_starting(cpuid);
  127. /* Must have completely accurate bogos. */
  128. local_irq_enable();
  129. /* Wait boot CPU to stop with irq enabled before running
  130. calibrate_delay. */
  131. wait_boot_cpu_to_stop(cpuid);
  132. mb();
  133. calibrate_delay();
  134. smp_store_cpu_info(cpuid);
  135. /* Allow master to continue only after we written loops_per_jiffy. */
  136. wmb();
  137. smp_secondary_alive = 1;
  138. DBGS(("smp_callin: commencing CPU %d current %p active_mm %p\n",
  139. cpuid, current, current->active_mm));
  140. preempt_disable();
  141. cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
  142. }
  143. /* Wait until hwrpb->txrdy is clear for cpu. Return -1 on timeout. */
  144. static int
  145. wait_for_txrdy (unsigned long cpumask)
  146. {
  147. unsigned long timeout;
  148. if (!(hwrpb->txrdy & cpumask))
  149. return 0;
  150. timeout = jiffies + 10*HZ;
  151. while (time_before(jiffies, timeout)) {
  152. if (!(hwrpb->txrdy & cpumask))
  153. return 0;
  154. udelay(10);
  155. barrier();
  156. }
  157. return -1;
  158. }
  159. /*
  160. * Send a message to a secondary's console. "START" is one such
  161. * interesting message. ;-)
  162. */
  163. static void
  164. send_secondary_console_msg(char *str, int cpuid)
  165. {
  166. struct percpu_struct *cpu;
  167. register char *cp1, *cp2;
  168. unsigned long cpumask;
  169. size_t len;
  170. cpu = (struct percpu_struct *)
  171. ((char*)hwrpb
  172. + hwrpb->processor_offset
  173. + cpuid * hwrpb->processor_size);
  174. cpumask = (1UL << cpuid);
  175. if (wait_for_txrdy(cpumask))
  176. goto timeout;
  177. cp2 = str;
  178. len = strlen(cp2);
  179. *(unsigned int *)&cpu->ipc_buffer[0] = len;
  180. cp1 = (char *) &cpu->ipc_buffer[1];
  181. memcpy(cp1, cp2, len);
  182. /* atomic test and set */
  183. wmb();
  184. set_bit(cpuid, &hwrpb->rxrdy);
  185. if (wait_for_txrdy(cpumask))
  186. goto timeout;
  187. return;
  188. timeout:
  189. printk("Processor %x not ready\n", cpuid);
  190. }
  191. /*
  192. * A secondary console wants to send a message. Receive it.
  193. */
  194. static void
  195. recv_secondary_console_msg(void)
  196. {
  197. int mycpu, i, cnt;
  198. unsigned long txrdy = hwrpb->txrdy;
  199. char *cp1, *cp2, buf[80];
  200. struct percpu_struct *cpu;
  201. DBGS(("recv_secondary_console_msg: TXRDY 0x%lx.\n", txrdy));
  202. mycpu = hard_smp_processor_id();
  203. for (i = 0; i < NR_CPUS; i++) {
  204. if (!(txrdy & (1UL << i)))
  205. continue;
  206. DBGS(("recv_secondary_console_msg: "
  207. "TXRDY contains CPU %d.\n", i));
  208. cpu = (struct percpu_struct *)
  209. ((char*)hwrpb
  210. + hwrpb->processor_offset
  211. + i * hwrpb->processor_size);
  212. DBGS(("recv_secondary_console_msg: on %d from %d"
  213. " HALT_REASON 0x%lx FLAGS 0x%lx\n",
  214. mycpu, i, cpu->halt_reason, cpu->flags));
  215. cnt = cpu->ipc_buffer[0] >> 32;
  216. if (cnt <= 0 || cnt >= 80)
  217. strcpy(buf, "<<< BOGUS MSG >>>");
  218. else {
  219. cp1 = (char *) &cpu->ipc_buffer[1];
  220. cp2 = buf;
  221. memcpy(cp2, cp1, cnt);
  222. cp2[cnt] = '\0';
  223. while ((cp2 = strchr(cp2, '\r')) != 0) {
  224. *cp2 = ' ';
  225. if (cp2[1] == '\n')
  226. cp2[1] = ' ';
  227. }
  228. }
  229. DBGS((KERN_INFO "recv_secondary_console_msg: on %d "
  230. "message is '%s'\n", mycpu, buf));
  231. }
  232. hwrpb->txrdy = 0;
  233. }
  234. /*
  235. * Convince the console to have a secondary cpu begin execution.
  236. */
  237. static int
  238. secondary_cpu_start(int cpuid, struct task_struct *idle)
  239. {
  240. struct percpu_struct *cpu;
  241. struct pcb_struct *hwpcb, *ipcb;
  242. unsigned long timeout;
  243. cpu = (struct percpu_struct *)
  244. ((char*)hwrpb
  245. + hwrpb->processor_offset
  246. + cpuid * hwrpb->processor_size);
  247. hwpcb = (struct pcb_struct *) cpu->hwpcb;
  248. ipcb = &task_thread_info(idle)->pcb;
  249. /* Initialize the CPU's HWPCB to something just good enough for
  250. us to get started. Immediately after starting, we'll swpctx
  251. to the target idle task's pcb. Reuse the stack in the mean
  252. time. Precalculate the target PCBB. */
  253. hwpcb->ksp = (unsigned long)ipcb + sizeof(union thread_union) - 16;
  254. hwpcb->usp = 0;
  255. hwpcb->ptbr = ipcb->ptbr;
  256. hwpcb->pcc = 0;
  257. hwpcb->asn = 0;
  258. hwpcb->unique = virt_to_phys(ipcb);
  259. hwpcb->flags = ipcb->flags;
  260. hwpcb->res1 = hwpcb->res2 = 0;
  261. #if 0
  262. DBGS(("KSP 0x%lx PTBR 0x%lx VPTBR 0x%lx UNIQUE 0x%lx\n",
  263. hwpcb->ksp, hwpcb->ptbr, hwrpb->vptb, hwpcb->unique));
  264. #endif
  265. DBGS(("Starting secondary cpu %d: state 0x%lx pal_flags 0x%lx\n",
  266. cpuid, idle->state, ipcb->flags));
  267. /* Setup HWRPB fields that SRM uses to activate secondary CPU */
  268. hwrpb->CPU_restart = __smp_callin;
  269. hwrpb->CPU_restart_data = (unsigned long) __smp_callin;
  270. /* Recalculate and update the HWRPB checksum */
  271. hwrpb_update_checksum(hwrpb);
  272. /*
  273. * Send a "start" command to the specified processor.
  274. */
  275. /* SRM III 3.4.1.3 */
  276. cpu->flags |= 0x22; /* turn on Context Valid and Restart Capable */
  277. cpu->flags &= ~1; /* turn off Bootstrap In Progress */
  278. wmb();
  279. send_secondary_console_msg("START\r\n", cpuid);
  280. /* Wait 10 seconds for an ACK from the console. */
  281. timeout = jiffies + 10*HZ;
  282. while (time_before(jiffies, timeout)) {
  283. if (cpu->flags & 1)
  284. goto started;
  285. udelay(10);
  286. barrier();
  287. }
  288. printk(KERN_ERR "SMP: Processor %d failed to start.\n", cpuid);
  289. return -1;
  290. started:
  291. DBGS(("secondary_cpu_start: SUCCESS for CPU %d!!!\n", cpuid));
  292. return 0;
  293. }
  294. /*
  295. * Bring one cpu online.
  296. */
  297. static int
  298. smp_boot_one_cpu(int cpuid, struct task_struct *idle)
  299. {
  300. unsigned long timeout;
  301. /* Signal the secondary to wait a moment. */
  302. smp_secondary_alive = -1;
  303. /* Whirrr, whirrr, whirrrrrrrrr... */
  304. if (secondary_cpu_start(cpuid, idle))
  305. return -1;
  306. /* Notify the secondary CPU it can run calibrate_delay. */
  307. mb();
  308. smp_secondary_alive = 0;
  309. /* We've been acked by the console; wait one second for
  310. the task to start up for real. */
  311. timeout = jiffies + 1*HZ;
  312. while (time_before(jiffies, timeout)) {
  313. if (smp_secondary_alive == 1)
  314. goto alive;
  315. udelay(10);
  316. barrier();
  317. }
  318. /* We failed to boot the CPU. */
  319. printk(KERN_ERR "SMP: Processor %d is stuck.\n", cpuid);
  320. return -1;
  321. alive:
  322. /* Another "Red Snapper". */
  323. return 0;
  324. }
  325. /*
  326. * Called from setup_arch. Detect an SMP system and which processors
  327. * are present.
  328. */
  329. void __init
  330. setup_smp(void)
  331. {
  332. struct percpu_struct *cpubase, *cpu;
  333. unsigned long i;
  334. if (boot_cpuid != 0) {
  335. printk(KERN_WARNING "SMP: Booting off cpu %d instead of 0?\n",
  336. boot_cpuid);
  337. }
  338. if (hwrpb->nr_processors > 1) {
  339. int boot_cpu_palrev;
  340. DBGS(("setup_smp: nr_processors %ld\n",
  341. hwrpb->nr_processors));
  342. cpubase = (struct percpu_struct *)
  343. ((char*)hwrpb + hwrpb->processor_offset);
  344. boot_cpu_palrev = cpubase->pal_revision;
  345. for (i = 0; i < hwrpb->nr_processors; i++) {
  346. cpu = (struct percpu_struct *)
  347. ((char *)cpubase + i*hwrpb->processor_size);
  348. if ((cpu->flags & 0x1cc) == 0x1cc) {
  349. smp_num_probed++;
  350. set_cpu_possible(i, true);
  351. set_cpu_present(i, true);
  352. cpu->pal_revision = boot_cpu_palrev;
  353. }
  354. DBGS(("setup_smp: CPU %d: flags 0x%lx type 0x%lx\n",
  355. i, cpu->flags, cpu->type));
  356. DBGS(("setup_smp: CPU %d: PAL rev 0x%lx\n",
  357. i, cpu->pal_revision));
  358. }
  359. } else {
  360. smp_num_probed = 1;
  361. }
  362. printk(KERN_INFO "SMP: %d CPUs probed -- cpu_present_mask = %lx\n",
  363. smp_num_probed, cpumask_bits(cpu_present_mask)[0]);
  364. }
  365. /*
  366. * Called by smp_init prepare the secondaries
  367. */
  368. void __init
  369. smp_prepare_cpus(unsigned int max_cpus)
  370. {
  371. /* Take care of some initial bookkeeping. */
  372. memset(ipi_data, 0, sizeof(ipi_data));
  373. current_thread_info()->cpu = boot_cpuid;
  374. smp_store_cpu_info(boot_cpuid);
  375. smp_setup_percpu_timer(boot_cpuid);
  376. /* Nothing to do on a UP box, or when told not to. */
  377. if (smp_num_probed == 1 || max_cpus == 0) {
  378. init_cpu_possible(cpumask_of(boot_cpuid));
  379. init_cpu_present(cpumask_of(boot_cpuid));
  380. printk(KERN_INFO "SMP mode deactivated.\n");
  381. return;
  382. }
  383. printk(KERN_INFO "SMP starting up secondaries.\n");
  384. smp_num_cpus = smp_num_probed;
  385. }
  386. void
  387. smp_prepare_boot_cpu(void)
  388. {
  389. }
  390. int
  391. __cpu_up(unsigned int cpu, struct task_struct *tidle)
  392. {
  393. smp_boot_one_cpu(cpu, tidle);
  394. return cpu_online(cpu) ? 0 : -ENOSYS;
  395. }
  396. void __init
  397. smp_cpus_done(unsigned int max_cpus)
  398. {
  399. int cpu;
  400. unsigned long bogosum = 0;
  401. for(cpu = 0; cpu < NR_CPUS; cpu++)
  402. if (cpu_online(cpu))
  403. bogosum += cpu_data[cpu].loops_per_jiffy;
  404. printk(KERN_INFO "SMP: Total of %d processors activated "
  405. "(%lu.%02lu BogoMIPS).\n",
  406. num_online_cpus(),
  407. (bogosum + 2500) / (500000/HZ),
  408. ((bogosum + 2500) / (5000/HZ)) % 100);
  409. }
  410. int
  411. setup_profiling_timer(unsigned int multiplier)
  412. {
  413. return -EINVAL;
  414. }
  415. static void
  416. send_ipi_message(const struct cpumask *to_whom, enum ipi_message_type operation)
  417. {
  418. int i;
  419. mb();
  420. for_each_cpu(i, to_whom)
  421. set_bit(operation, &ipi_data[i].bits);
  422. mb();
  423. for_each_cpu(i, to_whom)
  424. wripir(i);
  425. }
  426. void
  427. handle_ipi(struct pt_regs *regs)
  428. {
  429. int this_cpu = smp_processor_id();
  430. unsigned long *pending_ipis = &ipi_data[this_cpu].bits;
  431. unsigned long ops;
  432. #if 0
  433. DBGS(("handle_ipi: on CPU %d ops 0x%lx PC 0x%lx\n",
  434. this_cpu, *pending_ipis, regs->pc));
  435. #endif
  436. mb(); /* Order interrupt and bit testing. */
  437. while ((ops = xchg(pending_ipis, 0)) != 0) {
  438. mb(); /* Order bit clearing and data access. */
  439. do {
  440. unsigned long which;
  441. which = ops & -ops;
  442. ops &= ~which;
  443. which = __ffs(which);
  444. switch (which) {
  445. case IPI_RESCHEDULE:
  446. scheduler_ipi();
  447. break;
  448. case IPI_CALL_FUNC:
  449. generic_smp_call_function_interrupt();
  450. break;
  451. case IPI_CPU_STOP:
  452. halt();
  453. default:
  454. printk(KERN_CRIT "Unknown IPI on CPU %d: %lu\n",
  455. this_cpu, which);
  456. break;
  457. }
  458. } while (ops);
  459. mb(); /* Order data access and bit testing. */
  460. }
  461. cpu_data[this_cpu].ipi_count++;
  462. if (hwrpb->txrdy)
  463. recv_secondary_console_msg();
  464. }
  465. void
  466. smp_send_reschedule(int cpu)
  467. {
  468. #ifdef DEBUG_IPI_MSG
  469. if (cpu == hard_smp_processor_id())
  470. printk(KERN_WARNING
  471. "smp_send_reschedule: Sending IPI to self.\n");
  472. #endif
  473. send_ipi_message(cpumask_of(cpu), IPI_RESCHEDULE);
  474. }
  475. void
  476. smp_send_stop(void)
  477. {
  478. cpumask_t to_whom;
  479. cpumask_copy(&to_whom, cpu_possible_mask);
  480. cpumask_clear_cpu(smp_processor_id(), &to_whom);
  481. #ifdef DEBUG_IPI_MSG
  482. if (hard_smp_processor_id() != boot_cpu_id)
  483. printk(KERN_WARNING "smp_send_stop: Not on boot cpu.\n");
  484. #endif
  485. send_ipi_message(&to_whom, IPI_CPU_STOP);
  486. }
  487. void arch_send_call_function_ipi_mask(const struct cpumask *mask)
  488. {
  489. send_ipi_message(mask, IPI_CALL_FUNC);
  490. }
  491. void arch_send_call_function_single_ipi(int cpu)
  492. {
  493. send_ipi_message(cpumask_of(cpu), IPI_CALL_FUNC);
  494. }
  495. static void
  496. ipi_imb(void *ignored)
  497. {
  498. imb();
  499. }
  500. void
  501. smp_imb(void)
  502. {
  503. /* Must wait other processors to flush their icache before continue. */
  504. if (on_each_cpu(ipi_imb, NULL, 1))
  505. printk(KERN_CRIT "smp_imb: timed out\n");
  506. }
  507. EXPORT_SYMBOL(smp_imb);
  508. static void
  509. ipi_flush_tlb_all(void *ignored)
  510. {
  511. tbia();
  512. }
  513. void
  514. flush_tlb_all(void)
  515. {
  516. /* Although we don't have any data to pass, we do want to
  517. synchronize with the other processors. */
  518. if (on_each_cpu(ipi_flush_tlb_all, NULL, 1)) {
  519. printk(KERN_CRIT "flush_tlb_all: timed out\n");
  520. }
  521. }
  522. #define asn_locked() (cpu_data[smp_processor_id()].asn_lock)
  523. static void
  524. ipi_flush_tlb_mm(void *x)
  525. {
  526. struct mm_struct *mm = (struct mm_struct *) x;
  527. if (mm == current->active_mm && !asn_locked())
  528. flush_tlb_current(mm);
  529. else
  530. flush_tlb_other(mm);
  531. }
  532. void
  533. flush_tlb_mm(struct mm_struct *mm)
  534. {
  535. preempt_disable();
  536. if (mm == current->active_mm) {
  537. flush_tlb_current(mm);
  538. if (atomic_read(&mm->mm_users) <= 1) {
  539. int cpu, this_cpu = smp_processor_id();
  540. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  541. if (!cpu_online(cpu) || cpu == this_cpu)
  542. continue;
  543. if (mm->context[cpu])
  544. mm->context[cpu] = 0;
  545. }
  546. preempt_enable();
  547. return;
  548. }
  549. }
  550. if (smp_call_function(ipi_flush_tlb_mm, mm, 1)) {
  551. printk(KERN_CRIT "flush_tlb_mm: timed out\n");
  552. }
  553. preempt_enable();
  554. }
  555. EXPORT_SYMBOL(flush_tlb_mm);
  556. struct flush_tlb_page_struct {
  557. struct vm_area_struct *vma;
  558. struct mm_struct *mm;
  559. unsigned long addr;
  560. };
  561. static void
  562. ipi_flush_tlb_page(void *x)
  563. {
  564. struct flush_tlb_page_struct *data = (struct flush_tlb_page_struct *)x;
  565. struct mm_struct * mm = data->mm;
  566. if (mm == current->active_mm && !asn_locked())
  567. flush_tlb_current_page(mm, data->vma, data->addr);
  568. else
  569. flush_tlb_other(mm);
  570. }
  571. void
  572. flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)
  573. {
  574. struct flush_tlb_page_struct data;
  575. struct mm_struct *mm = vma->vm_mm;
  576. preempt_disable();
  577. if (mm == current->active_mm) {
  578. flush_tlb_current_page(mm, vma, addr);
  579. if (atomic_read(&mm->mm_users) <= 1) {
  580. int cpu, this_cpu = smp_processor_id();
  581. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  582. if (!cpu_online(cpu) || cpu == this_cpu)
  583. continue;
  584. if (mm->context[cpu])
  585. mm->context[cpu] = 0;
  586. }
  587. preempt_enable();
  588. return;
  589. }
  590. }
  591. data.vma = vma;
  592. data.mm = mm;
  593. data.addr = addr;
  594. if (smp_call_function(ipi_flush_tlb_page, &data, 1)) {
  595. printk(KERN_CRIT "flush_tlb_page: timed out\n");
  596. }
  597. preempt_enable();
  598. }
  599. EXPORT_SYMBOL(flush_tlb_page);
  600. void
  601. flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
  602. {
  603. /* On the Alpha we always flush the whole user tlb. */
  604. flush_tlb_mm(vma->vm_mm);
  605. }
  606. EXPORT_SYMBOL(flush_tlb_range);
  607. static void
  608. ipi_flush_icache_page(void *x)
  609. {
  610. struct mm_struct *mm = (struct mm_struct *) x;
  611. if (mm == current->active_mm && !asn_locked())
  612. __load_new_mm_context(mm);
  613. else
  614. flush_tlb_other(mm);
  615. }
  616. void
  617. flush_icache_user_range(struct vm_area_struct *vma, struct page *page,
  618. unsigned long addr, int len)
  619. {
  620. struct mm_struct *mm = vma->vm_mm;
  621. if ((vma->vm_flags & VM_EXEC) == 0)
  622. return;
  623. preempt_disable();
  624. if (mm == current->active_mm) {
  625. __load_new_mm_context(mm);
  626. if (atomic_read(&mm->mm_users) <= 1) {
  627. int cpu, this_cpu = smp_processor_id();
  628. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  629. if (!cpu_online(cpu) || cpu == this_cpu)
  630. continue;
  631. if (mm->context[cpu])
  632. mm->context[cpu] = 0;
  633. }
  634. preempt_enable();
  635. return;
  636. }
  637. }
  638. if (smp_call_function(ipi_flush_icache_page, mm, 1)) {
  639. printk(KERN_CRIT "flush_icache_page: timed out\n");
  640. }
  641. preempt_enable();
  642. }