2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1999 Niibe Yutaka
|
2007-11-09 08:37:18 +01:00
|
|
|
* Copyright (C) 2003 - 2007 Paul Mundt
|
2005-04-17 00:20:36 +02:00
|
|
|
*
|
|
|
|
* ASID handling idea taken from MIPS implementation.
|
|
|
|
*/
|
|
|
|
#ifndef __ASM_SH_MMU_CONTEXT_H
|
|
|
|
#define __ASM_SH_MMU_CONTEXT_H
|
|
|
|
|
2007-11-09 08:37:18 +01:00
|
|
|
#ifdef __KERNEL__
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <asm/cpu/mmu_context.h>
|
|
|
|
#include <asm/tlbflush.h>
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
#include <asm/io.h>
|
2007-05-02 19:27:14 +02:00
|
|
|
#include <asm-generic/mm_hooks.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The MMU "context" consists of two things:
|
|
|
|
* (a) TLB cache version (or round, cycle whatever expression you like)
|
|
|
|
* (b) ASID (Address Space IDentifier)
|
|
|
|
*/
|
|
|
|
#define MMU_CONTEXT_ASID_MASK 0x000000ff
|
|
|
|
#define MMU_CONTEXT_VERSION_MASK 0xffffff00
|
|
|
|
#define MMU_CONTEXT_FIRST_VERSION 0x00000100
|
|
|
|
#define NO_CONTEXT 0
|
|
|
|
|
|
|
|
/* ASID is 8-bit value, so it can't be 0x100 */
|
|
|
|
#define MMU_NO_ASID 0x100
|
|
|
|
|
2006-12-25 01:51:47 +01:00
|
|
|
#define asid_cache(cpu) (cpu_data[cpu].asid_cache)
|
2007-11-09 08:37:18 +01:00
|
|
|
#define cpu_context(cpu, mm) ((mm)->context.id[cpu])
|
|
|
|
|
|
|
|
#define cpu_asid(cpu, mm) \
|
|
|
|
(cpu_context((cpu), (mm)) & MMU_CONTEXT_ASID_MASK)
|
2006-12-25 01:51:47 +01:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Virtual Page Number mask
|
|
|
|
*/
|
|
|
|
#define MMU_VPN_MASK 0xfffff000
|
|
|
|
|
|
|
|
#ifdef CONFIG_MMU
|
2007-11-09 08:37:18 +01:00
|
|
|
#if defined(CONFIG_SUPERH32)
|
|
|
|
#include "mmu_context_32.h"
|
|
|
|
#else
|
|
|
|
#include "mmu_context_64.h"
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Get MMU context if needed.
|
|
|
|
*/
|
2006-12-25 01:51:47 +01:00
|
|
|
static inline void get_mmu_context(struct mm_struct *mm, unsigned int cpu)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2006-12-25 01:51:47 +01:00
|
|
|
unsigned long asid = asid_cache(cpu);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* Check if we have old version of context. */
|
2006-12-25 01:51:47 +01:00
|
|
|
if (((cpu_context(cpu, mm) ^ asid) & MMU_CONTEXT_VERSION_MASK) == 0)
|
2005-04-17 00:20:36 +02:00
|
|
|
/* It's up to date, do nothing */
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* It's old, we need to get new context with new version. */
|
2006-12-25 01:51:47 +01:00
|
|
|
if (!(++asid & MMU_CONTEXT_ASID_MASK)) {
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* We exhaust ASID of this version.
|
|
|
|
* Flush all TLB and start new cycle.
|
|
|
|
*/
|
|
|
|
flush_tlb_all();
|
2006-11-21 05:53:44 +01:00
|
|
|
|
2007-11-09 08:37:18 +01:00
|
|
|
#ifdef CONFIG_SUPERH64
|
|
|
|
/*
|
|
|
|
* The SH-5 cache uses the ASIDs, requiring both the I and D
|
|
|
|
* cache to be flushed when the ASID is exhausted. Weak.
|
|
|
|
*/
|
|
|
|
flush_cache_all();
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Fix version; Note that we avoid version #0
|
|
|
|
* to distingush NO_CONTEXT.
|
|
|
|
*/
|
2006-12-25 01:51:47 +01:00
|
|
|
if (!asid)
|
|
|
|
asid = MMU_CONTEXT_FIRST_VERSION;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2006-12-25 01:51:47 +01:00
|
|
|
|
|
|
|
cpu_context(cpu, mm) = asid_cache(cpu) = asid;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the context related info for a new mm_struct
|
|
|
|
* instance.
|
|
|
|
*/
|
2006-11-21 05:53:44 +01:00
|
|
|
static inline int init_new_context(struct task_struct *tsk,
|
2006-12-25 01:51:47 +01:00
|
|
|
struct mm_struct *mm)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2006-12-25 01:51:47 +01:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < num_online_cpus(); i++)
|
|
|
|
cpu_context(i, mm) = NO_CONTEXT;
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* After we have set current->mm to a new value, this activates
|
|
|
|
* the context for the new mm so we see the new mappings.
|
|
|
|
*/
|
2006-12-25 01:51:47 +01:00
|
|
|
static inline void activate_context(struct mm_struct *mm, unsigned int cpu)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2006-12-25 01:51:47 +01:00
|
|
|
get_mmu_context(mm, cpu);
|
|
|
|
set_asid(cpu_asid(cpu, mm));
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2006-11-21 05:53:44 +01:00
|
|
|
static inline void switch_mm(struct mm_struct *prev,
|
|
|
|
struct mm_struct *next,
|
|
|
|
struct task_struct *tsk)
|
|
|
|
{
|
2006-12-25 01:51:47 +01:00
|
|
|
unsigned int cpu = smp_processor_id();
|
|
|
|
|
2006-11-21 05:53:44 +01:00
|
|
|
if (likely(prev != next)) {
|
2006-12-25 01:51:47 +01:00
|
|
|
cpu_set(cpu, next->cpu_vm_mask);
|
2006-11-21 05:53:44 +01:00
|
|
|
set_TTB(next->pgd);
|
2006-12-25 01:51:47 +01:00
|
|
|
activate_context(next, cpu);
|
|
|
|
} else
|
|
|
|
if (!cpu_test_and_set(cpu, next->cpu_vm_mask))
|
|
|
|
activate_context(next, cpu);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2007-11-09 08:37:18 +01:00
|
|
|
#else
|
2005-04-17 00:20:36 +02:00
|
|
|
#define get_mmu_context(mm) do { } while (0)
|
|
|
|
#define init_new_context(tsk,mm) (0)
|
|
|
|
#define destroy_context(mm) do { } while (0)
|
|
|
|
#define set_asid(asid) do { } while (0)
|
|
|
|
#define get_asid() (0)
|
2007-03-28 09:38:13 +02:00
|
|
|
#define set_TTB(pgd) do { } while (0)
|
|
|
|
#define get_TTB() (0)
|
2006-12-25 01:51:47 +01:00
|
|
|
#define activate_context(mm,cpu) do { } while (0)
|
2005-04-17 00:20:36 +02:00
|
|
|
#define switch_mm(prev,next,tsk) do { } while (0)
|
2007-11-09 08:37:18 +01:00
|
|
|
#endif /* CONFIG_MMU */
|
|
|
|
|
|
|
|
#define activate_mm(prev, next) switch_mm((prev),(next),NULL)
|
2005-04-17 00:20:36 +02:00
|
|
|
#define deactivate_mm(tsk,mm) do { } while (0)
|
|
|
|
#define enter_lazy_tlb(mm,tsk) do { } while (0)
|
|
|
|
|
|
|
|
#if defined(CONFIG_CPU_SH3) || defined(CONFIG_CPU_SH4)
|
|
|
|
/*
|
|
|
|
* If this processor has an MMU, we need methods to turn it off/on ..
|
|
|
|
* paging_init() will also have to be updated for the processor in
|
|
|
|
* question.
|
|
|
|
*/
|
|
|
|
static inline void enable_mmu(void)
|
|
|
|
{
|
2006-12-25 01:51:47 +01:00
|
|
|
unsigned int cpu = smp_processor_id();
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* Enable MMU */
|
|
|
|
ctrl_outl(MMU_CONTROL_INIT, MMUCR);
|
2006-09-27 07:57:44 +02:00
|
|
|
ctrl_barrier();
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2006-12-25 01:51:47 +01:00
|
|
|
if (asid_cache(cpu) == NO_CONTEXT)
|
|
|
|
asid_cache(cpu) = MMU_CONTEXT_FIRST_VERSION;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2006-12-25 01:51:47 +01:00
|
|
|
set_asid(asid_cache(cpu) & MMU_CONTEXT_ASID_MASK);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void disable_mmu(void)
|
|
|
|
{
|
|
|
|
unsigned long cr;
|
|
|
|
|
|
|
|
cr = ctrl_inl(MMUCR);
|
|
|
|
cr &= ~MMU_CONTROL_INIT;
|
|
|
|
ctrl_outl(cr, MMUCR);
|
2006-09-27 07:57:44 +02:00
|
|
|
|
|
|
|
ctrl_barrier();
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* MMU control handlers for processors lacking memory
|
|
|
|
* management hardware.
|
|
|
|
*/
|
2007-03-28 09:38:13 +02:00
|
|
|
#define enable_mmu() do { } while (0)
|
|
|
|
#define disable_mmu() do { } while (0)
|
2005-04-17 00:20:36 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __KERNEL__ */
|
|
|
|
#endif /* __ASM_SH_MMU_CONTEXT_H */
|