smp.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  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_CALL_FUNC_SINGLE,
  58. IPI_CPU_STOP,
  59. };
  60. /* Set to a secondary's cpuid when it comes online. */
  61. static int smp_secondary_alive __devinitdata = 0;
  62. int smp_num_probed; /* Internal processor count */
  63. int smp_num_cpus = 1; /* Number that came online. */
  64. EXPORT_SYMBOL(smp_num_cpus);
  65. /*
  66. * Called by both boot and secondaries to move global data into
  67. * per-processor storage.
  68. */
  69. static inline void __init
  70. smp_store_cpu_info(int cpuid)
  71. {
  72. cpu_data[cpuid].loops_per_jiffy = loops_per_jiffy;
  73. cpu_data[cpuid].last_asn = ASN_FIRST_VERSION;
  74. cpu_data[cpuid].need_new_asn = 0;
  75. cpu_data[cpuid].asn_lock = 0;
  76. }
  77. /*
  78. * Ideally sets up per-cpu profiling hooks. Doesn't do much now...
  79. */
  80. static inline void __init
  81. smp_setup_percpu_timer(int cpuid)
  82. {
  83. cpu_data[cpuid].prof_counter = 1;
  84. cpu_data[cpuid].prof_multiplier = 1;
  85. }
  86. static void __init
  87. wait_boot_cpu_to_stop(int cpuid)
  88. {
  89. unsigned long stop = jiffies + 10*HZ;
  90. while (time_before(jiffies, stop)) {
  91. if (!smp_secondary_alive)
  92. return;
  93. barrier();
  94. }
  95. printk("wait_boot_cpu_to_stop: FAILED on CPU %d, hanging now\n", cpuid);
  96. for (;;)
  97. barrier();
  98. }
  99. /*
  100. * Where secondaries begin a life of C.
  101. */
  102. void __cpuinit
  103. smp_callin(void)
  104. {
  105. int cpuid = hard_smp_processor_id();
  106. if (cpu_online(cpuid)) {
  107. printk("??, cpu 0x%x already present??\n", cpuid);
  108. BUG();
  109. }
  110. set_cpu_online(cpuid, true);
  111. /* Turn on machine checks. */
  112. wrmces(7);
  113. /* Set trap vectors. */
  114. trap_init();
  115. /* Set interrupt vector. */
  116. wrent(entInt, 0);
  117. /* Get our local ticker going. */
  118. smp_setup_percpu_timer(cpuid);
  119. /* Call platform-specific callin, if specified */
  120. if (alpha_mv.smp_callin) alpha_mv.smp_callin();
  121. /* All kernel threads share the same mm context. */
  122. atomic_inc(&init_mm.mm_count);
  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. /* Do nothing. */
  140. cpu_idle();
  141. }
  142. /* Wait until hwrpb->txrdy is clear for cpu. Return -1 on timeout. */
  143. static int __devinit
  144. wait_for_txrdy (unsigned long cpumask)
  145. {
  146. unsigned long timeout;
  147. if (!(hwrpb->txrdy & cpumask))
  148. return 0;
  149. timeout = jiffies + 10*HZ;
  150. while (time_before(jiffies, timeout)) {
  151. if (!(hwrpb->txrdy & cpumask))
  152. return 0;
  153. udelay(10);
  154. barrier();
  155. }
  156. return -1;
  157. }
  158. /*
  159. * Send a message to a secondary's console. "START" is one such
  160. * interesting message. ;-)
  161. */
  162. static void __cpuinit
  163. send_secondary_console_msg(char *str, int cpuid)
  164. {
  165. struct percpu_struct *cpu;
  166. register char *cp1, *cp2;
  167. unsigned long cpumask;
  168. size_t len;
  169. cpu = (struct percpu_struct *)
  170. ((char*)hwrpb
  171. + hwrpb->processor_offset
  172. + cpuid * hwrpb->processor_size);
  173. cpumask = (1UL << cpuid);
  174. if (wait_for_txrdy(cpumask))
  175. goto timeout;
  176. cp2 = str;
  177. len = strlen(cp2);
  178. *(unsigned int *)&cpu->ipc_buffer[0] = len;
  179. cp1 = (char *) &cpu->ipc_buffer[1];
  180. memcpy(cp1, cp2, len);
  181. /* atomic test and set */
  182. wmb();
  183. set_bit(cpuid, &hwrpb->rxrdy);
  184. if (wait_for_txrdy(cpumask))
  185. goto timeout;
  186. return;
  187. timeout:
  188. printk("Processor %x not ready\n", cpuid);
  189. }
  190. /*
  191. * A secondary console wants to send a message. Receive it.
  192. */
  193. static void
  194. recv_secondary_console_msg(void)
  195. {
  196. int mycpu, i, cnt;
  197. unsigned long txrdy = hwrpb->txrdy;
  198. char *cp1, *cp2, buf[80];
  199. struct percpu_struct *cpu;
  200. DBGS(("recv_secondary_console_msg: TXRDY 0x%lx.\n", txrdy));
  201. mycpu = hard_smp_processor_id();
  202. for (i = 0; i < NR_CPUS; i++) {
  203. if (!(txrdy & (1UL << i)))
  204. continue;
  205. DBGS(("recv_secondary_console_msg: "
  206. "TXRDY contains CPU %d.\n", i));
  207. cpu = (struct percpu_struct *)
  208. ((char*)hwrpb
  209. + hwrpb->processor_offset
  210. + i * hwrpb->processor_size);
  211. DBGS(("recv_secondary_console_msg: on %d from %d"
  212. " HALT_REASON 0x%lx FLAGS 0x%lx\n",
  213. mycpu, i, cpu->halt_reason, cpu->flags));
  214. cnt = cpu->ipc_buffer[0] >> 32;
  215. if (cnt <= 0 || cnt >= 80)
  216. strcpy(buf, "<<< BOGUS MSG >>>");
  217. else {
  218. cp1 = (char *) &cpu->ipc_buffer[11];
  219. cp2 = buf;
  220. strcpy(cp2, cp1);
  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 __cpuinit
  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 __cpuinit
  296. smp_boot_one_cpu(int cpuid)
  297. {
  298. struct task_struct *idle;
  299. unsigned long timeout;
  300. /* Cook up an idler for this guy. Note that the address we
  301. give to kernel_thread is irrelevant -- it's going to start
  302. where HWRPB.CPU_restart says to start. But this gets all
  303. the other task-y sort of data structures set up like we
  304. wish. We can't use kernel_thread since we must avoid
  305. rescheduling the child. */
  306. idle = fork_idle(cpuid);
  307. if (IS_ERR(idle))
  308. panic("failed fork for CPU %d", cpuid);
  309. DBGS(("smp_boot_one_cpu: CPU %d state 0x%lx flags 0x%lx\n",
  310. cpuid, idle->state, idle->flags));
  311. /* Signal the secondary to wait a moment. */
  312. smp_secondary_alive = -1;
  313. /* Whirrr, whirrr, whirrrrrrrrr... */
  314. if (secondary_cpu_start(cpuid, idle))
  315. return -1;
  316. /* Notify the secondary CPU it can run calibrate_delay. */
  317. mb();
  318. smp_secondary_alive = 0;
  319. /* We've been acked by the console; wait one second for
  320. the task to start up for real. */
  321. timeout = jiffies + 1*HZ;
  322. while (time_before(jiffies, timeout)) {
  323. if (smp_secondary_alive == 1)
  324. goto alive;
  325. udelay(10);
  326. barrier();
  327. }
  328. /* We failed to boot the CPU. */
  329. printk(KERN_ERR "SMP: Processor %d is stuck.\n", cpuid);
  330. return -1;
  331. alive:
  332. /* Another "Red Snapper". */
  333. return 0;
  334. }
  335. /*
  336. * Called from setup_arch. Detect an SMP system and which processors
  337. * are present.
  338. */
  339. void __init
  340. setup_smp(void)
  341. {
  342. struct percpu_struct *cpubase, *cpu;
  343. unsigned long i;
  344. if (boot_cpuid != 0) {
  345. printk(KERN_WARNING "SMP: Booting off cpu %d instead of 0?\n",
  346. boot_cpuid);
  347. }
  348. if (hwrpb->nr_processors > 1) {
  349. int boot_cpu_palrev;
  350. DBGS(("setup_smp: nr_processors %ld\n",
  351. hwrpb->nr_processors));
  352. cpubase = (struct percpu_struct *)
  353. ((char*)hwrpb + hwrpb->processor_offset);
  354. boot_cpu_palrev = cpubase->pal_revision;
  355. for (i = 0; i < hwrpb->nr_processors; i++) {
  356. cpu = (struct percpu_struct *)
  357. ((char *)cpubase + i*hwrpb->processor_size);
  358. if ((cpu->flags & 0x1cc) == 0x1cc) {
  359. smp_num_probed++;
  360. set_cpu_possible(i, true);
  361. set_cpu_present(i, true);
  362. cpu->pal_revision = boot_cpu_palrev;
  363. }
  364. DBGS(("setup_smp: CPU %d: flags 0x%lx type 0x%lx\n",
  365. i, cpu->flags, cpu->type));
  366. DBGS(("setup_smp: CPU %d: PAL rev 0x%lx\n",
  367. i, cpu->pal_revision));
  368. }
  369. } else {
  370. smp_num_probed = 1;
  371. }
  372. printk(KERN_INFO "SMP: %d CPUs probed -- cpu_present_mask = %lx\n",
  373. smp_num_probed, cpumask_bits(cpu_present_mask)[0]);
  374. }
  375. /*
  376. * Called by smp_init prepare the secondaries
  377. */
  378. void __init
  379. smp_prepare_cpus(unsigned int max_cpus)
  380. {
  381. /* Take care of some initial bookkeeping. */
  382. memset(ipi_data, 0, sizeof(ipi_data));
  383. current_thread_info()->cpu = boot_cpuid;
  384. smp_store_cpu_info(boot_cpuid);
  385. smp_setup_percpu_timer(boot_cpuid);
  386. /* Nothing to do on a UP box, or when told not to. */
  387. if (smp_num_probed == 1 || max_cpus == 0) {
  388. init_cpu_possible(cpumask_of(boot_cpuid));
  389. init_cpu_present(cpumask_of(boot_cpuid));
  390. printk(KERN_INFO "SMP mode deactivated.\n");
  391. return;
  392. }
  393. printk(KERN_INFO "SMP starting up secondaries.\n");
  394. smp_num_cpus = smp_num_probed;
  395. }
  396. void __devinit
  397. smp_prepare_boot_cpu(void)
  398. {
  399. }
  400. int __cpuinit
  401. __cpu_up(unsigned int cpu)
  402. {
  403. smp_boot_one_cpu(cpu);
  404. return cpu_online(cpu) ? 0 : -ENOSYS;
  405. }
  406. void __init
  407. smp_cpus_done(unsigned int max_cpus)
  408. {
  409. int cpu;
  410. unsigned long bogosum = 0;
  411. for(cpu = 0; cpu < NR_CPUS; cpu++)
  412. if (cpu_online(cpu))
  413. bogosum += cpu_data[cpu].loops_per_jiffy;
  414. printk(KERN_INFO "SMP: Total of %d processors activated "
  415. "(%lu.%02lu BogoMIPS).\n",
  416. num_online_cpus(),
  417. (bogosum + 2500) / (500000/HZ),
  418. ((bogosum + 2500) / (5000/HZ)) % 100);
  419. }
  420. void
  421. smp_percpu_timer_interrupt(struct pt_regs *regs)
  422. {
  423. struct pt_regs *old_regs;
  424. int cpu = smp_processor_id();
  425. unsigned long user = user_mode(regs);
  426. struct cpuinfo_alpha *data = &cpu_data[cpu];
  427. old_regs = set_irq_regs(regs);
  428. /* Record kernel PC. */
  429. profile_tick(CPU_PROFILING);
  430. if (!--data->prof_counter) {
  431. /* We need to make like a normal interrupt -- otherwise
  432. timer interrupts ignore the global interrupt lock,
  433. which would be a Bad Thing. */
  434. irq_enter();
  435. update_process_times(user);
  436. data->prof_counter = data->prof_multiplier;
  437. irq_exit();
  438. }
  439. set_irq_regs(old_regs);
  440. }
  441. int
  442. setup_profiling_timer(unsigned int multiplier)
  443. {
  444. return -EINVAL;
  445. }
  446. static void
  447. send_ipi_message(const struct cpumask *to_whom, enum ipi_message_type operation)
  448. {
  449. int i;
  450. mb();
  451. for_each_cpu(i, to_whom)
  452. set_bit(operation, &ipi_data[i].bits);
  453. mb();
  454. for_each_cpu(i, to_whom)
  455. wripir(i);
  456. }
  457. void
  458. handle_ipi(struct pt_regs *regs)
  459. {
  460. int this_cpu = smp_processor_id();
  461. unsigned long *pending_ipis = &ipi_data[this_cpu].bits;
  462. unsigned long ops;
  463. #if 0
  464. DBGS(("handle_ipi: on CPU %d ops 0x%lx PC 0x%lx\n",
  465. this_cpu, *pending_ipis, regs->pc));
  466. #endif
  467. mb(); /* Order interrupt and bit testing. */
  468. while ((ops = xchg(pending_ipis, 0)) != 0) {
  469. mb(); /* Order bit clearing and data access. */
  470. do {
  471. unsigned long which;
  472. which = ops & -ops;
  473. ops &= ~which;
  474. which = __ffs(which);
  475. switch (which) {
  476. case IPI_RESCHEDULE:
  477. scheduler_ipi();
  478. break;
  479. case IPI_CALL_FUNC:
  480. generic_smp_call_function_interrupt();
  481. break;
  482. case IPI_CALL_FUNC_SINGLE:
  483. generic_smp_call_function_single_interrupt();
  484. break;
  485. case IPI_CPU_STOP:
  486. halt();
  487. default:
  488. printk(KERN_CRIT "Unknown IPI on CPU %d: %lu\n",
  489. this_cpu, which);
  490. break;
  491. }
  492. } while (ops);
  493. mb(); /* Order data access and bit testing. */
  494. }
  495. cpu_data[this_cpu].ipi_count++;
  496. if (hwrpb->txrdy)
  497. recv_secondary_console_msg();
  498. }
  499. void
  500. smp_send_reschedule(int cpu)
  501. {
  502. #ifdef DEBUG_IPI_MSG
  503. if (cpu == hard_smp_processor_id())
  504. printk(KERN_WARNING
  505. "smp_send_reschedule: Sending IPI to self.\n");
  506. #endif
  507. send_ipi_message(cpumask_of(cpu), IPI_RESCHEDULE);
  508. }
  509. void
  510. smp_send_stop(void)
  511. {
  512. cpumask_t to_whom;
  513. cpumask_copy(&to_whom, cpu_possible_mask);
  514. cpumask_clear_cpu(smp_processor_id(), &to_whom);
  515. #ifdef DEBUG_IPI_MSG
  516. if (hard_smp_processor_id() != boot_cpu_id)
  517. printk(KERN_WARNING "smp_send_stop: Not on boot cpu.\n");
  518. #endif
  519. send_ipi_message(&to_whom, IPI_CPU_STOP);
  520. }
  521. void arch_send_call_function_ipi_mask(const struct cpumask *mask)
  522. {
  523. send_ipi_message(mask, IPI_CALL_FUNC);
  524. }
  525. void arch_send_call_function_single_ipi(int cpu)
  526. {
  527. send_ipi_message(cpumask_of(cpu), IPI_CALL_FUNC_SINGLE);
  528. }
  529. static void
  530. ipi_imb(void *ignored)
  531. {
  532. imb();
  533. }
  534. void
  535. smp_imb(void)
  536. {
  537. /* Must wait other processors to flush their icache before continue. */
  538. if (on_each_cpu(ipi_imb, NULL, 1))
  539. printk(KERN_CRIT "smp_imb: timed out\n");
  540. }
  541. EXPORT_SYMBOL(smp_imb);
  542. static void
  543. ipi_flush_tlb_all(void *ignored)
  544. {
  545. tbia();
  546. }
  547. void
  548. flush_tlb_all(void)
  549. {
  550. /* Although we don't have any data to pass, we do want to
  551. synchronize with the other processors. */
  552. if (on_each_cpu(ipi_flush_tlb_all, NULL, 1)) {
  553. printk(KERN_CRIT "flush_tlb_all: timed out\n");
  554. }
  555. }
  556. #define asn_locked() (cpu_data[smp_processor_id()].asn_lock)
  557. static void
  558. ipi_flush_tlb_mm(void *x)
  559. {
  560. struct mm_struct *mm = (struct mm_struct *) x;
  561. if (mm == current->active_mm && !asn_locked())
  562. flush_tlb_current(mm);
  563. else
  564. flush_tlb_other(mm);
  565. }
  566. void
  567. flush_tlb_mm(struct mm_struct *mm)
  568. {
  569. preempt_disable();
  570. if (mm == current->active_mm) {
  571. flush_tlb_current(mm);
  572. if (atomic_read(&mm->mm_users) <= 1) {
  573. int cpu, this_cpu = smp_processor_id();
  574. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  575. if (!cpu_online(cpu) || cpu == this_cpu)
  576. continue;
  577. if (mm->context[cpu])
  578. mm->context[cpu] = 0;
  579. }
  580. preempt_enable();
  581. return;
  582. }
  583. }
  584. if (smp_call_function(ipi_flush_tlb_mm, mm, 1)) {
  585. printk(KERN_CRIT "flush_tlb_mm: timed out\n");
  586. }
  587. preempt_enable();
  588. }
  589. EXPORT_SYMBOL(flush_tlb_mm);
  590. struct flush_tlb_page_struct {
  591. struct vm_area_struct *vma;
  592. struct mm_struct *mm;
  593. unsigned long addr;
  594. };
  595. static void
  596. ipi_flush_tlb_page(void *x)
  597. {
  598. struct flush_tlb_page_struct *data = (struct flush_tlb_page_struct *)x;
  599. struct mm_struct * mm = data->mm;
  600. if (mm == current->active_mm && !asn_locked())
  601. flush_tlb_current_page(mm, data->vma, data->addr);
  602. else
  603. flush_tlb_other(mm);
  604. }
  605. void
  606. flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)
  607. {
  608. struct flush_tlb_page_struct data;
  609. struct mm_struct *mm = vma->vm_mm;
  610. preempt_disable();
  611. if (mm == current->active_mm) {
  612. flush_tlb_current_page(mm, vma, addr);
  613. if (atomic_read(&mm->mm_users) <= 1) {
  614. int cpu, this_cpu = smp_processor_id();
  615. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  616. if (!cpu_online(cpu) || cpu == this_cpu)
  617. continue;
  618. if (mm->context[cpu])
  619. mm->context[cpu] = 0;
  620. }
  621. preempt_enable();
  622. return;
  623. }
  624. }
  625. data.vma = vma;
  626. data.mm = mm;
  627. data.addr = addr;
  628. if (smp_call_function(ipi_flush_tlb_page, &data, 1)) {
  629. printk(KERN_CRIT "flush_tlb_page: timed out\n");
  630. }
  631. preempt_enable();
  632. }
  633. EXPORT_SYMBOL(flush_tlb_page);
  634. void
  635. flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
  636. {
  637. /* On the Alpha we always flush the whole user tlb. */
  638. flush_tlb_mm(vma->vm_mm);
  639. }
  640. EXPORT_SYMBOL(flush_tlb_range);
  641. static void
  642. ipi_flush_icache_page(void *x)
  643. {
  644. struct mm_struct *mm = (struct mm_struct *) x;
  645. if (mm == current->active_mm && !asn_locked())
  646. __load_new_mm_context(mm);
  647. else
  648. flush_tlb_other(mm);
  649. }
  650. void
  651. flush_icache_user_range(struct vm_area_struct *vma, struct page *page,
  652. unsigned long addr, int len)
  653. {
  654. struct mm_struct *mm = vma->vm_mm;
  655. if ((vma->vm_flags & VM_EXEC) == 0)
  656. return;
  657. preempt_disable();
  658. if (mm == current->active_mm) {
  659. __load_new_mm_context(mm);
  660. if (atomic_read(&mm->mm_users) <= 1) {
  661. int cpu, this_cpu = smp_processor_id();
  662. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  663. if (!cpu_online(cpu) || cpu == this_cpu)
  664. continue;
  665. if (mm->context[cpu])
  666. mm->context[cpu] = 0;
  667. }
  668. preempt_enable();
  669. return;
  670. }
  671. }
  672. if (smp_call_function(ipi_flush_icache_page, mm, 1)) {
  673. printk(KERN_CRIT "flush_icache_page: timed out\n");
  674. }
  675. preempt_enable();
  676. }