2 * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
3 * Copyright (C) 2004 Microtronix Datacom Ltd.
5 * MMU support based on asm/page.h from mips which is:
7 * Copyright (C) 1994 - 1999, 2000, 03 Ralf Baechle
8 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
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_NIOS2_PAGE_H
16 #define _ASM_NIOS2_PAGE_H
18 #include <linux/pfn.h>
19 #include <linux/const.h>
22 * PAGE_SHIFT determines the page size
25 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
26 #define PAGE_MASK (~(PAGE_SIZE - 1))
29 * PAGE_OFFSET -- the first address of the first page of memory.
32 (CONFIG_NIOS2_MEM_BASE + CONFIG_NIOS2_KERNEL_REGION_BASE)
37 * This gives the physical RAM offset.
39 #define PHYS_OFFSET CONFIG_NIOS2_MEM_BASE
42 * It's normally defined only for FLATMEM config but it's
43 * used in our early mem init code for all memory models.
44 * So always define it.
46 #define ARCH_PFN_OFFSET PFN_UP(PHYS_OFFSET)
48 #define clear_page(page) memset((page), 0, PAGE_SIZE)
49 #define copy_page(to, from) memcpy((to), (from), PAGE_SIZE)
53 extern void clear_user_page(void *addr
, unsigned long vaddr
, struct page
*page
);
54 extern void copy_user_page(void *vto
, void *vfrom
, unsigned long vaddr
,
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 pgd
; } pgd_t
;
63 typedef struct { unsigned long pgprot
; } pgprot_t
;
65 #define pte_val(x) ((x).pte)
66 #define pgd_val(x) ((x).pgd)
67 #define pgprot_val(x) ((x).pgprot)
69 #define __pte(x) ((pte_t) { (x) })
70 #define __pgd(x) ((pgd_t) { (x) })
71 #define __pgprot(x) ((pgprot_t) { (x) })
73 extern unsigned long memory_start
;
74 extern unsigned long memory_end
;
75 extern unsigned long memory_size
;
77 extern struct page
*mem_map
;
79 #endif /* !__ASSEMBLY__ */
82 ((unsigned long)(x) - PAGE_OFFSET + PHYS_OFFSET)
84 ((void *)((unsigned long)(x) + PAGE_OFFSET - PHYS_OFFSET))
86 #define page_to_virt(page) \
87 ((((page) - mem_map) << PAGE_SHIFT) + PAGE_OFFSET)
89 # define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
90 # define pfn_valid(pfn) ((pfn) >= ARCH_PFN_OFFSET && \
93 # define virt_to_page(vaddr) pfn_to_page(PFN_DOWN(virt_to_phys(vaddr)))
94 # define virt_addr_valid(vaddr) pfn_valid(PFN_DOWN(virt_to_phys(vaddr)))
96 # define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | \
97 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
99 # define UNCAC_ADDR(addr) \
100 ((void *)((unsigned)(addr) | CONFIG_NIOS2_IO_REGION_BASE))
101 # define CAC_ADDR(addr) \
102 ((void *)(((unsigned)(addr) & ~CONFIG_NIOS2_IO_REGION_BASE) | \
103 CONFIG_NIOS2_KERNEL_REGION_BASE))
105 #include <asm-generic/memory_model.h>
107 #include <asm-generic/getorder.h>
109 #endif /* _ASM_NIOS2_PAGE_H */