vmalloc.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #ifndef _LINUX_VMALLOC_H
  2. #define _LINUX_VMALLOC_H
  3. #include <linux/spinlock.h>
  4. #include <linux/init.h>
  5. #include <asm/page.h> /* pgprot_t */
  6. struct vm_area_struct; /* vma defining user mapping in mm_types.h */
  7. /* bits in flags of vmalloc's vm_struct below */
  8. #define VM_IOREMAP 0x00000001 /* ioremap() and friends */
  9. #define VM_ALLOC 0x00000002 /* vmalloc() */
  10. #define VM_MAP 0x00000004 /* vmap()ed pages */
  11. #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
  12. #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
  13. /* bits [20..32] reserved for arch specific ioremap internals */
  14. /*
  15. * Maximum alignment for ioremap() regions.
  16. * Can be overriden by arch-specific value.
  17. */
  18. #ifndef IOREMAP_MAX_ORDER
  19. #define IOREMAP_MAX_ORDER (7 + PAGE_SHIFT) /* 128 pages */
  20. #endif
  21. struct vm_struct {
  22. struct vm_struct *next;
  23. void *addr;
  24. unsigned long size;
  25. unsigned long flags;
  26. struct page **pages;
  27. unsigned int nr_pages;
  28. phys_addr_t phys_addr;
  29. void *caller;
  30. };
  31. /*
  32. * Highlevel APIs for driver use
  33. */
  34. extern void vm_unmap_ram(const void *mem, unsigned int count);
  35. extern void *vm_map_ram(struct page **pages, unsigned int count,
  36. int node, pgprot_t prot);
  37. extern void vm_unmap_aliases(void);
  38. #ifdef CONFIG_MMU
  39. extern void __init vmalloc_init(void);
  40. #else
  41. static inline void vmalloc_init(void)
  42. {
  43. }
  44. #endif
  45. extern void *vmalloc(unsigned long size);
  46. extern void *vzalloc(unsigned long size);
  47. extern void *vmalloc_user(unsigned long size);
  48. extern void *vmalloc_node(unsigned long size, int node);
  49. extern void *vzalloc_node(unsigned long size, int node);
  50. extern void *vmalloc_exec(unsigned long size);
  51. extern void *vmalloc_32(unsigned long size);
  52. extern void *vmalloc_32_user(unsigned long size);
  53. extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
  54. extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
  55. unsigned long start, unsigned long end, gfp_t gfp_mask,
  56. pgprot_t prot, int node, void *caller);
  57. extern void vfree(const void *addr);
  58. extern void *vmap(struct page **pages, unsigned int count,
  59. unsigned long flags, pgprot_t prot);
  60. extern void vunmap(const void *addr);
  61. extern int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
  62. unsigned long pgoff);
  63. void vmalloc_sync_all(void);
  64. /*
  65. * Lowlevel-APIs (not for driver use!)
  66. */
  67. static inline size_t get_vm_area_size(const struct vm_struct *area)
  68. {
  69. /* return actual size without guard page */
  70. return area->size - PAGE_SIZE;
  71. }
  72. extern struct vm_struct *get_vm_area(unsigned long size, unsigned long flags);
  73. extern struct vm_struct *get_vm_area_caller(unsigned long size,
  74. unsigned long flags, void *caller);
  75. extern struct vm_struct *__get_vm_area(unsigned long size, unsigned long flags,
  76. unsigned long start, unsigned long end);
  77. extern struct vm_struct *__get_vm_area_caller(unsigned long size,
  78. unsigned long flags,
  79. unsigned long start, unsigned long end,
  80. void *caller);
  81. extern struct vm_struct *remove_vm_area(const void *addr);
  82. extern int map_vm_area(struct vm_struct *area, pgprot_t prot,
  83. struct page ***pages);
  84. #ifdef CONFIG_MMU
  85. extern int map_kernel_range_noflush(unsigned long start, unsigned long size,
  86. pgprot_t prot, struct page **pages);
  87. extern void unmap_kernel_range_noflush(unsigned long addr, unsigned long size);
  88. extern void unmap_kernel_range(unsigned long addr, unsigned long size);
  89. #else
  90. static inline int
  91. map_kernel_range_noflush(unsigned long start, unsigned long size,
  92. pgprot_t prot, struct page **pages)
  93. {
  94. return size >> PAGE_SHIFT;
  95. }
  96. static inline void
  97. unmap_kernel_range_noflush(unsigned long addr, unsigned long size)
  98. {
  99. }
  100. static inline void
  101. unmap_kernel_range(unsigned long addr, unsigned long size)
  102. {
  103. }
  104. #endif
  105. /* Allocate/destroy a 'vmalloc' VM area. */
  106. extern struct vm_struct *alloc_vm_area(size_t size);
  107. extern void free_vm_area(struct vm_struct *area);
  108. /* for /dev/kmem */
  109. extern long vread(char *buf, char *addr, unsigned long count);
  110. extern long vwrite(char *buf, char *addr, unsigned long count);
  111. /*
  112. * Internals. Dont't use..
  113. */
  114. extern rwlock_t vmlist_lock;
  115. extern struct vm_struct *vmlist;
  116. extern __init void vm_area_register_early(struct vm_struct *vm, size_t align);
  117. #ifdef CONFIG_SMP
  118. # ifdef CONFIG_MMU
  119. struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
  120. const size_t *sizes, int nr_vms,
  121. size_t align);
  122. void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms);
  123. # else
  124. static inline struct vm_struct **
  125. pcpu_get_vm_areas(const unsigned long *offsets,
  126. const size_t *sizes, int nr_vms,
  127. size_t align)
  128. {
  129. return NULL;
  130. }
  131. static inline void
  132. pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
  133. {
  134. }
  135. # endif
  136. #endif
  137. #endif /* _LINUX_VMALLOC_H */