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