xref: /linux/arch/m68k/include/asm/page_mm.h (revision 0883c2c06fb5bcf5b9e008270827e63c09a88c1e)
1 #ifndef _M68K_PAGE_MM_H
2 #define _M68K_PAGE_MM_H
3 
4 #ifndef __ASSEMBLY__
5 
6 #include <linux/compiler.h>
7 #include <asm/module.h>
8 
9 /*
10  * We don't need to check for alignment etc.
11  */
12 #ifdef CPU_M68040_OR_M68060_ONLY
13 static inline void copy_page(void *to, void *from)
14 {
15   unsigned long tmp;
16 
17   __asm__ __volatile__("1:\t"
18 		       ".chip 68040\n\t"
19 		       "move16 %1@+,%0@+\n\t"
20 		       "move16 %1@+,%0@+\n\t"
21 		       ".chip 68k\n\t"
22 		       "dbra  %2,1b\n\t"
23 		       : "=a" (to), "=a" (from), "=d" (tmp)
24 		       : "0" (to), "1" (from) , "2" (PAGE_SIZE / 32 - 1)
25 		       );
26 }
27 
28 static inline void clear_page(void *page)
29 {
30 	unsigned long tmp;
31 	unsigned long *sp = page;
32 
33 	*sp++ = 0;
34 	*sp++ = 0;
35 	*sp++ = 0;
36 	*sp++ = 0;
37 
38 	__asm__ __volatile__("1:\t"
39 			     ".chip 68040\n\t"
40 			     "move16 %2@+,%0@+\n\t"
41 			     ".chip 68k\n\t"
42 			     "subqw  #8,%2\n\t"
43 			     "subqw  #8,%2\n\t"
44 			     "dbra   %1,1b\n\t"
45 			     : "=a" (sp), "=d" (tmp)
46 			     : "a" (page), "0" (sp),
47 			       "1" ((PAGE_SIZE - 16) / 16 - 1));
48 }
49 
50 #else
51 #define clear_page(page)	memset((page), 0, PAGE_SIZE)
52 #define copy_page(to,from)	memcpy((to), (from), PAGE_SIZE)
53 #endif
54 
55 #define clear_user_page(addr, vaddr, page)	\
56 	do {	clear_page(addr);		\
57 		flush_dcache_page(page);	\
58 	} while (0)
59 #define copy_user_page(to, from, vaddr, page)	\
60 	do {	copy_page(to, from);		\
61 		flush_dcache_page(page);	\
62 	} while (0)
63 
64 extern unsigned long m68k_memoffset;
65 
66 #ifndef CONFIG_SUN3
67 
68 #define WANT_PAGE_VIRTUAL
69 
70 static inline unsigned long ___pa(void *vaddr)
71 {
72 	unsigned long paddr;
73 	asm (
74 		"1:	addl #0,%0\n"
75 		m68k_fixup(%c2, 1b+2)
76 		: "=r" (paddr)
77 		: "0" (vaddr), "i" (m68k_fixup_memoffset));
78 	return paddr;
79 }
80 #define __pa(vaddr)	___pa((void *)(long)(vaddr))
81 static inline void *__va(unsigned long paddr)
82 {
83 	void *vaddr;
84 	asm (
85 		"1:	subl #0,%0\n"
86 		m68k_fixup(%c2, 1b+2)
87 		: "=r" (vaddr)
88 		: "0" (paddr), "i" (m68k_fixup_memoffset));
89 	return vaddr;
90 }
91 
92 #else	/* !CONFIG_SUN3 */
93 /* This #define is a horrible hack to suppress lots of warnings. --m */
94 #define __pa(x) ___pa((unsigned long)(x))
95 static inline unsigned long ___pa(unsigned long x)
96 {
97      if(x == 0)
98 	  return 0;
99      if(x >= PAGE_OFFSET)
100         return (x-PAGE_OFFSET);
101      else
102         return (x+0x2000000);
103 }
104 
105 static inline void *__va(unsigned long x)
106 {
107      if(x == 0)
108 	  return (void *)0;
109 
110      if(x < 0x2000000)
111         return (void *)(x+PAGE_OFFSET);
112      else
113         return (void *)(x-0x2000000);
114 }
115 #endif	/* CONFIG_SUN3 */
116 
117 /*
118  * NOTE: virtual isn't really correct, actually it should be the offset into the
119  * memory node, but we have no highmem, so that works for now.
120  * TODO: implement (fast) pfn<->pgdat_idx conversion functions, this makes lots
121  * of the shifts unnecessary.
122  */
123 #define virt_to_pfn(kaddr)	(__pa(kaddr) >> PAGE_SHIFT)
124 #define pfn_to_virt(pfn)	__va((pfn) << PAGE_SHIFT)
125 
126 extern int m68k_virt_to_node_shift;
127 
128 #ifdef CONFIG_SINGLE_MEMORY_CHUNK
129 #define __virt_to_node(addr)	(&pg_data_map[0])
130 #else
131 extern struct pglist_data *pg_data_table[];
132 
133 static inline __attribute_const__ int __virt_to_node_shift(void)
134 {
135 	int shift;
136 
137 	asm (
138 		"1:	moveq	#0,%0\n"
139 		m68k_fixup(%c1, 1b)
140 		: "=d" (shift)
141 		: "i" (m68k_fixup_vnode_shift));
142 	return shift;
143 }
144 
145 #define __virt_to_node(addr)	(pg_data_table[(unsigned long)(addr) >> __virt_to_node_shift()])
146 #endif
147 
148 #define virt_to_page(addr) ({						\
149 	pfn_to_page(virt_to_pfn(addr));					\
150 })
151 #define page_to_virt(page) ({						\
152 	pfn_to_virt(page_to_pfn(page));					\
153 })
154 
155 #define pfn_to_page(pfn) ({						\
156 	unsigned long __pfn = (pfn);					\
157 	struct pglist_data *pgdat;					\
158 	pgdat = __virt_to_node((unsigned long)pfn_to_virt(__pfn));	\
159 	pgdat->node_mem_map + (__pfn - pgdat->node_start_pfn);		\
160 })
161 #define page_to_pfn(_page) ({						\
162 	const struct page *__p = (_page);				\
163 	struct pglist_data *pgdat;					\
164 	pgdat = &pg_data_map[page_to_nid(__p)];				\
165 	((__p) - pgdat->node_mem_map) + pgdat->node_start_pfn;		\
166 })
167 
168 #define virt_addr_valid(kaddr)	((void *)(kaddr) >= (void *)PAGE_OFFSET && (void *)(kaddr) < high_memory)
169 #define pfn_valid(pfn)		virt_addr_valid(pfn_to_virt(pfn))
170 
171 #endif /* __ASSEMBLY__ */
172 
173 #endif /* _M68K_PAGE_MM_H */
174