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 |
Paul Mundt | 66dfe18 | 2008-06-03 18:54:02 +0900 | [diff] [blame] | 15 | #elif defined(CONFIG_PAGE_SIZE_16KB) |
| 16 | # define PAGE_SHIFT 14 |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 17 | #elif defined(CONFIG_PAGE_SIZE_64KB) |
| 18 | # define PAGE_SHIFT 16 |
| 19 | #else |
| 20 | # error "Bogus kernel page size?" |
| 21 | #endif |
Paul Mundt | 8c12b5d | 2006-09-27 18:31:06 +0900 | [diff] [blame] | 22 | |
Stuart Menefy | d02b08f | 2007-11-30 17:52:53 +0900 | [diff] [blame] | 23 | #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #define PAGE_MASK (~(PAGE_SIZE-1)) |
| 25 | #define PTE_MASK PAGE_MASK |
| 26 | |
| 27 | #if defined(CONFIG_HUGETLB_PAGE_SIZE_64K) |
| 28 | #define HPAGE_SHIFT 16 |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 29 | #elif defined(CONFIG_HUGETLB_PAGE_SIZE_256K) |
| 30 | #define HPAGE_SHIFT 18 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #elif defined(CONFIG_HUGETLB_PAGE_SIZE_1MB) |
| 32 | #define HPAGE_SHIFT 20 |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 33 | #elif defined(CONFIG_HUGETLB_PAGE_SIZE_4MB) |
| 34 | #define HPAGE_SHIFT 22 |
| 35 | #elif defined(CONFIG_HUGETLB_PAGE_SIZE_64MB) |
| 36 | #define HPAGE_SHIFT 26 |
Paul Mundt | caff44e | 2007-11-21 15:23:07 +0900 | [diff] [blame] | 37 | #elif defined(CONFIG_HUGETLB_PAGE_SIZE_512MB) |
| 38 | #define HPAGE_SHIFT 29 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #endif |
| 40 | |
| 41 | #ifdef CONFIG_HUGETLB_PAGE |
| 42 | #define HPAGE_SIZE (1UL << HPAGE_SHIFT) |
| 43 | #define HPAGE_MASK (~(HPAGE_SIZE-1)) |
| 44 | #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT-PAGE_SHIFT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #endif |
| 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #ifndef __ASSEMBLY__ |
Paul Mundt | d01447b | 2010-02-18 18:13:51 +0900 | [diff] [blame] | 48 | #include <asm/uncached.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | 5e2ff32 | 2010-05-10 20:17:25 +0900 | [diff] [blame] | 52 | extern unsigned long memory_start, memory_end, memory_limit; |
Paul Mundt | f3c2575 | 2006-09-27 18:36:17 +0900 | [diff] [blame] | 53 | |
Paul Mundt | 2277ab4 | 2009-07-22 19:20:49 +0900 | [diff] [blame] | 54 | static inline unsigned long |
| 55 | pages_do_alias(unsigned long addr1, unsigned long addr2) |
| 56 | { |
| 57 | return (addr1 ^ addr2) & shm_align_mask; |
| 58 | } |
| 59 | |
Paul Mundt | dfff0fa | 2009-07-27 20:53:22 +0900 | [diff] [blame] | 60 | #define clear_page(page) memset((void *)(page), 0, PAGE_SIZE) |
Paul Mundt | 379a95d | 2007-11-20 16:51:28 +0900 | [diff] [blame] | 61 | extern void copy_page(void *to, void *from); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Paul Mundt | dfff0fa | 2009-07-27 20:53:22 +0900 | [diff] [blame] | 63 | struct page; |
| 64 | struct vm_area_struct; |
| 65 | |
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 |
Paul Mundt | dfff0fa | 2009-07-27 20:53:22 +0900 | [diff] [blame] | 69 | extern void clear_user_highpage(struct page *page, unsigned long vaddr); |
| 70 | #define clear_user_highpage clear_user_highpage |
Paul Mundt | 0dfae7d | 2009-07-27 21:30:17 +0900 | [diff] [blame] | 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | /* |
| 73 | * These are used to make use of C type-checking.. |
| 74 | */ |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 75 | #ifdef CONFIG_X2TLB |
| 76 | typedef struct { unsigned long pte_low, pte_high; } pte_t; |
| 77 | typedef struct { unsigned long long pgprot; } pgprot_t; |
Paul Mundt | d04a0f7 | 2007-09-21 11:55:03 +0900 | [diff] [blame] | 78 | typedef struct { unsigned long long pgd; } pgd_t; |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 79 | #define pte_val(x) \ |
| 80 | ((x).pte_low | ((unsigned long long)(x).pte_high << 32)) |
| 81 | #define __pte(x) \ |
| 82 | ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; }) |
Paul Mundt | 249cfea | 2007-11-19 18:26:19 +0900 | [diff] [blame] | 83 | #elif defined(CONFIG_SUPERH32) |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 84 | typedef struct { unsigned long pte_low; } pte_t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | typedef struct { unsigned long pgprot; } pgprot_t; |
Paul Mundt | d04a0f7 | 2007-09-21 11:55:03 +0900 | [diff] [blame] | 86 | typedef struct { unsigned long pgd; } pgd_t; |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 87 | #define pte_val(x) ((x).pte_low) |
Paul Mundt | 249cfea | 2007-11-19 18:26:19 +0900 | [diff] [blame] | 88 | #define __pte(x) ((pte_t) { (x) } ) |
| 89 | #else |
| 90 | typedef struct { unsigned long long pte_low; } pte_t; |
Matt Fleming | 24ef7fc | 2009-11-19 21:11:05 +0000 | [diff] [blame] | 91 | typedef struct { unsigned long long pgprot; } pgprot_t; |
Paul Mundt | 249cfea | 2007-11-19 18:26:19 +0900 | [diff] [blame] | 92 | typedef struct { unsigned long pgd; } pgd_t; |
| 93 | #define pte_val(x) ((x).pte_low) |
| 94 | #define __pte(x) ((pte_t) { (x) } ) |
Paul Mundt | 21440cf | 2006-11-20 14:30:26 +0900 | [diff] [blame] | 95 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | #define pgd_val(x) ((x).pgd) |
| 98 | #define pgprot_val(x) ((x).pgprot) |
| 99 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | #define __pgd(x) ((pgd_t) { (x) } ) |
| 101 | #define __pgprot(x) ((pgprot_t) { (x) } ) |
| 102 | |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 103 | typedef struct page *pgtable_t; |
| 104 | |
Paul Mundt | cb700aa | 2008-09-12 20:41:05 +0900 | [diff] [blame] | 105 | #define pte_pgprot(x) __pgprot(pte_val(x) & PTE_FLAGS_MASK) |
| 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | #endif /* !__ASSEMBLY__ */ |
| 108 | |
Stuart Menefy | d02b08f | 2007-11-30 17:52:53 +0900 | [diff] [blame] | 109 | /* |
| 110 | * __MEMORY_START and SIZE are the physical addresses and size of RAM. |
| 111 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | #define __MEMORY_START CONFIG_MEMORY_START |
| 113 | #define __MEMORY_SIZE CONFIG_MEMORY_SIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Stuart Menefy | d02b08f | 2007-11-30 17:52:53 +0900 | [diff] [blame] | 115 | /* |
Simon Horman | e66ac3f | 2011-09-15 20:13:00 +0900 | [diff] [blame] | 116 | * PHYSICAL_OFFSET is the offset in physical memory where the base |
| 117 | * of the kernel is loaded. |
| 118 | */ |
| 119 | #ifdef CONFIG_PHYSICAL_START |
| 120 | #define PHYSICAL_OFFSET (CONFIG_PHYSICAL_START - __MEMORY_START) |
| 121 | #else |
| 122 | #define PHYSICAL_OFFSET 0 |
| 123 | #endif |
| 124 | |
| 125 | /* |
Stuart Menefy | d02b08f | 2007-11-30 17:52:53 +0900 | [diff] [blame] | 126 | * PAGE_OFFSET is the virtual address of the start of kernel address |
| 127 | * space. |
| 128 | */ |
Paul Mundt | e7f93a3 | 2006-09-27 17:19:13 +0900 | [diff] [blame] | 129 | #define PAGE_OFFSET CONFIG_PAGE_OFFSET |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
Stuart Menefy | d02b08f | 2007-11-30 17:52:53 +0900 | [diff] [blame] | 131 | /* |
| 132 | * Virtual to physical RAM address translation. |
| 133 | * |
| 134 | * In 29 bit mode, the physical offset of RAM from address 0 is visible in |
| 135 | * the kernel virtual address space, and thus we don't have to take |
| 136 | * this into account when translating. However in 32 bit mode this offset |
| 137 | * is not visible (it is part of the PMB mapping) and so needs to be |
| 138 | * added or subtracted as required. |
| 139 | */ |
Paul Mundt | 1d5cfcd | 2010-02-16 21:43:38 +0900 | [diff] [blame] | 140 | #ifdef CONFIG_PMB |
Matt Fleming | 7c4584d | 2010-04-24 11:12:12 +0100 | [diff] [blame] | 141 | #define ___pa(x) ((x)-PAGE_OFFSET+__MEMORY_START) |
| 142 | #define ___va(x) ((x)+PAGE_OFFSET-__MEMORY_START) |
Stuart Menefy | d02b08f | 2007-11-30 17:52:53 +0900 | [diff] [blame] | 143 | #else |
Matt Fleming | 7c4584d | 2010-04-24 11:12:12 +0100 | [diff] [blame] | 144 | #define ___pa(x) ((x)-PAGE_OFFSET) |
| 145 | #define ___va(x) ((x)+PAGE_OFFSET) |
Stuart Menefy | d02b08f | 2007-11-30 17:52:53 +0900 | [diff] [blame] | 146 | #endif |
| 147 | |
Matt Fleming | 7c4584d | 2010-04-24 11:12:12 +0100 | [diff] [blame] | 148 | #ifndef __ASSEMBLY__ |
| 149 | #define __pa(x) ___pa((unsigned long)x) |
| 150 | #define __va(x) (void *)___va((unsigned long)x) |
| 151 | #endif /* !__ASSEMBLY__ */ |
| 152 | |
Paul Mundt | 9edef28 | 2010-02-17 16:28:00 +0900 | [diff] [blame] | 153 | #ifdef CONFIG_UNCACHED_MAPPING |
Nobuhiro Iwamatsu | dfd3b59 | 2011-11-04 22:13:50 +0900 | [diff] [blame] | 154 | #if defined(CONFIG_29BIT) |
| 155 | #define UNCAC_ADDR(addr) P2SEGADDR(addr) |
| 156 | #define CAC_ADDR(addr) P1SEGADDR(addr) |
| 157 | #else |
Paul Mundt | 9edef28 | 2010-02-17 16:28:00 +0900 | [diff] [blame] | 158 | #define UNCAC_ADDR(addr) ((addr) - PAGE_OFFSET + uncached_start) |
| 159 | #define CAC_ADDR(addr) ((addr) - uncached_start + PAGE_OFFSET) |
Nobuhiro Iwamatsu | dfd3b59 | 2011-11-04 22:13:50 +0900 | [diff] [blame] | 160 | #endif |
Paul Mundt | 9edef28 | 2010-02-17 16:28:00 +0900 | [diff] [blame] | 161 | #else |
| 162 | #define UNCAC_ADDR(addr) ((addr)) |
| 163 | #define CAC_ADDR(addr) ((addr)) |
| 164 | #endif |
| 165 | |
Stuart Menefy | d02b08f | 2007-11-30 17:52:53 +0900 | [diff] [blame] | 166 | #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT) |
Paul Mundt | 0106662 | 2007-03-28 16:38:13 +0900 | [diff] [blame] | 167 | #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
Stuart Menefy | d02b08f | 2007-11-30 17:52:53 +0900 | [diff] [blame] | 169 | /* |
| 170 | * PFN = physical frame number (ie PFN 0 == physical address 0) |
| 171 | * PFN_START is the PFN of the first page of RAM. By defining this we |
| 172 | * don't have struct page entries for the portion of address space |
| 173 | * between physical address 0 and the start of RAM. |
| 174 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | #define PFN_START (__MEMORY_START >> PAGE_SHIFT) |
Alexey Dobriyan | 67bb2c6 | 2006-09-08 09:47:34 -0700 | [diff] [blame] | 176 | #define ARCH_PFN_OFFSET (PFN_START) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) |
Paul Mundt | 5900711 | 2007-05-23 17:40:56 +0900 | [diff] [blame] | 178 | #ifdef CONFIG_FLATMEM |
Paul Mundt | 0106662 | 2007-03-28 16:38:13 +0900 | [diff] [blame] | 179 | #define pfn_valid(pfn) ((pfn) >= min_low_pfn && (pfn) < max_low_pfn) |
Paul Mundt | 5900711 | 2007-05-23 17:40:56 +0900 | [diff] [blame] | 180 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) |
| 182 | |
| 183 | #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \ |
| 184 | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) |
| 185 | |
KAMEZAWA Hiroyuki | 104b8de | 2006-03-27 01:15:46 -0800 | [diff] [blame] | 186 | #include <asm-generic/memory_model.h> |
Arnd Bergmann | 5b17e1c | 2009-05-13 22:56:30 +0000 | [diff] [blame] | 187 | #include <asm-generic/getorder.h> |
Stephen Rothwell | fd4fd5a | 2005-09-03 15:54:30 -0700 | [diff] [blame] | 188 | |
Paul Mundt | cbd2d9d | 2007-06-04 15:46:56 +0900 | [diff] [blame] | 189 | /* |
Paul Mundt | 66d485b | 2007-11-27 15:57:30 +0900 | [diff] [blame] | 190 | * Some drivers need to perform DMA into kmalloc'ed buffers |
| 191 | * and so we have to increase the kmalloc minalign for this. |
Paul Mundt | cbd2d9d | 2007-06-04 15:46:56 +0900 | [diff] [blame] | 192 | */ |
FUJITA Tomonori | a6eb9fe | 2010-08-10 18:03:22 -0700 | [diff] [blame] | 193 | #define ARCH_DMA_MINALIGN L1_CACHE_BYTES |
Paul Mundt | 01fed93 | 2007-11-10 19:57:58 +0900 | [diff] [blame] | 194 | |
Paul Mundt | 66d485b | 2007-11-27 15:57:30 +0900 | [diff] [blame] | 195 | #ifdef CONFIG_SUPERH64 |
Paul Mundt | 01fed93 | 2007-11-10 19:57:58 +0900 | [diff] [blame] | 196 | /* |
Paul Mundt | 66d485b | 2007-11-27 15:57:30 +0900 | [diff] [blame] | 197 | * While BYTES_PER_WORD == 4 on the current sh64 ABI, GCC will still |
| 198 | * happily generate {ld/st}.q pairs, requiring us to have 8-byte |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 199 | * alignment to avoid traps. The kmalloc alignment is guaranteed by |
Paul Mundt | 66d485b | 2007-11-27 15:57:30 +0900 | [diff] [blame] | 200 | * virtue of L1_CACHE_BYTES, requiring this to only be special cased |
| 201 | * for slab caches. |
Paul Mundt | 01fed93 | 2007-11-10 19:57:58 +0900 | [diff] [blame] | 202 | */ |
| 203 | #define ARCH_SLAB_MINALIGN 8 |
| 204 | #endif |
Paul Mundt | cbd2d9d | 2007-06-04 15:46:56 +0900 | [diff] [blame] | 205 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | #endif /* __ASM_SH_PAGE_H */ |