pmap.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /*
  2. * Mach Operating System
  3. * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University.
  4. * Copyright (c) 1993,1994 The University of Utah and
  5. * the Computer Systems Laboratory (CSL).
  6. * All rights reserved.
  7. *
  8. * Permission to use, copy, modify and distribute this software and its
  9. * documentation is hereby granted, provided that both the copyright
  10. * notice and this permission notice appear in all copies of the
  11. * software, derivative works or modified versions, and any portions
  12. * thereof, and that both notices appear in supporting documentation.
  13. *
  14. * CARNEGIE MELLON, THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF
  15. * THIS SOFTWARE IN ITS "AS IS" CONDITION, AND DISCLAIM ANY LIABILITY
  16. * OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF
  17. * THIS SOFTWARE.
  18. *
  19. * Carnegie Mellon requests users of this software to return to
  20. *
  21. * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
  22. * School of Computer Science
  23. * Carnegie Mellon University
  24. * Pittsburgh PA 15213-3890
  25. *
  26. * any improvements or extensions that they make and grant Carnegie Mellon
  27. * the rights to redistribute these changes.
  28. */
  29. /*
  30. * File: vm/pmap.h
  31. * Author: Avadis Tevanian, Jr.
  32. * Date: 1985
  33. *
  34. * Machine address mapping definitions -- machine-independent
  35. * section. [For machine-dependent section, see "machine/pmap.h".]
  36. */
  37. #ifndef _VM_PMAP_H_
  38. #define _VM_PMAP_H_
  39. #include <machine/pmap.h>
  40. #include <mach/machine/vm_types.h>
  41. #include <mach/vm_prot.h>
  42. #include <mach/boolean.h>
  43. #include <kern/thread.h>
  44. /*
  45. * The following is a description of the interface to the
  46. * machine-dependent "physical map" data structure. The module
  47. * must provide a "pmap_t" data type that represents the
  48. * set of valid virtual-to-physical addresses for one user
  49. * address space. [The kernel address space is represented
  50. * by a distinguished "pmap_t".] The routines described manage
  51. * this type, install and update virtual-to-physical mappings,
  52. * and perform operations on physical addresses common to
  53. * many address spaces.
  54. */
  55. /*
  56. * Routines used for initialization.
  57. * There is traditionally also a pmap_bootstrap,
  58. * used very early by machine-dependent code,
  59. * but it is not part of the interface.
  60. */
  61. /* During VM initialization, steal a chunk of memory. */
  62. extern vm_offset_t pmap_steal_memory(vm_size_t);
  63. /* Initialization, after kernel runs in virtual memory. */
  64. extern void pmap_init(void);
  65. #ifndef MACHINE_PAGES
  66. /*
  67. * If machine/pmap.h defines MACHINE_PAGES, it must implement
  68. * the above functions. The pmap module has complete control.
  69. * Otherwise, it must implement
  70. * pmap_virtual_space
  71. * pmap_init
  72. * and vm/vm_resident.c implements pmap_steal_memory using
  73. * pmap_virtual_space and pmap_enter.
  74. */
  75. /* During VM initialization, report virtual space available for the kernel. */
  76. extern void pmap_virtual_space(vm_offset_t *, vm_offset_t *);
  77. #endif /* MACHINE_PAGES */
  78. /*
  79. * Routines to manage the physical map data structure.
  80. */
  81. /* Create a pmap_t. */
  82. pmap_t pmap_create(vm_size_t size);
  83. /* Return the kernel's pmap_t. */
  84. #ifndef pmap_kernel
  85. extern pmap_t pmap_kernel(void);
  86. #endif /* pmap_kernel */
  87. /* Gain and release a reference. */
  88. extern void pmap_reference(pmap_t pmap);
  89. extern void pmap_destroy(pmap_t pmap);
  90. /* Enter a mapping */
  91. extern void pmap_enter(pmap_t pmap, vm_offset_t va, phys_addr_t pa,
  92. vm_prot_t prot, boolean_t wired);
  93. /*
  94. * Routines that operate on ranges of virtual addresses.
  95. */
  96. /* Remove mappings. */
  97. void pmap_remove(pmap_t pmap, vm_offset_t sva, vm_offset_t eva);
  98. /* Change protections. */
  99. void pmap_protect(pmap_t pmap, vm_offset_t sva, vm_offset_t eva, vm_prot_t prot);
  100. /*
  101. * Routines to set up hardware state for physical maps to be used.
  102. */
  103. /* Prepare pmap_t to run on a given processor. */
  104. extern void pmap_activate(pmap_t, thread_t, int);
  105. /* Release pmap_t from use on processor. */
  106. extern void pmap_deactivate(pmap_t, thread_t, int);
  107. /*
  108. * Routines that operate on physical addresses.
  109. */
  110. /* Restrict access to page. */
  111. void pmap_page_protect(phys_addr_t pa, vm_prot_t prot);
  112. /*
  113. * Routines to manage reference/modify bits based on
  114. * physical addresses, simulating them if not provided
  115. * by the hardware.
  116. */
  117. /* Clear reference bit */
  118. void pmap_clear_reference(phys_addr_t pa);
  119. /* Return reference bit */
  120. #ifndef pmap_is_referenced
  121. boolean_t pmap_is_referenced(phys_addr_t pa);
  122. #endif /* pmap_is_referenced */
  123. /* Clear modify bit */
  124. void pmap_clear_modify(phys_addr_t pa);
  125. /* Return modify bit */
  126. boolean_t pmap_is_modified(phys_addr_t pa);
  127. /*
  128. * Sundry required routines
  129. */
  130. /* Return a virtual-to-physical mapping, if possible. */
  131. extern phys_addr_t pmap_extract(pmap_t, vm_offset_t);
  132. /* Perform garbage collection, if any. */
  133. extern void pmap_collect(pmap_t);
  134. /* Specify pageability. */
  135. extern void pmap_change_wiring(pmap_t, vm_offset_t, boolean_t);
  136. /*
  137. * Optional routines
  138. */
  139. #ifndef pmap_copy
  140. /* Copy range of mappings, if desired. */
  141. extern void pmap_copy(pmap_t, pmap_t, vm_offset_t, vm_size_t,
  142. vm_offset_t);
  143. #endif /* pmap_copy */
  144. #ifndef pmap_attribute
  145. /* Get/Set special memory attributes. */
  146. extern kern_return_t pmap_attribute(void);
  147. #endif /* pmap_attribute */
  148. /*
  149. * Grab a physical page:
  150. * the standard memory allocation mechanism
  151. * during system initialization.
  152. */
  153. extern vm_offset_t pmap_grab_page (void);
  154. /*
  155. * Make the specified pages (by pmap, offset)
  156. * pageable (or not) as requested.
  157. */
  158. extern void pmap_pageable(
  159. pmap_t pmap,
  160. vm_offset_t start,
  161. vm_offset_t end,
  162. boolean_t pageable);
  163. /*
  164. * Back-door routine for mapping kernel VM at initialization.
  165. * Useful for mapping memory outside the range of direct mapped
  166. * physical memory (i.e., devices).
  167. * Otherwise like pmap_map.
  168. */
  169. extern vm_offset_t pmap_map_bd(
  170. vm_offset_t virt,
  171. phys_addr_t start,
  172. phys_addr_t end,
  173. vm_prot_t prot);
  174. /*
  175. * Routines defined as macros.
  176. */
  177. #ifndef PMAP_ACTIVATE_USER
  178. #define PMAP_ACTIVATE_USER(pmap, thread, cpu) { \
  179. if ((pmap) != kernel_pmap) \
  180. PMAP_ACTIVATE(pmap, thread, cpu); \
  181. }
  182. #endif /* PMAP_ACTIVATE_USER */
  183. #ifndef PMAP_DEACTIVATE_USER
  184. #define PMAP_DEACTIVATE_USER(pmap, thread, cpu) { \
  185. if ((pmap) != kernel_pmap) \
  186. PMAP_DEACTIVATE(pmap, thread, cpu); \
  187. }
  188. #endif /* PMAP_DEACTIVATE_USER */
  189. #ifndef PMAP_ACTIVATE_KERNEL
  190. #define PMAP_ACTIVATE_KERNEL(cpu) \
  191. PMAP_ACTIVATE(kernel_pmap, THREAD_NULL, cpu)
  192. #endif /* PMAP_ACTIVATE_KERNEL */
  193. #ifndef PMAP_DEACTIVATE_KERNEL
  194. #define PMAP_DEACTIVATE_KERNEL(cpu) \
  195. PMAP_DEACTIVATE(kernel_pmap, THREAD_NULL, cpu)
  196. #endif /* PMAP_DEACTIVATE_KERNEL */
  197. /*
  198. * Exported data structures
  199. */
  200. extern pmap_t kernel_pmap; /* The kernel's map */
  201. #endif /* _VM_PMAP_H_ */