make oldconfig will rebuild these...
[linux-2.4.21-pre4.git] / include / asm-ppc64 / page.h
1 #ifndef _PPC64_PAGE_H
2 #define _PPC64_PAGE_H
3
4 /*
5  * Copyright (C) 2001 PPC64 Team, IBM Corp
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version
10  * 2 of the License, or (at your option) any later version.
11  */
12
13 #include <linux/config.h>
14
15 /* PAGE_SHIFT determines the page size */
16 #define PAGE_SHIFT      12
17 #ifndef __ASSEMBLY__
18 #define PAGE_SIZE       (1UL << PAGE_SHIFT)
19 #else
20 # define PAGE_SIZE      (1 << PAGE_SHIFT)
21 #endif
22 #define PAGE_MASK       (~(PAGE_SIZE-1))
23 #define PAGE_OFFSET_MASK (PAGE_SIZE-1)
24
25 #define SID_SHIFT       28
26 #define SID_MASK        0xfffffffff
27 #define GET_ESID(x)     (((x) >> SID_SHIFT) & SID_MASK)
28
29 /* Define an illegal instr to trap on the bug.
30  * We don't use 0 because that marks the end of a function
31  * in the ELF ABI.  That's "Boo Boo" in case you wonder...
32  */
33 #define BUG_OPCODE .long 0x00b00b00  /* For asm */
34 #define BUG_ILLEGAL_INSTR "0x00b00b00" /* For BUG macro */
35
36 #ifdef __KERNEL__
37 #ifndef __ASSEMBLY__
38 #include <asm/naca.h>
39 #include <asm/systemcfg.h>
40
41 #define STRICT_MM_TYPECHECKS
42
43 #define REGION_SIZE   4UL
44 #define OFFSET_SIZE   60UL
45 #define REGION_SHIFT  60UL
46 #define OFFSET_SHIFT  0UL
47 #define REGION_MASK   (((1UL<<REGION_SIZE)-1UL)<<REGION_SHIFT)
48 #define REGION_STRIDE (1UL << REGION_SHIFT)
49
50 #ifdef ___powerpc64__
51 typedef union ppc64_va {
52         struct {
53                 unsigned long off : OFFSET_SIZE;  /* intra-region offset */
54                 unsigned long reg : REGION_SIZE;  /* region number */
55         } f;
56         unsigned long l;
57         void *p;
58 } ppc64_va;
59 #endif /* ___powerpc64__ */
60        
61 static __inline__ void clear_page(void *addr)
62 {
63         unsigned long lines, line_size;
64
65         line_size = systemcfg->dCacheL1LineSize; 
66         lines = naca->dCacheL1LinesPerPage;
67
68         __asm__ __volatile__(
69 "       mtctr   %1\n\
70 1:      dcbz    0,%0\n\
71         add     %0,%0,%3\n\
72         bdnz+   1b"
73         : "=r" (addr)
74         : "r" (lines), "0" (addr), "r" (line_size)
75         : "ctr", "memory");
76 }
77
78 extern void copy_page(void *to, void *from);
79 struct page;
80 extern void clear_user_page(void *page, unsigned long vaddr);
81 extern void copy_user_page(void *to, void *from, unsigned long vaddr);
82
83 #ifdef STRICT_MM_TYPECHECKS
84 /*
85  * These are used to make use of C type-checking.  
86  * Entries in the pte table are 64b, while entries in the pgd & pmd are 32b.
87  */
88 typedef struct { unsigned long pte; } pte_t;
89 typedef struct { unsigned int  pmd; } pmd_t;
90 typedef struct { unsigned int  pgd; } pgd_t;
91 typedef struct { unsigned long pgprot; } pgprot_t;
92
93 #define pte_val(x)      ((x).pte)
94 #define pmd_val(x)      ((x).pmd)
95 #define pgd_val(x)      ((x).pgd)
96 #define pgprot_val(x)   ((x).pgprot)
97
98 #define __pte(x)        ((pte_t) { (x) } )
99 #define __pmd(x)        ((pmd_t) { (x) } )
100 #define __pgd(x)        ((pgd_t) { (x) } )
101 #define __pgprot(x)     ((pgprot_t) { (x) } )
102
103 #else
104 /*
105  * .. while these make it easier on the compiler
106  */
107 typedef unsigned long pte_t;
108 typedef unsigned int  pmd_t;
109 typedef unsigned int  pgd_t;
110 typedef unsigned long pgprot_t;
111
112 #define pte_val(x)      (x)
113 #define pmd_val(x)      (x)
114 #define pgd_val(x)      (x)
115 #define pgprot_val(x)   (x)
116
117 #define __pte(x)        (x)
118 #define __pmd(x)        (x)
119 #define __pgd(x)        (x)
120 #define __pgprot(x)     (x)
121
122 #endif
123
124 #ifdef CONFIG_XMON
125 #include <asm/ptrace.h>
126 extern void xmon(struct pt_regs *excp);
127 #define BUG() do { \
128         printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \
129         xmon(0); \
130 } while (0)
131 #elif defined(CONFIG_KDB)
132 #include <asm/ptrace.h>
133 #include <linux/kdb.h>
134 /* extern void kdb(kdb_reason_t reason, int error, kdb_eframe_t ef); */
135 #define BUG() do { \
136       printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \
137       kdb(KDB_REASON_CALL, 0, (kdb_eframe_t) 0); \
138 } while (0)
139 #else
140 #define BUG() do { \
141         printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \
142         __asm__ __volatile__(".long " BUG_ILLEGAL_INSTR); \
143 } while (0)
144 #endif
145
146 #define PAGE_BUG(page) do { BUG(); } while (0)
147
148 /* Pure 2^n version of get_order */
149 static inline int get_order(unsigned long size)
150 {
151         int order;
152
153         size = (size-1) >> (PAGE_SHIFT-1);
154         order = -1;
155         do {
156                 size >>= 1;
157                 order++;
158         } while (size);
159         return order;
160 }
161
162 #define __pa(x) ((unsigned long)(x)-PAGE_OFFSET)
163
164 #endif /* __ASSEMBLY__ */
165
166 /* align addr on a size boundry - adjust address up/down if needed */
167 #define _ALIGN_UP(addr,size)    (((addr)+((size)-1))&(~((size)-1)))
168 #define _ALIGN_DOWN(addr,size)  ((addr)&(~((size)-1)))
169
170 /* align addr on a size boundry - adjust address up if needed */
171 #define _ALIGN(addr,size)     _ALIGN_UP(addr,size)
172
173 /* to align the pointer to the (next) double word boundary */
174 #define DOUBLEWORD_ALIGN(addr)  _ALIGN(addr,sizeof(unsigned long))
175
176 /* to align the pointer to the (next) page boundary */
177 #define PAGE_ALIGN(addr)        _ALIGN(addr, PAGE_SIZE)
178
179 #ifdef MODULE
180 #define __page_aligned __attribute__((__aligned__(PAGE_SIZE)))
181 #else
182 #define __page_aligned \
183         __attribute__((__aligned__(PAGE_SIZE), \
184                 __section__(".data.page_aligned")))
185 #endif
186
187
188 /* This must match the -Ttext linker address            */
189 /* Note: tophys & tovirt make assumptions about how     */
190 /*       KERNELBASE is defined for performance reasons. */
191 /*       When KERNELBASE moves, those macros may have   */
192 /*             to change!                               */
193 #define PAGE_OFFSET     0xC000000000000000
194 #define KERNELBASE      PAGE_OFFSET
195 #define VMALLOCBASE     0xD000000000000000
196 #define IOREGIONBASE    0xE000000000000000
197 #define EEHREGIONBASE   0xA000000000000000
198 #define BOLTEDBASE      0xB000000000000000
199
200 #define IO_REGION_ID       (IOREGIONBASE>>REGION_SHIFT)
201 #define EEH_REGION_ID      (EEHREGIONBASE>>REGION_SHIFT)
202 #define VMALLOC_REGION_ID  (VMALLOCBASE>>REGION_SHIFT)
203 #define KERNEL_REGION_ID   (KERNELBASE>>REGION_SHIFT)
204 #define BOLTED_REGION_ID   (BOLTEDBASE>>REGION_SHIFT)
205 #define USER_REGION_ID     (0UL)
206 #define REGION_ID(X)       (((unsigned long)(X))>>REGION_SHIFT)
207
208 /*
209  * Define valid/invalid EA bits (for all ranges)
210  */
211 #define VALID_EA_BITS   (0x000001ffffffffffUL)
212 #define INVALID_EA_BITS (~(REGION_MASK|VALID_EA_BITS))
213
214 #define IS_VALID_REGION_ID(x) \
215         (((x) == USER_REGION_ID) || ((x) >= BOLTED_REGION_ID))
216 #define IS_VALID_EA(x) \
217         ((!((x) & INVALID_EA_BITS)) && IS_VALID_REGION_ID(REGION_ID(x)))
218
219 #define __bpn_to_ba(x) ((((unsigned long)(x))<<PAGE_SHIFT) + KERNELBASE)
220 #define __ba_to_bpn(x) ((((unsigned long)(x)) & ~REGION_MASK) >> PAGE_SHIFT)
221
222 #define __va(x) ((void *)((unsigned long)(x) + KERNELBASE))
223
224 /* Given that physical addresses do not map 1-1 to absolute addresses, we
225  * use these macros to better specify exactly what we want to do.
226  * The only restriction on their use is that the absolute address
227  * macros cannot be used until after the LMB structure has been
228  * initialized in prom.c.  -Peter
229  */
230 #define __v2p(x) ((void *) __pa(x))
231 #define __v2a(x) ((void *) phys_to_absolute(__pa(x)))
232 #define __p2a(x) ((void *) phys_to_absolute(x))
233 #define __p2v(x) ((void *) __va(x))
234 #define __a2p(x) ((void *) absolute_to_phys(x))
235 #define __a2v(x) ((void *) __va(absolute_to_phys(x)))
236
237 #define virt_to_page(kaddr) (mem_map+(__pa((unsigned long)kaddr) >> PAGE_SHIFT))
238
239 #define VALID_PAGE(page)    ((page - mem_map) < max_mapnr)
240
241 #define MAP_NR(addr)        (__pa(addr) >> PAGE_SHIFT)
242
243 #define VM_DATA_DEFAULT_FLAGS   (VM_READ | VM_WRITE | VM_EXEC | \
244                                  VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
245
246 #endif /* __KERNEL__ */
247 #endif /* _PPC64_PAGE_H */