- Kai Germaschewski: ymfpci cleanups and resource leak fixes
[davej-history.git] / include / asm-parisc / pgtable.h
blob6213ab8504f2a28d5e09055176d2ee0237eca01f
1 #ifndef _PARISC_PGTABLE_H
2 #define _PARISC_PGTABLE_H
4 #ifndef __ASSEMBLY__
5 /*
6 * we simulate an x86-style page table for the linux mm code
7 */
9 #include <asm/processor.h>
10 #include <asm/fixmap.h>
11 #include <asm/cache.h>
13 /* To make 53c7xx.c happy */
15 #define IOMAP_FULL_CACHING 2 /* used for 'what' below */
16 #define IOMAP_NOCACHE_SER 3
18 extern void kernel_set_cachemode(unsigned long addr,
19 unsigned long size, int what);
22 * cache_clear() semantics: Clear any cache entries for the area in question,
23 * without writing back dirty entries first. This is useful if the data will
24 * be overwritten anyway, e.g. by DMA to memory. The range is defined by a
25 * _physical_ address.
27 #define cache_clear(paddr, len) do { } while (0)
29 * cache_push() semantics: Write back any dirty cache data in the given area,
30 * and invalidate the range in the instruction cache. It needs not (but may)
31 * invalidate those entries also in the data cache. The range is defined by a
32 * _physical_ address.
34 #define cache_push(paddr, len) \
35 do { \
36 unsigned long vaddr = phys_to_virt(paddr); \
37 flush_cache_range(&init_mm, vaddr, vaddr + len); \
38 } while(0)
39 #define cache_push_v(vaddr, len) \
40 flush_cache_range(&init_mm, vaddr, vaddr + len)
43 * kern_addr_valid(ADDR) tests if ADDR is pointing to valid kernel
44 * memory. For the return value to be meaningful, ADDR must be >=
45 * PAGE_OFFSET. This operation can be relatively expensive (e.g.,
46 * require a hash-, or multi-level tree-lookup or something of that
47 * sort) but it guarantees to return TRUE only if accessing the page
48 * at that address does not cause an error. Note that there may be
49 * addresses for which kern_addr_valid() returns FALSE even though an
50 * access would not cause an error (e.g., this is typically true for
51 * memory mapped I/O regions.
53 * XXX Need to implement this for parisc.
55 #define kern_addr_valid(addr) (1)
57 /* Certain architectures need to do special things when PTEs
58 * within a page table are directly modified. Thus, the following
59 * hook is made available.
61 #define set_pte(pteptr, pteval) \
62 do{ \
63 *(pteptr) = (pteval); \
64 } while(0)
68 #endif /* !__ASSEMBLY__ */
70 #define pte_ERROR(e) \
71 printk("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, pte_val(e))
72 #define pmd_ERROR(e) \
73 printk("%s:%d: bad pmd %08lx.\n", __FILE__, __LINE__, pmd_val(e))
74 #define pgd_ERROR(e) \
75 printk("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e))
78 * pgd entries used up by user/kernel:
81 #define USER_PGD_PTRS (PAGE_OFFSET >> PGDIR_SHIFT)
82 #define FIRST_USER_PGD_NR 0
84 #ifndef __ASSEMBLY__
85 extern void *vmalloc_start;
86 #define PCXL_DMA_MAP_SIZE (8*1024*1024)
87 #define VMALLOC_START ((unsigned long)vmalloc_start)
88 #define VMALLOC_VMADDR(x) ((unsigned long)(x))
89 #define VMALLOC_END (FIXADDR_START)
90 #endif
92 #define _PAGE_READ 0x001 /* read access allowed */
93 #define _PAGE_WRITE 0x002 /* write access allowed */
94 #define _PAGE_EXEC 0x004 /* execute access allowed */
95 #define _PAGE_GATEWAY 0x008 /* privilege promotion allowed */
96 #define _PAGE_GATEWAY_BIT 28 /* _PAGE_GATEWAY & _PAGE_GATEWAY_BIT need */
97 /* to agree. One could be defined in relation */
98 /* to the other, but that's kind of ugly. */
100 /* 0x010 reserved (B bit) */
101 #define _PAGE_DIRTY 0x020 /* D: dirty */
102 /* 0x040 reserved (T bit) */
103 #define _PAGE_NO_CACHE 0x080 /* Software: Uncacheable */
104 #define _PAGE_NO_CACHE_BIT 24 /* Needs to agree with _PAGE_NO_CACHE above */
105 #define _PAGE_ACCESSED 0x100 /* R: page cache referenced */
106 #define _PAGE_PRESENT 0x200 /* Software: pte contains a translation */
107 #define _PAGE_PRESENT_BIT 22 /* Needs to agree with _PAGE_PRESENT above */
108 #define _PAGE_USER 0x400 /* Software: User accessable page */
109 #define _PAGE_USER_BIT 21 /* Needs to agree with _PAGE_USER above */
110 /* 0x800 still available */
112 #ifdef __ASSEMBLY__
113 #define _PGB_(x) (1 << (63 - (x)))
114 #define __PAGE_O _PGB_(13)
115 #define __PAGE_U _PGB_(12)
116 #define __PAGE_T _PGB_(2)
117 #define __PAGE_D _PGB_(3)
118 #define __PAGE_B _PGB_(4)
119 #define __PAGE_P _PGB_(14)
120 #endif
121 #define _PAGE_TABLE (_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | _PAGE_DIRTY | _PAGE_ACCESSED)
122 #define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
123 #define _PAGE_KERNEL (_PAGE_PRESENT | _PAGE_EXEC | _PAGE_READ | _PAGE_WRITE | _PAGE_DIRTY | _PAGE_ACCESSED)
125 #ifndef __ASSEMBLY__
127 #define PAGE_NONE __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED)
128 #define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
129 /* Others seem to make this executable, I don't know if that's correct
130 or not. The stack is mapped this way though so this is necessary
131 in the short term - dhd@linuxcare.com, 2000-08-08 */
132 #define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
133 #define PAGE_WRITEONLY __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_WRITE | _PAGE_ACCESSED)
134 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
135 #define PAGE_COPY PAGE_EXECREAD
136 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
137 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
138 #define PAGE_KERNEL_RO __pgprot(_PAGE_PRESENT | _PAGE_EXEC | _PAGE_READ | _PAGE_DIRTY | _PAGE_ACCESSED)
139 #define PAGE_KERNEL_UNC __pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
140 #define PAGE_GATEWAY __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED | _PAGE_GATEWAY| _PAGE_READ)
144 * We could have an execute only page using "gateway - promote to priv
145 * level 3", but that is kind of silly. So, the way things are defined
146 * now, we must always have read permission for pages with execute
147 * permission. For the fun of it we'll go ahead and support write only
148 * pages.
151 /*xwr*/
152 #define __P000 PAGE_NONE
153 #define __P001 PAGE_READONLY
154 #define __P010 __P000 /* copy on write */
155 #define __P011 __P001 /* copy on write */
156 #define __P100 PAGE_EXECREAD
157 #define __P101 PAGE_EXECREAD
158 #define __P110 __P100 /* copy on write */
159 #define __P111 __P101 /* copy on write */
161 #define __S000 PAGE_NONE
162 #define __S001 PAGE_READONLY
163 #define __S010 PAGE_WRITEONLY
164 #define __S011 PAGE_SHARED
165 #define __S100 PAGE_EXECREAD
166 #define __S101 PAGE_EXECREAD
167 #define __S110 PAGE_RWX
168 #define __S111 PAGE_RWX
170 extern unsigned long swapper_pg_dir[]; /* declared in init_task.c */
172 /* initial page tables for 0-8MB for kernel */
174 extern unsigned long pg0[];
176 /* zero page used for uninitialized stuff */
178 extern unsigned long *empty_zero_page;
181 * BAD_PAGETABLE is used when we need a bogus page-table, while
182 * BAD_PAGE is used for a bogus page.
184 * ZERO_PAGE is a global shared page that is always zero: used
185 * for zero-mapped memory areas etc..
187 extern pte_t __bad_page(void);
188 extern pte_t * __bad_pagetable(void);
190 #define BAD_PAGETABLE __bad_pagetable()
191 #define BAD_PAGE __bad_page()
192 #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
194 #define pte_none(x) (!pte_val(x))
195 #define pte_present(x) (pte_val(x) & _PAGE_PRESENT)
196 #define pte_clear(xp) do { pte_val(*(xp)) = 0; } while (0)
197 #define pte_pagenr(x) ((unsigned long)((pte_val(x) >> PAGE_SHIFT)))
199 #define pmd_none(x) (!pmd_val(x))
200 #define pmd_bad(x) ((pmd_val(x) & ~PAGE_MASK) != _PAGE_TABLE)
201 #define pmd_present(x) (pmd_val(x) & _PAGE_PRESENT)
202 #define pmd_clear(xp) do { pmd_val(*(xp)) = 0; } while (0)
206 #ifdef __LP64__
207 #define pgd_page(pgd) ((unsigned long) __va(pgd_val(pgd) & PAGE_MASK))
209 /* For 64 bit we have three level tables */
211 #define pgd_none(x) (!pgd_val(x))
212 #define pgd_bad(x) ((pgd_val(x) & ~PAGE_MASK) != _PAGE_TABLE)
213 #define pgd_present(x) (pgd_val(x) & _PAGE_PRESENT)
214 #define pgd_clear(xp) do { pgd_val(*(xp)) = 0; } while (0)
215 #else
217 * The "pgd_xxx()" functions here are trivial for a folded two-level
218 * setup: the pgd is never bad, and a pmd always exists (as it's folded
219 * into the pgd entry)
221 extern inline int pgd_none(pgd_t pgd) { return 0; }
222 extern inline int pgd_bad(pgd_t pgd) { return 0; }
223 extern inline int pgd_present(pgd_t pgd) { return 1; }
224 extern inline void pgd_clear(pgd_t * pgdp) { }
225 #endif
228 * The following only work if pte_present() is true.
229 * Undefined behaviour if not..
231 extern inline int pte_read(pte_t pte) { return pte_val(pte) & _PAGE_READ; }
232 extern inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY; }
233 extern inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; }
234 extern inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_WRITE; }
236 extern inline pte_t pte_rdprotect(pte_t pte) { pte_val(pte) &= ~_PAGE_READ; return pte; }
237 extern inline pte_t pte_mkclean(pte_t pte) { pte_val(pte) &= ~_PAGE_DIRTY; return pte; }
238 extern inline pte_t pte_mkold(pte_t pte) { pte_val(pte) &= ~_PAGE_ACCESSED; return pte; }
239 extern inline pte_t pte_wrprotect(pte_t pte) { pte_val(pte) &= ~_PAGE_WRITE; return pte; }
240 extern inline pte_t pte_mkread(pte_t pte) { pte_val(pte) |= _PAGE_READ; return pte; }
241 extern inline pte_t pte_mkdirty(pte_t pte) { pte_val(pte) |= _PAGE_DIRTY; return pte; }
242 extern inline pte_t pte_mkyoung(pte_t pte) { pte_val(pte) |= _PAGE_ACCESSED; return pte; }
243 extern inline pte_t pte_mkwrite(pte_t pte) { pte_val(pte) |= _PAGE_WRITE; return pte; }
246 * Conversion functions: convert a page and protection to a page entry,
247 * and a page entry and page directory to the page they refer to.
249 #define __mk_pte(addr,pgprot) \
250 ({ \
251 pte_t __pte; \
253 pte_val(__pte) = ((addr)+pgprot_val(pgprot)); \
255 __pte; \
258 #define mk_pte(page,pgprot) \
259 ({ \
260 pte_t __pte; \
262 pte_val(__pte) = ((page)-mem_map)*PAGE_SIZE + \
263 pgprot_val(pgprot); \
264 __pte; \
267 /* This takes a physical page address that is used by the remapping functions */
268 #define mk_pte_phys(physpage, pgprot) \
269 ({ pte_t __pte; pte_val(__pte) = physpage + pgprot_val(pgprot); __pte; })
271 extern inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
272 { pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); return pte; }
275 * Permanent address of a page. Obviously must never be
276 * called on a highmem page.
278 #define page_address(page) ({ if (!(page)->virtual) BUG(); (page)->virtual; })
279 #define __page_address(page) ({ if (PageHighMem(page)) BUG(); PAGE_OFFSET + (((page) - mem_map) << PAGE_SHIFT); })
280 #define pages_to_mb(x) ((x) >> (20-PAGE_SHIFT))
281 #define pte_page(x) (mem_map+pte_pagenr(x))
283 #define pmd_page(pmd) ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
285 #define pgd_index(address) ((address) >> PGDIR_SHIFT)
287 /* to find an entry in a page-table-directory */
288 #define pgd_offset(mm, address) \
289 ((mm)->pgd + ((address) >> PGDIR_SHIFT))
291 /* to find an entry in a kernel page-table-directory */
292 #define pgd_offset_k(address) pgd_offset(&init_mm, address)
294 /* Find an entry in the second-level page table.. */
296 #ifdef __LP64__
297 #define pmd_offset(dir,address) \
298 ((pmd_t *) pgd_page(*(dir)) + (((address)>>PMD_SHIFT) & (PTRS_PER_PMD-1)))
299 #else
300 #define pmd_offset(dir,addr) ((pmd_t *) dir)
301 #endif
303 /* Find an entry in the third-level page table.. */
304 #define pte_offset(pmd, address) \
305 ((pte_t *) pmd_page(*(pmd)) + (((address)>>PAGE_SHIFT) & (PTRS_PER_PTE-1)))
307 extern void paging_init (void);
309 extern inline void update_mmu_cache(struct vm_area_struct * vma,
310 unsigned long address, pte_t pte)
314 /* Encode and de-code a swap entry */
316 #define SWP_TYPE(x) ((x).val & 0x3f)
317 #define SWP_OFFSET(x) ( (((x).val >> 6) & 0x7) | \
318 (((x).val >> 7) & ~0x7) )
319 #define SWP_ENTRY(type, offset) ((swp_entry_t) { (type) | \
320 ((offset & 0x7) << 6) | \
321 ((offset & ~0x7) << 7) })
322 #define pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
323 #define swp_entry_to_pte(x) ((pte_t) { (x).val })
325 #define module_map vmalloc
326 #define module_unmap vfree
328 #include <asm-generic/pgtable.h>
330 #endif /* !__ASSEMBLY__ */
332 /* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
333 #define PageSkip(page) (0)
335 #define io_remap_page_range remap_page_range
337 #endif /* _PARISC_PAGE_H */