smp.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  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. /* Must have completely accurate bogos. */
  126. local_irq_enable();
  127. /* Wait boot CPU to stop with irq enabled before running
  128. calibrate_delay. */
  129. wait_boot_cpu_to_stop(cpuid);
  130. mb();
  131. calibrate_delay();
  132. smp_store_cpu_info(cpuid);
  133. /* Allow master to continue only after we written loops_per_jiffy. */
  134. wmb();
  135. smp_secondary_alive = 1;
  136. DBGS(("smp_callin: commencing CPU %d current %p active_mm %p\n",
  137. cpuid, current, current->active_mm));
  138. /* Do nothing. */
  139. cpu_idle();
  140. }
  141. /* Wait until hwrpb->txrdy is clear for cpu. Return -1 on timeout. */
  142. static int __devinit
  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 __init
  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[11];
  218. cp2 = buf;
  219. strcpy(cp2, cp1);
  220. while ((cp2 = strchr(cp2, '\r')) != 0) {
  221. *cp2 = ' ';
  222. if (cp2[1] == '\n')
  223. cp2[1] = ' ';
  224. }
  225. }
  226. DBGS((KERN_INFO "recv_secondary_console_msg: on %d "
  227. "message is '%s'\n", mycpu, buf));
  228. }
  229. hwrpb->txrdy = 0;
  230. }
  231. /*
  232. * Convince the console to have a secondary cpu begin execution.
  233. */
  234. static int __init
  235. secondary_cpu_start(int cpuid, struct task_struct *idle)
  236. {
  237. struct percpu_struct *cpu;
  238. struct pcb_struct *hwpcb, *ipcb;
  239. unsigned long timeout;
  240. cpu = (struct percpu_struct *)
  241. ((char*)hwrpb
  242. + hwrpb->processor_offset
  243. + cpuid * hwrpb->processor_size);
  244. hwpcb = (struct pcb_struct *) cpu->hwpcb;
  245. ipcb = &task_thread_info(idle)->pcb;
  246. /* Initialize the CPU's HWPCB to something just good enough for
  247. us to get started. Immediately after starting, we'll swpctx
  248. to the target idle task's pcb. Reuse the stack in the mean
  249. time. Precalculate the target PCBB. */
  250. hwpcb->ksp = (unsigned long)ipcb + sizeof(union thread_union) - 16;
  251. hwpcb->usp = 0;
  252. hwpcb->ptbr = ipcb->ptbr;
  253. hwpcb->pcc = 0;
  254. hwpcb->asn = 0;
  255. hwpcb->unique = virt_to_phys(ipcb);
  256. hwpcb->flags = ipcb->flags;
  257. hwpcb->res1 = hwpcb->res2 = 0;
  258. #if 0
  259. DBGS(("KSP 0x%lx PTBR 0x%lx VPTBR 0x%lx UNIQUE 0x%lx\n",
  260. hwpcb->ksp, hwpcb->ptbr, hwrpb->vptb, hwpcb->unique));
  261. #endif
  262. DBGS(("Starting secondary cpu %d: state 0x%lx pal_flags 0x%lx\n",
  263. cpuid, idle->state, ipcb->flags));
  264. /* Setup HWRPB fields that SRM uses to activate secondary CPU */
  265. hwrpb->CPU_restart = __smp_callin;
  266. hwrpb->CPU_restart_data = (unsigned long) __smp_callin;
  267. /* Recalculate and update the HWRPB checksum */
  268. hwrpb_update_checksum(hwrpb);
  269. /*
  270. * Send a "start" command to the specified processor.
  271. */
  272. /* SRM III 3.4.1.3 */
  273. cpu->flags |= 0x22; /* turn on Context Valid and Restart Capable */
  274. cpu->flags &= ~1; /* turn off Bootstrap In Progress */
  275. wmb();
  276. send_secondary_console_msg("START\r\n", cpuid);
  277. /* Wait 10 seconds for an ACK from the console. */
  278. timeout = jiffies + 10*HZ;
  279. while (time_before(jiffies, timeout)) {
  280. if (cpu->flags & 1)
  281. goto started;
  282. udelay(10);
  283. barrier();
  284. }
  285. printk(KERN_ERR "SMP: Processor %d failed to start.\n", cpuid);
  286. return -1;
  287. started:
  288. DBGS(("secondary_cpu_start: SUCCESS for CPU %d!!!\n", cpuid));
  289. return 0;
  290. }
  291. /*
  292. * Bring one cpu online.
  293. */
  294. static int __cpuinit
  295. smp_boot_one_cpu(int cpuid)
  296. {
  297. struct task_struct *idle;
  298. unsigned long timeout;
  299. /* Cook up an idler for this guy. Note that the address we
  300. give to kernel_thread is irrelevant -- it's going to start
  301. where HWRPB.CPU_restart says to start. But this gets all
  302. the other task-y sort of data structures set up like we
  303. wish. We can't use kernel_thread since we must avoid
  304. rescheduling the child. */
  305. idle = fork_idle(cpuid);
  306. if (IS_ERR(idle))
  307. panic("failed fork for CPU %d", cpuid);
  308. DBGS(("smp_boot_one_cpu: CPU %d state 0x%lx flags 0x%lx\n",
  309. cpuid, idle->state, idle->flags));
  310. /* Signal the secondary to wait a moment. */
  311. smp_secondary_alive = -1;
  312. /* Whirrr, whirrr, whirrrrrrrrr... */
  313. if (secondary_cpu_start(cpuid, idle))
  314. return -1;
  315. /* Notify the secondary CPU it can run calibrate_delay. */
  316. mb();
  317. smp_secondary_alive = 0;
  318. /* We've been acked by the console; wait one second for
  319. the task to start up for real. */
  320. timeout = jiffies + 1*HZ;
  321. while (time_before(jiffies, timeout)) {
  322. if (smp_secondary_alive == 1)
  323. goto alive;
  324. udelay(10);
  325. barrier();
  326. }
  327. /* We failed to boot the CPU. */
  328. printk(KERN_ERR "SMP: Processor %d is stuck.\n", cpuid);
  329. return -1;
  330. alive:
  331. /* Another "Red Snapper". */
  332. return 0;
  333. }
  334. /*
  335. * Called from setup_arch. Detect an SMP system and which processors
  336. * are present.
  337. */
  338. void __init
  339. setup_smp(void)
  340. {
  341. struct percpu_struct *cpubase, *cpu;
  342. unsigned long i;
  343. if (boot_cpuid != 0) {
  344. printk(KERN_WARNING "SMP: Booting off cpu %d instead of 0?\n",
  345. boot_cpuid);
  346. }
  347. if (hwrpb->nr_processors > 1) {
  348. int boot_cpu_palrev;
  349. DBGS(("setup_smp: nr_processors %ld\n",
  350. hwrpb->nr_processors));
  351. cpubase = (struct percpu_struct *)
  352. ((char*)hwrpb + hwrpb->processor_offset);
  353. boot_cpu_palrev = cpubase->pal_revision;
  354. for (i = 0; i < hwrpb->nr_processors; i++) {
  355. cpu = (struct percpu_struct *)
  356. ((char *)cpubase + i*hwrpb->processor_size);
  357. if ((cpu->flags & 0x1cc) == 0x1cc) {
  358. smp_num_probed++;
  359. cpu_set(i, cpu_present_map);
  360. cpu->pal_revision = boot_cpu_palrev;
  361. }
  362. DBGS(("setup_smp: CPU %d: flags 0x%lx type 0x%lx\n",
  363. i, cpu->flags, cpu->type));
  364. DBGS(("setup_smp: CPU %d: PAL rev 0x%lx\n",
  365. i, cpu->pal_revision));
  366. }
  367. } else {
  368. smp_num_probed = 1;
  369. }
  370. printk(KERN_INFO "SMP: %d CPUs probed -- cpu_present_map = %lx\n",
  371. smp_num_probed, cpu_present_map.bits[0]);
  372. }
  373. /*
  374. * Called by smp_init prepare the secondaries
  375. */
  376. void __init
  377. smp_prepare_cpus(unsigned int max_cpus)
  378. {
  379. /* Take care of some initial bookkeeping. */
  380. memset(ipi_data, 0, sizeof(ipi_data));
  381. current_thread_info()->cpu = boot_cpuid;
  382. smp_store_cpu_info(boot_cpuid);
  383. smp_setup_percpu_timer(boot_cpuid);
  384. /* Nothing to do on a UP box, or when told not to. */
  385. if (smp_num_probed == 1 || max_cpus == 0) {
  386. cpu_present_map = cpumask_of_cpu(boot_cpuid);
  387. printk(KERN_INFO "SMP mode deactivated.\n");
  388. return;
  389. }
  390. printk(KERN_INFO "SMP starting up secondaries.\n");
  391. smp_num_cpus = smp_num_probed;
  392. }
  393. void __devinit
  394. smp_prepare_boot_cpu(void)
  395. {
  396. }
  397. int __cpuinit
  398. __cpu_up(unsigned int cpu)
  399. {
  400. smp_boot_one_cpu(cpu);
  401. return cpu_online(cpu) ? 0 : -ENOSYS;
  402. }
  403. void __init
  404. smp_cpus_done(unsigned int max_cpus)
  405. {
  406. int cpu;
  407. unsigned long bogosum = 0;
  408. for(cpu = 0; cpu < NR_CPUS; cpu++)
  409. if (cpu_online(cpu))
  410. bogosum += cpu_data[cpu].loops_per_jiffy;
  411. printk(KERN_INFO "SMP: Total of %d processors activated "
  412. "(%lu.%02lu BogoMIPS).\n",
  413. num_online_cpus(),
  414. (bogosum + 2500) / (500000/HZ),
  415. ((bogosum + 2500) / (5000/HZ)) % 100);
  416. }
  417. void
  418. smp_percpu_timer_interrupt(struct pt_regs *regs)
  419. {
  420. struct pt_regs *old_regs;
  421. int cpu = smp_processor_id();
  422. unsigned long user = user_mode(regs);
  423. struct cpuinfo_alpha *data = &cpu_data[cpu];
  424. old_regs = set_irq_regs(regs);
  425. /* Record kernel PC. */
  426. profile_tick(CPU_PROFILING);
  427. if (!--data->prof_counter) {
  428. /* We need to make like a normal interrupt -- otherwise
  429. timer interrupts ignore the global interrupt lock,
  430. which would be a Bad Thing. */
  431. irq_enter();
  432. update_process_times(user);
  433. data->prof_counter = data->prof_multiplier;
  434. irq_exit();
  435. }
  436. set_irq_regs(old_regs);
  437. }
  438. int
  439. setup_profiling_timer(unsigned int multiplier)
  440. {
  441. return -EINVAL;
  442. }
  443. static void
  444. send_ipi_message(cpumask_t to_whom, enum ipi_message_type operation)
  445. {
  446. int i;
  447. mb();
  448. for_each_cpu_mask(i, to_whom)
  449. set_bit(operation, &ipi_data[i].bits);
  450. mb();
  451. for_each_cpu_mask(i, to_whom)
  452. wripir(i);
  453. }
  454. void
  455. handle_ipi(struct pt_regs *regs)
  456. {
  457. int this_cpu = smp_processor_id();
  458. unsigned long *pending_ipis = &ipi_data[this_cpu].bits;
  459. unsigned long ops;
  460. #if 0
  461. DBGS(("handle_ipi: on CPU %d ops 0x%lx PC 0x%lx\n",
  462. this_cpu, *pending_ipis, regs->pc));
  463. #endif
  464. mb(); /* Order interrupt and bit testing. */
  465. while ((ops = xchg(pending_ipis, 0)) != 0) {
  466. mb(); /* Order bit clearing and data access. */
  467. do {
  468. unsigned long which;
  469. which = ops & -ops;
  470. ops &= ~which;
  471. which = __ffs(which);
  472. switch (which) {
  473. case IPI_RESCHEDULE:
  474. /* Reschedule callback. Everything to be done
  475. is done by the interrupt return path. */
  476. break;
  477. case IPI_CALL_FUNC:
  478. generic_smp_call_function_interrupt();
  479. break;
  480. case IPI_CALL_FUNC_SINGLE:
  481. generic_smp_call_function_single_interrupt();
  482. break;
  483. case IPI_CPU_STOP:
  484. halt();
  485. default:
  486. printk(KERN_CRIT "Unknown IPI on CPU %d: %lu\n",
  487. this_cpu, which);
  488. break;
  489. }
  490. } while (ops);
  491. mb(); /* Order data access and bit testing. */
  492. }
  493. cpu_data[this_cpu].ipi_count++;
  494. if (hwrpb->txrdy)
  495. recv_secondary_console_msg();
  496. }
  497. void
  498. smp_send_reschedule(int cpu)
  499. {
  500. #ifdef DEBUG_IPI_MSG
  501. if (cpu == hard_smp_processor_id())
  502. printk(KERN_WARNING
  503. "smp_send_reschedule: Sending IPI to self.\n");
  504. #endif
  505. send_ipi_message(cpumask_of_cpu(cpu), IPI_RESCHEDULE);
  506. }
  507. void
  508. smp_send_stop(void)
  509. {
  510. cpumask_t to_whom = cpu_possible_map;
  511. cpu_clear(smp_processor_id(), to_whom);
  512. #ifdef DEBUG_IPI_MSG
  513. if (hard_smp_processor_id() != boot_cpu_id)
  514. printk(KERN_WARNING "smp_send_stop: Not on boot cpu.\n");
  515. #endif
  516. send_ipi_message(to_whom, IPI_CPU_STOP);
  517. }
  518. void arch_send_call_function_ipi(cpumask_t mask)
  519. {
  520. send_ipi_message(mask, IPI_CALL_FUNC);
  521. }
  522. void arch_send_call_function_single_ipi(int cpu)
  523. {
  524. send_ipi_message(cpumask_of_cpu(cpu), IPI_CALL_FUNC_SINGLE);
  525. }
  526. static void
  527. ipi_imb(void *ignored)
  528. {
  529. imb();
  530. }
  531. void
  532. smp_imb(void)
  533. {
  534. /* Must wait other processors to flush their icache before continue. */
  535. if (on_each_cpu(ipi_imb, NULL, 1))
  536. printk(KERN_CRIT "smp_imb: timed out\n");
  537. }
  538. EXPORT_SYMBOL(smp_imb);
  539. static void
  540. ipi_flush_tlb_all(void *ignored)
  541. {
  542. tbia();
  543. }
  544. void
  545. flush_tlb_all(void)
  546. {
  547. /* Although we don't have any data to pass, we do want to
  548. synchronize with the other processors. */
  549. if (on_each_cpu(ipi_flush_tlb_all, NULL, 1)) {
  550. printk(KERN_CRIT "flush_tlb_all: timed out\n");
  551. }
  552. }
  553. #define asn_locked() (cpu_data[smp_processor_id()].asn_lock)
  554. static void
  555. ipi_flush_tlb_mm(void *x)
  556. {
  557. struct mm_struct *mm = (struct mm_struct *) x;
  558. if (mm == current->active_mm && !asn_locked())
  559. flush_tlb_current(mm);
  560. else
  561. flush_tlb_other(mm);
  562. }
  563. void
  564. flush_tlb_mm(struct mm_struct *mm)
  565. {
  566. preempt_disable();
  567. if (mm == current->active_mm) {
  568. flush_tlb_current(mm);
  569. if (atomic_read(&mm->mm_users) <= 1) {
  570. int cpu, this_cpu = smp_processor_id();
  571. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  572. if (!cpu_online(cpu) || cpu == this_cpu)
  573. continue;
  574. if (mm->context[cpu])
  575. mm->context[cpu] = 0;
  576. }
  577. preempt_enable();
  578. return;
  579. }
  580. }
  581. if (smp_call_function(ipi_flush_tlb_mm, mm, 1)) {
  582. printk(KERN_CRIT "flush_tlb_mm: timed out\n");
  583. }
  584. preempt_enable();
  585. }
  586. EXPORT_SYMBOL(flush_tlb_mm);
  587. struct flush_tlb_page_struct {
  588. struct vm_area_struct *vma;
  589. struct mm_struct *mm;
  590. unsigned long addr;
  591. };
  592. static void
  593. ipi_flush_tlb_page(void *x)
  594. {
  595. struct flush_tlb_page_struct *data = (struct flush_tlb_page_struct *)x;
  596. struct mm_struct * mm = data->mm;
  597. if (mm == current->active_mm && !asn_locked())
  598. flush_tlb_current_page(mm, data->vma, data->addr);
  599. else
  600. flush_tlb_other(mm);
  601. }
  602. void
  603. flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)
  604. {
  605. struct flush_tlb_page_struct data;
  606. struct mm_struct *mm = vma->vm_mm;
  607. preempt_disable();
  608. if (mm == current->active_mm) {
  609. flush_tlb_current_page(mm, vma, addr);
  610. if (atomic_read(&mm->mm_users) <= 1) {
  611. int cpu, this_cpu = smp_processor_id();
  612. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  613. if (!cpu_online(cpu) || cpu == this_cpu)
  614. continue;
  615. if (mm->context[cpu])
  616. mm->context[cpu] = 0;
  617. }
  618. preempt_enable();
  619. return;
  620. }
  621. }
  622. data.vma = vma;
  623. data.mm = mm;
  624. data.addr = addr;
  625. if (smp_call_function(ipi_flush_tlb_page, &data, 1)) {
  626. printk(KERN_CRIT "flush_tlb_page: timed out\n");
  627. }
  628. preempt_enable();
  629. }
  630. EXPORT_SYMBOL(flush_tlb_page);
  631. void
  632. flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
  633. {
  634. /* On the Alpha we always flush the whole user tlb. */
  635. flush_tlb_mm(vma->vm_mm);
  636. }
  637. EXPORT_SYMBOL(flush_tlb_range);
  638. static void
  639. ipi_flush_icache_page(void *x)
  640. {
  641. struct mm_struct *mm = (struct mm_struct *) x;
  642. if (mm == current->active_mm && !asn_locked())
  643. __load_new_mm_context(mm);
  644. else
  645. flush_tlb_other(mm);
  646. }
  647. void
  648. flush_icache_user_range(struct vm_area_struct *vma, struct page *page,
  649. unsigned long addr, int len)
  650. {
  651. struct mm_struct *mm = vma->vm_mm;
  652. if ((vma->vm_flags & VM_EXEC) == 0)
  653. return;
  654. preempt_disable();
  655. if (mm == current->active_mm) {
  656. __load_new_mm_context(mm);
  657. if (atomic_read(&mm->mm_users) <= 1) {
  658. int cpu, this_cpu = smp_processor_id();
  659. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  660. if (!cpu_online(cpu) || cpu == this_cpu)
  661. continue;
  662. if (mm->context[cpu])
  663. mm->context[cpu] = 0;
  664. }
  665. preempt_enable();
  666. return;
  667. }
  668. }
  669. if (smp_call_function(ipi_flush_icache_page, mm, 1)) {
  670. printk(KERN_CRIT "flush_icache_page: timed out\n");
  671. }
  672. preempt_enable();
  673. }