2 * arch/sh/mm/pg-sh7705.c
4 * Copyright (C) 1999, 2000 Niibe Yutaka
5 * Copyright (C) 2004 Alex Song
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
13 #include <linux/init.h>
14 #include <linux/mman.h>
16 #include <linux/threads.h>
18 #include <asm/addrspace.h>
20 #include <asm/pgtable.h>
21 #include <asm/processor.h>
22 #include <asm/cache.h>
24 #include <asm/uaccess.h>
25 #include <asm/pgalloc.h>
26 #include <asm/mmu_context.h>
27 #include <asm/cacheflush.h>
29 static inline void __flush_purge_virtual_region(void *p1
, void *virt
, int size
)
32 unsigned long begin
, end
;
33 unsigned long p1_begin
;
36 begin
= L1_CACHE_ALIGN((unsigned long)virt
);
37 end
= L1_CACHE_ALIGN((unsigned long)virt
+ size
);
39 p1_begin
= (unsigned long)p1
& ~(L1_CACHE_BYTES
- 1);
41 /* do this the slow way as we may not have TLB entries
43 for (v
= begin
; v
< end
; v
+= L1_CACHE_BYTES
) {
45 unsigned long ways
, addr
;
49 ways
= current_cpu_data
.dcache
.ways
;
50 addr
= CACHE_OC_ADDRESS_ARRAY
;
55 addr
|= (v
& current_cpu_data
.dcache
.entry_mask
);
57 data
= ctrl_inl(addr
);
58 if ((data
& CACHE_PHYSADDR_MASK
) ==
59 (p
& CACHE_PHYSADDR_MASK
)) {
60 data
&= ~(SH_CACHE_UPDATED
|SH_CACHE_VALID
);
61 ctrl_outl(data
, addr
);
64 addr
+= current_cpu_data
.dcache
.way_incr
;
67 p1_begin
+= L1_CACHE_BYTES
;
74 * @address: U0 address to be mapped
76 void clear_user_page(void *to
, unsigned long address
, struct page
*pg
)
78 struct page
*page
= virt_to_page(to
);
80 __set_bit(PG_mapped
, &page
->flags
);
81 if (((address
^ (unsigned long)to
) & CACHE_ALIAS
) == 0) {
83 __flush_wback_region(to
, PAGE_SIZE
);
85 __flush_purge_virtual_region(to
,
86 (void *)(address
& 0xfffff000),
89 __flush_wback_region(to
, PAGE_SIZE
);
97 * @address: U0 address to be mapped
99 void copy_user_page(void *to
, void *from
, unsigned long address
, struct page
*pg
)
101 struct page
*page
= virt_to_page(to
);
104 __set_bit(PG_mapped
, &page
->flags
);
105 if (((address
^ (unsigned long)to
) & CACHE_ALIAS
) == 0) {
107 __flush_wback_region(to
, PAGE_SIZE
);
109 __flush_purge_virtual_region(to
,
110 (void *)(address
& 0xfffff000),
113 __flush_wback_region(to
, PAGE_SIZE
);
118 * For SH7705, we have our own implementation for ptep_get_and_clear
119 * Copied from pg-sh4.c
121 inline pte_t
ptep_get_and_clear(struct mm_struct
*mm
, unsigned long addr
, pte_t
*ptep
)
125 pte_clear(mm
, addr
, ptep
);
126 if (!pte_not_present(pte
)) {
127 unsigned long pfn
= pte_pfn(pte
);
128 if (pfn_valid(pfn
)) {
129 struct page
*page
= pfn_to_page(pfn
);
130 struct address_space
*mapping
= page_mapping(page
);
131 if (!mapping
|| !mapping_writably_mapped(mapping
))
132 __clear_bit(PG_mapped
, &page
->flags
);