smp.c 16 KB

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