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