pg-sh4.c 2.4 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4
/*
 * arch/sh/mm/pg-sh4.c
 *
 * Copyright (C) 1999, 2000, 2002  Niibe Yutaka
5
 * Copyright (C) 2002 - 2005  Paul Mundt
L
Linus Torvalds 已提交
6 7 8 9
 *
 * Released under the terms of the GNU GPL v2.0.
 */
#include <linux/mm.h>
P
Paul Mundt 已提交
10
#include <linux/mutex.h>
L
Linus Torvalds 已提交
11 12 13
#include <asm/mmu_context.h>
#include <asm/cacheflush.h>

P
Paul Mundt 已提交
14
extern struct mutex p3map_mutex[];
L
Linus Torvalds 已提交
15

16
#define CACHE_ALIAS (current_cpu_data.dcache.alias_mask)
17

L
Linus Torvalds 已提交
18 19 20 21 22 23 24 25 26 27 28 29 30
/*
 * clear_user_page
 * @to: P1 address
 * @address: U0 address to be mapped
 * @page: page (virt_to_page(to))
 */
void clear_user_page(void *to, unsigned long address, struct page *page)
{
	if (((address ^ (unsigned long)to) & CACHE_ALIAS) == 0)
		clear_page(to);
	else {
		unsigned long phys_addr = PHYSADDR(to);
		unsigned long p3_addr = P3SEG + (address & CACHE_ALIAS);
31 32 33
		pgd_t *pgd = pgd_offset_k(p3_addr);
		pud_t *pud = pud_offset(pgd, p3_addr);
		pmd_t *pmd = pmd_offset(pud, p3_addr);
L
Linus Torvalds 已提交
34 35 36 37
		pte_t *pte = pte_offset_kernel(pmd, p3_addr);
		pte_t entry;
		unsigned long flags;

38
		entry = pfn_pte(phys_addr >> PAGE_SHIFT, PAGE_KERNEL);
P
Paul Mundt 已提交
39
		mutex_lock(&p3map_mutex[(address & CACHE_ALIAS)>>12]);
L
Linus Torvalds 已提交
40 41
		set_pte(pte, entry);
		local_irq_save(flags);
42
		flush_tlb_one(get_asid(), p3_addr);
L
Linus Torvalds 已提交
43 44 45 46
		local_irq_restore(flags);
		update_mmu_cache(NULL, p3_addr, entry);
		__clear_user_page((void *)p3_addr, to);
		pte_clear(&init_mm, p3_addr, pte);
P
Paul Mundt 已提交
47
		mutex_unlock(&p3map_mutex[(address & CACHE_ALIAS)>>12]);
L
Linus Torvalds 已提交
48 49 50 51 52 53 54 55 56 57
	}
}

/*
 * copy_user_page
 * @to: P1 address
 * @from: P1 address
 * @address: U0 address to be mapped
 * @page: page (virt_to_page(to))
 */
58
void copy_user_page(void *to, void *from, unsigned long address,
L
Linus Torvalds 已提交
59 60 61 62 63 64 65
		    struct page *page)
{
	if (((address ^ (unsigned long)to) & CACHE_ALIAS) == 0)
		copy_page(to, from);
	else {
		unsigned long phys_addr = PHYSADDR(to);
		unsigned long p3_addr = P3SEG + (address & CACHE_ALIAS);
66 67 68
		pgd_t *pgd = pgd_offset_k(p3_addr);
		pud_t *pud = pud_offset(pgd, p3_addr);
		pmd_t *pmd = pmd_offset(pud, p3_addr);
L
Linus Torvalds 已提交
69 70 71 72
		pte_t *pte = pte_offset_kernel(pmd, p3_addr);
		pte_t entry;
		unsigned long flags;

73
		entry = pfn_pte(phys_addr >> PAGE_SHIFT, PAGE_KERNEL);
P
Paul Mundt 已提交
74
		mutex_lock(&p3map_mutex[(address & CACHE_ALIAS)>>12]);
L
Linus Torvalds 已提交
75 76
		set_pte(pte, entry);
		local_irq_save(flags);
77
		flush_tlb_one(get_asid(), p3_addr);
L
Linus Torvalds 已提交
78 79 80 81
		local_irq_restore(flags);
		update_mmu_cache(NULL, p3_addr, entry);
		__copy_user_page((void *)p3_addr, from, to);
		pte_clear(&init_mm, p3_addr, pte);
P
Paul Mundt 已提交
82
		mutex_unlock(&p3map_mutex[(address & CACHE_ALIAS)>>12]);
L
Linus Torvalds 已提交
83 84
	}
}