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 unsigned long phys_addr
= PHYSADDR(to
);
41 unsigned long p3_addr
= P3SEG
+ (address
& CACHE_ALIAS
);
42 pgd_t
*pgd
= pgd_offset_k(p3_addr
);
43 pud_t
*pud
= pud_offset(pgd
, p3_addr
);
44 pmd_t
*pmd
= pmd_offset(pud
, p3_addr
);
45 pte_t
*pte
= pte_offset_kernel(pmd
, p3_addr
);
49 entry
= pfn_pte(phys_addr
>> PAGE_SHIFT
, PAGE_KERNEL
);
50 down(&p3map_sem
[(address
& CACHE_ALIAS
)>>12]);
52 local_irq_save(flags
);
53 __flush_tlb_page(get_asid(), p3_addr
);
54 local_irq_restore(flags
);
55 update_mmu_cache(NULL
, p3_addr
, entry
);
56 __clear_user_page((void *)p3_addr
, to
);
57 pte_clear(&init_mm
, p3_addr
, pte
);
58 up(&p3map_sem
[(address
& CACHE_ALIAS
)>>12]);
66 * @address: U0 address to be mapped
67 * @page: page (virt_to_page(to))
69 void copy_user_page(void *to
, void *from
, unsigned long address
,
72 __set_bit(PG_mapped
, &page
->flags
);
73 if (((address
^ (unsigned long)to
) & CACHE_ALIAS
) == 0)
76 unsigned long phys_addr
= PHYSADDR(to
);
77 unsigned long p3_addr
= P3SEG
+ (address
& CACHE_ALIAS
);
78 pgd_t
*pgd
= pgd_offset_k(p3_addr
);
79 pud_t
*pud
= pud_offset(pgd
, p3_addr
);
80 pmd_t
*pmd
= pmd_offset(pud
, p3_addr
);
81 pte_t
*pte
= pte_offset_kernel(pmd
, p3_addr
);
85 entry
= pfn_pte(phys_addr
>> PAGE_SHIFT
, PAGE_KERNEL
);
86 down(&p3map_sem
[(address
& CACHE_ALIAS
)>>12]);
88 local_irq_save(flags
);
89 __flush_tlb_page(get_asid(), p3_addr
);
90 local_irq_restore(flags
);
91 update_mmu_cache(NULL
, p3_addr
, entry
);
92 __copy_user_page((void *)p3_addr
, from
, to
);
93 pte_clear(&init_mm
, p3_addr
, pte
);
94 up(&p3map_sem
[(address
& CACHE_ALIAS
)>>12]);
99 * For SH-4, we have our own implementation for ptep_get_and_clear
101 inline pte_t
ptep_get_and_clear(struct mm_struct
*mm
, unsigned long addr
, pte_t
*ptep
)
105 pte_clear(mm
, addr
, ptep
);
106 if (!pte_not_present(pte
)) {
107 unsigned long pfn
= pte_pfn(pte
);
108 if (pfn_valid(pfn
)) {
109 struct page
*page
= pfn_to_page(pfn
);
110 struct address_space
*mapping
= page_mapping(page
);
111 if (!mapping
|| !mapping_writably_mapped(mapping
))
112 __clear_bit(PG_mapped
, &page
->flags
);