Path: blob/master/arch/microblaze/include/asm/mmu_context_mm.h
26439 views
/* SPDX-License-Identifier: GPL-2.0 */1/*2* Copyright (C) 2008-2009 Michal Simek <[email protected]>3* Copyright (C) 2008-2009 PetaLogix4* Copyright (C) 2006 Atmark Techno, Inc.5*/67#ifndef _ASM_MICROBLAZE_MMU_CONTEXT_H8#define _ASM_MICROBLAZE_MMU_CONTEXT_H910#include <linux/atomic.h>11#include <linux/mm_types.h>12#include <linux/sched.h>1314#include <asm/bitops.h>15#include <asm/mmu.h>16#include <asm-generic/mm_hooks.h>1718# ifdef __KERNEL__19/*20* This function defines the mapping from contexts to VSIDs (virtual21* segment IDs). We use a skew on both the context and the high 4 bits22* of the 32-bit virtual address (the "effective segment ID") in order23* to spread out the entries in the MMU hash table.24*/25# define CTX_TO_VSID(ctx, va) (((ctx) * (897 * 16) + ((va) >> 28) * 0x111) \26& 0xffffff)2728/*29MicroBlaze has 256 contexts, so we can just rotate through these30as a way of "switching" contexts. If the TID of the TLB is zero,31the PID/TID comparison is disabled, so we can use a TID of zero32to represent all kernel pages as shared among all contexts.33*/3435# define NO_CONTEXT 25636# define LAST_CONTEXT 25537# define FIRST_CONTEXT 13839/*40* Set the current MMU context.41* This is done byloading up the segment registers for the user part of the42* address space.43*44* Since the PGD is immediately available, it is much faster to simply45* pass this along as a second parameter, which is required for 8xx and46* can be used for debugging on all processors (if you happen to have47* an Abatron).48*/49extern void set_context(mm_context_t context, pgd_t *pgd);5051/*52* Bitmap of contexts in use.53* The size of this bitmap is LAST_CONTEXT + 1 bits.54*/55extern unsigned long context_map[];5657/*58* This caches the next context number that we expect to be free.59* Its use is an optimization only, we can't rely on this context60* number to be free, but it usually will be.61*/62extern mm_context_t next_mmu_context;6364/*65* Since we don't have sufficient contexts to give one to every task66* that could be in the system, we need to be able to steal contexts.67* These variables support that.68*/69extern atomic_t nr_free_contexts;70extern struct mm_struct *context_mm[LAST_CONTEXT+1];71extern void steal_context(void);7273/*74* Get a new mmu context for the address space described by `mm'.75*/76static inline void get_mmu_context(struct mm_struct *mm)77{78mm_context_t ctx;7980if (mm->context != NO_CONTEXT)81return;82while (atomic_dec_if_positive(&nr_free_contexts) < 0)83steal_context();84ctx = next_mmu_context;85while (test_and_set_bit(ctx, context_map)) {86ctx = find_next_zero_bit(context_map, LAST_CONTEXT+1, ctx);87if (ctx > LAST_CONTEXT)88ctx = 0;89}90next_mmu_context = (ctx + 1) & LAST_CONTEXT;91mm->context = ctx;92context_mm[ctx] = mm;93}9495/*96* Set up the context for a new address space.97*/98# define init_new_context(tsk, mm) (((mm)->context = NO_CONTEXT), 0)99100/*101* We're finished using the context for an address space.102*/103#define destroy_context destroy_context104static inline void destroy_context(struct mm_struct *mm)105{106if (mm->context != NO_CONTEXT) {107clear_bit(mm->context, context_map);108mm->context = NO_CONTEXT;109atomic_inc(&nr_free_contexts);110}111}112113static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,114struct task_struct *tsk)115{116tsk->thread.pgdir = next->pgd;117get_mmu_context(next);118set_context(next->context, next->pgd);119}120121/*122* After we have set current->mm to a new value, this activates123* the context for the new mm so we see the new mappings.124*/125#define activate_mm activate_mm126static inline void activate_mm(struct mm_struct *active_mm,127struct mm_struct *mm)128{129current->thread.pgdir = mm->pgd;130get_mmu_context(mm);131set_context(mm->context, mm->pgd);132}133134extern void mmu_context_init(void);135136#include <asm-generic/mmu_context.h>137138# endif /* __KERNEL__ */139#endif /* _ASM_MICROBLAZE_MMU_CONTEXT_H */140141142