xref: /OK3568_Linux_fs/kernel/arch/parisc/include/asm/pgtable.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef _PARISC_PGTABLE_H
3*4882a593Smuzhiyun #define _PARISC_PGTABLE_H
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun #include <asm/page.h>
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #if CONFIG_PGTABLE_LEVELS == 3
8*4882a593Smuzhiyun #include <asm-generic/pgtable-nopud.h>
9*4882a593Smuzhiyun #elif CONFIG_PGTABLE_LEVELS == 2
10*4882a593Smuzhiyun #include <asm-generic/pgtable-nopmd.h>
11*4882a593Smuzhiyun #endif
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun #include <asm/fixmap.h>
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun #ifndef __ASSEMBLY__
16*4882a593Smuzhiyun /*
17*4882a593Smuzhiyun  * we simulate an x86-style page table for the linux mm code
18*4882a593Smuzhiyun  */
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun #include <linux/bitops.h>
21*4882a593Smuzhiyun #include <linux/spinlock.h>
22*4882a593Smuzhiyun #include <linux/mm_types.h>
23*4882a593Smuzhiyun #include <asm/processor.h>
24*4882a593Smuzhiyun #include <asm/cache.h>
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun /*
27*4882a593Smuzhiyun  * kern_addr_valid(ADDR) tests if ADDR is pointing to valid kernel
28*4882a593Smuzhiyun  * memory.  For the return value to be meaningful, ADDR must be >=
29*4882a593Smuzhiyun  * PAGE_OFFSET.  This operation can be relatively expensive (e.g.,
30*4882a593Smuzhiyun  * require a hash-, or multi-level tree-lookup or something of that
31*4882a593Smuzhiyun  * sort) but it guarantees to return TRUE only if accessing the page
32*4882a593Smuzhiyun  * at that address does not cause an error.  Note that there may be
33*4882a593Smuzhiyun  * addresses for which kern_addr_valid() returns FALSE even though an
34*4882a593Smuzhiyun  * access would not cause an error (e.g., this is typically true for
35*4882a593Smuzhiyun  * memory mapped I/O regions.
36*4882a593Smuzhiyun  *
37*4882a593Smuzhiyun  * XXX Need to implement this for parisc.
38*4882a593Smuzhiyun  */
39*4882a593Smuzhiyun #define kern_addr_valid(addr)	(1)
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun /* This is for the serialization of PxTLB broadcasts. At least on the N class
42*4882a593Smuzhiyun  * systems, only one PxTLB inter processor broadcast can be active at any one
43*4882a593Smuzhiyun  * time on the Merced bus. */
44*4882a593Smuzhiyun extern spinlock_t pa_tlb_flush_lock;
45*4882a593Smuzhiyun #if defined(CONFIG_64BIT) && defined(CONFIG_SMP)
46*4882a593Smuzhiyun extern int pa_serialize_tlb_flushes;
47*4882a593Smuzhiyun #else
48*4882a593Smuzhiyun #define pa_serialize_tlb_flushes        (0)
49*4882a593Smuzhiyun #endif
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun #define purge_tlb_start(flags)  do { \
52*4882a593Smuzhiyun 	if (pa_serialize_tlb_flushes)	\
53*4882a593Smuzhiyun 		spin_lock_irqsave(&pa_tlb_flush_lock, flags); \
54*4882a593Smuzhiyun 	else \
55*4882a593Smuzhiyun 		local_irq_save(flags);	\
56*4882a593Smuzhiyun 	} while (0)
57*4882a593Smuzhiyun #define purge_tlb_end(flags)	do { \
58*4882a593Smuzhiyun 	if (pa_serialize_tlb_flushes)	\
59*4882a593Smuzhiyun 		spin_unlock_irqrestore(&pa_tlb_flush_lock, flags); \
60*4882a593Smuzhiyun 	else \
61*4882a593Smuzhiyun 		local_irq_restore(flags); \
62*4882a593Smuzhiyun 	} while (0)
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun /* Purge data and instruction TLB entries. The TLB purge instructions
65*4882a593Smuzhiyun  * are slow on SMP machines since the purge must be broadcast to all CPUs.
66*4882a593Smuzhiyun  */
67*4882a593Smuzhiyun 
purge_tlb_entries(struct mm_struct * mm,unsigned long addr)68*4882a593Smuzhiyun static inline void purge_tlb_entries(struct mm_struct *mm, unsigned long addr)
69*4882a593Smuzhiyun {
70*4882a593Smuzhiyun 	unsigned long flags;
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun 	purge_tlb_start(flags);
73*4882a593Smuzhiyun 	mtsp(mm->context, 1);
74*4882a593Smuzhiyun 	pdtlb(addr);
75*4882a593Smuzhiyun 	pitlb(addr);
76*4882a593Smuzhiyun 	purge_tlb_end(flags);
77*4882a593Smuzhiyun }
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun extern void __update_cache(pte_t pte);
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun /* Certain architectures need to do special things when PTEs
82*4882a593Smuzhiyun  * within a page table are directly modified.  Thus, the following
83*4882a593Smuzhiyun  * hook is made available.
84*4882a593Smuzhiyun  */
85*4882a593Smuzhiyun #define set_pte(pteptr, pteval)			\
86*4882a593Smuzhiyun 	do {					\
87*4882a593Smuzhiyun 		*(pteptr) = (pteval);		\
88*4882a593Smuzhiyun 		mb();				\
89*4882a593Smuzhiyun 	} while(0)
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun #define set_pte_at(mm, addr, pteptr, pteval)	\
92*4882a593Smuzhiyun 	do {					\
93*4882a593Smuzhiyun 		if (pte_present(pteval) &&	\
94*4882a593Smuzhiyun 		    pte_user(pteval))		\
95*4882a593Smuzhiyun 			__update_cache(pteval);	\
96*4882a593Smuzhiyun 		*(pteptr) = (pteval);		\
97*4882a593Smuzhiyun 		purge_tlb_entries(mm, addr);	\
98*4882a593Smuzhiyun 	} while (0)
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun #endif /* !__ASSEMBLY__ */
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun #define pte_ERROR(e) \
103*4882a593Smuzhiyun 	printk("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, pte_val(e))
104*4882a593Smuzhiyun #if CONFIG_PGTABLE_LEVELS == 3
105*4882a593Smuzhiyun #define pmd_ERROR(e) \
106*4882a593Smuzhiyun 	printk("%s:%d: bad pmd %08lx.\n", __FILE__, __LINE__, (unsigned long)pmd_val(e))
107*4882a593Smuzhiyun #endif
108*4882a593Smuzhiyun #define pgd_ERROR(e) \
109*4882a593Smuzhiyun 	printk("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, (unsigned long)pgd_val(e))
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun /* This is the size of the initially mapped kernel memory */
112*4882a593Smuzhiyun #if defined(CONFIG_64BIT)
113*4882a593Smuzhiyun #define KERNEL_INITIAL_ORDER	26	/* 1<<26 = 64MB */
114*4882a593Smuzhiyun #else
115*4882a593Smuzhiyun #define KERNEL_INITIAL_ORDER	25	/* 1<<25 = 32MB */
116*4882a593Smuzhiyun #endif
117*4882a593Smuzhiyun #define KERNEL_INITIAL_SIZE	(1 << KERNEL_INITIAL_ORDER)
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun #if CONFIG_PGTABLE_LEVELS == 3
120*4882a593Smuzhiyun #define PMD_ORDER	1
121*4882a593Smuzhiyun #define PGD_ORDER	0
122*4882a593Smuzhiyun #else
123*4882a593Smuzhiyun #define PGD_ORDER	1
124*4882a593Smuzhiyun #endif
125*4882a593Smuzhiyun 
126*4882a593Smuzhiyun /* Definitions for 3rd level (we use PLD here for Page Lower directory
127*4882a593Smuzhiyun  * because PTE_SHIFT is used lower down to mean shift that has to be
128*4882a593Smuzhiyun  * done to get usable bits out of the PTE) */
129*4882a593Smuzhiyun #define PLD_SHIFT	PAGE_SHIFT
130*4882a593Smuzhiyun #define PLD_SIZE	PAGE_SIZE
131*4882a593Smuzhiyun #define BITS_PER_PTE	(PAGE_SHIFT - BITS_PER_PTE_ENTRY)
132*4882a593Smuzhiyun #define PTRS_PER_PTE    (1UL << BITS_PER_PTE)
133*4882a593Smuzhiyun 
134*4882a593Smuzhiyun /* Definitions for 2nd level */
135*4882a593Smuzhiyun #if CONFIG_PGTABLE_LEVELS == 3
136*4882a593Smuzhiyun #define PMD_SHIFT       (PLD_SHIFT + BITS_PER_PTE)
137*4882a593Smuzhiyun #define PMD_SIZE	(1UL << PMD_SHIFT)
138*4882a593Smuzhiyun #define PMD_MASK	(~(PMD_SIZE-1))
139*4882a593Smuzhiyun #define BITS_PER_PMD	(PAGE_SHIFT + PMD_ORDER - BITS_PER_PMD_ENTRY)
140*4882a593Smuzhiyun #define PTRS_PER_PMD    (1UL << BITS_PER_PMD)
141*4882a593Smuzhiyun #else
142*4882a593Smuzhiyun #define BITS_PER_PMD	0
143*4882a593Smuzhiyun #endif
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun /* Definitions for 1st level */
146*4882a593Smuzhiyun #define PGDIR_SHIFT	(PLD_SHIFT + BITS_PER_PTE + BITS_PER_PMD)
147*4882a593Smuzhiyun #if (PGDIR_SHIFT + PAGE_SHIFT + PGD_ORDER - BITS_PER_PGD_ENTRY) > BITS_PER_LONG
148*4882a593Smuzhiyun #define BITS_PER_PGD	(BITS_PER_LONG - PGDIR_SHIFT)
149*4882a593Smuzhiyun #else
150*4882a593Smuzhiyun #define BITS_PER_PGD	(PAGE_SHIFT + PGD_ORDER - BITS_PER_PGD_ENTRY)
151*4882a593Smuzhiyun #endif
152*4882a593Smuzhiyun #define PGDIR_SIZE	(1UL << PGDIR_SHIFT)
153*4882a593Smuzhiyun #define PGDIR_MASK	(~(PGDIR_SIZE-1))
154*4882a593Smuzhiyun #define PTRS_PER_PGD    (1UL << BITS_PER_PGD)
155*4882a593Smuzhiyun #define USER_PTRS_PER_PGD       PTRS_PER_PGD
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun #ifdef CONFIG_64BIT
158*4882a593Smuzhiyun #define MAX_ADDRBITS	(PGDIR_SHIFT + BITS_PER_PGD)
159*4882a593Smuzhiyun #define MAX_ADDRESS	(1UL << MAX_ADDRBITS)
160*4882a593Smuzhiyun #define SPACEID_SHIFT	(MAX_ADDRBITS - 32)
161*4882a593Smuzhiyun #else
162*4882a593Smuzhiyun #define MAX_ADDRBITS	(BITS_PER_LONG)
163*4882a593Smuzhiyun #define MAX_ADDRESS	(1UL << MAX_ADDRBITS)
164*4882a593Smuzhiyun #define SPACEID_SHIFT	0
165*4882a593Smuzhiyun #endif
166*4882a593Smuzhiyun 
167*4882a593Smuzhiyun /* This calculates the number of initial pages we need for the initial
168*4882a593Smuzhiyun  * page tables */
169*4882a593Smuzhiyun #if (KERNEL_INITIAL_ORDER) >= (PMD_SHIFT)
170*4882a593Smuzhiyun # define PT_INITIAL	(1 << (KERNEL_INITIAL_ORDER - PMD_SHIFT))
171*4882a593Smuzhiyun #else
172*4882a593Smuzhiyun # define PT_INITIAL	(1)  /* all initial PTEs fit into one page */
173*4882a593Smuzhiyun #endif
174*4882a593Smuzhiyun 
175*4882a593Smuzhiyun /*
176*4882a593Smuzhiyun  * pgd entries used up by user/kernel:
177*4882a593Smuzhiyun  */
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun #define FIRST_USER_ADDRESS	0UL
180*4882a593Smuzhiyun 
181*4882a593Smuzhiyun /* NB: The tlb miss handlers make certain assumptions about the order */
182*4882a593Smuzhiyun /*     of the following bits, so be careful (One example, bits 25-31  */
183*4882a593Smuzhiyun /*     are moved together in one instruction).                        */
184*4882a593Smuzhiyun 
185*4882a593Smuzhiyun #define _PAGE_READ_BIT     31   /* (0x001) read access allowed */
186*4882a593Smuzhiyun #define _PAGE_WRITE_BIT    30   /* (0x002) write access allowed */
187*4882a593Smuzhiyun #define _PAGE_EXEC_BIT     29   /* (0x004) execute access allowed */
188*4882a593Smuzhiyun #define _PAGE_GATEWAY_BIT  28   /* (0x008) privilege promotion allowed */
189*4882a593Smuzhiyun #define _PAGE_DMB_BIT      27   /* (0x010) Data Memory Break enable (B bit) */
190*4882a593Smuzhiyun #define _PAGE_DIRTY_BIT    26   /* (0x020) Page Dirty (D bit) */
191*4882a593Smuzhiyun #define _PAGE_REFTRAP_BIT  25   /* (0x040) Page Ref. Trap enable (T bit) */
192*4882a593Smuzhiyun #define _PAGE_NO_CACHE_BIT 24   /* (0x080) Uncached Page (U bit) */
193*4882a593Smuzhiyun #define _PAGE_ACCESSED_BIT 23   /* (0x100) Software: Page Accessed */
194*4882a593Smuzhiyun #define _PAGE_PRESENT_BIT  22   /* (0x200) Software: translation valid */
195*4882a593Smuzhiyun #define _PAGE_HPAGE_BIT    21   /* (0x400) Software: Huge Page */
196*4882a593Smuzhiyun #define _PAGE_USER_BIT     20   /* (0x800) Software: User accessible page */
197*4882a593Smuzhiyun 
198*4882a593Smuzhiyun /* N.B. The bits are defined in terms of a 32 bit word above, so the */
199*4882a593Smuzhiyun /*      following macro is ok for both 32 and 64 bit.                */
200*4882a593Smuzhiyun 
201*4882a593Smuzhiyun #define xlate_pabit(x) (31 - x)
202*4882a593Smuzhiyun 
203*4882a593Smuzhiyun /* this defines the shift to the usable bits in the PTE it is set so
204*4882a593Smuzhiyun  * that the valid bits _PAGE_PRESENT_BIT and _PAGE_USER_BIT are set
205*4882a593Smuzhiyun  * to zero */
206*4882a593Smuzhiyun #define PTE_SHIFT	   	xlate_pabit(_PAGE_USER_BIT)
207*4882a593Smuzhiyun 
208*4882a593Smuzhiyun /* PFN_PTE_SHIFT defines the shift of a PTE value to access the PFN field */
209*4882a593Smuzhiyun #define PFN_PTE_SHIFT		12
210*4882a593Smuzhiyun 
211*4882a593Smuzhiyun #define _PAGE_READ     (1 << xlate_pabit(_PAGE_READ_BIT))
212*4882a593Smuzhiyun #define _PAGE_WRITE    (1 << xlate_pabit(_PAGE_WRITE_BIT))
213*4882a593Smuzhiyun #define _PAGE_RW       (_PAGE_READ | _PAGE_WRITE)
214*4882a593Smuzhiyun #define _PAGE_EXEC     (1 << xlate_pabit(_PAGE_EXEC_BIT))
215*4882a593Smuzhiyun #define _PAGE_GATEWAY  (1 << xlate_pabit(_PAGE_GATEWAY_BIT))
216*4882a593Smuzhiyun #define _PAGE_DMB      (1 << xlate_pabit(_PAGE_DMB_BIT))
217*4882a593Smuzhiyun #define _PAGE_DIRTY    (1 << xlate_pabit(_PAGE_DIRTY_BIT))
218*4882a593Smuzhiyun #define _PAGE_REFTRAP  (1 << xlate_pabit(_PAGE_REFTRAP_BIT))
219*4882a593Smuzhiyun #define _PAGE_NO_CACHE (1 << xlate_pabit(_PAGE_NO_CACHE_BIT))
220*4882a593Smuzhiyun #define _PAGE_ACCESSED (1 << xlate_pabit(_PAGE_ACCESSED_BIT))
221*4882a593Smuzhiyun #define _PAGE_PRESENT  (1 << xlate_pabit(_PAGE_PRESENT_BIT))
222*4882a593Smuzhiyun #define _PAGE_HUGE     (1 << xlate_pabit(_PAGE_HPAGE_BIT))
223*4882a593Smuzhiyun #define _PAGE_USER     (1 << xlate_pabit(_PAGE_USER_BIT))
224*4882a593Smuzhiyun 
225*4882a593Smuzhiyun #define _PAGE_TABLE	(_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | _PAGE_DIRTY | _PAGE_ACCESSED)
226*4882a593Smuzhiyun #define _PAGE_CHG_MASK	(PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
227*4882a593Smuzhiyun #define _PAGE_KERNEL_RO	(_PAGE_PRESENT | _PAGE_READ | _PAGE_DIRTY | _PAGE_ACCESSED)
228*4882a593Smuzhiyun #define _PAGE_KERNEL_EXEC	(_PAGE_KERNEL_RO | _PAGE_EXEC)
229*4882a593Smuzhiyun #define _PAGE_KERNEL_RWX	(_PAGE_KERNEL_EXEC | _PAGE_WRITE)
230*4882a593Smuzhiyun #define _PAGE_KERNEL		(_PAGE_KERNEL_RO | _PAGE_WRITE)
231*4882a593Smuzhiyun 
232*4882a593Smuzhiyun /* The pgd/pmd contains a ptr (in phys addr space); since all pgds/pmds
233*4882a593Smuzhiyun  * are page-aligned, we don't care about the PAGE_OFFSET bits, except
234*4882a593Smuzhiyun  * for a few meta-information bits, so we shift the address to be
235*4882a593Smuzhiyun  * able to effectively address 40/42/44-bits of physical address space
236*4882a593Smuzhiyun  * depending on 4k/16k/64k PAGE_SIZE */
237*4882a593Smuzhiyun #define _PxD_PRESENT_BIT   31
238*4882a593Smuzhiyun #define _PxD_VALID_BIT     30
239*4882a593Smuzhiyun 
240*4882a593Smuzhiyun #define PxD_FLAG_PRESENT  (1 << xlate_pabit(_PxD_PRESENT_BIT))
241*4882a593Smuzhiyun #define PxD_FLAG_VALID    (1 << xlate_pabit(_PxD_VALID_BIT))
242*4882a593Smuzhiyun #define PxD_FLAG_MASK     (0xf)
243*4882a593Smuzhiyun #define PxD_FLAG_SHIFT    (4)
244*4882a593Smuzhiyun #define PxD_VALUE_SHIFT   (PFN_PTE_SHIFT-PxD_FLAG_SHIFT)
245*4882a593Smuzhiyun 
246*4882a593Smuzhiyun #ifndef __ASSEMBLY__
247*4882a593Smuzhiyun 
248*4882a593Smuzhiyun #define PAGE_NONE	__pgprot(_PAGE_PRESENT | _PAGE_USER)
249*4882a593Smuzhiyun #define PAGE_SHARED	__pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE)
250*4882a593Smuzhiyun /* Others seem to make this executable, I don't know if that's correct
251*4882a593Smuzhiyun    or not.  The stack is mapped this way though so this is necessary
252*4882a593Smuzhiyun    in the short term - dhd@linuxcare.com, 2000-08-08 */
253*4882a593Smuzhiyun #define PAGE_READONLY	__pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ)
254*4882a593Smuzhiyun #define PAGE_WRITEONLY  __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_WRITE)
255*4882a593Smuzhiyun #define PAGE_EXECREAD   __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC)
256*4882a593Smuzhiyun #define PAGE_COPY       PAGE_EXECREAD
257*4882a593Smuzhiyun #define PAGE_RWX        __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC)
258*4882a593Smuzhiyun #define PAGE_KERNEL	__pgprot(_PAGE_KERNEL)
259*4882a593Smuzhiyun #define PAGE_KERNEL_EXEC	__pgprot(_PAGE_KERNEL_EXEC)
260*4882a593Smuzhiyun #define PAGE_KERNEL_RWX	__pgprot(_PAGE_KERNEL_RWX)
261*4882a593Smuzhiyun #define PAGE_KERNEL_RO	__pgprot(_PAGE_KERNEL_RO)
262*4882a593Smuzhiyun #define PAGE_KERNEL_UNC	__pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
263*4882a593Smuzhiyun #define PAGE_GATEWAY    __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_GATEWAY| _PAGE_READ)
264*4882a593Smuzhiyun 
265*4882a593Smuzhiyun 
266*4882a593Smuzhiyun /*
267*4882a593Smuzhiyun  * We could have an execute only page using "gateway - promote to priv
268*4882a593Smuzhiyun  * level 3", but that is kind of silly. So, the way things are defined
269*4882a593Smuzhiyun  * now, we must always have read permission for pages with execute
270*4882a593Smuzhiyun  * permission. For the fun of it we'll go ahead and support write only
271*4882a593Smuzhiyun  * pages.
272*4882a593Smuzhiyun  */
273*4882a593Smuzhiyun 
274*4882a593Smuzhiyun 	 /*xwr*/
275*4882a593Smuzhiyun #define __P000  PAGE_NONE
276*4882a593Smuzhiyun #define __P001  PAGE_READONLY
277*4882a593Smuzhiyun #define __P010  __P000 /* copy on write */
278*4882a593Smuzhiyun #define __P011  __P001 /* copy on write */
279*4882a593Smuzhiyun #define __P100  PAGE_EXECREAD
280*4882a593Smuzhiyun #define __P101  PAGE_EXECREAD
281*4882a593Smuzhiyun #define __P110  __P100 /* copy on write */
282*4882a593Smuzhiyun #define __P111  __P101 /* copy on write */
283*4882a593Smuzhiyun 
284*4882a593Smuzhiyun #define __S000  PAGE_NONE
285*4882a593Smuzhiyun #define __S001  PAGE_READONLY
286*4882a593Smuzhiyun #define __S010  PAGE_WRITEONLY
287*4882a593Smuzhiyun #define __S011  PAGE_SHARED
288*4882a593Smuzhiyun #define __S100  PAGE_EXECREAD
289*4882a593Smuzhiyun #define __S101  PAGE_EXECREAD
290*4882a593Smuzhiyun #define __S110  PAGE_RWX
291*4882a593Smuzhiyun #define __S111  PAGE_RWX
292*4882a593Smuzhiyun 
293*4882a593Smuzhiyun 
294*4882a593Smuzhiyun extern pgd_t swapper_pg_dir[]; /* declared in init_task.c */
295*4882a593Smuzhiyun 
296*4882a593Smuzhiyun /* initial page tables for 0-8MB for kernel */
297*4882a593Smuzhiyun 
298*4882a593Smuzhiyun extern pte_t pg0[];
299*4882a593Smuzhiyun 
300*4882a593Smuzhiyun /* zero page used for uninitialized stuff */
301*4882a593Smuzhiyun 
302*4882a593Smuzhiyun extern unsigned long *empty_zero_page;
303*4882a593Smuzhiyun 
304*4882a593Smuzhiyun /*
305*4882a593Smuzhiyun  * ZERO_PAGE is a global shared page that is always zero: used
306*4882a593Smuzhiyun  * for zero-mapped memory areas etc..
307*4882a593Smuzhiyun  */
308*4882a593Smuzhiyun 
309*4882a593Smuzhiyun #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
310*4882a593Smuzhiyun 
311*4882a593Smuzhiyun #define pte_none(x)     (pte_val(x) == 0)
312*4882a593Smuzhiyun #define pte_present(x)	(pte_val(x) & _PAGE_PRESENT)
313*4882a593Smuzhiyun #define pte_user(x)	(pte_val(x) & _PAGE_USER)
314*4882a593Smuzhiyun #define pte_clear(mm, addr, xp)  set_pte_at(mm, addr, xp, __pte(0))
315*4882a593Smuzhiyun 
316*4882a593Smuzhiyun #define pmd_flag(x)	(pmd_val(x) & PxD_FLAG_MASK)
317*4882a593Smuzhiyun #define pmd_address(x)	((unsigned long)(pmd_val(x) &~ PxD_FLAG_MASK) << PxD_VALUE_SHIFT)
318*4882a593Smuzhiyun #define pud_flag(x)	(pud_val(x) & PxD_FLAG_MASK)
319*4882a593Smuzhiyun #define pud_address(x)	((unsigned long)(pud_val(x) &~ PxD_FLAG_MASK) << PxD_VALUE_SHIFT)
320*4882a593Smuzhiyun #define pgd_flag(x)	(pgd_val(x) & PxD_FLAG_MASK)
321*4882a593Smuzhiyun #define pgd_address(x)	((unsigned long)(pgd_val(x) &~ PxD_FLAG_MASK) << PxD_VALUE_SHIFT)
322*4882a593Smuzhiyun 
323*4882a593Smuzhiyun #define pmd_none(x)	(!pmd_val(x))
324*4882a593Smuzhiyun #define pmd_bad(x)	(!(pmd_flag(x) & PxD_FLAG_VALID))
325*4882a593Smuzhiyun #define pmd_present(x)	(pmd_flag(x) & PxD_FLAG_PRESENT)
pmd_clear(pmd_t * pmd)326*4882a593Smuzhiyun static inline void pmd_clear(pmd_t *pmd) {
327*4882a593Smuzhiyun 		set_pmd(pmd,  __pmd(0));
328*4882a593Smuzhiyun }
329*4882a593Smuzhiyun 
330*4882a593Smuzhiyun 
331*4882a593Smuzhiyun 
332*4882a593Smuzhiyun #if CONFIG_PGTABLE_LEVELS == 3
333*4882a593Smuzhiyun #define pud_page_vaddr(pud) ((unsigned long) __va(pud_address(pud)))
334*4882a593Smuzhiyun #define pud_page(pud)	virt_to_page((void *)pud_page_vaddr(pud))
335*4882a593Smuzhiyun 
336*4882a593Smuzhiyun /* For 64 bit we have three level tables */
337*4882a593Smuzhiyun 
338*4882a593Smuzhiyun #define pud_none(x)     (!pud_val(x))
339*4882a593Smuzhiyun #define pud_bad(x)      (!(pud_flag(x) & PxD_FLAG_VALID))
340*4882a593Smuzhiyun #define pud_present(x)  (pud_flag(x) & PxD_FLAG_PRESENT)
pud_clear(pud_t * pud)341*4882a593Smuzhiyun static inline void pud_clear(pud_t *pud) {
342*4882a593Smuzhiyun 	set_pud(pud, __pud(0));
343*4882a593Smuzhiyun }
344*4882a593Smuzhiyun #endif
345*4882a593Smuzhiyun 
346*4882a593Smuzhiyun /*
347*4882a593Smuzhiyun  * The following only work if pte_present() is true.
348*4882a593Smuzhiyun  * Undefined behaviour if not..
349*4882a593Smuzhiyun  */
pte_dirty(pte_t pte)350*4882a593Smuzhiyun static inline int pte_dirty(pte_t pte)		{ return pte_val(pte) & _PAGE_DIRTY; }
pte_young(pte_t pte)351*4882a593Smuzhiyun static inline int pte_young(pte_t pte)		{ return pte_val(pte) & _PAGE_ACCESSED; }
pte_write(pte_t pte)352*4882a593Smuzhiyun static inline int pte_write(pte_t pte)		{ return pte_val(pte) & _PAGE_WRITE; }
353*4882a593Smuzhiyun 
pte_mkclean(pte_t pte)354*4882a593Smuzhiyun static inline pte_t pte_mkclean(pte_t pte)	{ pte_val(pte) &= ~_PAGE_DIRTY; return pte; }
pte_mkold(pte_t pte)355*4882a593Smuzhiyun static inline pte_t pte_mkold(pte_t pte)	{ pte_val(pte) &= ~_PAGE_ACCESSED; return pte; }
pte_wrprotect(pte_t pte)356*4882a593Smuzhiyun static inline pte_t pte_wrprotect(pte_t pte)	{ pte_val(pte) &= ~_PAGE_WRITE; return pte; }
pte_mkdirty(pte_t pte)357*4882a593Smuzhiyun static inline pte_t pte_mkdirty(pte_t pte)	{ pte_val(pte) |= _PAGE_DIRTY; return pte; }
pte_mkyoung(pte_t pte)358*4882a593Smuzhiyun static inline pte_t pte_mkyoung(pte_t pte)	{ pte_val(pte) |= _PAGE_ACCESSED; return pte; }
pte_mkwrite(pte_t pte)359*4882a593Smuzhiyun static inline pte_t pte_mkwrite(pte_t pte)	{ pte_val(pte) |= _PAGE_WRITE; return pte; }
360*4882a593Smuzhiyun 
361*4882a593Smuzhiyun /*
362*4882a593Smuzhiyun  * Huge pte definitions.
363*4882a593Smuzhiyun  */
364*4882a593Smuzhiyun #ifdef CONFIG_HUGETLB_PAGE
365*4882a593Smuzhiyun #define pte_huge(pte)           (pte_val(pte) & _PAGE_HUGE)
366*4882a593Smuzhiyun #define pte_mkhuge(pte)         (__pte(pte_val(pte) | \
367*4882a593Smuzhiyun 				 (parisc_requires_coherency() ? 0 : _PAGE_HUGE)))
368*4882a593Smuzhiyun #else
369*4882a593Smuzhiyun #define pte_huge(pte)           (0)
370*4882a593Smuzhiyun #define pte_mkhuge(pte)         (pte)
371*4882a593Smuzhiyun #endif
372*4882a593Smuzhiyun 
373*4882a593Smuzhiyun 
374*4882a593Smuzhiyun /*
375*4882a593Smuzhiyun  * Conversion functions: convert a page and protection to a page entry,
376*4882a593Smuzhiyun  * and a page entry and page directory to the page they refer to.
377*4882a593Smuzhiyun  */
378*4882a593Smuzhiyun #define __mk_pte(addr,pgprot) \
379*4882a593Smuzhiyun ({									\
380*4882a593Smuzhiyun 	pte_t __pte;							\
381*4882a593Smuzhiyun 									\
382*4882a593Smuzhiyun 	pte_val(__pte) = ((((addr)>>PAGE_SHIFT)<<PFN_PTE_SHIFT) + pgprot_val(pgprot));	\
383*4882a593Smuzhiyun 									\
384*4882a593Smuzhiyun 	__pte;								\
385*4882a593Smuzhiyun })
386*4882a593Smuzhiyun 
387*4882a593Smuzhiyun #define mk_pte(page, pgprot)	pfn_pte(page_to_pfn(page), (pgprot))
388*4882a593Smuzhiyun 
pfn_pte(unsigned long pfn,pgprot_t pgprot)389*4882a593Smuzhiyun static inline pte_t pfn_pte(unsigned long pfn, pgprot_t pgprot)
390*4882a593Smuzhiyun {
391*4882a593Smuzhiyun 	pte_t pte;
392*4882a593Smuzhiyun 	pte_val(pte) = (pfn << PFN_PTE_SHIFT) | pgprot_val(pgprot);
393*4882a593Smuzhiyun 	return pte;
394*4882a593Smuzhiyun }
395*4882a593Smuzhiyun 
pte_modify(pte_t pte,pgprot_t newprot)396*4882a593Smuzhiyun static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
397*4882a593Smuzhiyun { pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); return pte; }
398*4882a593Smuzhiyun 
399*4882a593Smuzhiyun /* Permanent address of a page.  On parisc we don't have highmem. */
400*4882a593Smuzhiyun 
401*4882a593Smuzhiyun #define pte_pfn(x)		(pte_val(x) >> PFN_PTE_SHIFT)
402*4882a593Smuzhiyun 
403*4882a593Smuzhiyun #define pte_page(pte)		(pfn_to_page(pte_pfn(pte)))
404*4882a593Smuzhiyun 
pmd_page_vaddr(pmd_t pmd)405*4882a593Smuzhiyun static inline unsigned long pmd_page_vaddr(pmd_t pmd)
406*4882a593Smuzhiyun {
407*4882a593Smuzhiyun 	return ((unsigned long) __va(pmd_address(pmd)));
408*4882a593Smuzhiyun }
409*4882a593Smuzhiyun 
410*4882a593Smuzhiyun #define __pmd_page(pmd) ((unsigned long) __va(pmd_address(pmd)))
411*4882a593Smuzhiyun #define pmd_page(pmd)	virt_to_page((void *)__pmd_page(pmd))
412*4882a593Smuzhiyun 
413*4882a593Smuzhiyun /* Find an entry in the second-level page table.. */
414*4882a593Smuzhiyun 
415*4882a593Smuzhiyun extern void paging_init (void);
416*4882a593Smuzhiyun 
417*4882a593Smuzhiyun /* Used for deferring calls to flush_dcache_page() */
418*4882a593Smuzhiyun 
419*4882a593Smuzhiyun #define PG_dcache_dirty         PG_arch_1
420*4882a593Smuzhiyun 
421*4882a593Smuzhiyun #define update_mmu_cache(vms,addr,ptep) __update_cache(*ptep)
422*4882a593Smuzhiyun 
423*4882a593Smuzhiyun /* Encode and de-code a swap entry */
424*4882a593Smuzhiyun 
425*4882a593Smuzhiyun #define __swp_type(x)                     ((x).val & 0x1f)
426*4882a593Smuzhiyun #define __swp_offset(x)                   ( (((x).val >> 6) &  0x7) | \
427*4882a593Smuzhiyun 					  (((x).val >> 8) & ~0x7) )
428*4882a593Smuzhiyun #define __swp_entry(type, offset)         ((swp_entry_t) { (type) | \
429*4882a593Smuzhiyun 					    ((offset &  0x7) << 6) | \
430*4882a593Smuzhiyun 					    ((offset & ~0x7) << 8) })
431*4882a593Smuzhiyun #define __pte_to_swp_entry(pte)		((swp_entry_t) { pte_val(pte) })
432*4882a593Smuzhiyun #define __swp_entry_to_pte(x)		((pte_t) { (x).val })
433*4882a593Smuzhiyun 
ptep_test_and_clear_young(struct vm_area_struct * vma,unsigned long addr,pte_t * ptep)434*4882a593Smuzhiyun static inline int ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep)
435*4882a593Smuzhiyun {
436*4882a593Smuzhiyun 	pte_t pte;
437*4882a593Smuzhiyun 
438*4882a593Smuzhiyun 	if (!pte_young(*ptep))
439*4882a593Smuzhiyun 		return 0;
440*4882a593Smuzhiyun 
441*4882a593Smuzhiyun 	pte = *ptep;
442*4882a593Smuzhiyun 	if (!pte_young(pte)) {
443*4882a593Smuzhiyun 		return 0;
444*4882a593Smuzhiyun 	}
445*4882a593Smuzhiyun 	set_pte_at(vma->vm_mm, addr, ptep, pte_mkold(pte));
446*4882a593Smuzhiyun 	return 1;
447*4882a593Smuzhiyun }
448*4882a593Smuzhiyun 
449*4882a593Smuzhiyun struct mm_struct;
ptep_get_and_clear(struct mm_struct * mm,unsigned long addr,pte_t * ptep)450*4882a593Smuzhiyun static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
451*4882a593Smuzhiyun {
452*4882a593Smuzhiyun 	pte_t old_pte;
453*4882a593Smuzhiyun 
454*4882a593Smuzhiyun 	old_pte = *ptep;
455*4882a593Smuzhiyun 	set_pte_at(mm, addr, ptep, __pte(0));
456*4882a593Smuzhiyun 
457*4882a593Smuzhiyun 	return old_pte;
458*4882a593Smuzhiyun }
459*4882a593Smuzhiyun 
ptep_set_wrprotect(struct mm_struct * mm,unsigned long addr,pte_t * ptep)460*4882a593Smuzhiyun static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
461*4882a593Smuzhiyun {
462*4882a593Smuzhiyun 	set_pte_at(mm, addr, ptep, pte_wrprotect(*ptep));
463*4882a593Smuzhiyun }
464*4882a593Smuzhiyun 
465*4882a593Smuzhiyun #define pte_same(A,B)	(pte_val(A) == pte_val(B))
466*4882a593Smuzhiyun 
467*4882a593Smuzhiyun struct seq_file;
468*4882a593Smuzhiyun extern void arch_report_meminfo(struct seq_file *m);
469*4882a593Smuzhiyun 
470*4882a593Smuzhiyun #endif /* !__ASSEMBLY__ */
471*4882a593Smuzhiyun 
472*4882a593Smuzhiyun 
473*4882a593Smuzhiyun /* TLB page size encoding - see table 3-1 in parisc20.pdf */
474*4882a593Smuzhiyun #define _PAGE_SIZE_ENCODING_4K		0
475*4882a593Smuzhiyun #define _PAGE_SIZE_ENCODING_16K		1
476*4882a593Smuzhiyun #define _PAGE_SIZE_ENCODING_64K		2
477*4882a593Smuzhiyun #define _PAGE_SIZE_ENCODING_256K	3
478*4882a593Smuzhiyun #define _PAGE_SIZE_ENCODING_1M		4
479*4882a593Smuzhiyun #define _PAGE_SIZE_ENCODING_4M		5
480*4882a593Smuzhiyun #define _PAGE_SIZE_ENCODING_16M		6
481*4882a593Smuzhiyun #define _PAGE_SIZE_ENCODING_64M		7
482*4882a593Smuzhiyun 
483*4882a593Smuzhiyun #if defined(CONFIG_PARISC_PAGE_SIZE_4KB)
484*4882a593Smuzhiyun # define _PAGE_SIZE_ENCODING_DEFAULT _PAGE_SIZE_ENCODING_4K
485*4882a593Smuzhiyun #elif defined(CONFIG_PARISC_PAGE_SIZE_16KB)
486*4882a593Smuzhiyun # define _PAGE_SIZE_ENCODING_DEFAULT _PAGE_SIZE_ENCODING_16K
487*4882a593Smuzhiyun #elif defined(CONFIG_PARISC_PAGE_SIZE_64KB)
488*4882a593Smuzhiyun # define _PAGE_SIZE_ENCODING_DEFAULT _PAGE_SIZE_ENCODING_64K
489*4882a593Smuzhiyun #endif
490*4882a593Smuzhiyun 
491*4882a593Smuzhiyun 
492*4882a593Smuzhiyun #define pgprot_noncached(prot) __pgprot(pgprot_val(prot) | _PAGE_NO_CACHE)
493*4882a593Smuzhiyun 
494*4882a593Smuzhiyun /* We provide our own get_unmapped_area to provide cache coherency */
495*4882a593Smuzhiyun 
496*4882a593Smuzhiyun #define HAVE_ARCH_UNMAPPED_AREA
497*4882a593Smuzhiyun #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
498*4882a593Smuzhiyun 
499*4882a593Smuzhiyun #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
500*4882a593Smuzhiyun #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
501*4882a593Smuzhiyun #define __HAVE_ARCH_PTEP_SET_WRPROTECT
502*4882a593Smuzhiyun #define __HAVE_ARCH_PTE_SAME
503*4882a593Smuzhiyun 
504*4882a593Smuzhiyun #endif /* _PARISC_PGTABLE_H */
505