]> git.saurik.com Git - apple/xnu.git/blame - osfmk/vm/pmap.h
xnu-344.21.74.tar.gz
[apple/xnu.git] / osfmk / vm / pmap.h
CommitLineData
1c79356b 1/*
9bccf70c 2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
1c79356b
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
d7e50217 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
d7e50217
A
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
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
d7e50217
A
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.
1c79356b
A
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
9bccf70c
A
67#include <sys/appleapiopts.h>
68
69#ifdef __APPLE_API_PRIVATE
70
1c79356b
A
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
d7e50217
A
90/* Copy between a physical page and a virtual address */
91extern 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
9bccf70c 104#if !defined(MACH_KERNEL_PRIVATE)
1c79356b
A
105
106typedef void *pmap_t;
107
108#else /* MACH_KERNEL_PRIVATE */
109
110typedef 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
121extern vm_offset_t pmap_steal_memory(vm_size_t size);
122 /* During VM initialization,
123 * steal a chunk of memory.
124 */
125extern unsigned int pmap_free_pages(void); /* During VM initialization,
126 * report remaining unused
127 * physical pages.
128 */
129extern 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 */
136extern 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
d7e50217 158extern boolean_t pmap_next_page(ppnum_t *pnum);
1c79356b
A
159 /* During VM initialization,
160 * return the next unused
161 * physical page.
162 */
163extern 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 */
175extern pmap_t pmap_create(vm_size_t size); /* Create a pmap_t. */
176extern pmap_t (pmap_kernel)(void); /* Return the kernel's pmap */
177extern void pmap_reference(pmap_t pmap); /* Gain a reference. */
178extern void pmap_destroy(pmap_t pmap); /* Release a reference. */
179extern void pmap_switch(pmap_t);
180
181
182extern void pmap_enter( /* Enter a mapping */
183 pmap_t pmap,
184 vm_offset_t v,
d7e50217 185 ppnum_t pn,
1c79356b 186 vm_prot_t prot,
9bccf70c 187 unsigned int flags,
1c79356b
A
188 boolean_t wired);
189
0b4e3aa0
A
190extern void pmap_remove_some_phys(
191 pmap_t pmap,
d7e50217 192 ppnum_t pn);
0b4e3aa0 193
1c79356b
A
194
195/*
196 * Routines that operate on physical addresses.
197 */
0b4e3aa0 198
1c79356b 199extern void pmap_page_protect( /* Restrict access to page. */
d7e50217 200 ppnum_t phys,
1c79356b
A
201 vm_prot_t prot);
202
203extern void (pmap_zero_page)(
d7e50217 204 ppnum_t pn);
1c79356b
A
205
206extern void (pmap_zero_part_page)(
d7e50217 207 ppnum_t pn,
1c79356b
A
208 vm_offset_t offset,
209 vm_size_t len);
210
211extern void (pmap_copy_page)(
d7e50217
A
212 ppnum_t src,
213 ppnum_t dest);
1c79356b
A
214
215extern void (pmap_copy_part_page)(
d7e50217 216 ppnum_t src,
1c79356b 217 vm_offset_t src_offset,
d7e50217 218 ppnum_t dst,
1c79356b
A
219 vm_offset_t dst_offset,
220 vm_size_t len);
221
222extern void (pmap_copy_part_lpage)(
223 vm_offset_t src,
d7e50217 224 ppnum_t dst,
1c79356b
A
225 vm_offset_t dst_offset,
226 vm_size_t len);
227
228extern void (pmap_copy_part_rpage)(
d7e50217 229 ppnum_t src,
1c79356b
A
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 */
d7e50217 238extern boolean_t pmap_verify_free(ppnum_t pn);
1c79356b
A
239
240/*
241 * Statistics routines
242 */
243extern int (pmap_resident_count)(pmap_t pmap);
244
245/*
246 * Sundry required (internal) routines
247 */
248extern void pmap_collect(pmap_t pmap);/* Perform garbage
249 * collection, if any */
250
251
252extern 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
258extern 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 */
268extern 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
276extern 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
9bccf70c
A
284extern kern_return_t (pmap_attribute_cache_sync)( /* Flush appropriate
285 * cache based on
d7e50217
A
286 * page number sent */
287 ppnum_t pn,
9bccf70c
A
288 vm_size_t size,
289 vm_machine_attribute_t attribute,
290 vm_machine_attribute_val_t* value);
291
1c79356b
A
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 */
9bccf70c 329#define PMAP_ENTER(pmap, virtual_address, page, protection, flags, wired) \
1c79356b
A
330 MACRO_BEGIN \
331 pmap_enter( \
332 (pmap), \
333 (virtual_address), \
d7e50217 334 (page)->phys_page, \
1c79356b 335 (protection) & ~(page)->page_lock, \
9bccf70c 336 flags, \
1c79356b
A
337 (wired) \
338 ); \
339 MACRO_END
340#endif /* !PMAP_ENTER */
341
1c79356b
A
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 */
d7e50217 348extern void pmap_clear_reference(ppnum_t pn);
1c79356b 349 /* Return reference bit */
d7e50217 350extern boolean_t (pmap_is_referenced)(ppnum_t pn);
1c79356b 351 /* Set modify bit */
d7e50217 352extern void pmap_set_modify(ppnum_t pn);
1c79356b 353 /* Clear modify bit */
d7e50217 354extern void pmap_clear_modify(ppnum_t pn);
1c79356b 355 /* Return modify bit */
d7e50217 356extern boolean_t pmap_is_modified(ppnum_t pn);
1c79356b
A
357
358/*
359 * Routines that operate on ranges of virtual addresses.
360 */
1c79356b
A
361extern 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
367extern void (pmap_pageable)(
368 pmap_t pmap,
369 vm_offset_t start,
370 vm_offset_t end,
371 boolean_t pageable);
372
9bccf70c
A
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
383extern 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
1c79356b
A
396extern void pmap_modify_pages( /* Set modify bit for pages */
397 pmap_t map,
398 vm_offset_t s,
399 vm_offset_t e);
400
401extern vm_offset_t pmap_extract(pmap_t pmap,
402 vm_offset_t va);
403
404extern void pmap_change_wiring( /* Specify pageability */
405 pmap_t pmap,
406 vm_offset_t va,
407 boolean_t wired);
9bccf70c
A
408
409extern void pmap_remove( /* Remove mappings. */
410 pmap_t map,
d7e50217
A
411 addr64_t s,
412 addr64_t e);
413
9bccf70c
A
414
415#endif /* __APPLE_API_PRIVATE */
416
1c79356b 417#endif /* _VM_PMAP_H_ */