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.
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
15 #ifndef _ASM_MICROBLAZE_PAGE_H
16 #define _ASM_MICROBLAZE_PAGE_H
18 #include <linux/pfn.h>
19 #include <asm/setup.h>
20 #include <linux/const.h>
24 /* PAGE_SHIFT determines the page size */
25 #define PAGE_SHIFT (12)
26 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
27 #define PAGE_MASK (~(PAGE_SIZE-1))
31 #define PAGE_UP(addr) (((addr)+((PAGE_SIZE)-1))&(~((PAGE_SIZE)-1)))
32 #define PAGE_DOWN(addr) ((addr)&(~((PAGE_SIZE)-1)))
34 /* align addr on a size boundary - adjust address up/down if needed */
35 #define _ALIGN_UP(addr, size) (((addr)+((size)-1))&(~((size)-1)))
36 #define _ALIGN_DOWN(addr, size) ((addr)&(~((size)-1)))
38 /* align addr on a size boundary - adjust address up if needed */
39 #define _ALIGN(addr, size) _ALIGN_UP(addr, size)
43 * PAGE_OFFSET -- the first address of the first page of memory. When not
44 * using MMU this corresponds to the first free page in physical memory (aligned
45 * on a page boundary).
47 extern unsigned int __page_offset
;
48 #define PAGE_OFFSET __page_offset
50 #else /* CONFIG_MMU */
53 * PAGE_OFFSET -- the first address of the first page of memory. With MMU
54 * it is set to the kernel start address (aligned on a page boundary).
56 * CONFIG_KERNEL_START is defined in arch/microblaze/config.in and used
57 * in arch/microblaze/Makefile.
59 #define PAGE_OFFSET CONFIG_KERNEL_START
62 * MAP_NR -- given an address, calculate the index of the page struct which
63 * points to the address's page.
65 #define MAP_NR(addr) (((unsigned long)(addr) - PAGE_OFFSET) >> PAGE_SHIFT)
68 * The basic type of a PTE - 32 bit physical addressing.
70 typedef unsigned long pte_basic_t
;
71 #define PTE_SHIFT (PAGE_SHIFT - 2) /* 1024 ptes per page */
72 #define PTE_FMT "%.8lx"
74 #endif /* CONFIG_MMU */
77 # define copy_page(to, from) memcpy((to), (from), PAGE_SIZE)
78 # define get_user_page(vaddr) __get_free_page(GFP_KERNEL)
79 # define free_user_page(page, addr) free_page(addr)
80 # else /* CONFIG_MMU */
81 extern void copy_page(void *to
, void *from
);
82 # endif /* CONFIG_MMU */
84 # define clear_page(pgaddr) memset((pgaddr), 0, PAGE_SIZE)
86 # define clear_user_page(pgaddr, vaddr, page) memset((pgaddr), 0, PAGE_SIZE)
87 # define copy_user_page(vto, vfrom, vaddr, topg) \
88 memcpy((vto), (vfrom), PAGE_SIZE)
91 * These are used to make use of C type-checking..
93 typedef struct page
*pgtable_t
;
94 typedef struct { unsigned long pte
; } pte_t
;
95 typedef struct { unsigned long pgprot
; } pgprot_t
;
96 /* FIXME this can depend on linux kernel version */
98 typedef struct { unsigned long pmd
; } pmd_t
;
99 typedef struct { unsigned long pgd
; } pgd_t
;
100 # else /* CONFIG_MMU */
101 typedef struct { unsigned long ste
[64]; } pmd_t
;
102 typedef struct { pmd_t pue
[1]; } pud_t
;
103 typedef struct { pud_t pge
[1]; } pgd_t
;
104 # endif /* CONFIG_MMU */
106 # define pte_val(x) ((x).pte)
107 # define pgprot_val(x) ((x).pgprot)
110 # define pmd_val(x) ((x).pmd)
111 # define pgd_val(x) ((x).pgd)
112 # else /* CONFIG_MMU */
113 # define pmd_val(x) ((x).ste[0])
114 # define pud_val(x) ((x).pue[0])
115 # define pgd_val(x) ((x).pge[0])
116 # endif /* CONFIG_MMU */
118 # define __pte(x) ((pte_t) { (x) })
119 # define __pmd(x) ((pmd_t) { (x) })
120 # define __pgd(x) ((pgd_t) { (x) })
121 # define __pgprot(x) ((pgprot_t) { (x) })
124 * Conversions for virtual address, physical address, pfn, and struct
125 * page are defined in the following files.
128 * | asm-microblaze/page.h
132 * | asm-generic/memory_model.h
137 extern unsigned long max_low_pfn
;
138 extern unsigned long min_low_pfn
;
139 extern unsigned long max_pfn
;
141 extern unsigned long memory_start
;
142 extern unsigned long memory_end
;
143 extern unsigned long memory_size
;
145 extern int page_is_ram(unsigned long pfn
);
147 # define phys_to_pfn(phys) (PFN_DOWN(phys))
148 # define pfn_to_phys(pfn) (PFN_PHYS(pfn))
150 # define virt_to_pfn(vaddr) (phys_to_pfn((__pa(vaddr))))
151 # define pfn_to_virt(pfn) __va(pfn_to_phys((pfn)))
154 # define virt_to_page(kaddr) (mem_map + MAP_NR(kaddr))
155 # else /* CONFIG_MMU */
156 # define virt_to_page(vaddr) (pfn_to_page(virt_to_pfn(vaddr)))
157 # define page_to_virt(page) (pfn_to_virt(page_to_pfn(page)))
158 # define page_to_phys(page) (pfn_to_phys(page_to_pfn(page)))
159 # define page_to_bus(page) (page_to_phys(page))
160 # define phys_to_page(paddr) (pfn_to_page(phys_to_pfn(paddr)))
161 # endif /* CONFIG_MMU */
164 # define pfn_valid(pfn) ((pfn) >= min_low_pfn && (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 # define VALID_PAGE(page) ((page - mem_map) < max_mapnr)
170 # endif /* CONFIG_MMU */
172 # endif /* __ASSEMBLY__ */
174 #define virt_addr_valid(vaddr) (pfn_valid(virt_to_pfn(vaddr)))
178 # define __pa(vaddr) ((unsigned long) (vaddr))
179 # define __va(paddr) ((void *) (paddr))
180 # else /* CONFIG_MMU */
181 # define __pa(x) __virt_to_phys((unsigned long)(x))
182 # define __va(x) ((void *)__phys_to_virt((unsigned long)(x)))
183 # endif /* CONFIG_MMU */
186 /* Convert between virtual and physical address for MMU. */
187 /* Handle MicroBlaze processor with virtual memory. */
189 #define __virt_to_phys(addr) addr
190 #define __phys_to_virt(addr) addr
191 #define tophys(rd, rs) addik rd, rs, 0
192 #define tovirt(rd, rs) addik rd, rs, 0
194 #define __virt_to_phys(addr) \
195 ((addr) + CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START)
196 #define __phys_to_virt(addr) \
197 ((addr) + CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR)
198 #define tophys(rd, rs) \
199 addik rd, rs, (CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START)
200 #define tovirt(rd, rs) \
201 addik rd, rs, (CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR)
202 #endif /* CONFIG_MMU */
204 #define TOPHYS(addr) __virt_to_phys(addr)
207 #ifdef CONFIG_CONTIGUOUS_PAGE_ALLOC
208 #define WANT_PAGE_VIRTUAL 1 /* page alloc 2 relies on this */
211 #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
212 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
213 #endif /* CONFIG_MMU */
215 #endif /* __KERNEL__ */
217 #include <asm-generic/memory_model.h>
218 #include <asm-generic/getorder.h>
220 #endif /* _ASM_MICROBLAZE_PAGE_H */