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