4 /* PAGE_SHIFT determines the page size */
6 #define PAGE_SIZE (1UL << PAGE_SHIFT)
9 * Subtle: this is an int (not an unsigned long) and so it
10 * gets extended to 64 bits the way want (i.e. with 1s). -- paulus
12 #define PAGE_MASK (~((1 << PAGE_SHIFT) - 1))
15 #include <linux/config.h>
17 /* This must match what is in arch/ppc/Makefile */
18 #define PAGE_OFFSET CONFIG_KERNEL_START
19 #define KERNELBASE PAGE_OFFSET
24 * The basic type of a PTE - 64 bits for those CPUs with > 32 bit
25 * physical addressing. For now this just the IBM PPC440.
27 #ifdef CONFIG_PTE_64BIT
28 typedef unsigned long long pte_basic_t;
29 #define PTE_SHIFT (PAGE_SHIFT - 3) /* 512 ptes per page */
30 #define PTE_FMT "%16Lx"
32 typedef unsigned long pte_basic_t;
33 #define PTE_SHIFT (PAGE_SHIFT - 2) /* 1024 ptes per page */
34 #define PTE_FMT "%.8lx"
37 /* align addr on a size boundary - adjust address up/down if needed */
38 #define _ALIGN_UP(addr,size) (((addr)+((size)-1))&(~((size)-1)))
39 #define _ALIGN_DOWN(addr,size) ((addr)&(~((size)-1)))
41 /* align addr on a size boundary - adjust address up if needed */
42 #define _ALIGN(addr,size) _ALIGN_UP(addr,size)
44 /* to align the pointer to the (next) page boundary */
45 #define PAGE_ALIGN(addr) _ALIGN(addr, PAGE_SIZE)
48 #undef STRICT_MM_TYPECHECKS
50 #ifdef STRICT_MM_TYPECHECKS
52 * These are used to make use of C type-checking..
54 typedef struct { pte_basic_t pte; } pte_t;
55 typedef struct { unsigned long pmd; } pmd_t;
56 typedef struct { unsigned long pgd; } pgd_t;
57 typedef struct { unsigned long pgprot; } pgprot_t;
59 #define pte_val(x) ((x).pte)
60 #define pmd_val(x) ((x).pmd)
61 #define pgd_val(x) ((x).pgd)
62 #define pgprot_val(x) ((x).pgprot)
64 #define __pte(x) ((pte_t) { (x) } )
65 #define __pmd(x) ((pmd_t) { (x) } )
66 #define __pgd(x) ((pgd_t) { (x) } )
67 #define __pgprot(x) ((pgprot_t) { (x) } )
71 * .. while these make it easier on the compiler
73 typedef pte_basic_t pte_t;
74 typedef unsigned long pmd_t;
75 typedef unsigned long pgd_t;
76 typedef unsigned long pgprot_t;
78 #define pte_val(x) (x)
79 #define pmd_val(x) (x)
80 #define pgd_val(x) (x)
81 #define pgprot_val(x) (x)
86 #define __pgprot(x) (x)
91 extern void clear_pages(void *page, int order);
92 static inline void clear_page(void *page) { clear_pages(page, 0); }
93 extern void copy_page(void *to, void *from);
94 extern void clear_user_page(void *page, unsigned long vaddr, struct page *pg);
95 extern void copy_user_page(void *to, void *from, unsigned long vaddr,
99 #define PPC_MEMSTART 0
100 #define PPC_PGSTART 0
101 #define PPC_MEMOFFSET PAGE_OFFSET
103 extern unsigned long ppc_memstart;
104 extern unsigned long ppc_pgstart;
105 extern unsigned long ppc_memoffset;
106 #define PPC_MEMSTART ppc_memstart
107 #define PPC_PGSTART ppc_pgstart
108 #define PPC_MEMOFFSET ppc_memoffset
111 #if defined(CONFIG_APUS) && !defined(MODULE)
112 /* map phys->virtual and virtual->phys for RAM pages */
113 static inline unsigned long ___pa(unsigned long v)
116 asm volatile ("1: addis %0, %1, %2;"
117 ".section \".vtop_fixup\",\"aw\";"
122 : "b" (v), "K" (((-PAGE_OFFSET) >> 16) & 0xffff));
126 static inline void* ___va(unsigned long p)
129 asm volatile ("1: addis %0, %1, %2;"
130 ".section \".ptov_fixup\",\"aw\";"
135 : "b" (p), "K" (((PAGE_OFFSET) >> 16) & 0xffff));
140 #define ___pa(vaddr) ((vaddr)-PPC_MEMOFFSET)
141 #define ___va(paddr) ((paddr)+PPC_MEMOFFSET)
144 extern int page_is_ram(unsigned long pfn);
146 #define __pa(x) ___pa((unsigned long)(x))
147 #define __va(x) ((void *)(___va((unsigned long)(x))))
149 #define pfn_to_page(pfn) (mem_map + ((pfn) - PPC_PGSTART))
150 #define page_to_pfn(page) ((unsigned long)((page) - mem_map) + PPC_PGSTART)
151 #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
152 #define page_to_virt(page) __va(page_to_pfn(page) << PAGE_SHIFT)
154 #define pfn_valid(pfn) (((pfn) - PPC_PGSTART) < max_mapnr)
155 #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
157 /* Pure 2^n version of get_order */
158 extern __inline__ int get_order(unsigned long size)
162 size = (size-1) >> PAGE_SHIFT;
163 asm ("cntlzw %0,%1" : "=r" (lz) : "r" (size));
167 #endif /* __ASSEMBLY__ */
169 #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
170 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
172 #endif /* __KERNEL__ */
173 #endif /* _PPC_PAGE_H */