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 <asm/hwrpb.h>
  30. #include <asm/ptrace.h>
  31. #include <asm/atomic.h>
  32. #include <asm/io.h>
  33. #include <asm/irq.h>
  34. #include <asm/pgtable.h>
  35. #include <asm/pgalloc.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_CALL_FUNC_SINGLE,
  57. IPI_CPU_STOP,
  58. };
  59. /* Set to a secondary's cpuid when it comes online. */
  60. static int smp_secondary_alive __devinitdata = 0;
  61. /* Which cpus ids came online. */
  62. cpumask_t cpu_online_map;
  63. EXPORT_SYMBOL(cpu_online_map);
  64. int smp_num_probed; /* Internal processor count */
  65. int smp_num_cpus = 1; /* Number that came online. */
  66. EXPORT_SYMBOL(smp_num_cpus);
  67. /*
  68. * Called by both boot and secondaries to move global data into
  69. * per-processor storage.
  70. */
  71. static inline void __init
  72. smp_store_cpu_info(int cpuid)
  73. {
  74. cpu_data[cpuid].loops_per_jiffy = loops_per_jiffy;
  75. cpu_data[cpuid].last_asn = ASN_FIRST_VERSION;
  76. cpu_data[cpuid].need_new_asn = 0;
  77. cpu_data[cpuid].asn_lock = 0;
  78. }
  79. /*
  80. * Ideally sets up per-cpu profiling hooks. Doesn't do much now...
  81. */
  82. static inline void __init
  83. smp_setup_percpu_timer(int cpuid)
  84. {
  85. cpu_data[cpuid].prof_counter = 1;
  86. cpu_data[cpuid].prof_multiplier = 1;
  87. }
  88. static void __init
  89. wait_boot_cpu_to_stop(int cpuid)
  90. {
  91. unsigned long stop = jiffies + 10*HZ;
  92. while (time_before(jiffies, stop)) {
  93. if (!smp_secondary_alive)
  94. return;
  95. barrier();
  96. }
  97. printk("wait_boot_cpu_to_stop: FAILED on CPU %d, hanging now\n", cpuid);
  98. for (;;)
  99. barrier();
  100. }
  101. /*
  102. * Where secondaries begin a life of C.
  103. */
  104. void __init
  105. smp_callin(void)
  106. {
  107. int cpuid = hard_smp_processor_id();
  108. if (cpu_test_and_set(cpuid, cpu_online_map)) {
  109. printk("??, cpu 0x%x already present??\n", cpuid);
  110. BUG();
  111. }
  112. /* Turn on machine checks. */
  113. wrmces(7);
  114. /* Set trap vectors. */
  115. trap_init();
  116. /* Set interrupt vector. */
  117. wrent(entInt, 0);
  118. /* Get our local ticker going. */
  119. smp_setup_percpu_timer(cpuid);
  120. /* Call platform-specific callin, if specified */
  121. if (alpha_mv.smp_callin) 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. /* Do nothing. */
  141. cpu_idle();
  142. }
  143. /* Wait until hwrpb->txrdy is clear for cpu. Return -1 on timeout. */
  144. static int __devinit
  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 __init
  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[11];
  220. cp2 = buf;
  221. strcpy(cp2, cp1);
  222. while ((cp2 = strchr(cp2, '\r')) != 0) {
  223. *cp2 = ' ';
  224. if (cp2[1] == '\n')
  225. cp2[1] = ' ';
  226. }
  227. }
  228. DBGS((KERN_INFO "recv_secondary_console_msg: on %d "
  229. "message is '%s'\n", mycpu, buf));
  230. }
  231. hwrpb->txrdy = 0;
  232. }
  233. /*
  234. * Convince the console to have a secondary cpu begin execution.
  235. */
  236. static int __init
  237. secondary_cpu_start(int cpuid, struct task_struct *idle)
  238. {
  239. struct percpu_struct *cpu;
  240. struct pcb_struct *hwpcb, *ipcb;
  241. unsigned long timeout;
  242. cpu = (struct percpu_struct *)
  243. ((char*)hwrpb
  244. + hwrpb->processor_offset
  245. + cpuid * hwrpb->processor_size);
  246. hwpcb = (struct pcb_struct *) cpu->hwpcb;
  247. ipcb = &task_thread_info(idle)->pcb;
  248. /* Initialize the CPU's HWPCB to something just good enough for
  249. us to get started. Immediately after starting, we'll swpctx
  250. to the target idle task's pcb. Reuse the stack in the mean
  251. time. Precalculate the target PCBB. */
  252. hwpcb->ksp = (unsigned long)ipcb + sizeof(union thread_union) - 16;
  253. hwpcb->usp = 0;
  254. hwpcb->ptbr = ipcb->ptbr;
  255. hwpcb->pcc = 0;
  256. hwpcb->asn = 0;
  257. hwpcb->unique = virt_to_phys(ipcb);
  258. hwpcb->flags = ipcb->flags;
  259. hwpcb->res1 = hwpcb->res2 = 0;
  260. #if 0
  261. DBGS(("KSP 0x%lx PTBR 0x%lx VPTBR 0x%lx UNIQUE 0x%lx\n",
  262. hwpcb->ksp, hwpcb->ptbr, hwrpb->vptb, hwpcb->unique));
  263. #endif
  264. DBGS(("Starting secondary cpu %d: state 0x%lx pal_flags 0x%lx\n",
  265. cpuid, idle->state, ipcb->flags));
  266. /* Setup HWRPB fields that SRM uses to activate secondary CPU */
  267. hwrpb->CPU_restart = __smp_callin;
  268. hwrpb->CPU_restart_data = (unsigned long) __smp_callin;
  269. /* Recalculate and update the HWRPB checksum */
  270. hwrpb_update_checksum(hwrpb);
  271. /*
  272. * Send a "start" command to the specified processor.
  273. */
  274. /* SRM III 3.4.1.3 */
  275. cpu->flags |= 0x22; /* turn on Context Valid and Restart Capable */
  276. cpu->flags &= ~1; /* turn off Bootstrap In Progress */
  277. wmb();
  278. send_secondary_console_msg("START\r\n", cpuid);
  279. /* Wait 10 seconds for an ACK from the console. */
  280. timeout = jiffies + 10*HZ;
  281. while (time_before(jiffies, timeout)) {
  282. if (cpu->flags & 1)
  283. goto started;
  284. udelay(10);
  285. barrier();
  286. }
  287. printk(KERN_ERR "SMP: Processor %d failed to start.\n", cpuid);
  288. return -1;
  289. started:
  290. DBGS(("secondary_cpu_start: SUCCESS for CPU %d!!!\n", cpuid));
  291. return 0;
  292. }
  293. /*
  294. * Bring one cpu online.
  295. */
  296. static int __cpuinit
  297. smp_boot_one_cpu(int cpuid)
  298. {
  299. struct task_struct *idle;
  300. unsigned long timeout;
  301. /* Cook up an idler for this guy. Note that the address we
  302. give to kernel_thread is irrelevant -- it's going to start
  303. where HWRPB.CPU_restart says to start. But this gets all
  304. the other task-y sort of data structures set up like we
  305. wish. We can't use kernel_thread since we must avoid
  306. rescheduling the child. */
  307. idle = fork_idle(cpuid);
  308. if (IS_ERR(idle))
  309. panic("failed fork for CPU %d", cpuid);
  310. DBGS(("smp_boot_one_cpu: CPU %d state 0x%lx flags 0x%lx\n",
  311. cpuid, idle->state, idle->flags));
  312. /* Signal the secondary to wait a moment. */
  313. smp_secondary_alive = -1;
  314. /* Whirrr, whirrr, whirrrrrrrrr... */
  315. if (secondary_cpu_start(cpuid, idle))
  316. return -1;
  317. /* Notify the secondary CPU it can run calibrate_delay. */
  318. mb();
  319. smp_secondary_alive = 0;
  320. /* We've been acked by the console; wait one second for
  321. the task to start up for real. */
  322. timeout = jiffies + 1*HZ;
  323. while (time_before(jiffies, timeout)) {
  324. if (smp_secondary_alive == 1)
  325. goto alive;
  326. udelay(10);
  327. barrier();
  328. }
  329. /* We failed to boot the CPU. */
  330. printk(KERN_ERR "SMP: Processor %d is stuck.\n", cpuid);
  331. return -1;
  332. alive:
  333. /* Another "Red Snapper". */
  334. return 0;
  335. }
  336. /*
  337. * Called from setup_arch. Detect an SMP system and which processors
  338. * are present.
  339. */
  340. void __init
  341. setup_smp(void)
  342. {
  343. struct percpu_struct *cpubase, *cpu;
  344. unsigned long i;
  345. if (boot_cpuid != 0) {
  346. printk(KERN_WARNING "SMP: Booting off cpu %d instead of 0?\n",
  347. boot_cpuid);
  348. }
  349. if (hwrpb->nr_processors > 1) {
  350. int boot_cpu_palrev;
  351. DBGS(("setup_smp: nr_processors %ld\n",
  352. hwrpb->nr_processors));
  353. cpubase = (struct percpu_struct *)
  354. ((char*)hwrpb + hwrpb->processor_offset);
  355. boot_cpu_palrev = cpubase->pal_revision;
  356. for (i = 0; i < hwrpb->nr_processors; i++) {
  357. cpu = (struct percpu_struct *)
  358. ((char *)cpubase + i*hwrpb->processor_size);
  359. if ((cpu->flags & 0x1cc) == 0x1cc) {
  360. smp_num_probed++;
  361. cpu_set(i, cpu_present_map);
  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_map = %lx\n",
  373. smp_num_probed, cpu_present_map.bits[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. cpu_present_map = cpumask_of_cpu(boot_cpuid);
  389. printk(KERN_INFO "SMP mode deactivated.\n");
  390. return;
  391. }
  392. printk(KERN_INFO "SMP starting up secondaries.\n");
  393. smp_num_cpus = smp_num_probed;
  394. }
  395. void __devinit
  396. smp_prepare_boot_cpu(void)
  397. {
  398. }
  399. int __cpuinit
  400. __cpu_up(unsigned int cpu)
  401. {
  402. smp_boot_one_cpu(cpu);
  403. return cpu_online(cpu) ? 0 : -ENOSYS;
  404. }
  405. void __init
  406. smp_cpus_done(unsigned int max_cpus)
  407. {
  408. int cpu;
  409. unsigned long bogosum = 0;
  410. for(cpu = 0; cpu < NR_CPUS; cpu++)
  411. if (cpu_online(cpu))
  412. bogosum += cpu_data[cpu].loops_per_jiffy;
  413. printk(KERN_INFO "SMP: Total of %d processors activated "
  414. "(%lu.%02lu BogoMIPS).\n",
  415. num_online_cpus(),
  416. (bogosum + 2500) / (500000/HZ),
  417. ((bogosum + 2500) / (5000/HZ)) % 100);
  418. }
  419. void
  420. smp_percpu_timer_interrupt(struct pt_regs *regs)
  421. {
  422. struct pt_regs *old_regs;
  423. int cpu = smp_processor_id();
  424. unsigned long user = user_mode(regs);
  425. struct cpuinfo_alpha *data = &cpu_data[cpu];
  426. old_regs = set_irq_regs(regs);
  427. /* Record kernel PC. */
  428. profile_tick(CPU_PROFILING);
  429. if (!--data->prof_counter) {
  430. /* We need to make like a normal interrupt -- otherwise
  431. timer interrupts ignore the global interrupt lock,
  432. which would be a Bad Thing. */
  433. irq_enter();
  434. update_process_times(user);
  435. data->prof_counter = data->prof_multiplier;
  436. irq_exit();
  437. }
  438. set_irq_regs(old_regs);
  439. }
  440. int
  441. setup_profiling_timer(unsigned int multiplier)
  442. {
  443. return -EINVAL;
  444. }
  445. static void
  446. send_ipi_message(cpumask_t to_whom, enum ipi_message_type operation)
  447. {
  448. int i;
  449. mb();
  450. for_each_cpu_mask(i, to_whom)
  451. set_bit(operation, &ipi_data[i].bits);
  452. mb();
  453. for_each_cpu_mask(i, to_whom)
  454. wripir(i);
  455. }
  456. void
  457. handle_ipi(struct pt_regs *regs)
  458. {
  459. int this_cpu = smp_processor_id();
  460. unsigned long *pending_ipis = &ipi_data[this_cpu].bits;
  461. unsigned long ops;
  462. #if 0
  463. DBGS(("handle_ipi: on CPU %d ops 0x%lx PC 0x%lx\n",
  464. this_cpu, *pending_ipis, regs->pc));
  465. #endif
  466. mb(); /* Order interrupt and bit testing. */
  467. while ((ops = xchg(pending_ipis, 0)) != 0) {
  468. mb(); /* Order bit clearing and data access. */
  469. do {
  470. unsigned long which;
  471. which = ops & -ops;
  472. ops &= ~which;
  473. which = __ffs(which);
  474. switch (which) {
  475. case IPI_RESCHEDULE:
  476. /* Reschedule callback. Everything to be done
  477. is done by the interrupt return path. */
  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(cpu), IPI_RESCHEDULE);
  508. }
  509. void
  510. smp_send_stop(void)
  511. {
  512. cpumask_t to_whom = cpu_possible_map;
  513. cpu_clear(smp_processor_id(), to_whom);
  514. #ifdef DEBUG_IPI_MSG
  515. if (hard_smp_processor_id() != boot_cpu_id)
  516. printk(KERN_WARNING "smp_send_stop: Not on boot cpu.\n");
  517. #endif
  518. send_ipi_message(to_whom, IPI_CPU_STOP);
  519. }
  520. void arch_send_call_function_ipi(cpumask_t mask)
  521. {
  522. send_ipi_message(mask, IPI_CALL_FUNC);
  523. }
  524. void arch_send_call_function_single_ipi(int cpu)
  525. {
  526. send_ipi_message(cpumask_of_cpu(cpu), IPI_CALL_FUNC_SINGLE);
  527. }
  528. static void
  529. ipi_imb(void *ignored)
  530. {
  531. imb();
  532. }
  533. void
  534. smp_imb(void)
  535. {
  536. /* Must wait other processors to flush their icache before continue. */
  537. if (on_each_cpu(ipi_imb, NULL, 1))
  538. printk(KERN_CRIT "smp_imb: timed out\n");
  539. }
  540. EXPORT_SYMBOL(smp_imb);
  541. static void
  542. ipi_flush_tlb_all(void *ignored)
  543. {
  544. tbia();
  545. }
  546. void
  547. flush_tlb_all(void)
  548. {
  549. /* Although we don't have any data to pass, we do want to
  550. synchronize with the other processors. */
  551. if (on_each_cpu(ipi_flush_tlb_all, NULL, 1)) {
  552. printk(KERN_CRIT "flush_tlb_all: timed out\n");
  553. }
  554. }
  555. #define asn_locked() (cpu_data[smp_processor_id()].asn_lock)
  556. static void
  557. ipi_flush_tlb_mm(void *x)
  558. {
  559. struct mm_struct *mm = (struct mm_struct *) x;
  560. if (mm == current->active_mm && !asn_locked())
  561. flush_tlb_current(mm);
  562. else
  563. flush_tlb_other(mm);
  564. }
  565. void
  566. flush_tlb_mm(struct mm_struct *mm)
  567. {
  568. preempt_disable();
  569. if (mm == current->active_mm) {
  570. flush_tlb_current(mm);
  571. if (atomic_read(&mm->mm_users) <= 1) {
  572. int cpu, this_cpu = smp_processor_id();
  573. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  574. if (!cpu_online(cpu) || cpu == this_cpu)
  575. continue;
  576. if (mm->context[cpu])
  577. mm->context[cpu] = 0;
  578. }
  579. preempt_enable();
  580. return;
  581. }
  582. }
  583. if (smp_call_function(ipi_flush_tlb_mm, mm, 1)) {
  584. printk(KERN_CRIT "flush_tlb_mm: timed out\n");
  585. }
  586. preempt_enable();
  587. }
  588. EXPORT_SYMBOL(flush_tlb_mm);
  589. struct flush_tlb_page_struct {
  590. struct vm_area_struct *vma;
  591. struct mm_struct *mm;
  592. unsigned long addr;
  593. };
  594. static void
  595. ipi_flush_tlb_page(void *x)
  596. {
  597. struct flush_tlb_page_struct *data = (struct flush_tlb_page_struct *)x;
  598. struct mm_struct * mm = data->mm;
  599. if (mm == current->active_mm && !asn_locked())
  600. flush_tlb_current_page(mm, data->vma, data->addr);
  601. else
  602. flush_tlb_other(mm);
  603. }
  604. void
  605. flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)
  606. {
  607. struct flush_tlb_page_struct data;
  608. struct mm_struct *mm = vma->vm_mm;
  609. preempt_disable();
  610. if (mm == current->active_mm) {
  611. flush_tlb_current_page(mm, vma, addr);
  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. data.vma = vma;
  625. data.mm = mm;
  626. data.addr = addr;
  627. if (smp_call_function(ipi_flush_tlb_page, &data, 1)) {
  628. printk(KERN_CRIT "flush_tlb_page: timed out\n");
  629. }
  630. preempt_enable();
  631. }
  632. EXPORT_SYMBOL(flush_tlb_page);
  633. void
  634. flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
  635. {
  636. /* On the Alpha we always flush the whole user tlb. */
  637. flush_tlb_mm(vma->vm_mm);
  638. }
  639. EXPORT_SYMBOL(flush_tlb_range);
  640. static void
  641. ipi_flush_icache_page(void *x)
  642. {
  643. struct mm_struct *mm = (struct mm_struct *) x;
  644. if (mm == current->active_mm && !asn_locked())
  645. __load_new_mm_context(mm);
  646. else
  647. flush_tlb_other(mm);
  648. }
  649. void
  650. flush_icache_user_range(struct vm_area_struct *vma, struct page *page,
  651. unsigned long addr, int len)
  652. {
  653. struct mm_struct *mm = vma->vm_mm;
  654. if ((vma->vm_flags & VM_EXEC) == 0)
  655. return;
  656. preempt_disable();
  657. if (mm == current->active_mm) {
  658. __load_new_mm_context(mm);
  659. if (atomic_read(&mm->mm_users) <= 1) {
  660. int cpu, this_cpu = smp_processor_id();
  661. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  662. if (!cpu_online(cpu) || cpu == this_cpu)
  663. continue;
  664. if (mm->context[cpu])
  665. mm->context[cpu] = 0;
  666. }
  667. preempt_enable();
  668. return;
  669. }
  670. }
  671. if (smp_call_function(ipi_flush_icache_page, mm, 1)) {
  672. printk(KERN_CRIT "flush_icache_page: timed out\n");
  673. }
  674. preempt_enable();
  675. }