vmalloc.h 5.8 KB

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