smp.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  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, 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 __devinit
  385. smp_prepare_boot_cpu(void)
  386. {
  387. }
  388. int __cpuinit
  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. void
  409. smp_percpu_timer_interrupt(struct pt_regs *regs)
  410. {
  411. struct pt_regs *old_regs;
  412. int cpu = smp_processor_id();
  413. unsigned long user = user_mode(regs);
  414. struct cpuinfo_alpha *data = &cpu_data[cpu];
  415. old_regs = set_irq_regs(regs);
  416. /* Record kernel PC. */
  417. profile_tick(CPU_PROFILING);
  418. if (!--data->prof_counter) {
  419. /* We need to make like a normal interrupt -- otherwise
  420. timer interrupts ignore the global interrupt lock,
  421. which would be a Bad Thing. */
  422. irq_enter();
  423. update_process_times(user);
  424. data->prof_counter = data->prof_multiplier;
  425. irq_exit();
  426. }
  427. set_irq_regs(old_regs);
  428. }
  429. int
  430. setup_profiling_timer(unsigned int multiplier)
  431. {
  432. return -EINVAL;
  433. }
  434. static void
  435. send_ipi_message(const struct cpumask *to_whom, enum ipi_message_type operation)
  436. {
  437. int i;
  438. mb();
  439. for_each_cpu(i, to_whom)
  440. set_bit(operation, &ipi_data[i].bits);
  441. mb();
  442. for_each_cpu(i, to_whom)
  443. wripir(i);
  444. }
  445. void
  446. handle_ipi(struct pt_regs *regs)
  447. {
  448. int this_cpu = smp_processor_id();
  449. unsigned long *pending_ipis = &ipi_data[this_cpu].bits;
  450. unsigned long ops;
  451. #if 0
  452. DBGS(("handle_ipi: on CPU %d ops 0x%lx PC 0x%lx\n",
  453. this_cpu, *pending_ipis, regs->pc));
  454. #endif
  455. mb(); /* Order interrupt and bit testing. */
  456. while ((ops = xchg(pending_ipis, 0)) != 0) {
  457. mb(); /* Order bit clearing and data access. */
  458. do {
  459. unsigned long which;
  460. which = ops & -ops;
  461. ops &= ~which;
  462. which = __ffs(which);
  463. switch (which) {
  464. case IPI_RESCHEDULE:
  465. scheduler_ipi();
  466. break;
  467. case IPI_CALL_FUNC:
  468. generic_smp_call_function_interrupt();
  469. break;
  470. case IPI_CALL_FUNC_SINGLE:
  471. generic_smp_call_function_single_interrupt();
  472. break;
  473. case IPI_CPU_STOP:
  474. halt();
  475. default:
  476. printk(KERN_CRIT "Unknown IPI on CPU %d: %lu\n",
  477. this_cpu, which);
  478. break;
  479. }
  480. } while (ops);
  481. mb(); /* Order data access and bit testing. */
  482. }
  483. cpu_data[this_cpu].ipi_count++;
  484. if (hwrpb->txrdy)
  485. recv_secondary_console_msg();
  486. }
  487. void
  488. smp_send_reschedule(int cpu)
  489. {
  490. #ifdef DEBUG_IPI_MSG
  491. if (cpu == hard_smp_processor_id())
  492. printk(KERN_WARNING
  493. "smp_send_reschedule: Sending IPI to self.\n");
  494. #endif
  495. send_ipi_message(cpumask_of(cpu), IPI_RESCHEDULE);
  496. }
  497. void
  498. smp_send_stop(void)
  499. {
  500. cpumask_t to_whom;
  501. cpumask_copy(&to_whom, cpu_possible_mask);
  502. cpumask_clear_cpu(smp_processor_id(), &to_whom);
  503. #ifdef DEBUG_IPI_MSG
  504. if (hard_smp_processor_id() != boot_cpu_id)
  505. printk(KERN_WARNING "smp_send_stop: Not on boot cpu.\n");
  506. #endif
  507. send_ipi_message(&to_whom, IPI_CPU_STOP);
  508. }
  509. void arch_send_call_function_ipi_mask(const struct cpumask *mask)
  510. {
  511. send_ipi_message(mask, IPI_CALL_FUNC);
  512. }
  513. void arch_send_call_function_single_ipi(int cpu)
  514. {
  515. send_ipi_message(cpumask_of(cpu), IPI_CALL_FUNC_SINGLE);
  516. }
  517. static void
  518. ipi_imb(void *ignored)
  519. {
  520. imb();
  521. }
  522. void
  523. smp_imb(void)
  524. {
  525. /* Must wait other processors to flush their icache before continue. */
  526. if (on_each_cpu(ipi_imb, NULL, 1))
  527. printk(KERN_CRIT "smp_imb: timed out\n");
  528. }
  529. EXPORT_SYMBOL(smp_imb);
  530. static void
  531. ipi_flush_tlb_all(void *ignored)
  532. {
  533. tbia();
  534. }
  535. void
  536. flush_tlb_all(void)
  537. {
  538. /* Although we don't have any data to pass, we do want to
  539. synchronize with the other processors. */
  540. if (on_each_cpu(ipi_flush_tlb_all, NULL, 1)) {
  541. printk(KERN_CRIT "flush_tlb_all: timed out\n");
  542. }
  543. }
  544. #define asn_locked() (cpu_data[smp_processor_id()].asn_lock)
  545. static void
  546. ipi_flush_tlb_mm(void *x)
  547. {
  548. struct mm_struct *mm = (struct mm_struct *) x;
  549. if (mm == current->active_mm && !asn_locked())
  550. flush_tlb_current(mm);
  551. else
  552. flush_tlb_other(mm);
  553. }
  554. void
  555. flush_tlb_mm(struct mm_struct *mm)
  556. {
  557. preempt_disable();
  558. if (mm == current->active_mm) {
  559. flush_tlb_current(mm);
  560. if (atomic_read(&mm->mm_users) <= 1) {
  561. int cpu, this_cpu = smp_processor_id();
  562. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  563. if (!cpu_online(cpu) || cpu == this_cpu)
  564. continue;
  565. if (mm->context[cpu])
  566. mm->context[cpu] = 0;
  567. }
  568. preempt_enable();
  569. return;
  570. }
  571. }
  572. if (smp_call_function(ipi_flush_tlb_mm, mm, 1)) {
  573. printk(KERN_CRIT "flush_tlb_mm: timed out\n");
  574. }
  575. preempt_enable();
  576. }
  577. EXPORT_SYMBOL(flush_tlb_mm);
  578. struct flush_tlb_page_struct {
  579. struct vm_area_struct *vma;
  580. struct mm_struct *mm;
  581. unsigned long addr;
  582. };
  583. static void
  584. ipi_flush_tlb_page(void *x)
  585. {
  586. struct flush_tlb_page_struct *data = (struct flush_tlb_page_struct *)x;
  587. struct mm_struct * mm = data->mm;
  588. if (mm == current->active_mm && !asn_locked())
  589. flush_tlb_current_page(mm, data->vma, data->addr);
  590. else
  591. flush_tlb_other(mm);
  592. }
  593. void
  594. flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)
  595. {
  596. struct flush_tlb_page_struct data;
  597. struct mm_struct *mm = vma->vm_mm;
  598. preempt_disable();
  599. if (mm == current->active_mm) {
  600. flush_tlb_current_page(mm, vma, addr);
  601. if (atomic_read(&mm->mm_users) <= 1) {
  602. int cpu, this_cpu = smp_processor_id();
  603. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  604. if (!cpu_online(cpu) || cpu == this_cpu)
  605. continue;
  606. if (mm->context[cpu])
  607. mm->context[cpu] = 0;
  608. }
  609. preempt_enable();
  610. return;
  611. }
  612. }
  613. data.vma = vma;
  614. data.mm = mm;
  615. data.addr = addr;
  616. if (smp_call_function(ipi_flush_tlb_page, &data, 1)) {
  617. printk(KERN_CRIT "flush_tlb_page: timed out\n");
  618. }
  619. preempt_enable();
  620. }
  621. EXPORT_SYMBOL(flush_tlb_page);
  622. void
  623. flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
  624. {
  625. /* On the Alpha we always flush the whole user tlb. */
  626. flush_tlb_mm(vma->vm_mm);
  627. }
  628. EXPORT_SYMBOL(flush_tlb_range);
  629. static void
  630. ipi_flush_icache_page(void *x)
  631. {
  632. struct mm_struct *mm = (struct mm_struct *) x;
  633. if (mm == current->active_mm && !asn_locked())
  634. __load_new_mm_context(mm);
  635. else
  636. flush_tlb_other(mm);
  637. }
  638. void
  639. flush_icache_user_range(struct vm_area_struct *vma, struct page *page,
  640. unsigned long addr, int len)
  641. {
  642. struct mm_struct *mm = vma->vm_mm;
  643. if ((vma->vm_flags & VM_EXEC) == 0)
  644. return;
  645. preempt_disable();
  646. if (mm == current->active_mm) {
  647. __load_new_mm_context(mm);
  648. if (atomic_read(&mm->mm_users) <= 1) {
  649. int cpu, this_cpu = smp_processor_id();
  650. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  651. if (!cpu_online(cpu) || cpu == this_cpu)
  652. continue;
  653. if (mm->context[cpu])
  654. mm->context[cpu] = 0;
  655. }
  656. preempt_enable();
  657. return;
  658. }
  659. }
  660. if (smp_call_function(ipi_flush_icache_page, mm, 1)) {
  661. printk(KERN_CRIT "flush_icache_page: timed out\n");
  662. }
  663. preempt_enable();
  664. }