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