blob: e0fe02950f522b067d75bd8cf4f2d5ecbfeaf41c [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
15#elif defined(CONFIG_PAGE_SIZE_64KB)
16# define PAGE_SHIFT 16
17#else
18# error "Bogus kernel page size?"
19#endif
Paul Mundt8c12b5d2006-09-27 18:31:06 +090020
Stuart Menefyd02b08f2007-11-30 17:52:53 +090021#define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#define PAGE_MASK (~(PAGE_SIZE-1))
23#define PTE_MASK PAGE_MASK
24
Stuart Menefyd02b08f2007-11-30 17:52:53 +090025/* to align the pointer to the (next) page boundary */
26#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#if defined(CONFIG_HUGETLB_PAGE_SIZE_64K)
29#define HPAGE_SHIFT 16
Paul Mundt21440cf2006-11-20 14:30:26 +090030#elif defined(CONFIG_HUGETLB_PAGE_SIZE_256K)
31#define HPAGE_SHIFT 18
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#elif defined(CONFIG_HUGETLB_PAGE_SIZE_1MB)
33#define HPAGE_SHIFT 20
Paul Mundt21440cf2006-11-20 14:30:26 +090034#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 Mundtcaff44e2007-11-21 15:23:07 +090038#elif defined(CONFIG_HUGETLB_PAGE_SIZE_512MB)
39#define HPAGE_SHIFT 29
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#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 Torvalds1da177e2005-04-16 15:20:36 -070046#endif
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#ifndef __ASSEMBLY__
49
Paul Mundtf3c25752006-09-27 18:36:17 +090050extern unsigned long shm_align_mask;
Paul Mundt01066622007-03-28 16:38:13 +090051extern unsigned long max_low_pfn, min_low_pfn;
Paul Mundte08f4572007-05-14 12:52:56 +090052extern unsigned long memory_start, memory_end;
Paul Mundtf3c25752006-09-27 18:36:17 +090053
Paul Mundt379a95d2007-11-20 16:51:28 +090054extern void clear_page(void *to);
55extern void copy_page(void *to, void *from);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Paul Mundte7bd34a2007-07-31 17:07:28 +090057#if !defined(CONFIG_CACHE_OFF) && defined(CONFIG_MMU) && \
58 (defined(CONFIG_CPU_SH4) || defined(CONFIG_SH7705_CACHE_32KB))
Linus Torvalds1da177e2005-04-16 15:20:36 -070059struct page;
Paul Mundt7747b9a2007-11-05 16:12:32 +090060struct vm_area_struct;
Paul Mundtaf39c162007-11-05 16:20:42 +090061extern void clear_user_page(void *to, unsigned long address, struct page *page);
Paul Mundt7747b9a2007-11-05 16:12:32 +090062#ifdef CONFIG_CPU_SH4
63extern void copy_user_highpage(struct page *to, struct page *from,
64 unsigned long vaddr, struct vm_area_struct *vma);
65#define __HAVE_ARCH_COPY_USER_HIGHPAGE
66#endif
Paul Mundte7bd34a2007-07-31 17:07:28 +090067#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#define clear_user_page(page, vaddr, pg) clear_page(page)
69#define copy_user_page(to, from, vaddr, pg) copy_page(to, from)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#endif
71
72/*
73 * These are used to make use of C type-checking..
74 */
Paul Mundt21440cf2006-11-20 14:30:26 +090075#ifdef CONFIG_X2TLB
76typedef struct { unsigned long pte_low, pte_high; } pte_t;
77typedef struct { unsigned long long pgprot; } pgprot_t;
Paul Mundtd04a0f72007-09-21 11:55:03 +090078typedef struct { unsigned long long pgd; } pgd_t;
Paul Mundt21440cf2006-11-20 14:30:26 +090079#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 Mundt249cfea2007-11-19 18:26:19 +090083#elif defined(CONFIG_SUPERH32)
Paul Mundt21440cf2006-11-20 14:30:26 +090084typedef struct { unsigned long pte_low; } pte_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085typedef struct { unsigned long pgprot; } pgprot_t;
Paul Mundtd04a0f72007-09-21 11:55:03 +090086typedef struct { unsigned long pgd; } pgd_t;
Paul Mundt21440cf2006-11-20 14:30:26 +090087#define pte_val(x) ((x).pte_low)
Paul Mundt249cfea2007-11-19 18:26:19 +090088#define __pte(x) ((pte_t) { (x) } )
89#else
90typedef struct { unsigned long long pte_low; } pte_t;
91typedef struct { unsigned long pgprot; } pgprot_t;
92typedef struct { unsigned long pgd; } pgd_t;
93#define pte_val(x) ((x).pte_low)
94#define __pte(x) ((pte_t) { (x) } )
Paul Mundt21440cf2006-11-20 14:30:26 +090095#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Linus Torvalds1da177e2005-04-16 15:20:36 -070097#define pgd_val(x) ((x).pgd)
98#define pgprot_val(x) ((x).pgprot)
99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100#define __pgd(x) ((pgd_t) { (x) } )
101#define __pgprot(x) ((pgprot_t) { (x) } )
102
103#endif /* !__ASSEMBLY__ */
104
Stuart Menefyd02b08f2007-11-30 17:52:53 +0900105/*
106 * __MEMORY_START and SIZE are the physical addresses and size of RAM.
107 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108#define __MEMORY_START CONFIG_MEMORY_START
109#define __MEMORY_SIZE CONFIG_MEMORY_SIZE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Stuart Menefyd02b08f2007-11-30 17:52:53 +0900111/*
112 * PAGE_OFFSET is the virtual address of the start of kernel address
113 * space.
114 */
Paul Mundte7f93a32006-09-27 17:19:13 +0900115#define PAGE_OFFSET CONFIG_PAGE_OFFSET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Stuart Menefyd02b08f2007-11-30 17:52:53 +0900117/*
118 * Virtual to physical RAM address translation.
119 *
120 * In 29 bit mode, the physical offset of RAM from address 0 is visible in
121 * the kernel virtual address space, and thus we don't have to take
122 * this into account when translating. However in 32 bit mode this offset
123 * is not visible (it is part of the PMB mapping) and so needs to be
124 * added or subtracted as required.
125 */
126#ifdef CONFIG_32BIT
127#define __pa(x) ((unsigned long)(x)-PAGE_OFFSET+__MEMORY_START)
128#define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET-__MEMORY_START))
129#else
130#define __pa(x) ((unsigned long)(x)-PAGE_OFFSET)
131#define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
132#endif
133
134#define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
Paul Mundt01066622007-03-28 16:38:13 +0900135#define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Stuart Menefyd02b08f2007-11-30 17:52:53 +0900137/*
138 * PFN = physical frame number (ie PFN 0 == physical address 0)
139 * PFN_START is the PFN of the first page of RAM. By defining this we
140 * don't have struct page entries for the portion of address space
141 * between physical address 0 and the start of RAM.
142 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143#define PFN_START (__MEMORY_START >> PAGE_SHIFT)
Alexey Dobriyan67bb2c692006-09-08 09:47:34 -0700144#define ARCH_PFN_OFFSET (PFN_START)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
Paul Mundt59007112007-05-23 17:40:56 +0900146#ifdef CONFIG_FLATMEM
Paul Mundt01066622007-03-28 16:38:13 +0900147#define pfn_valid(pfn) ((pfn) >= min_low_pfn && (pfn) < max_low_pfn)
Paul Mundt59007112007-05-23 17:40:56 +0900148#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
150
151#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
152 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
153
KAMEZAWA Hiroyuki104b8de2006-03-27 01:15:46 -0800154#include <asm-generic/memory_model.h>
Stephen Rothwellfd4fd5a2005-09-03 15:54:30 -0700155#include <asm-generic/page.h>
156
Paul Mundt19f9a342006-09-27 18:33:49 +0900157/* vDSO support */
158#ifdef CONFIG_VSYSCALL
159#define __HAVE_ARCH_GATE_AREA
160#endif
161
Paul Mundtcbd2d9d2007-06-04 15:46:56 +0900162/*
Paul Mundt66d485b2007-11-27 15:57:30 +0900163 * Some drivers need to perform DMA into kmalloc'ed buffers
164 * and so we have to increase the kmalloc minalign for this.
Paul Mundtcbd2d9d2007-06-04 15:46:56 +0900165 */
Paul Mundt66d485b2007-11-27 15:57:30 +0900166#define ARCH_KMALLOC_MINALIGN L1_CACHE_BYTES
Paul Mundt01fed932007-11-10 19:57:58 +0900167
Paul Mundt66d485b2007-11-27 15:57:30 +0900168#ifdef CONFIG_SUPERH64
Paul Mundt01fed932007-11-10 19:57:58 +0900169/*
Paul Mundt66d485b2007-11-27 15:57:30 +0900170 * While BYTES_PER_WORD == 4 on the current sh64 ABI, GCC will still
171 * happily generate {ld/st}.q pairs, requiring us to have 8-byte
172 * alignment to avoid traps. The kmalloc alignment is gauranteed by
173 * virtue of L1_CACHE_BYTES, requiring this to only be special cased
174 * for slab caches.
Paul Mundt01fed932007-11-10 19:57:58 +0900175 */
176#define ARCH_SLAB_MINALIGN 8
177#endif
Paul Mundtcbd2d9d2007-06-04 15:46:56 +0900178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179#endif /* __ASM_SH_PAGE_H */