vmalloc.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. extern void vfree(const void *addr);
  75. extern void *vmap(struct page **pages, unsigned int count,
  76. unsigned long flags, pgprot_t prot);
  77. extern void vunmap(const void *addr);
  78. extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
  79. unsigned long uaddr, void *kaddr,
  80. unsigned long size);
  81. extern int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
  82. unsigned long pgoff);
  83. void vmalloc_sync_all(void);
  84. /*
  85. * Lowlevel-APIs (not for driver use!)
  86. */
  87. static inline size_t get_vm_area_size(const struct vm_struct *area)
  88. {
  89. if (!(area->flags & VM_NO_GUARD))
  90. /* return actual size without guard page */
  91. return area->size - PAGE_SIZE;
  92. else
  93. return area->size;
  94. }
  95. extern struct vm_struct *get_vm_area(unsigned long size, unsigned long flags);
  96. extern struct vm_struct *get_vm_area_caller(unsigned long size,
  97. unsigned long flags, const void *caller);
  98. extern struct vm_struct *__get_vm_area(unsigned long size, unsigned long flags,
  99. unsigned long start, unsigned long end);
  100. extern struct vm_struct *__get_vm_area_caller(unsigned long size,
  101. unsigned long flags,
  102. unsigned long start, unsigned long end,
  103. const void *caller);
  104. extern struct vm_struct *remove_vm_area(const void *addr);
  105. extern struct vm_struct *find_vm_area(const void *addr);
  106. extern int map_vm_area(struct vm_struct *area, pgprot_t prot,
  107. struct page **pages);
  108. #ifdef CONFIG_MMU
  109. extern int map_kernel_range_noflush(unsigned long start, unsigned long size,
  110. pgprot_t prot, struct page **pages);
  111. extern void unmap_kernel_range_noflush(unsigned long addr, unsigned long size);
  112. extern void unmap_kernel_range(unsigned long addr, unsigned long size);
  113. #else
  114. static inline int
  115. map_kernel_range_noflush(unsigned long start, unsigned long size,
  116. pgprot_t prot, struct page **pages)
  117. {
  118. return size >> PAGE_SHIFT;
  119. }
  120. static inline void
  121. unmap_kernel_range_noflush(unsigned long addr, unsigned long size)
  122. {
  123. }
  124. static inline void
  125. unmap_kernel_range(unsigned long addr, unsigned long size)
  126. {
  127. }
  128. #endif
  129. /* Allocate/destroy a 'vmalloc' VM area. */
  130. extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
  131. extern void free_vm_area(struct vm_struct *area);
  132. /* for /dev/kmem */
  133. extern long vread(char *buf, char *addr, unsigned long count);
  134. extern long vwrite(char *buf, char *addr, unsigned long count);
  135. /*
  136. * Internals. Dont't use..
  137. */
  138. extern struct list_head vmap_area_list;
  139. extern __init void vm_area_add_early(struct vm_struct *vm);
  140. extern __init void vm_area_register_early(struct vm_struct *vm, size_t align);
  141. #ifdef CONFIG_SMP
  142. # ifdef CONFIG_MMU
  143. struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
  144. const size_t *sizes, int nr_vms,
  145. size_t align);
  146. void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms);
  147. # else
  148. static inline struct vm_struct **
  149. pcpu_get_vm_areas(const unsigned long *offsets,
  150. const size_t *sizes, int nr_vms,
  151. size_t align)
  152. {
  153. return NULL;
  154. }
  155. static inline void
  156. pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
  157. {
  158. }
  159. # endif
  160. #endif
  161. #ifdef CONFIG_MMU
  162. #define VMALLOC_TOTAL (VMALLOC_END - VMALLOC_START)
  163. #else
  164. #define VMALLOC_TOTAL 0UL
  165. #endif
  166. int register_vmap_purge_notifier(struct notifier_block *nb);
  167. int unregister_vmap_purge_notifier(struct notifier_block *nb);
  168. #endif /* _LINUX_VMALLOC_H */