vmalloc.h 5.7 KB

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