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/config.h>
10 #include <linux/init.h>
11 #include <linux/mman.h>
13 #include <linux/threads.h>
14 #include <asm/addrspace.h>
16 #include <asm/pgtable.h>
17 #include <asm/processor.h>
18 #include <asm/cache.h>
20 #include <asm/uaccess.h>
21 #include <asm/pgalloc.h>
22 #include <asm/mmu_context.h>
23 #include <asm/cacheflush.h>
25 extern struct semaphore p3map_sem
[];
30 * @address: U0 address to be mapped
31 * @page: page (virt_to_page(to))
33 void clear_user_page(void *to
, unsigned long address
, struct page
*page
)
35 __set_bit(PG_mapped
, &page
->flags
);
36 if (((address
^ (unsigned long)to
) & CACHE_ALIAS
) == 0)
39 pgprot_t pgprot
= __pgprot(_PAGE_PRESENT
|
40 _PAGE_RW
| _PAGE_CACHABLE
|
41 _PAGE_DIRTY
| _PAGE_ACCESSED
|
42 _PAGE_HW_SHARED
| _PAGE_FLAGS_HARD
);
43 unsigned long phys_addr
= PHYSADDR(to
);
44 unsigned long p3_addr
= P3SEG
+ (address
& CACHE_ALIAS
);
45 pgd_t
*dir
= pgd_offset_k(p3_addr
);
46 pmd_t
*pmd
= pmd_offset(dir
, p3_addr
);
47 pte_t
*pte
= pte_offset_kernel(pmd
, p3_addr
);
51 entry
= pfn_pte(phys_addr
>> PAGE_SHIFT
, pgprot
);
52 down(&p3map_sem
[(address
& CACHE_ALIAS
)>>12]);
54 local_irq_save(flags
);
55 __flush_tlb_page(get_asid(), p3_addr
);
56 local_irq_restore(flags
);
57 update_mmu_cache(NULL
, p3_addr
, entry
);
58 __clear_user_page((void *)p3_addr
, to
);
59 pte_clear(&init_mm
, p3_addr
, pte
);
60 up(&p3map_sem
[(address
& CACHE_ALIAS
)>>12]);
68 * @address: U0 address to be mapped
69 * @page: page (virt_to_page(to))
71 void copy_user_page(void *to
, void *from
, unsigned long address
,
74 __set_bit(PG_mapped
, &page
->flags
);
75 if (((address
^ (unsigned long)to
) & CACHE_ALIAS
) == 0)
78 pgprot_t pgprot
= __pgprot(_PAGE_PRESENT
|
79 _PAGE_RW
| _PAGE_CACHABLE
|
80 _PAGE_DIRTY
| _PAGE_ACCESSED
|
81 _PAGE_HW_SHARED
| _PAGE_FLAGS_HARD
);
82 unsigned long phys_addr
= PHYSADDR(to
);
83 unsigned long p3_addr
= P3SEG
+ (address
& CACHE_ALIAS
);
84 pgd_t
*dir
= pgd_offset_k(p3_addr
);
85 pmd_t
*pmd
= pmd_offset(dir
, p3_addr
);
86 pte_t
*pte
= pte_offset_kernel(pmd
, p3_addr
);
90 entry
= pfn_pte(phys_addr
>> PAGE_SHIFT
, pgprot
);
91 down(&p3map_sem
[(address
& CACHE_ALIAS
)>>12]);
93 local_irq_save(flags
);
94 __flush_tlb_page(get_asid(), p3_addr
);
95 local_irq_restore(flags
);
96 update_mmu_cache(NULL
, p3_addr
, entry
);
97 __copy_user_page((void *)p3_addr
, from
, to
);
98 pte_clear(&init_mm
, p3_addr
, pte
);
99 up(&p3map_sem
[(address
& CACHE_ALIAS
)>>12]);
104 * For SH-4, we have our own implementation for ptep_get_and_clear
106 inline pte_t
ptep_get_and_clear(struct mm_struct
*mm
, unsigned long addr
, pte_t
*ptep
)
110 pte_clear(mm
, addr
, ptep
);
111 if (!pte_not_present(pte
)) {
112 unsigned long pfn
= pte_pfn(pte
);
113 if (pfn_valid(pfn
)) {
114 struct page
*page
= pfn_to_page(pfn
);
115 struct address_space
*mapping
= page_mapping(page
);
116 if (!mapping
|| !mapping_writably_mapped(mapping
))
117 __clear_bit(PG_mapped
, &page
->flags
);