4 * Copyright (C) 1999, 2000, 2002 Niibe Yutaka
5 * Copyright (C) 2002 Paul Mundt
7 * Released under the terms of the GNU GPL v2.0.
9 #include <linux/init.h>
10 #include <linux/mman.h>
12 #include <linux/threads.h>
13 #include <asm/addrspace.h>
15 #include <asm/pgtable.h>
16 #include <asm/processor.h>
17 #include <asm/cache.h>
19 #include <asm/uaccess.h>
20 #include <asm/pgalloc.h>
21 #include <asm/mmu_context.h>
22 #include <asm/cacheflush.h>
24 extern struct semaphore p3map_sem[];
29 * @address: U0 address to be mapped
30 * @page: page (virt_to_page(to))
32 void clear_user_page(void *to, unsigned long address, struct page *page)
34 __set_bit(PG_mapped, &page->flags);
35 if (((address ^ (unsigned long)to) & CACHE_ALIAS) == 0)
38 pgprot_t pgprot = __pgprot(_PAGE_PRESENT |
39 _PAGE_RW | _PAGE_CACHABLE |
40 _PAGE_DIRTY | _PAGE_ACCESSED |
41 _PAGE_HW_SHARED | _PAGE_FLAGS_HARD);
42 unsigned long phys_addr = PHYSADDR(to);
43 unsigned long p3_addr = P3SEG + (address & CACHE_ALIAS);
44 pgd_t *dir = pgd_offset_k(p3_addr);
45 pmd_t *pmd = pmd_offset(dir, p3_addr);
46 pte_t *pte = pte_offset_kernel(pmd, p3_addr);
50 entry = pfn_pte(phys_addr >> PAGE_SHIFT, pgprot);
51 down(&p3map_sem[(address & CACHE_ALIAS)>>12]);
53 local_irq_save(flags);
54 __flush_tlb_page(get_asid(), p3_addr);
55 local_irq_restore(flags);
56 update_mmu_cache(NULL, p3_addr, entry);
57 __clear_user_page((void *)p3_addr, to);
58 pte_clear(&init_mm, p3_addr, pte);
59 up(&p3map_sem[(address & CACHE_ALIAS)>>12]);
67 * @address: U0 address to be mapped
68 * @page: page (virt_to_page(to))
70 void copy_user_page(void *to, void *from, unsigned long address,
73 __set_bit(PG_mapped, &page->flags);
74 if (((address ^ (unsigned long)to) & CACHE_ALIAS) == 0)
77 pgprot_t pgprot = __pgprot(_PAGE_PRESENT |
78 _PAGE_RW | _PAGE_CACHABLE |
79 _PAGE_DIRTY | _PAGE_ACCESSED |
80 _PAGE_HW_SHARED | _PAGE_FLAGS_HARD);
81 unsigned long phys_addr = PHYSADDR(to);
82 unsigned long p3_addr = P3SEG + (address & CACHE_ALIAS);
83 pgd_t *dir = pgd_offset_k(p3_addr);
84 pmd_t *pmd = pmd_offset(dir, p3_addr);
85 pte_t *pte = pte_offset_kernel(pmd, p3_addr);
89 entry = pfn_pte(phys_addr >> PAGE_SHIFT, pgprot);
90 down(&p3map_sem[(address & CACHE_ALIAS)>>12]);
92 local_irq_save(flags);
93 __flush_tlb_page(get_asid(), p3_addr);
94 local_irq_restore(flags);
95 update_mmu_cache(NULL, p3_addr, entry);
96 __copy_user_page((void *)p3_addr, from, to);
97 pte_clear(&init_mm, p3_addr, pte);
98 up(&p3map_sem[(address & CACHE_ALIAS)>>12]);
103 * For SH-4, we have our own implementation for ptep_get_and_clear
105 inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
109 pte_clear(mm, addr, ptep);
110 if (!pte_not_present(pte)) {
111 unsigned long pfn = pte_pfn(pte);
112 if (pfn_valid(pfn)) {
113 struct page *page = pfn_to_page(pfn);
114 struct address_space *mapping = page_mapping(page);
115 if (!mapping || !mapping_writably_mapped(mapping))
116 __clear_bit(PG_mapped, &page->flags);