pmap.h revision 1.22 1 /* $NetBSD: pmap.h,v 1.22 2011/02/15 19:39:12 macallan Exp $ */
2
3 /*-
4 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5 * Copyright (C) 1995, 1996 TooLs GmbH.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by TooLs GmbH.
19 * 4. The name of TooLs GmbH may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #ifndef _POWERPC_OEA_PMAP_H_
35 #define _POWERPC_OEA_PMAP_H_
36
37 #ifdef _KERNEL_OPT
38 #include "opt_ppcarch.h"
39 #endif
40 #include <powerpc/oea/pte.h>
41
42 #ifndef _LOCORE
43 /*
44 * Pmap stuff
45 */
46 struct pmap {
47 #ifdef PPC_OEA64
48 struct steg *pm_steg_table; /* segment table pointer */
49 /* XXX need way to track exec pages */
50 #endif
51
52 #if defined(PPC_OEA) || defined (PPC_OEA64_BRIDGE)
53 register_t pm_sr[16]; /* segments used in this pmap */
54 int pm_exec[16]; /* counts of exec mappings */
55 #endif
56 register_t pm_vsid; /* VSID bits */
57 int pm_refs; /* ref count */
58 struct pmap_statistics pm_stats; /* pmap statistics */
59 unsigned int pm_evictions; /* pvo's not in page table */
60
61 #ifdef PPC_OEA64
62 unsigned int pm_ste_evictions;
63 #endif
64 };
65
66 struct pmap_ops {
67 int (*pmapop_pte_spill)(struct pmap *, vaddr_t, bool);
68 void (*pmapop_real_memory)(paddr_t *, psize_t *);
69 void (*pmapop_init)(void);
70 void (*pmapop_virtual_space)(vaddr_t *, vaddr_t *);
71 pmap_t (*pmapop_create)(void);
72 void (*pmapop_reference)(pmap_t);
73 void (*pmapop_destroy)(pmap_t);
74 void (*pmapop_copy)(pmap_t, pmap_t, vaddr_t, vsize_t, vaddr_t);
75 void (*pmapop_update)(pmap_t);
76 int (*pmapop_enter)(pmap_t, vaddr_t, paddr_t, vm_prot_t, u_int);
77 void (*pmapop_remove)(pmap_t, vaddr_t, vaddr_t);
78 void (*pmapop_kenter_pa)(vaddr_t, paddr_t, vm_prot_t, u_int);
79 void (*pmapop_kremove)(vaddr_t, vsize_t);
80 bool (*pmapop_extract)(pmap_t, vaddr_t, paddr_t *);
81
82 void (*pmapop_protect)(pmap_t, vaddr_t, vaddr_t, vm_prot_t);
83 void (*pmapop_unwire)(pmap_t, vaddr_t);
84 void (*pmapop_page_protect)(struct vm_page *, vm_prot_t);
85 bool (*pmapop_query_bit)(struct vm_page *, int);
86 bool (*pmapop_clear_bit)(struct vm_page *, int);
87
88 void (*pmapop_activate)(struct lwp *);
89 void (*pmapop_deactivate)(struct lwp *);
90
91 void (*pmapop_pinit)(pmap_t);
92 void (*pmapop_procwr)(struct proc *, vaddr_t, size_t);
93
94 void (*pmapop_pte_print)(volatile struct pte *);
95 void (*pmapop_pteg_check)(void);
96 void (*pmapop_print_mmuregs)(void);
97 void (*pmapop_print_pte)(pmap_t, vaddr_t);
98 void (*pmapop_pteg_dist)(void);
99 void (*pmapop_pvo_verify)(void);
100 vaddr_t (*pmapop_steal_memory)(vsize_t, vaddr_t *, vaddr_t *);
101 void (*pmapop_bootstrap)(paddr_t, paddr_t);
102 };
103
104 #ifdef _KERNEL
105 #include <sys/cdefs.h>
106 __BEGIN_DECLS
107 #include <sys/param.h>
108 #include <sys/systm.h>
109
110 #if defined (PPC_OEA) || defined (PPC_OEA64_BRIDGE)
111 extern register_t iosrtable[];
112 #endif
113 extern int pmap_use_altivec;
114
115 #define pmap_clear_modify(pg) (pmap_clear_bit((pg), PTE_CHG))
116 #define pmap_clear_reference(pg) (pmap_clear_bit((pg), PTE_REF))
117 #define pmap_is_modified(pg) (pmap_query_bit((pg), PTE_CHG))
118 #define pmap_is_referenced(pg) (pmap_query_bit((pg), PTE_REF))
119
120 #define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count)
121 #define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count)
122
123 /* ARGSUSED */
124 static inline void
125 pmap_remove_all(struct pmap *pmap)
126 {
127 /* Nothing. */
128 }
129
130 #if (defined(PPC_OEA) + defined(PPC_OEA64) + defined(PPC_OEA64_BRIDGE)) != 1
131 #define PMAP_NEEDS_FIXUP
132 #endif
133
134 void pmap_bootstrap(vaddr_t, vaddr_t);
135 bool pmap_extract(pmap_t, vaddr_t, paddr_t *);
136 bool pmap_query_bit(struct vm_page *, int);
137 bool pmap_clear_bit(struct vm_page *, int);
138 void pmap_real_memory(paddr_t *, psize_t *);
139 void pmap_procwr(struct proc *, vaddr_t, size_t);
140 int pmap_pte_spill(pmap_t, vaddr_t, bool);
141 void pmap_pinit(pmap_t);
142
143 u_int powerpc_mmap_flags(paddr_t);
144 #define POWERPC_MMAP_FLAG_MASK 0xf
145 #define POWERPC_MMAP_FLAG_PREFETCHABLE 0x1
146 #define POWERPC_MMAP_FLAG_CACHEABLE 0x2
147
148 #define pmap_phys_address(ppn) (ppn & ~POWERPC_MMAP_FLAG_MASK)
149 #define pmap_mmap_flags(ppn) powerpc_mmap_flags(ppn)
150
151 static inline paddr_t vtophys (vaddr_t);
152
153 /*
154 * Alternate mapping hooks for pool pages. Avoids thrashing the TLB.
155 *
156 * Note: This won't work if we have more memory than can be direct-mapped
157 * VA==PA all at once. But pmap_copy_page() and pmap_zero_page() will have
158 * this problem, too.
159 */
160 #if !defined(PPC_OEA64) && !defined (PPC_OEA64_BRIDGE)
161 #define PMAP_MAP_POOLPAGE(pa) (pa)
162 #define PMAP_UNMAP_POOLPAGE(pa) (pa)
163 #define POOL_VTOPHYS(va) vtophys((vaddr_t) va)
164 #endif
165
166 static inline paddr_t
167 vtophys(vaddr_t va)
168 {
169 paddr_t pa;
170
171 if (pmap_extract(pmap_kernel(), va, &pa))
172 return pa;
173 KASSERTMSG(0, ("vtophys: pmap_extract of %#"PRIxVADDR" failed", va));
174 return (paddr_t) -1;
175 }
176
177
178 #ifdef PMAP_NEEDS_FIXUP
179 extern const struct pmap_ops *pmapops;
180 extern const struct pmap_ops pmap32_ops;
181 extern const struct pmap_ops pmap64_ops;
182 extern const struct pmap_ops pmap64bridge_ops;
183
184 void pmap_fixup_stubs(const struct pmap_ops *);
185
186 static inline void
187 pmap_setup32(void)
188 {
189 pmap_fixup_stubs(&pmap32_ops);
190 }
191
192 static inline void
193 pmap_setup64(void)
194 {
195 pmap_fixup_stubs(&pmap64_ops);
196 }
197
198 static inline void
199 pmap_setup64bridge(void)
200 {
201 pmap_fixup_stubs(&pmap64bridge_ops);
202 }
203 #endif
204
205 bool pmap_pageidlezero (paddr_t);
206 void pmap_syncicache (paddr_t, psize_t);
207 #ifdef PPC_OEA64
208 vaddr_t pmap_setusr (vaddr_t);
209 vaddr_t pmap_unsetusr (void);
210 #endif
211
212 #ifdef PPC_OEA64_BRIDGE
213 int pmap_setup_segment0_map(int use_large_pages, ...);
214 #endif
215
216 #define PMAP_MD_NOCACHE 0x1000000
217 #define PMAP_MD_PREFETCHABLE 0x2000000
218 #define PMAP_STEAL_MEMORY
219 #define PMAP_NEED_PROCWR
220
221 void pmap_zero_page(paddr_t);
222 void pmap_copy_page(paddr_t, paddr_t);
223
224 LIST_HEAD(pvo_head, pvo_entry);
225
226 #define __HAVE_VM_PAGE_MD
227
228 struct vm_page_md {
229 struct pvo_head mdpg_pvoh;
230 unsigned int mdpg_attrs;
231 };
232
233 #define VM_MDPAGE_INIT(pg) do { \
234 LIST_INIT(&(pg)->mdpage.mdpg_pvoh); \
235 (pg)->mdpage.mdpg_attrs = 0; \
236 } while (/*CONSTCOND*/0)
237
238 __END_DECLS
239 #endif /* _KERNEL */
240 #endif /* _LOCORE */
241
242 #endif /* _POWERPC_OEA_PMAP_H_ */
243