···11+/*22+ * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>33+ * Copyright (C) 1996, 1997, 1998, 1999 by Ralf Baechle44+ * Copyright (C) 1999 Silicon Graphics, Inc.55+ *66+ * based on MIPS asm/mmu_context.h77+ *88+ * This file is subject to the terms and conditions of the GNU General Public99+ * License. See the file "COPYING" in the main directory of this archive1010+ * for more details.1111+ */1212+1313+#ifndef _ASM_NIOS2_MMU_CONTEXT_H1414+#define _ASM_NIOS2_MMU_CONTEXT_H1515+1616+#include <asm-generic/mm_hooks.h>1717+1818+extern void mmu_context_init(void);1919+extern unsigned long get_pid_from_context(mm_context_t *ctx);2020+2121+/*2222+ * For the fast tlb miss handlers, we keep a pointer to the current pgd.2323+ * processor.2424+ */2525+extern pgd_t *pgd_current;2626+2727+static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)2828+{2929+}3030+3131+/*3232+ * Initialize the context related info for a new mm_struct instance.3333+ *3434+ * Set all new contexts to 0, that way the generation will never match3535+ * the currently running generation when this context is switched in.3636+ */3737+static inline int init_new_context(struct task_struct *tsk,3838+ struct mm_struct *mm)3939+{4040+ mm->context = 0;4141+ return 0;4242+}4343+4444+/*4545+ * Destroy context related info for an mm_struct that is about4646+ * to be put to rest.4747+ */4848+static inline void destroy_context(struct mm_struct *mm)4949+{5050+}5151+5252+void switch_mm(struct mm_struct *prev, struct mm_struct *next,5353+ struct task_struct *tsk);5454+5555+static inline void deactivate_mm(struct task_struct *tsk,5656+ struct mm_struct *mm)5757+{5858+}5959+6060+/*6161+ * After we have set current->mm to a new value, this activates6262+ * the context for the new mm so we see the new mappings.6363+ */6464+void activate_mm(struct mm_struct *prev, struct mm_struct *next);6565+6666+#endif /* _ASM_NIOS2_MMU_CONTEXT_H */
+103
arch/nios2/include/asm/processor.h
···11+/*22+ * Copyright (C) 2013 Altera Corporation33+ * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>44+ * Copyright (C) 2004 Microtronix Datacom Ltd55+ * Copyright (C) 2001 Ken Hill (khill@microtronix.com)66+ * Vic Phillips (vic@microtronix.com)77+ *88+ * based on SPARC asm/processor_32.h which is:99+ *1010+ * Copyright (C) 1994 David S. Miller1111+ *1212+ * This file is subject to the terms and conditions of the GNU General Public1313+ * License. See the file "COPYING" in the main directory of this archive1414+ * for more details.1515+ */1616+1717+#ifndef _ASM_NIOS2_PROCESSOR_H1818+#define _ASM_NIOS2_PROCESSOR_H1919+2020+#include <asm/ptrace.h>2121+#include <asm/registers.h>2222+#include <asm/page.h>2323+2424+#define NIOS2_FLAG_KTHREAD 0x00000001 /* task is a kernel thread */2525+2626+#define NIOS2_OP_NOP 0x1883a2727+#define NIOS2_OP_BREAK 0x3da03a2828+2929+#ifdef __KERNEL__3030+3131+#define STACK_TOP TASK_SIZE3232+#define STACK_TOP_MAX STACK_TOP3333+3434+#endif /* __KERNEL__ */3535+3636+/* Kuser helpers is mapped to this user space address */3737+#define KUSER_BASE 0x10003838+#define KUSER_SIZE (PAGE_SIZE)3939+#ifndef __ASSEMBLY__4040+4141+/*4242+ * Default implementation of macro that returns current4343+ * instruction pointer ("program counter").4444+ */4545+#define current_text_addr() ({ __label__ _l; _l: &&_l; })4646+4747+# define TASK_SIZE 0x7FFF0000UL4848+# define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))4949+5050+/* The Nios processor specific thread struct. */5151+struct thread_struct {5252+ struct pt_regs *kregs;5353+5454+ /* Context switch saved kernel state. */5555+ unsigned long ksp;5656+ unsigned long kpsr;5757+};5858+5959+#define INIT_MMAP \6060+ { &init_mm, (0), (0), __pgprot(0x0), VM_READ | VM_WRITE | VM_EXEC }6161+6262+# define INIT_THREAD { \6363+ .kregs = NULL, \6464+ .ksp = 0, \6565+ .kpsr = 0, \6666+}6767+6868+extern void start_thread(struct pt_regs *regs, unsigned long pc,6969+ unsigned long sp);7070+7171+struct task_struct;7272+7373+/* Free all resources held by a thread. */7474+static inline void release_thread(struct task_struct *dead_task)7575+{7676+}7777+7878+/* Free current thread data structures etc.. */7979+static inline void exit_thread(void)8080+{8181+}8282+8383+/* Return saved PC of a blocked thread. */8484+#define thread_saved_pc(tsk) ((tsk)->thread.kregs->ea)8585+8686+extern unsigned long get_wchan(struct task_struct *p);8787+8888+/* Prepare to copy thread state - unlazy all lazy status */8989+#define prepare_to_copy(tsk) do { } while (0)9090+9191+#define task_pt_regs(p) \9292+ ((struct pt_regs *)(THREAD_SIZE + task_stack_page(p)) - 1)9393+9494+/* Used by procfs */9595+#define KSTK_EIP(tsk) ((tsk)->thread.kregs->ea)9696+#define KSTK_ESP(tsk) ((tsk)->thread.kregs->sp)9797+9898+#define cpu_relax() barrier()9999+#define cpu_relax_lowlatency() cpu_relax()100100+101101+#endif /* __ASSEMBLY__ */102102+103103+#endif /* _ASM_NIOS2_PROCESSOR_H */
+31
arch/nios2/include/asm/switch_to.h
···11+/*22+ * Copyright (C) 2004 Microtronix Datacom Ltd.33+ *44+ * This file is subject to the terms and conditions of the GNU General Public55+ * License. See the file "COPYING" in the main directory of this archive66+ * for more details.77+ */88+#ifndef _ASM_NIOS2_SWITCH_TO_H99+#define _ASM_NIOS2_SWITCH_TO_H1010+1111+/*1212+ * switch_to(n) should switch tasks to task ptr, first checking that1313+ * ptr isn't the current task, in which case it does nothing. This1414+ * also clears the TS-flag if the task we switched to has used the1515+ * math co-processor latest.1616+ */1717+#define switch_to(prev, next, last) \1818+{ \1919+ void *_last; \2020+ __asm__ __volatile__ ( \2121+ "mov r4, %1\n" \2222+ "mov r5, %2\n" \2323+ "call resume\n" \2424+ "mov %0,r4\n" \2525+ : "=r" (_last) \2626+ : "r" (prev), "r" (next) \2727+ : "r4", "r5", "r7", "r8", "ra"); \2828+ (last) = _last; \2929+}3030+3131+#endif /* _ASM_NIOS2_SWITCH_TO_H */
+120
arch/nios2/include/asm/thread_info.h
···11+/*22+ * NiosII low-level thread information33+ *44+ * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>55+ * Copyright (C) 2004 Microtronix Datacom Ltd.66+ *77+ * Based on asm/thread_info_no.h from m68k which is:88+ *99+ * Copyright (C) 2002 David Howells <dhowells@redhat.com>1010+ *1111+ * This file is subject to the terms and conditions of the GNU General Public1212+ * License. See the file "COPYING" in the main directory of this archive1313+ * for more details.1414+ */1515+1616+#ifndef _ASM_NIOS2_THREAD_INFO_H1717+#define _ASM_NIOS2_THREAD_INFO_H1818+1919+#ifdef __KERNEL__2020+2121+/*2222+ * Size of the kernel stack for each process.2323+ */2424+#define THREAD_SIZE_ORDER 12525+#define THREAD_SIZE 8192 /* 2 * PAGE_SIZE */2626+2727+#ifndef __ASSEMBLY__2828+2929+typedef struct {3030+ unsigned long seg;3131+} mm_segment_t;3232+3333+/*3434+ * low level task data that entry.S needs immediate access to3535+ * - this struct should fit entirely inside of one cache line3636+ * - this struct shares the supervisor stack pages3737+ * - if the contents of this structure are changed, the assembly constants3838+ * must also be changed3939+ */4040+struct thread_info {4141+ struct task_struct *task; /* main task structure */4242+ struct exec_domain *exec_domain; /* execution domain */4343+ unsigned long flags; /* low level flags */4444+ __u32 cpu; /* current CPU */4545+ int preempt_count; /* 0 => preemptable,<0 => BUG */4646+ mm_segment_t addr_limit; /* thread address space:4747+ 0-0x7FFFFFFF for user-thead4848+ 0-0xFFFFFFFF for kernel-thread4949+ */5050+ struct restart_block restart_block;5151+ struct pt_regs *regs;5252+};5353+5454+/*5555+ * macros/functions for gaining access to the thread information structure5656+ *5757+ * preempt_count needs to be 1 initially, until the scheduler is functional.5858+ */5959+#define INIT_THREAD_INFO(tsk) \6060+{ \6161+ .task = &tsk, \6262+ .exec_domain = &default_exec_domain, \6363+ .flags = 0, \6464+ .cpu = 0, \6565+ .preempt_count = INIT_PREEMPT_COUNT, \6666+ .addr_limit = KERNEL_DS, \6767+ .restart_block = { \6868+ .fn = do_no_restart_syscall, \6969+ }, \7070+}7171+7272+#define init_thread_info (init_thread_union.thread_info)7373+#define init_stack (init_thread_union.stack)7474+7575+/* how to get the thread information struct from C */7676+static inline struct thread_info *current_thread_info(void)7777+{7878+ register unsigned long sp asm("sp");7979+8080+ return (struct thread_info *)(sp & ~(THREAD_SIZE - 1));8181+}8282+#endif /* !__ASSEMBLY__ */8383+8484+/*8585+ * thread information flags8686+ * - these are process state flags that various assembly files may need to8787+ * access8888+ * - pending work-to-be-done flags are in LSW8989+ * - other flags in MSW9090+ */9191+#define TIF_SYSCALL_TRACE 0 /* syscall trace active */9292+#define TIF_NOTIFY_RESUME 1 /* resumption notification requested */9393+#define TIF_SIGPENDING 2 /* signal pending */9494+#define TIF_NEED_RESCHED 3 /* rescheduling necessary */9595+#define TIF_MEMDIE 4 /* is terminating due to OOM killer */9696+#define TIF_SECCOMP 5 /* secure computing */9797+#define TIF_SYSCALL_AUDIT 6 /* syscall auditing active */9898+#define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */9999+100100+#define TIF_POLLING_NRFLAG 16 /* true if poll_idle() is polling101101+ TIF_NEED_RESCHED */102102+103103+#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)104104+#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)105105+#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)106106+#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)107107+#define _TIF_SECCOMP (1 << TIF_SECCOMP)108108+#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)109109+#define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)110110+#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)111111+112112+/* work to do on interrupt/exception return */113113+#define _TIF_WORK_MASK 0x0000FFFE114114+115115+/* work to do on any return to u-space */116116+# define _TIF_ALLWORK_MASK 0x0000FFFF117117+118118+#endif /* __KERNEL__ */119119+120120+#endif /* _ASM_NIOS2_THREAD_INFO_H */
+258
arch/nios2/kernel/process.c
···11+/*22+ * Architecture-dependent parts of process handling.33+ *44+ * Copyright (C) 2013 Altera Corporation55+ * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>66+ * Copyright (C) 2009 Wind River Systems Inc77+ * Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com88+ * Copyright (C) 2004 Microtronix Datacom Ltd99+ *1010+ * This file is subject to the terms and conditions of the GNU General Public1111+ * License. See the file "COPYING" in the main directory of this archive1212+ * for more details.1313+ */1414+1515+#include <linux/export.h>1616+#include <linux/sched.h>1717+#include <linux/tick.h>1818+#include <linux/uaccess.h>1919+2020+#include <asm/unistd.h>2121+#include <asm/traps.h>2222+#include <asm/cpuinfo.h>2323+2424+asmlinkage void ret_from_fork(void);2525+asmlinkage void ret_from_kernel_thread(void);2626+2727+void (*pm_power_off)(void) = NULL;2828+EXPORT_SYMBOL(pm_power_off);2929+3030+void arch_cpu_idle(void)3131+{3232+ local_irq_enable();3333+}3434+3535+/*3636+ * The development boards have no way to pull a board reset. Just jump to the3737+ * cpu reset address and let the boot loader or the code in head.S take care of3838+ * resetting peripherals.3939+ */4040+void machine_restart(char *__unused)4141+{4242+ pr_notice("Machine restart (%08x)...\n", cpuinfo.reset_addr);4343+ local_irq_disable();4444+ __asm__ __volatile__ (4545+ "jmp %0\n\t"4646+ :4747+ : "r" (cpuinfo.reset_addr)4848+ : "r4");4949+}5050+5151+void machine_halt(void)5252+{5353+ pr_notice("Machine halt...\n");5454+ local_irq_disable();5555+ for (;;)5656+ ;5757+}5858+5959+/*6060+ * There is no way to power off the development boards. So just spin for now. If6161+ * we ever have a way of resetting a board using a GPIO we should add that here.6262+ */6363+void machine_power_off(void)6464+{6565+ pr_notice("Machine power off...\n");6666+ local_irq_disable();6767+ for (;;)6868+ ;6969+}7070+7171+void show_regs(struct pt_regs *regs)7272+{7373+ pr_notice("\n");7474+ show_regs_print_info(KERN_DEFAULT);7575+7676+ pr_notice("r1: %08lx r2: %08lx r3: %08lx r4: %08lx\n",7777+ regs->r1, regs->r2, regs->r3, regs->r4);7878+7979+ pr_notice("r5: %08lx r6: %08lx r7: %08lx r8: %08lx\n",8080+ regs->r5, regs->r6, regs->r7, regs->r8);8181+8282+ pr_notice("r9: %08lx r10: %08lx r11: %08lx r12: %08lx\n",8383+ regs->r9, regs->r10, regs->r11, regs->r12);8484+8585+ pr_notice("r13: %08lx r14: %08lx r15: %08lx\n",8686+ regs->r13, regs->r14, regs->r15);8787+8888+ pr_notice("ra: %08lx fp: %08lx sp: %08lx gp: %08lx\n",8989+ regs->ra, regs->fp, regs->sp, regs->gp);9090+9191+ pr_notice("ea: %08lx estatus: %08lx\n",9292+ regs->ea, regs->estatus);9393+}9494+9595+void flush_thread(void)9696+{9797+ set_fs(USER_DS);9898+}9999+100100+int copy_thread(unsigned long clone_flags,101101+ unsigned long usp, unsigned long arg, struct task_struct *p)102102+{103103+ struct pt_regs *childregs = task_pt_regs(p);104104+ struct pt_regs *regs;105105+ struct switch_stack *stack;106106+ struct switch_stack *childstack =107107+ ((struct switch_stack *)childregs) - 1;108108+109109+ if (unlikely(p->flags & PF_KTHREAD)) {110110+ memset(childstack, 0,111111+ sizeof(struct switch_stack) + sizeof(struct pt_regs));112112+113113+ childstack->r16 = usp; /* fn */114114+ childstack->r17 = arg;115115+ childstack->ra = (unsigned long) ret_from_kernel_thread;116116+ childregs->estatus = STATUS_PIE;117117+ childregs->sp = (unsigned long) childstack;118118+119119+ p->thread.ksp = (unsigned long) childstack;120120+ p->thread.kregs = childregs;121121+ return 0;122122+ }123123+124124+ regs = current_pt_regs();125125+ *childregs = *regs;126126+ childregs->r2 = 0; /* Set the return value for the child. */127127+ childregs->r7 = 0;128128+129129+ stack = ((struct switch_stack *) regs) - 1;130130+ *childstack = *stack;131131+ childstack->ra = (unsigned long)ret_from_fork;132132+ p->thread.kregs = childregs;133133+ p->thread.ksp = (unsigned long) childstack;134134+135135+ if (usp)136136+ childregs->sp = usp;137137+138138+ /* Initialize tls register. */139139+ if (clone_flags & CLONE_SETTLS)140140+ childstack->r23 = regs->r8;141141+142142+ return 0;143143+}144144+145145+/*146146+ * Generic dumping code. Used for panic and debug.147147+ */148148+void dump(struct pt_regs *fp)149149+{150150+ unsigned long *sp;151151+ unsigned char *tp;152152+ int i;153153+154154+ pr_emerg("\nCURRENT PROCESS:\n\n");155155+ pr_emerg("COMM=%s PID=%d\n", current->comm, current->pid);156156+157157+ if (current->mm) {158158+ pr_emerg("TEXT=%08x-%08x DATA=%08x-%08x BSS=%08x-%08x\n",159159+ (int) current->mm->start_code,160160+ (int) current->mm->end_code,161161+ (int) current->mm->start_data,162162+ (int) current->mm->end_data,163163+ (int) current->mm->end_data,164164+ (int) current->mm->brk);165165+ pr_emerg("USER-STACK=%08x KERNEL-STACK=%08x\n\n",166166+ (int) current->mm->start_stack,167167+ (int)(((unsigned long) current) + THREAD_SIZE));168168+ }169169+170170+ pr_emerg("PC: %08lx\n", fp->ea);171171+ pr_emerg("SR: %08lx SP: %08lx\n",172172+ (long) fp->estatus, (long) fp);173173+174174+ pr_emerg("r1: %08lx r2: %08lx r3: %08lx\n",175175+ fp->r1, fp->r2, fp->r3);176176+177177+ pr_emerg("r4: %08lx r5: %08lx r6: %08lx r7: %08lx\n",178178+ fp->r4, fp->r5, fp->r6, fp->r7);179179+ pr_emerg("r8: %08lx r9: %08lx r10: %08lx r11: %08lx\n",180180+ fp->r8, fp->r9, fp->r10, fp->r11);181181+ pr_emerg("r12: %08lx r13: %08lx r14: %08lx r15: %08lx\n",182182+ fp->r12, fp->r13, fp->r14, fp->r15);183183+ pr_emerg("or2: %08lx ra: %08lx fp: %08lx sp: %08lx\n",184184+ fp->orig_r2, fp->ra, fp->fp, fp->sp);185185+ pr_emerg("\nUSP: %08x TRAPFRAME: %08x\n",186186+ (unsigned int) fp->sp, (unsigned int) fp);187187+188188+ pr_emerg("\nCODE:");189189+ tp = ((unsigned char *) fp->ea) - 0x20;190190+ for (sp = (unsigned long *) tp, i = 0; (i < 0x40); i += 4) {191191+ if ((i % 0x10) == 0)192192+ pr_emerg("\n%08x: ", (int) (tp + i));193193+ pr_emerg("%08x ", (int) *sp++);194194+ }195195+ pr_emerg("\n");196196+197197+ pr_emerg("\nKERNEL STACK:");198198+ tp = ((unsigned char *) fp) - 0x40;199199+ for (sp = (unsigned long *) tp, i = 0; (i < 0xc0); i += 4) {200200+ if ((i % 0x10) == 0)201201+ pr_emerg("\n%08x: ", (int) (tp + i));202202+ pr_emerg("%08x ", (int) *sp++);203203+ }204204+ pr_emerg("\n");205205+ pr_emerg("\n");206206+207207+ pr_emerg("\nUSER STACK:");208208+ tp = (unsigned char *) (fp->sp - 0x10);209209+ for (sp = (unsigned long *) tp, i = 0; (i < 0x80); i += 4) {210210+ if ((i % 0x10) == 0)211211+ pr_emerg("\n%08x: ", (int) (tp + i));212212+ pr_emerg("%08x ", (int) *sp++);213213+ }214214+ pr_emerg("\n\n");215215+}216216+217217+unsigned long get_wchan(struct task_struct *p)218218+{219219+ unsigned long fp, pc;220220+ unsigned long stack_page;221221+ int count = 0;222222+223223+ if (!p || p == current || p->state == TASK_RUNNING)224224+ return 0;225225+226226+ stack_page = (unsigned long)p;227227+ fp = ((struct switch_stack *)p->thread.ksp)->fp; /* ;dgt2 */228228+ do {229229+ if (fp < stack_page+sizeof(struct task_struct) ||230230+ fp >= 8184+stack_page) /* ;dgt2;tmp */231231+ return 0;232232+ pc = ((unsigned long *)fp)[1];233233+ if (!in_sched_functions(pc))234234+ return pc;235235+ fp = *(unsigned long *) fp;236236+ } while (count++ < 16); /* ;dgt2;tmp */237237+ return 0;238238+}239239+240240+/*241241+ * Do necessary setup to start up a newly executed thread.242242+ * Will startup in user mode (status_extension = 0).243243+ */244244+void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp)245245+{246246+ memset((void *) regs, 0, sizeof(struct pt_regs));247247+ regs->estatus = ESTATUS_EPIE | ESTATUS_EU;248248+ regs->ea = pc;249249+ regs->sp = sp;250250+}251251+252252+#include <linux/elfcore.h>253253+254254+/* Fill in the FPU structure for a core dump. */255255+int dump_fpu(struct pt_regs *regs, elf_fpregset_t *r)256256+{257257+ return 0; /* Nios2 has no FPU and thus no FPU registers */258258+}
+116
arch/nios2/mm/mmu_context.c
···11+/*22+ * MMU context handling.33+ *44+ * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>55+ * Copyright (C) 2009 Wind River Systems Inc66+ * Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com77+ *88+ * This file is subject to the terms and conditions of the GNU General Public99+ * License. See the file "COPYING" in the main directory of this archive1010+ * for more details.1111+ */1212+1313+#include <linux/mm.h>1414+1515+#include <asm/cpuinfo.h>1616+#include <asm/mmu_context.h>1717+#include <asm/tlb.h>1818+1919+/* The pids position and mask in context */2020+#define PID_SHIFT 02121+#define PID_BITS (cpuinfo.tlb_pid_num_bits)2222+#define PID_MASK ((1UL << PID_BITS) - 1)2323+2424+/* The versions position and mask in context */2525+#define VERSION_BITS (32 - PID_BITS)2626+#define VERSION_SHIFT (PID_SHIFT + PID_BITS)2727+#define VERSION_MASK ((1UL << VERSION_BITS) - 1)2828+2929+/* Return the version part of a context */3030+#define CTX_VERSION(c) (((c) >> VERSION_SHIFT) & VERSION_MASK)3131+3232+/* Return the pid part of a context */3333+#define CTX_PID(c) (((c) >> PID_SHIFT) & PID_MASK)3434+3535+/* Value of the first context (version 1, pid 0) */3636+#define FIRST_CTX ((1UL << VERSION_SHIFT) | (0 << PID_SHIFT))3737+3838+static mm_context_t next_mmu_context;3939+4040+/*4141+ * Initialize MMU context management stuff.4242+ */4343+void __init mmu_context_init(void)4444+{4545+ /* We need to set this here because the value depends on runtime data4646+ * from cpuinfo */4747+ next_mmu_context = FIRST_CTX;4848+}4949+5050+/*5151+ * Set new context (pid), keep way5252+ */5353+static void set_context(mm_context_t context)5454+{5555+ set_mmu_pid(CTX_PID(context));5656+}5757+5858+static mm_context_t get_new_context(void)5959+{6060+ /* Return the next pid */6161+ next_mmu_context += (1UL << PID_SHIFT);6262+6363+ /* If the pid field wraps around we increase the version and6464+ * flush the tlb */6565+ if (unlikely(CTX_PID(next_mmu_context) == 0)) {6666+ /* Version is incremented since the pid increment above6767+ * overflows info version */6868+ flush_cache_all();6969+ flush_tlb_all();7070+ }7171+7272+ /* If the version wraps we start over with the first generation, we do7373+ * not need to flush the tlb here since it's always done above */7474+ if (unlikely(CTX_VERSION(next_mmu_context) == 0))7575+ next_mmu_context = FIRST_CTX;7676+7777+ return next_mmu_context;7878+}7979+8080+void switch_mm(struct mm_struct *prev, struct mm_struct *next,8181+ struct task_struct *tsk)8282+{8383+ unsigned long flags;8484+8585+ local_irq_save(flags);8686+8787+ /* If the process context we are swapping in has a different context8888+ * generation then we have it should get a new generation/pid */8989+ if (unlikely(CTX_VERSION(next->context) !=9090+ CTX_VERSION(next_mmu_context)))9191+ next->context = get_new_context();9292+9393+ /* Save the current pgd so the fast tlb handler can find it */9494+ pgd_current = next->pgd;9595+9696+ /* Set the current context */9797+ set_context(next->context);9898+9999+ local_irq_restore(flags);100100+}101101+102102+/*103103+ * After we have set current->mm to a new value, this activates104104+ * the context for the new mm so we see the new mappings.105105+ */106106+void activate_mm(struct mm_struct *prev, struct mm_struct *next)107107+{108108+ next->context = get_new_context();109109+ set_context(next->context);110110+ pgd_current = next->pgd;111111+}112112+113113+unsigned long get_pid_from_context(mm_context_t *context)114114+{115115+ return CTX_PID((*context));116116+}