Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __ASM_SH_PAGE_H |
| 2 | #define __ASM_SH_PAGE_H |
| 3 | |
| 4 | /* |
| 5 | * Copyright (C) 1999 Niibe Yutaka |
| 6 | */ |
| 7 | |
Stuart Menefy | d02b08f | 2007-11-30 17:52:53 +0900 | [diff] [blame] | 8 | #include <linux/const.h> |
| 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | /* PAGE_SHIFT determines the page size */ |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 11 | #if defined(CONFIG_PAGE_SIZE_4KB) |
| 12 | # define PAGE_SHIFT 12 |
| 13 | #elif defined(CONFIG_PAGE_SIZE_8KB) |
| 14 | # define PAGE_SHIFT 13 |
| 15 | #elif defined(CONFIG_PAGE_SIZE_64KB) |
| 16 | # define PAGE_SHIFT 16 |
| 17 | #else |
| 18 | # error "Bogus kernel page size?" |
| 19 | #endif |
Paul Mundt | 8c12b5d | 2006-09-27 18:31:06 +0900 | [diff] [blame] | 20 | |
Stuart Menefy | d02b08f | 2007-11-30 17:52:53 +0900 | [diff] [blame] | 21 | #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #define PAGE_MASK (~(PAGE_SIZE-1)) |
| 23 | #define PTE_MASK PAGE_MASK |
| 24 | |
Stuart Menefy | d02b08f | 2007-11-30 17:52:53 +0900 | [diff] [blame] | 25 | /* to align the pointer to the (next) page boundary */ |
| 26 | #define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK) |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #if defined(CONFIG_HUGETLB_PAGE_SIZE_64K) |
| 29 | #define HPAGE_SHIFT 16 |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 30 | #elif defined(CONFIG_HUGETLB_PAGE_SIZE_256K) |
| 31 | #define HPAGE_SHIFT 18 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #elif defined(CONFIG_HUGETLB_PAGE_SIZE_1MB) |
| 33 | #define HPAGE_SHIFT 20 |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 34 | #elif defined(CONFIG_HUGETLB_PAGE_SIZE_4MB) |
| 35 | #define HPAGE_SHIFT 22 |
| 36 | #elif defined(CONFIG_HUGETLB_PAGE_SIZE_64MB) |
| 37 | #define HPAGE_SHIFT 26 |
Paul Mundt | caff44e | 2007-11-21 15:23:07 +0900 | [diff] [blame] | 38 | #elif defined(CONFIG_HUGETLB_PAGE_SIZE_512MB) |
| 39 | #define HPAGE_SHIFT 29 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #endif |
| 41 | |
| 42 | #ifdef CONFIG_HUGETLB_PAGE |
| 43 | #define HPAGE_SIZE (1UL << HPAGE_SHIFT) |
| 44 | #define HPAGE_MASK (~(HPAGE_SIZE-1)) |
| 45 | #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT-PAGE_SHIFT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #endif |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #ifndef __ASSEMBLY__ |
| 49 | |
Paul Mundt | f3c2575 | 2006-09-27 18:36:17 +0900 | [diff] [blame] | 50 | extern unsigned long shm_align_mask; |
Paul Mundt | 0106662 | 2007-03-28 16:38:13 +0900 | [diff] [blame] | 51 | extern unsigned long max_low_pfn, min_low_pfn; |
Paul Mundt | e08f457 | 2007-05-14 12:52:56 +0900 | [diff] [blame] | 52 | extern unsigned long memory_start, memory_end; |
Paul Mundt | f3c2575 | 2006-09-27 18:36:17 +0900 | [diff] [blame] | 53 | |
Paul Mundt | 379a95d | 2007-11-20 16:51:28 +0900 | [diff] [blame] | 54 | extern void clear_page(void *to); |
| 55 | extern void copy_page(void *to, void *from); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Paul Mundt | e7bd34a | 2007-07-31 17:07:28 +0900 | [diff] [blame] | 57 | #if !defined(CONFIG_CACHE_OFF) && defined(CONFIG_MMU) && \ |
Paul Mundt | 38350e0 | 2008-02-13 20:14:10 +0900 | [diff] [blame] | 58 | (defined(CONFIG_CPU_SH5) || defined(CONFIG_CPU_SH4) || \ |
| 59 | defined(CONFIG_SH7705_CACHE_32KB)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | struct page; |
Paul Mundt | 7747b9a | 2007-11-05 16:12:32 +0900 | [diff] [blame] | 61 | struct vm_area_struct; |
Paul Mundt | af39c16 | 2007-11-05 16:20:42 +0900 | [diff] [blame] | 62 | extern void clear_user_page(void *to, unsigned long address, struct page *page); |
Paul Mundt | 38350e0 | 2008-02-13 20:14:10 +0900 | [diff] [blame] | 63 | extern void copy_user_page(void *to, void *from, unsigned long address, |
| 64 | struct page *page); |
| 65 | #if defined(CONFIG_CPU_SH4) |
Paul Mundt | 7747b9a | 2007-11-05 16:12:32 +0900 | [diff] [blame] | 66 | extern void copy_user_highpage(struct page *to, struct page *from, |
| 67 | unsigned long vaddr, struct vm_area_struct *vma); |
| 68 | #define __HAVE_ARCH_COPY_USER_HIGHPAGE |
| 69 | #endif |
Paul Mundt | e7bd34a | 2007-07-31 17:07:28 +0900 | [diff] [blame] | 70 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define clear_user_page(page, vaddr, pg) clear_page(page) |
| 72 | #define copy_user_page(to, from, vaddr, pg) copy_page(to, from) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #endif |
| 74 | |
| 75 | /* |
| 76 | * These are used to make use of C type-checking.. |
| 77 | */ |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 78 | #ifdef CONFIG_X2TLB |
| 79 | typedef struct { unsigned long pte_low, pte_high; } pte_t; |
| 80 | typedef struct { unsigned long long pgprot; } pgprot_t; |
Paul Mundt | d04a0f7 | 2007-09-21 11:55:03 +0900 | [diff] [blame] | 81 | typedef struct { unsigned long long pgd; } pgd_t; |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 82 | #define pte_val(x) \ |
| 83 | ((x).pte_low | ((unsigned long long)(x).pte_high << 32)) |
| 84 | #define __pte(x) \ |
| 85 | ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; }) |
Paul Mundt | 249cfea | 2007-11-19 18:26:19 +0900 | [diff] [blame] | 86 | #elif defined(CONFIG_SUPERH32) |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 87 | typedef struct { unsigned long pte_low; } pte_t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | typedef struct { unsigned long pgprot; } pgprot_t; |
Paul Mundt | d04a0f7 | 2007-09-21 11:55:03 +0900 | [diff] [blame] | 89 | typedef struct { unsigned long pgd; } pgd_t; |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 90 | #define pte_val(x) ((x).pte_low) |
Paul Mundt | 249cfea | 2007-11-19 18:26:19 +0900 | [diff] [blame] | 91 | #define __pte(x) ((pte_t) { (x) } ) |
| 92 | #else |
| 93 | typedef struct { unsigned long long pte_low; } pte_t; |
| 94 | typedef struct { unsigned long pgprot; } pgprot_t; |
| 95 | typedef struct { unsigned long pgd; } pgd_t; |
| 96 | #define pte_val(x) ((x).pte_low) |
| 97 | #define __pte(x) ((pte_t) { (x) } ) |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 98 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | #define pgd_val(x) ((x).pgd) |
| 101 | #define pgprot_val(x) ((x).pgprot) |
| 102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | #define __pgd(x) ((pgd_t) { (x) } ) |
| 104 | #define __pgprot(x) ((pgprot_t) { (x) } ) |
| 105 | |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 106 | typedef struct page *pgtable_t; |
| 107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | #endif /* !__ASSEMBLY__ */ |
| 109 | |
Stuart Menefy | d02b08f | 2007-11-30 17:52:53 +0900 | [diff] [blame] | 110 | /* |
| 111 | * __MEMORY_START and SIZE are the physical addresses and size of RAM. |
| 112 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | #define __MEMORY_START CONFIG_MEMORY_START |
| 114 | #define __MEMORY_SIZE CONFIG_MEMORY_SIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
Stuart Menefy | d02b08f | 2007-11-30 17:52:53 +0900 | [diff] [blame] | 116 | /* |
| 117 | * PAGE_OFFSET is the virtual address of the start of kernel address |
| 118 | * space. |
| 119 | */ |
Paul Mundt | e7f93a3 | 2006-09-27 17:19:13 +0900 | [diff] [blame] | 120 | #define PAGE_OFFSET CONFIG_PAGE_OFFSET |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Stuart Menefy | d02b08f | 2007-11-30 17:52:53 +0900 | [diff] [blame] | 122 | /* |
| 123 | * Virtual to physical RAM address translation. |
| 124 | * |
| 125 | * In 29 bit mode, the physical offset of RAM from address 0 is visible in |
| 126 | * the kernel virtual address space, and thus we don't have to take |
| 127 | * this into account when translating. However in 32 bit mode this offset |
| 128 | * is not visible (it is part of the PMB mapping) and so needs to be |
| 129 | * added or subtracted as required. |
| 130 | */ |
| 131 | #ifdef CONFIG_32BIT |
| 132 | #define __pa(x) ((unsigned long)(x)-PAGE_OFFSET+__MEMORY_START) |
| 133 | #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET-__MEMORY_START)) |
| 134 | #else |
| 135 | #define __pa(x) ((unsigned long)(x)-PAGE_OFFSET) |
| 136 | #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET)) |
| 137 | #endif |
| 138 | |
| 139 | #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT) |
Paul Mundt | 0106662 | 2007-03-28 16:38:13 +0900 | [diff] [blame] | 140 | #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
Stuart Menefy | d02b08f | 2007-11-30 17:52:53 +0900 | [diff] [blame] | 142 | /* |
| 143 | * PFN = physical frame number (ie PFN 0 == physical address 0) |
| 144 | * PFN_START is the PFN of the first page of RAM. By defining this we |
| 145 | * don't have struct page entries for the portion of address space |
| 146 | * between physical address 0 and the start of RAM. |
| 147 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | #define PFN_START (__MEMORY_START >> PAGE_SHIFT) |
Alexey Dobriyan | 67bb2c6 | 2006-09-08 09:47:34 -0700 | [diff] [blame] | 149 | #define ARCH_PFN_OFFSET (PFN_START) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) |
Paul Mundt | 5900711 | 2007-05-23 17:40:56 +0900 | [diff] [blame] | 151 | #ifdef CONFIG_FLATMEM |
Paul Mundt | 0106662 | 2007-03-28 16:38:13 +0900 | [diff] [blame] | 152 | #define pfn_valid(pfn) ((pfn) >= min_low_pfn && (pfn) < max_low_pfn) |
Paul Mundt | 5900711 | 2007-05-23 17:40:56 +0900 | [diff] [blame] | 153 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) |
| 155 | |
| 156 | #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \ |
| 157 | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) |
| 158 | |
KAMEZAWA Hiroyuki | 104b8de | 2006-03-27 01:15:46 -0800 | [diff] [blame] | 159 | #include <asm-generic/memory_model.h> |
Stephen Rothwell | fd4fd5a | 2005-09-03 15:54:30 -0700 | [diff] [blame] | 160 | #include <asm-generic/page.h> |
| 161 | |
Paul Mundt | 19f9a34 | 2006-09-27 18:33:49 +0900 | [diff] [blame] | 162 | /* vDSO support */ |
| 163 | #ifdef CONFIG_VSYSCALL |
| 164 | #define __HAVE_ARCH_GATE_AREA |
| 165 | #endif |
| 166 | |
Paul Mundt | cbd2d9d | 2007-06-04 15:46:56 +0900 | [diff] [blame] | 167 | /* |
Paul Mundt | 66d485b | 2007-11-27 15:57:30 +0900 | [diff] [blame] | 168 | * Some drivers need to perform DMA into kmalloc'ed buffers |
| 169 | * and so we have to increase the kmalloc minalign for this. |
Paul Mundt | cbd2d9d | 2007-06-04 15:46:56 +0900 | [diff] [blame] | 170 | */ |
Paul Mundt | 66d485b | 2007-11-27 15:57:30 +0900 | [diff] [blame] | 171 | #define ARCH_KMALLOC_MINALIGN L1_CACHE_BYTES |
Paul Mundt | 01fed93 | 2007-11-10 19:57:58 +0900 | [diff] [blame] | 172 | |
Paul Mundt | 66d485b | 2007-11-27 15:57:30 +0900 | [diff] [blame] | 173 | #ifdef CONFIG_SUPERH64 |
Paul Mundt | 01fed93 | 2007-11-10 19:57:58 +0900 | [diff] [blame] | 174 | /* |
Paul Mundt | 66d485b | 2007-11-27 15:57:30 +0900 | [diff] [blame] | 175 | * While BYTES_PER_WORD == 4 on the current sh64 ABI, GCC will still |
| 176 | * happily generate {ld/st}.q pairs, requiring us to have 8-byte |
| 177 | * alignment to avoid traps. The kmalloc alignment is gauranteed by |
| 178 | * virtue of L1_CACHE_BYTES, requiring this to only be special cased |
| 179 | * for slab caches. |
Paul Mundt | 01fed93 | 2007-11-10 19:57:58 +0900 | [diff] [blame] | 180 | */ |
| 181 | #define ARCH_SLAB_MINALIGN 8 |
| 182 | #endif |
Paul Mundt | cbd2d9d | 2007-06-04 15:46:56 +0900 | [diff] [blame] | 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | #endif /* __ASM_SH_PAGE_H */ |