1 #ifndef _CRIS_PAGE_H
2 #define _CRIS_PAGE_H
3 
4 #include <linux/config.h>
5 #include <asm/mmu.h>
6 
7 /* PAGE_SHIFT determines the page size */
8 #define PAGE_SHIFT	13
9 #define PAGE_SIZE	(1UL << PAGE_SHIFT)
10 #define PAGE_MASK	(~(PAGE_SIZE-1))
11 
12 #ifdef __KERNEL__
13 
14 #define clear_page(page)        memset((void *)(page), 0, PAGE_SIZE)
15 #define copy_page(to,from)      memcpy((void *)(to), (void *)(from), PAGE_SIZE)
16 
17 #define clear_user_page(page, vaddr)    clear_page(page)
18 #define copy_user_page(to, from, vaddr) copy_page(to, from)
19 
20 #define STRICT_MM_TYPECHECKS
21 
22 #ifdef STRICT_MM_TYPECHECKS
23 /*
24  * These are used to make use of C type-checking..
25  */
26 typedef struct { unsigned long pte; } pte_t;
27 typedef struct { unsigned long pmd; } pmd_t;
28 typedef struct { unsigned long pgd; } pgd_t;
29 typedef struct { unsigned long pgprot; } pgprot_t;
30 
31 #define pte_val(x)	((x).pte)
32 #define pmd_val(x)	((x).pmd)
33 #define pgd_val(x)	((x).pgd)
34 #define pgprot_val(x)	((x).pgprot)
35 
36 #define __pte(x)	((pte_t) { (x) } )
37 #define __pmd(x)	((pmd_t) { (x) } )
38 #define __pgd(x)	((pgd_t) { (x) } )
39 #define __pgprot(x)	((pgprot_t) { (x) } )
40 
41 #else
42 /*
43  * .. while these make it easier on the compiler
44  */
45 typedef unsigned long pte_t;
46 typedef unsigned long pmd_t;
47 typedef unsigned long pgd_t;
48 typedef unsigned long pgprot_t;
49 
50 #define pte_val(x)	(x)
51 #define pmd_val(x)	(x)
52 #define pgd_val(x)	(x)
53 #define pgprot_val(x)	(x)
54 
55 #define __pte(x)	(x)
56 #define __pmd(x)	(x)
57 #define __pgd(x)	(x)
58 #define __pgprot(x)	(x)
59 
60 #endif
61 
62 /* to align the pointer to the (next) page boundary */
63 #define PAGE_ALIGN(addr)	(((addr)+PAGE_SIZE-1)&PAGE_MASK)
64 
65 /* This handles the memory map.. */
66 
67 #ifdef CONFIG_CRIS_LOW_MAP
68 #define PAGE_OFFSET		KSEG_6   /* kseg_6 is mapped to physical ram */
69 #else
70 #define PAGE_OFFSET		KSEG_C   /* kseg_c is mapped to physical ram */
71 #endif
72 
73 #ifndef __ASSEMBLY__
74 
75 #define BUG() do { \
76   printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \
77 } while (0)
78 
79 #define PAGE_BUG(page) do { \
80          BUG(); \
81 } while (0)
82 
83 /* Pure 2^n version of get_order */
get_order(unsigned long size)84 static __inline__ int get_order(unsigned long size)
85 {
86 	int order;
87 
88 	size = (size-1) >> (PAGE_SHIFT-1);
89 	order = -1;
90 	do {
91 		size >>= 1;
92 		order++;
93 	} while (size);
94 	return order;
95 }
96 
97 #endif /* __ASSEMBLY__ */
98 
99 /* macros to convert between really physical and virtual addresses
100  * by stripping a selected bit, we can convert between KSEG_x and 0x40000000 where
101  * the DRAM really resides
102  */
103 
104 #ifdef CONFIG_CRIS_LOW_MAP
105 /* we have DRAM virtually at 0x6 */
106 #define __pa(x)                 ((unsigned long)(x) & 0xdfffffff)
107 #define __va(x)                 ((void *)((unsigned long)(x) | 0x20000000))
108 #else
109 /* we have DRAM virtually at 0xc */
110 #define __pa(x)                 ((unsigned long)(x) & 0x7fffffff)
111 #define __va(x)                 ((void *)((unsigned long)(x) | 0x80000000))
112 #endif
113 
114 /* to index into the page map. our pages all start at physical addr PAGE_OFFSET so
115  * we can let the map start there. notice that we subtract PAGE_OFFSET because
116  * we start our mem_map there - in other ports they map mem_map physically and
117  * use __pa instead. in our system both the physical and virtual address of DRAM
118  * is too high to let mem_map start at 0, so we do it this way instead (similar
119  * to arm and m68k I think)
120  */
121 
122 #define virt_to_page(kaddr)    (mem_map + (((unsigned long)kaddr - PAGE_OFFSET) >> PAGE_SHIFT))
123 #define VALID_PAGE(page)       ((page - mem_map) < max_mapnr)
124 
125 /* from linker script */
126 
127 extern unsigned long dram_start, dram_end;
128 
129 #define VM_DATA_DEFAULT_FLAGS	(VM_READ | VM_WRITE | VM_EXEC | \
130 				 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
131 
132 #endif /* __KERNEL__ */
133 
134 #endif /* _CRIS_PAGE_H */
135 
136