blob: 847eeabb9083fec300504cc7d14c0bbc0b1553a7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __ASM_SH_PAGE_H
2#define __ASM_SH_PAGE_H
3
4/*
5 * Copyright (C) 1999 Niibe Yutaka
6 */
7
Stuart Menefyd02b08f2007-11-30 17:52:53 +09008#include <linux/const.h>
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010/* PAGE_SHIFT determines the page size */
Paul Mundt21440cf2006-11-20 14:30:26 +090011#if defined(CONFIG_PAGE_SIZE_4KB)
12# define PAGE_SHIFT 12
13#elif defined(CONFIG_PAGE_SIZE_8KB)
14# define PAGE_SHIFT 13
Paul Mundt66dfe182008-06-03 18:54:02 +090015#elif defined(CONFIG_PAGE_SIZE_16KB)
16# define PAGE_SHIFT 14
Paul Mundt21440cf2006-11-20 14:30:26 +090017#elif defined(CONFIG_PAGE_SIZE_64KB)
18# define PAGE_SHIFT 16
19#else
20# error "Bogus kernel page size?"
21#endif
Paul Mundt8c12b5d2006-09-27 18:31:06 +090022
Stuart Menefyd02b08f2007-11-30 17:52:53 +090023#define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#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 Mundt21440cf2006-11-20 14:30:26 +090029#elif defined(CONFIG_HUGETLB_PAGE_SIZE_256K)
30#define HPAGE_SHIFT 18
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#elif defined(CONFIG_HUGETLB_PAGE_SIZE_1MB)
32#define HPAGE_SHIFT 20
Paul Mundt21440cf2006-11-20 14:30:26 +090033#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 Mundtcaff44e2007-11-21 15:23:07 +090037#elif defined(CONFIG_HUGETLB_PAGE_SIZE_512MB)
38#define HPAGE_SHIFT 29
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#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 Torvalds1da177e2005-04-16 15:20:36 -070045#endif
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#ifndef __ASSEMBLY__
48
Paul Mundtf3c25752006-09-27 18:36:17 +090049extern unsigned long shm_align_mask;
Paul Mundt01066622007-03-28 16:38:13 +090050extern unsigned long max_low_pfn, min_low_pfn;
Paul Mundte08f4572007-05-14 12:52:56 +090051extern unsigned long memory_start, memory_end;
Paul Mundtf3c25752006-09-27 18:36:17 +090052
Paul Mundt2277ab42009-07-22 19:20:49 +090053static inline unsigned long
54pages_do_alias(unsigned long addr1, unsigned long addr2)
55{
56 return (addr1 ^ addr2) & shm_align_mask;
57}
58
Paul Mundtdfff0fa2009-07-27 20:53:22 +090059
60#define clear_page(page) memset((void *)(page), 0, PAGE_SIZE)
Paul Mundt379a95d2007-11-20 16:51:28 +090061extern void copy_page(void *to, void *from);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Paul Mundtdfff0fa2009-07-27 20:53:22 +090063struct page;
64struct vm_area_struct;
65
Paul Mundt0dfae7d2009-07-27 21:30:17 +090066#if defined(CONFIG_CPU_SH5)
Paul Mundtaf39c162007-11-05 16:20:42 +090067extern void clear_user_page(void *to, unsigned long address, struct page *page);
Paul Mundt38350e02008-02-13 20:14:10 +090068extern void copy_user_page(void *to, void *from, unsigned long address,
69 struct page *page);
Paul Mundt0dfae7d2009-07-27 21:30:17 +090070
71#elif defined(CONFIG_MMU)
Paul Mundt7747b9a2007-11-05 16:12:32 +090072extern void copy_user_highpage(struct page *to, struct page *from,
73 unsigned long vaddr, struct vm_area_struct *vma);
74#define __HAVE_ARCH_COPY_USER_HIGHPAGE
Paul Mundtdfff0fa2009-07-27 20:53:22 +090075extern void clear_user_highpage(struct page *page, unsigned long vaddr);
76#define clear_user_highpage clear_user_highpage
Paul Mundt0dfae7d2009-07-27 21:30:17 +090077
Paul Mundte7bd34a2007-07-31 17:07:28 +090078#else
Paul Mundt0dfae7d2009-07-27 21:30:17 +090079
Linus Torvalds1da177e2005-04-16 15:20:36 -070080#define clear_user_page(page, vaddr, pg) clear_page(page)
81#define copy_user_page(to, from, vaddr, pg) copy_page(to, from)
Paul Mundt0dfae7d2009-07-27 21:30:17 +090082
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#endif
84
85/*
86 * These are used to make use of C type-checking..
87 */
Paul Mundt21440cf2006-11-20 14:30:26 +090088#ifdef CONFIG_X2TLB
89typedef struct { unsigned long pte_low, pte_high; } pte_t;
90typedef struct { unsigned long long pgprot; } pgprot_t;
Paul Mundtd04a0f72007-09-21 11:55:03 +090091typedef struct { unsigned long long pgd; } pgd_t;
Paul Mundt21440cf2006-11-20 14:30:26 +090092#define pte_val(x) \
93 ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
94#define __pte(x) \
95 ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
Paul Mundt249cfea2007-11-19 18:26:19 +090096#elif defined(CONFIG_SUPERH32)
Paul Mundt21440cf2006-11-20 14:30:26 +090097typedef struct { unsigned long pte_low; } pte_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098typedef struct { unsigned long pgprot; } pgprot_t;
Paul Mundtd04a0f72007-09-21 11:55:03 +090099typedef struct { unsigned long pgd; } pgd_t;
Paul Mundt21440cf2006-11-20 14:30:26 +0900100#define pte_val(x) ((x).pte_low)
Paul Mundt249cfea2007-11-19 18:26:19 +0900101#define __pte(x) ((pte_t) { (x) } )
102#else
103typedef struct { unsigned long long pte_low; } pte_t;
104typedef struct { unsigned long pgprot; } pgprot_t;
105typedef struct { unsigned long pgd; } pgd_t;
106#define pte_val(x) ((x).pte_low)
107#define __pte(x) ((pte_t) { (x) } )
Paul Mundt21440cf2006-11-20 14:30:26 +0900108#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110#define pgd_val(x) ((x).pgd)
111#define pgprot_val(x) ((x).pgprot)
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113#define __pgd(x) ((pgd_t) { (x) } )
114#define __pgprot(x) ((pgprot_t) { (x) } )
115
Martin Schwidefsky2f569af2008-02-08 04:22:04 -0800116typedef struct page *pgtable_t;
117
Paul Mundtcb700aa2008-09-12 20:41:05 +0900118#define pte_pgprot(x) __pgprot(pte_val(x) & PTE_FLAGS_MASK)
119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120#endif /* !__ASSEMBLY__ */
121
Stuart Menefyd02b08f2007-11-30 17:52:53 +0900122/*
123 * __MEMORY_START and SIZE are the physical addresses and size of RAM.
124 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125#define __MEMORY_START CONFIG_MEMORY_START
126#define __MEMORY_SIZE CONFIG_MEMORY_SIZE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Stuart Menefyd02b08f2007-11-30 17:52:53 +0900128/*
129 * PAGE_OFFSET is the virtual address of the start of kernel address
130 * space.
131 */
Paul Mundte7f93a32006-09-27 17:19:13 +0900132#define PAGE_OFFSET CONFIG_PAGE_OFFSET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Stuart Menefyd02b08f2007-11-30 17:52:53 +0900134/*
135 * Virtual to physical RAM address translation.
136 *
137 * In 29 bit mode, the physical offset of RAM from address 0 is visible in
138 * the kernel virtual address space, and thus we don't have to take
139 * this into account when translating. However in 32 bit mode this offset
140 * is not visible (it is part of the PMB mapping) and so needs to be
141 * added or subtracted as required.
142 */
Yoshihiro Shimoda2f47f442009-03-10 15:49:54 +0900143#if defined(CONFIG_PMB_FIXED)
144/* phys = virt - PAGE_OFFSET - (__MEMORY_START & 0xe0000000) */
145#define PMB_OFFSET (PAGE_OFFSET - PXSEG(__MEMORY_START))
146#define __pa(x) ((unsigned long)(x) - PMB_OFFSET)
147#define __va(x) ((void *)((unsigned long)(x) + PMB_OFFSET))
148#elif defined(CONFIG_32BIT)
Stuart Menefyd02b08f2007-11-30 17:52:53 +0900149#define __pa(x) ((unsigned long)(x)-PAGE_OFFSET+__MEMORY_START)
150#define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET-__MEMORY_START))
151#else
152#define __pa(x) ((unsigned long)(x)-PAGE_OFFSET)
153#define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
154#endif
155
156#define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
Paul Mundt01066622007-03-28 16:38:13 +0900157#define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Stuart Menefyd02b08f2007-11-30 17:52:53 +0900159/*
160 * PFN = physical frame number (ie PFN 0 == physical address 0)
161 * PFN_START is the PFN of the first page of RAM. By defining this we
162 * don't have struct page entries for the portion of address space
163 * between physical address 0 and the start of RAM.
164 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165#define PFN_START (__MEMORY_START >> PAGE_SHIFT)
Alexey Dobriyan67bb2c62006-09-08 09:47:34 -0700166#define ARCH_PFN_OFFSET (PFN_START)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
Paul Mundt59007112007-05-23 17:40:56 +0900168#ifdef CONFIG_FLATMEM
Paul Mundt01066622007-03-28 16:38:13 +0900169#define pfn_valid(pfn) ((pfn) >= min_low_pfn && (pfn) < max_low_pfn)
Paul Mundt59007112007-05-23 17:40:56 +0900170#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
172
173#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
174 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
175
KAMEZAWA Hiroyuki104b8de2006-03-27 01:15:46 -0800176#include <asm-generic/memory_model.h>
Arnd Bergmann5b17e1c2009-05-13 22:56:30 +0000177#include <asm-generic/getorder.h>
Stephen Rothwellfd4fd5a2005-09-03 15:54:30 -0700178
Paul Mundt19f9a342006-09-27 18:33:49 +0900179/* vDSO support */
180#ifdef CONFIG_VSYSCALL
181#define __HAVE_ARCH_GATE_AREA
182#endif
183
Paul Mundtcbd2d9d2007-06-04 15:46:56 +0900184/*
Paul Mundt66d485b2007-11-27 15:57:30 +0900185 * Some drivers need to perform DMA into kmalloc'ed buffers
186 * and so we have to increase the kmalloc minalign for this.
Paul Mundtcbd2d9d2007-06-04 15:46:56 +0900187 */
Paul Mundt66d485b2007-11-27 15:57:30 +0900188#define ARCH_KMALLOC_MINALIGN L1_CACHE_BYTES
Paul Mundt01fed932007-11-10 19:57:58 +0900189
Paul Mundt66d485b2007-11-27 15:57:30 +0900190#ifdef CONFIG_SUPERH64
Paul Mundt01fed932007-11-10 19:57:58 +0900191/*
Paul Mundt66d485b2007-11-27 15:57:30 +0900192 * While BYTES_PER_WORD == 4 on the current sh64 ABI, GCC will still
193 * happily generate {ld/st}.q pairs, requiring us to have 8-byte
194 * alignment to avoid traps. The kmalloc alignment is gauranteed by
195 * virtue of L1_CACHE_BYTES, requiring this to only be special cased
196 * for slab caches.
Paul Mundt01fed932007-11-10 19:57:58 +0900197 */
198#define ARCH_SLAB_MINALIGN 8
199#endif
Paul Mundtcbd2d9d2007-06-04 15:46:56 +0900200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201#endif /* __ASM_SH_PAGE_H */