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 */
26typedef struct { unsigned long pte; } pte_t;
27typedef struct { unsigned long pmd; } pmd_t;
28typedef struct { unsigned long pgd; } pgd_t;
29typedef 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 */
45typedef unsigned long pte_t;
46typedef unsigned long pmd_t;
47typedef unsigned long pgd_t;
48typedef 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#endif /* __ASSEMBLY__ */
84
85/* macros to convert between really physical and virtual addresses
86 * by stripping a selected bit, we can convert between KSEG_x and 0x40000000 where
87 * the DRAM really resides
88 */
89
90#ifdef CONFIG_CRIS_LOW_MAP
91/* we have DRAM virtually at 0x6 */
92#define __pa(x)                 ((unsigned long)(x) & 0xdfffffff)
93#define __va(x)                 ((void *)((unsigned long)(x) | 0x20000000))
94#else
95/* we have DRAM virtually at 0xc */
96#define __pa(x)                 ((unsigned long)(x) & 0x7fffffff)
97#define __va(x)                 ((void *)((unsigned long)(x) | 0x80000000))
98#endif
99
100/* to index into the page map. our pages all start at physical addr PAGE_OFFSET so
101 * we can let the map start there. notice that we subtract PAGE_OFFSET because
102 * we start our mem_map there - in other ports they map mem_map physically and
103 * use __pa instead. in our system both the physical and virtual address of DRAM
104 * is too high to let mem_map start at 0, so we do it this way instead (similar
105 * to arm and m68k I think)
106 */
107
108#define virt_to_page(kaddr)    (mem_map + (((unsigned long)kaddr - PAGE_OFFSET) >> PAGE_SHIFT))
109#define VALID_PAGE(page)       ((page - mem_map) < max_mapnr)
110
111/* from linker script */
112
113extern unsigned long dram_start, dram_end;
114
115#define VM_DATA_DEFAULT_FLAGS	(VM_READ | VM_WRITE | VM_EXEC | \
116				 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
117
118#endif /* __KERNEL__ */
119
120#endif /* _CRIS_PAGE_H */
121
122