vm_map.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright (c) 2011-2017 Richard Braun.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. *
  18. * Virtual memory map management.
  19. */
  20. #ifndef VM_VM_MAP_H
  21. #define VM_VM_MAP_H
  22. #include <stdint.h>
  23. #include <kern/init.h>
  24. #include <kern/list.h>
  25. #include <kern/mutex.h>
  26. #include <kern/rbtree.h>
  27. #include <machine/pmap.h>
  28. #include <vm/vm_adv.h>
  29. #include <vm/vm_inherit.h>
  30. #include <vm/vm_prot.h>
  31. /*
  32. * Mapping flags.
  33. *
  34. * Unless otherwise mentioned, these can also be used as map entry flags.
  35. */
  36. #define VM_MAP_NOMERGE 0x10000
  37. #define VM_MAP_FIXED 0x20000 /* Not an entry flag */
  38. /*
  39. * Macro used to forge "packed" flags.
  40. */
  41. #define VM_MAP_FLAGS(prot, maxprot, inherit, advice, mapflags) \
  42. ((prot) | ((maxprot) << 4) | ((inherit) << 8) | ((advice) << 12) \
  43. | (mapflags))
  44. /*
  45. * Flags usable as map entry flags.
  46. *
  47. * Map entry flags also use the packed format.
  48. */
  49. #define VM_MAP_ENTRY_MASK (VM_MAP_NOMERGE | 0xffff)
  50. /*
  51. * Macros used to extract specific properties out of packed flags.
  52. */
  53. #define VM_MAP_PROT(flags) ((flags) & 0xf)
  54. #define VM_MAP_MAXPROT(flags) (((flags) & 0xf0) >> 4)
  55. #define VM_MAP_INHERIT(flags) (((flags) & 0xf00) >> 8)
  56. #define VM_MAP_ADVICE(flags) (((flags) & 0xf000) >> 12)
  57. /*
  58. * Memory range descriptor.
  59. */
  60. struct vm_map_entry {
  61. struct list list_node;
  62. struct rbtree_node tree_node;
  63. uintptr_t start;
  64. uintptr_t end;
  65. struct vm_object *object;
  66. uint64_t offset;
  67. int flags;
  68. };
  69. /*
  70. * Memory map.
  71. */
  72. struct vm_map {
  73. struct mutex lock;
  74. struct list entry_list;
  75. struct rbtree entry_tree;
  76. unsigned int nr_entries;
  77. uintptr_t start;
  78. uintptr_t end;
  79. size_t size;
  80. struct vm_map_entry *lookup_cache;
  81. uintptr_t find_cache;
  82. size_t find_cache_threshold;
  83. struct pmap *pmap;
  84. };
  85. static inline struct vm_map *
  86. vm_map_get_kernel_map(void)
  87. {
  88. extern struct vm_map vm_map_kernel_map;
  89. return &vm_map_kernel_map;
  90. }
  91. /*
  92. * Create a virtual mapping.
  93. */
  94. int vm_map_enter(struct vm_map *map, uintptr_t *startp,
  95. size_t size, size_t align, int flags,
  96. struct vm_object *object, uint64_t offset);
  97. /*
  98. * Remove mappings from start to end.
  99. */
  100. void vm_map_remove(struct vm_map *map, uintptr_t start, uintptr_t end);
  101. /*
  102. * Create a VM map.
  103. */
  104. int vm_map_create(struct vm_map **mapp);
  105. /*
  106. * Display information about a memory map.
  107. */
  108. void vm_map_info(struct vm_map *map);
  109. /*
  110. * This init operation provides :
  111. * - kernel mapping operations
  112. */
  113. INIT_OP_DECLARE(vm_map_bootstrap);
  114. /*
  115. * This init operation provides :
  116. * - VM map creation
  117. * - module fully initialized
  118. */
  119. INIT_OP_DECLARE(vm_map_setup);
  120. #endif /* VM_VM_MAP_H */