Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _M68K_PAGE_H |
| 2 | #define _M68K_PAGE_H |
| 3 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | |
Geert Uytterhoeven | 020d8c0 | 2006-09-18 20:12:23 -0700 | [diff] [blame] | 5 | #ifdef __KERNEL__ |
| 6 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | /* PAGE_SHIFT determines the page size */ |
| 8 | #ifndef CONFIG_SUN3 |
| 9 | #define PAGE_SHIFT (12) |
| 10 | #else |
| 11 | #define PAGE_SHIFT (13) |
| 12 | #endif |
| 13 | #ifdef __ASSEMBLY__ |
| 14 | #define PAGE_SIZE (1 << PAGE_SHIFT) |
| 15 | #else |
| 16 | #define PAGE_SIZE (1UL << PAGE_SHIFT) |
| 17 | #endif |
| 18 | #define PAGE_MASK (~(PAGE_SIZE-1)) |
| 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <asm/setup.h> |
| 21 | |
| 22 | #if PAGE_SHIFT < 13 |
| 23 | #define THREAD_SIZE (8192) |
| 24 | #else |
| 25 | #define THREAD_SIZE PAGE_SIZE |
| 26 | #endif |
| 27 | |
| 28 | #ifndef __ASSEMBLY__ |
| 29 | |
| 30 | #define get_user_page(vaddr) __get_free_page(GFP_KERNEL) |
| 31 | #define free_user_page(page, addr) free_page(addr) |
| 32 | |
| 33 | /* |
| 34 | * We don't need to check for alignment etc. |
| 35 | */ |
| 36 | #ifdef CPU_M68040_OR_M68060_ONLY |
| 37 | static inline void copy_page(void *to, void *from) |
| 38 | { |
| 39 | unsigned long tmp; |
| 40 | |
| 41 | __asm__ __volatile__("1:\t" |
| 42 | ".chip 68040\n\t" |
| 43 | "move16 %1@+,%0@+\n\t" |
| 44 | "move16 %1@+,%0@+\n\t" |
| 45 | ".chip 68k\n\t" |
| 46 | "dbra %2,1b\n\t" |
| 47 | : "=a" (to), "=a" (from), "=d" (tmp) |
| 48 | : "0" (to), "1" (from) , "2" (PAGE_SIZE / 32 - 1) |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | static inline void clear_page(void *page) |
| 53 | { |
| 54 | unsigned long tmp; |
| 55 | unsigned long *sp = page; |
| 56 | |
| 57 | *sp++ = 0; |
| 58 | *sp++ = 0; |
| 59 | *sp++ = 0; |
| 60 | *sp++ = 0; |
| 61 | |
| 62 | __asm__ __volatile__("1:\t" |
| 63 | ".chip 68040\n\t" |
| 64 | "move16 %2@+,%0@+\n\t" |
| 65 | ".chip 68k\n\t" |
| 66 | "subqw #8,%2\n\t" |
| 67 | "subqw #8,%2\n\t" |
| 68 | "dbra %1,1b\n\t" |
| 69 | : "=a" (sp), "=d" (tmp) |
| 70 | : "a" (page), "0" (sp), |
| 71 | "1" ((PAGE_SIZE - 16) / 16 - 1)); |
| 72 | } |
| 73 | |
| 74 | #else |
| 75 | #define clear_page(page) memset((page), 0, PAGE_SIZE) |
| 76 | #define copy_page(to,from) memcpy((to), (from), PAGE_SIZE) |
| 77 | #endif |
| 78 | |
| 79 | #define clear_user_page(addr, vaddr, page) \ |
| 80 | do { clear_page(addr); \ |
| 81 | flush_dcache_page(page); \ |
| 82 | } while (0) |
| 83 | #define copy_user_page(to, from, vaddr, page) \ |
| 84 | do { copy_page(to, from); \ |
| 85 | flush_dcache_page(page); \ |
| 86 | } while (0) |
| 87 | |
| 88 | /* |
| 89 | * These are used to make use of C type-checking.. |
| 90 | */ |
| 91 | typedef struct { unsigned long pte; } pte_t; |
| 92 | typedef struct { unsigned long pmd[16]; } pmd_t; |
| 93 | typedef struct { unsigned long pgd; } pgd_t; |
| 94 | typedef struct { unsigned long pgprot; } pgprot_t; |
| 95 | |
| 96 | #define pte_val(x) ((x).pte) |
| 97 | #define pmd_val(x) ((&x)->pmd[0]) |
| 98 | #define pgd_val(x) ((x).pgd) |
| 99 | #define pgprot_val(x) ((x).pgprot) |
| 100 | |
| 101 | #define __pte(x) ((pte_t) { (x) } ) |
| 102 | #define __pmd(x) ((pmd_t) { (x) } ) |
| 103 | #define __pgd(x) ((pgd_t) { (x) } ) |
| 104 | #define __pgprot(x) ((pgprot_t) { (x) } ) |
| 105 | |
| 106 | /* to align the pointer to the (next) page boundary */ |
| 107 | #define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK) |
| 108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | #endif /* !__ASSEMBLY__ */ |
| 110 | |
| 111 | #include <asm/page_offset.h> |
| 112 | |
| 113 | #define PAGE_OFFSET (PAGE_OFFSET_RAW) |
| 114 | |
| 115 | #ifndef __ASSEMBLY__ |
| 116 | |
| 117 | #ifndef CONFIG_SUN3 |
| 118 | |
| 119 | #define WANT_PAGE_VIRTUAL |
| 120 | #ifdef CONFIG_SINGLE_MEMORY_CHUNK |
| 121 | extern unsigned long m68k_memoffset; |
| 122 | |
| 123 | #define __pa(vaddr) ((unsigned long)(vaddr)+m68k_memoffset) |
| 124 | #define __va(paddr) ((void *)((unsigned long)(paddr)-m68k_memoffset)) |
| 125 | #else |
Andreas Schwab | 40bb0c3 | 2005-08-24 17:36:21 +0200 | [diff] [blame] | 126 | #define __pa(vaddr) virt_to_phys((void *)(vaddr)) |
| 127 | #define __va(paddr) phys_to_virt((unsigned long)(paddr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | #endif |
| 129 | |
| 130 | #else /* !CONFIG_SUN3 */ |
| 131 | /* This #define is a horrible hack to suppress lots of warnings. --m */ |
Andreas Schwab | 40bb0c3 | 2005-08-24 17:36:21 +0200 | [diff] [blame] | 132 | #define __pa(x) ___pa((unsigned long)(x)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | static inline unsigned long ___pa(unsigned long x) |
| 134 | { |
| 135 | if(x == 0) |
| 136 | return 0; |
| 137 | if(x >= PAGE_OFFSET) |
| 138 | return (x-PAGE_OFFSET); |
| 139 | else |
| 140 | return (x+0x2000000); |
| 141 | } |
| 142 | |
| 143 | static inline void *__va(unsigned long x) |
| 144 | { |
| 145 | if(x == 0) |
| 146 | return (void *)0; |
| 147 | |
| 148 | if(x < 0x2000000) |
| 149 | return (void *)(x+PAGE_OFFSET); |
| 150 | else |
| 151 | return (void *)(x-0x2000000); |
| 152 | } |
| 153 | #endif /* CONFIG_SUN3 */ |
| 154 | |
| 155 | /* |
| 156 | * NOTE: virtual isn't really correct, actually it should be the offset into the |
| 157 | * memory node, but we have no highmem, so that works for now. |
| 158 | * TODO: implement (fast) pfn<->pgdat_idx conversion functions, this makes lots |
| 159 | * of the shifts unnecessary. |
| 160 | */ |
| 161 | #define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT) |
| 162 | #define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT) |
| 163 | |
| 164 | #define virt_to_page(kaddr) (mem_map + (((unsigned long)(kaddr)-PAGE_OFFSET) >> PAGE_SHIFT)) |
| 165 | #define page_to_virt(page) ((((page) - mem_map) << PAGE_SHIFT) + PAGE_OFFSET) |
| 166 | |
| 167 | #define pfn_to_page(pfn) virt_to_page(pfn_to_virt(pfn)) |
| 168 | #define page_to_pfn(page) virt_to_pfn(page_to_virt(page)) |
| 169 | |
| 170 | #define virt_addr_valid(kaddr) ((void *)(kaddr) >= (void *)PAGE_OFFSET && (void *)(kaddr) < high_memory) |
| 171 | #define pfn_valid(pfn) virt_addr_valid(pfn_to_virt(pfn)) |
| 172 | |
| 173 | #endif /* __ASSEMBLY__ */ |
| 174 | |
| 175 | #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \ |
| 176 | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) |
| 177 | |
Stephen Rothwell | fd4fd5a | 2005-09-03 15:54:30 -0700 | [diff] [blame] | 178 | #include <asm-generic/page.h> |
| 179 | |
Geert Uytterhoeven | 020d8c0 | 2006-09-18 20:12:23 -0700 | [diff] [blame] | 180 | #endif /* __KERNEL__ */ |
| 181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | #endif /* _M68K_PAGE_H */ |