[PATCH] w1: hotplug support.
[linux-2.6/verdex.git] / include / asm-ppc / page.h
blob4789dc024240a0b9830e575a35a5f681de2f2438
1 #ifndef _PPC_PAGE_H
2 #define _PPC_PAGE_H
4 /* PAGE_SHIFT determines the page size */
5 #define PAGE_SHIFT 12
6 #define PAGE_SIZE (1UL << PAGE_SHIFT)
8 /*
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))
14 #ifdef __KERNEL__
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
21 #ifndef __ASSEMBLY__
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"
31 #else
32 typedef unsigned long pte_basic_t;
33 #define PTE_SHIFT (PAGE_SHIFT - 2) /* 1024 ptes per page */
34 #define PTE_FMT "%.8lx"
35 #endif
37 #undef STRICT_MM_TYPECHECKS
39 #ifdef STRICT_MM_TYPECHECKS
41 * These are used to make use of C type-checking..
43 typedef struct { pte_basic_t pte; } pte_t;
44 typedef struct { unsigned long pmd; } pmd_t;
45 typedef struct { unsigned long pgd; } pgd_t;
46 typedef struct { unsigned long pgprot; } pgprot_t;
48 #define pte_val(x) ((x).pte)
49 #define pmd_val(x) ((x).pmd)
50 #define pgd_val(x) ((x).pgd)
51 #define pgprot_val(x) ((x).pgprot)
53 #define __pte(x) ((pte_t) { (x) } )
54 #define __pmd(x) ((pmd_t) { (x) } )
55 #define __pgd(x) ((pgd_t) { (x) } )
56 #define __pgprot(x) ((pgprot_t) { (x) } )
58 #else
60 * .. while these make it easier on the compiler
62 typedef pte_basic_t pte_t;
63 typedef unsigned long pmd_t;
64 typedef unsigned long pgd_t;
65 typedef unsigned long pgprot_t;
67 #define pte_val(x) (x)
68 #define pmd_val(x) (x)
69 #define pgd_val(x) (x)
70 #define pgprot_val(x) (x)
72 #define __pte(x) (x)
73 #define __pmd(x) (x)
74 #define __pgd(x) (x)
75 #define __pgprot(x) (x)
77 #endif
80 /* align addr on a size boundary - adjust address up if needed -- Cort */
81 #define _ALIGN(addr,size) (((addr)+(size)-1)&(~((size)-1)))
83 /* to align the pointer to the (next) page boundary */
84 #define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
86 struct page;
87 extern void clear_pages(void *page, int order);
88 static inline void clear_page(void *page) { clear_pages(page, 0); }
89 extern void copy_page(void *to, void *from);
90 extern void clear_user_page(void *page, unsigned long vaddr, struct page *pg);
91 extern void copy_user_page(void *to, void *from, unsigned long vaddr,
92 struct page *pg);
94 #ifndef CONFIG_APUS
95 #define PPC_MEMSTART 0
96 #define PPC_PGSTART 0
97 #define PPC_MEMOFFSET PAGE_OFFSET
98 #else
99 extern unsigned long ppc_memstart;
100 extern unsigned long ppc_pgstart;
101 extern unsigned long ppc_memoffset;
102 #define PPC_MEMSTART ppc_memstart
103 #define PPC_PGSTART ppc_pgstart
104 #define PPC_MEMOFFSET ppc_memoffset
105 #endif
107 #if defined(CONFIG_APUS) && !defined(MODULE)
108 /* map phys->virtual and virtual->phys for RAM pages */
109 static inline unsigned long ___pa(unsigned long v)
111 unsigned long p;
112 asm volatile ("1: addis %0, %1, %2;"
113 ".section \".vtop_fixup\",\"aw\";"
114 ".align 1;"
115 ".long 1b;"
116 ".previous;"
117 : "=r" (p)
118 : "b" (v), "K" (((-PAGE_OFFSET) >> 16) & 0xffff));
120 return p;
122 static inline void* ___va(unsigned long p)
124 unsigned long v;
125 asm volatile ("1: addis %0, %1, %2;"
126 ".section \".ptov_fixup\",\"aw\";"
127 ".align 1;"
128 ".long 1b;"
129 ".previous;"
130 : "=r" (v)
131 : "b" (p), "K" (((PAGE_OFFSET) >> 16) & 0xffff));
133 return (void*) v;
135 #else
136 #define ___pa(vaddr) ((vaddr)-PPC_MEMOFFSET)
137 #define ___va(paddr) ((paddr)+PPC_MEMOFFSET)
138 #endif
140 extern int page_is_ram(unsigned long pfn);
142 #define __pa(x) ___pa((unsigned long)(x))
143 #define __va(x) ((void *)(___va((unsigned long)(x))))
145 #define pfn_to_page(pfn) (mem_map + ((pfn) - PPC_PGSTART))
146 #define page_to_pfn(page) ((unsigned long)((page) - mem_map) + PPC_PGSTART)
147 #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
148 #define page_to_virt(page) __va(page_to_pfn(page) << PAGE_SHIFT)
150 #define pfn_valid(pfn) (((pfn) - PPC_PGSTART) < max_mapnr)
151 #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
153 /* Pure 2^n version of get_order */
154 extern __inline__ int get_order(unsigned long size)
156 int lz;
158 size = (size-1) >> PAGE_SHIFT;
159 asm ("cntlzw %0,%1" : "=r" (lz) : "r" (size));
160 return 32 - lz;
163 #endif /* __ASSEMBLY__ */
165 #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
166 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
168 #endif /* __KERNEL__ */
169 #endif /* _PPC_PAGE_H */