pte.h revision 1.21 1 1.21 matt /* $NetBSD: pte.h,v 1.21 2015/06/11 08:22:09 matt Exp $ */
2 1.1 jonathan
3 1.3 jonathan /*-
4 1.3 jonathan * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 1.3 jonathan * All rights reserved.
6 1.3 jonathan *
7 1.3 jonathan * This code is derived from software contributed to The NetBSD Foundation
8 1.3 jonathan * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.3 jonathan * NASA Ames Research Center.
10 1.3 jonathan *
11 1.3 jonathan * Redistribution and use in source and binary forms, with or without
12 1.3 jonathan * modification, are permitted provided that the following conditions
13 1.3 jonathan * are met:
14 1.3 jonathan * 1. Redistributions of source code must retain the above copyright
15 1.3 jonathan * notice, this list of conditions and the following disclaimer.
16 1.3 jonathan * 2. Redistributions in binary form must reproduce the above copyright
17 1.3 jonathan * notice, this list of conditions and the following disclaimer in the
18 1.3 jonathan * documentation and/or other materials provided with the distribution.
19 1.3 jonathan *
20 1.3 jonathan * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 1.3 jonathan * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.3 jonathan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 1.3 jonathan * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 1.3 jonathan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 1.3 jonathan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 1.3 jonathan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 1.3 jonathan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.3 jonathan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.3 jonathan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.3 jonathan * POSSIBILITY OF SUCH DAMAGE.
31 1.3 jonathan */
32 1.3 jonathan
33 1.1 jonathan /*
34 1.1 jonathan * Copyright 1996 The Board of Trustees of The Leland Stanford
35 1.1 jonathan * Junior University. All Rights Reserved.
36 1.1 jonathan *
37 1.1 jonathan * Permission to use, copy, modify, and distribute this
38 1.1 jonathan * software and its documentation for any purpose and without
39 1.1 jonathan * fee is hereby granted, provided that the above copyright
40 1.1 jonathan * notice appear in all copies. Stanford University
41 1.1 jonathan * makes no representations about the suitability of this
42 1.1 jonathan * software for any purpose. It is provided "as is" without
43 1.1 jonathan * express or implied warranty.
44 1.1 jonathan */
45 1.1 jonathan
46 1.1 jonathan #ifndef __MIPS_PTE_H__
47 1.1 jonathan #define __MIPS_PTE_H__
48 1.1 jonathan
49 1.3 jonathan #include <mips/mips1_pte.h>
50 1.3 jonathan #include <mips/mips3_pte.h>
51 1.3 jonathan
52 1.3 jonathan #define PG_ASID 0x000000ff /* Address space ID */
53 1.3 jonathan
54 1.3 jonathan #ifndef _LOCORE
55 1.3 jonathan #include <mips/cpu.h>
56 1.3 jonathan
57 1.3 jonathan typedef union pt_entry {
58 1.20 matt uint32_t pt_entry; /* for copying, etc. */
59 1.3 jonathan struct mips1_pte pt_mips1_pte; /* for getting to bits by name */
60 1.3 jonathan struct mips3_pte pt_mips3_pte;
61 1.3 jonathan } pt_entry_t;
62 1.3 jonathan
63 1.3 jonathan /*
64 1.3 jonathan * Macros/inline functions to hide PTE format differences.
65 1.3 jonathan */
66 1.3 jonathan
67 1.3 jonathan #define mips_pg_nv_bit() (MIPS1_PG_NV) /* same on mips1 and mips3 */
68 1.3 jonathan
69 1.3 jonathan
70 1.20 matt bool pmap_is_page_ro_p(struct pmap *pmap, vaddr_t, uint32_t);
71 1.3 jonathan
72 1.3 jonathan
73 1.3 jonathan /* MIPS1-only */
74 1.12 simonb #if defined(MIPS1) && !defined(MIPS3_PLUS)
75 1.3 jonathan #define mips_pg_v(entry) ((entry) & MIPS1_PG_V)
76 1.3 jonathan #define mips_pg_wired(entry) ((entry) & MIPS1_PG_WIRED)
77 1.3 jonathan
78 1.8 nisimura #define mips_pg_m_bit() (MIPS1_PG_D)
79 1.3 jonathan #define mips_pg_rw_bit() (MIPS1_PG_RW) /* no RW bits for mips1 */
80 1.3 jonathan #define mips_pg_ro_bit() (MIPS1_PG_RO)
81 1.3 jonathan #define mips_pg_ropage_bit() (MIPS1_PG_RO) /* XXX not MIPS1_PG_ROPAGE? */
82 1.3 jonathan #define mips_pg_rwpage_bit() (MIPS1_PG_RWPAGE)
83 1.17 macallan #define mips_pg_rwncpage_bit() (MIPS1_PG_RWNCPAGE)
84 1.3 jonathan #define mips_pg_cwpage_bit() (MIPS1_PG_CWPAGE)
85 1.17 macallan #define mips_pg_cwncpage_bit() (MIPS1_PG_CWNCPAGE)
86 1.3 jonathan #define mips_pg_global_bit() (MIPS1_PG_G)
87 1.3 jonathan #define mips_pg_wired_bit() (MIPS1_PG_WIRED)
88 1.3 jonathan
89 1.3 jonathan #define PTE_TO_PADDR(pte) MIPS1_PTE_TO_PADDR((pte))
90 1.3 jonathan #define PAGE_IS_RDONLY(pte, va) MIPS1_PAGE_IS_RDONLY((pte), (va))
91 1.3 jonathan
92 1.10 soda #define mips_tlbpfn_to_paddr(x) mips1_tlbpfn_to_paddr((vaddr_t)(x))
93 1.10 soda #define mips_paddr_to_tlbpfn(x) mips1_paddr_to_tlbpfn((x))
94 1.3 jonathan #endif /* mips1 */
95 1.3 jonathan
96 1.3 jonathan
97 1.12 simonb /* MIPS3 (or greater) only */
98 1.12 simonb #if !defined(MIPS1) && defined(MIPS3_PLUS)
99 1.3 jonathan #define mips_pg_v(entry) ((entry) & MIPS3_PG_V)
100 1.3 jonathan #define mips_pg_wired(entry) ((entry) & MIPS3_PG_WIRED)
101 1.3 jonathan
102 1.8 nisimura #define mips_pg_m_bit() (MIPS3_PG_D)
103 1.8 nisimura #define mips_pg_rw_bit() (MIPS3_PG_D)
104 1.3 jonathan #define mips_pg_ro_bit() (MIPS3_PG_RO)
105 1.3 jonathan #define mips_pg_ropage_bit() (MIPS3_PG_ROPAGE)
106 1.3 jonathan #define mips_pg_rwpage_bit() (MIPS3_PG_RWPAGE)
107 1.17 macallan #define mips_pg_rwncpage_bit() (MIPS3_PG_RWNCPAGE)
108 1.3 jonathan #define mips_pg_cwpage_bit() (MIPS3_PG_CWPAGE)
109 1.17 macallan #define mips_pg_cwncpage_bit() (MIPS3_PG_CWNCPAGE)
110 1.3 jonathan #define mips_pg_global_bit() (MIPS3_PG_G)
111 1.3 jonathan #define mips_pg_wired_bit() (MIPS3_PG_WIRED)
112 1.1 jonathan
113 1.3 jonathan #define PTE_TO_PADDR(pte) MIPS3_PTE_TO_PADDR((pte))
114 1.3 jonathan #define PAGE_IS_RDONLY(pte, va) MIPS3_PAGE_IS_RDONLY((pte), (va))
115 1.3 jonathan
116 1.10 soda #define mips_tlbpfn_to_paddr(x) mips3_tlbpfn_to_paddr((vaddr_t)(x))
117 1.10 soda #define mips_paddr_to_tlbpfn(x) mips3_paddr_to_tlbpfn((x))
118 1.3 jonathan #endif /* mips3 */
119 1.3 jonathan
120 1.12 simonb /* MIPS1 and MIPS3 (or greater) */
121 1.12 simonb #if defined(MIPS1) && defined(MIPS3_PLUS)
122 1.1 jonathan
123 1.20 matt static __inline bool
124 1.20 matt mips_pg_v(uint32_t entry),
125 1.20 matt mips_pg_wired(uint32_t entry),
126 1.20 matt PAGE_IS_RDONLY(uint32_t pte, vaddr_t va);
127 1.3 jonathan
128 1.20 matt static __inline uint32_t
129 1.20 matt mips_pg_wired_bit(void) __pure,
130 1.20 matt mips_pg_m_bit(void) __pure,
131 1.20 matt mips_pg_ro_bit(void) __pure,
132 1.20 matt mips_pg_rw_bit(void) __pure,
133 1.20 matt mips_pg_ropage_bit(void) __pure,
134 1.20 matt mips_pg_cwpage_bit(void) __pure,
135 1.20 matt mips_pg_rwpage_bit(void) __pure,
136 1.20 matt mips_pg_global_bit(void) __pure;
137 1.20 matt static __inline paddr_t PTE_TO_PADDR(uint32_t pte) __pure;
138 1.20 matt static __inline bool PAGE_IS_RDONLY(uint32_t pte, vaddr_t va) __pure;
139 1.3 jonathan
140 1.20 matt static __inline paddr_t mips_tlbpfn_to_paddr(uint32_t pfn) __pure;
141 1.20 matt static __inline uint32_t mips_paddr_to_tlbpfn(paddr_t pa) __pure;
142 1.3 jonathan
143 1.3 jonathan
144 1.20 matt static __inline bool
145 1.20 matt mips_pg_v(uint32_t entry)
146 1.3 jonathan {
147 1.12 simonb if (MIPS_HAS_R4K_MMU)
148 1.20 matt return (entry & MIPS3_PG_V) != 0;
149 1.20 matt return (entry & MIPS1_PG_V) != 0;
150 1.3 jonathan }
151 1.3 jonathan
152 1.20 matt static __inline bool
153 1.20 matt mips_pg_wired(uint32_t entry)
154 1.3 jonathan {
155 1.12 simonb if (MIPS_HAS_R4K_MMU)
156 1.20 matt return (entry & MIPS3_PG_WIRED) != 0;
157 1.20 matt return (entry & MIPS1_PG_WIRED) != 0;
158 1.3 jonathan }
159 1.3 jonathan
160 1.20 matt static __inline uint32_t
161 1.14 simonb mips_pg_m_bit(void)
162 1.3 jonathan {
163 1.12 simonb if (MIPS_HAS_R4K_MMU)
164 1.7 nisimura return (MIPS3_PG_D);
165 1.7 nisimura return (MIPS1_PG_D);
166 1.3 jonathan }
167 1.3 jonathan
168 1.16 perry static __inline unsigned int
169 1.14 simonb mips_pg_ro_bit(void)
170 1.3 jonathan {
171 1.12 simonb if (MIPS_HAS_R4K_MMU)
172 1.3 jonathan return (MIPS3_PG_RO);
173 1.3 jonathan return (MIPS1_PG_RO);
174 1.3 jonathan }
175 1.3 jonathan
176 1.16 perry static __inline unsigned int
177 1.14 simonb mips_pg_rw_bit(void)
178 1.3 jonathan {
179 1.12 simonb if (MIPS_HAS_R4K_MMU)
180 1.7 nisimura return (MIPS3_PG_D);
181 1.3 jonathan return (MIPS1_PG_RW);
182 1.3 jonathan }
183 1.3 jonathan
184 1.16 perry static __inline unsigned int
185 1.14 simonb mips_pg_ropage_bit(void)
186 1.3 jonathan {
187 1.12 simonb if (MIPS_HAS_R4K_MMU)
188 1.3 jonathan return (MIPS3_PG_ROPAGE);
189 1.3 jonathan return (MIPS1_PG_RO);
190 1.3 jonathan }
191 1.3 jonathan
192 1.16 perry static __inline unsigned int
193 1.14 simonb mips_pg_rwpage_bit(void)
194 1.3 jonathan {
195 1.12 simonb if (MIPS_HAS_R4K_MMU)
196 1.3 jonathan return (MIPS3_PG_RWPAGE);
197 1.3 jonathan return (MIPS1_PG_RWPAGE);
198 1.3 jonathan }
199 1.3 jonathan
200 1.16 perry static __inline unsigned int
201 1.14 simonb mips_pg_cwpage_bit(void)
202 1.3 jonathan {
203 1.12 simonb if (MIPS_HAS_R4K_MMU)
204 1.3 jonathan return (MIPS3_PG_CWPAGE);
205 1.3 jonathan return (MIPS1_PG_CWPAGE);
206 1.3 jonathan }
207 1.3 jonathan
208 1.3 jonathan
209 1.16 perry static __inline unsigned int
210 1.14 simonb mips_pg_global_bit(void)
211 1.3 jonathan {
212 1.12 simonb if (MIPS_HAS_R4K_MMU)
213 1.3 jonathan return (MIPS3_PG_G);
214 1.3 jonathan return (MIPS1_PG_G);
215 1.3 jonathan }
216 1.3 jonathan
217 1.16 perry static __inline unsigned int
218 1.14 simonb mips_pg_wired_bit(void)
219 1.3 jonathan {
220 1.12 simonb if (MIPS_HAS_R4K_MMU)
221 1.3 jonathan return (MIPS3_PG_WIRED);
222 1.3 jonathan return (MIPS1_PG_WIRED);
223 1.3 jonathan }
224 1.3 jonathan
225 1.16 perry static __inline paddr_t
226 1.20 matt PTE_TO_PADDR(uint32_t pte)
227 1.3 jonathan {
228 1.12 simonb if (MIPS_HAS_R4K_MMU)
229 1.3 jonathan return (MIPS3_PTE_TO_PADDR(pte));
230 1.3 jonathan return (MIPS1_PTE_TO_PADDR(pte));
231 1.3 jonathan }
232 1.3 jonathan
233 1.20 matt static __inline bool
234 1.20 matt PAGE_IS_RDONLY(uint32_t pte, vaddr_t va)
235 1.3 jonathan {
236 1.12 simonb if (MIPS_HAS_R4K_MMU)
237 1.3 jonathan return (MIPS3_PAGE_IS_RDONLY(pte, va));
238 1.3 jonathan return (MIPS1_PAGE_IS_RDONLY(pte, va));
239 1.3 jonathan }
240 1.3 jonathan
241 1.16 perry static __inline paddr_t
242 1.20 matt mips_tlbpfn_to_paddr(uint32_t pfn)
243 1.3 jonathan {
244 1.12 simonb if (MIPS_HAS_R4K_MMU)
245 1.10 soda return (mips3_tlbpfn_to_paddr(pfn));
246 1.10 soda return (mips1_tlbpfn_to_paddr(pfn));
247 1.3 jonathan }
248 1.1 jonathan
249 1.20 matt static __inline uint32_t
250 1.20 matt mips_paddr_to_tlbpfn(paddr_t pa)
251 1.3 jonathan {
252 1.12 simonb if (MIPS_HAS_R4K_MMU)
253 1.10 soda return (mips3_paddr_to_tlbpfn(pa));
254 1.10 soda return (mips1_paddr_to_tlbpfn(pa));
255 1.3 jonathan }
256 1.1 jonathan #endif
257 1.1 jonathan
258 1.3 jonathan #endif /* ! _LOCORE */
259 1.1 jonathan
260 1.1 jonathan #if defined(_KERNEL) && !defined(_LOCORE)
261 1.1 jonathan /*
262 1.1 jonathan * Kernel virtual address to page table entry and visa versa.
263 1.1 jonathan */
264 1.1 jonathan #define kvtopte(va) \
265 1.6 nisimura (Sysmap + (((vaddr_t)(va) - VM_MIN_KERNEL_ADDRESS) >> PGSHIFT))
266 1.1 jonathan #define ptetokv(pte) \
267 1.1 jonathan ((((pt_entry_t *)(pte) - Sysmap) << PGSHIFT) + VM_MIN_KERNEL_ADDRESS)
268 1.1 jonathan
269 1.1 jonathan extern pt_entry_t *Sysmap; /* kernel pte table */
270 1.1 jonathan extern u_int Sysmapsize; /* number of pte's in Sysmap */
271 1.21 matt
272 1.21 matt static inline bool
273 1.21 matt pte_zero_p(pt_entry_t pte)
274 1.21 matt {
275 1.21 matt return pte.pt_entry == 0;
276 1.21 matt }
277 1.21 matt
278 1.21 matt #define PRIxPTE PRIx32
279 1.21 matt static inline uint32_t
280 1.21 matt pte_value(pt_entry_t pte)
281 1.21 matt {
282 1.21 matt return pte.pt_entry;
283 1.21 matt }
284 1.21 matt
285 1.1 jonathan #endif /* defined(_KERNEL) && !defined(_LOCORE) */
286 1.1 jonathan #endif /* __MIPS_PTE_H__ */
287