Import 2.4.0-test6pre6
[davej-history.git] / include / asm-sh / pgtable.h
blobd7da3b727fb39d052f58bfb4dd710a3644cc25b7
1 #ifndef __ASM_SH_PGTABLE_H
2 #define __ASM_SH_PGTABLE_H
4 /* Copyright (C) 1999 Niibe Yutaka */
6 /*
7 * This file contains the functions and defines necessary to modify and use
8 * the SuperH page table tree.
9 */
10 #ifndef __ASSEMBLY__
11 #include <asm/processor.h>
12 #include <asm/addrspace.h>
13 #include <linux/threads.h>
15 extern pgd_t swapper_pg_dir[1024];
16 extern void paging_init(void);
18 #if defined(__sh3__)
19 /* Cache flushing:
21 * - flush_cache_all() flushes entire cache
22 * - flush_cache_mm(mm) flushes the specified mm context's cache lines
23 * - flush_cache_page(mm, vmaddr) flushes a single page
24 * - flush_cache_range(mm, start, end) flushes a range of pages
26 * - flush_page_to_ram(page) write back kernel page to ram
27 * - flush_icache_range(start, end) flushes(invalidates) a range for icache
28 * - flush_icache_page(vma, pg) flushes(invalidates) a page for icache
30 * Caches are indexed (effectively) by physical address on SH-3, so
31 * we don't need them.
33 #define flush_cache_all() do { } while (0)
34 #define flush_cache_mm(mm) do { } while (0)
35 #define flush_cache_range(mm, start, end) do { } while (0)
36 #define flush_cache_page(vma, vmaddr) do { } while (0)
37 #define flush_page_to_ram(page) do { } while (0)
38 #define flush_dcache_page(page) do { } while (0)
39 #define flush_icache_range(start, end) do { } while (0)
40 #define flush_icache_page(vma,pg) do { } while (0)
41 #elif defined(__SH4__)
43 * Caches are broken on SH-4, so we need them.
45 extern void flush_cache_all(void);
46 extern void flush_cache_mm(struct mm_struct *mm);
47 extern void flush_cache_range(struct mm_struct *mm, unsigned long start,
48 unsigned long end);
49 extern void flush_cache_page(struct vm_area_struct *vma, unsigned long addr);
50 extern void flush_page_to_ram(struct page *page);
51 extern void flush_icache_range(unsigned long start, unsigned long end);
52 extern void flush_icache_page(struct vm_area_struct *vma, struct page *pg);
53 #endif
56 * Basically we have the same two-level (which is the logical three level
57 * Linux page table layout folded) page tables as the i386.
61 * ZERO_PAGE is a global shared page that is always zero: used
62 * for zero-mapped memory areas etc..
64 extern unsigned long empty_zero_page[1024];
65 #define ZERO_PAGE(vaddr) (mem_map + MAP_NR(empty_zero_page))
67 #endif /* !__ASSEMBLY__ */
69 #include <asm/pgtable-2level.h>
71 #define __beep() asm("")
73 #define PMD_SIZE (1UL << PMD_SHIFT)
74 #define PMD_MASK (~(PMD_SIZE-1))
75 #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
76 #define PGDIR_MASK (~(PGDIR_SIZE-1))
78 #define USER_PTRS_PER_PGD (TASK_SIZE/PGDIR_SIZE)
79 #define FIRST_USER_PGD_NR 0
81 #define USER_PGD_PTRS (PAGE_OFFSET >> PGDIR_SHIFT)
82 #define KERNEL_PGD_PTRS (PTRS_PER_PGD-USER_PGD_PTRS)
84 #define TWOLEVEL_PGDIR_SHIFT 22
85 #define BOOT_USER_PGD_PTRS (PAGE_OFFSET >> TWOLEVEL_PGDIR_SHIFT)
86 #define BOOT_KERNEL_PGD_PTRS (1024-BOOT_USER_PGD_PTRS)
88 #ifndef __ASSEMBLY__
89 #define VMALLOC_START P3SEG
90 #define VMALLOC_VMADDR(x) ((unsigned long)(x))
91 #define VMALLOC_END P4SEG
93 #define _PAGE_PRESENT 0x001 /* software: page is present */
94 #define _PAGE_ACCESSED 0x002 /* software: page referenced */
95 #define _PAGE_DIRTY 0x004 /* D-bit : page changed */
96 #define _PAGE_CACHABLE 0x008 /* C-bit : cachable */
97 /* 0x010 SZ-bit : size of page */
98 #define _PAGE_RW 0x020 /* PR0-bit : write access allowed */
99 #define _PAGE_USER 0x040 /* PR1-bit : user space access allowed */
100 #define _PAGE_PROTNONE 0x080 /* software: if not present */
101 /* 0x100 V-bit : page is valid */
103 #if defined(__sh3__)
104 /* Mask which drop software flags */
105 #define _PAGE_FLAGS_HARDWARE_MASK 0x1ffff06c
106 /* Flags defalult: SZ=1 (4k-byte), C=0 (non-cachable), SH=0 (not shared) */
107 #define _PAGE_FLAGS_HARDWARE_DEFAULT 0x00000110
108 #elif defined(__SH4__)
109 /* Mask which drops software flags */
110 #define _PAGE_FLAGS_HARDWARE_MASK 0x1ffff06c
111 /* Flags defalult: SZ=01 (4k-byte), C=0 (non-cachable), SH=0 (not shared), WT=0 */
112 #define _PAGE_FLAGS_HARDWARE_DEFAULT 0x00000110
113 #endif
115 #define _PAGE_TABLE (_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED | _PAGE_DIRTY)
116 #define _KERNPG_TABLE (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY)
117 #define _PAGE_CHG_MASK (PTE_MASK | _PAGE_ACCESSED | _PAGE_CACHABLE | _PAGE_DIRTY)
119 #define PAGE_NONE __pgprot(_PAGE_PROTNONE | _PAGE_CACHABLE |_PAGE_ACCESSED)
120 #define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_CACHABLE |_PAGE_ACCESSED)
121 #define PAGE_COPY __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_CACHABLE | _PAGE_ACCESSED)
122 #define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_CACHABLE | _PAGE_ACCESSED)
123 #define PAGE_KERNEL __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_CACHABLE | _PAGE_DIRTY | _PAGE_ACCESSED)
124 #define PAGE_KERNEL_RO __pgprot(_PAGE_PRESENT | _PAGE_CACHABLE | _PAGE_DIRTY | _PAGE_ACCESSED)
127 * As i386 and MIPS, SuperH can't do page protection for execute, and
128 * considers that the same are read. Also, write permissions imply
129 * read permissions. This is the closest we can get..
132 #define __P000 PAGE_NONE
133 #define __P001 PAGE_READONLY
134 #define __P010 PAGE_COPY
135 #define __P011 PAGE_COPY
136 #define __P100 PAGE_READONLY
137 #define __P101 PAGE_READONLY
138 #define __P110 PAGE_COPY
139 #define __P111 PAGE_COPY
141 #define __S000 PAGE_NONE
142 #define __S001 PAGE_READONLY
143 #define __S010 PAGE_SHARED
144 #define __S011 PAGE_SHARED
145 #define __S100 PAGE_READONLY
146 #define __S101 PAGE_READONLY
147 #define __S110 PAGE_SHARED
148 #define __S111 PAGE_SHARED
151 * Handling allocation failures during page table setup.
153 extern void __handle_bad_pmd(pmd_t * pmd);
154 extern void __handle_bad_pmd_kernel(pmd_t * pmd);
156 #define pte_none(x) (!pte_val(x))
157 #define pte_present(x) (pte_val(x) & (_PAGE_PRESENT | _PAGE_PROTNONE))
158 #define pte_clear(xp) do { set_pte(xp, __pte(0)); } while (0)
159 #define pte_pagenr(x) ((unsigned long)(((pte_val(x) -__MEMORY_START) >> PAGE_SHIFT)))
161 #define pmd_none(x) (!pmd_val(x))
162 #define pmd_present(x) (pmd_val(x) & _PAGE_PRESENT)
163 #define pmd_clear(xp) do { set_pmd(xp, __pmd(0)); } while (0)
164 #define pmd_bad(x) ((pmd_val(x) & (~PAGE_MASK & ~_PAGE_USER)) != _KERNPG_TABLE)
167 * Permanent address of a page. Obviously must never be
168 * called on a highmem page.
170 #define page_address(page) ((page)->virtual)
171 #define pages_to_mb(x) ((x) >> (20-PAGE_SHIFT))
172 #define pte_page(x) (mem_map+pte_pagenr(x))
175 * The following only work if pte_present() is true.
176 * Undefined behaviour if not..
178 extern inline int pte_read(pte_t pte) { return pte_val(pte) & _PAGE_USER; }
179 extern inline int pte_exec(pte_t pte) { return pte_val(pte) & _PAGE_USER; }
180 extern inline int pte_dirty(pte_t pte){ return pte_val(pte) & _PAGE_DIRTY; }
181 extern inline int pte_young(pte_t pte){ return pte_val(pte) & _PAGE_ACCESSED; }
182 extern inline int pte_write(pte_t pte){ return pte_val(pte) & _PAGE_RW; }
184 extern inline pte_t pte_rdprotect(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_USER)); return pte; }
185 extern inline pte_t pte_exprotect(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_USER)); return pte; }
186 extern inline pte_t pte_mkclean(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_DIRTY)); return pte; }
187 extern inline pte_t pte_mkold(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_ACCESSED)); return pte; }
188 extern inline pte_t pte_wrprotect(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_RW)); return pte; }
189 extern inline pte_t pte_mkread(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_USER)); return pte; }
190 extern inline pte_t pte_mkexec(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_USER)); return pte; }
191 extern inline pte_t pte_mkdirty(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_DIRTY)); return pte; }
192 extern inline pte_t pte_mkyoung(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_ACCESSED)); return pte; }
193 extern inline pte_t pte_mkwrite(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_RW)); return pte; }
196 * Conversion functions: convert a page and protection to a page entry,
197 * and a page entry and page directory to the page they refer to.
199 * extern pte_t mk_pte(struct page *page, pgprot_t pgprot)
201 #define mk_pte(page,pgprot) \
202 ({ pte_t __pte; \
204 set_pte(&__pte, __pte(((page)-mem_map) * \
205 (unsigned long long)PAGE_SIZE + pgprot_val(pgprot) + \
206 __MEMORY_START)); \
207 __pte; \
210 /* This takes a physical page address that is used by the remapping functions */
211 #define mk_pte_phys(physpage, pgprot) \
212 ({ pte_t __pte; set_pte(&__pte, __pte(physpage + pgprot_val(pgprot))); __pte; })
214 extern inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
215 { set_pte(&pte, __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot))); return pte; }
217 #define page_pte(page) page_pte_prot(page, __pgprot(0))
219 #define pmd_page(pmd) \
220 ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
222 /* to find an entry in a page-table-directory. */
223 #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
224 #define __pgd_offset(address) pgd_index(address)
225 #define pgd_offset(mm, address) ((mm)->pgd+pgd_index(address))
227 /* to find an entry in a kernel page-table-directory */
228 #define pgd_offset_k(address) pgd_offset(&init_mm, address)
230 #define __pmd_offset(address) \
231 (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
233 /* Find an entry in the third-level page table.. */
234 #define __pte_offset(address) \
235 ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
236 #define pte_offset(dir, address) ((pte_t *) pmd_page(*(dir)) + \
237 __pte_offset(address))
239 extern void update_mmu_cache(struct vm_area_struct * vma,
240 unsigned long address, pte_t pte);
242 /* Encode and de-code a swap entry */
243 #define SWP_TYPE(x) (((x).val >> 1) & 0x3f)
244 #define SWP_OFFSET(x) ((x).val >> 8)
245 #define SWP_ENTRY(type, offset) ((swp_entry_t) { ((type) << 1) | ((offset) << 8) })
246 #define pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
247 #define swp_entry_to_pte(x) ((pte_t) { (x).val })
249 #define module_map vmalloc
250 #define module_unmap vfree
252 #endif /* !__ASSEMBLY__ */
254 /* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
255 #define PageSkip(page) (0)
256 #define kern_addr_valid(addr) (1)
258 #define io_remap_page_range remap_page_range
260 #endif /* __ASM_SH_PAGE_H */