]> git.saurik.com Git - apple/xnu.git/blob - osfmk/vm/pmap.h
7638a13a3a66da1cae80cd4b52ca3b045914549b
[apple/xnu.git] / osfmk / vm / pmap.h
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * @OSF_COPYRIGHT@
24 */
25 /*
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
28 * All Rights Reserved.
29 *
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
35 *
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
39 *
40 * Carnegie Mellon requests users of this software to return to
41 *
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
46 *
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
49 */
50 /*
51 */
52 /*
53 * File: vm/pmap.h
54 * Author: Avadis Tevanian, Jr.
55 * Date: 1985
56 *
57 * Machine address mapping definitions -- machine-independent
58 * section. [For machine-dependent section, see "machine/pmap.h".]
59 */
60
61 #ifndef _VM_PMAP_H_
62 #define _VM_PMAP_H_
63
64 #include <mach/kern_return.h>
65 #include <mach/vm_param.h>
66 #include <mach/vm_types.h>
67 #include <mach/vm_attributes.h>
68 #include <mach/boolean.h>
69 #include <mach/vm_prot.h>
70
71 #ifdef KERNEL_PRIVATE
72
73 /*
74 * The following is a description of the interface to the
75 * machine-dependent "physical map" data structure. The module
76 * must provide a "pmap_t" data type that represents the
77 * set of valid virtual-to-physical addresses for one user
78 * address space. [The kernel address space is represented
79 * by a distinguished "pmap_t".] The routines described manage
80 * this type, install and update virtual-to-physical mappings,
81 * and perform operations on physical addresses common to
82 * many address spaces.
83 */
84
85 /* Copy between a physical page and a virtual address */
86 /* LP64todo - switch to vm_map_offset_t when it grows */
87 extern kern_return_t copypv(
88 addr64_t source,
89 addr64_t sink,
90 unsigned int size,
91 int which);
92 #define cppvPsnk 1
93 #define cppvPsnkb 31
94 #define cppvPsrc 2
95 #define cppvPsrcb 30
96 #define cppvFsnk 4
97 #define cppvFsnkb 29
98 #define cppvFsrc 8
99 #define cppvFsrcb 28
100 #define cppvNoModSnk 16
101 #define cppvNoModSnkb 27
102 #define cppvNoRefSrc 32
103 #define cppvNoRefSrcb 26
104 #define cppvKmap 64 /* Use the kernel's vm_map */
105 #define cppvKmapb 25
106
107 #ifdef MACH_KERNEL_PRIVATE
108
109 #include <machine/pmap.h>
110
111 /*
112 * Routines used for initialization.
113 * There is traditionally also a pmap_bootstrap,
114 * used very early by machine-dependent code,
115 * but it is not part of the interface.
116 *
117 * LP64todo -
118 * These interfaces are tied to the size of the
119 * kernel pmap - and therefore use the "local"
120 * vm_offset_t, etc... types.
121 */
122
123 extern void *pmap_steal_memory(vm_size_t size);
124 /* During VM initialization,
125 * steal a chunk of memory.
126 */
127 extern unsigned int pmap_free_pages(void); /* During VM initialization,
128 * report remaining unused
129 * physical pages.
130 */
131 extern void pmap_startup(
132 vm_offset_t *startp,
133 vm_offset_t *endp);
134 /* During VM initialization,
135 * use remaining physical pages
136 * to allocate page frames.
137 */
138 extern void pmap_init(void); /* Initialization,
139 * after kernel runs
140 * in virtual memory.
141 */
142
143 extern void mapping_adjust(void); /* Adjust free mapping count */
144
145 extern void mapping_free_prime(void); /* Primes the mapping block release list */
146
147 #ifndef MACHINE_PAGES
148 /*
149 * If machine/pmap.h defines MACHINE_PAGES, it must implement
150 * the above functions. The pmap module has complete control.
151 * Otherwise, it must implement
152 * pmap_free_pages
153 * pmap_virtual_space
154 * pmap_next_page
155 * pmap_init
156 * and vm/vm_resident.c implements pmap_steal_memory and pmap_startup
157 * using pmap_free_pages, pmap_next_page, pmap_virtual_space,
158 * and pmap_enter. pmap_free_pages may over-estimate the number
159 * of unused physical pages, and pmap_next_page may return FALSE
160 * to indicate that there are no more unused pages to return.
161 * However, for best performance pmap_free_pages should be accurate.
162 */
163
164 extern boolean_t pmap_next_page(ppnum_t *pnum);
165 /* During VM initialization,
166 * return the next unused
167 * physical page.
168 */
169 extern void pmap_virtual_space(
170 vm_offset_t *virtual_start,
171 vm_offset_t *virtual_end);
172 /* During VM initialization,
173 * report virtual space
174 * available for the kernel.
175 */
176 #endif /* MACHINE_PAGES */
177
178 /*
179 * Routines to manage the physical map data structure.
180 */
181 extern pmap_t pmap_create( /* Create a pmap_t. */
182 vm_map_size_t size,
183 boolean_t is_64bit);
184 extern pmap_t (pmap_kernel)(void); /* Return the kernel's pmap */
185 extern void pmap_reference(pmap_t pmap); /* Gain a reference. */
186 extern void pmap_destroy(pmap_t pmap); /* Release a reference. */
187 extern void pmap_switch(pmap_t);
188
189
190 extern void pmap_enter( /* Enter a mapping */
191 pmap_t pmap,
192 vm_map_offset_t v,
193 ppnum_t pn,
194 vm_prot_t prot,
195 unsigned int flags,
196 boolean_t wired);
197
198 extern void pmap_remove_some_phys(
199 pmap_t pmap,
200 ppnum_t pn);
201
202
203 /*
204 * Routines that operate on physical addresses.
205 */
206
207 extern void pmap_page_protect( /* Restrict access to page. */
208 ppnum_t phys,
209 vm_prot_t prot);
210
211 extern void (pmap_zero_page)(
212 ppnum_t pn);
213
214 extern void (pmap_zero_part_page)(
215 ppnum_t pn,
216 vm_offset_t offset,
217 vm_size_t len);
218
219 extern void (pmap_copy_page)(
220 ppnum_t src,
221 ppnum_t dest);
222
223 extern void (pmap_copy_part_page)(
224 ppnum_t src,
225 vm_offset_t src_offset,
226 ppnum_t dst,
227 vm_offset_t dst_offset,
228 vm_size_t len);
229
230 extern void (pmap_copy_part_lpage)(
231 vm_offset_t src,
232 ppnum_t dst,
233 vm_offset_t dst_offset,
234 vm_size_t len);
235
236 extern void (pmap_copy_part_rpage)(
237 ppnum_t src,
238 vm_offset_t src_offset,
239 vm_offset_t dst,
240 vm_size_t len);
241
242 extern unsigned int (pmap_disconnect)( /* disconnect mappings and return reference and change */
243 ppnum_t phys);
244
245 extern kern_return_t (pmap_attribute_cache_sync)( /* Flush appropriate
246 * cache based on
247 * page number sent */
248 ppnum_t pn,
249 vm_size_t size,
250 vm_machine_attribute_t attribute,
251 vm_machine_attribute_val_t* value);
252
253 extern unsigned int (pmap_cache_attributes)(
254 ppnum_t pn);
255
256 /*
257 * debug/assertions. pmap_verify_free returns true iff
258 * the given physical page is mapped into no pmap.
259 */
260 extern boolean_t pmap_verify_free(ppnum_t pn);
261
262 /*
263 * Statistics routines
264 */
265 extern int (pmap_resident_count)(pmap_t pmap);
266
267 /*
268 * Sundry required (internal) routines
269 */
270 extern void pmap_collect(pmap_t pmap);/* Perform garbage
271 * collection, if any */
272
273 /*
274 * Optional routines
275 */
276 extern void (pmap_copy)( /* Copy range of mappings,
277 * if desired. */
278 pmap_t dest,
279 pmap_t source,
280 vm_map_offset_t dest_va,
281 vm_map_size_t size,
282 vm_map_offset_t source_va);
283
284 extern kern_return_t (pmap_attribute)( /* Get/Set special memory
285 * attributes */
286 pmap_t pmap,
287 vm_map_offset_t va,
288 vm_map_size_t size,
289 vm_machine_attribute_t attribute,
290 vm_machine_attribute_val_t* value);
291
292 /*
293 * Routines defined as macros.
294 */
295 #ifndef PMAP_ACTIVATE_USER
296 #ifndef PMAP_ACTIVATE
297 #define PMAP_ACTIVATE_USER(thr, cpu)
298 #else /* PMAP_ACTIVATE */
299 #define PMAP_ACTIVATE_USER(thr, cpu) { \
300 pmap_t pmap; \
301 \
302 pmap = (thr)->map->pmap; \
303 if (pmap != pmap_kernel()) \
304 PMAP_ACTIVATE(pmap, (thr), (cpu)); \
305 }
306 #endif /* PMAP_ACTIVATE */
307 #endif /* PMAP_ACTIVATE_USER */
308
309 #ifndef PMAP_DEACTIVATE_USER
310 #ifndef PMAP_DEACTIVATE
311 #define PMAP_DEACTIVATE_USER(thr, cpu)
312 #else /* PMAP_DEACTIVATE */
313 #define PMAP_DEACTIVATE_USER(thr, cpu) { \
314 pmap_t pmap; \
315 \
316 pmap = (thr)->map->pmap; \
317 if ((pmap) != pmap_kernel()) \
318 PMAP_DEACTIVATE(pmap, (thr), (cpu)); \
319 }
320 #endif /* PMAP_DEACTIVATE */
321 #endif /* PMAP_DEACTIVATE_USER */
322
323 #ifndef PMAP_ACTIVATE_KERNEL
324 #ifndef PMAP_ACTIVATE
325 #define PMAP_ACTIVATE_KERNEL(cpu)
326 #else /* PMAP_ACTIVATE */
327 #define PMAP_ACTIVATE_KERNEL(cpu) \
328 PMAP_ACTIVATE(pmap_kernel(), THREAD_NULL, cpu)
329 #endif /* PMAP_ACTIVATE */
330 #endif /* PMAP_ACTIVATE_KERNEL */
331
332 #ifndef PMAP_DEACTIVATE_KERNEL
333 #ifndef PMAP_DEACTIVATE
334 #define PMAP_DEACTIVATE_KERNEL(cpu)
335 #else /* PMAP_DEACTIVATE */
336 #define PMAP_DEACTIVATE_KERNEL(cpu) \
337 PMAP_DEACTIVATE(pmap_kernel(), THREAD_NULL, cpu)
338 #endif /* PMAP_DEACTIVATE */
339 #endif /* PMAP_DEACTIVATE_KERNEL */
340
341 #ifndef PMAP_ENTER
342 /*
343 * Macro to be used in place of pmap_enter()
344 */
345 #define PMAP_ENTER(pmap, virtual_address, page, protection, flags, wired) \
346 MACRO_BEGIN \
347 pmap_t __pmap = (pmap); \
348 vm_page_t __page = (page); \
349 \
350 if (__pmap != kernel_pmap) { \
351 ASSERT_PAGE_DECRYPTED(__page); \
352 } \
353 pmap_enter(__pmap, \
354 (virtual_address), \
355 __page->phys_page, \
356 (protection) & ~__page->page_lock, \
357 (flags), \
358 (wired)); \
359 MACRO_END
360 #endif /* !PMAP_ENTER */
361
362 /*
363 * Routines to manage reference/modify bits based on
364 * physical addresses, simulating them if not provided
365 * by the hardware.
366 */
367 /* Clear reference bit */
368 extern void pmap_clear_reference(ppnum_t pn);
369 /* Return reference bit */
370 extern boolean_t (pmap_is_referenced)(ppnum_t pn);
371 /* Set modify bit */
372 extern void pmap_set_modify(ppnum_t pn);
373 /* Clear modify bit */
374 extern void pmap_clear_modify(ppnum_t pn);
375 /* Return modify bit */
376 extern boolean_t pmap_is_modified(ppnum_t pn);
377 /* Return modified and referenced bits */
378 extern unsigned int pmap_get_refmod(ppnum_t pn);
379 /* Clear modified and referenced bits */
380 extern void pmap_clear_refmod(ppnum_t pn, unsigned int mask);
381 #define VM_MEM_MODIFIED 0x01 /* Modified bit */
382 #define VM_MEM_REFERENCED 0x02 /* Referenced bit */
383
384 /*
385 * Routines that operate on ranges of virtual addresses.
386 */
387 extern void pmap_protect( /* Change protections. */
388 pmap_t map,
389 vm_map_offset_t s,
390 vm_map_offset_t e,
391 vm_prot_t prot);
392
393 extern void (pmap_pageable)(
394 pmap_t pmap,
395 vm_map_offset_t start,
396 vm_map_offset_t end,
397 boolean_t pageable);
398
399 #endif /* MACH_KERNEL_PRIVATE */
400
401 /*
402 * JMM - This portion is exported to other kernel components right now,
403 * but will be pulled back in the future when the needed functionality
404 * is provided in a cleaner manner.
405 */
406
407 extern pmap_t kernel_pmap; /* The kernel's map */
408 #define pmap_kernel() (kernel_pmap)
409
410 /* machine independent WIMG bits */
411
412 #define VM_MEM_GUARDED 0x1 /* (G) Guarded Storage */
413 #define VM_MEM_COHERENT 0x2 /* (M) Memory Coherency */
414 #define VM_MEM_NOT_CACHEABLE 0x4 /* (I) Cache Inhibit */
415 #define VM_MEM_WRITE_THROUGH 0x8 /* (W) Write-Through */
416
417 #define VM_WIMG_MASK 0xFF
418 #define VM_WIMG_USE_DEFAULT 0x80000000
419
420 extern void pmap_modify_pages( /* Set modify bit for pages */
421 pmap_t map,
422 vm_map_offset_t s,
423 vm_map_offset_t e);
424
425 extern vm_offset_t pmap_extract(pmap_t pmap,
426 vm_map_offset_t va);
427
428 extern void pmap_change_wiring( /* Specify pageability */
429 pmap_t pmap,
430 vm_map_offset_t va,
431 boolean_t wired);
432
433 /* LP64todo - switch to vm_map_offset_t when it grows */
434 extern void pmap_remove( /* Remove mappings. */
435 pmap_t map,
436 addr64_t s,
437 addr64_t e);
438
439
440 #endif /* KERNEL_PRIVATE */
441
442 #endif /* _VM_PMAP_H_ */