Path: blob/master/arch/avr32/include/asm/mmu_context.h
10819 views
/*1* Copyright (C) 2004-2006 Atmel Corporation2*3* ASID handling taken from SH implementation.4* Copyright (C) 1999 Niibe Yutaka5* Copyright (C) 2003 Paul Mundt6*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU General Public License version 2 as9* published by the Free Software Foundation.10*/11#ifndef __ASM_AVR32_MMU_CONTEXT_H12#define __ASM_AVR32_MMU_CONTEXT_H1314#include <asm/tlbflush.h>15#include <asm/sysreg.h>16#include <asm-generic/mm_hooks.h>1718/*19* The MMU "context" consists of two things:20* (a) TLB cache version21* (b) ASID (Address Space IDentifier)22*/23#define MMU_CONTEXT_ASID_MASK 0x000000ff24#define MMU_CONTEXT_VERSION_MASK 0xffffff0025#define MMU_CONTEXT_FIRST_VERSION 0x0000010026#define NO_CONTEXT 02728#define MMU_NO_ASID 0x1002930/* Virtual Page Number mask */31#define MMU_VPN_MASK 0xfffff0003233/* Cache of MMU context last used */34extern unsigned long mmu_context_cache;3536/*37* Get MMU context if needed38*/39static inline void40get_mmu_context(struct mm_struct *mm)41{42unsigned long mc = mmu_context_cache;4344if (((mm->context ^ mc) & MMU_CONTEXT_VERSION_MASK) == 0)45/* It's up to date, do nothing */46return;4748/* It's old, we need to get new context with new version */49mc = ++mmu_context_cache;50if (!(mc & MMU_CONTEXT_ASID_MASK)) {51/*52* We have exhausted all ASIDs of this version.53* Flush the TLB and start new cycle.54*/55flush_tlb_all();56/*57* Fix version. Note that we avoid version #058* to distinguish NO_CONTEXT.59*/60if (!mc)61mmu_context_cache = mc = MMU_CONTEXT_FIRST_VERSION;62}63mm->context = mc;64}6566/*67* Initialize the context related info for a new mm_struct68* instance.69*/70static inline int init_new_context(struct task_struct *tsk,71struct mm_struct *mm)72{73mm->context = NO_CONTEXT;74return 0;75}7677/*78* Destroy context related info for an mm_struct that is about79* to be put to rest.80*/81static inline void destroy_context(struct mm_struct *mm)82{83/* Do nothing */84}8586static inline void set_asid(unsigned long asid)87{88/* XXX: We're destroying TLBEHI[8:31] */89sysreg_write(TLBEHI, asid & MMU_CONTEXT_ASID_MASK);90cpu_sync_pipeline();91}9293static inline unsigned long get_asid(void)94{95unsigned long asid;9697asid = sysreg_read(TLBEHI);98return asid & MMU_CONTEXT_ASID_MASK;99}100101static inline void activate_context(struct mm_struct *mm)102{103get_mmu_context(mm);104set_asid(mm->context & MMU_CONTEXT_ASID_MASK);105}106107static inline void switch_mm(struct mm_struct *prev,108struct mm_struct *next,109struct task_struct *tsk)110{111if (likely(prev != next)) {112unsigned long __pgdir = (unsigned long)next->pgd;113114sysreg_write(PTBR, __pgdir);115activate_context(next);116}117}118119#define deactivate_mm(tsk,mm) do { } while(0)120121#define activate_mm(prev, next) switch_mm((prev), (next), NULL)122123static inline void124enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)125{126}127128129static inline void enable_mmu(void)130{131sysreg_write(MMUCR, (SYSREG_BIT(MMUCR_S)132| SYSREG_BIT(E)133| SYSREG_BIT(MMUCR_I)));134nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();135136if (mmu_context_cache == NO_CONTEXT)137mmu_context_cache = MMU_CONTEXT_FIRST_VERSION;138139set_asid(mmu_context_cache & MMU_CONTEXT_ASID_MASK);140}141142static inline void disable_mmu(void)143{144sysreg_write(MMUCR, SYSREG_BIT(MMUCR_S));145}146147#endif /* __ASM_AVR32_MMU_CONTEXT_H */148149150