blob: 0fb68a0b0181c311eae08877d29809980639a76e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _PPC_PAGE_H
2#define _PPC_PAGE_H
3
Benjamin Herrenschmidta7f290d2005-11-11 21:15:21 +11004#include <linux/config.h>
5#include <asm/asm-compat.h>
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007/* PAGE_SHIFT determines the page size */
8#define PAGE_SHIFT 12
Benjamin Herrenschmidta7f290d2005-11-11 21:15:21 +11009#define PAGE_SIZE (ASM_CONST(1) << PAGE_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
11/*
12 * Subtle: this is an int (not an unsigned long) and so it
13 * gets extended to 64 bits the way want (i.e. with 1s). -- paulus
14 */
15#define PAGE_MASK (~((1 << PAGE_SHIFT) - 1))
16
17#ifdef __KERNEL__
18#include <linux/config.h>
19
20/* This must match what is in arch/ppc/Makefile */
21#define PAGE_OFFSET CONFIG_KERNEL_START
22#define KERNELBASE PAGE_OFFSET
Paul Mackerrase4de0022006-05-09 16:00:59 +100023#define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25#ifndef __ASSEMBLY__
26
27/*
28 * The basic type of a PTE - 64 bits for those CPUs with > 32 bit
29 * physical addressing. For now this just the IBM PPC440.
30 */
31#ifdef CONFIG_PTE_64BIT
32typedef unsigned long long pte_basic_t;
33#define PTE_SHIFT (PAGE_SHIFT - 3) /* 512 ptes per page */
34#define PTE_FMT "%16Lx"
35#else
36typedef unsigned long pte_basic_t;
37#define PTE_SHIFT (PAGE_SHIFT - 2) /* 1024 ptes per page */
38#define PTE_FMT "%.8lx"
39#endif
40
Paul Mackerras7c8c6b92005-10-06 12:23:33 +100041/* align addr on a size boundary - adjust address up/down if needed */
42#define _ALIGN_UP(addr,size) (((addr)+((size)-1))&(~((size)-1)))
43#define _ALIGN_DOWN(addr,size) ((addr)&(~((size)-1)))
44
45/* align addr on a size boundary - adjust address up if needed */
46#define _ALIGN(addr,size) _ALIGN_UP(addr,size)
47
48/* to align the pointer to the (next) page boundary */
49#define PAGE_ALIGN(addr) _ALIGN(addr, PAGE_SIZE)
50
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#undef STRICT_MM_TYPECHECKS
53
54#ifdef STRICT_MM_TYPECHECKS
55/*
56 * These are used to make use of C type-checking..
57 */
58typedef struct { pte_basic_t pte; } pte_t;
59typedef struct { unsigned long pmd; } pmd_t;
60typedef struct { unsigned long pgd; } pgd_t;
61typedef struct { unsigned long pgprot; } pgprot_t;
62
63#define pte_val(x) ((x).pte)
64#define pmd_val(x) ((x).pmd)
65#define pgd_val(x) ((x).pgd)
66#define pgprot_val(x) ((x).pgprot)
67
68#define __pte(x) ((pte_t) { (x) } )
69#define __pmd(x) ((pmd_t) { (x) } )
70#define __pgd(x) ((pgd_t) { (x) } )
71#define __pgprot(x) ((pgprot_t) { (x) } )
72
73#else
74/*
75 * .. while these make it easier on the compiler
76 */
77typedef pte_basic_t pte_t;
78typedef unsigned long pmd_t;
79typedef unsigned long pgd_t;
80typedef unsigned long pgprot_t;
81
82#define pte_val(x) (x)
83#define pmd_val(x) (x)
84#define pgd_val(x) (x)
85#define pgprot_val(x) (x)
86
87#define __pte(x) (x)
88#define __pmd(x) (x)
89#define __pgd(x) (x)
90#define __pgprot(x) (x)
91
92#endif
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094struct page;
95extern void clear_pages(void *page, int order);
96static inline void clear_page(void *page) { clear_pages(page, 0); }
97extern void copy_page(void *to, void *from);
98extern void clear_user_page(void *page, unsigned long vaddr, struct page *pg);
99extern void copy_user_page(void *to, void *from, unsigned long vaddr,
100 struct page *pg);
101
102#ifndef CONFIG_APUS
103#define PPC_MEMSTART 0
104#define PPC_PGSTART 0
105#define PPC_MEMOFFSET PAGE_OFFSET
106#else
107extern unsigned long ppc_memstart;
108extern unsigned long ppc_pgstart;
109extern unsigned long ppc_memoffset;
110#define PPC_MEMSTART ppc_memstart
111#define PPC_PGSTART ppc_pgstart
112#define PPC_MEMOFFSET ppc_memoffset
113#endif
114
115#if defined(CONFIG_APUS) && !defined(MODULE)
116/* map phys->virtual and virtual->phys for RAM pages */
117static inline unsigned long ___pa(unsigned long v)
118{
119 unsigned long p;
120 asm volatile ("1: addis %0, %1, %2;"
121 ".section \".vtop_fixup\",\"aw\";"
122 ".align 1;"
123 ".long 1b;"
124 ".previous;"
125 : "=r" (p)
126 : "b" (v), "K" (((-PAGE_OFFSET) >> 16) & 0xffff));
127
128 return p;
129}
130static inline void* ___va(unsigned long p)
131{
132 unsigned long v;
133 asm volatile ("1: addis %0, %1, %2;"
134 ".section \".ptov_fixup\",\"aw\";"
135 ".align 1;"
136 ".long 1b;"
137 ".previous;"
138 : "=r" (v)
139 : "b" (p), "K" (((PAGE_OFFSET) >> 16) & 0xffff));
140
141 return (void*) v;
142}
143#else
144#define ___pa(vaddr) ((vaddr)-PPC_MEMOFFSET)
145#define ___va(paddr) ((paddr)+PPC_MEMOFFSET)
146#endif
147
148extern int page_is_ram(unsigned long pfn);
149
150#define __pa(x) ___pa((unsigned long)(x))
151#define __va(x) ((void *)(___va((unsigned long)(x))))
152
KAMEZAWA Hiroyukif68d4c92006-03-27 01:15:44 -0800153#define ARCH_PFN_OFFSET (PPC_PGSTART)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
155#define page_to_virt(page) __va(page_to_pfn(page) << PAGE_SHIFT)
156
157#define pfn_valid(pfn) (((pfn) - PPC_PGSTART) < max_mapnr)
158#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
159
160/* Pure 2^n version of get_order */
161extern __inline__ int get_order(unsigned long size)
162{
163 int lz;
164
165 size = (size-1) >> PAGE_SHIFT;
166 asm ("cntlzw %0,%1" : "=r" (lz) : "r" (size));
167 return 32 - lz;
168}
169
170#endif /* __ASSEMBLY__ */
171
172#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
173 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
174
Benjamin Herrenschmidta7f290d2005-11-11 21:15:21 +1100175/* We do define AT_SYSINFO_EHDR but don't use the gate mecanism */
176#define __HAVE_ARCH_GATE_AREA 1
177
KAMEZAWA Hiroyukif68d4c92006-03-27 01:15:44 -0800178#include <asm-generic/memory_model.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179#endif /* __KERNEL__ */
180#endif /* _PPC_PAGE_H */