page.h 5.6 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
#ifndef __ASM_SH_PAGE_H
#define __ASM_SH_PAGE_H

/*
 * Copyright (C) 1999  Niibe Yutaka
 */

8 9
#include <linux/const.h>

L
Linus Torvalds 已提交
10
/* PAGE_SHIFT determines the page size */
11 12 13 14
#if defined(CONFIG_PAGE_SIZE_4KB)
# define PAGE_SHIFT	12
#elif defined(CONFIG_PAGE_SIZE_8KB)
# define PAGE_SHIFT	13
P
Paul Mundt 已提交
15 16
#elif defined(CONFIG_PAGE_SIZE_16KB)
# define PAGE_SHIFT	14
17 18 19 20 21
#elif defined(CONFIG_PAGE_SIZE_64KB)
# define PAGE_SHIFT	16
#else
# error "Bogus kernel page size?"
#endif
22

23
#define PAGE_SIZE	(_AC(1, UL) << PAGE_SHIFT)
L
Linus Torvalds 已提交
24 25 26 27 28
#define PAGE_MASK	(~(PAGE_SIZE-1))
#define PTE_MASK	PAGE_MASK

#if defined(CONFIG_HUGETLB_PAGE_SIZE_64K)
#define HPAGE_SHIFT	16
29 30
#elif defined(CONFIG_HUGETLB_PAGE_SIZE_256K)
#define HPAGE_SHIFT	18
L
Linus Torvalds 已提交
31 32
#elif defined(CONFIG_HUGETLB_PAGE_SIZE_1MB)
#define HPAGE_SHIFT	20
33 34 35 36
#elif defined(CONFIG_HUGETLB_PAGE_SIZE_4MB)
#define HPAGE_SHIFT	22
#elif defined(CONFIG_HUGETLB_PAGE_SIZE_64MB)
#define HPAGE_SHIFT	26
37 38
#elif defined(CONFIG_HUGETLB_PAGE_SIZE_512MB)
#define HPAGE_SHIFT	29
L
Linus Torvalds 已提交
39 40 41 42 43 44 45 46 47 48
#endif

#ifdef CONFIG_HUGETLB_PAGE
#define HPAGE_SIZE		(1UL << HPAGE_SHIFT)
#define HPAGE_MASK		(~(HPAGE_SIZE-1))
#define HUGETLB_PAGE_ORDER	(HPAGE_SHIFT-PAGE_SHIFT)
#endif

#ifndef __ASSEMBLY__

49
extern unsigned long shm_align_mask;
50
extern unsigned long max_low_pfn, min_low_pfn;
51
extern unsigned long memory_start, memory_end;
52

53 54 55 56 57 58
static inline unsigned long
pages_do_alias(unsigned long addr1, unsigned long addr2)
{
	return (addr1 ^ addr2) & shm_align_mask;
}

59 60

#define clear_page(page)	memset((void *)(page), 0, PAGE_SIZE)
61
extern void copy_page(void *to, void *from);
L
Linus Torvalds 已提交
62

63 64 65
struct page;
struct vm_area_struct;

P
Paul Mundt 已提交
66 67 68
extern void copy_user_highpage(struct page *to, struct page *from,
			       unsigned long vaddr, struct vm_area_struct *vma);
#define __HAVE_ARCH_COPY_USER_HIGHPAGE
69 70
extern void clear_user_highpage(struct page *page, unsigned long vaddr);
#define clear_user_highpage	clear_user_highpage
71

L
Linus Torvalds 已提交
72 73 74
/*
 * These are used to make use of C type-checking..
 */
75 76 77
#ifdef CONFIG_X2TLB
typedef struct { unsigned long pte_low, pte_high; } pte_t;
typedef struct { unsigned long long pgprot; } pgprot_t;
78
typedef struct { unsigned long long pgd; } pgd_t;
79 80 81 82
#define pte_val(x) \
	((x).pte_low | ((unsigned long long)(x).pte_high << 32))
#define __pte(x) \
	({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
83
#elif defined(CONFIG_SUPERH32)
84
typedef struct { unsigned long pte_low; } pte_t;
L
Linus Torvalds 已提交
85
typedef struct { unsigned long pgprot; } pgprot_t;
86
typedef struct { unsigned long pgd; } pgd_t;
87
#define pte_val(x)	((x).pte_low)
88 89 90
#define __pte(x)	((pte_t) { (x) } )
#else
typedef struct { unsigned long long pte_low; } pte_t;
91
typedef struct { unsigned long long pgprot; } pgprot_t;
92 93 94
typedef struct { unsigned long pgd; } pgd_t;
#define pte_val(x)	((x).pte_low)
#define __pte(x)	((pte_t) { (x) } )
95 96
#endif

L
Linus Torvalds 已提交
97 98 99 100 101 102
#define pgd_val(x)	((x).pgd)
#define pgprot_val(x)	((x).pgprot)

#define __pgd(x) ((pgd_t) { (x) } )
#define __pgprot(x)	((pgprot_t) { (x) } )

103 104
typedef struct page *pgtable_t;

P
Paul Mundt 已提交
105 106
#define pte_pgprot(x) __pgprot(pte_val(x) & PTE_FLAGS_MASK)

L
Linus Torvalds 已提交
107 108
#endif /* !__ASSEMBLY__ */

109 110 111
/*
 * __MEMORY_START and SIZE are the physical addresses and size of RAM.
 */
L
Linus Torvalds 已提交
112 113 114
#define __MEMORY_START		CONFIG_MEMORY_START
#define __MEMORY_SIZE		CONFIG_MEMORY_SIZE

115 116 117 118
/*
 * PAGE_OFFSET is the virtual address of the start of kernel address
 * space.
 */
P
Paul Mundt 已提交
119
#define PAGE_OFFSET		CONFIG_PAGE_OFFSET
L
Linus Torvalds 已提交
120

121 122 123 124 125 126 127 128 129
/*
 * Virtual to physical RAM address translation.
 *
 * In 29 bit mode, the physical offset of RAM from address 0 is visible in
 * the kernel virtual address space, and thus we don't have to take
 * this into account when translating. However in 32 bit mode this offset
 * is not visible (it is part of the PMB mapping) and so needs to be
 * added or subtracted as required.
 */
P
Paul Mundt 已提交
130
#if defined(CONFIG_PMB_LEGACY)
131 132 133 134 135
/* phys = virt - PAGE_OFFSET - (__MEMORY_START & 0xe0000000) */
#define PMB_OFFSET	(PAGE_OFFSET - PXSEG(__MEMORY_START))
#define __pa(x)	((unsigned long)(x) - PMB_OFFSET)
#define __va(x)	((void *)((unsigned long)(x) + PMB_OFFSET))
#elif defined(CONFIG_32BIT)
136 137 138 139 140 141 142 143
#define __pa(x)	((unsigned long)(x)-PAGE_OFFSET+__MEMORY_START)
#define __va(x)	((void *)((unsigned long)(x)+PAGE_OFFSET-__MEMORY_START))
#else
#define __pa(x)	((unsigned long)(x)-PAGE_OFFSET)
#define __va(x)	((void *)((unsigned long)(x)+PAGE_OFFSET))
#endif

#define pfn_to_kaddr(pfn)	__va((pfn) << PAGE_SHIFT)
144
#define page_to_phys(page)	(page_to_pfn(page) << PAGE_SHIFT)
L
Linus Torvalds 已提交
145

146 147 148 149 150 151
/*
 * PFN = physical frame number (ie PFN 0 == physical address 0)
 * PFN_START is the PFN of the first page of RAM. By defining this we
 * don't have struct page entries for the portion of address space
 * between physical address 0 and the start of RAM.
 */
L
Linus Torvalds 已提交
152
#define PFN_START		(__MEMORY_START >> PAGE_SHIFT)
A
Alexey Dobriyan 已提交
153
#define ARCH_PFN_OFFSET		(PFN_START)
L
Linus Torvalds 已提交
154
#define virt_to_page(kaddr)	pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
P
Paul Mundt 已提交
155
#ifdef CONFIG_FLATMEM
156
#define pfn_valid(pfn)		((pfn) >= min_low_pfn && (pfn) < max_low_pfn)
P
Paul Mundt 已提交
157
#endif
L
Linus Torvalds 已提交
158 159 160 161 162
#define virt_addr_valid(kaddr)	pfn_valid(__pa(kaddr) >> PAGE_SHIFT)

#define VM_DATA_DEFAULT_FLAGS	(VM_READ | VM_WRITE | VM_EXEC | \
				 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)

163
#include <asm-generic/memory_model.h>
164
#include <asm-generic/getorder.h>
165

P
Paul Mundt 已提交
166 167 168 169 170
/* vDSO support */
#ifdef CONFIG_VSYSCALL
#define __HAVE_ARCH_GATE_AREA
#endif

171
/*
172 173
 * Some drivers need to perform DMA into kmalloc'ed buffers
 * and so we have to increase the kmalloc minalign for this.
174
 */
175
#define ARCH_KMALLOC_MINALIGN	L1_CACHE_BYTES
176

177
#ifdef CONFIG_SUPERH64
178
/*
179 180 181 182 183
 * While BYTES_PER_WORD == 4 on the current sh64 ABI, GCC will still
 * happily generate {ld/st}.q pairs, requiring us to have 8-byte
 * alignment to avoid traps. The kmalloc alignment is gauranteed by
 * virtue of L1_CACHE_BYTES, requiring this to only be special cased
 * for slab caches.
184 185 186
 */
#define ARCH_SLAB_MINALIGN	8
#endif
187

L
Linus Torvalds 已提交
188
#endif /* __ASM_SH_PAGE_H */