xref: /openbmc/linux/arch/microblaze/include/asm/page.h (revision f125e2d4)
1 /*
2  * VM ops
3  *
4  * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu>
5  * Copyright (C) 2008-2009 PetaLogix
6  * Copyright (C) 2006 Atmark Techno, Inc.
7  * Changes for MMU support:
8  *    Copyright (C) 2007 Xilinx, Inc.  All rights reserved.
9  *
10  * This file is subject to the terms and conditions of the GNU General Public
11  * License. See the file "COPYING" in the main directory of this archive
12  * for more details.
13  */
14 
15 #ifndef _ASM_MICROBLAZE_PAGE_H
16 #define _ASM_MICROBLAZE_PAGE_H
17 
18 #include <linux/pfn.h>
19 #include <asm/setup.h>
20 #include <asm/asm-compat.h>
21 #include <linux/const.h>
22 
23 #ifdef __KERNEL__
24 
25 /* PAGE_SHIFT determines the page size */
26 #if defined(CONFIG_MICROBLAZE_64K_PAGES)
27 #define PAGE_SHIFT		16
28 #elif defined(CONFIG_MICROBLAZE_16K_PAGES)
29 #define PAGE_SHIFT		14
30 #else
31 #define PAGE_SHIFT		12
32 #endif
33 #define PAGE_SIZE	(ASM_CONST(1) << PAGE_SHIFT)
34 #define PAGE_MASK	(~(PAGE_SIZE-1))
35 
36 #define LOAD_OFFSET	ASM_CONST((CONFIG_KERNEL_START-CONFIG_KERNEL_BASE_ADDR))
37 
38 #define PTE_SHIFT	(PAGE_SHIFT - 2)	/* 1024 ptes per page */
39 
40 #ifndef __ASSEMBLY__
41 
42 /* MS be sure that SLAB allocates aligned objects */
43 #define ARCH_DMA_MINALIGN	L1_CACHE_BYTES
44 
45 #define ARCH_SLAB_MINALIGN	L1_CACHE_BYTES
46 
47 #define PAGE_UP(addr)	(((addr)+((PAGE_SIZE)-1))&(~((PAGE_SIZE)-1)))
48 #define PAGE_DOWN(addr)	((addr)&(~((PAGE_SIZE)-1)))
49 
50 #ifndef CONFIG_MMU
51 /*
52  * PAGE_OFFSET -- the first address of the first page of memory. When not
53  * using MMU this corresponds to the first free page in physical memory (aligned
54  * on a page boundary).
55  */
56 extern unsigned int __page_offset;
57 #define PAGE_OFFSET __page_offset
58 
59 #else /* CONFIG_MMU */
60 
61 /*
62  * PAGE_OFFSET -- the first address of the first page of memory. With MMU
63  * it is set to the kernel start address (aligned on a page boundary).
64  *
65  * CONFIG_KERNEL_START is defined in arch/microblaze/config.in and used
66  * in arch/microblaze/Makefile.
67  */
68 #define PAGE_OFFSET	CONFIG_KERNEL_START
69 
70 /*
71  * The basic type of a PTE - 32 bit physical addressing.
72  */
73 typedef unsigned long pte_basic_t;
74 #define PTE_FMT		"%.8lx"
75 
76 #endif /* CONFIG_MMU */
77 
78 # define copy_page(to, from)			memcpy((to), (from), PAGE_SIZE)
79 # define clear_page(pgaddr)			memset((pgaddr), 0, PAGE_SIZE)
80 
81 # define clear_user_page(pgaddr, vaddr, page)	memset((pgaddr), 0, PAGE_SIZE)
82 # define copy_user_page(vto, vfrom, vaddr, topg) \
83 			memcpy((vto), (vfrom), PAGE_SIZE)
84 
85 /*
86  * These are used to make use of C type-checking..
87  */
88 typedef struct page *pgtable_t;
89 typedef struct { unsigned long	pte; }		pte_t;
90 typedef struct { unsigned long	pgprot; }	pgprot_t;
91 /* FIXME this can depend on linux kernel version */
92 #   ifdef CONFIG_MMU
93 typedef struct { unsigned long pgd; } pgd_t;
94 #   else /* CONFIG_MMU */
95 typedef struct { unsigned long	ste[64]; }	pmd_t;
96 typedef struct { pmd_t		pue[1]; }	pud_t;
97 typedef struct { pud_t		p4e[1]; }	p4d_t;
98 typedef struct { p4d_t		pge[1]; }	pgd_t;
99 #   endif /* CONFIG_MMU */
100 
101 # define pte_val(x)	((x).pte)
102 # define pgprot_val(x)	((x).pgprot)
103 
104 #   ifdef CONFIG_MMU
105 #   define pgd_val(x)      ((x).pgd)
106 #   else  /* CONFIG_MMU */
107 #   define pmd_val(x)	((x).ste[0])
108 #   define pud_val(x)	((x).pue[0])
109 #   define pgd_val(x)	((x).pge[0])
110 #   endif  /* CONFIG_MMU */
111 
112 # define __pte(x)	((pte_t) { (x) })
113 # define __pgd(x)	((pgd_t) { (x) })
114 # define __pgprot(x)	((pgprot_t) { (x) })
115 
116 /**
117  * Conversions for virtual address, physical address, pfn, and struct
118  * page are defined in the following files.
119  *
120  * virt -+
121  *	 | asm-microblaze/page.h
122  * phys -+
123  *	 | linux/pfn.h
124  *  pfn -+
125  *	 | asm-generic/memory_model.h
126  * page -+
127  *
128  */
129 
130 extern unsigned long max_low_pfn;
131 extern unsigned long min_low_pfn;
132 extern unsigned long max_pfn;
133 
134 extern unsigned long memory_start;
135 extern unsigned long memory_size;
136 extern unsigned long lowmem_size;
137 
138 extern unsigned long kernel_tlb;
139 
140 extern int page_is_ram(unsigned long pfn);
141 
142 # define phys_to_pfn(phys)	(PFN_DOWN(phys))
143 # define pfn_to_phys(pfn)	(PFN_PHYS(pfn))
144 
145 # define virt_to_pfn(vaddr)	(phys_to_pfn((__pa(vaddr))))
146 # define pfn_to_virt(pfn)	__va(pfn_to_phys((pfn)))
147 
148 #  ifdef CONFIG_MMU
149 
150 #  define virt_to_page(kaddr)	(pfn_to_page(__pa(kaddr) >> PAGE_SHIFT))
151 #  define page_to_virt(page)   __va(page_to_pfn(page) << PAGE_SHIFT)
152 #  define page_to_phys(page)     (page_to_pfn(page) << PAGE_SHIFT)
153 
154 #  else /* CONFIG_MMU */
155 #  define virt_to_page(vaddr)	(pfn_to_page(virt_to_pfn(vaddr)))
156 #  define page_to_virt(page)	(pfn_to_virt(page_to_pfn(page)))
157 #  define page_to_phys(page)	(pfn_to_phys(page_to_pfn(page)))
158 #  define page_to_bus(page)	(page_to_phys(page))
159 #  define phys_to_page(paddr)	(pfn_to_page(phys_to_pfn(paddr)))
160 #  endif /* CONFIG_MMU */
161 
162 #  ifndef CONFIG_MMU
163 #  define pfn_valid(pfn)	(((pfn) >= min_low_pfn) && \
164 				((pfn) <= (min_low_pfn + max_mapnr)))
165 #  define ARCH_PFN_OFFSET	(PAGE_OFFSET >> PAGE_SHIFT)
166 #  else /* CONFIG_MMU */
167 #  define ARCH_PFN_OFFSET	(memory_start >> PAGE_SHIFT)
168 #  define pfn_valid(pfn)	((pfn) < (max_mapnr + ARCH_PFN_OFFSET))
169 #  endif /* CONFIG_MMU */
170 
171 # endif /* __ASSEMBLY__ */
172 
173 #define	virt_addr_valid(vaddr)	(pfn_valid(virt_to_pfn(vaddr)))
174 
175 # define __pa(x)	__virt_to_phys((unsigned long)(x))
176 # define __va(x)	((void *)__phys_to_virt((unsigned long)(x)))
177 
178 /* Convert between virtual and physical address for MMU. */
179 /* Handle MicroBlaze processor with virtual memory. */
180 #ifndef CONFIG_MMU
181 #define __virt_to_phys(addr)	addr
182 #define __phys_to_virt(addr)	addr
183 #define tophys(rd, rs)	addik rd, rs, 0
184 #define tovirt(rd, rs)	addik rd, rs, 0
185 #else
186 #define __virt_to_phys(addr) \
187 	((addr) + CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START)
188 #define __phys_to_virt(addr) \
189 	((addr) + CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR)
190 #define tophys(rd, rs) \
191 	addik rd, rs, (CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START)
192 #define tovirt(rd, rs) \
193 	addik rd, rs, (CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR)
194 #endif /* CONFIG_MMU */
195 
196 #define TOPHYS(addr)  __virt_to_phys(addr)
197 
198 #ifdef CONFIG_MMU
199 
200 #define VM_DATA_DEFAULT_FLAGS	(VM_READ | VM_WRITE | VM_EXEC | \
201 				 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
202 #endif /* CONFIG_MMU */
203 
204 #endif /* __KERNEL__ */
205 
206 #include <asm-generic/memory_model.h>
207 #include <asm-generic/getorder.h>
208 
209 #endif /* _ASM_MICROBLAZE_PAGE_H */
210