2 * Copyright (C) 2008 Michal Simek
3 * Copyright (C) 2008 PetaLogix
4 * Copyright (C) 2006 Atmark Techno, Inc.
5 * Changes for MMU support:
6 * Copyright (C) 2007 Xilinx, Inc. All rights reserved.
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
13 #ifndef _ASM_MICROBLAZE_PAGE_H
14 #define _ASM_MICROBLAZE_PAGE_H
16 #include <linux/pfn.h>
17 #include <asm/setup.h>
19 /* PAGE_SHIFT determines the page size */
20 #define PAGE_SHIFT (12)
21 #define PAGE_SIZE (1UL << PAGE_SHIFT)
22 #define PAGE_MASK (~(PAGE_SIZE-1))
28 #define PAGE_UP(addr) (((addr)+((PAGE_SIZE)-1))&(~((PAGE_SIZE)-1)))
29 #define PAGE_DOWN(addr) ((addr)&(~((PAGE_SIZE)-1)))
31 /* align addr on a size boundary - adjust address up/down if needed */
32 #define _ALIGN_UP(addr, size) (((addr)+((size)-1))&(~((size)-1)))
33 #define _ALIGN_DOWN(addr, size) ((addr)&(~((size)-1)))
35 /* align addr on a size boundary - adjust address up if needed */
36 #define _ALIGN(addr, size) _ALIGN_UP(addr, size)
39 * PAGE_OFFSET -- the first address of the first page of memory. When not
40 * using MMU this corresponds to the first free page in physical memory (aligned
41 * on a page boundary).
43 extern unsigned int __page_offset;
44 #define PAGE_OFFSET __page_offset
46 #define copy_page(to, from) memcpy((to), (from), PAGE_SIZE)
47 #define get_user_page(vaddr) __get_free_page(GFP_KERNEL)
48 #define free_user_page(page, addr) free_page(addr)
50 #define clear_page(pgaddr) memset((pgaddr), 0, PAGE_SIZE)
53 #define clear_user_page(pgaddr, vaddr, page) memset((pgaddr), 0, PAGE_SIZE)
54 #define copy_user_page(vto, vfrom, vaddr, topg) \
55 memcpy((vto), (vfrom), PAGE_SIZE)
58 * These are used to make use of C type-checking..
60 typedef struct page *pgtable_t;
61 typedef struct { unsigned long pte; } pte_t;
62 typedef struct { unsigned long pgprot; } pgprot_t;
63 typedef struct { unsigned long ste[64]; } pmd_t;
64 typedef struct { pmd_t pue[1]; } pud_t;
65 typedef struct { pud_t pge[1]; } pgd_t;
68 #define pte_val(x) ((x).pte)
69 #define pgprot_val(x) ((x).pgprot)
70 #define pmd_val(x) ((x).ste[0])
71 #define pud_val(x) ((x).pue[0])
72 #define pgd_val(x) ((x).pge[0])
74 #define __pte(x) ((pte_t) { (x) })
75 #define __pmd(x) ((pmd_t) { (x) })
76 #define __pgd(x) ((pgd_t) { (x) })
77 #define __pgprot(x) ((pgprot_t) { (x) })
80 * Conversions for virtual address, physical address, pfn, and struct
81 * page are defined in the following files.
84 * | asm-microblaze/page.h
88 * | asm-generic/memory_model.h
93 extern unsigned long max_low_pfn;
94 extern unsigned long min_low_pfn;
95 extern unsigned long max_pfn;
97 #define __pa(vaddr) ((unsigned long) (vaddr))
98 #define __va(paddr) ((void *) (paddr))
100 #define phys_to_pfn(phys) (PFN_DOWN(phys))
101 #define pfn_to_phys(pfn) (PFN_PHYS(pfn))
103 #define virt_to_pfn(vaddr) (phys_to_pfn((__pa(vaddr))))
104 #define pfn_to_virt(pfn) __va(pfn_to_phys((pfn)))
106 #define virt_to_page(vaddr) (pfn_to_page(virt_to_pfn(vaddr)))
107 #define page_to_virt(page) (pfn_to_virt(page_to_pfn(page)))
109 #define page_to_phys(page) (pfn_to_phys(page_to_pfn(page)))
110 #define page_to_bus(page) (page_to_phys(page))
111 #define phys_to_page(paddr) (pfn_to_page(phys_to_pfn(paddr)))
113 extern unsigned int memory_start;
114 extern unsigned int memory_end;
115 extern unsigned int memory_size;
117 #define pfn_valid(pfn) ((pfn) >= min_low_pfn && (pfn) < max_mapnr)
119 #define ARCH_PFN_OFFSET (PAGE_OFFSET >> PAGE_SHIFT)
122 #define tophys(rd, rs) (addik rd, rs, 0)
123 #define tovirt(rd, rs) (addik rd, rs, 0)
124 #endif /* __ASSEMBLY__ */
126 #define virt_addr_valid(vaddr) (pfn_valid(virt_to_pfn(vaddr)))
128 /* Convert between virtual and physical address for MMU. */
129 /* Handle MicroBlaze processor with virtual memory. */
130 #define __virt_to_phys(addr) addr
131 #define __phys_to_virt(addr) addr
133 #define TOPHYS(addr) __virt_to_phys(addr)
135 #endif /* __KERNEL__ */
137 #include <asm-generic/memory_model.h>
138 #include <asm-generic/page.h>
140 #endif /* _ASM_MICROBLAZE_PAGE_H */