1 #ifndef _MIPS_PGTABLE_32_H
2 #define _MIPS_PGTABLE_32_H
3 
4 /*
5  * traditional mips two-level paging structure:
6  */
7 
8 #ifdef CONFIG_64BIT_PHYS_ADDR
9 #define PGD_ORDER	1
10 #define PTE_ORDER	0
11 #else
12 #define PGD_ORDER	0
13 #define PTE_ORDER	0
14 #endif
15 
16 #define PMD_SHIFT       (2 * PAGE_SHIFT - PTE_T_LOG2)
17 
18 #if !defined (_LANGUAGE_ASSEMBLY)
19 #ifdef CONFIG_64BIT_PHYS_ADDR
20 #define pte_ERROR(e) \
21 	printk("%s:%d: bad pte %016Lx.\n", __FILE__, __LINE__, pte_val(e))
22 #else
23 #define pte_ERROR(e) \
24 	printk("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, (e).pte_low)
25 #endif
26 #define pmd_ERROR(e) \
27 	printk("%s:%d: bad pmd %08lx.\n", __FILE__, __LINE__, pmd_val(e))
28 #define pgd_ERROR(e) \
29 	printk("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e))
30 
pte_none(pte_t pte)31 static inline int pte_none(pte_t pte)    { return !(pte_val(pte) & ~_PAGE_GLOBAL); }
32 
pte_wrprotect(pte_t pte)33 static inline pte_t pte_wrprotect(pte_t pte)
34 {
35 	pte_val(pte) &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE);
36 	return pte;
37 }
38 
pte_rdprotect(pte_t pte)39 static inline pte_t pte_rdprotect(pte_t pte)
40 {
41 	pte_val(pte) &= ~(_PAGE_READ | _PAGE_SILENT_READ);
42 	return pte;
43 }
44 
pte_mkclean(pte_t pte)45 static inline pte_t pte_mkclean(pte_t pte)
46 {
47 	pte_val(pte) &= ~(_PAGE_MODIFIED|_PAGE_SILENT_WRITE);
48 	return pte;
49 }
50 
pte_mkold(pte_t pte)51 static inline pte_t pte_mkold(pte_t pte)
52 {
53 	pte_val(pte) &= ~(_PAGE_ACCESSED|_PAGE_SILENT_READ);
54 	return pte;
55 }
56 
pte_mkwrite(pte_t pte)57 static inline pte_t pte_mkwrite(pte_t pte)
58 {
59 	pte_val(pte) |= _PAGE_WRITE;
60 	if (pte_val(pte) & _PAGE_MODIFIED)
61 		pte_val(pte) |= _PAGE_SILENT_WRITE;
62 	return pte;
63 }
64 
pte_mkread(pte_t pte)65 static inline pte_t pte_mkread(pte_t pte)
66 {
67 	pte_val(pte) |= _PAGE_READ;
68 	if (pte_val(pte) & _PAGE_ACCESSED)
69 		pte_val(pte) |= _PAGE_SILENT_READ;
70 	return pte;
71 }
72 
pte_mkdirty(pte_t pte)73 static inline pte_t pte_mkdirty(pte_t pte)
74 {
75 	pte_val(pte) |= _PAGE_MODIFIED;
76 	if (pte_val(pte) & _PAGE_WRITE)
77 		pte_val(pte) |= _PAGE_SILENT_WRITE;
78 	return pte;
79 }
80 
81 /*
82  * Macro to make mark a page protection value as "uncacheable".  Note
83  * that "protection" is really a misnomer here as the protection value
84  * contains the memory attribute bits, dirty bits, and various other
85  * bits as well.
86  */
87 #define pgprot_noncached pgprot_noncached
88 
pgprot_noncached(pgprot_t _prot)89 static inline pgprot_t pgprot_noncached(pgprot_t _prot)
90 {
91 	unsigned long prot = pgprot_val(_prot);
92 
93 	prot = (prot & ~_CACHE_MASK) | _CACHE_UNCACHED;
94 
95 	return __pgprot(prot);
96 }
97 
pte_mkyoung(pte_t pte)98 static inline pte_t pte_mkyoung(pte_t pte)
99 {
100 	pte_val(pte) |= _PAGE_ACCESSED;
101 	if (pte_val(pte) & _PAGE_READ)
102 		pte_val(pte) |= _PAGE_SILENT_READ;
103 	return pte;
104 }
105 
106 /*
107  * Conversion functions: convert a page and protection to a page entry,
108  * and a page entry and page directory to the page they refer to.
109  */
110 
111 #ifdef CONFIG_CPU_VR41XX
112 #define mk_pte(page, pgprot)                                            \
113 ({                                                                      \
114         pte_t   __pte;                                                  \
115                                                                         \
116         pte_val(__pte) = ((phys_t)(page - mem_map) << (PAGE_SHIFT + 2)) | \
117                          pgprot_val(pgprot);                            \
118                                                                         \
119         __pte;                                                          \
120 })
121 #else
122 #define mk_pte(page, pgprot)						\
123 ({									\
124 	pte_t   __pte;							\
125 									\
126 	pte_val(__pte) = ((phys_t)(page - mem_map) << PAGE_SHIFT) | \
127 	                 pgprot_val(pgprot);				\
128 									\
129 	__pte;								\
130 })
131 #endif
132 
mk_pte_phys(phys_t physpage,pgprot_t pgprot)133 static inline pte_t mk_pte_phys(phys_t physpage, pgprot_t pgprot)
134 {
135 #ifdef CONFIG_CPU_VR41XX
136         return __pte((physpage << 2) | pgprot_val(pgprot));
137 #else
138 	return __pte(physpage | pgprot_val(pgprot));
139 #endif
140 }
141 
pte_modify(pte_t pte,pgprot_t newprot)142 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
143 {
144 	return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot));
145 }
146 
147 /* Certain architectures need to do special things when pte's
148  * within a page table are directly modified.  Thus, the following
149  * hook is made available.
150  */
set_pte(pte_t * ptep,pte_t pteval)151 static inline void set_pte(pte_t *ptep, pte_t pteval)
152 {
153 	*ptep = pteval;
154 #if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX)
155 	if (pte_val(pteval) & _PAGE_GLOBAL) {
156 		pte_t *buddy = ptep_buddy(ptep);
157 		/*
158 		 * Make sure the buddy is global too (if it's !none,
159 		 * it better already be global)
160 		 */
161 		if (pte_none(*buddy))
162 			pte_val(*buddy) = pte_val(*buddy) | _PAGE_GLOBAL;
163 	}
164 #endif
165 }
166 
pte_clear(pte_t * ptep)167 static inline void pte_clear(pte_t *ptep)
168 {
169 #if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX)
170 	/* Preserve global status for the pair */
171 	if (pte_val(*ptep_buddy(ptep)) & _PAGE_GLOBAL)
172 		set_pte(ptep, __pte(_PAGE_GLOBAL));
173 	else
174 #endif
175 		set_pte(ptep, __pte(0));
176 }
177 
178 #ifdef CONFIG_CPU_VR41XX
179 #define pte_page(x)  (mem_map+((unsigned long)(((x).pte_low >> (PAGE_SHIFT+2)))))
180 #define __mk_pte(page_nr,pgprot) __pte(((page_nr) << (PAGE_SHIFT+2)) | pgprot_val(pgprot))
181 #else
182 #define pte_page(x)  (mem_map+((unsigned long)(((x).pte_low >> PAGE_SHIFT))))
183 #define __mk_pte(page_nr,pgprot) __pte(((page_nr) << PAGE_SHIFT) | pgprot_val(pgprot))
184 #endif
185 
186 #endif
187 
188 #endif /* _MIPS_PGTABLE_32_H */
189