4 * Copyright (C) 1999, 2000, 2002 Niibe Yutaka
5 * Copyright (C) 2002 - 2005 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[];
26 #define CACHE_ALIAS (cpu_data->dcache.alias_mask)
31 * @address: U0 address to be mapped
32 * @page: page (virt_to_page(to))
34 void clear_user_page(void *to, unsigned long address, struct page *page)
36 __set_bit(PG_mapped, &page->flags);
37 if (((address ^ (unsigned long)to) & CACHE_ALIAS) == 0)
40 pgprot_t pgprot = __pgprot(_PAGE_PRESENT |
41 _PAGE_RW | _PAGE_CACHABLE |
42 _PAGE_DIRTY | _PAGE_ACCESSED |
43 _PAGE_HW_SHARED | _PAGE_FLAGS_HARD);
44 unsigned long phys_addr = PHYSADDR(to);
45 unsigned long p3_addr = P3SEG + (address & CACHE_ALIAS);
46 pgd_t *pgd = pgd_offset_k(p3_addr);
47 pud_t *pud = pud_offset(pgd, p3_addr);
48 pmd_t *pmd = pmd_offset(pud, p3_addr);
49 pte_t *pte = pte_offset_kernel(pmd, p3_addr);
53 entry = pfn_pte(phys_addr >> PAGE_SHIFT, pgprot);
54 down(&p3map_sem[(address & CACHE_ALIAS)>>12]);
56 local_irq_save(flags);
57 __flush_tlb_page(get_asid(), p3_addr);
58 local_irq_restore(flags);
59 update_mmu_cache(NULL, p3_addr, entry);
60 __clear_user_page((void *)p3_addr, to);
61 pte_clear(&init_mm, p3_addr, pte);
62 up(&p3map_sem[(address & CACHE_ALIAS)>>12]);
70 * @address: U0 address to be mapped
71 * @page: page (virt_to_page(to))
73 void copy_user_page(void *to, void *from, unsigned long address,
76 __set_bit(PG_mapped, &page->flags);
77 if (((address ^ (unsigned long)to) & CACHE_ALIAS) == 0)
80 pgprot_t pgprot = __pgprot(_PAGE_PRESENT |
81 _PAGE_RW | _PAGE_CACHABLE |
82 _PAGE_DIRTY | _PAGE_ACCESSED |
83 _PAGE_HW_SHARED | _PAGE_FLAGS_HARD);
84 unsigned long phys_addr = PHYSADDR(to);
85 unsigned long p3_addr = P3SEG + (address & CACHE_ALIAS);
86 pgd_t *pgd = pgd_offset_k(p3_addr);
87 pud_t *pud = pud_offset(pgd, p3_addr);
88 pmd_t *pmd = pmd_offset(pud, p3_addr);
89 pte_t *pte = pte_offset_kernel(pmd, p3_addr);
93 entry = pfn_pte(phys_addr >> PAGE_SHIFT, pgprot);
94 down(&p3map_sem[(address & CACHE_ALIAS)>>12]);
96 local_irq_save(flags);
97 __flush_tlb_page(get_asid(), p3_addr);
98 local_irq_restore(flags);
99 update_mmu_cache(NULL, p3_addr, entry);
100 __copy_user_page((void *)p3_addr, from, to);
101 pte_clear(&init_mm, p3_addr, pte);
102 up(&p3map_sem[(address & CACHE_ALIAS)>>12]);
107 * For SH-4, we have our own implementation for ptep_get_and_clear
109 inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
113 pte_clear(mm, addr, ptep);
114 if (!pte_not_present(pte)) {
115 unsigned long pfn = pte_pfn(pte);
116 if (pfn_valid(pfn)) {
117 struct page *page = pfn_to_page(pfn);
118 struct address_space *mapping = page_mapping(page);
119 if (!mapping || !mapping_writably_mapped(mapping))
120 __clear_bit(PG_mapped, &page->flags);