Linux 2.6.16.22
[linux/fpc-iii.git] / include / asm-ppc / page.h
blob538e0c8ab2434758682d44d4e234e9f595b7ef6a
1 #ifndef _PPC_PAGE_H
2 #define _PPC_PAGE_H
4 #include <linux/config.h>
5 #include <asm/asm-compat.h>
7 /* PAGE_SHIFT determines the page size */
8 #define PAGE_SHIFT 12
9 #define PAGE_SIZE (ASM_CONST(1) << PAGE_SHIFT)
12 * Subtle: this is an int (not an unsigned long) and so it
13 * gets extended to 64 bits the way want (i.e. with 1s). -- paulus
15 #define PAGE_MASK (~((1 << PAGE_SHIFT) - 1))
17 #ifdef __KERNEL__
18 #include <linux/config.h>
20 /* This must match what is in arch/ppc/Makefile */
21 #define PAGE_OFFSET CONFIG_KERNEL_START
22 #define KERNELBASE PAGE_OFFSET
24 #ifndef __ASSEMBLY__
27 * The basic type of a PTE - 64 bits for those CPUs with > 32 bit
28 * physical addressing. For now this just the IBM PPC440.
30 #ifdef CONFIG_PTE_64BIT
31 typedef unsigned long long pte_basic_t;
32 #define PTE_SHIFT (PAGE_SHIFT - 3) /* 512 ptes per page */
33 #define PTE_FMT "%16Lx"
34 #else
35 typedef unsigned long pte_basic_t;
36 #define PTE_SHIFT (PAGE_SHIFT - 2) /* 1024 ptes per page */
37 #define PTE_FMT "%.8lx"
38 #endif
40 /* align addr on a size boundary - adjust address up/down if needed */
41 #define _ALIGN_UP(addr,size) (((addr)+((size)-1))&(~((size)-1)))
42 #define _ALIGN_DOWN(addr,size) ((addr)&(~((size)-1)))
44 /* align addr on a size boundary - adjust address up if needed */
45 #define _ALIGN(addr,size) _ALIGN_UP(addr,size)
47 /* to align the pointer to the (next) page boundary */
48 #define PAGE_ALIGN(addr) _ALIGN(addr, PAGE_SIZE)
51 #undef STRICT_MM_TYPECHECKS
53 #ifdef STRICT_MM_TYPECHECKS
55 * These are used to make use of C type-checking..
57 typedef struct { pte_basic_t pte; } pte_t;
58 typedef struct { unsigned long pmd; } pmd_t;
59 typedef struct { unsigned long pgd; } pgd_t;
60 typedef struct { unsigned long pgprot; } pgprot_t;
62 #define pte_val(x) ((x).pte)
63 #define pmd_val(x) ((x).pmd)
64 #define pgd_val(x) ((x).pgd)
65 #define pgprot_val(x) ((x).pgprot)
67 #define __pte(x) ((pte_t) { (x) } )
68 #define __pmd(x) ((pmd_t) { (x) } )
69 #define __pgd(x) ((pgd_t) { (x) } )
70 #define __pgprot(x) ((pgprot_t) { (x) } )
72 #else
74 * .. while these make it easier on the compiler
76 typedef pte_basic_t pte_t;
77 typedef unsigned long pmd_t;
78 typedef unsigned long pgd_t;
79 typedef unsigned long pgprot_t;
81 #define pte_val(x) (x)
82 #define pmd_val(x) (x)
83 #define pgd_val(x) (x)
84 #define pgprot_val(x) (x)
86 #define __pte(x) (x)
87 #define __pmd(x) (x)
88 #define __pgd(x) (x)
89 #define __pgprot(x) (x)
91 #endif
93 struct page;
94 extern void clear_pages(void *page, int order);
95 static inline void clear_page(void *page) { clear_pages(page, 0); }
96 extern void copy_page(void *to, void *from);
97 extern void clear_user_page(void *page, unsigned long vaddr, struct page *pg);
98 extern void copy_user_page(void *to, void *from, unsigned long vaddr,
99 struct page *pg);
101 #ifndef CONFIG_APUS
102 #define PPC_MEMSTART 0
103 #define PPC_PGSTART 0
104 #define PPC_MEMOFFSET PAGE_OFFSET
105 #else
106 extern unsigned long ppc_memstart;
107 extern unsigned long ppc_pgstart;
108 extern unsigned long ppc_memoffset;
109 #define PPC_MEMSTART ppc_memstart
110 #define PPC_PGSTART ppc_pgstart
111 #define PPC_MEMOFFSET ppc_memoffset
112 #endif
114 #if defined(CONFIG_APUS) && !defined(MODULE)
115 /* map phys->virtual and virtual->phys for RAM pages */
116 static inline unsigned long ___pa(unsigned long v)
118 unsigned long p;
119 asm volatile ("1: addis %0, %1, %2;"
120 ".section \".vtop_fixup\",\"aw\";"
121 ".align 1;"
122 ".long 1b;"
123 ".previous;"
124 : "=r" (p)
125 : "b" (v), "K" (((-PAGE_OFFSET) >> 16) & 0xffff));
127 return p;
129 static inline void* ___va(unsigned long p)
131 unsigned long v;
132 asm volatile ("1: addis %0, %1, %2;"
133 ".section \".ptov_fixup\",\"aw\";"
134 ".align 1;"
135 ".long 1b;"
136 ".previous;"
137 : "=r" (v)
138 : "b" (p), "K" (((PAGE_OFFSET) >> 16) & 0xffff));
140 return (void*) v;
142 #else
143 #define ___pa(vaddr) ((vaddr)-PPC_MEMOFFSET)
144 #define ___va(paddr) ((paddr)+PPC_MEMOFFSET)
145 #endif
147 extern int page_is_ram(unsigned long pfn);
149 #define __pa(x) ___pa((unsigned long)(x))
150 #define __va(x) ((void *)(___va((unsigned long)(x))))
152 #define pfn_to_page(pfn) (mem_map + ((pfn) - PPC_PGSTART))
153 #define page_to_pfn(page) ((unsigned long)((page) - mem_map) + PPC_PGSTART)
154 #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
155 #define page_to_virt(page) __va(page_to_pfn(page) << PAGE_SHIFT)
157 #define pfn_valid(pfn) (((pfn) - PPC_PGSTART) < max_mapnr)
158 #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
160 /* Pure 2^n version of get_order */
161 extern __inline__ int get_order(unsigned long size)
163 int lz;
165 size = (size-1) >> PAGE_SHIFT;
166 asm ("cntlzw %0,%1" : "=r" (lz) : "r" (size));
167 return 32 - lz;
170 #endif /* __ASSEMBLY__ */
172 #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
173 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
175 /* We do define AT_SYSINFO_EHDR but don't use the gate mecanism */
176 #define __HAVE_ARCH_GATE_AREA 1
178 #endif /* __KERNEL__ */
179 #endif /* _PPC_PAGE_H */