]> git.saurik.com Git - apple/xnu.git/blob - osfmk/vm/pmap.h
xnu-517.9.5.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 * 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 <sys/appleapiopts.h>
65
66 #ifdef __APPLE_API_PRIVATE
67
68 #include <mach/kern_return.h>
69 #include <mach/vm_param.h>
70 #include <mach/vm_types.h>
71 #include <mach/vm_attributes.h>
72 #include <mach/boolean.h>
73 #include <mach/vm_prot.h>
74
75 /*
76 * The following is a description of the interface to the
77 * machine-dependent "physical map" data structure. The module
78 * must provide a "pmap_t" data type that represents the
79 * set of valid virtual-to-physical addresses for one user
80 * address space. [The kernel address space is represented
81 * by a distinguished "pmap_t".] The routines described manage
82 * this type, install and update virtual-to-physical mappings,
83 * and perform operations on physical addresses common to
84 * many address spaces.
85 */
86
87 /* Copy between a physical page and a virtual address */
88 extern kern_return_t copypv(
89 addr64_t source,
90 addr64_t sink,
91 unsigned int size,
92 int which);
93 #define cppvPsnk 1
94 #define cppvPsrc 2
95 #define cppvFsnk 4
96 #define cppvFsrc 8
97 #define cppvNoModSnk 16
98 #define cppvNoRefSrc 32
99 #define cppvKmap 64 /* User the kernel's vm_map */
100
101 #if !defined(MACH_KERNEL_PRIVATE)
102
103 typedef void *pmap_t;
104
105 #else /* MACH_KERNEL_PRIVATE */
106
107 typedef struct pmap *pmap_t;
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
118 extern vm_offset_t pmap_steal_memory(vm_size_t size);
119 /* During VM initialization,
120 * steal a chunk of memory.
121 */
122 extern unsigned int pmap_free_pages(void); /* During VM initialization,
123 * report remaining unused
124 * physical pages.
125 */
126 extern void pmap_startup(
127 vm_offset_t *startp,
128 vm_offset_t *endp);
129 /* During VM initialization,
130 * use remaining physical pages
131 * to allocate page frames.
132 */
133 extern void pmap_init(void); /* Initialization,
134 * after kernel runs
135 * in virtual memory.
136 */
137
138 #ifndef MACHINE_PAGES
139 /*
140 * If machine/pmap.h defines MACHINE_PAGES, it must implement
141 * the above functions. The pmap module has complete control.
142 * Otherwise, it must implement
143 * pmap_free_pages
144 * pmap_virtual_space
145 * pmap_next_page
146 * pmap_init
147 * and vm/vm_resident.c implements pmap_steal_memory and pmap_startup
148 * using pmap_free_pages, pmap_next_page, pmap_virtual_space,
149 * and pmap_enter. pmap_free_pages may over-estimate the number
150 * of unused physical pages, and pmap_next_page may return FALSE
151 * to indicate that there are no more unused pages to return.
152 * However, for best performance pmap_free_pages should be accurate.
153 */
154
155 extern boolean_t pmap_next_page(ppnum_t *pnum);
156 /* During VM initialization,
157 * return the next unused
158 * physical page.
159 */
160 extern void pmap_virtual_space(
161 vm_offset_t *virtual_start,
162 vm_offset_t *virtual_end);
163 /* During VM initialization,
164 * report virtual space
165 * available for the kernel.
166 */
167 #endif /* MACHINE_PAGES */
168
169 /*
170 * Routines to manage the physical map data structure.
171 */
172 extern pmap_t pmap_create(vm_size_t size); /* Create a pmap_t. */
173 extern pmap_t (pmap_kernel)(void); /* Return the kernel's pmap */
174 extern void pmap_reference(pmap_t pmap); /* Gain a reference. */
175 extern void pmap_destroy(pmap_t pmap); /* Release a reference. */
176 extern void pmap_switch(pmap_t);
177
178
179 extern void pmap_enter( /* Enter a mapping */
180 pmap_t pmap,
181 vm_offset_t v,
182 ppnum_t pn,
183 vm_prot_t prot,
184 unsigned int flags,
185 boolean_t wired);
186
187 extern void pmap_remove_some_phys(
188 pmap_t pmap,
189 ppnum_t pn);
190
191
192 /*
193 * Routines that operate on physical addresses.
194 */
195
196 extern void pmap_page_protect( /* Restrict access to page. */
197 ppnum_t phys,
198 vm_prot_t prot);
199
200 extern void (pmap_zero_page)(
201 ppnum_t pn);
202
203 extern void (pmap_zero_part_page)(
204 ppnum_t pn,
205 vm_offset_t offset,
206 vm_size_t len);
207
208 extern void (pmap_copy_page)(
209 ppnum_t src,
210 ppnum_t dest);
211
212 extern void (pmap_copy_part_page)(
213 ppnum_t src,
214 vm_offset_t src_offset,
215 ppnum_t dst,
216 vm_offset_t dst_offset,
217 vm_size_t len);
218
219 extern void (pmap_copy_part_lpage)(
220 vm_offset_t src,
221 ppnum_t dst,
222 vm_offset_t dst_offset,
223 vm_size_t len);
224
225 extern void (pmap_copy_part_rpage)(
226 ppnum_t src,
227 vm_offset_t src_offset,
228 vm_offset_t dst,
229 vm_size_t len);
230
231 /*
232 * debug/assertions. pmap_verify_free returns true iff
233 * the given physical page is mapped into no pmap.
234 */
235 extern boolean_t pmap_verify_free(ppnum_t pn);
236
237 /*
238 * Statistics routines
239 */
240 extern int (pmap_resident_count)(pmap_t pmap);
241
242 /*
243 * Sundry required (internal) routines
244 */
245 extern void pmap_collect(pmap_t pmap);/* Perform garbage
246 * collection, if any */
247
248
249 extern vm_offset_t (pmap_phys_address)( /* Transform address returned
250 * by device driver mapping
251 * function to physical address
252 * known to this module. */
253 int frame);
254
255 extern int (pmap_phys_to_frame)( /* Inverse of pmap_phys_addess,
256 * for use by device driver
257 * mapping function in
258 * machine-independent
259 * pseudo-devices. */
260 vm_offset_t phys);
261
262 /*
263 * Optional routines
264 */
265 extern void (pmap_copy)( /* Copy range of mappings,
266 * if desired. */
267 pmap_t dest,
268 pmap_t source,
269 vm_offset_t dest_va,
270 vm_size_t size,
271 vm_offset_t source_va);
272
273 extern kern_return_t (pmap_attribute)( /* Get/Set special memory
274 * attributes */
275 pmap_t pmap,
276 vm_offset_t va,
277 vm_size_t size,
278 vm_machine_attribute_t attribute,
279 vm_machine_attribute_val_t* value);
280
281 extern kern_return_t (pmap_attribute_cache_sync)( /* Flush appropriate
282 * cache based on
283 * page number sent */
284 ppnum_t pn,
285 vm_size_t size,
286 vm_machine_attribute_t attribute,
287 vm_machine_attribute_val_t* value);
288
289 /*
290 * Routines defined as macros.
291 */
292 #ifndef PMAP_ACTIVATE_USER
293 #define PMAP_ACTIVATE_USER(act, cpu) { \
294 pmap_t pmap; \
295 \
296 pmap = (act)->map->pmap; \
297 if (pmap != pmap_kernel()) \
298 PMAP_ACTIVATE(pmap, (act), (cpu)); \
299 }
300 #endif /* PMAP_ACTIVATE_USER */
301
302 #ifndef PMAP_DEACTIVATE_USER
303 #define PMAP_DEACTIVATE_USER(act, cpu) { \
304 pmap_t pmap; \
305 \
306 pmap = (act)->map->pmap; \
307 if ((pmap) != pmap_kernel()) \
308 PMAP_DEACTIVATE(pmap, (act), (cpu)); \
309 }
310 #endif /* PMAP_DEACTIVATE_USER */
311
312 #ifndef PMAP_ACTIVATE_KERNEL
313 #define PMAP_ACTIVATE_KERNEL(cpu) \
314 PMAP_ACTIVATE(pmap_kernel(), THR_ACT_NULL, cpu)
315 #endif /* PMAP_ACTIVATE_KERNEL */
316
317 #ifndef PMAP_DEACTIVATE_KERNEL
318 #define PMAP_DEACTIVATE_KERNEL(cpu) \
319 PMAP_DEACTIVATE(pmap_kernel(), THR_ACT_NULL, cpu)
320 #endif /* PMAP_DEACTIVATE_KERNEL */
321
322 #ifndef PMAP_ENTER
323 /*
324 * Macro to be used in place of pmap_enter()
325 */
326 #define PMAP_ENTER(pmap, virtual_address, page, protection, flags, wired) \
327 MACRO_BEGIN \
328 pmap_enter( \
329 (pmap), \
330 (virtual_address), \
331 (page)->phys_page, \
332 (protection) & ~(page)->page_lock, \
333 flags, \
334 (wired) \
335 ); \
336 MACRO_END
337 #endif /* !PMAP_ENTER */
338
339 /*
340 * Routines to manage reference/modify bits based on
341 * physical addresses, simulating them if not provided
342 * by the hardware.
343 */
344 /* Clear reference bit */
345 extern void pmap_clear_reference(ppnum_t pn);
346 /* Return reference bit */
347 extern boolean_t (pmap_is_referenced)(ppnum_t pn);
348 /* Set modify bit */
349 extern void pmap_set_modify(ppnum_t pn);
350 /* Clear modify bit */
351 extern void pmap_clear_modify(ppnum_t pn);
352 /* Return modify bit */
353 extern boolean_t pmap_is_modified(ppnum_t pn);
354
355 /*
356 * Routines that operate on ranges of virtual addresses.
357 */
358 extern void pmap_protect( /* Change protections. */
359 pmap_t map,
360 vm_offset_t s,
361 vm_offset_t e,
362 vm_prot_t prot);
363
364 extern void (pmap_pageable)(
365 pmap_t pmap,
366 vm_offset_t start,
367 vm_offset_t end,
368 boolean_t pageable);
369
370 #endif /* MACH_KERNEL_PRIVATE */
371
372 /*
373 * JMM - This portion is exported to other kernel components right now,
374 * but will be pulled back in the future when the needed functionality
375 * is provided in a cleaner manner.
376 */
377
378 #define PMAP_NULL ((pmap_t) 0)
379
380 extern pmap_t kernel_pmap; /* The kernel's map */
381 #define pmap_kernel() (kernel_pmap)
382
383 /* machine independent WIMG bits */
384
385 #define VM_MEM_GUARDED 0x1
386 #define VM_MEM_COHERENT 0x2
387 #define VM_MEM_NOT_CACHEABLE 0x4
388 #define VM_MEM_WRITE_THROUGH 0x8
389
390 #define VM_WIMG_MASK 0xFF
391 #define VM_WIMG_USE_DEFAULT 0x80000000
392
393 extern void pmap_modify_pages( /* Set modify bit for pages */
394 pmap_t map,
395 vm_offset_t s,
396 vm_offset_t e);
397
398 extern vm_offset_t pmap_extract(pmap_t pmap,
399 vm_offset_t va);
400
401 extern void pmap_change_wiring( /* Specify pageability */
402 pmap_t pmap,
403 vm_offset_t va,
404 boolean_t wired);
405
406 extern void pmap_remove( /* Remove mappings. */
407 pmap_t map,
408 addr64_t s,
409 addr64_t e);
410
411
412 #endif /* __APPLE_API_PRIVATE */
413
414 #endif /* _VM_PMAP_H_ */