[NETFILTER]: PPTP conntrack: simplify expectation handling
[hh.org.git] / arch / sh / mm / pg-sh4.c
blobc776b60fc25018ebfb0cf75e9976c603b65fdecd
1 /*
2 * arch/sh/mm/pg-sh4.c
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.
8 */
9 #include <linux/init.h>
10 #include <linux/mman.h>
11 #include <linux/mm.h>
12 #include <linux/threads.h>
13 #include <asm/addrspace.h>
14 #include <asm/page.h>
15 #include <asm/pgtable.h>
16 #include <asm/processor.h>
17 #include <asm/cache.h>
18 #include <asm/io.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[];
27 * clear_user_page
28 * @to: P1 address
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)
36 clear_page(to);
37 else {
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);
47 pte_t entry;
48 unsigned long flags;
50 entry = pfn_pte(phys_addr >> PAGE_SHIFT, pgprot);
51 down(&p3map_sem[(address & CACHE_ALIAS)>>12]);
52 set_pte(pte, entry);
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]);
64 * copy_user_page
65 * @to: P1 address
66 * @from: P1 address
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,
71 struct page *page)
73 __set_bit(PG_mapped, &page->flags);
74 if (((address ^ (unsigned long)to) & CACHE_ALIAS) == 0)
75 copy_page(to, from);
76 else {
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);
86 pte_t entry;
87 unsigned long flags;
89 entry = pfn_pte(phys_addr >> PAGE_SHIFT, pgprot);
90 down(&p3map_sem[(address & CACHE_ALIAS)>>12]);
91 set_pte(pte, entry);
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)
107 pte_t pte = *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);
119 return pte;