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