vmalloc.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #ifndef _LINUX_VMALLOC_H
  2. #define _LINUX_VMALLOC_H
  3. #include <linux/spinlock.h>
  4. #include <linux/init.h>
  5. #include <linux/list.h>
  6. #include <linux/llist.h>
  7. #include <asm/page.h> /* pgprot_t */
  8. #include <linux/rbtree.h>
  9. struct vm_area_struct; /* vma defining user mapping in mm_types.h */
  10. struct notifier_block; /* in notifier.h */
  11. /* bits in flags of vmalloc's vm_struct below */
  12. #define VM_IOREMAP 0x00000001 /* ioremap() and friends */
  13. #define VM_ALLOC 0x00000002 /* vmalloc() */
  14. #define VM_MAP 0x00000004 /* vmap()ed pages */
  15. #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
  16. #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
  17. #define VM_NO_GUARD 0x00000040 /* don't add guard page */
  18. #define VM_KASAN 0x00000080 /* has allocated kasan shadow memory */
  19. /* bits [20..32] reserved for arch specific ioremap internals */
  20. /*
  21. * Maximum alignment for ioremap() regions.
  22. * Can be overriden by arch-specific value.
  23. */
  24. #ifndef IOREMAP_MAX_ORDER
  25. #define IOREMAP_MAX_ORDER (7 + PAGE_SHIFT) /* 128 pages */
  26. #endif
  27. struct vm_struct {
  28. struct vm_struct *next;
  29. void *addr;
  30. unsigned long size;
  31. unsigned long flags;
  32. struct page **pages;
  33. unsigned int nr_pages;
  34. phys_addr_t phys_addr;
  35. const void *caller;
  36. };
  37. struct vmap_area {
  38. unsigned long va_start;
  39. unsigned long va_end;
  40. unsigned long flags;
  41. struct rb_node rb_node; /* address sorted rbtree */
  42. struct list_head list; /* address sorted list */
  43. struct llist_node purge_list; /* "lazy purge" list */
  44. struct vm_struct *vm;
  45. struct rcu_head rcu_head;
  46. };
  47. /*
  48. * Highlevel APIs for driver use
  49. */
  50. extern void vm_unmap_ram(const void *mem, unsigned int count);
  51. extern void *vm_map_ram(struct page **pages, unsigned int count,
  52. int node, pgprot_t prot);
  53. extern void vm_unmap_aliases(void);
  54. #ifdef CONFIG_MMU
  55. extern void __init vmalloc_init(void);
  56. #else
  57. static inline void vmalloc_init(void)
  58. {
  59. }
  60. #endif
  61. extern void *vmalloc(unsigned long size);
  62. extern void *vzalloc(unsigned long size);
  63. extern void *vmalloc_user(unsigned long size);
  64. extern void *vmalloc_node(unsigned long size, int node);
  65. extern void *vzalloc_node(unsigned long size, int node);
  66. extern void *vmalloc_exec(unsigned long size);
  67. extern void *vmalloc_32(unsigned long size);
  68. extern void *vmalloc_32_user(unsigned long size);
  69. extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
  70. extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
  71. unsigned long start, unsigned long end, gfp_t gfp_mask,
  72. pgprot_t prot, unsigned long vm_flags, int node,
  73. const void *caller);
  74. #ifndef CONFIG_MMU
  75. extern void *__vmalloc_node_flags(unsigned long size, int node, gfp_t flags);
  76. static inline void *__vmalloc_node_flags_caller(unsigned long size, int node,
  77. gfp_t flags, void *caller)
  78. {
  79. return __vmalloc_node_flags(size, node, flags);
  80. }
  81. #else
  82. extern void *__vmalloc_node_flags_caller(unsigned long size,
  83. int node, gfp_t flags, void *caller);
  84. #endif
  85. extern void vfree(const void *addr);
  86. extern void vfree_atomic(const void *addr);
  87. extern void *vmap(struct page **pages, unsigned int count,
  88. unsigned long flags, pgprot_t prot);
  89. extern void vunmap(const void *addr);
  90. extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
  91. unsigned long uaddr, void *kaddr,
  92. unsigned long size);
  93. extern int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
  94. unsigned long pgoff);
  95. void vmalloc_sync_all(void);
  96. /*
  97. * Lowlevel-APIs (not for driver use!)
  98. */
  99. static inline size_t get_vm_area_size(const struct vm_struct *area)
  100. {
  101. if (!(area->flags & VM_NO_GUARD))
  102. /* return actual size without guard page */
  103. return area->size - PAGE_SIZE;
  104. else
  105. return area->size;
  106. }
  107. extern struct vm_struct *get_vm_area(unsigned long size, unsigned long flags);
  108. extern struct vm_struct *get_vm_area_caller(unsigned long size,
  109. unsigned long flags, const void *caller);
  110. extern struct vm_struct *__get_vm_area(unsigned long size, unsigned long flags,
  111. unsigned long start, unsigned long end);
  112. extern struct vm_struct *__get_vm_area_caller(unsigned long size,
  113. unsigned long flags,
  114. unsigned long start, unsigned long end,
  115. const void *caller);
  116. extern struct vm_struct *remove_vm_area(const void *addr);
  117. extern struct vm_struct *find_vm_area(const void *addr);
  118. extern int map_vm_area(struct vm_struct *area, pgprot_t prot,
  119. struct page **pages);
  120. #ifdef CONFIG_MMU
  121. extern int map_kernel_range_noflush(unsigned long start, unsigned long size,
  122. pgprot_t prot, struct page **pages);
  123. extern void unmap_kernel_range_noflush(unsigned long addr, unsigned long size);
  124. extern void unmap_kernel_range(unsigned long addr, unsigned long size);
  125. #else
  126. static inline int
  127. map_kernel_range_noflush(unsigned long start, unsigned long size,
  128. pgprot_t prot, struct page **pages)
  129. {
  130. return size >> PAGE_SHIFT;
  131. }
  132. static inline void
  133. unmap_kernel_range_noflush(unsigned long addr, unsigned long size)
  134. {
  135. }
  136. static inline void
  137. unmap_kernel_range(unsigned long addr, unsigned long size)
  138. {
  139. }
  140. #endif
  141. /* Allocate/destroy a 'vmalloc' VM area. */
  142. extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
  143. extern void free_vm_area(struct vm_struct *area);
  144. /* for /dev/kmem */
  145. extern long vread(char *buf, char *addr, unsigned long count);
  146. extern long vwrite(char *buf, char *addr, unsigned long count);
  147. /*
  148. * Internals. Dont't use..
  149. */
  150. extern struct list_head vmap_area_list;
  151. extern __init void vm_area_add_early(struct vm_struct *vm);
  152. extern __init void vm_area_register_early(struct vm_struct *vm, size_t align);
  153. #ifdef CONFIG_SMP
  154. # ifdef CONFIG_MMU
  155. struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
  156. const size_t *sizes, int nr_vms,
  157. size_t align);
  158. void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms);
  159. # else
  160. static inline struct vm_struct **
  161. pcpu_get_vm_areas(const unsigned long *offsets,
  162. const size_t *sizes, int nr_vms,
  163. size_t align)
  164. {
  165. return NULL;
  166. }
  167. static inline void
  168. pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
  169. {
  170. }
  171. # endif
  172. #endif
  173. #ifdef CONFIG_MMU
  174. #define VMALLOC_TOTAL (VMALLOC_END - VMALLOC_START)
  175. #else
  176. #define VMALLOC_TOTAL 0UL
  177. #endif
  178. int register_vmap_purge_notifier(struct notifier_block *nb);
  179. int unregister_vmap_purge_notifier(struct notifier_block *nb);
  180. #endif /* _LINUX_VMALLOC_H */